Exemplo n.º 1
0
 public function errorAction()
 {
     $errors = $this->_getParam('error_handler');
     switch ($errors->type) {
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             // 404 error -- controller or action not found
             $this->getResponse()->setHttpResponseCode(404);
             $this->view->code = 404;
             $this->view->message = $this->view->translate("The page you are looking for was not found or does not exists.");
             $this->view->title = $this->view->translate("Not Found");
             break;
         default:
             // application error
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->code = 500;
             $this->view->title = $this->view->translate("Internal Error");
             $this->view->sidebar = false;
             $this->view->message = $this->view->translate("Some internal error occured while processing your request. Please contact the system administrator and report this incident.");
             break;
     }
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Error"), $this->view->title));
     $this->view->exception = $errors->exception;
     $this->view->request = $errors->request;
     $this->view->hideMenu = true;
     $this->view->headTitle($this->view->title, 'PREPEND');
 }
Exemplo n.º 2
0
 public function editAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Expression Alias"), $this->view->translate("Edit Expression Alias %s", $id)));
     $form = $this->getForm();
     $this->view->form = $form;
     $aliasesPersistency = new PBX_ExpressionAliases();
     if ($this->getRequest()->isPost()) {
         $isValid = $form->isValid($_POST);
         if ($isValid) {
             $expression = array("id" => $id, "name" => $_POST['name'], "expressions" => explode(",", $_POST['exprValue']));
             try {
                 $aliasesPersistency->update($expression);
             } catch (Exception $ex) {
                 throw $ex;
             }
             $this->_redirect($this->getRequest()->getControllerName());
         }
     }
     $alias = $aliasesPersistency->fetchRow('id_alias_expression = ' . $id);
     $aliasList = array();
     foreach ($alias->findPBX_Expression() as $row) {
         array_push($aliasList, $row->ds_expression);
     }
     $exprList = $aliasList;
     $expr = "exprObj.addItem(" . count($exprList) . ");\n";
     foreach ($exprList as $index => $value) {
         $expr .= "exprObj.widgets[{$index}].value='{$value}';\n";
     }
     $this->view->dataExprAlias = $expr;
     $form = $this->getForm();
     $form->getElement('name')->setValue($alias['ds_name']);
     $this->renderScript('expression-alias/add_edit.phtml');
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Configure"), $this->view->translate("System Status")));
     // Creates Snep_Inspector Object
     $objInspector = new Snep_Inspector();
     // Get array with status of inspected system requirements
     $inspect = $objInspector->getInspects();
     $this->view->inspect = $inspect;
 }
Exemplo n.º 4
0
 public function indexAction()
 {
     // Title
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Services Use")));
     $config = Zend_Registry::get('config');
     // Include Inpector class, for permission test
     include_once $config->system->path->base . "/inspectors/Permissions.php";
     $test = new Permissions();
     $response = $test->getTests();
     $form = $this->getForm();
     if ($this->_request->getPost()) {
         $formIsValid = $form->isValid($_POST);
         $formData = $this->_request->getParams();
         $locale = Snep_Locale::getInstance()->getLocale();
         if ($locale == 'en_US') {
             $format = 'yyyy-MM-dd';
         } else {
             $format = Zend_Locale_Format::getDateFormat($locale);
         }
         $ini_date = explode(" ", $formData['period']['init_day']);
         $final_date = explode(" ", $formData['period']['till_day']);
         $ini_date_valid = Zend_Date::isDate($ini_date[0], $format);
         $final_date_valid = Zend_Date::isDate($final_date[0], $format);
         if (!$ini_date_valid) {
             $iniDateElem = $form->getSubForm('period')->getElement('init_day');
             $iniDateElem->addError($this->view->translate('Invalid Date'));
             $formIsValid = false;
         }
         if (!$final_date_valid) {
             $finalDateElem = $form->getSubForm('period')->getElement('till_day');
             $finalDateElem->addError($this->view->translate('Invalid Date'));
             $formIsValid = false;
         }
         if ($formIsValid) {
             $reportType = $formData['service']['out_type'];
             if ($reportType == 'csv') {
                 $this->csvAction();
             } else {
                 $this->viewAction();
             }
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 5
0
 public function viewAction()
 {
     $log = $this->initLogFile();
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Status"), $this->view->translate("System Logs")));
     $this->view->back = $this->view->translate("Back");
     $this->view->exibition_mode = $this->view->translate("Exibition mode:");
     $this->view->normal = $this->view->translate("Normal");
     $this->view->terminal = $this->view->translate("Terminal");
     $this->view->contrast = $this->view->translate("Contrast");
     if ($log != 'error') {
         // Normal search mode
         if (strcmp($this->_request->getParam('real_time'), 'yes')) {
             $formData = $this->_request->getParams();
             $this->view->mode = 'normal';
             $this->view->location = 'index';
             $init_day = $formData['init_day'];
             $final_day = $formData['end_day'];
             $formated_init_day = new Zend_Date($init_day);
             $formated_init_time = $formated_init_day->toString('hh:mm');
             $formated_init_day = $formated_init_day->toString('yyyy-MM-dd');
             $formated_final_day = new Zend_Date($final_day);
             $formated_final_time = $formated_final_day->toString('hh:mm');
             $formated_final_day = $formated_final_day->toString('yyyy-MM-dd');
             $result = $log->getLog($formated_init_day, $formated_final_day, $formated_init_time, $formated_final_time, $formData['status'], $formData['source'], $formData['dest']);
             if (count($result) > 0) {
                 $this->view->result = $result;
             } else {
                 $this->view->error = $this->view->translate("No entries found!");
                 $this->_helper->viewRenderer('error');
             }
             // Tail log mode
         } else {
             $this->view->mode = 'tail';
             $this->view->location = '../../index';
             $this->view->lines = $this->view->translate("Line numbers");
         }
     } else {
         $this->view->error = $this->view->translate("The log file cannot be open!");
         $this->_helper->viewRenderer('error');
     }
 }
Exemplo n.º 6
0
 public function editAction()
 {
     $idAction = $this->getRequest()->getParam('id');
     if (!class_exists($idAction)) {
         throw new PBX_Exception_BadArg("Invalid Argument");
     } else {
         $action = new $idAction();
         $registry = PBX_Registry::getInstance($idAction);
         if ($action->getDefaultConfigXML() != "") {
             $actionConfig = new PBX_Rule_ActionConfig($action->getDefaultConfigXML());
             if ($this->getRequest()->isPost()) {
                 $newConfig = $actionConfig->parseConfig($_POST);
                 foreach ($newConfig as $key => $value) {
                     $registry->{$key} = $value;
                     $registry->setContext(get_class($action));
                 }
                 // Cleaning values no longer used
                 $previousValues = $registry->getAllValues();
                 foreach ($previousValues as $key => $value) {
                     if (!key_exists($key, $newConfig)) {
                         unset($registry->{$key});
                     }
                 }
                 $this->view->success = true;
             }
             $action->setDefaultConfig($registry->getAllValues());
             $actionConfig = new PBX_Rule_ActionConfig($action->getDefaultConfigXML());
             $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Default Configs"), $action->getName()));
             $actionForm = $actionConfig->getForm();
             $actionForm->getElement('cancel')->setAttrib("onclick", "location.href='{$this->getFrontController()->getBaseUrl()}/action-configs/'");
             $actionForm->getElement('cancel')->setLabel('Voltar');
             $this->view->form = $actionForm;
         } else {
             throw new PBX_Exception_BadArg("No Configurable Action");
         }
     }
 }
Exemplo n.º 7
0
 public function indexAction()
 {
     $exten = $this->getRequest()->getParam("exten");
     if ($exten === null) {
         throw new Zend_Controller_Action_Exception('Page not found.', 404);
     }
     try {
         PBX_Usuarios::get($exten);
     } catch (PBX_Exception_NotFound $ex) {
         throw new Zend_Controller_Action_Exception($this->view->translate("Extension %s does not exists.", $exten), 404);
     }
     $this->view->exten = $exten;
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array("Manage", "Extensions", "Permissions"));
     $resources = array();
     foreach (Snep_Acl::getInstance()->getResources() as $resource) {
         $res_tree = explode("_", $resource);
         $resource = array();
         while ($element = array_pop($res_tree)) {
             $resource = array($element => $resource);
         }
         $resources = array_merge_recursive($resources, $resource);
     }
     $this->view->resources = $resources;
 }
Exemplo n.º 8
0
 /**
  * Action for adding a route
  */
 public function addAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Routes"), $this->view->translate("Add Route")));
     $form = $this->getForm();
     $form->getElement('week')->setValue(true);
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         if ($this->isValidPost()) {
             $rule = $this->parseRuleFromPost();
             PBX_Rules::register($rule);
             $this->_redirect("route");
         } else {
             $actions = "";
             foreach ($this->forms as $id => $form) {
                 $actions .= "addAction(" . json_encode(array("id" => $id, "status" => $form['status'], "type" => $form['type'], "form" => $form['formData'])) . ")\n";
             }
             $actions .= "setActiveAction(\$('actions_list').firstChild)\n";
             $this->view->rule_actions = $actions;
             unset($_POST['actions_order']);
             $rule = $this->parseRuleFromPost($_POST);
             $this->populateFromRule($rule);
         }
     } else {
         $this->view->dt_agirules = array("dst" => "dstObj.addItem();\n", "src" => "origObj.addItem();\n", "time" => "timeObj.addItem();\n");
     }
     $this->renderScript('route/add_edit.phtml');
 }
Exemplo n.º 9
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Status"), $this->view->translate("IP Status")));
     require_once "includes/AsteriskInfo.php";
     $astinfo = new AsteriskInfo();
     $data = $astinfo->status_asterisk("database show", "", True);
     $lines = explode("\n", $data);
     $arr = array();
     foreach ($lines as $indice => $ramal) {
         $arr[] = substr($ramal, 0, strpos($ramal, ":"));
     }
     $agents = array();
     $lista = array();
     foreach ($arr as $ind => $arr2) {
         if (substr($arr2, 1, 3) == 'IAX' || substr($arr2, 1, 3) == 'SIP') {
             $lista[$ind]['tec'] = substr($arr2, 1, 3);
             $lista[$ind]['num'] = substr($arr2, 14);
         }
     }
     $ramais = array();
     foreach ($lista as $ram) {
         $swp = $this->ramalInfo($ram);
         if ($swp['ramal'] != '') {
             $ramais[] = $swp;
         }
     }
     // ---------------------------------------------------------------------
     $filas = $astinfo->status_asterisk("queue show", "", True);
     $queues = array();
     $fila = explode("\n", $filas);
     unset($fila['0']);
     if ($fila['1'] == 'No queues.') {
         unset($fila['1']);
         unset($fila['2']);
     }
     $strFila = '';
     foreach ($fila as $keyl => $vall) {
         if (!isset($queues[$strFila]['fila'])) {
             $queues[$strFila]['fila'] = '';
         }
         if (!isset($queues[$strFila]['agent'])) {
             $queues[$strFila]['agent'] = '';
         }
         if (!isset($queues[$strFila]['status'])) {
             $queues[$strFila]['status'] = '';
         }
         if (substr($vall, 0, 3) != "   " && strlen(trim($vall)) > 1) {
             $strFila = substr($vall, 0, strpos($vall, " "));
             $queues[$strFila]['fila'] = substr($vall, 0, strpos($vall, " "));
         }
         if (strpos($vall, "SIP") > 1 || strpos($vall, "IAX2") > 1 || strpos($vall, "KHOMP") > 1 || strpos($vall, "Agent") > 1) {
             $d = trim($vall);
             $queues[$strFila]['agent'] .= substr($d, 0, strpos($d, " ")) . "<br> ";
             switch ($vall) {
                 case strpos($vall, "Not in use") > 1:
                     $queues[$strFila]['status'] .= $this->view->translate('Unused') . "<br> ";
                     break;
                 case strpos($vall, "Unknown") > 1:
                     $queues[$strFila]['status'] .= $this->view->translate('Unknown') . "<br> ";
                     break;
                 case strpos($vall, "In use") > 1:
                     $queues[$strFila]['status'] .= $this->view->translate('In Use') . "<br> ";
                     break;
                 case strpos($vall, "paused") > 1:
                     $queues[$strFila]['status'] .= $this->view->translate('Paused') . "<br> ";
                     break;
                 case strpos($vall, "Unavailable") > 1:
                     $queues[$strFila]['status'] .= $this->view->translate('Unavailable') . "<br> ";
                     break;
             }
         }
     }
     /* -------------------------------------------------------------------------------------- */
     $trunk = $astinfo->status_asterisk("sip show registry", "", True);
     $peer = $astinfo->status_asterisk("sip show peers", "", True);
     $peers = explode("\n", $peer);
     $trunks = explode("\n", $trunk);
     $trunk_all = array();
     $trunk_ret = array();
     foreach ($trunks as $t_key => $t_val) {
         if ($t_key > 1) {
             $trunk_val = strtok($t_val, ' ');
             $trunk_val = strtok(' ');
             if ($trunk_val != null) {
                 array_push($trunk_all, $trunk_val);
             }
         }
     }
     // SIP Trunks from Peer list
     foreach ($peers as $p_key => $p_val) {
         if ($p_key > 1) {
             if (preg_match_all('/^([A-Za-z0-9]+|\\w+\\/|\\d+|\\d+\\.\\d+\\.\\d+\\.\\d+|\\d+\\/)(\\w+)?[ ]+(\\d+\\.\\d+\\.\\d+\\.\\d+)[ ]+([[:alpha:]]?[[:space:]]?)*\\d+[ ]+(\\w+[[:space:]]?)(\\(\\d+ ms\\))?[ ]+$/', $p_val, $match)) {
                 $trunk_tmp = array();
                 foreach ($trunk_all as $trunk_ip) {
                     if ($trunk_ip == $match[1][0] || $trunk_ip == $match[2][0]) {
                         array_push($trunk_tmp, $match[1][0] . $match[2][0]);
                         array_push($trunk_tmp, $match[3][0]);
                         $status = $match[5][0];
                         if (!strcmp("UNREACHABLE ", $status)) {
                             $status = $this->view->translate("Not Registered");
                         } elseif (!strcmp("Unmonitored ", $status)) {
                             $status = $this->view->translate("N/A");
                         } elseif (!strcmp("OK ", $status)) {
                             $status = $this->view->translate("Registered");
                         }
                         array_push($trunk_tmp, $status);
                         array_push($trunk_tmp, $match[6][0]);
                     }
                 }
                 array_push($trunk_ret, $trunk_tmp);
             }
         }
     }
     $this->view->troncos = $trunk_ret;
     // IAX2 TRUNK
     if (!($iax_trunk = $astinfo->status_asterisk("iax2 show peers", "", True))) {
         $this->view->iax2 = NULL;
     } else {
         $trunk_val = '';
         $iax_trunks = explode("\n", $iax_trunk);
         $iax_all_trunks = array();
         foreach ($iax_trunks as $t_key => $t_val) {
             if (!preg_match("/\\[+.*/", $t_val) && $t_key > 1) {
                 $t_val = preg_replace("'\\s+'", ' ', $t_val);
                 $iax_all_trunks[] = explode(")", $t_val);
             }
         }
         $iax2TrunksFormat = '';
         foreach ($iax_all_trunks as $value) {
             $tempIax1 = explode(' ', $value[0]);
             $nameIax = trim($tempIax1[0]);
             if (!empty($nameIax)) {
                 $ipIax = $tempIax1[1];
                 $tempIax2 = explode(' ', $value[1]);
                 $stateIax = trim($tempIax2[3]);
                 $latIax = '';
                 if ($stateIax == "UNREACHABLE") {
                     $stateIax = $this->view->translate("Not Registered");
                 } elseif ($stateIax == "Unmonitored") {
                     $stateIax = $this->view->translate("N/A");
                 } elseif ($stateIax == 'OK') {
                     $stateIax = $this->view->translate("Registered");
                     $latIaxTemp = explode('(', $tempIax2[4]);
                     $latIax = trim($latIaxTemp[1]);
                     if ($latIax != '') {
                         $latIax .= ' ms';
                     } else {
                         $latIax = '';
                     }
                 }
                 $iax2TrunksFormat[] = array('name' => $nameIax, 'ip' => $ipIax, 'status' => $stateIax, 'lat' => $latIax);
             }
         }
         $this->view->iax2 = $iax2TrunksFormat;
     }
     /* -------------------------------------------------------------------------------------- */
     $codecs = $astinfo->status_asterisk("g729 show licenses", "", True);
     $arrCodecs = explode("\n", $codecs);
     $codec = null;
     if (!preg_match("/No such command/", $arrCodecs['1'])) {
         $arrValores = explode(" ", $arrCodecs['1']);
         $exp = explode("/", $arrValores['0']);
         $codec = array('0' => $arrValores['3'], '1' => $exp['0'], '2' => $exp['1']);
     }
     $this->view->filas = $queues;
     $this->view->ramais = $ramais;
     $this->view->codecs = $codec;
 }
Exemplo n.º 10
0
 public function reportAction()
 {
     $db = Zend_Registry::get('db');
     $config = Zend_Registry::get('config');
     $format = new Formata();
     // View labels
     $this->view->seq = $this->view->translate("SEQ");
     $this->view->calldate = $this->view->translate("Call's date");
     $this->view->origin = $this->view->translate("Source");
     $this->view->destination = $this->view->translate("Destination");
     $this->view->callstatus = $this->view->translate("Status");
     $this->view->duration = $this->view->translate("Duration");
     $this->view->conversation = $this->view->translate("Conversation");
     $this->view->cost_center = $this->view->translate("Cost Center");
     $this->view->city = $this->view->translate("City");
     $this->view->state = $this->view->translate("State");
     $this->view->filter = $this->view->translate("Filter");
     $this->view->calls = $this->view->translate("Calls");
     $this->view->totals_sub = $this->view->translate("Totals");
     $this->view->times = $this->view->translate("Times");
     $this->view->tot_tariffed = $this->view->translate("Total tariffed");
     $this->view->answered = $this->view->translate("Answered");
     $this->view->nanswered = $this->view->translate("Not Answered");
     $this->view->busy = $this->view->translate("Busy");
     $this->view->failure = $this->view->translate("Failed");
     $this->view->other = $this->view->translate("Other");
     $this->view->tarrifation = $this->view->translate("Charging");
     $this->view->wait = $this->view->translate("Waiting");
     $this->view->sub_total = $this->view->translate("Subtotal");
     $this->view->gravation = $this->view->translate("Records");
     $this->view->back = $this->view->translate("Back");
     $defaultNS = new Zend_Session_Namespace('call_sql');
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Calls"), $defaultNS->sub_title));
     $this->view->totals = $defaultNS->totais;
     $this->view->tariffed = $defaultNS->view_tarif;
     $this->view->files = $defaultNS->view_files;
     $this->view->status = $defaultNS->status;
     $this->view->compress_files = $this->view->translate("Compress selected files");
     $this->view->duration_call = $format->fmt_segundos(array("a" => $defaultNS->totais['duration'], "b" => 'hms'));
     $this->view->bill_sec = $format->fmt_segundos(array("a" => $defaultNS->totais['billsec'], "b" => 'hms'));
     $this->view->wait_call = $format->fmt_segundos(array("a" => $defaultNS->totais['espera'], "b" => 'hms'));
     $row = $defaultNS->row;
     if ($defaultNS->report_type == 'synth') {
         // Cost center treatment
         $cc = $defaultNS->contas;
         if ($cc != '') {
             $valores = '';
             $sqlcc = "select nome from ccustos where codigo IN (" . $cc . ")";
             $ccs = $db->query($sqlcc)->fetchAll(PDO::FETCH_ASSOC);
             $ccusto_sintetic = '';
             foreach ($ccs as $id => $value) {
                 $ccusto_sintetic .= $ccs[$id]['nome'] . ", ";
             }
         } else {
             $ccusto_sintetic = $this->view->translate("Any");
         }
         $this->view->cost_center_res = $ccusto_sintetic;
         // Groups treatment
         $sint_destino = $defaultNS->dst;
         $sint_groupdst = $defaultNS->groupdst;
         if ($sint_destino != '' && $sint_groupdst == '') {
             $sint_dest = $sint_destino;
         }
         if ($sint_groupdst != '' && $sint_destino == '') {
             $sqldst = "select name from peers where peers.group = '{$sint_groupdst}' ";
             $sint_dst = $db->query($sqldst)->fetchAll(PDO::FETCH_ASSOC);
             $sint_dest = '';
             foreach ($sint_dst as $id => $value) {
                 $sint_dest .= $sint_dst[$id]['name'] . ", ";
             }
         }
         if (!empty($sint_dest)) {
             $this->view->sinteticdst = $sint_dest;
         }
         $sint_origem = $defaultNS->src;
         $sint_groupsrc = $defaultNS->groupsrc;
         if ($sint_origem != '' && $sint_groupsrc == '') {
             $src_sintetic = trim($sint_origem);
         }
         if ($sint_groupsrc != '' && $sint_origem == '') {
             $sqlsrc = "select name from peers where peers.group = '{$sint_groupsrc}' ";
             $sint_src = $db->query($sqlsrc)->fetchAll(PDO::FETCH_ASSOC);
             $src_sintetic = '';
             foreach ($sint_src as $id => $value) {
                 $src_sintetic .= $sint_src[$id]['name'] . ", ";
             }
         }
         if (!empty($sint_dest)) {
             $this->view->sinteticsrc = $src_sintetic;
         }
         $this->renderScript('calls-report/synthetic-report.phtml');
     } else {
         // Analytical Report
         $paginatorAdapter = new Zend_Paginator_Adapter_Array($row);
         $paginator = new Zend_Paginator($paginatorAdapter);
         $paginator->setCurrentPageNumber($this->_request->page);
         $paginator->setItemCountPerPage(Zend_Registry::get('config')->ambiente->linelimit);
         $items = $paginator->getCurrentItems();
         $this->view->pages = $paginator->getPages();
         $this->view->PAGE_URL = "/snep/index.php/calls-report/report/";
         $listItems = array();
         foreach ($items as $item) {
             // Status
             switch ($item['disposition']) {
                 case 'ANSWERED':
                     $item['disposition'] = $this->view->translate('Answered');
                     break;
                 case 'NO ANSWER':
                     $item['disposition'] = $this->view->translate('Not Answered');
                     break;
                 case 'FAILED':
                     $item['disposition'] = $this->view->translate('Failed');
                     break;
                 case 'BUSY':
                     $item['disposition'] = $this->view->translate('Busy');
                     break;
                 case 'OTHER':
                     $item['disposition'] = $this->view->translate('Others');
                     break;
             }
             // Search for a city or format the telephone type
             if (strlen($item['src']) > 7 && strlen($item['dst']) < 5) {
                 $item['city'] = $this->telType($item['src']);
             } else {
                 $item['city'] = $this->telType($item['dst']);
             }
             $item['nome'] = $item['tipo'] . " : " . $item['codigo'] . " - " . $item['nome'];
             if ($defaultNS->view_tarif) {
                 $item['rate'] = $format->fmt_tarifa(array("a" => $item['dst'], "b" => $item['billsec'], "c" => $item['accountcode'], "d" => $item['calldate'], "e" => $item['tipo']));
             }
             $item['src'] = $format->fmt_telefone(array("a" => $item['src']));
             $item['dst'] = $format->fmt_telefone(array("a" => $item['dst']));
             // Tarrifation
             $item['billsec'] = $format->fmt_segundos(array("a" => $item['billsec'], "b" => 'hms'));
             $item['duration'] = $format->fmt_segundos(array("a" => $item['duration'], "b" => 'hms'));
             if ($defaultNS->view_files) {
                 $filePath = Snep_Manutencao::arquivoExiste($item['calldate'], $item['userfield']);
                 $item['file_name'] = $item['userfield'] . ".wav";
                 if ($filePath) {
                     $item['file_path'] = $filePath;
                 } else {
                     $item['file_path'] = 'N.D.';
                 }
             }
             array_push($listItems, $item);
         }
         $this->view->call_list = $listItems;
         $this->view->compact_success = $this->view->translate("The files were compressed successfully! Wait for the download start.");
         $this->renderScript('calls-report/analytical-report.phtml');
     }
     return;
 }
Exemplo n.º 11
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Routes"), $this->view->translate("Simulator")));
     $trunks = array();
     foreach (PBX_Trunks::getAll() as $value) {
         $trunks[$value->getId()] = $value->getId() . " - " . $value->getName();
     }
     $this->view->trunks = $trunks;
     if ($this->_request->getPost()) {
         $formData = $this->_request->getParams();
         $extension = isset($formData['dst']) && $formData['dst'] != "" ? $formData['dst'] : 's';
         $srcType = isset($formData['srcType']) ? $formData['srcType'] : NULL;
         $trunk = isset($formData['trunk']) ? $formData['trunk'] : NULL;
         $caller = isset($formData['caller']) && $formData['caller'] != "" ? $formData['caller'] : "unknown";
         $time = isset($formData['time']) ? $formData['time'] : NULL;
         $dialplan = new PBX_Dialplan_Verbose();
         if ($srcType == "exten") {
             try {
                 $srcObj = PBX_Usuarios::get($caller);
             } catch (PBX_Exception_NotFound $ex) {
                 $this->view->error = $this->view->translate($ex->getMessage());
                 $this->view->back = $this->view->translate("Back");
                 $this->renderScript('simulator/error.phtml');
                 return;
             }
             $channel = $srcObj->getInterface()->getCanal();
         } else {
             if ($srcType == "trunk") {
                 $srcObj = PBX_Trunks::get($trunk);
                 $channel = $srcObj->getInterface()->getCanal();
             } else {
                 $srcObj = null;
                 $channel = "unknown";
             }
         }
         $request = new PBX_Asterisk_AGI_Request(array("agi_callerid" => $caller, "agi_extension" => $extension, "agi_channel" => $channel));
         $request->setSrcObj($srcObj);
         $dialplan->setRequest($request);
         if ($time) {
             if (preg_match("/^[0-9]:([0-9]{2})\$/", $time)) {
                 $time = "0" . $time;
             }
             $dialplan->setTime($time);
         }
         try {
             $dialplan->parse();
         } catch (PBX_Exception_NotFound $ex) {
             $this->view->error = $this->view->translate("No rule found.");
             $this->view->back = $this->view->translate("Back");
             $this->renderScript('simulator/error.phtml');
             return;
         }
         if (count($dialplan->getMatches()) > 0) {
             $found = false;
             foreach ($dialplan->getMatches() as $index => $rule) {
                 if ($rule->getId() == $dialplan->getLastRule()->getId()) {
                     $state = "torun";
                     $found = true;
                 } else {
                     if ($found) {
                         $state = "ignored";
                     } else {
                         $state = "outdated";
                     }
                 }
                 $actions = array();
                 foreach ($rule->getAcoes() as $action) {
                     $config = $action->getConfigArray();
                     if ($action instanceof CCustos) {
                         $actions[] = $this->view->translate("Define Cost Center to ") . $config['ccustos'];
                     } else {
                         if ($action instanceof DiscarTronco) {
                             $tronco = PBX_Trunks::get($config['tronco']);
                             $actions[] = $this->view->translate("Dial through Trunk ") . $tronco->getName();
                         } else {
                             if ($action instanceof DiscarRamal) {
                                 if (isset($config['ramal']) && $config['ramal'] != "") {
                                     $peer = $config['ramal'];
                                 } else {
                                     $peer = $extension;
                                 }
                                 try {
                                     $ramal = PBX_Usuarios::get($peer);
                                     $actions[] = $this->view->translate("Dial to extension %s", $ramal->getCallerid());
                                 } catch (PBX_Exception_NotFound $ex) {
                                     $actions[] = "<strong style='color:red'>" . $this->view->translate("Failure on trial to dial extension %: non existent extension", $extension) . "</strong>";
                                 }
                             } else {
                                 if ($action instanceof Queue) {
                                     $actions[] = $this->view->translate("Direct to queue %s", $config['queue']);
                                 } else {
                                     if ($action instanceof Cadeado) {
                                         $actions[] = $this->view->translate("Request password");
                                     } else {
                                         if ($action instanceof Context) {
                                             $actions[] = $this->view->translate("Redirect to context %s", $config['context']);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $srcs = array();
                 foreach ($rule->getSrcList() as $src) {
                     $srcs[] = trim(implode(":", $src), ':');
                 }
                 $srcs = implode(",", $srcs);
                 $dsts = array();
                 foreach ($rule->getDstList() as $dst) {
                     $dsts[] = trim(implode(":", $dst), ':');
                 }
                 $dsts = implode(",", $dsts);
                 $result[$index] = array("id" => $rule->getId(), "state" => $state, "caller" => $srcs, "dst" => $dsts, "desc" => $rule->getDesc(), "valid" => join(";", $rule->getValidTimeList()), "actions" => $actions);
             }
             $input = array("caller" => $caller, "dst" => $extension, "time" => $dialplan->getLastExecutionTime());
             $this->view->input = $input;
             $this->view->result = $result;
         }
     }
 }
Exemplo n.º 12
0
 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");
 }
Exemplo n.º 13
0
 /**
  * Associate fields between database and csv file
  */
 public function csvAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Contacts"), $this->view->translate("Import CSV"), $this->view->translate("Column Association")));
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $this->view->url = $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName();
     if (!$adapter->isValid()) {
         $this->view->invalid = true;
     } else {
         $this->view->invalid = false;
         $adapter->receive();
         $fileName = $adapter->getFileName();
         $handle = fopen($fileName, "r");
         $csv = array();
         $row_number = 2;
         $first_row = explode(",", str_replace("\n", "", fgets($handle, 4096)));
         $column_count = count($first_row);
         $csv[] = $first_row;
         while (!feof($handle)) {
             $line = fgets($handle, 4096);
             if (strpos($line, ",")) {
                 $row = explode(",", $line);
                 if (count($row) != $column_count) {
                     throw new ErrorException($this->view->translate("Invalid column count on line %d", $row_number));
                 }
                 $csv[] = $row;
                 $row_number++;
             }
         }
         fclose($handle);
         $standard_fields = array("discard" => $this->view->translate("Discard"), "ds_name" => $this->view->translate("Name"), "ds_address" => $this->view->translate("Address"), "ds_city" => $this->view->translate("City"), "ds_state" => $this->view->translate("State"), "ds_cep" => $this->view->translate("Zip Code"), "ds_phone" => $this->view->translate("Phone"), "ds_cell_phone" => $this->view->translate("Cellphone"));
         $session = new Zend_Session_Namespace('csv');
         $session->data = $csv;
         $group = new Snep_ContactGroups_Manager();
         $_allGroups = $group->fetchAll();
         foreach ($_allGroups as $group) {
             $allGroups[$group['id_contact_group']] = $group['ds_name'];
         }
         if (!count($_allGroups) > 0) {
             $this->view->error = $this->view->translate('There is no contacts group registered.');
         }
         $this->view->csvprocess = array_slice($csv, 0, 10);
         $this->view->fields = $standard_fields;
         isset($allGroups) ? $this->view->group = $allGroups : ($this->view->group = false);
     }
 }
Exemplo n.º 14
0
 /**
  * Remove a Billing
  */
 public function removeAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Billing"), $this->view->translate("Delete")));
     $id = $this->_request->getParam('id');
     Snep_Billing_Manager::remove($id);
     $this->_redirect($this->getRequest()->getControllerName());
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 public function indexAction()
 {
     // Title
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Configure"), $this->view->translate("Parameters")));
     // Get configuration properties from Zend_Registry
     $config = Zend_Registry::get('config');
     // Include Inpector class, for permission test
     include_once $config->system->path->base . "/inspectors/Permissions.php";
     $test = new Permissions();
     $response = $test->getTests();
     // Verify if there's any error, and if it's related to the setup.conf file
     if ($response['error'] && strpos($response['message'], "setup.conf") > 0) {
         // seta variavel verificada no template
         $this->view->error = $this->view->translate("The File includes/setup.conf does not have permission to be modified.");
     }
     // Create object Snep_Form
     $form = new Snep_Form();
     // Set form action
     $form->setAction($this->getFrontController()->getBaseUrl() . '/parameters/index');
     $form_xml = new Zend_Config_Xml('./modules/default/forms/setup.conf.xml');
     // Section General
     $general = new Snep_Form_SubForm($this->view->translate("General Configuration"), $form_xml->general);
     // Setting propoertie values
     $empName = $general->getElement('emp_nome');
     $empName->setValue($config->ambiente->emp_nome);
     $debug = $general->getElement('debug');
     $debug->setValue($config->system->debug);
     $ipSock = $general->getElement('ip_sock');
     $ipSock->setValue($config->ambiente->ip_sock);
     $userSock = $general->getElement('user_sock');
     $userSock->setValue($config->ambiente->user_sock);
     $passSock = $general->getElement('pass_sock');
     $passSock->setValue($config->ambiente->pass_sock);
     $email = $general->getElement('mail');
     $email->setValue($config->system->mail);
     $lineLimit = $general->getElement('linelimit');
     $lineLimit->setValue($config->ambiente->linelimit);
     $dstExceptions = $general->getElement('dst_exceptions');
     $dstExceptions->setValue($config->ambiente->dst_exceptions);
     $conferenceApp = $general->getElement('conference_app');
     $conferenceApp->setValue($config->ambiente->conference_app);
     $form->addSubForm($general, "general");
     $locale_form = new Snep_Form_SubForm($this->view->translate("Locale Configuration"), $form_xml->locale);
     $locale = Snep_Locale::getInstance()->getZendLocale();
     $locales = array();
     foreach ($locale->getTranslationList("territory", Snep_Locale::getInstance()->getLanguage(), 2) as $ccode => $country) {
         $locales[$country] = $locale->getLocaleToTerritory($ccode);
     }
     ksort($locales, SORT_LOCALE_STRING);
     foreach ($locales as $country => $ccode) {
         $locale_form->getElement("locale")->addMultiOption($ccode, $country);
     }
     $locale_form->getElement("locale")->setValue(Snep_Locale::getInstance()->getLocale());
     foreach ($locale->getTranslationList("territorytotimezone", Snep_Locale::getInstance()->getLanguage()) as $timezone => $territory) {
         $locale_form->getElement("timezone")->addMultiOption($timezone, $timezone);
     }
     $locale_form->getElement("timezone")->setValue(Snep_Locale::getInstance()->getTimezone());
     $languages = array();
     $languageElement = $locale_form->getElement("language");
     $available_languages = Snep_Locale::getInstance()->getAvailableLanguages();
     foreach ($locale->getTranslationList("language", Snep_Locale::getInstance()->getLanguage()) as $lcode => $language) {
         if (in_array($lcode, $available_languages)) {
             $languageElement->addMultiOption($lcode, ucfirst($language));
         }
     }
     $languageElement->setValue(Snep_Locale::getInstance()->getLanguage());
     $form->addSubForm($locale_form, "locale");
     // Section Recording
     $recording = new Snep_Form_SubForm($this->view->translate("Call Recording Configuration"), $form_xml->recording);
     // Setting propoertie values
     $application = $recording->getElement('application');
     $application->setValue($config->general->record->application);
     $flag = $recording->getElement('flag');
     $flag->setValue($config->general->record->flag);
     $recordMp3 = $recording->getElement('record_mp3');
     $recordMp3->setValue($config->general->record_mp3);
     $pathVoice = $recording->getElement('path_voz');
     $pathVoice->setValue($config->ambiente->path_voz);
     $pathVoiceBkp = $recording->getElement('path_voz_bkp');
     $pathVoiceBkp->setValue($config->ambiente->path_voz_bkp);
     $form->addSubForm($recording, "gravacao");
     // Section Trunks
     $trunks = new Snep_Form_SubForm($this->view->translate("Trunks Configuration"), $form_xml->trunks);
     // Setting propoertie values
     $qualControlValue = $trunks->getElement('valor_controle_qualidade');
     $qualControlValue->setValue($config->ambiente->valor_controle_qualidade);
     $form->addSubForm($trunks, "troncos");
     // Verify if the request is a post
     if ($this->_request->getPost()) {
         $formIsValid = $form->isValid($_POST);
         $formData = $this->getRequest()->getParams();
         // Specific verification for propertie path_voice
         if (!file_exists($formData['gravacao']['path_voz'])) {
             $recording->getElement('path_voz')->addError($this->view->translate("Invalid path"));
             $formIsValid = false;
         }
         //Validates form, then sets propertie values and records it on the configuration file
         if ($formIsValid) {
             $configFile = APPLICATION_PATH . "/includes/setup.conf";
             $config = new Zend_Config_Ini($configFile, null, true);
             $config->ambiente->emp_nome = $formData['general']['emp_nome'];
             $config->system->debug = $formData['general']['debug'];
             $config->system->language = $formData['locale']['language'];
             $config->system->locale = $formData['locale']['locale'];
             $config->system->timezone = $formData['locale']['timezone'];
             $config->ambiente->ip_sock = $formData['general']['ip_sock'];
             $config->ambiente->user_sock = $formData['general']['user_sock'];
             $config->ambiente->pass_sock = $formData['general']['pass_sock'];
             $config->system->mail = $formData['general']['mail'];
             $config->ambiente->linelimit = $formData['general']['linelimit'];
             $config->ambiente->dst_exceptions = $formData['general']['dst_exceptions'];
             $config->ambiente->conference_app = $formData['general']['conference_app'];
             $config->general->record->application = $formData['gravacao']['application'];
             $config->general->record->flag = $formData['gravacao']['flag'];
             $config->general->record_mp3 = $formData['gravacao']['record_mp3'];
             $config->ambiente->path_voz = $formData['gravacao']['path_voz'];
             $config->ambiente->path_voz_bkp = $formData['gravacao']['path_voz_bkp'];
             $config->ambiente->valor_controle_qualidade = $formData['troncos']['valor_controle_qualidade'];
             $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $configFile));
             // Write file
             $writer->write();
             $this->_redirect('parameters');
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
 /**
  * Remove a Carrier
  */
 public function removeAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Sound Files"), $this->view->translate("Delete")));
     $id = $this->_request->getParam('id');
     Snep_SoundFiles_Manager::remove($id);
     exec("rm /var/lib/asterisk/sounds/pt_BR/{$id}");
     $this->_redirect($this->getRequest()->getControllerName());
 }
Exemplo n.º 19
0
 public function loginAction()
 {
     $this->view->headTitle($this->view->translate("Login"));
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Login")));
     $this->view->hideMenu = true;
     $config = Zend_Registry::get('config');
     if (trim($config->ambiente->db->host) == "") {
         if (Zend_Auth::getInstance()->hasIdentity()) {
             Zend_Auth::getInstance()->clearIdentity();
         }
         $this->_redirect("installer/");
     }
     // Não precisamos fazer login se ja estamos logados
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->_redirect('/');
     }
     if ($this->_request->isPost()) {
         // Filtrando informações do usuário
         $f = new Zend_Filter_StripTags();
         $username = $f->filter($this->_request->getPost('exten'));
         $password = md5($this->_request->getPost('password'));
         if (empty($username)) {
             $this->view->message = $this->view->translate("Please insert a username");
             $this->view->msgclass = 'failure';
         } else {
             $db = Zend_Registry::get('db');
             // criando adaptador de autorização
             $authAdapter = new Zend_Auth_Adapter_DbTable($db);
             // informações das tabelas
             $authAdapter->setTableName('user');
             $authAdapter->setIdentityColumn('ds_login');
             $authAdapter->setCredentialColumn('cd_password');
             // Valores vindos do usuário como credencial
             $authAdapter->setIdentity($username);
             $authAdapter->setCredential($password);
             // autenticação
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             // tratando resultados
             switch ($result->getCode()) {
                 case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                 case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
                     $this->view->message = $this->view->translate('User or password invalid');
                     $this->view->msgclass = 'failure';
                     break;
                 case Zend_Auth_Result::SUCCESS:
                     //$extension = $db->query("SELECT id, callerid FROM peers WHERE name='$username'")->fetchObject();
                     $select = $db->select();
                     $select->from('user', array('id_user', 'ds_login', 'fg_active', 'cd_password'))->where("ds_login = '******'");
                     $user = $db->query($select)->fetchAll();
                     $extension = $db->query($select)->fetchObject();
                     // @todo - fazer verificação se o usuario esta ativo.
                     $auth->getStorage()->write($result->getIdentity());
                     $update_data = array('dt_lastlogin' => Zend_Date::now());
                     $db->update("user", $update_data, "ds_login = '******'");
                     $this->_redirect('/');
                     break;
                 default:
                     $this->view->message = $this->view->translate('Failed to authenticate');
                     $this->view->msgclass = 'failure';
                     break;
             }
         }
     }
     $layout = Zend_Layout::getMvcInstance();
     $layout->setLayout('login');
 }
Exemplo n.º 20
0
 public function viewAction()
 {
     $formData = $this->_request->getParams();
     $reportData = $this->getQuery($formData);
     if ($reportData) {
         $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Call Ranking"), $this->view->translate("{$formData["period"]["init_day"]} ({$formData["period"]["init_hour"]}) - {$formData["period"]["till_day"]} ({$formData["period"]["till_hour"]})")));
         $this->view->PAGE_URL = "/snep/index.php/{$this->getRequest()->getControllerName()}/view/";
         $this->view->rank = $reportData["rank"];
         $this->view->type = $reportData["type"];
         $this->view->timeData = $reportData["timeTotal"];
         $this->view->countData = $reportData["countTotal"];
         $this->_helper->viewRenderer('view');
     } else {
         $this->view->error = $this->view->translate("No records found.");
         $this->view->back = $this->view->translate("Back");
         $this->_helper->viewRenderer('error');
     }
 }
Exemplo n.º 21
0
 /**
  * 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;
 }
Exemplo n.º 22
0
 public function editAction()
 {
     $id = $this->_request->getParam("id");
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Extensions"), $this->view->translate("Edit %s", $id)));
     Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index');
     $form = $this->getForm();
     if (!$this->view->all_writable) {
         $form->getElement("submit")->setAttrib("disabled", "disabled");
     }
     $this->view->form = $form;
     $this->view->boardData = $this->boardData;
     $this->view->url = $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName();
     if ($this->getRequest()->isPost()) {
         $postData = $this->_request->getParams();
         if ($postData["technology"]['type'] == "virtual" && !key_exists('virtual', $postData)) {
             $this->view->error = $this->view->translate("There's no trunks available in the system. Try a different technology");
             $this->view->form->valid(false);
         } else {
             if ($this->view->form->isValid($_POST)) {
                 $postData["extension"]["exten"] = $this->_request->getParam("id");
                 $ret = $this->execAdd($postData, true);
                 if (!is_string($ret)) {
                     $this->_redirect('/extensions/');
                 } else {
                     $this->view->error = $ret;
                     $this->view->form->valid(false);
                 }
             }
         }
     }
     $extenUtil = new Snep_Extensions();
     $exten = $extenUtil->ExtenDataAsArray($extenUtil->get($id));
     $name = $exten["name"];
     $nameField = $form->getSubForm('extension')->getElement('exten');
     $nameField->setValue($name);
     $nameField->setAttrib('readonly', true);
     $nameField->setAttrib('disabled', true);
     if (!$exten["canal"] || $exten["canal"] == 'INVALID' || substr($exten["canal"], 0, strpos($exten["canal"], '/')) == '') {
         $techType = 'manual';
     } else {
         $techType = strtolower(substr($exten["canal"], 0, strpos($exten["canal"], '/')));
     }
     $form->getSubForm('technology')->getElement('type')->setValue($techType);
     $password = $exten["password"];
     $form->getSubForm('extension')->getElement('password')->setValue($password);
     $form->getSubForm('extension')->getElement('password')->renderPassword = true;
     $callerid = $exten["callerid"];
     $form->getSubForm('extension')->getElement('name')->setValue($callerid);
     $extenGroup = $exten["group"];
     $form->getSubForm('extension')->getElement('exten_group')->setValue($extenGroup);
     $pickupGroup = $exten["pickupgroup"];
     $form->getSubForm('extension')->getElement('pickup_group')->setValue($pickupGroup);
     $voiceMail = $exten["usa_vc"];
     if ($voiceMail) {
         $form->getSubForm('advanced')->getElement('voicemail')->setAttrib('checked', 'checked');
     }
     $email = $exten["email"];
     $form->getSubForm('advanced')->getElement('email')->setValue($email);
     $padlock = $exten["authenticate"];
     if ($padlock) {
         $form->getSubForm('advanced')->getElement('padlock')->setAttrib('checked', 'checked');
     }
     $timeTotal = $exten["time_total"];
     if (!empty($timeTotal)) {
         $form->getSubForm('advanced')->getElement('minute_control')->setAttrib('checked', 'checked');
         $form->getSubForm('advanced')->getElement('timetotal')->setValue($timeTotal);
         $ctrlType = $exten["time_chargeby"];
         $form->getSubForm('advanced')->getElement('controltype')->setValue($ctrlType);
     } else {
         $form->getSubForm('advanced')->getElement('timetotal')->setAttrib('disabled', true);
         $form->getSubForm('advanced')->getElement('timetotal')->setAttrib('readonly', true);
         $form->getSubForm('advanced')->getElement('controltype')->setAttrib('disabled', true);
         $form->getSubForm('advanced')->getElement('controltype')->setAttrib('readonly', true);
     }
     switch ($techType) {
         case "sip":
             $pass = $exten["secret"];
             $simCalls = $exten["call-limit"];
             $nat = $exten["nat"];
             $qualify = $exten["qualify"];
             $typeIp = $exten["type"];
             $dtmfMode = $exten["dtmfmode"];
             $form->getSubForm('sip')->getElement('password')->setValue($pass);
             $form->getSubForm('sip')->getElement('password')->renderPassword = true;
             $form->getSubForm('sip')->getElement('calllimit')->setValue($simCalls);
             if ($nat == 'yes') {
                 $form->getSubForm('sip')->getElement('nat')->setAttrib('checked', 'checked');
             }
             if ($qualify == 'yes') {
                 $form->getSubForm('sip')->getElement('qualify')->setAttrib('checked', 'checked');
             }
             $form->getSubForm('sip')->getElement('type')->setValue($typeIp);
             $form->getSubForm('sip')->getElement('dtmf')->setValue($dtmfMode);
             $codecs = explode(";", $exten['allow']);
             $form->getSubForm('sip')->getElement('codec')->setValue($codecs[0]);
             $form->getSubForm('sip')->getElement('codec1')->setValue($codecs[1]);
             $form->getSubForm('sip')->getElement('codec2')->setValue($codecs[2]);
             break;
         case "iax2":
             $pass = $exten["secret"];
             $simCalls = $exten["call-limit"];
             $nat = $exten["nat"];
             $qualify = $exten["qualify"];
             $typeIp = $exten["type"];
             $dtmfMode = $exten["dtmfmode"];
             $form->getSubForm('iax2')->getElement('password')->setValue($pass);
             $form->getSubForm('iax2')->getElement('password')->renderPassword = true;
             $form->getSubForm('iax2')->getElement('calllimit')->setValue($simCalls);
             if ($nat == 'yes') {
                 $form->getSubForm('iax2')->getElement('nat')->setAttrib('checked', 'checked');
             }
             if ($qualify == 'yes') {
                 $form->getSubForm('iax2')->getElement('qualify')->setAttrib('checked', 'checked');
             }
             $form->getSubForm('iax2')->getElement('type')->setValue($typeIp);
             $form->getSubForm('iax2')->getElement('dtmf')->setValue($dtmfMode);
             $codecs = explode(";", $exten['allow']);
             $form->getSubForm('iax2')->getElement('codec')->setValue($codecs[0]);
             $form->getSubForm('iax2')->getElement('codec1')->setValue($codecs[1]);
             $form->getSubForm('iax2')->getElement('codec2')->setValue($codecs[2]);
             break;
         case "khomp":
             $khompInfo = substr($exten["canal"], strpos($exten["canal"], '/') + 1);
             $khompBoard = substr($khompInfo, strpos($khompInfo, 'b') + 1, strpos($khompInfo, 'c') - 1);
             $khompChannel = substr($khompInfo, strpos($khompInfo, 'c') + 1);
             $khompInfo = new PBX_Khomp_Info();
             if ($khompInfo->hasWorkingBoards()) {
                 foreach ($khompInfo->boardInfo() as $board) {
                     if (preg_match("/KFXS/", $board['model'])) {
                         $channels = range(0, $board['channels']);
                         $form->getSubForm('khomp')->getElement('board')->addMultiOption($board['id'], $board['id']);
                         $boardList[$board['id']] = $channels;
                         if ($board['id'] == $khompBoard) {
                             foreach ($channels as $value) {
                                 $form->getSubForm('khomp')->getElement('channel')->addMultiOption($value, $value);
                             }
                         }
                     }
                 }
                 $form->getSubForm('khomp')->getElement('board')->setValue($khompBoard);
                 $form->getSubForm('khomp')->getElement('channel')->setValue($khompChannel);
             }
             break;
         case "virtual":
             $virtualTrunk = substr($exten["canal"], strpos($exten["canal"], '/') + 1);
             $form->getSubForm('virtual')->getElement('virtual')->setValue($virtualTrunk);
             break;
         case "manual":
             $manualComp = substr($exten["canal"], strpos($exten["canal"], '/') + 1);
             $form->getSubForm('manual')->getElement('manual')->setValue($manualComp);
             break;
     }
     $this->renderScript("extensions/add_edit.phtml");
 }
Exemplo n.º 23
0
 public function editAction()
 {
     $id = mysql_escape_string($this->getRequest()->getParam("trunk"));
     $this->view->breadcrumb = $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Trunks"), $this->view->translate("Edit trunk %s", $id)));
     Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index');
     $form = $this->getForm();
     $form->setAction($this->view->baseUrl() . "/index.php/trunks/edit/trunk/{$id}");
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($_POST)) {
             $trunk_data = $this->preparePost();
             $sql = "SELECT name FROM trunks WHERE id='{$id}' LIMIT 1";
             $name_data = Snep_Db::getInstance()->query($sql)->fetch();
             $trunk_data['trunk']['name'] = $trunk_data['ip']['name'] = $name_data['name'];
             $db = Snep_Db::getInstance();
             $db->beginTransaction();
             try {
                 $db->update("trunks", $trunk_data['trunk'], "id='{$id}'");
                 if ($trunk_data['trunk']['trunktype'] == "I") {
                     $db->update("peers", $trunk_data['ip'], "name='{$trunk_data['trunk']['name']}' and peer_type='T'");
                 }
                 $db->commit();
             } catch (Exception $ex) {
                 $db->rollBack();
                 throw $ex;
             }
             Snep_InterfaceConf::loadConfFromDb();
             $this->_redirect("trunks");
         }
     }
     $this->populateFromTrunk($form, $id);
     $this->view->form = $form;
     $this->renderScript("trunks/add_edit.phtml");
 }
Exemplo n.º 24
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Conference Rooms")));
     $config = Zend_Registry::get('config');
     $conf_app = $config->ambiente->conference_app;
     for ($i = 901; $i <= 915; $i++) {
         $salas[$i]["id"] = $i;
         $salas[$i]["usa_auth"] = False;
         $salas[$i]["authenticate"] = "";
         $salas[$i]["status"] = 0;
         $salas[$i]["ccustos"] = "";
     }
     exec('cat /etc/asterisk/snep/snep-authconferences.conf | grep "^[9][0-1][0-9]"', $senhas, $err);
     foreach ($senhas as $value) {
         $line = explode(":", $value);
         $salas[$line[0]]["authenticate"] = $line[1];
         $salas[$line[0]]["usa_auth"] = True;
     }
     exec("cat /etc/asterisk/snep/snep-conferences.conf | grep 'exten => [9][0-1][0-9]' | cut -d '>' -f2", $out, $err);
     foreach ($out as $key => $value) {
         $room = explode(",", $value);
         if (isset($room[0])) {
             $sala = trim($room[0]);
             $salas[$sala]["status"] = 1;
             isset($salas[$sala]["ccustos"]) ? null : ($salas[$sala]["ccustos"] = "");
         }
         if (strpos($room[2], "accountcode") > 0) {
             $ccustos = trim(substr($room[2], strpos($room[2], "=") + 1, -1));
             $salas[$sala]["ccustos"] = $ccustos;
         }
     }
     $this->view->conferenceRooms = $salas;
     $this->view->costCenter = Snep_CostCenter_Manager::getAll();
     if ($this->getRequest()->getPost()) {
         $file_conf = "/etc/asterisk/snep/snep-conferences.conf";
         $file_auth = "/etc/asterisk/snep/snep-authconferences.conf";
         if (!is_writable($file_conf) || !is_writable($file_auth)) {
             throw new ErrorException($this->view->translate("File does not have editing permission"));
             return False;
         }
         $linhas_conf = file($file_conf);
         $linhas_auth = file($file_auth);
         $authenticate = $_POST['authenticate'];
         $password = $_POST['password'];
         $costCenter = $_POST['costCenter'];
         $activate = $_POST['activate'];
         $updateDate = "; Atualizado em:" . date('d/m/Y H:i:s') . "\n";
         $contentAuth = ";-------------------------------------------------------------------------------\n";
         $contentAuth .= "; Arquivo: snep-authenticate.conf - Cadastro de Senhas de Cadeado\n";
         $contentAuth .= "; Sintaxe: codigo,senha(hash MD5)\n";
         $contentAuth .= "; Include: em /etc/asterisk/extensions.conf\n";
         $contentAuth .= ";      Ex: exten => _[7-9]XXXXXXX,n,Authenticate(/etc/asterisk/snep/snep-authenticate,am)\n";
         $contentAuth .= "; Atualizado em:22/07/2008 14:28:53\n";
         $contentAuth .= "; Copyright(c) 2008 Opens Tecnologia\n";
         $contentAuth .= ";-------------------------------------------------------------------------------\n";
         $contentAuth .= "; Os registros a Seguir sao gerados pelo Software SNEP. \n";
         $contentAuth .= "; Este Arquivo NAO DEVE ser editado Manualmente sob riscos de \n";
         $contentAuth .= "; causar mau funcionamento do Asterisk\n";
         $contentAuth .= ";-------------------------------------------------------------------------------\n";
         $contentConfe = ";----------------------------------------------------------------\n";
         $contentConfe .= "; Arquivo: snep-conferences.conf - Salasa de COnferencia\n";
         $contentConfe .= "; Sintaxe: exten => sala,1,Set(CHANNEL(language)=br)\n";
         $contentConfe .= ";          exten => sala,n,Set(CDR(accountcode)=Conferencia)\n";
         $contentConfe .= ";  (*)     exten => sala,n,Authenticate(senha em hash md5,a)\n";
         $contentConfe .= ";          exten => sala,n,Conference(\${EXTEN}/S)\n";
         $contentConfe .= ";          exten => sala,n,Hangup\n";
         $contentConfe .= "; (*) = Linha Opcional - so aparece se usar senha\n";
         $contentConfe .= "; Include: em /etc/asterisk/extensions.conf\n";
         $contentConfe .= ";          include /etc/asterisk/snep/snep-conferences.conf\n";
         $contentConfe .= "; Atualizado em:22/07/2008 14:28:53\n";
         $contentConfe .= "; Copyright(c) 2008 Opens Tecnologia\n";
         $contentConfe .= ";----------------------------------------------------------------\n";
         $contentConfe .= "; Os registros a Seguir sao gerados pelo Software SNEP.\n";
         $contentConfe .= "; Este Arquivo NAO DEVE ser editado Manualmente sob riscos de\n";
         $contentConfe .= "; causar mau funcionamento do Asterisk\n";
         $contentConfe .= ";----------------------------------------------------------------\n";
         $contentConfe .= "[conferences]\n";
         $contentConfe .= "\n";
         $contentConfe .= "; Next Lines = Default of System - don't change, please\n";
         $contentConfe .= "exten => i,1,Set(CHANNEL(language)=br)\n";
         $contentConfe .= "exten => i,n,Playback(invalid)\n";
         $contentConfe .= "exten => i,n,Hangup\n";
         $contentConfe .= "\n";
         $contentConfe .= "exten => t,1,Hangup\n";
         $contentConfe .= "exten => h,1,Hangup\n";
         $contentConfe .= "exten => H,1,Hangup\n";
         $contentConfe .= "\n";
         foreach ($activate as $idActivate => $valueActivate) {
             foreach ($password as $idPassword => $valuePassword) {
                 if ($valuePassword != "" && $idActivate == $idPassword) {
                     $newPassword = $idPassword . ":" . $valuePassword . "\n";
                     $contentAuth .= $newPassword;
                 }
             }
             foreach ($costCenter as $idCostCenter => $valueCostCenter) {
                 if ($idActivate == $idCostCenter) {
                     $contentConfe .= ";SNEP(" . $idActivate . "): Room added by system\n";
                     $contentConfe .= "exten => " . $idActivate . ",1,Set(CHANNEL(language)=pt_BR)\n";
                 }
                 foreach ($password as $idPassword => $valuePassword) {
                     if ($idActivate == $idCostCenter && $idActivate == $idPassword && $valuePassword != "") {
                         $contentConfe .= "exten => " . $idActivate . ",n,Authenticate(/etc/asterisk/snep/snep-authconferences.conf,m)\n";
                     }
                 }
                 if ($idActivate == $idCostCenter) {
                     $contentConfe .= "exten => " . $idActivate . ",n,Set(CDR(accountcode)=" . $valueCostCenter . ")\n";
                     $contentConfe .= "exten => " . $idActivate . ",n,Conference(\${EXTEN}/S)\n";
                     $contentConfe .= "exten => " . $idActivate . ",n,Hangup\n";
                     $contentConfe .= "\n";
                 }
             }
         }
         file_put_contents($file_conf, $contentConfe);
         file_put_contents($file_auth, $contentAuth);
         $this->_redirect($this->getRequest()->getControllerName());
     }
 }
Exemplo n.º 25
0
 /**
  * Set member queue
  * 
  */
 public function membersAction()
 {
     $queue = $this->_request->getParam("id");
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Queues"), $this->view->translate("Members {$queue}")));
     $members = Snep_Queues_Manager::getMembers($queue);
     $mem = array();
     foreach ($members as $m) {
         $mem[$m['interface']] = $m['interface'];
     }
     $_allMembers = Snep_Queues_Manager::getAllMembers();
     $notMem = array();
     foreach ($_allMembers as $row) {
         $cd = explode(";", $row['canal']);
         foreach ($cd as $canal) {
             if (strlen($canal) > 0) {
                 if (!array_key_exists($canal, $mem)) {
                     $notMem[$canal] = $row['callerid'] . " ({$canal})({$row['group']})";
                 }
             }
         }
     }
     Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index');
     $form = new Snep_Form();
     $this->view->objSelectBox = 'members';
     $form->setSelectBox($this->view->objSelectBox, $this->view->translate("Add Member"), $notMem, $mem);
     $queueId = new Zend_Form_Element_hidden('id');
     $queueId->setvalue($queue);
     $form->addElement($queueId);
     $this->view->form = $form;
     if ($this->_request->getPost()) {
         Snep_Queues_Manager::removeAllMembers($queue);
         if (isset($_POST['box_add'])) {
             foreach ($_POST['box_add'] as $add) {
                 Snep_Queues_Manager::insertMember($queue, $add);
             }
         }
         $this->_redirect($this->getRequest()->getControllerName() . '/');
     }
 }
Exemplo n.º 26
0
 /**
  * Migrate extensions to other Extensions Group
  */
 public function migrationAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Extension Groups"), $this->view->translate("Migrate Extension Group")));
     $id = $this->_request->getParam('id');
     $_allGroups = Snep_ExtensionsGroups_Manager::getAllGroup();
     foreach ($_allGroups as $group) {
         if ($group['name'] != $id) {
             $allGroups[$group['name']] = $group['name'];
         }
     }
     Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index');
     $form = new Snep_Form();
     $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/migration/');
     if (isset($allGroups)) {
         $groupSelect = new Zend_Form_Element_Select('select');
         $groupSelect->setMultiOptions($allGroups);
         $groupSelect->setLabel($this->view->translate($this->view->translate("New Group")));
         $form->addElement($groupSelect);
         $this->view->message = $this->view->translate("This groups has extensions associated. Select another group for these extensions. ");
     } else {
         $groupName = new Zend_Form_Element_Text('new_group');
         $groupName->setLabel($this->view->translate($this->view->translate("New Group")));
         $form->addElement($groupName);
         $this->view->message = $this->view->translate("This is the only group and it has extensions associated. You can migrate these extensions to a new group.");
     }
     $id_exclude = new Zend_Form_Element_Hidden("id");
     $id_exclude->setValue($id);
     $form->addElement($id_exclude);
     if ($this->_request->getPost()) {
         if (isset($_POST['select'])) {
             $toGroup = $_POST['select'];
         } else {
             $new_group = array('group' => $_POST['new_group']);
             $toGroup = Snep_ExtensionsGroups_Manager::addGroup($new_group);
         }
         $extensions = Snep_ExtensionsGroups_Manager::getExtensionsOnlyGroup($id);
         foreach ($extensions as $extension) {
             Snep_ExtensionsGroups_Manager::addExtensionsGroup(array('extensions' => $extension['name'], 'group' => $toGroup));
         }
         Snep_ExtensionsGroups_Manager::delete($id);
         $this->_redirect($this->getRequest()->getControllerName());
     }
     $this->view->form = $form;
 }
Exemplo n.º 27
0
 /**
  * Remove a Carrier
  */
 public function removeAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Carrier"), $this->view->translate("Delete")));
     $id = $this->_request->getParam('id');
     // Reset all values
     $data = array('ta' => 0, 'tf' => 0, 'active' => 0);
     $manager = new Snep_Carrier_Manager();
     $manager->save($id, $data);
     $this->_redirect($this->getRequest()->getControllerName());
 }
Exemplo n.º 28
0
 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;
 }
Exemplo n.º 29
0
 /**
  * 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;
 }