Skip to content

Commit

Permalink
Group lists by category feature (#426)
Browse files Browse the repository at this point in the history
* working on subscribe page

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

* subselect

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

* Fix accordion

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

* changes

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

* Refactor and fixed

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

* remove echo

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

* change not categorized to other

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

* add radio input to choose how to display lists

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

* show lists only

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

* split lists in two columns

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

* remove unnecessary lines

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

* Put default categorisation option first; Improve categorisation option wording; Add label to lists sub-section

* assign description value to description field

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

* dont display category with empty content

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

* Add default setting on configuration page

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

* add expanded all class

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>
  • Loading branch information
xh3n1 authored and Sam Tuke committed Oct 31, 2018
1 parent 05abad5 commit 62f3704
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 24 deletions.
8 changes: 8 additions & 0 deletions public_html/lists/admin/defaultconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
'category' => 'list-organisation',
),

'displaycategories' => array(
'value' => 0,
'description' => s('Display list categories on subscribe page'),
'type' => 'boolean',
'allowempty' => false,
'category' => 'list-organisation',
),

// width of a textline field
'textline_width' => array(
'value' => '40',
Expand Down
20 changes: 18 additions & 2 deletions public_html/lists/admin/spageedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
$id = Sql_Insert_id();
}
Sql_Query(sprintf('delete from %s where id = %d', $tables['subscribepage_data'], $id));

foreach (array(
'title',
'language_file',
Expand All @@ -58,6 +59,7 @@
'button',
'htmlchoice',
'emaildoubleentry',
'showcategories',
'ajax_subscribeconfirmation',
) as $item) {
Sql_Query(sprintf('insert into %s (name,id,data) values("%s",%d,"%s")',
Expand Down Expand Up @@ -146,6 +148,11 @@
$data['rssintro'] = s('Please indicate how often you want to receive messages'); //Leftover from the preplugin era
$selected_lists = array();
$attributedata = array();
if(getConfig('displaycategories')==0) {
$data['showcategories'] = 'no';
}else {
$data['showcategories'] = 'yes';
}

if ($id) {
//# Fill values from database
Expand Down Expand Up @@ -349,11 +356,20 @@

$listsHTML = '<h3><a name="lists">'.s('Select the lists to offer').'</a></h3>';
$listsHTML .= '<div>';
$listsHTML .= '<p>'.s('You can only select "public" lists for subscribe pages.');
$listsHTML .= sprintf('<label for="listcategories">%s</label><br/>',
s('Display list categories'));
$listsHTML .= sprintf('<input type="radio" name="showcategories" value="no" %s />%s<br/>',
$data['showcategories'] === 'no' ? 'checked="checked"' : '',
s('Do not show list categories'));
$listsHTML .= sprintf('<input type="radio" name="showcategories" value="yes" %s />%s<br/>',
$data['showcategories'] === 'yes' ? 'checked="checked"' : '',
s('Display lists in labelled categories'));
$listsHTML .= '<p><label>'.s('Lists').'</label><br/>'.s('You can only select "public" lists for subscribe pages.');
$req = Sql_query("SELECT * FROM {$tables['list']} $subselect order by listorder");
if (!Sql_Affected_Rows()) {
$listsHTML .= '<br/>'.s('No lists available, please create one first');
} else {

$listsHTML .= '<br/>'.s('If you do not choose a list here, all public lists will be displayed.');
$hideSingle = getConfig('hide_single_list');
if ($hideSingle) {
Expand Down Expand Up @@ -407,4 +423,4 @@
echo '
<input class="submit" type="submit" name="save" value="' .s('Save Changes').'" />
</form>';
</form>';
133 changes: 111 additions & 22 deletions public_html/lists/admin/subscribelib2.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
}
}

// check if the lists should be displayed by category
if (isset($subscribepagedata['showcategories']) && $subscribepagedata['showcategories'] == 'yes') {
$GLOBALS['showCat'] = true;
}

// anti spambot check
if (!empty($_POST['VerificationCodeX'])) {
if (NOTIFY_SPAM) {
Expand Down Expand Up @@ -701,6 +706,11 @@
// $msg = 'Unknown Error';
}

/**
* @param int $userid
* @param string $lists_to_show
* @return string
*/
function ListAvailableLists($userid = 0, $lists_to_show = '')
{
global $tables;
Expand All @@ -723,6 +733,7 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
$showlists = array_unique(array_merge($showlists, $subscribed));
}


foreach ($showlists as $listid) {
if (preg_match("/^\d+$/", $listid)) {
array_push($listset, $listid);
Expand All @@ -733,34 +744,112 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
}

$some = 0;
$html = '<ul class="list">';
$result = Sql_query("SELECT * FROM {$GLOBALS['tables']['list']} $subselect order by listorder, name");
while ($row = Sql_fetch_array($result)) {
if ($row['active'] || in_array($row['id'], $subscribed)) {
// id required for label
$html .= '<li class="list"><input type="checkbox" name="list[' . $row['id'] . ']" id="list'.$row['id'].'" value="signup" ';
if (isset($list[$row['id']]) && $list[$row['id']] == 'signup') {
$html .= 'checked="checked"';


if (isset($GLOBALS['showCat'])&& $GLOBALS['showCat']===true){
$listspercategory = array();
$categories = array();
$catresult = Sql_query(sprintf('select * from %s %s order by category',
$GLOBALS['tables']['list'], $subselect));


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

$listspercategory[] = array('id' => $row ['id'], 'name' => $row ['name'], 'description' => $row ['description'], 'active' => $row ['active'], 'category' => $row ['category']);

}

foreach ($listspercategory as $key => $value) {

if($value['active']) {
$categories[] = $value['category'];
}
if ($userid) {
$req = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and listid = %d',
$GLOBALS['tables']['listuser'], $userid, $row['id']));
if (Sql_Affected_Rows()) {
}
$uniqueCat = array_unique($categories);

$html = '<div class="accordion allexpanded" >';
foreach ($uniqueCat as $key) {

if ($key !== '') {
$displayedCat = $key;
} else $displayedCat = s('General');

$html .= '<h3 ><a name="general" >' . $displayedCat . '</a></h3>';
$html .= '<div>';
$html .= '<ul class="list" id="listcategory">';
$count = 0;
foreach ($listspercategory as $listelement)
if ($listelement['category'] === $key) {
if ($listelement['active'] || in_array($listelement['id'], $subscribed) ) {

$html .= '<li ><input type="checkbox" name="list[' . $listelement['id'] . ']" value="signup" ';
if (isset($list[$listelement['id']]) && $list[$listelement['id']] === 'signup') {
$html .= 'checked="checked"';
}
if ($userid) {
$req = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and listid = %d',
$GLOBALS['tables']['listuser'], $userid, $listelement['id']));
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
}


$html .= ' /><b>' . stripslashes($listelement['name']) . '</b><div class="listdescription">';
$desc = nl2br(stripslashes($listelement['description']));
// $html .= '<input type="hidden" name="listname['.$row["id"] . ']" value="'.htmlspecialchars(stripslashes($row["name"])).'"/>';
$html .= $desc . '</div></li>';
++$some;
if ($some == 1) {
$singlelisthtml = sprintf('<input type="hidden" name="list[%d]" value="signup" />', $listelement['id']);
$singlelisthtml .= '<input type="hidden" name="listname[' . $listelement['id'] . ']" value="' . htmlspecialchars(stripslashes($listelement['name'])) . '"/>';
}

}

} $html .= '</ul>';

$html .= '</div>';
}

// end of row active

$html .= '</div>';

} else {

$html = '<ul class="list">';
$result = Sql_query("SELECT * FROM {$GLOBALS['tables']['list']} $subselect order by listorder, name");
while ($row = Sql_fetch_array($result)) {
if ($row['active'] || in_array($row['id'], $subscribed)) {
// id required for label
$html .= '<li class="list"><input type="checkbox" name="list[' . $row['id'] . ']" id="list'.$row['id'].'" value="signup" ';
if (isset($list[$row['id']]) && $list[$row['id']] == 'signup') {
$html .= 'checked="checked"';
}
}
$html .= " /> <label for=\"list$row[id]\"><b>".stripslashes($row['name']).'</b></label><div class="listdescription">';
$desc = nl2br(stripslashes($row['description']));
// $html .= '<input type="hidden" name="listname['.$row["id"] . ']" value="'.htmlspecialchars(stripslashes($row["name"])).'"/>';
$html .= $desc.'</div></li>';
++$some;
if ($some == 1) {
$singlelisthtml = sprintf('<input type="hidden" name="list[%d]" value="signup" />', $row['id']);
$singlelisthtml .= '<input type="hidden" name="listname['.$row['id'].']" value="'.htmlspecialchars(stripslashes($row['name'])).'"/>';
if ($userid) {
$req = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and listid = %d',
$GLOBALS['tables']['listuser'], $userid, $row['id']));
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
}
$html .= " /> <label for=\"list$row[id]\"><b>".stripslashes($row['name']).'</b></label><div class="listdescription">';
$desc = nl2br(stripslashes($row['description']));
// $html .= '<input type="hidden" name="listname['.$row["id"] . ']" value="'.htmlspecialchars(stripslashes($row["name"])).'"/>';
$html .= $desc.'</div></li>';
++$some;
if ($some == 1) {
$singlelisthtml = sprintf('<input type="hidden" name="list[%d]" value="signup" />', $row['id']);
$singlelisthtml .= '<input type="hidden" name="listname['.$row['id'].']" value="'.htmlspecialchars(stripslashes($row['name'])).'"/>';
}

}
}
$html .= '</ul>';

}
$html .= '</ul>';

$hidesinglelist = getConfig('hide_single_list');
if (!$some) {
global $strNotAvailable;
Expand Down

0 comments on commit 62f3704

Please sign in to comment.