Location: PHPKode > projects > Trunk.net > creategroups.php
<?
foreach($_POST as $key=>$value) $$key=$value;
foreach($_GET as $key=>$value) $$key=$value; 
ob_start();
require_once("include/functions.php");
dbconn(false);
loggedinorreturn();
if (get_user_class() < UC_ADMINISTRATOR)
stderr("Error", "You can't go here!");
stdhead("Groups");
print("<h1>Groups</h1>\n");
print("</br>");
print("<table width=70% border=1 cellspacing=0 cellpadding=2><tr><td align=center>\n");

///////////////////// Delete group \\\\\\\\\\\\\\\\\\\\\\\\\\\\

$sure = $_GET['sure'];
if($sure == "yes") {
$del = $_GET['del'];
$query = "DELETE FROM groups WHERE id=" .sqlesc($del) . " LIMIT 1";
$sql = mysql_query($query);
echo("Group successfully deleted![ <a href='". $_SERVER['PHP_SELF'] . "'>Back</a> ]");
end_frame();
stdfoot();
die();
}
$del = $_GET['del'];
$name = $_GET['group'];
if($del > 0) {
echo("You and in the truth wish to delete group? ($name) ( <strong><a href='". $_SERVER['PHP_SELF'] . "?del=$del&group=$name&sure=yes'>Yes!</a></strong> / <strong><a href='". $_SERVER['PHP_SELF'] . "'>No!</a></strong> )");
end_frame();
stdfoot();
die();

}

///////////////////// Edit group \\\\\\\\\\\\\\\\\\\\\\\\\\\\

$edited = $_GET['edited'];
if($edited == 1) {
$id = $_GET['id'];
$group_name = $_GET['group_name'];
$group_image = $_GET['group_image'];
$query = "UPDATE groups SET
name = '$group_name',
image = '$group_image' 
WHERE id=".sqlesc($id);
$sql = mysql_query($query);
if($sql) {
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<tr><td><div align='center'><strong>Successfully </strong>eciaieii[ <a href='". $_SERVER['PHP_SELF'] . "'>Back</a> ]</div></tr>");
echo("</table>");
end_frame();
stdfoot();
die();
}
}

$editid = $_GET['editid'];
$name = $_GET['name'];
$image = $_GET['image'];
if($editid > 0) {
echo("<form name='smolf3d' method='get' action='" . $_SERVER['PHP_SELF'] . "'>");
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<div align='center'><input type='hidden' name='edited' value='1'>Now you edit group <strong>&quot;$name&quot;</strong></div>");
echo("<br>");
echo("<input type='hidden' name='id' value='$editid'<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<tr><td>Group: </td><td align='right'><input type='text' size=50 name='group_name' value='$name'></td></tr>");
echo("<tr><td>Image group: </td><td align='right'><input type='text' size=50 name='group_image' value='$image'></td></tr>");
echo("<tr><td></td><td><div align='right'><input type='Submit' value=Update'></div></td></tr>");
echo("</table></form>");
end_frame();
stdfoot();
die();
}

///////////////////// Add group \\\\\\\\\\\\\\\\\\\\\\\\\\\\

$add = $_GET['add'];
if($add == 'true') {
$group_name = $_GET['group_name'];
$group_image = $_GET['group_image'];
$query = "INSERT INTO groups SET
name = '$group_name',
image = '$group_image'";
$sql = mysql_query($query);
if($sql) {
$success = TRUE;
} else {
$success = FALSE;
}
}
print("<strong>Add new group:</strong>");
print("<br />");
print("<br />");
echo("<form name='smolf3d' method='get' action='" . $_SERVER['PHP_SELF'] . "'>");
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<tr><td>Group: </td><td align='right'><input type='text' size=50 name='group_name'></td></tr>");
echo("<tr><td>Image group: </td><td align='right'><input type='text' size=50 name='group_image'><input type='hidden' name='add' value='true'></td></tr>");
echo("<tr><td></td><td><div align='right'><input value='Add' type='Submit'></div></td></tr>");
echo("</table>");
if($success == TRUE) {
print("<strong>Group successfully added!</strong>");
}
echo("<br>");
echo("</form>");

///////////////////// All groups \\\\\\\\\\\\\\\\\\\\\\\\\\\\

print("<strong>All groups:</strong>");
print("<br />");
print("<br />");
echo("<table class=main cellspacing=0 cellpadding=5>");
echo("<td>ID group:</td><td>Image group:</td><td>Group name:</td><td>Edit:</td><td>Delete:</td>");
$query = "SELECT * FROM groups WHERE 1=1";
$sql = mysql_query($query);
while ($row = mysql_fetch_array($sql)) {
$id = $row['id'];
$name = $row['name'];
$image = $row['image'];
echo("<tr><td><strong>$id</strong> </td> <td><img src='$image' alt='$name' border='0' /></td> <td><strong>$name</strong></td><td><a href='". $_SERVER['PHP_SELF'] . "?editid=$id&name=$name&image=$image'><div align='center'><img src='$BASEURL/pic/multipage.gif' border='0' class=special /></a></div></td> <td><div align='center'><a href='". $_SERVER['PHP_SELF'] . "?del=$id&group=$name'><img src='$BASEURL/pic/warned2.gif' border='0' class=special align='center' /></a></div></td></tr>");
}

end_frame();
end_frame();
stdfoot();

?> 
Return current item: Trunk.net