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