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