diff --git a/public_html/lists/admin/spageedit.php b/public_html/lists/admin/spageedit.php
index e1f569790..12a74a1e8 100644
--- a/public_html/lists/admin/spageedit.php
+++ b/public_html/lists/admin/spageedit.php
@@ -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) {
@@ -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();
@@ -382,10 +394,26 @@
}
}
$listsHTML .= '
';
+$preselectList = (int) $data['preselectlist'];
+if (!in_array($preselectList, $selected_lists)) {
+ $preselectList = 0;
+}
+$listsHTML .= sprintf('',
+ empty($preselectList) ? 'checked="checked"' : '',
+ s('Do not preselect any list'));
while ($row = Sql_Fetch_Array($req)) {
- $listsHTML .= sprintf('%s
',
- $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(
+ ' %s
',
+ $row['id'],
+ $row['id'],
+ $listSelected ? 'checked="checked"' : '',
+ stripslashes($row['name']),
+ $row['id'],
+ $preselectList == $row['id'] ? 'checked="checked"' : '',
+ s('Preselect'),
+ htmlspecialchars(stripslashes($row['description']))
+ );
}
$listsHTML .= '';
diff --git a/public_html/lists/admin/subscribelib2.php b/public_html/lists/admin/subscribelib2.php
index cc014e97a..eb5b6a16a 100644
--- a/public_html/lists/admin/subscribelib2.php
+++ b/public_html/lists/admin/subscribelib2.php
@@ -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'])) {
@@ -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();
@@ -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,
+ );
}
@@ -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"';
}
@@ -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 .= " /> ';
$desc = nl2br(disableJavascript(stripslashes($row['description'])));
diff --git a/public_html/lists/index.php b/public_html/lists/index.php
index db494c541..81b52186e 100644
--- a/public_html/lists/index.php
+++ b/public_html/lists/index.php
@@ -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'];
}
@@ -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'];
@@ -799,7 +807,11 @@ function subscribePage2($id)
$html .= formStart();
$html .= '