| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /* $Id: functions.common.message.php 2934 2007-04-20 17:35:09Z b4rt $ */
- /*******************************************************************************
- LICENSE
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License (GPL)
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- To read the license please visit http://www.gnu.org/copyleft/gpl.html
- *******************************************************************************/
- /**
- * Delete Message
- *
- * @param $mid
- */
- function DeleteMessage($mid) {
- global $cfg, $db;
- $sql = "delete from tf_messages where mid=".$db->qstr($mid)." and to_user=".$db->qstr($cfg["user"]);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- /**
- * Mark Message as Read
- *
- * @param $mid
- */
- function MarkMessageRead($mid) {
- global $cfg, $db;
- $sql = "select * from tf_messages where mid = ".$db->qstr($mid);
- $rs = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $rec = array('IsNew'=>0, 'force_read'=>0);
- $sql = $db->GetUpdateSQL($rs, $rec);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- /**
- * Save Message
- *
- * @param $to_user
- * @param $from_user
- * @param $message
- * @param $to_all
- * @param $force_read
- */
- function SaveMessage($to_user, $from_user, $message, $to_all=0, $force_read=0) {
- global $cfg, $db;
- $message = str_replace(array("'"), "", $message);
- $create_time = time();
- $sTable = 'tf_messages';
- if ($to_all == 1) {
- $message .= "\n\n__________________________________\n*** ".$cfg['_MESSAGETOALL']." ***";
- $sql = 'select user_id from tf_users';
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- while ($row = $result->FetchRow()) {
- $rec = array(
- 'to_user' => strtolower($row['user_id']),
- 'from_user' => strtolower($from_user),
- 'message' => $message,
- 'IsNew' => 1,
- 'ip' => $cfg['ip'],
- 'time' => $create_time,
- 'force_read' => $force_read
- );
- $sql = $db->GetInsertSql($sTable, $rec);
- $result2 = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- } else {
- // Only Send to one Person
- $rec = array(
- 'to_user' => strtolower($to_user),
- 'from_user' => strtolower($from_user),
- 'message' => $message,
- 'IsNew' => 1,
- 'ip' => $cfg['ip'],
- 'time' => $create_time,
- 'force_read' => $force_read
- );
- $sql = $db->GetInsertSql($sTable, $rec);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- }
- /**
- * Get Message data in an array
- *
- * @param $mid
- * @return array
- */
- function GetMessage($mid) {
- global $cfg, $db;
- $sql = "select from_user, message, ip, time, isnew, force_read from tf_messages where mid=".$db->qstr($mid)." and to_user=".$db->qstr($cfg["user"]);
- $rtnValue = $db->GetRow($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- return $rtnValue;
- }
- ?>
|