/[drupal]/contributions/modules/pageroute/pageroute.page_manage.inc
ViewVC logotype

Contents of /contributions/modules/pageroute/pageroute.page_manage.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Sat Sep 13 13:45:09 2008 UTC (14 months, 2 weeks ago) by tauran
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of pageroute d6 dev version.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Page user edit type
7 */
8
9 include_once(drupal_get_path('module', 'pageroute') .'/pageroute.page.inc');
10 include_once(drupal_get_path('module', 'pageroute') .'/pageroute.page_add.inc');
11 include_once(drupal_get_path('module', 'pageroute') .'/pageroute.page_edit.inc');
12
13 class pageroute_page_manage extends pageroute_page {
14 /*
15 * Shows a node management page for the given content type
16 * It determines itself what has to be displayed (overview, add/edit/delete form).
17 */
18
19 public function get_form(&$form_state, &$args) {
20 $form = array();
21
22 switch ($args['todo']['action']) {
23 case t('Add'):
24 $args['hide_pageroute_buttons'] = TRUE;
25 $args['submit_action'] = PAGEROUTE_CURRENT;
26 return pageroute_page_add::get_node_add_form(&$form_state, $this);
27
28 case t('Edit'):
29 $args['hide_pageroute_buttons'] = TRUE;
30 $args['submit_action'] = PAGEROUTE_CURRENT;
31 $args['nid'] = $args['todo']['target'];
32 return pageroute_page_edit::get_node_edit_form(&$form_state, $this, $args);
33
34 case t('Delete'):
35 $args['hide_pageroute_buttons'] = TRUE;
36 $args['submit_action'] = PAGEROUTE_CURRENT;
37 if (!is_numeric($args['todo']['target']) || !($node = node_load($args['todo']['target']))) {
38 drupal_not_found();
39 pageroute_exit_now();
40 }
41
42 return pageroute_node_delete_confirm($node, $form, $this, $args);
43
44 default:
45 $args['submit_action'] = PAGEROUTE_CURRENT;
46 $args['hide_pageroute_buttons'] = FALSE;
47 return pageroute_page_manage::pageroute_page_manage_overview($form_state, $this, $this->options['content-type']);
48 }
49 }
50
51 /*
52 * Shows the overview of node management page
53 */
54 public static function pageroute_page_manage_overview($form_state, $page, $content_type) {
55 $result = db_query(db_rewrite_sql("
56 SELECT n.nid FROM {node} n
57 WHERE n.type = '%s' AND n.uid = %d AND n.status > 0
58 ORDER BY n.created
59 "), $content_type, pageroute_page_get_uid($page));
60
61 $i = 1; $output = '';
62 while ($row = db_fetch_object($result)) {
63 $node = node_load($row->nid);
64
65 $buttons = array();
66
67 if (node_access('update', $node)) {
68 $buttons[] = t('Edit');
69 }
70 if (node_access('delete', $node)) {
71 $buttons[] = t('Delete');
72 }
73
74 if (count($buttons)) {
75 $form[$node->nid]['buttons'] = theme('pageroute_page_manage_buttons', $node, $i, $buttons);
76 $buttons = drupal_render($form[$node->nid]['buttons']);
77 }
78 $form['node_list'][$node->nid] = array('#value' => theme('pageroute_page_manage_node', $node, $i++, $buttons));
79 }
80
81 //there are no nodes yet
82 if ($i == 1) {
83 if ($page->options['empty']['force_add']) {
84 //mark that we have shown the empty add page, so that we can alter the redirect target correctly
85 //and we have to apply the add form settings now
86 $page->empty_add = TRUE;
87 $form['target']['#value'] = PAGEROUTE_FORWARD;
88 //re-add the buttons with the new settings
89 unset($form['buttons']);
90 pageroute_add_buttons($form, $page, 'page_op');
91 return pageroute_page_add($route, $page, $form);
92 }
93 $types = node_get_types('names');
94 $form['output'] = theme('pageroute_page_manage_empty', $types[$content_type], $page);
95 $add_button = $page->options['empty']['add_button'];
96 }
97 else {
98 $add_button = $page->options['add_button'];
99 //remember all possible node ids for the target hook
100 $form['node_ids'] = array('#type' => 'value', '#value' => array_keys($form['node_list']));
101 }
102
103 //add buttons
104 if ($add_button) {
105 $form['add_button'] = theme('pageroute_page_manage_add_button', $content_type, t($add_button));
106 }
107
108 return $form;
109 }
110
111 public static function ui($page, &$form) {
112 $form['options']['cancel']['#access'] = FALSE;
113 $form['options']['content-type'] = array(
114 '#type' => 'select',
115 '#title' => t('Content type'),
116 '#options' => node_get_types('names'),
117 '#required' => TRUE,
118 '#default_value' => isset($page->options['content-type']) ? $page->options['content-type'] : '',
119 '#weight' => 2,
120 );
121 $form['options']['add_button'] = array(
122 '#type' => 'textfield',
123 '#title' => t('Add button label'),
124 '#maxlength' => 64,
125 '#default_value' => isset($page->options['add_button']) ? $page->options['add_button'] : t('Add'),
126 '#description' => t('The label of the Add button. Leave it empty to hide the button.'),
127 '#weight' => 5,
128 );
129 $form['options']['empty'] = array(
130 '#type' => 'fieldset',
131 '#title' => t('Overview with no nodes'),
132 '#collapsed' => TRUE,
133 '#collapsible' => TRUE,
134 '#weight' => 6,
135 '#description' => t('Configure how the page looks like, if there is no node available to list.'),
136 );
137 $form['options']['empty']['force_add'] = array(
138 '#type' => 'radios',
139 '#title' => '',
140 '#default_value' => isset($page->options['empty']['force_add']) ? $page->options['empty']['force_add'] : 0,
141 '#options' => array(
142 0 => t('Show an add button and a short message that there is no node yet.'),
143 1 => t('Show a node add form.'),
144 ),
145 '#weight' => 0,
146 );
147 $form['options']['empty']['cancel'] = array(
148 '#type' => 'textfield',
149 '#title' => t('Cancel link label'),
150 '#maxlength' => 64,
151 '#default_value' => isset($page->options['empty']['cancel']) ? $page->options['empty']['cancel'] : t('Cancel'),
152 '#description' => t('If the node add form has been chosen, the label of the cancel link. Leave it empty to hide the link, but not that this would force the user to add a node.'),
153 '#weight' => 4,
154 );
155 $form['options']['empty']['add_button'] = array(
156 '#type' => 'textfield',
157 '#title' => t('Add button label'),
158 '#maxlength' => 64,
159 '#default_value' => isset($page->options['empty']['add_button']) ? $page->options['empty']['add_button'] : t('Add'),
160 '#description' => t('If shown, the label of the add button. Leave it empty to hide the button in any case.'),
161 '#weight' => 4,
162 );
163 $groups = array(
164 'add' => t('Node add form'),
165 'edit' => t('Node edit form')
166 );
167 foreach ($groups as $name => $title) {
168 $form['options'][$name] = array(
169 '#type' => 'fieldset',
170 '#title' => $title,
171 '#collapsed' => TRUE,
172 '#collapsible' => TRUE,
173 '#weight' => 8,
174 );
175 $form['options'][$name]['forward'] = array(
176 '#type' => 'textfield',
177 '#title' => t('Forward button label'),
178 '#maxlength' => 32,
179 '#default_value' => isset($page->options[$name]['forward']) ? $page->options[$name]['forward'] : t('Forward'),
180 '#description' => t('The label of the forward button. Leave it empty to hide the button.'),
181 '#weight' => 3,
182 );
183 $form['options'][$name]['back'] = array(
184 '#type' => 'textfield',
185 '#title' => t('Back button label'),
186 '#maxlength' => 32,
187 '#default_value' => isset($page->options[$name]['back']) ? $page->options[$name]['back'] : 'Back',
188 '#description' => t('The label of the back button. Leave it empty to hide the button.'),
189 '#weight' => 4,
190 );
191 $form['options'][$name]['cancel'] = array(
192 '#type' => 'textfield',
193 '#title' => t('Cancel link label'),
194 '#maxlength' => 32,
195 '#default_value' => isset($page->options[$name]['cancel']) ? $page->options[$name]['cancel'] : t('Cancel'),
196 '#description' => t('The label of the cancel link. Leave it empty to hide the link, but note that the link is the only possibility for the user to not save the form but staying in the route.'),
197 '#weight' => 4,
198 );
199 $form['options'][$name]['preview'] = array(
200 '#type' => 'checkbox',
201 '#title' => t('Display preview button'),
202 '#default_value' => isset($page->options[$name]['preview']) ? $page->options[$name]['preview'] : 0,
203 '#weight' => 5,
204 );
205 $form['options'][$name]['submit'] = array(
206 '#type' => 'checkbox',
207 '#title' => t('Display submit button'),
208 '#default_value' => isset($page->options[$name]['submit']) ? $page->options[$name]['submit'] : 1,
209 '#weight' => 5,
210 );
211 if ($name != 'add') {
212 $form['options'][$name]['nodelete'] = array(
213 '#type' => 'checkbox',
214 '#title' => t('Never display the delete button'),
215 '#default_value' => isset($page->options[$name]['nodelete']) ? $page->options[$name]['nodelete'] : 1,
216 '#weight' => 5,
217 );
218 $form['options'][$name]['#weight'] = 9;
219 }
220 }
221 }
222
223 public static function help() {
224 return t('The node management page allows one to add, edit or delete '.
225 'nodes from a configurable content type from inside one page! It shows a themeable '.
226 'list of already created nodes of the configured type and allows editing and deleting '.
227 'if the user has the appropriate access rights.');
228 }
229
230 public static function info() {
231 return array('name' => t('Node managment'));
232 }
233
234 public function get_cancel_target() {
235 return PAGEROUTE_CURRENT;
236 }
237
238 public static function form_submitted(&$form_state) {
239
240 switch ($form_state['clicked_button']['#value']) {
241 case t('Preview'):
242 $todo = $form_state['storage']['args']['todo'];
243 break;
244 case t('Delete'):
245 if (is_numeric($form_state['clicked_button']['#name'])) {
246 $target = $form_state['clicked_button']['#name'];
247 }
248 else {
249 $target = $form_state['storage']['args']['todo']['target'];
250 }
251 $todo = array('action' => $form_state['clicked_button']['#value'], 'target' => $target);
252 break;
253 case t('Save'):
254 unset($form_state['todo']);
255 $todo = NULL;
256 break;
257 default:
258 $todo = array('action' => $form_state['clicked_button']['#value'], 'target' => $form_state['clicked_button']['#name']);
259 }
260
261 $form_state['todo'] = $todo;
262 $form_state['target'] = PAGEROUTE_CURRENT; // stay on page, we may not get to submit (preview, error)
263 }
264
265 protected function set_up() {
266 include_once(drupal_get_path('module', 'node') .'/node.pages.inc');
267 }
268 }
269
270 /*
271 * Theme the display of the edit/delete buttons of an existing node
272 */
273 function theme_pageroute_page_manage_buttons($node, $number, $buttons) {
274
275 foreach ($buttons as $key => $name) {
276 $form[$name]['#attributes']['class'] = 'pageroute-'. $name;
277 $form[$name]['#type'] = 'submit';
278 $form[$name]['#value'] = $name;
279 $form[$name]['#name'] = $node->nid;
280 $form[$name]['#weight'] = $key;
281 }
282 $form['#prefix'] = '<span class="pageroute_manage_buttons">';
283 $form['#suffix'] = '</span>';
284
285 return $form;
286 }
287
288 /*
289 * Theme the display of a pageroute node management page
290 */
291 function theme_pageroute_page_manage_node(&$node, $number, &$buttons) {
292
293 $output = node_view($node, FALSE, TRUE, FALSE);
294 $output .= $buttons;
295
296 $title = check_plain(node_get_types('name', $node->type));
297 $title .= ' '. $number .' - '. $node->title;
298
299 $fieldset = array(
300 '#title' => $title,
301 '#collapsible' => TRUE,
302 '#collapsed' => FALSE,
303 '#children' => $output,
304 );
305 return theme('fieldset', $fieldset);
306 }
307
308
309 /*
310 * Theme the add node button
311 */
312 function theme_pageroute_page_manage_add_button($content_type, $label) {
313
314 $form_element['#attributes']['class'] = 'pageroute-add';
315 $form_element['#type'] = 'submit';
316 $form_element['#name'] = $content_type;
317 $form_element['#value'] = $label;
318 $form_element['#prefix'] = '<span class="pageroute_manage_add_button">';
319 $form_element['#suffix'] = '</span>';
320 return $form_element;
321 }
322
323 /*
324 * Themes an empty node list
325 */
326 function theme_pageroute_page_manage_empty($type_name, $page) {
327 $fieldset = array(
328 '#type' => 'fieldset',
329 '#title' => check_plain($type_name),
330 '#collapsible' => TRUE,
331 '#collapsed' => FALSE,
332 '#children' => '<p>'. t('There is no @type.', array('@type' => $type_name)) .'</p>',
333 );
334 return $fieldset;
335 }

  ViewVC Help
Powered by ViewVC 1.1.2