Changeset 2914
- Timestamp:
- 02/04/12 09:05:44 (3 months ago)
- Location:
- trunk/lib/phpcommon
- Files:
-
- 1 added
- 2 modified
-
functions.php (modified) (8 diffs)
-
racesgroups.class.php (added)
-
users.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/phpcommon/functions.php
r2883 r2914 826 826 } 827 827 828 828 829 function getNumOpponents($idraces, $check = TRUE) { 829 830 //force type int … … 857 858 // arrivés en course inscrits (arr + out + en course) 858 859 return (array ($num_arrived,$num_racing,$num_arrived + $num_out + $num_racing)); 860 } 861 862 function getRacesGroupsBatch($racelist) { 863 $ret = Array(); 864 $in = "races.idraces IN ("; 865 $first = TRUE; 866 foreach ($racelist as $idr) { 867 if ($first) { 868 $first = FALSE; 869 $in.=$idr; 870 } else { 871 $in.=",".$idr; 872 } 873 } 874 $in.=")"; 875 876 $query = "SELECT races.`idraces`, group_concat(grouptag) AS grouptaglist ". 877 "FROM races LEFT JOIN racestogroups ON (races.idraces = racestogroups.idraces) WHERE ".$in." ". 878 "GROUP BY races.idraces"; 879 $result = wrapper_mysql_db_query_reader($query) or die($query); 880 while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 881 $ret[$row['idraces']] = $row; 882 } 883 return $ret; 859 884 } 860 885 … … 981 1006 $html .= htmlTinymap($rowdatas['idraces'], $rowdatas['racename']); 982 1007 $html .= "</td>\n"; 1008 $html .= " <td class=\"grouptaglist\">"; 1009 foreach (split(',', $rowdatas['grouptaglist']) as $g) { 1010 $html .= htmlRacesGroupLink($g); 1011 $html .= " "; 1012 } 1013 $html .= "</td>\n"; 983 1014 $html .= " </tr>\n"; 984 1015 return $html; … … 989 1020 } 990 1021 991 function dispHtmlRacesList($where = "") { 992 993 echo "<table>\n"; 994 echo "<thead>\n"; 995 echo " <tr>\n"; 996 echo " <th>".getLocalizedString("raceid")."</th>\n"; 997 echo " <th>".getLocalizedString("racename")."</th>\n"; 998 echo " <th>".getLocalizedString("departuredate")." (GMT)</th>\n"; 999 echo " <th>". join('<br />', explode("/", getLocalizedString("racenumboats")))."</th>\n"; 1000 echo " <th>".getLocalizedString("map")."</th>\n"; 1001 echo " </tr>\n"; 1002 echo " </thead>\n"; 1003 echo " <tbody>\n"; 1004 // echo "<tr><td></td><td></td><td></td><td></td></tr>"; 1005 1006 1007 // La requete qui donne la liste des courses en cours 1008 $query= "SELECT idraces, racename, started, deptime, startlong, startlat, ". 1009 "boattype, closetime, racetype, if(started=".RACE_ENDED.", 0, deptime) ". 1010 "AS deptimesort FROM races $where ORDER by started DESC, deptimesort ASC, ". 1011 "closetime DESC, idraces DESC"; 1012 1013 $result = wrapper_mysql_db_query_reader($query) or die($query); 1014 1015 if (mysql_num_rows($result)) { 1016 $allRacesRows = array(); 1017 $allRacesIds = array(); 1018 while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 1019 array_push($allRacesRows, $row); 1020 array_push($allRacesIds, $row['idraces']); 1021 } 1022 $allNumOpponents = getNumOpponentBatch($allRacesIds); 1023 1024 foreach($allRacesRows as $row) { 1025 $row['num_opps'] = $allNumOpponents[$row['idraces']]; 1026 echo htmlRacesListRow($row); 1027 } 1022 function dispHtmlRacesList($where = "", $limit = 100) { 1023 1024 // La requete qui donne la liste des courses en cours 1025 $query= "SELECT races.idraces, racename, started, deptime, startlong, startlat, ". 1026 "boattype, closetime, racetype, if(started=".RACE_ENDED.", 0, deptime) ". 1027 "AS deptimesort, group_concat(grouptag) AS grouptaglist ". 1028 "FROM races LEFT JOIN racestogroups ON (races.idraces = racestogroups.idraces) $where ". 1029 "GROUP BY races.idraces ORDER by started DESC, deptimesort ASC, closetime DESC, idraces DESC ". 1030 "LIMIT $limit"; 1031 1032 $result = wrapper_mysql_db_query_reader($query) or die($query); 1033 1034 if (mysql_num_rows($result)) { 1035 $allRacesRows = array(); 1036 while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 1037 $allRacesRows[$row['idraces']] = $row; 1038 } 1039 echo htmlRacesList($allRacesRows); 1040 } 1041 } 1042 1043 function htmlRacesList($raceslist) { 1044 $html = ""; 1045 $html .= "<table>\n"; 1046 $html .= "<thead>\n"; 1047 $html .= " <tr>\n"; 1048 $html .= " <th>".getLocalizedString("raceid")."</th>\n"; 1049 $html .= " <th>".getLocalizedString("racename")."</th>\n"; 1050 $html .= " <th>".getLocalizedString("departuredate")." (GMT)</th>\n"; 1051 $html .= " <th>". join('<br />', explode("/", getLocalizedString("racenumboats")))."</th>\n"; 1052 $html .= " <th>".getLocalizedString("map")."</th>\n"; 1053 $html .= " <th>".getLocalizedString("Group(s)")."</th>\n"; 1054 $html .= " </tr>\n"; 1055 $html .= " </thead>\n"; 1056 $html .= " <tbody>\n"; 1057 1058 $allNumOpponents = getNumOpponentBatch(array_keys($raceslist)); 1059 $allRacesGroups = getRacesGroupsBatch(array_keys($raceslist)); 1060 1061 foreach ($raceslist as $idraces => $row) { 1062 $row['num_opps'] = $allNumOpponents[$row['idraces']]; 1063 $row['grouptaglist'] = $allRacesGroups[$row['idraces']]['grouptaglist']; 1064 $html .= htmlRacesListRow($row); 1028 1065 } 1029 1066 1030 echo "</tbody>\n"; 1031 echo "</table>\n "; 1067 $html .= "</tbody>\n"; 1068 $html .= "</table>\n "; 1069 1070 return $html; 1071 } 1072 1073 function htmlRacesGroupLink($grouptag) { 1074 if (is_null($grouptag) || $grouptag == "") return ""; 1075 return "<a href=\"/racesgroups.php?grouptag=$grouptag\">!$grouptag</a>"; 1032 1076 } 1033 1077 … … 1465 1509 } 1466 1510 1511 function getFullUserObject($id, $initrow = NULL) { 1512 if (!is_null($uo = getUserObject($id, $initrow))) { 1513 return new fullUsers($id, $uo); 1514 } else { 1515 return null; 1516 } 1517 } 1518 1467 1519 function getUserObject($id, $initrow = NULL) { 1468 1520 static $uobjects = Array(); … … 1569 1621 } 1570 1622 1571 function setUserPref($idusers, $pref_name,$pref_value, $save=true) {1623 function setUserPref($idusers, $pref_name, $pref_value, $save=true) { 1572 1624 //FIXME : this is duplicated in users.class 1573 1625 if ($idusers != "" and $save) { … … 1583 1635 1584 1636 function getUserPref($idusers,$pref_name) { 1585 1586 1637 if ($idusers != "") { 1587 1638 $query_pref = "SELECT `pref_value` FROM `user_prefs` WHERE `idusers` = $idusers AND `pref_name` = '$pref_name'"; … … 1594 1645 1595 1646 return ($pref_value); 1596 }1597 }1598 1599 function listUserPref($idusers, $prefix = null) {1600 if ($idusers != "") {1601 $prefs=array();1602 $query_pref = "SELECT `pref_name`, `pref_value` FROM `user_prefs` WHERE `idusers` = $idusers";1603 if (!is_null($prefix)) $query_pref .= " AND `pref_name` LIKE '".$prefix."%'";1604 $query_pref .= " ORDER BY `pref_name`";1605 $result_pref = wrapper_mysql_db_query_reader($query_pref) or die($query_pref);1606 while ( $row = mysql_fetch_array($result_pref, MYSQL_ASSOC) ) {1607 $prefs[$row["pref_name"]]=$row["pref_value"];1608 }1609 return($prefs);1610 1647 } 1611 1648 } -
trunk/lib/phpcommon/users.class.php
r2876 r2914 652 652 } 653 653 } 654 655 function getMyPref($pref_name) {654 655 function feedPrefs() { 656 656 if (!isset($this->preferences)) { 657 657 $query_pref = "SELECT pref_name, pref_value FROM user_prefs". … … 669 669 $this->preferences['boatname'] = $this->users->boatname; 670 670 } 671 } 672 673 function getMyPref($pref_name) { 674 $this->feedPrefs(); 671 675 if (array_key_exists($pref_name, $this->preferences)) { 672 676 return $this->preferences[$pref_name];
