Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }