Code

e877dfd1515aa858d6ff25f08f8b8245762da3ec
[gosa.git] / trunk / 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" );
55   var $direct_packages_add = FALSE;
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     }
150     /* Check weither its allowed to directly add packages */
151     $direct_packages_add = $config->search("faiManagement","direct_packages_add",array("menu"));
152     if (preg_match("/^true$/i", $direct_packages_add) || preg_match("/yes/i", $direct_packages_add)) {
153         $this->direct_packages_add = TRUE;
154     }
156     /* Generate package list */
157     $this->list= $this->genPkgs(TRUE);
158   }
161   function execute()
162   {
163     /* Call parent execute */
164     plugin::execute();
166     if($this->is_account && !$this->view_logged){
167       $this->view_logged = TRUE;
168       new log("view","fai/".get_class($this),$this->dn);
169     }
171     /* Fill templating stuff */
172     $smarty= get_smarty();
173     $display= "";
175     /******
176      * Initialize a new Package List with release and section name
177      ******/
178     
179     if(!$this->is_account){
181       /* Assemble release name */
182       $release = $this->parent->parent->fai_release;
183       $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
184       $tmp= preg_replace('/ou=/', '', $tmp);
185       $rev= array_reverse(split(',', $tmp));
186       $this->FAIdebianRelease= "/";
187       foreach ($rev as $part){
188         $this->FAIdebianRelease.= "/$part";
189       }
190       $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
192       /* Assemble sections */
193       $repos= $this->getServerInfos();
194       if(isset($repos[$this->FAIdebianRelease])){
195         $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
196         $this->FAIdebianSection= array_unique($this->FAIdebianSection);
197       }
199       /* Assign Repository settings*/ 
200       $this->is_account     = true;
201     }
202   
204     /******
205      * Add 
206      ******/
208     if(isset($_POST['AddManualpkg']) && 
209         isset($_POST['addPpkgsText']) &&
210         strlen($_POST['addPpkgsText']) && 
211         $this->acl_is_writeable("FAIpackage") && 
212         !preg_match("/freeze/",$this->FAIstate)){
214       // Check all splitted packages for valid package names
215       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
216       $valid_packages = array();
217       if( is_array($add_packages) ) {
218         $invalid_packages = array();
219         foreach ($add_packages as $value) {
220           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
221             $invalid_packages[] = trim($value);
222           }else{
223             $valid_packages[] = trim($value);
224           }
225         }
226         if(count($invalid_packages)){
227           $str = implode(", ",$invalid_packages);
228           msg_dialog::display(_("Invalid package names"), 
229               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
230               ERROR_DIALOG);
231         }
234         // If we have a complete list of valid packages, add them
235         if(count($valid_packages)){
237           foreach($valid_packages as $key =>  $value){
238             if(array_key_exists($value,$this->usedPackages)) {
239               unset($valid_packages[$key]);
240             }
241           }
243           // Query SI-Deamon for additional package information
244           $daemon       = new gosaSupportDaemon();
245           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
246           $do_si_query  = true;
249           foreach ($valid_packages as $value) {
250             
251             if( $do_si_query == true ) {
252               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
253               if( ! $daemon->is_error()){
254                 
255                 if(count($res)){
257                   // We just use the last answer - there shouldn't be multiple
258                   $res_attrs = array_pop( $res );
259                   $this->list[$value] = $res_attrs;
260                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
262                 }else{
263                   $this->usedPackages[$value] = $value;
264                 }
265               }else{
266                 msg_dialog::display(_("Service infrastructure"),
267                     msgPool::siError($daemon->get_error()),
268                     ERROR_DIALOG);
269                 $do_si_query = false;
270               }
271             }
272           }
274           ksort($this->usedPackages);
276           /* Generate package list */
277           $this->list= $this->genPkgs(TRUE);
278         }
279       }
280     }
282     /* + was pressed to open the package dialog */
283     if(isset($_POST['Addpkg']) && 
284         $this->acl_is_writeable("FAIpackage") && 
285         !preg_match("/freeze/",$this->FAIstate)){
286       $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
287       $this->is_dialog =true;
288     }
291     /* Check image Posts 
292      */
293     foreach($_POST as $name => $value){
295       /******
296        * Mark as removed  
297        ******/
298       
299       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
300         $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
301         if(isset($this->usedPackages[$id])){
302           $pkg = $this->usedPackages[$id]; 
303           if (preg_match('/\-$/', $pkg)){
304             $pkg= preg_replace('/\-$/', '', $pkg);
305           } else {
306             $pkg= preg_replace('/$/', '-', $pkg);
307           }
308           $this->usedPackages[$id] = $pkg;
309         }
310         break;
311       }
313       /******
314        * Delete Pkgs   
315        ******/
316       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
317         $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
318         if(isset($this->usedPackages[$id])){
319           unset($this->usedPackages[$id]);
320         }
321         break;
322       }
324       /******
325        * Configure Pkgs   
326        ******/
327       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
328         $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
329          
330         if(isset($this->usedPackages[$pkg])){
332           /* Configuration dialog open*/
333           $pkg_config = array();
334           if(isset($this->ConfiguredPackages[$pkg])){
335             $pkg_config = $this->ConfiguredPackages[$pkg];
336           }
337           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
338           $this->is_dialog =true;
339         }
340         break;
341       }
342     }
344     /* Abort package selection dialog */ 
345     if(isset($_POST['CancelSubObject'])){
346       $this->dialog = false;
347       $this->is_dialog=false;
348     }
350     /* attach new packages */
351     if(isset($_POST['SaveSubObject'])) {
352       if(!preg_match("/freeze/i", $this->FAIstate)){
353         $this->dialog->save_object();
354         if(count($this->dialog->check())){
355           foreach($this->dialog->check() as $msgs){
356             msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
357           }
358         }else{
359           $use = $this->dialog->save();
360           $this->usedPackages = $use;
361           $this->dialog = false;
362           $this->is_dialog=false;
363           ksort($this->usedPackages);
365           /* Generate package list */
366           $this->list= $this->genPkgs(TRUE);
367         }
368       }else{
369         $this->dialog = false;
370         $this->is_dialog=false;
371       }
372     }
374     /* Save Configuration */
375     if(isset($_POST['SaveObjectConfig'])){
376       if(!preg_match("/^freeze/", $this->FAIstate)){
377         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
378       }
379       $this->dialog = false;
380       $this->is_dialog=false;
381     }
383     /* cancel configuration */     
384     if(isset($_POST['CancelObjectConfig'])){
385       $this->dialog = false;
386       $this->is_dialog=false;
387     }
389     /* Display dialog */ 
390     if($this->is_dialog){
391       $this->dialog->save_object();
392       return $this->dialog->execute();
393     }
396     /******
397      * Display UI / HTML / smarty 
398      ******/
400     /* Create divlist to display a list of all currently used packages
401      */
402     $divlist = new divSelectBox("faiPackages");
404     ksort($this->usedPackages);
405     if(is_array($this->usedPackages)){
406       foreach($this->usedPackages as $usedName => $name){
407     
408         $actions = "";
410         /* Append message if package is configured */
411         $configured = "<img src='images/empty.png' alt=' '  class='center'>";
412         if(isset($this->ConfiguredPackages[$usedName])){
413           $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
414                       title='"._("Configured")."' class='center'>";
415         }
417         /* Adapt used name if we're marked for removal */
418         $removal = "<img src='images/empty.png' alt=' '  class='center'>";
419         if (preg_match('/\-$/', $name)){
420           $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
421                       title='"._("Package marked for removal")."' class='center'>";
422         }
424         /* Get Version */
425         $version = "&nbsp;";
426         if(isset($this->list[$usedName]['VERSION'])){
427           $version = $this->list[$usedName]['VERSION'];
428         }
429     
430         /* Get description */
431         $description = "&nbsp;";
432         if(isset($this->list[$usedName]['DESCRIPTION'])){
433           $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
434         }
435  
436         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
437           $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
438             src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
439         }
441         if(isset($this->list[$usedName]['TEMPLATE']) && 
442            !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
443           $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
444             src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
445         }
446         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
447           $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
448             src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
449         }
451         $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
452         $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
453         $field3 = array("string" => $version);
454         $field4 = array("string" => $description);
455         $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
456         $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
457       }
458     }
460     /* Assign variables */
461     foreach($this->attributes as $attrs){
462       $smarty->assign($attrs,$this->$attrs);
463     }
464     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
466     /* Assign section to smarty */
467     $strsec = "";
468     foreach($this->FAIdebianSection as $sec){
469       $strsec .= $sec." ";
470     }
472     $tmp = $this->plInfo();
473     foreach($tmp['plProvidedAcls'] as $name => $translated){
474       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
475     }
476  
477     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
478     $smarty->assign("divlist",$divlist->DrawList());
479     $smarty->assign("release" ,$this->FAIdebianRelease);
480     $smarty->assign("sections",$this->sections);
481     $smarty->assign("section" ,$strsec);
482     $smarty->assign("direct_packages_add", $this->direct_packages_add);
483     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
484     return($display);
485   }
488   /*! \brief  Removes this packageList from the ldap database 
489    */
490   function remove_from_parent()
491   {
492     $ldap = $this->config->get_ldap_link();
493     $ldap->cd ($this->dn);
494     $release = $this->parent->parent->fai_release;
495     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
496     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
497     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
498     foreach($this->ConfiguredPackages as $pkgname => $attrs){
499       foreach($attrs as $name => $attr){
500         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
501         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
502         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
503       }
504     }
505     $this->handle_post_events("remove");
506   }
509   /*! \brief  Collect all relevant POST vars for this plugin 
510    */
511   function save_object()
512   {
513     if(preg_match("/^freeze/", $this->FAIstate)) return;
514     plugin::save_object();
515   }
518   /*! \brief  Check given inputs for this package list
519       @return Array Containing all error messages, or an empty array if no error occured
520    */
521   function check()
522   {
523     /* Call common method to give check the hook */
524     $message= plugin::check();
526     if(count($this->usedPackages)==0){
527       $message[]= _("Please select a least one package!");
528     }
530     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
531       $message[]=_("Please choose a valid release/section combination for your repository setup!");
532     }
534     /* Ensure that we do not overwrite an allready existing entry 
535      */
536     if($this->is_new){
537       $release = $this->parent->parent->fai_release;
538       $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
539       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
540       if(isset($res[$this->cn])){
541         $message[] = msgPool::duplicated(_("Name"));
542       }
543     }
544     return ($message);
545   }
548   /*! \brief  Reload the list of cached packages.
549       @return Returns the currently cached list of packages. 
550    */
551   function genPkgs($force = false)
552   {
553     if(empty($this->FAIdebianRelease)) return;
555     if(!count($this->buffer) || $force){
556       $q = new gosaSupportDaemon();
557       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
559       $packages = array_keys($this->usedPackages);
561       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
562       if($q->is_error()){
563         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
564       }else{
565         foreach($ret as $attr){
566           $this->buffer[$attr['PACKAGE']] = $attr;
567         }
568       }
569     }
570     return $this->buffer;
571   }
574   /*! \brief Save packages and their configuration to ldap 
575    */
576   function save()
577   {
579     /* Assemble release name */
580     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
582       $current_release  = $this->parent->parent->fai_release;
583       $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
584       $tmp= preg_replace('/ou=/', '', $tmp);
585       $rev= array_reverse(split(',', $tmp));
586       $this->FAIdebianRelease= "";
587       foreach ($rev as $part){
588         $this->FAIdebianRelease.= "/$part";
589       }
590       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
591     }
593     plugin::save();
595     $ldap = $this->config->get_ldap_link();
597     $this->attrs['FAIpackage'] = array();
598     foreach($this->usedPackages as $pkg){
599       $this->attrs['FAIpackage'][] = $pkg;
600     } 
602     $this->attrs['FAIdebianSection'] = array();
603     foreach($this->FAIdebianSection as $sec){
604       $this->attrs['FAIdebianSection'][] = $sec;
605     }
607     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
608     
609     if($this->initially_was_account){
610       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
611     }else{
612       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
613     }
615     $ldap->cd($this->dn);
617     /* Save Package configurations */
618     foreach($this->ConfiguredPackages as $pkgname => $attrs){
619       foreach($attrs as $name => $attr){
620       
621         $pkgattrs = array();
623         foreach($attr as $n=>$v){
624           if(empty($v)) $v = array();
625         }
627         /* Set attributes */
628         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
630         $pkgattrs['FAIpackage']           = $pkgname;
631         $pkgattrs['FAIvariable']          = $name;
632         $pkgattrs['FAIvariableType']      = $attr['Type'];
633         $pkgattrs['FAIvariableContent']   = $attr['Value'];
634         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
636         /* Tag object */
637        $ui= get_userinfo();
638         $this->tag_attrs($pkgattrs, $pkgdn, $ui->gosaUnitTag);
640         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
642           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
643             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
644           }else{
645             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
646           }
647         }
648       }
649     }
650   }
653   /*! \brief  Return plugin informations for acl handling 
654       @return Array ACL infos of this plugin.
655    */ 
656   static function plInfo()
657   {
658     return (array( 
659           "plShortName" => _("Package"),
660           "plDescription" => _("FAI Package list"),
661           "plSelfModify"  => FALSE,
662           "plDepends"     => array(),
663           "plPriority"    => 28,
664           "plSection"     => array("administration"),
665           "plCategory"    => array("fai"),
666           "plProvidedAcls" => array(
667             "cn"                => _("Name"),
668             "description"       => _("Description"),
669             "FAIpackage"        => _("Packages"),
670             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
671             "FAIinstallMethod"  => _("Install Method"),
672             "FAIdebconfInfo"    => _("Package configuration"),
673             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
674           ));
675   }
678   /*! \brief prepares this plugin to be inserted after it was copied or cut.
679       @param Array  All attributes from the source object. 
680    */
681   function PrepareForCopyPaste($source)
682   {
683     plugin::PrepareForCopyPaste($source);
685     if(isset($source['FAIstate'][0])){
686       $this->FAIstate = $source['FAIstate'][0];
687     }
689     $this->FAIdebianRelease = "ClearFromCopyPaste";
691     if(isset($source['FAIpackage'])){
692       unset($source['FAIpackage']['count']);
693       foreach($source['FAIpackage'] as $pkg){
694         $this->usedPackages[$pkg] = $pkg;
695       }
696       ksort($this->usedPackages);
697     }else{
698       $this->usedPackages = array();
699     }
701     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
702       $this->FAIdebianSection = array();
703       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
704         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
705       }
706     }
708     /* Create one filter with all package names, 
709        instead of calling $ldap->search for every single package 
710      */
711     $PackageFilter = "";
712     foreach($this->usedPackages as $name){
713       $PackageFilter .= "(FAIpackage=".$name.")";
714     }
715     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
717     /* Search for configuration objects */ 
718     $ldap = $this->config->get_ldap_link();
719     $ldap->cd($source['dn']);
720     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
722     /* Walk through configurations and append them to our list of ConfiguredPackages */
723     while($attr = $ldap->fetch()){
725       /* Skip objects, that are tagged as removed */
726       if(isset($object['FAIstate'][0])){
727         if(preg_match("/removed$/",$attr['FAIstate'][0])){
728           continue;
729         }
730       }
732       $tmp =array(); 
733       $tmp['Name']  = $attr['FAIvariable'][0];
734       $tmp['Type']  = $attr['FAIvariableType'][0];
736       if (isset($attr['FAIvariableContent'][0])){
737         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
738           $tmp['Value'] = $attr['FAIvariableContent'][0];
739         }else{
740           $content = array();        
741           unset($attr['FAIvariableContent']['count']);
742           foreach($attr['FAIvariableContent'] as $attr){
743             $tmp['Value'][] = $attr;
744           }
745         }
746         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
747       }
748     }
749   }
752   /*! \brief  Returns a list of all configured servers with repositories.
753       @return Array  All repository server 
754    */
755   function getServerInfos()
756   {
757     $ret = array();
758     $ldap = $this->config->get_ldap_link();
759     $ldap->cd($this->config->current['BASE']);
760     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
761     while($attrs = $ldap->fetch()){
762       if(isset($attrs['FAIrepository'])){
763         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
764           $obj = $attrs['FAIrepository'][$i];
765           $tmp = split("\|",$obj);
766           if(count($tmp)==4){
767             foreach(split(",",$tmp[3]) as $sec){
768               if(!empty($sec)){
769                 $ret[$tmp[2]][] =  $sec;
770               }
771             }
772           }
773         }
774       }
775     }
776     return($ret);
777   }
780   /*! \brief  Used for copy & paste.
781     Returns a HTML input mask, which allows to change the cn of this entry.
782     @param  Array   Array containing current status && a HTML template.
783    */
784   function getCopyDialog()
785   {
786     $vars = array("cn");
787     $smarty = get_smarty();
788     $smarty->assign("cn", htmlentities($this->cn));
789     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
790     $ret = array();
791     $ret['string'] = $str;
792     $ret['status'] = "";
793     return($ret);
794   }
797   /*! \brief  Used for copy & paste.
798     Some entries must be renamed to avaoid duplicate entries.
799    */
800   function saveCopyDialog()
801   {
802     if(isset($_POST['cn'])){
803       $this->cn = get_post('cn');
804     }
805   }
808 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
809 ?>