<?php

use_class('jng_sp');
$class_sp = new jng_sp();
use_class('jng_sp_catalog');
$class_jc = new jng_sp_catalog();
use_class('products_brand');
$class_pb = new products_brand();
use_class('products_linking');
$class_pl = new products_linking();
$maxlinks = array('C' => 5, 'U' => 1, 'A' => 3, 'D' => 3);
$maxlinks_js = 'var maxlink = new Object;';
foreach ($maxlinks as $type => $maxnum) {
    $maxlinks_js .= "\t\t" . "maxlink.{$type} = {$maxnum};\n";
}
//SP SETTING
salesPartnerCombo();
//GET PAGE
$session_page = 'sp-products-links';
$page = 1;
if (isset($_GET['page'])) {
    $page = $_GET['page'];
}
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'LOADPRODUCTLINKS') {
        function drawThumbs($links, $type, $addlink)
        {
            global $maxlinks;
            $results = '';
            if (is_array($links[$type]) && count($links[$type]) > 0) {
     $key = array_search($piid, $production_instruction_id);
     unset($production_instruction_id[$key]);
     $data['production_instruction_id'] = implode(",", $production_instruction_id);
     tep_db_perform('products_non_configurator', $data, 'update', "products_id={$pid}");
     $result['piid'] = $piid;
     ajaxReturn($result);
     exit;
 } elseif ($_POST['me_action'] == 'DETAILCOMPLETE') {
     $products_id = tep_db_prepare_input($_POST['products_id']);
     $make_template = tep_db_prepare_input($_POST['make_template']);
     $product = $class_pm->retrieveDetail($products_id, 'p,pd,pnc');
     $articles = $class_pa->retrieveList($products_id);
     if ($make_template == 'true') {
         use_class('products_linking');
         use_class('products_articles');
         $class_pl = new products_linking();
         $class_pa = new products_articles();
         $products_to_update = array();
         $draft = new design_draft(null, $products_id);
         $ucd_products = $draft->retrieveProducts("detailed_time IS NULL AND detailed_by IS NULL");
         //uncomplete detail products
         foreach ($ucd_products as $ucdp) {
             if ($ucdp['products_id'] != $products_id) {
                 $products_to_update[] = $ucdp['products_id'];
             }
         }
         //START UPDATE PRODUCT DETAIL TO ALL PRODUCTS WHICH PRODUCT DETAIL IS NOT FILLED
         foreach ($products_to_update as $pid) {
             //APPLY COLOR PATTERN
             /*$cps = $class_pm->loadColorPattern($products_id);
               if(count($cps)>0)saveColors($pid, implode(',', $cps));*/
<?php

use_class('products_minierp');
$class_pm = new products_minierp();
use_class('products_linking');
$class_pl = new products_linking();
use_class('jng_sp_catalog');
$class_jc = new jng_sp_catalog();
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'PRODUCTSLINKADD') {
        $products_id = tep_db_prepare_input($_POST['products_id']);
        $type = tep_db_prepare_input($_POST['link_type']);
        $links_id = tep_db_prepare_input($_POST['links_id']);
        $added = $class_pl->add($products_id, $type, $links_id, true);
        if (count($added) == 0) {
            $links_id = '!' . $links_id;
        }
        echo utf8_encode($links_id);
        exit;
    }
}
//START TEMPLATE
$products_id = tep_db_prepare_input($_GET['products_id']);
$type = tep_db_prepare_input($_GET['type']);
$jng_sp_id = isset($_GET['jng_sp_id']) ? $_GET['jng_sp_id'] : null;
switch ($type) {
    case 'C':
        $linktype = 'Cross-selling';
        break;
    case 'U':
tep_db_connect();
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
use_class('jng_sp_catalog');
use_class('jng_sp_upload');
use_class('products_minierp');
use_class('products_articles');
use_class('products_linking');
use_class('jng_sp');
$class_jc = new jng_sp_catalog();
$class_ju = new jng_sp_upload();
$class_pm = new products_minierp();
$class_pa = new products_articles();
$class_pl = new products_linking();
$class_sp = new jng_sp();
$jng_sp_id = '1';
$sp_detail = $class_sp->retrieveDetail($jng_sp_id);
$jng_sp_name = $sp_detail["name"];
$timestamp = date('d.m.Y H:i:s');
$datenow = date('ymd');
$HOURSTART = SP_NECKERMANN_CATUPLOAD_HOURSTART;
$HOUREND = SP_NECKERMANN_CATUPLOAD_HOUREND;
$hour_now = date('H');
//$hour_now = 04;
$max_pid_processed_per_run = 2000;
$total_pids_taken_per_run = 0;
$process_runned = 0;
$products_stock = array();
$bgst = $class_pm->retrieveBestGoodSettings();
<?php

use_class('products_minierp');
$class_pm = new products_minierp();
use_class('jng_sp_catalog');
$class_jc = new jng_sp_catalog();
use_class('products_brand');
$class_pb = new products_brand();
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'PRODUCTSLINKADD') {
        $products_id = tep_db_prepare_input($_POST['products_id']);
        $type = tep_db_prepare_input($_POST['link_type']);
        $links_id = tep_db_prepare_input($_POST['links_id']);
        use_class('products_linking');
        $class_pl = new products_linking();
        $added = $class_pl->add($products_id, $type, $links_id, true);
        if (count($added) == 0) {
            $links_id = '!' . $links_id;
        }
        echo utf8_encode($links_id);
        exit;
    }
}
//GET PAGE
$session_page = 'sp-products-links-popup';
$page = 1;
if (isset($_GET['page'])) {
    $page = $_GET['page'];
}
//START TEMPLATE
 function copyFromProducts($products_id_to_copied, $products_id_to_applied, $options = '*', $elements_id_to_exclude = '', $skip_same_add_length_composition = false)
 {
     use_class('products_articles');
     $class_pa = new products_articles();
     $have_element_to_exclude = false;
     if ($elements_id_to_exclude != '' && !is_array($elements_id_to_exclude)) {
         $elements_id_to_exclude = explode(',', $elements_id_to_exclude);
         $have_element_to_exclude = true;
     }
     $product = $this->retrieveDetail($products_id_to_copied, 'p,pd,pnc,cat');
     $product_to_applied = $this->retrieveDetail($products_id_to_copied, 'cat');
     $categories_is_same = $product['categories_id'] == $product_to_applied['categories_id'];
     $articles = $class_pa->retrieveList($products_id_to_copied);
     $articles_to_applied = $class_pa->retrieveList($products_id_to_applied);
     $add_length = array();
     $add_length_to_applied = array();
     if (isset($articles) && is_array($articles) && count($articles) > 0) {
         foreach ($articles as $a) {
             $add_length[] = $a['length'];
         }
     }
     if (isset($articles_to_applied) && is_array($articles_to_applied) && count($articles_to_applied) > 0) {
         foreach ($articles_to_applied as $ata) {
             $add_length_to_applied[] = $ata['length'];
         }
     }
     if (!is_array($products_id_to_applied)) {
         $products_id_to_applied = explode(',', $products_id_to_applied);
     }
     if ($options != '*') {
         $options = explode(',', $options);
     }
     //START UPDATE PRODUCT DETAIL TO ALL PRODUCTS WHICH PRODUCT DETAIL IS NOT FILLED
     foreach ($products_id_to_applied as $pid) {
         if ($options == '*' || in_array('cp', $options)) {
             //APPLY COLOR PATTERN
             $cps = $this->loadColorPattern($products_id_to_copied);
             if (count($cps) > 0) {
                 saveColors($pid, implode(',', $cps));
             }
         }
         if ($options == '*' || in_array('b', $options)) {
             //APPLY BRAND
             use_class('products_brand');
             $class_pb = new products_brand();
             $class_pb->updateProductBrand($pid, $product['p']['products_brand_id']);
         }
         if (($options == '*' || in_array('l', $options)) && $categories_is_same) {
             //APPLY LENGTH
             $def_length = $product['pnc']['products_length'];
             $this->saveLength($pid, $def_length, $add_length);
         }
         if ($options == '*' || in_array('eu', $options)) {
             //TODO: CHECK HOW TO ALSO COPY ELEMENTS IF OTHER PRODUCTS STILL DOESN'T HAVE ANY
             //APPLY ELEMENT USED & QTY
             $el_used = $this->retrieveElementsUsage($products_id_to_copied);
             if (count($el_used) > 0) {
                 $elids = array();
                 $elqtys = array();
                 foreach ($el_used as $elid => $el_data) {
                     if ($have_element_to_exclude) {
                         $check_key = array_search($elid, $elements_id_to_exclude);
                         if ($check_key !== false) {
                             continue;
                         }
                     }
                     $elids[] = $elid;
                     $elqtys[] = $el_data['quantity'];
                 }
                 $this->addElementToProducts($pid, $elids, $elqtys);
             }
             //APPLY OVERRIDE ELEMENTS (IF EXISTS) AND HAVE SAME ADDITIONAL LENGTH COMPOSITION
             if (count($add_length) > 0 && $categories_is_same) {
                 $have_same_add_length_composition = true;
                 if (count($add_length) == count($add_length_to_applied)) {
                     foreach ($add_length as $al) {
                         if (!in_array($al, $add_length_to_applied)) {
                             $have_same_add_length_composition = false;
                             break;
                         }
                     }
                 } else {
                     $have_same_add_length_composition = false;
                 }
                 if ($have_same_add_length_composition || $skip_same_add_length_composition) {
                     foreach ($add_length as $length) {
                         $dbq_o = tep_db_query("SELECT * FROM products_articles WHERE products_id = {$products_id_to_copied} AND length = {$length}");
                         $dbq_c = tep_db_query("SELECT * FROM products_articles WHERE products_id = {$pid} AND length = {$length}");
                         if (tep_db_num_rows($dbq_o) > 0 && tep_db_num_rows($dbq_c) > 0) {
                             $r_o = tep_db_fetch_array($dbq_o);
                             $r_c = tep_db_fetch_array($dbq_c);
                             $products_articles_id = $r_c['products_articles_id'];
                             $dbq_ovr = tep_db_query("SELECT * FROM products_articles_use_elements WHERE products_articles_id = {$r_o['products_articles_id']}");
                             while ($r_ovr = tep_db_fetch_array($dbq_ovr)) {
                                 $ovr_elid = $r_ovr['elements_id'];
                                 $dbq_pue_o = tep_db_query("SELECT * FROM products_use_elements WHERE products_use_elements_id = {$r_ovr['products_use_elements_id']}");
                                 $r_pue_o = tep_db_fetch_array($dbq_pue_o);
                                 $dbq_pue_c = tep_db_query("SELECT * FROM products_use_elements WHERE products_id = {$pid} AND elements_id = {$r_pue_o['elements_id']}");
                                 $r_pue_c = tep_db_fetch_array($dbq_pue_c);
                                 $products_use_elements_id = $r_pue_c['products_use_elements_id'];
                                 $ovr_data = array();
                                 if ($have_element_to_exclude) {
                                     $check_key = array_search($r_ovr['elements_id'], $elements_id_to_exclude);
                                     if ($check_key !== false) {
                                         continue;
                                     }
                                 }
                                 $ovr_data['elements_id'] = $r_ovr['elements_id'];
                                 $ovr_data['quantity'] = $r_ovr['quantity'];
                                 $ovr_data['products_articles_id'] = $products_articles_id;
                                 $ovr_data['products_use_elements_id'] = $products_use_elements_id;
                                 $class_pa->overrideElement($products_articles_id, $products_use_elements_id, $ovr_data);
                             }
                         }
                     }
                 }
             }
         }
         if ($options == '*' || in_array('mp', $options)) {
             //APPLY MANUAL PI
             $dbqmp = tep_db_query("SELECT * FROM products_non_configurator pnc WHERE pnc.products_id={$products_id_to_copied}");
             $mpi = tep_db_fetch_array($dbqmp);
             saveManualPI($pid, $mpi['products_instruction']);
         }
         if ($options == '*' || in_array('pl', $options)) {
             //APPLY PRODUCTS LINKING
             use_class('products_linking');
             $class_pl = new products_linking();
             $dbqpl = tep_db_query("SELECT * FROM products_linking WHERE products_id={$products_id_to_copied}");
             while ($r = tep_db_fetch_array($dbqpl)) {
                 $links_id = $r['links_id'];
                 $type = $r['type'];
                 $class_pl->add($pid, $type, $links_id, true);
             }
         }
         if ($options == '*' || in_array('ni', $options)) {
             //APPLY NAVID's
             use_class('jng_sp_catalog');
             $class_jc = new jng_sp_catalog();
             $dbq = tep_db_query("SELECT jng_sp_id, navigation, navigation2, navigation3 FROM jng_sp_catalog WHERE products_id={$products_id_to_copied} ORDER BY jng_sp_id");
             while ($r = tep_db_fetch_array($dbq)) {
                 $nav = $r['navigation'];
                 $nav2 = $r['navigation2'];
                 $nav3 = $r['navigation3'];
                 $class_jc->addProduct($r['jng_sp_id'], $pid);
                 $p_cat = $class_jc->retrieveCatalog($r['jng_sp_id'], "jc.products_id = '{$pid}'");
                 saveCatalog($p_cat[0]['jng_sp_catalog_id'], 'navigation', $nav);
                 saveCatalog($p_cat[0]['jng_sp_catalog_id'], 'navigation2', $nav2);
                 saveCatalog($p_cat[0]['jng_sp_catalog_id'], 'navigation3', $nav3);
             }
         }
     }
 }
<?php

global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('products_bundle');
use_class('products_linking');
$class_pl = new products_linking();
$flush_query = tep_db_query("TRUNCATE TABLE products_bundle_images");
$flush_query = tep_db_query("TRUNCATE TABLE products_bundle");
$flush_query = tep_db_query("UPDATE products SET products_bundle_id=0");
$pids = array();
$q = tep_db_query("SELECT jc.products_id, jc.price, p.products_brand_id FROM jng_sp_catalog jc LEFT JOIN products p ON p.products_id=jc.products_id WHERE jc.jng_sp_id=2 AND jc.active_status='1'");
while ($r = tep_db_fetch_array($q)) {
    $products[] = $r;
}
$bundles = array();
$jng_sp_id = 2;
$counter = 0;
$products_attached = array();
foreach ($products as $product) {
    if (!in_array($product['products_id'], $products_attached)) {
        $counter++;
        //$list = $class_pl->retrieveList($pid);
        $list = $class_pl->retrieveForCatalog($product, $jng_sp_id, 'C', 7);
        $bundle_nd = 'Auto Set ' . $counter;
        $bundles[$counter] = new products_bundle();
        $bundles[$counter]->create($bundle_nd, $bundle_nd);
        $bundles[$counter]->productAdd($product['products_id']);
<?php

use_class('Product');
use_class('products_linking');
use_class('jng_sp_catalog');
$class_pl = new products_linking();
$class_jc = new jng_sp_catalog();
$products_id = tep_db_prepare_input($_GET['id']);
function drawPLthumb($products_linking_id, $products_id, $hide = false, $show_remove = false)
{
    $obj_product = new Product($products_id);
    $hidden = $hide === true ? 'style="display:none;"' : '';
    $l = '<div id="pl-' . $products_linking_id . '" class="pro-thumb" ' . $hidden . '>';
    $l .= '<div>' . $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2) . '</div>';
    $l .= '<div>' . $obj_product->displayIDAndCode() . '</div>';
    if ($show_remove) {
        $l .= '<div title="Click to remove this product" class="red">(x) remove</div>';
    }
    $l .= '</div>';
    return $l;
}
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'PRODUCTLINKING') {
        $result = '';
        switch ($_POST['act']) {
            case 'LOAD':
                if (isset($_POST['plid']) && $_POST['plid'] != '') {
                    $pl = $class_pl->retrieveDetail($_POST['plid']);
                    $result .= drawPLthumb($pl['products_linking_id'], $pl['links_id'], true, true);
                } else {
 //$brand_allowed = array('3', '24', '23', '7');
 $upload_image_log = array();
 $active_log = array();
 $active_log['0'] = array();
 $active_log['1'] = array();
 $nousableimage = array();
 $brandisnotallowed = array();
 $message_counter = array();
 //MessageID Increment Value
 $xmlrelationship = array();
 $accessories_data = array();
 $descriptions_data = array();
 $have_image_data = false;
 $temp_images = array();
 use_class('products_linking');
 $class_pl = new products_linking();
 $discounted_products = array();
 $count_products = 0;
 foreach ($products as $p) {
     $limit_products = 0;
     $count_products += 1;
     if ($limit_products > 0 && $count_products > $limit_products) {
         break;
     }
     //CHECK FOR NON ELLI PRODUCTS
     //if (!in_array($p['products_brand_id'], $brand_allowed)) $brandisnotallowed[] = $p['products_id'];
     //we don't need this anymore because amazon already has their own rule of what brand can be uploaded
     //GRAB IMAGES
     $product_images = array();
     if ($p['image_uploaded'] != '1') {
         //AMAZON NOT ALLOWED TAG OR TEXT IN PRODUCTS IMAGES ~ CLEAR IMAGES