include ("./lib.php");
$db = new satellite;
$db->connectMySQL();
$cmd = $_POST["cmd"];
if ($cmd == "")
{
$cmd = $_GET["cmd"];
}
$cookie_login1 = $_COOKIE["satellite1"];
$cookie_login2 = $_COOKIE["satellite2"];
if (($cookie_login1 != "") && ($cookie_login2 != ""))
{
$logged_in = 1;
}
switch ($cmd)
{
case "login":
$form_email = $_POST["email"];
$form_password = $_POST["password"];
$login_sql = "SELECT installer_id, email, password, first_name, last_name, enabled FROM sat_installers WHERE email='$form_email'";
$res = MySQL_Query ($login_sql);
$row = mysql_fetch_array ($res);
$login_installer_id = $row["installer_id"];
$login_password = $row["password"];
$login_full_name = $row["first_name"] . " " . $row["last_name"];
$login_email = $row["email"];
$login_enabled = $row["enabled"];
if (($form_email == "") || ($form_password == ""))
{
$error_message = "You did not provide an email address and password.";
include ("tmpl/header.tem.php");
include ("tmpl/main-index.tem.php");
include ("tmpl/footer.tem.php");
}
elseif ($form_password != $login_password)
{
$error_message = "Your login information is incorrect.";
include ("tmpl/header.tem.php");
include ("tmpl/main-index.tem.php");
include ("tmpl/footer.tem.php");
}
else
{
if ($login_enabled <> 1)
{
$error_message = "Your login information is correct, but your account has been disabled.";
include ("tmpl/header.tem.php");
include ("tmpl/main-index.tem.php");
include ("tmpl/footer.tem.php");
}
else
{
$login_sql = "UPDATE sat_installers SET last_login=NOW() WHERE email='$form_email'";
$res = MySQL_Query ($login_sql);
setcookie("satellite1", "$login_email", 0);
setcookie("satellite2", "$login_installer_id", 0);
header("Location: index.php");
}
}
break;
case "logout":
setcookie("satellite1", "", 0);
setcookie("satellite2", "", 0);
header("Location: index.php");
break;
case "upload":
include "tmpl/header.tem.php";
include "tmpl/main-upload.tem.php";
include "tmpl/footer.tem.php";
break;
case "do_upload":
case "do_edit":
# $error_cond = 0;
$error_files = "";
$previous_cmd = $_GET["cmd"];
$job_site = $_POST["job_site"];
$which_database = $_GET["b"];
$uploaded_files = array();
$session = $_REQUEST['session'];
$qstr = join("",file("/tmp/{$session}_qstring"));
parse_str($qstr);
$k = count($file['name']);
for($i = 0; $i < $k; $i++)
{
$curr_file = $file["name"][$i];
$slash_pos = strrpos ($curr_file, "\\");
if ($slash_pos !== false)
{
$curr_file = substr ($curr_file, $slash_pos + 1);
}
$curr_file = str_replace (" ", "_", $curr_file);
$curr_file = str_replace ("#", "", $curr_file);
$target_file = $data_dir . $cookie_login1 . "/" . $job_site . "/" . $session . "_" . $curr_file;
# if ($_ENV["TMPDIR"] == "")
# {
# $last_slash = strrpos ($file["tmp_name"][$i], "/");
# $curr_upload_dir = substr ($file["tmp_name"][$i], 0, $last_slash);
# $target_file = $curr_upload_dir . "/" . $session . "_" . $curr_file;
# }
# else
# {
# $target_file = $_ENV["TMPDIR"] . "/" . $session . "_" . $curr_file;
# }
#print "copying: " . $file["tmp_name"][$i] . " to $target_file
\n";
# rename ($file["tmp_name"][$i], $target_file);
# copy ($file["tmp_name"][$i], $target_file);
# chown ($target_file, "iprole2");
$fh = fopen ($file["tmp_name"][$i], "r");
$fh2 = fopen ($target_file, "a+");
while (!feof ($fh))
{
$contents = fread ($fh, 8192);
fwrite ($fh2, $contents);
}
fclose ($fh);
fclose ($fh2);
sleep (2);
#print "copying: " . $file["tmp_name"][$i] . " to $target_file
\n";
chmod ($target_file, 0777);
}
#print "upload done, pc = $previous_cmd
\n";
if ($previous_cmd == "do_edit")
{
if ($k > 0)
{
$raw_qstring = file_get_contents("/tmp/{$session}_qstring");
$qstring_array = explode ("&", $raw_qstring);
#print "qs:
\n";
#print_r ($qstring_array);
#print "qs:
\n";
$org_site = "";
$new_site = "";
foreach ($qstring_array as $i)
{
list ($key, $val) = explode ("=", $i);
if ($key == "job_site")
{
$org_site = $val;
}
if ($key == "sites")
{
$new_site = $val;
}
}
if ($new_site != $org_site)
{
$job_site = $new_site;
}
else
{
$job_site = $org_site;
}
header ("Location: index.php?cmd=process&s=$session&d=$curr_upload_dir&p=$previous_cmd&j=$job_site&ec=0&b=$which_database");
header ("URI: index.php?cmd=process&s=$session&d=$curr_upload_dir&p=$previous_cmd&j=$job_site&ec=0&b=$which_database");
}
else
{
$upload_sql = "UPDATE sat_images SET notes=\"$new_notes\", sites_id=\"$new_sites\", uploaded=NOW() WHERE installer_id='$cookie_login2' AND filename='" . $_POST["i"] . "' AND sites_id='$job_site'";
$res = MySQL_Query ($upload_sql);
header ("Location: index.php?cmd=edit_commit&s=$session&p=$previous_cmd&j=$job_site&b=$which_database");
header ("URI: index.php?cmd=edit_commit&s=$session&p=$previous_cmd&j=$job_site&b=$which_database");
}
}
else
{
header ("Location: index.php?cmd=process&s=$session&d=$curr_upload_dir&p=$previous_cmd&j=$job_site&ec=0&b=$which_database");
header ("URI: index.php?cmd=process&s=$session&d=$curr_upload_dir&p=$previous_cmd&j=$job_site&ec=0&b=$which_database");
}
break;
case "process":
$session = $_GET["s"];
$upload_dir = $_GET["d"];
$previous_cmd = $_GET["p"];
$job_site = $_GET["j"];
$error_cond = $_GET["ec"];
$which_database = $_GET["b"];
$total_files = 0;
$files_array = array();
$target_dir = $data_dir . $cookie_login1 . "/" . $job_site . "/";
# $dh = opendir ($upload_dir);
$dh = opendir ($target_dir);
while (($filename = readdir ($dh)) !== false)
{
$ext_pos = strrpos ($filename, ".");
$file_ext = "";
if ($ext_pos !== false)
{
$file_ext = substr ($filename, $ext_pos);
}
if ((substr ($filename, 0, strlen ($session) + 1) == $session . "_") && ($file_ext != ".done"))
{
++$total_files;
$files_array[] = $filename;
}
}
closedir ($dh);
--$total_files;
sort ($files_array);
$base_fname_pos = strpos ($files_array[0], "_");
$base_fname = substr ($files_array[0], $base_fname_pos + 1);
if (count ($files_array) > 0)
{
include "tmpl/header.tem.php";
include "tmpl/main-process.tem.php";
include "tmpl/footer.tem.php";
}
else
{
if ($previous_cmd == "do_upload")
{
header ("Location: index.php?cmd=process_text&s=$session&j=$job_site&ec=$error_cond&b=$which_database");
header ("URI: index.php?cmd=process_text&s=$session&j=$job_site&ec=$error_cond&b=$which_database");
}
if ($previous_cmd == "do_edit")
{
header ("Location: index.php?cmd=edit_commit&s=$session&j=$job_site&b=$which_database");
header ("URI: index.php?cmd=edit_commit&s=$session&j=$job_site&b=$which_database");
}
}
break;
case "process_text":
$session = $_GET["s"];
$job_site = $_GET["j"];
$error_cond = $_GET["ec"];
$which_database = $_GET["b"];
$total_files = 0;
$files_array = array();
$dh = opendir ($data_dir . $cookie_login1 . "/" . $job_site);
while (($filename = readdir ($dh)) !== false)
{
$ext_pos = strrpos ($filename, ".");
$file_ext = "";
if ($ext_pos !== false)
{
$file_ext = substr ($filename, $ext_pos);
}
if ((substr ($filename, 0, strlen ($session) + 3) == $session . "_t_") && ($file_ext == ".done"))
{
++$total_files;
$files_array[] = $filename;
}
}
closedir ($dh);
sort ($files_array);
if (count ($files_array) > 0) {
include "tmpl/header.tem.php";
include "tmpl/main-text.tem.php";
include "tmpl/footer.tem.php";
} else {
include "tmpl/header.tem.php";
print "
None of the uploaded files were in a supported image format. They were not added to the job site.
Please convert the images. to JPEG or TIFF and re-upload them.
\n";
print "Upload Images
\n";
include "tmpl/footer.tem.php";
}
break;
case "do_text":
$session = $_POST["session"];
$job_site = $_POST["job_site"];
$which_database = $_POST["b"];
$uploaded_files = array();
$total_uploads = $_POST["total_uploads"];
$total_text = 0;
for ($i = 1; $i < $total_uploads + 1; ++$i)
{
if ($_POST["notes_" . $i] != "")
{
++$total_text;
}
}
if ($total_text != $total_uploads)
{
foreach (array_keys ($_POST) as $i)
{
if (substr ($i, 0, 9) == "filename_")
{
$curr_file = $_POST[$i];
$uploaded_files[] = $curr_file;
}
}
sort ($uploaded_files);
$error_message = "You MUST provide a description for ALL images.";
include "tmpl/header.tem.php";
include "tmpl/main-text.tem.php";
include "tmpl/footer.tem.php";
exit;
}
for ($i = 1; $i < $total_uploads + 1; ++$i)
{
if ($_POST["filename_" . $i] != "")
{
$curr_image_filename = substr ($_POST["filename_" . $i], strlen ($session) + 3);
$curr_notes = $_POST["notes_" . $i];
$curr_fname = $data_dir . $cookie_login1 . "/" . $job_site . "/" . $session . "_" . $curr_image_filename;
$curr_thumb_fname = $data_dir . $cookie_login1 . "/" . $job_site . "/" . $session . "_t_" . $curr_image_filename;
$fin_fname = $data_dir . $cookie_login1 . "/" . $job_site . "/" . substr ($curr_image_filename, 0, strlen ($curr_image_filename) - 5);
$fin_thumb_fname = $data_dir . $cookie_login1 . "/" . $job_site . "/" . "t_" . substr ($curr_image_filename, 0, strlen ($curr_image_filename) - 5);
rename ($curr_fname, $fin_fname);
rename ($curr_thumb_fname, $fin_thumb_fname);
$upload_sql = "INSERT INTO sat_images VALUES(\"$cookie_login2\", \"" . substr ($curr_image_filename, 0, strlen ($curr_image_filename) - 5) . "\", \"$curr_notes\", \"\", \"$job_site\", NOW(), \"01\", \"0\")";
$res = MySQL_Query ($upload_sql);
}
}
include "tmpl/header.tem.php";
print "Text descriptions added to $total_uploads images.
\n";
print "
\n";
print "Main Menu\n";
include "tmpl/footer.tem.php";
break;
case "adjust":
$installer_email = $_COOKIE["satellite1"];
$adjust_installer_id = $_GET["u"];
$adjust_filename = $_GET["i"];
$adjust_site = $_GET["s"];
header ("Cache-control: must-revalidate");
include "tmpl/header.tem.php";
include "tmpl/main-adjust.tem.php";
include "tmpl/footer.tem.php";
break;
case "do_adjust":
$installer_email = $_COOKIE["satellite1"];
$adjust_installer_id = $_POST["u"];
$adjust_filename = $_POST["i"];
$adjust_site = $_POST["s"];
$max_width = 650;
$max_height = 500;
$adjust_sql = "SELECT * FROM sat_images WHERE installer_id='$adjust_installer_id' AND filename='$adjust_filename'";
$res = MySQL_Query ($adjust_sql);
$row = mysql_fetch_array ($res);
$org_file = $data_dir . "$installer_email/" . $adjust_site . "/" . $row["filename"];
$rotate_file = $data_dir . "$installer_email/" . $adjust_site . "/" . "r_" . $row["filename"];
$source = imagecreatefromjpeg($org_file);
$source_width = imagesx ($source);
$source_height = imagesy ($source);
if (($_POST["rotate_counter"] != "") || ($_POST["rotate_clock"] != ""))
{
$rotation = 0;
if ($_POST["rotate_counter"] != "")
{
$rotation = 90;
}
else
{
$rotation = -90;
}
$rotate = imagerotate($source, $rotation, 0);
}
if ($_POST["flip_horiz"] != "")
{
$rotate = imagecreatetruecolor($source_width, $source_height);
for ($i = 0; $i < $source_width; ++$i)
{
imagecopy ($rotate, $source, $i, 0, $source_width - $i - 1, 0, 1, $source_height);
}
}
if ($_POST["flip_vert"] != "")
{
$rotate = imagecreatetruecolor($source_width, $source_height);
for ($i = 0; $i < $source_height; ++$i)
{
imagecopy ($rotate, $source, 0, $i, 0, $source_height - $i - 1, $source_width, 1);
}
}
imagejpeg ($rotate, $rotate_file);
unlink ($org_file);
rename ($rotate_file, $org_file);
list ($image_width, $image_height, $image_type, $image_attr) = getimagesize ($org_file);
$scale_width = $image_width / $max_width;
$scale_height = $image_height / $max_height;
if ($scale_width > $scale_height)
{
$scale_factor = $scale_width;
}
else
{
$scale_factor = $scale_height;
}
$thumb_target_file = $data_dir . "$installer_email/" . $adjust_site . "/" . "t_" . $row["filename"];
$thumb_width = round ($image_width / $scale_factor);
$thumb_height = round ($image_height / $scale_factor);
$thumb = imagecreatetruecolor ($thumb_width, $thumb_height);
switch ($image_type)
{
case 1:
$src_image = imagecreatefromgif ($org_file);
break;
case 2:
default:
$src_image = imagecreatefromjpeg ($org_file);
break;
case 3:
$src_image = imagecreatefrompng ($org_file);
break;
}
imagecopyresampled ($thumb, $src_image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
switch ($image_type)
{
case 1:
imagegif ($thumb, $thumb_target_file);
break;
case 2:
default:
imagejpeg ($thumb, $thumb_target_file);
break;
case 3:
imagepng ($thumb, $thumb_target_file);
break;
}
header ("Cache-control: must-revalidate");
include "tmpl/header.tem.php";
include "tmpl/main-adjust.tem.php";
include "tmpl/footer.tem.php";
break;
case "jobsites":
include "tmpl/header.tem.php";
include "tmpl/main-jobsites.tem.php";
include "tmpl/footer.tem.php";
break;
case "add_site":
case "edit_site":
include "tmpl/header.tem.php";
include "tmpl/main-edit-jobsites.tem.php";
include "tmpl/footer.tem.php";
break;
case "do_jobsites_commit":
$job_site_installer = $_POST["site_installer"];
$installer_sql = "SELECT email, CONCAT(first_name, \" \", last_name) AS full_name FROM sat_installers WHERE installer_id='" . $_COOKIE["satellite1"] . "'";
$res = MySQL_Query ($installer_sql);
$row = mysql_fetch_array ($res);
$installer_name = $row["full_name"];
$installer_email = $row["email"];
$job_site_id = $_POST["site_id"];
$job_site_label = $_POST["site_label"];
$job_site_contact = $_POST["site_contact"];
$job_site_project = $_POST["site_project"];
$job_site_street = $_POST["site_street"];
$job_site_location = $_POST["site_location"];
$job_site_date_install = $_POST["site_date_install"];
if ($job_site_id == "")
{
$job_sql = "INSERT INTO sat_job_sites VALUES(\"\", \"$cookie_login2\", \"$job_site_label\", \"$job_site_contact\", \"$job_site_project\", \"$job_site_street\", \"$job_site_location\", \"$job_site_date_install\", \"1\")";
$res = MySQL_Query ($job_sql);
$new_job_site_id = mysql_insert_id ();
mkdir ($data_dir . $cookie_login1 . "/" . $new_job_site_id, 0777);
}
else
{
$job_sql = "UPDATE sat_job_sites SET label=\"$job_site_label\", contact=\"$job_site_contact\", project=\"$job_site_project\", street=\"$job_site_street\", location=\"$job_site_location\", date_install=\"$job_site_date_install\" WHERE job_sites_id='$job_site_id'";
$res = MySQL_Query ($job_sql);
$email_to = $admin_email;
$email_subject = "New Job Site Created";
$email_headers = "From: root@iprole.com";
$email_message = "A new job site was created by $installer_name ($installer_email).\n";
$email_message = $email_message . "\n";
$email_message = $email_message . "It has the following details:\n";
$email_message = $email_message . "\n";
$email_message = $email_message . "Job Site Name: $job_site_label\n";
$email_message = $email_message . "Job Site Contact: $job_site_contact\n";
$email_message = $email_message . "Job Site Project: $job_site_project\n";
$email_message = $email_message . "Job Site Street: $job_site_street\n";
$email_message = $email_message . "Job Site Location: $job_site_location\n";
$email_message = $email_message . "Date of Install: $job_site_date_install\n";
mail ($email_to, $email_subject, $email_message, $email_headers);
}
include "tmpl/header.tem.php";
print "Job site saved.
\n";
print "
\n";
# if ($email_message <> "")
# {
# print "DEBUG:
\n";
# print "During development, email is not being sent. If it was being sent, it would have the following details:
\n";
# print "To: $email_to
\n";
# print "Subject: $email_subject
\n";
# print "Headers: $email_headers
\n";
# print "Message: $email_message
\n";
# }
print "Job Site Main Menu
\n";
print "Main Menu\n";
include "tmpl/footer.tem.php";
break;
case "delete_site":
$job_site_id = $_GET["value"];
$del_dir = $data_dir . $cookie_login1 . "/" . $job_site_id;
$dh = opendir ($del_dir);
while (($filename = readdir ($dh)) !== false)
{
if (($filename != ".") && ($filename != ".."))
{
unlink ($del_dir . "/" . $filename);
}
}
closedir ($dh);
rmdir ($del_dir);
$site_sql = "DELETE FROM sat_images WHERE sites_id='$job_site_id'";
$res = MySQL_Query ($site_sql);
$site_sql = "DELETE FROM sat_job_sites WHERE job_sites_id='$job_site_id'";
$res = MySQL_Query ($site_sql);
# $job_sql = "DELETE FROM job_sites WHERE job_sites_id='$job_site_id'";
# $res = MySQL_Query ($job_sql);
include "tmpl/header.tem.php";
print "Job site deleted.
\n";
print "
\n";
print "Job Site Main Menu
\n";
print "Main Menu\n";
include "tmpl/footer.tem.php";
break;
case "view":
include "tmpl/header.tem.php";
include "tmpl/main-view.tem.php";
include "tmpl/footer.tem.php";
break;
case "view_images":
include "tmpl/header.tem.php";
include "tmpl/view-images.tem.php";
include "tmpl/footer.tem.php";
break;
case "edit":
include "tmpl/header.tem.php";
include "tmpl/main-edit.tem.php";
include "tmpl/footer.tem.php";
break;
case "edit_commit":
$org_site = $_GET["j"];
$session = $_GET["s"];
$which_database = $_GET["b"];
$del_dir = $data_dir . $cookie_login1 . "/" . $org_site;
$dh = opendir ($del_dir);
while (($filename = readdir ($dh)) !== false)
{
if (substr ($filename, 0, strlen ($session)) == $session)
{
# print "rename: $filename to get rid of $session
\n";
$old_filename = $del_dir . "/" . $filename;
$new_filename = $del_dir . "/" . substr ($filename, strlen ($session) + 1, strlen ($filename));
rename ($old_filename, $new_filename);
}
}
closedir ($dh);
include "tmpl/header.tem.php";
print "Changes saved.
";
print "
\n";
print "View Images for Job Site
\n";
print "Main Menu\n";
include "tmpl/footer.tem.php";
break;
# case "do_edit":
# $new_notes = $_POST["new_notes"];
# $new_sites = $_POST["sites"];
# $org_site = $_POST["s"];
#
# $abs_max_width = 2048;
# $abs_max_height = 1536;
#
# $max_width = 500;
# $max_height = 375;
#
# if ($_FILES["new_image"]["name"] != "")
# {
# $curr_value_sql = "SELECT reject_notes, single_page FROM images WHERE installer_id='$cookie_login2' AND filename='" . $_POST["i"] . "'";
# $res = MySQL_Query ($curr_value_sql_sql);
#
# unlink ($data_dir . $_COOKIE["satellite1"] . "/" . $org_site . "/" . $_POST["i"]);
#
# $delete_sql = "DELETE FROM images WHERE installer_id='$cookie_login2' AND filename='" . $_POST["i"] . "'";
# $res = MySQL_Query ($delete_sql);
# $row = mysql_fetch_array ($res);
#
# $curr_file = $_FILES["new_image"]["name"];
# $target_file = $data_dir . $_COOKIE["satellite1"] . "/" . $org_site . "/" . $curr_file;
#
# if (move_uploaded_file($_FILES["new_image"]["tmp_name"], $target_file))
# {
# $upload_sql = "INSERT INTO images VALUES(\"$cookie_login2\", \"$curr_file\", \"$new_notes\", \"" . $row["reject_notes"] . "\", \"$new_sites\", NOW(), \"01\", \"" . $row["single_page"] . "\")";
# $res = MySQL_Query ($upload_sql);
# chmod("$target_file", 0644);
#
# list ($image_width, $image_height, $image_type, $image_attr) = getimagesize ($target_file);
#
# # Check if image is greater than 3MP.
# $org_img_res = $image_width * $image_height;
# $org_max_res = $abs_max_width * $abs_max_height;
#
# if ($org_img_res > $org_max_res)
# {
# $scale_width = $image_width / $abs_max_width;
# $scale_height = $image_height / $abs_max_height;
#
# if ($scale_width > $scale_height)
# {
# $scale_factor = $scale_width;
# }
# else
# {
# $scale_factor = $scale_height;
# }
#
# $new_target_file = $data_dir . $cookie_login1 . "/" . $org_site . "/" . "n_" . $curr_file;
#
# $new_width = round ($image_width / $scale_factor);
# $new_height = round ($image_height / $scale_factor);
#
# $new_img = imagecreatetruecolor ($new_width, $new_height);
#
# switch ($image_type)
# {
# case 1:
# $src_image = imagecreatefromgif ($target_file);
# break;
# case 2:
# default:
# $src_image = imagecreatefromjpeg ($target_file);
# break;
# case 3:
# $src_image = imagecreatefrompng ($target_file);
# break;
# }
#
# imagecopyresampled ($new_img, $src_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
#
# switch ($image_type)
# {
# case 1:
# imagegif ($new_img, $new_target_file);
# break;
# case 2:
# default:
# imagejpeg ($new_img, $new_target_file);
# break;
# case 3:
# imagepng ($new_img, $new_target_file);
# break;
# }
#
# unlink ($target_file);
# rename ($new_target_file, $target_file);
# }
#
# $scale_width = $image_width / $max_width;
# $scale_height = $image_height / $max_height;
#
# if ($scale_width > $scale_height)
# {
# $scale_factor = $scale_width;
# }
# else
# {
# $scale_factor = $scale_height;
# }
#
# $thumb_target_file = $data_dir . $_COOKIE["satellite1"] . "/" . $org_site . "/" . "t_" . $curr_file;
#
# $thumb_width = round ($image_width / $scale_factor);
# $thumb_height = round ($image_height / $scale_factor);
#
# $thumb = imagecreatetruecolor ($thumb_width, $thumb_height);
#
# switch ($image_type)
# {
# case 1:
# $src_image = imagecreatefromgif ($target_file);
# break;
# case 2:
# default:
# $src_image = imagecreatefromjpeg ($target_file);
# break;
# case 3:
# $src_image = imagecreatefrompng ($target_file);
# break;
# }
#
# imagecopyresampled ($thumb, $src_image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
#
# switch ($image_type)
# {
# case 1:
# imagegif ($thumb, $thumb_target_file);
# break;
# case 2:
# default:
# imagejpeg ($thumb, $thumb_target_file);
# break;
# case 3:
# imagepng ($thumb, $thumb_target_file);
# break;
# }
# }
# else
# {
# print "There was a problem uploading your new image.";
# }
# }
# else
# {
# $upload_sql = "UPDATE images SET notes=\"$new_notes\", sites_id=\"$new_sites\", uploaded=NOW() WHERE installer_id='$cookie_login2' AND filename='" . $_POST["i"] . "' AND sites_id='$org_site'";
# $res = MySQL_Query ($upload_sql);
#
##print "us: $upload_sql
\n";
# }
#
# include "tmpl/header.tem.php";
# print "Changes saved.
";
# print "
\n";
# print "View Images for Job Site
\n";
# print "Main Menu\n";
# include "tmpl/footer.tem.php";
# break;
case "delete":
$delete_installer_id = $_GET["u"];
$delete_filename = $_GET["i"];
$delete_site = $_GET["s"];
$del_dir = $data_dir . $cookie_login1 . "/" . $delete_site;
$delete_sql = "SELECT filename FROM sat_images WHERE installer_id='$delete_installer_id' AND filename='$delete_filename' AND sites_id='$delete_site'";
$res = MySQL_Query ($delete_sql);
$row = mysql_fetch_array ($res);
unlink ($del_dir . "/" . $row["filename"]);
unlink ($del_dir . "/t_" . $row["filename"]);
$delete_sql = "DELETE FROM sat_images WHERE installer_id='$delete_installer_id' AND filename='$delete_filename' AND sites_id='$delete_site'";
$res = MySQL_Query ($delete_sql);
include "tmpl/header.tem.php";
print "Image deleted.
";
print "
\n";
print "Images for Job Site
\n";
print "Main Menu\n";
include "tmpl/footer.tem.php";
break;
case "submit_job":
$job_site_id = $_GET["s"];
$job_sql = "UPDATE sat_job_sites SET status='2' WHERE job_sites_id='$job_site_id'";
$res = MySQL_Query ($job_sql);
$job_sql = "SELECT * FROM sat_job_sites WHERE job_sites_id='$job_site_id'";
$res = MySQL_Query ($job_sql);
$row = mysql_fetch_array ($res);
$job_site_name = $row["label"];
$installer_sql = "SELECT * FROM sat_installers WHERE installer_id='$cookie_login2'";
$res = MySQL_Query ($installer_sql);
$row = mysql_fetch_array ($res);
$installer_name = $row["first_name"] . " " . $row["last_name"];
$installer_email = $row["email"];
$email_to = $admin_email;
$email_subject = "Images Submitted for $job_site_name";
$email_headers = "From: root@iprole.com";
$email_message = "$installer_name ($installer_email) has submitted images for $job_site_name.\n";
$email_message = $email_message . "\n";
$email_message = $email_message . "Please login to review and approve/reject the images.\n";
$email_message = $email_message . "\n";
mail ($email_to, $email_subject, $email_message, $email_headers);
# print "DEBUG:
\n";
# print "During development, email is not being sent. If it was being sent, it would have the following details:
\n";
# print "To: $email_to
\n";
# print "Subject: $email_subject
\n";
# print "Headers: $email_headers
\n";
# print "Message: $email_message
\n";
# print "
\n";
# print "
\n";
include "tmpl/header.tem.php";
include "tmpl/main-submit.tem.php";
include "tmpl/footer.tem.php";
break;
case "profile":
include "tmpl/header.tem.php";
include "tmpl/main-profile.tem.php";
include "tmpl/footer.tem.php";
break;
case "profile_commit":
$curr_installer_id = $_COOKIE["satellite2"];
$new_first_name = $_POST["new_first_name"];
$new_last_name = $_POST["new_last_name"];
$new_email = $_POST["new_email"];
$new_password = $_POST["new_password"];
$profile_sql = "SELECT email FROM sat_installers WHERE installer_id='$curr_installer_id'";
$res = MySQL_Query ($profile_sql);
$row = mysql_fetch_array ($res);
$org_email = $row["email"];
$profile_sql = "UPDATE sat_installers SET first_name='$new_first_name', last_name='$new_last_name', email='$new_email', password='$new_password' WHERE installer_id='$curr_installer_id'";
$res = MySQL_Query ($profile_sql);
if ($new_email != $org_email) {
rename ($data_dir . "$org_email", $data_dir . "$new_email");
}
include "tmpl/header.tem.php";
print "Profile updated.
\n";
print "
\n";
print "Main Menu
\n";
include "tmpl/footer.tem.php";
break;
case "":
default:
include "tmpl/header.tem.php";
include "tmpl/main-index.tem.php";
include "tmpl/footer.tem.php";
break;
}
$db->disconnectMySQL();
?>