Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * View/Edit ACLs for a document
9  *
10  * @author Anakeen 2000
11  * @version $Id: freedom_gaccess.php,v 1.16 2008/10/02 12:34:03 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 include_once ("FDL/Class.VGroup.php");
21 // -----------------------------------
23 {
24  // -----------------------------------
25  //
26  // edition of group accessibilities
27  // ---------------------
28  // Get all the params
29  $dbaccess = $action->GetParam("FREEDOM_DB");
30  $docid = GetHttpVars("id");
31  $gid = GetHttpVars("gid"); // view user access for the gid group (view all groups if null)
32  $green = (GetHttpVars("allgreen") == "Y"); // view only up or un acl
33  //
34  // edition of group accessibilities
35  // ---------------------
36  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
37  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
38  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/AnchorPosition.js");
39 
41  $err = $doc->control("viewacl");
42  if ($err != "") $action->exitError($err);
43 
44  $acls = $doc->acls;
45  $acls[] = "viewacl";
46  $acls[] = "modifyacl"; //add this acl global for every document
47  // contruct headline
48  reset($acls);
49  $hacl = array();
50  $width = floor(70 / count($acls));
51  $action->lay->set("cellwidth", $width . '%');
52  foreach ($acls as $k => $v) {
53  $hacl[$k]["aclname"] = ucfirst(_($v));
54  $hacl[$k]["acldesc"] = ucfirst(_($doc->dacls[$v]["description"]));
55  $hacl[$k]["oddoreven"] = ($k % 2) ? "even" : "odd";
56  }
57 
58  $action->lay->SetBlockData("DACLS", $hacl);
59  $action->lay->Set("title", $doc->title);
60  $action->lay->Set("stitle", str_replace(array(
61  "[",
62  "]"
63  ) , "", $doc->title));
64  $tg = array(); // users or group list
65  if ($green) {
66  $ouser = new User("", $gid);
67  $tusers = $ouser->GetUserAndGroupList("TABLE");
68 
69  $q = new QueryDb($dbaccess, "DocPerm");
70  $q->AddQuery("docid=" . $doc->id);
71  $q->AddQuery("upacl != 0 OR unacl != 0");
72  $l = $q->Query(0, 0, "TABLE");
73 
74  $lu = array();
75  if ($q->nb > 0) {
76  foreach ($l as $lp) {
77  $lu[] = $lp["userid"];
78  }
79  if ($tusers) {
80  foreach ($tusers as $k => $v) {
81  if (in_array($v["id"], $lu)) {
82  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
83  $tg[] = array(
84  "level" => 10,
85  "gid" => $v["id"],
86  "displaydyn" => "none",
87  "isdyngroup" => false,
88  "displayuser" => ($v["isgroup"] != "Y") ? "inline" : "none",
89  "displaygroup" => ($v["isgroup"] == "Y") ? "inline" : "none"
90  );
91  }
92  }
93  }
94  }
95  } else if ($gid == 0) {
96  //-----------------------
97  // contruct grouplist
98  $ouser = new User();
99  $tiduser = $ouser->GetGroupList("TABLE");
100  $hg = array();
101  $userids = array();
102  $sgroup = array(); // all group which are in a group i.e. not the root group
103  foreach ($tiduser as $k => $v) {
104  $g = new Group("", $v["id"]);
105 
106  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
107  foreach ($g->groups as $kg => $gid) {
108 
109  $hg[$gid][$v["id"]] = $v["id"];
110  $sgroup[$v["id"]] = $v["id"]; // to define root group
111 
112  }
113  }
114  // foreach($hg as $k=>$v) {
115  foreach ($tiduser as $k => $v) {
116  if (!in_array($v["id"], $sgroup)) {
117  // it's a root group
118  $tg = array_merge($tg, getTableG($hg, $v["id"]));
119  }
120  }
121  if ($action->user->id > 1) {
122  $tg[] = array(
123  "level" => 0,
124  "gid" => $action->user->id,
125  "displayuser" => "inline",
126  "displaydyn" => "none",
127  "isdyngroup" => false,
128  "displaygroup" => "none"
129  );
130  $title[$action->user->id] = $action->user->firstname . " " . $action->user->lastname;
131  }
132  } else {
133  //-----------------------
134  // contruct user list
135  $ouser = new User("", $gid);
136  $tusers = $ouser->getGroupUserList("TABLE");
137 
138  $tg[] = array(
139  "level" => 0,
140  "gid" => $gid,
141  "displayuser" => "none",
142  "displaydyn" => "none",
143  "isdyngroup" => false,
144  "displaygroup" => "inline"
145  );
146  $title[$gid] = $ouser->firstname . " " . $ouser->lastname;
147  if ($tusers) {
148  foreach ($tusers as $k => $v) {
149 
150  if ($k > 100) {
151  $action->AddWarningMsg(sprintf(_("Not all users can be vieved.\nlimit %d has been reached") , $k));
152  break;
153  }
154  $title[$v["id"]] = $v["firstname"] . " " . $v["lastname"];
155  $tg[] = array(
156  "level" => 10,
157  "gid" => $v["id"],
158  "displaydyn" => "none",
159  "isdyngroup" => false,
160  "displayuser" => "inline",
161  "displaygroup" => "none"
162  );
163  }
164  }
165  }
166  // add dynamic group for dynamic profile
167  if ($doc->getValue("DPDOC_FAMID") > 0) {
168 
169  $pdoc = new_Doc($dbaccess, $doc->getValue("DPDOC_FAMID"));
170  $pattr = $pdoc->GetProfilAttributes();
171 
172  foreach ($pattr as $k => $v) {
173  $vg = new Vgroup($dbaccess, $v->id);
174  if (!$vg->isAffected()) {
175  $vg->id = $v->id;
176  $vg->Add();
177  }
178  $tg[] = array(
179  "level" => 0,
180  "gid" => $vg->num,
181  "isdyngroup" => $v->inArray() ,
182  "displaydyn" => "inline",
183  "displayuser" => "none",
184  "displaygroup" => "none"
185  );
186  $title[$vg->num] = $v->getLabel();
187  }
188  }
189  // add group title
190  foreach ($tg as $k => $v) {
191  $tacl[$v["gid"]] = getTacl($dbaccess, $doc->dacls, $acls, $docid, $v["gid"]);
192  $tg[$k]["gname"] = $title[$v["gid"]];
193  $tg[$k]["ACLS"] = "ACL$k";
194  $action->lay->setBlockData("ACL$k", $tacl[$v["gid"]]);
195  }
196 
197  $action->lay->setBlockData("GROUPS", $tg);
198  $action->lay->set("docid", $docid);
199 
200  $action->lay->set("allgreen", getHttpVars("allgreen", "N"));
201  $action->lay->set("isgreen", $green);
202  $err = $doc->control("modifyacl");
203  if ($err == "") {
204  $action->lay->setBlockData("MODIFY", array(
205  array(
206  "zou"
207  )
208  ));
209  $action->lay->set("dmodify", "");
210  } else $action->lay->set("dmodify", "none");
211 }
212 //--------------------------------------------
213 function getTableG($hg, $id, $level = 0)
214 {
215  //--------------------------------------------
216  $r[] = array(
217  "gid" => $id,
218  "level" => $level * 10,
219  "displayuser" => "none",
220  "displaydyn" => "none",
221  "isdyngroup" => false,
222  "displaygroup" => "inline"
223  );
224  if (isset($hg[$id])) {
225  reset($hg[$id]);
226  while (list($kg, $gid) = each($hg[$id])) {
227  $r = array_merge($r, getTableG($hg, $gid, $level + 1));
228  }
229  }
230 
231  return $r;
232 }
233 //--------------------------------------------
234 function getTacl($dbaccess, $dacls, $acls, $docid, $gid)
235 {
236  //--------------------------------------------
237  $perm = new DocPerm($dbaccess, array(
238  $docid,
239  $gid
240  ));
241 
242  foreach ($acls as $k => $v) {
243  $tableacl[$k]["aclname"] = $v;
244  $pos = $dacls[$v]["pos"];
245 
246  $tableacl[$k]["oddoreven"] = ($k % 2) ? "even" : "odd";
247  $tableacl[$k]["aclid"] = $pos;
248  $tableacl[$k]["iacl"] = $k; // index for table in xml
249  if ($perm->ControlUp($pos)) {
250  $tableacl[$k]["selected"] = "checked";
251  $tableacl[$k]["bimg"] = "bgreen.png";
252  } else {
253  $tableacl[$k]["selected"] = "";
254  if ($perm->ControlU($pos)) {
255  $tableacl[$k]["bimg"] = "bgrey.png";
256  } else {
257  if ($perm->ControlUn($pos)) $tableacl[$k]["bimg"] = "bred.png";
258  else $tableacl[$k]["bimg"] = "1x1.gif";
259  }
260  }
261  }
262 
263  return $tableacl;
264 }
265 ?>
← centre documentaire © anakeen - published under CC License - Dynacase