Code

Group generic used template fro copy & paste now
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
1 <?php
2 class group extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Handling of GOsa's base group object";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Group attributes */
10   var $cn= "";
11   var $description= "";
12   var $gidNumber= "";
13   var $memberUid= array();
15   /* Helpers */
16   var $base= "";
17   var $force_gid= FALSE;
18   var $fon_group= FALSE;
19   var $smbgroup= FALSE;
20   var $groupType= FALSE;
21   var $samba3= FALSE;
22   var $sambaSID= "";
23   var $sambaDomainName= "DEFAULT";
24   var $SID= "";
25   var $ridBase= 0;
26   var $members= array();
27   var $users= array();
28   var $allusers= array();
29   var $department= "";
30   var $saved_gidNumber= "";
31   var $oldgroupType= "";
32   var $orig_dn= "";
33   var $orig_cn= "";
34   var $has_mailAccount= FALSE;
35   var $group_dialog= FALSE;
36   var $nagios_group =FALSE;
37   var $sambaGroupType;
38   var $dialog;
39   var $OnlyShowFirstEntries =200;
41   var $allowGroupsWithSameNameInOtherSubtrees = true;
43   /* attribute list for save action */
44   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
45   var $objectclasses= array("top", "posixGroup");
47   function group ($config, $dn= NULL)
48   {
49     plugin::plugin ($config, $dn);
51     /* Load attributes depending on the samba version */
52     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
53     $this->orig_dn= $dn;
54     $this->orig_cn= $this->cn;
56     /* Get member list */
57     if (isset($this->attrs['memberUid'][0])){
58       $tmp= array();
59       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
60         $tmp[]= $this->attrs['memberUid'][$i];
61       }
62       $this->memberUid= $tmp;
63       sort ($this->memberUid);
64     }
66     /* Save gidNumber for later use */
67     if (isset($this->attrs['gidNumber'])){
68       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
69     }
71     /* Is a samba group? */
72     if (isset($this->attrs['objectClass'])){
73       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
74         $this->smbgroup= FALSE;
75       } else {
76         $this->smbgroup= TRUE;
77         if (isset($this->attrs['sambaSID'])){
78           $this->sambaSID= $this->attrs['sambaSID'][0];
79         }
80       }
81       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
82         $this->fon_group= FALSE;
83       } else {
84         $this->fon_group= TRUE;
85       }
86       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
87         $this->nagios_group= FALSE;
88       } else {
89         $this->nagios_group= TRUE;
90       }
91     }
93     /* Set mail flag */
94     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
95       $this->has_mailAccount= TRUE;
96     }
98     /* Get samba Domain in case of samba 3 */
99     if ($this->samba3 && $this->sambaSID != ""){
100       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
101       $ldap= $this->config->get_ldap_link();
102       $ldap->cd($this->config->current['BASE']);
103       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
104       if ($ldap->count() != 0){
105         $attrs= $ldap->fetch();
106         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
108         /* Get domain name for SID */
109         $this->sambaDomainName= "DEFAULT";
110         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
111           if ($val['SID'] == $this->SID){
112             $this->sambaDomainName= $key;
113             break;
114           }
115         }
116       } else {
117         if (isset($this->config->current['RIDBASE'])){
118           $this->sambaDomainName= "DEFAULT";
119           $this->ridBase= $this->config->current['RIDBASE'];
120           $this->SID= $this->config->current['SID'];
121         } else {
122           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
123         }
124       }
126       /* Get group type */
127       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
128       if ($this->groupType < 500 || $this->groupType > 553){
129         $this->groupType= 0;
130       }
131       $this->oldgroupType= $this->groupType;
132     }
134     /* Get global filter config */
135     if (!is_global("gufilter")){
136       $ui= get_userinfo();
137       $base= get_base_from_people($ui->dn);
138       $gufilter= array( "dselect"       => $base,
139           "regex"           => "*");
140       register_global("gufilter", $gufilter);
141     }
142     $gufilter= get_global('gufilter');
144     $gufilter['SubSearchGroup'] = false;
145     $gufilter['dselect'] = $_SESSION['groupfilter']['depselect'];  
147     register_global('gufilter',$gufilter);
148   
149       /* Bases / Departments */
150       
151     if(isset($_SESSION['groupfilter']['depselect'])){
152       $this->base = $_SESSION['groupfilter']['depselect'];
153     }else{
154       if ($this->dn == "new"){
155         $ui= get_userinfo();
156         $this->base= dn2base($ui->dn);
157       } else {
158         $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
159       }
160     }
161     
163     /* This is always an account */
164     $this->is_account= TRUE;
165     $this->reload();
166   }
168   function execute()
169   {
170         /* Call parent execute */
171         plugin::execute();
173   $ui= get_userinfo();
174   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
175   $this->acl= get_module_permission($acla, "group", $ui->dn);
176   /* Do we represent a valid group? */
177     if (!$this->is_account && $this->parent == NULL){
178       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
179         _("This 'dn' is no group.")."</b>";
180       return ($display);
181     }
183     /* Delete user from group */
184     if (isset($_POST['del_users']) && isset($_POST['members'])){
185       foreach ($_POST['members'] as $value){
186         unset ($this->members["$value"]);
187         $this->removeUser($value);
188       }
189       $this->reload();
190     }
192     /* Add objects? */
193     if (isset($_POST["edit_membership"])){
194       $this->group_dialog= TRUE;
195       $this->dialog= TRUE;
196     }
198     /* Add objects finished? */
199     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
200       $this->group_dialog= FALSE;
201       $this->dialog= FALSE;
202     }
204     /* Add user to group */
205     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
206       foreach ($_POST['users'] as $value){
207         $this->members["$value"]= $this->allusers[$value];
208         asort($this->members);
209         $this->addUser($value);
210       }
211       $this->reload();
212     }
214     /* Base select dialog */
215     $once = true;
216     foreach($_POST as $name => $value){
217       if(preg_match("/^chooseBase/",$name) && $once){
218         $once = false;
219         $this->dialog = new baseSelectDialog($this->config);
220         $this->dialog->setCurrentBase($this->base);
221       }
222     }
224     /* Dialog handling */
225     if(is_object($this->dialog)){
226       /* Must be called before save_object */
227       $this->dialog->save_object();
229       if($this->dialog->isClosed()){
230         $this->dialog = false;
231       }elseif($this->dialog->isSelected()){
232         $this->base = $this->dialog->isSelected();
233         $this->dialog= false;
234       }else{
235         return($this->dialog->execute());
236       }
237     }
239    /* Assign templating stuff */
240     $smarty= get_smarty();
241     if ($this->samba3){
242       $smarty->assign("samba3", "true");
243     } else {
244       $smarty->assign("samba3", "");
245     }
247     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
248       $smarty->assign("nagios",true);
249     }else{
250       $smarty->assign("nagios",false);
251     }
252     
253     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
254       $smarty->assign("pickupGroup",true);
255     }else{
256       $smarty->assign("pickupGroup",false);
257     }
259     /* Manage object add dialog */
260     if ($this->group_dialog){
262       /* Save data */
263       $gufilter= get_global("gufilter");
264       foreach( array("dselect", "regex") as $type){
265         if (isset($_POST[$type])){
266           $gufilter[$type]= $_POST[$type];
267         }
268       }
269       if(isset($_POST['regex'])){
270         if(isset($_POST['SubSearchGroup'])){
271           $gufilter['SubSearchGroup'] = true;
272         }else{
273           $gufilter['SubSearchGroup'] = false;
274         }
275       }
277       if (isset($_GET['search'])){
278         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
279         if ($s == "**"){
280           $s= "*";
281         }
282         $gufilter['regex']= $s;
283       }
284       $regex= preg_replace('/[*]/', ".*", $gufilter['regex']);
285       register_global("gufilter", $gufilter);
286       $this->reload();
288       /* Show dialog */
289       $smarty->assign("search_image", get_template_path('images/search.png'));
290       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
291       $smarty->assign("tree_image", get_template_path('images/tree.png'));
292       $smarty->assign("deplist", $this->config->idepartments);
293       $smarty->assign("alphabet", generate_alphabet());
294       foreach( array("dselect", "regex","SubSearchGroup") as $type){
295         $smarty->assign("$type", $gufilter[$type]);
296       }
297       $smarty->assign("hint", print_sizelimit_warning());
299       $users= array();
300       foreach ($this->allusers as $key => $value){
301         if (!array_key_exists($key, $this->members)){
302           if (preg_match("/^$regex/i", $key)){
303             $users[$key]= $value;
304           }
305         }
306       }
307       $smarty->assign("users", $users);
308       $smarty->assign("apply", apply_filter());
309       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
310       return ($display);
311     }
313     /* Bases / Departments */
314     if (isset($_POST['base'])){
315       $this->base= $_POST['base'];
316     }
318     $smarty->assign("bases", $this->config->idepartments);
319     $smarty->assign("base_select", $this->base);
320     $smarty->assign("department", $this->department);
322     if ($this->samba3){
323       $domains= array();
324       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
325         $domains[$name]= $name;
326       }
327       $smarty->assign("sambaDomains", $domains);
328       $smarty->assign("sambaDomainName", $this->sambaDomainName);
329       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
330           514 => _("Domain guests"));
332       /* Don't loose special groups! If not key'ed above, add it to
333          the combo box... */    
334       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
335         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
336       }
338       $smarty->assign("groupTypes", $groupTypes);
339       $smarty->assign("groupType", $this->groupType);
340     }
342     /* Members and users */
343     $smarty->assign("members", $this->members);
345     /* Checkboxes */
346     foreach (array("force_gid", "smbgroup") as $val){
347       if ($this->$val == "1"){
348         $smarty->assign("$val", "checked");
349       } else {
350         $smarty->assign("$val", "");
351       }
352     }
353     if ($this->force_gid != "1"){
354       $smarty->assign("forceMode", "disabled");
355     }else{
356       $smarty->assign("forceMode", "");
357     }
358     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
359     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
360     if ($this->fon_group){
361       $smarty->assign("fon_group", "checked");
362     } else {
363       $smarty->assign("fon_group", "");
364     }
365     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
367     if ($this->nagios_group){
368       $smarty->assign("nagios_group", "checked");
369     } else {
370       $smarty->assign("nagios_group", "");
371     }
372     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
374     /* Fields */
375     foreach (array("cn", "description", "gidNumber") as $val){
376       $smarty->assign("$val", $this->$val);
377       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
378     }
380     /* Missing ACL's */
381     foreach (array("base", "smbgroup", "members") as $val){
382       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
383     }
385     /* Show main page */
386     $smarty->assign("alphabet", generate_alphabet(10));
387     $smarty->assign("search_image", get_template_path('images/search.png'));
388     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
389     $smarty->assign("tree_image", get_template_path('images/tree.png'));
390     $smarty->assign("deplist", $this->config->idepartments);
391     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
392   }
394   function addUser($uid)
395   {
396     $this->memberUid[]= $uid;
397     $this->memberUid= array_unique($this->memberUid);
398   }
400   function removeUser($uid)
401   {
402     $temp= array();
403     foreach ($this->memberUid as $value){
404       if ($value != $uid){
405         $temp[]= $value;
406       }
407     }
408     $this->memberUid= $temp;
409   }
412   /* Reload data */
413   function reload()
414   {
415     /* Generate userlists */
416     $this->last_sorting= "invalid";
417     $this->users= array();
418     $ldap= $this->config->get_ldap_link();
420     $MaxUser = $this->OnlyShowFirstEntries;
422     $gufilter= get_global("gufilter");
423     $ldap->cd ($this->config->current['BASE']);
424     if($gufilter['SubSearchGroup']){
425       $ldap->cd ($gufilter['dselect']);
426       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",array("uid", "sn","givenName"));
427     }else{
428       $ldap->cd (get_people_ou().$gufilter['dselect']);
429       $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
430     }
431     $this->allusers= array();
432     
433     $i = 0 ;
434     while (($attrs= $ldap->fetch()) && ($i < $MaxUser)){
435       $i ++;
436       if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
437         $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
438           $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
439       } else {
440         $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
441       }
442     }
443   
444     if(($i == $MaxUser)){
445       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
446     }
447     
448     natcasesort ($this->allusers);
449     reset ($this->allusers);
451     /* Fill memberlist */
452     $this->members= array();
453     foreach ($this->memberUid as $value){
454       if (isset($this->allusers[$value])){
455         $this->members[$value]= $this->allusers[$value];
456       } else {
457         $ldap->cd($this->config->current['BASE']);
458         $ldap->search("(&(objectClass=gosaAccount)(uid=".$value."))",array("uid", "sn","givenName"));
459         $attrs = $ldap->fetch();
460     
461         if(!$attrs){
462           $this->members[$value] = _("! unknown id")." [".$value."]"; 
463         }else{
464     
465           if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
466             $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
467               $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
468           } else {
469             $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
470           }
471           if (isset($this->allusers[$value])){
472             $this->members[$value]= $this->allusers[$value];
473           } else {
474             $this->members[$value] = "[".$value."]";
475           }
476         }
477       }
478     }
479     asort($this->members);
480     reset($this->members);
481   }
485   function remove_from_parent()
486   {
487     plugin::remove_from_parent();
489     $ldap= $this->config->get_ldap_link();
490     $ldap->rmdir($this->dn);
491     show_ldap_error($ldap->get_error());
493     /* Delete references to object groups */
494     $ldap->cd ($this->config->current['BASE']);
495     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
496     while ($ldap->fetch()){
497       $og= new ogroup($this->config, $ldap->getDN());
498       unset($og->member[$this->dn]);
499       $og->save ();
500     }
502     /* Send signal to the world that we've done */
503     $this->handle_post_events("remove");
504   }
507   /* Save data to object */
508   function save_object()
509   {
510     /* Save additional values for possible next step */
511     if (isset($_POST['groupedit'])){
513       
514       plugin::save_object();
516       $this->force_gid= 0;
517       $this->smbgroup= 0;
518       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
519         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
520           $this->$val= $_POST["$val"];
521         }
522       }
524       /* Save sambaDomain attribute */
525       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
526           isset ($_POST['sambaDomainName'])){
528         $this->sambaDomainName= $_POST['sambaDomainName'];
529         $this->groupType= $_POST['groupType'];
530       }
532       /* Save fon attribute */
533       if (chkacl ($this->acl, "fon_group") == ""){
534         if (isset ($_POST['fon_group'])){
535           $this->fon_group= TRUE;
536         } else {
537           $this->fon_group= FALSE;
538         }
539       }
540          if (chkacl ($this->acl, "nagios_group") == ""){
541         if (isset ($_POST['nagios_group'])){
542           $this->nagios_group= TRUE;
543         } else {
544           $this->nagios_group= FALSE;
545         }
546       }
547     }
548   }
551   /* Save to LDAP */
552   function save()
553   {
554     /* ID handling */
555     if ($this->force_gid == 0){
556       if ($this->saved_gidNumber != ""){
557         $this->gidNumber= $this->saved_gidNumber;
558       } else {
559         /* Calculate new, lock uids */
560         $wait= 10;
561         while (get_lock("uidnumber") != ""){
562           sleep (1);
564           /* timed out? */
565           if ($wait-- == 0){
566             break;
567           }
568         }
569         add_lock ("uidnumber", "gosa");
570         $this->gidNumber= $this->get_next_id("gidNumber");
571       }
572     }
574     plugin::save(); 
576     /* Remove objectClass for samba/phone support */
577     $tmp= array();
578     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
579       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
580           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
581           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
582          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
583         $tmp[]= $this->attrs['objectClass'][$i];
584       }
585     }
586     $this->attrs['objectClass']= $tmp;
587     $ldap= $this->config->get_ldap_link();
589     /* Add samba group functionality */
590     if ($this->samba3 && $this->smbgroup){
591   
592       /* Fixed undefined index ... 
593        */ 
594       $this->SID = $this->ridBase = "";
595       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
596         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
597       }else{
598         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
599       }
600       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
601         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
602       }else{
603         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
604       }
606       $this->attrs['objectClass'][]= 'sambaGroupMapping';
607       $this->attrs['sambaGroupType']= "2";
609       /* Check if we need to create a special entry */
610       if ($this->groupType == 0){
612         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
613           $gidNumber= $this->gidNumber;
614           while(TRUE){
615             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
616             $ldap->cd($this->config->current['BASE']);
617             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
618             if ($ldap->count() == 0){
619               break;
620             }
621             $gidNumber++;
622           }
623           $this->attrs['sambaSID']= $sid;
624           $this->sambaSID= $sid;
625         }
627       } else {
628         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
629       }
631       /* User wants me to fake the idMappings? This is useful for
632          making winbind resolve the group names in a reasonable amount
633          of time in combination with larger databases. */
634       if (isset($this->config->current['SAMBAIDMAPPING']) &&
635           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
636         $this->attrs['objectClass'][]= "sambaIdmapEntry";
637       }
639     }
641     /* Add phone functionality */
642     if ($this->fon_group){
643       $this->attrs['objectClass'][]= "goFonPickupGroup";
644     }
646     /* Add nagios functionality */
647     if ($this->nagios_group){
648         $this->attrs['objectClass'][]= "nagiosContactGroup";
649     }
651     /* Take members array */
652     if (count ($this->memberUid)){
653       $this->attrs['memberUid']= array_unique($this->memberUid);
654     }
656     /* New accounts need proper 'dn', propagate it to remaining objects */
657     if ($this->dn == 'new'){
658       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
659     }
661     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
662        new entries. So do a check first... */
663     $ldap->cat ($this->dn);
664     if ($ldap->fetch()){
665       /* Modify needs array() to remove values :-( */
666       if (!count ($this->memberUid)){
667         $this->attrs['memberUid']= array();
668       }
669       if ($this->samba3){
670         if (!$this->smbgroup){
671           $this->attrs['sambaGroupType']= array();
672           $this->attrs['sambaSID']= array();
673         }
674       }
675       $mode= "modify";
676     } else {
677       $mode= "add";
678       $ldap->cd($this->config->current['BASE']);
679       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
680     }
682     /* Write back to ldap */
683     $ldap->cd($this->dn);
684     $this->cleanup();
685     $ldap->$mode($this->attrs);
687     $ret= 0;
688     if (show_ldap_error($ldap->get_error())){
689       $ret= 1;
690     }
692     /* Remove uid lock */
693     del_lock ("uidnumber");
695     /* Post that we've done*/
696     $this->handle_post_events($mode);
698     return ($ret);
699   }
701   function check()
702   {
703     $message= array();
705     /* Permissions for that base? */
706     if ($this->base != ""){
707       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
708     } else {
709       $new_dn= $this->dn;
710     }
712     $ui= get_userinfo();
713     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
714     $acl= get_module_permission($acl, "group", $ui->dn);
715     if (chkacl($this->acl, "create") != ""){
716       $message[]= _("You have no permissions to create a group on this 'Base'.");
717     }
719     /* must: cn */
720     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
721       $message[]= "The required field 'Name' is not set.";
722     }
724     /* Check for valid input */
725     if (!is_uid($this->cn)){
726       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
727     }
730     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
732       /* Check for used 'cn' */
733       $ldap= $this->config->get_ldap_link();
734       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
735         $ldap->cd("ou=groups,".$this->base);
736         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))","ou=groups,".$this->base,array("cn"));
737         if ($ldap->count() != 0){
738           $message[]= _("Value specified as 'Name' is already used.");
739         }
740       }
742     }else{
744       /* Check for used 'cn' */
745       $ldap= $this->config->get_ldap_link();
746       $ldap->cd($this->config->current['BASE']);
747       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
748       if ($ldap->count() != 0){
750         /* New entry? */
751         if ($this->dn == 'new'){
752           $message[]= _("Value specified as 'Name' is already used.");
753         }
755         /* Moved? */
756         elseif ($new_dn != $this->orig_dn){
757           $ldap->fetch();
758           if ($ldap->getDN() != $this->orig_dn){
759             $message[]= _("Value specified as 'Name' is already used.");
760           }
761         }
762       }
763     }
764      
765     /* Check ID */
766     if ($this->force_gid == "1"){
767       if (!is_id($this->gidNumber)){
768         $message[]= _("Value specified as 'GID' is not valid.");
769       } else {
770         if ($this->gidNumber < $this->config->current['MINID']){
771           $message[]= _("Value specified as 'GID' is too small.");
772         }
774       }
775     }
777     return ($message);
778   }
780   function get_next_id($attrib)
781   {
782     $ids= array();
783     $ldap= $this->config->get_ldap_link();
785     $ldap->cd ($this->config->current['BASE']);
786     if (preg_match('/gidNumber/i', $attrib)){
787       $oc= "posixGroup";
788     } else {
789       $oc= "posixAccount";
790     }
791     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
793     /* Get list of ids */
794     while ($attrs= $ldap->fetch()){
795       $ids[]= (int)$attrs["$attrib"][0];
796     }
798     /* Find out next free id near to UID_BASE */
799     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
800       if (!in_array($id, $ids)){
801         return ($id);
802       }
803     }
805     /* Should not happen */
806     if ($id == 65000){
807       print_red(_("Too many users, can't allocate a free ID!"));
808       exit;
809     }
810   }
812   function getCopyDialog()
813   {
814     $vars = array("cn");
815   
816     if($this ->force_gid){
817       $used = " checked ";
818       $dis  = "";
819     }else{
820       $used = "";
821       $dis  = " disabled ";
822     }
824     $smarty = get_smarty();
825     $smarty->assign("used",$used);
826     $smarty->assign("dis" ,$dis);
827     $smarty->assign("cn" ,$this->cn);
828     $smarty->assign("gidNumber",$this->gidNumber);
829     return($smarty->fetch(get_template_path("paste_generic.tpl",TRUE)));
830   }
832   function saveCopyDialog()
833   {
834     if(isset($_POST['cn'])){
835       $this->cn = $_POST['cn'];
836     }
837     if(isset($_POST['force_gid'])){
838       $this->force_gid  = 1;
839       $this->gidNumber= $_POST['gidNumber'];
840     }else{
841       $this->force_gid  = 0;
842       $this->gidNumber  = false;
843     }
844   }
847 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
848 ?>