1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # Copyright (c) 2010 Arnaud Renevier |
---|
5 | # published under the modified BSD license. |
---|
6 | # -- END LICENSE BLOCK ------------------------------------ |
---|
7 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
8 | dcPage::check('categories'); |
---|
9 | ?> |
---|
10 | <html> |
---|
11 | <head> |
---|
12 | <title><?php echo (__('private categories'))?></title> |
---|
13 | <?php |
---|
14 | echo dcPage::jsLoad('index.php?pf=prvcat/js/config.js'); |
---|
15 | ?> |
---|
16 | </head> |
---|
17 | <body> |
---|
18 | |
---|
19 | <h2><?php echo html::escapeHTML($core->blog->name).' › '. __('private categories'); ?></h2> |
---|
20 | <?php |
---|
21 | $categories = $core->blog->getCategories()->rows(); |
---|
22 | |
---|
23 | if (empty($categories)) { |
---|
24 | echo '<p>'.__('No category yet.').'</p>'; |
---|
25 | } else { |
---|
26 | $perms = new prvCatPermMgr($core->con, $core->prefix); |
---|
27 | |
---|
28 | $hasupdate = false; |
---|
29 | if (isset($_POST['prvcat_upd'])) { |
---|
30 | $hasupdate = true; |
---|
31 | if (!$_POST['prvcat_pwd']) { |
---|
32 | foreach ($categories as $cat) { |
---|
33 | # no password, but at least one box checked |
---|
34 | if ($_POST['prvcat_'.$cat['cat_id']] == "private") { |
---|
35 | $missing_pwd = true; |
---|
36 | break; |
---|
37 | } |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | if (!$missing_pwd) { |
---|
42 | $perms->setpassword($_POST['prvcat_pwd']); |
---|
43 | foreach ($categories as $cat) { |
---|
44 | $perms->setprivate($cat['cat_id'], |
---|
45 | ($_POST['prvcat_'.$cat['cat_id']] == "private"), |
---|
46 | $_POST['prvcat_pwd']); |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | print $p_url; |
---|
52 | echo '<form id="prvcat-form" action="'.$p_url.'" method="post">'. |
---|
53 | '<fieldset>'. |
---|
54 | '<legend>'.__('Categories list').'</legend>'; |
---|
55 | |
---|
56 | if ($hasupdate and !$missing_pwd) { |
---|
57 | echo '<p class="message">'.__('Configuration successfully updated').'</p>'; |
---|
58 | } |
---|
59 | |
---|
60 | $ref_level = $level = $categories[0]->level; |
---|
61 | foreach ($categories as $cat) { |
---|
62 | if ($missing_pwd) { |
---|
63 | $check_private = ($_POST['prvcat_'.$cat['cat_id']] == "private"); |
---|
64 | } else { |
---|
65 | $check_private = $perms->isprivate($cat['cat_id']); |
---|
66 | } |
---|
67 | |
---|
68 | $li_content = html::escapeHTML($cat['cat_title']).'<br />'. |
---|
69 | form::checkbox('prvcat_'.$cat['cat_id'], 'private', $check_private). |
---|
70 | __('make private'); |
---|
71 | |
---|
72 | if ($cat['level'] > $level) { |
---|
73 | echo str_repeat('<ul><li>',$cat['level'] - $level); |
---|
74 | } else if ($cat['level'] < $level) { |
---|
75 | echo str_repeat('</li></ul>',-($cat['level'] - $level)); |
---|
76 | } |
---|
77 | if ($cat['level'] <= $level) { |
---|
78 | echo '</li><li>'; |
---|
79 | } |
---|
80 | echo $li_content; |
---|
81 | |
---|
82 | $level = $cat['level']; |
---|
83 | } |
---|
84 | if ($ref_level - $level < 0) { |
---|
85 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
86 | } |
---|
87 | |
---|
88 | if ($missing_pwd) { |
---|
89 | $label = __('You need to enter a password'); |
---|
90 | $class = 'error'; |
---|
91 | } else { |
---|
92 | $label = __('Password to access private categories'); |
---|
93 | $class = ''; |
---|
94 | } |
---|
95 | |
---|
96 | # we use only one password for all categories, first because it's |
---|
97 | # probably more ergonomic for user. Also, browsers password managers do |
---|
98 | # not handle well different password in the same page. |
---|
99 | # FIXME: We still save in the database one password for each private |
---|
100 | # category (it will be the same for all categories). |
---|
101 | echo '<label class="'.$class.'">'.$label. |
---|
102 | form::password('prvcat_pwd', 20, 32). |
---|
103 | '</label>'; |
---|
104 | echo '<input type="submit" name="prvcat_upd" value="'.__('Save').'" />'. |
---|
105 | $core->formNonce(). |
---|
106 | '</fieldset>'. |
---|
107 | '</form>'; |
---|
108 | } |
---|
109 | |
---|
110 | dcPage::helpBlock('prvcat'); |
---|
111 | ?> |
---|
112 | |
---|
113 | </body> |
---|
114 | </html> |
---|