| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class previews the uploaded file and returns summary statistics. |
| 20 | * |
| 21 | * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes, |
| 22 | * those classes can be removed entirely and this class will not need to be abstract |
| 23 | */ |
| 24 | abstract class CRM_Import_Form_Preview extends CRM_Import_Forms { |
| 25 | |
| 26 | /** |
| 27 | * Return a descriptive name for the page, used in wizard header. |
| 28 | * |
| 29 | * @return string |
| 30 | */ |
| 31 | public function getTitle() { |
| 32 | return ts('Preview'); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Assign common values to the template. |
| 37 | */ |
| 38 | public function preProcess() { |
| 39 | $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader')); |
| 40 | $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Build the form object. |
| 45 | */ |
| 46 | public function buildQuickForm() { |
| 47 | |
| 48 | // FIXME: This is a hack... |
| 49 | // The tpl contains javascript that starts the import on form submit |
| 50 | // Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked |
| 51 | // Hacking in some onclick js to make them act more like links instead of buttons |
| 52 | $path = CRM_Utils_System::currentPath(); |
| 53 | $query = ['_qf_MapField_display' => 'true']; |
| 54 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String'); |
| 55 | if (CRM_Utils_Rule::qfKey($qfKey)) { |
| 56 | $query['qfKey'] = $qfKey; |
| 57 | } |
| 58 | $previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE); |
| 59 | $cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE); |
| 60 | |
| 61 | $this->addButtons([ |
| 62 | [ |
| 63 | 'type' => 'back', |
| 64 | 'name' => ts('Previous'), |
| 65 | 'js' => ['onclick' => "location.href='{$previousURL}'; return false;"], |
| 66 | ], |
| 67 | [ |
| 68 | 'type' => 'next', |
| 69 | 'name' => ts('Import Now'), |
| 70 | 'spacing' => ' ', |
| 71 | 'isDefault' => TRUE, |
| 72 | ], |
| 73 | [ |
| 74 | 'type' => 'cancel', |
| 75 | 'name' => ts('Cancel'), |
| 76 | 'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"], |
| 77 | ], |
| 78 | ]); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Set status url for ajax. |
| 83 | */ |
| 84 | public function setStatusUrl() { |
| 85 | $statusID = $this->get('statusID'); |
| 86 | if (!$statusID) { |
| 87 | $statusID = md5(uniqid(rand(), TRUE)); |
| 88 | $this->set('statusID', $statusID); |
| 89 | } |
| 90 | $statusUrl = CRM_Utils_System::url('civicrm/ajax/status', "id={$statusID}", FALSE, NULL, FALSE); |
| 91 | $this->assign('statusUrl', $statusUrl); |
| 92 | } |
| 93 | |
| 94 | } |