[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/order_editor/ -> javascript.php (source)

   1  <?php 
   2  /*
   3    $Id: javascript.php v5.0 08/05/2007 djmonkey1 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2007 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */   
  12  ?>
  13  
  14  <script language="javascript" type="text/javascript"><!--
  15  
  16  var xmlHttp = false;
  17  
  18  function  createRequest() {
  19      if(window.ActiveXObject) {
  20          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  21      } else if(window.XMLHttpRequest) {
  22          xmlHttp = new XMLHttpRequest();
  23      }
  24      
  25           if (!xmlHttp) {
  26           alert('<?php echo AJAX_CANNOT_CREATE_XMLHTTP; ?>');
  27           return false;
  28        }
  29   }   
  30  
  31  function rewriteDiv(field, stack) {
  32    
  33    if (stack == 'orders') {
  34    document.getElementById("ordersMessageStack").innerHTML ='<table><tr class="messageStackSuccess"><td class="messageStackSuccess"><?php echo tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . '&nbsp;' . sprintf(AJAX_MESSAGE_STACK_SUCCESS, 'field'); ?></td></tr></table>' ;
  35    
  36    document.getElementById("productsMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  37      
  38    document.getElementById("historyMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  39      
  40      }
  41    
  42    
  43    if (stack == 'products') {
  44    document.getElementById("productsMessageStack").innerHTML ='<table><tr class="messageStackSuccess"><td class="messageStackSuccess"><?php echo tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . '&nbsp;' . sprintf(AJAX_MESSAGE_STACK_SUCCESS, 'field'); ?></td></tr></table>' ;
  45    
  46    document.getElementById("historyMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  47    
  48    document.getElementById("ordersMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  49    
  50      }
  51    
  52    
  53    if (stack == 'history') {
  54    document.getElementById("historyMessageStack").innerHTML ='<table><tr class="messageStackSuccess"><td class="messageStackSuccess"><?php echo tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . '&nbsp;' . sprintf(AJAX_MESSAGE_STACK_SUCCESS, 'field'); ?></td></tr></table>' ;
  55    
  56    document.getElementById("ordersMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  57  
  58    document.getElementById("productsMessageStack").innerHTML ='<?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>' ;
  59    
  60      }   
  61             
  62    } //end function rewriteDiv
  63             
  64             
  65  function deleteDiv(div) {//can be used on any element with an id, not just divs, but if you want to delete a tr better to use deleteRow()
  66    document.getElementById(div).innerHTML = '' ;
  67    }
  68             
  69             
  70  function reloadDiv(div, data) {
  71    document.getElementById(div).innerHTML = data ;
  72    }
  73    
  74    
  75  function deleteRow(info, div) {
  76      var i = info.parentNode.parentNode.parentNode.rowIndex;
  77      document.getElementById(div).deleteRow(i);
  78     }
  79     
  80     
  81  function updateOrdersField(field, value) {
  82  
  83          createRequest();
  84          
  85          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_order_field&oID=<?php echo $_GET['oID']; ?>&field=" + field + "&new_value=" + value;
  86          
  87          xmlHttp.open("GET", url, true);
  88          
  89          xmlHttp.onreadystatechange=
  90                  function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'orders')}};
  91          
  92          xmlHttp.send(null);
  93  
  94  
  95  } //end function updatOrdersField
  96  
  97  function updateProductsField(action, pid, field, value, info) {
  98  
  99        createRequest();
 100  
 101          if ( (action == 'update') || (action == 'reload1') ) {
 102  
 103          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_product_field&oID=<?php echo $_GET['oID']; ?>&pid=" + pid + "&field=" + field + "&new_value=" + value;
 104  
 105          xmlHttp.open("GET", url, true);
 106  
 107              if (action == 'reload1') {
 108                  xmlHttp.onreadystatechange=
 109                    function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');obtainTotals();}};
 110              } else {//action == 'update'
 111                  xmlHttp.onreadystatechange=
 112                    function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');}};
 113              }
 114                  
 115          }//end if ( (action == 'update') || (action == 'reload1') ) {
 116          
 117          
 118          if (action == 'reload2') {
 119          
 120          var price = document.getElementById("update_products[" + pid + "][price]").value;
 121          var final_price = document.getElementById("update_products[" + pid + "][final_price]").value;
 122          
 123          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_product_value_field&oID=<?php echo $_GET['oID']; ?>&pid=" + pid + "&price=" + price + "&final_price=" + final_price;
 124  
 125          xmlHttp.open("GET", url, true);
 126  
 127          xmlHttp.onreadystatechange=
 128                  function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');obtainTotals();}};
 129          
 130          }//end if action == 'reload2'
 131  
 132  
 133          if ( (action == 'delete') && (field == 'delete') && (value == true) ){
 134  
 135            if (confirm('<?php echo AJAX_CONFIRM_PRODUCT_DELETE; ?>')) {
 136  
 137             var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=delete_product_field&oID=<?php echo $_GET['oID']; ?>&pid=" + pid + "&field=" + field + "&new_value=" + value;
 138  
 139             xmlHttp.open("GET", url, true);
 140  
 141             xmlHttp.onreadystatechange=
 142                     function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');deleteRow(info, 'productsTable');obtainTotals();}};
 143  
 144             }
 145           
 146       }//end if (action == 'delete') {
 147        
 148       xmlHttp.send(null);
 149  
 150  } //end function updateProductsField(action, pid, field, value) {
 151  
 152  
 153    function updateAttributesField (action, field, aid, pid, value) {
 154      
 155       createRequest();        
 156          
 157          if (action == 'simple') {
 158          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_attributes_field&oID=<?php echo $_GET['oID']; ?>&aid=" + aid +"&pid=" + pid + "&field=" + field + "&new_value=" + value;
 159          }
 160       
 161          if (action == 'hard') {
 162          var final_price = document.getElementById("update_products[" + pid + "][final_price]").value;
 163          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_attributes_field&oID=<?php echo $_GET['oID']; ?>&aid=" + aid +"&pid=" + pid + "&field=" + field + "&new_value=" + value + "&final_price=" + final_price;
 164          }
 165  
 166          xmlHttp.open("GET", url, true);
 167  
 168            if (action == 'simple') {
 169          
 170            xmlHttp.onreadystatechange=
 171                    function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');}};
 172  
 173            }//end if (action == 'simple') {
 174  
 175            
 176            if (action == 'hard') {
 177          
 178            xmlHttp.onreadystatechange=
 179                    function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');obtainTotals();}};
 180  
 181            }//end if (action == 'hard') {
 182       
 183         xmlHttp.send(null);
 184    
 185      }//end function updateAttributesField
 186      
 187      
 188      
 189  	function updateDownloads (field, did, pid, value) {
 190        
 191        createRequest();
 192        
 193          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_downloads&oID=<?php echo $_GET['oID']; ?>&pid=" + pid + "&field=" + field + "&new_value=" + value + "&did=" + did;
 194  
 195          xmlHttp.open("GET", url, true);
 196  
 197          xmlHttp.onreadystatechange=
 198                  function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'products');}};
 199                    
 200          xmlHttp.send(null);
 201      
 202      } //end function updateDownloads (field, did, pid) {
 203  
 204  
 205  function updateCommentsField(action, id, status, value, info) {
 206  
 207        if ( (status) && (status == true) && (action == 'delete') ) {
 208           if (confirm('<?php echo AJAX_CONFIRM_COMMENT_DELETE; ?>')) {
 209              
 210              createRequest();
 211              var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=delete_comment&cID=" + id + "&oID=<?php echo $_GET['oID']; ?>";
 212              xmlHttp.open("GET", url, true);
 213              
 214              xmlHttp.onreadystatechange=
 215                      function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'history');deleteRow(info, 'commentsTable')}};
 216          
 217              xmlHttp.send(null);
 218                      
 219              
 220           }
 221        }
 222              
 223       if (action == 'update') {
 224       
 225                createRequest();
 226              var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_comment&cID=" + id + "&comment=" + value + "&oID=<?php echo $_GET['oID']; ?>";
 227              xmlHttp.open("GET", url, true);
 228              
 229              xmlHttp.onreadystatechange=
 230                      function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'history');}};
 231          
 232              xmlHttp.send(null);
 233              
 234              }
 235              
 236    }//end function updateCommentsField(action, id, status) {
 237    
 238  
 239  function updateShippingZone(field, value) {
 240  
 241      updateOrdersField(field, value);
 242      
 243              if (confirm('<?php echo AJAX_CONFIRM_RELOAD_TOTALS; ?>')) {
 244              
 245                obtainTotals();
 246              
 247              }
 248  
 249  }//end function updateShippingZone(field, value) {
 250  
 251  
 252    function setShipping(method) {
 253      if (document.getElementById("ot_shipping[title]")) {
 254      document.getElementById("ot_shipping[title]").value = document.getElementById("update_shipping["+method+"][title]").value;
 255      document.getElementById("ot_shipping[value]").value = document.getElementById("update_shipping["+method+"][value]").value;
 256      document.getElementById("ot_shipping[id]").value = document.getElementById("update_shipping["+method+"][id]").value;
 257      <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>obtainTotals();<?php } ?>
 258      } <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?> else {
 259         
 260                if (confirm('<?php echo AJAX_SELECTED_NO_SHIPPING; ?>')) {
 261              
 262              createRequest();
 263              var title = document.getElementById("update_shipping["+method+"][title]").value;
 264              var value = document.getElementById("update_shipping["+method+"][value]").value;
 265              var id = document.getElementById("update_shipping["+method+"][id]").value;
 266              var sort_order = "<?php echo MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER ?>";
 267              var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=insert_shipping&title=" + title + "&id=" + id + "&value=" + value + "&sort_order=" + sort_order + "&oID=<?php echo $_GET['oID']; ?>";
 268              xmlHttp.open("GET", url, true);
 269              
 270              xmlHttp.onreadystatechange=
 271                      function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){reloadDiv('totalsBlock', xmlHttp.responseText);}};
 272          
 273              xmlHttp.send(null);
 274            
 275           }
 276        }<?php } ?>
 277     }
 278  
 279    function reloadTotals () { //this is called after a shipping method is added to an order that didn't previously have one
 280     //there's an onload command tucked in with the info icon used in conjunction with the order totals tooltip that fires this
 281      
 282      if (confirm('<?php echo AJAX_RELOAD_TOTALS; ?>')) {
 283      
 284          obtainTotals();
 285        
 286        }
 287      }
 288      
 289      
 290  
 291  		function currency(value) {
 292              var selObj = document.getElementById("update_info_payment_currency");
 293              var selIndex = selObj.selectedIndex;
 294              var currency;
 295              var currency_value;
 296              <?php
 297               $currency_query_raw = "SELECT code, value FROM " . TABLE_CURRENCIES . "";
 298               $currency_query = tep_db_query($currency_query_raw);
 299               while ($currency = tep_db_fetch_array($currency_query)) {
 300    echo '                  if (selObj.options[selIndex].value == \'' . $currency['code'] . '\') {' . "\n";
 301    echo '                  document.getElementById("update_info_payment_currency_value").value = \'' . $currency['value'] . '\';' . "\n";
 302    echo '                  currency = \'' . $currency['code'] . '\'' . "\n";
 303    echo '                  currency_value = \'' . $currency['value'] . '\'' . "\n";
 304    echo '                  }' . "\n";
 305              echo "\n";
 306              }
 307              ?>
 308              
 309          <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>
 310          
 311          createRequest();
 312          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=update_currency&oID=<?php echo $_GET['oID']; ?>&table=<?php echo TABLE_ORDERS; ?>&currency=" + currency + "&currency_value=" + currency_value;
 313          
 314          xmlHttp.open("GET", url, true);
 315          
 316          xmlHttp.onreadystatechange=
 317                  function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){rewriteDiv(xmlHttp.responseText, 'orders');obtainTotals();}};
 318           
 319          xmlHttp.send(null);
 320              
 321          <?php } ?>
 322              
 323          }
 324  
 325     
 326    function clearComments() {
 327              document.getElementById("notify").checked = false;
 328              document.getElementById("notify_comments").checked = false;
 329              document.getElementById("comments").value = '';
 330     }//end function clearComments()
 331  
 332  
 333     function getNewComment() { //this is used for inserting new commments
 334        
 335         createRequest();
 336         var status = document.getElementById("status").value;
 337         var notify = document.getElementById("notify").checked;
 338         var notifyComments = document.getElementById("notify_comments").checked;
 339         var comments = encodeURIComponent(document.getElementById("comments").value);
 340         var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=insert_new_comment&oID=<?php echo $_GET['oID']; ?>&status=" + status +"&notify=" + notify + "&notify_comments=" + notifyComments + "&comments=" + comments;
 341          
 342          xmlHttp.open("GET", url, true);
 343          
 344          xmlHttp.onreadystatechange=
 345                  function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){reloadDiv('commentsBlock', xmlHttp.responseText);clearComments();}};
 346           
 347          xmlHttp.send(null);
 348          
 349     }//end function getNewComment()
 350  
 351    
 352    function obtainTotals() { //this is used for processing/updating order totals
 353    
 354      createRequest();
 355      
 356      // Set up data variable
 357      var formdata = "";
 358       
 359      // Loop through form fields
 360      for (i=0; i < document.edit_order.elements.length; i++) {
 361         formdata += encodeURIComponent(document.edit_order.elements[i].name) + "=" + encodeURIComponent(document.edit_order.elements[i].value) + "&";
 362       }
 363            formdata += "action=reload_totals&";
 364            formdata += "oID=<?php echo $_GET['oID']; ?>"
 365          
 366       var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>";
 367       
 368        //hey- we're busy here
 369        document.getElementById("totalsBlock").innerHTML = '<div align="center"><img src="order_editor/images/working.gif"><br><?php echo AJAX_WORKING; ?><br></div>';  
 370        //if you do this before you loop the form the data will be lost
 371  
 372        xmlHttp.open("POST", url, true);//GET does not work with this data
 373       
 374        xmlHttp.onreadystatechange=
 375                function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){reloadDiv('totalsBlock', xmlHttp.responseText);}};
 376           
 377        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 378        xmlHttp.setRequestHeader("Content-length", formdata.length);
 379        xmlHttp.setRequestHeader("Connection", "close");
 380        xmlHttp.send(formdata);
 381            
 382      
 383     }//end function obtainTotals() {
 384     
 385     
 386     
 387     function newOrderEmail() { //sending out new order confirmation emails the AJAX way
 388      
 389       if (confirm('<?php echo AJAX_NEW_ORDER_EMAIL; ?>')) {
 390        
 391          //var comments = prompt('<?php echo AJAX_INPUT_NEW_EMAIL_COMMENTS; ?>');
 392          //at this point it seems unneccessary to include admin comments with new order confirmation emails
 393          //the comments included with an original order email are written in by the customer, not admin
 394          //also, the prompt function within IE7 is disabled by default and works like something from 1997
 395       
 396          createRequest();
 397          //if (comments) { 
 398          //var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=new_order_email&comments=" + encodeURIComponent(comments) + "&oID=<?php echo $_GET['oID']; ?>";
 399          //} else {
 400          var url = "<?php echo FILENAME_ORDERS_EDIT_AJAX; ?>?action=new_order_email&oID=<?php echo $_GET['oID']; ?>";
 401          //}
 402          
 403          xmlHttp.open("GET", url, true);
 404          
 405          xmlHttp.onreadystatechange=
 406                 function(){if(xmlHttp.readyState!=4)return;if(xmlHttp.status==200){reloadDiv('ordersMessageStack', xmlHttp.responseText)}};
 407           
 408          xmlHttp.send(null);
 409     
 410       }
 411       
 412     }//end function newOrderEmail()
 413  
 414  ///end AJAX section
 415  
 416  
 417  ///begin standard JavaScript for edit_orders.php file
 418  
 419     function setAddressVisibility(szDivID, checkID) {
 420       var obj = document.getElementById(szDivID);
 421  
 422        if (checkID.checked) {
 423          obj.style.visibility = "hidden";
 424          obj.style.display = "none";
 425        } else {
 426          obj.style.visibility = "visible";
 427          
 428          //fix IE, since Microsoft isn't going to
 429          if (window.navigator.userAgent.indexOf('MSIE') != -1) { 
 430             obj.style.display = "inline"; //IE is not standards compliant, apparently not even IE7
 431          } else {        
 432             obj.style.display = "table-row";
 433          }//this should all just be obj.style.display = "table-row"; but IE is not standards compliant
 434                  
 435        }
 436      }
 437      
 438      
 439      function update_zone(countryID, zoneID, inputID, menuID) {
 440      var theForm = document.edit_order;
 441      var NumState = theForm[countryID].options.length;
 442      var SelectedCountry = '';
 443  
 444      while(NumState > 0) {
 445        NumState--;
 446        theForm[zoneID].options[NumState] = null;
 447      }
 448  
 449      SelectedCountry = theForm[countryID].options[theForm[countryID].selectedIndex].value;
 450  
 451  <?php echo oe_js_zone_list('SelectedCountry', 'theForm', 'zoneID', 'inputID', 'menuID'); ?>
 452    }
 453  
 454   
 455       function setStateVisibility(ID, vis, ID2) {
 456      
 457        var obj = document.getElementById(ID);
 458        var obj2 = document.getElementById(ID2);
 459  
 460        if (vis == "hidden") {
 461          obj.style.visibility = "hidden";
 462          obj.style.display = "none";
 463          obj2.style.visibility = "visible";
 464          obj2.style.display = "inline";
 465        } else {
 466          obj.style.visibility = "visible";
 467          obj.style.display = "inline";
 468          obj2.style.visibility = "hidden";
 469          obj2.style.display = "none";
 470       
 471           } //end if vis == hidden
 472       } //end function
 473       
 474       
 475    function openWindow(file, windowName) {
 476      msgWindow = window.open(file, windowName,'top=250, left=250, width=550, height=450, location=0, status=1, toolbar=0, resize=1');
 477      if (!msgWindow.opener) msgWindow.opener = self;
 478    }
 479  
 480  
 481    function selectRowEffect(object, buttonSelect) {
 482      document.getElementById("shipping_radio_" + buttonSelect).checked=true;
 483    }
 484    
 485  
 486    function rowOverEffect(object) {
 487      object.className = 'dataTableRowSelected';
 488    }
 489  
 490    function rowOutEffect(object, oldClass) {
 491      object.className = oldClass;
 492    }
 493  
 494    function setVisibility(id, checkID) {
 495      var obj;
 496      
 497      obj = document.getElementById(id);
 498    
 499      if (obj != null) {
 500        if (obj.style) {
 501          obj = obj.style;
 502        }
 503        if (checkID.checked == true) {
 504          obj.visibility = 'visible';
 505        } else {
 506          obj.visibility = 'hidden';
 507        }
 508      }
 509    }
 510  
 511  
 512  
 513    function setCustomOTVisibility(ID, vis, ID2) {
 514  
 515        var obj = document.getElementById(ID);
 516        var obj2 = document.getElementById(ID2);
 517  
 518        if (vis == "hidden") {
 519          obj.style.visibility = "hidden";
 520          obj.style.display = "none";
 521          obj2.style.visibility = "visible";
 522          obj2.style.display = "inline";
 523        } else {
 524          obj.style.visibility = "visible";
 525          
 526            //fix IE, since Microsoft can't
 527            if (window.navigator.userAgent.indexOf('MSIE') != -1) { 
 528            obj.style.display = "inline"; //IE is not standards compliant, apparently not even IE7
 529            } else {        
 530            obj.style.display = "table-row";
 531            }//this should all just be obj.style.display = "table-row", however IE is not standards compliant
 532          
 533          obj2.style.visibility = "hidden";
 534          obj2.style.display = "none";
 535       
 536        } //end if (vis == "hidden") {
 537     } //end  function setCustomOTVisibility(ID, vis, ID2) {        
 538  
 539  
 540    function addLoadListener(fn)
 541  {
 542    if (typeof window.addEventListener != 'undefined')
 543    {
 544      window.addEventListener('load', fn, false);
 545    }
 546    else if (typeof document.addEventListener != 'undefined')
 547    {
 548      document.addEventListener('load', fn, false);
 549    }
 550    else if (typeof window.attachEvent != 'undefined')
 551    {
 552      window.attachEvent('onload', fn);
 553    }
 554    else
 555    {
 556      var oldfn = window.onload;
 557      if (typeof window.onload != 'function')
 558      {
 559        window.onload = fn;
 560      }
 561      else
 562      {
 563        window.onload = function()
 564        {
 565          oldfn();
 566          fn();
 567        };
 568      }
 569    }
 570  } // end function addLoadListener(fn)
 571  
 572  
 573  <?php echo "ORDER_EDITOR_PAYMENT_DROPDOWN = '" . ORDER_EDITOR_PAYMENT_DROPDOWN . "';"; ?>
 574  
 575  
 576  addLoadListener(init);
 577  
 578  function init()
 579  {
 580    var optional = document.getElementById("optional");
 581    if (optional) {
 582    optional.className = "hidden";
 583    }
 584    //START dropdown option for payment method by quick_fixer
 585        if (ORDER_EDITOR_PAYMENT_DROPDOWN == 'true') {
 586              var selObj = document.getElementById('update_info_payment_method');
 587              if (selObj) { var selIndex = selObj.selectedIndex; }
 588          
 589          //text in lieu of value supported by firefox and mozilla but not others SO MAKE SURE text and optional value are the same (in the payment dropdown they are)
 590              if (selObj.options[selIndex].text) {
 591                  var paymentMethod = selObj.options[selIndex].text;
 592              }
 593              else {
 594                  var paymentMethod = selObj.options[selIndex].value;
 595              }
 596          }
 597          else {
 598              //if you only use an input field to display payment method use this
 599              var selObj = document.getElementById('update_info_payment_method');
 600              if (selObj) { var paymentMethod = selObj.value; }
 601          }
 602                            
 603      //END dropdown option for payment method by quick_fixer
 604  
 605    if (optional) {
 606    if (paymentMethod == "<?php echo ORDER_EDITOR_CREDIT_CARD ?>") {
 607    optional.className = "";
 608    return true;
 609    } else {
 610    optional.className = "hidden";
 611    return true;
 612    }
 613    }
 614    
 615  } // end function init()
 616  
 617    function updatePrices(action, pid, taxdescription) { 
 618    //calculates all the different values as new entries are typed
 619      var qty = document.getElementById("update_products[" + pid + "][qty]").value;
 620      var taxRate = document.getElementById("update_products[" + pid + "][tax]").value;
 621      var attValue = getAttributesPrices(pid);    
 622      
 623      if ((action == 'qty') || (action == 'tax') || (action == 'att_price') || (action == 'price')) {
 624      
 625      var finalPriceValue = document.getElementById("update_products[" + pid + "][price]").value;
 626      var priceInclValue = document.getElementById("update_products[" + pid + "][price]").value;
 627      var totalInclValue = document.getElementById("update_products[" + pid + "][price]").value;
 628      var totalExclValue = document.getElementById("update_products[" + pid + "][price]").value;
 629              
 630      finalPriceValue = Number(attValue) + Number(finalPriceValue);
 631      priceInclValue = ( Number(attValue) + Number(priceInclValue) ) * ((taxRate / 100) + 1);
 632      totalInclValue = ( Number(attValue) + Number(totalInclValue) ) * ((taxRate / 100) + 1) * qty;
 633      totalExclValue = ( Number(attValue) + Number(totalExclValue) ) * qty;
 634      taxValue = taxRate * finalPriceValue / 100 * qty;
 635      
 636      }
 637      
 638      if (action == 'final_price') {
 639      
 640      var priceValue = document.getElementById("update_products[" + pid + "][final_price]").value;
 641      var priceInclValue = document.getElementById("update_products[" + pid + "][final_price]").value;
 642      var totalInclValue = document.getElementById("update_products[" + pid + "][final_price]").value;
 643      var totalExclValue = document.getElementById("update_products[" + pid + "][final_price]").value;
 644              
 645      priceValue = Number(priceValue) - Number(attValue);
 646      priceInclValue = priceInclValue * ((taxRate / 100) + 1);
 647      totalInclValue = totalInclValue * ((taxRate / 100) + 1) * qty;
 648      totalExclValue = totalExclValue * qty;
 649              
 650      } //end if ((action == 'qty') || (action == 'tax') || (action == 'final_price')) 
 651      
 652      if (action == 'price_incl') {
 653      
 654      var priceValue = document.getElementById("update_products[" + pid + "][price_incl]").value;
 655      var finalPriceValue = document.getElementById("update_products[" + pid + "][price_incl]").value;
 656      var totalInclValue = document.getElementById("update_products[" + pid + "][price_incl]").value;
 657      var totalExclValue = document.getElementById("update_products[" + pid + "][price_incl]").value;
 658          
 659      priceValue = Number(finalPriceValue / ((taxRate / 100) + 1)) - Number(attValue);
 660      finalPriceValue = finalPriceValue / ((taxRate / 100) + 1);
 661      totalInclValue = totalInclValue * qty;
 662      totalExclValue = totalExclValue * qty / ((taxRate / 100) + 1);
 663          
 664      } //end of if (action == 'price_incl')
 665      
 666      if (action == 'total_excl') {
 667      
 668      var priceValue = document.getElementById("update_products[" + pid + "][total_excl]").value;
 669      var finalPriceValue = document.getElementById("update_products[" + pid + "][total_excl]").value;
 670      var priceInclValue = document.getElementById("update_products[" + pid + "][total_excl]").value;
 671      var totalInclValue = document.getElementById("update_products[" + pid + "][total_excl]").value;
 672              
 673      priceValue = ( Number (finalPriceValue / qty) ) - Number (attValue);
 674      finalPriceValue = finalPriceValue / qty;
 675      priceInclValue = priceInclValue * ((taxRate / 100) + 1) / qty;
 676      totalInclValue = totalInclValue * ((taxRate / 100) + 1);
 677          
 678      } //end of if (action == 'total_excl')
 679      
 680      if (action == 'total_incl') {
 681      
 682      var priceValue = document.getElementById("update_products[" + pid + "][total_incl]").value;
 683      var finalPriceValue = document.getElementById("update_products[" + pid + "][total_incl]").value;
 684      var priceInclValue = document.getElementById("update_products[" + pid + "][total_incl]").value;
 685      var totalExclValue = document.getElementById("update_products[" + pid + "][total_incl]").value;
 686          
 687      priceValue = Number (finalPriceValue / ((taxRate / 100) + 1) / qty) - Number(attValue)
 688      finalPriceValue = finalPriceValue / ((taxRate / 100) + 1) / qty;
 689      priceInclValue = priceInclValue / qty;
 690      totalExclValue = totalExclValue / ((taxRate / 100) + 1);
 691          
 692      } //end of if (action == 'total_incl')
 693      
 694  
 695      if ((action != 'qty') && (action != 'tax') && (action != 'att_price') && (action != 'price')) {
 696      document.getElementById("update_products[" + pid + "][price]").value = doFormat(priceValue, 4);
 697      }
 698      
 699      if (action != 'final_price') {
 700      document.getElementById("update_products[" + pid + "][final_price]").value = doFormat(finalPriceValue, 4);
 701      }
 702      
 703      if ((action != 'qty') && (action != 'price_incl')) {
 704      document.getElementById("update_products[" + pid + "][price_incl]").value = doFormat(priceInclValue, 4);
 705      }
 706      
 707      if ((action != 'tax') && (action != 'total_excl')) {
 708      document.getElementById("update_products[" + pid + "][total_excl]").value = doFormat(totalExclValue, 4);
 709      }
 710      
 711      if (action != 'total_incl') {
 712      document.getElementById("update_products[" + pid + "][total_incl]").value = doFormat(totalInclValue, 4);
 713      }
 714      
 715      } //end function updatePrices(action, pid)
 716  
 717     function getAttributesPrices(pid){ //get any attributes prices that may exist 
 718      var sum =0;
 719      var el=document.getElementsByTagName('input');//all the input elements
 720        for(var i=0;i<el.length;i++){
 721         if(el[i].id.indexOf(pid)>-1){
 722          var aid=el[i].id.replace(pid,'').replace('p', '').replace('a', '');//extract the attribute id
 723          var p=el[i].id.replace(pid,'').replace(/\d/g,'');
 724            if((p=='pa') && (document.getElementById('p' + pid + '_' + aid + '_prefix')) && (document.getElementById('p' + pid + '_' + aid + '_prefix').value) == '-') {
 725             sum-=Number(el[i].value);
 726            }
 727            if((p=='pa') && (document.getElementById('p' + pid + '_' + aid + '_prefix')) && (document.getElementById('p' + pid + '_' + aid + '_prefix').value) == '+') {
 728             sum+=Number(el[i].value);
 729            }
 730           }
 731          }
 732        return sum
 733       } //end function getAttributePrices(pid)
 734       
 735  	function doRound(x, places) {  //we only have so much space
 736       return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
 737      }
 738   
 739      function doFormat(x, places) { //keeps all calculated values the same length
 740      var a = doRound(x, places);
 741      var s = a.toString();
 742  
 743      var decimalIndex = s.indexOf(".");
 744        
 745        if (places > 0 && decimalIndex < 0) {
 746           decimalIndex = s.length;
 747           s += '.';
 748         }
 749       
 750        while (decimalIndex + places + 1 > s.length) {
 751           s += '0';
 752        }
 753    
 754      return s;
 755    
 756      } // end function doFormat
 757  
 758  //--></script>
 759  
 760  <?php ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7