public function deleteAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $id = $this->_request->getParam('objid'); $messages['message'] = ''; $actionflag = 3; if ($id) { $policiesModel = new Default_Model_Policies(); $policydata = $policiesModel->getPolicyDataByID($id); $data = array('isactive' => 0, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s")); $where = array('id=?' => $id); $Id = $policiesModel->SaveorUpdatePolicyData($data, $where); if ($Id == 'update') { #$menuidArr = $menumodel->getMenuObjID('/policies'); #$menuID = $menuidArr[0]['id']; $menuID = -999; sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id); $messages['message'] = 'Policy deleted successfully.'; $messages['msgtype'] = 'success'; } else { $messages['message'] = 'Policy cannot be deleted.'; $messages['msgtype'] = 'error'; } } else { $messages['message'] = 'Policy cannot be deleted.'; $messages['msgtype'] = 'error'; } $this->_helper->json($messages); $this->_redirect('policies/index'); }
/** * */ public function editAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $sess_vals = $auth->getStorage()->read(); $loginUserId = $auth->getStorage()->read()->id; $loginuserRole = $auth->getStorage()->read()->emprole; $loginuserGroup = $auth->getStorage()->read()->group_id; } $messages['message'] = ''; $id = $this->getRequest()->getParam('id', null); $policiesModel = new Default_Model_Policies(); $where = ""; $actionflag = 1; $policydata = array(); $form = new Default_Form_policies(); $form->setAttrib('action', DOMAIN . 'policies/edit/id/' . $id); try { if ($id > 0 && is_numeric($id)) { //update code $where = ""; $actionflag = 2; $id = abs($id); $policydata = $policiesModel->getPolicyDataByID($id); $form->submit->setLabel('Update'); $this->view->loginuserGroup = $loginuserGroup; $this->view->form = $form; $this->view->data = $policydata; if ($this->getRequest()->getPost()) { #$result = $this->save($form, $policydata); $trDb = Zend_Db_Table::getDefaultAdapter(); // starting transaction $trDb->beginTransaction(); try { $tpolicyname = $this->_getParam('policyname', null); $tversion = $this->_getParam('version', null); $tgroup = $this->_getParam('group', null); $tpolicynotes = $this->_getParam('policynotes', null); $tdocumentname = ''; $tdocumentname = $this->_getParam('policy_documentname', null); if (!isset($tdocumentname) || $tdocumentname == '') { $tdocumentname = $policydata['documentname']; } if ($this->validateInsertOrUpdate($tpolicyname, $tversion, $tgroup, $tpolicynotes, $tdocumentname)) { $policydatalog = array('policyid' => trim($id), 'policyname' => trim($tpolicyname), 'version' => trim($tversion), 'group' => trim($tgroup), 'documentname' => trim($tdocumentname), 'documentnotes' => str_replace("'", "`", trim($tpolicynotes)), 'createdby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s")); $mpolicydata = array('policyname' => trim($tpolicyname), 'version' => trim($tversion), 'group' => trim($tgroup), 'documentname' => trim($tdocumentname), 'documentnotes' => trim($tpolicynotes), 'createdby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s")); $where = array('id=?' => $id); $Id = $policiesModel->SaveorUpdatePolicyData($mpolicydata, $where); $ID1 = $policiesModel->EntryToPolicyLog($policydatalog); if ($Id == 'update') { #$menuidArr = $menumodel->getMenuObjID('/policies'); #$menuID = $menuidArr[0]['id']; $menuID = -999; sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id); $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Policy details successfully updated.")); } else { $this->_helper->getHelper("FlashMessenger")->addMessage(array("error" => "Error while updating Policy details.")); } $trDb->commit(); //Send email to All Employees only if there is an Policy Document change. if ($policydata['documentname'] != $tdocumentname) { $this->SendPolicyEmail($policydatalog, 'Change'); } $this->_redirect('/policies'); } } catch (Exception $e) { $trDb->rollBack(); $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong, please try again later.")); $this->_redirect('/policies'); } } } else { //Insert code $actionflag = 1; if ($this->getRequest()->getPost()) { #$result = $this->save($form, $policydata); $trDb = Zend_Db_Table::getDefaultAdapter(); // starting transaction $trDb->beginTransaction(); try { $tpolicyname = $this->_getParam('policyname', null); $tversion = $this->_getParam('version', null); $tgroup = $this->_getParam('group', null); $tdocumentname = ''; $tdocumentname = $this->_getParam('policy_documentname', null); if (!isset($tdocumentname) || $tdocumentname == '') { $tdocumentname = $policydata['documentname']; } $tpolicynotes = $this->_getParam('policynotes', null); if ($this->validateInsertOrUpdate($tpolicyname, $tversion, $tgroup, $tpolicynotes, $tdocumentname)) { $mpolicydata = array('policyname' => trim($tpolicyname), 'version' => trim($tversion), 'group' => trim($tgroup), 'documentname' => trim($tdocumentname), 'documentnotes' => trim($tpolicynotes), 'createdby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s")); $Id = $policiesModel->SaveorUpdatePolicyData($mpolicydata, $where); $policydatalog = array('policyid' => trim($Id), 'policyname' => trim($tpolicyname), 'version' => trim($tversion), 'group' => trim($tgroup), 'documentname' => trim($tdocumentname), 'documentnotes' => str_replace("'", "`", trim($tpolicynotes)), 'createdby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s")); $ID1 = $policiesModel->EntryToPolicyLog($policydatalog); if ($Id > 0 && is_numeric($Id)) { $menuID = -999; sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id); $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Policy details successfully added.")); } else { $this->_helper->getHelper("FlashMessenger")->addMessage(array("error" => "Error while adding Policy details.")); } $trDb->commit(); $this->SendPolicyEmail($policydatalog, 'New'); $this->_redirect('/policies'); } } catch (Exception $e) { $trDb->rollBack(); $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong, please try again later.")); $this->_redirect('/policies'); } } $form->submit->setLabel('Insert'); $this->view->loginuserGroup = $loginuserGroup; $this->view->form = $form; } } catch (Exception $e) { $this->view->nodata = 'nodata'; } }