/**
  * detail of user
  * @author: ThanhN
  * @date: 2016/02/23
  */
 function addCustomer()
 {
     $userLogin = $this->Auth->user();
     // Check quuyen cua user
     if (!$this->Common->checkPermissionUser(AppConst::PERMISION_ADMIN, $userLogin, 'permission_user')) {
         $this->Session->setFlash(__("<div class='error-msg location_msg'>" . __("Bạn không có quyền vào trang này!") . "</div>"));
         $this->redirect('/users/error');
     }
     $userData = array();
     if ($this->request->is('post')) {
         $data = $this->request->data;
         debug($data);
         die;
         //remove html tag script, style, link
         $data = AppUtility::removeMetaTag($data);
         $data = Sanitize::clean($data);
         $arrError = $this->checkValidateFormAdd($data);
         if ($arrError == '') {
             try {
                 $data = $this->processData($data);
                 if ($this->saveData($data, $_FILES['user_image'])) {
                     $this->Session->setFlash(__("<div class='success-msg location_msg'>" . __("Thêm mới khách hàng thành công") . "</div>"));
                     $this->redirect('/Customer/listCustomer/');
                 } else {
                     $this->Session->setFlash(__("<div class='error-msg-table location_msg'>" . __("Thêm mới khách hàng thất bại, hãy thử lại!") . "</div>"));
                     $this->redirect('/Customer/listCustomer/');
                 }
             } catch (Exception $e) {
                 $this->log($e->getMessage());
                 return false;
             }
         } else {
             $this->Session->setFlash(__("<div class='success-msg location_msg'>" . $arrError . "</div>"));
             $this->redirect('/Customer/listCustomer/');
         }
     }
     // Get thông tin user
     $arrDataDoctor = array();
     $arrDataMember = array();
     $userData = $this->User->find("all", array('conditions' => array('delete_flag' => AppConst::USER_DELETE_FLAG_ACTIVE)));
     if (!empty($userData)) {
         foreach ($userData as $key => $value) {
             if ($value['User']['type_user'] == AppConst::TYPE_USER_BACSI) {
                 $arrDataDoctor[$value['User']['id']] = $value['User']['name'];
             }
             if (in_array($value['User']['type_user'], array(AppConst::TYPE_USER_NHANVIEN, AppConst::TYPE_USER_LETAN, AppConst::TYPE_USER_KETOAN))) {
                 $arrDataMember[$value['User']['id']] = $value['User']['name'];
             }
         }
     }
     $arrDadaDoctor = array();
     $this->set('arrDataDoctor', $arrDataDoctor);
     $this->set('arrDataMember', $arrDataMember);
     $this->set('userLogin', $userLogin);
     $this->set('baseUrl', $this->base);
 }
Exemplo n.º 2
0
 /**
  * detail of user
  * @author: ThanhN
  * @date: 2016/02/23
  */
 function addUser()
 {
     // Check quuyen cua user
     if (!$this->Common->checkPermissionUser(AppConst::PERMISION_ADMIN, $this->Auth->user(), 'permission_user')) {
         $this->Session->setFlash(__("<div class='error-msg location_msg'>" . __("Bạn không có quyền vào trang này!") . "</div>"));
         $this->redirect('/users/error');
     }
     $userData = array();
     if ($this->request->is('post')) {
         $data = $this->request->data;
         //remove html tag script, style, link
         $data = AppUtility::removeMetaTag($data);
         $data = Sanitize::clean($data);
         $data = $data['User'];
         // Check trùng username
         $arrUserDB = $this->User->find("all", array('conditions' => array('User.username' => $data['username'])));
         if (!empty($arrUserDB)) {
             $this->Session->setFlash(__("<div class='error-msg-table location_msg'>" . __("Mã nhân viên thêm mới bị trùng, hãy thử với mã nhân viên khác!") . "</div>"));
             $this->redirect('/users/listUser/');
         }
         $arrError = $this->checkValidateFormAdd($data);
         if ($arrError == '') {
             try {
                 if ($this->saveData($data, $_FILES['user_image'])) {
                     $this->Session->setFlash(__("<div class='success-msg location_msg'>" . __("Thêm mới user thành công") . "</div>"));
                     $this->redirect('/users/listUser/');
                 } else {
                     $this->Session->setFlash(__("<div class='error-msg-table location_msg'>" . __("Thêm mới user thất bại, hãy thử lại!") . "</div>"));
                     $this->redirect('/users/listUser/');
                 }
             } catch (Exception $e) {
                 $this->log($e->getMessage());
                 return false;
             }
         } else {
             $this->Session->setFlash(__("<div class='success-msg location_msg'>" . $arrError . "</div>"));
             $this->redirect('/users/listUser/');
         }
     }
     $this->set('baseUrl', $this->base);
 }