Code

Added checkboxes to management dialog to filter actions
[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     echo $this->base."<br>" ;
722   }
724   function rebind($ldap, $referral)
725   {
726     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
727     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
728       $this->error = "Success";
729       $this->hascon=true;
730       $this->reconnect= true;
731       return (0);
732     } else {
733       $this->error = "Could not bind to " . $credentials['ADMIN'];
734       return NULL;
735     }
736   }
738   
739   /* Save data to LDAP, depending on is_account we save or delete */
740   function save()
741   {
742     /* Only force save of changes .... 
743        If this attributes aren't changed, avoid saving.
744      */
745     if($this->gender=="0") $this->gender ="";
746     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
747     
748     /* First use parents methods to do some basic fillup in $this->attrs */
749     plugin::save ();
751     if ($this->use_dob == "1"){
752       /* 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. */
753       if(!is_array($this->attrs['dateOfBirth'])) {
754         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
755       }
756     }
758     /* Remove additional objectClasses */
759     $tmp= array();
760     foreach ($this->attrs['objectClass'] as $key => $set){
761       $found= false;
762       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
763         if (preg_match ("/^$set$/i", $val)){
764           $found= true;
765           break;
766         }
767       }
768       if (!$found){
769         $tmp[]= $set;
770       }
771     }
773     /* Replace the objectClass array. This is done because of the
774        separation into government and normal mode. */
775     $this->attrs['objectClass']= $tmp;
777     /* Add objectClasss for template mode? */
778     if ($this->is_template){
779       $this->attrs['objectClass'][]= "gosaUserTemplate";
780     }
782     /* Hard coded government mode? */
783     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
784       $this->attrs['objectClass'][]= "ivbbentry";
786       /* Copy standard attributes */
787       foreach ($this->govattrs as $val){
788         if ($this->$val != ""){
789           $this->attrs["$val"]= $this->$val;
790         } elseif (!$this->is_new) {
791           $this->attrs["$val"]= array();
792         }
793       }
795       /* Remove attribute if set to "nein" */
796       if ($this->publicVisible == "nein"){
797         $this->attrs['publicVisible']= array();
798         if($this->is_new){
799           unset($this->attrs['publicVisible']);
800         }else{
801           $this->attrs['publicVisible']=array();
802         }
804       }
806     }
808     /* Special handling for attribute userCertificate needed */
809     if ($this->userCertificate != ""){
810       $this->attrs["userCertificate;binary"]= $this->userCertificate;
811       $remove_userCertificate= false;
812     } else {
813       $remove_userCertificate= true;
814     }
816     /* Special handling for dateOfBirth value */
817     if ($this->use_dob != "1"){
818       if ($this->is_new) {
819         unset($this->attrs["dateOfBirth"]);
820       } else {
821         $this->attrs["dateOfBirth"]= array();
822       }
823     }
824     if (!$this->gender){
825       if ($this->is_new) {
826         unset($this->attrs["gender"]);
827       } else {
828         $this->attrs["gender"]= array();
829       }
830     }
831     if (!$this->preferredLanguage){
832       if ($this->is_new) {
833         unset($this->attrs["preferredLanguage"]);
834       } else {
835         $this->attrs["preferredLanguage"]= array();
836       }
837     }
839     /* Special handling for attribute jpegPhote needed, scale image via
840        image magick to 147x200 pixels and inject resulting data. */
841     if ($this->jpegPhoto == "*removed*"){
842     
843       /* Reset attribute to avoid writing *removed* as value */    
844       $this->attrs["jpegPhoto"] = array();
846     } else {
848       /* Fallback if there's no image magick inside PHP */
849       if (!function_exists("imagick_blob2image")){
850         /* Get temporary file name for conversation */
851         $fname = tempnam ("/tmp", "GOsa");
853         /* Open file and write out photoData */
854         $fp = fopen ($fname, "w");
855         fwrite ($fp, $this->photoData);
856         fclose ($fp);
858         /* Build conversation query. Filename is generated automatically, so
859            we do not need any special security checks. Exec command and save
860            output. For PHP safe mode, you'll need a configuration which respects
861            image magick as executable... */
862         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
863         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
864             $query, "Execute");
866         /* Read data written by convert */
867         $output= "";
868         $sh= popen($query, 'r');
869         while (!feof($sh)){
870           $output.= fread($sh, 4096);
871         }
872         pclose($sh);
874         unlink($fname);
876         /* Save attribute */
877         $this->attrs["jpegPhoto"] = $output;
879       } else {
881         /* Load the new uploaded Photo */
882         if(!$handle  =  imagick_blob2image($this->photoData))  {
883           new log("debug","users/".get_class($this),"",array(),"Could not access uploaded image");
884         }
886         /* Resizing image to 147x200 and blur */
887         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
888           new log("debug","users/".get_class($this),"",array(),"Could not resize uploaded image");
889         }
891         /* Converting image to JPEG */
892         if(!imagick_convert($handle,"JPEG")) {
893           new log("debug","users/".get_class($this),"",array(),"Could not convert uploaded image to jepg");
894         }
896         /* Creating binary Code for the Image */
897         if(!$dump = imagick_image2blob($handle)){
898           new log("debug","users/".get_class($this),"",array(),"Could not create new user image");
899         }
901         /* Sending Image */
902         $output=  $dump;
904         /* Save attribute */
905         $this->attrs["jpegPhoto"] = $output;
906       }
908     }
910     /* This only gets called when user is renaming himself */
911     $ldap= $this->config->get_ldap_link();
912     if ($this->dn != $this->new_dn){
914       /* Write entry on new 'dn' */
915       $this->update_acls($this->dn,$this->new_dn);
916       $this->move($this->dn, $this->new_dn);
918       /* Happen to use the new one */
919       change_ui_dn($this->dn, $this->new_dn);
920       $this->dn= $this->new_dn;
921     }
924     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
925        new entries. So do a check first... */
926     $ldap->cat ($this->dn, array('dn'));
927     if ($ldap->fetch()){
928       $mode= "modify";
929     } else {
930       $mode= "add";
931       $ldap->cd($this->config->current['BASE']);
932       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
933     }
935     /* Set password to some junk stuff in case of templates */
936     if ($this->is_template){
937       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
938     }
940     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
941         $this->attributes, "Save via $mode");
943     /* Finally write data with selected 'mode' */
944     $this->cleanup();
946     if(isset($this->attrs['preferredLanguage'])){
947       $_SESSION['ui']->language = $this->preferredLanguage;
948       $_SESSION['Last_init_lang'] = "update";
949     }
951     $ldap->cd ($this->dn);
952     $ldap->$mode ($this->attrs);
953     if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){
954       return (1);
955     }
958     /* Remove ACL dependencies too */
959     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
960       $tmp = new acl($this->config,$this->parent,$this->dn);
961       $tmp->update_acl_membership($this->orig_dn,$this->dn);
962     }
964     if($mode == "modify"){
965       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
966     }else{
967       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
968     }
970     /* Remove cert? 
971        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
972        to work around myself. */
973     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
975       /* Reset array, assemble new, this should be reworked */
976       $this->attrs= array();
977       $this->attrs['userCertificate;binary']= array();
979       /* Prepare connection */
980       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
981         die ("Could not connect to LDAP server");
982       }
983       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
984       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
985         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
986         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
987       }
988       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
989         ldap_start_tls($ds);
990       }
991       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
992               $this->config->current['PASSWORD']))) {
993         die ("Could not bind to LDAP");
994       }
996       /* Modify using attrs */
997       ldap_mod_del($ds,$this->dn,$this->attrs);
998       ldap_close($ds);
999     }
1001     /* If needed, let the password method do some cleanup */
1002     if ($this->pw_storage != $this->last_pw_storage){
1003       $tmp = new passwordMethod($_SESSION['config']);
1004       $available = $tmp->get_available_methods();
1005       if (in_array_ics($this->pw_storage, $available['name'])){
1006         $test= new $available[$this->pw_storage]($this->config);
1007         $test->attrs= $this->attrs;
1008         $test->dn= $this->dn;
1009         $test->remove_from_parent();
1010       }
1011     }
1013     /* Optionally execute a command after we're done */
1014     if ($mode == "add"){
1015       $this->handle_post_events("add", array("uid" => $this->uid));
1016     } elseif ($this->is_modified){
1017       $this->handle_post_events("modify", array("uid" => $this->uid));
1018     }
1020     /* Fix tagging if needed */
1021     $this->handle_object_tagging();
1023     return (0);
1024   }
1027   /* Check formular input */
1028   function check()
1029   {
1030     /* Call common method to give check the hook */
1031     $message= plugin::check();
1033     $pt= "";
1034     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1035       if(!empty($this->personalTitle)){
1036         $pt = $this->personalTitle." ";
1037       }
1038      }
1039     $this->cn= $pt.$this->givenName." ".$this->sn;
1041     /* Permissions for that base? */
1042     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1043       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1044     } else {
1045       /* Don't touch dn, if cn hasn't changed */
1046       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1047           $this->orig_base == $this->base ){
1048         $this->new_dn= $this->dn;
1049       } else {
1050         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1051       }
1052     }
1054     /* Set the new acl base */
1055     if($this->dn == "new") {
1056       $this->set_acl_base($this->base);
1057     }
1060     if(!$this->multiple_support_active){
1062       /* must: sn, givenName, uid */
1063       if ($this->sn == "" && ($this->acl_is_writeable("sn",(!is_object($this->parent) && !isset($_SESSION['edit'])) || ($this->is_new)))){
1064         $message[]= _("The required field 'Name' is not set.");
1065       }
1067       /* UID already used? */
1068       $ldap= $this->config->get_ldap_link();
1069       $ldap->cd($this->config->current['BASE']);
1070       $ldap->search("(uid=$this->uid)", array("uid"));
1071       $ldap->fetch();
1072       if ($ldap->count() != 0 && $this->dn == 'new'){
1073         $message[]= _("There's already a person with this 'Login' in the database.");
1074       }
1076       /* In template mode, the uid and givenName are autogenerated... */
1077       if (!$this->is_template){
1078         if ($this->givenName == "" && $this->acl_is_writeable("givenName",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
1079           $message[]= _("The required field 'Given name' is not set.");
1080         }
1081         if ($this->uid == "" && $this->acl_is_writeable("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
1082           $message[]= _("The required field 'Login' is not set.");
1083         }
1084         if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1085           $ldap->cat($this->new_dn);
1086           if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1087             $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
1088           }
1089         }
1090       }
1092       /* Check for valid input */
1093       if ($this->is_modified && !is_uid($this->uid)){
1094         $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
1095       }
1096       if (!is_url($this->labeledURI)){
1097         $message[]= _("The field 'Homepage' contains an invalid URL definition.");
1098       }
1099       if (preg_match ("/[\\\\]/", $this->sn)){
1100         $message[]= _("The field 'Name' contains invalid characters.");
1101       }
1102       if (preg_match ("/[\\\\]/", $this->givenName)){
1103         $message[]= _("The field 'Given name' contains invalid characters.");
1104       }
1105     }
1107     /* Check phone numbers */
1108     if (!is_phone_nr($this->telephoneNumber)){
1109       $message[]= _("The field 'Phone' contains an invalid phone number.");
1110     }
1111     if (!is_phone_nr($this->facsimileTelephoneNumber)){
1112       $message[]= _("The field 'Fax' contains an invalid phone number.");
1113     }
1114     if (!is_phone_nr($this->mobile)){
1115       $message[]= _("The field 'Mobile' contains an invalid phone number.");
1116     }
1117     if (!is_phone_nr($this->pager)){
1118       $message[]= _("The field 'Pager' contains an invalid phone number.");
1119     }
1121     /* Check for reserved characers */
1122     if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
1123       $message[]= _("The field 'Given name' contains invalid characters.");
1124     }
1125     if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
1126       $message[]= _("The field 'Name' contains invalid characters.");
1127     }
1129   return $message;
1130   }
1133   /* Indicate whether a password change is needed or not */
1134   function password_change_needed()
1135   {
1136     return($this->pw_storage != $this->last_pw_storage);
1137   }
1140   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1141   function load_picture()
1142   {
1143     $ldap = $this->config->get_ldap_link();
1144     $ldap->cd ($this->dn);
1145     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1146       
1147     if((!$data) || ($data == "*removed*")){ 
1149       /* In case we don't get an entry, load a default picture */
1150       $this->set_picture ();//"./images/default.jpg");
1151       $this->jpegPhoto= "*removed*";
1152     }else{
1154       /* Set picture */
1155       $this->photoData= $data;
1156       $_SESSION['binary']= $this->photoData;
1157       $_SESSION['binarytype']= "image/jpeg";
1158       $this->jpegPhoto= "";
1159     }
1160   }
1163   /* Load a certificate from LDAP, this is going to be simplified later on */
1164   function load_cert()
1165   {
1166     $ds= ldap_connect($this->config->current['SERVER']);
1167     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1168     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1169       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1170       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1171     }
1172     if(isset($this->config->current['TLS']) &&
1173         $this->config->current['TLS'] == "true"){
1175       ldap_start_tls($ds);
1176     }
1178     $r= ldap_bind($ds);
1179     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1181     if ($sr) {
1182       $ei= @ldap_first_entry($ds, $sr);
1183       
1184       if ($ei) {
1185         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1186           $this->userCertificate= "";
1187         } else {
1188           $this->userCertificate= $info[0];
1189         }
1190       }
1191     } else {
1192       $this->userCertificate= "";
1193     }
1195     ldap_unbind($ds);
1196   }
1199   /* Load picture from file to object */
1200   function set_picture($filename ="")
1201   {
1202     if (!is_file($filename) || $filename =="" ){
1203       $filename= "./images/default.jpg";
1204       $this->jpegPhoto= "*removed*";
1205     }
1207     $fd = fopen ($filename, "rb");
1208     $this->photoData= fread ($fd, filesize ($filename));
1209     $_SESSION['binary']= $this->photoData;
1210     $_SESSION['binarytype']= "image/jpeg";
1211     $this->jpegPhoto= "";
1213     fclose ($fd);
1214   }
1217   /* Load certificate from file to object */
1218   function set_cert($cert, $filename)
1219   {
1220     if(!$thsi->acl_is_writeable("Certificate",(!is_object($this->parent) && !isset($_SESSION['edit'])))) return;
1221     $fd = fopen ($filename, "rb");
1222     if (filesize($filename)>0) {
1223       $this->$cert= fread ($fd, filesize ($filename));
1224       fclose ($fd);
1225       $this->is_modified= TRUE;
1226     } else {
1227       print_red(_("Could not open specified certificate!"));
1228     }
1229   }
1231   /* Adapt from given 'dn' */
1232   function adapt_from_template($dn)
1233   {
1234     plugin::adapt_from_template($dn);
1236     /* Get base */
1237     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1239     if ($this->config->current['GOVERNMENTMODE']){
1241       /* Walk through govattrs */
1242       foreach ($this->govattrs as $val){
1244         if (isset($this->attrs["$val"][0])){
1246           /* If attribute is set, replace dynamic parts: 
1247              %sn, %givenName and %uid. Fill these in our local variables. */
1248           $value= $this->attrs["$val"][0];
1250           foreach (array("sn", "givenName", "uid") as $repl){
1251             if (preg_match("/%$repl/i", $value)){
1252               $value= preg_replace ("/%$repl/i",
1253                   $this->parent->$repl, $value);
1254             }
1255           }
1256           $this->$val= $value;
1257         }
1258       }
1259     }
1261     /* Get back uid/sn/givenName */
1262     if ($this->parent !== NULL){
1263       $this->uid= $this->parent->uid;
1264       $this->sn= $this->parent->sn;
1265       $this->givenName= $this->parent->givenName;
1266     }
1267   }
1269  
1270   /* This avoids that users move themselves out of their rights. 
1271    */
1272   function allowedBasesToMoveTo()
1273   {
1274     /* Get bases */
1275     $bases  = $this->get_allowed_bases();
1276     return($bases);
1277   } 
1280   function getCopyDialog()
1281   {
1282     $str = "";
1284     $_SESSION['binary'] = $this->photoData; 
1285     $_SESSION['binarytype']= "image/jpeg";
1287     /* Get random number for pictures */
1288     srand((double)microtime()*1000000); 
1289     $rand = rand(0, 10000);
1291     $smarty = get_smarty();
1293     $smarty->assign("passwordTodo","clear");
1295     if(isset($_POST['passwordTodo'])){
1296       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1297     }
1299     $smarty->assign("sn",       $this->sn);
1300     $smarty->assign("givenName",$this->givenName);
1301     $smarty->assign("uid",      $this->uid);
1302     $smarty->assign("rand",     $rand);
1303     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1306     $ret = array();
1307     $ret['string'] = $str;
1308     $ret['status'] = "";  
1309     return($ret);
1310   }
1312   function saveCopyDialog()
1313   {
1314     /* Set_acl_base */
1315     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1317     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1318       $this->set_picture($_FILES['picture_file']['tmp_name']);
1319     }
1321     /* Remove picture? */
1322     if (isset($_POST['picture_remove'])){
1323       $this->jpegPhoto= "*removed*";
1324       $this->set_picture ("./images/default.jpg");
1325       $this->is_modified= TRUE;
1326     }
1328     $attrs = array("uid","givenName","sn");
1329     foreach($attrs as $attr){
1330       if(isset($_POST[$attr])){
1331         $this->$attr = $_POST[$attr];
1332       }
1333     } 
1334   }
1337   function PrepareForCopyPaste($source)
1338   {
1339     plugin::PrepareForCopyPaste($source);
1341     /* Reset certificate information addepted from source user
1342        to avoid setting the same user certificate for the destination user. */
1343     $this->userPKCS12= "";
1344     $this->userSMIMECertificate= "";
1345     $this->userCertificate= "";
1346     $this->certificateSerialNumber= "";
1347     $this->old_certificateSerialNumber= "";
1348     $this->old_userPKCS12= "";
1349     $this->old_userSMIMECertificate= "";
1350     $this->old_userCertificate= "";
1351   }
1354   function plInfo()
1355   {
1356   
1357     $govattrs= array(
1358         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1359         "houseIdentifier"                           =>  _("House identifier"), 
1360         "vocation"                                  =>  _("Vocation"),
1361         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1362         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1363         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1364         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1365         "functionalTitle"                           =>  _("Functional title"),
1366         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1367         "publicVisible"                             =>  _("Public visible"),
1368         "street"                                    =>  _("Street"),
1369         "role"                                      =>  _("Role"),
1370         "postalCode"                                =>  _("Postal code"));
1372     $ret = array(
1373         "plShortName" => _("Generic"),
1374         "plDescription" => _("Generic user settings"),
1375         "plSelfModify"  => TRUE,
1376         "plDepends"     => array(),
1377         "plPriority"    => 1,
1378         "plSection"     => array("personal" => _("My account")),
1379         "plCategory"    => array("users" => array("description" => _("Users"),
1380                                                   "objectClass" => "gosaAccount")),
1382         "plProvidedAcls" => array(
1383           "base"              => _("Base"), 
1384           "userPassword"      => _("User password"), 
1385           "sn"                => _("Surename"),
1386           "givenName"         => _("Given name"),
1387           "uid"               => _("User identification"),
1388           "personalTitle"     => _("Personal title"),
1389           "academicTitle"     => _("Academic title"),
1390           "homePostalAddress" => _("Home postal address"),
1391           "homePhone"         => _("Home phone number"),
1392           "labeledURI"        => _("Homepage"),
1393           "o"                 => _("Organization"),
1394           "ou"                => _("Department"),
1395           "dateOfBirth"       => _("Date of birth"),
1396           "gender"            => _("Gender"),
1397           "preferredLanguage" => _("Preferred language"),
1398           "departmentNumber"  => _("Department number"),
1399           "employeeNumber"    => _("Employee number"),
1400           "employeeType"      => _("Employee type"),
1401           "l"                 => _("Location"),
1402           "st"                => _("State"),
1403           "userPicture"       => _("User picture"),
1404           "roomNumber"        => _("Room number"),
1405           "telephoneNumber"   => _("Telefon number"),
1406           "mobile"            => _("Mobile number"),
1407           "pager"             => _("Pager number"),
1408           "Certificate"        => _("User certificates"),
1410           "postalAddress"                => _("Postal address"),
1411           "facsimileTelephoneNumber"     => _("Fax number"))
1412         );
1414     /* Append government attributes if required */
1415       global $config;
1416     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1417       foreach($govattrs as $attr => $desc){
1418         $ret["plProvidedAcls"][$attr] = $desc;
1419       }
1420     }
1421     return($ret);
1422   }
1431   function get_values_to_update()
1432   {
1433     $ret = plugin::get_multi_edit_values();
1434     return($ret); 
1435   }
1438   function save_object_multiple()
1439   {
1440     foreach(array("pw_storage","base","edit_cert") as $attr){
1441       if(isset($_POST["use_".$attr])){
1442         $this->selected_edit_values[$attr] = TRUE;
1443       }else{
1444         $this->selected_edit_values[$attr] = FALSE;
1445       }
1446     }
1447   }
1450   function execute_multiple()
1451   {
1452     $smarty =get_smarty(); 
1453     $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
1454     $smarty->assign("preferredLanguage_list", $language);
1455     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
1456     $smarty->assign("base_select",      $this->base);
1458     /* Save government mode attributes */
1459     if (isset($this->config->current['GOVERNMENTMODE']) &&
1460         preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
1461       $smarty->assign("governmentmode", "true");
1462       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
1463           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
1464       $smarty->assign("ivbbmodes", $ivbbmodes);
1465       foreach ($this->govattrs as $val){
1466         $smarty->assign("$val", $this->$val);
1467         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
1468       }
1469     } else {
1470       $smarty->assign("governmentmode", "false");
1471     }
1473     $temp= passwordMethod::get_available_methods();
1474     $hashes = $temp['name'];
1475     $test= new $temp[$this->pw_storage]($this->config);
1476     $is_configurable= $test->is_configurable();
1477     $smarty->assign("pwmode", $hashes);
1478     $smarty->assign("pwmode_select", $this->pw_storage);
1479     $smarty->assign("pw_configurable", $is_configurable);
1481     foreach($this->attributes as $attr){
1482       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1483         $smarty->assign("use_".$attr,TRUE);
1484       }else{
1485         $smarty->assign("use_".$attr,FALSE);
1486       }
1487       $smarty->assign($attr,$this->$attr);
1488     }
1489     foreach(array("pw_storage","base","edit_cert") as $attr){
1490       if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
1491         $smarty->assign("use_".$attr,TRUE);
1492       }else{
1493         $smarty->assign("use_".$attr,FALSE);
1494       }
1495     }
1496     return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__))));
1497   }
1502 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1503 ?>