Code

Updated trunk, introduced gosa-core
[gosa.git] / plugins / admin / mimetypes / class_mimetypeGeneric.inc
1 <?php
2 class mimetype extends plugin
3 {
4         /* CLI vars */
5         var $cli_summary                  = "This tab allows you to modify, add or remove mime types in the selected department.";
6         var $cli_description    = "Management dialog to handle mime types";
7         var $ignore_account     = true; // This is always a valid account
8         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9         var $objectclasses              = array("top","gotoMimeType");
10         var $attributes                   = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon",
11                                                                         "description","gotoMimeFilePattern","gotoMimeEmbeddedApplication",
12                                                                         "gotoMimeGroup");       
14         /* Class vars */
15         var $ui;
16         var $cn                                                                               = "";                                     
17         var $gotoMimeLeftClickAction                        = "I";
18         var $gotoMimeLeftClickAction_I              = true;
19         var $gotoMimeLeftClickAction_E              = false;
20         var $gotoMimeLeftClickAction_Q              = false;
21         var $gotoMimeIcon                                                         = "*removed*";
22         var $description                                                          = "";
23         var $gotoMimeFilePattern                                      = array();
24         var $gotoMimeApplication                                      = array();
25         var $gotoMimeEmbeddedApplication            = array();
26         var $gotoMimeGroup                                                      = "";
27         var $iconData                                                               = NULL;     
28         var $base                                                                             = "";
29   var $ApplicationList                  = array();  
32   /* To prevent errors when using the 'apply' button, we use this variables 
33       to manage array attributes */
34         var $use_gotoMimeIcon                                           = NULL;
35         var $use_gotoMimeFilePattern                        = array();
36         var $use_gotoMimeApplication                        = array();
37         var $use_gotoMimeEmbeddedApplication    = array();
39   /* divLists */
40   var $DivPatterns                                                        = NULL;
41   var $DivApps                                                              = NULL;
42   var $DivEApps                                                             = NULL;
44   /* Mime type release mode */
45   var $isReleaseMimeType                                              = false;
47   /* These vars will be copied too, if you use copy&paste mode */
48   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
49                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
51   var $view_logged  = FALSE;
53   /* Select options */
54   var $MimeGroups                             = array("application","audio","chemical","image","inode","message","model",
55                                       "multipart","text","video","x-conference","x-world");
57   /* Orig_Dn is used to verify if this object is new or only edited */          
58   var $orig_dn                  = "";
60   function mimetype(&$config,$dn= NULL)
61   {
62     plugin::plugin ($config, $dn);
64     /* Save original dn */
65     $this->orig_dn = $dn;       
67     /* get gotoMimeLeftClickActions I/E/Q */
68     if(isset($this->gotoMimeLeftClickAction)){
69       $str = $this->gotoMimeLeftClickAction;
70       for($i = 0 ; $i < strlen($str) ; $i ++ ){
71         $varna = "gotoMimeLeftClickAction_". $str[$i];
72         if(isset($this->$varna)){
73           $this->$varna = true;
74         }
75       }
76     }
78     /* Create list of defined applications in GOsa */
79     $ldap = $this->config->get_ldap_link();
80     $ldap->cd($this->config->current['BASE']);
81     $ldap->search("(&(objectClass=gosaApplication)(cn=*))",array('cn'));
82     $this->ApplicationList = array();
83     while($attrs = $ldap->fetch()){
84       $this->ApplicationList[$attrs['cn'][0]] = $attrs['cn'][0];
85     }
87     /* If both radio buttons arn't set, set option I */
88     if(!$this->gotoMimeLeftClickAction_I && !$this->gotoMimeLeftClickAction_E){
89       $this->gotoMimeLeftClickAction_I = true;
90     }
92     /* Get list of array attributes */
93     foreach(array("gotoMimeFilePattern") as $attr){
94       $this->$attr = array();
95       if(isset($this->attrs[$attr])){
96         $tmp = array();
97         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
98           $str = $this->attrs[$attr][$i];
99           $tmp[] = $str;
100         }
101         $use_attr = "use_".$attr;
102         $this->$use_attr = $tmp;
103       }
104     }
106     /* Get list of array attributes with priority tag ( Test|32 )*/
107     foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){
108       $this->$attr = array();
109       if(isset($this->attrs[$attr])){
110         $tmp = array();
111         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
112           $str = $this->attrs[$attr][$i];
113           $tmp2= split("\|",$str);
115           if(count($tmp2) == 2){
116             $name = $tmp2[0];
117             $prio = $tmp2[1];
118             $tmp[$prio] = $name;
119           }
120         }
121         ksort($tmp);
122         $use_attr = "use_".$attr;
123         $this->$use_attr = $tmp;
124       }
125     }
127     /* Check if release Management is enabled */
128     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
129     if(!empty($tmp)) {
130       $this->isReleaseMimeType= true;
131     }
133     /* Set base */      
134     if ($this->dn == "new"){
135       if(isset($_SESSION['CurrentMainBase'])){
136         $this->base= $_SESSION['CurrentMainBase'];
137       }else{
138         $ui= get_userinfo();
139         $this->base= dn2base($ui->dn);
140       }
141     } else {
142       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
143     }
145     /* Get icon data */
146     if(isset($this->attrs['gotoMimeIcon'])){
147       $ldap = $this->config->get_ldap_link();
148       $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon");
149       $this->saved_attributes['gotoMimeIcon'] = $this->iconData;
150     }
151     if ($this->iconData == ""){
152       $this->set_new_picture("");
153     }
154     $_SESSION['binary']                 = $this->iconData;
155     $_SESSION['binarytype']             = "image/jpeg";
156   }
159   function execute()
160   {
161     $smarty = get_smarty();
163     if(!$this->view_logged){
164       $this->view_logged =TRUE;
165       new log("view","mimetypes/".get_class($this),$this->dn);
166     }
168     $tmp = $this->plInfo();
169     foreach($tmp['plProvidedAcls'] as $name => $translation){
170       $smarty->assign($name."ACL",$this->getacl($name));
171     }
173     /* Base select dialog */
174     $once = true;
175     foreach($_POST as $name => $value){
176       if(preg_match("/^chooseBase/",$name) && $once){
177         $once = false;
178         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
179         $this->dialog->setCurrentBase($this->base);
180       }
181     }
183     /* Dialog handling */
184     if(is_object($this->dialog)){
186       /* Must be called before save_object */
187       $this->dialog->save_object();
189       if($this->dialog->isClosed()){
190         $this->dialog = false;
191       }elseif($this->dialog->isSelected()){
193         /* A new base was selected, check if it is a valid one */
194         $tmp = $this->get_allowed_bases();
195         if(isset($tmp[$this->dialog->isSelected()])){
196           $this->base = $this->dialog->isSelected();
197         }
199         $this->dialog= false;
200       }else{
201         return($this->dialog->execute());
202       }
203     }
205     /* Check Posts */
206     $posts = array(     
207         "/^Pattern_SortUp_/"    => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
208         "/^Pattern_SortDown_/"  => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
209         "/^Pattern_Remove_/"    => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
210         "/^Apps_SortUp_/"               => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
211         "/^Apps_SortDown_/"     => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
212         "/^Apps_Remove_/"               => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
213         "/^EApps_SortUp_/"              => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
214         "/^EApps_SortDown_/"    => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
215         "/^EApps_Remove_/"              => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
216     $once = true;
218     /* Walk through posts and try to find some commands for us. */
219     foreach($_POST as $name => $value){
221       /* Walk through possible commands */
222       foreach($posts as $regex => $action){
224         /* Check if there is a command posted */
225         if(preg_match($regex,$name) && $once){
226           $once = false;
228           /* Get action vars */
229           $func                 = $action['Func'];              // Get function name 
230           $attr                 = $action['Attr'];              // Get attribute name
232           /* Get entry id */
233           $s_entry      = preg_replace($regex,"",$name);
234           $s_entry      = preg_replace("/_[xy]$/","",$s_entry); 
236           /* Execute a command with the given attribute and entry 
237              e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
238           if($this->acl_is_writeable($attr)){
239             $this->$attr= $this->$func($s_entry,$this->$attr,true);                                      
240           }
241         }
242       }
243     }
245     /* Set a new icon was requested */
246     if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
247       $this->set_new_picture($_FILES['picture_file']['tmp_name']);              
248     }
250     /* Add gotoMimeFilePattern */
251     if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
252       if($this->acl_is_writeable("gotoMimeFilePattern")){
253         $str = $_POST['NewFilePattern'];
254         if(!empty($str)){
255           $this->use_gotoMimeFilePattern[] = $str;
256         }
257       }
258     }   
260     /* Add gotoMimeFilePattern */
261     if(isset($_POST['AddNewApplication']) && 
262             (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
263       if($this->acl_is_writeable("gotoMimeApplication")){
264         $str = "";
265         if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
266           $str = get_post("NewApplicationSelect");
267         }
268         if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
269           $str = get_post("NewApplication");
270         }
271         if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
272           $this->use_gotoMimeApplication[] = $str;
273         }
274       }
275     }   
277     /* Add embedded application 
278      *  - From input or from select box 
279      */
280     if(isset($_POST['AddNewEmbeddedApplication']) && 
281             (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
282       if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
283         $str = "";
284         if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
285           $str = get_post('NewEmbeddedApplicationSelect');
286         }
287         if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
288           $str = get_post('NewEmbeddedApplication');
289         }
290         if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
291           $this->use_gotoMimeEmbeddedApplication[] = $str;
292         }
293       }
294     }   
296     /* Create divlists */
297     $DivPatterns        = new divSelectBox("gotoMimePatterns");
298     $DivApps            = new divSelectBox("gotoMimeApplications");
299     $DivEApps           = new divSelectBox("gotoMimeEmbeddedApplications");
300     $DivPatterns        -> SetHeight(100);
301     $DivApps            -> SetHeight(100);
302     $DivEApps           -> SetHeight(100);
305     if($this->acl_is_writeable("gotoMimeFilePattern")){
306       $Pattern_Actions= " <input type='image' src='images/sort_up.png'  class='center'  name='Pattern_SortUp_%s' >&nbsp;
307       <input type='image' src='images/sort_down.png'    class='center'  name='Pattern_SortDown_%s'>&nbsp;
308       <input type='image' src='images/edittrash.png'    class='center'  name='Pattern_Remove_%s'>";
309     }else{
310       $Pattern_Actions= "";     
311     }
313     if($this->acl_is_writeable("gotoMimeApplication")){
314       $Apps_Actions     = " <input type='image' src='images/sort_up.png'        class='center'  name='Apps_SortUp_%s' >&nbsp;
315       <input type='image' src='images/sort_down.png'    class='center'  name='Apps_SortDown_%s'>&nbsp;
316       <input type='image' src='images/edittrash.png'    class='center'  name='Apps_Remove_%s'>";
317     }else{
318       $Apps_Actions= "";        
319     }
321     if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
322       $EApps_Actions    = " <input type='image' src='images/sort_up.png'        class='center'  name='EApps_SortUp_%s' >&nbsp;
323       <input type='image' src='images/sort_down.png'    class='center'  name='EApps_SortDown_%s'>&nbsp;
324       <input type='image' src='images/edittrash.png'    class='center'  name='EApps_Remove_%s'>";
325     }else{
326       $EApps_Actions= "";       
327     }
329     /* Before adding some entries check acls */
330     if($this->acl_is_readable("gotoMimeFilePattern")){
331       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
332         $field1 = array("string" => $pattern);
333         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
334         $fields = array($field1,$field2);
335         $DivPatterns -> AddEntry($fields);
336       }                 
337     }
339     if($this->acl_is_readable("gotoMimeApplication")){
340       foreach($this->use_gotoMimeApplication as $key => $pattern){
341         $field1 = array("string" => $pattern);
342         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
343         $fields = array($field1,$field2);
344         $DivApps -> AddEntry($fields);
345       }                 
346     }                   
347     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
348       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
349         $field1 = array("string" => $pattern);
350         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
351         $fields = array($field1,$field2);
352         $DivEApps -> AddEntry($fields);
353       }
354     }                   
355     $smarty->assign("bases",                                            $this->get_allowed_bases());            
356     $smarty->assign("base_select",                                      $this->base);           
357     $smarty->assign("isReleaseMimeType",                        $this->isReleaseMimeType);
358     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
359     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
360     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
362     $smarty->assign("ApplicationList",$this->ApplicationList);
363   
364     /* Assign class vars to smarty */
365     foreach($this->attributes as $attr){
366       $smarty->assign($attr,$this->$attr);
367     }   
369     /* Assign additional vars that are not included in attributes*/
370     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
371       $smarty->assign($attr,$this->$attr);
372     }   
374     /* Assign select box options */
375     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
376     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
377     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
378   }
381   function save_object()
382   {
383     if(isset($_POST['MimeGeneric'])){
385       /* Create a base backup and reset the
386          base directly after calling plugin::save_object();
387          Base will be set seperatly a few lines below */
388       $base_tmp = $this->base;
389       plugin::save_object();
390       $this->base = $base_tmp;
391   
392       /* Only save base if we are not in release mode */
393       if(!$this->isReleaseMimeType){
395         /* Set new base if allowed */
396         $tmp = $this->get_allowed_bases();
397         if(isset($_POST['base'])){
398           if(isset($tmp[$_POST['base']])){
399             $this->base= $_POST['base'];
400           }
401         }
403       }
405       /* Save radio buttons */
406       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
407         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
408           $chr = $_POST['gotoMimeLeftClickAction_IE'];
409           if($chr == "E"){
410             $this->gotoMimeLeftClickAction_E = true;
411             $this->gotoMimeLeftClickAction_I = false;
412           }else{
413             $this->gotoMimeLeftClickAction_E = false;
414             $this->gotoMimeLeftClickAction_I = true;
415           }
416         }
417         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
418           $this->gotoMimeLeftClickAction_Q = true;
419         }else{
420           $this->gotoMimeLeftClickAction_Q = false;
421         }
422       }
423     }
424   }
427   /* save current changes */
428   function save()
429   {
430     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
431     $arr = array ("E","I","Q");
432     $str = "";
433     foreach ($arr as $Chr){
434       $var = "gotoMimeLeftClickAction_".$Chr;
435       if($this->$var){
436         $str .= $Chr;
437       }
438     }
439     $this->gotoMimeLeftClickAction = $str;
441     /* Create array entries with priority tag ( Test|3 )*/
442     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
443       $i                                = 0;
444       $use_attr                 = "use_".$attr;
445       $tmp                      = array();
446       $this->$attr      = array();
447       foreach($this->$use_attr as $entry){
448         $tmp[] = $entry."|".$i ++;
449       }
450       $this->$attr = $tmp;
451     }
453     /* Create array entries */
454     foreach(array("gotoMimeFilePattern") as $attr){
455       $i                                = 0;
456       $use_attr                 = "use_".$attr;
457       $tmp                      = array();
458       $this->$attr      = array();
459       foreach($this->$use_attr as $entry){
460         $tmp[] = $entry;
461       }
462       $this->$attr = $tmp;
463     }
465     /* Remove Icon if requested  */
466     if($this->use_gotoMimeIcon != "*removed*"){
467       $this->gotoMimeIcon = $this->iconData;
468     }else{
469       $this->gotoMimeIcon = "";
470     }
472     plugin::save();
474     /* If this is a newly created object, skip storing those 
475        attributes that contain an empty array */
476     if($this->orig_dn == "new"){
477       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
478         if(!count($this->$attr)){
479           unset($this->attrs[$attr]);
480         }
481       }
482     }
484     $ldap = $this->config->get_ldap_link();
485     $ldap-> cd ( $this->config->current['BASE']);
486     $ldap->cat($this->dn);
487     if($ldap->count()){
488       $ldap->cd($this->dn);
489       $this->cleanup();
490       $ldap->modify($this->attrs);
491       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
492     }else{
493       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
494       $ldap->cd($this->dn);
495       $ldap->add($this->attrs);
496       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
497     }
498     show_ldap_error($ldap->get_error(), sprintf(_("Saving of mime type/generic with dn '%s' failed."),$this->dn));
499   }
502   /* Remove current mime type */
503   function remove_from_parent()
504   {
505     plugin::remove_from_parent();
506     $ldap = $this->config->get_ldap_link();
507     $ldap->rmDir($this->dn);
508     show_ldap_error($ldap->get_error(), sprintf(_("Removing of mime type/generic with dn '%s' failed."),$this->dn));
509     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
511     /* Optionally execute a command after we're done */
512     $this->handle_post_events("remove");
514     /* Delete references to object groups */
515     $ldap->cd ($this->config->current['BASE']);
516     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
517     while ($ldap->fetch()){
518       $og= new ogroup($this->config, $ldap->getDN());
519       unset($og->member[$this->dn]);
520       $og->save ();
521       show_ldap_error($ldap->get_error(), sprintf(_("Removing mime type from objectgroup '%s' failed"), $og->dn));
522     }
523   }
526   /* Check given values */
527   function check()
528   {
529     $message = plugin::check();
530     if(empty($this->cn)){
531       $message[] = _("Please specify a valid name for this mime type.");
532     }
533     if(!count($this->use_gotoMimeFilePattern)){
534       $message[] = _("Please specify at least one file pattern.") ;
535     }
537     /* Check if there is already a mime type with this cn */
538     $ldap = $this->config->get_ldap_link();
539     $ldap->cd($this->config->current["BASE"]);
540     if($this->isReleaseMimeType && (isset($_SESSION['mimefilter']['release']))){
541       $baseDn = str_replace($this->config->current['BASE'],$this->base,$_SESSION['mimefilter']['release']);
542       $baseDn = preg_replace("/ou=mime,.*/","ou=mime,".$this->base,$_SESSION['mimefilter']['release']);
543       $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$baseDn,array("cn"));
544       if($ldap->count()){
545         $attrs = $ldap->fetch();
546         if($this->dn != $attrs['dn']) {
547           $message[]= _("There's already a mime type with this 'Name'.");
548         }
549       }
550     }else{
551       $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))","ou=mime,".$this->base,array("cn"));
552       if ($ldap->count()){
553         $attrs = $ldap->fetch();
554         if($this->dn != $attrs['dn']) {
555           $message[]= _("There's already an mime with this 'Name'.");
556         }
557       }
558     }
560     return($message);
561   }
563   /** Helper functions **/
565   /* Set a new picture */       
566   function set_new_picture($filename)
567   {
568     if (empty($filename)){
569       $filename= "./images/default_icon.png";
570       $this->use_gotoMimeIcon= "*removed*";
571     }else{
572       $this->use_gotoMimeIcon= $filename;
573     }
575     if (file_exists($filename)){
576       $fd = fopen ($filename, "rb");
577       $this->iconData= fread ($fd, filesize ($filename));
578       $_SESSION['binary']= $this->iconData;
579       $_SESSION['binarytype']= "image/jpeg";
580       fclose ($fd);
581     }
582   }
584   /* Get picture link */
585   function get_picture()
586   {
587     $_SESSION['binary']= $this->iconData;
588     $_SESSION['binarytype']= "image/jpeg";
589     return("getbin.php");
590   }
592   /* Transports the given Arraykey one position up*/
593   function ArrayUp($atr,$attrs)
594   {
595     $ret = $attrs;
596     $pos = $this->getpos($atr,$attrs) ;
597     $cn = count($attrs);
598     if(!(($pos == -1)||($pos == 1))){
599       $before = array_slice($attrs,0,($pos-2));
600       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
601       $unten  = array_slice($attrs,$pos);
602       $ret = array();
603       $ret = $this->combineArrays($before,$mitte,$unten);
604     }
605     return($ret);
606   }
609   /* Transports the given Arraykey one position down*/
610   function ArrayDown($atr,$attrs)
611   {
612     $ret = $attrs;
613     $pos = $this->getpos($atr,$attrs) ;
614     $cn = count($attrs);
615     if(!(($pos == -1)||($pos == $cn))){
616       $before = array_slice($attrs,0,($pos-1));
617       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
618       $unten  = array_slice($attrs,($pos+1));
619       $ret = array();
620       $ret = $this->combineArrays($before,$mitte,$unten);
621     }
622     return($ret);
623   }
626   /* return the position of the element in the array */
627   function getpos($atr,$attrs)
628   {
629     $i = 0;
630     foreach($attrs as $attr => $name)    {
631       $i++;
632       if($attr == $atr){
633         return($i);
634       }
635     }
636     return(-1);
637   }
640   /* Remove this element from array */
641   function ArrayRemove($key,$array,$reorder = false)    
642   {
643     if(isset($array[$key])){
644       unset($array[$key]);
645       if($reorder){
646         $tmp = array();
647         foreach($array as $entry){
648           $tmp[] = $entry;
649         }
650         $array = $tmp;
651       }
652     }   
653     return($array);
654   }
657   /* Combine new array */
658   function combineArrays($ar0,$ar1,$ar2)
659   {
660     $ret = array();
661     if(is_array($ar0))
662       foreach($ar0 as $ar => $a){
663         $ret[]=$a;
664       }
665     if(is_array($ar1))
666       foreach($ar1 as $ar => $a){
667         $ret[]=$a;
668       }
669     if(is_array($ar2))
670       foreach($ar2 as $ar => $a){
671         $ret[]=$a;
672       }
673     return($ret);
674   }
677   /* Return a dialog with all fields that must be changed, 
678      if we want to copy this entry */
679   function getCopyDialog()
680   {
681     $str = "";
683     $smarty = get_smarty();
684     $smarty->assign("cn",               $this->cn);
685     $smarty->assign("description",  $this->description);
686     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
688     $ret = array();
689     $ret['string'] = $str;
690     $ret['status'] = "";
691     return($ret);
692   }
695   /* Save all */
696   function saveCopyDialog()
697   {
698     $attrs = array("cn","description");
699     foreach($attrs as $attr){
700       if(isset($_POST[$attr])){
701         $this->$attr = $_POST[$attr];
702       }
703     }
704   }
706   /* Return plugin informations for acl handling  */ 
707   static function plInfo()
708   {
709     return (array(
710           "plShortName"   => _("Generic"),
711           "plDescription" => _("Mime type generic"),
712           "plSelfModify"  => FALSE,
713           "plDepends"     => array(),
714           "plPriority"    => 0,
715           "plSection"     => array("administration"),
716           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
717                                                         "objectClass"  => "gotoMimeType")),
718           "plProvidedAcls"=> array(
719             "cn"                          => _("Name"),
720             "gotoMimeGroup"               => _("Mime group"),
721             "description"                 => _("Description"),
722             "base"                        => _("Base"),
723             "gotoMimeApplication"         => _("Application"),
724             "gotoMimeLeftClickAction"     => _("Left click action"),
725             "gotoMimeIcon"                => _("Icon"),
726             "gotoMimeFilePattern"         => _("File patterns"),
727             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
728           ));
730   }
732   function PrepareForCopyPaste($source)
733   {
734     plugin::PrepareForCopyPaste($source);
736     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
738     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
739       $use_attr     = "use_".$name;
740       if(isset($this->$use_attr)){
741         $this->$use_attr= $source_o->$use_attr;
742       }
743       $this->$name = $source_o->$name;
744     } 
745     foreach($this->attributes as $name){
746       $this->$name = $source_o->$name;
747     }
749     if($this->iconData){
750       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
751     }
752   }
754 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
755 ?>