From 62933949bfefbe68f1f9bc227b06676207619aa7 Mon Sep 17 00:00:00 2001 From: priyankakaran26 Date: Wed, 3 Sep 2014 22:13:51 +0100 Subject: [PATCH] event recurring patch for v4.6 --- CRM/Core/BAO/ActionSchedule.php | 11 +- CRM/Core/BAO/RecurringEntity.php | 353 ++++++++++++++ CRM/Core/DAO.php | 36 ++ CRM/Core/DAO/RecurringEntity.php | 248 ++++++++++ CRM/Core/Form/RecurringEntity.php | 432 ++++++++++++++++++ CRM/Core/Page/AJAX/RecurringEntity.php | 81 ++++ CRM/Event/BAO/Query.php | 42 +- CRM/Event/Form/ManageEvent.php | 21 +- CRM/Event/Form/ManageEvent/Repeat.php | 199 ++++++++ CRM/Event/Form/ManageEvent/TabHeader.php | 6 + CRM/Event/Page/ManageEvent.php | 14 + CRM/Event/xml/Menu/Event.xml | 18 + templates/CRM/Event/Form/ConfirmSubmit.tpl | 103 +++++ .../CRM/Event/Form/ManageEvent/EventInfo.tpl | 3 +- templates/CRM/Event/Form/ManageEvent/Fee.tpl | 1 + .../CRM/Event/Form/ManageEvent/Location.tpl | 5 +- .../Event/Form/ManageEvent/Registration.tpl | 1 + .../CRM/Event/Form/ManageEvent/Repeat.hlp | 81 ++++ .../CRM/Event/Form/ManageEvent/Repeat.tpl | 91 ++++ .../Form/ManageEvent/ScheduleReminders.tpl | 1 + templates/CRM/Friend/Form/Friend.tpl | 1 + templates/CRM/PCP/Form/PCP.tpl | 1 + xml/schema/Core/ActionSchedule.xml | 7 + xml/schema/Core/RecurringEntity.xml | 40 ++ xml/schema/Core/files.xml | 1 + 25 files changed, 1782 insertions(+), 15 deletions(-) create mode 100644 CRM/Core/BAO/RecurringEntity.php create mode 100644 CRM/Core/DAO/RecurringEntity.php create mode 100644 CRM/Core/Form/RecurringEntity.php create mode 100644 CRM/Core/Page/AJAX/RecurringEntity.php create mode 100644 CRM/Event/Form/ManageEvent/Repeat.php create mode 100644 templates/CRM/Event/Form/ConfirmSubmit.tpl create mode 100644 templates/CRM/Event/Form/ManageEvent/Repeat.hlp create mode 100644 templates/CRM/Event/Form/ManageEvent/Repeat.tpl create mode 100644 xml/schema/Core/RecurringEntity.xml diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index b2f93dfede..c5f6eeafc5 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -367,20 +367,19 @@ FROM civicrm_action_schedule cas LEFT JOIN civicrm_action_mapping cam ON (cam.id = cas.mapping_id) "; $params = CRM_Core_DAO::$_nullArray; - + $where = " WHERE 1 "; if ($entityValue and $id) { - $where = " -WHERE cas.entity_value = $id AND + $where .= " +AND cas.entity_value = $id AND cam.entity_value = '$entityValue'"; - $query .= $where; - $params = array( 1 => array($id, 'Integer'), 2 => array($entityValue, 'String'), ); } - + $where .= " AND cas.used_for IS NULL"; + $query .= $where; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $list[$dao->id]['id'] = $dao->id; diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php new file mode 100644 index 0000000000..144cfd54d1 --- /dev/null +++ b/CRM/Core/BAO/RecurringEntity.php @@ -0,0 +1,353 @@ + 'CRM_Event_DAO_Event', + 'civicrm_price_set_entity' => 'CRM_Price_DAO_PriceSetEntity', + 'civicrm_uf_join' => 'CRM_Core_DAO_UFJoin', + 'civicrm_tell_friend' => 'CRM_Friend_DAO_Friend', + 'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock', + ); + + static function add(&$params) { + if (CRM_Utils_Array::value('id', $params)) { + CRM_Utils_Hook::pre('edit', 'RecurringEntity', $params['id'], $params); + } + else { + CRM_Utils_Hook::pre('create', 'RecurringEntity', NULL, $params); + } + + $daoRecurringEntity = new CRM_Core_DAO_RecurringEntity(); + $daoRecurringEntity->copyValues($params); + $result = $daoRecurringEntity->save(); + + if (CRM_Utils_Array::value('id', $params)) { + CRM_Utils_Hook::post('edit', 'RecurringEntity', $daoRecurringEntity->id, $daoRecurringEntity); + } + else { + CRM_Utils_Hook::post('create', 'RecurringEntity', $daoRecurringEntity->id, $daoRecurringEntity); + } + return $result; + } + + static function quickAdd($parentId, $entityId, $entityTable) { + $params = + array( + 'parent_id' => $parentId, + 'entity_id' => $entityId, + 'entity_table' => $entityTable + ); + return self::add($params); + } + + static public function getEntitiesForParent($parentId, $entityTable, $includeParent = TRUE) { + $entities = array(); + + $query = "SELECT * + FROM civicrm_recurring_entity + WHERE parent_id = %1 AND entity_table = %2"; + if (!$includeParent) { + $query .= " AND entity_id != %1"; + } + $dao = CRM_Core_DAO::executeQuery($query, + array( + 1 => array($parentId, 'Integer'), + 2 => array($entityTable, 'String'), + ) + ); + + while ($dao->fetch()) { + $entities["{$dao->entity_table}_{$dao->entity_id}"]['table'] = $dao->entity_table; + $entities["{$dao->entity_table}_{$dao->entity_id}"]['id'] = $dao->entity_id; + } + return $entities; + } + + static public function getEntitiesFor($entityId, $entityTable, $includeParent = TRUE) { + $parentId = self::getParentFor($entityId, $entityTable); + if ($parentId) { + return self::getEntitiesForParent($parentId, $entityTable, $includeParent); + } + return array(); + } + + static public function getParentFor($entityId, $entityTable, $includeParent = TRUE) { + $query = " + SELECT parent_id + FROM civicrm_recurring_entity + WHERE entity_id = %1 AND entity_table = %2"; + if (!$includeParent) { + $query .= " AND parent_id != %1"; + } + $parentId = + CRM_Core_DAO::singleValueQuery($query, + array( + 1 => array($entityId, 'Integer'), + 2 => array($entityTable, 'String'), + ) + ); + return $parentId; + } + + //static public function copyCreateEntity('civicrm_event', array('id' => $params['parent_event_id'], $newParams) { + static public function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) { + $daoName = self::$_tableDAOMapper[$entityTable]; + $newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams); + + if ($newObject->id && $createRecurringEntity) { + $object = new $daoName( ); + foreach ($fromCriteria as $key => $value) { + $object->$key = $value; + } + $object->find(TRUE); + + CRM_Core_BAO_RecurringEntity::quickAdd($object->id, $newObject->id, $entityTable); + } + return $newObject; + } + + static public function triggerUpdate($obj) { + static $processedEntities = array(); + if (empty($obj->id) || empty($obj->__table)) { + return FALSE; + } + $key = "{$obj->__table}_{$obj->id}"; + + if (array_key_exists($key, $processedEntities)) { + // already processed + return NULL; + } + + // get related entities + $repeatingEntities = self::getEntitiesFor($obj->id, $obj->__table, FALSE); + if (empty($repeatingEntities)) { + // return if its not a recurring entity parent + return NULL; + } + // mark processed + $processedEntities[$key] = 1; + + foreach ($repeatingEntities as $key => $val) { + $entityID = $val['id']; + $entityTable = $val['table']; + + $processedEntities[$key] = 1; + + if (array_key_exists($entityTable, self::$_tableDAOMapper)) { + $daoName = self::$_tableDAOMapper[$entityTable]; + + $fromId = self::getParentFor($entityID, $entityTable); + + // FIXME: generalize me + $skipData = array('start_date' => NULL, + 'end_date' => NULL, + ); + + $updateDAO = CRM_Core_DAO::cascadeUpdate($daoName, $fromId, $entityID, $skipData); + } + } + // done with processing. lets unset static var. + unset($processedEntities); + } + + static function mapFormValuesToDB($formParams = array()){ + $dbParams = array(); + if(CRM_Utils_Array::value('used_for', $formParams)){ + $dbParams['used_for'] = $formParams['used_for']; + } + + if(CRM_Utils_Array::value('parent_event_id', $formParams)){ + $dbParams['entity_value'] = $formParams['parent_event_id']; + } + + if(CRM_Utils_Array::value('repetition_frequency_unit', $formParams)){ + $dbParams['repetition_frequency_unit'] = $formParams['repetition_frequency_unit']; + } + + if(CRM_Utils_Array::value('repetition_frequency_interval', $formParams)){ + $dbParams['repetition_frequency_interval'] = $formParams['repetition_frequency_interval']; + } + + //For Repeats on:(weekly case) + if($formParams['repetition_frequency_unit'] == 'week'){ + if(CRM_Utils_Array::value('start_action_condition', $formParams)){ + $repeats_on = CRM_Utils_Array::value('start_action_condition', $formParams); + $dbParams['start_action_condition'] = implode(",", array_keys($repeats_on)); + } + } + + //For Repeats By:(monthly case) + if($formParams['repetition_frequency_unit'] == 'month'){ + if($formParams['repeats_by'] == 1){ + if(CRM_Utils_Array::value('limit_to', $formParams)){ + $dbParams['limit_to'] = $formParams['limit_to']; + } + } + if($formParams['repeats_by'] == 2){ + if(CRM_Utils_Array::value('start_action_date_1', $formParams) && CRM_Utils_Array::value('start_action_date_2', $formParams)){ + $dbParams['start_action_date'] = $formParams['start_action_date_1']." ".$formParams['start_action_date_2']; + } + } + } + + //For "Ends" - After: + if($formParams['ends'] == 1){ + if(CRM_Utils_Array::value('start_action_offset', $formParams)){ + $dbParams['start_action_offset'] = $formParams['start_action_offset']; + } + } + + //For "Ends" - On: + if($formParams['ends'] == 2){ + if(CRM_Utils_Array::value('repeat_absolute_date', $formParams)){ + $dbParams['absolute_date'] = CRM_Utils_Date::processDate($formParams['repeat_absolute_date']); + } + } + return $dbParams; + } + + static public function getScheduleReminderDetailsById($scheduleReminderId){ + $query = "SELECT * + FROM civicrm_action_schedule WHERE 1"; + if($scheduleReminderId){ + $query .= " + AND id = %1"; + } + $dao = CRM_Core_DAO::executeQuery($query, + array( + 1 => array($scheduleReminderId, 'Integer') + ) + ); + $dao->fetch(); + return $dao; + } + + static function getRecursionFromReminder($scheduleReminderId){ + if($scheduleReminderId){ + //Get all the details from schedule reminder table + $scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId); + $scheduleReminderDetails = (array) $scheduleReminderDetails; + $recursionDetails = self::getRecursionFromReminderByDBParams($scheduleReminderDetails); + } + return $recursionDetails; + } + + static function getRecursionFromReminderByDBParams($scheduleReminderDetails = array()){ + $r = new When(); + //If there is some data for this id + if($scheduleReminderDetails['repetition_frequency_unit']){ + $currDate = date("Y-m-d H:i:s"); + $start = new DateTime($currDate); + if($scheduleReminderDetails['repetition_frequency_unit']){ + $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit']; + if($repetition_frequency_unit == "day"){ + $repetition_frequency_unit = "dai"; + } + $repetition_frequency_unit = $repetition_frequency_unit.'ly'; + $r->recur($start, $repetition_frequency_unit); + } + + if($scheduleReminderDetails['repetition_frequency_interval']){ + $r->interval($scheduleReminderDetails['repetition_frequency_interval']); + } + + //week + if($scheduleReminderDetails['repetition_frequency_unit'] == 'week'){ + if($scheduleReminderDetails['start_action_condition']){ + $startActionCondition = $scheduleReminderDetails['start_action_condition']; + $explodeStartActionCondition = explode(',', $startActionCondition); + $buildRuleArray = array(); + foreach($explodeStartActionCondition as $key => $val){ + $buildRuleArray[] = strtoupper(substr($val, 0, 2)); + } +// CRM_Core_Error::debug('$buildRuleArray', $buildRuleArray);exit; + $r->wkst('MO')->byday($buildRuleArray); + } + } + + //month + if($scheduleReminderDetails['repetition_frequency_unit'] == 'month'){ + if($scheduleReminderDetails['limit_to']){ + $r->bymonthday(array($scheduleReminderDetails['limit_to'])); + } + if($scheduleReminderDetails['start_action_date']){ + $startActionDate = explode(" ", $scheduleReminderDetails['start_action_date']); + switch ($startActionDate[0]) { + case 'first': + $startActionDate1 = 1; + break; + case 'second': + $startActionDate1 = 2; + break; + case 'third': + $startActionDate1 = 3; + break; + case 'fourth': + $startActionDate1 = 4; + break; + case 'last': + $startActionDate1 = -1; + break; + } + $concatStartActionDateBits = $startActionDate1.strtoupper(substr($startActionDate[1], 0, 2)); + $r->byday(array($concatStartActionDateBits)); + } + } + + //Ends + if($scheduleReminderDetails['start_action_offset']){ + $r->count($scheduleReminderDetails['start_action_offset']); + } + + if($scheduleReminderDetails['absolute_date']){ + $absoluteDate = CRM_Utils_Date::setDateDefaults($scheduleReminderDetails['absolute_date']); + $endDate = new DateTime($absoluteDate[0].' '.$absoluteDate[1]); + $r->until($endDate); + } + + if(!$scheduleReminderDetails['start_action_offset'] && !$scheduleReminderDetails['absolute_date']){ + CRM_Core_Error::fatal("Could not find end limit for repeat configuration"); + } + } + return $r; + } + + + } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 0399e88fb1..445576fa5f 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -450,6 +450,7 @@ class CRM_Core_DAO extends DB_DataObject { function save() { if (!empty($this->id)) { $this->update(); + CRM_Core_BAO_RecurringEntity::triggerUpdate($this); } else { $this->insert(); @@ -1348,6 +1349,41 @@ FROM civicrm_domain return $newObject; } + static function cascadeUpdate($daoName, $fromId, $toId, $newData = array()) { + $object = new $daoName( ); + $object->id = $fromId; + + if ($object->find(TRUE)) { + $newObject = new $daoName( ); + $newObject->id = $toId; + + if ($newObject->find(TRUE)) { + $fields = &$object->fields(); + foreach ($fields as $name => $value) { + if ($name == 'id' || $value['name'] == 'id') { + // copy everything but the id! + continue; + } + + $colName = $value['name']; + $newObject->$colName = $object->$colName; + + if (substr($name, -5) == '_date' || + substr($name, -10) == '_date_time' + ) { + $newObject->$colName = CRM_Utils_Date::isoToMysql($newObject->$colName); + } + } + foreach ($newData as $k => $v) { + $newObject->$k = $v; + } + $newObject->save(); + return $newObject; + } + } + return CRM_Core_DAO::$_nullObject; + } + /** * Given the component id, compute the contact id * since its used for things like send email diff --git a/CRM/Core/DAO/RecurringEntity.php b/CRM/Core/DAO/RecurringEntity.php new file mode 100644 index 0000000000..a371ef2b31 --- /dev/null +++ b/CRM/Core/DAO/RecurringEntity.php @@ -0,0 +1,248 @@ +__table = 'civicrm_recurring_entity'; + parent::__construct(); + } + /** + * returns all the column names of this table + * + * @access public + * @return array + */ + static function &fields() + { + if (!(self::$_fields)) { + self::$_fields = array( + 'id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('ID') , + 'required' => true, + ) , + 'parent_id' => array( + 'name' => 'parent_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Parent ID') , + 'required' => true, + ) , + 'entity_id' => array( + 'name' => 'entity_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Entity ID') , + ) , + 'entity_table' => array( + 'name' => 'entity_table', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Entity Table') , + 'required' => true, + 'size' => CRM_Utils_Type::TWO, + ) , + ); + } + return self::$_fields; + } + /** + * Returns an array containing, for each field, the arary key used for that + * field in self::$_fields. + * + * @access public + * @return array + */ + static function &fieldKeys() + { + if (!(self::$_fieldKeys)) { + self::$_fieldKeys = array( + 'id' => 'id', + 'parent_id' => 'parent_id', + 'entity_id' => 'entity_id', + 'entity_table' => 'entity_table', + ); + } + return self::$_fieldKeys; + } + /** + * returns the names of this table + * + * @access public + * @static + * @return string + */ + static function getTableName() + { + return self::$_tableName; + } + /** + * returns if this table needs to be logged + * + * @access public + * @return boolean + */ + function getLog() + { + return self::$_log; + } + /** + * returns the list of fields that can be imported + * + * @access public + * return array + * @static + */ + static function &import($prefix = false) + { + if (!(self::$_import)) { + self::$_import = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('import', $field)) { + if ($prefix) { + self::$_import['recurring_entity'] = & $fields[$name]; + } else { + self::$_import[$name] = & $fields[$name]; + } + } + } + } + return self::$_import; + } + /** + * returns the list of fields that can be exported + * + * @access public + * return array + * @static + */ + static function &export($prefix = false) + { + if (!(self::$_export)) { + self::$_export = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('export', $field)) { + if ($prefix) { + self::$_export['recurring_entity'] = & $fields[$name]; + } else { + self::$_export[$name] = & $fields[$name]; + } + } + } + } + return self::$_export; + } +} diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php new file mode 100644 index 0000000000..db7462322a --- /dev/null +++ b/CRM/Core/Form/RecurringEntity.php @@ -0,0 +1,432 @@ +assign('currentEntityId', self::$_entityId); + + $form->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units'); + foreach ($form->_freqUnits as $val => $label) { + if($label == "day"){ + $label = "dai"; + } + $freqUnitsDisplay[$val] = ts('%1ly', array(1 => $label)); + } + // echo "
";print_r($freqUnitsDisplay);
+    $dayOfTheWeek = array('monday'   => 'Monday',
+                          'tuesday'   => 'Tuesday',
+                          'wednesday' => 'Wednesday',
+                          'thursday'  => 'Thursday',
+                          'friday'    => 'Friday',
+                          'saturday'  => 'Saturday',
+                          'sunday'    => 'Sunday'
+                         );
+    $form->add('select', 'repetition_frequency_unit', ts('Repeats:'), $freqUnitsDisplay, TRUE);
+    $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
+    $form->add('select', 'repetition_frequency_interval', ts('Repeats every:'), $numericOptions, TRUE, array('style' => 'width:49px;'));
+    foreach($dayOfTheWeek as $key => $val){
+        $startActionCondition[] = $form->createElement('checkbox', $key, NULL, substr($val." ", 0, 3));
+    }
+    $form->addGroup($startActionCondition, 'start_action_condition', ts('Repeats on'));
+    $roptionTypes = array('1' => ts('day of the month'),
+        '2' => ts('day of the week'),
+      );
+    $form->addRadio('repeats_by', ts("Repeats By:"), $roptionTypes, array(), NULL);
+    $getMonths = CRM_Core_SelectValues::getNumericOptions(1, 31);
+    $form->add('select', 'limit_to', '', $getMonths, FALSE, array('style' => 'width:49px;'));
+    $dayOfTheWeekNo = array('first'  => 'First',
+                            'second'=> 'Second',
+                            'third' => 'Third',
+                            'fourth'=> 'Fourth',
+                            'last'  => 'Last'
+                         );
+    $form->add('select', 'start_action_date_1', ts(''), $dayOfTheWeekNo);
+    $form->add('select', 'start_action_date_2', ts(''), $dayOfTheWeek);
+    $eoptionTypes = array('1' => ts('After'),
+        '2' => ts('On'),
+      );
+    $form->addRadio('ends', ts("Ends:"), $eoptionTypes, array(), NULL, TRUE);
+    $form->add('text', 'start_action_offset', ts(''), array('maxlength' => 2));
+    $form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
+    $form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
+    $form->addDate('exclude_date', ts('Exclude Date(s)'), FALSE);
+    $select = $form->add('select', 'exclude_date_list', ts(''), $form->_excludeDateInfo, FALSE, array('style' => 'width:200px;', 'size' => 4));
+    $select->setMultiple(TRUE);
+    $form->addElement('button','add_to_exclude_list','>>','onClick="addToExcludeList(document.getElementById(\'exclude_date\').value);"'); 
+    $form->addElement('button','remove_from_exclude_list', '<<', 'onClick="removeFromExcludeList(\'exclude_date_list\')"'); 
+    $form->addElement('hidden', 'isChangeInRepeatConfiguration', '', array('id' => 'isChangeInRepeatConfiguration'));
+    $form->addElement('hidden', 'copyExcludeDates', '', array('id' => 'copyExcludeDates'));
+    $form->addButtons(array(
+        array(
+          'type' => 'submit',
+          'name' => ts('Save'),
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => 'cancel',
+          'name' => ts('Cancel')
+        ),
+      )
+    );
+  }
+
+  /**
+   * global validation rules for the form
+   *
+   * @param array $fields posted values of the form
+   *
+   * @return array list of errors to be posted back to the form
+   * @static
+   * @access public
+   */
+  static function formRule($values) {
+    $errors = array();
+    $dayOfTheWeek = array(monday,tuesday,wednesday,thursday,friday,saturday,sunday);
+//    CRM_Core_Error::debug('$values', $values);
+    
+    //Repeats
+    if(!CRM_Utils_Array::value('repetition_frequency_unit', $values)){
+      $errors['repetition_frequency_unit'] = ts('This is a required field');
+    }
+    //Repeats every
+    if(!CRM_Utils_Array::value('repetition_frequency_interval', $values)){
+      $errors['repetition_frequency_interval'] = ts('This is a required field');
+    }
+    //Ends
+    if(CRM_Utils_Array::value('ends', $values)){
+      if($values['ends'] == 1){
+        if ($values['start_action_offset'] == "") {
+          $errors['start_action_offset'] = ts('This is a required field');
+        }else if($values['start_action_offset'] > 30){
+          $errors['start_action_offset'] = ts('Occurrences should be less than or equal to 30');
+        }
+      }
+      if($values['ends'] == 2){
+        if ($values['repeat_absolute_date'] != "") {
+          $today = date("Y-m-d H:i:s"); 
+          $today = CRM_Utils_Date::processDate($today);
+          $end = CRM_Utils_Date::processDate($values['repeat_absolute_date']);
+          if (($end <= $today) && ($end != 0)) {
+            $errors['repeat_absolute_date'] = ts('End date should be after today\'s date');
+          }
+        }else{
+          $errors['repeat_absolute_date'] = ts('This is a required field');
+        }
+      }
+    }else{
+      $errors['ends'] = ts('This is a required field');
+    }
+    
+    //Repeats BY
+    if(CRM_Utils_Array::value('repeats_by', $values)){
+      if($values['repeats_by'] == 1){
+        if($values['limit_to'] != ""){
+          if($values['limit_to'] < 1 && $values['limit_to'] > 31){
+            $errors['limit_to'] = ts('Invalid day of the month');
+          }
+        }else{
+          $errors['limit_to'] = ts('Invalid day of the month');
+        }
+      }
+      if($values['repeats_by'] == 2){
+        if($values['start_action_date_1'] != "" ) {
+          $dayOfTheWeekNo = array(first, second, third, fourth, last);
+          if(!in_array($values['start_action_date_1'], $dayOfTheWeekNo)){
+             $errors['start_action_date_1'] = ts('Invalid option');
+          }
+        }else{
+          $errors['start_action_date_1'] = ts('Invalid option');
+        }
+        if($values['start_action_date_2'] != "" ) {
+          if(!in_array($values['start_action_date_2'], $dayOfTheWeek)){
+             $errors['start_action_date_2'] = ts('Invalid day name');
+          }
+        }else{
+          $errors['start_action_date_2'] = ts('Invalid day name');
+        }
+      }
+    }
+    return $errors;
+  }
+
+  /**
+   * Function to process the form
+   *
+   * @access public
+   *
+   * @return None
+   */
+  static function postProcess($params=array(), $type) {
+    if(!empty($type)){
+      $params['used_for'] = $type;
+    }
+    
+    if(CRM_Utils_Array::value('id', $params)){
+      CRM_Core_BAO_ActionSchedule::del($params['id']);
+      unset($params['id']);
+    }
+    //Save post params to the schedule reminder table
+    $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params);
+    $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
+    
+    //Build Recursion Object
+    if($actionScheduleObj->id){
+      $recursionObject = CRM_Core_BAO_RecurringEntity::getRecursionFromReminder($actionScheduleObj->id);
+    }
+    
+    
+    //TO DO - Exclude date functionality
+    if(CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_event_id', $params)){   
+      //Since we get comma separated values lets get them in array
+      $exclude_date_list = array();
+      $exclude_date_list = explode(",", $params['copyExcludeDates']);
+
+      //Check if there exists any values for this option group
+      $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
+          'event_repeat_exclude_dates_'.$params['parent_event_id'],
+          'id',
+          'name'
+        );
+      if($optionGroupIdExists){
+        CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
+      }
+      $optionGroupParams = 
+          array(
+            'name'        => 'event_repeat_exclude_dates_'.$params['parent_event_id'],
+            'title'       => 'Event Recursion',
+            'is_reserved' => 0,
+            'is_active'   => 1
+          );
+      $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
+      if($opGroup->id){
+        $oldWeight= 0;
+        $fieldValues = array('option_group_id' => $opGroup->id);
+        foreach($exclude_date_list as $val){
+          $optionGroupValue = 
+              array(
+                'option_group_id' =>  $opGroup->id,
+                'label'           =>  CRM_Utils_Date::processDate($val),
+                'value'           =>  CRM_Utils_Date::processDate($val),
+                'name'            =>  $opGroup->name,
+                'description'     =>  'Used for event recursion',
+                'weight'          =>  CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues),
+                'is_active'       =>  1
+              );
+          CRM_Core_BAO_OptionValue::add($optionGroupValue);
+        }
+      }
+    }
+    
+    //Give call to create recursions
+    $recurResult = self::generateRecursions($recursionObject, $params);
+    if(!empty($recurResult)){
+      self::addEntityThroughRecursion($recurResult, $params['parent_event_id']);
+    }
+    $status = ts('Repeat Configuration Saved');
+    CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
+  }
+  //end of function
+
+  /**
+   * Return a descriptive name for the page, used in wizard header
+   *
+   * @return string
+   * @access public
+   */
+  public function getTitle() {
+    return ts('Repeat Event');
+  }
+
+  static public function generateRecursions($recursionObj, $params=array()){ 
+    $newParams = $recursionResult = array();
+    if($recursionObj && !empty($params)){ 
+      //Proceed only if these keys are found in array
+      if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){
+        $count = 1;
+        while($result = $recursionObj->next()){
+          //$result->format('YmdHis'). '
'; + $newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s')); + $parentStartDate = new DateTime($params['parent_event_start_date']); + //If open ended event + if(CRM_Utils_Array::value('parent_event_end_date', $params)){ + $parentEndDate = new DateTime($params['parent_event_end_date']); + $interval = $parentStartDate->diff($parentEndDate); + $end_date = new DateTime($newParams['start_date']); + $end_date->add($interval); + $newParams['end_date'] = CRM_Utils_Date::processDate($end_date->format('Y-m-d H:i:s')); + $recursionResult[$count]['end_date'] = $newParams['end_date']; + } + $recursionResult[$count]['start_date'] = $newParams['start_date']; + $count++; + } + } + } + return $recursionResult; + } + + static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){ + if(!empty($recursionResult) && $currEntityID){ + $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event'); + if(!$parent_event_id){ + $parent_event_id = $currEntityID; + } + + foreach ($recursionResult as $key => $value) { + $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', + array('id' => $parent_event_id), + $value); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ), + FALSE + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ), + FALSE + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ) + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ) + ); + } + CRM_Core_BAO_RecurringEntity::quickAdd($parent_event_id, $parent_event_id, 'civicrm_event'); + } + } + + /* + * Get Reminder id based on event id + */ + static public function getReminderDetailsByEventId($eventId=''){ + if(!empty($eventId)){ + $query = " + SELECT * + FROM civicrm_action_schedule + WHERE entity_value = '".$eventId."'"; + $dao = CRM_Core_DAO::executeQuery($query); + $dao->fetch(); + } + return $dao; + } + + //It is a repeating event if, there exists a parent for an event + static public function checkParentExistsForThisId($currentEventId){ + if(!empty($currentEventId)){ + $query = " + SELECT parent_id + FROM civicrm_recurring_entity + WHERE entity_id = ".$currentEventId; + $dao = CRM_Core_DAO::executeQuery($query); + $dao->fetch(); + } + return $dao; + } + + static public function getAllConnectedEvents($parentId=''){ + if(!empty($parentId)){ + $query = " + SELECT GROUP_CONCAT(entity_id) as entity_id + FROM civicrm_recurring_entity + WHERE parent_id = ".$parentId; + $dao = CRM_Core_DAO::executeQuery($query); + $dao->fetch(); + } + return $dao; + } + + static function getListOfCurrentAndFutureEvents($ids=''){ + if(isset($ids) and !empty($ids)){ + $curDate = date('YmdHis'); + $query = "SELECT group_concat(id) as ids FROM civicrm_event + WHERE id IN ({$ids}) + AND ( end_date >= {$curDate} OR + ( + ( end_date IS NULL OR end_date = '' ) AND start_date >= {$curDate} + ))"; + $dao = CRM_Core_DAO::executeQuery($query); + $dao->fetch(); + } + return $dao; + } + + static function deleleRelationsForEventsInPast($ids=''){ + if(isset($ids) and !empty($ids)){ + $query = "DELETE FROM civicrm_recurring_entity + WHERE entity_id IN ({$ids})"; + $dao = CRM_Core_DAO::executeQuery($query); + } + return; + } + +} diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php new file mode 100644 index 0000000000..4ab193c020 --- /dev/null +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -0,0 +1,81 @@ + array($cascadeType, 'Integer'), + 2 => array($entityId, 'Integer') + ); + CRM_Core_DAO::executeQuery($sql, $params); + $finalResult['status'] = 'Done'; + } + echo json_encode($finalResult); + CRM_Utils_System::civiExit(); + } + + public static function generatePreview(){ + $params = $formValues = $recurDates = array(); + $formValues = $_REQUEST; + if(!empty($formValues)){ + //Check for mandatory fields +// if(!CRM_Utils_Array::value('repetition_frequency_unit', $formValues)){ +// $recurDates['errors']['repetition_frequency_unit'] = 'Repeats is a required field'; +// } +// if(!CRM_Utils_Array::value('repetition_frequency_interval', $formValues)){ +// $recurDates['errors']['repetition_frequency_interval'] = 'Repeats every is a required field'; +// } +// if(!CRM_Utils_Array::value('start_action_offset', $formValues) && !CRM_Utils_Array::value('repeat_absolute_date', $formValues)){ +// $recurDates['errors']['start_action_offset'] = 'Ends is a required field'; +// } + + $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($formValues); + if(!empty($dbParams)){ + $recursionObject = CRM_Core_BAO_RecurringEntity::getRecursionFromReminderByDBParams($dbParams); + if(CRM_Utils_Array::value('event_id', $formValues)){ + $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['event_id'], 'civicrm_event'); + if(!$parent_event_id){ + $parent_event_id = $formValues['event_id']; + } + $params['parent_event_id'] = $parent_event_id; + $params['parent_event_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'start_date'); + $params['parent_event_end_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'end_date'); + } + $recurResult = CRM_Core_Form_RecurringEntity::generateRecursions($recursionObject, $params); + $count = 1; + foreach ($recurResult as $key => $value) { + $recurDates[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date'])); + if($value['end_date']){ + $recurDates[$count]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date'])); + } + $count++; + } + } + } + echo json_encode($recurDates); + CRM_Utils_System::civiExit(); + } + +} + diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 771631b717..5210b98513 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -206,6 +206,7 @@ class CRM_Event_BAO_Query { } } } + /** * @param $query @@ -248,14 +249,46 @@ class CRM_Event_BAO_Query { 'civicrm_event', 'event_end_date', 'end_date', 'End Date' ); return; - + case 'event_id': $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, 'title'); $query->_qill[$grouping][] = ts('Event') . " $op {$eventTitle}"; $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; return; - + + case 'event_include_repeating_events': + /** + * Include Repeating Events + */ + //Get parent of this event + $exEventId = ''; + if($query->_where[$grouping]){ + foreach($query->_where[$grouping] as $key => $val){ + if (strstr($val, 'civicrm_event.id =')) { + $exEventId = $val; + $extractEventId = explode(" ", $val); + $value = $extractEventId[2]; + unset($query->_where[$grouping][$key]); + } + } + $extractEventId = explode(" ", $exEventId); + $value = $extractEventId[2]; + unset($query->_where[$grouping][$key]); + } + $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event'); + if($thisEventHasParent){ + $getAllConnections = CRM_Core_Form_RecurringEntity::getAllConnectedEvents($thisEventHasParent); + if($getAllConnections->entity_id){ + $op = "IN"; + $value = "($getAllConnections->entity_id)"; + } + } + $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; + $query->_qill[$grouping][] = ts('Include Repeating Events (If Any) ') . " = TRUE"; + $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; + return; + case 'event_type_id': $eventTypes = CRM_Core_OptionGroup::values("event_type"); @@ -263,7 +296,7 @@ class CRM_Event_BAO_Query { $query->_qill[$grouping][] = ts('Event Type - %1', array(1 => $eventTypes[$value])); $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; return; - + case 'participant_test': // We dont want to include all tests for sql OR CRM-7827 if (!$value || $query->getOperator() != 'OR') { @@ -602,6 +635,7 @@ class CRM_Event_BAO_Query { $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select')); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); + $eventIncludeRepeatingEvents = &$form->addElement('checkbox', "event_include_repeating_events", NULL, ts(' Include Repeating Events (If Any) ? ')); $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); foreach ($status as $id => $Name) { @@ -638,7 +672,7 @@ class CRM_Event_BAO_Query { } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); - + $form->assign('validCiviEvent', TRUE); $form->setDefaults(array('participant_test' => 0)); } diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 62b688c2e9..d15b18a6af 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -84,6 +84,11 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { * the participant records */ protected $_campaignID = NULL; + + /** + * Check if repeating event + */ + protected $_isRepeatingEvent; /** * Function to set variables up before form is built @@ -96,13 +101,14 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { if (in_array('CiviEvent', $config->enableComponents)) { $this->assign('CiviEvent', TRUE); } - + $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); $this->assign('action', $this->_action); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); if ($this->_id) { + $this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); $this->assign('eventId', $this->_id); if (!empty($this->_addBlockName) && empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) { $this->add('hidden', 'id', $this->_id); @@ -148,8 +154,13 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title"); } else { + $configureText = ts('Configure Event'); $title = CRM_Utils_Array::value('title', $eventInfo); - CRM_Utils_System::setTitle(ts('Configure Event') . " - $title"); + //If it is a repeating event change title + if($this->_isRepeatingEvent){ + $configureText = 'Configure Repeating Event'; + } + CRM_Utils_System::setTitle($configureText . " - $title"); } $this->assign('title', $title); } @@ -176,6 +187,12 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { } $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this); + + //Is a repeating event + if($this->_isRepeatingEvent){ + $isRepeat = 'repeat'; + $this->assign('isRepeat', $isRepeat); + } // also set up tabs CRM_Event_Form_ManageEvent_TabHeader::build($this); diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php new file mode 100644 index 0000000000..680bb13347 --- /dev/null +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -0,0 +1,199 @@ +assign('currentEventId', $this->_id); + + $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); + $checkParentExistsForThisId; + //If this ID has parent, send parent id + if($checkParentExistsForThisId){ + $this->_scheduleReminderDetails = CRM_Core_Form_RecurringEntity::getReminderDetailsByEventId($checkParentExistsForThisId); + $this->_parentEventId = $checkParentExistsForThisId; + + /** + * Get connected event information list + */ + //Get all connected event ids + $allEventIds = CRM_Core_Form_RecurringEntity::getAllConnectedEvents($checkParentExistsForThisId); + if($allEventIds->entity_id){ + //echo "
"; print_r($eventIds);
+        //list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
+        $params = array();
+        $query = "
+          SELECT *
+          FROM civicrm_event
+          WHERE id IN (".$allEventIds->entity_id.")
+          ORDER BY start_date asc
+           ";
+
+        $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
+        //$permissions = CRM_Event_BAO_Event::checkPermission();
+        while($dao->fetch()){
+//          if(in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])){
+          if($dao->id){
+            $manageEvent[$dao->id] = array();
+            CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]);
+          }
+        }
+        $this->assign('rows', $manageEvent);
+      }
+    }else{
+      //ELse send this id as parent
+      $this->_scheduleReminderDetails = CRM_Core_Form_RecurringEntity::getReminderDetailsByEventId($this->_id);
+      $this->_parentEventId = $this->_id;
+    }
+    //Assign this to hide summary
+    $this->assign('scheduleReminderId', $this->_scheduleReminderDetails->id);
+    
+    $parentEventParams = array('id' => $this->_id);
+    $parentEventValues = array();
+    $parentEventReturnProperties = array('start_date', 'end_date');
+    $parentEventAttributes = CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties);
+    $this->_parentEventStartDate = $parentEventAttributes->start_date;
+    $this->_parentEventEndDate = $parentEventAttributes->end_date;
+    
+    //Get option exclude date information
+    //$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'event_repeat_exclude_dates_'.$this->_parentEventId, 'id', 'name');
+    CRM_Core_OptionValue::getValues(array('name' => 'event_repeat_exclude_dates_'.$this->_parentEventId), $optionValue);
+    $excludeOptionValues = array();
+    if(!empty($optionValue)){
+      foreach($optionValue as $key => $val){
+        $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
+      }
+      $this->_excludeDateInfo = $excludeOptionValues;
+    } 
+  }
+  
+  /**
+   * This function sets the default values for the form. For edit/view mode
+   * the default values are retrieved from the database
+   *
+   * @access public
+   *
+   * @return None
+   */
+  function setDefaultValues() {
+    $defaults = array();
+    
+    //Set Schedule Reminder Id
+      $this->_scheduleReminderId = $this->_scheduleReminderDetails->id;
+
+    // Check if there is id for this event in Reminder table
+    if($this->_scheduleReminderId){
+      $defaults['repetition_frequency_unit'] = $this->_scheduleReminderDetails->repetition_frequency_unit;
+      $defaults['repetition_frequency_interval'] = $this->_scheduleReminderDetails->repetition_frequency_interval;
+      $defaults['start_action_condition'] = array_flip(explode(",",$this->_scheduleReminderDetails->start_action_condition));
+      foreach($defaults['start_action_condition'] as $key => $val){
+        $val = 1;
+        $defaults['start_action_condition'][$key] = $val;
+      }
+      list($defaults['repeat_event_start_date'], $defaults['repeat_event_start_date_time']) = CRM_Utils_Date::setDateDefaults($this->_parentEventStartDate, 'activityDateTime');
+      $defaults['start_action_offset'] = $this->_scheduleReminderDetails->start_action_offset;
+      if($this->_scheduleReminderDetails->start_action_offset){
+        $defaults['ends'] = 1;
+      }
+      list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults($this->_scheduleReminderDetails->absolute_date);
+      if($this->_scheduleReminderDetails->absolute_date){
+        $defaults['ends'] = 2;
+      }
+      $defaults['limit_to'] = $this->_scheduleReminderDetails->limit_to;
+      if($this->_scheduleReminderDetails->limit_to){
+        $defaults['repeats_by'] = 1;
+      }
+      $explodeStartActionCondition = array();
+      $explodeStartActionCondition = explode(" ", $this->_scheduleReminderDetails->start_action_date);
+      $defaults['start_action_date_1'] = $explodeStartActionCondition[0];
+      $defaults['start_action_date_2'] = $explodeStartActionCondition[1];
+      if($this->_scheduleReminderDetails->start_action_date){
+        $defaults['repeats_by'] = 2;
+      }
+      //echo "
"; print_r($this->_excludeDateInfo);
+      $defaults['exclude_date_list'] = array('a', 'b');
+         /* array
+        (
+            0 => '08/25/2014',
+            1 => '08/28/2014'
+        );*/
+    } 
+    return $defaults;
+  }
+  
+  public function buildQuickForm() {
+    CRM_Core_Form_RecurringEntity::buildQuickForm($this);
+  }
+   
+  public function postProcess() {
+    if($this->_id){
+      $params = $this->controller->exportValues($this->_name); 
+      $params['parent_event_id'] = $this->_parentEventId;
+      $params['parent_event_start_date'] = $this->_parentEventStartDate;
+      $params['parent_event_end_date'] = $this->_parentEventEndDate;
+      //Unset event id
+      unset($params['id']);
+      
+      //Set Schedule Reminder id
+      $params['id'] = $this->_scheduleReminderId;
+      $url = 'civicrm/event/manage/repeat';
+      $urlParams = "action=update&reset=1&id={$this->_id}";
+      
+      //Check if isChangeInRepeatConfiguration is set in params
+//      if($params['isChangeInRepeatConfiguration'] == 1){
+//        CRM_Core_Form_RecurringEntity::updateRecurCriterias($this->_id);
+//      }
+      CRM_Core_Form_RecurringEntity::postProcess($params, 'event');
+      CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
+      //CRM_Core_Error::debug_var('Event Recursion');
+    }else{
+        CRM_Core_Error::fatal("Could not find Event ID");
+    }  
+  }
+  
+}
\ No newline at end of file
diff --git a/CRM/Event/Form/ManageEvent/TabHeader.php b/CRM/Event/Form/ManageEvent/TabHeader.php
index e488114b65..d8316ec857 100644
--- a/CRM/Event/Form/ManageEvent/TabHeader.php
+++ b/CRM/Event/Form/ManageEvent/TabHeader.php
@@ -89,6 +89,7 @@ class CRM_Event_Form_ManageEvent_TabHeader {
     $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
@@ -111,6 +112,8 @@ 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 )
 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()) {
@@ -134,6 +137,9 @@ WHERE      e.id = %1
       if (!$dao->is_reminder) {
         $tabs['reminder']['valid'] = FALSE;
       }
+      if(!$eventHasParent){
+        $tabs['repeat']['valid'] = FALSE;
+      }
     }
 
     // see if any other modules want to add any tabs
diff --git a/CRM/Event/Page/ManageEvent.php b/CRM/Event/Page/ManageEvent.php
index 9df6e77c81..0a5b01a14d 100644
--- a/CRM/Event/Page/ManageEvent.php
+++ b/CRM/Event/Page/ManageEvent.php
@@ -92,6 +92,11 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
           'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
           'title' => ts('Copy Event'),
         ),
+        'repeat' => array(
+          'title' => ts('Repeat Event'),
+          'url' => 'civicrm/event/manage/repeat',
+          'field' => 'is_pcp_enabled',
+        )
       );
     }
     return self::$_actionLinks;
@@ -311,6 +316,15 @@ ORDER BY start_date desc
     while ($dao->fetch()) {
       if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) {
         $manageEvent[$dao->id] = array();
+        $isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($dao->id, 'civicrm_event');
+        $manageEvent[$dao->id]['repeat'] = '';
+        if($isRepeatingEvent){
+          if($dao->id == $isRepeatingEvent){
+            $manageEvent[$dao->id]['repeat'] = 'Repeating Event - (Parent)';
+          }else{
+            $manageEvent[$dao->id]['repeat'] = 'Repeating Event - (Child)';
+          }
+        }
         CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]);
 
         // form all action links
diff --git a/CRM/Event/xml/Menu/Event.xml b/CRM/Event/xml/Menu/Event.xml
index 9222b5a921..de94dbd917 100644
--- a/CRM/Event/xml/Menu/Event.xml
+++ b/CRM/Event/xml/Menu/Event.xml
@@ -215,6 +215,14 @@
      true
      950
   
+  
+     civicrm/event/manage/repeat
+     Repeat Event
+     CRM_Event_Form_ManageEvent_Repeat
+     access CiviEvent
+     true
+     960
+  
   
      civicrm/event/manage/conference
      Conference Slots
@@ -318,4 +326,14 @@
     CRM_Event_Form_ParticipantFeeSelection
     access CiviEvent
   
+  
+     civicrm/ajax/recurringEntity/update_cascade_type
+     CRM_Core_Page_Ajax_RecurringEntity::updateCascadeType
+     access CiviCRM,access CiviEvent
+  
+  
+     civicrm/ajax/recurringEntity/generate_preview
+     CRM_Core_Page_Ajax_RecurringEntity::generatePreview
+     access CiviCRM,access CiviEvent
+  
 
diff --git a/templates/CRM/Event/Form/ConfirmSubmit.tpl b/templates/CRM/Event/Form/ConfirmSubmit.tpl
new file mode 100644
index 0000000000..5bca022f54
--- /dev/null
+++ b/templates/CRM/Event/Form/ConfirmSubmit.tpl
@@ -0,0 +1,103 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+  
+  
+{literal}
+    
+{/literal}
+{*{foreach from=$form.buttons item=button key=key name=btns}
+    {if $key|substring:0:4 EQ '_qf_'}
+    {/if}
+{/foreach}*}
+{if $isRepeat eq 'repeat'}
+    {literal}
+        
+    {/literal}
+{/if}
diff --git a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
index 2f3de3509d..92923e3582 100644
--- a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
+++ b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
@@ -150,8 +150,9 @@
     
   
   
+ {include file="CRM/Form/validate.tpl"} {*include custom data js file*} - {include file="CRM/common/customData.tpl"} + {include file="CRM/Event/Form/ConfirmSubmit.tpl"} {literal} + {/literal} +{/if} \ No newline at end of file diff --git a/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl b/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl index 6095070c6a..d584db8251 100755 --- a/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl +++ b/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl @@ -188,6 +188,7 @@ {/literal} {/if} + {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
diff --git a/templates/CRM/Friend/Form/Friend.tpl b/templates/CRM/Friend/Form/Friend.tpl index 2e8f85966d..74e0798512 100644 --- a/templates/CRM/Friend/Form/Friend.tpl +++ b/templates/CRM/Friend/Form/Friend.tpl @@ -109,6 +109,7 @@ + {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
diff --git a/templates/CRM/PCP/Form/PCP.tpl b/templates/CRM/PCP/Form/PCP.tpl index 3bdb87907e..ecd5cc0e8b 100644 --- a/templates/CRM/PCP/Form/PCP.tpl +++ b/templates/CRM/PCP/Form/PCP.tpl @@ -90,6 +90,7 @@ {/crmRegion} +{include file="CRM/Event/Form/ConfirmSubmit.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
{include file="CRM/common/showHideByFieldValue.tpl" diff --git a/xml/schema/Core/ActionSchedule.xml b/xml/schema/Core/ActionSchedule.xml index 726da804dc..e504902d87 100644 --- a/xml/schema/Core/ActionSchedule.xml +++ b/xml/schema/Core/ActionSchedule.xml @@ -326,4 +326,11 @@ SET NULL 4.5 + + used_for + varchar + 64 + Maintained for recurring entity + 4.4 + diff --git a/xml/schema/Core/RecurringEntity.xml b/xml/schema/Core/RecurringEntity.xml new file mode 100644 index 0000000000..e43f33458b --- /dev/null +++ b/xml/schema/Core/RecurringEntity.xml @@ -0,0 +1,40 @@ + + + + CRM/Core + RecurringEntity + civicrm_recurring_entity + 1.7 + true + + id + ID + int unsigned + true + 1.7 + + + id + true + + + parent_id + int unsigned + Parent ID + true + 1.7 + + + entity_id + int unsigned + Entity ID + 1.7 + + + entity_table + varchar + Entity Table + true + 1.7 + +
\ No newline at end of file diff --git a/xml/schema/Core/files.xml b/xml/schema/Core/files.xml index ca448f2106..aaac22233a 100644 --- a/xml/schema/Core/files.xml +++ b/xml/schema/Core/files.xml @@ -54,4 +54,5 @@ + -- 2.25.1