<?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 member_rank FROM group_memberships WHERE userid = '".$my_id."' AND groupid = '".$groupid."' AND member_rank > 1 AND is_pending = '0' LIMIT 1") or die(mysql_error());
$is_member = mysql_num_rows($check);

if($is_member > 0){
	$my_membership = mysql_fetch_assoc($check);
	$member_rank = $my_membership['member_rank'];
} else {
	echo "Modifica Del Gruppo Non Riuscita\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;
}

$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 "Modifica Gruppo Non Riuscita\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']);
$pane = FilterText($_POST['forumType']);
$topic = FilterTExt($_POST['newTopicPermission']);

if($groupdata['type'] == "3" && $_POST['type'] !== "3"){ echo "L'utente non puņ modificare il tipo di gruppo, se č impostato su 3."; exit; } // you can't change the group type once you set it to 4, fool
if($type < 0 || $type > 3){ 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)) > 255){
	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 Scrivi il 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."', description = '".$description."', type = '".$type."',pane='".$pane."',topics='".$topic."',roomid='".$_POST['roomId']."' WHERE id = '".$groupid."' AND ownerid = '".$my_id."' LIMIT 1") or die(mysql_error());
	echo "".$_POST['forum_type']." Modifica Del Gruppo Avvenuta 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>";
}
?>