Beispiel #1
0
 function ActionsAction()
 {
     $c = new ControllerModel();
     $c->_caches();
     $c->load($this->request->cid);
     $this->_view->assign('controller', $c);
     $a = new ActionModel();
     $a->_caches();
     $this->_view->assign('actions', $a->loadByController($c->id));
     if ($this->request->id) {
         $this->_view->assign('eaction', $a->load($this->request->id));
     }
     $this->_view->Actions();
     $this->_view->parse();
 }
 function EditGroupAction($rid = null)
 {
     $this->BaseAdminData();
     $request = Project::getRequest();
     $info = array();
     if ((int) $rid > 0) {
         $controller_id = $rid;
     } else {
         $controller_id = (int) $request->id;
     }
     $controller_model = new ControllerModel();
     $controller_model->load($controller_id);
     $param_group_model = new ParamGroupModel();
     if ($controller_id > 0) {
         $param_group_model->loadByLabel($controller_model->name);
         if ($param_group_model->id > 0) {
             $param_group_id = $param_group_model->id;
         } else {
             // Group is not exists yet, so create it
             $param_group_model->label = $controller_model->name;
             $param_group_id = $param_group_model->save();
         }
     } else {
         $param_group_id = 0;
     }
     $info['controller_id'] = $controller_id;
     $info['param_group_id'] = $param_group_id;
     $info['php_types'] = array('string' => 'строка', 'integer' => 'целое', 'float' => 'с плавающей точкой');
     $param_model = new ParamModel();
     $list = $param_model->getByGroupId($param_group_id);
     array_push($list, array('id' => 0, 'name' => '', 'value' => ''));
     $info['param_list'] = $list;
     $info['save_controller'] = null;
     $info['save_action'] = 'SaveParams';
     $info['save_controller'] = null;
     $info['delete_controller'] = null;
     $info['delete_action'] = 'DeleteParam';
     $this->_view->ParamList($info);
     $this->_view->parse();
 }
Beispiel #3
0
 function ChangeAccessAction()
 {
     $request = Project::getRequest();
     $group_model = new UserTypeModel();
     $group_data = $group_model->load($request->gid);
     if (!count($group_data)) {
         // Bad request:: group not exists
         return;
     }
     $controller_model = new ControllerModel();
     $controller_data = $controller_model->load($request->cid);
     if (!count($controller_data)) {
         // Bad request:: controller not exists
         return;
     }
     $action_model = new ActionModel();
     $action_data = $action_model->load($request->id);
     if (!count($action_data)) {
         // Bad request:: action not exists
         return;
     }
     $right_model = new UserRightModel();
     $right_data = $right_model->loadByTypeControllerAction($request->gid, $request->cid, $request->id);
     if (!count($right_data)) {
         $right_model->user_type_id = $request->gid;
         $right_model->controller_id = $request->cid;
         $right_model->action_id = $request->id;
         $right_model->access = 1;
     } else {
         $right_model->access = 1 - (int) $right_model->access;
     }
     $right_model->save();
 }
Beispiel #4
0
 public function createUrl($service = null, $action = null, $parameters = null, $user = null)
 {
     if ($service === null) {
         $service = $this->_current_controller;
     }
     if ($action === null) {
         $action = $this->_current_action;
     }
     // TODO:: need cache to service+action for getting request key!
     $controller_model = new ControllerModel();
     $controller_model->loadByKey($service);
     if ((int) $controller_model->id <= 0) {
         throw new InvalidValueException("Can't create url, controller is not exists");
     }
     $action_model = new ActionModel();
     $action_model->loadByKey($controller_model->id, $action);
     if ((int) $action_model->id <= 0) {
         throw new InvalidValueException("Can't create url, action is not exists");
     }
     if (!strlen($action_model->request_key)) {
         throw new InvalidValueException(__METHOD__ . "::" . __LINE__ . ":: Bad request key: controller - " . $controller_model->name . "; action - " . $action_model->name . ";action ID=" . $action_model->id);
     }
     // Default user controller action ----------
     if ($service == 'User' && $action_model->default && $this->getUsername()) {
         $action_model->request_key = '';
     }
     // -----------------------------------------
     if (!$this->_rewrite) {
         if ($action !== null) {
             $parameters = array_merge(array($this->_request_action_key => $action), $parameters);
         }
         $parameters = array_merge(array($this->_request_controller_key => $service), $parameters);
     }
     if (!is_array($parameters)) {
         $parameters = array();
     }
     $session_name = Project::getSession()->getSessionName();
     /*if (($this -> _username != $user) && ($user !== null) && ((int)Project::getUser() -> getDbUser() -> id > 0)){
     			$sid = Project::getSession() -> getSID();
     			//var_dump($sid);die;
     			$parameters[$session_name] = $sid;
     		} else {
     			if (isset($parameters[$session_name])){
     				unset($parameters[$session_name]);
     			}
     		}*/
     $query = '';
     foreach ($parameters as $k => $v) {
         if (strlen($query)) {
             $query .= $this->_param_delimiter;
         }
         if (!is_numeric($k) && strlen($k)) {
             $query .= $k . $this->_value_delimiter . $v;
         } else {
             $query .= $v;
         }
     }
     //$query = http_build_query(is_array($parameters)?$parameters:array(), '', $this -> _param_delimiter);
     $url = '';
     if ($this->_rewrite) {
         $url = $action_model->request_key;
     }
     if ($query) {
         //$query = str_replace('=', $this -> _value_delimiter, $query);
         //$query = str_replace($this -> _param_delimiter.$this -> _value_delimiter, $this -> _param_delimiter, $query);
         $url .= ($this->_rewrite ? '/' : '?') . $query . ($this->_rewrite ? '/' : null);
     }
     if ($this->_rewrite) {
         if ($user === null) {
             if ($this->_username !== null) {
                 $user = $this->_username;
             }
         }
         if ($user !== null) {
             $host = ($this->IsSecure() ? "https://" : "http://") . $user . (strlen($user) ? '.' : '') . $this->_config->get('base_host') . '/';
         } else {
             $host = $this->getHost();
         }
         $url = $host . $url;
     } else {
         $url = $this->getAbsoluteUrl() . $url;
     }
     return $url;
 }
Beispiel #5
0
         // sprawdzanie czy kontroller ma dzieci i czy w linku jest podane dziecko
         $child_controller = ClassTools::getValue('child_controller');
         if ($child_controller) {
             if (isset($class_controller['childrens']) && isset($class_controller['childrens'][$child_controller])) {
                 $class_controller = $class_controller['childrens'][$child_controller];
             } else {
                 ClassTools::redirect('404');
                 exit;
             }
         }
         if (isset($class_controller['permissions'])) {
             if (in_array($login->auth_user['id_permission'], $class_controller['permissions'])) {
                 $loadController = new $class_controller['controller']();
                 print $loadController->getContent();
             } else {
                 $loadController = new ControllerModel();
                 print $loadController->getPageNoPermissions();
             }
         } else {
             $loadController = new $class_controller['controller']();
             print $loadController->getContent();
         }
     } else {
         // jezeli nie jest zdefiniowany to zaladuje 404
         ClassTools::redirect('404');
         exit;
     }
 } elseif (!$controller && $current_link == '/') {
     // ladowanie strony start
     $loadController = new ControllerIndex();
     print $loadController->getContent();
Beispiel #6
0
 function procees($auth)
 {
     $request = Project::getRequest();
     $load_default = false;
     $request_action = $request->getAction();
     // Default action...
     if (!$request_action && $request->getUsername()) {
         $request_action = 'user_profile';
     }
     //
     $action_model = new ActionModel();
     $action_model->loadByRequestKey($request_action);
     if ((int) $action_model->id > 0) {
         // requested action exists
         $controller_model = new ControllerModel();
         $controller_model->load($action_model->controller_id);
         if ((int) $controller_model->id > 0) {
             // controller exists
             $reflection = new ReflectionClass($controller_model->name);
             if ($reflection->hasMethod($action_model->name . 'Action')) {
                 // Action exists at controller
                 if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                     // Have access to requested action
                     $this->setData($controller_model, $action_model);
                 } else {
                     $this->accessLog(__METHOD__, __LINE__, "No access to requested action: requested action - " . $request_action . ";controller - " . $controller_model->name);
                     // No access to action. try to get default action of controller
                     $action_model = new ActionModel();
                     $action_model->loadDefault($controller_model->id);
                     if ($action_model->id > 0) {
                         // Action exists at database
                         if ($reflection->hasMethod($action_model->name . 'Action')) {
                             // Action method exists at controller class
                             if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                                 // Have access to default action of requested controller (by requested action)
                                 $this->setData($controller_model, $action_model);
                             } else {
                                 // No access to default action : try to load default controller and action
                                 $this->accessLog(__METHOD__, __LINE__, "No access to default action of requested action's controller: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                                 $load_default = true;
                             }
                         } else {
                             // Default action not exists at controller
                             $this->accessLog(__METHOD__, __LINE__, "Default action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                             $load_default = true;
                         }
                     } else {
                         // Default action not exists at database (default in controller of requested action)
                         $this->accessLog(__METHOD__, __LINE__, "Default action not exists at database: controller - " . $controller_model->name);
                         $load_default = true;
                     }
                 }
             } else {
                 // No access to requested action:: get default action of this controller
                 $this->accessLog(__METHOD__, __LINE__, "Requested action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                 $action_model = new ActionModel();
                 $action_model->loadDefault($controller_model->id);
                 if ($action_model->id > 0) {
                     // Action exists at database
                     if ($reflection->hasMethod($action_model->name . 'Action')) {
                         // Action method exists at controller class
                         if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                             // Have access to default action of requested controller (by requested action)
                             $this->setData($controller_model, $action_model);
                         } else {
                             // No access to default action : try to load default controller and action
                             $this->accessLog(__METHOD__, __LINE__, "No access to default action of requested action's controller: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                             $load_default = true;
                         }
                     } else {
                         // Default action not exists at controller
                         $this->accessLog(__METHOD__, __LINE__, "Default action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                         $load_default = true;
                     }
                 } else {
                     // Default action not exists at database (default in controller of requested action)
                     $this->accessLog(__METHOD__, __LINE__, "Default action not exists at database: controller - " . $controller_model->name);
                     $load_default = true;
                 }
             }
         } else {
             // Controller not exists
             $load_default = true;
             $this->accessLog(__METHOD__, __LINE__, "Controller not exists at database: requested action - " . $request_action);
         }
     } else {
         // Requested action not exists
         $load_default = true;
         $this->accessLog(__METHOD__, __LINE__, "Requested action not exists at database: requested action - " . $request_action);
     }
     $get_login = false;
     if ($load_default === true) {
         // Load default controller and action
         $controller_model = new ControllerModel();
         // TODO:: how to check, if we need default admin or user controller?
         $controller_model->loadDefault($admin = true);
         if ($controller_model->id > 0) {
             // Default controller exists and load default action of it
             $reflection = new ReflectionClass($controller_model->name);
             $action_model = new ActionModel();
             $action_model->loadDefault($controller_model->id);
             if ($action_model->id > 0 && $reflection->hasMethod($action_model->name . 'Action')) {
                 // Default action exists
                 if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                     // Has access to default
                     $this->setData($controller_model, $action_model);
                 } else {
                     // No access to default controller and action, so get login
                     $this->accessLog(__METHOD__, __LINE__, "No access to default controller and action, so get login: default controller - " . $controller_model->name . ";default action - " . $action_model->name);
                     $get_login = true;
                 }
             } else {
                 // Default action not exists at default controller
                 $this->accessLog(__METHOD__, __LINE__, "No default action at default controller: default controller - " . $controller_model->name . ";default action - " . $action_model->name);
                 $get_login = true;
             }
         } else {
             // Default controller not exists
             $this->accessLog(__METHOD__, __LINE__, "Default controller not exists: default controller - " . $controller_model->name);
             $get_login = true;
         }
     }
     if ($get_login === true) {
         $controller_model = new ControllerModel();
         $controller_model->loadByKey($this->_login_controller);
         if ($controller_model->id > 0) {
             // Login controller exists at database list
             $reflection = new ReflectionClass($controller_model->name);
             $action_model = new ActionModel();
             $action_model->loadByKey($controller_model->id, $this->_login_action);
             if ($action_model->id > 0 && $reflection->hasMethod($action_model->name . 'Action')) {
                 // Login action exists at login controller
                 $this->setData($controller_model, $action_model);
             } else {
                 throw new SecurityException('Critical security error: login action not defined at configuration');
             }
         } else {
             throw new SecurityException('Critical security error: login controller not defined at configuration');
         }
     }
     Project::getRequest()->setController($controller_model->request_key);
     if ($controller_model->id > 0 && $action_model->id > 0) {
         if ($action_model->request_key != $request_action) {
             //var_dump($get_login, $load_default,$controller_model -> name, $request_controller, $action_model -> name, $request_action);die;
             if ($get_login || $load_default) {
                 // If controllers is not equal to requested
                 $url = Project::getRequest()->createUrl($controller_model->request_key, $action_model->name);
                 // TODO:: check, if it's ajax request, then change location!!!
                 //Project::getAjaxResponse() -> location($url);
                 //header("HTTP/1.0 404 Not Found");
                 //exit;
                 //Project::getResponse() -> redirect($url);
             }
         }
     }
 }