-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifications.php
executable file
·102 lines (87 loc) · 5.36 KB
/
notifications.php
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
<?php
session_start();
require_once 'class.farmer.php';
require_once 'consultants/class.consultant.php';
$farmer_home = new FARMER();
if($farmer_home->is_logged_in()){
$stmt = $farmer_home->runQuery("SELECT * FROM tbl_farmers WHERE email=:email_id");
$stmt->execute(array(":email_id"=>$_SESSION['farmerSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
}
$admin_home = new CONSULTANT();
if($admin_home->is_logged_in()){
$stmt = $admin_home->runQuery("SELECT * FROM tbl_consultants WHERE email=:email_id");
$stmt->execute(array(":email_id"=>$_SESSION['consultantSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
}
$name = $row['name'];
$stmt = $farmer_home->runQuery("SELECT * FROM sent_messages WHERE receiverEmail=:email_id AND status = 'unread' ORDER BY ID DESC LIMIT 0,10");
$stmt->execute(array(":email_id"=> $name));
?>
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
Notifications <i class="fa fa-envelope-o"></i>
<span class="badge bg-theme"><?php echo $stmt->rowCount(); ?></span>
</a>
<ul class="dropdown-menu extended inbox" >
<?php if ($stmt->rowCount() > 0) {
while($note = $stmt->fetch(PDO::FETCH_ASSOC)) {?>
<li>
<a href="farmer_inbox_view.php?message=<?php echo $note['ID']; ?>">
<?php
$stmt1 = $admin_home->runQuery("SELECT * FROM tbl_consultants WHERE name=:email_id AND photo!=''");
$stmt1->execute(array(":email_id"=>$note['name']));
if ($stmt1->rowCount() > 0) {
$rower = $stmt1->fetch(PDO::FETCH_ASSOC);?>
<span class="photo"><img class=" img-circle" alt="avatar" src="consultants/consult_images/<?php echo $rower['photo']; ?>" height="30px"></span>
<?php } else {
$stmt1 = $admin_home->runQuery("SELECT * FROM tbl_farmers WHERE name=:email_id AND photo!=''");
$stmt1->execute(array(":email_id"=>$note['name']));
if ($stmt1->rowCount() > 0) {
$rower = $stmt1->fetch(PDO::FETCH_ASSOC);?>
<span class="photo"><img class=" img-circle" alt="avatar" src="farmer_images/<?php echo $rower['photo']; ?>" height="30px"></span>
<?php } else { ?>
<span class="photo"><img class=" img-circle" alt="avatar" src="img/user.png" height="30px"></span>
<?php }
} ?>
<span class="subject">
<span class="from"><?php echo $note['name']; ?></span>
<span class="time"><?php
date_default_timezone_set('Africa/Nairobi');
$timed = $note['timer'];
$timestamp = strtotime($timed);
$strTime = array("second", "minute", "hour", "day", "month", "year");
$length = array("60","60","24","30","12","10");
$currentTime = time();
if($currentTime >= $timestamp) {
$diff = time()- $timestamp;
for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) {
$diff = $diff / $length[$i];
}
$diff = round($diff);
echo $diff . " " . $strTime[$i] . "(s) ago ";
} ?></span>
</span>
<span class="message">
<?php
$position = 100;
$messo = $note['message'];
$poster = substr($messo,0,$position);
echo $poster;
echo "...";
?>
</span>
</a>
</li>
<?php } ?>
<li>
<a href="farmer_inbox">See all messages</a>
</li>
<?php } else {?>
<li>
<span>No new Messages ...</span>
</li>
<li>
<a href="farmer_inbox">See all messages</a>
</li>
<?php } ?>
</ul>