aboutsummaryrefslogtreecommitdiff
path: root/mod/messages/views/default/messages/view.php
blob: 501be8bb3c86a3ca0ad1a66b1208c713ed8e2857 (plain)
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
<?php

	/**
	 * Elgg messages view page
	 *
	 * @package ElggMessages
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Curverider Ltd <info@elgg.com>
	 * @copyright Curverider Ltd 2008-2010
	 * @link http://elgg.com/
	 *
	 * @uses $vars['entity'] An array of messages to view
	 * @uses $vars['page_view'] This is the page the messages are being accessed from; inbox or sentbox
	 *
	 */

	$limit = $vars['limit']; if (empty($limit)) $limit = 10;
	$offset = $vars['offset']; if (!isset($offset)) $offset = 0;

	// If there are any messages to view, view them
	if (isloggedin())
	if (is_array($vars['entity']) && sizeof($vars['entity']) > 0) {

?>
	<div id="messages" /><!-- start the main messages wrapper div -->

<?php

			// get the correct display for the inbox view
			if($vars['page_view'] == "inbox") {

				$counter = 0;

				foreach($vars['entity'] as $message) {
					if ($message->owner_guid == $vars['user']->guid
						|| $message->toId == $vars['user']->guid) {

					//make sure to only display the messages that have not been 'deleted' (1 = deleted)
					if($message->hiddenFrom != 1){

						// check to see if the message has been read, if so, get the correct background color
						if($message->readYet == 1){
							echo "<div class=\"message_read\" />";
						}else{
							echo "<div class=\"message_notread\" />";
						}

						//set the table
						echo "<table width=\"100%\" cellspacing='0'><tr>";
						//get the icon of the user who owns the message
						$from = get_entity($message->fromId);
						echo "<td width='200px'>" . elgg_view("profile/icon",array('entity' => $from, 'size' => 'tiny')) . "<div class='msgsender'><b>" . $from->name . "</b><br /><small>" . friendly_time($message->time_created) . "</small></div></td>";
						//display the message title
						echo "<td><div class='msgsubject'>";
						echo "<input type=\"checkbox\" name=\"message_id[]\" value=\"{$message->guid}\" /> ";
						echo "<a href=\"{$message->getURL()}\">" . $message->title . "</a></div></td>";
						//display the link to 'delete'

						echo "<td width='70px'>";
						echo "<div class='delete_msg'>" . elgg_view("output/confirmlink", array(
																'href' => $vars['url'] . "action/messages/delete?message_id=" . $message->getGUID() . "&type=inbox&submit=" . urlencode(elgg_echo('delete')),
																'text' => elgg_echo('delete'),
																'confirm' => elgg_echo('deleteconfirm'),
															)) . "</div>";

						echo "</td></tr></table>";
						echo "</div>"; // close the message background div

					}//end of hiddenFrom if statement
					} // end of user check

					$counter++;
					if ($counter == $limit) break;

				}//end of for each loop

			}//end of inbox if statement

			// get the correct display for the sentbox view
			if($vars['page_view'] == "sent") {

				$counter = 0;

				foreach($vars['entity'] as $message) {

					//make sure to only display the messages that have not been 'deleted' (1 = deleted)
					if($message->hiddenTo != 1){

						//get the correct user entity
						$user = get_entity($message->toId);
						echo "<div class=\"message_sent\" />";
						echo "<table width=\"100%\" cellspacing='0'><tr>";

						//get the icon for the user the message was sent to
						echo "<tr><td width='200px'>" . elgg_view("profile/icon",array('entity' => $user, 'size' => 'tiny')) . "<div class='msgsender'><b>" . $user->name . "</b><br /><small>" . friendly_time($message->time_created) . "</small></div></td>";
						//display the message title
						echo "<td><div class='msgsubject'>";
						echo "<input type=\"checkbox\" name=\"message_id[]\" value=\"{$message->guid}\" /> ";
						echo "<a href=\"{$message->getURL()}?type=sent\">" . $message->title . "</a></div></td>";
						//display the link to 'delete'

						echo "<td width='70px'>";
							echo "<div class='delete_msg'>" . elgg_view("output/confirmlink", array(
							'href' => $vars['url'] . "action/messages/delete?message_id=" . $message->getGUID() . "&type=sent&submit=" . urlencode(elgg_echo('delete')),
							'text' => elgg_echo('delete'),
							'confirm' => elgg_echo('deleteconfirm'),
						)) . "</div>";
						echo "</td></tr></table></div>";

					}//close hiddeTo if statement

					$counter++;
					if ($counter == $limit) break;

				}//close foreach

			}//close page_view sent if statement

			$baseurl = $_SERVER['REQUEST_URI'];
			$nav = '';

			if (sizeof($vars['entity']) > $limit) {
				$newoffset = $offset + $limit;
				$nexturl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));

				$nav .= '<a class="pagination_previous" href="'.$nexturl.'">&laquo; ' . elgg_echo('previous') . '</a> ';
			}

			if ($offset > 0) {
				$newoffset = $offset - $limit;
				if ($newoffset < 0) $newoffset = 0;

				$prevurl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));

				$nav .= '<a class="pagination_next" href="'.$prevurl.'">' . elgg_echo('next') . ' &raquo;</a> ';
			}


			if (!empty($nav)) {
				echo '<div class="pagination"><p>'.$nav.'</p><div class="clearfloat"></div></div>';
			}

			echo "</div>"; // close the main messages wrapper div

	} else {

		echo "<div class=\"contentWrapper\"><p class='messages_nomessage_message'>" . elgg_echo("messages:nomessages") . "</p></div>";

	}//end of the first if statement
?>