public function saveAction()
 {
     parent::saveAction();
     $values = $this->_form->getValues();
     $columns = $this->_model->info(Zend_Db_Table_Abstract::COLS);
     $array = array();
     $this->_model->getAdapter()->beginTransaction();
     try {
         foreach ($values as $id => $value) {
             if (isset($value) && $value != '' && in_array($id, $columns)) {
                 $array[$id] = addslashes($value);
             }
         }
         $this->_model->insert($array);
         $cdclient = $this->_model->getAdapter()->lastInsertId($this->_controller);
         $clientphonunber = new ClientphonenumberModel();
         $columnsClientPhonunber = $clientphonunber->info(Zend_Db_Table_Abstract::COLS);
         $arrayClientPhonunber = array();
         foreach ($values as $id => $value) {
             if (isset($value) && $value != '' && in_array($id, $columnsClientPhonunber)) {
                 $arrayClientPhonunber[$id] = addslashes($value);
             }
         }
         $arrayClientPhonunber["cdclient"] = addslashes($cdclient);
         $clientphonunber->insert($arrayClientPhonunber);
         $clientAddress = new ClientaddressModel();
         $columnsClientAddress = $clientAddress->info(Zend_Db_Table_Abstract::COLS);
         $arrayClientAddress = array();
         foreach ($values as $id => $value) {
             if (isset($value) && $value != '' && in_array($id, $columnsClientAddress)) {
                 $arrayClientAddress[$id] = addslashes($value);
             }
         }
         $arrayClientAddress["cdclient"] = addslashes($cdclient);
         $clientAddress->insert($arrayClientAddress);
         $this->_model->getAdapter()->commit();
     } catch (Exception $e) {
         $this->_model->getAdapter()->rollBack();
         $this->addMessage($e->getMessage());
         $this->addMessage("Erro na inserção dos dados.");
         $url = '/cadastre/message/index';
         $this->_redirect($url);
     }
     $this->addMessage("Cadastro efetuado com sucesso.");
     $url = '/cadastre/message/index';
     $this->_redirect($url);
 }
 public function editAction()
 {
     $cdclient = $this->_request->getParam("cdclient");
     $addressTypeModel = new AddresstypeModel();
     $this->view->addressTypeData = $addressTypeModel->getAllAddressType();
     $clientModel = new ClientModel();
     $clientadressModel = new ClientaddressModel();
     $clientphoneModel = new ClientphonenumberModel();
     $clientaddressData = $clientadressModel->fetchRow();
     $client = $clientModel->fetchRow('cdclient = ' . $cdclient);
     $this->view->client = $client;
     $age = $this->view->client->dtbirth;
     $data = new Zend_Date($this->view->client->dtbirth, "YYYY-MM-dd HH:mm:ss");
     $this->view->client->dtbirth = $data->toString('dd-MM-YYYY');
     $this->view->nrage = GslabUtils::calcAgeDifferenceShort($age);
     $this->view->address = $clientadressModel->fetchRow($clientadressModel->getStateById($clientaddressData['idstate'], $cdclient));
     $clientphoneData = $clientphoneModel->fetchRow('cdclient = ' . $cdclient);
     $this->view->phone = $clientphoneData;
     if ($client['dtdum'] != '') {
         $client['dtdum'] = new Zend_Date($this->view->client->dtdum, "YYYY-MM-dd HH:mm:ss");
         $this->view->dtdum = $client['dtdum']->toString('dd-MM-YYYY');
     } else {
         $this->view->dtdum = '';
     }
     if ($clientphoneData['cdclientphonenumber'] != '') {
         $cdclientphonenumber = $clientphoneData['cdclientphonenumber'];
         if ($clientphoneData['nrphonenumber'] != '') {
             $phonenumber = $clientphoneData['nrphonenumber'];
             $dddphonenumber = $clientphoneData['nrdddphone'];
         } else {
             $phonenumber = '';
             $dddphonenumber = '';
         }
         if ($clientphoneData['nrcellphonenumber'] != '') {
             $cellphonenumber = $clientphoneData['nrcellphonenumber'];
             $dddcellphonenumber = $clientphoneData['nrdddcellphone'];
         } else {
             $cellphonenumber = '';
             $dddcellphonenumber = '';
         }
     } else {
         $phonenumber = '';
         $dddphonenumber = '';
         $cdclientphonenumber = '';
         $cellphonenumber = '';
         $dddcellphonenumber = '';
     }
     $this->view->nrphonenumber = $phonenumber;
     $this->view->nrcellphonenumber = $cellphonenumber;
     $this->view->nrdddphone = $dddphonenumber;
     $this->view->nrdddcellphone = $dddcellphonenumber;
     $this->view->cdclientphonenumber = $cdclientphonenumber;
 }