1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004 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_ogroups.inc";
22 class ogroupManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Object groups";
26 var $plDescription= "This does something";
28 /* attribute list for save action */
29 var $attributes= array();
30 var $objectclasses= array();
31 var $obtypes= array();
32 var $ogroup;
34 function ogroupManagement ($config, $dn= NULL)
35 {
36 /* Include config object */
37 $this->config= $config;
38 $this->ui= get_userinfo();
40 /* Fill translation array */
41 $this->obtypes= array( "posixAccount" => _("UNIX accounts"),
42 "posixGroup" => _("Groups"),
43 "gosaDepartment" => _("Departments"),
44 "gosaApplication" => _("Applications"),
45 "goServer" => _("Servers"),
46 "gotoTerminal" => _("Thin Clients"),
47 "gotoWorkstation" => _("Workstations"),
48 "goFonHardware" => _("Phone"),
49 "gotoPrinter" => _("Printer"));
50 asort($this->obtypes);
52 /* Get global filter config */
53 if (!is_global("ogroupfilter")){
54 $ui= get_userinfo();
55 $base= get_base_from_people($ui->dn);
56 $ogroupfilter= array( "usergroups" => "checked",
57 "groupgroups" => "checked",
58 "appgroups" => "checked",
59 "depgroups" => "checked",
60 "servergroups" => "checked",
61 "wsgroups" => "checked",
62 "prtgroups" => "checked",
63 "tcgroups" => "checked",
64 "fongroups" => "checked",
65 "depselect" => $base,
66 "regex" => "*");
67 register_global("ogroupfilter", $ogroupfilter);
68 }
69 }
71 function execute()
72 {
73 /* Call parent execute */
74 plugin::execute();
76 /* Prepare template */
77 $smarty= get_smarty();
79 $ogroupfilter= get_global("ogroupfilter");
80 $s_action = "";
81 $s_entry = "";
83 foreach( array("depselect", "regex") as $type){
84 if (isset($_POST[$type])){
85 $ogroupfilter[$type]= $_POST[$type];
86 }
87 }
88 if (isset($_POST['Ogroup_dialog_posted'])){
89 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
90 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
92 if (isset($_POST[$type])) {
93 $ogroupfilter[$type]= "checked";
94 } else {
95 $ogroupfilter[$type]= "";
96 }
97 }
98 }
99 if (isset($_GET['search'])){
100 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
101 if ($s == "**"){
102 $s= "*";
103 }
104 $ogroupfilter['regex']= $s;
105 }
107 /* Test Posts */
108 foreach($_POST as $key => $val){
109 // Post for delete
110 if(preg_match("/group_del.*/",$key)){
111 $s_action = "del";
112 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
113 // Post for edit
114 }elseif(preg_match("/group_edit_.*/",$key)){
115 $s_action="edit";
116 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
117 // Post for new
118 }elseif(preg_match("/dep_back.*/i",$key)){
119 $s_action="back";
120 }elseif(preg_match("/group_new.*/",$key)){
121 $s_action="new";
122 }elseif(preg_match("/dep_home.*/i",$key)){
123 $s_action="home";
124 }elseif(preg_match("/group_tplnew.*/i",$key)){
125 $s_action="new_tpl";
126 }elseif(preg_match("/group_chgpw.*/i",$key)){
127 $s_action="change_pw";
128 $s_entry = preg_replace("/group_chgpw_/i","",$key);
129 }elseif(preg_match("/dep_root.*/i",$key)){
130 $s_action="root";
131 }
132 }
133 $s_entry = preg_replace("/_.$/","",$s_entry);
135 /* Department changed? */
136 if(isset($_POST['depselect']) && $_POST['depselect']){
137 $ogroupfilter['depselect']= $_POST['depselect'];
138 }
140 /* Start for New List Managment */
141 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
142 $s_action="open";
143 $s_entry = base64_decode($_GET['dep_id']);
144 $ogroupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
145 }
147 /* If Backbutton is Posted */
148 if($s_action=="back"){
149 $base_back = preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']);
150 $base_back = convert_department_dn($base_back);
152 if(isset($this->config->departments[trim($base_back)])){
153 $ogroupfilter['depselect']= $this->config->departments[trim($base_back)];
154 }else{
155 $ogroupfilter['depselect']= $this->config->departments["/"];
156 }
157 register_global("ogroupfilter", $ogroupfilter);
158 }
160 /* Homebutton is posted */
161 if($s_action=="home"){
162 $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
163 $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']));
164 }
166 /* root posted */
167 if($s_action=="root"){
168 $ogroupfilter['depselect']=($this->config->current['BASE']);
169 }
171 // Edit if
172 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
173 $s_action ="edit";
174 $s_entry = $_GET['id'];
175 }
177 register_global("ogroupfilter", $ogroupfilter);
179 $this->reload();
181 /* Check for exeeded sizelimit */
182 if (($message= check_sizelimit()) != ""){
183 return($message);
184 }
186 /* New group? */
187 if ($s_action=="new"){
189 /* By default we set 'dn' to 'new', all relevant plugins will
190 react on this. */
191 $this->dn= "new";
193 /* Create new usertab object */
194 $this->ogroup= new ogrouptabs($this->config,
195 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
196 }
198 if ($s_action=="del"){
200 /* Get 'dn' from posted 'uid' */
201 $this->dn= $this->ogrouplist[$s_entry]['dn'];
203 /* Load permissions for selected 'dn' and check if
204 we're allowed to remove this 'dn' */
205 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
206 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
207 if (chkacl($this->acl, "delete") == ""){
209 /* Check locking, save current plugin in 'back_plugin', so
210 the dialog knows where to return. */
211 if (($user= get_lock($this->dn)) != ""){
212 return(gen_locked_message ($user, $this->dn));
213 }
215 /* Lock the current entry, so nobody will edit it during deletion */
216 add_lock ($this->dn, $this->ui->dn);
217 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
218 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
219 } else {
221 /* Obviously the user isn't allowed to delete. Show message and
222 clean session. */
223 print_red (_("You are not allowed to delete this object group!"));
224 }
225 }
227 /* Confirmation for deletion has been passed. Group should be deleted. */
228 if (isset($_POST['delete_group_confirm'])){
230 /* Some nice guy may send this as POST, so we've to check
231 for the permissions again. */
232 if (chkacl($this->acl, "delete") == ""){
234 /* Delete request is permitted, perform LDAP action */
235 $this->ogroup= new ogrouptabs($this->config,
236 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
237 $this->ogroup->set_acl(array($this->acl));
238 $this->ogroup->delete ();
239 gosa_log ("Object group'".$this->dn."' has been removed");
240 unset ($this->ogroup);
241 $this->ogroup= NULL;
243 /* Group list has changed, reload it. */
244 $this->reload ();
245 } else {
247 /* Normally this shouldn't be reached, send some extra
248 logs to notify the administrator */
249 print_red (_("You are not allowed to delete this object group!"));
250 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
251 }
253 /* Remove lock file after successfull deletion */
254 del_lock ($this->dn);
255 unset($_SESSION['objectinfo']);
256 }
259 /* Delete group canceled? */
260 if (isset($_POST['delete_cancel'])){
261 del_lock ($this->dn);
262 unset($_SESSION['objectinfo']);
263 }
265 if ($s_action=="edit"){
267 /* Get 'dn' from posted 'uid', must be unique */
268 $this->dn= $this->ogrouplist[$s_entry]['dn'];
270 /* Check locking, save current plugin in 'back_plugin', so
271 the dialog knows where to return. */
272 if (($user= get_lock($this->dn)) != ""){
273 return(gen_locked_message ($user, $this->dn));
274 }
276 /* Lock the current entry, so everyone will get the
277 above dialog */
278 add_lock ($this->dn, $this->ui->dn);
280 /* Set up the users ACL's for this 'dn' */
281 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
283 /* Register grouptab to trigger edit dialog */
284 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
285 $this->dn);
286 $this->ogroup->set_acl($acl);
287 $_SESSION['objectinfo']= $this->dn;
288 }
290 /* Finish button has been pressed */
291 if (isset($_POST['edit_finish'])){
293 /* Check tabs, will feed message array */
294 $message= $this->ogroup->check();
296 /* Save, or display error message? */
297 if (count($message) == 0){
299 /* Save user data to ldap */
300 $this->ogroup->save();
301 gosa_log ("Object group'".$this->dn."' has been saved");
303 /* Group has been saved successfully, remove lock from
304 LDAP. */
305 if ($this->dn != "new"){
306 del_lock ($this->dn);
307 }
309 /* There's no page reload so we have to read new users at
310 this point. */
311 $this->reload ();
312 unset ($this->ogroup);
313 $this->ogroup= NULL;
314 unset ($_SESSION['objectinfo']);
316 } else {
317 /* Ok. There seem to be errors regarding to the tab data,
318 show message and continue as usual. */
319 show_errors($message);
320 }
321 }
323 /* Cancel dialogs */
324 if (isset($_POST['edit_cancel'])){
325 del_lock ($this->ogroup->dn);
326 unset ($this->ogroup);
327 $this->ogroup= NULL;
328 unset($_SESSION['objectinfo']);
329 }
331 /* Show dialog if object is present */
332 if ($this->ogroup){
333 $display= $this->ogroup->execute();
335 /* Don't show buttons if tab dialog requests this */
336 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
337 $display.= "<p style=\"text-align:right\">\n";
338 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
339 $display.= " \n";
340 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
341 $display.= "</p>";
342 }
343 return ($display);
344 }
346 /* Prepare departments */
347 $options= "";
348 foreach ($this->config->idepartments as $key => $value){
349 if ($ogroupfilter['depselect'] == $key){
350 $options.= "<option selected value='$key'>$value</option>";
351 } else {
352 $options.= "<option value='$key'>$value</option>";
353 }
354 }
356 // Managment
357 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
358 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
359 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."'
360 name='dep_root' alt='"._("Root")."'> ".
361 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."'
362 alt='"._("Home")."' name='dep_home'> ".
363 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
364 " <input class='center' type='image' align='middle' src='images/list_new_ogroup.png' title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>".
365 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
366 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
367 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
368 "</div>";
371 $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
372 $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
374 // Defining Links
375 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
377 // image Buttons
378 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
379 $userimg = "<img src='images/select_groups.png' alt='User' title='%s'>";
381 // Extension images
382 $mailimg = "<img src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
384 // Space
385 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
387 // List Setup
388 $divlist = new divlist("ogroubstab");
389 $divlist->SetHeader(array(
390 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
391 array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"),
392 array("string" => _("Properties"), "attach" => "style='width:136px;'"),
393 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")
394 ));
397 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
398 $divlist->SetEntriesPerPage(0);
400 foreach($this->departments as $key=> $val){
402 if(!isset($this->config->departments[trim($key)])){
403 $this->config->departments[trim($key)]="";
404 }
406 $non_empty="";
407 $keys= str_replace("/","\/",$key);
408 foreach($this->config->departments as $keyd=>$vald ){
409 if(preg_match("/".$keys."\/.*/",$keyd)){
410 $non_empty="full";
411 }
412 }
416 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='"._("Department")."'>", "attach" => "style='text-align:center;width:20px;'");
417 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
418 $field3 = array("string" => " ", "attach" => "style='width:136px;'");
419 $field4 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
421 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
422 }
424 // Assigning ogroups
425 foreach($this->ogrouplist as $key => $val){
427 if(isset($val['mail'])){
428 $mail = $mailimg;
429 }else{
430 $mail = $empty;
431 }
433 $title = "title='dn : ".$val['dn']."'";
435 if(!isset($val['description'][0])){
436 $desc = "";
437 }else{
438 $desc = " - [ ".$val['description'][0]." ]";
439 }
440 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width:20px;'");
441 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
442 $field3 = array("string" => $this->convert_list($val)." ".$mail, "attach" => "style='width:136px;'");
443 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
445 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
446 }
453 /* Show main page */
454 $smarty->assign("search_image", get_template_path('images/search.png'));
455 $smarty->assign("tree_image", get_template_path('images/tree.png'));
456 $smarty->assign("infoimage", get_template_path('images/info.png'));
457 $smarty->assign("launchimage", get_template_path('images/launch.png'));
458 $smarty->assign("deplist", $this->config->idepartments);
460 $smarty->assign("groupshead", $listhead);
461 $smarty->assign("groups", $divlist->DrawList());
463 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
464 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
465 $smarty->assign("$type", $ogroupfilter[$type]);
466 }
468 $smarty->assign("hint", print_sizelimit_warning());
469 $smarty->assign("apply", apply_filter());
470 $smarty->assign("alphabet", generate_alphabet());
471 return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
472 }
475 function convert_list($input)
476 {
477 $temp= "";
480 $conv= array(
481 "U" => array("select_user.png",_("User")),
482 "G" => array("select_groups.png",_("Group")),
483 "A" => array("select_application.png",_("Application")),
484 "D" => array("select_department.png",_("Department")),
485 "S" => array("select_server.png",_("Server")),
486 "F" => array("select_phone.png",_("Phone")),
487 "W" => array("select_workstation.png",_("Workstation")),
488 "T" => array("select_terminal.png",_("Terminal")),
489 "P" => array("select_printer.png",_("Printer")));
491 /* Assemble picture */
492 $type= $input['gosaGroupObjects'][0];
493 $type= preg_replace("/[^A-Z]/i","",$type);
494 if (isset($type[0])){
495 $p1['pic']= $conv[$type[0]][0];
496 $p1['tit']= $conv[$type[0]][1];
497 $p1['alt']= $type[0];
498 } else {
499 $p1['pic']= "empty.png";
500 $p1['tit']= "";
501 $p1['alt']= "";
502 }
503 if (isset($type[1])){
504 $p2['pic']= $conv[$type[1]][0];
505 $p2['alt']= $type[1];
506 $p2['tit']= $conv[$type[1]][1];
507 } else {
508 $p2['pic']= "empty.png";
509 $p2['alt']= "";
510 $p2['tit']= "";
511 }
512 $temp = "<img src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
513 $temp.= "<img src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
514 return ($temp);
515 }
518 function reload()
519 {
520 /* Get config */
521 $ogroupfilter= get_global('ogroupfilter');
523 /* Set base for all searches */
524 $base= $ogroupfilter['depselect'];
526 /* Regex filter? */
527 if ($ogroupfilter['regex'] != ""){
528 $regex= $ogroupfilter['regex'];
529 } else {
530 $regex= "*";
531 }
533 /* User filter? */
534 $this->oogrouplist= array();
536 /* Generate oogrouplist filter */
537 $filter= "";
539 if ($ogroupfilter['usergroups'] == "checked"){
540 $filter.= "(gosaGroupObjects=*U*)";
541 }
542 if ($ogroupfilter['groupgroups'] == "checked"){
543 $filter.= "(gosaGroupObjects=*G*)";
544 }
545 if ($ogroupfilter['appgroups'] == "checked"){
546 $filter.= "(gosaGroupObjects=*A*)";
547 }
548 if ($ogroupfilter['depgroups'] == "checked"){
549 $filter.= "(gosaGroupObjects=*D*)";
550 }
551 if ($ogroupfilter['servergroups'] == "checked"){
552 $filter.= "(gosaGroupObjects=*S*)";
553 }
554 if ($ogroupfilter['wsgroups'] == "checked"){
555 $filter.= "(gosaGroupObjects=*W*)";
556 }
557 if ($ogroupfilter['prtgroups'] == "checked"){
558 $filter.= "(gosaGroupObjects=*P*)";
559 }
560 if ($ogroupfilter['tcgroups'] == "checked"){
561 $filter.= "(gosaGroupObjects=*T*)";
562 }
563 if ($ogroupfilter['fongroups'] == "checked"){
564 $filter.= "(gosaGroupObjects=*F*)";
565 }
567 if ($filter != ""){
568 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
569 } else {
570 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
571 }
573 $groups = ($this->config->current['GROUPS']);
575 $res= get_list($this->ui->subtreeACL, "$filter",FALSE, $groups.",".$base, array("*"), TRUE);
576 $this->ogrouplist= $res;
577 ksort ($this->ogrouplist);
578 reset ($this->ogrouplist);
581 /* NEW LIST MANAGMENT
582 * We also need to search for the departments
583 * So we are able to navigate like in konquerer
584 */
585 $base2 = preg_replace("/ou=people,/i","",$base);
587 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
588 TRUE, $base2, array("ou", "description"), TRUE);
592 $this->departments= array();
593 $tmp = array();
594 foreach ($res3 as $value){
595 $tmp[strtolower($value['dn']).$value['dn']]=$value;
596 }
597 ksort($tmp);
598 foreach($tmp as $value){
599 if(isset($value["description"][0])){
600 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
601 }else{
602 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
603 }
604 }
605 /* END NEW LIST MANAGMENT
606 */
608 $tmp=array();
609 foreach($this->ogrouplist as $tkey => $val ){
610 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
611 }
612 ksort($tmp);
613 $this->ogrouplist=array();
614 foreach($tmp as $val){
615 $this->ogrouplist[]=$val;
616 }
617 reset ($this->ogrouplist);
621 }
623 }
625 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
626 ?>