Edit Project
';
include("table.php");
if (isset($_GET['id']) && $_SERVER['REQUEST_METHOD'] != 'POST')
{
$id = clean($_GET['id']);
if (empty($id) || !is_numeric($id))
die("Please only follow the links on the page.");
$link = "SELECT * FROM projects WHERE id='$id'";
$res = mysql_query($link) or die(mysql_error());
$total = mysql_num_rows($res);
$row = mysql_fetch_assoc($res);
$priv = $row['private'];
//print_r(array_values($row)); die;
//ho $_SESSOIN['admin'];
if ($priv == 1 && $_SESSION['admin'] != 1)
die("An admin has marked this project un-editable.");
if ($total == 0)
die("No project exists by this id.");
echo '
';
}
elseif ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$id = clean($_POST['id']);
$status = clean($_POST['status']);
$name = clean($_POST['name']);
$date = $_POST['date'];
$des = clean($_POST['des']);
$cat = clean($_POST['cat']);
@$delete = $_POST['delete'];
$sort = clean($_POST['sort']);
@$priv = clean($_POST['private']);
$time = date("h:i:s A");
$d = date("n/j/Y");
$change = $d . " " . $time;
$n = $_SESSION['user'];
$need = array($status,$name,$date,$des,$cat,$sort);
foreach ($need as $val)
{
if (empty($val))
die("You did not fill out all required fields.");
}
if (!is_numeric($sort))
die("The sort value must be a whole number.");
if ($priv == 'on')
$priv = 1;
else
$priv = 0;
//echo "priv is " . $priv; die;
$set = "name='$name',`date`='$date',des='$des',cat='$cat',sort='$sort',last_changed='$change',private='$priv',last_user='$n',status='$status'";
$link = "SELECT * FROM projects WHERE id='$id'";
$res = mysql_query($link) or die(mysql_error());
$total = mysql_num_rows($res);
if ($total == 0)
die("No Projects exist by this id.");
if ($delete == 'on')
{
admin();
$link = "DELETE FROM projects WHERE id='$id'";
$res = mysql_query($link) or die(mysql_error());
if ($res)
die('
Project Succesfully Deleted.
Click here to go back.');
}
$link = "UPDATE projects SET $set WHERE id='$id'";
$res = mysql_query($link) or die(mysql_error());
if ($res)
die('succesfully updated.
click here to continue.
');
}
else
die('You should not be seeing this.
Click here to go back.');
?>