iChoze -> Zen Cart v1.5 $ Exp $ */ /* $Id: recover_cart_sales.php,v 1.6 2005/06/22 06:10:35 lane Exp $ Recover Cart Sales Tool v2.11 Copyright (c) 2003-2005 JM Ivler / Ideas From the Deep / OSCommerce Released under the GNU General Public License Based on an original release of unsold carts by: JM Ivler That was modifed by Aalst (aalst@aalst.com) until v1.7 of stats_unsold_carts.php Then, the report was turned into a sales tool (recover_cart_sales.php) by JM Ivler based on the scart.php program that was written off the Oct 8 unsold carts code release. Modifed by Aalst (recover_cart_sales.php,v 1.2 ... 1.36) aalst@aalst.com Modifed by willross (recover_cart_sales.php,v 1.4) reply@qwest.net - don't forget to flush the 'scart' db table every so often Modified by Lane Roathe (recover_cart_sales.php,v 1.4d .. v2.11) lane@ifd.com www.osc-modsquad.com / www.ifd.com */ require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . FILENAME_MAIL . '.php'); require(DIR_WS_CLASSES . 'currencies.php'); $currencies = new currencies(); if ($action == 'set_editor') { // Reset will be done by init_html_editor.php. Now we simply redirect to refresh page properly. zen_redirect(zen_href_link(FILENAME_RECOVER_CART_SALES)); } // Delete Entry Begin if ($_GET['action'] == 'delete') { $customer = $db->Execute("SELECT customers_firstname, customers_lastname FROM " . TABLE_CUSTOMERS . " WHERE customers_id ='" . (int)$_GET['customer_id'] . "' LIMIT 1"); $db->Execute("DELETE FROM " . TABLE_CUSTOMERS_BASKET . " WHERE customers_id='" . (int)$_GET['customer_id'] . "'"); $db->Execute("DELETE FROM " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " WHERE customers_id='" . (int)$_GET['customer_id'] . "'"); $messageStack->add(MESSAGE_STACK_CART_CUSTOMER . $customer->fields['customers_firstname'] . ' ' . $customer->fields['customers_lastname'] . ' (ID ' . $_GET['customer_id'] . ')' . MESSAGE_STACK_DELETE_SUCCESS, 'success'); } // Delete Entry End // Set Contacted Begin if ($_GET['action'] == 'setconacted') { $customer = $db->Execute("SELECT customers_firstname, customers_lastname FROM " . TABLE_CUSTOMERS . " WHERE customers_id ='" . (int)$_GET['customer_id'] . "' LIMIT 1"); // See if a record for this customer already exists; if not create one and if so update it $donequery = $db->Execute("SELECT * FROM ". TABLE_SCART ." WHERE customers_id = '" . (int)$_GET['customer_id'] . "'"); if ($donequery->RecordCount() == 0) $db->Execute("INSERT INTO " . TABLE_SCART . " (customers_id, dateadded, datemodified) VALUES ('" . (int)$_GET['customer_id'] . "', '" . date('Ymd') . "', '" . date('Ymd') . "')"); else $db->Execute("UPDATE " . TABLE_SCART . " SET datemodified = '" . date('Ymd') . "' WHERE customers_id = " . (int)$_GET['customer_id']); $messageStack->add(MESSAGE_STACK_CUSTOMER . $customer->fields['customers_firstname'] . ' ' . $customer->fields['customers_lastname'] . ' (ID ' . $_GET['customer_id'] . ')' . MESSAGE_STACK_SETCONACTED, 'success'); } // Set Contacted End $tdate = (isset($_GET['tdate']) ? (int)$_GET['tdate'] : RCS_BASE_DAYS); function zen_cart_date_short($raw_date) { if ($raw_date <= 0) return false; $year = substr($raw_date, 0, 4); $month = (int)substr($raw_date, 4, 2); $day = (int)substr($raw_date, 6, 2); if (@date('Y', mktime(0, 0, 0, $month, $day, $year)) == $year) { return date(DATE_FORMAT, mktime(0, 0, 0, $month, $day, $year)); } else { return preg_replace('/2037$/', $year, date(DATE_FORMAT, mktime(0, 0, 0, $month, $day, 2037))); /*lat9-c*/ } } // This will return a list of active customers function zen_GetCustomerOnline() { global $db; $members = array(); // Set expiration time, default is 1260 secs (20 mins) $xx_mins_ago = (time() - 1260); $whos_online_query = $db->Execute("SELECT customer_id FROM " . TABLE_WHOS_ONLINE . " WHERE time_last_click > '" . $xx_mins_ago . "'"); while (!$whos_online_query->EOF) { if ($whos_online_query->fields['customer_id'] != 0) { $members[] = $whos_online_query->fields['customer_id']; } $whos_online_query->MoveNext(); } return $members; } ?> > <?php echo TITLE; ?>
' . ''; // toggle switch for editor echo '    ' . TEXT_EDITOR_INFO . zen_draw_form('set_editor_form', FILENAME_RECOVER_CART_SALES, '', 'get') . '  ' . zen_draw_pull_down_menu('reset_editor', $editors_pulldown, $current_editor_key, 'onChange="this.form.submit();"') . zen_hide_session_id() . zen_draw_hidden_field('action', 'set_editor') . ''; ?>
Execute("SELECT cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, cus.customers_firstname fname, cus.customers_lastname lname, cus.customers_email_address email FROM " . TABLE_CUSTOMERS_BASKET . " cb, " . TABLE_CUSTOMERS . " cus WHERE cb.customers_id = cus.customers_id AND cus.customers_id ='" . $cid . "' ORDER BY cb.customers_basket_date_added DESC "); while (!$basket->EOF) { // set new cline and curcus if ($lastcid != $cid) { if ($lastcid != "") { $cline .= " \n"; echo $cline; } $cline = ""; $tprice = 0; } $lastcid = $cid; $products = $db->Execute("SELECT p.products_model model, pd.products_name name FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_id = '" . $basket->fields['products_id'] . "' AND pd.products_id = p.products_id AND pd.language_id = " . (int)$_SESSION['languages_id']); $sprice = zen_get_products_actual_price($basket->fields['products_id']); $tprice += $basket->fields['customers_basket_quantity'] * $sprice; $cline .= ""; $mline .= $basket->fields['customers_basket_quantity'] . ' x ' . $products->fields['name'] . "\n"; $mline .= '
' . zen_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id='. $basket->fields['products_id']) . "
\n\n"; $basket->MoveNext(); } $cline .= ""; // E-mail Processing - Requires EMAIL_* defines in the // includes/languages/english/recover_cart_sales.php file $email = ''; if (RCS_EMAIL_FRIENDLY == 'true'){ $email .= EMAIL_TEXT_SALUTATION . $basket->fields['fname'] . ' ' . $basket->fields['lname'] . ","; } else { $email .= STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n"; } $cquery = $db->Execute("SELECT * FROM " . TABLE_ORDERS . " WHERE customers_id = '" . $cid . "'" ); if ($cquery->RecordCount() < 1) { $email .= sprintf(EMAIL_TEXT_NEWCUST_INTRO, $mline); } else { $email .= sprintf(EMAIL_TEXT_CURCUST_INTRO, $mline); } $email .= EMAIL_TEXT_BODY_HEADER . $mline . EMAIL_TEXT_BODY_FOOTER; if( EMAIL_USE_HTML == 'true' ) $email .= '' . STORE_OWNER . "\n" . zen_catalog_href_link(FILENAME_DEFAULT) . ''; else $email .= STORE_OWNER . "\n" . zen_catalog_href_link(FILENAME_DEFAULT); $email .= "\n\n"; $email .= "\n" . EMAIL_SEPARATOR . "\n\n"; $email .= EMAIL_TEXT_LOGIN; if( EMAIL_USE_HTML == 'true' ) $email .= ' ' . zen_catalog_href_link(FILENAME_LOGIN, '', 'SSL') . ''; else $email .= ' (' . zen_catalog_href_link(FILENAME_LOGIN, '', 'SSL') . ')'; $custname = $basket->fields['fname']." ".$basket->fields['lname']; $outEmailAddr = '"' . $custname . '" <' . $basket->fields['email'] . '>'; if( zen_not_null(RCS_EMAIL_COPIES_TO) ) $outEmailAddr .= ', ' . RCS_EMAIL_COPIES_TO; $html_msg['EMAIL_MESSAGE_HTML'] = nl2br($email) . zen_db_prepare_input($_POST['message_html']); $email = strip_tags($email . "\n\n" . zen_db_prepare_input($_POST['message'])); $from = zen_db_prepare_input($_POST['from']); // STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS $subject = zen_db_prepare_input($_POST['subject']); // EMAIL_TEXT_SUBJECT zen_mail('', $outEmailAddr, $subject, $email, '', $from, $html_msg); $mline = ""; // See if a record for this customer already exists; if not create one and if so update it $donequery = $db->Execute("SELECT * FROM ". TABLE_SCART ." WHERE customers_id = '" . $cid . "'"); if ($donequery->RecordCount() == 0) $db->Execute("INSERT INTO " . TABLE_SCART . " (customers_id, dateadded, datemodified) VALUES ('" . $cid . "', '" . date('Ymd') . "', '" . date('Ymd') . "')"); else $db->Execute("UPDATE " . TABLE_SCART . " SET datemodified = '" . date('Ymd') . "' WHERE customers_id = " . $cid ); echo $cline; $cline = ""; } ?>
         
" . TABLE_CART_TOTAL . "" . $currencies->format($tprice) . "
" . zen_image_button('button_delete.gif', IMAGE_DELETE) . "
" . $basket->fields['fname'] . " " . $basket->fields['lname'] . "".$customer."
" . $products->fields['model'] . " fields['products_id'] . '&origin=' . FILENAME_RECOVER_CART_SALES . '?page=' . $_GET['page']) . "'>" . $products->fields['name'] . " " . $basket->fields['customers_basket_quantity'] . " " . $currencies->format($sprice) . " " . $currencies->format($basket->fields['customers_basket_quantity'] * $sprice) . "
' . TABLE_CART_TOTAL . '' . $currencies->format($tprice); ?>
Execute("SELECT cb.customers_id, cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, cus.customers_firstname, cus.customers_lastname, cus.customers_telephone, cus.customers_email_address, sc.datemodified FROM " . TABLE_CUSTOMERS_BASKET . " cb LEFT JOIN " . TABLE_CUSTOMERS . " cus ON (cb.customers_id = cus.customers_id) LEFT JOIN " . TABLE_SCART . " sc ON (cb.customers_id = sc.customers_id) WHERE cb.customers_basket_date_added >= '" . date('Ymd', time()-$tdate*24*60*60) . "' AND cb.customers_id NOT IN ('" . implode(", ", $cust_ses_ids) . "') ORDER BY cb.customers_id ASC, cb.customers_basket_date_added DESC"); $results = 0; $curcus = 0; $tprice = 0; $totalAll = 0; $first_line = true; $skip = false; while (!$basket->EOF) { //echo '
';var_export($basket->fields);echo '
'; // If this is a new customer, create the appropriate HTML if ($curcus != $basket->fields['customers_id']) { $totalAll += $tprice; if ($curcus != 0 && !$skip) { ?> fields['customers_id']; $tprice = 0; // change the color on those we have contacted add customer tag to customers $fcolor = RCS_UNCONTACTED_COLOR; $checked = 1; // assume we'll send an email $new = 1; $skip = false; $sentdate = ""; $beforeDate = RCS_CARTS_MATCH_ALL_DATES ? '0' : $basket->fields['customers_basket_date_added']; $customer = $basket->fields['customers_firstname'] . " " . $basket->fields['customers_lastname']; $status = ""; if ((time()-(RCS_EMAIL_TTL*24*60*60)) <= strtotime($basket->fields['datemodified'])) { $sentdate = $basket->fields['datemodified']; $fcolor = RCS_CONTACTED_COLOR; $checked = 0; $new = 0; } // See if the customer has purchased from us before // Customers are identified by either their customer ID or name or email address // If the customer has an order with items that match the current order, assume // order completed, bail on this entry! $orec = $db->Execute('SELECT orders_id, orders_status FROM ' . TABLE_ORDERS . ' WHERE (customers_id = ' . (int)$curcus . ' OR customers_email_address like "' . $basket->fields['customers_email_address'] .'" OR customers_name like "' . $basket->fields['customers_firstname'] . ' ' . $basket->fields['customers_lastname'] . '") AND date_purchased >= "' . $basket->fields['customers_basket_date_added'] . '"' ); if ($orec->RecordCount() > 0) { // skip repeat customers if (RCS_CHECK_REPEAT == 'true') { $skip = true; } else { // We have a matching order; assume current customer but not for this order $customer = '' . $customer . ''; // Now, look to see if one of the orders matches this current order's items while(!$orec->EOF) { $ccquery = $db->Execute('SELECT products_id FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = ' . (int)$orec->fields['orders_id'] . ' AND products_id = ' . (int)(int)$basket->fields['products_id'] ); if( $ccquery->RecordCount() > 0 ) { if( $orec->fields['orders_status'] > RCS_PENDING_SALE_STATUS ) $checked = 0; // OK, we have a matching order; see if we should just skip this or show the status if( RCS_SKIP_MATCHED_CARTS == 'true' && !$checked ) { $skip = true; // reset flag & break us out of the while loop! break; } else { // It's rare for the same customer to order the same item twice, so we probably have a matching order, show it $fcolor = RCS_MATCHED_ORDER_COLOR; $srec = $db->Execute("SELECT orders_status_name FROM " . TABLE_ORDERS_STATUS . " WHERE language_id = " . (int)$_SESSION['languages_id'] . " AND orders_status_id = " . (int)$orec->fields['orders_status'] ); if( $srec ) $status = ' [' . $srec->fields['orders_status_name'] . ']'; else $status = ' ['. TEXT_CURRENT_CUSTOMER . ']'; } } $orec->MoveNext(); } } if( $skip ) continue; // got a matched cart, skip to next one } ?> fields['customers_basket_quantity'] > 0) { // Get the product information (name, price, etc) $products = $db->Execute("SELECT p.products_model model, p.products_type, pd.products_name name FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (pd.products_id = p.products_id AND pd.language_id = '" . (int)$_SESSION['languages_id'] . "') WHERE p.products_id = '" . (int)$basket->fields['products_id'] . "'"); // Check to see if the product is on special, and if so use that pricing $sprice = zen_get_products_actual_price( (int)$basket->fields['products_id'] ); // BEGIN OF ATTRIBUTE DB CODE $prodAttribs = ''; // DO NOT DELETE if (RCS_SHOW_ATTRIBUTES == 'true') { $attribrecs = $db->Execute("SELECT cba.products_id, po.products_options_name poname, pov.products_options_values_name povname FROM " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " cba, " . TABLE_PRODUCTS_OPTIONS . " po, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_LANGUAGES . " l WHERE cba.products_id ='" . $basket->fields['products_id'] . "' AND cba.customers_id = " . $curcus . " AND po.products_options_id = cba.products_options_id AND pov.products_options_values_id = cba.products_options_value_id AND po.language_id =" . (int)$_SESSION['languages_id'] . " AND pov.language_id =" . (int)$_SESSION['languages_id']); $hasAttributes = false; if ($attribrecs->RecordCount() > 0){ $hasAttributes = true; $prodAttribs = '
'; while (!$attribrecs->EOF){ $prodAttribs .= ' - ' . $attribrecs->fields['poname'] . ' ' . $attribrecs->fields['povname'] . '
'; $attribrecs->MoveNext(); } } } // END OF ATTRIBUTE DB CODE $tprice += $basket->fields['customers_basket_quantity'] * $sprice; $ib++; ?> MoveNext(); } if ($curcus != 0) { $totalAll += $tprice; ?>
' . TABLE_CART_TOTAL . ' ' . $currencies->format($tprice); ?>
 
fields['customers_basket_date_added']); ?> fields['customers_email_address']); ?>" target="_blank">fields['customers_email_address']; ?> fields['customers_telephone']; ?>
fields['model']; ?> " target="_blank">fields['name']; ?> fields['customers_basket_quantity']; ?> format($sprice); ?> format($basket->fields['customers_basket_quantity'] * $sprice); ?>
' . TABLE_CART_TOTAL . '' . $currencies->format($tprice); ?>
 

' . TABLE_GRAND_TOTAL . '' . $currencies->format($totalAll); ?>

'), 'size="60"'); ?>
Value = stripslashes($_POST['message_html']) ; $oFCKeditor->Width = '97%' ; $oFCKeditor->Height = '350' ; // $oFCKeditor->Create() ; $output = $oFCKeditor->CreateHtml() ; echo $output; } else { // using HTMLAREA or just raw "source" echo zen_draw_textarea_field('message_html', 'soft', '100%', '25', stripslashes($_POST['message_html']), 'id="message_html"'); } } ?>