00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00038 class Database
00039 {
00040
00041
00047 var $dlI = false;
00048
00049
00053 function database($DP_dlI)
00054 {
00055 $this->dlI = $DP_dlI;
00056 $this->alluser_id = ALLUSERID;
00057 }
00058
00059
00064 function disconnect()
00065 {
00066 mysql_close($this->dlI);
00067 }
00068
00069
00074 function isConnected()
00075 {
00076 if (isset($this->dlI))
00077 {
00078 return true;
00079 }
00080 else
00081 {
00082 return false;
00083 }
00084 }
00085
00086
00091 function dbError()
00092 {
00093 return mysql_error();
00094 }
00095
00096
00104 function applyChangedDate ($a_user_id, $a_date_id, $a_timestamp)
00105 {
00106 if (isset($this->dlI) && isset($a_user_id) && isset($a_date_id) && isset($a_timestamp))
00107 {
00108 $result = mysql_query ("SELECT DISTINCT status FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00109 $status = mysql_fetch_array($result);
00110 mysql_free_result ($result);
00111 if ($status[0] == '0')
00112 {
00113 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00114 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00115 if (mysql_errno ($this->dlI) == 0) return true;
00116 }
00117 elseif ($status[0] == '1')
00118 {
00119 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00120 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00121 if (mysql_errno ($this->dlI) == 0) return true;
00122 }
00123 else
00124 {
00125 return true;
00126 }
00127 }
00128 else
00129 {
00130 return false;
00131 }
00132 }
00133
00134
00142 function discardChangedDate ($a_user_id, $a_date_id, $a_timestamp)
00143 {
00144 if (isset($this->dlI) && isset($a_user_id) && isset($a_date_id) && isset($a_timestamp))
00145 {
00146 $result = mysql_query ("SELECT DISTINCT status FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00147 $status = mysql_fetch_array($result);
00148 mysql_free_result ($result);
00149 if ($status[0] == '0')
00150 {
00151 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00152 if (mysql_errno ($this->dlI) == 0) return true;
00153 }
00154 elseif ($status[0] == '1')
00155 {
00156 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00157 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_neg_dates (id, date_id, user_id, timestamp) VALUES ('', '".$a_date_id."', '".$a_user_id."', '".$a_timestamp."')", $this->dlI);
00158 if (mysql_errno ($this->dlI) == 0) return true;
00159 }
00160 elseif ($status[0] == '2')
00161 {
00162 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id = '".$a_user_id."' AND date_id = '".$a_date_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00163 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_neg_dates (id, date_id, user_id, timestamp) VALUES ('', '".$a_date_id."', '".$a_user_id."', '".$a_timestamp."')", $this->dlI);
00164 $result = mysql_query ("SELECT DISTINCT group_id FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00165 $group_id = mysql_fetch_array($result);
00166 mysql_free_result ($result);
00167 $result = mysql_query ("SELECT DISTINCT count(id) as numOfNegDates FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND timestamp = '0'", $this->dlI);
00168 $numOfNegDates = mysql_fetch_array($result);
00169 mysql_free_result ($result);
00170 if ($numOfNegDates[0] >= ilCalInterface::getNumOfMembers($group_id[0]))
00171 {
00172 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00173 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."'", $this->dlI);
00174 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."'", $this->dlI);
00175 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id = '".$a_date_id."'", $this->dlI);
00176 }
00177
00178 return true;
00179 }
00180 else
00181 {
00182 return false;
00183 }
00184 }
00185 else
00186 {
00187 return false;
00188 }
00189 }
00190
00191
00198 function getChangedDates ($a_user_id, $a_status)
00199 {
00200 if (isset($this->dlI) && isset($a_user_id) && isset($a_status))
00201 {
00202 $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.shorttext, dp_dates.group_id, dp_dates.rotation, dp_changed_dates.timestamp FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_changed_dates WHERE dp_changed_dates.user_id = '".$a_user_id."' AND dp_changed_dates.status = '".$a_status."' AND dp_changed_dates.date_id = dp_dates.id ORDER BY dp_dates.begin, dp_dates.end DESC", $this->dlI);
00203 $dp_dates = false;
00204 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00205 {
00206 $dp_dates[$i] = $row;
00207 }
00208 mysql_free_result ($result);
00209 return $dp_dates;
00210 }
00211 else
00212 {
00213 return false;
00214 }
00215 }
00216
00217
00226 function getDates ($a_user_id, $a_begin, $a_end, $a_keyword_ids)
00227 {
00228 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_user_id) && isset($a_begin) && isset($a_end) && isset($a_keyword_ids))
00229 {
00230 $result = mysql_query ("SELECT DISTINCT dp_dates.id FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_neg_dates WHERE dp_neg_dates.user_id = '".$a_user_id."' AND dp_neg_dates.date_id = dp_dates.id AND dp_neg_dates.timestamp = '0'", $this->dlI);
00231 $dp_neg_dates = false;
00232 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00233 {
00234 $dp_neg_dates[$i] = $row[0];
00235 }
00236 mysql_free_result ($result);
00237 $group_ids = ilCalInterface::getMemberGroups($a_user_id);
00238
00239 if ($group_ids == false) $group_ids = array('-2');
00240 if ($dp_neg_dates == false) $dp_neg_dates = array('-2');
00241 if ($a_keyword_ids[0] == '*') $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end > '".$a_end."') AND dp_dates.rotation = '0' AND (dp_dates.end - dp_dates.begin != 86399) ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00242 else $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end > '".$a_end."') AND dp_dates.rotation = '0' AND (dp_dates.end - dp_dates.begin != 86399) AND dp_keywords.keyword_id IN ('!�$%&/=', '".implode("','",$a_keyword_ids)."') AND dp_keywords.date_id = dp_dates.id ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00243 $dp_dates = false;
00244 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00245 {
00246 $dp_dates[$i] = $row;
00247 }
00248 mysql_free_result ($result);
00249 return $dp_dates;
00250 }
00251 else
00252 {
00253 return false;
00254 }
00255 }
00256
00257
00266 function getFullDayDates ($a_user_id, $a_begin, $a_end, $a_keyword_ids)
00267 {
00268 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_user_id) && isset($a_begin) && isset($a_end) && isset($a_keyword_ids))
00269 {
00270 $result = mysql_query ("SELECT DISTINCT dp_dates.id FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_neg_dates WHERE dp_neg_dates.user_id = '".$a_user_id."' AND dp_neg_dates.date_id = dp_dates.id AND dp_neg_dates.timestamp = '0'", $this->dlI);
00271 $dp_neg_dates = false;
00272 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00273 {
00274 $dp_neg_dates[$i] = $row[0];
00275 }
00276 mysql_free_result ($result);
00277 $group_ids = ilCalInterface::getMemberGroups($a_user_id);
00278 if ($group_ids == false) $group_ids = array('-2');
00279 if ($dp_neg_dates == false) $dp_neg_dates = array('-2');
00280 if ($a_keyword_ids[0] == '*') $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end > '".$a_end."') AND dp_dates.rotation = '0' AND (dp_dates.end - dp_dates.begin = 86399) ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00281 else $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end > '".$a_end."') AND dp_dates.rotation = '0' AND (dp_dates.end - dp_dates.begin = 86399) AND dp_keywords.keyword_id IN ('!�$%&/=', '".implode("','",$a_keyword_ids)."') AND dp_keywords.date_id = dp_dates.id ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00282 $dp_dates = false;
00283 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00284 {
00285 $dp_dates[$i] = $row;
00286 }
00287 mysql_free_result ($result);
00288 return $dp_dates;
00289 }
00290 else
00291 {
00292 return false;
00293 }
00294 }
00295
00304 function getRotationDates ($a_user_id, $a_begin, $a_end, $a_keyword_ids)
00305 {
00306 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_user_id) && isset($a_begin) && isset($a_end) && isset($a_keyword_ids))
00307 {
00308 $result = mysql_query ("SELECT DISTINCT dp_dates.id FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_neg_dates WHERE dp_neg_dates.user_id = '".$a_user_id."' AND dp_neg_dates.timestamp = '0' AND dp_neg_dates.date_id = dp_dates.id", $this->dlI);
00309 $dp_neg_dates = false;
00310 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00311 {
00312 $dp_neg_dates[$i] = $row[0];
00313 }
00314 mysql_free_result ($result);
00315 $group_ids = ilCalInterface::getMemberGroups($a_user_id);
00316 if ($group_ids == false) $group_ids = array('-2');
00317 if ($dp_neg_dates == false) $dp_neg_dates = array('-2');
00318 if ($a_keyword_ids[0] == '*') $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end_rotation >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end_rotation = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end_rotation > '".$a_end."') AND dp_dates.rotation != '0' AND (dp_dates.end - dp_dates.begin != 86399) ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00319 else $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end_rotation >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end_rotation = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end_rotation > '".$a_end."') AND dp_dates.rotation != '0' AND (dp_dates.end - dp_dates.begin != 86399) AND dp_keywords.keyword_id IN ('!�$%&/=', '".implode("','",$a_keyword_ids)."') AND dp_keywords.date_id = dp_dates.id ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00320 $dp_dates = false;
00321 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00322 {
00323 $dp_dates[$i] = $row;
00324 }
00325 mysql_free_result ($result);
00326 return $dp_dates;
00327 }
00328 else
00329 {
00330 return false;
00331 }
00332 }
00333
00342 function getFullDayRotationDates ($a_user_id, $a_begin, $a_end, $a_keyword_ids)
00343 {
00344 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_user_id) && isset($a_begin) && isset($a_end) && isset($a_keyword_ids))
00345 {
00346 $result = mysql_query ("SELECT DISTINCT dp_dates.id FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_neg_dates WHERE dp_neg_dates.user_id = '".$a_user_id."' AND dp_neg_dates.timestamp = '0' AND dp_neg_dates.date_id = dp_dates.id", $this->dlI);
00347 $dp_neg_dates = false;
00348 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00349 {
00350 $dp_neg_dates[$i] = $row[0];
00351 }
00352 mysql_free_result ($result);
00353 $group_ids = ilCalInterface::getMemberGroups($a_user_id);
00354 if ($group_ids == false) $group_ids = array('-2');
00355 if ($dp_neg_dates == false) $dp_neg_dates = array('-2');
00356 if ($a_keyword_ids[0] == '*') $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end_rotation >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end_rotation = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end_rotation > '".$a_end."') AND dp_dates.rotation != '0' AND (dp_dates.end - dp_dates.begin = 86399) ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00357 else $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates, ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE (dp_dates.group_id IN ('".$this->alluser_id."','".implode("','",$group_ids)."') OR dp_dates.user_id = '".$a_user_id."') AND dp_dates.id NOT IN ('-2','".implode("','",$dp_neg_dates)."') AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end_rotation >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end_rotation = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end_rotation > '".$a_end."') AND dp_dates.rotation != '0' AND (dp_dates.end - dp_dates.begin = 86399) AND dp_keywords.keyword_id IN ('!�$%&/=', '".implode("','",$a_keyword_ids)."') AND dp_keywords.date_id = dp_dates.id ORDER BY dp_dates.begin, dp_dates.end DESC, dp_dates.changed, dp_dates.created", $this->dlI);
00358 $dp_dates = false;
00359 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00360 {
00361 $dp_dates[$i] = $row;
00362 }
00363 mysql_free_result ($result);
00364 return $dp_dates;
00365 }
00366 else
00367 {
00368 return false;
00369 }
00370 }
00371
00372
00379 function getDate ($a_date_id, $a_user_id)
00380 {
00381 if (isset($this->dlI) && isset($a_date_id) && isset($a_user_id))
00382 {
00383 $result = mysql_query ("SELECT DISTINCT id as date_id, begin, end, group_id, user_id, created, changed, rotation, shorttext, text, end_rotation FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00384 $date = false;
00385 $date = mysql_fetch_array($result);
00386 mysql_free_result ($result);
00387 if ($date)
00388 {
00389 $result = mysql_query ("SELECT DISTINCT dp_keyword.id as keyword_id, dp_keyword.keyword FROM ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE dp_keywords.date_id = '".$a_date_id."' AND dp_keyword.user_id = '".$a_user_id."' AND dp_keyword.id = dp_keywords.keyword_id", $this->dlI);
00390 $keyword_id = false;
00391 $keyword_id = mysql_fetch_array($result);
00392 mysql_free_result ($result);
00393 if ($keyword_id)
00394 {
00395 $date = array_merge ($date, $keyword_id);
00396 }
00397 return $date;
00398 }
00399 else
00400 {
00401 return false;
00402 }
00403 }
00404 else
00405 {
00406 return false;
00407 }
00408 }
00409
00410
00418 function getNegRotationDates ($a_user_id, $a_begin, $a_end)
00419 {
00420 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_user_id) && isset($a_begin) && isset($a_end))
00421 {
00422 $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation, dp_neg_dates.timestamp FROM ".$this->dbase_cscw.".dp_neg_dates, ".$this->dbase_cscw.".dp_dates WHERE dp_neg_dates.user_id = '".$a_user_id."' AND dp_neg_dates.timestamp != '0' AND (dp_dates.id = dp_neg_dates.date_id AND dp_dates.rotation != '0') AND dp_neg_dates.timestamp between '".$a_begin."' AND '".$a_end."' ORDER BY dp_neg_dates.timestamp", $this->dlI);
00423 $dp_neg_dates = false;
00424 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00425 {
00426 $dp_neg_dates[$i] = $row;
00427 }
00428 mysql_free_result ($result);
00429 return $dp_neg_dates;
00430 }
00431 else
00432 {
00433 return false;
00434 }
00435 }
00436
00437
00443 function getUserGroups ($a_user_id)
00444 {
00445 if (isset($this->dlI) && isset($a_user_id))
00446 {
00447 $groups = ilCalInterface::getUserGroups($a_user_id);
00448 return $groups;
00449 }
00450 else
00451 {
00452 return false;
00453 }
00454 }
00455
00456
00463 function addKeyword ($a_user_id, $a_keyword)
00464 {
00465 if (isset($this->dlI) && isset($a_user_id) && isset($a_keyword))
00466 {
00467 $result = mysql_query ("SELECT id FROM ".$this->dbase_cscw.".dp_keyword WHERE user_id = '".$a_user_id."' AND keyword = '".$a_keyword."'", $this->dlI);
00468 if (mysql_fetch_array($result) == false)
00469 {
00470 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_keyword (id, user_id, keyword) VALUES ('', '".$a_user_id."', '".$a_keyword."')", $this->dlI);
00471 if (mysql_errno ($this->dlI) == 0) return true;
00472 else return false;
00473 }
00474 else
00475 {
00476 return true;
00477 }
00478 mysql_free_result ($result);
00479 }
00480 else
00481 {
00482 return false;
00483 }
00484 }
00485
00486
00492 function getKeywords ($a_user_id)
00493 {
00494 if (isset($this->dlI) && isset($a_user_id))
00495 {
00496 $result = mysql_query ("SELECT DISTINCT id as keyword_id, keyword FROM ".$this->dbase_cscw.".dp_keyword WHERE user_id = '".$a_user_id."' ORDER BY keyword", $this->dlI);
00497 $dp_keywords = false;
00498 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00499 {
00500 $dp_keywords[$i] = $row;
00501 }
00502 return $dp_keywords;
00503 mysql_free_result ($result);
00504 }
00505 else
00506 {
00507 return false;
00508 }
00509 }
00510
00511
00517 function delKeyword ($a_keyword_id)
00518 {
00519 if (isset($this->dlI) && isset($a_keyword_id))
00520 {
00521 $return = false;
00522 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keyword WHERE id = '".$a_keyword_id."'", $this->dlI);
00523 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE keyword_id = '".$a_keyword_id."'", $this->dlI);
00524 if (mysql_errno ($this->dlI) == 0) $return = true;
00525 }
00526 else
00527 {
00528 $return = false;
00529 }
00530 return $return;
00531 }
00532
00533
00540 function updateKeyword ($a_keyword_id, $a_keyword)
00541 {
00542 if (isset($this->dlI) && isset($a_keyword_id) && isset($a_keyword))
00543 {
00544 mysql_query ("UPDATE ".$this->dbase_cscw.".dp_keyword SET keyword = '".$a_keyword."' WHERE id = '".$a_keyword_id."'", $this->dlI);
00545 if (mysql_errno ($this->dlI) == 0) return true;
00546 else
00547 {
00548 return false;
00549 }
00550 }
00551 else
00552 {
00553 return false;
00554 }
00555 }
00556
00557
00565 function getGroupDates ($a_group_id, $a_begin, $a_end)
00566 {
00567 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_group_id) && isset($a_begin) && isset($a_end))
00568 {
00569 $user_ids = ilCalInterface::getOtherMembers($a_group_id, -1);
00570 $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id = '".$a_group_id."' OR dp_dates.user_id IN ('".$this->alluser_id."','".implode("','",$user_ids)."')) AND rotation = '0' AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end = '".$a_begin."') ORDER BY begin, end DESC", $this->dlI);
00571 $dp_dates = false;
00572
00573 echo(mysql_error());
00574 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00575 {
00576 $dp_dates[$i] = $row;
00577 }
00578 mysql_free_result ($result);
00579
00580 return $dp_dates;
00581 }
00582 else
00583 {
00584 return false;
00585 }
00586 }
00587
00595 function getGroupRotationDates ($a_group_id, $a_begin, $a_end)
00596 {
00597 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_group_id) && isset($a_begin) && isset($a_end))
00598 {
00599 $user_ids = ilCalInterface::getOtherMembers($a_group_id, -1);
00600 $result = mysql_query ("SELECT DISTINCT dp_dates.id as date_id, dp_dates.begin, dp_dates.end, dp_dates.group_id, dp_dates.user_id, dp_dates.shorttext, dp_dates.text, dp_dates.rotation, dp_dates.end_rotation FROM ".$this->dbase_cscw.".dp_dates WHERE (dp_dates.group_id = '".$a_group_id."' OR dp_dates.user_id IN ('".$this->alluser_id."','".implode("','",$user_ids)."')) AND (dp_dates.begin <= '".$a_end."' AND dp_dates.end_rotation >= '".$a_begin."') AND NOT (dp_dates.begin < '".$a_begin."' AND dp_dates.end_rotation = '".$a_begin."') AND NOT (dp_dates.begin = '".$a_end."' AND dp_dates.end_rotation > '".$a_end."') AND dp_dates.rotation != '0' ORDER BY begin, end DESC", $this->dlI);
00601
00602 $dp_dates = false;
00603 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00604 {
00605 $dp_dates[$i] = $row;
00606 }
00607 mysql_free_result ($result);
00608 return $dp_dates;
00609 }
00610 else
00611 {
00612 return false;
00613 }
00614 }
00615
00621 function getGroupName ($a_group_id)
00622 {
00623 if (isset($this->dlI) && isset($a_group_id))
00624 {
00625 $groupname = ilCalInterface::getGroupName($a_group_id);
00626 return $groupname;
00627 }
00628 else
00629 {
00630 return false;
00631 }
00632 }
00633
00634
00642 function addStartEnd ($a_user_id, $a_start, $a_end)
00643 {
00644 if (isset($this->dlI) && isset($a_user_id) && isset($a_start) && isset($a_end))
00645 {
00646 $result = mysql_query ("SELECT id FROM ".$this->dbase_cscw.".dp_properties WHERE user_id = '".$a_user_id."' AND dv_starttime = '".$a_start."' AND dv_endtime = '".$a_end."'", $this->dlI);
00647 if (mysql_fetch_array($result) == false)
00648 {
00649 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_properties (id, user_id, dv_starttime, dv_endtime) VALUES ('', '".$a_user_id."', '".$a_start."', '".$a_end."')", $this->dlI);
00650 if (mysql_errno ($this->dlI) == 0) return true;
00651 else return false;
00652 }
00653 else
00654 {
00655 return true;
00656 }
00657 mysql_free_result ($result);
00658 }
00659 else
00660 {
00661 return false;
00662 }
00663 }
00664
00665
00671 function getStartEnd ($a_user_id)
00672 {
00673 if (isset($this->dlI) && isset($a_user_id))
00674 {
00675 $result = mysql_query ("SELECT DISTINCT id, dv_starttime, dv_endtime FROM ".$this->dbase_cscw.".dp_properties WHERE user_id = '".$a_user_id."'", $this->dlI);
00676 if ($times = mysql_fetch_array($result)) return $times;
00677 else return false;
00678 mysql_free_result ($result);
00679 }
00680 else
00681 {
00682 return false;
00683 }
00684 }
00685
00686
00694 function updateStartEnd ($a_properties_id, $a_start, $a_end)
00695 {
00696 if (isset($this->dlI) && isset($a_properties_id) && isset($a_start) && isset($a_end))
00697 {
00698 mysql_query ("UPDATE ".$this->dbase_cscw.".dp_properties SET dv_starttime = '".$a_start."', dv_endtime = '".$a_end."' WHERE id = '".$a_properties_id."'", $this->dlI);
00699 if (mysql_errno ($this->dlI) == 0) return true;
00700 else
00701 {
00702 return false;
00703 }
00704 }
00705 else
00706 {
00707 return false;
00708 }
00709 }
00710
00711
00725 function addDate ($a_begin, $a_end, $a_group_id, $a_user_id, $a_created, $a_rotation, $a_end_rotation, $a_shorttext, $a_text, $a_keyword_id)
00726 {
00727 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_begin) && isset($a_end) && isset($a_group_id) && isset($a_user_id) && isset($a_created) && isset($a_rotation) && isset($a_end_rotation) && isset($a_shorttext) && isset($a_keyword_id))
00728 {
00729 $result = mysql_query ("SELECT begin FROM ".$this->dbase_cscw.".dp_dates WHERE begin = '".$a_begin."' AND end = '".$a_end."' AND group_id = '".$a_group_id."' AND user_id = '".$a_user_id."' AND rotation = '".$a_rotation."' AND shorttext = '".$a_shorttext."' AND text = '".$a_text."' AND end_rotation = '".$a_end_rotation."'", $this->dlI);
00730 $test = mysql_fetch_array($result);
00731 mysql_free_result ($result);
00732 if ($a_begin != $test[0])
00733 {
00734 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_dates (id, begin, end, group_id, user_id, created, changed, rotation, shorttext, text, end_rotation) VALUES ('', '".$a_begin."', '".$a_end."' , '".$a_group_id."', '".$a_user_id."', '".$a_created."' , '".$a_created."' , '".$a_rotation."' , '".$a_shorttext."', '".$a_text."', '".$a_end_rotation."')", $this->dlI);
00735 if (mysql_errno ($this->dlI) == 0) $return = 0;
00736 $result = mysql_query ("SELECT id FROM ".$this->dbase_cscw.".dp_dates WHERE begin = '".$a_begin."' AND end = '".$a_end."' AND group_id = '".$a_group_id."' AND user_id = '".$a_user_id."' AND rotation = '".$a_rotation."' AND shorttext = '".$a_shorttext."' AND text = '".$a_text."' AND end_rotation = '".$a_end_rotation."'", $this->dlI);
00737 $date_id = mysql_fetch_array($result);
00738 mysql_free_result ($result);
00739 if ($a_keyword_id != '0') mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_keywords (id, date_id, keyword_id) VALUES ('', '".$date_id[0]."', '".$a_keyword_id."')", $this->dlI);
00740 if ($a_group_id != '0')
00741 {
00742 $users = false;
00743 $users = ilCalInterface::getOtherMembers($a_group_id, $a_user_id);
00744 if($users) {
00745 for ($i = 0; $i < count($users); $i++)
00746 {
00747 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_changed_dates (id, user_id, date_id, status, timestamp) VALUES ('', '".$users[$i]."', '".$date_id[0]."', '0', '0')", $this->dlI);
00748 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_neg_dates (id, date_id, user_id, timestamp) VALUES ('', '".$date_id[0]."', '".$users[$i]."', '0')", $this->dlI);
00749 }
00750 }
00751 }
00752 }
00753 else $return = 1;
00754 }
00755 else $return = 2;
00756 return $return;
00757 }
00758
00759
00773 function updateDate ($a_date_id, $a_begin, $a_end, $a_user_id, $a_changed, $a_rotation, $a_end_rotation, $a_shorttext, $a_text)
00774 {
00775 if (isset($this->dlI) && $a_begin <= $a_end && isset($a_date_id) && isset($a_begin) && isset($a_end) && isset($a_user_id) && isset($a_changed) && isset($a_rotation) && isset($a_end_rotation) && isset($a_shorttext))
00776 {
00777 $return = false;
00778 $result = mysql_query ("SELECT user_ID, group_ID, begin, end, rotation, end_rotation, shorttext, text FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00779 $date = mysql_fetch_row($result);
00780 mysql_free_result ($result);
00781 if ($a_user_id == $date[0] && ($a_begin != $date[2] || $a_end != $date[3] || $a_rotation != $date[4] || $a_end_rotation != $date[5] || $a_shorttext != $date[6] || $a_text != $date[7]))
00782 {
00783 mysql_query ("UPDATE ".$this->dbase_cscw.".dp_dates SET begin = '".$a_begin."', end = '".$a_end."', changed = '".$a_changed."', rotation = '".$a_rotation."', shorttext = '".$a_shorttext."', text = '".$a_text."', end_rotation = '".$a_end_rotation."' WHERE id = '".$a_date_id."'", $this->dlI);
00784 if (mysql_errno ($this->dlI) == 0) $return = true;
00785 if ($date[1] != '0')
00786 {
00787 $users = false;
00788 $users = ilCalInterface::getOtherMembers($date[1], $a_user_id);
00789 if($users) {
00790 for ($i = 0; $i < count($users); $i++)
00791 {
00792 $test = false;
00793 $result2 = mysql_query ("SELECT DISTINCT date_id FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."' AND timestamp = '0' AND status = '0' ", $this->dlI);
00794 $test = mysql_fetch_array($result2);
00795 mysql_free_result ($result2);
00796 if ($test[0] != $a_date_id)
00797 {
00798 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."' AND timestamp = '0' AND status = '1'", $this->dlI);
00799 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_changed_dates (id, user_id, date_id, status, timestamp) VALUES ('', '".$users[$i]."', '".$a_date_id."', '1', '0')", $this->dlI);
00800 }
00801 }
00802 }
00803 }
00804 if ($a_rotation != $date[4])
00805 {
00806 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND timestamp != '0'", $this->dlI);
00807 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND timestamp != '0'", $this->dlI);
00808 }
00809 }
00810 else
00811 {
00812 $return = false;
00813 }
00814 }
00815 else
00816 {
00817 $return = false;
00818 }
00819 return $return;
00820 }
00821
00822
00830 function delDate ($a_date_id, $a_user_id, $a_timestamp)
00831 {
00832 if (isset($this->dlI) && isset($a_date_id) && isset($a_user_id) && isset($a_timestamp))
00833 {
00834 $date = false;
00835 $result = mysql_query ("SELECT group_id, user_id, rotation FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00836 $date = mysql_fetch_row($result);
00837 mysql_free_result ($result);
00838 if ($date[0] == 0 && $a_user_id == $date[1])
00839 {
00840 if ($a_timestamp != 0 && $date[2] != 0)
00841 {
00842 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_neg_dates (id, date_id, user_id, timestamp) VALUES ('', '".$a_date_id."', '".$a_user_id."' , '".$a_timestamp."')", $this->dlI);
00843 }
00844 else
00845 {
00846 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00847 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."'", $this->dlI);
00848 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id = '".$a_date_id."'", $this->dlI);
00849 }
00850 $return = true;
00851 }
00852 elseif ($date[0] != 0)
00853 {
00854 if ($a_timestamp == 0)
00855 {
00856 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$a_user_id."'", $this->dlI);
00857 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$a_user_id."'", $this->dlI);
00858 $result = mysql_query ("SELECT DISTINCT dp_keywords.keyword_id FROM ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE dp_keywords.date_id = '".$a_date_id."' AND dp_keyword.id = dp_keywords.keyword_id AND dp_keyword.user_id = '".$a_user_id."'", $this->dlI);
00859 $keyword_id = mysql_fetch_array($result);
00860 mysql_free_result ($result);
00861 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id = '".$a_date_id."' AND keyword_id = '".$keyword_id[0]."'", $this->dlI);
00862 }
00863 else
00864 {
00865 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$a_user_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00866 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$a_user_id."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00867 }
00868 mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_neg_dates (id, date_id, user_id, timestamp) VALUES ('', '".$a_date_id."', '".$a_user_id."' , '".$a_timestamp."')", $this->dlI);
00869
00870 if ($a_user_id == $date[1])
00871 {
00872
00873 $users = false;
00874 $users = ilCalInterface::getOtherMembers($date[0], $a_user_id);
00875 if($users) {
00876 for ($i = 0; $i < count($users); $i++)
00877 {
00878
00879 $test = false;
00880 $test2 = false;
00881 $result = mysql_query ("SELECT DISTINCT date_id FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."'", $this->dlI);
00882 $test = mysql_fetch_array($result);
00883 mysql_free_result ($result);
00884 $result = mysql_query ("SELECT DISTINCT date_id, status FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."'", $this->dlI);
00885 $test2 = mysql_fetch_row($result);
00886 mysql_free_result ($result);
00887 if ($a_timestamp == 0)
00888 {
00889 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."'", $this->dlI);
00890 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."'", $this->dlI);
00891 }
00892 else
00893 {
00894 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00895 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND user_id = '".$users[$i]."' AND timestamp = '".$a_timestamp."'", $this->dlI);
00896 }
00897
00898 if ($test2[1] != "0") {mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_changed_dates (id, user_id, date_id, status, timestamp) VALUES ('', '".$users[$i]."', '".$a_date_id."' , '2', '".$a_timestamp."')", $this->dlI);
00899 }
00900 }
00901 }
00902 }
00903 $result = mysql_query ("SELECT DISTINCT count(id) as numOfNegDates FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."' AND timestamp = '0'", $this->dlI);
00904 $numOfNegDates = mysql_fetch_array($result);
00905 mysql_free_result ($result);
00906
00907 if ($numOfNegDates[0] >= ilCalInterface::getNumOfMembers($date[0]))
00908
00909 {
00910 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_dates WHERE id = '".$a_date_id."'", $this->dlI);
00911 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id = '".$a_date_id."'", $this->dlI);
00912 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id = '".$a_date_id."'", $this->dlI);
00913 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id = '".$a_date_id."'", $this->dlI);
00914 }
00915 $return = true;
00916 }
00917 else
00918 {
00919 $return = false;
00920 }
00921 }
00922 else
00923 {
00924 $return = false;
00925 }
00926 return $return;
00927 }
00928
00929
00937 function updateKeyword2Date ($a_user_id, $a_date_id, $a_keyword_id)
00938 {
00939 if (isset($this->dlI) && isset($a_user_id) && isset($a_date_id) && isset($a_keyword_id))
00940 {
00941 $keyword_id_old = false;
00942 $result = mysql_query ("SELECT DISTINCT dp_keywords.keyword_id FROM ".$this->dbase_cscw.".dp_keyword, ".$this->dbase_cscw.".dp_keywords WHERE dp_keywords.date_id = '".$a_date_id."' AND dp_keyword.id = dp_keywords.keyword_id AND dp_keyword.user_id = '".$a_user_id."'", $this->dlI);
00943 $keyword_id_old = mysql_fetch_array($result);
00944 mysql_free_result ($result);
00945 if ($a_keyword_id != $keyword_id_old[0])
00946 {
00947 if ($a_keyword_id == 0) mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id = '".$a_date_id."' AND keyword_id = '".$keyword_id_old[0]."'", $this->dlI);
00948 elseif ($keyword_id_old[0] == false) mysql_query ("INSERT INTO ".$this->dbase_cscw.".dp_keywords (id, date_id, keyword_id) VALUES ('', '".$a_date_id."', '".$a_keyword_id."')", $this->dlI);
00949 else mysql_query ("UPDATE ".$this->dbase_cscw.".dp_keywords SET keyword_id = '".$a_keyword_id."' WHERE date_id = '".$a_date_id."' AND keyword_id = '".$keyword_id_old[0]."'", $this->dlI);
00950 }
00951 return true;
00952 }
00953 else
00954 {
00955 return false;
00956 }
00957 }
00958
00959
00964 function cleanDatabase ()
00965 {
00966 if (isset($this->dlI))
00967 {
00968 $groups = ilCalInterface::getGroups();
00969 $ago = strtotime ("-6 month");
00970 $tobedeleted = false;
00971
00972 $result = mysql_query ("SELECT DISTINCT id FROM ".$this->dbase_cscw.".dp_dates WHERE rotation != '0' AND end_rotation <= '".$ago."'", $this->dlI);
00973 for ($i = 0; $row = mysql_fetch_array($result); $i++)
00974 {
00975 $tobedeleted[$i] = $row[0];
00976 }
00977 mysql_free_result ($result);
00978
00979 $result = mysql_query ("SELECT DISTINCT id FROM ".$this->dbase_cscw.".dp_dates WHERE rotation = '0' AND end <= '".$ago."'", $this->dlI);
00980 for ($i = 0, $temp = false; $row = mysql_fetch_array($result); $i++)
00981 {
00982 $temp[$i] = $row[0];
00983 }
00984 $tobedeleted = array_merge ($tobedeleted, $temp);
00985 mysql_free_result ($result);
00986
00987 $result = mysql_query ("SELECT DISTINCT id FROM ".$this->dbase_cscw.".dp_dates WHERE user_id NOT IN ('-1','".implode("','",$users)."')", $this->dlI);
00988 for ($i = 0, $temp = false; $row = mysql_fetch_array($result); $i++)
00989 {
00990 $temp[$i] = $row[0];
00991 }
00992 $tobedeleted = array_merge ($tobedeleted, $temp);
00993 mysql_free_result ($result);
00994
00995 $result = mysql_query ("SELECT DISTINCT id FROM ".$this->dbase_cscw.".dp_dates WHERE group_id NOT IN ('".$this->alluser_id."','".implode("','",$groups)."')", $this->dlI);
00996 for ($i = 0, $temp = false; $row = mysql_fetch_array($result); $i++)
00997 {
00998 $temp[$i] = $row[0];
00999 }
01000 $tobedeleted = array_merge ($tobedeleted, $temp);
01001 mysql_free_result ($result);
01002
01003 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_dates WHERE id IN ('-1','".implode("','",$tobedeleted)."')", $this->dlI);
01004 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE date_id IN ('-1','".implode("','",$tobedeleted)."')", $this->dlI);
01005 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE date_id IN ('-1','".implode("','",$tobedeleted)."')", $this->dlI);
01006 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE date_id IN ('-1','".implode("','",$tobedeleted)."')", $this->dlI);
01007
01008 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_changed_dates WHERE user_id NOT IN ('-1','".implode("','",$users)."')", $this->dlI);
01009 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_neg_dates WHERE user_id NOT IN ('-1','".implode("','",$users)."')", $this->dlI);
01010
01011 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keyword WHERE user_id NOT IN ('-1','".implode("','",$users)."')", $this->dlI);
01012
01013 $result = mysql_query ("SELECT DISTINCT id FROM ".$this->dbase_cscw.".dp_keyword", $this->dlI);
01014 for ($i = 0, $tobedeleted = false; $row = mysql_fetch_array($result); $i++)
01015 {
01016 $tobedeleted[$i] = $row[0];
01017 }
01018 mysql_free_result ($result);
01019
01020 mysql_query ("DELETE FROM ".$this->dbase_cscw.".dp_keywords WHERE keyword_id NOT IN ('-1','".implode("','",$tobedeleted)."')", $this->dlI);
01021
01022 return true;
01023 }
01024 else
01025 {
01026 return false;
01027 }
01028 }
01029
01030
01031 }
01032 ?>