$pageTitle="Visualizations :: Timelines :: Manage Timelines";
include($_SERVER['DOCUMENT_ROOT'] . "/template/header.php");
echo "
Creating Timeline Citation
\n";
echo "Return to Editing Your 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 timeline items.
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php");
exit();
}
//END user check
//validate object titles
function validate_citation($t){
if( strlen($t)>=10 && strlen($t)<=1024 && 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;
}
}
//validate a date
function generate_datetime($m, $d, $y){
if($d==0) $d=1;
if($m==0) $m=1;
if( !is_numeric($d) || !is_numeric($m) || !is_numeric($y) || $d<1 || $d>31 || $m<1 || $m>12 || $y<1000 || $y>9999 ) return false;
if( !checkdate($m, $d, $y) ) return false;
if( $d<10 ){ $d="0" . $d; } else { $d="$d"; }
if( $m<10 ){ $m="0" . $m; } else { $m="$m"; }
//YYYY-MM-DD HH:MM:SS
return "$y-$m-$d 00:00:00";
}
//take a year, month, and day and format a date for DISPLAY purposes
function format_display_date($y, $m, $d){
//if the month and day are both 1 then we ONLY show the year
if($m==1 && $d==1) return "$y";
//if the month is other than 1 and the day is one we dispay the month as well
if($m>1 && $d==1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " " .$y;
//if the day is other than 1 we show the full date
if($d>1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " $d, $y";
return false;
}
//let's see if they submitted any values and if so, we validate and process them
if( isset($_POST['submitCitation']) ){
//they submitted data so let's check it
if( isset($_POST['citation']) && isset($_POST['description']) ){
//they did include a title and description
$citation=trim(strip_tags($_POST['citation']));
$description=$_POST['description'];
//let's validate the description and title
if(validate_citation($citation)){
if(validate_description($description)){
//the title and description are good
//echo "TITLE and DESCRIPTION are GOOD
\n";
/*****************************************************
COMPUTE DATE
*****************************************************/
if( isset($_POST['day']) ){ $day=$_POST['day']; } else { $day=1; }
if( isset($_POST['month']) ){ $month=$_POST['month']; } else { $month=1; }
if( isset($_POST['year']) ){ $year=$_POST['year']; } else { $year=false; }
$citationDateTime=generate_datetime($month, $day, $year);
if($citationDateTime){
//the datetime is valid
//echo "
VALID: $startDateTime
\n";
}
else{
//invalid date
$errorArray[]="invalidDate";
}
/***************************************************/
//check to make sure we are ready to add to database
if( $citationDateTime ){
//everything is valid and ready to roll
//format and clean the variables
$citation=sanitize($citation);
$description=sanitize($description);
$sqlInsertString="INSERT INTO Citations (conceptID, citation, created, date, description) VALUES (0, '$citation', NOW(), '$citationDateTime', '$description')";
$result=database_query($sqlInsertString);
if($result){
echo "\n";
echo "- Your new citation was successfully added to the database. Thanks!
\n";
if( isset($_SESSION['targetTimeline']) ){
echo "- Continue editing your timeline
\n";
}
echo "
\n";
$citation="";
$description="";
$month="";
$day="";
$year="";
}
else{
$errorArray[]="databaseInsertFail";
}
}
else{
//something was wrong so we refuse to insert the new object into the database
$errorArray[]="citationDateTimeFormatFail";
}
}
else{
//description invalid
$errorArray[]="invalidDescription";
}
}
else{
//title invalid
$errorArray[]="invalidCitation";
}
}
else{
//they did not submit these required values so fail
$errorArray[]="missingCitationOrDescription";
}
}
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=="missingCitationOrDescription"){
echo "- You are missing either the citation or description. Both are required.
\n";
}
elseif($e=="invalidCitation"){
echo "- Your citation is not valid. It must be between 10 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=="citationDateTimeFormatFail"){
echo "- There appears to be something wrong with the date you have provided. Please check it and try again.
";
}
elseif($e=="databaseInsertFail"){
echo "- We experienced a technical error while attempting to add your citations to the database. We apologize. Please try again in a few moments.
";
}
elseif($e=="invalidDate"){
echo "- You did not provide a valid date. You must provide at least the year. Make sure the date is accurate and that you selected a valid day of the month.
";
}
else{
echo "- An error occured. We apologize. Please try again in a few moments.
\n";
}
}
echo "
\n
\n";
}
?>
Similar Citations in the Database
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>