PageRenderTime 63ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/Zone/Fdl/viewacl.php

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