/** * 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; }
/** * Add Queue */ public function addAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Carrier"), $this->view->translate("Add"))); $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/queues.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/add'); $this->view->url = $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName(); $carrier = new Snep_Carrier_Manager(); foreach ($carrier->fetchAll() as $_carrier) { $carriers[$_carrier['id_carrier']] = $_carrier['ds_name']; } $this->view->carriers = $carriers; $states['--'] = '--'; $statesList = new Snep_State_Manager(); foreach ($statesList->fetchAll() as $state) { $states[$state['id_state']] = $state['ds_name']; } $this->view->states = $states; $cities['--'] = '--'; foreach (Snep_Billing_Manager::getCity('AC') as $city) { $cities[$city['name']] = $city['name']; } $this->view->cities = $cities; $dados = $this->_request->getParams(); if ($this->_request->getPost()) { $form_isValid = true; $this->view->error = array(); if (!preg_match('/[0-9]+$/', $dados['ddd']) || $dados['ddd'] == "") { $form_isValid = false; $this->view->error['ddd'] = $this->view->translate("City Code not numeric"); } if (!preg_match('/[0-9]+$/', $dados['ddi']) || $dados['ddi'] == "") { $form_isValid = false; $this->view->error['ddi'] = $this->view->translate("Country Code not numeric"); } if (!preg_match('/[0-9]+$/', $dados['prefixo']) || $dados['prefixo'] == "") { $form_isValid = true; $this->view->error['prefixo'] = $this->view->translate("Prefix not numeric"); } if ($dados['operadora'] == "") { $form_isValid = false; $this->view->error['operadora'] = $this->view->translate("Carrier not selected "); } if ($form_isValid) { if ($_POST['ddd'] == "") { $_POST['ddd'] = 0; } if ($_POST['ddi'] == "") { $_POST['ddi'] = 0; } $billing = Snep_Billing_Manager::getPrefix($_POST); if ($billing) { $form_isValid = false; $this->view->message = $this->view->translate("This bill is already set"); } } if ($form_isValid) { $xdados = array('data' => $_POST['data'], 'carrier' => $_POST['operadora'], 'country_code' => $_POST['ddi'], 'country' => $_POST['pais'], 'city_code' => $_POST['ddd'], 'city' => $_POST['cidade'], 'state' => $_POST['estado'], 'prefix' => $_POST['prefixo'], 'tbf' => $_POST['vfix'], 'tbc' => $_POST['vcel']); Snep_Billing_Manager::add($xdados); $this->_redirect($this->getRequest()->getControllerName()); } $this->view->dados = isset($dados) ? $dados : null; } }