Code

Updated FAI management view.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 3 Dec 2008 08:50:44 +0000 (08:50 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 3 Dec 2008 08:50:44 +0000 (08:50 +0000)
-Remove method

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13132 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_divListFai.inc
gosa-plugins/fai/admin/fai/class_faiGroupHandle.inc [new file with mode: 0644]
gosa-plugins/fai/admin/fai/class_faiManagement.inc
gosa-plugins/fai/admin/fai/faiGroupHandle.tpl [new file with mode: 0644]

index 458ba09efada72fb5809509c38d6b87d85a059e0..8f3a594cea892773e5787d998a9054d34d444b5b 100644 (file)
@@ -261,6 +261,11 @@ class divListFai extends MultiSelectWindow
        */
       $actions = "";
       
+      $actions.= "<input type='image' name='group_edit_".$key."' class='center'
+        src='images/lists/edit.png'>";
+      $actions.= "<input type='image' name='group_remove_".$key."' class='center'
+        src='images/lists/trash.png'>";
+      
 
       /* Create list 
        */
diff --git a/gosa-plugins/fai/admin/fai/class_faiGroupHandle.inc b/gosa-plugins/fai/admin/fai/class_faiGroupHandle.inc
new file mode 100644 (file)
index 0000000..7b4454c
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+
+class faiGroupHandle{
+
+
+  private $FAI_group;
+  private $mode     = "edit";  
+  private $open     = TRUE;
+  private $canceled = FALSE;
+
+  public function __construct($FAI_group, $Action)
+  {
+    if(in_array($Action,array("edit","remove"))){
+      $this->mode = $Action;
+    }
+
+    /* Preset required values */
+    foreach($FAI_group as $type => $data){
+      $FAI_group[$type]['selected'] = FALSE;
+    }
+    $this->FAI_group = $FAI_group;
+  }
+
+  function execute()
+  {
+    $smarty = get_smarty();
+    $smarty->assign("FAI_group",$this->FAI_group);
+    $smarty->assign("types",$this->get_types());
+    $smarty->assign("mode",$this->mode);
+    return($smarty->fetch(get_template_path("faiGroupHandle.tpl",TRUE,dirname(__FILE__))));
+  }
+
+  function save_object()
+  {
+    if(isset($_POST['faiGroupHandle'])){
+      foreach($this->FAI_group as $key => $group){
+        if(isset($_POST[$this->mode."_".$key])){
+          $this->FAI_group[$key]['selected'] = TRUE;
+        }else{
+          $this->FAI_group[$key]['selected'] = FALSE;
+        }
+      } 
+      if(isset($_POST['faiGroupHandle_apply']) || isset($_POST['faiGroupHandle_cancel'])){
+        $this->open = FALSE;
+      }
+      if(isset($_POST['faiGroupHandle_cancel'])){
+        $this->canceled = TRUE;
+      }
+    
+    }
+  }
+
+  function is_open()
+  {
+    return($this->open);
+  }
+
+  function is_canceled()
+  {
+    return($this->canceled);
+  }
+  
+  function get_mode()
+  {
+    return($this->mode);
+  }
+  
+  function get_selected()
+  {
+    $ret= array();
+    foreach($this->FAI_group as $key => $obj){
+      if($obj['selected']){
+        $ret[$key] = $obj;
+      }
+    }
+    return($ret);
+  }
+
+  function get_types()
+  {
+    $objects = array(
+        "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
+          "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
+        "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
+          "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
+        "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
+          "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
+        "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
+          "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
+        "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
+          "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
+        "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
+          "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
+        "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
+          "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
+        "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
+          "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
+        "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
+          "NAME"=>_("OPSI local product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
+    return($objects);
+  }
+}
+
+
+
+
+
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 8148eb65bade41d9e0b02834c7ff3bfc3055d704..3266af679a579eb894bea5977aafdd48ba019705 100644 (file)
@@ -49,14 +49,11 @@ class faiManagement extends plugin
   /* Allow inserting of new elements if freezed releases 
   */
   var $allow_freeze_object_attach = TRUE;
-
   var $no_save;
   var $acl_base     ="";
   var $fai_base     ="";
   var $fai_release  ="";
-
   var $acl_module = array("fai");
-
   var $opsi = NULL;
 
        /* construction/reconstruction 
@@ -121,8 +118,7 @@ class faiManagement extends plugin
     $no_save = FALSE;   // hide Apply / Save buttons
     
     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
-    session::set('LOCK_VARS_TO_USE',array("/^edit_freeze_entry$/","/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/"));
-
+    session::set('LOCK_VARS_TO_USE',array("/^edit_freeze_entry$/","/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/","/^faiGroupHandle_apply$/"));
 
     /****************
       Handle posts 
@@ -131,17 +127,22 @@ class faiManagement extends plugin
                /* Check ImageButton posts
                 * Create new tab ich new_xx is posted
                 */
-    $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
-                    "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
-                    "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
-                    "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
-                    "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
-                    "/edit_continue/"=>"select_class_name_finished",
-                    "/^multiple_copy_fai/" => "copy_multiple", 
-                    "/^multiple_cut_fai/" => "cut_multiple", 
-                    "/^copy/" => "copy",
-                    "/^remove_multiple_fai_objects/" => "del_multiple");
-
+    $posts = array( "/^remove_branch/"                =>"remove_branch",    
+                    "/^branch_branch/"                =>"branch_branch",
+                    "/^freeze_branch/"                =>"freeze_branch",   
+                    "/^create_partition/i"            =>"new_partition",
+                    "/^create_script/i"               =>"new_script",      
+                    "/^create_hook/i"                 =>"new_hook",
+                    "/^create_variable/i"             =>"new_variable",  
+                    "/^create_template/i"             =>"new_template",
+                    "/^create_package/i"              =>"new_package",    
+                    "/^create_profile/i"              =>"new_profile",
+
+                    "/^edit_continue$/"               => "select_class_name_finished",
+
+                    "/^group_edit/"                   => "group_edit",
+                    "/^group_remove/"                 => "group_remove");
                foreach($_POST as $name => $value){
       foreach($posts as $reg => $act ){
         if(preg_match($reg,$name)){
@@ -152,11 +153,9 @@ class faiManagement extends plugin
         }
       }
                        if(preg_match("/^edit_[0-9]*_.*$/",$name)){
-
         $i_entryID  = preg_replace("/^edit_([0-9]*)_.*$/i","\\1",$name);
         $s_entryType= preg_replace("/^edit_[0-9]*_([^_]*)_.*$/i","\\1",$name);
         $s_action = "edit";
-
         break;
       }elseif(preg_match("/^entry_delete_.*/",$name)){
         $s_entry = preg_replace("/^entry_delete_/","",$name);
@@ -286,79 +285,24 @@ class faiManagement extends plugin
 
 
     /****************
-      Delete confirme dialog 
+      Delete a group of FAI objects 
+        (Group = same name & different classes)
      ****************/
 
-               if ($s_action=="delete"){
-
-      /* Get 'dn' from posted termlinst */
-      $this->dn= $this->objects[$s_entry]['dn'];
-
-                       /* Load permissions for selected 'dn' and check if
-                          we're allowed to remove this 'dn' */
-      $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
-      if(preg_match("/d/",$acl)){
-
-                               /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
-                               if (($user= get_lock($this->dn)) != ""){
-                                       return(gen_locked_message ($user, $this->dn));
-                               }
-
-                               /* Lock the current entry, so nobody will edit it during deletion */
-                               add_lock ($this->dn, $this->ui->dn);
-                               $smarty->assign("warning",msgPool::deleteInfo(LDAP::fix($this->dn),_("FAI object")));
-        $smarty->assign("multiple", false);
-                               return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
-                       } else {
-
-                               /* Obviously the user isn't allowed to delete. Show message and clean session. */
-        msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
-                       }
-               }
-
-
-    /********************
-      Delete MULTIPLE entries requested, display confirm dialog
-     ********************/
-
-    if ($s_action=="del_multiple"){
-      $this->dns = array();
-      $ids = $this->list_get_selected_items();
+    if($s_action == "group_remove"){
+      if(isset($this->objects[$s_entry])){
+        $group = $this->objects[$s_entry];
+        $this->dialog = new faiGroupHandle($group,"remove");
 
-      if(count($ids)){
-
-        $errors = "";
-        foreach($ids as $id){
-          $dn = $this->objects[$id]['dn'];
-          $cn = $this->objects[$id]['cn'];
-          if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
-            $this->dns[$id] = $dn;
-          }else{
-            $errors .= $cn.", ";
-          }
-        }
-        if ($user= get_multiple_locks($this->dns)){
-          return(gen_locked_message($user,$this->dns));
-        }
-
-        if($errors != ""){
-          msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
-            "<br><br>".trim($errors,", ")),INFO_DIALOG);
-        }
-
-        if(count($this->dns)){
-
-          $dns_names = array();
-          foreach($this->dns as $dn){
-            add_lock ($dn, $this->ui->dn);
-            $dns_names[] = LDAP::fix($dn);
-          }
-
-          /* Lock the current entry, so nobody will edit it during deletion */
-                                 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
-          $smarty->assign("multiple", true);
-          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
-        }
+      }
+    }
+    if($this->dialog instanceOf faiGroupHandle){
+      $this->dialog->save_object();
+      if($this->dialog->is_open()){
+        return($this->dialog->execute());
+      }
+      if($this->dialog->is_canceled() || isset($_POST['cancel_lock'])){
+        $this->dialog = FALSE;
       }
     }
 
@@ -408,17 +352,76 @@ class faiManagement extends plugin
       /* Remove lock file after successfull deletion */
       $this->remove_lock();
       $this->dns = array();
+      $this->dialog = FALSE;
     }
 
 
+    /****************
+      Delete confirme dialog 
+     ****************/
+
+    if ($s_action=="del_multiple" || 
+        $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "remove"){
+      /* Collect objects to delete and check if object is freezed
+       */ 
+      $dns = array();
+      $errors = "";
+      $this->dns = array();
+      if($this->dialog instanceOf faiGroupHandle){
+        $to_delete = $this->dialog->get_selected();
+        foreach($to_delete as $obj){
+          if(!preg_match('/^freeze/', $obj['FAIstate'])){
+            $this->dns[] = $obj['dn'];
+          }else{
+            $errors .= $obj['cn'].", ";
+          }
+        }
+      }else{
+        $ids = $this->list_get_selected_items();
+        foreach($ids as $id){
+          foreach($this->objects[$id] as $obj){
+            if(!preg_match('/^freeze/', $obj['FAIstate'])){
+              $this->dns[] = $obj['dn'];
+            }else{
+              $errors .= $obj['cn'].", ";
+            }
+          }
+        }
+      }
+      if($errors != ""){
+        msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
+              "<br><br>".trim($errors,", ")),INFO_DIALOG);
+      }
+
+      if(count($this->dns)){
+        if ($user= get_multiple_locks($this->dns)){
+          return(gen_locked_message($user,$this->dns));
+        }
+        if(count($this->dns)){
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            add_lock ($dn, $this->ui->dn);
+            $dns_names[] = LDAP::fix($dn);
+          }
+          /* Lock the current entry, so nobody will edit it during deletion */
+                                 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        }
+      }
+    }
+
+
+
     /********************
       Delete MULTIPLE entries Canceled
      ********************/
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_fai_object_cancel'])){
-      $this->dns = array();
       $this->remove_lock();
+      $this->dns = array();
     }
 
 
diff --git a/gosa-plugins/fai/admin/fai/faiGroupHandle.tpl b/gosa-plugins/fai/admin/fai/faiGroupHandle.tpl
new file mode 100644 (file)
index 0000000..4bc7c87
--- /dev/null
@@ -0,0 +1,33 @@
+
+
+
+
+<table>
+{foreach from=$FAI_group item=item key=key}
+       <tr>
+               <td>
+                       {if $mode == "remove"}
+                               <input type='checkbox' name='{$mode}_{$key}'
+                               {if $item.selected} checked {/if}>
+                       {/if}
+               </td>
+               <td>
+                       <img src='{$types.$key.IMG}' alt='{$types.$key.KZL}' title='{$types.$key.NAME}'
+                               class='center'>
+               </td>
+               <td>{$types.$key.NAME}</td>
+               <td>{$item.description}
+               </td>
+       </tr>
+{/foreach}
+</table>
+<input type='hidden' value='faiGroupHandle' name='faiGroupHandle'>
+
+<input type='submit'>
+
+<p class='seperator'></div>
+<div style='text-align:right; padding:5px'>
+       <input type='submit' value='{msgPool type=applyButton}' name='faiGroupHandle_apply'>
+       &nbsp;
+       <input type='submit' value='{msgPool type=cancelButton}' name='faiGroupHandle_cancel'>
+</div>