Code

Closes #237 Just a test commit
[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 sex */
289     $sex= array(0 => "&nbsp;", "F" => _("female"), "M" => _("male"));
290     $smarty->assign("gender_list", $sex);
292     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
293     $smarty->assign("preferredLanguage_list", $language);
295     /* Get random number for pictures */
296     srand((double)microtime()*1000000); 
297     $smarty->assign("rand", rand(0, 10000));
300     /* Do we represent a valid gosaAccount? */
301     if (!$this->is_account){
302       echo "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
303         _("This account has no valid GOsa extensions.")."</b>";
304       return;
305     }
307     /* Base select dialog */
308     $once = true;
309     foreach($_POST as $name => $value){
310       if(preg_match("/^chooseBase/",$name) && $once){
311         $once = false;
312         $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
313         $this->dialog->setCurrentBase($this->base);
314       }
315     }
317     /* Dialog handling */
318     if(is_object($this->dialog)){
319       /* Must be called before save_object */
320       $this->dialog->save_object();
321    
322       if($this->dialog->isClosed()){
323         $this->dialog = false;
324       }elseif($this->dialog->isSelected()){
326         /* check if selected base is allowed to move to / create a new object */
327         $tmp = $this->get_allowed_bases();
328         if(isset($tmp[$this->dialog->isSelected()])){
329           $this->base = $this->dialog->isSelected();
330         }
331         $this->dialog= false;
332       }else{
333         return($this->dialog->execute());
334       }
335     }
337     /* Want picture edit dialog? */
338     if($this->acl_is_writeable("userPicture")) {
339       if (isset($_POST['edit_picture'])){
340         /* Save values for later recovery, in case some presses
341            the cancel button. */
342         $this->old_jpegPhoto= $this->jpegPhoto;
343         $this->old_photoData= $this->photoData;
344         $this->picture_dialog= TRUE;
345         $this->dialog= TRUE;
346       }
347     }
349     /* Remove picture? */
350     if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))) ){
351       if (isset($_POST['picture_remove'])){
352         $this->set_picture ();
353         $this->jpegPhoto= "*removed*";
354         $this->is_modified= TRUE;
355         return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
356       }
357     }
359     /* Save picture */
360     if (isset($_POST['picture_edit_finish'])){
362       /* Check for clean upload */
363       if ($_FILES['picture_file']['name'] != ""){
364         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
365           print_red(_("The specified file has not been uploaded via HTTP POST! Aborted."));
366         }else{
367           /* Activate new picture */
368           $this->set_picture($_FILES['picture_file']['tmp_name']);
369         }
370       }
371       $this->picture_dialog= FALSE;
372       $this->dialog= FALSE;
373       $this->is_modified= TRUE;
374     }
377     /* Cancel picture */
378     if (isset($_POST['picture_edit_cancel'])){
380       /* Restore values */
381       $this->jpegPhoto= $this->old_jpegPhoto;
382       $this->photoData= $this->old_photoData;
384       /* Update picture */
385       $_SESSION['binary']= $this->photoData;
386       $_SESSION['binarytype']= "image/jpeg";
387       $this->picture_dialog= FALSE;
388       $this->dialog= FALSE;
389     }
391     /* Toggle dateOfBirth information */
392     if (isset($_POST['set_dob'])){
393       $this->use_dob= ($this->use_dob == "0")?"1":"0";
394     }
397     /* Want certificate= */
398     if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
400       /* Save original values for later reconstruction */
401       foreach (array("certificateSerialNumber", "userCertificate",
402             "userSMIMECertificate", "userPKCS12") as $val){
404         $oval= "old_$val";
405         $this->$oval= $this->$val;
406       }
408       $this->cert_dialog= TRUE;
409       $this->dialog= TRUE;
410     }
413     /* Cancel certificate dialog */
414     if (isset($_POST['cert_edit_cancel'])){
416       /* Restore original values in case of 'cancel' */
417       foreach (array("certificateSerialNumber", "userCertificate",
418             "userSMIMECertificate", "userPKCS12") as $val){
420         $oval= "old_$val";
421         $this->$val= $this->$oval;
422       }
423       $this->cert_dialog= FALSE;
424       $this->dialog= FALSE;
425     }
428     /* Remove certificate? */
429     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
430       foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
431         if (isset($_POST["remove_$val"])){
433           /* Reset specified cert*/
434           $this->$val= "";
435           $this->is_modified= TRUE;
436         }
437       }
438     }
440     /* Upload new cert and close dialog? */     
441     if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))){ 
442       if (isset($_POST['cert_edit_finish'])){
444         /* for all certificates do */
445         foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
446             as $val){
448           /* Check for clean upload */
449           if (array_key_exists($val."_file", $_FILES) &&
450               array_key_exists('name', $_FILES[$val."_file"]) &&
451               $_FILES[$val."_file"]['name'] != "" &&
452               is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
453             $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
454           }
455         }
457         /* Save serial number */
458         if (isset($_POST["certificateSerialNumber"]) &&
459             $_POST["certificateSerialNumber"] != ""){
461           if (!is_id($_POST["certificateSerialNumber"])){
462             print_red (_("Please enter a valid serial number"));
464             foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
465               if ($this->$cert != ""){
466                 $smarty->assign("$cert"."_state", "true");
467               } else {
468                 $smarty->assign("$cert"."_state", "");
469               }
470             }
471             return ($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
472           }
474           $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
475           $this->is_modified= TRUE;
476         }
478         $this->cert_dialog= FALSE;
479         $this->dialog= FALSE;
480       }
481     }
482     /* Display picture dialog */
483     if ($this->picture_dialog){
484       return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
485     }
487     /* Display cert dialog */
488     if ($this->cert_dialog){
489       $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
490       $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
492       foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
493         if ($this->$cert != ""){
494           /* import certificate */
495           $certificate = new certificate;
496           $certificate->import($this->$cert);
497       
498           /* Read out data*/
499           $timeto   = $certificate->getvalidto_date();
500           $timefrom = $certificate->getvalidfrom_date();
501          
502           
503           /* Additional info if start end time is '0' */
504           $add_str_info = "";
505           if($timeto == 0 && $timefrom == 0){
506             $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
507           }
509           $str = "<table summary=\"\" border=0>
510                     <tr>
511                       <td style='vertical-align:top'>CN</td>
512                       <td>".preg_replace("/ /", "&nbsp;", $certificate->getname())."</td>
513                     </tr>
514                   </table><br>".
516                   sprintf(_("Certificate is valid from %s to %s and is currently %s."),
517                         "<b>".date('d M Y',$timefrom)."</b>",
518                         "<b>".date('d M Y',$timeto)."</b>",
519                         $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
520                                                 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
522           $smarty->assign($cert."info",$str);
523           $smarty->assign($cert."_state","true");
524         } else {
525           $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
526           $smarty->assign($cert."_state","");
527         }
528       }
529       $smarty->assign("governmentmode", "false");
530       return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
531     }
533     /* Prepare password hashes */
534     if ($this->pw_storage == ""){
535       $this->pw_storage= $this->config->current['HASH'];
536     }
538     $temp= passwordMethod::get_available_methods();
539     $hashes = $temp['name'];
540     $test= new $temp[$this->pw_storage]($this->config);
541     $is_configurable= $test->is_configurable();
542     
543     /* Load attributes and acl's */
544     $ui =get_userinfo();
545     foreach($this->attributes as $val){
546       $smarty->assign("$val", $this->$val);
547     }
549     /* Set acls */
550     $tmp = $this->plinfo();
551     foreach($tmp['plProvidedAcls'] as $val => $translation){
552       $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
553     }
555     $smarty->assign("pwmode", $hashes);
556     $smarty->assign("pwmode_select", $this->pw_storage);
557     $smarty->assign("pw_configurable", $is_configurable);
558     $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !isset($_SESSION['edit']))));
559     $smarty->assign("base_select",      $this->base);
560     $smarty->assign("CertificatesACL",  $this->getacl("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit']))));
561     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
562     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !isset($_SESSION['edit']))));
564     /* Create base acls */
565     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
567     /* Save government mode attributes */
568     if (isset($this->config->current['GOVERNMENTMODE']) &&
569         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
570       $smarty->assign("governmentmode", "true");
571       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
572           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
573       $smarty->assign("ivbbmodes", $ivbbmodes);
574       foreach ($this->govattrs as $val){
575         $smarty->assign("$val", $this->$val);
576         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
577       }
578     } else {
579       $smarty->assign("governmentmode", "false");
580     }
582     /* Special mode for uid */
583     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])));
584     if (isset ($this->dn)){
585       if ($this->dn != "new"){
586         $uidACL= preg_replace("/w/","",$uidACL);
587       }
588     }  else {
589       $uidACL= preg_replace("/w/","",$uidACL);
590     }
591     
592     $smarty->assign("uidACL", $uidACL);
593     $smarty->assign("is_template", $this->is_template);
594     $smarty->assign("use_dob", $this->use_dob);
596     if (isset($this->parent)){
597       if (isset($this->parent->by_object['phoneAccount']) &&
598           $this->parent->by_object['phoneAccount']->is_account){
599         $smarty->assign("has_phoneaccount", "true");
600       } else {
601         $smarty->assign("has_phoneaccount", "false");
602       }
603     } else {
604       $smarty->assign("has_phoneaccount", "false");
605     }
606     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
607   }
610   /* remove object from parent */
611   function remove_from_parent()
612   {
613     $ldap= $this->config->get_ldap_link();
614     $ldap->rmdir ($this->dn);
615     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/generic account with dn '%s' failed."),$this->dn));
616   
617     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
618   
619     /* Delete references to groups */
620     $ldap->cd ($this->config->current['BASE']);
621     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
622     while ($ldap->fetch()){
623       $g= new group($this->config, $ldap->getDN());
624       $g->removeUser($this->uid);
625       $g->save ();
626     }
628     /* Delete references to object groups */
629     $ldap->cd ($this->config->current['BASE']);
630     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
631     while ($ldap->fetch()){
632       $og= new ogroup($this->config, $ldap->getDN());
633       unset($og->member[$this->dn]);
634       $og->save ();
635     }
637     /* If needed, let the password method do some cleanup */
638     $tmp = new passwordMethod($_SESSION['config']);
639     $available = $tmp->get_available_methods();
640     if (in_array_ics($this->pw_storage, $available['name'])){
641       $test= new $available[$this->pw_storage]($this->config);
642       $test->attrs= $this->attrs;
643       $test->dn= $this->dn;
644       $test->remove_from_parent();
645     }
647     /* Remove ACL dependencies too */
648     $tmp = new acl($this->config,$this->parent,$this->dn);
649     $tmp->remove_acl();
651     /* Optionally execute a command after we're done */
652     $this->handle_post_events("remove",array("uid" => $this->uid));
653   }
656   /* Save data to object */
657   function save_object()
658   {
659     if (isset($_POST['multiple_user_posted'])){
660       $this->save_object_multiple();
661     }
662     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
664       /* Make a backup of the current selected base */
665       $base_tmp = $this->base;
667       /* Parents save function */
668       plugin::save_object ();
670       /* Save government mode attributes */
671       if ($this->config->current['GOVERNMENTMODE']){
672         foreach ($this->govattrs as $val){
673           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !isset($_SESSION['edit']))) && isset($_POST["$val"])){
674             $data= stripcslashes($_POST["$val"]);
675             if ($data != $this->$val){
676               $this->is_modified= TRUE;
677             }
678             $this->$val= $data;
679           }
680         }
681       }
683       /* In template mode, the uid is autogenerated... */
684       if ($this->is_template){
685         $this->uid= strtolower($this->sn);
686         $this->givenName= $this->sn;
687       }
689       /* Save base and pw_storage, since these are no LDAP attributes */
690       if (isset($_POST['base'])){
692         $tmp = $this->get_allowed_bases();
693         if(isset($tmp[$_POST['base']])){
694           $base= validate($_POST['base']);
695           if ($base != $this->base){
696             $this->is_modified= TRUE;
697           }
698           $this->base= $base;
699         }else{
700           $this->base = $base_tmp;
701           print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
702           $this->set_acl_base('dummy,'.$this->base);
703         }
704       }
706       /* Get pw_storage mode */
707       if (isset($_POST['pw_storage'])){
708         foreach(array("pw_storage") as $val){
709           if(isset($_POST[$val])){
710             $data= validate($_POST[$val]);
711             if ($data != $this->$val){
712               $this->is_modified= TRUE;
713             }
714             $this->$val= $data;
715           }
716         }
717       }
719       $this->set_acl_base('dummy,'.$this->base);
720     }
721   }
723   function rebind($ldap, $referral)
724   {
725     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
726     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
727       $this->error = "Success";
728       $this->hascon=true;
729       $this->reconnect= true;
730       return (0);
731     } else {
732       $this->error = "Could not bind to " . $credentials['ADMIN'];
733       return NULL;
734     }
735   }
737   
738   /* Save data to LDAP, depending on is_account we save or delete */
739   function save()
740   {
741     /* Only force save of changes .... 
742        If this attributes aren't changed, avoid saving.
743      */
744     if($this->gender=="0") $this->gender ="";
745     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
746     
747     /* First use parents methods to do some basic fillup in $this->attrs */
748     plugin::save ();
750     if ($this->use_dob == "1"){
751       /* 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. */
752       if(!is_array($this->attrs['dateOfBirth'])) {
753         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
754       }
755     }
757     /* Remove additional objectClasses */
758     $tmp= array();
759     foreach ($this->attrs['objectClass'] as $key => $set){
760       $found= false;
761       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
762         if (preg_match ("/^$set$/i", $val)){
763           $found= true;
764           break;
765         }
766       }
767       if (!$found){
768         $tmp[]= $set;
769       }
770     }
772     /* Replace the objectClass array. This is done because of the
773        separation into government and normal mode. */
774     $this->attrs['objectClass']= $tmp;
776     /* Add objectClasss for template mode? */
777     if ($this->is_template){
778       $this->attrs['objectClass'][]= "gosaUserTemplate";
779     }
781     /* Hard coded government mode? */
782     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
783       $this->attrs['objectClass'][]= "ivbbentry";
785       /* Copy standard attributes */
786       foreach ($this->govattrs as $val){
787         if ($this->$val != ""){
788           $this->attrs["$val"]= $this->$val;
789         } elseif (!$this->is_new) {
790           $this->attrs["$val"]= array();
791         }
792       }
794       /* Remove attribute if set to "nein" */
795       if ($this->publicVisible == "nein"){
796         $this->attrs['publicVisible']= array();
797         if($this->is_new){
798           unset($this->attrs['publicVisible']);
799         }else{
800           $this->attrs['publicVisible']=array();
801         }
803       }
805     }
807     /* Special handling for attribute userCertificate needed */
808     if ($this->userCertificate != ""){
809       $this->attrs["userCertificate;binary"]= $this->userCertificate;
810       $remove_userCertificate= false;
811     } else {
812       $remove_userCertificate= true;
813     }
815     /* Special handling for dateOfBirth value */
816     if ($this->use_dob != "1"){
817       if ($this->is_new) {
818         unset($this->attrs["dateOfBirth"]);
819       } else {
820         $this->attrs["dateOfBirth"]= array();
821       }
822     }
823     if (!$this->gender){
824       if ($this->is_new) {
825         unset($this->attrs["gender"]);
826       } else {
827         $this->attrs["gender"]= array();
828       }
829     }
830     if (!$this->preferredLanguage){
831       if ($this->is_new) {
832         unset($this->attrs["preferredLanguage"]);
833       } else {
834         $this->attrs["preferredLanguage"]= array();
835       }
836     }
838     /* Special handling for attribute jpegPhote needed, scale image via
839        image magick to 147x200 pixels and inject resulting data. */
840     if ($this->jpegPhoto == "*removed*"){
841     
842       /* Reset attribute to avoid writing *removed* as value */    
843       $this->attrs["jpegPhoto"] = array();
845     } else {
847       /* Fallback if there's no image magick inside PHP */
848       if (!function_exists("imagick_blob2image")){
849         /* Get temporary file name for conversation */
850         $fname = tempnam ("/tmp", "GOsa");
852         /* Open file and write out photoData */
853         $fp = fopen ($fname, "w");
854         fwrite ($fp, $this->photoData);
855         fclose ($fp);
857         /* Build conversation query. Filename is generated automatically, so
858            we do not need any special security checks. Exec command and save
859            output. For PHP safe mode, you'll need a configuration which respects
860            image magick as executable... */
861         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
862         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
863             $query, "Execute");
865         /* Read data written by convert */
866         $output= "";
867         $sh= popen($query, 'r');
868         while (!feof($sh)){
869           $output.= fread($sh, 4096);
870         }
871         pclose($sh);
873         unlink($fname);
875         /* Save attribute */
876         $this->attrs["jpegPhoto"] = $output;
878       } else {
880         /* Load the new uploaded Photo */
881         if(!$handle  =  imagick_blob2image($this->photoData))  {
882           new log("debug","users/".get_class($this),"",array(),"Could not access uploaded image");
883         }
885         /* Resizing image to 147x200 and blur */
886         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
887           new log("debug","users/".get_class($this),"",array(),"Could not resize uploaded image");
888         }
890         /* Converting image to JPEG */
891         if(!imagick_convert($handle,"JPEG")) {
892           new log("debug","users/".get_class($this),"",array(),"Could not convert uploaded image to jepg");
893         }
895         /* Creating binary Code for the Image */
896         if(!$dump = imagick_image2blob($handle)){
897           new log("debug","users/".get_class($this),"",array(),"Could not create new user image");
898         }
900         /* Sending Image */
901         $output=  $dump;
903         /* Save attribute */
904         $this->attrs["jpegPhoto"] = $output;
905       }
907     }
909     /* This only gets called when user is renaming himself */
910     $ldap= $this->config->get_ldap_link();
911     if ($this->dn != $this->new_dn){
913       /* Write entry on new 'dn' */
914       $this->update_acls($this->dn,$this->new_dn);
915       $this->move($this->dn, $this->new_dn);
917       /* Happen to use the new one */
918       change_ui_dn($this->dn, $this->new_dn);
919       $this->dn= $this->new_dn;
920     }
923     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
924        new entries. So do a check first... */
925     $ldap->cat ($this->dn, array('dn'));
926     if ($ldap->fetch()){
927       $mode= "modify";
928     } else {
929       $mode= "add";
930       $ldap->cd($this->config->current['BASE']);
931       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
932     }
934     /* Set password to some junk stuff in case of templates */
935     if ($this->is_template){
936       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
937     }
939     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
940         $this->attributes, "Save via $mode");
942     /* Finally write data with selected 'mode' */
943     $this->cleanup();
945     if(isset($this->attrs['preferredLanguage'])){
946       $_SESSION['ui']->language = $this->preferredLanguage;
947       $_SESSION['Last_init_lang'] = "update";
948     }
950     $ldap->cd ($this->dn);
951     $ldap->$mode ($this->attrs);
952     if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){
953       return (1);
954     }
957     /* Remove ACL dependencies too */
958     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
959       $tmp = new acl($this->config,$this->parent,$this->dn);
960       $tmp->update_acl_membership($this->orig_dn,$this->dn);
961     }
963     if($mode == "modify"){
964       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
965     }else{
966       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
967     }
969     /* Remove cert? 
970        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
971        to work around myself. */
972     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
974       /* Reset array, assemble new, this should be reworked */
975       $this->attrs= array();
976       $this->attrs['userCertificate;binary']= array();
978       /* Prepare connection */
979       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
980         die ("Could not connect to LDAP server");
981       }
982       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
983       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
984         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
985         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
986       }
987       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
988         ldap_start_tls($ds);
989       }
990       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
991               $this->config->current['PASSWORD']))) {
992         die ("Could not bind to LDAP");
993       }
995       /* Modify using attrs */
996       ldap_mod_del($ds,$this->dn,$this->attrs);
997       ldap_close($ds);
998     }
1000     /* If needed, let the password method do some cleanup */
1001     if ($this->pw_storage != $this->last_pw_storage){
1002       $tmp = new passwordMethod($_SESSION['config']);
1003       $available = $tmp->get_available_methods();
1004       if (in_array_ics($this->pw_storage, $available['name'])){
1005         $test= new $available[$this->pw_storage]($this->config);
1006         $test->attrs= $this->attrs;
1007         $test->dn= $this->dn;
1008         $test->remove_from_parent();
1009       }
1010     }
1012     /* Optionally execute a command after we're done */
1013     if ($mode == "add"){
1014       $this->handle_post_events("add", array("uid" => $this->uid));
1015     } elseif ($this->is_modified){
1016       $this->handle_post_events("modify", array("uid" => $this->uid));
1017     }
1019     /* Fix tagging if needed */
1020     $this->handle_object_tagging();
1022     return (0);
1023   }
1026   /* Check formular input */
1027   function check()
1028   {
1029     /* Call common method to give check the hook */
1030     $message= plugin::check();
1032     $pt= "";
1033     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1034       if(!empty($this->personalTitle)){
1035         $pt = $this->personalTitle." ";
1036       }
1037      }
1038     $this->cn= $pt.$this->givenName." ".$this->sn;
1040     /* Permissions for that base? */
1041     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1042       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1043     } else {
1044       /* Don't touch dn, if cn hasn't changed */
1045       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1046           $this->orig_base == $this->base ){
1047         $this->new_dn= $this->dn;
1048       } else {
1049         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1050       }
1051     }
1053     /* Set the new acl base */
1054     if($this->dn == "new") {
1055       $this->set_acl_base($this->base);
1056     }
1059     if(!$this->multiple_support_active){
1061       /* must: sn, givenName, uid */
1062       if ($this->sn == "" && ($this->acl_is_writeable("sn",(!is_object($this->parent) && !isset($_SESSION['edit'])) || ($this->is_new)))){
1063         $message[]= _("The required field 'Name' is not set.");
1064       }
1066       /* UID already used? */
1067       $ldap= $this->config->get_ldap_link();
1068       $ldap->cd($this->config->current['BASE']);
1069       $ldap->search("(uid=$this->uid)", array("uid"));
1070       $ldap->fetch();
1071       if ($ldap->count() != 0 && $this->dn == 'new'){
1072         $message[]= _("There's already a person with this 'Login' in the database.");
1073       }
1075       /* In template mode, the uid and givenName are autogenerated... */
1076       if (!$this->is_template){
1077         if ($this->givenName == "" && $this->acl_is_writeable("givenName",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
1078           $message[]= _("The required field 'Given name' is not set.");
1079         }
1080         if ($this->uid == "" && $this->acl_is_writeable("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
1081           $message[]= _("The required field 'Login' is not set.");
1082         }
1083         if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1084           $ldap->cat($this->new_dn);
1085           if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1086             $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
1087           }
1088         }
1089       }
1091       /* Check for valid input */
1092       if ($this->is_modified && !is_uid($this->uid)){
1093         $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
1094       }
1095       if (!is_url($this->labeledURI)){
1096         $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1097       }
1098       if (preg_match ("/[\\\\]/", $this->sn)){
1099         $message[]= _("The field 'Name' contains invalid characters.");
1100       }
1101       if (preg_match ("/[\\\\]/", $this->givenName)){
1102         $message[]= _("The field 'Given name' contains invalid characters.");
1103       }
1104     }
1106     /* Check phone numbers */
1107     if (!is_phone_nr($this->telephoneNumber)){
1108       $message[]= _("The field 'Phone' contains an invalid phone number.");
1109     }
1110     if (!is_phone_nr($this->facsimileTelephoneNumber)){
1111       $message[]= _("The field 'Fax' contains an invalid phone number.");
1112     }
1113     if (!is_phone_nr($this->mobile)){
1114       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1115     }
1116     if (!is_phone_nr($this->pager)){
1117       $message[]= _("The field 'Pager' contains an invalid phone number.");
1118     }
1120     /* Check for reserved characers */
1121     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
1122       $message[]= _("The field 'Given name' contains invalid characters.");
1123     }
1124     if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
1125       $message[]= _("The field 'Name' contains invalid characters.");
1126     }
1128   return $message;
1129   }
1132   /* Indicate whether a password change is needed or not */
1133   function password_change_needed()
1134   {
1135     return($this->pw_storage != $this->last_pw_storage);
1136   }
1139   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1140   function load_picture()
1141   {
1142     $ldap = $this->config->get_ldap_link();
1143     $ldap->cd ($this->dn);
1144     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1145       
1146     if((!$data) || ($data == "*removed*")){ 
1148       /* In case we don't get an entry, load a default picture */
1149       $this->set_picture ();//"./images/default.jpg");
1150       $this->jpegPhoto= "*removed*";
1151     }else{
1153       /* Set picture */
1154       $this->photoData= $data;
1155       $_SESSION['binary']= $this->photoData;
1156       $_SESSION['binarytype']= "image/jpeg";
1157       $this->jpegPhoto= "";
1158     }
1159   }
1162   /* Load a certificate from LDAP, this is going to be simplified later on */
1163   function load_cert()
1164   {
1165     $ds= ldap_connect($this->config->current['SERVER']);
1166     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1167     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1168       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1169       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1170     }
1171     if(isset($this->config->current['TLS']) &&
1172         $this->config->current['TLS'] == "true"){
1174       ldap_start_tls($ds);
1175     }
1177     $r= ldap_bind($ds);
1178     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1180     if ($sr) {
1181       $ei= @ldap_first_entry($ds, $sr);
1182       
1183       if ($ei) {
1184         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1185           $this->userCertificate= "";
1186         } else {
1187           $this->userCertificate= $info[0];
1188         }
1189       }
1190     } else {
1191       $this->userCertificate= "";
1192     }
1194     ldap_unbind($ds);
1195   }
1198   /* Load picture from file to object */
1199   function set_picture($filename ="")
1200   {
1201     if (!is_file($filename) || $filename =="" ){
1202       $filename= "./images/default.jpg";
1203       $this->jpegPhoto= "*removed*";
1204     }
1206     $fd = fopen ($filename, "rb");
1207     $this->photoData= fread ($fd, filesize ($filename));
1208     $_SESSION['binary']= $this->photoData;
1209     $_SESSION['binarytype']= "image/jpeg";
1210     $this->jpegPhoto= "";
1212     fclose ($fd);
1213   }
1216   /* Load certificate from file to object */
1217   function set_cert($cert, $filename)
1218   {
1219     if(!$thsi->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))) return;
1220     $fd = fopen ($filename, "rb");
1221     if (filesize($filename)>0) {
1222       $this->$cert= fread ($fd, filesize ($filename));
1223       fclose ($fd);
1224       $this->is_modified= TRUE;
1225     } else {
1226       print_red(_("Could not open specified certificate!"));
1227     }
1228   }
1230   /* Adapt from given 'dn' */
1231   function adapt_from_template($dn)
1232   {
1233     plugin::adapt_from_template($dn);
1235     /* Get base */
1236     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1238     if ($this->config->current['GOVERNMENTMODE']){
1240       /* Walk through govattrs */
1241       foreach ($this->govattrs as $val){
1243         if (isset($this->attrs["$val"][0])){
1245           /* If attribute is set, replace dynamic parts: 
1246              %sn, %givenName and %uid. Fill these in our local variables. */
1247           $value= $this->attrs["$val"][0];
1249           foreach (array("sn", "givenName", "uid") as $repl){
1250             if (preg_match("/%$repl/i", $value)){
1251               $value= preg_replace ("/%$repl/i",
1252                   $this->parent->$repl, $value);
1253             }
1254           }
1255           $this->$val= $value;
1256         }
1257       }
1258     }
1260     /* Get back uid/sn/givenName */
1261     if ($this->parent !== NULL){
1262       $this->uid= $this->parent->uid;
1263       $this->sn= $this->parent->sn;
1264       $this->givenName= $this->parent->givenName;
1265     }
1266   }
1268  
1269   /* This avoids that users move themselves out of their rights. 
1270    */
1271   function allowedBasesToMoveTo()
1272   {
1273     /* Get bases */
1274     $bases  = $this->get_allowed_bases();
1275     return($bases);
1276   } 
1279   function getCopyDialog()
1280   {
1281     $str = "";
1283     $_SESSION['binary'] = $this->photoData; 
1284     $_SESSION['binarytype']= "image/jpeg";
1286     /* Get random number for pictures */
1287     srand((double)microtime()*1000000); 
1288     $rand = rand(0, 10000);
1290     $smarty = get_smarty();
1292     $smarty->assign("passwordTodo","clear");
1294     if(isset($_POST['passwordTodo'])){
1295       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1296     }
1298     $smarty->assign("sn",       $this->sn);
1299     $smarty->assign("givenName",$this->givenName);
1300     $smarty->assign("uid",      $this->uid);
1301     $smarty->assign("rand",     $rand);
1302     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1305     $ret = array();
1306     $ret['string'] = $str;
1307     $ret['status'] = "";  
1308     return($ret);
1309   }
1311   function saveCopyDialog()
1312   {
1313     /* Set_acl_base */
1314     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1316     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1317       $this->set_picture($_FILES['picture_file']['tmp_name']);
1318     }
1320     /* Remove picture? */
1321     if (isset($_POST['picture_remove'])){
1322       $this->jpegPhoto= "*removed*";
1323       $this->set_picture ("./images/default.jpg");
1324       $this->is_modified= TRUE;
1325     }
1327     $attrs = array("uid","givenName","sn");
1328     foreach($attrs as $attr){
1329       if(isset($_POST[$attr])){
1330         $this->$attr = $_POST[$attr];
1331       }
1332     } 
1333   }
1336   function PrepareForCopyPaste($source)
1337   {
1338     plugin::PrepareForCopyPaste($source);
1340     /* Reset certificate information addepted from source user
1341        to avoid setting the same user certificate for the destination user. */
1342     $this->userPKCS12= "";
1343     $this->userSMIMECertificate= "";
1344     $this->userCertificate= "";
1345     $this->certificateSerialNumber= "";
1346     $this->old_certificateSerialNumber= "";
1347     $this->old_userPKCS12= "";
1348     $this->old_userSMIMECertificate= "";
1349     $this->old_userCertificate= "";
1350   }
1353   function plInfo()
1354   {
1355   
1356     $govattrs= array(
1357         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1358         "houseIdentifier"                           =>  _("House identifier"), 
1359         "vocation"                                  =>  _("Vocation"),
1360         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1361         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1362         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1363         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1364         "functionalTitle"                           =>  _("Functional title"),
1365         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1366         "publicVisible"                             =>  _("Public visible"),
1367         "street"                                    =>  _("Street"),
1368         "role"                                      =>  _("Role"),
1369         "postalCode"                                =>  _("Postal code"));
1371     $ret = array(
1372         "plShortName" => _("Generic"),
1373         "plDescription" => _("Generic user settings"),
1374         "plSelfModify"  => TRUE,
1375         "plDepends"     => array(),
1376         "plPriority"    => 1,
1377         "plSection"     => array("personal" => _("My account")),
1378         "plCategory"    => array("users" => array("description" => _("Users"),
1379                                                   "objectClass" => "gosaAccount")),
1381         "plProvidedAcls" => array(
1382           "base"              => _("Base"), 
1383           "userPassword"      => _("User password"), 
1384           "sn"                => _("Surename"),
1385           "givenName"         => _("Given name"),
1386           "uid"               => _("User identification"),
1387           "personalTitle"     => _("Personal title"),
1388           "academicTitle"     => _("Academic title"),
1389           "homePostalAddress" => _("Home postal address"),
1390           "homePhone"         => _("Home phone number"),
1391           "labeledURI"        => _("Homepage"),
1392           "o"                 => _("Organization"),
1393           "ou"                => _("Department"),
1394           "dateOfBirth"       => _("Date of birth"),
1395           "gender"            => _("Gender"),
1396           "preferredLanguage" => _("Preferred language"),
1397           "departmentNumber"  => _("Department number"),
1398           "employeeNumber"    => _("Employee number"),
1399           "employeeType"      => _("Employee type"),
1400           "l"                 => _("Location"),
1401           "st"                => _("State"),
1402           "userPicture"       => _("User picture"),
1403           "roomNumber"        => _("Room number"),
1404           "telephoneNumber"   => _("Telefon number"),
1405           "mobile"            => _("Mobile number"),
1406           "pager"             => _("Pager number"),
1407           "Certificate"        => _("User certificates"),
1409           "postalAddress"                => _("Postal address"),
1410           "facsimileTelephoneNumber"     => _("Fax number"))
1411         );
1413     /* Append government attributes if required */
1414       global $config;
1415     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1416       foreach($govattrs as $attr => $desc){
1417         $ret["plProvidedAcls"][$attr] = $desc;
1418       }
1419     }
1420     return($ret);
1421   }
1430   function get_values_to_update()
1431   {
1432     $ret = plugin::get_multi_edit_values();
1433     return($ret); 
1434   }
1437   function save_object_multiple()
1438   {
1439     foreach(array("pw_storage","base","edit_cert") as $attr){
1440       if(isset($_POST["use_".$attr])){
1441         $this->selected_edit_values[$attr] = TRUE;
1442       }else{
1443         $this->selected_edit_values[$attr] = FALSE;
1444       }
1445     }
1446   }
1449   function execute_multiple()
1450   {
1451     $smarty =get_smarty(); 
1452     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
1453     $smarty->assign("preferredLanguage_list", $language);
1454     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
1455     $smarty->assign("base_select",      $this->base);
1457     /* Save government mode attributes */
1458     if (isset($this->config->current['GOVERNMENTMODE']) &&
1459         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
1460       $smarty->assign("governmentmode", "true");
1461       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
1462           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
1463       $smarty->assign("ivbbmodes", $ivbbmodes);
1464       foreach ($this->govattrs as $val){
1465         $smarty->assign("$val", $this->$val);
1466         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
1467       }
1468     } else {
1469       $smarty->assign("governmentmode", "false");
1470     }
1472     $temp= passwordMethod::get_available_methods();
1473     $hashes = $temp['name'];
1474     $test= new $temp[$this->pw_storage]($this->config);
1475     $is_configurable= $test->is_configurable();
1476     $smarty->assign("pwmode", $hashes);
1477     $smarty->assign("pwmode_select", $this->pw_storage);
1478     $smarty->assign("pw_configurable", $is_configurable);
1480     foreach($this->attributes as $attr){
1481       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1482         $smarty->assign("use_".$attr,TRUE);
1483       }else{
1484         $smarty->assign("use_".$attr,FALSE);
1485       }
1486       $smarty->assign($attr,$this->$attr);
1487     }
1488     foreach(array("pw_storage","base","edit_cert") as $attr){
1489       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1490         $smarty->assign("use_".$attr,TRUE);
1491       }else{
1492         $smarty->assign("use_".$attr,FALSE);
1493       }
1494     }
1495     return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__))));
1496   }
1501 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1502 ?>