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= " <input type='image' src='images/lists/sort-up.png' class='center' name='Pattern_SortUp_%s' >
283 <input type='image' src='images/lists/sort-down.png' class='center' name='Pattern_SortDown_%s'>
284 <input type='image' src='images/lists/trash.png' class='center' name='Pattern_Remove_%s'>";
285 }else{
286 $Pattern_Actions= "";
287 }
289 if($this->acl_is_writeable("gotoMimeApplication") && !preg_match("/freeze/i",$this->FAIstate)){
290 $Apps_Actions = " <input type='image' src='images/lists/sort-up.png' class='center' name='Apps_SortUp_%s' >
291 <input type='image' src='images/lists/sort-down.png' class='center' name='Apps_SortDown_%s'>
292 <input type='image' src='images/lists/trash.png' class='center' name='Apps_Remove_%s'>";
293 }else{
294 $Apps_Actions= "";
295 }
297 if($this->acl_is_writeable("gotoMimeEmbeddedApplication") && !preg_match("/freeze/i",$this->FAIstate)){
298 $EApps_Actions = " <input type='image' src='images/lists/sort-up.png' class='center' name='EApps_SortUp_%s' >
299 <input type='image' src='images/lists/sort-down.png' class='center' name='EApps_SortDown_%s'>
300 <input type='image' src='images/lists/trash.png' class='center' name='EApps_Remove_%s'>";
301 }else{
302 $EApps_Actions= "";
303 }
305 /* Before adding some entries check acls */
306 if($this->acl_is_readable("gotoMimeFilePattern")){
307 foreach($this->use_gotoMimeFilePattern as $key => $pattern){
308 $field1 = array("string" => $pattern);
309 $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
310 $fields = array($field1,$field2);
311 $DivPatterns -> AddEntry($fields);
312 }
313 }
315 if($this->acl_is_readable("gotoMimeApplication")){
316 foreach($this->use_gotoMimeApplication as $key => $pattern){
317 $field1 = array("string" => $pattern);
318 $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
319 $fields = array($field1,$field2);
320 $DivApps -> AddEntry($fields);
321 }
322 }
323 if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
324 foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
325 $field1 = array("string" => $pattern);
326 $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
327 $fields = array($field1,$field2);
328 $DivEApps -> AddEntry($fields);
329 }
330 }
331 $smarty->assign("bases", $this->get_allowed_bases());
332 $smarty->assign("base_select", $this->base);
333 $smarty->assign("isReleaseMimeType", $this->is_release());
334 $smarty->assign("gotoMimeFilePatterns", $DivPatterns->DrawList());
335 $smarty->assign("gotoMimeApplications", $DivApps->DrawList());
336 $smarty->assign("gotoMimeEmbeddedApplications", $DivEApps->DrawList());
338 $smarty->assign("ApplicationList",$this->ApplicationList);
340 /* Assign class vars to smarty */
341 foreach($this->attributes as $attr){
342 $smarty->assign($attr,$this->$attr);
343 }
345 /* Assign additional vars that are not included in attributes*/
346 foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){
347 $smarty->assign($attr,$this->$attr);
348 }
350 /* Assign select box options */
351 $smarty->assign("gotoMimeGroups",$this->MimeGroups);
352 $smarty->assign("gotoMimeIcon" ,$this->get_picture());
353 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
354 }
357 function save_object()
358 {
359 if(isset($_POST['MimeGeneric']) && !preg_match("/freeze/i",$this->FAIstate)){
361 /* Create a base backup and reset the
362 base directly after calling plugin::save_object();
363 Base will be set seperatly a few lines below */
364 $base_tmp = $this->base;
365 plugin::save_object();
366 $this->base = $base_tmp;
368 /* Only save base if we are not in release mode */
369 if(!$this->is_release()){
371 /* Set new base if allowed */
372 $tmp = $this->get_allowed_bases();
373 if(isset($_POST['base'])){
374 if(isset($tmp[$_POST['base']])){
375 $this->base= $_POST['base'];
376 }
377 }
379 }
381 /* Refresh base */
382 if ($this->acl_is_moveable($this->base)){
383 if (!$this->baseSelector->update()) {
384 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
385 }
386 if ($this->base != $this->baseSelector->getBase()) {
387 $this->base= $this->baseSelector->getBase();
388 $this->is_modified= TRUE;
389 }
390 }
392 /* Save radio buttons */
393 if($this->acl_is_writeable("gotoMimeLeftClickAction")){
394 if(isset($_POST['gotoMimeLeftClickAction_IE'])){
395 $chr = $_POST['gotoMimeLeftClickAction_IE'];
396 if($chr == "E"){
397 $this->gotoMimeLeftClickAction_E = true;
398 $this->gotoMimeLeftClickAction_I = false;
399 }else{
400 $this->gotoMimeLeftClickAction_E = false;
401 $this->gotoMimeLeftClickAction_I = true;
402 }
403 }
404 if(isset($_POST['gotoMimeLeftClickAction_Q'])){
405 $this->gotoMimeLeftClickAction_Q = true;
406 }else{
407 $this->gotoMimeLeftClickAction_Q = false;
408 }
409 }
410 }
411 }
414 /* save current changes */
415 function save()
416 {
417 /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */
418 $arr = array ("E","I","Q");
419 $str = "";
420 foreach ($arr as $Chr){
421 $var = "gotoMimeLeftClickAction_".$Chr;
422 if($this->$var){
423 $str .= $Chr;
424 }
425 }
426 $this->gotoMimeLeftClickAction = $str;
428 /* Create array entries with priority tag ( Test|3 )*/
429 foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){
430 $i = 0;
431 $use_attr = "use_".$attr;
432 $tmp = array();
433 $this->$attr = array();
434 foreach($this->$use_attr as $entry){
435 $tmp[] = $entry."|".$i ++;
436 }
437 $this->$attr = $tmp;
438 }
440 /* Create array entries */
441 foreach(array("gotoMimeFilePattern") as $attr){
442 $i = 0;
443 $use_attr = "use_".$attr;
444 $tmp = array();
445 $this->$attr = array();
446 foreach($this->$use_attr as $entry){
447 $tmp[] = $entry;
448 }
449 $this->$attr = $tmp;
450 }
452 /* Remove Icon if requested */
453 if($this->use_gotoMimeIcon != "*removed*"){
454 $this->gotoMimeIcon = $this->iconData;
455 }else{
456 $this->gotoMimeIcon = "";
457 }
459 plugin::save();
461 /* If this is a newly created object, skip storing those
462 attributes that contain an empty array */
463 if($this->orig_dn == "new"){
464 foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern") as $attr){
465 if(!count($this->$attr)){
466 unset($this->attrs[$attr]);
467 }
468 }
469 }
471 $ldap = $this->config->get_ldap_link();
472 $ldap-> cd ( $this->config->current['BASE']);
473 $ldap->cat($this->dn);
474 if($ldap->count()){
475 $ldap->cd($this->dn);
476 $this->cleanup();
477 $ldap->modify($this->attrs);
478 new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
479 }else{
480 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
481 $ldap->cd($this->dn);
482 $ldap->add($this->attrs);
483 new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
484 }
485 if (!$ldap->success()){
486 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
487 }
488 }
491 /* Remove current mime type */
492 function remove_from_parent()
493 {
494 plugin::remove_from_parent();
495 $ldap = $this->config->get_ldap_link();
496 $ldap->rmDir($this->dn);
497 if (!$ldap->success()){
498 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
499 }
500 new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
502 /* Optionally execute a command after we're done */
503 $this->handle_post_events("remove");
505 /* Delete references to object groups */
506 $ldap->cd ($this->config->current['BASE']);
507 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
508 while ($ldap->fetch()){
509 $og= new ogroup($this->config, $ldap->getDN());
510 unset($og->member[$this->dn]);
511 $og->save ();
512 if (!$ldap->success()){
513 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
514 }
515 }
516 }
519 /* Check given values */
520 function check()
521 {
522 $message = plugin::check();
523 if($this->cn == "" ){
524 $message[] = msgPool::required(_("Name"));
525 }
526 if(!count($this->use_gotoMimeFilePattern)){
527 $message[] = msgPool::required(_("File pattern"));
528 }
530 // Check if a wrong base was supplied
531 if(!$this->baseSelector->checkLastBaseUpdate()){
532 $message[]= msgPool::check_base();;
533 }
535 /* Check if there is already a mime type with this cn */
536 $ldap = $this->config->get_ldap_link();
537 $ldap->cd($this->config->current["BASE"]);
539 if($this->is_release()){
540 $base = $this->parent->parent->mime_release;
541 }else{
542 $base = get_ou("mimetypeRDN").$this->base;
543 }
545 $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
546 if($ldap->count()){
547 $attrs = $ldap->fetch();
548 if($this->dn != $attrs['dn']) {
549 $message[]= msgPool::duplicated("cn");
550 }
551 }
553 /* Check if we are allowed to create or move this object
554 */
555 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
556 $message[] = msgPool::permCreate();
557 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
558 $message[] = msgPool::permMove();
559 }
561 return($message);
562 }
565 /** Helper functions **/
567 /* Set a new picture */
568 function set_new_picture($filename)
569 {
570 if (empty($filename)){
571 $filename= "./plugins/goto/images/default_icon.png";
572 $this->use_gotoMimeIcon= "*removed*";
573 }else{
574 $this->use_gotoMimeIcon= $filename;
575 }
577 if (file_exists($filename)){
578 $fd = fopen ($filename, "rb");
579 $this->iconData= fread ($fd, filesize ($filename));
580 session::set('binary',$this->iconData);
581 session::set('binarytype',"image/jpeg");
582 fclose ($fd);
583 }
584 }
586 /* Get picture link */
587 function get_picture()
588 {
589 session::set('binary',$this->iconData);
590 session::set('binarytype',"image/jpeg");
591 return("getbin.php");
592 }
594 /* Transports the given Arraykey one position up*/
595 function ArrayUp($atr,$attrs)
596 {
597 $ret = $attrs;
598 $pos = $this->getpos($atr,$attrs) ;
599 $cn = count($attrs);
600 if(!(($pos == -1)||($pos == 1))){
601 $before = array_slice($attrs,0,($pos-2));
602 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
603 $unten = array_slice($attrs,$pos);
604 $ret = array();
605 $ret = $this->combineArrays($before,$mitte,$unten);
606 }
607 return($ret);
608 }
611 /* Transports the given Arraykey one position down*/
612 function ArrayDown($atr,$attrs)
613 {
614 $ret = $attrs;
615 $pos = $this->getpos($atr,$attrs) ;
616 $cn = count($attrs);
617 if(!(($pos == -1)||($pos == $cn))){
618 $before = array_slice($attrs,0,($pos-1));
619 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
620 $unten = array_slice($attrs,($pos+1));
621 $ret = array();
622 $ret = $this->combineArrays($before,$mitte,$unten);
623 }
624 return($ret);
625 }
628 /* return the position of the element in the array */
629 function getpos($atr,$attrs)
630 {
631 $i = 0;
632 foreach($attrs as $attr => $name) {
633 $i++;
634 if($attr == $atr){
635 return($i);
636 }
637 }
638 return(-1);
639 }
642 /* Remove this element from array */
643 function ArrayRemove($key,$array,$reorder = false)
644 {
645 if(isset($array[$key])){
646 unset($array[$key]);
647 if($reorder){
648 $tmp = array();
649 foreach($array as $entry){
650 $tmp[] = $entry;
651 }
652 $array = $tmp;
653 }
654 }
655 return($array);
656 }
659 /* Combine new array */
660 function combineArrays($ar0,$ar1,$ar2)
661 {
662 $ret = array();
663 if(is_array($ar0))
664 foreach($ar0 as $ar => $a){
665 $ret[]=$a;
666 }
667 if(is_array($ar1))
668 foreach($ar1 as $ar => $a){
669 $ret[]=$a;
670 }
671 if(is_array($ar2))
672 foreach($ar2 as $ar => $a){
673 $ret[]=$a;
674 }
675 return($ret);
676 }
679 /* Return a dialog with all fields that must be changed,
680 if we want to copy this entry */
681 function getCopyDialog()
682 {
683 $str = "";
685 $smarty = get_smarty();
686 $smarty->assign("cn", $this->cn);
687 $smarty->assign("description", $this->description);
688 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
690 $ret = array();
691 $ret['string'] = $str;
692 $ret['status'] = "";
693 return($ret);
694 }
697 /* Save all */
698 function saveCopyDialog()
699 {
700 $attrs = array("cn","description");
701 foreach($attrs as $attr){
702 if(isset($_POST[$attr])){
703 $this->$attr = $_POST[$attr];
704 }
705 }
706 }
708 /* Return plugin informations for acl handling */
709 static function plInfo()
710 {
711 return (array(
712 "plShortName" => _("Generic"),
713 "plDescription" => _("Mime type generic"),
714 "plSelfModify" => FALSE,
715 "plDepends" => array(),
716 "plPriority" => 0,
717 "plSection" => array("administration"),
718 "plCategory" => array("mimetypes" => array("description" => _("Mime types"),
719 "objectClass" => "gotoMimeType")),
720 "plProvidedAcls"=> array(
721 "cn" => _("Name"),
722 "gotoMimeGroup" => _("Mime group"),
723 "description" => _("Description"),
724 "base" => _("Base"),
725 "gotoMimeApplication" => _("Application"),
726 "gotoMimeLeftClickAction" => _("Left click action"),
727 "gotoMimeIcon" => _("Icon"),
728 "gotoMimeFilePattern" => _("File patterns"),
729 "gotoMimeEmbeddedApplication" => _("Embedded applications"))
730 ));
732 }
735 function is_release()
736 {
737 if(is_object($this->parent->parent)){
738 return($this->parent->parent->IsReleaseManagementActivated());
739 }else{
740 /* Check if we should enable the release selection */
741 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
742 if(!empty($tmp)){
743 return(true);
744 }
745 }
746 return(FALSE);
747 }
750 function PrepareForCopyPaste($source)
751 {
752 plugin::PrepareForCopyPaste($source);
754 $source_o = new mimetype($this->config,$source['dn'],$this->parent);
756 foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
757 $use_attr = "use_".$name;
758 if(isset($this->$use_attr)){
759 $this->$use_attr= $source_o->$use_attr;
760 }
761 $this->$name = $source_o->$name;
762 }
763 foreach($this->attributes as $name){
764 $this->$name = $source_o->$name;
765 }
767 if($this->iconData){
768 $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
769 }
770 }
771 }
772 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
773 ?>