20 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
23 include_once
$GLOBALS['xoops']->path('include/notification_constants.php');
24 include_once
$GLOBALS['xoops']->path('include/notification_functions.php');
63 function id($format =
'N')
65 return $this->getVar(
'not_id', $format);
71 function not_id($format =
'')
73 return $this->getVar(
'not_id', $format);
79 function not_modid($format =
'')
81 return $this->getVar(
'not_modid', $format);
87 function not_category($format =
'')
89 return $this->getVar(
'not_category', $format);
95 function not_itemid($format =
'')
97 return $this->getVar(
'not_itemid', $format);
103 function not_event($format =
'')
105 return $this->getVar(
'not_event', $format);
111 function not_uid($format =
'')
113 return $this->getVar(
'not_uid', $format);
119 function not_mode($format =
'')
121 return $this->getVar(
'not_mode', $format);
134 function notifyUser($template_dir, $template, $subject, $tags)
139 if (!is_object(
$user)) {
145 include_once
$GLOBALS[
'xoops']->path(
'include/notification_constants.php');
148 $xoopsMailer->usePM();
151 $xoopsMailer->setFromUser(
$member_handler->getUser($xoopsMailerConfig[
'fromuid']));
152 foreach ($tags as $k => $v) {
153 $xoopsMailer->assign($k, $v);
157 $xoopsMailer->useMail();
158 foreach ($tags as $k => $v) {
159 $xoopsMailer->assign($k, preg_replace(
"/&/i",
'&', $v));
168 $xoopsMailer->setTemplateDir($template_dir);
169 $xoopsMailer->setTemplate($template);
170 $xoopsMailer->setToUsers(
$user);
174 $xoopsMailer->setSubject($subject);
175 $success = $xoopsMailer->send();
179 include_once
$GLOBALS[
'xoops']->path(
'include/notification_constants.php');
223 $notification->setNew();
225 return $notification;
237 $notification =
false;
240 $sql =
'SELECT * FROM ' . $this->db->prefix(
'xoopsnotifications') .
' WHERE not_id=' . $id;
242 return $notification;
244 $numrows = $this->db->getRowsNum(
$result);
247 $notification->assignVars($this->db->fetchArray(
$result));
250 return $notification;
265 if (!is_a($notification,
'xoopsnotification')) {
268 if (!$notification->isDirty()) {
271 if (!$notification->cleanVars()) {
274 foreach ($notification->cleanVars as $k => $v) {
277 if ($notification->isNew()) {
278 $not_id = $this->db->genId(
'xoopsnotifications_not_id_seq');
279 $sql = sprintf(
"INSERT INTO %s (not_id, not_modid, not_itemid, not_category, not_uid, not_event, not_mode) VALUES (%u, %u, %u, %s, %u, %s, %u)", $this->db->prefix(
'xoopsnotifications'), $not_id, $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode);
281 $sql = sprintf(
"UPDATE %s SET not_modid = %u, not_itemid = %u, not_category = %s, not_uid = %u, not_event = %s, not_mode = %u WHERE not_id = %u", $this->db->prefix(
'xoopsnotifications'), $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode, $not_id);
286 if (empty($not_id)) {
287 $not_id = $this->db->getInsertId();
289 $notification->assignVar(
'not_id', $not_id);
300 function delete(&$notification)
305 if (!is_a($notification,
'xoopsnotification')) {
309 $sql = sprintf(
"DELETE FROM %s WHERE not_id = %u", $this->db->prefix(
'xoopsnotifications'), $notification->getVar(
'not_id'));
328 $sql =
'SELECT * FROM ' . $this->db->prefix(
'xoopsnotifications');
340 while ($myrow = $this->db->fetchArray(
$result)) {
342 $notification->assignVars($myrow);
344 $ret[] =& $notification;
346 $ret[$myrow[
'not_id']] =& $notification;
348 unset($notification);
363 $sql =
'SELECT COUNT(*) FROM ' . $this->db->prefix(
'xoopsnotifications');
370 list ($count) = $this->db->fetchRow(
$result);
383 $sql =
'DELETE FROM ' . $this->db->prefix(
'xoopsnotifications');
399 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
404 if (count($objects) == 1) {
426 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
452 if (empty($xoopsUser)) {
455 $user_id = $xoopsUser->getVar(
'uid');
466 $mode =
$user->getVar(
'notify_mode');
469 if (!is_array($events)) {
470 $events = array($events);
472 foreach ($events as $event) {
474 if ($notification->getVar(
'not_mode') != $mode) {
478 $notification =& $this->
create();
479 $notification->setVar(
'not_modid',
$module_id);
480 $notification->setVar(
'not_category', $category);
481 $notification->setVar(
'not_itemid', $item_id);
482 $notification->setVar(
'not_uid',
$user_id);
483 $notification->setVar(
'not_event', $event);
484 $notification->setVar(
'not_mode', $mode);
485 $this->
insert($notification);
516 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
523 foreach (array_keys($results) as
$i) {
524 $ret[] = $results[
$i]->getVar(
'not_event');
570 function triggerEvents($category, $item_id, $events, $extra_tags = array(), $user_list = array(),
$module_id = null, $omit_user_id = null)
572 if (!is_array($events)) {
573 $events = array($events);
575 foreach ($events as $event) {
592 function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(),
$module_id = null, $omit_user_id = null)
598 $module_id =! empty($xoopsModule) ? $xoopsModule->getVar(
'mid') : 0;
607 if (empty($mod_config[
'notification_enabled'])) {
612 if (!in_array(
notificationGenerateConfig($category_info, $event_info,
'option_name'), $mod_config[
'notification_events']) && empty($event_info[
'invisible'])) {
616 if (!isset($omit_user_id)) {
618 if (!empty($xoopsUser)) {
619 $omit_user_id = $xoopsUser->getVar(
'uid');
626 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
634 if (!empty($user_list)) {
636 foreach ($user_list as
$user) {
637 $user_criteria->add(
new Criteria(
'not_uid', intval($user)),
'OR');
642 if (empty($notifications)) {
648 $not_config =
$module->getInfo(
'notification');
650 if (!empty($not_config)) {
651 if (!empty($not_config[
'tags_file'])) {
652 $tags_file =
$GLOBALS[
'xoops']->path(
'modules/' .
$module->getVar(
'dirname') .
'/' . $not_config[
'tags_file']);
653 if (file_exists($tags_file)) {
654 include_once $tags_file;
655 if (!empty($not_config[
'tags_func'])) {
656 $tags_func = $not_config[
'tags_func'];
657 if (function_exists($tags_func)) {
658 $tags = $tags_func($category, intval($item_id), $event);
664 if (! empty($not_config[
'lookup_file'])) {
665 $lookup_file =
$GLOBALS[
'xoops']->path(
'modules/' .
$module->getVar(
'dirname') .
'/' . $not_config[
'lookup_file']);
666 if (file_exists($lookup_file)) {
667 include_once $lookup_file;
668 if (!empty($not_config[
'lookup_func'])) {
669 $lookup_func = $not_config[
'lookup_func'];
670 if (function_exists($lookup_func)) {
671 $item_info = $lookup_func($category, intval($item_id));
679 $tags[
'X_ITEM_TYPE'] = ! empty($category_info[
'item_name']) ? $category_info[
'title'] :
'[' .
_NOT_ITEMTYPENOTAVAILABLE .
']';
680 $tags[
'X_MODULE'] =
$module->getVar(
'name');
681 $tags[
'X_MODULE_URL'] = XOOPS_URL .
'/modules/' .
$module->getVar(
'dirname') .
'/';
682 $tags[
'X_NOTIFY_CATEGORY'] = $category;
683 $tags[
'X_NOTIFY_EVENT'] = $event;
685 $template_dir = $event_info[
'mail_template_dir'];
686 $template = $event_info[
'mail_template'] .
'.tpl';
687 $subject = $event_info[
'mail_subject'];
689 foreach ($notifications as $notification) {
690 if (empty($omit_user_id) || $notification->getVar(
'not_uid') != $omit_user_id) {
694 $tags[
'X_UNSUBSCRIBE_URL'] = XOOPS_URL .
'/notifications.php';
695 $tags = array_merge($tags, $extra_tags);
696 $notification->notifyUser($template_dir, $template, $subject, $tags);
729 if (empty($xoopsUser)) {
732 $user_id = $xoopsUser->getVar(
'uid');
741 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
744 if (!is_array($events)) {
745 $events = array($events);
748 foreach ($events as $event) {
749 $event_criteria->add(
new Criteria(
'not_event', mysql_real_escape_string($event)),
'OR');
783 $criteria->add(
new Criteria(
'not_category', mysql_real_escape_string($category)));
803 foreach ($notifications as $n) {
820 $notification->unsetNew();
821 $notification->setVar($field_name, $field_value);
822 return $this->
insert($notification);