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_/");
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("/_group_edit_/",$key)){
90 $type = preg_replace("/_group_edit_.*$/","",$key);
91 $s_action="edit";
92 $s_entry = preg_replace("/".$type."_group_edit_/i","",$key);
93 $_POST['arg'] = $type;
94 }
95 }
96 $s_entry = preg_replace("/_.$/","",$s_entry);
98 // Edit if
99 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
100 $s_action ="edit";
101 $s_entry = $_GET['id'];
102 }
105 /****************
106 Copy & Paste handling
107 ****************/
109 /* Display the copy & paste dialog, if it is currently open */
110 $ret = $this->copyPasteHandling($s_action,$s_entry);
111 if($ret){
112 return($ret);
113 }
115 /****************
116 Create a new object group
117 ****************/
119 /* New group? */
120 if ($s_action=="new"){
122 /* By default we set 'dn' to 'new', all relevant plugins will
123 react on this. */
124 $this->dn= "new";
126 /* Create new usertab object */
127 $this->ogroup= new ogrouptabs($this->config,$this->config->data['TABS']['OGROUPTABS'], $this->dn,"ogroups");
128 $this->ogroup->set_acl_base($this->DivListOGroup->selectedBase);
129 }
132 /****************
133 Delete object group
134 ****************/
136 if ($s_action=="del"){
138 /* Get 'dn' from posted 'uid' */
139 $this->dn= $this->ogrouplist[$s_entry]['dn'];
141 /* Load permissions for selected 'dn' and check if
142 we're allowed to remove this 'dn' */
143 $acl = $this->ui->get_permissions($this->dn,"ogroups");
144 if(preg_match("/d/",$acl)){
146 /* Check locking, save current plugin in 'back_plugin', so
147 the dialog knows where to return. */
148 if (($user= get_lock($this->dn)) != ""){
149 return(gen_locked_message ($user, $this->dn));
150 }
152 /* Lock the current entry, so nobody will edit it during deletion */
153 add_lock ($this->dn, $this->ui->dn);
154 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
155 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
156 } else {
158 /* Obviously the user isn't allowed to delete. Show message and
159 clean session. */
160 print_red (_("You are not allowed to delete this object group!"));
161 }
162 }
165 /****************
166 Delete confirmed
167 ****************/
169 /* Confirmation for deletion has been passed. Group should be deleted. */
170 if (isset($_POST['delete_group_confirm'])){
172 /* Some nice guy may send this as POST, so we've to check
173 for the permissions again. */
174 $acl = $this->ui->get_permissions($this->dn,"ogroups");
175 if(preg_match("/d/",$acl)){
177 /* Delete request is permitted, perform LDAP action */
178 $this->ogroup= new ogrouptabs($this->config,
179 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
180 $this->ogroup->delete ();
181 gosa_log ("Object group'".$this->dn."' has been removed");
182 unset ($this->ogroup);
183 $this->ogroup= NULL;
184 } else {
186 /* Normally this shouldn't be reached, send some extra
187 logs to notify the administrator */
188 print_red (_("You are not allowed to delete this object group!"));
189 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
190 }
192 /* Remove lock file after successfull deletion */
193 del_lock ($this->dn);
194 unset($_SESSION['objectinfo']);
195 }
198 /****************
199 Delete object group Canceled
200 ****************/
202 /* Delete group canceled? */
203 if (isset($_POST['delete_cancel'])){
204 del_lock ($this->dn);
205 unset($_SESSION['objectinfo']);
206 }
209 /****************
210 Edit group
211 ****************/
213 if (($s_action=="edit") && (! isset($this->ogroup->config)) ){
215 /* Get 'dn' from posted 'uid', must be unique */
216 $this->dn= $this->ogrouplist[$s_entry]['dn'];
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 everyone will get the
225 above dialog */
226 add_lock ($this->dn, $this->ui->dn);
228 /* Register grouptab to trigger edit dialog */
229 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $this->dn, "ogroups");
230 $this->ogroup->set_acl_base($this->dn);
231 $_SESSION['objectinfo']= $this->dn;
232 }
235 /****************
236 Edit finished save
237 ****************/
239 /* Finish button has been pressed */
240 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->ogroup->config)) ){
242 /* Check tabs, will feed message array */
243 $message= $this->ogroup->check();
245 /* Save, or display error message? */
246 if (count($message) == 0){
248 /* Save user data to ldap */
249 $this->ogroup->save();
250 gosa_log ("Object group'".$this->dn."' has been saved");
252 if (!isset($_POST['edit_apply'])){
253 /* Group has been saved successfully, remove lock from
254 LDAP. */
255 if ($this->dn != "new"){
256 del_lock ($this->dn);
257 }
259 unset ($this->ogroup);
260 $this->ogroup= NULL;
261 unset ($_SESSION['objectinfo']);
262 }
263 } else {
264 /* Ok. There seem to be errors regarding to the tab data,
265 show message and continue as usual. */
266 show_errors($message);
267 }
268 }
271 /****************
272 Cancel edit object group
273 ****************/
275 /* Cancel dialogs */
276 if ((isset($_POST['edit_cancel'])) && (isset($this->ogroup->dn))){
277 del_lock ($this->ogroup->dn);
278 unset ($this->ogroup);
279 $this->ogroup= NULL;
280 unset($_SESSION['objectinfo']);
281 }
284 /****************
285 Display open dialogs
286 ****************/
288 /* Show dialog if object is present */
289 if (isset($this->ogroup->config)){
290 $display= $this->ogroup->execute();
292 /* Don't show buttons if tab dialog requests this */
293 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
294 $display.= "<p style=\"text-align:right\">\n";
295 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
296 $display.= " \n";
297 if ($this->dn != "new"){
298 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
299 $display.= " \n";
300 }
301 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
302 $display.= "</p>";
303 }
304 return ($display);
305 }
308 /****************
309 Display list
310 ****************/
312 /* Check if there is a snapshot dialog open */
313 $base = $this->DivListOGroup->selectedBase;
314 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
315 return($str);
316 }
318 /* Display dialog with group list */
319 $this->DivListOGroup->parent = $this;
320 $this->DivListOGroup->execute();
322 /* Add departments if subsearch is disabled */
323 if(!$this->DivListOGroup->SubSearch){
324 $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4);
325 }
326 $this->reload ();
327 $this->DivListOGroup->setEntries($this->ogrouplist);
328 return($this->DivListOGroup->Draw());
329 }
332 /* Return departments, that will be included within snapshot detection */
333 function get_used_snapshot_bases()
334 {
335 return(array(get_groups_ou().$this->DivListOGroup->selectedBase));
336 }
340 function convert_list($input)
341 {
342 $temp= "";
344 $conv= array(
345 "U" => array("select_user.png" ,_("User") , "ogroup"),
346 "G" => array("select_groups.png" ,_("Group") , "ogroup"),
347 "A" => array("select_application.png" ,_("Application") , "ogroup"),
348 "D" => array("select_department.png" ,_("Department") , "ogroup"),
349 "S" => array("select_server.png" ,_("Server") , "ogroup"),
350 "F" => array("select_phone.png" ,_("Phone") , "phonequeue"),
351 "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
352 "T" => array("select_terminal.png" ,_("Terminal") , "termgroup"),
353 "P" => array("select_printer.png" ,_("Printer") , "ogroup"));
355 /* Assemble picture */
356 $type= $input['gosaGroupObjects'][0];
357 $type= preg_replace("/[^A-Z]/i","",$type);
358 if (isset($type[0])){
359 $p1['pic']= $conv[$type[0]][0];
360 $p1['tit']= $conv[$type[0]][1];
361 $p1['alt']= $type[0];
362 $p1['lnk']= $conv[$type[0]][2];
363 $html_object_1 = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' ";
364 } else {
365 $p1['pic']= "empty.png";
366 $p1['tit']= "";
367 $p1['alt']= "";
368 $p1['lnk']= "";//$conv[$type[0]][2];
369 $html_object_1 = "<img ";
370 }
372 if (isset($type[1])){
373 $p2['pic']= $conv[$type[1]][0];
374 $p2['alt']= $type[1];
375 $p2['tit']= $conv[$type[1]][1];
376 $p2['lnk']= $conv[$type[1]][2];
377 $html_object_2 = "<input type='image' name='".$p2['lnk']."_group_edit_%KEY' ";
378 } else {
379 $p2['pic']= "empty.png";
380 $p2['alt']= "";
381 $p2['tit']= "";
382 $p2['lnk']= ""; //$conv[$type[0]][2];
383 $html_object_2 = "<img ";
384 }
386 $temp = $html_object_1." class='center' id='iconA".preg_replace("/_/","",$p1['lnk']."_group_edit_%KEY")."'
387 src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
388 $temp.= $html_object_2." class='center' id='iconB".preg_replace("/_/","",$p2['lnk']."_group_edit_%KEY")."'
389 src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
390 return ($temp);
391 }
394 function reload()
395 {
396 /* Set base for all searches && initialise some vars */
397 $this->ogrouplist= array();
398 $base = $this->DivListOGroup->selectedBase;
399 $filter = "(gosaGroupObjects=[])";
400 $Regex = $this->DivListOGroup->Regex;
402 $chk = array(
403 "UserGroups" => "(gosaGroupObjects=*U*)" ,
404 "GroupGroups" => "(gosaGroupObjects=*G*)" ,
405 "ApplicationGroups" => "(gosaGroupObjects=*A*)" ,
406 "DepartmentGroups" => "(gosaGroupObjects=*D*)" ,
407 "ServerGroups" => "(gosaGroupObjects=*S*)" ,
408 "WorkstationGroups" => "(gosaGroupObjects=*W*)" ,
409 "TerminalGroups" => "(gosaGroupObjects=*T*)" ,
410 "PrinterGroups" => "(gosaGroupObjects=*P*)" ,
411 "PhoneGroups" => "(gosaGroupObjects=*F*)" );
412 /* Create filter */
413 foreach($chk as $chkBox => $FilterPart){
414 if($this->DivListOGroup->$chkBox){
415 $filter .= $FilterPart;
416 }
417 }
418 $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
420 if($this->DivListOGroup->SubSearch){
421 $res= get_list($filter, "ogroups", $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
422 }else{
423 $res= get_list($filter, "ogroups", get_groups_ou().$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
424 }
426 $this->ogrouplist= $res;
427 ksort ($this->ogrouplist);
428 reset ($this->ogrouplist);
429 $tmp=array();
430 foreach($this->ogrouplist as $tkey => $val ){
431 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
432 }
433 ksort($tmp);
434 $this->ogrouplist=array();
435 foreach($tmp as $val){
436 $this->ogrouplist[]=$val;
437 }
438 reset ($this->ogrouplist);
439 }
442 function copyPasteHandling($s_action,$s_entry)
443 {
444 if($this->CopyPasteHandler){
446 /* Paste copied/cutted object in here
447 */
448 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
449 $this->CopyPasteHandler->save_object();
450 $this->CopyPasteHandler->SetVar("base", $this->DivListOGroup->selectedBase);
451 return($this->CopyPasteHandler->execute());
452 }
454 /* Copy current object to CopyHandler
455 */
456 if($s_action == "copy"){
459 $this->CopyPasteHandler->Clear();
460 $dn = $this->ogrouplist[$s_entry]['dn'];
462 /* Check acls */
463 $acl_all= $this->ui->has_complete_category_acls($dn,"ogroups");
464 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
465 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
466 $objNew = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], "new");
468 $types_of_tabs = $obj->by_object['ogroup']->gosaGroupObjects;
469 $objNew->by_object['ogroup']->gosaGroupObjects = $types_of_tabs;
470 $objNew->reload($types_of_tabs);
472 $this->CopyPasteHandler->Copy($obj,$objNew);
473 }
474 }
476 /* Copy current object to CopyHandler
477 */
478 if($s_action == "cut"){
479 $this->CopyPasteHandler->Clear();
480 $dn = $this->ogrouplist[$s_entry]['dn'];
482 /* Check acls */
483 $acl_all= $this->ui->has_complete_category_acls($dn,"ogroups");
484 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
485 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
486 $this->CopyPasteHandler->Cut($obj);
487 }
488 }
489 }
490 }
493 function save_object()
494 {
495 $this->DivListOGroup->save_object();
496 }
498 }
500 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
501 ?>