objectionable.php 6.02 KB
Newer Older
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
<?php
/**
 *
 * @package    mahara
 * @subpackage core
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
 * @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.
 *
 */

/**
 * Returns a form to report objectionable material.
 *
 * @returns array Form elements.
 */
function objection_form() {
    $form = array(
        'name'              => 'objection_form',
        'method'            => 'post',
        'jsform'            => true,
        'autofocus'         => false,
        'elements'          => array(),
        'jssuccesscallback' => 'objectionSuccess',
    );

    $form['elements']['message'] = array(
        'type'  => 'textarea',
        'title' => get_string('complaint'),
        'rows'  => 5,
        'cols'  => 80,
        'rules' => array(
            'required' => true
        )
    );

    $form['elements']['submit'] = array(
        'type'    => 'submitcancel',
Pat Kira's avatar
Pat Kira committed
39
        'class'   => 'btn btn-success',
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        'value'   => array(get_string('notifyadministrator'), get_string('cancel')),
        'confirm' => array(get_string('notifyadministratorconfirm')),
    );
    return $form;
}

function objection_form_submit(Pieform $form, $values) {
    global $USER, $view, $artefact;

    if (!$USER->is_logged_in()) {
        throw new AccessDeniedException(get_string('accessdenied', 'error'));
    }

    require_once('activity.php');

    db_begin();

57
58
59
60
61
62
63
64
65
66
67
68
    $objection = new stdClass();
    if ($artefact) {
        $objection->objecttype = 'artefact';
        $objection->objectid   = $artefact->get('id');
    }
    else {
        $objection->objecttype = 'view';
        $objection->objectid   = $view->get('id');
    }
    $objection->reportedby = $USER->get('id');
    $objection->report = $values['message'];
    $objection->reportedtime = db_format_timestamp(time());
69

70
    insert_record('objectionable', $objection);
71
72
73
74
75

    $data = new StdClass();
    $data->view       = $view->get('id');
    $data->message    = $values['message'];
    $data->reporter   = $USER->get('id');
76
    $data->fromuser   = $USER->get('id');
77
78
79
80
81
82
83
84
85
86
    $data->ctime      = time();
    if ($artefact) {
        $data->artefact = $artefact->get('id');
    }

    activity_occurred('objectionable', $data);

    db_commit();

    if ($artefact) {
87
        $goto = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
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
    }
    else {
        $goto = $view->get_url();
    }

    $form->reply(PIEFORM_OK, array(
            'message' => get_string('reportsent'),
            'goto' => $goto,
        )
    );
}

function objection_form_cancel_submit(Pieform $form) {
    global $view;
    $form->reply(PIEFORM_OK, array(
            'goto' => $view->get_url(),
        )
    );
}

/**
 * Returns a form to mark a view as unobjectionable,
 * if the user is allowed to do that.
 *
 * @returns array Form elements.
 */
function notrude_form() {
115
    global $USER, $view, $artefact;
116
117
118
119
120
121
    $owner = $view->get('owner');
    if (!(($owner && ($USER->get('admin') || $USER->is_admin_for_user($owner)))
            || ($view->get('group') && $USER->get('admin')))) {
        return;
    }

122
123
    if ($artefact) {
        $params = array('artefact', $artefact->get('id'));
124
    }
125
126
    else {
        $params = array('view', $view->get('id'));
127
    }
128
    $isrude = get_record_select('objectionable', 'objecttype = ? AND objectid = ? AND resolvedby IS NULL LIMIT 1', $params);
129
130
131
132
133
134
135

    if (!$isrude) {
        return;
    }

    return array(
        'name'     => 'notrude_form',
Pat Kira's avatar
Pat Kira committed
136
        'class' => 'form-inline',
137
138
        'method'   => 'post',
        'elements' => array(
139
140
141
142
            'objection' => array(
                'type' => 'hidden',
                'value' => $isrude->id,
            ),
143
144
            'text' => array(
                'type' => 'html',
Pat Kira's avatar
Pat Kira committed
145
                'class' => 'pbm',
146
147
148
                'value' => get_string('viewobjectionableunmark', 'view'),
            ),
            'submit' => array(
Naomi Guyer's avatar
Naomi Guyer committed
149
150
                'type' => 'button',
                'usebuttontag' => true,
Pat Kira's avatar
Pat Kira committed
151
                'class' => 'btn btn-default',
Naomi Guyer's avatar
Naomi Guyer committed
152
                'value' => '<span class="fa fa-lg fa-times text-danger prs"></span> '.get_string('notobjectionable'),
153
154
155
156
157
158
159
160
161
162
163
164
            ),
        ),
    );
}

function notrude_form_submit(Pieform $form, $values) {
    global $view, $artefact, $USER;

    require_once('activity.php');

    db_begin();

165
166
167
168
169
170
171
172
173
174
175
    $objection = new stdClass();
    if ($artefact) {
        $objection->objecttype = 'artefact';
        $objection->objectid   = $artefact->get('id');
    }
    else {
        $objection->objecttype = 'view';
        $objection->objectid   = $view->get('id');
    }
    $objection->resolvedby = $USER->get('id');
    $objection->resolvedtime = db_format_timestamp(time());
176

177
    update_record('objectionable', $objection, array('id' => $values['objection']));
178
179
180
181
182

    // Send notification to other admins.
    $reportername = display_default_name($USER);

    if ($artefact) {
183
        $goto = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefact->get('id') . '&view=' . $view->get('id');
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    }
    else {
        $goto = $view->get_url();
    }

    $data = (object) array(
        'view'      => $view->get('id'),
        'reporter'  => $USER->get('id'),
        'subject'   => false,
        'message'   => false,
        'strings'   => (object) array(
            'subject' => (object) array(
                'key'     => 'viewunobjectionablesubject',
                'section' => 'view',
                'args'    => array($view->get('title'), $reportername),
            ),
            'message' => (object) array(
                'key'     => 'viewunobjectionablebody',
                'section' => 'view',
                'args'    => array($reportername, $view->get('title'), $view->formatted_owner()),
            ),
        ),
    );

    activity_occurred('objectionable', $data);

    db_commit();

    $form->reply(PIEFORM_OK, array(
        'message' => get_string('messagesent'),
        'goto' => $goto,
        )
    );
}