/**
 * subscribe/unsubscribe user with selected news
 *
 * @param $customer_id
 * @param $profile
 * @return bool|null
 */
function cw_vertical_response_on_profile_modify($customer_id, $profile)
{
    if (!isset($profile['mailing_list'])) {
        return true;
    }
    if ($customer_id) {
        $userinfo = cw_call('cw_user_get_info', array($customer_id, 1));
    } else {
        return null;
    }
    global $config;
    $vertical_response_data = cw_session_register('vertical_response_data');
    $vertical_response_email = trim($config[vertical_response_addon_name]['vertical_response_email']);
    $vertical_response_password = trim($config[vertical_response_addon_name]['vertical_response_password']);
    try {
        $clear_data = false;
        $delete_list_id = $vertical_response_data['user_lists'];
        foreach ($profile['mailing_list'] as $lid => $v) {
            if (strpos($lid, 'vr_') !== false) {
                $list_id = str_replace('vr_', '', $lid);
                // if select new email list, then add user to list
                if (!in_array($list_id, $vertical_response_data['user_lists'])) {
                    if (empty($sid)) {
                        $vr = new SoapClient(vertical_response_wsdl, array('connection_timeout' => 5));
                        $sid = $vr->login(array('username' => "{$vertical_response_email}", 'password' => "{$vertical_response_password}", 'session_duration_minutes' => vertical_response_ses_time));
                    }
                    // add user to list
                    $vr->addListMember(array('session_id' => $sid, 'list_member' => array('list_id' => $list_id, 'member_data' => array(array('name' => 'email_address', 'value' => $userinfo['email']), array('name' => 'first_name', 'value' => $userinfo['main_address']['firstname']), array('name' => 'last_name', 'value' => $userinfo['main_address']['lastname'])))));
                    $clear_data = true;
                } else {
                    // else list still select and don't need to delete them
                    $delete_list_id = array_diff($delete_list_id, array($list_id));
                }
            }
        }
        if (count($delete_list_id)) {
            foreach ($delete_list_id as $list_id) {
                if (empty($sid)) {
                    $vr = new SoapClient(vertical_response_wsdl, array('connection_timeout' => 5));
                    $sid = $vr->login(array('username' => "{$vertical_response_email}", 'password' => "{$vertical_response_password}", 'session_duration_minutes' => vertical_response_ses_time));
                }
                // delete user from list
                $vr->deleteListMember(array('session_id' => $sid, 'list_member' => array('list_id' => $list_id, 'member_data' => array(array('name' => 'hash', 'value' => $vertical_response_data['hash'])))));
            }
            $clear_data = true;
        }
        if ($clear_data) {
            cw_session_unregister('vertical_response_data');
        }
    } catch (SoapFault $exception) {
        //exit ('fault: "' . $exception->faultcode . '" - ' . $exception->faultstring . "\n");
    }
}
function cw_fbauth_user_logout()
{
    global $action;
    $fb_access_token = cw_session_register('fb_access_token');
    $fb_referer = cw_session_register('fb_referer');
    $referer_url = !empty($fb_referer) ? $fb_referer : 'index.php';
    cw_session_unregister('fb_referer');
    if ($fb_access_token) {
        $graph_url = "https://graph.facebook.com/me/permissions?method=delete&access_token=" . $fb_access_token;
        $result = cw_fbauth_get_ssl_page($graph_url);
        if ($result['error']) {
            $top_message = array('type' => 'E', 'content' => $result['error']);
            cw_header_location($referer_url, TRUE);
        }
        $result = json_decode($result['result']);
        if ($result) {
            cw_session_unregister('fb_access_token');
        }
    }
}
if (intval($cat) == 0) {
    $cat = $product_info['category_id'];
}
$smarty->assign('cat', $cat);
$smarty->assign('menu_arrivals', cw_sections_get_featured('new_arrivals', $cat));
if ($product_info['product_id']) {
    $product_info['meta_descr'] = strip_tags($product_info['descr']);
    $product_info['meta_keywords'] = strip_tags($product_info['product']) . " " . preg_replace("/[^a-zA-Z0-9]/", " ", strip_tags($product_info['descr']));
}
cw_include('include/products/send_to_friend.php');
if (!empty($send_to_friend_info)) {
    $smarty->assign('send_to_friend_info', $send_to_friend_info);
    if ($addons['image_verification']) {
        $smarty->assign('antibot_err', $send_to_friend_info['antibot_err']);
    }
    cw_session_unregister("send_to_friend_info");
}
# kornev, TOFIX
if ($addons['magnifier']) {
    cw_include('addons/magnifier/product.php');
}
// Update view statistic
if (!defined('IS_ROBOT')) {
    cw_call('cw_product_run_counter', array('product_id' => $product_id, 'count' => 1, 'type' => 0));
}
if ($config['General']['disable_outofstock_products'] == "Y" && empty($product_info['distribution'])) {
    $is_avail = cw_func_call('cw_product_check_avail', array('product' => $product_info));
    if (!$is_avail) {
        cw_header_location("index.php?target=error_message&error=access_denied&id=44");
    }
}
function dod_modify_details($generator_id)
{
    global $tables, $available_fields, $optional_fields, $skip_striptags_fields, $date_fields;
    /*if (empty($generator_id)) {
          return array(false, 'generator Id was not provided');
      }*/
    global $generator_data;
    if (empty($generator_data) || !is_array($generator_data)) {
        return array(true, null);
    }
    $error = null;
    $data = array();
    $excl_from_base_list = array('generator_id');
    foreach ($excl_from_base_list as $field) {
        if (isset($available_fields[$field])) {
            unset($available_fields[$field]);
        }
    }
    $additional_lang_data = array();
    foreach ($date_fields as $field) {
        if (isset($generator_data[$field]) && !empty($generator_data[$field])) {
            $generator_data[$field] = cw_core_strtotime($generator_data[$field]);
        }
    }
    foreach ($available_fields as $field => $field_type) {
        if (isset($generator_data[$field])) {
            $result = settype($generator_data[$field], $field_type);
            if ($result === false) {
                $error = 'msg_dod_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if ($field == 'description') {
                if ($generator_data[$field] == '<p>&#160;</p>') {
                    $generator_data[$field] = null;
                }
            }
            if (empty($generator_data[$field])) {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_dod_empty_fields';
                    break;
                }
            } else {
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $generator_data[$field] = cw_strip_tags($generator_data[$field]);
                }
                $data[$field] =& $generator_data[$field];
            }
        } else {
            if ($field_type == 'bool') {
                $data[$field] = 0;
            } else {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_dod_empty_fields';
                    break;
                }
            }
        }
    }
    $sess_generator_data =& cw_session_register('_generator_data');
    $GLOBALS['_generator_data'] =& $generator_data;
    cw_session_register('_generator_data');
    if (!empty($error)) {
        return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
    }
    global $attributes;
    $data['attributes'] = $attributes;
    $error = cw_error_check($data, array(), dod_ATTR_ITEM_TYPE);
    //cw_attributes_check($array_to_check['attribute_class_id'], $array_to_check['attributes'], $attributes_type, $index)
    if (!empty($error)) {
        return array(false, $error);
    }
    global $file_upload_data;
    if (empty($generator_id)) {
        if (empty($data)) {
            return array(false, null);
        }
        $generator_id = cw_array2insert($tables['dod_generators'], cw_addslashes($data));
    } else {
        cw_array2update($tables['dod_generators'], cw_addslashes($data), 'generator_id = \'' . $generator_id . '\'');
    }
    cw_call('cw_attributes_save', array('item_id' => $generator_id, 'item_type' => dod_ATTR_ITEM_TYPE, 'attributes' => $attributes));
    cw_session_unregister('_generator_data');
    return array($generator_id, null);
}
function ppd_add($product_id)
{
    global $tables, $top_message, $smarty, $available_fields;
    global $extra_fields, $optional_fields, $skip_striptags_fields;
    $product_id = (int) $product_id;
    global $new_files;
    if (!isset($new_files)) {
        $new_files = null;
        if (isset($_POST['new_files'])) {
            $new_files =& $_POST['new_files'];
        }
    }
    if (empty($new_files) || !is_array($new_files) || $_SERVER['REQUEST_METHOD'] != 'POST') {
        ppd_redirect($product_id);
    }
    if (isset($available_fields['file_id'])) {
        unset($available_fields['file_id']);
    }
    array_push($optional_fields, 'size');
    array_push($optional_fields, 'type_id');
    $error_description = null;
    $number_files = 0;
    foreach ($new_files as $new_file_key => $new_file) {
        $data = array();
        $error = null;
        $additional_lang_data = array();
        $_additional_lang_data = array('number' => ++$number_files);
        $_real_path = ppd_check_path($new_file['filename']);
        $new_file['size'] = null;
        if (empty($_real_path)) {
            $new_file['filename'] = null;
        }
        if (!empty($new_file['filename'])) {
            $new_file['size'] = ppd_get_filesize($_real_path);
            if (empty($new_file['size'])) {
                $error = 'msg_ppd_file_is_empty';
                $error_description .= cw_get_langvar_by_name('lbl_ppd_skipped_element', $_additional_lang_data) . ' ';
                $error_description .= cw_get_langvar_by_name($error) . '<br />';
                continue;
            }
            $_data = array();
            $_mime_type_by_ext = array();
            $_file_mime_type = ppd_get_mime_type($_real_path);
            $_file_extension = ppd_get_file_extension($_real_path);
            if (!empty($_file_mime_type)) {
                if (!empty($_file_extension)) {
                    $_mime_type_by_ext = cw_query_first('SELECT type_id, type FROM ' . $tables['ppd_types'] . ' WHERE extension = \'' . addslashes($_file_extension) . '\'');
                }
                $new_file['type_id'] = cw_query_first_cell('SELECT type_id FROM ' . $tables['ppd_types'] . ' WHERE type = \'' . addslashes($_file_mime_type) . '\'');
                if (isset($_mime_type_by_ext['type_id']) && $_mime_type_by_ext['type_id'] != $new_file['type_id']) {
                    $new_file['type_id'] = $_mime_type_by_ext['type_id'];
                }
                if (empty($new_file['type_id'])) {
                    $_data['type'] = $_file_mime_type;
                    $_data['extension'] = $_file_extension;
                    $_data['fileicon'] = null;
                    if (!empty($_file_extension)) {
                        $_data['fileicon'] = 'icon_' . $_file_extension . '.gif';
                    }
                    $new_file['type_id'] = cw_array2insert($tables['ppd_types'], $_data);
                }
            }
        }
        foreach ($available_fields as $field => $field_type) {
            if (!isset($new_file[$field])) {
                if (in_array($field, $optional_fields)) {
                    continue;
                } elseif (isset($extra_fields[$field])) {
                    $data[$field] = 0;
                } else {
                    $error = 'msg_ppd_empty_fields';
                    break;
                }
            } else {
                if (isset($extra_fields[$field]) && is_array($extra_fields[$field])) {
                    $_total_value = $_value = null;
                    foreach ($extra_fields[$field] as $extra_field) {
                        $_value = isset($new_file[$field][$extra_field]) ? $new_file[$field][$extra_field] : null;
                        @settype($_value, $field_type);
                        $_total_value += $_value;
                    }
                    $new_file[$field] = $_total_value;
                }
                $result = settype($new_file[$field], $field_type);
                if ($result === false) {
                    $error = 'msg_ppd_incorrect_field_type';
                    $additional_lang_data = array('field_name' => $field);
                    break;
                }
                if (empty($new_file[$field])) {
                    if (in_array($field, $optional_fields)) {
                        continue;
                    } else {
                        $error = 'msg_ppd_empty_fields';
                        break;
                    }
                }
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $new_file[$field] = cw_strip_tags($new_file[$field]);
                }
                $data[$field] =& $new_file[$field];
            }
        }
        if (!empty($error)) {
            $error_description .= cw_get_langvar_by_name('lbl_ppd_skipped_element', $_additional_lang_data) . ' ';
            $error_description .= cw_get_langvar_by_name($error, $additional_lang_data) . '<br />';
        }
        if (empty($error) && !empty($data)) {
            $file_exists = cw_query_first_cell('SELECT file_id FROM ' . $tables['ppd_files'] . ' WHERE filename = \'' . addslashes($data['filename']) . '\' AND product_id = \'' . $product_id . '\'');
            if ($file_exists) {
                $error = 'msg_ppd_file_already_exists';
                $additional_lang_data = array('file' => $data['filename']);
                $error_description .= cw_get_langvar_by_name('lbl_ppd_skipped_element', $_additional_lang_data) . ' ';
                $error_description .= cw_get_langvar_by_name($error, $additional_lang_data) . '<br />';
                continue;
            }
            $data['product_id'] = $product_id;
            cw_array2insert($tables['ppd_files'], $data);
            unset($new_files[$new_file_key]);
        }
    }
    if (!empty($new_files)) {
        $new_files = array_values($new_files);
        $GLOBALS['_new_files'] =& $new_files;
        cw_session_register('_new_files');
    }
    if (!empty($error_description)) {
        $top_message = array('content' => $error_description, 'type' => 'E');
    } else {
        $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_updated_succes'), 'type' => 'I');
        cw_session_unregister('_new_files');
    }
    ppd_redirect($product_id);
}
    $smarty->assign('newslists', $newslists);
    $smarty->assign('subscribed', $subscribed);
}
# TOFIX: move to addon hook
if ($addons['salesman'] && ($action == 'update' && $login_type == 'B' || $current_area == 'B')) {
    $plans = cw_query("SELECT * FROM {$tables['salesman_plans']} WHERE status = 'A' ORDER BY title");
    $smarty->assign('plans', $plans);
}
if ($_GET['parent']) {
    $smarty->assign('parent', $parent);
}
if (!empty($addons['image_verification'])) {
    if ($antibot_err) {
        $antibot_err =& cw_session_register("antibot_err");
        $smarty->assign('reg_antibot_err', $antibot_err);
        cw_session_unregister("antibot_err");
    }
    $smarty->assign('display_antibot', $display_antibot);
}
$smarty->assign('user', $user);
$smarty->assign('profile_fields', $profile_fields);
$smarty->assign('profile_sections', $profile_sections);
$smarty->assign('additional_fields', $additional_fields);
# assign information for the main address
$smarty->assign('countries', cw_map_get_countries());
$smarty->assign('states', cw_map_get_states());
if ($config['General']['use_counties'] == 'Y') {
    $smarty->assign('titles', cw_map_get_counties());
}
$smarty->assign('memberships', cw_get_memberships($userinfo ? $userinfo['usertype'] : $usertype));
$smarty->assign('salesmen', cw_user_get_salesmans_for_register());
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_category_icon_del'), 'type' => 'I');
    cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
}
$smarty->assign('memberships', cw_user_get_memberships(array('C', 'R')));
$current_category = cw_func_call('cw_category_get', array('cat' => $cat, 'from_category' => 0, 'location_target' => '', 'lang' => $edited_language));
if ($mode == 'add') {
    $current_category['category'] = '';
    $current_category['image'] = array();
}
if ($saved_category) {
    if (!is_array($current_category)) {
        $current_category = array();
    }
    $current_category = array_merge($current_category, $saved_category);
    cw_session_unregister('saved_category');
}
if ($mode == 'add' && !$current_category['memberships']) {
    $current_category['membership_ids'] = unserialize($config['category_settings']['default_category_memberships']);
}
if (!empty($ge_id)) {
    $total_items = cw_group_edit_count($ge_id);
    $navigation = cw_core_get_navigation($target, $total_items, $page);
    $navigation['script'] = 'index.php?target=' . $target . '&mode=edit&cat_id=' . $cat_id . $redirect_ge_id;
    $smarty->assign('navigation', $navigation);
    $smarty->assign('categories', cw_query("select {$tables['group_editing']}.obj_id, {$tables['categories']}.category, {$tables['categories']}.category_id from {$tables['categories']}, {$tables['group_editing']} WHERE {$tables['categories']}.category_id = {$tables['group_editing']}.obj_id AND {$tables['group_editing']}.ge_id = '{$ge_id}' LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}"));
    $smarty->assign('ge_id', $ge_id);
}
$location[] = array(cw_get_langvar_by_name('lbl_categories'), 'index.php?target=' . $target);
if ($mode == 'add') {
    $location[] = array(cw_get_langvar_by_name('lbl_add_category'), '');
                if ($data['file_path']) {
                    cw_file_area_save('accounting_records_files', $record_id, $data);
                }
            }
        }
        cw_session_unregister('record_saved_data');
        cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}&record_id={$record_id}");
    }
    if ($action == 'delete_enfile' && $file_id) {
        $record_id = cw_query_first_cell("select customer_id from {$tables['accounting_records_files']} where file_id='{$file_id}'");
        cw_file_area_delete('accounting_records_files', $file_id);
        cw_header_location("index.php?target={$target}&mode={$mode}&user={$user}&record_id={$record_id}");
    }
    if ($record_saved_data) {
        $record = array_merge($record, $record_saved_data);
        cw_session_unregister('record_saved_data');
    }
    $smarty->assign('record', $record);
    $smarty->assign('mode', $mode);
    $smarty->assign('main', 'transaction');
} else {
    cw_session_register('search_data', array());
    $data = array();
    $data['customer_id'] = $user;
    if (isset($fromdate)) {
        $data['start'] = $fromdate;
    }
    if (isset($todate)) {
        $data['end'] = $todate;
    }
    if (isset($saldo)) {
                foreach ($wlitem_data as $k => $v) {
                    if ($k == "amount") {
                        $v = $quantity;
                    }
                    if ($k == "event_id") {
                        $v = $eventid;
                    }
                    if ($k != "wishlist_id") {
                        $fields[] = $k;
                        $values[] = "'" . addslashes($v) . "'";
                    }
                }
                db_query("INSERT INTO {$tables['wishlist']} (" . implode(",", $fields) . ") VALUES (" . implode(",", $values) . ")");
                db_query("UPDATE {$tables['wishlist']} SET amount='{$rest_quantity}' WHERE {$customer_id_cond}");
            }
        }
        if (cw_session_is_registered("mail_data")) {
            cw_session_unregister("mail_data");
        }
    }
    if ($wlitem_data['event_id'] == 0) {
        cw_header_location("index.php?target=cart&mode=wishlist");
    } else {
        cw_header_location("index.php?target=gifts&eventid={$wlitem_data['event_id']}&mode=events");
    }
}
$events_list = cw_call('cw_gift_get_events', array($customer_id));
$smarty->assign('events_list', $events_list);
$smarty->assign('events_lists_count', is_array($events_list) ? count($events_list) : 0);
$location[] = array(cw_get_langvar_by_name('lbl_giftreg_events_list', ''));
$smarty->assign('main', 'events');
function ps_modify_details($offer_id)
{
    global $tables, $available_fields, $optional_fields, $skip_striptags_fields, $date_fields;
    /*if (empty($offer_id)) {
          return array(false, 'Offer Id was not provided');
      }*/
    global $offer_data;
    if (empty($offer_data) || !is_array($offer_data)) {
        return array(true, null);
    }
    $error = null;
    $data = array();
    $excl_from_base_list = array('offer_id');
    foreach ($excl_from_base_list as $field) {
        if (isset($available_fields[$field])) {
            unset($available_fields[$field]);
        }
    }
    $additional_lang_data = array();
    foreach ($date_fields as $field) {
        if (isset($offer_data[$field]) && !empty($offer_data[$field])) {
            $offer_data[$field] = cw_core_strtotime($offer_data[$field]);
        }
    }
    foreach ($available_fields as $field => $field_type) {
        if (isset($offer_data[$field])) {
            $result = settype($offer_data[$field], $field_type);
            if ($result === false) {
                $error = 'msg_ps_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if ($field == 'description') {
                if ($offer_data[$field] == '<p>&#160;</p>') {
                    $offer_data[$field] = null;
                }
            }
            if (empty($offer_data[$field])) {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_ps_empty_fields';
                    break;
                }
            } else {
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $offer_data[$field] = cw_strip_tags($offer_data[$field]);
                }
                $data[$field] =& $offer_data[$field];
            }
        } else {
            if ($field_type == 'bool') {
                $data[$field] = 0;
            } else {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_ps_empty_fields';
                    break;
                }
            }
        }
    }
    $sess_offer_data =& cw_session_register('_offer_data');
    $GLOBALS['_offer_data'] =& $offer_data;
    cw_session_register('_offer_data');
    if (!empty($error)) {
        return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
    }
    global $attributes;
    $data['attributes'] = $attributes;
    $error = cw_error_check($data, array(), PS_ATTR_ITEM_TYPE);
    //cw_attributes_check($array_to_check['attribute_class_id'], $array_to_check['attributes'], $attributes_type, $index)
    if (!empty($error)) {
        return array(false, $error);
    }
    global $file_upload_data;
    if (empty($offer_id)) {
        if (empty($data)) {
            return array(false, null);
        }
        $offer_id = cw_array2insert($tables['ps_offers'], cw_addslashes($data));
        $is_image = false;
        if (!empty($file_upload_data) && isset($file_upload_data[PS_IMG_TYPE]) && is_array($file_upload_data[PS_IMG_TYPE])) {
            $is_image = true;
            if (isset($sess_offer_data['image']) && !empty($sess_offer_data['image'])) {
                $file_upload_data[PS_IMG_TYPE]['is_redirect'] = false;
            }
            $GLOBALS['_offer_data']['image'] = $file_upload_data[PS_IMG_TYPE];
            $file_upload_data[PS_IMG_TYPE]['is_redirect'] = false;
        }
        if (!empty($offer_id)) {
            if ($is_image == true) {
                $image_posted = cw_image_check_posted($file_upload_data[PS_IMG_TYPE]);
                if ($image_posted) {
                    $image_id = cw_image_save($file_upload_data[PS_IMG_TYPE], array('alt' => $data['title'], 'id' => $offer_id));
                }
            }
        }
    } else {
        $image_id = 0;
        if (!empty($file_upload_data) && isset($file_upload_data[PS_IMG_TYPE]) && is_array($file_upload_data[PS_IMG_TYPE])) {
            $image_posted = cw_image_check_posted($file_upload_data[PS_IMG_TYPE]);
            if ($image_posted) {
                $image_id = cw_image_save($file_upload_data[PS_IMG_TYPE], array('alt' => $data['title'], 'id' => $offer_id));
            }
        }
        if (empty($data) && empty($image_id)) {
            $error = 'msg_ps_nothing_to_update';
            return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
        }
        cw_array2update($tables['ps_offers'], cw_addslashes($data), 'offer_id = \'' . $offer_id . '\'');
    }
    cw_call('cw_attributes_save', array('item_id' => $offer_id, 'item_type' => PS_ATTR_ITEM_TYPE, 'attributes' => $attributes));
    cw_session_unregister('_offer_data');
    return array($offer_id, null);
}
function cw_patch_restore_phase_result($remove_files = false)
{
    global $phase_result, $patch_phase_results_file, $patch_files;
    $patch_phase_results_file =& cw_session_register("patch_phase_results_file");
    $phase_result = false;
    if ($patch_phase_results_file !== false) {
        $phase_result = unserialize(file_get_contents($patch_phase_results_file));
        if ($remove_files) {
            @unlink($patch_phase_results_file);
        }
    }
    if ($remove_files) {
        cw_session_unregister("patch_phase_results_file");
    }
}
function cw_payment_check_results($payment_data)
{
    $log_payment_failure = false;
    if (!empty($payment_data['sess_id'])) {
        if (cw_check_webinput() == "err") {
            $log_payment_failure = true;
            if ($payment_data['code'] == 1) {
                $__transaction_status = "successful";
                $payment_data['code'] = 3;
            } elseif ($payment_data['code'] == 3) {
                $__transaction_status = "queued";
            } else {
                $__transaction_status = "declined";
            }
            $payment_data['billmes'] = "Gateway reported of {$__transaction_status} transaction but it's response came from the IP that is not specified in the list of valid IPs: " . cw_get_valid_ip($_SERVER['REMOTE_ADDR']) . "\n-- response ----\n" . $payment_data['billmes'];
        }
        $sessurl = APP_SESSION_NAME . "=" . $payment_data['sess_id'] . "&";
        cw_session_id($payment_data['sess_id']);
    } else {
        $sessurl = '';
    }
    $cart =& cw_session_register('cart', array());
    $secure_oid =& cw_session_register("secure_oid");
    $bill_error = $reason = '';
    $fatal = false;
    if (!empty($payment_data)) {
        $saved_payment_data = $payment_data;
    } else {
        $saved_payment_data = false;
    }
    if (empty($secure_oid)) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $payment_data['billmes'] = "error: your order was lost";
        $reason = $payment_data['billmes'];
        $fatal = true;
    } elseif (empty($cart) && empty($payment_data['skey'])) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $payment_data['billmes'] = "Error: Your cart was lost";
        $reason = $payment_data['billmes'];
        $fatal = true;
    } elseif ($payment_data['code'] == 3) {
        $reason = $payment_data['billmes'];
    } elseif ($payment_data['code'] == 2) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $reason = $payment_data['billmes'];
    } elseif ($payment_data['code'] == 1) {
        if (isset($payment_return) && !empty($payment_return) && $payment_data['code'] != 2) {
            if (isset($payment_return['total'])) {
                $sum = 0;
                foreach ($secure_oid as $_oid) {
                    $o = cw_order_data($_oid);
                    $sum += $o['order']['total'];
                }
                if ($sum != doubleval($payment_return['total'])) {
                    $payment_data['code'] = 2;
                    $payment_data['billmes'] .= "; Payment amount mismatch.";
                }
            }
            if ($payment_data['code'] != 2 && isset($payment_return['currency']) && isset($payment_return['_currency']) && !empty($payment_return['_currency']) && $payment_return['currency'] != $payment_return['_currency']) {
                $payment_data['code'] = 2;
                $payment_data['billmes'] .= "; Payment amount mismatch.";
            }
        }
        if ($payment_data['code'] == 1) {
            $payment_data['billmes'] = "Approved: " . $payment_data['billmes'];
        } else {
            $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
            $reason = $payment_data['billmes'];
            $payment_data['billmes'] = "Declined: " . $payment_data['billmes'];
        }
    } else {
        # unavailable
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_unavailable");
        $payment_data['billmes'] = "Error: Payment gateway is unavailable";
    }
    if (!$fatal) {
        cw_load('doc');
        $status_after_capture = cw_call('cw_payment_doc_status_after_capture', array($payment_data));
        $order_status = $bill_error ? "F" : ($payment_data['code'] == 3 ? "Q" : $status_after_capture);
        if (in_array($order_status, array('P', 'Q', $status_after_capture)) && !empty($payment_data['is_preauth'])) {
            $order_status = 'A';
            // Authorized
        }
        if ($payment_data['code'] == 1 || $payment_data['code'] == 3) {
            if (empty($payment_data['skey'])) {
                $cart = array();
            }
        }
        $advinfo = array();
        $advinfo[] = "Reason: " . $payment_data['billmes'];
        if ($payment_data['avsmes']) {
            $advinfo[] = "AVS info: " . $payment_data['avsmes'];
        }
        if ($payment_data['cvvmes']) {
            $advinfo[] = "CVV info: " . $payment_data['cvvmes'];
        }
        if (isset($cmpi_result)) {
            $advinfo[] = "3-D Secure Transaction:";
            if (isset($cmpi_result['Enrolled'])) {
                $advinfo[] = "  TransactionId: " . $cmpi_result['TransactionId'];
                $advinfo[] = "  Enrolled: " . $cmpi_result['Enrolled'];
            } else {
                $advinfo[] = "  PAResStatus: " . $cmpi_result['PAResStatus'];
                $advinfo[] = "  PAResStatusDesc: " . $cmpi_result['PAResStatusDesc'];
                $advinfo[] = "  CAVV: " . $cmpi_result['Cavv'];
                $advinfo[] = "  SignatureVerification: " . $cmpi_result['SignatureVerification'];
                $advinfo[] = "  Xid: " . $cmpi_result['Xid'];
                $advinfo[] = "  EciFlag: " . $cmpi_result['EciFlag'];
            }
            if (!empty($cmpi_result['ErrorNo'])) {
                $advinfo[] = "  ErrorNo: " . $cmpi_result['ErrorNo'];
            }
            if (!empty($cmpi_result['ErrorDesc'])) {
                $advinfo[] = "  ErrorDesc: " . $cmpi_result['ErrorDesc'];
            }
        }
        cw_call('cw_doc_change_status', array($secure_oid, $order_status, join("\n", $advinfo)));
    }
    if (!empty($payment_data['extra_order_data'])) {
        foreach ($secure_oid as $oid) {
            cw_call('cw_doc_place_extras_data', array($oid, $payment_data['extra_order_data']));
        }
        unset($payment_data['extra_order_data']);
    }
    cw_session_unregister("secure_oid");
    cw_session_save();
    return array('bill_error' => $bill_error, 'sessurl' => $sessurl, 'reason' => $reason, 'doc_ids' => $secure_oid);
}
Esempio n. 13
0
function tabs_add($tab_type = 'product', $product_id = 0)
{
    global $available_tab_fields, $optional_tab_fields, $skip_striptags_tab_fields, $top_message;
    global $_pt_addon_tables;
    $product_id = (int) $product_id;
    if ($tab_type == 'product') {
        if (empty($product_id)) {
            tabs_redirect();
        }
    }
    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        tabs_redirect($product_id);
    }
    $table = $_pt_addon_tables[$tab_type];
    global $new_tab;
    if (!isset($new_tab)) {
        $new_tab = null;
        if (isset($_POST['new_tab'])) {
            $new_tab =& $_POST['new_tab'];
        }
    }
    if (empty($new_tab) || !is_array($new_tab)) {
        tabs_redirect($product_id);
    }
    $error = null;
    $data = array();
    if (isset($available_tab_fields['tab_id'])) {
        unset($available_tab_fields['tab_id']);
    }
    $additional_lang_data = array();
    foreach ($available_tab_fields as $field => $field_type) {
        if (!isset($new_tab[$field])) {
            if (in_array($field, $optional_tab_fields)) {
                continue;
            } else {
                $error = 'msg_pt_empty_fields';
                break;
            }
        } else {
            $result = settype($new_tab[$field], $field_type);
            if ($result === false) {
                $error = 'msg_pt_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if ($field == 'content') {
                if ($new_tab[$field] == '<p>&#160;</p>') {
                    $new_tab[$field] = null;
                }
            }
            if (empty($new_tab[$field])) {
                if (in_array($field, $optional_tab_fields)) {
                    continue;
                } else {
                    $error = 'msg_pt_empty_fields';
                    break;
                }
            }
            if ($field_type == 'string' && !in_array($field, $skip_striptags_tab_fields)) {
                $new_tab[$field] = cw_strip_tags($new_tab[$field]);
            }
            $data[$field] =& $new_tab[$field];
        }
    }
    $GLOBALS['_new_tab'] =& $new_tab;
    cw_session_register('_new_tab');
    $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E');
    if (empty($error) && !empty($data)) {
        if (!empty($product_id) && $tab_type == 'product') {
            $data['product_id'] = $product_id;
        }
        cw_array2insert($table, cw_addslashes($data));
        $top_message = array('content' => cw_get_langvar_by_name('msg_pt_updated_succes'), 'type' => 'I');
        cw_session_unregister('_new_tab');
    }
    tabs_redirect($product_id);
}
function cw_gift_on_login($customer_id, $area, $on_register)
{
    global $tables;
    $customer_wishlist =& cw_session_register('customer_wishlist');
    if (!empty($customer_wishlist) && is_array($customer_wishlist)) {
        foreach ($customer_wishlist as $_cw) {
            $wishlist = cw_query_first("SELECT wishlist_id, amount FROM {$tables['wishlist']}\n                WHERE customer_id='{$customer_id}' AND product_id='{$_cw['product_id']}'\n                    AND options='{$_cw['options']}' AND event_id='0'");
            if (!empty($wishlist)) {
                cw_array2update('wishlist', array('amount' => $wishlist['amount'] + $_cw['amount']), "wishlist_id = '{$wishlist['wishlist_id']}'");
            } else {
                cw_array2insert('wishlist', array('customer_id' => $customer_id, 'product_id' => $_cw['product_id'], 'amount' => $_cw['amount'], 'options' => $_cw['options'], 'object' => $_cw['object']));
            }
        }
        cw_session_unregister('customer_wishlist');
    }
}
if (isset($address_id) && empty($user)) {
    $address = cw_user_get_address(null, $address_id);
    $user = $address['customer_id'];
}
if (empty($address_type)) {
    $address_type = $address_id;
}
if ($action == 'set_same') {
    $temp_current_address =& cw_session_register('temp_current_address', cw_user_get_address_by_type('current'));
    if ($same == 1) {
        $temp_current_address = $user_address['current_address'];
        $user_address['current_address'] = $user_address['main_address'];
    } else {
        $user_address['current_address'] = $temp_current_address;
        $user_address['current_address']['address_id'] = 'current';
        cw_session_unregister('temp_current_address');
    }
    $smarty->assign('is_checkout', 1);
    // cw_add_ajax_block(array('id'=>'debug','action'=>'ignore','content'=>print_r($user_address,true)));
    if (!$same) {
        $action = 'load';
        $address_type = $address_id = 'current';
        $address = $user_address['current_address'];
    } else {
        cw_add_ajax_block(array('id' => 'current_address', 'content' => ''), 'current_address');
    }
}
if ($action == 'save' && !empty($user)) {
    $fill_error = array();
    $update_fields['address'] = cw_user_address_array($update_fields['address']);
    // make sure we processes array of addresses
    $event_data = cw_query_first("select * from {$tables['giftreg_events']} where customer_id='{$customer_id}' AND event_id='{$event_id}'");
    $event_data['allow_to_send'] = cw_query_first_cell("select count(*) from {$tables['giftreg_maillist']} where event_id='{$event_id}' AND status=1");
    $smarty->assign('event_id', $event_id);
    $search_condition = "event_id='{$event_id}'";
    $total_items_in_search = cw_query_first_cell("select count(*) from {$tables['giftreg_guestbooks']} where {$search_condition}");
    $navigation = cw_core_get_navigation($target, $total_items_in_search, $page);
    $navigation['script'] = "index.php?target=gifts&mode=events&event_id={$event_id}&js_tab=guestbook";
    $smarty->assign('navigation', $navigation);
    $guestbook = cw_query("select * from {$tables['giftreg_guestbooks']} where {$search_condition} order by date DESC LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}");
    $smarty->assign('guestbook', $guestbook);
    $mailing_list = cw_query("select * from {$tables['giftreg_maillist']} where event_id='{$event_id}' order by recipient_name, recipient_email");
    $recipients_count = cw_query_first_cell("select count(*) from {$tables['giftreg_maillist']} where event_id='{$event_id}'");
    if ($recipients_count >= $config['estore_gift']['recipients_limit']) {
        $smarty->assign('recipients_limit_reached', 1);
    }
    $smarty->assign('mailing_list', $mailing_list);
    $wl_products = cw_gift_get_giftreg_wishlist($customer_id, $event_id);
    $smarty->assign('wl_products', $wl_products);
    $location[] = array($event_data['title'], '');
} else {
    $location[] = array(cw_get_langvar_by_name('lbl_giftreg_new_event', ''));
}
$event_details_sess =& cw_session_register('event_details_sess');
if ($event_details_sess) {
    $event_data = cw_array_map('stripslashes', $event_details_sess);
    cw_session_unregister('event_details_sess');
}
$smarty->assign('event_data', $event_data);
$smarty->assign('allow_edit', 1);
$smarty->assign('js_tab', $js_tab);
$smarty->assign('main', 'event');
Esempio n. 17
0
}
$cart = cw_func_call('cw_cart_actions', array('action' => $action, 'products' => $products, 'userinfo' => $userinfo), $cart);
if ($action == 'ajax_update') {
    $wcart = cw_func_call('cw_cart_get_warehouses_cart', array('cart' => $cart, 'products' => $products, 'userinfo' => $userinfo));
    $smarty->assign('warehouses_cart', $wcart);
    $smarty->assign('expired', !count($products));
    $smarty->assign('products', $products);
    cw_display('customer/cart/ajax_cart_js.tpl', $smarty);
    exit(0);
}
# kornev, check the requirements before the checkout
if ($mode == 'checkout') {
    if (cw_is_cart_empty($cart)) {
        cw_header_location('index.php?target=' . $target);
    }
    cw_session_unregister('secure_oid');
    if ($cart['info']['display_subtotal'] < $config['General']['minimal_order_amount'] && $config['General']['minimal_order_amount'] > 0) {
        cw_header_location('index.php?target=error_message&error=min_order');
    }
    if ($config['General']['maximum_order_amount'] > 0 && $cart['info']['display_subtotal'] > $config['General']['maximum_order_amount']) {
        cw_header_location("index.php?target=error_message&max_order");
    }
    if ($config['General']['maximum_order_items'] > 0 && cw_cart_count_items($cart) > $config['General']['maximum_order_items']) {
        cw_header_location("index.php?target=error_message&error=max_items");
    }
    $fields_area = cw_profile_fields_get_area($customer_id, $salesman_membership, 1);
    list($profile_sections, $profile_fields, $additional_fields) = cw_profile_fields_get_sections('U', true, $fields_area);
    # kornev, the web information is not required here.
    if ($customer_id) {
        unset($profile_sections['web']);
    }
<?php

if (defined('IS_AJAX') && constant('IS_AJAX') && !defined('AOM')) {
    return true;
}
if (!empty($action) && $action == 'clear_cart') {
    cw_session_unregister('special_offers_apply');
    return true;
}
// PS
cw_load('warehouse', 'cart', 'cart_process');
$special_offers_apply =& cw_session_register("special_offers_apply");
$cart_hash = crc32(serialize(array($cart, $user_account, $user_address)));
if (isset($special_offers_apply['cart_hash']) && $special_offers_apply['cart_hash'] == $cart_hash) {
    return true;
}
$special_offers_apply = array();
$special_offers_apply['free_shipping'] = false;
$special_offers_apply['cart_hash'] = $cart_hash;
// TODO: Do not forget about MDM
$join_statement = $where_statement = '';
$offers = cw_query("SELECT o.offer_id, o.exclusive, o.repeatable, o.pid FROM {$tables['ps_offers']} o {$join_statement} WHERE o.active=1 AND o.startdate<UNIX_TIMESTAMP() and (o.enddate+86400)>UNIX_TIMESTAMP() {$where_statement} ORDER BY priority");
# Delete all free added products
if (is_array($cart['products'])) {
    foreach ($cart['products'] as $kk => $vv) {
        if ($vv["promotion_suite"]["free_product"] == 'Y') {
            cw_call('cw_delete_from_cart', array(&$cart, $vv['cartid']));
        } else {
            unset($cart['products'][$kk]['promotion_suite']);
        }
    }
            }
        }
        cw_header_location("index.php?target={$target}&mode=details&doc_id={$doc_id}");
    } else {
        $js_tab = 'preview';
        $smarty->assign('confirmation', 'Y');
    }
} elseif ($action == "cancel") {
    $smarty->assign('message', 'cancel');
    unset($aom_orders[$doc_id]);
    cw_header_location("index.php?target={$target}&doc_id={$doc_id}&mode=edit");
}
if (cw_session_is_registered("message")) {
    $message =& cw_session_register("message");
    $smarty->assign('message', $message);
    cw_session_unregister("message");
}
$customer_membership_id = $aom_orders[$doc_id]['userinfo']['membership_id'];
if ($action == 'update_customer' && !$aom_orders[$doc_id]['saved'] && in_array(AREA_TYPE, array('P', 'A', 'G', 'B'))) {
    if ($customer_info['customer_id'] != $aom_orders[$doc_id]['userinfo']['customer_id']) {
        cw_aom_update_customer($aom_orders[$doc_id], $customer_info['customer_id']);
    } else {
        if ($customer_info['main_address']['address_id']) {
            $customer_info['main_address'] = cw_user_get_address($customer_info['customer_id'], $customer_info['main_address']['address_id']);
        }
        if ($customer_info['current_address']['address_id']) {
            $customer_info['current_address'] = cw_user_get_address($customer_info['customer_id'], $customer_info['current_address']['address_id']);
        }
        $aom_orders[$doc_id]['userinfo'] = cw_doc_prepare_user_information($customer_info, $aom_orders[$doc_id]['userinfo']);
    }
    cw_header_location("index.php?target={$target}&doc_id={$doc_id}&mode=edit&js_tab=customer");
function cw_ps_offers_set_hash($cart, $products, $user_info)
{
    $ps_offers_info =& cw_session_register('ps_offers_info');
    if (empty($ps_offers_info)) {
        return;
    }
    if (!isset($ps_offers_info['offers_ids']) || empty($ps_offers_info['offers_ids'])) {
        $ps_offers_info = array();
        cw_session_unregister('ps_offers_info');
        return;
    }
    if (isset($ps_offers_info['offers_ids']['new']) && !empty($ps_offers_info['offers_ids']['new'])) {
        $ps_offers_info['offers_ids']['suitable'] += $ps_offers_info['offers_ids']['new'];
        $ps_offers_info['offers_ids']['new'] = array();
    }
    if (isset($ps_offers_info['offers_ids']['to_delete']) && !empty($ps_offers_info['offers_ids']['to_delete'])) {
        $ps_offers_info['offers_ids']['to_delete'] = array();
    }
    if (!isset($ps_offers_info['offers_ids']['suitable']) || empty($ps_offers_info['offers_ids']['suitable'])) {
        $ps_offers_info = array();
        cw_session_unregister('ps_offers_info');
        return;
    }
    //$ps_offers_info['hash'][md5(cw_ps_prods_str($products) . cw_ps_address_str($user_info))] = 2;
}
    $counted = cw_query_first_cell("select * from {$tables['discount_coupons']} where coupon='{$new_discount['coupon']}'");
    if ($new_discount['discount'] > 100 || $new_discount['discount'] <= 0 || empty($new_discount['coupon'])) {
        $counted = 1;
    }
    if ($counted) {
        $top_message = array('content' => cw_get_langvar_by_name('msg_err_discount_coupons_add'), 'type' => 'E');
    } else {
        $new_discount['salesman_customer_id'] = $customer_id;
        $new_discount['coupon_type'] = "percent";
        $new_discount['status'] = 3;
        cw_array2insert('discount_coupons', $new_discount);
        if ($new_discount['from_account']) {
            cw_salesman_change_discount_status($new_discount['coupon'], 1);
        }
    }
    cw_header_location('index.php?target=' . $target);
}
if (empty($new_discount['coupon'])) {
    while (true) {
        $pc = substr(strtoupper(md5(uniqid(rand()))), 0, 9);
        if (!cw_query_first_cell("select count(*) from {$tables['discount_coupons']} where coupon='{$pc}'")) {
            break;
        }
    }
    $new_discount['coupon'] = $pc;
}
$smarty->assign('new_discount', $new_discount);
cw_session_unregister('new_discount_saved');
$smarty->assign('salesman_users', cw_salesman_get_customers($customer_id));
$smarty->assign('discounts', cw_salesman_get_discounts($customer_id));
$smarty->assign('main', 'discounts');
    }
    cw_header_location('index.php?target=' . $target . $redirect_to);
}
if ($mode == "add" || !empty($tax_id)) {
    $location[] = array(cw_get_langvar_by_name('lbl_taxes'), 'index.php?target=' . $target);
    $location[] = array(cw_get_langvar_by_name('lbl_tax_details'), '');
    if (!empty($tax_id)) {
        $tax_details = cw_query_first("SELECT * FROM {$tables['taxes']} WHERE tax_id='{$tax_id}'");
        $tax_details['tax_display_name'] = cw_get_languages_alt('tax_' . $tax_id);
    }
    if (empty($tax_details)) {
        $mode = "add";
        if (cw_session_is_registered("tmp_tax_details")) {
            $tmp_tax_details =& cw_session_register("tmp_tax_details");
            $tax_details = $tmp_tax_details;
            cw_session_unregister("tmp_tax_details");
        }
    } else {
        $tax_rates = cw_query("SELECT {$tables['tax_rates']}.*, {$tables['zones']}.zone_name FROM {$tables['tax_rates']} LEFT JOIN {$tables['zones']} ON {$tables['tax_rates']}.zone_id={$tables['zones']}.zone_id WHERE {$tables['tax_rates']}.tax_id='{$tax_id}' ORDER BY {$tables['zones']}.zone_name, {$tables['tax_rates']}.rate_value");
        $tmp = cw_user_get_memberships(array('C', 'R'));
        if (!empty($tax_rates)) {
            foreach ($tax_rates as $k => $v) {
                $keys = cw_query_column("SELECT membership_id FROM {$tables['tax_rate_memberships']} WHERE rate_id = '{$v['rate_id']}'");
                if (!empty($tmp) && !empty($keys)) {
                    $tax_rates[$k]['membership_ids'] = array();
                    foreach ($tmp as $m) {
                        if (in_array($m['membership_id'], $keys)) {
                            $tax_rates[$k]['membership_ids'][$m['membership_id']] = $m['membership'];
                        }
                    }
                }
    }
    $top_message = array('type' => 'I', 'content' => 'Wishlist item has been updated');
}
if ($action == 'update') {
    if ($quantity > 0) {
        if (empty($customer_id)) {
            cw_gift_update_session_wishlist($wlitem, $eventid, $quantity);
        } else {
            db_query("UPDATE {$tables['wishlist']} SET amount='{$quantity}', event_id='{$eventid}' WHERE wishlist_id='{$wlitem}' and  customer_id='{$customer_id}'");
        }
    }
    $top_message = array('type' => 'I', 'content' => 'Wishlist item has been updated');
}
if ($action == 'wlclear') {
    if (empty($customer_id)) {
        cw_session_unregister('customer_wishlist');
    } else {
        db_query("delete from {$tables['wishlist']} where customer_id='{$customer_id}' AND event_id='{$event_id}'");
    }
    $top_message = array('type' => 'I', 'content' => 'Wishlist has been cleared');
}
if ($action == 'entire_list') {
    $wishlist = cw_gift_get_wishlist($customer_id);
    $smarty->assign('wl_products', $wishlist);
    $smarty->assign('wlid', md5($customer_id));
    $smarty->assign('userinfo', $userinfo);
    cw_call('cw_send_mail', array($user_account['email'], $friend_email, 'mail/wishlist/sendall2friend_subj.tpl', 'mail/wishlist/sendall2friend.tpl', false));
    $top_message = array('type' => 'I', 'content' => cw_get_langvar_by_name('txt_wishlist_sent'));
}
if ($action == 'add2cart') {
    global $product_id, $amount, $action, $result;
function ppd_filetype_add()
{
    global $tables, $top_message, $smarty, $available_fields;
    global $optional_fields, $skip_striptags_fields;
    global $new_types;
    if (!isset($new_types)) {
        $new_types = null;
        if (isset($_POST['new_types'])) {
            $new_types =& $_POST['new_types'];
        }
    }
    if (empty($new_types) || !is_array($new_types) || $_SERVER['REQUEST_METHOD'] != 'POST') {
        ppd_filetype_redirect();
    }
    if (isset($available_fields['type_id'])) {
        unset($available_fields['type_id']);
    }
    $error_description = null;
    $number_types = 0;
    foreach ($new_types as $new_type_key => $new_type) {
        $data = array();
        $error = null;
        $additional_lang_data = array();
        $_additional_lang_data = array('number' => ++$number_types);
        if (isset($new_type['extension']) && !empty($new_type['extension'])) {
            $_file_exists = cw_query_first_cell('SELECT type_id FROM ' . $tables['ppd_types'] . ' WHERE extension = \'' . addslashes($new_type['extension']) . '\'');
            if (!empty($_file_exists)) {
                $error = 'msg_ppd_exts_exists';
                $error_description .= cw_get_langvar_by_name('lbl_ppd_filetype_skipped', $_additional_lang_data) . ' ';
                $error_description .= cw_get_langvar_by_name($error) . '<br />';
                continue;
            }
        }
        foreach ($available_fields as $field => $field_type) {
            if (!isset($new_type[$field])) {
                if (in_array($field, $optional_fields)) {
                    continue;
                } else {
                    $error = 'msg_ppd_empty_fields';
                    break;
                }
            } else {
                $result = settype($new_type[$field], $field_type);
                if ($result === false) {
                    $error = 'msg_ppd_incorrect_field_type';
                    $additional_lang_data = array('field_name' => $field);
                    break;
                }
                if (empty($new_type[$field])) {
                    if (in_array($field, $optional_fields)) {
                        continue;
                    } else {
                        $error = 'msg_ppd_empty_fields';
                        break;
                    }
                }
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $new_type[$field] = cw_strip_tags($new_type[$field]);
                }
                $data[$field] =& $new_type[$field];
            }
        }
        if (!empty($error)) {
            $error_description .= cw_get_langvar_by_name('lbl_ppd_filetype_skipped', $_additional_lang_data) . ' ';
            $error_description .= cw_get_langvar_by_name($error, $additional_lang_data) . '<br />';
        }
        if (empty($error) && !empty($data)) {
            cw_array2insert($tables['ppd_types'], $data);
            unset($new_types[$new_type_key]);
        }
    }
    if (!empty($new_types)) {
        $new_types = array_values($new_types);
        $GLOBALS['_new_types'] =& $new_types;
        cw_session_register('_new_types');
    }
    if (!empty($error_description)) {
        $top_message = array('content' => $error_description, 'type' => 'E');
        ppd_filetype_redirect(array('mode' => 'add'));
    } else {
        $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_filetypes_updated_succes'), 'type' => 'I');
        cw_session_unregister('_new_types');
    }
    ppd_filetype_redirect();
}
<?php

cw_load('category', 'export', 'mail', 'user');
if ($action == 'delete') {
    $users_to_delete =& cw_session_register("users_to_delete");
    if ($confirmed == "Y") {
        if (is_array($users_to_delete['user'])) {
            foreach ($users_to_delete['user'] as $user => $v) {
                cw_func_call('cw_user_delete', array('customer_id' => $user, 'send_mail' => true));
            }
            $top_message = array('content' => cw_get_langvar_by_name('msg_adm_users_del'), 'type' => 'I');
        } else {
            $top_message = array('content' => cw_get_langvar_by_name('msg_adm_warn_users_sel'), 'type' => 'W');
        }
        cw_session_unregister('users_to_delete');
        cw_header_location('index.php?target=' . $target . '&mode=search');
    }
    $users_to_delete['user'] = $user;
    $mode = 'delete';
    cw_header_location("index.php?target={$target}&mode=delete");
}
if ($mode == 'delete') {
    $users_to_delete =& cw_session_register("users_to_delete");
    if (is_array($users_to_delete['user'])) {
        $users = array();
        foreach ($users_to_delete['user'] as $k => $v) {
            $users[] = cw_call('cw_user_get_info', array($k, 1));
        }
        $smarty->assign('users', $users);
        $smarty->assign('current_section_dir', 'users');
        $smarty->assign('main', 'delete_confirmation');
                $add_coupon['apply_product_once'] = 1;
            } elseif ($how_to_apply_c == 2) {
                $add_coupon['apply_product_once'] = 0;
                $add_coupon['apply_category_once'] = 0;
            } else {
                $add_coupon['apply_product_once'] = 1;
                $add_coupon['apply_category_once'] = 0;
            }
            break;
    }
    if (empty($add_coupon['coupon']) || empty($add_coupon['discount']) && $add_coupon['coupon_type'] != 'free_ship' || cw_query_first_cell("select count(*) from {$tables['discount_coupons']} where coupon='{$add_coupon['coupon']}'") > 0) {
        $saved_coupon_data = $add_coupon;
        $top_message = array('content' => cw_get_langvar_by_name('msg_err_discount_coupons_add'), 'type' => 'E');
        cw_header_location("index.php?target={$target}&mode=add");
    } else {
        cw_array2insert('discount_coupons', $add_coupon, 1, array('coupon', 'discount', 'coupon_type', 'minimum', 'times', 'per_user', 'expire', 'status', 'product_id', 'category_id', 'recursive', 'apply_category_once', 'apply_product_once'));
        $top_message['content'] = cw_get_langvar_by_name('msg_discount_coupons_add');
        cw_session_unregister('saved_coupon_data');
    }
    cw_header_location("index.php?target={$target}");
}
if ($mode == 'add') {
    $smarty->assign('main', 'add_new_coupon');
} else {
    $coupons = cw_query("select * from {$tables['discount_coupons']}");
    $smarty->assign('coupons', $coupons);
    $smarty->assign('main', 'coupons');
}
$smarty->assign('coupon_data', $saved_coupon_data);
$smarty->assign('current_main_dir', 'addons');
$smarty->assign('current_section_dir', 'discount_coupons');
        if ($tmp) {
            return true;
        }
    }
    return false;
}
$_location = parse_url($current_location . $app_dirs['customer']);
$_location['path'] = cw_normalize_path($_location['path'], '/');
$current_script = substr(cw_normalize_path($REQUEST_URI, '/'), strlen($_location['path']));
$additional_query = ($QUERY_STRING ? "&" : "?") . (strstr($QUERY_STRING, APP_SESSION_NAME) ? '' : APP_SESSION_NAME . "=" . $APP_SESS_ID);
if (!preg_match("/(?:^|&)sl=/", $additional_query) && $app_http_host != $app_https_host) {
    $additional_query .= ($additional_query ? '&' : '?') . "sl=" . $current_language . "&is_https_redirect=Y";
}
if ($REQUEST_METHOD == "GET" && empty($_GET['keep_https'])) {
    $tmp_location = "";
    if (!$HTTPS && is_https_link($target, $current_script, $https_scripts)) {
        $tmp_location = $app_catalogs_secure['customer'] . $current_script . $additional_query;
    } elseif (!$HTTPS && is_https_link($target, $current_script, $https_messages) && !strncasecmp($HTTP_REFERER, $https_location, strlen($https_location))) {
        $tmp_location = $app_catalogs_secure['customer'] . $current_script . $additional_query;
    } elseif ($config['Security']['dont_leave_https'] != 'Y' && $HTTPS && !is_https_link($target, $current_script, $https_scripts) && !is_https_link($target, $current_script, $https_messages)) {
        $login_redirect =& cw_session_register("login_redirect");
        $do_redirect = empty($login_redirect);
        cw_session_unregister("login_redirect");
        if ($do_redirect) {
            $tmp_location = $http_location . $app_dirs['customer'] . $current_script . $additional_query;
        }
    }
    if (!empty($tmp_location)) {
        cw_header_location($tmp_location);
    }
}
Esempio n. 28
0
            $smarty->assign('message', $message);
            $smarty->assign('messageid', $messageid);
        }
        $messages = cw_query("SELECT * FROM {$tables['newsletter']} WHERE list_id='{$list_id}'");
        $smarty->assign('messages', $messages);
        $smarty->assign('main', 'management');
    } else {
        $smarty->assign('main', 'details');
        $list['usertype'] = 'C';
        $smarty->assign('list', $list);
        // default values of new list
    }
    $smarty->assign('memberships', cw_user_get_memberships(array('C', 'R')));
    $location[] = array($list['name'], '');
} else {
    $lists = cw_query("SELECT * FROM {$tables['newslists']} WHERE lngcode='{$current_language}' {$salesman_condition}");
    $smarty->assign('lists', $lists);
    $smarty->assign('main', 'lists_select');
}
if (cw_session_is_registered('nwslt_object')) {
    $nwslt_object =& cw_session_register('nwslt_object');
    if (is_array($nwslt_object)) {
        foreach ($nwslt_object as $k => $v) {
            $smarty->assign($k, $v);
        }
    }
    cw_session_unregister("nwslt_object");
}
$smarty->assign('action', $action);
$smarty->assign('mode', $mode);
$smarty->assign('js_tab', $js_tab);
Esempio n. 29
0
        }
    }
    $config['card_types'] = $_card_types;
}
$smarty->assign("card_types", $config['card_types']);
if ($config['General']['enable_debug_console'] == "Y" && !defined('IS_AJAX')) {
    $smarty->debugging = true;
}
$smarty->assign('PROXY_IP', $PROXY_IP);
$smarty->assign('CLIENT_IP', $CLIENT_IP);
$smarty->assign('REMOTE_ADDR', $REMOTE_ADDR);
// Detect crawlers and search robots
cw_include('init/robot.php');
$smarty->assign('addons', $addons);
if (!$addons['image_verification']) {
    cw_session_unregister("antibot_validation_val");
}
if (isset($_GET['delimiter']) && $_GET['delimiter'] == "tab" || isset($_POST['delimiter']) && $_POST['delimiter'] == "tab") {
    $delimiter = "\t";
}
$available_images = cw_query_hash("select * from {$tables['available_images']}", 'name', false);
if (is_array($available_images)) {
    foreach ($available_images as $k => $v) {
        $tables[$k] = 'cw_' . $k;
    }
}
// TODO. Move the special sections out from init.php - it requires in customer area only
$special_sections = array('arrivals', 'hot_deals', 'clearance', 'super_deals', 'accessories', 'bottom_line');
$res = null;
foreach ($special_sections as $val) {
    $tables[$val] = 'cw_' . $val;