From: Nik Okuntseff Date: Wed, 21 Nov 2018 23:05:10 +0000 (+0000) Subject: Some more work in progress on group editor. X-Git-Tag: timetracker_1.19-1~578 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ee3957cfc30d8ba3ed92ac99f3e5b784df1a9c58;p=timetracker.git Some more work in progress on group editor. --- diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 6ddffaa8..41c03114 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -59,4 +59,45 @@ class ttGroupHelper { } return false; } + + // The getSubgroupByName obtain an immediate subgroup by name if one exists. + static function getSubgroupByName($name) { + global $user; + + $mdb2 = getConnection(); + $parent_id = $user->getActiveGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_groups where parent_id = $parent_id and org_id = $org_id". + " and name = ".$mdb2->quote($name)." and status is not null"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val && $val['id']) + return $val; + } + return false; + } + + // The insertSubgroup inserts a new subgroup in database. + static function insertSubgroup($fields) { + global $user; + + $mdb2 = getConnection(); + $parent_id = $user->getActiveGroup(); + $org_id = $user->org_id; + + // TODO: inherit all attributes from the parent group, if not supplied. + $name = $fields['name']; + $description = $fields['description']; + + $created = 'now()'; + $created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']); + + $sql = "insert into tt_groups (parent_id, org_id, name, description, created, created_ip)". + " values($parent_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($description).", $created, $created_ip)"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + // TODO: design subgroup roles carefully. Perhaps roles are not to be touched in subgroups at all. + } } diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 86174547..8e9a8f21 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -414,11 +414,11 @@ class ttUser { function getSubgroups() { $mdb2 = getConnection(); - $sql = "select id, name from tt_groups where org_id = $this->org_id and parent_id = ".$this->getActiveGroup();; + $sql = "select id, name, description from tt_groups where org_id = $this->org_id and parent_id = ".$this->getActiveGroup();; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { - $groups[] = array('id'=>$val['id'],'name'=>$val['name']); + $groups[] = $val; // array('id'=>$val['id'],'name'=>$val['name']); } } return $groups; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c1be43ae..4a731726 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.26.4491 | Copyright © Anuko | +  Anuko Time Tracker 1.18.26.4492 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/group_add.php b/group_add.php index 4e8cb91a..f39ec016 100644 --- a/group_add.php +++ b/group_add.php @@ -28,6 +28,7 @@ require_once('initialize.php'); import('form.Form'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_subgroups')) { @@ -42,7 +43,7 @@ if ($request->isPost()) { } $form = new Form('groupForm'); -$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings)); +$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_name)); $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description)); $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->get('button.add'))); @@ -50,29 +51,23 @@ if ($request->isPost()) { // Validate user input. if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name')); if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description')); -/* + if ($err->no()) { - if (!ttProjectHelper::getProjectByName($cl_name)) { - if (ttProjectHelper::insert(array( - 'group_id' => $user->getActiveGroup(), - 'org_id' => $user->org_id, + if (!ttGroupHelper::getSubgroupByName($cl_name)) { + if (ttGroupHelper::insertSubgroup(array( 'name' => $cl_name, - 'description' => $cl_description, - 'users' => $cl_users, - 'tasks' => $cl_tasks, - 'status' => ACTIVE))) { - header('Location: projects.php'); + 'description' => $cl_description))) { + header('Location: groups.php'); exit(); } else $err->add($i18n->get('error.db')); } else $err->add($i18n->get('error.object_exists')); } -*/ } // isPost $smarty->assign('forms', array($form->getName()=>$form->toArray())); -//$smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"'); +$smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"'); $smarty->assign('title', $i18n->get('title.add_group')); $smarty->assign('content_page_name', 'group_add.tpl'); $smarty->display('index.tpl');