add a 'makePath' method to Diogenes_Barrel
[diogenes.git] / include / admin / menus.php
CommitLineData
6855525e
JL
1<?php
2require_once 'diogenes.common.inc.php';
3require_once 'diogenes.admin.inc.php';
51dda582
JL
4require_once 'Barrel/Menu.php';
5require_once 'Barrel/Page.php';
6855525e
JL
6
7$page = new DiogenesAdmin;
8$bbarrel =& $page->barrel;
51dda582 9$bmenu = new Diogenes_Barrel_Menu($globals->db, $bbarrel->table_menu);
6855525e
JL
10
11// the id of the parent menu
12$MIDpere = isset($_REQUEST['MIDpere']) ? $_REQUEST['MIDpere'] : 0;
13
6855525e
JL
14//// start constructing the page
15
16$page->assign('greeting',__("The site's menus"));
17$action = isset($_REQUEST['action']) ? $_REQUEST["action"] : "";
18switch ($action) {
19
20/* we want to erase the current entry */
21case "supprimer":
22 $MID = $_REQUEST['MID'];
51dda582 23 $bmenu->deleteEntry($MID, $MIDpere, $page);
6855525e
JL
24 break;
25
26/* bring an entry up in the menu */
27case "remonter":
28 $ordre = $_REQUEST['ordre'];
51dda582 29 $bmenu->swapEntries($MIDpere, $ordre-1, $ordre);
6855525e
JL
30 break;
31
32/* push an entry down in the menu */
33case "descendre":
34 $ordre = $_REQUEST['ordre'];
51dda582 35 $bmenu->swapEntries($MIDpere, $ordre, $ordre+1);
6855525e
JL
36 break;
37
38/* create or update a menu entry */
39case "modifier":
40 $typelink = $_REQUEST['typelink'];
51dda582
JL
41 $props = array(
42 'parent' => $MIDpere,
43 'pid' => 0,
44 'link' => '',
45 'title' => $_REQUEST['title'],
46 );
6855525e
JL
47 switch ($typelink) {
48 case "boutonPI" :
51dda582 49 $props['pid'] = isset($_REQUEST['PIvaleur']) ? $_REQUEST['PIvaleur'] : 0;
6855525e
JL
50 break;
51 case "boutonSE" :
51dda582 52 $props['link'] = $_REQUEST['SEvaleur'];
6855525e 53 break;
6855525e 54 }
51dda582 55 $MID = $bmenu->writeEntry($_REQUEST['MID'], $props);
6855525e
JL
56 break;
57
58/* display the form to edit an entry */
59case "editer":
60 // initialisation
61 $link = "";
62 $title = "";
63 $pid = 0;
64 $MID = isset($_REQUEST['MID']) ? $_REQUEST['MID'] : 0;
65
66 // if this is an existing entry, retrieve data
67 if ($MID) {
51dda582
JL
68 $mcache = $bmenu->menuRead();
69 $link = $mcache[$MID]['link'];
70 $title = $mcache[$MID]['title'];
71 $pid = $mcache[$MID]['pid'];
6855525e
JL
72 }
73
74 // fill out form data
75 $chk_pi = ($pid > 0);
76 $chk_se = ($link != "");
77 $chk_z = !$chk_pi && !$chk_se;
78 $chk = " checked=\"checked\"";
79
80 $page->assign('post',$page->script_self());
81 $page->assign('MID', $MID);
82 $page->assign('MIDpere',$_REQUEST['MIDpere']);
83 $page->assign('title',stripslashes($title));
84 $page->assign('chk_z',($chk_z ? $chk : ""));
85 $page->assign('chk_pi',($chk_pi ? $chk : ""));
86 $page->assign('chk_se',($chk_se ? $chk : ""));
87 $page->assign('SEvaleur', $link ? $link : "http://");
88 $page->assign('page_sel',$pid);
89
90 // retrieve all the barrel's pages
91 $fpages = $bbarrel->getPages();
92 $page_opts = array();
93 foreach($fpages as $pkey => $ppage)
94 {
95 $pageloc = $bbarrel->getLocation($pkey);
96 $page_opts[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title'];
97 }
98 $page->assign('page_opts', $page_opts);
99
100 $res = $globals->db->query("SELECT PID,title from {$bbarrel->table_page} ORDER BY title");
101 while (list($myPID,$myTITLE) = mysql_fetch_row($res)) {
102 //$pageloc = $bbarrel->getLocation($pkey);
103 //$page_opts[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title'];
104 $page->append('page_values',$myPID);
105 $page->append('page_names',stripslashes($myTITLE));
106 }
107 mysql_free_result($res);
108
109 $page->assign('doedit',1);
110
111 // translations
112 $page->assign('msg_prop',__("menu entry properties"));
113 $page->assign('msg_title',__("entry title"));
114 $page->assign('msg_type',__("type of link"));
115 $page->assign('msg_type_z',__("none"));
116 $page->assign('msg_type_pi',__("internal link"));
117 $page->assign('msg_type_se',__("external link"));
118
119 $page->assign('submit',__("Submit"));
120 $page->display('admin-menus.tpl');
121 exit;
122 break;
123}
124
125// get the maximum order
51dda582
JL
126$maxOrdre = $bmenu->maxChildIndex($MIDpere);
127
128// all menu entries from database
129$mcache = $bmenu->menuRead();
130
131foreach($mcache[$MIDpere]['children'] as $MID)
132{
133 $ordre = $mcache[$MID]['ordre'];
134 $title = $mcache[$MID]['title'];
135 $link = $mcache[$MID]['link'];
136 $PID = $mcache[$MID]['pid'];
6855525e
JL
137 $clickup="?action=remonter&amp;MIDpere=$MIDpere&amp;ordre=$ordre";
138 $clickdown="?action=descendre&amp;MIDpere=$MIDpere&amp;ordre=$ordre";
139
140 // do we offer an "up" link ?
141 $up = ($ordre != 1) ? array(__("move up"),$clickup) : _("move up");
142
143 // do we offer a "down" link ?
144 $down = ($ordre != $maxOrdre) ? array(__("move down"),$clickdown) : $down = __("move down");
145
146 $edit = array(__("edit"), "?action=editer&amp;MIDpere=$MIDpere&amp;MID=$MID");
147 $del = array(__("delete"), "?action=supprimer&amp;MIDpere=$MIDpere&amp;MID=$MID");
148
149 // describe the current link
150 if ($PID) {
51dda582
JL
151 $tpage = Diogenes_Barrel_Page::fromDb($bbarrel, $PID);
152 $descr = "<a href=\"pages?dir=$PID\">".$tpage->props['title']."</a>";
6855525e
JL
153 } elseif ($link) {
154 $descr = "<a href=\"$link\">[ext] $link</a>";
155 } else {
156 $descr = "none";
157 }
158
159 // smarty assignments
160 $page->append('entries',
161 array($MID, array(stripslashes($title), "?MIDpere=$MID"),
162 stripslashes($descr),
163 $edit,$del,$up,$down));
164}
6855525e 165
a92b0441 166// all menu entries from database
51dda582 167$filiation = $bmenu->menuToRoot($mcache,$MIDpere,array());
6855525e
JL
168$menubar = array();
169foreach($filiation as $mykey=>$myval) {
170 if ($myval == 0) {
171 $blab = "<i>home</i>";
172 } else {
51dda582 173 $blab = stripslashes($mcache[$myval]['title']);
6855525e
JL
174 }
175 array_unshift($menubar,$mykey ? array($blab,"?MIDpere=$myval") : array($blab));
176}
177$page->assign('menubar',$menubar);
178$page->assign('script',$page->script_self());
179$page->assign('MIDpere',$MIDpere);
180
181// translations
182$page->assign('msg_ext',__("External links are denoted with the [ext] prefix."));
183$page->assign('msg_menu',__("menu name"));
184$page->assign('msg_link',__("link"));
185$page->assign('msg_actions',__("actions"));
186$page->assign('msg_menubar',__("Menu"));
187$page->assign('submit',__("Add new entry"));
188$page->display('admin-menus.tpl');
189?>