예제 #1
0
 /**
  * Export contacts for CSV file.
  */
 public function exportAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Contacts"), $this->view->translate("Export CSV")));
     if ($this->_request->getPost()) {
         $db = Zend_Registry::get('db');
         $select = $db->select()->from(array("n" => "contact"), array("n.id_contact as id", "n.ds_name as name", "n.ds_city as city", "n.ds_state as state", "n.ds_cep as cep", "n.ds_phone as phone", "n.ds_cell_phone as cellphone", "g.ds_name as group"))->join(array("g" => "contact_group"), 'n.id_contact_group = g.id_contact_group', array())->order('n.id_contact');
         if ($_POST['group'] != '0') {
             $select->where('g.id_contact_group = ?', $_POST['group']);
         }
         $stmt = $db->query($select);
         $contacts = $stmt->fetchAll();
         $headers = array('id_contact' => $this->view->translate('Code'), 'ds_nome' => $this->view->translate('Name'), 'ds_city' => $this->view->translate('City'), 'ds_state' => $this->view->translate('State'), 'ds_cep' => $this->view->translate('ZipCode'), 'ds_phone' => $this->view->translate('Phone'), 'ds_cell_phone' => $this->view->translate('Mobile'), 'id_contact_group' => $this->view->translate('Grupo'));
         if (count($contacts) > 0) {
             $csv = new Snep_Csv();
             $csv_data = $csv->generate($contacts, $headers);
             $this->_helper->layout->disableLayout();
             $this->_helper->viewRenderer->setNoRender();
             $dateNow = new Zend_Date();
             $fileName = $this->view->translate('Contacts_csv_') . $dateNow->toString($this->view->translate(" dd-MM-yyyy_hh'h'mm'm' ")) . '.csv';
             header('Content-type: application/octet-stream');
             header('Content-Disposition: attachment; filename="' . $fileName . '"');
             echo $csv_data;
         } else {
             $this->view->message = $this->view->translate('A Selecao nao retornou resultados');
         }
     } else {
         $this->view->message = $this->view->translate('Select a contact group to export.');
         $group = new Snep_ContactGroups_Manager();
         $_allGroups = $group->fetchAll();
         foreach ($_allGroups as $group) {
             $allGroups[$group['id_contact_group']] = $group['ds_name'];
         }
         $form = new Snep_Form();
         $select = new Zend_Form_Element_Select('group');
         $select->addMultiOption("0", "All");
         if (count($allGroups > 0)) {
             $select->addMultiOptions($allGroups);
         }
         $form->addElement($select);
         $this->view->form = $form;
         $this->renderScript("contacts/export.phtml");
     }
 }
예제 #2
0
 public function csvAction()
 {
     if ($this->_request->getPost()) {
         $formData = $this->_request->getParams();
         $reportData = $this->getQuery($formData, true);
         if ($reportData) {
             $this->_helper->layout->disableLayout();
             $this->_helper->viewRenderer->setNoRender();
             $csv = new Snep_Csv();
             $csvData = $csv->generate($reportData, true);
             $dateNow = new Zend_Date();
             $fileName = $this->view->translate('services_report_csv_') . $dateNow->toString($this->view->translate(" dd-MM-yyyy_hh'h'mm'm' ")) . '.csv';
             header('Content-type: application/octet-stream');
             header('Content-Disposition: attachment; filename="' . $fileName . '"');
             echo $csvData;
         } else {
             $this->view->error = $this->view->translate("No records found.");
             $this->view->back = $this->view->translate("Back");
             $this->_helper->viewRenderer('error');
         }
     }
 }