function saveUploadData($db, $metadata) { global $dataMap, $fpConfig; $dbConnected = $db != NULL; if (!$dbConnected) { $db = new SqlManager($fpConfig); } if ($db->offline) { return -1; } //TODO: use remap between exif data and db row? //step 1: insert record based on image EXIF metadata if (!isset($metadata["upload_id"])) { $data = arrayRemap($metadata, $dataMap); // $data["meal"] = selectMeal($data["image_date_taken"]); } else { //step 2: update record based on form data $data = $metadata; } $data["username"] = fpCurrentUsername(); $data["table"] = "user_upload"; $result = $db->saveRow($data); if (!$dbConnected) { $db->disconnect(); } return $result; }
//echo jsValue($fpConfig, true, true); $username = fpCurrentUsername(); $upload_id = reqParam("upload_id"); debugVar("username", true); debug("Request", $_REQUEST); debug("GET request", $_GET); debug("POST request", $_POST); debug("POST files", $_FILES, true); if (!$username) { return errorMessage("Not logged in."); } if (!$upload_id) { return errorMessage("No File deleted."); } $db = new SqlManager($fpConfig); if ($db->offline) { return errorMessage("DB offline. No File deleted."); } //if profile filters( Q_ ) : demographic //otherwise: personal $params = array("table" => "user_upload"); addVarsToArray($params, "username upload_id"); //$results = demographicPortrait($db, $params); $success = $db->delete($params); $message = $success ? "record {$upload_id} deleted." : "record id {$upload_id} not deleted."; $db->disconnect(); //TODO delete image file: check if other records for this user use this filename. if only 1, delete file and its thumbs. $response = array(); addVarsToArray($response, "success message upload_id"); $response["time"] = getTimer(true); echo jsValue($response, true, true);