Code

Updated an error message. fixed server acl string
[gosa.git] / plugins / admin / systems / class_divListSystem.inc
index fd43f1cb3b1d6fef00148c0c8d67208c468c99ec..34dfaac5cd5c3a36f6f08feca84bf646618fceb7 100644 (file)
@@ -28,7 +28,11 @@ class divListSystem extends MultiSelectWindow
 
   function divListSystem ($config,$parent)
   {
-    MultiSelectWindow::MultiSelectWindow($config,"System");
+    MultiSelectWindow::MultiSelectWindow($config, "System", array("server",
+                                                                  "workstation",
+                                                                  "terminal",
+                                                                  "phone",
+                                                                  "printer"));
 
     $this->parent       = $parent;
     $this->ui           = get_userinfo();
@@ -47,10 +51,16 @@ class divListSystem extends MultiSelectWindow
     $this->EnableCloseButton(false);
     $this->EnableSaveButton (false);
 
+    /* Dynamic action col, depending on snapshot icons */
+    $action_col_size = 70;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 38;
+    }
+
     /* set Page header */
     $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("System / Department")));
-    $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:90px;border-right:0px;'"));
+    $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
 
     /*                  Text        ,Value    ,Name         ,Is selected */
     $this->AddCheckBox("ShowServers",         _("Select to see servers"),            _("Show servers"),          true);
@@ -72,17 +82,57 @@ class divListSystem extends MultiSelectWindow
 
   function GenHeader()
   {
-    /* Prepare departments,
+   /* Prepare departments,
        which are shown in the listbox on top of the listbox
      */
     $options= "";
-    foreach ($this->config->idepartments as $key => $value){
-      if ($this->selectedBase == $key){
-        $options.= "<option selected='selected' value='$key'>$value</option>";
-      } else {
-        $options.= "<option value='$key'>$value</option>";
+
+    /* Get all departments within this subtree */
+    $base = $this->config->current['BASE'];
+    $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    $tmp =array();
+    foreach($deps as $dep){
+      $tmp[$dep['dn']] = $dep;
+    }
+    $deps = $tmp;
+
+    /* Load possible departments */
+    $ui= get_userinfo();
+    $department = array();
+    foreach($this->module as $module){
+      $d = $ui->get_module_departments($module);      
+      foreach($d as $department){
+        $departments[$department] = $department;
+      }
+    }
+
+    $ids = $this->config->idepartments;
+
+    foreach($deps as $dep){
+      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $departments)){
+
+        $value = $ids[$dep['dn']];
+        if ($this->selectedBase == $dep['dn']){
+          $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
+        } else {
+          $options.= "<option value='".$dep['dn']."'>$value</option>";
+        }
       }
     }
+
+    /* If there is at least one c (Create) and one w (Write) acl in this combination
+        display the snapshot paste icon. BUT check the correct acls in the management plugin */
+    $all_module_acls = "";
+    foreach($this->module as $module){
+      $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
+    }
+
+    /* Must we add an additional seperator */
+    $add_sep = false;
+    
+    /* Add the basic icons for navigation */
     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
       " <input class='center' type='image' src='images/list_root.png' align='middle'
       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
@@ -93,26 +143,56 @@ class divListSystem extends MultiSelectWindow
       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".          _("Submit")."'>&nbsp;".
       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
 
-    if($this->parent->snapshotEnabled()){ 
-      $listhead .= "  <input class='center' type='image' align='middle' src='images/restore.png'
-        title='"._("Restore objects")."' alt='"._("Up")."' name='RestoreDeletedSnapShot'>".
-        " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+    /* Add snapshot icons */
+    if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
+      $listhead .= $this->get_snapshot_header($this->selectedBase);
+      $add_sep = true;
+    }
+
+    /* Handle create icons */ 
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_terminal.png'
+        name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>&nbsp;";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_workstation.png'
+        name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>&nbsp;";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"server/servgeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_server.png'     
+        name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'>&nbsp;";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_printer.png'    
+        name='newsystem_printer'     alt='"._("New Printer")."' title='"._("New Printer")."'>&nbsp;";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_phone.png'      
+        name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'>&nbsp;";
+    }
+
+    if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
+      $add_sep = true;
+      $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_component.png'  
+        name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'>&nbsp;";
     }
 
-    $listhead .= " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'
-      name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
-      " <input class='center' type='image' align='middle' src='images/select_new_workstation.png'
-      name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
-      " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."'
-      title='"._("New Server")."'>".
-      " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."'
-      title='"._("New Printer")."'>".
-      " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."'
-      title='"._("New Phone")."'>".
-      " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."'
-      title='"._("New Component")."'>".
-      " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;".
-      " <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
+    /* Should we add a seperator ? */
+    if($add_sep){
+      $listhead .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+    }
+
+    /* Add base selection */
+    $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
       " <input class='center' type='image' src='images/list_submit.png' align='middle'
       title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
       "</div>";
@@ -126,25 +206,6 @@ class divListSystem extends MultiSelectWindow
   }
 
 
-  function GetSnapShotActions($dn)
-  {
-    $str = "";
-
-    if($this->parent->snapshotEnabled()){
-
-      $str .="<input class='center' type='image' src='images/snapshot.png' 
-        alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create snapshot")."'>&nbsp;";
-
-      if(count($this->parent->Available_SnapsShots($dn))){
-        $str .="<input class='center' type='image' src='images/restore.png' 
-          alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
-      }else{
-        $str.= "<img src='images/empty.png' style='width:16px;' class='center'>&nbsp;";
-      }
-    }
-    return($str);
-  }
-
   function setEntries($terminals)
   {
     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
@@ -158,17 +219,61 @@ class divListSystem extends MultiSelectWindow
     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
 
-    $empty    ="&nbsp;";
+    $empty    ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center'>";
+
+    /* Dynamic action col, depending on snapshot icons */
+    $action_col_size = 70;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 38;
+    }
 
     // User and Template  Images
     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
+    /* ACL mapping */
+    $ui = get_userinfo();
+    $tabs = array(
+          "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
+          "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
+          "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
+          "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
+          "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
+          "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
+          "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
+
+
     // Test Every Entry and generate divlist Array
     foreach($terminals as $key => $val){
 
-      $action =  $this->GetSnapShotActions($val['dn']);
-      $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
-      $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
+      /* Get system type, it is used to fetch the acls for the current object.
+          "winstation" acls are stored as 2winworkstation", so we have to map this here */
+      $type     = $this->parent->get_system_type($val['objectClass']);
+      if($type == "winstation") {
+        $acl_type = "winworkstation";
+      }else{
+        $acl_type = $type;
+      }
+
+      /* Get complete category acls */
+      $acl_all  = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
+  
+      /* Get specific generic acls */
+      $acl      = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
+
+      $action= "<input class='center' type='image' src='images/edit.png' 
+                    alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
+      if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+        $action.= $this->GetSnapShotActions($val['dn']);
+      }else{
+        $action.= $empty."&nbsp;".$empty."&nbsp;";
+      }
+
+      if(preg_match("/d/",$acl)){
+        $action.= "<input class='center' type='image' src='images/edittrash.png' 
+          alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
+      }else{
+        $action.= $empty;    
+      }
 
       /* Generate picture list, which is currently disabled */
       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
@@ -198,20 +303,37 @@ class divListSystem extends MultiSelectWindow
         $display= $val["cn"][0].$dsc;
       }
 
-      if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
+     
+      /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
+      $pwd_acl =""; 
+      if(in_array("gotoWorkstation",$val['objectClass'])){
+        $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
+      }    
+      if(in_array("gotoTerminal",$val['objectClass'])){
+        $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
+      }    
+      if(preg_match("/w/",$pwd_acl)){
         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root       password")."'>";
       }else{
-        $action2 = "";
+        $action2 = $empty;
+      }
+
+
+      if(in_array("gotoWorkstation",$val['objectClass'])){
+        $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'   
+                      name='gen_cd_%KEY%' title='"._("Create FAI CD")."'>&nbsp;".$action2;
+      }else{
+        $action2= $empty.$action2;
       }
 
       if(isset($val['message'])){
-        $display.= "  (".$val['message']." '".$this->config->idepartments[$_SESSION['CurrentMainBase']]."'  )";
+        $display.= "  (".$val['message'].")";
       }
 
       $img    = $this->parent->convert_list($val);
       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
-      $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:90px;border-right:0px;text-align:right;'");
+      $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
       $this->AddElement( array($field1,$field2,$field3));
     }
 
@@ -230,62 +352,6 @@ class divListSystem extends MultiSelectWindow
     MultiSelectWindow :: save_object();  
 
 
-    /* check for posts */
-    $once = true;
-    foreach($_POST as $name => $value){
-
-      /* Create a new snapshot, display a dialog */
-      if(preg_match("/^CreateSnapShot_/",$name) && $once){
-        $once = false;
-        $entry = preg_replace("/^CreateSnapShot_/","",$name);
-        $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
-        $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent); 
-      }
-
-      /* Restore a snapshot, display a dialog with all snapshots of the current object */
-      if(preg_match("/^RestoreSnapShot_/",$name) && $once){
-        $once = false;
-        $entry = preg_replace("/^RestoreSnapShot_/","",$name);
-        $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
-        $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent); 
-        $this->parent->systab->Restore = true;
-      }
-
-      /* Restore one of the already deleted objects */
-      if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
-        $once = false;
-        $entry = "ou=systems,".$this->selectedBase;  
-        $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent); 
-        $this->parent->systab->Restore      = true;
-        $this->parent->systab->DeletedOnes  = true;
-      }
-    }
-
-    /* Create a new snapshot requested, check 
-       the given attributes and create the snapshot*/
-    if(isset($_POST['CreateSnapshot'])){
-      $this->parent->systab->save_object();
-      $msgs = $this->parent->systab->check();
-      if(count($msgs)){
-        foreach($msgs as $msg){
-          print_red($msg);
-        }
-      }else{
-        $this->parent->dn =  $this->parent->systab->dn;
-        $this->parent->create_snapshot("snapshot",$this->parent->systab->CurrentDescription);
-        $this->parent->systab = NULL;
-      }
-    }
-
-    /* Restore is requested, restore the object with the posted dn .*/ 
-    if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
-      $entry =trim($_POST['SnapShot']);
-      if(!empty($entry)){    
-        $entry = base64_decode($entry);
-        $this->parent->restore_snapshot($entry);
-        $this->parent->systab = NULL;
-      }
-    }
   }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: