Location: PHPKode > projects > ACollab > prefs/notifications.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2004  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may redistribute it and/or                        */
/* modify it under the terms of the GNU General Public License                          */
/* as published by the Free Software Foundation; either version 2 of the License,       */
/* or (at your option) any later version.                                               */
/*                                                                                      */
/* This program is distributed in the hope that it will be useful, but                  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of                           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
/* See the GNU General Public License for more details.                                 */
/*                                                                                      */
/* You may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: password.php 282 2004-06-14 13:23:50Z heidi $

define('AC_INCLUDE_PATH', '../include/');

require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_CLIENT, USER_GROUP_ADMIN, USER_ADMIN);

$_SECTION[0][0] = $_SESSION['course_title'].' '._AC('groups');
$_SECTION[0][1] = 'index.php';
$_SECTION[1][0] = _AC('options');
$_SECTION[1][1] = 'prefs/';
$_SECTION[2][0] = _AC('notification_settings');
$_SECTION[2][1] = 'prefs/notifications.php';

if ($_POST['cancel']) {
	Header('Location: index.php');
	exit;
}

if ($_POST['submit']) {
	$nots			   = $_POST['nots'];
	$_POST['group_id'] = intval($_POST['group_id']);

	//calculate notifications
	$notifications = 0;
	if (!(empty($nots))) {
		foreach ($nots as $key => $priv) {
			$notifications += $priv;
		}	
	}

	$sql = "UPDATE ".TABLE_PREFIX."groups_members SET notifications=$notifications WHERE member_id=$_SESSION[member_id] AND group_id=$_POST[group_id]";
	if (mysql_query($sql, $db)) {
		Header('Location: index.php?f='.F_NOTS_EDITED);
		exit;
	} else {
		$error[] = E_NOTS_EDIT;
	}
}

if (isset($_POST['group_id']) && isset($_POST['toNots']) && $_POST['group_id'] != 0) {
	$_POST['group_id'] = intval($_POST['group_id']);
	//retrieve current notification settings
	$sql    = "SELECT notifications FROM ".TABLE_PREFIX."groups_members WHERE member_id=$_SESSION[member_id] AND group_id = $_POST[group_id]";
	$result = mysql_query($sql, $db);
	$row    = mysql_fetch_assoc($result);

	require(AC_INCLUDE_PATH.'pub/header.inc.php');

	?>
	<br /><br /><br />
	<table border="0" cellspacing="0" cellpadding="0" align="center" class="box" width="70%">
		<tr>
			<th colspan="4" class="box"><h3><?php echo _AC('notification_settings'); ?></h3></th>
		</tr>
		<tr>
			<td style="border-bottom: 1px solid #006699; background: #EFEFEF;">
				<table border="0" width="100%" cellspacing="0" cellpadding="0" class="w">
					<tr>
						<td class="bread" valign="middle"><h4><?php
						
							$delim = ' » ';
							$num_sections = count($_SECTION);
							for($i = 0; $i < $num_sections-1; $i++) {
								echo '<a href="'.$_SECTION[$i][1] . '" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">';
								echo $_SECTION[$i][0];
								echo '</a>';
								echo $delim;
							}

							echo $_SECTION[$num_sections-1][0];
							echo '<small><small> ( <a href="accessibility.php" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'. _AC('accessibility').'</a> ';	
							if (!$_SESSION['course_id']) {
								echo ' | <a href="sign_out.php" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('sign_out').'</a>';
							} 
							echo ' )</small></small>';

						?></h4></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td><table border="0" cellspacing="0" cellpadding="4" class="border" width="100%">
					<tr>
						<td><?php
								if (isset($error)) {
									print_errors($error);
								}
						?>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	<input type="hidden" name="group_id" value="<?php echo $_POST['group_id']; ?>" />
	<?php 
		$sql1 = "SELECT title FROM ".TABLE_PREFIX."groups WHERE group_id=$_POST[group_id]";
		$result1 = mysql_query($sql1, $db);
		$row1 = mysql_fetch_assoc($result1);
	?>
		<table width="55%" border="0" cellspacing="0" cellpadding="0" align="center" class="box2">
		<tr>
			<th colspan="5" class="box"><h3><?php echo $row1['title']; ?></h3></td>
		</tr>
	<?php 
		foreach ($_nots as $key => $not) {
			if (query_bit($key, $row['notifications']) == TRUE) { 
				$selected = 'checked="checked"';
			} else {
				$blank = 'checked="checked"';
			}
			echo '<tr bgcolor="white">';
			echo '<td class="row1" align="right"><b>'. _AC($not['name']) .':</b></td>';
			echo '<td class="row1">&nbsp;</td>';
			echo '<td class="row1"><label><input type="radio" name="nots['.$key.']" class="input" value="'.$key.'" onfocus="this.className=\'input highlight\'" onblur="this.className=\'input\'" '. $selected .' />' . _AC('enable') . '</label></td>';
			echo '<td class="row1">&nbsp;</td>';
			echo '<td class="row1"><label><input type="radio" name="nots['.$key.']" class="input" value="0" onfocus="this.className=\'input highlight\'" onblur="this.className=\'input\'" '. $blank .' />' . _AC('disable') . '</label></td>';
			echo '</tr>';
			$blank = '';
			$selected = '';
		}
	?>

		<tr bgcolor="white">
			<td class="row1">&nbsp;</td>
			<td class="row1" colspan="4" align="right"><br /><input type="submit" name="submit" value=" <?php echo _AC('submit'); ?> " class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> &nbsp; <input type="submit" name="cancel" value="<?php echo _AC('cancel'); ?>" class="submitN" onfocus="this.className='submitN highlight'" onblur="this.className='submitN'" />&nbsp;&nbsp;<br /><br /></td>
		</tr>
		</table>
	</form></td>
	</tr>
	</table>
<?php
	require(AC_INCLUDE_PATH.'footer.inc.php');
}

//obtain the group_id from the user to determine which group to modify the settings for
if (!isset($_POST['group_id']) || $_POST['group_id'] == 0) {
	require(AC_INCLUDE_PATH.'pub/header.inc.php');
	
	if (isset($_POST['group_id']) && $_POST['group_id'] == 0) {
		$error[] = E_GROUP_NOT_FOUND;
	}

?>
	<br /><br /><br />
	<table border="0" cellspacing="0" cellpadding="0" align="center" class="box" width="70%">
		<tr>
			<th colspan="4" class="box"><h3><?php echo _AC('notification_settings'); ?></h3></th>
		</tr>
		<tr>
			<td style="border-bottom: 1px solid #006699; background: #EFEFEF;">
				<table border="0" width="100%" cellspacing="0" cellpadding="0" class="w">
					<tr>
						<td class="bread" valign="middle"><h4><?php
						
							$delim = ' » ';
							$num_sections = count($_SECTION);
							for($i = 0; $i < $num_sections-1; $i++) {
								echo '<a href="'.$_SECTION[$i][1] . '" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">';
								echo $_SECTION[$i][0];
								echo '</a>';
								echo $delim;
							}

							echo $_SECTION[$num_sections-1][0];
							echo '<small><small> ( <a href="accessibility.php" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'. _AC('accessibility').'</a> ';	
							if (!$_SESSION['course_id']) {
								echo ' | <a href="sign_out.php" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('sign_out').'</a>';
							} 
							echo ' )</small></small>';

						?></h4></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td><table border="0" cellspacing="0" cellpadding="4" class="border" width="100%">
					<tr>
						<td><?php
		if (isset($error)) {
			print_errors($error);
		}
						?>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<table width="55%" border="0" cellspacing="0" cellpadding="0" align="center" class="box2">
		<tr>
			<td class="row1 tline">&nbsp;</td>
			<td colspan="4" class="row1 tline"><img src="images/clr.gif" height="1" width="1" alt="" /></td>
			<td class="row1 tline">&nbsp;</td>
		</tr>
		<tr bgcolor="white">
			<td class="row1" align="right"><strong><?php echo _AC('choose_group') ?>:</strong></td>
			<td class="row1">&nbsp;</td>
			<td class="row1" align="left">
			<select name="group_id">
				<option value="0">-- <?php echo _AC('groups'); ?> --</option>
				<?php
					$sql = "SELECT G.title, GM.group_id FROM ".TABLE_PREFIX."groups_members GM, ".TABLE_PREFIX."groups G WHERE GM.member_id=$_SESSION[member_id] AND G.group_id=GM.group_id  AND G.course_id=$_SESSION[course_id]";
					$result = mysql_query($sql, $db);
					while ($row = mysql_fetch_assoc($result)) {
						echo '<option value='.$row['group_id'].'>'.$row['title'].'</option>';
					}
				?>
			</select>
			</td>			
			<td class="row1" colspan="3">&nbsp;</td>
		</tr>
		<tr bgcolor="white">
			<td class="row1">&nbsp;</td>
			<td class="row1" colspan="4" align="right"><br /><input type="submit" name="toNots" value=" <?php echo _AC('submit'); ?> " class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> &nbsp; <input type="submit" name="cancel" value="<?php echo _AC('cancel'); ?>" class="submitN" onfocus="this.className='submitN highlight'" onblur="this.className='submitN'" /><br /><br /></td>
			<td class="row1">&nbsp;</td>
		</tr>
		</table>
	</form></td>
	</tr>
	</table>
<?php
	require(AC_INCLUDE_PATH.'footer.inc.php');
}
?>
Return current item: ACollab