<?php
// vim: sw=4:ts=4
/**
* @version 00.04.09
* @package polaring
* @license This component in released under the GNU/GPL License
*
* File: view/upload.php
* Role: Handles uploading of a workout-file
**/
class uploadWorkout {
function storeFile($post, $files) {
if ( !user::validateIP($_SESSION['validIp']['upload']) ) {
return(false);
}
$file = $files['workoutFile'];
if ( !isset($file['name']) ) {
return(false);
}
$fileInfo = pathinfo($file['name']);
$fExt = strtolower($fileInfo['extension']);
$extLength = strlen($fExt);
$basenameLength = strlen($fileInfo['basename']);
$nameLength = ($basenameLength - $extLength) - 1;
$fName = strtolower(substr($fileInfo['basename'], 0,
$nameLength));
// Check if the file is a hst, tcx, hrm or srd
if ( ! ($fExt == "hst" || $fExt == "hrm" ||
$fExt == "srd" || $fExt == "tcx" ||
$fExt == "zip" ) ) {
echo "<h2>".strings::expression("error",
"Error")."</h2>\n";
echo "<p>".strings::expression("upload",
"notValidFileExt")."</p>\n";
return(false);
}
$source = $file['tmp_name'];
$destination = $_SESSION['dirUpload']."/".
$fName.".".uniqid().".".
$fExt;
if ( move_uploaded_file($source, $destination) ) {
echo "<p>".strings::expression("upload",
"FileSaveSuccess")."</p>";
return(true);
} else {
echo "<br /><br />";
echo "<h2>".strings::expression("error", "Error").
"</h2>\n";
echo "<p>".strings::expression("upload",
"FileSaveFailed")."</p>\n";
return(false);
}
} // end storeFile
function showUploadDialogue() {
if ( !user::validateIP($_SESSION['validIp']['upload']) ) {
return(false);
}
echo "<h2>".strings::expression("navigation",
"uploadWorkout")."</h2>\n\n";
echo "<form method=\"post\" action=\"".give::phpindex().
"?section=uploadWorkout\" enctype=\"multipart/".
"form-data\" >\n";
echo " <label for=\"workoutFile\">".strings::expression(
"upload", "ChooseFile")."</label>\n";
echo " <input type=\"hidden\" name=\"".
"MAX_FILE_SIZE\" value=\"1000000000\" />\n";
echo " <input type=\"file\" name=\"workoutFile\" ".
"id=\"workoutFile\" />\n";
echo "<br />\n";
echo " <input type=\"submit\" name=\"submit\" ".
"id=\"submit\" value=\"".strings::expression("upload",
"Upload")."\" />\n";
echo "</form>\n";
return(true);
} // end showUploadDialogue
} // end class uploadWorkout
?>