root/form/manage_form.php

Revision 277, 2.4 kB (checked in by kevin, 9 months ago)

First commit of form builder plugin

Line 
1 <?php
2
3 /*
4  * Elgg Forms
5  * Kevin Jardine
6  * Radagast Solutions
7  * http://radagast.biz
8  *
9  * The main function for creating and changing forms.
10  *
11  */
12  
13 // Load Elgg framework
14 @require_once("../../includes.php");
15     
16 // Define context
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         // TODO - analyse to see if error checking is required
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     // all done, so redirect to form page
63     $_SESSION['messages'] = $messages;
64     header("Location: $redirect_url");
65 } else {
66  
67      // Output to the screen
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 ?>
Note: See TracBrowser for help on using the browser.