src.dualinventive.com/mtinfo/dist/webroot/main/app/include/upload_comment.php

150 lines
5.5 KiB
PHP

<?php
/** \file upload_comment.php
* \brief DI upload_comment page
* \author Bram Lentjes, Core|Vision
* \version 1.0
* \date 14-06-2013
*
* This file contains the upload_comment file.
*/
require_once('app/di_app_projects/a_get_generic.php');
// Check if user is logged in and have the rigths
if (verifyPermissions()) {
// Check is user cancels the upload comment
if ((!isset($_SESSION[$_PAGE_INFO['id']]['abort_submit_comment']))) {
// unset the abort session variable
unset($_SESSION[$_PAGE_INFO['id']]['abort_submit_comment']);
// Check if user comment form is set
if (isset($_POST['project_name']) && !empty($_POST['project_name']) && isset($_POST['project_id']) && !empty($_POST['project_id'])) {
// Split the $_POST['project_id]' (id,gps(lat,lon))
$splitted = explode(";", $_POST['project_id']);
// Fill comment array
$comment = array();
$comment['document'] = $splitted[0]; // document id
$comment['gebruiker'] = $userId;
$latitude = '0';
$longitude = '0';
// Check if GPS is set [1]= lat, [2] = lon
if (isset($splitted[1]) && isset($splitted[2])) {
// get latitude
$latitude = $splitted[1];
// get longitude
$longitude = $splitted[2];
}
$comment['latitude'] = $latitude;
$comment['longitude'] = $longitude;
$comment['tekst'] = $_POST['project_name'];
$comment['gebruiker_tabel'] = $userTable;
if (!empty($comment['tekst'])) {
// Store comment
db_store_data_user_comment($comment);
// Get last inserted => Needed for the log user-action
$last_id = db_fetch_last_id();
// Log user-project action
db_log_user_project($projectId, "menu:projecten:project_documentatie:add_user_comment", $last_id);
}
$replace_comment_info = array();
$replace_comment_info['document'] = $splitted[0];
// Get user comments
$replace_comments_infos = db_fetch_data_user_comment($replace_comment_info, 1);
// Check if there are comments
if (is_array($replace_comments_infos)) {
$p = 0;
$backgroundcolor_c = 'rgb(240,250,255);';
$border_c = '';
$last_comment_c = sizeof($replace_comments_infos);
// Div where all comments are placed so the can loaded by ajax post
echo "<div style=\"display:block;\" id=\"loaded_commments_" . $splitted[0] . "\" >";
foreach ($replace_comments_infos as $com_c) {
// Set border bottom at last comment
if (($p + 1 >= $last_comment_c) || $last_comment_c == 1) {
$border_c = 'border-bottom :2px solid rgb(0,158,224) !important;';
}
// Check which table to get the 'comment by' name from
if ($com_c['gebruiker_tabel'] == 'gebruiker_profiel') {
$commentBy = getUserProfileName($com_c['gebruiker']);
} else {
$commentBy = getUser($com_c['gebruiker']);
}
$commentBy = strtoupper(checkSizeUsername($commentBy));
echo "<div class=\"single_comment\" style=\"display:block;background-color:" . $backgroundcolor_c . "" . $border_c . "border-left :2px solid rgb(0,158,224) !important;border-right :2px solid rgb(0,158,224) !important;width:100%;-moz-box-sizing:border-box;-webkit-box-sizing: border-box;box-sizing:border-box;\" id=\"single_" . $splitted[0] . "_" . $p . "\">
<!-- Comment text -->
<div class=\"comment_text\">
<br>" . strtoupper($com_c['tekst']) . "
</div>
<!-- username and gps info -->
<div class=\"comment_user_gps\" >
<br>$commentBy<br><br>" . strtoupper($com_c['datum']) . "
</div>
</div>";
// to create a unique id for the single_comment
$p++;
// switch the background-color to blue or white
$backgroundcolor_c = ($backgroundcolor_c == 'rgb(240,250,255);') ? 'white;' : 'rgb(240,250,255);';
}
echo "<div style=\"clear:both;\"></div> </div>";
// Set height of the single_comment div because the height of loaded_page is undefined in this file
echo "<script type=\"text/javascript\">
// set to default
upload_comment_c = true;
// Get height of loaded page in pixels
var DivHeight = document.getElementById('loaded_page').offsetHeight;
// set single comment box to 20% of loaded div
$('.single_comment').height((DivHeight/100)*20);
// clear text area box
$('.document_comment_box_input').val('');
// Add comments with 1
number_commentsj++;
showCommentBox('" . $splitted[0] . "','" . IMAGES_PATH . "app/', number_commentsj);
$.mobile.hidePageLoadingMsg();
</script>";
}
}
}
} else {
// No rights or not logged in
DBG("upload file: not logged in or nog rights");
}