Code

Centralized copy & paste ACL checks.
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_divListSudo.inc
index d13d554e0537285b67203bc15d66a88e42a73384..f16ddd90c01e71d67c0bc8308c3f29a28656b9fc 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+
+/*! \brief  The sudo management class.
+            This class lists all configured sudo roles.
+ */
 class divListSudo extends MultiSelectWindow
 {
 
   /* Current base */
-  var $selectedBase       = "";
-  var $departments        = array();
+  private $departments        = array();
 
   /* Regex */
-  var $Regex              = "*";
-  var $UserRegex          = "*";
+  public $Regex              = "*";
+  public $UserRegex          = "*";
 
   /* Subsearch checkbox */
-  var $SubSearch          = FALSE;
+  public $SubSearch          = FALSE;
+  protected $parent             ;
+  public $ui                 ;
 
-  var $parent             ;
-  var $ui                 ;
 
+  /*! \brief  Initialize this class 
+      @param  Object $config  The GOsa configuration object.
+      @param  Object $parent  The parent class.
+   */
   function divListSudo (&$config, &$parent)
   {
     MultiSelectWindow::MultiSelectWindow($config, "sudo", "sudo");
@@ -57,10 +64,16 @@ class divListSudo extends MultiSelectWindow
     $this->EnableSaveButton (false);
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 80;
+    $action_col_size = 54;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 32;
+    }
+    if($this->parent->CopyPasteHandler){
+      $action_col_size += 20;
+    }
 
     /* Toggle all selected / deselected */
-    $chk = "<input type='checkbox' id='select_all' name='select_all'
+    $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
 
     /* set Page header */
@@ -74,43 +87,70 @@ class divListSudo extends MultiSelectWindow
     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
       "*" , true);
     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
-      "*" , FALSE,"images/search_user.png");
+      "*" , FALSE,"images/lists/search-user.png");
   }
 
 
+  /*! \brief  Generate the list header.
+   */
   function GenHeader()
   {
     /* Prepare departments,
        which are shown in the listbox on top of the listbox
      */
     $base  = sudo::get_sudoers_ou($this->config);
-    $acl   = $this->ui->get_category_permissions($base,"sudo"); 
+    $acl    = $this->ui->get_permissions($base,"sudo/sudo"); 
+    $acl_all= $this->ui->get_category_permissions($base,"sudo"); 
  
     /* Add default header */
-    $listhead = MultiSelectWindow::get_default_header();
+    $listhead = MultiSelectWindow::get_default_header(false);
     
     /* Create Layers menu */
     $s  = ".|"._("Actions")."|\n";
-    $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
+    $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
       "&nbsp;"._("Create")."|\n";
 
     /* Append create options */
     if(preg_match("/c/",$acl)) {
       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
+      $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Default")."|new_default|\n";
     }
 
     /* Append multiple remove */
-    if(preg_match("/d/",$acl)){
+    if(preg_match("/r/",$acl)){
       $s.= "..|---|\n";
-      $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
+      $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
         "&nbsp;"._("Remove")."|"."del_role|\n";
     }
 
+    if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
+      $s.= "..|---|\n";
+      $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
+        "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
+    }
+
+    /* Copy & paste icons */
+    if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
+      $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
+      $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
+    }else{
+      $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
+      $s.="..|".$img."&nbsp;"._("Paste")."\n";
+    }
+
+    /* Add snapshot icons */
+    if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+      $s .= "..|---|\n";
+      $s .= $this->get_snapshot_header(TRUE);
+    }
+    
     $this->SetDropDownHeaderMenu($s);
     $this->SetListHeader($listhead);
   }
 
 
+  /*! \brief  Prepare the plguin to list a set of objects 
+   */
   function execute()
   {
     $this->ClearElementsList();
@@ -118,6 +158,9 @@ class divListSudo extends MultiSelectWindow
   }
 
 
+  /*! \brief  Create a list of all objects that should be displayed 
+      @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
+   */
   function setEntries($list)
   {
     /* Prepare links */
@@ -125,22 +168,45 @@ class divListSudo extends MultiSelectWindow
     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
     $ui       = get_userinfo();
 
-    $action_col_size = 80;
+    $action_col_size = 54;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 32;
+    }
+    if($this->parent->CopyPasteHandler){
+      $action_col_size += 20;
+    }
 
     // Test Every Entry and generate divlist Array
     foreach($list as $key => $val){
     
       /* Create action icons - copy & paste icons */
       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
+      $acl_all= $this->ui->get_category_permissions($val['dn'],"sudo"); 
 
       /* Add edit icon */
-      $actions = "";
+      $actions= "";
+      if($ui->is_copyable($val['dn'],"sudo","sudo") && $this->parent->CopyPasteHandler){
+        $actions.= "<input class='center' type='image'
+          src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
+      }else{
+        $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
+      }
+
       $actions.= "<input class='center' type='image'
-        src='images/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
+        src='images/lists/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
+
+      /* Add snapshot icon */
+      if(preg_match("/(r.*w|w.*r)/",$acl_all)){
+        $actions.= $this->GetSnapShotActions($val['dn']);
+      }else{
+        $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
+        $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
+      }
+
 
       if(preg_match("/d/",$acl)){
         $actions.= "<input class='center' type='image'
-          src='images/edittrash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
+          src='images/lists/trash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
       }
 
       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
@@ -152,6 +218,22 @@ class divListSudo extends MultiSelectWindow
       }
 
       $display = $val['cn'][0].$desc;
+     
+      /* Highlight defaults entry */ 
+      if(preg_match("/^defaults$/i",$val['cn'][0])){
+        $display = "<b>$display</b>";
+      }
+
+      /* Cutted objects should be displayed in light grey */
+      if($this->parent->CopyPasteHandler){
+        foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
+          if($queue_data['dn'] == $val['dn']) {
+            $display = "<font color='#999999'>".$display."</font>";
+            break;
+          }
+        }
+      }
+
       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
           "attach" => "style='width:20px;'");
       $field2 = array("string" => sprintf($userimg,$val['dn']), 
@@ -172,11 +254,16 @@ class divListSudo extends MultiSelectWindow
     $this->set_List_Bottom_Info($str);
   }
 
+  
+  /*! \brief  Save this plugin. In this case nothing will be saved
+    */
   function Save()
   {
     MultiSelectWindow :: Save();  
   }
 
+  /*! \brief  Save all relevant HTML inputs for this plugin.
+    */
   function save_object()
   {
     /* Save automatic created POSTs like regex, checkboxes */