function webController($path, $request) { global $smarty, $dao; list($reqPath, $queryString) = explode('?', $path); $pathParts = explode('/', substr($reqPath, 1)); list($action) = $pathParts; session_start(); $authnStatus = checkAuthn(); if (isLoggedIn()) { $smarty->assign("loggedIn", true); $smarty->assign("loginEmail", $_SESSION["loginEmail"]); } else { $smarty->assign("loggedIn", false); } if (checkAuthz($action) && $authnStatus != AUTHN_FAILED) { // user is authorized $loginId = $_SESSION["loginId"]; if ($loginId) { $loginUser = $dao->getUser($loginId); if ($loginUser["privileges"] == "admin") { $loginHasAdmin = true; } else { $loginHasAdmin = false; } } else { $loginhasAdmin = false; } $smarty->assign("loginHasAdmin", $loginHasAdmin); switch ($action) { case 'main': $smarty->display('main.tpl'); break; case '404': $smarty->display('404.tpl'); break; case 'maps': $projects = $dao->getProjects(); $smarty->assign("projects", $projects); $smarty->display('maps.tpl'); break; case 'login': $smarty->display('header.tpl'); $smarty->display('login.tpl'); $smarty->display('footer.tpl'); break; case 'login.do': if ($_POST["loginDestination"]) { $destination = "../web" . $_POST["loginDestination"]; } else { $destination = "main"; } header("Location: {$destination}"); break; case 'logout': session_destroy(); header("Location: main"); break; case 'register': $smarty->display('register.tpl'); break; case 'register.do': extract($request); if (!$email) { errorMessage("Email address is required."); } if (!$firstName) { errorMessage("First name is required."); } if (!$lastName) { errorMessage("Last name is required."); } if (strlen($pass1) < 6) { errorMessage("Password must be 6 characters or longer."); } if ($pass1 != $pass2) { errorMessage("Password and password confirmation do not match."); } $newUser = array($email, $firstName, $lastName, $pass1); $result = $dao->registerUser($newUser); if ($result === REGISTRATION_EMAILEXISTS) { errorMessage("That email address already exists."); } $_SESSION["loggedIn"] = true; $_SESSION["loginId"] = $result[0]; $_SESSION["loginEmail"] = $email; header("Location: main"); break; case 'projects': // print_r($_SESSION); $projects = $dao->getProjects(); $smarty->assign("projects", $projects); $smarty->display("projects.tpl"); break; case 'expeditions': $projectId = $request["project_id"]; $expeditions = $dao->getExpeditions($projectId); $smarty->assign("expeditions", $expeditions); $smarty->display("expeditions.tpl"); break; case 'expedition.tracker': $expeditionId = $request["id"]; $expeditionPoints = $dao->getExpeditionPoints($expeditionId); $smarty->assign("expeditionPoints", $expeditionPoints); $smarty->display("expedition_tracker.tpl"); break; case 'project.new': $smarty->display("new_project.tpl"); break; case 'project.new.do': $name = $request["name"]; $description = $request["description"]; $dao->newProject($name, $description); header("Location: projects"); break; case 'project.mapdisplay': list($queryType, $queryValue) = explode("=", $queryString); $id = $queryValue; $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->getFinds($id); $smarty->assign("finds", addslashes(json_encode($finds))); $smarty->display("project_mapdisplay.tpl"); break; case 'project.display': list($queryType, $queryValue) = explode("=", $queryString); $id = $queryValue; $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->getFinds($id); $smarty->assign("finds", $finds); $smarty->display("project_display.tpl"); break; case 'find.display': list($queryType, $queryValue) = explode("=", $queryString); $id = $queryValue; $find = $dao->getFind($id); // $find = $dao->getFind($find["barcode_id"]); $project_id = $find["project_id"]; $project = $dao->getProject($project_id); // $smarty->assign("images",$find["images"]); // $smarty->assign("videos",$find["videos"]); // $smarty->assign("audioClips",$find["audioClips"]); $smarty->assign("project", $project); $smarty->assign("find", $find); $smarty->display("find_display.tpl"); break; case 'settings': $userId = $_SESSION["loginId"]; $devices = $dao->getDevicesByUser($userId); $smarty->assign("devices", $devices); $smarty->display("settings/settings.tpl"); break; case 'settings.registerDevice': $authKey = genAuthKey(); $userId = $_SESSION["loginId"]; $result = $dao->registerDevicePending($userId, $authKey); $server = SERVER_BASE_URI; $email = $_SESSION["loginEmail"]; $data = array("server" => $server, "authKey" => $authKey); $smarty->assign("baseUrl", $server); $smarty->assign("authKey", $authKey); $smarty->assign("data", urlencode(json_encode($data))); $smarty->display("settings/registerDevice.tpl"); break; case 'settings.registerDevice.do': $imei = $request["imei"]; $deviceName = $request["deviceName"]; $result = $dao->changeDeviceNickname($imei, $deviceName); header("Location: settings"); break; case 'removeDevice.do': $imei = $request["imei"]; $dao->removeDevice($imei); header("Location: settings"); break; case 'purge': echo "Purging pending device registrations..."; $dao->purgePendingDevices(); break; case 'displayPicture': $id = $request["id"]; $image = $dao->getPicture($id); $size = $request["size"]; if ($size == "thumb") { $data = $image["data_thumb"]; } else { $data = $image["data_full"]; } $mimeType = $image["mime_type"]; header("Content-Type: {$mimeType}"); echo $data; break; case 'displayVideo': $id = $request["id"]; $video = $dao->getVideo($id); $video_name = $video["data_path"]; $video_path = "uploads/{$video_name}"; $fp_v = fopen($video_path, 'r'); $video_data = fread($fp_v, filesize($video_path)); header("Content-type: video/3gp"); echo $video_data; break; case 'displayAudio': $id = $request["id"]; $audio = $dao->getAudio($id); $audio_name = $audio["data_path"]; $audio_path = "uploads/{$audio_name}"; $fp_v = fopen($audio_path, 'r'); $audio_data = fread($fp_v, filesize($audio_path)); header("Content-type: audio/3gp"); print $audio_data; break; case 'admin': $smarty->display("admin/admin.tpl"); break; case 'qrcode': $oldwd = getcwd(); chdir("3rd"); require_once "qr_img.php"; chdir($oldwd); break; case 'customPosit.list': $project_id = $request["project_id"]; //$instances = $dao->getInstancesForProject($project_id); //$smarty->assign("instances", $instances); $smarty->assign("project_id", $project_id); $smarty->display("custom_posit_list.tpl"); break; case 'customPosit.download': $project_id = $request["project_id"]; //hack to get just project_id because php doesn't support multiple constructors.. $data = array(null, $project_id, null, null, null); $posit = new CustomPosit($data); $posit->download(); break; case 'customPosit': $userId = $_SESSION["loginId"]; $devices = $dao->getDevicesByUser($userId); $smarty->assign("devices", $devices); $project_id = $request["project_id"]; $smarty->assign("project_id", $project_id); $smarty->display("custom_posit.tpl"); break; case 'customPosit.create.do': $name = $request["name"]; $project_id = $request["project_id"]; $description = $request["description"]; $sync_on = $request["sync_on"]; $device_id = $request["device_id"]; echo $project_id; $data = array($name, $project_id, $description, $sync_on, $device_id); if ($name == null || $project_id == null) { $smarty->assign("name", $name); $smarty->assign("project_id", $project_id); $smarty->assign("description", $description); $smarty->assign("device_id", $device_id); $smarty->display("custom_posit.tpl"); } $posit = new CustomPosit($data); $posit->build(); break; default: header("Location: main"); } } else { if ($authnStatus == AUTHN_OK) { // user is authenticated but not authorized } else { if ($authnStatus == AUTHN_FAILED) { // user failed authentication' $smarty->display("header.tpl"); $smarty->assign("errMsg", "Login failed."); $smarty->display("login.tpl"); $smarty->display("footer.tpl"); } else { // user is not authenticated $smarty->display("header.tpl"); $smarty->assign("destination", $path); $smarty->display("login.tpl"); $smarty->display("footer.tpl"); } } } }
/** * the main apiController function that outputs json_encoded results * @param $path * @param $request * @param $files */ function apiController($path, $request, $files = null) { global $dao, $smarty; list($reqPath, $queryString) = explode('?', $path); $pathParts = explode('/', substr($reqPath, 1)); list($action) = $pathParts; Log::getInstance()->log("Reached server"); Log::getInstance()->log("{$path} , {$request}"); if ($action != "addExpeditionPoint" && $action != "getDeviceByAuthKey") { $log = Log::getInstance(); $log->log("{$action}"); $log->log("{$path}, {$request}"); } $authKey = $request["authKey"]; if ($action != "isreachable" && $action != "login" && $action != "registerUser" && $action != "registerDevice" && $action != "getPendingDeviceStatus" && !$authKey) { $response = array("errorCode" => ERR_AUTHKEY_MISSING, "errorMessage" => "You must provide an authentication key with each request."); echo json_encode($response); die; } if ($action != isreachable && $action != "login" && $action != "registerUser") { $device = $dao->getDeviceByAuthKey($authKey); if ($action != "registerDevice" && $action != "getPendingDeviceStatus" && !$device) { $response = errorResponseCode(ERR_AUTHKEY_INVALID, "Invalid authentication key."); echo json_encode($response); die; } $deviceUserId = $device["user_id"]; $deviceIdentifier = $device["imei"]; } switch ($action) { case 'isreachable': jsonMessage(AUTHN_OK, "The server is reachable"); break; case 'login': extract($request); Log::getInstance()->log("Login = {$request} email={$email} imei={$imei}"); if (!$email) { jsonError(ERR_EMAIL_MISSING, "Email Address is required"); } else { if (!validate_email_address($email)) { jsonError(ERR_EMAIL_INVALID, "Email Address is invalid"); } } if (!$password) { jsonError(ERR_PASSWORD_MISSING, "Password is required"); } // NOTE: Tablets don't have imei. So this will only work for phones. // if (!$imei){ // jsonError(ERR_IMEI_MISSING, "IMEI Code is required"); // } if ($login = $dao->checkLogin($email, $password)) { $authKey = genAuthKey(); $userId = $login["id"]; if ($dao->registerDevicePending($userId, $authKey)) { jsonMessage(AUTHN_OK, $authKey); } else { jsonError(ERR_SERVER, "Authentication Key cannot be generated"); } } else { jsonError(AUTHN_FAILED, "Authentication failed. Please Check email address or password."); } break; case 'registerUser': extract($request); if (!$email) { jsonError(ERR_EMAIL_MISSING, "Email Address is required"); } else { if (!validate_email_address($email)) { jsonError(ERR_EMAIL_INVALID, "Email Address is invalid"); } } if (!$firstname) { jsonError(ERR_FIRSTNAME_MISSING, "Firstname is required"); } if (!$lastname) { jsonError(ERR_LASTNAME_MISSING, "LastName is required"); } if (strlen($password1) < 6) { jsonError(ERR_PASSWORD1_INVALID, "Password must be 6 characters or longer"); } if ($password1 != $password2) { jsonError(ERR_PASSWORD_UNMATCHED, "Passwords must match"); } $newUser = array($email, $firstname, $lastname, $password1); $result = $dao->registerUser($newUser); if ($result === REGISTRATION_EMAILEXISTS) { jsonError(ERR_EMAIL_INVALID, "Email already exists"); } $smarty->assign('link', SERVER_BASE_URI . "/web/verifyEmail?email={$email}"); sendEmail($email, "email verification", $smarty->fetch("emails/new_user.tpl")); jsonMessage(AUTHN_OK, "Registration Successful"); break; case 'getDeltaFindsIds': echo $dao->getDeltaFindsIds($authKey, $request["projectId"]); break; case 'recordSync': $projectId = -1; if ($request["projectId"]) { $projectId = (int) $request["projectId"]; } echo $dao->recordSync($request["imei"], $authKey, $projectId); //echo $dao->recordSync($deviceIdentifier, $authKey); break; case 'registerDevice': $imei = $request["imei"]; $name = null; if (strstr($authKey, "sb_")) { $result = $dao->addSandboxDevice($authKey, $imei); } else { $result = $dao->confirmDevice($authKey, $imei, $name); } echo json_encode($result); break; case 'addExpedition': echo $dao->addExpedition($request["projectId"]); break; case 'addExpeditionPoint': echo $request["expedition"] . ","; echo $dao->addExpeditionPoint($request["expedition"], $request["latitude"], $request["longitude"], $request["altitude"], $request["swath"], $request["time"]); break; case 'getPendingDeviceStatus': $device = $dao->getDeviceByAuthKey($authKey); if ($device["status"] == "ok") { echo json_encode($device); } else { echo json_encode(false); } break; case 'listOpenProjects': $result = $dao->getProjects(PROJECTS_OPEN); echo json_encode($result); break; case 'listMyProjects': $result = $dao->getUserProjects($deviceUserId); echo json_encode($result); break; case 'newProject': extract($request); if (!$name) { jsonError(ERR_NAME_INVALID, "Project name is invalid."); } $result = $dao->newProject($name, $description, $deviceUserId); if (is_string($result)) { jsonMessage(PROJ_CREATE_SUCCESS, "Project created successfully."); } else { jsonError(PROJ_CREATE_FAIL, "Project creation failed."); } break; case 'projectExists': if ($request["projectId"]) { echo $dao->projectExists($request["projectId"]); } break; case 'listFinds': echo json_encode($dao->getFinds($request["project_id"])); break; case 'getFind': $result = $dao->getFind($request["guid"]); echo json_encode($result); break; case 'deleteFind': echo $dao->deleteFind($request["id"]); break; case 'deleteProject': $dao->deleteProject($request["projectId"]); break; case 'deleteAllFinds': $dao->deleteAllFinds($request["projectId"]); break; case 'createFind': echo $dao->createFind($authKey, $request["imei"], $request["guid"], $request["project_id"], $request["name"], $request["description"], $request["latitude"], $request["longitude"], $request["revision"], $request["data"]); break; case 'updateFind': echo $dao->updateFind($authKey, $request["imei"], $request["guid"], $request["project_id"], $request["name"], $request["description"], $request["revision"], $request["data"], $request["latitude"], $request["longitude"]); break; case 'attachPicture': $imagedata = base64_decode($request["data_full"]); $imagethumbdata = base64_decode($request["data_thumbnail"]); $result = $dao->addPictureToFind($request["imei"], $request["guid"], $request["identifier"], $request["project_id"], $request["mime_type"], $request["timestamp"], $imagedata, $imagethumbdata, $authKey); echo json_encode($result); break; case 'attachVideo': $video_data = $files['file']['tmp_name']; $video_type = $request["mimeType"]; $video_name = str_replace(' ', '_', $files["file"]["name"]); move_uploaded_file($video_data, "uploads/{$video_name}"); $result = $dao->addVideoToFind($request['id'], $request["findId"], $video_type, $video_name); return $result; break; case 'attachAudio': $audio_data = $files['file']['tmp_name']; $audio_type = $request["mimeType"]; $audio_name = str_replace(' ', '_', $files["file"]["name"]); move_uploaded_file($audio_data, "uploads/{$audio_name}"); $result = $dao->addAudioClipToFind($request['id'], $request["findId"], $audio_type, $audio_name); return $result; break; case 'removePicture': $dao->deletePictureFromFind($request["id"]); break; case 'removeVideo': $dao->deleteVideoFromFind($request["id"]); break; case 'removeAudioClip': $dao->deleteAudioClipFromFind($request["id"]); break; case 'deleteAllPictures': $dao->deleteImages($request["findId"]); break; case 'deleteAllVideos': $dao->deleteVideos($request["findId"]); break; case 'deleteAllAudioClips': $dao->deleteAudioClips($request["findId"]); break; case 'getPicture': $picture = $dao->getPicture($request["id"]); $imageEncoded = base64_encode($picture["data_full"]); $imageThumbEncoded = base64_encode($picture["data_thumb"]); $pictureEncoded = $picture; if ($imageEncoded != "") { $pictureEncoded["data_full"] = $imageEncoded; } if ($imageThumbEncoded != "") { $pictureEncoded["data_thumb"] = $imageThumbEncoded; } if (count($pictureEncoded) > 0) { echo json_encode($pictureEncoded); } else { echo "false"; } break; case 'getPicturesByFind': $pictures = $dao->getPicturesByFind($request["guid"]); $result = array(); foreach ($pictures as $pic) { $imageEncoded = base64_encode($pic["data_full"]); $imageThumbEncoded = base64_encode($pic["data_thumb"]); $pictureEncoded = $pic; if ($imageEncoded != "") { $pictureEncoded["data_full"] = $imageEncoded; } if ($imageThumbEncoded != "") { $pictureEncoded["data_thumb"] = $imageThumbEncoded; } if (count($pictureEncoded) > 0) { $result[] = $pictureEncoded; } } if (count($result) > 0) { echo json_encode($result); } else { echo "false"; } break; case 'getVideo': $video = $dao->getVideo($request["id"]); $video_name = $video["data_path"]; $video_path = "uploads/{$video_name}"; $fp_v = fopen($video_path, 'r'); $video_data = fread($fp_v, filesize($video_path)); $videoEncoded = base64_encode($video_data); $clipEncoded = $video; $clipEncoded["data_full"] = $videoEncoded; echo json_encode($clipEncoded); break; case 'getAudio': $audio = $dao->getAudioClip($request["id"]); $audio_name = $audio["data_path"]; $audio_path = "uploads/{$audio_name}"; $fp_v = fopen($audio_path, 'r'); $audio_data = fread($fp_v, filesize($audio_path)); $audioEncoded = base64_encode($audio_data); $clipEncoded = $audio; $clipEncoded["data_full"] = $audioEncoded; echo json_encode($clipEncoded); break; case 'searchFinds': $search_value = $request['search_value']; $project_id = $request['project_id']; $result = $dao->searchFinds($search_value, $project_id); echo json_encode($result); break; case 'execCommand': $command = $request['command']; echo $dao->execCommand($command); break; default: break; } }
function webController($path, $request) { global $smarty, $dao, $error; list($reqPath, $queryString) = explode('?', $path); $pathParts = explode('/', substr($reqPath, 1)); list($action) = $pathParts; // Log::getInstance()->log("Reached server"); Log::getInstance()->log("{$path} , {$request}"); session_start(); $authnStatus = checkAuthn(); if (isLoggedIn()) { $smarty->assign("loggedIn", true); $smarty->assign("loginEmail", $_SESSION["loginEmail"]); } else { $smarty->assign("loggedIn", false); } if (checkAuthz($action) && $authnStatus != AUTHN_FAILED) { // user is authorized $loginId = $_SESSION["loginId"]; if ($loginId) { $loginUser = $dao->getUser($loginId); if ($loginUser["privileges"] == "admin") { $loginHasAdmin = true; } else { $loginHasAdmin = false; } } else { $loginhasAdmin = false; } $smarty->assign("loginHasAdmin", $loginHasAdmin); switch ($action) { case 'formbuilder.iframe': $smarty->display('build.tpl'); break; case 'formbuilder': $smarty->display('formbuilder.tpl'); break; case 'main': $smarty->display('main.tpl'); break; case 'build': $smarty->display('build.tpl'); break; case '404': $smarty->display('404.tpl'); break; case 'maps': $projects = $dao->getProjects(); $smarty->assign("projects", $projects); $smarty->display('maps.tpl'); break; case 'login': $smarty->display('header.tpl'); $smarty->display('login.tpl'); $smarty->display('footer.tpl'); break; case 'login.do': if ($_POST["loginDestination"]) { $destination = "../web" . $_POST["loginDestination"]; } else { $destination = "main"; } header("Location: {$destination}"); break; case 'logout': session_destroy(); header("Location: main"); break; case 'register': $smarty->display('register.tpl'); break; case 'register.do': extract($request); if (!$email) { errorMessage("Email address is required."); } if (!$firstName) { errorMessage("First name is required."); } if (!$lastName) { errorMessage("Last name is required."); } if (strlen($pass1) < 6) { errorMessage("Password must be 6 characters or longer."); } if ($pass1 != $pass2) { errorMessage("Password and password confirmation do not match."); } $newUser = array($email, $firstName, $lastName, $pass1); $result = $dao->registerUser($newUser); if ($result === REGISTRATION_EMAILEXISTS) { errorMessage("That email address already exists."); } $_SESSION["loggedIn"] = true; $_SESSION["loginId"] = $result[0]; $_SESSION["loginEmail"] = $email; header("Location: main"); break; case 'admin.logs': //var_dump($request); $pageNum = $request["page"]; if (!$request["page"]) { $pageNum = 1; } $numPages = $dao->numLogPages(); $numArray = range(1, $numPages); $logs = $dao->getLogs($pageNum); $smarty->assign("numPages", $numPages); $smarty->assign("pageNum", $pageNum); $smarty->assign("numArray", $numArray); $smarty->assign("logs", $logs); $smarty->display("logs.tpl"); break; case 'projects': $loginId = $_SESSION["loginId"]; $projects = $dao->getUserProjects($loginId); $smarty->assign("projects", $projects); $smarty->display("projects.tpl"); break; case 'expeditions': $projectId = $request["project_id"]; $expeditions = $dao->getExpeditions($projectId); $smarty->assign("expeditions", $expeditions); $smarty->display("expeditions.tpl"); break; case 'expedition.tracker': $expeditionId = $request["id"]; $expeditionPoints = $dao->getExpeditionPoints($expeditionId); $smarty->assign("expeditionPoints", $expeditionPoints); $smarty->display("expedition_tracker.tpl"); break; case 'project.new': $smarty->assign("error", $_SESSION["error"]); $_SESSION["error"] = ""; $smarty->display("new_project.tpl"); break; case 'project.new.do': $name = $request["name"]; $description = $request["description"]; $loginId = $_SESSION["loginId"]; if ($name == "") { $_SESSION["error"] = "Project name must be entered."; header("Location: project.new"); break; } else { if (!validate_project_name($name)) { $_SESSION["error"] = "project name invalid."; header("Location: project.new"); break; } } if ($description != "") { $description = $description = strip_tags($description, "<b>"); } $dao->newProject($name, $description, $loginId); header("Location: projects"); break; case 'project.share': $loginId = $_SESSION["loginId"]; $projects = $dao->getOwnerProjects($loginId); $smarty->assign("error", $_SESSION["error"]); $_SESSION["error"] = ""; $smarty->assign("projects", $projects); $smarty->display("share_project.tpl"); break; case 'project.share.do': $loginId = $_SESSION["loginId"]; if (!$request["email"]) { $_SESSION["error"] = "email required"; header("Location: project.share"); break; } else { if ($request["email"] == "") { $_SESSION["error"] = "email required"; header("Location: project.share"); break; } } if ($userId = $dao->getUserId($request["email"])) { $error = "Username doesn't exist"; header("Location: project.share"); } $projectId = $request["projectId"]; //print_r("projectid: ".$projectId."userId:".$userId); $projects = $dao->shareProject($loginId, $userId, $projectId); header("Location: projects"); break; case 'project.delete': $project_id = $request["id"]; $project = $dao->getProject($project_id); $smarty->assign("project", $project); $smarty->display("delete_project.tpl"); break; case 'find.delete': $find_id = $request["id"]; $find = $dao->getFind($find_id); $smarty->assign("find", $find); $smarty->display("delete_find.tpl"); break; case 'project.delete.do': $project_id = $request["id"]; $dao->deleteProject($project_id); header("Location: projects"); break; case 'find.delete.do': $find_id = $request["id"]; $find = $dao->getFind($find_id); $location = "project.display?id=" . $find["project_id"]; $dao->deleteFind($find_id); header("Location: " . $location); //THIS LINE WILL PROBABLY NEED TO BE CHNANGED TO SPECIFY THE PROJECT ID... //THIS LINE WILL PROBABLY NEED TO BE CHNANGED TO SPECIFY THE PROJECT ID... case 'project.showMap': $project_id = $request["id"]; $project = $dao->getProject($project_id); $smarty->assign("project", $project); $finds = $dao->getFinds($project_id); $expeditions = $dao->getExpeditions($project_id); $expedition_points = array(); $expeditionKeys = array(); //print_r($expeditions); foreach ($expeditions as $k => $expedition) { $temp_points = $dao->getExpeditionPoints($expedition['id']); if (count($temp_points) > 1) { $expedition_points[$k] = $temp_points; $expeditionKeys[$k] = $expedition['id']; } else { unset($expeditions[$k]); } /* echo "ACCEPTING expedition {$expedition['id']}:\n"; print_r($temp_points); echo "\n\n"; } else { echo "REJECTING expedition {$expedition['id']}:\n"; print_r($temp_points); echo "\n\n"; */ } // print_r($expeditions); if (count($expeditions) == 0 && count($finds) != 0) { $smarty->assign("expCheck", 0); $smarty->assign("findCheck", 1); $smarty->assign("finds", addslashes(json_encode($finds))); $smarty->assign("expeds", json_encode($expeditionKeys)); $smarty->assign("expeditions", $expeditions); $smarty->assign("expedition_points", json_encode($expedition_points)); $smarty->assign("expedition_points_decode", $expedition_points); $extremes = $dao->getFindExtremes($project_id); $smarty->assign('extremes', $extremes); $geocenter = $dao->getGeocenter($extremes); $smarty->assign('geocenter', $geocenter); $colors = array("ff0000", "ff8800", "ffff00", "99ff00", "00ff00", "337766", "0000ff", "9955ff", "6600bb", "ff0088"); $smarty->assign('colors', json_encode($colors)); $smarty->assign('colors_decode', $colors); $smarty->display("project_dualdisplay_test.tpl"); } if (count($finds) == 0 && count($expeditions) != 0) { $smarty->assign("expCheck", 1); $smarty->assign("findCheck", 0); $smarty->assign("finds", addslashes(json_encode($finds))); $smarty->assign("expeds", json_encode($expeditionKeys)); $smarty->assign("expeditions", $expeditions); $smarty->assign("expedition_points", json_encode($expedition_points)); $smarty->assign("expedition_points_decode", $expedition_points); $extremes = $dao->getExpExtremes($expeditions); $smarty->assign('extremes', $extremes); $geocenter = $dao->getGeocenter($extremes); $smarty->assign('geocenter', $geocenter); $colors = array("ff0000", "ff8800", "ffff00", "99ff00", "00ff00", "337766", "0000ff", "9955ff", "6600bb", "ff0088"); $smarty->assign('colors', json_encode($colors)); $smarty->assign('colors_decode', $colors); $smarty->display("project_dualdisplay_test.tpl"); } if (count($finds) == 0 && count($expeditions) == 0) { $smarty->display("empty_project.tpl"); } if (count($finds) != 0 && count($expeditions) != 0) { $smarty->assign("expCheck", 1); $smarty->assign("findCheck", 1); $smarty->assign("finds", addslashes(json_encode($finds))); $smarty->assign("expeds", json_encode($expeditionKeys)); $smarty->assign("expeditions", $expeditions); $smarty->assign("expedition_points", json_encode($expedition_points)); $smarty->assign("expedition_points_decode", $expedition_points); $find_extremes = $dao->getFindExtremes($project_id); $exp_extremes = $dao->getExpExtremes($expeditions); $extremes = $dao->getDualExtremes($exp_extremes, $find_extremes); $smarty->assign('extremes', $extremes); $geocenter = $dao->getGeocenter($extremes); $smarty->assign('geocenter', $geocenter); $colors = array("ff0000", "ff8800", "ffff00", "99ff00", "00ff00", "337766", "0000ff", "9955ff", "6600bb", "ff0088"); $smarty->assign('colors', json_encode($colors)); $smarty->assign('colors_decode', $colors); $smarty->display("project_dualdisplay_test.tpl"); } break; case 'project.display': list($queryType, $queryValue) = explode("=", $queryString); $id = $queryValue; $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->getFinds($id); $smarty->assign("finds", $finds); $smarty->display("project_display.tpl"); break; case 'advanced.search': list($queryID, $querySearch) = explode("&", $queryString); list($queryType, $queryValue) = explode("=", $queryID); list($querySearchType, $querySearchFor) = explode("=", $querySearch); $id = $queryValue; $searchFor = str_replace("+", " ", $querySearchFor); $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->searchForFinds($id, $searchFor); $smarty->assign("finds", $finds); $smarty->assign("searchFor", $searchFor); $smarty->display("advanced_search.tpl"); break; case 'project.searchForFind': list($queryID, $querySearch) = explode("&", $queryString); list($queryType, $queryValue) = explode("=", $queryID); list($querySearchType, $querySearchFor) = explode("=", $querySearch); $id = $queryValue; $searchFor = str_replace("+", " ", $querySearchFor); $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->searchForFinds($id, $searchFor); $smarty->assign("finds", $finds); $smarty->assign("searchFor", $searchFor); $smarty->display("project_searchForFinds_display.tpl"); break; case 'advanced.searchForFind': list($queryID, $queryProject, $queryDescr) = explode("&", $queryString); list($queryType, $queryValue) = explode("=", $queryID); list($querySearchType, $querySearchProj) = explode("=", $queryProject); list($queryDescription, $querySearchDescr) = explode("=", $queryDescr); $id = $queryValue; $searchFor = str_replace("+", " ", $querySearchProj); $querySearchDescr = str_replace("+", " ", $querySearchDescr); $project = $dao->getProject($id); $smarty->assign("project", $project); $finds = $dao->advancedSearchForFinds($id, $searchFor, $querySearchDescr); $smarty->assign("descriptionVal", $querySearchDescr); $smarty->assign("finds", $finds); $smarty->assign("projectVal", $searchFor); $smarty->display("advanced_searchForFinds_display.tpl"); break; case 'find.display': list($queryType, $queryValue) = explode("=", $queryString); $id = $queryValue; $result = $dao->getFind($id); $find = $result["find"]; $extension = $result["extension"]; // Log::getInstance()->log("find.display.Find = $find"); // Log::getInstance()->log("image = " . $result["img"]); $project_id = $find["project_id"]; $project = $dao->getProject($project_id); $smarty->assign("extension", $extension); // $smarty->assign("images",$result["images"]); // $smarty->assign("images",$find["images"]); $smarty->assign("images", $result["images"]); $smarty->assign("img", $result["img"]); // Display 1 image // $smarty->assign("videos",$find["videos"]); // $smarty->assign("audioClips",$find["audioClips"]); $smarty->assign("project", $project); $smarty->assign("find", $find); $smarty->display("find_display.tpl"); break; case 'project.export': $project_id = $request["id"]; $project_name = $dao->formatProjectName($project_id); $filename = $project_name . ".csv"; $writer = $dao->exportProject($project_id); header('Content-Type: text/csv'); header("Content-Disposition: attachment; filename={$filename}"); echo $writer; break; case 'settings': $userId = $_SESSION["loginId"]; $devices = $dao->getDevicesByUser($userId); $smarty->assign("devices", $devices); $smarty->display("settings/settings.tpl"); break; case 'settings.registerDevice': $authKey = genAuthKey(); $userId = $_SESSION["loginId"]; $result = $dao->registerDevicePending($userId, $authKey); $server = SERVER_BASE_URI; $email = $_SESSION["loginEmail"]; $data = array("server" => $server, "authKey" => $authKey); $smarty->assign("baseUrl", $server); $smarty->assign("authKey", $authKey); $smarty->assign("data", urlencode(json_encode($data))); $smarty->display("settings/registerDevice.tpl"); break; case 'settings.registerDevice.do': $imei = $request["imei"]; $deviceName = $request["deviceName"]; $result = $dao->changeDeviceNickname($imei, $deviceName); header("Location: settings"); break; case 'removeDevice.do': $imei = $request["imei"]; $dao->removeDevice($imei); header("Location: settings"); break; case 'purge': echo "Purging pending device registrations..."; $dao->purgePendingDevices(); break; case 'displayPicture': $id = $request["id"]; $image = $dao->getPicture($id); $size = $request["size"]; if ($size == "thumb") { $data = $image["data_thumb"]; } else { $data = $image["data_full"]; } $mimeType = $image["mime_type"]; header("Content-Type: {$mimeType}"); echo $data; break; case 'displayVideo': $id = $request["id"]; $video = $dao->getVideo($id); $video_name = $video["data_path"]; $video_path = "uploads/{$video_name}"; $fp_v = fopen($video_path, 'r'); $video_data = fread($fp_v, filesize($video_path)); header("Content-type: video/3gp"); echo $video_data; break; case 'displayAudio': $id = $request["id"]; $audio = $dao->getAudio($id); $audio_name = $audio["data_path"]; $audio_path = "uploads/{$audio_name}"; $fp_v = fopen($audio_path, 'r'); $audio_data = fread($fp_v, filesize($audio_path)); header("Content-type: audio/3gp"); print $audio_data; break; case 'admin': $smarty->display("admin/admin.tpl"); break; case 'qrcode': $oldwd = getcwd(); chdir("3rd"); require_once "qr_img.php"; chdir($oldwd); break; case 'customPosit.list': $project_id = $request["project_id"]; //$instances = $dao->getInstancesForProject($project_id); //$smarty->assign("instances", $instances); $smarty->assign("project_id", $project_id); $smarty->display("custom_posit_list.tpl"); break; case 'customPosit.download': $project_id = $request["project_id"]; //hack to get just project_id because php doesn't support multiple constructors.. $data = array(null, $project_id, null, null, null); $posit = new CustomPosit($data); $posit->download(); break; case 'customPosit': $userId = $_SESSION["loginId"]; $devices = $dao->getDevicesByUser($userId); $smarty->assign("devices", $devices); $project_id = $request["project_id"]; $smarty->assign("project_id", $project_id); $smarty->display("custom_posit.tpl"); break; case 'customPosit.create.do': $name = $request["name"]; $project_id = $request["project_id"]; $description = $request["description"]; $sync_on = $request["sync_on"]; $device_id = $request["device_id"]; echo $project_id; $data = array($name, $project_id, $description, $sync_on, $device_id); if ($name == null || $project_id == null) { $smarty->assign("name", $name); $smarty->assign("project_id", $project_id); $smarty->assign("description", $description); $smarty->assign("device_id", $device_id); $smarty->display("custom_posit.tpl"); } $posit = new CustomPosit($data); $posit->build(); break; default: header("Location: main"); } } else { if ($authnStatus == AUTHN_OK) { // user is authenticated but not authorized } else { if ($authnStatus == AUTHN_FAILED) { // user failed authentication' $smarty->display("header.tpl"); $smarty->assign("errMsg", "Login failed."); $smarty->display("login.tpl"); $smarty->display("footer.tpl"); } else { // user is not authenticated $smarty->display("header.tpl"); $smarty->assign("destination", $path); $smarty->display("login.tpl"); $smarty->display("footer.tpl"); } } } }