Annotation of /mambo/branches/4.6/administrator/components/com_messages/admin.messages.php
Parent Directory
|
Revision Log
Revision 948 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | csouza | 297 | * @package Mambo Open Source |
| 4 : | root | 1 | * @subpackage Messages |
| 5 : | cauld | 948 | * @copyright Refer to copyright.php |
| 6 : | root | 1 | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 7 : | csouza | 297 | * |
| 8 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 9 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 10 : | root | 1 | * Mambo is Free Software |
| 11 : | neilt | 667 | */ |
| 12 : | root | 1 | |
| 13 : | /** ensure this file is being included by a parent file */ | ||
| 14 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 15 : | |||
| 16 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 17 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 18 : | |||
| 19 : | $task = trim( mosGetParam( $_REQUEST, 'task', null ) ); | ||
| 20 : | $cid = mosGetParam( $_REQUEST, 'cid', array( 0 ) ); | ||
| 21 : | if (!is_array( $cid )) { | ||
| 22 : | $cid = array ( 0 ); | ||
| 23 : | } | ||
| 24 : | |||
| 25 : | switch ($task) { | ||
| 26 : | case "view": | ||
| 27 : | viewMessage( $cid[0], $option ); | ||
| 28 : | break; | ||
| 29 : | |||
| 30 : | case "new": | ||
| 31 : | newMessage( $option, NULL, NULL ); | ||
| 32 : | break; | ||
| 33 : | |||
| 34 : | case "reply": | ||
| 35 : | newMessage( | ||
| 36 : | $option, | ||
| 37 : | mosGetParam( $_REQUEST, 'userid', 0 ), | ||
| 38 : | mosGetParam( $_REQUEST, 'subject', '' ) | ||
| 39 : | ); | ||
| 40 : | break; | ||
| 41 : | |||
| 42 : | case "save": | ||
| 43 : | saveMessage( $option ); | ||
| 44 : | break; | ||
| 45 : | |||
| 46 : | case "remove": | ||
| 47 : | removeMessage( $cid, $option ); | ||
| 48 : | break; | ||
| 49 : | |||
| 50 : | case "config": | ||
| 51 : | editConfig( $option ); | ||
| 52 : | break; | ||
| 53 : | |||
| 54 : | case "saveconfig": | ||
| 55 : | saveConfig( $option ); | ||
| 56 : | break; | ||
| 57 : | |||
| 58 : | default: | ||
| 59 : | showMessages( $option ); | ||
| 60 : | break; | ||
| 61 : | } | ||
| 62 : | |||
| 63 : | function editConfig( $option ) { | ||
| 64 : | global $database, $my; | ||
| 65 : | |||
| 66 : | $database->setQuery( "SELECT cfg_name, cfg_value FROM #__messages_cfg WHERE user_id='$my->id'" ); | ||
| 67 : | $data = $database->loadObjectList( 'cfg_name' ); | ||
| 68 : | |||
| 69 : | $vars = array(); | ||
| 70 : | $vars['lock'] = mosHTML::yesnoSelectList( "vars[lock]", 'class="inputbox" size="1"', @$data['lock']->cfg_value ); | ||
| 71 : | $vars['mail_on_new'] = mosHTML::yesnoSelectList( "vars[mail_on_new]", 'class="inputbox" size="1"', @$data['mail_on_new']->cfg_value ); | ||
| 72 : | |||
| 73 : | HTML_messages::editConfig( $vars, $option ); | ||
| 74 : | |||
| 75 : | } | ||
| 76 : | |||
| 77 : | function saveConfig( $option ) { | ||
| 78 : | global $database, $my; | ||
| 79 : | |||
| 80 : | $database->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='$my->id'" ); | ||
| 81 : | $database->query(); | ||
| 82 : | |||
| 83 : | $vars = mosGetParam( $_POST, 'vars', array() ); | ||
| 84 : | foreach ($vars as $k=>$v) { | ||
| 85 : | $v = $database->getEscaped( $v ); | ||
| 86 : | $database->setQuery( "INSERT INTO #__messages_cfg (user_id,cfg_name,cfg_value)" | ||
| 87 : | . "\nVALUES ('$my->id','$k','$v')" | ||
| 88 : | ); | ||
| 89 : | $database->query(); | ||
| 90 : | } | ||
| 91 : | mosRedirect( "index2.php?option=$option" ); | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | function newMessage( $option, $user, $subject ) { | ||
| 95 : | global $database, $mainframe, $my, $acl; | ||
| 96 : | |||
| 97 : | // get available backend user groups | ||
| 98 : | $gid = $acl->get_group_id( 'Public Backend', 'ARO' ); | ||
| 99 : | $gids = $acl->get_group_children( $gid, 'ARO', 'RECURSE' ); | ||
| 100 : | $gids = implode( ',', $gids ); | ||
| 101 : | |||
| 102 : | // get list of usernames | ||
| 103 : | $recipients = array( mosHTML::makeOption( '0', '- Select User -' ) ); | ||
| 104 : | $database->setQuery( "SELECT id AS value, username AS text FROM #__users" | ||
| 105 : | ."\n WHERE gid IN ($gids)" | ||
| 106 : | . "\n ORDER BY name" ); | ||
| 107 : | $recipients = array_merge( $recipients, $database->loadObjectList() ); | ||
| 108 : | |||
| 109 : | $recipientslist = | ||
| 110 : | mosHTML::selectList( | ||
| 111 : | $recipients, | ||
| 112 : | 'user_id_to', | ||
| 113 : | 'class="inputbox" size="1"', | ||
| 114 : | 'value', | ||
| 115 : | 'text', | ||
| 116 : | $user | ||
| 117 : | ); | ||
| 118 : | HTML_messages::newMessage($option, $recipientslist, $subject ); | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | function saveMessage( $option ) { | ||
| 122 : | neilt | 667 | global $database, $mainframe, $my, $mosConfig_absolute_path; |
| 123 : | global $mosConfig_mailfrom, $mosConfig_fromname; | ||
| 124 : | |||
| 125 : | neilt | 665 | require_once($mosConfig_absolute_path."/includes/mambofunc.php"); |
| 126 : | root | 1 | |
| 127 : | $row = new mosMessage( $database ); | ||
| 128 : | if (!$row->bind( $_POST )) { | ||
| 129 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 130 : | exit(); | ||
| 131 : | } | ||
| 132 : | neilt | 738 | |
| 133 : | require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php'); | ||
| 134 : | $iFilter = new InputFilter( null, null, 1, 1 ); | ||
| 135 : | $row->subject = trim( $iFilter->process( $row->subject ) ); | ||
| 136 : | $row->message = trim( $iFilter->process( $row->message ) ); | ||
| 137 : | |||
| 138 : | root | 1 | if (!$row->send()) { |
| 139 : | mosRedirect( "index2.php?option=com_messages&mosmsg=" . $row->getError() ); | ||
| 140 : | } | ||
| 141 : | neilt | 667 | |
| 142 : | $msg = $row->subject.' - '.$row->message; | ||
| 143 : | |||
| 144 : | $sql = "SELECT a.id, a.name, a.email" | ||
| 145 : | neilt | 665 | . "\nFROM #__users AS a" |
| 146 : | . "\nWHERE a.sendEmail = '1'" | ||
| 147 : | . "\nAND a.id = '".$row->user_id_to."'" | ||
| 148 : | ; | ||
| 149 : | neilt | 667 | $database->setQuery( $sql ); |
| 150 : | neilt | 665 | $rows = $database->loadObjectList(); |
| 151 : | neilt | 667 | |
| 152 : | if ($rows) { | ||
| 153 : | foreach($rows as $row){ | ||
| 154 : | $recipient = $row->email; | ||
| 155 : | $subject = "New private message from ".$row->name; | ||
| 156 : | mosMail($mosConfig_mailfrom, $mosConfig_fromname, $recipient, $subject, $msg); | ||
| 157 : | neilt | 665 | } |
| 158 : | neilt | 667 | } |
| 159 : | root | 1 | mosRedirect( "index2.php?option=com_messages" ); |
| 160 : | } | ||
| 161 : | |||
| 162 : | function showMessages( $option ) { | ||
| 163 : | global $database, $mainframe, $my, $mosConfig_list_limit; | ||
| 164 : | |||
| 165 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 166 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 167 : | $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' ); | ||
| 168 : | $search = $database->getEscaped( trim( strtolower( $search ) ) ); | ||
| 169 : | |||
| 170 : | $wheres = array(); | ||
| 171 : | $wheres[] = " a.user_id_to='$my->id'"; | ||
| 172 : | |||
| 173 : | if (isset($search) && $search!= "") { | ||
| 174 : | $wheres[] = "(u.username LIKE '%$search%' OR email LIKE '%$search%' OR u.name LIKE '%$search%')"; | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | $database->setQuery( "SELECT COUNT(*)" | ||
| 178 : | . "\nFROM #__messages AS a" | ||
| 179 : | . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from" | ||
| 180 : | . ($wheres ? " WHERE " . implode( " AND ", $wheres ) : "" ) | ||
| 181 : | ); | ||
| 182 : | $total = $database->loadResult(); | ||
| 183 : | |||
| 184 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 185 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 186 : | |||
| 187 : | $database->setQuery( "SELECT a.*, u.name AS user_from" | ||
| 188 : | . "\nFROM #__messages AS a" | ||
| 189 : | . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from" | ||
| 190 : | . ($wheres ? " WHERE " . implode( " AND ", $wheres ) : "" ) | ||
| 191 : | . "\nORDER BY date_time DESC" | ||
| 192 : | . "\nLIMIT $pageNav->limitstart, $pageNav->limit" | ||
| 193 : | ); | ||
| 194 : | |||
| 195 : | $rows = $database->loadObjectList(); | ||
| 196 : | if ($database->getErrorNum()) { | ||
| 197 : | echo $database->stderr(); | ||
| 198 : | return false; | ||
| 199 : | } | ||
| 200 : | |||
| 201 : | HTML_messages::showMessages( $rows, $pageNav, $search, $option ); | ||
| 202 : | } | ||
| 203 : | |||
| 204 : | function viewMessage( $uid='0', $option ) { | ||
| 205 : | global $database, $my, $acl; | ||
| 206 : | |||
| 207 : | $row = null; | ||
| 208 : | $database->setQuery( "SELECT a.*, u.name AS user_from" | ||
| 209 : | . "\nFROM #__messages AS a" | ||
| 210 : | . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from" | ||
| 211 : | . "\nWHERE a.message_id='$uid'" | ||
| 212 : | . "\nORDER BY date_time DESC" | ||
| 213 : | ); | ||
| 214 : | $database->loadObject( $row ); | ||
| 215 : | |||
| 216 : | $database->setQuery( "UPDATE #__messages SET state='1' WHERE message_id='$uid'" ); | ||
| 217 : | $database->query(); | ||
| 218 : | |||
| 219 : | HTML_messages::viewMessage( $row, $option ); | ||
| 220 : | } | ||
| 221 : | |||
| 222 : | function removeMessage( $cid, $option ) { | ||
| 223 : | global $database; | ||
| 224 : | |||
| 225 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 226 : | csouza | 165 | echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n"; |
| 227 : | root | 1 | exit; |
| 228 : | } | ||
| 229 : | if (count( $cid )) { | ||
| 230 : | $cids = implode( ',', $cid ); | ||
| 231 : | $database->setQuery( "DELETE FROM #__messages WHERE message_id IN ($cids)" ); | ||
| 232 : | if (!$database->query()) { | ||
| 233 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 234 : | } | ||
| 235 : | } | ||
| 236 : | |||
| 237 : | $limit = intval( mosGetParam( $_REQUEST, 'limit', 10 ) ); | ||
| 238 : | $limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) ); | ||
| 239 : | mosRedirect( "index2.php?option=$option&limit=$limit&limitstart=$limitstart" ); | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

