]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttRoleHelper.class.php
Work in progress on role editor.
[timetracker.git] / WEB-INF / lib / ttRoleHelper.class.php
index 957bcdaf8305025911b9ec78f65ca93a9cc9063a..7e1039435b2ce07de3d51043a622a1aea54994ad 100644 (file)
@@ -69,19 +69,17 @@ class ttRoleHelper {
   }
 
   // update function updates a role in the database.
-  static function update($fields)
-  {
+  static function update($fields) {
     global $user;
     $mdb2 = getConnection();
 
     $id = (int)$fields['id'];
-    $name = $fields['name'];
-    $description = $fields['description'];
-    $status = (int)$fields['status'];
-    // TODO: add rights later when we have them.
-
-    $sql = "update tt_roles set name = ".$mdb2->quote($name).", description = ".$mdb2->quote($description).
-      ", status = $status where id = $id and team_id = $user->team_id";
+    if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']);
+    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, ',');
+    $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'));
   }