function do_esd() { global $cartid, $zid, $lid, $custid, $flag_useesd, $flag_genesd; global $billing_first, $billing_mi, $billing_last, $billing_email; global $download_pw, $download_user; $fcesd = new FC_SQL(); $fcesn = new FC_SQL(); $fcesp = new FC_SQL(); $dlmax = 10; // 10 maximum downloads $dlmaxdays = 30; // 30 days before download expiration $now = time(); $end = $now + $dlmaxdays * 86400; // I don't think we care about compsku, but pull for possible reference $fcesd->query("select olid,sku,compsku from oline where orderid='{$cartid}'"); $esd_count = 0; while ($fcesd->next_record()) { $olid = (int) $fcesd->f("olid"); $sku = $fcesd->f("sku"); $compsku = $fcesd->f("compsku"); $fcesp->query("select prodflag1 from prod where prodzid={$zid} and " . "prodsku='{$sku}'"); $fcesp->next_record(); $flag1 = (int) $fcesp->f("prodflag1"); $fcesp->free_result(); $fcesp->query("select proddload from prodlang where prodlzid={$zid} and " . "prodlid={$lid} and prodlsku='{$sku}'"); $fcesp->next_record(); $proddload = $fcesp->f("proddload"); $fcesp->free_result(); if ($flag1 & $flag_useesd && $flag1 & $flag_genesd) { $esd_count++; // use fishcart internal ESD process $fcesp->query("insert into esd ( " . "esdoid,esdact,esdolid,esdpurchid,esddlact,esddlexp," . "esddlcnt,esddlmax,esdsernum,esddlfile" . ") values (" . "'{$cartid}',1,{$olid},{$custid},{$now},{$end}," . "0,{$dlmax},'','{$proddload}')"); $esdid = (int) $fcesp->insert_id('esdid', 'kmtesd', 'esdolid'); $fcesn->query("update oline set olesd={$esdid} where olid={$olid}"); } elseif ($flag1 & $flag_useesd) { $esd_count++; // use external process for ESD items // must set $esdid for the ESD table ID upon exit require './esd_external.php'; } } $fcesd->free_result(); if ($esd_count) { $cname = $billing_first . ' ' . $billing_mi . ' ' . $billing_last; // use the cart id as the download username $download_user = $cartid; // create a random number as a password // check for random number collisions; start by assuming a collision $i = 0; $collision = 1; while ($collision) { srand((double) microtime() * 1000000); $download_pw = (int) rand() + 1; $fcesn->query("select count(*) as cnt from pw where pwpw='{$download_pw}'"); $fcesn->next_record(); // collision is the count of rows found, leave loop when 0 $collision = (int) $fcesn->f('cnt'); $fcesn->free_result(); $i++; if ($i % 10 == 0) { global $gBitSystem; mail($gBitSystem->getErrorEmail(), " SERIAL NUMBER COLLISION LOOP", "Serial Number: {$download_pw}\nLoop count: {$i}\n"); sleep(1); // try a 1 second sleep } } $fcesp->query("insert into pw ( " . "pwactive,pwzone," . "pwjan,pwfeb,pwmar,pwapr,pwmay, pwjun," . "pwjul,pwaug,pwsep,pwoct,pwnov,pwdec," . "pwexp,pwdescr,pwemail,pwuid,pwpw,pwoid" . ") values (" . "1,{$zid}," . "0,0,0,0,0,0," . "0,0,0,0,0,0," . "{$end},'{$cname}','{$billing_email}','{$download_user}','{$download_pw}'," . "'{$cartid}')"); $fcesd->commit(); } return $esd_count; }
while ($i < count($subzshipid)) { $this_subzshipid = (int) $subzshipid[$i]; if ($this_subzshipid != $subzshipdef) { if ($databaseeng == 'odbc' && $dialect == 'solid') { $res = $fcs->query("call subzship_ins (" . "{$subzsid},{$this_subzshipid},0)"); } else { $res = $fcs->query("insert into subzship " . "(shipszid,shipid,shipdef,shiplid)" . " values " . "({$subzsid},{$this_subzshipid},0,{$langid})"); } } $i++; } } } elseif ($act == 'new') { if ($databaseeng == 'odbc' && $dialect == 'solid') { $res = $fcs->query("call subzone_ins (" . "{$zoneid},'{$subzdescr}'," . "{$subztaxpern},{$subztaxpers}," . "'{$subztaxcmtn}','{$subztaxcmts}'," . "{$subzvendid},{$subzwhsid},{$subzflag0},{$subzparent})"); $subzsid = $fcs->insert_id("subzid", "subzone"); $res = $fcs->query("call subzship_ins (" . "{$subzsid},{$subzshipdef},1)"); } else { $res = $fcs->query("insert into subzone " . "(subzid,subzdescr," . "subztaxpern,subztaxpers," . "subztaxcmtn,subztaxcmts," . "subzvendid,subzwhsid,subzflag0,subzparent)" . " values " . "({$zoneid},'{$subzdescr}'," . "{$subztaxpern},{$subztaxpers}," . "'{$subztaxcmtn}','{$subztaxcmts}'," . "{$subzvendid},{$subzwhsid},{$subzflag0},{$subzparent})"); // get the ID of the shipping profile just added $subzsid = $fcs->insert_id("subzid", "subzone"); $res = $fcs->query("insert into subzship " . "(shipszid,shipid,shipdef,shiplid)" . " values " . "({$subzsid},{$subzshipdef},1,{$langid})"); } if ($subzshipid) { $i = 0; while ($i < count($subzshipid)) { $this_subzshipid = (int) $subzshipid[$i]; if ($this_subzshipid != $subzshipdef) { if ($databaseeng == 'odbc' && $dialect == 'solid') { $res = $fcs->query("call subzship_ins (" . "{$subzsid},{$this_subzshipid},0)"); } else {
$shipdescr = $fct->f('shipdescr'); $shipcalc = $fct->f('shipcalc'); $shipadd = $fct->f('shipadd'); $shipmaint = $fct->f('shipmaint'); $shipupdate = $fct->f('shipupdate'); $shipaux1 = $fct->f('shipaux1'); $shipaux2 = $fct->f('shipaux2'); $shipsvccode = $fct->f('shipsvccode'); // now insert the record if ($databaseeng == 'odbc' and $dialect == 'solid') { $fcm->query("call ship_ins (" . " {$shipzid}, {$newlid}, '{$shipdescr}', " . " {$shipmeth}, {$shippercent}, {$shipitem}, {$shipitem2}, '{$shipcalc}', " . "'{$shipadd}', '{$shipmaint}', '{$shipupdate}', '{$shipaux1}', '{$shipaux2}', " . "'{$shipsvccode}, {$active})"); } else { $fcm->query("insert into ship (shipzid,shiplid," . "shipdescr,shipmeth,shippercent,shipitem,shipitem2,shipcalc,shipadd," . "shipmaint,shipupdate,shipaux1,shipaux2,shipsvccode,active) values " . "({$shipzid}, {$newlid}, '{$shipdescr}', " . " {$shipmeth}, {$shippercent}, {$shipitem}, {$shipitem2}, '{$shipcalc}', " . "'{$shipadd}', '{$shipmaint}', '{$shipupdate}', '{$shipaux1}', '{$shipaux2}', " . "'{$shipsvccode}', {$active})"); } // get the new ship profile id just inserted $new_shipid = (int) $fcm->insert_id('shipid', 'ship', "shipzid={$zoneid} and shiplid='{$newlid}' and shipdescr='{$shipdescr}'"); // duplicate the subzone ship table entries // get the entry for this ship profile in the default language if ($active) { // if this ship profile is active $fcta->query("select * from subzship " . "where shipid={$shipid} and shiplid={$zonedeflid}"); while ($fcta->next_record()) { $shipszid = (int) $fcta->f('shipszid'); $shipdef = (int) $fcta->f('shipdef'); $res = $fcm->query("insert into subzship " . "(shipszid,shipid,shipdef,shiplid)" . " values " . "({$shipszid},{$new_shipid},{$shipdef},{$newlid})"); } } // duplicate the price threshold entries to the new ship id $fcta->query("select * from shipthresh " . "where shipid={$shipid}"); //"where shipzid=$zoneid and shiplid=$zonedeflid"); while ($fcta->next_record()) {
// incr the one back index if ($l) { $i = $numlvl; } else { $i++; } } } } elseif ($act == "new") { if ($databaseeng == 'odbc' && $dialect == 'solid') { $fcs->query("call ship_ins (" . " {$zoneid}, {$langid}, '{$shipdescr}', " . " {$shipmeth}, {$shippercent}, {$shipitem}, {$shipitem2}, '{$shipcalc}', " . "'{$shipadd}', '{$shipmaint}', '{$shipupdate}', '{$shipaux1}', '{$shipaux2}', " . "'{$shipsvccode}, 1)"); } else { $fcs->query("insert into ship (shipzid,shiplid," . "shipdescr,shipmeth,shippercent,shipitem,shipitem2,shipcalc,shipadd," . "shipmaint,shipupdate,shipaux1,shipaux2,shipsvccode,active) values " . "({$zoneid}, {$langid}, '{$shipdescr}', " . " {$shipmeth}, {$shippercent}, {$shipitem}, {$shipitem2}, '{$shipcalc}', " . "'{$shipadd}', '{$shipmaint}', '{$shipupdate}', '{$shipaux1}', '{$shipaux2}', " . "'{$shipsvccode}', 1)"); } // get the ID of the shipping profile just added $shipid = $fcs->insert_id("shipid", "ship", "shipdescr='{$shipdescr}'"); if ($shipmeth == 1) { //threshold shipping // numlvl comes in from the Web form $i = 0; // loop counter, array index $j = 0; // lags i by one to reference last index $l = 0; // end of loop flag while ($i < $numlvl) { if (!$i) { $lo = (double) 0; } else { $lo = (double) $shiphi[$j]; }