Code

Updated get_ou()
[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","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']  = "";
50         // Transform disk type into image later...
51         if (!isset($obj['FAIdiskType'])){
52           $objects['FAIdiskType']        = "old";
53         } else {
54           $objects['FAIdiskType']        = $obj['FAIdiskType'];
55         }
57         // Get disk options, without 'count' index. 
58         $objects['FAIdiskOption'] = array();
59         if (isset($obj['FAIdiskOption'])){
60           for($i=0;$i<$obj['FAIdiskOption']['count'];$i++){ 
61             $objects['FAIdiskOption'][] = $obj['FAIdiskOption'][$i];
62           }
63         }
65         // Transform potential lvm information
66         if (isset($obj['FAIlvmDevice'])){
67           for($i=0;$i<$obj['FAIlvmDevice']['count'];$i++){
68             $name = $obj['FAIlvmDevice'][$i]; 
69             $objects['FAIlvmDevice'][$name] = $name;
70           }
71         }
73         $objects['dn']          = $obj['dn'];
74         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
75         $this->disks[$objects['cn']] = $objects;
76         $this->disks[$objects['cn']]['partitions'] = array();
77       }
79       /* read all partitions for each disk 
80        */
81       foreach($this->disks as $name => $disk){
82         $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
83         foreach($res as $obj){
85           /* Skip not relevant objects */
86           if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
88           $objects = array();
89           $objects['dn']          = $obj['dn'];
90           $objects                = $this->get_object_attributes($objects,$this->subPartAttributes);
91           unset($objects['dn']);;
92           $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
93         }
94       }
95     }
97     /* Keep track of disk changes, by comparing the initial and resulting 
98      *  disk setup.
99      */
100     $this->initial_disks = $this->disks;
102     $this->is_new = FALSE;
103     if($this->dn == "new"){
104       $this->is_new =TRUE;
105     }
106     ksort($this->disks);
108     // Prepare lists
109     $this->diskList = new sortableListing();
110     $this->diskList->setDeleteable(true);
111     $this->diskList->setEditable(true);
112     $this->diskList->setWidth("100%");
113     $this->diskList->setHeight("400px");
114     $this->diskList->setColspecs(array('20px','*','*','40px'));
115     $this->diskList->setHeader(array(("?"),_("Name"),_("Description"),"#"));
116     $this->diskList->setDefaultSortColumn(1);
118   }
121   function acl_base_for_current_object($dn)
122   {
123     if($dn == "new" || $dn == ""){
124       if($this->dn == "new"){
125         $dn= $this->parent->parent->acl_base;
126       }else{
127         $dn = $this->dn;
128       }
129     }
130     return($dn);
131   }
134   function execute()
135   {
136     /* Call parent execute */
137     plugin::execute();
139     if($this->is_account && !$this->view_logged){
140       $this->view_logged = TRUE;
141       new log("view","fai/".get_class($this),$this->dn);
142     }
144     /* Fill templating stuff */
145     $smarty= get_smarty();
146     $display= "";
147  
148     /* Add Disk to this Partitionset
149      * This code adds a new HDD to the disks 
150      * A new Dialog will be opened 
151      */
152     if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) && 
153         !preg_match("/freeze/i",$this->FAIstate)){
154       $usedDiskNames =array();
155       foreach($this->disks as $key=>$disk){
156         $usedDiskNames[]= $key;
157       }
158       if ($this->FAIpartitionMethod == "setup-storage") {
159         if(isset($_POST['AddDisk'])) $type = "disk";
160         if(isset($_POST['AddRaid'])) $type = "raid";
161         if(isset($_POST['AddVolgroup'])) $type = "lvm";
162         $this->dialog = new faiDiskEntry($this->config,$this->dn,$this, array(),$type); 
163       } else {
164         $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this); 
165       }
167       $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
168       $this->dialog->set_acl_category("fai");
169       $this->dialog->FAIstate = $this->FAIstate;
172       $this->is_dialog = true;
173     }
175     /* Edit disk.
176      * Open dialog which allows us to edit the selected entry 
177      */    
179     if($this->dn != "new"){
180       set_object_info($this->dn);
181     }
183     /* Edit entries via GET */
184     $s_action = "";
185     $s_entry = "";
186     if(isset($_GET['act']) && isset($_GET['id'])){
187       if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
188         $s_entry= $_GET['id'];
189         $s_action= "edit";
190       }
191     }
193     $this->diskList->save_object();
194     $action = $this->diskList->getAction();
195     if($action['action'] == 'edit'){
196         $s_entry = $this->diskList->getKey($action['targets'][0]);
197         $s_action ="edit";
198     }
199     if($action['action'] == 'delete'){
200         $s_entry = $this->diskList->getKey($action['targets'][0]);
201         $s_action ="remove";
202     }
204     /* Disk remove was requested. 
205      * Now check if the disk is still in use, in this case 
206      *  display a warning message and abort the removal. 
207      * If the disk is not used anymore, then remove it. 
208      */
209     if($s_action == "remove"){
210       if(isset($this->disks[$s_entry])){
212         /* Create a list of all partitions that are used in 
213          *  lvm or raid compilations. 
214          */
215         $list = array();
216         foreach($this->disks as $dname => $disk){
217           if($disk['FAIdiskType'] != "disk" && $dname != $s_entry){
218             if($disk['FAIdiskType'] == "lvm"){
219               foreach($disk['FAIlvmDevice'] as $partname){
220                 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
221               }
222             }
223             foreach($disk['partitions'] as $partkey => $part){
224               if($disk['FAIdiskType'] == "raid"){
225                 foreach(explode(",",$part['FAIpartitionSize']) as $partname){
226                   $list[preg_replace("/:.*$/","",$partname)][] = $disk;
227                 }
228               }
229             }  
230           }
231         }
233         /* Now that we've a list of all partition references, lets check if
234          *  one of the partitions we are going to remove is still in use.
235          */
236         $used = array();
237         foreach($this->disks[$s_entry]['partitions'] as $part){
238           if(isset($list[$part['cn']])){    
239             foreach($list[$part['cn']] as $disk){
240               $used[$disk['cn']] = $disk['cn'];
241             }
242           }
243         }
245         /* Skip removal while disk is in use. 
246          */
247         if(count($used)){
248           $used = implode(",",$used);
249           msg_dialog::display(_("Error"), 
250               sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), 
251                 $used), ERROR_DIALOG);
252         }else{
254           /* Everything is ok, we can remove the disk now.
255            */
256           unset($this->disks[$s_entry]);
257         } 
258       } 
259     }
261     
263     if($s_action == "edit"){
265       /* Set object info string, which will be displayed in plugin info line */ 
266       if(isset($this->disks[$s_entry]['dn'])){
267         set_object_info($this->disks[$s_entry]['dn']);
268         $dn = $this->disks[$s_entry]['dn'];
269       }else{
270         set_object_info("");
271         $dn = "new";
272       }
274       $type ="old"; 
275       if(isset($this->disks[$s_entry]['FAIdiskType'])){
276         $type = $this->disks[$s_entry]['FAIdiskType'];
277       }
278       if(in_array($type,array('raid','lvm','disk'))){
279         $this->dialog = new faiDiskEntry(
280             $this->config,$this->dn,$this,$this->disks[$s_entry], 
281             $this->disks[$s_entry]['FAIdiskType']); 
283       }else{
284         $this->dialog = new faiPartitionTableEntry(
285             $this->config,$this->dn,$this,$this->disks[$s_entry]); 
286       }
287       if($this->dialog){
288         $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
289         $this->dialog->set_acl_category("fai");
290         $this->dialog->FAIstate = $this->FAIstate;
291         $this->is_dialog = true;
292       }
293     }
295     /* Edit aborted, close dialog, without saving anything
296      */
297     if(isset($_POST['CancelDisk'])){
298       unset($this->dialog);
299       $this->dialog = FALSE;
300       $this->is_dialog=false;
301     }
303     /* Dialog saved
304      * Save given data from Dialog, if no error is occurred
305      */
306     if(isset($_POST['SaveDisk'])){
308       if (!preg_match("/freeze/i", $this->FAIstate)){
309         $this->dialog->save_object();
310         if(count($this->dialog->check())){
311           foreach($this->dialog->check() as $msg){
312             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
313           }
314         }else{
315           $disk = $this->dialog->save();
316           if(isset($disk['rename'])){
317             unset($this->disks[$disk['rename']['from']]);
318             $disk['cn']= $disk['rename']['to'];
319           }
321           $this->disks[$disk['cn']]=$disk; 
322           unset($this->dialog);
323           $this->dialog = FALSE;
324           $this->is_dialog=false;
325           ksort($this->disks);
326         }
327       }else{
328         $this->dialog = FALSE;
329         $this->is_dialog=false;
330       }
331     }
333     /* Display dialog if one is defined
334      */
335     if(is_object($this->dialog)){
336       $this->dialog->save_object();
337       return($this->dialog->execute());
338     }
340     /* Assign all attributes to smarty engine
341      */
342     foreach($this->attributes as $attrs){
343       $smarty->assign($attrs,$this->$attrs);
344       if($this->$attrs){
345         $smarty->assign($attrs."CHK"," ");
346       }else{
347         $smarty->assign($attrs."CHK"," disabled ");
348       }
349     }
350    
351     $dn = $this->acl_base_for_current_object($this->dn);
352     $smarty->assign("sub_object_is_addable",
353         preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
354         !preg_match("/freeze/",$this->FAIstate));
355     $smarty->assign("sub_object_is_removeable",
356         preg_match("/d/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
357         !preg_match("/freeze/",$this->FAIstate));
359     $tmp = $this->plInfo();
360     foreach($tmp['plProvidedAcls'] as $name => $translated){
361       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
362     }
364     /* Assign mode */
365     if ($this->FAIpartitionMethod == ""){
366       $smarty->assign("mode", "");
367       $smarty->assign("storage_mode", "disabled");
368     } else {
369       $smarty->assign("mode", "checked");
370       $smarty->assign("storage_mode", "");
371     }
372     if (!count($this->disks)) {
373       $smarty->assign("lockmode", "");
374     } else {
375       $smarty->assign("lockmode", "disabled");
376     }
377     if (isset($this->disks['raid'])){
378       $smarty->assign("addraid", "disabled");
379     } else {
380       $smarty->assign("addraid", "");
381     }
383     $dn = $this->acl_base_for_current_object($this->dn);
384     $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
385     $this->diskList->setAcl($acl);
386     $data = $lData = array();
387     foreach($this->disks as $key => $disk){
388       $act = "";
390       $dn = "new";
391       if(isset($obj['dn'])){
392         $dn = $obj['dn'];
393       }
394       $dn = $this->acl_base_for_current_object($dn);
395       $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
396       if(preg_match("/(r|w)/",$acl)) {
397         $cnt= count($disk['partitions']);
398         $types= array(
399             "old"  => "plugins/fai/images/fai_partitionTable.png", 
400             "disk" => "plugins/fai/images/fai_partitionTable.png",
401             "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
402         $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
403         $data[$key] = $key;
404         $lData[$key] = array('data' => array(image($type),$key,$disk['description'],$cnt));
405       }
406     }
407     $this->diskList->setListData($data,$lData);
408     $this->diskList->update();
409     $smarty->assign("Entry_listing",$this->diskList->render());
411     $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
412     return($display);
413   }
416   function getUsedDiskNames()
417   {
418     $ret = array();
419     foreach($this->disks as $disk){
420       $ret[] = $disk['cn'];
421     }
422     return($ret);  
423   }
426   /* Delete me, and all my subtrees
427    */
428   function remove_from_parent()
429   {
430     $ldap = $this->config->get_ldap_link();
431     $ldap->cd ($this->dn);
433     $release = $this->parent->parent->fai_release;
434     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
436     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
437     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);   
438     foreach($this->initial_disks as $disk){
439       $disk_dn = "cn=".$disk['cn'].",".$this->dn;
440       $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i",$release, $disk_dn);
441       FAI::prepare_to_save_FAI_object($use_dn,array(),true);
442       foreach($disk['partitions'] as $key => $partition){    
443         $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;      
444         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $partition_dn);
445         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
446       }
447     }
448   }
451   /* Save data to object 
452    */
453   function save_object()
454   {
455     if(isset($_POST['FAIpartitionTablePosted'])){
456       if (preg_match("/freeze/", $this->FAIstate)) return;
457       plugin::save_object();
458 #     foreach($this->attributes as $attrs){
459 #       if(isset($_POST[$attrs])){
460 #         $this->$attrs = $_POST[$attrs];
461 #       }
462 #     }
463       if(!count($this->disks)){
464         if(isset($_POST['mode'])){
465           $this->FAIpartitionMethod = "setup-storage";
466         }else{
467           $this->FAIpartitionMethod = "";
468         }
469       }
470     }
471   }
474   /* Check supplied data */
475   function check()
476   {
477     /* Call common method to give check the hook */
478     $message= plugin::check();
480     /* Ensure that we do not overwrite an allready existing entry 
481      */
482     if($this->is_new){
483       $release = $this->parent->parent->fai_release;
484       $new_dn= 'cn='.$this->cn.",".get_ou("faiPartitionTable", "faiPartitionRDN").get_ou('faiBaseRDN').$release;
485       $res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
486       if(isset($res[$this->cn])){
487         $message[] = msgPool::duplicated(_("Name"));
488       }
489     }
490     return ($message);
491   }
494   /* Save to LDAP */
495   function save()
496   {
497     plugin::save();
499     /* Save current settings.
500      * 1 : We must save the partition table, with its description and cn 
501      * 2 : Append Disk with cn and  description.
502      * 3 : Save partitions for each disk
503      */  
505     $ldap = $this->config->get_ldap_link();
507     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
509     if($this->initially_was_account){
510       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
511       @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Saving disk: ");
512     }else{
513       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
514       @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Adding disk: ");
515     }
516  
517     // Prepare disks to be saved - The 'status' attribute is added here.
518     $this->prepareDiskToBeSave(); 
519  
520     /* Sort entries, because we must delete entries with status="delete" first */
521     $order = array();
522     foreach($this->disks as $key => $disk){
523       if($disk['status'] == "delete"){
524         $order[$key] = $disk;
525       }
526     }
527     foreach($this->disks as $key => $disk){
528       if($disk['status'] != "delete"){
529         $order[$key] = $disk;
530       }
531     }
534     /* Append all disks to ldap */
535     foreach($order as $cn=>$disk){
537       $disk_dn                    = "cn=".$disk['cn'].",".$this->dn;
538       $short_dn                   = "cn=".$disk['cn'].",...";
539       $disk_attrs['cn']           =  $disk['cn'];
540       $disk_attrs['objectClass']  =  array("top","FAIclass","FAIpartitionDisk");
541   
543       if($disk['status']=="new"){
544         $ldap->cat($disk_dn,array("objectClass"));
545         if($ldap->count()){
546           $disk['status']="edited";
547         }
548       }
550       foreach(array("description","FAIdiskType","FAIdiskOption","FAIlvmDevice") as $attr){
551         if($disk['status'] == "new"){
552           if(isset($disk_attrs[$attr])) unset($disk_attrs[$attr]);
553           if(isset($disk[$attr]) && !empty($disk[$attr])){
554             if(is_array($disk[$attr])){
555               $disk_attrs[$attr] = array_values($disk[$attr]);
556             }else{
557               $disk_attrs[$attr] = $disk[$attr];
558             }
559           }
560         }else{
561           if(isset($disk[$attr]) && !empty($disk[$attr])){
562             if(is_array($disk[$attr])){
563               $disk_attrs[$attr] = array_values($disk[$attr]);
564             }else{
565               $disk_attrs[$attr] = $disk[$attr];
566             }
567           }else{
568             $disk_attrs[$attr] = array();
569           }
570         }
571       }
574       /* Tag object */
575       $this->tag_attrs($disk_attrs, $disk_dn, $this->gosaUnitTag);
577       if($disk['status'] == "delete"){
578         @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing disk: ");
579         FAI::prepare_to_save_FAI_object($disk_dn,array(),true);
580         $this->handle_post_events("remove");
581         unset($this->disks[$cn]);
582       }elseif($disk['status'] == "edited"){
583         @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating disk: ");
584         FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
585         $this->handle_post_events("modify");
586       }elseif($disk['status']=="new"){
587         @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding disk: ");
588         FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
589         $this->handle_post_events("add");
590       }
592       if($disk['status']!="delete")
594       /* Add all partitions */
595       foreach($disk['partitions'] as $pkey => $partition){
596         $partition_attrs = array();
598         foreach($partition as $key => $value){
599           if(!empty($value)){
600             $partition_attrs[$key]=$value;        
601           }else{
602             unset($partition_attrs[$key]);        
603           }
604         }
606         $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;     
607         $short_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",...";
608      
609         $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
610         
611         unset($partition_attrs['status']);
612         unset($partition_attrs['old_cn']);
614         if($partition['status']=="new"){
615           $ldap->cat($partition_dn,array("objectClass"));
616           if($ldap->count()){
617             $partition['status']="edited";
618           }
619         }
621         if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){
622           $partition_attrs['FAImountPoint']="swap";
623         }
625         /* Tag object */
626         $this->tag_attrs($partition_attrs, $partition_dn, $this->gosaUnitTag);
628         
629         if($partition['status'] == "delete"){
630           @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing partition: ");
631           FAI::prepare_to_save_FAI_object($partition_dn,array(),true);
632           $this->handle_post_events("remove");
633           unset($this->disks[$cn]['partitions'][$pkey]);
634         }elseif($partition['status'] == "edited"){
635           @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating partition: ");
636           FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
637           $this->handle_post_events("modify");
638         }elseif($partition['status']=="new"){
639           @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding partition: ");
640           FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
641           $this->handle_post_events("add");
642         }
643         
644         // We do not need the status flag any longer 
645         if(isset($this->disks[$cn]['partitions'][$pkey]['status'])){
646           unset($this->disks[$cn]['partitions'][$pkey]['status']);
647         }
648       }
649       // We do not need the status flag any longer 
650       if(isset($this->disks[$cn]['status'])){
651         unset($this->disks[$cn]['status']);
652       }
653     }
654     $this->initial_disks = $this->disks;
655     $this->handle_post_events("add");
656   }
659   function prepareDiskToBeSave()
660   {
661     foreach($this->disks as $id => $disk){
662       
663       /* Correct FAIpartitionNr.
664        * If we've only primary partition then set the partition numbers from  
665        *  1 to 4, else set the primary from 1 to 3 and logical >= 5 
666        * 
667        */
668       if(!isset($disk['partitions'])){
669         $disk['partitions'] = array();
670       }
671       $newSetup = array();
673       if($disk['FAIdiskType'] == "disk"){
674         $primary = $logical = array();
675         foreach($disk['partitions'] as $partid => $part){
676           if($part['FAIpartitionType'] == "primary"){
677             $primary[$partid] = $part;
678           }elseif($part['FAIpartitionType'] == "logical"){
679             $logical[$partid] = $part;
680           }else{
681             trigger_error("Fatal: unknown disk type? ".$part['FAIpartitionType']); 
682           }
683         }
684         $cnt = 1;
685         foreach($primary as $part){
686           $part['FAIpartitionNr'] = $cnt;
687           $part['cn'] = $disk['cn'].$cnt;
688           $newSetup[$cnt] = $part;
689           $cnt ++;
690         } 
691         $cnt = 5;
692         foreach($logical as $part){
693           $part['FAIpartitionNr'] = $cnt;
694           $part['cn'] = $disk['cn'].$cnt;
695           $newSetup[$cnt] = $part;
696           $cnt ++;
697         }
698         $this->disks[$disk['cn']]['partitions'] = $newSetup; 
699       }
700     }
702  
703     # FAIpartitionNr have to be used as index for this->disks
704     #  else the next operation will fail. 
706  
707     /* Check if there are disks to be removed, edited or added.
708      * We compare the initial disk setup with the current setup and
709      *  and add a status flag, which will then be used to perform the 
710      *  correct action - add, edited, remove.
711      */
712     foreach($this->disks as $key => $disk){
714       // - A complete NEW disk
715       if(!isset($this->initial_disks[$disk['cn']])){
716         $this->disks[$key]['status'] = "new";
717         foreach($disk['partitions'] as $pkey => $part){
718           $this->disks[$disk['cn']]['partitions'][$pkey]['status'] = "new";
719         }
720       }else{
721     
722         // - Disk was "EDITED" 
723         $this->disks[$key]['status'] = "edited";
724         foreach($disk['partitions'] as $pkey => $part){
726           // - Check whether partition is "NEW" or "EDITED" 
727           if(!isset($this->initial_disks[$key]['partitions'][$pkey])){
728             $this->disks[$key]['partitions'][$pkey]['status'] = "new";
729           }else{
730             $this->disks[$key]['partitions'][$pkey]['status'] = "edited";
731           }
732         }
733       }
734     }
735      
736     /* Check which partitions havbe to be removed. 
737      * (They intially existed, but are now gone.)
738      */ 
739     foreach($this->initial_disks as $ikey => $idisk){
740       
741       // - Complete disk was REMOVED.
742       if(!isset($this->disks[$idisk['cn']])){
743         $this->disks[$idisk['cn']] = $idisk;
744         $this->disks[$idisk['cn']]['status'] = "delete";
745         foreach($idisk['partitions'] as $pkey=>$part){
746           $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
747           $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
748         }
749       }else{
750         foreach($idisk['partitions'] as $pkey=>$part){
751           if(!isset($this->disks[$idisk['cn']]['partitions'][$pkey])){
752             $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
753             $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
754           }
755         }
756       }
757     }
758   }
759   
761   function PrepareForCopyPaste($source)
762   {
763     plugin::PrepareForCopyPaste($source);
765     /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
766      */
768     /* To be sure to copy disks and partitions correctly, just create a 
769      *  new PartitionTable object and use the 'disks' attribute 
770      *  from this it. This is much easier and less code.
771      */
772     $obj = new faiPartitionTable($this->config, $source['dn']);
773     $this->disks = $obj->disks;
774   }
777   /* Return plugin informations for acl handling */ 
778   static function plInfo()
779   {
780     return (array( 
781           "plShortName" => _("Partition table"),
782           "plDescription" => _("FAI partition table"),
783           "plSelfModify"  => FALSE,
784           "plDepends"     => array(),
785           "plPriority"    => 26,
786           "plSection"     => array("administration"),
787           "plCategory"    => array("fai"),
788           "plProperties" =>
789           array(
790               array(
791                   "name"          => "faiPartitionRDN",
792                   "type"          => "rdn",
793                   "default"       => "ou=disk,",
794                   "description"   => "The 'faiPartitionRDN' statement defines the location where new fai-partitions will be created. The default is 'ou=disk,'.",
795                   "check"         => "gosaProperty::isRdn",
796                   "migrate"       => "",
797                   "group"         => "plugin",
798                   "mandatory"     => FALSE)),
800           "plProvidedAcls" => array(
801             "cn"                => _("Name")."&nbsp;("._("Read only").")",
802             "description"       => _("Description"))
803           ));
804   }
807   /*! \brief  Used for copy & paste.
808     Returns a HTML input mask, which allows to change the cn of this entry.
809     @param  Array   Array containing current status && a HTML template.
810    */
811   function getCopyDialog()
812   {
813     $vars = array("cn");
814     $smarty = get_smarty();
815     $smarty->assign("cn", htmlentities($this->cn));
816     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
817     $ret = array();
818     $ret['string'] = $str;
819     $ret['status'] = "";
820     return($ret);
821   }
824   /*! \brief  Used for copy & paste.
825     Some entries must be renamed to avaoid duplicate entries.
826    */
827   function saveCopyDialog()
828   {
829     if(isset($_POST['cn'])){
830       $this->cn = get_post('cn');
831     }
832   }
834   /* Reload some attributes */
835   function get_object_attributes($object,$attributes)
836   {
837     $ldap = $this->config->get_ldap_link();
838     $ldap->cd($this->config->current['BASE']);
839     $ldap->cat($object['dn'],$attributes);
840     $tmp  = $ldap->fetch();
842     foreach($attributes as $attrs){
843       if(isset($tmp[$attrs][0])){
844         $var = $tmp[$attrs][0];
846         /* Check if we must decode some attributes */
847         if(in_array_ics($attrs,$this->sub64coded)){
848           $var = base64_decode($var);
849         }
851         /*  check if this is a binary entry */
852         if(in_array_ics($attrs,$this->subBinary)){
853           $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
854         }
856         /* Fix slashes */
857         $var = addslashes($var);
858         $object[$attrs] = $var;
859       }
860     }
861     return($object);
862   }
866 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
867 ?>