Code

Starting move
[gosa.git] / gosa-core / plugins / personal / generic / class_user.inc
1 <?php
2 /*!
3   \brief   user plugin
4   \author  Cajus Pollmeier <pollmeier@gonicus.de>
5   \version 2.00
6   \date    24.07.2003
8   This class provides the functionality to read and write all attributes
9   relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
10   from/to the LDAP. It does syntax checking and displays the formulars required.
11  */
13 class user extends plugin
14 {
15   /* Definitions */
16   var $plHeadline= "Generic";
17   var $plDescription= "This does something";
19   /* CLI vars */
20   var $cli_summary= "Handling of GOsa's user base object";
21   var $cli_description= "Some longer text\nfor help";
22   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
24   /* Plugin specific values */
25   var $base= "";
26   var $orig_base= "";
27   var $cn= "";
28   var $new_dn= "";
29   var $personalTitle= "";
30   var $academicTitle= "";
31   var $homePostalAddress= "";
32   var $homePhone= "";
33   var $labeledURI= "";
34   var $o= "";
35   var $ou= "";
36   var $departmentNumber= "";
37   var $employeeNumber= "";
38   var $employeeType= "";
39   var $roomNumber= "";
40   var $telephoneNumber= "";
41   var $facsimileTelephoneNumber= "";
42   var $mobile= "";
43   var $pager= "";
44   var $l= "";
45   var $st= "";
46   var $postalAddress= "";
47   var $dateOfBirth;
48   var $use_dob= "0";
49   var $gender="0";
50   var $preferredLanguage="0";
52   var $jpegPhoto= "*removed*";
53   var $photoData= "";
54   var $old_jpegPhoto= "";
55   var $old_photoData= "";
56   var $cert_dialog= FALSE;
57   var $picture_dialog= FALSE;
58   var $pwObject= NULL;
60   var $userPKCS12= "";
61   var $userSMIMECertificate= "";
62   var $userCertificate= "";
63   var $certificateSerialNumber= "";
64   var $old_certificateSerialNumber= "";
65   var $old_userPKCS12= "";
66   var $old_userSMIMECertificate= "";
67   var $old_userCertificate= "";
69   var $gouvernmentOrganizationalUnit= "";
70   var $houseIdentifier= "";
71   var $street= "";
72   var $postalCode= "";
73   var $vocation= "";
74   var $ivbbLastDeliveryCollective= "";
75   var $gouvernmentOrganizationalPersonLocality= "";
76   var $gouvernmentOrganizationalUnitDescription= "";
77   var $gouvernmentOrganizationalUnitSubjectArea= "";
78   var $functionalTitle= "";
79   var $role= "";
80   var $publicVisible= "";
82   var $orig_dn;
83   var $dialog;
85   /* variables to trigger password changes */
86   var $pw_storage= "crypt";
87   var $last_pw_storage= "unset";
88   var $had_userCertificate= FALSE;
90   var $view_logged = FALSE;
92   /* attribute list for save action */
93   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
94       "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
95       "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
96       "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
97       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
99   var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
100       "gosaAccount");
102   /* attributes that are part of the government mode */
103   var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
104       "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
105       "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
106       "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
107       "postalCode");
109   var $multiple_support = TRUE;
111   /* constructor, if 'dn' is set, the node loads the given
112      'dn' from LDAP */
113   function user (&$config, $dn= NULL)
114   {
115     $this->config= $config;
116     /* Configuration is fine, allways */
117     if ($this->config->current['GOVERNMENTMODE']){
118       $this->attributes=array_merge($this->attributes,$this->govattrs);
119     }
121     /* Load base attributes */
122     plugin::plugin ($config, $dn);
124     $this->orig_dn  = $this->dn;
125     $this->new_dn   = $dn;
127     if ($this->config->current['GOVERNMENTMODE']){
128       /* Fix public visible attribute if unset */
129       if (!isset($this->attrs['publicVisible'])){
130         $this->publicVisible == "nein";
131       }
132     }
134     /* Load government mode attributes */
135     if ($this->config->current['GOVERNMENTMODE']){
136       /* Copy all attributs */
137       foreach ($this->govattrs as $val){
138         if (isset($this->attrs["$val"][0])){
139           $this->$val= $this->attrs["$val"][0];
140         }
141       }
142     }
144     /* Create me for new accounts */
145     if ($dn == "new"){
146       $this->is_account= TRUE;
147     }
149     /* Make hash default to md5 if not set in config */
150     if (!isset($this->config->current['HASH'])){
151       $hash= "md5";
152     } else {
153       $hash= $this->config->current['HASH'];
154     }
156     /* Load data from LDAP? */
157     if ($dn !== NULL){
159       /* Do base conversation */
160       if ($this->dn == "new"){
161         $ui= get_userinfo();
162         $this->base= dn2base($ui->dn);
163       } else {
164         $this->base= dn2base($dn);
165       }
167       /* get password storage type */
168       if (isset ($this->attrs['userPassword'][0])){
169         /* Initialize local array */
170         $matches= array();
171         if (preg_match ("/^{([^}]+)}(.+)/", $this->attrs['userPassword'][0], $matches)){
172           $this->pw_storage= strtolower($matches[1]);
173         } else {
174           if ($this->attrs['userPassword'][0] != ""){
175             $this->pw_storage= "clear";
176           } else {
177             $this->pw_storage= $hash;
178           }
179         }
180       } else {
181         /* Preset with vaule from configuration */
182         $this->pw_storage= $hash;
183       }
185       /* Load extra attributes: certificate and picture */
186       $this->load_cert();
187       $this->load_picture();
188       if ($this->userCertificate != ""){
189         $this->had_userCertificate= TRUE;
190       }
191     }
193     /* Reset password storage indicator, used by password_change_needed() */
194     if ($dn == "new"){
195       $this->last_pw_storage= "unset";
196     } else {
197       $this->last_pw_storage= $this->pw_storage;
198     }
200     /* Generate dateOfBirth entry */
201     if (isset ($this->attrs['dateOfBirth'])){
202       /* This entry is ISO 8601 conform */
203       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
204     
205       $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
206       $this->use_dob= "1";
207     } else {
208       $this->use_dob= "0";
209     }
211     /* Put gender attribute to upper case */
212     if (isset ($this->attrs['gender'])){
213       $this->gender= strtoupper($this->attrs['gender'][0]);
214     }
215  
216     $this->orig_base = $this->base;
217   }
222   /* execute generates the html output for this node */
223   function execute()
224   {
225     /* Call parent execute */
226     plugin::execute();
228     /* Log view */
229     if($this->is_account && !$this->view_logged){
230       $this->view_logged = TRUE;
231       new log("view","users/".get_class($this),$this->dn);
232     }
234     $smarty= get_smarty();
236     /* Fill calendar */
237     if ($this->dateOfBirth == "0"){
238       $date= getdate();
239     } else {
240       if(is_array($this->dateOfBirth)){
241         $date = $this->dateOfBirth;
242   
243         // Trigger on dates like 1985-04-01, getdate only understands timestamps
244       } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
245         $date= getdate(strtotime($this->dateOfBirth));
247       } else {
248         $date = getdate($this->dateOfBirth);
249       }
250     }
252     $days= array();
253     for($d= 1; $d<32; $d++){
254       $days[$d]= $d;
255     }
256     $years= array();
258     if(($date['year']-100)<1901){
259       $start = 1901;
260     }else{
261       $start = $date['year']-100;
262     }
264     $end = $start +100;
265     
266     for($y= $start; $y<=$end; $y++){
267       $years[]= $y;
268     }
269     $years['-']= "-&nbsp;";
270     $months= array(_("January"), _("February"), _("March"), _("April"),
271         _("May"), _("June"), _("July"), _("August"), _("September"),
272         _("October"), _("November"), _("December"), '-' => '-&nbsp;');
273     $smarty->assign("day", $date["mday"]);
274     $smarty->assign("days", $days);
275     $smarty->assign("months", $months);
276     $smarty->assign("month", $date["mon"]-1);
277     $smarty->assign("years", $years);
278     $smarty->assign("year", $date["year"]);
280     /* Assign sex */
281     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
282     $smarty->assign("gender_list", $sex);
283     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
284     $smarty->assign("preferredLanguage_list", $language);
286     /* Get random number for pictures */
287     srand((double)microtime()*1000000); 
288     $smarty->assign("rand", rand(0, 10000));
291     /* Do we represent a valid gosaAccount? */
292     if (!$this->is_account){
293       echo "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
294         _("This account has no valid GOsa extensions.")."</b>";
295       return;
296     }
298     /* Base select dialog */
299     $once = true;
300     foreach($_POST as $name => $value){
301       if(preg_match("/^chooseBase/",$name) && $once){
302         $once = false;
303         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
304         $this->dialog->setCurrentBase($this->base);
305       }
306     }
308     /* Password configure dialog handling */
309     if(is_object($this->pwObject) && $this->pwObject->display){
310       $output= $this->pwObject->configure();
311       if ($output != ""){
312         $this->dialog= TRUE;
313         return $output;
314       }
315       $this->dialog= false;
316     }
318     /* Dialog handling */
319     if(is_object($this->dialog)){
320       /* Must be called before save_object */
321       $this->dialog->save_object();
322    
323       if($this->dialog->isClosed()){
324         $this->dialog = false;
325       }elseif($this->dialog->isSelected()){
327         /* check if selected base is allowed to move to / create a new object */
328         $tmp = $this->get_allowed_bases();
329         if(isset($tmp[$this->dialog->isSelected()])){
330           $this->base = $this->dialog->isSelected();
331         }
332         $this->dialog= false;
333       }else{
334         return($this->dialog->execute());
335       }
336     }
338     /* Want password method editing? */
339     if ($this->acl_is_writeable("userPassword")){
340       if (isset($_POST['edit_pw_method'])){
341         if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
342           $temp= passwordMethod::get_available_methods();
343           $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
344         }
345         $this->pwObject->display = TRUE;
346         $this->dialog= TRUE;
347         return ($this->pwObject->configure());
348       }
349     }
351     /* Want picture edit dialog? */
352     if($this->acl_is_writeable("userPicture")) {
353       if (isset($_POST['edit_picture'])){
354         /* Save values for later recovery, in case some presses
355            the cancel button. */
356         $this->old_jpegPhoto= $this->jpegPhoto;
357         $this->old_photoData= $this->photoData;
358         $this->picture_dialog= TRUE;
359         $this->dialog= TRUE;
360       }
361     }
363     /* Remove picture? */
364     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))) ){
365       if (isset($_POST['picture_remove'])){
366         $this->set_picture ();
367         $this->jpegPhoto= "*removed*";
368         $this->is_modified= TRUE;
369         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
370       }
371     }
373     /* Save picture */
374     if (isset($_POST['picture_edit_finish'])){
376       /* Check for clean upload */
377       if ($_FILES['picture_file']['name'] != ""){
378         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
379           print_red(_("The specified file has not been uploaded via HTTP POST! Aborted."));
380         }else{
381           /* Activate new picture */
382           $this->set_picture($_FILES['picture_file']['tmp_name']);
383         }
384       }
385       $this->picture_dialog= FALSE;
386       $this->dialog= FALSE;
387       $this->is_modified= TRUE;
388     }
391     /* Cancel picture */
392     if (isset($_POST['picture_edit_cancel'])){
394       /* Restore values */
395       $this->jpegPhoto= $this->old_jpegPhoto;
396       $this->photoData= $this->old_photoData;
398       /* Update picture */
399       $_SESSION['binary']= $this->photoData;
400       $_SESSION['binarytype']= "image/jpeg";
401       $this->picture_dialog= FALSE;
402       $this->dialog= FALSE;
403     }
405     /* Toggle dateOfBirth information */
406     if (isset($_POST['set_dob'])){
407       $this->use_dob= ($this->use_dob == "0")?"1":"0";
408     }
411     /* Want certificate= */
412     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
414       /* Save original values for later reconstruction */
415       foreach (array("certificateSerialNumber", "userCertificate",
416             "userSMIMECertificate", "userPKCS12") as $val){
418         $oval= "old_$val";
419         $this->$oval= $this->$val;
420       }
422       $this->cert_dialog= TRUE;
423       $this->dialog= TRUE;
424     }
427     /* Cancel certificate dialog */
428     if (isset($_POST['cert_edit_cancel'])){
430       /* Restore original values in case of 'cancel' */
431       foreach (array("certificateSerialNumber", "userCertificate",
432             "userSMIMECertificate", "userPKCS12") as $val){
434         $oval= "old_$val";
435         $this->$val= $this->$oval;
436       }
437       $this->cert_dialog= FALSE;
438       $this->dialog= FALSE;
439     }
442     /* Remove certificate? */
443     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
444       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
445         if (isset($_POST["remove_$val"])){
447           /* Reset specified cert*/
448           $this->$val= "";
449           $this->is_modified= TRUE;
450         }
451       }
452     }
454     /* Upload new cert and close dialog? */     
455     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
456       if (isset($_POST['cert_edit_finish'])){
458         /* for all certificates do */
459         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
460             as $val){
462           /* Check for clean upload */
463           if (array_key_exists($val."_file", $_FILES) &&
464               array_key_exists('name', $_FILES[$val."_file"]) &&
465               $_FILES[$val."_file"]['name'] != "" &&
466               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
467             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
468           }
469         }
471         /* Save serial number */
472         if (isset($_POST["certificateSerialNumber"]) &&
473             $_POST["certificateSerialNumber"] != ""){
475           if (!is_id($_POST["certificateSerialNumber"])){
476             print_red (_("Please enter a valid serial number"));
478             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
479               if ($this->$cert != ""){
480                 $smarty->assign("$cert"."_state", "true");
481               } else {
482                 $smarty->assign("$cert"."_state", "");
483               }
484             }
485             return ($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
486           }
488           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
489           $this->is_modified= TRUE;
490         }
492         $this->cert_dialog= FALSE;
493         $this->dialog= FALSE;
494       }
495     }
496     /* Display picture dialog */
497     if ($this->picture_dialog){
498       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
499     }
501     /* Display cert dialog */
502     if ($this->cert_dialog){
503       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
504       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
506       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
507         if ($this->$cert != ""){
508           /* import certificate */
509           $certificate = new certificate;
510           $certificate->import($this->$cert);
511       
512           /* Read out data*/
513           $timeto   = $certificate->getvalidto_date();
514           $timefrom = $certificate->getvalidfrom_date();
515          
516           
517           /* Additional info if start end time is '0' */
518           $add_str_info = "";
519           if($timeto == 0 && $timefrom == 0){
520             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
521           }
523           $str = "<table summary=\"\" border=0>
524                     <tr>
525                       <td style='vertical-align:top'>CN</td>
526                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
527                     </tr>
528                   </table><br>".
530                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
531                         "<b>".date('d M Y',$timefrom)."</b>",
532                         "<b>".date('d M Y',$timeto)."</b>",
533                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
534                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
536           $smarty->assign($cert."info",$str);
537           $smarty->assign($cert."_state","true");
538         } else {
539           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
540           $smarty->assign($cert."_state","");
541         }
542       }
543       $smarty->assign("governmentmode", "false");
544       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
545     }
547     /* Prepare password hashes */
548     if ($this->pw_storage == ""){
549       $this->pw_storage= $this->config->current['HASH'];
550     }
552     $temp= passwordMethod::get_available_methods();
553     $is_configurable= FALSE;
554     $hashes = $temp['name'];
555     if(isset($temp[$this->pw_storage])){
556       $test= new $temp[$this->pw_storage]($this->config);
557       $is_configurable= $test->is_configurable();
558     }else{
559       new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
560     }
561     
562     /* Load attributes and acl's */
563     $ui =get_userinfo();
564     foreach($this->attributes as $val){
565       $smarty->assign("$val", $this->$val);
566       if(in_array($val,$this->multi_boxes)){
567         $smarty->assign("use_".$val,TRUE);
568       }else{
569         $smarty->assign("use_".$val,FALSE);
570       }
571     }
572     foreach(array("base","pw_storage","edit_picture") as $val){
573       if(in_array($val,$this->multi_boxes)){
574         $smarty->assign("use_".$val,TRUE);
575       }else{
576         $smarty->assign("use_".$val,FALSE);
577       }
578     }
580     /* Set acls */
581     $tmp = $this->plinfo();
582     foreach($tmp['plProvidedAcls'] as $val => $translation){
583       $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
584     }
586     $smarty->assign("pwmode", $hashes);
587     $smarty->assign("pwmode_select", $this->pw_storage);
588     $smarty->assign("pw_configurable", $is_configurable);
589     $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !isset($_SESSION['edit']))));
590     $smarty->assign("base_select",      $this->base);
591     $smarty->assign("CertificatesACL",  $this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
592     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
593     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
595     /* Create base acls */
596     $tmp = @$this->allowedBasesToMoveTo();
597     $smarty->assign("bases", $tmp);
599     /* Save government mode attributes */
600     if (isset($this->config->current['GOVERNMENTMODE']) &&
601         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
602       $smarty->assign("governmentmode", "true");
603       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
604           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
605       $smarty->assign("ivbbmodes", $ivbbmodes);
606       foreach ($this->govattrs as $val){
607         $smarty->assign("$val", $this->$val);
608         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
609       }
610     } else {
611       $smarty->assign("governmentmode", "false");
612     }
614     /* Special mode for uid */
615     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])));
616     if (isset ($this->dn)){
617       if ($this->dn != "new"){
618         $uidACL= preg_replace("/w/","",$uidACL);
619       }
620     }  else {
621       $uidACL= preg_replace("/w/","",$uidACL);
622     }
623     
624     $smarty->assign("uidACL", $uidACL);
625     $smarty->assign("is_template", $this->is_template);
626     $smarty->assign("use_dob", $this->use_dob);
628     if (isset($this->parent)){
629       if (isset($this->parent->by_object['phoneAccount']) &&
630           $this->parent->by_object['phoneAccount']->is_account){
631         $smarty->assign("has_phoneaccount", "true");
632       } else {
633         $smarty->assign("has_phoneaccount", "false");
634       }
635     } else {
636       $smarty->assign("has_phoneaccount", "false");
637     }
638     $smarty->assign("multiple_support" , $this->multiple_support_active);
639     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
640   }
643   /* remove object from parent */
644   function remove_from_parent()
645   {
646     /* Remove password extension */
647     $temp= passwordMethod::get_available_methods();
648     $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
649     $this->pwObject->remove_from_parent();
651     /* Remove user */
652     $ldap= $this->config->get_ldap_link();
653     $ldap->rmdir ($this->dn);
654     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/generic account with dn '%s' failed."),$this->dn));
655   
656     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
657   
658     /* Delete references to groups */
659     $ldap->cd ($this->config->current['BASE']);
660     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
661     while ($ldap->fetch()){
662       $g= new group($this->config, $ldap->getDN());
663       $g->removeUser($this->uid);
664       $g->save ();
665     }
667     /* Delete references to object groups */
668     $ldap->cd ($this->config->current['BASE']);
669     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
670     while ($ldap->fetch()){
671       $og= new ogroup($this->config, $ldap->getDN());
672       unset($og->member[$this->dn]);
673       $og->save ();
674     }
676     /* If needed, let the password method do some cleanup */
677     $tmp = new passwordMethod($_SESSION['config']);
678     $available = $tmp->get_available_methods();
679     if (in_array_ics($this->pw_storage, $available['name'])){
680       $test= new $available[$this->pw_storage]($this->config);
681       $test->attrs= $this->attrs;
682       $test->dn= $this->dn;
683       $test->remove_from_parent();
684     }
686     /* Remove ACL dependencies too */
687     $tmp = new acl($this->config,$this->parent,$this->dn);
688     $tmp->remove_acl();
690     /* Optionally execute a command after we're done */
691     $this->handle_post_events("remove",array("uid" => $this->uid));
692   }
695   /* Save data to object */
696   function save_object()
697   {
698     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
700       /* Make a backup of the current selected base */
701       $base_tmp = $this->base;
703       /* Parents save function */
704       plugin::save_object ();
706       /* Save government mode attributes */
707       if ($this->config->current['GOVERNMENTMODE']){
708         foreach ($this->govattrs as $val){
709           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !isset($_SESSION['edit']))) && isset($_POST["$val"])){
710             $data= stripcslashes($_POST["$val"]);
711             if ($data != $this->$val){
712               $this->is_modified= TRUE;
713             }
714             $this->$val= $data;
715           }
716         }
717       }
719       /* In template mode, the uid is autogenerated... */
720       if ($this->is_template){
721         $this->uid= strtolower($this->sn);
722         $this->givenName= $this->sn;
723       }
725       /* Save base and pw_storage, since these are no LDAP attributes */
726       if (isset($_POST['base'])){
728         $tmp = $this->get_allowed_bases();
729         if(isset($tmp[$_POST['base']])){
730           $base= validate($_POST['base']);
731           if ($base != $this->base){
732             $this->is_modified= TRUE;
733           }
734           $this->base= $base;
735         }else{
736           $this->base = $base_tmp;
737           print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
738           $this->set_acl_base('dummy,'.$this->base);
739         }
740       }
742       /* Get pw_storage mode */
743       if (isset($_POST['pw_storage'])){
744         foreach(array("pw_storage") as $val){
745           if(isset($_POST[$val])){
746             $data= validate($_POST[$val]);
747             if ($data != $this->$val){
748               $this->is_modified= TRUE;
749             }
750             $this->$val= $data;
751           }
752         }
753       }
755       $this->set_acl_base('dummy,'.$this->base);
756     }
757   }
759   function rebind($ldap, $referral)
760   {
761     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
762     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
763       $this->error = "Success";
764       $this->hascon=true;
765       $this->reconnect= true;
766       return (0);
767     } else {
768       $this->error = "Could not bind to " . $credentials['ADMIN'];
769       return NULL;
770     }
771   }
773   
774   /* Save data to LDAP, depending on is_account we save or delete */
775   function save()
776   {
777     /* Only force save of changes .... 
778        If this attributes aren't changed, avoid saving.
779      */
780     if($this->gender=="0") $this->gender ="";
781     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
783     /* First use parents methods to do some basic fillup in $this->attrs */
784     plugin::save ();
786     if ($this->use_dob == "1"){
787       /* If it is an array, the generic page has never been loaded - so there's no difference. Using an array would cause an error btw. */
788       if(!is_array($this->attrs['dateOfBirth'])) {
789         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
790       }
791     }
793     /* Remove additional objectClasses */
794     $tmp= array();
795     foreach ($this->attrs['objectClass'] as $key => $set){
796       $found= false;
797       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
798         if (preg_match ("/^$set$/i", $val)){
799           $found= true;
800           break;
801         }
802       }
803       if (!$found){
804         $tmp[]= $set;
805       }
806     }
808     /* Replace the objectClass array. This is done because of the
809        separation into government and normal mode. */
810     $this->attrs['objectClass']= $tmp;
812     /* Add objectClasss for template mode? */
813     if ($this->is_template){
814       $this->attrs['objectClass'][]= "gosaUserTemplate";
815     }
817     /* Hard coded government mode? */
818     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
819       $this->attrs['objectClass'][]= "ivbbentry";
821       /* Copy standard attributes */
822       foreach ($this->govattrs as $val){
823         if ($this->$val != ""){
824           $this->attrs["$val"]= $this->$val;
825         } elseif (!$this->is_new) {
826           $this->attrs["$val"]= array();
827         }
828       }
830       /* Remove attribute if set to "nein" */
831       if ($this->publicVisible == "nein"){
832         $this->attrs['publicVisible']= array();
833         if($this->is_new){
834           unset($this->attrs['publicVisible']);
835         }else{
836           $this->attrs['publicVisible']=array();
837         }
839       }
841     }
843     /* Special handling for attribute userCertificate needed */
844     if ($this->userCertificate != ""){
845       $this->attrs["userCertificate;binary"]= $this->userCertificate;
846       $remove_userCertificate= false;
847     } else {
848       $remove_userCertificate= true;
849     }
851     /* Special handling for dateOfBirth value */
852     if ($this->use_dob != "1"){
853       if ($this->is_new) {
854         unset($this->attrs["dateOfBirth"]);
855       } else {
856         $this->attrs["dateOfBirth"]= array();
857       }
858     }
859     if (!$this->gender){
860       if ($this->is_new) {
861         unset($this->attrs["gender"]);
862       } else {
863         $this->attrs["gender"]= array();
864       }
865     }
866     if (!$this->preferredLanguage){
867       if ($this->is_new) {
868         unset($this->attrs["preferredLanguage"]);
869       } else {
870         $this->attrs["preferredLanguage"]= array();
871       }
872     }
874     /* Special handling for attribute jpegPhote needed, scale image via
875        image magick to 147x200 pixels and inject resulting data. */
876     if ($this->jpegPhoto == "*removed*"){
877     
878       /* Reset attribute to avoid writing *removed* as value */    
879       $this->attrs["jpegPhoto"] = array();
881     } else {
883       /* Fallback if there's no image magick inside PHP */
884       if (!function_exists("imagick_blob2image")){
885         /* Get temporary file name for conversation */
886         $fname = tempnam ("/tmp", "GOsa");
887   
888         /* Open file and write out photoData */
889         $fp = fopen ($fname, "w");
890         fwrite ($fp, $this->photoData);
891         fclose ($fp);
893         /* Build conversation query. Filename is generated automatically, so
894            we do not need any special security checks. Exec command and save
895            output. For PHP safe mode, you'll need a configuration which respects
896            image magick as executable... */
897         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
898         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
899             $query, "Execute");
900   
901         /* Read data written by convert */
902         $output= "";
903         $sh= popen($query, 'r');
904         while (!feof($sh)){
905           $output.= fread($sh, 4096);
906         }
907         pclose($sh);
909         unlink($fname);
911         /* Save attribute */
912         $this->attrs["jpegPhoto"] = $output;
914       } else {
916         /* Load the new uploaded Photo */
917         if(!$handle  =  imagick_blob2image($this->photoData))  {
918           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
919         }
921         /* Resizing image to 147x200 and blur */
922         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
923           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
924         }
926         /* Converting image to JPEG */
927         if(!imagick_convert($handle,"JPEG")) {
928           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
929         }
931         /* Creating binary Code for the Image */
932         if(!$dump = imagick_image2blob($handle)){
933           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
934         }
936         /* Sending Image */
937         $output=  $dump;
939         /* Save attribute */
940         $this->attrs["jpegPhoto"] = $output;
941       }
943     }
945     /* This only gets called when user is renaming himself */
946     $ldap= $this->config->get_ldap_link();
947     if ($this->dn != $this->new_dn){
949       /* Write entry on new 'dn' */
950       $this->update_acls($this->dn,$this->new_dn);
951       $this->move($this->dn, $this->new_dn);
953       /* Happen to use the new one */
954       change_ui_dn($this->dn, $this->new_dn);
955       $this->dn= $this->new_dn;
956     }
959     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
960        new entries. So do a check first... */
961     $ldap->cat ($this->dn, array('dn'));
962     if ($ldap->fetch()){
963       $mode= "modify";
964     } else {
965       $mode= "add";
966       $ldap->cd($this->config->current['BASE']);
967       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
968     }
970     /* Set password to some junk stuff in case of templates */
971     if ($this->is_template){
972       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
973     }
975     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
976         $this->attributes, "Save via $mode");
978     /* Finally write data with selected 'mode' */
979     $this->cleanup();
981     if(isset($this->attrs['preferredLanguage'])){
982       $_SESSION['ui']->language = $this->preferredLanguage;
983       $_SESSION['Last_init_lang'] = "update";
984     }
986     $ldap->cd ($this->dn);
987     $ldap->$mode ($this->attrs);
988     if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){
989       return (1);
990     }
992     /* Remove ACL dependencies too */
993     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
994       $tmp = new acl($this->config,$this->parent,$this->dn);
995       $tmp->update_acl_membership($this->orig_dn,$this->dn);
996     }
998     if($mode == "modify"){
999       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1000     }else{
1001       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1002     }
1004     /* Remove cert? 
1005        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1006        to work around myself. */
1007     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1009       /* Reset array, assemble new, this should be reworked */
1010       $this->attrs= array();
1011       $this->attrs['userCertificate;binary']= array();
1013       /* Prepare connection */
1014       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1015         die ("Could not connect to LDAP server");
1016       }
1017       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1018       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1019         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1020         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1021       }
1022       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1023         ldap_start_tls($ds);
1024       }
1025       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1026               $this->config->current['PASSWORD']))) {
1027         die ("Could not bind to LDAP");
1028       }
1030       /* Modify using attrs */
1031       ldap_mod_del($ds,$this->dn,$this->attrs);
1032       ldap_close($ds);
1033     }
1035     /* If needed, let the password method do some cleanup */
1036     if ($this->pw_storage != $this->last_pw_storage){
1037       $tmp = new passwordMethod($_SESSION['config']);
1038       $available = $tmp->get_available_methods();
1039       if (in_array_ics($this->last_pw_storage, $available['name'])){
1040         $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1041         $test->attrs= $this->attrs;
1042         $test->remove_from_parent();
1043       }
1044     }
1046     /* Maybe the current password method want's to do some changes... */
1047     if (is_object($this->pwObject)){
1048       $this->pwObject->save($this->dn);
1049     }
1051     /* Optionally execute a command after we're done */
1052     if ($mode == "add"){
1053       $this->handle_post_events("add", array("uid" => $this->uid));
1054     } elseif ($this->is_modified){
1055       $this->handle_post_events("modify", array("uid" => $this->uid));
1056     }
1058     /* Fix tagging if needed */
1059     $this->handle_object_tagging();
1061     return (0);
1062   }
1064   
1065   function update_new_dn()
1066   {
1067     $pt= "";
1068     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1069       if(!empty($this->personalTitle)){
1070         $pt = $this->personalTitle." ";
1071       }
1072     }
1073     $this->cn= $pt.$this->givenName." ".$this->sn;
1075     /* Permissions for that base? */
1076     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1077       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1078     } else {
1079       /* Don't touch dn, if cn hasn't changed */
1080       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1081           $this->orig_base == $this->base ){
1082         $this->new_dn= $this->dn;
1083       } else {
1084         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1085       }
1086     }
1087   }
1088   
1090   /* Check formular input */
1091   function check()
1092   {
1093     /* Call common method to give check the hook */
1094     $message= plugin::check();
1096     $this->update_new_dn();
1098     /* Set the new acl base */
1099     if($this->dn == "new") {
1100       $this->set_acl_base($this->base);
1101     }
1103     /* UID already used? */
1104     $ldap= $this->config->get_ldap_link();
1105     $ldap->cd($this->config->current['BASE']);
1106     $ldap->search("(uid=$this->uid)", array("uid"));
1107     $ldap->fetch();
1108     if ($ldap->count() != 0 && $this->dn == 'new'){
1109       $message[]= _("There's already a person with this 'Login' in the database.");
1110     }
1112     /* In template mode, the uid and givenName are autogenerated... */
1113     if (!$this->is_template){
1114       if ($this->sn == ""){
1115         $message[]= _("The required field 'Name' is not set.");
1116       }
1117       if ($this->givenName == ""){
1118         $message[]= _("The required field 'Given name' is not set.");
1119       }
1120       if ($this->uid == ""){
1121         $message[]= _("The required field 'Login' is not set.");
1122       }
1123       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1124         $ldap->cat($this->new_dn);
1125         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1126           $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
1127         }
1128       }
1129     }
1131     /* Check for valid input */
1132     if ($this->is_modified && !is_uid($this->uid)){
1133       $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
1134     }
1135     if (!is_url($this->labeledURI)){
1136       $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1137     }
1138     if (preg_match ("/[\\\\]/", $this->sn)){
1139       $message[]= _("The field 'Name' contains invalid characters.");
1140     }
1141     if (preg_match ("/[\\\\]/", $this->givenName)){
1142       $message[]= _("The field 'Given name' contains invalid characters.");
1143     }
1145     /* Check phone numbers */
1146     if (!is_phone_nr($this->telephoneNumber)){
1147       $message[]= _("The field 'Phone' contains an invalid phone number.");
1148     }
1149     if (!is_phone_nr($this->facsimileTelephoneNumber)){
1150       $message[]= _("The field 'Fax' contains an invalid phone number.");
1151     }
1152     if (!is_phone_nr($this->mobile)){
1153       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1154     }
1155     if (!is_phone_nr($this->pager)){
1156       $message[]= _("The field 'Pager' contains an invalid phone number.");
1157     }
1159     /* Check for reserved characers */
1160     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
1161       $message[]= _("The field 'Given name' contains invalid characters.");
1162   }
1163   if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
1164     $message[]= _("The field 'Name' contains invalid characters.");
1165   }
1167   return $message;
1168   }
1171   /* Indicate whether a password change is needed or not */
1172   function password_change_needed()
1173   {
1174     if(in_array("pw_storage",$this->multi_boxes)){
1175       return(TRUE);
1176     }
1177     return($this->pw_storage != $this->last_pw_storage);
1178   }
1181   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1182   function load_picture()
1183   {
1184     $ldap = $this->config->get_ldap_link();
1185     $ldap->cd ($this->dn);
1186     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1188     if((!$data) || ($data == "*removed*")){ 
1190       /* In case we don't get an entry, load a default picture */
1191       $this->set_picture ();//"./images/default.jpg");
1192       $this->jpegPhoto= "*removed*";
1193     }else{
1195       /* Set picture */
1196       $this->photoData= $data;
1197       $_SESSION['binary']= $this->photoData;
1198       $_SESSION['binarytype']= "image/jpeg";
1199       $this->jpegPhoto= "";
1200     }
1201   }
1204   /* Load a certificate from LDAP, this is going to be simplified later on */
1205   function load_cert()
1206   {
1207     $ds= ldap_connect($this->config->current['SERVER']);
1208     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1209     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1210       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1211       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1212     }
1213     if(isset($this->config->current['TLS']) &&
1214         $this->config->current['TLS'] == "true"){
1216       ldap_start_tls($ds);
1217     }
1219     $r= ldap_bind($ds);
1220     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1222     if ($sr) {
1223       $ei= @ldap_first_entry($ds, $sr);
1224       
1225       if ($ei) {
1226         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1227           $this->userCertificate= "";
1228         } else {
1229           $this->userCertificate= $info[0];
1230         }
1231       }
1232     } else {
1233       $this->userCertificate= "";
1234     }
1236     ldap_unbind($ds);
1237   }
1240   /* Load picture from file to object */
1241   function set_picture($filename ="")
1242   {
1243     if (!is_file($filename) || $filename =="" ){
1244       $filename= "./images/default.jpg";
1245       $this->jpegPhoto= "*removed*";
1246     }
1248     $fd = fopen ($filename, "rb");
1249     $this->photoData= fread ($fd, filesize ($filename));
1250     $_SESSION['binary']= $this->photoData;
1251     $_SESSION['binarytype']= "image/jpeg";
1252     $this->jpegPhoto= "";
1254     fclose ($fd);
1255   }
1258   /* Load certificate from file to object */
1259   function set_cert($cert, $filename)
1260   {
1261     if(!$thsi->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))) return;
1262     $fd = fopen ($filename, "rb");
1263     if (filesize($filename)>0) {
1264       $this->$cert= fread ($fd, filesize ($filename));
1265       fclose ($fd);
1266       $this->is_modified= TRUE;
1267     } else {
1268       print_red(_("Could not open specified certificate!"));
1269     }
1270   }
1272   /* Adapt from given 'dn' */
1273   function adapt_from_template($dn)
1274   {
1275     plugin::adapt_from_template($dn);
1277     /* Get base */
1278     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1280     if ($this->config->current['GOVERNMENTMODE']){
1282       /* Walk through govattrs */
1283       foreach ($this->govattrs as $val){
1285         if (isset($this->attrs["$val"][0])){
1287           /* If attribute is set, replace dynamic parts: 
1288              %sn, %givenName and %uid. Fill these in our local variables. */
1289           $value= $this->attrs["$val"][0];
1291           foreach (array("sn", "givenName", "uid") as $repl){
1292             if (preg_match("/%$repl/i", $value)){
1293               $value= preg_replace ("/%$repl/i",
1294                   $this->parent->$repl, $value);
1295             }
1296           }
1297           $this->$val= $value;
1298         }
1299       }
1300     }
1302     /* Get back uid/sn/givenName */
1303     if ($this->parent !== NULL){
1304       $this->uid= $this->parent->uid;
1305       $this->sn= $this->parent->sn;
1306       $this->givenName= $this->parent->givenName;
1307     }
1308   }
1310  
1311   /* This avoids that users move themselves out of their rights. 
1312    */
1313   function allowedBasesToMoveTo()
1314   {
1315     /* Get bases */
1316     $bases  = $this->get_allowed_bases();
1317     return($bases);
1318   } 
1321   function getCopyDialog()
1322   {
1323     $str = "";
1325     $_SESSION['binary'] = $this->photoData; 
1326     $_SESSION['binarytype']= "image/jpeg";
1328     /* Get random number for pictures */
1329     srand((double)microtime()*1000000); 
1330     $rand = rand(0, 10000);
1332     $smarty = get_smarty();
1334     $smarty->assign("passwordTodo","clear");
1336     if(isset($_POST['passwordTodo'])){
1337       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1338     }
1340     $smarty->assign("sn",       $this->sn);
1341     $smarty->assign("givenName",$this->givenName);
1342     $smarty->assign("uid",      $this->uid);
1343     $smarty->assign("rand",     $rand);
1344     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1347     $ret = array();
1348     $ret['string'] = $str;
1349     $ret['status'] = "";  
1350     return($ret);
1351   }
1353   function saveCopyDialog()
1354   {
1355     /* Set_acl_base */
1356     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1358     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1359       $this->set_picture($_FILES['picture_file']['tmp_name']);
1360     }
1362     /* Remove picture? */
1363     if (isset($_POST['picture_remove'])){
1364       $this->jpegPhoto= "*removed*";
1365       $this->set_picture ("./images/default.jpg");
1366       $this->is_modified= TRUE;
1367     }
1369     $attrs = array("uid","givenName","sn");
1370     foreach($attrs as $attr){
1371       if(isset($_POST[$attr])){
1372         $this->$attr = $_POST[$attr];
1373       }
1374     } 
1375   }
1378   function PrepareForCopyPaste($source)
1379   {
1380     plugin::PrepareForCopyPaste($source);
1382     /* Reset certificate information addepted from source user
1383        to avoid setting the same user certificate for the destination user. */
1384     $this->userPKCS12= "";
1385     $this->userSMIMECertificate= "";
1386     $this->userCertificate= "";
1387     $this->certificateSerialNumber= "";
1388     $this->old_certificateSerialNumber= "";
1389     $this->old_userPKCS12= "";
1390     $this->old_userSMIMECertificate= "";
1391     $this->old_userCertificate= "";
1392   }
1395   static function plInfo()
1396   {
1397   
1398     $govattrs= array(
1399         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1400         "houseIdentifier"                           =>  _("House identifier"), 
1401         "vocation"                                  =>  _("Vocation"),
1402         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1403         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1404         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1405         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1406         "functionalTitle"                           =>  _("Functional title"),
1407         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1408         "publicVisible"                             =>  _("Public visible"),
1409         "street"                                    =>  _("Street"),
1410         "role"                                      =>  _("Role"),
1411         "postalCode"                                =>  _("Postal code"));
1413     $ret = array(
1414         "plShortName" => _("Generic"),
1415         "plDescription" => _("Generic user settings"),
1416         "plSelfModify"  => TRUE,
1417         "plDepends"     => array(),
1418         "plPriority"    => 1,
1419         "plSection"     => array("personal" => _("My account")),
1420         "plCategory"    => array("users" => array("description" => _("Users"),
1421                                                   "objectClass" => "gosaAccount")),
1423         "plProvidedAcls" => array(
1424           "base"              => _("Base"), 
1425           "userPassword"      => _("User password"), 
1426           "sn"                => _("Surename"),
1427           "givenName"         => _("Given name"),
1428           "uid"               => _("User identification"),
1429           "personalTitle"     => _("Personal title"),
1430           "academicTitle"     => _("Academic title"),
1431           "homePostalAddress" => _("Home postal address"),
1432           "homePhone"         => _("Home phone number"),
1433           "labeledURI"        => _("Homepage"),
1434           "o"                 => _("Organization"),
1435           "ou"                => _("Department"),
1436           "dateOfBirth"       => _("Date of birth"),
1437           "gender"            => _("Gender"),
1438           "preferredLanguage" => _("Preferred language"),
1439           "departmentNumber"  => _("Department number"),
1440           "employeeNumber"    => _("Employee number"),
1441           "employeeType"      => _("Employee type"),
1442           "l"                 => _("Location"),
1443           "st"                => _("State"),
1444           "userPicture"       => _("User picture"),
1445           "roomNumber"        => _("Room number"),
1446           "telephoneNumber"   => _("Telefon number"),
1447           "mobile"            => _("Mobile number"),
1448           "pager"             => _("Pager number"),
1449           "Certificate"        => _("User certificates"),
1451           "postalAddress"                => _("Postal address"),
1452           "facsimileTelephoneNumber"     => _("Fax number"))
1453         );
1455     /* Append government attributes if required */
1456       global $config;
1457     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1458       foreach($govattrs as $attr => $desc){
1459         $ret["plProvidedAcls"][$attr] = $desc;
1460       }
1461     }
1462     return($ret);
1463   }
1465   function get_multi_edit_values()
1466   {
1467     $ret = plugin::get_multi_edit_values();
1468     if(in_array("pw_storage",$this->multi_boxes)){
1469       $ret['pw_storage'] = $this->pw_storage;
1470     }
1471     if(in_array("edit_picture",$this->multi_boxes)){
1472       $ret['jpegPhoto'] = $this->jpegPhoto;
1473       $ret['photoData'] = $this->photoData;
1474       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1475       $ret['old_photoData'] = $this->old_photoData;
1476     }
1477     if(isset($ret['dateOfBirth'])){
1478       unset($ret['dateOfBirth']);
1479     }
1480     if(isset($ret['cn'])){
1481       unset($ret['cn']);
1482     }
1483     $ret['is_modified'] = $this->is_modified;
1484     if(in_array("base",$this->multi_boxes)){
1485       $ret['orig_base']="Changed_by_Multi_Plug";
1486       $ret['base']=$this->base;
1487     }
1488     return($ret); 
1489   }
1492   function multiple_save_object()
1493   {
1494     plugin::multiple_save_object();
1496     /* Get pw_storage mode */
1497     if (isset($_POST['pw_storage'])){
1498       foreach(array("pw_storage") as $val){
1499         if(isset($_POST[$val])){
1500           $data= validate(get_post($val));
1501           if ($data != $this->$val){
1502             $this->is_modified= TRUE;
1503           }
1504           $this->$val= $data;
1505         }
1506       }
1507     }
1508     if(isset($_POST['base'])){
1509       $this->base = get_post('base');
1510     }
1512     if(isset($_POST['user_mulitple_edit'])){
1513       foreach(array("base","pw_storage","edit_picture") as $val){
1514         if(isset($_POST["use_".$val])){
1515           $this->multi_boxes[] = $val;
1516         }
1517       }
1518     }
1519   }
1521   
1522   function multiple_check()
1523   {
1524     /* Call check() to set new_dn correctly ... */
1525     $message = plugin::multiple_check();
1527     /* Set the new acl base */
1528     if($this->dn == "new") {
1529       $this->set_acl_base($this->base);
1530     }
1531     if (!is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1532       $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1533     }
1534     if (preg_match ("/[\\\\]/", $this->sn) && in_array("sn",$this->multi_boxes)){
1535       $message[]= _("The field 'Name' contains invalid characters.");
1536     }
1537     if (preg_match ("/[\\\\]/", $this->givenName) && in_array("givenName",$this->multi_boxes)){
1538       $message[]= _("The field 'Given name' contains invalid characters.");
1539     }
1540     if (!is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1541       $message[]= _("The field 'Phone' contains an invalid phone number.");
1542     }
1543     if (!is_phone_nr($this->facsimileTelephoneNumber) &&  in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1544       $message[]= _("The field 'Fax' contains an invalid phone number.");
1545     }
1546     if (!is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1547       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1548     }
1549     if (!is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1550       $message[]= _("The field 'Pager' contains an invalid phone number.");
1551     }
1552     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1553       $message[]= _("The field 'Given name' contains invalid characters.");
1554     }
1555     if (preg_match ('/[,+"?\'()=<>;]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1556       $message[]= _("The field 'Name' contains invalid characters.");
1557     }
1558     return($message);
1559   }
1563   function multiple_execute()
1564   {
1565     return($this->execute());
1566   }
1571 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1572 ?>