Thursday, January 26, 2006

Bug of sorting numerical values

The bug consists in not correct comparison of two numerical values in sorting functions of a file /usr/system/common_extfunctions.inc.php. I.e., for example, we sort on ID, we have records with ID: 1,2,3,4,5,6,7,8,9,10,11 in database. After performance of sorting _ORDER (INDEX, ID, ASC) _ in application get_infochannel (or anyone similar) the result will be following: 1,10,11,2,3,4,5,6,7,8,9.

Here it is an example of what there was and on what I have changed it, I'll not explain, who knows - all easily will understand:
// What there was
if(!defined("cmp_indexasc")) {
function cmp_indexasc($a, $b) {
global $sapi_obj;
$index = $sapi_obj->env["index"];
return strcmp($a[$index], $b[$index]);
}
define("cmp_indexasc", 1);
}

if(!defined("cmp_indexdesc")) {
function cmp_indexdesc($a, $b) {
global $sapi_obj;
$index = $sapi_obj->env["index"];
return strcmp($a[$index], $b[$index]);
}
define("cmp_indexdesc", 1);
}

// On what we change
if(!defined("cmp_indexasc")) {
function cmp_indexasc($a, $b) {
global $sapi_obj;
$index = $sapi_obj->env["index"];
if(is_numeric($a[$index]))
return ($a[$index] > $b[$index]) ? -1 : 1;
else
return strcmp($a[$index], $b[$index]);
}
define("cmp_indexasc", 1);
}

if(!defined("cmp_indexdesc")) {
function cmp_indexdesc($a, $b) {
global $sapi_obj;
$index = $sapi_obj->env["index"];
if(is_numeric($a[$index]))
return ($a[$index] > $b[$index]) ? 1 : -1;
else
return strcmp($a[$index], $b[$index]);
}
define("cmp_indexdesc", 1);
}
Also I offer to download already corrected file if suddenly someone laziness to correct it by himself ;)

Download: common_extfunctions.inc.zip
For version: Sapid 1.2.3 RC3

Wednesday, January 25, 2006

Lite version of get_infochannel

One of these days I've made the extension which is the lite version of get_infochannel, but as against it doesn't create any folders like /usr/xml/vdb/news/ in database, the index file is created only.

The given module is ideal for creation of various lists, price-lists, etc.

Download: get_list.zip
For version: Sapid 1.2.3 RC3