Code

16198fe7b33b891b5b334bfd7c82b63098a11fd3
[gosa.git] / 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;
110   var $multiple_user_handles  = array();
112   /* constructor, if 'dn' is set, the node loads the given
113      'dn' from LDAP */
114   function user (&$config, $dn= NULL)
115   {
117     $this->config= $config;
118     /* Configuration is fine, allways */
119     if ($this->config->current['GOVERNMENTMODE']){
120       $this->attributes=array_merge($this->attributes,$this->govattrs);
121     }
123     /* Load base attributes */
124     plugin::plugin ($config, $dn);
126     $this->orig_dn  = $this->dn;
127     $this->new_dn   = $this->dn;
129     $this->new_dn = $dn;
131     if ($this->config->current['GOVERNMENTMODE']){
132       /* Fix public visible attribute if unset */
133       if (!isset($this->attrs['publicVisible'])){
134         $this->publicVisible == "nein";
135       }
136     }
138     /* Load government mode attributes */
139     if ($this->config->current['GOVERNMENTMODE']){
140       /* Copy all attributs */
141       foreach ($this->govattrs as $val){
142         if (isset($this->attrs["$val"][0])){
143           $this->$val= $this->attrs["$val"][0];
144         }
145       }
146     }
148     /* Create me for new accounts */
149     if ($dn == "new"){
150       $this->is_account= TRUE;
151     }
153     /* Make hash default to md5 if not set in config */
154     if (!isset($this->config->current['HASH'])){
155       $hash= "md5";
156     } else {
157       $hash= $this->config->current['HASH'];
158     }
160     /* Load data from LDAP? */
161     if ($dn !== NULL){
163       /* Do base conversation */
164       if ($this->dn == "new"){
165         $ui= get_userinfo();
166         $this->base= dn2base($ui->dn);
167       } else {
168         $this->base= dn2base($dn);
169       }
171       /* get password storage type */
172       if (isset ($this->attrs['userPassword'][0])){
173         /* Initialize local array */
174         $matches= array();
175         if (preg_match ("/^{([^}]+)}(.+)/", $this->attrs['userPassword'][0], $matches)){
176           $this->pw_storage= strtolower($matches[1]);
177         } else {
178           if ($this->attrs['userPassword'][0] != ""){
179             $this->pw_storage= "clear";
180           } else {
181             $this->pw_storage= $hash;
182           }
183         }
184       } else {
185         /* Preset with vaule from configuration */
186         $this->pw_storage= $hash;
187       }
189       /* Load extra attributes: certificate and picture */
190       $this->load_cert();
191       $this->load_picture();
192       if ($this->userCertificate != ""){
193         $this->had_userCertificate= TRUE;
194       }
195     }
197     /* Reset password storage indicator, used by password_change_needed() */
198     if ($dn == "new"){
199       $this->last_pw_storage= "unset";
200     } else {
201       $this->last_pw_storage= $this->pw_storage;
202     }
204     /* Generate dateOfBirth entry */
205     if (isset ($this->attrs['dateOfBirth'])){
206       /* This entry is ISO 8601 conform */
207       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
208     
209       $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
210       $this->use_dob= "1";
211     } else {
212       $this->use_dob= "0";
213     }
215     /* Put gender attribute to upper case */
216     if (isset ($this->attrs['gender'])){
217       $this->gender= strtoupper($this->attrs['gender'][0]);
218     }
219  
220     $this->orig_base = $this->base;
221   }
226   /* execute generates the html output for this node */
227   function execute()
228   {
229     /* Call parent execute */
230     plugin::execute();
232     /* Log view */
233     if($this->is_account && !$this->view_logged){
234       $this->view_logged = TRUE;
235       new log("view","users/".get_class($this),$this->dn);
236     }
238     $smarty= get_smarty();
240     /* Fill calendar */
241     if ($this->dateOfBirth == "0"){
242       $date= getdate();
243     } else {
244       if(is_array($this->dateOfBirth)){
245         $date = $this->dateOfBirth;
246   
247         // Trigger on dates like 1985-04-01, getdate only understands timestamps
248       } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
249         $date= getdate(strtotime($this->dateOfBirth));
251       } else {
252         $date = getdate($this->dateOfBirth);
253       }
254     }
256     $days= array();
257     for($d= 1; $d<32; $d++){
258       $days[$d]= $d;
259     }
260     $years= array();
262     if(($date['year']-100)<1901){
263       $start = 1901;
264     }else{
265       $start = $date['year']-100;
266     }
268     $end = $start +100;
269     
270     for($y= $start; $y<=$end; $y++){
271       $years[]= $y;
272     }
273     $years['-']= "-&nbsp;";
274     $months= array(_("January"), _("February"), _("March"), _("April"),
275         _("May"), _("June"), _("July"), _("August"), _("September"),
276         _("October"), _("November"), _("December"), '-' => '-&nbsp;');
277     $smarty->assign("day", $date["mday"]);
278     $smarty->assign("days", $days);
279     $smarty->assign("months", $months);
280     $smarty->assign("month", $date["mon"]-1);
281     $smarty->assign("years", $years);
282     $smarty->assign("year", $date["year"]);
284     /* Assign sex */
285     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
286     $smarty->assign("gender_list", $sex);
287     
288     if($this->multiple_support_active){
289       $language= array_merge(array(0 => "&nbsp;","{default}"=>"{default}") ,get_languages(TRUE));
290     }else{
291       $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
292     }
293     $smarty->assign("preferredLanguage_list", $language);
295     /* Get random number for pictures */
296     srand((double)microtime()*1000000); 
297     $smarty->assign("rand", rand(0, 10000));
300     /* Do we represent a valid gosaAccount? */
301     if (!$this->is_account){
302       echo "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
303         _("This account has no valid GOsa extensions.")."</b>";
304       return;
305     }
307     /* Base select dialog */
308     $once = true;
309     foreach($_POST as $name => $value){
310       if(preg_match("/^chooseBase/",$name) && $once){
311         $once = false;
312         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
313         $this->dialog->setCurrentBase($this->base);
314       }
315     }
317     /* Password configure dialog handling */
318     if(is_object($this->pwObject) && $this->pwObject->display){
319       $output= $this->pwObject->configure();
320       if ($output != ""){
321         $this->dialog= TRUE;
322         return $output;
323       }
324       $this->dialog= false;
325     }
327     /* Dialog handling */
328     if(is_object($this->dialog)){
329       /* Must be called before save_object */
330       $this->dialog->save_object();
331    
332       if($this->dialog->isClosed()){
333         $this->dialog = false;
334       }elseif($this->dialog->isSelected()){
336         /* check if selected base is allowed to move to / create a new object */
337         $tmp = $this->get_allowed_bases();
338         if(isset($tmp[$this->dialog->isSelected()])){
339           $this->base = $this->dialog->isSelected();
340         }
341         $this->dialog= false;
342       }else{
343         return($this->dialog->execute());
344       }
345     }
347     /* Want password method editing? */
348     if ($this->acl_is_writeable("userPassword")){
349       if (isset($_POST['edit_pw_method'])){
350         if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
351           $temp= passwordMethod::get_available_methods();
352           $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
353         }
354         $this->pwObject->display = TRUE;
355         $this->dialog= TRUE;
356         return ($this->pwObject->configure());
357       }
358     }
360     /* Want picture edit dialog? */
361     if($this->acl_is_writeable("userPicture")) {
362       if (isset($_POST['edit_picture'])){
363         /* Save values for later recovery, in case some presses
364            the cancel button. */
365         $this->old_jpegPhoto= $this->jpegPhoto;
366         $this->old_photoData= $this->photoData;
367         $this->picture_dialog= TRUE;
368         $this->dialog= TRUE;
369       }
370     }
372     /* Remove picture? */
373     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))) ){
374       if (isset($_POST['picture_remove'])){
375         $this->set_picture ();
376         $this->jpegPhoto= "*removed*";
377         $this->is_modified= TRUE;
378         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
379       }
380     }
382     /* Save picture */
383     if (isset($_POST['picture_edit_finish'])){
385       /* Check for clean upload */
386       if ($_FILES['picture_file']['name'] != ""){
387         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
388           print_red(_("The specified file has not been uploaded via HTTP POST! Aborted."));
389         }else{
390           /* Activate new picture */
391           $this->set_picture($_FILES['picture_file']['tmp_name']);
392         }
393       }
394       $this->picture_dialog= FALSE;
395       $this->dialog= FALSE;
396       $this->is_modified= TRUE;
397     }
400     /* Cancel picture */
401     if (isset($_POST['picture_edit_cancel'])){
403       /* Restore values */
404       $this->jpegPhoto= $this->old_jpegPhoto;
405       $this->photoData= $this->old_photoData;
407       /* Update picture */
408       $_SESSION['binary']= $this->photoData;
409       $_SESSION['binarytype']= "image/jpeg";
410       $this->picture_dialog= FALSE;
411       $this->dialog= FALSE;
412     }
414     /* Toggle dateOfBirth information */
415     if (isset($_POST['set_dob'])){
416       $this->use_dob= ($this->use_dob == "0")?"1":"0";
417     }
420     /* Want certificate= */
421     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
423       /* Save original values for later reconstruction */
424       foreach (array("certificateSerialNumber", "userCertificate",
425             "userSMIMECertificate", "userPKCS12") as $val){
427         $oval= "old_$val";
428         $this->$oval= $this->$val;
429       }
431       $this->cert_dialog= TRUE;
432       $this->dialog= TRUE;
433     }
436     /* Cancel certificate dialog */
437     if (isset($_POST['cert_edit_cancel'])){
439       /* Restore original values in case of 'cancel' */
440       foreach (array("certificateSerialNumber", "userCertificate",
441             "userSMIMECertificate", "userPKCS12") as $val){
443         $oval= "old_$val";
444         $this->$val= $this->$oval;
445       }
446       $this->cert_dialog= FALSE;
447       $this->dialog= FALSE;
448     }
451     /* Remove certificate? */
452     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
453       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
454         if (isset($_POST["remove_$val"])){
456           /* Reset specified cert*/
457           $this->$val= "";
458           $this->is_modified= TRUE;
459         }
460       }
461     }
463     /* Upload new cert and close dialog? */     
464     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
465       if (isset($_POST['cert_edit_finish'])){
467         /* for all certificates do */
468         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
469             as $val){
471           /* Check for clean upload */
472           if (array_key_exists($val."_file", $_FILES) &&
473               array_key_exists('name', $_FILES[$val."_file"]) &&
474               $_FILES[$val."_file"]['name'] != "" &&
475               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
476             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
477           }
478         }
480         /* Save serial number */
481         if (isset($_POST["certificateSerialNumber"]) &&
482             $_POST["certificateSerialNumber"] != ""){
484           if (!is_id($_POST["certificateSerialNumber"])){
485             print_red (_("Please enter a valid serial number"));
487             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
488               if ($this->$cert != ""){
489                 $smarty->assign("$cert"."_state", "true");
490               } else {
491                 $smarty->assign("$cert"."_state", "");
492               }
493             }
494             return ($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
495           }
497           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
498           $this->is_modified= TRUE;
499         }
501         $this->cert_dialog= FALSE;
502         $this->dialog= FALSE;
503       }
504     }
505     /* Display picture dialog */
506     if ($this->picture_dialog){
507       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
508     }
510     /* Display cert dialog */
511     if ($this->cert_dialog){
512       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
513       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
515       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
516         if ($this->$cert != ""){
517           /* import certificate */
518           $certificate = new certificate;
519           $certificate->import($this->$cert);
520       
521           /* Read out data*/
522           $timeto   = $certificate->getvalidto_date();
523           $timefrom = $certificate->getvalidfrom_date();
524          
525           
526           /* Additional info if start end time is '0' */
527           $add_str_info = "";
528           if($timeto == 0 && $timefrom == 0){
529             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
530           }
532           $str = "<table summary=\"\" border=0>
533                     <tr>
534                       <td style='vertical-align:top'>CN</td>
535                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
536                     </tr>
537                   </table><br>".
539                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
540                         "<b>".date('d M Y',$timefrom)."</b>",
541                         "<b>".date('d M Y',$timeto)."</b>",
542                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
543                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
545           $smarty->assign($cert."info",$str);
546           $smarty->assign($cert."_state","true");
547         } else {
548           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
549           $smarty->assign($cert."_state","");
550         }
551       }
552       $smarty->assign("governmentmode", "false");
553       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
554     }
556     /* Prepare password hashes */
557     if ($this->pw_storage == ""){
558       $this->pw_storage= $this->config->current['HASH'];
559     }
561     $temp= passwordMethod::get_available_methods();
562     $is_configurable= FALSE;
563     $hashes = $temp['name'];
564     if($this->multiple_support_active){
565       $hashes["{default}"] = "{default}";
566     }
567     if(isset($temp[$this->pw_storage])){
568       $test= new $temp[$this->pw_storage]($this->config);
569       $is_configurable= $test->is_configurable();
570     }elseif($this->pw_storage != "{default}"){
571       new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
572     }
573     
574     /* Load attributes and acl's */
575     $ui =get_userinfo();
576     foreach($this->attributes as $val){
577       $smarty->assign("$val", $this->$val);
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     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
598     /* Save government mode attributes */
599     if (isset($this->config->current['GOVERNMENTMODE']) &&
600         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
601       $smarty->assign("governmentmode", "true");
602       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
603           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
604       $smarty->assign("ivbbmodes", $ivbbmodes);
605       foreach ($this->govattrs as $val){
606         $smarty->assign("$val", $this->$val);
607         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
608       }
609     } else {
610       $smarty->assign("governmentmode", "false");
611     }
613     /* Special mode for uid */
614     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])));
615     if (isset ($this->dn)){
616       if ($this->dn != "new"){
617         $uidACL= preg_replace("/w/","",$uidACL);
618       }
619     }  else {
620       $uidACL= preg_replace("/w/","",$uidACL);
621     }
622     
623     $smarty->assign("uidACL", $uidACL);
624     $smarty->assign("is_template", $this->is_template);
625     $smarty->assign("use_dob", $this->use_dob);
627     if (isset($this->parent)){
628       if (isset($this->parent->by_object['phoneAccount']) &&
629           $this->parent->by_object['phoneAccount']->is_account){
630         $smarty->assign("has_phoneaccount", "true");
631       } else {
632         $smarty->assign("has_phoneaccount", "false");
633       }
634     } else {
635       $smarty->assign("has_phoneaccount", "false");
636     }
637     $smarty->assign("multiple_support" , $this->multiple_support_active);
638     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
639   }
642   /* remove object from parent */
643   function remove_from_parent()
644   {
645     /* Remove password extension */
646     $temp= passwordMethod::get_available_methods();
647     $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
648     $this->pwObject->remove_from_parent();
650     /* Remove user */
651     $ldap= $this->config->get_ldap_link();
652     $ldap->rmdir ($this->dn);
653     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/generic account with dn '%s' failed."),$this->dn));
654   
655     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
656   
657     /* Delete references to groups */
658     $ldap->cd ($this->config->current['BASE']);
659     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
660     while ($ldap->fetch()){
661       $g= new group($this->config, $ldap->getDN());
662       $g->removeUser($this->uid);
663       $g->save ();
664     }
666     /* Delete references to object groups */
667     $ldap->cd ($this->config->current['BASE']);
668     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
669     while ($ldap->fetch()){
670       $og= new ogroup($this->config, $ldap->getDN());
671       unset($og->member[$this->dn]);
672       $og->save ();
673     }
675     /* If needed, let the password method do some cleanup */
676     $tmp = new passwordMethod($_SESSION['config']);
677     $available = $tmp->get_available_methods();
678     if (in_array_ics($this->pw_storage, $available['name'])){
679       $test= new $available[$this->pw_storage]($this->config);
680       $test->attrs= $this->attrs;
681       $test->dn= $this->dn;
682       $test->remove_from_parent();
683     }
685     /* Remove ACL dependencies too */
686     $tmp = new acl($this->config,$this->parent,$this->dn);
687     $tmp->remove_acl();
689     /* Optionally execute a command after we're done */
690     $this->handle_post_events("remove",array("uid" => $this->uid));
691   }
694   /* Save data to object */
695   function save_object()
696   {
697     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
699       /* Make a backup of the current selected base */
700       $base_tmp = $this->base;
702       /* Parents save function */
703       plugin::save_object ();
705       /* Save government mode attributes */
706       if ($this->config->current['GOVERNMENTMODE']){
707         foreach ($this->govattrs as $val){
708           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !isset($_SESSION['edit']))) && isset($_POST["$val"])){
709             $data= stripcslashes($_POST["$val"]);
710             if ($data != $this->$val){
711               $this->is_modified= TRUE;
712             }
713             $this->$val= $data;
714           }
715         }
716       }
718       /* In template mode, the uid is autogenerated... */
719       if ($this->is_template){
720         $this->uid= strtolower($this->sn);
721         $this->givenName= $this->sn;
722       }
724       /* Save base and pw_storage, since these are no LDAP attributes */
725       if (isset($_POST['base'])){
727         $tmp = $this->get_allowed_bases();
728         if(isset($tmp[$_POST['base']])){
729           $base= validate($_POST['base']);
730           if ($base != $this->base){
731             $this->is_modified= TRUE;
732           }
733           $this->base= $base;
734         }else{
735           $this->base = $base_tmp;
736           print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
737           $this->set_acl_base('dummy,'.$this->base);
738         }
739       }
741       /* Get pw_storage mode */
742       if (isset($_POST['pw_storage'])){
743         foreach(array("pw_storage") as $val){
744           if(isset($_POST[$val])){
745             $data= validate($_POST[$val]);
746             if ($data != $this->$val){
747               $this->is_modified= TRUE;
748             }
749             $this->$val= $data;
750           }
751         }
752       }
754       $this->set_acl_base('dummy,'.$this->base);
755     }
756   }
758   function rebind($ldap, $referral)
759   {
760     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
761     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
762       $this->error = "Success";
763       $this->hascon=true;
764       $this->reconnect= true;
765       return (0);
766     } else {
767       $this->error = "Could not bind to " . $credentials['ADMIN'];
768       return NULL;
769     }
770   }
772   
773   /* Save data to LDAP, depending on is_account we save or delete */
774   function save()
775   {
776     /* Only force save of changes .... 
777        If this attributes aren't changed, avoid saving.
778      */
779     if($this->gender=="0") $this->gender ="";
780     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
782     /* First use parents methods to do some basic fillup in $this->attrs */
783     plugin::save ();
785     if ($this->use_dob == "1"){
786       /* 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. */
787       if(!is_array($this->attrs['dateOfBirth'])) {
788         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
789       }
790     }
792     /* Remove additional objectClasses */
793     $tmp= array();
794     foreach ($this->attrs['objectClass'] as $key => $set){
795       $found= false;
796       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
797         if (preg_match ("/^$set$/i", $val)){
798           $found= true;
799           break;
800         }
801       }
802       if (!$found){
803         $tmp[]= $set;
804       }
805     }
807     /* Replace the objectClass array. This is done because of the
808        separation into government and normal mode. */
809     $this->attrs['objectClass']= $tmp;
811     /* Add objectClasss for template mode? */
812     if ($this->is_template){
813       $this->attrs['objectClass'][]= "gosaUserTemplate";
814     }
816     /* Hard coded government mode? */
817     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
818       $this->attrs['objectClass'][]= "ivbbentry";
820       /* Copy standard attributes */
821       foreach ($this->govattrs as $val){
822         if ($this->$val != ""){
823           $this->attrs["$val"]= $this->$val;
824         } elseif (!$this->is_new) {
825           $this->attrs["$val"]= array();
826         }
827       }
829       /* Remove attribute if set to "nein" */
830       if ($this->publicVisible == "nein"){
831         $this->attrs['publicVisible']= array();
832         if($this->is_new){
833           unset($this->attrs['publicVisible']);
834         }else{
835           $this->attrs['publicVisible']=array();
836         }
838       }
840     }
842     /* Special handling for attribute userCertificate needed */
843     if ($this->userCertificate != ""){
844       $this->attrs["userCertificate;binary"]= $this->userCertificate;
845       $remove_userCertificate= false;
846     } else {
847       $remove_userCertificate= true;
848     }
850     /* Special handling for dateOfBirth value */
851     if ($this->use_dob != "1"){
852       if ($this->is_new) {
853         unset($this->attrs["dateOfBirth"]);
854       } else {
855         $this->attrs["dateOfBirth"]= array();
856       }
857     }
858     if (!$this->gender){
859       if ($this->is_new) {
860         unset($this->attrs["gender"]);
861       } else {
862         $this->attrs["gender"]= array();
863       }
864     }
865     if (!$this->preferredLanguage){
866       if ($this->is_new) {
867         unset($this->attrs["preferredLanguage"]);
868       } else {
869         $this->attrs["preferredLanguage"]= array();
870       }
871     }
873     /* Special handling for attribute jpegPhote needed, scale image via
874        image magick to 147x200 pixels and inject resulting data. */
875     if ($this->jpegPhoto == "*removed*"){
876     
877       /* Reset attribute to avoid writing *removed* as value */    
878       $this->attrs["jpegPhoto"] = array();
880     } else {
882       /* Fallback if there's no image magick inside PHP */
883       if (!function_exists("imagick_blob2image")){
884         /* Get temporary file name for conversation */
885         $fname = tempnam ("/tmp", "GOsa");
886   
887         /* Open file and write out photoData */
888         $fp = fopen ($fname, "w");
889         fwrite ($fp, $this->photoData);
890         fclose ($fp);
892         /* Build conversation query. Filename is generated automatically, so
893            we do not need any special security checks. Exec command and save
894            output. For PHP safe mode, you'll need a configuration which respects
895            image magick as executable... */
896         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
897         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
898             $query, "Execute");
899   
900         /* Read data written by convert */
901         $output= "";
902         $sh= popen($query, 'r');
903         while (!feof($sh)){
904           $output.= fread($sh, 4096);
905         }
906         pclose($sh);
908         unlink($fname);
910         /* Save attribute */
911         $this->attrs["jpegPhoto"] = $output;
913       } else {
915         /* Load the new uploaded Photo */
916         if(!$handle  =  imagick_blob2image($this->photoData))  {
917           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
918         }
920         /* Resizing image to 147x200 and blur */
921         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
922           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
923         }
925         /* Converting image to JPEG */
926         if(!imagick_convert($handle,"JPEG")) {
927           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
928         }
930         /* Creating binary Code for the Image */
931         if(!$dump = imagick_image2blob($handle)){
932           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
933         }
935         /* Sending Image */
936         $output=  $dump;
938         /* Save attribute */
939         $this->attrs["jpegPhoto"] = $output;
940       }
942     }
944     /* This only gets called when user is renaming himself */
945     $ldap= $this->config->get_ldap_link();
946     if ($this->dn != $this->new_dn){
948       /* Write entry on new 'dn' */
949       $this->update_acls($this->dn,$this->new_dn);
950       $this->move($this->dn, $this->new_dn);
952       /* Happen to use the new one */
953       change_ui_dn($this->dn, $this->new_dn);
954       $this->dn= $this->new_dn;
955     }
958     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
959        new entries. So do a check first... */
960     $ldap->cat ($this->dn, array('dn'));
961     if ($ldap->fetch()){
962       $mode= "modify";
963     } else {
964       $mode= "add";
965       $ldap->cd($this->config->current['BASE']);
966       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
967     }
969     /* Set password to some junk stuff in case of templates */
970     if ($this->is_template){
971       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
972     }
974     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
975         $this->attributes, "Save via $mode");
977     /* Finally write data with selected 'mode' */
978     $this->cleanup();
980     if(isset($this->attrs['preferredLanguage'])){
981       $_SESSION['ui']->language = $this->preferredLanguage;
982       $_SESSION['Last_init_lang'] = "update";
983     }
985     $ldap->cd ($this->dn);
986     $ldap->$mode ($this->attrs);
987     if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){
988       return (1);
989     }
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   }
1065   /* Check formular input */
1066   function check()
1067   {
1068     /* Call common method to give check the hook */
1069     $message= plugin::check();
1071     $pt= "";
1072     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1073       if(!empty($this->personalTitle)){
1074         $pt = $this->personalTitle." ";
1075       }
1076     }
1077     $this->cn= $pt.$this->givenName." ".$this->sn;
1079     /* Permissions for that base? */
1080     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1081       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1082     } else {
1083       /* Don't touch dn, if cn hasn't changed */
1084       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1085           $this->orig_base == $this->base ){
1086         $this->new_dn= $this->dn;
1087       } else {
1088         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1089       }
1090     }
1092     /* Set the new acl base */
1093     if($this->dn == "new") {
1094       $this->set_acl_base($this->base);
1095     }
1097     /* UID already used? */
1098     $ldap= $this->config->get_ldap_link();
1099     $ldap->cd($this->config->current['BASE']);
1100     $ldap->search("(uid=$this->uid)", array("uid"));
1101     $ldap->fetch();
1102     if ($ldap->count() != 0 && $this->dn == 'new'){
1103       $message[]= _("There's already a person with this 'Login' in the database.");
1104     }
1106     /* In template mode, the uid and givenName are autogenerated... */
1107     if (!$this->is_template){
1108       if ($this->sn == ""){
1109         $message[]= _("The required field 'Name' is not set.");
1110       }
1111       if ($this->givenName == ""){
1112         $message[]= _("The required field 'Given name' is not set.");
1113       }
1114       if ($this->uid == ""){
1115         $message[]= _("The required field 'Login' is not set.");
1116       }
1117       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1118         $ldap->cat($this->new_dn);
1119         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1120           $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
1121         }
1122       }
1123     }
1125     /* Check for valid input */
1126     if ($this->is_modified && !is_uid($this->uid)){
1127       $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
1128     }
1129     if (!is_url($this->labeledURI)){
1130       $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1131     }
1132     if (preg_match ("/[\\\\]/", $this->sn)){
1133       $message[]= _("The field 'Name' contains invalid characters.");
1134     }
1135     if (preg_match ("/[\\\\]/", $this->givenName)){
1136       $message[]= _("The field 'Given name' contains invalid characters.");
1137     }
1139     /* Check phone numbers */
1140     if (!is_phone_nr($this->telephoneNumber)){
1141       $message[]= _("The field 'Phone' contains an invalid phone number.");
1142     }
1143     if (!is_phone_nr($this->facsimileTelephoneNumber)){
1144       $message[]= _("The field 'Fax' contains an invalid phone number.");
1145     }
1146     if (!is_phone_nr($this->mobile)){
1147       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1148     }
1149     if (!is_phone_nr($this->pager)){
1150       $message[]= _("The field 'Pager' contains an invalid phone number.");
1151     }
1153     /* Check for reserved characers */
1154     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
1155       $message[]= _("The field 'Given name' contains invalid characters.");
1156   }
1157   if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
1158     $message[]= _("The field 'Name' contains invalid characters.");
1159   }
1161   return $message;
1162   }
1165   /* Indicate whether a password change is needed or not */
1166   function password_change_needed()
1167   {
1168     if($this->pw_storage == "{default}"){
1169       return(FALSE);
1170     }
1171     return($this->pw_storage != $this->last_pw_storage);
1172   }
1175   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1176   function load_picture()
1177   {
1178     $ldap = $this->config->get_ldap_link();
1179     $ldap->cd ($this->dn);
1180     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1182     if((!$data) || ($data == "*removed*")){ 
1184       /* In case we don't get an entry, load a default picture */
1185       $this->set_picture ();//"./images/default.jpg");
1186       $this->jpegPhoto= "*removed*";
1187     }else{
1189       /* Set picture */
1190       $this->photoData= $data;
1191       $_SESSION['binary']= $this->photoData;
1192       $_SESSION['binarytype']= "image/jpeg";
1193       $this->jpegPhoto= "";
1194     }
1195   }
1198   /* Load a certificate from LDAP, this is going to be simplified later on */
1199   function load_cert()
1200   {
1201     $ds= ldap_connect($this->config->current['SERVER']);
1202     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1203     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1204       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1205       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1206     }
1207     if(isset($this->config->current['TLS']) &&
1208         $this->config->current['TLS'] == "true"){
1210       ldap_start_tls($ds);
1211     }
1213     $r= ldap_bind($ds);
1214     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1216     if ($sr) {
1217       $ei= @ldap_first_entry($ds, $sr);
1218       
1219       if ($ei) {
1220         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1221           $this->userCertificate= "";
1222         } else {
1223           $this->userCertificate= $info[0];
1224         }
1225       }
1226     } else {
1227       $this->userCertificate= "";
1228     }
1230     ldap_unbind($ds);
1231   }
1234   /* Load picture from file to object */
1235   function set_picture($filename ="")
1236   {
1237     if (!is_file($filename) || $filename =="" ){
1238       $filename= "./images/default.jpg";
1239       $this->jpegPhoto= "*removed*";
1240     }
1242     $fd = fopen ($filename, "rb");
1243     $this->photoData= fread ($fd, filesize ($filename));
1244     $_SESSION['binary']= $this->photoData;
1245     $_SESSION['binarytype']= "image/jpeg";
1246     $this->jpegPhoto= "";
1248     fclose ($fd);
1249   }
1252   /* Load certificate from file to object */
1253   function set_cert($cert, $filename)
1254   {
1255     if(!$thsi->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))) return;
1256     $fd = fopen ($filename, "rb");
1257     if (filesize($filename)>0) {
1258       $this->$cert= fread ($fd, filesize ($filename));
1259       fclose ($fd);
1260       $this->is_modified= TRUE;
1261     } else {
1262       print_red(_("Could not open specified certificate!"));
1263     }
1264   }
1266   /* Adapt from given 'dn' */
1267   function adapt_from_template($dn)
1268   {
1269     plugin::adapt_from_template($dn);
1271     /* Get base */
1272     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1274     if ($this->config->current['GOVERNMENTMODE']){
1276       /* Walk through govattrs */
1277       foreach ($this->govattrs as $val){
1279         if (isset($this->attrs["$val"][0])){
1281           /* If attribute is set, replace dynamic parts: 
1282              %sn, %givenName and %uid. Fill these in our local variables. */
1283           $value= $this->attrs["$val"][0];
1285           foreach (array("sn", "givenName", "uid") as $repl){
1286             if (preg_match("/%$repl/i", $value)){
1287               $value= preg_replace ("/%$repl/i",
1288                   $this->parent->$repl, $value);
1289             }
1290           }
1291           $this->$val= $value;
1292         }
1293       }
1294     }
1296     /* Get back uid/sn/givenName */
1297     if ($this->parent !== NULL){
1298       $this->uid= $this->parent->uid;
1299       $this->sn= $this->parent->sn;
1300       $this->givenName= $this->parent->givenName;
1301     }
1302   }
1304  
1305   /* This avoids that users move themselves out of their rights. 
1306    */
1307   function allowedBasesToMoveTo()
1308   {
1309     /* Get bases */
1310     $bases  = $this->get_allowed_bases();
1311     return($bases);
1312   } 
1315   function getCopyDialog()
1316   {
1317     $str = "";
1319     $_SESSION['binary'] = $this->photoData; 
1320     $_SESSION['binarytype']= "image/jpeg";
1322     /* Get random number for pictures */
1323     srand((double)microtime()*1000000); 
1324     $rand = rand(0, 10000);
1326     $smarty = get_smarty();
1328     $smarty->assign("passwordTodo","clear");
1330     if(isset($_POST['passwordTodo'])){
1331       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1332     }
1334     $smarty->assign("sn",       $this->sn);
1335     $smarty->assign("givenName",$this->givenName);
1336     $smarty->assign("uid",      $this->uid);
1337     $smarty->assign("rand",     $rand);
1338     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1341     $ret = array();
1342     $ret['string'] = $str;
1343     $ret['status'] = "";  
1344     return($ret);
1345   }
1347   function saveCopyDialog()
1348   {
1349     /* Set_acl_base */
1350     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1352     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1353       $this->set_picture($_FILES['picture_file']['tmp_name']);
1354     }
1356     /* Remove picture? */
1357     if (isset($_POST['picture_remove'])){
1358       $this->jpegPhoto= "*removed*";
1359       $this->set_picture ("./images/default.jpg");
1360       $this->is_modified= TRUE;
1361     }
1363     $attrs = array("uid","givenName","sn");
1364     foreach($attrs as $attr){
1365       if(isset($_POST[$attr])){
1366         $this->$attr = $_POST[$attr];
1367       }
1368     } 
1369   }
1372   function PrepareForCopyPaste($source)
1373   {
1374     plugin::PrepareForCopyPaste($source);
1376     /* Reset certificate information addepted from source user
1377        to avoid setting the same user certificate for the destination user. */
1378     $this->userPKCS12= "";
1379     $this->userSMIMECertificate= "";
1380     $this->userCertificate= "";
1381     $this->certificateSerialNumber= "";
1382     $this->old_certificateSerialNumber= "";
1383     $this->old_userPKCS12= "";
1384     $this->old_userSMIMECertificate= "";
1385     $this->old_userCertificate= "";
1386   }
1389   static function plInfo()
1390   {
1391   
1392     $govattrs= array(
1393         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1394         "houseIdentifier"                           =>  _("House identifier"), 
1395         "vocation"                                  =>  _("Vocation"),
1396         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1397         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1398         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1399         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1400         "functionalTitle"                           =>  _("Functional title"),
1401         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1402         "publicVisible"                             =>  _("Public visible"),
1403         "street"                                    =>  _("Street"),
1404         "role"                                      =>  _("Role"),
1405         "postalCode"                                =>  _("Postal code"));
1407     $ret = array(
1408         "plShortName" => _("Generic"),
1409         "plDescription" => _("Generic user settings"),
1410         "plSelfModify"  => TRUE,
1411         "plDepends"     => array(),
1412         "plPriority"    => 1,
1413         "plSection"     => array("personal" => _("My account")),
1414         "plCategory"    => array("users" => array("description" => _("Users"),
1415                                                   "objectClass" => "gosaAccount")),
1417         "plProvidedAcls" => array(
1418           "base"              => _("Base"), 
1419           "userPassword"      => _("User password"), 
1420           "sn"                => _("Surename"),
1421           "givenName"         => _("Given name"),
1422           "uid"               => _("User identification"),
1423           "personalTitle"     => _("Personal title"),
1424           "academicTitle"     => _("Academic title"),
1425           "homePostalAddress" => _("Home postal address"),
1426           "homePhone"         => _("Home phone number"),
1427           "labeledURI"        => _("Homepage"),
1428           "o"                 => _("Organization"),
1429           "ou"                => _("Department"),
1430           "dateOfBirth"       => _("Date of birth"),
1431           "gender"            => _("Gender"),
1432           "preferredLanguage" => _("Preferred language"),
1433           "departmentNumber"  => _("Department number"),
1434           "employeeNumber"    => _("Employee number"),
1435           "employeeType"      => _("Employee type"),
1436           "l"                 => _("Location"),
1437           "st"                => _("State"),
1438           "userPicture"       => _("User picture"),
1439           "roomNumber"        => _("Room number"),
1440           "telephoneNumber"   => _("Telefon number"),
1441           "mobile"            => _("Mobile number"),
1442           "pager"             => _("Pager number"),
1443           "Certificate"        => _("User certificates"),
1445           "postalAddress"                => _("Postal address"),
1446           "facsimileTelephoneNumber"     => _("Fax number"))
1447         );
1449     /* Append government attributes if required */
1450       global $config;
1451     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1452       foreach($govattrs as $attr => $desc){
1453         $ret["plProvidedAcls"][$attr] = $desc;
1454       }
1455     }
1456     return($ret);
1457   }
1460   function init_multiple_support()
1461   {
1462     plugin::init_multiple_support();
1463     $this->pw_storage = "{default}";
1464   }
1467   function get_multi_edit_values()
1468   {
1469     $ret = plugin::get_multi_edit_values();
1470     if($this->pw_storage != "{default}"){
1471       $ret['pw_storage'] = $this->pw_storage;
1472     }
1473     if($this->jpegPhoto != "{default}"){
1474       $ret['jpegPhoto'] = $this->jpegPhoto;
1475       $ret['photoData'] = $this->photoData;
1476       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1477       $ret['old_photoData'] = $this->old_photoData;
1478     }
1479     if(isset($ret['dateOfBirth'])){
1480       unset($ret['dateOfBirth']);
1481     }
1482     if(isset($ret['cn'])){
1483       unset($ret['cn']);
1484     }
1485     $ret['is_modified'] = $this->is_modified;
1486     $ret['base']=$this->base;
1487    
1488     print_a($ret); 
1489     return($ret); 
1490   }
1493   function multiple_save_object()
1494   {
1495     plugin::multiple_save_object();
1497     /* Get pw_storage mode */
1498     if (isset($_POST['pw_storage'])){
1499       foreach(array("pw_storage") as $val){
1500         if(isset($_POST[$val])){
1501           $data= validate(get_post($val));
1502           if ($data != $this->$val){
1503             $this->is_modified= TRUE;
1504           }
1505           $this->$val= $data;
1506         }
1507       }
1508     }
1509     if(isset($_POST['base'])){
1510       $this->base = get_post('base');
1511     }
1512   }
1514   
1515   function multiple_check()
1516   {
1517     /* Call check() to set new_dn correctly ... */
1518     $message = plugin::multiple_check();
1522     $pt= "";
1523     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1524       if(!empty($this->personalTitle)){
1525         $pt = $this->personalTitle." ";
1526       }
1527     }
1528     $this->cn= $pt.$this->givenName." ".$this->sn;
1530     /* Permissions for that base? */
1531     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1532       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1533     } else {
1534       if($this->orig_base == $this->base ){
1535         $this->new_dn= $this->dn;
1536       } else {
1537         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1538       }
1539     }
1541     /* Set the new acl base */
1542     if($this->dn == "new") {
1543       $this->set_acl_base($this->base);
1544     }
1545     if ($this->sn == ""){
1546       $message[]= _("The required field 'Name' is not set.");
1547     }
1548     if ($this->givenName == ""){
1549       $message[]= _("The required field 'Given name' is not set.");
1550     }
1551     if (!is_url($this->labeledURI) && $this->labeledURI != "{default}"){
1552       $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1553     }
1554     if (preg_match ("/[\\\\]/", $this->sn) && $this->sn != "{default}"){
1555       $message[]= _("The field 'Name' contains invalid characters.");
1556     }
1557     if (preg_match ("/[\\\\]/", $this->givenName) && $this->givenName != "{default}"){
1558       $message[]= _("The field 'Given name' contains invalid characters.");
1559     }
1560     if (!is_phone_nr($this->telephoneNumber) && $this->telephoneNumber != "{default}"){
1561       $message[]= _("The field 'Phone' contains an invalid phone number.");
1562     }
1563     if (!is_phone_nr($this->facsimileTelephoneNumber) && $this->facsimileTelephoneNumber != "{default}"){
1564       $message[]= _("The field 'Fax' contains an invalid phone number.");
1565     }
1566     if (!is_phone_nr($this->mobile) && $this->mobile != "{default}"){
1567       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1568     }
1569     if (!is_phone_nr($this->pager) && $this->pager != "{default}"){
1570       $message[]= _("The field 'Pager' contains an invalid phone number.");
1571     }
1572     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName) && $this->givenName != "{default}"){
1573       $message[]= _("The field 'Given name' contains invalid characters.");
1574     }
1575     if (preg_match ('/[,+"?\'()=<>;]/', $this->sn) && $this->sn != "{default}"){
1576       $message[]= _("The field 'Name' contains invalid characters.");
1577     }
1578     return($message);
1579   }
1583   function multiple_execute()
1584   {
1585     return($this->execute());
1586   }
1591 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1592 ?>