1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of pollsFactory, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2010 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_CONTEXT_ADMIN')){return;} |
---|
14 | |
---|
15 | $redir = $hidden_fields = ''; |
---|
16 | $posts_ids = array(); |
---|
17 | if (!empty($_GET['post_id'])) { |
---|
18 | $posts_ids[] = (integer) $_GET['post_id']; |
---|
19 | $hidden_fields .= form::hidden(array('entries[]'),$_GET['post_id']); |
---|
20 | } |
---|
21 | elseif (!empty($_POST['entries'])) { |
---|
22 | foreach($_POST['entries'] as $k => $id) { |
---|
23 | $posts_ids[] = (integer) $id; |
---|
24 | $hidden_fields .= form::hidden(array('entries[]'),$id); |
---|
25 | } |
---|
26 | } |
---|
27 | if (empty($posts_ids)) { |
---|
28 | $core->error->add(__('no post ID')); |
---|
29 | } |
---|
30 | $posts = $core->blog->getPosts(array('post_id'=>$posts_ids,'post_type'=>'')); |
---|
31 | |
---|
32 | if ($posts->post_type == 'post') { |
---|
33 | $redir = $posts->count() > 1 ? 'posts.php' : 'post.php?id='.$posts->post_id; |
---|
34 | } |
---|
35 | elseif ($posts->post_type == 'page') { |
---|
36 | $redir = $posts->count() > 1 ? 'plugin.php?p=pages&act=list' : 'plugin.php?p=pages&act=page&id='.$posts->post_id; |
---|
37 | } |
---|
38 | //todo post gal |
---|
39 | |
---|
40 | # Action |
---|
41 | if ($action == 'addpollstoposts' && !empty($_POST['pollspostlist'])) |
---|
42 | { |
---|
43 | try { |
---|
44 | while ($posts->fetch()) { |
---|
45 | # Delete relations between post and polls |
---|
46 | $core->con->execute( |
---|
47 | 'DELETE FROM '.$core->prefix.'post_option '. |
---|
48 | "WHERE option_type = 'pollspost' ". |
---|
49 | "AND post_id = '".$posts->post_id."' " |
---|
50 | ); |
---|
51 | # Add relations selected polls to entries |
---|
52 | $cur = $factory->open(); |
---|
53 | foreach($_POST['pollspostlist'] as $k => $id) { |
---|
54 | $cur->clean(); |
---|
55 | $cur->option_type = 'pollspost'; |
---|
56 | $cur->post_id = $posts->post_id; |
---|
57 | $cur->option_meta = $id; |
---|
58 | $factory->addOption($cur); |
---|
59 | } |
---|
60 | } |
---|
61 | http::redirect($_POST['redir']); |
---|
62 | } |
---|
63 | catch (Exception $e) { |
---|
64 | $core->error->add($e->getMessage()); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | # Display |
---|
69 | echo ' |
---|
70 | <html> |
---|
71 | <head><title>'.__('Polls manager').'</title>'.$header.'</head> |
---|
72 | <body>'; |
---|
73 | |
---|
74 | $polls = $core->blog->getPosts(array('post_type'=>'pollsfactory')); |
---|
75 | if ($polls->isEmpty()) { |
---|
76 | echo |
---|
77 | '<p>'.__('There is no polls').'</p>'. |
---|
78 | '<p><a href="'.$redir.'">'.__('go back').'</a></p>'; |
---|
79 | } |
---|
80 | else { |
---|
81 | echo ' |
---|
82 | <h2>'.__('Add polls to posts').'</h2> |
---|
83 | <form action="plugin.php" method="post"> |
---|
84 | <div class="two-cols"> |
---|
85 | <div class="col"> |
---|
86 | <h3>'.__('Polls').'</h3> |
---|
87 | <ul>'; |
---|
88 | |
---|
89 | while($polls->fetch()) { |
---|
90 | echo '<li><label class="classic">'.form::checkbox('pollspostlist[]',$polls->post_id,0,'').' '.$polls->post_title.'</label></li>'; |
---|
91 | } |
---|
92 | echo ' |
---|
93 | </ul> |
---|
94 | </div> |
---|
95 | <div class="col"> |
---|
96 | <h3>'.__('Entries').'</h3> |
---|
97 | <ul>'; |
---|
98 | while ($posts->fetch()) { |
---|
99 | echo '<li>'.html::escapeHTML($posts->post_title).'</li>'; |
---|
100 | } |
---|
101 | echo ' |
---|
102 | </ul> |
---|
103 | </div></div> |
---|
104 | <p class="clear"><input type="submit" name="save" value="'.__('save').'" />'. |
---|
105 | form::hidden(array('p'),'pollsFactory'). |
---|
106 | form::hidden(array('tab'),'post'). |
---|
107 | form::hidden(array('action'),'addpollstoposts'). |
---|
108 | form::hidden(array('redir'),$redir). |
---|
109 | $core->formNonce(). |
---|
110 | $hidden_fields.' |
---|
111 | </p> |
---|
112 | </form>'; |
---|
113 | } |
---|
114 | dcPage::helpBlock('pollsFactory'); |
---|
115 | echo $footer.'</body></html>'; |
---|
116 | ?> |
---|