Code

Updated get_ou it receives values from the config registry now.
[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         $invalid_packages = array();
223         foreach ($add_packages as $value) {
224           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
225             $invalid_packages[] = trim($value);
226           }else{
227             $valid_packages[] = trim($value);
228           }
229         }
230         if(count($invalid_packages)){
231           $str = implode(", ",$invalid_packages);
232           msg_dialog::display(_("Invalid package names"), 
233               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
234               ERROR_DIALOG);
235         }
238         // If we have a complete list of valid packages, add them
239         if(count($valid_packages)){
241           foreach($valid_packages as $key =>  $value){
242             if(array_key_exists($value,$this->usedPackages)) {
243               unset($valid_packages[$key]);
244             }
245           }
247           // Query SI-Deamon for additional package information
248           $daemon       = new gosaSupportDaemon();
249           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
250           $do_si_query  = true;
253           foreach ($valid_packages as $value) {
254             
255             if( $do_si_query == true ) {
256               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
257               if( ! $daemon->is_error()){
258                 
259                 if(count($res)){
261                   // We just use the last answer - there shouldn't be multiple
262                   $res_attrs = array_pop( $res );
263                   $this->list[$value] = $res_attrs;
264                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
266                 }else{
267                   $this->usedPackages[$value] = $value;
268                 }
269               }else{
270                 msg_dialog::display(_("Service infrastructure"),
271                     msgPool::siError($daemon->get_error()),
272                     ERROR_DIALOG);
273                 $do_si_query = false;
274               }
275             }
276           }
278           ksort($this->usedPackages);
280           /* Generate package list */
281           $this->list= $this->genPkgs(TRUE);
282         }
283       }
284     }
286     // Open the packageSelect dialog to allow adding packages out of a list.
287     if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
288       $this->packageSelect = new packageSelect($this->config, get_userinfo());
289       session::set('packageSelect_Release',$this->FAIdebianRelease);
290       $this->dialog =true;
291     }
293     // Close packageSelect dialog.
294     if(isset($_POST['packageSelect_cancel'])){
295       $this->packageSelect = FALSE;
296       $this->dialog =FALSE;
297     }
299     // Close packageSelect dialog and add the selected packages.
300     if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){
301       if(!preg_match("/freeze/i", $this->FAIstate)){
302         $use = $this->packageSelect->save();
304         foreach($use as $pkg){
305           $item = array();
306           for($i =0; $i < $pkg['count']; $i++){
307             $item[$pkg[$i]] = $pkg[$pkg[$i]][0];
308           }
309           $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; 
310         }
312         ksort($this->usedPackages);
314         /* Generate package list */
315         $this->list= $this->genPkgs(TRUE);
316       }
317       $this->packageSelect = FALSE;
318       $this->dialog =FALSE;
319     }
321     // Display package add dialog 
322     if($this->packageSelect instanceOf packageSelect){
324       session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages));
325       return $this->packageSelect->execute();
326     }
329     /* Check image Posts 
330      */
331     foreach($_POST as $name => $value){
333       /******
334        * Mark as removed  
335        ******/
336       
337       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
338         $id = @postDecode(preg_replace("/^removal_package_(.*)$/","\\1",$name));
339         if(isset($this->usedPackages[$id])){
340           $pkg = $this->usedPackages[$id]; 
341           if (preg_match('/\-$/', $pkg)){
342             $pkg= preg_replace('/\-$/', '', $pkg);
343           } else {
344             $pkg= preg_replace('/$/', '-', $pkg);
345           }
346           $this->usedPackages[$id] = $pkg;
347         }
348         break;
349       }
351       /******
352        * Delete Pkgs   
353        ******/
354       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
355         $id = @postDecode(preg_replace("/^remove_package_(.*)$/","\\1",$name));
356         if(isset($this->usedPackages[$id])){
357           unset($this->usedPackages[$id]);
358         }
359         break;
360       }
362       /******
363        * Configure Pkgs   
364        ******/
365       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
366         $pkg = @postDecode(preg_replace("/^configure_package_(.*)$/","\\1",$name));
367          
368         if(isset($this->usedPackages[$pkg])){
370           /* Configuration dialog open*/
371           $pkg_config = array();
372           if(isset($this->ConfiguredPackages[$pkg])){
373             $pkg_config = $this->ConfiguredPackages[$pkg];
374           }
375           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
376           $this->is_dialog =true;
377         }
378         break;
379       }
380     }
382     /* Abort package selection dialog */ 
383     if(isset($_POST['CancelSubObject'])){
384       $this->dialog = false;
385       $this->is_dialog=false;
386     }
388     /* Save Configuration */
389     if(isset($_POST['SaveObjectConfig'])){
390       if(!preg_match("/^freeze/", $this->FAIstate)){
391         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
392       }
393       $this->dialog = false;
394       $this->is_dialog=false;
395     }
397     /* cancel configuration */     
398     if(isset($_POST['CancelObjectConfig'])){
399       $this->dialog = false;
400       $this->is_dialog=false;
401     }
403     /* Display dialog */ 
404     if($this->is_dialog){
405       $this->dialog->save_object();
406       return $this->dialog->execute();
407     }
410     /******
411      * Display UI / HTML / smarty 
412      ******/
414     /* Create list to display a list of all currently used packages
415      */
416     $data = $lData = array();
417     if(is_array($this->usedPackages)){
418         foreach($this->usedPackages as $usedName => $name){
420             /* Append message if package is configured */
421             $configured = image('images/empty.png');
422             if(isset($this->ConfiguredPackages[$usedName])){
423                 $configured = image('plugins/fai/images/package_configure.png','',_("Configured"));
424             }
426             /* Adapt used name if we're marked for removal */
427             $removal = image('images/empty.png');
428             if (preg_match('/\-$/', $name)){
429                 $removal = image('plugins/fai/images/removal_mark.png','',_("Package marked for removal"));
430             }
432             /* Get Version */
433             $version = "";
434             if(isset($this->list[$usedName]['VERSION'])){
435                 $version = $this->list[$usedName]['VERSION'];
436             }
438             /* Get description */
439             $description = "";
440             if(isset($this->list[$usedName]['DESCRIPTION'])){
441                 $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
442             }
444             $actions= image('plugins/fai/images/removal_mark.png',
445                     'removal_package_'.postEncode($usedName),
446                     _("Mark package for removal"));
448             if(isset($this->list[$usedName]['TEMPLATE']) && 
449                     !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
450                 $actions.= image('plugins/fai/images/package_configure.png',
451                         'configure_package_'.postEncode($usedName),
452                         _("Configure this package"));
453             }
454             if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
455                 $actions.= image('images/lists/trash.png',
456                         'remove_package_'.postEncode($usedName),
457                         _("Remove this package"));
458             }
459             $data[$usedName] = $usedName;
460             $lData[$usedName] = array('data'=>
461                     array(
462                         $configured."&nbsp;".$removal,
463                         $usedName ,$version,htmlentities($description), $actions));
464         }
465     }
466     $this->packageList->setAcl($this->getacl("FAIpackage",preg_match('/^freeze/', $this->FAIstate)));
467     $this->packageList->setListData($data,$lData);
468     $this->packageList->update();
470     /* Assign variables */
471     foreach($this->attributes as $attrs){
472       $smarty->assign($attrs,$this->$attrs);
473     }
474     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
476     /* Assign section to smarty */
477     $strsec = "";
478     foreach($this->FAIdebianSection as $sec){
479       $strsec .= $sec." ";
480     }
482     $tmp = $this->plInfo();
483     foreach($tmp['plProvidedAcls'] as $name => $translated){
484       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
485     }
486  
487     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
488     $smarty->assign("listing",$this->packageList->render());
489     $smarty->assign("release" ,$this->FAIdebianRelease);
490     $smarty->assign("sections",$this->sections);
491     $smarty->assign("section" ,$strsec);
492     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
493     return($display);
494   }
497   /*! \brief  Removes this packageList from the ldap database 
498    */
499   function remove_from_parent()
500   {
501     $ldap = $this->config->get_ldap_link();
502     $ldap->cd ($this->dn);
503     $release = $this->parent->parent->fai_release;
504     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
505     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
506     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
507     foreach($this->ConfiguredPackages as $pkgname => $attrs){
508       foreach($attrs as $name => $attr){
509         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
510         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
511         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
512       }
513     }
514     $this->handle_post_events("remove");
515   }
518   /*! \brief  Collect all relevant POST vars for this plugin 
519    */
520   function save_object()
521   {
522     if(preg_match("/^freeze/", $this->FAIstate)) return;
523     plugin::save_object();
524   }
527   /*! \brief  Check given inputs for this package list
528       @return Array Containing all error messages, or an empty array if no error occured
529    */
530   function check()
531   {
532     /* Call common method to give check the hook */
533     $message= plugin::check();
535     if(count($this->usedPackages)==0){
536       $message[]= _("Please select a least one package!");
537     }
539     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
540       $message[]=_("Please choose a valid release/section combination for your repository setup!");
541     }
543     /* Ensure that we do not overwrite an allready existing entry 
544      */
545     if($this->is_new){
546       $release = $this->parent->parent->fai_release;
547       $new_dn= 'cn='.$this->cn.",".get_ou("faiPackage", "faiPackageRDN").get_ou("faiManagement", "faiBaseRDN").$release;
548       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
549       if(isset($res[$this->cn])){
550         $message[] = msgPool::duplicated(_("Name"));
551       }
552     }
553     return ($message);
554   }
557   /*! \brief  Reload the list of cached packages.
558       @return Returns the currently cached list of packages. 
559    */
560   function genPkgs($force = false)
561   {
562     if(empty($this->FAIdebianRelease)) return;
564     if(!count($this->buffer) || $force){
565       $q = new gosaSupportDaemon();
566       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
568       $packages = array_keys($this->usedPackages);
570       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
571       if($q->is_error()){
572         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
573       }else{
574         foreach($ret as $attr){
575           $this->buffer[$attr['PACKAGE']] = $attr;
576         }
577       }
578     }
579     return $this->buffer;
580   }
583   /*! \brief Save packages and their configuration to ldap 
584    */
585   function save()
586   {
588     /* Assemble release name */
589     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
591       $current_release  = $this->parent->parent->fai_release;
592       $tmp= preg_replace('/,'.preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').'.*$/i', '', $current_release);
593       $tmp= preg_replace('/ou=/', '', $tmp);
594       $rev= array_reverse(explode(',', $tmp));
595       $this->FAIdebianRelease= "";
596       foreach ($rev as $part){
597         $this->FAIdebianRelease.= "/$part";
598       }
599       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
600     }
602     plugin::save();
604     $ldap = $this->config->get_ldap_link();
606     $this->attrs['FAIpackage'] = array();
607     foreach($this->usedPackages as $pkg){
608       $this->attrs['FAIpackage'][] = $pkg;
609     } 
611     $this->attrs['FAIdebianSection'] = array();
612     foreach($this->FAIdebianSection as $sec){
613       $this->attrs['FAIdebianSection'][] = $sec;
614     }
616     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
617     
618     if($this->initially_was_account){
619       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
620     }else{
621       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
622     }
624     $ldap->cd($this->dn);
626     /* Save Package configurations */
627     foreach($this->ConfiguredPackages as $pkgname => $attrs){
628       foreach($attrs as $name => $attr){
629       
630         $pkgattrs = array();
632         foreach($attr as $n=>$v){
633           if(empty($v)) $v = array();
634         }
636         /* Set attributes */
637         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
639         $pkgattrs['FAIpackage']           = $pkgname;
640         $pkgattrs['FAIvariable']          = $name;
641         $pkgattrs['FAIvariableType']      = $attr['Type'];
642         $pkgattrs['FAIvariableContent']   = $attr['Value'];
643         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
645         /* Tag object */
646         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
648         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
650           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
651             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
652           }else{
653             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
654           }
655         }
656       }
657     }
658   }
661   /*! \brief  Return plugin informations for acl handling 
662       @return Array ACL infos of this plugin.
663    */ 
664   static function plInfo()
665   {
666     return (array( 
667           "plShortName" => _("Package"),
668           "plDescription" => _("FAI Package list"),
669           "plSelfModify"  => FALSE,
670           "plDepends"     => array(),
671           "plPriority"    => 28,
672           "plSection"     => array("administration"),
673           "plCategory"    => array("fai"),
674           "plProperties" =>
675           array(
676               array(
677                   "name"          => "faiPackageRDN",
678                   "type"          => "rdn",
679                   "default"       => "ou=packages,",
680                   "description"   => "The 'faiPackageRDN' statement defines the location where new fai-packages will be created. The default is 'ou=packages,'.",
681                   "check"         => "gosaProperty::isRdn",
682                   "migrate"       => "",
683                   "group"         => "plugin",
684                   "mandatory"     => FALSE)),
686           "plProvidedAcls" => array(
687             "cn"                => _("Name"),
688             "description"       => _("Description"),
689             "FAIpackage"        => _("Packages"),
690             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
691             "FAIinstallMethod"  => _("Install Method"),
692             "FAIdebconfInfo"    => _("Package configuration"),
693             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
694           ));
695   }
698   /*! \brief prepares this plugin to be inserted after it was copied or cut.
699       @param Array  All attributes from the source object. 
700    */
701   function PrepareForCopyPaste($source)
702   {
703     plugin::PrepareForCopyPaste($source);
705     if(isset($source['FAIstate'][0])){
706       $this->FAIstate = $source['FAIstate'][0];
707     }
709     $this->FAIdebianRelease = "ClearFromCopyPaste";
711     if(isset($source['FAIpackage'])){
712       unset($source['FAIpackage']['count']);
713       foreach($source['FAIpackage'] as $pkg){
714         $this->usedPackages[$pkg] = $pkg;
715       }
716       ksort($this->usedPackages);
717     }else{
718       $this->usedPackages = array();
719     }
721     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
722       $this->FAIdebianSection = array();
723       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
724         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
725       }
726     }
728     /* Create one filter with all package names, 
729        instead of calling $ldap->search for every single package 
730      */
731     $PackageFilter = "";
732     foreach($this->usedPackages as $name){
733       $PackageFilter .= "(FAIpackage=".$name.")";
734     }
735     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
737     /* Search for configuration objects */ 
738     $ldap = $this->config->get_ldap_link();
739     $ldap->cd($source['dn']);
740     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
742     /* Walk through configurations and append them to our list of ConfiguredPackages */
743     while($attr = $ldap->fetch()){
745       /* Skip objects, that are tagged as removed */
746       if(isset($object['FAIstate'][0])){
747         if(preg_match("/removed$/",$attr['FAIstate'][0])){
748           continue;
749         }
750       }
752       $tmp =array(); 
753       $tmp['Name']  = $attr['FAIvariable'][0];
754       $tmp['Type']  = $attr['FAIvariableType'][0];
756       if (isset($attr['FAIvariableContent'][0])){
757         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
758           $tmp['Value'] = $attr['FAIvariableContent'][0];
759         }else{
760           $content = array();        
761           unset($attr['FAIvariableContent']['count']);
762           foreach($attr['FAIvariableContent'] as $attr){
763             $tmp['Value'][] = $attr;
764           }
765         }
766         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
767       }
768     }
769   }
772   /*! \brief  Returns a list of all configured servers with repositories.
773       @return Array  All repository server 
774    */
775   function getServerInfos()
776   {
777     $ret = array();
778     $ldap = $this->config->get_ldap_link();
779     $ldap->cd($this->config->current['BASE']);
780     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
781     while($attrs = $ldap->fetch()){
782       if(isset($attrs['FAIrepository'])){
783         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
784           $obj = $attrs['FAIrepository'][$i];
785           $tmp = explode("|",$obj);
786           if(count($tmp)==4){
787             foreach(explode(",",$tmp[3]) as $sec){
788               if(!empty($sec)){
789                 $ret[$tmp[2]][] =  $sec;
790               }
791             }
792           }
793         }
794       }
795     }
796     return($ret);
797   }
800   /*! \brief  Used for copy & paste.
801     Returns a HTML input mask, which allows to change the cn of this entry.
802     @param  Array   Array containing current status && a HTML template.
803    */
804   function getCopyDialog()
805   {
806     $vars = array("cn");
807     $smarty = get_smarty();
808     $smarty->assign("cn", htmlentities($this->cn));
809     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
810     $ret = array();
811     $ret['string'] = $str;
812     $ret['status'] = "";
813     return($ret);
814   }
817   /*! \brief  Used for copy & paste.
818     Some entries must be renamed to avaoid duplicate entries.
819    */
820   function saveCopyDialog()
821   {
822     if(isset($_POST['cn'])){
823       $this->cn = get_post('cn');
824     }
825   }
828 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
829 ?>