~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to plugins/admin/ogroups/class_ogroupManagement.inc

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
   This code is part of GOsa (https://gosa.gonicus.de)
4
 
   Copyright (C) 2004 Cajus Pollmeier
5
 
 
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.
10
 
 
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.
15
 
 
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";
21
 
 
22
 
class ogroupManagement extends plugin
23
 
{
24
 
  /* Definitions */
25
 
  var $plHeadline= "Object groups";
26
 
  var $plDescription= "This does something";
27
 
 
28
 
  /* attribute list for save action */
29
 
  var $attributes= array();
30
 
  var $objectclasses= array();
31
 
  var $obtypes= array();
32
 
  var $ogroup;
33
 
 
34
 
  var $CopyPasteHandler = NULL;
35
 
  var $DivListOGroup    = NULL;
36
 
 
37
 
  function ogroupManagement ($config, $dn= NULL)
38
 
  {
39
 
    /* Include config object */
40
 
    $this->config= $config;
41
 
    $this->ui= get_userinfo();
42
 
 
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
 
    }
48
 
 
49
 
    /* Div lsit management */
50
 
    $this->DivListOGroup = new divListOGroup($this->config,$this);
51
 
  }
52
 
 
53
 
  function execute()
54
 
  {
55
 
    /* Call parent execute */
56
 
    plugin::execute();
57
 
 
58
 
    /****************
59
 
      Variable intialisation && Check posts for commands  
60
 
     ****************/
61
 
 
62
 
    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
63
 
 
64
 
    $smarty     = get_smarty();
65
 
    $s_action   = "";
66
 
    $s_entry    = "";
67
 
 
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);
102
 
 
103
 
    // Edit if
104
 
    if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
105
 
      $s_action ="edit";
106
 
      $s_entry  = $_GET['id'];
107
 
    }
108
 
 
109
 
 
110
 
    /****************
111
 
      Copy & Paste handling 
112
 
     ****************/
113
 
 
114
 
    /* Only perform copy / paste if it is enabled
115
 
     */
116
 
 
117
 
 
118
 
    /********************
119
 
      Copy & Paste Handling  ...
120
 
     ********************/
121
 
 
122
 
    /* Only perform copy&paste requests if it is enabled
123
 
     */
124
 
    /* Get 'dn' from posted 'uid' */
125
 
    if(in_array_ics($s_action,array("editPaste","cut","copy")) || (isset($this->CopyPasteHandler) &&  $this->CopyPasteHandler->stillOpen())){
126
 
 
127
 
      if(isset($this->ogrouplist[trim($s_entry)]['dn'])){
128
 
        $dn= $this->ogrouplist[trim($s_entry)]['dn'];
129
 
      }else{
130
 
        $dn = $this->DivListOGroup->selectedBase;
131
 
      }
132
 
 
133
 
      $acl= get_permissions ($dn, $this->ui->subtreeACL);
134
 
      $acl= get_module_permission($acl, "ogroup", $dn);
135
 
 
136
 
      if($acl != "#all#"){
137
 
        print_red (_("You are not allowed to execute this method!"));
138
 
      }else{
139
 
        /* Display the copy & paste dialog, if it is currently open */
140
 
        $ret = $this->copyPasteHandling($s_action,$s_entry);
141
 
        if($ret){
142
 
          return($ret);
143
 
        }
144
 
      }
145
 
    }
146
 
 
147
 
    /****************
148
 
      Create a new object group 
149
 
     ****************/
150
 
 
151
 
    /* New group? */
152
 
    if ($s_action=="new"){
153
 
 
154
 
      /* By default we set 'dn' to 'new', all relevant plugins will
155
 
         react on this. */
156
 
      $this->dn= "new";
157
 
 
158
 
      /* Create new usertab object */
159
 
      $this->ogroup= new ogrouptabs($this->config,
160
 
          $this->config->data['TABS']['OGROUPTABS'], $this->dn);
161
 
    }
162
 
 
163
 
 
164
 
    /****************
165
 
      Delete object group
166
 
     ****************/
167
 
 
168
 
    if ($s_action=="del"){
169
 
 
170
 
      /* Get 'dn' from posted 'uid' */
171
 
      $this->dn= $this->ogrouplist[$s_entry]['dn'];
172
 
 
173
 
      /* Load permissions for selected 'dn' and check if
174
 
         we're allowed to remove this 'dn' */
175
 
      $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
176
 
      $this->acl= get_module_permission($acl, "ogroup", $this->dn);
177
 
      if (chkacl($this->acl, "delete") == ""){
178
 
 
179
 
        /* Check locking, save current plugin in 'back_plugin', so
180
 
           the dialog knows where to return. */
181
 
        if (($user= get_lock($this->dn)) != ""){
182
 
          return(gen_locked_message ($user, $this->dn));
183
 
        }
184
 
 
185
 
        /* Lock the current entry, so nobody will edit it during deletion */
186
 
        add_lock ($this->dn, $this->ui->dn);
187
 
        $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
188
 
        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
189
 
      } else {
190
 
 
191
 
        /* Obviously the user isn't allowed to delete. Show message and
192
 
           clean session. */
193
 
        print_red (_("You are not allowed to delete this object group!"));
194
 
      }
195
 
    }
196
 
 
197
 
 
198
 
    /****************
199
 
      Delete confirmed 
200
 
     ****************/
201
 
 
202
 
    /* Confirmation for deletion has been passed. Group should be deleted. */
203
 
    if (isset($_POST['delete_group_confirm'])){
204
 
 
205
 
      /* Some nice guy may send this as POST, so we've to check
206
 
         for the permissions again. */
207
 
      if (chkacl($this->acl, "delete") == ""){
208
 
 
209
 
        /* Delete request is permitted, perform LDAP action */
210
 
        $this->ogroup= new ogrouptabs($this->config,
211
 
            $this->config->data['TABS']['OGROUPTABS'], $this->dn);
212
 
        $this->ogroup->set_acl(array($this->acl));
213
 
        $this->ogroup->delete ();
214
 
        gosa_log ("Object group'".$this->dn."' has been removed");
215
 
        unset ($this->ogroup);
216
 
        $this->ogroup= NULL;
217
 
      } else {
218
 
 
219
 
        /* Normally this shouldn't be reached, send some extra
220
 
           logs to notify the administrator */
221
 
        print_red (_("You are not allowed to delete this object group!"));
222
 
        gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
223
 
      }
224
 
 
225
 
      /* Remove lock file after successfull deletion */
226
 
      del_lock ($this->dn);
227
 
      unset($_SESSION['objectinfo']);
228
 
    }
229
 
 
230
 
 
231
 
    /****************
232
 
      Delete object group Canceled
233
 
     ****************/
234
 
 
235
 
    /* Delete group canceled? */
236
 
    if (isset($_POST['delete_cancel'])){
237
 
      del_lock ($this->dn);
238
 
      unset($_SESSION['objectinfo']);
239
 
    }
240
 
 
241
 
 
242
 
    /****************
243
 
      Edit group
244
 
     ****************/
245
 
 
246
 
    if (($s_action=="edit") && (! isset($this->ogroup->config)) ){
247
 
 
248
 
      /* Get 'dn' from posted 'uid', must be unique */
249
 
      $this->dn= $this->ogrouplist[$s_entry]['dn'];
250
 
 
251
 
      /* Check locking, save current plugin in 'back_plugin', so
252
 
         the dialog knows where to return. */
253
 
      if (($user= get_lock($this->dn)) != ""){
254
 
        return(gen_locked_message ($user, $this->dn));
255
 
      }
256
 
 
257
 
      /* Lock the current entry, so everyone will get the
258
 
         above dialog */
259
 
      add_lock ($this->dn, $this->ui->dn);
260
 
 
261
 
      /* Set up the users ACL's for this 'dn' */
262
 
      $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
263
 
 
264
 
      /* Register grouptab to trigger edit dialog */
265
 
      $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
266
 
          $this->dn);
267
 
      $this->ogroup->set_acl($acl);
268
 
      $_SESSION['objectinfo']= $this->dn;
269
 
    }
270
 
 
271
 
 
272
 
    /****************
273
 
      Edit finished save 
274
 
     ****************/
275
 
 
276
 
    /* Finish button has been pressed */
277
 
    if ((isset($_POST['edit_finish'])) && (isset($this->ogroup->config)) ){
278
 
 
279
 
      /* Check tabs, will feed message array */
280
 
      $message= $this->ogroup->check();
281
 
 
282
 
      /* Save, or display error message? */
283
 
      if (count($message) == 0){
284
 
 
285
 
        /* Save user data to ldap */
286
 
        $this->ogroup->save();
287
 
        gosa_log ("Object group'".$this->dn."' has been saved");
288
 
 
289
 
        /* Group has been saved successfully, remove lock from
290
 
           LDAP. */
291
 
        if ($this->dn != "new"){
292
 
          del_lock ($this->dn);
293
 
        }
294
 
 
295
 
        unset ($this->ogroup);
296
 
        $this->ogroup= NULL;
297
 
        unset ($_SESSION['objectinfo']);
298
 
 
299
 
      } else {
300
 
        /* Ok. There seem to be errors regarding to the tab data,
301
 
           show message and continue as usual. */
302
 
        show_errors($message);
303
 
      }
304
 
    }
305
 
 
306
 
 
307
 
    /****************
308
 
      Cancel edit object group
309
 
     ****************/
310
 
 
311
 
    /* Cancel dialogs */
312
 
    if ((isset($_POST['edit_cancel'])) && (isset($this->ogroup->dn))){
313
 
      del_lock ($this->ogroup->dn);
314
 
      unset ($this->ogroup);
315
 
      $this->ogroup= NULL;
316
 
      unset($_SESSION['objectinfo']);
317
 
    }
318
 
 
319
 
 
320
 
    /****************
321
 
      Display open dialogs 
322
 
     ****************/
323
 
 
324
 
    /* Show dialog if object is present */
325
 
    if (isset($this->ogroup->config)){
326
 
      $display= $this->ogroup->execute();
327
 
 
328
 
      /* Don't show buttons if tab dialog requests this */
329
 
      if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
330
 
        $display.= "<p style=\"text-align:right\">\n";
331
 
        $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
332
 
        $display.= "&nbsp;\n";
333
 
        $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
334
 
        $display.= "</p>";
335
 
      }
336
 
      return ($display);
337
 
    }
338
 
 
339
 
 
340
 
    /****************
341
 
      Display list 
342
 
     ****************/
343
 
 
344
 
    /* Display dialog with group list */
345
 
    $this->DivListOGroup->parent = $this;
346
 
    $this->DivListOGroup->execute();
347
 
 
348
 
    /* Add departments if subsearch is disabled */
349
 
    if(!$this->DivListOGroup->SubSearch){
350
 
      $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4);
351
 
    }
352
 
    $this->reload ();
353
 
    $this->DivListOGroup->setEntries($this->ogrouplist);
354
 
    return($this->DivListOGroup->Draw());
355
 
  }
356
 
 
357
 
 
358
 
  function convert_list($input)
359
 
  {
360
 
    $temp= "";
361
 
 
362
 
    $conv= array(   
363
 
        "U" => array("select_user.png"        ,_("User")        , "ogroup"),
364
 
        "G" => array("select_groups.png"      ,_("Group")       , "ogroup"),
365
 
        "A" => array("select_application.png" ,_("Application") , "ogroup"),
366
 
        "D" => array("select_department.png"  ,_("Department")  , "ogroup"),
367
 
        "S" => array("select_server.png"      ,_("Server")      , "ogroup"),
368
 
        "F" => array("select_phone.png"       ,_("Phone")       , "phonequeue"),
369
 
        "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
370
 
        "T" => array("select_terminal.png"    ,_("Terminal")    , "termgroup"),
371
 
        "P" => array("select_printer.png"     ,_("Printer")     , "ogroup"));
372
 
 
373
 
    /* Assemble picture */
374
 
    $type= $input['gosaGroupObjects'][0];
375
 
    $type= preg_replace("/[^A-Z]/i","",$type);
376
 
    if (isset($type[0])){
377
 
      $p1['pic']= $conv[$type[0]][0];
378
 
      $p1['tit']= $conv[$type[0]][1];
379
 
      $p1['alt']= $type[0];
380
 
      $p1['lnk']= $conv[$type[0]][2];
381
 
    } else {
382
 
      $p1['pic']= "empty.png";
383
 
      $p1['tit']= "";
384
 
      $p1['alt']= "";
385
 
      $p1['lnk']= "";//$conv[$type[0]][2];
386
 
    }
387
 
 
388
 
    if (isset($type[1])){
389
 
      $p2['pic']= $conv[$type[1]][0];
390
 
      $p2['alt']= $type[1];
391
 
      $p2['tit']= $conv[$type[1]][1];
392
 
      $p2['lnk']= $conv[$type[1]][2];
393
 
    } else {
394
 
      $p2['pic']= "empty.png";
395
 
      $p2['alt']= "";
396
 
      $p2['tit']= "";
397
 
      $p2['lnk']= ""; //$conv[$type[0]][2];
398
 
    }
399
 
    $temp = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' class='center' 
400
 
      src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
401
 
    $temp.= "<input type='image' name='".$p2['lnk']."_group_edit_%KEY'class='center' 
402
 
      src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
403
 
    return ($temp);
404
 
  }
405
 
 
406
 
 
407
 
  function reload()
408
 
  {
409
 
    /* Set base for all searches && initialise some vars */
410
 
    $this->ogrouplist= array();
411
 
    $base     = $this->DivListOGroup->selectedBase;
412
 
    $filter   = "(gosaGroupObjects=[])";
413
 
    $Regex    = $this->DivListOGroup->Regex;
414
 
 
415
 
    $chk = array(
416
 
        "UserGroups"          => "(gosaGroupObjects=*U*)" ,
417
 
        "GroupGroups"         => "(gosaGroupObjects=*G*)" ,
418
 
        "ApplicationGroups"   => "(gosaGroupObjects=*A*)" ,
419
 
        "DepartmentGroups"    => "(gosaGroupObjects=*D*)" ,
420
 
        "ServerGroups"        => "(gosaGroupObjects=*S*)" ,
421
 
        "WorkstationGroups"   => "(gosaGroupObjects=*W*)" ,
422
 
        "TerminalGroups"      => "(gosaGroupObjects=*T*)" ,
423
 
        "PrinterGroups"       => "(gosaGroupObjects=*P*)" ,
424
 
        "PhoneGroups"         => "(gosaGroupObjects=*F*)" );
425
 
    /* Create filter */ 
426
 
    foreach($chk as $chkBox => $FilterPart){
427
 
      if($this->DivListOGroup->$chkBox){
428
 
        $filter .=  $FilterPart;
429
 
      }
430
 
    }
431
 
    $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
432
 
 
433
 
    if($this->DivListOGroup->SubSearch){
434
 
      $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
435
 
    }else{
436
 
      $res= get_list($filter, $this->ui->subtreeACL, get_groups_ou().$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
437
 
    }
438
 
 
439
 
    $this->ogrouplist= $res;
440
 
    ksort ($this->ogrouplist);
441
 
    reset ($this->ogrouplist);
442
 
    $tmp=array();
443
 
    $tmp2 = array();
444
 
    foreach($this->ogrouplist as $tkey => $val ){
445
 
      $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
446
 
      $tmp2[strtolower($val['cn'][0]).$val['cn'][0]] = strtolower($val['cn'][0]).$val['cn'][0];
447
 
    }
448
 
    natcasesort($tmp2);
449
 
    $this->ogrouplist=array();
450
 
    foreach($tmp2 as $val){
451
 
      $this->ogrouplist[]=$tmp[$val];
452
 
    }
453
 
    reset ($this->ogrouplist);
454
 
  }
455
 
 
456
 
  function save_object()
457
 
  {
458
 
    $this->DivListOGroup->save_object();
459
 
  }
460
 
 
461
 
  
462
 
  function copyPasteHandling($s_action,$s_entry)
463
 
  {
464
 
 
465
 
    if($this->CopyPasteHandler){
466
 
 
467
 
      /* Paste copied/cutted object in here
468
 
       */
469
 
      if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
470
 
        $this->CopyPasteHandler->save_object();
471
 
        $this->CopyPasteHandler->SetVar("base", $this->DivListOGroup->selectedBase);
472
 
        return($this->CopyPasteHandler->execute());
473
 
      }
474
 
 
475
 
      /* Copy current object to CopyHandler
476
 
       */
477
 
      if($s_action == "copy"){
478
 
        $this->CopyPasteHandler->Clear();
479
 
        $dn       =   $this->ogrouplist[$s_entry]['dn'];
480
 
        $obj      =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
481
 
        $objNew   =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], "new");
482
 
 
483
 
        $types_of_tabs = $obj->by_object['ogroup']->gosaGroupObjects;
484
 
        $objNew->by_object['ogroup']->gosaGroupObjects = $types_of_tabs;    
485
 
        $objNew->reload($types_of_tabs);
486
 
 
487
 
        $this->CopyPasteHandler->Copy($obj,$objNew);
488
 
      }
489
 
 
490
 
      /* Copy current object to CopyHandler
491
 
       */
492
 
      if($s_action == "cut"){
493
 
        $this->CopyPasteHandler->Clear();
494
 
        $dn       =   $this->ogrouplist[$s_entry]['dn'];
495
 
        $obj      =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
496
 
        $this->CopyPasteHandler->Cut($obj);
497
 
      }
498
 
    }
499
 
  }
500
 
}
501
 
 
502
 
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
503
 
?>