<?php
chdir("../");
include "inc/functions.inc.php";
$mysql = new mysql(DB_MAIN);
if(empty($_POST['image']))
{
$imageurl = "";
} else {
$imageurl = $_POST['image'];
}
if(empty($_POST['name']))
{
header("Location: ".SITE_URL."Tutorial-Submit&serror=needname");
} elseif(empty($_POST['desc']))
{
header("Location: ".SITE_URL."Tutorial-Submit&serror=needdesc");
} elseif(empty($_POST['tutorial']))
{
header("Location: ".SITE_URL."Tutorial-Submit&serror=needtut");
}
$next['1'] = $mysql->select(PRE."tutorials", NULL, "id", "DESC", "1");
while($n=mysql_fetch_array($next['1']))
{
$next['2'] = $n['id']+1;
}
if(!empty($_POST['link']) && !empty($_POST['external']))
{
$link = $_POST['link'];
}
$mysql->insert(PRE."tutorials", array('name', 'cat', 'descr', 'date', 'author', 'level', 'link', 'image'), array($_POST['name'], $_POST['cat'], htmlspecialchars($_POST['desc']), time(), $_COOKIE['user'], $_POST['level'], htmlspecialchars($link), htmlspecialchars($imageurl))) or die(mysql_error());
$fp = fopen(SITE_PATH."tutorials/".$_POST['cat']."-".$next['2'].".php","w") or die("Can't make the file");
$writeout = parse(addslashes($_POST['tutorial']));
fwrite($fp, $writeout) or die("Couldn't write the file");
fclose($fp);
$mysql->close();
header("Location: ".SITE_URL."Tutorial/".$_POST['cat'].'/'.$next['2']);
?>