Code

Added up down button
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 21 Dec 2005 13:23:09 +0000 (13:23 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 21 Dec 2005 13:23:09 +0000 (13:23 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2365 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_faiProfile.inc
plugins/admin/fai/faiProfile.tpl

index 15f2ff7db24964fa7cdc6dc8f61114d62265f2f9..ff2b4923f42e1e9c85ecb0c02214db2739ccb513 100644 (file)
@@ -37,19 +37,33 @@ class faiProfile extends plugin
     $ldap=$this->config->get_ldap_link();
 
     $tmp = split(" ",$this->FAIclass);
-    
+    $tmp3 = $tmp2 = array();
     foreach($tmp as $class){
       if(!empty($class)){
-        $this->FAIclasses[trim($class)] = trim($class);
+        if(preg_match("/|/",$class)){
+          $o = split("\|",$class);
+          $tmp3[$o[1]] = trim($o[0]);
+        }else{
+          $tmp2[trim($class)] = trim($class);
+        }
+      }
+    }
+    $this->FAIclasses = array();
+    ksort($tmp3);
+    if(is_array($tmp3)){
+      foreach($tmp3 as $class){
+        $this->FAIclasses[$class]=$class;
       }
     }
-    natcasesort($this->FAIclasses);
-    reset($this->FAIclasses) ;
+    
+    if(is_array($tmp2)){
+      foreach($tmp2 as $class){
+        $this->FAIclasses[$class]=$class;
+      }
+    }
+
     $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage");
-  
     $sort = array();
-    
     $base = $_SESSION['faifilter']['base'];
     $ldap->cd($base);
     $ldap->search("(objectClass=*)",array("*"));
@@ -74,11 +88,89 @@ class faiProfile extends plugin
     $this->old_cn   = $this->cn;
   }
 
-  function execute()
+
+  /* Combine new array */
+  function combineArrays($ar0,$ar1,$ar2)
+  {
+    $ret = array();
+    if(is_array($ar0))
+      foreach($ar0 as $ar => $a){
+        $ret[$ar]=$a;
+      }
+    if(is_array($ar1))
+      foreach($ar1 as $ar => $a){
+        $ret[$ar]=$a;
+      }
+    if(is_array($ar2))
+      foreach($ar2 as $ar => $a){
+        $ret[$ar]=$a;
+      }
+    return($ret);
+  }
+
+  function getpos($atr,$attrs)
+  {
+    $i = 0;
+    foreach($attrs as $attr => $name)    {
+      $i++;
+      if($attr == $atr){
+        return($i);
+      }
+    }
+    return(-1);
+  }
+
+  /* TRansports the geiven Arraykey one position up*/
+  function ArrayUp($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $this->getpos($atr,$attrs) ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == 1))){
+      $before = array_slice($attrs,0,($pos-2));
+      $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
+      $unten  = array_slice($attrs,$pos);
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+
+  /* TRansports the geiven Arraykey one position up*/
+  function ArrayDown($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $this->getpos($atr,$attrs) ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == $cn))){
+      $before = array_slice($attrs,0,($pos-1));
+      $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
+      $unten  = array_slice($attrs,($pos+1));
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+  function catUp($id)
+  {
+    /* Get all cats depinding on current dir */
+    $cats = $this->FAIclasses;
+    $this->FAIclasses =$this->ArrayUp($id,$cats);
+  }
+
+  function catDown($id)
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Get all cats depinding on current dir */
+    $cats = $this->FAIclasses;
+    $this->FAIclasses =$this->ArrayDown($id,$cats);
+  }
 
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -87,6 +179,7 @@ class faiProfile extends plugin
     $s_action = "";
 
     /* Remove class name From list */
+    $sort_once = false;
     foreach($_POST as $name => $post){
       if(preg_match("/DEL_/i",$name)){
         $s_action = "delete";
@@ -100,6 +193,23 @@ class faiProfile extends plugin
       }elseif(preg_match("/AddClass/i",$name)){
         $s_action  = "add";
       }
+
+      if((preg_match("/sortup_/",$name))&&(!$sort_once)){
+        $sort_once = true;
+        $val = preg_replace("/sortup_/","",$name);
+        $val = preg_replace("/_.*$/","",$val);
+        $val = base64_decode($val);
+        $this->catUp($val);
+      }
+      
+      if((preg_match("/sortdown_/",$name))&&(!$sort_once)){
+        $sort_once = true;
+        $val = preg_replace("/sortdown_/","",$name);
+        $val = preg_replace("/_.*$/","",$val);
+        $val = base64_decode($val);
+        $this->catDown($val);
+      }
+
     }
 
     if($s_action == "delete"){
@@ -110,7 +220,7 @@ class faiProfile extends plugin
       $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses);
       $this->is_dialog  =true;
     }
-  
+
     /* Save Dialog */
     if(isset($_POST['SaveSubObject'])){
       $this->dialog->save_object();
@@ -135,52 +245,49 @@ class faiProfile extends plugin
       unset($this->dialog);
       $this->dialog=NULL;
     }
-    
+
     if(isset($this->dialog)){
       $this->dialog->save_object();
       return($this->dialog->execute());
     }
 
-    $divlist  =new divlist("Profile");
+    $divlist  =new divSelectBox("Profile");
     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
-    $divlist->SetEntriesPerPage(0);
-
-    $divlist->SetHeader(array(array("string"=>"Class name"),
-                              array("string"=>"Objects","attach"=>"style='width:120px;'"),
-                              array("string"=>"Options","attach"=>"style='border-right:none;width:60px;'")));
-    $listhead = 
-    "<div style='background:#F0F0F9;padding:5px;'>".
-    "<input type='image' align='middle' src='images/editpaste.png' title='"._("Append new class names")."' alt='"._("Add")."' name='Add_class'>&nbsp;".
-    "</div>";
-
-    $objTypes['FAIhook']            = "<image src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>";
-    $objTypes['FAItemplate']        = "<image src='images/fai_template.png' title='"._("Template bundle")."' alt=''>";
-    $objTypes['FAIscript']          = "<image src='images/fai_script.png' title='"._("Script bundle")."' alt=''>";
-    $objTypes['FAIvariable']        = "<image src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>";
-    $objTypes['FAIpackages']        = "<image src='images/fai_packages.png' title='"._("Packages bundle")."' alt=''>";
-    $objTypes['FAIpartitionTable']  = "<image src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>";
+
+    $objTypes['FAIhook']            = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>";
+    $objTypes['FAItemplate']        = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''>";
+    $objTypes['FAIscript']          = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''>";
+    $objTypes['FAIvariable']        = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>";
+    $objTypes['FAIpackages']        = "<img src='images/fai_packages.png' title='"._("Packages bundle")."' alt=''>";
+    $objTypes['FAIpartitionTable']  = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>";
 
     $actions = "<input type='image' src='images/editdelete.png' title='"._("Remove class from profile")."' name='DEL_%KEY%'>"; 
 
+    $linkupdown = "&nbsp;<input type='image' name='sortup_%s'   alt='up'    title='"._("Up")."'   src='images/sort_up.png' align='top' >";
+    $linkupdown.= "<input type='image' name='sortdown_%s' alt='down'  title='"._("Down")."' src='images/sort_down.png' >";
+
     foreach($this->FAIclasses as $usedClass){
-      $str = "";
+      $str = "&nbsp;";
+
+
       if(isset($this->FAIAllclasses[$usedClass])){
         foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
           $str.= $objTypes[$class]; 
         }
       }
 
+          
+  
       $field1 = array("string"=> $usedClass,"attach"=>"");
       $field2 = array("string"=> $str,"attach"=>"");
-      $field3 = array("string"=> preg_replace("/%KEY%/",$usedClass,$actions),"attach"=>"style='border-right:none;'");
+      $field3 = array("string"=> preg_replace("/%KEY%/",$usedClass,$actions).preg_replace("/%s/",base64_encode($usedClass),$linkupdown),"attach"=>"style='border-right:none;'");
       $divlist->AddEntry(array($field1,$field2,$field3));
     }
-    
+
     $smarty->assign("FAIclasses"  ,$this->FAIclasses);
-    $smarty->assign("divlisthead" ,$listhead);
     $smarty->assign("divlist"     ,$divlist->DrawList());
 
-     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
+    /* Magic quotes GPC, escapes every ' " \, to solve some security risks
      * If we post the escaped strings they will be escaped again
      */
     foreach($this->attributes as $attrs){
@@ -195,7 +302,7 @@ class faiProfile extends plugin
     $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE));
     return($display);
   }
-  
+
   function remove_from_parent()
   {
     $ldap = $this->config->get_ldap_link();
@@ -221,11 +328,11 @@ class faiProfile extends plugin
   function check()
   {
     $message= array();
-    
+
     if(count($this->FAIclasses) == 0){
       $message[]=_("Please assign at least one class to this  profile.");
     }
+
     if(empty($this->cn)){
       $message[]=_("Please enter a valid name.");
     }
@@ -233,7 +340,7 @@ class faiProfile extends plugin
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($_SESSION['faifilter']['base']);
     $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+
     if($ldap->count()){
       $message[]=_("There is already a profile with this class name defined.");
     }
@@ -246,12 +353,14 @@ class faiProfile extends plugin
   function save()
   {
     plugin::save();
+
     $ldap = $this->config->get_ldap_link();
 
     $this->FAIclass = "";
+    $i = 0 ; 
     foreach($this->FAIclasses as $class){
-      $this->FAIclass.=$class." ";
+      $i ++ ; 
+      $this->FAIclass.=$class."|".$i." ";
     }
 
     $this->attrs['FAIclass']=trim($this->FAIclass);
index 5bbfa3c5e7ffdb8aac96aad941f0bdc5749b7c17..54dd63ffe7044734bfcb23d9d8ea6c89af1377a7 100644 (file)
                                <tr>
                                        <td style="vertical-align:top;">
                                                <h2><img class="center" alt="" src="images/fai_template.png" align="middle" title="{t}Generic{/t}">&nbsp;{t}FAI classes{/t}</h2> 
-                                               <select name="FAIclass" title="{t}Choose a priority{/t}" size="20" style="width:100%;" multiple>
+<!--                                           <select name="FAIclass" title="{t}Choose a priority{/t}" size="20" style="width:100%;" multiple>
                                                        {html_options values=$FAIclasses output=$FAIclasses}
-                                               </select>
+                                               </select>-->
+                                               {$divlist}
                                                <br>
                                                <input type="submit" name="AddClass" value="{t}Add{/t}">
                                                <input type="submit" name="DelClass" value="{t}Delete{/t}">