Merge remote-tracking branch 'rajgo94/mailingui-new' into master-abtest
[civicrm-core.git] / CRM / Event / Form / ManageEvent / TabHeader.php
index 32beceabb6a6c562a7492320a736bbe8758f8e78..66fdd03fdc97b08d3e4389745fccdacb7d7acaaf 100644 (file)
  */
 class CRM_Event_Form_ManageEvent_TabHeader {
 
+  /**
+   * @param $form
+   *
+   * @return array
+   */
   static function build(&$form) {
     $tabs = $form->get('tabHeader');
     if (!$tabs || empty($_GET['reset'])) {
@@ -50,9 +55,16 @@ class CRM_Event_Form_ManageEvent_TabHeader {
       ->addSetting(array('tabSettings' => array(
         'active' => self::getCurrentTab($tabs),
       )));
+    CRM_Event_Form_ManageEvent::addProfileEditScripts();
     return $tabs;
   }
 
+  /**
+   * @param $form
+   *
+   * @return array
+   * @throws Exception
+   */
   static function process(&$form) {
     if ($form->getVar('_id') <= 0) {
       return NULL;
@@ -66,16 +78,19 @@ class CRM_Event_Form_ManageEvent_TabHeader {
       'class' => 'ajaxForm',
     );
 
-    $tabs = array(
-      'settings' => array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default,
-      'location' => array('title' => ts('Event Location')) + $default,
-      'fee' => array('title' => ts('Fees')) + $default,
-      'registration' => array('title' => ts('Online Registration')) + $default,
-      'reminder' => array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default,
-      'conference' => array('title' => ts('Conference Slots')) + $default,
-      'friend' => array('title' => ts('Tell a Friend')) + $default,
-      'pcp' => array('title' => ts('Personal Campaigns')) + $default,
-    );
+    $tabs = array();
+    $tabs['settings'] = array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default;
+    $tabs['location'] = array('title' => ts('Event Location')) + $default;
+    $tabs['fee'] = array('title' => ts('Fees')) + $default;
+    $tabs['registration'] = array('title' => ts('Online Registration')) + $default;
+    if (CRM_Core_Permission::check('administer CiviCRM')) {
+      $tabs['reminder'] = array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default;
+    }
+    $tabs['conference'] = array('title' => ts('Conference Slots')) + $default;
+    $tabs['friend'] = array('title' => ts('Tell a Friend')) + $default;
+    $tabs['pcp'] = array('title' => ts('Personal Campaigns')) + $default;
+    $tabs['repeat'] = array('title' => ts('Repeat')) + $default;
+
 
     // check if we're in shopping cart mode for events
     $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
@@ -87,16 +102,19 @@ class CRM_Event_Form_ManageEvent_TabHeader {
 
     $eventID = $form->getVar('_id');
     if ($eventID) {
-      // disable tabs based on their configuration status 
+      // disable tabs based on their configuration status
       $sql = "
-SELECT     e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder
+SELECT     e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder, re.id as is_repeating_event
 FROM       civicrm_event e
 LEFT JOIN  civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
 LEFT JOIN  civicrm_pcp_block pcp   ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
 LEFT JOIN  civicrm_action_mapping  map ON ( map.entity_value = 'civicrm_event' )
 LEFT JOIN  civicrm_action_schedule sch ON ( sch.mapping_id = map.id AND sch.entity_value = %1 )
+LEFT JOIN  civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
 WHERE      e.id = %1
 ";
+      //Check if repeat is configured
+      $eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event');
       $params = array(1 => array($eventID, 'Integer'));
       $dao = CRM_Core_DAO::executeQuery($sql, $params);
       if (!$dao->fetch()) {
@@ -120,6 +138,9 @@ WHERE      e.id = %1
       if (!$dao->is_reminder) {
         $tabs['reminder']['valid'] = FALSE;
       }
+      if (!$dao->is_repeating_event) {
+        $tabs['repeat']['valid'] = FALSE;
+      }
     }
 
     // see if any other modules want to add any tabs
@@ -176,11 +197,19 @@ WHERE      e.id = %1
     return $tabs;
   }
 
+  /**
+   * @param $form
+   */
   static function reset(&$form) {
     $tabs = self::process($form);
     $form->set('tabHeader', $tabs);
   }
 
+  /**
+   * @param $tabs
+   *
+   * @return int|string
+   */
   static function getCurrentTab($tabs) {
     static $current = FALSE;