Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
viewacl.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @author Anakeen
10  * @version $Id: viewacl.php,v 1.5 2007/03/12 17:38:41 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 // ---------------------------------------------------------------
17 // $Id: viewacl.php,v 1.5 2007/03/12 17:38:41 eric Exp $
18 // $Source: /home/cvsroot/anakeen/freedom/freedom/Zone/Fdl/viewacl.php,v $
19 // ---------------------------------------------------------------
20 // ---------------------------------------------------------------
21 include_once ("FDL/Class.Doc.php");
22 // -----------------------------------
23 function viewacl(Action & $action)
24 {
25  // ------------------------
26  $docid = intval($action->getArgument("docid"));
27  $userid = intval($action->getArgument("userid"));
28 
29  $dbaccess = $action->dbaccess;
30 
31  $doc = new_Doc($dbaccess, $docid);
32  $err = $doc->control('viewacl');
33  if ($err) $action->exitError($err);
34  //-------------------
35  $perm = new DocPerm($dbaccess, array(
36  $doc->profid,
37  $userid
38  ));
39 
40  $acls = $doc->acls;
41  $acls[] = "viewacl";
42  $acls[] = "modifyacl"; //add this acl global for every document
43  $tableacl = array();
44 
45  $user = new Account($dbaccess, $userid);
46 
47  $action->lay->Set("docid", $doc->id);
48  $action->lay->Set("userid", $user->id);
49  foreach ($acls as $k => $acl) {
50  $tableacl[$k]["aclname"] = mb_ucfirst(_($acl));
51 
52  if (!empty($doc->dacls[$acl]["description"])) {
53 
54  $tableacl[$k]["acldesc"] = _($doc->dacls[$acl]["description"]);
55  } else {
56  $tableacl[$k]["acldesc"] = "";
57  }
58 
59  $tableacl[$k]["aclid"] = $acl;
60  $tableacl[$k]["iacl"] = $acl; // index for table in xml
61  if (isset($doc->extendedAcls[$acl])) {
62  $grant = DocPermExt::hasExtAclGrant($docid, $user->id, $acl);
63  if ($grant == 'green') {
64 
65  $tableacl[$k]["selectedup"] = "checked";
66  $tableacl[$k]["imgacl"] = "bgreen.png";
67  } else {
68  $tableacl[$k]["selectedup"] = "";
69  if ($grant == 'grey') {
70  $tableacl[$k]["imgacl"] = "bgrey.png";
71  } else {
72  $tableacl[$k]["imgacl"] = "bred.png";
73  }
74  }
75  } else {
76 
77  $pos = $doc->dacls[$acl]["pos"];
78  if ($perm->ControlUp($pos)) {
79 
80  $tableacl[$k]["selectedup"] = "checked";
81  $tableacl[$k]["imgacl"] = "bgreen.png";
82  } else {
83  $tableacl[$k]["selectedup"] = "";
84  if ($perm->ControlU($pos)) {
85  $tableacl[$k]["imgacl"] = "bgrey.png";
86  } else {
87  $tableacl[$k]["imgacl"] = "bred.png";
88  }
89  }
90  }
91  $tableacl[$k]["aclcause"] = getAclCause($acl, $doc, $perm, $user);
92  }
93  $action->lay->set("readonly", ($doc->control("modifyacl") != '' || $doc->dprofid || $doc->profid != $doc->id));
94  $action->lay->setBlockData("SELECTACL", $tableacl);
95  $action->lay->set("updateWaitText", sprintf(_("Update profiling is in progress.")));
96 }
97 
98 function getAclCause($acl, Doc & $doc, DocPerm & $perm, Account & $user)
99 {
100  $Aclpos = isset($doc->dacls[$acl]["pos"]) ? $doc->dacls[$acl]["pos"] : -1;
101  $msg = '?';
102  if (($Aclpos !== - 1 && $perm->ControlUp($Aclpos)) || DocPermExt::hasExtAclGrant($doc->id, $user->id, $acl) == 'green') {
103  if (!$doc->dprofid) {
104  // direct green
105  if ($doc->profid == $doc->id) {
106  $msg = sprintf(_("Direct set through document itself \"%s\"") , $doc->getHtmlTitle());
107  } else {
108  // linked green
109  $msg = sprintf(_("Set through \"%s\" linked profil") , $doc->getHtmlTitle($doc->profid));
110  }
111  } else {
112  // Dynamic profiling
113  $dperm = new DocPerm($perm->dbaccess, array(
114  $doc->dprofid,
115  $perm->userid
116  ));
117 
118  $tAtt = array();
119  if ($dperm->isAffected()) {
120  if ($dperm->ControlUp($Aclpos)) {
121  $tAtt[] = sprintf(_("explicit privilege"));
122  $msg = sprintf(_("Set from template profil \"%s\"") , $doc->getHtmlTitle($doc->dprofid));
123  } else {
124  $msg = sprintf(_("Something wrong. No acl found in %s (user #%d)") , $doc->getHtmlTitle($doc->dprofid) , $perm->userid);
125  }
126  }
127  // search in dynamic
128  $sql = sprintf('select vgroup.id as aid from docperm,vgroup where docid=%d and userid >= %d and upacl & %d != 0 and docperm.userid=vgroup.num', $doc->dprofid, STARTIDVGROUP, 1 << $Aclpos);
129  simpleQuery($perm->dbaccess, $sql, $dynAids, true);
130  foreach ($dynAids as $aid) {
131  $va = $doc->getRawValue($aid);
132  if ($va) {
133  $tva = explode("\n", str_replace('<BR>', "\n", $va));
134  if (in_array($user->fid, $tva)) {
135  $oa = $doc->getAttribute($aid);
136  if ($oa) $alabel = $oa->getLabel();
137  else $alabel = $aid;
138  $tAtt[] = sprintf(_("the attribute %s") , htmlspecialchars($alabel));
139  }
140  }
141  }
142  if (count($tAtt) > 0) {
143  $sAtt = '<ul><li>' . implode('</li><li>', $tAtt) . '</li></ul>';
144  $msg = sprintf(_("Set by %s from template profil \"%s\"") , $sAtt, $doc->getHtmlTitle($doc->dprofid));
145  }
146  }
147  } else if ($perm->ControlU($Aclpos) || DocPermExt::hasExtAclGrant($doc->id, $user->id, $acl) == 'grey') {
148  $msg = '? role/group';
149  if (!$doc->dprofid) {
150  // grey
151  $msg = '? profid role/group';
152  if (isset($doc->extendedAcls[$acl])) {
153  $sql = sprintf("SELECT userid from docpermext where docid=%d and acl = '%s'", $doc->profid, pg_escape_string($acl));
154  } else {
155  $sql = sprintf("SELECT userid from docperm where docid=%d and upacl & %d != 0", $doc->profid, 1 << $Aclpos);
156  }
157  simpleQuery($perm->dbaccess, $sql, $gids, true);
158  $mo = $user->getMemberOf();
159 
160  $asIds = array_intersect($gids, $mo);
161  $sFrom = "?";
162  if (count($asIds) > 0) {
163  $sql = sprintf("select fid, accounttype, lastname, login from users where %s", GetSqlCond($asIds, "id", true));
164  simpleQuery($perm->dbaccess, $sql, $uas);
165 
166  $tFrom = array();
167  foreach ($uas as $as) {
168  if ($as["accounttype"] == 'R') {
169  $tFrom[] = sprintf(_("Role \"%s\"") , htmlspecialchars($as["lastname"]));
170  } else {
171  $tFrom[] = sprintf(_("Group \"%s\"") , htmlspecialchars($as["lastname"]));
172  }
173  }
174  if (count($tFrom) > 0) {
175  $sFrom = '<ul><li>' . implode('</li><li>', $tFrom) . '</li></ul>';
176  } else {
177  $sFrom = implode(', ', $tFrom);
178  }
179  }
180  if ($doc->profid == $doc->id) {
181  $msg = sprintf(_("Set by %s through document itself \"%s\"") , $sFrom, $doc->getHtmlTitle());
182  } else {
183  $msg = sprintf(_("Set by %s through \"%s\" linked profil") , $sFrom, $doc->getHtmlTitle($doc->profid));
184  }
185  } else {
186  $msg = '? dprofid role/group';
187 
188  $sql = sprintf("SELECT userid from docperm where docid=%d and upacl & %d != 0", $doc->dprofid, 1 << $Aclpos);
189  simpleQuery($perm->dbaccess, $sql, $gids, true);
190  $mo = $user->getMemberOf();
191 
192  $asIds = array_intersect($gids, $mo);
193  $sFrom = "?";
194  if (count($asIds) > 0) {
195  $sql = sprintf("select fid, accounttype, lastname, login from users where %s", GetSqlCond($asIds, "id", true));
196  simpleQuery($perm->dbaccess, $sql, $uas);
197 
198  $tFrom = array();
199  foreach ($uas as $as) {
200  if ($as["accounttype"] == 'R') {
201  $tFrom[] = sprintf(_("Role \"%s\"") , htmlspecialchars($as["lastname"]));
202  } else {
203  $tFrom[] = sprintf(_("Group \"%s\"") , htmlspecialchars($as["lastname"]));
204  }
205  }
206  if (count($tFrom) > 0) {
207  $sFrom = '<ul><li>' . implode('</li><li>', $tFrom) . '</li></ul>';
208  } else {
209  $sFrom = implode(', ', $tFrom);
210  }
211  $msg = sprintf(_("Set by %s through template profil \"%s\"") , $sFrom, $doc->getHtmlTitle($doc->dprofid));
212  } else {
213  $msg = sprintf(_("Set by %s through template profil \"%s\"") , $sFrom, $doc->getHtmlTitle($doc->dprofid));
214  // search in dynamic
215  $sql = sprintf('select vgroup.id as aid from docperm,vgroup where docid=%d and userid >= %d and upacl & %d != 0 and docperm.userid=vgroup.num', $doc->dprofid, STARTIDVGROUP, 1 << $Aclpos);
216  simpleQuery($perm->dbaccess, $sql, $dynAids, true);
217  $mo = $user->getMemberOf(false);
218  foreach ($dynAids as $aid) {
219  $va = $doc->getRawValue($aid);
220  if ($va) {
221  $tva = explode("\n", str_replace('<BR>', "\n", $va));
222  $as = array_intersect($tva, $mo);
223  if (count($as) > 0) {
224  $oa = $doc->getAttribute($aid);
225  if ($oa) $alabel = $oa->getLabel();
226  else $alabel = $aid;
227  $gv = array();
228  foreach ($as as $gid) {
229  $gv[] = $doc->getHtmlTitle($gid);
230  }
231 
232  $msg = sprintf(_("Set by \"%s\" attribute (%s) from template profil \"%s\"") , htmlspecialchars($alabel) , implode(', ', $gv) , $doc->getHtmlTitle($doc->dprofid));
233  }
234  }
235  }
236  }
237  }
238  } else {
239  $msg = '';
240  }
241  return $msg;
242 }
viewacl(Action &$action)
Definition: viewacl.php:23
global $action
& getAttribute($idAttr, &$oa=null, $useMask=true)
Definition: Class.Doc.php:2152
ControlUp($pos)
const STARTIDVGROUP
ControlU($pos)
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
getAclCause($acl, Doc &$doc, DocPerm &$perm, Account &$user)
Definition: viewacl.php:98
static hasExtAclGrant($docid, $accountId, $aclName)
mb_ucfirst($s)
Definition: Lib.Common.php:105
new_Doc($dbaccess, $id= '', $latest=false)
GetSqlCond($Table, $column, $integer=false)
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
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
getMemberOf($useSystemId=true)
← centre documentaire © anakeen