Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / CRM / Contact / Form / Task / Print.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class provides the functionality to save a search
20 * Saved Searches are used for saving frequently used queries
21 */
22class CRM_Contact_Form_Task_Print extends CRM_Contact_Form_Task {
23
24 /**
fe482240 25 * Build all the data structures needed to build the form.
6a488035 26 */
00be9182 27 public function preProcess() {
6a488035
TO
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.
353ffa53 39 foreach ($this->_contactIds as $contactId) {
be2fb01f 40 $params[] = [
6a488035
TO
41 CRM_Core_Form::CB_PREFIX . $contactId,
42 '=',
353ffa53
TO
43 1,
44 0,
d5cc0fc2 45 0,
be2fb01f 46 ];
353ffa53 47 }
6a488035
TO
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();
d3e86119 67 require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
6a488035 68
2e1f50d6 69 $returnP = $returnProperties ?? "";
6a488035 70 $customSearchClass = $this->get('customSearchClass');
9f05e0a7 71 $this->assign('customSearchID', $this->get('customSearchID'));
353ffa53
TO
72 $selector = new $selectorName($customSearchClass,
73 $fv,
74 $params,
75 $returnP,
76 $this->_action,
77 $includeContactIds
78 );
6a488035
TO
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 /**
c490a46a 91 * Build the form object - it consists of
6a488035
TO
92 * - displaying the QILL (query in local language)
93 * - displaying elements for saving the search
6a488035 94 */
00be9182 95 public function buildQuickForm() {
6a488035
TO
96 //
97 // just need to add a javacript to popup the window for printing
98 //
be2fb01f 99 $this->addButtons([
69078420
SL
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 ]);
6a488035
TO
111 }
112
113 /**
fe482240 114 * Process the form after the input has been submitted and validated.
6a488035
TO
115 */
116 public function postProcess() {
117 // redirect to the main search page after printing is over
118 }
96025800 119
6a488035 120}