src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/app/include/upload_photo.php

177 lines
5.2 KiB
PHP

<?php
/** \file upload to server.php
* \brief DI upload_to_server.php page
* \author Bram Lentjes, Core|Vision
* \version 1.0
* \date 14-06-2013
*
* This file contains the upload_to_server.php file.
*/
DBG('page : upload_to_server.php');
// Check if user is logged in and have the rigths
if( ($_SESSION[$_PAGE_INFO['id']]['logged_on'] == 1 ) && (Ver_Rights_Project_Log("login")) ) {
// Check if the user still have the rigths for this project
if(check_project($_SESSION[$_PAGE_INFO['id']]['search']['project']['id'])){
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
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'] = $_SESSION[$_PAGE_INFO['id']]['search']['project']['id'];
$file['doc_type'] = $description; // 'user upload' = Upload , 'work order' = Scan, 'project' = Documentation
// Get document data from temporty file
$uploaded = upload_document($_FILES, $form , array("pdf", "doc", "docx", "xls", "csv", "txt", "rtf", "html", "mp3", "mp4" , "wma", "mpg", "flv", "avi", "jpg", "jpeg", "png", "gif"));
// 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'] = $_SESSION[$_PAGE_INFO['id']]['search']['project']['id'];
// 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"
<script type=\"text/javascript\">
setToastAlert('". strtoupper(_('No valid rights for this project')) ."','". _('Ok')."','','refreshApp();');
</script>";
}
}else{
// No rigths or not logged in
DBG("upload photo: not logged in or nog rights");
}
?>