'Interior Layout Design', 'cover_design' => 'Cover Design', 'editing' => 'Editing'); $project_status_array = array('new' => 'New', 'in_progress' => 'In Progress', 'proof_submitted' => 'Proof Sent', 'updates_required' => 'Updates Required', 'completed' => 'Job Completed'); $account_condition_array = array('1' => 'Active', '2' => 'Awaiting Payment', '3' => 'Account on Hold', '4' => 'Account Terminated'); $package_type_array = array('1' => 'Premiere', '2' => 'Platnium', '3' => 'Platnium'); $yes_no_array = array("No", "Yes"); $book_size_array = array('1' => '5in x 8in', '2' => '5¼in x 8in', '3' => '5½in x 8½in', '4' => '5.83in x 8.27in', '5' => '6in x 9in', '6' => '7in x 10in', '7' => '7½in x 9¼in', '8' => '8in x 10in', '9' => '8¼in x 11in', '10' => '8½in x 11in', '11' => '8in x 10in Landscape'); $book_size_pod_array = array('1' => '5 x 8', '2' => '5.25 x 8', '3' => '5.5 x 8.5', '4' => '5.83 x 8.27', '5' => '6 x 9', '6' => '7 x 10', '7' => '7.5 x 9.25', '8' => '8 x 10', '9' => '8.25 x 11', '10' => '8.5 x 11'); $bind_type_array = array('1' => 'Perfect Bind', '2' => 'Case Bind', '3' => 'Saddle Stitch', '4' => 'Coil Bind', '5' => 'Wire Bind'); $paper_color_array = array('1' => 'White', '2' => 'Cream'); $shipping_type_array = array('1' => 'USPS Standard', '2' => 'USPS Priority', '3' => 'UPS Ground', '4' => 'Client Account'); $custom_shipping_type = array('1' => 'UPS Ground', '2' => 'UPS 3 Day', '3' => 'UPS Next Day', '4' => 'Fedex Ground', '5' => 'Fedex 3 Day', '6' => 'Fedex Next Day'); $package_name_array = array('1' => 'Premiere', '2' => 'Platinum', '3' => 'Platinum with Ingram Advantage'); $job_status_array = array('new' => 'New', 'in_progress' => 'In Progress', 'updates_required' => 'Updates Required', 'proof_submitted' => 'Proof Submitted', 'files_in_review' => 'Files in Review', 'files_approved' => 'Files Approved', 'proof_shipped' => 'Proof Shipped', 'proof_approved', 'Proof Approved', 'in_production' => 'In Production', 'completed' => 'Job Completed'); $job_status_printing_array = array('new' => 'New', 'files_in_review' => 'Files in Review', 'files_approved' => 'Files Approved', 'files_not_approved' => 'Files Not Approved', 'proof_shipped' => 'Proof Shipped', 'proof_approved' => 'Proof Approved', 'in_production' => 'In Production', 'completed' => 'Job Completed'); $search_type_array = array('member_name' => 'Members User Name', 'member_id' => 'Members ID', 'service_id' => 'Service / Job Number', 'job_title' => 'Job Title'); $admin_level_array = array('0' => 'Member', '1' => 'Customer Service', '2' => 'Publishing Coordinator', '3' => 'Production Service', '4' => 'Administrator', '5' => 'Manager', '6' => 'Designer', '7' => 'Supervisor'); $distro_upload_required_array = array('0' => "No Upload Required", '1' => "Upload Required", '2' => "Require Kindle Upload", '3' => "Upload Completed", '4' => "Upload Complete - ECKO Has The The Completed Files"); $distro_current_status_array = array('0' => "Member Processing Requried", '1' => "Member Process Completed", '3' => "ECKO's Processing Complete", '4' => "Incomplete / Error With Processing - (Notes)", '5' => "Awaiting Books for Amazon Distirbution", '6' => "Awaiting Books for Amazon Distirbution but Kindle Upload Complete", '7' => "Files Not Approved"); $evoice_find_array = array('order_id' => "Order ID", 'member_id' => 'Member ID'); $search_member_array = array('1' => 'Username', '2' => 'User ID', '3' => 'Members First Name', '4' => 'Members Last Name', '5' => 'Members Email'); $month_legnth_array = array('1' => 'One Month', '2' => 'Two Months', '3' => 'Three Months', '4' => 'Four Months', '5' => 'Five Months', '6' => 'Six Months', '7' => 'Seven Months', '8' => 'Eight Months', '9' => 'Nine Months', '10' => 'Ten Months', '11' => 'Eleven Months', '12' => 'Twelve Months'); $one_to_ten_array = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'); $retailer_list_array = array('1' => "Ingram", '2' => "Baker & Taylor", '3' => "Amazon", '4' => "Borders", '5' => "Barnes & Noble", '6' => "Library", '7' => "Online Retailer", '8' => "Bookstore", '9' => "Other", '10' => "ECKO Books"); $stock_type_array = array('1' => 'Print on Demand', '2' => "Stored Copy", '3' => 'Digital Edition'); // $sale_type_array = array ('1' => "Print on Demand", '2' => "Stored" ); $added_form_array = array('1' => "Printing Order", '2' => "Return From Distributor", '3' => "Mailed-in Stock"); $added_or_subtracted_array = array('1' => "Added", '2' => "Subtracted"); $royaltee_payment_option_array = array('1' => "Mailed Check", '2' => "PayPal Account"); $royaltee_release_value_array = array('15.00' => "$15.00", '25.00' => "$25.00", '40.00' => "$40.00", '55.00' => "$55.00"); $sub_stock_array = array('1' => "Substract From Stock", '2' => "Do Not Subtract"); $add_stock_array = array('1' => "Add To Stock", '2' => "Do Not Add To Stock"); $isbn_type_array = array('0' => "No ISBN Selected", '1' => "Standard ISBN Assignment", '2' => "ISBN Assigned in Your Name"); $yes_no_num_array = array('0' => "No", '1' => "Yes"); $time_array = array("0800" => "8:00am", "0830" => "8:30am", "0900" => "9:00am", "0930" => "9:30am", "1000" => "10:00am", "1030" => "10:30am", "1100" => "11:00am", "1130" => "11:30am", "1200" => "12:00 noon", "1230" => "12:30pm", "1300" => "1:00pm", "1330" => "1:30pm", "1400" => "2:00pm", "1430" => "2:30pm", "1500" => "3:00pm", "1530" => "3:30pm", "1600" => "4:00pm", "1630" => "4:30pm", "1700" => "5:00pm", "1730" => "5:30pm", "1800" => "6:00pm"); $show_durration_array = array('15', '20', '25', '30', '35', '40', '45', '50', '55', '60'); $pod_distro_current_status_array_v2 = array('0' => "Requires Members Attention", '1' => "Requires Attention of Publishing Coordinator", '2' => "Processing Complete - Nothing Left To Do", '6' => "Files Need To Be Reviewed For Approved Specs"); $amazon_distro_current_status_array_v2 = array('1' => "Requires Attention of Publishing Coordinator", '2' => "Processing Complete - Nothing Left To Do", '9' => "Awaiting Books For Distribution"); $digital_distro_current_status_array_v2 = array('0' => "Require Members Attention", '1' => "Requires Attention of Publishing Coordinator", '2' => "Processign Complete - Nothing Left To Do", '6' => "Files Need To Be Reviewed For Approved Specs"); $distro_status_array_all_v2 = array('0' => "Requires Members Attention", '1' => "Requires Attention of Publishing Coordinator", '2' => "Processing Complete - Nothing Left To Do", '3' => "Add To Package", '4' => "Do Not Show Link", '5' => "Self Publisher ISBN data submitted Awaiting ISBN", '6' => "Files Need To Be Reviewed For Approved Specs", '7' => "Radio Interview Scheduled", '8' => "LCCN Assigned but book needs to be sent in", '9' => "Awaiting books for Amazon distribution"); $publicity_page_status_array_v2 = array('0' => "Requires Members Attention", '1' => "Requires Attention of Publishing Coordinator", '2' => "Processing Complete - Nothing Left To Do"); $member_package_status_for_numbers_array = array('1' => 'retail_distribution', '2' => 'digital_distribution', '3' => 'isbn_assignment', '4' => 'isbn_assignment_selfpublishers_data', '5' => 'copyright_registration', '6' => 'lccn_assignment', '7' => 'radio_show', '8' => 'google_books'); $member_package_status_numbers_readable = array('1' => 'Retail Distribution', '2' => 'Digital Distribution', '3' => 'ISBN Assignment', '4' => 'ISBN Assignment', '5' => 'Copyright Registration', '6' => 'LCCN Assignment', '7' => 'Radio Interview', '8' => 'Google Books'); $cc_type_db_readable_array = array('1' => 'Visa', '2' => 'Mastercard', '3' => 'American Express', '4' => 'Discover'); $cc_type_db_array = array('Visa' => '1', 'MasterCard' => '2', 'Amex' => '3', 'Discover' => '4'); // This // is // how // the // merchanr // needs // the // data. $wholesale_rate_form_array = array('75', '70', '65', '60', '55', '50', '45', '40', '35'); $three_char_month_to_number_array = array('jan' => '01', 'feb' => '02', 'mar' => '03', 'apr' => '04', 'may' => '05', 'jun' => '06', 'jul' => '07', 'aug' => '08', 'sep' => '09', 'oct' => '10', 'nov' => '11', 'dec' => '12'); $month_array = array('01' => "January", '02' => "February", '03' => "March", '04' => "April", '05' => "May", '06' => "June", '07' => "July", '08' => "August", '09' => "September", '10' => "October", '11' => "Novemeber", '12' => "December"); // Display Messages function display_message($message_title, $message, $message_icon, $full_url_noslash) { global $add_cart; if ($message_icon) $message_icon_display = "
"; if ($message_title) $message_title = "

$message_title

"; if ($add_cart) $message_shortcut_links = ""; $message_content = "
$message_icon_display
Close Message
$message_title
$message
$message_shortcut_links
"; return $message_content; } // Convert Size in MB/KB function convert_file_size($filesize) { if ($filesize < 500) { $filesize = "$filesize B"; } elseif ($filesize < ((1024 * 1024) / 2)) { $filesize = round($filesize / 1024, 1); $filesize = "$filesize KB"; } else { $filesize = round(($filesize / 1024 / 1024), 2); $filesize = "$filesize MB"; } return $filesize; } // Returns member_username_safe function clean_username($member_username) { $member_username = strtolower($member_username); $member_username_safe = preg_replace("/[^a-zA-Z0-9s]/", "", $member_username); return $member_username_safe; } // Returns a clean filename function clean_filename($filename) { $filename = strtolower($filename); $filename = preg_replace("/[^a-zA-Z0-9s.]/", "", $filename); return $filename; } // Returns an array with the url, Surl and current url function current_url($url_type, $url_id, $url_title, $url_page) { // Manual ID's: 999, 998, 997 /* * Some pages have manual id's. Below is a list of them. Remember to update them when needed. 999 is for the shopping cart 998 is for the checkout system 997 is for the members area 996 is for the Sign in page 995 is for the evoice */ $custom_pages = array('999', '998', '997', '996', '995', '994'); if ($url_id && $url_title && !$url_type) // This is for main content pages // which use two rules or variables $current_page = "$url_id/$url_title/"; else if ($url_type && $url_title) $current_page = "$url_type/$url_title/"; else if (!$url_id && !$url_title && $url_type) // This is to view pages // with one rule or variable $current_page = "$url_type/"; else if ($url_page && $url_type) // This is to view pages with two rules or // variables $current_page = "$url_type/$url_page/"; $current_page_reg = "http://www.eckopublishing.com/$current_page"; $current_page_ssl = "https://www.eckopublishing.com/$current_page"; $page_array = array('url_reg' => "$current_page_reg", 'url_ssl' => "$current_page_ssl", 'url_DEBUG' => "$debug"); return $page_array; } // Generates a random string function random_gen($length) { $characters = "abchefghjkmnpqrstuvwxyz123456789"; $random = ""; for ($p = 0; $p < $length; $p++) { $random .= $characters [mt_rand(0, strlen($characters))]; } return $random; } // Converts the MYSQL Date into a readable format function mysqldate_readable($date) { return date('M jS Y', strtotime($date)); } // Converts the MYSQL Data/Time into a readable format function mysqlDateTime_readable($date) { return date('M. jS Y \a\t g:i a', strtotime($date)); } // Converts bytes into a readable format function byte_size_convert($bytes) { $size = $bytes / 1024; if ($size < 1024) { $size = number_format($size, 2); $size .= ' KB'; } else { if ($size / 1024 < 1024) { $size = number_format($size / 1024, 2); $size .= ' MB'; } else if ($size / 1024 / 1024 < 1024) { $size = number_format($size / 1024 / 1024, 2); $size .= ' GB'; } } return $size; } // Resize Images function resize_images($imagePath, $opts = null) { list ($width, $height) = getimagesize($imagePath); if ($width > $opts ['w'] || $height > $opts ['h']) { // this is the only thing that needs configuring.. $cacheFolder = $_SERVER ['DOCUMENT_ROOT'] . '/cache/'; $quality = 80; // you shouldn't need to configure anything else beyond this point if (file_exists($imagePath) == false) { $imagePath = $_SERVER ['DOCUMENT_ROOT'] . $imagePath; if (file_exists($imagePath) == false) { return 'image not found'; } } if ($opts ['w']) { $w = $opts ['w']; } if ($opts ['h']) { $h = $opts ['h']; } $fileParts = explode('.', $imagePath); $count = count($fileParts) - 1; $ext = $fileParts [$count]; $imgPath = str_replace('.' . $ext, '', $imagePath); $filename = md5_file($imagePath); if ($w and $h) { $newPath = $cacheFolder . $filename . '_w' . $w . '_h' . $h . ($opts ['scale'] == true ? "_scaled" : "") . '.' . $ext; } elseif ($w) { $newPath = $cacheFolder . $filename . '_w' . $w . '.' . $ext; } elseif ($h) { $newPath = $cacheFolder . $filename . '_h' . $h . '.' . $ext; } else { return false; } $create = true; if (file_exists($newPath) == true && $opts ['use_cache'] != 'no') { $create = false; $origFileTime = date("YmdHis", filemtime($imagePath)); $newFileTime = date("YmdHis", filemtime($newPath)); if ($newFileTime < $origFileTime) { $create = true; } } if ($create == true) { if ($w and $h) { $resize = $w; if ($width > $height) { $resize = $w; if ($opts ['crop'] == true) { $resize = "x" . $h; } } else { $resize = "x" . $h; if ($opts ['crop'] == true) { $resize = $w; } } if ($opts ['scale'] == true) { exec("convert " . $imagePath . " -resize " . $resize . " -quality " . $quality . " " . $newPath); } else { exec("convert " . $imagePath . " -resize " . $resize . " -size " . $w . "x" . $h . " xc:" . ($opts ['canvas-color'] ? $opts ['canvas-color'] : "transparent") . " +swap -gravity center -composite -quality " . $quality . " " . $newPath); } } } elseif ($w) { // exec ( "convert " . $imagePath . " -thumbnail " . $w . "" . // ($opts ['maxOnly'] == true ? "\>" : "") . " -quality " . $quality // . " " . $newPath ); exec("convert " . $imagePath . " -thumbnail " . $w . "" . ($opts ['maxOnly'] == true ? "/>" : "") . " -quality " . $quality . " " . $newPath); } elseif ($h) { // exec ( "convert " . $imagePath . " -thumbnail x" . $h . "" . // ($opts ['maxOnly'] == true ? "\>" : "") . " -quality " . $quality // . " " . $newPath ); exec("convert " . $imagePath . " -thumbnail x" . $h . "" . ($opts ['maxOnly'] == true ? "/>" : "") . " -quality " . $quality . " " . $newPath); } return str_replace($_SERVER ['DOCUMENT_ROOT'], '', $newPath); // How To Call /* * resize_images('/item_images/$item_photo_1.jpg',array('w'=>500)) resize_images('/item_images/$item_photo_1.jpg',array('w'=>200,'h'=>200)) resize_images('/item_images/$item_photo_1.jpg',array('h'=>200)) resize_images('/item_images/$item_photo_1.jpg',array('w'=>200,'h'=>200,'scale'=>true)) */ } else { return $opts ['source_url']; } } // Verifies the Credit card number function CCVal($ccn, $cc_type = "n/a") { /** * ********************************************************************** * mcd - Master Card * vis - Visa * amx - American Express * dsc - Discover * dnc - Diners Club * jcb - JCB * swi - Switch * dlt - Delta * enr - EnRoute * * You can also optionally specify an expiration date in the formay mmyy. * If the validation fails on the date, the function returns 0. If it * fails on the number validation, it returns false. * * A description of the criteria used in this function can be found at * http://www.paylib.net/ccval.html. If you have any questions or * comments, please direct them to ccval@holotech.net * ********************************************************************** */ // Innocent until proven guilty $GoodCard = true; // Get rid of any non-digits $ccn = ereg_replace("[^0-9]", "", $ccn); // Perform card-specific checks, if applicable switch ($cc_type) { case "MasterCard" : $GoodCard = ereg("^5[1-5].{14}$", $ccn); break; case "Visa" : $GoodCard = ereg("^4.{15}$|^4.{12}$", $ccn); break; case "Amex" : $GoodCard = ereg("^3[47].{13}$", $ccn); break; case "Discover" : $GoodCard = ereg("^6011.{12}$", $ccn); break; } // The Luhn formula works right to left, so reverse the number. $ccn = strrev($ccn); $Total = 0; for ($x = 0; $x < strlen($ccn); $x++) { $digit = substr($ccn, $x, 1); // If it's an odd digit, double it if ($x / 2 != floor($x / 2)) { $digit *= 2; // If the result is two digits, add them if (strlen($digit) == 2) $digit = substr($digit, 0, 1) + substr($digit, 1, 1); } // Add the current digit, doubled and added if applicable, to the Total $Total += $digit; } // If it passed (or bypassed) the card-specific check and the Total is // evenly divisible by 10, it's cool! if ($GoodCard && $Total % 10 == 0) return "true"; else return "false"; } function validateCreditCardData($vars) { //validateCreditCardData(array('creditCardNumber'=>$creditCardNumber,'ccvn'=>$ccvn,'expirationYear'=>$expirationYear,'expirationMonth'=>$expirationMonth)); $creditCardNumber = $vars['creditCardNumber']; $ccvn = $vars['ccvn']; $expirationYear = $vars['expirationYear']; $expirationMonth = $vars['expirationMonth']; // Credit Card Validation Area if ($creditCardNumber) { $ccv_result = CCVal($creditCardNumber, "Visa"); if ($ccv_result == 'true') $ccType = "Visa"; else { $ccv_result = CCVal($creditCardNumber, "MasterCard"); if ($ccv_result == 'true') $ccType = "MasterCard"; else { $ccv_result = CCVal($creditCardNumber, "Amex"); if ($ccv_result == 'true') $ccType = "Amex"; else { $ccv_result = CCVal($creditCardNumber, "Discover"); if ($ccv_result == 'true') $ccType = "Discover"; else { $error_fields [] = 'creditCardNumber'; $errors [] = "The credit card number entered does not appear to be valid or it is a different type of credit card than selected. Please check it and try again."; } } } } } else { $errors [] = "Please enter your credit card number."; $error_fields [] = 'creditCardNumber'; } if (!$ccvn) { $errors [] = "Please enter your credit card verification number."; $error_fields [] = 'ccvn'; } $ccvn_legnth = strlen($ccvn); if (($cc_type != 'Amex') && ($ccvn_legnth != '3') && ($ccvn != '')) { $error_fields [] = 'ccvn'; $errors [] = "Your credit card verification number does not appear to be correct. Please re-enter it."; } if (($cc_type == 'Amex') && ($ccvn_legnth != '4') && ($ccvn != '')) { $error_fields [] = 'ccvn'; $errors [] = "Your credit card verification number does not appear to be correct. Please re-enter it."; } // CC Date Check $this_year = date("y"); $this_month = date("m"); if ($expirationYear <= $this_year) { if (($expirationMonth < $this_month) || ($expirationYear < $this_year)) $errors [] = "Your credit card appears to have expired. Please check it and try again."; } if ($errors) { if ($errors) { $message .= ""; } $success = false; } else $success = true; return array('success' => $success, 'errors' => $message, 'ccType' => $ccType, 'errorArray' => $errors); } // Shows the category name and all hierarchey categories via cat id function show_category_name($orig_cat_id) { mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query_cat_name_1 = mysql_query("SELECT parent, name FROM category_list WHERE id='$orig_cat_id'"); $object_cat_name_1 = mysql_fetch_object($query_cat_name_1); $cat_name_1 = "$object_cat_name_1->name"; $cat_parent_1 = "$object_cat_name_1->parent"; $query_cat_name_2 = mysql_query("SELECT parent, name FROM category_list WHERE id='$cat_parent_1'"); $object_cat_name_2 = mysql_fetch_object($query_cat_name_2); $cat_name_2 = "$object_cat_name_2->name"; $cat_parent_2 = "$object_cat_name_2->parent"; if ($cat_parent_2 != 0) { $query_cat_name_3 = mysql_query("SELECT name FROM category_list WHERE id='$cat_parent_2'"); $count = mysql_num_rows($query_cat_name_3); $object_cat_name_3 = mysql_fetch_object($query_cat_name_3); $cat_name_3 = "$object_cat_name_3->name"; $full_cat_name = "$cat_name_3 > $cat_name_2 > $cat_name_1"; } else $full_cat_name = "$cat_name_2 > $cat_name_1"; if ($full_cat_name == ' > ' || $full_cat_name == ' > > ') $full_cat_name = ""; return "$full_cat_name"; } // Creates the form to attach a project to a package function member_attach_package_form($attached_to_package) { global $package_name_array; global $package_display_link; mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $member_id = $_SESSION ['member_id']; $query = mysql_query("SELECT package_id, package_type FROM member_package WHERE member_id='$member_id'"); if (mysql_num_rows($query) > 0) { $form .= ""; $return .= " Attach To Package $form
If this project is for a package in your members area, pelase select which package it is for. This will help us gather all required information "; } return $return; } // Generates some sort of name for the package (depends on if a name was enterd // or ISBN data entered) function member_attach_package_display($attached_to_package) { global $package_name_array; mysql_select_db(eckopub_members) or die("Unable to select database (1)"); if ($attached_to_package > 0) { global $package_display_link; $query = mysql_query("SELECT package_id, package_type FROM member_package WHERE package_id='$attached_to_package'") or die(mysql_error()); list ($package_id, $package_type) = mysql_fetch_row($query); $query_isbn_number = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$attached_to_package'"); $object_isbn_number = mysql_fetch_object($query_isbn_number); $isbn_assigned = "$object_isbn_number->isbn"; $query_package_title = mysql_query("SELECT book_title FROM member_book_details WHERE package_id='$attached_to_package'"); $object_package_title = mysql_fetch_object($query_package_title); $package_title = "$object_package_title->book_title"; $package_type = $package_name_array ["$package_type"]; if ($package_title) $show_name = "Package Title: $package_title (ID:$package_id)"; else if ($isbn_assigned) $show_name = "Package ISBN: $isbn_assigned (ID:$package_id)"; else $show_name = "Package Type: $package_type (ID:$package_id)"; $return .= " Attach To Package $show_name $package_display_link
If this project is for a package in your members area, pelase select which package it is for. "; } else $return .= " Attach To Package Not Attached To Project
If this project is for a package in your members area, pelase select which package it is for. "; return $return; } // Generates a list of packages function list_packages() { global $package_display_link; mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $member_id = $_SESSION ['member_id']; $query = mysql_query("SELECT package_id FROM v2_member_package WHERE member_id='$member_id'") or die(mysql_error()); if (mysql_num_rows($query) > 0) { $form .= ""; } return $form; } // Calculates the profit per book based on retail rate, manufacture cost and // wholesale rate function calculate_profit_by_retail_rate($amount, $cpb, $wholesale_fee = null) { if (!$wholesale_fee) $wholesale_fee = ".55"; if ($wholesale_fee [0] != '.') $wholesale_fee = '.' . $wholesale_fee; // In this case, $amount is the retail price $total_after_bookstore = $amount - ($amount * $wholesale_fee); $profit_left = $total_after_bookstore - $cpb; $bookstore_cut = $amount - $total_after_bookstore; $profit_left_array = array('profit_left' => "$profit_left", 'bookstore_cut' => "$bookstore_cut", 'total_after_bookstore' => "$total_after_bookstore"); return $profit_left_array; } // Calculates the profit per book based on retail rate, manufacture cost and // wholesale rate function calculate_retail_price_by_profit_required($amount, $cpb, $wholesale_fee = null) { if (!$wholesale_fee) $wholesale_fee = ".55"; // $retail_cost = ($amount + $cpb) * $wholesale_fee + ($amount + $cpb); $retail_cost = ($amount + $cpb) * $wholesale_fee + ($amount + $cpb); while ($profit_left < $amount && $g < 15000) { $retail_cost = round($retail_cost + .01, 3); $var1 = $retail_cost - ($retail_cost * $wholesale_fee); $profit_left = $var1 - $cpb; $profit_left = number_format($profit_left, 2, '.', ''); $g++; } $var1 = number_format($var1, 2, '.', ''); $retail_cost = number_format($retail_cost, 2, '.', ''); // echo "//$var1 :: $retail_cost"; // $retail_cost="$retail_cost / $amount / $cpb / $wholesale_fee"; return $retail_cost; } // Calcultes New Amazon Profit using the revised distrbution system function calculate_amazon_distribution_profit($retail_rate) { global $ecko_profit_for_amazon; $amazon_percentage = .15; $amazon_flat_fee = 1.35; $distribution_expense = number_format(($retail_rate * $amazon_percentage) + ($amazon_flat_fee + $ecko_profit_for_amazon), 2, '.', ''); $final_profit = number_format($retail_rate - $distribution_expense, 2, '.', ''); $results = array('final_profit' => "$final_profit", 'distribution_expense' => "$distribution_expense"); return $results; } // Calculate the profit for digital distribution function calculate_profit_for_digital_distribution($retail_rate, $ecko_fee = null) { // iPad takes 30% of the retail rate $ipad_percentage = 30; $ipad_cut = $retail_rate * ($ipad_percentage / 100); $ipad_profit = $retail_rate - $ipad_cut; // Nook takes 35% if price is between $2.99 and $9.99 60% if grater or less // than. // Amazon takes either 30% or 65%(plus delivery fee for the latter). If the // book is priced between $2.99 and $9.99, it qualifies for the 65% royaltee // rate. Less or more and it does not // Delivery fee is MB x .015 cents. if ($retail_rate > 9.99 || $retail_rate < 2.99) { // Take larger set of // royatlee rates $kindle_percentage = 65; $nook_percentage = 60; $digital_note = ""; } else { $kindle_percentage = 35; $nook_percentage = 40; $digital_note = ""; } $kindle_cut = $retail_rate * ($kindle_percentage / 100); $kindle_profit = $retail_rate - $kindle_cut; $nook_cut = $retail_rate * ($nook_percentage / 100); $nook_profit = $retail_rate - $nook_cut; // Google takes 48% $google_percentage = 48; $google_cut = $retail_rate * ($google_percentage / 100); $google_profit = $retail_rate - $google_cut; if ($ecko_fee) { $ipad_profit = $ipad_profit - $ecko_fee; $kindle_profit = $kindle_profit - $ecko_fee; $nook_profit = $nook_profit - $ecko_fee; $google_profit = $google_profit - $ecko_fee; } $retults = array('ipad_profit' => "$ipad_profit", 'kindle_profit' => "$kindle_profit", 'nook_profit' => "$nook_profit", 'google_profit' => "$google_profit", 'ipad_cut' => "$ipad_cut", 'kindle_cut' => "$kindle_cut", 'nook_cut' => "$nook_cut", 'google_cut' => "$google_cut", 'ipad_percentage' => "$ipad_percentage", 'kindle_percentage' => "$kindle_percentage", 'nook_percentage' => "$nook_percentage", 'google_percentage' => "$google_percentage"); return $retults; } // Downloads the latest currency rates form yahoo function get_current_currency_rates() { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_misc) or die("Unable to select database (1)"); $currency_from = 'USD'; $currency_type_array = array('GBP', 'EUR'); foreach ($currency_type_array as $currency_to) { $url = "http://download.finance.yahoo.com/d/quotes.csv?s=$currency_from$currency_to=X&f=l1&e=.csv"; $open = fopen($url, "r"); $exchange_rate = fread($open, 2000); fclose($open); $$currency_to = $exchange_rate; } mysql_query("UPDATE currency_exchange_rate SET date_updated=CURDATE(), gbp='$GBP', eur='$EUR' WHERE id='1'") or die(mysql_error()); $results = "Currency Rates Updated. New Rates: GBP: $GBP, EUR: $EUR"; return $results; } // Generates a random 8 character password function RandomPassword($legnth = null) { if (!$legnth) $legnth = 8; $salt = "abchefghjkmnpqrstuvwxyz123456789"; srand((double)microtime() * 1000000); $j = 0; while ($j < $legnth) { $num = rand() % strlen($salt); $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $j++; } $password_enc = md5($pass); $password = array('password_display' => "$pass", 'password_enc' => "$password_enc"); return $password; } // Sends out e-mails from info@eckopublishing.com function pear_mail($from, $first_name, $last_name, $email, $subject_line, $email_body) { require_once "Mail.php"; // Actually no real file here. This grabs the pear // file if ($first_name && $last_name) $to = "$first_name $last_name <$email>"; else if ($first_name && !$last_name) $to = "$first_name <$email>"; else $to = "$email<$email>"; $subject = "$subject_line"; $body = "$email_body"; $order_id = $id; if (!$from) $from = "info@eckopublishing.com"; // This is where the e-mail is coming from. This must be correct for the // smtp login... $host = "eckopublishing.com"; $username = "info.eckopublishing"; $password = "N4Qt1ZMmK7Tw"; $from_email = $from; $from = "ECKO Publishing <$from>"; // The e-mail headers // $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, // 'MIME-Version' => 'MIME-Version: 1.0', 'Content-type' => 'text/html; // charset=iso-8859-1', 'Message-Id' => md5 ( uniqid ( microtime () ) ) . // "@eckopublishing.com", 'Date' => date ( "r" ) ); $headers = array('From' => "$from", 'To' => "$to", 'Subject' => "$subject", 'Reply-To' => "$from_email", 'Return-Path' => "$from_email", 'MIME-Version' => '1.0', 'Content-Type' => 'text/html; charset="iso-8859-1"', 'Content-Transfer-Encoding' => '8bit', 'Message-ID' => md5(uniqid(microtime())) . "@eckopublishing.com", 'Date' => date("r")); // The actual delivery system $smtp = Mail::factory('smtp', array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'port' => "25")); $mail = $smtp->send($email, $headers, $body); // This is error control. if (PEAR::isError($mail)) { $error_headers = "MIME-Version: 1.0\r\n"; $error_headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $error_headers .= "From: ECKO Publishing <$from>\r\n"; $email_error_message = $mail->getMessage(); $auto_mail_error = "There was a problem sending the automated e-mail. The error is below
.$email_error_message
$email_body"; mail($from, "There was an error sending the automated email - ECKOPUBLISHING.COM", "$auto_mail_error", $error_headers, "-f$from"); // echo "$auto_mail_error :: $login_info"; } return $email_error_message; } function sendEmailV2($first_name, $last_name, $subject_email, $html_email, $text_email, $email) { //sendEmailV2($first_name,$last_name,'$subject',$htmlEmail,'',$emailAddressTo); if ($first_name && $last_name) $to = "$first_name $last_name"; else if ($first_name && !$last_name) $to = "$first_name"; else $to = ''; include_once '/home/eckopub/public_html/_tools/_phpMailer/class.phpmailer.php'; $mail = new PHPMailer(); //$mail->SMTPKeepAlive = true; $mail->IsSMTP(); $mail->WordWrap = 80; $mail->SMTPAuth = true; $mail->IsHTML(true); $mail->XMailer = 'ECKO Publishing Mail System'; //Server Settings //Amazon AWS Server $mail->Port = 443; $mail->Host = 'ssl://email-smtp.us-east-1.amazonaws.com'; $mail->Username = 'AKIAINLSQ3HB5SOZGKCA'; $mail->Password = 'AuBPg89lGpZBkn+2n6dCBNGVYJO8aAOOn9IipLZ5sn7u'; //Local Mail Server //$mail->Port = 25; //$mail->Host = 'mail.eckopublishing.com'; //$mail->Username = 'info.eckopublishing'; //$mail->Password = 'N4Qt1ZMmK7Tw'; //Who is sending the email $mail->SetFrom('info@eckopublishing.com', 'ECKO Publishing'); $mail->AddReplyTo('info@eckopublishing.com', 'ECKO Publishing'); $mail->addCustomHeader("Errors-To: "); $mail->ReturnPath = 'info@eckopublishing.com'; //The email information $mail->AddAddress($email, $to); $mail->Subject = $subject_email; $mail->Body = $html_email; if ($text_email) $mail->AltBody = $text_email; if (!$mail->Send()) { //Failed $errrMessage = $mail->ErrorInfo; $message = "

Message failed to $to
$errrMessage

"; } else { //Sent $message = "

Message successfully sent to $to ($email)

"; } // Clear all addresses and attachments for next loop $mail->ClearAllRecipients(); $mail->SmtpClose(); return $message; } // Cleans the URL of special characters function url_clean($content_title, $content_id) { $address_title_array = array(',', "'", '@', '$', '&', '*', '!', '`', '"'); $content_title = str_replace($address_title_array, '', $content_title); $content_title = str_replace(' ', '-', $content_title); $content_title = str_replace('---', '-', $content_title); $content_title = str_replace('--', '-', $content_title); $content_title = str_replace('--', '-', $content_title); $link_gen = "http://www.eckopublishing.com/$content_id/$content_title/"; return $link_gen; } // Cleans teh title function url_title_clean($content_title) { $content_title = str_ireplace('&', 'and', $content_title); $address_title_array = array(',', "'", '@', '$', '&', '*', '!', '`', '"', '?', '/'); $content_title = str_replace($address_title_array, '', $content_title); $content_title = str_replace(' ', '-', $content_title); $content_title = str_replace('---', '-', $content_title); $content_title = str_replace('--', '-', $content_title); $content_title = str_replace('--', '-', $content_title); return $content_title; } // Verifies the correct SQL Date function sql_date_correct($sql_date_verify) { $verify_date_array = explode('-', $sql_date_verify); $year_var = $verify_date_array ['0']; $month_var = $verify_date_array ['1']; $day_var = $verify_date_array ['2']; if (strlen($year_var) != '4' || !is_numeric($year_var)) { $approved = 'no'; $result .= "Year legnth incorrect or is not a number ($year_var)"; } else if (strlen($month_var) != '2' || !is_numeric($month_var) || $month_var > '12') { $approved = 'no'; $result .= "Month legnth incorrect or is not a number or over 12"; } else if (strlen($day_var) != '2' || !is_numeric($day_var) || $day_var > '31') { $approved = 'no'; $result .= "Day legnth incorrect or is not a number or over 31"; } else { $approved = 'yes'; $result .= "Date Approved"; } $result = array('approved' => "$approved", 'result' => "$result"); return $result; } // Verifies the correct SQL Date function sql_date_verify($sql_date_verify) { $sql_date_correct = sql_date_correct($sql_date_verify); $approved = $sql_date_correct ["approved"]; $result = $sql_date_correct ["result"]; if (!$approved) { $verify_date_time = mysqldate_readable($sql_date_verify); if ($sql_date_verify < date("Y-m-d")) { $result .= "The date entered is in the past. It needs to be in the future. ($verify_date_time)"; $approved = 'no'; } else { $verify_date_time = mysqldate_readable($sql_date_verify); $result .= "Date Accepted - Next Payment on $verify_date_time"; $approved = 'yes'; } } $result = array('result_message' => "$result", 'approved' => "$approved"); return $result; } // Display username from ID function display_username_from_id($member_id) { mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query = mysql_query("SELECT member_username FROM member_data WHERE member_id='$member_id'"); $object = mysql_fetch_object($query); $member_username = "$object->member_username"; return $member_username; } function user_info_from_id($member_id) { mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query = mysql_query("SELECT member_username,member_signup_date,member_first_name,member_last_name,member_address1,member_address2,member_city,member_state,member_zip,member_country,member_phone,member_email FROM member_data WHERE member_id='$member_id'"); list ($member_username, $member_signup_date, $member_first_name, $member_last_name, $member_address1, $member_address2, $member_city, $member_state, $member_zip, $member_country, $member_phone, $member_email) = mysql_fetch_row($query); return array('member_username' => $member_username, 'member_signup_date' => $member_signup_date, 'member_first_name' => $member_first_name, 'member_last_name' => $member_last_name, 'member_address1' => $member_address1, 'member_address2' => $member_address2, 'member_city' => $member_city, 'member_state' => $member_state, 'member_zip' => $member_zip, 'member_country' => $member_country, 'member_phone' => $member_phone, 'member_email' => $member_email); } // Display id from username function display_id_from_username($member_username) { $member_username = clean_username($member_username); mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query = mysql_query("SELECT member_id FROM member_data WHERE member_username_safe='$member_username'"); $members_found = mysql_num_rows($query); $object = mysql_fetch_object($query); $member_id = "$object->member_id"; $return = array('members_found' => "$members_found", 'member_id' => "$member_id"); return $return; } // For the marketing system - to get the title info function marketing_get_title_info($package_id) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (1)"); /* * $query = mysql_query ( "SELECT book_title, book_subtitle, author1 FROM member_book_details WHERE package_id='$package_id'" ); list ( $book_title, $book_subtitle, $author1 ) = mysql_fetch_row ( $query ); $query2 = mysql_query ( "SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$package_id'" ); list ( $isbn ) = mysql_fetch_row ( $query2 ); $query3 = mysql_query ( "SELECT package_type FROM member_package WHERE package_id='$package_id'" ); list ( $package_type ) = * mysql_fetch_row ( $query3 ); */ $query = mysql_query("SELECT title, subtitle, contributor_first_name_1, contributor_last_name_business_1 FROM package_isbn_registry_data WHERE package_id='$package_id'"); if (!mysql_numrows($query)) $query = mysql_query("SELECT title, subtitle, contributor_first_name_1, contributor_last_name_business_1 FROM v2_package_isbn_registry_data WHERE package_id='$package_id'"); list ($book_title, $book_subtitle, $contributor_first_name_1, $contributor_last_name_business_1) = mysql_fetch_row($query); $author = "$contributor_first_name_1 $contributor_last_name_business_1"; $query2 = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$package_id'"); list ($isbn) = mysql_fetch_row($query2); $result = array('book_title' => "$book_title", 'book_subtitle' => "$book_subtitle", 'author' => "$author", 'isbn' => "$isbn", 'package_type' => "$package_type"); return $result; } // Alternative image resize for marketing material function image_resize_mm($width, $height, $fname, $uploaddir, $tempfile) { // Image Resize Function // RE-SIZING UPLOADED IMAGE $filename = "$tempfile"; list ($width_orig, $height_orig) = getimagesize($tempfile); $img_quality = 95; if (($width_orig > $width) || ($height_orig > $height)) { // Get new dimensions if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, "$uploaddir/$fname", $img_quality); /* * return "
The image has been resized

The New Image Width: $width
The New Image Height: $height

"; */ } else { $image_p = imagecreatetruecolor($width_orig, $height_orig); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width_orig, $height_orig, $width_orig, $height_orig); imagejpeg($image_p, $uploaddir, $img_quality); } } // Generates a list of images uploaded for marketing function marketing_image_list($num, $uploaddir) { global $uplaod_folder_name; if (file_exists($uploaddir)) { if ($dh = opendir($uploaddir)) { $image_list .= ""; closedir($dh); } } return $image_list; } // Cleans the paragraphs for the marketing information function marketing_clean_paragraph($content) { $content = str_replace(' ', ' ', $content); $content = str_replace('..', '.', $content); $content = str_replace('.?', '?', $content); $content = str_replace('?.', '.', $content); $content = str_replace('??', '?', $content); $content = str_replace('!!', '!', $content); $content = str_replace('!.', '.', $content); $content = str_replace('.!', '!', $content); $content = str_replace(',,', ',', $content); $content = str_replace('""', '"', $content); $content = str_replace('. ".', '".', $content); $content = str_replace(' "', '"', $content); $content = str_replace(' .', '.', $content); $content = str_replace('. ', '. ', $content); return $content; } // Finds the package ID using the ISBN number function package_id_by_isbn($isbn) { if (strlen($isbn) != 13 && strlen($isbn) != 17) $error .= "-The ISBN number entered should be either 13 or 17 characters long-" . strlen($isbn); else { if (strlen($isbn) == 13) { // Add Dashes include_once 'administrator/stock_managment_functions.inc'; $isbn = insert_dashes_into_isbn($isbn); } include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query = mysql_query("SELECT assigned_member_id, assigned_package_id FROM package_isbn_numbers WHERE isbn='$isbn'"); $count = mysql_num_rows($query); if ($count == 0) { // Check aardvark_upgrade_isbn table $query = mysql_query("SELECT member_id, package_id FROM aardvark_upgrade_isbn WHERE isbn='$isbn'"); $count = mysql_num_rows($query); } if ($count > 1 || $count == 0) $error .= "-Found $count occurances of that ISBN number-"; else list ($member_id, $package_id) = mysql_fetch_row($query); } $return = array('package_id' => $package_id, 'member_id' => $member_id, 'error' => $error); return $return; } function insert_dashes_into_isbn($isbn) { if (substr($isbn, 0, 8) == '97814276') // This is for the prefix // 978-1-4276- $isbn = $isbn [0] . $isbn [1] . $isbn [2] . '-' . $isbn [3] . '-' . $isbn [4] . $isbn [5] . $isbn [6] . $isbn [7] . '-' . $isbn [8] . $isbn [9] . $isbn [10] . $isbn [11] . '-' . $isbn [12]; return $isbn; } function gencheckdigit($isbn) { // $isbn = trim($isbn); for ($i = 0; $i <= 12; $i++) { $tc = substr($isbn, -1, 1); $isbn = substr($isbn, 0, -1); $ta = ($tc * 3); $tci = substr($isbn, -1, 1); $isbn = substr($isbn, 0, -1); $tb = $tb + $ta + $tci; } $tg = ($tb / 10); $tint = intval($tg); if ($tint == $tg) { return 0; } $ts = substr($tg, -1, 1); $tsum = (10 - $ts); return $tsum; } function validateISBN($isbn) { $isbnClean = str_replace('-', '', trim($isbn)); if (!is_numeric($isbnClean) && strtolower(substr($isbnClean, -1)) != 'x') $message = '

The ISBN number entered contained items other than numbers and dashes. Please verify the entered number and try again.

'; else { if (strlen($isbnClean) == 13) { //Generate Check Digit $sum = $isbnClean[0] * 1 + $isbnClean[1] * 3 + $isbnClean[2] * 1 + $isbnClean[3] * 3 + $isbnClean[4] * 1 + $isbnClean[5] * 3 + $isbnClean[6] * 1 + $isbnClean[7] * 3 + $isbnClean[8] * 1 + $isbnClean[9] * 3 + $isbnClean[10] * 1 + $isbnClean[11] * 3; $generatedCheckDigit = 10 - ($sum % 10); if ($generatedCheckDigit == 10) $generatedCheckDigit = 0; if ($generatedCheckDigit == $isbnClean[12]) { $passed = true; $message .= '

The ISBN has been successfully validated and is correct.

'; } else $message = "

The entered 13 digit isbn number check digit is incorrect. The last number should be $generatedCheckDigit. Please verify your 13 digit ISBN number. If you are sure the first 12 digits are correct, you can enter $generatedCheckDigit for the last number.

"; } else if (strlen($isbnClean) == 10) { $isbn10to13 = isbn10to13($isbn); $message = '

The ISBN entered is 10 digits long. 10 digit ISBN numbers are no longer used and should be converted to a 13 digit and used from now on.

'; if ($isbn10to13['passed'] != true) $message .= '

An error was reported with your 10 digit ISBN: ' . $isbn10to13['message'] . '

'; else { $passed = true; $newISBN13 = $isbn10to13['newISBN13']; $message .= "

The converted 13 digit ISBN number is $newISBN13

"; } } else $message = '

The ISBN entered was not 13 digits long.

'; } return array('message' => $message, 'passed' => $passed, 'checkDigit' => $generatedCheckDigit, 'newISBN13' => $newISBN13); } function isbn10to13($isbn) { $isbnClean = str_replace('-', '', trim($isbn)); if (!is_numeric($isbnClean) && strtolower(substr($isbnClean, -1)) != 'x') $message = '

The ISBN number entered contained items other than numbers and dashes. Please verify the entered number and try again.

'; else { if (strlen($isbnClean) == 10) { //Verify 10 digit number $sum = $isbnClean[0] * 10 + $isbnClean[1] * 9 + $isbnClean[2] * 8 + $isbnClean[3] * 7 + $isbnClean[4] * 6 + $isbnClean[5] * 5 + $isbnClean[6] * 4 + $isbnClean[7] * 3 + $isbnClean[8] * 2; $generatedCheckDigit = 11 - ($sum % 11); if ($generatedCheckDigit == 10) $generatedCheckDigit = 'X'; if ($generatedCheckDigit != $isbnClean[9]) $message = "

The entered 10 digit isbn number check digit is incorrect. The last number should be $generatedCheckDigit. Please verify your 10 digit ISBN number. If you are sure the first 9 digits are correct, you can enter $generatedCheckDigit for the last number."; else { $passed = true; $isbn13 = '978' . $isbnClean; //Generate Check Digit $sum = $isbn13[0] * 1 + $isbn13[1] * 3 + $isbn13[2] * 1 + $isbn13[3] * 3 + $isbn13[4] * 1 + $isbn13[5] * 3 + $isbn13[6] * 1 + $isbn13[7] * 3 + $isbn13[8] * 1 + $isbn13[9] * 3 + $isbn13[10] * 1 + $isbn13[11] * 3; $generatedCheckDigit = 10 - ($sum % 10); if ($generatedCheckDigit == 10) $generatedCheckDigit = 0; $newISBN13 = '978-' . substr($isbn, 0, -1) . $generatedCheckDigit; } } else $message = '

Please enter a 10 digit number to convert.

'; } return array('message' => $message, 'newISBN13' => $newISBN13, 'checkDigit' => $generatedCheckDigit, 'passed' => $passed); } function calculate_royaltee($isbn, $product_type, $quantity_sold, $ship_cost, $ecko_fees, $trans_type) { mysql_select_db(eckopub_members) or die("Unable to select database (1)"); // Get Package ID from ISBN $package_id_by_isbn = package_id_by_isbn($isbn); $package_id = $package_id_by_isbn ['package_id']; $member_id = $package_id_by_isbn ['member_id']; $member_username = display_username_from_id($member_id); $error = $package_id_by_isbn ['error']; if (!$error) { // Find out the system version $query_v2 = mysql_query("SELECT package_id FROM v2_member_package WHERE package_id='$package_id'"); if (mysql_numrows($query_v2)) $ver = 'v2'; else $ver = 'v1'; if ($ver == 'v2') { // Get info about book and calcualte the manufacture CPB // , book_title, book_subtitle, author1 $query = mysql_query("SELECT production_cost_usd, retail_rate_usd, wholesale_rate_usd FROM v2_package_pod_distro WHERE package_id='$package_id'"); list ($production_cost_usd, $retail_rate_usd, $wholesale_rate_usd) = mysql_fetch_row($query); include_once '_quotes/printing_quote_function.inc'; // Calculate Profit Left $profit_left_array = calculate_profit_by_retail_rate($retail_rate_usd, $production_cost_usd, $wholesale_rate_usd); $profit_left = number_format($profit_left_array ["profit_left"], 2, '.', ''); $bookstore_cut = number_format($profit_left_array ["bookstore_cut"], 2, '.', ''); $total_after_bookstore = number_format($profit_left_array ["total_after_bookstore"], 2, '.', ''); $retail_rate = $retail_rate_usd; $cpb = $production_cost_usd; // This is the returned data $retail_rate_per_book = $retail_rate; $manufacture_cpb = $production_cost_usd; if ($trans_type == 'sale') { $royaltees_earned_per_book = $profit_left; // Calculate totals considering $quantity_sold, $ship_cost, // $ecko_fees $total_royaltees = ($profit_left * $quantity_sold) - ($ship_cost + $ecko_fees); } else { // This is the returned data $royaltees_earned_per_book = $profit_left + $manufacture_cpb; // Calculate totals considering $quantity_sold, $ship_cost, // $ecko_fees $total_royaltees = ($royaltees_earned_per_book * $quantity_sold) + $ecko_fees; } } elseif ($ver == 'v1') { // Get Package Type $query_pt = mysql_query("SELECT package_type FROM member_package WHERE package_id='$package_id'"); list ($package_type) = mysql_fetch_row($query_pt); // Get info about book and calcualte the manufacture CPB $query = mysql_query("SELECT book_size, binding_type, black_page_quantity, color_page_quantity, paper_color, book_title, book_subtitle, author1 FROM member_book_details WHERE package_id='$package_id'"); list ($book_size, $binding_type, $black_page_quantity, $color_page_quantity, $paper_color, $book_title, $book_subtitle, $author1) = mysql_fetch_row($query); include_once '_quotes/printing_quote_function.inc'; $printing_quote_array = printing_calculator($book_size, $binding_type, $black_page_quantity, $color_page_quantity, $paper_color); if ($package_type == '1') $cpb = $printing_quote_array ['member_cost']; else if (($package_type == '2' || $package_type == '3')) $cpb = $printing_quote_array ['platinum_member_cost']; // Calculate Profit Left $wholesale_fee = ".55"; $query2 = mysql_query("SELECT retail_rate, kindle_retail FROM member_package_distro WHERE package_id='$package_id'"); list ($retail_rate, $kindle_retail) = mysql_fetch_row($query2); $profit_left_array = calculate_profit_by_retail_rate($retail_rate, $cpb); $profit_left = number_format($profit_left_array ["profit_left"], 2, '.', ''); $bookstore_cut = number_format($profit_left_array ["bookstore_cut"], 2, '.', ''); $total_after_bookstore = number_format($profit_left_array ["total_after_bookstore"], 2, '.', ''); // This is the returned data $retail_rate_per_book = $retail_rate; $manufacture_cpb = $cpb; if ($trans_type == 'sale') { $royaltees_earned_per_book = $profit_left; // Calculate totals considering $quantity_sold, $ship_cost, // $ecko_fees $total_royaltees = ($profit_left * $quantity_sold) - ($ship_cost + $ecko_fees); } else { // This is the returned data $royaltees_earned_per_book = $profit_left + $manufacture_cpb; // Calculate totals considering $quantity_sold, $ship_cost, // $ecko_fees $total_royaltees = ($royaltees_earned_per_book * $quantity_sold) + $ecko_fees; } } } $retail_rate_per_book = number_format($retail_rate_per_book, 2, '.', ''); $manufacture_cpb = number_format($manufacture_cpb, 2, '.', ''); $royaltees_earned = number_format($royaltees_earned, 2, '.', ''); $total_royaltees = number_format($total_royaltees, 2, '.', ''); $results = array('retail_rate_per_book' => "$retail_rate_per_book", 'kindle_rate' => "$kindle_retail", 'manufacture_cpb' => "$manufacture_cpb", 'royaltees_earned_per_book' => "$royaltees_earned_per_book", 'total_royaltees' => "$total_royaltees", 'book_size' => "$book_size", 'binding_type' => "$binding_type", 'black_page_quantity' => "$black_page_quantity", 'color_page_quantity' => "$color_page_quantity", 'paper_color' => "$paper_color", 'book_title' => "$book_title", 'book_subtitle' => "$book_subtitle", 'author1' => "$author1", 'package_id' => "$package_id", 'package_type' => "$package_type", 'member_id' => "$member_id", 'member_username' => "$member_username", 'error' => "$error", 'quantity_in_stock' => "$quantity_in_stock"); return $results; } function isbn_by_package_id($package_id) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (98)"); $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$package_id'"); $count = mysql_numrows($query); if ($count == 0) { // Check aardvark_upgrade_isbn table $query = mysql_query("SELECT isbn FROM aardvark_upgrade_isbn WHERE package_id='$package_id'"); $count = mysql_num_rows($query); } if ($count == 1) { list ($isbn) = mysql_fetch_row($query); $successful = 'yes'; $result_disp = "ISBN Found"; } else if ($count == 0) { $result_disp = "No ISBN assigned to this package."; $successful = 'no'; } else $result_disp = "Multiple ISBN's found."; $results = array('successful' => "$successful", 'result_disp' => "$result_disp", 'isbn' => "$isbn"); return $results; } function package_details_by_package_id($package_id) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (99)"); $query_member_id = mysql_query("SELECT member_id FROM member_package WHERE package_id='$package_id'"); list ($member_id) = mysql_fetch_row($query_member_id); $member_username = display_username_from_id($member_id); // Get Package Type $query_pt = mysql_query("SELECT package_type FROM member_package WHERE package_id='$package_id'"); list ($package_type) = mysql_fetch_row($query_pt); // Get info about book and calcualte the manufacture CPB $query = mysql_query("SELECT book_size, binding_type, black_page_quantity, color_page_quantity, paper_color, book_title, book_subtitle, author1 FROM member_book_details WHERE package_id='$package_id'"); list ($book_size, $binding_type, $black_page_quantity, $color_page_quantity, $paper_color, $book_title, $book_subtitle, $author1) = mysql_fetch_row($query); include_once '_quotes/printing_quote_function.inc'; global $book_size_array; global $bind_type_array; global $paper_color_array; $book_size_disp = $book_size_array ["$book_size"]; $binding_type_disp = $bind_type_array ["$binding_type"]; $paper_color_disp = $paper_color_array ["$paper_color"]; if (!$color_page_quantity) $color_page_quantity = 0; if (!$black_page_quantity) $black_page_quantity = 0; $total_pages = $black_page_quantity + $color_page_quantity; // Calculate Profit Left $wholesale_fee = ".55"; // $books_in_stock $results = array ('successful' => "$successful", // 'result_disp' => "$result_disp", 'isbn' => "$isbn" ); include_once 'administrator/stock_managment_functions.inc'; $isbn_by_package_id = isbn_by_package_id($package_id); $isbn = $isbn_by_package_id ['isbn']; $get_stock_id = get_stock_id($isbn, '1'); // $results = array ('stock_id' => "$stock_id", 'disp_result' => // "$disp_result", 'successful' => "$success" ); $get_stock_id_successful = $get_stock_id ['successful']; if ($get_stock_id_successful == 'yes') { $stock_id = $get_stock_id ['stock_id']; $stock_id_results = $get_stock_id ['disp_result']; $books_in_stock = stock_quantity($stock_id); } else $books_in_stock = "0"; include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (99)"); $query2 = mysql_query("SELECT retail_rate, kindle_retail FROM member_package_distro WHERE package_id='$package_id'"); list ($retail_rate, $kindle_rate) = mysql_fetch_row($query2); $printing_quote_array = printing_calculator($book_size, $binding_type, $black_page_quantity, $color_page_quantity, $paper_color); if ($package_type == '1') $cpb = $printing_quote_array ['member_cost']; else if (($package_type == '2' || $package_type == '3')) $cpb = $printing_quote_array ['platinum_member_cost']; $result = "
Member Username $member_username ($member_id) Package ID $package_id
Title
Subtitle
Author 1
$book_title
$book_subtitle
$author1
Quantity in Stock $books_in_stock (Stock ID: $stock_id)
Book Details Size: $book_size_disp
Bind: $binding_type_disp
Page Quantity: $total_pages black:$black_page_quantity / color:$color_page_quantity
Paper Color: $paper_color_disp
Retail Rate
Kindle Retail
POD Cost
$$retail_rate
$$kindle_rate
$$cpb
$isbn_by_package_id_results"; return $result; } function month_number_readable($month_number) { switch ($month_number) { case '01' : $month_disp = 'January'; break; case '02' : $month_disp = 'February'; break; case '03' : $month_disp = 'March'; break; case '04' : $month_disp = 'April'; break; case '05' : $month_disp = 'May'; break; case '06' : $month_disp = 'June'; break; case '07' : $month_disp = 'July'; break; case '08' : $month_disp = 'August'; break; case '09' : $month_disp = 'September'; break; case '10' : $month_disp = 'October'; break; case '11' : $month_disp = 'November'; break; case '12' : $month_disp = 'December'; break; } return $month_disp; } /* * function total_royaltees($package_id) { mysql_select_db ( eckopub_members ); $query_1 = mysql_query ( "SELECT ship_cost, ecko_fee, royaltees_earned FROM sales_distribution WHERE paid='0'" ); while ( list ( $ship_cost, $ecko_fee, $royaltees_earned ) = mysql_fetch_row ( $query_1 ) ) { $subtraction_1 = ($ship_cost + $ecko_fee) + $subtraction_1; $total_royaltee = $royaltees_earned + $total_royaltee; } $query_2 = mysql_query ( "SELECT ship_cost, ecko_fee, royaltees_lost FROM * sales_distribution_returns WHERE been_subtracted='0'" ); while ( list ( $ship_cost, $ecko_fee, $royaltees_lost ) = mysql_fetch_row ( $query_2 ) ) { $subtraction_2 = ($ship_cost + $ecko_fee + $royaltees_lost) + $subtraction_2; } $query_3 = mysql_query ( "SELECT ship_cost, ecko_fee FROM sales_book_fulfilment WHERE fee_subtracted='0'" ); while ( list ( $ship_cost, $ecko_fee ) = mysql_fetch_row ( $query_3 ) ) { $subtraction_3 = ($ship_cost + $ecko_fee) + $subtraction_3; } $total_subtraction = * $subtraction_1 + $subtraction_2 + $subtraction_3; $final_royaltee = $total_royaltee - $total_subtraction; $return = array ('$total_royaltee' => "$total_royaltee", '$total_subtraction' => "$total_subtraction", 'final_royaltee' => "$final_royaltee" ); return $return; } */ function checkEmail($email) { $from_domain = 'eckopublishing.com'; $from_email_address = 'info@eckopublishing.com'; list ($username, $domain) = split('@', $email); // First check if the domain exists // checks proper syntax if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/", $email)) { // gets domain name // checks for if MX records in the DNS if (getmxrr("$domain", $mx_records, $mx_weight)) { // return false; $email_accepted = 'good'; } else { $email_accepted = 'bad'; $error_message = "The email address domain name may not be correct. Please verify it and try again."; } } else { // If the domain exists, verify the user $email_accepted = 'bad'; $error_message = "The email address name entered may not be correct due to an odd character. Please verify it and try again."; } if ($email_accepted == 'good') { // Grab all the Mail Servers getmxrr("$domain", $mx_records, $mx_weight); asort($mx_records); foreach ($mx_records as $mx_weight => $mx_records) { $fsock = @fsockopen($mx_records, 25, $errno, $errstr, 2); $msg = fread($fsock, 2082); $inital_code = $msg; $msg .= fwrite($fsock, 'HELO eckopublishing.com' . "\r\n"); $msg .= fread($fsock, 2082); $msg .= fwrite($fsock, "MAIL FROM: <$from_email_address>" . "\r\n"); $msg .= fread($fsock, 2082); $msg .= fwrite($fsock, "RCPT TO: <$email>" . "\r\n"); $code .= fread($fsock, 2082); $msg .= $code; $code = intval(substr($code, 0, 3)); fclose($fsock); if ($inital_code == 220) { break; } } $accepted_codes = array(250, 251, 451, 252); if (!in_array($code, $accepted_codes)) $error_message = "The e-mail address entered may not be correct. Verify the part before @ symbol."; else $error_message = 'success'; } return $error_message; } function coupon_function($coupon, $total_cart_value, $adding_code) { global $sid; // First verify coupon is available // Next verify if the coupon applies to the current shopping cart (depending // on the coupon) // Finally calculate how much should be saved // SQL Database values /* * value_type (1 = Total Value to Deduct), (2 = Total Percetage to Take Off Order) single_use (1 = Can Be Used Only Once), (2 = Can Be Used Unitl Expiration Date or Deactivated) verification_type - This will check the coupon_code_verifaction.inc file for the specific verification ID and compare the code to the shopping cart. If the requirements have been verified, the discount will be applied. - This is not yet being used. active (1 = The coupon code is currently active) (2 = The coupon code * is currently inactive) */ mysql_select_db(eckopub_shopping) or die("Unable to select database (6)"); $query_code = mysql_query("SELECT unique_id, code, value_type, value, min_total_order, added_on, expires_on, single_use, verification_type, active, note_customer FROM coupon_code WHERE code='$coupon' ORDER BY expires_on DESC LIMIT 1"); list ($unique_id, $code, $value_type, $value, $min_total_order, $added_on, $expires_on, $single_use, $verification_type, $active, $note_customer) = mysql_fetch_row($query_code); $expires_on = strtotime($expires_on); $cur_date = date('Y-m-d'); $current_date = strtotime($cur_date); if ($total_cart_value < $min_total_order) { $message_icon = "error"; $message = "Your cart must contain a minium of $$min_total_order for this coupon to work."; $message_title = "Error adding Coupoun"; $error = "Your cart must contain a minium of $$min_total_order for this coupon to work."; $error_type = 'soft'; } else if ($active == 1 && $current_date <= $expires_on) { if ($verification_type) { include_once 'coupoun_code_verification.inc'; $calculated_discount = $coupon_code_verification_discount_value; $new_total = number_format($total_cart_value - $calculated_discount, 2, '.', ''); $discount_saved = number_format($calculated_discount, 2, '.', ''); $successful = 'yes'; } else { // Take the $total_cart_value and figure out the discount if ($value_type == 1) { // Simple Subtraction $new_total = number_format($total_cart_value - $value, 2, '.', ''); $discount_saved = number_format($value, 2, '.', ''); } else if ($value_type == 2) { // Calculate discount based on // percentage $value = ".$value"; $discount_saved = number_format($total_cart_value * $value, 2, '.', ''); $new_total = number_format($total_cart_value - $discount_saved, 2, '.', ''); } $successful = 'yes'; } } else { $error = "The coupon code entered is either invalid or has expired.($active | $current_date | $expires_on)"; $error_type = 'hard'; } if ($adding_code) { if ($error) { $message_icon = "error"; $message = $error; $message_title = "Error adding Coupoun"; } else { $message_icon = "success"; $message = $note_customer; $message_title = "Coupoun Added Successfully"; } } $result = array('error_type' => "$error_type", 'successful' => "$successful", 'new_total' => "$new_total", 'discount_saved' => "$discount_saved", 'error' => "$error", 'message_icon' => "$message_icon", 'message' => "$message", 'message_title' => "$message_title"); return $result; } function clean_html($str) { $str = strip_tags($str, '

'); $str = str_replace('�', ' ', $str); $str = str_replace('\\', '', $str); // $str = stripslashes ( $str ); $str = preg_replace('/class=".*"/i', '', $str); $config = array('indent' => true, 'output-html' => true, 'show-body-only' => true, 'bare' => true, 'clean' => true, 'doctype' => 'omit', 'drop-empty-paras' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'enclose-block-text' => true, 'enclose-text' => true, 'quote-marks' => true); $tidy = new tidy (); $tidy->parseString($str, $config, 'utf8'); $tidy->cleanRepair(); $str = tidy_get_output($tidy); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); return $str; } function clean_html_v2($str, $vars = null) { if ($vars ['clean_br']) { $str = str_replace('
', ' ', $str); $str = str_replace('
', ' ', $str); $str = str_replace('
', ' ', $str); } $str = str_replace('�', '-', $str); $str = str_replace('�', '"', $str); $str = str_replace('�', '"', $str); $str = str_replace('�', ''', $str); $str = str_replace('�', '', $str); if ($vars ['strip_tags_full']) { if ($vars ['keep_tags']) $extra_tags = $vars ['keep_tags']; $str = strip_tags($str, "

$extra_tags"); } $str = str_replace('�', ' ', $str); $str = str_replace('\\', '', $str); if ($vars ['strip_classes']) $str = preg_replace('/class=".*"/i', '', $str); $config = array('input-encoding' => mb_detect_encoding($str), 'output-encoding' => 'utf8', 'vertical-space' => false, 'wrap' => '0', 'indent' => true, 'output-html' => true, 'show-body-only' => true, 'bare' => true, 'clean' => true, 'doctype' => 'omit', 'drop-empty-paras' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'enclose-block-text' => true, 'enclose-text' => true, 'quote-marks' => true, 'word-2000' => true); $tidy = new tidy (); $tidy->parseString($str, $config, 'utf8'); $tidy->cleanRepair(); $str = tidy_get_output($tidy); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); return $str; } /* * function create_membership_package_v2($member_username, $package_title, $package_status, $qualified_discount_level, $isbn, $copyright, $lccn, $radio_show, $digital_marketing_materials, $google_books_listing, $eckobooks_distro, $amazon_distro, $ingram_distro, $ingram_advantage, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro) { $display_id_from_username = display_id_from_username ( $member_username ); $member_id = $display_id_from_username ['member_id']; $members_found = * $display_id_from_username ['members_found']; if ($members_found == 1) { if ($package_title) $extra_sql .= ", package_title='$package_title'"; if ($package_status) $extra_sql .= ", package_status='$package_status'"; if ($qualified_discount_level) $extra_sql .= ", qualified_discount_level='$qualified_discount_level'"; mysql_select_db ( eckopub_members ); $query = mysql_query ( "INSERT INTO v2_member_package SET member_id='$member_id, creation_date=CURDATE(), isbn='$isbn', * copyright='$copyright', lccn='$lccn', radio_show='$radio_show', digital_marketing_material='$digital_marketing_material', google_books_listing='$google_books_listing', eckobooks_distro='$eckobooks_distro', amazon_distro='$amazon_distro', ingram_distro='$ingram_distro', ingram_advantage='$ingram_advantage', kindle_distro='$kindle_distro', ipad_distro='$ipad_distro', googlebooks_distro='$googlebooks_distro', nook_distro='$nook_distro' " ); $package_id = mysql_insert_id (); $result = "Package * Created for username $member_username. The package ID is $package_id."; } else $result = "Error verifying the member username. Found $members_found occurences."; return $result; } */ function verify_member_account_existince($id, $id_type) { mysql_select_db(eckopub_members); if ($id_type == 'username') { $member_username_safe = clean_username($id); $query = mysql_query("SELECT member_id FROM member_data WHERE member_username_safe='$member_username_safe'"); } else { $query = mysql_query("SELECT member_id FROM member_data WHERE member_id='$id'"); } $result = mysql_numrows($query); return $result; } function calculate_editing_cost($word_count) { include '_quotes/product_rates.inc'; if (is_numeric($word_count) && !strpos($word_count, '.') && !strpos($word_count, '#')) { $word_count = ceil($word_count); } else { $word_count = 0; $error = "Please enter only numbers for your word count."; } if ($word_count > 0) { $page_quantity = ceil($word_count / 300); $editing_cost = number_to_money_format($page_quantity * $pricing_editing_cost_per_page_v2); if ($editing_cost < 75) { $editing_cost = number_to_money_format(75.00); $error = "The minium cost is $75.00.
The above prices reflect this."; } $word_count_disp = number_format($word_count); } return array('editing_cost' => $editing_cost, 'word_count_disp' => $word_count_disp, 'page_quantity' => $page_quantity, 'error' => $error); } function add_cover_design_to_cart($type) { include '_quotes/product_rates.inc'; global $member_id; $type = strtolower($type); if ($type == 'basic' || $type == 1) { $extra_query = 'Basic'; $total_cost = $pricing_design_cover_basic_v2; } else { $extra_query = 'Advanced'; $total_cost = $pricing_design_cover_advanced_v2; } mysql_select_db(eckopub_publishingquotes); $query = mysql_query("INSERT INTO cover_design SET member_id='$member_id', package='$type', total_cost='$total_cost', date=CURDATE(), purchased='no'"); $quote_id = mysql_insert_id(); add_item_to_cart('cover_design', $quote_id); return $quote_id; } function add_interior_design_to_cart($type) { include '_quotes/product_rates.inc'; global $member_id; $type = strtolower($type); if ($type == 'basic' || $type == 1) { $extra_query = 'Basic'; $total_cost = $pricing_design_interior_basic_v2; } else { $extra_query = 'Advanced'; $total_cost = $pricing_design_interior_advanced_v2; } mysql_select_db(eckopub_publishingquotes); $query = mysql_query("INSERT INTO interior_layout SET member_id='$member_id', layout_type='$type', total_cost='$total_cost', date=CURDATE(), purchased='no'"); $quote_id = mysql_insert_id(); add_item_to_cart('interior_layout', $quote_id); return $quote_id; } function add_editing_to_cart($word_count) { global $member_id; $calculate_editing_cost = calculate_editing_cost($word_count); $editing_cost = $calculate_editing_cost ['editing_cost']; mysql_select_db(eckopub_publishingquotes); $page_quantity = ceil($word_count / 300); $query = mysql_query("INSERT INTO editing SET member_id='$member_id', word_count='$word_count', page_quantity='$page_quantity', total_cost='$editing_cost', date=CURDATE(), purchased='no'"); echo "INSERT INTO editing SET member_id='$member_id', word_count='$word_count', page_quantity='$page_quantity', total_cost='$editing_cost', date=CURDATE(), purchased='no'"; $quote_id = mysql_insert_id(); add_item_to_cart('editing', $quote_id); return $quote_id; } function add_package_to_cart($isbn_assignment_submit, $digital_isbn_submit, $copyright_submit, $lccn_submit, $radio_interview_submit, $digital_marketing_material, $google_books_submit, $ingram_advantage_submit, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro, $retail_distribution_submit, $digital_distribution_submit, $total_cost, $custom_digital, $member_id, $recurring_value, $recurring_legnth_days, $discount_value = null) { // Add The package vars into the database // Validate the settings if ($total_cost [0] == '$') $total_cost = substr($total_cost, 1); if ($recurring_value [0] == '$') $recurring_value = substr($recurring_value, 1); if ($retail_distribution_submit < 2 && $ingram_advantage_submit == 1) $ingram_advantage_submit = 0; if ($google_books_submit == 1 && $digital_distribution_submit == 1) $google_books_submit = 0; if ($retail_distribution_submit > 0) $digital_marketing_material = 1; if ($digital_distribution_submit == 1 && !$custom_digital) { $kindle_distro = 1; $ipad_distro = 1; $googlebooks_distro = 1; $nook_distro = 1; } else if ($digital_distribution_submit == 0 && !$custom_digital) { $kindle_distro = 0; $ipad_distro = 0; $googlebooks_distro = 0; $nook_distro = 0; } if (!$eckobooks_distro) $eckobooks_distro = 1; if (!$discount_value) $discount_value = '0.00'; mysql_select_db(eckopub_publishingquotes); $query = mysql_query("INSERT INTO member_package_v2 SET isbn='$isbn_assignment_submit', isbn_digital='$digital_isbn_submit', copyright='$copyright_submit', lccn='$lccn_submit', radio_show='$radio_interview_submit', digital_marketing_material='$digital_marketing_material', google_books_listing='$google_books_submit', ingram_advantage='$ingram_advantage_submit', kindle_distro='$kindle_distro', ipad_distro='$ipad_distro', googlebooks_distro='$googlebooks_distro', nook_distro='$nook_distro', eckobooks_distro='$eckobooks_distro', retail_distro='$retail_distribution_submit', total_cost='$total_cost', purchased='no', date=CURDATE(), member_id='$member_id', discount_value='$discount_value', recurring_value='$recurring_value', recurring_legnth_days='$recurring_legnth_days'") or die(mysql_error()); $quote_id = mysql_insert_id(); add_item_to_cart('member_package_v2', $quote_id); return $quote_id; } function add_item_to_cart($type, $quote_id) { global $member_id; global $sid; mysql_select_db(eckopub_shopping); mysql_query("INSERT INTO cart_publishing VALUES('','$sid','$type','$quote_id','$member_id',CURDATE())"); } function add_package_retail_interperter($retail_distro) { // Converts the // retail_disto from // the publishing // quotes into the // actual values // needed for the // final database if ($retail_distro == 0) { $amazon_distro = 0; $pod_northamerica = 0; $pod_uk = 0; $pod_europe = 0; $pod_australia = 0; } else if ($retail_distro == 1) { $amazon_distro = 1; $pod_northamerica = 0; $pod_uk = 0; $pod_europe = 0; $pod_australia = 0; $qualified_discount_level = 1; } else if ($retail_distro == 2) { $amazon_distro = 0; $pod_northamerica = 1; $pod_uk = 0; $pod_europe = 0; $pod_australia = 0; $qualified_discount_level = 1; } else if ($retail_distro == 3) { $amazon_distro = 0; $pod_northamerica = 1; $pod_uk = 1; $pod_europe = 1; $pod_australia = 1; $qualified_discount_level = 1; } $results = array('amazon_distro' => "$amazon_distro", 'pod_northamerica' => "$pod_northamerica", 'pod_uk' => "$pod_uk", 'pod_europe' => "$pod_europe", 'pod_australia' => "$pod_australia", 'qualified_discount_level' => "$qualified_discount_level"); return $results; } function add_package_to_purchased_services($isbn_assignment, $isbn_digital, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $ingram_advantage, $amazon_distro, $pod_distro_northamerica, $pod_distro_uk, $pod_distro_europe, $pod_distro_australia, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro, $qualified_discount_level, $total_cost, $order_id, $member_id, $recurring_payment_value, $recurring_payment_days) { $package_verification = package_verification($isbn_assignment, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $ingram_advantage, $amazon_distro, $pod_distro_northamerica, $pod_distro_uk, $pod_distro_europe, $pod_distro_australia, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro); $isbn_assignment = $package_verification ['isbn_assignment']; $copyright = $package_verification ['copyright']; $lccn = $package_verification ['lccn']; $radio_interview = $package_verification ['radio_interview']; $digital_marketing_material = $package_verification ['digital_marketing_material']; $google_books = $package_verification ['google_books']; $amazon_distro = $package_verification ['amazon_distro']; $pod_distro_northamerica = $package_verification ['pod_distro_northamerica']; $pod_distro_uk = $package_verification ['pod_distro_uk']; $pod_distro_europe = $package_verification ['pod_distro_europe']; $pod_distro_australia = $package_verification ['pod_distro_australia']; $ingram_advantage = $package_verification ['ingram_advantage']; $kindle_distro = $package_verification ['kindle_distro']; $ipad_distro = $package_verification ['ipad_distro']; $googlebooks_distro = $package_verification ['googlebooks_distro']; $nook_distro = $package_verification ['nook_distro']; $eckobooks_distro = $package_verification ['eckobooks_distro']; $package_error = $package_verification ['package_error']; mysql_select_db(eckopub_members); $query = mysql_query("INSERT INTO v2_member_package SET isbn='$isbn_assignment', isbn_digital='$isbn_digital', copyright='$copyright', lccn='$lccn', radio_show='$radio_interview', digital_marketing_material='$digital_marketing_material', google_books_listing='$google_books', eckobooks_distro='$eckobooks_distro', amazon_distro='$amazon_distro', pod_distro_northamerica='$pod_distro_northamerica', pod_distro_uk='$pod_distro_uk', pod_distro_europe='$pod_distro_europe', pod_distro_australia='$pod_distro_australia', ingram_advantage='$ingram_advantage', kindle_distro='$kindle_distro', ipad_distro='$ipad_distro', googlebooks_distro='$googlebooks_distro', nook_distro='$nook_distro', total_billed='$total_cost', creation_date=CURDATE(), member_id='$member_id', order_id='$order_id', package_status='1'") or die(mysql_error()); $package_id = mysql_insert_id(); if ($recurring_payment_value > 0 && $recurring_payment_days) { if (!$recurring_payment_days) $recurring_payment_days = '350'; $trans_details = get_transaction_id_and_cardinfo_from_order_id($order_id); $creditcard_id = add_credit_card_to_storage($member_id, $trans_details ['transaction_id'], $trans_details ['cc_type'], $trans_details ['cc_exp_mon'], $trans_details ['cc_exp_year'], $trans_details ['last_four_digits']); $next_due_payment = date('Y-m-d', strtotime("$recurring_payment_days days")); mysql_select_db(eckopub_members); mysql_query("INSERT INTO v2_member_recurring_payments SET member_id='$member_id',package_id='$package_id',amount='$recurring_payment_value',recurring_legnth_days='$recurring_payment_days',next_due_payment='$next_due_payment',creditcard_id='$creditcard_id'") or die(mysql_error()); } $results = array('package_id' => "$package_id", 'package_error' => "$package_error"); return $results; } function add_credit_card_to_storage($member_id, $transaction_id, $cc_type, $cc_exp_mon, $cc_exp_year, $last_four_digits) { mysql_select_db(eckopub_members); $query = mysql_query("SELECT creditcard_id FROM v2_member_credit_card_storage WHERE member_id='$member_id' AND cc_exp_mon='$cc_exp_mon' AND cc_exp_year='$cc_exp_year' AND last_four_digits='$last_four_digits'") or die(mysql_error()); if (!mysql_numrows($query)) { // Add To List mysql_query("INSERT INTO v2_member_credit_card_storage SET member_id='$member_id', orig_transaction_id='$transaction_id', latest_transaction_id='$transaction_id', cc_type='$cc_type', cc_exp_mon='$cc_exp_mon', cc_exp_year='$cc_exp_year', last_four_digits='$last_four_digits', date_added=CURDATE()"); $card_database_id = mysql_insert_id(); } else { list ($card_database_id) = mysql_fetch_row($query); mysql_query("UPDATE v2_member_credit_card_storage SET latest_transaction_id='$transaction_id' WHERE unique_id='$card_database_id'"); } return $card_database_id; } function get_transaction_id_and_cardinfo_from_order_id($order_id) { mysql_select_db(eckopub_shopping) or die("Unable to select database (3)"); $query = mysql_query("SELECT transaction_id, cc_type, cc_exp_mon, cc_exp_year, last_four_digits FROM payment_details WHERE order_id='$order_id'"); list ($transaction_id, $cc_type, $cc_exp_mon, $cc_exp_year, $last_four_digits) = mysql_fetch_row($query); $results = array('transaction_id' => "$transaction_id", 'cc_type' => "$cc_type", 'cc_exp_mon' => "$cc_exp_mon", 'cc_exp_year' => "$cc_exp_year", 'last_four_digits' => "$last_four_digits"); return $results; } function package_verification($isbn_assignment, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $ingram_advantage, $amazon_distro, $pod_distro_northamerica, $pod_distro_uk, $pod_distro_europe, $pod_distro_australia, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro) { // This function verifies the selected settings and changes them // accordingly. if ($amazon_distro == 1) { $ingram_advantage = 0; $error = 'yes'; } if ($googlebooks_distro == 1) { $google_books = 0; $error = 'yes'; } if ($amazon_distro == 1 && $pod_distro_northamerica == 1) { $amazon_distro = 1; $error = 'yes'; } if ($isbn_assignment == 2 && $lccn == 1) { $lccn = 0; $error = 'yes'; } $results = array("isbn_assignment" => "$isbn_assignment", "copyright" => "$copyright", "lccn" => "$lccn", "radio_interview" => "$radio_interview", "digital_marketing_material" => "$digital_marketing_material", "google_books" => "$google_books", "amazon_distro" => "$amazon_distro", "pod_distro_northamerica" => "$pod_distro_northamerica", "pod_distro_uk" => "$pod_distro_uk", "pod_distro_europe" => "$pod_distro_europe", "pod_distro_australia" => "$pod_distro_australia", "ingram_advantage" => "$ingram_advantage", "kindle_distro" => "$kindle_distro", "ipad_distro" => "$ipad_distro", "googlebooks_distro" => "$googlebooks_distro", "nook_distro" => "$nook_distro", "eckobooks_distro" => "$eckobooks_distro", 'package_error' => "$error"); return $results; } function update_membership_package($isbn_assignment, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $ingram_advantage, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro, $retail_distribution, $digital_distribution, $total_cost, $custom_digital, $member_id) { } function assign_isbn_number_to_package($package_id, $member_id, $isbn_type_db) { // See if there is an ISBN assigned to the package mysql_select_db(eckopub_members) or die("Unable to select database (1)"); // First see what this client should get. $query_isbn_types = mysql_query("SELECT isbn, isbn_digital FROM v2_member_package WHERE package_id='$package_id' AND member_id='$member_id'"); list ($isbn, $isbn_digital) = mysql_fetch_row($query_isbn_types); if ($isbn == 1) { // If they get a retail ISBN, either assign it OR grab it. $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_member_id='$member_id' AND assigned_package_id='$package_id' AND assignment_type='1'"); if (mysql_numrows($query)) list ($retail_isbn_number) = mysql_fetch_row($query); else { mysql_query("UPDATE package_isbn_numbers SET assigned_member_id='$member_id', assigned_package_id='$package_id', assignment_type='1', date_assigned=CURDATE() WHERE assigned_member_id = '' AND assigned_package_id='' ORDER BY unique_id ASC LIMIT 1"); $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$package_id' AND assigned_member_id='$member_id' AND assignment_type='1'"); list ($retail_isbn_number) = mysql_fetch_row($query); } } if ($isbn_digital == 1) { // If they get a digital ISBN, either assign it OR // grab it. $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_member_id='$member_id' AND assigned_package_id='$package_id' AND assignment_type='2'"); if (mysql_numrows($query)) list ($digital_isbn_number) = mysql_fetch_row($query); else { mysql_query("UPDATE package_isbn_numbers SET assigned_member_id='$member_id', assigned_package_id='$package_id', assignment_type='2', date_assigned=CURDATE() WHERE assigned_member_id = '' AND assigned_package_id='' ORDER BY unique_id ASC LIMIT 1"); $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_package_id='$package_id' AND assigned_member_id='$member_id' AND assignment_type='2'"); list ($digital_isbn_number) = mysql_fetch_row($query); } } if ($isbn == 2) { $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_member_id='$member_id' AND assigned_package_id='$package_id' AND assignment_type='1'"); if (mysql_numrows($query)) list ($retail_isbn_number) = mysql_fetch_row($query); } if ($isbn_digital == 2) { $query = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_member_id='$member_id' AND assigned_package_id='$package_id' AND assignment_type='2'"); if (mysql_numrows($query)) list ($digital_isbn_number) = mysql_fetch_row($query); } if ($isbn_type_db == 1) $isbn_number = $retail_isbn_number; else $isbn_number = $digital_isbn_number; return $isbn_number; } function calculate_currency_to_usd($amount, $currency_type) { mysql_select_db(eckopub_misc) or die("Unable to select database(11)"); $currency_type = strtolower($currency_type); $query = mysql_query("SELECT $currency_type, date_updated FROM currency_exchange_rate WHERE id=1"); list ($exchange_rate, $date_updated) = mysql_fetch_row($query); $exchange_value = number_format($amount * $exchange_rate, 2, '.', ''); $status = "$currency_type / $exchange_rate / $date_updated"; $results = array('exchange_value' => $exchange_value, 'date_updated' => $date_updated, 'stat' => "$status"); return $results; } // Checks to see if there are current vars attached to the URL and returns the // proper URL to add more to it function url_add_get_to($url) { if (!strpos($url, '?')) $url = $url . "?get=blank"; return $url; } function reset_pod_information($package_id, $member_id) { // Verify it is not locked. mysql_select_db(eckopub_members) or die("Unable to select database (5)"); $query = mysql_query("SELECT locked FROM v2_package_pod_distro WHERE package_id='$package_id' AND member_id='$member_id'"); list ($locked) = mysql_fetch_row($query); if ($locked == 0) { mysql_query("DELETE FROM v2_package_pod_distro WHERE package_id='$package_id' AND member_id='$member_id'"); $success = 'yes'; } else $success = 'no'; return $success; v2_package_status_change_entry($package_id, 'pod_distro', 'rem'); } function reset_digital_information($package_id, $member_id) { // Verify it is not locked. mysql_select_db(eckopub_members) or die("Unable to select database (5)"); $query = mysql_query("SELECT locked FROM v2_package_digital_distro WHERE package_id='$package_id' AND member_id='$member_id'") or die(mysql_error()); list ($locked) = mysql_fetch_row($query); if ($locked == 0) { mysql_query("DELETE FROM v2_package_digital_distro WHERE package_id='$package_id' AND member_id='$member_id'"); $success = 'yes'; } else $success = 'no'; return $success; v2_package_status_change_entry($package_id, 'digital_distro', 'rem'); } function v2_package_status_change_entry($package_id, $status_for, $status_change) { global $member_package_status_for_numbers_array; $status_for = array_search($status_for, $member_package_status_for_numbers_array); mysql_select_db(eckopub_members) or die("Unable to select database (5)"); $query = mysql_query("INSERT INTO v2_package_status_changes SET package_id='$package_id', status_for='$status_for', status_change='$status_change'"); } function v2_update_current_status($status, $database_name, $package_id = null, $member_id = null) { if (!$member_id) global $member_id; if (!$package_id) global $package_id; mysql_select_db(eckopub_members) or die("Unable to select database (5)"); $query = mysql_query("UPDATE $database_name SET status='$status' WHERE package_id='$package_id' AND member_id='$member_id'"); } function verify_date_is_future($date) { $current_date = strtotime(date('Y-m-d')); $date = strtotime($date); if ($current_date < $date) $result = 'pass'; else $result = 'fail'; return $result; } function member_id_from_package_id_v2($package_id) { mysql_select_db(eckopub_members) or die("Unable to select database (1)"); $query = mysql_query("SELECT member_id FROM v2_member_package WHERE package_id='$package_id'"); list ($member_id) = mysql_fetch_row($query); return $member_id; } function check_package_service_status($database_name, $package_id = null, $member_id = null) { if (!$member_id) global $member_id; if (!$package_id) global $package_id; mysql_select_db(eckopub_members) or die(mysql_error()); $query = mysql_query("SELECT status FROM $database_name WHERE package_id='$package_id' AND member_id='$member_id'"); if (!mysql_numrows($query)) $result = 0; else list ($result) = mysql_fetch_row($query); return $result; } function verify_purchased_service($service_type, $package_id = null, $member_id = null) { // In the database, 0=Not Purchase 1=Is Purchase if (!$member_id) global $member_id; if (!$package_id) global $package_id; mysql_select_db(eckopub_members) or die(mysql_error()); $query = mysql_query("SELECT $service_type FROM v2_member_package WHERE package_id='$package_id' AND member_id='$member_id'"); list ($result) = mysql_fetch_row($query); return $result; } function verify_discount_applies() { global $sid; global $member_id; $member_discount_level = 0; mysql_select_db(eckopub_shopping) or die("Unable to select database :: " . $_SERVER ["SCRIPT_NAME"]); $query_member_cart = mysql_query("SELECT quote_id FROM cart_publishing WHERE sid='$sid' AND type='member_package_v2'"); $count_member_cart = mysql_numrows($query_member_cart); if ($count_member_cart > 0) { // See if the membership qualifies for discount while (list ($quote_id) = mysql_fetch_row($query_member_cart)) { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database :: " . $_SERVER ["SCRIPT_NAME"]); $query_membership_package = mysql_query("SELECT retail_distro FROM member_package_v2 WHERE quote_id='$quote_id'"); list ($retail_distro) = mysql_fetch_row($query_membership_package); if ($retail_distro > 0) { $member_discount_level = 1; } } } if ($member_id) { $set_qualified_discount_level = 0; mysql_select_db(eckopub_members) or die("Unable to select database :: " . $_SERVER ["SCRIPT_NAME"]); $query = mysql_query("SELECT qualified_discount_level FROM v2_member_package WHERE member_id='$member_id'"); while (list ($qualified_discount_level) = mysql_fetch_row($query)) { if ($qualified_discount_level > $set_qualified_discount_level) $set_qualified_discount_level = $qualified_discount_level; } } if ($member_discount_level > $set_qualified_discount_level) $discount_level = $member_discount_level; return $discount_level; } function total_bill() { include "_quotes/product_rates.inc"; $coupon = $_SESSION ['coupon']; $sid = $_SESSION ['session_id']; // $discount_level = verify_discount_applies (); mysql_select_db(eckopub_shopping) or die("Unable to select database (2)"); $query_pub_cart = mysql_query("SELECT quote_id, type FROM cart_publishing WHERE sid='$sid'"); while (list ($quote_id, $type) = mysql_fetch_row($query_pub_cart)) { $jsonProductList['productList'][$type] = $quote_id; if ($type == 'editing') { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); $query_cost = mysql_query("SELECT word_count FROM $type WHERE quote_id='$quote_id'"); $query_cost_object = mysql_fetch_object($query_cost); $word_count = "$query_cost_object->word_count"; $calculate_editing_cost = calculate_editing_cost($word_count); $total_cost = $calculate_editing_cost ['editing_cost']; // $total_cost_member = $calculate_editing_cost ['editing_cost']; /* * if ($discount_level > 0) $discount_value = $total_cost - $total_cost_member; else $discount_value = 0; */ $total_after_discount = number_format($total_cost, 2, '.', ''); } else if ($type == 'printing') { $bill_total = 'yes'; include_once '_quotes/printing_quote_function.inc'; include_once '_quotes/printing_quote_total.inc'; $printing_total_array = printing_total($quote_id); $final_total = $printing_total_array ["final_total"]; $shipping_total = $printing_total_array ["shipping"]; $total_after_discount = number_format($final_total + $shipping_total, 2, '.', ''); } else if ($type == 'printing_v2') { $bill_total = 'yes'; mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); $query_cost = mysql_query("SELECT quantity,cpb,shipping_total FROM printing_v2 WHERE quote_id='$quote_id' AND purchased='no'"); list ($quantity, $cpb, $shipping_total) = mysql_fetch_row($query_cost); $final_total = number_to_money_format($cpb * $quantity); $total_after_discount = number_to_money_format($final_total + $shipping_total); } else if ($type == 'interior_layout') { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); $query_cost = mysql_query("SELECT total_cost, layout_type FROM interior_layout WHERE quote_id='$quote_id' AND purchased='no'"); list ($total_cost, $layout_type) = mysql_fetch_row($query_cost); /* * if ($discount_level > 0) { if ($layout_type == 'Basic') $total_after_discount = $pricing_design_interior_basic ['member']; else if ($layout_type == 'Advanced') $total_after_discount = $pricing_design_interior_advanced ['member']; } else */ $total_after_discount = $total_cost; } else if ($type == 'cover_design') { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); $query_cost = mysql_query("SELECT total_cost, package FROM cover_design WHERE quote_id='$quote_id' AND purchased='no'"); list ($total_cost, $package_type) = mysql_fetch_row($query_cost); $discount_value = number_format($total_cost * $discount_cover, 2, '.', ''); /* * if ($discount_level > 0) { if ($package_type == 'Basic') $total_after_discount = $pricing_design_cover_basic ['member']; else if ($package_type == 'Advanced') $total_after_discount = $pricing_design_cover_advanced ['member']; } else */ $total_after_discount = $total_cost; } else if ($type == 'member_package_v2') { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); $query_cost = mysql_query("SELECT total_cost FROM member_package_v2 WHERE quote_id='$quote_id' AND purchased='no'"); list ($total_after_discount) = mysql_fetch_row($query_cost); } // mysql_query ( "UPDATE $type SET // total_after_discount='$total_after_discount' WHERE // quote_id='$quote_id'" ); $final_cost = number_format($final_cost + $total_after_discount, 2, '.', ''); } // $array_1 = array ('QuoteID' => "$add1", 'Type' => "$add2", '3' => // "$add3", 'sid' => "$sid", 'bill_total' => "$total_after_discount" ); // return $array_1; if ($coupon) { $coupon_function = coupon_function($coupon, $final_cost, ''); $coupon_successful = $coupon_function ['successful']; if ($coupon_successful) { $final_cost = $coupon_function ['new_total']; $coupon_saved = $coupon_function ['discount_saved']; } } $results = array('final_cost' => $final_cost, 'coupon_successful' => $coupon_successful, 'coupon_saved' => $coupon_saved, 'jsonProductList' => $jsonProductList); return $results; } // Creates the Member account function create_member_account($first_name, $last_name, $address1, $address2, $city, $state, $zip, $country, $phone, $email, $order_id, $username, $password, $sid, $ip_record) { if ($password) { $password_display = $password; $password = md5($password); } else { $password_func = RandomPassword(); $password_display = $password_func ['password_display']; $password = $password_func ['password_enc']; } // Verfiy username is not alerady taken $check_username_exist = check_username_exist($username); if ($check_username_exist != 0) { $username = create_temp_username_from_duplicate($username); $notification = "The requested username was not available. A random username was created based on your information. This can be changed by you in your members area or by customer service. The current username is $username"; } $first_name = mysql_real_escape_string($first_name); $last_name = mysql_real_escape_string($last_name); $address1 = mysql_real_escape_string($address1); $address2 = mysql_real_escape_string($address2); $city = mysql_real_escape_string($city); $zip = mysql_real_escape_string($zip); $phone = mysql_real_escape_string($phone); $email = mysql_real_escape_string($email); $username_safe = clean_username($username); $username_disp = $username; $username = mysql_real_escape_string($username); $username_safe = mysql_real_escape_string($username_safe); mysql_select_db(eckopub_members) or die("Unable to select database (4)"); mysql_query("INSERT INTO member_data SET member_username='$username',member_username_safe='$username_safe',member_password='$password',member_signup_date=CURDATE(),member_last_login_attempt=NOW(),member_first_name='$first_name',member_last_name='$last_name',member_address1='$address1',member_address2='$address2',member_city='$city',member_state='$state',member_zip='$zip',member_country='$country',member_phone='$phone',member_email='$email',order_id_created='$order_id'") or die(mysql_error()); $member_id = mysql_insert_id(); mysql_query("INSERT INTO member_sessions VALUES('$sid','$member_id','$ip_record')"); $results = array('member_id' => "$member_id", 'username' => "$username_disp", 'username_safe' => "$username_safe", 'password_display' => "$password_display", 'notification' => "$notification"); return $results; } // Checks to see if the username is avaliable function check_username_exist($username) { // Do not submit the safe username // since the function cleans it. mysql_select_db(eckopub_members) or die("Unable to select database (4)"); $username_safe = clean_username($username); $count = mysql_num_rows(mysql_query("SELECT member_username FROM member_data WHERE member_username_safe='$username_safe'")); return $count; } // Creates a new username from entered username and adds random characters function create_temp_username_from_duplicate($username) { // Assuming the // original already // tested the username $found = 'no'; while ($found != 'yes') { $random = random_gen(5); $username = $username . $random; $check_username_exist = check_username_exist($username); if ($check_username_exist == 0) $found = 'yes'; } return $username; } function update_member_username($member_id, $username) { $check_username_exist = check_username_exist($username); if ($check_username_exist == 0 && $member_id) { $username_safe = clean_username($username); $username_safe = mysql_real_escape_string($username_safe); $username = mysql_real_escape_string($username); mysql_select_db(eckopub_members) or die("Unable to select database (4)"); mysql_query("UPDATE member_data SET member_username='$username', member_username_safe='$username_safe' WHERE member_id='$member_id'") or die(mysql_error()); $status = 'success'; } else $status = 'fail'; $results = array('username_safe' => "$username_safe", 'status' => "$status"); return $results; } function update_member_password($member_id, $password) { $password = md5($password); mysql_select_db(eckopub_members) or die("Unable to select database (4)"); mysql_query("UPDATE member_data SET member_password='$password' WHERE member_id='$member_id'") or die(mysql_error()); } function get_member_id_from_service_id($service_id) { mysql_select_db(eckopub_memberservices) or die("Unable to select database (1)"); $query = mysql_query("SELECT member_id FROM purchased_services WHERE service_id='$service_id'"); list ($member_id) = mysql_fetch_row($query); return $member_id; } function reset_isbn_to_available($isbn, $remove_isbn_data, $disable_assignment) { mysql_select_db(eckopub_members) or die("Unable to select database (4)"); // Verify the ISBN number is ECKO House Number $isbn_short = substr($isbn, 0, 10); if ($isbn_short != '978-1-4276') { $message .= "The ISBN Number Entered Is Not An ECKO Number"; } else { $query = mysql_query("SELECT unique_id, assigned_member_id, assigned_package_id, assignment_type FROM package_isbn_numbers WHERE assigned_member_id!='' AND assigned_package_id!='' AND isbn='$isbn'"); if (mysql_numrows($query) != 1) $message .= "The ISBN Entered Either Does Not Exist OR IS Not Registered."; } if (!$error) { list ($unique_id, $assigned_member_id, $assigned_package_id, $assignment_type) = mysql_fetch_row($query); mysql_query("UPDATE package_isbn_numbers SET assigned_member_id='', assigned_package_id='', assignment_type='1', date_assigned='' WHERE isbn='$isbn' LIMIT 1"); if ($disable_assignment == 'yes') { $query_package = mysql_query("SELECT isbn, isbn_digital FROM v2_member_package WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id'"); list ($package_isbn_retail, $package_isbn_digital) = mysql_fetch_row($query_package); if (($package_isbn_retail == 1 && $package_isbn_digital == 0) || ($package_isbn_retail == 0 && $package_isbn_digital == 1)) { mysql_query("DELETE FROM v2_package_isbn_registry_data WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id' LIMIT 1"); mysql_query("UPDATE v2_member_package SET isbn='0', isbn_digital='0' WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id'"); } else if ($package_isbn_retail == 1 && $package_isbn_digital == 1) { if ($assignment_type == 1) $sql_selection = 'isbn'; else $sql_selection = 'isbn_digital'; mysql_query("UPDATE v2_member_package SET $sql_selection='0' WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id'"); $query_alt_isbn = mysql_query("SELECT isbn FROM package_isbn_numbers WHERE assigned_member_id='$assigned_member_id' AND assigned_package_id='$assigned_package_id'"); list ($isbn_alt) = mysql_fetch_row($query_alt_isbn); $message .= "The package that owned this ISBN still has another ISBN assigned (likley for the other distribution service. The ISBN is $isbn_alt
"; } } else if ($remove_isbn_data == 'yes') { mysql_query("DELETE FROM v2_package_isbn_registry_data WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id' LIMIT 1") or die(mysql_error()); $message .= "Removing ISBN Registry Data--DELETE FROM v2_package_isbn_registry_data WHERE package_id='$assigned_package_id' AND member_id='$assigned_member_id' LIMIT 1--"; } $query = mysql_query("SELECT unique_id FROM package_isbn_numbers WHERE assigned_member_id='' AND assigned_package_id='' AND assignment_type='1' AND isbn='$isbn'"); if (mysql_numrows($query) == 1) $message .= "ISBN SUCCESSFULLY RESET"; else $message .= "ISBN WAS NOT ABLE TO BE REST - PLEASE VERIFY INFORMATION"; } return $message; } function clean_creditcard_number($ccn) { $ccn = str_replace(' ', '', $ccn); $ccn = str_replace('-', '', $ccn); $ccn = str_replace('-', '', $ccn); $ccn = str_replace('o', '0', $ccn); return $ccn; } function eckobooks_listing_url_from_isbn($isbn) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_eckobook_primary, $mysql_connect_eckobook_primary_password) or die(mysql_error()); mysql_select_db(eckobook_listings) or die("Unable to select database"); // Grab ID for ISBN Ident $query_isbn_ident = mysql_query("SELECT identifier_id FROM product_identifier WHERE identifier_name='ISBN'"); list ($identifier_id) = mysql_fetch_row($query_isbn_ident); $query_listing = mysql_query("SELECT product_id, title FROM product_listings WHERE identifier='$isbn' AND identifier_type='$identifier_id'") or die(mysql_error()); if (mysql_numrows($query_listing)) { list ($product_id, $title) = mysql_fetch_row($query_listing); $title_link = url_title_clean($title); $product_link = "http://www.eckobooks.com/product/$product_id/$title/"; $success = 'yes'; } else $success = 'no'; $results = array('success' => "$success", 'product_link' => "$product_link"); return $results; } function isbn_by_package_id_v2($package_id) { // This function will return two // ISBN Numbers (one for retail / // one for digital)if available include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_members) or die("Unable to select database (98)"); $query = mysql_query("SELECT isbn, assignment_type FROM package_isbn_numbers WHERE assigned_package_id='$package_id'"); $count = mysql_numrows($query); if ($count == 1) { list ($isbn, $assignment_type) = mysql_fetch_row($query); if ($assignment_type == '1') $retail_isbn = $isbn; else if ($assignment_type == '2') $digital_isbn = $isbn; } else if ($count == 2) { while (list ($isbn, $assignment_type) = mysql_fetch_row($query)) { if ($assignment_type == '1') $retail_isbn = $isbn; else if ($assignment_type == '2') $digital_isbn = $isbn; } } $results = array('retail_isbn' => "$retail_isbn", 'digital_isbn' => "$digital_isbn"); return $results; } function number_to_money_format($total) { $total = number_format($total, 2, '.', ''); return $total; } function last_day_of_month($month, $year) { if (!$month) $month = date('m'); if (!$year) $year = date('Y'); $result = strtotime("{$year}-{$month}-01"); $result = strtotime('-1 second', strtotime('+1 month', $result)); return date('Y-m-d', $result); } function days_in_month($month, $year) { $lastday = date('t', strtotime("$month/1/$year")); return $lastday; } function create_coupon_code($vars) { //create_coupon_code(array('note_customer'=>$noteCustomer,'active'=>'1','single_use'=>'1','expires_on'=>'60','value'=>'20','value_type'=>'2')); mysql_select_db(eckopub_shopping); $user_id = $vars ['user_id']; $note_customer = $vars ['note_customer']; $note_admin = $vars ['note_admin']; $active = $vars ['active']; //1=Active,2=Inactive $verification_type = $vars ['verification_type']; //Custom Coded Verification Type $single_use = $vars ['single_use']; //1=One Time,2=Multiple Times $expires_on = $vars ['expires_on']; //Full YMD or In X Days $min_total_order = $vars ['min_total_order']; //Is there a minium value to the order required $value = $vars ['value']; //Percentage(15) or dollar value(22.50) $value_type = $vars ['value_type']; //1=Dollar Value,2=Percentage $code = $vars ['code']; //The Actual Code To Use - Leave Blank For Automated Code ID if ($code) { $query_code_good = mysql_query("SELECT unique_id FROM coupon_code WHERE code='$code'"); if (mysql_numrows($query_code_good)) $error = 'existing code'; } if (!$code) { while (!$code_approved) { $code = random_gen('7'); $query_code_good = mysql_query("SELECT unique_id FROM coupon_code WHERE code='$code'"); if (!mysql_numrows($query_code_good)) $code_approved = 'yes'; } } if (strlen($expires_on) <= 4) $expires_on = date('Y-m-d', strtotime("+$expires_on days", strtotime(date('Y-m-d')))); if ($error) { $result = array('failed' => true, 'error' => $error); } else { $query = mysql_query("INSERT INTO coupon_code SET code='$code',value_type='$value_type',value='$value',min_total_order='$min_total_order',added_on=CURDATE(),expires_on='$expires_on',single_use='$single_use',verification_type='$verification_type',active='$active',note_admin='$note_admin',note_customer='$note_customer',times_entered='0',user_id='$user_id'"); $result = array('failed' => false, 'code' => $code); } return $result; } function cleanHtmlV2($str, $vars = null) { // BR Fix $str = str_ireplace('
', '
', $str); if ($vars ['clean_br']) { $str = str_replace('
', ' ', $str); $str = str_replace('
', ' ', $str); $str = str_replace('
', ' ', $str); } $str = str_replace('�', '-', $str); $str = str_replace('�', '"', $str); $str = str_replace('�', '"', $str); $str = str_replace('�', ''', $str); $str = str_replace('�', '', $str); if ($vars ['strip_tags_full']) { if ($vars ['keep_tags']) $extra_tags = $vars ['keep_tags']; $str = strip_tags($str, "

$extra_tags"); } $str = str_replace('�', ' ', $str); $str = str_replace('\\', '', $str); if ($vars ['strip_classes']) $str = preg_replace('/class=".*"/i', '', $str); $config = array('input-encoding' => mb_detect_encoding($str), 'output-encoding' => 'utf8', 'vertical-space' => false, 'wrap' => '0', 'indent' => true, 'output-html' => true, 'show-body-only' => true, 'bare' => true, 'clean' => true, 'doctype' => 'omit', 'drop-empty-paras' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'enclose-block-text' => true, 'enclose-text' => true, 'quote-marks' => true, 'word-2000' => true); $tidy = new tidy (); $tidy->parseString($str, $config, 'utf8'); $tidy->cleanRepair(); $str = tidy_get_output($tidy); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); $str = str_replace(' ', ' ', $str); // # tags fix if (!$vars ['#tagFix']) { if (strpos($str, '

' . PHP_EOL . ' #') !== false) { // Extra Space // Fix $str = str_replace('

' . PHP_EOL . ' #', '

' . PHP_EOL . '#', "$str"); } // Remove p tags if (strpos($str, '

' . PHP_EOL . '#') !== false && strpos($str, '#' . PHP_EOL . '

') !== false) { $str = str_replace('

' . PHP_EOL . '#', '#', $str); $str = str_replace('#' . PHP_EOL . '

', '#', $str); } } return $str; } function fullNameSplit($name) { list ($firstName, $lastName) = preg_split('/\s+(?=[^\s]+$)/', $name, 2); return array('firstName' => $firstName, 'lastName' => $lastName); } // Form Generation Functions // Generate a dropdown list and if applicaple select the current option function dropdown_from_array($vars) { $array_name = $vars ['array_name']; $currently_selected = $vars ['currently_selected']; $forn_name = $vars ['forn_name']; $form_id = $vars ['form_id']; $add_ignore_field = $vars ['add_ignore_field']; $js_function = $vars ['js_function']; if ($form_id) $form_id = " id=\"$form_id\""; if ($js_function) $js_function = " $js_function"; $res .= ""; return $res; } function dropdownFromArrayV2($vars) { //dropdownFromArrayV2(array('array_name'=>$array_name,'currently_selected'=>$currently_selected,'form_name'=>$form_name,'form_id'=>$form_id)); $array_name = $vars ['array_name']; $currently_selected = $vars ['currently_selected']; $form_name = $vars ['form_name']; $form_id = $vars ['form_id']; $add_ignore_field = $vars ['add_ignore_field']; $class = $vars ['class']; $js_function = $vars ['js_function']; if ($class) $class = " class=\"$class\""; if ($form_id) $form_id = " id=\"$form_id\""; if ($js_function) $js_function = " $js_function"; $res .= ""; return $res; } // Add new option to the dropdown field entried function dropdown_dabase_entries_add($database_name, $database_table, $new_value, $description = null, $percentage_based_discount = null) { mysql_selectdb($database_name); $new_value_clean = clean_string($new_value); $query = mysql_query("SELECT id FROM $database_table WHERE nameClean='$new_value_clean'"); if (!mysql_numrows($query)) { if ($description) { $description = mysql_real_escape_string($description); $description_sql = ", description='$description'"; } if ($percentage_based_discount) { $percentage_based_discount_sql = ", percentageBasedDiscount='$percentage_based_discount'"; } $new_value = mysql_real_escape_string($new_value); mysql_query("INSERT INTO $database_table SET name='$new_value', nameClean='$new_value_clean'$description_sql$percentage_based_discount_sql"); $result = "Option added to database"; } else $result = "Option NOT added to database. Usually because there is already an option for this."; $result .= " || INSERT INTO $database_table SET name='$new_value', nameClean='$new_value_clean'$description_sql"; return $result; } // Generate a dropdown list and if applicaple select the current option function dropdown_list_genereate($database_name, $database_table, $currently_selected = '0', $extra_js_functions = null, $add_ignore_field = null) { mysql_selectdb($database_name) or die(mysql_error()); if ($currently_selected == '0') unset($currently_selected); if ($extra_js_functions == 'show_dropdown_description') $extra_js = " onclick=\"dropdown_description('$database_table',this.value);return false;\""; $query = mysql_query("SELECT id, name FROM $database_table ORDER BY ID ASC") or die(mysql_error()); $res .= ""; return $res; } function create_a_box($vars) { //create_a_box(array('content'=>$content)); // $vars = width, height, content, float if (!$vars ['width']) $vars ['width'] = '962'; $width = $vars ['width'] . 'px'; if ($vars ['height']) $height = ' style="height:"' . $vars ['height'] . 'px;"'; $content = $vars ['content']; $float = $vars ['float']; $bx_container_styles = $vars ['bx_container_styles']; $box = <<
$content
box; if ($float) $box = "
" . $box . '
'; return $box; } function newsletterSignup($vars) { $firstName = ($vars['firstName']); $lastName = mysql_real_escape_string($vars['lastName']); $email = strtolower($vars['email']); include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db('eckopub_misc'); $email = mysql_real_escape_string($email); $query = mysql_query("SELECT id FROM newsletter_signup WHERE email='$email'"); if (!mysql_numrows($query)) { mysql_query("INSERT INTO newsletter_signup SET first_name='$firstName',last_name='$lastName',email='$email'"); return $added = true; } else return $added = false; } function newsletterSignupV2($vars) { $fullName = $vars['fullName']; $email = strtolower($vars['email']); $fullNameSplit = fullNameSplit($fullName); $firstName = $fullNameSplit['firstName']; $lastName = $fullNameSplit['lastName']; include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db('eckopub_misc'); $email = mysql_real_escape_string($email); $query = mysql_query("SELECT id,active FROM newsletter_signup WHERE email='$email'"); if (!mysql_numrows($query)) { mysql_query("INSERT INTO newsletter_signup SET first_name='$firstName',last_name='$lastName',email='$email'"); return $added = true; } else return $added = false; } function paymentErrors($vars) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_shopping) or die("Unable to select database (98)"); $checkout_error [] = "$PP_L_LONGMESSAGE0
$PP_L_SHORTMESSAGE0 ($PP_L_ERRORCODE0)"; mysql_query("INSERT INTO credit_card_purchase_errors SET correlation_id='$correlation_id',error_code='$error_code',"); //('$PP_CORRELATIONID','$PP_L_ERRORCODE0','$PP_L_LONGMESSAGE0','$PP_L_SEVERITYCODE0','$PP_L_ERRORPARAMVALUE0') } function addPaymentBitcoinTemp($vars) { //addPaymentBitcoinTemp(array('paymentAddress'=>$paymentAddress,'jsonProductList'=>$jsonProductList,'jsonOrderData'=>$jsonOrderData)); include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db(eckopub_shopping) or die("Unable to select database (98)"); $goodStr = false; while ($goodStr != true) { $btcPaymentId = randomStr(array('length' => '12', 'extended_salt' => true)); $query = mysql_query("SELECT sessionId FROM paymentBitcoinTemp WHERE id='$btcPaymentId'"); if (!mysql_numrows($query)) $goodStr = true; } if (!$vars['session_id']) $sessionId = mysql_real_escape_string($_SESSION['session_id']); else $sessionId = $vars['session_id']; $paymentAddress = mysql_real_escape_string($vars['paymentAddress']); $jsonProductList = mysql_real_escape_string($vars['jsonProductList']); $jsonOrderData = mysql_real_escape_string($vars['jsonOrderData']); mysql_query("INSERT INTO paymentBitcoinTemp SET orderCompleted='0',id='$btcPaymentId',sessionId='$sessionId',timeAdded=NOW(),paymentAddress='$paymentAddress',shoppingCart='$jsonProductList',orderData='$jsonOrderData'"); return $btcPaymentId; } function getConvertCurrentBitcoinPrice($vars) //getConvertCurrentBitcoinPrice(array('orderPrice'=>$orderPrice));//array('btcExchangePrice' => $btcExchangePrice, 'btcCost' => $btcCost); { $ticker = json_decode(file_get_contents('https://blockchain.info/ticker')); $btcExchangeRate = $ticker->USD->last; if (!$ticker) return false; if ($vars['orderPrice']) { //$btcCost = round($vars['orderPrice'] / $btcExchangeRate, 8); $btcCost = bcdiv($vars['orderPrice'], $btcExchangeRate, 8); // 16.007 } return array('btcExchangeRate' => $btcExchangeRate, 'btcCost' => $btcCost); } // Generates a random string function randomStr($vars = null) //randomStr(array('length'=>'12','extended_salt'=>true)); { if ($vars ['legnth']) $vars ['length'] = $vars ['legnth']; //Typo Fix if ($vars ['extened_salt']) $vars ['extended_salt'] = $vars ['extened_salt']; //Typo Fix if (!$vars ['length']) $length = 8; else $length = $vars ['length']; if ($vars ['extended_salt']) $salt = "abchefghjkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; else $salt = "abchefghjkmnpqrstuvwxyz123456789"; srand((double)microtime() * 1000000); $randomStr = null; $j = 0; while ($j < $length) { $num = rand() % strlen($salt); $randomStr .= substr($salt, $num, 1); $j++; } return $randomStr; } function checkBtcOrder($btcPaymentId) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db('eckopub_shopping') or die("Unable to select database (98)"); global $baseIncludeFolder; $btcPaymentId = mysql_real_escape_string($btcPaymentId); $query = mysql_query("SELECT orderCompleted,sessionId,timeAdded,paymentAddress,shoppingCart,orderData FROM paymentBitcoinTemp WHERE id='$btcPaymentId'") or die(mysql_error()); if (mysql_numrows($query) == 1) { list($orderCompleted, $sessionId, $timeAdded, $paymentAddress, $shoppingCart, $orderData) = mysql_fetch_row($query); if ($orderCompleted == 0) { $orderData = json_decode($orderData, true); include_once '/home/eckopub/_websiteFiles/bitcoinApi.inc'; $bitcoinResult = new Bitcoin('btcadmin57657', 'RYH456uyhHThtaRgjh6876UJTYu6'); $bitcoinResult->setSSL('/home/eckopub/ssl.cert'); $bitcoinResult->getreceivedbyaddress($paymentAddress, 0); if ($bitcoinResult->status == 200) { $bitcoinResult = $bitcoinResult->response; $walletValue = $bitcoinResult['result']; if ($walletValue >= $orderData['btcCost']) { //Complete The Order $orderCompleted = true; $orderData['timeStarted'] = $timeAdded; $orderData['timeCompleted'] = date("Y-m-d H:i:s"); $orderData['btcPaymentAddress'] = $paymentAddress; // return array('orderId' => $order_id, 'orderMessageDisp' => $checkout_content); $completeBtcOrder = completeBtcOrder($btcPaymentId); $orderCompletedMessage = $completeBtcOrder['orderMessageDisp']; // Unset The Sessions unset($_SESSION ['first_name']); unset($_SESSION ['last_name']); unset($_SESSION ['email']); unset($_SESSION ['email_verify']); unset($_SESSION ['phone']); unset($_SESSION ['address1']); unset($_SESSION ['address2']); unset($_SESSION ['city']); unset($_SESSION ['state']); unset($_SESSION ['zip']); unset($_SESSION ['country']); unset($_SESSION ['cc_type']); unset($_SESSION ['ccn']); unset($_SESSION ['exp_mon']); unset($_SESSION ['exp_yr']); unset($_SESSION ['ccvn']); unset($_SESSION ['first_name_bill']); unset($_SESSION ['last_name_bill']); unset($_SESSION ['phone_bill']); unset($_SESSION ['address1_bill']); unset($_SESSION ['address2_bill']); unset($_SESSION ['city_bill']); unset($_SESSION ['state_bill']); unset($_SESSION ['zip_bill']); unset($_SESSION ['country_bill']); unset($_SESSION ['checkout']); unset($_SESSION ['coupon']); $_SESSION ['purchase_complete'] = 'complete'; } else $error = ''; } else $error = 'Error retrieving payment information. If you sent the payment, please wait 30 minutes for a confirmation email. If you have not received the confirmation email after 30 minutes, plese contact us.'; } else $error = 'The Order Has Been Completed'; } else $error = 'Payment ID Not Found.'; return array('orderCompleted' => $orderCompleted, 'walletValue' => $walletValue, 'btcCost' => $orderData['btcCost'], 'error' => $error, 'message' => $orderCompletedMessage); } function completeBtcOrder($btcPaymentId) { include '/home/eckopub/db_pass.php'; mysql_connect($mysql_connect_location, $mysql_connect_primary_username, $mysql_connect_primary_password); mysql_select_db('eckopub_shopping') or die("Unable to select database (98)"); $queryBtcData = mysql_query("SELECT sessionId,timeAdded,paymentAddress,shoppingCart,orderData FROM paymentBitcoinTemp WHERE id='$btcPaymentId'"); list($sessionId, $timeAdded, $paymentAddress, $shoppingCartData, $orderData) = mysql_fetch_row($queryBtcData); $shoppingCartData = json_decode($shoppingCartData, true); $orderData = json_decode($orderData, true); mysql_query("DELETE FROM cart_publishing WHERE sid='$sessionId'"); foreach ($shoppingCartData['productList'] as $productType => $productQuoteId) { mysql_query("INSERT INTO cart_publishing SET sid='$sessionId',type='$productType',quote_id='$productQuoteId'"); } mysql_query("UPDATE paymentBitcoinTemp SET orderCompleted='1' WHERE id='$btcPaymentId'"); foreach ($orderData as $thisKey => $thisVal) { $$thisKey = $thisVal; } $first_name_disp = $first_name; $last_name_disp = $last_name; $email_disp = $email; // Update Purchase Database $sid = $sessionId; mysql_select_db(eckopub_shopping) or die("Unable to select database (6)"); // echo "$address1"; $first_name = mysql_real_escape_string($first_name); $last_name = mysql_real_escape_string($last_name); $address1 = mysql_real_escape_string($address1); $address2 = mysql_real_escape_string($address2); $city = mysql_real_escape_string($city); $zip = mysql_real_escape_string($zip); $phone = mysql_real_escape_string($phone); $email = mysql_real_escape_string($email); $first_name_bill = mysql_real_escape_string($first_name_bill); $last_name_bill = mysql_real_escape_string($last_name_bill); $address1_bill = mysql_real_escape_string($address1_bill); $address2_bill = mysql_real_escape_string($address2_bill); $city_bill = mysql_real_escape_string($city_bill); $zip_bill = mysql_real_escape_string($zip_bill); $phone_bill = mysql_real_escape_string($phone_bill); $payment_type = 'bitcoin'; $transaction_id = json_encode(array('btcPaymentAddress' => $paymentAddress, 'btcCost' => $btcCost, 'btcPaymentId' => $btcPaymentId)); $total_billed = $totalBilled; $total_cost = $total_billed; $totalCostBtc = $btcCost; $current_date = date('Y-m-d'); mysql_query("INSERT INTO payment_details SET member_id='$member_id',sid='$sid',token='$token',payment_type='$payment_type',transaction_id='$transaction_id', ip_address='$ip_record',total_billed='$total_billed',date_created='$current_date',first_name='$first_name',last_name='$last_name',email='$email',phone='$phone', address1='$address1',address2='$address2',city='$city',state='$state',zip='$zip',country='$country',bill_first_name='$first_name_bill', bill_last_name='$last_name_bill',bill_address1='$address1_bill',bill_address2='$address2_bill',bill_city='$city_bill',bill_state='$state_bill', bill_zip='$zip_bill',bill_country='$country_bill',bill_phone='$phone_bill',cc_type='$cc_type_db',cc_exp_mon='$cc_exp_mon',cc_exp_year='$cc_exp_year', last_four_digits='$last_four_digits',clickedAd='$clickedAd'") or die(mysql_error()); $order_id = mysql_insert_id(); // //////// if (!$member_username) { // Generate Member Login Area // Grab the contents for js_functions $temp_username = $order_id; $temp_username_safe = $order_id; $create_member_account = create_member_account($first_name, $last_name, $address1, $address2, $city, $state, $zip, $country, $phone, $email, $order_id, $temp_username, $password, $sid, $ip_record); $member_id = $create_member_account ['member_id']; $temp_username = $create_member_account ['username']; $temp_username_safe = $create_member_account ['username_safe']; $password_display = $create_member_account ['password_display']; mysql_select_db(eckopub_shopping) or die("Unable to select database (4)"); mysql_query("UPDATE payment_details SET member_id='$member_id' WHERE order_id='$order_id'") or die(mysql_error()); $_SESSION ['member_id'] = $member_id; $_SESSION ['member_username'] = $temp_username; $_SESSION ['member_username_safe'] = $temp_username_safe; $checkout_content .= "

Checkout Successful

Thank you for your order. Your order number is $order_id. A copy of your order information will be e-mailed to you. If you do not see it in your inbox, please check your spam/bulk folder. To begin, you will need to login to your account. Your temporary login details are below. The e-mail you receive will contain instructions on how to create a permanent login. Thank you for your order!

Temporary Username: $temp_username
Temporary password: $password_display

"; $order_new_member_email = "

It looks like this is your first order with ECKO Publishing. To manage your project(s), you will need to login at eckopublishing.com. Below are your temporary login details. To create permenent login details, go to https://www.eckopublishing.com/member/createaccount/ and create a personalized login now. Please use the temporary login details below when asked for them. PLEASE REMEMBER if you have already created your personalized login, the temporary login details below will not work.

Username: $temp_username
Password: $password_display
"; } else $checkout_content .= "

Checkout Successful

Thank you for your order. Your order number is $order_id. A copy of your order information will be e-mailed to you. If you do not see it in your inbox, please check your spam/bulk folder.

Click here to go to your members area now.

"; // Coupon Managment if ($coupon_successful) { // Insert the coupon into the used coupon // ID and see if this is a single use // coupon and // cancel it if required. mysql_select_db(eckopub_shopping) or die("Unable to select database (6)"); $query_coupon_id = mysql_query("SELECT unique_id FROM coupon_code WHERE code='$coupon' AND active='1' AND expires_on>=CURDATE()"); // $20.00 ISBN system if ($coupon == '20DollarISBN') { $create_coupon_code = create_coupon_code(array('user_id' => $_SESSION ["member_id"], 'note_customer' => 'Save $50.00 Instantly (From $20.00 ISBN).', 'note_admin' => "From $20.00 ISBN Order Number: $order_id", 'active' => '1', 'single_use' => '1', 'expires_on' => '21', 'min_total_order' => '0.00', 'value' => '50.00', 'value_type' => '1')); $couponCode = $create_coupon_code['code']; $checkout_content .= "

Your coupon code for $50.00 off your next purchase is $couponCode - Just use it during checkout for your next purchase or contact us for further assistance! Please remember, this coupon can not be used for another ISBN assignment.

"; $couponCodeEmail = "

Your coupon code for $50.00 off your next purchase is $couponCode - Just use it during checkout for your next purchase or contact us for further assistance! Please remember, this coupon can not be used for another ISBN assignment.

"; } list ($coupon_id) = mysql_fetch_row($query_coupon_id); mysql_query("INSERT INTO used_coupon_codes VALUES('$order_id','$coupon_id','$coupon_saved')"); $query_coupon_status = mysql_query("SELECT unique_id FROM coupon_code WHERE code='$coupon' AND single_use='1'"); if (mysql_num_rows($query_coupon_status)) mysql_query("UPDATE coupon_code SET active='2' WHERE code='$coupon'"); } // Send out e-mail to client mysql_select_db(eckopub_shopping) or die("Unable to select database :: " . $_SERVER ["SCRIPT_NAME"]); $query_eml = mysql_query("SELECT type, quote_id FROM cart_publishing WHERE sid='$sid'"); while (list ($type, $quote_id) = mysql_fetch_row($query_eml)) { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database :: " . $_SERVER ["SCRIPT_NAME"]); $query_cost_eml = mysql_query("SELECT total_cost, total_after_discount FROM $type WHERE quote_id='$quote_id'") or die(mysql_error()); $object_cost_eml = mysql_fetch_object($query_cost_eml); $total_cost_item = "$object_cost_eml->total_cost"; $total_after_discount = "$object_cost_eml->total_after_discount"; switch ($type) { case 'interior_layout' : $type_disp = 'Interior Layout Formatting'; break; case 'cover_design' : $type_disp = 'Cover Design'; break; case 'editing' : $type_disp = 'Book Editing'; break; case 'printing' : $type_disp = 'Quantity Book Printing'; break; case 'printing_v2' : $type_disp = 'Quantity Book Printing'; break; case 'member_package' : $type_disp = 'ECKO Membership Package'; break; case 'v2_member_package' : $type_disp = 'ECKO Membership Package'; break; } $order_email_info .= "$type_disp - Total: $$total_cost_item
"; } $from = "info@eckopublishing.com"; $subject_email = "Your Order With ECKO Publishing"; $message_email = "

Hello $first_name_disp,
Thank you for your order from ECKO Publishing. Below are your order details.

Order Number: $order_id
Total Billed (USD): $$total_cost
Total Billed (BTC): $totalCostBtc btc
Products Ordered
$order_email_info
$order_new_member_email $couponCodeEmail

If you have not already done so, you will need to login at https://www.eckopublishing.com/member/login/ and supply us some information to complete your project.

"; // pear_mail($from, $first_name, $last_name, $email_disp, $subject_email, $message_email); sendEmailV2($first_name, $last_name, $subject_email, $message_email, '', $email_disp); // End Email System // Move items out of cart and into permenent databases mysql_select_db(eckopub_shopping) or die("Unable to select database (2)"); $query_pub_cart = mysql_query("SELECT quote_id, type FROM cart_publishing WHERE sid='$sid'") or die(mysql_error()); while (list ($quote_id, $type) = mysql_fetch_row($query_pub_cart)) { if ($type == 'member_package_v2') { mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (2)"); // Get package details from the database $query_package_items = mysql_query("SELECT total_cost, isbn, isbn_digital, copyright, lccn, radio_show, digital_marketing_material, google_books_listing, eckobooks_distro, retail_distro, ingram_advantage, kindle_distro, ipad_distro, googlebooks_distro, nook_distro, recurring_value, recurring_legnth_days FROM member_package_v2 WHERE quote_id='$quote_id'"); list ($total_cost_package, $isbn_assignment, $isbn_digital, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $eckobooks_distro, $retail_distro, $ingram_advantage, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $recurring_value, $recurring_legnth_days) = mysql_fetch_row($query_package_items); // Convert retail distro number into meaningful // information $add_package_retail_interperter = add_package_retail_interperter($retail_distro); $amazon_distro = $add_package_retail_interperter ["amazon_distro"]; $pod_distro_northamerica = $add_package_retail_interperter ["pod_northamerica"]; $pod_distro_uk = $add_package_retail_interperter ["pod_uk"]; $pod_distro_europe = $add_package_retail_interperter ["pod_europe"]; $pod_distro_australia = $add_package_retail_interperter ["pod_australia"]; $qualified_discount_level = $add_package_retail_interperter ["qualified_discount_level"]; // Add the package to the database $recurring_legnth_days = '350'; $add_package_to_purchased_services = add_package_to_purchased_services($isbn_assignment, $isbn_digital, $copyright, $lccn, $radio_interview, $digital_marketing_material, $google_books, $ingram_advantage, $amazon_distro, $pod_distro_northamerica, $pod_distro_uk, $pod_distro_europe, $pod_distro_australia, $kindle_distro, $ipad_distro, $googlebooks_distro, $nook_distro, $eckobooks_distro, $qualified_discount_level, $total_cost_package, $order_id, $member_id, $recurring_value, $recurring_legnth_days); mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (4)"); // Mark the cart item as being purchased mysql_query("UPDATE $type SET purchased='yes', member_id='$member_id', order_id='$order_id' WHERE quote_id='$quote_id'") or die(mysql_error()); mysql_select_db(eckopub_shopping) or die("Unable to select database (5)"); mysql_query("DELETE FROM cart_publishing WHERE quote_id='$quote_id' AND type='$type'") or die(mysql_error()); if (!$_SESSION ['member_discount_level'] && $qualified_discount_level > 0) $_SESSION ['member_discount_level'] = 1; } else { // This takes care of design purchases (everything but // the memberships) // Select what db version to use for the job - Update // this to match what db to grab from switch ($type) { case 'interior_layout' : $db_ver = 1; case 'cover_design' : $db_ver = 1; case 'editing' : $db_ver = 1; case 'printing' : $db_ver = 1; case 'printing_v2' : $db_ver = 1; } mysql_select_db(eckopub_memberservices) or die("Unable to select database (3)"); mysql_query("INSERT INTO purchased_services VALUES('','$order_id','$member_id',CURDATE(),'','','','$type','$quote_id','new','','$db_ver')") or die(mysql_error()); } mysql_select_db(eckopub_publishingquotes) or die("Unable to select database (4)"); mysql_query("UPDATE $type SET purchased='yes', member_id='$member_id', order_id='$order_id' WHERE quote_id='$quote_id'") or die(mysql_error()); mysql_select_db(eckopub_shopping) or die("Unable to select database (5)"); mysql_query("DELETE FROM cart_publishing WHERE quote_id='$quote_id' AND type='$type'") or die(mysql_error()); } include_once 'order_notification.inc'; // Send E-mail To Cell Phones return array('orderId' => $order_id, 'orderMessageDisp' => $checkout_content); } ?>