source: temp/test-xoops.ec-cube.net/html/modules/xoopsheadline/admin/index.php @ 405

Revision 405, 16.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: index.php,v 1.4 2005/08/03 12:40:01 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27include '../../../include/cp_header.php';
28include XOOPS_ROOT_PATH.'/modules/xoopsheadline/include/functions.php';
29$op = 'list';
30
31if (!empty($_GET['op']) && ($_GET['op'] == 'delete' || $_GET['op'] == 'edit')) {
32    $op = $_GET['op'];
33    $headline_id = intval($_GET['headline_id']);
34} elseif (!empty($_POST['op'])) {
35    $op = $_POST['op'];
36}
37
38if ($op == 'list') {
39    include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
40    $hlman =& xoops_getmodulehandler('headline');;
41    $headlines =& $hlman->getObjects();
42    $count = count($headlines);
43    xoops_cp_header();
44    echo "<h4>"._AM_HEADLINES."</h4>";
45    echo '<form name="xoopsheadline_form" action="index.php" method="post"><table><tr><td>'._AM_SITENAME.'</td><td>'._AM_CACHETIME.'</td><td>'._AM_ENCODING.'</td><td>'._AM_DISPLAY.'</td><td>'._AM_ASBLOCK.'</td><td>'._AM_ORDER.'</td><td>&nbsp;</td></tr>';
46    for ($i = 0; $i < $count; $i++) {
47        echo '<tr><td>'.$headlines[$i]->getVar('headline_name').'</td>
48        <td><select name="headline_cachetime[]">';
49        $cachetime = array('3600' => sprintf(_HOUR, 1), '18000' => sprintf(_HOURS, 5), '86400' => sprintf(_DAY, 1), '259200' => sprintf(_DAYS, 3), '604800' => sprintf(_WEEK, 1), '2592000' => sprintf(_MONTH, 1));
50        foreach ($cachetime as $value => $name) {
51            echo '<option value="'.$value.'"';
52            if ($value == $headlines[$i]->getVar('headline_cachetime')) {
53                echo ' selected="selecetd"';
54            }
55            echo '>'.$name.'</option>';
56        }
57        echo '</select></td>
58        <td><select name="headline_encoding[]">';
59        $encodings = array('utf-8' => 'UTF-8', 'iso-8859-1' => 'ISO-8859-1', 'us-ascii' => 'US-ASCII');
60        foreach ($encodings as $value => $name) {
61            echo '<option value="'.$value.'"';
62            if ($value == $headlines[$i]->getVar('headline_encoding')) {
63                echo ' selected="selecetd"';
64            }
65            echo '>'.$name.'</option>';
66        }
67        echo '</select></td>';
68        echo '<td><input type="checkbox" value="1" name="headline_display['.$headlines[$i]->getVar('headline_id').']"';
69        if (1 == $headlines[$i]->getVar('headline_display')) {
70            echo ' checked="checked"';
71        }
72        echo ' /></td>';
73        echo '<td><input type="checkbox" value="1" name="headline_asblock['.$headlines[$i]->getVar('headline_id').']"';
74        if (1 == $headlines[$i]->getVar('headline_asblock')) {
75            echo ' checked="checked"';
76        }
77        echo ' /></td>';
78        echo '<td><input type="text" maxlength="3" size="4" name="headline_weight[]" value="'.$headlines[$i]->getVar('headline_weight').'" /><td><a href="index.php?op=edit&amp;headline_id='.$headlines[$i]->getVar('headline_id').'">'._EDIT.'</a>&nbsp;<a href="index.php?op=delete&amp;headline_id='.$headlines[$i]->getVar('headline_id').'">'._DELETE.'</a><input type="hidden" name="headline_id[]" value="'.$headlines[$i]->getVar('headline_id').'" /></td></tr>';
79    }
80    echo '</table><div style="text-align:center"><input type="hidden" name="op" value="update" /><input type="submit" name="headline_submit" value="'._SUBMIT.'" /></div></form>';
81    $form = new XoopsThemeForm(_AM_ADDHEADL, 'xoopsheadline_form_new', 'index.php');
82    $form->addElement(new XoopsFormText(_AM_SITENAME, 'headline_name', 50, 255), true);
83    $form->addElement(new XoopsFormText(_AM_URL, 'headline_url', 50, 255, 'http://'), true);
84    $form->addElement(new XoopsFormText(_AM_URLEDFXML, 'headline_rssurl', 50, 255, 'http://'), true);
85    $form->addElement(new XoopsFormText(_AM_ORDER, 'headline_weight', 4, 3, 0));    $enc_sel = new XoopsFormSelect(_AM_ENCODING, 'headline_encoding', 'utf-8');
86    $enc_sel->addOptionArray(array('utf-8' => 'UTF-8', 'iso-8859-1' => 'ISO-8859-1', 'us-ascii' => 'US-ASCII'));
87    $form->addElement($enc_sel);
88    $cache_sel = new XoopsFormSelect(_AM_CACHETIME, 'headline_cachetime', 86400);
89    $cache_sel->addOptionArray(array('3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH));
90    $form->addElement($cache_sel);
91
92    $form->insertBreak(_AM_MAINSETT);
93    $form->addElement(new XoopsFormRadioYN(_AM_DISPLAY, 'headline_display', 1, _YES, _NO));
94    $form->addElement(new XoopsFormRadioYN(_AM_DISPIMG, 'headline_mainimg', 0, _YES, _NO));
95    $form->addElement(new XoopsFormRadioYN(_AM_DISPFULL, 'headline_mainfull', 0, _YES, _NO));
96    $mmax_sel = new XoopsFormSelect(_AM_DISPMAX, 'headline_mainmax', 10);
97    $mmax_sel->addOptionArray(array('1' => 1, '5' => 5, '10' => 10, '15' => 15, '20' => 20, '25' => 25, '30' => 30));
98    $form->addElement($mmax_sel);
99
100    $form->insertBreak(_AM_BLOCKSETT);
101    $form->addElement(new XoopsFormRadioYN(_AM_ASBLOCK, 'headline_asblock', 1, _YES, _NO));
102    $form->addElement(new XoopsFormRadioYN(_AM_DISPIMG, 'headline_blockimg', 0, _YES, _NO));
103    $bmax_sel = new XoopsFormSelect(_AM_DISPMAX, 'headline_blockmax', 5);
104    $bmax_sel->addOptionArray(array('1' => 1, '5' => 5, '10' => 10, '15' => 15, '20' => 20, '25' => 25, '30' => 30));
105    $form->addElement($bmax_sel);
106
107
108    $form->insertBreak();
109    $form->addElement(new XoopsFormHidden('op', 'addgo'));
110    $form->addElement(new XoopsFormButton('', 'headline_submit2', _SUBMIT, 'submit'));
111    $form->display();
112    xoops_cp_footer();
113    exit();
114}
115
116if ($op == 'update') {
117    $hlman =& xoops_getmodulehandler('headline');;
118    $i = 0;
119    $msg = '';
120    foreach ($_POST['headline_id'] as $id) {
121        $hl =& $hlman->get($id);
122        if (!is_object($hl)) {
123            $i++;
124            continue;
125        }
126        $headline_display[$id] = empty($_POST['headline_display'][$id]) ? 0 : $_POST['headline_display'][$id];
127        $headline_asblock[$id] = empty($_POST['headline_asblock'][$id]) ? 0 : $_POST['headline_asblock'][$id];
128        $old_cachetime = $hl->getVar('headline_cachetime');
129        $hl->setVar('headline_cachetime', $_POST['headline_cachetime'][$i]);
130        $old_display = $hl->getVar('headline_display');
131        $hl->setVar('headline_display', $headline_display[$id]);
132        $hl->setVar('headline_weight', $_POST['headline_weight'][$i]);
133        $old_asblock = $hl->getVar('headline_asblock');
134        $hl->setVar('headline_asblock', $headline_asblock[$id]);
135        $old_encoding = $hl->getVar('headline_encoding');
136        if (!$hlman->insert($hl)) {
137            $msg .= '<br />'.sprintf(_AM_FAILUPDATE, $hl->getVar('headline_name'));
138        } else {
139            if ($hl->getVar('headline_xml') == '') {
140                $renderer =& xoopsheadline_getrenderer($hl);
141                $renderer->updateCache();
142            }
143        }
144        $i++;
145    }
146    if ($msg != '') {
147        xoops_cp_header();
148        echo "<h4>"._AM_HEADLINES."</h4>";
149        xoops_error($msg);
150        xoops_cp_footer();
151        exit();
152    }
153    redirect_header('index.php', 2, _AM_DBUPDATED);
154}
155
156if ($op == 'addgo') {
157    $hlman =& xoops_getmodulehandler('headline');;
158    $hl =& $hlman->create();
159    $hl->setVar('headline_name', $_POST['headline_name']);
160    $hl->setVar('headline_url', $_POST['headline_url']);
161    $hl->setVar('headline_rssurl', $_POST['headline_rssurl']);
162    $hl->setVar('headline_display', $_POST['headline_display']);
163    $hl->setVar('headline_weight', $_POST['headline_weight']);
164    $hl->setVar('headline_asblock', $_POST['headline_asblock']);
165    $hl->setVar('headline_encoding', $_POST['headline_encoding']);
166    $hl->setVar('headline_cachetime', $_POST['headline_cachetime']);
167    $hl->setVar('headline_mainfull', $_POST['headline_mainfull']);
168    $hl->setVar('headline_mainimg', $_POST['headline_mainimg']);
169    $hl->setVar('headline_mainmax', $_POST['headline_mainmax']);
170    $hl->setVar('headline_blockimg', $_POST['headline_blockimg']);
171    $hl->setVar('headline_blockmax', $_POST['headline_blockmax']);
172    if (!$hlman->insert($hl)) {
173        $msg = sprintf(_AM_FAILUPDATE, $hl->getVar('headline_name'));
174        $msg .= '<br />'.$hl->getErrors();
175        xoops_cp_header();
176        echo "<h4>"._AM_HEADLINES."</h4>";
177        xoops_error($msg);
178        xoops_cp_footer();
179        exit();
180    } else {
181        if ($hl->getVar('headline_xml') == '') {
182            $renderer =& xoopsheadline_getrenderer($hl);
183            $renderer->updateCache();
184        }
185    }
186    redirect_header('index.php', 2, _AM_DBUPDATED);
187}
188
189if ($op == 'edit') {
190
191    if ($headline_id <= 0) {
192        xoops_cp_header();
193        echo "<h4>"._AM_HEADLINES."</h4>";
194        xoops_error(_AM_INVALIDID);
195        xoops_cp_footer();
196        exit();
197    }
198    $hlman =& xoops_getmodulehandler('headline');;
199    $hl =& $hlman->get($headline_id);
200    if (!is_object($hl)) {
201        xoops_cp_header();
202        echo "<h4>"._AM_HEADLINES."</h4>";
203        xoops_error(_AM_OBJECTNG);
204        xoops_cp_footer();
205        exit();
206    }
207    include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
208    $form = new XoopsThemeForm(_AM_EDITHEADL, 'xoopsheadline_form', 'index.php');
209    $form->addElement(new XoopsFormText(_AM_SITENAME, 'headline_name', 50, 255, $hl->getVar('headline_name')), true);
210    $form->addElement(new XoopsFormText(_AM_URL, 'headline_url', 50, 255, $hl->getVar('headline_url')), true);
211    $form->addElement(new XoopsFormText(_AM_URLEDFXML, 'headline_rssurl', 50, 255, $hl->getVar('headline_rssurl')), true);
212    $form->addElement(new XoopsFormText(_AM_ORDER, 'headline_weight', 4, 3, $hl->getVar('headline_weight')));
213    $enc_sel = new XoopsFormSelect(_AM_ENCODING, 'headline_encoding', $hl->getVar('headline_encoding'));
214    $enc_sel->addOptionArray(array('utf-8' => 'UTF-8', 'iso-8859-1' => 'ISO-8859-1', 'us-ascii' => 'US-ASCII'));
215    $form->addElement($enc_sel);
216    $cache_sel = new XoopsFormSelect(_AM_CACHETIME, 'headline_cachetime', $hl->getVar('headline_cachetime'));
217    $cache_sel->addOptionArray(array('3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH));
218    $form->addElement($cache_sel);
219
220    $form->insertBreak(_AM_MAINSETT);
221    $form->addElement(new XoopsFormRadioYN(_AM_DISPLAY, 'headline_display', $hl->getVar('headline_display'), _YES, _NO));
222    $form->addElement(new XoopsFormRadioYN(_AM_DISPIMG, 'headline_mainimg', $hl->getVar('headline_mainimg'), _YES, _NO));
223    $form->addElement(new XoopsFormRadioYN(_AM_DISPFULL, 'headline_mainfull', $hl->getVar('headline_mainfull'), _YES, _NO));
224    $mmax_sel = new XoopsFormSelect(_AM_DISPMAX, 'headline_mainmax', $hl->getVar('headline_mainmax'));
225    $mmax_sel->addOptionArray(array('1' => 1, '5' => 5, '10' => 10, '15' => 15, '20' => 20, '25' => 25, '30' => 30));
226    $form->addElement($mmax_sel);
227
228    $form->insertBreak(_AM_BLOCKSETT);
229    $form->addElement(new XoopsFormRadioYN(_AM_ASBLOCK, 'headline_asblock', $hl->getVar('headline_asblock'), _YES, _NO));
230    $form->addElement(new XoopsFormRadioYN(_AM_DISPIMG, 'headline_blockimg', $hl->getVar('headline_blockimg'), _YES, _NO));
231    $bmax_sel = new XoopsFormSelect(_AM_DISPMAX, 'headline_blockmax', $hl->getVar('headline_blockmax'));
232    $bmax_sel->addOptionArray(array('1' => 1, '5' => 5, '10' => 10, '15' => 15, '20' => 20, '25' => 25, '30' => 30));
233    $form->addElement($bmax_sel);
234    $form->insertBreak();
235    $form->addElement(new XoopsFormHidden('headline_id', $hl->getVar('headline_id')));
236    $form->addElement(new XoopsFormHidden('op', 'editgo'));
237    $form->addElement(new XoopsFormButton('', 'headline_submit', _SUBMIT, 'submit'));
238    xoops_cp_header();
239    echo "<h4>"._AM_HEADLINES."</h4><br />";
240    //echo '<a href="index.php">'. _AM_HLMAIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$hl->getVar('headline_name').'<br /><br />';
241    $form->display();
242    xoops_cp_footer();
243    exit();
244}
245
246if ($op == 'editgo') {
247    $headline_id = !empty($_POST['headline_id']) ? intval($_POST['headline_id']) : 0;
248    if ($headline_id <= 0) {
249        xoops_cp_header();
250        echo "<h4>"._AM_HEADLINES."</h4>";
251        xoops_error(_AM_INVALIDID);
252        xoops_cp_footer();
253        exit();
254    }
255    $hlman =& xoops_getmodulehandler('headline');;
256    $hl =& $hlman->get($headline_id);
257    if (!is_object($hl)) {
258        xoops_cp_header();
259        echo "<h4>"._AM_HEADLINES."</h4>";
260        xoops_error(_AM_OBJECTNG);
261        xoops_cp_footer();
262        exit();
263    }
264    $hl->setVar('headline_name', $_POST['headline_name']);
265    $hl->setVar('headline_url', $_POST['headline_url']);
266    $hl->setVar('headline_encoding', $_POST['headline_encoding']);
267    $hl->setVar('headline_rssurl', $_POST['headline_rssurl']);
268    $hl->setVar('headline_display', $_POST['headline_display']);
269    $hl->setVar('headline_weight', $_POST['headline_weight']);
270    $hl->setVar('headline_asblock', $_POST['headline_asblock']);
271    $hl->setVar('headline_cachetime', $_POST['headline_cachetime']);
272    $hl->setVar('headline_mainfull', $_POST['headline_mainfull']);
273    $hl->setVar('headline_mainimg', $_POST['headline_mainimg']);
274    $hl->setVar('headline_mainmax', $_POST['headline_mainmax']);
275    $hl->setVar('headline_blockimg', $_POST['headline_blockimg']);
276    $hl->setVar('headline_blockmax', $_POST['headline_blockmax']);
277
278    if (!$res = $hlman->insert($hl)) {
279        $msg = sprintf(_AM_FAILUPDATE, $hl->getVar('headline_name'));
280        $msg .= '<br />'.$hl->getHtmlErrors();
281        xoops_cp_header();
282        echo "<h4>"._AM_HEADLINES."</h4>";
283        xoops_error($msg);
284        xoops_cp_footer();
285        exit();
286    } else {
287        if ($hl->getVar('headline_xml') == '') {
288            $renderer =& xoopsheadline_getrenderer($hl);
289            $renderer->updateCache();
290        }
291    }
292    redirect_header('index.php', 2, _AM_DBUPDATED);
293}
294
295if ($op == 'delete') {
296    if ($headline_id <= 0) {
297        xoops_cp_header();
298        echo "<h4>"._AM_HEADLINES."</h4>";
299        xoops_error(_AM_INVALIDID);
300        xoops_cp_footer();
301        exit();
302    }
303    $hlman =& xoops_getmodulehandler('headline');;
304    $hl =& $hlman->get($headline_id);
305    if (!is_object($hl)) {
306        xoops_cp_header();
307        echo "<h4>"._AM_HEADLINES."</h4>";
308        xoops_error(_AM_OBJECTNG);
309        xoops_cp_footer();
310        exit();
311    }
312    xoops_cp_header();
313    $name = $hl->getVar('headline_name');
314    echo "<h4>"._AM_HEADLINES."</h4>";
315    xoops_confirm(array('op' => 'deletego', 'headline_id' => $hl->getVar('headline_id')), 'index.php', sprintf(_AM_WANTDEL, $name));
316    xoops_cp_footer();
317    exit();
318}
319
320if ($op == 'deletego') {
321    $headline_id = !empty($_POST['headline_id']) ? intval($_POST['headline_id']) : 0;
322    if ($headline_id <= 0) {
323        xoops_cp_header();
324        echo "<h4>"._AM_HEADLINES."</h4>";
325        xoops_error(_AM_INVALIDID);
326        xoops_cp_footer();
327        exit();
328    }
329    $hlman =& xoops_getmodulehandler('headline');;
330    $hl =& $hlman->get($headline_id);
331    if (!is_object($hl)) {
332        xoops_cp_header();
333        echo "<h4>"._AM_HEADLINES."</h4>";
334        xoops_error(_AM_OBJECTNG);
335        xoops_cp_footer();
336        exit();
337    }
338    if (!$hlman->delete($hl)) {
339        xoops_cp_header();
340        echo "<h4>"._AM_HEADLINES."</h4>";
341        xoops_error(sprintf(_AM_FAILDELETE, $hl->getVar('headline_name')));
342        xoops_cp_footer();
343        exit();
344    }
345    redirect_header('index.php', 2, _AM_DBUPDATED);
346}
347
348?>
Note: See TracBrowser for help on using the repository browser.