Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
user_access.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_access.php,v 1.11 2007/02/16 08:32:08 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage ACCESS
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: user_access.php,v 1.11 2007/02/16 08:32:08 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Action/Access/user_access.php,v $
21 // ---------------------------------------------------------------
22 include_once ("Class.QueryDb.php");
23 include_once ("Class.QueryGen.php");
24 include_once ("Class.SubForm.php");
25 include_once ("Class.TableLayout.php");
26 // -----------------------------------
27 function user_access(&$action, $group = false)
28 {
29  // -----------------------------------
30  $baseurl = $action->GetParam("CORE_BASEURL");
31  $standurl = $action->GetParam("CORE_STANDURL");
32  $filteruser = getHttpVars("userfilter");
33  $user_id = getHttpVars("uid");
34  $action->lay->set("userfilter", $filteruser);
35  // Set the edit form element
36  if ($group) {
37  $paramedit = "&group=yes";
38  } else {
39  $paramedit = "&group=no";
40  }
41 
42  $form = new SubForm("edit", 500, 330, "app=ACCESS&action=MODIFY$paramedit", $standurl . "app=ACCESS&action=EDIT&mod=user&userfilter=$filteruser$paramedit");
43 
44  $form->SetKey("id");
45 
46  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
47  $action->parent->AddJsCode($form->GetMainJs());
48  $jsscript = $form->GetLinkJsMainCall();
49  // Set
50  $action->lay->set("ACTION_CHG", "ACCESS_USER_CHG$paramedit");
51  $action->lay->set("ACTION_MOD", "USER_ACCESS_MOD$paramedit");
52  $action->lay->set("fhelp", ($action->Read("navigator", "") == "EXPLORER") ? "_blank" : "fhidden");
53 
54  $action->lay->set("shortname", _($action->text("appname")));
55  $action->lay->set("desc", _($action->text("appdesc")));
56  $action->lay->set("permission", $action->text("permissions"));
57 
58  $action->lay->set("QUERY_FORM", "");
59  $action->lay->set("FULLTEXTFORM", "");
60 
61  $action->lay->set("maxreach", false);
62  $action->lay->set("usefilter", false);
63  // affect the select form elements
64  $u = new User();
65  if ($group) {
66  $list = $u->GetGroupList("TABLE");
67  $varreg = "access_group_id";
68  $action->lay->set("imgaccess", $action->GetIcon("access2.gif", "modify", 20));
69  } else {
70  $list = $u->GetUserList("TABLE", 0, 30, $filteruser);
71  $action->lay->set("maxreach", (count($list) == 30));
72  $action->lay->set("usefilter", true);
73  $varreg = "access_user_id";
74  $action->lay->set("imgaccess", $action->GetIcon("access.gif", "modify", 18));
75  }
76  // select the first user if not set
77  if ($user_id == "") $user_id = $action->Read($varreg);
78  else $action->register($varreg, $user_id);
79  $action->log->debug("user_id : $user_id");
80  if ($user_id == "") $user_id = 0;
81 
82  $tab = array();
83 
84  $action->lay->set("hasuser", $list ? true : false);
85  if ($list) {
86  $user_sel = $list[0];
87  foreach ($list as $k => $v) {
88  if ($v["id"] == 1) continue;
89  if ($user_id == 0) {
90  $user_id = $v["id"];
91  $action->Register($varreg, $user_id);
92  }
93  if (($v["lastname"] == "") && ($v["firstname"] == "")) {
94  $tab[$k]["text"] = $v["login"];
95  } else {
96  $tab[$k]["text"] = $v["lastname"] . " " . $v["firstname"] . " - " . $v["login"];
97  }
98  $tab[$k]["id"] = $v["id"];
99  if ($user_id == $v["id"]) {
100  $user_sel = $v;
101  $tab[$k]["selected"] = "selected";
102  } else {
103  $tab[$k]["selected"] = "";
104  }
105  }
106  $action->parent->AddJsRef("change_acl.js");
107 
108  $action->register($varreg, $user_sel["id"]);
109 
110  $action->lay->SetBlockData("SELUSER", $tab);
111  // 1) Get all application
112  $query = new QueryGen($action->dbaccess, "Application", $action);
113  $query->AddQuery("access_free = 'N'");
114  $query->AddQuery("(objectclass != 'Y' ) OR ( objectclass isnull)");
115  $query->table->headsortfields = array(
116  "shortname" => "name",
117  "desc" => "description"
118  );
119 
120  $query->table->headcontent = array(
121  "shortname" => $action->text("appname") ,
122  "desc" => $action->text("appdesc") ,
123  "permission" => $action->text("permissions")
124  );
125 
126  $query->table->fields = array(
127  "id",
128  "name",
129  "selname",
130  "description",
131  "edit"
132  );
133  $query->slice = 20;
134 
135  $query->Query();
136  // 2) Get all acl for all application
137  reset($query->table->array);
138 
139  while (list($k, $v) = each($query->table->array)) {
140 
141  if (!isset($v["id"])) continue;
142  // test if application is controled
143  $acl = new Acl($action->dbaccess);
144  if (!$acl->getAclApplication($v["id"])) continue;
145  // get user permissions
146  $uperm = new Permission($action->dbaccess, array(
147  $user_sel["id"],
148  $v["id"]
149  ));
150 
151  $name = $v["name"];
152 
153  $tab = array();
154  $aclids = $uperm->privileges;
155  if (!$aclids) { // no privilege
156  $aclids = array(
157  0
158  );
159  }
160 
161  while (list($k2, $v2) = each($aclids)) {
162  $tab[$k2]["aclid"] = $v2;
163 
164  if ($v2 == 0) {
165  $tab[$k2]["aclname"] = $action->text("none");
166  } else {
167  $acl = new Acl($action->dbaccess, $v2);
168  $tab[$k2]["aclname"] = $acl->name;
169  }
170  }
171  $action->lay->SetBlockData($v["id"], $tab);
172 
173  unset($tab);
174  unset($acls);
175  $query->table->array[$k]["name"] = $v["name"];
176  $query->table->array[$k]["selname"] = $v["name"];
177  $query->table->array[$k]["description"] = _($v["description"]);
178  $query->table->array[$k]["id"] = $v["id"];
179 
180  $query->table->array[$k]["edit"] = str_replace("[id]", $v["id"], $jsscript);
181  }
182 
183  $query->table->Set();
184  }
185 }
186 ?>
← centre documentaire © anakeen - published under CC License - Dynacase