function admin_search($pattern = null)
 {
     $user = parent::getUser();
     # code after form submit
     if (!empty($this->data)) {
         $pattern = "'%" . $this->data['Rule']['pattern'] . "%'";
         $WILDCARD = "'*'";
         $search_result = $this->Rule->query('SELECT * 
                                          FROM rules LEFT JOIN groups on rules.group_id = groups.id 
                                                     LEFT JOIN locations as loc1 on rules.location_id = loc1.id 
                                                     LEFT JOIN locations as loc2 on groups.location_id = loc2.id
                                          WHERE (rules.sitename LIKE ' . $pattern . ' OR rules.sitename = ' . $WILDCARD . ')
                                          AND (rules.location_id = 1 OR rules.location_id = ' . $this->data['Rule']['locations'] . ')
                                          ORDER BY sitename, priority;', $cachequeries = false);
         #pr($search_result);
         $this->set('results', $search_result);
     }
     if (in_array($user['Role']['name'], $this->priv_roles)) {
         $allowed_locations = parent::getAdminLocationIds();
         $find_condition = array('fields' => array('Location.*'), 'conditions' => array("AND" => array('Location.id' => $allowed_locations, 'Location.id NOT' => "1")), 'order' => 'Location.code');
     } else {
         $find_condition = array('fields' => array('Location.*'), 'order' => 'Location.code', 'conditions' => array("id NOT" => "1"));
     }
     $locations_list = $this->Location->find('all', $find_condition);
     $locations = Set::combine($locations_list, '{n}.Location.id', array('%s %s', '{n}.Location.code', '{n}.Location.name'));
     $this->set(compact('locations'));
 }
 function admin_start()
 {
     $user = parent::getUser();
     $allowed_locations = parent::getAdminLocationIds();
     # allow everyone to view location ALL...
     array_push($allowed_locations, 1);
     if (in_array($user['Role']['name'], $this->priv_roles)) {
         $find_condition = array('fields' => array('Location.*'), 'order' => 'Location.code');
     } else {
         $find_condition = array('fields' => array('Location.*'), 'conditions' => array('Location.id' => $allowed_locations), 'order' => 'Location.code');
     }
     $locations = $this->Location->find('all', $find_condition);
     $this->set('locations', $locations);
 }
Beispiel #3
0
 /**
  * Ajoute le fichier en tête à la réponse html
  */
 public static function getHeader()
 {
     $baseFolder = '';
     $urlLevel = count(explode('/', $_SERVER['REQUEST_URI'])) - 3;
     for ($i = 0; $i < $urlLevel; $i++) {
         $baseFolder .= '../';
     }
     $userMsgs = AppController::getMsg();
     if ($userMsgs == Null) {
         $userMsgs = [];
     }
     $user = AppController::getUser();
     require 'Src/View/HeaderView.php';
 }
Beispiel #4
0
 public static function render($params = [])
 {
     $user = AppController::getUser();
     if (!$user) {
         AppController::setMsg('warning', "La zone demandée n'est pas autorisé pour les personnes non inscrites.");
         AppController::redirect('index');
     }
     $algorithms = \Root\Src\Model\AlgorithmModel::loadFunctionByUser($user->getId());
     $structures = \Root\Src\Model\StructureModel::loadStructureByUser($user->getId());
     $translationOfC = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('c');
     $translationOfJava = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('java');
     $translationOfJavascript = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('javascript');
     $translationOfPhp = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('php');
     $translationOfPython = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('python');
     parent::getHeader();
     self::call('Render', ['algorithms' => $algorithms, 'structures' => $structures, 'translations' => ['c' => $translationOfC, 'java' => $translationOfJava, 'javascript' => $translationOfJavascript, 'php' => $translationOfPhp, 'python' => $translationOfPython]]);
     parent::getFooter();
 }
 function user_logs()
 {
     $user = parent::getUser();
     $this->set('location', $user['Location']['id']);
     $this->set('user', $user);
     ##################
     # If form was submitted
     if (!empty($this->data)) {
         $model = $this->modelClass;
         $proxy = $this->ProxySetting->find('first', array('conditions' => array('Location.id' => $user['Location']['id'])));
         $this->set('proxy', $proxy);
         // use correct datasource
         $this->CommonTasks->setDataSource($proxy);
         # build up conditions for query
         $conditions = array();
         $conditions['Log.user_id'] = $user['User']['id'];
         if (!empty($this->data[$model]['site'])) {
             $conditions['Log.sitename LIKE'] = '%' . $this->data[$model]['site'] . '%';
         }
         if (!empty($this->data[$model]['status'])) {
             $conditions['Log.source'] = $this->data[$model]['status'];
         }
         if (!empty($this->data[$model]['type'])) {
             if ($this->data[$model]['type'] == "NOT null") {
                 array_push($conditions, array("not" => array("Log.parent_id" => null)));
             }
             if ($this->data[$model]['type'] == "null") {
                 $conditions['Log.parent_id'] = null;
             }
         }
         // set parrent id to avoid double entries...
         if (empty($this->data[$model]['users']) && empty($this->data[$model]['site']) && empty($this->data[$model]['type'])) {
             $conditions['Log.parent_id'] = null;
         }
         // delete if requested...
         if (isset($this->params['form']['deleteMatching'])) {
             $this->Log->deleteAll($conditions);
         }
         // do a search
         $tree = $this->Log->find('all', array('conditions' => $conditions));
         $this->set('logs', $tree);
     }
 }
 function admin_index()
 {
     # get global settings
     $settings = $this->CommonTasks->getGlobalSettings();
     $this->set('settings', $settings);
     $user = parent::getUser();
     $conditions = array();
     # get proxys / locations
     if (!in_array($user['Role']['name'], $this->priv_roles)) {
         $allowed_locations = parent::getAdminLocationIds();
         $conditions['Location.id'] = $allowed_locations;
     }
     # If form has been submitted
     if (!empty($this->data) && isset($this->data['User']['searchstring'])) {
         $string = $this->data['User']['searchstring'];
         $conditions = array("User.username LIKE '%{$string}%' OR User.realname LIKE '%{$string}%'");
     }
     $this->User->recursive = 0;
     $this->set('users', $this->paginate('User', $conditions));
 }
Beispiel #7
0
 /**
  * 
  */
 public static function giveHelp()
 {
     debug($_POST);
     if (isset($_POST['msgHelpedId']) && isset($_POST['helpMsg']) && AppController::getUser()) {
         $msg = new \Root\Src\Model\MailModel();
         $msg->setContent($_POST['helpMsg']);
         $msg->setSubjectId($_POST['msgHelpedId']);
         $msg->setOwnerId(AppController::getUser()->getId());
         debug($msg);
         $msg->send();
         AppController::setMsg("success", "Votre aide a bien été publiée.");
     } else {
         if (!AppController::getUser()) {
             AppController::setMsg("warning", "Vous devez être connecté pour poster des messages d'aide");
         } else {
             AppController::setMsg("warning", "Aucun message n'a été saisi, vous devez en saisir un pour obtenir de l'aide");
         }
     }
     self::render();
 }
Beispiel #8
0
 /**
  * Methode de connexion
  */
 public static function connect()
 {
     if (AppController::getUser() != Null) {
         AppController::setMsg("warning", "Vous êtes déjà connecté. Veuillez vous déconnecter pour changer de compte.");
     } else {
         $login = '';
         $password = '';
         if (isset($_POST['login']) && isset($_POST['password'])) {
             $login = $_POST['login'];
             $password = $_POST['password'];
         }
         $user = new \Root\Src\Model\UserModel($login, $password);
         $user = $user->exist();
         if ($user) {
             AppController::setUser($user);
             AppController::setMsg("success", "Vous avez bien été connecté.");
             parent::redirect('index');
         } else {
             AppController::setMsg("warning", "Le mot de passe ou l'identifiant est incorrect.");
             self::render();
         }
     }
 }
Beispiel #9
0
 /**
  * Fonction de mise à jour d'un compte
  */
 public static function update()
 {
     if (isset($_POST['oldPassword'])) {
         $validPassword = AppController::getUser();
         $validPassword->setPassword($_POST['oldPassword']);
         $validPassword = $validPassword->exist();
         if (!$validPassword) {
             AppController::setMsg("warning", "Le mot de passe saisit n'est pas correct.");
         }
         if ($_POST['newPassword'] != $_POST['passwordConfirmation']) {
             AppController::setMsg("warning", "Les deux mots de passes ne sont pas les mêmes");
         }
         if (!AppController::hasError()) {
             $user = AppController::getUser();
             $user->setPassword($_POST['newPassword']);
             $user->updatePassword();
         }
     }
     $user = AppController::getUser();
     $user->setName($_POST['name']);
     $user->setEmail($_POST['email']);
     $user->setAvatar('');
     $user->update();
 }
Beispiel #10
0
 /**
  * Méthode de chargement d'une structure
  * @param type $params
  */
 public static function load($params = [])
 {
     if (isset($params[0])) {
         $_POST['idStructure'] = $params[0];
         $structure = \Root\Src\Model\StructureModel::loadStructureById($_POST['idStructure']);
         $user = AppController::getUser();
         if ($structure && $user && $structure->getOwnerId() == $user->getId()) {
             $_POST['idStructure'] = $structure->getId();
             $_POST['structure'] = $structure->getCode();
             $tranlsationToC = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'c');
             if ($tranlsationToC) {
                 $_POST['translationToC'] = $tranlsationToC->getCode();
             }
             $tranlsationToPhp = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'php');
             if ($tranlsationToPhp) {
                 $_POST['translationToPhp'] = $tranlsationToPhp->getCode();
             }
             $tranlsationToJava = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'java');
             if ($tranlsationToJava) {
                 $_POST['translationToJava'] = $tranlsationToJava->getCode();
             }
             $tranlsationToJavascript = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'javascript');
             if ($tranlsationToJavascript) {
                 $_POST['translationToJavascript'] = $tranlsationToJavascript->getCode();
             }
             $tranlsationToPython = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'python');
             if ($tranlsationToPython) {
                 $_POST['translationToPython'] = $tranlsationToPython->getCode();
             } else {
                 unset($_POST['idStructure']);
             }
         }
     }
     self::render();
 }
Beispiel #11
0
 /**
  * 
  */
 public static function askForHelp()
 {
     debug($_POST);
     if (isset($_POST['id']) && isset($_POST['helpMsg']) && AppController::getUser()) {
         $msg = new \Root\Src\Model\MailModel();
         $msg->setContent($_POST['helpMsg']);
         $msg->setSubjectId($_POST['id']);
         $msg->setOwnerId(AppController::getUser()->getId());
         debug($msg);
         $msg->send();
         AppController::setMsg("success", "Votre demande d'aide a bien été publiée.");
     } else {
         AppController::setMsg("warning", "Aucun message n'a été saisi, vous devez en saisir un pour obtenir de l'aide");
     }
     unset($_POST['askForHelp']);
     self::render();
 }
 function admin_searchlist()
 {
     /* # don't really know.......
        if ($this->Session->read('Auth.godmode') != 1) {
           $this->Session->setFlash(__('You are not allowed to access this search method', true));
           $this->Tracker->back();
        }
        */
     $user = parent::getUser();
     # get proxys / locations
     if ($user['Role']['name'] == "admin_global") {
         $find_conditions = array("Location.id NOT" => "1");
     } else {
         $allowed_locations = parent::getAdminLocationIds();
         $find_conditions = array('Location.id' => $allowed_locations, 'Location.id NOT' => "1");
     }
     $proxy_list = $this->ProxySetting->find('all', array('fields' => array('Location.id', 'Location.code', 'Location.name', 'ProxySetting.fqdn_proxy_hostname', 'ProxySetting.id'), 'conditions' => $find_conditions, 'order' => array('Location.code')));
     $proxyIds = Set::combine($proxy_list, '{n}.ProxySetting.id', array('%s - %s', '{n}.Location.code', '{n}.ProxySetting.fqdn_proxy_hostname'));
     $this->set(compact('proxyIds'));
     ##################
     # If form was submitted
     if (!empty($this->data) && isset($this->data['Log']['proxyId'])) {
         $proxy = $this->ProxySetting->findById($this->data['Log']['proxyId']);
         // check permissions
         if (!parent::checkSecurity($proxy['ProxySetting']['location_id'])) {
             $this->Tracker->back();
         }
         // use correct datasource
         $this->CommonTasks->setDataSource($proxy);
         # build up conditions for query
         $conditions = array();
         if (!empty($this->data['Log']['site'])) {
             $conditions['Log.sitename LIKE'] = '%' . $this->data['Log']['site'] . '%';
         }
         if (!empty($this->data['Log']['onlyThisLoc'])) {
             $conditions['Log.location_id'] = $proxy['ProxySetting']['location_id'];
         }
         if (!empty($this->data['Log']['status'])) {
             $conditions['Log.source'] = $this->data['Log']['status'];
         }
         if (!empty($this->data['Log']['type'])) {
             if ($this->data['Log']['type'] == "NOT null") {
                 array_push($conditions, array("not" => array("Log.parent_id" => null)));
             }
             if ($this->data['Log']['type'] == "null") {
                 $conditions['Log.parent_id'] = null;
             }
         }
         if (!empty($this->data['Log']['users'])) {
             # first get the ids of the matching users
             $user_ids = $this->User->find('all', array('fields' => 'id', 'conditions' => array('or' => array('User.realname LIKE' => '%' . $this->data['Log']['users'] . '%', 'User.username LIKE' => '%' . $this->data['Log']['users'] . '%'))));
             $user_ids = Set::extract('/User/id', $user_ids);
             $conditions['Log.user_id'] = $user_ids;
         }
         // set parrent id to avoid double entries...
         if (empty($this->data['Log']['users']) && empty($this->data['Log']['site']) && empty($this->data['Log']['type'])) {
             $conditions['Log.parent_id'] = null;
         }
         // delete if requested...
         if (isset($this->params['form']['deleteMatching'])) {
             $this->Log->deleteAll($conditions);
         }
         // do a search
         $tree = $this->Log->find('all', array('conditions' => $conditions));
         $this->set('logs', $tree);
         $this->log($this->MyAuth->user('username') . "; {$this->name}; search logs", "activity");
         #pr($conditions);    # debug
     }
 }