Esempio n. 1
0
 /**
  * get update page + update
  * @return ViewModel
  */
 public function editAction()
 {
     $err_msg = "";
     $this->init();
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toUrl(BASE_URL);
     }
     $this->selfEditCheck();
     $db = new WorkUserEntity();
     // get update information from DB
     $postRequest = $this->container()->get('postRequest');
     if ($postRequest) {
         $this->container()->clear('postRequest');
         $row = get_array_object(json_decode($postRequest, true));
     } else {
         $work_no = $this->container()->get('work_no');
         $row = $db->db()->getFetchRow($id, $this->auth()->get('user_no'), $work_no);
     }
     $form = new WorkUserForm();
     $form->setEditForm($this->auth()->get('branch_no'));
     $filter = new WorkUserFilter();
     $success = false;
     // if not exist target record
     if (!$row || $row->deleted) {
         $this->flashMessenger()->addMessage('Target does not exist');
         //            $this->flashMessenger()->addMessage('指定レコードは存在しません。');
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
     }
     $request = $this->getRequest();
     // get edit page
     if (!$request->isPost()) {
         $form->bind($row);
         $beforeData = make_before_data($row, 'tmp_user_no');
         if ($beforeData) {
             $form->bind($beforeData);
         }
     } else {
         $token_id = $this->container()->get('token_id');
         $this->container()->clear('token_id');
         $filter->setCreateToken($token_id);
         $form->setInputFilter($filter->getInputFilter());
         $form->setData($request->getPost());
         $success = $form->isValid();
         if ($success) {
             $success = check_change_data($request->getPost());
             $err_msg = $success ? '' : 'Not changed';
             //                $err_msg = $success ? '' : '変更を確認できません。';
         }
         if ($success) {
             $work_no = $this->container()->get('work_no');
             // update
             $stat = $request->getPost('login_id') != $request->getPost('before_login_id') ? true : false;
             $success = $db->updateRecord($this->auth()->get('user_no'), $form->getData(), $work_no, $stat);
         } else {
             // set result to form
             $data = $form->getInputFilter()->getValues();
             $form->bind(get_array_object($data));
         }
         if (false !== $success) {
             $this->flashMessenger()->addMessage("Success");
             //                $this->flashMessenger()->addMessage("成功しました。");
             return $this->redirect()->toRoute('app', array('controller' => 'work-user', 'action' => 'list'));
         }
     }
     $token_id = make_token_id();
     $this->container()->set('token_id', $token_id);
     $form->get('token_id')->setAttribute('value', $token_id);
     $form->get('submit')->setAttribute('value', 'Update');
     //        $form->get('submit')->setAttribute('value', '更新');
     $form->get('reset')->setAttribute('value', 'Reset');
     //        $form->get('reset')->setAttribute('value', 'リセット');
     $values = array('id' => $id, 'form' => $form, 'err_msg' => $err_msg);
     $view = new ViewModel($values);
     $view->setTemplate('/' . VIEW_DIR . '/work-user/edit.phtml');
     return $view;
 }
Esempio n. 2
0
 /**
  * get update page + update processing
  * @return ViewModel
  */
 public function editAction()
 {
     $this->init();
     $err_msg = "";
     // check auth by id
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         $success = false;
     } else {
         if ($id == $this->auth()->get('user_no')) {
             $self = true;
             $success = true;
         } else {
             $self = false;
             $success = 2 < $this->ctrlLv ? true : false;
         }
     }
     // redirect to error page
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden'));
     }
     $db = new UserEntity();
     // get update information from DB
     $postRequest = $this->container()->get('postRequest');
     if ($postRequest) {
         $this->container()->clear('postRequest');
         $row = get_array_object(json_decode($postRequest, true));
     } else {
         $row = $db->db()->getFetchOne($id);
     }
     $form = new UserForm();
     if ($this->auth()->get('admin')) {
         $branch_no = $row->branch_no;
     } else {
         $branch_no = $this->auth()->get('branch_no');
     }
     $form->setEditForm(null, $branch_no);
     $filter = new UserFilter();
     $success = false;
     if (!$row || $row->deleted) {
         $this->flashMessenger()->addMessage('Target does not exist');
         //            $this->flashMessenger()->addMessage('指定レコードは存在しません。');
     } else {
         if (!$this->auth()->get('admin') && $this->auth()->get('branch_no') != $row->branch_no) {
             $this->flashMessenger()->addMessage('Not allowed');
             //            $this->flashMessenger()->addMessage('許可されていません。');
         } else {
             $success = true;
         }
     }
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
     }
     $request = $this->getRequest();
     // get update page
     if (!$request->isPost()) {
         $form->bind($row);
         $beforeData = make_before_data($row, 'user_no');
         if ($beforeData) {
             $form->bind($beforeData);
         }
     } else {
         // update only belonging branch
         // user can't update position and section
         if ($self && ($row->section_no != $this->params()->fromPost('section_no') || $row->position_no != $this->params()->fromPost('position_no')) || !$this->auth()->get('admin') && $this->auth()->get('branch_no') != $this->params()->fromPost('branch_no')) {
             $this->flashMessenger()->addMessage('Not allowed');
             //                $this->flashMessenger()->addMessage('許可されていません。');
             return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
         }
         $token_id = $this->container()->get('token_id');
         $this->container()->clear('token_id');
         $filter->setCreateToken($token_id);
         $form->setInputFilter($filter->getInputFilter());
         $form->setData($request->getPost());
         $success = $form->isValid();
         if ($success) {
             $success = check_change_data($request->getPost());
             $success = true;
             // temporary hack
             $err_msg = $success ? '' : 'Not changed';
             //                $err_msg = $success ? '' : '変更を確認できません。';
         }
         if ($success) {
             // update
             $success = $db->updateUser($this->auth()->get('user_no'), $form->getData());
         } else {
             // set result to form
             $data = $form->getInputFilter()->getValues();
             $form->bind(get_array_object($data));
         }
         if (false !== $success && $self) {
             $this->container()->setContainer('user_auth');
             $this->container()->set('user_name', $request->getPost('user_name'));
             $this->container()->set('timezone', $request->getPost('timezone'));
             setcookie('timezone', $request->getPost('timezone'), time() + 60 * 60 * 24 * 30, '/', BASE_DOMAIN);
             $lang = new \App\Model\Table\LanguageTable();
             $row = $lang->getFetchOne($request->getPost('lang_no'));
             $this->container()->set('lang_id', $row->lang_id);
             $this->container()->set('resource_id', $row->resource_id);
             setcookie('lang_id', $row->lang_id, time() + 60 * 60 * 24 * 30, '/', BASE_DOMAIN);
             setcookie('resource_id', $row->resource_id, time() + 60 * 60 * 24 * 30, '/', BASE_DOMAIN);
         }
         if (false !== $success) {
             $this->flashMessenger()->addMessage("Success");
             //                $this->flashMessenger()->addMessage("成功しました。");
             return $this->redirect()->toRoute('app', array('controller' => 'user', 'action' => 'detail', 'id' => $id));
         }
     }
     $token_id = make_token_id();
     $this->container()->set('token_id', $token_id);
     $form->get('token_id')->setAttribute('value', $token_id);
     $form->get('submit')->setAttribute('value', 'Update');
     //        $form->get('submit')->setAttribute('value', '更新');
     $form->get('reset')->setAttribute('value', 'Reset');
     //        $form->get('reset')->setAttribute('value', 'リセット');
     if (!$this->auth()->get('admin')) {
         $form->setData(array('branch_no' => $this->auth()->get('branch_no')));
     }
     $values = array('id' => $id, 'self' => $self, 'action' => 'edit', 'form' => $form, 'admin' => $this->auth()->get('admin'), 'err_msg' => $err_msg);
     $view = new ViewModel($values);
     $view->setTemplate('/' . VIEW_DIR . '/user/edit.phtml');
     return $view;
 }
Esempio n. 3
0
 /**
  * get update page + update processing
  * @return ViewModel
  */
 public function editAction()
 {
     $this->init();
     $err_msg = '';
     // check target and auth by id
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         $success = false;
     } else {
         $success = 2 < $this->ctrlLv ? true : false;
     }
     // redirect to error page
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden'));
     }
     $form = new PositionForm();
     $form->setEditForm();
     $db = new PositionEntity();
     $filter = new PositionFilter();
     // get update information from DB
     $postRequest = $this->container()->get('postRequest');
     if ($postRequest) {
         $this->container()->clear('postRequest');
         $row = get_array_object(json_decode($postRequest, true));
     } else {
         $row = $db->db()->getFetchOne($id);
     }
     // if not exist target record
     $success = false;
     if (!$row || $row->deleted) {
         $this->flashMessenger()->addMessage('Target does not exist');
         //            $this->flashMessenger()->addMessage('指定レコードは存在しません。');
     } else {
         if (!$this->auth()->get('admin') && $this->auth()->get('branch_no') != $row->branch_no) {
             $this->flashMessenger()->addMessage('Not allowed');
             //            $this->flashMessenger()->addMessage('許可されていません。');
         } else {
             $success = true;
         }
     }
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
     }
     $request = $this->getRequest();
     // get update page
     if (!$request->isPost()) {
         $form->bind($row);
         $beforeData = make_before_data($row, 'position_no');
         if ($beforeData) {
             $form->bind($beforeData);
         }
     } else {
         // check belonging to branch
         if ($this->auth()->get('branch_no') != $this->params()->fromPost('branch_no') && !$this->auth()->get('admin')) {
             $this->flashMessenger()->addMessage('Not allowed');
             //                $this->flashMessenger()->addMessage('許可されていません。');
             return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
         }
         $token_id = $this->container()->get('token_id');
         $this->container()->clear('token_id');
         $filter->setCreateToken($token_id);
         $form->setInputFilter($filter->getInputFilter());
         $form->setData($request->getPost());
         $success = $form->isValid();
         if ($success) {
             $success = check_change_data($request->getPost());
             $err_msg = $success ? '' : 'Not changed';
             //                $err_msg = $success ? '' : '変更を確認できません。';
         }
         if ($success) {
             // update
             $success = $db->updateRecord($this->auth()->get('user_no'), $form->getData());
         } else {
             // set result to form
             $data = $form->getInputFilter()->getValues();
             $form->bind(get_array_object($data));
         }
         if (false !== $success) {
             $this->flashMessenger()->addMessage("Success");
             //                $this->flashMessenger()->addMessage("成功しました。");
             return $this->redirect()->toRoute('app', array('controller' => 'position', 'action' => 'list'));
         }
     }
     $token_id = make_token_id();
     $this->container()->set('token_id', $token_id);
     $form->get('token_id')->setAttribute('value', $token_id);
     $form->get('submit')->setAttribute('value', 'Update');
     //        $form->get('submit')->setAttribute('value', '更新');
     $form->get('reset')->setAttribute('value', 'Reset');
     //        $form->get('reset')->setAttribute('value', 'リセット');
     if (!$this->auth()->get('admin')) {
         $form->setData(array('branch_no' => $this->auth()->get('branch_no')));
     }
     $values = array('id' => $id, 'action' => 'edit', 'form' => $form, 'admin' => $this->auth()->get('admin'), 'err_msg' => $err_msg);
     $view = new ViewModel($values);
     $view->setTemplate('/' . VIEW_DIR . '/position/edit.phtml');
     return $view;
 }
Esempio n. 4
0
 /**
  * get update page + update processing
  * @return ViewModel
  */
 public function editAction()
 {
     $this->init();
     $err_msg = '';
     // check auth by id
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         $success = false;
     } else {
         $success = 2 < $this->ctrlLv ? true : false;
     }
     // redirect to error page
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden'));
     }
     $db = new RoleEntity();
     // get update information from db
     $postRequest = $this->container()->get('postRequest');
     if ($postRequest) {
         $this->container()->clear('postRequest');
         $row = get_array_object(json_decode($postRequest, true));
     } else {
         $row = $db->db()->getFetchOne($id);
     }
     // if not exist target record
     $success = false;
     if (!$row || $row->deleted) {
         $this->flashMessenger()->addMessage('Target does not exist');
         //            $this->flashMessenger()->addMessage('指定レコードは存在しません。');
     } else {
         if (!$this->auth()->get('admin') && $this->auth()->get('branch_no') != $row->branch_no) {
             $this->flashMessenger()->addMessage('Not allowed');
             //            $this->flashMessenger()->addMessage('許可されていません。');
         } else {
             $success = true;
         }
     }
     if (!$success) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
     }
     $request = $this->getRequest();
     $branch_no = $this->auth()->get('branch_no');
     if ($this->auth()->get('admin')) {
         $branch_no = !$request->isPost() ? $row->branch_no : $request->getPost('branch_no');
     }
     $form_opt = array('name' => !$request->isPost() && !$postRequest ? 'edit' : 'faild', 'user_no' => isset($row->user_no) && $row->user_no ? $row->user_no : $request->getPost('user_no'), 'branch_no' => $branch_no, 'role_no' => (int) $id);
     $form = new RoleForm();
     $form->setEditForm($form_opt);
     $filter = new RoleFilter();
     // get update page
     if (!$request->isPost()) {
         $form->bind($row);
         $beforeData = make_before_data($row, 'role_no');
         if ($beforeData) {
             $form->bind($beforeData);
         }
         $users = array();
         $rows = $db->db()->getRoleUserPairs($id);
         $users = array_keys($rows);
         $levels = array();
         $ctrlList = $db->db()->getRoleCtrl($id)->toArray();
         foreach ($ctrlList as $r) {
             $levels[gv('controller_no', $r)] = gv('level', $r);
         }
         $beforeData = array('before_user_no' => $users, 'before_level' => $levels);
     } else {
         // check belonging branch
         if ($this->auth()->get('branch_no') != $this->params()->fromPost('branch_no') && !$this->auth()->get('admin')) {
             $this->flashMessenger()->addMessage('Not allowed');
             //                $this->flashMessenger()->addMessage('許可されていません。');
             return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'index'));
         }
         $token_id = $this->container()->get('token_id');
         $this->container()->clear('token_id');
         $filter->setCreateToken($token_id);
         $form->setInputFilter($filter->getInputFilter());
         $form->setData($request->getPost());
         $success = $form->isValid();
         if ($success) {
             $success = check_change_data($request->getPost());
             $err_msg = $success ? '' : 'Not cahnged';
             //                $err_msg = $success ? '' : '変更を確認できません。';
         }
         if ($success) {
             // update
             $chg_user = $request->getPost('user_no') != $request->getPost('before_user_no');
             $chg_lv = $request->getPost('level') != $request->getPost('before_level');
             $chg = array('chg_user' => $chg_user, 'chg_lv' => $chg_lv);
             $success = $db->updateRecord($this->auth()->get('user_no'), $form->getData(), $chg);
         } else {
             // set result to form
             $data = $form->getInputFilter()->getValues();
             $form->bind(get_array_object($data));
         }
         if (false !== $success) {
             $this->flashMessenger()->addMessage("Success");
             //                $this->flashMessenger()->addMessage("成功しました。");
             return $this->redirect()->toRoute('app', array('controller' => 'role', 'action' => 'list'));
         }
         $beforeData = array('before_user_no' => $request->getPost('before_user_no'), 'before_level' => $request->getPost('before_level'));
         $ctrl = new ControllerTable();
         $ctrlList = $ctrl->search(array('deleted <> 1'), array('controller_no' => 'ASC'), null, null);
     }
     $token_id = make_token_id();
     $this->container()->set('token_id', $token_id);
     $form->get('token_id')->setAttribute('value', $token_id);
     $form->get('section_no')->setAttribute('value', '');
     $form->get('submit')->setAttribute('value', 'Update');
     //        $form->get('submit')->setAttribute('value', '更新');
     $form->get('reset')->setAttribute('value', 'Reset');
     //        $form->get('reset')->setAttribute('value', 'リセット');
     if (!$this->auth()->get('admin')) {
         $form->setData(array('branch_no' => $this->auth()->get('branch_no')));
     }
     $values = array('id' => $id, 'action' => 'edit', 'form' => $form, 'admin' => $this->auth()->get('admin'), 'err_msg' => $err_msg, 'ctrlList' => $ctrlList, 'form_level' => $request->getPost('level'), 'beforeData' => $beforeData);
     $view = new ViewModel($values);
     $view->setTemplate('/' . VIEW_DIR . '/role/edit.phtml');
     return $view;
 }