<?php
/*===================================================+
|| # HoloCMS - Website and Content Management System
|+===================================================+
|| # Copyright © 2008 Meth0d. All rights reserved.
|| # http://www.meth0d.org
|+===================================================+
|| # HoloCMS is provided "as is" and comes without
|| # warrenty of any kind. HoloCMS is free software!
|+===================================================*/

include('../core.php');
include('../includes/session.php');

$groupid = FilterText($_POST['groupId']);
if(!is_numeric($groupid)){ exit; }
$check = mysql_query("SELECT * FROM groups WHERE id = '".$groupid."' LIMIT 1") or die(mysql_error());
$valid = mysql_num_rows($check);

if($valid > 0){
	$groupdata = mysql_fetch_assoc($check);
	$ownerid = $groupdata['ownerid'];
} else {
	echo "Gruppo Non Salvato Con Successo\n\n<p>\n<a href=\"group_profile.php?id=".$groupid."\" class=\"new-button\"><b>Ok</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
	exit;
}

if($ownerid !== $my_id){ exit; }

$name = trim(FilterText($_POST['name']));
$description = trim(FilterText($_POST['description']));
$type = FilterText($_POST['type']);

if(is_numeric($_POST['roomId']))
$roomid = FilterText($_POST['roomId']);
else
$roomid = 0;

if($type != "locked" AND $type != "open" AND $type != "closed"){ echo "Gruppo Invalido."; exit; } // this naughty user doesn't even deserve an settings update

if(strlen(HoloText($name)) > 25){
	echo "Nome Troppo Lungo\n\n<p>\n<a href=\"group_profile.php?id=".$groupid."\" class=\"new-button\"><b>Ok</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
} elseif(strlen(HoloText($description)) > 200){
	echo "Descrizione troppo lunga\n\n<p>\n<a href=\"group_profile.php?id=".$groupid."\" class=\"new-button\"><b>Ok</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
} elseif(strlen(HoloText($name)) < 1){
	echo "Perfavore inserisci un Nome\n\n<p>\n<a href=\"group_profile.php?id=".$groupid."\" class=\"new-button\"><b>Ok</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";	
} else {
	mysql_query("UPDATE groups SET name = '".$name."', `desc` = '".$description."', locked = '".$type."', roomid = '".$roomid."' WHERE id = '".$groupid."' AND ownerid = '".$my_id."' LIMIT 1") or die(mysql_error());
	SendMUS("updategroup", $groupid);
	echo "Modifiche Salvate Con Successo\n\n<p>\n<a href=\"group_profile.php?id=".$groupid."\" class=\"new-button\"><b>Ok</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
}
?>