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

