-
Notifications
You must be signed in to change notification settings - Fork 1
/
changeeinfo-save.inc.php
185 lines (151 loc) · 4.77 KB
/
changeeinfo-save.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
if (!defined("ALLOWINCLUDES")) { exit; } // prohibits direct calling of include files
// ================================
// Save event into DB
// ================================
// Assign a begin/end timestamp (YYYY-MM-DD HH:MM:SS AMPM)
assemble_timestamp($event);
// Make a list containing all the resulting dates (in case there are any)
unset($repeatlist);
if ($repeat['mode']>=1 && $repeat['mode']<=2) { $repeatlist = producerepeatlist($event,$repeat); }
// Update an existing event (not a copy)
if (isset($eventid) && (!isset($copy) || $copy != 1)) {
// Before the event was non-reoccurring
if (empty($event['repeatid'])) {
// If the event is now reoccurring
if (isset($repeatlist) && sizeof($repeatlist) > 0) {
// Delete the old single event
deletefromevent($eventid);
// Insert recurrences
$event['repeatid'] = $eventid; // = getNewEventId();
insertintorepeat($event['repeatid'],$event,$repeat);
insertrecurrences($event['repeatid'],$event,$repeatlist);
}
// Otherwise, the event is still non-reoccurring.
else {
// Delete the event if is a recurring event but has no real recurrences
if ($repeat['mode']>=1 && $repeat['mode']<=2) {
deletefromevent($eventid);
}
// Otherwise, update the event in the DB
else {
$event['repeatid']="";
updateevent($eventid, $event);
}
}
}
// Before the event was reoccurring
else {
// The event still has recurrences
if (!empty($repeatlist)) {
// Delete the old events
repeatdeletefromevent($event['repeatid']);
// Insert the new recurrences
updaterepeat($event['repeatid'],$event,$repeat);
insertrecurrences($event['repeatid'],$event,$repeatlist);
}
// The event is now non-reoccurring.
else {
// Delete the event if it is a recurring event but has no real recurrences
// TODO: When does this apply?
if ($repeat['mode']>=1 && $repeat['mode']<=2) {
repeatdeletefromevent($event['repeatid']);
deletefromrepeat($event['repeatid']);
}
// Change the event to a non-reoccurring event.
else {
deletefromrepeat($event['repeatid']);
$oldrepeatid=$event['repeatid'];
$eventid=$event['repeatid']; // added to avoid "...-0001" in eventid if it's not repeating
$event['repeatid']="";
insertintoevent($eventid,$event);
// Delete all old recurring events but one
repeatdeletefromevent($oldrepeatid);
repeatdeletefromevent_public($oldrepeatid);
}
}
}
// Whatever the "admin" edits gets approved right away
if ($_SESSION['AUTH_ISCALENDARADMIN']) {
if (!empty($event['repeatid'])) {
repeatpublicizeevent($eventid,$event);
}
else {
publicizeevent($eventid,$event);
}
}
// Redirect the user back to the previous page.
if (strpos($httpreferer,"update.php")) {
redirect2URL("update.php?fbid=eupdatesuccess&fbparam=".urlencode($event['title']));
exit;
}
else {
$target = $httpreferer;
redirect2URL($target);
exit;
}
}
// Insert as a new event or copy of an existing event
else {
// Event is re-ocurring.
if (isset($repeatlist) && sizeof($repeatlist) > 0) {
// Create the new event ID.
$event['repeatid'] = getNewEventId();
// Insert in the DB.
insertintorepeat($event['repeatid'],$event,$repeat);
insertrecurrences($event['repeatid'],$event,$repeatlist);
$eventid = "";
}
// Event is not re-ocurring.
else {
$event['repeatid'] = "";
// Create the new event ID.
$eventid = getNewEventId();
// Insert into the DB.
insertintoevent($eventid,$event);
}
$event['id'] = $eventid;
// Whatever the "admin" edits gets approved right away
if ($_SESSION['AUTH_ISCALENDARADMIN']) {
if (!empty($event['repeatid'])) { repeatpublicizeevent($eventid,$event); }
else { publicizeevent($eventid,$event); }
}
// Redirect the user back to the previous page.
if (strpos($httpreferer,"update.php")) {
redirect2URL("update.php?fbid=eaddsuccess&fbparam=".urlencode($event['title']));
exit;
}
else {
$target = $httpreferer;
redirect2URL($target);
exit;
}
}
function insertrecurrences($repeatid,&$event,&$repeatlist) {
$i = 0;
while ($dateJD = each($repeatlist)) {
$i++;
$date = Decode_Date_US(JDToJulian($dateJD['value']));
$event['timebegin_month'] = $date['month'];
$event['timebegin_day'] = $date['day'];
$event['timebegin_year'] = $date['year'];
$event['timeend_month'] = $date['month'];
$event['timeend_day'] = $date['day'];
$event['timeend_year'] = $date['year'];
assemble_timestamp($event);
// insert event
$eventidext = "";
if ($i<1000) {
if ($i<100) {
if ($i<10) {
$eventidext .= "0";
}
$eventidext .= "0";
}
$eventidext .= "0";
}
$eventidext .= $i;
insertintoevent($repeatid."-".$eventidext,$event);
} // end: while ($dateJD = each($repeatlist))
} // end: function insertrecurrences
?>