Code

e7585c90b44a1c5551795b8774f10673367c4637
[gosa.git] / plugins / admin / mimetypes / class_mimetypeGeneric.inc
1 <?php
2 class mimetype extends plugin
3 {
4         /* CLI vars */
5         var $cli_summary                  = "This tab allows you to modify, add or remove mime types in the selected department.";
6         var $cli_description    = "Management dialog to handle mime types";
7         var $ignore_account     = true; // This is always a valid account
8         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9         var $objectclasses              = array("top","gotoMimeType");
10         var $attributes                   = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon",
11                                                                         "description","gotoMimeFilePattern","gotoMimeEmbeddedApplication",
12                                                                         "gotoMimeGroup");       
14         /* Class vars */
15         var $ui;
16         var $cn                                                                               = "";                                     
17         var $gotoMimeLeftClickAction                        = "I";
18         var $gotoMimeLeftClickAction_I              = true;
19         var $gotoMimeLeftClickAction_E              = false;
20         var $gotoMimeLeftClickAction_Q              = false;
21         var $gotoMimeIcon                                                         = "*removed*";
22         var $description                                                          = "";
23         var $gotoMimeFilePattern                                      = array();
24         var $gotoMimeApplication                                      = array();
25         var $gotoMimeEmbeddedApplication            = array();
26         var $gotoMimeGroup                                                      = "";
27         var $iconData                                                               = NULL;     
28         var $base                                                                             = "";
30   /* To prevent errors when using the 'apply' button, we use this variables 
31       to manage array attributes */
32         var $use_gotoMimeIcon                                           = NULL;
33         var $use_gotoMimeFilePattern                        = array();
34         var $use_gotoMimeApplication                        = array();
35         var $use_gotoMimeEmbeddedApplication    = array();
37   /* divLists */
38   var $DivPatterns                                                        = NULL;
39   var $DivApps                                                              = NULL;
40   var $DivEApps                                                             = NULL;
42   /* Mime type release mode */
43   var $isReleaseMimeType                                              = false;
44   var $dialog                                                                       = NULL;
46   /* These vars will be copied too, if you use copy&paste mode */
47   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
48                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
50   var $view_logged  = FALSE;
52   /* Select options */
53   var $MimeGroups                             = array("application","audio","chemical","image","inode","message","model",
54                                       "multipart","text","video","x-conference","x-world");
56   /* Orig_Dn is used to verify if this object is new or only edited */          
57   var $orig_dn                  = "";
59   function mimetype($config,$dn= NULL)
60   {
61     plugin::plugin ($config, $dn);
63     /* Save original dn */
64     $this->orig_dn = $dn;       
66     /* get gotoMimeLeftClickActions I/E/Q */
67     if(isset($this->gotoMimeLeftClickAction)){
68       $str = $this->gotoMimeLeftClickAction;
69       for($i = 0 ; $i < strlen($str) ; $i ++ ){
70         $varna = "gotoMimeLeftClickAction_". $str[$i];
71         if(isset($this->$varna)){
72           $this->$varna = true;
73         }
74       }
75     }
77     /* If both radio buttons arn't set, set option I */
78     if(!$this->gotoMimeLeftClickAction_I && !$this->gotoMimeLeftClickAction_E){
79       $this->gotoMimeLeftClickAction_I = true;
80     }
82     /* Get list of array attributes */
83     foreach(array("gotoMimeFilePattern") as $attr){
84       $this->$attr = array();
85       if(isset($this->attrs[$attr])){
86         $tmp = array();
87         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
88           $str = $this->attrs[$attr][$i];
89           $tmp[] = $str;
90         }
91         $use_attr = "use_".$attr;
92         $this->$use_attr = $tmp;
93       }
94     }
96     /* Get list of array attributes with priority tag ( Test|32 )*/
97     foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){
98       $this->$attr = array();
99       if(isset($this->attrs[$attr])){
100         $tmp = array();
101         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
102           $str = $this->attrs[$attr][$i];
103           $tmp2= split("\|",$str);
105           if(count($tmp2) == 2){
106             $name = $tmp2[0];
107             $prio = $tmp2[1];
108             $tmp[$prio] = $name;
109           }
110         }
111         ksort($tmp);
112         $use_attr = "use_".$attr;
113         $this->$use_attr = $tmp;
114       }
115     }
117     /* Check if release Management is enabled */
118     $tmp = search_config($this->config->data,"faiManagement","CLASS");
119     if(!empty($tmp)) {
120       $this->isReleaseMimeType= true;
121     }
123     /* Set base */      
124     if ($this->dn == "new"){
125       if(isset($_SESSION['CurrentMainBase'])){
126         $this->base= $_SESSION['CurrentMainBase'];
127       }else{
128         $ui= get_userinfo();
129         $this->base= dn2base($ui->dn);
130       }
131     } else {
132       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
133     }
135     /* Get icon data */
136     if(isset($this->attrs['gotoMimeIcon'])){
137       $ldap = $this->config->get_ldap_link();
138       $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon");
139       $this->saved_attributes['gotoMimeIcon'] = $this->iconData;
140     }
141     if ($this->iconData == ""){
142       $this->set_new_picture("");
143     }
144     $_SESSION['binary']                 = $this->iconData;
145     $_SESSION['binarytype']             = "image/jpeg";
146   }
149   function execute()
150   {
151     $smarty = get_smarty();
153     if(!$this->view_logged){
154       $this->view_logged =TRUE;
155       new log("view","mimetypes/".get_class($this),$this->dn);
156     }
158     $tmp = $this->plInfo();
159     foreach($tmp['plProvidedAcls'] as $name => $translation){
160       $smarty->assign($name."ACL",$this->getacl($name));
161     }
163     /* Base select dialog */
164     $once = true;
165     foreach($_POST as $name => $value){
166       if(preg_match("/^chooseBase/",$name) && $once){
167         $once = false;
168         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
169         $this->dialog->setCurrentBase($this->base);
170       }
171     }
173     /* Dialog handling */
174     if(is_object($this->dialog)){
176       /* Must be called before save_object */
177       $this->dialog->save_object();
179       if($this->dialog->isClosed()){
180         $this->dialog = false;
181       }elseif($this->dialog->isSelected()){
183         /* A new base was selected, check if it is a valid one */
184         $tmp = $this->get_allowed_bases();
185         if(isset($tmp[$this->dialog->isSelected()])){
186           $this->base = $this->dialog->isSelected();
187         }
189         $this->dialog= false;
190       }else{
191         return($this->dialog->execute());
192       }
193     }
195     /* Check Posts */
196     $posts = array(     
197         "/^Pattern_SortUp_/"    => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
198         "/^Pattern_SortDown_/"  => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
199         "/^Pattern_Remove_/"    => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
200         "/^Apps_SortUp_/"               => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
201         "/^Apps_SortDown_/"     => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
202         "/^Apps_Remove_/"               => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
203         "/^EApps_SortUp_/"              => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
204         "/^EApps_SortDown_/"    => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
205         "/^EApps_Remove_/"              => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
206     $once = true;
208     /* Walk through posts and try to find some commands for us. */
209     foreach($_POST as $name => $value){
211       /* Walk through possible commands */
212       foreach($posts as $regex => $action){
214         /* Check if there is a command posted */
215         if(preg_match($regex,$name) && $once){
216           $once = false;
218           /* Get action vars */
219           $func                 = $action['Func'];              // Get function name 
220           $attr                 = $action['Attr'];              // Get attribute name
222           /* Get entry id */
223           $s_entry      = preg_replace($regex,"",$name);
224           $s_entry      = preg_replace("/_[xy]$/","",$s_entry); 
226           /* Execute a command with the given attribute and entry 
227              e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
228           if($this->acl_is_writeable($attr)){
229             $this->$attr= $this->$func($s_entry,$this->$attr,true);                                      
230           }
231         }
232       }
233     }
235     /* Set a new icon was requested */
236     if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
237       $this->set_new_picture($_FILES['picture_file']['tmp_name']);              
238     }
240     /* Add gotoMimeFilePattern */
241     if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
242       if($this->acl_is_writeable("gotoMimeFilePattern")){
243         $str = $_POST['NewFilePattern'];
244         if(!empty($str)){
245           $this->use_gotoMimeFilePattern[] = $str;
246         }
247       }
248     }   
250     /* Add gotoMimeFilePattern */
251     if(isset($_POST['AddNewApplication']) && isset($_POST['NewApplication'])){
252       if($this->acl_is_writeable("gotoMimeApplication")){
253         $str = $_POST['NewApplication'];
254         if(!empty($str)){
255           $this->use_gotoMimeApplication[] = $str;
256         }
257       }
258     }   
260     /* Add gotoMimeFilePattern */
261     if(isset($_POST['AddNewEmbeddedApplication']) && isset($_POST['NewEmbeddedApplication'])){
262       if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
263         $str = $_POST['NewEmbeddedApplication'];
264         if(!empty($str)){
265           $this->use_gotoMimeEmbeddedApplication[] = $str;
266         }
267       }
268     }   
270     /* Create divlists */
271     $DivPatterns        = new DivSelectBox("gotoMimePatterns");
272     $DivApps            = new DivSelectBox("gotoMimeApplications");
273     $DivEApps           = new DivSelectBox("gotoMimeEmbeddedApplications");
274     $DivPatterns        -> SetHeight(100);
275     $DivApps            -> SetHeight(100);
276     $DivEApps           -> SetHeight(100);
279     if($this->acl_is_writeable("gotoMimeFilePattern")){
280       $Pattern_Actions= " <input type='image' src='images/sort_up.png'  class='center'  name='Pattern_SortUp_%s' >&nbsp;
281       <input type='image' src='images/sort_down.png'    class='center'  name='Pattern_SortDown_%s'>&nbsp;
282       <input type='image' src='images/edittrash.png'    class='center'  name='Pattern_Remove_%s'>";
283     }else{
284       $Pattern_Actions= "";     
285     }
287     if($this->acl_is_writeable("gotoMimeApplication")){
288       $Apps_Actions     = " <input type='image' src='images/sort_up.png'        class='center'  name='Apps_SortUp_%s' >&nbsp;
289       <input type='image' src='images/sort_down.png'    class='center'  name='Apps_SortDown_%s'>&nbsp;
290       <input type='image' src='images/edittrash.png'    class='center'  name='Apps_Remove_%s'>";
291     }else{
292       $Apps_Actions= "";        
293     }
295     if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
296       $EApps_Actions    = " <input type='image' src='images/sort_up.png'        class='center'  name='EApps_SortUp_%s' >&nbsp;
297       <input type='image' src='images/sort_down.png'    class='center'  name='EApps_SortDown_%s'>&nbsp;
298       <input type='image' src='images/edittrash.png'    class='center'  name='EApps_Remove_%s'>";
299     }else{
300       $EApps_Actions= "";       
301     }
303     /* Before adding some entries check acls */
304     if($this->acl_is_readable("gotoMimeFilePattern")){
305       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
306         $field1 = array("string" => $pattern);
307         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
308         $fields = array($field1,$field2);
309         $DivPatterns -> AddEntry($fields);
310       }                 
311     }
313     if($this->acl_is_readable("gotoMimeApplication")){
314       foreach($this->use_gotoMimeApplication as $key => $pattern){
315         $field1 = array("string" => $pattern);
316         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
317         $fields = array($field1,$field2);
318         $DivApps -> AddEntry($fields);
319       }                 
320     }                   
321     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
322       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
323         $field1 = array("string" => $pattern);
324         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
325         $fields = array($field1,$field2);
326         $DivEApps -> AddEntry($fields);
327       }
328     }                   
329     $smarty->assign("bases",                                            $this->get_allowed_bases());            
330     $smarty->assign("base_select",                                      $this->base);           
331     $smarty->assign("isReleaseMimeType",                        $this->isReleaseMimeType);
332     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
333     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
334     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
336     /* Assign class vars to smarty */
337     foreach($this->attributes as $attr){
338       $smarty->assign($attr,$this->$attr);
339     }   
341     /* Assign additional vars that are not included in attributes*/
342     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
343       $smarty->assign($attr,$this->$attr);
344     }   
346     /* Assign select box options */
347     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
348     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
349     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
350   }
353   function save_object()
354   {
355     if(isset($_POST['MimeGeneric'])){
357       /* Create a base backup and reset the
358          base directly after calling plugin::save_object();
359          Base will be set seperatly a few lines below */
360       $base_tmp = $this->base;
361       plugin::save_object();
362       $this->base = $base_tmp;
363   
364       /* Only save base if we are not in release mode */
365       if(!$this->isReleaseMimeType){
367         /* Set new base if allowed */
368         $tmp = $this->get_allowed_bases();
369         if(isset($_POST['base'])){
370           if(isset($tmp[$_POST['base']])){
371             $this->base= $_POST['base'];
372           }
373         }
375       }
377       /* Save radio buttons */
378       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
379         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
380           $chr = $_POST['gotoMimeLeftClickAction_IE'];
381           if($chr == "E"){
382             $this->gotoMimeLeftClickAction_E = true;
383             $this->gotoMimeLeftClickAction_I = false;
384           }else{
385             $this->gotoMimeLeftClickAction_E = false;
386             $this->gotoMimeLeftClickAction_I = true;
387           }
388         }
389         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
390           $this->gotoMimeLeftClickAction_Q = true;
391         }else{
392           $this->gotoMimeLeftClickAction_Q = false;
393         }
394       }
395     }
396   }
399   /* save current changes */
400   function save()
401   {
402     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
403     $arr = array ("E","I","Q");
404     $str = "";
405     foreach ($arr as $Chr){
406       $var = "gotoMimeLeftClickAction_".$Chr;
407       if($this->$var){
408         $str .= $Chr;
409       }
410     }
411     $this->gotoMimeLeftClickAction = $str;
413     /* Create array entries with priority tag ( Test|3 )*/
414     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
415       $i                                = 0;
416       $use_attr                 = "use_".$attr;
417       $tmp                      = array();
418       $this->$attr      = array();
419       foreach($this->$use_attr as $entry){
420         $tmp[] = $entry."|".$i ++;
421       }
422       $this->$attr = $tmp;
423     }
425     /* Create array entries */
426     foreach(array("gotoMimeFilePattern") as $attr){
427       $i                                = 0;
428       $use_attr                 = "use_".$attr;
429       $tmp                      = array();
430       $this->$attr      = array();
431       foreach($this->$use_attr as $entry){
432         $tmp[] = $entry;
433       }
434       $this->$attr = $tmp;
435     }
437     /* Remove Icon if requested  */
438     if($this->use_gotoMimeIcon != "*removed*"){
439       $this->gotoMimeIcon = $this->iconData;
440     }else{
441       $this->gotoMimeIcon = "";
442     }
444     plugin::save();
446     /* If this is a newly created object, skip storing those 
447        attributes that contain an empty array */
448     if($this->orig_dn == "new"){
449       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
450         if(!count($this->$attr)){
451           unset($this->attrs[$attr]);
452         }
453       }
454     }
456     $ldap = $this->config->get_ldap_link();
457     $ldap-> cd ( $this->config->current['BASE']);
458     $ldap->cat($this->dn);
459     if($ldap->count()){
460       $ldap->cd($this->dn);
461       $this->cleanup();
462       $ldap->modify($this->attrs);
463       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
464     }else{
465       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
466       $ldap->cd($this->dn);
467       $ldap->add($this->attrs);
468       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
469     }
470     show_ldap_error($ldap->get_error(), sprintf(_("Saving of mime type/generic with dn '%s' failed."),$this->dn));
471   }
474   /* Remove current mime type */
475   function remove_from_parent()
476   {
477     plugin::remove_from_parent();
478     $ldap = $this->config->get_ldap_link();
479     $ldap->rmDir($this->dn);
480     show_ldap_error($ldap->get_error(), sprintf(_("Removing of mime type/generic with dn '%s' failed."),$this->dn));
481     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
483     /* Optionally execute a command after we're done */
484     $this->handle_post_events("remove");
486     /* Delete references to object groups */
487     $ldap->cd ($this->config->current['BASE']);
488     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
489     while ($ldap->fetch()){
490       $og= new ogroup($this->config, $ldap->getDN());
491       unset($og->member[$this->dn]);
492       $og->save ();
493       show_ldap_error($ldap->get_error(), sprintf(_("Removing mime type from objectgroup '%s' failed"), $og->dn));
494     }
495   }
498   /* Check given values */
499   function check()
500   {
501     $message = plugin::check();
502     if(empty($this->cn)){
503       $message[] = _("Please specify a valid name for this mime type.");
504     }
505     if(!count($this->use_gotoMimeFilePattern)){
506       $message[] = _("Please specify at least one file pattern.") ;
507     }
509     /* Check if there is already a mime type with this cn */
510     $ldap = $this->config->get_ldap_link();
511     $ldap->cd($this->config->current["BASE"]);
512     if($this->isReleaseMimeType && (isset($_SESSION['mimefilter']['release']))){
513       $baseDn = str_replace($this->config->current['BASE'],$this->base,$_SESSION['mimefilter']['release']);
514       $baseDn = preg_replace("/ou=mime,.*/","ou=mime,".$this->base,$_SESSION['mimefilter']['release']);
515       $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$baseDn,array("cn"));
516       if($ldap->count()){
517         $attrs = $ldap->fetch();
518         if($this->dn != $attrs['dn']) {
519           $message[]= _("There's already a mime type with this 'Name'.");
520         }
521       }
522     }else{
523       $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))","ou=mime,".$this->base,array("cn"));
524       if ($ldap->count()){
525         $attrs = $ldap->fetch();
526         if($this->dn != $attrs['dn']) {
527           $message[]= _("There's already an mime with this 'Name'.");
528         }
529       }
530     }
532     return($message);
533   }
535   /** Helper functions **/
537   /* Set a new picture */       
538   function set_new_picture($filename)
539   {
540     if (empty($filename)){
541       $filename= "./images/default_icon.png";
542       $this->use_gotoMimeIcon= "*removed*";
543     }else{
544       $this->use_gotoMimeIcon= $filename;
545     }
547     if (file_exists($filename)){
548       $fd = fopen ($filename, "rb");
549       $this->iconData= fread ($fd, filesize ($filename));
550       $_SESSION['binary']= $this->iconData;
551       $_SESSION['binarytype']= "image/jpeg";
552       fclose ($fd);
553     }
554   }
556   /* Get picture link */
557   function get_picture()
558   {
559     $_SESSION['binary']= $this->iconData;
560     $_SESSION['binarytype']= "image/jpeg";
561     return("getbin.php");
562   }
564   /* Transports the given Arraykey one position up*/
565   function ArrayUp($atr,$attrs)
566   {
567     $ret = $attrs;
568     $pos = $this->getpos($atr,$attrs) ;
569     $cn = count($attrs);
570     if(!(($pos == -1)||($pos == 1))){
571       $before = array_slice($attrs,0,($pos-2));
572       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
573       $unten  = array_slice($attrs,$pos);
574       $ret = array();
575       $ret = $this->combineArrays($before,$mitte,$unten);
576     }
577     return($ret);
578   }
581   /* Transports the given Arraykey one position down*/
582   function ArrayDown($atr,$attrs)
583   {
584     $ret = $attrs;
585     $pos = $this->getpos($atr,$attrs) ;
586     $cn = count($attrs);
587     if(!(($pos == -1)||($pos == $cn))){
588       $before = array_slice($attrs,0,($pos-1));
589       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
590       $unten  = array_slice($attrs,($pos+1));
591       $ret = array();
592       $ret = $this->combineArrays($before,$mitte,$unten);
593     }
594     return($ret);
595   }
598   /* return the position of the element in the array */
599   function getpos($atr,$attrs)
600   {
601     $i = 0;
602     foreach($attrs as $attr => $name)    {
603       $i++;
604       if($attr == $atr){
605         return($i);
606       }
607     }
608     return(-1);
609   }
612   /* Remove this element from array */
613   function ArrayRemove($key,$array,$reorder = false)    
614   {
615     if(isset($array[$key])){
616       unset($array[$key]);
617       if($reorder){
618         $tmp = array();
619         foreach($array as $entry){
620           $tmp[] = $entry;
621         }
622         $array = $tmp;
623       }
624     }   
625     return($array);
626   }
629   /* Combine new array */
630   function combineArrays($ar0,$ar1,$ar2)
631   {
632     $ret = array();
633     if(is_array($ar0))
634       foreach($ar0 as $ar => $a){
635         $ret[]=$a;
636       }
637     if(is_array($ar1))
638       foreach($ar1 as $ar => $a){
639         $ret[]=$a;
640       }
641     if(is_array($ar2))
642       foreach($ar2 as $ar => $a){
643         $ret[]=$a;
644       }
645     return($ret);
646   }
649   /* Return a dialog with all fields that must be changed, 
650      if we want to copy this entry */
651   function getCopyDialog()
652   {
653     $str = "";
655     $smarty = get_smarty();
656     $smarty->assign("cn",               $this->cn);
657     $smarty->assign("description",  $this->description);
658     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
660     $ret = array();
661     $ret['string'] = $str;
662     $ret['status'] = "";
663     return($ret);
664   }
667   /* Save all */
668   function saveCopyDialog()
669   {
670     $attrs = array("cn","description");
671     foreach($attrs as $attr){
672       if(isset($_POST[$attr])){
673         $this->$attr = $_POST[$attr];
674       }
675     }
676   }
678   /* Return plugin informations for acl handling  */ 
679   function plInfo()
680   {
681     return (array(
682           "plShortName"   => _("Generic"),
683           "plDescription" => _("Mime type generic"),
684           "plSelfModify"  => FALSE,
685           "plDepends"     => array(),
686           "plPriority"    => 0,
687           "plSection"     => array("administration"),
688           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
689                                                         "objectClass"  => "gotoMimeType")),
690           "plProvidedAcls"=> array(
691             "cn"                          => _("Name"),
692             "gotoMimeGroup"               => _("Mime group"),
693             "description"                 => _("Description"),
694             "base"                        => _("Base"),
695             "gotoMimeApplication"         => _("Application"),
696             "gotoMimeLeftClickAction"     => _("Left click action"),
697             "gotoMimeIcon"                => _("Icon"),
698             "gotoMimeFilePattern"         => _("File patterns"),
699             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
700           ));
702   }
704   function PrepareForCopyPaste($source)
705   {
706     plugin::PrepareForCopyPaste($source);
708     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
710     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
711       $use_attr     = "use_".$name;
712       if(isset($this->$use_attr)){
713         $this->$use_attr= $source_o->$use_attr;
714       }
715       $this->$name = $source_o->$name;
716     } 
717     foreach($this->attributes as $name){
718       $this->$name = $source_o->$name;
719     }
721     if($this->iconData){
722       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
723     }
724   }
726 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
727 ?>