Code

3b44c41e3a52e7731bc2acd20df5dc55bb81207e
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPartitionTable.inc
1 <?php
3 class faiPartitionTable extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account   = TRUE;
7   var $attributes       = array("cn","description", "FAIpartitionMethod");
8   var $objectclasses    = array("top","FAIclass","FAIpartitionTable");
10   var $subAttributes      = array("cn","description");
11   var $subPartAttributes  = array("cn","FAIpartitionNr","FAIpartitionSize","FAImountPoint","FAIfsType","FAIpartitionType","FAImountOptions","FAIfsOptions","FAIpartitionFlags","description");
13   var $sub64coded = array();
14   var $subBinary = array();
16   /* Specific attributes */
17   var $cn                 = "";       // The class name for this object
18   var $description        = "";       // The description for this set of partitions
19   var $FAIpartitionMethod = "";       // "setup-storage" or not assigned
20   var $disks              = array();  // All defined Disks 
21   var $is_dialog          = false;    // specifies which buttons will be shown to save or abort
23   var $FAIstate           = "";
24   var $ui;
26   var $view_logged      = FALSE;
28   function faiPartitionTable (&$config, $dn= NULL)
29   {
30     /* Load Attributes */
31     plugin::plugin ($config, $dn);
33     /* If "dn==new" we try to create a new entry
34      * Else we must read all objects from ldap which belong to this entry.
35      */
36     $this->ui = get_userinfo();
37     if($dn != "new"){
38       $this->dn =$dn;
40       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
41        */
42       $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
43       foreach($res as $obj){
45         /* Skip not relevant objects */
46         if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
47         $objects = array();
48         $objects['description']  = "";
49         $objects['status']      = "edited";
51         // Transform disk type into image later...
52         if (!isset($obj['FAIdiskType'])){
53           $objects['FAIdiskType']        = "old";
54         } else {
55           $objects['FAIdiskType']        = $obj['FAIdiskType'];
56         }
57         $objects['FAIdiskOption']        = $obj['FAIdiskOption'];
59         // Transform potential lvm information
60         if (isset($obj['FAIlvmDevice'])){
61           $objects['FAIlvmDevice'] = $obj['FAIlvmDevice'];
62         }
64         $objects['dn']          = $obj['dn'];
65         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
66         $this->disks[$objects['cn']] = $objects;
67         $this->disks[$objects['cn']]['partitions'] = array();
68       }
70       /* read all partitions for each disk 
71        */
72       foreach($this->disks as $name => $disk){
73         $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
74         foreach($res as $obj){
76           /* Skip not relevant objects */
77           if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
79           $objects = array();
80           $objects['status']      = "edited";
81           $objects['dn']          = $obj['dn'];
82           $objects                = $this->get_object_attributes($objects,$this->subPartAttributes);
83           unset($objects['dn']);;
84           $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
85         }
86       }
87     }
89     $this->is_new = FALSE;
90     if($this->dn == "new"){
91       $this->is_new =TRUE;
92     }
93     ksort($this->disks);
94   }
97   function acl_base_for_current_object($dn)
98   {
99     if($dn == "new" || $dn == ""){
100       if($this->dn == "new"){
101         $dn= $this->parent->parent->acl_base;
102       }else{
103         $dn = $this->dn;
104       }
105     }
106     return($dn);
107   }
110   function execute()
111   {
112     /* Call parent execute */
113     plugin::execute();
115     if($this->is_account && !$this->view_logged){
116       $this->view_logged = TRUE;
117       new log("view","fai/".get_class($this),$this->dn);
118     }
120     /* Fill templating stuff */
121     $smarty= get_smarty();
122     $display= "";
123  
124     /* Add Disk to this Partitionset
125      * This code adds a new HDD to the disks 
126      * A new Dialog will be opened 
127      */
128     if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) && 
129         !preg_match("/freeze/i",$this->FAIstate)){
130       $usedDiskNames =array();
131       foreach($this->disks as $key=>$disk){
132         $usedDiskNames[]= $key;
133       }
134       if ($this->FAIpartitionMethod == "setup-storage") {
135         if(isset($_POST['AddDisk'])) $type = "disk";
136         if(isset($_POST['AddRaid'])) $type = "raid";
137         if(isset($_POST['AddAddVolgroup'])) $type = "lvm";
138         $this->dialog = new faiDiskEntry($this->config,$this->dn,$usedDiskNames, array(),$type); 
139       } else {
140         $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); 
141       }
143       $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
144       $this->dialog->set_acl_category("fai");
145       $this->dialog->FAIstate = $this->FAIstate;
148       $this->is_dialog = true;
149     }
151     /* Edit disk.
152      * Open dialog which allows us to edit the selected entry 
153      */    
155     if($this->dn != "new"){
156       set_object_info($this->dn);
157     }
159     /* Edit entries via GET */
160     $Udisk = null;
161     if(isset($_GET['act']) && isset($_GET['id'])){
162       if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
163         $Udisk= $_GET['id'];
164       }
165     }
167     /* New Listhandling */
168     foreach($_POST as $name => $value){
169       if(preg_match("/^edit_/",$name)){
170         $entry = preg_replace("/^edit_/","",$name);
171         $Udisk = base64_decode(preg_replace("/_.*/","",$entry));
172         break;
173       }
174       if(preg_match("/^delete_/",$name)){
175         $entry = preg_replace("/^delete_/","",$name);
176         $disk = base64_decode(preg_replace("/_.*/","",$entry));
178         if (!preg_match("/freeze/i", $this->FAIstate)){
179           if(isset($this->disks[$disk])){
181             /* Check for references */
182             $ignore = false;
183             $name = "";
184             foreach($this->disks as $dtest) {
185               // Is raid?
186               $device= null;
187               $name = $dtest['cn'];
189               if ($disk == "raid"){
190                 $device = "md";
191               } else {
192                 $device = $disk;
194                 // Used by raid?
195                 if (isset($this->disks[$name]['partitions'])){
196                   foreach ($this->disks[$name]['partitions'] as $partition) {
197                     if (preg_match("/${disk}\.?[0-9]+/", $partition['FAIpartitionSize'])){
198                       $ignore = true;
199                       break 2;
200                     }
201                   }
202                 }
203               }
205               // Used by volgroup?
206               if (isset($this->disks[$name]["FAIlvmDevice"])){
207                 foreach ($this->disks[$name]["FAIlvmDevice"] as $vg_element) {
208                   if (preg_match("/^${device}\.?[0-9]+$/", $vg_element)){
209                     $ignore = true;
210                     break 2;
211                   }
212                 }
213               }
214             }
216             if ($ignore) {
217               msg_dialog::display(_("Error"), sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), $name), ERROR_DIALOG);
218             } else {
219               if($this->disks[$disk]['status']=="edited"){
220                 $this->disks[$disk."-delete"]=$this->disks[$disk];
221                 unset($this->disks[$disk]);
222                 $disk = $disk."-delete";        
223                 $this->disks[$disk]['status']="delete";
224                 foreach($this->disks[$disk]['partitions'] as $name => $value ){
225                   if($value['status']=="edited"){
226                     $this->disks[$disk]['partitions'][$name]['status']="delete"; 
227                   }else{
228                     unset($this->disks[$disk]['partitions'][$name]);
229                   }
230                 }
231               }else{
232                 unset($this->disks[$disk]);
233               }
234             }
236           }
237         }
238         break;
239       }
240     }
242     if($Udisk){
243       $usedDiskNames =array();
244       if(isset($this->disks[$Udisk])){
246         foreach($this->disks  as $key=>$disk){
247           if($key != $Udisk){
248             $usedDiskNames[]= $key;
249           }
250         }
252         /* Set object info string, which will be displayed in plugin info line */ 
253         if(isset($this->disks[$Udisk]['dn'])){
254           set_object_info($this->disks[$Udisk]['dn']);
255           $dn = $this->disks[$Udisk]['dn'];
256         }else{
257           set_object_info("");
258           $dn = "new";
259         }
261         if(isset($this->disks[$Udisk]['FAIdiskType'])){
262           switch($this->disks[$Udisk]['FAIdiskType']){
263             case 'raid': 
264             case 'lvm': 
265             case 'disk': 
266               $this->dialog = new faiDiskEntry(
267                   $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk], 
268                   $this->disks[$Udisk]['FAIdiskType']); 
269               break;
270             case 'old': 
271               $this->dialog = new faiPartitionTableEntry(
272                   $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
273               break;
274           }
275         }else{
276           $this->dialog = new faiPartitionTableEntry(
277               $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
278         }
279         if($this->dialog){
280           $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
281           $this->dialog->set_acl_category("fai");
282           $this->dialog->FAIstate = $this->FAIstate;
283           $this->is_dialog = true;
284         }
285       }
286     }
288     /* Edit aborted, close dialog, without saving anything
289      */
290     if(isset($_POST['CancelDisk'])){
291       unset($this->dialog);
292       $this->dialog = FALSE;
293       $this->is_dialog=false;
294     }
296     /* Dialog saved
297      * Save given data from Dialog, if no error is occurred
298      */
299     if(isset($_POST['SaveDisk'])){
301       if (!preg_match("/freeze/i", $this->FAIstate)){
302         $this->dialog->save_object();
303         if(count($this->dialog->check())){
304           foreach($this->dialog->check() as $msg){
305             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
306           }
307         }else{
308           $disk = $this->dialog->save();
309           if(isset($disk['rename'])){
310             if($this->disks[$disk['rename']['from']]['status']=="edited"){
311               $this->disks[$disk['rename']['from']]['status']="delete";
312             }else{
313               unset($this->disks[$disk['rename']['from']]);
314             }
316             foreach($disk['partitions'] as $key => $val){
317               if($disk['partitions'][$key]['status']!="delete"){
318                 $disk['partitions'][$key]['status']= "new";
319               }
320             }
322             $disk['status']="new";
323             $disk['cn']= $disk['rename']['to'];
324           }
326           $this->disks[$disk['cn']]=$disk; 
327           unset($this->dialog);
328           $this->dialog = FALSE;
329           $this->is_dialog=false;
330           ksort($this->disks);
331         }
332       }else{
333         $this->dialog = FALSE;
334         $this->is_dialog=false;
335       }
336     }
338     /* Display dialog if one is defined
339      */
340     if(is_object($this->dialog)){
341       $this->dialog->save_object();
342       return($this->dialog->execute());
343     }
345     /* Assign all attributes to smarty engine
346      */
347     foreach($this->attributes as $attrs){
348       $smarty->assign($attrs,$this->$attrs);
349       if($this->$attrs){
350         $smarty->assign($attrs."CHK"," ");
351       }else{
352         $smarty->assign($attrs."CHK"," disabled ");
353       }
354     }
355    
356     $dn = $this->acl_base_for_current_object($this->dn);
357     $smarty->assign("sub_object_is_addable",
358         preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
359         !preg_match("/freeze/",$this->FAIstate));
360     $smarty->assign("sub_object_is_removeable",
361         preg_match("/d/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
362         !preg_match("/freeze/",$this->FAIstate));
364     $tmp = $this->plInfo();
365     foreach($tmp['plProvidedAcls'] as $name => $translated){
366       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
367     }
369     /* Assign mode */
370     if ($this->FAIpartitionMethod == ""){
371       $smarty->assign("mode", "");
372       $smarty->assign("storage_mode", "disabled");
373     } else {
374       $smarty->assign("mode", "checked");
375       $smarty->assign("storage_mode", "");
376     }
377     if (!count($this->disks)) {
378       $smarty->assign("lockmode", "");
379     } else {
380       $smarty->assign("lockmode", "disabled");
381     }
382     if (isset($this->disks['raid'])){
383       $smarty->assign("addraid", "disabled");
384     } else {
385       $smarty->assign("addraid", "");
386     }
388     /* Divlist containing disks */
389     $divlist = new divSelectBox("FAItemplates");
390     $divlist->setHeight(400);
391     foreach($this->disks as $key => $disk){
392       $act = "";
394       $dn = "new";
395       if(isset($obj['dn'])){
396         $dn = $obj['dn'];
397       }
398       $dn = $this->acl_base_for_current_object($dn);
399       $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
400       if(preg_match("/(r|w)/",$acl)) {
401         if($disk['status'] != "delete"){
403           $act .= "<input type='image' src='images/lists/edit.png'   name='edit_%s'    title='"._("edit")."' alt='"._("edit")."'>";
404           if(preg_match("/d/",$acl)){
405             $act .="<input type='image' src='images/lists/trash.png' name='delete_%s'  title='"._("delete")."' alt='"._("delete")."'>";
406           }
408           $cnt=0;
409           foreach($disk['partitions'] as $val){
410             if($val['status']!="delete"){
411               $cnt ++;
412             }
413           }
415           $edit_link = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$key."'>".$key."</a>";
416           $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
417                         "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
418           $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
419           $divlist->AddEntry(array( 
420               array("string"=> "<img border='0' src='".$type."'>", "attach"=>"style='width:16px'"),
421               array("string"=> $edit_link, "attach"=>"style='width:100px'"),
422               array("string"=> $disk['description']),
423               array("string"=> $cnt,  "attach"=>"style='width:16px'"),
424               array("string"=>str_replace("%s",base64_encode($key),$act),
425                 "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
426         }
427       }
428     }
429     $smarty->assign("Entry_divlist",$divlist->DrawList());
431     $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
432     return($display);
433   }
437   /* Delete me, and all my subtrees
438    */
439   function remove_from_parent()
440   {
441     $ldap = $this->config->get_ldap_link();
442     $ldap->cd ($this->dn);
444     $release = $this->parent->parent->fai_release;
445     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
447     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
448     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);   
449     foreach($this->disks as $disk){
450       $disk_dn = "cn=".$disk['cn'].",".$this->dn;
451       $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i",$release, $disk_dn);
452       FAI::prepare_to_save_FAI_object($use_dn,array(),true);
453       foreach($disk['partitions'] as $key => $partition){    
454         $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;      
455         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $partition_dn);
456         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
457       }
458     }
459   }
462   /* Save data to object 
463    */
464   function save_object()
465   {
466     if (preg_match("/freeze/", $this->FAIstate)) return;
467     plugin::save_object();
468     foreach($this->attributes as $attrs){
469       if(isset($_POST[$attrs])){
470         $this->$attrs = $_POST[$attrs];
471       }
472     }
473     if(isset($_POST['faiPartitionTable'])){
474       if(!count($this->disks)){
475         if(isset($_POST['mode'])){
476           $this->FAIpartitionMethod = "setup-storage";
477         }else{
478           $this->FAIpartitionMethod = "";
479         }
480       }
481     }
482   }
485   /* Check supplied data */
486   function check()
487   {
488     /* Call common method to give check the hook */
489     $message= plugin::check();
491     /* Ensure that we do not overwrite an allready existing entry 
492      */
493     if($this->is_new){
494       $release = $this->parent->parent->fai_release;
495       $new_dn= 'cn='.$this->cn.",".get_ou('faiPartitionRDN').get_ou('faiBaseRDN').$release;
496       $res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
497       if(isset($res[$this->cn])){
498         $message[] = msgPool::duplicated(_("Name"));
499       }
500     }
501     return ($message);
502   }
505   /* Save to LDAP */
506   function save()
507   {
509     plugin::save();
510     /* Save current settings.
511      * 1 : We must save the partition table, with its description and cn 
512      * 2 : Append Disk with cn and  description.
513      * 3 : Save partitions for each disk
514      */  
516     $ldap = $this->config->get_ldap_link();
518     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
520     if($this->initially_was_account){
521       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
522     }else{
523       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
524     }
525  
526     /* Sort entries, because we must delete entries with status="delete" first */
527     $order = array();
528     foreach($this->disks as $key => $disk){
529       if($disk['status'] == "delete"){
530         $order[$key] = $disk;
531       }
532     }
533     foreach($this->disks as $key => $disk){
534       if($disk['status'] != "delete"){
535         $order[$key] = $disk;
536       }
537     }
539     /* Append all disks to ldap */
540     foreach($order as $cn=>$disk){
541       $disk_dn                    = "cn=".$disk['cn'].",".$this->dn;
542       $disk_attrs['cn']           =  $disk['cn'];
543       $disk_attrs['description']  =  $disk['description'];
544   
545       if(isset($disk['FAIdiskType'])){
546         $disk_attrs['FAIdiskType']  =  $disk['FAIdiskType']; 
547       }
549       if(empty($disk_attrs['description']) && $disk['status'] == "edited"){
550         $disk_attrs['description'] = array();
551       }
553       $disk_attrs['objectClass']  =  array("top","FAIclass","FAIpartitionDisk");
555       if($disk['status']=="new"){
556         $ldap->cat($disk_dn,array("objectClass"));
557         if($ldap->count()){
558           $disk['status']="edited";
559         }
560       }
562       /* Tag object */
563       $this->tag_attrs($disk_attrs, $disk_dn, $this->gosaUnitTag);
565       if($disk['status'] == "delete"){
566         FAI::prepare_to_save_FAI_object($disk_dn,array(),true);
567         $this->handle_post_events("remove");
568       }elseif($disk['status'] == "edited"){
569         FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
570         $this->handle_post_events("modify");
571       }elseif($disk['status']=="new"){
572         FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
573         $this->handle_post_events("add");
574       }
576       if($disk['status']!="delete")
577       /* Add all partitions */
578       foreach($disk['partitions'] as $key => $partition){
579         $partition_attrs = array();
581         foreach($partition as $key => $value){
582           if(!empty($value)){
583             $partition_attrs[$key]=$value;        
584           }else{
585             unset($partition_attrs[$key]);        
586           }
587         }
589         $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;      
590         $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
591         $partition_attrs['cn']= $partition_attrs['FAIpartitionNr'];
592         
593         unset($partition_attrs['status']);
594         unset($partition_attrs['old_cn']);
596         if($partition['status']=="new"){
597           $ldap->cat($partition_dn,array("objectClass"));
598           if($ldap->count()){
599             $partition['status']="edited";
600           }
601         }
603         if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){
604           $partition_attrs['FAImountPoint']="swap";
605         }
607         /* Tag object */
608         $this->tag_attrs($partition_attrs, $partition_dn, $this->gosaUnitTag);
610         if($partition['status'] == "delete"){
611           FAI::prepare_to_save_FAI_object($partition_dn,array(),true);
612           $this->handle_post_events("remove");
613         }elseif($partition['status'] == "edited"){
614           FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
615           $this->handle_post_events("modify");
616         }elseif($partition['status']=="new"){
617           FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
618           $this->handle_post_events("add");
619         }
620       }
621     }
622     $this->handle_post_events("add");
623   }
626   function PrepareForCopyPaste($source)
627   {
628     plugin::PrepareForCopyPaste($source);
630     /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
631      */
632     $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
633     foreach($res as $obj){
635       /* Skip not relevant objects */
636       if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
638       $objects = array();
639       $objects['description']  = "";
640       $objects['status']      = "edited";
641       $objects['dn']          = $obj['dn'];
642       $objects                = $this->get_object_attributes($objects,$this->subAttributes);
643       $this->disks[$objects['cn']] = $objects;
644       $this->disks[$objects['cn']]['partitions'] = array();
645     }
647     /* read all partitions for each disk
648      */
649     foreach($this->disks as $name => $disk){
650       $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
651       foreach($res as $obj){
653         /* Skip not relevant objects */
654         if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
656         $objects = array();
657         $objects['status']      = "edited";
658         $objects['dn']          = $obj['dn'];
659         $objects                = $this->get_object_attributes($objects,$this->subPartAttributes);
660         unset($objects['dn']);;
661         $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
662       }
663     }
664     ksort($this->disks);
665   }
668   /* Return plugin informations for acl handling */ 
669   static function plInfo()
670   {
671     return (array( 
672           "plShortName" => _("Partition table"),
673           "plDescription" => _("FAI partition table"),
674           "plSelfModify"  => FALSE,
675           "plDepends"     => array(),
676           "plPriority"    => 26,
677           "plSection"     => array("administration"),
678           "plCategory"    => array("fai"),
679           "plProvidedAcls" => array(
680             "cn"                => _("Name")."&nbsp;("._("Read only").")",
681             "description"       => _("Description"))
682           ));
683   }
686   /*! \brief  Used for copy & paste.
687     Returns a HTML input mask, which allows to change the cn of this entry.
688     @param  Array   Array containing current status && a HTML template.
689    */
690   function getCopyDialog()
691   {
692     $vars = array("cn");
693     $smarty = get_smarty();
694     $smarty->assign("cn", htmlentities($this->cn));
695     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
696     $ret = array();
697     $ret['string'] = $str;
698     $ret['status'] = "";
699     return($ret);
700   }
703   /*! \brief  Used for copy & paste.
704     Some entries must be renamed to avaoid duplicate entries.
705    */
706   function saveCopyDialog()
707   {
708     if(isset($_POST['cn'])){
709       $this->cn = get_post('cn');
710     }
711   }
713   /* Reload some attributes */
714   function get_object_attributes($object,$attributes)
715   {
716     $ldap = $this->config->get_ldap_link();
717     $ldap->cd($this->config->current['BASE']);
718     $ldap->cat($object['dn'],$attributes);
719     $tmp  = $ldap->fetch();
721     foreach($attributes as $attrs){
722       if(isset($tmp[$attrs][0])){
723         $var = $tmp[$attrs][0];
725         /* Check if we must decode some attributes */
726         if(in_array_ics($attrs,$this->sub64coded)){
727           $var = base64_decode($var);
728         }
730         /*  check if this is a binary entry */
731         if(in_array_ics($attrs,$this->subBinary)){
732           $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
733         }
735         /* Fix slashes */
736         $var = addslashes($var);
737         $object[$attrs] = $var;
738       }
739     }
740     return($object);
741   }
745 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
746 ?>