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