require("../inc/db_conn.php"); ?> if(!isset($HTTP_COOKIE_VARS['u_id'])) { require("oops.php"); #phpInfo(); exit; } // Variables Expected: /* $theAction: "New" (no preload), "Add" (on submit) or "Edit" $entry_id $name (person's name) $address1 $address2 $city $state $zip $country $phone $email $dob $modelname $category $scale $otherscale $dimensions_feetinches $dimensions_studs $setup_time $specialneeds $powerneeds $picture1 $picture2 $picture3 $picture4 $picture5 */ /* Database table "buildthetrust": entry_id e_id u_id name (person's name) address1 address2 city state zip country phone email dob modelname category scale otherscale dimensions_feetinches dimensions_studs setup_time specialneeds powerneeds picture1 picture2 picture3 picture4 picture5 add_date mod_date goldbrick_flag */ // $_COOKIE['u_id'] // $_COOKIE["niceAccountName"] // Image upload function $theConcat = "\\"; // Windows $theFileBase = "D:\\Web\\brickfest.com\\www\\registration\\historicalcontest\\"; $webpathbase = "/registration/historicalcontest/"; $thumbsBase = $theFileBase; #$theUserFileName = "Headshot1"; $thumbs = array(); function moveThumb($theUserFileName) { global $HTTP_POST_FILES, $theFileBase, $webpathbase, $thumbsBase, $thumbs, $entry_id; $theOrigFileName = $HTTP_POST_FILES[$theUserFileName]['name']; $theTempDir = $HTTP_POST_FILES[$theUserFileName]['tmp_name']; $theType = $HTTP_POST_FILES[$theUserFileName]['type']; $theSize = $HTTP_POST_FILES[$theUserFileName]['size']; //Reassign the temp name $theFileName = basename($theOrigFileName); // Substitute spaces and other crap in the filename // let's make it lowercase, just in case $theFileName = strtolower($theFileName); // Remove garbage characters $replaceMe = array(".","@","'","#","/","\\","^","*","$","&","%","!","+",":",";","?","|","=","<",">",",","(",")","\"","?","[","]","{","}","~","`"); $newFileName = str_replace($replaceMe,"",$theFileName); // Now replace spaces with underscores $theFileName = str_replace(" ","_",$newFileName); // Allow .jpg, .gif, .png, .bmp files only $ext = strtolower(substr($theOrigFileName,-3)); if($ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "bmp") { $theFileName = substr($theFileName,0,strlen($theFileName)-3) . "." . $ext; } #echo("Trying to copy $theTempDir to " . $theFileBase . $theFileName . "
\n"); if($theFileName != "") { // Prepend [$u_id]_[$entry_id] to the filename, to stay unique $theFileName = "{$_COOKIE['u_id']}_{$entry_id}_" . $theFileName; //if(copy($theTempDir, "$theFileBase" . "$theFileName")) { if(move_uploaded_file($theTempDir,"$theFileBase" . "$theFileName")) { $headshotTemp = $theFileBase . $theFileName; $thumbName = substr($theFileName,0,strlen($theFileName)-4) . "." . $ext; $th_headshotTemp = $thumbsBase . $thumbName; $thumbURL = $webpathbase . $thumbName; @chmod ($headshotTemp, 0777); // Generate thumbnail #$theConvert = "convert {$theFileBase}{$theFileName} -resize 120x120 +profile \"*\" -type TrueColor -colorspace RGB -quality 90 $th_headshotTemp"; #echo("$theConvert
\n\n");
#$doIt = `$theConvert`;
// Add to array to return
// 0 = full image absolute uri
// 1 = thumb absolute uri
// 2 = thumb relative uri
$thumbs[$theUserFileName][0] = $headshotTemp;
$thumbs[$theUserFileName][1] = $th_headshotTemp;
$thumbs[$theUserFileName][2] = $thumbURL;
$thumbs[$theUserFileName][3] = $thumbName;
} else {
#echo("ERROR: $theFileName ($theOrigFileName) not moved! Please see the Help documentation on why this may have happened.
");
}
}
}
$errMsg = "";
// Now, parse the action, if any
if(!isset($theAction) || $theAction == "new") {
// Get default values, prepopulate
$theDisplayAction = "add";
$entry_id = "";
$subsubnav = "";
$theQuery = "select birthdate, address1, address2, city, state, postal, country, email from user_accounts where u_id = {$_COOKIE['u_id']}";
$theResult = mysql_query($theQuery);
if(mysql_num_rows($theResult) > 0) {
//assign
while($row = mysql_fetch_array($theResult)) {
$name = $_COOKIE["niceAccountName"];
$address1 = $row['address1'];
$address2 = $row['address2'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['postal'];
$country = $row['country'];
$email = $row['email'];
$dob = $row['birthdate'];
}
} else {
$name = $_COOKIE["niceAccountName"];
$address1 = "";
$address2 = "";
$city = "";
$state = "";
$zip = "";
$country = "";
$email = "";
$dob = "";
}
// Now the rest
$modelname = "";
$url = "";
$category = "";
$scale = "";
$otherscale = "";
$dimensions_feetinches = "";
$dimensions_studs = "";
$setup_time = "";
$specialneeds = "";
$powerneeds = "";
} elseif($theAction == "add") {
// Add to DB, set unique ID
$subsubnav = "
View All My Contest Entries | Enter Another MOC
\n"; $theDisplayAction = "showedit"; // Get and set the $entry_id $add_date = date("Y-m-d"); $theQuery = "insert into buildthetrust (e_id, u_id, name, address1, address2, city, state, zip, country, phone, email, dob, modelname, url, category, scale, otherscale, dimensions_feetinches, dimensions_studs, setup_time, specialneeds, powerneeds, add_date, goldbrick_flag) values ({$master_event_id}, {$_COOKIE['u_id']}, '{$name}', '{$address1}', '{$address2}', '{$city}', '{$state}', '{$zip}', '{$country}', '{$phone}', '{$email}', '{$dob}', '{$modelname}', '{$url}', {$category}, {$scale}, '{$otherscale}', '{$dimensions_feetinches}', '{$dimensions_studs}', '{$setup_time}', '{$specialneeds}', '{$powerneeds}', '{$add_date}', 0)"; mysql_query($theQuery); $entry_id = mysql_insert_id(); moveThumb('picture1'); moveThumb('picture2'); moveThumb('picture3'); moveThumb('picture4'); moveThumb('picture5'); #print_r($thumbs); #echo(""); $theUpdate = "update buildthetrust set "; $continueUpdate = false; $theAnd = ""; if($thumbs['picture1'][2] != "") { $theUpdate .= $theAnd . "picture1 = '" . $thumbs['picture1'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture2'][2] != "") { $theUpdate .= $theAnd . "picture2 = '" . $thumbs['picture2'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture3'][2] != "") { $theUpdate .= $theAnd . "picture3 = '" . $thumbs['picture3'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture4'][2] != "") { $theUpdate .= $theAnd . "picture4 = '" . $thumbs['picture4'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture5'][2] != "") { $theUpdate .= $theAnd . "picture5 = '" . $thumbs['picture5'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } $theUpdate .= " where entry_id = {$entry_id} and u_id = {$_COOKIE['u_id']}"; #echo($theUpdate); if($continueUpdate == true) { // At least one uploaded file #echo("
Updating image DB...
\n"); mysql_query($theUpdate); } $errMsg = "Your Entry Has Been Saved. You can change this at any time."; } elseif($theAction == "showedit") { // Display the DB entry $subsubnav = "
View All My Contest Entries | Enter Another MOC
\n"; $theDisplayAction = "subedit"; // Get it all from the DB $theQuery = "select name, address1, address2, city, state, zip, country, phone, email, dob, modelname, url, category, scale, otherscale, dimensions_feetinches, dimensions_studs, setup_time, specialneeds, powerneeds, picture1, picture2, picture3, picture4, picture5, add_date, mod_date from buildthetrust where entry_id = {$entry_id} and u_id = {$_COOKIE['u_id']}"; #echo($theQuery); $theResults = mysql_query($theQuery); if(mysql_num_rows($theResults) == 1) { // Got one, get info while($row = mysql_fetch_array($theResults)) { $name = $row['name']; $address1 = $row['address1']; $address2 = $row['address2']; $city = $row['city']; $state = $row['state']; $zip = $row[zip]; $country = $row['country']; $email = $row['email']; $dob = $row['dob']; $modelname = $row['modelname']; $url = $row['url']; $category = $row['category']; $scale = $row['scale']; $otherscale = $row['otherscale']; $dimensions_feetinches = $row['dimensions_feetinches']; $dimensions_studs = $row['dimensions_studs']; $setup_time = $row['setup_time']; $specialneeds = $row['specialneeds']; $powerneeds = $row['powerneeds']; $picture1 = $row['picture1']; $picture2 = $row['picture2']; $picture3 = $row['picture3']; $picture4 = $row['picture4']; $picture5 = $row['picture5']; $add_date = $row['add_date']; $mod_date = $row['mod_date']; } } else { $errMsg = "Sorry, could not find the requested information."; } } elseif($theAction == "subedit") { // Parse submitted edit $theDisplayAction = "showedit"; $subsubnav = "View All My Contest Entries | Enter Another MOC
\n"; $theModDate = date("Y-m-d"); $theUpdate = "update buildthetrust set name = '{$name}', address1 = '{$address1}', address2 = '{$address2}', city = '{$city}', state = '{$state}', zip = '{$zip}', country = '{$country}', email = '{$email}', dob = '{$dob}', modelname = '{$modelname}', category = {$category}, scale = {$scale}, otherscale = '{$otherscale}', dimensions_feetinches = '{$dimensions_feetinches}', dimensions_studs = '{$dimensions_studs}', setup_time = '{$setup_time}', specialneeds = '{$specialneeds}', powerneeds = '{$powerneeds}', mod_date = '{$theModDate}' where entry_id = {$entry_id} and u_id = {$_COOKIE['u_id']}"; mysql_query($theUpdate); moveThumb('picture1'); moveThumb('picture2'); moveThumb('picture3'); moveThumb('picture4'); moveThumb('picture5'); $theUpdate = "update buildthetrust set "; $continueUpdate = false; $theAnd = ""; if($thumbs['picture1'][2] != "") { $theUpdate .= $theAnd . "picture1 = '" . $thumbs['picture1'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture2'][2] != "") { $theUpdate .= $theAnd . "picture2 = '" . $thumbs['picture2'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture3'][2] != "") { $theUpdate .= $theAnd . "picture3 = '" . $thumbs['picture3'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture4'][2] != "") { $theUpdate .= $theAnd . "picture4 = '" . $thumbs['picture4'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } if($thumbs['picture5'][2] != "") { $theUpdate .= $theAnd . "picture5 = '" . $thumbs['picture5'][2] . "'"; $continueUpdate = true; $theAnd = ", "; } $theUpdate .= " where entry_id = {$entry_id} and u_id = {$_COOKIE['u_id']}"; #echo($theUpdate); if($continueUpdate == true) { // At least one uploaded file #echo("Updating image DB...
\n"); mysql_query($theUpdate); } $errMsg = "Your Entry Has Been Saved. You can change this at any time."; } // Get pix $thePixQuery = "select picture1, picture2, picture3, picture4, picture5 from buildthetrust where entry_id = {$entry_id} and u_id = {$_COOKIE['u_id']}"; $pixResults = mysql_query($thePixQuery); $picture1=""; $picture2=""; $picture3=""; $picture4=""; $picture5=""; while($row=mysql_fetch_array($pixResults)) { if($row['picture1'] != "") { $picture1 = $row['picture1']; } if($row['picture2'] != "") { $picture2 = $row['picture2']; } if($row['picture3'] != "") { $picture3 = $row['picture3']; } if($row['picture4'] != "") { $picture4 = $row['picture4']; } if($row['picture5'] != "") { $picture5 = $row['picture5']; } } ?>
Sponsored by the LEGO Group and National Trust for Historic Preservation. For entry rules and contest details, see "Build the Trust".
=$subsubnav?>You will be able to return and edit your entry for this model at any time.
include("../inc/footer.php"); ?>