Esempio n. 1
0
 function exportCustom($customSearchClass, $formValues, $order)
 {
     require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
     eval('$search = new ' . $customSearchClass . '( $formValues );');
     $includeContactIDs = false;
     if ($formValues['radio_ts'] == 'ts_sel') {
         $includeContactIDs = true;
     }
     $sql = $search->all(0, 0, $order, $includeContactIDs);
     $columns = $search->columns();
     $header = array_keys($columns);
     $fields = array_values($columns);
     $rows = array();
     $dao =& CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     $alterRow = false;
     if (method_exists($search, 'alterRow')) {
         $alterRow = true;
     }
     while ($dao->fetch()) {
         $row = array();
         foreach ($fields as $field) {
             $row[$field] = $dao->{$field};
         }
         if ($alterRow) {
             $search->alterRow($row);
         }
         $rows[] = $row;
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName(), $header, $rows);
     exit;
 }
Esempio n. 2
0
 /**
  * @param $exportTempTable
  * @param $headerRows
  * @param $sqlColumns
  * @param $exportMode
  * @param null $saveFile
  * @param string $batchItems
  */
 public static function writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode, $saveFile = NULL, $batchItems = '')
 {
     $writeHeader = TRUE;
     $offset = 0;
     $limit = self::EXPORT_ROW_COUNT;
     $query = "SELECT * FROM {$exportTempTable}";
     while (1) {
         $limitQuery = $query . "\nLIMIT {$offset}, {$limit}\n";
         $dao = CRM_Core_DAO::executeQuery($limitQuery);
         if ($dao->N <= 0) {
             break;
         }
         $componentDetails = array();
         while ($dao->fetch()) {
             $row = array();
             foreach ($sqlColumns as $column => $dontCare) {
                 $row[$column] = $dao->{$column};
             }
             $componentDetails[] = $row;
         }
         if ($exportMode == 'financial') {
             $getExportFileName = 'CiviCRM Contribution Search';
         } else {
             $getExportFileName = self::getExportFileName('csv', $exportMode);
         }
         $csvRows = CRM_Core_Report_Excel::writeCSVFile($getExportFileName, $headerRows, $componentDetails, NULL, $writeHeader, $saveFile);
         if ($saveFile && !empty($csvRows)) {
             $batchItems .= $csvRows;
         }
         $writeHeader = FALSE;
         $offset += $limit;
     }
 }
Esempio n. 3
0
 function writeCSVFile($fileName, &$header, &$rows)
 {
     $now = gmdate('D, d M Y H:i:s') . ' GMT';
     $mime_type = 'text/x-csv';
     $ext = 'csv';
     $fileName = CRM_Utils_String::munge($fileName);
     $config =& CRM_Core_Config::singleton();
     header('Content-Type: ' . $mime_type);
     header('Expires: ' . $now);
     // lem9 & loic1: IE need specific headers
     $isIE = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE');
     if ($isIE) {
         header('Content-Disposition: inline; filename="' . $fileName . '.' . $ext . '"');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         header('Content-Disposition: attachment; filename="' . $fileName . '.' . $ext . '"');
         header('Pragma: no-cache');
     }
     CRM_Core_Report_Excel::makeCSVTable($header, $rows, true);
 }
 /**
  * Heart of the Controller. This is where all the action takes place
  *
  *   - The rows are fetched and stored depending on the type of output needed
  *
  *   - For export/printing all rows are selected.
  *
  *   - for displaying on screen paging parameters are used to display the
  *     required rows.
  *
  *   - also depending on output type of session or template rows are appropriately stored in session
  *     or template variables are updated.
  *
  *
  * @return void
  *
  */
 function run()
 {
     // get the column headers
     $columnHeaders =& $this->_object->getColumnHeaders($this->_action, $this->_output);
     $contextArray = explode('_', get_class($this->_object));
     $contextName = strtolower($contextArray[1]);
     // fix contribute and member
     if ($contextName == 'contribute') {
         $contextName = 'contribution';
     } elseif ($contextName == 'member') {
         $contextName = 'membership';
     }
     // we need to get the rows if we are exporting or printing them
     if ($this->_output == self::EXPORT || $this->_output == self::SCREEN) {
         // get rows (without paging criteria)
         $rows = self::getRows($this);
         CRM_Utils_Hook::searchColumns($contextName, $columnHeaders, $rows, $this);
         if ($this->_output == self::EXPORT) {
             // export the rows.
             CRM_Core_Report_Excel::writeCSVFile($this->_object->getExportFileName(), $columnHeaders, $rows);
             CRM_Utils_System::civiExit();
         } else {
             // assign to template and display them.
             self::$_template->assign_by_ref('rows', $rows);
             self::$_template->assign_by_ref('columnHeaders', $columnHeaders);
         }
     } else {
         // output requires paging/sorting capability
         $rows = self::getRows($this);
         CRM_Utils_Hook::searchColumns($contextName, $columnHeaders, $rows, $this);
         $rowsEmpty = count($rows) ? FALSE : TRUE;
         $qill = $this->getQill();
         $summary = $this->getSummary();
         // if we need to store in session, lets update session
         if ($this->_output & self::SESSION) {
             $this->_store->set("{$this->_prefix}columnHeaders", $columnHeaders);
             if ($this->_dynamicAction) {
                 $this->_object->removeActions($rows);
             }
             $this->_store->set("{$this->_prefix}rows", $rows);
             $this->_store->set("{$this->_prefix}rowCount", $this->_total);
             $this->_store->set("{$this->_prefix}rowsEmpty", $rowsEmpty);
             $this->_store->set("{$this->_prefix}qill", $qill);
             $this->_store->set("{$this->_prefix}summary", $summary);
         } else {
             self::$_template->assign_by_ref("{$this->_prefix}pager", $this->_pager);
             self::$_template->assign_by_ref("{$this->_prefix}sort", $this->_sort);
             self::$_template->assign_by_ref("{$this->_prefix}columnHeaders", $columnHeaders);
             self::$_template->assign_by_ref("{$this->_prefix}rows", $rows);
             self::$_template->assign("{$this->_prefix}rowsEmpty", $rowsEmpty);
             self::$_template->assign("{$this->_prefix}qill", $qill);
             self::$_template->assign("{$this->_prefix}summary", $summary);
         }
         // always store the current pageID and sortID
         $this->_store->set($this->_prefix . CRM_Utils_Pager::PAGE_ID, $this->_pager->getCurrentPageID());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_ID, $this->_sort->getCurrentSortID());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_DIRECTION, $this->_sort->getCurrentSortDirection());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_ORDER, $this->_sort->orderBy());
         $this->_store->set($this->_prefix . CRM_Utils_Pager::PAGE_ROWCOUNT, $this->_pager->_perPage);
     }
 }
Esempio n. 5
0
 /**
  * Function to get the list the export fields
  *
  * @param int $exportContact type of export
  *
  * @access public
  */
 function exportContacts($selectAll, $ids, $formValues, $order = null, $fields = null)
 {
     $headerRows = array();
     $returnProperties = array();
     $primary = false;
     if ($fields) {
         $location = array();
         $locationType = array("Work" => array(), "Home" => array(), "Main" => array(), "Other" => array());
         $returnFields = $fields;
         foreach ($returnFields as $key => $field) {
             $flag = true;
             $phone_type = "";
             $phoneFlag = false;
             if ($field[3] && $field[1] == 'phone') {
                 if ($field[3] == 'Phone') {
                     $phone_type = $field[1] . "-" . "Phone";
                 } else {
                     if ($field[3] == 'Mobile') {
                         $phone_type = $field[1] . "-" . "Mobile";
                     } else {
                         if ($field[3] == 'Fax') {
                             $phone_type = $field[1] . "-" . "Fax";
                         } else {
                             if ($field[3] == 'Pager') {
                                 $phone_type = $field[1] . "-" . "Pager";
                             }
                         }
                     }
                 }
                 $phoneFlag = true;
             }
             if ($field[2]) {
                 if ($field[2] == 1) {
                     if ($phoneFlag) {
                         $locationType["Home"][$phone_type] = 1;
                     } else {
                         $locationType["Home"][$field[1]] = 1;
                     }
                 } else {
                     if ($field[2] == 2) {
                         if ($phoneFlag) {
                             $locationType["Work"][$phone_type] = 1;
                         } else {
                             $locationType["Work"][$field[1]] = 1;
                         }
                     } else {
                         if ($field[2] == 3) {
                             if ($phoneFlag) {
                                 $locationType["Main"][$phone_type] = 1;
                             } else {
                                 $locationType["Main"][$field[1]] = 1;
                             }
                         } else {
                             if ($field[2] == 4) {
                                 if ($phoneFlag) {
                                     $locationType["Other"][$phone_type] = 1;
                                 } else {
                                     $locationType["Other"][$field[1]] = 1;
                                 }
                             }
                         }
                     }
                 }
                 $flag = false;
             }
             if ($flag) {
                 $returnProperties[$field[1]] = 1;
             }
         }
         $returnProperties['location'] = $locationType;
     } else {
         $primary = true;
         $fields = CRM_Contact_BAO_Contact::exportableFields('All', true, true);
         foreach ($fields as $key => $var) {
             if ($key) {
                 $returnProperties[$key] = 1;
             }
         }
     }
     if ($primary) {
         $returnProperties['location_type'] = 1;
         $returnProperties['im_provider'] = 1;
         $returnProperties['phone_type'] = 1;
     }
     $session =& new CRM_Core_Session();
     if ($selectAll) {
         if ($primary) {
             $query =& new CRM_Contact_BAO_Query($formValues, $returnProperties, $fields);
         } else {
             $query =& new CRM_Contact_BAO_Query($formValues, $returnProperties);
         }
     } else {
         $params = array();
         foreach ($ids as $id) {
             $params[CRM_CORE_FORM_CB_PREFIX . $id] = 1;
         }
         if ($primary) {
             $query =& new CRM_Contact_BAO_Query($params, $returnProperties, $fields, true);
         } else {
             $query =& new CRM_Contact_BAO_Query($params, $returnProperties, null, true);
         }
     }
     list($select, $from, $where) = $query->query();
     $queryString = "{$select} {$from} {$where}";
     if ($order) {
         list($field, $dir) = explode(' ', $order, 2);
         $field = trim($field);
         if (CRM_Utils_Array::value($field, $returnProperties)) {
             $queryString .= " ORDER BY {$order}";
         }
     }
     if (CRM_Utils_Array::value('tags', $returnProperties) || CRM_Utils_Array::value('groups', $returnProperties)) {
         $queryString .= " GROUP BY civicrm_contact.id";
     }
     $dao =& CRM_Core_DAO::executeQuery($queryString);
     $header = false;
     $contactDetails = array();
     while ($dao->fetch()) {
         $row = array();
         $validRow = false;
         foreach ($dao as $key => $varValue) {
             $flag = false;
             foreach ($returnProperties as $propKey => $props) {
                 if (is_array($props)) {
                     foreach ($props as $propKey1 => $prop) {
                         foreach ($prop as $propkey2 => $prop1) {
                             if ($propKey1 . "-" . $propkey2 == $key) {
                                 $flag = true;
                             }
                         }
                     }
                 }
             }
             if (array_key_exists($key, $returnProperties)) {
                 $flag = true;
             }
             if ($flag) {
                 if (isset($varValue) && $varValue != '') {
                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                         $row[$key] = CRM_Core_BAO_CustomField::getDisplayValue($varValue, $cfID, $query->_options);
                     } else {
                         $row[$key] = $varValue;
                     }
                     $validRow = true;
                 } else {
                     $row[$key] = '';
                 }
                 if (!$header) {
                     if (isset($query->_fields[$key]['title'])) {
                         $headerRows[] = $query->_fields[$key]['title'];
                     } else {
                         if ($key == 'phone_type') {
                             $headerRows[] = 'Phone Type';
                         } else {
                             $keyArray = explode('-', $key);
                             $hdr = $keyArray[0] . "-" . $query->_fields[$keyArray[1]]['title'];
                             if (CRM_Utils_Array::value(2, $keyArray)) {
                                 $hdr .= " " . $keyArray[2];
                             }
                             $headerRows[] = $hdr;
                         }
                     }
                 }
             }
         }
         if ($validRow) {
             $contactDetails[$dao->contact_id] = $row;
         }
         $header = true;
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(CRM_Contact_BAO_Export::getExportFileName(), $headerRows, $contactDetails);
     exit;
 }
Esempio n. 6
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return void
  */
 function postProcess()
 {
     // create the selector, controller and run - store results in session
     $fv = $this->get('formValues');
     $query =& new CRM_Contact_BAO_Query($fv, null, null, false, false, CRM_CONTACT_BAO_QUERY_MODE_ALL);
     $returnProperties =& CRM_Contact_BAO_Query::defaultReturnProperties(CRM_CONTACT_BAO_QUERY_MODE_ALL);
     $properties = array('contact_id', 'contribution_id');
     $header = array(ts('Contact ID'), ts('Contribution ID'));
     foreach ($returnProperties as $name => $dontCare) {
         $properties[] = $name;
         if (CRM_Utils_Array::value($name, $query->_fields) && CRM_Utils_Array::value('title', $query->_fields[$name])) {
             $header[] = $query->_fields[$name]['title'];
         } else {
             $header[] = $name;
         }
     }
     // header fixed for colomns are not expotable
     $headerArray = array('image_URL' => 'Image URL', 'contact_type' => 'Contact Type', 'sort_name' => 'Sort Name', 'display_name' => 'Display Name');
     foreach ($header as $key => $value) {
         if (array_key_exists($value, $headerArray)) {
             $header[$key] = $headerArray[$value];
         }
     }
     $result = $query->searchQuery(0, 0, null, false, false, false, false, false, $this->_contributionClause);
     $rows = array();
     while ($result->fetch()) {
         $row = array();
         $valid = false;
         foreach ($properties as $property) {
             $row[] = $result->{$property};
             if (!CRM_Utils_System::isNull($result->{$property})) {
                 $valid = true;
             }
         }
         if ($valid) {
             $rows[] = $row;
         }
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(CRM_Contribute_Form_Task_Export::getExportFileName(), $header, $rows);
     exit;
 }
Esempio n. 7
0
 /**
  * Heart of the Controller. This is where all the action takes place
  *
  *   - The rows are fetched and stored depending on the type of output needed
  *
  *   - For export/printing all rows are selected.
  *
  *   - for displaying on screen paging parameters are used to display the
  *     required rows.
  *
  *   - also depending on output type of session or template rows are appropriately stored in session
  *     or template variables are updated.
  *
  *
  * @return void
  *
  */
 function run()
 {
     // get the column headers
     $columnHeaders =& $this->_object->getColumnHeaders($this->_action, $this->_output);
     // we need to get the rows if we are exporting or printing them
     if ($this->_output == self::EXPORT || $this->_output == self::SCREEN) {
         // get rows (without paging criteria)
         $rows = self::getRows($this);
         if ($this->_output == self::EXPORT) {
             // export the rows.
             CRM_Core_Report_Excel::writeCSVFile($this->_object->getExportFileName(), $columnHeaders, $rows);
             exit(1);
         } else {
             // assign to template and display them.
             self::$_template->assign_by_ref('rows', $rows);
             self::$_template->assign_by_ref('columnHeaders', $columnHeaders);
         }
     } else {
         // output requires paging/sorting capability
         $rows = self::getRows($this);
         $rowsEmpty = count($rows) ? false : true;
         $qill = $this->getQill();
         $summary = $this->getSummary();
         // if we need to store in session, lets update session
         if ($this->_output & self::SESSION) {
             $this->_store->set("{$this->_prefix}columnHeaders", $columnHeaders);
             $this->_store->set("{$this->_prefix}rows", $rows);
             $this->_store->set("{$this->_prefix}rowCount", $this->_total);
             $this->_store->set("{$this->_prefix}rowsEmpty", $rowsEmpty);
             $this->_store->set("{$this->_prefix}qill", $qill);
             $this->_store->set("{$this->_prefix}summary", $summary);
         } else {
             self::$_template->assign_by_ref("{$this->_prefix}pager", $this->_pager);
             self::$_template->assign_by_ref("{$this->_prefix}sort", $this->_sort);
             self::$_template->assign_by_ref("{$this->_prefix}columnHeaders", $columnHeaders);
             self::$_template->assign_by_ref("{$this->_prefix}rows", $rows);
             self::$_template->assign("{$this->_prefix}rowsEmpty", $rowsEmpty);
             self::$_template->assign("{$this->_prefix}qill", $qill);
             self::$_template->assign("{$this->_prefix}summary", $summary);
         }
         // always store the current pageID and sortID
         $this->_store->set($this->_prefix . CRM_Utils_Pager::PAGE_ID, $this->_pager->getCurrentPageID());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_ID, $this->_sort->getCurrentSortID());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_DIRECTION, $this->_sort->getCurrentSortDirection());
         $this->_store->set($this->_prefix . CRM_Utils_Sort::SORT_ORDER, $this->_sort->orderBy());
         $this->_store->set($this->_prefix . CRM_Utils_Pager::PAGE_ROWCOUNT, $this->_pager->_perPage);
     }
 }
Esempio n. 8
0
 static function writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode)
 {
     $writeHeader = true;
     $offset = 0;
     $limit = self::EXPORT_ROW_COUNT;
     $query = "\nSELECT *\nFROM   {$exportTempTable}\n";
     require_once 'CRM/Core/Report/Excel.php';
     while (1) {
         $limitQuery = $query . "\nLIMIT {$offset}, {$limit}\n";
         $dao = CRM_Core_DAO::executeQuery($limitQuery);
         if ($dao->N <= 0) {
             break;
         }
         $componentDetails = array();
         while ($dao->fetch()) {
             $row = array();
             foreach ($sqlColumns as $column => $dontCare) {
                 $row[$column] = $dao->{$column};
             }
             $componentDetails[] = $row;
         }
         CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode), $headerRows, $componentDetails, null, $writeHeader);
         $writeHeader = false;
         $offset += $limit;
     }
 }
Esempio n. 9
0
 /**
  * Heart of the Controller. This is where all the action takes place
  *
  *   - The rows are fetched and stored depending on the type of output needed
  *
  *   - For export/printing all rows are selected.
  *
  *   - for displaying on screen paging parameters are used to display the
  *     required rows.
  *
  *   - also depending on output type of session or template rows are appropriately stored in session
  *     or template variables are updated.
  *
  *
  * @return void
  *
  */
 function run()
 {
     // get the column headers
     $columnHeaders =& $this->_object->getColumnHeaders($this->_action, $this->_output);
     // we need to get the rows if we are exporting or printing them
     if ($this->_output == CRM_CORE_SELECTOR_CONTROLLER_EXPORT || $this->_output == CRM_CORE_SELECTOR_CONTROLLER_SCREEN) {
         // get rows (without paging criteria)
         $rows =& $this->_object->getRows($this->_action, 0, 0, $this->_sort, $this->_output);
         if ($this->_output == CRM_CORE_SELECTOR_CONTROLLER_EXPORT) {
             // export the rows.
             CRM_Core_Report_Excel::writeCSVFile($this->_object->getExportFileName(), $columnHeaders, $rows);
             exit(1);
         } else {
             // assign to template and display them.
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('rows', $rows);
         }
     } else {
         // output requires paging/sorting capability
         // get rows with paging criteria
         $rows =& $this->_object->getRows($this->_action, $this->_pagerOffset, $this->_pagerRowCount, $this->_sort, $this->_output);
         $rowsEmpty = count($rows) ? false : true;
         $qill = $this->getQill();
         // if we need to store in session, lets update session
         if ($this->_output & CRM_CORE_SELECTOR_CONTROLLER_SESSION) {
             $this->_store->set('columnHeaders', $columnHeaders);
             $this->_store->set('rows', $rows);
             $this->_store->set('rowCount', $this->_total);
             $this->_store->set('rowsEmpty', $rowsEmpty);
             $this->_store->set('qill', $qill);
         } else {
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('pager', $this->_pager);
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('sort', $this->_sort);
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('columnHeaders', $columnHeaders);
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('rows', $rows);
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('rowsEmpty', $rowsEmpty);
             $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('qill', $qill);
         }
         // always store the current pageID and sortID
         $this->_store->set(CRM_UTILS_PAGER_PAGE_ID, $this->_pager->getCurrentPageID());
         $this->_store->set(CRM_UTILS_SORT_SORT_ID, $this->_sort->getCurrentSortID());
         $this->_store->set(CRM_UTILS_SORT_SORT_DIRECTION, $this->_sort->getCurrentSortDirection());
         $this->_store->set(CRM_UTILS_SORT_SORT_ORDER, $this->_sort->orderBy());
         $this->_store->set(CRM_UTILS_PAGER_PAGE_ROWCOUNT, $this->_pager->_perPage);
     }
 }