Zen Cart Logo
Forums / All Other Contributions/Addons / need fresh eyes for possible addon (modified from osc)

need fresh eyes for possible addon (modified from osc)

Locked

Views: 3,175

Results 1 to 19 of 19
This thread is locked. New replies are disabled.
25 May 2009, 6:44 AM
#1
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

need fresh eyes for possible addon (modified from osc)

hi All,

just need some fresh eyes to tell me what i am doing wrong.
( I am trying to convert from OScommerce ) = iphone module for the admin section.

please keep in mind i am new to zen and my friend(mentor) is still at uni now.......i should be tooooooo LOL.

oh well im sure to get criticism(all is welcome) but here we go.

<?php
/**
 * Zen iphone.php -- version 1.0beta
 * 
 * Modified by MrChristoh
 *
 * By Dirk Malorny <iphone-apps (at) malorny (dot) net>
 * You may modify this script to fulfill your special needs, but all modifications you make are at your own risk!
 */
 
require('includes/application_top.php');

define("VERSION","1.0beta conversion");
define("DELIMITER","|");

// =========================== MAIN ===========================

$action = (isset($_REQUEST['a']) ? $_REQUEST['a'] : '');

if (zen_not_null($action)) {
	header('Content-Type: text/plain; Charset=UTF-8');
	
	switch ($action) {
		
	case 'login':
		echo "OK";
		break;
		
		
	case 'status':
		// 1: plugin version
		echo VERSION."\n";
		
		// 2: order_status
		$status_query = create_status_query();
		$arr = array();
		while ($status = zen_db_fetch_array($status_query)) {
			$arr[] = $status['orders_status_id'].':'.escape($status['orders_status_name']);
		}
		outputStatusLine($arr);
		
		// 3: order count
		$order_count = zen_db_fetch_array(create_order_count_query());
		echo $order_count['count']."\n";
		
		break;


	case 'customers':
		$customers_query = create_customer_query($_REQUEST['lu']);
			
		while ($customers = zen_db_fetch_array($customers_query)) {
			$arr = array();
			$arr[] = $customers['customers_id'];
			$arr[] = $customers['customers_lastname'];
			$arr[] = $customers['customers_firstname'];
			$arr[] = $customers['customers_email_address'];
			$arr[] = $customers['customers_dob'];
			$arr[] = $customers['customers_telephone'];
			$arr[] = $customers['customers_fax'];
			$arr[] = $customers['entry_company'];
			$arr[] = $customers['entry_street_address'];
			$arr[] = $customers['entry_postcode'];
			$arr[] = $customers['entry_city'];
			$arr[] = $customers['entry_state'];
			$arr[] = $customers['countries_name'];
			outputLine($arr);
		}
		break;
		

	case 'products':
		$products_query = create_products_query($_REQUEST['lu'],$_REQUEST['of'],$_REQUEST['li']);
			
		while ($products = zen_db_fetch_array($products_query)) {
			
			$arr = array();
			$arr[] = $products['products_id'];
			$arr[] = $products['products_model'];
			$arr[] = $products['products_price'];
			$arr[] = $products['products_name'];
			$arr[] = ereg_replace("[\n\r]",'\n',$products['products_description']);
			outputLine($arr);
		}
		break;

		
	case 'orders':
		$orders_query = create_orders_query($_REQUEST['lu'],$_REQUEST['of'],$_REQUEST['li']);
	
		$orderIds = array();
		while ($orders = zen_db_fetch_array($orders_query)) {
			$orderIds[] = $orders['orders_id'];
			$arr = array();
			$arr[] = $orders['orders_id'];
			$arr[] = $orders['customers_id'];
			$arr[] = $orders['orders_status_id'];
			$arr[] = $orders['customers_name'];
			$arr[] = $orders['payment_method'];
			$arr[] = $orders['date_purchased'];
			$arr[] = $orders['currency'];
			$arr[] = $orders['orders_status_name'];
			$arr[] = $orders['order_total'];
			outputLine($arr);
		}
		
		if (!$orderIds) continue;
		
		// order items
		echo "\n--\n\n";
		$orderIds = implode(',',$orderIds);
	
		$items_query = create_items_query($orderIds);
	
		while ($items = zen_db_fetch_array($items_query)) {
			$arr = array();
			$arr[] = $items['orders_products_id'];
			$arr[] = $items['orders_id'];
			$arr[] = $items['products_id'];
			$arr[] = $items['products_quantity'];
			$arr[] = $items['products_model'];
			$arr[] = $items['products_name'];
			$arr[] = $items['products_price'];
			$arr[] = $items['final_price'];
			$arr[] = $items['products_tax'];
			$arr[] = html_entity_decode(ereg_replace("[\n\r]",'\n',$items['attributes']));
			outputLine($arr);
		}
		break;
		

	
	default:
		echo "unknown action";
		break;

	} // switch
} else {
	// TESTMODE
	$TEST_RESULT = true;
	testSuite();
} // MAIN




// =========================== QUERY functions ===========================

function create_customer_query($lu)
{
	$filter = '';
	if (isset($lu) && zen_not_null($lu)) {
		$last_update = zen_db_input(zen_db_prepare_input($lu));
		$filter = "where i.customers_info_date_account_created > '$last_update' 
					  or i.customers_info_date_account_last_modified > '$last_update'";
	}

	$customers_query = zen_db_query("
	select 
		c.customers_id, 
		c.customers_lastname,
		c.customers_firstname,
		c.customers_email_address,
		NULLIF(DATE_FORMAT(c.customers_dob,'%Y-%m-%d'),'0000-00-00') customers_dob,
		c.customers_telephone,
		c.customers_fax,
		a.entry_company,
		a.entry_street_address,
		a.entry_postcode,
		a.entry_city,
		a.entry_state,
		l.countries_name 
	from " . zen_customers . " c 
		 left join " . zen_address_book . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id
		 left join " . zen_countries . " l on a.entry_country_id = l.countries_id
		 left join " . zen_customers_info . " i on  c.customers_id = i.customers_info_id
	$filter 
	order by c.customers_id");
	
	return $customers_query;
}

function create_products_query($lu,$of,$li)
{
	$filter = '';
	$limit  = '';
	if (isset($lu) && zen_not_null($lu)) {
		$last_update = zen_db_input(zen_db_prepare_input($lu));
		$filter = " and p.products_date_added > '$last_update' 
					  or p.products_last_modified > '$last_update'";
	}
	if (isset($of) && zen_not_null($of)) {
		$offset = zen_db_input(zen_db_prepare_input($of));
		$filter .= " and p.products_id < $offset";
	}
	if (isset($li) && zen_not_null($li)) {
		$limit = "limit " . zen_db_input(zen_db_prepare_input($li));
	}

	$products_query = zen_db_query("
	select 
		p.products_id, 
		p.products_model,
		p.products_price,
		d.products_name,
		d.products_description
	from " . ZEN_PRODUCTS . " p
		 left join " . ZEN_PRODUCTS_DESCRIPTION . " d on d.products_id = p.products_id
		 left join " . ZEN_LANGUAGES . " l on l.languages_id = d.language_id
	where 1
		$filter 
	order by p.products_id DESC
	$limit
	");
	
	return $products_query;
}

function create_orders_query($lu,$of,$li)
{
	global $languages_id;
	
	$filter = '';
	$limit  = '';
	if (isset($lu) && zen_not_null($lu)) {
		$last_update = zen_db_input(zen_db_prepare_input($lu));
		$filter .= " and (o.date_purchased > '$last_update' 
					 or o.last_modified > '$last_update')";
	}
	if (isset($of) && zen_not_null($of)) {
		$offset = zen_db_input(zen_db_prepare_input($of));
		$filter .= " and o.orders_id < $offset";
	}
	if (isset($li) && zen_not_null($li)) {
		$limit = "limit " . zen_db_input(zen_db_prepare_input($li));
	}
	
	$orders_query = zen_db_query("
	select 
		o.orders_id,
		o.customers_id,
		o.customers_name,
		o.payment_method,
		DATE_FORMAT(o.date_purchased,'%Y-%m-%d %H:%i:%s') date_purchased,
		o.currency,
		s.orders_status_id,
		s.orders_status_name,
		ot.value as order_total
	from " . ZEN_ORDERS . " o 
		 left join " . ZEN_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id),
		 " . ZEN_ORDERS_STATUS . " s 
	where o.orders_status = s.orders_status_id 
		and s.language_id = '" . (int)$languages_id . "' 
		and ot.class = 'ot_total'
		$filter
	order by o.orders_id DESC
	$limit
	");
	
	return $orders_query;
}

function create_items_query($orderIds)
{
	$items_query = zen_db_query("
	select 
		op.orders_products_id,
		op.orders_id,
		op.products_id,
		op.products_quantity,
		op.products_model,
		op.products_name,
		op.products_price,
		op.final_price,
		op.products_tax,
		group_concat(replace(concat_ws(':',replace(opa.products_options,':','{colon}'),replace(opa.products_options_values,':','{colon}')),'*','{star}') separator '*') attributes
	from " . ZEN_ORDERS_PRODUCTS . " op 
	left outer join
		 " . ZEN_ORDERS_PRODUCTS_ATTRIBUTES . " opa
		 on op.orders_id=opa.orders_id
		and op.orders_products_id=opa.orders_products_id
	where op.orders_id in ($orderIds)
	group by op.orders_products_id
	order by op.orders_id DESC
	");
	
	return $items_query;
}

function create_status_query()
{
	global $languages_id;
	
	$status_query = zen_db_query("
	select 
		s.orders_status_id,
		s.orders_status_name
	from " . ZEN_ORDERS_STATUS . " s 
	where s.language_id = '" . (int)$languages_id . "' 
	order by s.orders_status_id
	");
	
	return $status_query;
}

function create_order_count_query()
{
	$query = zen_db_query("select count(*) as count from ".ZEN_ORDERS);
	return $query;
}

function create_customer_count_query()
{
	$query = zen_db_query("select count(*) as count from ".ZEN_CUSTOMERS);
	return $query;
}


// =========================== MISC functions ===========================

function outputLine($arr) {
	$arr = array_map("clean", $arr);
	$line = implode(DELIMITER,$arr);
	$line = unhtmlentities($line);
	$line = mb_convert_encoding($line,"UTF-8");
	echo $line."\n";
}

function outputStatusLine($arr) {
	$line = implode("*",$arr);
	$line = unhtmlentities($line);
	$line = mb_convert_encoding($line,"UTF-8");
	echo $line."\n";
}

function clean($str)
{
	$str = str_replace(DELIMITER,'{pipe}',$str);
	return $str;
}

function escape($str)
{
	$str = str_replace(':','{colon}',$str);
	$str = str_replace('*','{star}',$str);
	return $str;
}

function unhtmlentities($string)
{
    // replace numeric entities
    $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
    $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
    // replace literal entities
    $trans_tbl = get_html_translation_table(HTML_ENTITIES);
    $trans_tbl = array_flip($trans_tbl);
    return strtr($string, $trans_tbl);
}



// =========================== TEST functions ===========================

function testSuite()
{
	global $TEST_RESULT;
	
	ini_set('display_errors', 1);
	header('Content-Type: text/html; Charset=UTF-8');
	
	echo "<html><body><b>MyShop iPhone App plugin version ".VERSION."</b><br /><br /><table>";
	assertVersion ("phpversion",phpversion(),"4.3.11");
	assertVersion ("mysqlversion",mysql_get_server_info(),"4.1.0");
	assertTrue ("mb_convert_encoding",function_exists("mb_convert_encoding"));
	assertTrue ("zen_db_prepare_input",function_exists("zen_db_prepare_input"));
	assertTrue ("zen_db_input",function_exists("zen_db_input"));
	assertTrue ("zen_db_query",function_exists("zen_db_query"));
	assertTrue ("zen_db_fetch_array",function_exists("zen_db_fetch_array"));
	
	// test customer query
	$customers_query = create_customer_query("2000-01-01");
	$customers = zen_db_fetch_array($customers_query);
	assertEqual ("customer query",count($customers),13);
	
	// test products query
	$products_query = create_products_query("2000-01-01");
	$products = zen_db_fetch_array($products_query);
	assertEqual ("products query",count($products),5);
	
	// test products query
	$orders_query = create_orders_query("2000-01-01",null,1);
	$orders = zen_db_fetch_array($orders_query);
	assertEqual ("orders query",count($orders),9);
	
	// test items query
	$items_query = create_items_query($orders['orders_id']);
	$items = zen_db_fetch_array($items_query);
	assertEqual ("items query",count($items),10);
	
	echo "</table></body></html>";
	
	if ($TEST_RESULT) {
		echo "<p><b>All tests passed!</b> The app MyShop should run on your iPhone / iPod touch!</p>";
	} else {
		echo "<p><b style=\"color:red\">There were test failures!</b> Please visit <a href='http://appstore.malorny.net'>http://appstore.malorny.net</a> and contact the author if you can run the app MyShop!</p>";
	}
}

function assertTrue($name,$success)
{
	global $TEST_RESULT;
	
	$style = $success ? "color:green" : "color:red";
	$text  = $success ? "OK" : "FAIL";
	echo "<tr><td>$name ... </td><td></td><td style=\"$style\">$text</td></tr>\n";
	
	if (!$success) $TEST_RESULT = false;
}

function assertEqual($name,$test,$expected)
{
	global $TEST_RESULT;
	
	$success = ($test == $expected);
	
	$style = $success ? "color:green" : "color:red";
	$text  = $success ? "OK" : "FAIL";
	echo "<tr><td>$name ... </td><td>$test</td><td style=\"$style\">$text</td></tr>\n";
	
	if (!$success) $TEST_RESULT = false;
}

function assertVersion($name,$test,$expected)
{
	global $TEST_RESULT;
	
	$success = version_compare($test,$expected,">=");
	
	$style = $success ? "color:green" : "color:red";
	$text  = $success ? "OK" : "FAIL";
	echo "<tr><td>$name ... </td><td>$test</td><td style=\"$style\">$text</td></tr>\n";
	
	if (!$success) $TEST_RESULT = false;
}



?>


If this is great to share I am happy to do so (cant help it seeing its here)

thanks to all that read and possibly help

25 May 2009, 7:15 AM
#2
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

I think i forgot to mention....

just ad this to your admin section.
(you will get a test result on your screen)
www[dot]yoursite/admin/iphone.php

it seems to function until line 158 if that helps?

the error is
Fatal error: Call to undefined function: zen_db_query_raw() in /../../../pets/admin/iphone.php on line 158

25 May 2009, 7:28 AM
#3
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

forget the error above;

error now

Fatal error: Call to undefined function: zen_db_query() in /../../../pets/admin/iphone.php on line 158

sorry for the mistake

25 May 2009, 4:18 PM
#4
skipwater avatar

skipwater

Totally Zenned

Join Date:
Jun 2008
Location:
Washington, DC
Posts:
775
Plugin Contributions:
1

Re: need fresh eyes for possible addon (modified from osc)

There is no function: zen_db_query() in zen cart that is why it is failing. Check out this link Porting modules from osC
and this db link Developers - Database

Skip

26 May 2009, 3:34 AM
#5
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

thanks skip,

i will make the amendments in the next couple of days and post again after its working.....just got to do 2 weeks worth of study for uni first...ouch.

i only have 5 days before i go back.....

me so stupid hyuck hyuck LOL

26 May 2009, 9:46 AM
#6
marg avatar

marg

Totally Zenned

Join Date:
Mar 2004
Posts:
642
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

I'd be interested in this - thanks

26 May 2009, 1:28 PM
#7
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

thanks,

i have 3 conversions going on at the same time....steeeeeeep learning curb.

let me knock over my study then i can focus more and think a little clearer :blink:

hopefully we can get others to help with the shopfront for this function so we have both admin & shopfront.....double winner.

keep you posted :)

i think i am the only one that thinks outside the box (joking joking) but feels like it.....the 80's are 30yrs ago (joking)

27 May 2009, 12:56 AM
#8
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

hi all,

attached is a very basic and pretty dirty iPhone admin / order app.
you can call your customers, email and view orders all from your iPhone.

sure i will get some criticism for this but.......im sure many people will test and have their own ideas.

please make improvements, modifications and even delete it if you think it really sucks.

the 1st revision(above) is still being hacked into like blind woodsman, but this is the 'dirty version'.
its just to show others that you can use iPhone easily.

instructions,

just ad to your admin section( pref: admin/iphone_zen)
this is just to make sure that when you delete it you never have to worry).

download from: http://mychikyuya.com/iphone_zen.zip

back to study now :(

27 May 2009, 7:37 AM
#9
marg avatar

marg

Totally Zenned

Join Date:
Mar 2004
Posts:
642
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

Thank you kindly, kind sir!!

Now - cram cram cram!!

I'll write how I get on with the mod..

31 May 2009, 6:08 PM
#10
garby avatar

garby

New Zenner

Join Date:
May 2009
Posts:
48
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

I am still trying to convert from v 1.2... but am interested in this for the iPhone. I added it to my store folder and updated the config file, but when I go to the path to the file I just get an index of the folder. How do I get it so I can log in correctly? Thanks!

4 Jun 2009, 1:41 AM
#11
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

Hi Garby,

Admiting there is still some work to be done with this....login etc
I was hoping that more experienced zenners would help and we all would have something good.

hopefully within the next week i will address the login issues etc (this was only to test that i could see if the two play nicely)

but saying this i have been working on 3-4 really cool modules that are closely guarded by others......one of them includes the front-end for iphone,
this will let you login etc and then after this the backend will be completed along with a xhceckout style checkout (adapted from magento)

4 Jun 2009, 5:15 AM
#12
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

quick update....

<?php
/**

  • Zen iphone.php -- version 1.0beta
  • Modified by MrChristoh
  • By Dirk Malorny <iphone-apps (at) malorny (dot) net>
  • You may modify this script to fulfill your special needs, but all modifications you make are at your own risk!
    */

require('includes/application_top.php');

define("VERSION","1.0beta conversion");
define("DELIMITER","|");

// =========================== MAIN ===========================

$action = (isset($_REQUEST['a']) ? $_REQUEST['a'] : '');

if (zen_not_null($action)) {
header('Content-Type: text/plain; Charset=UTF-8');

switch ($action) {
	
case 'login':
	echo "OK";
	break;
	
	
case 'status':
	// 1: plugin version
	echo VERSION."\n";
	
	// 2: order_status
	$status_query = create_status_query();
	$arr = array();
	while ($status = mysql_fetch_array($status_query)) {
		$arr[] = $status['orders_status_id'].':'.escape($status['orders_status_name']);
	}
	outputStatusLine($arr);
	
	// 3: order count
	$order_count = mysql_fetch_array(create_order_count_query());
	echo $order_count['count']."\n";
	
	break;


case 'customers':
	$customers_query = create_customer_query($_REQUEST['lu']);
		
	while ($customers = mysql_fetch_array($customers_query)) {
		$arr = array();
		$arr[] = $customers['customers_id'];
		$arr[] = $customers['customers_lastname'];
		$arr[] = $customers['customers_firstname'];
		$arr[] = $customers['customers_email_address'];
		$arr[] = $customers['customers_dob'];
		$arr[] = $customers['customers_telephone'];
		$arr[] = $customers['customers_fax'];
		$arr[] = $customers['entry_company'];
		$arr[] = $customers['entry_street_address'];
		$arr[] = $customers['entry_postcode'];
		$arr[] = $customers['entry_city'];
		$arr[] = $customers['entry_state'];
		$arr[] = $customers['countries_name'];
		outputLine($arr);
	}
	break;
	

case 'products':
	$products_query = create_products_query($_REQUEST['lu'],$_REQUEST['of'],$_REQUEST['li']);
		
	while ($products = mysql_fetch_array($products_query)) {
		
		$arr = array();
		$arr[] = $products['products_id'];
		$arr[] = $products['products_model'];
		//$arr[] = $products['products_price'];
		$arr[] = $products['products_name'];
		$arr[] = ereg_replace("[\n\r]",'\n',$products['products_description']);
		outputLine($arr);
	}
	break;

	
case 'orders':
	$orders_query = create_orders_query($_REQUEST['lu'],$_REQUEST['of'],$_REQUEST['li']);

	$orderIds = array();
	while ($orders = mysql_fetch_array($orders_query)) {
		$orderIds[] = $orders['orders_id'];
		$arr = array();
		$arr[] = $orders['orders_id'];
		$arr[] = $orders['customers_id'];
		$arr[] = $orders['orders_status_id'];
		$arr[] = $orders['customers_name'];
		$arr[] = $orders['payment_method'];
		$arr[] = $orders['date_purchased'];
		$arr[] = $orders['currency'];
		$arr[] = $orders['orders_status_name'];
		$arr[] = $orders['order_total'];
		outputLine($arr);
	}
	
	if (!$orderIds) continue;
	
	// order items
	echo "\n--\n\n";
	$orderIds = implode(',',$orderIds);

	$items_query = create_items_query($orderIds);

	while ($items = mysql_fetch_array($items_query)) {
		$arr = array();
		$arr[] = $items['orders_products_id'];
		$arr[] = $items['orders_id'];
		$arr[] = $items['products_id'];
		$arr[] = $items['products_quantity'];
		$arr[] = $items['products_model'];
		$arr[] = $items['products_name'];
		$arr[] = $items['products_price'];
		$arr[] = $items['final_price'];
		$arr[] = $items['products_tax'];
		$arr[] = html_entity_decode(ereg_replace("[\n\r]",'\n',$items['attributes']));
		outputLine($arr);
	}
	break;
	


default:
	echo "unknown action";
	break;

} // switch

} else {
// TESTMODE
$TEST_RESULT = true;
testSuite();
} // MAIN

// =========================== QUERY functions ===========================

function create_customer_query($lu)
{
$filter = '';
if (isset($lu) && zen_not_null($lu)) {
$last_update = zen_db_input(zen_db_prepare_input($lu));
$filter = "where i.customers_info_date_account_created > '$last_update'
or i.customers_info_date_account_last_modified > '$last_update'";
}

$customers_query = mysql_query("
select 
	c.customers_id, 
	c.customers_lastname,
	c.customers_firstname,
	c.customers_email_address,
	NULLIF(DATE_FORMAT(c.customers_dob,'%Y-%m-%d'),'0000-00-00') customers_dob,
	c.customers_telephone,
	c.customers_fax,
	a.entry_company,
	a.entry_street_address,
	a.entry_postcode,
	a.entry_city,
	a.entry_state,
	l.countries_name 
from " . zen_customers . " c 
	 left join " . zen_address_book . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id
	 left join " . zen_countries . " l on a.entry_country_id = l.countries_id
	 left join " . zen_customers_info . " i on  c.customers_id = i.customers_info_id
$filter 
order by c.customers_id");

return $customers_query;

}

function create_products_query($lu,$of,$li)
{
$filter = '';
$limit = '';
if (isset($lu) && zen_not_null($lu)) {
$last_update = zen_db_input(zen_db_prepare_input($lu));
$filter = " and p.products_date_added > '$last_update'
or p.products_last_modified > '$last_update'";
}
if (isset($of) && zen_not_null($of)) {
$offset = zen_db_input(zen_db_prepare_input($of));
$filter .= " and p.products_id < $offset";
}
if (isset($li) && zen_not_null($li)) {
$limit = "limit " . zen_db_input(zen_db_prepare_input($li));
}

$products_query = mysql_query("
select 
	p.products_id, 
	p.products_model,
	p.products_price,
	d.products_name,
	d.products_description
from " . zen_products . " p
	 left join " . zen_products_description . " d on d.products_id = p.products_id
	 left join " . zen_languages . " l on l.languages_id = d.language_id
where 1
	$filter 
order by p.products_id DESC
$limit
");

return $products_query;

}

function create_orders_query($lu,$of,$li)
{
global $languages_id;

$filter = '';
$limit  = '';
if (isset($lu) && zen_not_null($lu)) {
	$last_update = zen_db_input(zen_db_prepare_input($lu));
	$filter .= " and (o.date_purchased > '$last_update' 
				 or o.last_modified > '$last_update')";
}
if (isset($of) && zen_not_null($of)) {
	$offset = zen_db_input(zen_db_prepare_input($of));
	$filter .= " and o.orders_id < $offset";
}
if (isset($li) && zen_not_null($li)) {
	$limit = "limit " . zen_db_input(zen_db_prepare_input($li));
}

$orders_query = mysql_query("
select 
	o.orders_id,
	o.customers_id,
	o.customers_name,
	o.payment_method,
	DATE_FORMAT(o.date_purchased,'%Y-%m-%d %H:%i:%s') date_purchased,
	o.currency,
	s.orders_status_id,
	s.orders_status_name,
	ot.value as order_total
from " . zen_orders . " o 
	 left join " . zen_orders_total . " ot on (o.orders_id = ot.orders_id),
	 " . zen_order_status . " s 
where o.orders_status = s.orders_status_id 
	and s.language_id = '" . (int)$languages_id . "' 
	and ot.class = 'ot_total'
	$filter
order by o.orders_id DESC
$limit
");

return $orders_query;

}

function create_items_query($orderIds)
{
$items_query = mysql_query("
select
op.orders_products_id,
op.orders_id,
op.products_id,
op.products_quantity,
op.products_model,
op.products_name,
op.products_price,
op.final_price,
op.products_tax,
group_concat(replace(concat_ws(':',replace(opa.products_options,':','{colon}'),replace(opa.products_options_values,':','{colon}')),'','{star}') separator '') attributes
from " . zen_orders_products . " op
left outer join
" . zen_orders_products_attribute . " opa
on op.orders_id=opa.orders_id
and op.orders_products_id=opa.orders_products_id
where op.orders_id in ($orderIds)
group by op.orders_products_id
order by op.orders_id DESC
");

return $items_query;

}

function create_status_query()
{
global $languages_id;

$status_query = mysql_query("
select 
	s.orders_status_id,
	s.orders_status_name
from " . zen_orders_status . " s 
where s.language_id = '" . (int)$languages_id . "' 
order by s.orders_status_id
");

return $status_query;

}

function create_order_count_query()
{
$query = mysql_query("select count(*) as count from ".zen_orders);
return $query;
}

function create_customer_count_query()
{
$query = mysql_query("select count(*) as count from ".zen_customers);
return $query;
}

// =========================== MISC functions ===========================

function outputLine($arr) {
$arr = array_map("clean", $arr);
$line = implode(DELIMITER,$arr);
$line = unhtmlentities($line);
$line = mb_convert_encoding($line,"UTF-8");
echo $line."\n";
}

function outputStatusLine($arr) {
$line = implode("*",$arr);
$line = unhtmlentities($line);
$line = mb_convert_encoding($line,"UTF-8");
echo $line."\n";
}

function clean($str)
{
$str = str_replace(DELIMITER,'{pipe}',$str);
return $str;
}

function escape($str)
{
$str = str_replace(':','{colon}',$str);
$str = str_replace('*','{star}',$str);
return $str;
}

function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);ei', 'chr(hexdec("\1"))', $string);
$string = preg_replace('
&#([0-9]+);~e', 'chr("\1")', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}

// =========================== TEST functions ===========================

function testSuite()
{
global $TEST_RESULT;

ini_set('display_errors', 1);
header('Content-Type: text/html; Charset=UTF-8');

echo "<html><body><b>MyShop iPhone App plugin version ".VERSION."</b><br /><br /><table>";
assertVersion ("phpversion",phpversion(),"4.3.11");
assertVersion ("mysqlversion",mysql_get_server_info(),"4.1.0");
assertTrue ("mb_convert_encoding",function_exists("mb_convert_encoding"));
assertTrue ("zen_db_prepare_input",function_exists("zen_db_prepare_input"));
assertTrue ("zen_db_input",function_exists("zen_db_input"));
assertTrue ("mysql_query",function_exists("mysql_query"));
assertTrue ("mysql_fetch_array",function_exists("mysql_fetch_array"));

// test customer query
$customers_query = create_customer_query("2009-01-01");
$customers = mysql_fetch_array($customers_query);
assertEqual ("customer query",count($customers),13);

// test products query
$products_query = create_products_query("2009-01-01",null,1);
$products = mysql_fetch_array($products_query);
assertEqual ("products query",count($products),5);

// test orders query
$orders_query = create_orders_query("2009-01-01",null,1);
$orders = mysql_fetch_array($orders_query);
assertEqual ("orders query",count($orders),9);

// test items query
$items_query = create_items_query($orders['orders_id']);
$items = mysql_fetch_array($items_query);
assertEqual ("items query",count($items),10);

echo "</table></body></html>";

if ($TEST_RESULT) {
	echo "<p><b>All tests passed!</b> The app MyShop should run on your iPhone / iPod touch!</p>";
} else {
	echo "<p><b style=\"color:red\">fail</b> </p>";
}

}

function assertTrue($name,$success)
{
global $TEST_RESULT;

$style = $success ? "color:green" : "color:red";
$text  = $success ? "OK" : "FAIL";
echo "<tr><td>$name ... </td><td></td><td style=\"$style\">$text</td></tr>\n";

if (!$success) $TEST_RESULT = false;

}

function assertEqual($name,$test,$expected)
{
global $TEST_RESULT;

$success = ($test == $expected);

$style = $success ? "color:green" : "color:red";
$text  = $success ? "OK" : "FAIL";
echo "<tr><td>$name ... </td><td>$test</td><td style=\"$style\">$text</td></tr>\n";

if (!$success) $TEST_RESULT = false;

}

function assertVersion($name,$test,$expected)
{
global $TEST_RESULT;

$success = version_compare($test,$expected,">=");

$style = $success ? "color:green" : "color:red";
$text  = $success ? "OK" : "FAIL";
echo "<tr><td>$name ... </td><td>$test</td><td style=\"$style\">$text</td></tr>\n";

if (!$success) $TEST_RESULT = false;

}

?>

this only produces 2 errors now (i think db related) judging by the error description.....ANY HELP ANYONE?

errors are as such:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mychiky/public_html/pets/admin/phonetest.php on line 392

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mychiky/public_html/pets/admin/phonetest.php on line 397

thanks to skip for the obvious reminder before.

when i get this going and if its with no help from this forum.....I will most probably hide it and sell like others do.
the more people that help, the more people will read and im willing to share so it makes zen better.

oh well back to study

4 Jun 2009, 3:41 PM
#13
skipwater avatar

skipwater

Totally Zenned

Join Date:
Jun 2008
Location:
Washington, DC
Posts:
775
Plugin Contributions:
1

Re: need fresh eyes for possible addon (modified from osc)

This is not a complete fix just an example of code to stop the Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource for Customer Query ...

// test customer query
// $customers_query = create_customer_query2("2009-01-01");
// $customers = mysql_fetch_array($customers_query);
// assertEqual ("Customer Query",count($customers_query),13);

// test just this
// Get db prefix if any
$db_prefix = DB_PREFIX;

global $db;

$filter = '';
$customers_query = "
select
c.customers_id,
c.customers_lastname,
c.customers_firstname,
c.customers_email_address,
NULLIF(DATE_FORMAT(c.customers_dob,'%Y-%m-%d'),'0000-00-00') customers_dob,
c.customers_telephone,
c.customers_fax,
a.entry_company,
a.entry_street_address,
a.entry_postcode,
a.entry_city,
a.entry_state,
l.countries_name
from " . $db_prefix.customers . " c
left join " . $db_prefix.address_book . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id
left join " . $db_prefix.countries . " l on a.entry_country_id = l.countries_id
left join " . $db_prefix.customers_info . " i on c.customers_id = i.customers_info_id " . $filter . "
order by c.customers_id";

$result = $db->Execute($customers_query);

assertEqual ("Customer Query",$result->RecordCount(),$result->RecordCount());

// eof test just this

Skip

5 Jun 2009, 5:27 AM
#14
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

hi Skip,

looks like the edit i done wasnt submitted.

i worked out the issue and you are 100000% correct :)

the edit that didnt come through was to address the error and a slight error in my sql query.
Im sure that this will improve and be great for all to share once its working.

please check here and the original errors have gone now, only have a small issue then we have something new.

thanks for helping ...... very much appreciated

2 Jul 2009, 4:33 PM
#15
rompalicious avatar

rompalicious

New Zenner

Join Date:
Oct 2008
Posts:
11
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

I just wanted to thank you for taking time to begin work on a mobile platform for Zencart - your initial layout is working very fine on my Blackberry Storm (iPhone ripoff).

While my coding and layout skills are minimal, I will, over the next few weeks, take a look at this and see if I can offer any improvement to process and layout.

Are you considering work on a front end too? Sure would be nice to have a simple catalog and purchase process that was accessible to the mobile market (and to me, for placing orders through my store when taking a call from a customer when I am away from my desk).

Thanks again. :clap:

3 Jul 2009, 8:28 AM
#16
stealthify avatar

stealthify

New Zenner

Join Date:
Dec 2008
Posts:
21
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

The preview seems to have moved, but I'm really interested in this.

I'd contribute what I can, but there are certainly others more qualified. Please keep us updated.

3 Jul 2009, 5:43 PM
#17
rompalicious avatar

rompalicious

New Zenner

Join Date:
Oct 2008
Posts:
11
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

I am sure he moved it because this "module" is currently far from secure... however, I have it running in my sandbox environment and it really is a good start.

Try installing what he has done so far and see what you think.

11 Aug 2009, 10:40 AM
#18
jsweb avatar

jsweb

Zen Follower

Join Date:
Jul 2005
Location:
UK and Ireland
Posts:
392
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

What is the current status on Zen+iPhone?

I only recently got myself an iPhone (which seems to have now stuck itself to my hand and won't come off ;) );

I noticed a youTube presentation of FRONT END builds for OS<>iPhone --> http://www.youtube.com/watch?v=0ed-miEuQng

and also an front end ZenCart<>iPhone http://www.branninggroup.com/zen-cart-mobile.php

(...havent tested these yet, but not sure if these are any better than using the iPhone browser -- you still need to know your way around the website and who is really buying GOODS online using a phone?; maybe I'm still a iPhone virgin)

However, I'm loving iPhone APPS (and some of these are good!!)

I'm therefore seeking an iPhone app for admins allowing owners to keep up to date with the key functions of received 'customer orders' or adding 'reorders'.

(I noticed there has been lots of movement with OS)...

Any updates would be most appreciated.

11 Aug 2009, 4:53 PM
#19
jsweb avatar

jsweb

Zen Follower

Join Date:
Jul 2005
Location:
UK and Ireland
Posts:
392
Plugin Contributions:
0

Re: need fresh eyes for possible addon (modified from osc)

Anyone had a play with http://appstore.malorny.net/myshop.php ?