<?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: finalize.php 297 2005-01-17 19:15:02Z joel $
exit('this file no longer gets used');
define('AC_INCLUDE_PATH', '../include/');
require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_CLIENT, USER_GROUP_ADMIN);
if (isset($_POST['cancel'])) {
header('Location: index.php');
exit;
}
$id = intval($_REQUEST['id']);
if (isset($_POST['submit'])) {
if ($_POST['action'] == 'm') {
$sql = "SELECT file_id, file_size FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND file_name<>'' ORDER BY file_id DESC LIMIT 1";
$result = mysql_query($sql, $db);
if ($row = mysql_fetch_assoc($result)) {
/* move this file it is a revision */
/* we're moving the revision and deleting the parent and the older revisions */
$current_file_id = $row['file_id'];
/* delete the current child so that the ID is free to use for the parent */
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$current_file_id AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
/* delete the old parent file */
$char = substr($id, 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$id);
/* switch the parent with the child (by ID only). */
$sql = "UPDATE ".TABLE_PREFIX."files_revisions SET file_id=$current_file_id, parent_file_id=0, file_size=$row[file_size], language='$_POST[language]', section_type=".FILE_LIBRARY.", num_revisions=0 WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
/* reassign the categories to this new ID */
$sql = "UPDATE ".TABLE_PREFIX."categories_files SET file_id=$current_file_id WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* reassign the events to this new ID */
$sql = "UPDATE ".TABLE_PREFIX."events_files SET file_id=$current_file_id WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* delete all the old revisions/comments */
$sql = "SELECT file_id FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$row[file_id] AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
$char = substr($row['file_id'], 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$row['file_id']);
}
} else {
/* move this file. it is the parent */
/* we're moving the parent and just deleting the revisions, if any */
$sql = "UPDATE ".TABLE_PREFIX."files_revisions SET section_type=".FILE_LIBRARY.", language='$_POST[language]' WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
$sql = "SELECT file_id FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$row[file_id] AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
$char = substr($row['file_id'], 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$row['file_id']);
}
}
} else {
/* we're attaching a file to an existing library version */
$new_parent = intval($_POST['file_id']);
$sql = "SELECT file_id, file_size FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND file_name<>'' ORDER BY file_id DESC LIMIT 1";
$result = mysql_query($sql, $db);
if ($row = mysql_fetch_assoc($result)) {
/* attach this file it is a revision */
/* we're moving the revision and deleting the parent and the older revisions */
$current_file_id = $row['file_id'];
/* delete the current child so that the ID is free to use for the parent */
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$current_file_id AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
/* delete the old parent file */
$char = substr($id, 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$id);
/* switch the parent with the child (by ID only) and attach it to the new parent. */
$sql = "UPDATE ".TABLE_PREFIX."files_revisions SET file_id=$current_file_id, parent_file_id=$new_parent, file_size=$row[file_size], section_type=".FILE_LIBRARY.", num_revisions=0 WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
$sql = "DELETE FROM ".TABLE_PREFIX."categories_files WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* reassign the events to this new ID */
$sql = "UPDATE ".TABLE_PREFIX."events_files SET file_id=$new_parent WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* delete all the old revisions/comments */
$sql = "SELECT file_id FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$row[file_id] AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
$char = substr($row['file_id'], 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$row['file_id']);
}
} else {
/* attach this file (it is the parent) */
$sql = "UPDATE ".TABLE_PREFIX."files_revisions SET parent_file_id=$new_parent, language='$_POST[language]', section_type=".FILE_LIBRARY.", num_revisions=0 WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
$sql = "DELETE FROM ".TABLE_PREFIX."categories_files WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* reassign the events to this new ID */
$sql = "UPDATE ".TABLE_PREFIX."events_files SET file_id=$new_parent WHERE file_id=$id";
$result = mysql_query($sql, $db);
/* delete all the old revisions/comments */
$sql = "SELECT file_id FROM ".TABLE_PREFIX."files_revisions WHERE parent_file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$sql = "DELETE FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$row[file_id] AND group_id=$_SESSION[group_id]";
mysql_query($sql, $db);
$char = substr($row['file_id'], 0, 1).'/';
@unlink(UPLOAD_DIR.$char.$row['file_id']);
}
}
}
header('location: index.php?f='.F_DRAFT_FINALIZED);
exit;
}
$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('drafting_room');
$_SECTION[1][1] = 'drafting/';
$_SECTION[2][0] = _AC('finalize');
$_SECTION[2][1] = 'drafting/';
require(AC_INCLUDE_PATH.'header.inc.php');
$sql = "SELECT * FROM ".TABLE_PREFIX."files_revisions WHERE file_id=$id AND group_id=$_SESSION[group_id]";
$result = mysql_query($sql,$db);
if (!($row = mysql_fetch_assoc($result))) {
$errors[] = E_FILE_NOT_FOUND;
print_errors($errors);
require (AC_INCLUDE_PATH.'footer.inc.php');
exit;
} else if (($row['member_id'] != $_SESSION['member_id']) && !authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)){
/* actually permission is denied, but for security we fake a "FNF" */
$errors[] = E_FILE_NOT_FOUND;
print_errors($errors);
require (AC_INCLUDE_PATH.'footer.inc.php');
exit;
}
$sql = "SELECT file_id, parent_file_id, title, file_name, language FROM ".TABLE_PREFIX."files_revisions WHERE section_type=".FILE_LIBRARY." AND group_id=$_SESSION[group_id] AND language<>'bi' ORDER BY parent_file_id ASC, title, file_name";
$result = mysql_query($sql, $db);
$files = array();
while ($row2 = mysql_fetch_assoc($result)) {
if ($row2['parent_file_id'] == 0) {
if ($row2['language'] != $row['language']) {
$files[$row2['file_id']] = $row2['title'].' ('.$row2['file_name'].')';
}
} else {
unset($files[$row2['parent_file_id']]);
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form" id="form">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="hidden" name="language" value="<?php echo $row['language']; ?>">
<p>
<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2" width="75%">
<tr>
<th colspan="5" class="box"><h3><?php echo _AC('finalize'); ?></h3></th>
</tr>
<tr>
<td class="row1"> </td>
<td colspan="3" class="row1"><img src="images/clr.gif" height="1" width="1" alt="" /><br /><?php echo _AC('finalize_blurb'); ?><br /></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" align="right" valign="top"><label for="comments"><b><?php echo _AC('finalize'); ?>:</b></label></td>
<td class="row1" valign="top"> </td>
<td class="row1"><input type="radio" name="action" value="m" id="m" checked="checked" /><label for="m"><?php
echo _AC('finalize_move', $row['file_name']);
?></label><br />
<?php if (($row['language'] != 'bi') && (count($files))) { ?>
or<br />
<input type="radio" name="action" value="a" id="a" /><label for="a"><?php
echo _AC('finalize_attach', _AC($row['language']));
?></label> <select name="file_id">
<?php
foreach ($files as $f_id => $f_info) {
echo '<option value="'.$f_id.'">'.$f_info.'</option>';
}
?>
</select>
<?php } else {
echo _AC('no_attach_files');
}
?></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" colspan="3" align="right"><br /><input type="submit" name="submit" value=" <?php echo _AC('finalize'); ?> " class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> <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"> </td>
</tr>
</table>
</p>
</form>
<?php
require(AC_INCLUDE_PATH.'footer.inc.php');
?>