public function createObjectFromArray($arr, $trim = false)
 {
     $stdObj = NGS()->getDynObject();
     foreach ($arr as $key => $value) {
         $last = substr(strrchr($key, '.'), 1);
         if (!$last) {
             $last = $key;
         }
         $node = $stdObj;
         foreach (explode('.', $key) as $key2) {
             if (!isset($node->{$key2})) {
                 $node->{$key2} = new \stdclass();
             }
             if ($key2 == $last) {
                 if (is_string($value)) {
                     if ($trim == true) {
                         $node->{$key2} = trim(htmlspecialchars(strip_tags($value)));
                     } else {
                         $node->{$key2} = $value;
                     }
                 } else {
                     $node->{$key2} = $value;
                 }
             } else {
                 $node = $node->{$key2};
             }
         }
     }
     return $stdObj;
 }
Exemplo n.º 2
0
 /**
  * return ngs current logined or not
  * user object
  *
  * @return userObject
  */
 public function getUser()
 {
     if ($this->user != null) {
         return $this->user;
     }
     try {
         if (!isset($_COOKIE["ut"])) {
             $user = new \hqv\security\users\GuestUser();
             $user->register();
             $this->setUser($user, true, true);
         } else {
             $user = $this->getUserByLevel($_COOKIE["ut"]);
         }
         $user->validate();
     } catch (InvalidUserException $ex) {
         $this->deleteUser($user);
         NGS()->redirect(substr($_SERVER["REQUEST_URI"], 1));
         exit;
     }
     if ($user->getLevel() != UserGroups::$GUEST) {
         $user->updateActivity();
         if ($user->getLevel() != UserGroups::$API) {
             $this->updateUserUniqueId($user);
         }
     }
     $this->user = $user;
     return $this->user;
 }
 public function __call($m, $a)
 {
     if (!isset($m)) {
         throw new \Exception("Fatal error: Call to undefined method stdObject::{$m}()");
     }
     if (\is_callable($this->{$m})) {
         return \call_user_func_array($this->{$m}, $a);
     }
     // retrieving the method type (setter or getter)
     $type = substr($m, 0, 3);
     // retrieving the field name
     $fieldName = NGS()->getNgsUtils()->lowerFirstLetter(substr($m, 3));
     if ($type == 'set') {
         if (count($a) == 1) {
             $this->{$fieldName} = $a[0];
         } else {
             $this->{$fieldName} = $a;
         }
     } else {
         if ($type == 'get') {
             if (isset($this->{$fieldName})) {
                 return $this->{$fieldName};
             }
             return null;
         }
     }
 }
 /**
  * Initializes DBMS pointer.
  */
 function __construct()
 {
     $host = NGS()->getConfig()->DB->solr->host;
     $user = NGS()->getConfig()->DB->solr->port;
     $path = NGS()->getConfig()->DB->solr->path;
     $this->dbms = new SolrDBMS($host, $user, $path, $this->getTableName());
 }
Exemplo n.º 5
0
/**
 * Smarty {math} function plugin
 *
 * Type:     function<br>
 * Name:     nest<br>
 * Purpose:  handle math computations in template
 * <br>
 *
 * @author   Levon Naghashyan <levon at naghashyan dot com>
 * @site http://naghashyan.com
 * @mail levon@naghashyan.com
 * @year 2012-2015
 * @version 2.0.0
 * @param array $params parameters
 * @param object $template template object
 * @return render template|null
 */
function smarty_function_nest($params, $template)
{
    if (!isset($params['ns'])) {
        trigger_error("nest: missing 'ns' parameter");
        return;
    }
    if (!$template->tpl_vars["ns"]) {
        $template->tpl_vars["ns"] = $template->smarty->smarty->tpl_vars["ns"];
    }
    $nsValue = $template->tpl_vars["ns"]->value;
    $pmValue = $template->tpl_vars["pm"]->value;
    $namespace = $nsValue["inc"][$params["ns"]]["namespace"];
    $include_file = $nsValue["inc"][$params["ns"]]["filename"];
    $_tpl = $template->smarty->createTemplate($include_file, null, null, $nsValue["inc"][$params["ns"]]["params"]);
    foreach ($template->tpl_vars as $key => $tplVars) {
        $_tpl->assign($key, $tplVars);
    }
    $_tpl->assign("ns", $nsValue["inc"][$params["ns"]]["params"]);
    $_tpl->assign("pm", $pmValue);
    if ($_tpl->mustCompile()) {
        $_tpl->compileTemplateSource();
    }
    //$_tpl->renderTemplate();
    $_output = $_tpl->display();
    if (NGS()->isJsFrameworkEnable() && !NGS()->getHttpUtils()->isAjaxRequest()) {
        $jsonParams = $nsValue["inc"][$params["ns"]]["jsonParam"];
        $parentLoad = $nsValue["inc"][$params["ns"]]["parent"];
        $jsString = '<script type="text/javascript">';
        $jsString .= 'NGS.setNestedLoad("' . $parentLoad . '", "' . $namespace . '", ' . json_encode($jsonParams) . ')';
        $jsString .= '</script>';
        $_output = $jsString . $_output;
    }
    return $_output;
}
Exemplo n.º 6
0
 public function service()
 {
     if (isset(NGS()->args()->lang) && in_array(NGS()->args()->lang, ['am', 'en', 'ru'])) {
         setcookie('ul', NGS()->args()->lang, time() + 60 * 60 * 24 * 365, "/", NGS()->getHttpUtils()->getHttpHost());
     }
     header("location: " . $_SERVER['HTTP_REFERER']);
     exit;
 }
Exemplo n.º 7
0
 /**
  * Return a thingie based on $paramie
  * @abstract
  * @access
  * @param boolean $paramie
  * @return integer|babyclass
  */
 public function __construct($msg, $code = false)
 {
     NGS()->getTemplateEngine()->assignJson("status", "error");
     if ($code != false) {
         NGS()->getTemplateEngine()->assignJson("code", $code);
     }
     NGS()->getTemplateEngine()->assignJson("msg", $msg);
     NGS()->getTemplateEngine()->display();
     exit;
 }
Exemplo n.º 8
0
 /**
  * Returns an singleton instance of class.
  *
  * @return
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$db_host = NGS()->getConfig()->DB_host;
         self::$db_user = NGS()->getConfig()->DB_user;
         self::$db_pass = NGS()->getConfig()->DB_pass;
         self::$db_name = NGS()->getConfig()->DB_name;
         self::$instance = new ImprovedDBMS();
     }
     return self::$instance;
 }
 public function streamFile($module, $file)
 {
     $filePath = realpath(NGS()->getPublicDir($module) . "/" . $file);
     if ($filePath == false) {
         throw new DebugException("File Not Found");
     }
     $options = array();
     if (NGS()->getEnvironment() != "production") {
         $options["cache"] = false;
     }
     $this->sendFile($filePath, $options);
 }
 public function __construct($msg = "", $code = -1, $params = array())
 {
     if (!NGS()->getHttpUtils()->isAjaxRequest()) {
         //throw  new DebugException();
     }
     NGS()->getTemplateEngine()->setHttpStatusCode(400);
     NGS()->getTemplateEngine()->assignJson("code", $code);
     NGS()->getTemplateEngine()->assignJson("msg", $msg);
     NGS()->getTemplateEngine()->assignJson("params", $params);
     NGS()->getTemplateEngine()->display();
     exit;
 }
 public function displayJsonInvalidError($msg, $redirectTo, $redirectToLoad)
 {
     NGS()->getTemplateEngine()->setHttpStatusCode(403);
     NGS()->getTemplateEngine()->assignJson("msg", $msg);
     if ($redirectTo != "") {
         NGS()->getTemplateEngine()->assignJson("redirect_to", $redirectTo);
     }
     if ($redirectToLoad != "") {
         NGS()->getTemplateEngine()->assignJson("redirect_to_load", $redirectToLoad);
     }
     NGS()->getTemplateEngine()->display();
 }
Exemplo n.º 12
0
 /**
  * Initializes DBMS pointer.
  */
 function __construct()
 {
     try {
         $host = NGS()->getConfig()->DB->mongo->host;
         $user = NGS()->getConfig()->DB->mongo->user;
         $pass = NGS()->getConfig()->DB->mongo->pass;
         $name = NGS()->getConfig()->DB->mongo->name;
         $this->dbms = \ngs\framework\dal\connectors\MongoDBMS::getInstance($host, $user, $pass, $name);
     } catch (\Exception $e) {
         throw new DebugException($e->getMessage(), "Mongo DB");
     }
 }
Exemplo n.º 13
0
 public function __construct($msg = "", $code = -1, $params = array())
 {
     if (!NGS()->getHttpUtils()->isAjaxRequest()) {
         throw NGS()->getNotFoundException();
     }
     NGS()->getTemplateEngine()->assignJson("status", "error");
     NGS()->getTemplateEngine()->assignJson("code", $code);
     NGS()->getTemplateEngine()->assignJson("msg", $msg);
     NGS()->getTemplateEngine()->assignJson("params", $params);
     NGS()->getTemplateEngine()->display();
     exit;
 }
Exemplo n.º 14
0
/**
 * Smarty {math} function plugin
 *
 * Type:     function<br>
 * Name:     nest<br>
 * Purpose:  helper function gor access global NGS Object
 * <br>
 *
 * @author   Levon Naghashyan <levon at naghashyan dot com>
 * @site http://naghashyan.com
 * @mail levon@naghashyan.com
 * @year 2015
 * @version 2.0.0
 * @param array $params parameters
 * @param object $template template object
 * @return render template|null
 */
function smarty_function_ngs($params, $template)
{
    if (!isset($params['cmd'])) {
        trigger_error("NGS: missing 'cmd' parameter");
        return;
    }
    $ns = "";
    if (isset($params['ns'])) {
        $ns = $params['ns'];
    }
    switch ($params['cmd']) {
        case 'get_js_out_dir':
            $protocol = false;
            if (isset($params['protocol']) && $params['protocol'] == true) {
                $protocol = true;
            }
            return NGS()->getPublicOutputHost($ns, $protocol) . "/js";
            break;
        case 'get_css_out_dir':
            $protocol = false;
            if (isset($params['protocol']) && $params['protocol'] == true) {
                $protocol = true;
            }
            return NGS()->getPublicOutputHost($ns, $protocol) . "/css";
            break;
        case 'get_less_out_dir':
            $protocol = false;
            if (isset($params['protocol']) && $params['protocol'] == true) {
                $protocol = true;
            }
            return NGS()->getPublicOutputHost($ns, $protocol) . "/less";
            break;
        case 'get_template_dir':
            return NGS()->getTemplateDir($ns);
            break;
        case 'get_static_path':
            if (isset(NGS()->getConfig()->static_path)) {
                return "//" . NGS()->getConfig()->static_path;
            }
            $protocol = false;
            if (isset($params['protocol']) && $params['protocol'] == true) {
                $protocol = true;
            }
            return NGS()->getHttpUtils()->getNgsStaticPath($ns, $protocol);
            break;
        case 'get_version':
            return NGS()->getVersion();
            break;
        default:
            break;
    }
}
Exemplo n.º 15
0
 /**
  * Initializes DBMS pointer.
  */
 function __construct()
 {
     $config = NGS()->getConfig();
     if (!isset($config->DB->mysql)) {
         $config = NGS()->getNgsConfig();
     }
     $host = NGS()->getNgsConfig()->DB->pgsql->host;
     $user = NGS()->getNgsConfig()->DB->pgsql->user;
     $pass = NGS()->getNgsConfig()->DB->pgsql->pass;
     $name = NGS()->getNgsConfig()->DB->pgsql->name;
     $port = NGS()->getNgsConfig()->DB->pgsql->port;
     $this->dbms = \ngs\framework\dal\connectors\PgsqlPDO::getInstance($host, $user, $pass, $name, $port);
 }
Exemplo n.º 16
0
 public function service()
 {
     $startDate = NGS()->args()->startDate;
     $endDate = NGS()->args()->endDate;
     $partnerId = intval(NGS()->args()->partner_id);
     $where = ['cancelled', '=', 0, 'and', 'order_date', '>=', "'{$startDate}'", 'and', 'order_date', '<=', "'{$endDate} 23:59:59'"];
     $partnerDto = null;
     if ($partnerId > 0) {
         $partnerDto = \crm\managers\PartnerManager::getInstance()->selectByPK($partnerId);
         $where = array_merge($where, ['and', 'partner_id', '=', $partnerId]);
     }
     $rows = \crm\managers\SaleOrderManager::getInstance()->getSaleOrdersFull($where, 'order_date', "DESC");
     $this->exportCsv($rows, $startDate, $endDate, $partnerDto);
 }
Exemplo n.º 17
0
 /**
  * Return a thingie based on $paramie
  * @abstract
  * @access
  * @param boolean $paramie
  * @return integer|babyclass
  */
 public function __construct($msg, $type = false)
 {
     if (NGS()->getEnvironment() == "production") {
         return;
     }
     if ($msg != "") {
         $this->message = $msg;
     }
     $trace = $this->getTrace();
     header('Content-Type: application/json; charset=utf-8');
     header("HTTP/1.0 403 Forbidden");
     echo json_encode(array("type" => $type, "msg" => $this->getMessage(), "_tmst_" => time()));
     exit;
 }
Exemplo n.º 18
0
 /**
  * Return a thingie based on $paramie
  * @abstract
  * @access
  * @param boolean $paramie
  * @return integer|babyclass
  */
 public function __construct($msg, $code, $params)
 {
     if (NGS()->getEnvironment() == "production") {
         $this->message = $msg;
         return;
     }
     if ($msg != "") {
         $this->message = $msg;
     }
     $trace = $this->getTrace();
     header('Content-Type: application/json; charset=utf-8');
     header("HTTP/1.0 403 Forbidden");
     echo json_encode(array("NGSDEBUGMSG" => $this->getMessage(), "file" => $trace[0]["file"], "line" => $trace[0]["line"], "_tmst_" => time()));
     exit;
 }
Exemplo n.º 19
0
 /**
  * Initializes DBMS pointer.
  */
 function __construct()
 {
     $config = NGS()->getConfig();
     if (!isset($config->DB->mysql)) {
         $config = NGS()->getNgsConfig();
     }
     $usePdo = true;
     if (isset(NGS()->getConfig()->DB->mysql->driver) && NGS()->getConfig()->DB->mysql->driver == "mysqli") {
         $usePdo = false;
     }
     if ($usePdo) {
         $host = NGS()->getConfig()->DB->mysql->host;
         $user = NGS()->getConfig()->DB->mysql->user;
         $pass = NGS()->getConfig()->DB->mysql->pass;
         $name = NGS()->getConfig()->DB->mysql->name;
         $this->dbms = \ngs\framework\dal\connectors\MysqlPDO::getInstance($host, $user, $pass, $name);
     }
 }
Exemplo n.º 20
0
 public function service()
 {
     if (!isset(NGS()->args()->pasphrase) || NGS()->args()->pasphrase != 'P@rs1985') {
         return false;
     }
     if (isset(NGS()->args()->row_id)) {
         $rowId = NGS()->args()->row_id;
     } else {
         $rowId = 0;
     }
     if (isset(NGS()->args()->em_row_id)) {
         $emRowId = NGS()->args()->em_row_id;
     } else {
         $emRowId = 0;
     }
     $rows = \hqv\managers\VoterDataManager::getInstance()->selectAdvance('*', ['id', '>', "'{$rowId}'"], ['id'], 'ASC');
     $emrows = \hqv\managers\EmergencyPhoneNumberManager::getInstance()->selectAdvance('*', ['id', '>', "'{$emRowId}'"], ['id'], 'ASC');
     $this->addParam('data', $rows);
     $this->addParam('em_data', $emrows);
 }
 /**
  * set url nestedLoads
  *
  * @return void
  */
 private function setNestedRoutes($nestedLoads, $package)
 {
     foreach ($nestedLoads as $key => $value) {
         if (isset($value["namespace"])) {
             $actionNS = $value["namespace"];
         } else {
             $actionNS = NGS()->getModulesRoutesEngine()->getModuleNS();
         }
         $value["action"] = $actionNS . "." . $value["action"];
         $nestedLoads[$key]["action"] = $value["action"];
         if (isset($value["nestedLoad"]) && is_array($value["nestedLoad"])) {
             $this->setNestedRoutes($value["nestedLoad"], $actionNS . "." . $value["action"]);
             unset($nestedLoads[$key]["nestedLoad"]);
         }
     }
     $this->nestedRoutes[$package] = $nestedLoads;
 }
Exemplo n.º 22
0
 protected function getBuilderFile()
 {
     return realpath(NGS()->getLessDir() . "/builder.json");
 }
Exemplo n.º 23
0
 public function getSmartyConfigDir()
 {
     $configDir = "config";
     if (defined("SMARTY_CONFIG_DIR")) {
         $configDir = SMARTY_CONFIG_DIR;
     }
     return NGS()->getTemplateDir() . "/" . $configDir;
 }
 /**
  * encode dto to array
  *
  * @param object $dto
  *
  * @return json object
  */
 public function dtoToArray($dto)
 {
     $dto_fields = array_values($dto->getMapArray());
     $db_fields = array_keys($dto->getMapArray());
     for ($i = 0; $i < count($dto_fields); $i++) {
         $functionName = "get" . ucfirst($dto_fields[$i]);
         $val = $dto->{$functionName}();
         if ($val != null) {
             if (NGS()->isJson($val)) {
                 $params[$db_fields[$i]] = json_decode($val, true);
                 continue;
             }
             $params[$db_fields[$i]] = $val;
         }
     }
     return $params;
 }
Exemplo n.º 25
0
 /**
  * this method calculate dir conencted with module
  *
  * @return String rootDir
  */
 public function getRootDir($ns = "")
 {
     if ($ns == NGS()->getDefinedValue("FRAMEWORK_NS") || $ns == "" && $this->getDefaultNS() == $this->getModuleNS() || $this->getDefaultNS() == $ns) {
         return NGS()->getDefinedValue("NGS_ROOT");
     }
     if ($ns == "") {
         return realpath(NGS()->getDefinedValue("NGS_ROOT") . "/" . NGS()->getDefinedValue("MODULES_DIR") . "/" . $this->getModuleNS());
     }
     return realpath(NGS()->getDefinedValue("NGS_ROOT") . "/" . NGS()->getDefinedValue("MODULES_DIR") . "/" . $ns);
 }
 public function _getHttpHost($main = false)
 {
     $ngsHost = null;
     if (NGS()->getDefinedValue("HTTP_HOST")) {
         $ngsHost = NGS()->getDefinedValue("HTTP_HOST");
     } elseif (isset($_SERVER["HTTP_HOST"])) {
         $ngsHost = $_SERVER["HTTP_HOST"];
     }
     return $ngsHost;
 }
Exemplo n.º 27
0
<?php

if (php_sapi_name() == "cli") {
    defined('__DIR__') or define('__DIR__', dirname(__FILE__));
    chdir(__DIR__ . "/");
}
require_once "../vendor/autoload.php";
//require_once ("../classes/framework/NGS.class.php");
$dispatcher = new ngs\Dispatcher();
NGS()->setDispatcher($dispatcher);
$dispatcher->dispatch();
 public function getSmartyConfigDir()
 {
     return NGS()->getTemplateDir() . "/" . NGS()->getDefinedValue("SMARTY_CONFIG_DIR");
 }
Exemplo n.º 29
0
<?php

/**
 * default constants
 * in this file should be store all constants
 *
 * @author Levon Naghashyan
 * @site http://naghashyan.com
 * @mail levon@naghashyan.com
 * @year 2015
 * @version 6.0
 * @copyright Naghashyan Solutions LLC
 *
 */
NGS()->define("SESSION_MANAGER", 'admin\\managers\\SessionManager');
Exemplo n.º 30
0
 public function getTemplate()
 {
     return NGS()->getTemplateDir() . "/main/index.tpl";
 }