Code

Updated locale handling if a user gets saved Closes #525
[gosa.git] / gosa-core / plugins / personal / generic / class_user.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 /*!
24   \brief   user plugin
25   \author  Cajus Pollmeier <pollmeier@gonicus.de>
26   \version 2.00
27   \date    24.07.2003
29   This class provides the functionality to read and write all attributes
30   relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
31   from/to the LDAP. It does syntax checking and displays the formulars required.
32  */
34 class user extends plugin
35 {
36   /* Definitions */
37   var $plHeadline= "Generic";
38   var $plDescription= "Edit organizational user settings";
40   /* Plugin specific values */
41   var $base= "";
42   var $orig_base= "";
43   var $cn= "";
44   var $new_dn= "";
45   var $personalTitle= "";
46   var $academicTitle= "";
47   var $homePostalAddress= "";
48   var $homePhone= "";
49   var $labeledURI= "";
50   var $o= "";
51   var $ou= "";
52   var $departmentNumber= "";
53   var $employeeNumber= "";
54   var $employeeType= "";
55   var $roomNumber= "";
56   var $telephoneNumber= "";
57   var $facsimileTelephoneNumber= "";
58   var $mobile= "";
59   var $pager= "";
60   var $l= "";
61   var $st= "";
62   var $postalAddress= "";
63   var $dateOfBirth;
64   var $use_dob= "0";
65   var $gender="0";
66   var $preferredLanguage="0";
68   var $jpegPhoto= "*removed*";
69   var $photoData= "";
70   var $old_jpegPhoto= "";
71   var $old_photoData= "";
72   var $cert_dialog= FALSE;
73   var $picture_dialog= FALSE;
74   var $pwObject= NULL;
76   var $userPKCS12= "";
77   var $userSMIMECertificate= "";
78   var $userCertificate= "";
79   var $certificateSerialNumber= "";
80   var $old_certificateSerialNumber= "";
81   var $old_userPKCS12= "";
82   var $old_userSMIMECertificate= "";
83   var $old_userCertificate= "";
85   var $gouvernmentOrganizationalUnit= "";
86   var $houseIdentifier= "";
87   var $street= "";
88   var $postalCode= "";
89   var $vocation= "";
90   var $ivbbLastDeliveryCollective= "";
91   var $gouvernmentOrganizationalPersonLocality= "";
92   var $gouvernmentOrganizationalUnitDescription= "";
93   var $gouvernmentOrganizationalUnitSubjectArea= "";
94   var $functionalTitle= "";
95   var $role= "";
96   var $publicVisible= "";
98   var $orig_dn;
99   var $dialog;
101   /* variables to trigger password changes */
102   var $pw_storage= "md5";
103   var $last_pw_storage= "unset";
104   var $had_userCertificate= FALSE;
106   var $view_logged = FALSE;
108   /* attribute list for save action */
109   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
110       "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
111       "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
112       "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
113       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
115   var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
116       "gosaAccount");
118   /* attributes that are part of the government mode */
119   var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
120       "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
121       "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
122       "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
123       "postalCode");
125   var $multiple_support = TRUE;
127   var $governmentmode = FALSE;
129   /* constructor, if 'dn' is set, the node loads the given
130      'dn' from LDAP */
131   function user (&$config, $dn= NULL)
132   {
133     $this->config= $config;
134     /* Configuration is fine, allways */
135     if($this->config->get_cfg_value("governmentmode") == "true"){
136       $this->governmentmode = TRUE;
137       $this->attributes=array_merge($this->attributes,$this->govattrs);
138     }
140     /* Load base attributes */
141     plugin::plugin ($config, $dn);
143     $this->orig_dn  = $this->dn;
144     $this->new_dn   = $dn;
146     if ($this->governmentmode){
147       /* Fix public visible attribute if unset */
148       if (!isset($this->attrs['publicVisible'])){
149         $this->publicVisible == "nein";
150       }
151     }
153     /* Load government mode attributes */
154     if ($this->governmentmode){
155       /* Copy all attributs */
156       foreach ($this->govattrs as $val){
157         if (isset($this->attrs["$val"][0])){
158           $this->$val= $this->attrs["$val"][0];
159         }
160       }
161     }
163     /* Create me for new accounts */
164     if ($dn == "new"){
165       $this->is_account= TRUE;
166     }
168     /* Make hash default to md5 if not set in config */
169     $hash= $this->config->get_cfg_value("hash", "crypt/md5");
171     /* Load data from LDAP? */
172     if ($dn !== NULL){
174       /* Do base conversation */
175       if ($this->dn == "new"){
176         $ui= get_userinfo();
177         $this->base= dn2base($ui->dn);
178       } else {
179         $this->base= dn2base($dn);
180       }
182       /* get password storage type */
183       if (isset ($this->attrs['userPassword'][0])){
184         /* Initialize local array */
185         $matches= array();
186         if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
187           $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
188           if(is_object($tmp)){
189             $this->pw_storage= $tmp->get_hash(); 
190           }
192         } else {
193           if ($this->attrs['userPassword'][0] != ""){
194             $this->pw_storage= "clear";
195           } else {
196             $this->pw_storage= $hash;
197           }
198         }
199       } else {
200         /* Preset with vaule from configuration */
201         $this->pw_storage= $hash;
202       }
204       /* Load extra attributes: certificate and picture */
205       $this->load_cert();
206       $this->load_picture();
207       if ($this->userCertificate != ""){
208         $this->had_userCertificate= TRUE;
209       }
210     }
212     /* Reset password storage indicator, used by password_change_needed() */
213     if ($dn == "new"){
214       $this->last_pw_storage= "unset";
215     } else {
216       $this->last_pw_storage= $this->pw_storage;
217     }
219     /* Generate dateOfBirth entry */
220     if (isset ($this->attrs['dateOfBirth'])){
221       /* This entry is ISO 8601 conform */
222       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
223     
224       $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
225       $this->use_dob= "1";
226     } else {
227       $this->use_dob= "0";
228     }
230     /* Put gender attribute to upper case */
231     if (isset ($this->attrs['gender'])){
232       $this->gender= strtoupper($this->attrs['gender'][0]);
233     }
234  
235     $this->orig_base = $this->base;
236   }
241   /* execute generates the html output for this node */
242   function execute()
243   {
244     /* Call parent execute */
245     plugin::execute();
247     /* Log view */
248     if($this->is_account && !$this->view_logged){
249       $this->view_logged = TRUE;
250       new log("view","users/".get_class($this),$this->dn);
251     }
253     $smarty= get_smarty();
255     /* Fill calendar */
256     if ($this->dateOfBirth == "0"){
257       $date= getdate();
258     } else {
259       if(is_array($this->dateOfBirth)){
260         $date = $this->dateOfBirth;
261   
262         // Trigger on dates like 1985-04-01, getdate only understands timestamps
263       } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
264         $date= getdate(strtotime($this->dateOfBirth));
266       } else {
267         $date = getdate($this->dateOfBirth);
268       }
269     }
271     $days= array();
272     for($d= 1; $d<32; $d++){
273       $days[$d]= $d;
274     }
275     $years= array();
277     if(($date['year']-100)<1901){
278       $start = 1901;
279     }else{
280       $start = $date['year']-100;
281     }
283     $end = $start +100;
284     
285     for($y= $start; $y<=$end; $y++){
286       $years[]= $y;
287     }
288     $years['-']= "-&nbsp;";
289     $months= msgPool::months();
290     $months['-'] = '-&nbsp;';
292     $smarty->assign("day", $date["mday"]);
293     $smarty->assign("days", $days);
294     $smarty->assign("months", $months);
295     $smarty->assign("month", $date["mon"]-1);
296     $smarty->assign("years", $years);
297     $smarty->assign("year", $date["year"]);
299     /* Assign sex */
300     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
301     $smarty->assign("gender_list", $sex);
302     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
303     $smarty->assign("preferredLanguage_list", $language);
305     /* Get random number for pictures */
306     srand((double)microtime()*1000000); 
307     $smarty->assign("rand", rand(0, 10000));
310     /* Do we represent a valid gosaAccount? */
311     if (!$this->is_account){
312       $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
313         msgPool::noValidExtension("GOsa")."</b>";
314       return($str);
315     }
317     /* Base select dialog */
318     $once = true;
319     foreach($_POST as $name => $value){
320       if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
321         $once = false;
322         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
323         $this->dialog->setCurrentBase($this->base);
324       }
325     }
327     /* Password configure dialog handling */
328     if(is_object($this->pwObject) && $this->pwObject->display){
329       $output= $this->pwObject->configure();
330       if ($output != ""){
331         $this->dialog= TRUE;
332         return $output;
333       }
334       $this->dialog= false;
335     }
337     /* Dialog handling */
338     if(is_object($this->dialog)){
339       /* Must be called before save_object */
340       $this->dialog->save_object();
341    
342       if($this->dialog->isClosed()){
343         $this->dialog = false;
344       }elseif($this->dialog->isSelected()){
346         /* check if selected base is allowed to move to / create a new object */
347         $tmp = $this->get_allowed_bases();
348         if(isset($tmp[$this->dialog->isSelected()])){
349           $this->base = $this->dialog->isSelected();
350         }
351         $this->dialog= false;
352       }else{
353         return($this->dialog->execute());
354       }
355     }
357     /* Want password method editing? */
358     if ($this->acl_is_writeable("userPassword")){
359       if (isset($_POST['edit_pw_method'])){
360         if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
361           $temp= passwordMethod::get_available_methods();
362           $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
363         }
364         $this->pwObject->display = TRUE;
365         $this->dialog= TRUE;
366         return ($this->pwObject->configure());
367       }
368     }
370     /* Want picture edit dialog? */
371     if($this->acl_is_writeable("userPicture")) {
372       if (isset($_POST['edit_picture'])){
373         /* Save values for later recovery, in case some presses
374            the cancel button. */
375         $this->old_jpegPhoto= $this->jpegPhoto;
376         $this->old_photoData= $this->photoData;
377         $this->picture_dialog= TRUE;
378         $this->dialog= TRUE;
379       }
380     }
382     /* Remove picture? */
383     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
384       if (isset($_POST['picture_remove'])){
385         $this->set_picture ();
386         $this->jpegPhoto= "*removed*";
387         $this->is_modified= TRUE;
388         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
389       }
390     }
392     /* Save picture */
393     if (isset($_POST['picture_edit_finish'])){
395       /* Check for clean upload */
396       if ($_FILES['picture_file']['name'] != ""){
397         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
398           msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
399         }else{
400           /* Activate new picture */
401           $this->set_picture($_FILES['picture_file']['tmp_name']);
402         }
403       }
404       $this->picture_dialog= FALSE;
405       $this->dialog= FALSE;
406       $this->is_modified= TRUE;
407     }
410     /* Cancel picture */
411     if (isset($_POST['picture_edit_cancel'])){
413       /* Restore values */
414       $this->jpegPhoto= $this->old_jpegPhoto;
415       $this->photoData= $this->old_photoData;
417       /* Update picture */
418       session::set('binary',$this->photoData);
419       session::set('binarytype',"image/jpeg");
420       $this->picture_dialog= FALSE;
421       $this->dialog= FALSE;
422     }
424     /* Toggle dateOfBirth information */
425     if (isset($_POST['set_dob'])){
426       $this->use_dob= ($this->use_dob == "0")?"1":"0";
427     }
430     /* Want certificate= */
431     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
433       /* Save original values for later reconstruction */
434       foreach (array("certificateSerialNumber", "userCertificate",
435             "userSMIMECertificate", "userPKCS12") as $val){
437         $oval= "old_$val";
438         $this->$oval= $this->$val;
439       }
441       $this->cert_dialog= TRUE;
442       $this->dialog= TRUE;
443     }
446     /* Cancel certificate dialog */
447     if (isset($_POST['cert_edit_cancel'])){
449       /* Restore original values in case of 'cancel' */
450       foreach (array("certificateSerialNumber", "userCertificate",
451             "userSMIMECertificate", "userPKCS12") as $val){
453         $oval= "old_$val";
454         $this->$val= $this->$oval;
455       }
456       $this->cert_dialog= FALSE;
457       $this->dialog= FALSE;
458     }
461     /* Remove certificate? */
462     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){ 
463       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
464         if (isset($_POST["remove_$val"])){
466           /* Reset specified cert*/
467           $this->$val= "";
468           $this->is_modified= TRUE;
469         }
470       }
471     }
473     /* Upload new cert and close dialog? */     
474     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){ 
476       $fail =false;
478       if (isset($_POST['cert_edit_finish'])){
480         /* for all certificates do */
481         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
482             as $val){
484           /* Check for clean upload */
485           if (array_key_exists($val."_file", $_FILES) &&
486               array_key_exists('name', $_FILES[$val."_file"]) &&
487               $_FILES[$val."_file"]['name'] != "" &&
488               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
489             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
490           }
491         }
493         /* Save serial number */
494         if (isset($_POST["certificateSerialNumber"]) &&
495             $_POST["certificateSerialNumber"] != ""){
497           if (!tests::is_id($_POST["certificateSerialNumber"])){
498             $fail = true;
499             msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
501             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
502               if ($this->$cert != ""){
503                 $smarty->assign("$cert"."_state", "true");
504               } else {
505                 $smarty->assign("$cert"."_state", "");
506               }
507             }
508           }
510           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
511           $this->is_modified= TRUE;
512         }
513         if(!$fail){
514           $this->cert_dialog= FALSE;
515           $this->dialog= FALSE;
516         }
517       }
518     }
519     /* Display picture dialog */
520     if ($this->picture_dialog){
521       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
522     }
524     /* Display cert dialog */
525     if ($this->cert_dialog){
526       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
527       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
528       $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
530       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
531         if ($this->$cert != ""){
532           /* import certificate */
533           $certificate = new certificate;
534           $certificate->import($this->$cert);
535       
536           /* Read out data*/
537           $timeto   = $certificate->getvalidto_date();
538           $timefrom = $certificate->getvalidfrom_date();
539          
540           
541           /* Additional info if start end time is '0' */
542           $add_str_info = "";
543           if($timeto == 0 && $timefrom == 0){
544             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
545           }
547           $str = "<table summary=\"\" border=0>
548                     <tr>
549                       <td style='vertical-align:top'>CN</td>
550                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
551                     </tr>
552                   </table><br>".
554                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
555                         "<b>".date('d M Y',$timefrom)."</b>",
556                         "<b>".date('d M Y',$timeto)."</b>",
557                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
558                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
560           $smarty->assign($cert."info",$str);
561           $smarty->assign($cert."_state","true");
562         } else {
563           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
564           $smarty->assign($cert."_state","");
565         }
566       }
567   
568       if($this->governmentmode){
569         $smarty->assign("governmentmode", "true");
570       }else{
571         $smarty->assign("governmentmode", "false");
572       }
573       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
574     }
576     /* Prepare password hashes */
577     if ($this->pw_storage == ""){
578       $this->pw_storage= $this->config->get_cfg_value("hash");
579     }
581     $temp= passwordMethod::get_available_methods();
582     $is_configurable= FALSE;
583     $hashes = $temp['name'];
584     if(isset($temp[$this->pw_storage])){
585       $test= new $temp[$this->pw_storage]($this->config);
586       $is_configurable= $test->is_configurable();
587     }else{
588       new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
589     }
592     /* Create password methods array */
593     $pwd_methods = array();
594     foreach($hashes as $id => $name){
595       if(!empty($temp['desc'][$id])){
596         $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
597       }else{
598         $pwd_methods[$name] = $name;
599       }
600     }
601  
602     /* Load attributes and acl's */
603     $ui =get_userinfo();
604     foreach($this->attributes as $val){
605       $smarty->assign("$val", $this->$val);
606       if(in_array($val,$this->multi_boxes)){
607         $smarty->assign("use_".$val,TRUE);
608       }else{
609         $smarty->assign("use_".$val,FALSE);
610       }
611     }
612     foreach(array("base","pw_storage","edit_picture") as $val){
613       if(in_array($val,$this->multi_boxes)){
614         $smarty->assign("use_".$val,TRUE);
615       }else{
616         $smarty->assign("use_".$val,FALSE);
617       }
618     }
620     /* Set acls */
621     $tmp = $this->plinfo();
622     foreach($tmp['plProvidedAcls'] as $val => $translation){
623       $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
624     }
626     $smarty->assign("pwmode", $pwd_methods);
627     $smarty->assign("pwmode_select", $this->pw_storage);
628     $smarty->assign("pw_configurable", $is_configurable);
629     $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
630     $smarty->assign("base_select",      $this->base);
632     if(!session::is_set('edit')){
633       $smarty->assign("CertificatesACL","");
634     }else{
635       $smarty->assign("CertificatesACL",  $this->getacl("Certificate"));
636     }
637     
638     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
639     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
641     /* Create base acls */
642     $tmp = @$this->allowedBasesToMoveTo();
643     $smarty->assign("bases", $tmp);
645     /* Save government mode attributes */
646     if($this->governmentmode){
647       $smarty->assign("governmentmode", "true");
648       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
649           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
650       $smarty->assign("ivbbmodes", $ivbbmodes);
651       foreach ($this->govattrs as $val){
652         $smarty->assign("$val", $this->$val);
653         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
654       }
655     } else {
656       $smarty->assign("governmentmode", "false");
657     }
659     /* Special mode for uid */
660     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
661     if (isset ($this->dn)){
662       if ($this->dn != "new"){
663         $uidACL= preg_replace("/w/","",$uidACL);
664       }
665     }  else {
666       $uidACL= preg_replace("/w/","",$uidACL);
667     }
668     
669     $smarty->assign("uidACL", $uidACL);
670     $smarty->assign("is_template", $this->is_template);
671     $smarty->assign("use_dob", $this->use_dob);
673     if (isset($this->parent)){
674       if (isset($this->parent->by_object['phoneAccount']) &&
675           $this->parent->by_object['phoneAccount']->is_account){
676         $smarty->assign("has_phoneaccount", "true");
677       } else {
678         $smarty->assign("has_phoneaccount", "false");
679       }
680     } else {
681       $smarty->assign("has_phoneaccount", "false");
682     }
683     $smarty->assign("multiple_support" , $this->multiple_support_active);
684     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
685   }
688   /* remove object from parent */
689   function remove_from_parent()
690   {
691     /* Remove password extension */
692     $temp= passwordMethod::get_available_methods();
694     /* Remove password method from user account */
695     if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
696       $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
697       $this->pwObject->remove_from_parent();
698     }
700     /* Remove user */
701     $ldap= $this->config->get_ldap_link();
702     $ldap->rmdir ($this->dn);
703     if (!$ldap->success()){
704       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
705     }
706   
707     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
708   
709     /* Delete references to groups */
710     $ldap->cd ($this->config->current['BASE']);
711     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
712     while ($ldap->fetch()){
713       $g= new group($this->config, $ldap->getDN());
714       $g->removeUser($this->uid);
715       $g->save ();
716     }
718     /* Delete references to object groups */
719     $ldap->cd ($this->config->current['BASE']);
720     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
721     while ($ldap->fetch()){
722       $og= new ogroup($this->config, $ldap->getDN());
723       unset($og->member[$this->dn]);
724       $og->save ();
725     }
727     /* If needed, let the password method do some cleanup */
728     $tmp = new passwordMethod($this->config);
729     $available = $tmp->get_available_methods();
730     if (in_array_ics($this->pw_storage, $available['name'])){
731       $test= new $available[$this->pw_storage]($this->config);
732       $test->attrs= $this->attrs;
733       $test->dn= $this->dn;
734       $test->remove_from_parent();
735     }
737     /* Remove ACL dependencies too */
738     $tmp = new acl($this->config,$this->parent,$this->dn);
739     $tmp->remove_acl();
741     /* Optionally execute a command after we're done */
742     $this->handle_post_events("remove",array("uid" => $this->uid));
743   }
746   /* Save data to object */
747   function save_object()
748   {
749     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
751       /* Make a backup of the current selected base */
752       $base_tmp = $this->base;
754       /* Parents save function */
755       plugin::save_object ();
757       /* Save government mode attributes */
758       if ($this->governmentmode){
759         foreach ($this->govattrs as $val){
760           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
761             $data= stripcslashes($_POST["$val"]);
762             if ($data != $this->$val){
763               $this->is_modified= TRUE;
764             }
765             $this->$val= $data;
766           }
767         }
768       }
770       /* In template mode, the uid is autogenerated... */
771       if ($this->is_template){
772         $this->uid= strtolower($this->sn);
773         $this->givenName= $this->sn;
774       }
776       /* Save base and pw_storage, since these are no LDAP attributes */
777       if (isset($_POST['base'])){
779         $tmp = $this->get_allowed_bases();
780         if(isset($tmp[$_POST['base']])){
781           $base= validate($_POST['base']);
782           if ($base != $this->base){
783             $this->is_modified= TRUE;
784           }
785           $this->base= $base;
786         }else{
787           $this->base = $base_tmp;
788           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
789         }
790       }
792       /* Get pw_storage mode */
793       if (isset($_POST['pw_storage'])){
794         foreach(array("pw_storage") as $val){
795           if(isset($_POST[$val])){
796             $data= validate($_POST[$val]);
797             if ($data != $this->$val){
798               $this->is_modified= TRUE;
799             }
800             $this->$val= $data;
801           }
802         }
803       }
805       /* Save current cn
806        */
807       $this->cn = $this->givenName." ".$this->sn;
808     }
809   }
811   function rebind($ldap, $referral)
812   {
813     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
814     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
815       $this->error = "Success";
816       $this->hascon=true;
817       $this->reconnect= true;
818       return (0);
819     } else {
820       $this->error = "Could not bind to " . $credentials['ADMIN'];
821       return NULL;
822     }
823   }
825   
826   /* Save data to LDAP, depending on is_account we save or delete */
827   function save()
828   {
829     /* Only force save of changes .... 
830        If this attributes aren't changed, avoid saving.
831      */
832     if($this->gender=="0") $this->gender ="";
833     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
835     /* First use parents methods to do some basic fillup in $this->attrs */
836     plugin::save ();
838     if ($this->use_dob == "1"){
839       /* 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. */
840       if(!is_array($this->attrs['dateOfBirth'])) {
841         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
842       }
843     }
845     /* Remove additional objectClasses */
846     $tmp= array();
847     foreach ($this->attrs['objectClass'] as $key => $set){
848       $found= false;
849       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
850         if (preg_match ("/^$set$/i", $val)){
851           $found= true;
852           break;
853         }
854       }
855       if (!$found){
856         $tmp[]= $set;
857       }
858     }
860     /* Replace the objectClass array. This is done because of the
861        separation into government and normal mode. */
862     $this->attrs['objectClass']= $tmp;
864     /* Add objectClasss for template mode? */
865     if ($this->is_template){
866       $this->attrs['objectClass'][]= "gosaUserTemplate";
867     }
869     /* Hard coded government mode? */
870     if ($this->governmentmode){
871       $this->attrs['objectClass'][]= "ivbbentry";
873       /* Copy standard attributes */
874       foreach ($this->govattrs as $val){
875         if ($this->$val != ""){
876           $this->attrs["$val"]= $this->$val;
877         } elseif (!$this->is_new) {
878           $this->attrs["$val"]= array();
879         }
880       }
882       /* Remove attribute if set to "nein" */
883       if ($this->publicVisible == "nein"){
884         $this->attrs['publicVisible']= array();
885         if($this->is_new){
886           unset($this->attrs['publicVisible']);
887         }else{
888           $this->attrs['publicVisible']=array();
889         }
891       }
893     }
895     /* Special handling for attribute userCertificate needed */
896     if ($this->userCertificate != ""){
897       $this->attrs["userCertificate;binary"]= $this->userCertificate;
898       $remove_userCertificate= false;
899     } else {
900       $remove_userCertificate= true;
901     }
903     /* Special handling for dateOfBirth value */
904     if ($this->use_dob != "1"){
905       if ($this->is_new) {
906         unset($this->attrs["dateOfBirth"]);
907       } else {
908         $this->attrs["dateOfBirth"]= array();
909       }
910     }
911     if (!$this->gender){
912       if ($this->is_new) {
913         unset($this->attrs["gender"]);
914       } else {
915         $this->attrs["gender"]= array();
916       }
917     }
918     if (!$this->preferredLanguage){
919       if ($this->is_new) {
920         unset($this->attrs["preferredLanguage"]);
921       } else {
922         $this->attrs["preferredLanguage"]= array();
923       }
924     }
926     /* Special handling for attribute jpegPhote needed, scale image via
927        image magick to 147x200 pixels and inject resulting data. */
928     if ($this->jpegPhoto == "*removed*"){
929     
930       /* Reset attribute to avoid writing *removed* as value */    
931       $this->attrs["jpegPhoto"] = array();
933     } else {
935       /* Fallback if there's no image magick inside PHP */
936       if (!function_exists("imagick_blob2image")){
937         /* Get temporary file name for conversation */
938         $fname = tempnam (TEMP_DIR, "GOsa");
939   
940         /* Open file and write out photoData */
941         $fp = fopen ($fname, "w");
942         fwrite ($fp, $this->photoData);
943         fclose ($fp);
945         /* Build conversation query. Filename is generated automatically, so
946            we do not need any special security checks. Exec command and save
947            output. For PHP safe mode, you'll need a configuration which respects
948            image magick as executable... */
949         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
950         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
951             $query, "Execute");
952   
953         /* Read data written by convert */
954         $output= "";
955         $sh= popen($query, 'r');
956         while (!feof($sh)){
957           $output.= fread($sh, 4096);
958         }
959         pclose($sh);
961         unlink($fname);
963         /* Save attribute */
964         $this->attrs["jpegPhoto"] = $output;
966       } else {
968         /* Load the new uploaded Photo */
969         if(!$handle  =  imagick_blob2image($this->photoData))  {
970           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
971         }
973         /* Resizing image to 147x200 and blur */
974         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
975           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
976         }
978         /* Converting image to JPEG */
979         if(!imagick_convert($handle,"JPEG")) {
980           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
981         }
983         /* Creating binary Code for the Image */
984         if(!$dump = imagick_image2blob($handle)){
985           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
986         }
988         /* Sending Image */
989         $output=  $dump;
991         /* Save attribute */
992         $this->attrs["jpegPhoto"] = $output;
993       }
995     }
997     /* This only gets called when user is renaming himself */
998     $ldap= $this->config->get_ldap_link();
999     if ($this->dn != $this->new_dn){
1001       /* Write entry on new 'dn' */
1002       $this->update_acls($this->dn,$this->new_dn);
1003       $this->move($this->dn, $this->new_dn);
1005       /* Happen to use the new one */
1006       change_ui_dn($this->dn, $this->new_dn);
1007       $this->dn= $this->new_dn;
1008     }
1011     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1012        new entries. So do a check first... */
1013     $ldap->cat ($this->dn, array('dn'));
1014     if ($ldap->fetch()){
1015       $mode= "modify";
1016     } else {
1017       $mode= "add";
1018       $ldap->cd($this->config->current['BASE']);
1019       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1020     }
1022     /* Set password to some junk stuff in case of templates */
1023     if ($this->is_template){
1024       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1025     }
1027     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1028         $this->attributes, "Save via $mode");
1030     /* Finally write data with selected 'mode' */
1031     $this->cleanup();
1033     /* Update current locale settings, if we have edited ourselves */
1034     $ui = session::get('ui');
1035     if(isset($this->attrs['preferredLanguage']) && $this->dn == $ui->dn){
1036       $ui->language = $this->preferredLanguage;
1037       session::set('ui',$ui);
1038       session::set('Last_init_lang',"update");
1039     }
1041     $ldap->cd ($this->dn);
1042     $ldap->$mode ($this->attrs);
1043     if (!$ldap->success()){
1044       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1045       return (1);
1046     }
1048     /* Remove ACL dependencies too */
1049     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1050       $tmp = new acl($this->config,$this->parent,$this->dn);
1051       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1052     }
1054     if($mode == "modify"){
1055       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1056     }else{
1057       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1058     }
1060     /* Remove cert? 
1061        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1062        to work around myself. */
1063     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1065       /* Reset array, assemble new, this should be reworked */
1066       $this->attrs= array();
1067       $this->attrs['userCertificate;binary']= array();
1069       /* Prepare connection */
1070       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1071         die ("Could not connect to LDAP server");
1072       }
1073       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1074       if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("recursive") == "true") {
1075         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1076         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1077       }
1078       if($this->config->get_cfg_value("tls") == "true"){
1079         ldap_start_tls($ds);
1080       }
1081       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1082               $this->config->current['PASSWORD']))) {
1083         die ("Could not bind to LDAP");
1084       }
1086       /* Modify using attrs */
1087       ldap_mod_del($ds,$this->dn,$this->attrs);
1088       ldap_close($ds);
1089     }
1091     /* If needed, let the password method do some cleanup */
1092     if ($this->pw_storage != $this->last_pw_storage){
1093       $tmp = new passwordMethod($this->config);
1094       $available = $tmp->get_available_methods();
1095       if (in_array_ics($this->last_pw_storage, $available['name'])){
1096         $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1097         $test->attrs= $this->attrs;
1098         $test->remove_from_parent();
1099       }
1100     }
1102     /* Maybe the current password method want's to do some changes... */
1103     if (is_object($this->pwObject)){
1104       $this->pwObject->save($this->dn);
1105     }
1107     /* Optionally execute a command after we're done */
1108     if ($mode == "add"){
1109       $this->handle_post_events("add", array("uid" => $this->uid));
1110     } elseif ($this->is_modified){
1111       $this->handle_post_events("modify", array("uid" => $this->uid));
1112     }
1114     return (0);
1115   }
1117   
1118   function update_new_dn()
1119   {
1120     $pt= "";
1121     if($this->config->get_cfg_value("include_personal_title") == "true"){
1122       if(!empty($this->personalTitle)){
1123         $pt = $this->personalTitle." ";
1124       }
1125     }
1126     $this->cn= $pt.$this->givenName." ".$this->sn;
1128     /* Permissions for that base? */
1129     if ($this->config->get_cfg_value("dnmode") == "uid"){
1130       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1131     } else {
1132       /* Don't touch dn, if cn hasn't changed */
1133       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1134           $this->orig_base == $this->base ){
1135         $this->new_dn= $this->dn;
1136       } else {
1137         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1138       }
1139     }
1140   }
1141   
1143   /* Check formular input */
1144   function check()
1145   {
1146     /* Call common method to give check the hook */
1147     $message= plugin::check();
1149     /* Configurable password methods should be configured initially. 
1150      */ 
1151     if($this->last_pw_storage != $this->pw_storage){
1152       $temp= passwordMethod::get_available_methods();
1153       foreach($temp['name'] as $id => $name){
1154         if($name == $this->pw_storage){
1155           if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1156             $message[] = _("The selected password method requires initial configuration!");
1157           }
1158           break;
1159         }
1160       }
1161     }
1163     $this->update_new_dn();
1165     /* Set the new acl base */
1166     if($this->dn == "new") {
1167       $this->set_acl_base($this->base);
1168     }
1170     /* Check if we are allowed to create/move this user 
1171      */
1172     
1173     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1174       $message[]= msgPool::permCreate();
1175     }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1176       $message[]= msgPool::permMove();
1177     }
1179     /* UID already used? */
1180     $ldap= $this->config->get_ldap_link();
1181     $ldap->cd($this->config->current['BASE']);
1182     $ldap->search("(uid=$this->uid)", array("uid"));
1183     $ldap->fetch();
1184     if ($ldap->count() != 0 && $this->dn == 'new'){
1185       $message[]= msgPool::duplicated(_("Login"));
1186     }
1188     /* In template mode, the uid and givenName are autogenerated... */
1189     if ($this->sn == ""){
1190       $message[]= msgPool::required(_("Name"));
1191     }
1193     if (!$this->is_template){
1194       if ($this->givenName == ""){
1195         $message[]= msgPool::required(_("Given name"));
1196       }
1197       if ($this->uid == ""){
1198         $message[]= msgPool::required(_("Login"));
1199       }
1200       if ($this->config->get_cfg_value("dnmode") != "uid"){
1201         $ldap->cat($this->new_dn);
1202         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1203           $message[]= msgPool::duplicated(_("Name"));
1204         }
1205       }
1206     }
1208     /* Check for valid input */
1209     if ($this->is_modified && !tests::is_uid($this->uid)){
1211       if (strict_uid_mode()){
1212         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1213       } else {
1214         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1215       }
1216     }
1217     if (!tests::is_url($this->labeledURI)){
1218       $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1219     }
1221     /* Check phone numbers */
1222     if (!tests::is_phone_nr($this->telephoneNumber)){
1223       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1224     }
1225     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1226       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1227     }
1228     if (!tests::is_phone_nr($this->mobile)){
1229       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1230     }
1231     if (!tests::is_phone_nr($this->pager)){
1232       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1233     }
1235     /* Check for reserved characers */
1236     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1237       $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1238     }
1239     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1240       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1241     }
1243     return $message;
1244   }
1247   /* Indicate whether a password change is needed or not */
1248   function password_change_needed()
1249   {
1250     if(in_array("pw_storage",$this->multi_boxes)){
1251       return(TRUE);
1252     }
1253     return($this->pw_storage != $this->last_pw_storage);
1254   }
1257   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1258   function load_picture()
1259   {
1260     $ldap = $this->config->get_ldap_link();
1261     $ldap->cd ($this->dn);
1262     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1264     if((!$data) || ($data == "*removed*")){ 
1266       /* In case we don't get an entry, load a default picture */
1267       $this->set_picture ();
1268       $this->jpegPhoto= "*removed*";
1269     }else{
1271       /* Set picture */
1272       $this->photoData= $data;
1273       session::set('binary',$this->photoData);
1274       session::set('binarytype',"image/jpeg");
1275       $this->jpegPhoto= "";
1276     }
1277   }
1280   /* Load a certificate from LDAP, this is going to be simplified later on */
1281   function load_cert()
1282   {
1283     $ds= ldap_connect($this->config->current['SERVER']);
1284     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1285     if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("recursive") == "true"){
1286       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1287       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1288     }
1289     if ($this->config->get_cfg_value("tls") == "true"){
1290       ldap_start_tls($ds);
1291     }
1293     $r= ldap_bind($ds);
1294     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1296     if ($sr) {
1297       $ei= @ldap_first_entry($ds, $sr);
1298       
1299       if ($ei) {
1300         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1301           $this->userCertificate= "";
1302         } else {
1303           $this->userCertificate= $info[0];
1304         }
1305       }
1306     } else {
1307       $this->userCertificate= "";
1308     }
1310     ldap_unbind($ds);
1311   }
1314   /* Load picture from file to object */
1315   function set_picture($filename ="")
1316   {
1317     if (!is_file($filename) || $filename =="" ){
1318       $filename= "./plugins/users/images/default.jpg";
1319       $this->jpegPhoto= "*removed*";
1320     }
1322     $fd = fopen ($filename, "rb");
1323     $this->photoData= fread ($fd, filesize ($filename));
1324     session::set('binary',$this->photoData);
1325     session::set('binarytype',"image/jpeg");
1326     $this->jpegPhoto= "";
1328     fclose ($fd);
1329   }
1332   /* Load certificate from file to object */
1333   function set_cert($cert, $filename)
1334   {
1335     if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1336     $fd = fopen ($filename, "rb");
1337     if (filesize($filename)>0) {
1338       $this->$cert= fread ($fd, filesize ($filename));
1339       fclose ($fd);
1340       $this->is_modified= TRUE;
1341     } else {
1342       msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1343     }
1344   }
1346   /* Adapt from given 'dn' */
1347   function adapt_from_template($dn, $skip= array())
1348   {
1349     plugin::adapt_from_template($dn, $skip);
1351     /* Get base */
1352     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1354     if($this->governmentmode){
1356       /* Walk through govattrs */
1357       foreach ($this->govattrs as $val){
1359         if (in_array($val, $skip)){
1360           continue;
1361         }
1363         if (isset($this->attrs["$val"][0])){
1365           /* If attribute is set, replace dynamic parts: 
1366              %sn, %givenName and %uid. Fill these in our local variables. */
1367           $value= $this->attrs["$val"][0];
1369           foreach (array("sn", "givenName", "uid") as $repl){
1370             if (preg_match("/%$repl/i", $value)){
1371               $value= preg_replace ("/%$repl/i",
1372                   $this->parent->$repl, $value);
1373             }
1374           }
1375           $this->$val= $value;
1376         }
1377       }
1378     }
1380     /* Get back uid/sn/givenName - only write if nothing's skipped */
1381     if ($this->parent !== NULL && count($skip) == 0){
1382       $this->uid= $this->parent->uid;
1383       $this->sn= $this->parent->sn;
1384       $this->givenName= $this->parent->givenName;
1385     }
1386   }
1388  
1389   /* This avoids that users move themselves out of their rights. 
1390    */
1391   function allowedBasesToMoveTo()
1392   {
1393     /* Get bases */
1394     $bases  = $this->get_allowed_bases();
1395     return($bases);
1396   } 
1399   function getCopyDialog()
1400   {
1401     $str = "";
1403     session::set('binary',$this->photoData); 
1404     session::set('binarytype',"image/jpeg");
1406     /* Get random number for pictures */
1407     srand((double)microtime()*1000000); 
1408     $rand = rand(0, 10000);
1410     $smarty = get_smarty();
1412     $smarty->assign("passwordTodo","clear");
1414     if(isset($_POST['passwordTodo'])){
1415       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1416     }
1418     $smarty->assign("sn",       $this->sn);
1419     $smarty->assign("givenName",$this->givenName);
1420     $smarty->assign("uid",      $this->uid);
1421     $smarty->assign("rand",     $rand);
1422     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1425     $ret = array();
1426     $ret['string'] = $str;
1427     $ret['status'] = "";  
1428     return($ret);
1429   }
1431   function saveCopyDialog()
1432   {
1433     /* Set_acl_base */
1434     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1436     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1437       $this->set_picture($_FILES['picture_file']['tmp_name']);
1438     }
1440     /* Remove picture? */
1441     if (isset($_POST['picture_remove'])){
1442       $this->jpegPhoto= "*removed*";
1443       $this->set_picture ("./plugins/users/images/default.jpg");
1444       $this->is_modified= TRUE;
1445     }
1447     $attrs = array("uid","givenName","sn");
1448     foreach($attrs as $attr){
1449       if(isset($_POST[$attr])){
1450         $this->$attr = $_POST[$attr];
1451       }
1452     } 
1453   }
1456   function PrepareForCopyPaste($source)
1457   {
1458     plugin::PrepareForCopyPaste($source);
1460     /* Reset certificate information addepted from source user
1461        to avoid setting the same user certificate for the destination user. */
1462     $this->userPKCS12= "";
1463     $this->userSMIMECertificate= "";
1464     $this->userCertificate= "";
1465     $this->certificateSerialNumber= "";
1466     $this->old_certificateSerialNumber= "";
1467     $this->old_userPKCS12= "";
1468     $this->old_userSMIMECertificate= "";
1469     $this->old_userCertificate= "";
1470   }
1473   static function plInfo()
1474   {
1475   
1476     $govattrs= array(
1477         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1478         "houseIdentifier"                           =>  _("House identifier"), 
1479         "vocation"                                  =>  _("Vocation"),
1480         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1481         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1482         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1483         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1484         "functionalTitle"                           =>  _("Functional title"),
1485         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1486         "publicVisible"                             =>  _("Public visible"),
1487         "street"                                    =>  _("Street"),
1488         "role"                                      =>  _("Role"),
1489         "postalCode"                                =>  _("Postal code"));
1491     $ret = array(
1492         "plShortName" => _("Generic"),
1493         "plDescription" => _("Generic user settings"),
1494         "plSelfModify"  => TRUE,
1495         "plDepends"     => array(),
1496         "plPriority"    => 1,
1497         "plSection"     => array("personal" => _("My account")),
1498         "plCategory"    => array("users" => array("description" => _("Users"),
1499                                                   "objectClass" => "gosaAccount")),
1501         "plProvidedAcls" => array(
1503           "sn"                => _("Surname"),
1504           "givenName"         => _("Given name"),
1505           "uid"               => _("User identification"),
1506           "personalTitle"     => _("Personal title"),
1507           "academicTitle"     => _("Academic title"),
1509           "dateOfBirth"       => _("Date of birth"),
1510           "gender"            => _("Gender"),
1511           "preferredLanguage" => _("Preferred language"),
1512           "base"              => _("Base"), 
1514           "userPicture"       => _("User picture"),
1516           "o"                 => _("Organization"),
1517           "ou"                => _("Department"),
1518           "departmentNumber"  => _("Department number"),
1519           "employeeNumber"    => _("Employee number"),
1520           "employeeType"      => _("Employee type"),
1522           "roomNumber"        => _("Room number"),
1523           "telephoneNumber"   => _("Telefon number"),
1524           "pager"             => _("Pager number"),
1525           "mobile"            => _("Mobile number"),
1526           "facsimileTelephoneNumber"     => _("Fax number"),
1528           "st"                => _("State"),
1529           "l"                 => _("Location"),
1530           "postalAddress"     => _("Postal address"),
1532           "homePostalAddress" => _("Home postal address"),
1533           "homePhone"         => _("Home phone number"),
1534           "labeledURI"        => _("Homepage"),
1535           "userPassword"      => _("User password method"), 
1536           "Certificate"       => _("User certificates"))
1538         );
1540     /* Append government attributes if required */
1541     global $config;
1542     if($config->get_cfg_value("governmentmode") == "true"){
1543       foreach($govattrs as $attr => $desc){
1544         $ret["plProvidedAcls"][$attr] = $desc;
1545       }
1546     }
1547     return($ret);
1548   }
1550   function get_multi_edit_values()
1551   {
1552     $ret = plugin::get_multi_edit_values();
1553     if(in_array("pw_storage",$this->multi_boxes)){
1554       $ret['pw_storage'] = $this->pw_storage;
1555     }
1556     if(in_array("edit_picture",$this->multi_boxes)){
1557       $ret['jpegPhoto'] = $this->jpegPhoto;
1558       $ret['photoData'] = $this->photoData;
1559       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1560       $ret['old_photoData'] = $this->old_photoData;
1561     }
1562     if(isset($ret['dateOfBirth'])){
1563       unset($ret['dateOfBirth']);
1564     }
1565     if(isset($ret['cn'])){
1566       unset($ret['cn']);
1567     }
1568     $ret['is_modified'] = $this->is_modified;
1569     if(in_array("base",$this->multi_boxes)){
1570       $ret['orig_base']="Changed_by_Multi_Plug";
1571       $ret['base']=$this->base;
1572     }
1573     return($ret); 
1574   }
1577   function multiple_save_object()
1578   {
1579     plugin::multiple_save_object();
1581     /* Get pw_storage mode */
1582     if (isset($_POST['pw_storage'])){
1583       foreach(array("pw_storage") as $val){
1584         if(isset($_POST[$val])){
1585           $data= validate(get_post($val));
1586           if ($data != $this->$val){
1587             $this->is_modified= TRUE;
1588           }
1589           $this->$val= $data;
1590         }
1591       }
1592     }
1593     if(isset($_POST['base'])){
1594       $this->base = get_post('base');
1595     }
1597     if(isset($_POST['user_mulitple_edit'])){
1598       foreach(array("base","pw_storage","edit_picture") as $val){
1599         if(isset($_POST["use_".$val])){
1600           $this->multi_boxes[] = $val;
1601         }
1602       }
1603     }
1604   }
1606   
1607   function multiple_check()
1608   {
1609     /* Call check() to set new_dn correctly ... */
1610     $message = plugin::multiple_check();
1612     /* Set the new acl base */
1613     if($this->dn == "new") {
1614       $this->set_acl_base($this->base);
1615     }
1616     if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1617       $message[]= msgPool::invalid(_("Homepage"));
1618     }
1619     if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1620       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1621     }
1622     if (!tests::is_phone_nr($this->facsimileTelephoneNumber) &&  in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1623       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1624     }
1625     if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1626       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1627     }
1628     if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1629       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1630     }
1631     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1632       $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1633     }
1634     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1635       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1636     }
1637     return($message);
1638   }
1642   function multiple_execute()
1643   {
1644     return($this->execute());
1645   }
1650 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1651 ?>