public static function getDirCommerceML()
 {
     self::$path_commerceml = fn_get_files_dir_path() . 'exim/1C_' . date('dmY') . '/';
     self::$url_commerceml = Registry::get('config.http_location') . '/' . fn_get_rel_dir(self::$path_commerceml);
     self::$url_images = Storage::instance('images')->getAbsolutePath('from_1c/');
     return array(self::$path_commerceml, self::$url_commerceml, self::$url_images);
 }
Beispiel #2
0
function fn_rus_tovary_mailru_url_auto()
{
    $key = Registry::get('addons.rus_tovary_mailru.cron_key');
    $company_id = Registry::get('runtime.simple_ultimate') ? Registry::get('runtime.forced_company_id') : Registry::get('runtime.company_id');
    $url = fn_url('exim.mailru_cron_export?cron_key=' . urlencode($key) . '&switch_company_id=' . $company_id, 'A');
    $text = __('mailru_export_auto_info') . '<br/ >' . $url;
    $text = '<br/ ><br/ >' . __('mailru_export_auto_info_header') . '<br/ ><br/ >' . $text . '<br /><br/ >' . __('mailru_export_auto_info_end') . '<br /><br/ >' . __('mailru_export_auto_info_bottom');
    $file = fn_get_files_dir_path() . Registry::get('addons.rus_tovary_mailru.cron_filename');
    $url_to_file = Registry::get('config.current_location') . '/' . fn_get_rel_dir($file);
    $text .= '<br/ ><br/ >' . __('mailru_export_auto_info_file') . '<br/ >' . $file . '<br/ ><a href =' . $url_to_file . '>' . $url_to_file . '</a>';
    return $text;
}
Beispiel #3
0
 /**
  * Gets meta information from the PO file
  *
  * @param  string $base_path Root dir
  * @param  string $pack_file PO file name (without .po extension)
  * @param  bool   $reinstall Use this flag, if pack was alread installed before to get META information
  * @return array  List of lang pack meta information
  */
 public static function getLangPacksMeta($base_path = '', $pack_file = '', $reinstall = false, $check_installed = true)
 {
     $installed_languages = $check_installed ? self::getAll(true) : array();
     $path = empty($base_path) ? Registry::get('config.dir.lang_packs') : $base_path;
     $return = array();
     if (empty($pack_file)) {
         $po_file_list = array();
         foreach (fn_get_dir_contents($path, true, false) as $pack_directory) {
             if (is_dir($path . $pack_directory)) {
                 $po_file_list[] = $pack_directory . '/core.po';
             }
         }
     } else {
         $po_file_list = array($pack_file);
     }
     foreach ($po_file_list as $po_file_name) {
         $po_file_path = $path . $po_file_name;
         if (!file_exists($po_file_path)) {
             fn_set_notification('E', __('error'), __('incorrect_po_pack_structure', array('[pack_path]' => fn_get_rel_dir(dirname($po_file_path)))));
             continue;
         }
         $metadata = Po::getMeta($po_file_path);
         if (is_array($metadata)) {
             if (!self::isValidMeta($metadata)) {
                 fn_set_notification('E', __('error'), __('po_file_is_incorrect', array('[file]' => fn_get_rel_dir($po_file_path))));
                 continue;
             }
         } else {
             fn_set_notification('E', __('error'), $metadata);
             continue;
         }
         if (isset($installed_languages[$metadata['lang_code']]) && !$reinstall) {
             continue;
         }
         $return[] = $metadata;
     }
     if (!empty($pack_file) && !empty($return)) {
         return reset($return);
     }
     return $return;
 }
Beispiel #4
0
        }
    }
    // Get export files
    $export_files = fn_get_dir_contents(fn_get_files_dir_path(), false, true);
    $result = array();
    foreach ($export_files as $file) {
        $result[] = array('name' => $file, 'size' => filesize(fn_get_files_dir_path() . $file));
    }
    // Export languages
    foreach (fn_get_translation_languages() as $lang_code => $lang_data) {
        $export_langs[$lang_code] = $lang_data['name'];
    }
    Registry::set('navigation.dynamic.sections', $sections);
    Registry::set('navigation.dynamic.active_section', $_REQUEST['section']);
    Tygh::$app['view']->assign('export_files', $result);
    Tygh::$app['view']->assign('files_rel_dir', fn_get_rel_dir(fn_get_files_dir_path()));
    Tygh::$app['view']->assign('pattern', $patterns[$pattern_id]);
    Tygh::$app['view']->assign('layouts', $layouts);
    Tygh::$app['view']->assign('export_langs', $export_langs);
} elseif ($mode == 'import') {
    if (empty($_REQUEST['section'])) {
        $_REQUEST['section'] = 'products';
    }
    list($sections, $patterns) = fn_get_patterns($_REQUEST['section'], 'import');
    if (empty($sections) && empty($patterns) || isset($_REQUEST['section']) && empty($sections[$_REQUEST['section']])) {
        return array(CONTROLLER_STATUS_DENIED);
    }
    $pattern_id = empty($_REQUEST['pattern_id']) ? key($patterns) : $_REQUEST['pattern_id'];
    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));
    }
Beispiel #5
0
function fn_log_event($type, $action, $data = array())
{
    $object_primary_keys = array('users' => 'user_id', 'orders' => 'order_id', 'products' => 'product_id', 'categories' => 'category_id');
    $update = false;
    $content = array();
    $actions = Registry::get('settings.Logging.log_type_' . $type);
    $cut_log = Registry::ifGet('log_cut', false);
    Registry::del('log_cut');
    $cut_data = Registry::ifGet('log_cut_data', false);
    Registry::del('log_cut_data');
    if (empty($actions) || $action && !empty($actions) && empty($actions[$action]) || !empty($cut_log)) {
        return false;
    }
    if (!empty($_SESSION['auth']['user_id'])) {
        $user_id = $_SESSION['auth']['user_id'];
    } else {
        $user_id = 0;
    }
    if ($type == 'users' && $action == 'logout' && !empty($data['user_id'])) {
        $user_id = $data['user_id'];
    }
    if ($user_id) {
        $udata = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $user_id);
    }
    $event_type = 'N';
    // notice
    if (!empty($data['backtrace'])) {
        $_btrace = array();
        $func = '';
        foreach (array_reverse($data['backtrace']) as $v) {
            if (!empty($v['file'])) {
                $v['file'] = fn_get_rel_dir($v['file']);
            }
            if (empty($v['file'])) {
                $func = $v['function'];
                continue;
            } elseif (!empty($func)) {
                $v['function'] = $func;
                $func = '';
            }
            $_btrace[] = array('file' => !empty($v['file']) ? $v['file'] : '', 'line' => !empty($v['line']) ? $v['line'] : '', 'function' => $v['function']);
        }
        $data['backtrace'] = serialize($_btrace);
    } else {
        $data['backtrace'] = '';
    }
    if ($type == 'general') {
        if ($action == 'deprecated') {
            $content['deprecated_function'] = $data['function'];
        }
        $content['message'] = $data['message'];
    } elseif ($type == 'orders') {
        $order_status_descr = fn_get_simple_statuses(STATUSES_ORDER, true, true);
        $content = array('order' => '# ' . $data['order_id'], 'id' => $data['order_id']);
        if ($action == 'status') {
            $content['status'] = $order_status_descr[$data['status_from']] . ' -> ' . $order_status_descr[$data['status_to']];
        }
    } elseif ($type == 'products') {
        $product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $data['product_id'], Registry::get('settings.Appearance.backend_default_language'));
        $content = array('product' => $product . ' (#' . $data['product_id'] . ')', 'id' => $data['product_id']);
        if ($action == 'low_stock') {
            // log stock - warning
            $event_type = 'W';
        }
    } elseif ($type == 'categories') {
        $category = db_get_field("SELECT category FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $data['category_id'], Registry::get('settings.Appearance.backend_default_language'));
        $content = array('category' => $category . ' (#' . $data['category_id'] . ')', 'id' => $data['category_id']);
    } elseif ($type == 'database') {
        if ($action == 'error') {
            $content = array('error' => $data['error']['message'], 'query' => $data['error']['query']);
            $event_type = 'E';
        }
    } elseif ($type == 'requests') {
        if (!empty($cut_data)) {
            $data['data'] = preg_replace("/\\<(" . implode('|', $cut_data) . ")\\>(.*?)\\<\\/(" . implode('|', $cut_data) . ")\\>/s", '<${1}>******</${1}>', $data['data']);
            $data['data'] = preg_replace("/%3C(" . implode('|', $cut_data) . ")%3E(.*?)%3C%2F(" . implode('|', $cut_data) . ")%3E/s", '%3C${1}%3E******%3C%2F${1}%3E', $data['data']);
            $data['data'] = preg_replace("/(" . implode('|', $cut_data) . ")=(.*?)(&)/s", '${1}=******${3}', $data['data']);
        }
        $content = array('url' => $data['url'], 'request' => fn_strlen($data['data']) < LOG_MAX_DATA_LENGTH && preg_match('//u', $data['data']) ? $data['data'] : '', 'response' => fn_strlen($data['response']) < LOG_MAX_DATA_LENGTH && preg_match('//u', $data['response']) ? $data['response'] : '');
    } elseif ($type == 'users') {
        if (!empty($data['time'])) {
            if (empty($_SESSION['log']['login_log_id'])) {
                return false;
            }
            $content = db_get_field('SELECT content FROM ?:logs WHERE log_id = ?i', $_SESSION['log']['login_log_id']);
            $content = unserialize($content);
            $minutes = ceil($data['time'] / 60);
            $hours = floor($minutes / 60);
            if ($hours) {
                $minutes -= $hours * 60;
            }
            if ($hours || $minutes) {
                $content['loggedin_time'] = ($hours ? $hours . ' |hours| ' : '') . ($minutes ? $minutes . ' |minutes|' : '');
            }
            if (!empty($data['timeout']) && $data['timeout']) {
                $content['timeout'] = true;
            }
            $update = $_SESSION['log']['login_log_id'];
        } else {
            if (!empty($data['user_id'])) {
                $info = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $data['user_id']);
                $content = array('user' => $info['firstname'] . ($info['firstname'] && $info['lastname'] ? ' ' : '') . $info['lastname'] . ($info['firstname'] || $info['lastname'] ? '; ' : '') . $info['email'] . ' (#' . $data['user_id'] . ')');
                $content['id'] = $data['user_id'];
            } elseif (!empty($data['user'])) {
                $content = array('user' => $data['user']);
            }
            if (in_array($action, array('session', 'failed_login'))) {
                $ip = fn_get_ip();
                $content['ip_address'] = empty($data['ip']) ? $ip['host'] : $data['ip'];
            }
        }
        if ($action == 'failed_login') {
            // failed login - warning
            $event_type = 'W';
        }
    }
    fn_set_hook('save_log', $type, $action, $data, $user_id, $content, $event_type, $object_primary_keys);
    $content = serialize($content);
    if ($update) {
        db_query('UPDATE ?:logs SET content = ?s WHERE log_id = ?i', $content, $update);
    } else {
        if (Registry::get('runtime.company_id')) {
            $company_id = Registry::get('runtime.company_id');
        } elseif (!empty($object_primary_keys[$type]) && !empty($data[$object_primary_keys[$type]])) {
            $company_id = fn_get_company_id($type, $object_primary_keys[$type], $data[$object_primary_keys[$type]]);
        } else {
            $company_id = 0;
        }
        $row = array('user_id' => $user_id, 'timestamp' => TIME, 'type' => $type, 'action' => $action, 'event_type' => $event_type, 'content' => $content, 'backtrace' => $data['backtrace'], 'company_id' => $company_id);
        $log_id = db_query("INSERT INTO ?:logs ?e", $row);
        if ($type == 'users' && $action == 'session') {
            $_SESSION['log']['login_log_id'] = $log_id;
        }
    }
    return true;
}
****************************************************************************/
use Tygh\Registry;
use Tygh\Storage;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if (Registry::get('config.demo_mode')) {
    // ElFinder should not work in demo mode
    $message = json_encode(array('error' => __('error_demo_mode')));
    exit($message);
}
include Registry::get('config.dir.root') . '/js/lib/elfinder/connectors/php/elFinder.class.php';
$opts = array('rootAlias' => __('home'), 'tmbDir' => '', 'dirSize' => false, 'fileMode' => DEFAULT_FILE_PERMISSIONS, 'dirMode' => DEFAULT_DIR_PERMISSIONS, 'uploadDeny' => Registry::get('config.forbidden_mime_types'), 'disabled' => array('mkfile', 'rename', 'paste', 'read', 'edit', 'archive', 'extract'));
$company_id = Registry::get('runtime.simple_ultimate') ? Registry::get('runtime.forced_company_id') : Registry::get('runtime.company_id');
if ($mode == 'files') {
    $files_path = fn_get_files_dir_path();
    fn_mkdir($files_path);
    $opts = array('root' => $files_path, 'URL' => Registry::get('config.current_location') . '/' . fn_get_rel_dir($files_path));
    $fm = new \elFinder($opts);
    $fm->run();
} elseif ($mode == 'images') {
    $extra_path = '';
    if (!empty($company_id)) {
        $extra_path .= 'companies/' . $company_id . '/';
    }
    fn_mkdir(Storage::instance('images')->getAbsolutePath($extra_path));
    $opts = array('root' => Storage::instance('images')->getAbsolutePath($extra_path), 'URL' => Storage::instance('images')->getUrl($extra_path));
    $fm = new elFinder($opts);
    $fm->run();
}
exit;
Beispiel #7
0
 /**
  * Gets a style preview image
  * @param  string $style_id style ID
  * @return string preview image URL
  */
 public function getStyleImage($style_id)
 {
     $url = '';
     $path = $this->getStyleFile($style_id, 'png');
     if (file_exists($path)) {
         $url = Registry::get('config.current_location') . '/' . fn_get_rel_dir($path);
     }
     return $url;
 }
Beispiel #8
0
/**
 * Gets HTTP path user is allowed to put files to
 * @return string files path
 */
function fn_get_http_files_dir_path()
{
    $path = fn_get_rel_dir(fn_get_files_dir_path());
    $path = Registry::get('config.http_location') . '/' . $path;
    return $path;
}
Beispiel #9
0
 /**
  * Makes DB backup
  *  db_filename - string name of result pack. Will be stored in Registry::get('config.dir.database') . $db_filename;
  *  db_tables - array List of tables to be backuped
  *  db_schema - bool Backup tables schema
  *  db_data - bool Backup data from tables
  * @param array $params
  *
  * @return string Path to backuped DB sql/tgz file
  */
 public static function backupDatabase($params = array())
 {
     $default_params = array('db_tables' => array(), 'db_schema' => false, 'db_data' => false, 'db_compress' => false, 'move_progress' => true);
     $params = array_merge($default_params, $params);
     $db_filename = empty($params['db_filename']) ? 'dump_' . date('mdY') . '.sql' : fn_basename($params['db_filename']);
     if (!fn_mkdir(Registry::get('config.dir.backups'))) {
         fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir(Registry::get('config.dir.backups')))));
         return false;
     }
     $dump_file = Registry::get('config.dir.backups') . $db_filename;
     if (is_file($dump_file)) {
         if (!is_writable($dump_file)) {
             fn_set_notification('E', __('error'), __('dump_file_not_writable'));
             return false;
         }
     }
     $result = db_export_to_file($dump_file, $params['db_tables'], $params['db_schema'], $params['db_data'], true, true, $params['move_progress']);
     if (!empty($params['db_compress'])) {
         fn_set_progress('echo', __('compress_dump'), false);
         $ext = $params['db_compress'] == 'tgz' ? '.tgz' : '.zip';
         $result = fn_compress_files($db_filename . $ext, $db_filename, dirname($dump_file));
         unlink($dump_file);
         $dump_file .= $ext;
     }
     if ($result) {
         return $dump_file;
     }
     return false;
 }
function fn_exim_export_file($product_id, $path)
{
    $path = fn_get_files_dir_path() . fn_normalize_path($path);
    $files = db_get_array("SELECT file_path, preview_path, pfolder.folder_id FROM ?:product_files as pfiles" . " LEFT JOIN ?:product_file_folders as pfolder ON pfolder.folder_id = pfiles.folder_id" . " WHERE pfiles.product_id = ?i", $product_id);
    if (!empty($files)) {
        // If backup path is set, check if it exists and copy files there
        if (!empty($path)) {
            if (!fn_mkdir($path)) {
                fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($path))));
                return '';
            }
        }
        $_data = array();
        foreach ($files as $file) {
            Storage::instance('downloads')->export($product_id . '/' . $file['file_path'], $path . '/' . $file['file_path']);
            if (!empty($file['preview_path'])) {
                Storage::instance('downloads')->export($product_id . '/' . $file['preview_path'], $path . '/' . $file['preview_path']);
            }
            $file_data = $file['file_path'];
            if (!empty($file['folder_id'])) {
                $file_data = $file['folder_id'] . '/' . $file_data;
            }
            if (!empty($file['preview_path'])) {
                $file_data = $file_data . '#' . $file['preview_path'];
            }
            $_data[] = $file_data;
        }
        return implode(', ', $_data);
    }
    return '';
}
/**
 * Gets section root
 * @param string $type path type: full - full path, rel - relative path from root directory, repo - repository path
 * @return string path
 */
function fn_te_get_root($type, $section = 'themes')
{
    if ($section == 'themes') {
        if (fn_allowed_for('MULTIVENDOR') || Registry::get('runtime.company_id')) {
            $extra_path = '[theme]/';
        } else {
            $extra_path = '';
        }
        if ($type == 'full') {
            $path = fn_get_theme_path('[themes]/' . $extra_path, 'C');
        } elseif ($type == 'rel') {
            $path = fn_get_theme_path('/[relative]/' . $extra_path, 'C');
        } elseif ($type == 'repo') {
            $path = fn_get_theme_path('[repo]/' . $extra_path, 'C');
        }
    } elseif ($section == 'files') {
        if ($type == 'full') {
            $path = fn_get_files_dir_path();
            if (!is_dir($path)) {
                fn_mkdir($path);
            }
        } elseif ($type == 'rel') {
            $path = '/' . fn_get_rel_dir(fn_get_files_dir_path());
        }
    } elseif ($section == 'images') {
        if ($type == 'full') {
            $path = Storage::instance('images')->getAbsolutePath('');
        } elseif ($type == 'rel') {
            $path = '/' . fn_get_rel_dir(Storage::instance('images')->getAbsolutePath(''));
        }
    }
    fn_set_hook('te_get_root', $type, $section, $path);
    return $path;
}
Beispiel #12
0
 /**
  * Gets pattern URL
  * @param  string  $style_id style ID
  * @param  boolean $root     get style root directory if set to true
  * @return string  pattern URL
  */
 public function getUrl($style_id, $root = false)
 {
     $patterns = $this->getPath($style_id);
     $url = Registry::get('config.current_location') . '/' . fn_get_rel_dir($patterns) . '/';
     if ($root == true) {
         $url = str_replace('/' . $this->getRelPath($style_id), '', $url);
     }
     return $url;
 }
Beispiel #13
0
    }
    Registry::get('view')->assign('database_size', $database_size);
    Registry::get('view')->assign('all_tables', $all_tables);
    $files = fn_get_dir_contents(Registry::get('config.dir.database'), false, true, array('.sql', '.tgz'), '', true);
    sort($files, SORT_STRING);
    $backup_files = array();
    $date_format = Registry::get('settings.Appearance.date_format') . ' ' . Registry::get('settings.Appearance.time_format');
    if (is_array($files)) {
        foreach ($files as $file) {
            $backup_files[$file]['size'] = filesize(Registry::get('config.dir.database') . $file);
            $backup_files[$file]['type'] = strpos($file, '.tgz') === false ? 'sql' : 'tgz';
            $backup_files[$file]['create'] = fn_date_format(filemtime(Registry::get('config.dir.database') . $file), $date_format);
        }
    }
    Registry::get('view')->assign('backup_files', $backup_files);
    Registry::get('view')->assign('backup_dir', fn_get_rel_dir(Registry::get('config.dir.database')));
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['backup_file'])) {
        fn_rm(Registry::get('config.dir.database') . fn_basename($_REQUEST['backup_file']));
    }
    return array(CONTROLLER_STATUS_REDIRECT, "database.manage?selected_section=restore");
}
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);
Beispiel #14
0
            $ext = fn_get_file_ext($backup_dir . $file);
            $backup_files[$file]['size'] = filesize($backup_dir . $file);
            $backup_files[$file]['create'] = fn_date_format(filemtime($backup_dir . $file), $date_format);
            if ($ext == 'tgz') {
                $backup_files[$file]['type'] = DataKeeper::BACKUP_TYPE_UNKNOWN;
            } else {
                $backup_files[$file]['type'] = DataKeeper::getBackupType($backup_dir . $file);
            }
            $backup_files[$file]['can_be_restored'] = true;
            if ($ext == 'tgz' && !$validators->isPharDataAvailable()) {
                $backup_files[$file]['can_be_restored'] = false;
                $required_phardata = true;
            }
            if ($ext == 'zip' && !$validators->isZipArchiveAvailable()) {
                $backup_files[$file]['can_be_restored'] = false;
            }
        }
    }
    if ($required_phardata) {
        fn_set_notification('E', __('error'), __('error_class_phar_data_not_found'));
    }
    $backup_create_allowed = true;
    if (!$validators->isZipArchiveAvailable()) {
        $backup_create_allowed = false;
        fn_set_notification('E', __('error'), __('error_unable_to_create_backups'));
        fn_set_notification('E', __('error'), __('error_zip_php_extension_not_installed'));
    }
    /** @var \Tygh\SmartyEngine\Core $view */
    $view = Tygh::$app['view'];
    $view->assign('database_size', $database_size)->assign('all_tables', $all_tables)->assign('backup_create_allowed', $backup_create_allowed)->assign('backup_files', $backup_files)->assign('backup_dir', fn_get_rel_dir(Registry::get('config.dir.backups')));
}
 /**
  * Installs new language from PO pack
  *
  * @param string $pack_path Path to PO 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 installLanguagePack($pack_path, $params = array())
 {
     $default_params = array('reinstall' => false, 'validate_lang_code' => '', 'force_lang_code' => '');
     $params = array_merge($default_params, $params);
     if (!file_exists($pack_path)) {
         fn_set_notification('E', __('error'), __('unable_to_read_resource', array('[file]' => fn_get_rel_dir($pack_path))));
         return false;
     }
     $lang_meta = self::getLangPacksMeta(dirname($pack_path) . '/', basename($pack_path), $params['reinstall']);
     if (!self::isValidMeta($lang_meta)) {
         // Failed to read meta data of new language
         fn_set_notification('E', __('error'), __('check_po_file'));
         return false;
     }
     if (!empty($params['validate_lang_code']) && $lang_meta['lang_code'] != $params['validate_lang_code']) {
         fn_set_notification('E', __('error'), __('po_meta_error_validating_lang_code'));
         return false;
     }
     $lc = false;
     if (!Registry::get('runtime.company_id')) {
         if (!$params['reinstall']) {
             $language_data = array('lang_code' => $lang_meta['lang_code'], 'name' => $lang_meta['name'], 'country_code' => $lang_meta['country_code']);
             $lc = self::update($language_data, 0);
         } else {
             $lc = true;
         }
         if ($lc !== false) {
             fn_save_languages_integrity();
             $query = array();
             $original_values_query = array();
             $iteration = 0;
             $max_vars_in_query = 500;
             if (!empty($params['force_lang_code'])) {
                 $lang_meta['lang_code'] = $params['force_lang_code'];
             }
             $lang_data = Po::getValues($pack_path, 'Languages');
             if (!is_array($lang_data)) {
                 fn_set_notification('E', __('error'), $lang_data);
                 return array();
             }
             foreach ($lang_data as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $id = $var_data['id'];
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     $query[] = db_quote('(?s, ?s, ?s)', $lang_meta['lang_code'], trim($id), trim($value));
                     $original_values_query[] = db_quote('(?s, ?s)', $var_name, trim($original_value));
                 }
                 if ($iteration > $max_vars_in_query) {
                     self::executeLangQueries('language_values', array('lang_code', 'name', 'value'), $query);
                     self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
                     $query = array();
                     $iteration = 0;
                 }
                 $iteration++;
             }
             self::executeLangQueries('language_values', array('lang_code', 'name', 'value'), $query);
             self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
             $settings_sections = Po::getValues($pack_path, 'SettingsSections');
             $query = array();
             $original_values_query = array();
             $iteration = 0;
             foreach ($settings_sections as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     if (!empty($var_data['parent'])) {
                         $parent_id = db_get_field('SELECT section_id FROM ?:settings_sections WHERE name = ?s AND type = ?s', $var_data['parent'], Settings::ADDON_SECTION);
                         $section_id = db_get_field('SELECT section_id FROM ?:settings_sections WHERE name = ?s AND parent_id = ?i', $var_data['id'], $parent_id);
                     } else {
                         $section_id = db_get_field('SELECT section_id FROM ?:settings_sections WHERE name = ?s', $var_data['id']);
                     }
                     if (empty($section_id)) {
                         continue;
                     }
                     $query[] = db_quote('(?i, ?s, ?s, ?s)', $section_id, 'S', $lang_meta['lang_code'], trim($value), trim($original_value));
                     $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                 }
                 if ($iteration > $max_vars_in_query) {
                     self::executeLangQueries('settings_descriptions', array('object_id', 'object_type', 'lang_code', 'value'), $query);
                     self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
                     $query = array();
                     $iteration = 0;
                 }
                 $iteration++;
             }
             self::executeLangQueries('settings_descriptions', array('object_id', 'object_type', 'lang_code', 'value'), $query);
             self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
             $original_values_query = array();
             $setting_options = Po::getValues($pack_path, 'SettingsOptions');
             foreach ($setting_options as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     $object = Settings::instance()->getId($var_data['id'], $var_data['parent']);
                     if (empty($object)) {
                         continue;
                     }
                     $query = array('object_id' => $object, 'object_type' => 'O', 'lang_code' => $lang_meta['lang_code'], 'value' => trim($value));
                     $update = array('value' => trim($value));
                     $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                     db_query('INSERT INTO ?:settings_descriptions ?e ON DUPLICATE KEY UPDATE ?u', $query, $update);
                     self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
                 }
             }
             $original_values_query = array();
             $settings_tooltips = Po::getValues($pack_path, 'SettingsTooltips');
             foreach ($settings_tooltips as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     $object = Settings::instance()->getId($var_data['id'], $var_data['parent']);
                     if (empty($object)) {
                         continue;
                     }
                     $query = array('object_id' => $object, 'object_type' => 'O', 'lang_code' => $lang_meta['lang_code'], 'tooltip' => trim($value));
                     $update = array('tooltip' => trim($value));
                     $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                     db_query('INSERT INTO ?:settings_descriptions ?e ON DUPLICATE KEY UPDATE ?u', $query, $update);
                     self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
                 }
             }
             $setting_variants = Po::getValues($pack_path, 'SettingsVariants');
             $query = array();
             $original_values_query = array();
             $iteration = 0;
             foreach ($setting_variants as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     $object = Settings::instance()->getVariant($var_data['section'], $var_data['parent'], $var_data['id']);
                     if (empty($object)) {
                         continue;
                     }
                     $query[] = db_quote('(?i, ?s, ?s, ?s)', $object['variant_id'], 'V', $lang_meta['lang_code'], trim($value));
                     $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                 }
                 if ($iteration > $max_vars_in_query) {
                     self::executeLangQueries('settings_descriptions', array('variant_id', 'object_type', 'lang_code', 'value'), $query);
                     self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
                     $query = array();
                     $iteration = 0;
                 }
                 $iteration++;
             }
             self::executeLangQueries('settings_descriptions', array('object_id', 'object_type', 'lang_code', 'value'), $query);
             self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
             $addons = Po::getValues($pack_path, 'Addons');
             $query = array();
             $original_values_query = array();
             if (!empty($addons)) {
                 foreach ($addons as $var_name => $var_data) {
                     if (!empty($var_name)) {
                         $value = implode('', $var_data['msgstr']);
                         $original_value = $var_data['msgid'];
                         $value = empty($value) ? $original_value : $value;
                         if ($var_data['parent'] == 'name') {
                             db_query('UPDATE ?:addon_descriptions SET name = ?s WHERE addon = ?s AND lang_code = ?s', trim($value), $var_data['id'], $lang_meta['lang_code']);
                         } else {
                             db_query('UPDATE ?:addon_descriptions SET description = ?s WHERE addon = ?s AND lang_code = ?s', trim($value), $var_data['id'], $lang_meta['lang_code']);
                         }
                         $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                     }
                 }
                 self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
             }
             $profile_fields = Po::getValues($pack_path, 'ProfileFields');
             $query = array();
             $original_values_query = array();
             foreach ($profile_fields as $var_name => $var_data) {
                 if (!empty($var_name)) {
                     $value = implode('', $var_data['msgstr']);
                     $original_value = $var_data['msgid'];
                     $value = empty($value) ? $original_value : $value;
                     $field_ids = db_get_fields('SELECT field_id FROM ?:profile_fields WHERE field_name = ?s', $var_data['id']);
                     if (empty($field_ids)) {
                         continue;
                     }
                     foreach ($field_ids as $field_id) {
                         $query[] = db_quote('(?i, ?s, ?s, ?s)', $field_id, trim($value), 'F', $lang_meta['lang_code']);
                     }
                     $original_values_query[] = db_quote('(?s, ?s)', trim($var_name), trim($original_value));
                 }
             }
             self::executeLangQueries('profile_field_descriptions', array('object_id', 'description', 'object_type', 'lang_code'), $query);
             self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query);
             if (!$params['reinstall']) {
                 fn_set_notification('N', __('notice'), __('text_changes_saved'));
             }
             $_suffix = '';
         }
     }
     return $lc;
 }
Beispiel #16
0
         $kop = substr($for_rub, -$length_for_kop);
         $total_print = '<strong>' . $rub . '</strong>&nbsp;' . __("sbrf_rub") . '&nbsp;<strong>' . $kop . '</strong>&nbsp;' . __("sbrf_kop");
     } else {
         $total_print = '<strong>' . $for_rub . '</strong>&nbsp;' . __("sbrf_rub");
     }
 } else {
     $total_print = fn_format_price_by_currency($order_info['total']);
 }
 $view = Tygh::$app['view'];
 $view->assign('total_print', $total_print);
 $view->assign('order_info', $order_info);
 $view->assign('fonts_path', fn_get_theme_path('[relative]/[theme]/media/fonts'));
 $temp_dir = Registry::get('config.dir.cache_misc') . 'tmp/';
 fn_mkdir($temp_dir);
 $path = fn_qr_generate($order_info, '|', $temp_dir);
 $url_qr_code = Registry::get('config.http_location') . '/' . fn_get_rel_dir($path);
 $view->assign('url_qr_code', $url_qr_code);
 if ($mode == "send_sbrf_receipt") {
     if (!empty($order_info['email'])) {
         fn_disable_live_editor_mode();
         $html = array($view->displayMail('addons/rus_payments/print_sbrf_receipt.tpl', false, 'C'));
         Pdf::render($html, fn_get_files_dir_path() . 'sberbank_receipt.pdf', 'save');
         $data = array('order_info' => $order_info, 'total_print' => $total_print, 'fonts_path' => fn_get_theme_path('[relative]/[theme]/media/fonts'), 'url_qr_code' => $url_qr_code, 'email_subj' => __("sbrf_receipt_for_payment", array('[order_id]' => $order_info['order_id'])));
         Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'default_company_orders_department', 'data' => $data, 'attachments' => array(fn_get_files_dir_path() . 'sberbank_receipt.pdf'), 'tpl' => 'addons/rus_payments/print_sbrf_receipt.tpl', 'is_html' => true), 'A');
         fn_set_notification('N', __('notice'), __('text_email_sent'));
     }
 } else {
     $view->assign('show_print_button', true);
     $view->displayMail('addons/rus_payments/print_sbrf_receipt.tpl', true, 'C');
 }
 exit;
Beispiel #17
0
        }
    }
    // Get export files
    $export_files = fn_get_dir_contents(fn_get_files_dir_path(), false, true);
    $result = array();
    foreach ($export_files as $file) {
        $result[] = array('name' => $file, 'size' => filesize(fn_get_files_dir_path() . $file));
    }
    // Export languages
    foreach (fn_get_translation_languages() as $lang_code => $lang_data) {
        $export_langs[$lang_code] = $lang_data['name'];
    }
    Registry::set('navigation.dynamic.sections', $sections);
    Registry::set('navigation.dynamic.active_section', $_REQUEST['section']);
    Registry::get('view')->assign('export_files', $result);
    Registry::get('view')->assign('files_rel_dir', fn_get_rel_dir(fn_get_files_dir_path()));
    Registry::get('view')->assign('pattern', $patterns[$pattern_id]);
    Registry::get('view')->assign('layouts', $layouts);
    Registry::get('view')->assign('export_langs', $export_langs);
} elseif ($mode == 'import') {
    if (empty($_REQUEST['section'])) {
        $_REQUEST['section'] = 'products';
    }
    list($sections, $patterns) = fn_get_patterns($_REQUEST['section'], 'import');
    if (empty($sections) && empty($patterns) || isset($_REQUEST['section']) && empty($sections[$_REQUEST['section']])) {
        return array(CONTROLLER_STATUS_DENIED);
    }
    $pattern_id = empty($_REQUEST['pattern_id']) ? key($patterns) : $_REQUEST['pattern_id'];
    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));
    }
Beispiel #18
0
            $view->setArea('C', '', Registry::get('runtime.company_id'));
            $updated_template_path = str_replace($view->getTemplateDir(0), '', $file_path);
            $view->clearCompiledTemplate($updated_template_path);
            $view->setArea(AREA, '', Registry::get('runtime.company_id'));
        } else {
            fn_set_notification('E', __('error'), __('cannot_write_file', array('[file]' => fn_get_rel_dir($file_path))));
        }
        exit;
    }
    if ($mode == 'upload_file') {
        $uploaded_data = fn_filter_uploaded_data('uploaded_data');
        $pname = fn_normalize_path($root_dir . $_REQUEST['path'] . '/');
        foreach ((array) $uploaded_data as $udata) {
            if (fn_te_check_path($pname)) {
                if (!fn_copy($udata['path'], $pname . $udata['name'])) {
                    fn_set_notification('E', __('error'), __('cannot_write_file', array('[file]' => fn_get_rel_dir($pname . $udata['name']))));
                }
            }
        }
        return array(CONTROLLER_STATUS_OK, "templates.manage");
    }
}
if ($mode == 'manage') {
    if (!empty($_REQUEST['selected_path'])) {
        Tygh::$app['view']->assign('selected_path', '/' . fn_te_form_path($_REQUEST['selected_path']));
    }
    Tygh::$app['view']->assign('rel_path', fn_te_get_root('rel'));
} elseif ($mode == 'init_view') {
    $dir = $_REQUEST['dir'];
    $tpath = fn_normalize_path($root_dir . $dir);
    if (fn_te_check_path($tpath) === false || !file_exists($tpath)) {
Beispiel #19
0
function fn_rus_exim_1c_get_dir_1c()
{
    $dir_1c = fn_get_files_dir_path() . 'exim/1C_' . date('dmY') . '/';
    $dir_1c_url = Registry::get('config.http_location') . '/' . fn_get_rel_dir($dir_1c);
    $dir_1c_images = Storage::instance('images')->getAbsolutePath('from_1c/');
    return array($dir_1c, $dir_1c_url, $dir_1c_images);
}
Beispiel #20
0
        $database_size += $v['Data_length'] + $v['Index_length'];
        $all_tables[] = $v['Name'];
    }
    $view->assign('database_size', $database_size);
    $view->assign('all_tables', $all_tables);
    $files = fn_get_dir_contents(Registry::get('config.dir.backups'), false, true, array('.sql', '.tgz', '.zip'), '', true);
    sort($files, SORT_STRING);
    $backup_files = array();
    $date_format = Registry::get('settings.Appearance.date_format') . ' ' . Registry::get('settings.Appearance.time_format');
    if (is_array($files)) {
        $backup_dir = Registry::get('config.dir.backups');
        foreach ($files as $file) {
            $ext = fn_get_file_ext($backup_dir . $file);
            $backup_files[$file]['size'] = filesize($backup_dir . $file);
            $backup_files[$file]['create'] = fn_date_format(filemtime($backup_dir . $file), $date_format);
            if ($ext == 'sql') {
                $backup_files[$file]['type'] = 'database';
            } else {
                $backup_files[$file]['type'] = DataKeeper::getArchiveType($backup_dir . $file);
            }
        }
    }
    $supported_archive_types = array('tgz');
    $validators = new Validators();
    if ($validators->isZipArchiveAvailable()) {
        $supported_archive_types[] = 'zip';
    }
    $view->assign('supported_archive_types', $supported_archive_types);
    $view->assign('backup_files', $backup_files);
    $view->assign('backup_dir', fn_get_rel_dir(Registry::get('config.dir.backups')));
}
Beispiel #21
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;
}
Beispiel #22
0
 /**
  * Creates database and imports dump there
  * @param  string  $db_name db name
  * @return boolean true on success, false - otherwise
  */
 public static function createDb($db_name = '')
 {
     $snapshot_dir = Registry::get('config.dir.snapshots');
     $dbdump_filename = empty($db_name) ? 'cmp_current.sql' : 'cmp_release.sql';
     if (!fn_mkdir($snapshot_dir)) {
         fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($snapshot_dir))));
         return false;
     }
     $dump_file = $snapshot_dir . $dbdump_filename;
     if (is_file($dump_file)) {
         if (!is_writable($dump_file)) {
             fn_set_notification('E', __('error'), __('dump_file_not_writable'));
             return false;
         }
     }
     $fd = @fopen($snapshot_dir . $dbdump_filename, 'w');
     if (!$fd) {
         fn_set_notification('E', __('error'), __('dump_cant_create_file'));
         return false;
     }
     if (!empty($db_name)) {
         Database::changeDb($db_name);
     }
     // set export format
     db_query("SET @SQL_MODE = 'MYSQL323'");
     fn_start_scroller();
     $create_statements = array();
     $insert_statements = array();
     $status_data = db_get_array("SHOW TABLE STATUS");
     $dbdump_tables = array();
     foreach ($status_data as $k => $v) {
         $dbdump_tables[] = $v['Name'];
     }
     // get status data
     $t_status = db_get_hash_array("SHOW TABLE STATUS", 'Name');
     foreach ($dbdump_tables as $k => $table) {
         fn_echo('<br />' . __('backupping_data') . ': <b>' . $table . '</b>&nbsp;&nbsp;');
         $total_rows = db_get_field("SELECT COUNT(*) FROM {$table}");
         $index = db_get_array("SHOW INDEX FROM {$table}");
         $order_by = array();
         foreach ($index as $kk => $vv) {
             if ($vv['Key_name'] == 'PRIMARY') {
                 $order_by[] = '`' . $vv['Column_name'] . '`';
             }
         }
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . implode(',', $order_by);
         } else {
             $order_by = '';
         }
         // Define iterator
         if (!empty($t_status[$table]) && $t_status[$table]['Avg_row_length'] < DB_MAX_ROW_SIZE) {
             $it = DB_ROWS_PER_PASS;
         } else {
             $it = 1;
         }
         for ($i = 0; $i < $total_rows; $i = $i + $it) {
             $table_data = db_get_array("SELECT * FROM {$table} {$order_by} LIMIT {$i}, {$it}");
             foreach ($table_data as $_tdata) {
                 $_tdata = fn_add_slashes($_tdata, true);
                 $values = array();
                 foreach ($_tdata as $v) {
                     $values[] = $v !== null ? "'{$v}'" : 'NULL';
                 }
                 fwrite($fd, "INSERT INTO {$table} (`" . implode('`, `', array_keys($_tdata)) . "`) VALUES (" . implode(', ', $values) . ");\n");
             }
             fn_echo(' .');
         }
     }
     fn_stop_scroller();
     if (!empty($db_name)) {
         Settings::instance()->reloadSections();
     }
     if (fn_allowed_for('ULTIMATE')) {
         $companies = fn_get_short_companies();
         asort($companies);
         $settings['company_root'] = Settings::instance()->getList();
         foreach ($companies as $k => $v) {
             $settings['company_' . $k] = Settings::instance()->getList(0, 0, false, $k);
         }
     } else {
         $settings['company_root'] = Settings::instance()->getList();
     }
     if (!empty($db_name)) {
         Database::changeDb(Registry::get('config.db_name'));
     }
     $settings = self::processSettings($settings, '');
     $settings = self::formatSettings($settings['data']);
     ksort($settings);
     $data = print_r($settings, true);
     fwrite($fd, $data);
     fclose($fd);
     @chmod($snapshot_dir . $dbdump_filename, DEFAULT_FILE_PERMISSIONS);
     return true;
 }
Beispiel #23
0
 /**
  * Retrieves codes of languages, which .PO-files have to be updated by the upgrade package.
  *
  * @param array $package_content_schema Content schema of the upgrade package
  *
  * @return array List of language codes (i.e. array('ru', 'en', 'ua', ...))
  */
 public function getLangCodesToReinstallFromContentSchema($package_content_schema)
 {
     $lang_codes = array();
     $lang_packs_dir_path = fn_get_rel_dir($this->config['dir']['lang_packs']);
     if (isset($package_content_schema['files'])) {
         foreach ($package_content_schema['files'] as $file_path => $file_info) {
             // the file is located at "var/langs" directory,
             // so we should parse language code from file path
             if (strpos($file_path, $lang_packs_dir_path) === 0) {
                 // remove "var/langs" part from file path
                 $file_path = trim(str_replace($lang_packs_dir_path, '', $file_path), '\\/');
                 // first directory of path is the lang code
                 $parent_directories = fn_get_parent_directory_stack($file_path);
                 $lang_code = end($parent_directories);
                 if ($lang_code) {
                     $lang_code = trim($lang_code, '\\/');
                     $lang_codes[$lang_code] = $lang_code;
                 }
             }
         }
     }
     return array_values($lang_codes);
 }