Add some basic mailing list code
This commit is contained in:
parent
0e767d3930
commit
c8c0f636f0
49
action.php
49
action.php
@ -164,6 +164,55 @@ switch ($VARS['action']) {
|
||||
|
||||
$database->delete('tiles', ["tileid" => $VARS['tileid']]);
|
||||
exit(json_encode(["status" => "OK"]));
|
||||
case "editlist":
|
||||
$insert = true;
|
||||
if (is_empty($VARS['listid'])) {
|
||||
$insert = true;
|
||||
} else {
|
||||
if ($database->has('mail_lists', ['listid' => $VARS['listid']])) {
|
||||
$insert = false;
|
||||
if ($database->get("mail_lists", 'uid', ['listid' => $VARS['listid']]) != $_SESSION['uid']) {
|
||||
returnToSender("no_permission");
|
||||
}
|
||||
} else {
|
||||
returnToSender("invalid_listid");
|
||||
}
|
||||
}
|
||||
if (is_empty($VARS['name'])) {
|
||||
returnToSender('invalid_parameters');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'listname' => $VARS['name']
|
||||
];
|
||||
|
||||
if ($insert) {
|
||||
$data['uid'] = $_SESSION['uid'];
|
||||
$database->insert('mail_lists', $data);
|
||||
$listid = $database->id();
|
||||
if (is_empty($VARS['cloneid']) || !$database->has("mail_lists", ['listid' => $VARS['cloneid']])) {
|
||||
// Yeah, I'm copypasting. Deal with it.
|
||||
} else {
|
||||
$addresses = $database->select("addresses", ["email", "name"], ["listid" => $VARS['cloneid']]);
|
||||
foreach ($addresses as $addr) {
|
||||
$addr["listid"] = $listid;
|
||||
$database->insert("addresses", $addr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$database->update('mail_lists', $data, ['listid' => $VARS['listid']]);
|
||||
}
|
||||
returnToSender("list_saved");
|
||||
case "deletelist":
|
||||
if ($database->has('mail_lists', ['listid' => $VARS['listid']])) {
|
||||
if ($database->get("mail_lists", 'uid', ['listid' => $VARS['listid']]) != $_SESSION['uid']) {
|
||||
returnToSender("no_permission");
|
||||
}
|
||||
$database->delete('addresses', ['listid' => $VARS['listid']]);
|
||||
$database->delete('mail_lists', ['listid' => $VARS['listid']]);
|
||||
returnToSender("list_deleted");
|
||||
}
|
||||
returnToSender("invalid_parameters");
|
||||
case "signout":
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
|
@ -76,5 +76,12 @@ define("STRINGS", [
|
||||
"anyone with link and password can view" => "When a password is set, anyone with the link and password can view the publication.",
|
||||
"enter password to view file" => "Enter password to view file",
|
||||
"view file" => "View File",
|
||||
"password incorrect" => "Password incorrect."
|
||||
"password incorrect" => "Password incorrect.",
|
||||
"invalid listid" => "Invalid list ID.",
|
||||
"list saved" => "Mailing list saved.",
|
||||
"list deleted" => "Mailing list deleted.",
|
||||
"adding list" => "Adding mailing list",
|
||||
"cloning list" => "Copying {olist} <i class=\"fa fa-angle-right\"></i> {nlist}",
|
||||
"editing list" => "Editing {list}",
|
||||
"addresses" => "Addresses"
|
||||
]);
|
@ -34,4 +34,16 @@ define("MESSAGES", [
|
||||
"string" => "no permission",
|
||||
"type" => "danger"
|
||||
],
|
||||
"invalid_listid" => [
|
||||
"string" => "invalid listid",
|
||||
"type" => "danger"
|
||||
],
|
||||
"list_saved" => [
|
||||
"string" => "list saved",
|
||||
"type" => "success"
|
||||
],
|
||||
"list_deleted" => [
|
||||
"string" => "list deleted",
|
||||
"type" => "success"
|
||||
],
|
||||
]);
|
||||
|
94
lib/getlisttable.php
Normal file
94
lib/getlisttable.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
require_once __DIR__ . '/../required.php';
|
||||
require_once __DIR__ . '/userinfo.php';
|
||||
|
||||
dieifnotloggedin();
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$out = [];
|
||||
|
||||
$out['draw'] = intval($VARS['draw']);
|
||||
|
||||
$out['recordsTotal'] = $database->count('mail_lists');
|
||||
|
||||
$filter = false;
|
||||
|
||||
// sort
|
||||
$order = null;
|
||||
$sortby = "DESC";
|
||||
if ($VARS['order'][0]['dir'] == 'asc') {
|
||||
$sortby = "ASC";
|
||||
}
|
||||
switch ($VARS['order'][0]['column']) {
|
||||
case 2:
|
||||
$order = ["listname" => $sortby];
|
||||
break;
|
||||
}
|
||||
|
||||
// search
|
||||
if (!is_empty($VARS['search']['value'])) {
|
||||
$filter = true;
|
||||
$wherenolimit = [];
|
||||
$wherenolimit["AND"]["OR"] = [
|
||||
"listname[~]" => $VARS['search']['value']
|
||||
];
|
||||
$where = $wherenolimit;
|
||||
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
||||
} else {
|
||||
$where = ["LIMIT" => [$VARS['start'], $VARS['length']]];
|
||||
}
|
||||
if (!is_null($order)) {
|
||||
$where["ORDER"] = $order;
|
||||
}
|
||||
|
||||
/*$where["OR #perms"] = [
|
||||
"uid" => $_SESSION['uid'],
|
||||
"permname #logg" => "LOGGEDIN",
|
||||
"permname #link" => "LINK"
|
||||
];*/
|
||||
|
||||
//var_dump($where);
|
||||
|
||||
$lists = $database->select('mail_lists',
|
||||
[
|
||||
'listid',
|
||||
'listname',
|
||||
'uid'
|
||||
], $where);
|
||||
|
||||
|
||||
$out['status'] = "OK";
|
||||
if ($filter) {
|
||||
$recordsFiltered = $database->count('mail_lists', $wherenolimit);
|
||||
} else {
|
||||
$recordsFiltered = $out['recordsTotal'];
|
||||
}
|
||||
$out['recordsFiltered'] = $recordsFiltered;
|
||||
|
||||
$usercache = [];
|
||||
for ($i = 0; $i < count($lists); $i++) {
|
||||
if ($lists[$i]["uid"] == $_SESSION['uid']) {
|
||||
$lists[$i]["editbtn"] = '<a class="btn btn-primary btn-xs" href="app.php?page=editlist&id=' . $lists[$i]['listid'] . '"><i class="fa fa-pencil-square-o"></i> ' . lang("edit", false) . '</a>';
|
||||
} else {
|
||||
$lists[$i]["editbtn"] = '<a class="btn btn-purple btn-xs" href="app.php?page=viewlist&id=' . $lists[$i]['listid'] . '"><i class="fa fa-eye"></i> ' . lang("view", false) . '</a>';
|
||||
}
|
||||
$lists[$i]["clonebtn"] = '<a class="btn btn-success btn-xs" href="app.php?page=editlist&id=' . $lists[$i]['listid'] . '&clone=1"><i class="fa fa-clone"></i> ' . lang("clone", false) . '</a>';
|
||||
if (is_null($lists[$i]['uid'])) {
|
||||
$lists[$i]["username"] = "";
|
||||
} else {
|
||||
if (!isset($usercache[$lists[$i]['uid']])) {
|
||||
$usercache[$lists[$i]['uid']] = getUserByID($lists[$i]['uid']);
|
||||
}
|
||||
$lists[$i]["username"] = $usercache[$lists[$i]['uid']]['name'];
|
||||
}
|
||||
}
|
||||
$out['lists'] = $lists;
|
||||
|
||||
echo json_encode($out);
|
@ -53,6 +53,13 @@ define("PAGES", [
|
||||
"static/js/maillist.js"
|
||||
],
|
||||
],
|
||||
"editlist" => [
|
||||
"title" => "edit list",
|
||||
"navbar" => false,
|
||||
"scripts" => [
|
||||
"static/js/editlist.js"
|
||||
],
|
||||
],
|
||||
"404" => [
|
||||
"title" => "404 error"
|
||||
]
|
||||
|
96
pages/editlist.php
Normal file
96
pages/editlist.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
$data = [
|
||||
'name' => '',
|
||||
'id' => ''
|
||||
];
|
||||
|
||||
$editing = false;
|
||||
$cloning = false;
|
||||
|
||||
if (!is_empty($VARS['id'])) {
|
||||
if ($database->has('mail_lists', ['listid' => $VARS['id']])) {
|
||||
$editing = true;
|
||||
if ($VARS['clone'] == 1) {
|
||||
$cloning = true;
|
||||
}
|
||||
$data = $database->select(
|
||||
'mail_lists', [
|
||||
'listid (id)',
|
||||
'listname (name)',
|
||||
'uid'
|
||||
], [
|
||||
'listid' => $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=editlist');
|
||||
die();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form role="form" action="action.php" method="POST">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">
|
||||
<?php
|
||||
if ($cloning) {
|
||||
?>
|
||||
<i class="fa fa-pencil-square-o"></i> <?php lang2("cloning list", ['olist' => htmlspecialchars($data['name']), 'nlist' => "<span id=\"name_title\">" . htmlspecialchars($data['name']) . "</span>"]); ?>
|
||||
<?php
|
||||
} else if ($editing) {
|
||||
?>
|
||||
<i class="fa fa-pencil-square-o"></i> <?php lang2("editing list", ['list' => "<span id=\"name_title\">" . htmlspecialchars($data['name']) . "</span>"]); ?>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<i class="fa fa-pencil-square-o"></i> <?php lang("adding list"); ?>
|
||||
<?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($data['name']); ?>" />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="listid" value="<?php
|
||||
if ($editing && !$cloning) {
|
||||
echo htmlspecialchars($VARS['id']);
|
||||
}
|
||||
?>" />
|
||||
|
||||
<?php if ($editing && $cloning) { ?>
|
||||
<input type="hidden" name="cloneid" value="<?php echo htmlspecialchars($VARS['id']); ?>" />
|
||||
<?php } ?>
|
||||
<input type="hidden" name="action" value="editlist" />
|
||||
<input type="hidden" name="source" value="maillist" />
|
||||
|
||||
<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=deletelist&source=maillist&listid=<?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>
|
@ -4,4 +4,31 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
?>
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
?>
|
||||
|
||||
<div class="btn-group mgn-btm-10px">
|
||||
<a href="app.php?page=editlist" class="btn btn-success"><i class="fa fa-plus"></i> <?php lang("new list"); ?></a>
|
||||
</div>
|
||||
<table id="listtable" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-priority="0"></th>
|
||||
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="2"><i class="fa fa-fw fa-envelope hidden-xs"></i> <?php lang('addresses'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th data-priority="0"></th>
|
||||
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="2"><i class="fa fa-fw fa-envelope hidden-xs"></i> <?php lang('addresses'); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
7
static/js/editlist.js
Normal file
7
static/js/editlist.js
Normal file
@ -0,0 +1,7 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
$('#name').on('input propertychange paste', function () {
|
||||
$('#name_title').text($('#name').val());
|
||||
});
|
@ -2,13 +2,13 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var pubtable = $('#pubtable').DataTable({
|
||||
var table = $('#listtable').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];
|
||||
return "<i class=\"fa fa-envelope fa-fw\"></i> " + data[2];
|
||||
}
|
||||
}),
|
||||
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
|
||||
@ -27,30 +27,22 @@ var pubtable = $('#pubtable').DataTable({
|
||||
targets: 1,
|
||||
orderable: false
|
||||
},
|
||||
{
|
||||
targets: 4,
|
||||
orderable: false
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[2, 'asc']
|
||||
[1, 'asc']
|
||||
],
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: "lib/getpubtable.php",
|
||||
url: "lib/getlisttable.php",
|
||||
dataFilter: function (data) {
|
||||
var json = jQuery.parseJSON(data);
|
||||
json.data = [];
|
||||
json.pubs.forEach(function (row) {
|
||||
json.lists.forEach(function (row) {
|
||||
json.data.push([
|
||||
"",
|
||||
row.editbtn + " " + row.clonebtn,
|
||||
row.pubname,
|
||||
row.pubdate,
|
||||
row.username,
|
||||
row.stylename,
|
||||
row.columns,
|
||||
row.permname
|
||||
row.listname,
|
||||
row.count
|
||||
]);
|
||||
});
|
||||
return JSON.stringify(json);
|
||||
|
Loading…
x
Reference in New Issue
Block a user