diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 6e9da1d4..cf04981c 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -335,6 +335,68 @@ private function resolve_query_result_value($result, $index, $columnname) {
return $adb->query_result($result, $index, $columnname);
}
+ /** Function to find all recurringreferences ids from this idRef
+ * $idRef == this->id
+ */
+ public function findRecurringreferencesIDs($idRef){
+ // if $idRef belong to RecurringEvent so this funktion find all IDs, that belong to it to.
+ global $adb;
+ $sqlRef1 = 'SELECT * FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $resultRef1 = $adb->pquery($sqlRef1, array( $idRef ));
+ $rowsRef1 = $adb->num_rows($resultRef1);
+
+ $idsReferencesArray = array();
+ $parentactivityidMe ='';
+ //$rowsRef1, if it is not 0 so it can be only 1.
+ if($rowsRef1 > 0){
+ for($a = 0; $a < $rowsRef1 ; $a++){
+ $row1 = $adb->query_result_rowdata($resultRef1, $a);
+ $parentactivityidMe = $row1['parentactivityid'];
+ }
+ if($parentactivityidMe != ''){ // (here it muss have a value. )
+ $sqlRef2 = 'SELECT activityid FROM `berlicrm_recurringreferences` WHERE parentactivityid = ?';
+ $resultRef2 = $adb->pquery($sqlRef2, array( $parentactivityidMe ));
+ $rowsRef2 = $adb->num_rows($resultRef2);
+ // it can be nothing, one, or many here.
+ if($rowsRef2 > 0){
+ for($b = 0; $b < $rowsRef2 ; $b++){
+ $row2 = $adb->query_result_rowdata($resultRef2, $b);
+ $activityidMe = $row2['activityid'];
+ // add the belong IDs to the array.
+ $idsReferencesArray[] = $activityidMe;
+ }
+ }else{
+ // ERROR it can not step here, because if "parentactivityid" exist, it muss exist "activityid" to.
+ }
+ }else{
+ // ERROR it can not step here, because "parentactivityid" field are not found, but muss be in DB.
+ }
+ }else{
+ // here step it only if this $idRef not be in the table as 'activityid',
+ // but if we delete the first Event of the RecurringsEvents,
+ // it can be only 'parentactivityid' self. Vor another functionality it can help.
+ /*$sqlRef2 = 'SELECT activityid FROM `berlicrm_recurringreferences` WHERE parentactivityid = ?';
+ $resultRef2 = $adb->pquery($sqlRef2, array( $idRef ));
+ $rowsRef2 = $adb->num_rows($resultRef2);
+ if($rowsRef2 > 0){
+ for($b = 0; $b < $rowsRef2 ; $b++){
+ $row2 = $adb->query_result_rowdata($resultRef2, $b);
+ $activityidMe = $row2['activityid'];
+ // add the belong IDs to the array.
+ $idsReferencesArray[] = $activityidMe;
+ }
+ }else{
+ // if it is not a activityid or parentactivityid, so it can not be a Recurringevent, and this id belong to normal Event.
+ }*/
+ }
+ // if the array is empty, so it was a normal Event without recurring.
+ // doubles remove (it can not have a double values, but just in case)
+ $idsReferencesArray = array_unique($idsReferencesArray);
+ // from smallest to largest value. (normally it is allready sorted, but just im case)
+ sort($idsReferencesArray);
+ return $idsReferencesArray;
+ }
+
/** Function to insert values in the specifed table for the specified module
* @param $table_name -- table name:: Type varchar
* @param $module -- module:: Type varchar
@@ -360,6 +422,80 @@ function insertIntoEntityTable($table_name, $module, $fileid = '') {
}
}
+ if ($insertion_mode == 'edit' && $this->column_fields['recurringtype'] != '' && $this->column_fields['recurringtype'] != '--None--' ){
+
+ $idsReferencesArray = $this->findRecurringreferencesIDs(($this->id));
+
+ if( count($idsReferencesArray) > 0 ){
+ // in $_REQUEST : [date_start] => 23-06-2021 /// in DB : ['recurringdate'] 2021-06-23
+ $date_start_for_request = '';
+ $date_start_for_column_fields = '';
+
+ $sqlRef2 = 'SELECT startdate FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $resultRef2 = $adb->pquery($sqlRef2, array( $idsReferencesArray[0] ));
+ $rowsRef2 = $adb->num_rows($resultRef2);
+ if($rowsRef2 > 0){
+ $row2 = $adb->query_result_rowdata($resultRef2, 0);
+ $recurringdate = ($row2['startdate']); // 2021-06-23
+ $date_start_for_column_fields = $recurringdate;
+ $recurringdateArray = explode('-',$recurringdate);
+ $date_start_for_request = $recurringdateArray[2].'-'.$recurringdateArray[1].'-'.$recurringdateArray[0]; // 23-06-2021
+ }
+
+ // REQUEST [date_start] => 23-06-2021 //$this->column_fields['date_start'] 2021-06-23
+ $_REQUEST['due_date'] = $date_start_for_request;
+ $_REQUEST['date_start'] = $date_start_for_request;
+ $this->column_fields['date_start'] = $date_start_for_column_fields;
+ $this->column_fields['due_date'] = $date_start_for_column_fields;
+
+ $newRecurringdates = array();
+ for($a = 0; $a < count($idsReferencesArray) ; $a++){
+ // collect all datas from the recurringevents
+ $sqlRef1 = 'SELECT * FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $resultRef1 = $adb->pquery($sqlRef1, array( $idsReferencesArray[$a] ));
+ $rowsRef1 = $adb->num_rows($resultRef1);
+ // sollte immer nur ein Treffer sein. $rowsRef1 sollte = 1 sein.
+ if($rowsRef1 > 0){
+ for($b = 0; $b < $rowsRef1; $b++ ){
+ $row = $adb->query_result_rowdata($resultRef1, $b);
+ $newStartdate = $row['startdate'];
+ $newRecurringdates[] = $newStartdate;
+ }
+ }
+ }
+
+
+ for($a = 0; $a < count($idsReferencesArray) ; $a++){
+ // dell all (because it will be set new)
+ $deleteFromBerlicrm_recurringreferences = 'DELETE FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $adb->pquery($deleteFromBerlicrm_recurringreferences, array( $idsReferencesArray[$a] ));
+
+
+ if( $this->id == $idsReferencesArray[$a]){
+ //only if it is the id, not del. In Activity.php was a function for it to del and new set.
+ }else{
+ $delete_from_vtiger_activity = 'DELETE FROM `vtiger_activity` WHERE activityid = ?';
+ $adb->pquery($delete_from_vtiger_activity, array( $idsReferencesArray[$a] ));
+
+ // if a activity in `vtiger_activity` deleted, so it will be deleted auto in `vtiger_recurringevents` to.
+ //$delete_from_vtiger_recurringevents = 'DELETE FROM vtiger_recurringevents WHERE activityid=?';
+ //$adb->pquery($delete_from_vtiger_recurringevents, array($idsReferencesArray[$a]));
+
+ $delete_from_vtiger_activity_reminder = 'DELETE FROM vtiger_activity_reminder WHERE activity_id=?';
+ $adb->pquery($delete_from_vtiger_activity_reminder, array($idsReferencesArray[$a]));
+
+ $delete_from_vtiger_cntactivityrel = 'DELETE FROM vtiger_cntactivityrel WHERE activityid = ?';
+ $adb->pquery($delete_from_vtiger_cntactivityrel, array($idsReferencesArray[$a]));
+
+ }
+ }
+
+ $_REQUEST['newRecurringdates'] = $newRecurringdates;
+
+ }
+ }
+
+
$tabid = getTabid($module);
if ($module == 'Calendar' && $this->column_fields["activitytype"] != null && $this->column_fields["activitytype"] != 'Task') {
$tabid = getTabid('Events');
@@ -446,7 +582,7 @@ function insertIntoEntityTable($table_name, $module, $fileid = '') {
// crm-now: flag for appending data, preventing multiple appends (by save-triggered workflows f.e.)
$append = $_REQUEST["add"][$fieldname]=="on" && !$_REQUEST["added"][$fieldname][$this->id] && !empty($_REQUEST[$fieldname]);
- $_REQUEST["added"][$fieldname][$this->id]=true;
+ $_REQUEST["added"][$fieldname][$this->id]=true;
$typeofdata_array = explode("~", $typeofdata);
$datatype = $typeofdata_array[0];
@@ -1787,12 +1923,12 @@ function get_related_list($id, $cur_tab_id, $rel_tab_id, $actions = false) {
// crm-now: double joined crmentityrel (instead of OR in join-condition) yielding *huge* performance boost
$query .= " FROM $other->table_name";
$query .= " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $other->table_name.$other->table_index";
- $query .= " LEFT JOIN vtiger_crmentityrel AS entrel1 ON (entrel1.relcrmid = vtiger_crmentity.crmid AND entrel1.crmid = $id)";
- $query .= " LEFT JOIN vtiger_crmentityrel AS entrel2 ON (entrel2.crmid = vtiger_crmentity.crmid AND entrel2.relcrmid = $id)";
+ $query .= " LEFT JOIN vtiger_crmentityrel as entrel1 ON entrel1.relcrmid = vtiger_crmentity.crmid";
+ $query .= " LEFT JOIN vtiger_crmentityrel as entrel2 ON entrel2.crmid = vtiger_crmentity.crmid";
$query .= $more_relation;
$query .= " LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid";
$query .= " LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
- $query .= " WHERE vtiger_crmentity.deleted = 0 AND (entrel1.crmid = $id OR entrel2.relcrmid = $id)";
+ $query .= " WHERE vtiger_crmentity.deleted = 0 AND (entrel2.relcrmid = $id OR entrel1.crmid = $id)";
$return_value = GetRelatedList($currentModule, $related_module, $other, $query, $button, $returnset);
if ($return_value == null)
diff --git a/db_update.php b/db_update.php
index b9df878a..1c060048 100644
--- a/db_update.php
+++ b/db_update.php
@@ -425,6 +425,22 @@
}
}
+echo "
Create berlicrm_recurringreferences table for calendar recurring events
";
+
+$query = "
+CREATE TABLE IF NOT EXISTS `berlicrm_recurringreferences` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `parentactivityid` int(11) NOT NULL,
+ `activityid` int(11) NOT NULL,
+ `startdate` date DEFAULT NULL,
+ `enddate` date DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+";
+$adb->pquery($query, array());
+echo "create berlicrm_recurringreferences table done.
";
+
+
$query = "UPDATE `vtiger_version` SET `tag_version` = ?";
$adb->pquery($query, array($current_release_tag));
echo "
Finished updating to $current_release_tag!
";
diff --git a/languages/de_de/Vtiger.php b/languages/de_de/Vtiger.php
index a543d0ad..5fa50dff 100644
--- a/languages/de_de/Vtiger.php
+++ b/languages/de_de/Vtiger.php
@@ -862,6 +862,8 @@
// RelatedList Count fail
'LBL_QUERY_FAILED' => 'fehlerhafte Query',
+ 'LBL_SINGLE_EMAIL' => 'E-Mail',
+
// Workflow
'LBL_WORKFLOW_TOO_MANY_SUBJECT' => 'Probleme bei Workflow',
'LBL_WORKFLOW_TOO_MANY_CONTENT' => 'Diese Email wurde erzeugt, weil einer Ihrer Workflows mit %d Datensätzen die zulässige Anzahl der zu verarbeitenden Datensätze von %d überschreiten würde und deshalb auf %d reduziert wurde.
Sollten Sie diese Email mehrfach mit unveränderter Anzahl der zu verarbeitenden Datensätze erhalten, dann ändern Sie die Bedingungen, da ansonsten niemals alle Daten verarbeitet werden können.',
@@ -1086,5 +1088,9 @@
'JS_LBL_NO_TAXES'=>'Keine Steuern festgelegt',
'JS_LBL_SET_TAX_FOR'=>'setze Steuer für',
+ //To delete all or only one Appointment from calendar inquiry
+ 'JS_ALL'=>'Alle',
+ 'JS_ONLY_THIS'=>'Nur diesen',
+
);
?>
\ No newline at end of file
diff --git a/languages/en_us/Vtiger.php b/languages/en_us/Vtiger.php
index 833f9a58..87cf5a03 100644
--- a/languages/en_us/Vtiger.php
+++ b/languages/en_us/Vtiger.php
@@ -862,6 +862,8 @@
// RelatedList Count fail
'LBL_QUERY_FAILED' => 'Query failed',
+ 'LBL_SINGLE_EMAIL' => 'Email',
+
// Workflow
'LBL_WORKFLOW_TOO_MANY_SUBJECT' => 'Issues with Workflow',
'LBL_WORKFLOW_TOO_MANY_CONTENT' => 'This email has been generated because one of your Workflows with %d affected data sets would exceed the limitation of %d and thus was reduced to %d.
Should you recieve this email multiple times with an unaltered amount of affected data sets then you should consider to change the Workflow conditions, otherwise not all data will be processed.',
@@ -1086,4 +1088,8 @@
'JS_LBL_NO_TAXES'=>'no taxes assigned',
'JS_LBL_SET_TAX_FOR'=>'set tax for',
+ //To delete all or only one Appointment from calendar inquiry
+ 'JS_ALL'=>'All',
+ 'JS_ONLY_THIS'=>'Only this',
+
);
\ No newline at end of file
diff --git a/layouts/vlayout/modules/Calendar/resources/CalendarView.js b/layouts/vlayout/modules/Calendar/resources/CalendarView.js
index 8ee12bfa..470238f3 100644
--- a/layouts/vlayout/modules/Calendar/resources/CalendarView.js
+++ b/layouts/vlayout/modules/Calendar/resources/CalendarView.js
@@ -309,39 +309,149 @@ jQuery.Class("Calendar_CalendarView_Js",{
}
},
+
registerEventDelete : function(targetElement,calEvent) {
var thisInstance = this;
var recordId = calEvent.id;
- targetElement.find('.delete').click(function(e){
- var message = app.vtranslate('LBL_DELETE_CONFIRMATION');
- Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
- function(e) {
- //Confirmed to delete
- var params = {
- "module": "Calendar",
- "action": "DeleteAjax",
- "record": recordId
- }
- AppConnector.request(params).then(function(data){
- if(data.success) {
- thisInstance.getCalendarView().fullCalendar('removeEvents', calEvent.id);
- var param = {text:app.vtranslate('JS_RECORD_DELETED')};
- Vtiger_Helper_Js.showMessage(param);
- } else {
- var params = {
- text : app.vtranslate('JS_NO_DELETE_PERMISSION')
- }
- Vtiger_Helper_Js.showPnotify(params);
- }
- });
- },
- function(error, err){
- e.preventDefault();
- return false;
- });
- });
+
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "operation" : "checkRecurr"
+ }
+ AppConnector.request(params).then(function(data){
+ if(data.success) {
+ var idsReferencesArray = data.result.idsReferencesArray;
+ targetElement.find('.delete').click(function(e){
+
+ if(idsReferencesArray.length > 0){
+
+ var message = app.vtranslate('JS_LBL_ARE_YOU_SURE_YOU_WANT_TO_DELETE');
+ var cancel = app.vtranslate('JS_LBL_CANCEL');
+ var all = app.vtranslate('JS_ALL');
+ var onlyThis = app.vtranslate('JS_ONLY_THIS');
+
+ console.log(cancel);
+ var bootBoxModal = bootbox.dialog(
+ message,
+ [
+ {
+ "label" : cancel,
+ //"class" : "btn-primary",
+ "callback": function() {
+ // cancel, nothing to do
+ }
+ },
+ {
+ "label" : onlyThis,
+ "class" : "btn-danger",
+ "callback": function() {
+ // delete one, not all (and not cancel)
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "operation" : "deleteevent"
+ }
+ AppConnector.request(params).then(function(data){
+ if(data.success) {
+ thisInstance.getCalendarView().fullCalendar('removeEvents', recordId);
+ var param = {text:app.vtranslate('JS_RECORD_DELETED')};
+ Vtiger_Helper_Js.showMessage(param);
+ } else {
+ var params = {
+ text : app.vtranslate('JS_NO_DELETE_PERMISSION')
+ }
+ Vtiger_Helper_Js.showPnotify(params);
+ }
+ });
+
+ }
+ },
+ {
+ "label":all,
+ "class" : "btn-danger",
+ "callback": function() {
+ // delete all, not one (and not cancel)
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "idsReferencesArray": idsReferencesArray,
+ "operation" : "deleteManyEvents"
+ }
+ AppConnector.request(params).then(function(data){
+ if(data.success) {
+ // remove the views of all this ids in GUI
+ for(a = 0; a < idsReferencesArray.length; a++){
+ thisInstance.getCalendarView().fullCalendar('removeEvents', idsReferencesArray[a]);
+ }
+ var param = {text:app.vtranslate('JS_RECORD_DELETED')};
+ Vtiger_Helper_Js.showMessage(param);
+ } else {
+ var params = {
+ text : app.vtranslate('JS_NO_DELETE_PERMISSION')
+ }
+ Vtiger_Helper_Js.showPnotify(params);
+ }
+ });
+
+ }
+ }/*,
+ {
+ "label" : "Just a button more..."
+ }*/
+ ]
+ );
+
+
+ }else{
+ // if it was not a recurringevents
+ var message = app.vtranslate('LBL_DELETE_CONFIRMATION');
+ Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
+ function(e) {
+ //Confirmed to delete
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "operation" : "deleteevent"
+ }
+ AppConnector.request(params).then(function(data){
+ if(data.success) {
+ thisInstance.getCalendarView().fullCalendar('removeEvents', calEvent.id);
+ var param = {text:app.vtranslate('JS_RECORD_DELETED')};
+ Vtiger_Helper_Js.showMessage(param);
+ } else {
+ var params = {
+ text : app.vtranslate('JS_NO_DELETE_PERMISSION')
+ }
+ Vtiger_Helper_Js.showPnotify(params);
+ }
+ });
+ },
+ function(error, err){
+ e.preventDefault();
+ return false;
+ });
+
+
+ }
+
+ });
+
+ } else {
+ // error
+ var params = {
+ text : 'Check Recurring not correct'
+ }
+ Vtiger_Helper_Js.showPnotify(params);
+ }
+ });
},
+
registerCalendar : function(customConfig) {
var thisInstance = this;
var calendarview = this.getCalendarView();
@@ -454,29 +564,56 @@ jQuery.Class("Calendar_CalendarView_Js",{
return;
}
- var params = {
- module : 'Calendar',
- action : 'DragDropAjax',
- mode : 'updateDeltaOnResize',
- id : event.id,
- activitytype : event.activitytype,
- secDelta : delta.asSeconds()
- }
- AppConnector.request(params).then(function(data){
- if (!data || !data.result) {
- var err = app.vtranslate('JS_ERROR');
- if (data.error && data.error.message) err = err+ ': '+data.error.message;
- Vtiger_Helper_Js.showPnotify(err);
- revertFunc();
- } else if(!data.result.ispermitted){
- Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_NO_EDIT_PERMISSION'));
- revertFunc();
- }
- }, function() {
- var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
- Vtiger_Helper_Js.showPnotify(err);
+ var recordId = event.id;
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "operation" : "checkRecurr"
+ }
+ AppConnector.request(params).then(function(data){
+ var idsReferencesArray = [];
+ if(data.success) {
+ idsReferencesArray = data.result.idsReferencesArray;
+ if(idsReferencesArray.length > 0){
+ revertFunc();
+ return;
+ }else{
+ var params = {
+ module : 'Calendar',
+ action : 'DragDropAjax',
+ mode : 'updateDeltaOnResize',
+ id : event.id,
+ activitytype : event.activitytype,
+ secDelta : delta.asSeconds()
+ }
+ AppConnector.request(params).then(function(data){
+ if (!data || !data.result) {
+ var err = app.vtranslate('JS_ERROR');
+ if (data.error && data.error.message) err = err+ ': '+data.error.message;
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
+ } else if(!data.result.ispermitted){
+ Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_NO_EDIT_PERMISSION'));
+ revertFunc();
+ }
+ }, function() {
+ var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
+ });
+ }
+
+ }else{
revertFunc();
+ return;
+ }
+ }, function() {
+ var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
});
+
},
eventDrop : function( event, delta, revertFunc, jsEvent, ui, view ) {
@@ -488,29 +625,59 @@ jQuery.Class("Calendar_CalendarView_Js",{
revertFunc();
return;
}
- var params = {
- module : 'Calendar',
- action : 'DragDropAjax',
- mode : 'updateDeltaOnDrop',
- id : event.id,
- activitytype : event.activitytype,
- secDelta : delta.asSeconds()
- }
- AppConnector.request(params).then(function(data){
- if (!data || !data.result) {
- var err = app.vtranslate('JS_ERROR');
- if (data.error && data.error.message) err = err+ ': '+data.error.message;
- Vtiger_Helper_Js.showPnotify(err);
- revertFunc();
- } else if(!data.result.ispermitted){
- Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_NO_EDIT_PERMISSION'));
- revertFunc();
- }
- }, function() {
- var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
- Vtiger_Helper_Js.showPnotify(err);
- revertFunc();
- });
+
+ var recordId = event.id;
+ var params = {
+ "module": "Calendar",
+ "action": "DeleteAjax",
+ "record": recordId,
+ "operation" : "checkRecurr"
+ }
+ AppConnector.request(params).then(function(data){
+ var idsReferencesArray = [];
+ if(data.success) {
+ idsReferencesArray = data.result.idsReferencesArray;
+ if(idsReferencesArray.length > 0){
+ revertFunc();
+ return;
+ }else{
+
+ var params = {
+ module : 'Calendar',
+ action : 'DragDropAjax',
+ mode : 'updateDeltaOnDrop',
+ id : event.id,
+ activitytype : event.activitytype,
+ secDelta : delta.asSeconds()
+ }
+ AppConnector.request(params).then(function(data){
+ if (!data || !data.result) {
+ var err = app.vtranslate('JS_ERROR');
+ if (data.error && data.error.message) err = err+ ': '+data.error.message;
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
+ } else if(!data.result.ispermitted){
+ Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_NO_EDIT_PERMISSION'));
+ revertFunc();
+ }
+ }, function() {
+ var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
+ });
+
+ }
+
+ }else{
+ revertFunc();
+ return;
+ }
+ }, function() {
+ var err = app.vtranslate('JS_ERROR')+': Internal Server Error';
+ Vtiger_Helper_Js.showPnotify(err);
+ revertFunc();
+ });
+
},
eventMouseover : function(calEvent, jsEvent, view) {
diff --git a/modules/Calendar/Activity.php b/modules/Calendar/Activity.php
index e03cb206..118179ca 100644
--- a/modules/Calendar/Activity.php
+++ b/modules/Calendar/Activity.php
@@ -90,7 +90,8 @@ class Activity extends CRMEntity {
'Start Date'=>'date_start',
'Start Time'=>'time_start',
'End Date'=>'due_date',
- 'End Time'=>'time_end');
+ 'End Time'=>'time_end'
+ );
var $list_link_field= 'subject';
@@ -154,17 +155,26 @@ function save_module($module)
$recur_type='';
if(($recur_type == "--None--" || $recur_type == '') && $this->mode == "edit")
{
- $sql = 'delete from vtiger_recurringevents where activityid=?';
+ $sql = 'DELETE FROM vtiger_recurringevents WHERE activityid=?';
+ $adb->pquery($sql, array($this->id));
+
+ // If del it from vtiger_recurringevents, so del it from berlicrm_recurringreferences to.
+ $sql = 'DELETE FROM berlicrm_recurringreferences WHERE activityid = ?';
$adb->pquery($sql, array($this->id));
+
}
+
+
//Handling for recurring type
//Insert into vtiger_recurring event table
if(isset($this->column_fields['recurringtype']) && $this->column_fields['recurringtype']!='' && $this->column_fields['recurringtype']!='--None--')
{
$recur_type = trim($this->column_fields['recurringtype']);
$recur_data = getrecurringObjValue();
- if(is_object($recur_data))
- $this->insertIntoRecurringTable($recur_data);
+
+ if(is_object($recur_data)){
+ $this->insertIntoRecurringTable($recur_data);
+ }
}
//Insert into vtiger_activity_remainder table
@@ -878,6 +888,9 @@ function get_calendarsforol($user_name)
function unlinkDependencies($module, $id) {
global $log;
+ $deleteFromBerlicrm_recurringreferences = 'DELETE FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $this->db->pquery($deleteFromBerlicrm_recurringreferences, array($id));
+
$sql = 'DELETE FROM vtiger_activity_reminder WHERE activity_id=?';
$this->db->pquery($sql, array($id));
diff --git a/modules/Calendar/RepeatEvents.php b/modules/Calendar/RepeatEvents.php
index 4fe3cc5e..e7900a44 100644
--- a/modules/Calendar/RepeatEvents.php
+++ b/modules/Calendar/RepeatEvents.php
@@ -140,8 +140,23 @@ static function repeat($focus, $recurObj) {
$interval = strtotime($focus->column_fields['due_date']) -
strtotime($focus->column_fields['date_start']);
+ $recurringtypeOfFirstEvent = $focus->column_fields['recurringtype'];
+ $idOfFirstEvent = $focus->column_fields['id'];
+
+ $newRecurringdates = array();
+ if (isset($_REQUEST['newRecurringdates']) && count($_REQUEST['newRecurringdates']) != 0 && $_REQUEST['mode'] == 'edit'){
+ $newRecurringdates = $_REQUEST['newRecurringdates'];
+ $recurObj->recurringdates = $_REQUEST['newRecurringdates'];
+ }
+
foreach ($recurObj->recurringdates as $index => $startDate) {
- if($index == 0 && $eventStartDate == $startDate) {
+ if($index == 0 ) {
+ $insert_ref_of_recurringevent =
+ 'INSERT INTO `berlicrm_recurringreferences`(`parentactivityid`, `activityid`, `startdate`, `enddate`)
+ VALUES ( ?, ?, ?, ?)';
+ $adb->pquery($insert_ref_of_recurringevent,
+ array($idOfFirstEvent, $idOfFirstEvent, $startDate, $recurObj->recurringdates[0] ));
+ //array($idOfFirstEvent,$idOfFirstEvent,$recurObj->recurringdates['date_start'],$focus->column_fields['due_date']));
continue;
}
$startDateTimestamp = strtotime($startDate);
@@ -162,13 +177,23 @@ static function repeat($focus, $recurObj) {
} else {
$new_focus->column_fields[$key] = $value;
}
+
+ $new_focus->column_fields['recurringtype'] = $recurringtypeOfFirstEvent;
+
}
if($numberOfRepeats > 10 && $index > 10) {
unset($new_focus->column_fields['sendnotification']);
}
+
$new_focus->save('Calendar');
$record = $new_focus->id;
-
+
+ $insert_ref_of_recurringevent =
+ 'INSERT INTO `berlicrm_recurringreferences`(`parentactivityid`, `activityid`, `startdate`, `enddate`)
+ VALUES ( ?, ?, ?, ?)';
+ $adb->pquery($insert_ref_of_recurringevent,
+ array($idOfFirstEvent, $record, $new_focus->column_fields['date_start'], $new_focus->column_fields['due_date']));
+
// add repeat event to contact record
if (isset($_REQUEST['contactidlist']) && $_REQUEST['contactidlist'] != '') {
//split the string and store in an array
diff --git a/modules/Calendar/actions/DragDropAjax.php b/modules/Calendar/actions/DragDropAjax.php
index 6d573e45..e97fd4c9 100644
--- a/modules/Calendar/actions/DragDropAjax.php
+++ b/modules/Calendar/actions/DragDropAjax.php
@@ -48,8 +48,10 @@ public function updateDeltaOnResize(Vtiger_Request $request){
$resultDateTime = $this->changeDateTime($oldDateTime,$secDelta);
$parts = explode(' ',$resultDateTime);
$record->set('due_date',$parts[0]);
- if(activitytype != 'Task')
+
+ if($activityType != 'Task'){
$record->set('time_end',$parts[1]);
+ }
$startDateTime[] = $record->get('date_start');
$startDateTime[] = $record->get('time_start');
@@ -103,8 +105,11 @@ public function updateDeltaOnDrop(Vtiger_Request $request){
$resultDateTime = $this->changeDateTime($oldEndDateTime,$secDelta);
$parts = explode(' ',$resultDateTime);
$record->set('due_date',$parts[0]);
- if(activitytype != 'Task')
- $record->set('time_end',$parts[1]);
+
+ if($activityType != 'Task'){
+ $record->set('time_end',$parts[1]);
+ }
+
$record->save();
$response->setResult($result);
diff --git a/modules/Calendar/models/Record.php b/modules/Calendar/models/Record.php
index 34631d5e..2ae357a8 100644
--- a/modules/Calendar/models/Record.php
+++ b/modules/Calendar/models/Record.php
@@ -125,12 +125,19 @@ public function getRecurringDetails() {
*/
public function getRecurringObject() {
$db = PearDatabase::getInstance();
- $query = 'SELECT vtiger_recurringevents.*, vtiger_activity.date_start, vtiger_activity.time_start, vtiger_activity.due_date, vtiger_activity.time_end FROM vtiger_recurringevents
- INNER JOIN vtiger_activity ON vtiger_activity.activityid = vtiger_recurringevents.activityid
- WHERE vtiger_recurringevents.activityid = ?';
+ $query = 'SELECT vtiger_recurringevents.*,
+ vtiger_activity.date_start,
+ vtiger_activity.time_start,
+ vtiger_activity.due_date,
+ vtiger_activity.time_end
+ FROM vtiger_recurringevents
+ INNER JOIN vtiger_activity
+ ON vtiger_activity.activityid = vtiger_recurringevents.activityid
+ WHERE vtiger_recurringevents.activityid = ?';
$result = $db->pquery($query, array($this->getId()));
if ($db->num_rows($result)) {
- return RecurringType::fromDBRequest($db->query_result_rowdata($result, 0));
+ $recurringTypeResult = RecurringType::fromDBRequest($db->query_result_rowdata($result, 0));
+ return $recurringTypeResult;
}
return false;
}
diff --git a/modules/Vtiger/actions/DeleteAjax.php b/modules/Vtiger/actions/DeleteAjax.php
index 6bf3c936..697fb30e 100644
--- a/modules/Vtiger/actions/DeleteAjax.php
+++ b/modules/Vtiger/actions/DeleteAjax.php
@@ -14,12 +14,118 @@ public function process(Vtiger_Request $request) {
$moduleName = $request->getModule();
$recordId = $request->get('record');
- $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
- $recordModel->delete();
+ $operation = $request->get('operation');
- $cvId = $request->get('viewname');
- $response = new Vtiger_Response();
- $response->setResult(array('viewname'=>$cvId, 'module'=>$moduleName));
- $response->emit();
+ if($operation == "checkRecurr"){
+
+ $idsReferencesArray = $this->findRecurringreferencesIDs($recordId);
+
+ $response = new Vtiger_Response();
+ $result = array('idsReferencesArray'=>$idsReferencesArray,'error'=>false);
+ $response->setResult($result);
+ $response->emit();
+ exit;
+
+ }else if($operation == "deleteevent"){
+
+ $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
+ $recordModel->delete();
+
+ $cvId = $request->get('viewname');
+ $response = new Vtiger_Response();
+ $response->setResult(array('viewname'=>$cvId, 'module'=>$moduleName));
+ $response->emit();
+ exit;
+
+ }else if($operation == "deleteManyEvents"){
+
+ $idsReferencesArray = $request->get('idsReferencesArray');
+ for($a = 0; $a < count($idsReferencesArray) ; $a++){
+ $recordModel = Vtiger_Record_Model::getInstanceById($idsReferencesArray[$a], $moduleName);
+ if( !empty($recordModel) ){
+ $recordModel->delete();
+ }
+
+ }
+ $cvId = $request->get('viewname');
+ $response = new Vtiger_Response();
+ $response->setResult(array('viewname'=>$cvId, 'module'=>$moduleName));
+ $response->emit();
+ exit;
+
+ }else{
+ // normally it cannot step here, but if $operation not given in request.
+ $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
+ $recordModel->delete();
+
+ $cvId = $request->get('viewname');
+ $response = new Vtiger_Response();
+ $response->setResult(array('viewname'=>$cvId, 'module'=>$moduleName));
+ $response->emit();
+ exit;
+
+ }
}
+
+
+
+ public function findRecurringreferencesIDs($idRef){
+ // if $idRef belong to RecurringEvent so this funktion find all IDs, that belong to it to.
+ global $adb;
+ $sqlRef1 = 'SELECT * FROM `berlicrm_recurringreferences` WHERE activityid = ?';
+ $resultRef1 = $adb->pquery($sqlRef1, array( $idRef ));
+ $rowsRef1 = $adb->num_rows($resultRef1);
+
+ $idsReferencesArray = array();
+ $parentactivityidMe ='';
+ //$rowsRef1, if it is not 0 so it can be only 1.
+ if($rowsRef1 > 0){
+ for($a = 0; $a < $rowsRef1 ; $a++){
+ $row1 = $adb->query_result_rowdata($resultRef1, $a);
+ $parentactivityidMe = $row1['parentactivityid'];
+ }
+ if($parentactivityidMe != ''){ // (here it muss have a value. )
+ $sqlRef2 = 'SELECT activityid FROM `berlicrm_recurringreferences` WHERE parentactivityid = ?';
+ $resultRef2 = $adb->pquery($sqlRef2, array( $parentactivityidMe ));
+ $rowsRef2 = $adb->num_rows($resultRef2);
+ // it can be nothing, one, or many here.
+ if($rowsRef2 > 0){
+ for($b = 0; $b < $rowsRef2 ; $b++){
+ $row2 = $adb->query_result_rowdata($resultRef2, $b);
+ $activityidMe = $row2['activityid'];
+ // add the belong IDs to the array.
+ $idsReferencesArray[] = $activityidMe;
+ }
+ }else{
+ // ERROR it can not step here, because if "parentactivityid" exist, it muss exist "activityid" to.
+ }
+ }else{
+ // ERROR it can not step here, because "parentactivityid" field are not found, but muss be in DB.
+ }
+ }else{
+ // here step it only if this $idRef not be in the table as 'activityid',
+ // but if we delete the first Event of the RecurringsEvents,
+ // it can be only 'parentactivityid' self. Vor another functionality it can help.
+ /*$sqlRef2 = 'SELECT activityid FROM `berlicrm_recurringreferences` WHERE parentactivityid = ?';
+ $resultRef2 = $adb->pquery($sqlRef2, array( $idRef ));
+ $rowsRef2 = $adb->num_rows($resultRef2);
+ if($rowsRef2 > 0){
+ for($b = 0; $b < $rowsRef2 ; $b++){
+ $row2 = $adb->query_result_rowdata($resultRef2, $b);
+ $activityidMe = $row2['activityid'];
+ // add the belong IDs to the array.
+ $idsReferencesArray[] = $activityidMe;
+ }
+ }else{
+ // if it is not a activityid or parentactivityid, so it can not be a Recurringevent, and this id belong to normal Event.
+ }*/
+ }
+ // if the array is empty, so it was a normal Event without recurring.
+ // doubles remove (it can not have a double values, but just in case)
+ $idsReferencesArray = array_unique($idsReferencesArray);
+ // from smallest to largest value. (normally it is allready sorted, but just im case)
+ sort($idsReferencesArray);
+ return $idsReferencesArray;
+ }
+
}
diff --git a/resources/helper.js b/resources/helper.js
index da93d116..318cae4e 100644
--- a/resources/helper.js
+++ b/resources/helper.js
@@ -139,13 +139,15 @@ jQuery.Class("Vtiger_Helper_Js",{
*/
showConfirmationBox : function(data){
var aDeferred = jQuery.Deferred();
- var bootBoxModal = bootbox.confirm(data['message'],app.vtranslate('LBL_NO'),app.vtranslate('LBL_YES'), function(result) {
- if(result){
- aDeferred.resolve();
- } else{
- aDeferred.reject();
+ var bootBoxModal = bootbox.confirm(data['message'],app.vtranslate('LBL_NO'),app.vtranslate('LBL_YES'),
+ function(result){
+ if(result){
+ aDeferred.resolve();
+ } else{
+ aDeferred.reject();
+ }
}
- });
+ );
bootBoxModal.on('hidden',function(e){
//In Case of multiple modal. like mass edit and quick create, if bootbox is shown and hidden , it will remove