aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/menu.php23
-rw-r--r--mod/menu.php62
-rwxr-xr-xview/tpl/field_input.tpl2
-rw-r--r--view/tpl/menuedit.tpl21
-rw-r--r--view/tpl/menulist.tpl2
5 files changed, 95 insertions, 15 deletions
diff --git a/include/menu.php b/include/menu.php
index 951a2b1fe..cee17c1e9 100644
--- a/include/menu.php
+++ b/include/menu.php
@@ -38,6 +38,18 @@ function menu_render($menu) {
}
+function menu_fetch_id($menu_id,$channel_id) {
+
+ $r = q("select * from menu where menu_id = %d and menu_channel_id = %d limit 1",
+ intval($menu_id),
+ intval($channel_id)
+ );
+
+ return (($r) ? $r[0] : false);
+}
+
+
+
function menu_create($arr) {
@@ -103,6 +115,17 @@ function menu_edit($arr) {
return false;
+ $r = q("select menu_id from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
+ dbesc($menu_name),
+ intval($menu_channel_id)
+ );
+ if(($r) && ($r[0]['menu_id'] != $menu_id)) {
+ logger('menu_edit: duplicate menu name for channel ' . $menu_channel_id);
+ return false;
+ }
+
+
+
$menu_channel_id = intval($arr['menu_channel_id']);
$r = q("select * from menu where menu_id = %d and menu_channel_id = %d limit 1",
diff --git a/mod/menu.php b/mod/menu.php
index a624b4727..f00bf7a78 100644
--- a/mod/menu.php
+++ b/mod/menu.php
@@ -7,12 +7,29 @@ function menu_post(&$a) {
if(! local_user())
return;
- $channel = $a->get_channel();
- $menu_id = ((argc() > 1) ? intval(argv(1)) : 0);
+ $_REQUEST['menu_channel_id'] = local_user();
- $menu_name = (($_REQUEST['menu_name']) ? $_REQUEST['menu_name'] : '');
- $menu_desc = (($_REQUEST['menu_desc']) ? $_REQUEST['menu_desc'] : '');
+ $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);
+ }
+ 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);
+ }
+ else
+ notice( t('Unable to create menu.'). EOL);
+ }
}
@@ -37,6 +54,7 @@ function menu_content(&$a) {
'$new' => t('New'),
'$hintnew' => t('Create a new menu'),
'$hintdrop' => t('Delete this menu'),
+ '$hintcontent' => t('Edit menu contents'),
'$hintedit' => t('Edit this menu')
));
}
@@ -50,14 +68,22 @@ function menu_content(&$a) {
if(argc() > 1) {
- if(argv(1) === 'new') {
- // new menu
-
-
-
+ 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'), ''),
+ '$submit' => t('Create')
+ ));
+ return $o;
}
elseif(intval(argv(1))) {
+ $m = menu_fetch_id(intval(argv(1)),local_user());
+ if(! $m) {
+ notice( t('Menu not found.') . EOL);
+ return '';
+ }
if(argc() == 3 && argv(2) == 'drop') {
$r = menu_delete_id(intval(argv(1)),local_user());
if($r)
@@ -68,12 +94,22 @@ function menu_content(&$a) {
goaway(z_root() . '/menu');
}
else {
- // edit menu
-
-
+ $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'), ''),
+ '$submit' => t('Modify')
+ ));
+ return $o;
}
}
-
+ else {
+ notice( t('Not found.') . EOL);
+ return;
+ }
}
}
diff --git a/view/tpl/field_input.tpl b/view/tpl/field_input.tpl
index 2cb3cb91e..d5b3d6b4e 100755
--- a/view/tpl/field_input.tpl
+++ b/view/tpl/field_input.tpl
@@ -1,6 +1,6 @@
<div class='field input'>
<label for='id_{{$field.0}}' id='label_{{$field.0}}'>{{$field.1}}</label>
- <input name='{{$field.0}}' id='id_{{$field.0}}' value="{{$field.2}}">
+ <input name='{{$field.0}}' id='id_{{$field.0}}' value="{{$field.2}}">{{if $field.4}} <span class="required">{{$field.4}}</span> {{/if}}
<span id='help_{{$field.0}}' class='field_help'>{{$field.3}}</span>
<div id='end_{{$field.0}}' class='field_end'></div>
</div>
diff --git a/view/tpl/menuedit.tpl b/view/tpl/menuedit.tpl
new file mode 100644
index 000000000..a46727c55
--- /dev/null
+++ b/view/tpl/menuedit.tpl
@@ -0,0 +1,21 @@
+
+<h2>{{$header}}</h2>
+
+{{if $menu_id}}
+<a href="medit/{{$menu_id}}" title="{{$hintedit}}">{{$editcontents}}</a>
+{{/if}}
+
+<form id="menuedit" action="menu{{if $menu_id}}/{{$menu_id}}{{/if}}" method="post" >
+
+{{if $menu_id}}
+<input type="hidden" name="menu_id" value="{{$menu_id}}" />
+{{/if}}
+
+{{include file="field_input.tpl" field=$menu_name}}
+{{include file="field_input.tpl" field=$menu_desc}}
+
+<div class="menuedit-submit-wrapper" >
+<input type="submit" name="submit" class="menuedit-submit" value="{{$submit}}" />
+</div>
+
+</form>
diff --git a/view/tpl/menulist.tpl b/view/tpl/menulist.tpl
index 3ad92cb7e..0761322cd 100644
--- a/view/tpl/menulist.tpl
+++ b/view/tpl/menulist.tpl
@@ -7,7 +7,7 @@
{{if $menus }}
<ul id="menulist">
{{foreach $menus as $m }}
-<li>{{$m.menu_name}} <a href="menu/{{$m.menu_id}}" title="{{$hintedit}}">{{$edit}}</a>|<a href="menu/{{$m.menu.id}}/drop" title={{$hintdrop}}>{{$drop}}</a></li>
+<li><a href="menu/{{$m.menu_id}}" title="{{$hintedit}}">{{$edit}}</a> | <a href="menu/{{$m.menu.id}}/drop" title={{$hintdrop}}>{{$drop}}</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="medit/{{$m.menu_id}}" title="{{$hintcontent}}">{{$m.menu_name}}</a></li>
{{/foreach}}
</ul>
{{/if}}