Esempio n. 1
0
 /**
  * get an existing snapshot
  */
 public static function get($snapshot_id)
 {
     $snapshot = new CRM_Donrec_Logic_Snapshot($snapshot_id);
     if ($snapshot->exists()) {
         return $snapshot;
     } else {
         return NULL;
     }
 }
Esempio n. 2
0
 /**
  * Will try to initialize the engine with a snapshot
  * and the given parameters. If anything is wrong,
  * an error message will be returned.
  *
  * @return string with an error message on fail, FALSE otherwise
  */
 public function init($snapshot_id, $params = array(), $testMode = FALSE)
 {
     $this->parameters = $params;
     $this->snapshot = CRM_Donrec_Logic_Snapshot::get($snapshot_id);
     if ($this->snapshot == NULL) {
         return sprintf(ts("Snapshot [%d] does not exist (any more)!", array('domain' => 'de.systopia.donrec')), $snapshot_id);
     }
     // now, check if it's ours:
     $user_id = CRM_Core_Session::singleton()->get('userID');
     $snapshot_creator_id = $this->snapshot->getCreator();
     if ($user_id != $snapshot_creator_id && !$testMode) {
         // load creator name
         $creator = civicrm_api3('Contact', 'getsingle', array('id' => $snapshot_creator_id));
         return sprintf(ts("Snapshot [%d] belongs to user '%s'[%s]!", array('domain' => 'de.systopia.donrec')), $snapshot_id, $creator['display_name'], $snapshot_creator_id);
     }
     // now, if this is supposed to be test mode, there must not be a real status
     if ($this->isTestRun()) {
         $snapshot_status = $this->getSnapshotStatus();
         if ($snapshot_status == 'RUNNING') {
             return sprintf(ts("Snapshot [%d] is already processing!", array('domain' => 'de.systopia.donrec')), $snapshot_id);
         } elseif ($snapshot_status == 'COMPLETE') {
             return sprintf(ts("Snapshot [%d] is already completed!", array('domain' => 'de.systopia.donrec')), $snapshot_id);
         }
     }
     return FALSE;
 }
Esempio n. 3
0
 /** 
  * Build and run the query to select all contributions
  * matching the criteria, and try to create a snapshot
  *
  * @return snapshot creation result/error
  */
 public static function createSnapshot($values)
 {
     // prepare timestamps
     $raw_from_ts = $values['donrec_contribution_horizon_from'];
     $raw_to_ts = $values['donrec_contribution_horizon_to'];
     $date_from = CRM_Utils_DonrecHelper::convertDate($raw_from_ts, -1);
     $date_to = CRM_Utils_DonrecHelper::convertDate($raw_to_ts, 1);
     $formatted_date_from = date('Y-m-d H:i:s', $date_from);
     $formatted_date_to = date('Y-m-d H:i:s', $date_to);
     $query_date_limit = "";
     if ($date_from) {
         $query_date_limit .= "AND `receive_date` >= '{$formatted_date_from}'";
     }
     if ($date_to) {
         $query_date_limit .= " AND `receive_date` <= '{$formatted_date_to}'";
     }
     // get table- and column name
     $table_query = "SELECT `cg`.`table_name`,\n                           `cf`.`column_name`\n                    FROM `civicrm_custom_group` AS cg,\n                         `civicrm_custom_field` AS cf\n                    WHERE `cg`.`name` = 'zwb_donation_receipt_item'\n                      AND `cf`.`custom_group_id` = `cg`.`id`\n                      AND `cf`.`name` = 'status'";
     $results = CRM_Core_DAO::executeQuery($table_query);
     $custom_group_table = NULL;
     $status_column = NULL;
     while ($results->fetch()) {
         $custom_group_table = $results->table_name;
         $status_column = $results->column_name;
     }
     if ($custom_group_table == NULL || $status_column == NULL) {
         // something went wrong here
         CRM_Core_Error::debug_log_message("de.systopia.donrec: error: custom_group_table or status_column is empty!");
         return array();
     }
     // calculate main selector clause
     if (!empty($values['contact_id'])) {
         $contact_id = (int) $values['contact_id'];
         $main_selector = "`contact_id` = {$contact_id}";
     } elseif (!empty($values['contact_ids'])) {
         $contact_ids = implode(',', $values['contact_ids']);
         $main_selector = "`contact_id` IN ({$contact_ids})";
     } elseif (!empty($values['contribution_ids'])) {
         $contribution_ids = implode(',', $values['contribution_ids']);
         $main_selector = "`civicrm_contribution`.`id` IN ({$contribution_ids})";
     } else {
         CRM_Core_Error::debug_log_message("de.systopia.donrec: error: no selector data found in params!");
         $main_selector = "FALSE";
     }
     // get financial type selector clause
     $profile = new CRM_Donrec_Logic_Profile($values['profile']);
     $financialTypeClause = $profile->getContributionTypesClause();
     // run the main query
     $query = "SELECT `civicrm_contribution`.`id`\n              FROM (`civicrm_contribution`)\n              LEFT JOIN `{$custom_group_table}` AS existing_receipt\n                  ON  `civicrm_contribution`.`id` = existing_receipt.`entity_id`\n                  AND existing_receipt.`{$status_column}` = 'ORIGINAL'\n              WHERE\n                  ({$main_selector})\n                  {$query_date_limit}\n                  AND {$financialTypeClause}\n                  AND (`non_deductible_amount` = 0 OR `non_deductible_amount` IS NULL)\n                  AND `contribution_status_id` = 1\n                  AND `is_test` = 0\n                  AND `currency` = 'EUR'\n                  AND existing_receipt.`entity_id` IS NULL;";
     // execute the query
     $result = CRM_Core_DAO::executeQuery($query);
     // build array
     $contributionIds = array();
     while ($result->fetch()) {
         $contributionIds[] = $result->id;
     }
     // finally, build the snapshot with it
     return CRM_Donrec_Logic_Snapshot::create($contributionIds, CRM_Donrec_Logic_Settings::getLoggedInContactID(), $formatted_date_from, $formatted_date_to, $values['profile']);
 }
Esempio n. 4
0
 /**
  * generate the final result
  *
  * @return array:
  *          'is_error': set if there is a fatal error
  *          'log': array with keys: 'type', 'level', 'timestamp', 'message'
  *          'download_url: URL to download the result
  *          'download_name: suggested file name for the download
  */
 public function wrapUp($snapshot_id, $is_test, $is_bulk)
 {
     $snapshot = CRM_Donrec_Logic_Snapshot::get($snapshot_id);
     $reply = array();
     // open file
     $preferredFileName = ts('donation_receipts');
     $preferredFileSuffix = ts('.csv', array('domain' => 'de.systopia.donrec'));
     $temp_file = CRM_Donrec_Logic_File::makeFileName($preferredFileName, $preferredFileSuffix);
     $handle = fopen($temp_file, 'w');
     // get headers
     $headers = CRM_Donrec_Logic_ReceiptTokens::getFullTokenList();
     $headers = $this->flattenTokenData($headers);
     $headers = array_keys($headers);
     $header_written = false;
     // write them all into the file
     $ids = $snapshot->getIds();
     foreach ($ids as $id) {
         $proc_info = $snapshot->getProcessInformation($id);
         $csv_data = $proc_info['CSV']['csv_data'];
         if (!empty($csv_data)) {
             if (!$header_written) {
                 // extend header by extra fields
                 $headers = array_merge($headers, array_keys($csv_data));
                 $headers = array_unique($headers);
                 // write header
                 fputcsv($handle, $headers, ';', '"');
                 $header_written = true;
             }
             // create and write a line
             $line = array();
             foreach ($headers as $field) {
                 if (isset($csv_data[$field])) {
                     $line[$field] = $csv_data[$field];
                 } else {
                     $line[$field] = '';
                 }
             }
             fputcsv($handle, $line, ';', '"');
         }
     }
     // get process info iterator
     fclose($handle);
     // create the file
     $file = CRM_Donrec_Logic_File::createTemporaryFile($temp_file, $preferredFileName . $preferredFileSuffix);
     CRM_Core_Error::debug_log_message("de.systopia.donrec: resulting CSV file URL is '{$file}'.");
     if (!empty($file)) {
         $reply['download_name'] = $preferredFileName;
         $reply['download_url'] = $file;
     }
     CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'CSV process ended.', CRM_Donrec_Logic_Exporter::LOG_TYPE_INFO);
     return $reply;
 }
 function testCopy()
 {
     // prerequisites
     $contributions = $this->generateContributions(3);
     $this->assertEquals(3, count($contributions));
     // generate a new snapshot
     $snapshot = CRM_Donrec_Logic_Snapshot::create($contributions, 1);
     $this->assertNotNull($snapshot, "CRM_Donrec_Logic_Snapshot::create() returned NULL");
     // create a receipt
     $snapshot_line_id = 1;
     $params = array();
     $result = CRM_Donrec_Logic_Receipt::createSingleFromSnapshot($snapshot, $snapshot_line_id, $params);
     $this->assertEquals(TRUE, $result, "CRM_Donrec_Logic_Receipt::createSingleFromSnapshot returned FALSE");
     // clone it
 }
Esempio n. 6
0
 /**
  * generate the final result
  *
  * @return array:
  *          'is_error': set if there is a fatal error
  *          'log': array with keys: 'type', 'level', 'timestamp', 'message'
  *          'download_url: URL to download the result
  *          'download_name: suggested file name for the download
  */
 public function wrapUp($snapshot_id, $is_test, $is_bulk)
 {
     $reply = array();
     // create the zip file
     $config = CRM_Core_Config::singleton();
     $preferredFileName = ts("donation_receipts.zip", array('domain' => 'de.systopia.donrec'));
     $archiveFileName = CRM_Donrec_Logic_File::makeFileName(ts("donation_receipts", array('domain' => 'de.systopia.donrec')), ".zip");
     $zip = new ZipArchive();
     $snapshot = CRM_Donrec_Logic_Snapshot::get($snapshot_id);
     $ids = $snapshot->getIds();
     $toRemove = array();
     if ($zip->open($archiveFileName, ZIPARCHIVE::CREATE) === TRUE) {
         foreach ($ids as $id) {
             $proc_info = $snapshot->getProcessInformation($id);
             if (!empty($proc_info)) {
                 $filename = isset($proc_info['PDF']['pdf_file']) ? $proc_info['PDF']['pdf_file'] : FALSE;
                 if ($filename) {
                     $toRemove[$id] = $filename;
                     $opResult = $zip->addFile($filename, basename($filename));
                     CRM_Donrec_Logic_Exporter::addLogEntry($reply, "adding <span title='{$filename}'>created PDF file</span> to <span title='{$archiveFileName}'>ZIP archive</span> ({$opResult})", CRM_Donrec_Logic_Exporter::LOG_TYPE_DEBUG);
                 }
             }
         }
         if (!$zip->close()) {
             CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'zip->close() returned false!', CRM_Donrec_Logic_Exporter::LOG_TYPE_ERROR);
         }
     } else {
         CRM_Donrec_Logic_Exporter::addLogEntry($reply, sprintf('PDF processing failed: Could not open zip file '), CRM_Donrec_Logic_Exporter::LOG_TYPE_FATAL);
         return $reply;
     }
     $file = CRM_Donrec_Logic_File::createTemporaryFile($archiveFileName, $preferredFileName);
     CRM_Core_Error::debug_log_message("de.systopia.donrec: resulting ZIP file URL is '{$file}'.");
     if (!empty($file)) {
         $reply['download_name'] = $preferredFileName;
         $reply['download_url'] = $file;
     }
     // remove loose pdf files or store them
     CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'Removing temporary PDF files.', CRM_Donrec_Logic_Exporter::LOG_TYPE_DEBUG);
     foreach ($toRemove as $file) {
         unlink($file);
     }
     CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'PDF generation process ended.', CRM_Donrec_Logic_Exporter::LOG_TYPE_INFO);
     return $reply;
 }
Esempio n. 7
0
 function postProcess()
 {
     // CAUTION: changes to this function should also be done in CRM_Donrec_Form_Task_Create:postProcess()
     // process remaining snapshots if exsisting
     $rsid = empty($_REQUEST['rsid']) ? NULL : $_REQUEST['rsid'];
     if (!empty($rsid)) {
         //work on with a remaining snapshot...
         $use_remaining_snapshot = CRM_Utils_Array::value('use_remaining_snapshot', $_REQUEST, NULL);
         if (!empty($use_remaining_snapshot)) {
             CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/donrec/task', 'sid=' . $rsid));
             return;
             // or delete all remaining snapshots of this user
         } else {
             $uid = CRM_Donrec_Logic_Settings::getLoggedInContactID();
             CRM_Donrec_Logic_Snapshot::deleteUserSnapshots($uid);
         }
     }
     // process form values and try to build a snapshot with all contributions
     // that match the specified criteria (i.e. contributions which have been
     // created between two specific dates)
     $values = $this->exportValues();
     $values['contact_ids'] = $this->_contactIds;
     //set url_back as session-variable
     $session = CRM_Core_Session::singleton();
     $session->set('url_back', CRM_Utils_System::url('civicrm/contact/search', "reset=1"));
     // generate the snapshot
     $result = CRM_Donrec_Logic_Selector::createSnapshot($values);
     $sid = empty($result['snapshot']) ? NULL : $result['snapshot']->getId();
     if (!empty($result['intersection_error'])) {
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/donrec/task', 'conflict=1' . '&sid=' . $result['snapshot']->getId() . '&ccount=' . count($this->_contactIds)));
     } elseif (empty($result['snapshot'])) {
         CRM_Core_Session::setStatus(ts('There are no selectable contributions for these contacts in the selected time period.', array('domain' => 'de.systopia.donrec')), ts('Warning', array('domain' => 'de.systopia.donrec')), 'warning');
         $qfKey = $values['qfKey'];
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search', "_qf_DonrecTask_display=true&qfKey={$qfKey}"));
     } else {
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/donrec/task', 'sid=' . $result['snapshot']->getId() . '&ccount=' . count($this->_contactIds)));
     }
 }
 /**
  * 
  *
  * @author niko bochan
  */
 public function testSnapshotConflictMixed()
 {
     // prerequisites
     $contributions = $this->generateContributions(5);
     $this->assertEquals(5, count($contributions));
     // generate a snapshot
     $result = CRM_Donrec_Logic_Snapshot::create($contributions, 1);
     $snapshot1 = $result['snapshot'];
     $this->assertNotNull($snapshot1, "CRM_Donrec_Logic_Snapshot::create() returned NULL");
     $this->assertDBQuery(5, "SELECT count(*) FROM `donrec_snapshot`");
     // generate a second, expired snapshot
     $result = CRM_Donrec_Logic_Snapshot::create($contributions, 2, -10);
     $snapshot2 = $result['snapshot'];
     $this->assertNotNull($snapshot2, "CRM_Donrec_Logic_Snapshot::create() returned NULL");
     $this->assertDBQuery(10, "SELECT count(*) FROM `donrec_snapshot`");
     // check if there are intersections between the two snapshots
     error_log("\n--- the following warnings are expected ---");
     $result = CRM_Donrec_Logic_Snapshot::hasIntersections();
     $this->assertEquals(5, $result);
     error_log("--- end of expected warnings ---");
 }
Esempio n. 9
0
 function run()
 {
     CRM_Utils_System::setTitle(ts('Issue Donation Receipts', array('domain' => 'de.systopia.donrec')));
     // Since 4.6 the css-class crm-summary-row lives in contactSummary.css
     // instead of civicrm.css
     if (version_compare(CRM_Utils_System::version(), '4.6', '>=')) {
         CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/contactSummary.css');
     }
     $id = empty($_REQUEST['sid']) ? NULL : $_REQUEST['sid'];
     $ccount = empty($_REQUEST['ccount']) ? NULL : $_REQUEST['ccount'];
     $selected_exporter = empty($_REQUEST['exporters']) ? NULL : $_REQUEST['exporters'];
     $origin = empty($_REQUEST['origin']) ? NULL : $_REQUEST['origin'];
     // working on a test-snapshot
     $from_test = empty($_REQUEST['from_test']) ? NULL : $_REQUEST['from_test'];
     $this->assign('from_test', $from_test);
     // add statistic
     if (!empty($id)) {
         $statistic = CRM_Donrec_Logic_Snapshot::getStatistic($id);
         $statistic['requested_contacts'] = $ccount;
         $this->assign('statistic', $statistic);
     }
     if (!empty($selected_exporter)) {
         $this->assign('selected_exporter', $selected_exporter);
     }
     // check which button was clicked
     // called when the 'abort' button was selected
     if (!empty($_REQUEST['donrec_abort']) || !empty($_REQUEST['donrec_abort_by_admin'])) {
         $by_admin = !empty($_REQUEST['donrec_abort_by_admin']);
         // we need a (valid) snapshot id here
         if (empty($id)) {
             $this->assign('error', ts('No snapshot id has been provided!', array('domain' => 'de.systopia.donrec')));
             $this->assign('url_back', CRM_Utils_System::url('civicrm/donrec/task'));
         } else {
             $snapshot = CRM_Donrec_Logic_Snapshot::get($id);
             if (empty($snapshot)) {
                 $this->assign('error', ts('Invalid snapshot id!', array('domain' => 'de.systopia.donrec')));
                 $this->assign('url_back', CRM_Utils_System::url('civicrm/donrec/task'));
             } else {
                 // delete the snapshot and redirect to search form
                 $snapshot->delete();
                 if ($by_admin) {
                     $return_id = $_REQUEST['return_to'];
                     CRM_Core_Session::setStatus(ts('The older snapshot has been deleted. You can now proceed.', array('domain' => 'de.systopia.donrec')), ts('Warning', array('domain' => 'de.systopia.donrec')), 'warning');
                     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/donrec/task', "sid={$return_id}&ccount={$ccount}"));
                 } else {
                     CRM_Core_Session::setStatus(ts('The previously created snapshot has been deleted.', array('domain' => 'de.systopia.donrec')), ts('Warning', array('domain' => 'de.systopia.donrec')), 'warning');
                     if (!empty($_REQUEST['origin'])) {
                         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$origin}&selectedChild=donation_receipts"));
                     } else {
                         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search'));
                     }
                 }
             }
         }
     } elseif (!empty($_REQUEST['donrec_testrun'])) {
         // called when the 'test run' button was selected
         $bulk = (int) ($_REQUEST['donrec_type'] == "2");
         $exporters = $_REQUEST['result_type'];
         // at least one exporter has to be selected
         if (empty($exporters)) {
             $this->assign('error', ts('Missing exporter!', array('domain' => 'de.systopia.donrec')));
             $this->assign('url_back', CRM_Utils_System::url('civicrm/donrec/task'));
         } else {
             //on testrun we want to return to the stats-page instead of the contact-search-page
             //but we must not overwrite the url_back-var
             $session = CRM_Core_Session::singleton();
             $session->set('url_back_test', CRM_Utils_System::url('civicrm/donrec/task', "sid={$id}&ccount={$ccount}&from_test=1&origin={$origin}"));
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/donrec/runner', "sid={$id}&bulk={$bulk}&exporters={$exporters}"));
         }
     } elseif (!empty($_REQUEST['donrec_run'])) {
         // issue donation receipts case
         $bulk = (int) ($_REQUEST['donrec_type'] == "2");
         $exporters = $_REQUEST['result_type'];
         // at least one exporter has to be selected
         if (empty($exporters)) {
             $this->assign('error', ts('Missing exporter!', array('domain' => 'de.systopia.donrec')));
             $this->assign('url_back', CRM_Utils_System::url('civicrm/donrec/task'));
         } else {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/donrec/runner', "sid={$id}&bulk={$bulk}&final=1&exporters={$exporters}"));
         }
     } elseif (!empty($_REQUEST['conflict'])) {
         // called when a snapshot conflict has been detected
         $conflict = CRM_Donrec_Logic_Snapshot::hasIntersections();
         if (!$conflict) {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/donrec/task', "sid={$id}&ccount={$ccount}"));
         }
         $this->assign('conflict_error', $conflict[1]);
         $this->assign('url_back', CRM_Utils_System::url('civicrm/contact/search'));
         if (CRM_Core_Permission::check('delete receipts')) {
             $this->assign('is_admin', 1);
             $this->assign('return_to', $conflict[2][0]);
             $this->assign('formAction', CRM_Utils_System::url('civicrm/donrec/task', "sid=" . $conflict[1][0] . "&ccount={$ccount}", false, null, false, true));
         }
     } else {
         if (empty($id)) {
             $this->assign('error', ts('No snapshot id has been provided!', array('domain' => 'de.systopia.donrec')));
             $this->assign('url_back', CRM_Utils_System::url('civicrm/contact/search', ''));
         } else {
             // get supported exporters
             $exp_array = array();
             $exporters = CRM_Donrec_Logic_Exporter::listExporters();
             foreach ($exporters as $exporter) {
                 $classname = CRM_Donrec_Logic_Exporter::getClassForExporter($exporter);
                 // check requirements
                 $instance = new $classname();
                 $result = $instance->checkRequirements();
                 $is_usable = TRUE;
                 $error_msg = "";
                 $info_msg = "";
                 if ($result['is_error']) {
                     $is_usable = FALSE;
                     $error_msg = $result['message'];
                 } else {
                     if (!empty($result['message'])) {
                         $info_msg = $result['message'];
                     }
                 }
                 $exp_array[] = array($exporter, $classname::name(), $classname::htmlOptions(), $is_usable, $error_msg, $info_msg);
             }
             $this->assign('exporters', $exp_array);
             $this->assign('formAction', CRM_Utils_System::url('civicrm/donrec/task', "sid={$id}&ccount={$ccount}&origin={$origin}", false, null, false, true));
         }
     }
     parent::run();
 }
Esempio n. 10
0
 /**
  * generate the final result
  *
  * @return array:
  *          'is_error': set if there is a fatal error
  *          'log': array with keys: 'type', 'level', 'timestamp', 'message'
  *          'download_url: URL to download the result
  *          'download_name: suggested file name for the download
  */
 public function wrapUp($snapshot_id, $is_test, $is_bulk)
 {
     $reply = array();
     // create the zip file
     $config = CRM_Core_Config::singleton();
     $preferredFileName = ts("donation_receipts", array('domain' => 'de.systopia.donrec'));
     $preferredSuffix = ts('.zip', array('domain' => 'de.systopia.donrec'));
     $archiveFileName = CRM_Donrec_Logic_File::makeFileName($preferredFileName, $preferredSuffix);
     $fileURL = $archiveFileName;
     $outerArchive = new ZipArchive();
     $snapshot = CRM_Donrec_Logic_Snapshot::get($snapshot_id);
     $ids = $snapshot->getIds();
     $toRemove = array();
     // Sort array by page count
     $pageCountArr = array();
     foreach ($ids as $id) {
         $proc_info = $snapshot->getProcessInformation($id);
         if (!empty($proc_info)) {
             $pageCount = isset($proc_info['PDF']['pdf_pagecount']) ? $proc_info['PDF']['pdf_pagecount'] : FALSE;
             $filename = isset($proc_info['PDF']['pdf_file']) ? $proc_info['PDF']['pdf_file'] : FALSE;
             if ($pageCount) {
                 $pageCountArr[$pageCount][] = array($pageCount, $id, $filename);
             }
         }
     }
     // add files to sub-archives
     // open main archive and add sub-archives
     if ($outerArchive->open($fileURL, ZIPARCHIVE::CREATE) === TRUE) {
         foreach ($pageCountArr as $entry) {
             foreach ($entry as $item) {
                 if ($item[0] && $item[2]) {
                     // if page count and file name exists
                     $folder = sprintf(ts('%d-page', array('domain' => 'de.systopia.donrec')), $item[0]) . DIRECTORY_SEPARATOR;
                     $opResult = $outerArchive->addFile($item[2], $folder . basename($item[2]));
                     CRM_Donrec_Logic_Exporter::addLogEntry($reply, "adding <span title='{$item[2]}'>created {$item[0]}-page PDF file</span> ({$opResult})", CRM_Donrec_Logic_Exporter::LOG_TYPE_DEBUG);
                 }
             }
         }
         if (!$outerArchive->close()) {
             CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'zip->close() returned false!', CRM_Donrec_Logic_Exporter::LOG_TYPE_ERROR);
         }
     } else {
         CRM_Donrec_Logic_Exporter::addLogEntry($reply, sprintf('PDF processing failed: Could not open zip file '), CRM_Donrec_Logic_Exporter::FATAL);
         return $reply;
     }
     $file = CRM_Donrec_Logic_File::createTemporaryFile($fileURL, $preferredFileName . $preferredSuffix);
     CRM_Core_Error::debug_log_message("de.systopia.donrec: resulting ZIP file URL is '{$file}'.");
     if (!empty($file)) {
         $reply['download_name'] = $preferredFileName . $preferredSuffix;
         $reply['download_url'] = $file;
     }
     // remove loose pdf files or store them
     CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'Removing temporary files.', CRM_Donrec_Logic_Exporter::LOG_TYPE_DEBUG);
     foreach ($toRemove as $file) {
         unlink($file);
     }
     CRM_Donrec_Logic_Exporter::addLogEntry($reply, 'PDF generation process ended.', CRM_Donrec_Logic_Exporter::LOG_TYPE_INFO);
     return $reply;
 }
Esempio n. 11
0
function donrec_civicrm_pre($op, $objectName, $id, &$params)
{
    if ($objectName == 'Contribution' && ($op == 'edit' || $op == 'delete')) {
        $has_item = CRM_Donrec_Logic_ReceiptItem::hasValidReceiptItem($id);
        $in_snapshot = CRM_Donrec_Logic_Snapshot::isInOpenSnapshot($id);
        if ($has_item || $in_snapshot) {
            if ($op == 'edit') {
                // columns that must not be changed
                $forbidden = array('financial_type_id', 'total_amount', 'receive_date', 'currency', 'contribution_status_id', 'payment_instrument_id');
                // get the contribution
                $query = "\n          SELECT *\n          FROM civicrm_contribution\n          WHERE id = {$id}";
                $result = CRM_Core_DAO::executeQuery($query);
                $result->fetch();
                // check if forbidden values are going to be changed.
                foreach ($forbidden as $col) {
                    if (isset($params[$col]) && $result->{$col} != $params[$col]) {
                        // we need a extra-check for dates (which are not in the same format)
                        if (strpos($col, 'date')) {
                            if ($col == 'receive_date' && substr(preg_replace('/[-: ]/', '', $result->{$col}), 0, -2) . "00" == $params[$col]) {
                                continue;
                            }
                        }
                        $message = sprintf(ts("The column '%s' of this contribution [%d] must not be changed because it has a receipt or is going to be receipted!", array('domain' => 'de.systopia.donrec')), $col, $id);
                        CRM_Utils_DonrecHelper::exitWithMessage($message);
                    }
                }
            } elseif ($op == 'delete') {
                $message = sprintf(ts("This contribution [%d] must not be deleted because it has a receipt or is going to be receipted!", array('domain' => 'de.systopia.donrec')), $id);
                CRM_Utils_DonrecHelper::exitWithMessage($message);
            }
        }
    }
    return;
}
Esempio n. 12
0
 public function testEngineMultiExport()
 {
     // create a new snapshot
     $contributions = $this->generateContributions(6);
     $result = CRM_Donrec_Logic_Snapshot::create($contributions, 1);
     $snapshot = $result['snapshot'];
     // engine setup parameters
     $sid = $snapshot->getId();
     $parameters = array();
     $parameters['test'] = 1;
     $parameters['bulk'] = 0;
     $parameters['exporters'] = 'Dummy,SecondDummy';
     // let's try to start it
     $engine = new CRM_Donrec_Logic_Engine();
     $engine_error = $engine->init($sid, $parameters, TRUE);
     $this->assertEquals(FALSE, $engine_error);
     $ctr = 0;
     foreach ($contributions as $id) {
         $stats = $engine->nextStep();
         $ctr++;
         $this->assertDBQuery('TEST', sprintf("SELECT `status` FROM `donrec_snapshot` WHERE `contribution_id` = %d;", $id));
         $this->assertDBQuery('{"Dummy":{"test":"Dummy was here!"},"SecondDummy":{"test":"2nd Dummy was here!"}}', sprintf("SELECT `process_data` FROM `donrec_snapshot` WHERE `contribution_id` = %d;", $id));
         $this->assertEquals($stats['count'], 6);
         $this->assertEquals($stats['completed_test'], $ctr);
     }
 }