Code

plProperty updates
[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);
154     // Prepare lists
155     $this->packageList = new sortableListing();
156     $this->packageList->setDeleteable(false);
157     $this->packageList->setEditable(false);
158     $this->packageList->setWidth("100%");
159     $this->packageList->setHeight("200px");
160     $this->packageList->setColspecs(array('20px','*','*','100px','60px'));
161     $this->packageList->setHeader(array(_("Status"),_("Name"),_("Description"),_("Version")));
162     $this->packageList->setDefaultSortColumn(1);
163   }
166   function execute()
167   {
168     /* Call parent execute */
169     plugin::execute();
171     if($this->is_account && !$this->view_logged){
172       $this->view_logged = TRUE;
173       new log("view","fai/".get_class($this),$this->dn);
174     }
176     /* Fill templating stuff */
177     $smarty= get_smarty();
178     $display= "";
180     /******
181      * Initialize a new Package List with release and section name
182      ******/
183     
184     if(!$this->is_account){
186       /* Assemble release name */
187       $release = $this->parent->parent->fai_release;
188       $tmp= preg_replace('/[,]*'.preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').'.*$/i', '', $release);
189       $tmp= preg_replace('/ou=/', '', $tmp);
190       $rev= array_reverse(explode(',', $tmp));
191       $this->FAIdebianRelease= "/";
192       foreach ($rev as $part){
193         $this->FAIdebianRelease.= "/$part";
194       }
195       $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
197       /* Assemble sections */
198       $repos= $this->getServerInfos();
199       if(isset($repos[$this->FAIdebianRelease])){
200         $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
201         $this->FAIdebianSection= array_unique($this->FAIdebianSection);
202       }
204       /* Assign Repository settings*/ 
205       $this->is_account     = true;
206     }
207   
209     /******
210      * Add 
211      ******/
213     if(isset($_POST['AddManualpkg']) && 
214         isset($_POST['addPpkgsText']) &&
215         strlen($_POST['addPpkgsText']) && 
216         $this->acl_is_writeable("FAIpackage") && 
217         !preg_match("/freeze/",$this->FAIstate)){
219       // Check all splitted packages for valid package names
220       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
221       if( is_array($add_packages) ) {
222         $valid_packages = array();
223         $invalid_packages = array();
224         foreach ($add_packages as $value) {
225           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
226             $invalid_packages[] = trim($value);
227           }else{
228             $valid_packages[] = trim($value);
229           }
230         }
231         if(count($invalid_packages)){
232           $str = implode(", ",$invalid_packages);
233           msg_dialog::display(_("Invalid package names"), 
234               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
235               ERROR_DIALOG);
236         }
239         // If we have a complete list of valid packages, add them
240         if(count($valid_packages)){
242           foreach($valid_packages as $key =>  $value){
243             if(array_key_exists($value,$this->usedPackages)) {
244               unset($valid_packages[$key]);
245             }
246           }
248           // Query SI-Deamon for additional package information
249           $daemon       = new gosaSupportDaemon();
250           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
251           $do_si_query  = true;
254           foreach ($valid_packages as $value) {
255             
256             if( $do_si_query == true ) {
257               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
258               if( ! $daemon->is_error()){
259                 
260                 if(count($res)){
262                   // We just use the last answer - there shouldn't be multiple
263                   $res_attrs = array_pop( $res );
264                   $this->list[$value] = $res_attrs;
265                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
267                 }else{
268                   $this->usedPackages[$value] = $value;
269                 }
270               }else{
271                 msg_dialog::display(_("Service infrastructure"),
272                     msgPool::siError($daemon->get_error()),
273                     ERROR_DIALOG);
274                 $do_si_query = false;
275               }
276             }
277           }
279           ksort($this->usedPackages);
281           /* Generate package list */
282           $this->list= $this->genPkgs(TRUE);
283         }
284       }
285     }
287     // Open the packageSelect dialog to allow adding packages out of a list.
288     if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
289       $this->packageSelect = new packageSelect($this->config, get_userinfo());
290       session::set('packageSelect_Release',$this->FAIdebianRelease);
291       $this->dialog =true;
292     }
294     // Close packageSelect dialog.
295     if(isset($_POST['packageSelect_cancel'])){
296       $this->packageSelect = FALSE;
297       $this->dialog =FALSE;
298     }
300     // Close packageSelect dialog and add the selected packages.
301     if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){
302       if(!preg_match("/freeze/i", $this->FAIstate)){
303         $use = $this->packageSelect->save();
305         foreach($use as $pkg){
306           $item = array();
307           for($i =0; $i < $pkg['count']; $i++){
308             $item[$pkg[$i]] = $pkg[$pkg[$i]][0];
309           }
310           $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; 
311         }
313         ksort($this->usedPackages);
315         /* Generate package list */
316         $this->list= $this->genPkgs(TRUE);
317       }
318       $this->packageSelect = FALSE;
319       $this->dialog =FALSE;
320     }
322     // Display package add dialog 
323     if($this->packageSelect instanceOf packageSelect){
325       session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages));
326       return $this->packageSelect->execute();
327     }
330     /* Check image Posts 
331      */
332     foreach($_POST as $name => $value){
334       /******
335        * Mark as removed  
336        ******/
337       
338       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
339         $id = @postDecode(preg_replace("/^removal_package_(.*)$/","\\1",$name));
340         if(isset($this->usedPackages[$id])){
341           $pkg = $this->usedPackages[$id]; 
342           if (preg_match('/\-$/', $pkg)){
343             $pkg= preg_replace('/\-$/', '', $pkg);
344           } else {
345             $pkg= preg_replace('/$/', '-', $pkg);
346           }
347           $this->usedPackages[$id] = $pkg;
348         }
349         break;
350       }
352       /******
353        * Delete Pkgs   
354        ******/
355       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
356         $id = @postDecode(preg_replace("/^remove_package_(.*)$/","\\1",$name));
357         if(isset($this->usedPackages[$id])){
358           unset($this->usedPackages[$id]);
359         }
360         break;
361       }
363       /******
364        * Configure Pkgs   
365        ******/
366       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
367         $pkg = @postDecode(preg_replace("/^configure_package_(.*)$/","\\1",$name));
368          
369         if(isset($this->usedPackages[$pkg])){
371           /* Configuration dialog open*/
372           $pkg_config = array();
373           if(isset($this->ConfiguredPackages[$pkg])){
374             $pkg_config = $this->ConfiguredPackages[$pkg];
375           }
376           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
377           $this->is_dialog =true;
378         }
379         break;
380       }
381     }
383     /* Abort package selection dialog */ 
384     if(isset($_POST['CancelSubObject'])){
385       $this->dialog = false;
386       $this->is_dialog=false;
387     }
389     /* Save Configuration */
390     if(isset($_POST['SaveObjectConfig'])){
391       if(!preg_match("/^freeze/", $this->FAIstate)){
392         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
393       }
394       $this->dialog = false;
395       $this->is_dialog=false;
396     }
398     /* cancel configuration */     
399     if(isset($_POST['CancelObjectConfig'])){
400       $this->dialog = false;
401       $this->is_dialog=false;
402     }
404     /* Display dialog */ 
405     if($this->is_dialog){
406       $this->dialog->save_object();
407       return $this->dialog->execute();
408     }
411     /******
412      * Display UI / HTML / smarty 
413      ******/
415     /* Create list to display a list of all currently used packages
416      */
417     $data = $lData = array();
418     if(is_array($this->usedPackages)){
419         foreach($this->usedPackages as $usedName => $name){
421             /* Append message if package is configured */
422             $configured = image('images/empty.png');
423             if(isset($this->ConfiguredPackages[$usedName])){
424                 $configured = image('plugins/fai/images/package_configure.png','',_("Configured"));
425             }
427             /* Adapt used name if we're marked for removal */
428             $removal = image('images/empty.png');
429             if (preg_match('/\-$/', $name)){
430                 $removal = image('plugins/fai/images/removal_mark.png','',_("Package marked for removal"));
431             }
433             /* Get Version */
434             $version = "";
435             if(isset($this->list[$usedName]['VERSION'])){
436                 $version = $this->list[$usedName]['VERSION'];
437             }
439             /* Get description */
440             $description = "";
441             if(isset($this->list[$usedName]['DESCRIPTION'])){
442                 $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
443             }
445             $actions= image('plugins/fai/images/removal_mark.png',
446                     'removal_package_'.postEncode($usedName),
447                     _("Mark package for removal"));
449             if(isset($this->list[$usedName]['TEMPLATE']) && 
450                     !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
451                 $actions.= image('plugins/fai/images/package_configure.png',
452                         'configure_package_'.postEncode($usedName),
453                         _("Configure this package"));
454             }
455             if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
456                 $actions.= image('images/lists/trash.png',
457                         'remove_package_'.postEncode($usedName),
458                         _("Remove this package"));
459             }
460             $data[$usedName] = $usedName;
461             $lData[$usedName] = array('data'=>
462                     array(
463                         $configured."&nbsp;".$removal,
464                         $usedName ,set_post($description), $version, $actions));
465         }
466     }
467     $this->packageList->setAcl($this->getacl("FAIpackage",preg_match('/^freeze/', $this->FAIstate)));
468     $this->packageList->setListData($data,$lData);
469     $this->packageList->update();
471     /* Assign variables */
472     foreach($this->attributes as $attrs){
473       $smarty->assign($attrs,set_post($this->$attrs));
474     }
475     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
477     /* Assign section to smarty */
478     $strsec = "";
479     foreach($this->FAIdebianSection as $sec){
480       $strsec .= $sec." ";
481     }
483     $tmp = $this->plInfo();
484     foreach($tmp['plProvidedAcls'] as $name => $translated){
485       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
486     }
487  
488     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
489     $smarty->assign("listing",$this->packageList->render());
490     $smarty->assign("release" ,$this->FAIdebianRelease);
491     $smarty->assign("sections",$this->sections);
492     $smarty->assign("section" ,$strsec);
493     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
494     return($display);
495   }
498   /*! \brief  Removes this packageList from the ldap database 
499    */
500   function remove_from_parent()
501   {
502     $ldap = $this->config->get_ldap_link();
503     $ldap->cd ($this->dn);
504     $release = $this->parent->parent->fai_release;
505     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
506     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
507     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
508     foreach($this->ConfiguredPackages as $pkgname => $attrs){
509       foreach($attrs as $name => $attr){
510         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
511         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
512         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
513       }
514     }
515     $this->handle_post_events("remove");
516   }
519   /*! \brief  Collect all relevant POST vars for this plugin 
520    */
521   function save_object()
522   {
523     if(preg_match("/^freeze/", $this->FAIstate)) return;
524     plugin::save_object();
525   }
528   /*! \brief  Check given inputs for this package list
529       @return Array Containing all error messages, or an empty array if no error occured
530    */
531   function check()
532   {
533     /* Call common method to give check the hook */
534     $message= plugin::check();
536     if(count($this->usedPackages)==0){
537       $message[]= _("Please select a least one package!");
538     }
540     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
541       $message[]=_("Please choose a valid release/section combination for your repository setup!");
542     }
544     /* Ensure that we do not overwrite an allready existing entry 
545      */
546     if($this->is_new){
547       $release = $this->parent->parent->fai_release;
548       $new_dn= 'cn='.$this->cn.",".get_ou("faiPackage", "faiPackageRDN").get_ou("faiManagement", "faiBaseRDN").$release;
549       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
550       if(isset($res[$this->cn])){
551         $message[] = msgPool::duplicated(_("Name"));
552       }
553     }
554     return ($message);
555   }
558   /*! \brief  Reload the list of cached packages.
559       @return Returns the currently cached list of packages. 
560    */
561   function genPkgs($force = false)
562   {
563     if(empty($this->FAIdebianRelease)) return;
565     if(!count($this->buffer) || $force){
566       $q = new gosaSupportDaemon();
567       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
569       $packages = array_keys($this->usedPackages);
571       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
572       if($q->is_error()){
573         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
574       }else{
575         foreach($ret as $attr){
576           $this->buffer[$attr['PACKAGE']] = $attr;
577         }
578       }
579     }
580     return $this->buffer;
581   }
584   /*! \brief Save packages and their configuration to ldap 
585    */
586   function save()
587   {
589     /* Assemble release name */
590     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
592       $current_release  = $this->parent->parent->fai_release;
593       $tmp= preg_replace('/,'.preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').'.*$/i', '', $current_release);
594       $tmp= preg_replace('/ou=/', '', $tmp);
595       $rev= array_reverse(explode(',', $tmp));
596       $this->FAIdebianRelease= "";
597       foreach ($rev as $part){
598         $this->FAIdebianRelease.= "/$part";
599       }
600       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
601     }
603     plugin::save();
605     $ldap = $this->config->get_ldap_link();
607     $this->attrs['FAIpackage'] = array();
608     foreach($this->usedPackages as $pkg){
609       $this->attrs['FAIpackage'][] = $pkg;
610     } 
612     $this->attrs['FAIdebianSection'] = array();
613     foreach($this->FAIdebianSection as $sec){
614       $this->attrs['FAIdebianSection'][] = $sec;
615     }
617     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
618     
619     if($this->initially_was_account){
620       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
621     }else{
622       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
623     }
625     $ldap->cd($this->dn);
627     /* Save Package configurations */
628     foreach($this->ConfiguredPackages as $pkgname => $attrs){
629       foreach($attrs as $name => $attr){
630       
631         $pkgattrs = array();
633         foreach($attr as $n=>$v){
634           if(empty($v)) $v = array();
635         }
637         /* Set attributes */
638         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
640         $pkgattrs['FAIpackage']           = $pkgname;
641         $pkgattrs['FAIvariable']          = $name;
642         $pkgattrs['FAIvariableType']      = $attr['Type'];
643         $pkgattrs['FAIvariableContent']   = $attr['Value'];
644         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
646         /* Tag object */
647         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
649         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
651           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
652             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
653           }else{
654             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
655           }
656         }
657       }
658     }
659   }
662   /*! \brief  Return plugin informations for acl handling 
663       @return Array ACL infos of this plugin.
664    */ 
665   static function plInfo()
666   {
667     return (array( 
668           "plShortName" => _("Package"),
669           "plDescription" => _("FAI Package list"),
670           "plSelfModify"  => FALSE,
671           "plDepends"     => array(),
672           "plPriority"    => 28,
673           "plSection"     => array("administration"),
674           "plCategory"    => array("fai"),
675           "plProperties" =>
676           array(
677               array(
678                   "name"          => "faiPackageRDN",
679                   "type"          => "rdn",
680                   "default"       => "ou=packages,",
681                   "description"   => _("RDN for FAI package storage."),
682                   "check"         => "gosaProperty::isRdn",
683                   "migrate"       => "migrate_faiPackageRDN",
684                   "group"         => "plugin",
685                   "mandatory"     => TRUE)),
687           "plProvidedAcls" => array(
688             "cn"                => _("Name"),
689             "description"       => _("Description"),
690             "FAIpackage"        => _("Packages"),
691             "FAIdebianSection"  => _("Section")."&nbsp;("._("Read-only").")",
692             "FAIinstallMethod"  => _("Install Method"),
693             "FAIdebconfInfo"    => _("Package configuration"),
694             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Read-only").")")
695           ));
696   }
699   /*! \brief prepares this plugin to be inserted after it was copied or cut.
700       @param Array  All attributes from the source object. 
701    */
702   function PrepareForCopyPaste($source)
703   {
704     plugin::PrepareForCopyPaste($source);
706     if(isset($source['FAIstate'][0])){
707       $this->FAIstate = $source['FAIstate'][0];
708     }
710     $this->FAIdebianRelease = "ClearFromCopyPaste";
712     if(isset($source['FAIpackage'])){
713       unset($source['FAIpackage']['count']);
714       foreach($source['FAIpackage'] as $pkg){
715         $this->usedPackages[$pkg] = $pkg;
716       }
717       ksort($this->usedPackages);
718     }else{
719       $this->usedPackages = array();
720     }
722     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
723       $this->FAIdebianSection = array();
724       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
725         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
726       }
727     }
729     /* Create one filter with all package names, 
730        instead of calling $ldap->search for every single package 
731      */
732     $PackageFilter = "";
733     foreach($this->usedPackages as $name){
734       $PackageFilter .= "(FAIpackage=".$name.")";
735     }
736     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
738     /* Search for configuration objects */ 
739     $ldap = $this->config->get_ldap_link();
740     $ldap->cd($source['dn']);
741     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
743     /* Walk through configurations and append them to our list of ConfiguredPackages */
744     while($attr = $ldap->fetch()){
746       /* Skip objects, that are tagged as removed */
747       if(isset($object['FAIstate'][0])){
748         if(preg_match("/removed$/",$attr['FAIstate'][0])){
749           continue;
750         }
751       }
753       $tmp =array(); 
754       $tmp['Name']  = $attr['FAIvariable'][0];
755       $tmp['Type']  = $attr['FAIvariableType'][0];
757       if (isset($attr['FAIvariableContent'][0])){
758         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
759           $tmp['Value'] = $attr['FAIvariableContent'][0];
760         }else{
761           $content = array();        
762           unset($attr['FAIvariableContent']['count']);
763           foreach($attr['FAIvariableContent'] as $attr){
764             $tmp['Value'][] = $attr;
765           }
766         }
767         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
768       }
769     }
770   }
773   /*! \brief  Returns a list of all configured servers with repositories.
774       @return Array  All repository server 
775    */
776   function getServerInfos()
777   {
778     $ret = array();
779     $ldap = $this->config->get_ldap_link();
780     $ldap->cd($this->config->current['BASE']);
781     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
782     while($attrs = $ldap->fetch()){
783       if(isset($attrs['FAIrepository'])){
784         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
785           $obj = $attrs['FAIrepository'][$i];
786           $tmp = explode("|",$obj);
787           if(count($tmp)==4){
788             foreach(explode(",",$tmp[3]) as $sec){
789               if(!empty($sec)){
790                 $ret[$tmp[2]][] =  $sec;
791               }
792             }
793           }
794         }
795       }
796     }
797     return($ret);
798   }
801   /*! \brief  Used for copy & paste.
802     Returns a HTML input mask, which allows to change the cn of this entry.
803     @param  Array   Array containing current status && a HTML template.
804    */
805   function getCopyDialog()
806   {
807     $vars = array("cn");
808     $smarty = get_smarty();
809     $smarty->assign("cn", set_post($this->cn));
810     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
811     $ret = array();
812     $ret['string'] = $str;
813     $ret['status'] = "";
814     return($ret);
815   }
818   /*! \brief  Used for copy & paste.
819     Some entries must be renamed to avaoid duplicate entries.
820    */
821   function saveCopyDialog()
822   {
823     if(isset($_POST['cn'])){
824       $this->cn = get_post('cn');
825     }
826   }
829 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
830 ?>