diff --git a/inc/inc.Calendar.php b/inc/inc.Calendar.php deleted file mode 100644 index f3dbe2981..000000000 --- a/inc/inc.Calendar.php +++ /dev/null @@ -1,95 +0,0 @@ -= " . $date; - $ret = $db->getResultArray($queryStr); - return $ret; -} - -function getEventsInInterval($start, $stop){ - - global $db; - - $queryStr = "SELECT * FROM `tblEvents` WHERE ( `start` <= " . (int) $start . " AND `stop` >= " . (int) $start . " ) ". - "OR ( `start` <= " . (int) $stop . " AND `stop` >= " . (int) $stop . " ) ". - "OR ( `start` >= " . (int) $start . " AND `stop` <= " . (int) $stop . " )"; - $ret = $db->getResultArray($queryStr); - return $ret; -} - -function addEvent($from, $to, $name, $comment ){ - - global $db,$user; - - $queryStr = "INSERT INTO `tblEvents` (`name`, `comment`, `start`, `stop`, `date`, `userID`) VALUES ". - "(".$db->qstr($name).", ".$db->qstr($comment).", ".(int) $from.", ".(int) $to.", ".$db->getCurrentTimestamp().", ".$user->getID().")"; - - $ret = $db->getResult($queryStr); - return $ret; -} - -function getEvent($id){ - - if (!is_numeric($id)) return false; - - global $db; - - $queryStr = "SELECT * FROM `tblEvents` WHERE `id` = " . (int) $id; - $ret = $db->getResultArray($queryStr); - - if (is_bool($ret) && $ret == false) return false; - else if (count($ret) != 1) return false; - - return $ret[0]; -} - -function editEvent($id, $from, $to=null, $name=null, $comment=null ){ - - if (!is_numeric($id)) return false; - - global $db; - - $queryStr = "UPDATE `tblEvents` SET `start` = " . (int) $from . ($to !== null ? ", `stop` = " . (int) $to : '') . ($name !== null ? ", `name` = " . $db->qstr($name) : '') . ($comment !== null ? ", `comment` = " . $db->qstr($comment) : '') . ", `date` = " . $db->getCurrentTimestamp() . " WHERE `id` = ". (int) $id; - $ret = $db->getResult($queryStr); - return $ret; -} - -function delEvent($id){ - - if (!is_numeric($id)) return false; - - global $db; - - $queryStr = "DELETE FROM `tblEvents` WHERE `id` = " . (int) $id; - $ret = $db->getResult($queryStr); - return $ret; -} - -?> diff --git a/inc/inc.ClassCalendar.php b/inc/inc.ClassCalendar.php new file mode 100644 index 000000000..e50aafc7f --- /dev/null +++ b/inc/inc.ClassCalendar.php @@ -0,0 +1,93 @@ + + * @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 + * @copyright Copyright (C) 2010 Matteo Lucarelli, + * 2017 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Calendar { + /** + * Instanz of database + */ + protected $db; + + function __construct($db, $user) { + $this->db = $db; + $this->user = $user; + } + + function getEvents($day, $month, $year) { /* {{{ */ + $date = mktime(12,0,0, $month, $day, $year); + + $queryStr = "SELECT * FROM `tblEvents` WHERE `start` <= " . $date . " AND `stop` >= " . $date; + $ret = $this->db->getResultArray($queryStr); + return $ret; + } /* }}} */ + + function getEventsInInterval($start, $stop) { /* {{{ */ + $queryStr = "SELECT * FROM `tblEvents` WHERE ( `start` <= " . (int) $start . " AND `stop` >= " . (int) $start . " ) ". + "OR ( `start` <= " . (int) $stop . " AND `stop` >= " . (int) $stop . " ) ". + "OR ( `start` >= " . (int) $start . " AND `stop` <= " . (int) $stop . " )"; + $ret = $this->db->getResultArray($queryStr); + return $ret; + } /* }}} */ + + function addEvent($from, $to, $name, $comment ) { /* {{{ */ + $queryStr = "INSERT INTO `tblEvents` (`name`, `comment`, `start`, `stop`, `date`, `userID`) VALUES ". + "(".$this->db->qstr($name).", ".$this->db->qstr($comment).", ".(int) $from.", ".(int) $to.", ".$this->db->getCurrentTimestamp().", ".$this->user->getID().")"; + + $ret = $this->db->getResult($queryStr); + return $ret; + } /* }}} */ + + function getEvent($id) { /* {{{ */ + 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]; + } /* }}} */ + + function editEvent($id, $from, $to=null, $name=null, $comment=null) { /* {{{ */ + 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; + } /* }}} */ + + function delEvent($id) { /* {{{ */ + if (!is_numeric($id)) return false; + + $queryStr = "DELETE FROM `tblEvents` WHERE `id` = " . (int) $id; + $ret = $this->db->getResult($queryStr); + return $ret; + } /* }}} */ +} +?> diff --git a/op/op.AddEvent.php b/op/op.AddEvent.php index ff3309128..c18aac653 100644 --- a/op/op.AddEvent.php +++ b/op/op.AddEvent.php @@ -27,7 +27,7 @@ include("../inc/inc.Extension.php"); include("../inc/inc.DBInit.php"); include("../inc/inc.Language.php"); include("../inc/inc.ClassUI.php"); -include("../inc/inc.Calendar.php"); +include("../inc/inc.ClassCalendar.php"); include("../inc/inc.Authentication.php"); if ($user->isGuest()) { @@ -66,7 +66,9 @@ if ($to<=$from){ UI::exitError(getMLText("add_event"),getMLText("to_before_from")); } -$res = addEvent($from, $to, $name, $comment); +$calendar = new SeedDMS_Calendar($dms->getDB(), $user); + +$res = $calendar->addEvent($from, $to, $name, $comment); if (is_bool($res) && !$res) { UI::exitError(getMLText("add_event"),getMLText("error_occured")); diff --git a/op/op.EditEvent.php b/op/op.EditEvent.php index 9aa9adcf1..b287e40ae 100644 --- a/op/op.EditEvent.php +++ b/op/op.EditEvent.php @@ -27,7 +27,7 @@ include("../inc/inc.Init.php"); include("../inc/inc.Extension.php"); include("../inc/inc.DBInit.php"); include("../inc/inc.ClassUI.php"); -include("../inc/inc.Calendar.php"); +include("../inc/inc.ClassCalendar.php"); include("../inc/inc.Authentication.php"); if ($user->isGuest()) { @@ -43,7 +43,9 @@ if (!isset($_POST["from"]) && !(isset($_POST["frommonth"]) && isset($_POST["from UI::exitError(getMLText("edit_event"),getMLText("error_occured")); } -if (!isset($_POST["eventid"]) || !($event = getEvent($_POST["eventid"]))) { +$calendar = new SeedDMS_Calendar($dms->getDB(), $user); + +if (!isset($_POST["eventid"]) || !($event = $calendar->getEvent($_POST["eventid"]))) { UI::exitError(getMLText("edit_event"),getMLText("error_occured")); } @@ -75,7 +77,7 @@ if ($to !== null && $to<=$from){ $to = $from + 86400 -1; } -$res = editEvent($_POST["eventid"], $from, $to, $name, $comment ); +$res = $calendar->editEvent($_POST["eventid"], $from, $to, $name, $comment ); if(isset($_POST["ajax"]) && $_POST["ajax"]) { header('Content-Type: application/json'); diff --git a/op/op.RemoveEvent.php b/op/op.RemoveEvent.php index 395686d89..998671038 100644 --- a/op/op.RemoveEvent.php +++ b/op/op.RemoveEvent.php @@ -27,7 +27,7 @@ include("../inc/inc.Init.php"); include("../inc/inc.Extension.php"); include("../inc/inc.DBInit.php"); include("../inc/inc.ClassUI.php"); -include("../inc/inc.Calendar.php"); +include("../inc/inc.ClassCalendar.php"); include("../inc/inc.Authentication.php"); /* Check if the form data comes from a trusted request */ @@ -39,13 +39,14 @@ if (!isset($_POST["eventid"]) || !is_numeric($_POST["eventid"]) || intval($_POST UI::exitError(getMLText("edit_event"),getMLText("error_occured")); } -$event=getEvent($_POST["eventid"]); +$calendar = new SeedDMS_Calendar($dms->getDB(), $user); +$event=$calendar->getEvent($_POST["eventid"]); if (($user->getID()!=$event["userID"])&&(!$user->isAdmin())){ UI::exitError(getMLText("edit_event"),getMLText("access_denied")); } -$res = delEvent($_POST["eventid"]); +$res = $calendar->delEvent($_POST["eventid"]); if (is_bool($res) && !$res) { UI::exitError(getMLText("edit_event"),getMLText("error_occured")); diff --git a/out/out.Calendar.php b/out/out.Calendar.php index 40242c1aa..f708851dd 100644 --- a/out/out.Calendar.php +++ b/out/out.Calendar.php @@ -18,7 +18,8 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. include("../inc/inc.Settings.php"); -include("../inc/inc.Calendar.php"); +include("../inc/inc.ClassCalendar.php"); +include("../inc/inc.DBInit.php"); include("../inc/inc.Language.php"); include("../inc/inc.Init.php"); include("../inc/inc.Extension.php"); @@ -39,8 +40,10 @@ if(isset($_GET['documentid']) && $_GET['documentid'] && is_numeric($_GET['docume } else $document = null; +$calendar = new SeedDMS_Calendar($dms->getDB(), $user); + if(isset($_GET['eventid']) && $_GET['eventid'] && is_numeric($_GET['eventid'])) { - $event = getEvent($_GET["eventid"]); + $event = $calendar->getEvent($_GET["eventid"]); } else $event = null; @@ -57,6 +60,7 @@ if(isset($_GET['eventtype']) && $_GET['eventtype']) { $tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); $view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user)); if($view) { + $view->setParam('calendar', $calendar); $view->setParam('start', $start); $view->setParam('end', $end); $view->setParam('document', $document); diff --git a/views/bootstrap/class.Calendar.php b/views/bootstrap/class.Calendar.php index fda55e0fb..6b096281d 100644 --- a/views/bootstrap/class.Calendar.php +++ b/views/bootstrap/class.Calendar.php @@ -164,6 +164,7 @@ class SeedDMS_View_Calendar extends SeedDMS_Bootstrap_Style { function events() { /* {{{ */ $dms = $this->params['dms']; $user = $this->params['user']; + $calendar = $this->params['calendar']; $eventtype = $this->params['eventtype']; $start = explode('-', $this->params['start']); $end = explode('-', $this->params['end']); @@ -171,7 +172,7 @@ class SeedDMS_View_Calendar extends SeedDMS_Bootstrap_Style { $arr = array(); switch($eventtype) { case 'regular': - $events = getEventsInInterval(mktime(0,0,0, $start[1], $start[2], $start[0]), mktime(23,59,59, $end[1], $end[2], $end[0])); + $events = $calendar->getEventsInInterval(mktime(0,0,0, $start[1], $start[2], $start[0]), mktime(23,59,59, $end[1], $end[2], $end[0])); foreach ($events as $event){ $arr[] = array('start'=>date('Y-m-d', $event["start"]), 'end'=>date('Y-m-d', $event["stop"]), 'title'=>$event["name"].($event['comment'] ? "\n".$event['comment'] : ''), 'eventid'=>$event["id"]); }