Code

Updated mime-types
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_mimetypeGeneric.inc
1 <?php
2 class mimetype extends plugin
3 {
4         var $ignore_account     = true; // This is always a valid account
5         var $objectclasses              = array("top","gotoMimeType");
6         var $attributes                   = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon",
7                                                                         "description","gotoMimeFilePattern","gotoMimeEmbeddedApplication",
8                                                                         "gotoMimeGroup");       
10         /* Class vars */
11         var $ui;
12         var $cn                                                                               = "";                                     
13         var $gotoMimeLeftClickAction                        = "I";
14         var $gotoMimeLeftClickAction_I              = true;
15         var $gotoMimeLeftClickAction_E              = false;
16         var $gotoMimeLeftClickAction_Q              = false;
17         var $gotoMimeIcon                                                         = "*removed*";
18         var $description                                                          = "";
19         var $gotoMimeFilePattern                                      = array();
20         var $gotoMimeApplication                                      = array();
21         var $gotoMimeEmbeddedApplication            = array();
22         var $gotoMimeGroup                                                      = "";
23         var $iconData                                                               = NULL;     
24         var $base                                                                             = "";
25   var $ApplicationList                  = array();  
28   /* To prevent errors when using the 'apply' button, we use this variables 
29       to manage array attributes */
30         var $use_gotoMimeIcon                                           = NULL;
31         var $use_gotoMimeFilePattern                        = array();
32         var $use_gotoMimeApplication                        = array();
33         var $use_gotoMimeEmbeddedApplication    = array();
35   /* divLists */
36   var $DivPatterns                                                        = NULL;
37   var $DivApps                                                              = NULL;
38   var $DivEApps                                                             = NULL;
40   var $FAIstate ="";
42   /* These vars will be copied too, if you use copy&paste mode */
43   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
44                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
46   var $view_logged  = FALSE;
48   /* Select options */
49   var $MimeGroups                             = array("application","audio","chemical","image","inode","message","model",
50                                       "multipart","text","video","x-conference","x-world");
52   /* Orig_Dn is used to verify if this object is new or only edited */          
53   var $orig_dn                  = "";
54   var $orig_base          = "";
56   function mimetype(&$config,$dn= NULL)
57   {
58     plugin::plugin ($config, $dn);
60     /* Save original dn */
61     $this->orig_dn = $dn;       
63     /* get gotoMimeLeftClickActions I/E/Q */
64     if(isset($this->gotoMimeLeftClickAction)){
65       $str = $this->gotoMimeLeftClickAction;
66       for($i = 0 ; $i < strlen($str) ; $i ++ ){
67         $varna = "gotoMimeLeftClickAction_". $str[$i];
68         if(isset($this->$varna)){
69           $this->$varna = true;
70         }
71       }
72     }
74     /* Create list of defined applications in GOsa */
75     $ldap = $this->config->get_ldap_link();
76     $ldap->cd($this->config->current['BASE']);
77     $ldap->search("(&(objectClass=gosaApplication)(cn=*))",array('cn'));
78     $this->ApplicationList = array();
79     while($attrs = $ldap->fetch()){
80       $this->ApplicationList[$attrs['cn'][0]] = $attrs['cn'][0];
81     }
83     /* If both radio buttons arn't set, set option I */
84     if(!$this->gotoMimeLeftClickAction_I && !$this->gotoMimeLeftClickAction_E){
85       $this->gotoMimeLeftClickAction_I = true;
86     }
88     /* Get list of array attributes */
89     foreach(array("gotoMimeFilePattern") as $attr){
90       $this->$attr = array();
91       if(isset($this->attrs[$attr])){
92         $tmp = array();
93         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
94           $str = $this->attrs[$attr][$i];
95           $tmp[] = $str;
96         }
97         $use_attr = "use_".$attr;
98         $this->$use_attr = $tmp;
99       }
100     }
102     /* Get list of array attributes with priority tag ( Test|32 )*/
103     foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){
104       $this->$attr = array();
105       if(isset($this->attrs[$attr])){
106         $tmp = array();
107         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
108           $str = $this->attrs[$attr][$i];
109           $tmp2= explode("|",$str);
111           if(count($tmp2) == 2){
112             $name = $tmp2[0];
113             $prio = $tmp2[1];
114             $tmp[$prio] = $name;
115           }
116         }
117         ksort($tmp);
118         $use_attr = "use_".$attr;
119         $this->$use_attr = $tmp;
120       }
121     }
123     /* Set base */      
124     if ($this->dn == "new"){
125       if(session::is_set('CurrentMainBase')){
126         $this->base= session::get('CurrentMainBase');
127       }else{
128         $ui= get_userinfo();
129         $this->base= dn2base($ui->dn);
130       }
131     } else {
132       $this->base= preg_replace ("/^.*,".preg_quote(get_ou("mimetypeRDN"), '/')."/i", "", $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::set('binary',$this->iconData);
145     session::set('binarytype',"image/jpeg");
146     $this->orig_base = $this->base;
147   }
150   function execute()
151   {
152     $smarty = get_smarty();
154     if(!$this->view_logged){
155       $this->view_logged =TRUE;
156       new log("view","mimetypes/".get_class($this),$this->dn);
157     }
159     $tmp = $this->plInfo();
160     foreach($tmp['plProvidedAcls'] as $name => $translation){
161       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
162     }
163     $smarty->assign("IconReadable", preg_match("/r/",$this->getacl("gotoMimeIcon",preg_match("/freeze/i",$this->FAIstate))));
165     /* Check Posts */
166     $posts = array(     
167         "/^Pattern_SortUp_/"    => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
168         "/^Pattern_SortDown_/"  => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
169         "/^Pattern_Remove_/"    => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
170         "/^Apps_SortUp_/"               => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
171         "/^Apps_SortDown_/"     => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
172         "/^Apps_Remove_/"               => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
173         "/^EApps_SortUp_/"              => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
174         "/^EApps_SortDown_/"    => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
175         "/^EApps_Remove_/"              => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
176     $once = true;
178     /* Walk through posts and try to find some commands for us. */
179     if(!preg_match("/freeze/i",$this->FAIstate)){
180       foreach($_POST as $name => $value){
182         /* Walk through possible commands */
183         foreach($posts as $regex => $action){
185           /* Check if there is a command posted */
186           if(preg_match($regex,$name) && $once){
187             $once = false;
189             /* Get action vars */
190             $func               = $action['Func'];              // Get function name 
191             $attr               = $action['Attr'];              // Get attribute name
192             $acl_a              = preg_replace("/^use_/","",$action['Attr']);           // Get attribute name
194             /* Get entry id */
195             $s_entry    = preg_replace($regex,"",$name);
196             $s_entry    = preg_replace("/_[xy]$/","",$s_entry); 
198             /* Execute a command with the given attribute and entry 
199                e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
200             if($this->acl_is_writeable($acl_a)){
201               $this->$attr= $this->$func($s_entry,$this->$attr,true);                                    
202             }
203           }
204         }
205       }
207       /* Set a new icon was requested */
208       if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
209         $this->set_new_picture($_FILES['picture_file']['tmp_name']);            
210       }
212       /* Add gotoMimeFilePattern */
213       if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
214         if($this->acl_is_writeable("gotoMimeFilePattern")){
215           $str = trim($_POST['NewFilePattern']);
216           if($str != ""){
217             $this->use_gotoMimeFilePattern[] = $str;
218           }
219         }
220       } 
222       /* Add gotoMimeFilePattern */
223       if(isset($_POST['AddNewApplication']) && 
224           (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
225         if($this->acl_is_writeable("gotoMimeApplication")){
226           $str = "";
227           if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
228             $str = trim(get_post("NewApplicationSelect"));
229           }
230           if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
231             $str = trim(get_post("NewApplication"));
232           }
233           if($str != "" && !in_array($str,$this->use_gotoMimeApplication)){
234             $this->use_gotoMimeApplication[] = $str;
235           }
236         }
237       } 
239       /* Add embedded application 
240        *  - From input or from select box 
241        */
242       if(isset($_POST['AddNewEmbeddedApplication']) && 
243           (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
244         if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
245           $str = "";
246           if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
247             $str = trim(get_post('NewEmbeddedApplicationSelect'));
248           }
249           if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
250             $str = trim(get_post('NewEmbeddedApplication'));
251           }
252           if($str != "" && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
253             $this->use_gotoMimeEmbeddedApplication[] = $str;
254           }
255         }
256       } 
257     }   
259     /* Create divlists */
260     $DivPatterns        = new divSelectBox("gotoMimePatterns");
261     $DivApps            = new divSelectBox("gotoMimeApplications");
262     $DivEApps           = new divSelectBox("gotoMimeEmbeddedApplications");
263     $DivPatterns        -> SetHeight(100);
264     $DivApps            -> SetHeight(100);
265     $DivEApps           -> SetHeight(100);
268     if($this->acl_is_writeable("gotoMimeFilePattern") && !preg_match("/freeze/i",$this->FAIstate)){
269       $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'    class='center'  name='Pattern_SortUp_%s' >&nbsp;
270       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Pattern_SortDown_%s'>&nbsp;
271       <input type='image' src='images/lists/trash.png'  class='center'  name='Pattern_Remove_%s'>";
272     }else{
273       $Pattern_Actions= "";     
274     }
276     if($this->acl_is_writeable("gotoMimeApplication") && !preg_match("/freeze/i",$this->FAIstate)){
277       $Apps_Actions     = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
278       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Apps_SortDown_%s'>&nbsp;
279       <input type='image' src='images/lists/trash.png'  class='center'  name='Apps_Remove_%s'>";
280     }else{
281       $Apps_Actions= "";        
282     }
284     if($this->acl_is_writeable("gotoMimeEmbeddedApplication") && !preg_match("/freeze/i",$this->FAIstate)){
285       $EApps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
286       <input type='image' src='images/lists/sort-down.png'      class='center'  name='EApps_SortDown_%s'>&nbsp;
287       <input type='image' src='images/lists/trash.png'  class='center'  name='EApps_Remove_%s'>";
288     }else{
289       $EApps_Actions= "";       
290     }
292     /* Before adding some entries check acls */
293     if($this->acl_is_readable("gotoMimeFilePattern")){
294       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
295         $field1 = array("string" => $pattern);
296         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
297         $fields = array($field1,$field2);
298         $DivPatterns -> AddEntry($fields);
299       }                 
300     }
302     if($this->acl_is_readable("gotoMimeApplication")){
303       foreach($this->use_gotoMimeApplication as $key => $pattern){
304         $field1 = array("string" => $pattern);
305         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
306         $fields = array($field1,$field2);
307         $DivApps -> AddEntry($fields);
308       }                 
309     }                   
310     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
311       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
312         $field1 = array("string" => $pattern);
313         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
314         $fields = array($field1,$field2);
315         $DivEApps -> AddEntry($fields);
316       }
317     }                   
318     $smarty->assign("bases",                                            $this->get_allowed_bases());            
319     $smarty->assign("base_select",                                      $this->base);           
320     $smarty->assign("isReleaseMimeType",                        $this->is_release());
321     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
322     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
323     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
325     $smarty->assign("ApplicationList",$this->ApplicationList);
326   
327     /* Assign class vars to smarty */
328     foreach($this->attributes as $attr){
329       $smarty->assign($attr,$this->$attr);
330     }   
332     /* Assign additional vars that are not included in attributes*/
333     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
334       $smarty->assign($attr,$this->$attr);
335     }   
337     /* Assign select box options */
338     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
339     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
340     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
341   }
344   function save_object()
345   {
346     if(isset($_POST['MimeGeneric']) && !preg_match("/freeze/i",$this->FAIstate)){
348       /* Create a base backup and reset the
349          base directly after calling plugin::save_object();
350          Base will be set seperatly a few lines below */
351       $base_tmp = $this->base;
352       plugin::save_object();
353       $this->base = $base_tmp;
354   
355       /* Only save base if we are not in release mode */
356       if(!$this->is_release()){
358         /* Set new base if allowed */
359         $tmp = $this->get_allowed_bases();
360         if(isset($_POST['base'])){
361           if(isset($tmp[$_POST['base']])){
362             $this->base= $_POST['base'];
363           }
364         }
366       }
368       /* Save radio buttons */
369       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
370         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
371           $chr = $_POST['gotoMimeLeftClickAction_IE'];
372           if($chr == "E"){
373             $this->gotoMimeLeftClickAction_E = true;
374             $this->gotoMimeLeftClickAction_I = false;
375           }else{
376             $this->gotoMimeLeftClickAction_E = false;
377             $this->gotoMimeLeftClickAction_I = true;
378           }
379         }
380         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
381           $this->gotoMimeLeftClickAction_Q = true;
382         }else{
383           $this->gotoMimeLeftClickAction_Q = false;
384         }
385       }
386     }
387   }
390   /* save current changes */
391   function save()
392   {
393     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
394     $arr = array ("E","I","Q");
395     $str = "";
396     foreach ($arr as $Chr){
397       $var = "gotoMimeLeftClickAction_".$Chr;
398       if($this->$var){
399         $str .= $Chr;
400       }
401     }
402     $this->gotoMimeLeftClickAction = $str;
404     /* Create array entries with priority tag ( Test|3 )*/
405     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
406       $i                                = 0;
407       $use_attr                 = "use_".$attr;
408       $tmp                      = array();
409       $this->$attr      = array();
410       foreach($this->$use_attr as $entry){
411         $tmp[] = $entry."|".$i ++;
412       }
413       $this->$attr = $tmp;
414     }
416     /* Create array entries */
417     foreach(array("gotoMimeFilePattern") as $attr){
418       $i                                = 0;
419       $use_attr                 = "use_".$attr;
420       $tmp                      = array();
421       $this->$attr      = array();
422       foreach($this->$use_attr as $entry){
423         $tmp[] = $entry;
424       }
425       $this->$attr = $tmp;
426     }
428     /* Remove Icon if requested  */
429     if($this->use_gotoMimeIcon != "*removed*"){
430       $this->gotoMimeIcon = $this->iconData;
431     }else{
432       $this->gotoMimeIcon = "";
433     }
435     plugin::save();
437     /* If this is a newly created object, skip storing those 
438        attributes that contain an empty array */
439     if($this->orig_dn == "new"){
440       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
441         if(!count($this->$attr)){
442           unset($this->attrs[$attr]);
443         }
444       }
445     }
447     $ldap = $this->config->get_ldap_link();
448     $ldap-> cd ( $this->config->current['BASE']);
449     $ldap->cat($this->dn);
450     if($ldap->count()){
451       $ldap->cd($this->dn);
452       $this->cleanup();
453       $ldap->modify($this->attrs);
454       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
455     }else{
456       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
457       $ldap->cd($this->dn);
458       $ldap->add($this->attrs);
459       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
460     }
461     if (!$ldap->success()){
462       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
463     }
464   }
467   /* Remove current mime type */
468   function remove_from_parent()
469   {
470     plugin::remove_from_parent();
471     $ldap = $this->config->get_ldap_link();
472     $ldap->rmDir($this->dn);
473     if (!$ldap->success()){
474       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
475     }
476     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
478     /* Optionally execute a command after we're done */
479     $this->handle_post_events("remove");
481     /* Delete references to object groups */
482     $ldap->cd ($this->config->current['BASE']);
483     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
484     while ($ldap->fetch()){
485       $og= new ogroup($this->config, $ldap->getDN());
486       unset($og->member[$this->dn]);
487       $og->save ();
488       if (!$ldap->success()){
489         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
490       }
491     }
492   }
495   /* Check given values */
496   function check()
497   {
498     $message = plugin::check();
499     if($this->cn == "" ){
500       $message[] = msgPool::required(_("Name"));
501     }
502     if(!count($this->use_gotoMimeFilePattern)){
503       $message[] = msgPool::required(_("File pattern"));
504     }
506     /* Check if there is already a mime type with this cn */
507     $ldap = $this->config->get_ldap_link();
508     $ldap->cd($this->config->current["BASE"]);
510     if($this->is_release()){
511       $base = $this->parent->parent->mime_release;
512     }else{
513       $base = get_ou("mimetypeRDN").$this->base;
514     }
516     $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
517     if($ldap->count()){
518       $attrs = $ldap->fetch();
519       if($this->dn != $attrs['dn']) {
520         $message[]= msgPool::duplicated("cn");
521       }
522     }
524     /* Check if we are allowed to create or move this object
525      */
526     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
527       $message[] = msgPool::permCreate();
528     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
529       $message[] = msgPool::permMove();
530     }
532     return($message);
533   }
536   /** Helper functions **/
538   /* Set a new picture */       
539   function set_new_picture($filename)
540   {
541     if (empty($filename)){
542       $filename= "./plugins/goto/images/default_icon.png";
543       $this->use_gotoMimeIcon= "*removed*";
544     }else{
545       $this->use_gotoMimeIcon= $filename;
546     }
548     if (file_exists($filename)){
549       $fd = fopen ($filename, "rb");
550       $this->iconData= fread ($fd, filesize ($filename));
551       session::set('binary',$this->iconData);
552       session::set('binarytype',"image/jpeg");
553       fclose ($fd);
554     }
555   }
557   /* Get picture link */
558   function get_picture()
559   {
560     session::set('binary',$this->iconData);
561     session::set('binarytype',"image/jpeg");
562     return("getbin.php");
563   }
565   /* Transports the given Arraykey one position up*/
566   function ArrayUp($atr,$attrs)
567   {
568     $ret = $attrs;
569     $pos = $this->getpos($atr,$attrs) ;
570     $cn = count($attrs);
571     if(!(($pos == -1)||($pos == 1))){
572       $before = array_slice($attrs,0,($pos-2));
573       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
574       $unten  = array_slice($attrs,$pos);
575       $ret = array();
576       $ret = $this->combineArrays($before,$mitte,$unten);
577     }
578     return($ret);
579   }
582   /* Transports the given Arraykey one position down*/
583   function ArrayDown($atr,$attrs)
584   {
585     $ret = $attrs;
586     $pos = $this->getpos($atr,$attrs) ;
587     $cn = count($attrs);
588     if(!(($pos == -1)||($pos == $cn))){
589       $before = array_slice($attrs,0,($pos-1));
590       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
591       $unten  = array_slice($attrs,($pos+1));
592       $ret = array();
593       $ret = $this->combineArrays($before,$mitte,$unten);
594     }
595     return($ret);
596   }
599   /* return the position of the element in the array */
600   function getpos($atr,$attrs)
601   {
602     $i = 0;
603     foreach($attrs as $attr => $name)    {
604       $i++;
605       if($attr == $atr){
606         return($i);
607       }
608     }
609     return(-1);
610   }
613   /* Remove this element from array */
614   function ArrayRemove($key,$array,$reorder = false)    
615   {
616     if(isset($array[$key])){
617       unset($array[$key]);
618       if($reorder){
619         $tmp = array();
620         foreach($array as $entry){
621           $tmp[] = $entry;
622         }
623         $array = $tmp;
624       }
625     }   
626     return($array);
627   }
630   /* Combine new array */
631   function combineArrays($ar0,$ar1,$ar2)
632   {
633     $ret = array();
634     if(is_array($ar0))
635       foreach($ar0 as $ar => $a){
636         $ret[]=$a;
637       }
638     if(is_array($ar1))
639       foreach($ar1 as $ar => $a){
640         $ret[]=$a;
641       }
642     if(is_array($ar2))
643       foreach($ar2 as $ar => $a){
644         $ret[]=$a;
645       }
646     return($ret);
647   }
650   /* Return a dialog with all fields that must be changed, 
651      if we want to copy this entry */
652   function getCopyDialog()
653   {
654     $str = "";
656     $smarty = get_smarty();
657     $smarty->assign("cn",               $this->cn);
658     $smarty->assign("description",  $this->description);
659     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
661     $ret = array();
662     $ret['string'] = $str;
663     $ret['status'] = "";
664     return($ret);
665   }
668   /* Save all */
669   function saveCopyDialog()
670   {
671     $attrs = array("cn","description");
672     foreach($attrs as $attr){
673       if(isset($_POST[$attr])){
674         $this->$attr = $_POST[$attr];
675       }
676     }
677   }
679   /* Return plugin informations for acl handling  */ 
680   static function plInfo()
681   {
682     return (array(
683           "plShortName"   => _("Generic"),
684           "plDescription" => _("Mime type generic"),
685           "plSelfModify"  => FALSE,
686           "plDepends"     => array(),
687           "plPriority"    => 0,
688           "plSection"     => array("administration"),
689           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
690                                                         "objectClass"  => "gotoMimeType")),
691           "plProvidedAcls"=> array(
692             "cn"                          => _("Name"),
693             "gotoMimeGroup"               => _("Mime group"),
694             "description"                 => _("Description"),
695             "base"                        => _("Base"),
696             "gotoMimeApplication"         => _("Application"),
697             "gotoMimeLeftClickAction"     => _("Left click action"),
698             "gotoMimeIcon"                => _("Icon"),
699             "gotoMimeFilePattern"         => _("File patterns"),
700             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
701           ));
703   }
706   function is_release()
707   {
708     if(is_object($this->parent->parent)){
709       return($this->parent->parent->IsReleaseManagementActivated());
710     }else{
711       /* Check if we should enable the release selection */
712       $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
713       if(!empty($tmp)){
714         return(true);
715       }
716     }
717     return(FALSE);
718   }
721   function PrepareForCopyPaste($source)
722   {
723     plugin::PrepareForCopyPaste($source);
725     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
727     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
728       $use_attr     = "use_".$name;
729       if(isset($this->$use_attr)){
730         $this->$use_attr= $source_o->$use_attr;
731       }
732       $this->$name = $source_o->$name;
733     } 
734     foreach($this->attributes as $name){
735       $this->$name = $source_o->$name;
736     }
738     if($this->iconData){
739       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
740     }
741   }
743 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
744 ?>