[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 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::checkSuper(); |
---|
| 16 | |
---|
| 17 | # Filters |
---|
| 18 | $sortby_combo = array( |
---|
| 19 | __('Blog ID') => 'B.blog_id', |
---|
| 20 | __('Blog name') => 'blog_name' |
---|
| 21 | ); |
---|
| 22 | |
---|
| 23 | $order_combo = array( |
---|
| 24 | __('Descending') => 'desc', |
---|
| 25 | __('Ascending') => 'asc' |
---|
| 26 | ); |
---|
| 27 | |
---|
| 28 | $q = !empty($_GET['q']) ? $_GET['q'] : ''; |
---|
| 29 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_id'; |
---|
| 30 | $order = !empty($_GET['order']) ? $_GET['order'] : 'asc'; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | # Check users |
---|
| 34 | if (!empty($_REQUEST['user_id']) && is_array($_REQUEST['user_id'])) |
---|
| 35 | { |
---|
| 36 | foreach ($_REQUEST['user_id'] as $u) |
---|
| 37 | { |
---|
| 38 | if ($core->userExists($u)) { |
---|
| 39 | $users[] = $u; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | if (empty($users)) |
---|
| 45 | { |
---|
| 46 | $core->error->add(__('No blog or user given.')); |
---|
| 47 | } |
---|
| 48 | else |
---|
| 49 | { |
---|
| 50 | $page = !empty($_GET['page']) ? $_GET['page'] : 1; |
---|
| 51 | $nb_per_page = 30; |
---|
| 52 | |
---|
| 53 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
| 54 | $nb_per_page = $_GET['nb']; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | $show_filters = false; |
---|
| 58 | |
---|
| 59 | # - Search filter |
---|
| 60 | if ($q) { |
---|
| 61 | $params['q'] = $q; |
---|
| 62 | $show_filters = true; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | # - Sortby and order filter |
---|
| 66 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
| 67 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
| 68 | $params['order'] = $sortby.' '.$order; |
---|
| 69 | $show_filters = true; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
| 74 | |
---|
| 75 | try { |
---|
| 76 | $rs = $core->getBlogs($params); |
---|
| 77 | $counter = $core->getBlogs($params,1); |
---|
| 78 | $nb_blog = $counter->f(0); |
---|
| 79 | } catch (Exception $e) { |
---|
| 80 | $core->error->add($e->getMessage()); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /* DISPLAY |
---|
| 85 | -------------------------------------------------------- */ |
---|
| 86 | $starting_script = dcPage::jsLoad('js/_permissions_blog.js'); |
---|
| 87 | if (!$show_filters) { |
---|
| 88 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
| 89 | } |
---|
| 90 | dcPage::open(__('choose a blog'),$starting_script); |
---|
| 91 | |
---|
| 92 | echo '<h2><a href="users.php">'.__('Users').'</a> › '.__('Choose a blog').'</h2>'; |
---|
| 93 | |
---|
| 94 | if (!$core->error->flag()) |
---|
| 95 | { |
---|
| 96 | $hidden_fields = ''; |
---|
| 97 | foreach ($users as $u) { |
---|
| 98 | $hidden_fields .= form::hidden(array('user_id[]'),$u); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | if (!$show_filters) { |
---|
| 102 | echo '<p><a id="filter-control" class="form-control" href="#">'.__('Filters').'</a></p>'; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | echo |
---|
| 106 | '<form action="permissions_blog.php" method="get" id="filters-form">'. |
---|
| 107 | '<fieldset class="two-cols"><legend>'.__('Filters').'</legend>'. |
---|
| 108 | |
---|
| 109 | '<div class="col">'. |
---|
[68] | 110 | '<p><label for="sortby">'.__('Order by:').' '. |
---|
[0] | 111 | form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)). |
---|
| 112 | '</label> '. |
---|
[68] | 113 | '<label for="order">'.__('Sort:').' '. |
---|
[0] | 114 | form::combo('order',$order_combo,html::escapeHTML($order)). |
---|
| 115 | '</label></p>'. |
---|
| 116 | '</div>'. |
---|
| 117 | |
---|
| 118 | '<div class="col">'. |
---|
[68] | 119 | '<p><label for="q">'.__('Search:').' '. |
---|
[0] | 120 | form::field('q',20,255,html::escapeHTML($q)). |
---|
| 121 | '</label></p>'. |
---|
[68] | 122 | '<p><label for="nb" class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
---|
[0] | 123 | __('Entries per page').'</label> '. |
---|
[3] | 124 | '<input type="submit" value="'.__('Apply filters').'" />'. |
---|
[0] | 125 | $hidden_fields.'</p>'. |
---|
| 126 | '</div>'. |
---|
| 127 | |
---|
| 128 | '<br class="clear" />'. //Opera sucks |
---|
| 129 | '</fieldset>'. |
---|
| 130 | '</form>'; |
---|
| 131 | |
---|
| 132 | echo |
---|
| 133 | '<p>'. |
---|
| 134 | sprintf(__('Choose one or more blogs to which you want to give permissions to users %s.'), |
---|
| 135 | '<strong>'.implode(', ',$users).'</strong>').'</p>'; |
---|
| 136 | |
---|
| 137 | # Show blogs |
---|
| 138 | if ($nb_blog == 0) |
---|
| 139 | { |
---|
| 140 | echo '<p><strong>'.__('No blog').'</strong></p>'; |
---|
| 141 | } |
---|
| 142 | else |
---|
| 143 | { |
---|
| 144 | $pager = new pager($page,$nb_blog,$nb_per_page,10); |
---|
| 145 | $pager->var_page = 'page'; |
---|
| 146 | |
---|
| 147 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
| 148 | |
---|
| 149 | echo |
---|
| 150 | '<form action="permissions.php" method="post" id="form-blogs">'. |
---|
| 151 | '<table class="clear"><tr>'. |
---|
| 152 | '<th colspan="2">'.__('Blog ID').'</th>'. |
---|
| 153 | '<th>'.__('Blog name').'</th>'. |
---|
| 154 | '<th class="nowrap">'.__('Entries').'</th>'. |
---|
| 155 | '<th class="nowrap">'.__('Status').'</th>'. |
---|
| 156 | '</tr>'; |
---|
| 157 | |
---|
| 158 | while ($rs->fetch()) { |
---|
| 159 | echo blogLine($rs); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | echo |
---|
| 163 | '</table>'. |
---|
| 164 | |
---|
| 165 | '<p class="checkboxes-helpers"></p>'. |
---|
| 166 | |
---|
| 167 | '<p><input type="submit" value="'.__('set permissions').'" />'. |
---|
| 168 | $hidden_fields. |
---|
| 169 | $core->formNonce().'</p>'. |
---|
| 170 | '</form>'; |
---|
| 171 | |
---|
| 172 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | dcPage::close(); |
---|
| 177 | |
---|
| 178 | function blogLine($rs) |
---|
| 179 | { |
---|
| 180 | global $core; |
---|
| 181 | |
---|
| 182 | $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
| 183 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); |
---|
| 184 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
| 185 | |
---|
| 186 | return |
---|
| 187 | '<tr class="line">'. |
---|
| 188 | '<td class="nowrap">'. |
---|
[68] | 189 | form::checkbox(array('blog_id[]'),$rs->blog_id,'','','',false,'title="'.__('select').' '.$rs->blog_id.'"').'</td>'. |
---|
[0] | 190 | '<td class="nowrap">'.$rs->blog_id.'</td>'. |
---|
| 191 | '<td class="maximal">'.html::escapeHTML($rs->blog_name).'</td>'. |
---|
| 192 | '<td class="nowrap">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
| 193 | '<td class="status">'.$img_status.'</td>'. |
---|
| 194 | '</tr>'; |
---|
| 195 | } |
---|
| 196 | ?> |
---|