<?php

/*
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
This is a Free version 3 of qlWeb Directory Script.
(C) 2007-10 Contact USA, Inc. (http://www.qlWeb.com) All Rights Reserved.
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Unbranded and Unlimited Domain Licenses may be purchased at http://www.qlWeb.com/features.html
All copyright notices, LICENSE.TXT file, "Copyright (c) Contact USA, Inc. All Rights Reserved." and "Powered by: qlWebDS" or "Powered by: qlWeb Directory Script" must remain intact.
The above notice must remain intact.
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Software License Agreement - qlWebDS - Directory Script - Commercial License.
Copyright (c) Contact USA, Inc. (http://www.qlWeb.com) All Rights Reserved.
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
License
1. Under this Software License Agreement (the "Agreement"), Contact USA, Inc. (the "Vendor") grants to the user (the "Licensee") a nonexclusive and nontransferable license (the "License") to use qlWebDS - Directory Script ("qlWebDS") (the "Software").
2. "Software" includes the php script, templates, the source code and any related printed, electronic and online documentation and any other files that may accompany the product.
3. Title, copyright, intellectual property rights and distribution rights of the Software remain exclusively with the Vendor. Intellectual property rights include the look and feel of the Software. This Agreement constitutes a license for use only and is not in any way a transfer of ownership rights to the Software.
4. The Software may be loaded onto no more than one computer or no more than one Website and it may only be used on a single domain unless additional licenses or unlimited domain licenses are purchased. A single copy may be made for backup purposes only.
5. The rights and obligations of this Agreement are personal rights granted to the Licensee only. The Licensee may not transfer or assign any of the rights or obligations granted under this Agreement to any other person or legal entity. The Licensee may not make available the Software for use by one or more third parties.
6. The Licensee may not redistribute, sell or otherwise share this software in whole or in part without the consent of the Vendor. Licensee also agrees to retain a link back ("Powered by: qlWebDS or qlWeb Directory Script") to http://www.qlWeb.com unless a powered by removal license is purchased.
7. Failure to comply with any of the terms under the License section will be considered a material breach of this Agreement.
License Fee
8. The original purchase price paid by the Licensee will constitute the entire license fee and is the full consideration for this Agreement. Licensee will be entitled to future upgrades at $5 for Deluxe Version, $10 for Premium Version, $15 for Pro Version and $20 for Supreme Version.
Limitation of Liability
9. The Software is provided by the Vendor and accepted by the Licensee "as is". Liability of the Vendor will be limited to a maximum of the original purchase price of the Software. The Vendor will not be liable for any general, special, incidental or consequential damages including, but not limited to, loss of production, loss of profits, loss of revenue, loss of data, or any other business or economic disadvantage suffered by the Licensee arising out of the use or failure to use the Software.
10. The Vendor makes no warranty expressed or implied regarding the fitness of the Software for a particular purpose or that the Software will be suitable or appropriate for the specific requirements of the Licensee.
11. The Vendor does not warrant that use of the Software will be uninterrupted or errorfree. The Licensee accepts that software in general is prone to bugs and flaws within an acceptable level as determined in the industry.
Warrants and Representations
12. The Vendor warrants and represents that it is the copyright holder of the Software. The Vendor warrants and represents that granting the license to use this Software is not in violation of any other agreement, copyright or applicable statute.
Acceptance
13. All terms, conditions and obligations of this Agreement will be deemed to be accepted by the Licensee ("Acceptance") on installation of the Software.
Term
14. The term of this Agreement will begin on Acceptance and is perpetual.
Termination
15. This Agreement will be terminated and the License forfeited where the Licensee has failed to comply with any of the terms of this Agreement or is in breach of this Agreement. On termination of this Agreement for any reason, the Licensee will promptly destroy the Software or return the Software to the Vendor.
Force Majeure
16. The Vendor will be free of liability to the Licensee where the Vendor is prevented from executing its obligations under this Agreement in whole or in part due to Force Majeure, such as earthquake, typhoon, flood, fire, and war or any other unforeseen and uncontrollable event where the Vendor has taken any and all appropriate action to mitigate such an event.
Governing Law
17. The Parties to this Agreement submit to the jurisdiction of the courts of the State of New York for the enforcement of this Agreement or any arbitration award or decision arising from this Agreement. This Agreement will be enforced or construed according to the laws of the State of New York.
Miscellaneous
18. This Agreement can only be modified in writing signed by both the Vendor and the Licensee.
19. This Agreement does not create or imply any relationship in agency or partnership between the Vendor and the Licensee.
20. Headings are inserted for the convenience of the parties only and are not to be considered when interpreting this Agreement. Words in the singular mean and include the plural and vice versa. Words in the masculine gender include the feminine gender and vice versa. Words in the neuter gender include the masculine gender and the feminine gender and vice versa.
21. If any term, covenant, condition or provision of this Agreement is held by a court of competent jurisdiction to be invalid, void or unenforceable, it is the parties' intent that such provision be reduced in scope by the court only to the extent deemed necessary by that court to render the provision reasonable and enforceable and the remainder of the provisions of this Agreement will in no way be affected, impaired or invalidated as a result.
22. This Agreement contains the entire agreement between the parties. All understandings have been included in this Agreement. Representations which may have been made by any party to this Agreement may in some way be inconsistent with this final written Agreement. All such statements are declared to be of no value in this Agreement. Only the written terms of this Agreement will bind the parties.
23. This Agreement and the terms and conditions contained in this Agreement apply to and are binding upon the Vendor's successors and assigns.
Notices
24. All notices to the Vendor under this Agreement are to be provided at the following address:

Contact USA, Inc.
qlWeb.com Team
P.O. Box 160
Baldwin Place, NY 10505-0160  USA
In the U.S. call: 1-888-QLWEB-COM or 1-888-759-3226
Local: 845-621-4240
Outside of the U.S. call: +1 845-621-4240
Fax: 845-621-4449
E-mail: Script@qlWeb.com
Skype: EntireAccess or qlWebDS

SCRIPT INFO:
Script:												qlWebDS - Directory Script
Copyright:											(c) Contact USA, Inc. (http://www.qlWeb.com) All Rights Reserved
Requirements:										PHP 4.0 or higher, MySQL 4.1 or higher
Use:												All copyright notices, LICENSE.TXT file, "Copyright (c) Contact USA, Inc. All Rights Reserved." and "Powered by: qlWebDS" or "Powered by: qlWeb Directory Script" must remain intact
License Info:										http://www.qlWeb.com/modules.php?name=FAQ
License Type:										Free - qlWebDS
Unbranded License:									To purchase a "Powered by" Removal License: http://www.qlWeb.com/features.html
Unlimited Domains License:							http://www.qlWeb.com/features.html
Customization and Installation Help:				http://www.qlWeb.com/features.html
Main Site:											http://www.qlWeb.com
Demo Site:											http://www.qlWebDemo.com
Support Forums:										http://www.qlWeb.com/forum
Free Version Download:								http://www.qlWeb.com/forum
All Versions - Features								http://www.qlweb.com/features.html#features
Versions Deluxe, Premium, Pro and Supreme			http://www.qlWeb.com/features.html
qlWeb Internet Scripts Affiliate Program			http://www.qlWeb.com/affiliates
qlWeb Scripts Manuals								http://www.qlweb.com/qlweb_manual.html

Other Scripts by Contact USA, Inc.
qlWebDS - Directory Script
qlWebDM - Directory Management
qlWebQS - Quick Site Script
qlWebDA - Directory Adder
qlWebEC - eCommerce Script
qlWebCM - Content Management Script
qlWebDL - Directory List Script

Unbranded and Unlimited Domain Licenses may be purchased at http://www.qlWeb.com/features.html
All copyright notices, LICENSE.TXT file, "Copyright (c) Contact USA, Inc. All Rights Reserved." and "Powered by: qlWebDS" or "Powered by: qlWeb Directory Script" must remain intact.
The above notice must remain intact.
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
*/

  # Create a reply to validate the PayPal post. (Standard PayPal Code)
  
  //------------------------------------------------
  // Read post from PayPal system and create reply
  // starting with: 'cmd=_notify-validate'...
  // then repeating all values sent - VALIDATION.
  //------------------------------------------------
  $postvars = array();
  while (list ($key, $value) = each ($_POST)) {
    $postvars[] = $key;
  }
  
  $req = 'cmd=_notify-validate';
  
  foreach ($_POST as $key => $value) {
    
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    
  }
  
  # Create an HTTP header for the reply message, open a connection...
  
  //--------------------------------------------
  // Create message to post back to PayPal...
  // Open a socket to the PayPal server...
  //--------------------------------------------
  $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  $header .= "Host: www.paypal.com\r\n";
  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
  
  //---------------------------------------------
  // Get Item Info, check if this item still exists
  //---------------------------------------------
  $id = (int) $_GET['id'];
  $row = $g_site->GetSiteById($id);  
  $pRow = $g_site->GetLastPayment($id);  
  
  $date = date(DATETIME_FORMAT);  
  
  # Check Connection...
  
  //----------------------------------------------------------------------
  // Check if HTTP connection made to PayPal is OK, If not, print an error msg
  //----------------------------------------------------------------------  
  if (!$fp) {
    $res = "FAILED";
    $aPayment['error'] = 'fsockopen "www.paypal.com" connection failed';
    $aPayment['is_error'] = 1;
  } else {
    fputs ($fp, $header . $req);

    while (!feof($fp)) {
      $res = fgets ($fp, 1024);
     
      if (strcmp ($res, "VERIFIED") == 0) {

        # If payment is complete.
        
        //----------------------------------------------------------------------
        // If the payment_status=Completed... 
        //----------------------------------------------------------------------        
        if ( ($id>0) and strcmp($_POST['payment_status'], "Completed") == 0) {
          
          $site = $g_site->GetSiteById($id);
          
          // send email, payment received
          $psite = $site;
          $psite['email'] =  $payer_email;
          $g_site->SendEmail($g_params->GetParams('payment_received'), $psite );
          
          $aSite['last_payment'] = $date;
          $aSite['last_payment_id'] = $pRow['id'];
          
          if (LINK_INSTANTLY_APPEAR) {
            $aSite['status'] = SITE_VIEW;
            
            // send email, site approved            
            $g_site->SendEmail($g_params->GetParams('site_approved_email'), $site );
          
          } 
          
          $ok = $g_site->UpdateSite($aSite, $id);
          $aPayment['payed'] = PM_PAYED;
          $aPayment['error'] = LANG_INFO_PAYMENT0;
          $aPayment['is_error'] = 0;
        }
  
        //----------------------------------------------------------------------
        // If the payment_status is NOT Completed... 
        //----------------------------------------------------------------------
        else {
          $aPayment['error'] = LANG_INFO_PAYMENT1;
          $aPayment['is_error'] = 1;
          $aPayment['payed'] = PM_NOT_COMPLETED;
        }
        break;
  
      # Deal with 'Unverified' transactions
      //----------------------------------------------------------------
      // ..If UNVerified - It's 'Suspicious' and needs investigating!
      // Send an email to yourself so you can investigate it.
      //----------------------------------------------------------------
      } else {
        $aPayment['error'] = LANG_INFO_PAYMENT2;
        $aPayment['is_error'] = 1;
        $aPayment['payed'] = PM_UNVERIFIED;

      }
      
    }
  }
  
  $aPayment['paymeny_period'] = $g_params->Get('payment', 'payment_period');
  
  $aPayment['business'] = $_POST['business'];
  $aPayment['receiver_email'] = $_POST['receiver_email'];
  $aPayment['email'] = $_POST['payer_email'];
  $aPayment['payment_date'] = $date;
  $aPayment['currency'] = $_POST['mc_currency'];
  $aPayment['amount'] = $_POST['mc_gross']; 
  $aPayment['log'] = serialize($_POST);
  
  $ok = false;
  if ($pRow['id']>0) {
    $ok = $g_site->UpdatePayment($aPayment, $pRow['id']);
  }  
   
  ?>
