From: Nik Okuntseff Date: Mon, 10 Dec 2018 14:32:18 +0000 (+0000) Subject: Refactored project edit for subgroups. X-Git-Tag: timetracker_1.19-1~436 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ea116938e30f04a448b87956b7660baeec83876e;p=timetracker.git Refactored project edit for subgroups. --- diff --git a/WEB-INF/lib/ttProjectHelper.class.php b/WEB-INF/lib/ttProjectHelper.class.php index 362a2b62..31a88ccc 100644 --- a/WEB-INF/lib/ttProjectHelper.class.php +++ b/WEB-INF/lib/ttProjectHelper.class.php @@ -332,4 +332,23 @@ class ttProjectHelper { $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } + + // getAssignedUsers - returns an array of user ids assigned to a project. + static function getAssignedUsers($project_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $result = array(); + $sql = "select user_id from tt_user_project_binds". + " where project_id = $project_id and group_id = $group_id and org_id = $org_id and status = 1"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) return false; + while ($row = $res->fetchRow()) { + $result[] = $row['user_id']; + } + return $result; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1903310b..6209ab65 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- +{if $show_users} -{if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{/if} +{if $show_tasks} diff --git a/WEB-INF/templates/project_edit.tpl b/WEB-INF/templates/project_edit.tpl index bcabc37a..2a2364f2 100644 --- a/WEB-INF/templates/project_edit.tpl +++ b/WEB-INF/templates/project_edit.tpl @@ -22,7 +22,7 @@ {/if} -{if $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() && $show_tasks} +{if $show_tasks} diff --git a/mobile/project_edit.php b/mobile/project_edit.php index 8bccd110..31da3890 100644 --- a/mobile/project_edit.php +++ b/mobile/project_edit.php @@ -36,7 +36,7 @@ if (!ttAccessAllowed('manage_projects')) { header('Location: access_denied.php'); exit(); } -if (MODE_PROJECTS != $user->tracking_mode && MODE_PROJECTS_AND_TASKS != $user->tracking_mode) { +if (MODE_PROJECTS != $user->getTrackingMode() && MODE_PROJECTS_AND_TASKS != $user->getTrackingMode()) { header('Location: feature_disabled.php'); exit(); } @@ -55,6 +55,7 @@ foreach ($users as $user_item) $tasks = ttGroupHelper::getActiveTasks(); foreach ($tasks as $task_item) $all_tasks[$task_item['id']] = $task_item['name']; +$show_tasks = MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() && count($tasks) > 0; if ($request->isPost()) { $cl_name = trim($request->getParameter('project_name')); @@ -66,15 +67,7 @@ if ($request->isPost()) { $cl_name = $project['name']; $cl_description = $project['description']; $cl_status = $project['status']; - - $mdb2 = getConnection(); - $sql = "select user_id from tt_user_project_binds where status = 1 and project_id = $cl_project_id"; - $res = $mdb2->query($sql); - if (is_a($res, 'PEAR_Error')) - die($res->getMessage()); - while ($row = $res->fetchRow()) - $cl_users[] = $row['user_id']; - + $cl_users = ttProjectHelper::getAssignedUsers($cl_project_id); $cl_tasks = explode(',', $project['tasks']); } @@ -85,7 +78,7 @@ $form->addInput(array('type'=>'textarea','name'=>'description','class'=>'mobile- $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status, 'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive')))); $form->addInput(array('type'=>'checkboxgroup','name'=>'users','data'=>$all_users,'layout'=>'H','value'=>$cl_users)); -if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) +if ($show_tasks) $form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks)); $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->get('button.copy'))); @@ -142,6 +135,8 @@ if ($request->isPost()) { $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"'); +$smarty->assign('show_users', count($users) > 0); +$smarty->assign('show_tasks', $show_tasks); $smarty->assign('title', $i18n->get('title.edit_project')); $smarty->assign('content_page_name', 'mobile/project_edit.tpl'); $smarty->display('mobile/index.tpl'); diff --git a/project_edit.php b/project_edit.php index 106e657b..1402eb11 100644 --- a/project_edit.php +++ b/project_edit.php @@ -55,6 +55,7 @@ foreach ($users as $user_item) $tasks = ttGroupHelper::getActiveTasks(); foreach ($tasks as $task_item) $all_tasks[$task_item['id']] = $task_item['name']; +$show_tasks = MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() && count($tasks) > 0; if ($request->isPost()) { $cl_name = trim($request->getParameter('project_name')); @@ -66,15 +67,7 @@ if ($request->isPost()) { $cl_name = $project['name']; $cl_description = $project['description']; $cl_status = $project['status']; - - $mdb2 = getConnection(); - $sql = "select user_id from tt_user_project_binds where status = 1 and project_id = $cl_project_id"; - $res = $mdb2->query($sql); - if (is_a($res, 'PEAR_Error')) - die($res->getMessage()); - while ($row = $res->fetchRow()) - $cl_users[] = $row['user_id']; - + $cl_users = ttProjectHelper::getAssignedUsers($cl_project_id); $cl_tasks = explode(',', $project['tasks']); } @@ -85,7 +78,7 @@ $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status, 'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive')))); $form->addInput(array('type'=>'checkboxgroup','name'=>'users','data'=>$all_users,'layout'=>'H','value'=>$cl_users)); -if (MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) +if ($show_tasks) $form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks)); $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->get('button.copy'))); @@ -135,9 +128,9 @@ if ($request->isPost()) { } // isPost $smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('show_users', count($users) > 0); -$smarty->assign('show_tasks', count($tasks) > 0); $smarty->assign('onload', 'onLoad="document.projectForm.name.focus()"'); +$smarty->assign('show_users', count($users) > 0); +$smarty->assign('show_tasks', $show_tasks); $smarty->assign('title', $i18n->get('title.edit_project')); $smarty->assign('content_page_name', 'project_edit.tpl'); $smarty->display('index.tpl');
 Anuko Time Tracker 1.18.29.4628 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4629 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/project_edit.tpl b/WEB-INF/templates/mobile/project_edit.tpl index 4a94bfeb..871f5c1d 100644 --- a/WEB-INF/templates/mobile/project_edit.tpl +++ b/WEB-INF/templates/mobile/project_edit.tpl @@ -15,12 +15,14 @@ {$i18n.label.status}: {$forms.projectForm.status.control}
 
{$i18n.label.users}: {$forms.projectForm.users.control}
 
{$i18n.label.tasks}:{$forms.projectForm.users.control}
 
{$i18n.label.tasks}: