Adjusted plugins.php page to support subgroups.
authorNik Okuntseff <support@anuko.com>
Tue, 27 Nov 2018 00:32:34 +0000 (00:32 +0000)
committerNik Okuntseff <support@anuko.com>
Tue, 27 Nov 2018 00:32:34 +0000 (00:32 +0000)
WEB-INF/lib/ttGroup.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/plugins.tpl
plugins.php

index 26f2ee6..1d33fe1 100644 (file)
@@ -94,12 +94,15 @@ class ttGroup {
       $this->password_complexity = $val['password_complexity'];
       $this->group_name = $val['group_name'];
       $this->currency = $val['currency'];
+      */
       $this->plugins = $val['plugins'];
+      /*
       $this->lock_spec = $val['lock_spec'];
       $this->workday_minutes = $val['workday_minutes'];
       $this->custom_logo = $val['custom_logo'];
-
+      */
       $this->config = $val['config'];
+      /*
       $config = new ttConfigHelper($this->config);
       // Set user config options.
       $this->show_holidays = $config->getDefinedValue('show_holidays');
index 2da8f98..bece653 100644 (file)
@@ -181,6 +181,16 @@ class ttUser {
     return ($this->behalfGroup ? $this->behalfGroup->tracking_mode : $this->tracking_mode);
   }
 
+  // getPlugins returns plugins string for active group.
+  function getPlugins() {
+    return ($this->behalfGroup ? $this->behalfGroup->plugins : $this->plugins);
+  }
+
+  // getConfig returns config string for active group.
+  function getConfig() {
+    return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
+  }
+
   // The getActiveUser returns user id on behalf of whom the current user is operating.
   function getActiveUser() {
     return ($this->behalf_id ? $this->behalf_id : $this->id);
index dba4a8b..fa23923 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.28.4526 | 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.28.4527 | 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 f72d569..d31bb84 100644 (file)
@@ -89,6 +89,13 @@ function handlePluginCheckboxes() {
 <table cellspacing="4" cellpadding="7" border="0">
     <tr>
       <td>
+{if $group_dropdown}
+        <table width="100%">
+          <tr>
+            <td align="center">{$i18n.label.group}: {$forms.pluginsForm.group.control}</td>
+          </tr>
+        </table>
+{/if}
         <table cellspacing="1" cellpadding="2" border="0">
           <tr>
             <td align="right" nowrap>{$forms.pluginsForm.charts.control}</td>
index 60b86fe..5c83014 100644 (file)
@@ -34,10 +34,19 @@ if (!ttAccessAllowed('manage_features')) {
   header('Location: access_denied.php');
   exit();
 }
+if ($request->isPost() && $request->getParameter('group_changed') && !$user->isGroupValid($request->getParameter('group'))) {
+  header('Location: access_denied.php'); // Wrong group id in post.
+  exit();
+}
 // End of access checks.
 
-$config = new ttConfigHelper($user->config);
-
+// TODO: re-structure the file, perhaps by separating post and get processing into whole different sections.
+if ($request->isPost() && $request->getParameter('group_changed')) {
+  $group_id = $request->getParameter('group');
+  $user->setOnBehalfGroup($group_id);
+} else {
+  $group_id = $user->getGroup();
+}
 
 if ($request->isPost()) {
   // Plugin checkboxes.
@@ -56,7 +65,7 @@ if ($request->isPost()) {
   $cl_work_units = $request->getParameter('work_units');
 } else {
   // Which plugins do we have enabled?
-  $plugins = explode(',', $user->plugins);
+  $plugins = explode(',', $user->getPlugins());
   $cl_charts = in_array('ch', $plugins);
   $cl_clients = in_array('cl', $plugins);
   $cl_client_required = in_array('cm', $plugins);
@@ -74,6 +83,21 @@ if ($request->isPost()) {
 
 $form = new Form('pluginsForm');
 
+if ($user->can('manage_subgroups')) {
+  $groups = $user->getGroupsForDropdown();
+  if (count($groups) > 1) {
+    $form->addInput(array('type'=>'combobox',
+      'onchange'=>'document.pluginsForm.group_changed.value=1;document.pluginsForm.submit();',
+      'name'=>'group',
+      'style'=>'width: 250px;',
+      'value'=>$group_id,
+      'data'=>$groups,
+      'datakeys'=>array('id','name')));
+    $form->addInput(array('type'=>'hidden','name'=>'group_changed'));
+    $smarty->assign('group_dropdown', 1);
+  }
+}
+
 // Plugin checkboxes.
 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
@@ -91,7 +115,15 @@ $form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_
 
 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
 
+$form->setValueByElement('group_changed','');
+
 if ($request->isPost()) {
+  if ($request->getParameter('group_changed')) {
+    // User changed the group in dropdown.
+    // Redirect to self.
+    header('Location: plugins.php');
+    exit();
+  }
 
   // Validate user input. Do we have to?
 
@@ -125,7 +157,7 @@ if ($request->isPost()) {
       $plugins .= ',wu';
 
     // Recycle week view plugin options as they are not configured on this page.
-    $existing_plugins = explode(',', $user->plugins);
+    $existing_plugins = explode(',', $user->getPlugins());
     if (in_array('wvn', $existing_plugins))
       $plugins .= ',wvn';
     if (in_array('wvl', $existing_plugins))
@@ -137,7 +169,7 @@ if ($request->isPost()) {
 
     if ($user->updateGroup(array(
       'plugins' => $plugins))) {
-      header('Location: time.php');
+      header('Location: success.php');
       exit();
     } else
       $err->add($i18n->get('error.db'));