Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions public_html/lists/admin/spageedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,21 @@
}
Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"attributes","%s")',
$tables['subscribepage_data'], $id, $attributes));
$preselectList = 0;
if (!empty($_POST['preselectlist'])) {
$preselectList = (int) $_POST['preselectlist'];
}
if (isset($_POST['list']) && is_array($_POST['list'])) {
if (!$preselectList || !isset($_POST['list'][$preselectList])) {
$preselectList = 0;
}
Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"lists","%s")',
$tables['subscribepage_data'], $id, implode(',', $_POST['list'])));
} else {
$preselectList = 0;
}
Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"preselectlist","%d")',
$tables['subscribepage_data'], $id, $preselectList));

//## Store plugin data
foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
Expand Down Expand Up @@ -144,6 +155,7 @@
$data['unsubscribesubject'] = getConfig('unsubscribesubject');
$data['htmlchoice'] = 'htmlonly';
$data['emaildoubleentry'] = 'yes';
$data['preselectlist'] = 0;
$data['rssdefault'] = 'daily'; //Leftover from the preplugin era
$data['rssintro'] = s('Please indicate how often you want to receive messages'); //Leftover from the preplugin era
$selected_lists = array();
Expand Down Expand Up @@ -382,10 +394,26 @@
}
}
$listsHTML .= '</p>';
$preselectList = (int) $data['preselectlist'];
if (!in_array($preselectList, $selected_lists)) {
$preselectList = 0;
}
$listsHTML .= sprintf('<p><label><input type="radio" name="preselectlist" value="0" %s /> %s</label></p>',
empty($preselectList) ? 'checked="checked"' : '',
s('Do not preselect any list'));
while ($row = Sql_Fetch_Array($req)) {
$listsHTML .= sprintf('<label><input type="checkbox" name="list[%d]" value="%d" %s /> %s</label><div>%s</div>',
$row['id'], $row['id'], in_array($row['id'], $selected_lists) ? 'checked="checked"' : '',
stripslashes($row['name']), htmlspecialchars(stripslashes($row['description'])));
$listSelected = in_array($row['id'], $selected_lists);
$listsHTML .= sprintf(
'<label><input type="checkbox" name="list[%d]" value="%d" %s /> %s</label> <label><input type="radio" name="preselectlist" value="%d" %s /> %s</label><div>%s</div>',
$row['id'],
$row['id'],
$listSelected ? 'checked="checked"' : '',
stripslashes($row['name']),
$row['id'],
$preselectList == $row['id'] ? 'checked="checked"' : '',
s('Preselect'),
htmlspecialchars(stripslashes($row['description']))
);
}

$listsHTML .= '</div>';
Expand Down
47 changes: 45 additions & 2 deletions public_html/lists/admin/subscribelib2.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,31 @@
}
}

/**
* Determine whether a list checkbox should be preselected.
*
* @param bool $hasExplicitListSelection
* @param int $preselect_list_id
* @param int $listId
* @param mixed $rowPreselect
* @return bool
*/
function shouldPreselectList($hasExplicitListSelection, $preselect_list_id, $listId, $rowPreselect)
{
return !$hasExplicitListSelection &&
(
($preselect_list_id && $preselect_list_id == $listId) ||
(!$preselect_list_id && !empty($rowPreselect))
);
}

/**
* @param int $userid
* @param string $lists_to_show
* @param int $preselect_list_id
* @return string
*/
function ListAvailableLists($userid = 0, $lists_to_show = '')
function ListAvailableLists($userid = 0, $lists_to_show = '', $preselect_list_id = 0)
{
global $tables;
if (isset($_POST['list'])) {
Expand All @@ -730,6 +749,9 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
} else {
$list = '';
}
$hasExplicitListSelection = isset($_POST['list'])
|| (!isset($_POST['subscribe']) && isset($_GET['list']) && preg_match("/^(\d+,)*\d+$/", $_GET['list']));
$preselect_list_id = (int) $preselect_list_id;
$subselect = '';
$listset = array();
$subscribed = array();
Expand Down Expand Up @@ -766,7 +788,14 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')

while ($row = Sql_fetch_array($catresult)) {

$listspercategory[] = array('id' => $row ['id'], 'name' => $row ['name'], 'description' => $row ['description'], 'active' => $row ['active'], 'category' => $row ['category']);
$listspercategory[] = array(
'id' => $row['id'],
'name' => $row['name'],
'description' => $row['description'],
'active' => $row['active'],
'category' => $row['category'],
'preselect' => isset($row['preselect']) ? $row['preselect'] : 0,
);

}

Expand Down Expand Up @@ -803,6 +832,13 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
} elseif (shouldPreselectList(
$hasExplicitListSelection,
$preselect_list_id,
$listelement['id'],
$listelement['preselect']
)) {
$html .= 'checked="checked"';
}


Expand Down Expand Up @@ -844,6 +880,13 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
} elseif (shouldPreselectList(
$hasExplicitListSelection,
$preselect_list_id,
$row['id'],
isset($row['preselect']) ? $row['preselect'] : 0
)) {
$html .= 'checked="checked"';
}
$html .= " /> <label for=\"list$row[id]\"><b>".stripslashes($row['name']).'</b></label><div class="listdescription">';
$desc = nl2br(disableJavascript(stripslashes($row['description'])));
Expand Down
18 changes: 15 additions & 3 deletions public_html/lists/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ function checkEmail()
}
}

$html .= ListAvailableLists($userid, $GLOBALS['pagedata']['lists']);
$html .= ListAvailableLists(
$userid,
$GLOBALS['pagedata']['lists'],
isset($GLOBALS['pagedata']['preselectlist']) ? (int) $GLOBALS['pagedata']['preselectlist'] : 0
);
if (isBlackListedID($userid)) {
$html .= $GLOBALS['strYouAreBlacklisted'];
}
Expand Down Expand Up @@ -690,7 +694,11 @@ function checkGroup(name,value)
$html .= $plugin->displaySubscriptionChoice($GLOBALS['pagedata']);
}
}
$html .= ListAvailableLists('', $GLOBALS['pagedata']['lists']);
$html .= ListAvailableLists(
'',
$GLOBALS['pagedata']['lists'],
isset($GLOBALS['pagedata']['preselectlist']) ? (int) $GLOBALS['pagedata']['preselectlist'] : 0
);

if (empty($GLOBALS['pagedata']['button'])) {
$GLOBALS['pagedata']['button'] = $GLOBALS['strSubmit'];
Expand Down Expand Up @@ -799,7 +807,11 @@ function subscribePage2($id)
$html .= formStart();
$html .= '<fieldset class="phplist"><legend>'.strip_tags($GLOBALS['pagedata']['intro']).'</legend>';
$html .= ListAttributes2011($attributes,$attributedata,$GLOBALS['pagedata']["htmlchoice"],0,$GLOBALS['pagedata']['emaildoubleentry']);
$html .= ListAvailableLists("",$GLOBALS['pagedata']["lists"]);
$html .= ListAvailableLists(
"",
$GLOBALS['pagedata']["lists"],
isset($GLOBALS['pagedata']['preselectlist']) ? (int) $GLOBALS['pagedata']['preselectlist'] : 0
);

if (empty($GLOBALS['pagedata']['button'])) {
$GLOBALS['pagedata']['button'] = $GLOBALS['strSubmit'];
Expand Down
Loading