1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of periodical, 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 | $period_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : -1; |
---|
16 | $action_redir = $p_url.'&part=editperiod&tab=period&tab=period&id=%s&msg='.$action; |
---|
17 | |
---|
18 | $period_title = isset($_POST['period_title']) ? $_POST['period_title'] : __('One post per day'); |
---|
19 | $period_pub_nb = isset($_POST['period_pub_nb']) ? abs((integer) $_POST['period_pub_nb']) : 1; |
---|
20 | $period_pub_int = isset($_POST['period_pub_int']) ? (string) $_POST['period_pub_int'] : 'day'; |
---|
21 | $period_curdt = isset($_POST['period_curdt']) ? date('Y-m-d H:i:00',strtotime($_POST['period_curdt'])) : date('Y-m-d H:i:00',time()); |
---|
22 | $period_enddt = isset($_POST['period_enddt']) ? date('Y-m-d H:i:00',strtotime($_POST['period_enddt'])) : date('Y-m-d H:i:00',time()+31536000); //one year |
---|
23 | |
---|
24 | # Update period |
---|
25 | if ($action == 'createperiod' && !empty($_POST)) |
---|
26 | { |
---|
27 | try { |
---|
28 | $old_titles = $per->getPeriods(array('periodical_title'=>$period_title)); |
---|
29 | if (!$old_titles->isEmpty()) { |
---|
30 | throw New Exception(__('Period title is already taken')); |
---|
31 | } |
---|
32 | if (empty($period_title)) { |
---|
33 | throw New Exception(__('Period title is required')); |
---|
34 | } |
---|
35 | if (strtotime($period_strdt) > strtotime($period_enddt)) { |
---|
36 | throw New Exception(__('Start date must be older than end date')); |
---|
37 | } |
---|
38 | |
---|
39 | $cur = $per->openCursor(); |
---|
40 | $cur->periodical_title = $period_title; |
---|
41 | $cur->periodical_curdt = $period_curdt; |
---|
42 | $cur->periodical_enddt = $period_enddt; |
---|
43 | $cur->periodical_pub_int = $period_pub_int; |
---|
44 | $cur->periodical_pub_nb = $period_pub_nb; |
---|
45 | $period_id = $per->addPeriod($cur); |
---|
46 | |
---|
47 | http::redirect(sprintf($action_redir,$period_id)); |
---|
48 | } |
---|
49 | catch (Exception $e) { |
---|
50 | $core->error->add($e->getMessage()); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | # Display |
---|
55 | echo ' |
---|
56 | <html><head><title>'.__('Periodical').'</title>'. |
---|
57 | dcPage::jsDatePicker(). |
---|
58 | dcPage::jsLoad('index.php?pf=periodical/js/period.js'). |
---|
59 | '</head> |
---|
60 | <body> |
---|
61 | <h2>'. |
---|
62 | html::escapeHTML($core->blog->name). |
---|
63 | ' › <a href="'.$p_url.'&part=periods">'.__('Periodical').'</a>'. |
---|
64 | ' › '.__('New period'). |
---|
65 | '</h2>'.$msg; |
---|
66 | |
---|
67 | # Period |
---|
68 | echo ' |
---|
69 | <form method="post" action="plugin.php"> |
---|
70 | <p><label>'.__('Title:'). |
---|
71 | form::field('period_title',60,255,html::escapeHTML($period_title),'maximal',3).'</label></p> |
---|
72 | <div class="two-cols"> |
---|
73 | <div class="col"> |
---|
74 | <p><label>'.__('Next update:'). |
---|
75 | form::field('period_curdt',16,16,date('Y-m-d H:i',strtotime($period_curdt)),'',3).'</label></p> |
---|
76 | <p><label>'.__('End date:'). |
---|
77 | form::field('period_enddt',16,16,date('Y-m-d H:i',strtotime($period_enddt)),'',3).'</label></p> |
---|
78 | </div><div class="col"> |
---|
79 | <p><label>'.__('Publication frequency:'). |
---|
80 | form::combo('period_pub_int',$per->getTimesCombo(),$period_pub_int,'',3).'</label></p> |
---|
81 | <p><label>'.__('Number of entries to publish every time:'). |
---|
82 | form::field('period_pub_nb',10,3,html::escapeHTML($period_pub_nb),'',3).'</label></p> |
---|
83 | </div></div> |
---|
84 | <div class="clear"> |
---|
85 | <p><input type="submit" name="save" value="'.__('save').'" />'. |
---|
86 | $core->formNonce(). |
---|
87 | form::hidden(array('action'),'createperiod'). |
---|
88 | form::hidden(array('id'),$period_id). |
---|
89 | form::hidden(array('p'),'periodical'). |
---|
90 | form::hidden(array('part'),'addperiod').' |
---|
91 | </p> |
---|
92 | </div> |
---|
93 | </form>'; |
---|
94 | ?> |
---|