Update Copywrite year to be 2019
[civicrm-core.git] / CRM / Event / Form / SelfSvcUpdate.php
index 72a1374cb25b9430cc74a6f339038ae3ea11c61e..4ef7afc0f568afb980c22b04b1bc0608c9dd30c8 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  * $Id$
  *
  */
@@ -107,6 +107,12 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
    * @var array
    */
   protected $_details = array();
+  /**
+   * Is backoffice form?
+   *
+   * @array bool
+   */
+  protected $isBackoffice = FALSE;
   /**
    * Set variables up before form is built based on participant ID from URL
    *
@@ -119,6 +125,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
     $participant = $values = array();
     $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
+    $this->isBackoffice = CRM_Utils_Request::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST');
     $params = array('id' => $this->_participant_id);
     $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
     $this->_part_values = $values[$this->_participant_id];
@@ -159,7 +166,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
     while ($dao->fetch()) {
       $details['status']  = $dao->status;
       $details['role'] = $dao->role;
-      $details['fee_level']   = $dao->fee_level;
+      $details['fee_level'] = trim($dao->fee_level, CRM_Core_DAO::VALUE_SEPARATOR);
       $details['fee_amount'] = $dao->fee_amount;
       $details['register_date'] = $dao->register_date;
       $details['event_start_date'] = $dao->start_date;
@@ -178,11 +185,11 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
     }
     $start_time = new Datetime($start_date);
     $timenow = new Datetime();
-    if (!empty($start_time) && $start_time < $timenow) {
+    if (!$this->isBackoffice && !empty($start_time) && $start_time < $timenow) {
       $status = ts("Registration for this event cannot be cancelled or transferred once the event has begun. Contact the event organizer if you have questions.");
       CRM_Core_Error::statusBounce($status, $url, ts('Sorry'));
     }
-    if (!empty($time_limit) && $time_limit > 0) {
+    if (!$this->isBackoffice && !empty($time_limit) && $time_limit > 0) {
       $interval = $timenow->diff($start_time);
       $days = $interval->format('%d');
       $hours   = $interval->format('%h');
@@ -274,11 +281,16 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
    * return @void
    */
   public function transferParticipant($params) {
-    $transferUrl = 'civicrm/event/form/selfsvctransfer';
-    $url = CRM_Utils_System::url('civicrm/event/selfsvctransfer', 'reset=1&action=add&pid=' . $this->_participant_id . '&cs=' . $this->_userChecksum);
-    $this->controller->setDestination($url);
-    $session = CRM_Core_Session::singleton();
-    $session->replaceUserContext($url);
+    $isBackOfficeArg = $this->isBackoffice ? '&is_backoffice=1' : '';
+    CRM_Utils_System::redirect(CRM_Utils_System::url(
+      'civicrm/event/selfsvctransfer',
+      array(
+        'reset' => 1,
+        'action' => 'add',
+        'pid' => $this->_participant_id,
+        'cs' => $this->_userChecksum,
+      )
+    ));
   }
 
   /**
@@ -358,6 +370,9 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
     $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
     $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
     CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success');
+    if (!empty($this->isBackoffice)) {
+      return;
+    }
     $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
     CRM_Utils_System::redirect($url);
   }