Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/ECommerce/ECCheckout/ECCheckout.php - 1245 lines - 59048 bytes - Summary - Text - Print

   1  <?php
   2  require_once(T_APP_BASE . "ECommerce/eccorefunctions.php");
   3  require_once(T_CODE_BASE . "Widget/FormBuilderOptionWidget.php");
   4  
   5  class ECCheckout extends App
   6    {
   7    function onInit()
   8      {
   9      $this->mode = isset($this->httpVars['mode']) ? $this->httpVars['mode'] : '';
  10      }
  11  
  12    function onSave()
  13      {
  14      if($this->mode == '')
  15        {
  16        $setting['nopayreq'] = $this->httpVars['nopayreq'];
  17        $setting['creditcard'] = $this->httpVars['creditcard'];
  18        $setting['authorizer'] = $this->httpVars['authorizer'];
  19        $setting['email'] = $this->httpVars['email'];
  20        $setting['emailaddress'] = $this->httpVars['emailaddress'];
  21        
  22        //credit card options
  23        $setting['acceptvisa'] = $this->httpVars['acceptvisa'];
  24        $setting['acceptmastercard'] = $this->httpVars['acceptmastercard'];
  25        $setting['acceptdiscover'] = $this->httpVars['acceptdiscover']; 
  26        $setting['requestshipping'] = $this->httpVars['requestshipping'];
  27        $setting['accountnumber'] = $this->httpVars['accountnumber'];
  28        $setting['transdesc'] = $this->httpVars['transdesc'];
  29        $setting['subsid'] = $this->httpVars['subsid'];
  30        $setting['projectcode'] = $this->httpVars['projectcode'];
  31        $setting['debug'] = $this->httpVars['debug'];      
  32        
  33        // check options
  34        $setting['eventpaymentdefer'] = $this->httpVars['event_payment_defer'];
  35        if($this->httpVars['event_payment_defer'] == "")
  36          {
  37          $this->httpVars['checks_payable'] = "";
  38          $this->httpVars['checks_location'] = "";
  39          }
  40        $setting['checkspayable'] = $this->httpVars['checks_payable'];
  41        $setting['checkslocation'] = $this->httpVars['checks_location'];
  42        // pjh 6/2/2006
  43        $ret = Plugins::dohook('cvhook_checkoutAdminOnSave', array($this->httpVars));
  44        if(!is_array($ret))
  45            $ret = array();
  46        foreach ($ret as $r)
  47          $setting = array_merge($r, $setting);
  48        
  49        
  50        $this->saveSettings($setting);
  51        }
  52      }
  53  
  54    function getContent()
  55      {
  56      // pjh 08/02/2006
  57      if ($_GET['mode'] == 'paypal') 
  58        $_POST['shipping_method'] = 'none';
  59        
  60      if($_GET['mode'] == 'info')
  61        $_POST['shipping_method'] = 'none';
  62      else if($_POST['shipping_method'] == "")
  63        return "This page can only be reached from the shopping cart.";
  64      eccorefunctions::connectToDB();
  65      
  66      // calculate the cost of the items
  67      $items = eccorefunctions::getCookieItems();
  68      $events = eccorefunctions::getCookieEvents();
  69  
  70      if($items == "" && $events == "")
  71        return "Thank you for your purchase.";
  72      // get the items unique types and then     
  73      $formsets = eccorefunctions::getUniqueFormsets($items, $events);
  74      // this needs to be added into the getcookieevents function at some point and rempved from here
  75      if (!is_array($events)) $events = array();
  76      foreach($events as $eid => $evalue)
  77          {
  78          $query = "SELECT event_query_each 
  79                      FROM ec_event
  80                     WHERE event_id = " . $eid;
  81          $res = $this->db->query($query);
  82          $row = $res->fetchrow(DB_FETCHMODE_ASSOC);
  83          $row = array_change_key_case($row, CASE_LOWER);                   
  84          $events[$eid]['event_query_each'] = $row['event_query_each'];
  85          if(!isset($this->queryEach))
  86              $this->queryEach = $row['event_query_each'];
  87          }           
  88  
  89      $all_plugins = array();
  90      if(is_array($items))
  91        {
  92        foreach($items as $key => $value)
  93          {
  94          $items[$key]['formset_associated_plugins'] = $formsets[$items[$key]['formset_id']]['formset_associated_plugins'];
  95          $all_plugins = @array_merge($all_plugins, $formsets[$items[$key]['formset_id']]['formset_associated_plugins']);
  96          $items[$key]['formset_fields'] = $formsets[$items[$key]['formset_id']]['formset_fields'];
  97          $items[$key]['formset_name'] = $formsets[$items[$key]['formset_id']]['formset_name'];
  98          $items[$key]['formset_notifier'] = $formsets[$items[$key]['formset_id']]['formset_notifier'];      
  99          }
 100        }
 101  
 102      if(is_array($events))
 103        {
 104        foreach($events as $key => $value)
 105          {
 106          $events[$key]['formset_associated_plugins'] = $formsets[$events[$key]['formset_id']]['formset_associated_plugins'];
 107          $all_plugins = @array_merge($all_plugins, $formsets[$events[$key]['formset_id']]['formset_associated_plugins']);
 108          $events[$key]['formset_fields'] = $formsets[$events[$key]['formset_id']]['formset_fields'];
 109          $events[$key]['formset_name'] = $formsets[$events[$key]['formset_id']]['formset_name'];
 110          $events[$key]['formset_notifier'] = $formsets[$events[$key]['formset_id']]['formset_notifier'];      
 111          
 112          foreach($value['subevents'] as $k => $v)
 113            {
 114            $events[$key]['subevents'][$k]['formset_associated_plugins'] = $formsets[$events[$key]['subevents'][$k]['formset_id']]['formset_associated_plugins'];
 115            if($events[$key]['subevents'][$k]['quantity'] > 0)
 116              $all_plugins = @array_merge($all_plugins, $formsets[$events[$key]['subevents'][$k]['formset_id']]['formset_associated_plugins']);
 117            $events[$key]['subevents'][$k]['formset_fields'] = $formsets[$events[$key]['subevents'][$k]['formset_id']]['formset_fields'];
 118            $events[$key]['subevents'][$k]['formset_name'] = $formsets[$events[$key]['subevents'][$k]['formset_id']]['formset_name'];
 119            $events[$key]['subevents'][$k]['formset_notifier'] = $formsets[$events[$key]['subevents'][$k]['formset_id']]['formset_notifier'];      
 120            }
 121          }
 122        }       
 123      
 124      $retopts = Plugins::dohook('cvhook_getPostSaleOptions', array(""));
 125      $opts = $retopts[0];
 126      if($opts != "")
 127        {
 128        $opts = substr($opts, 0, strlen($opts) - 12);
 129        $tempoptsarr = explode("<postoption>", $opts);
 130        foreach($tempoptsarr as $val)
 131          {
 132          $tempoptsarr2 = explode("<separate>", $val);
 133          $optsarr[] = array('pluginname' => $tempoptsarr2[0], 'plugintext' => $tempoptsarr2[1]);
 134          }
 135        }
 136  
 137      if(!is_array($all_plugins))
 138          $all_plugins = array();
 139  
 140      // this makes sure that all the plugins associated with the items will still be processed
 141      foreach($all_plugins as $key => $val)
 142        {
 143        $pfound = false;
 144        foreach($optsarr as $k => $v)
 145          {
 146          if($v['pluginname'] == $key)
 147            $pfound = true;
 148          }
 149        
 150        if($pfound == false)
 151          {
 152          new mnAlert('Postsale Plugin error!');
 153          return "";
 154          }
 155        }
 156  
 157      $fields = array();
 158      $first = true;
 159      $this->duplicates[] = array();
 160  
 161      if(is_array($formsets))
 162        {
 163        foreach($formsets as $key => $value)
 164          {
 165          if($first)
 166              {
 167              $this->firstKey = $value['formset_name'];
 168              $first = false;
 169              }
 170              
 171          for($z=1; $z <= $value['formset_dupl']; $z++)
 172            {
 173            $newfieldnames = $value['formset_fields'];
 174  
 175            foreach($newfieldnames as $ii => $rr)
 176                {
 177                if($newfieldnames[$ii]['label'] == '')
 178                  $newfieldnames[$ii]['label'] = $newfieldnames[$ii]['name'];
 179                $newfieldnames[$ii]['name'] = $newfieldnames[$ii]['name'].(($z > 1) ? "__mark__".$z : "");
 180                }
 181            
 182            $fields[$value['formset_name'].(($z > 1) ? " ".$z : "")] = $newfieldnames;
 183            if($z > 1)
 184                $this->duplicates[] = $value['formset_name']." ".$z;
 185            }
 186          }
 187        } 
 188  
 189      foreach($fields as $s1 => $s2)
 190          {  
 191          $fields[$s1] = FormBuilderOptionWidget::generateQueries($fields[$s1]);
 192          }
 193  
 194      foreach($fields as $s1 => $s2)
 195          {
 196          $fields[$s1] = FormBuilderOptionWidget::executeRetrieveQueries($fields[$s1], T_APP_BASE . "ECommerce/ECCheckout/.dbrc");
 197          }
 198          
 199      //calculate the cost of the items and events
 200      if(is_array($events))
 201        {
 202        foreach($events as $key => $val)
 203          {
 204          foreach($val['subevents'] as $k => $v)
 205            {
 206            $total = $v['quantity'] * $v['priceper'];
 207            $beforeshippingamount += $total;
 208            }
 209          }
 210        }
 211      
 212      if(is_array($items))
 213          {
 214          foreach($items as $key => $val)
 215            {
 216            $total = $val['quantity'] * $items[$key]['priceper'];
 217            $beforeshippingamount += $total;          
 218            }
 219          }
 220      // calculate the shipping costs
 221      if($_POST['shipping_method'] != "none")
 222        {
 223        if($this->params['shipping_same'] == 1)
 224          $shipping_zip = $this->params['billing_zip'];
 225        else
 226          $shipping_zip = $this->params['shipping_zip'];  
 227                             
 228        if($_POST['shipping_method'] != "ups")
 229          $shipping = eccorefunctions::calculateShipping($items, $beforeshippingamount, $_POST['shipping_method'], $_POST['shipping_option']);
 230        else
 231          {
 232          $shipping = eccorefunctions::calculateShipping($items, $beforeshippingamount, $_POST['shipping_method'], $_POST['shipping_option'], $shipping_zip, $_POST['ups_service_type']);
 233          }
 234        }
 235  
 236      $amount = $beforeshippingamount + $shipping;
 237  
 238      if ($this->params['checkout_submit'] == 1 && $this->params['paypal_payment'] == true)
 239          {
 240          $ret = Plugins::dohook('cvhook_getCheckoutForm', array($this->params, $_POST, $items, $this->httpVars));        
 241          if ($ret[0]) 
 242            return $ret[0];
 243          }
 244  
 245  
 246      else if($this->params['checkout_submit'] == 1 || $_GET['mode'] == 'paypal') // pjh 10/02/2005
 247        {
 248        // billing vars        
 249        $billing_state = ($this->params['billing_outside'] == "") ? $this->params['billing_state'] : "";
 250          
 251        if($this->settingsVars['requestshipping'] != "")
 252          {
 253          //shipping vars
 254          if($this->params['shipping_same'] == 1)
 255            {
 256            $shipping_state = ($this->params['billing_outside'] == "") ? $this->params['billing_state'] : "";
 257            $shipping_street_address = $this->params['billing_street_address'];
 258            $shipping_city = $this->params['billing_city'];
 259            $shipping_zip = $this->params['billing_zip'];
 260            $shipping_country = $this->params['billing_country'];
 261            }
 262          else
 263            {  
 264            $shipping_state = ($this->params['shipping_outside'] == "") ? $this->params['shipping_state'] : "";
 265            $shipping_street_address = $this->params['shipping_street_address'];
 266            $shipping_city = $this->params['shipping_city'];
 267            $shipping_zip = $this->params['shipping_zip'];
 268            $shipping_country = $this->params['shipping_country'];
 269            }
 270          }  
 271  
 272        if($this->settingsVars['creditcard'] != ""  || $this->params['defer_payment'] == true || ($this->params['nopayreq'] != "" && $amount == 0))
 273          {
 274          global $plugin_hook;
 275          $plugin_hook['cvhook_authorizeCommerce'][$this->settingsVars['authorizer']] = 'doProcessCard';              
 276          
 277          // general vars
 278          $card_number = $this->params['card1'].$this->params['card2'].$this->params['card3'].$this->params['card4'];
 279          $expire = $this->params['cardmonth']."-".$this->params['cardyear'];
 280  
 281          
 282          if($this->params['defer_payment'] == "" && !($this->params['nopayreq'] != "" && $amount == 0))
 283            {
 284            if($this->settingsVars['requestshipping'] != "")
 285              $res = Plugins::dohook('cvhook_authorizeCommerce', array($amount, $this->settingsVars['accountnumber'], $this->params['credittype'], $this->params['cardholderfirst'], $this->params['cardholderlast'], $card_number, $expire, $this->settingsVars['transdesc'], $this->params['billing_street_address'], $this->params['billing_city'], $billing_state, $this->params['billing_zip'], $this->params['billing_country'], $this->settingsVars['subsid'], $this->settingsVars['projectcode'], 1, $shipping_street_address, $shipping_city, $shipping_state, $shipping_zip, $shipping_country));
 286            else if ($_GET['mode'] == 'paypal') 
 287              {
 288              $auth_token = $this->settingsVars['paypalauthtoken']; 
 289              $res = Plugins::dohook('cvhook_authorizeCommerce', array(array($auth_token)));
 290              $keyarray = $res[0];
 291              $status = 1;
 292              // item fields
 293              $fields = array();
 294              $x = 1;
 295              //print_r($keyarray);
 296              while (isset($keyarray['option_selection1_'. $x]))
 297                {
 298                //$tmp[$keyarray['option_name1_'. $x]] = $keyarray['option_selection1_'. $x]; 
 299                
 300                $tmp = explode('&', $keyarray['option_selection1_'. $x]);
 301                foreach ($tmp as $v) 
 302                    {
 303                    $tmp2 = explode('=', $v);
 304                  if ($tmp2[1] != 'linebreak')
 305                        $fields[$tmp2[0]] = array(array('type' => 'hidden', 'name' => $tmp2[1], 'label' => $tmp2[1]));
 306                    
 307                    }
 308                $x++;
 309                }
 310              $shipping = $keyarray['mc_shipping'];
 311              $beforeshippingamount = $keyarray['mc_gross'] - $keyarray['mc_shipping'];
 312              $firstname = $keyarray['first_name'];
 313              $lastname = $keyarray['last_name'];
 314              $itemname = $keyarray['item_name'];
 315              $amount = $keyarray['payment_gross'];
 316  
 317              $shipping_state = $keyarray['address_state'];
 318              $shipping_street_address = $keyarray['address_street'];
 319              $shipping_city = $keyarray['address_city'];
 320              $shipping_zip =    $keyarray['address_zip'];
 321              $shipping_country =    $keyarray['address_country'];
 322  
 323              $billing_state = $shipping_state;
 324              $billing_zip_code = $shipping_zip;
 325              $billing_address = $shipping_street_address;
 326              $billing_state = $shipping_state;
 327              $billing_country = $shipping_country;
 328              $billing_city = $shipping_city;
 329              $transaction_desc = $keyarray['txn_id'];
 330              $account_number = $keyarray['receiver_id'];
 331              $card_holder_name = $firstname ." ". $lastname;
 332              }
 333            else
 334              $res = Plugins::dohook('cvhook_authorizeCommerce', array($amount, $this->settingsVars['accountnumber'], $this->params['credittype'], $this->params['cardholderfirst'], $this->params['cardholderlast'], $card_number, $expire, $this->settingsVars['transdesc'], $this->params['billing_street_address'], $this->params['billing_city'], $billing_state, $this->params['billing_zip'], $this->params['billing_country'], $this->settingsVars['subsid'], $this->settingsVars['projectcode'], 0));            
 335            $status = isset($status) ? $status : $res[0];
 336            }
 337          else
 338            {
 339            $status = 1;
 340            }
 341  
 342          if($status == 1)
 343            {
 344            if(T_ORG_DN == "dc=checkin,dc=www,dc=goshen,dc=edu")
 345              {
 346              if($this->params['personalfname'] == "" || $this->params['personallname'] == "" || $this->params['vehiclelicense'] == '' || $this->params['vehiclelicense'] == '')
 347                {
 348                return 'There was an error processing your registration. Please try to submit it once more. If you continue to have difficulties please contact the <a href="mailto:arachnid@goshen.edu">webmaster</a>.';
 349                }
 350              }
 351              
 352            // billing the credit card was successful          
 353            // first store in postgres
 354            $fields = isset($fields) ? $fields : unserialize(urldecode($_POST['poss_fields'])); // pjh
 355            if (!is_array($fields)) $fields = array();
 356            foreach($fields as $fkey => $fval)
 357              {
 358              $otherfields .= $fkey."\n";
 359              $otherfields_stored .= $fkey."\n";
 360              
 361              foreach($fval as $key => $val)
 362                {
 363                if($val['type'] == 'newsection' || $val['type'] == 'linebreak' || $val['type'] == '' || $val['type'] == 'hidden')
 364                    {}
 365                else
 366                    {    
 367                    $otherfields .=  "&nbsp;&nbsp;&nbsp;&nbsp;".($val['label'] == "" ? $val['name'] : $val['label']).": ".(is_array($this->params[str_replace(" ", "__", $val['name'])]) ? implode(",", $this->params[str_replace(" ", "__", $val['name'])]) : $this->params[str_replace(" ", "__", $val['name'])])."\n";
 368                    $otherfields_stored .=  ($val['label'] == "" ? $val['name'] : $val['label'])."::".(is_array($this->params[str_replace(" ", "__", $val['name'])]) ? implode(",", $this->params[str_replace(" ", "__", $val['name'])]) : $this->params[str_replace(" ", "__", $val['name'])])."\n";
 369                    }              
 370                }
 371              }
 372            if($this->params['defer_payment'] != "")
 373              $billmode = "Payment Defered";
 374            else if($this->params['nopayreq'] != "" && $amount == 0)
 375              $billmode = "No Cost";  
 376            else if ($_GET['mode'] == 'paypal')  // pjh 10/02/2006
 377              $billmode = "PayPal";
 378            else
 379              $billmode = "Credit Card";
 380  
 381            $order_id = eccorefunctions::addOrder($shipping_street_address, $shipping_city, $shipping_state, $shipping_zip, $billmode, $beforeshippingamount, $shipping, $items, $events, $otherfields_stored);
 382  
 383            // next mail the specified address with the order information
 384            $txt = "===============================================================\n";
 385            $txt .= "ORDER NO      : $order_id\n";
 386            $txt .= "ORDER TIME    : ".date("l F d Y h:i:s A")."\n";
 387            
 388            if(is_array($events))
 389              {
 390              $txt .= "ORDER CONTENT (Events) : \n";
 391              foreach($events as $key => $val)
 392                {
 393                $txt .= $val['event_name']."\n";
 394                //This is here to get the list of subevents shows up in the order of subevent_order instead of item _id.
 395                //theodoreb, June 18, 2007
 396                for($jo = 1;$jo <= count($val['subevents']);$jo++)
 397                    {
 398                  foreach($val['subevents'] as $k => $v)
 399                        {
 400                        if($jo == $v['subevent_order'])
 401                            $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$v['quantity']." x ".$v['item_name']." @ ".eccorefunctions::format_dollar_amount($v['priceper'])."\n";
 402                      }
 403                  }
 404                }
 405              }   
 406  
 407            if(is_array($items))
 408              {
 409              $txt .= "ORDER CONTENT (Items) : \n";
 410              foreach($items as $key => $val)
 411                $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$val['quantity']." x ".$items[$key]['item_name']." @ ".eccorefunctions::format_dollar_amount($val['priceper'])."\n";
 412              }
 413             
 414            $txt .= "\n";
 415            
 416            $txt .= "ORDER COST:\n";
 417            $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;SUBTOTAL : ".eccorefunctions::format_dollar_amount($beforeshippingamount)."\n";
 418            $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;SHIPPING : ".eccorefunctions::format_dollar_amount($shipping)."\n";
 419            $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;TOTAL    : ".eccorefunctions::format_dollar_amount($amount)."\n\n";
 420            
 421            if($this->params['defer_payment'] == ""  && !($this->params['nopayreq'] != "" && $amount == 0) && !$_GET['mode'] == 'paypal')
 422              {
 423              $txt .= "PAYMENT METHOD: Credit Card\n\n";
 424            
 425              if($_POST['shipping_method'] != "none")
 426                {
 427                $upss = array("01" => "Next Day Air", "02" => "2nd Day Air", "03" => "Ground"); 
 428                if($_POST['shipping_method'] == "ups")
 429                  $s_type = "UPS - " . $upss[$_POST['ups_service_type']]; 
 430                else
 431                  $s_type = "CUSTOM"; 
 432                
 433                $txt .= "SHIPPING METHOD: $s_type\n";
 434                $txt .= "SHIPPING ADDRESS:\n";
 435                $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$this->params['cardholderfirst']." ".$this->params['cardholderlast']."\n";
 436                $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;$shipping_street_address\n";
 437                $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;$shipping_city, $shipping_state $shipping_zip\n\n";
 438                }
 439               
 440              $notifier_txt .= $txt;
 441              $txt .= "BILLING ADDRESS:\n";
 442              $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$this->params['cardholderfirst']." ".$this->params['cardholderlast']."\n";
 443              $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$this->params['billing_street_address']."\n";
 444              $txt .= "&nbsp;&nbsp;&nbsp;&nbsp;".$this->params['billing_city'].", ". $billing_state ." ". $this->params['billing_zip']."\n\n"; 
 445              }
 446            else if($this->params['nopayreq'] != "" && $amount == 0)   
 447              {
 448              $txt .= "\n\n";
 449              $notifier_txt .= "\n\n";
 450              }
 451            else if ($_GET['mode'] == 'paypal')
 452                {
 453                $txt .= "Thank you for using PayPal.\n\n";
 454                $notifier_txt .= $txt;
 455                }
 456            else
 457              {
 458              $txt .= "PAYMENT METHOD: Payment Deferred\n\n";
 459              $txt .= "Please Note that your order will not be processed until payment is recieved.\n\n";
 460              $notifier_txt .= $txt;
 461              }            
 462            $txt .= "FORM INFORMATION:\n".$otherfields;
 463            $notifier_txt .= "FORM INFORMATION:\n".$otherfields;
 464            
 465            $txt .= "\n";
 466            $notifier_txt .= "\n";
 467            
 468            if($this->params['defer_payment'] != "")
 469              {
 470              @reset($events);
 471              $eventkey = @key($events);
 472              
 473              $defertext = "<br />&nbsp;<br /><span style=''>Please make checks payable to: <span style='font-weight: bold;'>".$this->settingsVars['checkspayable']."</span></span><br />
 474                             Mail checks to:<br /><div style='padding: 4px;'>".
 475                             str_replace("\n", "<br />", $this->settingsVars['checkslocation'])."<br />&nbsp;<br />";
 476              $defertextemail = "\nPlease make checks payable to: ".$this->settingsVars['checkspayable']."\n\nMail checks to:\n".$this->settingsVars['checkslocation']."\n\n";
 477              }
 478            else
 479              $defertext = "";  
 480            
 481            // finally process any plugins that exist and were specified to run
 482            if(is_array($optsarr))
 483              {
 484              foreach($optsarr as $key => $val)
 485                {
 486                //this is in case there is an error, so we don't mess things up
 487                if($val['pluginname'] != '')
 488                    {
 489                    global $plugin_hook;
 490                    $plugin_hook['cvhook_postsaleCommerce'][$val['pluginname']] = 'doPostAction';  
 491                    }
 492                }
 493              }  
 494             
 495            if (!is_array($fields)) $fields = array();           
 496            foreach($fields as $key => $value)
 497              {
 498              foreach($value as $k => $v)
 499                  $fields[$key][$k]['value'] =  $this->params[$v['name']];
 500              } 
 501            
 502            if (!is_array($fields)) $fields = array();
 503            
 504            unset($this->sequences);
 505            foreach($fields as $s1 => $s2)
 506                { 
 507                if(in_array($s1, $this->duplicates))
 508                    {
 509                    $newfield = $fields[$this->firstKey];
 510                    foreach($fields[$s1] as $uniquename => $queries)
 511                        {
 512                        $repl = substr($queries['name'], 0, strpos($queries['name'], "__mark__")); 
 513                        
 514                        foreach($fields[$s1] as $ee => $ee1)
 515                            {
 516                            $fields[$s1][$ee]['sto_query'] = str_replace('|' . $repl . '|', '|' . $queries['name'] . '|', $fields[$s1][$ee]['sto_query']);
 517                            $fields[$s1][$ee]['post_queries'] = str_replace('|' . $repl . '|', '|' . $queries['name'] . '|', $fields[$s1][$ee]['post_queries']);
 518                            }
 519                        foreach($newfield as $nn => $nn1)
 520                            {
 521                            $newfield[$nn]['sto_query'] = str_replace('|' . $repl . '|', '|' . $queries['name'] . '|', $newfield[$nn]['sto_query']);
 522                            $newfield[$nn]['post_queries'] = str_replace('|' . $repl . '|', '|' . $queries['name'] . '|', $newfield[$nn]['post_queries']);
 523                            }
 524                        }  
 525                    if($this->queryEach == 'Y')
 526                        {
 527                        $this->allsequences[] = $this->sequences;
 528                        unset($this->sequences);
 529                        FormBuilderOptionWidget::executeStoreQueries($newfield, $this->httpVars, T_APP_BASE . "EmailFeedback/.dbrc", $this->settingsVars['debug']);
 530                        }    
 531                    }
 532                  else
 533                    {
 534                    foreach($s2 as $uniquename => $queries)
 535                        {
 536                        preg_match('/\:.+\:/', $queries['sto_query'], $matches);
 537                        foreach($matches as $m1 => $m2)
 538                        {
 539                        if(is_array($events))
 540                          {
 541                          foreach($events as $key => $val)
 542                              {
 543                            foreach($val['subevents'] as $k => $v)
 544                                if(preg_match("/".$v['item_name' ]."/i", $m2))
 545                                $fields[$s1][$uniquename]['sto_query'] = str_replace($m2, $v['quantity'], $fields[$s1][$uniquename]['sto_query']);
 546                              }
 547                          }
 548                          }
 549                        }
 550                    }  
 551                    
 552                FormBuilderOptionWidget::executeStoreQueries($fields[$s1], $this->httpVars, T_APP_BASE . "EmailFeedback/.dbrc", $this->settingsVars['debug']);
 553                }
 554  
 555            $this->allsequences[] = $this->sequences;
 556            $fields['allsequences'] = $this->allsequences;    
 557  
 558            Plugins::dohook('cvhook_postsaleCommerce', array($beforeshippingamount, $shipping, $items, $events, $fields)); 
 559             
 560            $emailtxt = "";    
 561            if(is_array($this->sequences))    
 562                {
 563                $emailtxt = "FORM DB INFORMATION:\n";
 564                foreach($this->allsequences as $arr1)
 565                    {
 566                    if(!is_array($arr1))
 567                        $arr1 = array();
 568                    foreach($arr1 as $seqname => $seqval)
 569                        {
 570                        $emailtxt .= "    " . $seqname . ": " . $seqval . "\n";
 571                        }
 572                    }    
 573                }
 574                
 575            // finally email the information
 576            if($this->settingsVars['email'] != "")
 577              {
 578              //print "Mailing full order to ".$this->settingsVars['emailaddress']."<br>"; 
 579              mail($this->settingsVars['emailaddress'], "Caravel Order", $defertextemail."\n".str_replace("&nbsp;", " ", $txt . $emailtxt . "\n===============================================================\n"),
 580                   "From: caraveleccommerce@noreply.com\r\n" .
 581                   "Reply-To: caraveleccommerce@noreply.com\r\n" .
 582                   "X-Mailer: PHP/" . phpversion());
 583              }
 584            
 585            if(isset($formsets))
 586              { 
 587              foreach($formsets as $key => $val)
 588                {
 589                if(@$sent_mail[$val['formset_notifier']] == "")
 590                  {
 591                  $sent_mail[$val['formset_notifier']] = 1;
 592                  //print "Mailing ". $val['formset_notifier']."<br>";
 593                  mail($val['formset_notifier'], "Caravel Order", $defertextemail."\n".str_replace("&nbsp;", " ", $notifier_txt . $emailtxt . "\n===============================================================\n"),
 594                       "From: caraveleccommerce@caravelnoreply.com\r\n" .
 595                       "Reply-To: caraveleccommerce@caravelnoreply.com\r\n" .
 596                       "X-Mailer: PHP/" . phpversion());
 597                  }   
 598                }
 599              }
 600            $txt .= "\n===============================================================\n";
 601            $notifier_txt .= "\n===============================================================\n";    
 602            
 603            if($this->params['nopayreq'] != "" && $amount == 0)
 604                $txt_for_web = str_replace(array("\n", "==============================================================="), array("<br>", ""), $notifier_txt);
 605            else    
 606                $txt_for_web = str_replace("\n", "<br>", $txt);    
 607                
 608            // since everything was successful we can now clear the cookie so we dont accidentally bill them twice if they refresh
 609            eccorefunctions::deleteCookie(); 
 610            if($this->params['nopayreq'] != "" && $amount == 0)
 611              return "Your form has been successfully submited. Here is a copy of your records. <br>Please print this page for your own records. $defertext<br><br>$txt_for_web";
 612            else
 613              return "Your order was successfully completed. Below is a copy of your order for your records. <br>Please print this page for your own records. $defertext<br><br>$txt_for_web";  
 614            }
 615          else
 616            // billing failed let them know about it
 617            return "We were unable to bill your credit card, try entering your information again. We are sorry for the inconvenience."; 
 618          }
 619        }
 620  
 621      $tpl = new Template_PHPLIB($this->appBase);
 622      $tpl->setFile(array('main' => '/checkout.tpl.html'));
 623      // let the user know what they are paying
 624      $tpl->setVar('amount', eccorefunctions::format_dollar_amount($beforeshippingamount + $shipping));
 625  
 626  
 627      if($_POST['shipping_method'] == "ups")
 628        {
 629        $tpl->setVar('ups', "<span style='font-weight: bold; padding-right: 20px; margin: 0 0 0 40px;'>UPS Shipping Method</span>
 630  <div style='width: 80%;padding: 5px 2px 2px 2px; margin: 0 0 0 40px; border: solid 1px #000; background-color: #EEE;'>
 631  <div style='margin-left: 160px;'>
 632  UPS Shipping:&nbsp;<select name='ups_service_type'>
 633  <option value='03'>UPS Ground</option>
 634  <option value='01'>UPS Next Day Air</option>
 635  <option value='02'>UPS 2nd Day Air</option>
 636  </select>
 637  </div>
 638  </div>");
 639        }
 640  
 641      $tpl->setVar('shipping_method_val', $_POST['shipping_method']);
 642      $tpl->setVar('shipping_option_val', $_POST['shipping_option']);
 643      $tpl->setVar('beforeshippingamount', $beforeshippingamount); // pjh
 644      $tpl->setVar('checkout_submit', $this->paramName('checkout_submit'));    
 645  
 646      $linktoself = $this->linktoself();
 647      if ($this->settingsVars['authorizer'] != 'PayPal') 
 648          $tpl->setVar('linktoself', str_replace("http://", "http://", $linktoself)); 
 649      else
 650          $tpl->setVar('linktoself', $linktoself);
 651      $tpl->setVar('poss_fields', urlencode(serialize($fields)));
 652      $fcount = 0;
 653  
 654      foreach($fields as $k => $v)
 655        {
 656        foreach($v as $key => $val)
 657          {
 658          if($v[$key]['type'] == "checkbox")
 659            {
 660            if($v[$key]['label'] == "")
 661              $v[$key]['label'] = $v[$key]['name'];
 662  
 663            $v[$key]['name'] = $v[$key]['name'] . "[]";
 664            } 
 665        }
 666  
 667        foreach($v as $key => $val)
 668            {
 669            //don't display header if the section only contains hidden fields, theodoreb
 670            if($v[$key]['type'] != "newsection" && $v[$key]['type'] != "hidden" && $v[$key]['type'] != "")
 671              {
 672            $ffinal .= "<div style='padding: 5px;font-weight: bold;'>". $k . "</div>";
 673            break;
 674            }
 675          }
 676        $ffinal .= $this->getUserForm($v, $fcount);
 677        $fcount = $fcount + count($v);
 678        }
 679      $tpl->setVar('buyer_info_form', $ffinal);
 680  
 681      //form values to check
 682      $tpl->setVar('cardholderfirst', $this->paramName('cardholderfirst'));
 683      $tpl->setVar('cardholderlast', $this->paramName('cardholderlast'));
 684      $tpl->setVar('credittype', $this->paramName('credittype'));
 685      $tpl->setVar('card1', $this->paramName('card1'));
 686      $tpl->setVar('card2', $this->paramName('card2'));
 687      $tpl->setVar('card3', $this->paramName('card3'));
 688      $tpl->setVar('card4', $this->paramName('card4'));
 689      $tpl->setVar('cardyear', $this->paramName('cardyear'));
 690      $tpl->setVar('cardmonth', $this->paramName('cardmonth'));
 691      $tpl->setVar('billing_street_address', $this->paramName('billing_street_address'));
 692      $tpl->setVar('billing_city', $this->paramName('billing_city'));
 693      $tpl->setVar('billing_zip', $this->paramName('billing_zip'));
 694      $tpl->setVar('shipping_street_address', $this->paramName('shipping_street_address'));
 695      $tpl->setVar('shipping_city', $this->paramName('shipping_city'));
 696      $tpl->setVar('shipping_zip', $this->paramName('shipping_zip'));
 697      $tpl->setVar('shipping_same', $this->paramName('shipping_same'));
 698  
 699      // make sure that the extra information that is required is actually required by the javascript
 700      foreach($fields as $ii => $fields2)
 701        {
 702        foreach($fields2 as $i => $field)
 703          {
 704          if($field['reqd'] == "1")
 705            {
 706            if($field['type'] == 'checkbox')
 707              {
 708              }
 709            else
 710              {  
 711              $reqtext .= "if(document.checkoutform.".$this->paramName(str_replace(" ", "__", $field['name'])).".value == '')
 712          {
 713          missing[x] = '".($field['label'] == "" ? $field['name'] : $field['label'])."';
 714          x++;
 715          }
 716      
 717          ";
 718              }
 719            }
 720          }
 721        }  
 722      $tpl->setVar('extra_req', $reqtext);  
 723  
 724  
 725      if($this->settingsVars['creditcard'] != "")
 726        {
 727        $tpl->setVar('billedimmediate_hide', '');
 728        $tpl->setVar('checkcard', 'true');
 729        // the card billing information
 730        $f = FormWidget::init('', 'form.noformtag.tpl.html');
 731        $f->html("<table style='width: 100%;'>");
 732        
 733        
 734        if($this->settingsVars['eventpaymentdefer'] != "")
 735          {
 736          $tpl->setVar('defer_set', 'true');
 737          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
 738          $f->html("  <tr style='width: 100%;'>
 739                        <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 740                        Defer Payment (Pay by Check or Cash):
 741                        </td>
 742                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 743          $f->checkbox('defer_payment', ''); 
 744          $f->html("    </td>
 745                      </tr>
 746                      ");  
 747          }
 748        else
 749          {
 750          $tpl->setVar('defer_set', 'false');
 751          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
 752          }  
 753  
 754  
 755        // PayPal
 756        if ($this->settingsVars['authorizer'] == 'PayPal') { $pp = 1; }
 757        if ($pp)
 758            {
 759            $tpl->setVar('checkcard', 'false');
 760                $tpl->setVar('paypal_set', 'true');
 761          $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
 762  
 763          $f->html("  <tr style='widght: 100%;'>
 764                          <td style='width: 31%; text-align: right; vertical-align: top; padding: 0 5px 0 0;'>
 765                          Pay With PayPal:
 766                          </td>
 767                          <td style='margin: 2px; width: 52%; border: solid 1px #CCC;'>");
 768          $f->checkbox('paypal_payment', '');
 769          $f->html(" </td>
 770                    </tr>");
 771      
 772            }
 773        else
 774            {
 775            $tpl->setVar('paypal_set', 'false');
 776            $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
 777            }
 778  
 779        
 780        $cards = array();
 781        if($this->settingsVars['acceptvisa'] != "")
 782          $cards['Visa'] = 'Visa';
 783        if($this->settingsVars['acceptmastercard'] != "")
 784          $cards['MasterCard'] = 'Mastercard';
 785        if($this->settingsVars['acceptdiscover'] != "")
 786          $cards['Discover'] = 'Discover';    
 787  
 788        if (count($cards)) 
 789            {              
 790            $f->html(" <tr style='width: 100%;'>
 791                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 792                          Type of Card: 
 793                          </td>
 794                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 795  
 796            $f->radio('credittype', $cards);
 797            
 798            
 799            
 800            $f->html("    </td>
 801                        </tr>
 802                        ");
 803            $f->html("  <tr style='width: 100%;'>
 804                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 805                          First Name:
 806                          </td>
 807                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 808            $f->text('cardholderfirst', '', 25);          
 809            $f->html("    </td>
 810                        </tr>");
 811                        
 812            $f->html("  <tr style='width: 100%;'>
 813                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 814                          Last Name:
 815                          </td>
 816                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 817            $f->text('cardholderlast', '', 25);
 818            $f->html("    </td>
 819                        </tr>");            
 820                      
 821            $f->html("  <tr style='width: 100%;'>
 822                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 823                          Account number:
 824                          </td>
 825                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 826            $f->text('card1', '', 5);
 827            $f->html("-");
 828            $f->text('card2', '', 5);
 829            $f->html("-");
 830            $f->text('card3', '', 5);
 831            $f->html("-");
 832            $f->text('card4', '', 5);
 833            $f->html("    </td>
 834                        </tr>");          
 835                      
 836            $f->html("  <tr style='width: 100%;'>
 837                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 838                          Expiration date:
 839                          </td>
 840                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 841            //$f->text('cardmonth', '', 3);
 842            $months = array('01'=>'01','02'=>'02','03'=>'03','04'=>'04','05'=>'05','06'=>'06','07'=>'07','08'=>'08','09'=>'09','10'=>'10','11'=>'11','12'=>'12');
 843            $f->dropdown('cardmonth', $months);
 844            $f->html("&nbsp;");
 845            //$f->text('cardyear', '', 3);
 846            for($h=date('Y');$h < date('Y')+8;$h++)
 847                $years[substr($h,-2)] = $h; //value format should be yy, that's what the substr() for.
 848            $f->dropdown('cardyear', $years);
 849            //$f->html("(mm/yy)");
 850            $f->html("    </td>
 851                        </tr>
 852                      </table>");          
 853            
 854            $tpl->setVar('billing_info_form', $f->get());      
 855            $tpl->setVar('billing_info_header', "<span style='font-weight: bold; padding-right: 20px; margin: 0 0 0 40px;{billedinfo_hide}'>Billing Information</span>");
 856            
 857            // the billing address form
 858            $f = FormWidget::init('', 'form.noformtag.tpl.html');
 859            $f->html("<table style='width: 100%;'>
 860                        <tr style='width: 100%;'>
 861                          <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 862                          Street Address:
 863                          </td>
 864                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 865            $f->text('billing_street_address', '', 50);
 866            $f->html("    </td>
 867                        </tr>");
 868                      
 869            $f->html("  <tr style='width: 100%;'>
 870                           <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 871                           City:
 872                           </td>
 873                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 874            $f->text('billing_city', '', 30);
 875            $f->html("    </td>
 876                        </tr>");
 877                      
 878            $f->html("  <tr style='width: 100%;'>
 879                           <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 880                           State:
 881                           </td>
 882                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 883            $f->states('billing_state');
 884            $f->html('<br />');
 885            $f->checkbox('billing_outside', 0, 'Outside US or Canada', array('onclick' => "if(this.checked)
 886                                                                                             {
 887                                                                                             document.getElementById('".$this->paramName('billing_state')."').style.visibility = 'hidden';
 888                                                                                             }
 889                                                                                           else
 890                                                                                             {
 891                                                                                             document.getElementById('".$this->paramName('billing_state')."').style.visibility = 'visible';
 892                                                                                             }"));
 893            $f->html("    </td>
 894                        </tr>");          
 895  
 896            $f->html("   <tr style='width: 100%;'>
 897                           <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 898                           Country:
 899                           </td>
 900                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 901            $f->countries('billing_country');
 902            $f->html("    </td>
 903                        </tr>");
 904                      
 905            $f->html("  <tr style='width: 100%;'>
 906                           <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 907                           Zip:
 908                           </td>
 909                          <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 910            $f->text('billing_zip');
 911            $f->html("    </td>
 912                        </tr>
 913                      </table>");              
 914            $tpl->setVar('billingaddress_info_form', $f->get());
 915            $tpl->setVar('billingaddress_header', "<span style='font-weight: bold; padding-right: 20px; margin: 0 0 0 40px;{billedimmediate_hide}'>Billing Address</span>");
 916  
 917          }
 918        else
 919            {
 920            $tpl->setVar('billingaddress_info_form','');
 921            $f->html("</table>");
 922            $tpl->setVar('billing_info_form',$f->get());
 923            
 924            }          
 925        if($this->settingsVars['requestshipping'] != "")
 926          {
 927          $tpl->setVar('couldHide', '');
 928          $tpl->setVar('check_shipping', 'true');
 929          // the shipping address form
 930          $f = FormWidget::init('', 'form.noformtag.tpl.html');
 931          $f->html("<table style='width: 100%;'>
 932                      <tr style='width: 100%;'>
 933                         <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 934                         Same as Billing Address:
 935                         </td>
 936                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 937          $f->radio('shipping_same', array('1' => 'Yes', '0' => 'No'), 0);
 938          $f->html("    </td>
 939                      </tr>");
 940  
 941          $f->html("  <tr style='width: 100%;'>
 942                        <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 943                        Street Address:
 944                        </td>
 945                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 946          $f->text('shipping_street_address', '', 50);
 947          $f->html("    </td>
 948                      </tr>");
 949                    
 950          $f->html("   <tr style='width: 100%;'>
 951                         <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 952                         City:
 953                         </td>
 954                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 955          $f->text('shipping_city', '', 30);
 956          $f->html("    </td>
 957                      </tr>");
 958                    
 959          $f->html("  <tr style='width: 100%;'>
 960                         <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 961                         State:
 962                         </td>
 963                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 964          $f->states('shipping_state');
 965          $f->checkbox('shipping_outside', 0, 'Outside US or Canada', array('onclick' => "if(this.checked)
 966                                                                                           {
 967                                                                                           document.getElementById('".$this->paramName('shipping_state')."').style.visibility = 'hidden';
 968                                                                                           }
 969                                                                                         else
 970                                                                                           {
 971                                                                                           document.getElementById('".$this->paramName('shipping_state')."').style.visibility = 'visible';
 972                                                                                           }"));
 973          $f->html("    </td>
 974                      </tr>");          
 975  
 976          $f->html("  <tr style='width: 100%;'>
 977                         <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 978                         Country:
 979                         </td>
 980                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 981          $f->countries('shipping_country');
 982          $f->html("    </td>
 983                      </tr>");
 984                    
 985          $f->html("  <tr style='width: 100%;'>
 986                         <td style='width: 31%;text-align: right;vertical-align: top;padding: 0 5px 0 0;'>
 987                         Zip:
 988                         </td>
 989                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
 990          $f->text('shipping_zip');
 991          $f->html("    </td>
 992                      </tr>
 993                    </table>");              
 994          $tpl->setVar('shippingaddress_info_form', $f->get());
 995          }
 996        else 
 997          {
 998          $tpl->setVar('couldHide', 'display: none;');
 999          $tpl->setVar('check_shipping', 'false');
1000          }  
1001        $tpl->setVar('submit_button', '<button style="padding: 0px; background-color: #6c2875;color: #FFF;font-size: 10px;" onclick="document.checkoutform.'.$this->paramName('checkout_submit').'.value = 1;
1002                                                                                                if(okToSubmit())
1003                                                                                                  {
1004                                                                                                  document.checkoutform.submit();
1005                                                                                                  }
1006                                                                                                else
1007                                                                                                  {
1008                                                                                                  return false;
1009                                                                                                  }">Submit</button>');
1010  
1011        if($this->settingsVars['nopayreq'] && $amount == 0)
1012          {
1013          $tpl->setVar('paypal_set', 'false');
1014          $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
1015          $tpl->setVar('defer_set', 'false');
1016          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
1017          $tpl->setVar('billedinfo_hide', 'display: none;');
1018          $tpl->setVar('billing_info_form', '');
1019          $tpl->setVar('submit_button', '<button style="padding: 0px; background-color: #6c2875;color: #FFF;font-size: 10px;" onclick="document.checkoutform.'.$this->paramName('checkout_submit').'.value = 1;
1020                                                                                                if(okToSubmit())
1021                                                                                                  {
1022                                                                                                  document.checkoutform.submit();
1023                                                                                                  }
1024                                                                                                else
1025                                                                                                  {
1026                                                                                                  return false;
1027                                                                                                  }">Submit</button>');
1028          $tpl->setVar('checkcard', 'false');
1029          $tpl->setVar('check_shipping', 'false');
1030          $tpl->setVar('billedimmediate_hide', 'display: none;');        
1031          }
1032        }
1033      else
1034        {
1035        $tpl->setVar('checkcard', 'false');
1036        $tpl->setVar('check_shipping', 'false');
1037        $tpl->setVar('billedimmediate_hide', 'display: none;');
1038        if($this->settingsVars['eventpaymentdefer'] != "")
1039          {
1040          // the card billing information
1041          $f = FormWidget::init('', 'form.noformtag.tpl.html');
1042          $f->html("<table style='width: 100%;'>");
1043          $tpl->setVar('paypal_set', 'false');
1044          $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
1045          $tpl->setVar('defer_set', 'true');
1046          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
1047          $f->html("  <table><tr style='width: 100%;'>
1048                        <td style='width: 31%;text-align: right;vertical-align: middle;padding: 0 5px 0 0;'>
1049                        Defer Payment (Pay by check or in person):
1050                        </td>
1051                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;'>");
1052          $f->checkbox('defer_payment', '');
1053          $f->html("    </td>
1054                      </tr>
1055                      ");
1056          $f->html("  <tr style='width: 100%;'>
1057                        <td style='width: 31%;text-align: right;vertical-align: middle;padding: 0 5px 0 0;'>
1058                        &nbsp;
1059                        </td>
1060                        <td style='margin: 2px; width: 52%;border: solid 1px #CCC;padding: 2px;'>");
1061          $f->html("<span style=''>Please make checks payable to: <span style='font-weight: bold;'>".$this->settingsVars['checkspayable']."</span></span><br />
1062                 Mail checks to:<br /><div style='padding: 4px;'>".
1063                 str_replace("\n", "<br />", $this->settingsVars['checkslocation'])."
1064                 </div></td></tr></table>");            
1065  
1066          $tpl->setVar('billing_info_form', $f->get());
1067          $tpl->setVar('submit_button', '<button style="padding: 0px; background-color: #6c2875;color: #FFF;font-size: 10px;" onclick="document.checkoutform.'.$this->paramName('checkout_submit').'.value = 1;
1068                                                                                                if(okToSubmit())
1069                                                                                                  {
1070                                                                                                  document.checkoutform.submit();
1071                                                                                                  }
1072                                                                                                else
1073                                                                                                  {
1074                                                                                                  return false;
1075                                                                                                  }">Submit</button>');
1076          }
1077        else if($this->settingsVars['nopayreq'] && $amount == 0)
1078          {
1079          $tpl->setVar('paypal_set', 'false');
1080          $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
1081          $tpl->setVar('defer_set', 'false');
1082          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
1083          $tpl->setVar('billedinfo_hide', 'display: none;');
1084          $tpl->setVar('billing_info_form', '');
1085          $tpl->setVar('submit_button', '<button style="padding: 0px; background-color: #6c2875;color: #FFF;font-size: 10px;" onclick="document.checkoutform.'.$this->paramName('checkout_submit').'.value = 1;
1086                                                                                                if(okToSubmit())
1087                                                                                                  {
1088                                                                                                  document.checkoutform.submit();
1089                                                                                                  }
1090                                                                                                else
1091                                                                                                  {
1092                                                                                                  return false;
1093                                                                                                  }">Submit</button>');
1094          }  
1095        else
1096          {
1097          $tpl->setVar('paypal_set', 'true');
1098          $tpl->setVar('paypal_payment', $this->paramName('paypal_payment'));
1099          $tpl->setVar('defer_set', 'true');
1100          $tpl->setVar('defer_payment', $this->paramName('defer_payment'));
1101          $tpl->setVar('billing_info_form', 'No billing method has been set up for this site. Please contact the site admin.');
1102          $tpl->setVar('submit_button', '');
1103          }
1104        }
1105        
1106      return $tpl->subst('main');
1107      }
1108      
1109    function getUserForm($fields, $offset)
1110      {
1111      if (count($fields) == 0)
1112          return "No additional information is required for this order.";
1113      $qf = FormWidget::quickFormGenerator($fields, $offset, 1);
1114      foreach($qf as $key => $val)
1115        {
1116        //don't display label if the field is a hidden field, theodoreb
1117        if($qf[$key][2] == "hidden" && $qf[$key][1] != "")
1118          $qf[$key][1] = "";         
1119        }
1120      $f .= FormWidget::quickForm($qf, '', 'form.noformtagnonsettings.tpl.html');
1121      $f = str_replace('class="label"', 'class="label" style="width: 20%;"');
1122      return $f;
1123      }  
1124  
1125    function getConfig()
1126      {
1127      if(!T_SUPERUSER)
1128        return "You must be a Superuser to edit this application";
1129        
1130      $tpl = new Template_PHPLIB($this->appBase);
1131      $tpl->setFile(array('main' => '/checkoutoptions.tpl.html'));
1132  
1133      $nopayreq = ($this->settingsVars['nopayreq'] != "") ? $this->settingsVars['nopayreq'] : 0;
1134      $creditcard = ($this->settingsVars['creditcard'] != "") ? $this->settingsVars['creditcard'] : 0;
1135      $authorizer = ($this->settingsVars['authorizer'] != "") ? $this->settingsVars['authorizer'] : "";
1136      $standard = ($this->settingsVars['standard'] != "") ? $this->settingsVars['standard'] : 0;
1137      $email = ($this->settingsVars['email'] != "") ? $this->settingsVars['email'] : 0;
1138      $emailaddress = ($this->settingsVars['emailaddress'] != "") ? $this->settingsVars['emailaddress'] : "";
1139      
1140      $acceptvisa = ($this->settingsVars['acceptvisa'] != "") ? $this->settingsVars['acceptvisa'] : "";
1141      $acceptmastercard = ($this->settingsVars['acceptmastercard'] != "") ? $this->settingsVars['acceptmastercard'] : 0;
1142      $acceptdiscover = ($this->settingsVars['acceptdiscover'] != "") ? $this->settingsVars['acceptdiscover'] : 0;
1143      $requestshipping = ($this->settingsVars['requestshipping'] != "") ? $this->settingsVars['requestshipping'] : "";
1144      $debug = ($this->settingsVars['debug'] != "") ? $this->settingsVars['debug'] : 0;
1145      
1146      $f = FormWidget::init();
1147      
1148      $f->html("<div style='font-weight: bold;padding: 10px 0 5px 0;'>Payment Options</div>");
1149      $f->section();
1150      $f->checkbox('creditcard', $creditcard, 'Credit Card authorization using ', array('onclick' => "if(this.checked)
1151                                                                                                        {
1152                                                                                                        document.getElementById('".$this->paramName('ccoptions')."').style.display = 'block';
1153                                                                                                        }
1154                                                                                                      else
1155                                                                                                        {
1156                                                                                                        document.getElementById('".$this->paramName('ccoptions')."').style.display = 'none';
1157                                                                                                        }"));
1158      $authop = "<select name='".$this->paramName('authorizer')."'>";
1159      $opt_array = Plugins::dohook('cvhook_getAuthorizeOptions', array($authorizer));
1160      if(!is_array($opt_array))
1161          $opt_array = array();
1162      foreach($opt_array as $key => $value)
1163        {
1164        $authop .= $value; 
1165        }
1166  
1167      $authop .= "</select>"; 
1168      $f->html($authop);
1169      // pjh 06/02/2006
1170      $ret = Plugins::dohook('cvhook_getAuthorizeForm', array($this->settingsVars));
1171      if(!is_array($ret))
1172          $ret = array();
1173      foreach ($ret as $r) { $f->html($r); }
1174  
1175      $ccoptions = ($creditcard != "") ? "block" : "none";    
1176      $f->html("<div id=".$this->paramName('ccoptions')." style='display:".$ccoptions .";'><div style='padding: 1px 0 0 20px;'>");
1177      $f->checkbox('acceptvisa', $acceptvisa, 'Accept Visa', array());
1178      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1179      $f->checkbox('acceptmastercard', $acceptmastercard, 'Accept MasterCard', array());
1180      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1181      $f->checkbox('acceptdiscover', $acceptdiscover, 'Accept Discover', array());
1182      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1183      $f->checkbox('requestshipping', $requestshipping, 'Request shipping location in addition to billing location', array());
1184      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1185      $f->html("Account number");
1186      $f->text("accountnumber", $this->settingsVars['accountnumber'], 25);
1187      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1188      $f->html("Transaction description");
1189      $f->text("transdesc", $this->settingsVars['transdesc'], 40);
1190      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1191      $f->html("SubSID Code");
1192      $f->text("subsid", $this->settingsVars['subsid'], 25);
1193      $f->html("</div><div style='padding: 0 0 0 20px;'>");
1194      $f->html("Project Code");
1195      $f->text("projectcode", $this->settingsVars['projectcode'], 25);
1196      $f->html("</div></div>");
1197      $f->html("<div style='padding: 1px 0 0 0;'>");
1198      $f->checkbox('nopayreq', $nopayreq, 'If the selection does not cost anything do not require billing information.', array());
1199      $f->html("</div>");
1200      $f->endSection();
1201      
1202      $checks_hide = ($this->settingsVars['eventpaymentdefer'] == "") ? "display: none;" : "";
1203      
1204      $f->checkbox('event_payment_defer', $this->settingsVars['eventpaymentdefer'], 'Allow payment to be defered to pay by check', array('onclick' => "if(this.checked == true)
1205                                                                                           {
1206                                                                                           document.getElementById('check1').style.display = 'inline';
1207                                                                                           document.getElementById('check2').style.display = 'block';
1208                                                                                           }
1209                                                                                         else
1210                                                                                           {
1211                                                                                           document.getElementById('check1').style.display = 'none';
1212                                                                                           document.getElementById('check2').style.display = 'none';
1213                                                                                           }"));
1214      $f->html("<br /><span id='check1' style='margin-left:24px;$checks_hide'>Make checks payable to");
1215      $f->text('checks_payable', $this->settingsVars['checkspayable'], 25);
1216      $f->html("    </span>");
1217  
1218      $f->html("<div id='check2' style='margin-left:24px;$checks_hide'>Send checks to<br />");
1219      $f->textarea('checks_location', $this->settingsVars['checkslocation'], 3, 10, array('style' => 'width:256px;'));
1220      $f->html("    </div>");
1221      
1222      
1223      $f->html("<div style='font-weight: bold;padding: 10px 0 5px 0;'>Post Sale Actions</div>");
1224      $f->section();
1225      $f->checkbox('email', $email, 'Email the results to ', array());
1226      $f->text('emailaddress', $emailaddress, 20);
1227  
1228      $f->html($postop);
1229      $f->endSection();
1230      $f->html("<div style='font-weight: bold;padding: 10px 0 5px 0;'>Debugging</div>");
1231      $f->section();
1232      $f->checkbox('debug', $debug, 'Display query debugging and errors. ', array());
1233      $f->endSection();
1234                  
1235      $f->html("<div style='padding: 5px 0 5px 0;'>&nbsp;</div>");
1236      $f->html("<div style='float:right;'>");    
1237      $f->defaultButtons(array(), false, true, true);
1238      $f->html("</div>");
1239  
1240      $tpl->setVar('informationoptions', $f->get());
1241      return $tpl->subst('main');
1242      }
1243      
1244    }
1245  ?>

title

Description

title

Description

title

Description

title

title

Body