<?php

// configure.php - Interface for configuration options
// ------------------------------------------------------------------------
// Copyright (c) 2001, 2002 The phpBugTracker Group
// Copyright (c) 2004, 2005 David Han Sze Chuen, Denis Guinnepain for Air Liquide Medical Systems (Taema)
// Copyright (c) 2005, 2006, 2015 Denis Guinnepain
 
// ------------------------------------------------------------------------
// This file is part of Diamentis

// Diamentis is free software; you can 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.

// Diamentis 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 should have received a copy of the GNU General Public License
// along with phpBugTracker; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// ------------------------------------------------------------------------
// $Id: configure.php,v 1.1.1.3 2006/06/02 20:17:33 denis Exp $

chdir('..');
define('TEMPLATE_PATH', 'admin');
include 'include.php';

$perm->check('Admin');

if (isset($_pv['submit'])) 
{
	foreach ($_pv as $k => $v) 
	{
		if ($k == 'CHANGE_FILE_INDEX')
		{
			$v=intval($v);
			if ($v<4294967295)//max_int for an interger(10)
			{
				$current_id=$db->getOne("SELECT max(file_id) FROM " . TBL_FILE_INDEX );
				$current_id=intval($current_id);
				if ($v>=$current_id)
				{
					$db->query($rqst='update ' . TBL_FILE_INDEX . "_seq set id = '$v' ");
					//println("la requete vaut $rqst");
					$db->query('update '.TBL_CONFIGURATION." set varvalue = '$v' where varname = '$k'");
				}
				else
				{
					if ($v!=CHANGE_FILE_INDEX)
					{
						$message=$STRING['bad_index'];
					}
				}
			}
			else
			{
				$message=$STRING['bad_index'];
			}
		}	
		else
		{
			$db->query('update '.TBL_CONFIGURATION." set varvalue = '$v' where varname = '$k'");
		}
		// Refresh the template variable now instead of waiting for the next page load.
		if ($k == 'STYLE') 
		{
			$t->assign('STYLE', $v);
		}
	}
}

$t->assign('message',  $message);
$t->assign('vars',  $db->getAll('select * from '.TBL_CONFIGURATION));
$t->wrap('admin/configure.html', 'configuration');

?>


