Code

Updated class user.
[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       }
803       /* Save current cn
804        */
805       $this->cn = $this->givenName." ".$this->sn;
806     }
807   }
809   function rebind($ldap, $referral)
810   {
811     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
812     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
813       $this->error = "Success";
814       $this->hascon=true;
815       $this->reconnect= true;
816       return (0);
817     } else {
818       $this->error = "Could not bind to " . $credentials['ADMIN'];
819       return NULL;
820     }
821   }
823   
824   /* Save data to LDAP, depending on is_account we save or delete */
825   function save()
826   {
827     /* Only force save of changes .... 
828        If this attributes aren't changed, avoid saving.
829      */
830     if($this->gender=="0") $this->gender ="";
831     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
833     /* First use parents methods to do some basic fillup in $this->attrs */
834     plugin::save ();
836     if ($this->use_dob == "1"){
837       /* 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. */
838       if(!is_array($this->attrs['dateOfBirth'])) {
839         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
840       }
841     }
843     /* Remove additional objectClasses */
844     $tmp= array();
845     foreach ($this->attrs['objectClass'] as $key => $set){
846       $found= false;
847       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
848         if (preg_match ("/^$set$/i", $val)){
849           $found= true;
850           break;
851         }
852       }
853       if (!$found){
854         $tmp[]= $set;
855       }
856     }
858     /* Replace the objectClass array. This is done because of the
859        separation into government and normal mode. */
860     $this->attrs['objectClass']= $tmp;
862     /* Add objectClasss for template mode? */
863     if ($this->is_template){
864       $this->attrs['objectClass'][]= "gosaUserTemplate";
865     }
867     /* Hard coded government mode? */
868     if ($this->governmentmode){
869       $this->attrs['objectClass'][]= "ivbbentry";
871       /* Copy standard attributes */
872       foreach ($this->govattrs as $val){
873         if ($this->$val != ""){
874           $this->attrs["$val"]= $this->$val;
875         } elseif (!$this->is_new) {
876           $this->attrs["$val"]= array();
877         }
878       }
880       /* Remove attribute if set to "nein" */
881       if ($this->publicVisible == "nein"){
882         $this->attrs['publicVisible']= array();
883         if($this->is_new){
884           unset($this->attrs['publicVisible']);
885         }else{
886           $this->attrs['publicVisible']=array();
887         }
889       }
891     }
893     /* Special handling for attribute userCertificate needed */
894     if ($this->userCertificate != ""){
895       $this->attrs["userCertificate;binary"]= $this->userCertificate;
896       $remove_userCertificate= false;
897     } else {
898       $remove_userCertificate= true;
899     }
901     /* Special handling for dateOfBirth value */
902     if ($this->use_dob != "1"){
903       if ($this->is_new) {
904         unset($this->attrs["dateOfBirth"]);
905       } else {
906         $this->attrs["dateOfBirth"]= array();
907       }
908     }
909     if (!$this->gender){
910       if ($this->is_new) {
911         unset($this->attrs["gender"]);
912       } else {
913         $this->attrs["gender"]= array();
914       }
915     }
916     if (!$this->preferredLanguage){
917       if ($this->is_new) {
918         unset($this->attrs["preferredLanguage"]);
919       } else {
920         $this->attrs["preferredLanguage"]= array();
921       }
922     }
924     /* Special handling for attribute jpegPhote needed, scale image via
925        image magick to 147x200 pixels and inject resulting data. */
926     if ($this->jpegPhoto == "*removed*"){
927     
928       /* Reset attribute to avoid writing *removed* as value */    
929       $this->attrs["jpegPhoto"] = array();
931     } else {
933       /* Fallback if there's no image magick inside PHP */
934       if (!function_exists("imagick_blob2image")){
935         /* Get temporary file name for conversation */
936         $fname = tempnam (TEMP_DIR, "GOsa");
937   
938         /* Open file and write out photoData */
939         $fp = fopen ($fname, "w");
940         fwrite ($fp, $this->photoData);
941         fclose ($fp);
943         /* Build conversation query. Filename is generated automatically, so
944            we do not need any special security checks. Exec command and save
945            output. For PHP safe mode, you'll need a configuration which respects
946            image magick as executable... */
947         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
948         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
949             $query, "Execute");
950   
951         /* Read data written by convert */
952         $output= "";
953         $sh= popen($query, 'r');
954         while (!feof($sh)){
955           $output.= fread($sh, 4096);
956         }
957         pclose($sh);
959         unlink($fname);
961         /* Save attribute */
962         $this->attrs["jpegPhoto"] = $output;
964       } else {
966         /* Load the new uploaded Photo */
967         if(!$handle  =  imagick_blob2image($this->photoData))  {
968           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
969         }
971         /* Resizing image to 147x200 and blur */
972         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
973           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
974         }
976         /* Converting image to JPEG */
977         if(!imagick_convert($handle,"JPEG")) {
978           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
979         }
981         /* Creating binary Code for the Image */
982         if(!$dump = imagick_image2blob($handle)){
983           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
984         }
986         /* Sending Image */
987         $output=  $dump;
989         /* Save attribute */
990         $this->attrs["jpegPhoto"] = $output;
991       }
993     }
995     /* This only gets called when user is renaming himself */
996     $ldap= $this->config->get_ldap_link();
997     if ($this->dn != $this->new_dn){
999       /* Write entry on new 'dn' */
1000       $this->update_acls($this->dn,$this->new_dn);
1001       $this->move($this->dn, $this->new_dn);
1003       /* Happen to use the new one */
1004       change_ui_dn($this->dn, $this->new_dn);
1005       $this->dn= $this->new_dn;
1006     }
1009     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1010        new entries. So do a check first... */
1011     $ldap->cat ($this->dn, array('dn'));
1012     if ($ldap->fetch()){
1013       $mode= "modify";
1014     } else {
1015       $mode= "add";
1016       $ldap->cd($this->config->current['BASE']);
1017       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1018     }
1020     /* Set password to some junk stuff in case of templates */
1021     if ($this->is_template){
1022       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1023     }
1025     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1026         $this->attributes, "Save via $mode");
1028     /* Finally write data with selected 'mode' */
1029     $this->cleanup();
1031     if(isset($this->attrs['preferredLanguage'])){
1032       $ui = session::get('ui');
1033       $ui->language = $this->preferredLanguage;
1034       session::set('ui',$ui);
1035       session::set('Last_init_lang',"update");
1036     }
1038     $ldap->cd ($this->dn);
1039     $ldap->$mode ($this->attrs);
1040     if (!$ldap->success()){
1041       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1042       return (1);
1043     }
1045     /* Remove ACL dependencies too */
1046     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1047       $tmp = new acl($this->config,$this->parent,$this->dn);
1048       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1049     }
1051     if($mode == "modify"){
1052       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1053     }else{
1054       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1055     }
1057     /* Remove cert? 
1058        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1059        to work around myself. */
1060     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1062       /* Reset array, assemble new, this should be reworked */
1063       $this->attrs= array();
1064       $this->attrs['userCertificate;binary']= array();
1066       /* Prepare connection */
1067       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1068         die ("Could not connect to LDAP server");
1069       }
1070       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1071       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1072         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1073         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1074       }
1075       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1076         ldap_start_tls($ds);
1077       }
1078       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1079               $this->config->current['PASSWORD']))) {
1080         die ("Could not bind to LDAP");
1081       }
1083       /* Modify using attrs */
1084       ldap_mod_del($ds,$this->dn,$this->attrs);
1085       ldap_close($ds);
1086     }
1088     /* If needed, let the password method do some cleanup */
1089     if ($this->pw_storage != $this->last_pw_storage){
1090       $tmp = new passwordMethod($this->config);
1091       $available = $tmp->get_available_methods();
1092       if (in_array_ics($this->last_pw_storage, $available['name'])){
1093         $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1094         $test->attrs= $this->attrs;
1095         $test->remove_from_parent();
1096       }
1097     }
1099     /* Maybe the current password method want's to do some changes... */
1100     if (is_object($this->pwObject)){
1101       $this->pwObject->save($this->dn);
1102     }
1104     /* Optionally execute a command after we're done */
1105     if ($mode == "add"){
1106       $this->handle_post_events("add", array("uid" => $this->uid));
1107     } elseif ($this->is_modified){
1108       $this->handle_post_events("modify", array("uid" => $this->uid));
1109     }
1111     return (0);
1112   }
1114   
1115   function update_new_dn()
1116   {
1117     $pt= "";
1118     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1119       if(!empty($this->personalTitle)){
1120         $pt = $this->personalTitle." ";
1121       }
1122     }
1123     $this->cn= $pt.$this->givenName." ".$this->sn;
1125     /* Permissions for that base? */
1126     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1127       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1128     } else {
1129       /* Don't touch dn, if cn hasn't changed */
1130       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1131           $this->orig_base == $this->base ){
1132         $this->new_dn= $this->dn;
1133       } else {
1134         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1135       }
1136     }
1137   }
1138   
1140   /* Check formular input */
1141   function check()
1142   {
1143     /* Call common method to give check the hook */
1144     $message= plugin::check();
1146     /* Configurable password methods should be configured initially. 
1147      */ 
1148     if($this->last_pw_storage != $this->pw_storage){
1149       $temp= passwordMethod::get_available_methods();
1150       foreach($temp['name'] as $id => $name){
1151         if($name == $this->pw_storage){
1152           if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1153             $message[] = _("The selected password method requires initial configuration!");
1154           }
1155           break;
1156         }
1157       }
1158     }
1160     $this->update_new_dn();
1162     /* Set the new acl base */
1163     if($this->dn == "new") {
1164       $this->set_acl_base($this->base);
1165     }
1167     /* Check if we are allowed to create/move this user 
1168      */
1169     
1170     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1171       $message[]= msgPool::permCreate();
1172     }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1173       $message[]= msgPool::permMove();
1174     }
1176     /* UID already used? */
1177     $ldap= $this->config->get_ldap_link();
1178     $ldap->cd($this->config->current['BASE']);
1179     $ldap->search("(uid=$this->uid)", array("uid"));
1180     $ldap->fetch();
1181     if ($ldap->count() != 0 && $this->dn == 'new'){
1182       $message[]= msgPool::duplicated(_("Login"));
1183     }
1185     /* In template mode, the uid and givenName are autogenerated... */
1186     if ($this->sn == ""){
1187       $message[]= msgPool::required(_("Name"));
1188     }
1190     if (!$this->is_template){
1191       if ($this->givenName == ""){
1192         $message[]= msgPool::required(_("Given name"));
1193       }
1194       if ($this->uid == ""){
1195         $message[]= msgPool::required(_("Login"));
1196       }
1197       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1198         $ldap->cat($this->new_dn);
1199         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1200           $message[]= msgPool::duplicated(_("Name"));
1201         }
1202       }
1203     }
1205     /* Check for valid input */
1206     if ($this->is_modified && !tests::is_uid($this->uid)){
1208       if (strict_uid_mode()){
1209         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1210       } else {
1211         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1212       }
1213     }
1214     if (!tests::is_url($this->labeledURI)){
1215       $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1216     }
1218     /* Check phone numbers */
1219     if (!tests::is_phone_nr($this->telephoneNumber)){
1220       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1221     }
1222     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1223       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1224     }
1225     if (!tests::is_phone_nr($this->mobile)){
1226       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1227     }
1228     if (!tests::is_phone_nr($this->pager)){
1229       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1230     }
1232     /* Check for reserved characers */
1233     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1234       $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1235     }
1236     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1237       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1238     }
1240     return $message;
1241   }
1244   /* Indicate whether a password change is needed or not */
1245   function password_change_needed()
1246   {
1247     if(in_array("pw_storage",$this->multi_boxes)){
1248       return(TRUE);
1249     }
1250     return($this->pw_storage != $this->last_pw_storage);
1251   }
1254   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1255   function load_picture()
1256   {
1257     $ldap = $this->config->get_ldap_link();
1258     $ldap->cd ($this->dn);
1259     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1261     if((!$data) || ($data == "*removed*")){ 
1263       /* In case we don't get an entry, load a default picture */
1264       $this->set_picture ();//"./images/default.jpg");
1265       $this->jpegPhoto= "*removed*";
1266     }else{
1268       /* Set picture */
1269       $this->photoData= $data;
1270       session::set('binary',$this->photoData);
1271       session::set('binarytype',"image/jpeg");
1272       $this->jpegPhoto= "";
1273     }
1274   }
1277   /* Load a certificate from LDAP, this is going to be simplified later on */
1278   function load_cert()
1279   {
1280     $ds= ldap_connect($this->config->current['SERVER']);
1281     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1282     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1283       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1284       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1285     }
1286     if(isset($this->config->current['TLS']) &&
1287         $this->config->current['TLS'] == "true"){
1289       ldap_start_tls($ds);
1290     }
1292     $r= ldap_bind($ds);
1293     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1295     if ($sr) {
1296       $ei= @ldap_first_entry($ds, $sr);
1297       
1298       if ($ei) {
1299         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1300           $this->userCertificate= "";
1301         } else {
1302           $this->userCertificate= $info[0];
1303         }
1304       }
1305     } else {
1306       $this->userCertificate= "";
1307     }
1309     ldap_unbind($ds);
1310   }
1313   /* Load picture from file to object */
1314   function set_picture($filename ="")
1315   {
1316     if (!is_file($filename) || $filename =="" ){
1317       $filename= "./images/default.jpg";
1318       $this->jpegPhoto= "*removed*";
1319     }
1321     $fd = fopen ($filename, "rb");
1322     $this->photoData= fread ($fd, filesize ($filename));
1323     session::set('binary',$this->photoData);
1324     session::set('binarytype',"image/jpeg");
1325     $this->jpegPhoto= "";
1327     fclose ($fd);
1328   }
1331   /* Load certificate from file to object */
1332   function set_cert($cert, $filename)
1333   {
1334     if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1335     $fd = fopen ($filename, "rb");
1336     if (filesize($filename)>0) {
1337       $this->$cert= fread ($fd, filesize ($filename));
1338       fclose ($fd);
1339       $this->is_modified= TRUE;
1340     } else {
1341       msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1342     }
1343   }
1345   /* Adapt from given 'dn' */
1346   function adapt_from_template($dn, $skip= array())
1347   {
1348     plugin::adapt_from_template($dn, $skip);
1350     /* Get base */
1351     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1353     if($this->governmentmode){
1355       /* Walk through govattrs */
1356       foreach ($this->govattrs as $val){
1358         if (in_array($val, $skip)){
1359           continue;
1360         }
1362         if (isset($this->attrs["$val"][0])){
1364           /* If attribute is set, replace dynamic parts: 
1365              %sn, %givenName and %uid. Fill these in our local variables. */
1366           $value= $this->attrs["$val"][0];
1368           foreach (array("sn", "givenName", "uid") as $repl){
1369             if (preg_match("/%$repl/i", $value)){
1370               $value= preg_replace ("/%$repl/i",
1371                   $this->parent->$repl, $value);
1372             }
1373           }
1374           $this->$val= $value;
1375         }
1376       }
1377     }
1379     /* Get back uid/sn/givenName - only write if nothing's skipped */
1380     if ($this->parent !== NULL && count($skip) == 0){
1381       $this->uid= $this->parent->uid;
1382       $this->sn= $this->parent->sn;
1383       $this->givenName= $this->parent->givenName;
1384     }
1385   }
1387  
1388   /* This avoids that users move themselves out of their rights. 
1389    */
1390   function allowedBasesToMoveTo()
1391   {
1392     /* Get bases */
1393     $bases  = $this->get_allowed_bases();
1394     return($bases);
1395   } 
1398   function getCopyDialog()
1399   {
1400     $str = "";
1402     session::set('binary',$this->photoData); 
1403     session::set('binarytype',"image/jpeg");
1405     /* Get random number for pictures */
1406     srand((double)microtime()*1000000); 
1407     $rand = rand(0, 10000);
1409     $smarty = get_smarty();
1411     $smarty->assign("passwordTodo","clear");
1413     if(isset($_POST['passwordTodo'])){
1414       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1415     }
1417     $smarty->assign("sn",       $this->sn);
1418     $smarty->assign("givenName",$this->givenName);
1419     $smarty->assign("uid",      $this->uid);
1420     $smarty->assign("rand",     $rand);
1421     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1424     $ret = array();
1425     $ret['string'] = $str;
1426     $ret['status'] = "";  
1427     return($ret);
1428   }
1430   function saveCopyDialog()
1431   {
1432     /* Set_acl_base */
1433     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1435     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1436       $this->set_picture($_FILES['picture_file']['tmp_name']);
1437     }
1439     /* Remove picture? */
1440     if (isset($_POST['picture_remove'])){
1441       $this->jpegPhoto= "*removed*";
1442       $this->set_picture ("./images/default.jpg");
1443       $this->is_modified= TRUE;
1444     }
1446     $attrs = array("uid","givenName","sn");
1447     foreach($attrs as $attr){
1448       if(isset($_POST[$attr])){
1449         $this->$attr = $_POST[$attr];
1450       }
1451     } 
1452   }
1455   function PrepareForCopyPaste($source)
1456   {
1457     plugin::PrepareForCopyPaste($source);
1459     /* Reset certificate information addepted from source user
1460        to avoid setting the same user certificate for the destination user. */
1461     $this->userPKCS12= "";
1462     $this->userSMIMECertificate= "";
1463     $this->userCertificate= "";
1464     $this->certificateSerialNumber= "";
1465     $this->old_certificateSerialNumber= "";
1466     $this->old_userPKCS12= "";
1467     $this->old_userSMIMECertificate= "";
1468     $this->old_userCertificate= "";
1469   }
1472   static function plInfo()
1473   {
1474   
1475     $govattrs= array(
1476         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1477         "houseIdentifier"                           =>  _("House identifier"), 
1478         "vocation"                                  =>  _("Vocation"),
1479         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1480         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1481         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1482         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1483         "functionalTitle"                           =>  _("Functional title"),
1484         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1485         "publicVisible"                             =>  _("Public visible"),
1486         "street"                                    =>  _("Street"),
1487         "role"                                      =>  _("Role"),
1488         "postalCode"                                =>  _("Postal code"));
1490     $ret = array(
1491         "plShortName" => _("Generic"),
1492         "plDescription" => _("Generic user settings"),
1493         "plSelfModify"  => TRUE,
1494         "plDepends"     => array(),
1495         "plPriority"    => 1,
1496         "plSection"     => array("personal" => _("My account")),
1497         "plCategory"    => array("users" => array("description" => _("Users"),
1498                                                   "objectClass" => "gosaAccount")),
1500         "plProvidedAcls" => array(
1501           "base"              => _("Base"), 
1502           "userPassword"      => _("User password"), 
1503           "sn"                => _("Surname"),
1504           "givenName"         => _("Given name"),
1505           "uid"               => _("User identification"),
1506           "personalTitle"     => _("Personal title"),
1507           "academicTitle"     => _("Academic title"),
1508           "homePostalAddress" => _("Home postal address"),
1509           "homePhone"         => _("Home phone number"),
1510           "labeledURI"        => _("Homepage"),
1511           "o"                 => _("Organization"),
1512           "ou"                => _("Department"),
1513           "dateOfBirth"       => _("Date of birth"),
1514           "gender"            => _("Gender"),
1515           "preferredLanguage" => _("Preferred language"),
1516           "departmentNumber"  => _("Department number"),
1517           "employeeNumber"    => _("Employee number"),
1518           "employeeType"      => _("Employee type"),
1519           "l"                 => _("Location"),
1520           "st"                => _("State"),
1521           "userPicture"       => _("User picture"),
1522           "roomNumber"        => _("Room number"),
1523           "telephoneNumber"   => _("Telefon number"),
1524           "mobile"            => _("Mobile number"),
1525           "pager"             => _("Pager number"),
1526           "Certificate"        => _("User certificates"),
1528           "postalAddress"                => _("Postal address"),
1529           "facsimileTelephoneNumber"     => _("Fax number"))
1530         );
1532     /* Append government attributes if required */
1533       global $config;
1534     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1535       foreach($govattrs as $attr => $desc){
1536         $ret["plProvidedAcls"][$attr] = $desc;
1537       }
1538     }
1539     return($ret);
1540   }
1542   function get_multi_edit_values()
1543   {
1544     $ret = plugin::get_multi_edit_values();
1545     if(in_array("pw_storage",$this->multi_boxes)){
1546       $ret['pw_storage'] = $this->pw_storage;
1547     }
1548     if(in_array("edit_picture",$this->multi_boxes)){
1549       $ret['jpegPhoto'] = $this->jpegPhoto;
1550       $ret['photoData'] = $this->photoData;
1551       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1552       $ret['old_photoData'] = $this->old_photoData;
1553     }
1554     if(isset($ret['dateOfBirth'])){
1555       unset($ret['dateOfBirth']);
1556     }
1557     if(isset($ret['cn'])){
1558       unset($ret['cn']);
1559     }
1560     $ret['is_modified'] = $this->is_modified;
1561     if(in_array("base",$this->multi_boxes)){
1562       $ret['orig_base']="Changed_by_Multi_Plug";
1563       $ret['base']=$this->base;
1564     }
1565     return($ret); 
1566   }
1569   function multiple_save_object()
1570   {
1571     plugin::multiple_save_object();
1573     /* Get pw_storage mode */
1574     if (isset($_POST['pw_storage'])){
1575       foreach(array("pw_storage") as $val){
1576         if(isset($_POST[$val])){
1577           $data= validate(get_post($val));
1578           if ($data != $this->$val){
1579             $this->is_modified= TRUE;
1580           }
1581           $this->$val= $data;
1582         }
1583       }
1584     }
1585     if(isset($_POST['base'])){
1586       $this->base = get_post('base');
1587     }
1589     if(isset($_POST['user_mulitple_edit'])){
1590       foreach(array("base","pw_storage","edit_picture") as $val){
1591         if(isset($_POST["use_".$val])){
1592           $this->multi_boxes[] = $val;
1593         }
1594       }
1595     }
1596   }
1598   
1599   function multiple_check()
1600   {
1601     /* Call check() to set new_dn correctly ... */
1602     $message = plugin::multiple_check();
1604     /* Set the new acl base */
1605     if($this->dn == "new") {
1606       $this->set_acl_base($this->base);
1607     }
1608     if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1609       $message[]= msgPool::invalid(_("Homepage"));
1610     }
1611     if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1612       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1613     }
1614     if (!tests::is_phone_nr($this->facsimileTelephoneNumber) &&  in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1615       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1616     }
1617     if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1618       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1619     }
1620     if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1621       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1622     }
1623     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1624       $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1625     }
1626     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1627       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1628     }
1629     return($message);
1630   }
1634   function multiple_execute()
1635   {
1636     return($this->execute());
1637   }
1642 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1643 ?>