| 1 | <?php |
|---|
| 2 | // $Id: main.php,v 1.4 2005/08/03 12:39:17 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: Kazumi Ono (AKA onokazu) // |
|---|
| 28 | // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
|---|
| 29 | // Project: The XOOPS Project // |
|---|
| 30 | // ------------------------------------------------------------------------- // |
|---|
| 31 | |
|---|
| 32 | if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|---|
| 33 | exit("Access Denied"); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | include_once XOOPS_ROOT_PATH."/modules/system/admin/smilies/smilies.php"; |
|---|
| 37 | $op ='SmilesAdmin'; |
|---|
| 38 | |
|---|
| 39 | if (!empty($_GET['op'])) { |
|---|
| 40 | $op = $_GET['op']; |
|---|
| 41 | } elseif (!empty($_POST['op'])) { |
|---|
| 42 | $op = $_POST['op']; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | switch($op) { |
|---|
| 46 | |
|---|
| 47 | case "SmilesUpdate": |
|---|
| 48 | if (!XoopsMultiTokenHandler::quickValidate('smilies_SmilesUpdate')) { |
|---|
| 49 | redirect_header('admin.php?fct=smilies',3,"Ticket Error"); |
|---|
| 50 | } |
|---|
| 51 | $count = (!empty($_POST['smile_id']) && is_array($_POST['smile_id'])) ? count($_POST['smile_id']) : 0; |
|---|
| 52 | $db =& Database::getInstance(); |
|---|
| 53 | for ($i = 0; $i < $count; $i++) { |
|---|
| 54 | $smile_id = intval($_POST['smile_id'][$i]); |
|---|
| 55 | if (empty($smile_id)) { |
|---|
| 56 | continue; |
|---|
| 57 | } |
|---|
| 58 | $smile_display = empty($_POST['smile_display'][$i]) ? 0 : 1; |
|---|
| 59 | if (isset($_POST['old_display'][$i]) && $_POST['old_display'][$i] != $smile_display[$i]) { |
|---|
| 60 | $db->query('UPDATE '.$db->prefix('smiles').' SET display='.$smile_display.' WHERE id ='.$smile_id); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | redirect_header('admin.php?fct=smilies',2,_AM_DBUPDATED); |
|---|
| 64 | break; |
|---|
| 65 | |
|---|
| 66 | case "SmilesAdd": |
|---|
| 67 | if (!XoopsMultiTokenHandler::quickValidate('smilies_SmilesAdd')) { |
|---|
| 68 | redirect_header('admin.php?fct=smilies',3,"Ticket Error"); |
|---|
| 69 | } |
|---|
| 70 | $db =& Database::getInstance(); |
|---|
| 71 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 72 | include_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|---|
| 73 | $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'), 100000, 120, 120); |
|---|
| 74 | $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); |
|---|
| 75 | $uploader->setPrefix('smil'); |
|---|
| 76 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
|---|
| 77 | if (!$uploader->upload()) { |
|---|
| 78 | $err = $uploader->getErrors(); |
|---|
| 79 | } else { |
|---|
| 80 | $smile_url = $uploader->getSavedFileName(); |
|---|
| 81 | $smile_code = $myts->stripSlashesGPC($_POST['smile_code']); |
|---|
| 82 | $smile_desc = $myts->stripSlashesGPC($_POST['smile_desc']); |
|---|
| 83 | $smile_display = intval($_POST['smile_display']) > 0 ? 1 : 0; |
|---|
| 84 | $newid = $db->genId($db->prefix('smilies')."_id_seq"); |
|---|
| 85 | $sql = sprintf("INSERT INTO %s (id, code, smile_url, emotion, display) VALUES (%d, %s, %s, %s, %d)", $db->prefix('smiles'), $newid, $db->quoteString($smile_code), $db->quoteString($smile_url), $db->quoteString($smile_desc), $smile_display); |
|---|
| 86 | if (!$db->query($sql)) { |
|---|
| 87 | $err = 'Failed storing smiley data into the database'; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | } else { |
|---|
| 91 | $err = $uploader->getErrors(); |
|---|
| 92 | } |
|---|
| 93 | if (!isset($err)) { |
|---|
| 94 | redirect_header('admin.php?fct=smilies&op=SmilesAdmin',2,_AM_DBUPDATED); |
|---|
| 95 | } else { |
|---|
| 96 | xoops_cp_header(); |
|---|
| 97 | xoops_error($err); |
|---|
| 98 | xoops_cp_footer(); |
|---|
| 99 | } |
|---|
| 100 | break; |
|---|
| 101 | |
|---|
| 102 | case "SmilesEdit": |
|---|
| 103 | $id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
|---|
| 104 | if ($id > 0) { |
|---|
| 105 | SmilesEdit($id); |
|---|
| 106 | } |
|---|
| 107 | break; |
|---|
| 108 | |
|---|
| 109 | case "SmilesSave": |
|---|
| 110 | $id = isset($_POST['id']) ? intval($_POST['id']) : 0; |
|---|
| 111 | if ($id <= 0 || !XoopsMultiTokenHandler::quickValidate('smilies_SmilesSave')) { |
|---|
| 112 | redirect_header('admin.php?fct=smilies',3,"Ticket Error"); |
|---|
| 113 | } |
|---|
| 114 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 115 | $smile_code = $myts->stripSlashesGPC($_POST['smile_code']); |
|---|
| 116 | $smile_desc = $myts->stripSlashesGPC($_POST['smile_desc']); |
|---|
| 117 | $smile_display = intval($_POST['smile_display']) > 0 ? 1 : 0; |
|---|
| 118 | $db =& Database::getInstance(); |
|---|
| 119 | if (!empty($_POST['smile_url'])) { |
|---|
| 120 | include_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|---|
| 121 | $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'), 100000, 120, 120); |
|---|
| 122 | $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); |
|---|
| 123 | $uploader->setPrefix('smil'); |
|---|
| 124 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
|---|
| 125 | if (!$uploader->upload()) { |
|---|
| 126 | $err = $uploader->getErrors(); |
|---|
| 127 | } else { |
|---|
| 128 | $smile_url = $uploader->getSavedFileName(); |
|---|
| 129 | if (!$db->query(sprintf("UPDATE %s SET code = %s, smile_url = %s, emotion = %s, display = %d WHERE id = %d", $db->prefix('smiles'), $db->quoteString($smile_code), $db->quoteString($smile_url), $db->quoteString($smile_desc), $smile_display, $id))) { |
|---|
| 130 | $err = 'Failed storing smiley data into the database'; |
|---|
| 131 | } else { |
|---|
| 132 | $oldsmile_path = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.trim($_POST['old_smile']))); |
|---|
| 133 | if (0 === strpos($oldsmile_path, XOOPS_UPLOAD_PATH) && is_file($oldsmile_path)) { |
|---|
| 134 | unlink($oldsmile_path); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } else { |
|---|
| 139 | $err = $uploader->getErrors(); |
|---|
| 140 | } |
|---|
| 141 | } else { |
|---|
| 142 | $sql = sprintf("UPDATE %s SET code = %s, emotion = %s, display = %d WHERE id = %d", $db->prefix('smiles'), $db->quoteString($smile_code), $db->quoteString($smile_desc), $smile_display, $id); |
|---|
| 143 | if (!$db->query($sql)) { |
|---|
| 144 | $err = 'Failed storing smiley data into the database'; |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | if (!isset($err)) { |
|---|
| 148 | redirect_header('admin.php?fct=smilies&op=SmilesAdmin',2,_AM_DBUPDATED); |
|---|
| 149 | } else { |
|---|
| 150 | xoops_cp_header(); |
|---|
| 151 | xoops_error($err); |
|---|
| 152 | xoops_cp_footer(); |
|---|
| 153 | exit(); |
|---|
| 154 | } |
|---|
| 155 | break; |
|---|
| 156 | |
|---|
| 157 | case "SmilesDel": |
|---|
| 158 | $id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
|---|
| 159 | if ($id > 0 ) { |
|---|
| 160 | xoops_cp_header(); |
|---|
| 161 | xoops_token_confirm(array('fct' => 'smilies', 'op' => 'SmilesDelOk', 'id' => $id), 'admin.php', _AM_WAYSYWTDTS); |
|---|
| 162 | xoops_cp_footer(); |
|---|
| 163 | } |
|---|
| 164 | break; |
|---|
| 165 | |
|---|
| 166 | case "SmilesDelOk": |
|---|
| 167 | $id = isset($_POST['id']) ? intval($_POST['id']) : 0; |
|---|
| 168 | if ($id <= 0 || !xoops_confirm_validate()) { |
|---|
| 169 | redirect_header('admin.php?fct=smilies',3,"Ticket Error"); |
|---|
| 170 | } |
|---|
| 171 | $db =& Database::getInstance(); |
|---|
| 172 | $sql = sprintf("DELETE FROM %s WHERE id = %u", $db->prefix('smiles'), $id); |
|---|
| 173 | $db->query($sql); |
|---|
| 174 | redirect_header("admin.php?fct=smilies&op=SmilesAdmin",2,_AM_DBUPDATED); |
|---|
| 175 | break; |
|---|
| 176 | |
|---|
| 177 | case "SmilesAdmin": |
|---|
| 178 | default: |
|---|
| 179 | SmilesAdmin(); |
|---|
| 180 | break; |
|---|
| 181 | } |
|---|
| 182 | ?> |
|---|