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