outbox.php 7.96 KB
Newer Older
1
2
3
4
<?php
/**
 *
 * @package    mahara
5
 * @subpackage module-multirecipientnotification
6
7
8
9
10
11
12
13
 * @author     David Ballhausen, Tobias Zeuch
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
define('MENUITEM', 'inbox');
14
define('SECTION_PLUGINTYPE', 'module');
15
16
17
18
define('SECTION_PLUGINNAME', 'multirecipientnotification');
define('SECTION_PAGE', 'outbox');

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
19
safe_require('module', 'multirecipientnotification');
20
define('SUBSECTIONHEADING', get_string('labeloutbox1',  'module.multirecipientnotification'));
21
22
23
24

global $THEME;
global $USER;
// Add new title
25
define('TITLE', get_string('notification', 'module.multirecipientnotification'));
26
27
28
29
30
31
32
33
34
35
36

// Make sure the unread message count is up to date whenever the
// user hits this page.
$USER->reload_background_fields();

$installedtypes = get_records_assoc(
    'activity_type', '', '',
    'plugintype,pluginname,name',
    'name,admin,plugintype,pluginname'
);

Tobias Zeuch's avatar
Tobias Zeuch committed
37
$options = array();
38
foreach ($installedtypes as $t) {
39
40
    // ignore activity type newpost, as each recipients notification appears
    // as a single entry for the poster and thus floods his outbox
41
    if ((!$t->admin || $USER->get('admin')) && ('newpost' !== $t->name)) {
42
43
44
45
46
47
48
49
50
        $section = $t->pluginname ? "{$t->plugintype}.{$t->pluginname}" : 'activity';
        $options[$t->name] = get_string('type' . $t->name, $section);
    }
}

if ($USER->get('admin')) {
    $options['adminmessages'] = get_string('typeadminmessages', 'activity');
}

Tobias Zeuch's avatar
Tobias Zeuch committed
51
52
53
54
// sort activitytypes now, when they have been translated
uasort($options, 'strcmp');
// ... and add the element for 'all types' to the beginning
$options = array_merge(array('all' => get_string('alltypes', 'activity')), $options);
55
56
57
58
59
60
61
$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(
62
        explode(',', $type),
63
64
65
66
67
68
69
70
71
        function ($a) {global $installedtypes; return isset($installedtypes[$a]);}
    )));
}

require_once(get_config('docroot') . 'lib/activity.php');
// use the new function to show from - and to user
$activitylist = activitylistout_html($type);

$strread = json_encode(get_string('read', 'activity'));
72
$strnodelete = json_encode(get_string('nodelete', 'activity'));
73

74
75
76
77
78
$paginationjavascript = <<<JAVASCRIPT

// NOTE: most js is in the notification.js file, but we found
// this part much more difficult to relocate

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
function toggleMessageDisplay(table, id) {
    var messages = jQuery('#message-' + table + '-' + id);
    if (messages.length <= 0) {
        return;
    }
    var rows = messages.parents("tr");
    if (rows.length > 0) {
        if (jQuery(rows[0]).find(".messagedisplaylong.hidden").length > 0) {
            jQuery(rows[0]).find(".messagedisplaylong").removeClass("hidden");
            jQuery(rows[0]).find(".messagedisplayshort").addClass("hidden");
        }
        else {
            jQuery(rows[0]).find(".messagedisplaylong").addClass("hidden");
            jQuery(rows[0]).find(".messagedisplayshort").removeClass("hidden");
        }
    }
}

function changeactivitytype() {
    var delallform = document.forms['delete_all_notifications'];
    delallform.elements['type'].value = this.options[this.selectedIndex].value;
    var params = {'type': this.options[this.selectedIndex].value};
    sendjsonrequest('indexout.json.php', params, 'GET', function(data) {
        jQuery("#activitylist span.countresults").remove();
        jQuery("#activitylist th").each(function() {
                var link = jQuery(this).find('a');
                if (link.length >= 1) {
                    var headertext = link.text().trim();
                    jQuery(this).html(headertext);
                }
            });
        jQuery("input#search").val('');
        paginator.updateResults(data);
    });
}

115
jQuery(function($) {
116
117
118
119
  // We want the paginator to tell us when a page gets changed.
  function PaginatorData() {
      var self = this;
      var params = {};
120
      this.pageChanged = function(ev, data) {
121
122
123
124
125
126
127
128
129
130
131
132
          self.params = {
              'offset': data.offset,
              'limit': data.limit,
              'type': data.type
          }
      }
      paginatorProxy.addObserver(self);
      $(self).on('pagechanged', self.pageChanged);
  }
  window.paginatorData = new PaginatorData();

  window.paginator = {$activitylist['pagination_js']}
133
134
135
136
137

});
JAVASCRIPT;


138
139
$deleteall = pieform(array(
    'name'        => 'delete_all_notifications',
Naomi Guyer's avatar
Naomi Guyer committed
140
    'class'       => 'form-deleteall sr-only',
141
142
143
144
145
146
147
148
149
150
    'method'      => 'post',
    'plugintype'  => 'core',
    'pluginname'  => 'account',
    'elements'    => array(
        'type' => array(
            'type' => 'hidden',
            'value' => $type,
        ),
        'submit' => array(
            'type' => 'submit',
Naomi Guyer's avatar
Naomi Guyer committed
151
            'class' => 'deleteallnotifications',
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
            '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');
    $count = 0;
    if (in_array($type, array('all', 'usermessage'))) {
        if ($type !== 'all') {
            $at = activity_locate_typerecord($type);
            $typecond = 'AND msg.type = ' . $at->id;
        }
        else {
            $typecond = '';
        }

        $query = 'SELECT msg.id AS id
173
174
                FROM {module_multirecipient_notification} as msg
                INNER JOIN {module_multirecipient_userrelation} as rel
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
                    ON msg.id = rel.notification
                    AND rel.usr = ?
                    AND rel.role = ?
                    AND rel.deleted = \'0\'
                    ' . $typecond;
        $result = get_records_sql_array($query, array($userid, 'sender'));
        $msgids = array();
        if (is_array($result)) {
            foreach ($result as $record) {
                $msgids[] = $record->id;
            }
            db_begin();
            delete_messages_mr($msgids, $userid);
            db_commit();
        }
        $count = count($msgids);
    }
192
193
    $SESSION->add_ok_msg(get_string('deletednotifications1', 'module.multirecipientnotification', $count));
    redirect(get_config('wwwroot') . 'module/multirecipientnotification/outbox.php?type=' . $type);
194
195
}

196
$smarty = smarty(array('paginator'));
197
198
199
$smarty->assign('options', $options);
$smarty->assign('type', $type);

200
201
$smarty->assign('INLINEJAVASCRIPT', $paginationjavascript);

202
// show urls and titles
203
define('NOTIFICATION_SUBPAGE', 'outbox');
204
$smarty->assign('SUBPAGENAV', PluginModuleMultirecipientnotification::submenu_items());
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
$searchtext = param_variable('search', null);
$searcharea = param_variable('searcharea', null);

$searchdata = new stdClass();
$searchdata->searchtext = $searchtext;
$searchdata->searcharea = $searcharea;
$searchdata->searchurl = 'outbox.php?type=' . $type . '&search=' . $searchtext . '&searcharea=';
$searchdata->all_count = 0;
$searchdata->sender_count = 0;
$searchdata->recipient_count = 0;
$searchdata->sub_count = 0;
$searchdata->mes_count = 0;
if ($searchtext !== null) {
    $searchresults = get_message_search($searchtext, $type, 0, 9999999, "outbox.php", $USER->get('id'));
    $searchdata->all_count = $searchresults['All_data']['count'];
    $searchdata->sender_count = $searchresults['Sender']['count'];
    $searchdata->recipient_count = $searchresults['Recipient']['count'];
    $searchdata->sub_count = $searchresults['Subject']['count'];
    $searchdata->mes_count = $searchresults['Message']['count'];
224
}
225
$smarty->assign('searchdata', $searchdata);
226
227
228
229
$smarty->assign('deleteall', $deleteall);
$smarty->assign('activitylist', $activitylist);

// Changed to new tpl
230
$smarty->display('module:multirecipientnotification:indexout.tpl');