/** * Edit Contact */ public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Contacts"), $this->view->translate("Edit"))); $id = $this->_request->getParam('id'); $obj = new Snep_Contacts_Manager(); $select = $obj->select()->where('id_contact = ?', $id); $contact = $obj->fetchRow($select)->toArray(); Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index'); $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/contacts.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/edit/id/' . $id); $idco = new Zend_Form_Element_Hidden('id_contact'); $idco->setValue($contact['id_contact']); $form->getElement('id')->setValue($contact['id_contact'])->setAttrib('readonly', true); $form->getElement('name')->setValue($contact['ds_name']); $form->getElement('address')->setValue($contact['ds_address']); /* * Combo de Grupos */ $group = new Snep_ContactGroups_Manager(); $_allGroups = $group->fetchAll(); foreach ($_allGroups as $group) { $allGroups[$group['id_contact_group']] = $group['ds_name']; } if (count($_allGroups)) { $form->getElement('group')->setMultiOptions($allGroups); $form->getElement('group')->setValue($contact['id_contact_group']); } isset($contact['group']) ? $group->setValue($contact['id_contact_group']) : null; /* * Combo de Cidades * */ $city = new Snep_City_Manager(); $_allCities = $city->fetchAll(); foreach ($_allCities as $city) { $allCities[$city['ds_name']] = $city['ds_name']; } if (count($_allCities)) { $form->getElement('city')->setMultiOptions($allCities)->addMultiOption($contact['ds_city'], $contact['ds_city'])->setValue($contact['ds_city']); } /* * Combo de Estado * */ $state = new Snep_State_Manager(); $_allStates = $state->fetchAll(); foreach ($_allStates as $state) { $allStates[$state['ds_name']] = $state['ds_name']; } if (count($_allStates)) { $form->getElement('state')->setMultiOptions($allStates)->addMultiOption($contact['ds_state'], $contact['ds_state'])->setValue($contact['ds_state']); } $form->getElement('zipcode')->setValue($contact['ds_cep']); $form->getElement('phone')->setValue($contact['ds_phone']); $form->getElement('cell')->setValue($contact['ds_cell_phone']); if ($this->_request->getPost()) { $_POST['id'] = trim($_POST['id']); $form_isValid = $form->isValid($_POST); $dados = array('ds_name' => $_POST['name'], 'id_contact_group' => $_POST['group'], 'ds_address' => $_POST['address'], 'ds_city' => $_POST['city'], 'ds_state' => $_POST['state'], 'ds_cep' => $_POST['zipcode'], 'ds_phone' => $_POST['phone'], 'ds_cell_phone' => $_POST['cell']); if ($form_isValid) { $contact = new Snep_Contacts_Manager(); $contact->update($dados, "id_contact = {$_POST['id']}"); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }
/** * Migrate contacts to other Contact Group */ public function migrationAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Contact Group"), $this->view->translate("Migrate Contacts"))); $id = $this->_request->getParam('id'); $groupAll = new Snep_ContactGroups_Manager(); $_allGroups = $groupAll->fetchAll(); foreach ($_allGroups as $group) { if ($group['id_contact_group'] != $id) { $allGroups[$group['id_contact_group']] = $group['ds_name']; } } Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index'); $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/contact_groups_migration.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/contact-groups/migration/stage/2'); if (isset($allGroups)) { $form->getElement('group')->setMultiOptions($allGroups); $form->getElement('option')->setMultiOptions(array('migrate' => 'migrate contacts to group', 'remove' => 'remove all'))->setValue('migrate'); } else { $form->removeElement('group'); $form->getElement('option')->setMultiOptions(array('remove' => 'remove all')); } $this->view->message = $this->view->translate("The excluded group has associated contacts."); $form->getElement('id')->setValue($id); $stage = $this->_request->getParam('stage'); if (isset($stage['stage']) && $id) { if ($_POST['option'] == 'migrate') { $obj = new Snep_Contacts_Manager(); $select = $obj->select()->where('id_contact_group = ?', $id); $contacts = $obj->fetchAll($select)->toarray(); $idGroup = $_POST['group']; $dadosUpdate = array('id_contact_group' => $idGroup); foreach ($contacts as $contactselect) { $idContact = $contactselect['id_contact']; $obj->update($dadosUpdate, "id_contact = {$idContact}"); } $groupAll->delete("id_contact_group ={$id}"); } elseif ($_POST['option'] == 'remove') { $obj = new Snep_Contacts_Manager(); $select = $obj->select()->where('id_contact_group = ?', $id); $contacts = $obj->fetchAll($select)->toArray(); foreach ($contacts as $contact) { $idContact = $contact['id_contact']; $obj->delete("id_contact = {$idContact}"); } $groupAll->delete("id_contact_group ={$id}"); } $this->_redirect($this->getRequest()->getControllerName()); } $this->view->form = $form; }