aboutsummaryrefslogtreecommitdiffstats
path: root/mod/menu.php
blob: 7e9c580a889d789d52c7556ce9222a2779910ab0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

require_once('include/menu.php');
require_once('include/identity.php');

function menu_post(&$a) {

	$uid = local_channel();

	if(array_key_exists('sys',$_REQUEST) && $_REQUEST['sys'] && is_site_admin()) {
		$sys = get_sys_channel();
		$uid = intval($sys['channel_id']);
		$a->is_sys = true;
	}

	if(! $uid)
		return;

	$_REQUEST['menu_channel_id'] = $uid;
	
	if($_REQUEST['menu_bookmark'])
		$_REQUEST['menu_flags'] |= MENU_BOOKMARK;
	if($_REQUEST['menu_system'])
		$_REQUEST['menu_flags'] |= MENU_SYSTEM;

	$menu_id = ((argc() > 1) ? intval(argv(1)) : 0);
	if($menu_id) {
		$_REQUEST['menu_id'] = intval(argv(1));
		$r = menu_edit($_REQUEST);
		if($r) {
			info( t('Menu updated.') . EOL);
			goaway(z_root() . '/mitem/' . $menu_id . (($a->is_sys) ? '?f=&sys=1' : '')); 
		}
		else
			notice( t('Unable to update menu.'). EOL);
	}
	else {
		$r = menu_create($_REQUEST);
			if($r) {
			info( t('Menu created.') . EOL);
			goaway(z_root() . '/mitem/' . $r . (($a->is_sys) ? '?f=&sys=1' : '')); 
		}
		else
			notice( t('Unable to create menu.'). EOL);

	}

}


function menu_content(&$a) {

	$uid = local_channel();

	if($a->is_sys && is_site_admin()) {
		$sys = get_sys_channel();
		$uid = intval($sys['channel_id']);
	}

	if(! $uid) {
		notice( t('Permission denied.') . EOL);
		return '';
	}


	if(argc() == 1) {
		// list menus
		$x = menu_list($uid);
		if($x) {
			for($y = 0; $y < count($x); $y ++) {
				$x[$y]['bookmark'] = (($x[$y]['menu_flags'] & MENU_BOOKMARK) ? true : false);
			}
		}

		$o = replace_macros(get_markup_template('menulist.tpl'),array(
			'$title' => t('Manage Menus'),
			'$menus' => $x,
			'$edit' => t('Edit'),
			'$drop' => t('Drop'),
			'$new' => t('New'),
			'$bmark' => t('Bookmarks allowed'),
			'$hintnew' => t('Create a new menu'),
			'$hintdrop' => t('Delete this menu'),
			'$hintcontent' => t('Edit menu contents'),
			'$hintedit' => t('Edit this menu')
		));

		return $o;

	}


	if(argc() > 1) {
		if(argv(1) === 'new') {			
			$o = replace_macros(get_markup_template('menuedit.tpl'), array(
				'$header' => t('New Menu'),
				'$menu_name' => array('menu_name', t('Menu name'), '', t('Must be unique, only seen by you'), '*'),
				'$menu_desc' => array('menu_desc', t('Menu title'), '', t('Menu title as seen by others'), ''),
				'$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), 0 , t('Menu may be used to store saved bookmarks'), ''),
				'$submit' => t('Create')
			));
			return $o;
		}

 		elseif(intval(argv(1))) {
			$m = menu_fetch_id(intval(argv(1)),$uid);
			if(! $m) {
				notice( t('Menu not found.') . EOL);
				return '';
			}
			if(argc() == 3 && argv(2) == 'drop') {
				$r = menu_delete_id(intval(argv(1)),$uid);
				if($r)
					info( t('Menu deleted.') . EOL);
				else
					notice( t('Menu could not be deleted.'). EOL);

				goaway(z_root() . '/menu' . (($a->is_sys) ? '?f=&sys=1' : ''));
			}
			else {
				$o = replace_macros(get_markup_template('menuedit.tpl'), array(
					'$header' => t('Edit Menu'),
					'$menu_id' => intval(argv(1)),
					'$hintedit' => t('Add or remove entries to this menu'),
					'$editcontents' => t('Edit menu contents'),
					'$menu_name' => array('menu_name', t('Menu name'), $m['menu_name'], t('Must be unique, only seen by you'), '*'),
					'$menu_desc' => array('menu_desc', t('Menu title'), $m['menu_desc'], t('Menu title as seen by others'), ''),
					'$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), (($m['menu_flags'] & MENU_BOOKMARK) ? 1 : 0), t('Menu may be used to store saved bookmarks'), ''),
					'$menu_system' => (($m['menu_flags'] & MENU_SYSTEM) ? 1 : 0),
					'$submit' => t('Modify')
				));
				return $o;
			}
		}
		else {
			notice( t('Not found.') . EOL);
			return;
		}
	}

}