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 /* Only perform copy / paste if it is enabled
115 */
117 /* Display the copy & paste dialog, if it is currently open */
118 $ret = $this->copyPasteHandling($s_action,$s_entry);
119 if($ret){
120 return($ret);
121 }
123 /****************
124 Create a new object group
125 ****************/
127 /* New group? */
128 if ($s_action=="new"){
130 /* By default we set 'dn' to 'new', all relevant plugins will
131 react on this. */
132 $this->dn= "new";
134 /* Create new usertab object */
135 $this->ogroup= new ogrouptabs($this->config,
136 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
137 }
140 /****************
141 Delete object group
142 ****************/
144 if ($s_action=="del"){
146 /* Get 'dn' from posted 'uid' */
147 $this->dn= $this->ogrouplist[$s_entry]['dn'];
149 /* Load permissions for selected 'dn' and check if
150 we're allowed to remove this 'dn' */
151 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
152 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
153 if (chkacl($this->acl, "delete") == ""){
155 /* Check locking, save current plugin in 'back_plugin', so
156 the dialog knows where to return. */
157 if (($user= get_lock($this->dn)) != ""){
158 return(gen_locked_message ($user, $this->dn));
159 }
161 /* Lock the current entry, so nobody will edit it during deletion */
162 add_lock ($this->dn, $this->ui->dn);
163 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
164 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
165 } else {
167 /* Obviously the user isn't allowed to delete. Show message and
168 clean session. */
169 print_red (_("You are not allowed to delete this object group!"));
170 }
171 }
174 /****************
175 Delete confirmed
176 ****************/
178 /* Confirmation for deletion has been passed. Group should be deleted. */
179 if (isset($_POST['delete_group_confirm'])){
181 /* Some nice guy may send this as POST, so we've to check
182 for the permissions again. */
183 if (chkacl($this->acl, "delete") == ""){
185 /* Delete request is permitted, perform LDAP action */
186 $this->ogroup= new ogrouptabs($this->config,
187 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
188 $this->ogroup->set_acl(array($this->acl));
189 $this->ogroup->delete ();
190 gosa_log ("Object group'".$this->dn."' has been removed");
191 unset ($this->ogroup);
192 $this->ogroup= NULL;
193 } else {
195 /* Normally this shouldn't be reached, send some extra
196 logs to notify the administrator */
197 print_red (_("You are not allowed to delete this object group!"));
198 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
199 }
201 /* Remove lock file after successfull deletion */
202 del_lock ($this->dn);
203 unset($_SESSION['objectinfo']);
204 }
207 /****************
208 Delete object group Canceled
209 ****************/
211 /* Delete group canceled? */
212 if (isset($_POST['delete_cancel'])){
213 del_lock ($this->dn);
214 unset($_SESSION['objectinfo']);
215 }
218 /****************
219 Edit group
220 ****************/
222 if (($s_action=="edit") && (! isset($this->ogroup->config)) ){
224 /* Get 'dn' from posted 'uid', must be unique */
225 $this->dn= $this->ogrouplist[$s_entry]['dn'];
227 /* Check locking, save current plugin in 'back_plugin', so
228 the dialog knows where to return. */
229 if (($user= get_lock($this->dn)) != ""){
230 return(gen_locked_message ($user, $this->dn));
231 }
233 /* Lock the current entry, so everyone will get the
234 above dialog */
235 add_lock ($this->dn, $this->ui->dn);
237 /* Set up the users ACL's for this 'dn' */
238 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
240 /* Register grouptab to trigger edit dialog */
241 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
242 $this->dn);
243 $this->ogroup->set_acl($acl);
244 $_SESSION['objectinfo']= $this->dn;
245 }
248 /****************
249 Edit finished save
250 ****************/
252 /* Finish button has been pressed */
253 if ((isset($_POST['edit_finish'])) && (isset($this->ogroup->config)) ){
255 /* Check tabs, will feed message array */
256 $message= $this->ogroup->check();
258 /* Save, or display error message? */
259 if (count($message) == 0){
261 /* Save user data to ldap */
262 $this->ogroup->save();
263 gosa_log ("Object group'".$this->dn."' has been saved");
265 /* Group has been saved successfully, remove lock from
266 LDAP. */
267 if ($this->dn != "new"){
268 del_lock ($this->dn);
269 }
271 unset ($this->ogroup);
272 $this->ogroup= NULL;
273 unset ($_SESSION['objectinfo']);
275 } else {
276 /* Ok. There seem to be errors regarding to the tab data,
277 show message and continue as usual. */
278 show_errors($message);
279 }
280 }
283 /****************
284 Cancel edit object group
285 ****************/
287 /* Cancel dialogs */
288 if ((isset($_POST['edit_cancel'])) && (isset($this->ogroup->dn))){
289 del_lock ($this->ogroup->dn);
290 unset ($this->ogroup);
291 $this->ogroup= NULL;
292 unset($_SESSION['objectinfo']);
293 }
296 /****************
297 Display open dialogs
298 ****************/
300 /* Show dialog if object is present */
301 if (isset($this->ogroup->config)){
302 $display= $this->ogroup->execute();
304 /* Don't show buttons if tab dialog requests this */
305 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
306 $display.= "<p style=\"text-align:right\">\n";
307 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
308 $display.= " \n";
309 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
310 $display.= "</p>";
311 }
312 return ($display);
313 }
316 /****************
317 Display list
318 ****************/
320 /* Display dialog with group list */
321 $this->DivListOGroup->parent = $this;
322 $this->DivListOGroup->execute();
324 /* Add departments if subsearch is disabled */
325 if(!$this->DivListOGroup->SubSearch){
326 $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4);
327 }
328 $this->reload ();
329 $this->DivListOGroup->setEntries($this->ogrouplist);
330 return($this->DivListOGroup->Draw());
331 }
334 function convert_list($input)
335 {
336 $temp= "";
338 $conv= array(
339 "U" => array("select_user.png" ,_("User") , "ogroup"),
340 "G" => array("select_groups.png" ,_("Group") , "ogroup"),
341 "A" => array("select_application.png" ,_("Application") , "ogroup"),
342 "D" => array("select_department.png" ,_("Department") , "ogroup"),
343 "S" => array("select_server.png" ,_("Server") , "ogroup"),
344 "F" => array("select_phone.png" ,_("Phone") , "phonequeue"),
345 "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
346 "T" => array("select_terminal.png" ,_("Terminal") , "termgroup"),
347 "P" => array("select_printer.png" ,_("Printer") , "ogroup"));
349 /* Assemble picture */
350 $type= $input['gosaGroupObjects'][0];
351 $type= preg_replace("/[^A-Z]/i","",$type);
352 if (isset($type[0])){
353 $p1['pic']= $conv[$type[0]][0];
354 $p1['tit']= $conv[$type[0]][1];
355 $p1['alt']= $type[0];
356 $p1['lnk']= $conv[$type[0]][2];
357 } else {
358 $p1['pic']= "empty.png";
359 $p1['tit']= "";
360 $p1['alt']= "";
361 $p1['lnk']= "";//$conv[$type[0]][2];
362 }
364 if (isset($type[1])){
365 $p2['pic']= $conv[$type[1]][0];
366 $p2['alt']= $type[1];
367 $p2['tit']= $conv[$type[1]][1];
368 $p2['lnk']= $conv[$type[1]][2];
369 } else {
370 $p2['pic']= "empty.png";
371 $p2['alt']= "";
372 $p2['tit']= "";
373 $p2['lnk']= ""; //$conv[$type[0]][2];
374 }
375 $temp = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' class='center'
376 src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
377 $temp.= "<input type='image' name='".$p2['lnk']."_group_edit_%KEY'class='center'
378 src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
379 return ($temp);
380 }
383 function reload()
384 {
385 /* Set base for all searches && initialise some vars */
386 $this->ogrouplist= array();
387 $base = $this->DivListOGroup->selectedBase;
388 $filter = "(gosaGroupObjects=[])";
389 $Regex = $this->DivListOGroup->Regex;
391 $chk = array(
392 "UserGroups" => "(gosaGroupObjects=*U*)" ,
393 "GroupGroups" => "(gosaGroupObjects=*G*)" ,
394 "ApplicationGroups" => "(gosaGroupObjects=*A*)" ,
395 "DepartmentGroups" => "(gosaGroupObjects=*D*)" ,
396 "ServerGroups" => "(gosaGroupObjects=*S*)" ,
397 "WorkstationGroups" => "(gosaGroupObjects=*W*)" ,
398 "TerminalGroups" => "(gosaGroupObjects=*T*)" ,
399 "PrinterGroups" => "(gosaGroupObjects=*P*)" ,
400 "PhoneGroups" => "(gosaGroupObjects=*F*)" );
401 /* Create filter */
402 foreach($chk as $chkBox => $FilterPart){
403 if($this->DivListOGroup->$chkBox){
404 $filter .= $FilterPart;
405 }
406 }
407 $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
409 if($this->DivListOGroup->SubSearch){
410 $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
411 }else{
412 $res= get_list($filter, $this->ui->subtreeACL, get_groups_ou().$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
413 }
415 $this->ogrouplist= $res;
416 ksort ($this->ogrouplist);
417 reset ($this->ogrouplist);
418 $tmp=array();
419 foreach($this->ogrouplist as $tkey => $val ){
420 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
421 }
422 ksort($tmp);
423 $this->ogrouplist=array();
424 foreach($tmp as $val){
425 $this->ogrouplist[]=$val;
426 }
427 reset ($this->ogrouplist);
428 }
430 function save_object()
431 {
432 $this->DivListOGroup->save_object();
433 }
436 function copyPasteHandling($s_action,$s_entry)
437 {
439 if($this->CopyPasteHandler){
441 /* Paste copied/cutted object in here
442 */
443 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
444 $this->CopyPasteHandler->save_object();
445 $this->CopyPasteHandler->SetVar("base", $this->DivListOGroup->selectedBase);
446 return($this->CopyPasteHandler->execute());
447 }
449 /* Copy current object to CopyHandler
450 */
451 if($s_action == "copy"){
452 $this->CopyPasteHandler->Clear();
453 $dn = $this->ogrouplist[$s_entry]['dn'];
454 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
455 $objNew = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], "new");
456 $this->CopyPasteHandler->Copy($obj,$objNew);
457 }
459 /* Copy current object to CopyHandler
460 */
461 if($s_action == "cut"){
462 $this->CopyPasteHandler->Clear();
463 $dn = $this->ogrouplist[$s_entry]['dn'];
464 $obj = new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
465 $this->CopyPasteHandler->Cut($obj);
466 }
467 }
468 }
469 }
471 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
472 ?>