public function gettargetcurrencyAction()
 {
     $ajaxContext = $this->_helper->getHelper('AjaxContext');
     $ajaxContext->addActionContext('gettargetcurrency', 'html')->initContext();
     $basecurr_id = $this->_request->getParam('basecurr_id');
     $currencyconverterform = new Default_Form_currencyconverter();
     $currencymodel = new Default_Model_Currency();
     $targetcurrencydata = $currencymodel->getTargetCurrencyList($basecurr_id);
     $this->view->currencyconverterform = $currencyconverterform;
     $this->view->targetcurrencydata = $targetcurrencydata;
 }
 public function save($currencyconverterform)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $currencyconvertermodel = new Default_Model_Currencyconverter();
     $errorflag = 'true';
     $msgarray = array();
     $id = $this->_request->getParam('id');
     $basecurrparam = $this->_request->getParam('basecurrency');
     if ($basecurrparam != '') {
         $basecurrency = $this->_request->getParam('basecurrency');
     }
     $targetcurrparam = $this->_request->getParam('targetcurrency');
     if ($targetcurrparam != '') {
         $targetcurrency = $this->_request->getParam('targetcurrency');
     }
     $exchangerate = $this->_request->getParam('exchangerate');
     $start_date = $this->_request->getParam('start_date');
     $start_date = sapp_Global::change_date($start_date, 'database');
     $end_date = $this->_request->getParam('end_date');
     $end_date = sapp_Global::change_date($end_date, 'database');
     if ($basecurrparam != '' && $targetcurrparam != '' && $basecurrency == $targetcurrency) {
         $errorflag = 'false';
         $msgarray['targetcurrency'] = 'Base currency and target currency cannot be same.';
     }
     if ($currencyconverterform->isValid($this->_request->getPost()) && $errorflag == 'true') {
         try {
             $description = $this->_request->getParam('description');
             $date = new Zend_Date();
             $actionflag = '';
             $tableid = '';
             $cur_names = $currencyconvertermodel->getCurrencyNames($basecurrency, $targetcurrency);
             $basecurrtext = isset($cur_names[$basecurrency]) ? $cur_names[$basecurrency] : "";
             $targetcurrtext = isset($cur_names[$targetcurrency]) ? $cur_names[$targetcurrency] : "";
             $data = array('basecurrency' => $basecurrency, 'targetcurrency' => $targetcurrency, 'basecurrtext' => $basecurrtext, 'targetcurrtext' => $targetcurrtext, 'exchangerate' => trim($exchangerate), 'start_date' => $start_date, 'end_date' => $end_date, 'description' => $description, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($id != '') {
                 $where = array('id=?' => $id);
                 $actionflag = 2;
             } else {
                 $data['createdby'] = $loginUserId;
                 $data['createddate'] = gmdate("Y-m-d H:i:s");
                 $data['isactive'] = 1;
                 $where = '';
                 $actionflag = 1;
             }
             $Id = $currencyconvertermodel->SaveorUpdateCurrencyConverterData($data, $where);
             if ($Id == 'update') {
                 $tableid = $id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Currency converter updated successfully."));
             } else {
                 $tableid = $Id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Currency converter added successfully."));
             }
             $menuID = CURRENCYCONVERTER;
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             $this->_redirect('currencyconverter');
         } catch (Exception $e) {
             $msgarray['basecurrency'] = "Something went wrong, please try again.";
             return $msgarray;
         }
     } else {
         $messages = $currencyconverterform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         if (isset($basecurrparam) && $basecurrparam != 0 && $basecurrparam != '') {
             $currencymodel = new Default_Model_Currency();
             $currdatadata = $currencymodel->getTargetCurrencyList($basecurrency);
             if (sizeof($currdatadata > 0)) {
                 foreach ($currdatadata as $res) {
                     $currencyconverterform->targetcurrency->addMultiOption($res['id'], utf8_encode($res['targetcurr']));
                 }
                 if (isset($targetcurrparam) && $targetcurrparam != 0 && $targetcurrparam != '') {
                     $currencyconverterform->setDefault('targetcurrency', $targetcurrparam);
                 }
             }
         }
         return $msgarray;
     }
 }