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