00001 <?
00009 class BaseInbox extends MyManager
00010 {
00016 public function __construct($class = 'Message')
00017 {
00018 parent::__construct($class);
00019 }
00020
00024 public function initSearchPage()
00025 {
00026 $this->assertLogin();
00027
00028 parent::initSearchPage();
00029
00030 $this->pageTitle = 'Inbox';
00031 }
00032
00038 public function getSearchParamXml()
00039 {
00040 $xml = parent::getSearchParamXml();
00041
00042 $xml .= <<<XML
00043 <param name="status">
00044 <option value="read"/>
00045 <option value="unread"/>
00046 </param>
00047 XML;
00048 return $xml;
00049 }
00050
00056 protected function getSearchSelect($params)
00057 {
00058 $sql = parent::getSearchSelect($params);
00059
00060 $sql .= ", i.read ";
00061
00062 return $sql;
00063 }
00064
00070 protected function getSearchFrom($params)
00071 {
00072 $from = "FROM {$this->object->inboxTable} i\n";
00073 $from .= "INNER JOIN {$this->object->tableName} o\n";
00074 $from .= "ON o.id = i.message_id\n";
00075
00076 return $from;
00077 }
00078
00084 protected function getSearchWhere($params)
00085 {
00086 global $me;
00087
00088 $where = parent::getSearchWhere($params);
00089
00090 $where .= " AND i.user_id = '$me->id'\n";
00091
00092 if ($params['status'] == 'unread')
00093 $where .= " AND i.read = 0 ";
00094
00095 if ($params['status'] == 'read')
00096 $where .= " AND i.read = 1 ";
00097
00098 return $where;
00099 }
00100
00105 protected function getSortFieldsArray()
00106 {
00107 $data = parent::getSortFieldsArray();
00108
00109 $data['read'] = 'Sort by read status';
00110
00111 return $data;
00112 }
00113
00119 protected function loadObjects($data)
00120 {
00121 $objs = parent::loadObjects($data);
00122
00123 foreach ($data AS $row)
00124 $objs[$row['id']]->read = $row['read'];
00125
00126 return $objs;
00127 }
00128
00136 public function drawRows($rs)
00137 {
00138 if (count($rs))
00139 {
00140 echo "<form id=\"deleteAll\" method=\"post\" action=\"" . $this->getUrl(array('page' => 'delete')) . "\">\n";
00141
00142 echo "<table class=\"InOutBox\">";
00143 $this->object->drawHeaderRow('inbox');
00144 foreach ($rs AS $ar)
00145 {
00146 $on = !$on;
00147 $ar->drawRow('inbox', $on);
00148 }
00149 echo "</table>";
00150
00151 echo "<input type=\"submit\" name=\"submit\" value=\"Delete Selected\"/>\n";
00152 echo "</form>\n";
00153 }
00154 }
00155
00161 public function getPagesXml()
00162 {
00163 $xml = parent::getPagesXml();
00164
00165 $xml .= "<page name=\"delete\" description=\"delete inbox messages.\"/>\n";
00166
00167 return $xml;
00168 }
00169
00173 public function initDeletePage()
00174 {
00175 global $me;
00176
00177 $this->pageTitle = 'Delete Inbox Messages';
00178
00179 $this->assertLogin();
00180
00181 if (!count($_POST['message']))
00182 throw new PageError('You must select at least 1 message to delete.');
00183 else
00184 {
00185 foreach ($_POST['message'] AS $messageId)
00186 {
00187 dbExecute("
00188 DELETE FROM {$this->object->inboxTable}
00189 WHERE user_id = '$me->id'
00190 AND message_id = '$messageId'
00191 ");
00192 }
00193
00194 Util::redirect($this->getUrl(".main"));
00195 }
00196 }
00197
00201 public function drawDeletePage()
00202 {
00203 echo 'Messages deleted.';
00204 }
00205 }
00206 ?>