private function telType($telefone) { $prefixo = 0; if (strlen($telefone) == 6) { $prefixo = $telefone; } elseif (strlen($telefone) > 6) { $prefixo = substr($telefone, 0, strlen($telefone) - 4); if (strlen($prefixo) > 6) { $prefixo = substr($prefixo, -6); } } else { $prefixo = $telefone; } if (!is_numeric($prefixo)) { $cidade = $this->view->translate('Unknown'); } try { $cidade = ''; $city = Snep_Cnl::getCidade($prefixo); if (sizeof($city) > 0) { $cidade = $city[0]['municipio'] . ' - ' . $city[0]['estado']; } if (strlen($cidade) <= 3) { if (strlen($telefone) >= 8 && substr($prefixo, -4, 1) > 6) { $cidade = $this->view->translate('Cellphone'); } else { if (strlen($telefone) >= 14) { $cidade = $this->view->translate('D.D.I'); } else { $cidade = $this->view->translate('Local'); } } } } catch (Exception $e) { $cidade = $e; } return $cidade; }
public function indexAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Configure"), $this->view->translate("CNL Update"))); $config = Zend_Registry::get('config'); $this->view->pathweb = $config->system->path->web; // verification procedure $db = Zend_Registry::get('db'); $select = $db->select()->from('state'); $stmt = $select->query(); $result = $stmt->fetchAll(); // insert state data if (count($result) < 26) { $brStates = array('AC' => 'Acre', 'AL' => 'Alagoas', 'AM' => 'Amazonas', 'AP' => 'Amapá', 'BA' => 'Bahia', 'CE' => 'Ceará', 'DF' => 'Distrito Federal', 'ES' => 'Espírito Santo', 'GO' => 'Goiás', 'MA' => 'Maranhão', 'MG' => 'Minas Gerais', 'MS' => 'Mato Grosso do Sul', 'MT' => 'Mato Grosso', 'PA' => 'Pará', 'PB' => 'Paraíba', 'PE' => 'Pernambuco', 'PI' => 'Piauí', 'PR' => 'Paraná', 'RJ' => 'Rio de Janeiro', 'RN' => 'Rio Grande do Norte', 'RO' => 'Rondônia', 'RR' => 'Roraima', 'RS' => 'Rio Grande do Sul', 'SC' => 'Santa Catarina', 'SE' => 'Sergipe', 'SP' => 'São Paulo', 'TO' => 'Tocantins'); foreach ($brStates as $uf => $state) { $db->beginTransaction(); try { $_state = array('ds_code' => $uf, 'ds_name' => $state); $db->insert('state', $_state); $db->commit(); } catch (Exception $ex) { $db->rollBack(); throw $ex; } } } $form = new Snep_Form(); $form->setAction($this->getFrontController()->getBaseUrl() . "/default/cnl/index"); $this->view->formAction = $this->getFrontController()->getBaseUrl() . "/default/cnl/index"; $element = new Zend_Form_Element_File('cnl'); $element->setLabel($this->view->translate('CNL File'))->setDestination('/tmp/')->setRequired(true); $element->addValidator('Extension', false, array('bz2', 'json')); $element->removeDecorator('DtDdWrapper'); $form->addElement($element, 'cnl'); $form->getElement("submit")->setLabel($this->view->translate("Save")); $form->setAttrib('enctype', 'multipart/form-data'); $this->view->valid = true; if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); $this->view->valid = $form_isValid; if ($form_isValid) { $data = $_POST; $adapter = new Zend_File_Transfer_Adapter_Http(); if ($adapter->isValid()) { $adapter->receive(); $fileName = $adapter->getFileName(); $json = file_get_contents($fileName); $cnl = Zend_Json_Decoder::decode($json, Zend_Json::TYPE_ARRAY); $data = $cnl["operadoras"]; unset($cnl["operadoras"]); $db->delete('city_code'); $db->delete('carrier_prefix'); $db->delete('city'); foreach ($data as $carrier => $id) { Snep_Cnl::addOperadora($id, $carrier); } foreach ($cnl as $data => $id) { foreach ($id as $state => $es) { foreach ($es as $ddd => $d) { foreach ($d as $city => $pre) { $stateId = Snep_Cnl::fetchStateId($state); $cityId = Snep_Cnl::addCidade($city); Snep_Cnl::addDDD($ddd, $stateId, $cityId); foreach ($pre as $prefix => $op) { Snep_Cnl::addPrefixo($prefix, $cityId, $op); } } } } } $this->view->message = $this->view->translate('A lista de informações CNL foi atualizada com sucesso.'); } else { throw new ErrorException($this->view->translate("File format is not valid")); } } } $this->view->form = $form; }
/** * Depracated method * PALEATIVOS para adaptação da interface. * */ public function cidadeAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $estado = isset($_POST['uf']) && $_POST['uf'] != "" ? $_POST['uf'] : display_error($LANG['msg_nostate'], true); $municipios = Snep_Cnl::get($estado); $options = ''; if (count($municipios > 0)) { foreach ($municipios as $cidades) { $options .= "<option value='{$cidades['municipio']}' > {$cidades['municipio']} </option> "; } } else { $options = "<option> {$LANG['select']} </option>"; } echo $options; }