function SessionGc($maxExpireTime)
 {
     SysLog::Log('Garbage collecting...', 'Session');
     $result = $this->Execute($this->mSqlQueries['gc_data'], array(time(), $maxExpireTime));
     if (!$result) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 function test($test_value)
 {
     if (trim($test_value) == '') {
         SysLog::Log('RuleRequired: Field ' . $this->mElementName . ' harus diisi', 'formhelper');
         $this->setError('Field ' . $this->mElementName . ' harus diisi');
         return false;
     } else {
         SysLog::Log('RuleRequired: Field ' . $this->mElementName . ' is not empty', 'formhelper');
         return true;
     }
 }
 function test($test_value)
 {
     SysLog::Log('TypeEmail: testing TestValue: "' . $test_value . '"', 'formhelper');
     if (filter_var($test_value, FILTER_VALIDATE_EMAIL) === FALSE) {
         SysLog::Log('TypeEmail: Field ' . $this->mElementName . ' harus berupa alamat email', 'formhelper');
         $this->setError('Field ' . $this->mElementName . ' harus berupa alamat email');
         return false;
     } else {
         SysLog::Log('TypeEmail: Field ' . $this->mElementName . ' adalah alamat email', 'formhelper');
         return true;
     }
 }
    function GetFormHelperManagerJs($standalone = true)
    {
        $js1 = "";
        if (!empty($this->mFormHelpers)) {
            $js_formhelper .= <<<_FORM_HELPER_
   <script type="text/javascript">
      /* must preceed behaviour Library to get the desired effect: add validation selector and then let the rest handled by the simple_validator */
      function GtfwFormHelper() {
_FORM_HELPER_;
            //
            foreach ($this->mFormHelpers as $item) {
                $js_formhelper .= "\n" . $item->getJsCode() . "\n";
            }
            $js_formhelper .= <<<_FORM_HELPER_
      }
_FORM_HELPER_;
            if ($standalone) {
                $js_formhelper .= "\nFormHelperManager.addLoadEvent(GtfwFormHelper); /* apply */";
                // use loadevent
                SysLog::Log('Preparing formHelper for fullpage request', 'formhelpermanager');
            } else {
                $js_formhelper .= "\nGtfwFormHelper(); /* run immediately */";
                // run immediately
                SysLog::Log('Preparing formHelper for component requiremnt', 'formhelpermanager');
            }
            $js_formhelper .= '</script>';
        } else {
            SysLog::Log('No FormHelper set', 'formhelpermanager');
            $js_formhelper = '';
        }
        if ($standalone) {
            $js = <<<_RAW_HEAD_
   <script type="text/javascript" src="js/FormHelper.js"></script>
_RAW_HEAD_;
            $js1 .= <<<_RAW_HEAD_
   <script type="text/javascript" src="js/behaviour.js"></script>
   <script type="text/javascript" src="js/balloon.js"></script>
   <script type="text/javascript" src="js/simple_validator.js"></script>
_RAW_HEAD_;
            // load available js rules
            foreach (FormHelper::$JsRuleFiles as $item) {
                SysLog::Log('Loading JsRulesFiles: ' . $item . '.js', 'formhelpermanager');
                $js1 .= <<<_RAW_HEAD_
   <script type="text/javascript" src="js/formhelper_rules/{$item}.js"></script>
_RAW_HEAD_;
            }
        }
        if ($standalone) {
            return $js . $js_formhelper . $js1;
        } else {
            return $js_formhelper;
        }
    }
 final function validate()
 {
     $test_value = $this->mTestValue;
     SysLog::Log($this->getRuleName() . ': testing TestValue: "' . print_r($test_value, true) . '"', 'formhelper');
     if (is_array($test_value)) {
         foreach ($test_value as $key => $value) {
             if (!$this->test($value)) {
                 return false;
             }
         }
         return true;
     } else {
         return $this->test($test_value);
     }
 }
 function test($test_value)
 {
     $regexp = '/\\d+/';
     if ($test_value != '') {
         SysLog::Log('TypeNumber(' . $this->mElementName . '): Field is not empty: ' . $test_value, 'formhelper');
         if (!preg_match($regexp, $test_value, $matches)) {
             $this->setError('Field ' . $this->mElementName . ' harus berupa angka');
             return false;
         } else {
             return true;
         }
     } else {
         SysLog::Log('TypeNumber(' . $this->mElementName . '): Field is empty', 'formhelper');
         return true;
     }
 }
 /**
  * this method offers a default result caching technique,
  * but you can override this method as needed when the default isn't satisfying
  * @param string sql, within the form for sprintf
  * @param array params
  */
 public function OpenCache($sql, $params, $varMarker = NULL)
 {
     $sql_parsed = $this->GetCacheIdentifier($sql, $params);
     if (($result = $this->GetCache($sql_parsed)) === FALSE) {
         SysLog::Log('cache MISS for ' . $sql, 'cache');
         // cache miss
         $result = $this->Open($sql, $params, $varMarker);
         if ($result !== FALSE) {
             $this->CacheResult($sql_parsed, $result);
         }
         // cache valid only result
     } else {
         SysLog::Log('cache HIT for ' . $sql, 'cache');
     }
     SysLog::Log("OpenCache returns:\n" . print_r($result, true), 'cache');
     return $result;
 }
 function GetUserGroup()
 {
     // fecth user groups
     $this->mUserGroup = array();
     $result = $this->Open($this->mSqlQueries['get_user_group'], array($this->mUserId, $this->mApplicationId));
     if ($result) {
         foreach ($result as $row => $val) {
             $this->mUserGroup[$val['GroupId']] = $val['GroupName'];
         }
     }
     // determine default user group & unit id
     $result = $this->Open($this->mSqlQueries['get_default_user_group'], array($this->mUserId, $this->mApplicationId));
     $this->mDefaultUserGroupId = $result[0]['GroupId'];
     $this->mDefaultUnitId = $result[0]['UnitId'];
     SysLog::Log('Got default GUID: ' . $this->mDefaultUserGroupId, get_class());
     if (!isset($_SESSION['active_user_group_id'])) {
         SysLog::Log('SetActiveUserGroupId to DefaultGUID: ' . $this->mDefaultUserGroupId, get_class());
         $_SESSION['active_user_group_id'] = $this->mDefaultUserGroupId;
     }
 }
 function GetUserGroup()
 {
     // fecth user groups
     $this->mUserGroup = array();
     if (Configuration::Instance()->GetValue('app_version', 'version') == 3) {
         $sql = $this->mSqlQueries['get_user_group'];
     } else {
         $sql = $this->mSqlQueries['get_user_group_2'];
     }
     $result = $this->Open($sql, array($this->mUserName, $this->mApplicationId));
     if ($result) {
         foreach ($result as $row => $val) {
             $this->mUserGroup[$val['GroupId']] = $val['GroupName'];
         }
     }
     //added by choirul no need.
     //$this->mActiveUserGroupId = $result[0]['GroupId'];
     // determine default user group & unit id
     if (Configuration::Instance()->GetValue('app_version', 'version') == 3) {
         $sql = $this->mSqlQueries['get_default_user_group'];
     } else {
         $sql = $this->mSqlQueries['get_default_user_group_2'];
     }
     $result = $this->Open($sql, array($this->mUserName, $this->mApplicationId));
     $this->mDefaultUserGroupId = $result[0]['GroupId'];
     $this->mDefaultUnitId = $result[0]['UnitId'];
     SysLog::Log('Got default GUID: ' . $this->mDefaultUserGroupId, get_class());
     if (!isset($_SESSION['active_user_group_id'])) {
         SysLog::Log('SetActiveUserGroupId to DefaultGUID: ' . $this->mDefaultUserGroupId, get_class());
         $_SESSION['active_user_group_id'] = $this->mDefaultUserGroupId;
         #$_SESSION['active_user_group_id'] = $this->mActiveUserGroupId;
     } else {
         //added by choirul
         $_SESSION['active_user_group_id'] = $this->mActiveUserGroupId;
     }
 }
 public function Open($sql, $params, $varMarker = NULL)
 {
     if ($this->mrDbConnection->debug) {
         SysLog::Log(get_class() . '::Open ' . $sql, get_class());
     }
     $this->mDebugMessage = '';
     if ($this->mrDbConnection->debug) {
         ob_start();
     }
     if (!empty($varMarker)) {
         $sql_parsed = $this->GetParsedSqlEx($sql, $params, $varMarker);
     } else {
         $sql_parsed = $this->GetParsedSql($sql, $params);
     }
     //print "<pre>".$sql_parsed."</pre>";
     $rs = $this->mrDbConnection->Execute($sql_parsed);
     if ($this->mrDbConnection->debug) {
         SysLog::Instance()->addQueryLog(strip_tags(ob_get_contents()));
         //$this->mArrDebugMessage[] = strip_tags(ob_get_contents());
         SysLog::Log('DebugMessage: ' . $this->mDebugMessage, get_class());
         ob_end_clean();
     }
     if ($rs) {
         $result = $rs->GetArray();
         return $result;
     } else {
         return FALSE;
     }
 }
 function registerFormHelper($objFormHelper)
 {
     SysLog::Log('new formhelper registered: ' . $objFormHelper->mFormName, 'formhelper');
     $this->mFormHelpers[] = $objFormHelper;
 }
 private function RegisterServiceByWsdlConfig($wsdlConfig = NULL)
 {
     if (!$wsdlConfig) {
         return FALSE;
     }
     if ($wsdlConfig['location'] == 'remote') {
         if ($this->mUseWsdlCache) {
             $wsdl_cache = new wsdlcache($this->mWsdlCachePath, $this->mWsdlCacheLifetime);
         }
         // try to get from cache first...
         if ($wsdl_cache) {
             $wsdl = $wsdl_cache->get($wsdlConfig['address']);
         }
         // cache hit? if not, get it from server and put to cache
         if (!$wsdl) {
             $wsdl = new wsdl($wsdlConfig['address'], $wsdlConfig['proxy_host'], $wsdlConfig['proxy_port'], $wsdlConfig['proxy_user'], $wsdlConfig['proxy_pass']);
             $error = $wsdl->getError();
             if ($error) {
                 SysLog::Log('An error occured when fecthing wsdl from ' . $wsdlConfig['address'] . ': ' . $error, 'wsdlgenerator');
             }
             if ($wsdl_cache && !$error) {
                 $wsdl_cache->put($wsdl);
             }
         }
         if (!$error) {
             $this->RegisterServiceByWsdlObject($wsdl);
         }
     } elseif ($wsdlConfig['location'] == 'local') {
         $this->RegisterServiceBySoapClass($wsdlConfig);
     }
 }
 /**
  * Processes all files and returns array containing all processed files,
  * ie: processable and non processable
  * this is a default action that can be used. As requirement progress,
  * we'll see how we should handle things
  * @param $final_destination_folder string
  * @return array
  */
 function ProcessFiles($final_destination_folder)
 {
     $files = $this->GetFiles();
     SysLog::Log('Processing ' . count($files) . ' uploads', 'uploadhelper');
     foreach ($files as $file) {
         SysLog::Log('Processing upload: ' . $file['name'], 'uploadhelper');
         if ($file['compliance']) {
             SysLog::Log('Moving upload: ' . $file['name'], 'uploadhelper');
             $fname = $this->GetFileNameFor($file['name']);
             move_uploaded_file($file['tmp_name'], $final_destination_folder . '/' . $fname);
             $success[] = $file['name'];
         } else {
             $failed[] = $file['name'];
         }
     }
     return array('success' => $success, 'failed' => $failed);
 }
 function Dispatch()
 {
     // send header first
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     if (isset($_SERVER['HTTP_X_GTFWMODULETYPE'])) {
         $type = $_SERVER['HTTP_X_GTFWMODULETYPE'];
     } else {
         $type = null;
     }
     //SysLog::Log("HEADER: " .$_SERVER['X-GtfwModuleType'], 'dispatcher');
     SysLog::Log("HEADER: " . $type, 'dispatcher');
     $module = '';
     $submodule = '';
     $action = '';
     $type = '';
     if (Configuration::Instance()->GetValue('application', 'url_type') == 'Long') {
         if (isset($_REQUEST['mod']) && isset($_REQUEST['sub']) && isset($_REQUEST['act']) && isset($_REQUEST['typ']) || $_REQUEST['typ'] == "rest") {
             // hack for requests/responses that don't need obfuscation
             if (in_array($_REQUEST['typ'], Configuration::Instance()->GetValue('application', 'url_obfuscator_exception'))) {
                 Configuration::Instance()->RegisterHook($this);
             }
             //
             $module = $this->Decrypt($_REQUEST['mod']);
             $submodule = $this->Decrypt($_REQUEST['sub']);
             $action = $this->Decrypt($_REQUEST['act']);
             $type = $this->Decrypt($_REQUEST['typ']);
             SysLog::Log("Long URL \$_REQUEST", 'dispatcher');
         } else {
             SysLog::Log("No \$_REQUEST set for Long URL {$_REQUEST['mod']}", 'dispatcher');
         }
     } elseif (Configuration::Instance()->GetValue('application', 'url_type') == 'Short') {
         if (isset($_REQUEST['mid'])) {
             $module_id = $this->Decrypt($_REQUEST['mid']);
             $request_translated = $this->TranslateRequestToLong($module_id);
             if (is_array($request_translated)) {
                 $module = $request_translated[0];
                 $submodule = $request_translated[1];
                 $action = $request_translated[2];
                 $type = $request_translated[3];
             }
         }
     } elseif (Configuration::Instance()->GetValue('application', 'url_type') == 'Path') {
         list(, , $module, , $submodule, , $action, , $type, ) = explode('/', $_SERVER['PATH_INFO']);
         $module = $this->Decrypt($module);
         $submodule = $this->Decrypt($submodule);
         $action = $this->Decrypt($action);
         $type = $this->Decrypt($type);
     }
     SysLog::Log("Translated request: {$module}/{$submodule}/{$action}/{$type} from " . print_r($_REQUEST, true), 'dispatcher');
     // default
     if ($module == '' && $submodule == '' && $action == '' && $type == '') {
         $module = Configuration::Instance()->GetValue('application', 'default_module');
         $submodule = Configuration::Instance()->GetValue('application', 'default_submodule');
         $action = Configuration::Instance()->GetValue('application', 'default_action');
         $type = Configuration::Instance()->GetValue('application', 'default_type');
     }
     // hack to overide any typ specified before.
     if (isset($_COOKIE['GtfwModuleType'])) {
         $type = $_COOKIE['GtfwModuleType']->Raw();
         // delete the cookie
         setcookie('GtfwModuleType', '', mktime(5, 0, 0, 7, 26, 1997));
     }
     if (isset($_SERVER['HTTP_X_GTFWMODULETYPE'])) {
         $type = $_SERVER['HTTP_X_GTFWMODULETYPE'];
     }
     SysLog::Log("Final request: {$module}/{$submodule}/{$action}/{$type}", 'dispatcher');
     $this->mModule = $module;
     $this->mSubModule = $submodule;
     $this->mAction = $action;
     $this->mType = $type;
     if (class_exists('ServiceSecurity')) {
         if (ServiceSecurity::Instance()->AllowedToAccess($module, $submodule, $action, $type)) {
             list($file_path, $class_name) = $this->GetModule($module, $submodule, $action, $type);
             if (FALSE === $file_path) {
                 $dbMsg = SysLog::Instance()->getAllError();
                 if (!empty($dbMsg)) {
                     echo "<pre>";
                     for ($i = 0; $i < count($dbMsg); $i++) {
                         echo $dbMsg[$i];
                     }
                     echo "</pre>";
                 }
                 die('Service Not Found');
             } else {
                 $this->DispacherSend($type, $file_path, $class_name);
             }
         }
     } else {
         SysLog::Instance()->log("Security::Instance()->AllowedToAccess({$module}, {$submodule}, {$action}, {$type})", 'sanitizer');
         if (Security::Instance()->AllowedToAccess($module, $submodule, $action, $type)) {
             list($file_path, $class_name) = $this->GetModule($module, $submodule, $action, $type);
             if (FALSE === $file_path) {
                 $this->ModuleNotFound();
             } else {
                 if (!Security::Instance()->IsProtocolCheckPassed($module, $submodule, $action, $type)) {
                     // redirect to https or http
                     $url = Configuration::Instance()->GetValue('application', 'baseaddress');
                     if (!isset($_SERVER['HTTPS'])) {
                         $url = preg_replace('/^http:/', 'https:', $url);
                     }
                     $url .= $this->GetUrl($module, $submodule, $action, $type);
                     Redirector::RedirectToUrl($url);
                 } else {
                     $this->DispacherSend($type, $file_path, $class_name);
                 }
             }
         } else {
             Security::Instance()->RequestDenied();
         }
     }
 }
 private function RunQuery($obj, $sql, $params, $id)
 {
     preg_match("/^([^\\(\\)]*)\\(([^\\(\\)]*)\\)\$/is", $sql, $parts);
     $sql_command = trim($parts[1]);
     $params_count = trim($parts[2]) != '' ? count(explode(',', $parts[2])) : 0;
     $params_text = '';
     for ($i = 0; $i < $params_count; $i++) {
         $params_text .= "\$params[{$i}], ";
     }
     $params_text = substr($params_text, 0, -2);
     $function_parsed = $sql_command . '(' . $params_text . ')';
     if (empty($sql_command)) {
         SysLog::Log('Unable to understand "' . $sql_command . '". This command resulted in empty sql_command', 'soapproxy');
         $obj->fault = TRUE;
         $obj->setError('Unable to understand "' . $sql_command . '". This command resulted in empty sql_command');
         return false;
     }
     try {
         $reflect = new ReflectionMethod(get_class($obj), $sql_command);
         foreach ($reflect->getParameters() as $i => $param) {
             $foo .= sprintf("\n-- Parameter #%d: %s {\n" . "  Class: %s\n" . "  Allows NULL: %s\n" . "  Passed to by reference: %s\n" . "  Is optional?: %s\n" . "}\n", $i, $param->getName(), var_export($param->getClass(), 1), var_export($param->allowsNull(), 1), var_export($param->isPassedByReference(), 1), $param->isOptional() ? 'yes' : 'no');
             $doclit_param[] = "'{$param->getName()}' => '{$params[$i]}'";
         }
         SysLog::Log("Calling {$sql_command}\n" . print_r($params, true) . "\n" . $foo, 'soapproxy');
         /* end debug */
         $obj->updateCookies($_SESSION['soap_cookies'][$id]);
         $obj->checkCookies();
         $result = FALSE;
         if (method_exists($obj, $sql_command)) {
             // doc/lit support
             if ($obj->operations[$sql_command]['style'] == 'document' && $obj->operations[$sql_command]['input']['use'] == 'literal') {
                 $result = call_user_func_array(array(&$obj, $sql_command), array('parameters' => $params));
                 SysLog::Log("Using doc/lit \$obj->{$sql_command}( array( 'parameters' =>" . join($doclit_param, ', ') . " ))", 'soapproxy');
             } else {
                 $result = call_user_func_array(array(&$obj, $sql_command), $params);
                 SysLog::Log("Using rpc/enc \$obj->{$function_parsed}", 'soapproxy');
             }
             $_SESSION['soap_cookies'][$id] = $obj->getCookies();
         } else {
             SysLog::Log('Request to undefined service ' . $sql_command, 'soapproxy');
             $obj->fault = TRUE;
             $obj->setError('Request to undefined service ' . $sql_command);
         }
     } catch (ReflectionException $e) {
         SysLog::Log('Service "' . $sql_command . '" not found!', 'soapproxy');
         $obj->fault = TRUE;
         $obj->setError('Service "' . $sql_command . '" not found!');
         return false;
     }
     SysLog::Log("Returning:\n" . print_r($result, true), 'soapproxy');
     return $result;
 }
 /**
  * validate rule subscribers
  * @param bool $force_revalidation Always re-validate flag
  * @return boolean
  */
 function isValid($force_revalidation = false)
 {
     if (!$this->mHadBeenValidated || $force_revalidation) {
         $this->validate();
     }
     SysLog::Log('FormHelper::isValid: mError count=' . count($this->mError), 'formhelper');
     return empty($this->mError);
 }
 public function SerializeParams()
 {
     SysLog::Log('Serializing parameters...', 'BgProcess');
     $this->mSerializedParams = serialize(func_get_args());
 }
 public function Database($connectionNumber = 0)
 {
     SysLog::Instance()->log("creating Database using connection: #{$connectionNumber}", "database");
     $db_conn = Configuration::Instance()->GetValue('application', 'db_conn');
     $db_conn = $db_conn[$connectionNumber];
     // remind me
     if (!$db_conn) {
         die('Can\'t find database configuration of index ' . $connectionNumber . '. Please, configure it properly in application.conf.php.');
     }
     if ($this->mDbConfig != NULL) {
         foreach ($this->mDbConfig as $key => $value) {
             $db_conn[$key] = $value;
         }
     }
     $this->mDbConfig = $db_conn;
     // makes connection id as part of db config
     $this->mDbConfig['connection_id'] = md5(serialize($this->mDbConfig));
     //
     $db_driv_class = str_replace(' ', '', ucwords(str_replace('_', ' ', $this->mDbConfig['db_driv'])));
     if (!isset($GLOBALS['db'][$this->mDbConfig['connection_id']])) {
         // not connected yet
         require_once Configuration::Instance()->GetValue('application', 'gtfw_base') . 'main/lib/gtfw/database/database_engine/' . $this->mDbConfig['db_driv'] . '/' . $db_driv_class . 'DatabaseEngine.class.php';
         if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
             SysLog::Instance()->log('$this->mrDbEngine' . " = new {$db_driv_class}DatabaseEngine(\$this->mDbConfig);", 'database');
             SysLog::Instance()->log('$this->mDbConfig):' . print_r($this->mDbConfig, true), 'database');
             eval('$this->mrDbEngine' . " = new {$db_driv_class}DatabaseEngine(\$this->mDbConfig);");
         } else {
             SysLog::Instance()->log('$this->mrDbEngine' . " = new {$db_driv_class}DatabaseEngine(\$this->mDbConfig);", 'database');
             SysLog::Instance()->log('$this->mDbConfig):' . print_r($this->mDbConfig, true), 'database');
             eval('$this->mrDbEngine' . " = new {$db_driv_class}DatabaseEngine(\$this->mDbConfig);");
         }
         if (!$this->mrDbEngine) {
             SysLog::Log('mrDbEngine is not available, how come?!', 'database');
             die('mrDbEngine is not available!!!');
         }
         if ($this->Connect()) {
             SysLog::Log('Connected using dbid #' . $this->mDbConfig['connection_id'], 'database');
             $GLOBALS['db'][$this->mDbConfig['connection_id']] = $this->mrDbEngine;
             if ($connectionNumber != 0) {
                 $this->addConn = true;
             }
         } else {
             //die('Can\'t connect to database!');
             SysLog::Instance()->log('Can\'t connect to database!', 'database');
             //die($this->GetLastError());
             if ($connectionNumber == 0) {
                 die('Can\'t connect to database number ' . $connectionNumber);
             } else {
                 $this->addConn = false;
             }
         }
     } else {
         // connected already
         SysLog::Log('Already connected using dbid #' . $this->mDbConfig['connection_id'], 'database');
         $this->mrDbEngine = $GLOBALS['db'][$this->mDbConfig['connection_id']];
     }
     // new and old instance have to load sql file!
     $this->LoadSql();
 }