Code

Some changes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 6 Oct 2005 10:03:37 +0000 (10:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 6 Oct 2005 10:03:37 +0000 (10:03 +0000)
This line, and those below, will be ignored--

M    fai/class_faiPackageEntry.inc
M    fai/class_faiPackage.inc

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

plugins/admin/fai/class_faiPackage.inc
plugins/admin/fai/class_faiPackageEntry.inc

index eb27521f5c591d5c891999b72a8ba5c20b71c9c7..1688637e148cf0adb3d448ea50d77c022855a2e0 100644 (file)
@@ -44,6 +44,7 @@ class faiPackage extends plugin
 
   var $mirrors          = array();  // The combination of server/section/release
   var $confDir          = "";
+  var $usedPackages      = array();
 
   function faiPackage ($config, $dn= NULL)
   {
@@ -58,6 +59,10 @@ class faiPackage extends plugin
       $this->dn =$dn;
     }
 
+    unset($this->attrs['FAIpackage']['count']);
+    foreach($this->attrs['FAIpackage'] as $pkg){
+      $this->usedPackages[] = $pkg;
+    }
     $this->confDir = CONFIG_DIR."/fai/";
     $this->FAIpackage = "test";
   }
@@ -73,10 +78,56 @@ class faiPackage extends plugin
       $smarty->assign($attrs,$this->$attrs);
     }
 
-    /* Second try */
+    $this->genMirror();
+
+    $availableServer = array();
+    foreach($this->mirrors as $mir){
+      if(($mir['section'] == $this->section)&&($mir['release']==$this->release)){
+        $availableServer[$mir['mirror']]=$mir['mirror'];
+      }
+    }
+
+    if(isset($_POST['Addpkg'])){
+      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->confDir.$this->mirror."/".$this->section."/".$this->release,$this->usedPackages);
+      $this->is_dialog =true;
+    }
+  
+    if(isset($_POST['CancelSubObject'])){
+      $this->dialog = false;
+      $this->is_dialog=false;
+    }
+
+    if(isset($_POST['SaveSubObject'])) {
+      $this->dialog->save_object();
+      if(count($this->dialog->check())){
+        foreach($this->dialog->check() as $msgs){
+        print_red($msgs);
+        }
+      }else{
+        $use = $this->dialog->save();
+        $this->usedPackages = $use;
+        $this->dialog = false;
+        $this->is_dialog=false;
+      }
+    }
+    if($this->is_dialog){
+      return $this->dialog->execute();
+    }
     
-    /* Check available server entries in CONFIG_DIR/fai 
-     */
+
+    $smarty->assign("mirrors" ,$availableServer);
+    $smarty->assign("mirror"  ,$this->mirror);
+    $smarty->assign("sections",$this->sections);
+    $smarty->assign("section" ,$this->section);
+    $smarty->assign("releases",$this->releases);
+    $smarty->assign("release" ,$this->release);
+    $smarty->assign("usedPackages",$this->printUsedPackages());
+    $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
+    return($display);
+  }
+
+  function genMirror(){
     $confDir = $this->confDir; 
     if(!is_readable($confDir)){
       print_red(sprintf(_("Can't read configuration folder '%s'."),$confDir));
@@ -133,32 +184,7 @@ class faiPackage extends plugin
       fclose($fd);
     }
 
-    $availableServer = array();
-    foreach($this->mirrors as $mir){
-      if(($mir['section'] == $this->section)&&($mir['release']==$this->release)){
-        $availableServer[$mir['mirror']]=$mir['mirror'];
-      }
-    }
-
-    if(isset($_POST['Addpkg'])){
-      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->confDir.$this->mirror."/".$this->section."/".$this->release);
-      $this->is_dialog =true;
-    }
-    
-    if($this->is_dialog){
-      return $this->dialog->execute();
-    }
-    
 
-    $smarty->assign("mirrors" ,$availableServer);
-    $smarty->assign("mirror"  ,$this->mirror);
-    $smarty->assign("sections",$this->sections);
-    $smarty->assign("section" ,$this->section);
-    $smarty->assign("releases",$this->releases);
-    $smarty->assign("release" ,$this->release);
-    $smarty->assign("usedPackages",$this->usedPackages);
-    $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
-    return($display);
   }
 
   /* Delete me, and all my subtrees
@@ -196,6 +222,15 @@ class faiPackage extends plugin
     return ($message);
   }
 
+  function printUsedPackages(){
+    $a_ret=array(); 
+    if(is_array($this->usedPackages)) {
+      foreach($this->usedPackages as $usedName){
+        $a_ret[$usedName] = $usedName;
+      }
+    }
+    return($a_ret);
+  }
 
   /* Save to LDAP */
   function save()
@@ -203,7 +238,16 @@ class faiPackage extends plugin
     plugin::save();
  
     $ldap = $this->config->get_ldap_link();
-  
+
+    $this->attrs['FAIpackage'] = array();
+    foreach($this->usedPackages as $pkg => $obj){
+      $this->attrs['FAIpackage'][] = $pkg;
+    } 
+
+    unset($this->attrs['section']);
+    unset($this->attrs['mirror']);
+    unset($this->attrs['release']);
+
     $ldap->cat($this->dn);
     if($ldap->count()!=0){
       /* Write FAIscript to ldap*/
index 954cbd77b28d4fa50ebb4759a48434b5babeb311..006462389081a5935c7f277ba3a3634ba32a1e48 100644 (file)
@@ -16,15 +16,17 @@ class faiPackageEntry extends plugin
   var $buffer       = array();
   var $categories   = array();
   var $searchStr    = "*";
+  var $selected     = array();
 
   /* Array with available class names */
   var $FAIAllclasses        = array();
 
-  function faiPackageEntry ($config, $dn= NULL,$strID=false)
+  function faiPackageEntry ($config, $dn= NULL,$strID=false,$selected=array())
   {
     plugin::plugin ($config, $dn);
     $this->strID = $strID;
 
+    $this->selected=$selected;
   }
 
   function execute()
@@ -39,7 +41,7 @@ class faiPackageEntry extends plugin
     $divlist->SetHeader(array(array("string"=>"&nbsp;"),
                               array("string"=>"Name"),
                               array("string"=>"Version"),
-                              array("string"=>"Description")));
+                              array("string"=>"Description","attach"=>"style='border-right:0px;'")));
 
     if(isset($_GET['search'])){
       $this->searchStr= $_GET['search']."*";
@@ -64,9 +66,9 @@ class faiPackageEntry extends plugin
     $CHKS = "<table><tr><td><input type='hidden' value='chkchange' name='chkchange'>";
     foreach($this->categories as $cat => $selected){
       if($selected){
-        $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."' checked>&nbsp;".$cat."&nbsp;";
+        $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;";
       }else{
-        $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."'>&nbsp;".$cat."&nbsp;";
+        $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;";
       }
     }
     $CHKS .= "<br><input type='submit' name='refresh0' value='"._("refresh")."'> </td></tr></table>";
@@ -77,26 +79,35 @@ class faiPackageEntry extends plugin
         $packages = array_merge($packages,$pkgs[$cat]);
       }
     }
-/*
+
     foreach($_POST as $name => $value){
       if(preg_match("/^wasonpage_/i",$name)){
         $name = preg_replace("/^wasonpage_/","",$name);
+        $n =base64_decode($name);
         if(isset($_POST['use_'.$name])){
-          print "was checked";
+          $this->selected[$n] = $n; 
+        }else{
+          if(isset($this->selected[$n])){
+            unset($this->selected[$n]);
+          }
         }
+
       }
-    
     }
 
-*/
     foreach($packages as $pkg){
       if(preg_match("/^".str_replace("*",".*",$this->searchStr)."/i",$pkg[0])){
-      $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."'>
+      if(in_array($pkg[0],$this->selected)){
+        $check = " checked ";
+      }else{
+        $check = "";
+      }
+      $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check." onclick='document.mainform.submit()'>
                  <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
       $divlist->AddEntry(array(array("string"=>$chkbox),
                                array("string"=>$pkg[0]),
                                array("string"=>$pkg[1]),
-                               array("string"=>$pkg[3])));
+                               array("string"=>$pkg[3],"attach"=>"style='border-right:0px'")));
       }
     }
 
@@ -117,6 +128,21 @@ class faiPackageEntry extends plugin
   /* Save data to object */
   function save_object()
   {
+    foreach($_POST as $name => $value){
+      if(preg_match("/^wasonpage_/i",$name)){
+        $name = preg_replace("/^wasonpage_/","",$name);
+        $n =base64_decode($name);
+        if(isset($_POST['use_'.$name])){
+          $this->selected[$n] = $n;
+        }else{
+          if(isset($this->selected[$n])){
+            unset($this->selected[$n]);
+          }
+        }
+
+      }
+    }
+
   }
 
   /* Check supplied data */
@@ -128,13 +154,22 @@ class faiPackageEntry extends plugin
 
   function save()
   {
-    $tmp = array();
-    foreach($this->FAIAllclasses as $class => $obj){
-      if($obj['status']==true){
-        $tmp[$class]=$class;
+/*
+    $a_ret= array();
+    $pkgs = $this->genPkgs();
+    foreach($this->selected as $pkg){
+      foreach($pkgs as $cat => $obj){
+        foreach($obj as $package){
+          if($package[0] == $pkg){
+            $a_ret[$package[0]]=$package;
+          }
+        }
       }
     }
-    return($tmp);
+    return($a_ret);
+*/
+
+  return($this->selected);
   }
 
     /* Generate listbox friendly SubObject list