Code

Updated create check
[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 (isset($this->config->current['GOVERNMENTMODE']) && preg_match("/true/i",$this->config->current['GOVERNMENTMODE'])){
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     if (!isset($this->config->current['HASH'])){
170       $hash= "md5";
171     } else {
172       $hash= $this->config->current['HASH'];
173     }
175     /* Load data from LDAP? */
176     if ($dn !== NULL){
178       /* Do base conversation */
179       if ($this->dn == "new"){
180         $ui= get_userinfo();
181         $this->base= dn2base($ui->dn);
182       } else {
183         $this->base= dn2base($dn);
184       }
186       /* get password storage type */
187       if (isset ($this->attrs['userPassword'][0])){
188         /* Initialize local array */
189         $matches= array();
190         if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
191           $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
192           if(is_object($tmp)){
193             $this->pw_storage= $tmp->get_hash(); 
194           }
196         } else {
197           if ($this->attrs['userPassword'][0] != ""){
198             $this->pw_storage= "clear";
199           } else {
200             $this->pw_storage= $hash;
201           }
202         }
203       } else {
204         /* Preset with vaule from configuration */
205         $this->pw_storage= $hash;
206       }
208       /* Load extra attributes: certificate and picture */
209       $this->load_cert();
210       $this->load_picture();
211       if ($this->userCertificate != ""){
212         $this->had_userCertificate= TRUE;
213       }
214     }
216     /* Reset password storage indicator, used by password_change_needed() */
217     if ($dn == "new"){
218       $this->last_pw_storage= "unset";
219     } else {
220       $this->last_pw_storage= $this->pw_storage;
221     }
223     /* Generate dateOfBirth entry */
224     if (isset ($this->attrs['dateOfBirth'])){
225       /* This entry is ISO 8601 conform */
226       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
227     
228       $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
229       $this->use_dob= "1";
230     } else {
231       $this->use_dob= "0";
232     }
234     /* Put gender attribute to upper case */
235     if (isset ($this->attrs['gender'])){
236       $this->gender= strtoupper($this->attrs['gender'][0]);
237     }
238  
239     $this->orig_base = $this->base;
240   }
245   /* execute generates the html output for this node */
246   function execute()
247   {
248     /* Call parent execute */
249     plugin::execute();
251     /* Log view */
252     if($this->is_account && !$this->view_logged){
253       $this->view_logged = TRUE;
254       new log("view","users/".get_class($this),$this->dn);
255     }
257     $smarty= get_smarty();
259     /* Fill calendar */
260     if ($this->dateOfBirth == "0"){
261       $date= getdate();
262     } else {
263       if(is_array($this->dateOfBirth)){
264         $date = $this->dateOfBirth;
265   
266         // Trigger on dates like 1985-04-01, getdate only understands timestamps
267       } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
268         $date= getdate(strtotime($this->dateOfBirth));
270       } else {
271         $date = getdate($this->dateOfBirth);
272       }
273     }
275     $days= array();
276     for($d= 1; $d<32; $d++){
277       $days[$d]= $d;
278     }
279     $years= array();
281     if(($date['year']-100)<1901){
282       $start = 1901;
283     }else{
284       $start = $date['year']-100;
285     }
287     $end = $start +100;
288     
289     for($y= $start; $y<=$end; $y++){
290       $years[]= $y;
291     }
292     $years['-']= "-&nbsp;";
293     $months= msgPool::months();
294     $months['-'] = '-&nbsp;';
296     $smarty->assign("day", $date["mday"]);
297     $smarty->assign("days", $days);
298     $smarty->assign("months", $months);
299     $smarty->assign("month", $date["mon"]-1);
300     $smarty->assign("years", $years);
301     $smarty->assign("year", $date["year"]);
303     /* Assign sex */
304     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
305     $smarty->assign("gender_list", $sex);
306     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
307     $smarty->assign("preferredLanguage_list", $language);
309     /* Get random number for pictures */
310     srand((double)microtime()*1000000); 
311     $smarty->assign("rand", rand(0, 10000));
314     /* Do we represent a valid gosaAccount? */
315     if (!$this->is_account){
316       $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
317         msgPool::noValidExtension("GOsa")."</b>";
318       return($str);
319     }
321     /* Base select dialog */
322     $once = true;
323     foreach($_POST as $name => $value){
324       if(preg_match("/^chooseBase/",$name) && $once){
325         $once = false;
326         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
327         $this->dialog->setCurrentBase($this->base);
328       }
329     }
331     /* Password configure dialog handling */
332     if(is_object($this->pwObject) && $this->pwObject->display){
333       $output= $this->pwObject->configure();
334       if ($output != ""){
335         $this->dialog= TRUE;
336         return $output;
337       }
338       $this->dialog= false;
339     }
341     /* Dialog handling */
342     if(is_object($this->dialog)){
343       /* Must be called before save_object */
344       $this->dialog->save_object();
345    
346       if($this->dialog->isClosed()){
347         $this->dialog = false;
348       }elseif($this->dialog->isSelected()){
350         /* check if selected base is allowed to move to / create a new object */
351         $tmp = $this->get_allowed_bases();
352         if(isset($tmp[$this->dialog->isSelected()])){
353           $this->base = $this->dialog->isSelected();
354         }
355         $this->dialog= false;
356       }else{
357         return($this->dialog->execute());
358       }
359     }
361     /* Want password method editing? */
362     if ($this->acl_is_writeable("userPassword")){
363       if (isset($_POST['edit_pw_method'])){
364         if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
365           $temp= passwordMethod::get_available_methods();
366           $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
367         }
368         $this->pwObject->display = TRUE;
369         $this->dialog= TRUE;
370         return ($this->pwObject->configure());
371       }
372     }
374     /* Want picture edit dialog? */
375     if($this->acl_is_writeable("userPicture")) {
376       if (isset($_POST['edit_picture'])){
377         /* Save values for later recovery, in case some presses
378            the cancel button. */
379         $this->old_jpegPhoto= $this->jpegPhoto;
380         $this->old_photoData= $this->photoData;
381         $this->picture_dialog= TRUE;
382         $this->dialog= TRUE;
383       }
384     }
386     /* Remove picture? */
387     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
388       if (isset($_POST['picture_remove'])){
389         $this->set_picture ();
390         $this->jpegPhoto= "*removed*";
391         $this->is_modified= TRUE;
392         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
393       }
394     }
396     /* Save picture */
397     if (isset($_POST['picture_edit_finish'])){
399       /* Check for clean upload */
400       if ($_FILES['picture_file']['name'] != ""){
401         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
402           msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
403         }else{
404           /* Activate new picture */
405           $this->set_picture($_FILES['picture_file']['tmp_name']);
406         }
407       }
408       $this->picture_dialog= FALSE;
409       $this->dialog= FALSE;
410       $this->is_modified= TRUE;
411     }
414     /* Cancel picture */
415     if (isset($_POST['picture_edit_cancel'])){
417       /* Restore values */
418       $this->jpegPhoto= $this->old_jpegPhoto;
419       $this->photoData= $this->old_photoData;
421       /* Update picture */
422       session::set('binary',$this->photoData);
423       session::set('binarytype',"image/jpeg");
424       $this->picture_dialog= FALSE;
425       $this->dialog= FALSE;
426     }
428     /* Toggle dateOfBirth information */
429     if (isset($_POST['set_dob'])){
430       $this->use_dob= ($this->use_dob == "0")?"1":"0";
431     }
434     /* Want certificate= */
435     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
437       /* Save original values for later reconstruction */
438       foreach (array("certificateSerialNumber", "userCertificate",
439             "userSMIMECertificate", "userPKCS12") as $val){
441         $oval= "old_$val";
442         $this->$oval= $this->$val;
443       }
445       $this->cert_dialog= TRUE;
446       $this->dialog= TRUE;
447     }
450     /* Cancel certificate dialog */
451     if (isset($_POST['cert_edit_cancel'])){
453       /* Restore original values in case of 'cancel' */
454       foreach (array("certificateSerialNumber", "userCertificate",
455             "userSMIMECertificate", "userPKCS12") as $val){
457         $oval= "old_$val";
458         $this->$val= $this->$oval;
459       }
460       $this->cert_dialog= FALSE;
461       $this->dialog= FALSE;
462     }
465     /* Remove certificate? */
466     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){ 
467       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
468         if (isset($_POST["remove_$val"])){
470           /* Reset specified cert*/
471           $this->$val= "";
472           $this->is_modified= TRUE;
473         }
474       }
475     }
477     /* Upload new cert and close dialog? */     
478     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){ 
480       $fail =false;
482       if (isset($_POST['cert_edit_finish'])){
484         /* for all certificates do */
485         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
486             as $val){
488           /* Check for clean upload */
489           if (array_key_exists($val."_file", $_FILES) &&
490               array_key_exists('name', $_FILES[$val."_file"]) &&
491               $_FILES[$val."_file"]['name'] != "" &&
492               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
493             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
494           }
495         }
497         /* Save serial number */
498         if (isset($_POST["certificateSerialNumber"]) &&
499             $_POST["certificateSerialNumber"] != ""){
501           if (!tests::is_id($_POST["certificateSerialNumber"])){
502             $fail = true;
503             msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
505             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
506               if ($this->$cert != ""){
507                 $smarty->assign("$cert"."_state", "true");
508               } else {
509                 $smarty->assign("$cert"."_state", "");
510               }
511             }
512           }
514           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
515           $this->is_modified= TRUE;
516         }
517         if(!$fail){
518           $this->cert_dialog= FALSE;
519           $this->dialog= FALSE;
520         }
521       }
522     }
523     /* Display picture dialog */
524     if ($this->picture_dialog){
525       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
526     }
528     /* Display cert dialog */
529     if ($this->cert_dialog){
530       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
531       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
532       $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
534       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
535         if ($this->$cert != ""){
536           /* import certificate */
537           $certificate = new certificate;
538           $certificate->import($this->$cert);
539       
540           /* Read out data*/
541           $timeto   = $certificate->getvalidto_date();
542           $timefrom = $certificate->getvalidfrom_date();
543          
544           
545           /* Additional info if start end time is '0' */
546           $add_str_info = "";
547           if($timeto == 0 && $timefrom == 0){
548             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
549           }
551           $str = "<table summary=\"\" border=0>
552                     <tr>
553                       <td style='vertical-align:top'>CN</td>
554                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
555                     </tr>
556                   </table><br>".
558                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
559                         "<b>".date('d M Y',$timefrom)."</b>",
560                         "<b>".date('d M Y',$timeto)."</b>",
561                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
562                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
564           $smarty->assign($cert."info",$str);
565           $smarty->assign($cert."_state","true");
566         } else {
567           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
568           $smarty->assign($cert."_state","");
569         }
570       }
571   
572       if($this->governmentmode){
573         $smarty->assign("governmentmode", "true");
574       }else{
575         $smarty->assign("governmentmode", "false");
576       }
577       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
578     }
580     /* Prepare password hashes */
581     if ($this->pw_storage == ""){
582       $this->pw_storage= $this->config->current['HASH'];
583     }
585     $temp= passwordMethod::get_available_methods();
586     $is_configurable= FALSE;
587     $hashes = $temp['name'];
588     if(isset($temp[$this->pw_storage])){
589       $test= new $temp[$this->pw_storage]($this->config);
590       $is_configurable= $test->is_configurable();
591     }else{
592       new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
593     }
596     /* Create password methods array */
597     $pwd_methods = array();
598     foreach($hashes as $id => $name){
599       if(!empty($temp['desc'][$id])){
600         $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
601       }else{
602         $pwd_methods[$name] = $name;
603       }
604     }
605  
606     /* Load attributes and acl's */
607     $ui =get_userinfo();
608     foreach($this->attributes as $val){
609       $smarty->assign("$val", $this->$val);
610       if(in_array($val,$this->multi_boxes)){
611         $smarty->assign("use_".$val,TRUE);
612       }else{
613         $smarty->assign("use_".$val,FALSE);
614       }
615     }
616     foreach(array("base","pw_storage","edit_picture") as $val){
617       if(in_array($val,$this->multi_boxes)){
618         $smarty->assign("use_".$val,TRUE);
619       }else{
620         $smarty->assign("use_".$val,FALSE);
621       }
622     }
624     /* Set acls */
625     $tmp = $this->plinfo();
626     foreach($tmp['plProvidedAcls'] as $val => $translation){
627       $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
628     }
630     $smarty->assign("pwmode", $pwd_methods);
631     $smarty->assign("pwmode_select", $this->pw_storage);
632     $smarty->assign("pw_configurable", $is_configurable);
633     $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
634     $smarty->assign("base_select",      $this->base);
635     $smarty->assign("CertificatesACL",  $this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
636     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
637     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
639     /* Create base acls */
640     $tmp = @$this->allowedBasesToMoveTo();
641     $smarty->assign("bases", $tmp);
643     /* Save government mode attributes */
644     if($this->governmentmode){
645       $smarty->assign("governmentmode", "true");
646       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
647           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
648       $smarty->assign("ivbbmodes", $ivbbmodes);
649       foreach ($this->govattrs as $val){
650         $smarty->assign("$val", $this->$val);
651         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
652       }
653     } else {
654       $smarty->assign("governmentmode", "false");
655     }
657     /* Special mode for uid */
658     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
659     if (isset ($this->dn)){
660       if ($this->dn != "new"){
661         $uidACL= preg_replace("/w/","",$uidACL);
662       }
663     }  else {
664       $uidACL= preg_replace("/w/","",$uidACL);
665     }
666     
667     $smarty->assign("uidACL", $uidACL);
668     $smarty->assign("is_template", $this->is_template);
669     $smarty->assign("use_dob", $this->use_dob);
671     if (isset($this->parent)){
672       if (isset($this->parent->by_object['phoneAccount']) &&
673           $this->parent->by_object['phoneAccount']->is_account){
674         $smarty->assign("has_phoneaccount", "true");
675       } else {
676         $smarty->assign("has_phoneaccount", "false");
677       }
678     } else {
679       $smarty->assign("has_phoneaccount", "false");
680     }
681     $smarty->assign("multiple_support" , $this->multiple_support_active);
682     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
683   }
686   /* remove object from parent */
687   function remove_from_parent()
688   {
689     /* Remove password extension */
690     $temp= passwordMethod::get_available_methods();
692     /* Remove password method from user account */
693     if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
694       $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
695       $this->pwObject->remove_from_parent();
696     }
698     /* Remove user */
699     $ldap= $this->config->get_ldap_link();
700     $ldap->rmdir ($this->dn);
701     if (!$ldap->success()){
702       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
703     }
704   
705     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
706   
707     /* Delete references to groups */
708     $ldap->cd ($this->config->current['BASE']);
709     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
710     while ($ldap->fetch()){
711       $g= new group($this->config, $ldap->getDN());
712       $g->removeUser($this->uid);
713       $g->save ();
714     }
716     /* Delete references to object groups */
717     $ldap->cd ($this->config->current['BASE']);
718     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
719     while ($ldap->fetch()){
720       $og= new ogroup($this->config, $ldap->getDN());
721       unset($og->member[$this->dn]);
722       $og->save ();
723     }
725     /* If needed, let the password method do some cleanup */
726     $tmp = new passwordMethod($this->config);
727     $available = $tmp->get_available_methods();
728     if (in_array_ics($this->pw_storage, $available['name'])){
729       $test= new $available[$this->pw_storage]($this->config);
730       $test->attrs= $this->attrs;
731       $test->dn= $this->dn;
732       $test->remove_from_parent();
733     }
735     /* Remove ACL dependencies too */
736     $tmp = new acl($this->config,$this->parent,$this->dn);
737     $tmp->remove_acl();
739     /* Optionally execute a command after we're done */
740     $this->handle_post_events("remove",array("uid" => $this->uid));
741   }
744   /* Save data to object */
745   function save_object()
746   {
747     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
749       /* Make a backup of the current selected base */
750       $base_tmp = $this->base;
752       /* Parents save function */
753       plugin::save_object ();
755       /* Save government mode attributes */
756       if ($this->governmentmode){
757         foreach ($this->govattrs as $val){
758           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
759             $data= stripcslashes($_POST["$val"]);
760             if ($data != $this->$val){
761               $this->is_modified= TRUE;
762             }
763             $this->$val= $data;
764           }
765         }
766       }
768       /* In template mode, the uid is autogenerated... */
769       if ($this->is_template){
770         $this->uid= strtolower($this->sn);
771         $this->givenName= $this->sn;
772       }
774       /* Save base and pw_storage, since these are no LDAP attributes */
775       if (isset($_POST['base'])){
777         $tmp = $this->get_allowed_bases();
778         if(isset($tmp[$_POST['base']])){
779           $base= validate($_POST['base']);
780           if ($base != $this->base){
781             $this->is_modified= TRUE;
782           }
783           $this->base= $base;
784         }else{
785           $this->base = $base_tmp;
786           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
787         }
788       }
790       /* Get pw_storage mode */
791       if (isset($_POST['pw_storage'])){
792         foreach(array("pw_storage") as $val){
793           if(isset($_POST[$val])){
794             $data= validate($_POST[$val]);
795             if ($data != $this->$val){
796               $this->is_modified= TRUE;
797             }
798             $this->$val= $data;
799           }
800         }
801       }
802     }
803   }
805   function rebind($ldap, $referral)
806   {
807     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
808     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
809       $this->error = "Success";
810       $this->hascon=true;
811       $this->reconnect= true;
812       return (0);
813     } else {
814       $this->error = "Could not bind to " . $credentials['ADMIN'];
815       return NULL;
816     }
817   }
819   
820   /* Save data to LDAP, depending on is_account we save or delete */
821   function save()
822   {
823     /* Only force save of changes .... 
824        If this attributes aren't changed, avoid saving.
825      */
826     if($this->gender=="0") $this->gender ="";
827     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
829     /* First use parents methods to do some basic fillup in $this->attrs */
830     plugin::save ();
832     if ($this->use_dob == "1"){
833       /* 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. */
834       if(!is_array($this->attrs['dateOfBirth'])) {
835         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
836       }
837     }
839     /* Remove additional objectClasses */
840     $tmp= array();
841     foreach ($this->attrs['objectClass'] as $key => $set){
842       $found= false;
843       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
844         if (preg_match ("/^$set$/i", $val)){
845           $found= true;
846           break;
847         }
848       }
849       if (!$found){
850         $tmp[]= $set;
851       }
852     }
854     /* Replace the objectClass array. This is done because of the
855        separation into government and normal mode. */
856     $this->attrs['objectClass']= $tmp;
858     /* Add objectClasss for template mode? */
859     if ($this->is_template){
860       $this->attrs['objectClass'][]= "gosaUserTemplate";
861     }
863     /* Hard coded government mode? */
864     if ($this->governmentmode){
865       $this->attrs['objectClass'][]= "ivbbentry";
867       /* Copy standard attributes */
868       foreach ($this->govattrs as $val){
869         if ($this->$val != ""){
870           $this->attrs["$val"]= $this->$val;
871         } elseif (!$this->is_new) {
872           $this->attrs["$val"]= array();
873         }
874       }
876       /* Remove attribute if set to "nein" */
877       if ($this->publicVisible == "nein"){
878         $this->attrs['publicVisible']= array();
879         if($this->is_new){
880           unset($this->attrs['publicVisible']);
881         }else{
882           $this->attrs['publicVisible']=array();
883         }
885       }
887     }
889     /* Special handling for attribute userCertificate needed */
890     if ($this->userCertificate != ""){
891       $this->attrs["userCertificate;binary"]= $this->userCertificate;
892       $remove_userCertificate= false;
893     } else {
894       $remove_userCertificate= true;
895     }
897     /* Special handling for dateOfBirth value */
898     if ($this->use_dob != "1"){
899       if ($this->is_new) {
900         unset($this->attrs["dateOfBirth"]);
901       } else {
902         $this->attrs["dateOfBirth"]= array();
903       }
904     }
905     if (!$this->gender){
906       if ($this->is_new) {
907         unset($this->attrs["gender"]);
908       } else {
909         $this->attrs["gender"]= array();
910       }
911     }
912     if (!$this->preferredLanguage){
913       if ($this->is_new) {
914         unset($this->attrs["preferredLanguage"]);
915       } else {
916         $this->attrs["preferredLanguage"]= array();
917       }
918     }
920     /* Special handling for attribute jpegPhote needed, scale image via
921        image magick to 147x200 pixels and inject resulting data. */
922     if ($this->jpegPhoto == "*removed*"){
923     
924       /* Reset attribute to avoid writing *removed* as value */    
925       $this->attrs["jpegPhoto"] = array();
927     } else {
929       /* Fallback if there's no image magick inside PHP */
930       if (!function_exists("imagick_blob2image")){
931         /* Get temporary file name for conversation */
932         $fname = tempnam (TEMP_DIR, "GOsa");
933   
934         /* Open file and write out photoData */
935         $fp = fopen ($fname, "w");
936         fwrite ($fp, $this->photoData);
937         fclose ($fp);
939         /* Build conversation query. Filename is generated automatically, so
940            we do not need any special security checks. Exec command and save
941            output. For PHP safe mode, you'll need a configuration which respects
942            image magick as executable... */
943         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
944         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
945             $query, "Execute");
946   
947         /* Read data written by convert */
948         $output= "";
949         $sh= popen($query, 'r');
950         while (!feof($sh)){
951           $output.= fread($sh, 4096);
952         }
953         pclose($sh);
955         unlink($fname);
957         /* Save attribute */
958         $this->attrs["jpegPhoto"] = $output;
960       } else {
962         /* Load the new uploaded Photo */
963         if(!$handle  =  imagick_blob2image($this->photoData))  {
964           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
965         }
967         /* Resizing image to 147x200 and blur */
968         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
969           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
970         }
972         /* Converting image to JPEG */
973         if(!imagick_convert($handle,"JPEG")) {
974           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
975         }
977         /* Creating binary Code for the Image */
978         if(!$dump = imagick_image2blob($handle)){
979           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
980         }
982         /* Sending Image */
983         $output=  $dump;
985         /* Save attribute */
986         $this->attrs["jpegPhoto"] = $output;
987       }
989     }
991     /* This only gets called when user is renaming himself */
992     $ldap= $this->config->get_ldap_link();
993     if ($this->dn != $this->new_dn){
995       /* Write entry on new 'dn' */
996       $this->update_acls($this->dn,$this->new_dn);
997       $this->move($this->dn, $this->new_dn);
999       /* Happen to use the new one */
1000       change_ui_dn($this->dn, $this->new_dn);
1001       $this->dn= $this->new_dn;
1002     }
1005     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1006        new entries. So do a check first... */
1007     $ldap->cat ($this->dn, array('dn'));
1008     if ($ldap->fetch()){
1009       $mode= "modify";
1010     } else {
1011       $mode= "add";
1012       $ldap->cd($this->config->current['BASE']);
1013       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1014     }
1016     /* Set password to some junk stuff in case of templates */
1017     if ($this->is_template){
1018       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1019     }
1021     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1022         $this->attributes, "Save via $mode");
1024     /* Finally write data with selected 'mode' */
1025     $this->cleanup();
1027     if(isset($this->attrs['preferredLanguage'])){
1028       $ui = session::get('ui');
1029       $ui->language = $this->preferredLanguage;
1030       session::set('ui',$ui);
1031       session::set('Last_init_lang',"update");
1032     }
1034     $ldap->cd ($this->dn);
1035     $ldap->$mode ($this->attrs);
1036     if (!$ldap->success()){
1037       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1038       return (1);
1039     }
1041     /* Remove ACL dependencies too */
1042     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1043       $tmp = new acl($this->config,$this->parent,$this->dn);
1044       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1045     }
1047     if($mode == "modify"){
1048       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1049     }else{
1050       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1051     }
1053     /* Remove cert? 
1054        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1055        to work around myself. */
1056     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1058       /* Reset array, assemble new, this should be reworked */
1059       $this->attrs= array();
1060       $this->attrs['userCertificate;binary']= array();
1062       /* Prepare connection */
1063       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1064         die ("Could not connect to LDAP server");
1065       }
1066       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1067       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1068         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1069         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1070       }
1071       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1072         ldap_start_tls($ds);
1073       }
1074       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1075               $this->config->current['PASSWORD']))) {
1076         die ("Could not bind to LDAP");
1077       }
1079       /* Modify using attrs */
1080       ldap_mod_del($ds,$this->dn,$this->attrs);
1081       ldap_close($ds);
1082     }
1084     /* If needed, let the password method do some cleanup */
1085     if ($this->pw_storage != $this->last_pw_storage){
1086       $tmp = new passwordMethod($this->config);
1087       $available = $tmp->get_available_methods();
1088       if (in_array_ics($this->last_pw_storage, $available['name'])){
1089         $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1090         $test->attrs= $this->attrs;
1091         $test->remove_from_parent();
1092       }
1093     }
1095     /* Maybe the current password method want's to do some changes... */
1096     if (is_object($this->pwObject)){
1097       $this->pwObject->save($this->dn);
1098     }
1100     /* Optionally execute a command after we're done */
1101     if ($mode == "add"){
1102       $this->handle_post_events("add", array("uid" => $this->uid));
1103     } elseif ($this->is_modified){
1104       $this->handle_post_events("modify", array("uid" => $this->uid));
1105     }
1107     return (0);
1108   }
1110   
1111   function update_new_dn()
1112   {
1113     $pt= "";
1114     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1115       if(!empty($this->personalTitle)){
1116         $pt = $this->personalTitle." ";
1117       }
1118     }
1119     $this->cn= $pt.$this->givenName." ".$this->sn;
1121     /* Permissions for that base? */
1122     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1123       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1124     } else {
1125       /* Don't touch dn, if cn hasn't changed */
1126       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1127           $this->orig_base == $this->base ){
1128         $this->new_dn= $this->dn;
1129       } else {
1130         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1131       }
1132     }
1133   }
1134   
1136   /* Check formular input */
1137   function check()
1138   {
1139     /* Call common method to give check the hook */
1140     $message= plugin::check();
1142     /* Configurable password methods should be configured initially. 
1143      */ 
1144     if($this->last_pw_storage != $this->pw_storage){
1145       $temp= passwordMethod::get_available_methods();
1146       foreach($temp['name'] as $id => $name){
1147         if($name == $this->pw_storage){
1148           if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1149             $message[] = _("The selected password method requires initial configuration!");
1150           }
1151           break;
1152         }
1153       }
1154     }
1156     $this->update_new_dn();
1158     /* Set the new acl base */
1159     if($this->dn == "new") {
1160       $this->set_acl_base($this->base);
1161     }
1163     /* Check if we are allowed to create/move this user 
1164      */
1165     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1166       $message[]= msgPool::permCreate();
1167     }elseif($this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1168       $message[]= msgPool::permMove();
1169     }
1171     /* UID already used? */
1172     $ldap= $this->config->get_ldap_link();
1173     $ldap->cd($this->config->current['BASE']);
1174     $ldap->search("(uid=$this->uid)", array("uid"));
1175     $ldap->fetch();
1176     if ($ldap->count() != 0 && $this->dn == 'new'){
1177       $message[]= msgPool::duplicated(_("Login"));
1178     }
1180     /* In template mode, the uid and givenName are autogenerated... */
1181     if (!$this->is_template){
1182       if ($this->sn == ""){
1183         $message[]= msgPool::required(_("Name"));
1184       }
1185       if ($this->givenName == ""){
1186         $message[]= msgPool::required(_("Given name"));
1187       }
1188       if ($this->uid == ""){
1189         $message[]= msgPool::required(_("Login"));
1190       }
1191       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1192         $ldap->cat($this->new_dn);
1193         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1194           $message[]= msgPool::duplicated(_("Name"));
1195         }
1196       }
1197     }
1199     /* Check for valid input */
1200     if ($this->is_modified && !tests::is_uid($this->uid)){
1202       if (strict_uid_mode()){
1203         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1204       } else {
1205         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1206       }
1207     }
1208     if (!tests::is_url($this->labeledURI)){
1209       $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1210     }
1212     /* Check phone numbers */
1213     if (!tests::is_phone_nr($this->telephoneNumber)){
1214       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1215     }
1216     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1217       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1218     }
1219     if (!tests::is_phone_nr($this->mobile)){
1220       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1221     }
1222     if (!tests::is_phone_nr($this->pager)){
1223       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1224     }
1226     /* Check for reserved characers */
1227     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1228       $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1229     }
1230     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1231       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1232     }
1234     return $message;
1235   }
1238   /* Indicate whether a password change is needed or not */
1239   function password_change_needed()
1240   {
1241     if(in_array("pw_storage",$this->multi_boxes)){
1242       return(TRUE);
1243     }
1244     return($this->pw_storage != $this->last_pw_storage);
1245   }
1248   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1249   function load_picture()
1250   {
1251     $ldap = $this->config->get_ldap_link();
1252     $ldap->cd ($this->dn);
1253     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1255     if((!$data) || ($data == "*removed*")){ 
1257       /* In case we don't get an entry, load a default picture */
1258       $this->set_picture ();//"./images/default.jpg");
1259       $this->jpegPhoto= "*removed*";
1260     }else{
1262       /* Set picture */
1263       $this->photoData= $data;
1264       session::set('binary',$this->photoData);
1265       session::set('binarytype',"image/jpeg");
1266       $this->jpegPhoto= "";
1267     }
1268   }
1271   /* Load a certificate from LDAP, this is going to be simplified later on */
1272   function load_cert()
1273   {
1274     $ds= ldap_connect($this->config->current['SERVER']);
1275     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1276     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1277       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1278       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1279     }
1280     if(isset($this->config->current['TLS']) &&
1281         $this->config->current['TLS'] == "true"){
1283       ldap_start_tls($ds);
1284     }
1286     $r= ldap_bind($ds);
1287     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1289     if ($sr) {
1290       $ei= @ldap_first_entry($ds, $sr);
1291       
1292       if ($ei) {
1293         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1294           $this->userCertificate= "";
1295         } else {
1296           $this->userCertificate= $info[0];
1297         }
1298       }
1299     } else {
1300       $this->userCertificate= "";
1301     }
1303     ldap_unbind($ds);
1304   }
1307   /* Load picture from file to object */
1308   function set_picture($filename ="")
1309   {
1310     if (!is_file($filename) || $filename =="" ){
1311       $filename= "./images/default.jpg";
1312       $this->jpegPhoto= "*removed*";
1313     }
1315     $fd = fopen ($filename, "rb");
1316     $this->photoData= fread ($fd, filesize ($filename));
1317     session::set('binary',$this->photoData);
1318     session::set('binarytype',"image/jpeg");
1319     $this->jpegPhoto= "";
1321     fclose ($fd);
1322   }
1325   /* Load certificate from file to object */
1326   function set_cert($cert, $filename)
1327   {
1328     if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1329     $fd = fopen ($filename, "rb");
1330     if (filesize($filename)>0) {
1331       $this->$cert= fread ($fd, filesize ($filename));
1332       fclose ($fd);
1333       $this->is_modified= TRUE;
1334     } else {
1335       msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1336     }
1337   }
1339   /* Adapt from given 'dn' */
1340   function adapt_from_template($dn, $skip= array())
1341   {
1342     plugin::adapt_from_template($dn, $skip);
1344     /* Get base */
1345     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1347     if($this->governmentmode){
1349       /* Walk through govattrs */
1350       foreach ($this->govattrs as $val){
1352         if (in_array($val, $skip)){
1353           continue;
1354         }
1356         if (isset($this->attrs["$val"][0])){
1358           /* If attribute is set, replace dynamic parts: 
1359              %sn, %givenName and %uid. Fill these in our local variables. */
1360           $value= $this->attrs["$val"][0];
1362           foreach (array("sn", "givenName", "uid") as $repl){
1363             if (preg_match("/%$repl/i", $value)){
1364               $value= preg_replace ("/%$repl/i",
1365                   $this->parent->$repl, $value);
1366             }
1367           }
1368           $this->$val= $value;
1369         }
1370       }
1371     }
1373     /* Get back uid/sn/givenName - only write if nothing's skipped */
1374     if ($this->parent !== NULL && count($skip) == 0){
1375       $this->uid= $this->parent->uid;
1376       $this->sn= $this->parent->sn;
1377       $this->givenName= $this->parent->givenName;
1378     }
1379   }
1381  
1382   /* This avoids that users move themselves out of their rights. 
1383    */
1384   function allowedBasesToMoveTo()
1385   {
1386     /* Get bases */
1387     $bases  = $this->get_allowed_bases();
1388     return($bases);
1389   } 
1392   function getCopyDialog()
1393   {
1394     $str = "";
1396     session::set('binary',$this->photoData); 
1397     session::set('binarytype',"image/jpeg");
1399     /* Get random number for pictures */
1400     srand((double)microtime()*1000000); 
1401     $rand = rand(0, 10000);
1403     $smarty = get_smarty();
1405     $smarty->assign("passwordTodo","clear");
1407     if(isset($_POST['passwordTodo'])){
1408       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1409     }
1411     $smarty->assign("sn",       $this->sn);
1412     $smarty->assign("givenName",$this->givenName);
1413     $smarty->assign("uid",      $this->uid);
1414     $smarty->assign("rand",     $rand);
1415     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1418     $ret = array();
1419     $ret['string'] = $str;
1420     $ret['status'] = "";  
1421     return($ret);
1422   }
1424   function saveCopyDialog()
1425   {
1426     /* Set_acl_base */
1427     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1429     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1430       $this->set_picture($_FILES['picture_file']['tmp_name']);
1431     }
1433     /* Remove picture? */
1434     if (isset($_POST['picture_remove'])){
1435       $this->jpegPhoto= "*removed*";
1436       $this->set_picture ("./images/default.jpg");
1437       $this->is_modified= TRUE;
1438     }
1440     $attrs = array("uid","givenName","sn");
1441     foreach($attrs as $attr){
1442       if(isset($_POST[$attr])){
1443         $this->$attr = $_POST[$attr];
1444       }
1445     } 
1446   }
1449   function PrepareForCopyPaste($source)
1450   {
1451     plugin::PrepareForCopyPaste($source);
1453     /* Reset certificate information addepted from source user
1454        to avoid setting the same user certificate for the destination user. */
1455     $this->userPKCS12= "";
1456     $this->userSMIMECertificate= "";
1457     $this->userCertificate= "";
1458     $this->certificateSerialNumber= "";
1459     $this->old_certificateSerialNumber= "";
1460     $this->old_userPKCS12= "";
1461     $this->old_userSMIMECertificate= "";
1462     $this->old_userCertificate= "";
1463   }
1466   static function plInfo()
1467   {
1468   
1469     $govattrs= array(
1470         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1471         "houseIdentifier"                           =>  _("House identifier"), 
1472         "vocation"                                  =>  _("Vocation"),
1473         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1474         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1475         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1476         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1477         "functionalTitle"                           =>  _("Functional title"),
1478         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1479         "publicVisible"                             =>  _("Public visible"),
1480         "street"                                    =>  _("Street"),
1481         "role"                                      =>  _("Role"),
1482         "postalCode"                                =>  _("Postal code"));
1484     $ret = array(
1485         "plShortName" => _("Generic"),
1486         "plDescription" => _("Generic user settings"),
1487         "plSelfModify"  => TRUE,
1488         "plDepends"     => array(),
1489         "plPriority"    => 1,
1490         "plSection"     => array("personal" => _("My account")),
1491         "plCategory"    => array("users" => array("description" => _("Users"),
1492                                                   "objectClass" => "gosaAccount")),
1494         "plProvidedAcls" => array(
1495           "base"              => _("Base"), 
1496           "userPassword"      => _("User password"), 
1497           "sn"                => _("Surename"),
1498           "givenName"         => _("Given name"),
1499           "uid"               => _("User identification"),
1500           "personalTitle"     => _("Personal title"),
1501           "academicTitle"     => _("Academic title"),
1502           "homePostalAddress" => _("Home postal address"),
1503           "homePhone"         => _("Home phone number"),
1504           "labeledURI"        => _("Homepage"),
1505           "o"                 => _("Organization"),
1506           "ou"                => _("Department"),
1507           "dateOfBirth"       => _("Date of birth"),
1508           "gender"            => _("Gender"),
1509           "preferredLanguage" => _("Preferred language"),
1510           "departmentNumber"  => _("Department number"),
1511           "employeeNumber"    => _("Employee number"),
1512           "employeeType"      => _("Employee type"),
1513           "l"                 => _("Location"),
1514           "st"                => _("State"),
1515           "userPicture"       => _("User picture"),
1516           "roomNumber"        => _("Room number"),
1517           "telephoneNumber"   => _("Telefon number"),
1518           "mobile"            => _("Mobile number"),
1519           "pager"             => _("Pager number"),
1520           "Certificate"        => _("User certificates"),
1522           "postalAddress"                => _("Postal address"),
1523           "facsimileTelephoneNumber"     => _("Fax number"))
1524         );
1526     /* Append government attributes if required */
1527       global $config;
1528     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1529       foreach($govattrs as $attr => $desc){
1530         $ret["plProvidedAcls"][$attr] = $desc;
1531       }
1532     }
1533     return($ret);
1534   }
1536   function get_multi_edit_values()
1537   {
1538     $ret = plugin::get_multi_edit_values();
1539     if(in_array("pw_storage",$this->multi_boxes)){
1540       $ret['pw_storage'] = $this->pw_storage;
1541     }
1542     if(in_array("edit_picture",$this->multi_boxes)){
1543       $ret['jpegPhoto'] = $this->jpegPhoto;
1544       $ret['photoData'] = $this->photoData;
1545       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1546       $ret['old_photoData'] = $this->old_photoData;
1547     }
1548     if(isset($ret['dateOfBirth'])){
1549       unset($ret['dateOfBirth']);
1550     }
1551     if(isset($ret['cn'])){
1552       unset($ret['cn']);
1553     }
1554     $ret['is_modified'] = $this->is_modified;
1555     if(in_array("base",$this->multi_boxes)){
1556       $ret['orig_base']="Changed_by_Multi_Plug";
1557       $ret['base']=$this->base;
1558     }
1559     return($ret); 
1560   }
1563   function multiple_save_object()
1564   {
1565     plugin::multiple_save_object();
1567     /* Get pw_storage mode */
1568     if (isset($_POST['pw_storage'])){
1569       foreach(array("pw_storage") as $val){
1570         if(isset($_POST[$val])){
1571           $data= validate(get_post($val));
1572           if ($data != $this->$val){
1573             $this->is_modified= TRUE;
1574           }
1575           $this->$val= $data;
1576         }
1577       }
1578     }
1579     if(isset($_POST['base'])){
1580       $this->base = get_post('base');
1581     }
1583     if(isset($_POST['user_mulitple_edit'])){
1584       foreach(array("base","pw_storage","edit_picture") as $val){
1585         if(isset($_POST["use_".$val])){
1586           $this->multi_boxes[] = $val;
1587         }
1588       }
1589     }
1590   }
1592   
1593   function multiple_check()
1594   {
1595     /* Call check() to set new_dn correctly ... */
1596     $message = plugin::multiple_check();
1598     /* Set the new acl base */
1599     if($this->dn == "new") {
1600       $this->set_acl_base($this->base);
1601     }
1602     if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1603       $message[]= msgPool::invalid(_("Homepage"));
1604     }
1605     if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1606       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1607     }
1608     if (!tests::is_phone_nr($this->facsimileTelephoneNumber) &&  in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1609       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1610     }
1611     if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1612       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1613     }
1614     if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1615       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1616     }
1617     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1618       $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1619     }
1620     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1621       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1622     }
1623     return($message);
1624   }
1628   function multiple_execute()
1629   {
1630     return($this->execute());
1631   }
1636 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1637 ?>