Code

Removed mirror from faiPackage
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 9 Dec 2005 12:31:15 +0000 (12:31 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 9 Dec 2005 12:31:15 +0000 (12:31 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2272 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_faiPackage.inc
plugins/admin/fai/class_faiPackageNew.inc
plugins/admin/fai/faiPackage.tpl
plugins/admin/fai/faiPackageNew.tpl

index 402404c8b47e5ed2027d0fa28cb8bb5536776d97..cb9b9f8d8071dc62e97ed7997fe870193f69507f 100644 (file)
@@ -11,7 +11,7 @@ class faiPackage extends plugin
   var $ignore_account   = TRUE;
 
   /* Attributes for this Object */
-  var $attributes       = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection","FAIdebianMirror");
+  var $attributes       = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection");
 
   /* ObjectClasses for this Object*/
   var $objectclasses    = array("top","FAIclass","FAIpackageList","FAIrepository");
@@ -38,7 +38,6 @@ class faiPackage extends plugin
 
   var $FAIdebianRelease          = ""; // The selected release
   var $FAIdebianSection          = ""; // selected section
-  var $FAIdebianMirror           = ""; // selected mirror
   var $mirror                    = ""; // selected mirror
 
   var $servers          = array();  // All available servers
@@ -116,9 +115,6 @@ class faiPackage extends plugin
     }
     $this->confDir = CONFIG_DIR."/fai/";
     $this->FAIpackage = array();
-
-    /* Extract mirror location */
-    $this->mirror= preg_replace("!^[^/]+//([^/]+).*$!", '$1', $this->FAIdebianMirror);
   }
 
   function execute()
@@ -131,8 +127,6 @@ class faiPackage extends plugin
     $smarty= get_smarty();
     $display= "";
 
-    $this->genMirror();
-
     /* Check if we exist already - no need to ask for revisions, etc. then */
     if ($this->dn != "new"){
         $this->newDialogShown= true;
@@ -145,23 +139,16 @@ class faiPackage extends plugin
         $this->is_dialog =true;
       }
 
-      /* alert possible missconfigurations */ 
-      if((count($this->releases)==0)||(count($this->servers)==0)||(count($this->sections)==0)){
-        print_red(_("There is no useable package list defined."));
-      }
-
       /* Assign posible changes, for mirror combinations */
       $this->dialog->save_object();
-      $this->dialog->releases = $this->releases;
-      $this->dialog->servers  = $this->servers;
-      $this->dialog->sections = $this->sections;
-      $this->dialog->mirrors  = $this->mirrors;
 
       /* Assign Repository settings*/ 
       if(isset($_POST['SaveObjectNew'])){
-        $this->FAIdebianRelease = $this->dialog->FAIdebianRelease;
-        $this->FAIdebianSection = $this->dialog->FAIdebianSection;
-        $this->FAIdebianMirror  = $this->dialog->FAIdebianMirror;
+        $obj = $this->dialog->save();
+      
+        $this->FAIdebianSection = $obj['FAIdebianSection'];
+        $this->FAIdebianRelease = $obj['FAIdebianRelease'];
+    
         unset($this->dialog);
         $this->dialog = false;
         $this->is_dialog=false;
@@ -180,27 +167,6 @@ class faiPackage extends plugin
       $smarty->assign($attrs,$this->$attrs);
     }
   
-    /* Set mirror if changed */
-    if((isset($_POST['FAIdebianMirrorS']))&&(!empty($_POST['FAIdebianMirrorS']))){
-      $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
-    }
-  
-    /* check servers matching release and section settings */
-    $availableServer = array();
-    foreach($this->mirrors as $mir){
-      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'];
-          }
-        }
-      }
-    }
     /* Generate package list */
     $this->list=$this->genPkgs();
 
@@ -239,7 +205,7 @@ class faiPackage extends plugin
 
     /* Configuration dialog open*/
     if((isset($_POST['Conpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages']))){
-      $path = "/etc/gosa/fai/".preg_replace("#^[^/]+//([^/]+).*$#","\\1",$this->FAIdebianMirror)."/".$this->FAIdebianRelease."/debconf.d";
+      $path = "/etc/gosa/fai/".$this->FAIdebianRelease."/debconf.d";
       $pkg_config = array();
       if(isset($this->ConfiguredPackages[$_POST['usedPackages']])){
         $pkg_config = $this->ConfiguredPackages[$_POST['usedPackages']];
@@ -274,12 +240,7 @@ class faiPackage extends plugin
     }
 
     $smarty->assign("OptionsACL","");
-    if(empty($this->FAIdebianMirror)){
-      $smarty->assign("OptionsACL"," disabled ");
-    }
 
-    $smarty->assign("mirrors" ,$availableServer);
-    $smarty->assign("mirror"  ,$this->FAIdebianMirror);
     $smarty->assign("releases",$this->releases);
     $smarty->assign("release" ,$this->FAIdebianRelease);
     $smarty->assign("sections",$this->sections);
@@ -289,60 +250,6 @@ class faiPackage extends plugin
     return($display);
   }
 
-  function genMirror(){
-    $confDir = $this->confDir; 
-    if(!is_readable($confDir)){
-      print_red(sprintf(_("Can't read configuration folder '%s'."),$confDir));
-    }else{
-      
-      /* Try to catch all available mirrors 
-         Possibly check if each server is reachable
-       */
-
-      $this->servers= array();
-      $this->releases=array();  
-      $this->sections=array(); 
-      $this->mirrors= array();
-      $fd = opendir($confDir);
-      while($mirror = readdir($fd)){
-        if((is_dir($confDir.$mirror."/"))&&(($mirror != "." )&&($mirror!=".."))){
-
-          $mirrorDir = $confDir.$mirror."/";
-
-          $fe = opendir($mirrorDir);
-          while($release = readdir($fe)){
-            if((is_dir($mirrorDir.$release))&&(($release != "." )&&($release!=".."))){
-
-              $releaseDir = $mirrorDir.$release."/";
-
-              $ff = opendir($releaseDir);
-              while($section = readdir($ff)){
-                if((is_file($releaseDir.$section))&&(($section != "." )&&($section!="..")&&(!preg_match("/.*\.in$/",$section)))){
-              
-                  $this->servers[$mirror]=$mirror;
-                  $this->releases[$release]=$release;
-                  $this->sections[$section]=$section;
-
-                  $arr=array();
-                  $arr['mirror'] = $mirror;
-                  $arr['release']= $release; 
-                  $arr['section']= $section;
-                  $this->mirrors[] = $arr ;
-                }
-              }
-              fclose($ff);
-            }
-          }
-          fclose($fe);
-        }
-      }
-      fclose($fd);
-    }
-
-
-  }
-
   /* Delete me, and all my subtrees
    */
   function remove_from_parent()
@@ -377,7 +284,7 @@ class faiPackage extends plugin
       $message[]=_("Please select a least one Package.");
     }
   
-    if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))||(empty($this->FAIdebianMirror))){
+    if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
       $message[]=_("Please choose a valid combination for your repository setup.");
     }
 
@@ -420,11 +327,10 @@ class faiPackage extends plugin
       $this->buffer=array();
       $a_ret = array();
       foreach($this->FAIdebianSection as $sec){
-        $strID= "/etc/gosa/fai/".preg_replace("#^[^/]+//([^/]+).*$#","\\1",$this->FAIdebianMirror)."/".$this->FAIdebianRelease."/".$sec;
+        $strID= "/etc/gosa/fai/".$this->FAIdebianRelease."/".$sec;
         
         if(!is_file($strID)){
           print_red(sprintf(_("Package file '%s' does not exist."),$strID));
-          $this->FAIdebianMirror="";
           unset($this->buffer);
           return(array());
         }
index 485e561cfe34d6f660fd4a42754102674a230935..b90107a990fe52a31aa8f42feccd4e634a0b426a 100644 (file)
@@ -12,183 +12,115 @@ class faiPackageNew extends plugin
   var $attributes         = array();
   var $objectclasses      = array();
  
-  var $mirrors            = array(); // The possible mirror,release and section combinations
-  var $servers            = array(); // All available server
   var $sections           = array(); // All sections
   var $releases           = array(); // Releases 
 
-  var $FAIdebianRelease   = "";     // The selected release
-  var $FAIdebianSection   = array();     // selected section
-  var $FAIdebianMirror    = "";     // selected mirror
-
+  var $FAIdebianRelease   = "";           // The selected release
+  var $FAIdebianSection   = array();      // selected section
 
   var $obj;
 
-  function faiPackageNew ($config, $dn= NULL,$mirrors,$servers,$sections,$releases)
+  function faiPackageNew ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
-    $this->mirrors  = $mirrors;
-    $this->servers  = $servers;
-    $this->sections = $sections;
-    $this->releases = $releases;
-
-    foreach($this->sections as $sec){
-      $this->sections[$sec]  =false;
-    }
   }
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
-
-    /* Fill templating stuff */
-    $smarty     = get_smarty();
+         /* Call parent execute */
+         plugin::execute();
     $display = "";
-
-    // reset grayout options 
-    $disableRelease   = false;
-    $disableMirror    = false;
-    $disableContinue  = false;
-    $disableSection   = false;
-
-    /* Post handling for Section, Release and Mirror Setup */
-    if(isset($_POST['SetRepository'])){
-      foreach($this->sections as $sec => $val){
-        if(isset($_POST[$sec])){
-          $this->sections[$sec]=true;
-          $this->FAIdebianSection[$sec]=$sec;
-        }else{
-          $this->sections[$sec]=false;
-        }
-      }
-    
+    $smarty = get_smarty(); 
+    $atr = $this->getServerInfos(); 
+    foreach($atr as $release => $sections){
+      $releases[$release]=$release;
     }
-
-    /* Grayout settings */    
-    if(empty($this->FAIdebianRelease)){
-      $disableSection = $disableMirror  = $disableContinue = true;
-    }elseif(empty($this->FAIdebianSection)){
-      $disableRelease = $disableMirror  = $disableContinue = true;
-    }elseif(empty($this->FAIdebianMirror)){
-      $disableRelease = $disableSection =  true;
+    if(!empty($this->FAIdebianRelease)){
+      $sections = $atr[$this->FAIdebianRelease] ;
     }else{
-      $disableRelease = $disableSection =  true;
-    }
-
-    /* check servers matching release and section settings */
-    $availableServer = array();
-    foreach($this->mirrors as $mir){
-    
-      /* Check if release and section match */
-      if($mir['release'] == $this->FAIdebianRelease){
-        $pass = true;
-    
-        foreach($this->FAIdebianSection as $sec){
-
-        /* If a mirror match, attach */
-          if($sec != $mir['section']){
-            $pass = false;
-          }
-
-        /* Save all matching */ 
-        if($pass){
-            $availableServer[$mir['mirror']]=$mir['mirror'];
-          }
-        }
-      }
+      $sections = array();
     }
 
-    /* If no servers matching the settings, allow setting release and section again */
-    if(($disableMirror==false)&&(count($availableServer)==0)){
-      $this->FAIdebianRelease = $this->FAIdebianMirror = "";
-      $this->FAIdebianSection = array();
-      $disableSection = $disableMirror  = $disableContinue = true;
-      $disableRelease = false;
+    /* Fill templating stuff */
+    if((empty($this->FAIdebianRelease))||(count($this->FAIdebianSection)==0)){
+      $smarty->assign("goon"," disabled ");
+    }else{
+      $smarty->assign("goon"," ");
     }
 
-    /* Create checkboxes for the avaliable sections */
-    $strsec = "<table><tr>";
-    foreach($this->sections as $sec => $val){
-
-      /* Only add this section if it is supported by the selected release */
-      $goon = false;
-      foreach($this->mirrors as $mir){
-
-        /* Is there a release with this section ? */
-        if((($mir['release'] == $this->FAIdebianRelease )&&($mir['section'] == $sec))){
-          $goon = true; 
-        }
-      }
+    $smarty->assign("releases"    ,$releases);
+    $smarty->assign("releaseKeys" ,array_flip($releases));
+    $smarty->assign("release" ,$this->FAIdebianRelease);
+    $smarty->assign("sections",$this->generateSections($sections));
 
-      if($goon){
-        if($this->sections[$sec] == true ){
-          $chk = " checked ";
-        }else{
-          $chk = "";
-        }
+    $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
+    return($display);
+  }
 
-        /* Add disabled if needed */
-        if($disableSection){
-          $strsec .= "<td><input type='checkbox' name='".$sec."' disabled ".$chk.">".$sec."</td>";
+  function generateSections($secs)
+  {
+    $str = "";
+    if(is_array($secs)){
+      $rel  = " onClick='document.mainform.submit();' ";
+      foreach($secs as $section){
+        if(in_array($section,$this->FAIdebianSection)){
+          $str .= "<input ".$rel." type='checkbox' value='".$section."' name='section_".$section."' checked>".$section."<br>";
         }else{
-          $strsec .= "<td><input type='checkbox' name='".$sec."' ".$chk.">".$sec."</td>";
+          $str .= "<input ".$rel." type='checkbox' value='".$section."' name='section_".$section."'>".$section."<br>";
         }
       }
     }
-    $strsec .= "</table>";
-    
-    /* Add --- to mirror selectbox if it is empty */
-    if(count($availableServer)==0){
-      $availableServer=array("---");
-    }
-
-    /* Tell smarty the grayout settigs */
-    $smarty->assign("ReleaseACL"  , "");
-    $smarty->assign("MirrorACL"   , "");
-    $smarty->assign("ContinueACL" , "");
-    $smarty->assign("SectionACL"  , "");
+    return($str); 
+  }
 
-    if($disableContinue){
-      $smarty->assign("ContinueACL"," disabled ");
-    }
-    if($disableRelease){
-      $smarty->assign("ReleaseACL"," disabled ");
-    }
-    if($disableMirror){
-      $smarty->assign("MirrorACL"," disabled ");
-    }
-    if($disableSection){
-      $smarty->assign("SectionACL"," disabled ");
+  function getServerInfos()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
+    while($attrs = $ldap->fetch()){
+      if(isset($attrs['FAIrepository'])){
+        for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
+          $obj = $attrs['FAIrepository'][$i];
+          $tmp = split("\|",$obj);
+          if(count($tmp)==4){
+            foreach(split(",",$tmp[3]) as $sec){
+              if(!empty($sec)){
+                $ret[$tmp[2]][] =  $sec;
+              }
+            }
+          }
+        } 
+      }
     }
-
-
-    $smarty->assign("DisSection",!empty($this->FAIdebianSection));
-    $smarty->assign("DisRelease",!empty($this->FAIdebianRelease));
-
-    $smarty->assign("mirrors" ,$availableServer);
-    $smarty->assign("mirror"  ,$this->FAIdebianMirror);
-    $smarty->assign("releases",$this->releases);
-    $smarty->assign("release" ,$this->FAIdebianRelease);
-    $smarty->assign("sections",$strsec);
-    $smarty->assign("section" ,$this->FAIdebianSection);
-
-    $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
-    return($display);
+    return($ret);
   }
 
+
   /* Save data to object */
   function save_object()
   {
-    if(isset($_POST['SetRepository'])){
-      /* Post handling for Section, Release and Mirror Setup */
-      if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
-        $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
+    /* Post handling for Section, Release  Setup */
+    if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
+      $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
+    }
+
+    /* Get Sections */
+    foreach($_POST as $name => $value){
+      if(preg_match("/^section_/",$name)){
+        $this->FAIdebianSection[$value] = $value;
       }
-      if((isset($_POST['FAIdebianMirrorS']))&&(!empty($_POST['FAIdebianMirrorS']))){
-        $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
+    }
+
+    /* Remove all section that are not available at the currently selected server */ 
+    $atr = $this->getServerInfos();
+    foreach($this->FAIdebianSection as $section){
+      if(!in_array($section,$atr[$this->FAIdebianRelease])){
+        unset($this->FAIdebianSection[$section]);
       }
     }
+
   }
 
   /* Check supplied data */
@@ -200,6 +132,7 @@ class faiPackageNew extends plugin
 
   function save()
   {
+    return(array("FAIdebianRelease"=>$this->FAIdebianRelease,"FAIdebianSection"=>$this->FAIdebianSection));
   }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 61d76f2568b3bdbb0f1fd1f71710799323052ef2..99b946090f9f48f348c20300d755961a3b9ddbc4 100644 (file)
                                                        {$section}
                                                </td>
                                        </tr>
-                                       <tr>
-                                               <td>
-                                                       <LABEL for="mirror">
-                                                       {t}Mirror{/t}
-                                                       </LABEL>
-                                               </td>
-                                               <td>
-                                                       <select name="FAIdebianMirrorS" title="{t}mirror{/t}">
-                                                               {html_options options=$mirrors selected=$mirror}
-                                                       </select>
-                                                       <input type="submit" value="{t}set{/t}" name="SetMirror">
-                                               </td>
-                                       </tr>
                                </table>
                </td>
        </tr>
index 3e54019e4a6142977e6307007bf6a7240ee3fa21..2325d330434887fef2b67c44b649d558da52db24 100644 (file)
                </h2>
        </td>
        <td>
-               <select name="FAIdebianReleaseS" title="{t}Release{/t}" {$ReleaseACL}>
-                       {html_options options=$releases selected=$release}
+               <select name="FAIdebianReleaseS" title="{t}Release{/t}">
+                       {html_options options=$releases values=$releaseKeys selected=$release}
                </select>
        </td>
 </tr>
-{if $DisRelease neq false}
 <tr>
        <td height="30">
         <h2>{t}Sections for this release{/t}: </h2> 
        </td>
        <td>
                {$sections} 
+               <input type="submit" value="{t}set{/t}" name="SetRepository">
        </td>
 </tr>
-{/if}
-{if $DisSection neq false}
-<tr>
-       <td height="30">
-               <h2><LABEL for="mirror">{t}Matching mirrors{/t}</LABEL>: </h2>
-       </td>
-       <td>
-               <select name="FAIdebianMirrorS" title="{t}mirror{/t}" {$MirrorACL}>
-                       {html_options options=$mirrors selected=$mirror}
-               </select>
-       </td>
-</tr>
-{/if}
 </table>
-{if $ContinueACL neq ""}
-<input type="submit" value="{t}set{/t}" name="SetRepository">
-{/if}
 <p class="seperator">&nbsp;
 </p>
 
 <div align="right" style="align:right;">
-    <input name="SaveObjectNew" value="{t}Continue{/t}" type="submit" {$ContinueACL}>
+    <input name="SaveObjectNew" value="{t}Continue{/t}" type="submit" {$goon}>
     <input name="edit_cancel" value="{t}Cancel{/t}" type="submit">
 </div>