| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
@require_once("../../includes.php"); |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
define("context","form"); |
|---|
| 18 |
|
|---|
| 19 |
$redirect_url = ''; |
|---|
| 20 |
|
|---|
| 21 |
if (isloggedin() && run("users:flags:get", array("admin", $_SESSION['userid']))) { |
|---|
| 22 |
|
|---|
| 23 |
$action = optional_param('action',''); |
|---|
| 24 |
|
|---|
| 25 |
if ($action == 'add' || $action == 'change' ) { |
|---|
| 26 |
|
|---|
| 27 |
// Should at least make sure that the user does not try to |
|---|
| 28 |
// add a form with an empty or existing form name |
|---|
| 29 |
$form = form_set_form_definition(); |
|---|
| 30 |
$title = __gettext("Manage form \"{$form->title}\" ({$form->name})"); |
|---|
| 31 |
$body = form_get_form_form($form); |
|---|
| 32 |
if ($action == 'add') { |
|---|
| 33 |
$messages[] = __gettext("This form has been created."); |
|---|
| 34 |
} else { |
|---|
| 35 |
$messages[] = __gettext("Your changes to this form have been saved."); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
} else if ($action == 'delete') { |
|---|
| 39 |
$form_id = optional_param('id',0,PARAM_INT); |
|---|
| 40 |
delete_records('forms','ident',$form_id); |
|---|
| 41 |
delete_records('form_fields_map','form_id',$form_id); |
|---|
| 42 |
$messages[] = __gettext("The form has been deleted."); |
|---|
| 43 |
$redirect_url = $CFG->wwwroot.'mod/form/index.php'; |
|---|
| 44 |
|
|---|
| 45 |
} else { |
|---|
| 46 |
$form_id = optional_param('id',0,PARAM_INT); |
|---|
| 47 |
if ($form_id) { |
|---|
| 48 |
$form = form_get_form_definition($form_id); |
|---|
| 49 |
$body = form_get_form_form($form); |
|---|
| 50 |
$title = __gettext("Manage form \"{$form->title}\" ({$form->name})"); |
|---|
| 51 |
} else { |
|---|
| 52 |
$body = form_get_form_form(); |
|---|
| 53 |
$title = __gettext("Create form"); |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
} else { |
|---|
| 57 |
$body = __gettext("You must be logged in as a site administrator to view this page."); |
|---|
| 58 |
$title = __gettext("Error"); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
if ($redirect_url) { |
|---|
| 62 |
|
|---|
| 63 |
$_SESSION['messages'] = $messages; |
|---|
| 64 |
header("Location: $redirect_url"); |
|---|
| 65 |
} else { |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
$body = templates_draw(array( |
|---|
| 69 |
'context' => 'contentholder', |
|---|
| 70 |
'title' => $title, |
|---|
| 71 |
'body' => $body |
|---|
| 72 |
) |
|---|
| 73 |
); |
|---|
| 74 |
|
|---|
| 75 |
echo templates_page_draw( array( |
|---|
| 76 |
$title, $body |
|---|
| 77 |
) |
|---|
| 78 |
); |
|---|
| 79 |
} |
|---|
| 80 |
?> |
|---|