2017-02-21 16:26:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of calendar
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010 Matteo Lucarelli,
|
|
|
|
* 2017 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include parent class
|
|
|
|
*/
|
|
|
|
require_once("inc.ClassNotify.php");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to manage events
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010 Matteo Lucarelli,
|
|
|
|
* 2017 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Calendar {
|
|
|
|
/**
|
|
|
|
* Instanz of database
|
|
|
|
*/
|
|
|
|
protected $db;
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function __construct($db, $user) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
$this->db = $db;
|
2017-02-21 16:29:38 +00:00
|
|
|
$this->user = $user;
|
2022-03-31 04:36:48 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function setUser($user) { /* {{{ */
|
|
|
|
$this->user = $user;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function getUser() { /* {{{ */
|
|
|
|
return $this->user;
|
|
|
|
} /* }}} */
|
2017-02-21 16:26:16 +00:00
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function getEvents($day, $month, $year) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
$date = mktime(12,0,0, $month, $day, $year);
|
|
|
|
|
|
|
|
$queryStr = "SELECT * FROM `tblEvents` WHERE `start` <= " . $date . " AND `stop` >= " . $date;
|
2022-03-28 17:09:02 +00:00
|
|
|
if(!$this->user->isAdmin()) {
|
|
|
|
$queryStr .= " AND `userID`=".$this->user->getID();
|
|
|
|
}
|
2017-02-21 16:26:16 +00:00
|
|
|
$ret = $this->db->getResultArray($queryStr);
|
|
|
|
return $ret;
|
|
|
|
} /* }}} */
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function getEventsInInterval($start, $stop) { /* {{{ */
|
2022-03-31 04:52:27 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblEvents` WHERE (( `start` <= " . (int) $start . " AND `stop` >= " . (int) $start . " ) ".
|
2017-02-21 16:26:16 +00:00
|
|
|
"OR ( `start` <= " . (int) $stop . " AND `stop` >= " . (int) $stop . " ) ".
|
2022-03-31 04:52:27 +00:00
|
|
|
"OR ( `start` >= " . (int) $start . " AND `stop` <= " . (int) $stop . " ))";
|
2022-03-28 17:09:02 +00:00
|
|
|
if(!$this->user->isAdmin()) {
|
|
|
|
$queryStr .= " AND `userID`=".$this->user->getID();
|
|
|
|
}
|
2017-02-21 16:26:16 +00:00
|
|
|
$ret = $this->db->getResultArray($queryStr);
|
|
|
|
return $ret;
|
|
|
|
} /* }}} */
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function addEvent($from, $to, $name, $comment ) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
$queryStr = "INSERT INTO `tblEvents` (`name`, `comment`, `start`, `stop`, `date`, `userID`) VALUES ".
|
2017-02-21 16:29:38 +00:00
|
|
|
"(".$this->db->qstr($name).", ".$this->db->qstr($comment).", ".(int) $from.", ".(int) $to.", ".$this->db->getCurrentTimestamp().", ".$this->user->getID().")";
|
2017-02-21 16:26:16 +00:00
|
|
|
|
|
|
|
$ret = $this->db->getResult($queryStr);
|
2022-04-07 11:57:49 +00:00
|
|
|
if (!$ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$event = $this->getEvent((int) $this->db->getInsertID('tblEvents'));
|
|
|
|
|
|
|
|
return $event;
|
2017-02-21 16:26:16 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function getEvent($id) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
if (!is_numeric($id)) return false;
|
|
|
|
|
|
|
|
$queryStr = "SELECT * FROM `tblEvents` WHERE `id` = " . (int) $id;
|
|
|
|
$ret = $this->db->getResultArray($queryStr);
|
|
|
|
|
|
|
|
if (is_bool($ret) && $ret == false) return false;
|
|
|
|
else if (count($ret) != 1) return false;
|
|
|
|
|
|
|
|
return $ret[0];
|
|
|
|
} /* }}} */
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function editEvent($id, $from, $to=null, $name=null, $comment=null) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
if (!is_numeric($id)) return false;
|
|
|
|
|
|
|
|
$queryStr = "UPDATE `tblEvents` SET `start` = " . (int) $from . ($to !== null ? ", `stop` = " . (int) $to : '') . ($name !== null ? ", `name` = " . $this->db->qstr($name) : '') . ($comment !== null ? ", `comment` = " . $this->db->qstr($comment) : '') . ", `date` = " . $this->db->getCurrentTimestamp() . " WHERE `id` = ". (int) $id;
|
|
|
|
$ret = $this->db->getResult($queryStr);
|
|
|
|
return $ret;
|
|
|
|
} /* }}} */
|
|
|
|
|
2022-03-31 04:36:48 +00:00
|
|
|
public function delEvent($id) { /* {{{ */
|
2017-02-21 16:26:16 +00:00
|
|
|
if (!is_numeric($id)) return false;
|
|
|
|
|
|
|
|
$queryStr = "DELETE FROM `tblEvents` WHERE `id` = " . (int) $id;
|
|
|
|
$ret = $this->db->getResult($queryStr);
|
|
|
|
return $ret;
|
|
|
|
} /* }}} */
|
|
|
|
}
|