コード例 #1
0
ファイル: UserController.php プロジェクト: nidzix/Airtime
 public function addUserAction()
 {
     global $CC_CONFIG;
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $js_files = array('/js/datatables/js/jquery.dataTables.js?', '/js/datatables/plugin/dataTables.pluginAPI.js?', '/js/airtime/user/user.js?');
     foreach ($js_files as $js) {
         $this->view->headScript()->appendFile($baseUrl . $js . $CC_CONFIG['airtime_version'], 'text/javascript');
     }
     $this->view->headLink()->appendStylesheet($baseUrl . '/css/users.css?' . $CC_CONFIG['airtime_version']);
     $form = new Application_Form_AddUser();
     $this->view->successMessage = "";
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $formdata = $form->getValues();
             if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1 && $formdata['login'] == 'admin' && $formdata['user_id'] != 0) {
                 $this->view->successMessage = "<div class='errors'>Specific action is not allowed in demo version!</div>";
             } elseif ($form->validateLogin($formdata)) {
                 $user = new Application_Model_User($formdata['user_id']);
                 $user->setFirstName($formdata['first_name']);
                 $user->setLastName($formdata['last_name']);
                 $user->setLogin($formdata['login']);
                 // We don't allow 6 x's as a password.
                 // The reason is because we that as a password placeholder
                 // on the client side.
                 if ($formdata['password'] != "xxxxxx") {
                     $user->setPassword($formdata['password']);
                 }
                 $user->setType($formdata['type']);
                 $user->setEmail($formdata['email']);
                 $user->setCellPhone($formdata['cell_phone']);
                 $user->setSkype($formdata['skype']);
                 $user->setJabber($formdata['jabber']);
                 $user->save();
                 $form->reset();
                 if (strlen($formdata['user_id']) == 0) {
                     $this->view->successMessage = "<div class='success'>User added successfully!</div>";
                 } else {
                     $this->view->successMessage = "<div class='success'>User updated successfully!</div>";
                 }
             }
         }
     }
     $this->view->form = $form;
 }
コード例 #2
0
 public function addUserAction()
 {
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $this->view->headScript()->appendFile($baseUrl . '/js/datatables/js/jquery.dataTables.js', 'text/javascript');
     $this->view->headScript()->appendFile($baseUrl . '/js/datatables/plugin/dataTables.pluginAPI.js', 'text/javascript');
     $this->view->headScript()->appendFile($baseUrl . '/js/airtime/user/user.js', 'text/javascript');
     $form = new Application_Form_AddUser();
     $this->view->successMessage = "";
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $formdata = $form->getValues();
             if ($form->validateLogin($formdata)) {
                 $user = new User($formdata['user_id']);
                 $user->setFirstName($formdata['first_name']);
                 $user->setLastName($formdata['last_name']);
                 $user->setLogin($formdata['login']);
                 if ($formdata['password'] != "xxxxxx") {
                     $user->setPassword($formdata['password']);
                 }
                 $user->setType($formdata['type']);
                 $user->setEmail($formdata['email']);
                 $user->setSkype($formdata['skype']);
                 $user->setJabber($formdata['jabber']);
                 $user->save();
                 $form->reset();
                 if (strlen($formdata['user_id']) == 0) {
                     $this->view->successMessage = "<div class='success'>User added successfully!</div>";
                 } else {
                     $this->view->successMessage = "<div class='success'>User updated successfully!</div>";
                 }
             }
         }
     }
     $this->view->form = $form;
 }
コード例 #3
0
 public function addUserAction()
 {
     $CC_CONFIG = Config::getConfig();
     $request = $this->getRequest();
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $js_files = array('js/datatables/js/jquery.dataTables.js?', 'js/datatables/plugin/dataTables.pluginAPI.js?', 'js/airtime/user/user.js?');
     foreach ($js_files as $js) {
         $this->view->headScript()->appendFile($baseUrl . $js . $CC_CONFIG['airtime_version'], 'text/javascript');
     }
     $this->view->headLink()->appendStylesheet($baseUrl . 'css/users.css?' . $CC_CONFIG['airtime_version']);
     $form = new Application_Form_AddUser();
     $this->view->successMessage = "";
     if ($request->isPost()) {
         $params = $request->getPost();
         $postData = explode('&', $params['data']);
         $formData = array();
         foreach ($postData as $k => $v) {
             $v = explode('=', $v);
             $formData[$v[0]] = urldecode($v[1]);
         }
         if ($form->isValid($formData)) {
             if ($form->validateLogin($formData)) {
                 $user = new Application_Model_User($formData['user_id']);
                 if (empty($formData['user_id'])) {
                     $user->setLogin($formData['login']);
                 }
                 $user->setFirstName($formData['first_name']);
                 $user->setLastName($formData['last_name']);
                 // We don't allow 6 x's as a password.
                 // The reason is because we that as a password placeholder
                 // on the client side.
                 if ($formData['password'] != "xxxxxx") {
                     $user->setPassword($formData['password']);
                 }
                 $user->setType($formData['type']);
                 $user->setEmail($formData['email']);
                 $user->setCellPhone($formData['cell_phone']);
                 $user->setSkype($formData['skype']);
                 $user->setJabber($formData['jabber']);
                 $user->save();
                 // Language and timezone settings are saved on a per-user basis
                 // By default, the default language, and timezone setting on
                 // preferences page is what gets assigned.
                 Application_Model_Preference::SetUserLocale();
                 Application_Model_Preference::SetUserTimezone();
                 $form->reset();
                 $this->view->form = $form;
                 if (strlen($formData['user_id']) == 0) {
                     $this->view->successMessage = "<div class='success'>" . _("User added successfully!") . "</div>";
                 } else {
                     $this->view->successMessage = "<div class='success'>" . _("User updated successfully!") . "</div>";
                 }
                 $this->_helper->json->sendJson(array("valid" => "true", "html" => $this->view->render('user/add-user.phtml')));
             } else {
                 $this->view->form = $form;
                 $this->_helper->json->sendJson(array("valid" => "false", "html" => $this->view->render('user/add-user.phtml')));
             }
         } else {
             $this->view->form = $form;
             $this->_helper->json->sendJson(array("valid" => "false", "html" => $this->view->render('user/add-user.phtml')));
         }
     }
     $this->view->form = $form;
 }
コード例 #4
0
ファイル: HnaController.php プロジェクト: randaalex/hna-base
    public function addAction() {

        if (Zend_Auth::getInstance()->getIdentity())
            $role = Zend_Auth::getInstance()->getIdentity()->status;

        $acl = new App_Acl();

        if (!$acl->isAllowed($role, App_Resources::ADD))
            $this->getHelper('Redirector')->gotoSimpleAndExit('index', 'error', '');

        $this->view->title = "HNA - Добавление пользователя";
        $this->view->headTitle($this->view->title);

        $form = new Application_Form_AddUser();
        $this->view->form = $form;

        $this->view->Dojo()->addOnLoad("function() {
                                           dojo.connect(dojo.byId('getpass'),'onclick',function(){
                                                var chars = '1234567890abcdefghijklmnopqrstuvwxyz';
                                                var pass = '';
                                                for( var i=1; i <= 8; i++ ){
                                                    rand = Math.floor(Math.random()*(37));
                                                    pass += chars.substring(rand,rand+1);
                                                }
                                                dojo.attr(dojo.byId('pass'),'value',pass);
                                           })
                                        }");

        if ($this->getRequest()->isPost()) {

            $formData = $this->getRequest()->getPost();

            if ($form->isValid($formData)) {

                $surname = $form->getValue('surname');
                $firstname = $form->getValue('firstname');
                $lastname = $form->getValue('lastname');

                $pass = $this->passgen(8);
                $group = $form->getValue('group');

                $modcontract = new Application_Model_DbTable_Hna();
                $contract = $modcontract->getLastContract() + 1;

                // TODO: сделать переменную года, согласно которой и делать проверку
                /*if($contract < 10000){
                    $contract = 10000;
                }*/

                $login = $contract . $this->logingen();

                $block = $form->getValue('block');
                $room = $form->getValue('room');

                switch ($form->getValue('status')) {
                    case 'Активный пользователь':
                        $status = 0;
                        break;
                    case 'Забаненый пользователь':
                        $status = 1;
                        break;
                    case 'Архивный пользователь':
                        $status = 2;
                        break;
                    case 'Администратор':
                        $status = 3;
                        break;
                    default:
                        break;
                }

                $register = date('Y-m-d');

                $admin_id = Zend_Auth::getInstance()->getIdentity()->admin_id;

                $note = $form->getValue('note');

                $hostel = (int) $form->getValue('hostel');
                if (!$hostel)
                    $hostel = 2;

                $cable = (int) $form->getValue('cable');

                $hna = new Application_Model_DbTable_Hna();
                $user_id = $hna->addUser($surname, $firstname, $lastname, $login, $pass, $group, $contract, $block, $room, $status, $register, $admin_id, $note, $hostel, $cable);
                $pays = new Application_Model_DbTable_Pays();
                $userlog = new Application_Model_DbTable_Logs();

                if ($form->getValue('arhiv') == '0') {
                    $pays->addUser($user_id);
                    $userlog->addMessage($user_id, $admin_id, 0, "ФИО: $surname $firstname $lastname; Логин:$login; Группа:$group, Блок:$block$room; Статус:$status; Общ:$hostel; Каб:$cable; Свич:$switch_id; Примечание:$note");
                } else {
                    $pays->addUser($user_id, true);
                    $userlog->addMessage($user_id, $admin_id, 1, "ФИО: $surname $firstname $lastname; Логин:$login; Группа:$group, Блок:$block$room; Статус:$status; Общ:$hostel; Каб:$cable; Свич:$switch_id; Примечание:$note");
                }

                $this->getHelper('Redirector')->gotoSimpleAndExit('vadd', 'hna', '', array('user_id' => $user_id));
            } else {
                $form->populate($formData);
            }
        }
    }