Code

Updated package selection
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPackage.inc
1 <?php
3 class faiPackage extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account   = TRUE;
8   /* Attributes for this Object */
9   var $attributes       = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection", "FAIinstallMethod");
11   /* ObjectClasses for this Object*/
12   var $objectclasses    = array("top","FAIclass","FAIpackageList","FAIrepository");
14   /* Class name of the Ldap ObjectClass for the Sub Object */
15   var $subClass         = "";
16   var $subClasses       = array("top","FAIclass","FAIscriptEntry");
18   /* Class name of the php class which allows us to edit a Sub Object */
19   var $subClassName     = "";      
21   /* Attributes to initialise for each subObject */
22   var $subAttributes    = array("cn","description"); 
23   var $sub64coded       = array();
25   var $ConfiguredPackages = array();
27   /* Specific attributes */
28   var $cn               = "";       // The class name for this object
29   var $description      = "";       // The description for this set of partitions
30   var $is_dialog        = false;    // specifies which buttons will be shown to save or abort
31   var $SubObjects       = array();  // All leafobjects of this object
33   var $FAIdebianRelease          = ""; // The selected release
34   var $FAIdebianSection          = array(); // selected section
35   var $FAIinstallMethod          = "aptitude"; // hard coded
37   var $sections         = array();  // All section types
39   var $list             = NULL;
41   var $usedPackages     = array();
42   var $buffer           = NULL; 
43   var $newDialogShown   = false;
45   var $FAIstate         = "";
46   var $view_logged      = FALSE;
47   var $base;
48   var $FAIpackage ;
50   var $packageSelect ;
52   var $FAIinstallMethods  = array( "install", "ninstall", "remove", 
53       "dselect-upgrade", "taskinst", "taskrm",
54       "hold", "clean", "aptitude", "aptitude-r",
55       "pending", "dpkgc" );
58   function faiPackage (&$config, $dn= NULL)
59   {
60     /* Load Attributes */
61     plugin::plugin ($config, $dn);
63     /* If "dn==new" we try to create a new entry
64      * Else we must read all objects from ldap which belong to this entry.
65      * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
66      */
67     if($dn != "new"){
68       $this->dn =$dn;
70       /* Check if there are already some packages in this list 
71        */
72       $this->usedPackages = array();
73       if(isset($this->attrs['FAIpackage'])){
74         unset($this->attrs['FAIpackage']['count']);
75         foreach($this->attrs['FAIpackage'] as $pkg){
76           $name = preg_replace("/\-$/","",$pkg);
77           $this->usedPackages[$name] = $pkg;
78         }
79         ksort($this->usedPackages);
80       }  
82       /* Fetch all package configurations from ldap 
83        */
84       $PackageFilter = "";
85       foreach($this->usedPackages as $name => $value){
86         $PackageFilter .= "(FAIpackage=".$name.")";
87       }
88       $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
90       /* Search for configuration objects */ 
91       $ldap = $this->config->get_ldap_link();
92       $ldap->cd($this->dn);
93       $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
94             "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
96       /* Walk through configurations and append them to our list of ConfiguredPackages 
97        */
98       while($attr = $ldap->fetch()){
100         /* Skip objects, that are tagged as removed */
101         if(isset($object['FAIstate'][0])){
102           if(preg_match("/removed$/",$attr['FAIstate'][0])){
103             continue;
104           }
105         }
107         $tmp =array(); 
108         $tmp['Name']  = $attr['FAIvariable'][0];
109         $tmp['Type']  = $attr['FAIvariableType'][0];
111         if (isset($attr['FAIvariableContent'][0])){
112           if(!in_array($attr['FAIvariableType'],array("multiselect"))){
113             $tmp['Value'] = $attr['FAIvariableContent'][0];
114           }else{
115             $content = array();        
116             unset($attr['FAIvariableContent']['count']);
117             foreach($attr['FAIvariableContent'] as $attr){
118               $tmp['Value'][] = $attr;
119             }
120           }
121           $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
122         }
123       }
125       $this->FAIdebianSection = array();
126       if(isset($this->attrs['FAIdebianSection'])){
127         for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){ 
128           $sec = $this->attrs['FAIdebianSection'][$i];
129           $this->FAIdebianSection[$sec]=$sec;
130         }
131       }
132       $this->FAIpackage = array();
134     } // ENDE  dn != new  
136     $methods = array();
137     foreach($this->FAIinstallMethods as $method){
138       $methods[$method] = $method;
139     }
140     $this->FAIinstallMethods = $methods;
142     /* Check if we exist already - no need to ask for revisions, etc. then */
143     if ($this->dn != "new"){
144       $this->newDialogShown= true;
145     }
146     $this->is_new = FALSE;
147     if($this->dn == "new"){
148       $this->is_new =TRUE;
149     }
151     /* Generate package list */
152     $this->list= $this->genPkgs(TRUE);
153   }
156   function execute()
157   {
158     /* Call parent execute */
159     plugin::execute();
161     if($this->is_account && !$this->view_logged){
162       $this->view_logged = TRUE;
163       new log("view","fai/".get_class($this),$this->dn);
164     }
166     /* Fill templating stuff */
167     $smarty= get_smarty();
168     $display= "";
170     /******
171      * Initialize a new Package List with release and section name
172      ******/
173     
174     if(!$this->is_account){
176       /* Assemble release name */
177       $release = $this->parent->parent->fai_release;
178       $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $release);
179       $tmp= preg_replace('/ou=/', '', $tmp);
180       $rev= array_reverse(explode(',', $tmp));
181       $this->FAIdebianRelease= "/";
182       foreach ($rev as $part){
183         $this->FAIdebianRelease.= "/$part";
184       }
185       $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
187       /* Assemble sections */
188       $repos= $this->getServerInfos();
189       if(isset($repos[$this->FAIdebianRelease])){
190         $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
191         $this->FAIdebianSection= array_unique($this->FAIdebianSection);
192       }
194       /* Assign Repository settings*/ 
195       $this->is_account     = true;
196     }
197   
199     /******
200      * Add 
201      ******/
203     if(isset($_POST['AddManualpkg']) && 
204         isset($_POST['addPpkgsText']) &&
205         strlen($_POST['addPpkgsText']) && 
206         $this->acl_is_writeable("FAIpackage") && 
207         !preg_match("/freeze/",$this->FAIstate)){
209       // Check all splitted packages for valid package names
210       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
211       if( is_array($add_packages) ) {
212         $invalid_packages = array();
213         foreach ($add_packages as $value) {
214           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
215             $invalid_packages[] = trim($value);
216           }else{
217             $valid_packages[] = trim($value);
218           }
219         }
220         if(count($invalid_packages)){
221           $str = implode(", ",$invalid_packages);
222           msg_dialog::display(_("Invalid package names"), 
223               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
224               ERROR_DIALOG);
225         }
228         // If we have a complete list of valid packages, add them
229         if(count($valid_packages)){
231           foreach($valid_packages as $key =>  $value){
232             if(array_key_exists($value,$this->usedPackages)) {
233               unset($valid_packages[$key]);
234             }
235           }
237           // Query SI-Deamon for additional package information
238           $daemon       = new gosaSupportDaemon();
239           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
240           $do_si_query  = true;
243           foreach ($valid_packages as $value) {
244             
245             if( $do_si_query == true ) {
246               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
247               if( ! $daemon->is_error()){
248                 
249                 if(count($res)){
251                   // We just use the last answer - there shouldn't be multiple
252                   $res_attrs = array_pop( $res );
253                   $this->list[$value] = $res_attrs;
254                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
256                 }else{
257                   $this->usedPackages[$value] = $value;
258                 }
259               }else{
260                 msg_dialog::display(_("Service infrastructure"),
261                     msgPool::siError($daemon->get_error()),
262                     ERROR_DIALOG);
263                 $do_si_query = false;
264               }
265             }
266           }
268           ksort($this->usedPackages);
270           /* Generate package list */
271           $this->list= $this->genPkgs(TRUE);
272         }
273       }
274     }
276     // Open the packageSelect dialog to allow adding packages out of a list.
277     if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
278       $this->packageSelect = new packageSelect($this->config, get_userinfo());
279       $this->dialog =true;
280     }
282     // Close packageSelect dialog.
283     if(isset($_POST['packageSelect_cancel'])){
284       $this->packageSelect = FALSE;
285       $this->dialog =FALSE;
286     }
288     // Close packageSelect dialog and add the selected packages.
289     if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){
290       if(!preg_match("/freeze/i", $this->FAIstate)){
291         $use = $this->packageSelect->save();
293         foreach($use as $pkg){
294           $item = array();
295           for($i =0; $i < $pkg['count']; $i++){
296             $item[$pkg[$i]] = $pkg[$pkg[$i]][0];
297           }
298           $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; 
299         }
301         ksort($this->usedPackages);
303         /* Generate package list */
304         $this->list= $this->genPkgs(TRUE);
305       }
306       $this->packageSelect = FALSE;
307       $this->dialog =FALSE;
308     }
310     // Display package add dialog 
311     if($this->packageSelect instanceOf packageSelect){
313       session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages));
314       return $this->packageSelect->execute();
315     }
318     /* Check image Posts 
319      */
320     foreach($_POST as $name => $value){
322       /******
323        * Mark as removed  
324        ******/
325       
326       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
327         $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
328         if(isset($this->usedPackages[$id])){
329           $pkg = $this->usedPackages[$id]; 
330           if (preg_match('/\-$/', $pkg)){
331             $pkg= preg_replace('/\-$/', '', $pkg);
332           } else {
333             $pkg= preg_replace('/$/', '-', $pkg);
334           }
335           $this->usedPackages[$id] = $pkg;
336         }
337         break;
338       }
340       /******
341        * Delete Pkgs   
342        ******/
343       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
344         $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
345         if(isset($this->usedPackages[$id])){
346           unset($this->usedPackages[$id]);
347         }
348         break;
349       }
351       /******
352        * Configure Pkgs   
353        ******/
354       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
355         $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
356          
357         if(isset($this->usedPackages[$pkg])){
359           /* Configuration dialog open*/
360           $pkg_config = array();
361           if(isset($this->ConfiguredPackages[$pkg])){
362             $pkg_config = $this->ConfiguredPackages[$pkg];
363           }
364           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
365           $this->is_dialog =true;
366         }
367         break;
368       }
369     }
371     /* Abort package selection dialog */ 
372     if(isset($_POST['CancelSubObject'])){
373       $this->dialog = false;
374       $this->is_dialog=false;
375     }
377     /* Save Configuration */
378     if(isset($_POST['SaveObjectConfig'])){
379       if(!preg_match("/^freeze/", $this->FAIstate)){
380         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
381       }
382       $this->dialog = false;
383       $this->is_dialog=false;
384     }
386     /* cancel configuration */     
387     if(isset($_POST['CancelObjectConfig'])){
388       $this->dialog = false;
389       $this->is_dialog=false;
390     }
392     /* Display dialog */ 
393     if($this->is_dialog){
394       $this->dialog->save_object();
395       return $this->dialog->execute();
396     }
399     /******
400      * Display UI / HTML / smarty 
401      ******/
403     /* Create divlist to display a list of all currently used packages
404      */
405     $divlist = new divSelectBox("faiPackages");
407     ksort($this->usedPackages);
408     if(is_array($this->usedPackages)){
409       foreach($this->usedPackages as $usedName => $name){
410     
411         $actions = "";
413         /* Append message if package is configured */
414         $configured = "<img src='images/empty.png' alt=' '  class='center'>";
415         if(isset($this->ConfiguredPackages[$usedName])){
416           $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
417                       title='"._("Configured")."' class='center'>";
418         }
420         /* Adapt used name if we're marked for removal */
421         $removal = "<img src='images/empty.png' alt=' '  class='center'>";
422         if (preg_match('/\-$/', $name)){
423           $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
424                       title='"._("Package marked for removal")."' class='center'>";
425         }
427         /* Get Version */
428         $version = "&nbsp;";
429         if(isset($this->list[$usedName]['VERSION'])){
430           $version = $this->list[$usedName]['VERSION'];
431         }
432     
433         /* Get description */
434         $description = "&nbsp;";
435         if(isset($this->list[$usedName]['DESCRIPTION'])){
436           $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
437         }
438  
439         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
440           $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
441             src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
442         }
444         if(isset($this->list[$usedName]['TEMPLATE']) && 
445            !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
446           $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
447             src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
448         }
449         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
450           $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
451             src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
452         }
454         $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
455         $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
456         $field3 = array("string" => $version);
457         $field4 = array("string" => $description);
458         $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
459         $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
460       }
461     }
463     /* Assign variables */
464     foreach($this->attributes as $attrs){
465       $smarty->assign($attrs,$this->$attrs);
466     }
467     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
469     /* Assign section to smarty */
470     $strsec = "";
471     foreach($this->FAIdebianSection as $sec){
472       $strsec .= $sec." ";
473     }
475     $tmp = $this->plInfo();
476     foreach($tmp['plProvidedAcls'] as $name => $translated){
477       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
478     }
479  
480     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
481     $smarty->assign("divlist",$divlist->DrawList());
482     $smarty->assign("release" ,$this->FAIdebianRelease);
483     $smarty->assign("sections",$this->sections);
484     $smarty->assign("section" ,$strsec);
485     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
486     return($display);
487   }
490   /*! \brief  Removes this packageList from the ldap database 
491    */
492   function remove_from_parent()
493   {
494     $ldap = $this->config->get_ldap_link();
495     $ldap->cd ($this->dn);
496     $release = $this->parent->parent->fai_release;
497     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
498     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
499     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
500     foreach($this->ConfiguredPackages as $pkgname => $attrs){
501       foreach($attrs as $name => $attr){
502         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
503         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
504         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
505       }
506     }
507     $this->handle_post_events("remove");
508   }
511   /*! \brief  Collect all relevant POST vars for this plugin 
512    */
513   function save_object()
514   {
515     if(preg_match("/^freeze/", $this->FAIstate)) return;
516     plugin::save_object();
517   }
520   /*! \brief  Check given inputs for this package list
521       @return Array Containing all error messages, or an empty array if no error occured
522    */
523   function check()
524   {
525     /* Call common method to give check the hook */
526     $message= plugin::check();
528     if(count($this->usedPackages)==0){
529       $message[]= _("Please select a least one package!");
530     }
532     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
533       $message[]=_("Please choose a valid release/section combination for your repository setup!");
534     }
536     /* Ensure that we do not overwrite an allready existing entry 
537      */
538     if($this->is_new){
539       $release = $this->parent->parent->fai_release;
540       $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
541       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
542       if(isset($res[$this->cn])){
543         $message[] = msgPool::duplicated(_("Name"));
544       }
545     }
546     return ($message);
547   }
550   /*! \brief  Reload the list of cached packages.
551       @return Returns the currently cached list of packages. 
552    */
553   function genPkgs($force = false)
554   {
555     if(empty($this->FAIdebianRelease)) return;
557     if(!count($this->buffer) || $force){
558       $q = new gosaSupportDaemon();
559       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
561       $packages = array_keys($this->usedPackages);
563       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
564       if($q->is_error()){
565         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
566       }else{
567         foreach($ret as $attr){
568           $this->buffer[$attr['PACKAGE']] = $attr;
569         }
570       }
571     }
572     return $this->buffer;
573   }
576   /*! \brief Save packages and their configuration to ldap 
577    */
578   function save()
579   {
581     /* Assemble release name */
582     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
584       $current_release  = $this->parent->parent->fai_release;
585       $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $current_release);
586       $tmp= preg_replace('/ou=/', '', $tmp);
587       $rev= array_reverse(explode(',', $tmp));
588       $this->FAIdebianRelease= "";
589       foreach ($rev as $part){
590         $this->FAIdebianRelease.= "/$part";
591       }
592       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
593     }
595     plugin::save();
597     $ldap = $this->config->get_ldap_link();
599     $this->attrs['FAIpackage'] = array();
600     foreach($this->usedPackages as $pkg){
601       $this->attrs['FAIpackage'][] = $pkg;
602     } 
604     $this->attrs['FAIdebianSection'] = array();
605     foreach($this->FAIdebianSection as $sec){
606       $this->attrs['FAIdebianSection'][] = $sec;
607     }
609     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
610     
611     if($this->initially_was_account){
612       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
613     }else{
614       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
615     }
617     $ldap->cd($this->dn);
619     /* Save Package configurations */
620     foreach($this->ConfiguredPackages as $pkgname => $attrs){
621       foreach($attrs as $name => $attr){
622       
623         $pkgattrs = array();
625         foreach($attr as $n=>$v){
626           if(empty($v)) $v = array();
627         }
629         /* Set attributes */
630         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
632         $pkgattrs['FAIpackage']           = $pkgname;
633         $pkgattrs['FAIvariable']          = $name;
634         $pkgattrs['FAIvariableType']      = $attr['Type'];
635         $pkgattrs['FAIvariableContent']   = $attr['Value'];
636         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
638         /* Tag object */
639         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
641         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
643           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
644             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
645           }else{
646             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
647           }
648         }
649       }
650     }
651   }
654   /*! \brief  Return plugin informations for acl handling 
655       @return Array ACL infos of this plugin.
656    */ 
657   static function plInfo()
658   {
659     return (array( 
660           "plShortName" => _("Package"),
661           "plDescription" => _("FAI Package list"),
662           "plSelfModify"  => FALSE,
663           "plDepends"     => array(),
664           "plPriority"    => 28,
665           "plSection"     => array("administration"),
666           "plCategory"    => array("fai"),
667           "plProvidedAcls" => array(
668             "cn"                => _("Name"),
669             "description"       => _("Description"),
670             "FAIpackage"        => _("Packages"),
671             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
672             "FAIinstallMethod"  => _("Install Method"),
673             "FAIdebconfInfo"    => _("Package configuration"),
674             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
675           ));
676   }
679   /*! \brief prepares this plugin to be inserted after it was copied or cut.
680       @param Array  All attributes from the source object. 
681    */
682   function PrepareForCopyPaste($source)
683   {
684     plugin::PrepareForCopyPaste($source);
686     if(isset($source['FAIstate'][0])){
687       $this->FAIstate = $source['FAIstate'][0];
688     }
690     $this->FAIdebianRelease = "ClearFromCopyPaste";
692     if(isset($source['FAIpackage'])){
693       unset($source['FAIpackage']['count']);
694       foreach($source['FAIpackage'] as $pkg){
695         $this->usedPackages[$pkg] = $pkg;
696       }
697       ksort($this->usedPackages);
698     }else{
699       $this->usedPackages = array();
700     }
702     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
703       $this->FAIdebianSection = array();
704       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
705         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
706       }
707     }
709     /* Create one filter with all package names, 
710        instead of calling $ldap->search for every single package 
711      */
712     $PackageFilter = "";
713     foreach($this->usedPackages as $name){
714       $PackageFilter .= "(FAIpackage=".$name.")";
715     }
716     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
718     /* Search for configuration objects */ 
719     $ldap = $this->config->get_ldap_link();
720     $ldap->cd($source['dn']);
721     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
723     /* Walk through configurations and append them to our list of ConfiguredPackages */
724     while($attr = $ldap->fetch()){
726       /* Skip objects, that are tagged as removed */
727       if(isset($object['FAIstate'][0])){
728         if(preg_match("/removed$/",$attr['FAIstate'][0])){
729           continue;
730         }
731       }
733       $tmp =array(); 
734       $tmp['Name']  = $attr['FAIvariable'][0];
735       $tmp['Type']  = $attr['FAIvariableType'][0];
737       if (isset($attr['FAIvariableContent'][0])){
738         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
739           $tmp['Value'] = $attr['FAIvariableContent'][0];
740         }else{
741           $content = array();        
742           unset($attr['FAIvariableContent']['count']);
743           foreach($attr['FAIvariableContent'] as $attr){
744             $tmp['Value'][] = $attr;
745           }
746         }
747         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
748       }
749     }
750   }
753   /*! \brief  Returns a list of all configured servers with repositories.
754       @return Array  All repository server 
755    */
756   function getServerInfos()
757   {
758     $ret = array();
759     $ldap = $this->config->get_ldap_link();
760     $ldap->cd($this->config->current['BASE']);
761     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
762     while($attrs = $ldap->fetch()){
763       if(isset($attrs['FAIrepository'])){
764         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
765           $obj = $attrs['FAIrepository'][$i];
766           $tmp = explode("|",$obj);
767           if(count($tmp)==4){
768             foreach(explode(",",$tmp[3]) as $sec){
769               if(!empty($sec)){
770                 $ret[$tmp[2]][] =  $sec;
771               }
772             }
773           }
774         }
775       }
776     }
777     return($ret);
778   }
781   /*! \brief  Used for copy & paste.
782     Returns a HTML input mask, which allows to change the cn of this entry.
783     @param  Array   Array containing current status && a HTML template.
784    */
785   function getCopyDialog()
786   {
787     $vars = array("cn");
788     $smarty = get_smarty();
789     $smarty->assign("cn", htmlentities($this->cn));
790     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
791     $ret = array();
792     $ret['string'] = $str;
793     $ret['status'] = "";
794     return($ret);
795   }
798   /*! \brief  Used for copy & paste.
799     Some entries must be renamed to avaoid duplicate entries.
800    */
801   function saveCopyDialog()
802   {
803     if(isset($_POST['cn'])){
804       $this->cn = get_post('cn');
805     }
806   }
809 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
810 ?>