Add option to profile_edit.php to show/hide users uncompleted entries (#24)
authorAndréas Lundgren <Adevade@users.noreply.github.com>
Sun, 23 Oct 2016 13:22:44 +0000 (15:22 +0200)
committeranuko <support@anuko.com>
Sun, 23 Oct 2016 13:22:44 +0000 (13:22 +0000)
I'll try to do some renaming after this merge.

13 files changed:
WEB-INF/lib/ttTeamHelper.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/resources/en.lang.php
WEB-INF/resources/sv.lang.php
WEB-INF/templates/mobile/users.tpl
WEB-INF/templates/profile_edit.tpl
WEB-INF/templates/users.tpl
dbinstall.php
initialize.php
mobile/users.php
mysql.sql
profile_edit.php
users.php

index 4c1af14..7b1fc24 100644 (file)
@@ -701,6 +701,15 @@ class ttTeamHelper {
       $record_type_v = '';
     }
 
+    $uncompleted_entries = $fields['uncompleted_entries'];
+    if ($uncompleted_entries !== null) {
+      $uncompleted_entries_f = ', uncompleted_entries';
+      $uncompleted_entries_v = ', ' . (int)$uncompleted_entries;
+    } else {
+      $uncompleted_entries_f = '';
+      $uncompleted_entries_v = '';
+    }
+
     $workday_hours = $fields['workday_hours'];
     if ($workday_hours !== null) {
       $workday_hours_f = ', workday_hours';
@@ -710,11 +719,11 @@ class ttTeamHelper {
       $workday_hours_v = '';
     }
 
-    $sql = "insert into tt_teams (name, address, currency $lockspec_f, lang $decimal_mark_f $date_format_f $time_format_f $week_start_f $plugins_f $tracking_mode_f $record_type_f $workday_hours_f)
+    $sql = "insert into tt_teams (name, address, currency $lockspec_f, lang $decimal_mark_f $date_format_f $time_format_f $week_start_f $plugins_f $tracking_mode_f $record_type_f $uncompleted_entries_f $workday_hours_f)
       values(".$mdb2->quote(trim($fields['name'])).
       ", ".$mdb2->quote(trim($fields['address'])).
       ", ".$mdb2->quote(trim($fields['currency']))." $lockspec_v, ".$mdb2->quote($lang).
-      "$decimal_mark_v $date_format_v $time_format_v $week_start_v $plugins_v $tracking_mode_v $record_type_v $workday_hours_v)";
+      "$decimal_mark_v $date_format_v $time_format_v $week_start_v $plugins_v $tracking_mode_v $record_type_v $uncompleted_entries_v $workday_hours_v)";
     $affected = $mdb2->exec($sql);
 
     if (!is_a($affected, 'PEAR_Error')) {
@@ -742,6 +751,7 @@ class ttTeamHelper {
     $week_start_part = '';
     $tracking_mode_part = '';
     $record_type_part = '';
+    $uncompleted_entries_part = '';
     $plugins_part = '';
     $lock_spec_part = '';
     $workday_hours_part = '';
@@ -755,13 +765,14 @@ class ttTeamHelper {
     if (isset($fields['week_start'])) $week_start_part = ', week_start = '.intval($fields['week_start']);
     if (isset($fields['tracking_mode'])) $tracking_mode_part = ', tracking_mode = '.intval($fields['tracking_mode']);
     if (isset($fields['record_type'])) $record_type_part = ', record_type = '.intval($fields['record_type']);
+    if (isset($fields['uncompleted_entries'])) $uncompleted_entries_part = ', uncompleted_entries = '.intval($fields['uncompleted_entries']);
     if (isset($fields['plugins'])) $plugins_part = ', plugins = '.$mdb2->quote($fields['plugins']);
     if (isset($fields['lock_spec'])) $lock_spec_part = ', lock_spec = '.$mdb2->quote($fields['lock_spec']);
     if (isset($fields['workday_hours'])) $workday_hours_part = ', workday_hours = '.$mdb2->quote($fields['workday_hours']);
 
     $sql = "update tt_teams set $name_part $addr_part $currency_part $lang_part $decimal_mark_part
       $date_format_part $time_format_part $week_start_part $tracking_mode_part $record_type_part
-      $plugins_part $lock_spec_part $workday_hours_part where id = $team_id";
+      $uncompleted_entries_part $plugins_part $lock_spec_part $workday_hours_part where id = $team_id";
     $affected = $mdb2->exec($sql);
     if (is_a($affected, 'PEAR_Error')) return false;
 
index 1566a48..0d64826 100644 (file)
 // +----------------------------------------------------------------------+
 
 class ttUser {
-  var $login = null;        // User login.
-  var $name = null;         // User name.
-  var $id = null;           // User id.
-  var $team_id = null;      // Team id.
-  var $role = null;         // User role (user, client, comanager, manager, admin).
-  var $client_id = null;    // Client id for client user role.
-  var $behalf_id = null;    // User id, on behalf of whom we are working.
-  var $behalf_name = null;  // User name, on behalf of whom we are working.
-  var $email = null;        // User email.
-  var $lang = null;         // Language.
-  var $decimal_mark = null; // Decimal separator.
-  var $date_format = null;  // Date format.
-  var $time_format = null;  // Time format.
-  var $week_start = 0;      // Week start day.
-  var $tracking_mode = 0;   // Tracking mode.
-  var $record_type = 0;     // Record type (duration vs start and finish, or both).
-  var $currency = null;     // Currency.
-  var $plugins = null;      // Comma-separated list of enabled plugins.
-  var $team = null;         // Team name.
-  var $custom_logo = 0;     // Whether to use a custom logo for team.
-  var $address = null;      // Address for invoices.
-  var $lock_spec = null;    // Cron specification for record locking.
-  var $workday_hours = 8;   // Number of work hours in a regular day.
-  var $rights = 0;          // A mask of user rights.
+  var $login = null;            // User login.
+  var $name = null;             // User name.
+  var $id = null;               // User id.
+  var $team_id = null;          // Team id.
+  var $role = null;             // User role (user, client, comanager, manager, admin).
+  var $client_id = null;        // Client id for client user role.
+  var $behalf_id = null;        // User id, on behalf of whom we are working.
+  var $behalf_name = null;      // User name, on behalf of whom we are working.
+  var $email = null;            // User email.
+  var $lang = null;             // Language.
+  var $decimal_mark = null;     // Decimal separator.
+  var $date_format = null;      // Date format.
+  var $time_format = null;      // Time format.
+  var $week_start = 0;          // Week start day.
+  var $tracking_mode = 0;       // Tracking mode.
+  var $record_type = 0;         // Record type (duration vs start and finish, or both).
+  var $uncompleted_entries = 0; // Uncompleted entries (show nowhere or on users page).
+  var $currency = null;         // Currency.
+  var $plugins = null;          // Comma-separated list of enabled plugins.
+  var $team = null;             // Team name.
+  var $custom_logo = 0;         // Whether to use a custom logo for team.
+  var $address = null;          // Address for invoices.
+  var $lock_spec = null;        // Cron specification for record locking.
+  var $workday_hours = 8;       // Number of work hours in a regular day.
+  var $rights = 0;              // A mask of user rights.
 
   // Constructor.
   function ttUser($login, $id = null) {
@@ -63,7 +64,7 @@ class ttUser {
 
     $sql = "SELECT u.id, u.login, u.name, u.team_id, u.role, u.client_id, u.email, t.name as team_name, 
       t.address, t.currency, t.lang, t.decimal_mark, t.date_format, t.time_format, t.week_start,
-      t.tracking_mode, t.record_type, t.plugins, t.lock_spec, t.workday_hours, t.custom_logo
+      t.tracking_mode, t.record_type, t.uncompleted_entries, t.plugins, t.lock_spec, t.workday_hours, t.custom_logo
       FROM tt_users u LEFT JOIN tt_teams t ON (u.team_id = t.id) WHERE ";
     if ($id)
       $sql .= "u.id = $id";
@@ -92,6 +93,7 @@ class ttUser {
       $this->week_start = $val['week_start'];
       $this->tracking_mode = $val['tracking_mode'];
       $this->record_type = $val['record_type'];
+      $this->uncompleted_entries = $val['uncompleted_entries'];
       $this->team = $val['team_name'];
       $this->address = $val['address'];
       $this->currency = $val['currency'];
index 0a83a1b..5b72669 100644 (file)
@@ -389,6 +389,9 @@ $i18n_key_words = array(
 'form.profile.mode_projects' => 'projects',
 'form.profile.mode_projects_and_tasks' => 'projects and tasks',
 'form.profile.record_type' => 'Record type',
+'form.profile.uncompleted_entries' => 'Uncompleted entries',
+'form.profile.entries_none' => 'Do not show',
+'form.profile.entries_users_page' => 'Show on Users page',
 'form.profile.type_all' => 'all',
 'form.profile.type_start_finish' => 'start and finish',
 'form.profile.type_duration' => 'duration',
index 2094860..b40f107 100644 (file)
@@ -388,6 +388,9 @@ $i18n_key_words = array(
 'form.profile.mode_projects' => 'Projekt',
 'form.profile.mode_projects_and_tasks' => 'Projekt och arbetsuppgifter',
 'form.profile.record_type' => 'Typ av tidsregistrering',
+'form.profile.uncompleted_entries' => 'Oavslutade tidsregistreringar',
+'form.profile.entries_none' => 'Visa inte',
+'form.profile.entries_users_page' => 'Visa på sidan Användare',
 'form.profile.type_all' => 'Alla',
 'form.profile.type_start_finish' => 'Starttid och sluttid',
 'form.profile.type_duration' => 'Varaktighet',
index fedfa80..bd2f0f4 100644 (file)
@@ -19,7 +19,9 @@
     {foreach $active_users as $u}
         <tr bgcolor="{cycle values="#f5f5f5,#dedee5"}">
           <td>
-            <span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
+            {if $smarty.const.ENTRIES_USERS_PAGE == $user->uncompleted_entries}
+              <span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
+            {/if}
             {if $user->isManager()}
               <a href="user_edit.php?id={$u.id}">{$u.name|escape:'html'}</a>
             {else}
index e463ca6..d13e087 100644 (file)
@@ -139,6 +139,10 @@ function handlePluginCheckboxes() {
             <td align="right" nowrap>{$i18n.form.profile.record_type}:</td>
             <td>{$forms.profileForm.record_type.control}</td>
           </tr>
+          <tr>
+            <td align="right" nowrap>{$i18n.form.profile.uncompleted_entries}:</td>
+            <td>{$forms.profileForm.uncompleted_entries.control}</td>
+          </tr>
 
           {* initialize preview text *}
           <script>
index 0eaa149..d537dda 100644 (file)
@@ -21,7 +21,9 @@
     {foreach $active_users as $u}
         <tr bgcolor="{cycle values="#f5f5f5,#dedee5"}">
           <td>
+          {if $smarty.const.ENTRIES_USERS_PAGE == $user->uncompleted_entries}
             <span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
+          {/if}
             {$u.name|escape:'html'}
           </td>
           <td>{$u.login|escape:'html'}</td>
index 255f944..9361cda 100755 (executable)
@@ -634,6 +634,7 @@ if ($_POST) {
     setChange("ALTER TABLE `tt_teams` ADD `workday_hours` SMALLINT NULL DEFAULT '8' AFTER `lock_spec`");
     setChange("RENAME TABLE tt_monthly_quota TO tt_monthly_quotas");
     setChange("ALTER TABLE tt_expense_items modify `name` text NOT NULL");
+    setChange("ALTER TABLE `tt_teams` ADD `uncompleted_entries` SMALLINT(2) NOT NULL DEFAULT '0' AFTER `record_type`");
   }
   
   // The update_clients function updates projects field in tt_clients table.
index ded539c..5f8a760 100644 (file)
@@ -120,6 +120,10 @@ define('TYPE_ALL', 0); // Time record can be specified with either duration or s
 define('TYPE_START_FINISH', 1); // Time record has start and finish times.
 define('TYPE_DURATION', 2); // Time record has only duration, no start and finish times.
 
+// Definitions of types for uncompleted time entries.
+define('ENTRIES_NONE', 0); // Do not show uncompleted time entries anywhere.
+define('ENTRIES_USERS_PAGE', 1); // Show uncompleted time entries on the users page.
+
 // User access rights - bits that collectively define an access mask to the system (a role).
 // We'll have some bits here (1,2, etc...) reserved for future use.
 define('right_data_entry', 4);     // Right to enter work hours and expenses.
index b3d8ae7..c4f65d9 100644 (file)
@@ -44,9 +44,12 @@ if($user->canManageTeam()) {
   $inactive_users = ttTeamHelper::getInactiveUsers($user->team_id, true);
 }
 
-// Check each active user if they have an uncompleted time entry.
-foreach ($active_users as $key => $user) {
-  $active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($user['id']);
+// Check if the user wants to show uncompleted time entries.
+if (ENTRIES_USERS_PAGE == $user->uncompleted_entries) {
+  // Check each active user if they have an uncompleted time entry.
+  foreach ($active_users as $key => $user) {
+    $active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($user['id']);
+  }
 }
 
 $smarty->assign('active_users', $active_users);
index e373c3e..0ca6fea 100644 (file)
--- a/mysql.sql
+++ b/mysql.sql
 # This table stores settings common to all team members such as language, week start day, etc.
 #
 CREATE TABLE `tt_teams` (
-  `id` int(11) NOT NULL auto_increment,                  # team id
-  `timestamp` timestamp NOT NULL,                        # modification timestamp
-  `name` varchar(80) default NULL,                       # team name
-  `address` varchar(255) default NULL,                   # team address, used in invoices
-  `currency` varchar(7) default NULL,                    # team currency symbol
-  `decimal_mark` char(1) NOT NULL default '.',           # separator in decimals
-  `lang` varchar(10) NOT NULL default 'en',              # language
-  `date_format` varchar(20) NOT NULL default '%Y-%m-%d', # date format
-  `time_format` varchar(20) NOT NULL default '%H:%M',    # time format
-  `week_start` smallint(2) NOT NULL DEFAULT '0',         # Week start day, 0 == Sunday.
-  `tracking_mode` smallint(2) NOT NULL DEFAULT '1',      # tracking mode ("projects" or "projects and tasks")
-  `record_type` smallint(2) NOT NULL DEFAULT '0',        # time record type ("start and finish", "duration", or both)
-  `plugins` varchar(255) default NULL,                   # a list of enabled plugins for team
-  `lock_spec` varchar(255) default NULL,                 # Cron specification for record locking,
-                                                         # for example: "0 10 * * 1" for "weekly on Mon at 10:00".
-  `workday_hours` smallint(6) DEFAULT '8',               # number of work hours in a regular day
-  `custom_logo` tinyint(4) default '0',                  # whether to use a custom logo or not
-  `status` tinyint(4) default '1',                       # team status
+  `id` int(11) NOT NULL auto_increment,                   # team id
+  `timestamp` timestamp NOT NULL,                         # modification timestamp
+  `name` varchar(80) default NULL,                        # team name
+  `address` varchar(255) default NULL,                    # team address, used in invoices
+  `currency` varchar(7) default NULL,                     # team currency symbol
+  `decimal_mark` char(1) NOT NULL default '.',            # separator in decimals
+  `lang` varchar(10) NOT NULL default 'en',               # language
+  `date_format` varchar(20) NOT NULL default '%Y-%m-%d',  # date format
+  `time_format` varchar(20) NOT NULL default '%H:%M',     # time format
+  `week_start` smallint(2) NOT NULL DEFAULT '0',          # Week start day, 0 == Sunday.
+  `tracking_mode` smallint(2) NOT NULL DEFAULT '1',       # tracking mode ("projects" or "projects and tasks")
+  `record_type` smallint(2) NOT NULL DEFAULT '0',         # time record type ("start and finish", "duration", or both)
+  `uncompleted_entries` smallint(2) NOT NULL DEFAULT '0', # show indicator next to users with uncompleted time entries
+                                                          # ("dont show", "on users page")
+  `plugins` varchar(255) default NULL,                    # a list of enabled plugins for team
+  `lock_spec` varchar(255) default NULL,                  # Cron specification for record locking,
+                                                          # for example: "0 10 * * 1" for "weekly on Mon at 10:00".
+  `workday_hours` smallint(6) DEFAULT '8',                # number of work hours in a regular day
+  `custom_logo` tinyint(4) default '0',                   # whether to use a custom logo or not
+  `status` tinyint(4) default '1',                        # team status
   PRIMARY KEY (`id`)
 );
 
index 2304c92..fbdbf83 100644 (file)
@@ -60,6 +60,7 @@ if ($request->isPost()) {
     $cl_start_week = $request->getParameter('start_week');
     $cl_tracking_mode = $request->getParameter('tracking_mode');
     $cl_record_type = $request->getParameter('record_type');
+    $cl_uncompleted_entries = $request->getParameter('uncompleted_entries');
     $cl_charts = $request->getParameter('charts');
     $cl_clients = $request->getParameter('clients');
     $cl_client_required = $request->getParameter('client_required');
@@ -86,6 +87,7 @@ if ($request->isPost()) {
     $cl_start_week = $user->week_start;
     $cl_tracking_mode = $user->tracking_mode;
     $cl_record_type = $user->record_type;
+    $cl_uncompleted_entries = $user->uncompleted_entries;
 
     // Which plugins do we have enabled?
     $plugins = explode(',', $user->plugins);
@@ -168,6 +170,12 @@ if ($user->canManageTeam()) {
   $record_type_options[TYPE_DURATION] = $i18n->getKey('form.profile.type_duration');
   $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
 
+  // Prepare uncompleted entries choices.
+  $uncompleted_entries_options = array();
+  $uncompleted_entries_options[ENTRIES_NONE] = $i18n->getKey('form.profile.entries_none');
+  $uncompleted_entries_options[ENTRIES_USERS_PAGE] = $i18n->getKey('form.profile.entries_users_page');
+  $form->addInput(array('type'=>'combobox','name'=>'uncompleted_entries','style'=>'width: 150px;','data'=>$uncompleted_entries_options,'value'=>$cl_uncompleted_entries));
+
   $form->addInput(array('type'=>'checkbox','name'=>'charts','data'=>1,'value'=>$cl_charts));
   $form->addInput(array('type'=>'checkbox','name'=>'clients','data'=>1,'value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
   $form->addInput(array('type'=>'checkbox','name'=>'client_required','data'=>1,'value'=>$cl_client_required));
@@ -244,6 +252,7 @@ if ($request->isPost()) {
         'week_start' => $cl_start_week,
         'tracking_mode' => $cl_tracking_mode,
         'record_type' => $cl_record_type,
+        'uncompleted_entries' => $cl_uncompleted_entries,
         'plugins' => $plugins));
     }
     if ($update_result) {
index 1233f11..15850d2 100644 (file)
--- a/users.php
+++ b/users.php
@@ -44,9 +44,12 @@ if($user->canManageTeam()) {
   $inactive_users = ttTeamHelper::getInactiveUsers($user->team_id, true);
 }
 
-// Check each active user if they have an uncompleted time entry.
-foreach ($active_users as $key => $user) {
-  $active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($user['id']);
+// Check if the user wants to show uncompleted time entries.
+if (ENTRIES_USERS_PAGE == $user->uncompleted_entries) {
+  // Check each active user if they have an uncompleted time entry.
+  foreach ($active_users as $key => $user) {
+    $active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($user['id']);
+  }
 }
 
 $smarty->assign('active_users', $active_users);