| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
|---|
| 7 | # Licensed under the GPL version 2.0 license. |
|---|
| 8 | # See LICENSE file or |
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 10 | # |
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
|---|
| 12 | |
|---|
| 13 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
|---|
| 14 | |
|---|
| 15 | dcPage::check('usage,contentadmin'); |
|---|
| 16 | |
|---|
| 17 | # Filters |
|---|
| 18 | $status_combo = array_merge( |
|---|
| 19 | array('-' => ''), |
|---|
| 20 | dcAdminCombos::getBlogStatusesCombo() |
|---|
| 21 | ); |
|---|
| 22 | |
|---|
| 23 | $sortby_combo = array( |
|---|
| 24 | __('Last update') => 'blog_upddt', |
|---|
| 25 | __('Blog name') => 'UPPER(blog_name)', |
|---|
| 26 | __('Blog ID') => 'B.blog_id', |
|---|
| 27 | __('Status') => 'blog_status' |
|---|
| 28 | ); |
|---|
| 29 | |
|---|
| 30 | $order_combo = array( |
|---|
| 31 | __('Descending') => 'desc', |
|---|
| 32 | __('Ascending') => 'asc' |
|---|
| 33 | ); |
|---|
| 34 | |
|---|
| 35 | # Actions |
|---|
| 36 | |
|---|
| 37 | if ($core->auth->isSuperAdmin()) { |
|---|
| 38 | $blogs_actions_page = new dcBlogsActionsPage($core, $core->adminurl->get("admin.blogs")); |
|---|
| 39 | if ($blogs_actions_page->process()) { |
|---|
| 40 | return; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | # Requests |
|---|
| 45 | $q = !empty($_GET['q']) ? $_GET['q'] : ''; |
|---|
| 46 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
|---|
| 47 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_upddt'; |
|---|
| 48 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
|---|
| 49 | |
|---|
| 50 | $show_filters = false; |
|---|
| 51 | |
|---|
| 52 | $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; |
|---|
| 53 | $nb_per_page = 30; |
|---|
| 54 | |
|---|
| 55 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
|---|
| 56 | if ($nb_per_page != (integer) $_GET['nb']) { |
|---|
| 57 | $show_filters = true; |
|---|
| 58 | } |
|---|
| 59 | $nb_per_page = (integer) $_GET['nb']; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | # - Search filter |
|---|
| 63 | if ($q) { |
|---|
| 64 | $params['q'] = $q; |
|---|
| 65 | $show_filters = true; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | # - Status filter |
|---|
| 69 | if ($status !== '' && in_array($status, $status_combo, true)) { |
|---|
| 70 | $params['blog_status'] = $status; |
|---|
| 71 | $show_filters = true; |
|---|
| 72 | } else { |
|---|
| 73 | $status = ''; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | # - Sortby and order filter |
|---|
| 77 | if ($sortby !== '' && in_array($sortby, $sortby_combo, true)) { |
|---|
| 78 | if ($order !== '' && in_array($order, $order_combo, true)) { |
|---|
| 79 | $params['order'] = $sortby . ' ' . $order; |
|---|
| 80 | } |
|---|
| 81 | } else { |
|---|
| 82 | $sortby = 'blog_upddt'; |
|---|
| 83 | $order = 'desc'; |
|---|
| 84 | } |
|---|
| 85 | if ($sortby != 'blog_upddt' || $order != 'desc') { |
|---|
| 86 | $show_filters = true; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | $params['limit'] = array((($page - 1) * $nb_per_page), $nb_per_page); |
|---|
| 90 | |
|---|
| 91 | try { |
|---|
| 92 | $counter = $core->getBlogs($params, 1); |
|---|
| 93 | $rs = $core->getBlogs($params); |
|---|
| 94 | $nb_blog = $counter->f(0); |
|---|
| 95 | $rsStatic = $rs->toStatic(); |
|---|
| 96 | if (($sortby != 'blog_upddt') && ($sortby != 'blog_status')) { |
|---|
| 97 | // Sort blog list using lexical order if necessary |
|---|
| 98 | $rsStatic->extend('rsExtUser'); |
|---|
| 99 | $rsStatic = $rsStatic->toExtStatic(); |
|---|
| 100 | $rsStatic->lexicalSort(($sortby == 'UPPER(blog_name)' ? 'blog_name' : 'blog_id'), $order); |
|---|
| 101 | } |
|---|
| 102 | $blog_list = new adminBlogList($core, $rs, $counter->f(0)); |
|---|
| 103 | } catch (Exception $e) { |
|---|
| 104 | $core->error->add($e->getMessage()); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* DISPLAY |
|---|
| 108 | -------------------------------------------------------- */ |
|---|
| 109 | |
|---|
| 110 | dcPage::open(__('List of blogs'), |
|---|
| 111 | dcPage::jsLoad('js/_blogs.js') . dcPage::jsFilterControl($show_filters), |
|---|
| 112 | dcPage::breadcrumb( |
|---|
| 113 | array( |
|---|
| 114 | __('System') => '', |
|---|
| 115 | __('List of blogs') => '' |
|---|
| 116 | )) |
|---|
| 117 | ); |
|---|
| 118 | |
|---|
| 119 | if (!$core->error->flag()) { |
|---|
| 120 | if ($core->auth->isSuperAdmin()) { |
|---|
| 121 | echo '<p class="top-add"><a class="button add" href="' . $core->adminurl->get("admin.blog") . '">' . __('Create a new blog') . '</a></p>'; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | echo |
|---|
| 125 | '<form action="' . $core->adminurl->get("admin.blogs") . '" method="get" id="filters-form">' . |
|---|
| 126 | '<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>' . |
|---|
| 127 | |
|---|
| 128 | '<div class="table">' . |
|---|
| 129 | '<div class="cell">' . |
|---|
| 130 | '<h4>' . __('Filters') . '</h4>' . |
|---|
| 131 | '<p><label for="q" class="ib">' . __('Search:') . '</label> ' . |
|---|
| 132 | form::field('q', 20, 255, html::escapeHTML($q)) . '</p>' . |
|---|
| 133 | ($core->auth->isSuperAdmin() ? |
|---|
| 134 | '<p><label for="status" class="ib">' . __('Status:') . '</label> ' . |
|---|
| 135 | form::combo('status', $status_combo, $status) . '</p>' : '') . |
|---|
| 136 | '</div>' . |
|---|
| 137 | |
|---|
| 138 | '<div class="cell filters-options">' . |
|---|
| 139 | '<h4>' . __('Display options') . '</h4>' . |
|---|
| 140 | '<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' . |
|---|
| 141 | form::combo('sortby', $sortby_combo, html::escapeHTML($sortby)) . '</p>' . |
|---|
| 142 | '<p><label for="order" class="ib">' . __('Sort:') . '</label> ' . |
|---|
| 143 | form::combo('order', $order_combo, html::escapeHTML($order)) . '</p>' . |
|---|
| 144 | '<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' . |
|---|
| 145 | form::number('nb', 0, 999, $nb_per_page) . ' ' . __('blogs per page') . '</label></p>' . |
|---|
| 146 | '</div>' . |
|---|
| 147 | '</div>' . |
|---|
| 148 | |
|---|
| 149 | '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' . |
|---|
| 150 | '<br class="clear" /></p>' . //Opera sucks |
|---|
| 151 | '</form>'; |
|---|
| 152 | |
|---|
| 153 | # Show blogs |
|---|
| 154 | $blog_list->display($page, $nb_per_page, |
|---|
| 155 | ($core->auth->isSuperAdmin() ? |
|---|
| 156 | '<form action="' . $core->adminurl->get("admin.blogs") . '" method="post" id="form-blogs">' : '') . |
|---|
| 157 | |
|---|
| 158 | '%s' . |
|---|
| 159 | |
|---|
| 160 | ($core->auth->isSuperAdmin() ? |
|---|
| 161 | '<div class="two-cols clearfix">' . |
|---|
| 162 | '<p class="col checkboxes-helpers"></p>' . |
|---|
| 163 | |
|---|
| 164 | '<p class="col right"><label for="action" class="classic">' . __('Selected blogs action:') . '</label> ' . |
|---|
| 165 | form::combo('action', $blogs_actions_page->getCombo(), |
|---|
| 166 | array('class' => 'online', 'extra_html' => 'title="' . __('Actions') . '"')) . |
|---|
| 167 | $core->formNonce() . |
|---|
| 168 | '<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' . |
|---|
| 169 | '</div>' . |
|---|
| 170 | |
|---|
| 171 | '<p><label for="pwd" class="classic">' . __('Please give your password to confirm blog(s) deletion:') . '</label> ' . |
|---|
| 172 | form::password('pwd', 20, 255, array('autocomplete' => 'current-password')) . '</p>' . |
|---|
| 173 | |
|---|
| 174 | form::hidden(array('sortby'), $sortby) . |
|---|
| 175 | form::hidden(array('order'), $order) . |
|---|
| 176 | form::hidden(array('status'), $status) . |
|---|
| 177 | form::hidden(array('page'), $page) . |
|---|
| 178 | form::hidden(array('nb'), $nb_per_page) . |
|---|
| 179 | |
|---|
| 180 | '</form>' : ''), |
|---|
| 181 | $show_filters |
|---|
| 182 | ); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | dcPage::helpBlock('core_blogs'); |
|---|
| 186 | dcPage::close(); |
|---|