Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_gaccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * View/Edit ACLs for a document
8  *
9  * @author Anakeen
10  * @version $Id: freedom_gaccess.php,v 1.16 2008/10/02 12:34:03 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 include_once ("FDL/Class.VGroup.php");
19 // -----------------------------------
20 function freedom_gaccess(Action & $action)
21 {
22  // -----------------------------------
23  //
24  // edition of group accessibilities
25  // ---------------------
26  // Get all the params
27  $dbaccess = $action->dbaccess;
28  $usage = new ActionUsage($action);
29  $usage->setStrictMode(false);
30  $usage->setDefinitionText("view or modify document accessibilities");
31  $docid = $usage->addRequiredParameter("id", "document identifier to profil");
32  $gid = $usage->addOptionalParameter("gid", "group identificator, view user access for this group");
33  $green = ($usage->addOptionalParameter("allgreen", "view only up acl", array(
34  "Y",
35  "N"
36  ) , "N") == "Y");
37  $viewgroup = ($usage->addOptionalParameter("group", "view group", array(
38  "Y",
39  "N"
40  ) , "N") == "Y");
41  $limit = $usage->addOptionalParameter("memberLimit", "when gid option is set, limit members to display", array() , 100);
42  $usage->verify();
43  // edition of group accessibilities
44  // ---------------------
45  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
46  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
47  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/AnchorPosition.js");
48  $action->parent->addJsRef("lib/jquery/jquery.js");
49  $action->parent->addCssRef("css/dcp/jquery-ui.css");
51  $err = $doc->control("viewacl");
52  if ($err != "") $action->exitError($err);
53 
54  $acls = $doc->acls;
55  $acls[] = "viewacl";
56  $acls[] = "modifyacl"; //add this acl global for every document
57  // $acls=array_merge($acls, $doc->extendedAcls);
58  // contruct headline
59  reset($acls);
60  $hacl = array();
61  $title = array();
62  $width = floor(70 / count($acls));
63  $action->lay->set("cellwidth", $width . '%');
64  /**
65  * @var $v string
66  */
67  foreach ($acls as $k => $v) {
68  $hacl[$k]["aclname"] = mb_ucfirst(_($v));
69  $desc = isset($doc->dacls[$v]) ? $doc->dacls[$v]["description"] : "";
70  if (!$desc) {
71  $desc = $doc->extendedAcls[$v]["description"];
72  } else {
73  $desc = _($desc);
74  }
75  $hacl[$k]["acldesc"] = mb_ucfirst($desc);
76  $hacl[$k]["oddoreven"] = ($k % 2) ? "even" : "odd";
77  }
78 
79  $action->lay->SetBlockData("DACLS", $hacl);
80  $action->lay->Set("title", $doc->title);
81  $action->lay->Set("hasgid", ($gid > 0));
82  $action->lay->Set("stitle", str_replace(array(
83  "[",
84  "]"
85  ) , "", $doc->title));
86  $tg = array(); // users or group list
87  if ($green) {
88 
89  $sql = sprintf("SELECT users.* from docperm,users where docperm.docid=%d and users.id=docperm.userid and docperm.upacl != 0 order by users.lastname", $doc->profid);
90  simpleQuery($dbaccess, $sql, $tusers);
91  $tgreenUid = array();
92  foreach ($tusers as $k => $v) {
93  $tgreenUid[] = $v["id"];
94  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
95  $tg[] = array(
96  "level" => 10,
97  "gid" => $v["id"],
98  "isdyn" => false,
99  "accountType" => $v["accounttype"],
100  "displaygroup" => ($v["accounttype"] != "U") ? "inline" : "none"
101  );
102  }
103 
104  if ($doc->extendedAcls) {
105  // add more users
106  $sql = sprintf("select users.id, users.firstname, users.lastname,users.accounttype, array_agg(docpermext.acl) as acls from docpermext,users where users.id=docpermext.userid and docpermext.docid=%d", $doc->profid);
107  if (!empty($tgreenUid)) $sql.= sprintf(" and id not in (%s)", implode(',', $tgreenUid));
108  $sql.= " group by users.id, users.firstname, users.lastname, users.accounttype ;";
109  simpleQuery($dbaccess, $sql, $tusers);
110  //print_r($sql);
111  //print_r($tusers);
112  foreach ($tusers as $k => $v) {
113 
114  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
115  $tg[] = array(
116  "level" => 10,
117  "gid" => $v["id"],
118  "isdyn" => false,
119  "extacl" => $v["acls"],
120  "accountType" => $v["accounttype"],
121  "displaygroup" => ($v["accounttype"] != "U") ? "inline" : "none"
122  );
123  }
124  }
125  } else if ($gid == 0) {
126  //-----------------------
127  // contruct grouplist
128  $ouser = new Account();
129  if ($viewgroup) {
130  $tidAccount = array_merge($ouser->getGroupList("TABLE") , $ouser->getRoleList("TABLE"));
131  } else {
132  $tidAccount = $ouser->getRoleList("TABLE");
133  }
134  $hg = array();
135  $userids = array();
136  $sgroup = array(); // all group which are in a group i.e. not the root group
137  foreach ($tidAccount as $k => $v) {
138  $g = new Group("", $v["id"]);
139 
140  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
141  foreach ($g->groups as $kg => $gid) {
142 
143  $hg[$gid][$v["id"]] = $v;
144  $sgroup[$v["id"]] = $v["id"]; // to define root group
145 
146  }
147  }
148  // foreach($hg as $k=>$v) {
149  foreach ($tidAccount as $k => $v) {
150  if (!in_array($v["id"], $sgroup)) {
151  // it's a root group
152  $tg = array_merge($tg, getTableG($hg, $v["id"], $v["accounttype"]));
153  }
154  }
155  if ($action->user->id > 1) {
156  $tg[] = array(
157  "level" => 0,
158  "gid" => $action->user->id,
159  "isdyn" => false,
160  "accountType" => "U",
161  "displaygroup" => "none"
162  );
163  $title[$action->user->id] = $action->user->firstname . " " . $action->user->lastname;
164  }
165  } else {
166  //-----------------------
167  // contruct user list
168  $ouser = new Account("", $gid);
169  if ($ouser->accounttype == 'G') {
170  $tusers = $ouser->getGroupUserList("TABLE", false, $limit);
171  } else {
172  $tusers = $ouser->getAllMembers($limit, false);
173  }
174  if (count($tusers) == $limit) $action->AddWarningMsg(sprintf(_("limit reached, only %d members has been displayed") , $limit));
175 
176  $tg[] = array(
177  "level" => 0,
178  "gid" => $gid,
179  "isdyn" => false,
180  "accountType" => $ouser->accounttype,
181  "displaygroup" => "none"
182  );
183  $title[$gid] = $ouser->firstname . " " . $ouser->lastname;
184  if ($tusers) {
185  foreach ($tusers as $k => $v) {
186 
187  if ($k > 100) {
188  $action->AddWarningMsg(sprintf(_("Not all users can be vieved.\nlimit %d has been reached") , $k));
189  break;
190  }
191  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
192  $tg[] = array(
193  "level" => 10,
194  "gid" => $v["id"],
195  "isdyn" => false,
196  "accountType" => $v["accounttype"],
197  "displaygroup" => "none"
198  );
199  }
200  }
201  }
202  // add dynamic group for dynamic profile
203  if ($doc->getRawValue("DPDOC_FAMID") > 0) {
204 
205  $pdoc = new_Doc($dbaccess, $doc->getRawValue("DPDOC_FAMID"));
206  $pattr = $pdoc->GetProfilAttributes();
207  /*
208  * @var NormalAttribute $v
209  */
210  foreach ($pattr as $k => $v) {
211  $vg = new Vgroup($dbaccess, $v->id);
212  if (!$vg->isAffected()) {
213  $vg->id = $v->id;
214  $vg->Add();
215  }
216  $tg[] = array(
217  "level" => 0,
218  "gid" => $vg->num,
219  "isdyn" => true,
220  "accountType" => $v->isMultiple() ? "M" : "D",
221  "displaygroup" => "none"
222  );
223  $title[$vg->num] = $v->getLabel();
224  }
225  }
226  //print_r2($tg);
227  // add group title
228  foreach ($tg as $k => $v) {
229  $tacl[$v["gid"]] = getTacl($dbaccess, $doc->dacls, $acls, $doc->profid, $v["gid"]);
230  $tg[$k]["gname"] = $title[$v["gid"]];
231  $tg[$k]["ACLS"] = "ACL$k";
232  $action->lay->setBlockData("ACL$k", $tacl[$v["gid"]]);
233  }
234  // print_r2($tacl);
235  $action->lay->setBlockData("GROUPS", $tg);
236  $action->lay->set("docid", $doc->id);
237 
238  $action->lay->eset("allgreen", $action->getArgument("allgreen", "N"));
239  $action->lay->set("viewgroup", (bool)$viewgroup);
240  $action->lay->eset("group", $action->getArgument("group", "N"));
241  $action->lay->set("isgreen", (bool)$green);
242  $err = $doc->control("modifyacl");
243  $action->lay->set("profcount", "");
244  $action->lay->set("cellWidth", "65");
245  if (count($acls) > 15) $action->lay->set("cellWidth", "50");
246 
247  $action->lay->set("updateWaitText", sprintf(_("Update profiling is in progress.")));
248  if ($err == "" && (!$doc->dprofid) && ($doc->profid == $doc->id)) {
249  $action->lay->set("MODIFY", true);
250  $action->lay->set("dmodify", "");
251  if ($doc->isRealProfile()) {
252  if ($doc->getRawValue("dpdoc_famid")) {
253 
254  simpleQuery($dbaccess, sprintf("select count(id) from docread where dprofid=%d", $doc->id) , $cont, true, true);
255  } else {
256  simpleQuery($dbaccess, sprintf("select count(id) from docread where profid=%d", $doc->id) , $cont, true, true);
257  $cont--;
258  }
259  if ($cont > 0) {
260  if ($cont > 1) $action->lay->set("profcount", sprintf(_("%d documents linked to the profil") , $cont));
261  else $action->lay->set("profcount", _("only one document linked to the profil"));
262  $action->lay->set("updateWaitText", sprintf(_("Update profiling of %d documents is in progress.") , $cont));
263  }
264  }
265  } else {
266  $action->lay->set("dmodify", "none");
267  $action->lay->set("MODIFY", false);
268  }
269 
270  $action->lay->Set("toOrigin", $doc->getDocAnchor($doc->id, 'account', true, false, false, 'latest', true));
271 
272  if ($doc->dprofid) {
273  $action->lay->Set("dynamic", true);
274  $action->lay->Set("dprofid", $doc->dprofid);
275  $action->lay->Set("toDynProfil", $doc->getHtmlTitle($doc->dprofid));
276  $action->lay->Set("ComputedFrom", _("Computed from profil"));
277  } elseif ($doc->profid != $doc->id) {
278 
279  $action->lay->Set("dynamic", true);
280  $action->lay->Set("dprofid", $doc->profid);
281  $action->lay->Set("toDynProfil", $doc->getHtmlTitle($doc->profid));
282  $action->lay->Set("ComputedFrom", _("Linked from profil"));
283  } else {
284  $action->lay->Set("dynamic", false);
285  }
286  $action->lay->setBlockData("legendcolor", array(
287  array(
288  "legendimage" => "G",
289  "legendexplication" => _("Legend:Groups")
290  ) ,
291  array(
292  "legendimage" => "U",
293  "legendexplication" => _("Legend:Users")
294  ) ,
295  array(
296  "legendimage" => "R",
297  "legendexplication" => _("Legend:Roles")
298  ) ,
299  array(
300  "legendimage" => "D",
301  "legendexplication" => _("Legend:Dynamic")
302  ) ,
303  array(
304  "legendimage" => "M",
305  "legendexplication" => _("Legend:Dynamic multiple")
306  )
307  ));
308 }
309 //--------------------------------------------
310 function getTableG($hg, $id, $type, $level = 0)
311 {
312  //--------------------------------------------
313  $r[] = array(
314  "gid" => $id,
315  "level" => $level * 10,
316  "isdyn" => false,
317  "accountType" => $type,
318  "displaygroup" => "inline"
319  );
320 
321  if (isset($hg[$id])) {
322  foreach ($hg[$id] as $kg => $account) {
323  $r = array_merge($r, getTableG($hg, $kg, $account["accounttype"], $level + 1));
324  }
325  }
326 
327  return $r;
328 }
329 //--------------------------------------------
330 function getTacl($dbaccess, $dacls, $acls, $docid, $gid, $extAcl = '')
331 {
332  //--------------------------------------------
333  $perm = new DocPerm($dbaccess, array(
334  $docid,
335  $gid
336  ));
337  $tableacl = array();
338  foreach ($acls as $k => $v) {
339  $tableacl[$k]["aclname"] = $v;
340  $pos = 0;
341  if (!$extAcl && isset($dacls[$v])) $pos = $dacls[$v]["pos"];
342  $tableacl[$k]["selected"] = "";
343  $tableacl[$k]["bimg"] = "1x1.gif";
344  $tableacl[$k]["oddoreven"] = ($k % 2) ? "even" : "odd";
345  $tableacl[$k]["aclid"] = $v;
346  $tableacl[$k]["iacl"] = $v; // index for table in xml
347  if (!$pos) {
348  $tableacl[$k]["aclname"] = $extAcl;
349  $grant = DocPermExt::hasExtAclGrant($docid, $gid, $v);
350  if ($grant) {
351  if ($grant == 'green') {
352  $tableacl[$k]["bimg"] = "bgreen.png";
353  $tableacl[$k]["selected"] = "checked";
354  } else {
355  $tableacl[$k]["bimg"] = "bgrey.png";
356  }
357  }
358  } elseif ($perm->ControlUp($pos)) {
359  $tableacl[$k]["selected"] = "checked";
360  $tableacl[$k]["bimg"] = "bgreen.png";
361  } else {
362  if ($perm->ControlU($pos)) {
363  $tableacl[$k]["bimg"] = "bgrey.png";
364  }
365  }
366  }
367  //print_r2($tableacl);
368  return $tableacl;
369 }
global $action
getTacl($dbaccess, $dacls, $acls, $docid, $gid, $extAcl= '')
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
static hasExtAclGrant($docid, $accountId, $aclName)
Verify arguments for action function.
mb_ucfirst($s)
Definition: Lib.Common.php:105
new_Doc($dbaccess, $id= '', $latest=false)
getTableG($hg, $id, $type, $level=0)
$account
Definition: guest.php:36
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
$usage
← centre documentaire © anakeen