Location: PHPKode > projects > ACollab > drafting/add_revision.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2005  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_revision.php 420 2005-03-04 19:41:41Z shozubq $

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

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

$id = intval($_REQUEST['id']);

if (isset($_POST['cancel'])) {
	header('Location: revisions.php?id='.$id);
	exit;
}

$sql = "SELECT * FROM ".TABLE_PREFIX."files WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql,$db);


if (!($row = mysql_fetch_assoc($result))) {
		$_SECTION[0][0] = _AC('home');
		$_SECTION[0][1] = 'home.php';
		$_SECTION[1][0] = _AC('drafting_room');
		$_SECTION[1][1] = 'drafting/';
		$_SECTION[2][0] = _AC('revisions');

		require(AC_INCLUDE_PATH.'header.inc.php');
		$errors[] = E_FILE_NOT_FOUND;
		print_errors($errors);
		require (AC_INCLUDE_PATH.'footer.inc.php');
		exit;
}
$title = $row['title'];

$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('drafting_room');
$_SECTION[1][1] = 'drafting/';
$_SECTION[2][0] = _AC('revisions'). ': ' . $title;
$_SECTION[2][1] = 'drafting/revisions.php?id='.$id;
$_SECTION[3][0] = _AC('add_revision');
$_SECTION[3][1] = 'drafting/add_revision.php';

if (isset($_POST['submit'])) {
	$_POST['description']   = trim($_POST['description']);

	if($_FILES['file']['name'] == '') {
		$error[] = E_DRAFT_EMPTY_FILE;
	} else if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
		$error[] = E_DRAFT_UPLOAD;
	}

	if ($_POST['description'] == '') {
		$error[] = E_DRAFT_EMPTY_COMM;
	}

	if (!isset($error)) {
		$_POST['description'] = $addslashes($_POST['description']);

		$sql = "INSERT INTO ".TABLE_PREFIX."files_revisions VALUES (0, $id, $_SESSION[member_id], NOW(), '{$_FILES[file][name]}', '{$_FILES[file][size]}', '$_POST[description]', 0)";

		if (mysql_query($sql, $db)) {
			$file_id = mysql_insert_id($db);
			$sql	= "UPDATE ".TABLE_PREFIX."files SET num_revisions=num_revisions+1 WHERE file_id=$id AND group_id=$_SESSION[group_id]";
			$result	= mysql_query($sql, $db);

			$char = substr($file_id, 0, 1).'/';
			move_uploaded_file($_FILES['file']['tmp_name'], UPLOAD_DIR.$char.$file_id);

			@chmod(UPLOAD_DIR.$char.$file_id, 01600);

			if ($row['folder_id'] > 0) {
				$my_group = get_group($_SESSION['group_id']); 

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

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

				$user_list = notify_subscribers('N_DRAFT');
				
				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;
					}
				}
			}

			if ($_POST['notify']) {
				/* send a notification to the group admin */

				require(AC_INCLUDE_PATH.'classes/class.phpmailer.php');
				$my_group = get_group($_SESSION['group_id']); 

				$sql = "SELECT M.email FROM ".MEMBERS_TABLE_PREFIX."members M WHERE M.member_id=$_SESSION[member_id]";
				$result = mysql_query($sql, $db);
				$row = mysql_fetch_assoc($result);

				$mail = new PHPMailer();
				if (MAIL_USE_SMTP) {
					$mail->IsSMTP(); // set mailer to use SMTP
					$mail->Host = ini_get('SMTP');  // specify main and backup server
				} else {
					$mail->IsSendmail(); // use sendmail
					$mail->Sendmail = ini_get('sendmail_path');
				}
				$mail->SMTPAuth = false;     // turn on SMTP authentication
				$mail->From = $row['email'];
				$mail->FromName = $_SESSION['login'];
				$mail->IsHTML(false);
				$mail->Subject = _AC('notification');
				$mail->Body    = _AC('notification_body', $_SESSION['login'], $my_group['title'], $_base_href.'sign_in.php', $title);
				$mail->WordWrap = 50;

				/* get all the group admins */
				$sql = "SELECT M.email FROM ".TABLE_PREFIX."groups_members G INNER JOIN ".MEMBERS_TABLE_PREFIX."members M USING (member_id) WHERE G.group_id=$_SESSION[group_id] AND G.privileges=".USER_GROUP_ADMIN." AND M.email<>''";
				$result = mysql_query($sql, $db);
				if ($row = mysql_fetch_assoc($result)) {
					do {
						$mail->AddAddress($row['email']);
					} while ($row = mysql_fetch_assoc($result));

					if(!$mail->Send()) {
					   echo "Message could not be sent. <p>";
					   echo "Mailer Error: " . $mail->ErrorInfo;
					   exit;
					}
				}

			}

			header('Location: revisions.php?id='.$id.SEP.'f='.F_DRAFT_UPLOADED);
			exit;
		}
		$error[] = E_DRAFT_UPLOAD;
	}
}

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

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

?>
<br />
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" name="form" id="form">
	<input type="hidden" name="id" value="<?php echo $id; ?>" />

	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="5" class="box"><h3><?php echo _AC('add_revision'); ?></h3></th>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td colspan="3" class="row1"><img src="images/clr.gif" height="1" width="1" alt="" /><br /><?php
			echo _AC('denotes_required', '<img src="images/required.gif" height="14" width="14" alt="'._AC('required_field').'" />');
		?><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right"><label for="file"><b><?php echo _AC('file'); ?>:</b></label></td>
		<td class="row1"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" /></td>
		<td class="row1"><input type="file" name="file" id="file" class="input" size="30" onfocus="this.className='input highlight'" onblur="this.className='input'" /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" valign="top"><label for="description"><b><?php echo _AC('description'); ?>:</b></label></td>
		<td class="row1" valign="top"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" class="img" /></td>
		<td class="row1"><textarea name="description" id="description" class="input" onfocus="this.className='input highlight'" onblur="this.className='input'" cols="40" rows="3"><?php echo $_POST['description']; ?></textarea></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<?php if (ALLOW_NOTIFY_GROUP_ADMIN && !authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)): ?>
		<tr>
			<td class="row1">&nbsp;</td>
			<td class="row1" align="right"><label for="file"><b><?php echo _AC('notification'); ?>:</b></label></td>
			<td class="row1">&nbsp;</td>
			<td class="row1"><input type="checkbox" name="notify" value="1" id="notify" /><label for="notify"><?php echo _AC('notify_group_admin'); ?></label></td>
			<td class="row1">&nbsp;</td>
		</tr>
	<?php endif; ?>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" colspan="3" align="right"><br /><input type="submit" name="submit" value="<?php echo _AC('add_file'); ?>" 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>
<br />
<?php
	require(AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab