From 88cfc3265e59c902667ead24d98a2109d0ae4578 Mon Sep 17 00:00:00 2001 From: Gerald Raab Date: Thu, 9 Aug 2018 15:48:21 +0200 Subject: [PATCH] Lock entry per user if has submitted timesheets --- cis/private/tools/zeitaufzeichnung.php | 8 ++++- include/zeitaufzeichnung.class.php | 43 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/cis/private/tools/zeitaufzeichnung.php b/cis/private/tools/zeitaufzeichnung.php index 46842aab8..2bf367449 100755 --- a/cis/private/tools/zeitaufzeichnung.php +++ b/cis/private/tools/zeitaufzeichnung.php @@ -102,11 +102,16 @@ else $activities_str = "'".implode("','", $activities)."'"; // definiert bis zu welchem Datum die Eintragung nicht mehr möglich ist -if (defined('CIS_ZEITAUFZEICHNUNG_GESPERRT_BIS') && CIS_ZEITAUFZEICHNUNG_GESPERRT_BIS != '') +$zasperre = new zeitaufzeichnung(); +if ($sperrdat = $zasperre->getEintragungGesperrtBisForUser($user)) + $gesperrt_bis = $sperrdat; +else if (defined('CIS_ZEITAUFZEICHNUNG_GESPERRT_BIS') && CIS_ZEITAUFZEICHNUNG_GESPERRT_BIS != '') $gesperrt_bis = CIS_ZEITAUFZEICHNUNG_GESPERRT_BIS; else $gesperrt_bis = '2015-08-31'; +//var_dump($gesperrt_bis); + $sperrdatum = date('c', strtotime($gesperrt_bis)); // Uses urlencode to avoid XSS issues @@ -1506,4 +1511,5 @@ function getZeitaufzeichnung($user, $von, $bis) $za->getListeUserFromTo($user, $von, $bis); return $za; } + ?> diff --git a/include/zeitaufzeichnung.class.php b/include/zeitaufzeichnung.class.php index fdd0bcdc1..858a5a0c5 100755 --- a/include/zeitaufzeichnung.class.php +++ b/include/zeitaufzeichnung.class.php @@ -742,5 +742,48 @@ or not exists return $lehre_arr; } + + /** + * Holt das Datum bis zu dem die Eintragung für einen bestimmten User gesperrt ist + * @param string $user + * @return string $tag Y-m-d or false + */ + + public function getEintragungGesperrtBisForUser($user) + { + //check if addon casetime is installed + $qrytable = " + SELECT EXISTS( + SELECT * + FROM information_schema.tables + WHERE + table_schema = 'addon' AND + table_name = 'tbl_casetime_timesheet' + ); + "; + + $res = $this->db_query($qrytable); + if ($this->db_fetch_row($res)[0]) + { + //check if sent timesheets for the UID exist + $where = "uid=".$this->db_add_param($user); + + $qry = "select max(datum) from addon.tbl_casetime_timesheet where ".$where." and abgeschicktamum is not null"; + + if($result = $this->db_query($qry)) + { + $datum = $this->db_fetch_object($result); + return $datum->max; + } + else + { + return false; + } + } + else + { + return false; + } + } } ?>