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;
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+require_once 'packages/When/When.php';
+
+class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
+
+ static $_tableDAOMapper =
+ array(
+ 'civicrm_event' => '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;
+ }
+
+
+ }
function save() {
if (!empty($this->id)) {
$this->update();
+ CRM_Core_BAO_RecurringEntity::triggerUpdate($this);
}
else {
$this->insert();
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
--- /dev/null
+<?php
+/*
++--------------------------------------------------------------------+
+| 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 |
++--------------------------------------------------------------------+
+*/
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ *
+ * Generated from xml/schema/CRM/Core/RecurringEntity.xml
+ * DO NOT EDIT. Generated by GenCode.php
+ */
+require_once 'CRM/Core/DAO.php';
+require_once 'CRM/Utils/Type.php';
+class CRM_Core_DAO_RecurringEntity extends CRM_Core_DAO
+{
+ /**
+ * static instance to hold the table name
+ *
+ * @var string
+ * @static
+ */
+ static $_tableName = 'civicrm_recurring_entity';
+ /**
+ * static instance to hold the field values
+ *
+ * @var array
+ * @static
+ */
+ static $_fields = null;
+ /**
+ * static instance to hold the keys used in $_fields for each field.
+ *
+ * @var array
+ * @static
+ */
+ static $_fieldKeys = null;
+ /**
+ * static instance to hold the FK relationships
+ *
+ * @var string
+ * @static
+ */
+ static $_links = null;
+ /**
+ * static instance to hold the values that can
+ * be imported
+ *
+ * @var array
+ * @static
+ */
+ static $_import = null;
+ /**
+ * static instance to hold the values that can
+ * be exported
+ *
+ * @var array
+ * @static
+ */
+ static $_export = null;
+ /**
+ * static value to see if we should log any modifications to
+ * this table in the civicrm_log table
+ *
+ * @var boolean
+ * @static
+ */
+ static $_log = true;
+ /**
+ *
+ * @var int unsigned
+ */
+ public $id;
+ /**
+ *
+ * @var int unsigned
+ */
+ public $parent_id;
+ /**
+ *
+ * @var int unsigned
+ */
+ public $entity_id;
+ /**
+ *
+ * @var string
+ */
+ public $entity_table;
+ /**
+ * class constructor
+ *
+ * @access public
+ * @return civicrm_recurring_entity
+ */
+ function __construct()
+ {
+ $this->__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;
+ }
+}
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+/**
+ * This class generates form components for processing Event
+ *
+ */
+class CRM_Core_Form_RecurringEntity {
+ /**
+ * Current entity id
+ */
+ protected static $_entityId = NULL;
+
+ static function buildQuickForm(&$form) {
+ //$attributes_schedule = CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionMapping');
+ self::$_entityId = CRM_Utils_Array::value('id', $_GET);
+ $form->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 "<pre>";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'). '<br />';
+ $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;
+ }
+
+}
--- /dev/null
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of EntityApplyChangesTo
+ *
+ * @author Priyanka
+ */
+
+class CRM_Core_Page_Ajax_RecurringEntity {
+
+ public static function updateCascadeType(){
+ if(CRM_Utils_Array::value('cascadeType', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){
+ $finalResult = array();
+ $cascadeType = CRM_Utils_Type::escape($_REQUEST['cascadeType'], 'Integer');
+ $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
+
+ $sql = "UPDATE
+ civicrm_recurring_entity
+ SET cascade_type = (%1)
+ WHERE entity_id = (%2) AND entity_table = 'civicrm_event'";
+ $params = array(
+ 1 => 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();
+ }
+
+}
+
}
}
}
+
/**
* @param $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");
$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') {
$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) {
}
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id');
-
+
$form->assign('validCiviEvent', TRUE);
$form->setDefaults(array('participant_test' => 0));
}
* the participant records
*/
protected $_campaignID = NULL;
+
+ /**
+ * Check if repeating event
+ */
+ protected $_isRepeatingEvent;
/**
* Function to set variables up before form is built
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);
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);
}
}
$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);
--- /dev/null
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of Repeat
+ *
+ * @author Priyanka
+ */
+class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
+
+ /**
+ * Schedule Reminder Id
+ */
+ protected $_scheduleReminderId = NULL;
+
+ /**
+ * Schedule Reminder data
+ */
+ protected $_scheduleReminderDetails = array();
+
+ /**
+ * Parent Event ID
+ */
+ protected $_parentEventId = NULL;
+
+ /**
+ * Parent Event Start Date
+ */
+ protected $_parentEventStartDate = NULL;
+
+ /**
+ * Parent Event End Date
+ */
+ protected $_parentEventEndDate = NULL;
+
+ /**
+ * Exclude date information
+ */
+ public $_excludeDateInfo = array();
+
+ protected $_pager = NULL;
+
+
+
+ function preProcess() {
+ parent::preProcess();
+ $this->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 "<pre>"; 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 "<pre>"; 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
$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
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()) {
if (!$dao->is_reminder) {
$tabs['reminder']['valid'] = FALSE;
}
+ if(!$eventHasParent){
+ $tabs['repeat']['valid'] = FALSE;
+ }
}
// see if any other modules want to add any tabs
'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;
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
<is_ssl>true</is_ssl>
<weight>950</weight>
</item>
+ <item>
+ <path>civicrm/event/manage/repeat</path>
+ <title>Repeat Event</title>
+ <page_callback>CRM_Event_Form_ManageEvent_Repeat</page_callback>
+ <access_arguments>access CiviEvent</access_arguments>
+ <is_ssl>true</is_ssl>
+ <weight>960</weight>
+ </item>
<item>
<path>civicrm/event/manage/conference</path>
<title>Conference Slots</title>
<page_callback>CRM_Event_Form_ParticipantFeeSelection</page_callback>
<access_arguments>access CiviEvent</access_arguments>
</item>
+ <item>
+ <path>civicrm/ajax/recurringEntity/update_cascade_type</path>
+ <page_callback>CRM_Core_Page_Ajax_RecurringEntity::updateCascadeType</page_callback>
+ <access_arguments>access CiviCRM,access CiviEvent</access_arguments>
+ </item>
+ <item>
+ <path>civicrm/ajax/recurringEntity/generate_preview</path>
+ <page_callback>CRM_Core_Page_Ajax_RecurringEntity::generatePreview</page_callback>
+ <access_arguments>access CiviCRM,access CiviEvent</access_arguments>
+ </item>
</menu>
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+*}
+ <div id="dialog" style="display:none;">
+ Would you like to change this event only, or this and following events in series?<br/><br/>
+ <div style="display: inline-block">
+ <div style="display:inline-block;width:100%;">
+ <div style="width:30%;float:left;">
+ <button class="dialog-button only-this-event">Only this Event</button>
+ </div>
+ <div style="width:70%;float:left;">All other events in the series will remain same</div></div>
+ <div style="display:inline-block;width:100%;">
+ <div style="width:30%;float:left;">
+ <button class="dialog-button this-and-all-following-event">This and Following Events</button>
+ </div>
+ <div style="width:70%;float:left;">This and all the following events will be changed</div>
+ </div>
+ </div>
+ </div>
+ <input type="hidden" value="" name="isRepeatingEvent" id="is-repeating-event"/>
+{literal}
+ <style type="text/css">
+ .dialog-button{
+ background: #f5f5f5;
+ background-image: -webkit-linear-gradient(top,#f5f5f5,#f1f1f1);
+ border: 1px solid rgba(0,0,0,0.1);
+ padding: 5px 8px;
+ text-align: center;
+ border-radius: 2px;
+ cursor: pointer;
+ font-size: 11px !important;
+ }
+ </style>
+{/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}
+ <script type="text/javascript">
+ cj(document).ready(function() {
+ cj("#dialog").dialog({ autoOpen: false });
+ cj('div.crm-submit-buttons span.crm-button input[value="Save"], div.crm-submit-buttons span.crm-button input[value="Save and Done"]').click( function () {
+ cj("#dialog").dialog('open');
+ cj("#dialog").dialog({
+ title: 'Save recurring event',
+ width: '650',
+ position: 'center',
+ //draggable: false,
+ buttons: {
+ Cancel: function() { //cancel
+ cj( this ).dialog( "close" );
+ }
+ }
+ });
+ return false;
+ });
+ cj(".this-and-all-following-event").click(function(){
+ var eventID ={/literal}{$id}{literal};
+ if(eventID != ""){
+ var ajaxurl = CRM.url("civicrm/ajax/recurringEntity/update_cascade_type");
+ var data = {cascadeType: 2, entityId: eventID};
+ cj.ajax({
+ dataType: "json",
+ data: data,
+ url: ajaxurl,
+ success: function (result) {
+ cj("#dialog").dialog('close');
+ }
+ });
+ }
+ });
+ cj(".only-this-event").click(function(){
+ cj("#dialog").dialog('close');
+ cj("form").submit();
+ });
+ });
+ </script>
+ {/literal}
+{/if}
</tr>
</table>
<div id="customData"></div>
+ {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}
<script type="text/javascript">
CRM.$(function($) {
</div>
</div>
</div>
+{include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
<td id="locUsedMsg" colspan="3">
</td>
</tr>
-
+
</table>
{/if}
-
+
<div id="newLocation">
</td>
</tr>
</table>
+ {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</fieldset>
</div> {*end of div registration_blocks*}
</div>
+ {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2010 |
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+*}
+
+{htxt id="id-repeats-title"}
+{ts}Repeats{/ts}
+{/htxt}
+{htxt id="id-repeats"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-repeats-every-title"}
+{ts}Repeats every{/ts}
+{/htxt}
+{htxt id="id-repeats-every"}
+ {ts}This option defines the interval.{/ts}
+{/htxt}
+
+{htxt id="id-repeats-on-title"}
+{ts}Repeats on{/ts}
+{/htxt}
+{htxt id="id-repeats-on"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-repeats-by-month-title"}
+{ts}Repeats by day of the month{/ts}
+{/htxt}
+{htxt id="id-repeats-by-month"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-repeats-by-week-title"}
+{ts}Repeats by day of the week{/ts}
+{/htxt}
+{htxt id="id-repeats-by-week"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-ends-after-title"}
+{ts}Ends{/ts}
+{/htxt}
+{htxt id="id-ends-after"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-ends-on-title"}
+{ts}Ends{/ts}
+{/htxt}
+{htxt id="id-ends-on"}
+ {ts}{/ts}
+{/htxt}
+
+{htxt id="id-exclude-date-title"}
+{ts}Exclude Date{/ts}
+{/htxt}
+{htxt id="id-exclude-date"}
+ {ts}Dates added here would be ignored for repeating events{/ts}
+{/htxt}
\ No newline at end of file
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.5 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+*}
+<div class="crm-block crm-form-block crm-event-manage-repeat-form-block">
+{include file="CRM/Core/Form/RecurringEntity.tpl"}
+{if $rows}
+<div id="event_status_id" class="crm-block crm-manage-events crm-accordion-wrapper">
+ <div class="crm-accordion-header">Connected Repeating Events</div>
+ <div class="crm-accordion-body">
+ {strip}
+ {include file="CRM/common/jsortable.tpl"}
+ <table id="options" class="display">
+ <thead>
+ <tr>
+ <th>{ts}Event{/ts}</th>
+ <th>{ts}Public?{/ts}</th>
+ <th>{ts}Starts{/ts}</th>
+ <th>{ts}Ends{/ts}</th>
+ <th>{ts}Active?{/ts}</th>
+ <th>{ts}Event Link{/ts}</th>
+ <th class="hiddenElement"></th>
+ <th class="hiddenElement"></th>
+ </tr>
+ </thead>
+ {foreach from=$rows key=keys item=row}
+ {if $keys neq 'tab'}
+ {if $currentEventId eq $row.id}
+ {assign var="highlight" value=" highlight-record"}
+ {else}
+ {assign var="highlight" value=""}
+ {/if}
+ <tr id="row_{$row.id}" class="{if NOT $row.is_active} disabled{/if}">
+ <td class="crm-event_{$row.id}{$highlight}">
+ <a href="{crmURL p='civicrm/event/info' q="id=`$row.id`&reset=1"}"
+ title="{ts}View event info page{/ts}" class="bold">{$row.title}</a> ({ts}ID:{/ts} {$row.id})
+ </td>
+ <td class="crm-event-is_public{$highlight}">{if $row.is_public eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
+ <td class="crm-event-start_date{$highlight}">{$row.start_date|crmDate:"%b %d, %Y %l:%M %P"}</td>
+ <td class="crm-event-end_date{$highlight}">{$row.end_date|crmDate:"%b %d, %Y %l:%M %P"}</td>
+ <td class="crm-event_status{$highlight}" id="row_{$row.id}_status">
+ {if $row.is_active eq 1}{ts}Yes{/ts} {else} {ts}No{/ts} {/if}
+ </td>
+ <td class="{$highlight}">
+ <a href="{crmURL p="civicrm/event/manage/settings" q="reset=1&action=update&id=`$row.id`"}">Manage Event</a>
+ </td>
+ <td class="crm-event-start_date hiddenElement">{$row.start_date|crmDate}</td>
+ <td class="crm-event-end_date hiddenElement">{$row.end_date|crmDate}</td>
+ </tr>
+ {/if}
+ {/foreach}
+ </table>
+ {include file="CRM/common/pager.tpl" location="bottom"}
+ {/strip}
+ </div>
+</div>
+{/if}
+</div>
+{*Hide Summary*}
+{if empty($scheduleReminderId)}
+ {literal}
+ <script type="text/javascript">
+ cj(document).ready(function() {
+ if(cj('#rec-summary').length){
+ cj('#rec-summary').parent().parent().hide();
+ }
+ });
+ </script>
+ {/literal}
+{/if}
\ No newline at end of file
</script>
{/literal}
{/if}
+ {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</tr>
</table>
</div>
+ {include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
</table>
{/crmRegion}
</div>
+{include file="CRM/Event/Form/ConfirmSubmit.tpl"}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
{include file="CRM/common/showHideByFieldValue.tpl"
<onDelete>SET NULL</onDelete>
<add>4.5</add>
</foreignKey>
+ <field>
+ <name>used_for</name>
+ <type>varchar</type>
+ <length>64</length>
+ <comment>Maintained for recurring entity</comment>
+ <add>4.4</add>
+ </field>
</table>
--- /dev/null
+<?xml version="1.0" encoding="iso-8859-1" ?>
+
+<table>
+ <base>CRM/Core</base>
+ <class>RecurringEntity</class>
+ <name>civicrm_recurring_entity</name>
+ <add>1.7</add>
+ <log>true</log>
+ <field>
+ <name>id</name>
+ <title>ID</title>
+ <type>int unsigned</type>
+ <required>true</required>
+ <add>1.7</add>
+ </field>
+ <primaryKey>
+ <name>id</name>
+ <autoincrement>true</autoincrement>
+ </primaryKey>
+ <field>
+ <name>parent_id</name>
+ <type>int unsigned</type>
+ <title>Parent ID</title>
+ <required>true</required>
+ <add>1.7</add>
+ </field>
+ <field>
+ <name>entity_id</name>
+ <type>int unsigned</type>
+ <title>Entity ID</title>
+ <add>1.7</add>
+ </field>
+ <field>
+ <name>entity_table</name>
+ <type>varchar</type>
+ <title>Entity Table</title>
+ <required>true</required>
+ <add>1.7</add>
+ </field>
+</table>
\ No newline at end of file
<xi:include href="Setting.xml" parse="xml" />
<xi:include href="PrintLabel.xml" parse="xml" />
<xi:include href="WordReplacement.xml" parse="xml" />
+ <xi:include href="RecurringEntity.xml" parse="xml" />
</tables>