]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttUser.class.php
Moved enablePlugin to ttUser class.
[timetracker.git] / WEB-INF / lib / ttUser.class.php
index ae197c6983351b3213f54e0dda7f939efcf1bd7a..cbfd62d1a262a4054e411441ed7c8d8955c1dc9d 100644 (file)
@@ -416,6 +416,9 @@ class ttUser {
 
   // updateGroup updates group information with new data.
   function updateGroup($fields) {
+    if (!($this->can('manage_basic_settings') ||
+      $this->can('manage_advanced_settings') ||
+      $this->can('manage_features'))) return false;
 
     $mdb2 = getConnection();
 
@@ -450,4 +453,32 @@ class ttUser {
 
     return true;
   }
+
+  // enablePlugin either enables or disables a specific plugin for group.
+  function enablePlugin($plugin, $enable = true)
+  {
+    if (!$this->can('manage_advanced_settings'))
+      return false; // Note: enablePlugin is currently only used on week_view.php.
+                    // So, it's not really a plugin we are enabling, but rather week view display options.
+                    // Therefore, a check for manage_advanced_settings, not manage_features.
+
+    $plugin_array = explode(',', $this->plugins);
+    if ($enable && !in_array($plugin, $plugin_array))
+      $plugin_array[] = $plugin; // Add plugin to array.
+
+    if (!$enable && in_array($plugin, $plugin_array)) {
+      $key = array_search($plugin, $plugin_array);
+      if ($key !== false)
+        unset($plugin_array[$key]); // Remove plugin from array.
+    }
+
+    $plugins = implode(',', $plugin_array);
+    if ($plugins != $this->plugins) {
+      if (!$this->updateGroup(array('plugins' => $plugins)))
+        return false;
+      $this->plugins = $plugins;
+    }
+
+    return true;
+  }
 }