80c1b5412d3adbcb056b624521233c9cb7a08fc1
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 /* Prepare template */
74 $smarty= get_smarty();
76 $ogroupfilter= get_global("ogroupfilter");
77 $s_action = "";
78 $s_entry = "";
80 foreach( array("depselect", "regex") as $type){
81 if (isset($_POST[$type])){
82 $ogroupfilter[$type]= $_POST[$type];
83 }
84 }
85 if (isset($_POST['regex'])){
86 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
87 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
89 if (isset($_POST[$type])) {
90 $ogroupfilter[$type]= "checked";
91 } else {
92 $ogroupfilter[$type]= "";
93 }
94 }
95 }
96 if (isset($_GET['search'])){
97 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
98 if ($s == "**"){
99 $s= "*";
100 }
101 $ogroupfilter['regex']= $s;
102 }
104 /* Test Posts */
105 foreach($_POST as $key => $val){
106 // Post for delete
107 if(preg_match("/group_del.*/",$key)){
108 $s_action = "del";
109 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
110 // Post for edit
111 }elseif(preg_match("/group_edit_.*/",$key)){
112 $s_action="edit";
113 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
114 // Post for new
115 }elseif(preg_match("/dep_back.*/i",$key)){
116 $s_action="back";
117 }elseif(preg_match("/group_new.*/",$key)){
118 $s_action="new";
119 }elseif(preg_match("/dep_home.*/i",$key)){
120 $s_action="home";
121 }elseif(preg_match("/group_tplnew.*/i",$key)){
122 $s_action="new_tpl";
123 }elseif(preg_match("/group_chgpw.*/i",$key)){
124 $s_action="change_pw";
125 $s_entry = preg_replace("/group_chgpw_/i","",$key);
126 }elseif(preg_match("/dep_root.*/i",$key)){
127 $s_action="root";
128 }
129 }
130 $s_entry = preg_replace("/_.$/","",$s_entry);
132 /* Department changed? */
133 if(isset($_POST['depselect']) && $_POST['depselect']){
134 $ogroupfilter['depselect']= $_POST['depselect'];
135 $this->reload();
136 }
138 /* Start for New List Managment */
139 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
140 $s_action="open";
141 $s_entry = base64_decode($_GET['dep_id']);
142 $ogroupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
143 $this->reload();
144 }
146 /* If Backbutton is Posted */
147 if($s_action=="back"){
148 $base_back = preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']);
149 $base_back = convert_department_dn($base_back);
151 if(isset($this->config->departments[trim($base_back)])){
152 $ogroupfilter['depselect']= $this->config->departments[trim($base_back)];
153 }else{
154 $ogroupfilter['depselect']= $this->config->departments["/"];
155 }
156 register_global("ogroupfilter", $ogroupfilter);
157 $this->reload();
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 $this->reload();
165 }
167 /* root posted */
168 if($s_action=="root"){
169 $ogroupfilter['depselect']=($this->config->current['BASE']);
170 $this->reload();
171 }
173 // Edit if
174 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
175 $s_action ="edit";
176 $s_entry = $_GET['id'];
177 }
179 register_global("ogroupfilter", $ogroupfilter);
181 /* Prepare formular */
182 if (!isset($this->ogroup) &&
183 !isset($_POST['new_group']) &&
184 !isset($_POST['delete_group']) &&
185 !isset($_POST['select_group'])){
186 $this->reload();
187 }
189 /* Check for exeeded sizelimit */
190 if (($message= check_sizelimit()) != ""){
191 return($message);
192 }
194 /* New group? */
195 if ($s_action=="new"){
197 /* By default we set 'dn' to 'new', all relevant plugins will
198 react on this. */
199 $this->dn= "new";
201 /* Create new usertab object */
202 $this->ogroup= new ogrouptabs($this->config,
203 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
204 $this->ogroup->set_acl(array(':all'));
205 }
207 if ($s_action=="del"){
209 /* Get 'dn' from posted 'uid' */
210 $this->dn= $this->ogrouplist[$s_entry]['dn'];
212 /* Load permissions for selected 'dn' and check if
213 we're allowed to remove this 'dn' */
214 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
215 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
216 if (chkacl($this->acl, "delete") == ""){
218 /* Check locking, save current plugin in 'back_plugin', so
219 the dialog knows where to return. */
220 if (($user= get_lock($this->dn)) != ""){
221 return(gen_locked_message ($user, $this->dn));
222 }
224 /* Lock the current entry, so nobody will edit it during deletion */
225 add_lock ($this->dn, $this->ui->dn);
226 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
227 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
228 } else {
230 /* Obviously the user isn't allowed to delete. Show message and
231 clean session. */
232 print_red (_("You are not allowed to delete this object group!"));
233 }
234 }
236 /* Confirmation for deletion has been passed. Group should be deleted. */
237 if (isset($_POST['delete_group_confirm'])){
239 /* Some nice guy may send this as POST, so we've to check
240 for the permissions again. */
241 if (chkacl($this->acl, "delete") == ""){
243 /* Delete request is permitted, perform LDAP action */
244 $this->ogroup= new ogrouptabs($this->config,
245 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
246 $this->ogroup->set_acl(array($this->acl));
247 $this->ogroup->delete ();
248 gosa_log ("Object group'".$this->dn."' has been removed");
249 unset ($this->ogroup);
250 $this->ogroup= NULL;
252 /* Group list has changed, reload it. */
253 $this->reload ();
254 } else {
256 /* Normally this shouldn't be reached, send some extra
257 logs to notify the administrator */
258 print_red (_("You are not allowed to delete this object group!"));
259 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
260 }
262 /* Remove lock file after successfull deletion */
263 del_lock ($this->dn);
264 unset($_SESSION['objectinfo']);
265 }
268 /* Delete group canceled? */
269 if (isset($_POST['delete_cancel'])){
270 del_lock ($this->dn);
271 unset($_SESSION['objectinfo']);
272 }
274 if ($s_action=="edit"){
276 /* Get 'dn' from posted 'uid', must be unique */
277 $this->dn= $this->ogrouplist[$s_entry]['dn'];
279 /* Check locking, save current plugin in 'back_plugin', so
280 the dialog knows where to return. */
281 if (($user= get_lock($this->dn)) != ""){
282 return(gen_locked_message ($user, $this->dn));
283 }
285 /* Lock the current entry, so everyone will get the
286 above dialog */
287 add_lock ($this->dn, $this->ui->dn);
289 /* Set up the users ACL's for this 'dn' */
290 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
292 /* Register grouptab to trigger edit dialog */
293 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
294 $this->dn);
295 $this->ogroup->set_acl($acl);
296 $_SESSION['objectinfo']= $this->dn;
297 }
299 /* Finish button has been pressed */
300 if (isset($_POST['edit_finish'])){
302 /* Check tabs, will feed message array */
303 $message= $this->ogroup->check();
305 /* Save, or display error message? */
306 if (count($message) == 0){
308 /* Save user data to ldap */
309 $this->ogroup->save();
310 gosa_log ("Object group'".$this->dn."' has been saved");
312 /* Group has been saved successfully, remove lock from
313 LDAP. */
314 if ($this->dn != "new"){
315 del_lock ($this->dn);
316 }
318 /* There's no page reload so we have to read new users at
319 this point. */
320 $this->reload ();
321 unset ($this->ogroup);
322 $this->ogroup= NULL;
323 unset ($_SESSION['objectinfo']);
325 } else {
326 /* Ok. There seem to be errors regarding to the tab data,
327 show message and continue as usual. */
328 show_errors($message);
329 }
330 }
332 /* Cancel dialogs */
333 if (isset($_POST['edit_cancel'])){
334 del_lock ($this->ogroup->dn);
335 unset ($this->ogroup);
336 $this->ogroup= NULL;
337 unset($_SESSION['objectinfo']);
338 }
340 /* Show dialog if object is present */
341 if ($this->ogroup){
342 $display= $this->ogroup->execute();
344 /* Don't show buttons if tab dialog requests this */
345 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
346 $display.= "<p style=\"text-align:right\">\n";
347 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
348 $display.= " \n";
349 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
350 $display.= "</p>";
351 }
352 return ($display);
353 }
355 /* Prepare departments */
356 $options= "";
357 foreach ($this->config->idepartments as $key => $value){
358 if ($ogroupfilter['depselect'] == $key){
359 $options.= "<option selected value='$key'>$value</option>";
360 } else {
361 $options.= "<option value='$key'>$value</option>";
362 }
363 }
365 // Managment
366 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
367 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
368 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."'
369 name='dep_root' alt='"._("Root")."'> ".
370 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."'
371 alt='"._("Home")."' name='dep_home'> ".
372 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
373 " <input type='image' align='middle' src='images/list_new_ogroup.png' title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>".
374 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
375 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
376 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
377 "</div>";
380 $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
381 $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
383 // Defining Links
384 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
386 // image Buttons
387 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
388 $userimg = "<img src='images/select_groups.png' alt='User' title='%s'>";
390 // Extension images
391 $mailimg = "<img src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
393 // Space
394 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
396 // List Setup
397 $divlist = new divlist();
398 $divlist->SetHeader(array(
399 array("string" => " ","attach"=>"style='width:20px;'"),
400 array("string" => _("Name of object groups")." / "._("Departments")),
401 array("string" => _("Properties") ,"attach"=>"style='width:50px;'"),
402 array("string" => _("Actions") ,"attach"=>"style='width:50px;border:none;'")
403 ));
406 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
407 $divlist->SetEntriesPerPage(20);
409 foreach($this->departments as $key=> $val){
411 $field1 = array("string" => "<img src='images/folder.png' alt='"._("Department")."'>");
412 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
413 $field3 = array("string" => " ");
414 $field4 = array("string" => " ","attach"=>"style='text-align:right;border:none'");
416 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
417 }
419 // Assigning ogroups
420 foreach($this->ogrouplist as $key => $val){
422 if(isset($val['mail'])){
423 $mail = $mailimg;
424 }else{
425 $mail = $empty;
426 }
428 $title = "title='dn : ".$val['dn']."'";
430 if(!isset($val['description'][0])){
431 $desc = "";
432 }else{
433 $desc = " - [ ".$val['description'][0]." ]";
434 }
435 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">");
436 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
437 $field3 = array("string" => $this->convert_list($val)." ".$mail);
438 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none'");
440 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
441 }
448 /* Show main page */
449 $smarty->assign("search_image", get_template_path('images/search.png'));
450 $smarty->assign("tree_image", get_template_path('images/tree.png'));
451 $smarty->assign("infoimage", get_template_path('images/info.png'));
452 $smarty->assign("launchimage", get_template_path('images/launch.png'));
453 $smarty->assign("deplist", $this->config->idepartments);
455 $smarty->assign("groupshead", $listhead);
456 $smarty->assign("groups", $divlist->DrawList());
458 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
459 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
460 $smarty->assign("$type", $ogroupfilter[$type]);
461 }
463 $smarty->assign("hint", print_sizelimit_warning());
464 $smarty->assign("apply", apply_filter());
465 $smarty->assign("alphabet", generate_alphabet());
466 return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
467 }
470 function convert_list($input)
471 {
472 $temp= "";
475 $conv= array(
476 "U" => array("select_user.png",_("User")),
477 "G" => array("select_groups.png",_("Group")),
478 "A" => array("select_application.png",_("Application")),
479 "D" => array("select_department.png",_("Department")),
480 "S" => array("select_server.png",_("Server")),
481 "F" => array("select_phone.png",_("Phone")),
482 "W" => array("select_workstation.png",_("Workstation")),
483 "T" => array("select_terminal.png",_("Terminal")),
484 "P" => array("select_printer.png",_("Printer")));
486 /* Assemble picture */
487 $type= $input['gosaGroupObjects'][0];
488 $type= preg_replace("/[^A-Z]/i","",$type);
489 if (isset($type[0])){
490 $p1['pic']= $conv[$type[0]][0];
491 $p1['tit']= $conv[$type[0]][1];
492 $p1['alt']= $type[0];
493 } else {
494 $p1['pic']= "empty.png";
495 $p1['tit']= "";
496 $p1['alt']= "";
497 }
498 if (isset($type[1])){
499 $p2['pic']= $conv[$type[1]][0];
500 $p2['alt']= $type[1];
501 $p2['tit']= $conv[$type[1]][1];
502 } else {
503 $p2['pic']= "empty.png";
504 $p2['alt']= "";
505 $p2['tit']= "";
506 }
507 $temp = "<img src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
508 $temp.= "<img src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
509 return ($temp);
510 }
513 function reload()
514 {
515 /* Get config */
516 $ogroupfilter= get_global('ogroupfilter');
518 /* Set base for all searches */
519 $base= $ogroupfilter['depselect'];
521 /* Regex filter? */
522 if ($ogroupfilter['regex'] != ""){
523 $regex= $ogroupfilter['regex'];
524 } else {
525 $regex= "*";
526 }
528 /* User filter? */
529 $this->oogrouplist= array();
531 /* Generate oogrouplist filter */
532 $filter= "";
534 if ($ogroupfilter['usergroups'] == "checked"){
535 $filter.= "(gosaGroupObjects=*U*)";
536 }
537 if ($ogroupfilter['groupgroups'] == "checked"){
538 $filter.= "(gosaGroupObjects=*G*)";
539 }
540 if ($ogroupfilter['appgroups'] == "checked"){
541 $filter.= "(gosaGroupObjects=*A*)";
542 }
543 if ($ogroupfilter['depgroups'] == "checked"){
544 $filter.= "(gosaGroupObjects=*D*)";
545 }
546 if ($ogroupfilter['servergroups'] == "checked"){
547 $filter.= "(gosaGroupObjects=*S*)";
548 }
549 if ($ogroupfilter['wsgroups'] == "checked"){
550 $filter.= "(gosaGroupObjects=*W*)";
551 }
552 if ($ogroupfilter['prtgroups'] == "checked"){
553 $filter.= "(gosaGroupObjects=*P*)";
554 }
555 if ($ogroupfilter['tcgroups'] == "checked"){
556 $filter.= "(gosaGroupObjects=*T*)";
557 }
558 if ($ogroupfilter['fongroups'] == "checked"){
559 $filter.= "(gosaGroupObjects=*F*)";
560 }
562 if ($filter != ""){
563 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
564 } else {
565 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
566 }
567 $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("*"), TRUE);
568 $this->ogrouplist= $res;
569 ksort ($this->ogrouplist);
570 reset ($this->ogrouplist);
573 /* NEW LIST MANAGMENT
574 * We also need to search for the departments
575 * So we are able to navigate like in konquerer
576 */
577 $base2 = preg_replace("/ou=people,/i","",$base);
579 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
580 TRUE, $base2, array("ou", "description"), TRUE);
582 $this->departments= array();
583 foreach ($res3 as $value){
584 if($value["description"][0]!=".."){
585 $this->departments[$value['dn']]= convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
586 }else{
587 $this->departments[$value['dn']]=$value["description"][0];
588 }
589 }
591 /* END NEW LIST MANAGMENT
592 */
597 }
599 }
601 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
602 ?>