Code

Mimetypes
[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= split("\|",$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 ("/^.*,".normalizePreg(get_ou("mimetypeou"))."/", "", $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     }
164     /* Base select dialog */
165     $once = true;
166     foreach($_POST as $name => $value){
167       if(preg_match("/^chooseBase/",$name) && $once && !preg_match("/freeze/i",$this->FAIstate)){
168         $once = false;
169         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
170         $this->dialog->setCurrentBase($this->base);
171       }
172     }
174     /* Dialog handling */
175     if(is_object($this->dialog)){
177       /* Must be called before save_object */
178       $this->dialog->save_object();
180       if($this->dialog->isClosed()){
181         $this->dialog = false;
182       }elseif($this->dialog->isSelected()){
184         /* A new base was selected, check if it is a valid one */
185         $tmp = $this->get_allowed_bases();
186         if(isset($tmp[$this->dialog->isSelected()])){
187           $this->base = $this->dialog->isSelected();
188         }
190         $this->dialog= false;
191       }else{
192         return($this->dialog->execute());
193       }
194     }
196     /* Check Posts */
197     $posts = array(     
198         "/^Pattern_SortUp_/"    => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
199         "/^Pattern_SortDown_/"  => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
200         "/^Pattern_Remove_/"    => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
201         "/^Apps_SortUp_/"               => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
202         "/^Apps_SortDown_/"     => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
203         "/^Apps_Remove_/"               => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
204         "/^EApps_SortUp_/"              => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
205         "/^EApps_SortDown_/"    => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
206         "/^EApps_Remove_/"              => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
207     $once = true;
209     /* Walk through posts and try to find some commands for us. */
210     if(!preg_match("/freeze/i",$this->FAIstate)){
211       foreach($_POST as $name => $value){
213         /* Walk through possible commands */
214         foreach($posts as $regex => $action){
216           /* Check if there is a command posted */
217           if(preg_match($regex,$name) && $once){
218             $once = false;
220             /* Get action vars */
221             $func               = $action['Func'];              // Get function name 
222             $attr               = $action['Attr'];              // Get attribute name
224             /* Get entry id */
225             $s_entry    = preg_replace($regex,"",$name);
226             $s_entry    = preg_replace("/_[xy]$/","",$s_entry); 
228             /* Execute a command with the given attribute and entry 
229                e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
230             if($this->acl_is_writeable($attr)){
231               $this->$attr= $this->$func($s_entry,$this->$attr,true);                                    
232             }
233           }
234         }
235       }
237       /* Set a new icon was requested */
238       if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
239         $this->set_new_picture($_FILES['picture_file']['tmp_name']);            
240       }
242       /* Add gotoMimeFilePattern */
243       if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
244         if($this->acl_is_writeable("gotoMimeFilePattern")){
245           $str = $_POST['NewFilePattern'];
246           if(!empty($str)){
247             $this->use_gotoMimeFilePattern[] = $str;
248           }
249         }
250       } 
252       /* Add gotoMimeFilePattern */
253       if(isset($_POST['AddNewApplication']) && 
254           (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
255         if($this->acl_is_writeable("gotoMimeApplication")){
256           $str = "";
257           if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
258             $str = get_post("NewApplicationSelect");
259           }
260           if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
261             $str = get_post("NewApplication");
262           }
263           if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
264             $this->use_gotoMimeApplication[] = $str;
265           }
266         }
267       } 
269       /* Add embedded application 
270        *  - From input or from select box 
271        */
272       if(isset($_POST['AddNewEmbeddedApplication']) && 
273           (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
274         if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
275           $str = "";
276           if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
277             $str = get_post('NewEmbeddedApplicationSelect');
278           }
279           if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
280             $str = get_post('NewEmbeddedApplication');
281           }
282           if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
283             $this->use_gotoMimeEmbeddedApplication[] = $str;
284           }
285         }
286       } 
287     }   
289     /* Create divlists */
290     $DivPatterns        = new divSelectBox("gotoMimePatterns");
291     $DivApps            = new divSelectBox("gotoMimeApplications");
292     $DivEApps           = new divSelectBox("gotoMimeEmbeddedApplications");
293     $DivPatterns        -> SetHeight(100);
294     $DivApps            -> SetHeight(100);
295     $DivEApps           -> SetHeight(100);
298     if($this->acl_is_writeable("gotoMimeFilePattern") && !preg_match("/freeze/i",$this->FAIstate)){
299       $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'    class='center'  name='Pattern_SortUp_%s' >&nbsp;
300       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Pattern_SortDown_%s'>&nbsp;
301       <input type='image' src='images/lists/trash.png'  class='center'  name='Pattern_Remove_%s'>";
302     }else{
303       $Pattern_Actions= "";     
304     }
306     if($this->acl_is_writeable("gotoMimeApplication") && !preg_match("/freeze/i",$this->FAIstate)){
307       $Apps_Actions     = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
308       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Apps_SortDown_%s'>&nbsp;
309       <input type='image' src='images/lists/trash.png'  class='center'  name='Apps_Remove_%s'>";
310     }else{
311       $Apps_Actions= "";        
312     }
314     if($this->acl_is_writeable("gotoMimeEmbeddedApplication") && !preg_match("/freeze/i",$this->FAIstate)){
315       $EApps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
316       <input type='image' src='images/lists/sort-down.png'      class='center'  name='EApps_SortDown_%s'>&nbsp;
317       <input type='image' src='images/lists/trash.png'  class='center'  name='EApps_Remove_%s'>";
318     }else{
319       $EApps_Actions= "";       
320     }
322     /* Before adding some entries check acls */
323     if($this->acl_is_readable("gotoMimeFilePattern")){
324       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
325         $field1 = array("string" => $pattern);
326         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
327         $fields = array($field1,$field2);
328         $DivPatterns -> AddEntry($fields);
329       }                 
330     }
332     if($this->acl_is_readable("gotoMimeApplication")){
333       foreach($this->use_gotoMimeApplication as $key => $pattern){
334         $field1 = array("string" => $pattern);
335         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
336         $fields = array($field1,$field2);
337         $DivApps -> AddEntry($fields);
338       }                 
339     }                   
340     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
341       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
342         $field1 = array("string" => $pattern);
343         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
344         $fields = array($field1,$field2);
345         $DivEApps -> AddEntry($fields);
346       }
347     }                   
348     $smarty->assign("bases",                                            $this->get_allowed_bases());            
349     $smarty->assign("base_select",                                      $this->base);           
350     $smarty->assign("isReleaseMimeType",                        $this->is_release());
351     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
352     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
353     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
355     $smarty->assign("ApplicationList",$this->ApplicationList);
356   
357     /* Assign class vars to smarty */
358     foreach($this->attributes as $attr){
359       $smarty->assign($attr,$this->$attr);
360     }   
362     /* Assign additional vars that are not included in attributes*/
363     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
364       $smarty->assign($attr,$this->$attr);
365     }   
367     /* Assign select box options */
368     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
369     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
370     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
371   }
374   function save_object()
375   {
376     if(isset($_POST['MimeGeneric']) && !preg_match("/freeze/i",$this->FAIstate)){
378       /* Create a base backup and reset the
379          base directly after calling plugin::save_object();
380          Base will be set seperatly a few lines below */
381       $base_tmp = $this->base;
382       plugin::save_object();
383       $this->base = $base_tmp;
384   
385       /* Only save base if we are not in release mode */
386       if(!$this->is_release()){
388         /* Set new base if allowed */
389         $tmp = $this->get_allowed_bases();
390         if(isset($_POST['base'])){
391           if(isset($tmp[$_POST['base']])){
392             $this->base= $_POST['base'];
393           }
394         }
396       }
398       /* Save radio buttons */
399       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
400         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
401           $chr = $_POST['gotoMimeLeftClickAction_IE'];
402           if($chr == "E"){
403             $this->gotoMimeLeftClickAction_E = true;
404             $this->gotoMimeLeftClickAction_I = false;
405           }else{
406             $this->gotoMimeLeftClickAction_E = false;
407             $this->gotoMimeLeftClickAction_I = true;
408           }
409         }
410         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
411           $this->gotoMimeLeftClickAction_Q = true;
412         }else{
413           $this->gotoMimeLeftClickAction_Q = false;
414         }
415       }
416     }
417   }
420   /* save current changes */
421   function save()
422   {
423     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
424     $arr = array ("E","I","Q");
425     $str = "";
426     foreach ($arr as $Chr){
427       $var = "gotoMimeLeftClickAction_".$Chr;
428       if($this->$var){
429         $str .= $Chr;
430       }
431     }
432     $this->gotoMimeLeftClickAction = $str;
434     /* Create array entries with priority tag ( Test|3 )*/
435     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
436       $i                                = 0;
437       $use_attr                 = "use_".$attr;
438       $tmp                      = array();
439       $this->$attr      = array();
440       foreach($this->$use_attr as $entry){
441         $tmp[] = $entry."|".$i ++;
442       }
443       $this->$attr = $tmp;
444     }
446     /* Create array entries */
447     foreach(array("gotoMimeFilePattern") as $attr){
448       $i                                = 0;
449       $use_attr                 = "use_".$attr;
450       $tmp                      = array();
451       $this->$attr      = array();
452       foreach($this->$use_attr as $entry){
453         $tmp[] = $entry;
454       }
455       $this->$attr = $tmp;
456     }
458     /* Remove Icon if requested  */
459     if($this->use_gotoMimeIcon != "*removed*"){
460       $this->gotoMimeIcon = $this->iconData;
461     }else{
462       $this->gotoMimeIcon = "";
463     }
465     plugin::save();
467     /* If this is a newly created object, skip storing those 
468        attributes that contain an empty array */
469     if($this->orig_dn == "new"){
470       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
471         if(!count($this->$attr)){
472           unset($this->attrs[$attr]);
473         }
474       }
475     }
477     $ldap = $this->config->get_ldap_link();
478     $ldap-> cd ( $this->config->current['BASE']);
479     $ldap->cat($this->dn);
480     if($ldap->count()){
481       $ldap->cd($this->dn);
482       $this->cleanup();
483       $ldap->modify($this->attrs);
484       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
485     }else{
486       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
487       $ldap->cd($this->dn);
488       $ldap->add($this->attrs);
489       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
490     }
491     if (!$ldap->success()){
492       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
493     }
494   }
497   /* Remove current mime type */
498   function remove_from_parent()
499   {
500     plugin::remove_from_parent();
501     $ldap = $this->config->get_ldap_link();
502     $ldap->rmDir($this->dn);
503     if (!$ldap->success()){
504       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
505     }
506     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
508     /* Optionally execute a command after we're done */
509     $this->handle_post_events("remove");
511     /* Delete references to object groups */
512     $ldap->cd ($this->config->current['BASE']);
513     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
514     while ($ldap->fetch()){
515       $og= new ogroup($this->config, $ldap->getDN());
516       unset($og->member[$this->dn]);
517       $og->save ();
518       if (!$ldap->success()){
519         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
520       }
521     }
522   }
525   /* Check given values */
526   function check()
527   {
528     $message = plugin::check();
529     if(empty($this->cn)){
530       $message[] = msgPool::required(_("Name"));
531     }
532     if(!count($this->use_gotoMimeFilePattern)){
533       $message[] = msgPool::required(_("File pattern"));
534     }
536     /* Check if there is already a mime type with this cn */
537     $ldap = $this->config->get_ldap_link();
538     $ldap->cd($this->config->current["BASE"]);
540     if($this->is_release()){
541       $base = $this->parent->parent->mime_release;
542     }else{
543       $base = get_ou("mimetypeou").$this->base;
544     }
546     $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
547     if($ldap->count()){
548       $attrs = $ldap->fetch();
549       if($this->dn != $attrs['dn']) {
550         $message[]= msgPool::duplicated("cn");
551       }
552     }
554     /* Check if we are allowed to create or move this object
555      */
556     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
557       $message[] = msgPool::permCreate();
558     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
559       $message[] = msgPool::permMove();
560     }
562     return($message);
563   }
566   /** Helper functions **/
568   /* Set a new picture */       
569   function set_new_picture($filename)
570   {
571     if (empty($filename)){
572       $filename= "./images/default_icon.png";
573       $this->use_gotoMimeIcon= "*removed*";
574     }else{
575       $this->use_gotoMimeIcon= $filename;
576     }
578     if (file_exists($filename)){
579       $fd = fopen ($filename, "rb");
580       $this->iconData= fread ($fd, filesize ($filename));
581       session::set('binary',$this->iconData);
582       session::set('binarytype',"image/jpeg");
583       fclose ($fd);
584     }
585   }
587   /* Get picture link */
588   function get_picture()
589   {
590     session::set('binary',$this->iconData);
591     session::set('binarytype',"image/jpeg");
592     return("getbin.php");
593   }
595   /* Transports the given Arraykey one position up*/
596   function ArrayUp($atr,$attrs)
597   {
598     $ret = $attrs;
599     $pos = $this->getpos($atr,$attrs) ;
600     $cn = count($attrs);
601     if(!(($pos == -1)||($pos == 1))){
602       $before = array_slice($attrs,0,($pos-2));
603       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
604       $unten  = array_slice($attrs,$pos);
605       $ret = array();
606       $ret = $this->combineArrays($before,$mitte,$unten);
607     }
608     return($ret);
609   }
612   /* Transports the given Arraykey one position down*/
613   function ArrayDown($atr,$attrs)
614   {
615     $ret = $attrs;
616     $pos = $this->getpos($atr,$attrs) ;
617     $cn = count($attrs);
618     if(!(($pos == -1)||($pos == $cn))){
619       $before = array_slice($attrs,0,($pos-1));
620       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
621       $unten  = array_slice($attrs,($pos+1));
622       $ret = array();
623       $ret = $this->combineArrays($before,$mitte,$unten);
624     }
625     return($ret);
626   }
629   /* return the position of the element in the array */
630   function getpos($atr,$attrs)
631   {
632     $i = 0;
633     foreach($attrs as $attr => $name)    {
634       $i++;
635       if($attr == $atr){
636         return($i);
637       }
638     }
639     return(-1);
640   }
643   /* Remove this element from array */
644   function ArrayRemove($key,$array,$reorder = false)    
645   {
646     if(isset($array[$key])){
647       unset($array[$key]);
648       if($reorder){
649         $tmp = array();
650         foreach($array as $entry){
651           $tmp[] = $entry;
652         }
653         $array = $tmp;
654       }
655     }   
656     return($array);
657   }
660   /* Combine new array */
661   function combineArrays($ar0,$ar1,$ar2)
662   {
663     $ret = array();
664     if(is_array($ar0))
665       foreach($ar0 as $ar => $a){
666         $ret[]=$a;
667       }
668     if(is_array($ar1))
669       foreach($ar1 as $ar => $a){
670         $ret[]=$a;
671       }
672     if(is_array($ar2))
673       foreach($ar2 as $ar => $a){
674         $ret[]=$a;
675       }
676     return($ret);
677   }
680   /* Return a dialog with all fields that must be changed, 
681      if we want to copy this entry */
682   function getCopyDialog()
683   {
684     $str = "";
686     $smarty = get_smarty();
687     $smarty->assign("cn",               $this->cn);
688     $smarty->assign("description",  $this->description);
689     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
691     $ret = array();
692     $ret['string'] = $str;
693     $ret['status'] = "";
694     return($ret);
695   }
698   /* Save all */
699   function saveCopyDialog()
700   {
701     $attrs = array("cn","description");
702     foreach($attrs as $attr){
703       if(isset($_POST[$attr])){
704         $this->$attr = $_POST[$attr];
705       }
706     }
707   }
709   /* Return plugin informations for acl handling  */ 
710   static function plInfo()
711   {
712     return (array(
713           "plShortName"   => _("Generic"),
714           "plDescription" => _("Mime type generic"),
715           "plSelfModify"  => FALSE,
716           "plDepends"     => array(),
717           "plPriority"    => 0,
718           "plSection"     => array("administration"),
719           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
720                                                         "objectClass"  => "gotoMimeType")),
721           "plProvidedAcls"=> array(
722             "cn"                          => _("Name"),
723             "gotoMimeGroup"               => _("Mime group"),
724             "description"                 => _("Description"),
725             "base"                        => _("Base"),
726             "gotoMimeApplication"         => _("Application"),
727             "gotoMimeLeftClickAction"     => _("Left click action"),
728             "gotoMimeIcon"                => _("Icon"),
729             "gotoMimeFilePattern"         => _("File patterns"),
730             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
731           ));
733   }
736   function is_release()
737   {
738     if(is_object($this->parent->parent)){
739       return($this->parent->parent->IsReleaseManagementActivated());
740     }else{
741       /* Check if we should enable the release selection */
742       $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
743       if(!empty($tmp)){
744         return(true);
745       }
746     }
747     return(FALSE);
748   }
751   function PrepareForCopyPaste($source)
752   {
753     plugin::PrepareForCopyPaste($source);
755     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
757     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
758       $use_attr     = "use_".$name;
759       if(isset($this->$use_attr)){
760         $this->$use_attr= $source_o->$use_attr;
761       }
762       $this->$name = $source_o->$name;
763     } 
764     foreach($this->attributes as $name){
765       $this->$name = $source_o->$name;
766     }
768     if($this->iconData){
769       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
770     }
771   }
773 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
774 ?>