static function getUserCart() { global $db, $user, $router; $sessAr = expSession::get('verify_shopper'); // initialize this users cart if they have ecomm installed. $active = $db->selectValue('modstate', 'active', 'module="storeController"'); if (!expModules::controllerExists('cart') || empty($active)) { // if ecomm is turned off, no cart. return null; } else { if (isset($router->params['controller']) && $router->params['controller'] == 'order' && ($router->params['action'] == 'verifyReturnShopper' || $router->params['action'] == 'verifyAndRestoreCart' || $router->params['action'] == 'clearCart') && (!isset($sessAr['validated']) || $sessAr['validated'] != true)) { return new order(); } else { // if ecomm is turned off, no cart. //$active = ; if (empty($active)) { return null; } $order = new order(); //initialize a new order object to use the find function from. $ticket = expSession::getTicketString(); //get this users session ticket. this is how we track anonymous users. // grab the origional referrer from the session table so that we can transfer it into the cart where it will be used for reporting purposes // sessions are temporary so we can't report on the referrer in the session table itsef because it may not be there // and we can't just get the referrer ar this point becaues the user likely navigated the site a bit and we want the origional referring site $orig_referrer = $db->selectValue('sessionticket', 'referrer', "`ticket`='" . $ticket . "'"); //see if we have a LIVE and ACTIVE session w/ cart and grab it if so $sessioncart = $order->find('first', "invoice_id='' AND sessionticket_ticket='" . $ticket . "'"); //check to see if the user is logged in, and if so grab their existing cart if (!empty($user) && $user->isLoggedIn()) { $usercart = $order->find('first', "invoice_id='' AND user_id=" . $user->id); } //eDebug($sessioncart); //eDebug($usercart); //enter here if we have NO ACTIVE SESSION CART -OR- We're awaiting a potential cart retore if (empty($sessioncart->id) || $sessAr['awaiting_choice'] == true) { if (empty($usercart->id)) { // no SESSION cart was found and user is not logged in... //let's see if they have a cart_id cookie set and we'll snag that if so //they won't have any user data, since they are "logged in" once they get to //checkout, so all we're really doing here is populating a cart for return //shoppers $cookie_cart_id = isset($_COOKIE['cid']) ? $_COOKIE['cid'] : 0; //eDebug($cookie_cart_id,true); if ($cookie_cart_id) { $tmpCart = new order($cookie_cart_id); if ($tmpCart->id != $cookie_cart_id) { //cookie set, but we gots no cart in the DB so act as if we had no cookie $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer, 'return_count' => $cart->setReturnCount($orig_referrer))); order::setCartCookie($cart); } else { $u = new user($tmpCart->user_id); //1) Was Not logged in if (empty($tmpCart->user_id)) { $cart = new order($cookie_cart_id); //update the session ticket and return count $cart->update(array('sessionticket_ticket' => $ticket, 'return_count' => $cart->setReturnCount($orig_referrer))); order::setCartCookie($cart); flash('message', gt('Welcome back')); } else { if (!empty($tmpCart->user_id)) { //check for is admin first if ($u->isActingAdmin() || $u->isAdmin()) { //no need to restore anything. $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); } else { if (!empty($tmpCart->user_id) && count($tmpCart->orderitem) == 0) { //silently copy tracking data from old order and continue on $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer, 'return_count' => $tmpCart->setReturnCount($orig_referrer))); order::setCartCookie($cart); flash('message', gt('Welcome back')); } else { if (!empty($tmpCart->user_id) && count($tmpCart->orderitem) > 0) { //3) Was Logged in w/ NON-?real user? account //eDebug(expUtil::right($u->username,10),true); if ($u->isTempUser()) { if (isset($sessAr['validated']) && $sessAr['validated']) { //already went through validation and we're good to go $cart = new order($sessAr['cid']); //update the session ticket and return count $cart->update(array('sessionticket_ticket' => $ticket, 'return_count' => $cart->mergeReturnCount($sessioncart->return_count), 'orig_referrer' => $sessioncart->orig_referrer)); order::setCartCookie($cart); expSession::un_set('verify_shopper'); $user = new user($cart->user_id); expSession::login($user); //Update the last login timestamp for this user. $user->updateLastLogin(); flash('message', gt('Welcome back') . ' ' . $sessAr['firstname'] . '! ' . gt('Your shopping cart has been restored - you may continue shopping or') . ' <a href="' . makelink(array("controller" => "cart", "action" => "checkout")) . '">checkout</a> ' . gt('at your convenience.')); } else { //send to verification? If user has elected to restore their cart //eDebug($_SESSION); if (isset($sessAr['awaiting_choice']) && $sessAr['awaiting_choice'] == true) { /*expSession::set('verify_shopper',array('au'=>1,'orig_path'=>$router->current_url, 'firstname'=>$u->firstname, 'cid'=>$cookie_cart_id)); redirect_to(array("controller"=>"order",'action'=>'verifyReturnShopper')); orderController::verifyReturnShopper();*/ //just give em the sessioncart $cart = $sessioncart; if (count($cart->orderitem) > 0) { //added items to current cart, so we'll assume they do not want to restore the previous at this point expSession::un_set('verify_shopper'); order::setCartCookie($cart); } else { flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('We see that you have shopped with us before.') . '<br><br><a id="submit-verify" href="' . makelink(array("controller" => "order", "action" => "verifyReturnShopper")) . '" rel="nofollow">' . gt('Click Here to Restore Your Previous Shopping Cart') . '</a><br><br><a class="exp-ecom-link" href="' . makelink(array("controller" => "order", "action" => "clearCart", "id" => $cookie_cart_id)) . '">' . gt('Click Here To Start a New Shopping Cart') . '</a>'); $sessAr['orig_path'] = $router->current_url; expSession::set('verify_shopper', $sessAr); } } else { //first time...create a default cart, issue message, set session, rinse, repeat $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'return_count' => $cart->setReturnCount($orig_referrer))); expSession::set('verify_shopper', array('au' => 1, 'orig_path' => $router->current_url, 'firstname' => $u->firstname, 'cid' => $cookie_cart_id, 'awaiting_choice' => true)); //order::setCartCookie($cart); flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('We see that you have shopped with us before.') . '<br><br><a id="submit-verify" href="' . makelink(array("controller" => "order", "action" => "verifyReturnShopper")) . '" rel="nofollow">' . gt('Click Here to Restore Your Previous Shopping Cart') . '</a><br><br><a class="exp-ecom-link" href="' . makelink(array("controller" => "order", "action" => "clearCart", "id" => $cookie_cart_id)) . '">' . gt('Click Here To Start a New Shopping Cart') . '</a>'); } } } else { //prompt to login and restore, otherwise reset and start fresh //this should be all we need to do here //redirect_to(array("controller"=>"order",'action'=>'verifyReturnShopper','au'=>'0')); $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('If you would like to pick up where you left off, click here to login and your previous shopping cart will be restored.')); } } } } } } } } else { $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); } } else { //user is logged in, so we grab their usercart and update the session ticket only //$usercart->update(array('sessionticket_ticket'=>$ticket, 'orig_referrer'=>$orig_referrer)); $usercart->update(array('sessionticket_ticket' => $ticket)); $cart = $usercart; } //enter here if we HAVE an ACTIVE session/cart, but the user is not logged in } elseif (!empty($sessioncart->id) && $user->id == 0) { // the user isn't logged in yet...the session cart will do for now. $cart = $sessioncart; // if we hit here we've found a session cart AND a usercart because the user just logged in // and had both...that means we need to merge them } elseif (!empty($sessioncart->id) && !empty($usercart->id)) { // if we hit here we've found a session cart and a usercart...that means we need to merge them // if it's not the same cart. if ($sessioncart->id == $usercart->id) { $cart = $sessioncart; } else { // if the old user cart had gone through any of the checkout process before, than we // will clean that data out now and start fresh. $usercart->cleanOrderitems(); //merge the current session cart with previously saved user cart. foreach ($sessioncart->orderitem as $orderitem) { $orderitem->merge(array('orders_id' => $usercart->id, 'user_id' => $user->id)); } //if session cart HAS coupon codes, delete usercart codes and copy new code to usercart, else leave be if (count($sessioncart->getOrderDiscounts())) { foreach ($usercart->getOrderDiscounts() as $od) { $od->delete(); } foreach ($sessioncart->getOrderDiscounts() as $sod) { $sod->orders_id = $usercart->id; $sod->save(); } } $cart = new order($usercart->id); $sessioncart->delete(); } order::setCartCookie($cart); expSession::un_set('verify_shopper'); // the user doesn't have a cart with his/her user id in it. this probably means they just // logged in so we need to update the cart with the new user id information. } elseif (!empty($sessioncart->id) && (empty($usercart->id) && $user->isLoggedIn())) { //$sessioncart->update(array('user_id'=>$user->id, 'orig_referrer'=>$orig_referrer)); $sessioncart->update(array('user_id' => $user->id)); $cart = $sessioncart; } $cart->item_count = 0; foreach ($cart->orderitem as $items) { if ($items->product->requiresShipping && !$items->product->no_shipping) { $cart->shipping_required = true; } if ($items->product->requiresBilling) { $cart->billing_required = true; } $cart->item_count += $items->quantity; } $cart->lastcat = expSession::get('last_ecomm_category'); $cart->total = $cart->getCartTotal(); //eDebug($cart,true); return $cart; } } }
function showGiftCards() { //Get all giftcards $product_type = 'giftcard'; $giftcard = new $product_type(); $giftcards = $giftcard->find("all", "product_type = 'giftcard'"); //Grab the config $this->grabConfig(); //Set the needed config for the view $config['custom_message_product'] = $this->config['custom_message_product']; $config['minimum_gift_card_purchase'] = $this->config['minimum_gift_card_purchase']; $records = expSession::get('params'); expSession::un_set('params'); assign_to_template(array('giftcards' => $giftcards, 'config' => $config, 'records' => $records)); }
function afterValidationOnCreate() { global $user, $db; //check if user is logged in. If so, then we won't have the password and capture fields //eDebug($_POST,true); if (!$user->isLoggedIn()) { //user is not logged in, so we assume they are creating their first address //we'll check to see if they have elected to 'remember me' and if so, check the username and passwords. //if not, then we just check the captha and create an account manually $password = $_POST['password']; if (isset($_POST['remember_me']) && $_POST['remember_me'] == true) { $user->username = $_POST['email']; $validateUser = $user->setPassword($password, $_POST['password2']); if (!is_bool($validateUser)) { expValidator::failAndReturnToForm($validateUser, $_POST); } } else { $user->username = $_POST['email'] . time(); //make a unique username $password = md5(time() . rand(50, 00)); //generate random password $user->setPassword($password, $password); } //expValidator::check_antispam($_POST, "Your anti-spam verification failed. Please try again."); //if we've come this far, we're good to create the new user account $user->email = $_POST['email']; $user->firstname = $_POST['firstname']; $user->lastname = $_POST['lastname']; //eDebug($_POST); //eDebug($user); $checkUser = $db->selectObject('user', 'username="******"'); if (isset($checkUser->id)) { expValidator::failAndReturnToForm(gt("The email address you entered already exists as a user. If you have lost your password, you may reset it here:") . " <a href='/users/reset_password'>Reset Password</a>.", $_POST); } $user->is_system_user = false; $user->save(true); $user->login($user->username, $password); $this->user_id = $user->id; $this->is_default = true; //eDebug($user,true); //$user-> = $_POST['first_name']; //eDebug($this,true); //set this back since we now have a logged in user and we don't want things going goofy if they logout and log back in and such expSession::un_set("ALLOW_ANONYMOUS_CHECKOUT"); } }
/** * Switches current help version temporarily */ public function switch_version() { global $db; // unset the current version. expSession::un_set('help-version'); // set the requested version. $version = $db->selectValue('help_version', 'version', 'id="' . $this->params['version'] . '"'); expSession::set('help-version', $version); flash('message', gt('Now displaying Help version') . ' ' . $version); expHistory::back(); }
if (empty($from)) { $from = trim(SMTP_FROMADDRESS); } if (empty($from_name)) { $from_name = trim(ORGANIZATION_NAME); } $headers = array("MIME-Version" => "1.0", "Content-type" => "text/html; charset=" . LANG_CHARSET); if (count($emaillist)) { //This is an easy way to remove duplicates $emaillist = array_flip(array_flip($emaillist)); $emaillist = array_map('trim', $emaillist); $mail = new expMail(); $mail->quickSend(array('headers' => $headers, 'html_message' => $emailHtml, "text_message" => $emailText, 'to' => $emaillist, 'from' => array(trim($from) => $from_name), 'subject' => $f->subject)); } } // clear the users post data from the session. expSession::un_set('formmodule_data_' . $f->id); //If is a new post show response, otherwise redirect to the flow. if (!isset($_POST['data_id'])) { $template = new template("formbuilder", "_view_response"); $template->assign("backlink", expHistory::getLastNotEditable()); $template->assign("response_html", $f->response); $template->output(); } else { flash('message', gt('Record was updated!')); // expHistory::back(); expHistory::returnTo('editable'); } } else { echo SITE_403_HTML; }
# # Exponent is free software; you can redistribute # it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../../.." */ if (!defined('EXPONENT')) { exit(''); } $dest_dir = expSession::get('dest_dir'); $files = expSession::get('files_data'); if (!file_exists(BASE . 'files')) { mkdir(BASE . 'files', 0777); } $filecount = 0; foreach (array_keys($files) as $file) { expFile::copyDirectoryStructure($dest_dir . '/files/' . $file, BASE . 'files/' . $file); copy($dest_dir . '/files/' . $file, BASE . 'files/' . $file); $filecount += 1; } expSession::un_set('dest_dir'); expSession::un_set('files_data'); expFile::removeDirectory($dest_dir); $template = new template('importer', '_files_final'); $template->assign('file_count', $filecount); $template->output();
public function clearCart() { global $order; $sessAr = expSession::get('verify_shopper'); if (isset($sessAr)) { order::setCartCookie($order); $orig_path = $sessAr['orig_path']; expSession::un_set('verify_shopper'); redirect_to($orig_path); } else { expHistory::back(); } }
public function toggle_preview() { $level = 99; if (expSession::is_set('uilevel')) { $level = expSession::get('uilevel'); } if ($level == UILEVEL_PREVIEW) { expSession::un_set('uilevel'); } else { //edit mode expSession::set("uilevel", 0); } $message = $level == UILEVEL_PREVIEW ? gt("Exponent is no longer in 'Preview' mode") : gt("Exponent is now in 'Preview' mode"); flash('message', $message); expHistory::back(); }
/** * main login method */ public static function login() { user::login($_POST['username'], $_POST['password']); if (!isset($_SESSION[SYS_SESSION_KEY]['user'])) { flash('error', gt('Invalid Username / Password')); if (expSession::is_set('redirecturl_error')) { $url = expSession::get('redirecturl_error'); expSession::un_set('redirecturl_error'); header("Location: " . $url); } else { expHistory::back(); } } else { global $user; if (!empty($_POST['username'])) { flash('message', gt('Welcome back') . ' ' . $_POST['username']); } foreach ($user->groups as $g) { if (!empty($g->redirect)) { $url = URL_FULL . $g->redirect; break; } } if (isset($url)) { header("Location: " . $url); } else { expHistory::back(); } } }
expVersion::checkVersion(); // Handle sub themes $page = expTheme::getTheme(); // If we are in a printer friendly request then we need to change to our printer friendly subtheme if (PRINTER_FRIENDLY == 1) { expSession::set("uilevel", 0); $pftheme = expTheme::getPrinterFriendlyTheme(); // get the printer friendly theme $page = $pftheme == null ? $page : $pftheme; // if there was no theme found then just use the current subtheme } if (is_readable($page)) { if (!expJavascript::inAjaxAction()) { include_once $page; expTheme::satisfyThemeRequirements(); } else { expTheme::runAction(); } } else { echo sprintf(gt('Page "%s" not readable.'), $page); } if (PRINTER_FRIENDLY == 1) { //$levels = expSession::get('uilevels'); //if (!empty($levels)) expSession::set('uilevel',max(array_keys($levels))); expSession::un_set('uilevel'); } } //$microtime_str = explode(' ',microtime()); //$i_end = $microtime_str[0] + $microtime_str[1]; //echo "\r\n<!--".sprintf(gt('Execution time : %d seconds'),round($i_end - $i_start,4)).'-->'; ob_end_flush();