-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnoteshome.php
More file actions
166 lines (151 loc) · 8.16 KB
/
noteshome.php
File metadata and controls
166 lines (151 loc) · 8.16 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
include 'header.php';
include 'titlebar.php';
if ($validity == "valid") {
$col = $db -> posts;
$usercol = $db -> users;
$userresult = $usercol -> find(['username' => $loginuser]);
$usergroups = "";
foreach ($userresult as $userinfo){
$usergroups = $userinfo['groups'];
$usergroups = str_replace(" ", "", $usergroups);
$groupsarray = explode(",", $usergroups);
}
//This is the search function for the page
if(isset($_POST['notesearch'])){
$notesearch = $_POST['notesearch'];
//handling case insensitive searches
$notesearchlow = strtolower($notesearch); //lowercase all the values
$notesearchup = ucwords($notesearch); //make the first letter an upper case
//Search against the same user name or group name
$record = $col->find(['$or'=>[
['name'=> $loginuser, 'postname'=> ['$regex'=>$notesearch]],
['name'=> $loginuser, 'postname'=> ['$regex'=>$notesearchlow]],
['name'=> $loginuser, 'postname'=> ['$regex'=>$notesearchup]],
['groups' => ['$in' => $groupsarray], 'postname'=> ['$regex'=>$notesearch]],
['groups' => ['$in' => $groupsarray], 'postname'=> ['$regex'=>$notesearchlow]],
['groups' => ['$in' => $groupsarray], 'postname'=> ['$regex'=>$notesearchup]],
['groups' => ['$in' => $groupsarray], 'groups'=> ['$regex'=>$notesearch]],
['groups' => ['$in' => $groupsarray], 'groups'=> ['$regex'=>$notesearchup]],
['groups' => ['$in' => $groupsarray], 'groups'=> ['$regex'=>$notesearchlow]]
]]);
}
//This returns all values if the search bar is not used or has yet to be used
else { $record = $col->find(['$or'=>[
['name' => $loginuser],
['groups' => ['$in' => $groupsarray]]
]], ['sort' => ['date'=> -1]]); }
$item=0;
//Search bar
echo "<tr><td class='search' colspan='4'>
<form method='post' action='".$_SERVER['PHP_SELF']."'>
<input name='notesearch' type='text' class='search' placeholder='Search by group or post name'>
<input class='search' type='submit' value='SEARCH' ></form>
</td></tr>
<tr>";
foreach ($record as $note) {
$name=$note['name'];
$postname=$note['postname'];
$postcolor=$note['postcolor'];
$postdate = $note['date'];
$postid = $note['_id'];
$postimage = "";
if(isset($note['postimage'])){ $postimage = $note['postimage']; }
$redflag = "<a style="; //An exception when the post has a link auto copited in from Google Docs
$redflag2 = "<img src="; // An exception for when images are posted in the note body
//still working on getting the formatting right for this
$content = $note['blog'];
if (strlen($content) >= 200 && $postimage == ""){
//handle posts with just a link exception
if (strpos($content, $redflag) != false && strpos($content, $redflag) <= 200) { $content = "<p>Hyperlink in body. Click View to see details.<p>"; }
if (strpos($content, $redflag2) != false && strpos($content, $redflag2) <= 200) { $content = "<p>Image in body. Click View to see details.<p>"; }
$content = substr($content,0,200)." ...<br>";
$content = str_replace("< ", "", $content); //replace a bad cut if a <p> or <li> gets cut
$content .= "</li></ul>"; //this helps messing up other formatting if a list is used and cut
}
elseif (strlen($content) >= 100 && $postimage != ""){
//handle posts with just a link exception
if (strpos($content, $redflag) != false && strpos($content, $redflag) <= 100) { $content = "<p>Hyperlink in body. Click View to see details.</p>"; }
if (strpos($content, $redflag2) != false && strpos($content, $redflag2) <= 200) { $content = "<p>Image in body. Click View to see details.<p>"; }
$content = substr($content,0,100)." ...<br>";
$content = str_replace("< ", "", $content); //replace a bad cut if a <p> or <li> gets cut
$content .= "</li></ul>"; //this helps messing up other formatting if a list is used and cut
}
if ($item < 4){
echo "<td>
<form method='post' action='viewpost.php'>
<div class='postlink overview' style='background-color: $postcolor;'><strong>Author: $name <br>Note: $postname</strong>
<br><strong>$postdate</strong>";
if($postimage != "none" && $postimage != null){ echo "<br><div style='text-align: center;'><img src='$postimage' style='max-height: 80px;'></div>"; }
echo "$content<br>
<input type='hidden' name='name' value='$name'>
<input type='hidden' name='postname' value='$postname'>
<input type='hidden' name='postcolor' value='$postcolor'>
<input type='hidden' name='postid' value='$postid'>
<input type='submit' value='VIEW' class='view'></div></form></td>";
$item++;
}
elseif($item >= 4){
$item=1;
echo "</tr><tr>";
echo "<td><form method='post' action='viewpost.php'>
<div class='postlink overview' style='background-color: $postcolor;'><strong>Author: $name <br>Note: $postname</strong>
<br><strong>$postdate</strong>";
if($postimage != "none" && $postimage != null){ echo "<br><div style='text-align: center;'><img src='$postimage' style='max-height: 80px;'></div>"; }
echo "<br>$content<br>
<input type='hidden' name='name' value='$name'>
<input type='hidden' name='postname' value='$postname'>
<input type='hidden' name='postcolor' value='$postcolor'>
<input type='hidden' name='postid' value='$postid'>
<input type='submit' value='VIEW' class='view'></div></form></td>";
}
}
echo "</tr>";
//Capture tasks for the upcoming tasks alert
$col2 = $db->tasks;
$tasklist = $col2 -> find(['taskowner' => $loginuser]);
$duetaskcount = 0; //this is to help trigger the javascript to show the popup
$todaysdate = time();
echo "<div class='groupmgmt' style='visibility: hidden;' id='dueTask'>
<img class='closepopup' onclick='tasksdue()' src='close.png'>
<h4>Upcoming tasks</h4><strong><p>The following tasks are coming up in the next 7 days:</p></strong>";
foreach ($tasklist as $taskitem) {
$taskdate = strtotime($taskitem['duedate']);
$difference = abs($taskdate - $todaysdate);
if ( $difference <= 604800 && $taskitem['taskstatus'] == "Open") {
echo "<p>Item name: ".$taskitem['postname']." -- Due: ".$taskitem['duedate']."</p>";
$duetaskcount++;
}
}
echo "<p>See more in <a href='mytasks.php'>MY TASKS</a></p>
<input type='hidden' id='taskcount' value='$duetaskcount'>";
if (isset($_SESSION['popupseen']) && $_SESSION['popupseen'] == "alreadyshown"){
echo "<input type='hidden' id='alreadyshown' value='alreadyshown'>";
}
else {
$_SESSION['popupseen'] = "notyet";
echo "<input type='hidden' id='alreadyshown' value='notyet'>";
}
echo "</div>";
}
else { echo "<br><br>Sorry, username and password are unknown. Please try to log in again."; }
?>
</table>
</td></tr></table>
</body>
<script>
function tasksdue() {
var taskcount = document.getElementById('taskcount').value;
var tasksduepopup = document.getElementById('dueTask');
var alreadyshown = document.getElementById('alreadyshown').value;
console.log(taskcount+" "+alreadyshown);
if (taskcount > 0 && alreadyshown == 'notyet') {
if (tasksduepopup.style.visibility == 'hidden') {
tasksduepopup.style.visibility = 'visible';
}
else { tasksduepopup.style.visibility = 'hidden'; }
}
}
window.onload = tasksdue();
</script>
</html>