Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
user_mod.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 modify properties
9  *
10  * @author Anakeen 2000
11  * @version $Id: user_mod.php,v 1.12 2007/02/21 11:08:02 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage USERS
15  */
16 /**
17  */
18 
19 include_once ("Class.SubForm.php");
20 include_once ("Class.User.php");
21 include_once ("Class.MailAccount.php");
22 // -----------------------------------
23 function user_mod(&$action)
24 {
25  // -----------------------------------
26  $action->log->info("USERMOD ");
27  // Get all the params
28  $id = GetHttpVars("id");
29  $newgroup = GetHttpVars("groupview", array());
30 
31  if ($id == "") {
32  $user = new User($action->GetParam("CORE_DB"));
33  } else {
34  $user = new User($action->GetParam("CORE_DB") , $id);
35  }
36 
37  $group = (GetHttpVars("group") == "yes");
38 
39  $user->firstname = GetHttpVars("firstname");
40  $user->lastname = GetHttpVars("lastname");
41  $user->status = GetHttpVars("status");
42  $user->passdelay = intval(GetHttpVars("passdelay")) * 3600 * 24; // day to second
43  $expdate = GetHttpVars("expdate");
44  $exptime = 0;
45  if ($expdate != "") {
46  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)) {
47 
48  $exptime = mktime($reg[4], $reg[5], $reg[6], $reg[2], $reg[1], $reg[3]);
49  } else {
50  $action->AddWarningMsg(_("expire date format is not correct : will be set to default"));
51  }
52  }
53 
54  if ($id == "") {
55  $user->login = GetHttpVars("login");
56  $user->iddomain = GetHttpVars("domainid");
57  $user->password_new = GetHttpVars("passwd");
58  $user->isgroup = ($group) ? 'Y' : 'N';
59  $res = $user->Add(true);
60  if ($res != "") {
61  $txt = $action->text("err_add_user") . " : $res";
62  $action->Register("USERS_ERROR", AddSlashes($txt));
63  }
64  if (!$group && $user->iddomain != 1) {
65  $mailapp = new Application();
66  if ($mailapp->Exists("MAILADMIN")) {
67  $mailapp->Set("MAILADMIN", $action->parent);
68  $uacc = new MailAccount($mailapp->GetParam("MAILDB"));
69  $uacc->iddomain = $user->iddomain;
70  $uacc->iduser = $user->id;
71  $uacc->login = $user->login;
72  $uacc->Add();
73  }
74  }
75  } else {
76  // Affect the user to a domain
77  if (!$group && ($user->iddomain == 1) && (GetHttpVars("domainid") != 1)) {
78  $user->iddomain = GetHttpVars("domainid");
79  $mailapp = new Application();
80  if ($mailapp->Exists("MAILADMIN")) {
81  $mailapp->Set("MAILADMIN", $action->parent);
82  $uacc = new MailAccount($mailapp->GetParam("MAILDB"));
83  $uacc->iddomain = $user->iddomain;
84  $uacc->iduser = $user->id;
85  $uacc->login = $user->login;
86  $uacc->Add();
87  }
88  }
89  }
90  if (GetHttpVars("passwd") != "") {
91  $user->password_new = GetHttpVars("passwd");
92 
93  if (($exptime > 0) && ($exptime != $user->expires)) $user->expires = $exptime;
94  else $user->expires = 0; // means recompute expire date if needed
95 
96  } else {
97  if (($exptime > 0) && ($exptime != $user->expires)) $user->expires = $exptime;
98  }
99 
100  $user->Modify();
101 
102  $rgid = $user->GetGroupsId();
103 
104  if ((count($rgid) != count($newgroup)) || (count(array_diff($rgid, $newgroup)) != 0)) {
105 
106  $ugroup = new Group($action->dbaccess, $user->id);
107  if ($ugroup->IsAffected()) {
108  $ugroup->Delete(true); // delete all before add
109 
110  } else { // new group
111  $ugroup->iduser = $user->id;
112  }
113  if ((is_array($newgroup))) {
114  while (list($k, $v) = each($newgroup)) {
115  $ugroup->idgroup = $v;
116  $ugroup->Add(true);
117  }
118  }
119  // only at the end : it is not necessary before
120  $ugroup->FreedomCopyGroup();
121  if (usefreedomuser()) {
122  $gdif = array_merge(array_diff($rgid, $newgroup) , array_diff($newgroup, $rgid));
123 
124  refreshGroups($gdif, true);
125  }
126  }
127 
128  if ($group) {
129  redirect($action, "USERS", "GROUP_TABLE");
130  } else {
131  redirect($action, "USERS", "USER_TABLE");
132  }
133 }
134 ?>
← centre documentaire © anakeen - published under CC License - Dynacase