Permalink
Browse files

Move tabs from userhistory to user by using ajax (#356)

* move buttons from userhistory to user by using ajax

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

*  remove the history page from the test

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* test if email is listed on users page

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* remove ucfirst

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>
  • Loading branch information...
xh3n1 authored and michield committed Jun 30, 2018
1 parent 849a53f commit 3449a976df7a7809e1d4ec87db1e71896e7eb2f5
@@ -0,0 +1,54 @@
<?php
require_once dirname(__FILE__).'/../accesscheck.php';
if (!defined('PHPLISTINIT')) {
exit;
}
if (!$_GET['id']) {
Fatal_Error(s('no such User'));
return;
} else {
$id = sprintf('%d', $_GET['id']);
}
$status = "";
$result = Sql_query("SELECT * FROM {$GLOBALS['tables']['user']} where id = $id");
if (!Sql_Affected_Rows()) {
Fatal_Error(s('no such User'));
return;
}
$user = sql_fetch_array($result);
$bouncels = new WebblerListing(s('Bounces'));
$bouncels->setElementHeading('Bounce ID');
$bouncelist = '';
$bounces = array();
// check for bounces
$req = Sql_Query(sprintf('
select
message_bounce.id
, message_bounce.message
, time
, bounce
, date_format(time,"%%e %%b %%Y %%T") as ftime
from
%s as message_bounce
where
user = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));
if (Sql_Affected_Rows()) {
while ($row = Sql_Fetch_Array($req)) {
$messagedata = loadMessageData($row['message']);
$bouncels->addElement($row['bounce'],
PageURL2('bounce', s('view'), 'id=' . $row['bounce']));
$bouncels->addColumn($row['bounce'], s('Campaign title'), stripslashes($messagedata['campaigntitle']));
$bouncels->addColumn($row['bounce'], s('time'), $row['ftime']);
$bounces[$row['message']] = $row['ftime'];
}
echo $bouncels->display();
} else {
echo s("Bounces data not found");
}
@@ -0,0 +1,71 @@
<?php
require_once dirname(__FILE__).'/../accesscheck.php';
if (!defined('PHPLISTINIT')) {
exit;
}
if (!$_GET['id']) {
Fatal_Error(s('no such User'));
return;
} else {
$id = sprintf('%d', $_GET['id']);
}
$status = "";
$result = Sql_query("SELECT * FROM {$GLOBALS['tables']['user']} where id = $id");
if (!Sql_Affected_Rows()) {
Fatal_Error(s('no such User'));
return;
}
$user = sql_fetch_array($result);
$ls = new WebblerListing(s('Campaigns'));
if (Sql_Table_Exists($GLOBALS['tables']['usermessage'])) {
$msgs = Sql_Query(sprintf('select messageid,entered,viewed,(viewed = 0 or viewed is null) as notviewed,
abs(unix_timestamp(entered) - unix_timestamp(viewed)) as responsetime from %s where userid = %d and status = "sent" order by entered desc',
$GLOBALS['tables']['usermessage'], $user['id']));
$num = Sql_Affected_Rows();
} else {
$num = 0;
}
printf('%d '.s('messages sent to this user').'<br/>', $num);
if ($num) {
$resptime = 0;
$totalresp = 0;
$ls->setElementHeading(s('Campaign Id'));
while ($msg = Sql_Fetch_Array($msgs)) {
$ls->addElement($msg['messageid'],
PageURL2('message', s('view'), 'id='.$msg['messageid']));
if (defined('CLICKTRACK') && CLICKTRACK) {
$clicksreq = Sql_Fetch_Row_Query(sprintf('select sum(clicked) as numclicks from %s where userid = %s and messageid = %s',
$GLOBALS['tables']['linktrack_uml_click'], $user['id'], $msg['messageid']));
$clicks = sprintf('%d', $clicksreq[0]);
if ($clicks) {
$ls->addColumn($msg['messageid'], s('clicks'),
PageLink2('userclicks&amp;userid='.$user['id'].'&amp;msgid='.$msg['messageid'], $clicks));
} else {
$ls->addColumn($msg['messageid'], s('clicks'), 0);
}
}
$ls->addColumn($msg['messageid'], s('sent'), formatDateTime($msg['entered'], 1));
if (!$msg['notviewed']) {
$ls->addColumn($msg['messageid'], s('viewed'), formatDateTime($msg['viewed'], 1));
$ls->addColumn($msg['messageid'], s('Response time'), secs2time($msg['responsetime']));
$resptime += $msg['responsetime'];
$totalresp += 1;
}
if (!empty($bounces[$msg['messageid']])) {
$ls->addColumn($msg['messageid'], s('bounce'), $bounces[$msg['messageid']]);
}
}
if ($totalresp) {
$avgresp = sprintf('%d', ($resptime / $totalresp));
$ls->addElement('<strong>'.s('Average response time: ').'</strong>'.secs2time($avgresp));
}
}
echo $ls->display();
@@ -0,0 +1,120 @@
<?php
require_once dirname(__FILE__).'/../accesscheck.php';
if (!defined('PHPLISTINIT')) {
exit;
}
if (!$_GET['id']) {
Fatal_Error(s('no such User'));
return;
} else {
$id = sprintf('%d', $_GET['id']);
}
$status = '';
$access = accessLevel('user');
switch ($access) {
case 'owner':
$subselect = ' and '.$GLOBALS['tables']['list'].'.owner = '.$_SESSION['logindetails']['id'];
break;
case 'all':
$subselect = '';
break;
case 'view':
$subselect = '';
if (count($_POST) || $_GET['unblacklist']) {
echo Error(s('you only have privileges to view this page, not change any of the information'));
return;
}
break;
case 'none':
default:
$subselect = ' and '.$GLOBALS['tables']['list'].'.id = 0';
break;
}
$result = Sql_query("SELECT * FROM {$GLOBALS['tables']['user']} where id = $id");
if (!Sql_Affected_Rows()) {
Fatal_Error(s('no such User'));
return;
}
$user = sql_fetch_array($result);
if (isBlackListed($user['email'])) {
echo '<h3>'.s('subscriber is blacklisted since').' ';
$blacklist_info = Sql_Fetch_Array_Query(sprintf('select * from %s where email = "%s"',
$GLOBALS['tables']['user_blacklist'], $user['email']));
echo formatDateTime($blacklist_info['added']).'</h3><br/>';
echo '';
$isSpamReport = false;
$ls = new WebblerListing(s('Blacklist info'));
$req = Sql_Query(sprintf('select * from %s where email = "%s"',
$GLOBALS['tables']['user_blacklist_data'], $user['email']));
while ($row = Sql_Fetch_Array($req)) {
$ls->addElement(s($row['name']));
$isSpamReport = $isSpamReport || $row['data'] == 'blacklisted due to spam complaints';
$ls->addColumn(s($row['name']), s('value'), stripslashes($row['data']));
}
$ls->addElement('<!-- remove -->');
if (!$isSpamReport) {
$button = new ConfirmButton(
htmlspecialchars(s('are you sure you want to delete this subscriber from the blacklist')).'?\\n'.htmlspecialchars(s('it should only be done with explicit permission from this subscriber')),
PageURL2("user&unblacklist={$user['id']}&id={$user['id']}", 'button',
s('remove subscriber from blacklist')),
s('remove subscriber from blacklist'));
$ls->addRow('<!-- remove -->', s('remove'), $button->show());
} else {
$ls->addRow('<!-- remove -->', s('remove'),
s('For this subscriber to be removed from the blacklist, you need to ask them to re-subscribe using the phpList subscribe page'));
}
echo $ls->display();
}
$ls = new WebblerListing(s('Subscription History'));
$ls->setElementHeading(s('Event'));
$req = Sql_Query(sprintf('select * from %s where userid = %d order by id desc', $GLOBALS['tables']['user_history'], $user['id']));
if (!Sql_Affected_Rows()) {
echo s('no details found');
}
while ($row = Sql_Fetch_Array($req)) {
$ls->addElement($row['id']);
$ls->setClass($row['id'], 'row1');
$ls->addColumn($row['id'], s('ip'), $row['ip']);
$ls->addColumn($row['id'], s('date'), formatDateTime($row['date']));
$ls->addColumn($row['id'], s('summary'), $row['summary']);
$ls->addRow(
$row['id']
, "<div class='gray'><strong>".s('detail').'</strong></div>'
, "<div class='tleft'>".
nl2br(
htmlspecialchars(
$row['detail']
)
).'</div>'
);
// nl2br inserts leading <br/> elements and unnecessary whitespace; preg_replace removes this
$ls->addRow(
$row['id']
, "<div class='gray'><strong>".s('info').'</strong></div>'
, "<div class='tleft'>".
preg_replace(
"|^(?:<br />[\n\r]+)*(.*?)(?:<br />[\n\r]+)*$|s"
, '$1'
, nl2br(
htmlspecialchars_decode(
$row['systeminfo']
)
)
).'</div>'
);
}
echo $ls->display();
@@ -637,7 +637,6 @@ function pageTitle($page)
'suppressionlist',
'reconcileusers',
'usercheck',
'userhistory',
'user',
'adduser',
'attributes',
@@ -1101,18 +1101,10 @@ class confirmButton extends button
public function __construct($confirmationtext, $link, $linktext, $title = '', $class = 'confirm')
{
if (!isset($GLOBALS['confirmButtonCount'])) {
$GLOBALS['confirmButtonCount'] = 0;
}
++$GLOBALS['confirmButtonCount'];
$this->linkhtml = ' class="'.$class.'" id="confirm'.$GLOBALS['confirmButtonCount'].'"';
$this->link = '#';
$onclickevent = 'return confirm(\''.htmlspecialchars(strip_tags($confirmationtext)).'\')';
$this->linkhtml = ' class="'.$class.'" onclick="'.$onclickevent.'"';
$this->link = $link;
$this->linktext = $linktext;
$GLOBALS['pagefooter']['confirmbutton'.$GLOBALS['confirmButtonCount']] = '
<script type="text/javascript">
$("#confirm' .$GLOBALS['confirmButtonCount'].'").click(function(){ if (confirm("'.htmlspecialchars(strip_tags($confirmationtext)).'")){window.location="'.$link.'"};});
</script>';
$this->title = $title;
}
}
@@ -106,7 +106,7 @@
$ls->addElement($row['userid'], PageUrl2('user&amp;id='.$row['userid']));
$ls->addColumn($row['userid'], s('Subscriber address'), PageLink2('user&id='.$row['userid'], $userdata['email']));
$ls->addColumn($row['userid'], s('Total bounces'),
PageLink2('userhistory&id='.$row['userid'], $row['numbounces']));
PageLink2('user&id='.$row['userid'], $row['numbounces']));
}
}
}
@@ -212,7 +212,7 @@
$element = shortenTextDisplay($row['email'], 35);
$separator = '<br/>';
}
$ls->addElement($element, PageUrl2('userhistory&amp;id='.$row['userid']));
$ls->addElement($element, PageUrl2('user&amp;id='.$row['userid']));
$ls->addColumn($element, s('Sent'), formatDateTime($row['sent'], 1));
$ls->addColumn($element, s('Response time'), secs2time($row['responsetime']));
@@ -326,7 +326,6 @@
}
echo '<div class="actions">';
echo PageLinkButton("userhistory&amp;id=$id", s('History'));
echo PageLinkButton("exportuserdata&amp;id=$id", s('Download subscriber data'));
if (!isBlackListed($user['email'])) {
echo
@@ -534,8 +533,11 @@ class="confirm btn btn-default"
echo '<div class="tabbed">';
echo '<ul>';
echo '<li><a href="#details">'.ucfirst(s('Details')).'</a></li>';
echo '<li><a href="#lists">'.ucfirst(s('Lists')).'</a></li>';
echo '<li><a href="#details">'.s('Details').'</a></li>';
echo '<li><a href="#lists">'.s('Lists').'</a></li>';
echo '<li><a href="./?page=pageaction&action=campaigns&ajaxed=true&id='.$id .addCsrfGetToken().'">'.s('Campaigns').'</a></li>';
echo '<li><a href="./?page=pageaction&action=bounces&ajaxed=true&id='.$id .addCsrfGetToken().'">'.s('Bounces').'</a></li>';
echo '<li><a href="./?page=pageaction&action=subscription&ajaxed=true&id='.$id .addCsrfGetToken().'">'.s('Subscription').'</a></li>';
echo '</ul>';
@@ -547,4 +549,10 @@ class="confirm btn btn-default"
echo '</div>'; //# end of tabbed
if (isset($_GET['unblacklist'])) {
$unblacklist = sprintf('%d', $_GET['unblacklist']);
unBlackList($unblacklist);
Redirect('user&id='.$unblacklist);
}
echo '</form>';
@@ -210,7 +210,7 @@
} else {
if (!$userid) {
$element = shortenTextDisplay($row['email']);
$ls->addElement($element, PageUrl2('userhistory&amp;id='.$row['userid']));
$ls->addElement($element, PageUrl2('user&amp;id='.$row['userid']));
$ls->setClass($element, 'row1');
} else {
// $link = substr($row['url'],0,50);
Oops, something went wrong.

0 comments on commit 3449a97

Please sign in to comment.