<?php
// $Id: admin.checkin.php,v 1.4 2003/12/17 22:14:31 eddieajau Exp $
/**
* Global Checkin
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.4 $
**/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

if (!$acl->acl_check( 'administration', 'config', 'users', $my->usertype )) {
	mosRedirect( 'index2.php', _NOT_AUTH );
}
?>
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td class="sectionname"><img src="images/mos_gel.png" width="70" height="67" align="middle">Global Check-in</td>
</tr>
</table>
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
<tr>
	<th class="title">Database Table</th>
	<th class="title"># of Items</th>
	<th class="title">Checked-In</th>
	<th class="title">&nbsp;</th>
</tr>
<?php
$lt = mysql_list_tables($mosConfig_db);
$k = 0;
$dbprefix = $mainframe->getCfg( 'mosConfig_dbprefix' );
while (list($tn) = mysql_fetch_array( $lt )) {
	// make sure we get the right tables based on prefix
	if (!preg_match( "/^".$dbprefix."/i", $tn )) {
		continue;
	}
	$lf = mysql_list_fields($mosConfig_db, "$tn");
	$nf = mysql_num_fields($lf);

	$checked_out = false;
	$editor = false;

	for ($i = 0; $i < $nf; $i++) {
		$fname = mysql_field_name($lf, $i);
		if ( $fname == "checked_out") {
			$checked_out = true;
		} else if ( $fname == "editor") {
			$editor = true;
		}
	}

	if ($checked_out) {
		if ($editor) {
			$database->setQuery( "SELECT checked_out, editor FROM $tn WHERE checked_out > 0" );
		} else {
			$database->setQuery( "SELECT checked_out FROM $tn WHERE checked_out > 0" );
		}
		$res = $database->query();
		$num = $database->getNumRows( $res );

		if ($editor) {
			$database->setQuery( "UPDATE $tn SET checked_out=0, checked_out_time='00:00:00', editor=NULL WHERE checked_out > 0" );
		} else {
			$database->setQuery( "UPDATE $tn SET checked_out=0, checked_out_time='0000-00-00 00:00:00' WHERE checked_out > 0" );
		}
		$res = $database->query();

		if ($res == 1) {
			if ($num > 0) {
				echo "<tr class=\"row$k\">";
				echo "\n	<td width=\"350\">Checking table - $tn</td>";
				echo "\n	<td width=\"150\">Checked in <b>$num</b> items</td>";
				echo "\n	<td width=\"100\" align=\"center\"><img src=\"images/tick.png\" border=\"0\" alt=\"\" /></td>";
				echo "\n	<td>&nbsp;</td>";
				echo "\n</tr>";
			} else {
				echo "<tr class=\"row$k\">";
				echo "\n	<td width=\"350\">Checking table - $tn</td>";
				echo "\n	<td width=\"150\">Checked in <b>$num</b> items</td>";
				echo "\n	<td width=\"100\">&nbsp;</td>";
				echo "\n	<td>&nbsp;</td>";
				echo "\n</tr>";
			}
			$k = 1 - $k;
		}
	}
}
?>
<tr>
	<td colspan="4"><b>Checked out items have now been all checked in</b></td>
</tr>
</table>
