function category_load($id, $param=array()) { global $db_central; $db=null; // Postgre-Escape id $pg_id=postgre_escape($id); // if requesting newest version use central database if(isset($param['version'])&&($param['version']=="newest")) { $db=$db_central; } // if no version supplied, return current version if(isset($param['version'])&&($param['version']!="newest")) { $version=$param['version']; } else { $res=sql_query("select * from category_current where category_id=$pg_id", $db); if(!$elem=pg_fetch_assoc($res)) { return array('status'=>"'$id': No such category"); } else { $version=$elem['version']; } } // Postgre-Escape version $pg_version=postgre_escape($version); // Get root of category $res=sql_query("select * from category where version=$pg_version", $db); if(!$elem=pg_fetch_assoc($res)) { return array('status'=>"'$id/$version': No such category/version"); } $res=sql_query("select * from category_current where category_id='$id'", $db_central); $newest=pg_fetch_assoc($res); // Prepare returning XML $dom=new DOMDocument(); $root=$dom->createElement("category"); $dom->appendChild($root); $root->setAttribute("id", $id); $root->setAttribute("version", $version); if($newest) $root->setAttribute("newest_version", $newest['version']); // process Tags $tags=new tags(parse_hstore($elem['tags'])); $tags->writeDOM($root, $dom); // check if there's important stuff in version tags $version_tags=parse_hstore($elem['version_tags']); if($version_tags['lock']=="yes") $root->setAttribute("lock", "yes"); // Now process the rules $res=sql_query("select * from category_rule where version=$pg_version", $db); while($elem=pg_fetch_assoc($res)) { // base $rule=$dom->createElement("rule"); $rule->setAttribute("id", $elem['rule_id']); $root->appendChild($rule); // tags $tags=new tags(parse_hstore($elem['tags'])); $tags->writeDOM($rule, $dom); } // we are done! return $dom->saveXML(); }