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
|
<?php
/*************************************************
* ownCloud - Calendar Plugin *
* *
* (c) Copyright 2011 Georg Ehrke *
* author: Georg Ehrke *
* email: ownclouddev at georgswebsite dot de *
* homepage: ownclouddev.georgswebsite.de *
* manual: ownclouddev.georgswebsite.de/manual *
* License: GNU AFFERO GENERAL PUBLIC LICENSE *
* *
* <http://www.gnu.org/licenses/> *
* If you are not able to view the License, *
* <http://www.gnu.org/licenses/> *
* <http://ownclouddev.georgswebsite.de/license/> *
* please write to the Free Software Foundation. *
* Address: *
* 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
*************************************************/
require_once('../../../lib/base.php');
$l10n = new OC_L10N('calendar');
if(!OC_USER::isLoggedIn()) {
die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
}
//short variables
$title = $_POST["title"];
$location = $_POST["location"];
$cat = $_POST["cat"];
$cal = $_POST["cal"];
$cal = "1";
$allday = $_POST["allday"];
$from = $_POST["from"];
$fromtime = $_POST["fromtime"];
$to = $_POST["to"];
$totime = $_POST["totime"];
$description = $_POST["description"];
$repeat = $_POST["repeat"];
/*switch($_POST["repeatfreq"]){
case "DAILY":
$repeatfreq = "DAILY";
case "WEEKLY":
$repeatfreq = "WEEKLY";
case "WEEKDAY":
$repeatfreq = "DAILY;BYDAY=MO,TU,WE,TH,FR"; //load weeksdayss from userconfig when weekdays are choosable
case "":
$repeatfreq = "";
case "":
$repeatfreq = "";
case "":
$repeatfreq = "";
default:
$repeat = "false";
}*/
$repeat = "false";
//validate variables
$errnum = 0;
$errarr = array("title"=>"false", "cal"=>"false", "from"=>"false", "fromtime"=>"false", "to"=>"false", "totime"=>"false", "endbeforestart"=>"false");
if($title == ""){
$errarr["title"] = "true";
$errnum++;
}
$calendar = OC_Calendar_Calendar::findCalendar($cal);
if($calendar["userid"] != OC_User::getUser()){
$errarr["cal"] = "true";
$errnum++;
}
$fromday = substr($_POST["from"], 0, 2);
$frommonth = substr($_POST["from"], 3, 2);
$fromyear = substr($_POST["from"], 6, 4);
if(!checkdate($frommonth, $fromday, $fromyear)){
$errarr["from"] = "true";
$errnum++;
}
$fromhours = substr($_POST["fromtime"], 0, 2);
$fromminutes = substr($_POST["fromtime"], 3, 2);
if($fromhours > 24 || $fromminutes > 60 || $fromtime == ""){
$errarr["fromtime"] = "true";
$errnum++;
}
$today = substr($_POST["to"], 0, 2);
$tomonth = substr($_POST["to"], 3, 2);
$toyear = substr($_POST["to"], 6, 4);
if(!checkdate($tomonth, $today, $toyear)){
$errarr["to"] = "true";
$errnum++;
}
$tohours = substr($_POST["totime"], 0, 2);
$tominutes = substr($_POST["totime"], 3, 2);
if($tohours > 24 || $tominutes > 60 || $totime == ""){
$errarr["totime"] = "true";
$errnum++;
}
if($today < $fromday && $frommonth == $tomonth && $fromyear == $toyear){
$errarr["endbeforestart"] = "true";
$errnum++;
}
if($today == $fromday && $frommonth > $tomonth && $fromyear == $toyear){
$errarr["endbeforestart"] = "true";
$errnum++;
}
if($today == $fromday && $frommonth == $tomonth && $fromyear > $toyear){
$errarr["endbeforestart"] = "true";
$errnum++;
}
if($fromday == $today && $frommonth == $tomonth && $fromyear == $toyear){
if($tohours < $fromhours){
$errarr["endbeforestart"] = "true";
$errnum++;
}
if($tohours == $fromhours && $tominutes < $fromminutes){
$errarr["endbeforestart"] = "true";
$errnum++;
}
}
if($errnum != 0){
//show validate errors
$errarr["error"] = "true";
echo json_encode($errarr);
exit;
}else{
$data = "BEGIN:VCALENDAR\nPRODID:ownCloud Calendar\nVERSION:2.0\n";
if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == ""){
$timezone = "Europe/London";
}else{
$timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone");
}
$created = date("Ymd") . "T" . date("His");
$data .= "BEGIN:VEVENT\n";
$data .= "CREATED:" . $created . "\nLAST-MODIFIED:" . $created . "\nDTSTAMP:" . $created . "\n";
$data .= "SUMMARY:" . $title . "\n";
if($allday == "true"){
$start = $fromyear . $frommonth . $fromday;
$unixend = mktime(0,0,0,$tomonth, $today, $toyear) + (24 * 60 * 60);
$end = date("Ymd", $unixend);
$data .= "DTSTART;VALUE=DATE:" . $start . "\n";
$data .= "DTEND;VALUE=DATE:" . $end . "\n";
}else{
$start = $fromyear . $frommonth . $fromday . "T" . $fromhours . $fromminutes . "00";
$end = $toyear . $tomonth . $today . "T" . $tohours . $tominutes . "00";
$data .= "DTSTART;TZID=" . $timezone . ":" . $start . "\n";
$data .= "DTEND;TZID=" . $timezone . ":" . $end . "\n";
}
if($location != ""){
$data .= "LOCATION:" . $location . "\n";
}
if($description != ""){
$des = str_replace("\n","\\n", $description);
$data .= "DESCRIPTION:" . $des . "\n";
}
if($cat != "none"){
$data .= "CATEGORIES:" . $cat . "\n";
}
if($repeat == "true"){
$data .= "RRULE:" . $repeat . "\n";
}
$data .= "END:VEVENT\nEND:VCALENDAR";
echo $data;
$result = OC_Calendar_Calendar::addCalendarObject($cal, $data);
}
?>
|