19 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
50 function id($format =
'N')
52 return $this->getVar(
'msg_id', $format);
58 function msg_id($format =
'')
60 return $this->getVar(
'msg_id', $format);
66 function msg_image($format =
'')
68 return $this->getVar(
'msg_image', $format);
74 function subject($format =
'')
76 return $this->getVar(
'subject', $format);
82 function from_userid($format =
'')
84 return $this->getVar(
'from_userid', $format);
90 function to_userid($format =
'')
92 return $this->getVar(
'to_userid', $format);
98 function msg_time($format =
'')
100 return $this->getVar(
'msg_time', $format);
106 function msg_text($format =
'')
108 return $this->getVar(
'msg_text', $format);
114 function read_msg($format =
'')
116 return $this->getVar(
'read_msg', $format);
160 $sql =
'SELECT * FROM ' . $this->db->prefix(
'priv_msgs') .
' WHERE msg_id=' . $id;
164 $numrows = $this->db->getRowsNum(
$result);
167 $pm->assignVars($this->db->fetchArray(
$result));
185 if (!is_a($pm,
'xoopsprivmessage')) {
189 if (!$pm->isDirty()) {
192 if (!$pm->cleanVars()) {
195 foreach ($pm->cleanVars as $k => $v) {
199 $msg_id = $this->db->genId(
'priv_msgs_msg_id_seq');
200 $sql = sprintf(
"INSERT INTO %s (msg_id, msg_image, subject, from_userid, to_userid, msg_time, msg_text, read_msg) VALUES (%u, %s, %s, %u, %u, %u, %s, %u)", $this->db->prefix(
'priv_msgs'),
$msg_id, $this->db->quoteString($msg_image), $this->db->quoteString($subject), $from_userid,
$to_userid, time(), $this->db->quoteString($msg_text), 0);
202 $sql = sprintf(
"UPDATE %s SET msg_image = %s, subject = %s, from_userid = %u, to_userid = %u, msg_text = %s, read_msg = %u WHERE msg_id = %u", $this->db->prefix(
'priv_msgs'), $this->db->quoteString($msg_image), $this->db->quoteString($subject), $from_userid,
$to_userid, $this->db->quoteString($msg_text), $read_msg,
$msg_id);
204 $queryFunc = empty($force) ?
"query" :
"queryF";
209 $msg_id = $this->db->getInsertId();
211 $pm->assignVar(
'msg_id',
$msg_id);
220 function delete(&$pm)
225 if (!is_a($pm,
'xoopsprivmessage')) {
229 if (!
$result = $this->db->query(sprintf(
"DELETE FROM %s WHERE msg_id = %u", $this->db->prefix(
'priv_msgs'), $pm->getVar(
'msg_id')))) {
241 function getObjects(
$criteria = null, $id_as_key =
false)
245 $sql =
'SELECT * FROM ' . $this->db->prefix(
'priv_msgs');
248 $sort = ! in_array(
$criteria->getSort(), array(
251 'from_userid')) ?
'msg_id' :
$criteria->getSort();
260 while ($myrow = $this->db->fetchArray(
$result)) {
262 $pm->assignVars($myrow);
266 $ret[$myrow[
'msg_id']] =& $pm;
280 $sql =
'SELECT COUNT(*) FROM ' . $this->db->prefix(
'priv_msgs');
287 list ($count) = $this->db->fetchRow(
$result);
296 function setRead(&$pm)
301 if (!is_a($pm,
'xoopsprivmessage')) {
305 $sql = sprintf(
"UPDATE %s SET read_msg = 1 WHERE msg_id = %u", $this->db->prefix(
'priv_msgs'), $pm->getVar(
'msg_id'));
306 if (!$this->db->queryF(
$sql)) {