Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
appl_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: appl_access.php,v 1.7 2007/02/16 14:11:14 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: appl_access.php,v 1.7 2007/02/16 14:11:14 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Action/Access/appl_access.php,v $
21 // ---------------------------------------------------------------
22 include_once ("Class.QueryDb.php");
23 include_once ("Class.SubForm.php");
24 include_once ("Class.QueryGen.php");
25 // -----------------------------------
26 function appl_access(&$action, $oid = 0)
27 {
28  // -----------------------------------
29  $baseurl = $action->GetParam("CORE_BASEURL");
30  $standurl = $action->GetParam("CORE_STANDURL");
31 
32  $action->lay->set("usefilter", false);
33  $action->lay->set("maxreach", false);
34  // affect the select form elements
35  $query = new QueryDb("", "Application");
36  if ($oid == 0) {
37  $query->AddQuery("(objectclass != 'Y' ) OR ( objectclass isnull)");
38  $varreg = "access_appl_id";
39  $paramedit = "&isclass=no";
40  } else {
41  $query->AddQuery("objectclass = 'Y'");
42  $varreg = "access_class_id";
43  $paramedit = "&isclass=yes&oid=$oid";
44  }
45  $applist = $query->Query();
46  unset($query);
47 
48  $action->lay->set("ACTION_CHG", "ACCESS_APPL_CHG$paramedit");
49  $action->lay->set("ACTION_MOD", "APPL_ACCESS_MOD$paramedit");
50  // select the first user if not set
51  $appl_id = $action->Read($varreg);
52 
53  if ($appl_id == "") $appl_id = 0;
54  // Set the edit form element
55  $form = new SubForm("edit", 500, 330, "not used", $standurl . "app=ACCESS&action=EDIT&mod=app$paramedit");
56  $form->SetParam("id", "-1");
57  $form->SetKey("id");
58 
59  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
60  $action->parent->AddJsCode($form->GetMainJs());
61  $jsscript = $form->GetLinkJsMainCall();
62 
63  $action->lay->set("hasuser", true);
64  // display application / object class
65  $tab = array();
66  $appl_sel = "";
67  $i = 0;
68  if (is_array($applist)) {
69  reset($applist);
70  while (list($k, $v) = each($applist)) {
71 
72  if (($v->objectclass == "Y") || (true)) {
73  $query = new QueryDb("", "Acl");
74  $query->basic_elem->sup_where = array(
75  "id_application={$v->id}"
76  );
77  $acl_list = $query->Query("", "", "TABLE");
78  if ($query->nb == 0) continue;
79  if ($appl_id == 0) {
80  $appl_id = $v->id;
81  $action->Register($varreg, $appl_id);
82  }
83  if ($oid != 0) $tab[$i]["text"] = _($v->short_name);
84  else $tab[$i]["text"] = $v->name;
85  $tab[$i]["id"] = $v->id;
86  if ($appl_id == $v->id) {
87  $appl_sel = $v;
88  $appl_sel->acl = $acl_list;
89  $tab[$i]["selected"] = "selected";
90  } else {
91  $tab[$i]["selected"] = "";
92  }
93  $i++;
94  }
95  }
96 
97  $action->lay->SetBlockData("SELUSER", $tab);
98  $action->parent->AddJsRef("change_acl.js");
99  // Init a querygen object to select users
100  $query = new QueryGen($action->dbaccess, "User", $action);
101  //
102  // Give some global elements for the table layout
103  $query->table->fields = array(
104  "id",
105  "name",
106  "selname",
107  "description",
108  "lastname",
109  "firstname",
110  "edit",
111  "imgaccess"
112  );
113  $query->table->headsortfields = array(
114  "shortname" => "login",
115  "desc" => "lastname"
116  );
117 
118  $query->table->headcontent = array(
119  "shortname" => _("userlogin") ,
120  "desc" => _("username") ,
121  "permission" => _("permissions")
122  );
123  // 1) Get all users except admin
124  $query->AddQuery("id != 1");
125  $query->slice = 20;
126  $query->Query();
127  // 2) Get all acl for all users
128  reset($query->table->array);
129  unset($tab);
130 
131  while (list($k, $v) = each($query->table->array)) {
132  if (!isset($v["login"])) continue;
133 
134  if ($oid == 0) $uperm = new Permission($action->dbaccess, array(
135  $v["id"],
136  $appl_sel->id
137  ));
138  else $uperm = new ObjectPermission($action->dbaccess, array(
139  $v["id"],
140  $oid,
141  $appl_sel->id
142  ));
143  $name = $v["login"];
144 
145  $tab = array();
146  $aclids = $uperm->privileges;
147  if (!$aclids) { // no privilege
148  $aclids = array(
149  0
150  );
151  }
152 
153  while (list($k2, $v2) = each($aclids)) {
154  $tab[$k2]["aclid"] = $v2;
155 
156  if ($v2 == 0) {
157  $tab[$k2]["aclname"] = $action->text("none");
158  } else {
159  $acl = new Acl($action->dbaccess, $v2);
160  $tab[$k2]["aclname"] = $acl->name;
161  }
162  }
163  $action->lay->SetBlockData($v["id"], $tab);
164  unset($tab);
165 
166  $query->table->array[$k]["name"] = $v["login"];
167  $query->table->array[$k]["selname"] = $v["id"];
168  $query->table->array[$k]["id"] = $v["id"];
169  if (!isset($v["firstname"])) $v["firstname"] = "";
170  if (!isset($v["lastname"])) $v["lastname"] = "";
171  $query->table->array[$k]["description"] = $v["firstname"] . " " . $v["lastname"];
172  $query->table->array[$k]["edit"] = str_replace("[id]", $v["id"], $jsscript);
173  if ($v["isgroup"] == "Y") {
174  $query->table->array[$k]["imgaccess"] = $action->GetIcon("access2.gif", "modify", 20);
175  } else {
176  $query->table->array[$k]["imgaccess"] = $action->GetIcon("access.gif", "modify", 18);
177  }
178  }
179 
180  $query->table->Set();
181  } else {
182  $action->ExitError("no class controlled");
183  }
184 }
185 ?>
← centre documentaire © anakeen - published under CC License - Dynacase