Code

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