Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
user_edit.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  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: user_edit.php,v 1.11 2005/07/08 15:29:51 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 // $Id: user_edit.php,v 1.11 2005/07/08 15:29:51 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Action/Users/user_edit.php,v $
21 // ---------------------------------------------------------------
22 include_once ("Class.SubForm.php");
23 include_once ("Class.Domain.php");
24 include_once ("Class.MailAccount.php");
25 include_once ("Class.User.php");
26 // -----------------------------------
27 function user_edit(&$action)
28 {
29  // -----------------------------------
30  // Get all the params
31  global $_POST;
32  $id = GetHttpVars("id");
33  if ($id == - 1) $id = "";
34  // initialise if user group or single user
35  $group = (GetHttpVars("group") == "Y");
36 
37  $tpasswd = array();
38  $tpasswd[0]["passwd"] = "";
39 
40  $action->lay->Set("selected_desactive", "");
41  $action->lay->Set("daydelay", $action->getParam("CORE_PASSWDDELAY"));
42  $action->lay->Set("expdate", "");
43  if (!$action->HasPermission("DOMAIN_MASTER")) {
44  $id = $action->user->id;
45  }
46  $tfirstname = array();
47  $tfirstname[0]["firstname"] = "";
48  if ($id == "") {
49 
50  if ($group) $action->lay->SetBlockData("HIDDENFIRSTNAME", $tfirstname);
51  else $action->lay->SetBlockData("FIRSTNAME", $tfirstname);
52 
53  $action->lay->Set("firstname", "");
54  $action->lay->Set("lastname", "");
55 
56  $action->lay->Set("id", "");
57  if ($group) {
58  $action->lay->Set("TITRE", $action->text("titlecreateg"));
59  } else {
60  $action->lay->Set("TITRE", $action->text("titlecreateu"));
61  }
62  $action->lay->Set("BUTTONTYPE", $action->text("butcreate"));
63  $login = new Layout($action->GetLayoutFile("login_create.xml") , $action);
64  $login->set("login", "");
65  if ($action->HasPermission("ADMIN")) {
66  $seldom = 1;
67  $ugroup = array(
68  "2"
69  ); // default group
70 
71  } else if ($action->HasPermission("DOMAIN_MASTER")) {
72  $seldom = $action->user->iddomain;
73  $query = new QueryDb($action->dbaccess, "User");
74  $query->AddQuery("iddomain=$seldom");
75  $query->AddQuery("login='all'");
76  $table = $query->Query();
77  if ($query->nb > 0) $ugroup = array(
78  $table[0]->id
79  ); // default domain group
80  else $ugroup = array(
81  "2"
82  ); // default group
83 
84  } else {
85  $action->exitError(_("Not Allowed Access Attempt : need DOMAIN_MASTER privilege"));
86  }
87  } else {
88  $user = new User($action->GetParam("CORE_DB") , $id);
89  $action->lay->Set("id", $id);
90  $group = ($user->isgroup == 'Y'); // reset group to value of user
91  if ($group) $action->lay->SetBlockData("HIDDENFIRSTNAME", $tfirstname);
92  else {
93  $tfirstname[0]["firstname"] = $user->firstname;
94  $action->lay->SetBlockData("FIRSTNAME", $tfirstname);
95  }
96  $action->lay->Set("lastname", $user->lastname);
97 
98  $action->lay->Set("selected_desactive", $user->status == "D" ? "selected" : "");
99  $action->lay->Set("daydelay", intval($user->passdelay / (3600 * 24))); // second to day
100  if (intval($user->expires) > 0) $action->lay->Set("expdate", strftime("%d/%m/%Y %X", intval($user->expires)));
101  if ($group) {
102  $action->lay->Set("TITRE", $action->text("titlemodifyg"));
103  } else {
104  $action->lay->Set("TITRE", $action->text("titlemodifyu"));
105  }
106  $action->lay->Set("BUTTONTYPE", $action->text("butmodify"));
107  $login = new Layout($action->GetLayoutFile("login.xml") , $action);
108  $action->log->debug(" utilisateur connu : {$user->login}");
109  $login->set("login", $user->login);
110  $seldom = $user->iddomain;
111 
112  $ug = new Group($action->GetParam("CORE_DB") , $user->id);
113  $ugroup = $ug->groups; // direct group
114 
115  }
116 
117  $tab = array();
118  // Mail domain can be change only if it's not yet set
119  if ($seldom == 1) {
120  if ($action->HasPermission("ADMIN")) {
121 
122  $dom = new Domain($action->GetParam("CORE_DB"));
123  $dom->ListAll(0);
124 
125  while (list($k, $v) = each($dom->qlist)) {
126  $tab[$k]["selected"] = ($v->iddomain == $seldom ? "selected" : "");
127  $tab[$k]["domainid"] = $v->iddomain;
128  $tab[$k]["domainname"] = ($v->iddomain == 1 ? $action->text("nomail") : $v->name);
129  }
130  } else {
131  $tab[0]["selected"] = "selected";
132  $tab[0]["domainid"] = $seldom;
133  $tab[0]["domainname"] = $action->text("nomail");
134  }
135  $action->lay->Set("disableddomain", "");
136  } else {
137  $tab[0]["selected"] = "selected";
138  $dom = new Domain($action->GetParam("CORE_DB") , $seldom);
139  $tab[0]["domainid"] = $dom->iddomain;
140  $tab[0]["domainname"] = $dom->name;
141  $action->lay->Set("disableddomain", "disabled");
142  }
143 
144  $action->lay->SetBlockData("SELECTDOMAIN", $tab);
145 
146  if ($group) { // dont't see passwd
147  $action->lay->SetBlockData("HIDDENPASSWD", $tpasswd);
148  } else {
149  // in user mode : display passwd field
150  $action->lay->SetBlockData("PASSWD", $tpasswd);
151  }
152  // search user group
153  $tab = array();
154  //
155  while (list($k, $v) = each($ugroup)) {
156  $gu = new User($action->GetParam("CORE_DB") , $v);
157  $tab[$k]["groupid"] = $v;
158  $dom = new Domain($action->GetParam("CORE_DB") , $gu->iddomain);
159  $tab[$k]["groupname"] = "{$gu->login}@{$dom->name}";
160  }
161 
162  if (count($tab) > 1) {
163  $action->lay->Set("sizegv", "2");
164  } else {
165  $action->lay->Set("sizegv", "1");
166  }
167  $action->lay->SetBlockData("VIEWGROUP", $tab);
168 
169  $action->lay->Set("imgchggroup", "");
170 
171  if ($action->HasPermission("DOMAIN_MASTER")) {
172  $action->lay->Set("imgchggroup", $action->GetIcon("users.gif", "chggroup", 15));
173  }
174  // search all group
175  $tabd = array(); // domain table
176  $tabo = array(); // other table
177  //
178  $bduser = new User($action->GetParam("CORE_DB"));
179  $allgroups = $bduser->GetGroupList();
180 
181  while (list($k, $g) = each($allgroups)) {
182  $infogroup = array();
183  $infogroup["groupid"] = $g->id;
184  if (in_array($g->id, $ugroup)) {
185  $infogroup["selectgroup"] = "selected";
186  } else {
187  $infogroup["selectgroup"] = "";
188  }
189  $dom = new Domain($action->GetParam("CORE_DB") , $g->iddomain);
190  $infogroup["groupname"] = "{$g->login}@{$dom->name}";
191 
192  if (isset($user)) {
193  // search group inherit in group to avoid recursion
194  $ug = new Group($action->GetParam("CORE_DB") , $g->id);
195 
196  if (($user->isgroup != "Y") || ((!in_array($user->id, $ug->GetAllGroups())) && // don
197  ($g->id != $user->id))) {
198 
199  if ($g->iddomain == $user->iddomain) {
200  $tabd[] = $infogroup;
201  } else {
202  $tabo[] = $infogroup;
203  }
204  }
205  } else {
206  $tabo[] = $infogroup;
207  }
208  }
209 
210  $action->lay->SetBlockData("SELECTDOMAINGROUP", $tabd);
211  $action->lay->SetBlockData("SELECTOTHERGROUP", $tabo);
212 
213  $action->lay->Set("LOGIN_MOD", $login->gen());
214  $form = new SubForm("edit");
215  $form->SetParam("firstname");
216  $form->SetParam("lastname");
217  $form->SetParam("login");
218  $form->SetParam("passwd");
219  $form->SetParam("id");
220  $form->SetParam("domainid", "", "sel");
221  $action->parent->AddJsCode($form->GetSubJs());
222  $control = $action->GetLayoutFile("user_control.js");
223  $lay = new Layout($control);
224  $action->parent->AddJsCode($lay->gen());
225 }
226 ?>
← centre documentaire © anakeen - published under CC License - Dynacase