Code

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