} else { $uploaded = false; if ($upload = new upload('', '', '777', array('jpeg', 'jpg', 'gif', 'png'))) { $size = @getimagesize($categories_image); if ($size[2] == '3') { $ext = '.png'; } elseif ($size[2] == '2') { $ext = '.jpg'; } else { $ext = '.gif'; } $new_filename = $boards_categories_id . $ext; $upload->filename = 'categories/' . $new_filename; if ($upload->upload('image', DIR_FS_CATALOG_IMAGES)) { if (CATEGORY_IMAGE_WIDTH > 0 || CATEGORY_IMAGE_HEIGHT > 0) { tep_create_thumb(DIR_FS_CATALOG_IMAGES . $upload->filename, '', CATEGORY_IMAGE_WIDTH, CATEGORY_IMAGE_HEIGHT); } $prev_file_query = tep_db_query("select image from " . TABLE_BOARDS_CATEGORIES . " where boards_categories_id = '" . (int) $boards_categories_id . "'"); $prev_file = tep_db_fetch_array($prev_file_query); if (tep_not_null($prev_file['image']) && $prev_file['image'] != $upload->filename) { @unlink(DIR_FS_CATALOG_IMAGES . $prev_file['image']); } tep_db_query("update " . TABLE_BOARDS_CATEGORIES . " set image = '" . $upload->filename . "' where boards_categories_id = '" . (int) $boards_categories_id . "'"); } } } tep_update_blocks($boards_categories_id, 'boards_category'); tep_redirect(tep_href_link(FILENAME_BOARDS, 'tPath=' . $tPath . '&cPath=' . $cPath . '&cID=' . $boards_categories_id)); } break; case 'delete_category_confirm':
$new_filename = $authors_id; } $new_filename .= $ext; $upload->filename = 'authors/' . $new_filename; if ($upload->upload('authors_image', DIR_FS_CATALOG_IMAGES)) { $prev_file_query = tep_db_query("select authors_image from " . TABLE_AUTHORS . " where authors_id = '" . (int) $authors_id . "'"); $prev_file = tep_db_fetch_array($prev_file_query); if (tep_not_null($prev_file['authors_image']) && $prev_file['authors_image'] != $upload->filename) { @unlink(DIR_FS_CATALOG_IMAGES . $prev_file['authors_image']); } if (AUTHOR_IMAGE_WIDTH > 0 || AUTHOR_IMAGE_HEIGHT > 0) { tep_create_thumb(DIR_FS_CATALOG_IMAGES . $upload->filename, '', AUTHOR_IMAGE_WIDTH, AUTHOR_IMAGE_HEIGHT); if (!is_dir(DIR_FS_CATALOG_IMAGES . 'authors/thumbs')) { mkdir(DIR_FS_CATALOG_IMAGES . 'authors/thumbs', 0777); } tep_create_thumb(DIR_FS_CATALOG_IMAGES . $upload->filename, DIR_FS_CATALOG_IMAGES . str_replace('authors/', 'authors/thumbs/', $upload->filename), 50, 70); } tep_db_query("update " . TABLE_AUTHORS . " set authors_image = '" . $upload->filename . "' where authors_id = '" . (int) $authors_id . "'"); } } tep_update_blocks($authors_id, 'author'); tep_redirect(tep_href_link(FILENAME_AUTHORS, 'search=' . urlencode($search) . '&page=' . $HTTP_GET_VARS['page'] . '&aID=' . $authors_id)); break; case 'deleteconfirm': $authors_id = tep_db_prepare_input($HTTP_GET_VARS['aID']); if (isset($HTTP_POST_VARS['delete_image']) && $HTTP_POST_VARS['delete_image'] == 'on') { $author_query = tep_db_query("select authors_image from " . TABLE_AUTHORS . " where authors_id = '" . (int) $authors_id . "'"); $author = tep_db_fetch_array($author_query); $image_location = DIR_FS_CATALOG . DIR_WS_CATALOG_IMAGES . $author['authors_image']; if (file_exists($image_location)) { @unlink($image_location);
$is_copied = true; } } elseif (tep_not_null($products_image_url)) { if (copy($products_image_url, DIR_FS_CATALOG_IMAGES . 'foreign/' . $new_filename)) { $is_copied = true; } } if ($is_copied) { $prev_file_query = tep_db_query("select products_image from " . TABLE_FOREIGN_PRODUCTS . " where products_id = '" . (int) $products_id . "'"); $prev_file = tep_db_fetch_array($prev_file_query); if (tep_not_null($prev_file['products_image'])) { @unlink(DIR_FS_CATALOG_IMAGES . 'foreign/' . $prev_file['products_image']); @unlink(DIR_FS_CATALOG_IMAGES . 'foreign/big/' . $prev_file['products_image']); } tep_create_thumb(DIR_FS_CATALOG_IMAGES . 'foreign/' . $new_filename, DIR_FS_CATALOG_IMAGES . 'foreign/big/' . $new_filename, BIG_IMAGE_WIDTH, BIG_IMAGE_HEIGHT, '85', 'reduce_only'); tep_create_thumb(DIR_FS_CATALOG_IMAGES . 'foreign/' . $new_filename, '', SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, '85', 'reduce_only'); tep_db_query("update " . TABLE_FOREIGN_PRODUCTS . " set products_image = '" . tep_db_input($new_filename) . "' where products_id = '" . (int) $products_id . "'"); } } tep_db_query("update " . TABLE_FOREIGN_PRODUCTS . " set products_image_exists = '0', sort_order = '0'"); tep_db_query("update " . TABLE_FOREIGN_PRODUCTS . " set products_image_exists = '1' where products_image <> ''"); // сортировка по умолчанию (сначала книги с картинками, потом все остальное) $query = tep_db_query("select products_id, products_image_exists from " . TABLE_FOREIGN_PRODUCTS . " where 1 order by products_image_exists desc, products_year desc, products_name"); $s = 1; while ($row = tep_db_fetch_array($query)) { tep_db_query("update " . TABLE_FOREIGN_PRODUCTS . " set sort_order = '" . (int) $s . "' where products_id = '" . (int) $row['products_id'] . "'"); $s++; } tep_redirect(tep_href_link(FILENAME_FOREIGN_PRODUCTS, 'page=' . $page . '&pID=' . $products_id)); break; }
} else { $ext = ''; } if (tep_not_null($ext)) { if (tep_not_null($prev_images_array[$i])) { $boards_image_name = basename($prev_images_array[$i]); @unlink($boards_images_dir . basename($prev_images_array[$i])); @unlink($boards_images_dir . 'big/' . basename($prev_images_array[$i])); @unlink($boards_images_dir . 'thumbs/' . basename($prev_images_array[$i])); } else { $boards_image_name = substr(uniqid(rand()), 0, 10) . $ext; } if (tep_create_thumb($_FILES['boards_images']['tmp_name'][$i], $boards_images_dir . 'big/' . $boards_image_name, '', '750', '85', 'reduce_only')) { $boards_images[] = $boards_image_name; tep_create_thumb($boards_images_dir . 'big/' . $boards_image_name, $boards_images_dir . $boards_image_name, BIG_IMAGE_WIDTH, BIG_IMAGE_HEIGHT, '85', 'reduce_only'); tep_create_thumb($boards_images_dir . 'big/' . $boards_image_name, $boards_images_dir . 'thumbs/' . $boards_image_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, '85', 'reduce_only'); } } } elseif (tep_not_null($HTTP_POST_VARS['boards_existing_images'][$i])) { if ($HTTP_POST_VARS['boards_images_delete'][$i] == '1') { @unlink($boards_images_dir . basename($prev_images_array[$i])); @unlink($boards_images_dir . 'big/' . basename($prev_images_array[$i])); @unlink($boards_images_dir . 'thumbs/' . basename($prev_images_array[$i])); } else { $boards_images[] = basename($prev_images_array[$i]); } } } tep_db_query("update " . TABLE_BOARDS . " set boards_image = '" . implode("\n", $boards_images) . "' where boards_id = '" . (int) $boards_id . "'"); tep_redirect(tep_href_link(FILENAME_BOARDS, tep_get_all_get_params(array('action')) . 'tPath=' . $boards_types_id)); } else {
$products_path = sprintf('%06d', $products_id); $levels = array(substr($products_path, 0, 3), substr($products_path, 3, 2)); $full_level = ''; reset($levels); while (list(, $level) = each($levels)) { $full_level .= $level . '/'; if (!is_dir(DIR_FS_CATALOG_IMAGES . 'thumbs/' . $full_level)) { mkdir(DIR_FS_CATALOG_IMAGES . 'thumbs/' . $full_level, 0777); } if (!is_dir(DIR_FS_CATALOG_IMAGES_BIG . $full_level)) { mkdir(DIR_FS_CATALOG_IMAGES_BIG . $full_level, 0777); } } if (tep_create_thumb($image_big, DIR_FS_CATALOG_IMAGES . 'thumbs/' . $full_level . $products_image_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, '85', 'reduce_only')) { $new_filename = $full_level . $products_image_name; tep_create_thumb($image_big, DIR_FS_CATALOG_IMAGES_BIG . $new_filename, BIG_IMAGE_WIDTH, BIG_IMAGE_HEIGHT, '85', 'reduce_only'); } } } tep_db_query("update " . TABLE_TEMP_PRODUCTS . " set products_image = '" . tep_db_input($new_filename) . "', products_image_exists = '" . (tep_not_null($new_filename) ? '1' : '0') . "' where products_id = '" . (int) $products_id . "'"); tep_db_query("update " . TABLE_TEMP_PRODUCTS_INFO . " set products_image = '" . tep_db_input($new_filename) . "' where products_id = '" . (int) $products_id . "'"); tep_db_query("update " . TABLE_PRODUCTS . " set products_image = '" . tep_db_input($new_filename) . "', products_image_exists = '" . (tep_not_null($new_filename) ? '1' : '0') . "' where products_id = '" . (int) $products_id . "'"); tep_db_query("update " . TABLE_PRODUCTS_INFO . " set products_image = '" . tep_db_input($new_filename) . "' where products_id = '" . (int) $products_id . "'"); } } } fclose($fp); fclose($np); $products_query = tep_db_query("select products_id, categories_id from " . TABLE_TEMP_PRODUCTS_INFO . " where " . ($action == 'upload_other_products' ? "products_types_id > '1'" : "products_types_id = '1'")); while ($products = tep_db_fetch_array($products_query)) { $products_id = $products['products_id'];
$information_linked = array(); } tep_db_query("delete from " . TABLE_PRODUCTS_TO_INFORMATION . " where products_id = '" . (int) $products_id . "'"); while (list(, $linked_id) = each($information_linked)) { if ((int) $linked_id > 0) { tep_db_query("insert into " . TABLE_PRODUCTS_TO_INFORMATION . " (products_id, information_id) values ('" . (int) $products_id . "', '" . (int) $linked_id . "')"); } } tep_update_blocks($products_id, 'product'); $images_query = tep_db_query("select products_image, products_id from " . TABLE_PRODUCTS . " where products_image <> ''"); while ($images = tep_db_fetch_array($images_query)) { if (!file_exists(DIR_FS_CATALOG_IMAGES . $images['products_image'])) { if (file_exists(DIR_FS_CATALOG_IMAGES_BIG . $images['products_image'])) { tep_create_thumb(DIR_FS_CATALOG_IMAGES_BIG . $images['products_image'], DIR_FS_CATALOG_IMAGES . $images['products_image'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); } elseif (file_exists(DIR_FS_CATALOG_IMAGES_MIDDLE . $images['products_image'])) { tep_create_thumb(DIR_FS_CATALOG_IMAGES_MIDDLE . $images['products_image'], DIR_FS_CATALOG_IMAGES . $images['products_image'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); } else { tep_db_query("update " . TABLE_PRODUCTS . " set products_image = '' where products_id = '" . (int) $images['products_id'] . "'"); } } } tep_redirect(tep_href_link(FILENAME_CATEGORIES, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $products_id)); } } break; case 'copy_to_confirm': if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['categories_id'])) { $products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']); $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']); if ($HTTP_POST_VARS['copy_as'] == 'link') { if ($categories_id != $current_category_id) {
} else { $ext = '.gif'; } $new_filename = preg_replace('/[^\\d\\w]/i', '', strtolower($news_path)); if (!tep_not_null($new_filename)) { $new_filename = $news_id; } $new_filename .= $ext; $upload->filename = 'news/' . $new_filename; if ($upload->upload('news_image', DIR_FS_CATALOG_IMAGES)) { if (NEWS_IMAGE_WIDTH > 0 || NEWS_IMAGE_HEIGHT > 0) { tep_create_thumb(DIR_FS_CATALOG_IMAGES . $upload->filename, '', NEWS_IMAGE_WIDTH, NEWS_IMAGE_HEIGHT); if (!is_dir(DIR_FS_CATALOG_IMAGES . 'news/thumbs')) { mkdir(DIR_FS_CATALOG_IMAGES . 'news/thumbs', 0777); } tep_create_thumb(DIR_FS_CATALOG_IMAGES . $upload->filename, DIR_FS_CATALOG_IMAGES . str_replace('news/', 'news/thumbs/', $upload->filename), XSMALL_IMAGE_WIDTH, XSMALL_IMAGE_HEIGHT); } $prev_file_query = tep_db_query("select news_image from " . TABLE_NEWS . " where news_id = '" . (int) $news_id . "'"); $prev_file = tep_db_fetch_array($prev_file_query); if (tep_not_null($prev_file['news_image']) && $prev_file['news_image'] != $upload->filename) { @unlink(DIR_FS_CATALOG_IMAGES . $prev_file['news_image']); @unlink(DIR_FS_CATALOG_IMAGES . str_replace('news/', 'news/thumbs/', $prev_file['news_image'])); } $t = 0; $shops_query = tep_db_query("select shops_id, shops_database, shops_fs_dir, shops_default_status from " . TABLE_SHOPS . " where shops_database <> ''" . ($action == 'update_news' ? " and shops_id = '" . (int) SHOP_ID . "'" : " and shops_id in ('" . implode("', '", $shops_array) . "')")); while ($shops = tep_db_fetch_array($shops_query)) { $database = $shops['shops_database']; tep_db_query("update " . $database . "." . TABLE_NEWS . " set news_image = '" . tep_db_input($upload->filename) . "' where news_id = '" . (int) $news_id . "'"); $copy_to = str_replace('//', '/', $shops['shops_fs_dir'] . DIR_WS_CATALOG_IMAGES); if ($action == 'insert_news' && tep_not_null($upload->filename)) { copy(DIR_FS_CATALOG_IMAGES . $upload->filename, $copy_to . $upload->filename);