Code

Added create move acls
[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   /* These vars will be copied too, if you use copy&paste mode */
41   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
42                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
44   var $view_logged  = FALSE;
46   /* Select options */
47   var $MimeGroups                             = array("application","audio","chemical","image","inode","message","model",
48                                       "multipart","text","video","x-conference","x-world");
50   /* Orig_Dn is used to verify if this object is new or only edited */          
51   var $orig_dn                  = "";
52   var $orig_base          = "";
54   function mimetype(&$config,$dn= NULL)
55   {
56     plugin::plugin ($config, $dn);
58     /* Save original dn */
59     $this->orig_dn = $dn;       
61     /* get gotoMimeLeftClickActions I/E/Q */
62     if(isset($this->gotoMimeLeftClickAction)){
63       $str = $this->gotoMimeLeftClickAction;
64       for($i = 0 ; $i < strlen($str) ; $i ++ ){
65         $varna = "gotoMimeLeftClickAction_". $str[$i];
66         if(isset($this->$varna)){
67           $this->$varna = true;
68         }
69       }
70     }
72     /* Create list of defined applications in GOsa */
73     $ldap = $this->config->get_ldap_link();
74     $ldap->cd($this->config->current['BASE']);
75     $ldap->search("(&(objectClass=gosaApplication)(cn=*))",array('cn'));
76     $this->ApplicationList = array();
77     while($attrs = $ldap->fetch()){
78       $this->ApplicationList[$attrs['cn'][0]] = $attrs['cn'][0];
79     }
81     /* If both radio buttons arn't set, set option I */
82     if(!$this->gotoMimeLeftClickAction_I && !$this->gotoMimeLeftClickAction_E){
83       $this->gotoMimeLeftClickAction_I = true;
84     }
86     /* Get list of array attributes */
87     foreach(array("gotoMimeFilePattern") as $attr){
88       $this->$attr = array();
89       if(isset($this->attrs[$attr])){
90         $tmp = array();
91         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
92           $str = $this->attrs[$attr][$i];
93           $tmp[] = $str;
94         }
95         $use_attr = "use_".$attr;
96         $this->$use_attr = $tmp;
97       }
98     }
100     /* Get list of array attributes with priority tag ( Test|32 )*/
101     foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){
102       $this->$attr = array();
103       if(isset($this->attrs[$attr])){
104         $tmp = array();
105         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
106           $str = $this->attrs[$attr][$i];
107           $tmp2= split("\|",$str);
109           if(count($tmp2) == 2){
110             $name = $tmp2[0];
111             $prio = $tmp2[1];
112             $tmp[$prio] = $name;
113           }
114         }
115         ksort($tmp);
116         $use_attr = "use_".$attr;
117         $this->$use_attr = $tmp;
118       }
119     }
121     /* Set base */      
122     if ($this->dn == "new"){
123       if(session::is_set('CurrentMainBase')){
124         $this->base= session::get('CurrentMainBase');
125       }else{
126         $ui= get_userinfo();
127         $this->base= dn2base($ui->dn);
128       }
129     } else {
130       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
131     }
133     /* Get icon data */
134     if(isset($this->attrs['gotoMimeIcon'])){
135       $ldap = $this->config->get_ldap_link();
136       $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon");
137       $this->saved_attributes['gotoMimeIcon'] = $this->iconData;
138     }
139     if ($this->iconData == ""){
140       $this->set_new_picture("");
141     }
142     session::set('binary',$this->iconData);
143     session::set('binarytype',"image/jpeg");
144     $this->orig_base = $this->base;
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']) && 
251             (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
252       if($this->acl_is_writeable("gotoMimeApplication")){
253         $str = "";
254         if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
255           $str = get_post("NewApplicationSelect");
256         }
257         if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
258           $str = get_post("NewApplication");
259         }
260         if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
261           $this->use_gotoMimeApplication[] = $str;
262         }
263       }
264     }   
266     /* Add embedded application 
267      *  - From input or from select box 
268      */
269     if(isset($_POST['AddNewEmbeddedApplication']) && 
270             (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
271       if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
272         $str = "";
273         if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
274           $str = get_post('NewEmbeddedApplicationSelect');
275         }
276         if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
277           $str = get_post('NewEmbeddedApplication');
278         }
279         if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
280           $this->use_gotoMimeEmbeddedApplication[] = $str;
281         }
282       }
283     }   
285     /* Create divlists */
286     $DivPatterns        = new divSelectBox("gotoMimePatterns");
287     $DivApps            = new divSelectBox("gotoMimeApplications");
288     $DivEApps           = new divSelectBox("gotoMimeEmbeddedApplications");
289     $DivPatterns        -> SetHeight(100);
290     $DivApps            -> SetHeight(100);
291     $DivEApps           -> SetHeight(100);
294     if($this->acl_is_writeable("gotoMimeFilePattern")){
295       $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'    class='center'  name='Pattern_SortUp_%s' >&nbsp;
296       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Pattern_SortDown_%s'>&nbsp;
297       <input type='image' src='images/lists/trash.png'  class='center'  name='Pattern_Remove_%s'>";
298     }else{
299       $Pattern_Actions= "";     
300     }
302     if($this->acl_is_writeable("gotoMimeApplication")){
303       $Apps_Actions     = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
304       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Apps_SortDown_%s'>&nbsp;
305       <input type='image' src='images/lists/trash.png'  class='center'  name='Apps_Remove_%s'>";
306     }else{
307       $Apps_Actions= "";        
308     }
310     if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
311       $EApps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
312       <input type='image' src='images/lists/sort-down.png'      class='center'  name='EApps_SortDown_%s'>&nbsp;
313       <input type='image' src='images/lists/trash.png'  class='center'  name='EApps_Remove_%s'>";
314     }else{
315       $EApps_Actions= "";       
316     }
318     /* Before adding some entries check acls */
319     if($this->acl_is_readable("gotoMimeFilePattern")){
320       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
321         $field1 = array("string" => $pattern);
322         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
323         $fields = array($field1,$field2);
324         $DivPatterns -> AddEntry($fields);
325       }                 
326     }
328     if($this->acl_is_readable("gotoMimeApplication")){
329       foreach($this->use_gotoMimeApplication as $key => $pattern){
330         $field1 = array("string" => $pattern);
331         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
332         $fields = array($field1,$field2);
333         $DivApps -> AddEntry($fields);
334       }                 
335     }                   
336     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
337       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
338         $field1 = array("string" => $pattern);
339         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
340         $fields = array($field1,$field2);
341         $DivEApps -> AddEntry($fields);
342       }
343     }                   
344     $smarty->assign("bases",                                            $this->get_allowed_bases());            
345     $smarty->assign("base_select",                                      $this->base);           
346     $smarty->assign("isReleaseMimeType",                        $this->is_release());
347     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
348     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
349     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
351     $smarty->assign("ApplicationList",$this->ApplicationList);
352   
353     /* Assign class vars to smarty */
354     foreach($this->attributes as $attr){
355       $smarty->assign($attr,$this->$attr);
356     }   
358     /* Assign additional vars that are not included in attributes*/
359     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
360       $smarty->assign($attr,$this->$attr);
361     }   
363     /* Assign select box options */
364     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
365     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
366     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
367   }
370   function save_object()
371   {
372     if(isset($_POST['MimeGeneric'])){
374       /* Create a base backup and reset the
375          base directly after calling plugin::save_object();
376          Base will be set seperatly a few lines below */
377       $base_tmp = $this->base;
378       plugin::save_object();
379       $this->base = $base_tmp;
380   
381       /* Only save base if we are not in release mode */
382       if(!$this->is_release()){
384         /* Set new base if allowed */
385         $tmp = $this->get_allowed_bases();
386         if(isset($_POST['base'])){
387           if(isset($tmp[$_POST['base']])){
388             $this->base= $_POST['base'];
389           }
390         }
392       }
394       /* Save radio buttons */
395       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
396         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
397           $chr = $_POST['gotoMimeLeftClickAction_IE'];
398           if($chr == "E"){
399             $this->gotoMimeLeftClickAction_E = true;
400             $this->gotoMimeLeftClickAction_I = false;
401           }else{
402             $this->gotoMimeLeftClickAction_E = false;
403             $this->gotoMimeLeftClickAction_I = true;
404           }
405         }
406         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
407           $this->gotoMimeLeftClickAction_Q = true;
408         }else{
409           $this->gotoMimeLeftClickAction_Q = false;
410         }
411       }
412     }
413   }
416   /* save current changes */
417   function save()
418   {
419     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
420     $arr = array ("E","I","Q");
421     $str = "";
422     foreach ($arr as $Chr){
423       $var = "gotoMimeLeftClickAction_".$Chr;
424       if($this->$var){
425         $str .= $Chr;
426       }
427     }
428     $this->gotoMimeLeftClickAction = $str;
430     /* Create array entries with priority tag ( Test|3 )*/
431     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
432       $i                                = 0;
433       $use_attr                 = "use_".$attr;
434       $tmp                      = array();
435       $this->$attr      = array();
436       foreach($this->$use_attr as $entry){
437         $tmp[] = $entry."|".$i ++;
438       }
439       $this->$attr = $tmp;
440     }
442     /* Create array entries */
443     foreach(array("gotoMimeFilePattern") as $attr){
444       $i                                = 0;
445       $use_attr                 = "use_".$attr;
446       $tmp                      = array();
447       $this->$attr      = array();
448       foreach($this->$use_attr as $entry){
449         $tmp[] = $entry;
450       }
451       $this->$attr = $tmp;
452     }
454     /* Remove Icon if requested  */
455     if($this->use_gotoMimeIcon != "*removed*"){
456       $this->gotoMimeIcon = $this->iconData;
457     }else{
458       $this->gotoMimeIcon = "";
459     }
461     plugin::save();
463     /* If this is a newly created object, skip storing those 
464        attributes that contain an empty array */
465     if($this->orig_dn == "new"){
466       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
467         if(!count($this->$attr)){
468           unset($this->attrs[$attr]);
469         }
470       }
471     }
473     $ldap = $this->config->get_ldap_link();
474     $ldap-> cd ( $this->config->current['BASE']);
475     $ldap->cat($this->dn);
476     if($ldap->count()){
477       $ldap->cd($this->dn);
478       $this->cleanup();
479       $ldap->modify($this->attrs);
480       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
481     }else{
482       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
483       $ldap->cd($this->dn);
484       $ldap->add($this->attrs);
485       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
486     }
487     if (!$ldap->success()){
488       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
489     }
490   }
493   /* Remove current mime type */
494   function remove_from_parent()
495   {
496     plugin::remove_from_parent();
497     $ldap = $this->config->get_ldap_link();
498     $ldap->rmDir($this->dn);
499     if (!$ldap->success()){
500       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
501     }
502     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
504     /* Optionally execute a command after we're done */
505     $this->handle_post_events("remove");
507     /* Delete references to object groups */
508     $ldap->cd ($this->config->current['BASE']);
509     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
510     while ($ldap->fetch()){
511       $og= new ogroup($this->config, $ldap->getDN());
512       unset($og->member[$this->dn]);
513       $og->save ();
514       if (!$ldap->success()){
515         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
516       }
517     }
518   }
521   /* Check given values */
522   function check()
523   {
524     $message = plugin::check();
525     if(empty($this->cn)){
526       $message[] = msgPool::required(_("Name"));
527     }
528     if(!count($this->use_gotoMimeFilePattern)){
529       $message[] = msgPool::required(_("File pattern"));
530     }
532     /* Check if there is already a mime type with this cn */
533     $ldap = $this->config->get_ldap_link();
534     $ldap->cd($this->config->current["BASE"]);
536     if($this->is_release()){
537       $base = $this->parent->parent->mime_release;
538     }else{
539       $base = get_ou("mimetypeou").$this->base;
540     }
542     $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
543     if($ldap->count()){
544       $attrs = $ldap->fetch();
545       if($this->dn != $attrs['dn']) {
546         $message[]= msgPool::duplicated("cn");
547       }
548     }
550     /* Check if we are allowed to create or move this object
551      */
552     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
553       $message[] = msgPool::permCreate();
554     }elseif($this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
555       $message[] = msgPool::permMove();
556     }
558     return($message);
559   }
562   /** Helper functions **/
564   /* Set a new picture */       
565   function set_new_picture($filename)
566   {
567     if (empty($filename)){
568       $filename= "./images/default_icon.png";
569       $this->use_gotoMimeIcon= "*removed*";
570     }else{
571       $this->use_gotoMimeIcon= $filename;
572     }
574     if (file_exists($filename)){
575       $fd = fopen ($filename, "rb");
576       $this->iconData= fread ($fd, filesize ($filename));
577       session::set('binary',$this->iconData);
578       session::set('binarytype',"image/jpeg");
579       fclose ($fd);
580     }
581   }
583   /* Get picture link */
584   function get_picture()
585   {
586     session::set('binary',$this->iconData);
587     session::set('binarytype',"image/jpeg");
588     return("getbin.php");
589   }
591   /* Transports the given Arraykey one position up*/
592   function ArrayUp($atr,$attrs)
593   {
594     $ret = $attrs;
595     $pos = $this->getpos($atr,$attrs) ;
596     $cn = count($attrs);
597     if(!(($pos == -1)||($pos == 1))){
598       $before = array_slice($attrs,0,($pos-2));
599       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
600       $unten  = array_slice($attrs,$pos);
601       $ret = array();
602       $ret = $this->combineArrays($before,$mitte,$unten);
603     }
604     return($ret);
605   }
608   /* Transports the given Arraykey one position down*/
609   function ArrayDown($atr,$attrs)
610   {
611     $ret = $attrs;
612     $pos = $this->getpos($atr,$attrs) ;
613     $cn = count($attrs);
614     if(!(($pos == -1)||($pos == $cn))){
615       $before = array_slice($attrs,0,($pos-1));
616       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
617       $unten  = array_slice($attrs,($pos+1));
618       $ret = array();
619       $ret = $this->combineArrays($before,$mitte,$unten);
620     }
621     return($ret);
622   }
625   /* return the position of the element in the array */
626   function getpos($atr,$attrs)
627   {
628     $i = 0;
629     foreach($attrs as $attr => $name)    {
630       $i++;
631       if($attr == $atr){
632         return($i);
633       }
634     }
635     return(-1);
636   }
639   /* Remove this element from array */
640   function ArrayRemove($key,$array,$reorder = false)    
641   {
642     if(isset($array[$key])){
643       unset($array[$key]);
644       if($reorder){
645         $tmp = array();
646         foreach($array as $entry){
647           $tmp[] = $entry;
648         }
649         $array = $tmp;
650       }
651     }   
652     return($array);
653   }
656   /* Combine new array */
657   function combineArrays($ar0,$ar1,$ar2)
658   {
659     $ret = array();
660     if(is_array($ar0))
661       foreach($ar0 as $ar => $a){
662         $ret[]=$a;
663       }
664     if(is_array($ar1))
665       foreach($ar1 as $ar => $a){
666         $ret[]=$a;
667       }
668     if(is_array($ar2))
669       foreach($ar2 as $ar => $a){
670         $ret[]=$a;
671       }
672     return($ret);
673   }
676   /* Return a dialog with all fields that must be changed, 
677      if we want to copy this entry */
678   function getCopyDialog()
679   {
680     $str = "";
682     $smarty = get_smarty();
683     $smarty->assign("cn",               $this->cn);
684     $smarty->assign("description",  $this->description);
685     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
687     $ret = array();
688     $ret['string'] = $str;
689     $ret['status'] = "";
690     return($ret);
691   }
694   /* Save all */
695   function saveCopyDialog()
696   {
697     $attrs = array("cn","description");
698     foreach($attrs as $attr){
699       if(isset($_POST[$attr])){
700         $this->$attr = $_POST[$attr];
701       }
702     }
703   }
705   /* Return plugin informations for acl handling  */ 
706   static function plInfo()
707   {
708     return (array(
709           "plShortName"   => _("Generic"),
710           "plDescription" => _("Mime type generic"),
711           "plSelfModify"  => FALSE,
712           "plDepends"     => array(),
713           "plPriority"    => 0,
714           "plSection"     => array("administration"),
715           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
716                                                         "objectClass"  => "gotoMimeType")),
717           "plProvidedAcls"=> array(
718             "cn"                          => _("Name"),
719             "gotoMimeGroup"               => _("Mime group"),
720             "description"                 => _("Description"),
721             "base"                        => _("Base"),
722             "gotoMimeApplication"         => _("Application"),
723             "gotoMimeLeftClickAction"     => _("Left click action"),
724             "gotoMimeIcon"                => _("Icon"),
725             "gotoMimeFilePattern"         => _("File patterns"),
726             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
727           ));
729   }
732   function is_release()
733   {
734     if(is_object($this->parent->parent)){
735       return($this->parent->parent->IsReleaseManagementActivated());
736     }else{
737       /* Check if we should enable the release selection */
738       $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
739       if(!empty($tmp)){
740         return(true);
741       }
742     }
743     return(FALSE);
744   }
747   function PrepareForCopyPaste($source)
748   {
749     plugin::PrepareForCopyPaste($source);
751     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
753     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
754       $use_attr     = "use_".$name;
755       if(isset($this->$use_attr)){
756         $this->$use_attr= $source_o->$use_attr;
757       }
758       $this->$name = $source_o->$name;
759     } 
760     foreach($this->attributes as $name){
761       $this->$name = $source_o->$name;
762     }
764     if($this->iconData){
765       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
766     }
767   }
769 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
770 ?>