Exemplo n.º 1
0
function vam_upload_attribute_image($file, $lang, $max_byte_size, $upload_dir, $thumb_width, $thumb_height, $admin_width, $admin_height)
{
    if (!isset($file)) {
        return array('failed', '0');
    }
    if ($file['error'][$lang] == 1 || $file['error'][$lang] == 2 || $file['size'][$lang] > $max_byte_size) {
        return array('failed', '1');
    }
    if ($file['error'][$lang] == 3) {
        return array('failed', '2');
    }
    if ($file['error'][$lang] == 4) {
        return array('success', '');
    }
    // TEST auf unterstьtzte Bildformate
    $valid_suffix = array();
    $gd_typ = gd_info();
    if ($gd_typ["GIF Read Support"] and $gd_typ["GIF Create Support"]) {
        array_push($valid_suffix, 'gif', 'GIF');
    }
    if ($gd_typ["JPG Support"]) {
        array_push($valid_suffix, 'jpg', 'JPG');
    }
    if ($gd_typ["PNG Support"]) {
        array_push($valid_suffix, 'png', 'PNG');
    }
    // TEST auf unterstьtzte Bildformate -eof
    $filetyp = explode('.', $file['name'][$lang]);
    $filetyp = $filetyp[count($filetyp) - 1];
    if (!in_array($filetyp, $valid_suffix)) {
        return array('failed', '4');
    }
    //filename bestimmen
    $file_exist = false;
    $filename = 'temp';
    // dummy
    do {
        $file_exist = false;
        $filename = time() . rand(0, 9999) . $lang . '.' . $filetyp;
        if (file_exists($filename)) {
            $file_exist = true;
        }
    } while ($file_exist and $count <= 20);
    if ($count > 20) {
        return array('failed', '7');
    }
    //filename bestimmen -eof
    if (move_uploaded_file($file['tmp_name'][$lang], $upload_dir . 'original/' . $filename)) {
        if (vam_attribute_image_processing($filename, $filetyp, $upload_dir, $thumb_width, $thumb_height, $admin_width, $admin_height)) {
            return array('success', $filename);
        } else {
            return array('failed', '6');
        }
    } else {
        return array('failed', '5');
    }
}
if ($_GET['status'] == '5') {
    $messageStack->add(TEXT_ATTRIBUTE_FILE_6);
}
if ($_GET['status'] == '6') {
    $messageStack->add(TEXT_ATTRIBUTE_FILE_7);
}
if ($_GET['status'] == '7') {
    $messageStack->add(TEXT_ATTRIBUTE_FILE_8);
}
if ($_GET['status'] == 'image_processing') {
    $files_to_rebuild = vam_db_query('SELECT products_options_values_image FROM ' . TABLE_PRODUCTS_OPTIONS_VALUES . ' WHERE products_options_values_image != ""');
    while ($file_to_rebuild = vam_db_fetch_array($files_to_rebuild)) {
        $filename = $file_to_rebuild['products_options_values_image'];
        $filetyp = explode('.', $filename);
        $filetyp = $filetyp[count($filetyp) - 1];
        if (!vam_attribute_image_processing($filename, $filetyp, DIR_FS_DOCUMENT_ROOT . DIR_WS_IMAGES . 'attribute_images/', $max_thumb_width, $max_thumb_height, $max_admin_width, $max_admin_height)) {
            $messageStack->add('failed while image_processing filename: ' . $filename);
        }
    }
}
//Options update
if ($_GET['action']) {
    $page_info = 'option_page=' . $_GET['option_page'] . '&value_page=' . $_GET['value_page'] . '&attribute_page=' . $_GET['attribute_page'];
    switch ($_GET['action']) {
        case 'add_product_options':
            for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                $option_name = $_POST['option_name'];
                vam_db_query("insert into " . TABLE_PRODUCTS_OPTIONS . " (products_options_id, products_options_name, language_id) values ('" . $_POST['products_options_id'] . "', '" . $option_name[$languages[$i]['id']] . "', '" . $languages[$i]['id'] . "')");
            }
            vam_redirect(vam_href_link(FILENAME_PRODUCTS_ATTRIBUTES, $page_info));
            break;