PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/lists/admin/list.php

https://github.com/samtuke/phplist
PHP | 277 lines | 186 code | 33 blank | 58 comment | 43 complexity | cd389c24d68a40037d7765ed3ccd6578 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. require_once dirname(__FILE__).'/accesscheck.php';
  3. print formStart('class="listListing"');
  4. $some = 0;
  5. if (isset($_GET['s'])) {
  6. $s = sprintf('%d',$_GET['s']);
  7. } else {
  8. $s = 0;
  9. }
  10. $baseurl = './?page=list';
  11. $actionresult = '';
  12. if (isset($_POST['listorder']) && is_array($_POST['listorder']))
  13. while (list($key,$val) = each ($_POST['listorder'])) {
  14. $active = empty($_POST['active'][$key]) ? '0' : '1';
  15. $active = $active || listUsedInSubscribePage($key);
  16. $query
  17. = ' update %s'
  18. . ' set listorder = ?, active = ?'
  19. . ' where id = ?';
  20. $query = sprintf($query, $tables['list']);
  21. Sql_Query_Params($query, array($val, $active, $key));
  22. }
  23. $access = accessLevel('list');
  24. switch ($access) {
  25. case 'owner':
  26. $subselect = ' where owner = ' . $_SESSION['logindetails']['id'];
  27. $subselect_and = ' and owner = ' . $_SESSION['logindetails']['id'];
  28. break;
  29. case 'all':
  30. $subselect = '';
  31. $subselect_and = '';
  32. break;
  33. case 'none':
  34. default:
  35. $subselect = ' where id = 0';
  36. $subselect_and = ' and id = 0';
  37. break;
  38. }
  39. print '<div class="actions">';
  40. print PageLinkButton('catlists',$I18N->get('Categorise lists'));
  41. $canaddlist = false;
  42. if ($GLOBALS['require_login'] && !isSuperUser()) {
  43. $numlists = Sql_Fetch_Row_query("select count(*) from {$tables['list']} where owner = " . $_SESSION['logindetails']['id']);
  44. if ($numlists[0] < MAXLIST) {
  45. print PageLinkButton("editlist",$GLOBALS['I18N']->get('Add a list'));
  46. $canaddlist = true;
  47. }
  48. } else {
  49. print PageLinkButton('editlist',$GLOBALS['I18N']->get('Add a list'));
  50. $canaddlist = true;
  51. }
  52. print '</div>';
  53. if (isset($_GET['delete'])) {
  54. $delete = sprintf('%d',$_GET['delete']);
  55. # delete the index in delete
  56. $actionresult = $GLOBALS['I18N']->get('Deleting') . ' '.$GLOBALS['I18N']->get('list')." $delete ..\n";
  57. $result = Sql_query(sprintf('delete from '.$tables['list'].' where id = %d %s',$delete,$subselect_and));
  58. $done = Sql_Affected_Rows();
  59. if ($done) {
  60. $result = Sql_query('delete from '.$tables['listuser']." where listid = $delete");
  61. $result = Sql_query('delete from '.$tables['listmessage']." where listid = $delete");
  62. }
  63. $actionresult .= '..' . $GLOBALS['I18N']->get('Done') . "<br /><hr /><br />\n";
  64. $_SESSION['action_result'] = $actionresult;
  65. Redirect('list');
  66. return;
  67. # print ActionResult($actionresult);
  68. }
  69. if (!empty($_POST['importcontent'])) {
  70. include dirname(__FILE__).'/importsimple.php';
  71. }
  72. $html = '';
  73. $aConfiguredListCategories = listCategories();
  74. $aListCategories = array();
  75. $req = Sql_Query(sprintf('select distinct category from %s where category != "" %s ',$tables['list'],$subselect_and));
  76. while ($row = Sql_Fetch_Row($req)) {
  77. array_push($aListCategories,$row[0]);
  78. }
  79. array_push($aListCategories,s('Uncategorised'));
  80. if (sizeof($aListCategories)) {
  81. if (isset($_GET['tab']) && in_array($_GET['tab'],$aListCategories)) {
  82. $current = $_GET['tab'];
  83. } elseif (isset($_SESSION['last_list_category']) && in_array($_SESSION['last_list_category'],$aListCategories)) {
  84. $current = $_SESSION['last_list_category'];
  85. } else {
  86. $current = '';
  87. }
  88. if (stripos($current,strtolower(s('Uncategorised'))) !== false) {
  89. $current = '';
  90. }
  91. /*
  92. *
  93. * hmm, if lists are marked for a category, which is then removed, this would
  94. * cause them to not show up
  95. if (!in_array($current,$aConfiguredListCategories)) {
  96. $current = '';#$aListCategories[0];
  97. }
  98. */
  99. $_SESSION['last_list_category'] = $current;
  100. if ($subselect == '') {
  101. $subselect = ' where category = "'.$current.'"';
  102. } else {
  103. $subselect .= ' and category = "'.$current.'"';
  104. }
  105. $tabs = new WebblerTabs();
  106. foreach ($aListCategories as $category) {
  107. $category = trim($category);
  108. if ($category == '') {
  109. $category = $GLOBALS['I18N']->get('Uncategorised');
  110. }
  111. $tabs->addTab($category,$baseurl.'&amp;tab='.urlencode($category));
  112. }
  113. if ($current != '') {
  114. $tabs->setCurrent($current);
  115. } else {
  116. $tabs->setCurrent(s('Uncategorised'));
  117. }
  118. print $tabs->display();
  119. }
  120. $countquery
  121. = ' select *'
  122. . ' from ' . $tables['list']
  123. . $subselect;
  124. $countresult = Sql_query($countquery);
  125. $total = Sql_Num_Rows($countresult);
  126. if ($total == 0 && sizeof($aListCategories) && $current == '' && empty($_GET['tab'])) {
  127. ## reload to first category, if none found by default (ie all lists are categorised)
  128. if (!empty($aListCategories[0])) {
  129. Redirect('list&tab='.$aListCategories[0]);
  130. }
  131. }
  132. print '<p class="total">'.$total .' '. $GLOBALS['I18N']->get('Lists').'</p>';
  133. $limit = '';
  134. $query
  135. = ' select *'
  136. . ' from ' . $tables['list']
  137. . $subselect
  138. . ' order by listorder '.$limit;
  139. $result = Sql_query($query);
  140. $numlists = Sql_Affected_Rows($result);
  141. $ls = new WebblerListing(s('Lists'));
  142. if ($numlists > 15) {
  143. Info(s('You seem to have quite a lot of lists, do you want to organise them in categories? ').' '.PageLinkButton('catlists',$GLOBALS['I18N']->get('Great idea!')));
  144. /* @@TODO add paging when there are loads of lists, because otherwise the page is very slow
  145. $limit = ' limit 50';
  146. $query
  147. = ' select *'
  148. . ' from ' . $tables['list']
  149. . $subselect
  150. . ' order by listorder '.$limit;
  151. $result = Sql_query($query);
  152. */
  153. }
  154. while ($row = Sql_fetch_array($result)) {
  155. ## we only consider confirmed and not blacklisted subscribers members of a list
  156. ## we assume "confirmed" to be 1 or 0, so that the sum gives the total confirmed
  157. ## could be incorrect, as 1000 is also "true" but will be ok (saves a few queries)
  158. ## same with blacklisted, but we're disregarding that for now, because blacklisted subscribers should not
  159. ## be on the list at all.
  160. ## @@TODO increase accuracy, without adding loads of queries.
  161. $query
  162. = ' select count(u.id) as total,'
  163. . ' sum(u.confirmed) as confirmed, '
  164. . ' sum(u.blacklisted) as blacklisted '
  165. . ' from ' . $tables['listuser']
  166. . ' lu, '.$tables['user'].' u where u.id = lu.userid and listid = ? ';
  167. $req = Sql_Query_Params($query, array($row["id"]));
  168. $membercount = Sql_Fetch_Assoc($req);
  169. $members = $membercount['confirmed'];
  170. $unconfirmedMembers = (int)($membercount['total'] - $members);
  171. $desc = stripslashes($row['description']);
  172. if ($unconfirmedMembers > 0) {
  173. $membersDisplay = '<span class="memberCount">'.$members.'</span> <span class="unconfirmedCount">('.$unconfirmedMembers. ')</span>';
  174. } else {
  175. $membersDisplay = '<span class="memberCount">'.$members.'</span>';
  176. }
  177. //## allow plugins to add columns
  178. // @@@ TODO review this
  179. //foreach ($GLOBALS['plugins'] as $plugin) {
  180. //$desc = $plugin->displayLists($row) . $desc;
  181. //}
  182. $element = '<!-- '.$row['id'].'-->'.stripslashes($row['name']);
  183. $ls->addElement($element);
  184. $ls->setClass($element,'rows row1');
  185. $ls->addColumn($element,
  186. $GLOBALS['I18N']->get('Members'),'<div style="display:inline-block;text-align:right;width:50%;float:left;">'.$membersDisplay. '</div><span class="view" style="text-align:left;display:inline-block;float:right;width:48%;"><a class="button " href="./?page=members&id='.$row["id"].'" title="'.$GLOBALS['I18N']->get('View Members').'">'.$GLOBALS['I18N']->get('View Members').'</a></span>');
  187. $ls->addColumn($element,
  188. $GLOBALS['I18N']->get('Public'),sprintf('<input type="checkbox" name="active[%d]" value="1" %s %s />',$row["id"],
  189. $row["active"] ? 'checked="checked"' : '',listUsedInSubscribePage($row["id"]) ? ' disabled="disabled" ':''));
  190. /* $owner = adminName($row['owner']);
  191. if (!empty($owner)) {
  192. $ls->addColumn($element,
  193. $GLOBALS['I18N']->get('Owner'),$GLOBALS['require_login'] ? adminName($row['owner']):$GLOBALS['I18N']->get('n/a'));
  194. }
  195. if (trim($desc) != '') {
  196. $ls->addRow($element,
  197. $GLOBALS['I18N']->get('Description'),$desc);
  198. }
  199. */
  200. $ls->addColumn($element,
  201. $GLOBALS['I18N']->get('Order'),
  202. sprintf('<input type="text" name="listorder[%d]" value="%d" size="3" class="listorder" />',$row['id'],$row['listorder']));
  203. $deletebutton = new ConfirmButton(
  204. s('Are you sure you want to delete this list?'),
  205. PageURL2("list&delete=".$row["id"]),
  206. s('delete this list'));
  207. $ls->addRow($element,'','<span class="edit-list"><a class="button" href="?page=editlist&amp;id='.$row["id"].'" title="'.$GLOBALS['I18N']->get('Edit this list').'"></a></span>'.'<span class="send-list">'.PageLinkButton('send&new=1&list='.$row['id'],$GLOBALS['I18N']->get('send'),'','',$GLOBALS['I18N']->get('start a new campaign targetting this list')).'</span>'.
  208. '<span class="add_member">'.PageLinkDialogOnly('importsimple&list='.$row["id"],$GLOBALS['I18N']->get('Add Members')).'</span>'.
  209. '<span class="delete">'.$deletebutton->show().'</span>'
  210. ,'','','actions nodrag');
  211. $some = 1;
  212. }
  213. $ls->addSubmitButton('update',$GLOBALS['I18N']->get('Save Changes'));
  214. if (!$some) {
  215. echo $GLOBALS['I18N']->get('No lists, use Add List to add one');
  216. } else {
  217. print $ls->display('','draggable');
  218. }
  219. /*
  220. echo '<table class="x" border="0">
  221. <tr>
  222. <td>'.$GLOBALS['I18N']->get('No').'</td>
  223. <td>'.$GLOBALS['I18N']->get('Name').'</td>
  224. <td>'.$GLOBALS['I18N']->get('Order').'</td>
  225. <td>'.$GLOBALS['I18N']->get('Functions').'</td>
  226. <td>'.$GLOBALS['I18N']->get('Active').'</td>
  227. <td>'.$GLOBALS['I18N']->get('Owner').'</td>
  228. <td>'.$html . '
  229. <tr>
  230. <td colspan="6" align="center">
  231. <input type="submit" name="update" value="'.$GLOBALS['I18N']->get('Save Changes').'"></td>
  232. </tr>
  233. </table>';
  234. }
  235. */
  236. ?>
  237. </form>
  238. <p>
  239. <?php
  240. if ($canaddlist) {
  241. print PageLinkButton('editlist',$GLOBALS['I18N']->get('Add a list'));
  242. }
  243. ?>
  244. </p>