<% On Error Resume Next ' Turn On Error Handling for *.xls sheets showSplash("Searching phone cards...") ' This page will need a loading message %> <% ' viewAll.asp ' =========== ' This module constructs phone card combinations ' using rate spreadhseet data, combined with ' phone card product data from the database. ' ' Each phone card becomes a phone card object. ' A phonecard object contains a paypal button ' object. Phone card objects may also contain ' bundle objects, which themselves may contain ' another paypal button object. ' ' Another object is used to store an array ' of phone cards. keywords = "phone card, phonecard, calling card, cheap call, discount, international call, abroad, overseas, lowest rates, india, bangladesh, sri lanka, pakistan, australia, new zealand, south africa, africa, europe, student calls, call from mobile, instant PIN" description = "Phone Cards Online. View phone card (calling card) rates and discounts, and buy online for delivery direct to email." %> <% ' General functions ' ================= ' If call type is 'mobile' then we need to append '_MOBILE' to ' the country, since this is how appears in the spreadhseet Function checkMobile(byVal destination, byVal callType) If callType = MOBILE Then checkMobile = Trim(destination & "_MOBILE") Else checkMobile = Trim(destination) End If End Function ' Product codes in the spreadhseet have lots of gunk after ' the actual product code. We just split on '_' and ' return the first thing we get, the code may now be used in ' the MS SQL database. Function getProductCode(byVal excelCode) tmpString = Split(excelCode,"_") getProductCode = tmpString(0) End Function ' Takes a recordset and a dictionary object, and returns that ' dictionary object populated by the recordset. Advanced versions ' of this exist excel.asp, but this is a quick and dirty one. Function addToDic(byVal ArgRs, byRef ArgDic, byVal startIndex) For i = startIndex To ArgRs.Fields.Count - 1 ArgDic.Add ArgRs.Fields.Item(i).Name, ArgRs.Fields.Item(i).Value Next set addToDic = ArgDic End Function ' Entry point - declare variables ' =============================== Dim rateData ' Dictionary object to hold recordset data for cards Dim locations ' Dictionary object to hold recordset data for countries Dim cardData ' Dictionary object to hold phone card data Dim bundles ' Dictionary object to hold bundles attached to this site (not group) Dim rs ' Spreadhseet recordset Dim strSQL ' Used for building long SQL statements or stored procedures Dim itemsArray, keysArray ' Arrays to hold dictionary object data Dim varForm ' Holds name of incoming vars Dim columnCounter ' Keeps track of how many spreadhseet columns we've read in Dim tmpCard ' Temporary PhoneCard object used in populating and reading 'TheCardArray' Dim theCardArray ' Wrapper for an array of cards and its operations Dim gotData ' Did the spreadhseet return any rate data? Dim codeString ' Concatinate all card codes we want to process for next page Dim formSession ' Custom Session class holding form settings Dim arr() ' Stores recordsets returned from various worksheets Dim a,b,k ' Loop vars for counting Dim saveCard ' Flag for saving or discarding the generated cards ' Initialize variables and objects ' ================================ varForm = "callType||destination||accessNumRad" &_ "||displayType||typeFilter" ' Incoming variables to this page from default.asp set var = VarInitAll( varForm ) ' Populate incoming variables set rateData = Server.CreateObject("Scripting.Dictionary") ' Initialise Dictionary objects set locations = Server.CreateObject("Scripting.Dictionary") set cardData = Server.CreateObject("Scripting.Dictionary") set bundles = Server.CreateObject("Scripting.Dictionary") set tmpCard = new PhoneCard ' Initialise custom objects set theCardArray = new CardArray set formSession = new CustomSession columnCounter = 0 gotData = false ' Assume we have no data from spreadhseet (safer than assuming we have) saveCard = True ' Save or load form settings from Session object ' ============================================== ' We do this, so that if the user gets to this page from a link, and ' hence with no POST data, then the form will default to their last ' search option. But if they do arrive with POST data, then those ' settings will be saved. if var("destination") <> "" then formSession.add "LOCATION", var("destination") formSession.add "CALL_TYPE", var("callType") formSession.add "ACCESS_NUM", var("accessNumRad") formSession.add "DISPLAY", var("displayType") formSession.add "TYPE_FILTER", var("typeFilter") else var("destination") = formSession.ToString("LOCATION") var("callType") = formSession.ToString("CALL_TYPE") var("accessNumRad") = formSession.ToString("ACCESS_NUM") var("displayType") = formSession.ToString("DISPLAY") var("typeFilter") = formSession.ToString("TYPE_FILTER") end if ' Because of the type filtering, we must make sure typeFilter ' contains a non empty value (which it will do if the user used ' the tab link rather than a form button to get to this page). if Trim(var("typeFilter")) = "" then var("typeFilter") = -1 end if ' Connect to Spreadhseet - pull rate data & product codes ' ======================================================= ' This is all a little messy because it's a work around ' of Excel restricting columns to 256 per worksheet. Therefore ' multiple worksheets may exist in the *.xls file, but we don't ' know how many. openExcelConnection(DATABASE) ' Open connection to spreadsheet sheetExists = true a = 1 ' Start with SHEET1 while sheetExists name = "SHEET" & a ' Construct the name of the potential worksheet ' Attempt to access the worksheet. ' This will Error if the sheet doesn't exist, ' setting Err.Number to a non zero value. set rs = SQlSelectExcel("SELECT * FROM " & name & " WHERE DESTINATION = '" & _ checkMobile(var("destination"), var("callType")) & _ "';") ' Did the sheet exist? If Err.Number <> 0 Then ' No, so stop looking for any more sheets sheetExists = false Else ' Yes, store the recordset returned in an array ' while we look for more sheets in the *.xls file redim preserve arr(a) set arr(a-1) = rs End If a = a + 1 ' Sheet1, Sheet2, Sheet3......Sheetn wend ' Loop through recordsets returned and create ' one large dictionary object from them. for b=0 to UBound(arr)-1 if arr(b).RecordCount > 0 then gotData = true set rateData = addToDic(arr(b),rateData, 1) end if next set locations = SQl2DicExcell("SELECT * FROM LOCATIONS;") ' Get list of countries closeExcelConnection ' Close connection to spreadsheet if gotData then ItemsArray = rateData.Items ' Populate arrays with dictionary object data, we must loop through this way KeysArray = rateData.Keys ' since we don't know the names of the dictionary 'keys' else Redim ItemsArray(0) ' There was no data, but we need to initialise the arrays to avoid Redim KeysArray(0) ' erroring later on end if ' Connect to MS SQL database - create PhoneCard objects to display ' ================================================================ SQLConnect ' Connect to MS SQL database ' new: replaces GROUP_ID strSQL = "ALPHA_SP_GET_GROUP_ID " & DIRECT_ACCOUNT_ID Set group = SQlSelect2Dic(strSQL) ' Retrieve any bundles attached to this site (not group) strSQL = "ALPHA_SP_GET_BUNDLE_DATA " & DIRECT_ACCOUNT_ID set bundles = SQlSelect2Dic( strSQL ) ' Retrieve all product types attached to this group strSQL = "ALPHA_SP_GET_GROUP_PRODUCT_TYPES " & group(0)("GROUP_ID") set cardTypeData = SQlSelect2Dic(strSQL) for k = 0 to UBound(ItemsArray) ' Populate PhoneCard object with Spreadhseet data if Trim(ItemsArray(k)) <> "" then select case columnCounter case CONNECTION_CHARGE tmpCard.ConnectionCharge = ItemsArray(k) case MAINTENANCE_CHARGE tmpCard.MaintenanceCharge = ItemsArray(k) case RATE_0800 tmpCard.Rate0800 = ItemsArray(k) case RATE_0207 tmpCard.Rate0207 = ItemsArray(k) case RATE_0845 tmpCard.Rate0845 = ItemsArray(k) case NOM_0800 tmpCard.Nom0800 = ItemsArray(k) case NOM_0207 tmpCard.Nom0207 = ItemsArray(k) case NOM_0845 tmpCard.Nom0845 = ItemsArray(k) end select else ' A field was empty, so we don't want to save / display the card saveCard = False end if If columnCounter = COLS_PER_PRODUCT -1 Then ' We've read in a whole product If saveCard then ' No data was missing, so we can save the card strSQL = "ALPHA_SP_DIRECT_PRODUCT_LIST '" & getProductCode(KeysArray(k)) & "'," & group(0)("GROUP_ID") set cardData = SQlSelect2Dic(strSQL) result = tmpCard.populate( cardData ) ' Populate PhoneCard object with Database data and check it was successful ' Attempt to add any bundles for this site to a specific card tmpCard.AttachBundle( bundles ) if result then theCardArray.addCard(tmpCard) end if End if ' saveCard set tmpCard = new PhoneCard ' Clear the temporary object anyway columnCounter = -1 ' We've read in a card, so reset the column counter (-1 because of increment below) saveCard = True End If columnCounter = columnCounter + 1 next SQLDisconnect ' Disconnect from the MS SQL database ' Do we need to do any sorting? ' ============================= if var("displayType") <> "full" then theCardArray.Sort( var("accessNumRad") ) end if ' Call PrintTemplate which calls PrintContent ' =========================================== ' PrintTemplate "tite.asp", would normally be called here, ' but because this module displays a loading message, we ' move the call to print the pages content to the bottom ' of this module. This is because calling a sub routine ' over-rides any buffering to stop content from being ' displayed until all processing has been done. sub PrintContent %>
Country you are calling: [?]
Calling to: [?]
Preferred access type: checked<% End If %> name="accessNumRad" value="<%= NUM_0800 %>" /><%= NUM_0800 %> checked<% End If %> name="accessNumRad" value="<%= NUM_0207 %>" /><%= NUM_0207 %> checked<% End If %> name="accessNumRad" value="<%= NUM_0845 %>" /><%= NUM_0845 %> [?]
Display options: checked<% End If %> name="displayType" value="full" /> View full product list [?]  
checked<% End If %> name="displayType" value="noCharge"/> View cards with no connection charge [?]
  checked<% End If %> name="displayType" value="charge" /> View cards with connection charge [?]
Favourite card (optional) [?]
 

<% if not gotData then %> Please click 'View Cards' to see card list and buy now. <% else %> Showing rates and minutes to <%= var("destination") %> using <%= var("accessNumRad") %> access, calling to a <%= LCase(var("callType")) %>.[?] <% end if %>

Choose from the menu above to see rates to the country you are calling and the type of call you are making.

<% i = 0 for m = 0 to theCardArray.numCards set tmpCard = theCardArray.getCard(m) codeString = codeString & Trim(tmpCard.Code) & SEPARATOR ' Build a string of spreadhsheet codes for buyCards.asp, so we don't have to ' connect to the spreadhseet again on buyCard.asp. skip = false if var("displayType") = "charge" and not CDbl(tmpCard.ConnectionCharge) > 0 then ' only display cards that have a connection charge over 0.0 skip = true end if if var("displayType") = "noCharge" and CDbl(tmpCard.ConnectionCharge) > 0 then ' only display cards that have a connection charge of 0.0 skip = true end if ' typeFilter may be -1 for all cards if CInt(var("typeFilter")) <> tmpCard.TypeID and CInt(var("typeFilter")) >= 0 then ' product filter used, only display 1 type of card skip = true end if %> <% if not skip then %>

<%= tmpCard.TypeShortDescription %>    <%= tmpCard.ProductShortDescription %>

<%= tmpCard.MiniImage %>
<%= var("accessNumRad") %> rate per min: <%= tmpCard.Rate( var("accessNumRad") ) %>p    Number of minutes (based on one call): <%= tmpCard.Nom( var("accessNumRad") ) %> mins   
Connection charge (per call): <%= tmpCard.ConnectionCharge %>p    Maintenance charge (per day): <%= tmpCard.MaintenanceCharge %>p
Price from PCO Direct £<%= tmpCard.DiscountPrice %> <% for x=0 to tmpCard.BundleCount -1 %>
Bundle offer: <%= tmpCard.BundleName(x) %>
Buy <%= tmpCard.BundleQuantity(x) %> of these cards for only £ <%= tmpCard.BundlePrice(x) %>.    <%= tmpCard.BundleDescription(x) %>    <%= tmpCard.BundleLink(x) %>
<% next %>


<% i = i + 1 ' For JavaScript div counter, may not be same as array count because of 'skip' end if next %>
<% if not gotData then %> Please use the rate finder above to choose the destination you will be calling to see cards and rates. If you already know the card you are looking for you can select directly from "Product-type" to go straight to that card.

If you want to look at rates to more than one country or change other display settings, you can change each individually without re-entering them all. <% end if %> <% end sub %> <% hideSplash PrintTemplate "Phone cards online - product list for PCOdirect.com", description, keywords %>