1: 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: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118:
<?php
if (!defined('SMF'))
die('No direct access...');
function getNotifyPrefs($members, $prefs = '', $process_default = false)
{
global $smcFunc;
$members = is_array($members) ? $members : (array) $members;
if (!empty($prefs))
$prefs = is_array($prefs) ? $prefs : (array) $prefs;
$result = array();
$members[] = 0;
$request = $smcFunc['db_query']('', '
SELECT id_member, alert_pref, alert_value
FROM {db_prefix}user_alerts_prefs
WHERE id_member IN ({array_int:members})' . (!empty($prefs) ? '
AND alert_pref IN ({array_string:prefs})' : ''),
array(
'members' => $members,
'prefs' => $prefs,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$result[$row['id_member']][$row['alert_pref']] = $row['alert_value'];
if ($process_default && isset($result[0]))
{
foreach ($members as $member)
if (isset($result[$member]))
$result[$member] += $result[0];
else
$result[$member] = $result[0];
unset ($result[0]);
}
return $result;
}
function setNotifyPrefs($memID, $prefs = array())
{
global $smcFunc;
if (empty($prefs) || !is_int($memID))
return;
$update_rows = array();
foreach ($prefs as $k => $v)
$update_rows[] = array($memID, $k, $v);
$smcFunc['db_insert']('replace',
'{db_prefix}user_alerts_prefs',
array('id_member' => 'int', 'alert_pref' => 'string', 'alert_value' => 'int'),
$update_rows,
array('id_member', 'alert_pref')
);
}
function deleteNotifyPrefs($memID, array $prefs)
{
global $smcFunc;
if (empty($prefs) || empty($memID))
return;
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}user_alerts_prefs
WHERE id_member = {int:member}
AND alert_pref IN ({array_string:prefs})',
array(
'member' => $memID,
'prefs' => $prefs,
)
);
}
?>