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