Esempio n. 1
0
function osc_encrypt_string($plain)
{
    $password = '';
    for ($i = 0; $i < 10; $i++) {
        $password .= osc_rand();
    }
    $salt = substr(md5($password), 0, 2);
    $password = md5($salt . $plain) . ':' . $salt;
    return $password;
}
Esempio n. 2
0
function osc_random_name()
{
    $letters = 'abcdefghijklmnopqrstuvwxyz';
    $dirname = '.';
    $length = floor(osc_rand(16, 20));
    for ($i = 1; $i <= $length; $i++) {
        $q = floor(osc_rand(1, 26));
        $dirname .= $letters[$q];
    }
    return $dirname;
}
 function randomQueryMulti($query)
 {
     $resource = $this->simpleQuery($query);
     $num_rows = $this->numberOfRows($resource);
     if ($num_rows > 0) {
         $random_row = osc_rand(0, $num_rows - 1);
         $this->dataSeek($random_row, $resource);
         return $resource;
     } else {
         return false;
     }
 }
Esempio n. 4
0
/**
 * Create a random string
 *
 * @param int $length The length of the random string to create
 * @param string $type The type of random string to create (mixed, chars, digits)
 * @access public
 */
function create_random_string($length, $type = 'mixed')
{
    if (!in_array($type, array('mixed', 'chars', 'digits'))) {
        return false;
    }
    $chars_pattern = 'abcdefghijklmnopqrstuvwxyz';
    $mixed_pattern = '1234567890' . $chars_pattern;
    $rand_value = '';
    while (strlen($rand_value) < $length) {
        if ($type == 'digits') {
            $rand_value .= osc_rand(0, 9);
        } elseif ($type == 'chars') {
            $rand_value .= substr($chars_pattern, osc_rand(0, 25), 1);
        } else {
            $rand_value .= substr($mixed_pattern, osc_rand(0, 35), 1);
        }
    }
    return $rand_value;
}
 function _get_express_checkout_details($params)
 {
     global $osC_ShoppingCart, $osC_Currencies, $osC_Language, $osC_Database, $osC_Tax, $messageStack, $osC_Customer, $osC_Session;
     // if there is nothing in the customers cart, redirect them to the shopping cart page
     if (!$osC_ShoppingCart->hasContents()) {
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL', true, true, true));
     }
     $params['VERSION'] = $this->api_version;
     $params['METHOD'] = 'GetExpressCheckoutDetails';
     $params['TOKEN'] = $_GET['token'];
     $post_string = '';
     foreach ($params as $key => $value) {
         $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
     }
     $post_string = substr($post_string, 0, -1);
     $response = $this->sendTransactionToGateway($this->api_url, $post_string);
     $response_array = array();
     parse_str($response, $response_array);
     if ($response_array['ACK'] == 'Success' || $response_array['ACK'] == 'SuccessWithWarning') {
         $force_login = false;
         // Begin: check if e-mail address exists in database and login or create customer account
         if ($osC_Customer->isLoggedOn() == false) {
             $force_login = true;
             if (class_exists('osC_Account') == false) {
                 require_once 'includes/classes/account.php';
             }
             $email_address = $response_array['EMAIL'];
             $Qcheck = $osC_Database->query('select * from :table_customers where customers_email_address = :email_address limit 1');
             $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
             $Qcheck->bindValue(':email_address', $email_address);
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() > 0) {
                 $check = $Qcheck->toArray();
                 $customer_id = $check['customers_id'];
                 $osC_Customer->setCustomerData($customer_id);
             } else {
                 $data = array('firstname' => $response_array['FIRSTNAME'], 'lastname' => $response_array['LASTNAME'], 'email_address' => $email_address, 'password' => osc_rand(ACCOUNT_PASSWORD, max(ACCOUNT_PASSWORD, 8)));
                 osC_Account::createEntry($data);
             }
             $Qcheck->freeResult();
             if (SERVICE_SESSION_REGENERATE_ID == '1') {
                 $osC_Session->recreate();
             }
         }
         // End: check if e-mail address exists in database and login or create customer account
         // Begin: Add shipping and billing address from paypal to the shopping cart
         if ($force_login == true) {
             $country_query = $osC_Database->query('select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format from :table_countries where countries_iso_code_2 = :country_iso_code_2');
             $country_query->bindTable(':table_countries', TABLE_COUNTRIES);
             $country_query->bindValue(':country_iso_code_2', $response_array['SHIPTOCOUNTRYCODE']);
             $country_query->execute();
             $country = $country_query->toArray();
             $zone_name = $response_array['SHIPTOSTATE'];
             $zone_id = 0;
             $zone_query = $osC_Database->query('select zone_id, zone_name from :table_zones where zone_country_id = :zone_country_id and zone_code = :zone_code');
             $zone_query->bindTable(':table_zones', TABLE_ZONES);
             $zone_query->bindInt(':zone_country_id', $country['countries_id']);
             $zone_query->bindValue(':zone_code', $response_array['SHIPTOSTATE']);
             $zone_query->execute();
             if ($zone_query->numberOfRows()) {
                 $zone = $zone_query->toArray();
                 $zone_name = $zone['zone_name'];
                 $zone_id = $zone['zone_id'];
             }
             $sendto = array('firstname' => substr($response_array['SHIPTONAME'], 0, strpos($response_array['SHIPTONAME'], ' ')), 'lastname' => substr($response_array['SHIPTONAME'], strpos($response_array['SHIPTONAME'], ' ') + 1), 'company' => '', 'street_address' => $response_array['SHIPTOSTREET'], 'suburb' => '', 'email_address' => $response_array['EMAIL'], 'postcode' => $response_array['SHIPTOZIP'], 'city' => $response_array['SHIPTOCITY'], 'zone_id' => $zone_id, 'zone_name' => $zone_name, 'country_id' => $country['countries_id'], 'country_name' => $country['countries_name'], 'country_iso_code_2' => $country['countries_iso_code_2'], 'country_iso_code_3' => $country['countries_iso_code_3'], 'address_format_id' => $country['address_format_id'] > 0 ? $country['address_format_id'] : '1');
             $osC_ShoppingCart->setRawShippingAddress($sendto);
             $osC_ShoppingCart->setRawBillingAddress($sendto);
             $osC_ShoppingCart->setBillingMethod(array('id' => $this->getCode(), 'title' => $this->getMethodTitle()));
         }
         // End: Add shipping and billing address from paypal to the shopping cart
         //Begin: Add the shipping
         if ($osC_ShoppingCart->getContentType() != 'virtual') {
             if ($osC_ShoppingCart->hasShippingMethod() === false) {
                 if (class_exists('osC_Shipping') === false) {
                     include_once 'includes/classes/shipping.php';
                 }
                 $osC_Shipping = new osC_Shipping();
                 if ($osC_Shipping->hasQuotes()) {
                     $shipping_set = false;
                     // get all available shipping quotes
                     $quotes = $osC_Shipping->getQuotes();
                     if (isset($response_array['SHIPPINGOPTIONNAME']) && isset($response_array['SHIPPINGOPTIONAMOUNT'])) {
                         foreach ($quotes as $quote) {
                             if (!isset($quote['error'])) {
                                 foreach ($quote['methods'] as $rate) {
                                     if ($response_array['SHIPPINGOPTIONNAME'] == $quote['module'] . ' (' . $rate['title'] . ')') {
                                         if ($response_array['SHIPPINGOPTIONAMOUNT'] == $osC_Currencies->formatRaw($rate['cost'] + $quote['cost'] * $quote['tax'] / 100)) {
                                             $shipping = $quote['id'] . '_' . $rate['id'];
                                             $module = 'osC_Shipping_' . $quote['module'];
                                             if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) {
                                                 $quote = $osC_Shipping->getQuote($shipping);
                                                 if (isset($quote['error'])) {
                                                     $osC_ShoppingCart->resetShippingMethod();
                                                     $errors[] = $quote['error'];
                                                 } else {
                                                     $osC_ShoppingCart->setShippingMethod($quote);
                                                     $shipping_set = true;
                                                 }
                                             } else {
                                                 $osC_ShoppingCart->resetShippingMethod();
                                             }
                                             break 2;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($shipping_set == false) {
                         // select cheapest shipping method
                         $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote());
                     }
                 }
             }
         }
         if (!isset($_SESSION['ppe_token'])) {
             $_SESSION['ppe_token'] = $response_array['TOKEN'];
         }
         if (!isset($_SESSION['ppe_payerid'])) {
             $_SESSION['ppe_payerid'] = $response_array['PAYERID'];
         }
         if (!isset($_SESSION['ppe_payerstatus'])) {
             $_SESSION['ppe_payerstatus'] = $response_array['PAYERSTATUS'];
         }
         if (!isset($_SESSION['ppe_addressstatus'])) {
             $_SESSION['ppe_addressstatus'] = $response_array['ADDRESSSTATUS'];
         }
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'process', 'SSL'));
     } else {
         $messageStack->add_session('shopping_cart', $osC_Language->get('payment_paypal_express_error_title') . ' <strong>' . stripslashes($response_array['L_LONGMESSAGE0']) . '</strong>');
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL'));
     }
 }