1: <?php
2: 3: 4:
5:
6: 7: 8: 9:
10: function updateItemsSortorder() {
11: if (empty($_POST['order'])) {
12: return '<p class="notebox fade-message">' . gettext('Nothing changed') . '</p>';
13: } else {
14: $order = processOrder($_POST['order']);
15: $parents = array('NULL');
16: foreach ($order as $id => $orderlist) {
17:
18: $sortstring = implode('-', $orderlist);
19: $level = count($orderlist);
20: $parents[$level] = $id;
21: $myparent = $parents[$level - 1];
22: $sql = "UPDATE " . prefix('menu') . " SET `sort_order` = " . db_quote($sortstring) . ", `parentid`= " . db_quote($myparent) . " WHERE `id`=" . sanitize_numeric($id);
23: query($sql);
24: }
25: return "<p class='messagebox fade-message'>" . gettext("Sort order saved.") . "</p>";
26: }
27: }
28:
29: 30: 31: 32: 33: 34:
35: function printItemsListTable($item, $flag) {
36: global $_zp_gallery;
37: $link = '';
38: $array = getItemTitleAndURL($item);
39: if ($array['valid']) {
40: switch ($item['type']) {
41: case "album":
42: $link = '<a href="../../admin-edit.php?page=edit&album=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
43: break;
44: case "zenpagenewsindex":
45: if(!class_exists('zenpage')) {
46: $link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
47: }
48: break;
49: case "zenpagepage":
50: if(class_exists('zenpage')) {
51: $link = '<a href="../zenpage/admin-edit.php?page&titlelink=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
52: } else {
53: $link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
54: }
55: break;
56: case "zenpagecategory":
57: if(class_exists('zenpage')) {
58: $link = '<a href="../zenpage/admin-edit.php?newscategory&titlelink=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
59: } else {
60: $link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
61: }
62: break;
63: case 'customlink':
64: $link = '<a href="' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
65: break;
66: case 'menulabel':
67: $link = '';
68: break;
69: default:
70: $link = html_encode(truncate_string($item['link'], 40, '...'));
71: break;
72: }
73: } else {
74: $link = '<span class="notebox">' . sprintf(gettext('Target does not exists in <em>%1$s</em> theme'), $array['theme']) . '</span>';
75: }
76: ?>
77: <div class="page-list_row">
78: <div class="page-list_title">
79: <?php
80: printItemEditLink($item);
81: ?>
82: </div>
83: <div class="page-list_extra">
84: <em><?php echo $item['type']; ?></em>
85: </div>
86: <div class="page-list_extra">
87: <?php echo $link; ?>
88: </div>
89: <div class="page-list_iconwrapper">
90: <div class="page-list_icon">
91: <?php
92: if ($array['protected']) {
93: ?>
94: <img src="../../images/lock_2.png" alt="<?php echo gettext("The object of this menu is under password protection"); ?>" title="<?php echo gettext("The object of this menu is under password protection"); ?>" style="border: 0px;" />
95: <?php
96: } else {
97: ?>
98: <img src="../../images/place_holder_icon.png" alt="<?php echo gettext("under password protection"); ?>" style="border: 0px;" />
99: <?php
100: }
101: ?>
102: </div>
103: <div class="page-list_icon">
104: <?php
105: if ($item['show'] === '1') {
106: ?>
107: <a href="menu_tab.php?publish&id=<?php echo $item['id'] . "&show=0"; ?>&add&XSRFToken=<?php echo getXSRFToken('update_menu') ?>" title="<?php echo gettext('hide'); ?>" >
108: <img src="../../images/pass.png" alt="<?php echo gettext('hide'); ?>" style="border: 0px;" />
109: </a>
110: <?php
111: } else {
112: ?>
113: <a href="menu_tab.php?publish&id=<?php echo $item['id'] . "&show=1"; ?>&add&XSRFToken=<?php echo getXSRFToken('update_menu') ?>" title="<?php echo gettext('show'); ?>">
114: <img src="../../images/action.png" alt="<?php echo gettext('show'); ?>" style="border: 0px;" />
115: </a>
116: <?php
117: }
118: ?>
119: </div>
120: <div class="page-list_icon">
121: <?php
122: switch ($item['type']) {
123: default:
124: if (!empty($array['url'])) {
125: ?>
126: <a href="<?php echo $array['url']; ?>">
127: <img src="../../images/view.png" alt="<?php echo gettext('view'); ?>" title="<?php echo gettext('view'); ?>" style="border: 0px;" />
128: </a>
129: <?php
130: break;
131: }
132: case 'menulabel':
133: case 'menufunction':
134: case 'html':
135: ?>
136: <img src="../../images/icon_inactive.png" alt="" style="border: 0px;" />
137: <?php
138: break;
139: }
140: ?>
141: </div>
142: <div class="page-list_icon">
143: <a href="javascript:deleteMenuItem('<?php echo $item['id']; ?>','<?php printf(gettext('Ok to delete %s? This cannot be undone.'), html_encode($array['name'])); ?>');" >
144: <img src="../../images/fail.png" alt="<?php echo gettext('delete'); ?>" title="<?php echo gettext('delete'); ?>" style="border: 0px;" />
145: </a>
146: </div>
147: <div class="page-list_icon">
148: <input class="checkbox" type="checkbox" name="ids[]" value="<?php echo html_encode($item['id']); ?>" onclick="triggerAllBox(this.form, 'ids[]', this.form.allbox);" />
149: </div>
150: </div>
151: </div>
152: <?php
153: }
154:
155: 156: 157: 158: 159: 160: 161: 162:
163: function printItemsList($items) {
164: $indent = 1;
165: $open = array(1 => 0);
166: $rslt = false;
167: foreach ($items as $item) {
168: $order = explode('-', $item['sort_order']);
169: $level = max(1, count($order));
170: if ($toodeep = $level > 1 && $order[$level - 1] === '') {
171: $rslt = true;
172: }
173: if ($level > $indent) {
174: echo "\n" . str_pad("\t", $indent, "\t") . "<ul class=\"page-list\">\n";
175: $indent++;
176: $open[$indent] = 0;
177: } else if ($level < $indent) {
178: while ($indent > $level) {
179: $open[$indent] --;
180: $indent--;
181: echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n";
182: }
183: } else {
184: if ($open[$indent]) {
185: echo str_pad("\t", $indent, "\t") . "</li>\n";
186: $open[$indent] --;
187: } else {
188: echo "\n";
189: }
190: }
191: if ($open[$indent]) {
192: echo str_pad("\t", $indent, "\t") . "</li>\n";
193: $open[$indent] --;
194: }
195: echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $item['id'] . "\">";
196: echo printItemsListTable($item, $toodeep);
197: $open[$indent] ++;
198: }
199: while ($indent > 1) {
200: echo "</li>\n";
201: $open[$indent] --;
202: $indent--;
203: echo str_pad("\t", $indent, "\t") . "</ul>";
204: }
205: if ($open[$indent]) {
206: echo "</li>\n";
207: } else {
208: echo "\n";
209: }
210: return $rslt;
211: }
212:
213: 214: 215: 216: 217:
218: function printItemEditLink($item) {
219: $link = "";
220: $array = getItemTitleAndURL($item);
221: $title = html_encode($array['title']);
222: $link = '<a href="menu_tab_edit.php?edit&id=' . $item['id'] . "&type=" . $item['type'] . "&menuset=" . html_encode(checkChosenMenuset()) . '">' . $title . '</a>';
223: echo $link;
224: }
225:
226: 227: 228: 229:
230: function printItemStatusDropdown() {
231: $all = "";
232: $visible = "";
233: $hidden = "";
234: $status = checkChosenItemStatus();
235: $menuset = checkChosenMenuset();
236: ?>
237: <select name="ListBoxURL" id="ListBoxURL" class="dirtyignore" size="1" onchange="window.location = '?menuset=<?php echo urlencode($menuset); ?>&visible=' + $('#ListBoxURL').val()">
238: <?php
239: switch ($status) {
240: case "hidden":
241: $hidden = 'selected="selected"';
242: break;
243: case "visible":
244: $visible = 'selected="selected"';
245: break;
246: default:
247: $all = 'selected="selected"';
248: break;
249: }
250: echo "<option $all value='all'>" . gettext("Hidden and visible items") . "</option>\n";
251: echo "<option $visible value='visible'>" . gettext("Visible items") . "</option>\n";
252: echo "<option $hidden value='hidden'>" . gettext("hidden items") . "</option>\n";
253: ?>
254: </select>
255: <?php
256: }
257:
258: 259: 260: 261: 262:
263: function getMenuSetSelector($active) {
264: $menuset = checkChosenMenuset();
265: $menusets = array($menuset => $menuset);
266: $result = query_full_array("SELECT DISTINCT menuset FROM " . prefix('menu') . " ORDER BY menuset");
267: if ($result) {
268: foreach ($result as $set) {
269: $menusets[$set['menuset']] = $set['menuset'];
270: }
271: natcasesort($menusets);
272: } else {
273: return NULL;
274: }
275:
276: if ($active) {
277: $selector = '<select name="menuset" id="menuset" class="dirtyignore" size="1" onchange="window.location=\'?menuset=\'+encodeURIComponent($(\'#menuset\').val())">' . "\n";
278: } else {
279: $selector = '<select name="menuset" size="1">' . "\n";
280: }
281: foreach ($menusets as $set) {
282: if ($menuset == $set) {
283: $selected = 'selected="selected"';
284: } else {
285: $selected = '';
286: }
287: $selector .= '<option ' . $selected . ' value="' . html_encode($set) . '">' . html_encode($set) . "</option>\n";
288: }
289: $selector .= "</select>\n";
290: return $selector;
291: }
292:
293: 294: 295: 296: 297: 298: 299:
300: function publishItem($id, $show, $menuset) {
301: query("UPDATE " . prefix('menu') . " SET `show` = '" . $show . "' WHERE id = " . $id, true . " AND menuset = " . db_quote($menuset));
302: }
303:
304: 305: 306: 307: 308: 309: 310: 311:
312: function addSubalbumMenus($menuset, $id, $link, $sort) {
313: $album = newAlbum($link);
314: $show = $album->getShow();
315: $title = $album->getTitle();
316: $sql = "INSERT INTO " . prefix('menu') . " (`link`,`type`,`title`,`show`,`menuset`,`sort_order`, `parentid`) " .
317: 'VALUES (' . db_quote($link) . ', "album",' . db_quote($album->name) . ', ' . $show . ',' . db_quote($menuset) . ',' . db_quote($sort) . ',' . $id . ')';
318: $result = query($sql, false);
319: if ($result) {
320: $id = db_insert_id();
321: } else {
322: $result = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="album" AND `link`=' . db_quote($link));
323: $id = $result['id'];
324: }
325: if (!$album->isDynamic()) {
326: $albums = $album->getAlbums();
327: foreach ($albums as $key => $link) {
328: addSubalbumMenus($menuset, $id, $link, $sort . '-' . sprintf('%03u', $key));
329: }
330: }
331: }
332:
333: 334: 335: 336: 337: 338:
339: function addalbumsToDatabase($menuset, $base = NULL) {
340: global $_zp_gallery;
341: if (is_null($base)) {
342: $albumbase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
343: $sortbase = '';
344: } else {
345: $albumbase = array_pop($base);
346: $sortbase = '';
347: for ($i = 0; $i < count($base); $i++) {
348: $sortbase .= sprintf('%03u', $base[$i]) . '-';
349: }
350: }
351: $result = $albumbase;
352: $albums = $_zp_gallery->getAlbums();
353: foreach ($albums as $key => $link) {
354: addSubalbumMenus($menuset, 'NULL', $link, $sortbase . sprintf('%03u', $result = $key + $albumbase));
355: }
356: return $result;
357: }
358:
359: 360: 361: 362: 363: 364:
365: function addPagesToDatabase($menuset, $base = NULL) {
366: if (is_null($base)) {
367: $pagebase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
368: $sortbase = '';
369: } else {
370: $pagebase = array_pop($base);
371: $sortbase = '';
372: for ($i = 0; $i < count($base); $i++) {
373: $sortbase .= sprintf('%03u', $base[$i]) . '-';
374: }
375: }
376: $result = $pagebase;
377: $parents = array('NULL');
378: $result = query_full_array("SELECT * FROM " . prefix('pages') . " ORDER BY sort_order");
379: foreach ($result as $key => $item) {
380: $sorts = explode('-', $item['sort_order']);
381: $level = count($sorts);
382: $sorts[0] = sprintf('%03u', $result = $sorts[0] + $pagebase);
383: $order = $sortbase . implode('-', $sorts);
384: $show = $item['show'];
385: $link = $item['titlelink'];
386: $parent = $parents[$level - 1];
387: $sql = "INSERT INTO " . prefix('menu') . " (`title`, `link`, `type`, `show`,`menuset`,`sort_order`, `parentid`) " .
388: 'VALUES (' . db_quote($item['title']) . ',' . db_quote($link) . ',"zenpagepage",' . $show . ',' . db_quote($menuset) . ',' . db_quote($order) . ',' . $parent . ')';
389: if (query($sql, false)) {
390: $id = db_insert_id();
391: } else {
392: $rslt = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="zenpagepage" AND `link`="' . $link . '"');
393: $id = $rslt['id'];
394: }
395: $parents[$level] = $id;
396: }
397: return $result;
398: }
399:
400: 401: 402: 403:
404: function addCategoriesToDatabase($menuset, $base = NULL) {
405: if (is_null($base)) {
406: $categorybase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
407: $sortbase = '';
408: } else {
409: $categorybase = array_pop($base);
410: $sortbase = '';
411: for ($i = 0; $i < count($base); $i++) {
412: $sortbase .= sprintf('%03u', $base[$i]) . '-';
413: }
414: }
415: $result = $categorybase;
416: $parents = array('NULL');
417: $result = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY sort_order");
418: foreach ($result as $key => $item) {
419: $sorts = explode('-', $item['sort_order']);
420: $level = count($sorts);
421: $sorts[0] = sprintf('%03u', $result = $sorts[0] + $categorybase);
422: $order = $sortbase . implode('-', $sorts);
423: $link = $item['titlelink'];
424: $parent = $parents[$level - 1];
425: $sql = "INSERT INTO " . prefix('menu') . " (`title`, `link`, `type`, `show`,`menuset`,`sort_order`,`parentid`) " .
426: 'VALUES (' . db_quote($item['title']) . ',' . db_quote($link) . ',"zenpagecategory", 1,' . db_quote($menuset) . ',' . db_quote($order) . ',' . $parent . ')';
427: if (query($sql, false)) {
428: $id = db_insert_id();
429: } else {
430: $rslt = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="zenpagecategory" AND `link`="' . $link . '"');
431: $id = $rslt['id'];
432: }
433: $parents[$level] = $id;
434: }
435: return $result;
436: }
437:
438: 439: 440:
441:
442: 443: 444: 445: 446:
447: function addItem(&$reports) {
448: $menuset = checkChosenMenuset();
449: $result['type'] = sanitize($_POST['type']);
450: $result['show'] = getCheckboxState('show');
451: $result['include_li'] = getCheckboxState('include_li');
452: $result['id'] = 0;
453: if (getCheckboxState('span')) {
454: $result['span_id'] = sanitize($_POST['span_id']);
455: $result['span_class'] = sanitize($_POST['span_class']);
456: } else {
457: $result['span_id'] = '';
458: $result['span_class'] = '';
459: }
460: switch ($result['type']) {
461: case 'all_items':
462: query("INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
463: "VALUES ('" . gettext('Home') . "', '" . WEBPATH . '/' . "','galleryindex','1'," . db_quote($menuset) . ",'000')", true);
464: addAlbumsToDatabase($menuset);
465: if (extensionEnabled('zenpage')) {
466: query("INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
467: "VALUES ('" . gettext('News index') . "', '" . getNewsIndexURL() . "', 'zenpagenewsindex', '1', " . db_quote($menuset) . ", '001')", true);
468: addPagesToDatabase($menuset);
469: addCategoriesToDatabase($menuset);
470: }
471: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenphoto objects added.") . " </p>";
472: return NULL;
473: case 'all_albums':
474: addAlbumsToDatabase($menuset);
475: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all albums added.") . " </p>";
476: return NULL;
477: case 'all_zenpagepages':
478: addPagesToDatabase($menuset);
479: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenpage pages added.") . " </p>";
480: return NULL;
481: case 'all_zenpagecategorys':
482: addCategoriesToDatabase($menuset);
483: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenpage categories added.") . " </p>";
484: return NULL;
485: case 'album':
486: $result['title'] = $result['link'] = sanitize($_POST['albumselect']);
487: if (empty($result['link'])) {
488: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to select an album.") . " </p>";
489: return $result;
490: }
491: $successmsg = sprintf(gettext("Album menu item <em>%s</em> added"), $result['link']);
492: break;
493: case 'galleryindex':
494: $result['title'] = process_language_string_save("title", 2);
495: $result['link'] = NULL;
496: if (empty($result['title'])) {
497: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
498: return $result;
499: }
500: $successmsg = sprintf(gettext("Gallery index menu item <em>%s</em> added"), $result['link']);
501: break;
502: case 'zenpagepage':
503: $result['title'] = NULL;
504: $result['link'] = sanitize($_POST['pageselect']);
505: if (empty($result['link'])) {
506: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
507: return $result;
508: }
509: $successmsg = sprintf(gettext("Zenpage page menu item <em>%s</em> added"), $result['link']);
510: break;
511: case 'zenpagenewsindex':
512: $result['title'] = process_language_string_save("title", 2);
513: $result['link'] = NULL;
514: if (empty($result['title'])) {
515: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
516: return $result;
517: }
518: $successmsg = sprintf(gettext("Zenpage news index menu item <em>%s</em> added"), $result['link']);
519: break;
520: case 'zenpagecategory':
521: $result['title'] = NULL;
522: $result['link'] = sanitize($_POST['categoryselect']);
523: if (empty($result['link'])) {
524: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
525: return $result;
526: }
527: $successmsg = sprintf(gettext("Zenpage news category menu item <em>%s</em> added"), $result['link']);
528: break;
529: case 'custompage':
530: $result['title'] = process_language_string_save("title", 2);
531: $result['link'] = sanitize($_POST['custompageselect']);
532: if (empty($result['title'])) {
533: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
534: return $result;
535: }
536: $successmsg = sprintf(gettext("Custom page menu item <em>%s</em> added"), $result['link']);
537: break;
538: case 'customlink':
539: $result['title'] = process_language_string_save("title", 2);
540: if (empty($result['title'])) {
541: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
542: return $result;
543: }
544: $result['link'] = sanitize($_POST['link']);
545: if (empty($result['link'])) {
546: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
547: return $result;
548: }
549: $successmsg = sprintf(gettext("Custom page menu item <em>%s</em> added"), $result['link']);
550: break;
551: case 'menulabel':
552: $result['title'] = process_language_string_save("title", 2);
553: $result['link'] = NULL;
554: if (empty($result['title'])) {
555: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
556: return $result;
557: }
558: $successmsg = gettext("Custom label added");
559: break;
560: case 'menufunction':
561: $result['title'] = process_language_string_save("title", 2);
562: if (empty($result['title'])) {
563: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
564: return $result;
565: }
566: $result['link'] = sanitize($_POST['link'], 4);
567: if (empty($result['link'])) {
568: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
569: return $result;
570: }
571: $successmsg = sprintf(gettext("Function menu item <em>%s</em> added"), $result['link']);
572: break;
573: case 'html':
574: $result['title'] = process_language_string_save("title", 2);
575: if (empty($result['title'])) {
576: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
577: return $result;
578: }
579: $result['link'] = sanitize($_POST['link'], 4);
580: if (empty($result['link'])) {
581: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
582: return $result;
583: }
584: $successmsg = gettext("<em>HTML</em> added");
585: break;
586: default:
587: break;
588: }
589: $count = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
590: $order = sprintf('%03u', $count);
591: $sql = "INSERT INTO " . prefix('menu') . " ( `title`, `link`, `type`, `show`, `menuset`, `sort_order`, `include_li`, `span_id`, `span_class`) " .
592: "VALUES (" . db_quote($result['title']) .
593: ", " . db_quote($result['link']) .
594: ", " . db_quote($result['type']) . ", " . $result['show'] .
595: ", " . db_quote($menuset) . ", " . db_quote($order) . ", " . $result['include_li'] .
596: ", " . db_quote($result['span_id']) . ", " . db_quote($result['span_class']) .
597: ")";
598: if (query($sql, true)) {
599: $reports[] = "<p class = 'messagebox fade-message'>" . $successmsg . "</p>";
600:
601: $result['id'] = db_insert_id();
602: return $result;
603: } else {
604: if (empty($result['link'])) {
605: $reports[] = "<p class = 'errorbox fade-message'>" . sprintf(gettext('A <em>%1$s</em> item already exists in <em>%2$s </em>!'), $result['type'], $menuset) . "</p>";
606: } else {
607: $reports[] = "<p class = 'errorbox fade-message'>" . sprintf(gettext('A <em>%1$s</em> item with the link <em>%2$s</em> already exists in <em>%3$s </em>!'), $result['type'], $result['link'], $menuset) . "</p>";
608: }
609: return NULL;
610: }
611: }
612:
613: 614: 615: 616:
617: function updateMenuItem(&
618:
619: $reports) {
620: $menuset = checkChosenMenuset();
621: $result = array();
622: $result['id'] = sanitize($_POST['id']);
623: $result['show'] = getCheckboxState('show');
624: $result['type'] = sanitize($_POST['type']);
625: $result['title'] = process_language_string_save("title", 2);
626: $result['include_li'] = getCheckboxState('include_li');
627: if (getCheckboxState('span')) {
628: $result['span_id'] = sanitize($_POST['span_id']);
629: $result['span_class'] = sanitize($_POST['span_class']);
630: } else {
631: $result['span_id'] = '';
632: $result['span_class'] = '';
633: }
634: switch ($result['type']) {
635: case 'album':
636: $result['title'] = $result['link'] = sanitize($_POST['albumselect']);
637: if (empty($result['link'])) {
638: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to select an album.") . " </p>";
639: return $result;
640: }
641: break;
642: case 'galleryindex':
643: $result['title'] = process_language_string_save("title", 2);
644: $result['link'] = NULL;
645: if (empty($result['title'])) {
646: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
647: return $result;
648: }
649: break;
650: case 'zenpagepage':
651: $result['title'] = NULL;
652: $result['link'] = sanitize($_POST['pageselect']);
653: if (empty($result['link'])) {
654: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
655: return $result;
656: }
657: break;
658: case 'zenpagenewsindex':
659: $result['title'] = process_language_string_save("title", 2);
660: $result['link'] = NULL;
661: if (empty($result['title'])) {
662: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
663: return $result;
664: }
665: break;
666: case 'zenpagecategory':
667: $result['title'] = NULL;
668: $result['link'] = sanitize($_POST['categoryselect']);
669: if (empty($result['link'])) {
670: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
671: return $result;
672: }
673: break;
674: case 'custompage':
675: $result['title'] = process_language_string_save("title", 2);
676: $result['link'] = sanitize($_POST['custompageselect']);
677: if (empty($result['title'])) {
678: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
679: return $result;
680: }
681: break;
682: case 'customlink':
683: $result['title'] = process_language_string_save("title", 2);
684: if (empty($result['title'])) {
685: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
686: return $result;
687: }
688: $result['link'] = sanitize($_POST['link']);
689: if (empty($result['link'])) {
690: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
691: return $result;
692: }
693: break;
694: case 'menulabel':
695: $result['title'] = process_language_string_save("title", 2);
696: $result['link'] = NULL;
697: if (empty($result['title'])) {
698: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
699: return $result;
700: }
701: break;
702: case 'menufunction':
703: $result['title'] = process_language_string_save("title", 2);
704: if (empty($result['title'])) {
705: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
706: return $result;
707: }
708: $result['link'] = sanitize($_POST['link'], 4);
709: if (empty($result['link'])) {
710: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
711: return $result;
712: }
713: break;
714: case 'html':
715: $result['title'] = process_language_string_save("title", 2);
716: if (empty($result['title'])) {
717: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
718: return $result;
719: }
720: $result['link'] = sanitize($_POST['link'], 4);
721: if (empty($result['link'])) {
722: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
723: return $result;
724: }
725: break;
726: default:
727: $result['link'] = sanitize($_POST['link'], 4);
728: break;
729: }
730:
731: $sql = "UPDATE " . prefix('menu') . " SET title = " . db_quote($result['title']) .
732: ", link = " . db_quote($result['link']) .
733: ", type = " . db_quote($result['type']) . ", `show` = " . db_quote($result['show']) .
734: ", menuset = " . db_quote($menuset) . ", include_li = " . $result['include_li'] .
735: ", span_id = " . db_quote($result['span_id']) . ", span_class = " . db_quote($result['span_class']) .
736: " WHERE `id` = " . $result['id'];
737: if (query($sql)) {
738: if (isset($_POST['title']) && empty($result['title'])) {
739: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
740: } else if (isset($_POST['link']) && empty($result['link'])) {
741: $reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
742: } else {
743: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu item updated!") . " </p>";
744: }
745: }
746: return $result;
747: }
748:
749: 750: 751: 752:
753: function deleteItem(&
754:
755: $reports) {
756: if (isset($_GET['delete'])) {
757: $delete = sanitize_numeric($_GET['delete'], 3);
758: query("DELETE FROM " . prefix('menu') . " WHERE `id` = $delete");
759: $reports[] = "<p class = 'messagebox fade-message'>" . gettext("Custom menu item successfully deleted!") . " </p>";
760: }
761: }
762:
763: 764: 765: 766: 767: 768: 769: 770: 771:
772: function printAlbumsSelector($current) {
773: global $_zp_gallery;
774: $albumlist = array();
775: genAlbumList($albumlist, NULL, ALL_ALBUMS_RIGHTS);
776: ?>
777: <select id="albumselector" name="albumselect">
778: <?php
779: foreach ($albumlist as $key => $value) {
780: $albumobj = newAlbum($key);
781: $albumname = $albumobj->name;
782: if ($albumname == $current) {
783: $selected = ' selected="selected"';
784: } else {
785: $selected = '';
786: }
787: $level = substr_count($albumname, "/");
788: $arrow = "";
789: for ($count = 1; $count <= $level; $count++) {
790: $arrow .= "» ";
791: }
792: echo "<option value = '" . html_encode($albumobj->name) . "'" . $selected . '>';
793: echo $arrow . $albumobj->getTitle() . unpublishedZenphotoItemCheck($albumobj) . "</option>";
794: }
795: ?>
796: </select>
797: <?php
798: }
799:
800: 801: 802: 803: 804: 805: 806:
807: function printZenpagePagesSelector($current) {
808: global $_zp_gallery, $_zp_zenpage;
809: ?>
810: <select id="pageselector" name="pageselect">
811: <?php
812: $pages = $_zp_zenpage->getPages(false);
813: foreach ($pages as $key => $page) {
814: if ($page['titlelink'] == $current) {
815: $selected = ' selected= "selected
816:
817: "';
818: } else {
819: $selected = '';
820: }
821: $pageobj = new ZenpagePage($page['titlelink']);
822: $level = substr_count($pageobj->getSortOrder(), "-");
823: $arrow = "";
824: for ($count = 1; $count <= $level; $count++) {
825: $arrow .= "» ";
826: }
827: echo "<option value = '" . html_encode($pageobj->getTitlelink()) . "'" . $selected . '>';
828: echo $arrow . $pageobj->getTitle() . unpublishedZenphotoItemCheck($pageobj) . "</option>";
829: }
830: ?>
831: </select>
832: <?php
833: }
834:
835: 836: 837: 838: 839: 840: 841: 842: 843:
844: function printZenpageNewsCategorySelector($current) {
845: global $_zp_gallery, $_zp_zenpage;
846: ?>
847: <select id="categoryselector" name="categoryselect">
848: <?php
849: $cats = $_zp_zenpage->getAllCategories(false);
850: foreach ($cats as $cat) {
851: if ($cat['titlelink'] == $current) {
852: $selected = ' selected="selected"';
853: } else {
854: $selected = '';
855: }
856: $catobj = new ZenpageCategory($cat['titlelink']);
857:
858: $getparents = $catobj->getParents();
859: $levelmark = '';
860: foreach ($getparents as $parent) {
861: $levelmark .= '» ';
862: }
863: echo "<option value = '" . html_encode($catobj->getTitlelink()) . "'" . $selected . '>';
864: echo $levelmark . $catobj->getTitle() . "</option>"
865:
866: ;
867: }
868: ?>
869: </select>
870: <?php
871: }
872:
873: 874: 875: 876: 877:
878: function printCustomPageSelector($current) {
879: global $_zp_gallery;
880: ?>
881: <select id="custompageselector" name="custompageselect">
882: <?php
883: $curdir = getcwd();
884: $themename = $_zp_gallery->getCurrentTheme();
885: $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/';
886: chdir($root);
887: $filelist = safe_glob('*.php');
888: $list = array();
889: foreach ($filelist as $file) {
890: $file = filesystemToInternal($file);
891: $list[$file] = str_replace('.php', '', $file);
892: }
893: generateListFromArray(array($current), $list, false, true);
894: chdir($curdir);
895: ?>
896: </select>
897: <?php
898: }
899:
900: 901: 902: 903: 904:
905: function unpublishedZenphotoItemCheck($obj, $dropdown = true) {
906: if ($obj->getShow() != "1") {
907: $show = "*";
908: } else {
909: $show = "";
910: }
911: return $show;
912: }
913:
914: 915: 916: 917:
918: function processMenuBulkActions() {
919: $report = NULL;
920: if (isset($_POST[
921: 'ids'])) {
922: $action = sanitize(
923: $_POST['checkallaction']);
924: $ids = $_POST['ids'];
925: $total = count($ids);
926: $message = NULL;
927: if ($action != 'noaction') {
928: if ($total > 0) {
929: $n = 0;
930: switch ($action) {
931: case 'deleteall':
932: $sql = "DELETE FROM " . prefix('menu') . " WHERE ";
933: $message = gettext('Selected items deleted');
934: break;
935: case 'showall':
936: $sql = "UPDATE " . prefix('menu') . " SET `show` = 1 WHERE ";
937: $message = gettext('Selected items published');
938: break;
939: case 'hideall':
940: $sql = "UPDATE " . prefix('menu') . " SET `show` = 0 WHERE ";
941: $message = gettext('Selected items unpublished');
942: break;
943: }
944: foreach ($ids as $id) {
945: $n++;
946: $sql .= " id = '" . sanitize_numeric($id) . "' ";
947: if ($n < $total)
948: $sql .= "OR ";
949: }
950: query($sql);
951: }
952: if (!is_null($message))
953: $report = "<p class = 'messagebox fade-message'>" . $message . "</p>";
954: }
955: }
956: return $report;
957: }
958: ?>
959: