Exemple #1
0
 /**
  * Post Processing function for Form.
  *
  * postProcessCommon should be used to set other variables from input as the api accesses that function.
  * This function is not accessed when the api calls the report.
  */
 public function beginPostProcess()
 {
     $this->setParams($this->controller->exportValues($this->_name));
     if (empty($this->_params) && $this->_force) {
         $this->setParams($this->_formValues);
     }
     // hack to fix params when submitted from dashboard, CRM-8532
     // fields array is missing because form building etc is skipped
     // in dashboard mode for report
     //@todo - this could be done in the dashboard no we have a setter
     if (empty($this->_params['fields']) && !$this->_noFields) {
         $this->setParams($this->_formValues);
     }
     $this->_formValues = $this->_params;
     if (CRM_Core_Permission::check('administer Reports') && isset($this->_id) && ($this->_instanceButtonName == $this->controller->getButtonName() . '_save' || $this->_chartButtonName == $this->controller->getButtonName())) {
         $this->assign('updateReportButton', TRUE);
     }
     $this->processReportMode();
     if ($this->_outputMode == 'save' || $this->_outputMode == 'copy') {
         $this->_createNew = $this->_outputMode == 'copy';
         // Do not pass go. Do not collect another chance to re-run the same query.
         // This will be called from the button - there is an earlier response to the url
         // perhaps they can still be consolidated more.
         CRM_Report_Form_Instance::postProcess($this);
     }
     $this->beginPostProcessCommon();
 }
Exemple #2
0
 /**
  * Post Processing function for Form.
  *
  * postProcessCommon should be used to set other variables from input as the api accesses that function.
  * This function is not accessed when the api calls the report.
  */
 public function beginPostProcess()
 {
     $this->setParams($this->controller->exportValues($this->_name));
     if (empty($this->_params) && $this->_force) {
         $this->setParams($this->_formValues);
     }
     // hack to fix params when submitted from dashboard, CRM-8532
     // fields array is missing because form building etc is skipped
     // in dashboard mode for report
     //@todo - this could be done in the dashboard no we have a setter
     if (empty($this->_params['fields']) && !$this->_noFields) {
         $this->setParams($this->_formValues);
     }
     $this->processReportMode();
     if ($this->_outputMode == 'save' || $this->_outputMode == 'copy') {
         $this->_createNew = $this->_outputMode == 'copy';
         CRM_Report_Form_Instance::postProcess($this);
     }
     if ($this->_outputMode == 'delete') {
         CRM_Report_BAO_ReportInstance::doFormDelete($this->_id, 'civicrm/report/list?reset=1', 'civicrm/report/list?reset=1');
     }
     $this->_formValues = $this->_params;
     $this->beginPostProcessCommon();
 }
  /**
   * @param null $rows
   */
  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;
      }
      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 formattd png
          header('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);
    }
    elseif ($this->_instanceButtonName == $this->controller->getButtonName()) {
      CRM_Report_Form_Instance::postProcess($this);
    }
    elseif ($this->_createNewButtonName == $this->controller->getButtonName() ||
      $this->_outputMode == 'create_report'
    ) {
      $this->_createNew = TRUE;
      CRM_Report_Form_Instance::postProcess($this);
    }
  }
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $status = '';
     $params = $this->controller->exportValues($this->_name);
     $params['id'] = $this->_surveyId;
     $updateResultSet = FALSE;
     $resultSetOptGrpId = NULL;
     if (CRM_Utils_Array::value('option_type', $params) == 2 && !empty($params['option_group_id'])) {
         $updateResultSet = TRUE;
         $resultSetOptGrpId = $params['option_group_id'];
     }
     $recontactInterval = array();
     if ($updateResultSet) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $resultSetOptGrpId;
         $optionValue->delete();
         $params['result_id'] = $resultSetOptGrpId;
     } else {
         $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
         $optionGroup = new CRM_Core_DAO_OptionGroup();
         $optionGroup->name = $opGroupName;
         $optionGroup->title = $this->_values['title'] . ' Result Set';
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['result_id'] = $optionGroup->id;
     }
     foreach ($params['option_value'] as $k => $v) {
         if (strlen(trim($v))) {
             $optionValue = new CRM_Core_DAO_OptionValue();
             $optionValue->option_group_id = $params['result_id'];
             $optionValue->label = $params['option_label'][$k];
             $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
             $optionValue->value = trim($v);
             $optionValue->weight = $params['option_weight'][$k];
             $optionValue->is_active = 1;
             if (!empty($params['default_option']) && $params['default_option'] == $k) {
                 $optionValue->is_default = 1;
             }
             $optionValue->save();
             // using is_numeric since 0 is a valid value for option_interval
             if (is_numeric($params['option_interval'][$k])) {
                 $recontactInterval[$optionValue->label] = $params['option_interval'][$k];
             }
         }
     }
     $params['recontact_interval'] = serialize($recontactInterval);
     $survey = CRM_Campaign_BAO_Survey::create($params);
     // create report if required.
     if (!$this->_reportId && $survey->id && !empty($params['create_report'])) {
         $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
         $activityStatus = array_flip($activityStatus);
         $this->_params = array('name' => "survey_{$survey->id}", 'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'], 'status_id_op' => 'eq', 'status_id_value' => $activityStatus['Scheduled'], 'survey_id_value' => array($survey->id), 'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.'));
         //Default value of order by
         $this->_params['order_bys'] = array(1 => array('column' => 'sort_name', 'order' => 'ASC'));
         // for WalkList or default
         $displayFields = array('id', 'sort_name', 'result', 'street_number', 'street_name', 'street_unit', 'survey_response');
         if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_values['activity_type_id']) {
             $this->_params['order_bys'] = array(1 => array('column' => 'street_name', 'order' => 'ASC'), 2 => array('column' => 'street_number_odd_even', 'order' => 'ASC'), 3 => array('column' => 'street_number', 'order' => 'ASC'), 4 => array('column' => 'sort_name', 'order' => 'ASC'));
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone');
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'Survey') == $this->_values['activity_type_id'] || CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email');
         }
         foreach ($displayFields as $key) {
             $this->_params['fields'][$key] = 1;
         }
         $this->_createNew = TRUE;
         $this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail');
         CRM_Report_Form_Instance::postProcess($this, FALSE);
         $query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1";
         $reportID = CRM_Core_DAO::singleValueQuery($query, array(1 => array("survey_{$survey->id}", 'String')));
         if ($reportID) {
             $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
             $status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.", array(1 => $url, 2 => $this->_params['title']));
         }
     }
     if ($status) {
         // reset status as we don't want status set by Instance::postProcess
         $session = CRM_Core_Session::singleton();
         $session->getStatus(TRUE);
         // set new status
         CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
     }
     parent::endPostProcess();
 }
Exemple #5
0
 function endPostProcess(&$rows = null)
 {
     if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf' || $this->_sendmail) {
         $templateFile = parent::getTemplateFileName();
         $content = $this->_formValues['report_header'] . CRM_Core_Form::$_template->fetch($templateFile) . $this->_formValues['report_footer'];
         if ($this->_sendmail) {
             if (CRM_Report_Utils_Report::mailReport($content, $this->_id, $this->_outputMode)) {
                 CRM_Core_Session::setStatus(ts("Report mail has been sent."));
             } else {
                 CRM_Core_Session::setStatus(ts("Report mail could not be sent."));
             }
             if ($this->get('instanceId')) {
                 CRM_Utils_System::civiExit();
             }
             CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
         } else {
             if ($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 = $chartType . '_' . $this->_id . '.png';
                     //get image url path
                     $uploadUrl = str_replace('persist/contribute', 'upload/openFlashChart', $config->imageUploadURL);
                     $uploadUrl .= $chartImg;
                     //get image doc path to overwrite
                     $uploadImg = $config->uploadDir . 'openFlashChart/' . $chartImg;
                     //Load the image
                     $chart = imagecreatefrompng($uploadUrl);
                     //convert it into formattd png
                     header('Content-type: image/png');
                     //overwrite with same image
                     imagepng($chart, $uploadImg);
                     //delete the object
                     imagedestroy($chart);
                 }
                 require_once 'CRM/Utils/PDF/Utils.php';
                 CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf");
             }
         }
         CRM_Utils_System::civiExit();
     } else {
         if ($this->_outputMode == 'csv') {
             CRM_Report_Utils_Report::export2csv($this, $rows);
         } else {
             if ($this->_outputMode == 'group') {
                 $group = $this->_params['groups'];
                 CRM_Report_Utils_Report::add2group($this, $group);
             } else {
                 if ($this->_instanceButtonName == $this->controller->getButtonName()) {
                     require_once 'CRM/Report/Form/Instance.php';
                     CRM_Report_Form_Instance::postProcess($this);
                 }
             }
         }
     }
 }
Exemple #6
0
 function endPostProcess(&$rows = null)
 {
     if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf' || $this->_sendmail) {
         $templateFile = parent::getTemplateFileName();
         $content = $this->_formValues['report_header'] . CRM_Core_Form::$_template->fetch($templateFile) . $this->_formValues['report_footer'];
         if ($this->_sendmail) {
             if (CRM_Report_Utils_Report::mailReport($content, $this->_id, $this->_outputMode)) {
                 CRM_Core_Session::setStatus(ts("Report mail has been sent."));
             } else {
                 CRM_Core_Session::setStatus(ts("Report mail could not be sent."));
             }
             if ($this->get('instanceId')) {
                 exit;
             }
             CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
         } else {
             if ($this->_outputMode == 'print') {
                 echo $content;
             } else {
                 require_once 'CRM/Utils/PDF/Utils.php';
                 CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf");
             }
         }
         exit;
     } else {
         if ($this->_outputMode == 'csv') {
             CRM_Report_Utils_Report::export2csv($this, $rows);
         } else {
             if ($this->_outputMode == 'group') {
                 $group = $this->_params['groups'];
                 CRM_Report_Utils_Report::add2group($this, $group);
             } else {
                 if ($this->_instanceButtonName == $this->controller->getButtonName()) {
                     require_once 'CRM/Report/Form/Instance.php';
                     CRM_Report_Form_Instance::postProcess($this);
                 }
             }
         }
     }
 }