$options[$t->name] = get_string('type' . $t->name, $section); } } if ($USER->get('admin')) { $options['adminmessages'] = get_string('typeadminmessages', 'activity'); } $type = param_variable('type', 'all'); if ($type == '') { $type = 'all'; } if (!isset($options[$type])) { // Comma-separated list; filter out anything that's not an installed type $type = join(',', array_unique(array_filter(explode(',', $type), create_function('$a', 'global $installedtypes; return isset($installedtypes[$a]);')))); } require_once 'activity.php'; $activitylist = activitylist_html($type); $strread = json_encode(get_string('read', 'activity')); $javascript = <<<JAVASCRIPT JAVASCRIPT; $deleteall = pieform(array('name' => 'delete_all_notifications', 'method' => 'post', 'plugintype' => 'core', 'pluginname' => 'account', 'elements' => array('type' => array('type' => 'hidden', 'value' => $type), 'submit' => array('type' => 'submit', 'class' => 'btn-primary', 'value' => get_string('deleteallnotifications', 'activity'), 'confirm' => get_string('reallydeleteallnotifications', 'activity'))))); function delete_all_notifications_submit() { global $USER, $SESSION; $userid = $USER->get('id'); $type = param_variable('type', 'all'); $typesql = ''; if ($type != 'all') { // Treat as comma-separated list of activity type names $types = explode(',', preg_replace('/[^a-z,]+/', '', $type));
if ($ids) { set_field_select('notification_internal_activity', 'read', 1, 'id IN (' . join(',', $ids) . ') AND usr = ?', array($USER->get('id'))); } $message = get_string('markedasread', 'activity'); } else { if ($delete) { $ids = array(); foreach ($_GET as $k => $v) { if (preg_match('/^delete\\-(\\d+)$/', $k, $m)) { $ids[] = $m[1]; } } if ($ids) { $strids = join(',', $ids); $userid = $USER->get('id'); db_begin(); // Remove parent pointers to messages we're about to delete // Use temp table in subselect for Mysql compat. execute_sql("\n UPDATE {notification_internal_activity}\n SET parent = NULL\n WHERE parent IN (\n SELECT id\n FROM (\n SELECT id FROM {notification_internal_activity} WHERE id IN ({$strids}) AND usr = ?\n ) AS temp\n )", array($userid)); delete_records_select('notification_internal_activity', "id IN ({$strids}) AND usr = ?", array($userid)); db_commit(); } $message = get_string('deletednotifications', 'activity', count($ids)); } } $newhtml = activitylist_html($type, $limit, $offset); if ($message) { safe_require('notification', 'internal'); $newhtml['newunreadcount'] = call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')); } json_reply(false, (object) array('message' => $message, 'data' => $newhtml));