#!/usr/bin/php5
<?php
########################################################################
# MuGLIn - MuGLIn GNU/Linux Installation		                       #
#                                                                      #
# Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>       #
# Copyricht (C) 2010 Srdjan Markovic <smark2ki@htl.moedling.at>        #
#                                                                      #
# This file is part of MuGLIn source code.                             #
#                                                                      #
# MuGLIn 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 3 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# MuGLIn 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 MuGLIn. If not, see <http://www.gnu.org/licenses/>.       #
########################################################################

include "/usr/local/lib/muglin/php/functions.php";
get_conf("/etc/muglin/base.conf",$conf);

if(($argv[1]=="--help") || ($argv[1]=="-h") || ($argv[1]=="-?")) die("$argv[0] <ImageName> <Enabled(1)/Disabled(0)> [--verbose]");

$Image="$argv[1]";
$Enable="$argv[2]";

if($argv[3]=="--verbose") $Verbose=true;

if(!($Enable=="0"||$Enable=="1")) return 1;

if(!($Connection=mysql_connect($conf['MYS_HOST'],$conf['MYS_USER'],$conf['MYS_PASS']))) 
	return 3;
if(!(mysql_select_db($conf['MYS_DB'],$Connection))) 
	return 3;
if(!(mysql_num_rows(mysql_query("SELECT Enabled FROM Images WHERE Name='".mysql_real_escape_string($Image)."'",$Connection)))) 
	return 2;
if(mysql_query("UPDATE Images SET Enabled='".mysql_real_escape_string($Enable)."' WHERE Name='".mysql_real_escape_string($Image)."'",$Connection)) 
	return 0;
else 
	return 4;
/*
return-Codes:
	0: finished without errors
	1: false parameters
	2: no Image with this name
	3: mysql error
	4: any other error
*/
?>
