1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19:
20: 21: 22: 23: 24: 25: 26: 27:
28: class PmMessage extends XoopsObject
29: {
30: 31: 32:
33: public function __construct()
34: {
35: parent::__construct();
36: $this->initVar('msg_id', XOBJ_DTYPE_INT, null, false);
37: $this->initVar('msg_image', XOBJ_DTYPE_OTHER, 'icon1.gif', false, 100);
38: $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, true, 255);
39: $this->initVar('from_userid', XOBJ_DTYPE_INT, null, true);
40: $this->initVar('to_userid', XOBJ_DTYPE_INT, null, true);
41: $this->initVar('msg_time', XOBJ_DTYPE_INT, time(), false);
42: $this->initVar('msg_text', XOBJ_DTYPE_TXTAREA, null, true);
43: $this->initVar('read_msg', XOBJ_DTYPE_INT, 0, false);
44: $this->initVar('from_delete', XOBJ_DTYPE_INT, 1, false);
45: $this->initVar('to_delete', XOBJ_DTYPE_INT, 0, false);
46: $this->initVar('from_save', XOBJ_DTYPE_INT, 0, false);
47: $this->initVar('to_save', XOBJ_DTYPE_INT, 0, false);
48: }
49: }
50:
51: 52: 53:
54: class PmMessageHandler extends XoopsPersistableObjectHandler
55: {
56: 57: 58:
59: public function __construct(XoopsDatabase $db)
60: {
61: parent::__construct($db, 'priv_msgs', 'PmMessage', 'msg_id', 'subject');
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71:
72: public function setRead(PmMessage $pm, $val = 1)
73: {
74: return $this->updateAll('read_msg', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')), true);
75: }
76:
77: 78: 79: 80: 81: 82:
83: public function setFromdelete(PmMessage $pm, $val = 1)
84: {
85: if ($pm->getVar('to_delete') == 0) {
86: return $this->updateAll('from_delete', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
87: } else {
88: return parent::delete($pm);
89: }
90: }
91:
92: 93: 94: 95: 96: 97:
98: public function setTodelete(PmMessage $pm, $val = 1)
99: {
100: if ($pm->getVar('from_delete') == 0 || $pm->getVar('from_userid') == 0) {
101: return $this->updateAll('to_delete', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
102: } else {
103: return parent::delete($pm);
104: }
105: }
106:
107: 108: 109: 110: 111: 112:
113: public function setFromsave(PmMessage $pm, $val = 1)
114: {
115: return $this->updateAll('from_save', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
116: }
117:
118: 119: 120: 121: 122: 123:
124: public function setTosave(PmMessage $pm, $val = 1)
125: {
126: return $this->updateAll('to_save', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
127: }
128:
129: 130: 131: 132: 133:
134: public function getSavecount(XoopsUser $user = null)
135: {
136: if (!is_object($user)) {
137: $user =& $GLOBALS['xoopsUser'];
138: }
139: $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
140: $crit_to->add(new Criteria('to_save', 1));
141: $crit_to->add(new Criteria('to_userid', $user->getVar('uid')));
142: $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
143: $crit_from->add(new Criteria('from_save', 1));
144: $crit_from->add(new Criteria('from_userid', $user->getVar('uid')));
145: $criteria = new CriteriaCompo($crit_to);
146: $criteria->add($crit_from, 'OR');
147:
148: return $this->getCount($criteria);
149: }
150:
151: 152: 153: 154: 155: 156:
157: public function sendEmail(PmMessage $pm, XoopsUser $user)
158: {
159: global $xoopsConfig;
160:
161: if (!is_object($user)) {
162: $user =& $GLOBALS['xoopsUser'];
163: }
164: $msg = sprintf(_PM_EMAIL_DESC, $user->getVar('uname'));
165: $msg .= "\n\n";
166: $msg .= formatTimestamp($pm->getVar('msg_time'));
167: $msg .= "\n";
168: $from = new XoopsUser($pm->getVar('from_userid'));
169: $to = new XoopsUser($pm->getVar('to_userid'));
170: $msg .= sprintf(_PM_EMAIL_FROM, $from->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('from_userid') . ')');
171: $msg .= "\n";
172: $msg .= sprintf(_PM_EMAIL_TO, $to->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('to_userid') . ')');
173: $msg .= "\n";
174: $msg .= _PM_EMAIL_MESSAGE . ":\n";
175: $msg .= "\n" . $pm->getVar('subject') . "\n";
176: $msg .= "\n" . strip_tags(str_replace(array('<p>', '</p>', '<br>', '<br>'), "\n", $pm->getVar('msg_text'))) . "\n\n";
177: $msg .= "--------------\n";
178: $msg .= $xoopsConfig['sitename'] . ': ' . XOOPS_URL . "\n";
179:
180: $xoopsMailer =& xoops_getMailer();
181: $xoopsMailer->useMail();
182: $xoopsMailer->setToEmails($user->getVar('email'));
183: $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
184: $xoopsMailer->setFromName($xoopsConfig['sitename']);
185: $xoopsMailer->setSubject(sprintf(_PM_EMAIL_SUBJECT, $pm->getVar('subject')));
186: $xoopsMailer->setBody($msg);
187:
188: return $xoopsMailer->send();
189: }
190:
191: 192: 193: 194: 195:
196: public function getPruneForm()
197: {
198: include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
199: $form = new XoopsThemeForm(_PM_AM_PRUNE, 'form', 'prune.php', 'post', true);
200:
201: $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEAFTER, 'after'));
202: $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEBEFORE, 'before'));
203: $form->addElement(new XoopsFormRadioYN(_PM_AM_ONLYREADMESSAGES, 'onlyread', 1));
204: $form->addElement(new XoopsFormRadioYN(_PM_AM_INCLUDESAVE, 'includesave', 0));
205: $form->addElement(new XoopsFormRadioYN(_PM_AM_NOTIFYUSERS, 'notifyusers', 0));
206:
207: $form->addElement(new XoopsFormHidden('op', 'prune'));
208: $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
209:
210: return $form;
211: }
212: }
213: