Example #1
0
 /**
  * Checks if file with this name is already exist and generate new name if it is so
  *
  * @param  string $file path to file
  * @return string unique file name
  */
 public function generateName($file)
 {
     $info = fn_pathinfo($file);
     while ($this->isExist($file)) {
         $info['filename'] .= '_' . fn_strtolower(fn_generate_code('', $this->_file_suffix_length));
         $file = $info['dirname'] . '/' . $info['filename'] . '.' . $info['extension'];
     }
     return $file;
 }
Example #2
0
 /**
  * Checks if file with this name is already exist and generate new name if it is so
  *
  * @param  string $file path to file
  * @return string unique file name
  */
 protected function _generateName($file)
 {
     if ($this->isExist($file)) {
         $parts = explode('.', $file);
         $parts[0] .= '_' . fn_strtolower(fn_generate_code('', $this->_file_suffix_length));
         $file = implode('.', $parts);
     }
     return $file;
 }
Example #3
0
    public static function WAGetCities($location)
    {
        $city_name = $location['city'];
        $url = self::$url;
        if (!empty($location['country'])) {
            $country_name = fn_get_country_name($location['country'], 'ru');
        } else {
            $country_name = '';
        }
        $data = <<<EOT
        <root xmlns="http://spsr.ru/webapi/Info/GetCities/1.0">
            <p:Params Name="WAGetCities" Ver="1.0" xmlns:p="http://spsr.ru/webapi/WA/1.0" />
            <GetCities CityName="{$city_name}" CountryName="{$country_name}"/>
        </root>
EOT;
        $response = Http::post($url, $data, self::$extra);
        $xml = simplexml_load_string($response);
        $return = false;
        $status_code = (string) $xml->Result['RC'];
        if ($status_code != 0) {
            self::$last_error = !empty(self::$_error_descriptions[$status_code]) ? self::$_error_descriptions[$status_code] : __("shippings.spsr.error_city");
        } else {
            if (isset($xml->City->Cities) && !empty($xml->City)) {
                $return = array();
                $city_name = fn_strtolower($city_name);
                foreach ($xml->City->Cities as $city) {
                    $spsr_city = fn_strtolower((string) $city['CityName']);
                    if ($spsr_city == $city_name) {
                        $return = self::attributesToArray($city);
                    }
                }
            }
        }
        if (empty($return)) {
            self::$last_error = __("shipping.sdek.not_city");
        }
        return $return;
    }
Example #4
0
$post['transactionAmount'] = $order_info['total'];
// Payment Params
$post['paymentCardName'] = $order_info['payment_info']['cardholder_name'];
$post['paymentCardNumber'] = $order_info['payment_info']['card_number'];
$post['paymentCardExpiry'] = $order_info['payment_info']['expiry_month'] . $order_info['payment_info']['expiry_year'];
$post['paymentCardCSC'] = $order_info['payment_info']['cvv2'];
// Customer Params
$post['customerName'] = $order_info['b_firstname'] . ' ' . $order_info['b_lastname'];
$post['customerCountry'] = $order_info['b_country'];
$post['customerState'] = $order_info['b_state_descr'];
$post['customerCity'] = $order_info['b_city'];
$post['customerAddress'] = $order_info['b_address'] . (!empty($order_info['b_address_2']) ? ' ; ' . $order_info['b_address_2'] : '');
$post['customerPostCode'] = $order_info['b_zipcode'];
$post['customerIP'] = $_SERVER['REMOTE_ADDR'];
//Transaction Hash
$post['hash'] = md5(fn_strtolower($passPhrase . $processor_data['processor_params']['merchant_id'] . $order_info['total'] . $processor_data['processor_params']['currency']));
// Post a request and analyse the response
Registry::set('log_cut_data', array('paymentCardName', 'paymentCardNumber', 'paymentCardExpiry', 'paymentCardCSC'));
$response_data = Http::post($post_address, $post);
if (!empty($response_data)) {
    // Parse the XML
    $xml = simplexml_load_string($response_data);
    // Convert the result from a SimpleXMLObject into an array
    $xml = (array) $xml;
    // Validate the response - the only successful code is 0
    $status = (int) $xml['responseCode'] === 0 ? 'P' : 'F';
    // Pass TRN Status, Id and Response
    $pp_response = array('order_status' => $status, 'transaction_id' => isset($xml['transactionID']) ? $xml['transactionID'] : null, 'reason_text' => ($pos = strpos($xml['responseMessage'], ':')) === false ? $xml['responseMessage'] : substr($xml['responseMessage'], $pos + 1));
} else {
    // Invalid response
    $pp_response = array('order_status' => 'F', 'transaction_id' => null, 'reason_text' => 'API response invalid.');
Example #5
0
    }
    $width = !empty($_REQUEST['width']) ? $_REQUEST['width'] : BCD_DEFAULT_WIDTH;
    $height = !empty($_REQUEST['height']) ? $_REQUEST['height'] : BCD_DEFAULT_HEIGHT;
    $id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : '';
    $type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : '';
    $xres = 1;
    $font = 3;
    $prefix = 'spsr';
    $objects = array('I25' => 'I25Object', 'C39' => 'C39Object', 'C128A' => 'C128AObject', 'C128B' => 'C128BObject', 'C128C' => 'C128CObject');
    $numeric_objects = array('I25' => true, 'C128C' => true);
    if (!empty($objects[$type])) {
        if (!empty($numeric_objects[$type]) && !is_numeric($prefix)) {
            $prefix = '';
        }
        $code = $prefix . $id;
        require Registry::get('config.dir.addons') . 'barcode/lib/barcodegenerator/' . fn_strtolower($objects[$type]) . '.php';
        $obj = new $objects[$type]($width, $height, $style, $code);
        if ($obj) {
            $obj->SetFont($font);
            $obj->DrawObject($xres);
            $obj->FlushObject();
            $obj->DestroyObject();
            unset($obj);
        }
    } else {
        __DEBUG__("Need bar code type ex. C39");
    }
    exit;
}
function fn_spsr_pre_check_invoice_create($order_id, $section, $spsr_shipments = array())
{
Example #6
0
        fn_set_notification('N', __('notice'), __('text_directory_created', array('[directory]' => fn_basename($folder_path))));
    } else {
        fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_basename($folder_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'get_file') {
    $pname = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($pname)) {
        if (is_file($pname) && !in_array(fn_strtolower(fn_get_file_ext($pname)), Registry::get('config.forbidden_file_extensions'))) {
            fn_get_file($pname);
        }
    }
    exit;
} elseif ($mode == 'edit') {
    $fname = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($fname) && !in_array(fn_strtolower(fn_get_file_ext($fname)), Registry::get('config.forbidden_file_extensions'))) {
        Tygh::$app['ajax']->assign('content', fn_get_contents($fname));
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    exit;
} elseif ($mode == 'restore') {
    $copied = false;
    $file_path = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($file_path)) {
        $repo_path = str_replace($root_dir, fn_te_get_root('repo'), $file_path);
        if (!file_exists($repo_path) && fn_get_theme_path('[theme]') != Registry::get('config.base_theme') && is_dir(fn_get_theme_path('[repo]/[theme]'))) {
            $repo_path = preg_replace("/\\/themes_repository\\/(\\w+)\\//", "/themes_repository/" . Registry::get('config.base_theme') . "/", $repo_path);
        }
        $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : '');
        if (!empty($object_base) && fn_copy($repo_path, $file_path)) {
Example #7
0
 /**
  * Generates additional cache levels by storage
  *
  * @param  array  $cache_scheme Block cache scheme
  * @param  string $handler_name Name of handlers frocm block scheme
  * @param  array  $storage      Storage to find params
  * @return string Additional chache level
  */
 private static function _generateAdditionalCacheLevel($cache_scheme, $handler_name, $storage)
 {
     $additional_level = '';
     if (!empty($cache_scheme[$handler_name]) && is_array($cache_scheme[$handler_name])) {
         foreach ($cache_scheme[$handler_name] as $param) {
             $param = fn_strtolower(str_replace('%', '', $param));
             if (isset($storage[$param])) {
                 $additional_level .= '|' . $param . '=' . md5(serialize($storage[$param]));
             }
         }
     }
     return $additional_level;
 }
Example #8
0
        $full_path = fn_get_theme_path('[themes]/[theme]', 'C') . '/templates/' . $_REQUEST['file'];
        if (fn_check_path($full_path)) {
            $c_name = fn_normalize_path($full_path);
            $r_name = fn_normalize_path(Registry::get('config.dir.themes_repository') . Registry::get('config.base_theme') . '/templates/' . $_REQUEST['file']);
            if (is_file($r_name)) {
                $copied = fn_copy($r_name, $c_name);
            }
            if ($copied) {
                fn_set_notification('N', __('notice'), __('text_file_restored', array('[file]' => fn_basename($_REQUEST['file']))));
            } else {
                fn_set_notification('E', __('error'), __('text_cannot_restore_file', array('[file]' => fn_basename($_REQUEST['file']))));
            }
            if ($copied) {
                if (defined('AJAX_REQUEST')) {
                    Registry::get('ajax')->assign('force_redirection', fn_url($_REQUEST['current_url']));
                    Registry::get('ajax')->assign('non_ajax_notifications', true);
                }
                return array(CONTROLLER_STATUS_OK, $_REQUEST['current_url']);
            }
        }
        exit;
    }
}
if ($mode == 'get_content') {
    $ext = fn_strtolower(fn_get_file_ext($_REQUEST['file']));
    if ($ext == 'tpl') {
        $theme_path = fn_get_theme_path('[themes]/[theme]/templates/', 'C');
        Registry::get('ajax')->assign('content', fn_get_contents($_REQUEST['file'], $theme_path));
    }
    exit;
}
Example #9
0
/**
 * Filter data from file uploader
 *
 * @param string $name
 * @return array $filtered
 */
function fn_filter_uploaded_data($name, $filter_by_ext = array())
{
    $udata_local = fn_rebuild_files('file_' . $name);
    $udata_other = !empty($_REQUEST['file_' . $name]) ? $_REQUEST['file_' . $name] : array();
    $utype = !empty($_REQUEST['type_' . $name]) ? $_REQUEST['type_' . $name] : array();
    //var_dump($name);echo"<br/>";
    //    if($name=='p_feature_var_extra_image_detailed'){
    //        var_dump($utype);die();
    //    }
    if (empty($utype)) {
        return array();
    }
    $filtered = array();
    foreach ($utype as $id => $type) {
        if ($type == 'local' && !fn_is_empty(@$udata_local[$id])) {
            $filtered[$id] = fn_get_local_data(Bootstrap::stripSlashes($udata_local[$id]));
        } elseif ($type == 'server' && !fn_is_empty(@$udata_other[$id]) && AREA == 'A') {
            fn_get_last_key($udata_other[$id], 'fn_get_server_data', true);
            $filtered[$id] = $udata_other[$id];
        } elseif ($type == 'url' && !fn_is_empty(@$udata_other[$id])) {
            fn_get_last_key($udata_other[$id], 'fn_get_url_data', true);
            $filtered[$id] = $udata_other[$id];
        }
        if (isset($filtered[$id]) && $filtered[$id] === false) {
            unset($filtered[$id]);
            fn_set_notification('E', __('error'), __('cant_upload_file'));
        }
        if (!empty($filtered[$id]) && is_array($filtered[$id]) && !empty($filtered[$id]['name'])) {
            $filtered[$id]['name'] = str_replace(' ', '_', urldecode($filtered[$id]['name']));
            // replace spaces with underscores
            $ext = fn_get_file_ext($filtered[$id]['name']);
            if (!empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) {
                unset($filtered[$id]);
                fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext)));
            } elseif (in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) {
                unset($filtered[$id]);
                fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext)));
            }
        }
        if (!empty($filtered[$id]['path']) && in_array(fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain'), Registry::get('config.forbidden_mime_types'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain'))));
            unset($filtered[$id]);
        }
    }
    static $shutdown_inited;
    if (!$shutdown_inited) {
        $shutdown_inited = true;
        register_shutdown_function('fn_remove_temp_data');
    }
    return $filtered;
}
        fn_set_notification('N', __('notice'), __('text_permissions_changed'));
    } else {
        fn_set_notification('E', __('error'), __('error_permissions_not_changed'));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'get_file') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($pname, $_SESSION['active_section'])) {
        if (is_file($pname) && !in_array(fn_strtolower(fn_get_file_ext($pname)), Registry::get('config.forbidden_file_extensions'))) {
            fn_get_file($pname);
        }
    }
    exit;
} elseif ($mode == 'edit') {
    $fname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($fname, $_SESSION['active_section']) && !in_array(fn_strtolower(fn_get_file_ext($fname)), Registry::get('config.forbidden_file_extensions'))) {
        Registry::get('ajax')->assign('content', fn_get_contents($fname));
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    exit;
} elseif ($mode == 'restore') {
    $copied = false;
    $file_path = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($file_path, $_SESSION['active_section'])) {
        $repo_path = str_replace($section_root_dir, fn_te_get_root('repo'), $file_path);
        if (!file_exists($repo_path) && fn_get_theme_path('[theme]') != Registry::get('config.base_theme') && is_dir(fn_get_theme_path('[repo]/[theme]'))) {
            $repo_path = preg_replace("/\\/themes_repository\\/(\\w+)\\//", "/themes_repository/" . Registry::get('config.base_theme') . "/", $repo_path);
        }
        $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : '');
        if (!empty($object_base) && fn_copy($repo_path, $file_path)) {
Example #11
0
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    require './init_payment.php';
    $order_id = (int) $_REQUEST['order_id'];
    if (!empty($_REQUEST['payer_merchant_reference_id']) || !empty($_REQUEST['payer_callback_type']) && $_REQUEST['payer_callback_type'] == 'settle') {
        // Settle data is received
        $payment_id = db_get_field("SELECT payment_id FROM ?:orders WHERE order_id = ?i", $order_id);
        $processor_data = fn_get_payment_method_data($payment_id);
        $order_info = fn_get_order_info($order_id);
        if ($order_info['status'] == 'N' || $order_info['status'] == 'O') {
            $pp_response = array();
            $req_url = ($_SERVER['SERVER_PORT'] == '80' ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
            $ok1 = fn_strtolower($_REQUEST['md5sum']) == fn_strtolower(md5($processor_data['processor_params']['key_1'] . substr($req_url, 0, strpos($req_url, '&md5sum')) . $processor_data['processor_params']['key_2']));
            $valid_ips = array('217.151.207.84', '79.136.103.5', '79.136.103.9', '94.140.57.180', '94.140.57.184', '192.168.100.1');
            $ok2 = in_array($_SERVER['REMOTE_ADDR'], $valid_ips);
            $pp_response['order_status'] = $ok1 && $ok2 ? 'P' : 'F';
            $pp_response['reason_text'] = __('order_id') . '-' . $order_id;
            $pp_response['transaction_id'] = !empty($_REQUEST['payread_payment_id']) ? $_REQUEST['payread_payment_id'] : 'BANK';
            fn_finish_payment($order_id, $pp_response);
        }
        echo "TRUE";
        exit;
    } else {
        // Customer is redirected from the Pay&Read server
        // Check if the settle data was recieved and order status was upsated otherwise transaction is failed
        $order_info = fn_get_order_info($order_id);
        if ($order_info['status'] == 'N' || $order_info['status'] == 'O') {
            $pp_response = array();
Example #12
0
/**
 * Detect user agent
 *
 * @return boolean true always
 */
function fn_init_ua()
{
    static $crawlers = array('google', 'bot', 'yahoo', 'spider', 'archiver', 'curl', 'python', 'nambu', 'Twitterbot', 'perl', 'sphere', 'PEAR', 'java', 'wordpress', 'radian', 'crawl', 'yandex', 'eventbox', 'monitor', 'mechanize', 'facebookexternal');
    $http_ua = fn_strtolower($_SERVER['HTTP_USER_AGENT']);
    if (strpos($http_ua, 'shiretoko') !== false || strpos($http_ua, 'firefox') !== false) {
        $ua = 'firefox';
    } elseif (strpos($http_ua, 'chrome') !== false) {
        $ua = 'chrome';
    } elseif (strpos($http_ua, 'safari') !== false) {
        $ua = 'safari';
    } elseif (strpos($http_ua, 'opera') !== false) {
        $ua = 'opera';
    } elseif (strpos($http_ua, 'msie') !== false || strpos($http_ua, 'trident/7.0; rv:11.0') !== false) {
        // IE11 does not send normal headers and seems like Mozilla:
        // Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko
        $ua = 'ie';
        if (preg_match("/msie (6|7|8)/i", $http_ua)) {
            Registry::set('runtime.unsupported_browser', true);
        }
    } elseif (preg_match('/(' . implode('|', $crawlers) . ')/', $http_ua, $m)) {
        $ua = 'crawler';
        fn_define('CRAWLER', $m[1]);
        fn_define('NO_SESSION', true);
        // do not start session for crawler
    } else {
        $ua = 'unknown';
    }
    fn_define('USER_AGENT', $ua);
    return array(INIT_STATUS_OK);
}
function fn_clone_table_data($table_data, $clone_data, $start, $from, $to, $extra = array())
{
    static $schema;
    static $cloned_ids = array();
    $clone_id = $table_data['name'];
    if (!isset($cloned_ids[$clone_id])) {
        $cloned_ids[$clone_id] = array();
    }
    if (empty($schema)) {
        $schema = fn_init_clone_schemas();
    }
    $limit = 50;
    // Clone 50 lines per one iteration
    $return = array();
    $condition = '';
    if (!empty($table_data['condition'])) {
        $condition = ' AND ' . implode(' AND ', $table_data['condition']);
        preg_match_all('/%(.*?)%/', $condition, $variables);
        foreach ($variables[1] as $variable) {
            $variable = fn_strtolower($variable);
            $var = ${$variable};
            if (is_array($var)) {
                $var = implode(', ', $var);
            }
            $condition = preg_replace('/%(.*?)%/', $var, $condition, 1);
        }
    }
    if (!empty($table_data['dependence_tree'])) {
        $ids = fn_build_dependence_tree($table_data['name'], $table_data['key'], $parent = 'parent_id', $from);
        $data = $_data = array();
        if (!empty($ids)) {
            $_data = db_get_hash_array('SELECT * FROM ?:' . $table_data['name'] . ' WHERE company_id = ?i ' . $condition . 'AND ' . $table_data['key'] . ' IN (?a)', $table_data['key'], $from, $ids);
        }
        foreach ($ids as $id) {
            if (isset($_data[$id])) {
                $data[] = $_data[$id];
            }
        }
        unset($_data, $ids);
        $start = db_get_field('SELECT COUNT(*) FROM ?:' . $table_data['name'] . ' WHERE company_id = ?i', $from);
    } elseif (empty($clone_data)) {
        $data = db_get_array('SELECT * FROM ?:' . $table_data['name'] . ' WHERE company_id = ?i ' . $condition . ' LIMIT ?i, ?i', $from, $start, $limit);
    } else {
        $data = db_get_array('SELECT * FROM ?:' . $table_data['name'] . ' WHERE ' . $table_data['key'] . ' IN (?a)' . $condition, array_keys($clone_data));
    }
    if (!empty($data)) {
        // We using sharing. So do not use "quick" insert schema...
        if (false && empty($table_data['children']) && empty($table_data['pre_process']) && empty($table_data['post_process']) && empty($table_data['return_clone_data'])) {
            $exclude = array(empty($clone_data) ? $table_data['key'] : '');
            if (!empty($table_data['exclude'])) {
                $exclude = array_merge($exclude, $table_data['exclude']);
            }
            $fields = fn_get_table_fields($table_data['name'], $exclude, true);
            $query = 'REPLACE INTO ?:' . $table_data['name'] . ' (' . implode(',', $fields) . ') VALUES ';
            $rows = array();
            foreach ($data as $row) {
                if (empty($clone_data)) {
                    unset($row[$table_data['key']]);
                } else {
                    $row[$table_data['key']] = $clone_data[$row[$table_data['key']]];
                }
                if (!empty($extra)) {
                    foreach ($extra as $field => $field_data) {
                        if (isset($field_data[$row[$field]])) {
                            $row[$field] = $field_data[$row[$field]];
                        }
                    }
                }
                if (isset($row['company_id'])) {
                    $row['company_id'] = $to;
                }
                if (!empty($table_data['exclude'])) {
                    foreach ($table_data['exclude'] as $exclude_field) {
                        unset($row[$exclude_field]);
                    }
                }
                $row = explode('(###)', addslashes(implode('(###)', $row)));
                $rows[] = "('" . implode("', '", $row) . "')";
            }
            $query .= implode(', ', $rows);
            db_query($query);
        } else {
            foreach ($data as $id => $row) {
                if (!empty($table_data['key'])) {
                    $key = $row[$table_data['key']];
                    if (empty($clone_data)) {
                        unset($row[$table_data['key']]);
                    } else {
                        $row[$table_data['key']] = $clone_data[$row[$table_data['key']]];
                    }
                }
                if (isset($row['company_id'])) {
                    $row['company_id'] = $to;
                }
                if (!empty($extra)) {
                    foreach ($extra as $field => $field_data) {
                        if (isset($field_data[$row[$field]])) {
                            $row[$field] = $field_data[$row[$field]];
                        }
                    }
                }
                if (!empty($table_data['exclude'])) {
                    foreach ($table_data['exclude'] as $exclude_field) {
                        unset($row[$exclude_field]);
                    }
                }
                if (!empty($table_data['pre_process']) && function_exists($table_data['pre_process'])) {
                    call_user_func($table_data['pre_process'], $table_data, $row, $clone_data, $cloned_ids[$clone_id], $extra);
                }
                $new_key = db_query('REPLACE INTO ?:' . $table_data['name'] . ' ?e', $row);
                if (!empty($key)) {
                    $cloned_ids[$clone_id][$key] = $new_key;
                }
                if (!empty($table_data['return_clone_data'])) {
                    if (count($table_data['return_clone_data']) == 1 && reset($table_data['return_clone_data']) == $table_data['key']) {
                        $return[$table_data['key']][$key] = $new_key;
                    } else {
                        $_key = !empty($table_data['return_clone_data']) ? reset($table_data['return_clone_data']) : $table_data['key'];
                        $new_data = db_get_row('SELECT ' . implode(', ', $table_data['return_clone_data']) . ' FROM ?:' . $table_data['name'] . ' WHERE `' . $_key . '` = ?s', $new_key);
                        foreach ($table_data['return_clone_data'] as $field) {
                            $return[$field][$data[$id][$field]] = $new_data[$field];
                        }
                    }
                }
                if (!empty($table_data['post_process']) && function_exists($table_data['post_process'])) {
                    call_user_func($table_data['post_process'], $new_key, $table_data, $row, $clone_data, $cloned_ids[$clone_id], $extra);
                }
            }
            if (!empty($table_data['children'])) {
                $__data = !empty($table_data['return_clone_data']) ? reset($return) : $cloned_ids[$clone_id];
                foreach ($table_data['children'] as $child_data) {
                    if (!empty($child_data['data_from'])) {
                        if (Registry::get('clone_data.' . $child_data['data_from']) == 'Y') {
                            $data_from = $schema[$child_data['data_from']];
                            if (!empty($tables['tables'])) {
                                foreach ($tables['tables'] as $_table_data) {
                                    fn_clone_table_data($_table_data, $__data, 0, $from, $to);
                                }
                            } elseif (!empty($data_from['function']) && function_exists($data_from['function'])) {
                                call_user_func($data_from['function'], $table_data, $cloned_ids[$clone_id], $start, $from, $to, $extra);
                            }
                        }
                    } else {
                        fn_clone_table_data($child_data, $__data, 0, $from, $to);
                    }
                }
            }
        }
    }
    if (empty($clone_data)) {
        $total = db_get_field('SELECT COUNT(*) FROM ?:' . $table_data['name'] . ' WHERE company_id = ?i', $from);
        if ($total >= $start + $limit) {
            $start += $limit;
            fn_clone_table_data($table_data, array(), $start, $from, $to);
        }
    }
    return array($return, $cloned_ids[$clone_id]);
}
Example #14
0
            $pp_response["reason_text"] = "CpiResultsCode: " . $_REQUEST['CpiResultsCode'];
        } else {
            $pp_response["order_status"] = "F";
            $pp_response["reason_text"] = $hsbc_errors[$_REQUEST['CpiResultsCode']];
        }
        $order_id = $_REQUEST['OrderId'];
        if (fn_check_payment_script('hsbc.php', $order_id)) {
            fn_finish_payment($order_id, $pp_response, false);
            fn_order_placement_routines('route', $order_id);
        }
        exit;
    }
} else {
    $hashkey = $processor_data['processor_params']['cpihashkey'];
    $post_data = array("CpiDirectResultUrl" => fn_url("payment_notification.notify?payment=hsbc&order_id={$order_id}", AREA, 'https'), "CpiReturnUrl" => fn_url("payment_notification.invoice?payment=hsbc&order_id={$order_id}", AREA, 'https'), "MerchantData" => "ORDER " . $order_id, "Mode" => $processor_data['processor_params']['mode'], "OrderDesc" => "ORDER " . $order_id . ($order_info['repaid'] ? '_' . $order_info['repaid'] : ''), "OrderId" => $order_info['repaid'] ? $order_id . '_' . $order_info['repaid'] : $order_id, "PurchaseAmount" => $order_info['total'] * ($processor_data['processor_params']['currency'] != '392' ? 100 : 1), "PurchaseCurrency" => $processor_data['processor_params']['currency'], "StorefrontId" => $processor_data['processor_params']['store_id'], "TimeStamp" => time() . "000", "TransactionType" => "Capture", "UserId" => $order_info['firstname'] . " " . $order_info['lastname'], "BillingAddress1" => str_replace('\\n', '', $order_info['b_address']), "BillingCity" => $order_info['b_city'], "BillingCountry" => db_get_field("SELECT code_N3 FROM ?:countries WHERE code = ?s", $order_info['b_country']), "BillingCounty" => $order_info['b_state'] ? $order_info['b_state'] : 'n/a', "BillingFirstName" => $order_info['b_firstname'], "BillingLastName" => $order_info['b_lastname'], "BillingPostal" => $order_info['b_zipcode'], "ShopperEmail" => $order_info['email'], "ShippingAddress1" => str_replace('\\n', '', $order_info['s_address']), "ShippingCity" => $order_info['s_city'], "ShippingCountry" => db_get_field("SELECT code_N3 FROM ?:countries WHERE code = ?s", $order_info['s_country']), "ShippingCounty" => $order_info['s_state'] ? $order_info['s_state'] : 'n/a', "ShippingFirstName" => $order_info['s_firstname'], "ShippingLastName" => $order_info['s_lastname'], "ShippingPostal" => $order_info['s_zipcode']);
    $_current_os = fn_strtolower(substr(PHP_OS, 0, 3));
    $post_data_line = escapeshellarg(implode("\" \"", $post_data));
    // Generate Hash
    if ($_current_os == 'win') {
        @exec('PATH ' . Registry::get('config.dir.payments') . 'hsbc_files/lib/' . $_current_os);
        @exec(Registry::get('config.dir.payments') . 'hsbc_files/modules/' . $_current_os . '/TestHash.exe ' . $hashkey . " \"" . $post_data_line . "\"", $data);
    } elseif ($_current_os == 'sun') {
        putenv("LD_LIBRARY_PATH=" . Registry::get('config.dir.payments') . "hsbc_files/lib/{$_current_os}");
        @exec(Registry::get('config.dir.payments') . "hsbc_files/modules/{$_current_os}/TestHash.e " . $hashkey . " \"" . $post_data_line . "\"", $data);
    } elseif ($_current_os == 'lin') {
        putenv("LD_LIBRARY_PATH=" . Registry::get('config.dir.payments') . "hsbc_files/lib/{$_current_os}");
        @exec(Registry::get('config.dir.payments') . "hsbc_files/modules/{$_current_os}/TestHash.e " . $hashkey . " \"" . $post_data_line . "\"", $data);
    }
    if (!preg_match("/^Hash value:  (.*)\$/", @$data[0], $a)) {
        //Set notification
        fn_set_notification('E', __('error'), __('error_hash_generation'));
Example #15
0
function fn_payjunction_response_val($key, $response)
{
    $processor_response = array("avs" => array("AWZ" => "Match Address OR Zip", "XY" => "Match Address AND Zip", "WZ" => "Match Zip", "AW" => "Match Address OR 9 Digit Zip", "AZ" => "Match Address OR 5 Digit Zip", "A" => "Match Address", "X" => "Match Address AND 9 Digit Zip", "Y" => "Match Address AND 5 Digit Zip", "W" => "Match 9 Digit Zip", "Z" => "Match 5 Digit Zip"), "cvv" => array("M" => "CVV On", "I" => "CVV Off"), "preauth" => array("true" => "Pre-auth On", "false" => "Pre-auth Off"), "avsforce" => array("true" => "AVS Force On", "false" => "AVS Force Off"), "cvvforce" => array("true" => "CVV Force On", "false" => "CVV Force Off"));
    $key_ = strtr(fn_strtolower($key), array(" " => "_"));
    return $processor_response[$key_][$response[$key_]] ? $processor_response[$key_][$response[$key_]] : $key . " Code: " . $response[$key_];
}
Example #16
0
 /**
  * Function retuns variants for setting objects
  *
  * Usage (examples):
  *  // Addons
  *  Settings::instance->get_variants('affiliate', 'payment_period');
  *
  *  // Core same as addons but if $section_tab_name is empty it will be setted to 'main'
  *  Settings::instance->get_variants('general', 'feedback_type');
  *
  *  // Return variants only by setting id, but function not check custom variant functions
  *  Settings::instance->get_variants('', '', '', 40);
  *
  *  // Return variants only by setting id, and checks custom variant functions
  *  Settings::instance->get_variants('affiliate', 'payment_period', '', 40);
  *
  * @param  string $section_name     Setting name
  * @param  string $setting_name     Section name
  * @param  string $section_tab_name Section tab name
  * @param  int    $object_id        Id of setting in setting_objects table
  * @param  string $lang_code        2 letters language code
  * @return array  Array of variants or empty array if this setting have no variants
  */
 public function getVariants($section_name, $setting_name, $section_tab_name = '', $object_id = null, $lang_code = CART_LANGUAGE)
 {
     fn_get_schema('settings', 'variants.functions', 'php', true);
     $variants = array();
     // Generate custom variants
     $addon_variant_func = 'fn_settings_variants_addons_' . fn_strtolower($section_name) . '_' . fn_strtolower($setting_name);
     $core_variant_func = 'fn_settings_variants_' . fn_strtolower($section_name) . '_' . ($section_tab_name != 'main' ? fn_strtolower($section_tab_name) . '_' : '') . fn_strtolower($setting_name);
     if (function_exists($addon_variant_func)) {
         $variants = $addon_variant_func();
     } elseif (function_exists($core_variant_func)) {
         $variants = $core_variant_func();
     } else {
         // If object id is 0 try to get it from section name and setting name
         if ($object_id === null || $object_id === 0) {
             $object_id = $this->getId($setting_name, $section_name);
         }
         if ($object_id !== null && $object_id !== 0 || $object_id == 'all') {
             if ($object_id == 'all') {
                 $object_condition = '';
             } else {
                 $object_condition = db_quote('?:settings_variants.object_id = ?i AND', $object_id);
             }
             $_variants = db_get_array("SELECT ?:settings_variants.*, ?:settings_descriptions.value, ?:settings_descriptions.object_type " . "FROM ?:settings_variants " . "INNER JOIN ?:settings_descriptions " . "ON ?:settings_descriptions.object_id = ?:settings_variants.variant_id AND object_type = ?s " . "WHERE ?p ?:settings_descriptions.lang_code = ?s ORDER BY ?:settings_variants.position", Settings::VARIANT_DESCRIPTION, $object_condition, $lang_code);
             fn_update_lang_objects('variants', $_variants);
             foreach ($_variants as $variant) {
                 if ($object_id == 'all') {
                     $variants[$variant['name']] = array('value' => $variant['value']);
                 } else {
                     $variants[$variant['name']] = $variant['value'];
                 }
             }
         } else {
             if (Debugger::isActive() || fn_is_development()) {
                 $message = str_replace("[option_id]", $setting_name, __('setting_has_no_variants'));
                 fn_set_notification('E', __('error'), $message);
             }
             return $variants;
         }
     }
     return $variants;
 }
Example #17
0
function fn_return_bytes($val)
{
    $last = fn_strtolower($val[strlen($val) - 1]);
    switch ($last) {
        case 'g':
            $val *= 1024;
        case 'm':
            $val *= 1024;
        case 'k':
            $val *= 1024;
            break;
    }
    return $val;
}
Example #18
0
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$processor_error = array("A4" => "A link error has occurred between the bank and the modem.", "A5" => "The secure PIN Pad unit is not responding.", "A6" => "No free PIN Pad slots were available to service the transaction request.", "A7" => "A generic interface request specified an illegal value in 'Polled' field.", "A8" => "An invalid amount was specified.", "AA" => "An invalid card number was specified.", "AB" => "An account invalid value for account was specified", "AC" => "A past date was specified for expiry", "AD" => "The specified account is not available on the server.", "AE" => "A queued Authorisation timed-out.", "AF" => "A journal lookup did not find the requested transaction.", "U9" => "A valid response was not received in time from the Bank Host.", "W6" => "The function requested is not supported by the OCV servers bank.");
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_REQUEST['ewayTrxnStatus'])) {
    $order_info = fn_get_order_info($_REQUEST['order_id']);
    if (fn_strtolower($_REQUEST['ewayTrxnStatus']) == 'true' && fn_format_price(str_replace(array('$', ','), '', $_REQUEST['eWAYReturnAmount'])) == fn_format_price($order_info['total'])) {
        $pp_response['order_status'] = 'P';
        $pp_response["reason_text"] = $_REQUEST['eWAYresponseText'];
    } else {
        $pp_response['order_status'] = 'F';
        $pp_response["reason_text"] = $_REQUEST['eWAYresponseText'] . ":" . @$processor_error[$_REQUEST['eWAYresponseCode']];
    }
    if (fn_strtolower($_REQUEST['eWAYoption3']) == 'true') {
        $pp_response["reason_text"] .= "; This is a TEST transaction";
    }
    $pp_response["transaction_id"] = $_REQUEST['ewayTrxnReference'];
    if (fn_check_payment_script('eway_form.php', $_REQUEST['order_id'])) {
        fn_finish_payment($_REQUEST['order_id'], $pp_response, false);
        fn_order_placement_routines('route', $_REQUEST['order_id']);
    }
} else {
    $return_url = fn_url("payment_notification.notify?payment=eway_form&order_id={$order_id}", AREA, 'current');
    $order_total = 100 * $order_info['total'];
    $testmode = $processor_data['processor_params']['test'] == 'Y' ? "TRUE" : "FALSE";
    $_order_id = $processor_data['processor_params']['order_prefix'] . ($order_info['repaid'] ? $order_id . '_' . $order_info['repaid'] : $order_id);
    $post_data = array('ewayCustomerID' => $processor_data['processor_params']['client_id'], 'ewayTotalAmount' => $order_total, 'ewayCustomerInvoiceRef' => $_order_id, 'ewayCustomerFirstName' => $order_info['firstname'], 'ewayCustomerLastName' => $order_info['lastname'], 'ewayCustomerEmail' => $order_info['email'], 'ewayCustomerAddress' => $order_info['b_address'], 'ewayCustomerPostcode' => $order_info['b_zipcode'], 'ewayOption3' => $testmode, 'ewayURL' => $return_url);
    fn_create_payment_form('https://www.eway.com.au/gateway/payment.asp', $post_data, 'eWay');
    exit;
Example #19
0
function fn_anti_fraud_place_order(&$order_id, &$action, &$order_status)
{
    $checked = db_get_field('SELECT COUNT(*) FROM ?:order_data WHERE order_id = ?i AND type = ?s', $order_id, 'F');
    if ($action == 'save' || defined('ORDER_MANAGEMENT') || $checked) {
        return true;
    }
    $return = array();
    $af_settings = Registry::get('addons.anti_fraud');
    if (empty($af_settings['anti_fraud_key'])) {
        return false;
    }
    $order_info = fn_get_order_info($order_id);
    if (empty($order_info['ip_address'])) {
        $return['B'][] = 'af_ip_not_found';
    }
    $risk_factor = 1;
    $request = array('license_key' => $af_settings['anti_fraud_key'], 'i' => $order_info['ip_address'], 'city' => $order_info['b_city'], 'region' => $order_info['b_state'], 'postal' => $order_info['b_zipcode'], 'country' => $order_info['b_country'], 'domain' => substr($order_info['email'], strpos($order_info['email'], '@') + 1), 'emailMD5' => $order_info['email']);
    $_result = Http::get('http://www.maxmind.com/app/ccv2r', $request);
    $result = array();
    $_result = explode(';', $_result);
    if (is_array($_result)) {
        foreach ($_result as $v) {
            $tmp = explode('=', $v);
            $result[$tmp[0]] = $tmp[1];
        }
    }
    unset($_result);
    if (!empty($result['err'])) {
        $return['B'][] = 'af_' . fn_strtolower($result['err']);
        $risk_factor *= AF_ERROR_FACTOR;
    } else {
        // Check if order total greater than defined
        if (!empty($af_settings['anti_fraud_max_order_total']) && floatval($order_info['total']) > floatval($af_settings['anti_fraud_max_order_total'])) {
            $risk_factor *= AF_ORDER_TOTAL_FACTOR;
            $return['B'][] = 'af_big_order_total';
        }
        if (!empty($order_info['user_id'])) {
            // Check if this customer has processed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('P','C') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor /= AF_COMPLETED_ORDERS_FACTOR;
                $return['G'][] = 'af_has_successfull_orders';
            }
            // Check if this customer has failed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('D','F') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor *= AF_FAILED_ORDERS_FACTOR;
                $return['B'][] = 'af_has_failed_orders';
            }
        }
        if ($result['countryMatch'] == 'No') {
            $return['B'][] = 'af_country_doesnt_match';
        }
        if ($result['highRiskCountry'] == 'Yes') {
            $return['B'][] = 'af_high_risk_country';
        }
        if (!empty($af_settings['anti_fraud_safe_distance']) && intval($result['distance']) > intval($af_settings['anti_fraud_safe_distance'])) {
            $return['B'][] = 'af_long_distance';
        }
        if ($result['carderEmail'] == 'Yes') {
            $return['B'][] = 'af_carder_email';
        }
        $risk_factor += floatval($result['riskScore']);
        if ($risk_factor > 100) {
            $risk_factor = 100;
        }
    }
    $return['risk_factor'] = $risk_factor;
    if (floatval($risk_factor) >= floatval($af_settings['anti_fraud_risk_factor'])) {
        $action = 'save';
        $order_status = Registry::get('addons.anti_fraud.antifraud_order_status');
        $return['B'][] = 'af_high_risk_factor';
        $return['I'] = true;
        fn_set_notification('W', __('warning'), __('antifraud_failed_order'));
    } else {
        $return['G'][] = 'af_low_risk_factor';
    }
    $return = serialize($return);
    $data = array('order_id' => $order_id, 'type' => 'F', 'data' => $return);
    db_query("REPLACE INTO ?:order_data ?e", $data);
    return true;
}
Example #20
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     if ($origination['country'] != 'RU') {
         $this->_internalError(__('ems_country_error'));
     }
     $weight = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
     $origination_point = '';
     $destination_point = '';
     if (!isset($shipping_settings['mode']) || $shipping_settings['mode'] == 'regions') {
         $origination_point = $this->_convertState($origination['state']);
         $destination_point = $this->_convertState($location['state']);
     } else {
         $cities = $this->getEmsLocations();
         if (!empty($cities)) {
             foreach ($cities as $i => $loc_data) {
                 if (fn_strtolower($loc_data['name']) == fn_strtolower($origination['city']) || fn_strtolower(str_replace('city--', '', $loc_data['value'])) == fn_strtolower($origination['city'])) {
                     $origination_point = $loc_data['value'];
                 }
                 if (!empty($location['city']) && $location['country'] == 'RU') {
                     if (fn_strtolower($loc_data['name']) == fn_strtolower($location['city']) || fn_strtolower(str_replace('city--', '', $loc_data['value'])) == fn_strtolower($location['city'])) {
                         $destination_point = $loc_data['value'];
                     }
                 }
                 if (!empty($destination_point) && !empty($origination_point)) {
                     break;
                 }
             }
         }
         if (empty($destination_point)) {
             if (empty($location['state'])) {
                 $general = Registry::get('settings.General');
                 $location['state'] = $general['default_state'];
             }
             if ($location['country'] == 'RU') {
                 $destination_point = $this->_convertState($location['state']);
             } else {
                 $countries = $this->getEmsLocations('countries');
                 if (!empty($countries)) {
                     foreach ($countries as $i => $loc_data) {
                         if ($loc_data['value'] == $location['country']) {
                             $destination_point = $location['country'];
                             break;
                         }
                     }
                 }
             }
         }
     }
     $url = 'http://www.emspost.ru/api/rest';
     $data = array();
     if (!empty($destination_point) && !empty($origination_point)) {
         $data = array('method' => 'ems.calculate', 'from' => $origination_point, 'to' => $destination_point, 'weight' => $weight, 'type' => 'att');
     }
     $request_data = array('method' => 'get', 'url' => $url, 'data' => $data);
     return $request_data;
 }
function fn_get_browser_language($languages = array())
{
    if (empty($languages)) {
        return false;
    }
    $browser_language = false;
    if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $preg_string = fn_strtolower(implode('|', array_keys($languages)));
        if (preg_match("/({$preg_string})+(-|;|,)?(.*)?/", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) {
            $browser_language = $matches[1];
        }
    }
    return $browser_language;
}
Example #22
0
/**
 * Fucntion changes company status. Allowed statuses are A(ctive) and D(isabled)
 *
 * @param int $company_id
 * @param string $status_to A or D
 * @param string $reason The reason of the change
 * @param string $status_from Previous status
 * @param boolean $skip_query By default false. Update query might be skipped if status is already changed.
 * @return boolean True on success or false on failure
 */
function fn_change_company_status($company_id, $status_to, $reason = '', &$status_from = '', $skip_query = false, $notify = true)
{
    /**
     * Actions before change company status
     *
     * @param int    $company_id  Company ID
     * @param string $status_to   Status to letter
     * @param string $reason      Reason text
     * @param string $status_from Status from letter
     * @param bool   $skip_query  Skip query flag
     * @param bool   $notify      Notify flag
     */
    fn_set_hook('change_company_status_pre', $company_id, $status_to, $reason, $status_from, $skip_query, $notify);
    if (empty($status_from)) {
        $status_from = db_get_field("SELECT status FROM ?:companies WHERE company_id = ?i", $company_id);
    }
    if (!in_array($status_to, array('A', 'P', 'D')) || $status_from == $status_to) {
        return false;
    }
    $result = $skip_query ? true : db_query("UPDATE ?:companies SET status = ?s WHERE company_id = ?i", $status_to, $company_id);
    if (!$result) {
        return false;
    }
    $company_data = fn_get_company_data($company_id);
    $account = $username = '';
    if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
        if (Registry::get('settings.Vendors.create_vendor_administrator_account') == 'Y') {
            if (!empty($company_data['request_user_id'])) {
                $password_change_timestamp = db_get_field("SELECT password_change_timestamp FROM ?:users WHERE user_id = ?i", $company_data['request_user_id']);
                $_set = '';
                if (empty($password_change_timestamp)) {
                    $_set = ", password_change_timestamp = 1 ";
                }
                db_query("UPDATE ?:users SET company_id = ?i, user_type = 'V'{$_set} WHERE user_id = ?i", $company_id, $company_data['request_user_id']);
                $username = fn_get_user_name($company_data['request_user_id']);
                $account = 'updated';
                $msg = __('new_administrator_account_created') . '<a href="' . fn_url('profiles.update?user_id=' . $company_data['request_user_id']) . '">' . __('you_can_edit_account_details') . '</a>';
                fn_set_notification('N', __('notice'), $msg, 'K');
            } else {
                $_company_data = $company_data + unserialize($company_data['request_account_data']);
                $_company_data['status'] = 'A';
                if (!empty($_company_data['request_account_name'])) {
                    $_company_data['admin_username'] = $_company_data['request_account_name'];
                }
                $user_data = fn_create_company_admin($_company_data, $_company_data['fields'], false);
                if (!empty($user_data['user_id'])) {
                    $username = $user_data['user_login'];
                    $account = 'new';
                }
            }
        }
    }
    if (empty($user_data)) {
        $user_id = db_get_field("SELECT user_id FROM ?:users WHERE company_id = ?i AND is_root = 'Y' AND user_type = 'V'", $company_id);
        $user_data = fn_get_user_info($user_id);
    }
    /**
     * Actions between change company status and send mail
     *
     * @param int    $company_id   Company ID
     * @param string $status_to    Status to letter
     * @param string $reason       Reason text
     * @param string $status_from  Status from letter
     * @param bool   $skip_query   Skip query flag
     * @param bool   $notify       Notify flag
     * @param array  $company_data Company data
     * @param array  $user_data    User data
     * @param bool   $result       Updated flag
     */
    fn_set_hook('change_company_status_before_mail', $company_id, $status_to, $reason, $status_from, $skip_query, $notify, $company_data, $user_data, $result);
    if ($notify && !empty($company_data['email'])) {
        $e_username = '';
        $e_account = '';
        $e_password = '';
        if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
            $e_username = $username;
            $e_account = $account;
            if ($account == 'new') {
                $e_password = $user_data['password1'];
            }
        }
        $mail_template = fn_strtolower($status_from . '_' . $status_to);
        Mailer::sendMail(array('to' => $company_data['email'], 'from' => 'default_company_support_department', 'data' => array('user_data' => $user_data, 'reason' => $reason, 'status' => __($status_to == 'A' ? 'active' : 'disabled'), 'e_username' => $e_username, 'e_account' => $e_account, 'e_password' => $e_password), 'company_id' => $company_id, 'tpl' => 'companies/status_' . $mail_template . '_notification.tpl'), 'A');
    }
    return $result;
}
/**
 * Fucntion changes company status. Allowed statuses are A(ctive) and D(isabled)
 *
 * @param int $company_id
 * @param string $status_to A or D
 * @param string $reason The reason of the change
 * @param string $status_from Previous status
 * @param boolean $skip_query By default false. Update query might be skipped if status is already changed.
 * @return boolean True on success or false on failure
 */
function fn_companies_change_status($company_id, $status_to, $reason = '', &$status_from = '', $skip_query = false, $notify = true)
{
    if (empty($status_from)) {
        $status_from = db_get_field("SELECT status FROM ?:companies WHERE company_id = ?i", $company_id);
    }
    if (!in_array($status_to, array('A', 'P', 'D')) || $status_from == $status_to) {
        return false;
    }
    $result = $skip_query ? true : db_query("UPDATE ?:companies SET status = ?s WHERE company_id = ?i", $status_to, $company_id);
    if (!$result) {
        return false;
    }
    $company_data = fn_get_company_data($company_id);
    $account = $username = '';
    if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
        if (Registry::get('settings.Vendors.create_vendor_administrator_account') == 'Y') {
            if (!empty($company_data['request_user_id'])) {
                $password_change_timestamp = db_get_field("SELECT password_change_timestamp FROM ?:users WHERE user_id = ?i", $company_data['request_user_id']);
                $_set = '';
                if (empty($password_change_timestamp)) {
                    $_set = ", password_change_timestamp = 1 ";
                }
                db_query("UPDATE ?:users SET company_id = ?i, user_type = 'V'{$_set} WHERE user_id = ?i", $company_id, $company_data['request_user_id']);
                $username = fn_get_user_name($company_data['request_user_id']);
                $account = 'updated';
                $msg = __('new_administrator_account_created') . '<a href="' . fn_url('profiles.update?user_id=' . $company_data['request_user_id']) . '">' . __('you_can_edit_account_details') . '</a>';
                fn_set_notification('N', __('notice'), $msg, 'K');
            } else {
                $user_data = array();
                if (!empty($company_data['request_account_name'])) {
                    $user_data['user_login'] = $company_data['request_account_name'];
                } else {
                    $user_data['user_login'] = $company_data['email'];
                }
                $request_account_data = unserialize($company_data['request_account_data']);
                $user_data['fields'] = $request_account_data['fields'];
                $user_data['firstname'] = $user_data['b_firstname'] = $user_data['s_firstname'] = $request_account_data['admin_firstname'];
                $user_data['lastname'] = $user_data['b_lastname'] = $user_data['s_lastname'] = $request_account_data['admin_lastname'];
                $user_data['user_type'] = 'V';
                $user_data['password1'] = fn_generate_password();
                $user_data['password2'] = $user_data['password1'];
                $user_data['status'] = 'A';
                $user_data['company_id'] = $company_id;
                $user_data['email'] = $company_data['email'];
                $user_data['company'] = $company_data['company'];
                $user_data['last_login'] = 0;
                $user_data['lang_code'] = $company_data['lang_code'];
                $user_data['password_change_timestamp'] = 0;
                // Copy vendor admin billing and shipping addresses from the company's credentials
                $user_data['b_address'] = $user_data['s_address'] = $company_data['address'];
                $user_data['b_city'] = $user_data['s_city'] = $company_data['city'];
                $user_data['b_country'] = $user_data['s_country'] = $company_data['country'];
                $user_data['b_state'] = $user_data['s_state'] = $company_data['state'];
                $user_data['b_zipcode'] = $user_data['s_zipcode'] = $company_data['zipcode'];
                list($added_user_id, $null) = fn_update_user(0, $user_data, $null, false, false);
                if ($added_user_id) {
                    $msg = __('new_administrator_account_created') . '<a href="' . fn_url('profiles.update?user_id=' . $added_user_id) . '">' . __('you_can_edit_account_details') . '</a>';
                    fn_set_notification('N', __('notice'), $msg, 'K');
                    $username = $user_data['user_login'];
                    $account = 'new';
                }
            }
        }
    }
    if (empty($user_data)) {
        $user_id = db_get_field("SELECT user_id FROM ?:users WHERE company_id = ?i AND is_root = 'Y' AND user_type = 'V'", $company_id);
        $user_data = fn_get_user_info($user_id);
    }
    if ($notify && !empty($company_data['email'])) {
        $e_username = '';
        $e_account = '';
        $e_password = '';
        if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
            $e_username = $username;
            $e_account = $account;
            if ($account == 'new') {
                $e_password = $user_data['password1'];
            }
        }
        $mail_template = fn_strtolower($status_from . '_' . $status_to);
        Mailer::sendMail(array('to' => $company_data['email'], 'from' => 'default_company_support_department', 'data' => array('user_data' => $user_data, 'reason' => $reason, 'status' => __($status_to == 'A' ? 'active' : 'disabled'), 'e_username' => $e_username, 'e_account' => $e_account, 'e_password' => $e_password), 'company_id' => $company_id, 'tpl' => 'companies/status_' . $mail_template . '_notification.tpl'), 'A');
    }
    return $result;
}
Example #24
0
 /**
  * Gets items from block content
  *
  * @param  string $item_name    Name of current content variable
  * @param  array  $block        Array of block data
  * @param  array  $block_scheme Array of block scheme data generated by Block Schemes Manager
  * @return array  Array of block items
  */
 public function getItems($item_name, $block, $block_scheme)
 {
     $params = $items = $bulk_modifier = array();
     if (!empty($block['content'][$item_name])) {
         $filling_params = $block['content'][$item_name];
     } else {
         $filling_params = array();
     }
     if (isset($block['content'][$item_name]['filling'])) {
         $filling = $block['content'][$item_name]['filling'];
         unset($filling_params['filling']);
     } else {
         $filling = current($block_scheme['content'][$item_name]['fillings']);
     }
     $field_scheme = $block_scheme['content'][$item_name]['fillings'][$filling];
     // Params from scheme
     if (isset($field_scheme['params'])) {
         $params = $field_scheme['params'];
     }
     // Params from content
     $params = array_merge($params, $block['content']);
     // Assign additional template params
     if (isset($block_scheme['templates'][$block['properties']['template']]['params'])) {
         $params = fn_array_merge($params, $block_scheme['templates'][$block['properties']['template']]['params']);
     }
     // Collect data from $_REQUEST
     if (!empty($params['request'])) {
         foreach ($params['request'] as $param => $val) {
             $val = fn_strtolower(str_replace('%', '', $val));
             if (isset($_REQUEST[$val])) {
                 $params[$param] = $_REQUEST[$val];
             }
         }
         unset($params['request']);
     }
     // Collect data from $_SESSION !!! FIXME, merge with $_REQUEST
     if (!empty($params['session'])) {
         foreach ($params['session'] as $param => $val) {
             $val = fn_strtolower(str_replace('%', '', $val));
             if (isset($_SESSION[$val])) {
                 $params[$param] = $_SESSION[$val];
             }
         }
         unset($params['session']);
     }
     // Collect data from $auth !!! FIXME, merge with $_REQUEST
     if (!empty($params['auth'])) {
         foreach ($params['auth'] as $param => $val) {
             $val = fn_strtolower(str_replace('%', '', $val));
             if (isset($_SESSION['auth'][$val])) {
                 $params[$param] = $_SESSION['auth'][$val];
             }
         }
         unset($params['auth']);
     }
     if ($filling == 'manually') {
         // Check items list
         if (empty($params[$item_name]['item_ids'])) {
             if (empty($params['process_empty_items'])) {
                 return array();
             }
         } else {
             $params['item_ids'] = $params[$item_name]['item_ids'];
         }
     }
     $_params = $block['properties'];
     unset($params[$item_name], $_params['content_type'], $_params['template'], $_params['order'], $_params['positions']);
     if (!empty($_params)) {
         $params = fn_array_merge($params, $_params);
     }
     if (!empty($filling_params)) {
         foreach ($filling_params as $param => $value) {
             if (!empty($field_scheme['settings'][$param]) && !empty($field_scheme['settings'][$param]['unset_empty']) && empty($value)) {
                 unset($filling_params[$param]);
             }
         }
         $params = fn_array_merge($params, $filling_params);
     }
     if (isset($block_scheme['content'][$item_name]['items_function'])) {
         $callable = $block_scheme['content'][$item_name]['items_function'];
         $params['block_data'] = $block;
     } else {
         $callable = 'fn_get_' . $block['type'];
     }
     if (is_callable($callable)) {
         @(list($items, ) = call_user_func($callable, $params));
     }
     // If in template issets bulk modifer set it
     if (isset($block_scheme['templates'][$block['properties']['template']]['bulk_modifier'])) {
         $bulk_modifier = $block_scheme['templates'][$block['properties']['template']]['bulk_modifier'];
     }
     // Picker values
     if (!empty($items)) {
         if (!empty($bulk_modifier)) {
             // global modifier
             if (!empty($bulk_modifier)) {
                 foreach ($bulk_modifier as $_func => $_param) {
                     $__params = array();
                     foreach ($_param as $v) {
                         if (is_string($v) && $v == '#this') {
                             $__params[] =& $items;
                         } else {
                             $__params[] = $v;
                         }
                     }
                     call_user_func_array($_func, $__params);
                 }
             }
         }
     }
     return $items;
 }
Example #25
0
/**
 * Checks uploaded file can be processed
 * @param array $uploaded_data uploaded file data
 * @param array $filter_by_ext allowed file extensions
 * @return boolean true if file can be processed, false - otherwise
 */
function fn_check_uploaded_data($uploaded_data, $filter_by_ext)
{
    $result = true;
    $processed = false;
    /**
     * Actions before check uploaded data
     *
     * @param array $uploaded_data Uploaded data
     * @param array $filter_by_ext Allowed file extensions
     * @param bool  $result        Result status
     * @param bool  $processed     Processed flag
     */
    fn_set_hook('check_uploaded_data_pre', $uploaded_data, $filter_by_ext, $result, $processed);
    if ($processed) {
        return $result;
    }
    if (!empty($uploaded_data) && is_array($uploaded_data) && !empty($uploaded_data['name'])) {
        $ext = fn_get_file_ext($uploaded_data['name']);
        if (empty($ext)) {
            $types = fn_get_ext_mime_types('mime');
            $mime = fn_get_mime_content_type($uploaded_data['path']);
            $ext = isset($types[$mime]) ? $types[$mime] : '';
        }
        if (!$processed && !empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) {
            fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext)));
            $result = false;
            $processed = true;
        }
        if (!$processed && in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext)));
            $result = false;
            $processed = true;
        }
        $mime_type = fn_get_mime_content_type($uploaded_data['path'], true, 'text/plain');
        if (!$processed && !empty($uploaded_data['path']) && in_array($mime_type, Registry::get('config.forbidden_mime_types'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => $mime_type)));
            $result = false;
            $processed = true;
        }
    }
    /**
     * Actions after check uploaded data
     *
     * @param array $uploaded_data Uploaded data
     * @param array $filter_by_ext Allowed file extensions
     * @param bool  $result        Result status
     * @param bool  $processed     Processed flag
     */
    fn_set_hook('check_uploaded_data_post', $uploaded_data, $filter_by_ext, $result, $processed);
    return $result;
}
Example #26
0
/**
 * Generate url-safe name for the object
 * Example:
 *  Hello, World! => hello-world
 *  Русский код => russky-kod
 *
 * @param string $str String to be checked and converted
 * @param string $object_type Extra string, object type (e.g.: 'products', 'categories'). Result: some-string-products
 * @param int $object_id Extra string, Object identifier. Result: some-string-products-34
 * @param boolean $is_multi_lang Support multi-language names
 * @return string Url-safe name
 */
function fn_generate_name($str, $object_type = '', $object_id = 0, $is_multi_lang = false)
{
    /**
     * Change parameters for generating file name
     *
     * @param string $str         Basic file name
     * @param string $object_type Object type
     * @param int    $object_id   Object identifier
     */
    fn_set_hook('generate_name_pre', $str, $object_type, $object_id);
    $delimiter = SEO_DELIMITER;
    $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
    // convert html special chars back to original chars
    $result = '';
    if (!empty($str)) {
        if ($is_multi_lang) {
            $literals = "/[^a-z\\p{Ll}\\p{Lu}\\p{Lt}\\p{Lo}\\p{Nd}\\p{Pc}\\p{Mn}0-9-\\.]/u";
            $convert_letters = fn_get_schema('literal_converter', 'general');
        } else {
            $literals = "/[^a-z0-9-\\.]/";
            $convert_letters = fn_get_schema('literal_converter', 'schema');
        }
        $str = strtr($str, $convert_letters);
        if (!empty($object_type)) {
            $str .= $delimiter . $object_type . $object_id;
        }
        $str = fn_strtolower($str);
        // only lower letters
        $str = preg_replace($literals, '', $str);
        // URL can contain latin letters, numbers, dashes and points only
        $str = preg_replace("/({$delimiter}){2,}/", $delimiter, $str);
        // replace double (and more) dashes with one dash
        $result = trim($str, '-');
        // remove trailing dash if exist
    }
    /**
     * Change generated file name
     *
     * @param string $result      Generated file name
     * @param string $str         Basic file name
     * @param string $object_type Object type
     * @param int    $object_id   Object identifier
     */
    fn_set_hook('generate_name_post', $result, $str, $object_type, $object_id);
    return $result;
}
Example #27
0
 /**
  * Gets snapshot file name
  * @param  string $type snapshot type
  * @return string snapshot file name
  */
 private static function getName($type = 'dist')
 {
     $snapshot_filename = Registry::get('config.dir.snapshots') . fn_strtolower(PRODUCT_VERSION . '_' . (PRODUCT_STATUS ? PRODUCT_STATUS . '_' : '') . PRODUCT_EDITION);
     if ($type == 'dist') {
         $snapshot_filename .= '_dist.php';
     } else {
         $snapshot_filename .= '.php';
     }
     return $snapshot_filename;
 }
Example #28
0
function fn_cmcic_hmac_sha1($key, $data)
{
    $key = fn_cmcic_get_usable_key($key);
    $length = 64;
    // block length for SHA1
    if (strlen($key) > $length) {
        $key = pack('H*', sha1($key));
    }
    $key = str_pad($key, $length, chr(0x0));
    $ipad = str_pad('', $length, chr(0x36));
    $opad = str_pad('', $length, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return fn_strtolower(sha1($k_opad . pack('H*', sha1($k_ipad . $data))));
}