par
Invité » 02 janv. 2007, 12:59
Voilà ce doit être ça !
function RenderTable(
$strTable,
$oCol,
$oNames,
$iWidth,
$sqlClause,
$strCheckColumnName,
$strCheckValue,
$strFormAction
){
global $arrHighlightIds;
global $strHighlightIdName;
global $IS_RADIO;
global $RADIO_VALUE;
global $DBHost,$DBUser,$DBPass,$DBName,$DBprefix,$action,$category;
global $strExplanationTitle,$PageSize,$PageNumber,$arrTDSizes,$iRTables;
global $SEARCH_IN,$SEARCH,$TOTAL_NUMBER_OF_RESULTS,$QUERY_EXECUTED_FOR,$PAGE_SIZE,$customFormEnd,$order,$order_type,$ORDER_QUERY,$QUERY_TO_EXECUTE,$comboSearch,$textSearch;
if(!isset($PageSize)){
$PageSize=20;
}
if(!isset($PageNumber)){
$PageNumber=1;
}
echo "
<script>
function ChangePageSize(x){
var category='$category';
var action='$action';
var newSize=10;
if(x==0){
newSize=5;
}
else
if(x==1){
newSize=10;
}
else
if(x==2){
newSize=20;
}
else
if(x==3){
newSize=50;
}
else
if(x==4){
newSize=100;
}
document.location.href='index.php?category=$category&action=$action&PageSize='+newSize+'';
}
</script>
";
if(isset($order)){
$strQuery="SELECT * FROM $DBprefix".$strTable." $sqlClause ORDER BY $order $order_type";
}
else
if(isset($textSearch)){
if(trim($sqlClause)!=""){
$strQuery="SELECT * FROM $DBprefix".$strTable." ".$sqlClause." AND ".$comboSearch." LIKE '%".$textSearch."%' ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
else{
$strQuery="SELECT * FROM $DBprefix".$strTable." WHERE ".$comboSearch." LIKE '%".$textSearch."%' ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
}
else
{
$strQuery="SELECT * FROM $DBprefix".$strTable." ".$sqlClause." ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
if($QUERY_TO_EXECUTE){
$strQuery=$QUERY_TO_EXECUTE;
}
$iTotalResults=SQLCount_Query($strQuery);
mysql_connect($DBHost,$DBUser,$DBPass);
mysql_select_db($DBName);
list($msec1,$sec1)=explode(" ",microtime());
$oDataTable=mysql_query($strQuery." LIMIT ".(($PageNumber-1)*$PageSize).",".($PageSize)."") or RegisterError("SQL_ERROR",$strQuery."<br>".mysql_error());
list($msec2,$sec2)=explode(" ",microtime());
$strExecutionTime=(intval($sec2)-intval($sec1))+(floatval($msec2)-floatval($msec1))." sec";
mysql_close();
echo "<table width=$iWidth>
<tr>
<td class=basictext>
<table>
<tr>
<td class=basicText>
<b>
$PAGE_SIZE:
<!--Taille de la page-->
</b>
</td>
<td class=basicText valign=top>
<select onchange='javascript:ChangePageSize(this.selectedIndex)'>
<option ".($PageSize==5?"selected":"").">5</option>
<option ".($PageSize==10?"selected":"").">10</option>
<option ".($PageSize==20?"selected":"").">20</option>
<option ".($PageSize==50?"selected":"").">50</option>
<option ".($PageSize==100?"selected":"").">100</option>
</select>
</td>
<td class=basictext>
<b>";
for($f=1;$f<=ceil($iTotalResults/$PageSize);$f++){
echo "<a href='index.php?category=$category&action=$action&PageSize=$PageSize&PageNumber=$f".(isset($order)?"&order=$order":"")."".(isset($order_type)?"&order_type=$order_type":"")."".(isset($comboSearch)?"&comboSearch=$comboSearch":"")."".(isset($textSearch)?"&textSearch=$textSearch":"")."'>$f</a>";
echo " ";
if($f==20){
break;
}
if($f%25==0){
echo "<br>";
}
}
echo " </b>
</td>
</tr>
</table>
</td>
<td class=basictext align=right>
<b>
";
if(isset($strExplanationTitle)){
$strExplanationTitle=str_replace("[COUNT]","(total: ".$iTotalResults.")",$strExplanationTitle);
echo $strExplanationTitle;
}
echo "
</b>
</td>
</tr>
</table><br>";
$iRTables++;
echo "<table height=22 cellspacing=0 cellpadding=0 width=$iWidth><form action='$strFormAction' method=POST><tr>
<td class=basictext width=60 >
<a href=\"javascript:nvoid()\" onclick=\"document.all.spanSearch".$iRTables.".style.display='none';document.all.spanInfo".$iRTables.".style.display='block';\"><img src='images/qhelp.gif' width=12 height=13 border=0></a>
<a href=\"javascript:nvoid()\" onclick=\"document.all.spanSearch".$iRTables.".style.display='block';document.all.spanInfo".$iRTables.".style.display='none';\"><img src='images/qsearch.gif' width=13 height=14 border=0></a>
</td>
<td width=".($iWidth-60)." class=basictext align=left valign=top>
<span id=spanInfo".$iRTables." style='display:none'>
$TOTAL_NUMBER_OF_RESULTS: <font color=red>".$iTotalResults."</font>
$QUERY_EXECUTED_FOR: <font color=red>".$strExecutionTime."</font>
</span>
<span id=spanSearch".$iRTables." style='display:none'>
$SEARCH_IN <select name=comboSearch style='font-size:11;font-family:verdana'>";
for($k=0;$k<sizeof($oNames);$k++){
if(strtolower(substr($oCol[$k],0,4))!="show"&&strtolower(substr($oCol[$k],0,4))!="edit")
{
echo "<option value=\"".$oCol[$k]."\" ".(isset($comboSearch)&&$comboSearch==$oCol[$k]?"selected":"").">".$oNames[$k]."</option>";
}
}
echo "</select> <input style='font-size:11;font-family:verdana' ".(isset($textSearch)?$textSearch:"")." type=text name=textSearch> <input type=submit class=adminButton value=' $SEARCH '>
</span>
</td></form>
</tr></table>";
echo "<table cellpadding=3 cellspacing=0 width=$iWidth style='border-color:#cecfce;border-width:1px 1px 1px 1px;border-style:solid'>";
echo "<form action='$strFormAction' method=POST> ";
echo "<tr class=table_header height=20 nowrap>";
$iTDWidth=0;
$iDefaultTDWidth=0;
$iTDTotalNumber=sizeof($oCol);
if(!isset($arrTDSizes)){
$iTDWidth=round(($iWidth-30)/$iTDTotalNumber);
$arrTDSizes=array_fill(0, sizeof($oCol), $iTDWidth);
}
else{
$iOccupied=0;
$iTDHaveValues=0;
foreach($arrTDSizes as $strTDSize){
if($strTDSize!="*"){
$iOccupied+=intval($strTDSize);
$iTDHaveValues++;
}
}
if(($iTDTotalNumber-$iTDHaveValues)==0){
$iDefaultTDWidth=round((($iWidth-30)-$iOccupied)/($iTDHaveValues));
}
else{
$iDefaultTDWidth=round((($iWidth-30)-$iOccupied)/($iTDTotalNumber-$iTDHaveValues));
}
for($k=0;$k<sizeof($arrTDSizes);$k++){
if($arrTDSizes[$k]!="*"){
$arrTDSizes[$k]=intval($arrTDSizes[$k]);
}
else{
$arrTDSizes[$k]=$iDefaultTDWidth;
}
}
}
if(trim($strCheckColumnName)!=""){
echo "<td class=oHeader width=30 nowrap >$strCheckColumnName</td>";
}
$iTDHeaderCounter=0;
if(!isset($order_type)){
$order_type="desc";
$strImgName="";
}
else
if($order_type=="asc"){
$order_type="desc";
$strImgName="up";
}
else{
$order_type="asc";
$strImgName="down";
}
$arrFields=GetFieldsInTable($strTable);
foreach ($oNames as $columnName)
{
echo "<td class=oHeader width=".$arrTDSizes[$iTDHeaderCounter]." nowrap >
<table cellspacing=0 cellpadding=0><tr><td class=oHeader>
".(in_array($oCol[$iTDHeaderCounter],$arrFields)?("<a href='".$strFormAction."&order=".$oCol[$iTDHeaderCounter]."&order_type=".$order_type."' style='color:#8c8a73'>"):"")."
$columnName
</a>
</td><td class=oHeader>
".((isset($order)&&$order==$oCol[$iTDHeaderCounter]&&$strImgName!="")?"<img src='../ADMIN/images/".$strImgName.".gif' width=10 height=10 style='position:relative;top:2;left:3'>":"")."
</td></tr></table>
</td>";
$iTDHeaderCounter++;
}
echo "</tr>";
$boolColor=true;
while ($myArray = mysql_fetch_array($oDataTable))
{
if(isset($arrHighlightIds) && isset($strHighlightIdName) && in_array($myArray[$strHighlightIdName],$arrHighlightIds,false)){
echo "<tr bgcolor=\"#efefef\" height=20>";
}
else{
echo "<tr bgcolor=".($boolColor?"#ffffff":"#efefef")." height=20>";
}
if(trim($strCheckColumnName)!=""){
$cVal=$myArray["$strCheckValue"];
echo "<td class=oMain nowrap >";
if(isset($IS_RADIO)){
echo "<input type=radio name=CheckList value=\"$cVal\" ".($cVal==$RADIO_VALUE?"checked":"").">";
}
else{
echo "<input type=checkbox name=CheckList[] value='$cVal'>";
}
echo "</td>";
}
foreach ($oCol as $columnName) {
$strParticularCases=particularCases($columnName,$myArray);
if($strParticularCases!=""){
echo $strParticularCases;
}
else
if($columnName == "date")
{
if(isset($myArray[$columnName]) && $myArray[$columnName] != "")
{
global $PHP_DATE_FORMAT;
echo "<td class=oMain>".date($PHP_DATE_FORMAT,$myArray[$columnName])."</td>";
}
else
{
echo "<td class=oMain> </td>";
}
}
else{
$val="";
if(isset($myArray[$columnName])){
$val=$myArray[$columnName];
}
if(isset($textSearch)&&$comboSearch==$columnName)
{
$val=eregi_replace($textSearch,"<span style='background:yellow'>".$textSearch."</span>",$val);
echo "<td class=oMain>".$val."</td>";
}
else{
if(substr($val,0,4) == "http")
{
echo "<td class=oMain><a href=\"$val\">$val</a></td>";
}
else{
echo "<td class=oMain>$val</td>";
}
}
}
}
echo "</tr>";
$boolColor=$boolColor?false:true;
}
echo "</table>";
if(trim($strCheckColumnName)!=""){
echo "
<br>
<input type=hidden name='$strCheckColumnName' value=''>
<table width=".($iWidth+15)." cellpadding=0 cellspacing=0><tr><td align=right>
<input type=submit name=DELETE value=' $strCheckColumnName ' class=adminButton>
</td></tr></table>
";
}
if(isset($customFormEnd)&&$customFormEnd){
}
else{
echo "</form>";
}
}
Voilà ce doit être ça !
[php]function RenderTable(
$strTable,
$oCol,
$oNames,
$iWidth,
$sqlClause,
$strCheckColumnName,
$strCheckValue,
$strFormAction
){
global $arrHighlightIds;
global $strHighlightIdName;
global $IS_RADIO;
global $RADIO_VALUE;
global $DBHost,$DBUser,$DBPass,$DBName,$DBprefix,$action,$category;
global $strExplanationTitle,$PageSize,$PageNumber,$arrTDSizes,$iRTables;
global $SEARCH_IN,$SEARCH,$TOTAL_NUMBER_OF_RESULTS,$QUERY_EXECUTED_FOR,$PAGE_SIZE,$customFormEnd,$order,$order_type,$ORDER_QUERY,$QUERY_TO_EXECUTE,$comboSearch,$textSearch;
if(!isset($PageSize)){
$PageSize=20;
}
if(!isset($PageNumber)){
$PageNumber=1;
}
echo "
<script>
function ChangePageSize(x){
var category='$category';
var action='$action';
var newSize=10;
if(x==0){
newSize=5;
}
else
if(x==1){
newSize=10;
}
else
if(x==2){
newSize=20;
}
else
if(x==3){
newSize=50;
}
else
if(x==4){
newSize=100;
}
document.location.href='index.php?category=$category&action=$action&PageSize='+newSize+'';
}
</script>
";
if(isset($order)){
$strQuery="SELECT * FROM $DBprefix".$strTable." $sqlClause ORDER BY $order $order_type";
}
else
if(isset($textSearch)){
if(trim($sqlClause)!=""){
$strQuery="SELECT * FROM $DBprefix".$strTable." ".$sqlClause." AND ".$comboSearch." LIKE '%".$textSearch."%' ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
else{
$strQuery="SELECT * FROM $DBprefix".$strTable." WHERE ".$comboSearch." LIKE '%".$textSearch."%' ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
}
else
{
$strQuery="SELECT * FROM $DBprefix".$strTable." ".$sqlClause." ".(isset($ORDER_QUERY)?$ORDER_QUERY:"");
}
if($QUERY_TO_EXECUTE){
$strQuery=$QUERY_TO_EXECUTE;
}
$iTotalResults=SQLCount_Query($strQuery);
mysql_connect($DBHost,$DBUser,$DBPass);
mysql_select_db($DBName);
list($msec1,$sec1)=explode(" ",microtime());
$oDataTable=mysql_query($strQuery." LIMIT ".(($PageNumber-1)*$PageSize).",".($PageSize)."") or RegisterError("SQL_ERROR",$strQuery."<br>".mysql_error());
list($msec2,$sec2)=explode(" ",microtime());
$strExecutionTime=(intval($sec2)-intval($sec1))+(floatval($msec2)-floatval($msec1))." sec";
mysql_close();
echo "<table width=$iWidth>
<tr>
<td class=basictext>
<table>
<tr>
<td class=basicText>
<b>
$PAGE_SIZE:
<!--Taille de la page-->
</b>
</td>
<td class=basicText valign=top>
<select onchange='javascript:ChangePageSize(this.selectedIndex)'>
<option ".($PageSize==5?"selected":"").">5</option>
<option ".($PageSize==10?"selected":"").">10</option>
<option ".($PageSize==20?"selected":"").">20</option>
<option ".($PageSize==50?"selected":"").">50</option>
<option ".($PageSize==100?"selected":"").">100</option>
</select>
</td>
<td class=basictext>
<b>";
for($f=1;$f<=ceil($iTotalResults/$PageSize);$f++){
echo "<a href='index.php?category=$category&action=$action&PageSize=$PageSize&PageNumber=$f".(isset($order)?"&order=$order":"")."".(isset($order_type)?"&order_type=$order_type":"")."".(isset($comboSearch)?"&comboSearch=$comboSearch":"")."".(isset($textSearch)?"&textSearch=$textSearch":"")."'>$f</a>";
echo " ";
if($f==20){
break;
}
if($f%25==0){
echo "<br>";
}
}
echo " </b>
</td>
</tr>
</table>
</td>
<td class=basictext align=right>
<b>
";
if(isset($strExplanationTitle)){
$strExplanationTitle=str_replace("[COUNT]","(total: ".$iTotalResults.")",$strExplanationTitle);
echo $strExplanationTitle;
}
echo "
</b>
</td>
</tr>
</table><br>";
$iRTables++;
echo "<table height=22 cellspacing=0 cellpadding=0 width=$iWidth><form action='$strFormAction' method=POST><tr>
<td class=basictext width=60 >
<a href=\"javascript:nvoid()\" onclick=\"document.all.spanSearch".$iRTables.".style.display='none';document.all.spanInfo".$iRTables.".style.display='block';\"><img src='images/qhelp.gif' width=12 height=13 border=0></a>
<a href=\"javascript:nvoid()\" onclick=\"document.all.spanSearch".$iRTables.".style.display='block';document.all.spanInfo".$iRTables.".style.display='none';\"><img src='images/qsearch.gif' width=13 height=14 border=0></a>
</td>
<td width=".($iWidth-60)." class=basictext align=left valign=top>
<span id=spanInfo".$iRTables." style='display:none'>
$TOTAL_NUMBER_OF_RESULTS: <font color=red>".$iTotalResults."</font>
$QUERY_EXECUTED_FOR: <font color=red>".$strExecutionTime."</font>
</span>
<span id=spanSearch".$iRTables." style='display:none'>
$SEARCH_IN <select name=comboSearch style='font-size:11;font-family:verdana'>";
for($k=0;$k<sizeof($oNames);$k++){
if(strtolower(substr($oCol[$k],0,4))!="show"&&strtolower(substr($oCol[$k],0,4))!="edit")
{
echo "<option value=\"".$oCol[$k]."\" ".(isset($comboSearch)&&$comboSearch==$oCol[$k]?"selected":"").">".$oNames[$k]."</option>";
}
}
echo "</select> <input style='font-size:11;font-family:verdana' ".(isset($textSearch)?$textSearch:"")." type=text name=textSearch> <input type=submit class=adminButton value=' $SEARCH '>
</span>
</td></form>
</tr></table>";
echo "<table cellpadding=3 cellspacing=0 width=$iWidth style='border-color:#cecfce;border-width:1px 1px 1px 1px;border-style:solid'>";
echo "<form action='$strFormAction' method=POST> ";
echo "<tr class=table_header height=20 nowrap>";
$iTDWidth=0;
$iDefaultTDWidth=0;
$iTDTotalNumber=sizeof($oCol);
if(!isset($arrTDSizes)){
$iTDWidth=round(($iWidth-30)/$iTDTotalNumber);
$arrTDSizes=array_fill(0, sizeof($oCol), $iTDWidth);
}
else{
$iOccupied=0;
$iTDHaveValues=0;
foreach($arrTDSizes as $strTDSize){
if($strTDSize!="*"){
$iOccupied+=intval($strTDSize);
$iTDHaveValues++;
}
}
if(($iTDTotalNumber-$iTDHaveValues)==0){
$iDefaultTDWidth=round((($iWidth-30)-$iOccupied)/($iTDHaveValues));
}
else{
$iDefaultTDWidth=round((($iWidth-30)-$iOccupied)/($iTDTotalNumber-$iTDHaveValues));
}
for($k=0;$k<sizeof($arrTDSizes);$k++){
if($arrTDSizes[$k]!="*"){
$arrTDSizes[$k]=intval($arrTDSizes[$k]);
}
else{
$arrTDSizes[$k]=$iDefaultTDWidth;
}
}
}
if(trim($strCheckColumnName)!=""){
echo "<td class=oHeader width=30 nowrap >$strCheckColumnName</td>";
}
$iTDHeaderCounter=0;
if(!isset($order_type)){
$order_type="desc";
$strImgName="";
}
else
if($order_type=="asc"){
$order_type="desc";
$strImgName="up";
}
else{
$order_type="asc";
$strImgName="down";
}
$arrFields=GetFieldsInTable($strTable);
foreach ($oNames as $columnName)
{
echo "<td class=oHeader width=".$arrTDSizes[$iTDHeaderCounter]." nowrap >
<table cellspacing=0 cellpadding=0><tr><td class=oHeader>
".(in_array($oCol[$iTDHeaderCounter],$arrFields)?("<a href='".$strFormAction."&order=".$oCol[$iTDHeaderCounter]."&order_type=".$order_type."' style='color:#8c8a73'>"):"")."
$columnName
</a>
</td><td class=oHeader>
".((isset($order)&&$order==$oCol[$iTDHeaderCounter]&&$strImgName!="")?"<img src='../ADMIN/images/".$strImgName.".gif' width=10 height=10 style='position:relative;top:2;left:3'>":"")."
</td></tr></table>
</td>";
$iTDHeaderCounter++;
}
echo "</tr>";
$boolColor=true;
while ($myArray = mysql_fetch_array($oDataTable))
{
if(isset($arrHighlightIds) && isset($strHighlightIdName) && in_array($myArray[$strHighlightIdName],$arrHighlightIds,false)){
echo "<tr bgcolor=\"#efefef\" height=20>";
}
else{
echo "<tr bgcolor=".($boolColor?"#ffffff":"#efefef")." height=20>";
}
if(trim($strCheckColumnName)!=""){
$cVal=$myArray["$strCheckValue"];
echo "<td class=oMain nowrap >";
if(isset($IS_RADIO)){
echo "<input type=radio name=CheckList value=\"$cVal\" ".($cVal==$RADIO_VALUE?"checked":"").">";
}
else{
echo "<input type=checkbox name=CheckList[] value='$cVal'>";
}
echo "</td>";
}
foreach ($oCol as $columnName) {
$strParticularCases=particularCases($columnName,$myArray);
if($strParticularCases!=""){
echo $strParticularCases;
}
else
if($columnName == "date")
{
if(isset($myArray[$columnName]) && $myArray[$columnName] != "")
{
global $PHP_DATE_FORMAT;
echo "<td class=oMain>".date($PHP_DATE_FORMAT,$myArray[$columnName])."</td>";
}
else
{
echo "<td class=oMain> </td>";
}
}
else{
$val="";
if(isset($myArray[$columnName])){
$val=$myArray[$columnName];
}
if(isset($textSearch)&&$comboSearch==$columnName)
{
$val=eregi_replace($textSearch,"<span style='background:yellow'>".$textSearch."</span>",$val);
echo "<td class=oMain>".$val."</td>";
}
else{
if(substr($val,0,4) == "http")
{
echo "<td class=oMain><a href=\"$val\">$val</a></td>";
}
else{
echo "<td class=oMain>$val</td>";
}
}
}
}
echo "</tr>";
$boolColor=$boolColor?false:true;
}
echo "</table>";
if(trim($strCheckColumnName)!=""){
echo "
<br>
<input type=hidden name='$strCheckColumnName' value=''>
<table width=".($iWidth+15)." cellpadding=0 cellspacing=0><tr><td align=right>
<input type=submit name=DELETE value=' $strCheckColumnName ' class=adminButton>
</td></tr></table>
";
}
if(isset($customFormEnd)&&$customFormEnd){
}
else{
echo "</form>";
}
}[/php]