Code

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