示例#1
0
 public function IsAdministrator()
 {
     $auth = Zend_Auth::getInstance();
     $data = (array) $auth->getStorage()->read();
     if (empty($data)) {
         return false;
     }
     $authID = $data['EU_ID'];
     $administrator = new ExtranetUsersGroups();
     $select = $administrator->select();
     $select->where('EUG_UserID = ?', $authID)->where('EUG_GroupID = 1');
     $row = $administrator->fetchRow($select);
     if (count($row) == 0) {
         return false;
     } else {
         return true;
     }
 }
 function addAction()
 {
     // page title
     $this->view->title = "Ajout d'un administrateur";
     // get group data
     $groupsData = Cible_FunctionsAdministrators::getAllAdministratorGroups();
     /********** ACTIONS ***********/
     $returnLink = $this->view->url(array('controller' => 'administrator', 'action' => 'index'));
     $form = new FormExtranetUser(array('baseDir' => $this->view->baseUrl(), 'cancelUrl' => "{$returnLink}"), $groupsData->toArray());
     $form->getElement('cancel')->setAttrib('onclick', 'document.location.href="' . $returnLink . '"');
     $form->getElement("EU_Password")->setRequired(true);
     $form->getElement("EU_Password")->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => "Veuillez entrer un mot de passe")));
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             // validate username is unique
             $findUser = new ExtranetUsers();
             $select = $findUser->select()->where('EU_Username = ?', $form->getValue('EU_Username'));
             $findUserData = $findUser->fetchAll($select);
             // username is allready use
             if ($findUserData->count() > 0) {
                 $form->getElement('EU_Username')->addError('Un autre utilisateur possède déjà ce nom d\'utilisateur');
             } else {
                 $userData = new ExtranetUsers();
                 $row = $userData->createRow();
                 $row->EU_LName = $form->getValue('EU_LName');
                 $row->EU_FName = $form->getValue('EU_FName');
                 $row->EU_Email = $form->getValue('EU_Email');
                 $row->EU_Username = $form->getValue('EU_Username');
                 $row->EU_Password = md5($form->getValue('EU_Password'));
                 $newInsertID = $row->save();
                 // insert all user and group association for that user
                 if ($formData['groups']) {
                     foreach ($formData['groups'] as $group) {
                         $userGroupAssociationData = new ExtranetUsersGroups();
                         $rowGroup = $userGroupAssociationData->createRow();
                         $rowGroup->EUG_UserID = $newInsertID;
                         $rowGroup->EUG_GroupID = $group;
                         $rowGroup->save();
                     }
                 }
                 header("location:" . $returnLink);
             }
         }
     }
 }
 function deleteAction()
 {
     // set page title
     $this->view->title = "Supprimer un groupe d'administrateur";
     // get params
     $administratorGroupID = (int) $this->_getParam('administratorGroupID');
     if ($this->_request->isPost()) {
         // if is set delete, then delete
         $delete = isset($_POST['delete']);
         $returnLink = $this->view->url(array('controller' => 'administrator-group', 'action' => 'index', 'administratorGroupID' => null));
         if ($delete && $administratorGroupID > 0) {
             // delete group
             $group = new ExtranetGroups();
             $where = 'EG_ID = ' . $administratorGroupID;
             $group->delete($where);
             // delete group index
             $groupIndex = new ExtranetGroupsIndex();
             $where = 'EGI_GroupID = ' . $administratorGroupID;
             $groupIndex->delete($where);
             // delete Extranet_Groups_Pages_Permissions
             $groupPagesPermissions = new ExtranetGroupsPagesPermissions();
             $where = 'EGPP_GroupID = ' . $administratorGroupID;
             $groupPagesPermissions->delete($where);
             // delete Extranet_UsersGroups
             $groupUsers = new ExtranetUsersGroups();
             $where = 'EUG_GroupID = ' . $administratorGroupID;
             $groupUsers->delete($where);
         }
         header("location:" . $returnLink);
     } else {
         if ($administratorGroupID > 0) {
             $administratorGroup = new ExtranetGroupsIndex();
             $this->view->group = $administratorGroup->fetchRow('EGI_GroupID=' . $administratorGroupID . ' AND EGI_LanguageID = ' . Zend_Registry::get("languageID"));
         }
     }
 }
 public static function getAllUserGroups($userID)
 {
     $userGroupAssociationData = new ExtranetUsersGroups();
     $select = $userGroupAssociationData->select()->where('EUG_UserID = ?', $userID);
     return $userGroupAssociationData->fetchAll($select);
 }