X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttClientHelper.class.php;h=1974401cfa1be83c2bfb3a9df5d21625126d2754;hb=fff7786bd4be1a6de9b200a8b546493b9bb739e5;hp=64eedb0a7435993ffaa1fe0616dabe42682ffbb0;hpb=d71e36acc9393f7657dd3ab1fbb148c4bbf466c7;p=timetracker.git diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 64eedb0a..1974401c 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -316,4 +316,51 @@ class ttClientHelper { } return $result; } + + // deleteProject - deletes a project from the projects field it tt_clients table + // for all clients in a group. + static function deleteProject($project_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_clients". + " where projects like '%$project_id%'". + " and group_id = $group_id and org_id = $org_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + if (!ttClientHelper::deleteProjectFromClient($project_id, $val['id'])) + return false; + } + } + return true; + } + + // deleteProject - deletes a project from the projects field in tt_clients table + // for a single client in a group. + static function deleteProjectFromClient($project_id, $client_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select projects from tt_clients". + " where id = $client_id and group_id = $group_id and org_id = $org_id"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) return false; + $val = $res->fetchRow(); + $projects = explode(',', $val['projects']); + if (($key = array_search($project_id, $projects)) !== false) { + unset($projects[$key]); + } + $comma_separated = implode(',', $projects); + $sql = "update tt_clients set projects = ".$mdb2->quote($comma_separated). + " where id = $client_id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } }