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