PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/edit_permissions.php

https://github.com/adamfranco/segue-1.x
PHP | 366 lines | 239 code | 61 blank | 66 comment | 58 complexity | a777d62217d4557c5c46f3e4d73023ef MD5 | raw file
  1. <? /* $Id$ */
  2. /******************************************************************************
  3. * edit_permissions takes in one variable: $site
  4. *
  5. * The first screen is for the adding, delete, and choosing of editors
  6. * The second screen is for the editing of the permissions for selected editors
  7. ******************************************************************************/
  8. require("objects/objects.inc.php");
  9. ob_start();
  10. session_start();
  11. //printpre($classname);
  12. // include all necessary files
  13. require("includes.inc.php");
  14. if ($_REQUEST[cancel]) {
  15. unset($_SESSION[obj],$_SESSION[editors]);
  16. header("Location: close.php");
  17. exit;
  18. }
  19. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  20. if ($_REQUEST[site] && isset($_SESSION[obj])) {
  21. if ($_REQUEST[site] != $_SESSION[obj]->name)
  22. unset($_SESSION[obj],$_SESSION[editors]);
  23. }
  24. /******************************************************************************
  25. * create the site object if it doesn't exist.
  26. ******************************************************************************/
  27. if (!is_object($_SESSION[obj])) {
  28. $_SESSION[obj] =& new site($_REQUEST[site]);
  29. $_SESSION[obj]->fetchSiteAtOnceForeverAndEverAndDontForgetThePermissionsAsWell_Amen(0,1);
  30. $_SESSION[obj]->spiderDownLockedFlag();
  31. }
  32. $site_owner = $_SESSION[obj]->owner;
  33. $isOwner = $isEditor = 1;
  34. if ($site_owner != $_SESSION[auser]) {
  35. /* error("You are not allowed to edit permissions for this site!"); */
  36. $isOwner = 0;
  37. }
  38. if (!$isOwner && !$_SESSION[obj]->isEditor()) {
  39. error("You are not an editor for this site. You may not view any permissions.");
  40. $isEditor=0;
  41. }
  42. /* $_SESSION[obj]->buildPermissionsArray(0,1); */
  43. if (!isset($_SESSION[editors])) $_SESSION[editors] = array();
  44. //print "here";exit;
  45. if ($error) { printerr2(); return; }
  46. //printpre($_SESSION[editors]);
  47. //printpre($_REQUEST);
  48. /******************************************************************************
  49. * Save changes to the DB
  50. ******************************************************************************/
  51. if ($_REQUEST[savechanges]) {
  52. if ($isOwner) {
  53. /* print "<pre>"; print_r($_SESSION[obj]); print "</pre>"; */
  54. /* begin bug-fix X-294273alpha. thank you, Adam. */
  55. // go through each editor and make sure that they are in the local DB.
  56. print_r($_SESSION[obj]->getEditors());
  57. foreach ($_SESSION[obj]->getEditors() as $_editor) {
  58. if(!$_editor) continue;
  59. print "synchronizing $_editor...<br />";
  60. synchronizeLocalUserAndClassDB($_editor);
  61. }
  62. /* end bug-fix. Again, thank you, Adam. */
  63. $_SESSION[obj]->updateDB(1);
  64. // print_r($_SESSION[obj]->editorsToDelete);
  65. $_SESSION[obj]->deletePendingEditors();
  66. // echo "<pre>";
  67. // print_r($_SESSION[obj]);
  68. unset($_SESSION[obj],$_SESSION[editors]);
  69. Header("Location: close.php");
  70. exit;
  71. }
  72. }
  73. /******************************************************************************
  74. * Editor Actions:
  75. ******************************************************************************/
  76. if ($isOwner && $_REQUEST[edaction] == 'add') {
  77. if (isgroup($_REQUEST[edname])) {
  78. $classes = group::getClassesFromName($_REQUEST[edname]);
  79. foreach ($classes as $class) {
  80. $_SESSION[obj]->addEditor($class);
  81. }
  82. } else {
  83. $_SESSION[obj]->addEditor($_REQUEST[edname]);
  84. }
  85. }
  86. if ($isOwner && $_REQUEST[edaction] == 'del') {
  87. $_SESSION[obj]->delEditor($_REQUEST[edname]);
  88. }
  89. /******************************************************************************
  90. * switch between forms 1 and 2
  91. ******************************************************************************/
  92. $step = $_REQUEST['step'];
  93. if (!$isOwner && $isEditor) {
  94. if (!count($_SESSION[editors])) {
  95. if (in_array($_SESSION[auser],$_SESSION[obj]->getEditors()))
  96. $_SESSION[editors][] = $_SESSION[auser];
  97. $groupsAndClasses = array_unique(
  98. array_merge(
  99. $_SESSION[obj]->returnEditorOverlap(
  100. getuserclasses($_SESSION[auser],"all")),
  101. getusergroups($_SESSION[auser])));
  102. foreach ($groupsAndClasses as $groupOrClass) {
  103. if (in_array($groupOrClass, $_SESSION[obj]->getEditors()))
  104. $_SESSION[editors][] = $groupOrClass;
  105. }
  106. // done... now send them to step 2
  107. $step = 2;
  108. }
  109. }
  110. if($isOwner && $_REQUEST[editpermissions]) {
  111. if (!count($_REQUEST[editors])) {
  112. error("You must choose some editors.");
  113. } else {
  114. $_SESSION[editors] = $_REQUEST[editors];
  115. $step = 2;
  116. }
  117. }
  118. if ($isOwner && $_REQUEST[chooseeditors]) {
  119. $step = 1;
  120. }
  121. if (!$isOwner)
  122. $step = 2;
  123. /******************************************************************************
  124. * catch any change field functionality
  125. ******************************************************************************/
  126. $fieldchange = $_REQUEST[fieldchange];
  127. $pscope = $_REQUEST[pscope];
  128. $psite = $_REQUEST[psite];
  129. $psection = $_REQUEST[psection];
  130. $ppage = $_REQUEST[ppage];
  131. $pstory = $_REQUEST[pstory];
  132. $pfield = $_REQUEST[pfield];
  133. $pwhat = $_REQUEST[pwhat];
  134. $puser = $_REQUEST[puser];
  135. //print "$pscope - $psite - $psection - $ppage - $pstory - $pfield - $pwhat - $puser";
  136. if ($isOwner) {
  137. if ($fieldchange) { // we're supposed to change a field
  138. $_a = array("story"=>0,"page"=>1,"section"=>2,"site"=>3);
  139. if ($pscope == 'site') $theObj = &$_SESSION[obj];
  140. if ($pscope == 'section') $theObj = &$_SESSION[obj]->sections[$psection];
  141. if ($pscope == 'page') $theObj = &$_SESSION[obj]->sections[$psection]->pages[$ppage];
  142. if ($pscope == 'story') $theObj = &$_SESSION[obj]->sections[$psection]->pages[$ppage]->stories[$pstory];
  143. if ($pfield == 'locked') {
  144. $theObj->setField('locked',$pwhat);
  145. }
  146. if (ereg("perms-([a-z]){1,}",$pfield)) {
  147. $regs = split('-',$pfield);
  148. $perm = $regs[1];
  149. $theObj->setUserPermissionDown($perm,$puser,$pwhat);
  150. $theObj->setFieldDown("l%$puser%$perm",$pwhat);
  151. // echo "l-$puser-$perm: ".$pwhat;
  152. if ($pwhat ==1) $theObj->setField("l%$puser%$perm",(1-$pwhat));
  153. }
  154. }
  155. }
  156. /******************************************************************************
  157. * common styles/javascripts:
  158. ******************************************************************************/
  159. ?>
  160. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  161. <html>
  162. <head>
  163. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  164. <title><? print ($isOwner)?"Edit Permissions - ":"Your Permissions - "; print $_SESSION[obj]->getField("title"); ?></title>
  165. <style type='text/css'>
  166. a {
  167. color: #a33;
  168. text-decoration: none;
  169. }
  170. a:hover {text-decoration: underline;}
  171. table {
  172. border: 1px solid #555;
  173. }
  174. th, td {
  175. border: 0px;
  176. background-color: #ddd;
  177. }
  178. .viewcol {
  179. background-color: #cec;
  180. border-left: 2px solid #FFF;
  181. }
  182. .lockedcol {
  183. background-color: #ecc;
  184. }
  185. .collabel {
  186. text-align: center;
  187. background-color: #bbb;
  188. }
  189. .edname {
  190. border-left: 2px solid #FFF;
  191. }
  192. .td1 {
  193. background-color: #ccc;
  194. }
  195. .td0 {
  196. background-color: #ddd;
  197. }
  198. th {
  199. background-color: #bbb;
  200. font-variant: small-caps;
  201. }
  202. body {
  203. background-color: white;
  204. }
  205. body, table, td, th, input {
  206. font-size: 12px;
  207. font-family: "Verdana", "sans-serif";
  208. }
  209. input {
  210. border: 1px solid black;
  211. background-color: white;
  212. font-size: 10px;
  213. }
  214. </style>
  215. <script type='text/javascript'>
  216. // <![CDATA[
  217. function doWindow(name,width,height) {
  218. var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
  219. win.focus();
  220. }
  221. function sendWindow(name,width,height,url) {
  222. var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
  223. win.document.location=url.replace(/&amp;/, '&');
  224. win.focus();
  225. }
  226. function checkAll() {
  227. field = document.forms[0].elements['editors[]'];
  228. for (i = 0; i < field.length; i++)
  229. field[i].checked = true ;
  230. }
  231. function uncheckAll() {
  232. field = document.forms[0].elements['editors[]'];
  233. for (i = 0; i < field.length; i++)
  234. field[i].checked = false ;
  235. }
  236. function delEditor(n) {
  237. if (confirm('ALERT: Removing an editor will completely remove all their permissions from every part of your site! If you wish to revoke privileges for this part only, uncheck all the associated boxes instead of removing them. Continue if you are sure you want to remove all privileges for this user.')) {
  238. f = document.addform;
  239. f.edaction.value = 'del';
  240. f.edname.value = n;
  241. document.forms["addform"].submit();
  242. }
  243. }
  244. function doFieldChange(user,scope,site,section,page,story,field,what) {
  245. f = document.addform;
  246. f.fieldchange.value = 1;
  247. f.puser.value = user;
  248. f.pscope.value = scope;
  249. f.psite.value = site;
  250. f.psection.value = section;
  251. f.ppage.value = page;
  252. f.pstory.value = story;
  253. f.pfield.value = field;
  254. f.pwhat.value = what;
  255. f.submit();
  256. }
  257. // ]]>
  258. </script>
  259. <?
  260. if ($isOwner && $className = $_SESSION[obj]->name) {
  261. print "\n<script type='text/javascript'>";
  262. print "\n// <![CDATA[";
  263. print "\n\nfunction addClassEditor() {";
  264. print "\n f = document.addform;";
  265. print "\n f.edaction.value='add';";
  266. print "\n f.edname.value='".$className."';";
  267. print "\n f.submit();";
  268. print "\n}";
  269. print "\n\n// ]]>";
  270. print "\n</script>";
  271. }
  272. ?>
  273. </head>
  274. <body>
  275. <?
  276. /******************************************************************************
  277. * output any errors
  278. ******************************************************************************/
  279. printerr();
  280. print $content;
  281. /******************************************************************************
  282. * include the appropriate page:
  283. ******************************************************************************/
  284. if ($step == 2) require("edit_permissions_form2.inc.php");
  285. else require("edit_permissions_form1.inc.php");
  286. // debug output -- handy :)
  287. /* print "<pre>"; */
  288. /* print "session:\n"; */
  289. /* print_r($_SESSION); */
  290. /* print "\n\n"; */
  291. /* print "request:\n"; */
  292. /* print_r($_REQUEST); */
  293. /* if (is_object($thisSection)) { */
  294. /* print "\n\n"; */
  295. /* print "thisSection:\n"; */
  296. /* print_r($thisSection); */
  297. /* } else if (is_object($thisSite)) { */
  298. /* print "\n\n"; */
  299. /* print "thisSite:\n"; */
  300. /* print_r($thisSite); */
  301. /* } */
  302. /* print "</pre>"; */
  303. ?>
  304. </body>
  305. </html>