public function indexAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Status"), $this->view->translate("System Logs"))); $config = Zend_Registry::get('config'); include $config->system->path->base . "/inspectors/Permissions.php"; $test = new Permissions(); $response = $test->getTests(); $form = new Snep_Form(new Zend_Config_Xml('./modules/default/forms/logs.xml', 'general', true)); $form->setAction($this->getFrontController()->getBaseUrl() . '/logs/view'); $locale = Snep_Locale::getInstance()->getLocale(); $now = Zend_Date::now(); if ($locale == 'en_US') { $now = $now->toString('YYYY-MM-dd HH:mm'); } else { $now = $now->toString('dd/MM/YYYY HH:mm'); } $initDay = $form->getElement('init_day'); $initDay->setValue($now); $endDay = $form->getElement('end_day'); $endDay->setValue($now); $status = $form->getElement('status'); $status->setValue('ALL'); $realtime = $form->getElement('real_time'); $realtime->setValue('no'); $submit = $form->getElement("submit"); $submit->setLabel("Log Search"); $this->initLogFile(); $this->view->form = $form; }
public function formsAction() { // Define o título da página, é mostrado automaticamente na view. $this->view->breadcrumb = $this->view->translate("Exemplo » Formulários"); // Parse do arquivo formulário. $xml = new Zend_Config_Xml(Zend_Registry::get("config")->system->path->base . "/modules/example/forms/example.xml"); // Cria objeto Snep_Form $form = new Snep_Form($xml); // Pega determinado elemento do Form $campo4 = $form->getElement('campo04'); // Seta as opções do elemento dinamicamente. $campo4->setMultiOptions(array(1 => 'teste1', 2 => 'teste2', 3 => 'teste3')); // Chama método setButton(), que inclue a barra de botões padrão do SNEP. $form->setButton(); // Verifica se existe dados sendo enviados via $_POST // Se for verdadeiro, é porqyue o formulário foi submetido. if ($this->_request->getPost()) { // Chama método isValid() é confronta os dados submetidos pelo formulário. $isValid = $form->isValid($_POST); if ($isValid) { $this->view->message = $this->view->translate("Dados recebidos") . "!"; $this->view->dados = $_POST; } } // Envia o objeto Snep_Form para a View $this->view->form = $form; }
public function editfileAction() { $fileName = $this->_request->getParam('file'); $class = $this->_request->getParam('class'); $className = Snep_SoundFiles_Manager::getClasse($class); $files = Snep_SoundFiles_Manager::getClassFiles($className); $_files = array('arquivo' => '', 'descricao' => '', 'tipo' => '', 'secao' => $class, 'full' => ''); foreach ($files as $name => $file) { if ($name == $fileName) { if (isset($file['arquivo'])) { $_files = $file; } } } $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Music on Hold Sessions"), $this->view->translate("Edit File"), $className)); $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/sound_files.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . "/editfile/file/{$fileName}/class/{$class}"); $file = new Zend_Form_Element_File('file'); $file->setLabel($this->view->translate('Sound File'))->addValidator(new Zend_Validate_File_Extension(array('wav', 'gsm')))->removeDecorator('DtDdWrapper')->setIgnore(true); $form->addElement($file); $form->getElement('description')->setValue($_files['descricao']); $section = new Zend_Form_Element_Hidden('section'); $section->setValue($_files['secao']); $form->addElement($section); $originalName = new Zend_Form_Element_Hidden('originalName'); $originalName->setValue($fileName); $form->addElement($originalName); $originalPath = new Zend_Form_Element_Hidden('originalPath'); $originalPath->setValue($_files['full']); $form->addElement($originalPath); $form->removeElement('type'); if ($this->_request->getPost()) { $class = Snep_SoundFiles_Manager::getClasse($_POST['section']); $form_isValid = $form->isValid($_POST); $dados = $this->_request->getParams(); $invalid = array('â', 'ã', 'á', 'à', 'ẽ', 'é', 'è', 'ê', 'í', 'ì', 'ó', 'õ', 'ò', 'ú', 'ù', 'ç', " ", '@', '!'); $valid = array('a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'u', 'u', 'c', "_", '_', '_'); if ($_FILES['file']['size'] > 0) { $oldName = $_POST['originalName']; $originalName = str_replace($invalid, $valid, $_FILES['file']['name']); $files = Snep_SoundFiles_Manager::get($originalName); if ($files) { $file->addError($this->view->translate("The file already exists")); $form_isValid = false; } if ($form_isValid) { $uploadName = $_FILES['file']['tmp_name']; $arq_tmp = $class['directory'] . "/tmp/" . $originalName; $arq_dst = $class['directory'] . "/" . $originalName; $arq_bkp = $class['directory'] . "/backup/" . $originalName; $arq_orig = $class['directory'] . "/" . $originalName; exec("mv {$uploadName} {$arq_tmp}"); $fileNe = basename($arq_dst, 'wav'); if ($_POST['gsm']) { exec("sox {$arq_tmp} -r 8000 {$fileNe}.gsm"); $exists = file_exists($fileNe . "gsm"); } else { exec("sox {$arq_tmp} -r 8000 -c 1 -e signed-integer -b 16 {$arq_dst}"); $exists = file_exists($arq_dst); } } if ($exists) { exec("rm -f {$_POST['originalPath']}"); Snep_SoundFiles_Manager::remove($oldName); Snep_SoundFiles_Manager::add(array('arquivo' => $originalName, 'descricao' => $dados['description'], 'data' => new Zend_Db_Expr('NOW()'), 'tipo' => 'MOH', 'secao' => $dados['section'])); } } else { $originalName = $_POST['originalName']; Snep_SoundFiles_Manager::editClassFile(array('arquivo' => $originalName, 'descricao' => $dados['description'], 'data' => new Zend_Db_Expr('NOW()'), 'tipo' => 'MOH', 'secao' => $dados['section'])); } $this->_redirect($this->getRequest()->getControllerName() . "/file/class/{$className['name']}/"); } $this->view->form = $form; }
/** * Remove a Extensions Group */ public function deleteAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Extension Groups"), $this->view->translate("Delete Extension Groups"))); $id = $this->_request->getParam('id'); $confirm = $this->_request->getParam('confirm'); if ($confirm == 1) { Snep_ExtensionsGroups_Manager::delete($id); $this->_redirect($this->getRequest()->getControllerName()); } $extensions = Snep_ExtensionsGroups_Manager::getExtensionsGroup($id); if (count($extensions) > 0) { $this->_redirect($this->getRequest()->getControllerName() . '/migration/id/' . $id); } else { $this->view->message = $this->view->translate("The extension group will be deleted. Are you sure?."); $form = new Snep_Form(); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/delete/id/' . $id . '/confirm/1'); $form->getElement('submit')->setLabel($this->view->translate('Yes')); $this->view->form = $form; } }
public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Users"), $this->view->translate("Edit User"))); $id = $this->_request->getParam("id"); $obj = new Snep_User_Manager(); $select = $obj->select()->where("id_user = ?", $id); $user = $obj->fetchRow($select)->toArray(); $form = new Snep_Form(new Zend_Config_Xml('./modules/default/forms/user.xml')); $form->getElement('id')->setValue($user['id_user']); $form->getElement('ds_login')->setValue($user['ds_login']); $form->getElement('ds_mail')->setValue($user['ds_mail']); $form->getElement('fg_active')->setValue($user['fg_active']); if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); if ($form_isValid) { $dados = array('ds_login' => $_POST['ds_login'], 'dt_lastlogin' => $user['dt_lastlogin'], 'ds_mail' => $_POST['ds_mail'], 'fg_active' => $_POST['fg_active'], 'id_profile' => null); if ($_POST['cd_password'] != '') { $new_pass = md5($_POST['cd_password']); if ($user['cd_password'] != $new_pass) { $dados['cd_password'] = md5($_POST['cd_password']); } } $obj->update($dados, "id_user = '******'"); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }
private function getForm() { $config = Zend_Registry::get('config'); $db = Zend_Registry::get('db'); $form = new Snep_Form(); $form->setAction($this->getFrontController()->getBaseUrl() . '/calls-report/'); $form->setName('create'); $form_xml = new Zend_Config_Xml('./modules/default/forms/calls_report.xml'); // --- Subsection - Periods $period = new Snep_Form_SubForm($this->view->translate("Period"), $form_xml->period); $locale = Snep_Locale::getInstance()->getLocale(); $now = Zend_Date::now(); if ($locale == 'en_US') { $now = $now->toString('YYYY-MM-dd HH:mm'); } else { $now = $now->toString('dd/MM/YYYY HH:mm'); } $initDay = $period->getElement('initDay'); $initDay->setValue($now); $finalDay = $period->getElement('finalDay'); $finalDay->setValue($now); $order = $period->getElement('order'); $order->setValue('data'); $form->addSubForm($period, "period"); // Populate groups $groupLib = new Snep_GruposRamais(); $groupsTmp = $groupLib->getAll(); $groupsData = array(); foreach ($groupsTmp as $key => $group) { switch ($group['name']) { case 'administrator': $groupsData[$this->view->translate('Administrators')] = $group['name']; break; case 'users': $groupsData[$this->view->translate('Users')] = $group['name']; break; case 'all': $groupsData[$this->view->translate('All')] = $group['name']; break; default: $groupsData[$group['name']] = $group['name']; } } // --- Subsection -- Source $source = new Snep_Form_SubForm($this->view->translate("Source"), $form_xml->source); $sourceElement = $source->getElement('selectSrc'); $sourceElement->addMultiOption(null, ''); $sourceElement->setAttrib('onChange', 'blockFields($(this).id, $(this).value);'); $srcType = $source->getElement('srctype'); $srcType->setValue('src1'); $form->addSubForm($source, "source"); // --- Subsection -- Destination $destination = new Snep_Form_SubForm($this->view->translate("Destination"), $form_xml->destination); $destinationElement = $destination->getElement('selectDst'); $destinationElement->addMultiOption(null, ''); $destinationElement->setAttrib('onChange', 'blockFields($(this).id, $(this).value);'); $dstType = $destination->getElement('dsttype'); $dstType->setValue('dst1'); $form->addSubForm($destination, "destination"); foreach ($groupsData as $key => $value) { $sourceElement->addMultiOption($value, $key); $destinationElement->addMultiOption($value, $key); } // --- Subsection - Calls related options $calls = new Snep_Form_SubForm($this->view->translate("Calls"), $form_xml->calls); // List Cost Centers and populate select $select = $db->select()->from(array('cc' => 'ccustos'))->order('codigo'); $costs = $db->query($select)->fetchAll(); $costsElement = $calls->getElement('costs_center'); foreach ($costs as $cost) { $costsElement->addMultiOption($cost['codigo'], $cost['tipo'] . ' : ' . $cost['codigo'] . ' - ' . $cost['nome']); } $calls->getElement('status')->setValue('ALL'); $calls->getElement('type')->setValue('T'); $form->addSubForm($calls, "calls"); // --- Subsection - Other options $other = new Snep_Form_SubForm($this->view->translate("Other Options"), $form_xml->others); //$other->getElement('graph_type')->setValue('bars'); $other->getElement('report_type')->setValue('analytical'); $form->addSubForm($other, "others"); $form->getElement('submit')->setLabel($this->view->translate("Show Report")); $form->removeElement('cancel'); /* $form->addElement(new Zend_Form_Element_Submit("submit_graph", array("label" => $this->view->translate("Exibir Gráfico")) )); $buttonCsv = new Zend_Form_Element_Submit("submit_csv", array("label" => $this->view->translate("Exportar CSV"))); $buttonCsv->setOrder(5004); $buttonCsv->addDecorator(array("closetd" => 'HtmlTag'), array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)); $buttonCsv->addDecorator(array("closetr" => 'HtmlTag'), array('tag' => 'tr', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)); $form->addElement($buttonCsv); */ return $form; }
/** * 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; }
public function configureAction() { $objInspector = new Snep_Inspector('Permissions'); $inspect = $objInspector->getInspects(); $this->view->error = $inspect['Permissions']; $this->view->hideMenu = true; $this->view->breadcrumb = $this->view->translate("Installer » Configuration"); $form_config = new Zend_Config_Xml("./modules/default/formsinstaller.xml"); $form = new Snep_Form(); $form->setAction($this->getFrontController()->getBaseUrl() . '/installer/configure'); $asterisk_form = new Snep_Form_SubForm($this->view->translate("Asterisk Configuration"), $form_config->asterisk); $database_form = new Snep_Form_SubForm($this->view->translate("Database Configuration"), $form_config->database); $snep_form = new Snep_Form_SubForm($this->view->translate("Admin Password"), $form_config->snep); $form->addSubForm($database_form, "database"); $form->addSubForm($asterisk_form, "asterisk"); $form->addSubForm($snep_form, "snep"); $submit_button = $form->getElement('submit'); if ($this->view->error['error']) { $submit_button->setAttrib('disabled', true); } if ($this->getRequest()->isPost()) { $form_isValid = $form->isValid($_POST); $snep_data = $form->getValue("snep"); if ($snep_data['password'] !== $snep_data['confirmpassword']) { $snep_form->getElement('confirmpassword')->addError($this->view->translate("The password confirmation is different from the original")); $form_isValid = false; } if (!$asterisk_form->isErrors()) { $asterisk_data = $form->getValue("asterisk"); $asterisk = new Asterisk_AMI(null, $asterisk_data); try { $asterisk->connect(); } catch (Asterisk_Exception_Auth $ex) { $asterisk_form->getElement('secret')->addError($this->view->translate("User and/or password rejected by Asterisk")); $form_isValid = false; } catch (Asterisk_Exception_CantConnect $ex) { $asterisk_form->getElement('server')->addError($this->view->translate("Unable to connect: %s", $ex->getMessage())); $form_isValid = false; } } if (!$database_form->isErrors()) { $database_data = $form->getValue('database'); $db = Zend_Db::factory('Pdo_Mysql', $database_data); try { $db->getConnection(); } catch (Zend_Db_Exception $ex) { $database_form->getElement('hostname')->addError($this->view->translate("Unable to connect: %s", $ex->getMessage())); $form_isValid = false; } } if ($form_isValid) { try { $this->install($db); } catch (Exception $ex) { $this->view->message = $ex->getMessage(); $this->renderScript("installer/error.phtml"); } // Setando usuário do admin. $db->update("peers", array('password' => $snep_data['password']), "id = 1"); // Gravando alterações no arquivo de configuração. $config_file = "./includes/setup.conf"; $config = new Zend_Config_Ini($config_file, null, true); $config->ambiente->ip_sock = $_POST['asterisk']['server']; $config->ambiente->user_sock = $_POST['asterisk']['username']; $config->ambiente->pass_sock = $_POST['asterisk']['secret']; $config->ambiente->db->host = $_POST['database']['hostname']; $config->ambiente->db->username = $_POST['database']['username']; $config->ambiente->db->password = $_POST['database']['password']; $config->ambiente->db->dbname = $_POST['database']['dbname']; $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $config_file)); // Grava arquivo. $writer->write(); $this->_redirect("installer/installed"); } } $this->view->form = $form; }
/** * Edit Carrier */ public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Carrier"), $this->view->translate("Edit"))); $this->view->objSelectBox = "carrier"; $id = $this->_request->getParam("id"); $xml = new Zend_Config_Xml("modules/default/forms/carrier.xml"); $form = new Snep_Form($xml); $carriers = new Snep_Carrier_Manager(); $carrier = $carriers->find($id)->current(); // Popula lista de operadoras $carrierList = array(); foreach ($carriers->fetchAll() as $carrierRow) { $carrierList[$carrierRow->id_carrier] = $carrierRow->ds_name; } $carrierElement = $form->getElement('name'); $carrierElement->setMultiOptions($carrierList)->removeDecorator('DtDdWrapper')->setRegisterInArrayValidator(false); $name = $form->getElement('name'); $name->setValue($carrier['id_carrier'])->setAttrib('disabled', 'disabled'); $form->getElement('ta')->setValue($carrier['vl_start']); $form->getElement('tf')->setValue($carrier['vl_fractionation']); $_idleCostCenter = Snep_Carrier_Manager::getIdleCostCenter(); $idleCostCenter = array(); foreach ($_idleCostCenter as $idle) { $idleCostCenter[$idle['id_costcenter']] = $idle['id_costcenter'] . " : " . $idle['cd_type'] . " - " . $idle['ds_name']; } if (isset($id)) { $_selectedCostCenter = $carrier->findSnep_CostCenter_Manager(); $selectedCostCenter = array(); foreach ($_selectedCostCenter as $selected) { $selectedCostCenter[$selected['id_costcenter']] = $selected['id_costcenter'] . " : " . $selected['cd_type'] . " - " . $selected['ds_name']; } } $form->setSelectBox($this->view->objSelectBox, $this->view->translate('Cost Center'), $idleCostCenter, $selectedCostCenter); $formId = new Zend_Form_Element_Hidden('id'); $formId->setValue($id); $form->addElement($formId); if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); $dados = $this->_request->getParams(); if ($form_isValid) { $dados['active'] = 1; $manager = new Snep_Carrier_Manager(); $manager->save($id, $dados); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }
protected function getForm() { // Create object Snep_Form $form = new Snep_Form(); // Set form action $form->setAction($this->getFrontController()->getBaseUrl() . '/services-report/index'); $form_xml = new Zend_Config_Xml('./modules/default/forms/services_report.xml'); $config = Zend_Registry::get('config'); $period = new Snep_Form_SubForm($this->view->translate("Period"), $form_xml->period); $validatorDate = new Zend_Validate_Date(Zend_Locale_Format::getDateFormat(Zend_Registry::get('Zend_Locale'))); $locale = Snep_Locale::getInstance()->getLocale(); $now = Zend_Date::now(); if ($locale == 'en_US') { $now = $now->toString('YYYY-MM-dd HH:mm'); } else { $now = $now->toString('dd/MM/YYYY HH:mm'); } $yesterday = Zend_Date::now()->subDate(1); $initDay = $period->getElement('init_day'); $initDay->setValue($now); //$initDay->addValidator($validatorDate); $tillDay = $period->getElement('till_day'); $tillDay->setValue($now); //$tillDay->addValidator($validatorDate); $form->addSubForm($period, "period"); $exten = new Snep_Form_SubForm($this->view->translate("Extensions"), $form_xml->exten); $groupLib = new Snep_GruposRamais(); $groupsTmp = $groupLib->getAll(); $groupsData = array(); foreach ($groupsTmp as $key => $group) { switch ($group['name']) { case 'administrator': $groupsData[$this->view->translate('Administrators')] = $group['name']; break; case 'users': $groupsData[$this->view->translate('Users')] = $group['name']; break; case 'all': $groupsData[$this->view->translate('All')] = $group['name']; break; default: $groupsData[$group['name']] = $group['name']; } } $selectGroup = $exten->getElement('group_select'); $selectGroup->addMultiOption(null, '----'); foreach ($groupsData as $key => $value) { $selectGroup->addMultiOption($value, $key); } $selectGroup->setAttrib('onSelect', "enableField('exten-group_select', 'exten-exten_select');"); $form->addSubForm($exten, "exten"); $service = new Snep_Form_SubForm($this->view->translate("Services"), $form_xml->service); $form->addSubForm($service, "service"); $form->getElement('submit')->setLabel($this->view->translate("Show Report")); $form->removeElement("cancel"); return $form; }
/** * Edit Carrier */ public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Sound Files"), $this->view->translate("Edit"))); $file = $this->_request->getParam("file"); $data = Snep_SoundFiles_Manager::get($file); $this->view->file = $data; $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/sound_files.xml")); $file = new Zend_Form_Element_File('file'); $file->setLabel($this->view->translate('Sound Files'))->addValidator(new Zend_Validate_File_Extension(array('wav', 'gsm')))->removeDecorator('DtDdWrapper')->setIgnore(true); $form->addElement($file); $form->getElement('filename')->setValue($data['arquivo'])->setAttrib('readonly', true); $form->getElement('description')->setLabel($this->view->translate('Description'))->setValue($data['descricao'])->setRequired(true); if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); $dados = $this->_request->getParams(); if ($form_isValid) { if ($_FILES['file']['name'] != "" && $_FILES['file']['size'] > 0) { $path_sound = Zend_Registry::get('config')->system->path->asterisk->sounds; $filepath = Snep_SoundFiles_Manager::verifySoundFiles($_POST['filename'], true); exec("mv {$filepath['fullpath']} {$path_sound}/backup/ "); exec("mv {$_FILES['file']['tmp_name']} {$filepath['fullpath']} "); } Snep_SoundFiles_Manager::edit($_POST); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }
protected function getForm() { // Create object Snep_Form $form = new Snep_Form(); // Set form action $form->setAction($this->getFrontController()->getBaseUrl() . '/ranking-report/index'); $form_xml = new Zend_Config_Xml('./modules/default/forms/ranking_report.xml'); $config = Zend_Registry::get('config'); $period = new Snep_Form_SubForm($this->view->translate("Period"), $form_xml->period); $locale = Snep_Locale::getInstance()->getLocale(); $now = Zend_Date::now(); if ($locale == 'en_US') { $now = $now->toString('YYYY-MM-dd HH:mm'); } else { $now = $now->toString('dd/MM/YYYY HH:mm'); } $yesterday = Zend_Date::now()->subDate(1); $initDay = $period->getElement('init_day'); $initDay->setValue($now); $tillDay = $period->getElement('till_day'); $tillDay->setValue($now); $form->addSubForm($period, "period"); $rank = new Snep_Form_SubForm($this->view->translate("Ranking Options"), $form_xml->rank); $selectNumView = $rank->getElement('view'); for ($index = 1; $index <= 30; $index++) { $selectNumView->addMultiOption($index, $index); } $form->addSubForm($rank, "rank"); $form->getElement('submit')->setLabel($this->view->translate("Show Report")); $form->removeElement("cancel"); return $form; }
/** * Método edit, editar item conforme id fornecido. */ public function editAction() { // Define o título da página, é mostrado automaticamente na view. $this->view->breadcrumb = $this->view->translate("Exemplo » Editar"); // Pega o id do item selecionado, passado via GET $id = $this->_request->getParam("id"); // Chama método Example_Cadastro::get(), ele retorna os dados confome o id. $dados = Example_Manager::get($id); // Parse do arquivo formulário. $xml = new Zend_Config_Xml(Zend_Registry::get("config")->system->path->base . "/modules/example/forms/cadastro.xml"); // Cria objeto Snep_Form $form = new Snep_Form($xml); // Preenche dados do formulário com dados vindos do banco. // Perceba que ele captura o elemento e ao mesmo tempo seta um valor para ele. $form->getElement('id')->setValue($dados['id']); $form->getElement('nome')->setValue($dados['nome']); // Chama método que insere a barra padrão. $form->setButton(); // Verifica se existe dados sendo enviados via $_POST // Se for verdadeiro, é porqyue o formulário foi submetido. if ($this->_request->getPost()) { // Chama método isValid() é confronta os dados submetidos pelo formulário. $isValid = $form->isValid($_POST); // Caso tudo seja válido chama a classe (Model) para inserir o dado. if ($isValid) { // Chama método estático para atualizar o registro. Example_Manager::update($_POST); // Após remover ou nao dados redireciona para método index $this->_redirect($this->getRequest()->getModuleName() . '/' . $this->getRequest()->getControllerName()); } } // Envia form para a view $this->view->form = $form; }
public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Pickup Groups"), $this->view->translate("Edit Pickup Group"))); $id = $this->_request->getParam('group'); $pickupgroupObj = new Snep_PickupGroups_Manager(); Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index'); $form_xml = new Zend_Config_Xml("modules/default/forms/pickupGroup.xml"); $form = new Snep_Form($form_xml->general); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . "/edit/group/{$id}"); $pickupgroup = $pickupgroupObj->fetchRow('id_pickupgroup = ' . $id); $name = $form->getElement('name')->setValue($pickupgroup->ds_name); $name = $form->getElement('name')->setLabel($this->view->translate("Name")); if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); $dados = $this->_request->getParams(); if ($form_isValid) { $pickupgroup->ds_name = $dados['name']; $pickupgroup->save(); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; $this->renderScript("pickup-groups/add_edit.phtml"); }
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; }
/** * Edit Cost Center's */ public function editAction() { $id = $this->_request->getParam('id'); $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Cost Center"), $this->view->translate("Edit"))); $obj = new Snep_CostCenter_Manager(); $select = $obj->select()->where('id_costcenter = ?', $id); $cost_center = $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/cost_center.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/edit/id/' . $id); $idcc = new Zend_Form_Element_Hidden('id_costcenter'); $idcc->setValue($cost_center['id_costcenter']); $form->getElement('id')->setValue($cost_center['cd_code'])->setAttrib('readonly', true); $form->getElement('name')->setValue($cost_center['ds_name']); $form->getElement('description')->setValue($cost_center['ds_description']); $form->getElement('type')->setValue($cost_center['cd_type']); $form->addElement($idcc); if ($this->_request->getPost()) { $_POST['id'] = trim($_POST['id']); $form_isValid = $form->isValid($_POST); $data = array('cd_code' => trim($_POST['id']), 'ds_name' => $_POST['name'], 'cd_type' => $_POST['type'], 'ds_description' => $_POST['description'], 'id_carrier' => null); if ($form_isValid) { $costCenter = new Snep_CostCenter_Manager(); $costCenter->update($data, "id_costcenter = {$_POST['id_costcenter']}"); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }