Dotclear

source: plugins/pollsFactory/inc/index.poll.php @ 2140

Revision 2140, 13.2 KB checked in by JcDenis, 14 years ago (diff)

minor fix

Line 
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
13if (!defined('DC_CONTEXT_ADMIN')){return;}
14
15dcPage::check('usage,contentadmin');
16
17$redir_url = $p_url.'&tab=poll';
18
19$post_id = '';
20$post_dt = '';
21$post_format = $core->auth->getOption('post_format');
22$post_url = '';
23$post_lang = $core->auth->getInfo('user_lang');
24$post_title = '';
25$post_excerpt = '';
26$post_excerpt_xhtml = '';
27$post_content = '';
28$post_content_xhtml = '';
29$post_status = $core->auth->getInfo('user_post_status');
30$post_selected = false;
31$post_open_tb = false; //closed poll
32
33$page_title = __('New poll');
34
35$can_view_page = true;
36$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
37$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
38$can_delete = false;
39
40$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
41$post_link = '<a href="'.$p_url.'&amp;tab=poll&amp;id=%s" title="%s">%s</a>';
42
43$next_link = $prev_link = $next_headlink = $prev_headlink = null;
44
45# If user can't publish
46if (!$can_publish) {
47     $post_status = -2;
48}
49
50# Status combo
51foreach ($core->blog->getAllPostStatus() as $k => $v) {
52     $status_combo[$v] = (string) $k;
53}
54
55# Formaters combo
56foreach ($core->getFormaters() as $v) {
57     $formaters_combo[$v] = $v;
58}
59
60# Languages combo
61$rs = $core->blog->getLangs(array('order'=>'asc'));
62$all_langs = l10n::getISOcodes(0,1);
63$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
64while ($rs->fetch()) {
65     if (isset($all_langs[$rs->post_lang])) {
66          $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
67          unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
68     } else {
69          $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
70     }
71}
72unset($all_langs);
73unset($rs);
74
75
76# Get entry informations
77if (!empty($_REQUEST['id']))
78{
79     $params['post_type'] = 'pollsfactory';
80     $params['post_id'] = $_REQUEST['id'];
81     
82     $post = $core->blog->getPosts($params);
83     
84     if ($post->isEmpty())
85     {
86          $core->error->add(__('This poll does not exist.'));
87          $can_view_page = false;
88     }
89     else
90     {
91          $post_id = $post->post_id;
92          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
93          $post_format = $post->post_format;
94          $post_url = $post->post_url;
95          $post_lang = $post->post_lang;
96          $post_title = $post->post_title;
97          $post_excerpt = '';
98          $post_excerpt_xhtml = '';
99          $post_content = $post->post_content;
100          $post_content_xhtml = $post->post_content_xhtml;
101          $post_status = $post->post_status;
102          $post_selected = (boolean) $post->post_selected;
103          $post_open_tb = (boolean) $post->post_open_tb;
104         
105          $can_edit_post = $post->isEditable();
106          $can_delete= $post->isDeletable();
107         
108          $next_rs = $core->blog->getNextPost($post,1);
109          $prev_rs = $core->blog->getNextPost($post,-1);
110         
111          if ($next_rs !== null) {
112               $next_link = sprintf($post_link,$next_rs->post_id,
113                    html::escapeHTML($next_rs->post_title),__('next poll').'&nbsp;&#187;');
114               $next_headlink = sprintf($post_headlink,'next',
115                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
116          }
117         
118          if ($prev_rs !== null) {
119               $prev_link = sprintf($post_link,$prev_rs->post_id,
120                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('previous poll'));
121               $prev_headlink = sprintf($post_headlink,'previous',
122                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
123          }
124     }
125}
126
127# Format excerpt and content
128if (!empty($_POST) && $can_edit_post)
129{
130     $post_format = $_POST['post_format'];
131     $post_excerpt = '';
132     $post_content = $_POST['post_content'];
133     
134     $post_title = $_POST['post_title'];
135         
136     if (isset($_POST['post_status'])) {
137          $post_status = (integer) $_POST['post_status'];
138     }
139     
140     if (empty($_POST['post_dt'])) {
141          $post_dt = '';
142     } else {
143          $post_dt = strtotime($_POST['post_dt']);
144          $post_dt = date('Y-m-d H:i',$post_dt);
145     }
146     
147     $post_selected = !empty($_POST['post_selected']);
148     $post_open_tb = !empty($_POST['post_open_tb']);
149     $post_lang = $_POST['post_lang'];
150     
151     if (isset($_POST['post_url'])) {
152          $post_url = $_POST['post_url'];
153     }
154
155     $core->blog->setPostContent(
156          $post_id,$post_format,$post_lang,
157          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
158     );
159}
160
161# Create or update post
162if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)
163{
164     # remove relation between poll and posts
165     if (!empty($_POST['removeentries']))
166     {
167          try {
168               foreach ($_POST['removeentries'] as $k => $v) {
169                    $removeentries[$k] = (integer) $v;
170               }
171               $core->con->execute(
172                    'DELETE FROM '.$core->prefix.'post_option '.
173                    "WHERE option_meta = ".$post_id." AND option_type = 'pollspost' ".
174                    'AND '.implode(' OR post_id = ',$removeentries)
175               );
176          } catch (Exception $e) {
177               $core->error->add($e->getMessage());
178          }
179     }
180
181     $cur = $core->con->openCursor($core->prefix.'post');
182     
183     $cur->post_type = 'pollsfactory';
184     $cur->post_title = $post_title;
185     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
186     $cur->post_format = $post_format;
187     $cur->post_lang = $post_lang;
188     $cur->post_title = $post_title;
189     $cur->post_excerpt = '';
190     $cur->post_excerpt_xhtml = '';
191     $cur->post_content = $post_content;
192     $cur->post_content_xhtml = $post_content_xhtml;
193     $cur->post_status = $post_status;
194     $cur->post_selected = (integer) $post_selected;
195     $cur->post_open_tb = (integer) $post_open_tb;
196     
197     if (isset($_POST['post_url'])) {
198          $cur->post_url = $post_url;
199     }
200     if ($cur->post_content == '') {
201          $cur->post_content = ' ';
202     }
203     
204     # Update post
205     if ($post_id)
206     {
207          try
208          {
209               # --BEHAVIOR-- adminBeforePollsFactoryUpdate
210               $core->callBehavior('adminBeforePollsFactoryUpdate',$cur,$post_id);
211               
212               $core->blog->updPost($post_id,$cur);
213               
214               # --BEHAVIOR-- adminAfterPollsFactoryUpdate
215               $core->callBehavior('adminAfterPollsFactoryUpdate',$cur,$post_id);
216               
217               http::redirect($p_url.'&tab=poll&id='.$post_id.'&msg=editpoll');
218          }
219          catch (Exception $e)
220          {
221               $core->error->add($e->getMessage());
222          }
223     }
224     else
225     {
226          $cur->user_id = $core->auth->userID();
227         
228          try
229          {
230               # --BEHAVIOR-- adminBeforePollsFactoryCreate
231               $core->callBehavior('adminBeforePollsFactoryCreate',$cur);
232               
233               $return_id = $core->blog->addPost($cur);
234               
235               # --BEHAVIOR-- adminAfterPollsFactoryCreate
236               $core->callBehavior('adminAfterPollsFactoryCreate',$cur,$return_id);
237               
238               http::redirect($p_url.'&tab=poll&id='.$return_id.'&msg=createpoll');
239          }
240          catch (Exception $e)
241          {
242               $core->error->add($e->getMessage());
243          }
244     }
245}
246
247# delete post
248if (!empty($_POST['delete']) && $can_delete)
249{
250     try {
251
252          # --BEHAVIOR-- adminBeforePollsFactoryDelete
253          $core->callBehavior('adminBeforePollsFactoryDelete',$post_id);
254
255          $core->blog->delPost($post_id);
256          http::redirect($p_url.'&tab=polls&msg=deletepoll');
257     } catch (Exception $e) {
258          $core->error->add($e->getMessage());
259     }
260}
261
262
263/* DISPLAY
264-------------------------------------------------------- */
265
266echo '<html>
267<head><title>'.__('Polls manager').'</title>'.$header.
268dcPage::jsDatePicker().
269dcPage::jsToolBar().
270dcPage::jsModal().
271dcPage::jsLoad('js/_post.js').
272dcPage::jsPageTabs('edit-entry').
273dcPage::jsConfirmClose('entry-form').
274dcPage::jsLoad('index.php?pf=pollsFactory/js/poll.js').
275"<script type=\"text/javascript\">\n//<![CDATA[\n".
276dcPage::jsVar('pollsFactoryAddEditor.prototype.text_title',__('Related posts')).
277dcPage::jsVar('pollsFactoryAddEditor.prototype.text_remove_post',__('Are you sure you want to remove this post?')).
278"\n//]]>\n</script>\n".
279
280# --BEHAVIOR-- adminPollsFactoryHeaders
281$core->callBehavior('adminPollsFactoryHeaders').
282
283$next_headlink."\n".$prev_headlink.
284'</head>
285<body>'.$msg.'
286<h2>'.html::escapeHTML($core->blog->name).
287' &rsaquo; <a href="'.$p_url.'&amp;tab=polls">'.__('Polls').'</a>';
288if ($post_id) {
289     $preview_url = $core->blog->url.$core->url->getBase('pollsFactoryPagePreview').'/'.$core->auth->userID().'/'.http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).'/'.$post->post_url;
290
291     echo ' &rsaquo; '.__('Edit poll').
292     ' - <a id="poll-preview" href="'.$preview_url.'" class="button nowait">'.__('Preview poll').'</a>'.
293     ' - <a class="button" href="'.$p_url.'&amp;tab=poll">'.__('New poll').'</a>';
294}
295else {
296     echo ' &rsaquo; '.__('New poll');
297}
298echo '</h2>';
299
300# XHTML conversion
301if (!empty($_GET['xconv']))
302{
303     $post_excerpt = $post_excerpt_xhtml;
304     $post_content = $post_content_xhtml;
305     $post_format = 'xhtml';
306     
307     echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your poll.').'</p>';
308}
309# nav link
310if ($post_id)
311{
312     echo '<p>';
313     if ($prev_link) { echo $prev_link; }
314     if ($next_link && $prev_link) { echo ' - '; }
315     if ($next_link) { echo $next_link; }
316     
317     # --BEHAVIOR-- adminPollsFactoryNavLinks
318     $core->callBehavior('adminPollsFactoryNavLinks',isset($post) ? $post : null);
319     
320     echo '</p>';
321}
322
323# Exit if we cannot view page
324if (!$can_view_page) {
325     dcPage::helpBlock('core_post');
326     dcPage::close();
327     exit;
328}
329
330
331/* Post form if we can edit post
332-------------------------------------------------------- */
333if ($can_edit_post)
334{
335     echo '<div class="multi-part" title="'.__('Poll').'" id="edit-entry">';
336     echo '<form action="'.$p_url.'&amp;tab=poll" method="post" id="entry-form">';
337     echo '<div id="entry-sidebar">';
338     
339     echo 
340     '<p><label>'.__('Poll status:').
341     form::combo('post_status',$status_combo,$post_status,'',3,!$can_publish).
342     '</label></p>'.
343     
344     '<p><label>'.__('Published on:').
345     form::field('post_dt',16,16,$post_dt,'',3).
346     '</label></p>'.
347
348     '<p><label>'.__('Text formating:').
349     form::combo('post_format',$formaters_combo,$post_format,'',3).
350     ($post_id && $post_format != 'xhtml' ? '<a href="post.php?id='.$post_id.'&amp;xconv=1">'.__('Convert to XHTML').'</a>' : '').
351     '</label></p>'.
352     
353     '<p><label class="classic">'.form::checkbox('post_selected',1,$post_selected,'',3).' '.
354     __('Selected poll').'</label></p>'.
355     
356     '<p><label class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb,'',3).' '.
357     __('Opened poll').'</label></p>'.
358     
359     '<p><label>'.__('Poll lang:').
360     form::combo('post_lang',$lang_combo,$post_lang,'',5).
361     '</label></p>'.
362     
363     '<div class="lockable">'.
364     '<p><label>'.__('Basename:').
365     form::field('post_url',10,255,html::escapeHTML($post_url),'maximal',3).
366     '</label></p>'.
367     '<p class="form-note warn">'.
368     __('Warning: If you set the URL manually, it may conflict with another poll.').
369     '</p>'.
370     '</div>';
371
372     # Posts linked to this poll
373     $rels_params['option_type'] = 'pollspost';
374     $rels_params['option_meta'] = $post_id;
375     $rels = $factory->getOptions($rels_params);
376     if (!$rels->isEmpty()) {
377          $c = '';
378          while ($rels->fetch()) {
379               $rel_params['no_content'] = true;
380               $rel_params['post_id'] = $rels->post_id;
381               $rel_params['post_type'] = '';
382               $rel_params['limit'] = 1;
383               $rel = $core->blog->getPosts($rel_params);
384               if (!$rel->isEmpty()) {
385                    $c .= '<li>'.form::checkbox(array('removeentries[]'),$rel->post_id,0,3).' <a title="'.__('edit entry').'" href="'.$core->getPostAdminURL($rel->post_type,$rel->post_id).'">'.html::escapeHTML($rel->post_title).'</a> ('.__($rel->post_type).')</li>';
386               }
387          }
388          if (!empty($c)) {
389               echo 
390               '<div id="pollsfactory-entries">'.
391               '<h3>'.__('Related posts').'</h3>'.
392               '<p class="form-note">'.__('Uncheck post to remove').'</p>'.
393               '<ul>'.$c.'</ul>'.
394               '</div>';
395          }
396     }
397     
398     # --BEHAVIOR-- adminPollsFactoryFormSidebar
399     $core->callBehavior('adminPollsFactoryFormSidebar',isset($post) ? $post : null);
400     
401     echo '</div>';      // End #entry-sidebar
402     
403     echo '<div id="entry-content"><fieldset class="constrained">';
404     
405     echo
406     '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:').
407     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal',2).
408     '</label></p>'.
409     
410     '<p class="area"><label for="post_content">'.__('Description:').'</label> '.
411     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content),'',2).
412     '</p>';
413     
414     # --BEHAVIOR-- adminPollsFactoryForm
415     $core->callBehavior('adminPollsFactoryForm',isset($post) ? $post : null);
416     
417     echo
418     '<p>'.
419     ($post_id ? form::hidden('id',$post_id) : '').
420     '<input type="submit" value="'.__('save').' (s)" tabindex="4" '.
421     'accesskey="s" name="save" /> '.
422     ($can_delete ? '<input type="submit" value="'.__('delete').'" name="delete" />' : '').
423     $core->formNonce().
424     '</p>';
425     
426     echo '</fieldset></div>';          // End #entry-content
427     echo '</form>';
428     echo '</div>';
429
430     if ($post_id) {
431          echo '<a class="multi-part" href="'.$p_url.'&amp;tab=content&amp;poll_id='.$post->post_id.'" title="'.__('Edit queries').'">'.__('Content').'</a> ';
432          $count = $factory->countVotes($post->post_id);
433          if ($count) {
434               echo '<a class="multi-part" href="'.$p_url.'&amp;tab=result&amp;poll_id='.$post->post_id.'" title="'.__('Show results').'">'.__('Results').'</a> ';
435          }
436     }
437}
438
439dcPage::helpBlock('pollsFactory','core_wiki');
440echo $footer.'</body></html>';
441?>
Note: See TracBrowser for help on using the repository browser.

Sites map