| <?php | |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php"; | |
| require_once "/home/data/httpd/eclipse-php-classes/system/app.class.php"; | |
| #***************************************************************************** | |
| # | |
| # mir_list.php | |
| # | |
| # Author: Denis Roy | |
| # Date: 2004-11-16 | |
| # | |
| # Description: Logic for displaying mirrors according to incoming parameters | |
| # | |
| # HISTORY: | |
| # | |
| #***************************************************************************** | |
| $_drop_id = $_GET['drop_id'] ? $_GET['drop_id'] : $_POST['drop_id']; | |
| $_format = $_GET['format'] ? $_GET['format'] : $_POST['format']; | |
| $_debug = $_GET['debug']; | |
| $_protocol = $_GET['protocol'] ? $_GET['protocol'] : $_POST['protocol']; | |
| $_version = $_GET['version'] ? $_GET['version'] : $_POST['version']; | |
| if($_format != "html" && $_format != "xml") { | |
| $_format = "html"; | |
| } | |
| if($_protocol != "http" && $_protocol != "ftp" && $_protocol != "rsync" && $_protocol != "bittorrent") { | |
| $_protocol = ""; | |
| } | |
| # Connect to database | |
| $dbc = new DBConnectionRW(); | |
| $dbh = $dbc->connect(); | |
| $app = new App(); | |
| # ensure incoming drop_id parameter is a valid drop_id | |
| if($_drop_id != "") { | |
| $sql = "SELECT | |
| COUNT(drop_id) AS RecordCount | |
| FROM drops | |
| WHERE drop_id = '$_drop_id' | |
| "; | |
| $rs = mysql_query($sql, $dbh); | |
| $myrow = mysql_fetch_assoc($rs); | |
| if($myrow['RecordCount'] == 0) { | |
| $_drop_id = ""; | |
| } | |
| } | |
| # Build where string | |
| if($_drop_id == "") { | |
| $_drop_id = "Full"; | |
| } | |
| $where = " DRP.drop_id = 'EclipseFull'"; | |
| # temp table req'd because curent version of mysql doesn't support union | |
| createTmpMirList($_drop_id, $_drop_id, "_tmp_mir_list", $dbh, false); | |
| # Add Full | |
| if($_drop_id == "Update" || $_drop_id == "Stable" || $_drop_id == "Release") { | |
| createTmpMirList($_drop_id, "Full", "_tmp_mir_list2", $dbh, true); | |
| $sql = "INSERT INTO _tmp_mir_list SELECT * FROM _tmp_mir_list2"; | |
| if($_debug == 1) { | |
| echo $sql; | |
| } | |
| mysql_query($sql,$dbh); | |
| mysql_query("DROP TABLE _tmp_mir_list2", $dbh); | |
| } | |
| # Add EclipseFull | |
| if($_drop_id != "EclipseFull") { | |
| createTmpMirList($_drop_id, "EclipseFull", "_tmp_mir_list3", $dbh, true); | |
| $sql = "INSERT INTO _tmp_mir_list SELECT * FROM _tmp_mir_list3"; | |
| if($_debug == 1) { | |
| echo $sql; | |
| } | |
| mysql_query($sql,$dbh); | |
| mysql_query("DROP TABLE _tmp_mir_list3", $dbh); | |
| } | |
| #Fetch complete resultset | |
| $sql = "SELECT TMP.*, | |
| COU.en_description AS country_desc, | |
| CON.en_description AS continent_desc | |
| FROM _tmp_mir_list AS TMP | |
| INNER JOIN SYS_countries AS COU ON COU.ccode = TMP.ccode | |
| INNER JOIN SYS_continents AS CON ON CON.continent_code = COU.continent_code | |
| ORDER BY TMP.organization"; | |
| if($_debug == 1) { | |
| echo $sql; | |
| } | |
| $rs = mysql_query($sql, $dbh); | |
| if($_format == "html") { | |
| include("inc/en_mir_list.php"); | |
| } | |
| if($_format == "xml") { | |
| $app->sendXMLHeader(); | |
| include("inc/en_mir_list_xml.php"); | |
| } | |
| $dbc->disconnect(); | |
| $rs = null; | |
| $dbh = null; | |
| $dbc = null; | |
| # Local subroutines | |
| function createTmpMirList($_drop_id_wanted, $_drop_id_search, $_table_name, $_dbh, $_exclude_dups) { | |
| global $_debug; | |
| global $_protocol; | |
| # Add EclipseFull | |
| $join = ""; | |
| $where = " MRD.drop_id = '$_drop_id_search'"; | |
| if($_exclude_dups) { | |
| $join = "LEFT JOIN _tmp_mir_list AS TMP ON TMP.mirror_id = MIR.mirror_id"; | |
| $where .= " AND TMP.drop_id IS NULL"; | |
| } | |
| if($_protocol != "") { | |
| $where .= " AND MRP.protocol = '$_protocol'"; | |
| } | |
| $sql = "CREATE TEMPORARY TABLE $_table_name AS | |
| SELECT | |
| MIR.mirror_id, | |
| MIR.organization, | |
| MIR.ccode, | |
| MRD.drop_id, | |
| DRP.our_path, | |
| MRP.protocol, | |
| MRP.base_path, | |
| MRD.rel_path_override, | |
| DRW.our_path AS our_path2 | |
| FROM mirrors AS MIR | |
| INNER JOIN mirror_protocols AS MRP on MRP.mirror_id = MIR.mirror_id | |
| INNER JOIN mirror_drops AS MRD ON MRD.mirror_id = MIR.mirror_id | |
| AND MRD.protocol = MRP.protocol | |
| INNER JOIN drops as DRP ON DRP.drop_id = '$_drop_id_search' | |
| INNER JOIN drops as DRW ON DRW.drop_id = '$_drop_id_wanted' | |
| $join | |
| WHERE | |
| MIR.is_internal <> 1 | |
| AND MIR.is_advertise = 1 | |
| AND MIR.create_status = 'active' | |
| AND $where | |
| "; | |
| if($_debug == 1) { | |
| echo $sql; | |
| } | |
| mysql_query($sql, $_dbh); | |
| } | |
| function getPath($_cur_drop_id, $_drop_id, $_rel_path_override, $_our_path, $_our_path2) { | |
| global $_version; | |
| $path = ""; | |
| if($_cur_drop_id == $_drop_id) { | |
| if($_rel_path_override != "") { | |
| $path = $_rel_path_override; | |
| } | |
| else { | |
| $path = $_our_path; | |
| } | |
| } | |
| else { | |
| if($_rel_path_override != "") { | |
| # Build path | |
| $our_path2 = str_replace($_our_path, $_rel_path_override, $_our_path2); | |
| $path = $our_path2; | |
| } | |
| else { | |
| $path = $_our_path2; | |
| } | |
| } | |
| if($_version != "") { | |
| $path .= "/" . $_version; | |
| } | |
| return $path; | |
| } | |
| ?> | |