Location: PHPKode > projects > ACollab > library/cat_files.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: cat_files.php 234 2004-06-07 19:43:50Z boonhau $

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

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

$cid = intval($_GET['cid']);
$cat_info = get_category($cid);
if (!$cat_info) {
	header('Location: index.php');
	exit;
}

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

require(AC_INCLUDE_PATH.'header.inc.php');
print_popup_help('help_library');
echo '<p align="center"><b><a href="library/add_file.php?cid='.$cid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('add_file').'</a></b></p>';

if (isset($_GET['f'])) {
	print_feedback($_GET['f']);
}

if ($_GET['col']) {
	$col = addslashes($_GET['col']);
} else {
	$col = 'title';
}

if ($_GET['order']) {
	$order = addslashes($_GET['order']);
} else {
	$order = 'asc';
}


${'highlight_'.$col} = ' u';

	echo '<table cellspacing="0" cellpadding="2" border="0" bgcolor="white" align="center" summary="">';
	echo '<tr>';
	echo '<th align="left"><small>Sort by:</small></th>';

	echo '<th class="box" align="left"><small><a href="'.$_SERVER['PHP_SELF'].'?col=title'.SEP.'order=asc'.SEP.'cid='.$cid.'" class="nav'.$highlight_title.'" title="'._AC('title_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_title.'\'">'._AC('title').'</a> ';
		if (($col == 'title') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=title'.SEP.'order=desc'.SEP.'cid='.$cid.'"><img src="images/desc.gif" height="7" width="11" alt="'._AC('title_desc').'" border="0" class="img4" /></a>';
		} else if (($col == 'title') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=title'.SEP.'order=asc'.SEP.'cid='.$cid.'"><img src="images/asc.gif" height="7" width="11" alt="'._AC('title_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	echo '<th class="box" align="left"><small><a href="'.$_SERVER['PHP_SELF'].'?col=file_name'.SEP.'order=asc'.SEP.'cid='.$cid.'" class="nav'.$highlight_file_name.'" title="'._AC('file_name_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_file_name.'\'">'._AC('file_name').'</a> ';
		if (($col == 'file_name') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=file_name'.SEP.'order=desc'.SEP.'cid='.$cid.'"><img src="images/desc.gif" height="7" width="11" alt="'._AC('file_name_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'file_name') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=file_name'.SEP.'order=asc'.SEP.'cid='.$cid.'"><img src="images/asc.gif" height="7" width="11" alt="'._AC('file_name_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	echo '<th class="box" align="left"><small><a href="'.$_SERVER['PHP_SELF'].'?col=initial_date'.SEP.'order=asc'.SEP.'cid='.$cid.'" class="nav'.$highlight_initial_date.'" title="'._AC('date_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_initial_date.'\'">'._AC('date').'</a> ';
		if (($col == 'initial_date') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=initial_date'.SEP.'order=desc'.SEP.'cid='.$cid.'"><img src="images/desc.gif" height="7" width="11" alt="'._AC('date_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'initial_date') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=initial_date'.SEP.'order=asc'.SEP.'cid='.$cid.'"><img src="images/asc.gif" height="7" width="11" alt="'._AC('date_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';
	
	echo '<th class="box" align="left"><small><a href="'.$_SERVER['PHP_SELF'].'?col=file_size'.SEP.'order=asc'.SEP.'cid='.$cid.'" class="nav'.$highlight_file_size.'" title="'._AC('size_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_file_size.'\'">'._AC('size').'</a> ';
		if (($col == 'file_size') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=file_size'.SEP.'order=desc'.SEP.'cid='.$cid.'"><img src="images/desc.gif" height="7" width="11" alt="'._AC('size_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'file_size') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?col=file_size'.SEP.'order=asc'.SEP.'cid='.$cid.'"><img src="images/asc.gif" height="7" width="11" alt="'._AC('size_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';
	echo '</tr>';
	echo '</table><br />';

$sql	= "SELECT F.* FROM ".TABLE_PREFIX."files_revisions F, ".TABLE_PREFIX."categories_files C WHERE (F.parent_file_id=0 AND F.file_id=C.file_id) AND F.section_type=".FILE_LIBRARY." AND F.group_id=$_SESSION[group_id] AND C.category_id=$cid ORDER BY F.$col $order";

$result = mysql_query($sql, $db);

$files = array();

if ($row = mysql_fetch_assoc($result)) {
	do {
		$files[$row['file_id']][$row['language']] = $row;

		/* get all the other language files */
		if ($row['language'] != 'bi') {
			$sql	= "SELECT * FROM ".TABLE_PREFIX."files WHERE parent_file_id=$row[file_id] LIMIT 1";
			$result2= mysql_query($sql, $db);
			if ($row2 = mysql_fetch_assoc($result2)) {
				$files[$row2['parent_file_id']][$row2['language']] = $row2;
			}
		}
	} while ($row = mysql_fetch_assoc($result));
} else {
	echo '<p>'._AC('no_files_found').'</p>';
	require(AC_INCLUDE_PATH.'footer.inc.php');
	exit;
}

reset($files);

echo '<table cellspacing="0" cellpadding="2" border="0" bgcolor="white" width="75%" align="center" summary="" class="box">';
echo '<tr>';
echo '<th class="box"><h3>'.$cat_info['title'].' ';

echo ' </h3></th>';
echo '</tr>';
echo '</table><img src="images/clr.gif" height="5" width="5" alt="" />';

foreach ($files as $file_id => $file_info_all) {
	$col = 1;

	if (isset($file_info_all['bi'])) {
		$current_cat  = $file_info_all['bi']['category_id'];
	} else {
		if (isset($file_info_all['en'])) {
			if ($file_info_all['en']['file_id'] == $file_id) {
				$current_cat  = $file_info_all['en']['category_id'];
			}
		} else if (isset($file_info_all['fr'])) {
			if ($file_info_all['fr']['file_id'] == $file_id) {
				$current_cat  = $file_info_all['fr']['category_id'];
			}
		}
	}


	echo '<a name="f'.$file_id.'"></a><table cellspacing="0" cellpadding="2" border="0" bgcolor="white" width="75%" align="center" summary="" class="box">';

	echo '<tr>';
	echo '<td class="row'.$col.'" align="left" valign="middle" colspan="2"><small><b>'._AC('title').': ';

	$notice = '';
	if (isset($file_info_all['bi'])) {
		$info = $file_info_all['bi'];
	} else if (isset($file_info_all['en'], $file_info_all['fr'])){
		if ($_SESSION['lang'] == 'en') {
			$info = $file_info_all['en'];
			// everything's fine, show english info with french file link
		} else {
			$info = $file_info_all['fr'];
			// everything's fine, show french info with english file link
		}
	} else if (isset($file_info_all['en'])){
		$info = $file_info_all['en'];
		if ($_SESSION['lang'] == 'en') {
			// everything's fine, show english info only (no french available)
		} else {
			// bad, show english info only with "no french available warning"
			$notice = ', '._AC('no_french_version');
		}
	} else if (isset($file_info_all['fr'])){
		$info = $file_info_all['fr'];
		if ($_SESSION['lang'] == 'en') {
			// bad, show french info only with "no english available warning"
			$notice = ', '._AC('no_english_version');
		} /* else {
			// everything's fine, show french info only (no english available)
		} */
	}

	$ext = substr($info['file_name'], strrpos($info['file_name'], '.')+1);

	echo '<a href="get_file.php?id='.$info['file_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'"><img src="images/download.gif" height="24" width="20" alt="'._AC('download').': '.$info['title'].'" border="0" class="img5" /><img src="images/clr.gif" height="2" width="2" alt="" border="0" />';
	echo $info['title'].'</a> ('._AC($info['language']).$notice.')';
	echo '</b></small>';

	echo '</td>';
	echo '<td class="row'.$col.'" colspan="2" align="center" width="30%">';
	echo '<small><small>';
	if (($info['member_id'] == $_SESSION['member_id']) || authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {

		if ($info['language'] == 'bi') {
			echo '[ <a href="library/edit_file.php?id='.$file_id.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('edit').'</a> | <a href="library/delete_file.php?id='.$file_id.SEP.'cid='.$cid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('delete').'</a> ]';
		} else {
			if (isset($file_info_all['en'])) {
				echo '[ '._AC('en').': <a href="library/edit_file.php?id='.$file_info_all['en']['file_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('edit').'</a> | <a href="library/delete_file.php?id='.$file_info_all['en']['file_id'].SEP.'cid='.$cid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('delete').'</a> ]<br />';
			} else {
				echo '[ <a href="library/add_file.php?l=en'.SEP.'pid='.$file_id.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('add_english_version').'</a> ]<br />';
			}
			if (isset($file_info_all['fr'])) {
				echo '[ '._AC('fr').': <a href="library/edit_file.php?id='.$file_info_all['fr']['file_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('edit').'</a> | <a href="library/delete_file.php?id='.$file_info_all['fr']['file_id'].SEP.'cid='.$cid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('delete').'</a> ]';
			} else {
				echo '[ <a href="library/add_file.php?l=fr'.SEP.'pid='.$file_id.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('add_french_version').'</a> ]';
			}
		}
	}
	echo '&nbsp;</small></small>';
	echo '</td>';
	echo '</tr>';

	echo '<tr>';
	echo '<td class="row'.$col.'" align="right" valign="top"><small><b>'._AC('description').':</b></small></td><td colspan="3" class="row'.$col.'"><small>'.$info['description'].'</small></td>';
	echo '</tr>';

	echo '<tr>';
	echo '<td class="row'.$col.'" align="right"><small><b>'._AC('file_name').':</b></small></td>';
	echo '<td class="row'.$col.'"><small>'.$info['file_name'].'</small></td>';
	echo '<td class="row'.$col.'" align="right"><small><b>'._AC('date').':</b></small></td>';
	echo '<td class="row'.$col.'"><small>'.AT_date(_AC('file_date_format'), $info['initial_date'], AT_DATE_MYSQL_DATETIME).'</small></td>';
	echo '</tr>';

	echo '<tr>';
	echo '<td class="row'.$col.'" align="right"><small><b>'._AC('source').':</b></small></td>';
	echo '<td class="row'.$col.'"><small>'.$info['source'].'</small></td>';
	echo '<td class="row'.$col.'" align="right"><small><b>'._AC('by').':</b></small></td>';
	echo '<td class="row'.$col.'"><small><a href="profile.php?id='.$info['member_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.get_login($info['member_id']).'</a></small></td>';
	echo '</tr>';

	echo '<tr>';
	echo '<td class="row'.$col.' nobar" align="right"><small><b>'._AC('file_type').':</b></small></td>';
	echo '<td class="row'.$col.' nobar"><small>';
	if (isset($_file_types[$ext][1])) {
		echo $_file_types[$ext][1];
	} else {
		echo _AC('unknown');
	}
	echo '&nbsp;</small></td>';
	echo '<td class="row'.$col.' nobar" align="right"><small><b>'._AC('size').':</b></small></td>';
	echo '<td class="row'.$col.' nobar"><small>'.number_format($info['file_size']/1024, 1).' KB</small></td>';
	echo '</tr>';

	echo '</table>';
	echo '<img src="images/clr.gif" height="5" width="5" alt="" />';
}

	require(AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab