Code

c5d52cf27d5a8d639de01f0ab5153e2b6d4d2414
[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                  = "";
53   function mimetype(&$config,$dn= NULL)
54   {
55     plugin::plugin ($config, $dn);
57     /* Save original dn */
58     $this->orig_dn = $dn;       
60     /* get gotoMimeLeftClickActions I/E/Q */
61     if(isset($this->gotoMimeLeftClickAction)){
62       $str = $this->gotoMimeLeftClickAction;
63       for($i = 0 ; $i < strlen($str) ; $i ++ ){
64         $varna = "gotoMimeLeftClickAction_". $str[$i];
65         if(isset($this->$varna)){
66           $this->$varna = true;
67         }
68       }
69     }
71     /* Create list of defined applications in GOsa */
72     $ldap = $this->config->get_ldap_link();
73     $ldap->cd($this->config->current['BASE']);
74     $ldap->search("(&(objectClass=gosaApplication)(cn=*))",array('cn'));
75     $this->ApplicationList = array();
76     while($attrs = $ldap->fetch()){
77       $this->ApplicationList[$attrs['cn'][0]] = $attrs['cn'][0];
78     }
80     /* If both radio buttons arn't set, set option I */
81     if(!$this->gotoMimeLeftClickAction_I && !$this->gotoMimeLeftClickAction_E){
82       $this->gotoMimeLeftClickAction_I = true;
83     }
85     /* Get list of array attributes */
86     foreach(array("gotoMimeFilePattern") as $attr){
87       $this->$attr = array();
88       if(isset($this->attrs[$attr])){
89         $tmp = array();
90         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
91           $str = $this->attrs[$attr][$i];
92           $tmp[] = $str;
93         }
94         $use_attr = "use_".$attr;
95         $this->$use_attr = $tmp;
96       }
97     }
99     /* Get list of array attributes with priority tag ( Test|32 )*/
100     foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){
101       $this->$attr = array();
102       if(isset($this->attrs[$attr])){
103         $tmp = array();
104         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
105           $str = $this->attrs[$attr][$i];
106           $tmp2= split("\|",$str);
108           if(count($tmp2) == 2){
109             $name = $tmp2[0];
110             $prio = $tmp2[1];
111             $tmp[$prio] = $name;
112           }
113         }
114         ksort($tmp);
115         $use_attr = "use_".$attr;
116         $this->$use_attr = $tmp;
117       }
118     }
120     /* Set base */      
121     if ($this->dn == "new"){
122       if(session::is_set('CurrentMainBase')){
123         $this->base= session::get('CurrentMainBase');
124       }else{
125         $ui= get_userinfo();
126         $this->base= dn2base($ui->dn);
127       }
128     } else {
129       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
130     }
132     /* Get icon data */
133     if(isset($this->attrs['gotoMimeIcon'])){
134       $ldap = $this->config->get_ldap_link();
135       $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon");
136       $this->saved_attributes['gotoMimeIcon'] = $this->iconData;
137     }
138     if ($this->iconData == ""){
139       $this->set_new_picture("");
140     }
141     session::set('binary',$this->iconData);
142     session::set('binarytype',"image/jpeg");
143   }
146   function execute()
147   {
148     $smarty = get_smarty();
150     if(!$this->view_logged){
151       $this->view_logged =TRUE;
152       new log("view","mimetypes/".get_class($this),$this->dn);
153     }
155     $tmp = $this->plInfo();
156     foreach($tmp['plProvidedAcls'] as $name => $translation){
157       $smarty->assign($name."ACL",$this->getacl($name));
158     }
160     /* Base select dialog */
161     $once = true;
162     foreach($_POST as $name => $value){
163       if(preg_match("/^chooseBase/",$name) && $once){
164         $once = false;
165         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
166         $this->dialog->setCurrentBase($this->base);
167       }
168     }
170     /* Dialog handling */
171     if(is_object($this->dialog)){
173       /* Must be called before save_object */
174       $this->dialog->save_object();
176       if($this->dialog->isClosed()){
177         $this->dialog = false;
178       }elseif($this->dialog->isSelected()){
180         /* A new base was selected, check if it is a valid one */
181         $tmp = $this->get_allowed_bases();
182         if(isset($tmp[$this->dialog->isSelected()])){
183           $this->base = $this->dialog->isSelected();
184         }
186         $this->dialog= false;
187       }else{
188         return($this->dialog->execute());
189       }
190     }
192     /* Check Posts */
193     $posts = array(     
194         "/^Pattern_SortUp_/"    => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
195         "/^Pattern_SortDown_/"  => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
196         "/^Pattern_Remove_/"    => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
197         "/^Apps_SortUp_/"               => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
198         "/^Apps_SortDown_/"     => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
199         "/^Apps_Remove_/"               => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
200         "/^EApps_SortUp_/"              => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
201         "/^EApps_SortDown_/"    => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
202         "/^EApps_Remove_/"              => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
203     $once = true;
205     /* Walk through posts and try to find some commands for us. */
206     foreach($_POST as $name => $value){
208       /* Walk through possible commands */
209       foreach($posts as $regex => $action){
211         /* Check if there is a command posted */
212         if(preg_match($regex,$name) && $once){
213           $once = false;
215           /* Get action vars */
216           $func                 = $action['Func'];              // Get function name 
217           $attr                 = $action['Attr'];              // Get attribute name
219           /* Get entry id */
220           $s_entry      = preg_replace($regex,"",$name);
221           $s_entry      = preg_replace("/_[xy]$/","",$s_entry); 
223           /* Execute a command with the given attribute and entry 
224              e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
225           if($this->acl_is_writeable($attr)){
226             $this->$attr= $this->$func($s_entry,$this->$attr,true);                                      
227           }
228         }
229       }
230     }
232     /* Set a new icon was requested */
233     if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
234       $this->set_new_picture($_FILES['picture_file']['tmp_name']);              
235     }
237     /* Add gotoMimeFilePattern */
238     if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
239       if($this->acl_is_writeable("gotoMimeFilePattern")){
240         $str = $_POST['NewFilePattern'];
241         if(!empty($str)){
242           $this->use_gotoMimeFilePattern[] = $str;
243         }
244       }
245     }   
247     /* Add gotoMimeFilePattern */
248     if(isset($_POST['AddNewApplication']) && 
249             (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
250       if($this->acl_is_writeable("gotoMimeApplication")){
251         $str = "";
252         if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
253           $str = get_post("NewApplicationSelect");
254         }
255         if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
256           $str = get_post("NewApplication");
257         }
258         if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
259           $this->use_gotoMimeApplication[] = $str;
260         }
261       }
262     }   
264     /* Add embedded application 
265      *  - From input or from select box 
266      */
267     if(isset($_POST['AddNewEmbeddedApplication']) && 
268             (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
269       if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
270         $str = "";
271         if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
272           $str = get_post('NewEmbeddedApplicationSelect');
273         }
274         if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
275           $str = get_post('NewEmbeddedApplication');
276         }
277         if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
278           $this->use_gotoMimeEmbeddedApplication[] = $str;
279         }
280       }
281     }   
283     /* Create divlists */
284     $DivPatterns        = new divSelectBox("gotoMimePatterns");
285     $DivApps            = new divSelectBox("gotoMimeApplications");
286     $DivEApps           = new divSelectBox("gotoMimeEmbeddedApplications");
287     $DivPatterns        -> SetHeight(100);
288     $DivApps            -> SetHeight(100);
289     $DivEApps           -> SetHeight(100);
292     if($this->acl_is_writeable("gotoMimeFilePattern")){
293       $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'    class='center'  name='Pattern_SortUp_%s' >&nbsp;
294       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Pattern_SortDown_%s'>&nbsp;
295       <input type='image' src='images/lists/trash.png'  class='center'  name='Pattern_Remove_%s'>";
296     }else{
297       $Pattern_Actions= "";     
298     }
300     if($this->acl_is_writeable("gotoMimeApplication")){
301       $Apps_Actions     = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
302       <input type='image' src='images/lists/sort-down.png'      class='center'  name='Apps_SortDown_%s'>&nbsp;
303       <input type='image' src='images/lists/trash.png'  class='center'  name='Apps_Remove_%s'>";
304     }else{
305       $Apps_Actions= "";        
306     }
308     if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
309       $EApps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
310       <input type='image' src='images/lists/sort-down.png'      class='center'  name='EApps_SortDown_%s'>&nbsp;
311       <input type='image' src='images/lists/trash.png'  class='center'  name='EApps_Remove_%s'>";
312     }else{
313       $EApps_Actions= "";       
314     }
316     /* Before adding some entries check acls */
317     if($this->acl_is_readable("gotoMimeFilePattern")){
318       foreach($this->use_gotoMimeFilePattern as $key => $pattern){
319         $field1 = array("string" => $pattern);
320         $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
321         $fields = array($field1,$field2);
322         $DivPatterns -> AddEntry($fields);
323       }                 
324     }
326     if($this->acl_is_readable("gotoMimeApplication")){
327       foreach($this->use_gotoMimeApplication as $key => $pattern){
328         $field1 = array("string" => $pattern);
329         $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
330         $fields = array($field1,$field2);
331         $DivApps -> AddEntry($fields);
332       }                 
333     }                   
334     if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
335       foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
336         $field1 = array("string" => $pattern);
337         $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
338         $fields = array($field1,$field2);
339         $DivEApps -> AddEntry($fields);
340       }
341     }                   
342     $smarty->assign("bases",                                            $this->get_allowed_bases());            
343     $smarty->assign("base_select",                                      $this->base);           
344     $smarty->assign("isReleaseMimeType",                        $this->is_release());
345     $smarty->assign("gotoMimeFilePatterns",                     $DivPatterns->DrawList());
346     $smarty->assign("gotoMimeApplications",                     $DivApps->DrawList());
347     $smarty->assign("gotoMimeEmbeddedApplications",     $DivEApps->DrawList());
349     $smarty->assign("ApplicationList",$this->ApplicationList);
350   
351     /* Assign class vars to smarty */
352     foreach($this->attributes as $attr){
353       $smarty->assign($attr,$this->$attr);
354     }   
356     /* Assign additional vars that are not included in attributes*/
357     foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
358       $smarty->assign($attr,$this->$attr);
359     }   
361     /* Assign select box options */
362     $smarty->assign("gotoMimeGroups",$this->MimeGroups);
363     $smarty->assign("gotoMimeIcon"      ,$this->get_picture());
364     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
365   }
368   function save_object()
369   {
370     if(isset($_POST['MimeGeneric'])){
372       /* Create a base backup and reset the
373          base directly after calling plugin::save_object();
374          Base will be set seperatly a few lines below */
375       $base_tmp = $this->base;
376       plugin::save_object();
377       $this->base = $base_tmp;
378   
379       /* Only save base if we are not in release mode */
380       if(!$this->is_release()){
382         /* Set new base if allowed */
383         $tmp = $this->get_allowed_bases();
384         if(isset($_POST['base'])){
385           if(isset($tmp[$_POST['base']])){
386             $this->base= $_POST['base'];
387           }
388         }
390       }
392       /* Save radio buttons */
393       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
394         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
395           $chr = $_POST['gotoMimeLeftClickAction_IE'];
396           if($chr == "E"){
397             $this->gotoMimeLeftClickAction_E = true;
398             $this->gotoMimeLeftClickAction_I = false;
399           }else{
400             $this->gotoMimeLeftClickAction_E = false;
401             $this->gotoMimeLeftClickAction_I = true;
402           }
403         }
404         if(isset($_POST['gotoMimeLeftClickAction_Q'])){
405           $this->gotoMimeLeftClickAction_Q = true;
406         }else{
407           $this->gotoMimeLeftClickAction_Q = false;
408         }
409       }
410     }
411   }
414   /* save current changes */
415   function save()
416   {
417     /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */    
418     $arr = array ("E","I","Q");
419     $str = "";
420     foreach ($arr as $Chr){
421       $var = "gotoMimeLeftClickAction_".$Chr;
422       if($this->$var){
423         $str .= $Chr;
424       }
425     }
426     $this->gotoMimeLeftClickAction = $str;
428     /* Create array entries with priority tag ( Test|3 )*/
429     foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
430       $i                                = 0;
431       $use_attr                 = "use_".$attr;
432       $tmp                      = array();
433       $this->$attr      = array();
434       foreach($this->$use_attr as $entry){
435         $tmp[] = $entry."|".$i ++;
436       }
437       $this->$attr = $tmp;
438     }
440     /* Create array entries */
441     foreach(array("gotoMimeFilePattern") as $attr){
442       $i                                = 0;
443       $use_attr                 = "use_".$attr;
444       $tmp                      = array();
445       $this->$attr      = array();
446       foreach($this->$use_attr as $entry){
447         $tmp[] = $entry;
448       }
449       $this->$attr = $tmp;
450     }
452     /* Remove Icon if requested  */
453     if($this->use_gotoMimeIcon != "*removed*"){
454       $this->gotoMimeIcon = $this->iconData;
455     }else{
456       $this->gotoMimeIcon = "";
457     }
459     plugin::save();
461     /* If this is a newly created object, skip storing those 
462        attributes that contain an empty array */
463     if($this->orig_dn == "new"){
464       foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
465         if(!count($this->$attr)){
466           unset($this->attrs[$attr]);
467         }
468       }
469     }
471     $ldap = $this->config->get_ldap_link();
472     $ldap-> cd ( $this->config->current['BASE']);
473     $ldap->cat($this->dn);
474     if($ldap->count()){
475       $ldap->cd($this->dn);
476       $this->cleanup();
477       $ldap->modify($this->attrs);
478       new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
479     }else{
480       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
481       $ldap->cd($this->dn);
482       $ldap->add($this->attrs);
483       new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
484     }
485     if (!$ldap->success()){
486       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
487     }
488   }
491   /* Remove current mime type */
492   function remove_from_parent()
493   {
494     plugin::remove_from_parent();
495     $ldap = $this->config->get_ldap_link();
496     $ldap->rmDir($this->dn);
497     if (!$ldap->success()){
498       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
499     }
500     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
502     /* Optionally execute a command after we're done */
503     $this->handle_post_events("remove");
505     /* Delete references to object groups */
506     $ldap->cd ($this->config->current['BASE']);
507     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
508     while ($ldap->fetch()){
509       $og= new ogroup($this->config, $ldap->getDN());
510       unset($og->member[$this->dn]);
511       $og->save ();
512       if (!$ldap->success()){
513         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
514       }
515     }
516   }
519   /* Check given values */
520   function check()
521   {
522     $message = plugin::check();
523     if(empty($this->cn)){
524       $message[] = msgPool::required(_("Name"));
525     }
526     if(!count($this->use_gotoMimeFilePattern)){
527       $message[] = msgPool::required(_("File pattern"));
528     }
530     /* Check if there is already a mime type with this cn */
531     $ldap = $this->config->get_ldap_link();
532     $ldap->cd($this->config->current["BASE"]);
534     if($this->is_release()){
535       $base = $this->parent->parent->mime_release;
536     }else{
537       $base = get_ou("mimetypeou").$this->base;
538     }
540     $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
541     if($ldap->count()){
542       $attrs = $ldap->fetch();
543       if($this->dn != $attrs['dn']) {
544         $message[]= msgPool::duplicated("cn");
545       }
546     }
547     return($message);
548   }
551   /** Helper functions **/
553   /* Set a new picture */       
554   function set_new_picture($filename)
555   {
556     if (empty($filename)){
557       $filename= "./images/default_icon.png";
558       $this->use_gotoMimeIcon= "*removed*";
559     }else{
560       $this->use_gotoMimeIcon= $filename;
561     }
563     if (file_exists($filename)){
564       $fd = fopen ($filename, "rb");
565       $this->iconData= fread ($fd, filesize ($filename));
566       session::set('binary',$this->iconData);
567       session::set('binarytype',"image/jpeg");
568       fclose ($fd);
569     }
570   }
572   /* Get picture link */
573   function get_picture()
574   {
575     session::set('binary',$this->iconData);
576     session::set('binarytype',"image/jpeg");
577     return("getbin.php");
578   }
580   /* Transports the given Arraykey one position up*/
581   function ArrayUp($atr,$attrs)
582   {
583     $ret = $attrs;
584     $pos = $this->getpos($atr,$attrs) ;
585     $cn = count($attrs);
586     if(!(($pos == -1)||($pos == 1))){
587       $before = array_slice($attrs,0,($pos-2));
588       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
589       $unten  = array_slice($attrs,$pos);
590       $ret = array();
591       $ret = $this->combineArrays($before,$mitte,$unten);
592     }
593     return($ret);
594   }
597   /* Transports the given Arraykey one position down*/
598   function ArrayDown($atr,$attrs)
599   {
600     $ret = $attrs;
601     $pos = $this->getpos($atr,$attrs) ;
602     $cn = count($attrs);
603     if(!(($pos == -1)||($pos == $cn))){
604       $before = array_slice($attrs,0,($pos-1));
605       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
606       $unten  = array_slice($attrs,($pos+1));
607       $ret = array();
608       $ret = $this->combineArrays($before,$mitte,$unten);
609     }
610     return($ret);
611   }
614   /* return the position of the element in the array */
615   function getpos($atr,$attrs)
616   {
617     $i = 0;
618     foreach($attrs as $attr => $name)    {
619       $i++;
620       if($attr == $atr){
621         return($i);
622       }
623     }
624     return(-1);
625   }
628   /* Remove this element from array */
629   function ArrayRemove($key,$array,$reorder = false)    
630   {
631     if(isset($array[$key])){
632       unset($array[$key]);
633       if($reorder){
634         $tmp = array();
635         foreach($array as $entry){
636           $tmp[] = $entry;
637         }
638         $array = $tmp;
639       }
640     }   
641     return($array);
642   }
645   /* Combine new array */
646   function combineArrays($ar0,$ar1,$ar2)
647   {
648     $ret = array();
649     if(is_array($ar0))
650       foreach($ar0 as $ar => $a){
651         $ret[]=$a;
652       }
653     if(is_array($ar1))
654       foreach($ar1 as $ar => $a){
655         $ret[]=$a;
656       }
657     if(is_array($ar2))
658       foreach($ar2 as $ar => $a){
659         $ret[]=$a;
660       }
661     return($ret);
662   }
665   /* Return a dialog with all fields that must be changed, 
666      if we want to copy this entry */
667   function getCopyDialog()
668   {
669     $str = "";
671     $smarty = get_smarty();
672     $smarty->assign("cn",               $this->cn);
673     $smarty->assign("description",  $this->description);
674     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
676     $ret = array();
677     $ret['string'] = $str;
678     $ret['status'] = "";
679     return($ret);
680   }
683   /* Save all */
684   function saveCopyDialog()
685   {
686     $attrs = array("cn","description");
687     foreach($attrs as $attr){
688       if(isset($_POST[$attr])){
689         $this->$attr = $_POST[$attr];
690       }
691     }
692   }
694   /* Return plugin informations for acl handling  */ 
695   static function plInfo()
696   {
697     return (array(
698           "plShortName"   => _("Generic"),
699           "plDescription" => _("Mime type generic"),
700           "plSelfModify"  => FALSE,
701           "plDepends"     => array(),
702           "plPriority"    => 0,
703           "plSection"     => array("administration"),
704           "plCategory"    => array("mimetypes" => array("description"  => _("Mime types"),
705                                                         "objectClass"  => "gotoMimeType")),
706           "plProvidedAcls"=> array(
707             "cn"                          => _("Name"),
708             "gotoMimeGroup"               => _("Mime group"),
709             "description"                 => _("Description"),
710             "base"                        => _("Base"),
711             "gotoMimeApplication"         => _("Application"),
712             "gotoMimeLeftClickAction"     => _("Left click action"),
713             "gotoMimeIcon"                => _("Icon"),
714             "gotoMimeFilePattern"         => _("File patterns"),
715             "gotoMimeEmbeddedApplication" => _("Embedded applications"))
716           ));
718   }
721   function is_release()
722   {
723     if(is_object($this->parent->parent)){
724       return($this->parent->parent->IsReleaseManagementActivated());
725     }else{
726       /* Check if we should enable the release selection */
727       $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
728       if(!empty($tmp)){
729         return(true);
730       }
731     }
732     return(FALSE);
733   }
736   function PrepareForCopyPaste($source)
737   {
738     plugin::PrepareForCopyPaste($source);
740     $source_o = new mimetype($this->config,$source['dn'],$this->parent);
742     foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
743       $use_attr     = "use_".$name;
744       if(isset($this->$use_attr)){
745         $this->$use_attr= $source_o->$use_attr;
746       }
747       $this->$name = $source_o->$name;
748     } 
749     foreach($this->attributes as $name){
750       $this->$name = $source_o->$name;
751     }
753     if($this->iconData){
754       $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
755     }
756   }
758 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
759 ?>