Refactored project edit for subgroups.
authorNik Okuntseff <support@anuko.com>
Mon, 10 Dec 2018 14:32:18 +0000 (14:32 +0000)
committerNik Okuntseff <support@anuko.com>
Mon, 10 Dec 2018 14:32:18 +0000 (14:32 +0000)
WEB-INF/lib/ttProjectHelper.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/mobile/project_edit.tpl
WEB-INF/templates/project_edit.tpl
mobile/project_edit.php
project_edit.php

index 362a2b6..31a88cc 100644 (file)
@@ -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;
+  }
 }
index 1903310..6209ab6 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.29.4628 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.29.4629 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 4a94bfe..871f5c1 100644 (file)
           <td align="right">{$i18n.label.status}:</td>
           <td>{$forms.projectForm.status.control}</td>
         </tr>
+{if $show_users}
         <tr><td>&nbsp;</td></tr>
         <tr>
           <td align="right">{$i18n.label.users}:</td>
           <td>{$forms.projectForm.users.control}</td>
         </tr>
-{if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
+{/if}
+{if $show_tasks}
         <tr><td>&nbsp;</td></tr>
         <tr>
           <td align="right">{$i18n.label.tasks}:</td>
index bcabc37..2a2364f 100644 (file)
@@ -22,7 +22,7 @@
           <td>{$forms.projectForm.users.control}</td>
         </tr>
 {/if}
-{if $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() && $show_tasks}
+{if $show_tasks}
         <tr><td>&nbsp;</td></tr>
         <tr>
           <td align="right">{$i18n.label.tasks}:</td>
index 8bccd11..31da389 100644 (file)
@@ -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');
index 106e657..1402eb1 100644 (file)
@@ -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');