<?php
/*******************************************************************
 * DataBinding.php
 * Copyright (C) 2006 Midnight Coders, LLC
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * The software is licensed under the GNU General Public License (GPL)
 * For details, see http://www.gnu.org/licenses/gpl.txt.
 ********************************************************************/
class DataBinding
{
    // The getCustomers method retrieves data from the database and returns it to the requesting client.
    // Notice the return value data type - it is System.Data.DataTable. WebORB automatically converts 
    // instances of the DataTable objects to arrays, so they can be used as data providers for 
    // the components like DataGrid
    public function getCustomers()
    {
    	$link = mysql_connect("localhost", "flexuser", "password");

    	mysql_select_db('northwind', $link);

		$result = mysql_query("SELECT * FROM Customers order by CustomerID;")or die("Invalid query: " . mysql_error());
    	
	    mysql_close($link);

        return $result;
    }

    public function updateCustomer(Customer $originalCustomerRecord, $changedFieldName = null, $newValue = null)
    {
    	$link = mysql_connect("localhost", "flexuser", "password");

    	mysql_select_db('northwind', $link);

    	if ($changedFieldName == null && $newValue == null)
    	{
    		$query = "UPDATE Customers set  Address = 		'$originalCustomerRecord->Address',
											City = 			'$originalCustomerRecord->City',
											CompanyName = 	'$originalCustomerRecord->CompanyName',
											ContactName = 	'$originalCustomerRecord->ContactName',
											ContactTitle = 	'$originalCustomerRecord->ContactTitle',
											Country =	 	'$originalCustomerRecord->Country',
											PostalCode = 	'$originalCustomerRecord->PostalCode' ";
    	}
    	else
    	{
    		$query = "UPDATE Customers set $changedFieldName = '$newValue' ";
    	}
    	
    	$query .= " WHERE CustomerID = '$originalCustomerRecord->CustomerID';";
    	
    	$result = mysql_query($query) or die("Invalid query: " . mysql_error());

	    mysql_close($link);
    }
}
class Customer
{
	var $Address;
	var $City;
	var $CompanyName;
	var	$ContactName;
	var $ContactTitle;
	var $Country;
	var $PostalCode;
	var $CustomerID;
}
?>