- if ($history_id) {
- message('The fields below have been filled with an archived version of this page. To publish this version (revert the page) click "save" button at the bottom. Feel free to make changes before saving.');
- $history_data = db_get_assoc('history_cms_pages', 'id,'.ADMIN_PAGES_DB_FIELDS, 'where history_id=%i', $history_id);
- if (!$history_data) {
- message("Error 3938 please inform developer");
- return './admin_pages';
- }
- $id = $history_data['id'];
- }
- if($id) {
- tem_set('id', $id);
- }
-
- tem_set('$basename', 'admin_pages');
-
- pulldown('layout', [
- ['0', "Full (no sidebar)"],
- ['1', "With Plain Sidebar"],
- ['2', "With Bordered Sidebar"]
- ]);
-
- $navbar_options = array(array('ignored', 'Not at all'), array('0', 'First'));
- $rows = db_get_rows('cms_pages', 'id,coalesce(nullif(nav_title,\'\'), title) as title,navbar', 'where navbar != 0 order by navbar');
- if($rows) for($i = 0; $i < count($rows); ++$i) {
- list($other_id, $other_title, $other_ord) = $rows[$i];
- if($other_id != $id) { # don't display ourselves
- $navbar_options[] = array($i + 1, "After \"$other_title\"");
- }
- }
- pulldown('navbar', $navbar_options, PULLDOWN_2D);
-
- if(isset($_POST['title'])) {
- $data = admin_pages_get_fields();
-
- # We'll save anything (no required fields)
-
- $data['navbar'] = db_reposition('cms_pages', $id, $data['navbar'], 'navbar', 'page');
-
- if($data['navbar'] && $data['filename'] == '') {
- message('This page was removed from the navigation column because it does not have a filename. (Pages without filenames are visible only to admins.)');
- $data['navbar'] = 0;
- }
-
- # save
- if($id) {
- db_update_assoc('cms_pages', $data, 'where id=%i', $id);
- message('Page updated.');
- } else {
- db_insert_assoc('cms_pages', $data);
- $id = db_auto_id();
- message('Page saved.');
- }
-
- # save to version history
- $data['id'] = $id;
- $data['history_when'] = time();
- $s = session_auth();
- $data['history_user_id'] = $s['id'];
- db_insert_assoc('history_cms_pages', $data);
-
- # redirect
- if ($data['filename'] === 'index') {
- return './';
- } elseif($data['filename'] !== '') {
- return "./{$data['filename']}";
- } else {
- return "./admin_pages?id=$id";
- }
- } elseif($id) {
- # we've recieved an edit id, but no data. So we grab the values to be edited from the database
- if ($history_id) {
- $data = $history_data;
- } else {
- $data = db_get_assoc('cms_pages', ADMIN_PAGES_DB_FIELDS, 'where id=%i', $id);
- }
- if($data['navbar']) {
- $data['navbar'] = db_count('cms_pages', 'where navbar!=0 && navbar<%i', $data['navbar']);
- } else {
- $data['navbar'] = 'ignored';
- }
- } else {
- # form not submitted, set default values:
- $data = array('filename' => format_cms_filename($_REQUEST['new_filename']));
- }
-
- if (!isset($data['layout']) || $data['layout'] === '' || $data['layout'] === '0') {
- $data['sidebar_editor_display'] = 'none';
- } else {
- $data['sidebar_editor_display'] = 'block';
- }
-
- tem_set('wfpl_images_json', json_encode(admin_pages_get_images()));
- tem_set('wfpl_image_width_full', WFPL_IMAGE_WIDTH_FULL);
- tem_set('wfpl_image_width_small', WFPL_IMAGE_WIDTH_SMALL);
- tem_set('wfpl_image_width_thumb', WFPL_IMAGE_WIDTH_THUMB);
- tem_set('form', $data);
- tem_set('$head'); # wysiwyg init goes in <head>
+ if ($history_id) {
+ message('The fields below have been filled with an archived version of this page. To publish this version (revert the page) click "save" button at the bottom. Feel free to make changes before saving.');
+ $history_data = db_get_assoc('history_cms_pages', 'id,'.ADMIN_PAGES_DB_FIELDS, 'where history_id=%i', $history_id);
+ if (!$history_data) {
+ message("Error 3938 please inform developer");
+ return './admin_pages';
+ }
+ $id = $history_data['id'];
+ } elseif ($id) {
+ if (db_count('history_cms_pages', 'where id=%i', $id) > 1) {
+ tem_set('archived_versions');
+ }
+ }
+ if($id) {
+ tem_set('id', $id);
+ }
+
+ tem_set('$basename', 'admin_pages');
+
+ pulldown('layout', [
+ ['0', "Full (no sidebar)"],
+ ['1', "With Plain Sidebar"],
+ ['2', "With Bordered Sidebar"]
+ ]);
+
+ $navbar_options = array(array('ignored', 'Not at all'), array('0', 'First'));
+ $rows = db_get_rows('cms_pages', 'id,coalesce(nullif(nav_title,\'\'), title) as title,navbar', 'where navbar != 0 order by navbar');
+ if($rows) for($i = 0; $i < count($rows); ++$i) {
+ list($other_id, $other_title, $other_ord) = $rows[$i];
+ if($other_id != $id) { # don't display ourselves
+ $navbar_options[] = array($i + 1, "After \"$other_title\"");
+ }
+ }
+ pulldown('navbar', $navbar_options, PULLDOWN_2D);
+
+ if(isset($_POST['title'])) {
+ $data = admin_pages_get_fields();
+
+ # We'll save anything (no required fields)
+
+ $data['navbar'] = db_reposition('cms_pages', $id, $data['navbar'], 'navbar', 'page');
+
+ if($data['navbar'] && $data['filename'] == '') {
+ message('This page was removed from the navigation column because it does not have a filename. (Pages without filenames are visible only to admins.)');
+ $data['navbar'] = 0;
+ }
+
+ # save
+ if($id) {
+ db_update_assoc('cms_pages', $data, 'where id=%i', $id);
+ message('Page updated.');
+ } else {
+ db_insert_assoc('cms_pages', $data);
+ $id = db_auto_id();
+ message('Page saved.');
+ }
+
+ # save to version history
+ $data['id'] = $id;
+ $data['history_when'] = time();
+ $s = session_auth();
+ $data['history_user_id'] = $s['id'];
+ db_insert_assoc('history_cms_pages', $data);
+
+ # redirect
+ if ($data['filename'] === 'index') {
+ return './';
+ } elseif($data['filename'] !== '') {
+ return "./{$data['filename']}";
+ } else {
+ return "./admin_pages?id=$id";
+ }
+ } elseif($id) {
+ # we've recieved an edit id, but no data. So we grab the values to be edited from the database
+ if ($history_id) {
+ $data = $history_data;
+ } else {
+ $data = db_get_assoc('cms_pages', ADMIN_PAGES_DB_FIELDS, 'where id=%i', $id);
+ }
+ if($data['navbar']) {
+ $data['navbar'] = db_count('cms_pages', 'where navbar!=0 && navbar<%i', $data['navbar']);
+ } else {
+ $data['navbar'] = 'ignored';
+ }
+ } else {
+ # form not submitted, set default values:
+ $data = array('filename' => format_cms_filename($_REQUEST['new_filename']));
+ }
+
+ if (!isset($data['layout']) || $data['layout'] === '' || $data['layout'] === '0') {
+ $data['sidebar_editor_display'] = 'none';
+ } else {
+ $data['sidebar_editor_display'] = 'block';
+ }
+
+ tem_set('wfpl_images_json', json_encode(admin_pages_get_images()));
+ tem_set('wfpl_image_width_full', WFPL_IMAGE_WIDTH_FULL);
+ tem_set('wfpl_image_width_small', WFPL_IMAGE_WIDTH_SMALL);
+ tem_set('wfpl_image_width_thumb', WFPL_IMAGE_WIDTH_THUMB);
+ tem_set('form', $data);
+ tem_set('$head'); # wysiwyg init goes in <head>