#98492: Recent comments block needed to filter out moderated comments
[project/views.git] / views_ui.module
1 <?php
2 // $Id$
3
4 // ---------------------------------------------------------------------------
5 // Drupal Hooks
6
7 /*
8 * Implementation of hook_help()
9 */
10 function views_ui_help($section) {
11 switch ($section) {
12 case 'admin/help#views_ui':
13 return _views_ui_help_add();
14 case 'admin/build/views/import':
15 return t('You may import a view by cut-and-pasting the results of an export view. If the import is successful you will be taken to the Add View page with all of the settings of the imported view..');
16 case 'admin/build/views':
17 return t('This screen shows all of the views that are currently defined in your system. The default views are provided by Views and other modules and are automatically available. If a customized view of the same name exists, it will be used in place of a default view.');
18 }
19 if (!strncmp($section, 'admin/build/views', 11)) {
20 switch (arg(2)) {
21 case 'add':
22 case 'edit':
23 return t('Please see !s or the views documentation on drupal.org for help here.', array('!s' => l(t('the views help page'), 'admin/help/views_ui')));
24 case 'export':
25 return t('You may cut & paste this view into an import function on another system. The view will only work if all modules required by the view are installed on the target location.');
26 }
27 }
28 }
29
30 /*
31 * Because the add/edit page is kind of complicated.
32 */
33 function _views_ui_help_add() {
34 $output = t('<p>A view retrieves some number of nodes from the database and displays them in a variety of formats.</p>');
35 $output .= t("<h3>View Types</h3>
36 <dl>
37 <dt><em>List View</em></dt><dd>A List View provides the data for each node retrieved in the form of an unordered list. Each item in the Fields section will be displayed; the Title will be displayed as a label. The order the items appear in the Fields list is the order the items will appear in the output. Leaving the title blank will cause the field to appear with no label (which is desirable in lists that just display titles, for example).</dd>
38 <dt><em>Table View</em></dt><dd>A Table View provides the data for each node as one row of a table. The Fields selected in the Fields list will be displayed in the order they are listed. The title column will be shown in the header. If you set the field to 'sortable' then the header will be click-sortable; be careful here as click-sorts will be processed after built-in sort criteria, and built-in sort criteria can easily make click-sorts invalid. If using click-sorts, choose a field to be the default sort; otherwise the first field presented will be the default sort.</dd>
39 <dt><em>Teaser List</em></dt><dd>A Teaser List will simply present the teaser of each node retrieved.</dd>
40 <dt><em>Full Nodes</em></dt><dd>This will show the full content of each node retrieved.</dd>
41 <dt><em>Random Teaser</em></dt><dd>This will show a single random teaser.</dd>
42 <dt><em>Random Node</em></dt><dd>This will show a single random node's full view.</dd>
43 </dl>");
44
45 views_load_cache();
46 $output .= t("<h3>Fields</h3>\n");
47 $output .= t("<p>When using List or Table view, it is necessary to choose which fields will be displayed to the user.</p><dl>\n");
48 $fields = _views_get_fields();
49 foreach ($fields as $field) {
50 $output .= "<dt><em>$field[name]</em></dt><dd>$field[help]</dd>\n";
51 }
52 $output .= "</dl>\n";
53
54 $output .= t("<h3>Arguments</h3>\n");
55 $output .= t("<p>Arguments can be passed to the View through the URL, in order to create views that are configurable by the user. This is very useful to create views for taxonomy, or to sort by user. When using arguments, substitution is performed on the title. %1 will represent argument 1, %2 will represent argument 2. Each argument has a title field; this title is used if providing a summary view (which can matter because the argument is missing which could result in confusing phrases such as 'view for')</p><dl>\n");
56 $arguments = _views_get_arguments();
57 foreach ($arguments as $argument) {
58 $output .= "<dt><em>$argument[name]</em></dt><dd>$argument[help]</dd>\n";
59 }
60 $output .= "</dl>\n";
61
62 $output .= t("<h3>Filters</h3>\n");
63 $output .= t("<p>Views may be filtered to restrict the view on a number of criteria.</p><dl>\n");
64 $filters = _views_get_filters();
65 foreach ($filters as $filter) {
66 $output .= "<dt><em>$filter[name]</em></dt><dd>$filter[help]</dd>\n";
67 }
68 $output .= "</dl>\n";
69
70 $output .= t("<h3>Sorting Critera</h3>\n");
71 $output .= t("<p>The result set may be sorted on any of the following criteria.</p><dl>\n");
72 $sorts = _views_get_sorts();
73 foreach ($sorts as $sort) {
74 $output .= "<dt><em>$sort[name]</em></dt><dd>$sort[help]</dd>\n";
75 }
76 $output .= "</dl>\n";
77
78 return $output;
79 }
80
81 /*
82 * Implementation of hook_perm()
83 */
84 function views_ui_perm() {
85 return array('administer views');
86 }
87
88 /*
89 * Implementation of hook_menu()
90 */
91 function views_ui_menu($may_cache) {
92 $items = array();
93
94 if ($may_cache) {
95 $items[] = array('path' => 'admin/build/views',
96 'title' => t('Views'),
97 'callback' => 'views_ui_admin_page',
98 'access' => user_access('administer views'),
99 'description' => t('Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.'),
100 'type' => MENU_NORMAL_ITEM);
101 $items[] = array('path' => 'admin/build/views/list',
102 'title' => t('List'),
103 'callback' => 'views_ui_admin_page',
104 'access' => user_access('administer views'),
105 'type' => MENU_DEFAULT_LOCAL_TASK,
106 'weight' => '-1');
107 $items[] = array('path' => 'admin/build/views/add',
108 'title' => t('Add'),
109 'callback' => 'views_ui_admin_add_page',
110 'access' => user_access('administer views'),
111 'type' => MENU_LOCAL_TASK);
112 $items[] = array('path' => 'admin/build/views/clone',
113 'title' => t('Clone'),
114 'callback' => 'views_ui_admin_clone_page',
115 'access' => user_access('administer views'),
116 'type' => MENU_CALLBACK);
117 $items[] = array('path' => 'admin/build/views/edit',
118 'title' => t('Edit view'),
119 'callback' => 'views_ui_admin_edit_page',
120 'access' => user_access('administer views'),
121 'type' => MENU_CALLBACK);
122 $items[] = array('path' => 'admin/build/views/import',
123 'title' => t('Import'),
124 'callback' => 'views_ui_admin_import_page',
125 'access' => user_access('administer views'),
126 'type' => MENU_LOCAL_TASK);
127 $items[] = array('path' => 'admin/build/views/export',
128 'title' => t('Export view'),
129 'callback' => 'drupal_get_form',
130 'callback arguments' => array('views_ui_admin_export_page'),
131 'access' => user_access('administer views'),
132 'type' => MENU_CALLBACK);
133 $items[] = array('path' => 'admin/build/views/delete',
134 'title' => t('Edit view'),
135 'callback' => 'drupal_get_form',
136 'callback arguments' => array('views_ui_admin_delete_confirm'),
137 'access' => user_access('administer views'),
138 'type' => MENU_CALLBACK);
139 $items[] = array('path' => 'admin/build/views/enable',
140 'callback' => 'views_ui_admin_enable_page',
141 'access' => user_access('administer views'),
142 'type' => MENU_CALLBACK);
143 $items[] = array('path' => 'admin/build/views/disable',
144 'callback' => 'views_ui_admin_disable_page',
145 'access' => user_access('administer views'),
146 'type' => MENU_CALLBACK);
147
148 }
149 return $items;
150 }
151
152 // ---------------------------------------------------------------------------
153 // Administrative Pages
154
155 /*
156 * This page lists all system views and provides links to edit them.
157 */
158 function views_ui_admin_page() {
159 views_load_cache();
160
161 $numViews = 25;
162
163 drupal_set_title(t('administer views'));
164
165 $result = pager_query("SELECT vid, name, description, menu_title, page_title, block_title, url, page, menu, block FROM {view_view} ORDER BY name", $numViews);
166
167 while ($view = db_fetch_object($result)) {
168 $url = ($view->page ? l($view->url, $view->url) : t('No Page View'));
169 $provides = array();
170 if ($view->page) {
171 $provides[] = 'Page';
172 }
173 if ($view->block) {
174 $provides[] = 'Block';
175 }
176 if ($view->menu) {
177 $provides[] = 'Menu';
178 }
179 $items[] = array(
180 $view->name,
181 views_get_title($view, 'menu'),
182 $view->description,
183 implode(', ', $provides),
184 $url,
185 theme('links', array(
186 array('title' => t('Edit'), 'href' => "admin/build/views/edit/$view->vid"),
187 array('title' => t('Export'), 'href' => "admin/build/views/export/$view->vid"),
188 array('title' => t('Delete'), 'href' => "admin/build/views/delete/$view->vid"),
189 array('title' => t('Clone'), 'href' => "admin/build/views/clone/$view->vid"),
190 ))
191 );
192 }
193
194 if ($items) {
195 $output = theme('table', array(t('View'), t('Title'), t('Description'), t('Provides'), t('URL'), t('Actions')), $items, array("cellpadding" => "4"), t('Existing Views'));
196 $output .= theme('pager', NULL, $numViews);
197 }
198 else {
199 $output .= t('<p>No views have currently been defined.</p>');
200 }
201
202 $result = db_query("SELECT name FROM {view_view}");
203 while ($view = db_fetch_object($result)) {
204 $used[$view->name] = true;
205 }
206
207 $output .= t('<p>Below are system default views; if you edit one of these, a view will be created that will override any system use of the view.</p>');
208 $items = array();
209 $default_views = _views_get_default_views();
210
211 $views_status = variable_get('views_defaults', array());
212
213 foreach ($default_views as $view) {
214 $url = ($view->page ? l($view->url, $view->url) : t('No Page View'));
215
216 if ($used[$view->name]) {
217 $status = t('Overridden');
218 }
219 else if (isset($views_status[$view->name])) {
220 if ($views_status[$view->name] == 'enabled') {
221 $status = t('Enabled');
222 }
223 else {
224 $status = t('Disabled');
225 }
226 }
227 else if ($view->disabled) {
228 $status = t('Disabled');
229 }
230 else {
231 $status = t('Enabled');
232 }
233
234 $provides = array();
235 if ($view->page) {
236 $provides[] = t('Page');
237 }
238 if ($view->block) {
239 $provides[] = t('Block');
240 }
241 if ($view->menu) {
242 $provides[] = t('Menu');
243 }
244
245 $links = array();
246 $links[] = array('title' => t('Add'), 'href' => "admin/build/views/add/$view->name");
247 if ($status == t('Enabled')) {
248 $links[] = array('title' => t('Disable'), 'href' => "admin/build/views/disable/$view->name");
249 }
250 else if ($status == t('Disabled')) {
251 $links[] = array('title' => t('Enable'), 'href' => "admin/build/views/enable/$view->name");
252 }
253
254 $items[] = array($view->name, views_get_title($view, 'menu'), $view->description, implode(', ', $provides), $url, $status, theme('links', $links));
255 }
256
257 if ($items) {
258 $output .= theme('table', array(t('Default view'), t('Title'), t('Description'), t('Provides'), t('URL'), t('Status'), t('Actions')), $items, array("cellpadding" => "4"), t('Default Views'));
259 }
260 else {
261 $output .= t('<p>No views have currently been defined.</p>');
262 }
263
264 return $output;
265 }
266
267 /*
268 * Page to enable a disabled default view
269 */
270 function views_ui_admin_enable_page($view = '') {
271 views_load_cache();
272
273 if ($view) {
274 $views_status = variable_get('views_defaults', array());
275 $views_status[$view] = 'enabled';
276 variable_set('views_defaults', $views_status);
277 menu_rebuild();
278 }
279 drupal_goto('admin/build/views');
280 }
281
282 /*
283 * Page to disable an enabled default view
284 */
285 function views_ui_admin_disable_page($view = '') {
286 views_load_cache();
287
288 if ($view) {
289 $views_status = variable_get('views_defaults', array());
290 $views_status[$view] = 'disabled';
291 variable_set('views_defaults', $views_status);
292 menu_rebuild();
293 }
294 drupal_goto('admin/build/views');
295 }
296
297 /*
298 * Provide a textarea to paste a view export into.
299 */
300 function views_ui_admin_import_page() {
301 views_load_cache();
302
303 if ($_POST['form_id'] == 'views_edit_view') {
304 return views_ui_admin_add_page();
305 }
306 drupal_set_title("Import a View");
307
308 return drupal_get_form('views_ui_admin_import', $form);
309 }
310
311 function views_ui_admin_import() {
312 $form['view'] = array(
313 '#type' => 'textarea',
314 '#title' => t('Import View Code'),
315 '#cols' => 60,
316 '#rows' => 6,
317 '#description' => t('Cut and paste the results of an Export View here.'),
318 );
319
320 $form['submit'] = array(
321 '#type' => 'submit',
322 '#value' => t("Submit"),
323 );
324
325 $form['#redirect'] = NULL;
326 return $form;
327 }
328
329 /*
330 * Handle the submit button on importing a view.
331 */
332 function views_ui_admin_import_submit($formid, $form) {
333 ob_start();
334 eval($form['view']);
335 ob_end_clean();
336
337 $tables = array_keys(_views_get_tables());
338 if ($view) {
339 if (!is_array($view->requires) || !array_diff($view->requires, $tables)) {
340 views_sanitize_view($view);
341 drupal_set_title(t('Add a View'));
342 $output = drupal_get_form('views_edit_view', $view, NULL);
343 print theme('page', $output);
344 exit;
345 }
346 else {
347 drupal_set_message(t("You don't seem to have the following requirements: ") . implode(', ', array_diff($view->requires, $tables)));
348 }
349 }
350 else {
351 drupal_set_message(t('Unable to get a view out of that.'));
352 }
353 }
354
355 /*
356 * Export a view for cut & paste.
357 */
358 function views_ui_admin_export_page($vid = '') {
359 views_load_cache();
360
361 $code = views_create_view_code($vid);
362 $lines = substr_count($code, "\n");
363 $form['code'] = array(
364 '#type' => 'textarea',
365 '#title' => $view->name,
366 '#default_value' => $code,
367 '#rows' => $lines);
368 return $form;
369 }
370
371 /*
372 * Provide a form to add a view. Allow adding a view from default templates.
373 */
374 function views_ui_admin_add_page($template = NULL) {
375 views_load_cache();
376
377 $op = $_POST['op'];
378 if ($op == t('Cancel')) {
379 return 'admin/build/views';
380 }
381
382 $view = _views_get_default_view($template);
383
384 drupal_set_title(t('Add a View'));
385
386 return drupal_get_form('views_edit_view', $view, $op);
387 }
388
389 /*
390 * Provide a form to clone a view.
391 */
392 function views_ui_admin_clone_page($viewname) {
393 views_load_cache();
394
395 $op = $_POST['op'];
396 if ($op == t('Cancel')) {
397 return 'admin/build/views';
398 }
399
400 $view = views_load_view($viewname);
401 if (!$view) {
402 return drupal_not_found();
403 }
404
405 unset($view->vid);
406 drupal_set_title(t('Add a View'));
407
408 return drupal_get_form('views_edit_view', $view, $op);
409 }
410
411 /*
412 * Provide a form to edit a view.
413 */
414 function views_ui_admin_edit_page($vid = '') {
415 views_load_cache();
416
417 $op = $_POST['op'];
418 if ($op == t('Cancel')) {
419 drupal_goto('admin/build/views');
420 }
421
422 if ($op == t('Delete')) {
423 drupal_goto("admin/build/views/delete/$vid");
424 }
425
426 if (!($view = _views_load_view($vid))) {
427 drupal_goto('admin/build/views');
428 }
429
430 drupal_set_title(t('Edit view %n', array('%n' => $view->name)));
431 return drupal_get_form('views_edit_view', $view, $op);
432 }
433
434 /*
435 * Provide a form to confirm deletion of a view.
436 */
437 function views_ui_admin_delete_confirm($vid = '') {
438 $view = _views_load_view($vid);
439
440 if (!$view) {
441 return drupal_goto('admin/build/views');
442 }
443
444 $form['vid'] = array('#type' => 'value', '#value' => $view->vid);
445 // bdragon note: Did you mean to drop the above line on the floor with this?
446 $form = confirm_form($form,
447 t('Are you sure you want to delete %title?', array('%title' => $view->name)),
448 $_GET['destination'] ? $_GET['destination'] : 'admin/build/views',
449 t('This action cannot be undone.'),
450 t('Delete'), t('Cancel')
451 );
452 return $form;
453 }
454
455 /*
456 * Handle the submit button to delete a view.
457 */
458 function views_ui_admin_delete_confirm_submit($form_id, $form) {
459 _views_delete_view((object) $form);
460 menu_rebuild();
461 drupal_goto('admin/build/views');
462 }
463
464 /*
465 * Get an empty view with basic defaults.
466 */
467 function _views_get_default_view($template = '') {
468 if ($template) {
469 $default_views = _views_get_default_views();
470 if (isset($default_views[$template])) {
471 $view = $default_views[$template];
472 }
473 }
474 if (!$view) {
475 $view = new stdClass();
476 $view->use_pager = true;
477 $view->nodes_per_page = variable_get('default_nodes_main', 10);
478 $view->page_header_format = variable_get('filter_default_format', 1);
479 $view->page_footer_format = variable_get('filter_default_format', 1);
480 $view->page_header_format = variable_get('filter_default_format', 1);
481 $view->block_header_format = variable_get('filter_default_format', 1);
482 $view->block_footer_format = variable_get('filter_default_format', 1);
483 $view->block_header_format = variable_get('filter_default_format', 1);
484 $view->vid = 0;
485 }
486
487 return _views_check_arrays($view);
488 }
489
490 // ---------------------------------------------------------------------------
491 // Select Box Definitions
492
493 // These should probably have string array keys that are easier to identify.
494
495 /**
496 * Select box entries for argument defaults.
497 */
498 function _views_get_arguments_default() {
499 return array(
500 1 => t('Return Page Not Found'),
501 2 => t('Display All Values'),
502 3 => t('Summary, unsorted'),
503 4 => t('Summary, sorted ascending'),
504 5 => t('Summary, sorted descending'),
505 6 => t('Summary, sorted as view'),
506 7 => t('Use Empty Text'),
507 );
508 }
509
510 /**
511 * Select box entries for sort ordering.
512 */
513 function _views_sortorders() {
514 return array(
515 'ASC' => t('Ascending'),
516 'DESC' => t('Descending')
517 );
518 }
519
520 /**
521 * Swap two items in an array.
522 */
523 function _views_swap(&$arr, $a, $b) {
524 $temp = $arr[$a];
525 $arr[$a] = $arr[$b];
526 $arr[$b] = $temp;
527 }
528
529 /**
530 * Move an item up in an array.
531 */
532 function _views_move_up(&$arr, $i) {
533 if ($i <= 0 || $i >= count($arr)) {
534 return; // can't do it.
535 }
536 _views_swap($arr, $i - 1, $i);
537 }
538
539 /**
540 * Move an item down in an array.
541 */
542 function _views_move_down(&$arr, $i) {
543 if ($i >= count($arr) - 1 || $i < 0) {
544 return; // can't do it.
545 }
546 _views_swap($arr, $i + 1, $i);
547 }
548
549 /**
550 * Move an item to the front of an array.
551 */
552 function _views_move_top(&$arr, $i) {
553 if ($i <= 0 || $i >= count($arr)) {
554 return; // can't do it.
555 }
556 $temp = $arr[$i];
557 for ($x = $i; $x > 0; $x--)
558 $arr[$x] = $arr[$x - 1];
559 $arr[0] = $temp;
560 }
561
562 /**
563 * Move an item to the end of an array.
564 */
565 function _views_move_bottom(&$arr, $i) {
566 $end = count($arr) - 1;
567 if ($i >= $end || $i < 0) {
568 return; // can't do it.
569 }
570 $temp = $arr[$i];
571 for ($x = $i; $x < $end; $x++)
572 $arr[$x] = $arr[$x + 1];
573 $arr[$end] = $temp;
574 }
575
576 /**
577 * Figure out which of the many, many buttons on a form were clicked and
578 * handle it.
579 */
580 function _views_check_sub_ops(&$form, &$order, $i) {
581
582 if ($form['delete']['#value']) {
583 unset($form['delete']['#value']);
584 unset($order[$i]);
585 $order = array_values($order); // reindex
586 $form['delete']['#printed'] = true;
587 $form['up']['#printed'] = true;
588 $form['down']['#printed'] = true;
589 $form['top']['#printed'] = true;
590 $form['bottom']['#printed'] = true;
591 return 'delete';
592 }
593 else foreach (array('up', 'down', 'top', 'bottom') as $dir) {
594 if ($form[$dir]['#value']) {
595 unset ($form[$dir]['#value']);
596 $func = "_views_move_$dir";
597 $func($order, $i);
598 return true;
599 }
600 }
601 return false;
602 }
603
604 /**
605 * Figure out if one of the add buttons on a form were clicked, and handle it.
606 */
607 function _views_check_ops(&$view, $op, $form) {
608 if ($op == t('Add Filter')) {
609 $view->new_filter['id'] = $form['filter']['add']['id']['#value'];
610 return 'filter';
611 }
612 else if ($op == t('Add Criteria')) {
613 $view->new_sort['id'] = $form['sort']['add']['id']['#value'];
614 return 'sort';
615 }
616 else if ($op == t('Add Argument')) {
617 $view->new_argument['id'] = $form['argument']['add']['id']['#value'];
618 return 'argument';
619 }
620 else if ($op == t('Add Field')) {
621 $fieldbits = explode('.', $form['field']['add']['id']['#value']);
622 $view->new_field['id'] = $form['field']['add']['id']['#value'];
623 $view->new_field['tablename'] = $fieldbits[0];
624 $view->new_field['field'] = $fieldbits[1];
625 $view->new_field['label'] = $fieldnames[$form['field']['add']['id']['#value']];
626 $view->new_field['queryname'] = "$fieldbits[0]_$fieldbits[1]";
627 return 'field';
628 }
629 else if ($op == t('Expose Filter')) {
630 $view->new_exposed_filter['id'] = $form['exposed_filter']['add']['id']['#value'];
631 return 'filter';
632 }
633 }
634
635 /**
636 * Custom form element to do our nice images.
637 */
638 function views_elements() {
639 $type['views_imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit',);
640 return $type;
641 }
642
643 function theme_views_imagebutton($element) {
644 return '<input type="image" class="form-'. $element['#button_type'] .'" name="'. $element['#name'] .'" value="'. check_plain($element['#default_value']) .'" '. drupal_attributes($element['#attributes']) . ' src="' . $element['#image'] . '" alt="' . $element['#title'] . '" title="' . $element['#title'] . "\" />\n";
645 }
646
647 function views_imagebutton_value() {
648 // null function guarantees default_value doesn't get moved to #value.
649 }
650
651 /**
652 * Set up the dynamic #options on a widget
653 */
654 function views_ui_setup_widget($widget, $default_value, $argument = NULL) {
655 if (!$argument) {
656 $argument = $widget;
657 }
658
659 if (is_string($widget['#options']) && function_exists($widget['#options'])) {
660 $widget['#options'] = $widget['#options']('option', $argument);
661 }
662 if ($widget['#multiple'] && is_array($widget['#options'])) {
663 $widget['#size'] = min(count($widget['#options']), 8);
664 }
665 $widget['#default_value'] = $default_value;
666 return $widget;
667 }
668
669 /**
670 * Display all the guts of a view in a form for editing.
671 */
672 function views_edit_view($view, $op = '') {
673 _views_check_arrays($view); // make sure arrays that might be empty get set
674
675 // Put in all our add buttons, then process them to see if they've been hit.
676 $form = array();
677 views_ui_add_add_button($form, 'field', _views_get_fields(true), t('Add Field'));
678 views_ui_add_add_button($form, 'argument', _views_get_arguments(true), t('Add Argument'));
679 views_ui_add_add_button($form, 'filter', _views_get_filters(true), t('Add Filter'));
680 views_ui_add_add_button($form, 'sort', _views_get_sorts(true), t('Add Criteria'));
681
682 $allbut = _views_check_ops($view, $op, $form);
683 if ($_POST['edit'] && $op != t('Save')) {
684 drupal_set_message(t('You have modified this view; changes will not be recorded until you Save the form.'));
685 }
686
687 $form['exposed_filter'] = array();
688 foreach (array('field', 'argument', 'filter', 'exposed_filter', 'sort') as $section) {
689 if (views_ui_add_section($form[$section], $view, $section)) {
690 $allbut = $section;
691 }
692 }
693
694 $form['vid'] = array(
695 '#type' => 'value',
696 '#value' => $view->vid,
697 );
698 $form['allbut'] = array(
699 '#type' => 'value',
700 '#value' => $allbut,
701 );
702 $form['changed'] = array(
703 '#type' => 'hidden',
704 '#value' => $view->changed,
705 );
706
707 $form['basic-info'] = array(
708 '#type' => 'fieldset',
709 '#collapsible' => true,
710 '#collapsed' => ($allbut != NULL),
711 '#title' => t('Basic Information'),
712 );
713
714 $form['basic-info']['name'] = array(
715 '#type' => 'textfield',
716 '#title' => t('Name'),
717 '#default_value' => $view->name,
718 '#size' => 20,
719 '#maxlength' => 32,
720 '#description' => t('The unique identifier of the view; it is only important for overridden views and views that modules or themes will need to use. Only alphanumeric and _ allowed here'),
721 '#required' => true,
722 );
723
724 $form['basic-info']['access'] = array(
725 '#type' => 'checkboxes',
726 '#title' => t('Access'),
727 '#default_value' => $view->access,
728 '#options' => views_handler_filter_role(),
729 '#description' => t('Only the checked roles will be able to see this view in any form; if no roles are checked, access will not be restricted.'),
730 );
731
732 $form['basic-info']['description'] = array(
733 '#type' => 'textfield',
734 '#title' => t('Description'),
735 '#default_value' => $view->description,
736 '#size' => 60,
737 '#maxlength' => 255,
738 '#description' => t('A description of the view for the admin list.'),
739 );
740
741 // page info
742
743 $form['page-info'] = array(
744 '#type' => 'fieldset',
745 '#collapsible' => true,
746 '#collapsed' => ($allbut != NULL || !$view->page),
747 '#title' => t('Page'),
748 );
749
750 $form['page-info']['page'] = array(
751 '#type' => 'checkbox',
752 '#title' => t('Provide Page View'),
753 '#return_value' => 1,
754 '#default_value' => $view->page,
755 '#description' => t('If checked this view will be provided as a page. If not checked, the fields in this group will be ignored.'),
756 );
757
758 $form['page-info']['url'] = array(
759 '#type' => 'textfield',
760 '#title' => t('URL'),
761 '#default_value' => $view->url,
762 '#size' => 60,
763 '#maxlength' => 255,
764 '#description' => t('Enter the URL to use for this view in the form of \'dir/dir\'. Do not begin or end the URL with a /. Example: \'view/tracker\'. This is required if providing a page view. You can also add $arg as a placeholder for arguments passed in the URL, for example \'user/$arg/tracker\' or \'view/taxonomy/$arg\'. Note that any arguments listed here will be required, even if they are listed as optional below. You do not need to list arguments at the end of the path.'),
765 );
766
767 $form['page-info']['page_type'] = array(
768 '#type' => 'select',
769 '#title' => t('View Type'),
770 '#default_value' => $view->page_type,
771 '#options' => _views_get_style_plugins(true),
772 '#description' => t('How the nodes should be displayed to the user.'),
773 );
774
775 $form['page-info']['page_title'] = array(
776 '#type' => 'textfield',
777 '#title' => t('Title'),
778 '#default_value' => $view->page_title,
779 '#size' => 60,
780 '#maxlength' => 255,
781 '#description' => t('The title that be shown at the top of the view. May be blank. This title ignores arguments; if you want your title to take arguments into account, use the "title" field in the arguments section.'),
782 );
783
784 $form['page-info']['use_pager'] = array(
785 '#type' => 'checkbox',
786 '#title' => t('Use Pager'),
787 '#return_value' => 1,
788 '#default_value' => $view->use_pager,
789 '#description' => t('If checked this query may be multiple pages. If not checked this query will be one page.'),
790 );
791 $form['page-info']['breadcrumb_no_home'] = array(
792 '#type' => 'checkbox',
793 '#title' => t('Breadcrumb trail should not include "Home"'),
794 '#return_value' => 1,
795 '#default_value' => $view->breadcrumb_no_home,
796 '#description' => t('If checked the breadcrumb trail for this page will discard "Home". Usually you will not set this, but this is used for the Front Page View, where it IS Home and should not leave a trail to itself.'),
797 );
798 $form['page-info']['nodes_per_page'] = array(
799 '#type' => 'textfield',
800 '#title' => t('Nodes per Page'),
801 '#default_value' => intval($view->nodes_per_page),
802 '#size' => 5,
803 '#maxlength' => 5,
804 '#description' => t('The number of nodes to display per page. If 0, all nodes will be displayed. If not using a pager, this will be the maximum number of nodes in the list.'),
805 '#attributes' => NULL,
806 );
807 $form['page-info']['page_header_fieldset'] = array(
808 '#type' => 'fieldset',
809 '#collapsible' => TRUE,
810 '#collapsed' => TRUE,
811 '#title' => t('Header'),
812 );
813 $form['page-info']['page_header_fieldset']['page_header'] = array(
814 '#type' => 'textarea',
815 '#default_value' => $view->page_header,
816 '#cols' => 60,
817 '#rows' => 6,
818 '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
819 );
820
821 $form['page-info']['page_header_fieldset']['page_header_format'] = filter_form($view->page_header_format, 1, array('page_header_format'));
822
823 $form['page-info']['page_footer_fieldset'] = array(
824 '#type' => 'fieldset',
825 '#collapsible' => TRUE,
826 '#collapsed' => TRUE,
827 '#title' => t('Footer'),
828 );
829 $form['page-info']['page_footer_fieldset']['page_footer'] = array(
830 '#type' => 'textarea',
831 '#default_value' => $view->page_footer,
832 '#cols' => 60,
833 '#rows' => 6,
834 '#description' => t('Text to display at the bottom of the view. May contain an explanation or links or whatever you like. Optional.'),
835 );
836
837 $form['page-info']['page_footer_fieldset']['page_footer_format'] = filter_form($view->page_footer_format, 1, array('page_footer_format'));
838
839 $form['page-info']['page_empty_fieldset'] = array(
840 '#type' => 'fieldset',
841 '#collapsible' => TRUE,
842 '#collapsed' => TRUE,
843 '#title' => t('Empty Text'),
844 );
845 $form['page-info']['page_empty_fieldset']['page_empty'] = array(
846 '#type' => 'textarea',
847 '#default_value' => $view->page_empty,
848 '#cols' => 60,
849 '#rows' => 6,
850 '#description' => t('Text to display if a view returns no nodes. Optional.'),
851 );
852
853 $form['page-info']['page_empty_fieldset']['page_empty_format'] = filter_form($view->page_empty_format, 1, array('page_empty_format'));
854
855 $form['page-info']['menu-info'] = array(
856 '#type' => 'fieldset',
857 '#collapsible' => TRUE,
858 '#collapsed' => TRUE,
859 '#title' => t('Menu'),
860 );
861
862 $form['page-info']['menu-info']['menu'] = array(
863 '#type' => 'checkbox',
864 '#title' => t('Provide Menu'),
865 '#return_value' => 1,
866 '#default_value' => $view->menu,
867 '#description' => t('If checked this view be given a menu entry in the Drupal menu system. If not checked the data in this group will be ignored.'),
868 );
869
870 $form['page-info']['menu-info']['menu_tab'] = array(
871 '#type' => 'checkbox',
872 '#title' => t('Provide Menu as Tab'),
873 '#return_value' => 1,
874 '#default_value' => $view->menu_tab,
875 '#description' => t("If checked this view's menu entry will be provided as a tab rather than in the main menu system."),
876 );
877
878 $form['page-info']['menu-info']['menu_tab_default'] = array(
879 '#type' => 'checkbox',
880 '#title' => t('Make Default Menu Tab'),
881 '#return_value' => 1,
882 '#default_value' => $view->menu_tab_default,
883 '#description' => t("If checked this view's menu entry will be provided as a tab, and will be the default tab for that URL path. For example, if the URL is 'tracker/all' and it is set as the default menu tab, it will be put into the menu as 'tracker' and 'tracker/all' will be the default tab. For tabs to work properly, one tab in the group must be set as the default."),
884 );
885
886 $form['page-info']['menu-info']['menu_tab_weight'] = array(
887 '#type' => 'textfield',
888 '#title' => t('Tab Weight'),
889 '#default_value' => $view->menu_tab_weight,
890 '#width' => 10,
891 '#description' => t('If this is a menu tab, select the weight; lower numbers will be further to the left.'),
892 );
893
894 $form['page-info']['menu-info']['menu_title'] = array(
895 '#type' => 'textfield',
896 '#title' => t('Menu Title'),
897 '#default_value' => $view->menu_title,
898 '#size' => 60,
899 '#maxlength' => 255,
900 '#description' => t('Enter the title to use for the menu entry or tab. If blank, the page title will be used.'),
901 );
902
903 // block info
904
905 $form['block-info'] = array(
906 '#type' => 'fieldset',
907 '#collapsible' => true,
908 '#collapsed' => ($allbut != NULL || !$view->block),
909 '#title' => t('Block'),
910 );
911
912 $form['block-info']['block'] = array(
913 '#type' => 'checkbox',
914 '#title' => t('Provide Block'),
915 '#return_value' => 1,
916 '#default_value' => $view->block,
917 '#description' => t('If checked this view will be provided as a block. If checked title may not be blank.'),
918 );
919
920 $form['block-info']['block_type'] = array(
921 '#type' => 'select',
922 '#title' => t('View Type'),
923 '#default_value' => $view->block_type,
924 '#options' => _views_get_style_plugins(true),
925 '#description' => t('How the nodes should be displayed to the user.'),
926 );
927
928 $form['block-info']['block_title'] = array(
929 '#type' => 'textfield',
930 '#title' => t('Title'),
931 '#default_value' => $view->block_title,
932 '#size' => 60,
933 '#maxlength' => 255,
934 '#description' => t('The title that will be shown at the top of the block. May be blank.'),
935 );
936
937 $form['block-info']['nodes_per_block'] = array(
938 '#type' => 'textfield',
939 '#title' => t('Nodes per Block'),
940 '#default_value' => $view->nodes_per_block,
941 '#size' => 2,
942 '#maxlength' => 2,
943 '#description' => t('If using a block, the maximum number of items to display in the block. Pagers are not used in blocks.'),
944 '#attributes' => NULL,
945 );
946
947 $form['block-info']['block_more'] = array(
948 '#type' => 'checkbox',
949 '#title' => t('[More] Link?'),
950 '#return_value' => 1,
951 '#default_value' => $view->block_more,
952 '#description' => t('If using a view as both a page and a block, display a more link in the block that links to the view URL?'),
953 );
954
955 $form['block-info']['block_header_fieldset'] = array(
956 '#type' => 'fieldset',
957 '#collapsible' => TRUE,
958 '#collapsed' => TRUE,
959 '#title' => t('Header'),
960 );
961 $form['block-info']['block_header_fieldset']['block_use_page_header'] = array(
962 '#type' => 'checkbox',
963 '#title' => t('Use Page Header'),
964 '#return_value' => 1,
965 '#default_value' => $view->block_use_page_header,
966 '#description' => t('If checked, use the Page Header for block view instead. If so, you should leave the Block Header blank.'),
967 );
968
969 $form['block-info']['block_header_fieldset']['block_header'] = array(
970 '#type' => 'textarea',
971 '#title' => t('Header'),
972 '#default_value' => $view->block_header,
973 '#cols' => 60,
974 '#rows' => 6,
975 '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
976 );
977
978 $form['block-info']['block_header_fieldset']['block_header_format'] = filter_form($view->block_header_format, 1, array( 'block_header_format'));
979
980 $form['block-info']['block_footer_fieldset'] = array(
981 '#type' => 'fieldset',
982 '#collapsible' => TRUE,
983 '#collapsed' => TRUE,
984 '#title' => t('Footer'),
985 );
986 $form['block-info']['block_footer_fieldset']['block_use_page_footer'] = array(
987 '#type' => 'checkbox',
988 '#title' => t('Use Page Footer'),
989 '#return_value' => 1,
990 '#default_value' => $view->block_use_page_footer,
991 '#description' => t('If checked, use the page footer for block view instead. If so, you should leave the block footer blank.'),
992 );
993
994 $form['block-info']['block_footer_fieldset']['block_footer'] = array(
995 '#type' => 'textarea',
996 '#title' => t('Footer'),
997 '#default_value' => $view->block_footer,
998 '#cols' => 60,
999 '#rows' => 6,
1000 '#description' => t('Text to display at the bottom of the view. May contain an explanation or links or whatever you like. Optional.'),
1001 );
1002
1003 $form['block-info']['block_footer_fieldset']['block_footer_format'] = filter_form($view->block_footer_format, 1, array( 'block_footer_format'));
1004
1005 $form['block-info']['block_empty_fieldset'] = array(
1006 '#type' => 'fieldset',
1007 '#collapsible' => TRUE,
1008 '#collapsed' => TRUE,
1009 '#title' => t('Empty text'),
1010 );
1011 $form['block-info']['block_empty_fieldset']['block_use_page_empty'] = array(
1012 '#type' => 'checkbox',
1013 '#title' => t('Use Page empty'),
1014 '#return_value' => 1,
1015 '#default_value' => $view->block_use_page_empty,
1016 '#description' => t('If checked, use the Page Empty Text for block view instead. If so, you should leave the block empty text blank.'),
1017 );
1018
1019 $form['block-info']['block_empty_fieldset']['block_empty'] = array(
1020 '#type' => 'textarea',
1021 '#title' => t('Empty text'),
1022 '#default_value' => $view->block_empty,
1023 '#cols' => 60,
1024 '#rows' => 6,
1025 '#description' => t('Text to display if a view results in no nodes. Optional.'),
1026 );
1027
1028 $form['block-info']['block_empty_fieldset']['block_empty_format'] = filter_form($view->block_empty_format, 1, array( 'block_empty_format'));
1029
1030 $access = user_access('use PHP for block visibility');
1031 if ($access) {
1032 $form['view_args_php_fieldset'] = array(
1033 '#type' => 'fieldset',
1034 '#collapsible' => TRUE,
1035 '#collapsed' => empty($view->view_args_php) ? TRUE : FALSE,
1036 '#title' => t('Argument Handling Code'),
1037 );
1038
1039 $form['view_args_php_fieldset']['view_args_php'] = array(
1040 '#type' => 'textarea',
1041 '#title' => t('Argument Code'),
1042 '#default_value' => $view->view_args_php,
1043 '#cols' => 60,
1044 '#rows' => 6,
1045 '#description' => '<p>'. t('Advanced Usage Only: PHP code that returns a custom array of arguments for the view. Should not include &lt;?php ?&gt; delimiters.') .'</p>' .
1046 '<p>'. t('For more information, please see the <a href="!arg">Argument Handling Code documentation</a> in the Drupal handbook.', array('%arg' => 'http://drupal.org/node/70145')) .'</p>',
1047 );
1048 } else {
1049 $form['view_args_php_fieldset']['view_args_php'] = array(
1050 '#type' => 'value',
1051 '#value' => $view->view_args_php,
1052 );
1053 }
1054
1055 $form['save'] = array(
1056 '#type' => 'submit',
1057 '#value' => t('Save'),
1058 );
1059 if ($view->vid) {
1060 $form['delete'] = array(
1061 '#type' => 'submit',
1062 '#value' => t('Delete'),
1063 );
1064 }
1065 $form['cancel'] = array(
1066 '#type' => 'submit',
1067 '#value' => t('Cancel'),
1068 );
1069
1070 return $form;
1071 }
1072
1073 /**
1074 * separately build a piece of the form
1075 */
1076 function views_ui_build_form(&$form) {
1077 // NOT REALLY SURE WHY THIS SORT OF WORKS. IT'S MAGIC THAT CHX POINTED ME TO
1078 // IN THE POLL MODULE.
1079 $form['#post'] = $_POST;
1080 $form = form_builder('views_edit_view', $form);
1081 }
1082
1083 /**
1084 * Add the 'add' button for a section into the form
1085 */
1086 function views_ui_add_add_button(&$form, $section, $options, $label) {
1087 $form[$section]['add'] = array('#tree' => true, '#parents' => array($section, 'add'));
1088
1089 $form[$section]['add']['id'] = array(
1090 '#type' => 'select',
1091 '#options' => $options,
1092 );
1093 $form[$section]['add']['button'] = array(
1094 '#type' => 'button',
1095 '#value' => $label,
1096 );
1097 views_ui_build_form($form[$section]['add']);
1098 }
1099
1100 /**
1101 * Add one of the list sections to the form.
1102 */
1103 function views_ui_add_section(&$form, &$view, $section) {
1104 // add fields to the form.
1105
1106 $form += array('#tree' => true, '#parents' => array($section));
1107 $view_section = &$view->$section;
1108
1109 $num_items = count($view_section);
1110 // Populate the form with fields we need to check to track
1111 // changes through the form's life.
1112 $form['count'] = array('#type' => 'hidden', '#default_value' => $num_items);
1113
1114 $form['order'] = array(
1115 '#type' => 'hidden',
1116 '#default_value' => $num_items ? implode(',', range(0, $num_items - 1)) : '',
1117 );
1118
1119 // Run the builder to get the value on the form.
1120 views_ui_build_form($form);
1121 $order = $form['order']['#value'] != ''
1122 ? explode(',', $form['order']['#value'])
1123 : array();
1124
1125 // Shortcut because operator precedence gets sticky if using $foo->$bar[]
1126 for ($i = $num_items; $i < $form['count']['#value']; $i++) {
1127 $view_section[] = array();
1128 }
1129
1130 $new_section = "new_$section";
1131 // instantiate the new field if one was added.
1132 if ($view->$new_section) {
1133 $view_section[] = $view->$new_section;
1134 $order[] = $form['count']['#value'];
1135 $form['count']['#value']++;
1136 }
1137
1138 $func = "views_ui_add_$section";
1139 if ($order) {
1140 foreach ($order as $key => $i) {
1141 $form[$i] = array('#tree' => true, '#parents' => array($section, $i));
1142
1143 $form[$i]['id'] = array(
1144 '#type' => 'hidden',
1145 '#default_value' => $view_section[$i]['id'],
1146 );
1147
1148 views_ui_add_buttons($form[$i]);
1149 views_ui_build_form($form[$i]);
1150
1151 $retval = _views_check_sub_ops($form[$i], $order, $key);
1152 if ($retval !== 'delete') {
1153 $retval2 = $func($form[$i], $view_section[$i], $order, $key, $i, $view);
1154 }
1155
1156 if ($retval || $retval2) {
1157 $allbut = $section;
1158 }
1159 }
1160 $form['order']['#value'] = implode(',', $order);
1161 }
1162 return $allbut;
1163 }
1164
1165 /**
1166 * Add all the info for a single field into the form.
1167 */
1168 function views_ui_add_field(&$form, $field, &$order, $key, $i) {
1169 $fields = _views_get_fields();
1170 $fieldname = $form['id']['#value']; // combined table & fieldname
1171 $fieldinfo = $fields[$fieldname]; // laziness + readability
1172
1173 $form['fullname'] = array(
1174 '#type' => 'hidden',
1175 '#default_value' => $field['id'],
1176 );
1177
1178 $form['name'] = array(
1179 '#type' => 'markup',
1180 '#value' => $fieldinfo['name'], // combined table & fieldname
1181 );
1182 $form['queryname'] = array(
1183 '#type' => 'hidden',
1184 '#default_value' => $field['queryname'],
1185 );
1186 $form['tablename'] = array(
1187 '#type' => 'hidden',
1188 '#default_value' => $field['tablename'],
1189 );
1190 $form['field'] = array(
1191 '#type' => 'hidden',
1192 '#default_value' => $field['field'],
1193 );
1194
1195 $form['label'] = array(
1196 '#type' => 'textfield',
1197 '#default_value' => $field['label'],
1198 '#size' => 15,
1199 '#maxlength' => 255,
1200 );
1201
1202 if (is_array($fieldinfo['handler'])) {
1203 $form['handler'] = array(
1204 '#type' => 'select',
1205 '#default_value' => $field['handler'],
1206 '#options' => $fieldinfo['handler'],
1207 );
1208 }
1209
1210 if (isset($fieldinfo['option'])) {
1211 $form['options'] = views_ui_setup_widget($fieldinfo['option'], $field['options']);
1212 }
1213
1214
1215 if ($fieldinfo['sortable']) {
1216 $form['sortable'] = array(
1217 '#type' => 'select',
1218 '#default_value' => $field['sortable'],
1219 '#options' => array('0' => t('No'), '1' => t('Yes')),
1220 );
1221 $form['defaultsort'] = array(
1222 '#type' => 'select',
1223 '#default_value' => $field['defaultsort'],
1224 '#options' => array('0' => t('None'), 'ASC' => t('Ascending'), 'DESC' => t('Descending')),
1225 );
1226 }
1227 if (isset($fieldinfo['help'])) {
1228 $form['help'] = array(
1229 '#type' => 'markup',
1230 '#value' => '<div class="description">' . $fieldinfo['help'] . '</div>',
1231 );
1232 }
1233 }
1234
1235 /**
1236 * Add all the info for a single argument into the form.
1237 */
1238 function views_ui_add_argument(&$form, $argument, &$order, $key, $i) {
1239 $arguments = _views_get_arguments();
1240 $arg_type = $form['id']['#value'];
1241 $arginfo = $arguments[$arg_type];
1242
1243 $form['type'] = array(
1244 '#type' => 'hidden',
1245 '#default_value' => $argument['id'],
1246 );
1247
1248 $form['name'] = array(
1249 '#value' => $arginfo['name'],
1250 );
1251
1252 $form['argdefault'] = array(
1253 '#type' => 'select',
1254 '#default_value' => max(1, intval($argument['argdefault'])),
1255 '#options' => _views_get_arguments_default(),
1256 );
1257 $form['title'] = array(
1258 '#type' => 'textfield',
1259 '#default_value' => $argument['title'],
1260 '#size' => 10,
1261 '#maxlength' => 255,
1262 );
1263 if (isset($arginfo['option'])) {
1264 $form['options'] = views_ui_setup_widget($arginfo['option'], $argument['options']);
1265 }
1266 $form['wildcard'] = array(
1267 '#type' => 'textfield',
1268 '#default_value' => $argument['wildcard'],
1269 '#size' => 5,
1270 '#maxlength' => 32,
1271 );
1272 $form['wildcard_substitution'] = array(
1273 '#type' => 'textfield',
1274 '#default_value' => $argument['wildcard_substitution'],
1275 '#size' => 5,
1276 '#maxlength' => 32,
1277 );
1278 if (isset($arginfo['help'])) {
1279 $form['help'] = array(
1280 '#type' => 'markup',
1281 '#value' => $arginfo['help'],
1282 );
1283 }
1284 }
1285
1286 /**
1287 * Add all the info for a single filter into the form.
1288 */
1289 function views_ui_add_filter(&$form, $filter, &$order, $key, $i, &$view) {
1290 $filters = _views_get_filters();
1291 $filtername = $form['id']['#value']; // combined table & filtername
1292 $filterinfo = $filters[$filtername];
1293
1294 $form['field'] = array(
1295 '#type' => 'hidden',
1296 '#default_value' => $filter['id'],
1297 );
1298
1299 $form['name'] = array(
1300 '#type' => 'markup',
1301 '#value' => $filterinfo['name'],
1302 );
1303
1304 // 'operator' is either an array or a handler
1305 $operator = $filterinfo['operator'];
1306 if (!is_array($operator) && function_exists($filterinfo['operator'])) {
1307 $operator = $filterinfo['operator']('operator', $filterinfo);
1308 }
1309
1310 $form['operator'] = array(
1311 '#type' => 'select',
1312 '#default_value' => $filter['operator'],
1313 '#options' => $operator,
1314 );
1315 if (isset($filterinfo['option'])) {
1316 $form['options'] = views_ui_setup_widget($filterinfo['option'], $filter['options']);
1317 }
1318
1319 $form['value'] = views_ui_setup_widget($filterinfo['value'], $filter['value'], $filterinfo);
1320
1321 if (isset($filterinfo['help'])) {
1322 $form['help'] = array(
1323 '#type' => 'markup',
1324 '#value' => $filterinfo['help'],
1325 );
1326 }
1327
1328 // This is kind of a pain in the butt -- The only way to know all of
1329 // the filters that have been exposed is to look at the form, but that
1330 // part of the form hasn't been built yet, so I can't use the form_builder
1331 // method. I can't put this after that, either, because then I'd have to
1332 // go back to add one if we see one here. So we cheat heavily with _POST.
1333
1334 if ($_POST['edit']) {
1335 $exposed_order = $_POST['edit']['exposed_filter']['order'];
1336 if ($exposed_order !== '') {
1337 $exposed_order = explode(',', $exposed_order);
1338 foreach ($exposed_order as $x) {
1339 if ($_POST['edit']['exposed_filter'][$x]['id'] == $filtername) {
1340 $exposed = true;
1341 break;
1342 }
1343 }
1344 }
1345 }
1346 else { // do this if there's never been a submit.
1347 $exposed_order = array_keys($view->exposed_filter);
1348 foreach ($exposed_order as $x) {
1349 if ($view->exposed_filter[$x]['id'] == $filtername) {
1350 $exposed = true;
1351 break;
1352 }
1353 }
1354 }
1355 if (!$exposed) {
1356 // I can't find a way to see if this button was pressed other than
1357 // directly checking, because #form_submitted doesn't work on arrays
1358
1359 if ($_POST['edit']['filter'][$i]['expose']) {
1360 $view->new_exposed_filter['id'] = $filtername;
1361 return true;
1362 }
1363 else {
1364 $form['expose'] = array(
1365 '#type' => 'button',
1366 '#default_value' => t('Expose'),
1367 '#name' => "edit[filter][$i][expose]",
1368 );
1369 }
1370 }
1371 }
1372
1373 /**
1374 * Add all the info for a single exposed filter into the form.
1375 */
1376 function views_ui_add_exposed_filter(&$form, $filter, &$order, $key, $i) {
1377 $filters = _views_get_filters();
1378 $filtername = $form['id']['#value']; // combined table & filtername
1379 $filterinfo = $filters[$filtername];
1380
1381 $form['field'] = array(
1382 '#type' => 'hidden',
1383 '#default_value' => $filter['id'],
1384 );
1385
1386 $form['name'] = array(
1387 '#type' => 'markup',
1388 '#value' => $filterinfo['name'],
1389 );
1390
1391 $form['label'] = array(
1392 '#type' => 'textfield',
1393 '#default_value' => $filter['label'],
1394 '#size' => 15,
1395 '#maxlength' => 255,
1396 );
1397
1398 $form['optional'] = array(
1399 '#type' => 'checkbox',
1400 '#default_value' => $filter['optional'],
1401 );
1402
1403 $form['is_default'] = array(
1404 '#type' => 'checkbox',
1405 '#default_value' => $filter['is_default'],
1406 );
1407
1408 $form['single'] = array(
1409 '#type' => 'checkbox',
1410 '#default_value' => $filter['single'],
1411 );
1412
1413 $form['operator'] = array(
1414 '#type' => 'checkbox',
1415 '#default_value' => $filter['operator'],
1416 );
1417 }
1418
1419 /**
1420 * Add all the info for a single sort into the form.
1421 */
1422 function views_ui_add_sort(&$form, $sort, &$order, $key, $i) {
1423 $sorts = _views_get_sorts();
1424 $sortname = $form['id']['#value']; // combined table & sortname
1425 $sortinfo = $sorts[$sortname];
1426
1427 $form['field'] = array(
1428 '#type' => 'hidden',
1429 '#default_value' => $sort['id'],
1430 );
1431
1432 $form['name'] = array(
1433 '#value' => $sortinfo['name'],
1434 );
1435
1436 $form['sortorder'] = array(
1437 '#type' => 'select',
1438 '#title' => NULL,
1439 '#default_value' => $sort['sortorder'],
1440 '#options' => _views_sortorders(),
1441 );
1442 // option can be either 'string', 'integer', an array or a handler
1443 // that must return an array.
1444 if (isset($sortinfo['option'])) {
1445 $form['options'] = views_ui_setup_widget($sortinfo['option'], $sort['options']);
1446 }
1447 if (isset($sortinfo['help'])) {
1448 $form['help'] = array(
1449 '#type' => 'markup',
1450 '#value' => $sortinfo['help'],
1451 );
1452 }
1453 }
1454
1455 /**
1456 * Add the up, down, top, bottom, delete buttons to a form.
1457 */
1458 function views_ui_add_buttons(&$form_item) {
1459 $form_item['delete'] = views_ui_add_button('user-trash.png', t('Delete'), t('Delete this item.'));
1460 $form_item['up'] = views_ui_add_button('go-up.png', t('Up'), t('Move this item up.'));
1461 $form_item['down'] = views_ui_add_button('go-down.png', t('Down'), t('Move this item down.'));
1462 $form_item['top'] = views_ui_add_button('go-top.png', t('Top'), t('Move this item to the top.'));
1463 $form_item['bottom'] = views_ui_add_button('go-bottom.png', t('Bottom'), t('Move this item to the bottom.'));
1464 }
1465
1466 /**
1467 * Add a single button to a form.
1468 */
1469 function views_ui_add_button($image, $name, $text) {
1470 $module_path = base_path() . drupal_get_path('module', 'views');
1471
1472 return array(
1473 '#type' => 'views_imagebutton',
1474 '#image' => $module_path . '/' . $image,
1475 '#title' => $text,
1476 '#default_value' => $name,
1477 );
1478 }
1479
1480 /**
1481 * Display the form built by _views_view_form()
1482 */
1483 function theme_views_edit_view($form) {
1484
1485 $output .= drupal_render($form['basic-info'], false);
1486 $output .= drupal_render($form['page-info'], false);
1487 $output .= drupal_render($form['block-info'], false);
1488
1489 $allbut = $form['allbut']['#value'];
1490
1491 // drupal_render wants a reference so use full array notation.
1492
1493 // fields
1494 $collapsed = $allbut && $allbut != 'field';
1495 $group = views_ui_render_section($form['field'], array('name', 'label', 'handler', 'options', 'sortable', 'defaultsort'), array(t('Name'), t('Label'), t('Handler'), t('Option'), t('Sortable'), t('Default Sort')), 'fields', $collapsed);
1496 $group .= views_ui_render_section_add($form['field']['add'], array('id', 'button'), t('Add Field'));
1497
1498 $group .= '<p>'. t('Fields are only meaningful with List view and Table View; they allow you to choose which fields are presented and in what order.') .'</p>';
1499 $output .= theme('fieldset', array('#title' => t('Fields'), '#children' => $group,
1500 '#collapsible' => true, '#collapsed' => $collapsed,));
1501
1502
1503 // arguments
1504 $collapsed = $allbut && $allbut != 'argument';
1505 $group = views_ui_render_section($form['argument'], array('name', 'argdefault', 'title', 'options', 'wildcard', 'wildcard_substitution'), array(t('Argument Type'), t('Default'), t('Title'), t('Option'), t('Wildcard'), t('Wildcard Sub')), 'arguments', $collapsed);
1506
1507 $group .= views_ui_render_section_add($form['argument']['add'], array('id', 'button'), t('Add Argument'));
1508
1509 $group .= drupal_render($form['view_args_php_fieldset']);
1510
1511 $group .= '<p>'. t('Arguments are parsed directly from the URL. They are not necessary to any given view, but allow flexibility.') .'</p>';
1512 $output .= theme('fieldset', array('#title' => t('Arguments'), '#children' => $group,
1513 '#collapsible' => true, '#collapsed' => $collapsed,));
1514
1515 // filter
1516 $collapsed = $allbut && $allbut != 'filter';
1517 $group = views_ui_render_section($form['filter'], array('name', 'operator', 'value', 'options', 'expose'), array(t('Field'), t('Operator'), t('Value'), t('Option'), ''), 'filters', $collapsed);
1518
1519 $group .= views_ui_render_section_add($form['filter']['add'], array('id', 'button'), t('Add Filter'));
1520
1521 $group .= '<p>'. t('Filters allow you to select a subset of all the nodes to display. All Filters are ANDed together.') .'</p>';
1522 $output .= theme('fieldset', array('#title' => t('Filters'), '#children' => $group,
1523 '#collapsible' => true, '#collapsed' => $collapsed,));
1524 $group = '';
1525
1526 // exposed exposed_filter
1527 $collapsed = $allbut && $allbut != 'exposed_filter';
1528 $group = views_ui_render_section($form['exposed_filter'], array('name', 'label', 'optional', 'is_default', 'single', 'operator'), array(t('Field'), t('Label'), t('Optional'), t('Filter settings Default'), t('Force Single'), t('Lock Operator')), 'exposed_filters', $collapsed);
1529
1530
1531 // $group .= views_ui_render_section_add($form['exposed_filter']['add'], array('id', 'button'), t('Expose Filter'));
1532
1533 $group .= '<p>'. t('Exposed filters will be presented to the viewer. If not set required, then filters will include a "&lt;None&gt;" Value if possible. If set default, filters will default as set here, otherwise filter settings will be ignored. If Lock Operator is set, no operator will be made available to the user.') .'</p>';
1534 $output .= theme('fieldset', array('#title' => t('Exposed Filters'), '#children' => $group,
1535 '#collapsible' => true, '#collapsed' => $collapsed,));
1536 $group = '';
1537
1538 // sort
1539 $collapsed = $allbut && $allbut != 'sort';
1540 $group = views_ui_render_section($form['sort'], array('name', 'sortorder', 'options'), array(t('Field'), t('Order'), t('Option')), 'sort criteria', $collapsed);
1541
1542 $group .= views_ui_render_section_add($form['sort']['add'], array('id', 'button'), t('Add criteria'));
1543 $output .= theme('fieldset', array('#title' => t('Sort Criteria'), '#children' => $group,
1544 '#collapsible' => true, '#collapsed' => $collapsed,));
1545
1546 $output .= drupal_render($form, false);
1547 return $output;
1548 }
1549
1550 /**
1551 * Render one of the dynamic sections on our form.
1552 */
1553 function views_ui_render_section(&$form, $items, $header, $section, &$collapsed) {
1554 // always do the buttons
1555 $items = array_merge($items, array('delete', 'top', 'up', 'down', 'bottom'));
1556 $num_items = count($items);
1557
1558 $order = ($form['order']['#value'] != ''
1559 ? explode(',', $form['order']['#value'])
1560 : array());
1561
1562 $count = count($order) - 1;
1563 foreach ($order as $key => $i) {
1564 $row = array();
1565 foreach ($items as $item) {
1566 if (($key == 0 && ($item == 'up' || $item == 'top')) ||
1567 ($key == $count && ($item == 'down' || $item == 'bottom'))) {
1568 $form[$i][$item]['#printed'] = true;
1569 $row[] = '&nbsp;'; // array('data' => '&nbsp;', 'width' => 16);
1570 }
1571 else {
1572 $row[] = drupal_render($form[$i][$item], false);
1573 }
1574 }
1575 $rows[] = $row;
1576 if (isset($form[$i]['help'])) {
1577 $rows[] = array(array('data' => drupal_render($form[$i]['help']), 'colspan' => $num_items));
1578 }
1579 }
1580 if (!$rows) {
1581 $rows[] = array(array('data' => t('This view currently has no %s defined.', array('%s' => $section)), 'colspan' => $num_items));
1582 $collapsed = true;
1583 }
1584
1585 $header[] = array('data' => t('Ops'), 'colspan' => 5);
1586 return theme('table', $header, $rows) . "<br />";
1587 }
1588
1589 /**
1590 * Render the add buttons for one of the dynamic sections on our form.
1591 */
1592 function views_ui_render_section_add(&$form, $items, $label) {
1593 foreach ($items as $item) {
1594 $row[] = drupal_render($form[$item], false);
1595 }
1596 $rows[] = $row;
1597
1598 $header = array(array('data' => $label, 'colspan' => count($items)));
1599 return theme('table', $header, $rows) . "<br />";
1600 }
1601
1602 /**
1603 * Validate that a view sent via form is OK.
1604 */
1605 function views_edit_view_validate($form_id, $view, $form) {
1606 $op = $_POST['op'];
1607 if ($op != t('Save')) {
1608 return; // only validate on saving!
1609 }
1610
1611 if ($view['vid']) {
1612 $changed = db_result(db_query("SELECT changed FROM {view_view} WHERE vid = %d", $view['vid']));
1613 if ($changed && $view['changed'] != $changed) {
1614 form_set_error('', t('Another user has modified this view, unable to save. You can get this error by using the Back button to re-edit a view after saving one; if you do this, be sure to Reload before making any changes!'));
1615 return;
1616 }
1617 }
1618
1619 if (!$view['name']) {
1620 form_error($form['basic-info']['name'], t('View name is required.'));
1621 }
1622
1623 // view name must be alphanumeric or underscores, no other punctuation.
1624 if (preg_match('/[^a-zA-Z0-9_]/', $view['name'])) {
1625 form_error($form['basic-info']['name'], t('View name must be alphanumeric or underscores only.'));
1626 }
1627
1628 // test uniqueness of name
1629 $vid = db_result(db_query("SELECT vid FROM {view_view} WHERE name='%s'", $view['name']));
1630 if ($vid && $vid != $view['vid']) {
1631 form_error($form['basic-info']['name'], t('View name already in use.'));
1632 }
1633
1634 if ($view['page']) {
1635 if ($view['use_pager'] && !$view['nodes_per_page']) {
1636 form_error($form['page-info']['nodes_per_page'], t('Nodes per page cannot be 0 if using the pager.'));
1637 }
1638 }
1639
1640 if ($view['block'] && $view['nodes_per_block'] < 1) {
1641 form_error($form['block-info']['nodes_per_block'], t('If being used as a block, Nodes Per Block must be positive.'));
1642 }
1643
1644 // validation based on type:
1645
1646 $plugins = _views_get_style_plugins();
1647 if ($view['page']) {
1648 $validator = $plugins[$view['page_type']]['validate'];
1649 if (function_exists($validator)) {
1650 $validator('page', $view, $form);
1651 }
1652 }
1653
1654 if ($view['block']) {
1655 $validator = $plugins[$view['block_type']]['validate'];
1656 if (function_exists($validator)) {
1657 $validator('block', $view, $form);
1658 }
1659 }
1660
1661 foreach (array('field', 'argument', 'sort', 'filter') as $type) {
1662 $function = "_views_get_$type" . 's';
1663 $info = $function();
1664 if (is_array($view->$type)) {
1665 foreach ($view->$type as $key => $data) {
1666 if (!is_numeric($key)) {
1667 continue; // some non-data data is in here.
1668 }
1669 $validator = $info[$data['id']]['validate'];
1670 if (function_exists($validator)) {
1671 $validator($data, $view, $form);
1672 }
1673 }
1674 }
1675 }
1676 }
1677
1678 function views_ui_reorder(&$view) {
1679 // re-order things as they were ordered on the form.
1680 $order = $view['order'] != '' ? explode(',', $view['order']) : array();
1681 foreach ($order as $position => $key) {
1682 $placeholder[] = $view[$key];
1683 }
1684 $view = $placeholder;
1685 }
1686
1687 /**
1688 * Handle submit buttons on a view form.
1689 */
1690 function views_edit_view_submit($form_id, $form) {
1691 $view = (object) $form;
1692
1693 // Transform any data that requires it here.
1694 $view->access = array_keys(array_filter($view->access));
1695
1696 // ensure for MYSQL 5 irritation reasons.
1697 $view->nodes_per_page = intval($view->nodes_per_page);
1698 $view->nodes_per_block = intval($view->nodes_per_block);
1699 $view->menu_tab_weight = intval($view->menu_tab_weight);
1700
1701 // re-order things as they were ordered on the form.
1702 foreach (array('field', 'argument', 'filter', 'sort', 'exposed_filter') as $section) {
1703 views_ui_reorder($view->$section);
1704 }
1705
1706 _views_save_view($view);
1707 menu_rebuild();
1708 if ($form['vid']) {
1709 drupal_set_message(t('View successfully saved.'));
1710 }
1711 else {
1712 drupal_set_message(t('View successfully added.'));
1713 }
1714
1715 return 'admin/build/views';
1716 }
1717
1718 /**
1719 * Validate a view with a type: list.
1720 */
1721 function views_ui_plugin_validate_list($type, $view, $form) {
1722 // list (and table) modes require there to be at least 1 field active.
1723 if (is_array($view['field'])) {
1724 $fields = array_filter(array_keys($view['field']), 'is_numeric');
1725 }
1726 if (!$fields) {
1727 form_error($form["$type-info"][$type . '_type'], t('List and Table types require at least one field.'));
1728 }
1729
1730 if (isset($view['field']['count'])) {
1731 $defaultsort = false;
1732 for ($i = 0; $i < $view['field']['count']; $i++) {
1733 if ($view['field'][$i]['defaultsort']) {
1734 if ($defaultsort) {
1735 form_error($form['field'][$i]['defaultsort'], t('You can only set on Default Sort on one field.'));
1736 break;
1737 }
1738 $defaultsort = true;
1739 }
1740 }
1741 }
1742 }
1743
1744 /**
1745 * Validate a view with type: table.
1746 */
1747 function views_ui_plugin_validate_table($type, $view, $form) {
1748 // pass thru to list cause for now they're the same.
1749 return views_ui_plugin_validate_list($type, $view, $form);
1750 }
1751 // ---------------------------------------------------------------------------
1752 // View creator tool
1753
1754 /*
1755 * Get a true/false.
1756 */
1757 function views_tf($val) {
1758 return ($val ? 'TRUE' : 'FALSE');
1759 }
1760
1761 /*
1762 * This function creates view code for a view.
1763 */
1764 function views_create_view_code($vid) {
1765 $view = _views_load_view($vid);
1766 if (!$view) {
1767 return t("View '%vid' not found.", array('%vid' => $vid));
1768 }
1769
1770 $requires = array();
1771
1772 $output = " \$view = new stdClass();\n";
1773 $output .= " \$view->name = " . var_export($view->name, true) . ";\n";
1774 $output .= " \$view->description = " . var_export($view->description, true) . ";\n";
1775 $output .= " \$view->access = " . var_export($view->access, true) . ";\n";
1776 if (user_access('use PHP for block visibility')) {
1777 $output .= " \$view->view_args_php = " . var_export($view->view_args_php, true) . ";\n";
1778 }
1779 // page items
1780 if ($view->page) {
1781 $output .= " \$view->page = " . views_tf($view->page) . ";\n";
1782 $output .= " \$view->page_title = " . var_export($view->page_title, true) . ";\n";
1783 $output .= " \$view->page_header = " . var_export($view->page_header, true) .";\n";
1784 $output .= " \$view->page_header_format = " . var_export($view->page_header_format, true) . ";\n";
1785 $output .= " \$view->page_footer = " . var_export($view->page_footer, true) .";\n";
1786 $output .= " \$view->page_footer_format = " . var_export($view->page_footer_format, true) . ";\n";
1787 $output .= " \$view->page_empty = " . var_export($view->page_empty, true) .";\n";
1788 $output .= " \$view->page_empty_format = " . var_export($view->page_empty_format, true) . ";\n";
1789 $output .= " \$view->page_type = " . var_export($view->page_type, true) . ";\n";
1790 $output .= " \$view->url = " . var_export($view->url, true) . ";\n";
1791 $output .= " \$view->use_pager = " . views_tf($view->use_pager) . ";\n";
1792 $output .= " \$view->nodes_per_page = " . var_export($view->nodes_per_page, true) . ";\n";
1793 if ($view->menu) {
1794 $output .= " \$view->menu = " . views_tf($view->menu) . ";\n";
1795 $output .= " \$view->menu_title = " . var_export($view->menu_title, true) . ";\n";
1796 $output .= " \$view->menu_tab = " . views_tf($view->menu_tab) . ";\n";
1797 $output .= " \$view->menu_tab_default = " . views_tf($view->menu_tab_default) . ";\n";
1798 $output .= " \$view->menu_tab_weight = " . var_export($view->menu_tab_weight, true) . ";\n";
1799 }
1800 }
1801 if ($view->block) {
1802 $output .= " \$view->block = " . views_tf($view->block) . ";\n";
1803 $output .= " \$view->block_title = " . var_export($view->block_title, true) . ";\n";
1804 $output .= " \$view->block_header = " . var_export($view->block_header, true) . ";\n";
1805 $output .= " \$view->block_header_format = " . var_export($view->block_header_format, true) . ";\n";
1806 $output .= " \$view->block_footer = " . var_export($view->block_footer, true) . ";\n";
1807 $output .= " \$view->block_footer_format = " . var_export($view->block_footer_format, true) . ";\n";
1808 $output .= " \$view->block_empty = " . var_export($view->block_empty, true) .";\n";
1809 $output .= " \$view->block_empty_format = " . var_export($view->block_empty_format, true) . ";\n";
1810 $output .= " \$view->block_type = " . var_export($view->block_type, true) . ";\n";
1811 $output .= " \$view->nodes_per_block = " . var_export($view->nodes_per_block, true) . ";\n";
1812 $output .= " \$view->block_more = " . views_tf($view->block_more) . ";\n";
1813 $output .= " \$view->block_use_page_header = " . views_tf($view->block_use_page_header) . ";\n";
1814 $output .= " \$view->block_use_page_footer = " . views_tf($view->block_use_page_footer) . ";\n";
1815 $output .= " \$view->block_use_page_empty = " . views_tf($view->block_use_page_empty) . ";\n";
1816 }
1817
1818 $output .= " \$view->sort = array (\n";
1819 foreach ($view->sort as $sort) {
1820 $output .= " array (\n";
1821 $fieldbits = explode('.', $sort['field']);
1822 $output .= " 'tablename' => " . var_export($fieldbits[0], true) . ",\n";
1823 $output .= " 'field' => " . var_export($fieldbits[1], true) . ",\n";
1824 $output .= " 'sortorder' => " . var_export($sort['sortorder'], true) . ",\n";
1825 $output .= " 'options' => " . var_export($sort['options'], true) . ",\n";
1826 $output .= " ),\n";
1827 $requires[$fieldbits[0]] = 1;
1828 }
1829 $output .= " );\n";
1830
1831 $output .= " \$view->argument = array (\n";
1832 foreach ($view->argument as $argument) {
1833 $output .= " array (\n";
1834 $output .= " 'type' => " . var_export($argument['type'], true) . ",\n";
1835 $output .= " 'argdefault' => " . var_export($argument['argdefault'], true) . ",\n";
1836 $output .= " 'title' => " . var_export($argument['title'], true) . ",\n";
1837 $output .= " 'options' => " . var_export($argument['options'], true) . ",\n";
1838 $output .= " 'wildcard' => " . var_export($argument['wildcard'], true) . ",\n";
1839 $output .= " 'wildcard_substitution' => " . var_export($argument['wildcard_substitution'], true) . ",\n";
1840 $output .= " ),\n";
1841 }
1842 $output .= " );\n";
1843
1844 $output .= " \$view->field = array (\n";
1845 foreach ($view->field as $field) {
1846 $output .= " array (\n";
1847 $output .= " 'tablename' => " . var_export($field['tablename'], true) . ",\n";
1848 $output .= " 'field' => " . var_export($field['field'], true) . ",\n";
1849 $output .= " 'label' => " . var_export($field['label'], true) . ",\n";
1850 if ($field['handler']) {
1851 $output .= " 'handler' => " . var_export($field['handler'], true) . ",\n";
1852 }
1853 if ($field['sortable']) {
1854 $output .= " 'sortable' => " . var_export($field['sortable'], true) . ",\n";
1855 }
1856 if ($field['defaultsort']) {
1857 $output .= " 'defaultsort' => " . var_export($field['defaultsort'], true) . ",\n";
1858 }
1859 if ($field['options']) {
1860 $output .= " 'options' => " . var_export($field['options'], true) . ",\n";
1861 }
1862 $output .= " ),\n";
1863 $requires[$field['tablename']] = 1;
1864 }
1865 $output .= " );\n";
1866
1867 $output .= " \$view->filter = array (\n";
1868 foreach ($view->filter as $filter) {
1869 $output .= " array (\n";
1870 $fieldbits = explode('.', $filter['field']);
1871 $output .= " 'tablename' => " . var_export($fieldbits[0], true) . ",\n";
1872 $output .= " 'field' => " . var_export($fieldbits[1], true) . ",\n";
1873 $output .= " 'operator' => " . var_export($filter['operator'], true) . ",\n";
1874 $output .= " 'options' => " . var_export($filter['options'], true) . ",\n";
1875 $output .= " 'value' => " . var_export($filter['value'], true) . ",\n";
1876 $output .= " ),\n";
1877 $requires[$fieldbits[0]] = 1;
1878 }
1879 $output .= " );\n";
1880
1881 $output .= " \$view->exposed_filter = array (\n";
1882 foreach ($view->exposed_filter as $filter) {
1883 $output .= " array (\n";
1884 $fieldbits = explode('.', $filter['field']);
1885 $output .= " 'tablename' => " . var_export($fieldbits[0], true) . ",\n";
1886 $output .= " 'field' => " . var_export($fieldbits[1], true) . ",\n";
1887 $output .= " 'label' => " . var_export($filter['label'], true) . ",\n";
1888 $output .= " 'optional' => " . var_export($filter['optional'], true) . ",\n";
1889 $output .= " 'is_default' => " . var_export($filter['is_default'], true) . ",\n";
1890 $output .= " 'operator' => " . var_export($filter['operator'], true) . ",\n";
1891 $output .= " 'single' => " . var_export($filter['single'], true) . ",\n";
1892 $output .= " ),\n";
1893 $requires[$fieldbits[0]] = 1;
1894 }
1895 $output .= " );\n";
1896 $output .= " \$view->requires = array(" . implode(', ', array_keys($requires)) . ");\n";
1897 $output .= " \$views[\$view->name] = \$view;\n";
1898 return $output;
1899 }
1900
1901