Пример #1
0
 public function addAction()
 {
     $request = $this->getRequest();
     $id = $this->params()->fromRoute('id');
     //insert
     if ($id == '') {
         if ($request->isPost()) {
             $cat = new User();
             $cat->setUserName($this->params()->fromPost('userName'));
             $cat->setFullName($this->params()->fromPost('fullName'));
             $cat->setPassword(sha1($this->params()->fromPost('password')));
             $cat->setIsdelete(0);
             $cat->setType(0);
             $userInserted = $this->modelUsers->insert($cat);
         }
         //insert new user
         //$this->redirect()->toRoute('admin/child',array('controller'=>'category'));
         return new ViewModel(array('title' => $this->translator->translate('Add new user')));
     } else {
         $cat = $this->modelUsers->findOneBy(array('id' => $id));
         if ($request->isPost()) {
             $idFormPost = $this->params()->fromPost('id');
             $cat = $this->modelUsers->findOneBy(array('id' => $idFormPost));
             $cat->setUserName($this->params()->fromPost('userName'));
             $cat->setFullName($this->params()->fromPost('fullName'));
             if ($this->params()->fromPost('password') != '') {
                 $cat->setPassword(sha1($this->params()->fromPost('password')));
             }
             $this->modelUsers->edit($cat);
         }
         return new ViewModel(array('data' => $cat, 'title' => $this->translator->translate('Edit User:') . $cat->getUserName()));
     }
 }
Пример #2
0
 public function addAction()
 {
     $request = $this->getRequest();
     $id = $this->params()->fromRoute('id');
     //insert
     if ($id == '') {
         if ($request->isPost()) {
             $checkExist = Utility::checkUserExist($this->params()->fromPost('userName'));
             if ($checkExist == true) {
                 $this->flashMessenger()->addSuccessMessage("User existed");
                 return $this->redirect()->toRoute('admin/child', array('controller' => 'users', 'action' => 'add'));
             }
             $cat = new User();
             $cat->setUserName($this->params()->fromPost('userName'));
             $cat->setFullName($this->params()->fromPost('fullName'));
             $cat->setPassword(sha1($this->params()->fromPost('password')));
             $cat->setIsdelete(0);
             $cat->setType($this->params()->fromPost('usertype'));
             $userInserted = $this->modelUsers->insert($cat);
             //flash
             $this->flashMessenger()->addSuccessMessage("Insert success");
             return $this->redirect()->toRoute('admin/child', array('controller' => 'users'));
         }
         //insert new user
         //$this->redirect()->toRoute('admin/child',array('controller'=>'category'));
         return new ViewModel(array('title' => $this->translator->translate('Add new user')));
     } else {
         $cat = $this->modelUsers->findOneBy(array('id' => $id));
         if ($request->isPost()) {
             //check exist
             $checkExist = Utility::checkUserExist($this->params()->fromPost('userName'));
             if ($checkExist == true) {
                 $this->flashMessenger()->addSuccessMessage("User existed");
                 return $this->redirect()->toRoute('admin/child', array('controller' => 'users', 'action' => 'add', 'id' => $cat->getId()));
             }
             $idFormPost = $this->params()->fromPost('id');
             $cat = $this->modelUsers->findOneBy(array('id' => $idFormPost));
             $cat->setUserName($this->params()->fromPost('userName'));
             $cat->setFullName($this->params()->fromPost('fullName'));
             $cat->setType($this->params()->fromPost('usertype'));
             if ($this->params()->fromPost('password') != '') {
                 $cat->setPassword(sha1($this->params()->fromPost('password')));
             }
             $this->modelUsers->edit($cat);
             //flash
             $this->flashMessenger()->addSuccessMessage("Update success");
             return $this->redirect()->toRoute('admin/child', array('controller' => 'users'));
         }
         return new ViewModel(array('data' => $cat, 'title' => $this->translator->translate('Edit User:') . $cat->getUserName()));
     }
 }