home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / modules / system / admin / userrank / main.php < prev    next >
Encoding:
PHP Script  |  2008-01-13  |  8.0 KB  |  166 lines

  1. <?php
  2. // $Id: main.php 1248 2008-01-12 11:42:47Z dugris $
  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.  * Manage user rank.
  33.  * @copyright XOOPS Project
  34.  * @todo    Fix register_globals!
  35.  **/
  36.  
  37. if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
  38.     exit("Access Denied");
  39. }
  40.  
  41. $op = 'RankForumAdmin';
  42.  
  43. if (isset($_GET['op'])) {
  44.     $op = $_GET['op'];
  45. } elseif (isset($_POST['op'])) {
  46.     $op = $_POST['op'];
  47. }
  48.  
  49. switch ($op) {
  50.  
  51. case "RankForumEdit":
  52.     $rank_id = isset($_GET['rank_id']) ? intval($_GET['rank_id']) : 0;
  53.     if ($rank_id > 0) {
  54.         include_once XOOPS_ROOT_PATH."/modules/system/admin/userrank/userrank.php";
  55.         RankForumEdit($rank_id);
  56.     }
  57.     break;
  58.  
  59. case "RankForumDel":
  60.     $rank_id = isset($_GET['rank_id']) ? intval($_GET['rank_id']) : 0;
  61.     if ($rank_id > 0) {
  62.         xoops_cp_header();
  63.         xoops_confirm(array('fct' => 'userrank', 'op' => 'RankForumDelGo', 'rank_id' => $rank_id), 'admin.php', _AM_WAYSYWTDTR);
  64.         xoops_cp_footer();
  65.     }
  66.     break;
  67.  
  68. case "RankForumDelGo":
  69.     $rank_id = isset($_POST['rank_id']) ? intval($_POST['rank_id']) : 0;
  70.     if ($rank_id <= 0 | !$GLOBALS['xoopsSecurity']->check()) {
  71.         redirect_header("admin.php?fct=userrank", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  72.     }
  73.     $db =& Database::getInstance();
  74.     $sql = sprintf("DELETE FROM %s WHERE rank_id = %u", $db->prefix("ranks"), $rank_id);
  75.     $db->query($sql);
  76.     redirect_header("admin.php?fct=userrank&op=ForumAdmin",1,_AM_DBUPDATED);
  77.     break;
  78.  
  79. case "RankForumAdd":
  80.     if (!$GLOBALS['xoopsSecurity']->check()) {
  81.         redirect_header("admin.php?fct=userrank", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  82.     }
  83.     $db =& Database::getInstance();
  84.     $myts =& MyTextSanitizer::getInstance();
  85.     $rank_special = isset($_POST['rank_special']) && intval($_POST['rank_special']) ? 1 : 0;
  86.     $rank_title = $myts->stripSlashesGPC($_POST['rank_title']);
  87.     $rank_image = '';
  88.     include_once XOOPS_ROOT_PATH.'/class/uploader.php';
  89.     $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'), 100000, 120, 120);
  90.     $uploader->setPrefix('rank');
  91.     if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
  92.         if ($uploader->upload()) {
  93.             $rank_image = $uploader->getSavedFileName();
  94.         }
  95.     }
  96.     $newid = $db->genId($db->prefix("ranks")."_rank_id_seq");
  97.     if ($rank_special == 1) {
  98.         $sql = "INSERT INTO ".$db->prefix("ranks")." (rank_id, rank_title, rank_min, rank_max, rank_special, rank_image) VALUES ($newid, ".$db->quoteString($rank_title).", -1, -1, 1, ".$db->quoteString($rank_image).")";
  99.     } else {
  100.         $sql = "INSERT INTO ".$db->prefix("ranks")." (rank_id, rank_title, rank_min, rank_max, rank_special, rank_image) VALUES ($newid, ".$db->quoteString($rank_title).", ".intval($_POST['rank_min'])." , ".intval($_POST['rank_max'])." , 0, ".$db->quoteString($rank_image).")";
  101.     }
  102.     if (!$db->query($sql)) {
  103.         xoops_cp_header();
  104.         xoops_error('Failed storing rank data into the database');
  105.         xoops_cp_footer();
  106.     } else {
  107.         if ( $uploader->getErrors() ) {
  108.             redirect_header("admin.php?fct=userrank&op=RankForumAdmin",3, xoops_error($uploader->getErrors()) . _AM_DBUPDATED);
  109.         } else {
  110.             redirect_header("admin.php?fct=userrank&op=RankForumAdmin",3, _AM_DBUPDATED);
  111.         }
  112.     }
  113.     break;
  114.  
  115. case "RankForumSave":
  116.     $rank_id = isset($_POST['rank_id']) ? intval($_POST['rank_id']) : 0;
  117.     if ($rank_id <= 0 | !$GLOBALS['xoopsSecurity']->check()) {
  118.         redirect_header("admin.php?fct=userrank", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  119.     }
  120.     $db =& Database::getInstance();
  121.     $myts =& MyTextSanitizer::getInstance();
  122.     $rank_special = isset($_POST['rank_special']) && intval($_POST['rank_special']) ? 1 : 0;
  123.     $rank_title = $myts->stripSlashesGPC($_POST['rank_title']);
  124.     $delete_old_image = false;
  125.     include_once XOOPS_ROOT_PATH.'/class/uploader.php';
  126.     $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'), 100000, 120, 120);
  127.     $uploader->setPrefix('rank');
  128.     if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
  129.         if ($uploader->upload()) {
  130.             $rank_image = $uploader->getSavedFileName();
  131.             $delete_old_image = true;
  132.         }
  133.     }
  134.     if ($rank_special > 0) {
  135.         $_POST['rank_min'] = $_POST['rank_max'] = -1;
  136.     }
  137.     $sql = "UPDATE ".$db->prefix("ranks")." SET rank_title = ".$db->quoteString($rank_title).", rank_min = ".intval($_POST['rank_min']).", rank_max = ".intval($_POST['rank_max']).", rank_special = ".$rank_special;
  138.     if ($delete_old_image) {
  139.         $sql .= ", rank_image = ".$db->quoteString($rank_image);
  140.     }
  141.     $sql .= " WHERE rank_id = ".$rank_id;
  142.     if (!$db->query($sql)) {
  143.         xoops_cp_header();
  144.         xoops_error('Failed storing rank data into the database');
  145.         xoops_cp_footer();
  146.     } else {
  147.         if ($delete_old_image) {
  148.             $old_rank_path = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.trim($_POST['old_rank'])));
  149.             if (0 === strpos($old_rank_path, XOOPS_UPLOAD_PATH) && is_file($old_rank_path)) {
  150.                 unlink($old_rank_path);
  151.             }
  152.         }
  153.         if ( $uploader->getErrors() ) {
  154.             redirect_header("admin.php?fct=userrank&op=RankForumAdmin",3, xoops_error($uploader->getErrors()) . _AM_DBUPDATED);
  155.         } else {
  156.             redirect_header("admin.php?fct=userrank&op=RankForumAdmin",3, _AM_DBUPDATED);
  157.         }
  158.     }
  159.     break;
  160.  
  161. default:
  162.     include_once XOOPS_ROOT_PATH."/modules/system/admin/userrank/userrank.php";
  163.     RankForumAdmin();
  164.     break;
  165. }
  166. ?>