Code

Typo fixes
[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 $FAIinstallMethods  = array( "install", "ninstall", "remove", 
51       "dselect-upgrade", "taskinst", "taskrm",
52       "hold", "clean", "aptitude", "aptitude-r",
53       "pending", "dpkgc" );
56   function faiPackage (&$config, $dn= NULL)
57   {
58     /* Load Attributes */
59     plugin::plugin ($config, $dn);
61     /* If "dn==new" we try to create a new entry
62      * Else we must read all objects from ldap which belong to this entry.
63      * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
64      */
65     if($dn != "new"){
66       $this->dn =$dn;
68       /* Check if there are already some packages in this list 
69        */
70       $this->usedPackages = array();
71       if(isset($this->attrs['FAIpackage'])){
72         unset($this->attrs['FAIpackage']['count']);
73         foreach($this->attrs['FAIpackage'] as $pkg){
74           $name = preg_replace("/\-$/","",$pkg);
75           $this->usedPackages[$name] = $pkg;
76         }
77         ksort($this->usedPackages);
78       }  
80       /* Fetch all package configurations from ldap 
81        */
82       $PackageFilter = "";
83       foreach($this->usedPackages as $name => $value){
84         $PackageFilter .= "(FAIpackage=".$name.")";
85       }
86       $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
88       /* Search for configuration objects */ 
89       $ldap = $this->config->get_ldap_link();
90       $ldap->cd($this->dn);
91       $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
92             "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
94       /* Walk through configurations and append them to our list of ConfiguredPackages 
95        */
96       while($attr = $ldap->fetch()){
98         /* Skip objects, that are tagged as removed */
99         if(isset($object['FAIstate'][0])){
100           if(preg_match("/removed$/",$attr['FAIstate'][0])){
101             continue;
102           }
103         }
105         $tmp =array(); 
106         $tmp['Name']  = $attr['FAIvariable'][0];
107         $tmp['Type']  = $attr['FAIvariableType'][0];
109         if (isset($attr['FAIvariableContent'][0])){
110           if(!in_array($attr['FAIvariableType'],array("multiselect"))){
111             $tmp['Value'] = $attr['FAIvariableContent'][0];
112           }else{
113             $content = array();        
114             unset($attr['FAIvariableContent']['count']);
115             foreach($attr['FAIvariableContent'] as $attr){
116               $tmp['Value'][] = $attr;
117             }
118           }
119           $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
120         }
121       }
123       $this->FAIdebianSection = array();
124       if(isset($this->attrs['FAIdebianSection'])){
125         for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){ 
126           $sec = $this->attrs['FAIdebianSection'][$i];
127           $this->FAIdebianSection[$sec]=$sec;
128         }
129       }
130       $this->FAIpackage = array();
132     } // ENDE  dn != new  
134     $methods = array();
135     foreach($this->FAIinstallMethods as $method){
136       $methods[$method] = $method;
137     }
138     $this->FAIinstallMethods = $methods;
140     /* Check if we exist already - no need to ask for revisions, etc. then */
141     if ($this->dn != "new"){
142       $this->newDialogShown= true;
143     }
144     $this->is_new = FALSE;
145     if($this->dn == "new"){
146       $this->is_new =TRUE;
147     }
149     /* Generate package list */
150     $this->list= $this->genPkgs(TRUE);
151   }
154   function execute()
155   {
156     /* Call parent execute */
157     plugin::execute();
159     if($this->is_account && !$this->view_logged){
160       $this->view_logged = TRUE;
161       new log("view","fai/".get_class($this),$this->dn);
162     }
164     /* Fill templating stuff */
165     $smarty= get_smarty();
166     $display= "";
168     /******
169      * Initialize a new Package List with release and section name
170      ******/
171     
172     if(!$this->is_account){
174       /* Assemble release name */
175       $release = $this->parent->parent->fai_release;
176       $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
177       $tmp= preg_replace('/ou=/', '', $tmp);
178       $rev= array_reverse(split(',', $tmp));
179       $this->FAIdebianRelease= "/";
180       foreach ($rev as $part){
181         $this->FAIdebianRelease.= "/$part";
182       }
183       $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
185       /* Assemble sections */
186       $repos= $this->getServerInfos();
187       if(isset($repos[$this->FAIdebianRelease])){
188         $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
189         $this->FAIdebianSection= array_unique($this->FAIdebianSection);
190       }
192       /* Assign Repository settings*/ 
193       $this->is_account     = true;
194     }
195   
197     /******
198      * Add 
199      ******/
201     if(isset($_POST['AddManualpkg']) && 
202         isset($_POST['addPpkgsText']) &&
203         strlen($_POST['addPpkgsText']) && 
204         $this->acl_is_writeable("FAIpackage") && 
205         !preg_match("/freeze/",$this->FAIstate)){
207       // Check all splitted packages for valid package names
208       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
209       if( is_array($add_packages) ) {
210         $invalid_packages = array();
211         foreach ($add_packages as $value) {
212           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
213             $invalid_packages[] = trim($value);
214           }else{
215             $valid_packages[] = trim($value);
216           }
217         }
218         if(count($invalid_packages)){
219           $str = implode(", ",$invalid_packages);
220           msg_dialog::display(_("Invalid package names"), 
221               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
222               ERROR_DIALOG);
223         }
226         // If we have a complete list of valid packages, add them
227         if(count($valid_packages)){
229           foreach($valid_packages as $key =>  $value){
230             if(array_key_exists($value,$this->usedPackages)) {
231               unset($valid_packages[$key]);
232             }
233           }
235           // Query SI-Deamon for additional package information
236           $daemon       = new gosaSupportDaemon();
237           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
238           $do_si_query  = true;
241           foreach ($valid_packages as $value) {
242             
243             if( $do_si_query == true ) {
244               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
245               if( ! $daemon->is_error()){
246                 
247                 if(count($res)){
249                   // We just use the last answer - there shouldn't be multiple
250                   $res_attrs = array_pop( $res );
251                   $this->list[$value] = $res_attrs;
252                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
254                 }else{
255                   $this->usedPackages[$value] = $value;
256                 }
257               }else{
258                 msg_dialog::display(_("Service infrastructure"),
259                     msgPool::siError($daemon->get_error()),
260                     ERROR_DIALOG);
261                 $do_si_query = false;
262               }
263             }
264           }
266           ksort($this->usedPackages);
268           /* Generate package list */
269           $this->list= $this->genPkgs(TRUE);
270         }
271       }
272     }
274     /* + was pressed to open the package dialog */
275     if(isset($_POST['Addpkg']) && 
276         $this->acl_is_writeable("FAIpackage") && 
277         !preg_match("/freeze/",$this->FAIstate)){
278       $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
279       $this->is_dialog =true;
280     }
283     /* Check image Posts 
284      */
285     foreach($_POST as $name => $value){
287       /******
288        * Mark as removed  
289        ******/
290       
291       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
292         $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
293         if(isset($this->usedPackages[$id])){
294           $pkg = $this->usedPackages[$id]; 
295           if (preg_match('/\-$/', $pkg)){
296             $pkg= preg_replace('/\-$/', '', $pkg);
297           } else {
298             $pkg= preg_replace('/$/', '-', $pkg);
299           }
300           $this->usedPackages[$id] = $pkg;
301         }
302         break;
303       }
305       /******
306        * Delete Pkgs   
307        ******/
308       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
309         $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
310         if(isset($this->usedPackages[$id])){
311           unset($this->usedPackages[$id]);
312         }
313         break;
314       }
316       /******
317        * Configure Pkgs   
318        ******/
319       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
320         $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
321          
322         if(isset($this->usedPackages[$pkg])){
324           /* Configuration dialog open*/
325           $pkg_config = array();
326           if(isset($this->ConfiguredPackages[$pkg])){
327             $pkg_config = $this->ConfiguredPackages[$pkg];
328           }
329           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
330           $this->is_dialog =true;
331         }
332         break;
333       }
334     }
336     /* Abort package selection dialog */ 
337     if(isset($_POST['CancelSubObject'])){
338       $this->dialog = false;
339       $this->is_dialog=false;
340     }
342     /* attach new packages */
343     if(isset($_POST['SaveSubObject'])) {
344       if(!preg_match("/freeze/i", $this->FAIstate)){
345         $this->dialog->save_object();
346         if(count($this->dialog->check())){
347           foreach($this->dialog->check() as $msgs){
348             msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
349           }
350         }else{
351           $use = $this->dialog->save();
352           $this->usedPackages = $use;
353           $this->dialog = false;
354           $this->is_dialog=false;
355           ksort($this->usedPackages);
357           /* Generate package list */
358           $this->list= $this->genPkgs(TRUE);
359         }
360       }else{
361         $this->dialog = false;
362         $this->is_dialog=false;
363       }
364     }
366     /* Save Configuration */
367     if(isset($_POST['SaveObjectConfig'])){
368       if(!preg_match("/^freeze/", $this->FAIstate)){
369         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
370       }
371       $this->dialog = false;
372       $this->is_dialog=false;
373     }
375     /* cancel configuration */     
376     if(isset($_POST['CancelObjectConfig'])){
377       $this->dialog = false;
378       $this->is_dialog=false;
379     }
381     /* Display dialog */ 
382     if($this->is_dialog){
383       $this->dialog->save_object();
384       return $this->dialog->execute();
385     }
388     /******
389      * Display UI / HTML / smarty 
390      ******/
392     /* Create divlist to display a list of all currently used packages
393      */
394     $divlist = new divSelectBox("faiPackages");
396     ksort($this->usedPackages);
397     if(is_array($this->usedPackages)){
398       foreach($this->usedPackages as $usedName => $name){
399     
400         $actions = "";
402         /* Append message if package is configured */
403         $configured = "<img src='images/empty.png' alt=' '  class='center'>";
404         if(isset($this->ConfiguredPackages[$usedName])){
405           $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
406                       title='"._("Configured")."' class='center'>";
407         }
409         /* Adapt used name if we're marked for removal */
410         $removal = "<img src='images/empty.png' alt=' '  class='center'>";
411         if (preg_match('/\-$/', $name)){
412           $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
413                       title='"._("Package marked for removal")."' class='center'>";
414         }
416         /* Get Version */
417         $version = "&nbsp;";
418         if(isset($this->list[$usedName]['VERSION'])){
419           $version = $this->list[$usedName]['VERSION'];
420         }
421     
422         /* Get description */
423         $description = "&nbsp;";
424         if(isset($this->list[$usedName]['DESCRIPTION'])){
425           $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
426         }
427  
428         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
429           $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
430             src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
431         }
433         if(isset($this->list[$usedName]['TEMPLATE']) && 
434            !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
435           $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
436             src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
437         }
438         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
439           $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
440             src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
441         }
443         $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
444         $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
445         $field3 = array("string" => $version);
446         $field4 = array("string" => $description);
447         $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
448         $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
449       }
450     }
452     /* Assign variables */
453     foreach($this->attributes as $attrs){
454       $smarty->assign($attrs,$this->$attrs);
455     }
456     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
458     /* Assign section to smarty */
459     $strsec = "";
460     foreach($this->FAIdebianSection as $sec){
461       $strsec .= $sec." ";
462     }
464     $tmp = $this->plInfo();
465     foreach($tmp['plProvidedAcls'] as $name => $translated){
466       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
467     }
468  
469     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
470     $smarty->assign("divlist",$divlist->DrawList());
471     $smarty->assign("release" ,$this->FAIdebianRelease);
472     $smarty->assign("sections",$this->sections);
473     $smarty->assign("section" ,$strsec);
474     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
475     return($display);
476   }
479   /*! \brief  Removes this packageList from the ldap database 
480    */
481   function remove_from_parent()
482   {
483     $ldap = $this->config->get_ldap_link();
484     $ldap->cd ($this->dn);
485     $release = $this->parent->parent->fai_release;
486     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
487     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
488     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
489     foreach($this->ConfiguredPackages as $pkgname => $attrs){
490       foreach($attrs as $name => $attr){
491         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
492         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
493         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
494       }
495     }
496     $this->handle_post_events("remove");
497   }
500   /*! \brief  Collect all relevant POST vars for this plugin 
501    */
502   function save_object()
503   {
504     if(preg_match("/^freeze/", $this->FAIstate)) return;
505     plugin::save_object();
506   }
509   /*! \brief  Check given inputs for this package list
510       @return Array Containing all error messages, or an empty array if no error occured
511    */
512   function check()
513   {
514     /* Call common method to give check the hook */
515     $message= plugin::check();
517     if(count($this->usedPackages)==0){
518       $message[]= _("Please select a least one package!");
519     }
521     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
522       $message[]=_("Please choose a valid release/section combination for your repository setup!");
523     }
525     /* Ensure that we do not overwrite an allready existing entry 
526      */
527     if($this->is_new){
528       $release = $this->parent->parent->fai_release;
529       $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
530       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
531       if(isset($res[$this->cn])){
532         $message[] = msgPool::duplicated(_("Name"));
533       }
534     }
535     return ($message);
536   }
539   /*! \brief  Reload the list of cached packages.
540       @return Returns the currently cached list of packages. 
541    */
542   function genPkgs($force = false)
543   {
544     if(empty($this->FAIdebianRelease)) return;
546     if(!count($this->buffer) || $force){
547       $q = new gosaSupportDaemon();
548       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
550       $packages = array_keys($this->usedPackages);
552       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
553       if($q->is_error()){
554         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
555       }else{
556         foreach($ret as $attr){
557           $this->buffer[$attr['PACKAGE']] = $attr;
558         }
559       }
560     }
561     return $this->buffer;
562   }
565   /*! \brief Save packages and their configuration to ldap 
566    */
567   function save()
568   {
570     /* Assemble release name */
571     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
573       $current_release  = $this->parent->parent->fai_release;
574       $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
575       $tmp= preg_replace('/ou=/', '', $tmp);
576       $rev= array_reverse(split(',', $tmp));
577       $this->FAIdebianRelease= "";
578       foreach ($rev as $part){
579         $this->FAIdebianRelease.= "/$part";
580       }
581       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
582     }
584     plugin::save();
586     $ldap = $this->config->get_ldap_link();
588     $this->attrs['FAIpackage'] = array();
589     foreach($this->usedPackages as $pkg){
590       $this->attrs['FAIpackage'][] = $pkg;
591     } 
593     $this->attrs['FAIdebianSection'] = array();
594     foreach($this->FAIdebianSection as $sec){
595       $this->attrs['FAIdebianSection'][] = $sec;
596     }
598     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
599     
600     if($this->initially_was_account){
601       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
602     }else{
603       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
604     }
606     $ldap->cd($this->dn);
608     /* Save Package configurations */
609     foreach($this->ConfiguredPackages as $pkgname => $attrs){
610       foreach($attrs as $name => $attr){
611       
612         $pkgattrs = array();
614         foreach($attr as $n=>$v){
615           if(empty($v)) $v = array();
616         }
618         /* Set attributes */
619         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
621         $pkgattrs['FAIpackage']           = $pkgname;
622         $pkgattrs['FAIvariable']          = $name;
623         $pkgattrs['FAIvariableType']      = $attr['Type'];
624         $pkgattrs['FAIvariableContent']   = $attr['Value'];
625         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
627         /* Tag object */
628         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
630         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
632           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
633             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
634           }else{
635             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
636           }
637         }
638       }
639     }
640   }
643   /*! \brief  Return plugin informations for acl handling 
644       @return Array ACL infos of this plugin.
645    */ 
646   static function plInfo()
647   {
648     return (array( 
649           "plShortName" => _("Package"),
650           "plDescription" => _("FAI Package list"),
651           "plSelfModify"  => FALSE,
652           "plDepends"     => array(),
653           "plPriority"    => 28,
654           "plSection"     => array("administration"),
655           "plCategory"    => array("fai"),
656           "plProvidedAcls" => array(
657             "cn"                => _("Name"),
658             "description"       => _("Description"),
659             "FAIpackage"        => _("Packages"),
660             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
661             "FAIinstallMethod"  => _("Install Method"),
662             "FAIdebconfInfo"    => _("Package configuration"),
663             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
664           ));
665   }
668   /*! \brief prepares this plugin to be inserted after it was copied or cut.
669       @param Array  All attributes from the source object. 
670    */
671   function PrepareForCopyPaste($source)
672   {
673     plugin::PrepareForCopyPaste($source);
675     if(isset($source['FAIstate'][0])){
676       $this->FAIstate = $source['FAIstate'][0];
677     }
679     $this->FAIdebianRelease = "ClearFromCopyPaste";
681     if(isset($source['FAIpackage'])){
682       unset($source['FAIpackage']['count']);
683       foreach($source['FAIpackage'] as $pkg){
684         $this->usedPackages[$pkg] = $pkg;
685       }
686       ksort($this->usedPackages);
687     }else{
688       $this->usedPackages = array();
689     }
691     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
692       $this->FAIdebianSection = array();
693       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
694         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
695       }
696     }
698     /* Create one filter with all package names, 
699        instead of calling $ldap->search for every single package 
700      */
701     $PackageFilter = "";
702     foreach($this->usedPackages as $name){
703       $PackageFilter .= "(FAIpackage=".$name.")";
704     }
705     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
707     /* Search for configuration objects */ 
708     $ldap = $this->config->get_ldap_link();
709     $ldap->cd($source['dn']);
710     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
712     /* Walk through configurations and append them to our list of ConfiguredPackages */
713     while($attr = $ldap->fetch()){
715       /* Skip objects, that are tagged as removed */
716       if(isset($object['FAIstate'][0])){
717         if(preg_match("/removed$/",$attr['FAIstate'][0])){
718           continue;
719         }
720       }
722       $tmp =array(); 
723       $tmp['Name']  = $attr['FAIvariable'][0];
724       $tmp['Type']  = $attr['FAIvariableType'][0];
726       if (isset($attr['FAIvariableContent'][0])){
727         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
728           $tmp['Value'] = $attr['FAIvariableContent'][0];
729         }else{
730           $content = array();        
731           unset($attr['FAIvariableContent']['count']);
732           foreach($attr['FAIvariableContent'] as $attr){
733             $tmp['Value'][] = $attr;
734           }
735         }
736         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
737       }
738     }
739   }
742   /*! \brief  Returns a list of all configured servers with repositories.
743       @return Array  All repository server 
744    */
745   function getServerInfos()
746   {
747     $ret = array();
748     $ldap = $this->config->get_ldap_link();
749     $ldap->cd($this->config->current['BASE']);
750     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
751     while($attrs = $ldap->fetch()){
752       if(isset($attrs['FAIrepository'])){
753         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
754           $obj = $attrs['FAIrepository'][$i];
755           $tmp = split("\|",$obj);
756           if(count($tmp)==4){
757             foreach(split(",",$tmp[3]) as $sec){
758               if(!empty($sec)){
759                 $ret[$tmp[2]][] =  $sec;
760               }
761             }
762           }
763         }
764       }
765     }
766     return($ret);
767   }
770   /*! \brief  Used for copy & paste.
771     Returns a HTML input mask, which allows to change the cn of this entry.
772     @param  Array   Array containing current status && a HTML template.
773    */
774   function getCopyDialog()
775   {
776     $vars = array("cn");
777     $smarty = get_smarty();
778     $smarty->assign("cn", htmlentities($this->cn));
779     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
780     $ret = array();
781     $ret['string'] = $str;
782     $ret['status'] = "";
783     return($ret);
784   }
787   /*! \brief  Used for copy & paste.
788     Some entries must be renamed to avaoid duplicate entries.
789    */
790   function saveCopyDialog()
791   {
792     if(isset($_POST['cn'])){
793       $this->cn = get_post('cn');
794     }
795   }
798 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
799 ?>