4f4317233f6c95f2afdd5808c064480a3db835c6
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 var $CopyPasteHandler = NULL;
35 var $DivListOGroup = NULL;
37 function ogroupManagement ($config, $dn= NULL)
38 {
39 /* Include config object */
40 $this->config= $config;
41 $this->ui= get_userinfo();
43 /* Copy & Paste enabled ?
44 */
45 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE'] ))){
46 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
47 }
49 /* Div lsit management */
50 $this->DivListOGroup = new divListOGroup($this->config,$this);
51 }
53 function execute()
54 {
55 /* Call parent execute */
56 plugin::execute();
58 /****************
59 Variable intialisation && Check posts for commands
60 ****************/
62 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/","/^item_selected/","/^remove_multiple_ogroups/");
64 $smarty = get_smarty();
65 $s_action = "";
66 $s_entry = "";
68 /* Test Posts */
69 foreach($_POST as $key => $val){
70 // Post for delete
71 if(preg_match("/^group_del.*/",$key)){
72 $s_action = "del";
73 $s_entry = preg_replace("/^group_".$s_action."_/i","",$key);
74 // Post for edit
75 }elseif(preg_match("/^group_edit_.*/",$key)){
76 $s_action="edit";
77 $s_entry = preg_replace("/^group_".$s_action."_/i","",$key);
78 // Post for new
79 }elseif(preg_match("/^group_new.*/",$key)){
80 $s_action="new";
81 }elseif(preg_match("/^editPaste.*/i",$key)){
82 $s_action="editPaste";
83 }elseif(preg_match("/^copy_.*/",$key)){
84 $s_action="copy";
85 $s_entry = preg_replace("/^copy_/i","",$key);
86 }elseif(preg_match("/^cut_.*/",$key)){
87 $s_action="cut";
88 $s_entry = preg_replace("/^cut_/i","",$key);
89 }elseif(preg_match("/^remove_multiple_ogroups/",$key)){
90 $s_action="del_multiple";
91 }elseif(preg_match("/_group_edit_/",$key)){
92 $type = preg_replace("/_group_edit_.*$/","",$key);
93 $s_action="edit";
94 $s_entry = preg_replace("/".$type."_group_edit_/i","",$key);
95 $_POST['arg'] = $type;
96 }
97 }
98 $s_entry = preg_replace("/_.$/","",$s_entry);
100 // Edit if
101 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
102 $s_action ="edit";
103 $s_entry = $_GET['id'];
104 }
107 /****************
108 Copy & Paste handling
109 ****************/
111 /* Display the copy & paste dialog, if it is currently open */
112 $ret = $this->copyPasteHandling($s_action,$s_entry);
113 if($ret){
114 return($ret);
115 }
117 /****************
118 Create a new object group
119 ****************/
121 /* New group? */
122 if ($s_action=="new"){
124 /* By default we set 'dn' to 'new', all relevant plugins will
125 react on this. */
126 $this->dn= "new";
128 /* Create new usertab object */
129 $this->ogroup= new ogrouptabs($this->config,$this->config->data['TABS']['OGROUPTABS'], $this->dn,"ogroups");
130 $this->ogroup->set_acl_base($this->DivListOGroup->selectedBase);
131 }
139 /********************
140 Delete MULTIPLE entries requested, display confirm dialog
141 ********************/
142 if ($s_action=="del_multiple"){
143 $ids = $this->list_get_selected_items();
144 if(count($ids)){
145 foreach($ids as $id){
146 $dn = $this->ogrouplist[$id]['dn'];
147 if (($user= get_lock($dn)) != ""){
148 return(gen_locked_message ($user, $dn));
149 }
150 $this->dns[$id] = $dn;
151 }
152 $dns_names = "<br><pre>";
153 foreach($this->dns as $dn){
154 add_lock ($dn, $this->ui->dn);
155 $dns_names .= $dn."\n";
156 }
157 $dns_names .="</pre>";
158 /* Lock the current entry, so nobody will edit it during deletion */
159 $smarty->assign("info", sprintf(_("You're about to delete the following object group(s) %s"), @LDAP::fix($dns_names)));
160 $smarty->assign("multiple", true);
161 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
162 }
163 }
166 /********************
167 Delete MULTIPLE entries confirmed
168 ********************/
170 /* Confirmation for deletion has been passed. Users should be deleted. */
171 if (isset($_POST['delete_multiple_ogroup_confirm'])){
173 /* Remove user by user and check acls before removeing them */
174 foreach($this->dns as $key => $dn){
176 $acl = $this->ui->get_permissions($dn, "ogroups");
177 if (preg_match('/d/', $acl)){
179 /* Delete request is permitted, perform LDAP action */
180 $this->ogroup= new ogrouptabs($this->config,$this->config->data['TABS']['OGROUPTABS'], $dn);
181 $this->ogroup->delete ();
182 gosa_log ("Object group'".$this->dn."' has been removed");
183 unset ($this->ogroup);
184 $this->ogroup= NULL;
185 } else {
187 /* Normally this shouldn't be reached, send some extra
188 logs to notify the administrator */
189 print_red (_("You are not allowed to delete this object group!"));
190 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
191 }
192 /* Remove lock file after successfull deletion */
193 del_lock ($dn);
194 unset($this->dns[$key]);
195 }
196 }
199 /********************
200 Delete MULTIPLE entries Canceled
201 ********************/
203 /* Remove lock */
204 if(isset($_POST['delete_multiple_ogroup_cancel'])){
205 foreach($this->dns as $key => $dn){
206 del_lock ($dn);
207 unset($this->dns[$key]);
208 }
209 }
212 /****************
213 Delete object group
214 ****************/
216 if ($s_action=="del"){
218 /* Get 'dn' from posted 'uid' */
219 $this->dn= $this->ogrouplist[$s_entry]['dn'];
221 /* Load permissions for selected 'dn' and check if
222 we're allowed to remove this 'dn' */
223 $acl = $this->ui->get_permissions($this->dn,"ogroups");
224 if(preg_match("/d/",$acl)){
226 /* Check locking, save current plugin in 'back_plugin', so
227 the dialog knows where to return. */
228 if (($user= get_lock($this->dn)) != ""){
229 return(gen_locked_message ($user, $this->dn));
230 }
232 /* Lock the current entry, so nobody will edit it during deletion */
233 add_lock ($this->dn, $this->ui->dn);
234 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
235 $smarty->assign("multiple", false);
236 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
237 } else {
239 /* Obviously the user isn't allowed to delete. Show message and
240 clean session. */
241 print_red (_("You are not allowed to delete this object group!"));
242 }
243 }
246 /****************
247 Delete confirmed
248 ****************/
250 /* Confirmation for deletion has been passed. Group should be deleted. */
251 if (isset($_POST['delete_group_confirm'])){
253 /* Some nice guy may send this as POST, so we've to check
254 for the permissions again. */
255 $acl = $this->ui->get_permissions($this->dn,"ogroups");
256 if(preg_match("/d/",$acl)){
258 /* Delete request is permitted, perform LDAP action */
259 $this->ogroup= new ogrouptabs($this->config,
260 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
261 $this->ogroup->delete ();
262 gosa_log ("Object group'".$this->dn."' has been removed");
263 unset ($this->ogroup);
264 $this->ogroup= NULL;
265 } else {
267 /* Normally this shouldn't be reached, send some extra
268 logs to notify the administrator */
269 print_red (_("You are not allowed to delete this object group!"));
270 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
271 }
273 /* Remove lock file after successfull deletion */
274 del_lock ($this->dn);
275 unset($_SESSION['objectinfo']);
276 }
279 /****************
280 Delete object group Canceled
281 ****************/
283 /* Delete group canceled? */
284 if (isset($_POST['delete_cancel'])){
285 del_lock ($this->dn);
286 unset($_SESSION['objectinfo']);
287 }
290 /****************
291 Edit group
292 ****************/
294 if (($s_action=="edit") && (! isset($this->ogroup->config)) ){
296 /* Get 'dn' from posted 'uid', must be unique */
297 $this->dn= $this->ogrouplist[$s_entry]['dn'];
299 /* Check locking, save current plugin in 'back_plugin', so
300 the dialog knows where to return. */
301 if (($user= get_lock($this->dn)) != ""){
302 return(gen_locked_message ($user, $this->dn));
303 }
305 /* Lock the current entry, so everyone will get the
306 above dialog */
307 add_lock ($this->dn, $this->ui->dn);
309 /* Register grouptab to trigger edit dialog */
310 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $this->dn, "ogroups");
311 $this->ogroup->set_acl_base($this->dn);
312 $_SESSION['objectinfo']= $this->dn;
313 }
316 /****************
317 Edit finished save
318 ****************/
320 /* Finish button has been pressed */
321 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->ogroup->config)) ){
323 /* Check tabs, will feed message array */
324 $message= $this->ogroup->check();
326 /* Save, or display error message? */
327 if (count($message) == 0){
329 /* Save user data to ldap */
330 $this->ogroup->save();
331 gosa_log ("Object group'".$this->dn."' has been saved");
333 if (!isset($_POST['edit_apply'])){
334 /* Group has been saved successfully, remove lock from
335 LDAP. */
336 if ($this->dn != "new"){
337 del_lock ($this->dn);
338 }
340 unset ($this->ogroup);
341 $this->ogroup= NULL;
342 unset ($_SESSION['objectinfo']);
343 }
344 } else {
345 /* Ok. There seem to be errors regarding to the tab data,
346 show message and continue as usual. */
347 show_errors($message);
348 }
349 }
352 /****************
353 Cancel edit object group
354 ****************/
356 /* Cancel dialogs */
357 if ((isset($_POST['edit_cancel'])) && (isset($this->ogroup->dn))){
358 del_lock ($this->ogroup->dn);
359 unset ($this->ogroup);
360 $this->ogroup= NULL;
361 unset($_SESSION['objectinfo']);
362 }
365 /****************
366 Display open dialogs
367 ****************/
369 /* Show dialog if object is present */
370 if (isset($this->ogroup->config)){
371 $display= $this->ogroup->execute();
373 /* Don't show buttons if tab dialog requests this */
374 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
375 $display.= "<p style=\"text-align:right\">\n";
376 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
377 $display.= " \n";
378 if ($this->dn != "new"){
379 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
380 $display.= " \n";
381 }
382 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
383 $display.= "</p>";
384 }
385 return ($display);
386 }
389 /****************
390 Display list
391 ****************/
393 /* Check if there is a snapshot dialog open */
394 $base = $this->DivListOGroup->selectedBase;
395 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
396 return($str);
397 }
399 /* Display dialog with group list */
400 $this->DivListOGroup->parent = $this;
401 $this->DivListOGroup->execute();
403 /* Add departments if subsearch is disabled */
404 if(!$this->DivListOGroup->SubSearch){
405 $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4,1);
406 }
407 $this->reload ();
408 $this->DivListOGroup->setEntries($this->ogrouplist);
409 return($this->DivListOGroup->Draw());
410 }
413 /* Return departments, that will be included within snapshot detection */
414 function get_used_snapshot_bases()
415 {
416 return(array(get_groups_ou().$this->DivListOGroup->selectedBase));
417 }
421 function convert_list($input)
422 {
423 $temp= "";
425 $conv= array(
426 "U" => array("select_user.png" ,_("User") , "ogroup"),
427 "G" => array("select_groups.png" ,_("Group") , "ogroup"),
428 "A" => array("select_application.png" ,_("Application") , "ogroup"),
429 "D" => array("select_department.png" ,_("Department") , "ogroup"),
430 "S" => array("select_server.png" ,_("Server") , "ogroup"),
431 "F" => array("select_phone.png" ,_("Phone") , "phonequeue"),
432 "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
433 "T" => array("select_terminal.png" ,_("Terminal") , "termgroup"),
434 "P" => array("select_printer.png" ,_("Printer") , "ogroup"));
436 /* Assemble picture */
437 $type= $input['gosaGroupObjects'][0];
438 $type= preg_replace("/[^A-Z]/i","",$type);
439 if (isset($type[0])){
440 $p1['pic']= $conv[$type[0]][0];
441 $p1['tit']= $conv[$type[0]][1];
442 $p1['alt']= $type[0];
443 $p1['lnk']= $conv[$type[0]][2];
444 $html_object_1 = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' ";
445 } else {
446 $p1['pic']= "empty.png";
447 $p1['tit']= "";
448 $p1['alt']= "";
449 $p1['lnk']= "";//$conv[$type[0]][2];
450 $html_object_1 = "<img ";
451 }
453 if (isset($type[1])){
454 $p2['pic']= $conv[$type[1]][0];
455 $p2['alt']= $type[1];
456 $p2['tit']= $conv[$type[1]][1];
457 $p2['lnk']= $conv[$type[1]][2];
458 $html_object_2 = "<input type='image' name='".$p2['lnk']."_group_edit_%KEY' ";
459 } else {
460 $p2['pic']= "empty.png";
461 $p2['alt']= "";
462 $p2['tit']= "";
463 $p2['lnk']= ""; //$conv[$type[0]][2];
464 $html_object_2 = "<img ";
465 }
467 $temp = $html_object_1." class='center' id='iconA".preg_replace("/_/","",$p1['lnk']."_group_edit_%KEY")."'
468 src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
469 $temp.= $html_object_2." class='center' id='iconB".preg_replace("/_/","",$p2['lnk']."_group_edit_%KEY")."'
470 src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
471 return ($temp);
472 }
475 function reload()
476 {
477 /* Set base for all searches && initialise some vars */
478 $this->ogrouplist= array();
479 $base = $this->DivListOGroup->selectedBase;
480 $filter = "(gosaGroupObjects=[])";
481 $Regex = $this->DivListOGroup->Regex;
483 $chk = array(
484 "UserGroups" => "(gosaGroupObjects=*U*)" ,
485 "GroupGroups" => "(gosaGroupObjects=*G*)" ,
486 "ApplicationGroups" => "(gosaGroupObjects=*A*)" ,
487 "DepartmentGroups" => "(gosaGroupObjects=*D*)" ,
488 "ServerGroups" => "(gosaGroupObjects=*S*)" ,
489 "WorkstationGroups" => "(gosaGroupObjects=*W*)" ,
490 "TerminalGroups" => "(gosaGroupObjects=*T*)" ,
491 "PrinterGroups" => "(gosaGroupObjects=*P*)" ,
492 "PhoneGroups" => "(gosaGroupObjects=*F*)" );
493 /* Create filter */
494 foreach($chk as $chkBox => $FilterPart){
495 if($this->DivListOGroup->$chkBox){
496 $filter .= $FilterPart;
497 }
498 }
499 $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
501 if($this->DivListOGroup->SubSearch){
502 $res= get_list($filter, "ogroups", $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
503 }else{
504 $res= get_list($filter, "ogroups", get_groups_ou().$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
505 }
507 $this->ogrouplist= $res;
508 ksort ($this->ogrouplist);
509 reset ($this->ogrouplist);
510 $tmp=array();
511 foreach($this->ogrouplist as $tkey => $val ){
512 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
513 }
514 ksort($tmp);
515 $this->ogrouplist=array();
516 foreach($tmp as $val){
517 $this->ogrouplist[]=$val;
518 }
519 reset ($this->ogrouplist);
520 }
523 function list_get_selected_items()
524 {
525 $ids = array();
526 foreach($_POST as $name => $value){
527 if(preg_match("/^item_selected_[0-9]*$/",$name)){
528 $id = preg_replace("/^item_selected_/","",$name);
529 $ids[$id] = $id;
530 }
531 }
532 return($ids);
533 }
536 function copyPasteHandling($s_action,$s_entry)
537 {
538 if($this->CopyPasteHandler){
540 /* Paste copied/cutted object in here
541 */
542 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
543 $this->CopyPasteHandler->save_object();
544 $this->CopyPasteHandler->SetVar("base", $this->DivListOGroup->selectedBase);
545 return($this->CopyPasteHandler->execute());
546 }
548 /* Copy current object to CopyHandler
549 */
550 if($s_action == "copy"){
553 $this->CopyPasteHandler->Clear();
554 $dn = $this->ogrouplist[$s_entry]['dn'];
556 /* Check acls */
557 $acl_all= $this->ui->has_complete_category_acls($dn,"ogroups");
558 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
559 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
560 $objNew = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], "new");
562 $types_of_tabs = $obj->by_object['ogroup']->gosaGroupObjects;
563 $objNew->by_object['ogroup']->gosaGroupObjects = $types_of_tabs;
564 $objNew->reload($types_of_tabs);
566 $this->CopyPasteHandler->Copy($obj,$objNew);
567 }
568 }
570 /* Copy current object to CopyHandler
571 */
572 if($s_action == "cut"){
573 $this->CopyPasteHandler->Clear();
574 $dn = $this->ogrouplist[$s_entry]['dn'];
576 /* Check acls */
577 $acl_all= $this->ui->has_complete_category_acls($dn,"ogroups");
578 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
579 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
580 $this->CopyPasteHandler->Cut($obj);
581 }
582 }
583 }
584 }
587 function save_object()
588 {
589 $this->DivListOGroup->save_object();
590 }
592 }
594 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
595 ?>