Initial implementation of role editor.
authorNik Okuntseff <support@anuko.com>
Fri, 16 Mar 2018 22:49:51 +0000 (22:49 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 16 Mar 2018 22:49:51 +0000 (22:49 +0000)
WEB-INF/lib/ttRoleHelper.class.php
WEB-INF/lib/ttTeamHelper.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/profile_edit.tpl
role_edit.php
roles.php

index 4a666cb..2f2415b 100644 (file)
@@ -126,10 +126,11 @@ class ttRoleHelper {
 
     $id = (int)$fields['id'];
     if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']);
+    if (isset($fields['rank'])) $rank_part = ', rank = '.(int)$fields['rank'];
     if (isset($fields['description'])) $descr_part = ', description = '.$mdb2->quote($fields['description']);
     if (isset($fields['status'])) $status_part = ', status = '.(int)$fields['status'];
     if (isset($fields['rights'])) $rights_part = ', rights = '.$mdb2->quote($fields['rights']);
-    $parts = trim($name_part.$descr_part.$status_part.$rights_part, ',');
+    $parts = trim($name_part.$rank_part.$descr_part.$status_part.$rights_part, ',');
     $sql = "update tt_roles set $parts where id = $id and team_id = $user->team_id";
     $affected = $mdb2->exec($sql);
     return (!is_a($affected, 'PEAR_Error'));
index b30b9cc..fec798a 100644 (file)
@@ -325,6 +325,28 @@ class ttTeamHelper {
     return $result;
   }
 
+  // getInactiveRolesForUser - returns an array of relevant active roles for user with rank less than self.
+  // "Relevant" means that client roles are filtered out if Client plugin is disabled.
+  static function getInactiveRolesForUser()
+  {
+    global $user;
+    $result = array();
+    $mdb2 = getConnection();
+
+    $sql = "select id, name, description, rank, rights from tt_roles where team_id = $user->team_id and rank < $user->rank and status = 0 order by rank";
+    $res = $mdb2->query($sql);
+    $result = array();
+    if (!is_a($res, 'PEAR_Error')) {
+      while ($val = $res->fetchRow()) {
+        $val['is_client'] = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right.
+        if ($val['is_client'] && !$user->isPluginEnabled('cl'))
+          continue; // Skip adding a client role.
+        $result[] = $val;
+      }
+    }
+    return $result;
+  }
+
   // getAllRoles - obtains all roles defined for team.
   static function getAllRoles($team_id) {
     $mdb2 = getConnection();
index 9a23ed4..8f5d92e 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.17.50.4090 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.17.51.4091 | 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 955f7d5..244c6cb 100644 (file)
@@ -141,7 +141,7 @@ function handlePluginCheckboxes() {
             <td align="right">{$i18n.label.currency}:</td>
             <td>{$forms.profileForm.currency.control}</td>
           </tr>
-  {if defined(DEBUG_ROLES)}
+  {if $user->can('manage_roles')}
           <tr>
             <td align="right" nowrap>{$i18n.label.roles}:</td>
             <td><a href="roles.php">{$i18n.label.configure}</a></td>
index 25970bd..946f834 100644 (file)
@@ -89,6 +89,7 @@ if ($request->isPost()) {
         if (ttRoleHelper::update(array(
           'id' => $cl_role_id,
           'name' => $cl_name,
+          'rank' => $cl_rank,
           'description' => $cl_description,
           'status' => $cl_status))) {
           header('Location: roles.php');
index b2629be..64a1ee4 100644 (file)
--- a/roles.php
+++ b/roles.php
@@ -37,8 +37,8 @@ if (!ttAccessAllowed('manage_roles')) {
   exit();
 }
 
-$smarty->assign('active_roles', ttTeamHelper::getActiveRoles($user->team_id));
-$smarty->assign('inactive_roles', ttTeamHelper::getInactiveRoles($user->team_id));
+$smarty->assign('active_roles', ttTeamHelper::getActiveRolesForUser());
+$smarty->assign('inactive_roles', ttTeamHelper::getInactiveRolesForUser());
 $smarty->assign('title', $i18n->getKey('title.roles'));
 $smarty->assign('content_page_name', 'roles.tpl');
 $smarty->display('index.tpl');