Example #1
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;
 }
Example #2
0
 /**
  * Setup complete action
  *
  * @param array $params Request variables
  *
  * @return bool Always true
  */
 public function actionComplete($params = array())
 {
     $validator = new Validator();
     $app = App::instance();
     fn_define('CART_LANGUAGE', $app->getCurrentLangCode());
     fn_define('DESCR_SL', $app->getCurrentLangCode());
     $database = $app->getFromStorage('database_settings');
     if (!empty($database)) {
         $result = $validator->isMysqlSettingsValid($database['host'], $database['name'], $database['user'], $database['password'], $database['table_prefix'], $database['database_backend'], false);
         if ($result) {
             // Delete installer after store was installed.
             fn_rm(Registry::get('config.dir.root') . '/install');
             session_destroy();
             $this->_prepareHttpData();
             Session::init($params);
             $user_data = array('user_id' => 1, 'user_type' => 'A', 'area' => 'A', 'login' => 'admin', 'is_root' => 'Y', 'company_id' => 0);
             $_SESSION['auth'] = fn_fill_auth($user_data, array(), false, 'A');
             if (is_file(Registry::get('config.dir.root') . '/install/index.php')) {
                 $_SESSION['notifications']['installer'] = array('type' => 'W', 'title' => 'warning', 'message' => 'delete_install_folder', 'message_state' => 'S', 'new' => true, 'extra' => '', 'init_message' => true);
             }
             $redirect_url = Registry::get('config.http_location') . '/' . Registry::get('config.admin_index') . '?welcome';
             fn_redirect($redirect_url);
         }
     }
     fn_redirect('install/index.php');
     return true;
 }
Example #3
0
 public function updateViaFtp($content, $settings)
 {
     $this->saveBackup();
     $tmp_file = fn_create_temp_file();
     fn_put_contents($tmp_file, $content);
     $ftp_copy_result = fn_copy_by_ftp($tmp_file, $this->path, $settings);
     fn_rm($tmp_file);
     $status = $ftp_copy_result === true;
     return array($status, $ftp_copy_result);
 }
Example #4
0
function fn_rus_dellin_uninstall()
{
    $service_ids = db_get_fields('SELECT service_id FROM ?:shipping_services WHERE module = ?s', 'dellin');
    if (!empty($service_ids)) {
        db_query('DELETE FROM ?:shipping_services WHERE service_id IN (?a)', $service_ids);
        db_query('DELETE FROM ?:shipping_service_descriptions WHERE service_id IN (?a)', $service_ids);
    }
    db_query('DROP TABLE IF EXISTS ?:rus_dellin_cities');
    $file_dir = fn_get_files_dir_path() . "dellin/";
    fn_rm($file_dir);
}
Example #5
0
/**
 * Check if mod_rewrite is active and clean up templates cache
 */
function fn_settings_actions_addons_seo(&$new_value, $old_value)
{
    if ($new_value == 'A') {
        $result = fn_http_request('GET', Registry::get('config.http_location') . '/catalog.html?version');
        if (strpos($result[0]['RESPONSE'], '200 OK') === false) {
            $new_value = 'D';
            fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('warning_seo_urls_disabled'));
        }
    }
    fn_rm(DIR_COMPILED . 'customer');
    return true;
}
 static function clear($changed_tables)
 {
     $tags = array();
     foreach ($changed_tables as $table => $flag) {
         if (!empty(self::$_cache_handlers[$table])) {
             $tags = fn_array_merge($tags, array_keys(self::$_cache_handlers[$table]), false);
         }
     }
     foreach ($tags as $tag) {
         fn_rm(DIR_CACHE . $tag, true);
     }
     fn_put_contents(DIR_CACHE . self::$_handlers_name, serialize(self::$_cache_handlers));
     return true;
 }
Example #7
0
 public function update($id, $params)
 {
     $status = Response::STATUS_BAD_REQUEST;
     $data = array();
     $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE);
     if (isset($params['processor_params']['certificate_filename']) && !$params['processor_params']['certificate_filename']) {
         fn_rm(Registry::get('config.dir.certificates') . $id);
     }
     $payment_id = fn_update_payment($params, $id, $lang_code);
     if ($payment_id) {
         $status = Response::STATUS_OK;
         $data = array('payment_id' => $payment_id);
     }
     return array('status' => $status, 'data' => $data);
 }
Example #8
0
 /**
  * Downloads upgrade package from the Upgade server
  *
  * @param  array  $schema       Package schema
  * @param  string $package_path Path where the upgrade pack must be saved
  * @return bool   True if upgrade package was successfully downloaded, false otherwise
  */
 public function downloadPackage($schema, $package_path)
 {
     $data = fn_get_contents(Registry::get('config.resources.updates_server') . '/index.php?dispatch=product_updates.get_package&package_id=' . $schema['package_id'] . '&edition=' . PRODUCT_EDITION . '&license_number=' . $this->uc_settings['license_number']);
     if (!empty($data)) {
         fn_put_contents($package_path, $data);
         if (md5_file($package_path) == $schema['md5']) {
             $result = array(true, '');
         } else {
             fn_rm($package_path);
             $result = array(false, __('text_uc_broken_package'));
         }
     } else {
         $result = array(false, __('text_uc_cant_download_package'));
     }
     return $result;
 }
Example #9
0
 public function rotate()
 {
     if (file_exists($this->path . $this->filename)) {
         if (empty($this->save_name)) {
             $this->save_name = date('log_commerceml.txt', TIME);
         }
         fn_rename($this->path . $this->filename, $this->path . $this->save_name);
         $logs_list = fn_get_dir_contents($this->path, false, true);
         if (!empty($logs_list) && count($logs_list) > self::MAX_LOGS_FILE) {
             rsort($logs_list);
             list(, $old_logs) = array_chunk($logs_list, self::MAX_LOGS_FILE);
             foreach ($old_logs as $filename) {
                 fn_rm($this->path . $filename);
             }
         }
     }
 }
Example #10
0
 public function downloadPackage($schema, $package_path)
 {
     if (!empty($schema['download_key'])) {
         $upgrade_path = $this->settings['packages_server'] . $this->settings['addon'] . '/' . $schema['file'];
         $addon_upgrades_dir = Registry::get('config.dir.addons') . $this->settings['addon'] . '/upgrades/';
         $addon_upgrades_path = $addon_upgrades_dir . $schema['file'];
         if (!file_exists($addon_upgrades_path)) {
             fn_mkdir($addon_upgrades_dir);
             $addon_upgrade_data = fn_get_contents($upgrade_path);
             fn_put_contents($addon_upgrades_path, $addon_upgrade_data);
         }
         $result = fn_copy($addon_upgrades_path, $package_path);
         if ($result) {
             fn_rm($addon_upgrades_path);
         }
         //cleanup
         $message = $result ? '' : __('failed') . '-' . $addon_upgrades_path;
         return array($result, $message);
     } else {
         return array(false, __($schema['error_message']));
     }
 }
Example #11
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;
 }
Example #12
0
function fn_sdek_get_ticket_order($data_auth, $order_id, $chek_id)
{
    unset($data_auth['Number']);
    $xml = '            ' . RusSdek::arraySimpleXml('OrdersPrint', $data_auth, 'open');
    $order_sdek = array('Number' => $order_id . '_' . $chek_id, 'Date' => $data_auth['Date']);
    $xml .= '            ' . RusSdek::arraySimpleXml('Order', $order_sdek);
    $xml .= '            ' . '</OrdersPrint>';
    $response = RusSdek::xmlRequest('http://gw.edostavka.ru:11443/orders_print.php', $xml, $data_auth);
    $download_file_dir = fn_get_files_dir_path() . '/sdek' . '/' . $chek_id . '/';
    fn_rm($download_file_dir);
    fn_mkdir($download_file_dir);
    $name = $order_id . '.pdf';
    $download_file_path = $download_file_dir . $name;
    if (!fn_is_empty($response)) {
        fn_put_contents($download_file_path, $response);
    }
}
Example #13
0
//
// $Id: site_layout.php 9938 2010-07-01 14:18:59Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    fn_trusted_vars("lang_data");
    $suffix = '';
    if ($mode == 'update_design_mode') {
        db_query("UPDATE ?:settings SET value = ?s WHERE option_name = ?s AND section_id = ?s", $action == $_REQUEST['design_mode'] ? 'Y' : 'N', $_REQUEST['design_mode'], '');
        if (!empty($_REQUEST['disable_mode'])) {
            db_query("UPDATE ?:settings SET value = 'N' WHERE option_name = ?s AND section_id = ?s", $_REQUEST['disable_mode'], '');
        }
        fn_rm(DIR_COMPILED . 'customer', false);
        fn_rm(DIR_COMPILED . 'admin', false);
        $suffix = '.design_mode';
    }
    if ($mode == 'update_logos') {
        $logos = fn_filter_uploaded_data('logotypes');
        $areas = fn_get_manifest_definition();
        fn_save_logo_alt($areas);
        // Update customer logotype
        if (!empty($logos)) {
            foreach ($logos as $type => $logo) {
                $area = $areas[$type];
                $manifest = parse_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, true);
                $filename = DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . $area['path'] . '/images/' . $logo['name'];
                if (fn_copy($logo['path'], $filename)) {
                    list($w, $h, ) = fn_get_image_size($filename);
                    $manifest[$area['name']]['filename'] = $logo['name'];
Example #14
0
/**
 * Deletes theme
 * @param string $theme_name theme name to delete. If empty - deletes all themes
 * @return boolean true if deleted, false if not
 */
function fn_delete_theme($theme_name)
{
    $themes_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C');
    $can_delete = true;
    if (fn_allowed_for('ULTIMATE')) {
        $company_themes = Settings::instance()->getAllVendorsValues('theme_name');
        if (in_array($theme_name, $company_themes)) {
            fn_set_notification('E', __('error'), __('error_delete_theme_company'));
            $can_delete = false;
        }
    } else {
        if ($theme_name == Registry::get('runtime.layout.theme_name')) {
            $can_delete = false;
            fn_set_notification('E', __('error'), __('cannot_remove_active_theme'));
        }
    }
    $layouts = db_get_array('SELECT layout_id, is_default FROM ?:bm_layouts WHERE theme_name = ?s', $theme_name);
    if ($can_delete && fn_rm($themes_dest)) {
        // Delete layout
        foreach ($layouts as $layout) {
            Layout::instance()->delete($layout['layout_id']);
        }
        return true;
    }
    return false;
}
Example #15
0
            $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'));
    }
    if ($mode == 'delete') {
        if (!empty($_REQUEST['backup_file'])) {
            fn_rm(Registry::get('config.dir.backups') . fn_basename($_REQUEST['backup_file']));
        }
    }
    return array(CONTROLLER_STATUS_OK, 'datakeeper.manage');
}
if ($mode == 'getfile' && !empty($_REQUEST['file'])) {
    fn_get_file(Registry::get('config.dir.backups') . fn_basename($_REQUEST['file']));
} elseif ($mode == 'manage') {
    $view = Tygh::$app['view'];
    // Calculate database size and fill tables array
    $status_data = db_get_array("SHOW TABLE STATUS");
    $database_size = 0;
    $all_tables = array();
    foreach ($status_data as $k => $v) {
        $database_size += $v['Data_length'] + $v['Index_length'];
        $all_tables[] = $v['Name'];
Example #16
0
    $areas = array('customer', 'admin', 'mail');
    $installed_skins = fn_get_dir_contents(DIR_SKINS);
    foreach ($installed_skins as $skin_name) {
        foreach ($areas as $area) {
            if (is_dir(DIR_SKINS . $skin_name . '/' . $area . '/addons/' . $addon)) {
                if (!defined('DEVELOPMENT')) {
                    fn_rm(DIR_SKINS . $skin_name . '/' . $area . '/addons/' . $addon);
                }
            }
        }
    }
    $msg = fn_get_lang_var('text_addon_uninstalled');
    fn_set_notification('N', fn_get_lang_var('notice'), str_replace('[addon]', $addon_name, $msg));
    // Clean cache
    fn_rm(DIR_COMPILED, false);
    fn_rm(DIR_CACHE, false);
    return array(CONTROLLER_STATUS_OK, "addons.manage");
} elseif ($mode == 'update_status') {
    fn_get_schema('settings', 'actions', 'php', false, true);
    $old_status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $_REQUEST['id']);
    $new_status = $_REQUEST['status'];
    if ($old_status != $new_status) {
        $func = 'fn_settings_actions_addons_' . $_REQUEST['id'];
        if (function_exists($func)) {
            $func($new_status, $old_status);
        }
        if ($old_status != $new_status) {
            db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $_REQUEST['status'], $_REQUEST['id']);
            fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('status_changed'));
        } else {
            $ajax->assign('return_status', $old_status);
Example #17
0
/**
 * Move addon pack from temporarily folder to specified place and install it if possible
 *
 * @param string $from Source path
 * @param string $to Destination path
 * @return bool true if installed, false otherwise
 */
function fn_addons_move_and_install($from, $to)
{
    if (defined('AJAX_REQUEST')) {
        Registry::get('ajax')->assign('non_ajax_notifications', true);
    }
    $struct = fn_get_dir_contents($from, false, true, '', '', true);
    $addon_name = '';
    foreach ($struct as $file) {
        if (preg_match('/app.+?addons[^a-zA-Z0-9_]+([a-zA-Z0-9_-]+).+?addon.xml$/i', $file, $matches)) {
            if (!empty($matches[1])) {
                $addon_name = $matches[1];
                break;
            }
        }
    }
    $relative_addon_path = str_replace(Registry::get('config.dir.root') . '/', '', Registry::get('config.dir.addons'));
    if (!file_exists($from . $relative_addon_path . $addon_name . '/addon.xml')) {
        fn_set_notification('E', __('error'), __('broken_addon_pack'));
        return false;
    }
    fn_copy($from, $to);
    fn_install_addon($addon_name);
    fn_rm($from);
    return true;
}
Example #18
0
 /**
  * Deletes files using glob pattern
  *
  * @param  string  $pattern glob-compatible pattern
  * @return boolean true if deleted successfully, false - otherwise
  */
 public function deleteByPattern($pattern)
 {
     $files = glob($this->prefix($pattern));
     if (!empty($files)) {
         foreach ($files as $file) {
             fn_rm($file);
         }
     }
     return true;
 }
Example #19
0
/**
 * Create/Update payments data
 *
 * @param array $payment_data
 * @param int $payment_id
 * @param string $lang_code 2-letter language code
 * @return int Payment id
 */
function fn_update_payment($payment_data, $payment_id, $lang_code = DESCR_SL)
{
    $certificate_file = fn_filter_uploaded_data('payment_certificate');
    $certificates_dir = Registry::get('config.dir.certificates');
    fn_set_hook('update_payment_pre', $payment_data, $payment_id, $lang_code, $certificate_file, $certificates_dir);
    /**
     * Create/update the certificate file
     * only for an existing payment method.
     *
     * Non-existing payment method will be created first,
     * then will be updated. (fn_update_payment calling at line 450).
     */
    if ($payment_id) {
        if ($certificate_file) {
            $file = reset($certificate_file);
            $filename = $payment_id . '/' . $file['name'];
            fn_mkdir($certificates_dir . $payment_id);
            fn_copy($file['path'], $certificates_dir . $filename);
            $payment_data['processor_params']['certificate_filename'] = $filename;
        }
        $old_params = fn_get_processor_data($payment_id);
        if (empty($payment_data['processor_params']['certificate_filename']) && isset($old_params['processor_params']['certificate_filename'])) {
            $payment_data['processor_params']['certificate_filename'] = $old_params['processor_params']['certificate_filename'];
        }
        if (!empty($payment_data['processor_params']['certificate_filename'])) {
            if (!empty($old_params['processor_params']['certificate_filename']) && $payment_data['processor_params']['certificate_filename'] != $old_params['processor_params']['certificate_filename']) {
                fn_rm($certificates_dir . $old_params['processor_params']['certificate_filename']);
            }
            if (!file_exists($certificates_dir . $payment_data['processor_params']['certificate_filename'])) {
                $payment_data['processor_params']['certificate_filename'] = '';
            }
        }
    }
    if (!empty($payment_data['processor_id'])) {
        $payment_data['template'] = db_get_field("SELECT processor_template FROM ?:payment_processors WHERE processor_id = ?i", $payment_data['processor_id']);
    }
    $payment_data['localization'] = !empty($payment_data['localization']) ? fn_implode_localizations($payment_data['localization']) : '';
    $payment_data['usergroup_ids'] = empty($payment_data['usergroup_ids']) ? USERGROUP_ALL : (is_array($payment_data['usergroup_ids']) ? implode(',', $payment_data['usergroup_ids']) : $payment_data['usergroup_ids']);
    $payment_data['tax_ids'] = !empty($payment_data['tax_ids']) ? fn_create_set($payment_data['tax_ids']) : '';
    // Update payment processor settings
    $processor_params = array();
    if (!empty($payment_data['processor_params'])) {
        $processor_params = $payment_data['processor_params'];
        $payment_data['processor_params'] = serialize($payment_data['processor_params']);
    }
    if (!empty($payment_id)) {
        $arow = db_query("UPDATE ?:payments SET ?u WHERE payment_id = ?i", $payment_data, $payment_id);
        db_query("UPDATE ?:payment_descriptions SET ?u WHERE payment_id = ?i AND lang_code = ?s", $payment_data, $payment_id, $lang_code);
        if ($arow === false) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('payment'))), '', '404');
            $payment_id = false;
        }
    } else {
        $payment_data['payment_id'] = $payment_id = db_query("INSERT INTO ?:payments ?e", $payment_data);
        foreach (fn_get_translation_languages() as $payment_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:payment_descriptions ?e", $payment_data);
        }
        /**
         * Update the certificate
         */
        if ($certificate_file && $payment_id) {
            unset($payment_data['lang_code']);
            $payment_data['processor_params'] = $processor_params;
            fn_update_payment($payment_data, $payment_id, $lang_code);
        }
    }
    fn_attach_image_pairs('payment_image', 'payment', $payment_id, $lang_code);
    fn_set_hook('update_payment_post', $payment_data, $payment_id, $lang_code, $certificate_file, $certificates_dir, $processor_params);
    return $payment_id;
}
Example #20
0
            if (empty($_REQUEST['pattern_id'])) {
                fn_set_notification('E', __('error'), __('error_exim_pattern_not_found'));
            } else {
                $pattern = fn_get_pattern_definition($_REQUEST['pattern_id'], 'import');
                if (($data = fn_get_csv($pattern, $file[0]['path'], $_REQUEST['import_options'])) != false) {
                    fn_import($pattern, $data, $_REQUEST['import_options']);
                }
            }
        } else {
            fn_set_notification('E', __('error'), __('error_exim_no_file_uploaded'));
        }
        return array(CONTROLLER_STATUS_OK, 'exim.import?section=' . $_REQUEST['section'] . '&pattern_id=' . $_REQUEST['pattern_id']);
    }
    if ($mode == 'delete_file' && !empty($_REQUEST['filename'])) {
        $file = fn_basename($_REQUEST['filename']);
        fn_rm(fn_get_files_dir_path() . $file);
        return array(CONTROLLER_STATUS_REDIRECT);
    }
    if ($mode == 'delete_range') {
        unset($_SESSION['export_ranges'][$_REQUEST['section']]);
        return array(CONTROLLER_STATUS_REDIRECT, 'exim.export?section=' . $_REQUEST['section'] . '&pattern_id=' . $_REQUEST['pattern_id']);
    }
    exit;
}
if ($mode == 'export') {
    if (empty($_REQUEST['section'])) {
        $_REQUEST['section'] = 'products';
    }
    list($sections, $patterns) = fn_get_patterns($_REQUEST['section'], 'export');
    if (empty($sections) && empty($patterns) || isset($_REQUEST['section']) && empty($sections[$_REQUEST['section']])) {
        return array(CONTROLLER_STATUS_DENIED);
Example #21
0
    $pattern_id = empty($_REQUEST['pattern_id']) ? key($patterns) : $_REQUEST['pattern_id'];
    $patterns = $parser->enchancePattern($patterns);
    foreach ($patterns as $p_id => $p) {
        Registry::set('navigation.tabs.' . $p_id, array('title' => $p['name'], 'href' => "exim.import?pattern_id=" . $p_id . '&section=' . $_REQUEST['section'], 'ajax' => true));
    }
    Registry::set('navigation.dynamic.sections', $sections);
    Registry::set('navigation.dynamic.active_section', $_REQUEST['section']);
    $patterns['product_images']['analogs_dev'] = 1;
    $view->assign('pattern', $patterns[$pattern_id]);
    $view->assign('sections', $sections);
} elseif ($mode == 'get_file' && !empty($_REQUEST['filename'])) {
    $file = basename($_REQUEST['filename']);
    fn_get_file(DIR_EXIM . $file);
} elseif ($mode == 'delete_file' && !empty($_REQUEST['filename'])) {
    $file = basename($_REQUEST['filename']);
    fn_rm(DIR_EXIM . $file);
    return array(CONTROLLER_STATUS_REDIRECT);
} elseif ($mode == 'delete_range') {
    unset($_SESSION['export_ranges'][$_REQUEST['section']]);
    return array(CONTROLLER_STATUS_REDIRECT, "exim.export?section={$_REQUEST['section']}&pattern_id={$_REQUEST['pattern_id']}");
} elseif ($mode == 'select_range') {
    $_SESSION['export_ranges'][$_REQUEST['section']] = array('pattern_id' => $_REQUEST['pattern_id'], 'data' => array());
    $pattern = fn_get_pattern_definition($_REQUEST['pattern_id']);
    return array(CONTROLLER_STATUS_REDIRECT, $pattern['range_options']['selector_url']);
} elseif ($mode == 'export_simple') {
    $products = db_get_array("SELECT `product_id`, `product_code` FROM `cscart_products`");
    $date = date('d-m-Y');
    $myFile = '' . DIR_EXIM . 'simple_products_' . $date . '.csv';
    //var_dump($myFile);
    $handle = fopen($myFile, 'w') or die('Cannot open file:  ' . $my_file);
    //implicitly creates file
Example #22
0
/**
 * Recursively remove directory (or just a file)
 *
 * @param string $source
 * @param bool $delete_root
 * @param string $pattern
 * @return bool
 */
function fn_rm($source, $delete_root = true, $pattern = '')
{
    // Simple copy for a file
    if (is_file($source)) {
        $res = true;
        if (empty($pattern) || !empty($pattern) && preg_match('/' . $pattern . '/', basename($source))) {
            $res = @unlink($source);
        }
        return $res;
    }
    // Loop through the folder
    if (is_dir($source)) {
        $dir = dir($source);
        while (false !== ($entry = $dir->read())) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            if (fn_rm($source . '/' . $entry, true, $pattern) == false) {
                return false;
            }
        }
        // Clean up
        $dir->close();
        return $delete_root == true && empty($pattern) ? @rmdir($source) : true;
    } else {
        return false;
    }
}
Example #23
0
 /**
  * Installs new language from ZIP pack
  *
  * @param string $path   Path to ZIP file
  * @param array  $params
  *  reinstall: Skip adding new language
  *  validate_lang_code:Check meta information (lang_code) with updated language data (lang_code) and forbid to update if does not match
  *  force_lang_code: Skip meta lang code and use this one in all laguage variables
  * @return int Language ID
  */
 public static function installZipPack($path, $params = array())
 {
     $result = false;
     // Extract language pack and check the permissions
     $extract_path = fn_get_cache_path(false) . 'tmp/language_pack/';
     // Re-create source folder
     fn_rm($extract_path);
     fn_mkdir($extract_path);
     fn_copy($path, $extract_path . 'pack.zip');
     if (fn_decompress_files($extract_path . 'pack.zip', $extract_path)) {
         fn_rm($extract_path . 'pack.zip');
         $result = self::installCrowdinPack($extract_path, $params);
     } else {
         fn_set_notification('E', __('error'), __('broken_po_pack'));
     }
     return $result;
 }
Example #24
0
function fn_delete_image($image_id, $pair_id, $object_type = 'product', $rev_data = array())
{
    $table = 'images_links';
    $itable = 'images';
    $cond = '';
    $path = DIR_IMAGES . $object_type . '/';
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        $_img_data = db_get_row("SELECT object_type, object_id FROM ?:rev_images_links WHERE pair_id = ?i ORDER BY revision DESC LIMIT 1", $pair_id);
        if (!empty($_img_data['object_type']) && !empty($revisions['objects'][$_img_data['object_type']]) && !empty($revisions['objects'][$_img_data['object_type']]['tables'])) {
            $object_data = $revisions['objects'][$_img_data['object_type']];
            if ($object_data['images']) {
                if (empty($rev_data)) {
                    $entry = array($object_data['key'] => $_img_data['object_id']);
                    list($revision, $revision_id) = fn_revisions_get_last($_img_data['object_type'], $entry, 0, $itable);
                } else {
                    $revision = $rev_data['revision'];
                    $revision_id = $rev_data['revision_id'];
                }
                if (!empty($revision_id)) {
                    $table = 'rev_images_links';
                    $itable = 'rev_images';
                    $cond = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
                    $path = DIR_IMAGES . $object_type . '_rev/';
                }
            }
        }
    }
    $path .= floor($image_id / MAX_FILES_IN_DIR) . "/";
    $_image_file = db_get_field("SELECT image_path FROM ?:{$itable} WHERE image_id = ?i ?p", $image_id, $cond);
    if (!empty($_image_file)) {
        if (!empty($revision_id)) {
            $use_count = db_get_field("SELECT COUNT(image_path) FROM ?:{$itable} WHERE image_id = ?i AND image_path = ?s", $image_id, $_image_file);
            if ($use_count == 1) {
                fn_delete_file($path . $_image_file);
            }
        } else {
            fn_delete_file($path . $_image_file);
        }
    }
    $dir_content = fn_get_dir_contents($path, true, true);
    if (empty($dir_content)) {
        fn_rm($path);
    }
    db_query("DELETE FROM ?:{$itable} WHERE image_id = ?i ?p", $image_id, $cond);
    db_query("DELETE FROM ?:common_descriptions WHERE object_id = ?i AND object_holder = 'images'", $image_id);
    db_query("UPDATE ?:{$table} SET " . ($object_type == 'detailed' ? 'detailed_id' : 'image_id') . " = '0' WHERE pair_id = ?i ?p", $pair_id, $cond);
    $_ids = db_get_row("SELECT image_id, detailed_id FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
    if (empty($_ids['image_id']) && empty($_ids['detailed_id'])) {
        db_query("DELETE FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
    }
    return true;
}
Example #25
0
 public function clearCache()
 {
     return fn_rm($this->getFileName());
 }
Example #26
0
 /**
  * This is a copy of the fn_uc_is_writable_dest function which was removed in 4.1.5
  *
  * Check if destination is writable
  *
  * @param string $dest destination file/directory
  * @return boolean true if writable, false - if not
  */
 private static function isWritableDest($dest)
 {
     $dest = rtrim($dest, '/');
     if (is_file($dest)) {
         $f = @fopen($dest, 'ab');
         if ($f === false) {
             return false;
         }
         fclose($f);
     } elseif (is_dir($dest)) {
         if (!fn_put_contents($dest . '/zzzz.zz', '1')) {
             return false;
         }
         fn_rm($dest . '/zzzz.zz');
     } else {
         return false;
     }
     return true;
 }
Example #27
0
/**
 * Remove temporary files
 */
function fn_remove_temp_data()
{
    $fs_data = Registry::get('temp_fs_data');
    if (!empty($fs_data)) {
        foreach ($fs_data as $file) {
            fn_rm($file);
        }
    }
}
Example #28
0
             return array(CONTROLLER_STATUS_OK, 'themes.manage');
         }
     }
     $non_writable_folders = fn_check_copy_ability($source, $destination);
     if (!empty($non_writable_folders)) {
         if (!empty($_REQUEST['ftp_access'])) {
             Tygh::$app['view']->assign('ftp_access', $_REQUEST['ftp_access']);
         }
         Tygh::$app['view']->assign('non_writable', $non_writable_folders);
         if (defined('AJAX_REQUEST')) {
             Tygh::$app['view']->display('views/themes/components/correct_permissions.tpl');
             exit;
         }
     } else {
         fn_copy($source, $destination);
         fn_rm($source);
         if (defined('AJAX_REQUEST')) {
             Tygh::$app['ajax']->assign('force_redirection', fn_url('themes.manage'));
             exit;
         }
     }
 }
 if ($mode == 'install') {
     if (!empty($_REQUEST['theme_name'])) {
         // Copy theme files to design/themes directory
         fn_install_theme_files($_REQUEST['theme_name'], $_REQUEST['theme_name']);
     }
     return array(CONTROLLER_STATUS_OK, 'themes.manage?selected_section=general');
 }
 if ($mode == 'delete') {
     fn_delete_theme($_REQUEST['theme_name']);
Example #29
0
 /**
  * Deletes style
  * @param  string  $style_id style ID
  * @return boolean true on succes, false otherwise
  */
 public function delete($style_id)
 {
     $style_id = fn_basename($style_id);
     if (fn_rm($this->getStyleFile($style_id))) {
         fn_rm($this->getStyleFile($style_id, 'css'));
         // remove custom css
         fn_rm($this->getStyleFile($style_id, 'png'));
         // remove style image
         fn_rm(Patterns::instance($this->params)->getPath($style_id));
         fn_delete_logo('theme', null, $style_id);
         fn_delete_logo('mail', null, $style_id);
         fn_delete_logo('favicon', null, $style_id);
         fn_rm(fn_get_theme_path('[themes]/[theme]/media/images/logos/' . $style_id, 'C'));
         fn_set_hook('delete_style_post', $style_id);
         return true;
     }
     return false;
 }
Example #30
0
 /**
  * Put file to storage
  *
  * @param  string $file   file path in storage
  * @param  array  $params uploaded data and options
  * @return array  file size and file name
  */
 public function put($file, $params)
 {
     if (empty($params['overwrite'])) {
         $file = $this->generateName($file);
         // check if name is unique and generate new if not
     }
     $file = $this->prefix($file);
     $s3 = $this->s3();
     // get object to initialize class and get access to contstants below
     $data = array('acl' => \AmazonS3::ACL_PUBLIC, 'headers' => array());
     if (!empty($params['compress'])) {
         $data['headers']['Content-Encoding'] = 'gzip';
         $data['headers']['Cache-control'] = 'private';
         if (!empty($params['contents'])) {
             $params['contents'] = gzencode($params['contents']);
         }
     }
     // File can not be accessible via direct link
     if ($this->getOption('secured')) {
         $data['headers']['Content-disposition'] = 'attachment; filename="' . fn_basename($file) . '"';
         $data['acl'] = \AmazonS3::ACL_PRIVATE;
     }
     $data['contentType'] = fn_get_file_type($file);
     if (!empty($params['contents'])) {
         $data['body'] = $params['contents'];
     } else {
         $data['fileUpload'] = $params['file'];
     }
     $res = $s3->create_object($this->getOption('bucket'), $file, $data);
     if ($res->isOK()) {
         if (!empty($params['caching'])) {
             Registry::set('s3_' . $this->getOption('bucket') . '.' . md5($file), true);
         }
         if (!empty($params['file'])) {
             $filesize = filesize($params['file']);
             if (empty($params['keep_origins'])) {
                 fn_rm($params['file']);
             }
         } else {
             $filesize = strlen($params['contents']);
         }
         return array($filesize, str_replace($this->prefix(), '', $file));
     }
     return false;
 }