Code

Added initial dojo support
[gosa.git] / plugins / personal / generic / class_user.inc
1 <?php
2 /*!
3   \brief   user plugin
4   \author  Cajus Pollmeier <pollmeier@gonicus.de>
5   \version 2.00
6   \date    24.07.2003
8   This class provides the functionality to read and write all attributes
9   relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
10   from/to the LDAP. It does syntax checking and displays the formulars required.
11  */
13 class user extends plugin
14 {
15   /* Definitions */
16   var $plHeadline= "Generic";
17   var $plDescription= "This does something";
19   /* CLI vars */
20   var $cli_summary= "Handling of GOsa's user base object";
21   var $cli_description= "Some longer text\nfor help";
22   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
24   /* Plugin specific values */
25   var $base= "";
26   var $orig_base= "";
27   var $cn= "";
28   var $new_dn= "";
29   var $personalTitle= "";
30   var $academicTitle= "";
31   var $homePostalAddress= "";
32   var $homePhone= "";
33   var $labeledURI= "";
34   var $o= "";
35   var $ou= "";
36   var $departmentNumber= "";
37   var $employeeNumber= "";
38   var $employeeType= "";
39   var $roomNumber= "";
40   var $telephoneNumber= "";
41   var $facsimileTelephoneNumber= "";
42   var $mobile= "";
43   var $pager= "";
44   var $l= "";
45   var $st= "";
46   var $postalAddress= "";
47   var $dateOfBirth;
48   var $use_dob= "0";
49   var $gender="0";
50   var $preferredLanguage="0";
52   var $jpegPhoto= "*removed*";
53   var $photoData= "";
54   var $old_jpegPhoto= "";
55   var $old_photoData= "";
56   var $cert_dialog= FALSE;
57   var $picture_dialog= FALSE;
59   var $userPKCS12= "";
60   var $userSMIMECertificate= "";
61   var $userCertificate= "";
62   var $certificateSerialNumber= "";
63   var $old_certificateSerialNumber= "";
64   var $old_userPKCS12= "";
65   var $old_userSMIMECertificate= "";
66   var $old_userCertificate= "";
68   var $gouvernmentOrganizationalUnit= "";
69   var $houseIdentifier= "";
70   var $street= "";
71   var $postalCode= "";
72   var $vocation= "";
73   var $ivbbLastDeliveryCollective= "";
74   var $gouvernmentOrganizationalPersonLocality= "";
75   var $gouvernmentOrganizationalUnitDescription= "";
76   var $gouvernmentOrganizationalUnitSubjectArea= "";
77   var $functionalTitle= "";
78   var $role= "";
79   var $publicVisible= "";
81   var $orig_dn;
82   var $dialog;
84   /* variables to trigger password changes */
85   var $pw_storage= "crypt";
86   var $last_pw_storage= "unset";
87   var $had_userCertificate= FALSE;
89   var $view_logged = FALSE;
91   /* attribute list for save action */
92   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
93       "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
94       "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
95       "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
96       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
98   var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
99       "gosaAccount");
101   /* attributes that are part of the government mode */
102   var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
103       "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
104       "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
105       "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
106       "postalCode");
108   var $multiple_support = TRUE;
109   var $multiple_support_active  = FALSE;
110   var $selected_edit_values  = array();
111   var $multiple_user_handles  = array();
113   /* constructor, if 'dn' is set, the node loads the given
114      'dn' from LDAP */
115   function user (&$config, $dn= NULL)
116   {
118     $this->config= $config;
119     /* Configuration is fine, allways */
120     if ($this->config->current['GOVERNMENTMODE']){
121       $this->attributes=array_merge($this->attributes,$this->govattrs);
122     }
124     /* Load base attributes */
125     plugin::plugin ($config, $dn);
127     $this->orig_dn  = $this->dn;
128     $this->new_dn   = $this->dn;
130     $this->new_dn = $dn;
132     if ($this->config->current['GOVERNMENTMODE']){
133       /* Fix public visible attribute if unset */
134       if (!isset($this->attrs['publicVisible'])){
135         $this->publicVisible == "nein";
136       }
137     }
139     /* Load government mode attributes */
140     if ($this->config->current['GOVERNMENTMODE']){
141       /* Copy all attributs */
142       foreach ($this->govattrs as $val){
143         if (isset($this->attrs["$val"][0])){
144           $this->$val= $this->attrs["$val"][0];
145         }
146       }
147     }
149     /* Create me for new accounts */
150     if ($dn == "new"){
151       $this->is_account= TRUE;
152     }
154     /* Make hash default to md5 if not set in config */
155     if (!isset($this->config->current['HASH'])){
156       $hash= "md5";
157     } else {
158       $hash= $this->config->current['HASH'];
159     }
161     /* Load data from LDAP? */
162     if ($dn !== NULL){
164       /* Do base conversation */
165       if ($this->dn == "new"){
166         $ui= get_userinfo();
167         $this->base= dn2base($ui->dn);
168       } else {
169         $this->base= dn2base($dn);
170       }
172       /* get password storage type */
173       if (isset ($this->attrs['userPassword'][0])){
174         /* Initialize local array */
175         $matches= array();
176         if (preg_match ("/^{([^}]+)}(.+)/", $this->attrs['userPassword'][0], $matches)){
177           $this->pw_storage= strtolower($matches[1]);
178         } else {
179           if ($this->attrs['userPassword'][0] != ""){
180             $this->pw_storage= "clear";
181           } else {
182             $this->pw_storage= $hash;
183           }
184         }
185       } else {
186         /* Preset with vaule from configuration */
187         $this->pw_storage= $hash;
188       }
190       /* Load extra attributes: certificate and picture */
191       $this->load_cert();
192       $this->load_picture();
193       if ($this->userCertificate != ""){
194         $this->had_userCertificate= TRUE;
195       }
196     }
198     /* Reset password storage indicator, used by password_change_needed() */
199     if ($dn == "new"){
200       $this->last_pw_storage= "unset";
201     } else {
202       $this->last_pw_storage= $this->pw_storage;
203     }
205     /* Generate dateOfBirth entry */
206     if (isset ($this->attrs['dateOfBirth'])){
207       /* This entry is ISO 8601 conform */
208       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
209     
210       $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
211       $this->use_dob= "1";
212     } else {
213       $this->use_dob= "0";
214     }
216     /* Put gender attribute to upper case */
217     if (isset ($this->attrs['gender'])){
218       $this->gender= strtoupper($this->attrs['gender'][0]);
219     }
220  
221     $this->orig_base = $this->base;
222   }
227   /* execute generates the html output for this node */
228   function execute()
229   {
230     /* Call parent execute */
231     plugin::execute();
233     if($this->multiple_support_active){
234       return($this->execute_multiple());
235     }
236     /* Log view */
237     if($this->is_account && !$this->view_logged){
238       $this->view_logged = TRUE;
239       new log("view","users/".get_class($this),$this->dn);
240     }
242     $smarty= get_smarty();
244     /* Fill calendar */
245     if ($this->dateOfBirth == "0"){
246       $date= getdate();
247     } else {
248       if(is_array($this->dateOfBirth)){
249         $date = $this->dateOfBirth;
250   
251         // Trigger on dates like 1985-04-01, getdate only understands timestamps
252       } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
253         $date= getdate(strtotime($this->dateOfBirth));
255       } else {
256         $date = getdate($this->dateOfBirth);
257       }
258     }
260     $days= array();
261     for($d= 1; $d<32; $d++){
262       $days[$d]= $d;
263     }
264     $years= array();
266     if(($date['year']-100)<1901){
267       $start = 1901;
268     }else{
269       $start = $date['year']-100;
270     }
272     $end = $start +100;
273     
274     for($y= $start; $y<=$end; $y++){
275       $years[]= $y;
276     }
277     $years['-']= "-&nbsp;";
278     $months= array(_("January"), _("February"), _("March"), _("April"),
279         _("May"), _("June"), _("July"), _("August"), _("September"),
280         _("October"), _("November"), _("December"), '-' => '-&nbsp;');
281     $smarty->assign("day", $date["mday"]);
282     $smarty->assign("days", $days);
283     $smarty->assign("months", $months);
284     $smarty->assign("month", $date["mon"]-1);
285     $smarty->assign("years", $years);
286     $smarty->assign("year", $date["year"]);
288     /* Assign uid regex for dojo */
289     $smarty->assign("uid_regex", get_uid_regexp());
290     if (strict_uid_mode()){
291       $smarty->assign("uid_invalid_message", _("Please use only a-z, 0-9, _ or - as valid characters"));
292     } else {
293       $smarty->assign("uid_invalid_message", _("Please use only a-z, A-Z, 0-9, ., space, _ or - as valid characters"));
294     }
296     /* Assign sex */
297     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
298     $smarty->assign("gender_list", $sex);
300     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
301     $smarty->assign("preferredLanguage_list", $language);
303     /* Get random number for pictures */
304     srand((double)microtime()*1000000); 
305     $smarty->assign("rand", rand(0, 10000));
308     /* Do we represent a valid gosaAccount? */
309     if (!$this->is_account){
310       echo "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
311         _("This account has no valid GOsa extensions.")."</b>";
312       return;
313     }
315     /* Base select dialog */
316     $once = true;
317     foreach($_POST as $name => $value){
318       if(preg_match("/^chooseBase/",$name) && $once){
319         $once = false;
320         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
321         $this->dialog->setCurrentBase($this->base);
322       }
323     }
325     /* Dialog handling */
326     if(is_object($this->dialog)){
327       /* Must be called before save_object */
328       $this->dialog->save_object();
329    
330       if($this->dialog->isClosed()){
331         $this->dialog = false;
332       }elseif($this->dialog->isSelected()){
334         /* check if selected base is allowed to move to / create a new object */
335         $tmp = $this->get_allowed_bases();
336         if(isset($tmp[$this->dialog->isSelected()])){
337           $this->base = $this->dialog->isSelected();
338         }
339         $this->dialog= false;
340       }else{
341         return($this->dialog->execute());
342       }
343     }
345     /* Want picture edit dialog? */
346     if($this->acl_is_writeable("userPicture")) {
347       if (isset($_POST['edit_picture'])){
348         /* Save values for later recovery, in case some presses
349            the cancel button. */
350         $this->old_jpegPhoto= $this->jpegPhoto;
351         $this->old_photoData= $this->photoData;
352         $this->picture_dialog= TRUE;
353         $this->dialog= TRUE;
354       }
355     }
357     /* Remove picture? */
358     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))) ){
359       if (isset($_POST['picture_remove'])){
360         $this->set_picture ();
361         $this->jpegPhoto= "*removed*";
362         $this->is_modified= TRUE;
363         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
364       }
365     }
367     /* Save picture */
368     if (isset($_POST['picture_edit_finish'])){
370       /* Check for clean upload */
371       if ($_FILES['picture_file']['name'] != ""){
372         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
373           print_red(_("The specified file has not been uploaded via HTTP POST! Aborted."));
374         }else{
375           /* Activate new picture */
376           $this->set_picture($_FILES['picture_file']['tmp_name']);
377         }
378       }
379       $this->picture_dialog= FALSE;
380       $this->dialog= FALSE;
381       $this->is_modified= TRUE;
382     }
385     /* Cancel picture */
386     if (isset($_POST['picture_edit_cancel'])){
388       /* Restore values */
389       $this->jpegPhoto= $this->old_jpegPhoto;
390       $this->photoData= $this->old_photoData;
392       /* Update picture */
393       $_SESSION['binary']= $this->photoData;
394       $_SESSION['binarytype']= "image/jpeg";
395       $this->picture_dialog= FALSE;
396       $this->dialog= FALSE;
397     }
399     /* Toggle dateOfBirth information */
400     if (isset($_POST['set_dob'])){
401       $this->use_dob= ($this->use_dob == "0")?"1":"0";
402     }
405     /* Want certificate= */
406     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
408       /* Save original values for later reconstruction */
409       foreach (array("certificateSerialNumber", "userCertificate",
410             "userSMIMECertificate", "userPKCS12") as $val){
412         $oval= "old_$val";
413         $this->$oval= $this->$val;
414       }
416       $this->cert_dialog= TRUE;
417       $this->dialog= TRUE;
418     }
421     /* Cancel certificate dialog */
422     if (isset($_POST['cert_edit_cancel'])){
424       /* Restore original values in case of 'cancel' */
425       foreach (array("certificateSerialNumber", "userCertificate",
426             "userSMIMECertificate", "userPKCS12") as $val){
428         $oval= "old_$val";
429         $this->$val= $this->$oval;
430       }
431       $this->cert_dialog= FALSE;
432       $this->dialog= FALSE;
433     }
436     /* Remove certificate? */
437     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
438       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
439         if (isset($_POST["remove_$val"])){
441           /* Reset specified cert*/
442           $this->$val= "";
443           $this->is_modified= TRUE;
444         }
445       }
446     }
448     /* Upload new cert and close dialog? */     
449     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
450       if (isset($_POST['cert_edit_finish'])){
452         /* for all certificates do */
453         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
454             as $val){
456           /* Check for clean upload */
457           if (array_key_exists($val."_file", $_FILES) &&
458               array_key_exists('name', $_FILES[$val."_file"]) &&
459               $_FILES[$val."_file"]['name'] != "" &&
460               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
461             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
462           }
463         }
465         /* Save serial number */
466         if (isset($_POST["certificateSerialNumber"]) &&
467             $_POST["certificateSerialNumber"] != ""){
469           if (!is_id($_POST["certificateSerialNumber"])){
470             print_red (_("Please enter a valid serial number"));
472             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
473               if ($this->$cert != ""){
474                 $smarty->assign("$cert"."_state", "true");
475               } else {
476                 $smarty->assign("$cert"."_state", "");
477               }
478             }
479             return ($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
480           }
482           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
483           $this->is_modified= TRUE;
484         }
486         $this->cert_dialog= FALSE;
487         $this->dialog= FALSE;
488       }
489     }
490     /* Display picture dialog */
491     if ($this->picture_dialog){
492       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
493     }
495     /* Display cert dialog */
496     if ($this->cert_dialog){
497       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
498       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
500       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
501         if ($this->$cert != ""){
502           /* import certificate */
503           $certificate = new certificate;
504           $certificate->import($this->$cert);
505       
506           /* Read out data*/
507           $timeto   = $certificate->getvalidto_date();
508           $timefrom = $certificate->getvalidfrom_date();
509          
510           
511           /* Additional info if start end time is '0' */
512           $add_str_info = "";
513           if($timeto == 0 && $timefrom == 0){
514             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
515           }
517           $str = "<table summary=\"\" border=0>
518                     <tr>
519                       <td style='vertical-align:top'>CN</td>
520                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
521                     </tr>
522                   </table><br>".
524                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
525                         "<b>".date('d M Y',$timefrom)."</b>",
526                         "<b>".date('d M Y',$timeto)."</b>",
527                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
528                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
530           $smarty->assign($cert."info",$str);
531           $smarty->assign($cert."_state","true");
532         } else {
533           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
534           $smarty->assign($cert."_state","");
535         }
536       }
537       $smarty->assign("governmentmode", "false");
538       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
539     }
541     /* Prepare password hashes */
542     if ($this->pw_storage == ""){
543       $this->pw_storage= $this->config->current['HASH'];
544     }
546     $temp= passwordMethod::get_available_methods();
547     $hashes = $temp['name'];
548     $test= new $temp[$this->pw_storage]($this->config);
549     $is_configurable= $test->is_configurable();
550     
551     /* Load attributes and acl's */
552     $ui =get_userinfo();
553     foreach($this->attributes as $val){
554       $smarty->assign("$val", $this->$val);
555     }
557     /* Set acls */
558     $tmp = $this->plinfo();
559     foreach($tmp['plProvidedAcls'] as $val => $translation){
560       $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
561     }
563     $smarty->assign("pwmode", $hashes);
564     $smarty->assign("pwmode_select", $this->pw_storage);
565     $smarty->assign("pw_configurable", $is_configurable);
566     $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !isset($_SESSION['edit']))));
567     $smarty->assign("base_select",      $this->base);
568     $smarty->assign("CertificatesACL",  $this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
569     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
570     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
572     /* Create base acls */
573     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
575     /* Save government mode attributes */
576     if (isset($this->config->current['GOVERNMENTMODE']) &&
577         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
578       $smarty->assign("governmentmode", "true");
579       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
580           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
581       $smarty->assign("ivbbmodes", $ivbbmodes);
582       foreach ($this->govattrs as $val){
583         $smarty->assign("$val", $this->$val);
584         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
585       }
586     } else {
587       $smarty->assign("governmentmode", "false");
588     }
590     /* Special mode for uid */
591     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])));
592     if (isset ($this->dn)){
593       if ($this->dn != "new"){
594         $uidACL= preg_replace("/w/","",$uidACL);
595       }
596     }  else {
597       $uidACL= preg_replace("/w/","",$uidACL);
598     }
599     
600     $smarty->assign("uidACL", $uidACL);
601     $smarty->assign("is_template", $this->is_template);
602     $smarty->assign("use_dob", $this->use_dob);
604     if (isset($this->parent)){
605       if (isset($this->parent->by_object['phoneAccount']) &&
606           $this->parent->by_object['phoneAccount']->is_account){
607         $smarty->assign("has_phoneaccount", "true");
608       } else {
609         $smarty->assign("has_phoneaccount", "false");
610       }
611     } else {
612       $smarty->assign("has_phoneaccount", "false");
613     }
614     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
615   }
618   /* remove object from parent */
619   function remove_from_parent()
620   {
621     $ldap= $this->config->get_ldap_link();
622     $ldap->rmdir ($this->dn);
623     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/generic account with dn '%s' failed."),$this->dn));
624   
625     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
626   
627     /* Delete references to groups */
628     $ldap->cd ($this->config->current['BASE']);
629     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
630     while ($ldap->fetch()){
631       $g= new group($this->config, $ldap->getDN());
632       $g->removeUser($this->uid);
633       $g->save ();
634     }
636     /* Delete references to object groups */
637     $ldap->cd ($this->config->current['BASE']);
638     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
639     while ($ldap->fetch()){
640       $og= new ogroup($this->config, $ldap->getDN());
641       unset($og->member[$this->dn]);
642       $og->save ();
643     }
645     /* If needed, let the password method do some cleanup */
646     $tmp = new passwordMethod($_SESSION['config']);
647     $available = $tmp->get_available_methods();
648     if (in_array_ics($this->pw_storage, $available['name'])){
649       $test= new $available[$this->pw_storage]($this->config);
650       $test->attrs= $this->attrs;
651       $test->dn= $this->dn;
652       $test->remove_from_parent();
653     }
655     /* Remove ACL dependencies too */
656     $tmp = new acl($this->config,$this->parent,$this->dn);
657     $tmp->remove_acl();
659     /* Optionally execute a command after we're done */
660     $this->handle_post_events("remove",array("uid" => $this->uid));
661   }
664   /* Save data to object */
665   function save_object()
666   {
667     if (isset($_POST['multiple_user_posted'])){
668       $this->save_object_multiple();
669     }
670     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
672       /* Make a backup of the current selected base */
673       $base_tmp = $this->base;
675       /* Parents save function */
676       plugin::save_object ();
678       /* Save government mode attributes */
679       if ($this->config->current['GOVERNMENTMODE']){
680         foreach ($this->govattrs as $val){
681           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !isset($_SESSION['edit']))) && isset($_POST["$val"])){
682             $data= stripcslashes($_POST["$val"]);
683             if ($data != $this->$val){
684               $this->is_modified= TRUE;
685             }
686             $this->$val= $data;
687           }
688         }
689       }
691       /* In template mode, the uid is autogenerated... */
692       if ($this->is_template){
693         $this->uid= strtolower($this->sn);
694         $this->givenName= $this->sn;
695       }
697       /* Save base and pw_storage, since these are no LDAP attributes */
698       if (isset($_POST['base'])){
700         $tmp = $this->get_allowed_bases();
701         if(isset($tmp[$_POST['base']])){
702           $base= validate($_POST['base']);
703           if ($base != $this->base){
704             $this->is_modified= TRUE;
705           }
706           $this->base= $base;
707         }else{
708           $this->base = $base_tmp;
709           print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
710           $this->set_acl_base('dummy,'.$this->base);
711         }
712       }
714       /* Get pw_storage mode */
715       if (isset($_POST['pw_storage'])){
716         foreach(array("pw_storage") as $val){
717           if(isset($_POST[$val])){
718             $data= validate($_POST[$val]);
719             if ($data != $this->$val){
720               $this->is_modified= TRUE;
721             }
722             $this->$val= $data;
723           }
724         }
725       }
727       $this->set_acl_base('dummy,'.$this->base);
728     }
729   }
731   function rebind($ldap, $referral)
732   {
733     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
734     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
735       $this->error = "Success";
736       $this->hascon=true;
737       $this->reconnect= true;
738       return (0);
739     } else {
740       $this->error = "Could not bind to " . $credentials['ADMIN'];
741       return NULL;
742     }
743   }
745   
746   /* Save data to LDAP, depending on is_account we save or delete */
747   function save()
748   {
749     /* Only force save of changes .... 
750        If this attributes aren't changed, avoid saving.
751      */
752     if($this->gender=="0") $this->gender ="";
753     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
754     
755     /* First use parents methods to do some basic fillup in $this->attrs */
756     plugin::save ();
758     if ($this->use_dob == "1"){
759       /* 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. */
760       if(!is_array($this->attrs['dateOfBirth'])) {
761         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
762       }
763     }
765     /* Remove additional objectClasses */
766     $tmp= array();
767     foreach ($this->attrs['objectClass'] as $key => $set){
768       $found= false;
769       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
770         if (preg_match ("/^$set$/i", $val)){
771           $found= true;
772           break;
773         }
774       }
775       if (!$found){
776         $tmp[]= $set;
777       }
778     }
780     /* Replace the objectClass array. This is done because of the
781        separation into government and normal mode. */
782     $this->attrs['objectClass']= $tmp;
784     /* Add objectClasss for template mode? */
785     if ($this->is_template){
786       $this->attrs['objectClass'][]= "gosaUserTemplate";
787     }
789     /* Hard coded government mode? */
790     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
791       $this->attrs['objectClass'][]= "ivbbentry";
793       /* Copy standard attributes */
794       foreach ($this->govattrs as $val){
795         if ($this->$val != ""){
796           $this->attrs["$val"]= $this->$val;
797         } elseif (!$this->is_new) {
798           $this->attrs["$val"]= array();
799         }
800       }
802       /* Remove attribute if set to "nein" */
803       if ($this->publicVisible == "nein"){
804         $this->attrs['publicVisible']= array();
805         if($this->is_new){
806           unset($this->attrs['publicVisible']);
807         }else{
808           $this->attrs['publicVisible']=array();
809         }
811       }
813     }
815     /* Special handling for attribute userCertificate needed */
816     if ($this->userCertificate != ""){
817       $this->attrs["userCertificate;binary"]= $this->userCertificate;
818       $remove_userCertificate= false;
819     } else {
820       $remove_userCertificate= true;
821     }
823     /* Special handling for dateOfBirth value */
824     if ($this->use_dob != "1"){
825       if ($this->is_new) {
826         unset($this->attrs["dateOfBirth"]);
827       } else {
828         $this->attrs["dateOfBirth"]= array();
829       }
830     }
831     if (!$this->gender){
832       if ($this->is_new) {
833         unset($this->attrs["gender"]);
834       } else {
835         $this->attrs["gender"]= array();
836       }
837     }
838     if (!$this->preferredLanguage){
839       if ($this->is_new) {
840         unset($this->attrs["preferredLanguage"]);
841       } else {
842         $this->attrs["preferredLanguage"]= array();
843       }
844     }
846     /* Special handling for attribute jpegPhote needed, scale image via
847        image magick to 147x200 pixels and inject resulting data. */
848     if ($this->jpegPhoto == "*removed*"){
849     
850       /* Reset attribute to avoid writing *removed* as value */    
851       $this->attrs["jpegPhoto"] = array();
853     } else {
855       /* Fallback if there's no image magick inside PHP */
856       if (!function_exists("imagick_blob2image")){
857         /* Get temporary file name for conversation */
858         $fname = tempnam ("/tmp", "GOsa");
860         /* Open file and write out photoData */
861         $fp = fopen ($fname, "w");
862         fwrite ($fp, $this->photoData);
863         fclose ($fp);
865         /* Build conversation query. Filename is generated automatically, so
866            we do not need any special security checks. Exec command and save
867            output. For PHP safe mode, you'll need a configuration which respects
868            image magick as executable... */
869         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
870         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
871             $query, "Execute");
873         /* Read data written by convert */
874         $output= "";
875         $sh= popen($query, 'r');
876         while (!feof($sh)){
877           $output.= fread($sh, 4096);
878         }
879         pclose($sh);
881         unlink($fname);
883         /* Save attribute */
884         $this->attrs["jpegPhoto"] = $output;
886       } else {
888         /* Load the new uploaded Photo */
889         if(!$handle  =  imagick_blob2image($this->photoData))  {
890           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
891         }
893         /* Resizing image to 147x200 and blur */
894         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
895           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
896         }
898         /* Converting image to JPEG */
899         if(!imagick_convert($handle,"JPEG")) {
900           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
901         }
903         /* Creating binary Code for the Image */
904         if(!$dump = imagick_image2blob($handle)){
905           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
906         }
908         /* Sending Image */
909         $output=  $dump;
911         /* Save attribute */
912         $this->attrs["jpegPhoto"] = $output;
913       }
915     }
917     /* This only gets called when user is renaming himself */
918     $ldap= $this->config->get_ldap_link();
919     if ($this->dn != $this->new_dn){
921       /* Write entry on new 'dn' */
922       $this->update_acls($this->dn,$this->new_dn);
923       $this->move($this->dn, $this->new_dn);
925       /* Happen to use the new one */
926       change_ui_dn($this->dn, $this->new_dn);
927       $this->dn= $this->new_dn;
928     }
931     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
932        new entries. So do a check first... */
933     $ldap->cat ($this->dn, array('dn'));
934     if ($ldap->fetch()){
935       $mode= "modify";
936     } else {
937       $mode= "add";
938       $ldap->cd($this->config->current['BASE']);
939       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
940     }
942     /* Set password to some junk stuff in case of templates */
943     if ($this->is_template){
944       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
945     }
947     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
948         $this->attributes, "Save via $mode");
950     /* Finally write data with selected 'mode' */
951     $this->cleanup();
953     if(isset($this->attrs['preferredLanguage'])){
954       $_SESSION['ui']->language = $this->preferredLanguage;
955       $_SESSION['Last_init_lang'] = "update";
956     }
958     $ldap->cd ($this->dn);
959     $ldap->$mode ($this->attrs);
960     if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){
961       return (1);
962     }
965     /* Remove ACL dependencies too */
966     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
967       $tmp = new acl($this->config,$this->parent,$this->dn);
968       $tmp->update_acl_membership($this->orig_dn,$this->dn);
969     }
971     if($mode == "modify"){
972       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
973     }else{
974       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
975     }
977     /* Remove cert? 
978        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
979        to work around myself. */
980     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
982       /* Reset array, assemble new, this should be reworked */
983       $this->attrs= array();
984       $this->attrs['userCertificate;binary']= array();
986       /* Prepare connection */
987       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
988         die ("Could not connect to LDAP server");
989       }
990       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
991       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
992         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
993         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
994       }
995       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
996         ldap_start_tls($ds);
997       }
998       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
999               $this->config->current['PASSWORD']))) {
1000         die ("Could not bind to LDAP");
1001       }
1003       /* Modify using attrs */
1004       ldap_mod_del($ds,$this->dn,$this->attrs);
1005       ldap_close($ds);
1006     }
1008     /* If needed, let the password method do some cleanup */
1009     if ($this->pw_storage != $this->last_pw_storage){
1010       $tmp = new passwordMethod($_SESSION['config']);
1011       $available = $tmp->get_available_methods();
1012       if (in_array_ics($this->pw_storage, $available['name'])){
1013         $test= new $available[$this->pw_storage]($this->config);
1014         $test->attrs= $this->attrs;
1015         $test->dn= $this->dn;
1016         $test->remove_from_parent();
1017       }
1018     }
1020     /* Optionally execute a command after we're done */
1021     if ($mode == "add"){
1022       $this->handle_post_events("add", array("uid" => $this->uid));
1023     } elseif ($this->is_modified){
1024       $this->handle_post_events("modify", array("uid" => $this->uid));
1025     }
1027     /* Fix tagging if needed */
1028     $this->handle_object_tagging();
1030     return (0);
1031   }
1034   /* Check formular input */
1035   function check()
1036   {
1037     /* Call common method to give check the hook */
1038     $message= plugin::check();
1040     $pt= "";
1041     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1042       if(!empty($this->personalTitle)){
1043         $pt = $this->personalTitle." ";
1044       }
1045      }
1046     $this->cn= $pt.$this->givenName." ".$this->sn;
1048     /* Permissions for that base? */
1049     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1050       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1051     } else {
1052       /* Don't touch dn, if cn hasn't changed */
1053       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1054           $this->orig_base == $this->base ){
1055         $this->new_dn= $this->dn;
1056       } else {
1057         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1058       }
1059     }
1061     /* Set the new acl base */
1062     if($this->dn == "new") {
1063       $this->set_acl_base($this->base);
1064     }
1066     if(!$this->multiple_support_active){
1068       /* UID already used? */
1069       $ldap= $this->config->get_ldap_link();
1070       $ldap->cd($this->config->current['BASE']);
1071       $ldap->search("(uid=$this->uid)", array("uid"));
1072       $ldap->fetch();
1073       if ($ldap->count() != 0 && $this->dn == 'new'){
1074         $message[]= _("There's already a person with this 'Login' in the database.");
1075       }
1077       /* In template mode, the uid and givenName are autogenerated... */
1078       if (!$this->is_template){
1079         if ($this->sn == ""){
1080           $message[]= _("The required field 'Name' is not set.");
1081         }
1082         if ($this->givenName == ""){
1083           $message[]= _("The required field 'Given name' is not set.");
1084         }
1085         if ($this->uid == ""){
1086           $message[]= _("The required field 'Login' is not set.");
1087         }
1088         if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1089           $ldap->cat($this->new_dn);
1090           if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1091             $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
1092           }
1093         }
1094       }
1096       /* Check for valid input */
1097       if ($this->is_modified && !is_uid($this->uid)){
1098         $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
1099       }
1100       if (!is_url($this->labeledURI)){
1101         $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1102       }
1103       if (preg_match ("/[\\\\]/", $this->sn)){
1104         $message[]= _("The field 'Name' contains invalid characters.");
1105       }
1106       if (preg_match ("/[\\\\]/", $this->givenName)){
1107         $message[]= _("The field 'Given name' contains invalid characters.");
1108       }
1109     }
1111     /* Check phone numbers */
1112     if (!is_phone_nr($this->telephoneNumber)){
1113       $message[]= _("The field 'Phone' contains an invalid phone number.");
1114     }
1115     if (!is_phone_nr($this->facsimileTelephoneNumber)){
1116       $message[]= _("The field 'Fax' contains an invalid phone number.");
1117     }
1118     if (!is_phone_nr($this->mobile)){
1119       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1120     }
1121     if (!is_phone_nr($this->pager)){
1122       $message[]= _("The field 'Pager' contains an invalid phone number.");
1123     }
1125     /* Check for reserved characers */
1126     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
1127       $message[]= _("The field 'Given name' contains invalid characters.");
1128     }
1129     if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
1130       $message[]= _("The field 'Name' contains invalid characters.");
1131     }
1133   return $message;
1134   }
1137   /* Indicate whether a password change is needed or not */
1138   function password_change_needed()
1139   {
1140     return($this->pw_storage != $this->last_pw_storage);
1141   }
1144   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1145   function load_picture()
1146   {
1147     $ldap = $this->config->get_ldap_link();
1148     $ldap->cd ($this->dn);
1149     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1150       
1151     if((!$data) || ($data == "*removed*")){ 
1153       /* In case we don't get an entry, load a default picture */
1154       $this->set_picture ();//"./images/default.jpg");
1155       $this->jpegPhoto= "*removed*";
1156     }else{
1158       /* Set picture */
1159       $this->photoData= $data;
1160       $_SESSION['binary']= $this->photoData;
1161       $_SESSION['binarytype']= "image/jpeg";
1162       $this->jpegPhoto= "";
1163     }
1164   }
1167   /* Load a certificate from LDAP, this is going to be simplified later on */
1168   function load_cert()
1169   {
1170     $ds= ldap_connect($this->config->current['SERVER']);
1171     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1172     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1173       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1174       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1175     }
1176     if(isset($this->config->current['TLS']) &&
1177         $this->config->current['TLS'] == "true"){
1179       ldap_start_tls($ds);
1180     }
1182     $r= ldap_bind($ds);
1183     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1185     if ($sr) {
1186       $ei= @ldap_first_entry($ds, $sr);
1187       
1188       if ($ei) {
1189         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1190           $this->userCertificate= "";
1191         } else {
1192           $this->userCertificate= $info[0];
1193         }
1194       }
1195     } else {
1196       $this->userCertificate= "";
1197     }
1199     ldap_unbind($ds);
1200   }
1203   /* Load picture from file to object */
1204   function set_picture($filename ="")
1205   {
1206     if (!is_file($filename) || $filename =="" ){
1207       $filename= "./images/default.jpg";
1208       $this->jpegPhoto= "*removed*";
1209     }
1211     $fd = fopen ($filename, "rb");
1212     $this->photoData= fread ($fd, filesize ($filename));
1213     $_SESSION['binary']= $this->photoData;
1214     $_SESSION['binarytype']= "image/jpeg";
1215     $this->jpegPhoto= "";
1217     fclose ($fd);
1218   }
1221   /* Load certificate from file to object */
1222   function set_cert($cert, $filename)
1223   {
1224     if(!$thsi->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))) return;
1225     $fd = fopen ($filename, "rb");
1226     if (filesize($filename)>0) {
1227       $this->$cert= fread ($fd, filesize ($filename));
1228       fclose ($fd);
1229       $this->is_modified= TRUE;
1230     } else {
1231       print_red(_("Could not open specified certificate!"));
1232     }
1233   }
1235   /* Adapt from given 'dn' */
1236   function adapt_from_template($dn)
1237   {
1238     plugin::adapt_from_template($dn);
1240     /* Get base */
1241     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1243     if ($this->config->current['GOVERNMENTMODE']){
1245       /* Walk through govattrs */
1246       foreach ($this->govattrs as $val){
1248         if (isset($this->attrs["$val"][0])){
1250           /* If attribute is set, replace dynamic parts: 
1251              %sn, %givenName and %uid. Fill these in our local variables. */
1252           $value= $this->attrs["$val"][0];
1254           foreach (array("sn", "givenName", "uid") as $repl){
1255             if (preg_match("/%$repl/i", $value)){
1256               $value= preg_replace ("/%$repl/i",
1257                   $this->parent->$repl, $value);
1258             }
1259           }
1260           $this->$val= $value;
1261         }
1262       }
1263     }
1265     /* Get back uid/sn/givenName */
1266     if ($this->parent !== NULL){
1267       $this->uid= $this->parent->uid;
1268       $this->sn= $this->parent->sn;
1269       $this->givenName= $this->parent->givenName;
1270     }
1271   }
1273  
1274   /* This avoids that users move themselves out of their rights. 
1275    */
1276   function allowedBasesToMoveTo()
1277   {
1278     /* Get bases */
1279     $bases  = $this->get_allowed_bases();
1280     return($bases);
1281   } 
1284   function getCopyDialog()
1285   {
1286     $str = "";
1288     $_SESSION['binary'] = $this->photoData; 
1289     $_SESSION['binarytype']= "image/jpeg";
1291     /* Get random number for pictures */
1292     srand((double)microtime()*1000000); 
1293     $rand = rand(0, 10000);
1295     $smarty = get_smarty();
1297     $smarty->assign("passwordTodo","clear");
1299     if(isset($_POST['passwordTodo'])){
1300       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1301     }
1303     $smarty->assign("sn",       $this->sn);
1304     $smarty->assign("givenName",$this->givenName);
1305     $smarty->assign("uid",      $this->uid);
1306     $smarty->assign("rand",     $rand);
1307     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1310     $ret = array();
1311     $ret['string'] = $str;
1312     $ret['status'] = "";  
1313     return($ret);
1314   }
1316   function saveCopyDialog()
1317   {
1318     /* Set_acl_base */
1319     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1321     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1322       $this->set_picture($_FILES['picture_file']['tmp_name']);
1323     }
1325     /* Remove picture? */
1326     if (isset($_POST['picture_remove'])){
1327       $this->jpegPhoto= "*removed*";
1328       $this->set_picture ("./images/default.jpg");
1329       $this->is_modified= TRUE;
1330     }
1332     $attrs = array("uid","givenName","sn");
1333     foreach($attrs as $attr){
1334       if(isset($_POST[$attr])){
1335         $this->$attr = $_POST[$attr];
1336       }
1337     } 
1338   }
1341   function PrepareForCopyPaste($source)
1342   {
1343     plugin::PrepareForCopyPaste($source);
1345     /* Reset certificate information addepted from source user
1346        to avoid setting the same user certificate for the destination user. */
1347     $this->userPKCS12= "";
1348     $this->userSMIMECertificate= "";
1349     $this->userCertificate= "";
1350     $this->certificateSerialNumber= "";
1351     $this->old_certificateSerialNumber= "";
1352     $this->old_userPKCS12= "";
1353     $this->old_userSMIMECertificate= "";
1354     $this->old_userCertificate= "";
1355   }
1358   static function plInfo()
1359   {
1360   
1361     $govattrs= array(
1362         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1363         "houseIdentifier"                           =>  _("House identifier"), 
1364         "vocation"                                  =>  _("Vocation"),
1365         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1366         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1367         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1368         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1369         "functionalTitle"                           =>  _("Functional title"),
1370         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1371         "publicVisible"                             =>  _("Public visible"),
1372         "street"                                    =>  _("Street"),
1373         "role"                                      =>  _("Role"),
1374         "postalCode"                                =>  _("Postal code"));
1376     $ret = array(
1377         "plShortName" => _("Generic"),
1378         "plDescription" => _("Generic user settings"),
1379         "plSelfModify"  => TRUE,
1380         "plDepends"     => array(),
1381         "plPriority"    => 1,
1382         "plSection"     => array("personal" => _("My account")),
1383         "plCategory"    => array("users" => array("description" => _("Users"),
1384                                                   "objectClass" => "gosaAccount")),
1386         "plProvidedAcls" => array(
1387           "base"              => _("Base"), 
1388           "userPassword"      => _("User password"), 
1389           "sn"                => _("Surename"),
1390           "givenName"         => _("Given name"),
1391           "uid"               => _("User identification"),
1392           "personalTitle"     => _("Personal title"),
1393           "academicTitle"     => _("Academic title"),
1394           "homePostalAddress" => _("Home postal address"),
1395           "homePhone"         => _("Home phone number"),
1396           "labeledURI"        => _("Homepage"),
1397           "o"                 => _("Organization"),
1398           "ou"                => _("Department"),
1399           "dateOfBirth"       => _("Date of birth"),
1400           "gender"            => _("Gender"),
1401           "preferredLanguage" => _("Preferred language"),
1402           "departmentNumber"  => _("Department number"),
1403           "employeeNumber"    => _("Employee number"),
1404           "employeeType"      => _("Employee type"),
1405           "l"                 => _("Location"),
1406           "st"                => _("State"),
1407           "userPicture"       => _("User picture"),
1408           "roomNumber"        => _("Room number"),
1409           "telephoneNumber"   => _("Telefon number"),
1410           "mobile"            => _("Mobile number"),
1411           "pager"             => _("Pager number"),
1412           "Certificate"        => _("User certificates"),
1414           "postalAddress"                => _("Postal address"),
1415           "facsimileTelephoneNumber"     => _("Fax number"))
1416         );
1418     /* Append government attributes if required */
1419       global $config;
1420     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1421       foreach($govattrs as $attr => $desc){
1422         $ret["plProvidedAcls"][$attr] = $desc;
1423       }
1424     }
1425     return($ret);
1426   }
1435   function get_values_to_update()
1436   {
1437     $ret = plugin::get_multi_edit_values();
1438     return($ret); 
1439   }
1442   function save_object_multiple()
1443   {
1444     foreach(array("pw_storage","base","edit_cert") as $attr){
1445       if(isset($_POST["use_".$attr])){
1446         $this->selected_edit_values[$attr] = TRUE;
1447       }else{
1448         $this->selected_edit_values[$attr] = FALSE;
1449       }
1450     }
1451   }
1454   function execute_multiple()
1455   {
1456     $smarty =get_smarty(); 
1457     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
1458     $smarty->assign("preferredLanguage_list", $language);
1459     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
1460     $smarty->assign("base_select",      $this->base);
1462     /* Save government mode attributes */
1463     if (isset($this->config->current['GOVERNMENTMODE']) &&
1464         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
1465       $smarty->assign("governmentmode", "true");
1466       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
1467           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
1468       $smarty->assign("ivbbmodes", $ivbbmodes);
1469       foreach ($this->govattrs as $val){
1470         $smarty->assign("$val", $this->$val);
1471         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
1472       }
1473     } else {
1474       $smarty->assign("governmentmode", "false");
1475     }
1477     $temp= passwordMethod::get_available_methods();
1478     $hashes = $temp['name'];
1479     $test= new $temp[$this->pw_storage]($this->config);
1480     $is_configurable= $test->is_configurable();
1481     $smarty->assign("pwmode", $hashes);
1482     $smarty->assign("pwmode_select", $this->pw_storage);
1483     $smarty->assign("pw_configurable", $is_configurable);
1485     foreach($this->attributes as $attr){
1486       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1487         $smarty->assign("use_".$attr,TRUE);
1488       }else{
1489         $smarty->assign("use_".$attr,FALSE);
1490       }
1491       $smarty->assign($attr,$this->$attr);
1492     }
1493     foreach(array("pw_storage","base","edit_cert") as $attr){
1494       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1495         $smarty->assign("use_".$attr,TRUE);
1496       }else{
1497         $smarty->assign("use_".$attr,FALSE);
1498       }
1499     }
1500     return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__))));
1501   }
1506 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1507 ?>