Add full email list functionality
This commit is contained in:
parent
d11bd67645
commit
7591b5e709
29
action.php
29
action.php
@ -190,17 +190,28 @@ switch ($VARS['action']) {
|
||||
$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']]);
|
||||
$listid = $VARS['listid'];
|
||||
}
|
||||
|
||||
$emails = explode(",", $VARS['emails']);
|
||||
$dbemails = $database->select('addresses', 'email', ['listid' => $listid]);
|
||||
$todelete = $dbemails;
|
||||
$toadd = [];
|
||||
foreach ($emails as $m) {
|
||||
if (!in_array($m, $dbemails)) {
|
||||
$toadd[] = $m;
|
||||
}
|
||||
|
||||
$todelete = array_diff($todelete, [$m]);
|
||||
}
|
||||
|
||||
foreach ($todelete as $m) {
|
||||
$database->delete('addresses', ["AND" => ['listid' => $listid, "email" => $m]]);
|
||||
}
|
||||
foreach ($toadd as $m) {
|
||||
$database->insert('addresses', ['listid' => $listid, 'email' => $m, 'name' => '']);
|
||||
}
|
||||
returnToSender("list_saved");
|
||||
case "deletelist":
|
||||
|
@ -86,4 +86,5 @@ define("STRINGS", [
|
||||
"addresses" => "Addresses",
|
||||
"theme" => "Theme",
|
||||
"format" => "Format",
|
||||
"addresses comma separated" => "Addresses (comma separated)"
|
||||
]);
|
@ -88,6 +88,7 @@ for ($i = 0; $i < count($lists); $i++) {
|
||||
}
|
||||
$lists[$i]["username"] = $usercache[$lists[$i]['uid']]['name'];
|
||||
}
|
||||
$lists[$i]['count'] = $database->count('addresses', ['listid' => $lists[$i]["listid"]]);
|
||||
}
|
||||
$out['lists'] = $lists;
|
||||
|
||||
|
@ -59,7 +59,11 @@ define("PAGES", [
|
||||
"editlist" => [
|
||||
"title" => "edit list",
|
||||
"navbar" => false,
|
||||
"styles" => [
|
||||
"static/css/tagsinput.css"
|
||||
],
|
||||
"scripts" => [
|
||||
"static/js/jquery.tagsinput.min.js",
|
||||
"static/js/editlist.js"
|
||||
],
|
||||
],
|
||||
|
@ -12,6 +12,7 @@ $data = [
|
||||
'name' => '',
|
||||
'id' => ''
|
||||
];
|
||||
$emails = [];
|
||||
|
||||
$editing = false;
|
||||
$cloning = false;
|
||||
@ -30,6 +31,7 @@ if (!is_empty($VARS['id'])) {
|
||||
], [
|
||||
'listid' => $VARS['id']
|
||||
])[0];
|
||||
$emails = $database->select('addresses', 'email', ['listid' => $VARS['id']]);
|
||||
} else {
|
||||
// item id is invalid, redirect to a page that won't cause an error when pressing Save
|
||||
header('Location: app.php?page=editlist');
|
||||
@ -63,8 +65,13 @@ if (!is_empty($VARS['id'])) {
|
||||
<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">
|
||||
|
||||
<label for="emails"><i class="far fa-envelope"></i> <?php lang("addresses comma separated"); ?></label>
|
||||
<div class="card">
|
||||
<input class="form-control" name="emails" id="emails" type="text" value="<?php
|
||||
foreach ($emails as $m) {
|
||||
echo "$m,";
|
||||
}
|
||||
?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -74,9 +81,6 @@ if (!is_empty($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" />
|
||||
|
||||
|
61
static/css/tagsinput.css
Normal file
61
static/css/tagsinput.css
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* From https://github.com/xoxco/jQuery-Tags-Input
|
||||
* MIT License
|
||||
*/
|
||||
div.tagsinput {
|
||||
padding: 5px;
|
||||
padding-top: 10px;
|
||||
padding-left: 10px;
|
||||
width: 300px;
|
||||
height: 100px;
|
||||
overflow-y: auto;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
div.tagsinput span.tag {
|
||||
border: 1px solid #a5d24a;
|
||||
display: block;
|
||||
border-radius: 2px;
|
||||
float: left;
|
||||
padding: 5px;
|
||||
text-decoration: none;
|
||||
background-color: #4CAF50;
|
||||
color: #fff;
|
||||
margin-right: 8px;
|
||||
margin-bottom: 8px;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.4);
|
||||
line-height: 1.5;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
div.tagsinput span.tag a {
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
padding-right: 3px;
|
||||
}
|
||||
|
||||
div.tagsinput input {
|
||||
width: 100%;
|
||||
margin: 0px;
|
||||
border: 1px solid transparent;
|
||||
padding: 5px;
|
||||
background: transparent;
|
||||
color: #000;
|
||||
outline: 0px;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
div.tagsinput div {
|
||||
display: block;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.tags_clear {
|
||||
clear: both;
|
||||
width: 100%;
|
||||
height: 0px;
|
||||
}
|
@ -4,4 +4,20 @@
|
||||
|
||||
$('#name').on('input propertychange paste', function () {
|
||||
$('#name_title').text($('#name').val());
|
||||
});
|
||||
|
||||
$("#emails").tagsInput({
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
defaultText: "Click to add",
|
||||
onAddTag: function (tag) {
|
||||
if (!
|
||||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(tag)) {
|
||||
$("#emails").removeTag(tag);
|
||||
alert(tag + " does not appear to be a valid email address.");
|
||||
} else if (tag.length > 255) {
|
||||
$("#emails").removeTag(tag);
|
||||
alert(tag + " is too long. Email addresses must be less than 256 characters in length.");
|
||||
}
|
||||
}
|
||||
});
|
1
static/js/jquery.tagsinput.min.js
vendored
Normal file
1
static/js/jquery.tagsinput.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user