Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / CRM / Contact / Form / Task / Print.php
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 provides the functionality to save a search
20 * Saved Searches are used for saving frequently used queries
21 */
22 class CRM_Contact_Form_Task_Print extends CRM_Contact_Form_Task {
23
24 /**
25 * Build all the data structures needed to build the form.
26 */
27 public function preProcess() {
28 parent::preprocess();
29
30 // set print view, so that print templates are called
31 $this->controller->setPrint(1);
32 $this->assign('id', $this->get('id'));
33 $this->assign('pageTitle', ts('CiviCRM Contact Listing'));
34
35 $params = $this->get('queryParams');
36 if (!empty($this->_contactIds)) {
37 //using _contactIds field for creating params for query so that multiple selections on multiple pages
38 //can be printed.
39 foreach ($this->_contactIds as $contactId) {
40 $params[] = [
41 CRM_Core_Form::CB_PREFIX . $contactId,
42 '=',
43 1,
44 0,
45 0,
46 ];
47 }
48 }
49
50 // create the selector, controller and run - store results in session
51 $fv = $this->get('formValues');
52 $returnProperties = $this->get('returnProperties');
53
54 $sortID = NULL;
55 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
56 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
57 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
58 );
59 }
60
61 $includeContactIds = FALSE;
62 if ($fv['radio_ts'] == 'ts_sel') {
63 $includeContactIds = TRUE;
64 }
65
66 $selectorName = $this->controller->selectorName();
67 require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
68
69 $returnP = $returnProperties ?? "";
70 $customSearchClass = $this->get('customSearchClass');
71 $this->assign('customSearchID', $this->get('customSearchID'));
72 $selector = new $selectorName($customSearchClass,
73 $fv,
74 $params,
75 $returnP,
76 $this->_action,
77 $includeContactIds
78 );
79 $controller = new CRM_Core_Selector_Controller($selector,
80 NULL,
81 $sortID,
82 CRM_Core_Action::VIEW,
83 $this,
84 CRM_Core_Selector_Controller::SCREEN
85 );
86 $controller->setEmbedded(TRUE);
87 $controller->run();
88 }
89
90 /**
91 * Build the form object - it consists of
92 * - displaying the QILL (query in local language)
93 * - displaying elements for saving the search
94 */
95 public function buildQuickForm() {
96 //
97 // just need to add a javacript to popup the window for printing
98 //
99 $this->addButtons([
100 [
101 'type' => 'next',
102 'name' => ts('Print Contact List'),
103 'js' => ['onclick' => 'window.print()'],
104 'isDefault' => TRUE,
105 ],
106 [
107 'type' => 'back',
108 'name' => ts('Done'),
109 ],
110 ]);
111 }
112
113 /**
114 * Process the form after the input has been submitted and validated.
115 */
116 public function postProcess() {
117 // redirect to the main search page after printing is over
118 }
119
120 }