Пример #1
1
 /**
  * Setup next_step action
  *
  * @param  array $cart_settings     Cart settings
  * @param  array $database_settings Database settings
  * @param  array $server_settings   Server settings
  * @return bool  Always true
  */
 public function actionNextStep($cart_settings, $database_settings, $server_settings)
 {
     $app = App::instance();
     $validator = new Validator();
     if ($validator->validateAll(array_merge($cart_settings, $server_settings, $database_settings))) {
         fn_set_progress('parts', 14);
         set_time_limit(0);
         if ($app->connectToDB($database_settings['host'], $database_settings['name'], $database_settings['user'], $database_settings['password'], $database_settings['table_prefix'], $database_settings['database_backend'])) {
             $app->setToStorage('database_settings', $database_settings);
             define('CART_LANGUAGE', $cart_settings['main_language']);
             define('DESCR_SL', $cart_settings['main_language']);
             define('CART_SECONDARY_CURRENCY', 'NULL');
             // Need for cache_level
             $sCart = new Setup($cart_settings, $server_settings, $database_settings, $this->isDemoInstall($cart_settings));
             $sAddons = new AddonsSetup();
             /* Setup Scheme */
             fn_set_progress('title', $app->t('setup_scheme'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 2000);
             $sCart->setupScheme();
             /* Setup Scheme Data */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_data'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 5000);
             $sCart->setupData();
             $sCart->setSimpleMode();
             /* Setup Demo */
             if ($this->isDemoInstall($cart_settings)) {
                 fn_set_progress('step_scale', 1);
                 fn_set_progress('title', $app->t('setup_demo'));
                 fn_set_progress('echo', $app->t('installing_demo_catalog'), true);
                 fn_set_progress('step_scale', 5000);
                 $sCart->setupDemo();
             } else {
                 fn_set_progress('step_scale', 1);
                 fn_set_progress('echo', $app->t('cleaning'), true);
                 $sCart->clean();
             }
             $sCart->setupUsers();
             /* Setup companies */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_companies'));
             fn_set_progress('echo', $app->t('processing'), true);
             $sCart->setupCompanies();
             /* Setup Languages */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_languages'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 1000);
             $sCart->setupLanguages($this->isDemoInstall($cart_settings));
             $sCart->setupThemes();
             /* Setup Add-ons */
             fn_set_progress('title', $app->t('setup_addons'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 100);
             $sAddons->setup($this->isDemoInstall($cart_settings), array());
             /* Write config */
             fn_set_progress('step_scale', 1);
             fn_set_progress('echo', $app->t('writing_config'), true);
             $sCart->writeConfig();
             $this->_prepareHttpData();
             $redirect_url = Registry::get('config.http_location') . '/install/index.php?dispatch=setup.complete';
             if (Registry::get('runtime.comet')) {
                 Registry::get('ajax')->assign('force_redirection', $redirect_url);
             } else {
                 fn_redirect($redirect_url);
             }
             exit;
         }
     } else {
         if (Registry::get('runtime.comet')) {
             exit;
         } else {
             $params['dispatch'] = 'setup.index';
             $params['cart_settings'] = $cart_settings;
             $params['database_settings'] = $database_settings;
             $params['server_settings'] = $server_settings;
             $app->run($params);
         }
     }
     return true;
 }
Пример #2
0
 public function generate($force = false)
 {
     $filename = $this->getFileName();
     if (!is_dir(dirname($filename))) {
         fn_mkdir(dirname($filename));
     }
     if ($force) {
         fn_rm($filename);
     }
     if (!file_exists($filename)) {
         fn_set_progress('echo', __('generating_xls'), false);
         $header = $data = array();
         $currencies = Registry::get('currencies');
         $currency = $currencies[CART_SECONDARY_CURRENCY];
         $currency_format = '#' . $currency['thousands_separator'] . '##0.' . str_repeat('0', $currency['decimals']);
         $currency_format = $currency['after'] == 'Y' ? $currency_format . $currency['symbol'] : $currency['symbol'] . $currency_format;
         foreach ($this->selected_fields as $field_id => $field_value) {
             $header[$this->price_schema['fields'][$field_id]['title']] = $field_id == 'price' ? $currency_format : 'string';
         }
         $this->writer->writeSheetHeader($this->sheet, $header);
         $this->render();
         $this->writer->writeToFile($filename);
     }
     return $filename;
 }
Пример #3
0
 /**
  * Gets products for printing and print them
  * @param array $params product search params
  */
 protected function processProducts($params)
 {
     $total = static::ITEMS_PER_PAGE;
     while (static::ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
         list($products, $search) = fn_get_products($params, static::ITEMS_PER_PAGE);
         $total = $search['total_items'];
         if ($params['page'] == 1) {
             fn_set_progress('parts', $total);
         }
         $get_images = !empty($this->selected_fields['image']);
         $_params = array('get_icon' => $get_images, 'get_detailed' => $get_images, 'get_options' => Registry::get('addons.price_list.include_options') == 'Y' ? true : false, 'get_discounts' => false);
         fn_gather_additional_products_data($products, $_params);
         $params['page']++;
         $this->printProductsBatch(true);
         foreach ($products as $product) {
             fn_set_progress('echo');
             if (Registry::get('addons.price_list.include_options') == 'Y' && $product['has_options']) {
                 $product = fn_price_list_get_combination($product);
                 foreach ($product['combinations'] as $c_id => $c_value) {
                     $product['price'] = $product['combination_prices'][$c_id];
                     $product['weight'] = $product['combination_weight'][$c_id];
                     $product['amount'] = $product['combination_amount'][$c_id];
                     $product['product_code'] = $product['combination_code'][$c_id];
                     $this->printProductRow($product, $c_value);
                 }
             } else {
                 $this->printProductRow($product);
             }
         }
         $this->printProductsBatch();
     }
 }
Пример #4
0
 /**
  * Installs addons
  *
  * @param  bool  $install_demo
  * @param  array $addons       List of addons to be installed, if empty will be installed addons according <auto_install> tag
  * @return bool  Always true
  */
 public function setup($install_demo = true, $addons = array())
 {
     $app = App::instance();
     Registry::set('customer_theme_path', Registry::get('config.dir.install_themes') . '/' . App::THEME_NAME);
     $addons = empty($addons) ? $this->_getAddons() : $addons;
     foreach ($addons as $addon_name) {
         if (fn_install_addon($addon_name, false, $install_demo)) {
             fn_set_progress('echo', $app->t('addon_installed', array('addon' => $addon_name)) . '<br/>', true);
         }
         Registry::set('runtime.database.errors', '');
     }
     return true;
 }
Пример #5
0
function fn_delete_localization($localization_ids)
{
    $loc_objects = fn_get_localization_objects();
    fn_set_progress('parts', sizeof($localization_ids) * sizeof($loc_objects));
    foreach ($localization_ids as $loc_id) {
        foreach ($loc_objects as $table) {
            fn_set_progress('echo', __('converting_data_in_table', array('[table]' => $table)));
            db_query("UPDATE ?:{$table} SET localization = ?p", fn_remove_from_set('localization', $loc_id));
        }
        db_query("DELETE FROM ?:localizations WHERE localization_id = ?i", $loc_id);
        db_query("DELETE FROM ?:localization_descriptions WHERE localization_id = ?i", $loc_id);
        db_query("DELETE FROM ?:localization_elements WHERE localization_id = ?i", $loc_id);
    }
    fn_set_notification('N', __('notice'), __('done'));
}
Пример #6
0
 /**
  * Displays message to appropriate output screen (console/display)
  *
  * @param string $message   Message text
  * @param string $title     Title text
  * @param bool   $next_step Move progress to next step
  */
 public static function display($message, $title = '', $next_step = true)
 {
     if (self::isConsole()) {
         if (!empty($title)) {
             echo $title . PHP_EOL . '================================================' . PHP_EOL;
         }
         echo $message . PHP_EOL;
         if ($next_step) {
             echo 'Step ' . self::$current_step . '/' . self::$steps . ' completed' . PHP_EOL;
         }
     } else {
         if (!empty($title)) {
             fn_set_progress('title', $title);
         }
         fn_set_progress('echo', $message, $next_step);
     }
     if ($next_step) {
         self::$current_step++;
     }
 }
Пример #7
0
 public function generate($force = false)
 {
     $filename = $this->getFileName();
     if (!is_dir(dirname($filename))) {
         fn_mkdir(dirname($filename));
     }
     if ($force) {
         fn_rm($filename);
     }
     // Min column width in percent
     $min_width = array('product' => 50, 'product_code' => 13, 'image' => 10);
     if (!file_exists($filename)) {
         $max_perc = 100;
         $field_count = count($this->selected_fields);
         // First step. Check for the min width.
         $perc = intval($max_perc / $field_count);
         foreach ($this->selected_fields as $field_name => $active) {
             if (isset($min_width[$field_name])) {
                 if ($min_width[$field_name] > $perc) {
                     $max_perc -= $min_width[$field_name];
                     $field_count--;
                 }
             }
         }
         // Second step. Set up the new width values.
         $perc = intval($max_perc / $field_count);
         foreach ($this->selected_fields as $field_name => $active) {
             if (!isset($min_width[$field_name]) || $min_width[$field_name] < $perc) {
                 $this->price_schema['fields'][$field_name]['min_width'] = $perc;
             } else {
                 $this->price_schema['fields'][$field_name]['min_width'] = $min_width[$field_name];
             }
         }
         fn_set_progress('echo', __('generating_pdf'), false);
         $this->render();
     }
     return $filename;
 }
Пример #8
0
function fn_google_sitemap_check_counter(&$file, &$link_counter, &$file_counter, $links, $header, $footer, $type)
{
    $stat = fstat($file);
    if (count($links) + $link_counter > MAX_URLS_IN_MAP || $stat['size'] >= MAX_SIZE_IN_KBYTES * 1024) {
        fwrite($file, $footer);
        fclose($file);
        $file_counter++;
        $filename = fn_get_files_dir_path() . 'google_sitemap/sitemap' . $file_counter . '.xml';
        $file = fopen($filename, "wb");
        $link_counter = count($links);
        fwrite($file, $header);
    } else {
        $link_counter += count($links);
        fn_set_progress('echo', __($type));
    }
}
Пример #9
0
 /**
  * Sync ebay objects
  * @param int $site_id
  * @param int $category_id
  * @return bool
  */
 public static function synchronizationObjects($site_id, $category_id)
 {
     @set_time_limit(600);
     $start_time = fn_get_storage_data('ebay_synchronization_start_time');
     if (!empty($start_time) && $start_time > strtotime('-10 minutes')) {
         $time = time();
         $current_step = fn_get_storage_data('ebay_synchronization_step');
         $count_steps = fn_get_storage_data('ebay_synchronization_step_count');
         fn_set_progress('title', __('ebay_synchronization_title'));
         fn_set_progress('parts', $count_steps);
         for ($i = 1; $i < $current_step; $i++) {
             fn_set_progress('echo', '.');
         }
         fn_set_progress('echo', fn_get_storage_data('ebay_synchronization_step_title'), false);
         while (true) {
             //TODO move logic to same function fn_get_storage_data
             Registry::del('storage_data.ebay_synchronization_step');
             Registry::del('storage_data.ebay_synchronization_step_title');
             $step = fn_get_storage_data('ebay_synchronization_step');
             if (empty($step)) {
                 return true;
             }
             if ($step != $current_step) {
                 fn_set_progress('echo', '.');
                 fn_set_progress('echo', fn_get_storage_data('ebay_synchronization_step_title'), false);
                 $current_step = $step;
             }
             if ($time < strtotime('-10 minutes')) {
                 return true;
             }
             sleep(1);
         }
         return true;
     }
     $objects = fn_ebay_get_objects_needed_synchronization($site_id, $category_id);
     if (!empty($objects)) {
         $current_step = 1;
         register_shutdown_function(function () {
             fn_set_storage_data('ebay_synchronization_start_time', null);
             fn_set_storage_data('ebay_synchronization_step_title', null);
             fn_set_storage_data('ebay_synchronization_step', null);
             fn_set_storage_data('ebay_synchronization_step_count', null);
         });
         fn_set_storage_data('ebay_synchronization_start_time', time());
         fn_set_storage_data('ebay_synchronization_step_count', count($objects));
         fn_set_storage_data('ebay_synchronization_step', $current_step);
         fn_set_progress('title', __('ebay_synchronization_title'));
         fn_set_progress('parts', count($objects));
         if (in_array('Site', $objects)) {
             fn_set_progress('echo', __('ebay_synchronization_regions'), false);
             fn_set_storage_data('ebay_synchronization_step_title', __('ebay_synchronization_regions'));
             Site::synchronization();
             fn_set_storage_data('ebay_synchronization_step', ++$current_step);
             fn_set_progress('echo', '.');
         }
         if (in_array('Category', $objects)) {
             fn_set_progress('echo', __('ebay_synchronization_categories'), false);
             fn_set_storage_data('ebay_synchronization_step_title', __('ebay_synchronization_categories'));
             Category::synchronization($site_id);
             fn_set_storage_data('ebay_synchronization_step', ++$current_step);
             fn_set_progress('echo', '.');
         }
         if (in_array('Shipping', $objects)) {
             fn_set_progress('echo', __('ebay_synchronization_shipping_services'), false);
             fn_set_storage_data('ebay_synchronization_step_title', __('ebay_synchronization_shipping_services'));
             Shipping::synchronization($site_id);
             fn_set_storage_data('ebay_synchronization_step', ++$current_step);
             fn_set_progress('echo', '.');
         }
         if (in_array('CategoryFeature', $objects)) {
             fn_set_progress('echo', __('ebay_synchronization_category_features'), false);
             fn_set_storage_data('ebay_synchronization_step_title', __('ebay_synchronization_category_features'));
             CategoryFeature::synchronization($site_id, $category_id);
             fn_set_storage_data('ebay_synchronization_step', ++$current_step);
             fn_set_progress('echo', '.');
         }
     }
     return true;
 }
Пример #10
0
         if (fn_copy($dump['path'], Registry::get('config.dir.backups') . $dump['name'])) {
             fn_set_notification('N', __('notice'), __('done'));
         } else {
             fn_set_notification('E', __('error'), __('cant_create_backup_file'));
         }
     } else {
         fn_set_notification('E', __('error'), __('cant_upload_file'));
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
     fn_set_progress('parts', sizeof($all_tables));
     foreach ($all_tables as $table) {
         fn_set_progress('echo', __('optimizing_table') . "&nbsp;<b>{$table}</b>...<br />");
         db_query("OPTIMIZE TABLE {$table}");
         db_query("ANALYZE TABLE {$table}");
         $fields = db_get_hash_array("SHOW COLUMNS FROM {$table}", 'Field');
         if (!empty($fields['is_global'])) {
             // Sort table by is_global field
             fn_echo('.');
             db_query("ALTER TABLE {$table} ORDER BY is_global DESC");
         } elseif (!empty($fields['position'])) {
             // Sort table by position field
             fn_echo('.');
             db_query("ALTER TABLE {$table} ORDER BY position");
         }
     }
     fn_set_notification('N', __('notice'), __('done'));
 }
Пример #11
0
/**
 * Recursively copy directory (or just a file)
 *
 * @param string $source
 * @param string $dest
 * @param bool $silent
 * @param array $exclude_files
 * @return bool True on success, false otherwise
 */
function fn_copy($source, $dest, $silent = true, $exclude_files = array())
{
    /**
     * Ability to forbid file copy or change parameters
     *
     * @param string  $source  source file/directory
     * @param string  $dest    destination file/directory
     * @param boolean $silent  silent flag
     * @param array   $exclude files to exclude
     */
    fn_set_hook('copy_file', $source, $dest, $silent, $exclude_files);
    if (empty($source)) {
        return false;
    }
    // Simple copy for a file
    if (is_file($source)) {
        $source_file_name = fn_basename($source);
        if (in_array($source_file_name, $exclude_files)) {
            return true;
        }
        if (@is_dir($dest)) {
            $dest .= '/' . $source_file_name;
        }
        if (filesize($source) == 0) {
            $fd = fopen($dest, 'w');
            fclose($fd);
            $res = true;
        } else {
            $res = @copy($source, $dest);
        }
        @chmod($dest, DEFAULT_FILE_PERMISSIONS);
        clearstatcache(true, $dest);
        return $res;
    }
    // Make destination directory
    if ($silent == false) {
        $_dir = strpos($dest, Registry::get('config.dir.root')) === 0 ? str_replace(Registry::get('config.dir.root') . '/', '', $dest) : $dest;
        fn_set_progress('echo', $_dir . '<br/>');
    }
    if (!fn_mkdir($dest)) {
        return false;
    }
    // Loop through the folder
    if (@is_dir($source)) {
        $dir = dir($source);
        while (false !== ($entry = $dir->read())) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            // Deep copy directories
            if ($dest !== $source . '/' . $entry) {
                if (fn_copy($source . '/' . $entry, $dest . '/' . $entry, $silent, $exclude_files) == false) {
                    return false;
                }
            }
        }
        // Clean up
        $dir->close();
        return true;
    } else {
        return false;
    }
}
Пример #12
0
function fn_restore_dump($files)
{
    if (empty($files)) {
        return false;
    }
    fn_set_progress('parts', sizeof($files));
    foreach ($files as $file) {
        $is_archive = false;
        $list = array($file);
        if (in_array(fn_get_file_ext($file), array('zip', 'tgz'))) {
            $is_archive = true;
            fn_decompress_files(Registry::get('config.dir.database') . $file, Registry::get('config.dir.database') . '_tmp');
            $list = fn_get_dir_contents(Registry::get('config.dir.database') . '_tmp', false, true, 'sql', '_tmp/');
        }
        foreach ($list as $_file) {
            db_import_sql_file(Registry::get('config.dir.database') . $_file);
        }
        if ($is_archive) {
            fn_rm(Registry::get('config.dir.database') . '_tmp');
        }
    }
    // Log database restore
    fn_log_event('database', 'restore');
    fn_set_hook('database_restore', $files);
    fn_clear_cache();
    return true;
}
Пример #13
0
 /**
  * Puts list of local files to storage
  *
  * @param  array   $list   files list (relative path)
  * @param  string  $prefix absolute path prefix
  * @param  array   $params additional parameters list
  * @return boolean true on success, false if at least one put was failed
  */
 public function putList($list, $prefix, $params = array())
 {
     if (!empty($list)) {
         fn_set_progress('step_scale', sizeof($list));
         foreach ($list as $item) {
             fn_set_progress('echo', '.');
             if (strpos($prefix, '://') !== false) {
                 $params['contents'] = fn_get_contents($prefix . $item);
             } else {
                 $params['file'] = $prefix . $item;
                 $params['keep_origins'] = true;
             }
             if (!$this->put($item, $params)) {
                 return false;
             }
         }
     }
     return true;
 }
Пример #14
0
/**
 * Installs theme files
 *
 * @param string $source_theme source theme name
 * @param string $dest_theme destination theme name
 * @param boolean $from_repo flag, if set to true, theme files are copied from themes_repository
 * @return boolean true if theme was installed, false otherwise
 */
function fn_install_theme_files($source_theme, $dest_theme, $from_repo = true)
{
    $path_dest = fn_get_theme_path('[themes]/' . $dest_theme, 'C');
    if (!fn_is_theme_installed($dest_theme)) {
        if (!fn_mkdir($path_dest)) {
            fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($path_dest))));
            return false;
        }
        $path_repo_base = '';
        if ($from_repo) {
            $path_repo = fn_get_theme_path('[repo]/' . $source_theme, 'C');
            $manifest = Themes::factory($source_theme)->getRepoManifest();
            $parent_theme = isset($manifest['parent_theme']) ? $manifest['parent_theme'] : Registry::get('config.base_theme');
            if (!empty($parent_theme) && $source_theme != $parent_theme) {
                $path_repo_base = fn_get_theme_path('[repo]/' . $parent_theme, 'C');
            }
        } else {
            $path_repo = fn_get_theme_path('[themes]/' . $source_theme, 'C');
        }
        fn_set_progress('parts', fn_dirs_count($path_repo_base) + fn_dirs_count($path_repo) + 1);
        // FIXME: Backward compatibility. Create manifest.json if theme only has manifest.ini
        if (file_exists($path_repo . '/' . THEME_MANIFEST_INI) && !file_exists($path_repo . '/' . THEME_MANIFEST)) {
            $content = parse_ini_file($path_repo . '/' . THEME_MANIFEST_INI);
            fn_put_contents($path_repo . '/' . THEME_MANIFEST, json_encode($content));
        }
        if (!empty($path_repo_base)) {
            fn_copy($path_repo_base, $path_dest, false);
            // Clear layouts and styles data
            fn_rm($path_dest . '/styles');
            fn_rm($path_dest . '/layouts');
            // FIXME: Backward compatibility
            fn_rm($path_dest . '/presets');
        }
        fn_copy($path_repo, $path_dest, false);
    }
    // Re-install add-ons template files
    list($installed_addons) = fn_get_addons(array('type' => 'installed'));
    foreach ($installed_addons as $addon) {
        fn_install_addon_templates($addon['addon']);
    }
    return true;
}
Пример #15
0
 /**
  * Put directory to storage
  *
  * @param  string  $dir    directory to get files from
  * @param  array   $params additional parameters
  * @return boolean true of success, false on fail
  */
 public function putDir($dir, $params = array())
 {
     $s3 = $this->s3();
     // get object to initialize class and get access to contstants below
     $i = 0;
     $max_batch = 10;
     $files = fn_get_dir_contents($dir, false, true, '', '', true);
     fn_set_progress('step_scale', sizeof($files));
     foreach ($files as $source_file) {
         fn_set_progress('echo', '.');
         $i++;
         $data = array('acl' => \AmazonS3::ACL_PUBLIC, 'headers' => array());
         // File can not be accessible via direct link
         if ($this->getOption('secured')) {
             $data['headers']['Content-disposition'] = 'attachment; filename="' . fn_basename($source_file) . '"';
             $data['acl'] = \AmazonS3::ACL_PRIVATE;
         }
         $data['contentType'] = fn_get_file_type($source_file);
         $data['fileUpload'] = $dir . '/' . $source_file;
         $res = $s3->batch()->create_object($this->getOption('bucket'), $this->prefix($source_file), $data);
         if ($i == $max_batch) {
             $s3->batch()->send();
             $i = 0;
         }
     }
     if (!empty($i)) {
         $s3->batch()->send();
         // send the rest of the batch
     }
     return true;
 }
Пример #16
0
function fn_export_ebay_products($template, $product_ids, $auth)
{
    $parts = floor(count($product_ids) / 5) + 1;
    fn_set_progress('parts', $parts);
    $data = array();
    $i = 1;
    $j = 0;
    $success = true;
    foreach ($product_ids as $product_id) {
        fn_echo(' .');
        $data[$product_id] = fn_get_product_data($product_id, $auth, CART_LANGUAGE);
        fn_gather_additional_product_data($data[$product_id], true, true);
        $data[$product_id]['ebay_item_id'] = db_get_field('SELECT ebay_item_id FROM ?:ebay_template_products WHERE product_id = ?i AND template_id = ?i', $product_id, $template['template_id']);
        if ($data[$product_id]['ebay_item_id']) {
            fn_set_progress('echo', '<br />' . __('exporting_images_to_ebay'));
            $images_data = Ebay::instance()->UploadImages(array($data[$product_id]));
            list($transaction_id, $result, $error_code) = Ebay::instance()->ReviseItem($data[$product_id], $template, $images_data);
            if (!empty($result)) {
                if (!$error_code) {
                    $_data = array('ebay_item_id' => $data[$product_id]['ebay_item_id'], 'template_id' => $template['template_id'], 'product_id' => $product_id, 'product_hash' => fn_ebay_calculate_item_hash($data[$product_id]));
                    db_query('REPLACE INTO ?:ebay_template_products ?e', $_data);
                } elseif ($error_code == 291) {
                    //listing time is over, we should relist item.
                    list($transaction_id, $result, $error_code) = Ebay::instance()->RelistItem($data[$product_id], $template, $images_data);
                    if (!$error_code) {
                        //Since the RelistItem return new ItemId we should remove old data.
                        db_query("DELETE FROM ?:ebay_template_products WHERE ebay_item_id = ?i", $data[$product_id]['ebay_item_id']);
                        $_data = array('ebay_item_id' => (int) $result->ItemID, 'template_id' => $template['template_id'], 'product_id' => $product_id, 'product_hash' => fn_ebay_calculate_item_hash($data[$product_id]));
                        db_query('REPLACE INTO ?:ebay_template_products ?e', $_data);
                    } else {
                        $success = false;
                    }
                } else {
                    $success = false;
                }
            }
            unset($data[$product_id]);
            continue;
        }
    }
    if (!empty($data)) {
        fn_set_progress('echo', '<br />' . __('exporting_images_to_ebay'));
        $images_data = Ebay::instance()->UploadImages($data);
        fn_set_progress('echo', '<br />' . __('exporting_products_to_ebay'));
        $_data = array_chunk($data, 5);
        foreach ($_data as $products_data) {
            list($transaction_id, $result) = Ebay::instance()->AddItems($products_data, $template, $images_data);
            if (!empty($result)) {
                foreach ($result as $item_key => $item) {
                    $_data = array('ebay_item_id' => $item['ItemID'], 'template_id' => $template['template_id'], 'product_id' => $products_data[$item_key]['product_id'], 'product_hash' => $item['product_hash']);
                    db_query('REPLACE INTO ?:ebay_template_products ?e', $_data);
                }
            } else {
                $success = false;
            }
        }
    }
    if ($success) {
        fn_set_notification('N', __('successful'), __('ebay_success_products_notice'));
    }
    return $success;
}
Пример #17
0
 public static function import($store_data, $actualize_data = false)
 {
     set_time_limit(0);
     ini_set('memory_limit', '1024M');
     fn_define('STORE_IMPORT', true);
     fn_define('DISABLE_HOOK_CACHE', true);
     $log_dir = Registry::get('config.dir.store_import');
     fn_mkdir($log_dir);
     $logger = \Tygh\Logger::instance();
     $logger->logfile = $log_dir . date('Y-m-d_H-i') . '.log';
     if ($actualize_data) {
         $logos = self::_backupLogos();
     }
     $import_classes_cascade = self::getImportClassesCascade($store_data);
     $db_already_cloned = false;
     Registry::set('runtime.skip_sharing_selection', true);
     self::_removeTempTables();
     self::_setUnavailableLangVars();
     if (!$actualize_data) {
         self::_uninstallAllAddons();
     }
     fn_set_progress('parts', count($import_classes_cascade) * 6 + 2);
     $result = !empty($import_classes_cascade) ? true : false;
     self::setDefaultLanguage($store_data);
     $store_data['skin_name'] = self::setDefaultSkinName($store_data);
     $theme_to_be_installed = db_get_field("SELECT value FROM ?:settings_vendor_values WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'theme_name')");
     if (empty($theme_to_be_installed)) {
         $theme_to_be_installed = db_get_field("SELECT value FROM ?:settings_objects WHERE name = 'theme_name'");
     }
     $style_id_to_be_installed = db_get_field("SELECT style_id FROM ?:bm_layouts WHERE is_default = '1'");
     foreach ($import_classes_cascade as $class_name) {
         if ($result) {
             if (class_exists($class_name)) {
                 $obj = new $class_name($store_data);
                 $result = $db_already_cloned = $obj->import($db_already_cloned);
                 Settings::instance()->reloadSections();
             } else {
                 $result = false;
                 fn_set_notification('E', __('error'), __('store_import.class_not_found'));
                 break;
             }
         } else {
             fn_set_notification('E', __('error'), __('store_import.import_failed'));
             break;
         }
     }
     Registry::set('runtime.skip_sharing_selection', false);
     if ($result) {
         if (fn_allowed_for('ULTIMATE')) {
             General::setForcedCompanyId();
         }
         General::setLicenseData();
         //First, we should install all addons from old version in the new version that all templates, etc were installed in the new version
         self::installAddons();
         //Next, we should install all tabs in the upgraded database (mostly for the old version, 2.2.x)
         self::installAddonsTabs();
         if (fn_allowed_for('ULTIMATE')) {
             General::ultProcessImages($store_data);
         } else {
             General::mveProcessImages($store_data);
         }
         General::processFiles($store_data, 'downloads');
         General::processFiles($store_data, 'attachments');
         General::processFiles($store_data, 'custom_files');
         fn_clear_cache();
         if (!$actualize_data) {
             self::_removeRussianServices($store_data);
             General::uninstallAddons(array('twigmo', 'searchanise', 'live_help', 'exim_store', 'webmail'));
             /*
                             if (fn_allowed_for('ULTIMATE')) {
                $company_ids = db_get_fields("SELECT company_id FROM ?:companies");
                foreach ($company_ids as $company_id) {
                    self::_installTheme($company_id);
                }
                             } else {
                self::_installTheme();
                             }
             */
             db_query("UPDATE ?:settings_objects SET value = '{$theme_to_be_installed}' WHERE name = 'theme_name'");
             db_query("UPDATE ?:settings_vendor_values SET value = '{$theme_to_be_installed}' WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'theme_name')");
             db_query("UPDATE ?:bm_layouts SET style_id = '{$style_id_to_be_installed}'");
             db_query("UPDATE ?:bm_layouts SET theme_name  = '{$theme_to_be_installed}'");
         }
         self::replaceOriginalDB($store_data, $actualize_data);
         fn_install_addon('store_import', false);
         fn_uninstall_addon('twigmo', false);
         self::_removeTempTables();
         if (defined('AJAX_REQUEST')) {
             Registry::get('ajax')->assign('non_ajax_notifications', true);
             Registry::get('ajax')->assign('force_redirection', fn_url('index.index'));
         }
         if ($actualize_data) {
             self::_restoreLogos($logos);
         }
         fn_set_progress('step_scale', '1');
         fn_set_progress('echo', __('store_import.done'), true);
         return true;
     }
     return false;
 }
Пример #18
0
 public static function import($store_data, $actualize_data = false)
 {
     set_time_limit(0);
     ini_set('memory_limit', '1024M');
     fn_define('STORE_IMPORT', true);
     $log_dir = Registry::get('config.dir.store_import');
     fn_mkdir($log_dir);
     $logger = \Tygh\Logger::instance();
     $logger->logfile = $log_dir . date('Y-m-d_H-i') . '.log';
     if ($actualize_data) {
         $logos = self::_backupLogos();
     }
     $import_classes_cascade = self::getImportClassesCascade($store_data);
     $db_already_cloned = false;
     Registry::set('runtime.skip_sharing_selection', true);
     self::_removeTempTables();
     self::_setUnavailableLangVars();
     if (!$actualize_data) {
         self::_uninstallAllAddons();
     }
     fn_set_progress('parts', count($import_classes_cascade) * 6 + 2);
     $result = !empty($import_classes_cascade) ? true : false;
     self::setDefaultLanguage($store_data);
     foreach ($import_classes_cascade as $class_name) {
         if ($result) {
             if (class_exists($class_name)) {
                 $obj = new $class_name($store_data);
                 $result = $db_already_cloned = $obj->import($db_already_cloned);
                 Settings::instance()->reloadSections();
             } else {
                 $result = false;
                 fn_set_notification('E', __('error'), __('store_import.class_not_found'));
                 break;
             }
         } else {
             fn_set_notification('E', __('error'), __('store_import.import_failed'));
             break;
         }
     }
     Registry::set('runtime.skip_sharing_selection', false);
     if ($result) {
         General::setLicenseData();
         //First, we should install all addons from old version in the new version that all templates, etc were installed in the new version
         self::installAddons();
         //Next, we should install all tabs in the upgraded database (mostly for the old version, 2.2.x)
         self::installAddonsTabs();
         fn_clear_cache();
         if (!$actualize_data) {
             self::_removeRussianServices($store_data);
             if (fn_allowed_for('ULTIMATE')) {
                 $company_ids = db_get_fields("SELECT company_id FROM ?:companies");
                 foreach ($company_ids as $company_id) {
                     self::_installTheme($company_id);
                 }
             } else {
                 self::_installTheme();
             }
         }
         self::replaceOriginalDB($store_data, $actualize_data);
         fn_install_addon('store_import', false);
         self::_removeTempTables();
         if (defined('AJAX_REQUEST')) {
             Registry::get('ajax')->assign('non_ajax_notifications', true);
             Registry::get('ajax')->assign('force_redirection', fn_url('index.index'));
         }
         if ($actualize_data) {
             self::_restoreLogos($logos);
         }
         fn_set_progress('step_scale', '1');
         fn_set_progress('echo', __('store_import.done'), true);
         return true;
     }
     return false;
 }
Пример #19
0
                 }
             }
         }
     }
     $suffix = ".details?order_id={$_REQUEST['order_id']}";
 }
 if ($mode == 'bulk_print' && !empty($_REQUEST['order_ids'])) {
     fn_print_order_invoices($_REQUEST['order_ids'], Registry::get('runtime.dispatch_extra') == 'pdf');
     exit;
 }
 if ($mode == 'packing_slip' && !empty($_REQUEST['order_ids'])) {
     fn_print_order_packing_slips($_REQUEST['order_ids'], Registry::get('runtime.dispatch_extra') == 'pdf');
     exit;
 }
 if ($mode == 'remove_cc_info' && !empty($_REQUEST['order_ids'])) {
     fn_set_progress('parts', sizeof($_REQUEST['order_ids']));
     foreach ($_REQUEST['order_ids'] as $v) {
         $payment_info = db_get_field("SELECT data FROM ?:order_data WHERE order_id = ?i AND type = 'P'", $v);
         fn_cleanup_payment_info($v, $payment_info);
     }
     fn_set_notification('N', __('notice'), __('done'));
     if (count($_REQUEST['order_ids']) == 1) {
         $o_id = array_pop($_REQUEST['order_ids']);
         $suffix = ".details?order_id={$o_id}";
     } else {
         exit;
     }
 }
 if ($mode == 'export_range') {
     if (!empty($_REQUEST['order_ids'])) {
         if (empty($_SESSION['export_ranges'])) {
function fn_exim_put_product_combination($product_id, $product_name, $combination_code, $combination, $amount, &$counter, $set_delimiter, $lang_code)
{
    $pair_delimiter = ':';
    if (!empty($combination)) {
        // Get product_id
        $object_id = 0;
        if (!empty($product_id)) {
            $object_exists = db_get_field('SELECT COUNT(*) FROM ?:products WHERE product_id = ?i', $product_id);
            if ($object_exists) {
                $object_id = $product_id;
            }
        }
        if (empty($object_id) && !empty($product_name)) {
            $object_id = db_get_field('SELECT product_id FROM ?:product_descriptions WHERE product = ?s AND lang_code = ?s', $product_name[$lang_code], $lang_code);
        }
        if (empty($object_id)) {
            $counter['S']++;
            return false;
        }
        $options = array();
        $_options = explode($set_delimiter, $combination);
        foreach ($_options as $key => $value) {
            $options[$key][$lang_code] = $value;
        }
        if (!empty($options)) {
            $_combination = array();
            foreach ($options as $option_pair) {
                $pair = explode($pair_delimiter, $option_pair[$lang_code]);
                if (is_array($pair)) {
                    array_walk($pair, 'fn_trim_helper');
                    $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $object_id, $pair[0], $lang_code);
                    if (empty($option_id)) {
                        // Search for the global product options
                        $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", 0, $pair[0], $lang_code);
                    }
                    $variant_id = db_get_field("SELECT v.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as v ON v.variant_id = d.variant_id AND v.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $option_id, $pair[1], $lang_code);
                    // Checkboxed do not have descriptions
                    if (empty($variant_id) && in_array($pair[1], array('Yes', 'No'))) {
                        $variant_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE option_id = ?i AND position = ?i LIMIT 1", $option_id, $pair[1] == 'Yes' ? 1 : 0);
                    }
                    if (empty($option_id) || empty($variant_id)) {
                        $counter['S']++;
                        return false;
                    }
                    $_combination[$option_id] = $variant_id;
                }
            }
            $combination = fn_get_options_combination($_combination);
            $combination_hash = fn_generate_cart_id($object_id, array('product_options' => $_combination));
            $object_details = db_get_row('SELECT COUNT(*) as count, amount FROM ?:product_options_inventory WHERE combination_hash = ?i AND product_id = ?i', $combination_hash, $object_id);
            $_data = array('product_id' => $object_id, 'product_code' => $combination_code, 'combination_hash' => $combination_hash, 'combination' => $combination, 'amount' => $amount);
            if ($object_details['count']) {
                if ($object_details['amount'] <= 0 && $_data['amount'] > 0) {
                    fn_send_product_notifications($object_id);
                }
                db_query('UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?i', $_data, $combination_hash);
                fn_set_progress('echo', __('updating') . ' ' . __('product_combinations') . '...', false);
                $counter['E']++;
            } else {
                db_query('INSERT INTO ?:product_options_inventory ?e', $_data);
                fn_set_progress('echo', __('creating') . ' ' . __('product_combinations') . '...', false);
                $counter['N']++;
            }
            fn_set_progress('echo', '<b>' . $object_id . '</b>.<br />', false);
            return $combination_hash;
        }
    }
    $counter['S']++;
    return false;
}
Пример #21
0
function fn_import_feature($data, &$processed_data, &$skip_record, $category_delimiter = '///')
{
    static $new_groups = array();
    $skip_record = true;
    $feature = reset($data);
    $langs = array_keys($data);
    $main_lang = reset($langs);
    if (Registry::get('runtime.company_id')) {
        $company_id = Registry::get('runtime.company_id');
    } else {
        if (!empty($feature['company'])) {
            $company_id = fn_get_company_id_by_name($feature['company']);
        } else {
            $company_id = isset($feature['company_id']) ? $feature['company_id'] : Registry::get('runtime.company_id');
        }
    }
    if (!empty($feature['feature_id'])) {
        $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features WHERE feature_id = ?i', $feature['feature_id']);
    }
    $parent_id = fn_exim_get_product_feature_group_id($feature['parent_id'], $company_id, $new_groups, $main_lang);
    if (empty($feature_id)) {
        $condition = db_quote("WHERE description = ?s AND lang_code = ?s AND feature_type = ?s", $feature['description'], $main_lang, $feature['feature_type']);
        $condition .= db_quote(" AND parent_id = ?i", $parent_id);
        $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features_descriptions ' . 'LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_features_descriptions.feature_id ' . $condition);
    }
    unset($feature['feature_id']);
    $feature['company_id'] = $company_id;
    $feature['parent_id'] = $parent_id;
    $feature['variants'] = array();
    if (!empty($feature['Variants'])) {
        $variants = str_getcsv($feature['Variants'], ',', "'");
        array_walk($variants, 'fn_trim_helper');
        list($origin_variants) = fn_get_product_feature_variants(array('feature_id' => $feature_id), 0, $main_lang);
        $feature['original_var_ids'] = implode(',', array_keys($origin_variants));
        foreach ($variants as $variant) {
            $feature['variants'][]['variant'] = $variant;
        }
    }
    $skip = false;
    if (empty($feature_id)) {
        $feature_id = fn_update_product_feature($feature, 0, $main_lang);
        $processed_data['N']++;
        fn_set_progress('echo', __('updating') . ' features <b>' . $feature_id . '</b>. ', false);
    } else {
        if (!fn_check_company_id('product_features', 'feature_id', $feature_id)) {
            $processed_data['S']++;
            $skip = true;
        } else {
            // Convert categories from Names to C_IDS: Electronics,Processors -> 3,45
            $_data = $feature;
            $_data['categories_path'] = fn_exim_get_features_convert_category_path($feature, $main_lang, $category_delimiter);
            fn_update_product_feature($_data, $feature_id, $main_lang);
            if (in_array($feature_id, $new_groups)) {
                $processed_data['N']++;
            } else {
                $processed_data['E']++;
                fn_set_progress('echo', __('creating') . ' features <b>' . $feature_id . '</b>. ', false);
            }
        }
    }
    if (!$skip) {
        fn_exim_set_product_feature_categories($feature_id, $feature, $main_lang, $category_delimiter);
        foreach ($data as $lang_code => $feature_data) {
            unset($feature_data['feature_id']);
            db_query('UPDATE ?:product_features_descriptions SET ?u WHERE feature_id = ?i AND lang_code = ?s', $feature_data, $feature_id, $lang_code);
        }
        if (fn_allowed_for('ULTIMATE')) {
            if (!empty($company_id)) {
                fn_exim_update_share_feature($feature_id, $company_id);
            }
        }
    }
    return $feature_id;
}
Пример #22
0
function fn_export($pattern, $export_fields, $options)
{
    if (empty($pattern) || empty($export_fields)) {
        return false;
    }
    // Languages
    if (!empty($options['lang_code'])) {
        $multi_lang = $options['lang_code'];
        $count_langs = count($multi_lang);
    } else {
        $multi_lang = array(DEFAULT_LANGUAGE);
        $count_langs = 1;
        $options['lang_code'] = $multi_lang;
    }
    $can_continue = true;
    if (!empty($pattern['export_pre_moderation'])) {
        $data_export_pre_moderation = array('pattern' => &$pattern, 'export_fields' => &$export_fields, 'options' => &$options, 'can_continue' => &$can_continue);
        fn_exim_processing('export', $pattern['export_pre_moderation'], $options, $data_export_pre_moderation);
    }
    if (!$can_continue) {
        return false;
    }
    if (!empty($pattern['pre_processing'])) {
        fn_exim_processing('export', $pattern['pre_processing'], $options);
    }
    if (isset($options['fields_names'])) {
        if ($options['fields_names']) {
            $fields_names = $export_fields;
            $export_fields = array_keys($export_fields);
        }
    }
    $primary_key = array();
    $_primary_key = $pattern['key'];
    foreach ($_primary_key as $key) {
        $primary_key[$key] = $key;
    }
    array_walk($primary_key, 'fn_attach_value_helper', $pattern['table'] . '.');
    $table_fields = $primary_key;
    $processes = array();
    // Build list of fields that should be retrieved from the database
    fn_export_build_retrieved_fields($processes, $table_fields, $pattern, $export_fields);
    if (empty($pattern['export_fields']['multilang'])) {
        $multi_lang = array(DEFAULT_LANGUAGE);
        $count_langs = 1;
        $options['lang_code'] = $multi_lang;
    }
    // Build the list of joins
    $joins = fn_export_build_joins($pattern, $options, $primary_key, $multi_lang);
    // Add retrieve conditions
    $conditions = fn_export_build_conditions($pattern, $options);
    if (!empty($pattern['pre_export_process'])) {
        $pre_export_process_data = array('pattern' => &$pattern, 'export_fields' => &$export_fields, 'options' => &$options, 'conditions' => &$conditions, 'joins' => &$joins, 'table_fields' => &$table_fields, 'processes' => &$processes);
        fn_exim_processing('export', $pattern['pre_export_process'], $options, $pre_export_process_data);
    }
    $total = db_get_field("SELECT COUNT(*) FROM ?:" . $pattern['table'] . " as " . $pattern['table'] . ' ' . implode(' ', $joins) . (!empty($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : ''));
    fn_set_progress('parts', $total);
    fn_set_progress('step_scale', 1);
    $sorting = '';
    if (!empty($pattern['order_by'])) {
        $sorting = ' ORDER BY ' . $pattern['order_by'];
    }
    // Build main query
    $query = "SELECT " . implode(', ', $table_fields) . " FROM ?:" . $pattern['table'] . " as " . $pattern['table'] . ' ' . implode(' ', $joins) . (!empty($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : '') . $sorting;
    $step = fn_floor_to_step(DB_LIMIT_SELECT_ROW, $count_langs);
    // define number of rows to get from database
    $iterator = 0;
    // start retrieving from
    $progress = 0;
    $data_exported = false;
    $main_lang = reset($multi_lang);
    $manual_multilang = true;
    $field_lang = '';
    foreach ($pattern['export_fields']['multilang'] as $key => $value) {
        if (array_search('languages', $value, true)) {
            if (!isset($value['linked']) || $value['linked'] === true) {
                $manual_multilang = false;
            }
            $field_lang = $key;
            break;
        }
    }
    if (empty($field_lang) || !in_array($field_lang, $export_fields)) {
        $multi_lang = array($main_lang);
        $count_langs = 1;
    }
    while ($data = db_get_array($query . " LIMIT {$iterator}, {$step}")) {
        $data_exported = true;
        if ($manual_multilang) {
            $data_lang = $data;
            $data = array();
            foreach ($data_lang as $data_key => $data_value) {
                $data[] = array_combine($multi_lang, array_fill(0, $count_langs, $data_value));
            }
        } else {
            $data_lang = array_chunk($data, $count_langs);
            $data = array();
            foreach ($data_lang as $data_key => $data_value) {
                // Sort
                foreach ($multi_lang as $lang_code) {
                    foreach ($data_value as $v) {
                        if (array_search($lang_code, $v, true)) {
                            $data[$data_key][$lang_code] = $v;
                        }
                    }
                }
            }
        }
        $result = array();
        foreach ($data as $k => $v) {
            $progress += $count_langs;
            fn_set_progress('echo', __('exporting_data') . ':&nbsp;<b>' . $progress . '</b>');
            fn_export_fill_fields($result[$k], $v, $processes, $pattern, $options);
        }
        $_result = array();
        foreach ($result as $k => $v) {
            foreach ($multi_lang as $lang_code) {
                $_data = array();
                foreach ($export_fields as $field) {
                    if (isset($fields_names[$field])) {
                        $_data[$fields_names[$field]] = $v[$lang_code][$field];
                    } else {
                        $_data[$field] = isset($v[$lang_code][$field]) ? $v[$lang_code][$field] : '';
                    }
                }
                $_result[] = $_data;
            }
        }
        // Put data
        $enclosure = isset($pattern['enclosure']) ? $pattern['enclosure'] : '"';
        fn_echo(' .');
        if (isset($pattern['func_save_content_to_file']) && is_callable($pattern['func_save_content_to_file'])) {
            call_user_func($pattern['func_save_content_to_file'], $_result, $options, $enclosure);
        } else {
            fn_put_csv($_result, $options, $enclosure);
        }
        $iterator += $step;
    }
    if (!empty($pattern['post_processing'])) {
        fn_set_progress('echo', __('processing'), false);
        if ($data_exported && file_exists(fn_get_files_dir_path() . $options['filename'])) {
            $data_exported = fn_exim_processing('export', $pattern['post_processing'], $options);
        }
    }
    return $data_exported;
}
Пример #23
0
function fn_cleanup_payment_info($order_id = '', $payment_info, $silent = false)
{
    if ($silent == false) {
        fn_set_progress('echo', __('processing_order') . '&nbsp;<b>#' . $order_id . '</b>...');
    }
    if (!is_array($payment_info)) {
        $info = @unserialize(fn_decrypt_text($payment_info));
    } else {
        $info = $payment_info;
    }
    if (!empty($info['cvv2'])) {
        $info['cvv2'] = 'XXX';
    }
    if (!empty($info['card_number'])) {
        $info['card_number'] = str_replace(array('-', ' '), '', $info['card_number']);
        $info['card_number'] = substr_replace($info['card_number'], str_repeat('X', strlen($info['card_number']) - 4), 0, strlen($info['card_number']) - 4);
    }
    foreach (array('expiry_month', 'expiry_year') as $v) {
        if (!empty($info[$v])) {
            $info[$v] = 'XX';
        }
    }
    $_data = fn_encrypt_text(serialize($info));
    if (!empty($order_id)) {
        db_query("UPDATE ?:order_data SET data = ?s WHERE order_id = ?i AND type = 'P'", $_data, $order_id);
    } else {
        return $_data;
    }
}
Пример #24
0
 /**
  * Put directory to storage
  *
  * @param  string  $dir    directory to get files from
  * @param  array   $params additional parameters
  * @return boolean true of success, false on fail
  */
 public function putDir($dir, $params = array())
 {
     // Prefix param is required
     if (empty($params['prefix'])) {
         return false;
     }
     $files = fn_get_dir_contents($dir, false, true, '', '', true);
     fn_set_progress('step_scale', sizeof($files));
     foreach ($files as $source_file) {
         fn_set_progress('echo', '.');
         $dest = $this->prefix(rtrim($params['prefix'], '/') . '/' . $source_file);
         if (!is_dir(dirname($dest))) {
             fn_mkdir(dirname($dest));
         }
         fn_copy($dir . '/' . $source_file, $dest);
     }
     return true;
 }
Пример #25
0
 protected function _convertOrders($default_company_id)
 {
     $limit = 50;
     General::connectToOriginalDB(array('table_prefix' => General::formatPrefix()));
     db_query("UPDATE ?:order_data SET type='A' WHERE type='G'");
     //change marker for addon Reward points
     $orders_count = db_get_field("SELECT COUNT(*) FROM ?:orders");
     $crypt = new Crypt_Blowfish($this->store_data['crypt_key']);
     $crypt_new = new Crypt_Blowfish(Registry::get('config.crypt_key'));
     $location_fields = array('s_firstname as firstname', 's_lastname as lastname', 's_address as address', 's_address_2 as address_2', 's_city as city', 's_state as state', 's_country as country', 's_zipcode as zipcode', 's_phone as phone', 's_address_type as address_type');
     fn_set_progress('step_scale', ceil($orders_count / $limit));
     for ($i = 0; $i <= floor($orders_count / $limit); $i++) {
         $order_ids = db_get_fields("SELECT order_id FROM ?:orders LIMIT ?i, ?i", $i * $limit, $limit);
         $data = array();
         $shipment_items = array();
         fn_set_progress('echo', '<br />' . General::getUnavailableLangVar('converting_orders'), true);
         foreach ($order_ids as $order_id) {
             $order_info = array();
             $order_info['shipping'] = unserialize(db_get_field("SELECT data FROM ?:order_data WHERE type='L' AND order_id = ?i", $order_id));
             $order_info['products'] = db_get_hash_array("SELECT * FROM ?:order_details WHERE order_id = ?i", 'item_id', $order_id);
             $location = db_get_row("SELECT ?p FROM ?:orders WHERE order_id = ?i", implode(',', $location_fields), $order_id);
             if ($order_info['products']) {
                 foreach ($order_info['products'] as $cart_id => $product) {
                     if ($product['extra']) {
                         $order_info['products'][$cart_id]['extra'] = unserialize($product['extra']);
                     }
                 }
             }
             $products = array();
             foreach ($order_info['products'] as $cart_id => $product) {
                 $products[$cart_id] = $product['extra'];
                 $products[$cart_id]['amount'] = $product['amount'];
                 $products[$cart_id]['product_id'] = $product['product_id'];
             }
             $product_groups = $this->_groupProductsListOrder($products);
             $shippings = array();
             foreach ($product_groups as $key_group => $group) {
                 if (!empty($order_info['shipping'])) {
                     foreach ($order_info['shipping'] as $shipping_id => $shipping) {
                         $_shipping = $shipping;
                         $_shipping['shipping_id'] = $shipping_id;
                         unset($_shipping['rates']);
                         if (isset($_shipping['tracking_number'])) {
                             $shipment = array('shipping_id' => $shipping_id, 'tracking_number' => $_shipping['tracking_number'], 'carrier' => strtolower($_shipping['carrier']));
                             $shipment_id = db_query("INSERT INTO ?:shipments ?e", $shipment);
                             foreach ($group['products'] as $cart_id => $product) {
                                 $shipment_items[] = array('item_id' => $cart_id, 'shipment_id' => $shipment_id, 'order_id' => $order_id, 'product_id' => $product['product_id'], 'amount' => $product['amount']);
                             }
                             unset($_shipping['tracking_number']);
                             unset($_shipping['carrier']);
                         }
                         if (!empty($shipping_id)) {
                             foreach ($shipping['rates'] as $company_id => $rate) {
                                 if ($company_id == $group['company_id'] || $company_id == 0 && $group['company_id'] == $default_company_id) {
                                     $_shipping['rate'] = $rate;
                                     $_shipping['group_key'] = $key_group;
                                     $product_groups[$key_group]['shippings'][$shipping_id] = $_shipping;
                                     $product_groups[$key_group]['chosen_shippings'][] = $_shipping;
                                     $product_groups[$key_group]['package_info'] = !empty($_shipping['packages_info']) ? $_shipping['packages_info'] : array();
                                     $product_groups[$key_group]['package_info']['location'] = $location;
                                     $shippings[$shipping_id] = !empty($shippings[$shipping_id]) ? $shippings[$shipping_id] : $_shipping;
                                     $shippings[$shipping_id]['rates'][$key_group] = $shipping_id;
                                 }
                             }
                         }
                     }
                 }
             }
             $payment_info = db_get_field("SELECT data FROM ?:order_data WHERE type='P' AND order_id = ?i", $order_id);
             if (!empty($payment_info)) {
                 $payment_info = $crypt->decrypt(base64_decode($payment_info));
                 $payment_info = base64_encode($crypt_new->encrypt($payment_info));
                 $data[] = array('order_id' => $order_id, 'type' => 'P', 'data' => $payment_info);
             }
             $data[] = array('order_id' => $order_id, 'type' => 'G', 'data' => serialize($product_groups));
             $data[] = array('order_id' => $order_id, 'type' => 'L', 'data' => serialize(array_values($shippings)));
             fn_echo(' .');
         }
         if (!empty($data)) {
             db_query("REPLACE INTO ?:order_data ?m", $data);
         }
         if (!empty($shipment_items)) {
             db_query("REPLACE INTO ?:shipment_items ?m", $shipment_items);
         }
     }
     db_query("UPDATE ?:shipments SET carrier = LOWER(carrier);");
     db_query("UPDATE ?:shipments SET carrier = 'usps' WHERE carrier = 'usp';");
     db_query("UPDATE ?:shipments SET carrier = 'fedex' WHERE carrier = 'fdx';");
     db_query("UPDATE ?:shipments SET carrier = 'swisspost' WHERE carrier = 'chp';");
 }
Пример #26
0
                Tygh::$app['ajax']->destruct();
                exit;
            }
        });
        $seconds_to_execute = 360;
        $flush_every_seconds = 0.25;
        $number_of_flushes = $seconds_to_execute * (1 / $flush_every_seconds);
        $start_timestamp = microtime(true);
        $die_timestamp = $start_timestamp + $seconds_to_execute;
        fn_set_progress('parts', $number_of_flushes);
        $time_elapsed = 0;
        while (($now_timestamp = microtime(true)) < $die_timestamp) {
            if ($now_timestamp - $start_timestamp - $time_elapsed >= $flush_every_seconds) {
                $time_elapsed += $now_timestamp - $start_timestamp - $time_elapsed;
                // Pefrorm progress-bar flush
                fn_set_progress('echo', __('upgrade_center.warning_msg_executed_php') . PHP_EOL . __('seconds_left', array(sprintf('%d', $die_timestamp - $now_timestamp), (int) sprintf('%d', $die_timestamp - $now_timestamp))));
            }
        }
        // Success notification
        fn_set_notification('N', __('successful'), __('text_uc_timeout_check_success'), 'S', 'uc.timeout_check_success');
        Tygh::$app['ajax']->assign('non_ajax_notifications', true);
        Tygh::$app['ajax']->assign('force_redirection', fn_url('upgrade_center.manage'));
        exit;
    }
    return array(CONTROLLER_STATUS_REDIRECT);
}
if ($mode == 'refresh') {
    $app->clearDownloadedPackages();
    $app->checkUpgrades(false);
    $upgrade_packages = $app->getPackagesList();
    if (empty($upgrade_packages)) {
Пример #27
0
         if ($test === true) {
             $total = 0;
             if (fn_allowed_for('ULTIMATE')) {
                 foreach (fn_get_all_companies_ids() as $company_id) {
                     $themes[$company_id] = fn_get_dir_contents(fn_get_theme_path('[themes]', 'C', $company_id));
                     $total += sizeof($themes[$company_id]);
                 }
             } else {
                 $themes[0] = fn_get_dir_contents(fn_get_theme_path('[themes]', 'C'));
                 $total += sizeof($themes[0]);
             }
             $storage = Registry::get('config.storage');
             unset($storage['statics']);
             // Do not transfer auto-generated data
             $total += sizeof($storage);
             fn_set_progress('parts', $total);
             // transfer storages
             foreach ($storage as $type => $options) {
                 $from = Storage::instance($type, Registry::get('runtime.storage'));
                 $to = Storage::instance($type, $_REQUEST['storage_data']);
                 $to->putList($from->getList(''), $from->getAbsolutePath(''), array('overwrite' => true));
             }
             Settings::instance()->updateValue('storage', serialize($_REQUEST['storage_data']));
             fn_clear_cache();
             fn_set_notification('N', __('notice'), __('text_storage_changed'));
         } else {
             fn_save_post_data('storage_data');
             fn_set_notification('E', __('error'), $test);
         }
     }
 }
Пример #28
0
/**
 * Fuctnions parses SQL file and import data from it
 *
 * @param string $file File for import
 * @param integer $buffer Buffer size for fread function
 * @param bool $show_status Show or do not show process by printing ' .'
 * @param integer $show_create_table 0 - Do not print the name of created table, 1 - Print name and get lang_var('create_table'), 2 - Print name without getting lang_var
 * @param bool $check_prefix Check table prefix and replace it with the installed in config.php
 * @param bool $track Use queries cache. Do not execute queries that already are executed.
 * @param bool $skip_errors Skip errors or not
 * @param bool $move_progress_bar Move COMET progress bar or not on show progress
 * @return bool false, if file is not accessible
 */
function db_import_sql_file($file, $buffer = 16384, $show_status = true, $show_create_table = 1, $check_prefix = false, $track = false, $skip_errors = false, $move_progress_bar = true)
{
    if (file_exists($file)) {
        $path = dirname($file);
        $file_name = fn_basename($file);
        $tmp_file = $path . "/{$file_name}.tmp";
        $executed_queries = array();
        if ($track && file_exists($tmp_file)) {
            $executed_queries = unserialize(fn_get_contents($tmp_file));
        }
        if ($skip_errors) {
            $_skip_errors = Registry::get('runtime.database.skip_errors');
            Registry::set('runtime.database.skip_errors', true);
        }
        $fd = fopen($file, 'r');
        if ($fd) {
            $ret = array();
            $rest = '';
            $fs = filesize($file);
            if ($show_status && $move_progress_bar) {
                fn_set_progress('step_scale', ceil($fs / $buffer));
            }
            while (!feof($fd)) {
                $str = $rest . fread($fd, $buffer);
                $rest = fn_parse_queries($ret, $str);
                if ($show_status) {
                    fn_set_progress('echo', '<br />' . __('importing_data'), $move_progress_bar);
                }
                if (!empty($ret)) {
                    foreach ($ret as $query) {
                        if (!in_array($query, $executed_queries)) {
                            if ($show_create_table && preg_match('/CREATE\\s+TABLE\\s+`?(\\w+)`?/i', $query, $matches)) {
                                if ($show_create_table == 1) {
                                    $_text = __('creating_table');
                                } elseif ($show_create_table == 2) {
                                    $_text = 'Creating table';
                                }
                                $table_name = $check_prefix ? fn_check_db_prefix($matches[1], Registry::get('config.table_prefix')) : $matches[1];
                                if ($show_status) {
                                    fn_set_progress('echo', '<br />' . $_text . ': <b>' . $table_name . '</b>', $move_progress_bar);
                                }
                            }
                            if ($check_prefix) {
                                $query = fn_check_db_prefix($query);
                            }
                            Database::query($query);
                            if ($track) {
                                $executed_queries[] = $query;
                                fn_put_contents($tmp_file, serialize($executed_queries));
                            }
                            if ($show_status) {
                                fn_echo(' .');
                            }
                        }
                    }
                    $ret = array();
                }
            }
            fclose($fd);
            return true;
        }
        if ($skip_errors) {
            Registry::set('runtime.database.skip_errors', $_skip_errors);
        }
    }
    return false;
}
Пример #29
0
 /**
  * Parse and import sql file
  *
  * @param  string $filename path to SQL file
  * @param  string $title    Language value that will be showed on import
  * @param  array  $extra    Extra param
  * @return bool   True on success, false otherwise
  */
 private function _parseSql($filename, $title, $extra = array())
 {
     $app = App::instance();
     $title_shown = false;
     $fd = fopen($filename, 'r');
     if ($fd) {
         $_sess_name = md5($filename);
         if (!empty($_SESSION['parse_sql'][$_sess_name])) {
             if ($_SESSION['parse_sql'][$_sess_name] == 'COMPLETED') {
                 fclose($fd);
                 return true;
             }
             fseek($fd, $_SESSION['parse_sql'][$_sess_name]);
         }
         $rest = '';
         $ret = array();
         $counter = 0;
         while (!feof($fd)) {
             $str = $rest . fread($fd, 16384);
             $rest = fn_parse_queries($ret, $str);
             if (!empty($ret)) {
                 if ($title_shown == false) {
                     $app->setNotification('N', '', $app->t($title, $extra), true);
                     $title_shown = true;
                 }
                 foreach ($ret as $query) {
                     $counter++;
                     if (strpos($query, 'CREATE TABLE') !== false) {
                         preg_match("/CREATE\\s+TABLE\\s+`(\\w*)`/i", $query, $matches);
                         $table_name = str_replace(App::DEFAULT_PREFIX, '', $matches[1]);
                         fn_set_progress('echo', $app->t('creating_table', array('table' => $table_name)));
                     } else {
                         if ($counter > 30 && !App::instance()->isConsole()) {
                             fn_set_progress('echo', '');
                             $counter = 0;
                         }
                     }
                     $query = str_replace(App::DEFAULT_PREFIX, $this->_database_settings['table_prefix'], $query);
                     db_query($query);
                 }
                 $ret = array();
             }
             // Break the connection and re-request
             if (time() - TIME > INSTALL_DB_EXECUTION && !App::instance()->isConsole()) {
                 $pos = ftell($fd);
                 $pos = $pos - strlen($rest);
                 fclose($fd);
                 $_SESSION['parse_sql'][$_sess_name] = $pos;
                 $location = $_SERVER['REQUEST_URI'] . '&no_checking=1';
                 fn_echo("<meta http-equiv=\"Refresh\" content=\"0;URL={$location}\" />");
                 die;
             }
         }
         fclose($fd);
         $_SESSION['parse_sql'][$_sess_name] = 'COMPLETED';
         return true;
     }
     return false;
 }