Code

Fixed dhcp saving for renamed objects
[gosa.git] / plugins / admin / fai / class_faiScript.inc
index 935b771b2b6d1e17d35c5c76b8d8c9af09be8e4a..ac945d890fedffa402ae1542b5017aa9546b303a 100644 (file)
@@ -2,11 +2,6 @@
 
 class faiScript extends plugin
 {
-  /* CLI vars */
-  var $cli_summary      = "Manage server basic objects";
-  var $cli_description  = "Some longer text\nfor help";
-  var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* attribute list for save action */
   var $ignore_account   = TRUE;
 
@@ -36,11 +31,16 @@ class faiScript extends plugin
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
   var $SubObjects       = array();  // All leafobjects of this object
 
-  var $FAIstate         ="";
+  var $FAIstate         = "";
+  var $sort_by          = "name";
+  var $sort_order       = "up";
 
   var $base             ="";
   var $release          ="";
   var $copy_paste_mode  = false;
+  var $cut_paste_mode   = false;
+  var $CopyPasteVars    = array("SubObjects");
+
 
   function faiScript ($config, $dn= NULL)
   {
@@ -133,6 +133,7 @@ class faiScript extends plugin
     if(isset($_POST['AddSubObject'])){
       $this->dialog= new $this->subClassName($this->config,"new");
       $this->dialog->acl = $this->acl;
+      $this->dialog->parent = &$this;
       $this->is_dialog=true;
     }
 
@@ -140,41 +141,61 @@ class faiScript extends plugin
       $_SESSION['objectinfo']= $this->dn;
     }
 
-
-    /* New Listhandling 
-     */
-    $once = true;
+    /* Handle posts */
+    $s_action = $s_entry = "";
     foreach($_POST as $name => $value){
-      if(preg_match("/^editscript_/",$name)&&($once)){
-        $once = false;
-        $entry = preg_replace("/^editscript_/","",$name);
-        $entry = base64_decode(preg_replace("/_.*/","",$entry));
-
-        $obj  = $this->SubObjects[$entry];
-        if($obj['status'] == "FreshLoaded"){
-          $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
-        }
 
-        $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
-        $this->dialog->acl = $this->acl;
-        $_SESSION['objectinfo'] = $obj['dn'];
-        $this->dialog->parent = &$this;
-        $this->is_dialog=true;
+      /* Edit script posted */
+      if(preg_match("/^editscript_/",$name)){
+        $s_action = "edit";
+        $s_entry = preg_replace("/^editscript_/","",$name);
+        $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+        break;
+      }
 
+      /* Delete script requested */
+      if(preg_match("/^deletescript_/",$name)){
+        $s_action = "remove";
+        $s_entry = preg_replace("/^deletescript_/","",$name);
+        $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+        break;
       }
-      if(preg_match("/^deletescript_/",$name)&&($once)){
-        $once = false;
-        $entry = preg_replace("/^deletescript_/","",$name);
-        $entry = base64_decode(preg_replace("/_.*/","",$entry));
-
-        $status = $this->SubObjects[$entry]['status'];
-        if($status == "edited" || $status == "FreshLoaded"){
-          $this->SubObjects[$entry]['status']= "delete";
-        }else{
-          unset($this->SubObjects[$entry]);
-        }
+    }
+
+    if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
+      $s_entry = $_GET['id'];
+      if(isset($this->SubObjects[$s_entry])){
+        $s_action = "edit";
       }
     }
+
+    if($s_action =="edit" && isset($this->SubObjects[$s_entry])){
+
+      /* Get object, and load missing entry values */
+      $obj  = $this->SubObjects[$s_entry];
+      if($obj['status'] == "FreshLoaded"){
+        $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
+      }
+      
+      /* Create new dialog and set acl attributes  */
+      $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
+      $this->dialog->acl = $this->acl;
+      $_SESSION['objectinfo'] = $obj['dn'];
+      $this->dialog->parent = &$this;
+      $this->is_dialog=true;
+    }
+
+    /* Check acls, are we allowed to delete an entry */
+    if($s_action == "remove" && isset($this->SubObjects[$s_entry])){
+      $entry = $this->SubObjects[$s_entry];
+      $status = $entry['status'];
+      if($status == "edited" || $status == "FreshLoaded"){
+        $this->SubObjects[$s_entry]['status']= "delete";
+      }else{
+        unset($this->SubObjects[$s_entry]);
+      }
+    }
+
     ///// Ende new list handling
     if(isset($_POST['SaveSubObject'])){
       $this->dialog->save_object();
@@ -214,11 +235,24 @@ class faiScript extends plugin
 
     /* Sort entries */
     $tmp = $keys = array();
-    foreach($this->SubObjects as $key => $entry){
-      $keys[$key]=$key;
+
+    if($this->sort_by == "name"){
+      foreach($this->SubObjects as $key => $entry){
+        $keys[$key]=$entry['cn'];
+      }
+    }elseif($this->sort_by == "priority"){
+      foreach($this->SubObjects as $key => $entry){
+        $keys[$key]=$entry['FAIpriority'];
+      }
     }
+
     natcasesort($keys);
-    foreach($keys as $key){
+
+    if($this->sort_order == "down"){
+      $keys =array_reverse($keys);
+    }
+
+    foreach($keys as $key => $order_var){
       $tmp[$key]=$this->SubObjects[$key];
     }
     $this->SubObjects = $tmp;
@@ -240,8 +274,35 @@ class faiScript extends plugin
     /* Divlist            added 23.02.2006 
        Containing FAIscripts 
      */
-    $divlist = new divSelectBox("FAIscripts");
-    $divlist->setHeight(400);
+    $divlist = new divlist("FAIscripts");
+    $divlist -> SetEntriesPerPage(0); 
+    $plug = $_GET['plug'];
+
+     if($this->sort_order == "up"){
+       $dir = "<img src='images/sort_up.png' title='"._("Sort direction")."' alt='\/' border=0>";
+     }else{
+       $dir = "<img src='images/sort_down.png' title='"._("Sort direction")."' alt='/\' border=0>";
+     }
+
+     if($this->sort_by == "name"){
+       $sort_name = $dir;
+       $sort_prio = "";
+     }else{
+       $sort_name = "";
+       $sort_prio = $dir;
+     }
+
+     $divlist->SetHeader(array(  
+          array("string"=>"<a href='?plug=".$plug."&amp;sort=name'>"._("Name").$sort_name."</a>"),
+          array("string"=>"<a href='?plug=".$plug."&amp;sort=priority'>".$sort_prio._("Priority")."</a>",
+                "attach" => "style='width:100px;'"),
+          array("string"=>_("Download"),
+                "attach" => "style='width:100px;'"),
+          array("string"=>_("Action"),
+                "attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
+    $divlist->SetHeight(300);
+    $divlist->SetWidth("100%");
+
     if((chkacl($this->acl,"cn")!="") || ($this->FAIstate == "freeze")){
       $img_edit = "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
       $img_remo = "";
@@ -260,10 +321,11 @@ class faiScript extends plugin
           </a>"; 
       } 
 
-      $divlist->AddEntry(array( array("string"=>$name['name']),
-            array("string"=>$down , "attach" => "style='width:20px;'"),
+      $divlist->AddEntry(array( array("string"=>"<a href='?plug=".$_GET['plug']."&act=edit&id=".$key."'>".$name['name']."</a>"),
+            array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"),
+            array("string"=>$down , "attach" => "style='width:100px;'"),
             array("string"=>str_replace("%s",base64_encode($key),$img_edit.$img_remo),
-              "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
+              "attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
     }
     $smarty->assign("Entry_divlist",$divlist->DrawList());
 
@@ -299,6 +361,7 @@ class faiScript extends plugin
             $a_return[$obj['cn']]['name']= $obj['cn'];
           }
           $a_return[$obj['cn']]['dn']= $obj['dn'];
+          $a_return[$obj['cn']]['FAIpriority']= $obj['FAIpriority'];
         }else{
           if((isset($obj['description']))&&(!empty($obj['description']))){
             $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]";
@@ -335,6 +398,18 @@ class faiScript extends plugin
         }
       }
     }
+    
+    /* Get sort order */
+    if(isset($_GET['sort']) && in_array($_GET['sort'],array("name","priority"))){
+      if($this->sort_by == $_GET['sort']){
+        if($this->sort_order == "up"){
+          $this->sort_order = "down";
+        }elseif($this->sort_order == "down"){
+          $this->sort_order = "up";
+        }
+      }
+      $this->sort_by = $_GET['sort'];
+    }
   }
 
 
@@ -345,7 +420,7 @@ class faiScript extends plugin
     $message= plugin::check();
 
     /* If this is a new script, check if a script with this name already exists */
-    if(!empty($this->release) && $this->copy_paste_mode){
+    if(!empty($this->release) && ($this->copy_paste_mode || $this->cut_paste_mode) ){
      
       /* Check if current name is already used for fai scripts in selected release */ 
       $dn = 'cn='.$this->cn.",ou=scripts,".$this->release;
@@ -368,6 +443,11 @@ class faiScript extends plugin
 
     $ldap = $this->config->get_ldap_link();
 
+    /* Copy & Paste : Ensure that FAIstate is copied too */
+    if($this->copy_paste_mode && preg_match("/freeze/",$this->FAIstate)){
+      $this->attrs['FAIstate'] = $this->FAIstate;
+    }
+
     $ldap->cat($this->dn,array("objectClass"));
     if($ldap->count()!=0){
       /* Write FAIscript to ldap*/
@@ -397,7 +477,12 @@ class faiScript extends plugin
     /* We do not need to save untouched objects */
     foreach($this->SubObjects as $name => $obj){
       if($obj['status'] == "FreshLoaded"){
-        unset($this->SubObjects[$name]);
+        if($this->copy_paste_mode){
+          $this->SubObjects[$name] = $this->get_object_attributes($obj,$this->sub_Load_Later);
+          $this->SubObjects[$name]['status'] = "new";
+        }else{
+          unset($this->SubObjects[$name]);
+        }
       }
     }
 
@@ -486,6 +571,31 @@ class faiScript extends plugin
       $this->handle_object_tagging($sub_dn, $this->gosaUnitTag);
     }
   }
+
+  
+  /* return copy & paste dialog
+   */
+  function getCopyDialog()
+  {
+    /* Ask for cn */
+    $smarty = get_smarty();
+    $smarty->assign("cn" ,$this->cn);
+    $str = $smarty->fetch(get_template_path("paste_fai_object.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+  /* Get posted cn */
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = $_POST['cn'];
+    }
+  }
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: