[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 ih_manager.php

Zen Cart 源代码 ih_manager.php




下载文件

文件名: ih_manager.php
文件类型: PHP文件
文件大小: 15.17 KiB
MD5: e0765bb448e014c5cd48a2db741adcad

ih_manager.php - 关闭高亮
  1. <?php
  2. /**
  3.  * ih_manager.php
  4.  * manager module for IH2 admin interface
  5.  *
  6.  * @author  Tim Kroeger (original author)
  7.  * @copyright Copyright 2005-2006
  8.  * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
  9.  * @version $Id: ih_manager.php,v 2.0 Rev 8 2010-05-31 23:46:5 DerManoMann Exp $
  10.  * Last modified by DerManoMann 2010-05-31 23:46:50
  11.  */
  12.  
  13.   if ($action == 'new_cat') {
  14.     $current_category_id = (isset($_GET['current_category_id']) ? $_GET['current_category_id'] : $current_category_id);
  15.     $new_product_query = $db->Execute("select ptc.* from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc  left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on ptc.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' where ptc.categories_id='" . $current_category_id . "' order by pd.products_name");
  16.     $products_filter = $new_product_query->fields['products_id'];
  17.     zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=manager&products_filter=' . $products_filter . '&current_category_id=' . $current_category_id));
  18.   }
  19.  
  20.   // set categories and products if not set
  21.   if ($products_filter == '' and $current_category_id != '') {
  22.     $new_product_query = $db->Execute("select ptc.* from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc  left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on ptc.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' where ptc.categories_id='" . $current_category_id . "' order by pd.products_name");
  23.     $products_filter = $new_product_query->fields['products_id'];
  24.     if ($products_filter != '') {
  25.       zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=manager&products_filter=' . $products_filter . '&current_category_id=' . $current_category_id));
  26.     }
  27.   } else {
  28.     if ($products_filter == '' and $current_categories_id == '') {
  29.       $reset_categories_id = zen_get_category_tree('', '', '0', '', '', true);
  30.       $current_category_id = $reset_categories_id[0]['id'];
  31.       $new_product_query = $db->Execute("select ptc.* from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc  left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on ptc.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' where ptc.categories_id='" . $current_category_id . "' order by pd.products_name");
  32.       $products_filter = $new_product_query->fields['products_id'];
  33.       $_GET['products_filter'] = $products_filter;
  34.     }
  35.   }
  36.  
  37.   require(DIR_WS_MODULES . FILENAME_PREV_NEXT);
  38.  
  39.   if ($action == 'save') {
  40.     $check = 0;
  41.     $data = array();
  42.  
  43.     $data['imgExtension'] = substr( $_FILES['default_image']['name'],
  44.             strrpos($_FILES['default_image']['name'], '.'));
  45.     /* Nigel fix here
  46.     This basically converts the extension of the uploaded file to match the main image, PROVIDED they are the same file type
  47.     */
  48.    
  49.     $sm_imgExtension = strtolower($data['imgExtension']);
  50.     $df_extension = strtolower($_GET['imgExtension']); // file extension of base original file
  51.    
  52.     //ugly but effective code
  53.     if ($sm_imgExtension == $df_extension) { // this should get rid of any capitilisation issues for files with the same extensions
  54.     $data['imgExtension'] = $_GET['imgExtension'];
  55.     } // This deals with any jpg that have differing extensions eg jpeg and jpg
  56.     elseif ((($sm_imgExtension == ".jpeg") && ($df_extension == ".jpg")) || (($sm_imgExtension == ".jpg") && ($df_extension == ".jpeg")) )
  57.     {// this is where they don't match eg original image is a gif and additional image is a jpg or png
  58.     $data['imgExtension'] = $_GET['imgExtension'];
  59.     } else
  60.     {
  61.     //file mismatch really should put a warning in here that the additional image won't show
  62.     // or a call to convert the actual image to a compatible format
  63.     }
  64.  
  65.     // Check the data
  66.     if ((isset($_GET['newImg']) && $_GET['newImg'] == 1) || (isset($_GET['imgEdit']) && ($_GET['imgEdit'] == 1) && ($_GET['imgSuffix'] ==  '') && ($_POST['imgNaming'] != 'keep_name') && ($_FILES['default_image']['name'] != ''))) {
  67.       // New Image Name and Base Dir
  68.       if ( ($_POST['imgBase'] != '') ) {
  69.         $data['imgBase'] = $_POST['imgBase'];
  70.                    echo "<!--  point 12 - ".$_POST['imgBase']."-->";
  71.       } else {
  72.         // Extract the name from the default file
  73.         if ($_FILES['default_image']['name'] != '') {
  74.           preg_match("/(.+)\.[^\.]+$/", $_FILES['default_image']['name'], $matches);
  75.           $data['imgBase'] = $matches[1];
  76.         } else {
  77.           $messageStack->add(TEXT_MSG_AUTO_BASE_ERROR, 'error');
  78.           $check = 1;
  79.         }
  80.       }
  81.      
  82.       // catch nasty characters
  83.       if (preg_match("|\+|", $data['imgBase'])) {
  84.         $data['imgBase'] = str_replace("\+", "-", $data['imgBase']);
  85.         $messageStack->add( TEXT_MSG_AUTO_REPLACE .$data['imgBase'], 'warning' );
  86.       }
  87.      
  88.       if ( $_POST['imgNewBaseDir'] != '') {
  89.         $data['imgBaseDir'] = $_POST['imgNewBaseDir'];
  90.       } else {
  91.         $data['imgBaseDir'] = $_POST['imgBaseDir'];
  92.       }
  93.      
  94.       $data['imgSuffix'] = "";
  95.  
  96.       if ($_POST['imgNaming'] == 'new_copy') {
  97.         // need to copy/rename additional images for new default image
  98.         // this will be implemented in a future release
  99.       }    
  100.      
  101.     } else if (isset($_GET['imgEdit']) && $_GET['imgEdit'] == 1) {
  102.       $data['imgBaseDir'] = $_GET['imgBaseDir'];
  103.       $data['imgBase'] = $_GET['imgBase'];
  104.       //$data['imgExtension'] = $_GET['imgExtension'];
  105.       $data['imgSuffix'] = $_GET['imgSuffix'];
  106.     } else {
  107.       // An additional image is being added
  108.       $data['imgBaseDir'] = $_GET['imgBaseDir'];
  109.       $data['imgBase'] = $_GET['imgBase'];
  110.       //$data['imgExtension'] = $_GET['imgExtension'];
  111.            
  112.       // Image Suffix (if set)
  113.       if ($_POST['imgSuffix'] != '') {
  114.         $data['imgSuffix'] = '_'.$_POST['imgSuffix'];
  115.       } else {
  116.         // get directory list
  117.         $array = array();
  118.         find_additional_images($array, DIR_FS_CATALOG . DIR_WS_IMAGES . $data['imgBaseDir'],
  119.           $data['imgExtension'], $data['imgBase'] );
  120.         echo "<!--  point 1".$data['imgExtension']."-->";
  121.         $c = sizeof( $array );
  122.         if ($c > 1) {
  123.           sort($array);
  124.         }
  125.        
  126.         // calculate the next suffix
  127.         // (This is lame, unscalable, and inefficient, but effective)
  128.         $suffix = 1;
  129.         $m = 0;
  130.         while ($m != 1) {
  131.          
  132.           if ($suffix < 10) {
  133.             $suffixStr = "0".$suffix;
  134.           } else {
  135.             $suffixStr = $suffix;
  136.           }
  137.          
  138.           $string = $data['imgBase'] . '_'. $suffixStr . $data['imgExtension'];
  139.           echo "<!--  point 2".$data['imgExtension']."-->";
  140.           $n = 0;
  141.           for ($i=0; $i < $c; $i++) {
  142.             if ($array[$i] == $string) {
  143.               $n = 1;
  144.             }
  145.           }
  146.           if ($n == 1) {
  147.             $suffix++;
  148.           } else {
  149.             $data['imgSuffix'] = "_".$suffixStr;
  150.             $m = 1;
  151.           }
  152.         }
  153.       }
  154.     } // if newImg
  155.  
  156.     // determine the filenames
  157.     if ($check != 1) {
  158.       // add slash to base dir
  159.       if (($data['imgBaseDir'] != '') && (!preg_match("|\/$|", $data['imgBaseDir']))) {
  160.         $data['imgBaseDir'] .= '/';
  161.       }
  162.       $data['defaultFileName'] = $data['imgBaseDir']
  163.         . $data['imgBase']
  164.         . $data['imgSuffix']
  165.         . $data['imgExtension'];
  166.  
  167.       // Check if the file already exists
  168.       if ( isset($_GET['imgEdit']) && ($_GET['imgEdit'] != 1) && (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $data['defaultFileName'])) ) {
  169.         $messageStack->add( TEXT_MSG_FILE_EXISTS, 'error' );
  170.         $check = 1;
  171.       }
  172.            
  173.     }
  174.  
  175.  
  176.     // Update the database
  177.     if (($check != 1) &&
  178.         ( isset($_GET['newImg']) && ($_GET['newImg'] == 1) || (isset($_GET['imgEdit']) && ($_GET['imgEdit'] == 1) && ($_GET['imgSuffix'] ==  '') && ($_POST['imgNaming'] != 'keep_name') && ($_FILES['default_image']['name'] != '')) )) {
  179.       // update the database
  180.       $sql = "update ". TABLE_PRODUCTS . " set products_image='"
  181.         .$data['defaultFileName']."' where products_id='".$products_filter."'";
  182.       if ( ! $db->Execute($sql) ) {
  183.         $messageStack->add(TEXT_MSG_INVALID_SQL, "error");
  184.         $check = 1;
  185.       }
  186.     }
  187.  
  188.     if ($check != 1) {
  189.       // check for destination directory and create, if they don't exist!
  190.       // Then move uploaded file to its new destination
  191.      
  192.       // default image
  193.       if ($_FILES['default_image']['name'] != '') {
  194.         io_makeFileDir(DIR_FS_CATALOG_IMAGES.$data['defaultFileName']);
  195.         $source_name = $_FILES['default_image']['tmp_name'];
  196.         $destination_name = DIR_FS_CATALOG_IMAGES . $data['defaultFileName'];
  197.         if ( !move_uploaded_file($source_name, $destination_name) ) {
  198.           $messageStack->add( TEXT_MSG_NOUPLOAD_DEFAULT, "error" );
  199.           $check = 1;
  200.         }
  201.       }  // Nigel Hack for special idiots  
  202.          
  203.       elseif (($_FILES['default_image']['name'] == '') && !(isset($_GET['imgEdit']))) {
  204.          io_makeFileDir(DIR_FS_CATALOG_IMAGES.$data['defaultFileName']);
  205.         $source_name = $_FILES['default_image']['tmp_name'];
  206.         $destination_name = DIR_FS_CATALOG_IMAGES . $data['defaultFileName'];
  207.         if ( !move_uploaded_file($source_name, $destination_name) ) {
  208.           $messageStack->add( 'you must select a default image', "error" );
  209.           $check = 1;
  210.           $_FILES['medium_image']['name'] = $_FILES['large_image']['name'] = '';
  211.         }
  212.       }  // End special idiots hack
  213.       // medium image
  214.       if ($_FILES['medium_image']['name'] != '') {
  215.         $data['mediumImgExtension'] = substr( $_FILES['medium_image']['name'],
  216.           strrpos($_FILES['medium_image']['name'], '.'));
  217.         $data['mediumFileName'] ='medium/' . $data['imgBaseDir']
  218.           . $data['imgBase']
  219.           . $data['imgSuffix'] . IMAGE_SUFFIX_MEDIUM
  220.           . $data['mediumImgExtension'];
  221.         io_makeFileDir(DIR_FS_CATALOG_IMAGES.$data['mediumFileName']);
  222.         $source_name = $_FILES['medium_image']['tmp_name'];
  223.         $destination_name = DIR_FS_CATALOG_IMAGES . $data['mediumFileName'];
  224.         if ( !move_uploaded_file($source_name, $destination_name) ) {
  225.           $messageStack->add( TEXT_MSG_NOUPLOAD_MEDIUM, "error" );
  226.           $check = 1;
  227.         }
  228.       }
  229.       // large image
  230.       if ($_FILES['large_image']['name'] != '') {
  231.         $data['largeImgExtension'] = substr( $_FILES['large_image']['name'],
  232.           strrpos($_FILES['large_image']['name'], '.'));
  233.         $data['largeFileName'] = 'large/' . $data['imgBaseDir']
  234.           . $data['imgBase']
  235.           . $data['imgSuffix'] . IMAGE_SUFFIX_LARGE
  236.           . $data['largeImgExtension'];
  237.         io_makeFileDir(DIR_FS_CATALOG_IMAGES.$data['largeFileName']);
  238.         $source_name = $_FILES['large_image']['tmp_name'];
  239.         $destination_name = DIR_FS_CATALOG_IMAGES . $data['largeFileName'];
  240.         if ( !move_uploaded_file($source_name, $destination_name) ) {
  241.           $messageStack->add( TEXT_MSG_NOUPLOAD_LARGE, "error" );
  242.           $check = 1;
  243.         }
  244.       }  
  245.     }
  246.  
  247.     if ($check == 1) {
  248.       if ($_GET['imgEdit'] == 1) {
  249.         $action = "layout_edit";
  250.       } else {
  251.         $action = "layout_new";
  252.       }
  253.       $repeat_check = 1;
  254.     } else {
  255.       // Data has been saved
  256.       // show the new image information
  257.            
  258.       $messageStack->add( TEXT_MSG_IMAGE_SAVED, 'success' );
  259.       // we might need to clear the cache if filenames are kept
  260.       if (isset($_GET['imgEdit']) && $_GET['imgEdit'] == 1) {
  261.         $error = bmz_clear_cache();
  262.         if (!$error) {
  263.           $messageStack->add(IH_CACHE_CLEARED, 'success');
  264.         }
  265.       }
  266.       $_GET['imgName'] = $data['imgBase'] . $data['imgSuffix'];
  267.       $action = "layout_info";
  268.     }
  269.   }
  270.  
  271.  
  272.  
  273.  
  274.   if ($action == 'quick_delete') {
  275.     $img_name = $_GET['imgName'];
  276.     $img_name_full = DIR_FS_CATALOG . $img_name;
  277.     if (is_file($img_name_full)) {
  278.       if (unlink($img_name_full)) {
  279.         // file successfully deleted
  280.         $messageStack->add_session(TEXT_MSG_IMAGE_DELETED, 'success');
  281.       } else {
  282.         // couldn't delete file
  283.         $messageStack->add_session(TEXT_MSG_IMAGE_NOT_DELETED, 'error');
  284.       }
  285.     } else {
  286.       // could not find file to delete
  287.       $messageStack->add_session(TEXT_MSG_IMAGE_NOT_FOUND, 'error');
  288.     }
  289.     zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'products_filter=' . $_GET['products_filter'] . '&current_category_id=' . $current_category_id));
  290.   }
  291.  
  292.  
  293.  
  294.  
  295.   if ($action == 'delete') {
  296.     $data['imgBaseDir'] = $_GET['imgBaseDir'];
  297.     $data['imgBase'] = $_GET['imgBase'];
  298.     $data['imgExtension'] = $_GET['imgExtension'];
  299.     $data['imgSuffix'] = $_GET['imgSuffix'];
  300.  
  301.     // add slash to base dir
  302.     if (($data['imgBaseDir'] != '') && (!preg_match("|\/$|", $data['imgBaseDir']))) {
  303.       $data['imgBaseDir'] .= '/';
  304.     }
  305.  
  306.  
  307.     // Determine file names
  308.     $data['defaultFileName'] = DIR_FS_CATALOG.DIR_WS_IMAGES
  309.         . $data['imgBaseDir'] . $data['imgBase']
  310.         . $data['imgSuffix'] . $data['imgExtension'];
  311.     $data['mediumFileName'] = DIR_FS_CATALOG.DIR_WS_IMAGES
  312.         . 'medium/'
  313.         . $data['imgBaseDir'] . $data['imgBase']
  314.         . $data['imgSuffix'] . IMAGE_SUFFIX_MEDIUM
  315.         . $data['imgExtension'];
  316.     $data['largeFileName'] = DIR_FS_CATALOG.DIR_WS_IMAGES
  317.         . 'large/'
  318.         . $data['imgBaseDir'] . $data['imgBase']
  319.         . $data['imgSuffix'] . IMAGE_SUFFIX_LARGE
  320.         . $data['imgExtension'];
  321.    
  322.     if ($_POST['delete_from_db_only'] != "Y") {
  323.       // check for each file, and delete it!
  324.       if (is_file($data['largeFileName'])) {
  325.         if (unlink($data['largeFileName'])) {
  326.           $messageStack->add(TEXT_MSG_LARGE_DELETED, "success");
  327.         } else {
  328.           $messageStack->add(TEXT_MSG_NO_DELETE_LARGE, "error");
  329.         }
  330.       }
  331.       if (is_file($data['mediumFileName'])) {
  332.         if (unlink($data['mediumFileName'])) {
  333.           $messageStack->add(TEXT_MSG_MEDIUM_DELETED, "success");
  334.         } else {
  335.           $messageStack->add(TEXT_MSG_NO_DELETE_MEDIUM, "error");
  336.         }
  337.       }
  338.       if (is_file($data['defaultFileName'])) {
  339.         if (unlink($data['defaultFileName'])) {
  340.           $messageStack->add(TEXT_MSG_DEFAULT_DELETED, "success");
  341.         } else {
  342.           $messageStack->add(TEXT_MSG_NO_DELETE_DEFAULT, "error");
  343.         }
  344.       } else {
  345.         $messageStack->add(TEXT_MSG_NO_DEFAULT_FILE_FOUND.': '.$data['defaultFileName'], "error");
  346.       }
  347.     }
  348.    
  349.     // update the database
  350.     if ($data['imgSuffix'] == '') {
  351.       $sql = "update ". TABLE_PRODUCTS . " set products_image='' where products_id='".$products_filter."'";
  352.       if ( ! $db->Execute($sql) ) {
  353.         $messageStack->add(TEXT_MSG_INVALID_SQL, "error");
  354.       }
  355.     }
  356.     zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'products_filter=' . $_GET['products_filter'] . '&current_category_id=' . $current_category_id));
  357.   }
  358.  
  359.   if ($action == 'cancel') {
  360.     // set edit message
  361.     $messageStack->add_session(PRODUCT_WARNING_UPDATE_CANCEL, 'warning');
  362.     zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'products_filter=' . $_GET['products_filter'] . '&current_category_id=' . $current_category_id));
  363.   }