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","FAIfsCreateOptions","FAIfsTuneOptions","FAIfsOptions","FAIpartitionFlags","FAIlvmDevice");
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 for($i=0;$i<$obj['FAIlvmDevice']['count'];$i++){
62 $name = $obj['FAIlvmDevice'][$i];
63 $objects['FAIlvmDevice'][$name] = $name;
64 }
65 }
67 $objects['dn'] = $obj['dn'];
68 $objects = $this->get_object_attributes($objects,$this->subAttributes);
69 $this->disks[$objects['cn']] = $objects;
70 $this->disks[$objects['cn']]['partitions'] = array();
71 }
73 /* read all partitions for each disk
74 */
75 foreach($this->disks as $name => $disk){
76 $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
77 foreach($res as $obj){
79 /* Skip not relevant objects */
80 if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
82 $objects = array();
83 $objects['status'] = "edited";
84 $objects['dn'] = $obj['dn'];
85 $objects = $this->get_object_attributes($objects,$this->subPartAttributes);
86 unset($objects['dn']);;
87 $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
88 }
89 }
90 }
92 $this->is_new = FALSE;
93 if($this->dn == "new"){
94 $this->is_new =TRUE;
95 }
96 ksort($this->disks);
97 }
100 function acl_base_for_current_object($dn)
101 {
102 if($dn == "new" || $dn == ""){
103 if($this->dn == "new"){
104 $dn= $this->parent->parent->acl_base;
105 }else{
106 $dn = $this->dn;
107 }
108 }
109 return($dn);
110 }
113 function execute()
114 {
115 /* Call parent execute */
116 plugin::execute();
118 if($this->is_account && !$this->view_logged){
119 $this->view_logged = TRUE;
120 new log("view","fai/".get_class($this),$this->dn);
121 }
123 /* Fill templating stuff */
124 $smarty= get_smarty();
125 $display= "";
127 /* Add Disk to this Partitionset
128 * This code adds a new HDD to the disks
129 * A new Dialog will be opened
130 */
131 if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) &&
132 !preg_match("/freeze/i",$this->FAIstate)){
133 $usedDiskNames =array();
134 foreach($this->disks as $key=>$disk){
135 $usedDiskNames[]= $key;
136 }
137 if ($this->FAIpartitionMethod == "setup-storage") {
138 if(isset($_POST['AddDisk'])) $type = "disk";
139 if(isset($_POST['AddRaid'])) $type = "raid";
140 if(isset($_POST['AddAddVolgroup'])) $type = "lvm";
141 $this->dialog = new faiDiskEntry($this->config,$this->dn,$this, array(),$type);
142 } else {
143 $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this);
144 }
146 $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
147 $this->dialog->set_acl_category("fai");
148 $this->dialog->FAIstate = $this->FAIstate;
151 $this->is_dialog = true;
152 }
154 /* Edit disk.
155 * Open dialog which allows us to edit the selected entry
156 */
158 if($this->dn != "new"){
159 set_object_info($this->dn);
160 }
162 /* Edit entries via GET */
163 $Udisk = null;
164 if(isset($_GET['act']) && isset($_GET['id'])){
165 if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
166 $Udisk= $_GET['id'];
167 }
168 }
170 /* New Listhandling */
171 foreach($_POST as $name => $value){
172 if(preg_match("/^edit_/",$name)){
173 $entry = preg_replace("/^edit_/","",$name);
174 $Udisk = base64_decode(preg_replace("/_.*/","",$entry));
175 break;
176 }
177 if(preg_match("/^delete_/",$name)){
178 $entry = preg_replace("/^delete_/","",$name);
179 $disk = base64_decode(preg_replace("/_.*/","",$entry));
181 if (!preg_match("/freeze/i", $this->FAIstate)){
182 if(isset($this->disks[$disk])){
184 /* Check for references */
185 $ignore = false;
186 $name = "";
187 foreach($this->disks as $dtest) {
188 // Is raid?
189 $device= null;
190 $name = $dtest['cn'];
192 if ($disk == "raid"){
193 $device = "md";
194 } else {
195 $device = $disk;
197 // Used by raid?
198 if (isset($this->disks[$name]['partitions'])){
199 foreach ($this->disks[$name]['partitions'] as $partition) {
200 if (preg_match("/${disk}\.?[0-9]+/", $partition['FAIpartitionSize'])){
201 $ignore = true;
202 break 2;
203 }
204 }
205 }
206 }
208 // Used by volgroup?
209 if (isset($this->disks[$name]["FAIlvmDevice"])){
210 foreach ($this->disks[$name]["FAIlvmDevice"] as $vg_element) {
211 if (preg_match("/^${device}\.?[0-9]+$/", $vg_element)){
212 $ignore = true;
213 break 2;
214 }
215 }
216 }
217 }
219 if ($ignore) {
220 msg_dialog::display(_("Error"), sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), $name), ERROR_DIALOG);
221 } else {
222 if($this->disks[$disk]['status']=="edited"){
223 $this->disks[$disk."-delete"]=$this->disks[$disk];
224 unset($this->disks[$disk]);
225 $disk = $disk."-delete";
226 $this->disks[$disk]['status']="delete";
227 foreach($this->disks[$disk]['partitions'] as $name => $value ){
228 if($value['status']=="edited"){
229 $this->disks[$disk]['partitions'][$name]['status']="delete";
230 }else{
231 unset($this->disks[$disk]['partitions'][$name]);
232 }
233 }
234 }else{
235 unset($this->disks[$disk]);
236 }
237 }
239 }
240 }
241 break;
242 }
243 }
245 if($Udisk){
246 $usedDiskNames =array();
247 if(isset($this->disks[$Udisk])){
249 foreach($this->disks as $key=>$disk){
250 if($key != $Udisk){
251 $usedDiskNames[]= $key;
252 }
253 }
255 /* Set object info string, which will be displayed in plugin info line */
256 if(isset($this->disks[$Udisk]['dn'])){
257 set_object_info($this->disks[$Udisk]['dn']);
258 $dn = $this->disks[$Udisk]['dn'];
259 }else{
260 set_object_info("");
261 $dn = "new";
262 }
264 if(isset($this->disks[$Udisk]['FAIdiskType'])){
265 switch($this->disks[$Udisk]['FAIdiskType']){
266 case 'raid':
267 case 'lvm':
268 case 'disk':
269 $this->dialog = new faiDiskEntry(
270 $this->config,$this->dn,$this,$this->disks[$Udisk],
271 $this->disks[$Udisk]['FAIdiskType']);
272 break;
273 case 'old':
274 $this->dialog = new faiPartitionTableEntry(
275 $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
276 break;
277 }
278 }else{
279 $this->dialog = new faiPartitionTableEntry(
280 $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
281 }
282 if($this->dialog){
283 $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
284 $this->dialog->set_acl_category("fai");
285 $this->dialog->FAIstate = $this->FAIstate;
286 $this->is_dialog = true;
287 }
288 }
289 }
291 /* Edit aborted, close dialog, without saving anything
292 */
293 if(isset($_POST['CancelDisk'])){
294 unset($this->dialog);
295 $this->dialog = FALSE;
296 $this->is_dialog=false;
297 }
299 /* Dialog saved
300 * Save given data from Dialog, if no error is occurred
301 */
302 if(isset($_POST['SaveDisk'])){
304 if (!preg_match("/freeze/i", $this->FAIstate)){
305 $this->dialog->save_object();
306 if(count($this->dialog->check())){
307 foreach($this->dialog->check() as $msg){
308 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
309 }
310 }else{
311 $disk = $this->dialog->save();
312 if(isset($disk['rename'])){
313 if($this->disks[$disk['rename']['from']]['status']=="edited"){
314 $this->disks[$disk['rename']['from']]['status']="delete";
315 }else{
316 unset($this->disks[$disk['rename']['from']]);
317 }
319 foreach($disk['partitions'] as $key => $val){
320 if($disk['partitions'][$key]['status']!="delete"){
321 $disk['partitions'][$key]['status']= "new";
322 }
323 }
325 $disk['status']="new";
326 $disk['cn']= $disk['rename']['to'];
327 }
329 $this->disks[$disk['cn']]=$disk;
330 unset($this->dialog);
331 $this->dialog = FALSE;
332 $this->is_dialog=false;
333 ksort($this->disks);
334 }
335 }else{
336 $this->dialog = FALSE;
337 $this->is_dialog=false;
338 }
339 }
341 /* Display dialog if one is defined
342 */
343 if(is_object($this->dialog)){
344 $this->dialog->save_object();
345 return($this->dialog->execute());
346 }
348 /* Assign all attributes to smarty engine
349 */
350 foreach($this->attributes as $attrs){
351 $smarty->assign($attrs,$this->$attrs);
352 if($this->$attrs){
353 $smarty->assign($attrs."CHK"," ");
354 }else{
355 $smarty->assign($attrs."CHK"," disabled ");
356 }
357 }
359 $dn = $this->acl_base_for_current_object($this->dn);
360 $smarty->assign("sub_object_is_addable",
361 preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
362 !preg_match("/freeze/",$this->FAIstate));
363 $smarty->assign("sub_object_is_removeable",
364 preg_match("/d/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
365 !preg_match("/freeze/",$this->FAIstate));
367 $tmp = $this->plInfo();
368 foreach($tmp['plProvidedAcls'] as $name => $translated){
369 $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
370 }
372 /* Assign mode */
373 if ($this->FAIpartitionMethod == ""){
374 $smarty->assign("mode", "");
375 $smarty->assign("storage_mode", "disabled");
376 } else {
377 $smarty->assign("mode", "checked");
378 $smarty->assign("storage_mode", "");
379 }
380 if (!count($this->disks)) {
381 $smarty->assign("lockmode", "");
382 } else {
383 $smarty->assign("lockmode", "disabled");
384 }
385 if (isset($this->disks['raid'])){
386 $smarty->assign("addraid", "disabled");
387 } else {
388 $smarty->assign("addraid", "");
389 }
391 /* Divlist containing disks */
392 $divlist = new divSelectBox("FAItemplates");
393 $divlist->setHeight(400);
394 foreach($this->disks as $key => $disk){
395 $act = "";
397 $dn = "new";
398 if(isset($obj['dn'])){
399 $dn = $obj['dn'];
400 }
401 $dn = $this->acl_base_for_current_object($dn);
402 $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
403 if(preg_match("/(r|w)/",$acl)) {
404 if($disk['status'] != "delete"){
406 $act .= "<input type='image' src='images/lists/edit.png' name='edit_%s' title='"._("edit")."' alt='"._("edit")."'>";
407 if(preg_match("/d/",$acl)){
408 $act .="<input type='image' src='images/lists/trash.png' name='delete_%s' title='"._("delete")."' alt='"._("delete")."'>";
409 }
411 $cnt=0;
412 foreach($disk['partitions'] as $val){
413 if($val['status']!="delete"){
414 $cnt ++;
415 }
416 }
418 $edit_link = "<a href='?plug=".$_GET['plug']."&act=edit&id=".$key."'>".$key."</a>";
419 $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
420 "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
421 $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
422 $divlist->AddEntry(array(
423 array("string"=> "<img border='0' src='".$type."'>", "attach"=>"style='width:16px'"),
424 array("string"=> $edit_link, "attach"=>"style='width:100px'"),
425 array("string"=> $disk['description']),
426 array("string"=> $cnt, "attach"=>"style='width:16px'"),
427 array("string"=>str_replace("%s",base64_encode($key),$act),
428 "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
429 }
430 }
431 }
432 $smarty->assign("Entry_divlist",$divlist->DrawList());
434 $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
435 return($display);
436 }
440 /* Delete me, and all my subtrees
441 */
442 function remove_from_parent()
443 {
444 $ldap = $this->config->get_ldap_link();
445 $ldap->cd ($this->dn);
447 $release = $this->parent->parent->fai_release;
448 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
450 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
451 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
452 foreach($this->disks as $disk){
453 $disk_dn = "cn=".$disk['cn'].",".$this->dn;
454 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i",$release, $disk_dn);
455 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
456 foreach($disk['partitions'] as $key => $partition){
457 $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;
458 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $partition_dn);
459 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
460 }
461 }
462 }
465 /* Save data to object
466 */
467 function save_object()
468 {
469 if (preg_match("/freeze/", $this->FAIstate)) return;
470 plugin::save_object();
471 foreach($this->attributes as $attrs){
472 if(isset($_POST[$attrs])){
473 $this->$attrs = $_POST[$attrs];
474 }
475 }
476 if(isset($_POST['faiPartitionTable'])){
477 if(!count($this->disks)){
478 if(isset($_POST['mode'])){
479 $this->FAIpartitionMethod = "setup-storage";
480 }else{
481 $this->FAIpartitionMethod = "";
482 }
483 }
484 }
485 }
488 /* Check supplied data */
489 function check()
490 {
491 /* Call common method to give check the hook */
492 $message= plugin::check();
494 /* Ensure that we do not overwrite an allready existing entry
495 */
496 if($this->is_new){
497 $release = $this->parent->parent->fai_release;
498 $new_dn= 'cn='.$this->cn.",".get_ou('faiPartitionRDN').get_ou('faiBaseRDN').$release;
499 $res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
500 if(isset($res[$this->cn])){
501 $message[] = msgPool::duplicated(_("Name"));
502 }
503 }
504 return ($message);
505 }
508 /* Save to LDAP */
509 function save()
510 {
512 plugin::save();
513 /* Save current settings.
514 * 1 : We must save the partition table, with its description and cn
515 * 2 : Append Disk with cn and description.
516 * 3 : Save partitions for each disk
517 */
519 $ldap = $this->config->get_ldap_link();
521 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
523 if($this->initially_was_account){
524 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
525 }else{
526 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
527 }
529 /* Sort entries, because we must delete entries with status="delete" first */
530 $order = array();
531 foreach($this->disks as $key => $disk){
532 if($disk['status'] == "delete"){
533 $order[$key] = $disk;
534 }
535 }
536 foreach($this->disks as $key => $disk){
537 if($disk['status'] != "delete"){
538 $order[$key] = $disk;
539 }
540 }
542 /* Append all disks to ldap */
543 foreach($order as $cn=>$disk){
544 $disk_dn = "cn=".$disk['cn'].",".$this->dn;
545 $disk_attrs['cn'] = $disk['cn'];
546 $disk_attrs['description'] = $disk['description'];
548 if(isset($disk['FAIdiskType'])){
549 $disk_attrs['FAIdiskType'] = $disk['FAIdiskType'];
550 }
551 if(isset($disk['FAIdiskOption'])){
552 $disk_attrs['FAIdiskOption'] = $disk['FAIdiskOption'];
553 }
554 if(isset($disk['FAIlvmDevice'])){
555 $disk_attrs['FAIlvmDevice'] = $disk['FAIlvmDevice'];
556 }
558 if(empty($disk_attrs['description']) && $disk['status'] == "edited"){
559 $disk_attrs['description'] = array();
560 }
562 $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk");
564 if($disk['status']=="new"){
565 $ldap->cat($disk_dn,array("objectClass"));
566 if($ldap->count()){
567 $disk['status']="edited";
568 }
569 }
571 /* Tag object */
572 $this->tag_attrs($disk_attrs, $disk_dn, $this->gosaUnitTag);
574 if($disk['status'] == "delete"){
575 FAI::prepare_to_save_FAI_object($disk_dn,array(),true);
576 $this->handle_post_events("remove");
577 }elseif($disk['status'] == "edited"){
578 FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
579 $this->handle_post_events("modify");
580 }elseif($disk['status']=="new"){
581 FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
582 $this->handle_post_events("add");
583 }
585 if($disk['status']!="delete")
587 /* Add all partitions */
588 foreach($disk['partitions'] as $key => $partition){
589 $partition_attrs = array();
591 foreach($partition as $key => $value){
592 if(!empty($value)){
593 $partition_attrs[$key]=$value;
594 }else{
595 unset($partition_attrs[$key]);
596 }
597 }
599 $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;
600 $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
602 unset($partition_attrs['status']);
603 unset($partition_attrs['old_cn']);
605 if($partition['status']=="new"){
606 $ldap->cat($partition_dn,array("objectClass"));
607 if($ldap->count()){
608 $partition['status']="edited";
609 }
610 }
612 if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){
613 $partition_attrs['FAImountPoint']="swap";
614 }
616 /* Tag object */
617 $this->tag_attrs($partition_attrs, $partition_dn, $this->gosaUnitTag);
619 if($partition['status'] == "delete"){
620 FAI::prepare_to_save_FAI_object($partition_dn,array(),true);
621 $this->handle_post_events("remove");
622 }elseif($partition['status'] == "edited"){
623 FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
624 $this->handle_post_events("modify");
625 }elseif($partition['status']=="new"){
626 FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
627 $this->handle_post_events("add");
628 }
629 }
630 }
631 $this->handle_post_events("add");
632 }
635 function PrepareForCopyPaste($source)
636 {
637 plugin::PrepareForCopyPaste($source);
639 /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
640 */
641 $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
642 foreach($res as $obj){
644 /* Skip not relevant objects */
645 if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
647 $objects = array();
648 $objects['description'] = "";
649 $objects['status'] = "edited";
650 $objects['dn'] = $obj['dn'];
651 $objects = $this->get_object_attributes($objects,$this->subAttributes);
652 $this->disks[$objects['cn']] = $objects;
653 $this->disks[$objects['cn']]['partitions'] = array();
654 }
656 /* read all partitions for each disk
657 */
658 foreach($this->disks as $name => $disk){
659 $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
660 foreach($res as $obj){
662 /* Skip not relevant objects */
663 if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
665 $objects = array();
666 $objects['status'] = "edited";
667 $objects['dn'] = $obj['dn'];
668 $objects = $this->get_object_attributes($objects,$this->subPartAttributes);
669 unset($objects['dn']);;
670 $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
671 }
672 }
673 ksort($this->disks);
674 }
677 /* Return plugin informations for acl handling */
678 static function plInfo()
679 {
680 return (array(
681 "plShortName" => _("Partition table"),
682 "plDescription" => _("FAI partition table"),
683 "plSelfModify" => FALSE,
684 "plDepends" => array(),
685 "plPriority" => 26,
686 "plSection" => array("administration"),
687 "plCategory" => array("fai"),
688 "plProvidedAcls" => array(
689 "cn" => _("Name")." ("._("Read only").")",
690 "description" => _("Description"))
691 ));
692 }
695 /*! \brief Used for copy & paste.
696 Returns a HTML input mask, which allows to change the cn of this entry.
697 @param Array Array containing current status && a HTML template.
698 */
699 function getCopyDialog()
700 {
701 $vars = array("cn");
702 $smarty = get_smarty();
703 $smarty->assign("cn", htmlentities($this->cn));
704 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
705 $ret = array();
706 $ret['string'] = $str;
707 $ret['status'] = "";
708 return($ret);
709 }
712 /*! \brief Used for copy & paste.
713 Some entries must be renamed to avaoid duplicate entries.
714 */
715 function saveCopyDialog()
716 {
717 if(isset($_POST['cn'])){
718 $this->cn = get_post('cn');
719 }
720 }
722 /* Reload some attributes */
723 function get_object_attributes($object,$attributes)
724 {
725 $ldap = $this->config->get_ldap_link();
726 $ldap->cd($this->config->current['BASE']);
727 $ldap->cat($object['dn'],$attributes);
728 $tmp = $ldap->fetch();
730 foreach($attributes as $attrs){
731 if(isset($tmp[$attrs][0])){
732 $var = $tmp[$attrs][0];
734 /* Check if we must decode some attributes */
735 if(in_array_ics($attrs,$this->sub64coded)){
736 $var = base64_decode($var);
737 }
739 /* check if this is a binary entry */
740 if(in_array_ics($attrs,$this->subBinary)){
741 $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
742 }
744 /* Fix slashes */
745 $var = addslashes($var);
746 $object[$attrs] = $var;
747 }
748 }
749 return($object);
750 }
752 }
754 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
755 ?>