Added quota column on the users page.
authorNik Okuntseff <support@anuko.com>
Fri, 21 Dec 2018 22:09:59 +0000 (22:09 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 21 Dec 2018 22:09:59 +0000 (22:09 +0000)
WEB-INF/lib/common.lib.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/users.tpl
users.php

index 0e9ff9e..f483b3d 100644 (file)
@@ -391,6 +391,14 @@ function ttStartsWith($string, $startString)
     return (substr($string, 0, $len) === $startString);
 }
 
+// ttEndsWith functions checks if a string ends with a given substring.
+function ttEndsWith($string, $endString)
+{
+    $len = strlen($endString);
+    if ($len == 0) return true;
+    return (substr($string, -$len) === $endString);
+}
+
 // ttDateToUserFormat converts a date from database format to user format.
 function ttDateToUserFormat($date)
 {
index f163e58..73ec7a1 100644 (file)
@@ -395,7 +395,16 @@ class ttUser {
     $includeSelf = isset($options['include_self']);
 
     $select_part = 'select u.id, u.group_id, u.name';
-    if (isset($options['include_login'])) $select_part .= ', u.login';
+    if (isset($options['include_login'])) {
+      $select_part .= ', u.login';
+      // Piggy-back on include_login to see if we must also include quota_percent.
+      $include_quota = $this->isPluginEnabled('mq');
+      if ($include_quota) {
+        $decimal_mark = $this->getDecimalMark();
+        $replaceDecimalMark = ('.' != $decimal_mark);
+        $select_part .= ', u.quota_percent';
+      }
+    }
     if (!isset($options['include_clients'])) $select_part .= ', r.rights';
     if (isset($options['include_role'])) $select_part .= ', r.name as role_name, r.rank';
 
@@ -430,6 +439,16 @@ class ttUser {
         if ($isClient)
           continue; // Skip adding clients.
       }
+      if ($include_quota) {
+        $quota = $val['quota_percent'];
+        if (null == $quota)
+          $quota = '100'; // Null means 100%. Perhaps enforce not NULLs in db and eliminate this check.
+        elseif (ttEndsWith($quota, '.00'))
+          $quota = substr($quota, 0, strlen($quota)-3); // Trim trailing ".00";
+        elseif ($replaceDecimalMark)
+          $quota = str_replace('.', $decimal_mark, $quota);
+        $val['quota_percent'] = $quota.'%';
+      }
       $user_list[] = $val;
     }
 
index aaf04fa..19832de 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.34.4678 | 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.34.4679 | 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 236475c..d3fadad 100644 (file)
           <td width="30%" class="tableHeader">{$i18n.label.person_name}</td>
           <td width="30%" class="tableHeader">{$i18n.label.login}</td>
           <td width="20%" class="tableHeader">{$i18n.form.users.role}</td>
-          <td width="10%" class="tableHeader">{$i18n.label.edit}</td>
-          <td width="10%" class="tableHeader">{$i18n.label.delete}</td>
+  {if $show_quota}
+          <td class="tableHeader">{$i18n.label.quota}</td>
+  {/if}
+          <td class="tableHeader">{$i18n.label.edit}</td>
+          <td class="tableHeader">{$i18n.label.delete}</td>
         </tr>
   {if $active_users}
     {foreach $active_users as $u}
@@ -28,6 +31,9 @@
           </td>
           <td>{$u.login|escape}</td>
           <td>{$u.role_name|escape}</td>
+      {if $show_quota}
+          <td class="cellRightAligned">{$u.quota_percent}</td>
+      {/if}
       {if $u.group_id != $user->group_id || $u.rank < $user->rank || ($u.rank == $user->rank && $u.id == $user->id)}
           <td><a href="user_edit.php?id={$u.id}">{$i18n.label.edit}</a></td>
          {if $u.id != $user->id}<td><a href="user_delete.php?id={$u.id}">{$i18n.label.delete}</a></td>{else}<td></td>{/if}
           <td width="30%" class="tableHeader">{$i18n.label.person_name}</td>
           <td width="30%" class="tableHeader">{$i18n.label.login}</td>
           <td width="20%" class="tableHeader">{$i18n.form.users.role}</td>
-          <td width="10%" class="tableHeader">{$i18n.label.edit}</td>
-          <td width="10%" class="tableHeader">{$i18n.label.delete}</td>
+    {if $show_quota}
+          <td class="tableHeader">{$i18n.label.quota}</td>
+    {/if}
+          <td class="tableHeader">{$i18n.label.edit}</td>
+          <td class="tableHeader">{$i18n.label.delete}</td>
         </tr>
     {foreach $inactive_users as $u}
         <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
           <td>{$u.name|escape}</td>
           <td>{$u.login|escape}</td>
           <td>{$u.role_name|escape}</td>
+      {if $show_quota}
+          <td class="cellRightAligned">{$u.quota_percent}</td>
+      {/if}
       {if $u.group_id != $user->group_id || $u.rank < $user->rank}
           <td><a href="user_edit.php?id={$u.id}">{$i18n.label.edit}</a></td>
           <td><a href="user_delete.php?id={$u.id}">{$i18n.label.delete}</a></td>
index fd9e759..aa7f444 100644 (file)
--- a/users.php
+++ b/users.php
@@ -63,6 +63,7 @@ if ($uncompleted_indicators) {
 
 $smarty->assign('active_users', $active_users);
 $smarty->assign('inactive_users', $inactive_users);
+$smarty->assign('show_quota', $user->isPluginEnabled('mq'));
 $smarty->assign('title', $i18n->get('title.users'));
 $smarty->assign('content_page_name', 'users.tpl');
 $smarty->display('index.tpl');