Code

Replaced in_array calls with in_array_strict
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPackage.inc
index 88fb15dc02268bb1c8cf4c00004457a2dd5380e3..703f197cbf68a50531adedcc830c9d7f017882bf 100644 (file)
@@ -47,6 +47,8 @@ class faiPackage extends plugin
   var $base;
   var $FAIpackage ;
 
+  var $packageSelect ;
+
   var $FAIinstallMethods  = array( "install", "ninstall", "remove", 
       "dselect-upgrade", "taskinst", "taskrm",
       "hold", "clean", "aptitude", "aptitude-r",
@@ -107,7 +109,7 @@ class faiPackage extends plugin
         $tmp['Type']  = $attr['FAIvariableType'][0];
 
         if (isset($attr['FAIvariableContent'][0])){
-          if(!in_array($attr['FAIvariableType'],array("multiselect"))){
+          if(!in_array_strict($attr['FAIvariableType'],array("multiselect"))){
             $tmp['Value'] = $attr['FAIvariableContent'][0];
           }else{
             $content = array();        
@@ -148,6 +150,16 @@ class faiPackage extends plugin
 
     /* Generate package list */
     $this->list= $this->genPkgs(TRUE);
+
+    // Prepare lists
+    $this->packageList = new sortableListing();
+    $this->packageList->setDeleteable(false);
+    $this->packageList->setEditable(false);
+    $this->packageList->setWidth("100%");
+    $this->packageList->setHeight("200px");
+    $this->packageList->setColspecs(array('20px','*','*','100px','60px'));
+    $this->packageList->setHeader(array(_("Status"),_("Name"),_("Description"),_("Version")));
+    $this->packageList->setDefaultSortColumn(1);
   }
 
 
@@ -173,9 +185,9 @@ class faiPackage extends plugin
 
       /* Assemble release name */
       $release = $this->parent->parent->fai_release;
-      $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $release);
+      $tmp= preg_replace('/[,]*'.preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').'.*$/i', '', $release);
       $tmp= preg_replace('/ou=/', '', $tmp);
-      $rev= array_reverse(split(',', $tmp));
+      $rev= array_reverse(explode(',', $tmp));
       $this->FAIdebianRelease= "/";
       foreach ($rev as $part){
         $this->FAIdebianRelease.= "/$part";
@@ -207,6 +219,7 @@ class faiPackage extends plugin
       // Check all splitted packages for valid package names
       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
       if( is_array($add_packages) ) {
+        $valid_packages = array();
         $invalid_packages = array();
         foreach ($add_packages as $value) {
           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
@@ -271,12 +284,46 @@ class faiPackage extends plugin
       }
     }
 
-    /* + was pressed to open the package dialog */
-    if(isset($_POST['Addpkg']) && 
-        $this->acl_is_writeable("FAIpackage") && 
-        !preg_match("/freeze/",$this->FAIstate)){
-      $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
-      $this->is_dialog =true;
+    // Open the packageSelect dialog to allow adding packages out of a list.
+    if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
+      $this->packageSelect = new packageSelect($this->config, get_userinfo());
+      session::set('packageSelect_Release',$this->FAIdebianRelease);
+      $this->dialog =true;
+    }
+
+    // Close packageSelect dialog.
+    if(isset($_POST['packageSelect_cancel'])){
+      $this->packageSelect = FALSE;
+      $this->dialog =FALSE;
+    }
+
+    // Close packageSelect dialog and add the selected packages.
+    if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){
+      if(!preg_match("/freeze/i", $this->FAIstate)){
+        $use = $this->packageSelect->save();
+
+        foreach($use as $pkg){
+          $item = array();
+          for($i =0; $i < $pkg['count']; $i++){
+            $item[$pkg[$i]] = $pkg[$pkg[$i]][0];
+          }
+          $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; 
+        }
+
+        ksort($this->usedPackages);
+
+        /* Generate package list */
+        $this->list= $this->genPkgs(TRUE);
+      }
+      $this->packageSelect = FALSE;
+      $this->dialog =FALSE;
+    }
+
+    // Display package add dialog 
+    if($this->packageSelect instanceOf packageSelect){
+
+      session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages));
+      return $this->packageSelect->execute();
     }
 
 
@@ -289,7 +336,7 @@ class faiPackage extends plugin
        ******/
       
       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
-        $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
+        $id = @postDecode(preg_replace("/^removal_package_(.*)$/","\\1",$name));
         if(isset($this->usedPackages[$id])){
           $pkg = $this->usedPackages[$id]; 
           if (preg_match('/\-$/', $pkg)){
@@ -306,7 +353,7 @@ class faiPackage extends plugin
        * Delete Pkgs   
        ******/
       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
-        $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
+        $id = @postDecode(preg_replace("/^remove_package_(.*)$/","\\1",$name));
         if(isset($this->usedPackages[$id])){
           unset($this->usedPackages[$id]);
         }
@@ -317,7 +364,7 @@ class faiPackage extends plugin
        * Configure Pkgs   
        ******/
       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
-        $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
+        $pkg = @postDecode(preg_replace("/^configure_package_(.*)$/","\\1",$name));
          
         if(isset($this->usedPackages[$pkg])){
 
@@ -339,30 +386,6 @@ class faiPackage extends plugin
       $this->is_dialog=false;
     }
 
-    /* attach new packages */
-    if(isset($_POST['SaveSubObject'])) {
-      if(!preg_match("/freeze/i", $this->FAIstate)){
-        $this->dialog->save_object();
-        if(count($this->dialog->check())){
-          foreach($this->dialog->check() as $msgs){
-            msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
-          }
-        }else{
-          $use = $this->dialog->save();
-          $this->usedPackages = $use;
-          $this->dialog = false;
-          $this->is_dialog=false;
-          ksort($this->usedPackages);
-
-          /* Generate package list */
-          $this->list= $this->genPkgs(TRUE);
-        }
-      }else{
-        $this->dialog = false;
-        $this->is_dialog=false;
-      }
-    }
-
     /* Save Configuration */
     if(isset($_POST['SaveObjectConfig'])){
       if(!preg_match("/^freeze/", $this->FAIstate)){
@@ -389,69 +412,65 @@ class faiPackage extends plugin
      * Display UI / HTML / smarty 
      ******/
 
-    /* Create divlist to display a list of all currently used packages
+    /* Create list to display a list of all currently used packages
      */
-    $divlist = new divSelectBox("faiPackages");
-
-    ksort($this->usedPackages);
+    $data = $lData = array();
     if(is_array($this->usedPackages)){
-      foreach($this->usedPackages as $usedName => $name){
-    
-        $actions = "";
+        foreach($this->usedPackages as $usedName => $name){
 
-        /* Append message if package is configured */
-        $configured = "<img src='images/empty.png' alt=' '  class='center'>";
-        if(isset($this->ConfiguredPackages[$usedName])){
-          $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
-                      title='"._("Configured")."' class='center'>";
-        }
+            /* Append message if package is configured */
+            $configured = image('images/empty.png');
+            if(isset($this->ConfiguredPackages[$usedName])){
+                $configured = image('plugins/fai/images/package_configure.png','',_("Configured"));
+            }
 
-        /* Adapt used name if we're marked for removal */
-        $removal = "<img src='images/empty.png' alt=' '  class='center'>";
-        if (preg_match('/\-$/', $name)){
-          $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
-                      title='"._("Package marked for removal")."' class='center'>";
-        }
+            /* Adapt used name if we're marked for removal */
+            $removal = image('images/empty.png');
+            if (preg_match('/\-$/', $name)){
+                $removal = image('plugins/fai/images/removal_mark.png','',_("Package marked for removal"));
+            }
 
-        /* Get Version */
-        $version = "&nbsp;";
-        if(isset($this->list[$usedName]['VERSION'])){
-          $version = $this->list[$usedName]['VERSION'];
-        }
-    
-        /* Get description */
-        $description = "&nbsp;";
-        if(isset($this->list[$usedName]['DESCRIPTION'])){
-          $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
-        }
-        if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
-          $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
-            src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
-        }
+            /* Get Version */
+            $version = "";
+            if(isset($this->list[$usedName]['VERSION'])){
+                $version = $this->list[$usedName]['VERSION'];
+            }
 
-        if(isset($this->list[$usedName]['TEMPLATE']) && 
-           !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
-          $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
-            src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
-        }
-        if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
-          $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
-            src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
-        }
+            /* Get description */
+            $description = "";
+            if(isset($this->list[$usedName]['DESCRIPTION'])){
+                $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
+            }
 
-        $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
-        $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
-        $field3 = array("string" => $version);
-        $field4 = array("string" => $description);
-        $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
-        $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
-      }
+            $actions= image('plugins/fai/images/removal_mark.png',
+                    'removal_package_'.postEncode($usedName),
+                    _("Mark package for removal"));
+
+            if(isset($this->list[$usedName]['TEMPLATE']) && 
+                    !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
+                $actions.= image('plugins/fai/images/package_configure.png',
+                        'configure_package_'.postEncode($usedName),
+                        _("Configure this package"));
+            }
+            if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
+                $actions.= image('images/lists/trash.png',
+                        'remove_package_'.postEncode($usedName),
+                        _("Remove this package"));
+            }
+            $data[$usedName] = $usedName;
+            $lData[$usedName] = array('data'=>
+                    array(
+                        $configured."&nbsp;".$removal,
+                        $usedName ,set_post($description), $version, $actions));
+        }
     }
+    $this->packageList->setAcl($this->getacl("FAIpackage",preg_match('/^freeze/', $this->FAIstate)));
+    $this->packageList->setListData($data,$lData);
+    $this->packageList->update();
 
     /* Assign variables */
     foreach($this->attributes as $attrs){
-      $smarty->assign($attrs,$this->$attrs);
+      $smarty->assign($attrs,set_post($this->$attrs));
     }
     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
 
@@ -467,7 +486,7 @@ class faiPackage extends plugin
     }
  
     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
-    $smarty->assign("divlist",$divlist->DrawList());
+    $smarty->assign("listing",$this->packageList->render());
     $smarty->assign("release" ,$this->FAIdebianRelease);
     $smarty->assign("sections",$this->sections);
     $smarty->assign("section" ,$strsec);
@@ -526,7 +545,7 @@ class faiPackage extends plugin
      */
     if($this->is_new){
       $release = $this->parent->parent->fai_release;
-      $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
+      $new_dn= 'cn='.$this->cn.",".get_ou("faiPackage", "faiPackageRDN").get_ou("faiManagement", "faiBaseRDN").$release;
       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
       if(isset($res[$this->cn])){
         $message[] = msgPool::duplicated(_("Name"));
@@ -571,9 +590,9 @@ class faiPackage extends plugin
     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
 
       $current_release  = $this->parent->parent->fai_release;
-      $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $current_release);
+      $tmp= preg_replace('/,'.preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').'.*$/i', '', $current_release);
       $tmp= preg_replace('/ou=/', '', $tmp);
-      $rev= array_reverse(split(',', $tmp));
+      $rev= array_reverse(explode(',', $tmp));
       $this->FAIdebianRelease= "";
       foreach ($rev as $part){
         $this->FAIdebianRelease.= "/$part";
@@ -627,7 +646,7 @@ class faiPackage extends plugin
         /* Tag object */
         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
 
-        if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
+        if(in_array_strict($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
 
           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
@@ -653,14 +672,26 @@ class faiPackage extends plugin
           "plPriority"    => 28,
           "plSection"     => array("administration"),
           "plCategory"    => array("fai"),
+          "plProperties" =>
+          array(
+              array(
+                  "name"          => "faiPackageRDN",
+                  "type"          => "rdn",
+                  "default"       => "ou=packages,",
+                  "description"   => _("RDN for FAI package storage."),
+                  "check"         => "gosaProperty::isRdn",
+                  "migrate"       => "migrate_faiPackageRDN",
+                  "group"         => "plugin",
+                  "mandatory"     => TRUE)),
+
           "plProvidedAcls" => array(
             "cn"                => _("Name"),
             "description"       => _("Description"),
             "FAIpackage"        => _("Packages"),
-            "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
+            "FAIdebianSection"  => _("Section")."&nbsp;("._("Read-only").")",
             "FAIinstallMethod"  => _("Install Method"),
             "FAIdebconfInfo"    => _("Package configuration"),
-            "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
+            "FAIdebianRelease"  => _("Release")."&nbsp;("._("Read-only").")")
           ));
   }
 
@@ -724,7 +755,7 @@ class faiPackage extends plugin
       $tmp['Type']  = $attr['FAIvariableType'][0];
 
       if (isset($attr['FAIvariableContent'][0])){
-        if(!in_array($attr['FAIvariableType'],array("multiselect"))){
+        if(!in_array_strict($attr['FAIvariableType'],array("multiselect"))){
           $tmp['Value'] = $attr['FAIvariableContent'][0];
         }else{
           $content = array();        
@@ -752,9 +783,9 @@ class faiPackage extends plugin
       if(isset($attrs['FAIrepository'])){
         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
           $obj = $attrs['FAIrepository'][$i];
-          $tmp = split("\|",$obj);
+          $tmp = explode("|",$obj);
           if(count($tmp)==4){
-            foreach(split(",",$tmp[3]) as $sec){
+            foreach(explode(",",$tmp[3]) as $sec){
               if(!empty($sec)){
                 $ret[$tmp[2]][] =  $sec;
               }
@@ -775,7 +806,7 @@ class faiPackage extends plugin
   {
     $vars = array("cn");
     $smarty = get_smarty();
-    $smarty->assign("cn", htmlentities($this->cn));
+    $smarty->assign("cn", set_post($this->cn));
     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
     $ret = array();
     $ret['string'] = $str;