Issues (2113)

public/main/survey/survey.php (1 issue)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Enums\ActionIcon;
6
use Chamilo\CoreBundle\Enums\StateIcon;
7
use Chamilo\CoreBundle\Enums\ToolIcon;
8
use ChamiloSession as Session;
9
10
/**
11
 * @author Patrick Cool <[email protected]>, Ghent University:
12
 * cleanup, refactoring and rewriting large parts of the code
13
 * @author Julio Montoya
14
 */
15
require_once __DIR__.'/../inc/global.inc.php';
16
17
$this_section = SECTION_COURSES;
18
$current_course_tool = TOOL_SURVEY;
19
20
api_protect_course_script(true);
21
22
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
23
// Coach can't view this page
24
$extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
25
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info());
26
27
if ($isDrhOfCourse) {
28
    header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
29
    exit;
30
}
31
if (!api_is_allowed_to_edit(false, true) ||
32
    (api_is_session_general_coach() && 'false' === $extend_rights_for_coachs)
33
) {
34
    api_not_allowed(true);
35
    exit;
36
}
37
38
// Database table definitions
39
$table_survey = Database::get_course_table(TABLE_SURVEY);
40
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
41
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
42
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
43
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
44
$table_user = Database::get_main_table(TABLE_MAIN_USER);
45
46
$survey_id = (int) $_GET['survey_id'];
47
$course_id = api_get_course_int_id();
48
$action = $_GET['action'] ?? null;
49
50
// Breadcrumbs
51
$interbreadcrumb[] = [
52
    'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
53
    'name' => get_lang('Survey list'),
54
];
55
56
Session::erase('answer_count');
57
Session::erase('answer_list');
58
59
// Getting the survey information
60
if (!empty($_GET['survey_id'])) {
61
    $course_code = api_get_course_id();
62
    if (-1 != $course_code) {
63
        $survey_data = SurveyManager::get_survey($survey_id);
64
    } else {
65
        api_not_allowed(true);
66
    }
67
} else {
68
    api_not_allowed(true);
69
}
70
71
$tool_name = strip_tags($survey_data['title'], '<span>');
72
$is_survey_type_1 = 1 == $survey_data['survey_type'];
73
74
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
75
    $tool_name .= '...';
76
}
77
78
if ($is_survey_type_1 && ('addgroup' === $action || 'deletegroup' === $action)) {
79
    $_POST['name'] = trim($_POST['name']);
80
    if ('addgroup' === $action) {
81
        if (!empty($_POST['group_id'])) {
82
            Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
83
                             WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
84
            Display::addFlash(Display::return_message(get_lang('Update successful')));
85
        } elseif (!empty($_POST['name'])) {
86
            Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, title,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.$survey_id.'\') ');
87
            Display::addFlash(Display::return_message(get_lang('Item added')));
88
        } else {
89
            Display::addFlash(Display::return_message(get_lang('Group need name'), 'warning'));
90
        }
91
    }
92
93
    if ('deletegroup' === $action) {
94
        $sql = 'DELETE FROM '.$table_survey_question_group.'
95
                WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' AND survey_id = '.$survey_id;
96
        Database::query($sql);
97
        Display::addFlash(Display::return_message(get_lang('Deleted')));
98
    }
99
100
    api_location(api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq());
101
}
102
103
$my_question_id_survey = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null;
104
$my_survey_id_survey = (int) $_GET['survey_id'];
105
// Displaying the header
106
if (!empty($action)) {
107
    switch ($action) {
108
        case 'copyquestion':
109
            $copied = SurveyManager::copyQuestion($_GET['question_id']);
110
            if (false !== $copied) {
111
                Display::addFlash(Display::return_message(get_lang('The question has been added.')));
112
            } else {
113
                Display::addFlash(Display::return_message(get_lang('An error occurred.'), 'warning'));
114
            }
115
            break;
116
        case 'delete':
117
            $result = SurveyManager::deleteQuestion($my_question_id_survey);
118
            if (false == $result) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
119
                Display::addFlash(Display::return_message(get_lang('An error occurred.'), 'warning'));
120
            } else {
121
                Display::addFlash(Display::return_message(get_lang('Deleted')));
122
            }
123
            break;
124
        case 'moveup':
125
        case 'movedown':
126
            SurveyManager::moveSurveyQuestion(
127
                $action,
128
                $my_question_id_survey,
129
                $my_survey_id_survey
130
            );
131
            Display::addFlash(Display::return_message(get_lang('The question has been moved')));
132
            break;
133
    }
134
135
    api_location(api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq());
136
}
137
138
Display::display_header($tool_name, 'Survey');
139
140
if (!empty($survey_data['survey_version'])) {
141
    echo '<b>'.get_lang('Version').': '.$survey_data['survey_version'].'</b>';
142
}
143
144
// We exit here is the first or last question is a pagebreak (which causes errors)
145
SurveyUtil::check_first_last_question($_GET['survey_id']);
146
147
/**
148
 * Render a Tailwind "card" toolbar with icon-only buttons.
149
 * @param string $title
150
 * @param array<int, array{url: string, iconHtml: string, label: string}> $items
151
 */
152
$renderIconCardToolbar = static function (string $title, array $items): void {
153
    if (empty($items)) {
154
        return;
155
    }
156
157
    echo '<div class="mt-6 mb-6">';
158
    echo '  <div class="bg-white border border-gray-20 rounded-3xl shadow-md p-6">';
159
    echo '    <div class="flex items-center justify-between mb-5">';
160
    echo '      <div class="text-sm font-semibold text-gray-900">'.Security::remove_XSS($title).'</div>';
161
    echo '    </div>';
162
163
    echo '    <div class="flex flex-wrap gap-4">';
164
165
    foreach ($items as $item) {
166
        $url = $item['url'];
167
        $label = $item['label'];
168
        $iconHtml = $item['iconHtml'];
169
170
        echo '      <a href="'.$url.'"'
171
            .' class="group inline-flex items-center justify-center'
172
            .' rounded-2xl border border-gray-20 bg-gray-10'
173
            .' shadow-md hover:shadow-lg'
174
            .' hover:bg-white hover:border-gray-300'
175
            .' transform hover:-translate-y-0.5 active:translate-y-0'
176
            .' transition-all duration-150 ease-out'
177
            .' p-3'
178
            .' focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500"'
179
            .' style="text-decoration:none"'
180
            .' title="'.api_htmlentities($label, ENT_QUOTES).'"'
181
            .' aria-label="'.api_htmlentities($label, ENT_QUOTES).'">'
182
            .'<span class="block leading-none pointer-events-none">'.$iconHtml.'</span>'
183
            .'</a>';
184
    }
185
186
    echo '    </div>';
187
    echo '  </div>';
188
    echo '</div>';
189
};
190
191
// Action links
192
$survey_actions = '';
193
if (3 != $survey_data['survey_type']) {
194
    $survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq(
195
        ).'&action=edit&survey_id='.$survey_id.'">'.
196
        Display::getMdiIcon(ActionIcon::EDIT, 'ch-toolbar-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit survey')).'</a>';
197
}
198
$survey_actions .= '<a
199
    href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('Delete survey').'?', ENT_QUOTES)).'\')) return false;">'.
200
    Display::getMdiIcon(ActionIcon::DELETE, 'ch-toolbar-icon', null, ICON_SIZE_MEDIUM, get_lang('Delete survey')).'</a>';
201
202
if (3 != $survey_data['survey_type']) {
203
    $survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
204
        Display::getMdiIcon(ActionIcon::PREVIEW_CONTENT, 'ch-toolbar-icon', null, ICON_SIZE_MEDIUM, get_lang('Preview')).'</a>';
205
}
206
207
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
208
    Display::getMdiIcon(StateIcon::MAIL_NOTIFICATION, 'ch-toolbar-icon', null, ICON_SIZE_MEDIUM, get_lang('Publish')).'</a>';
209
210
if (3 != $survey_data['survey_type']) {
211
    if ('true' !== api_get_setting('survey.hide_survey_reporting_button')) {
212
        $survey_actions .= Display::url(
213
            Display::getMdiIcon(ToolIcon::TRACKING, 'ch-toolbar-icon', null, ICON_SIZE_MEDIUM, get_lang('Reporting')),
214
            api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
215
        );
216
    }
217
}
218
219
$survey_actions .= SurveyUtil::getAdditionalTeacherActions($survey_id, ICON_SIZE_MEDIUM);
220
221
$surveyToolbarHtml = Display::toolbarAction('survey', [$survey_actions]);
222
echo $surveyToolbarHtml;
223
224
$urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
225
if (0 == $survey_data['survey_type']) {
226
    $questionItems = [];
227
228
    $questionItems[] = [
229
        'url' => $urlQuestion.'&type=yesno&survey_id='.$survey_id,
230
        'label' => get_lang('Yes / No'),
231
        'iconHtml' => Display::getMdiIcon('thumbs-up-down', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Yes / No')),
232
    ];
233
    $questionItems[] = [
234
        'url' => $urlQuestion.'&type=multiplechoice&survey_id='.$survey_id,
235
        'label' => get_lang('Multiple choice'),
236
        'iconHtml' => Display::getMdiIcon('format-list-bulleted', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Multiple choice')),
237
    ];
238
    $questionItems[] = [
239
        'url' => $urlQuestion.'&type=multipleresponse&survey_id='.$survey_id,
240
        'label' => get_lang('Multiple answers'),
241
        'iconHtml' => Display::getMdiIcon('format-list-bulleted-square', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Multiple answers')),
242
    ];
243
    $questionItems[] = [
244
        'url' => $urlQuestion.'&type=open&survey_id='.$survey_id,
245
        'label' => get_lang('Open'),
246
        'iconHtml' => Display::getMdiIcon('form-textarea', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Open')),
247
    ];
248
    $questionItems[] = [
249
        'url' => $urlQuestion.'&type=dropdown&survey_id='.$survey_id,
250
        'label' => get_lang('Dropdown'),
251
        'iconHtml' => Display::getMdiIcon('form-dropdown', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Dropdown')),
252
    ];
253
    $questionItems[] = [
254
        'url' => $urlQuestion.'&type=percentage&survey_id='.$survey_id,
255
        'label' => get_lang('Percentage'),
256
        'iconHtml' => Display::getMdiIcon('percent-box-outline', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Percentage')),
257
    ];
258
    $questionItems[] = [
259
        'url' => $urlQuestion.'&type=score&survey_id='.$survey_id,
260
        'label' => get_lang('Score'),
261
        'iconHtml' => Display::getMdiIcon('format-annotation-plus', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Score')),
262
    ];
263
    $questionItems[] = [
264
        'url' => $urlQuestion.'&type=comment&survey_id='.$survey_id,
265
        'label' => get_lang('Comment'),
266
        'iconHtml' => Display::getMdiIcon('format-align-top', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Comment')),
267
    ];
268
    $questionItems[] = [
269
        'url' => $urlQuestion.'&type=multiplechoiceother&survey_id='.$survey_id,
270
        'label' => get_lang('Multiple choice with *other* option'),
271
        'iconHtml' => Display::getMdiIcon('format-list-bulleted-type', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Multiple choice with *other* option')),
272
    ];
273
274
    if (0 == $survey_data['one_question_per_page']) {
275
        $questionItems[] = [
276
            'url' => $urlQuestion.'&type=selectivedisplay&survey_id='.$survey_id,
277
            'label' => get_lang('Selective display'),
278
            'iconHtml' => Display::getMdiIcon('thumbs-up-down', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Selective display')),
279
        ];
280
        $questionItems[] = [
281
            'url' => $urlQuestion.'&type=pagebreak&survey_id='.$survey_id,
282
            'label' => get_lang('Page break'),
283
            'iconHtml' => Display::getMdiIcon('format-page-break', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Page break')),
284
        ];
285
    }
286
287
    $renderIconCardToolbar(get_lang('Questions'), $questionItems);
288
} else {
289
    if (3 != $survey_data['survey_type']) {
290
        $questionItems = [
291
            [
292
                'url' => $urlQuestion.'&type=personality&survey_id='.$survey_id,
293
                'label' => get_lang('Yes / No'),
294
                'iconHtml' => Display::getMdiIcon('thumbs-up-down', 'ch-toolbar-icon', null, ICON_SIZE_BIG, get_lang('Yes / No')),
295
            ],
296
        ];
297
        $renderIconCardToolbar(get_lang('Questions'), $questionItems);
298
    }
299
}
300
301
// Displaying the table header with all the questions
302
echo '<table class="table table-bordered data_table">';
303
echo '<thead>';
304
echo '<tr>';
305
echo '		<th width="5%">'.get_lang('N°').'</th>';
306
echo '		<th width="50%">'.get_lang('Title').'</th>';
307
echo '		<th width="15%">'.get_lang('Type').'</th>';
308
echo '		<th width="15%" >'.get_lang('Options').'</th>';
309
echo '		<th width="15%">'.get_lang('Edit').'</th>';
310
if ($is_survey_type_1) {
311
    echo '<th width="100">'.get_lang('Condition').'</th>';
312
    echo '<th width="40">'.get_lang('Group').'</th>';
313
}
314
echo '	</tr>';
315
echo '</thead>';
316
317
// Displaying the table contents with all the questions
318
$question_counter = 1;
319
/*$sql = "SELECT * FROM $table_survey_question_group
320
        WHERE c_id = $course_id AND survey_id = $survey_id
321
        ORDER BY iid";
322
$result = Database::query($sql);
323
$groups = [];
324
while ($row = Database::fetch_array($result)) {
325
    $groups[$row['iid']] = $row['name'];
326
}*/
327
$sql = "SELECT survey_question.*, count(survey_question_option.iid) as number_of_options
328
        FROM $table_survey_question survey_question
329
        LEFT JOIN $table_survey_question_option survey_question_option
330
        ON
331
            survey_question.iid = survey_question_option.question_id
332
        WHERE
333
            survey_question.survey_id = $survey_id
334
        GROUP BY survey_question.iid
335
        ORDER BY survey_question.sort ASC";
336
337
$result = Database::query($sql);
338
$question_counter_max = Database::num_rows($result);
339
$questionsGroupClass = '';
340
while ($row = Database::fetch_assoc($result)) {
341
    $questionId = $row['iid'];
342
343
    $breakClass = '';
344
    // Visually impact questions between page breaks by changing the bg color
345
    if ('pagebreak' === $row['type']) {
346
        $breakClass = ' highlight';
347
        if (empty($questionsGroupClass)) {
348
            $questionsGroupClass = 'row_even';
349
        } else {
350
            $questionsGroupClass = '';
351
        }
352
    }
353
354
    echo '<tr class="'.$questionsGroupClass.$breakClass.'">';
355
    echo '	<td>'.$question_counter.'</td>';
356
    echo '	<td>';
357
358
    if (3 != $survey_data['survey_type']) {
359
        if (api_strlen($row['survey_question']) > 100) {
360
            echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
361
        } else {
362
            echo $row['survey_question'];
363
        }
364
    } else {
365
        $parts = explode('@@', $row['survey_question']);
366
        echo api_get_local_time($parts[0]).' - '.api_get_local_time($parts[1]);
367
    }
368
369
    if ('yesno' === $row['type']) {
370
        $tool_name = get_lang('Yes / No');
371
    } elseif ('multiplechoice' === $row['type']) {
372
        $tool_name = get_lang('Multiple choice');
373
    } elseif ('multipleresponse' === $row['type']) {
374
        $tool_name = get_lang('Multiple choice, multiple answers');
375
    } elseif ('selectivedisplay' === $row['type']) {
376
        $tool_name = get_lang('Selective display');
377
    } else {
378
        $tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
379
    }
380
381
    echo '</td>';
382
    echo '<td>'.$tool_name.'</td>';
383
    echo '<td>'.$row['number_of_options'].'</td>';
384
    echo '<td>';
385
    if (3 != $survey_data['survey_type']) {
386
        echo '<a
387
            href="'.api_get_path(WEB_CODE_PATH).
388
            'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$questionId.'">'.
389
            Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).'</a>';
390
    }
391
392
    echo '<a
393
        href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.
394
        api_get_cidreq().'&action=copyquestion&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$questionId.'">'.
395
        Display::getMdiIcon(ActionIcon::COPY_CONTENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Copy')).'</a>';
396
397
    echo '<a
398
        href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.
399
        api_get_cidreq().'&action=delete&survey_id='.$survey_id.'&question_id='.$questionId.'"
400
        onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("Are you sure you want to delete the question?").'?', ENT_QUOTES)).'\')) return false;">'.
401
        Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Delete')).'</a>';
402
    if (3 != $survey_data['survey_type']) {
403
        if ($question_counter > 1) {
404
            echo '<a
405
                href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.
406
                api_get_cidreq().'&action=moveup&survey_id='.$survey_id.'&question_id='.$questionId.'">'.
407
                Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move up')).'</a>';
408
        } else {
409
            echo Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, '&nbsp;');
410
        }
411
        if ($question_counter < $question_counter_max) {
412
            echo '<a
413
                href="'.api_get_path(WEB_CODE_PATH).
414
                'survey/survey.php?'.api_get_cidreq().'&action=movedown&survey_id='.$survey_id.'&question_id='.$questionId.'">'.
415
                Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Move down')).'</a>';
416
        } else {
417
            echo Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL,'&nbsp;');
418
        }
419
    }
420
    echo '	</td>';
421
    $question_counter++;
422
423
    /*if ($is_survey_type_1) {
424
        echo '<td>'.((0 == $row['survey_group_pri']) ? get_lang('Secondary') : get_lang('Primary')).'</td>';
425
        echo '<td>'.((0 == $row['survey_group_pri']) ? $groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']] : $groups[$row['survey_group_pri']]).'</td>';
426
    }*/
427
    echo '</tr>';
428
}
429
430
echo '</table>';
431
432
if ($is_survey_type_1) {
433
    echo '<br /><br /><b>'.get_lang('Manage groups').'</b><br /><br />';
434
    if (in_array(
435
        $_GET['sendmsg'],
436
        ['GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully']
437
    )
438
    ) {
439
        echo Display::return_message(
440
            get_lang($_GET['sendmsg']),
441
            'confirmation',
442
            false
443
        );
444
    }
445
446
    if (in_array($_GET['sendmsg'], ['GroupNeedName'])) {
447
        echo Display::return_message(
448
            get_lang($_GET['sendmsg']),
449
            'warning',
450
            false
451
        );
452
    }
453
    echo '<table border="0">
454
            <tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
455
    echo '<form
456
        action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
457
    if ('editgroup' === $_GET['action']) {
458
        $sql = 'SELECT title, description FROM '.$table_survey_question_group.'
459
                WHERE id = '.intval($_GET['gid']).' AND survey_id = '.$survey_id.'
460
                LIMIT 1';
461
        $rs = Database::query($sql);
462
        $editedrow = Database::fetch_assoc($rs);
463
        echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['title'].'" size="10" disabled>';
464
        echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
465
        echo '<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
466
        echo '<input
467
                type="submit"
468
                value="'.get_lang('Save').'"'.'
469
                <input type="button" value="'.get_lang('Cancel').'"
470
                onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
471
    } else {
472
        echo '<input type="text" maxlength="20" name="name" value="" size="10">';
473
        echo '<input type="text" maxlength="250" name="description" value="" size="80">';
474
        echo '<input type="submit" value="'.get_lang('Create').'"';
475
    }
476
    echo '</form><br />';
477
    echo '<table class="data_table">';
478
    echo '	<tr class="row_odd">';
479
    echo '		<th width="200">'.get_lang('Name').'</th>';
480
    echo '		<th>'.get_lang('Description').'</th>';
481
    echo '		<th width="100">'.get_lang('Edit').'</th>';
482
    echo '	</tr>';
483
484
    $sql = 'SELECT id, title, description
485
            FROM '.$table_survey_question_group.'
486
            WHERE
487
                c_id = '.$course_id.' AND
488
                survey_id = '.intval($survey_id).'
489
            ORDER BY name';
490
491
    $rs = Database::query($sql);
492
    $grouplist = '';
493
    while ($row = Database::fetch_assoc($rs)) {
494
        $grouplist .= '<tr><td>'.$row['title'].'</td><td>'.$row['description'].'</td><td>'.
495
            '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
496
            Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).'</a> '.
497
            '<a
498
            href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup"
499
            onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('Are you sure you want to delete %s?'), $row['title']).'?', ENT_QUOTES)).'\')) return false;">'.
500
            Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'.
501
            '</td></tr>';
502
    }
503
    echo $grouplist.'</table>';
504
}
505
506
Session::erase('answer_count');
507
Display::display_footer();
508