-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetails-view.php
More file actions
106 lines (91 loc) · 4.44 KB
/
details-view.php
File metadata and controls
106 lines (91 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* This file is part of student-sen-info.
*
* student-sen-info is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* student-sen-info is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with student-sen-info. If not, see <http://www.gnu.org/licenses/>.
*
* @author Jonathan Hart
*/
/**
* Loads the message thread for the currently viewed message
*
* This file is called from AJAX calls to view the message thread
* about a particular student's message
*/
// Setting up the define RUNNING_FROM, so it is known if the website is being
// accessed in the correct manner
define('RUNNING_FROM', 'ajax');
// Checking to see if the config.php file exists
if (!file_exists('./config.php')) {
// The config file wasn't found, so quit with an error message
die('<h2>The config file was not found. Contact your network admin.</h2>');
}
// Getting any settings from the config file
require('./config.php');
// Loading the functions file
require('./functions.php');
// Connecting to the database and saving the connection to it for use later
$databaseConnection = dbConnect($CFG['DBHost'], $CFG['DBUser'], $CFG['DBPass'], $CFG['DBName']);
// Sanitising all POSTS to this page
$sessionID = $databaseConnection->real_escape_string($_POST['cookie']);
$messageID = $databaseConnection->real_escape_string($_POST['messageID']);
// Generating a list of comments relevant to this message thread
// and displaying them for the user to see
$sqlMessageThread = "SELECT * FROM `sen_info`.`tbl_comments` WHERE (MessageID = ".$messageID.")";
$queryResultMessageThread = dbSelect($sqlMessageThread, $databaseConnection);
if (dbSelectCountRows($queryResultMessageThread) > 0) {
// Saving the results of the comment thread to a variable,
// which is returned once the comment thread has been created
$commentThreadHtml = '';
foreach (dbSelectGetRows($queryResultMessageThread) as $comment) {
// Getting the name of the staff member who wrote the comment
$sqlStaffFullName = "SELECT StaffForename, StaffSurname FROM `sen_info`.`tbl_staff` WHERE (StaffUsername = '".$comment['StaffUsername']."')";
$queryResultStaffFullname = dbSelect($sqlStaffFullName, $databaseConnection);
$tableRows = dbSelectGetRows($queryResultStaffFullname);
$staffForename = $tableRows[0]['StaffForename'];
$staffSurname = $tableRows[0]['StaffSurname'];
$staffFullName = $staffForename . " " . $staffSurname;
// Creating the comment thread HTML code, to pass back to the AJAX call
$commentThreadHtml .= '<div class="modal--comment_thread--comment-div" id="modal--comment_thread--comment-id_'.$comment['CommentID'].'">';
$commentThreadHtml .= '<p class="modal--comment_thread--comment-text">'.nl2br($comment['Comment']).'</p>';
$commentThreadHtml .= '<span class="modal--comment_thread--comment-meta pull-right">'.$staffFullName.' — '.substr($comment['CommentDate'], 0, 10).'</span>';
$commentThreadHtml .= '</div>';
}
// Scrolling the user to the bottom of the message thread,
// as they'll probably want the newest messages first
// See: http://stackoverflow.com/a/22232328
$commentThreadHtml .= '<script>';
$commentThreadHtml .= '$(function () {';
$commentThreadHtml .= ' $("#modal-textfield--comments").scrollTop(1E10);';
$commentThreadHtml .= '});';
$commentThreadHtml .= '</script>';
// Recentering the modal div vertically, as AJAX loading
// doesn't seem to do this properly. While not ideal, it
// keeps the modal buttons above the bottom of the page
// See: http://stackoverflow.com/a/13903655
$commentThreadHtml .= '<script>';
$commentThreadHtml .= "$(function() {";
$commentThreadHtml .= " $('.modal-box').css({";
$commentThreadHtml .= " 'position' : 'absolute',";
$commentThreadHtml .= " 'top' : '50%',";
$commentThreadHtml .= " 'margin-top' : function() {return -$(this).outerHeight()/2}";
$commentThreadHtml .= " });";
$commentThreadHtml .= "});";
$commentThreadHtml .= '</script>';
// Returning the generate comment thread
echo $commentThreadHtml;
}
// Closing the connection to the database
dbClose($databaseConnection);
?>