/[drupal]/contributions/modules/webform_paths/webform_paths.admin.inc
ViewVC logotype

Contents of /contributions/modules/webform_paths/webform_paths.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jan 13 23:41:13 2009 UTC (10 months, 1 week ago) by owahab
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit
1 <?php
2 /**
3 * @file webform_paths.admin.inc
4 * Administrative methods for webform_paths module.
5 *
6 * @author Omar Abdel-Wahab <owahab@owahab.com>
7 * @copyright: KnowledgeTree Inc
8 * @license: GPL 2 or any later version.
9 * @date 2009-01-01
10 */
11
12 /**
13 * Menu callback: Confirms deleting a webform path.
14 */
15 function webform_paths_delete_path_confirm($form_state, $pathid) {
16 $path = webform_paths_load($pathid);
17 if (user_access('administer webform paths')) {
18 $form['pathid'] = array('#type' => 'value', '#value' => $path->pathid);
19 $output = confirm_form($form,
20 t('Are you sure you want to delete webform path %title?', array('%title' => $path->path)),
21 isset($_GET['destination']) ? $_GET['destination'] : 'node/' . $path->nid .'/edit/webform_paths' );
22 }
23 return $output;
24 }
25
26 /**
27 * Executes webform path deletion.
28 *
29 * @param $form_id form id.
30 * @param $form_state form state array.
31 */
32 function webform_paths_delete_path_confirm_submit($form_id, &$form_state) {
33 $path = webform_paths_load($form_state['values']['pathid']);
34 path_set_alias(NULL, $path->path);
35 db_query('DELETE FROM {webform_paths} WHERE pathid = %d', $path->pathid);
36 drupal_set_message('Path deleted.');
37 $form_state['redirect'] = 'node/' . $path->nid .'/edit/webform_paths';
38 }
39
40 /**
41 * Menu callback: Displays the settings page for a given webform node.
42 *
43 * @param $node a node object.
44 * @param $pathid path id.
45 *
46 * @return HTML representation of the webform settings page.
47 */
48 function webform_paths_edit_node_settings($node, $pathid = NULL) {
49 // Show saved paths
50 $output = webform_paths_show_node_paths($node);
51 if (is_null($output)) {
52 $output = t('No paths defined for this webform.');
53 }
54 // Append the path form
55 $output .= drupal_get_form('webform_paths_path_form', array('nid' => $node->nid, 'pathid' => $pathid));
56 return $output;
57 }
58
59 /**
60 * Display a list of declared webform paths for a given node.
61 *
62 * @param $node a node object.
63 *
64 * @return HTML table of declared webform paths.
65 */
66 function webform_paths_show_node_paths($node) {
67 $output = NULL;
68 $header = array(
69 'Path',
70 'Title',
71 array('data' => 'Operations', 'colspan' => 2),
72 );
73 $rows = array();
74 $paths = webform_paths_get_node_paths($node);
75 foreach ($paths as $pathid => $path) {
76 $rows[] = array(
77 l($path['path'], $path['path']),
78 $path['title'],
79 l('edit', 'node/' . $node->nid . '/edit/webform_paths/' . $path['pathid'] . '/edit'),
80 l('delete', 'webform_paths/delete/'. $path['pathid']),
81 );
82 }
83 if (count($rows)) {
84 $output = theme('table', $header, $rows);
85 }
86 return $output;
87 }
88
89 /**
90 * Displays a creation or modification form for a given webform path.
91 *
92 * @param $form_state form state array.
93 * @param $values list of form values to override default values.
94 *
95 * @return a form array.
96 */
97 function webform_paths_path_form($form_state, $values = array()) {
98 if (!empty($values['pathid'])) {
99 $path = webform_paths_load($values['pathid']);
100 $values['title'] = $path->title;
101 $values['path'] = $path->path;
102 $values['message'] = $path->message;
103 }
104 $form = array();
105
106 $form['set'] = array(
107 '#type' => 'fieldset',
108 '#title' => ($values['pathid'] ? $values['title'] : t('Add a new path')),
109 '#collapsible' => TRUE,
110 '#collapsed' => (bool) !$values['pathid'],
111 );
112 $form['set']['pathid'] = array(
113 '#type' => 'hidden',
114 '#value' => $values['pathid'],
115 );
116 $form['set']['nid'] = array(
117 '#type' => 'hidden',
118 '#value' => $values['nid'],
119 );
120 $form['set']['path'] = array(
121 '#type' => 'textfield',
122 '#title' => t('Path'),
123 '#default_value' => $values['path'],
124 '#required' => TRUE,
125 );
126 $form['set']['title'] = array(
127 '#type' => 'textfield',
128 '#title' => t('Title'),
129 '#default_value' => $values['title'],
130 );
131 $form['set']['message'] = array(
132 '#type' => 'textarea',
133 '#title' => t('A message to display in the form page'),
134 '#default_value' => $values['thankyou'],
135 );
136 $form['set']['save'] = array(
137 '#type' => 'submit',
138 '#value' => t('Save'),
139 );
140 $form['set']['cancel'] = array(
141 '#type' => 'submit',
142 '#value' => t('Cancel'),
143 );
144
145 return $form;
146 }
147
148 /**
149 * Handles webform path saving.
150 *
151 * @param $form_id form id.
152 * @param $form_state form state array.
153 */
154 function webform_paths_path_form_submit($form_id, &$form_state) {
155 if ($form_state['values']['op'] == t('Save')) {
156 $path = $form_state['values'];
157 if (webform_paths_path_save($path) !== FALSE) {
158 drupal_set_message('Your configuration has been saved.');
159 }
160 else {
161 drupal_set_message('Unable to save path.');
162 }
163 }
164 $form_state['redirect'] = 'node/' . $form_state['values']['nid'] . '/edit/webform_paths';
165 }

  ViewVC Help
Powered by ViewVC 1.1.2