Ejemplo n.º 1
0
 public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('id');
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $timeformatform = new Default_Form_timeformat();
     $timeformatmodel = new Default_Model_Timeformat();
     try {
         if ($id) {
             $data = $timeformatmodel->getTimeFormatDataByID($id);
             if (!empty($data)) {
                 $timeformatform->populate($data[0]);
                 $timeformatform->setAttrib('action', BASE_URL . 'timeformat/edit/id/' . $id);
                 $this->view->data = $data;
                 $this->view->id = $id;
                 $this->view->ermsg = '';
             } else {
                 $this->view->ermsg = 'norecord';
             }
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->form = $timeformatform;
     if ($this->getRequest()->getPost()) {
         if ($timeformatform->isValid($this->_request->getPost())) {
             $id = $this->_request->getParam('id');
             $timeformat = $this->_request->getParam('timeformat');
             $description = $this->_request->getParam('description');
             $menumodel = new Default_Model_Menu();
             $date = new Zend_Date();
             $actionflag = '';
             $tableid = '';
             $data = array('timeformat' => trim($timeformat), 'description' => trim($description), 'modifiedby' => $loginUserId, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'));
             if ($id != '') {
                 $where = array('id=?' => $id);
                 $actionflag = 2;
             } else {
                 $data['createdby'] = $loginUserId;
                 $data['createddate'] = $date->get('yyyy-MM-dd HH:mm:ss');
                 $data['isactive'] = 1;
                 $where = '';
                 $actionflag = 1;
             }
             $Id = $timeformatmodel->SaveorUpdateTimeFormatData($data, $where);
             if ($Id == 'update') {
                 $tableid = $id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Time format updated successfully."));
             } else {
                 $tableid = $Id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Time format added successfully."));
             }
             $menuidArr = $menumodel->getMenuObjID('/timeformat');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             $this->_redirect('timeformat');
         } else {
             $messages = $timeformatform->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                 }
             }
             $this->view->msgarray = $msgarray;
         }
     }
 }