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