コード例 #1
0
 /**
  * Retrieve records.
  */
 public static function getBatchList()
 {
     $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $params = $_REQUEST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     if ($context != 'financialBatch') {
         // data entry status batches
         $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name');
     }
     $params['context'] = $context;
     // get batch list
     $batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
     $iFilteredTotal = $iTotal = $params['total'];
     if ($context == 'financialBatch') {
         $selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links');
     } else {
         $selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links');
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #2
0
ファイル: Document.php プロジェクト: nielosz/civicrm-core
 /**
  * @param object|string $phpWord
  * @param string $ext
  * @param string $fileName
  */
 public static function printDoc($phpWord, $ext, $fileName)
 {
     $formats = array('docx' => 'Word2007', 'odt' => 'ODText', 'html' => 'HTML', 'pdf' => 'PDF');
     if (realpath($phpWord)) {
         $phpWord = \PhpOffice\PhpWord\IOFactory::load($phpWord, $formats[$ext]);
     }
     $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $formats[$ext]);
     CRM_Utils_System::setHttpHeader('Content-Type', "application/{$ext}");
     CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"');
     $objWriter->save("php://output");
 }
コード例 #3
0
ファイル: AJAX.php プロジェクト: kcristiano/civicrm-core
 /**
  * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
  * @deprecated
  */
 public static function getOptionList()
 {
     $params = $_REQUEST;
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $options = CRM_Core_BAO_CustomOption::getOptionListSelector($params);
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('label', 'value', 'is_default', 'is_active', 'links', 'class');
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #4
0
 /**
  * @param string $file
  *   Local file path.
  * @param string $mimeType
  * @param int $ttl
  *   Time to live (seconds).
  */
 protected function download($file, $mimeType, $ttl)
 {
     if (!file_exists($file)) {
         header("HTTP/1.0 404 Not Found");
         return;
     } elseif (!is_readable($file)) {
         header('HTTP/1.0 403 Forbidden');
         return;
     }
     CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', CRM_Utils_Time::getTimeRaw() + $ttl));
     CRM_Utils_System::setHttpHeader("Content-Type", $mimeType);
     CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename=\"" . basename($file) . "\"");
     CRM_Utils_System::setHttpHeader("Cache-Control", "max-age={$ttl}, public");
     CRM_Utils_System::setHttpHeader('Pragma', 'public');
     readfile($file);
 }
コード例 #5
0
 /**
  * Run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 public function run()
 {
     $session = CRM_Core_Session::singleton();
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
     $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
     $options = array();
     $session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
     //get the options if control come from search context, CRM-3711
     if (empty($options)) {
         $session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
     }
     // FIXME: the below and CRM_Mailing_Form_Test::testMail()
     // should be refactored
     $fromEmail = NULL;
     $mailing = new CRM_Mailing_BAO_Mailing();
     if (!empty($options)) {
         $mailing->id = $options['mailing_id'];
         $fromEmail = CRM_Utils_Array::value('from_email', $options);
     }
     $mailing->find(TRUE);
     CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
     // get and format attachments
     $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
     //get details of contact with token value including Custom Field Token Values.CRM-3734
     $returnProperties = $mailing->getReturnProperties();
     $params = array('contact_id' => $session->get('userID'));
     $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this));
     $mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments);
     if ($type == 'html') {
         CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
         print $mime->getHTMLBody();
     } else {
         CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
         print $mime->getTXTBody();
     }
     CRM_Utils_System::civiExit();
 }
コード例 #6
0
ファイル: Modules.php プロジェクト: FundingWorks/civicrm-core
 /**
  * Send a response.
  *
  * @param string $type
  *   Content type.
  * @param string $data
  *   Content.
  */
 public function send($type, $data)
 {
     // Encourage browsers to cache for a long time - 1 year
     $ttl = 60 * 60 * 24 * 364;
     \CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $ttl));
     \CRM_Utils_System::setHttpHeader("Content-Type", $type);
     \CRM_Utils_System::setHttpHeader("Cache-Control", "max-age={$ttl}, public");
     echo $data;
 }
コード例 #7
0
ファイル: Form.php プロジェクト: konadave/civicrm-core
 /**
  * End post processing.
  *
  * @param array|null $rows
  */
 public function endPostProcess(&$rows = NULL)
 {
     if ($this->_storeResultSet) {
         $this->_resultSet = $rows;
     }
     if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf' || $this->_sendmail) {
         $content = $this->compileContent();
         $url = CRM_Utils_System::url("civicrm/report/instance/{$this->_id}", "reset=1", TRUE);
         if ($this->_sendmail) {
             $config = CRM_Core_Config::singleton();
             $attachments = array();
             if ($this->_outputMode == 'csv') {
                 $content = $this->_formValues['report_header'] . '<p>' . ts('Report URL') . ": {$url}</p>" . '<p>' . ts('The report is attached as a CSV file.') . '</p>' . $this->_formValues['report_footer'];
                 $csvFullFilename = $config->templateCompileDir . CRM_Utils_File::makeFileName('CiviReport.csv');
                 $csvContent = CRM_Report_Utils_Report::makeCsv($this, $rows);
                 file_put_contents($csvFullFilename, $csvContent);
                 $attachments[] = array('fullPath' => $csvFullFilename, 'mime_type' => 'text/csv', 'cleanName' => 'CiviReport.csv');
             }
             if ($this->_outputMode == 'pdf') {
                 // generate PDF content
                 $pdfFullFilename = $config->templateCompileDir . CRM_Utils_File::makeFileName('CiviReport.pdf');
                 file_put_contents($pdfFullFilename, CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf", TRUE, array('orientation' => 'landscape')));
                 // generate Email Content
                 $content = $this->_formValues['report_header'] . '<p>' . ts('Report URL') . ": {$url}</p>" . '<p>' . ts('The report is attached as a PDF file.') . '</p>' . $this->_formValues['report_footer'];
                 $attachments[] = array('fullPath' => $pdfFullFilename, 'mime_type' => 'application/pdf', 'cleanName' => 'CiviReport.pdf');
             }
             if (CRM_Report_Utils_Report::mailReport($content, $this->_id, $this->_outputMode, $attachments)) {
                 CRM_Core_Session::setStatus(ts("Report mail has been sent."), ts('Sent'), 'success');
             } else {
                 CRM_Core_Session::setStatus(ts("Report mail could not be sent."), ts('Mail Error'), 'error');
             }
             return TRUE;
         } elseif ($this->_outputMode == 'print') {
             echo $content;
         } else {
             if ($chartType = CRM_Utils_Array::value('charts', $this->_params)) {
                 $config = CRM_Core_Config::singleton();
                 //get chart image name
                 $chartImg = $this->_chartId . '.png';
                 //get image url path
                 $uploadUrl = str_replace('/persist/contribute/', '/persist/', $config->imageUploadURL) . 'openFlashChart/';
                 $uploadUrl .= $chartImg;
                 //get image doc path to overwrite
                 $uploadImg = str_replace('/persist/contribute/', '/persist/', $config->imageUploadDir) . 'openFlashChart/' . $chartImg;
                 //Load the image
                 $chart = imagecreatefrompng($uploadUrl);
                 //convert it into formatted png
                 CRM_Utils_System::setHttpHeader('Content-type', 'image/png');
                 //overwrite with same image
                 imagepng($chart, $uploadImg);
                 //delete the object
                 imagedestroy($chart);
             }
             CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf", FALSE, array('orientation' => 'landscape'));
         }
         CRM_Utils_System::civiExit();
     } elseif ($this->_outputMode == 'csv') {
         CRM_Report_Utils_Report::export2csv($this, $rows);
     } elseif ($this->_outputMode == 'group') {
         $group = $this->_params['groups'];
         $this->add2group($group);
     }
 }
コード例 #8
0
ファイル: AJAX.php プロジェクト: FundingWorks/civicrm-core
 /**
  * Get list of groups.
  *
  * @return array
  */
 public static function getGroupList()
 {
     $params = $_REQUEST;
     if (isset($params['parent_id'])) {
         // requesting child groups for a given parent
         $params['page'] = 1;
         $params['rp'] = 0;
         $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
         CRM_Utils_JSON::output($groups);
     } else {
         $sortMapper = array(0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility');
         $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
         $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
         $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
         $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
         $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
         if ($sort && $sortOrder) {
             $params['sortBy'] = $sort . ' ' . $sortOrder;
         }
         $params['page'] = $offset / $rowCount + 1;
         $params['rp'] = $rowCount;
         // get group list
         $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
         // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
         // go ahead with flat hierarchy, CRM-12225
         if (empty($groups)) {
             $groupsAccessible = CRM_Core_PseudoConstant::group();
             $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
             if (!empty($groupsAccessible) && $parentsOnly) {
                 // recompute group list with flat hierarchy
                 $params['parentsOnly'] = 0;
                 $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
             }
         }
         $iFilteredTotal = $iTotal = $params['total'];
         $selectorElements = array('group_name', 'count', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
         if (empty($params['showOrgInfo'])) {
             unset($selectorElements[6]);
         }
         //add setting so this can be tested by unit test
         //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
         // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
         if (!empty($params['is_unit_test'])) {
             return array($groups, $iFilteredTotal);
         }
         CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
         echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
         CRM_Utils_System::civiExit();
     }
 }
コード例 #9
0
 /**
  * Send the ICalendar to the browser with the specified content type
  * - 'text/calendar' : used for downloaded ics file
  * - 'text/plain'    : used for iCal formatted feed
  * - 'text/xml'      : used for gData or rss formatted feeds
  *
  *
  * @param string $calendar
  *   The calendar data to be published.
  * @param string $content_type
  * @param string $charset
  *   The character set to use, defaults to 'us-ascii'.
  * @param string $fileName
  *   The file name (for downloads).
  * @param string $disposition
  *   How the file should be sent ('attachment' for downloads).
  */
 public static function send($calendar, $content_type = 'text/calendar', $charset = 'us-ascii', $fileName = NULL, $disposition = NULL)
 {
     $config = CRM_Core_Config::singleton();
     $lang = $config->lcMessages;
     CRM_Utils_System::setHttpHeader("Content-Language", $lang);
     CRM_Utils_System::setHttpHeader("Content-Type", "{$content_type}; charset={$charset}");
     if ($content_type == 'text/calendar') {
         CRM_Utils_System::setHttpHeader('Content-Length', strlen($calendar));
         CRM_Utils_System::setHttpHeader("Content-Disposition", "{$disposition}; filename=\"{$fileName}\"");
         CRM_Utils_System::setHttpHeader("Pragma", "no-cache");
         CRM_Utils_System::setHttpHeader("Expires", "0");
         CRM_Utils_System::setHttpHeader("Cache-Control", "no-cache, must-revalidate");
     }
     echo $calendar;
 }
コード例 #10
0
ファイル: Joomla.php プロジェクト: nyimbi/civicrm-core
 /**
  * @inheritDoc
  */
 public function logout()
 {
     session_destroy();
     CRM_Utils_System::setHttpHeader("Location", "index.php");
 }
コード例 #11
0
ファイル: Report.php プロジェクト: nyimbi/civicrm-core
 /**
  * @param CRM_Core_Form $form
  * @param $rows
  */
 public static function export2csv(&$form, &$rows)
 {
     //Mark as a CSV file.
     CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
     //Force a download and name the file using the current timestamp.
     $datetime = date('Ymd-Gi', $_SERVER['REQUEST_TIME']);
     CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=Report_' . $datetime . '.csv');
     echo self::makeCsv($form, $rows);
     CRM_Utils_System::civiExit();
 }
コード例 #12
0
ファイル: View.php プロジェクト: scardinius/civicrm-core
 /**
  * Run this page (figure out the action needed and perform it).
  *
  * @param int $id
  * @param int $contactID
  * @param bool $print
  * @param bool $allowID
  */
 public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE)
 {
     if (is_numeric($id)) {
         $this->_mailingID = $id;
     } else {
         $print = TRUE;
         $this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
     }
     // # CRM-7651
     // override contactID from the function level if passed in
     if (isset($contactID) && is_numeric($contactID)) {
         $this->_contactID = $contactID;
     } else {
         $session = CRM_Core_Session::singleton();
         $this->_contactID = $session->get('userID');
     }
     // mailing key check
     if (Civi::settings()->get('hash_mailing_url')) {
         $this->_mailing = new CRM_Mailing_BAO_Mailing();
         if (!is_numeric($this->_mailingID)) {
             $this->_mailing->hash = $this->_mailingID;
         } elseif (is_numeric($this->_mailingID)) {
             $this->_mailing->id = $this->_mailingID;
             // if mailing is present and associated hash is present
             // while 'hash' is not been used for mailing view : throw 'permissionDenied'
             if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) {
                 CRM_Utils_System::permissionDenied();
                 return;
             }
         }
     } else {
         $this->_mailing = new CRM_Mailing_BAO_Mailing();
         $this->_mailing->id = $this->_mailingID;
     }
     if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
         CRM_Utils_System::permissionDenied();
         return;
     }
     CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
     // get and format attachments
     $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
     // get contact detail and compose if contact id exists
     $returnProperties = $this->_mailing->getReturnProperties();
     if (isset($this->_contactID)) {
         // get details of contact with token value including Custom Field Token Values.CRM-3734
         $params = array('contact_id' => $this->_contactID);
         $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
         $details = $details[0][$this->_contactID];
         $contactId = $this->_contactID;
     } else {
         // get tokens that are not contact specific resolved
         $params = array('contact_id' => 0);
         $details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
         $details = CRM_Utils_Array::value(0, $details[0]);
         $contactId = 0;
     }
     $mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
     $title = NULL;
     if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
         $header = 'text/html; charset=utf-8';
         $content = $mime->getHTMLBody();
         if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
             $title = '<head><title>' . $this->_mailing->subject . '</title></head>';
         }
     } else {
         $header = 'text/plain; charset=utf-8';
         $content = $mime->getTXTBody();
     }
     CRM_Utils_System::setTitle($this->_mailing->subject);
     if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
         CRM_Core_Page_AJAX::returnJsonResponse($content);
     }
     if ($print) {
         CRM_Utils_System::setHttpHeader('Content-Type', $header);
         print $title;
         print $content;
         CRM_Utils_System::civiExit();
     } else {
         return $content;
     }
 }
コード例 #13
0
ファイル: AJAX.php プロジェクト: kcristiano/civicrm-core
 /**
  *  Function to get email address of a contact.
  */
 public static function getContactEmail()
 {
     if (!empty($_REQUEST['contact_id'])) {
         $contactID = CRM_Utils_Type::escape($_REQUEST['contact_id'], 'Positive');
         if (!CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) {
             return;
         }
         list($displayName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
         if ($userEmail) {
             echo $userEmail;
         }
     } else {
         $noemail = CRM_Utils_Array::value('noemail', $_GET);
         $queryString = NULL;
         $name = CRM_Utils_Array::value('name', $_GET);
         if ($name) {
             $name = CRM_Utils_Type::escape($name, 'String');
             if ($noemail) {
                 $queryString = " cc.sort_name LIKE '%{$name}%'";
             } else {
                 $queryString = " ( cc.sort_name LIKE '%{$name}%' OR ce.email LIKE '%{$name}%' ) ";
             }
         } else {
             $cid = CRM_Utils_Array::value('cid', $_GET);
             if ($cid) {
                 //check cid for integer
                 $contIDS = explode(',', $cid);
                 foreach ($contIDS as $contID) {
                     CRM_Utils_Type::escape($contID, 'Integer');
                 }
                 $queryString = " cc.id IN ( {$cid} )";
             }
         }
         if ($queryString) {
             $offset = CRM_Utils_Array::value('offset', $_GET, 0);
             $rowCount = Civi::settings()->get('search_autocomplete_count');
             $offset = CRM_Utils_Type::escape($offset, 'Int');
             // add acl clause here
             list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
             if ($aclWhere) {
                 $aclWhere = " AND {$aclWhere}";
             }
             if ($noemail) {
                 $query = "\nSELECT sort_name name, cc.id\nFROM civicrm_contact cc\n     {$aclFrom}\nWHERE cc.is_deceased = 0 AND {$queryString}\n      {$aclWhere}\nLIMIT {$offset}, {$rowCount}\n";
                 // send query to hook to be modified if needed
                 CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject));
                 $dao = CRM_Core_DAO::executeQuery($query);
                 while ($dao->fetch()) {
                     $result[] = array('id' => $dao->id, 'text' => $dao->name);
                 }
             } else {
                 $query = "\nSELECT sort_name name, ce.email, cc.id\nFROM   civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id\n       {$aclFrom}\nWHERE  ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString}\n       {$aclWhere}\nLIMIT {$offset}, {$rowCount}\n";
                 // send query to hook to be modified if needed
                 CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject));
                 $dao = CRM_Core_DAO::executeQuery($query);
                 while ($dao->fetch()) {
                     //working here
                     $result[] = array('text' => '"' . $dao->name . '" <' . $dao->email . '>', 'id' => CRM_Utils_Array::value('id', $_GET) ? "{$dao->id}::{$dao->email}" : '"' . $dao->name . '" <' . $dao->email . '>');
                 }
             }
             if ($result) {
                 CRM_Utils_JSON::output($result);
             }
         }
     }
     CRM_Utils_System::civiExit();
 }
コード例 #14
0
 /**
  * @param array $result
  *   List of API responses, keyed by file.
  */
 public static function sendResponse($result)
 {
     $isError = FALSE;
     foreach ($result as $item) {
         $isError = $isError || $item['is_error'];
     }
     if ($isError) {
         $sapi_type = php_sapi_name();
         if (substr($sapi_type, 0, 3) == 'cgi') {
             CRM_Utils_System::setHttpHeader("Status", "500 Internal Server Error");
         } else {
             header("HTTP/1.1 500 Internal Server Error");
         }
     }
     CRM_Utils_JSON::output(array_merge($result));
 }
コード例 #15
0
 /**
  * @param null $fileName
  */
 public function setExcel($fileName = NULL)
 {
     //Mark as an excel file.
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-excel');
     //Force a download and name the file using the current timestamp.
     if (!$fileName) {
         $fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.xls';
     }
     CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_{$fileName}");
 }
コード例 #16
0
ファイル: REST.php プロジェクト: FundingWorks/civicrm-core
 /**
  * used to load a template "inline", eg. for ajax, without having to build a menu for each template
  */
 public static function loadTemplate()
 {
     $request = CRM_Utils_Request::retrieve('q', 'String');
     if (FALSE !== strpos($request, '..')) {
         die("SECURITY FATAL: the url can't contain '..'. Please report the issue on the forum at civicrm.org");
     }
     $request = explode('/', $request);
     $entity = _civicrm_api_get_camel_name($request[2]);
     $tplfile = _civicrm_api_get_camel_name($request[3]);
     $tpl = 'CRM/' . $entity . '/Page/Inline/' . $tplfile . '.tpl';
     $smarty = CRM_Core_Smarty::singleton();
     CRM_Utils_System::setTitle("{$entity}::{$tplfile} inline {$tpl}");
     if (!$smarty->template_exists($tpl)) {
         CRM_Utils_System::setHttpHeader("Status", "404 Not Found");
         die("Can't find the requested template file templates/{$tpl}");
     }
     if (array_key_exists('id', $_GET)) {
         // special treatmenent, because it's often used
         $smarty->assign('id', (int) $_GET['id']);
         // an id is always positive
     }
     $pos = strpos(implode(array_keys($_GET)), '<');
     if ($pos !== FALSE) {
         die("SECURITY FATAL: one of the param names contains &lt;");
     }
     $param = array_map('htmlentities', $_GET);
     unset($param['q']);
     $smarty->assign_by_ref("request", $param);
     if (!array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) || $_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest") {
         $smarty->assign('tplFile', $tpl);
         $config = CRM_Core_Config::singleton();
         $content = $smarty->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl');
         if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) {
             CRM_Utils_System::addHTMLHead($region->render(''));
         }
         CRM_Utils_System::appendTPLFile($tpl, $content);
         return CRM_Utils_System::theme($content);
     } else {
         $content = "<!-- .tpl file embedded: {$tpl} -->\n";
         CRM_Utils_System::appendTPLFile($tpl, $content);
         echo $content . $smarty->fetch($tpl);
         CRM_Utils_System::civiExit();
     }
 }
コード例 #17
0
ファイル: Utils.php プロジェクト: saurabhbatra96/civicrm-core
 /**
  * @param $paper_size
  * @param $orientation
  * @param $margins
  * @param $html
  * @param $output
  * @param string $fileName
  */
 public static function _html2pdf_wkhtmltopdf($paper_size, $orientation, $margins, $html, $output, $fileName)
 {
     require_once 'packages/snappy/src/autoload.php';
     $config = CRM_Core_Config::singleton();
     $snappy = new Knp\Snappy\Pdf($config->wkhtmltopdfPath);
     $snappy->setOption("page-width", $paper_size[2] . "pt");
     $snappy->setOption("page-height", $paper_size[3] . "pt");
     $snappy->setOption("orientation", $orientation);
     $snappy->setOption("margin-top", $margins[1] . $margins[0]);
     $snappy->setOption("margin-right", $margins[2] . $margins[0]);
     $snappy->setOption("margin-bottom", $margins[3] . $margins[0]);
     $snappy->setOption("margin-left", $margins[4] . $margins[0]);
     $pdf = $snappy->getOutputFromHtml($html);
     if ($output) {
         return $pdf;
     } else {
         CRM_Utils_System::setHttpHeader('Content-Type', 'application/pdf');
         CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"');
         echo $pdf;
     }
 }
コード例 #18
0
 public function initiateDownload()
 {
     $config = CRM_Core_Config::singleton();
     //zip files if more than one.
     if (count($this->_downloadFile) > 1) {
         $zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip';
         $result = $this->createZip($this->_downloadFile, $zip, TRUE);
         if ($result) {
             CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
             CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
             CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($zip));
             ob_clean();
             flush();
             readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip)));
             unlink($zip);
             //delete the zip to avoid clutter.
             CRM_Utils_System::civiExit();
         }
     } else {
         CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
         CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
         CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($this->_downloadFile[0]));
         ob_clean();
         flush();
         readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
         CRM_Utils_System::civiExit();
     }
 }
コード例 #19
0
ファイル: JSON.php プロジェクト: utkarshsharma/civicrm-core
 /**
  * Output json to the client.
  * @param mixed $input
  */
 public static function output($input)
 {
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo json_encode($input);
     CRM_Utils_System::civiExit();
 }
コード例 #20
0
ファイル: AJAX.php プロジェクト: rollox/civicrm-core
 /**
  * Get output of financial transactions.
  *
  * @param bool $return
  *   Return result. This parameter allows the output to be unit tested.
  *
  * @return string
  */
 public static function getFinancialTransactionsList($return = FALSE)
 {
     $sortMapper = array(0 => '', 1 => '', 2 => 'sort_name', 3 => 'amount', 4 => 'trxn_id', 5 => 'transaction_date', 6 => 'payment_method', 7 => 'status', 8 => 'name');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $return = isset($_REQUEST['return']) ? CRM_Utils_Type::escape($_REQUEST['return'], 'Boolean') : FALSE;
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $entityID = isset($_REQUEST['entityID']) ? CRM_Utils_Type::escape($_REQUEST['entityID'], 'String') : NULL;
     $notPresent = isset($_REQUEST['notPresent']) ? CRM_Utils_Type::escape($_REQUEST['notPresent'], 'String') : NULL;
     $statusID = isset($_REQUEST['statusID']) ? CRM_Utils_Type::escape($_REQUEST['statusID'], 'String') : NULL;
     $search = isset($_REQUEST['search']) ? TRUE : FALSE;
     $params = $_POST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $returnvalues = array('civicrm_financial_trxn.payment_instrument_id as payment_method', 'civicrm_contribution.contact_id as contact_id', 'civicrm_contribution.id as contributionID', 'contact_a.sort_name', 'civicrm_financial_trxn.total_amount as amount', 'civicrm_financial_trxn.trxn_id as trxn_id', 'contact_a.contact_type', 'contact_a.contact_sub_type', 'civicrm_financial_trxn.trxn_date as transaction_date', 'name', 'civicrm_contribution.currency as currency', 'civicrm_financial_trxn.status_id as status', 'civicrm_financial_trxn.check_number as check_number');
     $columnHeader = array('contact_type' => '', 'sort_name' => ts('Contact Name'), 'amount' => ts('Amount'), 'trxn_id' => ts('Trxn ID'), 'transaction_date' => ts('Received'), 'payment_method' => ts('Payment Method'), 'status' => ts('Status'), 'name' => ts('Type'));
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $params['context'] = $context;
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['total'] = 0;
     // get batch list
     if (isset($notPresent)) {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
         if ($search) {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
         } else {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
         }
         while ($unassignedTransactions->fetch()) {
             $unassignedTransactionsCount[] = $unassignedTransactions->id;
         }
         if (!empty($unassignedTransactionsCount)) {
             $params['total'] = count($unassignedTransactionsCount);
         }
     } else {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
         $assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues);
         while ($assignedTransactions->fetch()) {
             $assignedTransactionsCount[] = $assignedTransactions->id;
         }
         if (!empty($assignedTransactionsCount)) {
             $params['total'] = count($assignedTransactionsCount);
         }
     }
     $financialitems = array();
     while ($financialItem->fetch()) {
         $row[$financialItem->id] = array();
         foreach ($columnHeader as $columnKey => $columnValue) {
             if ($financialItem->contact_sub_type && $columnKey == 'contact_type') {
                 $row[$financialItem->id][$columnKey] = $financialItem->contact_sub_type;
                 continue;
             }
             $row[$financialItem->id][$columnKey] = $financialItem->{$columnKey};
             if ($columnKey == 'sort_name' && $financialItem->{$columnKey}) {
                 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=" . $financialItem->contact_id);
                 $row[$financialItem->id][$columnKey] = '<a href=' . $url . '>' . $financialItem->{$columnKey} . '</a>';
             } elseif ($columnKey == 'payment_method' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $financialItem->{$columnKey});
                 if ($row[$financialItem->id][$columnKey] == 'Check') {
                     $checkNumber = $financialItem->check_number ? ' (' . $financialItem->check_number . ')' : '';
                     $row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber;
                 }
             } elseif ($columnKey == 'amount' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->{$columnKey}, $financialItem->currency);
             } elseif ($columnKey == 'transaction_date' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->{$columnKey});
             } elseif ($columnKey == 'status' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $financialItem->{$columnKey});
             }
         }
         if ($statusID == CRM_Core_OptionGroup::getValue('batch_status', 'Open')) {
             if (isset($notPresent)) {
                 $js = "enableActions('x')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_x_" . $financialItem->id . "' name='mark_x_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Form_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             } else {
                 $js = "enableActions('y')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_y_" . $financialItem->id . "' name='mark_y_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Page_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             }
         } else {
             $row[$financialItem->id]['check'] = NULL;
             $tempBAO = new CRM_Financial_Page_BatchTransaction();
             $links = $tempBAO->links();
             unset($links['remove']);
             $row[$financialItem->id]['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
         }
         $row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) ? CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) : CRM_Utils_Array::value('contact_type', $row[$financialItem->id]), FALSE, $financialItem->contact_id);
         $financialitems = $row;
     }
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('check', 'contact_type', 'sort_name', 'amount', 'trxn_id', 'transaction_date', 'payment_method', 'status', 'name', 'action');
     if ($return) {
         return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #21
0
ファイル: AJAX.php プロジェクト: utkarshsharma/civicrm-core
 /**
  * Set headers appropriate for a js file.
  *
  * @param int|NULL $ttl
  *   Time-to-live (seconds).
  */
 public static function setJsHeaders($ttl = NULL)
 {
     if ($ttl === NULL) {
         // Encourage browsers to cache for a long time - 1 year
         $ttl = 60 * 60 * 24 * 364;
     }
     CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $ttl));
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/javascript');
     CRM_Utils_System::setHttpHeader('Cache-Control', "max-age={$ttl}, public");
 }
コード例 #22
0
 public static function getDedupes()
 {
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = 'sort_name';
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $gid = isset($_REQUEST['gid']) ? CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer') : 0;
     $rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer') : 0;
     $contactType = '';
     if ($rgid) {
         $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
     }
     $cacheKeyString = "merge {$contactType}_{$rgid}_{$gid}";
     $searchRows = array();
     $selectorElements = array('src', 'dst', 'weight', 'actions');
     $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND\n                                                             pn.entity_id2 = de.contact_id2 )";
     $where = "de.id IS NULL";
     $iFilteredTotal = $iTotal = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, $join, $where);
     $mainContacts = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, $offset, $rowCount);
     foreach ($mainContacts as $mainId => $main) {
         $searchRows[$mainId]['src'] = CRM_Utils_System::href($main['srcName'], 'civicrm/contact/view', "reset=1&cid={$main['srcID']}");
         $searchRows[$mainId]['dst'] = CRM_Utils_System::href($main['dstName'], 'civicrm/contact/view', "reset=1&cid={$main['dstID']}");
         $searchRows[$mainId]['weight'] = CRM_Utils_Array::value('weight', $main);
         if (!empty($main['canMerge'])) {
             $mergeParams = "reset=1&cid={$main['srcID']}&oid={$main['dstID']}&action=update&rgid={$rgid}";
             if ($gid) {
                 $mergeParams .= "&gid={$gid}";
             }
             $searchRows[$mainId]['actions'] = '<a class="action-item crm-hover-button" href="' . CRM_Utils_System::url('civicrm/contact/merge', $mergeParams) . '">' . ts('merge') . '</a>';
             $searchRows[$mainId]['actions'] .= "<a class='action-item crm-hover-button crm-notDuplicate' href='#' onClick=\"processDupes( {$main['srcID']}, {$main['dstID']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>";
         } else {
             $searchRows[$mainId]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>';
         }
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #23
0
ファイル: AJAX.php プロジェクト: konadave/civicrm-core
 /**
  * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
  * @deprecated
  */
 public function petitionList()
 {
     //get the search criteria params.
     $searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
     $searchParams = explode(',', $searchCriteria);
     $params = $searchRows = array();
     foreach ($searchParams as $param) {
         if (!empty($_POST[$param])) {
             $params[$param] = $_POST[$param];
         }
     }
     //this is sequence columns on datatable.
     $selectorCols = array('id', 'title', 'campaign_id', 'campaign', 'activity_type_id', 'activity_type', 'is_default', 'is_active', 'isActive', 'action');
     // get the data table params.
     $dataTableParams = array('sEcho' => array('name' => 'sEcho', 'type' => 'Integer', 'default' => 0), 'offset' => array('name' => 'iDisplayStart', 'type' => 'Integer', 'default' => 0), 'rowCount' => array('name' => 'iDisplayLength', 'type' => 'Integer', 'default' => 25), 'sort' => array('name' => 'iSortCol_0', 'type' => 'Integer', 'default' => 'created_date'), 'sortOrder' => array('name' => 'sSortDir_0', 'type' => 'String', 'default' => 'desc'));
     foreach ($dataTableParams as $pName => $pValues) {
         ${$pName} = $pValues['default'];
         if (!empty($_POST[$pValues['name']])) {
             ${$pName} = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
             if ($pName == 'sort') {
                 ${$pName} = $selectorCols[${$pName}];
             }
         }
     }
     foreach (array('sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) {
         $params[$sortParam] = ${$sortParam};
     }
     $petitions = CRM_Campaign_Page_DashBoard::getPetitionSummary($params);
     $searchCount = CRM_Campaign_BAO_Petition::getPetitionSummary($params, TRUE);
     $iTotal = $searchCount;
     if ($searchCount > 0) {
         if ($searchCount < $offset) {
             $offset = 0;
         }
         foreach ($petitions as $petitionID => $values) {
             foreach ($selectorCols as $col) {
                 $searchRows[$petitionID][$col] = CRM_Utils_Array::value($col, $values);
             }
         }
     }
     $selectorElements = $selectorCols;
     $iFilteredTotal = $iTotal;
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
コード例 #24
0
ファイル: Export.php プロジェクト: jenlampton/civicrm-core
 /**
  * Handle import error file creation.
  */
 public static function invoke()
 {
     $type = CRM_Utils_Request::retrieve('type', 'Positive', CRM_Core_DAO::$_nullObject);
     $parserName = CRM_Utils_Request::retrieve('parser', 'String', CRM_Core_DAO::$_nullObject);
     if (empty($parserName) || empty($type)) {
         return;
     }
     // clean and ensure parserName is a valid string
     $parserName = CRM_Utils_String::munge($parserName);
     $parserClass = explode('_', $parserName);
     // make sure parserClass is in the CRM namespace and
     // at least 3 levels deep
     if ($parserClass[0] == 'CRM' && count($parserClass) >= 3) {
         require_once str_replace('_', DIRECTORY_SEPARATOR, $parserName) . ".php";
         // ensure the functions exists
         if (method_exists($parserName, 'errorFileName') && method_exists($parserName, 'saveFileName')) {
             $errorFileName = $parserName::errorFileName($type);
             $saveFileName = $parserName::saveFileName($type);
             if (!empty($errorFileName) && !empty($saveFileName)) {
                 CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
                 CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer');
                 CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
                 CRM_Utils_System::setHttpHeader('Content-Length', filesize($errorFileName));
                 CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . $saveFileName);
                 readfile($errorFileName);
             }
         }
     }
     CRM_Utils_System::civiExit();
 }
コード例 #25
0
ファイル: Utils.php プロジェクト: utkarshsharma/civicrm-core
 /**
  * @param string $fileName
  * @param $searchPath
  * @param $values
  * @param int $numPages
  * @param bool $echo
  * @param string $output
  * @param string $creator
  * @param string $author
  * @param string $title
  */
 public static function &pdflib($fileName, $searchPath, &$values, $numPages = 1, $echo = TRUE, $output = 'College_Match_App', $creator = 'CiviCRM', $author = 'http://www.civicrm.org/', $title = '2006 College Match Scholarship Application')
 {
     try {
         $pdf = new PDFlib();
         $pdf->set_parameter("compatibility", "1.6");
         $pdf->set_parameter("licensefile", "/home/paras/bin/license/pdflib.txt");
         if ($pdf->begin_document('', '') == 0) {
             CRM_Core_Error::statusBounce("PDFlib Error: " . $pdf->get_errmsg());
         }
         $config = CRM_Core_Config::singleton();
         $pdf->set_parameter('resourcefile', $config->templateDir . '/Quest/pdf/pdflib.upr');
         $pdf->set_parameter('textformat', 'utf8');
         /* Set the search path for fonts and PDF files */
         $pdf->set_parameter('SearchPath', $searchPath);
         /* This line is required to avoid problems on Japanese systems */
         $pdf->set_parameter('hypertextencoding', 'winansi');
         $pdf->set_info('Creator', $creator);
         $pdf->set_info('Author', $author);
         $pdf->set_info('Title', $title);
         $blockContainer = $pdf->open_pdi($fileName, '', 0);
         if ($blockContainer == 0) {
             CRM_Core_Error::statusBounce('PDFlib Error: ' . $pdf->get_errmsg());
         }
         for ($i = 1; $i <= $numPages; $i++) {
             $page = $pdf->open_pdi_page($blockContainer, $i, '');
             if ($page == 0) {
                 CRM_Core_Error::statusBounce('PDFlib Error: ' . $pdf->get_errmsg());
             }
             /* dummy page size */
             $pdf->begin_page_ext(20, 20, '');
             /* This will adjust the page size to the block container's size. */
             $pdf->fit_pdi_page($page, 0, 0, 'adjustpage');
             $status = array();
             /* Fill all text blocks with dynamic data */
             foreach ($values as $key => $value) {
                 if (is_array($value)) {
                     continue;
                 }
                 // pdflib does like the forward slash character, hence convert
                 $value = str_replace('/', '_', $value);
                 $res = $pdf->fill_textblock($page, $key, $value, 'embedding encoding=winansi');
             }
             $pdf->end_page_ext('');
             $pdf->close_pdi_page($page);
         }
         $pdf->end_document('');
         $pdf->close_pdi($blockContainer);
         $buf = $pdf->get_buffer();
         $len = strlen($buf);
         if ($echo) {
             CRM_Utils_System::setHttpHeader('Content-type', 'application/pdf');
             CRM_Utils_System::setHttpHeader("Content-Length", $len);
             CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename={$output}.pdf");
             echo $buf;
             CRM_Utils_System::civiExit();
         } else {
             return $buf;
         }
     } catch (PDFlibException $excp) {
         CRM_Core_Error::statusBounce('PDFlib Error: Exception' . "[" . $excp->get_errnum() . "] " . $excp->get_apiname() . ": " . $excp->get_errmsg());
     } catch (Exception $excp) {
         CRM_Core_Error::statusBounce("PDFlib Error: " . $excp->get_errmsg());
     }
 }