XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
message.php
Go to the documentation of this file.
1 <?php
29 class PmMessage extends XoopsObject
30 {
31  function __construct()
32  {
33  $this->XoopsObject();
34  $this->initVar('msg_id', XOBJ_DTYPE_INT, null, false);
35  $this->initVar('msg_image', XOBJ_DTYPE_OTHER, 'icon1.gif', false, 100);
36  $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, true, 255);
37  $this->initVar('from_userid', XOBJ_DTYPE_INT, null, true);
38  $this->initVar('to_userid', XOBJ_DTYPE_INT, null, true);
39  $this->initVar('msg_time', XOBJ_DTYPE_INT, time(), false);
40  $this->initVar('msg_text', XOBJ_DTYPE_TXTAREA, null, true);
41  $this->initVar('read_msg', XOBJ_DTYPE_INT, 0, false);
42  $this->initVar('from_delete', XOBJ_DTYPE_INT, 1, false);
43  $this->initVar('to_delete', XOBJ_DTYPE_INT, 0, false);
44  $this->initVar('from_save', XOBJ_DTYPE_INT, 0, false);
45  $this->initVar('to_save', XOBJ_DTYPE_INT, 0, false);
46  }
47 
48  function PmMessage()
49  {
50  $this->__construct();
51  }
52 }
53 
55 {
56 
57  function __construct(&$db)
58  {
59  parent::__construct($db, "priv_msgs", 'PmMessage', 'msg_id', 'subject');
60  }
61 
62  function PmMessageHandler(&$db)
63  {
64  $this->__construct($db);
65  }
66 
73  function setRead($pm, $val = 1)
74  {
75  return $this->updateAll('read_msg', intval($val), new Criteria('msg_id', $pm->getVar('msg_id')), true);
76  }
77 
83  function setFromdelete($pm, $val = 1)
84  {
85  if ($pm->getVar('to_delete') == 0) {
86  return $this->updateAll('from_delete', intval($val), new Criteria('msg_id', $pm->getVar('msg_id')));
87  } else {
88  return parent::delete($pm);
89  }
90  }
91 
97  function setTodelete($pm, $val = 1)
98  {
99  if ($pm->getVar('from_delete') == 0 || $pm->getVar('from_userid') == 0) {
100  return $this->updateAll('to_delete', intval($val), new Criteria('msg_id', $pm->getVar('msg_id')));
101  } else {
102  return parent::delete($pm);
103  }
104  }
105 
111  function setFromsave($pm, $val = 1)
112  {
113  return $this->updateAll('from_save', intval($val), new Criteria('msg_id', $pm->getVar('msg_id')));
114  }
115 
121  function setTosave($pm, $val = 1)
122  {
123  return $this->updateAll('to_save', intval($val), new Criteria('msg_id', $pm->getVar('msg_id')));
124  }
125 
131  function getSavecount($user = null)
132  {
133  if (!is_object($user)) {
134  $user =& $GLOBALS["xoopsUser"];
135  }
136  $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
137  $crit_to->add(new Criteria('to_save', 1));
138  $crit_to->add(new Criteria('to_userid', $user->getVar('uid')));
139  $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
140  $crit_from->add(new Criteria('from_save', 1));
141  $crit_from->add(new Criteria('from_userid', $user->getVar('uid')));
142  $criteria = new CriteriaCompo($crit_to);
143  $criteria->add($crit_from, "OR");
144  return $this->getCount($criteria);
145  }
146 
153  function sendEmail($pm, $user)
154  {
155  global $xoopsConfig;
156 
157  if (!is_object($user)) {
158  $user =& $GLOBALS["xoopsUser"];
159  }
160  $msg = sprintf(_PM_EMAIL_DESC, $user->getVar("uname"));
161  $msg .= "\n\n";
162  $msg .= formatTimestamp($pm->getVar("msg_time"));
163  $msg .= "\n";
164  $from = new XoopsUser($pm->getVar("from_userid"));
165  $to = new XoopsUser($pm->getVar("to_userid"));
166  $msg .= sprintf(_PM_EMAIL_FROM, $from->getVar("uname") . " (" . XOOPS_URL . "/userinfo.php?uid=" . $pm->getVar("from_userid") . ")");
167  $msg .= "\n";
168  $msg .= sprintf(_PM_EMAIL_TO, $to->getVar("uname") . " (" . XOOPS_URL . "/userinfo.php?uid=" . $pm->getVar("to_userid") . ")");
169  $msg .= "\n";
170  $msg .= _PM_EMAIL_MESSAGE . ":\n";
171  $msg .= "\n" . $pm->getVar("subject") . "\n";
172  $msg .= "\n" . strip_tags( str_replace(array("<p>", "</p>", "<br />", "<br />"), "\n", $pm->getVar("msg_text")) ) . "\n\n";
173  $msg .= "--------------\n";
174  $msg .= $xoopsConfig['sitename'] . ": ". XOOPS_URL . "\n";
175 
176  $xoopsMailer =& xoops_getMailer();
177  $xoopsMailer->useMail();
178  $xoopsMailer->setToEmails($user->getVar("email"));
179  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
180  $xoopsMailer->setFromName($xoopsConfig['sitename']);
181  $xoopsMailer->setSubject(sprintf(_PM_EMAIL_SUBJECT, $pm->getVar("subject")));
182  $xoopsMailer->setBody($msg);
183  return $xoopsMailer->send();
184  }
185 
191  function getPruneForm()
192  {
193  include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
194  $form = new XoopsThemeForm(_PM_AM_PRUNE, 'form', 'prune.php', 'post', true);
195 
196  $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEAFTER, 'after'));
197  $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEBEFORE, 'before'));
198  $form->addElement(new XoopsFormRadioYN(_PM_AM_ONLYREADMESSAGES, 'onlyread', 1));
199  $form->addElement(new XoopsFormRadioYN(_PM_AM_INCLUDESAVE, 'includesave', 0));
200  $form->addElement(new XoopsFormRadioYN(_PM_AM_NOTIFYUSERS, 'notifyusers', 0));
201 
202  $form->addElement(new XoopsFormHidden('op', 'prune'));
203  $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
204 
205  return $form;
206  }
207 }
208 ?>