Mostly functional publication creation/deletion/editing
This commit is contained in:
parent
2c60d8f941
commit
50b78fd920
47
action.php
47
action.php
@ -3,7 +3,6 @@
|
|||||||
/**
|
/**
|
||||||
* Make things happen when buttons are pressed and forms submitted.
|
* Make things happen when buttons are pressed and forms submitted.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once __DIR__ . "/required.php";
|
require_once __DIR__ . "/required.php";
|
||||||
|
|
||||||
if ($VARS['action'] !== "signout") {
|
if ($VARS['action'] !== "signout") {
|
||||||
@ -27,6 +26,52 @@ function returnToSender($msg, $arg = "") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($VARS['action']) {
|
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":
|
case "signout":
|
||||||
session_destroy();
|
session_destroy();
|
||||||
header('Location: index.php');
|
header('Location: index.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.",
|
"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.",
|
"captcha error" => "There was a problem with the CAPTCHA (robot test). Try again.",
|
||||||
"home" => "Home",
|
"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} <i class=\"fa fa-angle-right\"></i> {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"
|
||||||
]);
|
]);
|
@ -12,5 +12,17 @@ define("MESSAGES", [
|
|||||||
"404_error" => [
|
"404_error" => [
|
||||||
"string" => "page not found",
|
"string" => "page not found",
|
||||||
"type" => "info"
|
"type" => "info"
|
||||||
]
|
],
|
||||||
|
"pub_saved" => [
|
||||||
|
"string" => "publication saved",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"pub_deleted" => [
|
||||||
|
"string" => "publication deleted",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"invalid_pubid" => [
|
||||||
|
"string" => "invalid pubid",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__ . '/../required.php';
|
require_once __DIR__ . '/../required.php';
|
||||||
|
require_once __DIR__ . '/userinfo.php';
|
||||||
|
|
||||||
dieifnotloggedin();
|
dieifnotloggedin();
|
||||||
|
|
||||||
@ -69,10 +70,11 @@ $pubs = $database->select('publications', [
|
|||||||
'stylename',
|
'stylename',
|
||||||
'columns',
|
'columns',
|
||||||
'permname',
|
'permname',
|
||||||
'permid'
|
'publications.permid'
|
||||||
], $where);
|
], $where);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$out['status'] = "OK";
|
$out['status'] = "OK";
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$recordsFiltered = $database->count('publications', [
|
$recordsFiltered = $database->count('publications', [
|
||||||
@ -88,6 +90,7 @@ $usercache = [];
|
|||||||
for ($i = 0; $i < count($pubs); $i++) {
|
for ($i = 0; $i < count($pubs); $i++) {
|
||||||
$pubs[$i]["editbtn"] = '<a class="btn btn-blue btn-xs" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '"><i class="fa fa-pencil-square-o"></i> ' . lang("edit", false) . '</a>';
|
$pubs[$i]["editbtn"] = '<a class="btn btn-blue btn-xs" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '"><i class="fa fa-pencil-square-o"></i> ' . lang("edit", false) . '</a>';
|
||||||
$pubs[$i]["clonebtn"] = '<a class="btn btn-green btn-xs" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '&clone=1"><i class="fa fa-clone"></i> ' . lang("clone", false) . '</a>';
|
$pubs[$i]["clonebtn"] = '<a class="btn btn-green btn-xs" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '&clone=1"><i class="fa fa-clone"></i> ' . lang("clone", false) . '</a>';
|
||||||
|
$pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"]));
|
||||||
if (is_null($pubs[$i]['uid'])) {
|
if (is_null($pubs[$i]['uid'])) {
|
||||||
$pubs[$i]["username"] = "";
|
$pubs[$i]["username"] = "";
|
||||||
} else {
|
} else {
|
||||||
|
18
pages.php
18
pages.php
@ -22,6 +22,24 @@ define("PAGES", [
|
|||||||
"static/js/editpub.js"
|
"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" => [
|
"404" => [
|
||||||
"title" => "404 error"
|
"title" => "404 error"
|
||||||
]
|
]
|
||||||
|
0
pages/content.php
Normal file
0
pages/content.php
Normal file
@ -1 +1,130 @@
|
|||||||
<h1>Hello World</h1>
|
<?php
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
$pubdata = [
|
||||||
|
'name' => '',
|
||||||
|
'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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="panel panel-blue">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<?php
|
||||||
|
if ($cloning) {
|
||||||
|
?>
|
||||||
|
<i class="fa fa-pencil-square-o"></i> <?php lang2("cloning publication", ['opub' => htmlspecialchars($pubdata['name']), 'npub' => "<span id=\"name_title\">" . htmlspecialchars($pubdata['name']) . "</span>"]); ?>
|
||||||
|
<?php
|
||||||
|
} else if ($editing) {
|
||||||
|
?>
|
||||||
|
<i class="fa fa-pencil-square-o"></i> <?php lang2("editing publication", ['pub' => "<span id=\"name_title\">" . htmlspecialchars($pubdata['name']) . "</span>"]); ?>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
<i class="fa fa-pencil-square-o"></i> <?php lang("adding publication"); ?>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name"><i class="fa fa-font"></i> <?php lang("name"); ?></label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" placeholder="<?php lang("placeholder name"); ?>" required="required" value="<?php echo htmlspecialchars($pubdata['name']); ?>" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-md-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="style"><i class="fa fa-star"></i> <?php lang('style'); ?></label>
|
||||||
|
<select name="style" class="form-control" required>
|
||||||
|
<?php
|
||||||
|
$styles = $database->select("pub_styles", ['styleid', 'stylename']);
|
||||||
|
foreach ($styles as $s) {
|
||||||
|
$si = $s['styleid'];
|
||||||
|
$sn = $s['stylename'];
|
||||||
|
$ss = $pubdata["styleid"] == $si ? " selected" : "";
|
||||||
|
echo "<option value=\"$si\"$ss>$sn</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="columns"><i class="fa fa-columns"></i> <?php lang('columns'); ?></label>
|
||||||
|
<input type="number" class="form-control" id="columns" name="columns" placeholder="2" value="<?php echo $pubdata['columns']; ?>" required />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="perm"><i class="fa fa-eye"></i> <?php lang('visibility'); ?></label>
|
||||||
|
<select name="perm" class="form-control" required>
|
||||||
|
<?php
|
||||||
|
$perms = $database->select("pub_permissions", ['permid', 'permname']);
|
||||||
|
foreach ($perms as $p) {
|
||||||
|
$pi = $p['permid'];
|
||||||
|
$pn = $p['permname'];
|
||||||
|
$ps = $pubdata["permid"] == $pi ? " selected" : "";
|
||||||
|
echo "<option value=\"$pi\"$ps>$pn</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="pubid" value="<?php
|
||||||
|
if ($editing && !$cloning) {
|
||||||
|
echo htmlspecialchars($VARS['id']);
|
||||||
|
}
|
||||||
|
?>" />
|
||||||
|
<input type="hidden" name="action" value="editpub" />
|
||||||
|
<input type="hidden" name="source" value="home" />
|
||||||
|
|
||||||
|
<div class="panel-footer">
|
||||||
|
<button type="submit" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button>
|
||||||
|
<?php
|
||||||
|
if ($editing && !$cloning) {
|
||||||
|
?>
|
||||||
|
<a href="action.php?action=deletepub&source=home&pubid=<?php echo htmlspecialchars($VARS['id']); ?>" class="btn btn-danger btn-xs pull-right mgn-top-8px"><i class="fa fa-times"></i> <?php lang('delete'); ?></a>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
0
pages/maillist.php
Normal file
0
pages/maillist.php
Normal file
@ -35,6 +35,9 @@ define("PORTAL_KEY", "123");
|
|||||||
// For supported values, see http://php.net/manual/en/timezones.php
|
// For supported values, see http://php.net/manual/en/timezones.php
|
||||||
define("TIMEZONE", "America/Denver");
|
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.
|
// Base URL for site links.
|
||||||
define('URL', 'http://localhost/newspen');
|
define('URL', 'http://localhost/newspen');
|
||||||
|
|
||||||
|
3
static/js/editpub.js
Normal file
3
static/js/editpub.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
$('#name').on('input propertychange paste', function() {
|
||||||
|
$('#name_title').text($('#name').val());
|
||||||
|
});
|
55
static/js/maillist.js
Normal file
55
static/js/maillist.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
var pubtable = $('#pubtable').DataTable({
|
||||||
|
responsive: {
|
||||||
|
details: {
|
||||||
|
display: $.fn.dataTable.Responsive.display.modal({
|
||||||
|
header: function (row) {
|
||||||
|
var data = row.data();
|
||||||
|
return "<i class=\"fa fa-cube fa-fw\"></i> " + 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user