<?php
include("init.php");
$tpl = new TemplatePower("templates/".$config['site_template']."/submit.html");
$tpl->assignInclude("header", "templates/".$config['site_template']."/header.html");
$tpl->assignInclude("footer", "templates/".$config['site_template']."/footer.html");
$tpl->prepare();
require_once("inc/pagehead.php");
if(isset($_POST['canProcess']) && $_POST['canProcess'] == "true")
{
$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$url = mysql_escape_string($_POST['url']);
$title = mysql_escape_string($_POST['title']);
$tutorial_url = mysql_escape_string($_POST['tutorial_url']);
$thumbnail_url = mysql_escape_string($_POST['thumbnail_url']);
list($category, $subcategory) = explode("-", $_POST['category']);
if(empty($name))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 1));
}
else if(empty($email) || !eregi("^[_a-z0-9]+(\.[_a-z0-9-]+)*@([a-z0-9-]+\.)+([a-z0-9]{2,4})$",$email))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 2));
}
else if(empty($url))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 3));
}
else if(empty($title))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 4));
}
else if(empty($tutorial_url))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 5));
}
else if(empty($thumbnail_url))
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 6));
}
else if(empty($category) || $category == "0")
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 7));
}
else if(empty($subcategory) || $subcategory == "0")
{
$tpl->newBlock("SUBMISSIONERRORS");
$tpl->assign("SUBMISSIONERROR", getError("submit", 8));
}
else
{
require("inc/nusoap/nusoap.php");
$params = array(array(
"api_key"=>$config['api_key'],
"name"=>$name,
"email"=>$email,
"url"=>$url,
"title"=>$title,
"tutorial_url"=>$tutorial_url,
"thumbnail_url"=>$thumbnail_url,
"category"=>$category,
"subcategory"=>$subcategory
));
$client = new soapclient($config['submit_service_url']);
$response = $client->call("submitTutorial", $params);
if($response['errCode'] != "Tutorial submitted")
{
$tpl->newBlock("APIERRORS");
$tpl->assign("APIERROR", $response['errDesc']);
}
else
{
$tpl->newBlock("SUBMISSIONSUCCESS");
$tpl->assign("AUTHORNAME", $name);
$tpl->assign("TUTORIALNAME", $title);
}
}
}
else
{
$tpl->newBlock("SUBMITFORM");
$tpl->assign("F_NAME", "name");
$tpl->assign("F_EMAIL", "email");
$tpl->assign("F_URL", "url");
$tpl->assign("F_TITLE", "title");
$tpl->assign("F_TUTORIALURL", "tutorial_url");
$tpl->assign("F_THUMBNAILURL", "thumbnail_url");
$tpl->assign("F_CATEGORY", "category");
$tpl->assign("F_SUBMIT", "submit");
$tpl->assign("F_CANPROCESS", "canProcess");
$tpl->assign("F_CANPROCESSVALUE", "true");
foreach($complexCategoryArray as $catId=>$categoryArray)
{
$tpl->newBlock("CATEGORYCOMBO");
$tpl->assign("F_CATEGORYCOMBONAME", $categoryArray['name']);
foreach($categoryArray['subcategory'] as $subCatId=>$subcatName)
{
$tpl->newBlock("SUBCATEGORYCOMBO");
$tpl->assign("F_CATEGORYCOMBOVALUE", "$catId-$subCatId");
$tpl->assign("F_SUBCATEGORYCOMBONAME", $subcatName);
}
}
}
$tpl->printToScreen();
?>