Code

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1522 594d385d-05f5-0310...
[gosa.git] / plugins / admin / fai / class_faiPackage.inc
index eb27521f5c591d5c891999b72a8ba5c20b71c9c7..de42cecfb929b592940532a6697e304d723fe129 100644 (file)
@@ -11,10 +11,10 @@ class faiPackage extends plugin
   var $ignore_account   = TRUE;
 
   /* Attributes for this Object */
-  var $attributes       = array("cn","description","FAIpackage","section","mirror","release");
+  var $attributes       = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection","FAIdebianMirror");
 
   /* ObjectClasses for this Object*/
-  var $objectclasses    = array("top","FAIclass","FAIpackageList");
+  var $objectclasses    = array("top","FAIclass","FAIpackageList","FAIrepository");
 
   /* Class name of the Ldap ObjectClass for the Sub Object */
   var $subClass         = "";
@@ -34,16 +34,17 @@ class faiPackage extends plugin
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
   var $SubObjects       = array();  // All leafobjects of this object
 
-  var $section          = ""; // The selected section
-  var $release          = ""; // selected release
-  var $mirror           = ""; // selected mirror
+  var $FAIdebianRelease          = ""; // The selected release
+  var $FAIdebianSection          = ""; // selected section
+  var $FAIdebianMirror           = ""; // selected mirror
 
   var $servers          = array();  // All available servers
-  var $sections         = array();  // All possible section
-  var $releases         = array();  // All release types
+  var $releases         = array();  // All possible release
+  var $sections         = array();  // All section types
 
-  var $mirrors          = array();  // The combination of server/section/release
+  var $mirrors          = array();  // The combination of server/release/section
   var $confDir          = "";
+  var $usedPackages     = array();
 
   function faiPackage ($config, $dn= NULL)
   {
@@ -58,8 +59,16 @@ class faiPackage extends plugin
       $this->dn =$dn;
     }
 
+    if(isset($this->attrs['FAIpackage'])){
+      unset($this->attrs['FAIpackage']['count']);
+      foreach($this->attrs['FAIpackage'] as $pkg){
+        $this->usedPackages[$pkg] = $pkg;
+      }
+    }else{
+      $this->usedPackages = array();
+    }  
     $this->confDir = CONFIG_DIR."/fai/";
-    $this->FAIpackage = "test";
+    $this->FAIpackage = array();
   }
 
   function execute()
@@ -68,15 +77,112 @@ class faiPackage extends plugin
     $smarty= get_smarty();
     $display= "";
 
+    $disableRelease   = false;
+    $disableMirror    = false;
+    $disableOptions   = false;
+    $disableSection   = false;
+
     /* Assign variables */
     foreach($this->attributes as $attrs){
       $smarty->assign($attrs,$this->$attrs);
     }
 
-    /* Second try */
-    
-    /* Check available server entries in CONFIG_DIR/fai 
-     */
+    /* 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;
+    }elseif(empty($this->FAIdebianSection)){
+      $disableRelease = $disableMirror  = $disableOptions = true;
+    }elseif(empty($this->FAIdebianMirror)){
+      $disableRelease = $disableSection = $disableOptions = true;
+    }else{
+      $disableRelease = $disableSection =  true;
+    }
+
+    $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->genMirror();
+
+    $availableServer = array();
+    foreach($this->mirrors as $mir){
+      if(($mir['release'] == $this->FAIdebianRelease)&&($mir['section']==$this->FAIdebianSection)){
+        $availableServer[$mir['mirror']]=$mir['mirror'];
+      }
+    }
+
+    if($disableMirror){
+      $availableServer[$mir['mirror']]=array("---");
+    }
+
+    if(isset($_POST['Addpkg'])){
+      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->confDir.$this->FAIdebianMirror."/".$this->FAIdebianRelease."/".$this->FAIdebianSection,$this->usedPackages);
+      $this->is_dialog =true;
+    }
+    if(isset($_POST['Delpkg'])){
+      unset($this->usedPackages[$_POST['usedPackages']]);
+    }
+    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();
+    }
+
+    $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("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));
@@ -85,6 +191,10 @@ class faiPackage extends plugin
       /* 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)){
@@ -93,33 +203,33 @@ class faiPackage extends plugin
           $mirrorDir = $confDir.$mirror."/";
 
           $fe = opendir($mirrorDir);
-          while($section = readdir($fe)){
-            if((is_dir($mirrorDir.$section))&&(($section != "." )&&($section!=".."))){
+          while($release = readdir($fe)){
+            if((is_dir($mirrorDir.$release))&&(($release != "." )&&($release!=".."))){
 
-              $sectionDir = $mirrorDir.$section."/";
+              $releaseDir = $mirrorDir.$release."/";
 
-              $ff = opendir($sectionDir);
-              while($release = readdir($ff)){
-                if((is_file($sectionDir.$release))&&(($release != "." )&&($release!="..")&&(!preg_match("/.*\.in$/",$release)))){
+              $ff = opendir($releaseDir);
+              while($section = readdir($ff)){
+                if((is_file($releaseDir.$section))&&(($section != "." )&&($section!="..")&&(!preg_match("/.*\.in$/",$section)))){
               
                   $this->servers[$mirror]=$mirror;
-                  $this->sections[$section]=$section;
                   $this->releases[$release]=$release;
+                  $this->sections[$section]=$section;
 
-                  if(empty($this->mirror)){
-                    $this->mirror= $mirror;
+                  if(empty($this->FAIdebianRelease)){
+                    $this->servers= array("---");
                   }
-                  if(empty($this->section)){
-                    $this->section = $section;
+                  if(empty($this->FAIdebianSection)){
+                    $this->releases= array("---");
                   }
-                  if(empty($this->release)){
-                    $this->release = $release;
+                  if(empty($this->FAIdebianSection)){
+                    $this->FAIdebianSection = $section;
                   }                    
 
                   $arr=array();
                   $arr['mirror'] = $mirror;
-                  $arr['section']= $section
-                  $arr['release']= $release;
+                  $arr['release']= $release
+                  $arr['section']= $section;
  
                   $this->mirrors[] = $arr ;
                 }
@@ -133,32 +243,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
@@ -176,6 +261,7 @@ class faiPackage extends plugin
    */
   function save_object()
   {
+    
     plugin::save_object();
     foreach($this->attributes as $attrs){
       if(isset($_POST[$attrs])){
@@ -189,13 +275,27 @@ class faiPackage extends plugin
   function check()
   {
     $message= array();
-    $str = utf8_encode("üöä");
-    if((preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->description))){
-      $message[]=_("Please enter a valid description.");
+  
+    if(count($this->usedPackages)==0){
+      $message[]=_("Please select a least one Package.");
     }
+  
+    if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))||(empty($this->FAIdebianMirror))){
+      $message[]=_("Please choose a valid combination for your repository setup.");
+    }
+
     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 +303,12 @@ 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;
+    } 
+
     $ldap->cat($this->dn);
     if($ldap->count()!=0){
       /* Write FAIscript to ldap*/