public function saveAction()
 {
     $update = false;
     $erro = false;
     $cddepartmentparent = $this->_request->getParam("cddepartmentparent");
     $cddepartment = $this->_request->getParam("cddepartment");
     $cddcompany = $this->_request->getParam("cdcompany");
     //        var_dump($this->_request->getParams());
     //        die();
     if ($cddcompany == '' && $cddepartmentparent == '' && $cddepartment == '') {
         $this->addMessage("Selecione uma pasta na arvore de setores.");
         $this->_redirect("/message/error/param_module/cadastre/param_controller/department/param_action/index");
     } else {
         parent::saveAction();
         $columns = $this->_model->info(Zend_Db_Table_Abstract::COLS);
         $array = array();
         $this->_model->getAdapter()->beginTransaction();
         try {
             foreach ($this->_values as $id => $value) {
                 if (isset($value) && $value != '' && in_array($id, $columns)) {
                     $array[$id] = addslashes($value);
                 }
             }
             if ($cddepartment != '') {
                 $departmentModel = new DepartmentModel();
                 if (isset($array['cddepartmentparent'])) {
                     $validate = $departmentModel->validateUpdateDepartment($array['cddepartmentparent'], $cddepartment);
                     if ($validate->nmdepartment == null || $validate->nmdepartment == '') {
                         $this->_model->update($array, 'cddepartment=' . $cddepartment);
                         $update = true;
                     } else {
                         $this->addMessage("Não pode ser alterado.");
                         $erro = true;
                     }
                 } else {
                     $array['cddepartmentparent'] = null;
                     $this->_model->update($array, 'cddepartment=' . $cddepartment);
                     $update = true;
                 }
             } else {
                 $this->_model->insert($array);
                 $insertdep_cddepartment = $this->_model->getAdapter()->lastInsertId($this->_controller);
             }
             $departmentCompanyModel = new CompanydepartmentModel();
             $columnsDepatmentCompany = $departmentCompanyModel->info(Zend_Db_Table_Abstract::COLS);
             $arrayDepartementCompany = array();
             foreach ($this->_values as $id => $value) {
                 if (isset($this->_values) && $value != '' && in_array($id, $columnsDepatmentCompany)) {
                     $arrayDepartementCompany[$id] = addslashes($value);
                 }
             }
             if ($cddcompany != '0' && $cddepartment != '') {
                 //die($cddcompany);
                 $array = array('cdcompany' => $arrayDepartementCompany, 'cddepartment' => $cddepartment);
                 $arrayDepartementCompany["cdcompany"] = $cddcompany;
                 $departmentCompanyModel->update($arrayDepartementCompany, 'cddepartment=' . $cddepartment);
                 $update = true;
             } else {
                 //die($cddcompany);
                 if ($cddepartment == '' && $cddcompany != '0') {
                     $arrayDepartementCompany["cdcompany"] = $cddcompany;
                     $arrayDepartementCompany["cddepartment"] = addslashes($insertdep_cddepartment);
                     $departmentCompanyModel->insert($arrayDepartementCompany);
                 }
             }
             $this->_model->getAdapter()->commit();
         } catch (Exception $e) {
             $this->_model->getAdapter()->rollBack();
             $this->addMessage($e->getMessage());
             $this->addMessage("Erro na inserção dos dados.");
             $erro = true;
         }
         if ($erro == true) {
             $this->_redirect($this->redirectLink("error", "cadastre", "department", "index"));
         }
         if ($update == true) {
             $this->addMessage("Registro alterado com sucesso.");
         } else {
             $this->addMessage("Registro Incluido com sucesso.");
         }
         $this->_redirect($this->redirectLink("success", "cadastre", "department", "index"));
     }
 }