par
Invité » 07 sept. 2005, 09:11
Ca doit être par là alors
/*
* Generic class to create dynamicTables
*/
class dynamicTable {
var $result;
var $setup;
var $size;
var $index;
var $pos;
var $calcStart;
var $rows;
var $start;
/*
* Return the ID of the setup row
*/
function id() {
return $this->setup['id'];
}
/*
* The number of headers
*/
function size() {
return $this->size;
}
function ok() {
return ($this->rows > 0);
}
/*
* Return the next heading
*/
function headings($i=-1) {
if ($i == -1) {
if ($this->setup[$this->index] != "") {
$this->index++;
return ($this->setup[$this->index-1]);
}
else
return false;
}
return ($this->setup[$i+2]);
}
/*
* See if we have a calculated field
*/
function ifCalc($i) {
return ($this->setup[$i+$this->calcStart]!="");
}
/*
* Return the calculated field
*/
function calc($i) {
return ($this->setup[$i+$this->calcStart - 1]);
}
/*
* Return the postion number of the standing
*/
function position($i) {
if ($this->setup[$i+$this->calcStart]=="pos") {
$origpos = $this->pos;
$this->pos++;
return $origpos;
}
return "";
}
/*
* Get a row of data for this dynamic table
*/
function fetchRow(&$data_result, &$data) {
global $db;
$data = $db->sql_fetchrow($data_result);
if (empty($data)) {
return false;
}
return (true);
}
/*
* Return the next data value from a row of data
*/
function fetchRowValue(&$data_index, &$data, $start, $i=0) {
$index = $data_index;
$index2 = $index + 1;
if ($i == 0) {
if ($data[$index] != "") {
$data_index = $index2;
return ($data[$index]);
}
}
return ($data[$i + $start]);
}
}
/*
* Stanndings tables
*/
class Standings extends dynamicTable {
var $data;
var $data_index;
var $data_result;
function Standings($lid) {
global $prefix, $db;
$this->result = $db->sql_query("select * from " . $prefix . "_league_standings_setup where lid = $lid");
$this->setup = $db->sql_fetchrow($this->result);
$this->rows = $db->sql_numrows($this->result);
$c=0;
for ($i=2; $i < 17; $i++) {
if ($this->setup[$i] != "")
$c++;
else
break;
}
$this->size = $c;
$this->start = 2;
$this->index = 2;
$this->pos = 1;
$this->calcStart=17;
}
function size() {
return ($this->size);
}
function select($did, $sid, $limit=0, $tid=0) {
global $prefix, $db;
if ($did != 0)
$select_did = " and " . $prefix . "_league_team_seasons.did = $did ";
else
$select_did = "";
$select = "select " . $prefix . "_league_teams.id as tid, " . $prefix . "_league_standings.id as stdid,";
$j=1;
for ($i=$this->calcStart; $i < $this->size+$this->calcStart; $i++) {
if ($this->setup[$i] != "") {
if ($this->setup[$i] == "pos")
$select .= "1 as std$j,";
else
$select .= eregi_replace("col","std",$this->setup[$i]) . " as std$j,";
}
else {
$select .= "std$j,";
}
$j++;
}
$select = substr($select, 0, strlen($select)-1);
$select .= " from " . $prefix . "_league_team_seasons, " . $prefix . "_league_teams," . $prefix . "_league_standings where " . $prefix . "_league_teams.id = " . $prefix . "_league_standings.tid and " . $prefix . "_league_standings.sid = $sid and " . $prefix . "_league_team_seasons.sid = " . $prefix . "_league_standings.sid and " . $prefix . "_league_teams.id = " . $prefix . "_league_team_seasons.tid $select_did";
if ($tid != 0)
$select .= "and " . $prefix . "_league_teams.id = $tid ";
$by = "";
$order = "";
if ($this->setup['sort1'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort1'] . " desc,";
}
if ($this->setup['sort2'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort2'] . " desc,";
}
if ($this->setup['sort3'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort3'] . " desc,";
}
if (strlen($order) > 0) {
$by = substr($by, 0, strlen($by)-1);
$select .= "$order $by";
}
if ($limit > 0)
$select .= " limit $limit";
//echo "$select<br><br>";
$this->data_result = $db->sql_query($select);
}
function fetchSetupSort() {
$row = array();
$row[0] = $this->setup['sort1'];
$row[1] = $this->setup['sort2'];
$row[2] = $this->setup['sort3'];
return ($row);
}
function fetchSetupGame() {
$row = array();
$row[0] = $this->setup['W'];
$row[1] = $this->setup['T'];
$row[2] = $this->setup['L'];
$row[3] = $this->setup['PF'];
$row[4] = $this->setup['PA'];
return ($row);
}
function fetchRowStdid() {
return ($this->data['stdid']);
}
function fetchRow() {
$ret = dynamicTable::fetchRow($this->data_result, $this->data);
if ($ret)
$this->data_index = 2;
else
$this->data_index = 0;
return $ret;
}
function fetchRowValue($i=0) {
return dynamicTable::fetchRowValue($this->data_index, $this->data,
$this->start, $i);
}
function tid() {
return $this->data['tid'];
}
}
/*
* Game Summary table
*/
class Games extends dynamicTable {
var $data_index;
var $tid1;
var $tid2;
var $data_team1_result;
var $data_team2_result;
var $data_team1;
var $data_team2;
function Games($lid) {
global $prefix, $db;
$this->result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary_setup where lid = $lid");
$this->setup = $db->sql_fetchrow($this->result);
$this->rows = $db->sql_numrows($this->result);
$c=0;
for ($i=2;$i < 13; $i++) {
if ($this->setup[$i] != "")
$c++;
}
$this->size = $c;
$this->index = 2;
$this->start = 2;
}
function select($schid, $tid) {
global $prefix, $db;
$result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary where schid = $schid and tid = $tid");
return ($result);
}
function fetchRow(&$result, &$data) {
$ret = dynamicTable::fetchRow($result, $data);
if ($ret)
$this->data_index = 3;
else
$this->data_index = 0;
return $ret;
}
function setTid1($tid) {
$this->tid1 = $tid;
}
function setTid2($tid) {
$this->tid2 = $tid;
}
function fetchRowValueTeam(&$data, $i) {
return dynamicTable::fetchRowValue($this->data_index, $data,
$this->start, $i, 1);
}
function summaryTeam1($schid) {
$this->data_team1_result = $this->select($schid, $this->tid1);
$this->fetchRow($this->data_team1_result, $this->data_team1);
}
function summaryTeam2($schid) {
$this->data_team2_result = $this->select($schid, $this->tid2);
$this->fetchRow($this->data_team2_result, $this->data_team2);
}
function summaryTeamOK($team_data) {
for($i=1; $i <= $this->size+1; $i++) {
$val = $this->fetchRowValueTeam($team_data, $i);
if ($val != "")
return 1;
}
return 0;
}
function summaryTeam1OK() {
return ($this->summaryTeamOK($this->data_team1));
}
function summaryTeam2OK() {
return ($this->summaryTeamOK($this->data_team1));
}
function printTeamSummary($team, $data, $id, $display=1) {
echo "<tr>";
echo "<td align=\"right\" nowrap><b>" . $team . ":</b> </td>";
for ($i=1;$i <= $this->size(); $i++) {
$value = $this->fetchRowValueTeam($data, $i);
echo "<td align=\"center\">";
if ($display == 1)
echo "$value";
else
echo "<input type=\"text\" name=\"team" . $id . "_period[$i]\" value=\"$value\" size=\"2\">";
echo "</td>";
}
echo "</tr>";
}
function printTeam1Summary($display) {
$this->printTeamSummary(getTeamName($this->tid1), $this->data_team1, "1", $display);
}
function printTeam2Summary($display) {
$this->printTeamSummary(getTeamName($this->tid2), $this->data_team2, "2", $display);
}
}
Ca doit être par là alors :wink:
[php]/*
* Generic class to create dynamicTables
*/
class dynamicTable {
var $result;
var $setup;
var $size;
var $index;
var $pos;
var $calcStart;
var $rows;
var $start;
/*
* Return the ID of the setup row
*/
function id() {
return $this->setup['id'];
}
/*
* The number of headers
*/
function size() {
return $this->size;
}
function ok() {
return ($this->rows > 0);
}
/*
* Return the next heading
*/
function headings($i=-1) {
if ($i == -1) {
if ($this->setup[$this->index] != "") {
$this->index++;
return ($this->setup[$this->index-1]);
}
else
return false;
}
return ($this->setup[$i+2]);
}
/*
* See if we have a calculated field
*/
function ifCalc($i) {
return ($this->setup[$i+$this->calcStart]!="");
}
/*
* Return the calculated field
*/
function calc($i) {
return ($this->setup[$i+$this->calcStart - 1]);
}
/*
* Return the postion number of the standing
*/
function position($i) {
if ($this->setup[$i+$this->calcStart]=="pos") {
$origpos = $this->pos;
$this->pos++;
return $origpos;
}
return "";
}
/*
* Get a row of data for this dynamic table
*/
function fetchRow(&$data_result, &$data) {
global $db;
$data = $db->sql_fetchrow($data_result);
if (empty($data)) {
return false;
}
return (true);
}
/*
* Return the next data value from a row of data
*/
function fetchRowValue(&$data_index, &$data, $start, $i=0) {
$index = $data_index;
$index2 = $index + 1;
if ($i == 0) {
if ($data[$index] != "") {
$data_index = $index2;
return ($data[$index]);
}
}
return ($data[$i + $start]);
}
}
/*
* Stanndings tables
*/
class Standings extends dynamicTable {
var $data;
var $data_index;
var $data_result;
function Standings($lid) {
global $prefix, $db;
$this->result = $db->sql_query("select * from " . $prefix . "_league_standings_setup where lid = $lid");
$this->setup = $db->sql_fetchrow($this->result);
$this->rows = $db->sql_numrows($this->result);
$c=0;
for ($i=2; $i < 17; $i++) {
if ($this->setup[$i] != "")
$c++;
else
break;
}
$this->size = $c;
$this->start = 2;
$this->index = 2;
$this->pos = 1;
$this->calcStart=17;
}
function size() {
return ($this->size);
}
function select($did, $sid, $limit=0, $tid=0) {
global $prefix, $db;
if ($did != 0)
$select_did = " and " . $prefix . "_league_team_seasons.did = $did ";
else
$select_did = "";
$select = "select " . $prefix . "_league_teams.id as tid, " . $prefix . "_league_standings.id as stdid,";
$j=1;
for ($i=$this->calcStart; $i < $this->size+$this->calcStart; $i++) {
if ($this->setup[$i] != "") {
if ($this->setup[$i] == "pos")
$select .= "1 as std$j,";
else
$select .= eregi_replace("col","std",$this->setup[$i]) . " as std$j,";
}
else {
$select .= "std$j,";
}
$j++;
}
$select = substr($select, 0, strlen($select)-1);
$select .= " from " . $prefix . "_league_team_seasons, " . $prefix . "_league_teams," . $prefix . "_league_standings where " . $prefix . "_league_teams.id = " . $prefix . "_league_standings.tid and " . $prefix . "_league_standings.sid = $sid and " . $prefix . "_league_team_seasons.sid = " . $prefix . "_league_standings.sid and " . $prefix . "_league_teams.id = " . $prefix . "_league_team_seasons.tid $select_did";
if ($tid != 0)
$select .= "and " . $prefix . "_league_teams.id = $tid ";
$by = "";
$order = "";
if ($this->setup['sort1'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort1'] . " desc,";
}
if ($this->setup['sort2'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort2'] . " desc,";
}
if ($this->setup['sort3'] > 0) {
$order = "order by ";
$by .= "std" . $this->setup['sort3'] . " desc,";
}
if (strlen($order) > 0) {
$by = substr($by, 0, strlen($by)-1);
$select .= "$order $by";
}
if ($limit > 0)
$select .= " limit $limit";
//echo "$select<br><br>";
$this->data_result = $db->sql_query($select);
}
function fetchSetupSort() {
$row = array();
$row[0] = $this->setup['sort1'];
$row[1] = $this->setup['sort2'];
$row[2] = $this->setup['sort3'];
return ($row);
}
function fetchSetupGame() {
$row = array();
$row[0] = $this->setup['W'];
$row[1] = $this->setup['T'];
$row[2] = $this->setup['L'];
$row[3] = $this->setup['PF'];
$row[4] = $this->setup['PA'];
return ($row);
}
function fetchRowStdid() {
return ($this->data['stdid']);
}
function fetchRow() {
$ret = dynamicTable::fetchRow($this->data_result, $this->data);
if ($ret)
$this->data_index = 2;
else
$this->data_index = 0;
return $ret;
}
function fetchRowValue($i=0) {
return dynamicTable::fetchRowValue($this->data_index, $this->data,
$this->start, $i);
}
function tid() {
return $this->data['tid'];
}
}
/*
* Game Summary table
*/
class Games extends dynamicTable {
var $data_index;
var $tid1;
var $tid2;
var $data_team1_result;
var $data_team2_result;
var $data_team1;
var $data_team2;
function Games($lid) {
global $prefix, $db;
$this->result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary_setup where lid = $lid");
$this->setup = $db->sql_fetchrow($this->result);
$this->rows = $db->sql_numrows($this->result);
$c=0;
for ($i=2;$i < 13; $i++) {
if ($this->setup[$i] != "")
$c++;
}
$this->size = $c;
$this->index = 2;
$this->start = 2;
}
function select($schid, $tid) {
global $prefix, $db;
$result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary where schid = $schid and tid = $tid");
return ($result);
}
function fetchRow(&$result, &$data) {
$ret = dynamicTable::fetchRow($result, $data);
if ($ret)
$this->data_index = 3;
else
$this->data_index = 0;
return $ret;
}
function setTid1($tid) {
$this->tid1 = $tid;
}
function setTid2($tid) {
$this->tid2 = $tid;
}
function fetchRowValueTeam(&$data, $i) {
return dynamicTable::fetchRowValue($this->data_index, $data,
$this->start, $i, 1);
}
function summaryTeam1($schid) {
$this->data_team1_result = $this->select($schid, $this->tid1);
$this->fetchRow($this->data_team1_result, $this->data_team1);
}
function summaryTeam2($schid) {
$this->data_team2_result = $this->select($schid, $this->tid2);
$this->fetchRow($this->data_team2_result, $this->data_team2);
}
function summaryTeamOK($team_data) {
for($i=1; $i <= $this->size+1; $i++) {
$val = $this->fetchRowValueTeam($team_data, $i);
if ($val != "")
return 1;
}
return 0;
}
function summaryTeam1OK() {
return ($this->summaryTeamOK($this->data_team1));
}
function summaryTeam2OK() {
return ($this->summaryTeamOK($this->data_team1));
}
function printTeamSummary($team, $data, $id, $display=1) {
echo "<tr>";
echo "<td align=\"right\" nowrap><b>" . $team . ":</b> </td>";
for ($i=1;$i <= $this->size(); $i++) {
$value = $this->fetchRowValueTeam($data, $i);
echo "<td align=\"center\">";
if ($display == 1)
echo "$value";
else
echo "<input type=\"text\" name=\"team" . $id . "_period[$i]\" value=\"$value\" size=\"2\">";
echo "</td>";
}
echo "</tr>";
}
function printTeam1Summary($display) {
$this->printTeamSummary(getTeamName($this->tid1), $this->data_team1, "1", $display);
}
function printTeam2Summary($display) {
$this->printTeamSummary(getTeamName($this->tid2), $this->data_team2, "2", $display);
}
}[/php]