public function useModel($name = null)
 {
     if ($name) {
         if (strstr($name, '/')) {
             $names = explode('/', $name);
             $modelpath = $names[0] . _DS_ . 'model' . _DS_ . $names[1];
             $modelname = $names[1] . 'Model';
             $modelfile = $modelpath . 'Model.php';
         } else {
             $modelpath = $name . 'Model';
             $modelname = $name . 'Model';
             $modelfile = _MODEL_DIR_ . $modelpath . '.php';
         }
     } else {
         $modelpath = str_replace('Controller', '', get_class($this)) . 'Model';
         $modelname = $modelpath;
         $modelfile = _MODEL_DIR_ . $modelpath . '.php';
     }
     if (file_exists(_SYS_DIR_ . $modelfile)) {
         include_once _SYS_DIR_ . $modelfile;
         return $model = new $modelname($this->db);
     } else {
         q4mSystem::haltOnError('The file is not found', $modelfile, __FILE__, __LINE__);
         exit;
     }
 }
예제 #2
0
 public function validate($file = '', $rule = '', $encode = 'utf8', $VAL = null)
 {
     q4mController::useHelper('validator');
     if ($file == '') {
         $file = str_replace('Model', '', get_class($this)) . 'Rules.php';
     }
     if ($rule == '') {
         $rule = str_replace('Model', '', get_class($this));
     }
     if (file_exists(_SYS_DIR_ . _SETTINGS_DIR_ . $file . 'Rules.php')) {
         include_once _SETTINGS_DIR_ . $file . 'Rules.php';
         if (!isset(${$rule}) || !count(${$rule})) {
             q4mSystem::haltOnError('The requested rule "' . ${$rule} . '" is empty in ', _SYS_DIR_ . _SETTINGS_DIR_ . $file . 'Rules.php', __FILE__, __LINE__);
             exit;
         }
     } else {
         q4mSystem::haltOnError('The file is not found', _SYS_DIR_ . _SETTINGS_DIR_ . $file . 'Rules.php', __FILE__, __LINE__);
         exit;
     }
     $rules = ${$rule};
     $vc = new validator($rules, $encode, $VAL);
     if (count($vc->RULES)) {
         foreach ($vc->RULES as $key => $SV) {
             $vc->validate($key);
         }
     }
     if (count($vc->ERRORS)) {
         return $vc->ERRORS;
     } else {
         return false;
     }
 }
 public function query($string, $values = null)
 {
     $stmt = $this->dbLink->prepare($string);
     $stmt->setFetchMode(PDO::FETCH_ASSOC);
     try {
         $stmt->execute($values);
         return $stmt;
     } catch (PDOException $e) {
         q4mSystem::haltOnError('Query error', get_class($this) . $e->getMessage(), __FILE__, __LINE__);
         exit;
     }
 }
 public function logOut(&$view)
 {
     $_SESSION[_SESS_MY_KEY_] = array();
     if (!file_exists(_SYS_DIR_ . _MY_DIR_ . 'auth_inc.php')) {
         q4mSystem::haltOnError('The file is not found', _SYS_DIR_ . _MY_DIR_ . 'auth_inc.php', __FILE__, __LINE__);
         exit;
     }
     include_once _MY_DIR_ . 'auth_inc.php';
     if (!file_exists(_SYS_DIR_ . _HELPER_DIR_ . 'class.' . _AUTH_TYPE_ . '.php')) {
         q4mSystem::haltOnError('The file is not found', _SYS_DIR_ . _HELPER_DIR_ . 'class.' . _AUTH_TYPE_ . '.php', __FILE__, __LINE__);
         exit;
     }
     include_once _HELPER_DIR_ . 'class.' . _AUTH_TYPE_ . '.php';
     $authclass = _AUTH_TYPE_;
     $authmodel = new $authclass();
     $authmodel->showLogin($view);
 }
예제 #5
0
 /**
  * Breaks donwn the REQUEST_URI and derives names of a controller, a method and its parameter.
  * If not specified, the defaults are: indexController, index() and an empty parameter.
  * GET is ignored here.  It's handled as usual php $_GET.
  * After setting these names, the method of the controller is triggered.
  * @param none
  * @return none
  * Should be called as a static function from q4m_index.php
  */
 public function kaboom()
 {
     $command = str_replace(dirname($_SERVER['PHP_SELF']) . "/", '', $_SERVER['REQUEST_URI']);
     $command = str_replace('?' . $_SERVER['QUERY_STRING'], '', $command);
     if (!strlen($command)) {
         $controller = 'indexController';
         $method = 'index';
     } else {
         $command = preg_replace("/^\\//", "", $command);
         $commands = explode('/', $command);
         if (isset($commands[0]) && strlen($commands[0])) {
             $controller = preg_replace("/(.+)(\\.[^.]+\$)/", "\$1", $commands[0]);
             $controller = $controller . 'Controller';
         } else {
             $controller = 'indexController';
         }
         if (isset($commands[1]) && strlen($commands[1])) {
             $method = preg_replace("/(.+)(\\.[^.]+\$)/", "\$1", $commands[1]);
         } else {
             $method = 'index';
         }
     }
     if (file_exists(_CONTROLLER_DIR_ . $controller . '.php')) {
         include_once _CONTROLLER_DIR_ . $controller . '.php';
         $controllerObj = new $controller();
         $controllerObj->setDefaultMethod($method);
         $controllerObj->setTemplate($method);
         if (isset($commands[2])) {
             $controllerObj->action($commands[2]);
         } else {
             $controllerObj->action();
         }
     } else {
         q4mSystem::haltOnError('The file can not be found', _CONTROLLER_DIR_ . $controller . '.php', __FILE__, __LINE__);
         exit;
     }
 }
예제 #6
0
 public function showLogin(&$view, $message = '')
 {
     $view->assign('system_name', _SYSTEM_NAME_);
     $view->assign('base_path', _MY_PATH_);
     $view->assign('timestamp', time());
     $view->assign('message', $message);
     if (isset($_POST[_USERNAME_NAME_])) {
         $view->assign(_USERNAME_NAME_, $_POST[_USERNAME_NAME_]);
     } else {
         $view->assign(_USERNAME_NAME_, "");
     }
     if (isset($_POST[_PASS_NAME_])) {
         $view->assign(_PASS_NAME_, $_POST[_PASS_NAME_]);
     } else {
         $view->assign(_PASS_NAME_, "");
     }
     try {
         $view->display(_MY_DIR_ . _DEFAULT_LANG_ . _DS_ . 'login.' . _TPL_EXT_);
         exit;
     } catch (SmartyException $e) {
         q4mSystem::haltOnError($e->getMessage(), get_class($this) . '::' . $this->default_method, __FILE__, __LINE__);
         exit;
     }
 }