Beispiel #1
0
 public function __construct($spec, $options = null)
 {
     foreach (PBX_Trunks::getAll() as $trunk) {
         $data[$trunk->getId()] = $trunk->getName();
     }
     if ($data != null) {
         $this->addMultiOptions($data);
     } else {
         $this->addMultiOption(null, '');
     }
     parent::__construct($spec, $options);
 }
Beispiel #2
0
 /**
  * Faz o parse de um campo <tronco>
  * @param SimpleXMLElement $element
  */
 protected function parseTronco($element)
 {
     $i18n = Zend_Registry::get('i18n');
     $form_element = new Zend_Form_Element_Select((string) $element->id);
     $form_element->setLabel((string) $i18n->translate("Trunk"));
     foreach (PBX_Trunks::getAll() as $tronco) {
         $form_element->addMultiOption($tronco->getId(), $tronco->getName());
         if (isset($element->value) && $tronco->getId() == $element->value) {
             $form_element->setValue($element->value);
         }
     }
     return $form_element;
 }
Beispiel #3
0
 /**
  * Generate the form for routes
  *
  * @return Zend_Form
  */
 protected function getForm()
 {
     if ($this->form === Null) {
         $form_xml = new Zend_Config_Xml(Zend_Registry::get("config")->system->path->base . "/modules/default/forms/route.xml");
         $form = new Snep_Form($form_xml);
         $actions = PBX_Rule_Actions::getInstance();
         $installed_actions = array();
         foreach ($actions->getInstalledActions() as $action) {
             $action_instance = new $action();
             $installed_actions[$action] = $action_instance->getName();
         }
         asort($installed_actions);
         $this->view->actions = $installed_actions;
         $src = new Snep_Form_Element_Html("route/elements/src.phtml", "src", false);
         $src->setLabel($this->view->translate("Source"));
         $src->setOrder(1);
         $form->addElement($src);
         $dst = new Snep_Form_Element_Html("route/elements/dst.phtml", "dst", false);
         $dst->setLabel($this->view->translate("Destiny"));
         $dst->setOrder(2);
         $form->addElement($dst);
         $time = new Snep_Form_Element_Html("route/elements/time.phtml", "time", false);
         $time->setOrder(4);
         $time->setLabel($this->view->translate("Valid times"));
         $form->addElement($time);
         $form->addElement(new Snep_Form_Element_Html("route/elements/actions.phtml", "actions"));
         $this->form = $form;
         $groups = new Snep_GruposRamais();
         $groups = $groups->getAll();
         $group_list = "";
         foreach ($groups as $group) {
             $group_list .= "[\"{$group['name']}\", \"{$group['name']}\"],";
         }
         $group_list = "[" . trim($group_list, ",") . "]";
         $this->view->group_list = $group_list;
         $alias_list = "";
         foreach (PBX_ExpressionAliases::getInstance()->getAll() as $alias) {
             $alias_list .= "[\"{$alias['id']}\", \"{$alias['name']}\"],";
         }
         $alias_list = "[" . trim($alias_list, ",") . "]";
         $this->view->alias_list = $alias_list;
         $trunks = "";
         foreach (PBX_Trunks::getAll() as $trunk) {
             $trunks .= "[\"{$trunk->getId()}\", \"{$trunk->getName()}\"],";
         }
         $trunks = "[" . trim($trunks, ",") . "]";
         $this->view->trunk_list = $trunks;
         $cgroup_list = "";
         $cgroup_manager = new Snep_ContactGroups_Manager();
         foreach ($cgroup_manager->getAll() as $cgroup) {
             $cgroup_list .= "[\"{$cgroup['id']}\", \"{$cgroup['name']}\"],";
         }
         $cgroup_list = "[" . trim($cgroup_list, ",") . "]";
         $this->view->contact_groups_list = $cgroup_list;
     }
     return $this->form;
 }
Beispiel #4
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;
         }
     }
 }