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

Revision 405, 13.0 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: index.php,v 1.4 2005/08/03 12:40:02 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//  ------------------------------------------------------------------------ //
27// Author: Raul Recio (AKA UNFOR)                                            //
28// Project: The XOOPS Project                                                //
29// ------------------------------------------------------------------------- //
30
31include '../../../include/cp_header.php';
32
33function partnersAdmin()
34{
35    $xoopsDB =& Database::getInstance();
36    $myts =& MyTextSanitizer::getInstance();
37    xoops_cp_header();
38    echo "<h4>"._MD_PARTNERADMIN."</h4>
39    <form action='index.php' method='post' name='reorderform'>
40    <table width='100%' border='0' cellspacing='1' cellpadding='0' class='outer'><tr>
41    <th width='10%' align='center'>" ._MD_TITLE."</th>
42    <th width='3%' align='center'>" ._MD_IMAGE."</th>
43    <th>" ._MD_DESCRIPTION."</th>
44    <th width='3%' align='center'>" ._MD_ACTIVE."</th>
45    <th width='3%' align='center'>" ._MD_WEIGHT."</th>
46    <th width='3%' align='center'>" ._MD_HITS."</th>
47    <th>&nbsp;</th></tr>";
48    $result = $xoopsDB->query("SELECT id, hits, url, weight, image, title, description, status FROM ".$xoopsDB->prefix("partners")." ORDER BY status DESC, weight ASC, title DESC");
49    $class = 'even';
50    while (list($id, $hits, $url, $weight, $image, $title, $description, $status) = $xoopsDB->fetchrow($result)) {
51        $url          = formatURL($myts->makeTboxData4Show($url));
52        $image        = formatURL($myts->makeTboxData4Show($image));
53        $title        = $myts->makeTboxData4Show($title);
54        $description  = $myts->makeTboxData4Show($description);
55        $imageInfo    = @getimagesize($image);
56        $imageWidth   = $imageInfo[0];
57        $imageHeight  = $imageInfo[1];
58        $check1 = "";
59        $check2 = "";
60        if( $status == 1){ $check1 = "selected='selected'"; }else{ $check2 = "selected='selected'"; }
61        if( $imageWidth >= 110 or $imageHeight >= 50 ){
62            $errorMsg = "<br />"._MD_IMAGE_ERROR;
63        } else {
64            $errorMsg = "";
65        }
66        echo "<tr>
67        <td class='$class' width='10%' align='center' valign='middle'><a href='".$url."' target='_blank'>".$title."</a></td>
68        <td class='$class' width='3%' align='center'>";
69        if ( !empty($image) ) {
70            echo "<img src='".$image."' alt='".$title."' width='102' height='47' />".$errorMsg;
71        }
72        echo "</td><td class='$class'>".$description."</td>
73        <td class='$class' width='3%' align='center'>
74        <select size='1' name='status[$id]'> <option value='1' ".$check1.">"._MD_YES."</option><option value='0' ".$check2.">"._MD_NO."</option></select>
75        <td class='$class' width='3%' align='center'>";
76        echo "<input type='text' name='weight[$id]' value='$weight' size='3' maxlength='3' style='text-align: center;' />";
77        echo "</td><td class='$class' width='3%' align='center'>".$hits."</td>
78        <td class='$class' width='3%' align='center'>
79        <a href='index.php?op=editPartner&amp;id=".$id."'>"._MD_EDIT."</a><br />--<br /><a href='index.php?op=delPartner&amp;id=".$id."'>"._MD_DELETE."</a>
80        </td></tr>";
81        $class = ($class == 'odd') ? 'even' : 'odd';
82    }
83    echo "<tr><td class='foot' colspan='7' align='right'>
84    <input type='hidden' name='op' value='reorderPartners' />
85    <input type='button' name='button' onclick=\"location='index.php?op=partnersAdminAdd'\" value='"._MD_PARTNERS_ADD."' />
86    <input type='button' name='button' onclick=\"location='index.php?op=reorderAutoPartners'\" value='"._MD_AUTOMATIC_SORT."' />
87    <input type='submit' name='submit' value='"._MD_REORDER."' />
88    </td></tr></table></form>";
89    xoops_cp_footer();
90}
91
92function reorderAutoPartners()
93{
94    $xoopsDB =& Database::getInstance();
95    $weight = 0;
96    $result = $xoopsDB->query("SELECT id FROM ".$xoopsDB->prefix("partners")." ORDER BY weight ASC");
97    while (list($id) = $xoopsDB->fetchrow($result)) {
98        $weight++;
99        $xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("partners")." SET weight='$weight' WHERE id=$id");
100    }
101    redirect_header("./index.php", 1, _MD_UPDATED);
102    exit();
103}
104
105function partnersAdminAdd()
106{
107    $xoopsDB =& Database::getInstance();
108    $myts =& MyTextSanitizer::getInstance();
109    xoops_cp_header();
110    echo "<h4>"._MD_PARTNERADMIN."</h4>";
111    include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
112    $form       = new XoopsThemeForm(_MD_ADDPARTNER, "addform", "index.php");
113    $formweight = new XoopsFormText(_MD_WEIGHT, "weight", 3, 10, 0);
114    $formimage  = new XoopsFormText(_MD_IMAGE, "image", 50, 150, 'http://');
115    $formurl    = new XoopsFormText(_MD_URL, "url", 50, 150, 'http://');
116    $formtitle  = new XoopsFormText(_MD_TITLE, "title", 50, 50);
117    $formdesc   = new XoopsFormTextArea(_MD_DESCRIPTION, "description","", 10, "60");
118    $formstat   = new XoopsFormSelect(_MD_STATUS, "status");
119    $formstat->addOption("1", _MD_ACTIVE);
120    $formstat->addOption("0", _MD_INACTIVE);
121    $op_hidden  = new XoopsFormHidden("op", "addPartner");
122    $submit_button = new XoopsFormButton("", "submir", _MD_ADDPARTNER, "submit");
123    $form->addElement($formweight);
124    $form->addElement($formimage);
125    $form->addElement($formurl, true);
126    $form->addElement($formtitle, true);
127    $form->addElement($formdesc, true);
128    $form->addElement($formstat);
129    $form->addElement($op_hidden);
130    $form->addElement($submit_button);
131    $form->display();
132    xoops_cp_footer();
133}
134
135function editPartner($id)
136{
137    $xoopsDB =& Database::getInstance();
138    $myts =& MyTextSanitizer::getInstance();
139    xoops_cp_header();
140    echo "<h4>"._MD_PARTNERADMIN."</h4>";
141    $result = $xoopsDB->query("SELECT weight, hits, url, image, title, description, status FROM ".$xoopsDB->prefix("partners")." WHERE id=$id");
142    list($weight, $hits, $url, $image, $title, $description, $status) = $xoopsDB->fetchrow($result);
143    $url          = $myts->makeTboxData4Edit($url);
144    $image        = $myts->makeTboxData4Edit($image);
145    $title        = $myts->makeTboxData4Edit($title);
146    $description  = $myts->makeTboxData4Edit($description);
147    include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
148    $form         = new XoopsThemeForm(_MD_EDITPARTNER, "editform", "index.php");
149    $formweight   = new XoopsFormText(_MD_WEIGHT, "weight", 3, 10, $weight);
150    $formhits     = new XoopsFormText(_MD_HITS, "hits", 3, 10, $hits);
151    $formimage    = new XoopsFormText(_MD_IMAGE, "image", 50, 150, $image);
152    $formurl      = new XoopsFormText(_MD_URL, "url", 50, 150, $url);
153    $formtitle    = new XoopsFormText(_MD_TITLE, "title", 50, 50, $title);
154    $formdesc     = new XoopsFormTextArea(_MD_DESCRIPTION, "description", $description, 10, "100%");
155    $formstat     = new XoopsFormSelect(_MD_STATUS, "status", $status);
156    $formstat->addOption("1", _MD_ACTIVE);
157    $formstat->addOption("0", _MD_INACTIVE);
158    $id_hidden    = new XoopsFormHidden("id", $id);
159    $op_hidden    = new XoopsFormHidden("op", "updatePartner");
160    $submit_button = new XoopsFormButton("", "submit", _MD_EDITPARTNER, "submit");
161    $form->addElement($formweight);
162    $form->addElement($formhits);
163    $form->addElement($formimage);
164    $form->addElement($formurl, true);
165    $form->addElement($formtitle, true);
166    $form->addElement($formdesc, true);
167    $form->addElement($formstat);
168    $form->addElement($id_hidden);
169    $form->addElement($op_hidden);
170    $form->addElement($submit_button);
171    $form->display();
172    xoops_cp_footer();
173}
174
175$op = '';
176
177if (!empty($_GET['op'])) {
178    $op = $_GET['op'];
179    if (isset($_GET['id'])) {
180        $id = intval($_GET['id']);
181    }
182} elseif (!empty($_POST['op'])) {
183    $op = $_POST['op'];
184}
185switch ($op) {
186
187case "partnersAdminAdd":
188    partnersAdminAdd();
189    break;
190
191case "updatePartner":
192    $xoopsDB =& Database::getInstance();
193    $myts =& MyTextSanitizer::getInstance();
194    $title = isset($_POST['title']) ? trim($_POST['title']) : '';
195    $image = isset($_POST['image']) ? trim($_POST['image']) : '';
196    $url = isset($_POST['url']) ? trim($_POST['url']) : '';
197    $description = isset($_POST['description']) ? trim($_POST['description']) : '';
198    $id = intval($_POST['id']);
199    $status  = isset($_POST['status']) ? intval($_POST['status']) : 0;
200    if ($title == '' || $url == '' || empty($id) || $description == '') {
201        redirect_header("index.php?op=edit_partner&amp;id=$id", 1, _MD_BESURE);
202        exit();
203    }
204    $url          = $myts->makeTboxData4Save(formatURL($url));
205    $image        = $myts->makeTboxData4Save(formatURL($image));
206    $title        = $myts->makeTboxData4Save($title);
207    $description  = $myts->makeTboxData4Save($description);
208    if ($xoopsDB->query("UPDATE ".$xoopsDB->prefix("partners")." SET hits=".intval($_POST['hits']).", weight=".intval($_POST['weight']).", url='$url', image='$image', title='$title', description='$description', status=$status WHERE id=$id")) {
209        redirect_header("index.php", 1, _MD_UPDATED);
210    } else {
211        redirect_header("index.php", 1, _MD_NOTUPDATED);
212    }
213    break;
214
215case "addPartner":
216    $myts =& MyTextSanitizer::getInstance();
217    $title = isset($_POST['title']) ? trim($_POST['title']) : '';
218    $image = isset($_POST['image']) ? trim($_POST['image']) : '';
219    $url = isset($_POST['url']) ? trim($_POST['url']) : '';
220    $description = isset($_POST['description']) ? trim($_POST['description']) : '';
221    if ($title == '' || $url == '' || $description == '') {
222        redirect_header("index.php", 1, _MD_BESURE);
223        exit();
224    }
225    $url          = $myts->makeTboxData4Save(formatURL($url));
226    $image        = $myts->makeTboxData4Save(formatURL($image));
227    $title        = $myts->makeTboxData4Save($title);
228    $description  = $myts->makeTboxData4Save($description);
229    $status  = isset($_POST['status']) ? intval($_POST['status']) : 0;
230    $sql = "INSERT INTO ".$xoopsDB->prefix("partners")." VALUES (NULL, ".intval($_POST['weight']).", 0, '$url', '$image', '$title', '$description', $status)";
231    if ($xoopsDB->query($sql)) {
232        redirect_header("index.php", 1, _MD_UPDATED);
233    } else {
234        redirect_header("index.php", 1, _MD_NOTUPDATED);
235    }
236    exit();
237    break;
238
239case "delPartner":
240    xoops_cp_header();
241    echo "<h4>"._MD_PARTNERADMIN."</h4>";
242    xoops_confirm(array('op' => 'delPartnerOk', 'id' => $id), 'index.php', _MD_SUREDELETE);
243    xoops_cp_footer();
244    break;
245
246case "delPartnerOk":
247    $xoopsDB =& Database::getInstance();
248    $sql = sprintf("DELETE FROM %s WHERE id = %u", $xoopsDB->prefix("partners"), $_POST['id']);
249    if ( $xoopsDB->query($sql) ) {
250        redirect_header("index.php", 1, _MD_UPDATED);
251    } else {
252        redirect_header("index.php", 1, _MD_NOTUPDATED);
253    }
254    break;
255
256case "editPartner":
257    editPartner($id);
258    break;
259
260case "reorderPartners":
261    $xoopsDB =& Database::getInstance();
262    foreach ($_POST['weight'] as $id=>$order) {
263        if ( isset($id) && is_numeric($id) && isset($order) ) {
264        if ( !is_numeric($order) or empty($order)) { $order = 0; }
265            $xoopsDB->query("UPDATE ".$xoopsDB->prefix("partners")." SET weight='$order', status='".$_POST['status'][$id]."' WHERE id=$id");
266        }
267    }
268    redirect_header("./index.php", 1, _MD_UPDATED);
269    exit();
270    break;
271
272case "reorderAutoPartners":
273    reorderAutoPartners();
274    break;
275
276default:
277    partnersAdmin();
278    break;
279}
280?>
Note: See TracBrowser for help on using the repository browser.