Community Add-Ons

Maintainers: pbor1234
Add file to this package
Top » Other

Multiple dropdown configuration
for osCommerce Online Merchant v2.2

Contribution:
================================================
Multiple dropdown configuration


Description:
================================================
This contribution allows you to define a configuration item to select multiple order statuses. It's pretty easy to create functions for other types, this contribution adds the basic implementation to configuration.php and provides a sample on how to use it.


Sample sql:
================================================
INSERT INTO `configuration` ( `configuration_id` , `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` )
VALUES ('', "Pending sales statuses", 'RCS_PENDING_SALE_STATUS', 'a:5:{i:0;s:1:"7";i:1;s:1:"8";i:2;s:1:"6";i:3;s:1:"4";i:4;s:1:"2";}',
"Select the order statuses that can be considered as pending. This information is used to find a succesfull order from the same customer with the same products", 6501, 85, NULL, NOW(), 'tep_get_multiple_order_status_names', 'tep_cfg_pull_down_multiple_order_statuses(');

This is just a sample (don't start importing it now...)


Sample how to use:
================================================
In any query use it like this:

...and o.orders_status NOT IN (' . implode(unserialize(RCS_PENDING_SALE_STATUS), ',') . ') and...


Limitations:
================================================
- Changing the configuration setting will not preselect the current selections
- The query (when used as the example) will fail if the list is empty


Changes/Additions:
================================================
admin/configuration.php (line 20):

Replace:

if (tep_not_null($action)) {
switch ($action) {
case 'save':
$configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);
$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));
break;
}
}

With:

if (tep_not_null($action)) {
switch ($action) {
case 'save':
$configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);

//BOF Multiple dropdown
if(is_array($configuration_value)) {
$configuration_value = serialize($configuration_value);
}
//EOF Multiple dropdown

$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));
break;
}
}


admin/includes/functions/general.php

Add (somewhere):

//BOF Multiple dropdown
function tep_cfg_pull_down_multiple_order_statuses($order_status_id, $key = '') {
global $languages_id;

$name = 'configuration_value[]';

$statuses_array = array(array('id' => '0', 'text' => TEXT_DEFAULT));
$statuses_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' order by orders_status_name");
while ($statuses = tep_db_fetch_array($statuses_query)) {
$statuses_array[] = array('id' => $statuses['orders_status_id'],
'text' => $statuses['orders_status_name']);
}

return tep_draw_pull_down_menu($name, $statuses_array, $order_status_id, "multiple");
}

function tep_get_multiple_order_status_names($values, $language_id = '') {
global $languages_id;
$order_status_names = "";

$order_statuses = unserialize($values);
if(is_array($order_statuses) && 0 != count($order_statuses)) {
if (!is_numeric($language_id)) $language_id = $languages_id;

$status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id IN (" . implode($order_statuses, ',') . ") and language_id = '" . (int)$language_id . "'");
while($status = tep_db_fetch_array($status_query)) {
$order_status_names .= $status['orders_status_name'] . ', ';
}
}

return trim($order_status_names, ', ');
}
//EOF Multiple dropdown

Legend:  Download   Report
Expand All / Collapse All
Multiple dropdown configuration pbor1234 28 Mar 2009  

Contribution:
================================================
Multiple dropdown configuration


Description:
================================================
This contribution allows you to define a configuration item to select multiple order statuses. It's pretty easy to create functions for other types, this contribution adds the basic implementation to configuration.php and provides a sample on how to use it.


Sample sql:
================================================
INSERT INTO `configuration` ( `configuration_id` , `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` )
VALUES ('', "Pending sales statuses", 'RCS_PENDING_SALE_STATUS', 'a:5:{i:0;s:1:"7";i:1;s:1:"8";i:2;s:1:"6";i:3;s:1:"4";i:4;s:1:"2";}',
"Select the order statuses that can be considered as pending. This information is used to find a succesfull order from the same customer with the same products", 6501, 85, NULL, NOW(), 'tep_get_multiple_order_status_names', 'tep_cfg_pull_down_multiple_order_statuses(');

This is just a sample (don't start importing it now...)


Sample how to use:
================================================
In any query use it like this:

...and o.orders_status NOT IN (' . implode(unserialize(RCS_PENDING_SALE_STATUS), ',') . ') and...


Limitations:
================================================
- Changing the configuration setting will not preselect the current selections
- The query (when used as the example) will fail if the list is empty


Changes/Additions:
================================================
admin/configuration.php (line 20):

Replace:

if (tep_not_null($action)) {
switch ($action) {
case 'save':
$configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);
$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));
break;
}
}

With:

if (tep_not_null($action)) {
switch ($action) {
case 'save':
$configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);

//BOF Multiple dropdown
if(is_array($configuration_value)) {
$configuration_value = serialize($configuration_value);
}
//EOF Multiple dropdown

$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));
break;
}
}


admin/includes/functions/general.php

Add (somewhere):

//BOF Multiple dropdown
function tep_cfg_pull_down_multiple_order_statuses($order_status_id, $key = '') {
global $languages_id;

$name = 'configuration_value[]';

$statuses_array = array(array('id' => '0', 'text' => TEXT_DEFAULT));
$statuses_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' order by orders_status_name");
while ($statuses = tep_db_fetch_array($statuses_query)) {
$statuses_array[] = array('id' => $statuses['orders_status_id'],
'text' => $statuses['orders_status_name']);
}

return tep_draw_pull_down_menu($name, $statuses_array, $order_status_id, "multiple");
}

function tep_get_multiple_order_status_names($values, $language_id = '') {
global $languages_id;
$order_status_names = "";

$order_statuses = unserialize($values);
if(is_array($order_statuses) && 0 != count($order_statuses)) {
if (!is_numeric($language_id)) $language_id = $languages_id;

$status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id IN (" . implode($order_statuses, ',') . ") and language_id = '" . (int)$language_id . "'");
while($status = tep_db_fetch_array($status_query)) {
$order_status_names .= $status['orders_status_name'] . ', ';
}
}

return trim($order_status_names, ', ');
}
//EOF Multiple dropdown