00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00067 require_once(PATH_tslib."class.tslib_pibase.php");
00068 require_once(PATH_t3lib."class.t3lib_parsehtml.php");
00069
00070 class tx_ttproducts extends tslib_pibase {
00071 var $cObj;
00072
00073 var $searchFieldList="title,note,itemnumber";
00074
00075
00076 var $pid_list="";
00077 var $uid_list="";
00078 var $categories=array();
00079 var $pageArray=array();
00080 var $orderRecord = array();
00081
00082
00083
00084 var $templateCode="";
00085
00086
00087 var $basket=array();
00088 var $basketExtra;
00089 var $recs = Array();
00090 var $personInfo;
00091 var $deliveryInfo;
00092
00093
00094 var $calculatedBasket;
00095 var $calculatedSums_tax;
00096 var $calculatedSums_no_tax;
00097
00098 var $config=array();
00099 var $conf=array();
00100 var $tt_product_single="";
00101 var $globalMarkerArray=array();
00102 var $externalCObject="";
00103
00104
00108 function main_products($content,$conf) {
00109 $GLOBALS["TSFE"]->set_no_cache();
00110
00111
00112
00113
00114
00115
00116 $this->conf=$conf;
00117 $this->config["code"] = strtolower(trim($this->cObj->stdWrap($this->conf["code"],$this->conf["code."])));
00118 $this->config["limit"] = t3lib_div::intInRange($this->conf["limit"],0,1000);
00119 $this->config["limit"] = $this->config["limit"] ? $this->config["limit"] : 50;
00120
00121 $this->config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
00122 $this->config["pid_list"] = $this->config["pid_list"] ? $this->config["pid_list"] : $GLOBALS["TSFE"]->id;
00123
00124 $this->config["recursive"] = $this->cObj->stdWrap($this->conf["recursive"],$this->conf["recursive."]);
00125 $this->config["storeRootPid"] = $this->conf["PIDstoreRoot"] ? $this->conf["PIDstoreRoot"] : $GLOBALS["TSFE"]->tmpl->rootLine[0][uid];
00126
00127
00128 $this->searchFieldList = trim($this->conf["stdSearchFieldExt"]) ? implode(",", array_unique(t3lib_div::trimExplode(",",$this->searchFieldList.",".trim($this->conf["stdSearchFieldExt"]),1))) : $this->searchFieldList;
00129
00130
00131 $this->config["displayCurrentRecord"] = $this->conf["displayCurrentRecord"];
00132 if ($this->config["displayCurrentRecord"]) {
00133 $this->config["code"]="SINGLE";
00134 $this->tt_product_single = true;
00135 } else {
00136 $this->tt_product_single = t3lib_div::_GET("tt_products");
00137 }
00138
00139
00140 $this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);
00141
00142
00143 $splitMark = md5(microtime());
00144 $globalMarkerArray=array();
00145 list($globalMarkerArray["###GW1B###"],$globalMarkerArray["###GW1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap1."]));
00146 list($globalMarkerArray["###GW2B###"],$globalMarkerArray["###GW2E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap2."]));
00147 $globalMarkerArray["###GC1###"] = $this->cObj->stdWrap($this->conf["color1"],$this->conf["color1."]);
00148 $globalMarkerArray["###GC2###"] = $this->cObj->stdWrap($this->conf["color2"],$this->conf["color2."]);
00149 $globalMarkerArray["###GC3###"] = $this->cObj->stdWrap($this->conf["color3"],$this->conf["color3."]);
00150
00151
00152 $this->templateCode= $this->cObj->substituteMarkerArrayCached($this->templateCode, $globalMarkerArray);
00153
00154
00155
00156 $this->externalCObject = $this->getExternalCObject("externalProcessing");
00157
00158
00159 $this->setPidlist($this->config["pid_list"]);
00160 $this->TAXpercentage = doubleval($this->conf["TAXpercentage"]);
00161 $this->globalMarkerArray = $globalMarkerArray;
00162 $this->initCategories();
00163 $this->initBasket($GLOBALS["TSFE"]->fe_user->getKey("ses","recs"));
00164
00165
00166
00167
00168
00169
00170 $codes=t3lib_div::trimExplode(",", $this->config["code"]?$this->config["code"]:$this->conf["defaultCode"],1);
00171 if (!count($codes)) $codes=array("");
00172 while(list(,$theCode)=each($codes)) {
00173 $theCode = (string)strtoupper(trim($theCode));
00174
00175
00176 switch($theCode) {
00177 case "TRACKING":
00178 $content.=$this->products_tracking($theCode);
00179 break;
00180 case "BASKET":
00181 case "PAYMENT":
00182 case "FINALIZE":
00183 case "INFO":
00184 $content.=$this->products_basket($theCode);
00185 break;
00186 case "SEARCH":
00187 case "SINGLE":
00188 case "LIST":
00189 $content.=$this->products_display($theCode);
00190 break;
00191 default:
00192 $langKey = strtoupper($GLOBALS["TSFE"]->config["config"]["language"]);
00193 $helpTemplate = $this->cObj->fileResource("EXT:tt_products/pi/products_help.tmpl");
00194
00195
00196 $helpTemplate_lang="";
00197 if ($langKey) {$helpTemplate_lang = $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_".$langKey."###");}
00198 $helpTemplate = $helpTemplate_lang ? $helpTemplate_lang : $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_DEFAULT###");
00199
00200
00201 $markerArray["###CODE###"] = $theCode;
00202 $content.=$this->cObj->substituteMarkerArray($helpTemplate,$markerArray);
00203 break;
00204 }
00205 }
00206 return $content;
00207 }
00208
00212 function getExternalCObject($mConfKey) {
00213 if ($this->conf[$mConfKey] && $this->conf[$mConfKey."."]) {
00214 $this->cObj->regObj = &$this;
00215 return $this->cObj->cObjGetSingle($this->conf[$mConfKey],$this->conf[$mConfKey."."],"/".$mConfKey."/")."";
00216 }
00217 }
00218
00222 function products_tracking($theCode) {
00223 $admin = $this->shopAdmin();
00224 if (t3lib_div::_GP("tracking") || $admin) {
00225 $orderRow = $this->getOrderRecord("",t3lib_div::_GP("tracking"));
00226 if (is_array($orderRow) || $admin) {
00227 if (!is_array($orderRow)) $orderRow=array("uid"=>0);
00228 $content = $this->getTrackingInformation($orderRow,$this->templateCode);
00229 } else {
00230 $content=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###TRACKING_WRONG_NUMBER###"));
00231 if (!$GLOBALS["TSFE"]->beUserLogin) {$content = $this->cObj->substituteSubpart($content,"###ADMIN_CONTROL###","");}
00232 }
00233 } else {
00234 $content=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###TRACKING_ENTER_NUMBER###"));
00235 if (!$GLOBALS["TSFE"]->beUserLogin) {$content = $this->cObj->substituteSubpart($content,"###ADMIN_CONTROL###","");}
00236 }
00237 $markerArray=array();
00238 $markerArray["###FORM_URL###"] = $this->getLinkUrl();
00239 $content= $this->cObj->substituteMarkerArray($content, $markerArray);
00240
00241 return $content;
00242 }
00243
00247 function products_basket($theCode) {
00248 $this->setPidlist($this->config["storeRootPid"]);
00249 $this->initRecursive(999);
00250 $this->generatePageArray();
00251
00252 if (count($this->basket)) {
00253
00254 $activity="";
00255 if (t3lib_div::_GP("products_info")) {
00256 $activity="products_info";
00257 } elseif (t3lib_div::_GP("products_payment")) {
00258 $activity="products_payment";
00259 } elseif (t3lib_div::_GP("products_finalize")) {
00260 $activity="products_finalize";
00261 }
00262
00263 if ($theCode=="INFO") {
00264 $activity="products_info";
00265 } elseif ($theCode=="PAYMENT") {
00266 $activity="products_payment";
00267 } elseif ($theCode=="FINALIZE") {
00268 $activity="products_finalize";
00269 }
00270
00271
00272
00273 switch($activity) {
00274 case "products_info":
00275 $this->load_noLinkExtCobj();
00276 $content.=$this->getBasket("###BASKET_INFO_TEMPLATE###");
00277 break;
00278 case "products_payment":
00279 $this->load_noLinkExtCobj();
00280 if ($this->checkRequired()) {
00281 $this->mapPersonIntoToDelivery();
00282 $content=$this->getBasket("###BASKET_PAYMENT_TEMPLATE###");
00283 } else {
00284 $content.=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###BASKET_REQUIRED_INFO_MISSING###"));
00285 $content = $this->cObj->substituteMarkerArray($content, $this->addURLMarkers(array()));
00286 }
00287 break;
00288 case "products_finalize":
00289 if ($this->checkRequired()) {
00290 $this->load_noLinkExtCobj();
00291 $this->mapPersonIntoToDelivery();
00292 $handleScript = $GLOBALS["TSFE"]->tmpl->getFileName($this->basketExtra["payment."]["handleScript"]);
00293 if ($handleScript) {
00294 $content = $this->includeHandleScript($handleScript,$this->basketExtra["payment."]["handleScript."]);
00295 } else {
00296 $orderUid = $this->getBlankOrderUid();
00297 $content=$this->getBasket("###BASKET_ORDERCONFIRMATION_TEMPLATE###");
00298 $this->finalizeOrder($orderUid);
00299 }
00300 } else {
00301 $content.=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###BASKET_REQUIRED_INFO_MISSING###"));
00302 $content = $this->cObj->substituteMarkerArray($content, $this->addURLMarkers(array()));
00303 }
00304 break;
00305 default:
00306 $content.=$this->getBasket();
00307 break;
00308 }
00309 } else {
00310 $content.=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###BASKET_TEMPLATE_EMPTY###"));
00311 }
00312 $markerArray=array();
00313 $markerArray["###EXTERNAL_COBJECT###"] = $this->externalCObject;
00314 $content= $this->cObj->substituteMarkerArray($content, $markerArray);
00315
00316 return $content;
00317 }
00318 function load_noLinkExtCobj() {
00319 if ($this->conf["externalProcessing_final"] || is_array($this->conf["externalProcessing_final."])) {
00320 $this->externalCObject = $this->getExternalCObject("externalProcessing_final");
00321 }
00322 }
00323
00327 function spMarker($subpartMarker) {
00328 $sPBody = substr($subpartMarker,3,-3);
00329 $altSPM = "";
00330 if (isset($this->conf["altMainMarkers."])) {
00331 $altSPM = trim($this->cObj->stdWrap($this->conf["altMainMarkers."][$sPBody],$this->conf["altMainMarkers."][$sPBody."."]));
00332 $GLOBALS["TT"]->setTSlogMessage("Using alternative subpart marker for '".$subpartMarker."': ".$altSPM,1);
00333 }
00334 return $altSPM ? $altSPM : $subpartMarker;
00335 }
00336
00340 function products_display($theCode) {
00341 $formUrl = $this->getLinkUrl($this->conf["PIDbasket"]);
00342 if ($this->tt_product_single) {
00343
00344
00345 $this->setPidlist($this->config["storeRootPid"]);
00346 $this->initRecursive(999);
00347 $this->generatePageArray();
00348
00349 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_products', 'uid='.intval($this->tt_product_single).' AND pid IN ('.$this->pid_list.')'.$this->cObj->enableFields('tt_products'));
00350
00351 if($this->config["displayCurrentRecord"] || $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00352
00353 $item ="";
00354 if ($this->config["displayCurrentRecord"]) {
00355 $row=$this->cObj->data;
00356 $item = trim($this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_SINGLE_DISPLAY_RECORDINSERT###")));
00357 }
00358 $catTitle= $this->pageArray[$row["pid"]]["title"].($row["category"]?"/".$this->categories[$row["category"]]:"");
00359 if (!$item) {$item = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_SINGLE_DISPLAY###"));}
00360
00361
00362 $wrappedSubpartArray=array();
00363 $wrappedSubpartArray["###LINK_ITEM###"]= array('<A href="'.$this->getLinkUrl(t3lib_div::_GP("backPID")).'">','</A>');
00364
00365 $markerArray = $this->getItemMarkerArray ($row,$catTitle,10);
00366 $markerArray["###FORM_NAME###"]="item_".$this->tt_product_single;
00367 $markerArray["###FORM_URL###"]=$formUrl;
00368
00369
00370 $content= $this->cObj->substituteMarkerArrayCached($item,$markerArray,array(),$wrappedSubpartArray);
00371 }
00372 } elseif ($theCode=="SINGLE") {
00373 $content.="Wrong parameters, GET/POST var 'tt_products' was missing.";
00374 } else {
00375 $content="";
00376
00377 $where="";
00378 if ($theCode=="SEARCH") {
00379
00380 $t["search"] = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_SEARCH###"));
00381
00382 $out=$t["search"];
00383 $out=$this->cObj->substituteMarker($out, "###FORM_URL###", $this->getLinkUrl($this->conf["PIDsearch"]));
00384 $out=$this->cObj->substituteMarker($out, "###SWORDS###", htmlspecialchars(t3lib_div::_GP("swords")));
00385
00386 $content.=$out;
00387 if (t3lib_div::_GP("swords")) {
00388 $where = $this->searchWhere(trim(t3lib_div::_GP("swords")));
00389 }
00390 }
00391 $begin_at=t3lib_div::intInRange(t3lib_div::_GP("begin_at"),0,100000);
00392 if (($theCode!="SEARCH" && !t3lib_div::_GP("swords")) || $where) {
00393
00394 $this->initRecursive($this->config["recursive"]);
00395 $this->generatePageArray();
00396
00397
00398 $selectConf = Array();
00399 $selectConf["pidInList"] = $this->pid_list;
00400 $selectConf["where"] = "1=1 ".$where;
00401
00402
00403 $selectConf["selectFields"] = 'count(*)';
00404 $res = $this->cObj->exec_getQuery("tt_products",$selectConf);
00405 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00406 $productsCount = $row[0];
00407
00408
00409 $begin_at = t3lib_div::intInRange(($begin_at >= $productsCount)?($productsCount-$this->config["limit"]):$begin_at,0);
00410
00411
00412 $selectConf['orderBy'] = 'pid,category,title';
00413 $selectConf['selectFields'] = '*';
00414 $selectConf['max'] = ($this->config['limit']+1);
00415 $selectConf['begin'] = $begin_at;
00416
00417 $res = $this->cObj->exec_getQuery('tt_products',$selectConf);
00418
00419 $productsArray=array();
00420 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00421 $productsArray[$row["pid"]][]=$row;
00422 }
00423
00424
00425 $t["listFrameWork"] = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_LIST_TEMPLATE###"));
00426 $t["categoryTitle"] = $this->cObj->getSubpart($t["listFrameWork"],"###ITEM_CATEGORY###");
00427 $t["itemFrameWork"] = $this->cObj->getSubpart($t["listFrameWork"],"###ITEM_LIST###");
00428 $t["item"] = $this->cObj->getSubpart($t["itemFrameWork"],"###ITEM_SINGLE###");
00429
00430 $pageArr=explode(",",$this->pid_list);
00431 $currentP="";
00432 $out="";
00433 $iCount=0;
00434 $more=0;
00435 while(list(,$v)=each($pageArr)) {
00436 if (is_array($productsArray[$v])) {
00437 reset($productsArray[$v]);
00438 $itemsOut="";
00439 while(list(,$row)=each($productsArray[$v])) {
00440 $iCount++;
00441 if ($iCount>$this->config["limit"]) {
00442 $more=1;
00443 break;
00444 }
00445
00446
00447
00448 if ($row["pid"]."_".$row["category"]!=$currentP) {
00449 if ($itemsOut) {
00450 $out.=$this->cObj->substituteSubpart($t["itemFrameWork"], "###ITEM_SINGLE###", $itemsOut);
00451 }
00452 $itemsOut="";
00453
00454 $currentP = $row["pid"]."_".$row["category"];
00455 if ($where || $this->conf["displayListCatHeader"]) {
00456 $markerArray=array();
00457 $catTitle= $this->pageArray[$row["pid"]]["title"].($row["category"]?"/".$this->categories[$row["category"]]:"");
00458 $this->cObj->setCurrentVal($catTitle);
00459 $markerArray["###CATEGORY_TITLE###"]=$this->cObj->cObjGetSingle($this->conf["categoryHeader"],$this->conf["categoryHeader."], "categoryHeader");
00460 $out.= $this->cObj->substituteMarkerArray($t["categoryTitle"], $markerArray);
00461 }
00462 }
00463
00464
00465 $wrappedSubpartArray=array();
00466 $wrappedSubpartArray["###LINK_ITEM###"]= array('<A href="'.$this->getLinkUrl($this->conf["PIDitemDisplay"]).'&tt_products='.$row["uid"].'">','</A>');
00467 $markerArray = $this->getItemMarkerArray ($row,$catTitle,1,"listImage");
00468 $markerArray["###FORM_URL###"]=$formUrl;
00469 $markerArray["###FORM_NAME###"]="item_".$iCount;
00470 $itemsOut.= $this->cObj->substituteMarkerArrayCached($t["item"],$markerArray,array(),$wrappedSubpartArray);
00471 }
00472 if ($itemsOut) {
00473 $out.=$this->cObj->substituteMarkerArrayCached($t["itemFrameWork"], array(), array("###ITEM_SINGLE###"=>$itemsOut));
00474 }
00475 }
00476 }
00477 }
00478 if ($out) {
00479
00480 $url = $this->getLinkUrl("","begin_at");
00481
00482 $subpartArray=array();
00483 $wrappedSubpartArray=array();
00484 $markerArray=array();
00485
00486 if ($more) {
00487 $next = ($begin_at+$this->config["limit"] > $productsCount) ? $productsCount-$this->config["limit"] : $begin_at+$this->config["limit"];
00488 $wrappedSubpartArray["###LINK_NEXT###"]=array('<A href="'.$url.'&begin_at='.$next.'">','</A>');
00489 } else {
00490 $subpartArray["###LINK_NEXT###"]="";
00491 }
00492 if ($begin_at) {
00493 $prev = ($begin_at-$this->config["limit"] < 0) ? 0 : $begin_at-$this->config["limit"];
00494 $wrappedSubpartArray["###LINK_PREV###"]=array('<A href="'.$url.'&begin_at='.$prev.'">','</A>');
00495 } else {
00496 $subpartArray["###LINK_PREV###"]="";
00497 }
00498 if ($productsCount > $this->config["limit"] ) {
00499 $wrappedSubpartArray["###LINK_BROWSE###"]=array('','');
00500 $markerArray["###BROWSE_LINKS###"]="";
00501 for ($i = 0 ; $i < ($productsCount/$this->config["limit"]); $i++) {
00502 if (($begin_at >= $i*$this->config["limit"]) && ($begin_at < $i*$this->config["limit"]+$this->config["limit"])) {
00503 $markerArray["###BROWSE_LINKS###"].= ' <b>'.(string)($i+1).'</b> ';
00504
00505
00506 } else {
00507 $markerArray["###BROWSE_LINKS###"].= ' <A href="'.$url.'&begin_at='.(string)($i * $this->config["limit"]).'">'.(string)($i+1).'</A> ';
00508 }
00509 }
00510 } else {
00511 $subpartArray["###LINK_BROWSE###"]="";
00512 }
00513
00514 $subpartArray["###ITEM_CATEGORY_AND_ITEMS###"]=$out;
00515 $markerArray["###FORM_URL###"]=$formUrl;
00516 $markerArray["###ITEMS_SELECT_COUNT###"]=$productsCount;
00517
00518 $content.= $this->cObj->substituteMarkerArrayCached($t["listFrameWork"],$markerArray,$subpartArray,$wrappedSubpartArray);
00519 } elseif ($where) {
00520 $content.=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_SEARCH_EMPTY###"));
00521 }
00522 }
00523 return $content;
00524 }
00525
00529 function setPidlist($pid_list) {
00530 $this->pid_list = $pid_list;
00531 }
00532
00536 function initRecursive($recursive) {
00537 if ($recursive) {
00538 $pid_list_arr = explode(",",$this->pid_list);
00539 $this->pid_list="";
00540 while(list(,$val)=each($pid_list_arr)) {
00541 $this->pid_list.=$val.",".$this->cObj->getTreeList($val,intval($recursive));
00542 }
00543 $this->pid_list = ereg_replace(",$","",$this->pid_list);
00544 }
00545 }
00546
00550 function initCategories() {
00551
00552 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_products_cat', '1=1'.$this->cObj->enableFields('tt_products_cat'));
00553 $this->categories = array();
00554 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00555 $this->categories[$row["uid"]] = $row["title"];
00556 }
00557 }
00558
00562 function generatePageArray() {
00563
00564 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title,uid', 'pages', 'uid IN ('.$this->pid_list.')');
00565 $this->pageArray = array();
00566 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00567 $this->pageArray[$row["uid"]] = $row;
00568 }
00569 }
00570
00576 function initBasket($basket) {
00577 $this->recs = $basket;
00578 $this->basket=array();
00579 $uidArr=array();
00580 if (is_array($basket["tt_products"])) {
00581 reset($basket["tt_products"]);
00582 while(list($uid,$count)=each($basket["tt_products"])) {
00583 if (t3lib_div::testInt($uid)) {
00584 $count=t3lib_div::intInRange($count,0,100000);
00585 if ($count) {
00586 $this->basket[$uid]=$count;
00587 $uidArr[]=$uid;
00588 }
00589 }
00590 }
00591 }
00592 $this->uid_list=implode($uidArr,",");
00593 $this->setBasketExtras($basket);
00594
00595 $this->personInfo = $basket["personinfo"];
00596 $this->deliveryInfo = $basket["delivery"];
00597 if ($GLOBALS["TSFE"]->loginUser && (!$this->personInfo || $this->conf["lockLoginUserInfo"])) {
00598 $address = implode(chr(10),t3lib_div::trimExplode(chr(10),
00599 $GLOBALS["TSFE"]->fe_user->user["address"].chr(10).
00600 $GLOBALS["TSFE"]->fe_user->user["zip"]." ".$GLOBALS["TSFE"]->fe_user->user["city"].chr(10).
00601 $GLOBALS["TSFE"]->fe_user->user["country"]
00602 ,1)
00603 );
00604
00605 $this->personInfo["name"] = $GLOBALS["TSFE"]->fe_user->user["name"];
00606 $this->personInfo["address"] = $address;
00607 $this->personInfo["email"] = $GLOBALS["TSFE"]->fe_user->user["email"];
00608 $this->personInfo["telephone"] = $GLOBALS["TSFE"]->fe_user->user["telephone"];
00609 $this->personInfo["fax"] = $GLOBALS["TSFE"]->fe_user->user["fax"];
00610 }
00611 }
00612
00616 function checkExtraAvailable($name,$key) {
00617 if (is_array($this->conf[$name."."][$key."."]) && (!isset($this->conf[$name."."][$key."."]["show"]) || $this->conf[$name."."][$key."."]["show"])) {
00618 return true;
00619 }
00620 }
00621
00625 function setBasketExtras($basket) {
00626
00627 ksort($this->conf["shipping."]);
00628 reset($this->conf["shipping."]);
00629 $k=intval($basket["tt_products"]["shipping"]);
00630 if (!$this->checkExtraAvailable("shipping",$k)) {
00631 $k=intval(key($this->cleanConfArr($this->conf["shipping."],1)));
00632 }
00633 $this->basketExtra["shipping"] = $k;
00634 $this->basketExtra["shipping."] = $this->conf["shipping."][$k."."];
00635 $excludePayment = trim($this->basketExtra["shipping."]["excludePayment"]);
00636
00637
00638 if ($excludePayment) {
00639 $exclArr = t3lib_div::intExplode(",",$excludePayment);
00640 while(list(,$theVal)=each($exclArr)) {
00641 unset($this->conf["payment."][$theVal]);
00642 unset($this->conf["payment."][$theVal."."]);
00643 }
00644 }
00645
00646 ksort($this->conf["payment."]);
00647 reset($this->conf["payment."]);
00648 $k=intval($basket["tt_products"]["payment"]);
00649 if (!$this->checkExtraAvailable("payment",$k)) {
00650 $k=intval(key($this->cleanConfArr($this->conf["payment."],1)));
00651 }
00652 $this->basketExtra["payment"] = $k;
00653 $this->basketExtra["payment."] = $this->conf["payment."][$k."."];
00654
00655
00656
00657 }
00658
00662 function getClearBasketRecord() {
00663
00664 unset($this->recs["tt_products"]);
00665 return ($this->recs);
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00684 function createOrder() {
00685 $newId = 0;
00686 $pid = intval($this->conf["PID_sys_products_orders"]);
00687 if (!$pid) $pid = intval($GLOBALS["TSFE"]->id);
00688 if ($GLOBALS["TSFE"]->sys_page->getPage_noCheck ($pid)) {
00689 $advanceUid = 0;
00690 if ($this->conf["advanceOrderNumberWithInteger"]) {
00691 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'sys_products_orders', '', '', 'uid DESC', '1');
00692 list($prevUid) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00693
00694 $rndParts = explode(",",$this->conf["advanceOrderNumberWithInteger"]);
00695 $advanceUid = $prevUid+t3lib_div::intInRange(rand(intval($rndParts[0]),intval($rndParts[1])),1);
00696 }
00697
00698 $insertFields = array(
00699 'pid' => $pid,
00700 'tstamp' => time(),
00701 'crdate' => time(),
00702 'deleted' => 1
00703 );
00704 if ($advanceUid > 0) {
00705 $insertFields['uid'] = $advanceUid;
00706 }
00707
00708 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_products_orders', $insertFields);
00709
00710 $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
00711 }
00712 return $newId;
00713 }
00714
00722 function getBlankOrderUid() {
00723 $orderUid = intval($this->recs["tt_products"]["orderUid"]);
00724 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'sys_products_orders', 'uid='.intval($orderUid).' AND deleted!=0 AND status=0');
00725 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
00726 $orderUid = $this->createOrder();
00727 $this->recs["tt_products"]["orderUid"] = $orderUid;
00728 $this->recs["tt_products"]["orderDate"] = time();
00729 $this->recs["tt_products"]["orderTrackingNo"] = $this->getOrderNumber($orderUid)."-".strtolower(substr(md5(uniqid(time())),0,6));
00730 $GLOBALS["TSFE"]->fe_user->setKey("ses","recs",$this->recs);
00731 }
00732 return $orderUid;
00733 }
00734
00739 function getOrderRecord($orderUid,$tracking='') {
00740 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_products_orders', ($tracking ? 'tracking_code='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tracking, 'sys_products_orders') : 'uid='.intval($orderUid)).' AND deleted=0');
00741 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00742 }
00743
00748 function getOrderNumber($orderUid) {
00749 return substr($this->conf["orderNumberPrefix"],0,10).$orderUid;
00750 }
00751
00761 function finalizeOrder($orderUid,$mainMarkerArray=array()) {
00762
00763 $this->mapPersonIntoToDelivery();
00764 $mainMarkerArray["###EXTERNAL_COBJECT###"] = $this->externalCObject."";
00765 $orderConfirmationHTML=trim($this->getBasket("###BASKET_ORDERCONFIRMATION_TEMPLATE###","",$mainMarkerArray));
00766
00767
00768 $fieldsArray=array();
00769 $fieldsArray["note"]=$this->deliveryInfo["note"];
00770 $fieldsArray["name"]=$this->deliveryInfo["name"];
00771 $fieldsArray["telephone"]=$this->deliveryInfo["telephone"];
00772 $fieldsArray["email"]=$this->deliveryInfo["email"];
00773 $fieldsArray["email_notify"]= $this->conf["email_notify_default"];
00774
00775
00776 $fieldsArray["payment"]=$this->basketExtra["payment"].": ".$this->basketExtra["payment."]["title"];
00777 $fieldsArray["shipping"]=$this->basketExtra["shipping"].": ".$this->basketExtra["shipping."]["title"];
00778 $fieldsArray["amount"]=$this->calculatedSums_tax["total"];
00779 $fieldsArray["status"]=1;
00780
00781
00782 $status_log=array();
00783 $status_log[] = array(
00784 "time" => time(),
00785 "info" => $this->conf["statusCodes."][$fieldsArray["status"]],
00786 "status" => $fieldsArray["status"],
00787 "comment" => $this->deliveryInfo["note"]
00788 );
00789 $fieldsArray["status_log"]=serialize($status_log);
00790
00791
00792 $fieldsArray["orderData"]=serialize(array(
00793 "html_output" => $orderConfirmationHTML,
00794 "deliveryInfo" => $this->deliveryInfo,
00795 "personInfo" => $this->personInfo,
00796 "calculatedBasket" => $this->calculatedBasket,
00797 "calculatedSum_tax" => $this->calculatedSums_tax,
00798 "calculatedSums_no_tax" => $this->calculatedSums_no_tax
00799 ));
00800
00801
00802 $fieldsArray["tstamp"]=time();
00803 $fieldsArray["deleted"]=0;
00804 $fieldsArray["tracking_code"]=$this->recs["tt_products"]["orderTrackingNo"];
00805
00806
00807 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_products_orders', 'uid='.intval($orderUid), $fieldsArray);
00808
00809
00810 $this->orderRecord = $this->getOrderRecord($orderUid);
00811
00812
00813
00814
00815 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_products_orders_mm_tt_products', 'sys_products_orders_uid='.intval($orderUid));
00816
00817
00818 reset($this->calculatedBasket);
00819 while(list(,$itemInfo)=each($this->calculatedBasket)) {
00820 $insertFields = array(
00821 'sys_products_orders_uid' => $orderUid,
00822 'sys_products_orders_qty' => intval($itemInfo['count']),
00823 'tt_products_uid' => intval($itemInfo['rec']['uid'])
00824 );
00825 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_products_orders_mm_tt_products', $insertFields);
00826 }
00827
00828
00829 $headers=array();
00830 if ($this->conf["orderEmail_from"]) {$headers[]="FROM: ".$this->conf["orderEmail_fromName"]." <".$this->conf["orderEmail_from"].">";}
00831
00832 $recipients = $this->conf["orderEmail_to"];
00833 $recipients.=",".$this->deliveryInfo["email"];
00834 $recipients=t3lib_div::trimExplode(",",$recipients,1);
00835
00836 if (count($recipients)) {
00837 $emailContent=trim($this->getBasket("###EMAIL_PLAINTEXT_TEMPLATE###"));
00838 if ($emailContent) {
00839 $parts = split(chr(10),$emailContent,2);
00840 $subject=trim($parts[0]);
00841 $plain_message=trim($parts[1]);
00842
00843
00844 $cls = t3lib_div::makeInstanceClassName("tt_products_htmlmail");
00845 if (class_exists($cls) && $this->conf["orderEmail_htmlmail"]) {
00846 $HTMLmailShell=$this->cObj->getSubpart($this->templateCode,"###EMAIL_HTML_SHELL###");
00847 $HTMLmailContent=$this->cObj->substituteMarker($HTMLmailShell,"###HTML_BODY###",$orderConfirmationHTML);
00848 $HTMLmailContent=$this->cObj->substituteMarkerArray($HTMLmailContent, $this->globalMarkerArray);
00849
00850
00851
00852 if ($this->conf["orderEmail_htmlmail."]["removeImagesWithPrefix"]) {
00853 $parser = t3lib_div::makeInstance("t3lib_parsehtml");
00854 $htmlMailParts = $parser->splitTags("img",$HTMLmailContent);
00855
00856 reset($htmlMailParts);
00857 while(list($kkk,$vvv)=each($htmlMailParts)) {
00858 if ($kkk%2) {
00859 list($attrib) = $parser->get_tag_attributes($vvv);
00860 if (t3lib_div::isFirstPartOfStr($attrib["src"],$this->conf["orderEmail_htmlmail."]["removeImagesWithPrefix"])) {
00861 #debug($htmlMailParts[$kkk]);
00862 $htmlMailParts[$kkk]="";
00863 }
00864 }
00865 }
00866 $HTMLmailContent=implode("",$htmlMailParts);
00867 }
00868
00869 $V = array (
00870 "from_email" => $this->conf["orderEmail_from"],
00871 "from_name" => $this->conf["orderEmail_fromName"]
00872 );
00873
00874 $Typo3_htmlmail = t3lib_div::makeInstance("tt_products_htmlmail");
00875 $Typo3_htmlmail->useBase64();
00876 $Typo3_htmlmail->start(implode($recipients,","), $subject, $plain_message, $HTMLmailContent, $V);
00877
00878
00879
00880
00881 $Typo3_htmlmail->sendtheMail();
00882
00883
00884 } else {
00885 $GLOBALS["TSFE"]->plainMailEncoded(implode($recipients,","), $subject, $plain_message, implode($headers,chr(10)));
00886 }
00887 }
00888 }
00889
00890
00891 $GLOBALS["TSFE"]->fe_user->setKey("ses","recs",$this->getClearBasketRecord());
00892
00893
00894
00895 $this->getExternalCObject("externalFinalizing");
00896 }
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00911 function getPrice($price,$tax=1) {
00912 $taxFactor = 1+$this->TAXpercentage/100;
00913 $taxIncluded = $this->conf["TAXincluded"];
00914 if ($tax) {
00915 if ($taxIncluded) {
00916 return doubleval($price);
00917 } else {
00918 return doubleval($price)*$taxFactor;
00919 }
00920 } else {
00921 if ($taxIncluded) {
00922 return doubleval($price)/$taxFactor;
00923 } else {
00924 return doubleval($price);
00925 }
00926 }
00927 }
00928
00932 function searchWhere($sw) {
00933 $where=$this->cObj->searchWhere($sw, $this->searchFieldList, 'tt_products');
00934 return $where;
00935 }
00936
00940 function getLinkUrl($id="",$excludeList="") {
00941 $queryString=array();
00942 $queryString["id"] = ($id ? $id : $GLOBALS["TSFE"]->id);
00943 $queryString["type"]= $GLOBALS["TSFE"]->type ? 'type='.$GLOBALS["TSFE"]->type : "";
00944 $queryString["backPID"]= 'backPID='.$GLOBALS["TSFE"]->id;
00945 $queryString["begin_at"]= t3lib_div::_GP("begin_at") ? 'begin_at='.t3lib_div::_GP("begin_at") : "";
00946 $queryString["swords"]= t3lib_div::_GP("swords") ? "swords=".rawurlencode(t3lib_div::_GP("swords")) : "";
00947
00948 reset($queryString);
00949 while(list($key,$val)=each($queryString)) {
00950 if (!$val || ($excludeList && t3lib_div::inList($excludeList,$key))) {
00951 unset($queryString[$key]);
00952 }
00953 }
00954 return $GLOBALS["TSFE"]->absRefPrefix.'index.php?'.implode($queryString,"&");
00955 }
00956
00960 function priceFormat($double) {
00961 return number_format($double,intval($this->conf["priceDec"]),$this->conf["priceDecPoint"],$this->conf["priceThousandPoint"]);
00962 }
00963
00967 function mapPersonIntoToDelivery() {
00968 $infoFields = explode(",","name,address,telephone,fax,email,company,city,zip,state,country");
00969 while(list(,$fName)=each($infoFields)) {
00970 if (!trim($this->deliveryInfo[$fName])) {
00971 $this->deliveryInfo[$fName] = $this->personInfo[$fName];
00972 }
00973 }
00974 }
00975
00979 function checkRequired() {
00980 $flag=1;
00981 if (trim($this->conf["requiredInfoFields"])) {
00982 $infoFields = t3lib_div::trimExplode(",",$this->conf["requiredInfoFields"]);
00983 while(list(,$fName)=each($infoFields)) {
00984 if (!trim($this->personInfo[$fName])) {
00985 $flag=0;
00986 break;
00987 }
00988 }
00989 }
00990 return $flag;
00991 }
00992
00996 function includeCalcScript($calcScript,$conf) {
00997 include($calcScript);
00998 }
00999
01003 function includeHandleScript($handleScript,$conf) {
01004 include($handleScript);
01005 return $content;
01006 }
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01021 function getItemMarkerArray ($row,$catTitle, $imageNum=0, $imageRenderObj="image") {
01022
01023 $markerArray=array();
01024
01025 $theImgCode="";
01026 $imgs = explode(",",$row["image"]);
01027 $val = $imgs[0];
01028 while(list($c,$val)=each($imgs)) {
01029 if ($c==$imageNum) break;
01030 if ($val) {
01031 $this->conf[$imageRenderObj."."]["file"] = "uploads/pics/".$val;
01032 } else {
01033 $this->conf[$imageRenderObj."."]["file"] = $this->conf["noImageAvailable"];
01034 }
01035 $theImgCode.=$this->cObj->IMAGE($this->conf[$imageRenderObj."."]);
01036 }
01037
01038 $markerArray["###PRODUCT_TITLE###"] = $row["title"];
01039 $markerArray["###PRODUCT_NOTE###"] = nl2br($row["note"]);
01040 if (is_array($this->conf["parseFunc."])) {
01041 $markerArray["###PRODUCT_NOTE###"] = $this->cObj->parseFunc($markerArray["###PRODUCT_NOTE###"],$this->conf["parseFunc."]);
01042 }
01043 $markerArray["###PRODUCT_ITEMNUMBER###"] = $row["itemnumber"];
01044 $markerArray["###PRODUCT_IMAGE###"] = $theImgCode;
01045 $markerArray["###PRICE_TAX###"] = $this->priceFormat($this->getPrice($row["price"]));
01046 $markerArray["###PRICE_NO_TAX###"] = $this->priceFormat($this->getPrice($row["price"],0));
01047 $markerArray["###PRODUCT_INSTOCK###"] = $row["inStock"];
01048
01049 $markerArray["###CATEGORY_TITLE###"] = $catTitle;
01050
01051 $markerArray["###FIELD_NAME###"]="recs[tt_products][".$row["uid"]."]";
01052 $markerArray["###FIELD_QTY###"]= $this->basket[$row["uid"]] ? $this->basket[$row["uid"]] : "";
01053
01054 if ($this->conf["itemMarkerArrayFunc"]) {
01055 $markerArray = $this->userProcess("itemMarkerArrayFunc",$markerArray);
01056 }
01057
01058 return $markerArray;
01059 }
01060
01064 function userProcess($mConfKey,$passVar) {
01065 if ($this->conf[$mConfKey]) {
01066 $funcConf = $this->conf[$mConfKey."."];
01067 $funcConf["parentObj"]=&$this;
01068 $passVar = $GLOBALS["TSFE"]->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
01069 }
01070 return $passVar;
01071 }
01072
01076 function addURLMarkers($markerArray) {
01077
01078 $markerArray["###FORM_URL###"] = $this->getLinkUrl($this->conf["PIDbasket"]);
01079 $markerArray["###FORM_URL_INFO###"] = $this->getLinkUrl($this->conf["PIDinfo"] ? $this->conf["PIDinfo"] : $this->conf["PIDbasket"]);
01080 $markerArray["###FORM_URL_FINALIZE###"] = $this->getLinkUrl($this->conf["PIDfinalize"] ? $this->conf["PIDfinalize"] : $this->conf["PIDbasket"]);
01081 $markerArray["###FORM_URL_THANKS###"] = $this->getLinkUrl($this->conf["PIDthanks"] ? $this->conf["PIDthanks"] : $this->conf["PIDbasket"]);
01082 $markerArray["###FORM_URL_TARGET###"] = "_self";
01083
01084 if ($this->basketExtra["payment."]["handleURL"]) {
01085 $markerArray["###FORM_URL_THANKS###"] = $this->basketExtra["payment."]["handleURL"];
01086 }
01087 if ($this->basketExtra["payment."]["handleTarget"]) {
01088 $markerArray["###FORM_URL_TARGET###"] = $this->basketExtra["payment."]["handleTarget"];
01089 }
01090 return $markerArray;
01091 }
01092
01096 function generateRadioSelect($key) {
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106 $type=$this->conf[$key."."]["radio"];
01107 $active = $this->basketExtra[$key];
01108 $confArr = $this->cleanConfArr($this->conf[$key."."]);
01109 $out="";
01110
01111 $template = $this->conf[$key."."]["template"] ? $this->conf[$key."."]["template"] : '<nobr>###IMAGE### <input type="radio" name="recs[tt_products]['.$key.']" onClick="submit()" value="###VALUE###"###CHECKED###> ###TITLE###</nobr><BR>';
01112 $wrap = $this->conf[$key."."]["wrap"] ? $this->conf[$key."."]["wrap"] :'<select name="recs[tt_products]['.$key.']" onChange="submit()">|</select>';
01113
01114 while(list($key,$val)=each($confArr)) {
01115 if ($val["show"] || !isset($val["show"])) {
01116 if ($type) {
01117 $markerArray=array();
01118 $markerArray["###VALUE###"]=intval($key);
01119 $markerArray["###CHECKED###"]=(intval($key)==$active?" checked":"");
01120 $markerArray["###TITLE###"]=$val["title"];
01121 $markerArray["###IMAGE###"]=$this->cObj->IMAGE($val["image."]);
01122 $out.=$this->cObj->substituteMarkerArrayCached($template, $markerArray);
01123 } else {
01124 $out.='<option value="'.intval($key).'"'.(intval($key)==$active?" selected":"").'>'.htmlspecialchars($val["title"]).'</option>';
01125 }
01126 }
01127 }
01128 if (!$type) {
01129 $out=$this->cObj->wrap($out,$wrap);
01130 }
01131 return $out;
01132 }
01133 function cleanConfArr($confArr,$checkShow=0) {
01134 $outArr=array();
01135 if (is_array($confArr)) {
01136 reset($confArr);
01137 while(list($key,$val)=each($confArr)) {
01138 if (!t3lib_div::testInt($key) && intval($key) && is_array($val) && (!$checkShow || $val["show"] || !isset($val["show"]))) {
01139 $outArr[intval($key)]=$val;
01140 }
01141 }
01142 }
01143 ksort($outArr);
01144 reset($outArr);
01145 return $outArr;
01146 }
01150 function getBasket($subpartMarker="###BASKET_TEMPLATE###", $templateCode="", $mainMarkerArray=array()) {
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167 $templateCode = $templateCode ? $templateCode : $this->templateCode;
01168 $this->calculatedBasket = array();
01169
01170
01171 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_products', 'uid IN ('.$this->uid_list.') AND pid IN ('.$this->pid_list.')'.$this->cObj->enableFields('tt_products'));
01172 $productsArray = array();
01173 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01174 $productsArray[$row["pid"]][] = $row;
01175 }
01176
01177
01178
01179 $t=array();
01180
01181 $t["basketFrameWork"] = $this->cObj->getSubpart($templateCode,$this->spMarker($subpartMarker));
01182 if (trim($this->cObj->getSubpart($t["basketFrameWork"],"###BILLING_ADDRESS_LOGIN###"))) {
01183 if ($GLOBALS["TSFE"]->loginUser) {
01184 $t["basketFrameWork"] = $this->cObj->substituteSubpart($t["basketFrameWork"], "###BILLING_ADDRESS###", "");
01185 } else {
01186 $t["basketFrameWork"] = $this->cObj->substituteSubpart($t["basketFrameWork"], "###BILLING_ADDRESS_LOGIN###", "");
01187 }
01188 }
01189
01190 $t["categoryTitle"] = $this->cObj->getSubpart($t["basketFrameWork"],"###ITEM_CATEGORY###");
01191 $t["itemFrameWork"] = $this->cObj->getSubpart($t["basketFrameWork"],"###ITEM_LIST###");
01192 $t["item"] = $this->cObj->getSubpart($t["itemFrameWork"],"###ITEM_SINGLE###");
01193
01194 $pageArr=explode(",",$this->pid_list);
01195 $currentP="";
01196 $out="";
01197
01198
01199 $this->calculatedSums_tax=array();
01200 $this->calculatedSums_no_tax=array();
01201
01202 while(list(,$v)=each($pageArr)) {
01203 if (is_array($productsArray[$v])) {
01204 reset($productsArray[$v]);
01205 $itemsOut="";
01206 while(list(,$row)=each($productsArray[$v])) {
01207
01208 if ($row["pid"]."_".$row["category"]!=$currentP) {
01209 if ($itemsOut) {
01210 $out.=$this->cObj->substituteSubpart($t["itemFrameWork"], "###ITEM_SINGLE###", $itemsOut);
01211 }
01212 $itemsOut="";
01213 $currentP = $row["pid"]."_".$row["category"];
01214 if ($this->conf["displayBasketCatHeader"]) {
01215 $markerArray=array();
01216 $catTitle= $this->pageArray[$row["pid"]]["title"].($row["category"]?"/".$this->categories[$row["category"]]:"");
01217 $this->cObj->setCurrentVal($catTitle);
01218 $markerArray["###CATEGORY_TITLE###"]=$this->cObj->cObjGetSingle($this->conf["categoryHeader"],$this->conf["categoryHeader."], "categoryHeader");
01219 $out.= $this->cObj->substituteMarkerArray($t["categoryTitle"], $markerArray);
01220 }
01221 }
01222
01223
01224 $wrappedSubpartArray=array();
01225 $markerArray = $this->getItemMarkerArray ($row,$catTitle,1,"basketImage");
01226
01227 $calculatedBasketItem = array(
01228 "priceTax" => $this->getPrice($row["price"]),
01229 "priceNoTax" => $this->getPrice($row["price"],0),
01230 "count" => intval($this->basket[$row["uid"]]),
01231 "rec" => $row
01232 );
01233 $calculatedBasketItem["totalTax"] = $calculatedBasketItem["priceTax"]*$calculatedBasketItem["count"];
01234 $calculatedBasketItem["totalNoTax"] = $calculatedBasketItem["priceNoTax"]*$calculatedBasketItem["count"];
01235 $markerArray["###PRICE_TOTAL_TAX###"]=$this->priceFormat($calculatedBasketItem["totalTax"]);
01236 $markerArray["###PRICE_TOTAL_NO_TAX###"]=$this->priceFormat($calculatedBasketItem["totalNoTax"]);
01237
01238 $wrappedSubpartArray["###LINK_ITEM###"]=array('<A href="'.$this->getLinkUrl($this->conf["PIDitemDisplay"]).'&tt_products='.$row["uid"].'">','</A>');
01239
01240 $itemsOut.= $this->cObj->substituteMarkerArrayCached($t["item"],$markerArray,array(),$wrappedSubpartArray);
01241
01242 $this->calculatedSums_tax["goodstotal"]+= $calculatedBasketItem["totalTax"];
01243 $this->calculatedSums_no_tax["goodstotal"]+= $calculatedBasketItem["totalNoTax"];
01244 $this->calculatedBasket[] = $calculatedBasketItem;
01245 }
01246 if ($itemsOut) {
01247 $out.=$this->cObj->substituteSubpart($t["itemFrameWork"], "###ITEM_SINGLE###", $itemsOut);
01248 }
01249 }
01250 }
01251
01252
01253 $markerArray=$mainMarkerArray;
01254
01255
01256 $markerArray["###PRICE_GOODSTOTAL_TAX###"] = $this->priceFormat($this->calculatedSums_tax["goodstotal"]);
01257 $markerArray["###PRICE_GOODSTOTAL_NO_TAX###"] = $this->priceFormat($this->calculatedSums_no_tax["goodstotal"]);
01258
01259
01260
01261 $this->calculatedSums_tax["shipping"]=doubleVal($this->basketExtra["shipping."]["priceTax"]);
01262 $this->calculatedSums_no_tax["shipping"]=doubleVal($this->basketExtra["shipping."]["priceNoTax"]);
01263 $perc = doubleVal($this->basketExtra["shipping."]["percentOfGoodstotal"]);
01264 if ($perc) {
01265 $this->calculatedSums_tax["shipping"]+= $this->calculatedSums_tax["goodstotal"]/100*$perc;
01266 $this->calculatedSums_no_tax["shipping"]+= $this->calculatedSums_no_tax["goodstotal"]/100*$perc;
01267 }
01268 if ($this->basketExtra["shipping."]["calculationScript"]) {
01269 $calcScript = $GLOBALS["TSFE"]->tmpl->getFileName($this->basketExtra["shipping."]["calculationScript"]);
01270 if ($calcScript) {
01271 $this->includeCalcScript($calcScript,$this->basketExtra["shipping."]["calculationScript."]);
01272 }
01273 }
01274
01275 $markerArray["###PRICE_SHIPPING_PERCENT###"] = $perc;
01276 $markerArray["###PRICE_SHIPPING_TAX###"] = $this->priceFormat($this->calculatedSums_tax["shipping"]);
01277 $markerArray["###PRICE_SHIPPING_NO_TAX###"] = $this->priceFormat($this->calculatedSums_no_tax["shipping"]);
01278
01279 $markerArray["###SHIPPING_SELECTOR###"] = $this->generateRadioSelect("shipping");
01280 $markerArray["###SHIPPING_IMAGE###"] = $this->cObj->IMAGE($this->basketExtra["shipping."]["image."]);
01281 $markerArray["###SHIPPING_TITLE###"] = $this->basketExtra["shipping."]["title"];
01282
01283
01284
01285 $this->calculatedSums_tax["payment"]=doubleVal($this->basketExtra["payment."]["priceTax"]);
01286 $this->calculatedSums_no_tax["payment"]=doubleVal($this->basketExtra["payment."]["priceNoTax"]);
01287 $perc = doubleVal($this->basketExtra["payment."]["percentOfGoodstotal"]);
01288 if ($perc) {
01289 $this->calculatedSums_tax["payment"]+= $this->calculatedSums_tax["goodstotal"]/100*$perc;
01290 $this->calculatedSums_no_tax["payment"]+= $this->calculatedSums_no_tax["goodstotal"]/100*$perc;
01291 }
01292 if ($this->basketExtra["payment."]["calculationScript"]) {
01293 $calcScript = $GLOBALS["TSFE"]->tmpl->getFileName($this->basketExtra["payment."]["calculationScript"]);
01294 if ($calcScript) {
01295 $this->includeCalcScript($calcScript,$this->basketExtra["payment."]["calculationScript."]);
01296 }
01297 }
01298
01299 $markerArray["###PRICE_PAYMENT_PERCENT###"] = $perc;
01300 $markerArray["###PRICE_PAYMENT_TAX###"] = $this->priceFormat($this->calculatedSums_tax["payment"]);
01301 $markerArray["###PRICE_PAYMENT_NO_TAX###"] = $this->priceFormat($this->calculatedSums_no_tax["payment"]);
01302
01303 $markerArray["###PAYMENT_SELECTOR###"] = $this->generateRadioSelect("payment");
01304 $markerArray["###PAYMENT_IMAGE###"] = $this->cObj->IMAGE($this->basketExtra["payment."]["image."]);
01305 $markerArray["###PAYMENT_TITLE###"] = $this->basketExtra["payment."]["title"];
01306
01307
01308
01309 $this->calculatedSums_tax["total"] = $this->calculatedSums_tax["goodstotal"];
01310 $this->calculatedSums_tax["total"]+= $this->calculatedSums_tax["payment"];
01311 $this->calculatedSums_tax["total"]+= $this->calculatedSums_tax["shipping"];
01312
01313 $this->calculatedSums_no_tax["total"] = $this->calculatedSums_no_tax["goodstotal"];
01314 $this->calculatedSums_no_tax["total"]+= $this->calculatedSums_no_tax["payment"];
01315 $this->calculatedSums_no_tax["total"]+= $this->calculatedSums_no_tax["shipping"];
01316
01317 $markerArray["###PRICE_TOTAL_TAX###"] = $this->priceFormat($this->calculatedSums_tax["total"]);
01318 $markerArray["###PRICE_TOTAL_NO_TAX###"] = $this->priceFormat($this->calculatedSums_no_tax["total"]);
01319
01320
01321
01322 $infoFields = explode(",","name,address,telephone,fax,email,company,city,zip,state,country");
01323 while(list(,$fName)=each($infoFields)) {
01324 $markerArray["###PERSON_".strtoupper($fName)."###"] = $this->personInfo[$fName];
01325 $markerArray["###DELIVERY_".strtoupper($fName)."###"] = $this->deliveryInfo[$fName];
01326 }
01327
01328 $markerArray["###PERSON_ADDRESS_DISPLAY###"] = nl2br($markerArray["###PERSON_ADDRESS###"]);
01329 $markerArray["###DELIVERY_ADDRESS_DISPLAY###"] = nl2br($markerArray["###DELIVERY_ADDRESS###"]);
01330
01331 $markerArray["###DELIVERY_NOTE###"] = $this->deliveryInfo["note"];
01332 $markerArray["###DELIVERY_NOTE_DISPLAY###"] = nl2br($markerArray["###DELIVERY_NOTE###"]);
01333
01334
01335
01336 $markerArray["###ORDER_UID###"] = $this->getOrderNumber($this->recs["tt_products"]["orderUid"]);
01337 $markerArray["###ORDER_DATE###"] = $this->cObj->stdWrap($this->recs["tt_products"]["orderDate"],$this->conf["orderDate_stdWrap."]);
01338 $markerArray["###ORDER_TRACKING_NO###"] = $this->recs["tt_products"]["orderTrackingNo"];
01339
01340
01341 $markerArray["###FE_USER_USERNAME###"] = $GLOBALS["TSFE"]->fe_user->user["username"];
01342 $markerArray["###FE_USER_UID###"] = $GLOBALS["TSFE"]->fe_user->user["uid"];
01343
01344
01345 $markerArray = $this->addURLMarkers($markerArray);
01346 $subpartArray = array();
01347 $wrappedSubpartArray = array();
01348
01349
01350 if (!$GLOBALS["TSFE"]->loginUser) {
01351 $subpartArray["###FE_USER_SECTION###"]="";
01352 }
01353 $bFrameWork = $t["basketFrameWork"];
01354
01355
01356 $subpartArray["###MESSAGE_SHIPPING###"] = $this->cObj->substituteMarkerArrayCached($this->cObj->getSubpart($bFrameWork,"###MESSAGE_SHIPPING_".$this->basketExtra["shipping"]."###"),$markerArray);
01357 $subpartArray["###MESSAGE_PAYMENT###"] = $this->cObj->substituteMarkerArrayCached($this->cObj->getSubpart($bFrameWork,"###MESSAGE_PAYMENT_".$this->basketExtra["payment"]."###"),$markerArray);
01358
01359 $bFrameWork=$this->cObj->substituteMarkerArrayCached($t["basketFrameWork"],$markerArray,$subpartArray,$wrappedSubpartArray);
01360
01361
01362 $out=$this->cObj->substituteSubpart($bFrameWork, "###ITEM_CATEGORY_AND_ITEMS###", $out);
01363 return $out;
01364 }
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01381 function shopAdmin() {
01382 $admin=0;
01383 if ($GLOBALS["TSFE"]->beUserLogin) {
01384 if (t3lib_div::_GP("update_code")==$this->conf["update_code"]) {
01385 $admin= 1;
01386 }
01387 }
01388 return $admin;
01389 }
01390
01394 function getTrackingInformation($orderRow, $templateCode) {
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412 $admin = $this->shopAdmin();
01413
01414 if ($orderRow["uid"]) {
01415
01416 $fieldsArray = array();
01417 $orderRecord = t3lib_div::_GP("orderRecord");
01418 if (isset($orderRecord["email_notify"])) {
01419 $fieldsArray["email_notify"]=$orderRecord["email_notify"];
01420 $orderRow["email_notify"] = $fieldsArray["email_notify"];
01421 }
01422 if (isset($orderRecord["email"])) {
01423 $fieldsArray["email"]=$orderRecord["email"];
01424 $orderRow["email"] = $fieldsArray["email"];
01425 }
01426
01427 if (is_array($orderRecord["status"])) {
01428 $status_log = unserialize($orderRow["status_log"]);
01429 reset($orderRecord["status"]);
01430 $update=0;
01431 while(list(,$val)=each($orderRecord["status"])) {
01432 if ($admin || ($val>=50 && $val<59)) {
01433 $status_log_element = array(
01434 "time" => time(),
01435 "info" => $this->conf["statusCodes."][$val],
01436 "status" => $val,
01437 "comment" => $orderRecord["status_comment"]
01438 );
01439 if ($orderRow["email"] && $orderRow["email_notify"]) {
01440 $this->sendNotifyEmail($orderRow["email"], $status_log_element, t3lib_div::_GP("tracking"), $this->getOrderNumber($orderRow["uid"]),$templateCode);
01441 }
01442 $status_log[] = $status_log_element;
01443 $update=1;
01444 }
01445 }
01446 if ($update) {
01447 $fieldsArray["status_log"]=serialize($status_log);
01448 $fieldsArray["status"]=$status_log_element["status"];
01449 if ($fieldsArray["status"] >= 100) {
01450
01451
01452
01453 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_products_orders_mm_tt_products', 'sys_products_orders_uid='.intval($orderRow['uid']));
01454 }
01455 }
01456 }
01457
01458 if (count($fieldsArray)) {
01459 $fieldsArray["tstamp"] = time();
01460
01461 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_products_orders', 'uid='.intval($orderRow["uid"]), $fieldsArray);
01462
01463 $orderRow = $this->getOrderRecord($orderRow["uid"]);
01464 }
01465 }
01466
01467
01468
01469
01470
01471 $content=$this->cObj->getSubpart($templateCode,"###TRACKING_DISPLAY_INFO###");
01472 $status_log = unserialize($orderRow["status_log"]);
01473 $orderData = unserialize($orderRow["orderData"]);
01474
01475
01476 $STATUS_ITEM=$this->cObj->getSubpart($content,"###STATUS_ITEM###");
01477 $STATUS_ITEM_c="";
01478 if (is_array($status_log)) {
01479 reset($status_log);
01480 while(list($k,$v)=each($status_log)) {
01481 $markerArray=Array();
01482 $markerArray["###ORDER_STATUS_TIME###"]=$this->cObj->stdWrap($v["time"],$this->conf["statusDate_stdWrap."]);
01483 $markerArray["###ORDER_STATUS###"]=$v["status"];
01484 $markerArray["###ORDER_STATUS_INFO###"]=$v["info"];
01485 $markerArray["###ORDER_STATUS_COMMENT###"]=nl2br($v["comment"]);
01486
01487 $STATUS_ITEM_c.=$this->cObj->substituteMarkerArrayCached($STATUS_ITEM, $markerArray);
01488 }
01489 }
01490
01491 $subpartArray=array();
01492 $subpartArray["###STATUS_ITEM###"]=$STATUS_ITEM_c;
01493
01494
01495
01496
01497 $markerArray=Array();
01498
01499
01500 if (!$GLOBALS["TSFE"]->beUserLogin) {
01501 $subpartArray["###ADMIN_CONTROL###"]="";
01502 } elseif ($admin) {
01503 $subpartArray["###ADMIN_CONTROL_DENY###"]="";
01504 } else {
01505 $subpartArray["###ADMIN_CONTROL_OK###"]="";
01506 }
01507 if ($GLOBALS["TSFE"]->beUserLogin) {
01508
01509 if (is_array($this->conf["statusCodes."])) {
01510 reset($this->conf["statusCodes."]);
01511 while(list($k,$v)=each($this->conf["statusCodes."])) {
01512 if ($k!=1) {
01513 $markerArray["###STATUS_OPTIONS###"].='<option value="'.$k.'">'.htmlspecialchars($k.": ".$v).'</option>';
01514 }
01515 }
01516 }
01517
01518
01519 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,name,tracking_code,amount', 'sys_products_orders', 'NOT deleted AND status!=0 AND status<100', '', 'crdate');
01520 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01521 $markerArray["###OTHER_ORDERS_OPTIONS###"].='<option value="'.$row["tracking_code"].'">'.htmlspecialchars($this->getOrderNumber($row["uid"]).": ".$row["name"]." (".$this->priceFormat($row["amount"])." ".$this->conf["currencySymbol"].")").'</option>';
01522 }
01523 }
01524
01525
01526
01527 $markerArray["###ORDER_HTML_OUTPUT###"] = $orderData["html_output"];
01528 $markerArray["###FIELD_EMAIL_NOTIFY###"] = $orderRow["email_notify"] ? " checked" : "";
01529 $markerArray["###FIELD_EMAIL###"] = $orderRow["email"];
01530 $markerArray["###ORDER_UID###"] = $this->getOrderNumber($orderRow["uid"]);
01531 $markerArray["###ORDER_DATE###"] = $this->cObj->stdWrap($orderRow["crdate"],$this->conf["orderDate_stdWrap."]);
01532 $markerArray["###TRACKING_NUMBER###"] = t3lib_div::_GP("tracking");
01533 $markerArray["###UPDATE_CODE###"] = t3lib_div::_GP("update_code");
01534
01535 $content= $this->cObj->substituteMarkerArrayCached($content, $markerArray, $subpartArray);
01536 return $content;
01537 }
01538
01542 function sendNotifyEmail($recipient, $v, $tracking, $uid, $templateCode) {
01543
01544 $headers=array();
01545 if ($this->conf["orderEmail_from"]) {$headers[]="FROM: ".$this->conf["orderEmail_fromName"]." <".$this->conf["orderEmail_from"].">";}
01546
01547 $recipients = $recipient;
01548 $recipients=t3lib_div::trimExplode(",",$recipients,1);
01549
01550 if (count($recipients)) {
01551 $emailContent=trim($this->cObj->getSubpart($templateCode,"###TRACKING_EMAILNOTIFY_TEMPLATE###"));
01552 if ($emailContent) {
01553
01554 $markerArray["###ORDER_STATUS_TIME###"]=$this->cObj->stdWrap($v["time"],$this->conf["statusDate_stdWrap."]);
01555 $markerArray["###ORDER_STATUS###"]=$v["status"];
01556 $markerArray["###ORDER_STATUS_INFO###"]=$v["info"];
01557 $markerArray["###ORDER_STATUS_COMMENT###"]=$v["comment"];
01558
01559 $markerArray["###ORDER_TRACKING_NO###"]=$tracking;
01560 $markerArray["###ORDER_UID###"]=$uid;
01561
01562 $emailContent=$this->cObj->substituteMarkerArrayCached($emailContent, $markerArray);
01563
01564 $parts = split(chr(10),$emailContent,2);
01565 $subject=trim($parts[0]);
01566 $plain_message=trim($parts[1]);
01567
01568
01569 $GLOBALS["TSFE"]->plainMailEncoded(implode($recipients,","), $subject, $plain_message, implode($headers,chr(10)));
01570
01571 }
01572 }
01573 }
01574 }
01575
01576
01577
01578 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_products/pi/class.tx_ttproducts.php"]) {
01579 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_products/pi/class.tx_ttproducts.php"]);
01580 }
01581
01582
01583 ?>