segue-1.x /edit_permissions.php

Language PHP Lines 366
MD5 Hash a777d62217d4557c5c46f3e4d73023ef Estimated Cost $3,249 (why?)
Repository https://github.com/adamfranco/segue-1.x.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<? /* $Id$ */

/******************************************************************************
 * edit_permissions takes in one variable: $site
 *
 * The first screen is for the adding, delete, and choosing of editors
 * The second screen is for the editing of the permissions for selected editors
 ******************************************************************************/

require("objects/objects.inc.php");

ob_start();
session_start();
//printpre($classname);
// include all necessary files
require("includes.inc.php");

if ($_REQUEST[cancel]) {
	unset($_SESSION[obj],$_SESSION[editors]);
	header("Location: close.php");
	exit;
}

db_connect($dbhost, $dbuser, $dbpass, $dbdb);

if ($_REQUEST[site] && isset($_SESSION[obj])) {
	if ($_REQUEST[site] != $_SESSION[obj]->name)
		unset($_SESSION[obj],$_SESSION[editors]);
}

/******************************************************************************
 * create the site object if it doesn't exist.
 ******************************************************************************/

if (!is_object($_SESSION[obj])) {
	$_SESSION[obj] =& new site($_REQUEST[site]);
	$_SESSION[obj]->fetchSiteAtOnceForeverAndEverAndDontForgetThePermissionsAsWell_Amen(0,1);
	$_SESSION[obj]->spiderDownLockedFlag();
}

$site_owner = $_SESSION[obj]->owner;

$isOwner = $isEditor = 1;

if ($site_owner != $_SESSION[auser]) {
/* 	error("You are not allowed to edit permissions for this site!"); */
	$isOwner = 0;
}

if (!$isOwner && !$_SESSION[obj]->isEditor()) {
	error("You are not an editor for this site. You may not view any permissions.");
	$isEditor=0;
}

/* $_SESSION[obj]->buildPermissionsArray(0,1); */
if (!isset($_SESSION[editors])) $_SESSION[editors] = array();

//print "here";exit;

if ($error) { printerr2(); return; }

//printpre($_SESSION[editors]);
//printpre($_REQUEST);

/******************************************************************************
 * Save changes to the DB
 ******************************************************************************/

if ($_REQUEST[savechanges]) {
	if ($isOwner) {
		/* print "<pre>"; print_r($_SESSION[obj]); print "</pre>"; */
		/* begin bug-fix X-294273alpha. thank you, Adam. */
		// go through each editor and make sure that they are in the local DB.
		print_r($_SESSION[obj]->getEditors());
		foreach ($_SESSION[obj]->getEditors() as $_editor) {
			if(!$_editor) continue;
			print "synchronizing $_editor...<br />";
			synchronizeLocalUserAndClassDB($_editor);
		}
		/* end bug-fix. Again, thank you, Adam. */
		$_SESSION[obj]->updateDB(1);
//		print_r($_SESSION[obj]->editorsToDelete);
		$_SESSION[obj]->deletePendingEditors();
//		echo "<pre>";
//		print_r($_SESSION[obj]);
		unset($_SESSION[obj],$_SESSION[editors]);
		Header("Location: close.php");
		exit;
	}
}

/******************************************************************************
 * Editor Actions:
 ******************************************************************************/
if ($isOwner && $_REQUEST[edaction] == 'add') {
	if (isgroup($_REQUEST[edname])) {
		$classes = group::getClassesFromName($_REQUEST[edname]);
		foreach ($classes as $class) {
			$_SESSION[obj]->addEditor($class);
		}
	} else {
		$_SESSION[obj]->addEditor($_REQUEST[edname]);
	}
}

if ($isOwner && $_REQUEST[edaction] == 'del') {
	$_SESSION[obj]->delEditor($_REQUEST[edname]);
}

/******************************************************************************
 * switch between forms 1 and 2
 ******************************************************************************/
$step = $_REQUEST['step'];
if (!$isOwner && $isEditor) {
	if (!count($_SESSION[editors])) {
		if (in_array($_SESSION[auser],$_SESSION[obj]->getEditors())) 
			$_SESSION[editors][] = $_SESSION[auser];
		
		$groupsAndClasses = array_unique(
								array_merge(
									$_SESSION[obj]->returnEditorOverlap(
										getuserclasses($_SESSION[auser],"all")), 
									getusergroups($_SESSION[auser])));
		foreach ($groupsAndClasses as $groupOrClass) {
			if (in_array($groupOrClass, $_SESSION[obj]->getEditors()))
				$_SESSION[editors][] = $groupOrClass;
		}
		
		// done... now send them to step 2
		$step = 2;
	}
}
 
if($isOwner && $_REQUEST[editpermissions]) {
	if (!count($_REQUEST[editors])) {
		error("You must choose some editors.");
	} else {
		$_SESSION[editors] = $_REQUEST[editors];
		$step = 2;
	}
}

if ($isOwner && $_REQUEST[chooseeditors]) {
	$step = 1;
}

if (!$isOwner)
	$step = 2;

/******************************************************************************
 * catch any change field functionality
 ******************************************************************************/
$fieldchange = $_REQUEST[fieldchange];
$pscope = $_REQUEST[pscope];
$psite = $_REQUEST[psite];
$psection = $_REQUEST[psection];
$ppage = $_REQUEST[ppage];
$pstory = $_REQUEST[pstory];
$pfield = $_REQUEST[pfield];
$pwhat = $_REQUEST[pwhat];
$puser = $_REQUEST[puser];

//print "$pscope - $psite - $psection - $ppage - $pstory - $pfield - $pwhat - $puser";
if ($isOwner) {
	if ($fieldchange) {	 // we're supposed to change a field
		$_a = array("story"=>0,"page"=>1,"section"=>2,"site"=>3);
		if ($pscope == 'site') $theObj = &$_SESSION[obj];
		if ($pscope == 'section') $theObj = &$_SESSION[obj]->sections[$psection];
		if ($pscope == 'page') $theObj = &$_SESSION[obj]->sections[$psection]->pages[$ppage];
		if ($pscope == 'story') $theObj = &$_SESSION[obj]->sections[$psection]->pages[$ppage]->stories[$pstory];
		if ($pfield == 'locked') {
			$theObj->setField('locked',$pwhat);
		}
		if (ereg("perms-([a-z]){1,}",$pfield)) {
			$regs = split('-',$pfield);
			$perm = $regs[1];
			$theObj->setUserPermissionDown($perm,$puser,$pwhat);
			$theObj->setFieldDown("l%$puser%$perm",$pwhat);
//			echo "l-$puser-$perm: ".$pwhat;
			if ($pwhat ==1) $theObj->setField("l%$puser%$perm",(1-$pwhat));
		}
	}
}

/******************************************************************************
 * common styles/javascripts:
 ******************************************************************************/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? print ($isOwner)?"Edit Permissions - ":"Your Permissions - "; print $_SESSION[obj]->getField("title"); ?></title>

<style type='text/css'>
a {
	color: #a33;
	text-decoration: none;
}

a:hover {text-decoration: underline;}

table {
	border: 1px solid #555;
}

th, td {
	border: 0px;
	background-color: #ddd;
}

.viewcol {
	background-color: #cec;
	border-left: 2px solid #FFF;
}

.lockedcol {
	background-color: #ecc;
}

.collabel {
	text-align: center;
	background-color: #bbb;
}

.edname {
	border-left: 2px solid #FFF;
}

.td1 { 
	background-color: #ccc; 
}

.td0 { 
	background-color: #ddd; 
}

th { 
	background-color: #bbb; 
	font-variant: small-caps;
}

body { 
	background-color: white; 
}

body, table, td, th, input {
	font-size: 12px;
	font-family: "Verdana", "sans-serif";
}

input {
	border: 1px solid black;
	background-color: white;
	font-size: 10px;
}

</style>

<script type='text/javascript'>
// <![CDATA[

function doWindow(name,width,height) {
	var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
	win.focus();
}

function sendWindow(name,width,height,url) {
	var win = window.open("",name,"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height);
	win.document.location=url.replace(/&amp;/, '&');
	win.focus();
}

function checkAll() {
	field = document.forms[0].elements['editors[]'];
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll() {
	field = document.forms[0].elements['editors[]'];
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function delEditor(n) {
	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.')) {		
		f = document.addform;
		f.edaction.value = 'del';
		f.edname.value = n;
		document.forms["addform"].submit();
	}
}

function doFieldChange(user,scope,site,section,page,story,field,what) {
	f = document.addform;
	f.fieldchange.value = 1;
	f.puser.value = user;
	f.pscope.value = scope;
	f.psite.value = site;
	f.psection.value = section;
	f.ppage.value = page;
	f.pstory.value = story;
	f.pfield.value = field;
	f.pwhat.value = what;
	f.submit();
}

// ]]>
</script>

<?
if ($isOwner && $className = $_SESSION[obj]->name) {
	print "\n<script type='text/javascript'>";
	print "\n// <![CDATA[";
	print "\n\nfunction addClassEditor() {";
	print "\n	f = document.addform;";
	print "\n	f.edaction.value='add';";
	print "\n	f.edname.value='".$className."';";
	print "\n	f.submit();";
	print "\n}";
	print "\n\n// ]]>";
	print "\n</script>";
}
?>

</head>
<body>

<? 

/******************************************************************************
 * output any errors
 ******************************************************************************/

printerr();
print $content;

/******************************************************************************
 * include the appropriate page:
 ******************************************************************************/
if ($step == 2) require("edit_permissions_form2.inc.php");
else require("edit_permissions_form1.inc.php");


// debug output -- handy :)
/* print "<pre>"; */
/* print "session:\n"; */
/* print_r($_SESSION); */
/* print "\n\n"; */
/* print "request:\n"; */
/* print_r($_REQUEST); */
/* if (is_object($thisSection)) { */
/* 	print "\n\n"; */
/* 	print "thisSection:\n"; */
/* 	print_r($thisSection); */
/* } else if (is_object($thisSite)) { */
/* 	print "\n\n"; */
/* 	print "thisSite:\n"; */
/* 	print_r($thisSite); */
/* } */
/* print "</pre>"; */

?>
</body>
</html>
Back to Top