1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*!
24 \brief user plugin
25 \author Cajus Pollmeier <pollmeier@gonicus.de>
26 \version 2.00
27 \date 24.07.2003
29 This class provides the functionality to read and write all attributes
30 relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
31 from/to the LDAP. It does syntax checking and displays the formulars required.
32 */
34 class user extends plugin
35 {
36 /* Definitions */
37 var $plHeadline= "Generic";
38 var $plDescription= "Edit organizational user settings";
40 /* Plugin specific values */
41 var $base= "";
42 var $orig_base= "";
43 var $cn= "";
44 var $new_dn= "";
45 var $personalTitle= "";
46 var $academicTitle= "";
47 var $homePostalAddress= "";
48 var $homePhone= "";
49 var $labeledURI= "";
50 var $o= "";
51 var $ou= "";
52 var $departmentNumber= "";
53 var $employeeNumber= "";
54 var $employeeType= "";
55 var $roomNumber= "";
56 var $telephoneNumber= "";
57 var $facsimileTelephoneNumber= "";
58 var $mobile= "";
59 var $pager= "";
60 var $l= "";
61 var $st= "";
62 var $postalAddress= "";
63 var $dateOfBirth;
64 var $use_dob= "0";
65 var $gender="0";
66 var $preferredLanguage="0";
68 var $jpegPhoto= "*removed*";
69 var $photoData= "";
70 var $old_jpegPhoto= "";
71 var $old_photoData= "";
72 var $cert_dialog= FALSE;
73 var $picture_dialog= FALSE;
74 var $pwObject= NULL;
76 var $userPKCS12= "";
77 var $userSMIMECertificate= "";
78 var $userCertificate= "";
79 var $certificateSerialNumber= "";
80 var $old_certificateSerialNumber= "";
81 var $old_userPKCS12= "";
82 var $old_userSMIMECertificate= "";
83 var $old_userCertificate= "";
85 var $gouvernmentOrganizationalUnit= "";
86 var $houseIdentifier= "";
87 var $street= "";
88 var $postalCode= "";
89 var $vocation= "";
90 var $ivbbLastDeliveryCollective= "";
91 var $gouvernmentOrganizationalPersonLocality= "";
92 var $gouvernmentOrganizationalUnitDescription= "";
93 var $gouvernmentOrganizationalUnitSubjectArea= "";
94 var $functionalTitle= "";
95 var $role= "";
96 var $publicVisible= "";
98 var $orig_dn;
99 var $dialog;
101 /* variables to trigger password changes */
102 var $pw_storage= "md5";
103 var $last_pw_storage= "unset";
104 var $had_userCertificate= FALSE;
106 var $view_logged = FALSE;
108 /* attribute list for save action */
109 var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
110 "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
111 "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
112 "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
113 "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
115 var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
116 "gosaAccount");
118 /* attributes that are part of the government mode */
119 var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
120 "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
121 "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
122 "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
123 "postalCode");
125 var $multiple_support = TRUE;
127 var $governmentmode = FALSE;
129 /* constructor, if 'dn' is set, the node loads the given
130 'dn' from LDAP */
131 function user (&$config, $dn= NULL)
132 {
133 $this->config= $config;
134 /* Configuration is fine, allways */
135 if($this->config->get_cfg_value("governmentmode") == "true"){
136 $this->governmentmode = TRUE;
137 $this->attributes=array_merge($this->attributes,$this->govattrs);
138 }
140 /* Load base attributes */
141 plugin::plugin ($config, $dn);
143 $this->orig_dn = $this->dn;
144 $this->new_dn = $dn;
146 if ($this->governmentmode){
147 /* Fix public visible attribute if unset */
148 if (!isset($this->attrs['publicVisible'])){
149 $this->publicVisible == "nein";
150 }
151 }
153 /* Load government mode attributes */
154 if ($this->governmentmode){
155 /* Copy all attributs */
156 foreach ($this->govattrs as $val){
157 if (isset($this->attrs["$val"][0])){
158 $this->$val= $this->attrs["$val"][0];
159 }
160 }
161 }
163 /* Create me for new accounts */
164 if ($dn == "new"){
165 $this->is_account= TRUE;
166 }
168 /* Make hash default to md5 if not set in config */
169 $hash= $this->config->get_cfg_value("hash", "crypt/md5");
171 /* Load data from LDAP? */
172 if ($dn !== NULL){
174 /* Do base conversation */
175 if ($this->dn == "new"){
176 $ui= get_userinfo();
177 $this->base= dn2base($ui->dn);
178 } else {
179 $this->base= dn2base($dn);
180 }
182 /* get password storage type */
183 if (isset ($this->attrs['userPassword'][0])){
184 /* Initialize local array */
185 $matches= array();
186 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
187 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
188 if(is_object($tmp)){
189 $this->pw_storage= $tmp->get_hash();
190 }
192 } else {
193 if ($this->attrs['userPassword'][0] != ""){
194 $this->pw_storage= "clear";
195 } else {
196 $this->pw_storage= $hash;
197 }
198 }
199 } else {
200 /* Preset with vaule from configuration */
201 $this->pw_storage= $hash;
202 }
204 /* Load extra attributes: certificate and picture */
205 $this->load_cert();
206 $this->load_picture();
207 if ($this->userCertificate != ""){
208 $this->had_userCertificate= TRUE;
209 }
210 }
212 /* Reset password storage indicator, used by password_change_needed() */
213 if ($dn == "new"){
214 $this->last_pw_storage= "unset";
215 } else {
216 $this->last_pw_storage= $this->pw_storage;
217 }
219 /* Generate dateOfBirth entry */
220 if (isset ($this->attrs['dateOfBirth'])){
221 /* This entry is ISO 8601 conform */
222 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
224 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
225 $this->use_dob= "1";
226 } else {
227 $this->use_dob= "0";
228 }
230 /* Put gender attribute to upper case */
231 if (isset ($this->attrs['gender'])){
232 $this->gender= strtoupper($this->attrs['gender'][0]);
233 }
235 $this->orig_base = $this->base;
236 }
241 /* execute generates the html output for this node */
242 function execute()
243 {
244 /* Call parent execute */
245 plugin::execute();
247 /* Log view */
248 if($this->is_account && !$this->view_logged){
249 $this->view_logged = TRUE;
250 new log("view","users/".get_class($this),$this->dn);
251 }
253 $smarty= get_smarty();
255 /* Fill calendar */
256 if ($this->dateOfBirth == "0"){
257 $date= getdate();
258 } else {
259 if(is_array($this->dateOfBirth)){
260 $date = $this->dateOfBirth;
262 // Trigger on dates like 1985-04-01, getdate only understands timestamps
263 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
264 $date= getdate(strtotime($this->dateOfBirth));
266 } else {
267 $date = getdate($this->dateOfBirth);
268 }
269 }
271 $days= array();
272 for($d= 1; $d<32; $d++){
273 $days[$d]= $d;
274 }
275 $years= array();
277 if(($date['year']-100)<1901){
278 $start = 1901;
279 }else{
280 $start = $date['year']-100;
281 }
283 $end = $start +100;
285 for($y= $start; $y<=$end; $y++){
286 $years[]= $y;
287 }
288 $years['-']= "- ";
289 $months= msgPool::months();
290 $months['-'] = '- ';
292 $smarty->assign("day", $date["mday"]);
293 $smarty->assign("days", $days);
294 $smarty->assign("months", $months);
295 $smarty->assign("month", $date["mon"]-1);
296 $smarty->assign("years", $years);
297 $smarty->assign("year", $date["year"]);
299 /* Assign sex */
300 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
301 $smarty->assign("gender_list", $sex);
302 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
303 $smarty->assign("preferredLanguage_list", $language);
305 /* Get random number for pictures */
306 srand((double)microtime()*1000000);
307 $smarty->assign("rand", rand(0, 10000));
310 /* Do we represent a valid gosaAccount? */
311 if (!$this->is_account){
312 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
313 msgPool::noValidExtension("GOsa")."</b>";
314 return($str);
315 }
317 /* Base select dialog */
318 $once = true;
319 foreach($_POST as $name => $value){
320 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
321 $once = false;
322 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
323 $this->dialog->setCurrentBase($this->base);
324 }
325 }
327 /* Password configure dialog handling */
328 if(is_object($this->pwObject) && $this->pwObject->display){
329 $output= $this->pwObject->configure();
330 if ($output != ""){
331 $this->dialog= TRUE;
332 return $output;
333 }
334 $this->dialog= false;
335 }
337 /* Dialog handling */
338 if(is_object($this->dialog)){
339 /* Must be called before save_object */
340 $this->dialog->save_object();
342 if($this->dialog->isClosed()){
343 $this->dialog = false;
344 }elseif($this->dialog->isSelected()){
346 /* check if selected base is allowed to move to / create a new object */
347 $tmp = $this->get_allowed_bases();
348 if(isset($tmp[$this->dialog->isSelected()])){
349 $this->base = $this->dialog->isSelected();
350 }
351 $this->dialog= false;
352 }else{
353 return($this->dialog->execute());
354 }
355 }
357 /* Want password method editing? */
358 if ($this->acl_is_writeable("userPassword")){
359 if (isset($_POST['edit_pw_method'])){
360 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
361 $temp= passwordMethod::get_available_methods();
362 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
363 }
364 $this->pwObject->display = TRUE;
365 $this->dialog= TRUE;
366 return ($this->pwObject->configure());
367 }
368 }
370 /* Want picture edit dialog? */
371 if($this->acl_is_writeable("userPicture")) {
372 if (isset($_POST['edit_picture'])){
373 /* Save values for later recovery, in case some presses
374 the cancel button. */
375 $this->old_jpegPhoto= $this->jpegPhoto;
376 $this->old_photoData= $this->photoData;
377 $this->picture_dialog= TRUE;
378 $this->dialog= TRUE;
379 }
380 }
382 /* Remove picture? */
383 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
384 if (isset($_POST['picture_remove'])){
385 $this->set_picture ();
386 $this->jpegPhoto= "*removed*";
387 $this->is_modified= TRUE;
388 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
389 }
390 }
392 /* Save picture */
393 if (isset($_POST['picture_edit_finish'])){
395 /* Check for clean upload */
396 if ($_FILES['picture_file']['name'] != ""){
397 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
398 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
399 }else{
400 /* Activate new picture */
401 $this->set_picture($_FILES['picture_file']['tmp_name']);
402 }
403 }
404 $this->picture_dialog= FALSE;
405 $this->dialog= FALSE;
406 $this->is_modified= TRUE;
407 }
410 /* Cancel picture */
411 if (isset($_POST['picture_edit_cancel'])){
413 /* Restore values */
414 $this->jpegPhoto= $this->old_jpegPhoto;
415 $this->photoData= $this->old_photoData;
417 /* Update picture */
418 session::set('binary',$this->photoData);
419 session::set('binarytype',"image/jpeg");
420 $this->picture_dialog= FALSE;
421 $this->dialog= FALSE;
422 }
424 /* Toggle dateOfBirth information */
425 if (isset($_POST['set_dob'])){
426 $this->use_dob= ($this->use_dob == "0")?"1":"0";
427 }
430 /* Want certificate= */
431 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
433 /* Save original values for later reconstruction */
434 foreach (array("certificateSerialNumber", "userCertificate",
435 "userSMIMECertificate", "userPKCS12") as $val){
437 $oval= "old_$val";
438 $this->$oval= $this->$val;
439 }
441 $this->cert_dialog= TRUE;
442 $this->dialog= TRUE;
443 }
446 /* Cancel certificate dialog */
447 if (isset($_POST['cert_edit_cancel'])){
449 /* Restore original values in case of 'cancel' */
450 foreach (array("certificateSerialNumber", "userCertificate",
451 "userSMIMECertificate", "userPKCS12") as $val){
453 $oval= "old_$val";
454 $this->$val= $this->$oval;
455 }
456 $this->cert_dialog= FALSE;
457 $this->dialog= FALSE;
458 }
461 /* Remove certificate? */
462 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
463 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
464 if (isset($_POST["remove_$val"])){
466 /* Reset specified cert*/
467 $this->$val= "";
468 $this->is_modified= TRUE;
469 }
470 }
471 }
473 /* Upload new cert and close dialog? */
474 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
476 $fail =false;
478 if (isset($_POST['cert_edit_finish'])){
480 /* for all certificates do */
481 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
482 as $val){
484 /* Check for clean upload */
485 if (array_key_exists($val."_file", $_FILES) &&
486 array_key_exists('name', $_FILES[$val."_file"]) &&
487 $_FILES[$val."_file"]['name'] != "" &&
488 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
489 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
490 }
491 }
493 /* Save serial number */
494 if (isset($_POST["certificateSerialNumber"]) &&
495 $_POST["certificateSerialNumber"] != ""){
497 if (!tests::is_id($_POST["certificateSerialNumber"])){
498 $fail = true;
499 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
501 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
502 if ($this->$cert != ""){
503 $smarty->assign("$cert"."_state", "true");
504 } else {
505 $smarty->assign("$cert"."_state", "");
506 }
507 }
508 }
510 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
511 $this->is_modified= TRUE;
512 }
513 if(!$fail){
514 $this->cert_dialog= FALSE;
515 $this->dialog= FALSE;
516 }
517 }
518 }
519 /* Display picture dialog */
520 if ($this->picture_dialog){
521 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
522 }
524 /* Display cert dialog */
525 if ($this->cert_dialog){
526 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
527 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
528 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
530 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
531 if ($this->$cert != ""){
532 /* import certificate */
533 $certificate = new certificate;
534 $certificate->import($this->$cert);
536 /* Read out data*/
537 $timeto = $certificate->getvalidto_date();
538 $timefrom = $certificate->getvalidfrom_date();
541 /* Additional info if start end time is '0' */
542 $add_str_info = "";
543 if($timeto == 0 && $timefrom == 0){
544 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
545 }
547 $str = "<table summary=\"\" border=0>
548 <tr>
549 <td style='vertical-align:top'>CN</td>
550 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
551 </tr>
552 </table><br>".
554 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
555 "<b>".date('d M Y',$timefrom)."</b>",
556 "<b>".date('d M Y',$timeto)."</b>",
557 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
558 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
560 $smarty->assign($cert."info",$str);
561 $smarty->assign($cert."_state","true");
562 } else {
563 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
564 $smarty->assign($cert."_state","");
565 }
566 }
568 if($this->governmentmode){
569 $smarty->assign("governmentmode", "true");
570 }else{
571 $smarty->assign("governmentmode", "false");
572 }
573 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
574 }
576 /* Prepare password hashes */
577 if ($this->pw_storage == ""){
578 $this->pw_storage= $this->config->get_cfg_value("hash");
579 }
581 $temp= passwordMethod::get_available_methods();
582 $is_configurable= FALSE;
583 $hashes = $temp['name'];
584 if(isset($temp[$this->pw_storage])){
585 $test= new $temp[$this->pw_storage]($this->config);
586 $is_configurable= $test->is_configurable();
587 }else{
588 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
589 }
592 /* Create password methods array */
593 $pwd_methods = array();
594 foreach($hashes as $id => $name){
595 if(!empty($temp['desc'][$id])){
596 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
597 }else{
598 $pwd_methods[$name] = $name;
599 }
600 }
602 /* Load attributes and acl's */
603 $ui =get_userinfo();
604 foreach($this->attributes as $val){
605 $smarty->assign("$val", $this->$val);
606 if(in_array($val,$this->multi_boxes)){
607 $smarty->assign("use_".$val,TRUE);
608 }else{
609 $smarty->assign("use_".$val,FALSE);
610 }
611 }
612 foreach(array("base","pw_storage","edit_picture") as $val){
613 if(in_array($val,$this->multi_boxes)){
614 $smarty->assign("use_".$val,TRUE);
615 }else{
616 $smarty->assign("use_".$val,FALSE);
617 }
618 }
620 /* Set acls */
621 $tmp = $this->plinfo();
622 foreach($tmp['plProvidedAcls'] as $val => $translation){
623 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
624 }
626 $smarty->assign("pwmode", $pwd_methods);
627 $smarty->assign("pwmode_select", $this->pw_storage);
628 $smarty->assign("pw_configurable", $is_configurable);
629 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
630 $smarty->assign("base_select", $this->base);
632 if(!session::is_set('edit')){
633 $smarty->assign("CertificatesACL","");
634 }else{
635 $smarty->assign("CertificatesACL", $this->getacl("Certificate"));
636 }
638 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
639 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
641 /* Create base acls */
642 $tmp = @$this->allowedBasesToMoveTo();
643 $smarty->assign("bases", $tmp);
645 /* Save government mode attributes */
646 if($this->governmentmode){
647 $smarty->assign("governmentmode", "true");
648 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
649 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
650 $smarty->assign("ivbbmodes", $ivbbmodes);
651 foreach ($this->govattrs as $val){
652 $smarty->assign("$val", $this->$val);
653 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
654 }
655 } else {
656 $smarty->assign("governmentmode", "false");
657 }
659 /* Special mode for uid */
660 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
661 if (isset ($this->dn)){
662 if ($this->dn != "new"){
663 $uidACL= preg_replace("/w/","",$uidACL);
664 }
665 } else {
666 $uidACL= preg_replace("/w/","",$uidACL);
667 }
669 $smarty->assign("uidACL", $uidACL);
670 $smarty->assign("is_template", $this->is_template);
671 $smarty->assign("use_dob", $this->use_dob);
673 if (isset($this->parent)){
674 if (isset($this->parent->by_object['phoneAccount']) &&
675 $this->parent->by_object['phoneAccount']->is_account){
676 $smarty->assign("has_phoneaccount", "true");
677 } else {
678 $smarty->assign("has_phoneaccount", "false");
679 }
680 } else {
681 $smarty->assign("has_phoneaccount", "false");
682 }
683 $smarty->assign("multiple_support" , $this->multiple_support_active);
684 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
685 }
688 /* remove object from parent */
689 function remove_from_parent()
690 {
691 /* Remove password extension */
692 $temp= passwordMethod::get_available_methods();
694 /* Remove password method from user account */
695 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
696 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
697 $this->pwObject->remove_from_parent();
698 }
700 /* Remove user */
701 $ldap= $this->config->get_ldap_link();
702 $ldap->rmdir ($this->dn);
703 if (!$ldap->success()){
704 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
705 }
707 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
709 /* Delete references to groups */
710 $ldap->cd ($this->config->current['BASE']);
711 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
712 while ($ldap->fetch()){
713 $g= new group($this->config, $ldap->getDN());
714 $g->removeUser($this->uid);
715 $g->save ();
716 }
718 /* Delete references to object groups */
719 $ldap->cd ($this->config->current['BASE']);
720 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
721 while ($ldap->fetch()){
722 $og= new ogroup($this->config, $ldap->getDN());
723 unset($og->member[$this->dn]);
724 $og->save ();
725 }
727 /* If needed, let the password method do some cleanup */
728 $tmp = new passwordMethod($this->config);
729 $available = $tmp->get_available_methods();
730 if (in_array_ics($this->pw_storage, $available['name'])){
731 $test= new $available[$this->pw_storage]($this->config);
732 $test->attrs= $this->attrs;
733 $test->dn= $this->dn;
734 $test->remove_from_parent();
735 }
737 /* Remove ACL dependencies too */
738 $tmp = new acl($this->config,$this->parent,$this->dn);
739 $tmp->remove_acl();
741 /* Optionally execute a command after we're done */
742 $this->handle_post_events("remove",array("uid" => $this->uid));
743 }
746 /* Save data to object */
747 function save_object()
748 {
749 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
751 /* Make a backup of the current selected base */
752 $base_tmp = $this->base;
754 /* Parents save function */
755 plugin::save_object ();
757 /* Save government mode attributes */
758 if ($this->governmentmode){
759 foreach ($this->govattrs as $val){
760 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
761 $data= stripcslashes($_POST["$val"]);
762 if ($data != $this->$val){
763 $this->is_modified= TRUE;
764 }
765 $this->$val= $data;
766 }
767 }
768 }
770 /* In template mode, the uid is autogenerated... */
771 if ($this->is_template){
772 $this->uid= strtolower($this->sn);
773 $this->givenName= $this->sn;
774 }
776 /* Save base and pw_storage, since these are no LDAP attributes */
777 if (isset($_POST['base'])){
779 $tmp = $this->get_allowed_bases();
780 if(isset($tmp[$_POST['base']])){
781 $base= validate($_POST['base']);
782 if ($base != $this->base){
783 $this->is_modified= TRUE;
784 }
785 $this->base= $base;
786 }else{
787 $this->base = $base_tmp;
788 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
789 }
790 }
792 /* Get pw_storage mode */
793 if (isset($_POST['pw_storage'])){
794 foreach(array("pw_storage") as $val){
795 if(isset($_POST[$val])){
796 $data= validate($_POST[$val]);
797 if ($data != $this->$val){
798 $this->is_modified= TRUE;
799 }
800 $this->$val= $data;
801 }
802 }
803 }
805 /* Save current cn
806 */
807 $this->cn = $this->givenName." ".$this->sn;
808 }
809 }
811 function rebind($ldap, $referral)
812 {
813 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
814 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
815 $this->error = "Success";
816 $this->hascon=true;
817 $this->reconnect= true;
818 return (0);
819 } else {
820 $this->error = "Could not bind to " . $credentials['ADMIN'];
821 return NULL;
822 }
823 }
826 /* Save data to LDAP, depending on is_account we save or delete */
827 function save()
828 {
829 /* Only force save of changes ....
830 If this attributes aren't changed, avoid saving.
831 */
832 if($this->gender=="0") $this->gender ="";
833 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
835 /* First use parents methods to do some basic fillup in $this->attrs */
836 plugin::save ();
838 if ($this->use_dob == "1"){
839 /* 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. */
840 if(!is_array($this->attrs['dateOfBirth'])) {
841 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
842 }
843 }
845 /* Remove additional objectClasses */
846 $tmp= array();
847 foreach ($this->attrs['objectClass'] as $key => $set){
848 $found= false;
849 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
850 if (preg_match ("/^$set$/i", $val)){
851 $found= true;
852 break;
853 }
854 }
855 if (!$found){
856 $tmp[]= $set;
857 }
858 }
860 /* Replace the objectClass array. This is done because of the
861 separation into government and normal mode. */
862 $this->attrs['objectClass']= $tmp;
864 /* Add objectClasss for template mode? */
865 if ($this->is_template){
866 $this->attrs['objectClass'][]= "gosaUserTemplate";
867 }
869 /* Hard coded government mode? */
870 if ($this->governmentmode){
871 $this->attrs['objectClass'][]= "ivbbentry";
873 /* Copy standard attributes */
874 foreach ($this->govattrs as $val){
875 if ($this->$val != ""){
876 $this->attrs["$val"]= $this->$val;
877 } elseif (!$this->is_new) {
878 $this->attrs["$val"]= array();
879 }
880 }
882 /* Remove attribute if set to "nein" */
883 if ($this->publicVisible == "nein"){
884 $this->attrs['publicVisible']= array();
885 if($this->is_new){
886 unset($this->attrs['publicVisible']);
887 }else{
888 $this->attrs['publicVisible']=array();
889 }
891 }
893 }
895 /* Special handling for attribute userCertificate needed */
896 if ($this->userCertificate != ""){
897 $this->attrs["userCertificate;binary"]= $this->userCertificate;
898 $remove_userCertificate= false;
899 } else {
900 $remove_userCertificate= true;
901 }
903 /* Special handling for dateOfBirth value */
904 if ($this->use_dob != "1"){
905 if ($this->is_new) {
906 unset($this->attrs["dateOfBirth"]);
907 } else {
908 $this->attrs["dateOfBirth"]= array();
909 }
910 }
911 if (!$this->gender){
912 if ($this->is_new) {
913 unset($this->attrs["gender"]);
914 } else {
915 $this->attrs["gender"]= array();
916 }
917 }
918 if (!$this->preferredLanguage){
919 if ($this->is_new) {
920 unset($this->attrs["preferredLanguage"]);
921 } else {
922 $this->attrs["preferredLanguage"]= array();
923 }
924 }
926 /* Special handling for attribute jpegPhote needed, scale image via
927 image magick to 147x200 pixels and inject resulting data. */
928 if ($this->jpegPhoto == "*removed*"){
930 /* Reset attribute to avoid writing *removed* as value */
931 $this->attrs["jpegPhoto"] = array();
933 } else {
935 /* Fallback if there's no image magick inside PHP */
936 if (!function_exists("imagick_blob2image")){
937 /* Get temporary file name for conversation */
938 $fname = tempnam (TEMP_DIR, "GOsa");
940 /* Open file and write out photoData */
941 $fp = fopen ($fname, "w");
942 fwrite ($fp, $this->photoData);
943 fclose ($fp);
945 /* Build conversation query. Filename is generated automatically, so
946 we do not need any special security checks. Exec command and save
947 output. For PHP safe mode, you'll need a configuration which respects
948 image magick as executable... */
949 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
950 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
951 $query, "Execute");
953 /* Read data written by convert */
954 $output= "";
955 $sh= popen($query, 'r');
956 while (!feof($sh)){
957 $output.= fread($sh, 4096);
958 }
959 pclose($sh);
961 unlink($fname);
963 /* Save attribute */
964 $this->attrs["jpegPhoto"] = $output;
966 } else {
968 /* Load the new uploaded Photo */
969 if(!$handle = imagick_blob2image($this->photoData)) {
970 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
971 }
973 /* Resizing image to 147x200 and blur */
974 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
975 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
976 }
978 /* Converting image to JPEG */
979 if(!imagick_convert($handle,"JPEG")) {
980 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
981 }
983 /* Creating binary Code for the Image */
984 if(!$dump = imagick_image2blob($handle)){
985 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
986 }
988 /* Sending Image */
989 $output= $dump;
991 /* Save attribute */
992 $this->attrs["jpegPhoto"] = $output;
993 }
995 }
997 /* This only gets called when user is renaming himself */
998 $ldap= $this->config->get_ldap_link();
999 if ($this->dn != $this->new_dn){
1001 /* Write entry on new 'dn' */
1002 $this->update_acls($this->dn,$this->new_dn);
1003 $this->move($this->dn, $this->new_dn);
1005 /* Happen to use the new one */
1006 change_ui_dn($this->dn, $this->new_dn);
1007 $this->dn= $this->new_dn;
1008 }
1011 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1012 new entries. So do a check first... */
1013 $ldap->cat ($this->dn, array('dn'));
1014 if ($ldap->fetch()){
1015 $mode= "modify";
1016 } else {
1017 $mode= "add";
1018 $ldap->cd($this->config->current['BASE']);
1019 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1020 }
1022 /* Set password to some junk stuff in case of templates */
1023 if ($this->is_template){
1024 $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1025 }
1027 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1028 $this->attributes, "Save via $mode");
1030 /* Finally write data with selected 'mode' */
1031 $this->cleanup();
1033 if(isset($this->attrs['preferredLanguage'])){
1034 $ui = session::get('ui');
1035 $ui->language = $this->preferredLanguage;
1036 session::set('ui',$ui);
1037 session::set('Last_init_lang',"update");
1038 }
1040 $ldap->cd ($this->dn);
1041 $ldap->$mode ($this->attrs);
1042 if (!$ldap->success()){
1043 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1044 return (1);
1045 }
1047 /* Remove ACL dependencies too */
1048 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1049 $tmp = new acl($this->config,$this->parent,$this->dn);
1050 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1051 }
1053 if($mode == "modify"){
1054 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1055 }else{
1056 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1057 }
1059 /* Remove cert?
1060 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1061 to work around myself. */
1062 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1064 /* Reset array, assemble new, this should be reworked */
1065 $this->attrs= array();
1066 $this->attrs['userCertificate;binary']= array();
1068 /* Prepare connection */
1069 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1070 die ("Could not connect to LDAP server");
1071 }
1072 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1073 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("recursive") == "true") {
1074 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1075 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1076 }
1077 if($this->config->get_cfg_value("tls") == "true"){
1078 ldap_start_tls($ds);
1079 }
1080 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1081 $this->config->current['PASSWORD']))) {
1082 die ("Could not bind to LDAP");
1083 }
1085 /* Modify using attrs */
1086 ldap_mod_del($ds,$this->dn,$this->attrs);
1087 ldap_close($ds);
1088 }
1090 /* If needed, let the password method do some cleanup */
1091 if ($this->pw_storage != $this->last_pw_storage){
1092 $tmp = new passwordMethod($this->config);
1093 $available = $tmp->get_available_methods();
1094 if (in_array_ics($this->last_pw_storage, $available['name'])){
1095 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1096 $test->attrs= $this->attrs;
1097 $test->remove_from_parent();
1098 }
1099 }
1101 /* Maybe the current password method want's to do some changes... */
1102 if (is_object($this->pwObject)){
1103 $this->pwObject->save($this->dn);
1104 }
1106 /* Optionally execute a command after we're done */
1107 if ($mode == "add"){
1108 $this->handle_post_events("add", array("uid" => $this->uid));
1109 } elseif ($this->is_modified){
1110 $this->handle_post_events("modify", array("uid" => $this->uid));
1111 }
1113 return (0);
1114 }
1117 function update_new_dn()
1118 {
1119 $pt= "";
1120 if($this->config->get_cfg_value("include_personal_title") == "true"){
1121 if(!empty($this->personalTitle)){
1122 $pt = $this->personalTitle." ";
1123 }
1124 }
1125 $this->cn= $pt.$this->givenName." ".$this->sn;
1127 /* Permissions for that base? */
1128 if ($this->config->get_cfg_value("dnmode") == "uid"){
1129 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1130 } else {
1131 /* Don't touch dn, if cn hasn't changed */
1132 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1133 $this->orig_base == $this->base ){
1134 $this->new_dn= $this->dn;
1135 } else {
1136 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1137 }
1138 }
1139 }
1142 /* Check formular input */
1143 function check()
1144 {
1145 /* Call common method to give check the hook */
1146 $message= plugin::check();
1148 /* Configurable password methods should be configured initially.
1149 */
1150 if($this->last_pw_storage != $this->pw_storage){
1151 $temp= passwordMethod::get_available_methods();
1152 foreach($temp['name'] as $id => $name){
1153 if($name == $this->pw_storage){
1154 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1155 $message[] = _("The selected password method requires initial configuration!");
1156 }
1157 break;
1158 }
1159 }
1160 }
1162 $this->update_new_dn();
1164 /* Set the new acl base */
1165 if($this->dn == "new") {
1166 $this->set_acl_base($this->base);
1167 }
1169 /* Check if we are allowed to create/move this user
1170 */
1172 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1173 $message[]= msgPool::permCreate();
1174 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1175 $message[]= msgPool::permMove();
1176 }
1178 /* UID already used? */
1179 $ldap= $this->config->get_ldap_link();
1180 $ldap->cd($this->config->current['BASE']);
1181 $ldap->search("(uid=$this->uid)", array("uid"));
1182 $ldap->fetch();
1183 if ($ldap->count() != 0 && $this->dn == 'new'){
1184 $message[]= msgPool::duplicated(_("Login"));
1185 }
1187 /* In template mode, the uid and givenName are autogenerated... */
1188 if ($this->sn == ""){
1189 $message[]= msgPool::required(_("Name"));
1190 }
1192 if (!$this->is_template){
1193 if ($this->givenName == ""){
1194 $message[]= msgPool::required(_("Given name"));
1195 }
1196 if ($this->uid == ""){
1197 $message[]= msgPool::required(_("Login"));
1198 }
1199 if ($this->config->get_cfg_value("dnmode") != "uid"){
1200 $ldap->cat($this->new_dn);
1201 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1202 $message[]= msgPool::duplicated(_("Name"));
1203 }
1204 }
1205 }
1207 /* Check for valid input */
1208 if ($this->is_modified && !tests::is_uid($this->uid)){
1210 if (strict_uid_mode()){
1211 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1212 } else {
1213 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1214 }
1215 }
1216 if (!tests::is_url($this->labeledURI)){
1217 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1218 }
1220 /* Check phone numbers */
1221 if (!tests::is_phone_nr($this->telephoneNumber)){
1222 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1223 }
1224 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1225 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1226 }
1227 if (!tests::is_phone_nr($this->mobile)){
1228 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1229 }
1230 if (!tests::is_phone_nr($this->pager)){
1231 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1232 }
1234 /* Check for reserved characers */
1235 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1236 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1237 }
1238 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1239 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1240 }
1242 return $message;
1243 }
1246 /* Indicate whether a password change is needed or not */
1247 function password_change_needed()
1248 {
1249 if(in_array("pw_storage",$this->multi_boxes)){
1250 return(TRUE);
1251 }
1252 return($this->pw_storage != $this->last_pw_storage);
1253 }
1256 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1257 function load_picture()
1258 {
1259 $ldap = $this->config->get_ldap_link();
1260 $ldap->cd ($this->dn);
1261 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1263 if((!$data) || ($data == "*removed*")){
1265 /* In case we don't get an entry, load a default picture */
1266 $this->set_picture ();
1267 $this->jpegPhoto= "*removed*";
1268 }else{
1270 /* Set picture */
1271 $this->photoData= $data;
1272 session::set('binary',$this->photoData);
1273 session::set('binarytype',"image/jpeg");
1274 $this->jpegPhoto= "";
1275 }
1276 }
1279 /* Load a certificate from LDAP, this is going to be simplified later on */
1280 function load_cert()
1281 {
1282 $ds= ldap_connect($this->config->current['SERVER']);
1283 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1284 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("recursive") == "true"){
1285 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1286 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1287 }
1288 if ($this->config->get_cfg_value("tls") == "true"){
1289 ldap_start_tls($ds);
1290 }
1292 $r= ldap_bind($ds);
1293 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1295 if ($sr) {
1296 $ei= @ldap_first_entry($ds, $sr);
1298 if ($ei) {
1299 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1300 $this->userCertificate= "";
1301 } else {
1302 $this->userCertificate= $info[0];
1303 }
1304 }
1305 } else {
1306 $this->userCertificate= "";
1307 }
1309 ldap_unbind($ds);
1310 }
1313 /* Load picture from file to object */
1314 function set_picture($filename ="")
1315 {
1316 if (!is_file($filename) || $filename =="" ){
1317 $filename= "./plugins/users/images/default.jpg";
1318 $this->jpegPhoto= "*removed*";
1319 }
1321 $fd = fopen ($filename, "rb");
1322 $this->photoData= fread ($fd, filesize ($filename));
1323 session::set('binary',$this->photoData);
1324 session::set('binarytype',"image/jpeg");
1325 $this->jpegPhoto= "";
1327 fclose ($fd);
1328 }
1331 /* Load certificate from file to object */
1332 function set_cert($cert, $filename)
1333 {
1334 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1335 $fd = fopen ($filename, "rb");
1336 if (filesize($filename)>0) {
1337 $this->$cert= fread ($fd, filesize ($filename));
1338 fclose ($fd);
1339 $this->is_modified= TRUE;
1340 } else {
1341 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1342 }
1343 }
1345 /* Adapt from given 'dn' */
1346 function adapt_from_template($dn, $skip= array())
1347 {
1348 plugin::adapt_from_template($dn, $skip);
1350 /* Get base */
1351 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1353 if($this->governmentmode){
1355 /* Walk through govattrs */
1356 foreach ($this->govattrs as $val){
1358 if (in_array($val, $skip)){
1359 continue;
1360 }
1362 if (isset($this->attrs["$val"][0])){
1364 /* If attribute is set, replace dynamic parts:
1365 %sn, %givenName and %uid. Fill these in our local variables. */
1366 $value= $this->attrs["$val"][0];
1368 foreach (array("sn", "givenName", "uid") as $repl){
1369 if (preg_match("/%$repl/i", $value)){
1370 $value= preg_replace ("/%$repl/i",
1371 $this->parent->$repl, $value);
1372 }
1373 }
1374 $this->$val= $value;
1375 }
1376 }
1377 }
1379 /* Get back uid/sn/givenName - only write if nothing's skipped */
1380 if ($this->parent !== NULL && count($skip) == 0){
1381 $this->uid= $this->parent->uid;
1382 $this->sn= $this->parent->sn;
1383 $this->givenName= $this->parent->givenName;
1384 }
1385 }
1388 /* This avoids that users move themselves out of their rights.
1389 */
1390 function allowedBasesToMoveTo()
1391 {
1392 /* Get bases */
1393 $bases = $this->get_allowed_bases();
1394 return($bases);
1395 }
1398 function getCopyDialog()
1399 {
1400 $str = "";
1402 session::set('binary',$this->photoData);
1403 session::set('binarytype',"image/jpeg");
1405 /* Get random number for pictures */
1406 srand((double)microtime()*1000000);
1407 $rand = rand(0, 10000);
1409 $smarty = get_smarty();
1411 $smarty->assign("passwordTodo","clear");
1413 if(isset($_POST['passwordTodo'])){
1414 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1415 }
1417 $smarty->assign("sn", $this->sn);
1418 $smarty->assign("givenName",$this->givenName);
1419 $smarty->assign("uid", $this->uid);
1420 $smarty->assign("rand", $rand);
1421 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1424 $ret = array();
1425 $ret['string'] = $str;
1426 $ret['status'] = "";
1427 return($ret);
1428 }
1430 function saveCopyDialog()
1431 {
1432 /* Set_acl_base */
1433 $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1435 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1436 $this->set_picture($_FILES['picture_file']['tmp_name']);
1437 }
1439 /* Remove picture? */
1440 if (isset($_POST['picture_remove'])){
1441 $this->jpegPhoto= "*removed*";
1442 $this->set_picture ("./plugins/users/images/default.jpg");
1443 $this->is_modified= TRUE;
1444 }
1446 $attrs = array("uid","givenName","sn");
1447 foreach($attrs as $attr){
1448 if(isset($_POST[$attr])){
1449 $this->$attr = $_POST[$attr];
1450 }
1451 }
1452 }
1455 function PrepareForCopyPaste($source)
1456 {
1457 plugin::PrepareForCopyPaste($source);
1459 /* Reset certificate information addepted from source user
1460 to avoid setting the same user certificate for the destination user. */
1461 $this->userPKCS12= "";
1462 $this->userSMIMECertificate= "";
1463 $this->userCertificate= "";
1464 $this->certificateSerialNumber= "";
1465 $this->old_certificateSerialNumber= "";
1466 $this->old_userPKCS12= "";
1467 $this->old_userSMIMECertificate= "";
1468 $this->old_userCertificate= "";
1469 }
1472 static function plInfo()
1473 {
1475 $govattrs= array(
1476 "gouvernmentOrganizationalUnit" => _("Unit"),
1477 "houseIdentifier" => _("House identifier"),
1478 "vocation" => _("Vocation"),
1479 "ivbbLastDeliveryCollective" => _("Last delivery"),
1480 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1481 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1482 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1483 "functionalTitle" => _("Functional title"),
1484 "certificateSerialNumber" => _("Certificate serial number"),
1485 "publicVisible" => _("Public visible"),
1486 "street" => _("Street"),
1487 "role" => _("Role"),
1488 "postalCode" => _("Postal code"));
1490 $ret = array(
1491 "plShortName" => _("Generic"),
1492 "plDescription" => _("Generic user settings"),
1493 "plSelfModify" => TRUE,
1494 "plDepends" => array(),
1495 "plPriority" => 1,
1496 "plSection" => array("personal" => _("My account")),
1497 "plCategory" => array("users" => array("description" => _("Users"),
1498 "objectClass" => "gosaAccount")),
1500 "plProvidedAcls" => array(
1502 "sn" => _("Surname"),
1503 "givenName" => _("Given name"),
1504 "uid" => _("User identification"),
1505 "personalTitle" => _("Personal title"),
1506 "academicTitle" => _("Academic title"),
1508 "dateOfBirth" => _("Date of birth"),
1509 "gender" => _("Gender"),
1510 "preferredLanguage" => _("Preferred language"),
1511 "base" => _("Base"),
1513 "userPicture" => _("User picture"),
1515 "o" => _("Organization"),
1516 "ou" => _("Department"),
1517 "departmentNumber" => _("Department number"),
1518 "employeeNumber" => _("Employee number"),
1519 "employeeType" => _("Employee type"),
1521 "roomNumber" => _("Room number"),
1522 "telephoneNumber" => _("Telefon number"),
1523 "pager" => _("Pager number"),
1524 "mobile" => _("Mobile number"),
1525 "facsimileTelephoneNumber" => _("Fax number"),
1527 "st" => _("State"),
1528 "l" => _("Location"),
1529 "postalAddress" => _("Postal address"),
1531 "homePostalAddress" => _("Home postal address"),
1532 "homePhone" => _("Home phone number"),
1533 "labeledURI" => _("Homepage"),
1534 "userPassword" => _("User password method"),
1535 "Certificate" => _("User certificates"))
1537 );
1539 /* Append government attributes if required */
1540 global $config;
1541 if($config->get_cfg_value("governmentmode") == "true"){
1542 foreach($govattrs as $attr => $desc){
1543 $ret["plProvidedAcls"][$attr] = $desc;
1544 }
1545 }
1546 return($ret);
1547 }
1549 function get_multi_edit_values()
1550 {
1551 $ret = plugin::get_multi_edit_values();
1552 if(in_array("pw_storage",$this->multi_boxes)){
1553 $ret['pw_storage'] = $this->pw_storage;
1554 }
1555 if(in_array("edit_picture",$this->multi_boxes)){
1556 $ret['jpegPhoto'] = $this->jpegPhoto;
1557 $ret['photoData'] = $this->photoData;
1558 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1559 $ret['old_photoData'] = $this->old_photoData;
1560 }
1561 if(isset($ret['dateOfBirth'])){
1562 unset($ret['dateOfBirth']);
1563 }
1564 if(isset($ret['cn'])){
1565 unset($ret['cn']);
1566 }
1567 $ret['is_modified'] = $this->is_modified;
1568 if(in_array("base",$this->multi_boxes)){
1569 $ret['orig_base']="Changed_by_Multi_Plug";
1570 $ret['base']=$this->base;
1571 }
1572 return($ret);
1573 }
1576 function multiple_save_object()
1577 {
1578 plugin::multiple_save_object();
1580 /* Get pw_storage mode */
1581 if (isset($_POST['pw_storage'])){
1582 foreach(array("pw_storage") as $val){
1583 if(isset($_POST[$val])){
1584 $data= validate(get_post($val));
1585 if ($data != $this->$val){
1586 $this->is_modified= TRUE;
1587 }
1588 $this->$val= $data;
1589 }
1590 }
1591 }
1592 if(isset($_POST['base'])){
1593 $this->base = get_post('base');
1594 }
1596 if(isset($_POST['user_mulitple_edit'])){
1597 foreach(array("base","pw_storage","edit_picture") as $val){
1598 if(isset($_POST["use_".$val])){
1599 $this->multi_boxes[] = $val;
1600 }
1601 }
1602 }
1603 }
1606 function multiple_check()
1607 {
1608 /* Call check() to set new_dn correctly ... */
1609 $message = plugin::multiple_check();
1611 /* Set the new acl base */
1612 if($this->dn == "new") {
1613 $this->set_acl_base($this->base);
1614 }
1615 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1616 $message[]= msgPool::invalid(_("Homepage"));
1617 }
1618 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1619 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1620 }
1621 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1622 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1623 }
1624 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1625 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1626 }
1627 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1628 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1629 }
1630 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1631 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1632 }
1633 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1634 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1635 }
1636 return($message);
1637 }
1641 function multiple_execute()
1642 {
1643 return($this->execute());
1644 }
1647 }
1649 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1650 ?>