1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Sort multidimensional arrays for key 'text' */
24 function sort_list($val1, $val2)
25 {
26 $v1= strtolower($val1['text']);
27 $v2= strtolower($val2['text']);
28 if ($v1 > $v2){
29 return 1;
30 }
31 if ($v1 < $v2){
32 return -1;
33 }
34 return 0;
35 }
38 class ogroup extends plugin
39 {
40 /* Variables */
41 var $cn= "";
42 var $description= "";
43 var $base= "";
44 var $gosaGroupObjects= "";
45 var $department= "";
46 var $objects= array();
47 var $objcache= array();
48 var $memberList= array();
49 var $member= array();
50 var $orig_dn= "";
51 var $group_dialog= FALSE;
52 var $view_logged = FALSE;
54 /* attribute list for save action */
55 var $attributes= array("cn", "description", "gosaGroupObjects","member");
56 var $objectclasses= array("top", "gosaGroupOfNames");
58 function ogroup (&$config, $dn= NULL)
59 {
60 plugin::plugin ($config, $dn);
61 $this->orig_dn= $dn;
63 $this->member = array();
65 /* Load member objects */
66 if (isset($this->attrs['member'])){
67 foreach ($this->attrs['member'] as $key => $value){
68 if ("$key" != "count"){
69 $value= @LDAP::convert($value);
70 $this->member["$value"]= "$value";
71 }
72 }
73 }
74 $this->is_account= TRUE;
76 /* Get global filter config */
77 if (!session::is_set("ogfilter")){
78 $ui= get_userinfo();
79 $base= get_base_from_people($ui->dn);
80 $ogfilter= array( "dselect" => $base,
81 "regex" => "*");
82 session::set("ogfilter", $ogfilter);
83 }
84 $ogfilter= session::get('ogfilter');
86 /* Adjust flags */
87 foreach( array( "U" => "accounts",
88 "G" => "groups",
89 "A" => "applications",
90 "D" => "departments",
91 "S" => "servers",
92 "W" => "workstations",
93 "O" => "winstations",
94 "T" => "terminals",
95 "F" => "phones",
96 "_" => "subtrees",
97 "P" => "printers") as $key => $val){
99 if (preg_match("/$key/", $this->gosaGroupObjects)){
100 $ogfilter[$val]= "checked";
101 } else {
102 $ogfilter[$val]= "";
103 }
104 }
105 session::set("ogfilter", $ogfilter);
107 if(session::is_set('CurrentMainBase')){
108 $this->base = session::get('CurrentMainBase');
109 }
111 /* Set base */
112 if ($this->dn == "new"){
113 $this->base = session::get('CurrentMainBase');
114 } else {
115 $this->base= preg_replace("/^[^,]+,".normalizePreg(get_ou("ogroupou"))."/","",$this->dn);
116 }
118 /* Load member data */
119 $this->reload();
120 }
122 function AddDelMembership($NewMember = false){
124 if($NewMember){
126 /* Add member and force reload */
127 $this->member[$NewMember]= $NewMember;
128 $this->reload();
130 $this->memberList[$NewMember]= $this->objcache[$NewMember];
131 unset ($this->objects[$NewMember]);
132 uasort ($this->memberList, 'sort_list');
133 reset ($this->memberList);
134 }else{
135 /* Delete objects from group */
136 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
137 foreach ($_POST['members'] as $value){
138 $this->objects["$value"]= $this->memberList[$value];
139 unset ($this->memberList["$value"]);
140 unset ($this->member["$value"]);
141 uasort ($this->objects, 'sort_list');
142 reset ($this->objects);
143 }
144 $this->reload();
145 }
147 /* Add objects to group */
148 if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
150 $tmp = "";
151 foreach($this->memberList as $obj){
152 $tmp .= $obj['type'];
153 }
154 $skipped = FALSE;
155 foreach ($_POST['objects'] as $value){
156 if(preg_match("/T/",$tmp) && $this->objects[$value]['type'] == "W"){
157 $skipped =TRUE;
158 }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
159 $skipped =TRUE;
160 }else{
161 $this->memberList["$value"]= $this->objects[$value];
162 $this->member["$value"]= $value;
163 unset ($this->objects[$value]);
164 uasort ($this->memberList, 'sort_list');
165 reset ($this->memberList);
166 }
167 }
168 if($skipped){
169 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
170 }
171 $this->reload();
172 }
173 }
174 }
176 function execute()
177 {
178 /* Call parent execute */
179 plugin::execute();
181 if(!$this->view_logged){
182 $this->view_logged = TRUE;
183 new log("view","ogroups/".get_class($this),$this->dn);
184 }
187 /* Do we represent a valid group? */
188 if (!$this->is_account){
189 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
190 msgPool::noValidExtension("object group")."</b>";
191 return ($display);
192 }
195 /* Load templating engine */
196 $smarty= get_smarty();
198 $tmp = $this->plInfo();
199 foreach($tmp['plProvidedAcls'] as $name => $translation){
200 $smarty->assign($name."ACL",$this->getacl($name));
201 }
203 /* Base select dialog */
204 $once = true;
205 foreach($_POST as $name => $value){
206 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
207 $once = false;
208 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
209 $this->dialog->setCurrentBase($this->base);
210 }
211 }
213 /* Dialog handling */
214 if(is_object($this->dialog) && $this->acl_is_moveable()){
215 /* Must be called before save_object */
216 $this->dialog->save_object();
218 if($this->dialog->isClosed()){
219 $this->dialog = false;
220 }elseif($this->dialog->isSelected()){
222 /* A new base was selected, check if it is a valid one */
223 $tmp = $this->get_allowed_bases();
224 if(isset($tmp[$this->dialog->isSelected()])){
225 $this->base = $this->dialog->isSelected();
226 }
227 $this->dialog= false;
228 }else{
229 return($this->dialog->execute());
230 }
231 }
233 /* Add objects? */
234 if (isset($_POST["edit_membership"])){
235 $this->group_dialog= TRUE;
236 $this->dialog= TRUE;
237 }
239 /* Add objects finished? */
240 if (isset($_POST["add_object_finish"]) || isset($_POST["add_object_cancel"])){
241 $this->group_dialog= FALSE;
242 $this->dialog= FALSE;
243 }
245 /* Manage object add dialog */
246 if ($this->group_dialog){
248 /* Save data */
249 $ogfilter= session::get("ogfilter");
250 foreach( array("dselect", "regex") as $type){
251 if (isset($_POST[$type])){
252 $ogfilter[$type]= $_POST[$type];
253 }
254 }
255 if (isset($_POST['dselect'])){
256 foreach( array("accounts", "groups", "applications", "departments",
257 "servers", "workstations", "winstations", "terminals", "printers","subtrees",
258 "phones") as $type){
260 if (isset($_POST[$type])) {
261 $ogfilter[$type]= "checked";
262 } else {
263 $ogfilter[$type]= "";
264 }
265 }
266 }
267 if (isset($_GET['search'])){
268 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
269 if ($s == "**"){
270 $s= "*";
271 }
272 $ogfilter['regex']= $s;
273 }
274 session::set("ogfilter", $ogfilter);
275 $this->reload();
277 /* Calculate actual groups */
278 $smarty->assign("objects", $this->convert_list($this->objects));
280 /* Show dialog */
281 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
282 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
283 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
284 $smarty->assign("deplist", $this->config->idepartments);
285 $smarty->assign("alphabet", generate_alphabet());
286 foreach( array("dselect", "regex", "subtrees") as $type){
287 $smarty->assign("$type", $ogfilter[$type]);
288 }
289 $smarty->assign("hint", print_sizelimit_warning());
290 $smarty->assign("apply", apply_filter());
292 /* Build up checkboxes
293 */
294 $ar = array(
295 "departments" => array(
296 "T" => msgPool::selectToView(_("departments")),
297 "C" => (isset($ogfilter['departments']) && ($ogfilter['departments'])),
298 "L" => sprintf(_("Show %s"),_("departments"))),
299 "accounts" => array(
300 "T" => msgPool::selectToView(_("people")),
301 "C" => (isset($ogfilter['accounts']) && ($ogfilter['accounts'])),
302 "L" => sprintf(_("Show %s"),_("people"))),
303 "groups"=> array(
304 "T" => msgPool::selectToView(_("groups")),
305 "C" => (isset($ogfilter['groups']) && ($ogfilter['groups'])),
306 "L" => sprintf(_("Show %s"),_("groups"))),
307 "servers"=> array(
308 "T" => msgPool::selectToView(_("servers")),
309 "C" => (isset($ogfilter['servers']) && ($ogfilter['servers'])),
310 "L" => sprintf(_("Show %s"),_("servers"))),
311 "workstations"=> array(
312 "T" => msgPool::selectToView(_("workstations")),
313 "C" => (isset($ogfilter['workstations']) && ($ogfilter['workstations'])),
314 "L" => sprintf(_("Show %s"),_("workstations"))),
315 "terminals"=> array(
316 "T" => msgPool::selectToView(_("terminals")),
317 "C" => (isset($ogfilter['terminals']) && ($ogfilter['terminals'])),
318 "L" => sprintf(_("Show %s"),_("terminals"))),
319 "printers"=> array(
320 "T" => msgPool::selectToView(_("printer")),
321 "C" => (isset($ogfilter['printers']) && ($ogfilter['printers'])),
322 "L" => sprintf(_("Show %s"),_("printers"))),
323 "phones"=> array(
324 "T" => msgPool::selectToView(_("phones")),
325 "C" => (isset($ogfilter['phones']) && ($ogfilter['phones'])),
326 "L" => sprintf(_("Show %s"),_("phones"))));
328 /* Allow selecting applications if we are having a non
329 release managed application storage */
330 if(!$this->IsReleaseManagementActivated()){
331 $ar["applications"] = array(
332 "T" => msgPool::selectToView(_("applications")),
333 "C" => (isset($ogfilter['applications']) && ($ogfilter['applications'])),
334 "L" => sprintf(_("Show %s"),_("applications")));
335 }
337 $smarty->assign("checkboxes",$ar);
338 $display= $smarty->fetch (get_template_path('ogroup_objects.tpl', TRUE, dirname(__FILE__)));
339 return ($display);
340 }
342 /* Bases / Departments */
343 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
344 $this->base= $_POST['base'];
345 }
347 /* Assemble combine string */
348 if ($this->gosaGroupObjects == "[]"){
349 $smarty->assign("combinedObjects", _("none"));
350 } elseif (strlen($this->gosaGroupObjects) > 4){
351 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
352 } else {
353 $conv= array( "U" => _("users"),
354 "G" => _("groups"),
355 "A" => _("applications"),
356 "D" => _("departments"),
357 "S" => _("servers"),
358 "W" => _("workstations"),
359 "O" => _("winstations"),
360 "T" => _("terminals"),
361 "F" => _("phones"),
362 "P" => _("printers"));
364 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
365 $p1= $conv[$type[0]];
366 error_reporting(0);
367 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
368 $p2= $conv[$type[1]];
369 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
370 } else {
371 $smarty->assign("combinedObjects", "$p1");
372 }
373 error_reporting(E_ALL | E_STRICT);
374 }
376 /* Assign variables */
377 $smarty->assign("bases", $this->get_allowed_bases());
378 $smarty->assign("base_select", $this->base);
379 $smarty->assign("department", $this->department);
380 $smarty->assign("members", $this->convert_list($this->memberList));
382 /* Objects have to be tuned... */
383 $smarty->assign("objects", $this->convert_list($this->objects));
385 /* Fields */
386 foreach ($this->attributes as $val){
387 $smarty->assign("$val", $this->$val);
388 }
390 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
391 }
394 /* Save data to object */
395 function save_object()
396 {
397 /* Save additional values for possible next step */
398 if (isset($_POST['ogroupedit'])){
400 /* Create a base backup and reset the
401 base directly after calling plugin::save_object();
402 Base will be set seperatly a few lines below */
403 $base_tmp = $this->base;
404 plugin::save_object();
405 $this->base = $base_tmp;
407 /* Save base, since this is no LDAP attribute */
408 $tmp = $this->get_allowed_bases();
409 if(isset($_POST['base'])){
410 if(isset($tmp[$_POST['base']])){
411 $this->base= $_POST['base'];
412 }
413 }
414 }
415 }
418 /* (Re-)Load objects */
419 function reload()
420 {
421 /*###########
422 Variable initialisation
423 ###########*/
425 $this->objects = array();
426 $this->ui = get_userinfo();
427 $filter = "";
428 $objectClasses = array();
430 $ogfilter = session::get("ogfilter");
431 $regex = $ogfilter['regex'];
433 $ldap= $this->config->get_ldap_link();
434 $ldap->cd ($ogfilter['dselect']);
437 /*###########
438 Generate Filter
439 ###########*/
441 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
442 "DN"=> get_people_ou() ,"ACL" => "users"),
443 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
444 "DN"=> get_groups_ou('ogroupou') ,"ACL" => "groups"),
445 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
446 "DN"=> "" ,"ACL" => "department"),
447 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
448 "DN"=> get_ou('serverou') ,"ACL" => "server"),
449 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
450 "DN"=> get_ou('workstationou') ,"ACL" => "workstation"),
451 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
452 "DN"=> get_ou('WINSTATIONS') ,"ACL" => "winstation"),
453 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
454 "DN"=> get_ou('terminalou') ,"ACL" => "terminal"),
455 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
456 "DN"=> get_ou('printerou') ,"ACL" => "printer"),
457 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
458 "DN"=> get_ou('phoneou') ,"ACL" => "phone"));
461 /* Allow searching for applications, if we are not using release managed applications
462 */
463 if(!$this->IsReleaseManagementActivated()){
464 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
465 "DN"=> get_ou('applicationou') ,"ACL" => "application");
466 }
468 /*###########
469 Perform search for selected objectClasses & regex to fill list with objects
470 ###########*/
472 $Get_list_flags = 0;
473 if($ogfilter['subtrees'] == "checked"){
474 $Get_list_flags |= GL_SUBSEARCH;
475 }
477 foreach($p_f as $post_name => $data){
479 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
481 if($ogfilter['subtrees']){
482 $base = $ogfilter['dselect'];
483 }else{
484 $base = $data['DN'].$ogfilter['dselect'];
485 }
488 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
489 $res = get_list($filter, $data['ACL'] , $base,
490 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
492 /* fetch results and append them to the list */
493 foreach($res as $attrs){
495 $type= $this->getObjectType($attrs);
496 $name= $this->getObjectName($attrs);
498 /* Fill array */
499 if (isset($attrs["description"][0])){
500 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
501 } elseif (isset($attrs["uid"][0])) {
502 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
503 } else {
504 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
505 }
506 }
507 }
508 }
509 uasort ($this->objects, 'sort_list');
510 reset ($this->objects);
513 /*###########
514 Build member list and try to detect obsolete entries
515 ###########*/
517 $this->memberList = array();
519 /* Walk through all single member entry */
520 foreach($this->member as $dn){
522 /* The dn for the current member can't be resolved
523 it seams that this entry was removed
524 */
525 /* Try to resolv the entry again, if it still fails, display error msg */
526 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
528 /* It has failed, add entry with type flag I (Invalid)*/
529 if (!$ldap->success()){
530 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
532 } else {
534 /* Append this entry to our all object list */
536 /* Fetch object */
537 $attrs= $ldap->fetch();
539 $type= $this->getObjectType($attrs);
540 $name= $this->getObjectName($attrs);
542 if (isset($attrs["description"][0])){
543 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
544 } elseif (isset($attrs["uid"][0])) {
545 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
546 } else {
547 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
548 }
549 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
551 if(isset($attrs['macAddress'][0])){
552 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
553 }else{
554 $this->objcache[$attrs["dn"]]['macAddress'] = "";
555 }
557 if(isset($attrs['uid'])){
558 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
559 }
561 /* Fill array */
562 if (isset($attrs["description"][0])){
563 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
564 } else {
565 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
566 }
568 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
569 }
570 }
571 uasort ($this->memberList, 'sort_list');
572 reset ($this->memberList);
574 /* Assemble types of currently combined objects */
575 $objectTypes= "";
576 foreach ($this->memberList as $dn => $desc){
578 /* Invalid object? */
579 if ($desc['type'] == 'I'){
580 continue;
581 }
583 /* Fine. Add to list. */
584 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
585 $objectTypes.= $desc['type'];
586 }
587 }
588 $this->gosaGroupObjects= "[$objectTypes]";
589 }
592 function convert_list($input)
593 {
594 $temp= "";
595 $conv= array( "U" => "select_user.png",
596 "G" => "plugins/groups/images/groups.png",
597 "A" => "plugins/ogroups/images/application.png",
598 "D" => "plugins/departments/images/department.png",
599 "S" => "plugins/ogroups/images/server.png",
600 "W" => "plugins/ogroups/images/workstation.png",
601 "O" => "plugins/ogroups/images/winstation.png",
602 "T" => "plugins/ogroups/images/terminal.png",
603 "F" => "plugins/ogroups/images/phone.png",
604 "I" => "images/lists/flag.png",
605 "P" => "plugins/ogroups/images/printer.png");
607 foreach ($input as $key => $value){
608 /* Generate output */
609 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
610 }
612 return ($temp);
613 }
616 function getObjectType($attrs)
617 {
618 $type= "I";
620 foreach(array( "U" => "gosaAccount",
621 "G" => "posixGroup",
622 "A" => "gosaApplication",
623 "D" => "gosaDepartment",
624 "S" => "goServer",
625 "W" => "gotoWorkstation",
626 "O" => "opsiClient",
627 "T" => "gotoTerminal",
628 "F" => "goFonHardware",
629 "P" => "gotoPrinter") as $index => $class){
630 if (in_array($class, $attrs['objectClass'])){
631 $type= $index;
632 break;
633 }
634 }
636 return ($type);
637 }
640 function getObjectName($attrs)
641 {
642 /* Person? */
643 $name ="";
644 if (in_array('gosaAccount', $attrs['objectClass'])){
645 if(isset($attrs['sn']) && isset($attrs['givenName'])){
646 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
647 } else {
648 $name= $attrs['uid'][0];
649 }
650 } else {
651 if(isset($attrs["cn"][0])) {
652 $name= $attrs['cn'][0];
653 } else {
654 $name= $attrs['ou'][0];
655 }
656 }
658 return ($name);
659 }
662 function check()
663 {
664 /* Call common method to give check the hook */
665 $message= plugin::check();
667 /* Permissions for that base? */
668 if ($this->base != ""){
669 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
670 } else {
671 $new_dn= $this->dn;
672 }
675 $ldap = $this->config->get_ldap_link();
676 if($this->dn != $new_dn){
677 $ldap->cat ($new_dn, array('dn'));
678 }
680 if($ldap->count() !=0){
681 $message[]= msgPool::duplicated(_("Name"));
682 }
684 /* Set new acl base */
685 if($this->dn == "new") {
686 $this->set_acl_base($this->base);
687 }
689 /* must: cn */
690 if ($this->cn == ""){
691 $message[]= msgPool::required(_("Name"));
692 }
694 /* To many different object types? */
695 if (strlen($this->gosaGroupObjects) > 4){
696 $message[]= _("You can combine two different object types at maximum, only!");
697 }
699 return ($message);
700 }
703 /* Save to LDAP */
704 function save()
705 {
706 plugin::save();
708 /* Move members to target array */
709 $this->attrs['member'] =array();
710 foreach ($this->member as $key => $desc){
711 $this->attrs['member'][]= @LDAP::fix($key);
712 }
714 $ldap= $this->config->get_ldap_link();
716 /* New accounts need proper 'dn', propagate it to remaining objects */
717 if ($this->dn == 'new'){
718 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
719 }
721 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
722 new entries. So do a check first... */
723 $ldap->cat ($this->dn, array('dn'));
724 if ($ldap->fetch()){
725 /* Modify needs array() to remove values :-( */
726 if (!count ($this->member)){
727 $this->attrs['member']= array();
728 }
729 $mode= "modify";
731 } else {
732 $mode= "add";
733 $ldap->cd($this->config->current['BASE']);
734 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
735 }
737 /* Write back to ldap */
738 $ldap->cd($this->dn);
739 $this->cleanup();
740 $ldap->$mode($this->attrs);
742 if($mode == "add"){
743 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
744 }else{
745 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
746 }
748 /* Trigger post signal */
749 $this->handle_post_events($mode);
751 $ret= 0;
752 if (!$ldap->success()){
753 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
754 $ret= 1;
755 }
757 return ($ret);
758 }
760 function remove_from_parent()
761 {
762 plugin::remove_from_parent();
764 $ldap= $this->config->get_ldap_link();
765 $ldap->rmdir($this->dn);
766 if (!$ldap->success()){
767 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
768 }
770 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
772 /* Trigger remove signal */
773 $this->handle_post_events("remove");
774 }
777 function PrepareForCopyPaste($source)
778 {
779 /* Update available object types */
780 if(isset($source['gosaGroupObjects'][0])){
781 $this->gosaGroupObjects = $source['gosaGroupObjects'][0];
782 }
784 /* Reload tabs */
785 $this->parent->reload($this->gosaGroupObjects );
787 /* Reload plugins */
788 foreach($this->parent->by_object as $name => $class ){
789 if(get_class($this) != $name) {
790 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
791 }
792 }
794 /* Load member objects */
795 if (isset($source['member'])){
796 foreach ($source['member'] as $key => $value){
797 if ("$key" != "count"){
798 $value= @LDAP::convert($value);
799 $this->member["$value"]= "$value";
800 }
801 }
802 }
804 }
807 function getCopyDialog()
808 {
809 $smarty = get_smarty();
810 $smarty->assign("cn", $this->cn);
811 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
812 $ret = array();
813 $ret['string'] = $str;
814 $ret['status'] = "";
815 return($ret);
816 }
818 function saveCopyDialog()
819 {
820 if(isset($_POST['cn'])){
821 $this->cn = $_POST['cn'];
822 }
823 }
826 function IsReleaseManagementActivated()
827 {
828 /* Check if we should enable the release selection */
829 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
830 if(!empty($tmp)){
831 return(true);
832 }
833 return(false);
834 }
837 static function plInfo()
838 {
839 return (array(
840 "plShortName" => _("Generic"),
841 "plDescription" => _("Object group generic"),
842 "plSelfModify" => FALSE,
843 "plDepends" => array(),
844 "plPriority" => 1,
845 "plSection" => array("administration"),
846 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
847 "objectClass" => "gosaGroupOfNames")),
848 "plProvidedAcls"=> array(
849 "cn" => _("Name"),
850 "base" => _("Base"),
851 "description" => _("Description"),
852 "member" => _("Member"))
853 ));
854 }
855 }
857 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
858 ?>