Location: PHPKode > projects > ACollab > library/add_file.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: add_file.php 396 2005-02-11 14:18:53Z shozubq $

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

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

$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('library');
$_SECTION[1][1] = 'library/';
$_SECTION[2][0] = _AC('add_file');
$_SECTION[2][1] = 'library/add_file.php';

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

if (isset($_POST['submit'])) {
	if (!$_POST['file']) {
		$error = E_LIBRARY_MISSING_FILE;
	}

	if (!isset($error)) {
		list($rev_id, $file_id) = explode('_', $_POST['file'], 2);

		$sql = "UPDATE ".TABLE_PREFIX."files SET library_revision_id=$rev_id WHERE file_id=$file_id";
		$result = mysql_query($sql, $db);
		
		if ($result) {
			/*notify subscribers about addition of new library file*/
			$my_group = get_group($_SESSION['group_id']); 

			require(AC_INCLUDE_PATH . 'classes/acollabmailer.class.php');
			$mail = new ACollabMailer;

			$mail->From     = ADMIN_EMAIL;
			$mail->FromName = _AC('group_admin');
			$mail->Subject  = _AC('library_notification');
			$mail->Body     = _AC('library_new_file', $my_group['title'], $_base_href.'sign_in.php');

			$user_list = notify_subscribers('N_LIBRARY');
			if (!empty($user_list)) {
				while ($user = mysql_fetch_assoc($user_list)) {
					$bcc = true;
					$mail->AddBCC($user['email']);
				}
			}

			if ($bcc) {
				if(!$mail->Send()) {
				   echo "Message could not be sent. <p>";
				   echo "Mailer Error: " . $mail->ErrorInfo;
				   exit;
				}
			}
		}
		
		header('Location: index.php?f='.F_LIBRARY_ADDED);
		exit;
	}
}

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

if (isset($error)) {
	print_errors($error);
	unset($error);
}

?>
<br />
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form" id="form">
	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="4" class="box"><h3><?php echo _AC('add_file'); ?></h3></th>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" valign="top"><b><?php echo _AC('select_file_and_revision'); ?>:</b></td>
		<td class="row1">
<?php
	$sql = "SELECT * FROM ".TABLE_PREFIX."files WHERE group_id=$_SESSION[group_id] AND folder_id > 0";
	$result = mysql_query($sql, $db);
	if ($row = mysql_fetch_assoc($result)) {
		
		echo '<select name="file" size="10">';
		do {
			echo '<optgroup label="'.$row['title'].'">';
			$sql = "SELECT * FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$row[file_id] ORDER BY initial_date DESC";
			$revision_result = mysql_query($sql, $db);
			if ($revision_row = mysql_fetch_assoc($revision_result)) {
				do {
					echo '<option value="'.$revision_row['revision_id'].'_'.$row['file_id'].'"';
					echo '>'._AC('revision').' #'.(--$row['num_revisions']). ' - '.$revision_row['file_name'] .' - '. _AC('by').' '.get_login($revision_row['member_id']).'</option>';
				} while ($revision_row = mysql_fetch_assoc($revision_result));
			} else {
				echo '<option value="">['._AC('no_revisions_found').']</option>';
			}
			echo '</optgroup>';
		} while ($row = mysql_fetch_assoc($result));
		echo '</select>';
	} else {
		echo _AC('no_files_found');
		$disabled = 'disabled="disabled"';
	}
?>
		</td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" colspan="2"><br /><input type="submit" name="submit" value="<?php echo _AC('add'); ?>" class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" <?php echo $disabled; ?> /> &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>
<br />
<?php
	require(AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab