1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_application.inc";
22 class applicationManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Applications";
26 var $plDescription= "This does something";
28 /* Dialog attributes */
29 var $apptabs= NULL;
30 var $applications= array();
31 var $ui= NULL;
32 var $acl= "";
34 var $CopyPasteHandler ;
36 var $enableCopyPaste = false;
38 function applicationManagement ($config, $ui)
39 {
40 /* Save configuration for internal use */
41 $this->config= $config;
42 $this->ui= $ui;
44 if( (isset($this->config->data['MAIN']['ENABLECOPYPASTE']))
45 &&
46 (preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE'] ))){
47 $this->enableCopyPaste = true;
48 }
50 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
52 /* Get global filter config */
53 if (!is_global("appfilter")){
54 $base= get_base_from_people($ui->dn);
55 $appfilter= array("depselect" => $base,
56 "regex" => "*");
57 register_global("appfilter", $appfilter);
58 }
59 }
61 function execute()
62 {
63 /* Call parent execute */
64 plugin::execute();
66 // print_a($_POST);
67 // print_a($_GET);
68 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/");
70 /* Save data */
71 $appfilter = get_global("appfilter");
72 $smarty = get_smarty(); // Smarty instance
73 $s_action = ""; // Contains the action to proceed
74 $s_entry = ""; // The value for s_action
75 $base_back = ""; // The Link for Backbutton
77 /* Start for New List Managment */
78 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
79 $s_action="open";
80 $s_entry = base64_decode($_GET['dep_id']);
81 $appfilter['depselect']= "".$this->config->departments[trim($s_entry)];
82 }
84 /* Test Posts */
85 foreach($_POST as $key => $val){
86 // Post for delete
87 if(preg_match("/appl_del.*/",$key)){
88 $s_action = "del";
89 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
90 // Post for edit
91 }elseif(preg_match("/appl_edit_.*/",$key)){
92 $s_action="edit";
93 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
94 // Post for new
95 }elseif(preg_match("/^copy_.*/",$key)){
96 $s_action="copy";
97 $s_entry = preg_replace("/^copy_/i","",$key);
98 }elseif(preg_match("/^cut_.*/",$key)){
99 $s_action="cut";
100 $s_entry = preg_replace("/^cut_/i","",$key);
101 // Post for new
102 }elseif(preg_match("/^dep_back.*/i",$key)){
103 $s_action="back";
104 }elseif(preg_match("/^appl_new.*/",$key)){
105 $s_action="new";
106 }elseif(preg_match("/^dep_home.*/i",$key)){
107 $s_action="home";
108 }elseif(preg_match("/^dep_root.*/i",$key)){
109 $s_action="root";
110 }elseif(preg_match("/^editPaste.*/i",$key)){
111 $s_action="editPaste";
112 }
113 }
115 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
116 $s_action ="edit";
117 $s_entry = $_GET['id'];
118 }
120 $s_entry = preg_replace("/_.$/","",$s_entry);
122 /* Department changed? */
123 if(isset($_POST['depselect']) && $_POST['depselect']){
124 $appfilter['depselect']= $_POST['depselect'];
125 }
127 /* Homebutton is posted */
128 if($s_action=="home"){
129 $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
130 $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$appfilter['depselect']));
131 }
133 if($s_action=="root"){
134 $appfilter['depselect']=($this->config->current['BASE']);
135 }
137 /* If Backbutton is Posted */
138 if($s_action=="back"){
139 $base_back = preg_replace("/^[^,]+,/","",$appfilter['depselect']);
140 $base_back = convert_department_dn($base_back);
142 if(isset($this->config->departments[trim($base_back)])){
143 $appfilter['depselect']= $this->config->departments[trim($base_back)];
144 }else{
145 $appfilter['depselect']= $this->config->departments["/"];
146 }
147 }
149 if (isset($_POST['regex'])){
150 $appfilter['regex']= $_POST['regex'];
151 }
152 if (isset($_GET['search'])){
153 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
154 if ($s == "**"){
155 $s= "*";
156 }
157 $appfilter['regex']= $s;
158 }
159 register_global("appfilter", $appfilter);
161 /* Check sorting variable */
162 $this->reload();
163 $smarty= get_smarty();
165 /* Check for exeeded sizelimit */
166 if (($message= check_sizelimit()) != ""){
167 return($message);
168 }
171 /* Only perform copy / paste if it is enabled
172 */
173 if($this->enableCopyPaste){
175 /* Paste copied/cutted object in here
176 */
177 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
178 $this->CopyPasteHandler->save_object();
179 $this->CopyPasteHandler->SetVar("base",$appfilter['depselect']);
180 return($this->CopyPasteHandler->execute());
181 }
184 /* Copy current object to CopyHandler
185 */
186 if($s_action == "copy"){
187 $this->CopyPasteHandler->Clear();
188 $dn = $this->applications[$s_entry]['dn'];
189 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
190 $objNew = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], "new");
191 $this->CopyPasteHandler->Copy($obj,$objNew);
192 }
195 /* Copy current object to CopyHandler
196 */
197 if($s_action == "cut"){
198 $this->CopyPasteHandler->Clear();
199 $dn = $this->applications[$s_entry]['dn'];
200 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
201 $this->CopyPasteHandler->Cut($obj);
202 }
203 }
205 /* New application? */
206 if ($s_action=="new"){
208 /* By default we set 'dn' to 'new', all relevant plugins will
209 react on this. */
210 $this->dn= "new";
212 /* Create new usertab object */
213 $this->apptabs= new apptabs($this->config,
214 $this->config->data['TABS']['APPSTABS'], $this->dn);
215 $this->apptabs->set_acl(array(':all'));
216 }
218 /* Cancel dialogs */
219 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
220 del_lock ($this->apptabs->dn);
221 unset ($this->apptabs);
222 $this->apptabs= NULL;
223 unset ($_SESSION['objectinfo']);
224 }
226 /* Finish apps edit is triggered by the tabulator dialog, so
227 the user wants to save edited data. Check and save at this
228 point. */
229 if ((isset($_POST['edit_finish'])) && (isset($this->apptabs->config))){
231 /* Check tabs, will feed message array */
232 $this->apptabs->last= $this->apptabs->current;
233 $this->apptabs->save_object();
234 $message= $this->apptabs->check();
236 /* Save, or display error message? */
237 if (count($message) == 0){
239 /* Save data data to ldap */
240 $this->apptabs->save();
241 gosa_log ("Application object'".$this->dn."' has been saved");
243 /* Application has been saved successfully, remove lock from
244 LDAP. */
245 if ($this->dn != "new"){
246 del_lock ($this->dn);
247 }
249 /* There's no page reload so we have to read new apps at
250 this point. */
251 $this->reload ();
252 unset ($this->apptabs);
253 $this->apptabs= NULL;
254 unset ($_SESSION['objectinfo']);
255 } else {
256 /* Ok. There seem to be errors regarding to the tab data,
257 show message and continue as usual. */
258 show_errors($message);
259 }
260 }
262 /* User wants to edit data? */
263 if (($s_action=="edit") && (!isset($this->apptabs->config))){
265 /* Get 'dn' from posted 'applist', must be unique */
266 $this->dn= $this->applications[$s_entry]['dn'];
268 /* Check locking, save current plugin in 'back_plugin', so
269 the dialog knows where to return. */
270 if (($user= get_lock($this->dn)) != ""){
271 return(gen_locked_message ($user, $this->dn));
272 }
274 /* Lock the current entry, so everyone will get the
275 above dialog */
276 add_lock ($this->dn, $this->ui->dn);
278 /* Set up the users ACL's for this 'dn' */
279 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
281 /* Register apptabs to trigger edit dialog */
282 $this->apptabs= new apptabs($this->config,
283 $this->config->data['TABS']['APPSTABS'], $this->dn);
284 $this->apptabs->set_acl($acl);
285 $_SESSION['objectinfo']= $this->dn;
286 }
288 /* Remove user was requested */
289 if ($s_action == "del"){
291 /* Get 'dn' from posted 'uid' */
292 $this->dn= $this->applications[$s_entry]['dn'];
294 /* Load permissions for selected 'dn' and check if
295 we're allowed to remove this 'dn' */
296 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
297 $this->acl= get_module_permission($acl, "application", $this->dn);
298 if (chkacl($this->acl, "delete") == ""){
300 /* Check locking, save current plugin in 'back_plugin', so
301 the dialog knows where to return. */
302 if (($user= get_lock($this->dn)) != ""){
303 return (gen_locked_message ($user, $this->dn));
304 }
306 /* Lock the current entry, so nobody will edit it during deletion */
307 add_lock ($this->dn, $this->ui->dn);
308 $smarty= get_smarty();
309 $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), LDAP::fix($this->dn)));
310 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
311 } else {
313 /* Obviously the user isn't allowed to delete. Show message and
314 clean session. */
315 print_red (_("You are not allowed to delete this application!"));
316 }
317 }
319 /* Confirmation for deletion has been passed. Group should be deleted. */
320 if (isset($_POST['delete_app_confirm'])){
322 /* Some nice guy may send this as POST, so we've to check
323 for the permissions again. */
324 if (chkacl($this->acl, "delete") == ""){
326 /* Delete request is permitted, perform LDAP action */
327 $this->apptabs= new apptabs($this->config,
328 $this->config->data['TABS']['APPSTABS'], $this->dn);
329 $this->apptabs->set_acl(array($this->acl));
330 $this->apptabs->delete ();
331 gosa_log ("Application object'".$this->dn."' has been removed");
332 unset ($this->apptabs);
333 $this->apptabs= NULL;
335 /* Group list has changed, reload it. */
336 $this->reload ();
337 } else {
339 /* Normally this shouldn't be reached, send some extra
340 logs to notify the administrator */
341 print_red (_("You are not allowed to delete this application!"));
342 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
343 }
345 /* Remove lock file after successfull deletion */
346 del_lock ($this->dn);
347 }
350 /* Delete application canceled? */
351 if (isset($_POST['delete_cancel'])){
352 del_lock ($this->dn);
353 unset($_SESSION['objectinfo']);
354 }
356 /* Show tab dialog if object is present */
357 if (($this->apptabs) && (isset($this->apptabs->config))){
358 $display= $this->apptabs->execute();
360 /* Don't show buttons if tab dialog requests this */
361 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
362 $display.= "<p style=\"text-align:right\">\n";
363 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
364 $display.= " \n";
365 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
366 $display.= "</p>";
367 }
368 return ($display);
369 }
371 /* Show main page */
373 /* Prepare departments */
374 $options= "";
375 foreach ($this->config->idepartments as $key => $value){
376 if ($appfilter['depselect'] == $key){
377 $options.= "<option selected='selected' value='$key'>$value</option>";
378 } else {
379 $options.= "<option value='$key'>$value</option>";
380 }
381 }
383 if($this->enableCopyPaste){
384 $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
386 if($this->CopyPasteHandler->isCurrentObjectPastAble()){
388 if($this->CopyPasteHandler->isCurrentCutted()){
389 $img = "images/cutpaste.png";
390 }else{
391 $img = "images/copypaste.png";
392 }
394 $Copy_Paste .= "<input type='image' name='editPaste' class='center'
395 src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'> ";
396 }else{
397 $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'> ";
398 }
399 }else{
400 $Copy_Paste ="";
401 }
403 // Managment
404 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
405 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
406 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
407 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
408 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
409 " <input class='center' type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."' title='"._("Create new application")."' name='appl_new'> ".
410 $Copy_Paste.
411 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
412 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
413 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
414 "</div>";
418 if($this->enableCopyPaste){
419 $actions = "<input class='center' type='image'
420 src='images/editdelete.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
421 $actions.= "<input class='center' type='image'
422 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
423 $actions.= "<input class='center' type='image'
424 src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
425 $actions.= "<input class='center' type='image'
426 src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
427 }else{
429 $actions = "<input class='center' type='image'
430 src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
431 $actions.= "<input class='center' type='image'
432 src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
433 }
436 // Defining Links
437 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
439 // image Buttons
440 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
441 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
443 // Extension images
444 $applimg = "<img class='center' src='images/select_application.png' alt='A' title='"._("Application")."'>";
446 // Space
447 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
450 $divlist = new divlist("applicationtabs");
451 $divlist->SetHeader(array(
452 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
453 array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"),
454 array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
455 ));
458 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
459 $divlist->SetEntriesPerPage(0);
461 foreach($this->departments as $key=> $val){
463 if(!isset($this->config->departments[trim($key)])){
464 $this->config->departments[trim($key)]="";
465 }
467 $non_empty="";
468 $keys= str_replace("/","\/",$key);
469 foreach($this->config->departments as $keyd=>$vald ){
470 if(preg_match("/".$keys."\/.*/",$keyd)){
471 $non_empty="full";
472 }
473 }
475 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
476 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
477 $field3 = array("string" => " ", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
479 $divlist->AddEntry(array($field1,$field2,$field3));
480 }
482 foreach($this->applications as $key => $val){
483 $title = "title='dn : ".$val['dn']."'";
485 if(!isset($val['description'][0])){
486 $desc = "";
487 }else{
488 $desc = " - [ ".$val['description'][0]." ]";
489 }
490 $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
491 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
492 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
494 $divlist->AddEntry(array($field1,$field2,$field3));
495 }
497 $smarty->assign("applicationshead", $listhead);
498 $smarty->assign("applications", $divlist->DrawList());
499 $smarty->assign("search_image", get_template_path('images/search.png'));
500 $smarty->assign("tree_image", get_template_path('images/tree.png'));
501 $smarty->assign("infoimage", get_template_path('images/info.png'));
502 $smarty->assign("launchimage", get_template_path('images/launch.png'));
503 $smarty->assign("deplist", $this->config->idepartments);
504 $smarty->assign("regex", $appfilter['regex']);
506 /* Extend if we are not using javascript */
507 $smarty->assign("apply", apply_filter());
508 $smarty->assign("alphabet", generate_alphabet());
509 $smarty->assign("hint", print_sizelimit_warning());
511 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
512 }
515 function reload()
516 {
517 /* Get config */
518 $appfilter= get_global('appfilter');
520 /* Set base for all searches */
521 $base= $appfilter['depselect'];
523 /* Regex filter? */
524 if ($appfilter['regex'] != ""){
525 $regex= $appfilter['regex'];
526 } else {
527 $regex= "*";
528 }
530 /* Generate application list */
531 $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=gosaApplication))", FALSE, "ou=apps,".$base, array("*"), TRUE);
532 $this->applications= array();
533 foreach ($res as $value){
534 $this->applications[]= $value;
535 }
536 reset ($this->applications);
540 /* NEW LIST MANAGMENT
541 * We also need to search for the departments
542 * So we are able to navigate like in konquerer
543 */
544 $peopleOU = get_people_ou();
546 if(empty($peopleOU)){
547 $base2 = $base;
548 }else{
549 $base2 = preg_replace("/".$peopleOU."/i","",$base);
550 }
552 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
553 TRUE, $base2, array("ou", "description"), TRUE);
555 $this->departments= array();
556 $tmp = array();
557 foreach ($res3 as $value){
558 $tmp[strtolower($value['dn']).$value['dn']]=$value;
559 }
560 ksort($tmp);
561 foreach($tmp as $value){
562 if(isset($value["description"][0])){
563 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
564 }else{
565 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
566 }
567 }
570 /* END NEW LIST MANAGMENT
571 */
573 $tmp=array();
574 foreach($this->applications as $tkey => $val ){
575 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
576 }
577 ksort($tmp);
578 $this->applications=array();
579 foreach($tmp as $val){
580 $this->applications[]=$val;
581 }
582 reset ($this->applications);
585 }
587 function remove_from_parent()
588 {
589 /* Optionally execute a command after we're done */
590 $this->postremove();
591 }
594 /* Save data to object */
595 function save_object()
596 {
597 }
600 /* Check values */
601 function check()
602 {
603 }
606 /* Save to LDAP */
607 function save()
608 {
609 /* Optionally execute a command after we're done */
610 $this->postcreate();
611 }
613 function adapt_from_template($dn)
614 {
615 }
617 function password_change_needed()
618 {
619 }
621 function show_header($button_text, $text, $disabled= FALSE)
622 {
623 }
625 function remove_lock()
626 {
627 if (isset($this->apptabs->dn)){
628 del_lock ($this->apptabs->dn);
629 }
630 }
632 }
633 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
634 ?>