| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:28:27 2008 ] | [ PgMarket 2.2.3 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 // (C) 2000 Ying Zhang (ying@zippydesign.com) 3 // (C) 2000-2003 Marco Pratesi <marco@pgmarket.net> 4 5 include ("../config.inc.php"); 6 include ("../common.inc.php"); 7 require_login(); 8 include ($CFG["libdir"] . "pgm_orders.inc.php"); 9 10 $paybutton = nvl($_POST["paybutton"], ""); 11 12 /* this page will do the CC authentication, so we want to try to prevent 13 * people from entering here casually */ 14 $cart_is_empty = ($PGM_SESSION["CART"]->num_items() == 0); 15 $order = load_orderinfo(); 16 if ($cart_is_empty || !$order) { 17 pgm_session_close($PGM_SESSION, $session_name); 18 redirect($CFG["firstpage"]); 19 die; 20 } 21 22 /* 23 24 Se si tratta del pulsante del ContrAssegno, semplicemente e` gia` tutto finito 25 e bisogna solamente fare cio` che e` descritto nell'if sottostante; 26 forse si potrebbe mettere qualche controllo sul valore di ritorno di $orderid . 27 28 Se si tratta del pulsante relativo alla Carta di Credito, bisogna preparare 29 le variabili necessarie per preparare la form da sottomettere 30 al Payment Authorization Service (parte da aggiungere), che corrisponde 31 a un opportuno template. 32 33 */ 34 35 $t = new Template(); 36 include ($CFG["localelangdir"] . "global-common.inc.php"); 37 if ($paybutton == $t->get_var("Cash_On_Delivery")) { // si tratta di un pagamento in contrassegno 38 $DOC_TITLE = "Order_Completed_Successfully"; 39 } else if ($paybutton == $t->get_var("Credit_Card")) { 40 $DOC_TITLE = "submission_to_banca_sella"; 41 } 42 include($CFG["dirroot"] . "header.php"); 43 44 $t = new Template(); 45 include ($CFG["localelangdir"] . "global-common.inc.php"); 46 include ($CFG["localelangdir"] . "global-shopping.inc.php"); 47 include ($CFG["localelangdir"] . "global-admin.inc.php"); 48 49 if ($paybutton == $t->get_var("Cash_On_Delivery")) { // si tratta di un pagamento in contrassegno 50 51 /* we will create the order in our database, then try to authorize the 52 * payment. if all was successful, the user's order will have been 53 * completed. 54 */ 55 $emailbody = ""; 56 $orderid = create_order_ca($order, $emailbody); 57 // echo "<pre>" . $emailbody . "</pre>"; // for debugging... 58 mail( 59 $CFG["seller_fullname"] . " <" . $CFG["seller_email"] . ">", 60 $CFG["subject_cash_on_delivery"], 61 $emailbody, 62 "From: " . $PGM_SESSION["user"]["email"] 63 ); 64 65 $t->set_file("page", "templates/" . $PGM_SESSION["lang"] . "/complete_order_success.ihtml"); 66 $t->set_var(array( 67 "orderid" => $orderid, 68 "fgrandtotal" => formatted_price($PGM_SESSION["CART"]->get_grandtotal()), 69 "firstpage" => $CFG["firstpage"], 70 "myname" => $CFG["myname"] 71 )); 72 /* clear out the shopping cart, so the user doesn't accidentally re-submit 73 * and purchase twice!! */ 74 $PGM_SESSION["CART"]->init(); 75 $PGM_SESSION["CART"]->calc_grandtotal(); 76 clear_orderinfo(); 77 $PGM_SESSION["wantsurl"] = ""; 78 79 } else if ($paybutton == $t->get_var("Credit_Card")) { 80 81 ///////////////////////////////////////////////////////////////////////// 82 // A PART OF THE CODE HAS BEEN CUT AWAY BECAUSE IT STRICTLY DEPENDS 83 // ON THE PARTICULAR PAYMENT AUTHORIZATION SERVICE YOU DECIDE TO USE; 84 // HENCE, IN GENERAL, THE PART OF CODE CUT AWAY WILL NOT BE USEFUL TO YOU 85 ///////////////////////////////////////////////////////////////////////// 86 87 $orderid = create_order_cc($order, nvl($passwordric, "")); 88 $t->set_file("page", "templates/" . $PGM_SESSION["lang"] . "/banca_sella_submit.ihtml"); 89 90 } 91 92 $t->pparse("out", "page"); 93 94 include ($CFG["dirroot"] . "footer.php"); 95 96 pgm_session_close($PGM_SESSION, $session_name); 97 98 /* ******************************************************************* 99 * FUNCTIONS 100 ****************************************************************** */ 101 102 /** 103 * This function saves the order info into the database for a cash on delivery order. 104 * 105 * It stores an entry in the corresponding orders table, and then 106 * it stores the shopping cart content into the order_items table; 107 * finally, it prepares the body of the e-mail message to be sent 108 * to the market seller. 109 * It returns the order id. 110 * 111 * @param array $order the order informations 112 * @param string $emailbody the body of the e-mail message 113 * @return string 114 */ 115 function create_order_ca(&$order, &$emailbody) { 116 global $_SERVER; 117 global $PGM_SESSION; 118 global $adminday, $adminmonth, $ordersdb; 119 120 /* build the custinfo string */ 121 $custinfo = 122 $ordersdb["Customer"] . " " . $order["customer"] . "\n" 123 . $ordersdb["Phone"] . " " . $order["contact"] . "\n" 124 . $ordersdb["Address"] . "\n" . $order["address"] . " " . $order["number"] . "\n" 125 . " " . $order["zip_code"] . "\n " . $order["city"] . "\n " . $order["country"] . "\n"; 126 127 /* save order information first */ 128 129 // $Date = $myday[date("w")] . date(" j ") . $mymonth[date("n")] . date(" Y H:i:s"); 130 $Dateusec = gettimeofday(); 131 $unixtime = $Dateusec["sec"]; 132 $year = date("Y"); 133 $month = date("n"); 134 $day = date("j"); 135 $weekday = date("w"); 136 $FromIP = $_SERVER["REMOTE_ADDR"]; 137 $Dateusec = gettimeofday(); 138 $orderid = $Dateusec["sec"] . sprintf("%06d", $Dateusec["usec"]) . "-" . $FromIP; 139 140 $grandtotal = $PGM_SESSION["CART"]->get_grandtotal(); 141 $delivery = $PGM_SESSION["CART"]->get_delivery(); 142 143 $qid = new PGM_Sql(); 144 $qid->begin(); 145 146 $qid->query(" 147 INSERT INTO ordersca ( 148 id 149 ,username 150 ,unixtime 151 ,year 152 ,month 153 ,day 154 ,weekday 155 ,fromip 156 ,custinfo 157 ,notes 158 ,amount 159 ,user_discount_id 160 ,user_discount 161 ,delivery 162 ,state_id 163 ) VALUES ( 164 '$orderid' 165 ,'" . $PGM_SESSION["user"]["username"] . "' 166 ,'$unixtime' 167 ,'$year' 168 ,'$month' 169 ,'$day' 170 ,'$weekday' 171 ,'$FromIP' 172 ,'$custinfo' 173 ,'" . $order["comments"] . "' 174 ,'$grandtotal' 175 ,'" . $PGM_SESSION["user"]["user_discount_id"] . "' 176 ,'" . $PGM_SESSION["user"]["user_discount"] . "' 177 ,'$delivery' 178 ,'1' 179 ) 180 "); 181 182 $order_comments = stripslashes ($order["comments"]); 183 $emailbody .= "\n" . $ordersdb["Cash_On_Delivery"] . "\n" 184 . "\n" . $ordersdb["Order"] . " " . $orderid 185 . "\n" . $ordersdb["Username"] . ": " . $PGM_SESSION["user"]["username"] 186 . "\n" . $ordersdb["Date"] . ": " . $adminday[$weekday] . " " . $day . " " . $adminmonth[$month] . " " . $year 187 . "\n" . $ordersdb["Comments"] . ":\n" . $order_comments 188 . "\n\n" . $ordersdb["TOTAL"] . ": " . formatted_price_text($PGM_SESSION["CART"]->get_grandtotal()) . "\n"; 189 190 /* now add the shopping cart items into the order_items table */ 191 $products_list = array(); 192 $products_list = $PGM_SESSION["CART"]->get_items_array(); 193 for ($cnt=0; $cnt<count($products_list); $cnt++) { 194 $color = $products_list[$cnt]["color_name"]; 195 if ($products_list[$cnt]["color_lname"] != "") { 196 $color .= " (" . $products_list[$cnt]["color_lname"] . ")"; 197 } 198 199 $product_id = $products_list[$cnt]["id"]; 200 $color_id = addslashes($products_list[$cnt]["color_id"]); 201 $name = addslashes($products_list[$cnt]["name"]); 202 $price = $products_list[$cnt]["price"]; 203 $discount = $products_list[$cnt]["discount"]; 204 $discqty = $products_list[$cnt]["discqty"]; 205 $iva = $products_list[$cnt]["iva"]; 206 $weight = $products_list[$cnt]["weight"]; 207 $qty = $products_list[$cnt]["qty"]; 208 $qid->query(" 209 INSERT INTO order_items ( 210 order_id 211 ,product_id 212 ,color_id 213 ,name 214 ,color 215 ,price 216 ,discount 217 ,discqty 218 ,iva 219 ,weight 220 ,qty 221 ) VALUES ( 222 '$orderid' 223 ,'$product_id' 224 ,'$color_id' 225 ,'$name' 226 ,'$color' 227 ,'$price' 228 ,'$discount' 229 ,'$discqty' 230 ,'$iva' 231 ,'$weight' 232 ,'$qty' 233 ) 234 "); 235 236 $emailbody .= "\n" . $ordersdb["Product"] . " " . $products_list[$cnt]["id"] . " - " . stripslashes($products_list[$cnt]["name"]); 237 if ($color != "") { 238 $emailbody .= " - " . $color; 239 } 240 $emailbody .= "\n" . $ordersdb["Unit_Price"] . ": " . formatted_price_text($products_list[$cnt]["price"]) 241 . "\n" . $ordersdb["Number_of_items"] . ": " . $products_list[$cnt]["qty"] . "\n"; 242 } 243 244 $qid->commit(); 245 246 $foobar = $PGM_SESSION["CART"]->get_delivery(); 247 if ($foobar != 0) { 248 $emailbody .= "\n" . $ordersdb["Delivery"] . ": " . formatted_price_text($foobar); 249 } 250 251 return $orderid; 252 } 253 254 /** 255 * This function concerns credit card orders; it is analogous to the corresponding function used for cash on delivery orders. 256 */ 257 function create_order_cc(&$order, $passwordric) { 258 global $_SERVER; 259 global $PGM_SESSION; 260 global $ordersdb; 261 262 /* build the custinfo string */ 263 $custinfo = 264 $ordersdb["Customer"] . " " . $order["customer"] . "\n" 265 . $ordersdb["Phone"] . " " . $order["contact"] . "\n" 266 . $ordersdb["Address"] . "\n" . $order["address"] . " " . $order["number"] . "\n" 267 . " " . $order["zip_code"] . "\n " . $order["city"] . "\n " . $order["country"] . "\n"; 268 269 /* save order information first */ 270 271 // $Date = $myday[date("w")] . date(" j ") . $mymonth[date("n")] . date(" Y H:i:s"); 272 $Dateusec = gettimeofday(); 273 $unixtime = $Dateusec["sec"]; 274 $year = date("Y"); 275 $month = date("n"); 276 $day = date("j"); 277 $weekday = date("w"); 278 $FromIP = $_SERVER["REMOTE_ADDR"]; 279 $Dateusec = gettimeofday(); 280 $orderid = $Dateusec["sec"] . sprintf("%06d", $Dateusec["usec"]) . "-" . $FromIP; 281 282 $grandtotal = $PGM_SESSION["CART"]->get_grandtotal(); 283 $delivery = $PGM_SESSION["CART"]->get_delivery(); 284 285 $qid = new PGM_Sql(); 286 $qid->begin(); 287 288 $qid->query(" 289 INSERT INTO orderscc ( 290 id 291 ,username 292 ,unixtime 293 ,year 294 ,month 295 ,day 296 ,weekday 297 ,fromip 298 ,custinfo 299 ,notes 300 ,amount 301 ,user_discount_id 302 ,user_discount 303 ,delivery 304 ,state_id 305 ,otpric 306 ) VALUES ( 307 '$orderid' 308 ,'" . $PGM_SESSION["user"]["username"] . "' 309 ,'$unixtime' 310 ,'$year' 311 ,'$month' 312 ,'$day' 313 ,'$weekday' 314 ,'$FromIP' 315 ,'$custinfo' 316 ,'" . $order["comments"] . "' 317 ,'$grandtotal' 318 ,'" . $PGM_SESSION["user"]["user_discount_id"] . "' 319 ,'" . $PGM_SESSION["user"]["user_discount"] . "' 320 ,'$delivery' 321 ,'1' 322 ,'$passwordric' 323 ) 324 "); 325 326 /* now add the shopping cart items into the order_items table */ 327 $products_list = array(); 328 $products_list = $PGM_SESSION["CART"]->get_items_array(); 329 for ($cnt=0; $cnt<count($products_list); $cnt++) { 330 $color = $products_list[$cnt]["color_name"]; 331 if ($products_list[$cnt]["color_lname"] != "") { 332 $color .= " (" . $products_list[$cnt]["color_lname"] . ")"; 333 } 334 335 $product_id = $products_list["$cnt"]["id"]; 336 $color_id = addslashes($products_list[$cnt]["color_id"]); 337 $name = addslashes($products_list[$cnt]["name"]); 338 $price = $products_list[$cnt]["price"]; 339 $discount = $products_list[$cnt]["discount"]; 340 $discqty = $products_list[$cnt]["discqty"]; 341 $iva = $products_list[$cnt]["iva"]; 342 $weight = $products_list[$cnt]["weight"]; 343 $qty = $products_list[$cnt]["qty"]; 344 $qid->query(" 345 INSERT INTO order_items ( 346 order_id 347 ,product_id 348 ,color_id 349 ,name 350 ,color 351 ,price 352 ,discount 353 ,discqty 354 ,iva 355 ,weight 356 ,qty 357 ) VALUES ( 358 '$orderid' 359 ,'$product_id' 360 ,'$color_id' 361 ,'$name' 362 ,'$color' 363 ,'$price' 364 ,'$discount' 365 ,'$discqty' 366 ,'$iva' 367 ,'$weight' 368 ,'$qty' 369 ) 370 "); 371 } 372 373 $qid->commit(); 374 375 return $orderid; 376 } 377 378 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |