$pageTitle="Visualizations :: Timelines :: Create Timeline";
include($_SERVER['DOCUMENT_ROOT'] . "/template/header.php");
echo "
Timelines :: Create Timeline
\n";
$errorArray=array();
/*************************************************************
Start by figuring out who is logged in
*************************************************************/
if(user_logged_in() && !$doingLogout){
$username=$_COOKIE['sclcr'];
}
else{
// the user isn't logged in
?>
Not Logged In
You must be logged in before you can create timelines.
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php");
exit();
}
//END user check
//validate object titles
function validate_title($t){
if( strlen($t)>=5 && strlen($t)<=255 && str_word_count($t)>=1 ){
return true;
}
else{
return false;
}
}
//validate object descriptions
function validate_description($d){
if( strlen($d)>=5 && strlen($d)<=2000 && str_word_count($d)>=2 ){
return true;
}
else{
return false;
}
}
//let's see if they submitted any values and if so, we validate and process them
if( isset($_POST['submitTimeline']) ){
//they submitted data so let's check it
if( isset($_POST['title']) && isset($_POST['description']) ){
//they did include a title and description
$title=trim(strip_tags($_POST['title']));
$description=$_POST['description'];
//let's validate the description and title
if(validate_title($title)){
if(validate_description($description)){
//the title and description are good
//echo "TITLE and DESCRIPTION are GOOD
\n";
//everything is valid and ready to roll
//format and clean the variables
$title=sanitize($title);
$description=sanitize($description);
$sqlInsertString="INSERT INTO Timelines (title, description, contributor, created) VALUES ('$title', '$description', '$username', NOW())";
$resultArray=database_query($sqlInsertString, 2, true);
if($resultArray){
$result=$resultArray['db'];
$newTimelineID=$resultArray['id'];
if($result){
echo "
\n";
echo "
\n";
$title="";
$description="";
}
}
else{
$errorArray[]="databaseInsertFail";
}
}
else{
//something was wrong so we refuse to insert the new object into the database
$errorArray[]="invalidDescription";
}
}
else{
//description invalid
$errorArray[]="invalidTitle";
}
}
else{
//they did not submit these required values so fail
$errorArray[]="missingTitleOrDescription";
}
}
else{
//they didn't submit anything
//$errorArray[]="noData";
}
//if there were errors we need to display messages
if(count($errorArray)>=1){
echo "\n";
echo "
\n";
foreach($errorArray as $e){
if($e=="noData"){
echo "- No data was submitted. Please fill out the form and press the submit button.
\n";
}
elseif($e=="missingTitleOrDescription"){
echo "- You are missing either the title or description for your timeline. Both are required.
\n";
}
elseif($e=="invalidTitle"){
echo "- Your title is not valid. It must be between 5 and 1024 characters long.
";
}
elseif($e=="invalidDescription"){
echo "- Your description is not valid. It must be between 5 and 2000 characters long and consist of at least three words.
";
}
elseif($e=="databaseInsertFail"){
echo "- We experienced a technical error while attempting to add your timeline to the database. We apologize. Please try again in a few moments.
";
}
else{
echo "- An error occured. We apologize. Please try again in a few moments.
\n";
}
}
echo "
\n
\n";
}
?>
Similar Timelines in the Database
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>