0) {
echo "Error: " . $_FILES["file"]["error"] . "
";
} else {
$form;
$description;
$latitude;
$longitude;
$heading;
$photo_file = '0'; // default file
if (isset($_GET)) {
// Get latitude
if (isset($_GET['latitude'])) {
$latitude = $_GET['latitude'];
// No GPs
if (($latitude == '0') || ($latitude == 'null')) {
unset($latitude);
}
}
// Get longitude
if (isset($_GET['longitude'])) {
$longitude = $_GET['longitude'];
// No GPs
if (($longitude == '0') || ($longitude == 'null')) {
unset($longitude);
}
}
// Get heading
if (isset($_GET['heading'])) {
$heading = $_GET['heading'];
// No GPs
if (($heading == '0') || ($heading == 'null')) {
unset($heading);
}
}
} else {
// No GPS
unset($latitude);
unset($longitude);
unset($heading);
}
// Get $_POST parameters
if (isset($_POST)) {
$form = $_POST['arg1'];
$description = $_POST['arg2'];
$photo_file = $_POST['arg3'];
}
$file;
$file['project'] = $projectId;
$file['doc_type'] = $description; // 'user upload' = Upload , 'work order' = Scan, 'project' = Documentation
// Get document data from temporty file
global $_VALID_EXT_UPLOAD;
$uploaded = upload_document($_FILES, $form, $_VALID_EXT_UPLOAD);
// Errors?
if (isset($_PAGE_INFO['errormsg'])) {
$_SESSION[$_PAGE_INFO['id']]['errormsg'] = $_PAGE_INFO['errormsg'];
}
// Merge 2 arrays
if (is_array($uploaded)) {
$file = array_merge($file, $uploaded);
}
// Store file in SESSION
if ((isset($file['document'])) && (strlen($file['document']))) {
if (!is_array($_SESSION[$_PAGE_INFO['id']]['project_doc'])) {
$_SESSION[$_PAGE_INFO['id']]['project_doc'] = array();
}
// Copy file => Otherwhise it will be removed!
$tmp = session_save_path() . "/_" . basename($_FILES[$form]['tmp_name']);
copy($_FILES[$form]['tmp_name'], $tmp);
// Check if upload is an photo then replace name with date en time of the server
if (!strcmp($photo_file, '1')) {
$_FILES[$form]['name'] = date('Y-m-d H:i:s') . ".jpg";
}
// Add new document!
array_push($_SESSION[$_PAGE_INFO['id']]['project_doc'], array(tmp_name => $tmp,
doc_type => $file['doc_type'],
date => date('Y-m-d H:i:s'),
mimetype => $file['mimetype'],
filename => $_FILES[$form]['name']));
}
if (is_array($_SESSION[$_PAGE_INFO['id']]['project_doc'])) {
foreach ($_SESSION[$_PAGE_INFO['id']]['project_doc'] as $new_doc) {
if (isset($new_doc['tmp_name'])) {
// Read temporary file
$fp = fopen($new_doc['tmp_name'], 'r');
$new_doc['document'] = fread($fp, filesize($new_doc['tmp_name']));
fclose($fp);
// Add project number
$new_doc['project'] = $projectId;
// Add latitude
$new_doc['latitude'] = $latitude;
// Add longitude
$new_doc['longitude'] = $longitude;
// Add heading
$new_doc['heading'] = $heading;
// Store new document
db_store_file($new_doc, "project_documenten");
if ($new_doc['doc_type'] == "work order") {
// send mail
db_project_send_mail_for_file_upload($new_doc['project'], 'administratie', $new_doc);
} else if ($new_doc['doc_type'] == "user upload") {
// send mail
db_project_send_mail_for_file_upload($new_doc['project'], 'beheerder', $new_doc);
}
// Return new filename
echo delete_characters($_FILES[$form]['name']);
// Clear document
unset($_SESSION[$_PAGE_INFO['id']]['project_doc']);
}
}
}
}
} else {
// When the user doesn't have the correct rights for this project
echo "
";
}
} else {
// No rigths or not logged in
DBG("upload photo: not logged in or nog rights");
}