コード例 #1
0
 function insert_product($products_data, $dest_category_id, $action = 'insert')
 {
     $products_id = olc_db_prepare_input($products_data['products_id']);
     $products_date_available = olc_db_prepare_input($products_data['products_date_available']);
     $products_date_available = date('Y-m-d') < $products_date_available ? $products_date_available : 'null';
     if ($products_data['products_startpage'] == 1) {
         $this->link_product($products_data['products_id'], 0);
         $products_status = 1;
     } else {
         $products_status = olc_db_prepare_input($products_data['products_status']);
     }
     if ($products_data['products_startpage'] == 0) {
         $products_status = olc_db_prepare_input($products_data['products_status']);
     }
     if (PRICE_IS_BRUTTO == TRUE_STRING_S && $products_data['products_price']) {
         $products_data['products_price'] = round($products_data['products_price'] / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100, PRICE_PRECISION);
     }
     //
     $customers_statuses_array = olc_get_customers_statuses();
     $permission = array();
     for ($i = 0; $n = sizeof($customers_statuses_array), $i < $n; $i++) {
         if (isset($customers_statuses_array[$i]['id'])) {
             $permission[$customers_statuses_array[$i]['id']] = 0;
         }
     }
     if (isset($products_data['groups'])) {
         foreach ($products_data['groups'] as $dummy => $b) {
             $permission[$b] = 1;
         }
     }
     // build array
     if ($permission['all'] == 1) {
         $permission = array();
         end($customers_statuses_array);
         for ($i = 0; $n = key($customers_statuses_array), $i < $n + 1; $i++) {
             if (isset($customers_statuses_array[$i]['id'])) {
                 $permission[$customers_statuses_array[$i]['id']] = 1;
             }
         }
     }
     $permission_array = array();
     // set pointer to last key
     end($customers_statuses_array);
     for ($i = 0; $n = key($customers_statuses_array), $i < $n + 1; $i++) {
         if (isset($customers_statuses_array[$i]['id'])) {
             $permission_array = array_merge($permission_array, array('group_permission_' . $customers_statuses_array[$i]['id'] => $permission[$customers_statuses_array[$i]['id']]));
         }
     }
     //
     $sql_data_array = array('products_quantity' => olc_db_prepare_input($products_data['products_quantity']), 'products_model' => olc_db_prepare_input($products_data['products_model']), 'products_ean' => olc_db_prepare_input($products_data['products_ean']), 'products_price' => olc_db_prepare_input($products_data['products_price']), 'products_sort' => olc_db_prepare_input($products_data['products_sort']), 'products_shippingtime' => olc_db_prepare_input($products_data['shipping_status']), 'products_discount_allowed' => olc_db_prepare_input($products_data['products_discount_allowed']), 'products_date_available' => $products_date_available, 'products_weight' => olc_db_prepare_input($products_data['products_weight']), 'products_status' => $products_status, 'products_startpage' => olc_db_prepare_input($products_data['products_startpage']), 'products_startpage_sort' => olc_db_prepare_input($products_data['products_startpage_sort']), 'products_tax_class_id' => olc_db_prepare_input($products_data['products_tax_class_id']), 'product_template' => olc_db_prepare_input($products_data['info_template']), 'options_template' => olc_db_prepare_input($products_data['options_template']), 'manufacturers_id' => olc_db_prepare_input($products_data['manufacturers_id']), 'products_fsk18' => olc_db_prepare_input($products_data['fsk18']), 'products_vpe_value' => olc_db_prepare_input($products_data['products_vpe_value']), 'products_vpe_status' => olc_db_prepare_input($products_data['products_vpe_status']), 'products_vpe' => olc_db_prepare_input($products_data['products_vpe']), 'products_promotion_status' => olc_db_prepare_input($products_data['products_promotion_status']), 'products_promotion_product_title' => olc_db_prepare_input($products_data['products_promotion_product_title']), 'products_promotion_product_desc' => olc_db_prepare_input($products_data['products_promotion_product_desc']));
     $sql_data_array = array_merge($sql_data_array, $permission_array);
     //get the next ai-value from table products if no products_id is set
     if (!$products_id || $products_id == '') {
         $new_pid_query = olc_db_query("SHOW TABLE STATUS LIKE '" . TABLE_PRODUCTS . "'");
         $new_pid_query_values = olc_db_fetch_array($new_pid_query);
         $products_id = $new_pid_query_values['Auto_increment'];
     }
     //prepare products_image filename
     if ($products_image = olc_try_upload('products_image', DIR_FS_CATALOG_ORIGINAL_IMAGES, '777', '')) {
         $pname_arr = explode('.', $products_image->filename);
         $nsuffix = array_pop($pname_arr);
         $products_image_name = $products_id . '_0.' . $nsuffix;
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_data['products_previous_image_0'] . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] < 2) {
             @olc_del_image_file($products_data['products_previous_image_0']);
         }
         //workaround if there are v2 images mixed with v3
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_image->filename . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] == 0) {
             rename(DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image_name);
         } else {
             copy(DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image_name);
         }
         $sql_data_array['products_image'] = olc_db_prepare_input($products_image_name);
         require DIR_WS_INCLUDES . 'product_thumbnail_images.php';
         require DIR_WS_INCLUDES . 'product_info_images.php';
         require DIR_WS_INCLUDES . 'product_popup_images.php';
     } else {
         $products_image_name = $products_data['products_previous_image_0'];
     }
     //are we asked to delete some pics?
     if ($products_data['del_pic'] != '') {
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_data['del_pic'] . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] < 2) {
             @olc_del_image_file($products_data['del_pic']);
         }
         olc_db_query("SQL_UPDATE " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                 SET products_image = ''\n\t\t\t\t\t\t\t\t               WHERE products_id    = '" . olc_db_input($products_id) . "'");
     }
     if ($products_data['del_mo_pic'] != '') {
         foreach ($products_data['del_mo_pic'] as $dummy => $val) {
             $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t                               WHERE image_name = '" . $val . "'");
             $dup_check = olc_db_fetch_array($dup_check_query);
             if ($dup_check['total'] < 2) {
                 @olc_del_image_file($val);
             }
             olc_db_query("DELETE FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t               WHERE products_id = '" . olc_db_input($products_id) . "'\n\t\t\t\t\t\t\t\t\t\t\t                 AND image_name  = '" . $val . "'");
         }
     }
     //MO_PICS
     for ($img = 0; $img < MO_PICS; $img++) {
         if ($pIMG =& olc_try_upload('mo_pics_' . $img, DIR_FS_CATALOG_ORIGINAL_IMAGES, '777', '')) {
             $pname_arr = explode('.', $pIMG->filename);
             $nsuffix = array_pop($pname_arr);
             $products_image_name = $products_id . '_' . ($img + 1) . '.' . $nsuffix;
             $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t                               WHERE image_name = '" . $products_data['products_previous_image_' . ($img + 1)] . "'");
             $dup_check = olc_db_fetch_array($dup_check_query);
             if ($dup_check['total'] < 2) {
                 @olc_del_image_file($products_data['products_previous_image_' . ($img + 1)]);
             }
             @olc_del_image_file($products_image_name);
             rename(DIR_FS_CATALOG_ORIGINAL_IMAGES . '/' . $pIMG->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . '/' . $products_image_name);
             //get data & write to table
             $mo_img = array('products_id' => olc_db_prepare_input($products_id), 'image_nr' => olc_db_prepare_input($img + 1), 'image_name' => olc_db_prepare_input($products_image_name));
             if ($action == 'insert') {
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
             } elseif ($action == 'update' && $products_data['products_previous_image_' . ($img + 1)]) {
                 if ($products_data['del_mo_pic']) {
                     foreach ($products_data['del_mo_pic'] as $dummy => $val) {
                         if ($val == $products_data['products_previous_image_' . ($img + 1)]) {
                             olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
                         }
                         break;
                     }
                 }
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img, 'update', 'image_name = \'' . olc_db_input($products_data['products_previous_image_' . ($img + 1)]) . '\'');
             } elseif (!$products_data['products_previous_image_' . ($img + 1)]) {
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
             }
             //image processing
             require DIR_WS_INCLUDES . 'product_thumbnail_images.php';
             require DIR_WS_INCLUDES . 'product_info_images.php';
             require DIR_WS_INCLUDES . 'product_popup_images.php';
         }
     }
     if (isset($products_data['products_image']) && olc_not_null($products_data['products_image']) && $products_data['products_image'] != 'none') {
         $sql_data_array['products_image'] = olc_db_prepare_input($products_data['products_image']);
     }
     if ($action == 'insert') {
         $insert_sql_data = array('products_date_added' => 'now()');
         $sql_data_array = olc_array_merge($sql_data_array, $insert_sql_data);
         olc_db_perform(TABLE_PRODUCTS, $sql_data_array);
         $products_id = olc_db_insert_id();
         olc_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_CATEGORIES . "\n\t\t\t\t\t\t\t\t              SET products_id   = '" . $products_id . "',\n\t\t\t\t\t\t\t\t              categories_id = '" . $dest_category_id . "'");
     } elseif ($action == 'update') {
         $update_sql_data = array('products_last_modified' => 'now()');
         $sql_data_array = olc_array_merge($sql_data_array, $update_sql_data);
         olc_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', 'products_id = \'' . olc_db_input($products_id) . '\'');
     }
     $languages = olc_get_languages();
     // Here we go, lets write Group prices into db
     // start
     $i = 0;
     $group_query = olc_db_query("SELECT customers_status_id\n\t\t\t\t\t                               FROM " . TABLE_CUSTOMERS_STATUS . "\n\t\t\t\t\t                              WHERE language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t\t\t\t\t                                AND customers_status_id != '0'");
     while ($group_values = olc_db_fetch_array($group_query)) {
         // load data into array
         $i++;
         $group_data[$i] = array('STATUS_ID' => $group_values['customers_status_id']);
     }
     for ($col = 0, $n = sizeof($group_data); $col < $n + 1; $col++) {
         if ($group_data[$col]['STATUS_ID'] != '') {
             $personal_price = olc_db_prepare_input($products_data['products_price_' . $group_data[$col]['STATUS_ID']]);
             if ($personal_price == '' || $personal_price == '0.0000') {
                 $personal_price = '0.00';
             } else {
                 if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
                     $personal_price = $personal_price / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100;
                 }
                 $personal_price = olc_round($personal_price, PRICE_PRECISION);
             }
             if ($action == 'insert') {
                 olc_db_query("DELETE FROM personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . " WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t                 AND quantity    = '1'");
                 $insert_array = array();
                 $insert_array = array('personal_offer' => $personal_price, 'quantity' => '1', 'products_id' => $products_id);
                 olc_db_perform("personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'], $insert_array);
             } else {
                 olc_db_query("SQL_UPDATE personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t                 SET personal_offer = '" . $personal_price . "'\n\t\t\t\t\t\t\t\t\t\t\t\t               WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t                 AND quantity    = '1'");
             }
         }
     }
     // end
     // ok, lets check write new staffelpreis into db (if there is one)
     $i = 0;
     $group_query = olc_db_query("SELECT customers_status_id\n\t\t\t\t\t                               FROM " . TABLE_CUSTOMERS_STATUS . "\n\t\t\t\t\t                              WHERE language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t\t\t\t\t                                AND customers_status_id != '0'");
     while ($group_values = olc_db_fetch_array($group_query)) {
         // load data into array
         $i++;
         $group_data[$i] = array('STATUS_ID' => $group_values['customers_status_id']);
     }
     for ($col = 0, $n = sizeof($group_data); $col < $n + 1; $col++) {
         if ($group_data[$col]['STATUS_ID'] != '') {
             $quantity = olc_db_prepare_input($products_data['products_quantity_staffel_' . $group_data[$col]['STATUS_ID']]);
             $staffelpreis = olc_db_prepare_input($products_data['products_price_staffel_' . $group_data[$col]['STATUS_ID']]);
             if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
                 $staffelpreis = $staffelpreis / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100;
             }
             $staffelpreis = olc_round($staffelpreis, PRICE_PRECISION);
             if ($staffelpreis != '' && $quantity != '') {
                 // ok, lets check entered data to get rid of user faults
                 if ($quantity <= 1) {
                     $quantity = 2;
                 }
                 $check_query = olc_db_query("SELECT quantity\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                               FROM personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                              WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                AND quantity    = '" . $quantity . "'");
                 // dont insert if same qty!
                 if (olc_db_num_rows($check_query) < 1) {
                     olc_db_query("INSERT INTO personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                 SET price_id       = '',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     products_id    = '" . $products_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     quantity       = '" . $quantity . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     personal_offer = '" . $staffelpreis . "'");
                 }
             }
         }
     }
     //foreach ($languages AS $lang) {
     $n = sizeof($languages);
     for ($i = 0; $i < $n; $i++) {
         $language_id = $languages[$i]['id'];
         //--- PRODUCT PROMOTION
         if ($_FILES['products_promotion_image' . $i]['name'] != '') {
             if ($image =& olc_try_upload('products_promotion_image' . $i, DIR_FS_CATALOG_IMAGES . 'products_promotion/')) {
                 $paname_arr = explode('.', $image->filename);
                 $pnsuffix = array_pop($paname_arr);
                 $products_promotion_imagename = $products_id . '_' . $i . '.' . $pnsuffix;
                 @unlink(DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $products_promotion_imagename);
                 rename(DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $image->filename, DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $products_promotion_imagename);
             }
         } elseif ($products_data['del_products_promotion_image' . $i] == true) {
             // bild loeschen
             $products_promotion_imagename = '';
         } else {
             $products_promotion_imagename = $products_data['products_promotion_image' . $i];
         }
         //--- PRODUCT PROMOTION eof
         $sql_data_array = array('products_name' => olc_db_prepare_input($products_data['products_name'][$language_id]), 'products_description' => olc_db_prepare_input($products_data['products_description_' . $language_id]), 'products_short_description' => olc_db_prepare_input($products_data['products_short_description_' . $language_id]), 'products_keywords' => olc_db_prepare_input($products_data['products_keywords'][$language_id]), 'products_url' => olc_db_prepare_input($products_data['products_url'][$language_id]), 'products_meta_title' => olc_db_prepare_input($products_data['products_meta_title'][$language_id]), 'products_meta_description' => olc_db_prepare_input($products_data['products_meta_description'][$language_id]), 'products_meta_keywords' => olc_db_prepare_input($products_data['products_meta_keywords'][$language_id]), 'products_promotion_title' => olc_db_prepare_input($products_data['products_promotion_title'][$language_id]), 'products_promotion_image' => $products_promotion_imagename, 'products_promotion_desc' => olc_db_prepare_input($products_data['products_promotion_desc'][$language_id]));
         if ($action == 'insert') {
             $insert_sql_data = array('products_id' => $products_id, 'language_id' => $language_id);
             $sql_data_array = olc_array_merge($sql_data_array, $insert_sql_data);
             olc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
         } elseif ($action == 'update') {
             olc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', 'products_id = \'' . olc_db_input($products_id) . '\' and language_id = \'' . $language_id . '\'');
         }
     }
 }
function ProductsImageUpload()
{
    global $_GET, $_POST;
    if ($products_image =& olc_try_upload('products_image', DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES, '777', '', true)) {
        $products_image_name = $products_image->filename;
        // rewrite values to use resample classes
        // generate resampled images if picture on the fly is OFF
        //W. Kaiser - pictures-on-the-fly
        if (PRODUCT_IMAGE_ON_THE_FLY != 'true') {
            $dir = DIR_FS_DOCUMENT_ROOT . 'admin/includes/product_';
            require $dir . 'thumbnail_images.php';
            require $dir . 'info_images.php';
            require $dir . 'popup_images.php';
        }
        //W. Kaiser - pictures-on-the-fly
        $code = 0;
        $message = 'OK';
    } else {
        $code = -1;
        $message = 'UPLOAD FAILED';
    }
    print_xml_status($code, $_POST['action'], $message, '', 'FILE_NAME', $products_image->filename);
}
コード例 #3
0
function ProductsImageUpload()
{
    global $_GET, $_POST;
    if ($products_image =& olc_try_upload('products_image', DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES, '777', '', true)) {
        $products_image_name = $products_image->filename;
        // rewrite values to use resample classes
        define('DIR_FS_CATALOG_ORIGINAL_IMAGES', DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES);
        define('DIR_FS_CATALOG_INFO_IMAGES', DIR_FS_CATALOG . DIR_WS_INFO_IMAGES);
        define('DIR_FS_CATALOG_POPUP_IMAGES', DIR_FS_CATALOG . DIR_WS_POPUP_IMAGES);
        define('DIR_FS_CATALOG_THUMBNAIL_IMAGES', DIR_FS_CATALOG . DIR_WS_THUMBNAIL_IMAGES);
        define('DIR_FS_CATALOG_IMAGES', DIR_FS_CATALOG . DIR_WS_IMAGES);
        // generate resampled images if picture on the fly is OFF
        $not_pictures_on_the_fly = PRODUCT_IMAGE_ON_THE_FLY != TRUE_STRING_S;
        if ($not_pictures_on_the_fly) {
            require DIR_FS_DOCUMENT_ROOT . 'admin/includes/product_thumbnail_images.php';
            require DIR_FS_DOCUMENT_ROOT . 'admin/includes/product_info_images.php';
            require DIR_FS_DOCUMENT_ROOT . 'admin/includes/product_popup_images.php';
        }
        $code = 0;
        $message = 'OK';
    } else {
        $code = -1;
        $message = 'UPLOAD FAILED';
    }
    print_xml_status($code, $_POST['action'], $message, '', 'FILE_NAME', $products_image->filename);
}