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 /* Mime type release mode */
41 var $isReleaseMimeType = false;
43 /* These vars will be copied too, if you use copy&paste mode */
44 var $CopyPasteVars = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
45 "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
47 var $view_logged = FALSE;
49 /* Select options */
50 var $MimeGroups = array("application","audio","chemical","image","inode","message","model",
51 "multipart","text","video","x-conference","x-world");
53 /* Orig_Dn is used to verify if this object is new or only edited */
54 var $orig_dn = "";
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= split("\|",$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 /* Check if release Management is enabled */
124 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
125 if(!empty($tmp)) {
126 $this->isReleaseMimeType= true;
127 }
129 /* Set base */
130 if ($this->dn == "new"){
131 if(session::is_set('CurrentMainBase')){
132 $this->base= session::get('CurrentMainBase');
133 }else{
134 $ui= get_userinfo();
135 $this->base= dn2base($ui->dn);
136 }
137 } else {
138 $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
139 }
141 /* Get icon data */
142 if(isset($this->attrs['gotoMimeIcon'])){
143 $ldap = $this->config->get_ldap_link();
144 $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon");
145 $this->saved_attributes['gotoMimeIcon'] = $this->iconData;
146 }
147 if ($this->iconData == ""){
148 $this->set_new_picture("");
149 }
150 session::set('binary',$this->iconData);
151 session::set('binarytype',"image/jpeg");
152 }
155 function execute()
156 {
157 $smarty = get_smarty();
159 if(!$this->view_logged){
160 $this->view_logged =TRUE;
161 new log("view","mimetypes/".get_class($this),$this->dn);
162 }
164 $tmp = $this->plInfo();
165 foreach($tmp['plProvidedAcls'] as $name => $translation){
166 $smarty->assign($name."ACL",$this->getacl($name));
167 }
169 /* Base select dialog */
170 $once = true;
171 foreach($_POST as $name => $value){
172 if(preg_match("/^chooseBase/",$name) && $once){
173 $once = false;
174 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
175 $this->dialog->setCurrentBase($this->base);
176 }
177 }
179 /* Dialog handling */
180 if(is_object($this->dialog)){
182 /* Must be called before save_object */
183 $this->dialog->save_object();
185 if($this->dialog->isClosed()){
186 $this->dialog = false;
187 }elseif($this->dialog->isSelected()){
189 /* A new base was selected, check if it is a valid one */
190 $tmp = $this->get_allowed_bases();
191 if(isset($tmp[$this->dialog->isSelected()])){
192 $this->base = $this->dialog->isSelected();
193 }
195 $this->dialog= false;
196 }else{
197 return($this->dialog->execute());
198 }
199 }
201 /* Check Posts */
202 $posts = array(
203 "/^Pattern_SortUp_/" => array("Action" => "Pattern_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeFilePattern"),
204 "/^Pattern_SortDown_/" => array("Action" => "Pattern_SortDown","Func" => "ArrayDown", "Attr" => "use_gotoMimeFilePattern"),
205 "/^Pattern_Remove_/" => array("Action" => "Pattern_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
206 "/^Apps_SortUp_/" => array("Action" => "Apps_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeApplication"),
207 "/^Apps_SortDown_/" => array("Action" => "Apps_SortDown", "Func" => "ArrayDown", "Attr" => "use_gotoMimeApplication"),
208 "/^Apps_Remove_/" => array("Action" => "Apps_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
209 "/^EApps_SortUp_/" => array("Action" => "EApps_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeEmbeddedApplication"),
210 "/^EApps_SortDown_/" => array("Action" => "EApps_SortDown", "Func" => "ArrayDown", "Attr" => "use_gotoMimeEmbeddedApplication"),
211 "/^EApps_Remove_/" => array("Action" => "EApps_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));
212 $once = true;
214 /* Walk through posts and try to find some commands for us. */
215 foreach($_POST as $name => $value){
217 /* Walk through possible commands */
218 foreach($posts as $regex => $action){
220 /* Check if there is a command posted */
221 if(preg_match($regex,$name) && $once){
222 $once = false;
224 /* Get action vars */
225 $func = $action['Func']; // Get function name
226 $attr = $action['Attr']; // Get attribute name
228 /* Get entry id */
229 $s_entry = preg_replace($regex,"",$name);
230 $s_entry = preg_replace("/_[xy]$/","",$s_entry);
232 /* Execute a command with the given attribute and entry
233 e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
234 if($this->acl_is_writeable($attr)){
235 $this->$attr= $this->$func($s_entry,$this->$attr,true);
236 }
237 }
238 }
239 }
241 /* Set a new icon was requested */
242 if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
243 $this->set_new_picture($_FILES['picture_file']['tmp_name']);
244 }
246 /* Add gotoMimeFilePattern */
247 if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
248 if($this->acl_is_writeable("gotoMimeFilePattern")){
249 $str = $_POST['NewFilePattern'];
250 if(!empty($str)){
251 $this->use_gotoMimeFilePattern[] = $str;
252 }
253 }
254 }
256 /* Add gotoMimeFilePattern */
257 if(isset($_POST['AddNewApplication']) &&
258 (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
259 if($this->acl_is_writeable("gotoMimeApplication")){
260 $str = "";
261 if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
262 $str = get_post("NewApplicationSelect");
263 }
264 if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
265 $str = get_post("NewApplication");
266 }
267 if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
268 $this->use_gotoMimeApplication[] = $str;
269 }
270 }
271 }
273 /* Add embedded application
274 * - From input or from select box
275 */
276 if(isset($_POST['AddNewEmbeddedApplication']) &&
277 (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
278 if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
279 $str = "";
280 if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
281 $str = get_post('NewEmbeddedApplicationSelect');
282 }
283 if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
284 $str = get_post('NewEmbeddedApplication');
285 }
286 if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
287 $this->use_gotoMimeEmbeddedApplication[] = $str;
288 }
289 }
290 }
292 /* Create divlists */
293 $DivPatterns = new divSelectBox("gotoMimePatterns");
294 $DivApps = new divSelectBox("gotoMimeApplications");
295 $DivEApps = new divSelectBox("gotoMimeEmbeddedApplications");
296 $DivPatterns -> SetHeight(100);
297 $DivApps -> SetHeight(100);
298 $DivEApps -> SetHeight(100);
301 if($this->acl_is_writeable("gotoMimeFilePattern")){
302 $Pattern_Actions= " <input type='image' src='images/sort_up.png' class='center' name='Pattern_SortUp_%s' >
303 <input type='image' src='images/sort_down.png' class='center' name='Pattern_SortDown_%s'>
304 <input type='image' src='images/edittrash.png' class='center' name='Pattern_Remove_%s'>";
305 }else{
306 $Pattern_Actions= "";
307 }
309 if($this->acl_is_writeable("gotoMimeApplication")){
310 $Apps_Actions = " <input type='image' src='images/sort_up.png' class='center' name='Apps_SortUp_%s' >
311 <input type='image' src='images/sort_down.png' class='center' name='Apps_SortDown_%s'>
312 <input type='image' src='images/edittrash.png' class='center' name='Apps_Remove_%s'>";
313 }else{
314 $Apps_Actions= "";
315 }
317 if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
318 $EApps_Actions = " <input type='image' src='images/sort_up.png' class='center' name='EApps_SortUp_%s' >
319 <input type='image' src='images/sort_down.png' class='center' name='EApps_SortDown_%s'>
320 <input type='image' src='images/edittrash.png' class='center' name='EApps_Remove_%s'>";
321 }else{
322 $EApps_Actions= "";
323 }
325 /* Before adding some entries check acls */
326 if($this->acl_is_readable("gotoMimeFilePattern")){
327 foreach($this->use_gotoMimeFilePattern as $key => $pattern){
328 $field1 = array("string" => $pattern);
329 $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
330 $fields = array($field1,$field2);
331 $DivPatterns -> AddEntry($fields);
332 }
333 }
335 if($this->acl_is_readable("gotoMimeApplication")){
336 foreach($this->use_gotoMimeApplication as $key => $pattern){
337 $field1 = array("string" => $pattern);
338 $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
339 $fields = array($field1,$field2);
340 $DivApps -> AddEntry($fields);
341 }
342 }
343 if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
344 foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
345 $field1 = array("string" => $pattern);
346 $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
347 $fields = array($field1,$field2);
348 $DivEApps -> AddEntry($fields);
349 }
350 }
351 $smarty->assign("bases", $this->get_allowed_bases());
352 $smarty->assign("base_select", $this->base);
353 $smarty->assign("isReleaseMimeType", $this->isReleaseMimeType);
354 $smarty->assign("gotoMimeFilePatterns", $DivPatterns->DrawList());
355 $smarty->assign("gotoMimeApplications", $DivApps->DrawList());
356 $smarty->assign("gotoMimeEmbeddedApplications", $DivEApps->DrawList());
358 $smarty->assign("ApplicationList",$this->ApplicationList);
360 /* Assign class vars to smarty */
361 foreach($this->attributes as $attr){
362 $smarty->assign($attr,$this->$attr);
363 }
365 /* Assign additional vars that are not included in attributes*/
366 foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
367 $smarty->assign($attr,$this->$attr);
368 }
370 /* Assign select box options */
371 $smarty->assign("gotoMimeGroups",$this->MimeGroups);
372 $smarty->assign("gotoMimeIcon" ,$this->get_picture());
373 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
374 }
377 function save_object()
378 {
379 if(isset($_POST['MimeGeneric'])){
381 /* Create a base backup and reset the
382 base directly after calling plugin::save_object();
383 Base will be set seperatly a few lines below */
384 $base_tmp = $this->base;
385 plugin::save_object();
386 $this->base = $base_tmp;
388 /* Only save base if we are not in release mode */
389 if(!$this->isReleaseMimeType){
391 /* Set new base if allowed */
392 $tmp = $this->get_allowed_bases();
393 if(isset($_POST['base'])){
394 if(isset($tmp[$_POST['base']])){
395 $this->base= $_POST['base'];
396 }
397 }
399 }
401 /* Save radio buttons */
402 if($this->acl_is_writeable("gotoMimeLeftClickAction")){
403 if(isset($_POST['gotoMimeLeftClickAction_IE'])){
404 $chr = $_POST['gotoMimeLeftClickAction_IE'];
405 if($chr == "E"){
406 $this->gotoMimeLeftClickAction_E = true;
407 $this->gotoMimeLeftClickAction_I = false;
408 }else{
409 $this->gotoMimeLeftClickAction_E = false;
410 $this->gotoMimeLeftClickAction_I = true;
411 }
412 }
413 if(isset($_POST['gotoMimeLeftClickAction_Q'])){
414 $this->gotoMimeLeftClickAction_Q = true;
415 }else{
416 $this->gotoMimeLeftClickAction_Q = false;
417 }
418 }
419 }
420 }
423 /* save current changes */
424 function save()
425 {
426 /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */
427 $arr = array ("E","I","Q");
428 $str = "";
429 foreach ($arr as $Chr){
430 $var = "gotoMimeLeftClickAction_".$Chr;
431 if($this->$var){
432 $str .= $Chr;
433 }
434 }
435 $this->gotoMimeLeftClickAction = $str;
437 /* Create array entries with priority tag ( Test|3 )*/
438 foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
439 $i = 0;
440 $use_attr = "use_".$attr;
441 $tmp = array();
442 $this->$attr = array();
443 foreach($this->$use_attr as $entry){
444 $tmp[] = $entry."|".$i ++;
445 }
446 $this->$attr = $tmp;
447 }
449 /* Create array entries */
450 foreach(array("gotoMimeFilePattern") as $attr){
451 $i = 0;
452 $use_attr = "use_".$attr;
453 $tmp = array();
454 $this->$attr = array();
455 foreach($this->$use_attr as $entry){
456 $tmp[] = $entry;
457 }
458 $this->$attr = $tmp;
459 }
461 /* Remove Icon if requested */
462 if($this->use_gotoMimeIcon != "*removed*"){
463 $this->gotoMimeIcon = $this->iconData;
464 }else{
465 $this->gotoMimeIcon = "";
466 }
468 plugin::save();
470 /* If this is a newly created object, skip storing those
471 attributes that contain an empty array */
472 if($this->orig_dn == "new"){
473 foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
474 if(!count($this->$attr)){
475 unset($this->attrs[$attr]);
476 }
477 }
478 }
480 $ldap = $this->config->get_ldap_link();
481 $ldap-> cd ( $this->config->current['BASE']);
482 $ldap->cat($this->dn);
483 if($ldap->count()){
484 $ldap->cd($this->dn);
485 $this->cleanup();
486 $ldap->modify($this->attrs);
487 new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
488 }else{
489 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
490 $ldap->cd($this->dn);
491 $ldap->add($this->attrs);
492 new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
493 }
494 if (!$ldap->success()){
495 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
496 }
497 }
500 /* Remove current mime type */
501 function remove_from_parent()
502 {
503 plugin::remove_from_parent();
504 $ldap = $this->config->get_ldap_link();
505 $ldap->rmDir($this->dn);
506 if (!$ldap->success()){
507 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
508 }
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=".LDAP::prepare4filter($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 if (!$ldap->success()){
522 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
523 }
524 }
525 }
528 /* Check given values */
529 function check()
530 {
531 $message = plugin::check();
532 if(empty($this->cn)){
533 $message[] = msgPool::required(_("Name"));
534 }
535 if(!count($this->use_gotoMimeFilePattern)){
536 $message[] = msgPool::required(_("File pattern"));
537 }
539 /* Check if there is already a mime type with this cn */
540 $ldap = $this->config->get_ldap_link();
541 $ldap->cd($this->config->current["BASE"]);
543 $mimefilter = session::get('mimefilter');
545 if($this->isReleaseMimeType && (isset($mimefilter['release']))){
546 $baseDn = str_replace($this->config->current['BASE'],$this->base,$mimefilter['release']);
547 $baseDn = preg_replace("/".get_ou('mimetypeou').".*/",get_ou('mimetypeou').$this->base,$mimefilter['release']);
548 $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$baseDn,array("cn"));
549 if($ldap->count()){
550 $attrs = $ldap->fetch();
551 if($this->dn != $attrs['dn']) {
552 $message[]= msgPool::duplicated(_("Name"));
553 }
554 }
555 }else{
556 $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",get_ou('mimetypeou').$this->base,array("cn"));
557 if ($ldap->count()){
558 $attrs = $ldap->fetch();
559 if($this->dn != $attrs['dn']) {
560 $message[]= msgPool::duplicated(_("Name"));
561 }
562 }
563 }
565 return($message);
566 }
568 /** Helper functions **/
570 /* Set a new picture */
571 function set_new_picture($filename)
572 {
573 if (empty($filename)){
574 $filename= "./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 }
737 function PrepareForCopyPaste($source)
738 {
739 plugin::PrepareForCopyPaste($source);
741 $source_o = new mimetype($this->config,$source['dn'],$this->parent);
743 foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
744 $use_attr = "use_".$name;
745 if(isset($this->$use_attr)){
746 $this->$use_attr= $source_o->$use_attr;
747 }
748 $this->$name = $source_o->$name;
749 }
750 foreach($this->attributes as $name){
751 $this->$name = $source_o->$name;
752 }
754 if($this->iconData){
755 $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
756 }
757 }
758 }
759 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
760 ?>