diff --git a/action.php b/action.php index 073592f..4ea6148 100644 --- a/action.php +++ b/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'); diff --git a/lang/en_us.php b/lang/en_us.php index 5298cfb..af68f1f 100644 --- a/lang/en_us.php +++ b/lang/en_us.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} {nlist}", + "editing list" => "Editing {list}", + "addresses" => "Addresses" ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 04ecb73..0cd4edc 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -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" + ], ]); diff --git a/lib/getlisttable.php b/lib/getlisttable.php new file mode 100644 index 0000000..f3fcea2 --- /dev/null +++ b/lib/getlisttable.php @@ -0,0 +1,94 @@ +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"] = ' ' . lang("edit", false) . ''; + } else { + $lists[$i]["editbtn"] = ' ' . lang("view", false) . ''; + } + $lists[$i]["clonebtn"] = ' ' . lang("clone", false) . ''; + 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); diff --git a/pages.php b/pages.php index 41d1324..c9bfc44 100644 --- a/pages.php +++ b/pages.php @@ -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" ] diff --git a/pages/editlist.php b/pages/editlist.php new file mode 100644 index 0000000..fc8f536 --- /dev/null +++ b/pages/editlist.php @@ -0,0 +1,96 @@ + '', + '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(); + } +} +?> + +
\ No newline at end of file diff --git a/pages/maillist.php b/pages/maillist.php index dca4afe..5784385 100644 --- a/pages/maillist.php +++ b/pages/maillist.php @@ -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/. */ -?> \ No newline at end of file +require_once __DIR__ . '/../required.php'; + +redirectifnotloggedin(); +?> + + ++ | + | + | + |
---|---|---|---|
+ | + | + | + |