Code

reworked faiPackage package management, better reading, new repository setup dialog
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Oct 2005 08:25:03 +0000 (08:25 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Oct 2005 08:25:03 +0000 (08:25 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1540 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_askClassName.inc
plugins/admin/fai/class_faiPackage.inc
plugins/admin/fai/class_faiPackageEntry.inc
plugins/admin/fai/faiPackage.tpl

index edb9d277dc404c33c9abab9b4a9de047268d0f54..d7cb25485939e9b482f07448de472381a646e358 100644 (file)
@@ -3,17 +3,17 @@
 class askClassName 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");
+  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;
-  var $attributes     = array();
-  var $objectclasses  = array("whatever");
+  var $ignore_account     = TRUE;
+  var $attributes         = array();
+  var $objectclasses      = array("whatever");
 
-  var $objectClass    = false;
-  var $forbidden      =array();
+  var $objectClass        = false;
+  var $forbidden          = array();
   var $ClassName          = "";  
   var $ClassAlreadyExists = false;
 
@@ -31,7 +31,7 @@ class askClassName extends plugin
     $display= "";
 
     /* The faifilter contais 
-       The base for all fai objects 
+     * The base for all fai objects 
      */
     $faifilter = $_SESSION['faifilter'];
 
@@ -49,7 +49,6 @@ class askClassName extends plugin
           FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE);
 
       foreach($res2 as $object){
-      
         /* skip class names with this name */ 
         if(in_array($this->objectClass,$object['objectClass'])){
           $delete[] = $object['cn'][0];
index c48e29ec3435a1655615f021fd2a0e48c124427d..918dab1d892bb07e7dd88ef41fd5cd2ae4684f81 100644 (file)
@@ -42,13 +42,14 @@ class faiPackage extends plugin
   var $releases         = array();  // All possible releases 
   var $sections         = array();  // All section types
 
-  var $list             = array();
+  var $list             = NULL;
 
   var $mirrors          = array();  // The combination of server/release/section
   var $confDir          = "";
   var $usedPackages     = array();
-  
+  var $buffer           = NULL; 
   var $strID            ="";
+  var $newDialogShown   =false;
 
   function faiPackage ($config, $dn= NULL)
   {
@@ -71,6 +72,18 @@ class faiPackage extends plugin
     }else{
       $this->usedPackages = array();
     }  
+
+    unset($this->attrs['FAIdebianSection']['count']);
+    if((isset($this->attrs['FAIdebianSection']))&&(is_array($this->attrs['FAIdebianSection']))){
+      $this->FAIdebianSection = array();
+      foreach($this->attrs['FAIdebianSection'] as $sec){
+        $this->FAIdebianSection[$sec]=$sec;
+      }
+    }
+
+    if((isset($this->attrs['FAIdebianSection']))&&(is_string($this->attrs['FAIdebianSection']))){
+      $this->FAIdebianSection=array($this->attrs['FAIdebianSection']=>$this->attrs['FAIdebianSection']) ;
+    }
     $this->confDir = CONFIG_DIR."/fai/";
     $this->FAIpackage = array();
   }
@@ -81,6 +94,29 @@ class faiPackage extends plugin
     $smarty= get_smarty();
     $display= "";
 
+    if((!$this->is_account)&&(!$this->newDialogShown)){
+      
+      if($this->dialog==NULL){
+        $this->genMirror();
+        $this->dialog = new faiPackageNew($this->config, $this->dn,$this->mirrors,$this->servers,$this->sections,$this->releases);
+        $this->is_dialog =true;
+      }
+  
+      if(isset($_POST['SaveObjectNew'])){
+        $this->FAIdebianRelease = $this->dialog->FAIdebianRelease;
+        $this->FAIdebianSection = $this->dialog->FAIdebianSection;
+        $this->FAIdebianMirror  = $this->dialog->FAIdebianMirror;
+        unset($this->dialog);
+        $this->dialog = false;
+        $this->is_dialog=false;
+        $this->newDialogShown = true;
+      }
+
+      if($this->dialog){
+        $display=$this->dialog->execute();
+        return($display); 
+      }
+    }
     $disableRelease   = false;
     $disableMirror    = false;
     $disableOptions   = false;
@@ -91,76 +127,29 @@ class faiPackage extends plugin
       $smarty->assign($attrs,$this->$attrs);
     }
 
-    /* Post handling for Section, Release and Mirror Setup */
-    if(isset($_POST['SetSection'])){
-      $this->FAIdebianSection = $_POST['FAIdebianSectionS'];
-    }
-    if(isset($_POST['SetRelease'])){
-      $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
-    }
-    if(isset($_POST['SetMirror'])){
-      $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
-    }
-
-    if(empty($this->FAIdebianRelease)){
-      $disableSection = $disableMirror  = $disableOptions = true;
-      $this->sections=array("---");
-    }elseif(empty($this->FAIdebianSection)){
-      $disableRelease = $disableMirror  = $disableOptions = true;
-    }elseif(empty($this->FAIdebianMirror)){
-      $disableRelease = $disableSection = $disableOptions = true;
-    }else{
-      $disableRelease = $disableSection =  true;
-    }
-
     $this->genMirror();
 
+    /* check servers matching release and section settings */
     $availableServer = array();
     foreach($this->mirrors as $mir){
-      if(($mir['release'] == $this->FAIdebianRelease)&&($mir['section']==$this->FAIdebianSection)){
-        $availableServer[$mir['mirror']]=$mir['mirror'];
+      if($mir['release'] == $this->FAIdebianRelease){
+        $pass = true;
+        foreach($this->FAIdebianSection as $sec){
+          if($sec != $mir['section']){
+            $pass = false;
+          }
+        if($pass){
+            $availableServer[$mir['mirror']]=$mir['mirror'];
+          }
+        }
       }
     }
-
-    if(($disableMirror==false)&&(count($availableServer)==0)){
-      $this->FAIdebianRelease = $this->FAIdebianSection = $this->FAIdebianMirror = "";
-      $disableSection = $disableMirror  = $disableOptions = true;
-      $disableRelease = false;
-    }
-
-    if(count($availableServer)==0){
-      $availableServer=array("---");
-    }
-
-    $smarty->assign("ReleaseACL"  , "");
-    $smarty->assign("MirrorACL"   , "");
-    $smarty->assign("OptionACL"   , "");
-    $smarty->assign("SectionACL"  , "");
-
-    if($disableOptions){
-      $smarty->assign("OptionACL"," disabled ");
-    } 
-    if($disableRelease){
-      $smarty->assign("ReleaseACL"," disabled ");
-    } 
-    if($disableMirror){
-      $smarty->assign("MirrorACL"," disabled ");
-    }
-    if($disableSection){
-      $smarty->assign("SectionACL"," disabled ");
-    } 
-
-    $this->strID = $this->confDir.$this->FAIdebianMirror."/".$this->FAIdebianRelease."/".$this->FAIdebianSection;
-    if(!$disableOptions){
-      if(!isset($this->list[$this->strID])){
-        $tmp = new faiPackageEntry($this->config, $this->dn,$this->strID,$this->usedPackages);
-        $this->list[$this->strID]=$tmp->genPkgs();
-      }
+    if($this->list==NULL){
+      $this->list=$this->genPkgs();
     }
 
     if(isset($_POST['Addpkg'])){
-      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->strID,$this->usedPackages);
-      $this->dialog->buffer[$this->strID]= $this->list[$this->strID];
+      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->list,$this->usedPackages);
       $this->is_dialog =true;
     }
  
@@ -206,12 +195,17 @@ class faiPackage extends plugin
       return $this->dialog->execute();
     }
 
+    $strsec = "";
+    foreach($this->FAIdebianSection as $sec){
+       $strsec .= $sec." ";
+    }
+
     $smarty->assign("mirrors" ,$availableServer);
     $smarty->assign("mirror"  ,$this->FAIdebianMirror);
     $smarty->assign("releases",$this->releases);
     $smarty->assign("release" ,$this->FAIdebianRelease);
     $smarty->assign("sections",$this->sections);
-    $smarty->assign("section" ,$this->FAIdebianSection);
+    $smarty->assign("section" ,$strsec);
     $smarty->assign("usedPackages",$this->printUsedPackages());
     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
     return($display);
@@ -251,10 +245,6 @@ class faiPackage extends plugin
                   $this->releases[$release]=$release;
                   $this->sections[$section]=$section;
 
-                  if(empty($this->FAIdebianRelease)){
-                    $this->sections= array("---");
-                  }
-
                   $arr=array();
                   $arr['mirror'] = $mirror;
                   $arr['release']= $release; 
@@ -320,8 +310,8 @@ class faiPackage extends plugin
     $a_ret=array(); 
     if(is_array($this->usedPackages)) {
       foreach($this->usedPackages as $usedName){
-        if(isset($this->list[$this->strID][$usedName][1])){
-          $a_ret[$usedName] = $usedName." [".$this->list[$this->strID][$usedName][1]."]";
+        if(isset($this->list[$usedName][1])){
+          $a_ret[$usedName] = $usedName." [".$this->list[$usedName][1]."]";
         }else{
           $a_ret[$usedName] = $usedName;
         }
@@ -330,6 +320,42 @@ class faiPackage extends plugin
     return($a_ret);
   }
 
+   function genPkgs(){
+    /* Generate a list off available packages for this mirror, section and release
+     */
+    /* Only read this file if it wasn't read before */
+    if($this->buffer==NULL){
+      $this->buffer=array();
+      $a_ret = array();
+      foreach($this->FAIdebianSection as $sec){
+        $strID= "/etc/gosa/fai/".$this->FAIdebianMirror."/".$this->FAIdebianRelease."/".$sec;
+        
+        if(!is_file($strID)){
+          print_red(sprintf(_("Package file don't exists '%s'."),$strID));
+          return(array());
+        }
+        $fp = fopen($strID,"r");
+
+        /* Parse every line and create an array */
+        while(!feof($fp)){
+          $str= fgets($fp,512);
+          $stra= split("\|",$str);
+          if(count($stra)==4){
+            $a_ret[$stra[0]] = $stra;
+          }
+        }
+        fclose($fp);
+          /* Save our Data, to avoid reading it again */
+      }
+      $this->buffer = $a_ret;
+      ksort($a_ret);
+      return($a_ret);
+    }else{
+      return $this->buffer[$strID];
+    }
+  }
+
+
   /* Save to LDAP */
   function save()
   {
@@ -341,6 +367,11 @@ class faiPackage extends plugin
     foreach($this->usedPackages as $pkg => $obj){
       $this->attrs['FAIpackage'][] = $pkg;
     } 
+  
+    $this->attrs['FAIdebianSection'] = array();
+    foreach($this->FAIdebianSection as $sec){
+      $this->attrs['FAIdebianSection'][] = $sec;
+    }
 
     $ldap->cat($this->dn);
     if($ldap->count()!=0){
index c5c53d20d1f44dcf68ab943bccf8e19d5ea32acc..f57ec2e140bfd3bdaae945f3a8e9df153f714b7d 100644 (file)
@@ -11,7 +11,7 @@ class faiPackageEntry extends plugin
   var $ignore_account= TRUE;
   var $attributes   = array();
   var $objectclasses= array();
-  var $strID        = "";  
+  var $pkgs        = array();  
 
   var $buffer       = array();
   var $categories   = array();
@@ -21,15 +21,15 @@ class faiPackageEntry extends plugin
   /* Array with available class names */
   var $FAIAllclasses        = array();
 
-  function faiPackageEntry ($config, $dn= NULL,$strID=false,$selected=array())
+  function faiPackageEntry ($config, $dn= NULL,$pkgs,$selected=array())
   {
     plugin::plugin ($config, $dn);
-    $this->strID = $strID;
+    
+    $this->pkgs=$pkgs;
 
     if(isset($_SESSION['searchStrPKG'])){
       $this->searchStrPKG=$_SESSION['searchStrPKG'];
     }
-
     $this->selected=$selected;
   }
 
@@ -50,8 +50,9 @@ class faiPackageEntry extends plugin
     if(isset($_GET['search'])){
       $this->searchStrPKG= $_GET['search']."*";
     }
+    
+    $pkgs= $this->pkgs;
 
-    $pkgs = $this->genPkgs();
     unset($this->categories);
     foreach($pkgs as $name => $entry){
       $cat = $entry[2];
@@ -169,41 +170,6 @@ class faiPackageEntry extends plugin
   {
     return($this->selected);
   }
-
-    /* Generate listbox friendly SubObject list
-  */
-  function genPkgs(){
-    /* Generate a list off available packages for this mirror, section and release
-     */
-    $strID = $this->strID;    // This var contains the path to the parsed package file
-    
-    /* Open the packelist */
-    $fp = fopen($strID,"r");  
-    $a_ret = array();
-    $this->buffer = array();
-    /* Only read this file if it wasn't read before */
-    if(!isset($this->buffer[$strID])){
-      $str = "";
-      /* Parse every line and create an array */
-      while(!feof($fp)){
-        $str= fgets($fp,512);
-        $stra= split("\|",$str);
-        if(count($stra)==4){
-          $a_ret[$stra[0]] = $stra;
-          }
-        }
-        /* Save our Data, to avoid reading it again */
-      $this->buffer[$strID]=$a_ret;
-
-      ksort($a_ret);
-
-      return($a_ret);
-    }else{
-      return $this->buffer[$strID];
-    }
-  }
-
-
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 60e2f15c97fa159409d906bd0edbc8eb5aa8dcdd..0521f5997b06344f99e63a04d60e23dd138ffb99 100644 (file)
                                <table summary="" cellspacing="4">
                                        <tr>
                                                <td>
-                                                       <LABEL for="release">
                                                        {t}Release{/t}
-                                                       </LABEL>
                                                </td>
                                                <td>
-                                                       <select name="FAIdebianReleaseS" title="{t}Release{/t}" {$ReleaseACL}>
-                                                               {html_options options=$releases selected=$release}
-                                                       </select>
-                                                       <input type="submit" value="{t}set{/t}" name="SetRelease" {$ReleaseACL}>
+                                                       {$release}
                                                </td>
                                        </tr>
                                        <tr>
                                                <td>
-                                                       <LABEL for="section">
                                                        {t}Section{/t}
-                                                       </LABEL>
                                                </td>
                                                <td>
-                                                       <select name="FAIdebianSectionS" title="{t}Section{/t}" {$SectionACL}>
-                                                               {html_options options=$sections selected=$section}
-                                                       </select>
-                                                       <input type="submit" value="{t}set{/t}" name="SetSection" {$SectionACL}>
+                                                       {$section}
                                                </td>
                                        </tr>
                                        <tr>
                                                        </LABEL>
                                                </td>
                                                <td>
-                                                       <select name="FAIdebianMirrorS" title="{t}mirror{/t}" {$MirrorACL}>
+                                                       <select name="FAIdebianMirrorS" title="{t}mirror{/t}">
                                                                {html_options options=$mirrors selected=$mirror}
                                                        </select>
-                                                       <input type="submit" value="{t}set{/t}" name="SetMirror" {$MirrorACL}>
+                                                       <input type="submit" value="{t}set{/t}" name="SetMirror">
                                                </td>
                                        </tr>
                                </table>
@@ -80,9 +70,9 @@
                                {html_options options=$usedPackages}
                </select>
                        <br>
-                       <input type="submit" name="Addpkg" value="+" {$OptionACL}>
-                       <input type="submit" name="Delpkg" value="-" {$OptionACL}>
-                       <input type="submit" name="Conpkg" value="Configure" {$OptionACL}>
+                       <input type="submit" name="Addpkg" value="+">
+                       <input type="submit" name="Delpkg" value="-">
+                       <input type="submit" name="Conpkg" value="Configure"
                </td>
        </tr>
 </table>