From 50b78fd920ffa97f4d06430fa0184e1adf16b07a Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Thu, 30 Nov 2017 00:18:55 -0700 Subject: [PATCH] Mostly functional publication creation/deletion/editing --- action.php | 47 ++++++++++++++- lang/en_us.php | 19 ++++++ lang/messages.php | 14 ++++- lib/getpubtable.php | 5 +- pages.php | 18 ++++++ pages/content.php | 0 pages/editpub.php | 131 +++++++++++++++++++++++++++++++++++++++++- pages/maillist.php | 0 settings.template.php | 3 + static/js/editpub.js | 3 + static/js/maillist.js | 55 ++++++++++++++++++ 11 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 pages/content.php create mode 100644 pages/maillist.php create mode 100644 static/js/editpub.js create mode 100644 static/js/maillist.js diff --git a/action.php b/action.php index f7ed372..a554ac6 100644 --- a/action.php +++ b/action.php @@ -3,7 +3,6 @@ /** * Make things happen when buttons are pressed and forms submitted. */ - require_once __DIR__ . "/required.php"; if ($VARS['action'] !== "signout") { @@ -27,6 +26,52 @@ function returnToSender($msg, $arg = "") { } switch ($VARS['action']) { + case "editpub": + $insert = true; + if (is_empty($VARS['pubid'])) { + $insert = true; + } else { + if ($database->has('publications', ['pubid' => $VARS['pubid']])) { + $insert = false; + } else { + returnToSender("invalid_pubid"); + } + } + if (is_empty($VARS['name'])) { + returnToSender('invalid_parameters'); + } + if (!is_numeric($VARS['columns'])) { + returnToSender('invalid_parameters'); + } + if (!$database->has('pub_styles', ["styleid" => $VARS['style']])) { + returnToSender('invalid_parameters'); + } + if (!$database->has('pub_permissions', ["permid" => $VARS['perm']])) { + returnToSender('invalid_parameters'); + } + + $data = [ + 'pubname' => $VARS['name'], + 'pubdate' => date("Y-m-d H:i:s"), + 'styleid' => $VARS['style'], + 'columns' => $VARS['columns'], + 'permid' => $VARS['perm'] + ]; + + if ($insert) { + $data['uid'] = $_SESSION['uid']; + $database->insert('publications', $data); + } else { + $database->update('publications', $data, ['pubid' => $VARS['pubid']]); + } + + returnToSender("pub_saved"); + case "deletepub": + if ($database->has('publications', ['pubid' => $VARS['pubid']])) { + $database->delete('publications', ['pubid' => $VARS['pubid']]); + returnToSender("pub_deleted"); + } + returnToSender("invalid_parameters"); case "signout": session_destroy(); header('Location: index.php'); diff --git a/lang/en_us.php b/lang/en_us.php index 0c69d14..048537b 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -25,4 +25,23 @@ define("STRINGS", [ "login server user data error" => "The login server refused to provide account information. Try again or contact technical support.", "captcha error" => "There was a problem with the CAPTCHA (robot test). Try again.", "home" => "Home", + "new publication" => "New Publication", + "actions" => "Actions", + "name" => "Name", + "date" => "Date", + "author" => "Author", + "style" => "Style", + "columns" => "Columns", + "visibility" => "Visibility", + "adding publication" => "Adding Publication", + "cloning publication" => "Copying {opub} {npub}", + "editing publication" => "Editing {pub}", + "placeholder name" => "", + "content" => "Content", + "edit" => "Edit", + "clone" => "Clone", + "publication saved" => "Publication saved.", + "publication deleted" => "Publication deleted.", + "invalid pubid" => "Invalid publication ID.", + "mailing lists" => "Mailing Lists" ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 8ac0b7a..4128300 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -12,5 +12,17 @@ define("MESSAGES", [ "404_error" => [ "string" => "page not found", "type" => "info" - ] + ], + "pub_saved" => [ + "string" => "publication saved", + "type" => "success" + ], + "pub_deleted" => [ + "string" => "publication deleted", + "type" => "success" + ], + "invalid_pubid" => [ + "string" => "invalid pubid", + "type" => "danger" + ], ]); diff --git a/lib/getpubtable.php b/lib/getpubtable.php index 1fdcb87..88e1aea 100644 --- a/lib/getpubtable.php +++ b/lib/getpubtable.php @@ -1,6 +1,7 @@ select('publications', [ 'stylename', 'columns', 'permname', - 'permid' + 'publications.permid' ], $where); + $out['status'] = "OK"; if ($filter) { $recordsFiltered = $database->count('publications', [ @@ -88,6 +90,7 @@ $usercache = []; for ($i = 0; $i < count($pubs); $i++) { $pubs[$i]["editbtn"] = ' ' . lang("edit", false) . ''; $pubs[$i]["clonebtn"] = ' ' . lang("clone", false) . ''; + $pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"])); if (is_null($pubs[$i]['uid'])) { $pubs[$i]["username"] = ""; } else { diff --git a/pages.php b/pages.php index 3565641..86c2918 100644 --- a/pages.php +++ b/pages.php @@ -22,6 +22,24 @@ define("PAGES", [ "static/js/editpub.js" ], ], + "content" => [ + "title" => "content", + "navbar" => true, + "icon" => "paragraph", + ], + "maillist" => [ + "title" => "mailing lists", + "navbar" => true, + "icon" => "envelope", + "styles" => [ + "static/css/datatables.min.css", + "static/css/tables.css" + ], + "scripts" => [ + "static/js/datatables.min.js", + "static/js/maillist.js" + ], + ], "404" => [ "title" => "404 error" ] diff --git a/pages/content.php b/pages/content.php new file mode 100644 index 0000000..e69de29 diff --git a/pages/editpub.php b/pages/editpub.php index 9a1eb8d..f87d6e5 100644 --- a/pages/editpub.php +++ b/pages/editpub.php @@ -1 +1,130 @@ -

Hello World

\ No newline at end of file + '', + 'pubdate' => '', + 'styleid' => '', + 'columns' => '', + 'permid' => '' + ]; + +$editing = false; +$cloning = false; + +if (!is_empty($VARS['id'])) { + if ($database->has('publications', ['pubid' => $VARS['id']])) { + $editing = true; + if ($VARS['clone'] == 1) { + $cloning = true; + } + $pubdata = $database->select( + 'publications', + [ + 'pubname (name)', + 'pubdate', + 'styleid', + 'columns', + 'permid' + ], [ + 'pubid' => $VARS['id'] + ])[0]; + } else { + // item id is invalid, redirect to a page that won't cause an error when pressing Save + header('Location: app.php?page=editpub'); + die(); + } +} +?> + +
+
+
+

+ + htmlspecialchars($pubdata['name']), 'npub' => "" . htmlspecialchars($pubdata['name']) . ""]); ?> + + "" . htmlspecialchars($pubdata['name']) . ""]); ?> + + + +

+
+
+
+ + " required="required" value="" /> +
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + + + + + +
+
\ No newline at end of file diff --git a/pages/maillist.php b/pages/maillist.php new file mode 100644 index 0000000..e69de29 diff --git a/settings.template.php b/settings.template.php index 87188d7..121e59e 100644 --- a/settings.template.php +++ b/settings.template.php @@ -35,6 +35,9 @@ define("PORTAL_KEY", "123"); // For supported values, see http://php.net/manual/en/timezones.php define("TIMEZONE", "America/Denver"); +define("DATETIME_FORMAT", "M j Y g:i A"); // 12 hour time +#define("DATETIME_FORMAT", "M j Y G:i"); // 24 hour time + // Base URL for site links. define('URL', 'http://localhost/newspen'); diff --git a/static/js/editpub.js b/static/js/editpub.js new file mode 100644 index 0000000..7a18cab --- /dev/null +++ b/static/js/editpub.js @@ -0,0 +1,3 @@ +$('#name').on('input propertychange paste', function() { + $('#name_title').text($('#name').val()); +}); \ No newline at end of file diff --git a/static/js/maillist.js b/static/js/maillist.js new file mode 100644 index 0000000..5ff5322 --- /dev/null +++ b/static/js/maillist.js @@ -0,0 +1,55 @@ +var pubtable = $('#pubtable').DataTable({ + responsive: { + details: { + display: $.fn.dataTable.Responsive.display.modal({ + header: function (row) { + var data = row.data(); + return " " + data[2]; + } + }), + renderer: $.fn.dataTable.Responsive.renderer.tableAll({ + tableClass: 'table' + }), + type: "column" + } + }, + columnDefs: [ + { + targets: 0, + className: 'control', + orderable: false + }, + { + targets: 1, + orderable: false + }, + { + targets: 4, + orderable: false + } + ], + order: [ + [2, 'asc'] + ], + serverSide: true, + ajax: { + url: "lib/getpubtable.php", + dataFilter: function (data) { + var json = jQuery.parseJSON(data); + json.data = []; + json.pubs.forEach(function (row) { + json.data.push([ + "", + row.editbtn + " " + row.clonebtn, + row.pubname, + row.pubdate, + row.username, + row.stylename, + row.columns, + row.permname + ]); + }); + return JSON.stringify(json); + } + } +}); \ No newline at end of file