public function getstatesAction() { $cnval = $this->_getParam('cnval'); $statesModel = new Timemanagement_Model_States(); $statesData = $statesModel->getStatesByCountryId($cnval); $opt = '<option value=\'\'>Select State</option>'; foreach ($statesData as $state) { $opt .= "<option value='" . $state['id'] . "'>" . $state['state_name'] . "</option>"; } $this->_helper->json(array('options' => utf8_encode($opt))); }
/** * This Action is used to Create/Update the client details based on the client id. * */ public function editAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $objName = 'clients'; $id = $this->getRequest()->getParam('id'); $callval = $this->getRequest()->getParam('call'); if ($callval == 'ajaxcall') { $this->_helper->layout->disableLayout(); } $clientsForm = new Timemanagement_Form_Clients(); $clientsModel = new Timemanagement_Model_Clients(); try { if ($id) { //Edit Record... if (is_numeric($id) && $id > 0) { $data = $clientsModel->getClientDetailsById($id); if (!empty($data) && $data != "norows") { $statesModel = new Timemanagement_Model_States(); $statesData = $statesModel->getStatesByCountryId($data[0]['country_id']); foreach ($statesData as $state) { $clientsForm->state_id->addMultiOption($state['id'], utf8_encode($state['state_name'])); } $clientsForm->populate($data[0]); $clientsForm->submit->setLabel('Update'); $this->view->form = $clientsForm; $this->view->controllername = $objName; $this->view->id = $id; $this->view->ermsg = ''; $this->view->inpage = 'Edit'; } else { $this->view->ermsg = 'norecord'; } } else { $this->view->ermsg = 'nodata'; } } else { //Add Record... $this->view->ermsg = ''; $this->view->form = $clientsForm; $this->view->inpage = 'Add'; } } catch (Exception $e) { $this->view->ermsg = 'nodata'; } if ($this->getRequest()->getPost()) { if ($clientsForm->isValid($this->_request->getPost())) { $country_id = NULL; $state_id = NULL; $id = $this->_request->getParam('id'); $address = $this->_request->getParam('address'); $client_name = $this->_request->getParam('client_name'); if ($this->_request->getParam('country_id')) { $country_id = $this->_request->getParam('country_id'); } $email = $this->_request->getParam('email'); $phone_no = $this->_request->getParam('phone_no'); $poc = $this->_request->getParam('poc'); $fax = $this->_request->getParam('fax'); if ($this->_request->getParam('state_id')) { $state_id = $this->_request->getParam('state_id'); } $date = gmdate("Y-m-d H:i:s"); $data = array('address' => $address, 'client_name' => $client_name, 'country_id' => $country_id, 'email' => $email, 'phone_no' => $phone_no, 'poc' => $poc, 'fax' => $fax, 'state_id' => $state_id); if ($id != '') { $data['modified_by'] = $loginUserId; $data['modified'] = $date; $where = array('id=?' => $id); } else { $data['created_by'] = $loginUserId; $data['created'] = $date; $data['modified'] = $date; $data['is_active'] = 1; $where = ''; } $Id = $clientsModel->saveOrUpdateClientsData($data, $where); if ($Id == 'update') { $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Client updated successfully.")); } else { $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Client added successfully.")); } $this->_redirect('timemanagement/clients'); } else { $messages = $clientsForm->getMessages(); foreach ($messages as $key => $val) { foreach ($val as $key2 => $val2) { $msgarray[$key] = $val2; break; } } $this->view->msgarray = $msgarray; } } }