Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.DocIUser.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * User manipulation
9  *
10  * @author Anakeen 2004
11  * @version $Id: Method.DocIUser.php,v 1.49 2008/08/13 14:07:54 jerome Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage USERCARD
15  */
16 /**
17  */
18 /**
19  * @begin-method-ignore
20  * this part will be deleted when construct document class until end-method-ignore
21  */
22 class _IUSER extends _USER
23 {
24  /*
25  * @end-method-ignore
26  */
27  var $cviews = array(
28  "FUSERS:FUSERS_IUSER"
29  );
30  var $eviews = array(
31  "USERCARD:CHOOSEGROUP"
32  );
33  var $defaultview = "FDL:VIEWBODYCARD";
34  var $defaultedit = "FDL:EDITBODYCARD";
35 
36  function SpecRefresh()
37  {
39 
40  $this->AddParamRefresh("US_WHATID", "US_LOGIN,US_GROUP");
41  $this->AddParamRefresh("US_AUTOMAIL", "US_EXTMAIL");
42  if ($this->getValue("US_IDDOMAIN", 1) > 1) $this->AddParamRefresh("US_WHATID", "US_DOMAIN");
43  $this->AddParamRefresh("US_IDDOMAIN", "US_DOMAIN");
44 
45  if ($this->getValue("US_STATUS") == 'D') $err.= ($err == "" ? "" : "\n") . _("user is deactivated");
46  // refresh MEID itself
47  $this->SetValue("US_MEID", $this->id);
48  $iduser = $this->getValue("US_WHATID");
49  if ($iduser > 0) {
50  $user = $this->getWUser();
51  if (!$user->isAffected()) return sprintf(_("user #%d does not exist") , $iduser);
52  } else {
53  if ($this->getValue("us_login") != '-') $err = _("user has not identificator");
54  $oa = $this->getAttribute("us_passwd1");
55  if ($oa) $oa->needed = true;
56  $oa = $this->getAttribute("us_passwd2");
57  if ($oa) $oa->needed = true;
58  $oa = $this->getAttribute("us_tab_system");
59  $oa->setOption("firstopen", "yes");
60  }
61  return $err;
62  }
63  /**
64  * test if the document can be set in LDAP
65  */
66  function canUpdateLdapCard()
67  {
68  return ($this->getValue("US_STATUS") != 'D');
69  }
70  /**
71  * @deprecated
72  */
73  function getOtherGroups()
74  {
76  if ($this->id == 0) return array();
77 
78  include_once ("FDL/freedom_util.php");
79  include_once ("FDL/Lib.Dir.php");
80 
81  $sqlfilters[] = "in_textlist(grp_idruser,{$this->id})";
82  // $sqlfilters[]="fromid !=".getFamIdFromName($this->dbaccess,"IGROUP");
83  $tgroup = getChildDoc($this->dbaccess, 0, "0", "ALL", $sqlfilters, 1, "TABLE", getFamIdFromName($this->dbaccess, "GROUP"));
84 
85  return $tgroup;
86  }
87  /**
88  * get all direct group document identificators of the isuser
89  * @return @array of group document id, the index of array is the system identificator
90  */
91  public function getUserGroups()
92  {
93  $err = simpleQuery($this->dbaccess, sprintf("SELECT id, fid from users, groups where groups.iduser=%d and users.id = groups.idgroup;", $this->getValue("us_whatid")) , $groupIds, false, false);
94  if (!$err) {
95  $gids = array();
96  foreach ($groupIds as $gid) {
97  $gids[$gid["id"]] = $gid["fid"];
98  }
99  return $gids;
100  }
101  return null;
102  }
103  /**
104  * return all direct group and parent group document identificators of $gid
105  * @param string $gid systeme identificator group or users
106  */
107  protected function getAscendantGroup($gid)
108  {
109  $groupIds = array();
110  if ($gid > 0) {
111  $err = simpleQuery($this->dbaccess, sprintf("SELECT id, fid from users, groups where groups.iduser=%d and users.id = groups.idgroup;", $gid) , $groupIds, false, false);
112  $gids = array(); // current level
113  $pgids = array(); // fathers
114  foreach ($groupIds as $gid) {
115  $gids[$gid["id"]] = $gid["fid"];
116  }
117 
118  foreach ($gids as $systemGid => $docGid) {
119  $pgids+= $this->getAscendantGroup($systemGid);
120  }
121  $groupIds = $gids + $pgids;
122  }
123  return $groupIds;
124  }
125  /**
126  * get all direct group and parent group document identificators of the isuser
127  * @return @array of group document id the index of array is the system identificator
128  */
129  public function getAllUserGroups()
130  {
131  return $this->getAscendantGroup($this->getValue("us_whatid"));
132  }
133  /**
134  * Refresh folder parent containt
135  */
137  {
138  $tgid = $this->getTValue("US_IDGROUP");
139  foreach ($tgid as $gid) {
140  $gdoc = new_Doc($this->dbaccess, $gid);
141  if ($gdoc->isAlive()) {
142  $gdoc->insertGroups();
143  }
144  }
145  }
146  /**
147  * recompute intranet values from USER database
148  */
149  function RefreshDocUser()
150  {
151 
152  $err = "";
153  $wid = $this->getValue("us_whatid");
154  if ($wid > 0) {
155  $wuser = $this->getWuser(true);
156 
157  if ($wuser->isAffected()) {
158  $this->SetValue("US_WHATID", $wuser->id);
159  $this->SetValue("US_LNAME", $wuser->lastname);
160  $this->SetValue("US_FNAME", $wuser->firstname);
161  $this->SetValue("US_PASSWD", $wuser->password);
162  $this->SetValue("US_PASSWD1", " ");
163  $this->SetValue("US_PASSWD2", " ");
164  $this->SetValue("US_LOGIN", $wuser->login);
165  $this->SetValue("US_STATUS", $wuser->status);
166  $this->SetValue("US_PASSDELAY", $wuser->passdelay);
167  $this->SetValue("US_EXPIRES", $wuser->expires);
168  $this->SetValue("US_DAYDELAY", $wuser->passdelay / 3600 / 24);
169  $this->SetValue("US_IDDOMAIN", $wuser->iddomain);
170  include_once ("Class.Domain.php");
171  $dom = new Domain("", $wuser->iddomain);
172  $this->SetValue("US_DOMAIN", $dom->name);
173  $mail = $wuser->getMail();
174  if (!$mail) $this->DeleteValue("US_MAIL");
175  else $this->SetValue("US_MAIL", $mail);
176  if ($wuser->passdelay <> 0) {
177  $this->SetValue("US_EXPIRESD", strftime("%d/%m/%Y", $wuser->expires));
178  $this->SetValue("US_EXPIREST", strftime("%H:%M", $wuser->expires));
179  } else {
180  $this->SetValue("US_EXPIRESD", " ");
181  $this->SetValue("US_EXPIREST", " ");
182  }
183 
184  $this->SetValue("US_MEID", $this->id);
185  // search group of the user
186  $g = new Group("", $wid);
187 
188  if (count($g->groups) > 0) {
189  foreach ($g->groups as $gid) {
190  $gt = new User("", $gid);
191  $tgid[$gid] = $gt->fid;
192  $tglogin[$gid] = $this->getTitle($gt->fid);
193  }
194  $this->SetValue("US_GROUP", $tglogin);
195  $this->SetValue("US_IDGROUP", $tgid);
196  } else {
197  $this->SetValue("US_GROUP", " ");
198  $this->SetValue("US_IDGROUP", " ");
199  }
200  $err = $this->modify();
201  } else {
202  $err = sprintf(_("user %d does not exist") , $wid);
203  }
204  }
205 
206  return $err;
207  }
208  /**
209  * affect to default group
210  */
211  function setToDefaultGroup()
212  {
213  $grpid = $this->getParamValue("us_defaultgroup");
214  if ($grpid) {
215  $grp = new_doc($this->dbaccess, $grpid);
216  if ($grp->isAlive()) {
217  $err = $grp->addFile($this->initid);
218  }
219  }
220  return $err;
221  }
222 
223  function postCreated()
224  {
225  $err = "";
226  global $action;
227  $ed = $action->getParam("AUTHENT_ACCOUNTEXPIREDELAY");
228  if ($ed > 0) {
229  $expdate = time() + ($ed * 24 * 3600);
230  $err = $this->SetValue("us_accexpiredate", strftime("%d/%m/%Y 00:00:00", $expdate));
231  if ($err == '') $err = $this->modify(true, array(
232  "us_accexpiredate"
233  ) , true);
234  }
235  return $err;
236  }
237  /**
238  * Modify IUSER via Freedom
239  */
240  function PostModify()
241  {
242  $uid = $this->GetValue("US_WHATID");
243  $lname = $this->GetValue("US_LNAME");
244  $fname = $this->GetValue("US_FNAME");
245  $pwd1 = $this->GetValue("US_PASSWD1");
246  $pwd2 = $this->GetValue("US_PASSWD2");
247  $pwd = $this->GetValue("US_PASSWD");
248  $expires = $this->GetValue("US_EXPIRES");
249  $daydelay = $this->GetValue("US_DAYDELAY");
250  if ($daydelay == - 1) $passdelay = $daydelay;
251  else $passdelay = intval($daydelay) * 3600 * 24;
252  $status = $this->GetValue("US_STATUS");
253  $login = $this->GetValue("US_LOGIN");
254  $extmail = $this->GetValue("US_EXTMAIL", $this->getValue("us_homemail", " "));
255  $err = "";
256 
257  if ($login != "-") {
258  // compute expire for epoch
259  $expiresd = $this->GetValue("US_EXPIRESD");
260  $expirest = $this->GetValue("US_EXPIREST", "00:00");
261  //convert date
262  $expdate = $expiresd . " " . $expirest . ":00";
263  $expires = 0;
264  if ($expdate != "") {
265  if (preg_match("|([0-9][0-9])/([0-9][0-9])/(2[0-9][0-9][0-9]) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9])|", $expdate, $reg)) {
266  $expires = mktime($reg[4], $reg[5], $reg[6], $reg[2], $reg[1], $reg[3]);
267  } else if (preg_match("|(2[0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9]) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9])|", $expdate, $reg)) {
268  $expires = mktime($reg[4], $reg[5], $reg[6], $reg[2], $reg[3], $reg[1]);
269  }
270  }
271 
272  $iddomain = $this->GetValue("US_IDDOMAIN");
273  $domain = $this->GetValue("US_DOMAIN");
274 
275  $fid = $this->id;
276  $newuser = false;
277  $user = $this->getWUser();
278  if (!$user) {
279  $user = new User(""); // create new user
280  $this->wuser = & $user;
281  $newuser = true;
282  }
283  $err.= $user->SetUsers($fid, $lname, $fname, $expires, $passdelay, $login, $status, $pwd1, $pwd2, $iddomain, $extmail);
284  if ($err == "") {
285  if ($user) {
286  $this->setValue("US_WHATID", $user->id);
287  $this->modify(false, array(
288  "us_whatid"
289  ));
290  $err = $this->setGroups(); // set groups (add and suppress) may be long
291  if ($newuser) $err.= $this->setToDefaultGroup();
292  }
293  if (($pwd1 == "") && ($pwd1 == $pwd2) && ($pwd != "")) {
294  if (($pwd != $user->password) && (strlen($pwd) > 12)) {
295  $user->password = $pwd;
296  $err = $user->modify();
297  }
298  }
299  }
300 
301  if ($err == "") {
302  $err = $this->RefreshDocUser(); // refresh from core database
303  // $this->refreshParentGroup();
304  $errldap = $this->RefreshLdapCard();
305  if ($errldap != "") AddWarningMsg($errldap);
306  }
307  } else {
308  // tranfert extern mail if no login specified yet
309  if ($this->getValue("us_login") == "-") {
310  $this->setValue("US_IDDOMAIN", "0");
311  $email = $this->getValue("us_extmail", $this->getValue("us_homemail"));
312  if (($email != "") && ($email[0] != "<")) $this->setValue("us_mail", $email);
313  else $this->deleteValue("us_mail");
314  }
315  }
316 
317  $this->setValue("US_LDAPDN", $this->getLDAPValue("dn", 1));
318  return $err;
319  }
320 
321  function PostDelete()
322  {
324 
325  $user = $this->getWUser();
326  if ($user) $user->Delete();
327  }
328  /**
329  * Do not call ::setGroup if its import
330  * called only in initialisation
331  */
332  function preImport()
333  {
334  if ($this->id > 0) {
335  global $_POST;
336  $_POST["gidnew"] = "N";
337  }
338  }
339 
340  function ConstraintPassword($pwd1, $pwd2, $login)
341  {
342  $sug = array();
343  $err = "";
344 
345  if ($pwd1 <> $pwd2) {
346  $err = _("the 2 passwords are not the same");
347  } else if (($pwd1 == "") && ($this->getValue("us_whatid") == "")) {
348  if ($login != "-") $err = _("passwords must not be empty");
349  }
350 
351  return array(
352  "err" => $err,
353  "sug" => $sug
354  );
355  }
356 
357  function ConstraintExpires($expiresd, $expirest, $daydelay)
358  {
359  $sug = array();
360  if (($expiresd <> "") && ($daydelay == 0)) {
361  $err = _("Expiration delay must not be 0 to keep expiration date");
362  }
363 
364  return array(
365  "err" => $err,
366  "sug" => $sug
367  );
368  }
369 
370  function editlikeperson($target = "finfo", $ulink = true, $abstract = "Y")
371  {
372  global $action;
373 
374  $this->lay = new Layout(getLayoutFile("FDL", "editbodycard.xml") , $action);
375 
376  $this->attributes->attr['us_tab_system']->visibility = 'R';
377  $this->attributes->attr['us_fr_userchange']->visibility = 'R';
378  $this->ApplyMask();
379  if ($this->getValue("us_iddomain") == 0) {
380  $this->attributes->attr['us_extmail']->mvisibility = 'W';
381  $this->attributes->attr['us_extmail']->fieldSet = $this->attributes->attr['us_fr_coord'];
382  $this->attributes->attr['us_extmail']->ordered = $this->attributes->attr['us_pphone']->ordered - 1;
383  uasort($this->attributes->attr, "tordered");
384  }
385 
386  $this->editbodycard($target, $ulink, $abstract);
387  }
388 
389  function fusers_iuser($target = "finfo", $ulink = true, $abstract = "Y")
390  {
391  global $action;
392  //setHttpVar("specialmenu","menuab");
393  $this->viewdefaultcard($target, $ulink, $abstract);
394  $action->parent->AddCssRef("USERCARD:faddbook.css", true);
395  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/USERCARD/Layout/faddbook.js");
396  // list of attributes displayed directly in layout
397  $ta = array(
398  "us_workweb",
399  "us_photo",
400  "us_lname",
401  "us_fname",
402  "us_society",
403  "us_civility",
404  "us_mail",
405  "us_phone",
406  "us_mobile",
407  "us_fax",
408  "us_intphone",
409  "us_workaddr",
410  "us_workcedex",
411  "us_country",
412  "us_workpostalcode",
413  "us_worktown",
414  "us_groups",
415  "us_whatid",
416  "us_state",
417  "us_login",
418  "us_status",
419  "us_domain",
420  "us_expiresd",
421  "us_expirest",
422  "us_daydelay",
423  "us_idsociety"
424  );
425  //$ta["ident"]=array("us_lo
426  $la = $this->getAttributes();
427  $to = array();
428  $tabs = array();
429  foreach ($la as $k => $v) {
430  $va = $this->getValue($v->id);
431  if (($va || ($v->type == "array")) && (!in_array($v->id, $ta)) && (!$v->inArray())) {
432 
433  if ((($v->mvisibility == "R") || ($v->mvisibility == "W"))) {
434  if ($v->type == "array") {
435  $hv = $this->getHtmlValue($v, $va, $target, $ulink);
436  if ($hv) {
437  $to[] = array(
438  "lothers" => $v->labelText,
439  "aid" => $v->id,
440  "vothers" => $hv,
441  "isarray" => true
442  );
443  $tabs[$v->fieldSet->labelText][] = $v->id;
444  }
445  } else {
446  $to[] = array(
447  "lothers" => $v->labelText,
448  "aid" => $v->id,
449  "vothers" => $this->getHtmlValue($v, $va, $target, $ulink) ,
450  "isarray" => false
451  );
452  $tabs[$v->fieldSet->labelText][] = $v->id;
453  }
454  }
455  }
456  }
457  $this->lay->setBlockData("OTHERS", $to);
458  $this->lay->set("HasOTHERS", (count($to) > 0));
459  $this->lay->set("HasDOMAIN", ($this->getValue("US_IDDOMAIN") > 9));
460  $this->lay->set("HasDPassword", (intval($this->getValue("US_DAYDELAY")) != 0));
461  $ltabs = array();
462  foreach ($tabs as $k => $v) {
463  $ltabs[$k] = array(
464  "tabtitle" => $k,
465  "aids" => "['" . implode("','", $v) . "']"
466  );
467  }
468  $this->lay->setBlockData("TABS", $ltabs);
469  $this->lay->set("CanEdit", ($this->control("edit") == ""));
470  }
471  /**
472  * interface to only modify name and password
473  */
475  {
476  $this->viewprop();
477  $this->editattr(false);
478  }
479  function fusers_eiuser()
480  {
481  global $action;
482  $this->editattr();
483  $action->parent->AddCssRef("USERCARD:faddbook.css", true);
484  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/USERCARD/Layout/faddbook.js");
485  $firsttab = getHttpVars("tab"); // first tab displayed
486  // list of attributes displayed directly in layout
487  $ta = array(
488  "us_workweb",
489  "us_photo",
490  "us_lname",
491  "us_fname",
492  "us_society",
493  "us_idsociety",
494  "us_civility",
495  "us_mail",
496  "us_phone",
497  "us_mobile",
498  "us_fax",
499  "us_intphone",
500  "us_workaddr",
501  "us_workcedex",
502  "us_country",
503  "us_workpostalcode",
504  "us_worktown",
505  "us_groups",
506  "us_whatid",
507  "us_state",
508  "us_login",
509  "us_status",
510  "us_domain",
511  "us_iddomain",
512  "us_expiresd",
513  "us_expirest",
514  "us_daydelay",
515  "us_passwd1",
516  "us_passwd2",
517  "us_extmail",
518  "us_role",
519  "us_scatg",
520  "us_pfax",
521  "us_pphone",
522  "us_job",
523  "us_type",
524  "us_initials",
525  "us_service",
526  "us_idservice",
527  "us_socaddr"
528  );
529  //$ta["ident"]=array("us_lo
530  $la = $this->getNormalAttributes();
531 
532  $this->lay->set("editgroup", ($la["us_group"]->mvisibility == "W"));
533  $this->lay->set("firsttab", $firsttab);
534  $to = array();
535  $th = array();
536  $tabs = array();
537  foreach ($la as $k => $v) {
538  $va = $this->getValue($v->id);
539  if (!$v->inArray() && (!in_array($v->id, $ta))) {
540  if ($v->mvisibility != "I") {
541  if ($v->type == "array") {
542  $hv = getHtmlInput($this, $v, $va);
543  if ($hv) {
544  if ($v->mvisibility != "H") {
545  $to[] = array(
546  "lothers" => $v->labelText,
547  "aid" => $v->id,
548  "vothers" => $hv,
549  "isarray" => true
550  );
551  $tabs[$v->fieldSet->labelText][] = $v->id;
552  } else {
553  $th[] = array(
554  "aid" => $v->id,
555  "vothers" => getHtmlInput($this, $v, $va)
556  );
557  }
558  }
559  } else {
560  if ($v->mvisibility != "H") {
561  $to[] = array(
562  "lothers" => $v->labelText,
563  "aid" => $v->id,
564  "vothers" => getHtmlInput($this, $v, $va) ,
565  "isarray" => false
566  );
567  $tabs[$v->fieldSet->labelText][] = $v->id;
568  } else {
569  $th[] = array(
570  "aid" => $v->id,
571  "vothers" => getHtmlInput($this, $v, $va)
572  );
573  }
574  }
575  }
576  }
577  }
578  $this->lay->setBlockData("OTHERS", $to);
579  $this->lay->setBlockData("IHIDDENS", $th);
580  $this->lay->set("HasOTHERS", (count($to) > 0));
581  $ltabs = array();
582  foreach ($tabs as $k => $v) {
583  $ltabs[$k] = array(
584  "tabtitle" => $k,
585  "aids" => "['" . implode("','", $v) . "']"
586  );
587  }
588  $this->lay->setBlockData("TABS", $ltabs);
589  $this->viewprop();
590  }
591  /**
592  * Set/change user password
593  */
595  {
596  $idwuser = $this->getValue("US_WHATID");
597 
598  $wuser = $this->getWUser();
599  if (!$wuser->isAffected()) {
600  return sprintf(_("user #%d does not exist") , $idwuser);
601  }
602  // Change what user password
603  $wuser->password_new = $password;
604  $err = $wuser->modify();
605  if ($err != "") {
606  return $err;
607  }
608  // Change IUSER password
609  $err = $this->SetValue("US_PASSWD", $password);
610  if ($err != "") {
611  return $err;
612  }
613  $err = $this->modify();
614  if ($err != "") {
615  return $err;
616  }
617 
618  return "";
619  }
620  /**
621  * Increase login failure count
622  */
624  {
625  if ($this->getValue("us_whatid") == 1) return ""; // it makes non sense for admin
626  $lf = $this->getValue("us_loginfailure", 0) + 1;
627  $err = $this->SetValue("us_loginfailure", $lf);
628  if ($err == "") {
629  $err = $this->modify(false, array(
630  "us_loginfailure"
631  ) , false);
632  }
633  return "";
634  }
635  /**
636  * Reset login failure count
637  */
638  function resetLoginFailure()
639  {
640  if ($this->getValue("us_whatid") == 1) return ""; // it makes non sense for admin
641  if (intval($this->getValue("us_loginfailure")) > 0) {
642  $err = $this->setValue("us_loginfailure", 0);
643  if ($err == "") {
644  $err = $this->modify(false, array(
645  "us_loginfailure"
646  ) , false);
647  }
648  }
649  return "";
650  }
651  /*
652  * Securitys menus visibilities
653  */
655  {
656  // Do not show the menu if the user has no FUSERS privileges
657  global $action;
658  if (!$action->parent->hasPermission('FUSERS', 'FUSERS')) {
659  return MENU_INVISIBLE;
660  }
661  // Do not show the menu if the user has no edit rights on the document
662  if ($this->canEdit() != '') {
663  return MENU_INVISIBLE;
664  }
665  // Do not show the menu on the 'admin' user
666  if ($this->getValue('us_whatid') == 1) {
667  return MENU_INVISIBLE;
668  }
669  // Do not show the menu if the account had no failures
670  if ($this->getValue("us_loginfailure") <= 0) {
671  return MENU_INVISIBLE;
672  }
673  return MENU_ACTIVE;
674  }
675  function menuActivateAccount() {
676  // Do not show the menu if the user has no FUSERS privileges
677  global $action;
678  if (!$action->parent->hasPermission('FUSERS', 'FUSERS')) {
679  return MENU_INVISIBLE;
680  }
681  // Do not show the menu if the user has no edit rights on the document
682  if ($this->canEdit() != '') {
683  return MENU_INVISIBLE;
684  }
685  // Do not show the menu on the 'admin' user
686  if ($this->getValue('us_whatid') == 1) {
687  return MENU_INVISIBLE;
688  }
689  // Do not show the menu if the account is already active
690  if ($this->getValue('us_status', 'A') == 'A') {
691  return MENU_INVISIBLE;
692  }
693  return MENU_ACTIVE;
694  }
696  // Do not show the menu if the user has no FUSERS privileges
697  global $action;
698  if (!$action->parent->hasPermission('FUSERS', 'FUSERS')) {
699  return MENU_INVISIBLE;
700  }
701  // Do not show the menu if the user has no edit rights on the document
702  if ($this->canEdit() != '') {
703  return MENU_INVISIBLE;
704  }
705  // Do not show the menu on the 'admin' user
706  if ($this->getValue('us_whatid') == 1) {
707  return MENU_INVISIBLE;
708  }
709  // Do not show the menu if the account is already inactive
710  if ($this->getValue('us_status', 'A') != 'A') {
711  return MENU_INVISIBLE;
712  }
713  return MENU_ACTIVE;
714  }
715  /**
716  * Manage account security
717  */
718  function isAccountActive()
719  {
720  if ($this->getValue("us_whatid") == 1) return false; // it makes non sense for admin
721  return ($this->getValue("us_status", 'A') == 'A');
722  }
723  function activateAccount()
724  {
725  // Check that the user has FUSERS privileges
726  global $action;
727  if ($this->canEdit() != '' || !$action->parent->hasPermission('FUSERS', 'FUSERS')) {
728  return _("current user cannot activate account");
729  }
730  // The 'admin' account cannot be deactivated
731  if ($this->getValue("us_whatid") == 1) {
732  return '';
733  }
734  $err = $this->SetValue("us_status", 'A');
735  if ($err == "") {
736  $err = $this->modify(true, array(
737  "us_status"
738  ) , true);
739  $this->PostModify();
740  }
741  return $err;
742  }
743  function isAccountInactive()
744  {
745  if ($this->getValue("us_whatid") == 1) return false; // it makes non sense for admin
746  return ($this->getValue("us_status", 'A') != 'A');
747  }
748  function deactivateAccount()
749  {
750  // Check that the user has FUSERS privileges
751  global $action;
752  if ($this->canEdit() != '' || !$action->parent->hasPermission('FUSERS', 'FUSERS')) {
753  return _("current user cannot deactivate account");
754  }
755  // The 'admin' account cannot be deactivated
756  if ($this->getValue("us_whatid") == 1) {
757  return '';
758  }
759  $err = $this->SetValue("us_status", 'D');
760  if ($err == "") {
761  $err = $this->modify(true, array(
762  "us_status"
763  ) , true);
764  $this->PostModify();
765  }
766  return $err;
767  }
768  function accountHasExpired()
769  {
770  if ($this->getValue("us_whatid") == 1) return false;
771  $expd = $this->GetValue("us_accexpiredate");
772  //convert date
773  $expires = 0;
774  if ($expd != "") {
775  if (preg_match("|([0-9][0-9])/([0-9][0-9])/(2[0-9][0-9][0-9])|", $expd, $reg)) {
776  $expires = mktime(0, 0, 0, $reg[2], $reg[1], $reg[3]);
777  } else if (preg_match("|(2[0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9]|", $expd, $reg)) {
778  $expires = mktime(0, 0, 0, $reg[2], $reg[3], $reg[1]);
779  }
780  return ($expires <= time());
781  }
782  return false;
783  }
784  /**
785  * @begin-method-ignore
786  * this part will be deleted when construct document class until end-method-ignore
787  */
788 }
789 /*
790  * @end-method-ignore
791 */
792 ?>
← centre documentaire © anakeen - published under CC License - Dynacase