Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * This class acts as our base controller class and adds additional | |
30 | * functionality and smarts to the base QFC. Specifically we create | |
31 | * our own action classes and handle the transitions ourselves by | |
32 | * simulating a state machine. We also create direct jump links to any | |
33 | * page that can be used universally. | |
34 | * | |
35 | * This concept has been discussed on the PEAR list and the QFC FAQ | |
36 | * goes into a few details. Please check | |
37 | * http://pear.php.net/manual/en/package.html.html-quickform-controller.faq.php | |
38 | * for other useful tips and suggestions | |
39 | * | |
40 | * @package CRM | |
41 | * @copyright CiviCRM LLC (c) 2004-2013 | |
42 | * $Id$ | |
43 | * | |
44 | */ | |
45 | ||
46 | require_once 'HTML/QuickForm/Controller.php'; | |
47 | require_once 'HTML/QuickForm/Action/Direct.php'; | |
48 | ||
49 | class CRM_Core_Controller extends HTML_QuickForm_Controller { | |
50 | ||
51 | /** | |
52 | * the title associated with this controller | |
53 | * | |
54 | * @var string | |
55 | */ | |
56 | protected $_title; | |
57 | ||
58 | /** | |
59 | * The key associated with this controller | |
60 | * | |
61 | * @var string | |
62 | */ | |
63 | public $_key; | |
64 | ||
65 | /** | |
66 | * the name of the session scope where values are stored | |
67 | * | |
68 | * @var object | |
69 | */ | |
70 | protected $_scope; | |
71 | ||
72 | /** | |
73 | * the state machine associated with this controller | |
74 | * | |
75 | * @var object | |
76 | */ | |
77 | protected $_stateMachine; | |
78 | ||
79 | /** | |
80 | * Is this object being embedded in another object. If | |
81 | * so the display routine needs to not do any work. (The | |
82 | * parent object takes care of the display) | |
83 | * | |
84 | * @var boolean | |
85 | */ | |
86 | protected $_embedded = FALSE; | |
87 | ||
88 | /** | |
89 | * After entire form execution complete, | |
90 | * do we want to skip control redirection. | |
91 | * Default - It get redirect to user context. | |
92 | * | |
93 | * Useful when we run form in non civicrm context | |
94 | * and we need to transfer control back.(eg. drupal) | |
95 | * | |
96 | * @var boolean | |
97 | */ | |
98 | protected $_skipRedirection = FALSE; | |
99 | ||
100 | /** | |
101 | * Are we in print mode? if so we need to modify the display | |
102 | * functionality to do a minimal display :) | |
103 | * | |
104 | * @var boolean | |
105 | */ | |
106 | public $_print = 0; | |
107 | ||
108 | /** | |
109 | * Should we generate a qfKey, true by default | |
110 | * | |
111 | * @var boolean | |
112 | */ | |
113 | public $_generateQFKey = TRUE; | |
114 | ||
115 | /** | |
116 | * QF response type | |
117 | */ | |
118 | public $_QFResponseType = 'html'; | |
119 | ||
120 | /** | |
121 | * cache the smarty template for efficiency reasons | |
122 | * | |
123 | * @var CRM_Core_Smarty | |
124 | */ | |
125 | static protected $_template; | |
126 | ||
127 | /** | |
128 | * cache the session for efficiency reasons | |
129 | * | |
130 | * @var CRM_Core_Session | |
131 | */ | |
132 | static protected $_session; | |
133 | ||
134 | /** | |
135 | * The parent of this form if embedded | |
136 | * | |
137 | * @var object | |
138 | */ | |
139 | protected $_parent = NULL; | |
140 | ||
141 | /** | |
142 | * The destination if set will override the destination the code wants to send it to | |
143 | * | |
144 | * @var string; | |
145 | */ | |
146 | public $_destination = NULL; | |
147 | ||
3ab88a8c DL |
148 | /** |
149 | * The entry url for a top level form or wizard. Typically the URL with a reset=1 | |
150 | * used to redirect back to when we land into some session wierdness | |
151 | * | |
152 | * @var string | |
153 | */ | |
154 | public $_entryURL = NULL; | |
155 | ||
6a488035 TO |
156 | /** |
157 | * All CRM single or multi page pages should inherit from this class. | |
158 | * | |
159 | * @param string title descriptive title of the controller | |
160 | * @param boolean whether controller is modal | |
161 | * @param string scope name of session if we want unique scope, used only by Controller_Simple | |
162 | * @param boolean addSequence should we add a unique sequence number to the end of the key | |
163 | * @param boolean ignoreKey should we not set a qfKey for this controller (for standalone forms) | |
164 | * | |
165 | * @access public | |
166 | * | |
167 | * @return void | |
168 | * | |
169 | */ | |
170 | function __construct( | |
171 | $title = NULL, | |
172 | $modal = TRUE, | |
173 | $mode = NULL, | |
174 | $scope = NULL, | |
175 | $addSequence = FALSE, | |
176 | $ignoreKey = FALSE | |
177 | ) { | |
178 | // this has to true for multiple tab session fix | |
179 | $addSequence = TRUE; | |
180 | ||
181 | // let the constructor initialize this, should happen only once | |
182 | if (!isset(self::$_template)) { | |
183 | self::$_template = CRM_Core_Smarty::singleton(); | |
184 | self::$_session = CRM_Core_Session::singleton(); | |
185 | } | |
186 | ||
3ab88a8c DL |
187 | // lets try to get it from the session and/or the request vars |
188 | // we do this early on in case there is a fatal error in retrieving the | |
189 | // key and/or session | |
e69299b1 DL |
190 | $this->_entryURL = |
191 | CRM_Utils_Request::retrieve('entryURL', 'String', $this); | |
3ab88a8c | 192 | |
6a488035 | 193 | // add a unique validable key to the name |
e69299b1 | 194 | $name = CRM_Utils_System::getClassName($this); |
6a488035 TO |
195 | if ($name == 'CRM_Core_Controller_Simple' && !empty($scope)) { |
196 | // use form name if we have, since its a lot better and | |
197 | // definitely different for different forms | |
198 | $name = $scope; | |
199 | } | |
200 | $name = $name . '_' . $this->key($name, $addSequence, $ignoreKey); | |
201 | $this->_title = $title; | |
202 | if ($scope) { | |
203 | $this->_scope = $scope; | |
204 | } | |
205 | else { | |
206 | $this->_scope = CRM_Utils_System::getClassName($this); | |
207 | } | |
208 | $this->_scope = $this->_scope . '_' . $this->_key; | |
209 | ||
210 | // only use the civicrm cache if we have a valid key | |
211 | // else we clash with other users CRM-7059 | |
212 | if (!empty($this->_key)) { | |
213 | CRM_Core_Session::registerAndRetrieveSessionObjects(array( | |
214 | "_{$name}_container", | |
215 | array('CiviCRM', $this->_scope), | |
216 | )); | |
217 | } | |
218 | ||
219 | $this->HTML_QuickForm_Controller($name, $modal); | |
220 | ||
221 | $snippet = CRM_Utils_Array::value('snippet', $_REQUEST); | |
222 | if ($snippet) { | |
223 | if ($snippet == 3) { | |
224 | $this->_print = CRM_Core_Smarty::PRINT_PDF; | |
225 | } | |
226 | elseif ($snippet == 4) { | |
227 | // this is used to embed fragments of a form | |
228 | $this->_print = CRM_Core_Smarty::PRINT_NOFORM; | |
229 | self::$_template->assign('suppressForm', TRUE); | |
230 | $this->_generateQFKey = FALSE; | |
231 | } | |
232 | elseif ($snippet == 5) { | |
233 | // this is used for popups and inlined ajax forms | |
234 | // also used for the various tabs via TabHeader | |
235 | $this->_print = CRM_Core_Smarty::PRINT_NOFORM; | |
236 | } | |
fc05b8da CW |
237 | // Respond with JSON if in AJAX context (also support legacy value '6') |
238 | elseif (in_array($snippet, array(CRM_Core_Smarty::PRINT_JSON, 6))) { | |
239 | $this->_print = CRM_Core_Smarty::PRINT_JSON; | |
6a488035 TO |
240 | $this->_QFResponseType = 'json'; |
241 | } | |
242 | else { | |
243 | $this->_print = CRM_Core_Smarty::PRINT_SNIPPET; | |
244 | } | |
245 | } | |
246 | ||
3ab88a8c | 247 | // if the request has a reset value, initialize the controller session |
a7488080 | 248 | if (!empty($_GET['reset'])) { |
6a488035 | 249 | $this->reset(); |
3ab88a8c DL |
250 | |
251 | // in this case we'll also cache the url as a hidden form variable, this allows us to | |
252 | // redirect in case the session has disappeared on us | |
253 | $this->_entryURL = CRM_Utils_System::makeURL(NULL, TRUE, FALSE, NULL, TRUE); | |
254 | $this->set('entryURL', $this->_entryURL); | |
6a488035 TO |
255 | } |
256 | ||
257 | // set the key in the session | |
258 | // do this at the end so we have initialized the object | |
259 | // and created the scope etc | |
260 | $this->set('qfKey', $this->_key); | |
261 | ||
262 | ||
263 | // also retrieve and store destination in session | |
3ab88a8c DL |
264 | $this->_destination = CRM_Utils_Request::retrieve( |
265 | 'civicrmDestination', | |
266 | 'String', | |
267 | $this, | |
268 | FALSE, | |
269 | NULL, | |
270 | $_REQUEST | |
6a488035 TO |
271 | ); |
272 | } | |
273 | ||
274 | function fini() { | |
275 | CRM_Core_BAO_Cache::storeSessionToCache(array( | |
276 | "_{$this->_name}_container", | |
277 | array('CiviCRM', $this->_scope), | |
278 | ), | |
279 | TRUE | |
280 | ); | |
281 | } | |
282 | ||
283 | function key($name, $addSequence = FALSE, $ignoreKey = FALSE) { | |
284 | $config = CRM_Core_Config::singleton(); | |
285 | ||
286 | if ( | |
287 | $ignoreKey || | |
288 | (isset($config->keyDisable) && $config->keyDisable) | |
289 | ) { | |
290 | return NULL; | |
291 | } | |
292 | ||
293 | $key = CRM_Utils_Array::value('qfKey', $_REQUEST, NULL); | |
294 | if (!$key && $_SERVER['REQUEST_METHOD'] === 'GET') { | |
295 | $key = CRM_Core_Key::get($name, $addSequence); | |
296 | } | |
297 | else { | |
298 | $key = CRM_Core_Key::validate($key, $name, $addSequence); | |
299 | } | |
300 | ||
301 | if (!$key) { | |
c02edd0e | 302 | $this->invalidKey(); |
6a488035 TO |
303 | } |
304 | ||
305 | $this->_key = $key; | |
306 | ||
307 | return $key; | |
308 | } | |
309 | ||
310 | /** | |
311 | * Process the request, overrides the default QFC run method | |
312 | * This routine actually checks if the QFC is modal and if it | |
313 | * is the first invalid page, if so it call the requested action | |
314 | * if not, it calls the display action on the first invalid page | |
315 | * avoids the issue of users hitting the back button and getting | |
316 | * a broken page | |
317 | * | |
318 | * This run is basically a composition of the original run and the | |
319 | * jump action | |
320 | * | |
321 | */ | |
322 | function run() { | |
323 | // the names of the action and page should be saved | |
324 | // note that this is split into two, because some versions of | |
325 | // php 5.x core dump on the triple assignment :) | |
326 | $this->_actionName = $this->getActionName(); | |
327 | list($pageName, $action) = $this->_actionName; | |
328 | ||
329 | if ($this->isModal()) { | |
330 | if (!$this->isValid($pageName)) { | |
331 | $pageName = $this->findInvalid(); | |
332 | $action = 'display'; | |
333 | } | |
334 | } | |
335 | ||
336 | // note that based on action, control might not come back!! | |
337 | // e.g. if action is a valid JUMP, u basically do a redirect | |
338 | // to the appropriate place | |
339 | $this->wizardHeader($pageName); | |
340 | return $this->_pages[$pageName]->handle($action); | |
341 | } | |
342 | ||
343 | function validate() { | |
344 | $this->_actionName = $this->getActionName(); | |
345 | list($pageName, $action) = $this->_actionName; | |
346 | ||
347 | $page = &$this->_pages[$pageName]; | |
348 | ||
349 | $data = &$this->container(); | |
350 | $this->applyDefaults($pageName); | |
351 | $page->isFormBuilt() or $page->buildForm(); | |
352 | // We use defaults and constants as if they were submitted | |
353 | $data['values'][$pageName] = $page->exportValues(); | |
354 | $page->loadValues($data['values'][$pageName]); | |
355 | // Is the page now valid? | |
356 | if (TRUE === ($data['valid'][$pageName] = $page->validate())) { | |
357 | return TRUE; | |
358 | } | |
359 | return $page->_errors; | |
360 | } | |
361 | ||
362 | /** | |
363 | * Helper function to add all the needed default actions. Note that the framework | |
364 | * redefines all of the default QFC actions | |
365 | * | |
366 | * @param string directory to store all the uploaded files | |
367 | * @param array names for the various upload buttons (note u can have more than 1 upload) | |
368 | * | |
369 | * @access private | |
370 | * | |
371 | * @return void | |
372 | * | |
373 | */ | |
374 | function addActions($uploadDirectory = NULL, $uploadNames = NULL) { | |
375 | $names = array( | |
376 | 'display' => 'CRM_Core_QuickForm_Action_Display', | |
377 | 'next' => 'CRM_Core_QuickForm_Action_Next', | |
378 | 'back' => 'CRM_Core_QuickForm_Action_Back', | |
379 | 'process' => 'CRM_Core_QuickForm_Action_Process', | |
380 | 'cancel' => 'CRM_Core_QuickForm_Action_Cancel', | |
381 | 'refresh' => 'CRM_Core_QuickForm_Action_Refresh', | |
382 | 'reload' => 'CRM_Core_QuickForm_Action_Reload', | |
383 | 'done' => 'CRM_Core_QuickForm_Action_Done', | |
384 | 'jump' => 'CRM_Core_QuickForm_Action_Jump', | |
385 | 'submit' => 'CRM_Core_QuickForm_Action_Submit', | |
386 | ); | |
387 | ||
388 | foreach ($names as $name => $classPath) { | |
389 | $action = new $classPath($this->_stateMachine); | |
390 | $this->addAction($name, $action); | |
391 | } | |
392 | ||
393 | $this->addUploadAction($uploadDirectory, $uploadNames); | |
394 | } | |
395 | ||
396 | /** | |
397 | * getter method for stateMachine | |
398 | * | |
399 | * @return object | |
400 | * @access public | |
401 | */ | |
402 | function getStateMachine() { | |
403 | return $this->_stateMachine; | |
404 | } | |
405 | ||
406 | /** | |
407 | * setter method for stateMachine | |
408 | * | |
409 | * @param object a stateMachineObject | |
410 | * | |
411 | * @return void | |
412 | * @access public | |
413 | */ | |
414 | function setStateMachine($stateMachine) { | |
415 | $this->_stateMachine = $stateMachine; | |
416 | } | |
417 | ||
418 | /** | |
419 | * add pages to the controller. Note that the controller does not really care | |
420 | * the order in which the pages are added | |
421 | * | |
422 | * @param object $stateMachine the state machine object | |
423 | * @param int $action the mode in which the state machine is operating | |
424 | * typicaly this will be add/view/edit | |
425 | * | |
426 | * @return void | |
427 | * @access public | |
428 | * | |
429 | */ | |
430 | function addPages(&$stateMachine, $action = CRM_Core_Action::NONE) { | |
431 | $pages = $stateMachine->getPages(); | |
432 | foreach ($pages as $name => $value) { | |
433 | $className = CRM_Utils_Array::value('className', $value, $name); | |
434 | $title = CRM_Utils_Array::value('title', $value); | |
435 | $options = CRM_Utils_Array::value('options', $value); | |
436 | $stateName = CRM_Utils_String::getClassName($className); | |
a7488080 | 437 | if (!empty($value['className'])) { |
6a488035 TO |
438 | $formName = $name; |
439 | } | |
440 | else { | |
441 | $formName = CRM_Utils_String::getClassName($name); | |
442 | } | |
443 | ||
444 | $ext = CRM_Extension_System::singleton()->getMapper(); | |
445 | if ($ext->isExtensionClass($className)) { | |
446 | require_once ($ext->classToPath($className)); | |
447 | } | |
448 | else { | |
449 | require_once (str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'); | |
450 | } | |
451 | $$stateName = new $className($stateMachine->find($className), $action, 'post', $formName); | |
452 | if ($title) { | |
453 | $$stateName->setTitle($title); | |
454 | } | |
455 | if ($options) { | |
456 | $$stateName->setOptions($options); | |
457 | } | |
8f44f704 | 458 | if (property_exists($$stateName, 'urlPath') && isset($_GET[CRM_Core_Config::singleton()->userFrameworkURLVar])) { |
118e964e CW |
459 | $$stateName->urlPath = explode('/', $_GET[CRM_Core_Config::singleton()->userFrameworkURLVar]); |
460 | } | |
6a488035 TO |
461 | $this->addPage($$stateName); |
462 | $this->addAction($stateName, new HTML_QuickForm_Action_Direct()); | |
463 | ||
464 | //CRM-6342 -we need kill the reference here, | |
465 | //as we have deprecated reference object creation. | |
466 | unset($$stateName); | |
467 | } | |
468 | } | |
469 | ||
470 | /** | |
471 | * QFC does not provide native support to have different 'submit' buttons. | |
472 | * We introduce this notion to QFC by using button specific data. Thus if | |
473 | * we have two submit buttons, we could have one displayed as a button and | |
474 | * the other as an image, both are of type 'submit'. | |
475 | * | |
476 | * @return string the name of the button that has been pressed by the user | |
477 | * @access public | |
478 | */ | |
479 | function getButtonName() { | |
480 | $data = &$this->container(); | |
481 | return CRM_Utils_Array::value('_qf_button_name', $data); | |
482 | } | |
483 | ||
484 | /** | |
485 | * function to destroy all the session state of the controller. | |
486 | * | |
487 | * @access public | |
488 | * | |
489 | * @return void | |
490 | */ | |
491 | function reset() { | |
492 | $this->container(TRUE); | |
493 | self::$_session->resetScope($this->_scope); | |
494 | } | |
495 | ||
496 | /** | |
497 | * virtual function to do any processing of data. | |
498 | * Sometimes it is useful for the controller to actually process data. | |
499 | * This is typically used when we need the controller to figure out | |
500 | * what pages are potentially involved in this wizard. (this is dynamic | |
501 | * and can change based on the arguments | |
502 | * | |
503 | * @return void | |
504 | * @access public | |
505 | */ | |
506 | function process() {} | |
507 | ||
508 | /** | |
509 | * Store the variable with the value in the form scope | |
510 | * | |
511 | * @param string|array $name name of the variable or an assoc array of name/value pairs | |
512 | * @param mixed $value value of the variable if string | |
513 | * | |
514 | * @access public | |
515 | * | |
516 | * @return void | |
517 | * | |
518 | */ | |
519 | function set($name, $value = NULL) { | |
520 | self::$_session->set($name, $value, $this->_scope); | |
521 | } | |
522 | ||
523 | /** | |
524 | * Get the variable from the form scope | |
525 | * | |
526 | * @param string name : name of the variable | |
527 | * | |
528 | * @access public | |
529 | ||
530 | * | |
531 | * @return mixed | |
532 | * | |
533 | */ | |
534 | function get($name) { | |
535 | return self::$_session->get($name, $this->_scope); | |
536 | } | |
537 | ||
538 | /** | |
539 | * Create the header for the wizard from the list of pages | |
540 | * Store the created header in smarty | |
541 | * | |
542 | * @param string $currentPageName name of the page being displayed | |
543 | * | |
544 | * @return array | |
545 | * @access public | |
546 | */ | |
547 | function wizardHeader($currentPageName) { | |
548 | $wizard = array(); | |
549 | $wizard['steps'] = array(); | |
550 | $count = 0; | |
551 | foreach ($this->_pages as $name => $page) { | |
552 | $count++; | |
553 | $wizard['steps'][] = array( | |
554 | 'name' => $name, | |
555 | 'title' => $page->getTitle(), | |
556 | //'link' => $page->getLink ( ), | |
557 | 'link' => NULL, | |
558 | 'step' => TRUE, | |
559 | 'valid' => TRUE, | |
560 | 'stepNumber' => $count, | |
561 | 'collapsed' => FALSE, | |
562 | ); | |
563 | ||
564 | if ($name == $currentPageName) { | |
565 | $wizard['currentStepNumber'] = $count; | |
566 | $wizard['currentStepName'] = $name; | |
567 | $wizard['currentStepTitle'] = $page->getTitle(); | |
568 | } | |
569 | } | |
570 | ||
571 | $wizard['stepCount'] = $count; | |
572 | ||
573 | $this->addWizardStyle($wizard); | |
574 | ||
575 | $this->assign('wizard', $wizard); | |
576 | return $wizard; | |
577 | } | |
578 | ||
579 | function addWizardStyle(&$wizard) { | |
580 | $wizard['style'] = array( | |
581 | 'barClass' => '', | |
582 | 'stepPrefixCurrent' => '»', | |
583 | 'stepPrefixPast' => '√', | |
584 | 'stepPrefixFuture' => ' ', | |
585 | 'subStepPrefixCurrent' => ' ', | |
586 | 'subStepPrefixPast' => ' ', | |
587 | 'subStepPrefixFuture' => ' ', | |
588 | 'showTitle' => 1, | |
589 | ); | |
590 | } | |
591 | ||
592 | /** | |
593 | * assign value to name in template | |
594 | * | |
595 | * @param array|string $name name of variable | |
596 | * @param mixed $value value of varaible | |
597 | * | |
598 | * @return void | |
599 | * @access public | |
600 | */ | |
601 | function assign($var, $value = NULL) { | |
602 | self::$_template->assign($var, $value); | |
603 | } | |
604 | ||
4a9538ac CW |
605 | /** |
606 | * assign value to name in template by reference | |
607 | * | |
608 | * @param array|string $name name of variable | |
609 | * @param mixed $value (reference) value of varaible | |
610 | * | |
611 | * @return void | |
612 | * @access public | |
613 | */ | |
6a488035 TO |
614 | function assign_by_ref($var, &$value) { |
615 | self::$_template->assign_by_ref($var, $value); | |
616 | } | |
617 | ||
4a9538ac CW |
618 | /** |
619 | * appends values to template variables | |
620 | * | |
621 | * @param array|string $tpl_var the template variable name(s) | |
622 | * @param mixed $value the value to append | |
623 | * @param bool $merge | |
624 | */ | |
625 | function append($tpl_var, $value=NULL, $merge=FALSE) { | |
626 | self::$_template->append($tpl_var, $value, $merge); | |
627 | } | |
628 | ||
629 | /** | |
630 | * Returns an array containing template variables | |
631 | * | |
632 | * @param string $name | |
633 | * @param string $type | |
634 | * @return array | |
635 | */ | |
636 | function get_template_vars($name=null) { | |
637 | return self::$_template->get_template_vars($name); | |
638 | } | |
639 | ||
6a488035 TO |
640 | /** |
641 | * setter for embedded | |
642 | * | |
643 | * @param boolean $embedded | |
644 | * | |
645 | * @return void | |
646 | * @access public | |
647 | */ | |
648 | function setEmbedded($embedded) { | |
649 | $this->_embedded = $embedded; | |
650 | } | |
651 | ||
652 | /** | |
653 | * getter for embedded | |
654 | * | |
655 | * @return boolean return the embedded value | |
656 | * @access public | |
657 | */ | |
658 | function getEmbedded() { | |
659 | return $this->_embedded; | |
660 | } | |
661 | ||
662 | /** | |
663 | * setter for skipRedirection | |
664 | * | |
665 | * @param boolean $skipRedirection | |
666 | * | |
667 | * @return void | |
668 | * @access public | |
669 | */ | |
670 | function setSkipRedirection($skipRedirection) { | |
671 | $this->_skipRedirection = $skipRedirection; | |
672 | } | |
673 | ||
674 | /** | |
675 | * getter for skipRedirection | |
676 | * | |
677 | * @return boolean return the skipRedirection value | |
678 | * @access public | |
679 | */ | |
680 | function getSkipRedirection() { | |
681 | return $this->_skipRedirection; | |
682 | } | |
683 | ||
684 | function setWord($fileName = NULL) { | |
685 | //Mark as a CSV file. | |
686 | header('Content-Type: application/vnd.ms-word'); | |
687 | ||
688 | //Force a download and name the file using the current timestamp. | |
689 | if (!$fileName) { | |
690 | $fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.doc'; | |
691 | } | |
692 | header("Content-Disposition: attachment; filename=Contacts_$fileName"); | |
693 | } | |
694 | ||
695 | function setExcel($fileName = NULL) { | |
696 | //Mark as an excel file. | |
697 | header('Content-Type: application/vnd.ms-excel'); | |
698 | ||
699 | //Force a download and name the file using the current timestamp. | |
700 | if (!$fileName) { | |
701 | $fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.xls'; | |
702 | } | |
703 | ||
704 | header("Content-Disposition: attachment; filename=Contacts_$fileName"); | |
705 | } | |
706 | ||
707 | /** | |
708 | * setter for print | |
709 | * | |
710 | * @param boolean $print | |
711 | * | |
712 | * @return void | |
713 | * @access public | |
714 | */ | |
715 | function setPrint($print) { | |
716 | if ($print == "xls") { | |
717 | $this->setExcel(); | |
718 | } | |
719 | elseif ($print == "doc") { | |
720 | $this->setWord(); | |
721 | } | |
722 | $this->_print = $print; | |
723 | } | |
724 | ||
725 | /** | |
726 | * getter for print | |
727 | * | |
728 | * @return boolean return the print value | |
729 | * @access public | |
730 | */ | |
731 | function getPrint() { | |
732 | return $this->_print; | |
733 | } | |
734 | ||
735 | function getTemplateFile() { | |
736 | if ($this->_print) { | |
737 | if ($this->_print == CRM_Core_Smarty::PRINT_PAGE) { | |
738 | return 'CRM/common/print.tpl'; | |
739 | } | |
740 | elseif ($this->_print == 'xls' || $this->_print == 'doc') { | |
741 | return 'CRM/Contact/Form/Task/Excel.tpl'; | |
742 | } | |
743 | else { | |
744 | return 'CRM/common/snippet.tpl'; | |
745 | } | |
746 | } | |
747 | else { | |
748 | $config = CRM_Core_Config::singleton(); | |
749 | return 'CRM/common/' . strtolower($config->userFramework) . '.tpl'; | |
750 | } | |
751 | } | |
752 | ||
753 | public function addUploadAction($uploadDir, $uploadNames) { | |
754 | if (empty($uploadDir)) { | |
755 | $config = CRM_Core_Config::singleton(); | |
756 | $uploadDir = $config->uploadDir; | |
757 | } | |
758 | ||
759 | if (empty($uploadNames)) { | |
760 | $uploadNames = $this->get('uploadNames'); | |
761 | if (!empty($uploadNames)) { | |
762 | $uploadNames = array_merge($uploadNames, | |
763 | CRM_Core_BAO_File::uploadNames() | |
764 | ); | |
765 | } | |
766 | else { | |
767 | $uploadNames = CRM_Core_BAO_File::uploadNames(); | |
768 | } | |
769 | } | |
770 | ||
771 | $action = new CRM_Core_QuickForm_Action_Upload($this->_stateMachine, | |
772 | $uploadDir, | |
773 | $uploadNames | |
774 | ); | |
775 | $this->addAction('upload', $action); | |
776 | } | |
777 | ||
778 | public function setParent($parent) { | |
779 | $this->_parent = $parent; | |
780 | } | |
781 | ||
782 | public function getParent() { | |
783 | return $this->_parent; | |
784 | } | |
785 | ||
786 | public function getDestination() { | |
787 | return $this->_destination; | |
788 | } | |
789 | ||
790 | public function setDestination($url = NULL, $setToReferer = FALSE) { | |
791 | if (empty($url)) { | |
792 | if ($setToReferer) { | |
793 | $url = $_SERVER['HTTP_REFERER']; | |
794 | } | |
795 | else { | |
796 | $config = CRM_Core_Config::singleton(); | |
797 | $url = $config->userFrameworkBaseURL; | |
798 | } | |
799 | } | |
800 | ||
801 | $this->_destination = $url; | |
802 | $this->set('civicrmDestination', $this->_destination); | |
803 | } | |
804 | ||
805 | public function cancelAction() { | |
806 | $actionName = $this->getActionName(); | |
807 | list($pageName, $action) = $actionName; | |
808 | return $this->_pages[$pageName]->cancelAction(); | |
809 | } | |
6a488035 | 810 | |
c02edd0e DL |
811 | /** |
812 | * Write a simple fatal error message. Other controllers can decide to do something else | |
813 | * and present the user a better message and/or redirect to the same page with a reset url | |
814 | * | |
815 | * @return void | |
816 | * | |
817 | */ | |
818 | public function invalidKey() { | |
3ab88a8c DL |
819 | self::invalidKeyCommon(); |
820 | } | |
821 | ||
822 | public function invalidKeyCommon() { | |
c02edd0e DL |
823 | $msg = ts('We can\'t load the requested web page. This page requires cookies to be enabled in your browser settings. Please check this setting and enable cookies (if they are not enabled). Then try again. If this error persists, contact the site adminstrator for assistance.') . '<br /><br />' . ts('Site Administrators: This error may indicate that users are accessing this page using a domain or URL other than the configured Base URL. EXAMPLE: Base URL is http://example.org, but some users are accessing the page via http://www.example.org or a domain alias like http://myotherexample.org.') . '<br /><br />' . ts('Error type: Could not find a valid session key.'); |
824 | CRM_Core_Error::fatal($msg); | |
825 | } | |
826 | ||
3ab88a8c DL |
827 | /** |
828 | * Instead of outputting a fatal error message, we'll just redirect to the entryURL if present | |
829 | * | |
830 | * @return void | |
831 | */ | |
832 | public function invalidKeyRedirect() { | |
833 | if ($this->_entryURL) { | |
7ecaf943 | 834 | CRM_Core_Session::setStatus(ts('Your browser session has expired and we are unable to complete your form submission. We have returned you to the initial step so you can complete and resubmit the form. If you experience continued difficulties, please contact us for assistance.')); |
3ab88a8c DL |
835 | return CRM_Utils_System::redirect($this->_entryURL); |
836 | } | |
837 | else { | |
838 | self::invalidKeyCommon(); | |
839 | } | |
840 | } | |
841 | ||
c02edd0e | 842 | } |