buongiorno ragazzi scusate avrei bisognio un a vostra mano , ho scaricato una classe dal sito phpclasses.org , e l ho modificata a secondo le mie necessita , ora la classe per il datagrid funziona , però se nel database e inseroito un link o un email , me la vede come semplice testo perche? posto la classe e in fase di modifiche
Codice PHP:
<?php
class phpSortTable {
var $tableName;
var $urlKeyName;
var $tableKeyName;
var $editLink;
var $editTarget;
var $editWindowFormat;
var $deleteLink;
var $addLink;
var $addTarget;
var $addText;
var $editPromptMsg;
var $deletePromptMsg;
var $asc_img;
var $desc_img;
var $edit_img;
var $delete_img;
var $add_img;
var $cellpadding = "" ;
var $cellspacing = "" ;
var $tableborder = "" ;
var $width = "" ;
var $tbclass = "" ;
var $style = "" ;
var $columHeader = array();
var $columContent = array();
var $tableTitle = array();
var $defaultRowsNum;
var $imgFilePath;
var $cssFilePath;
var $emptyMsg;
var $columns;
var $selfLink;
var $urlVars; # contains the application given urls vars
/**
* @var string total number of rows found in the query
*/
var $totalRows;
var $shownRows;
var $colsNum;
var $rows;
var $begin;
var $sortby;
function __construct($connectionData, $tableName) {
$this->connectionData = $connectionData;
$this->tableName = $tableName;
/**
* * * * * * * * * * * * * * * * *
* Vars Initialization
* * * * * * * * * * * * * * * * *
*/
$this->imgFilePath = "phpSortTable/img/";
$this->cssFilePath = "phpSortTable/php_sort_table.css";
$this->asc_img = "asc.gif";
$this->desc_img = "desc.gif";
$this->add_img = "add.gif";
$this->delete_img = "delete.gif";
$this->edit_img = "edit.gif";
$this->defaultRowsNum = 5;
$this->emptyMsg = "No data to be shown.";
$this->editWindowFormat = "";
}
function phpSortTable($connectionData, $tableName) {
$this->connectionData = $connectionData;
$this->tableName = $tableName;
/**
* * * * * * * * * * * * * * * * *
* Vars Initialization
* * * * * * * * * * * * * * * * *
*/
$this->imgFilePath = "phpSortTable/img/";
$this->cssFilePath = "phpSortTable/php_sort_table.css";
$this->asc_img = "asc.gif";
$this->desc_img = "desc.gif";
$this->add_img = "add.gif";
$this->delete_img = "delete.gif";
$this->edit_img = "edit.gif";
$this->defaultRowsNum = 5;
$this->emptyMsg = "No data to be shown.";
}
function setPackageFilePath ($path) {
$this->packageFilePath = $path;
}
/**
* @access private
* @return void connect to the database with the configured
* connection parameters
*/
function connect(){
$connParam = explode(",", $this->connectionData, 4);
$host = $connParam[0];
$db = $connParam[1];
$user = $connParam[2];
$pass = $connParam[3];
$connection = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db, $connection) or die(mysql_error());
return $connection;
}
/**
* @access public
* @return void set the format strings for the table
* @param string $cellpadding cellpading table parameter
* @param string $cellspacing cellspacing table parameter
* @param string $border border table parameter
*/
function setTableFormat($cellpadding = "", $cellspacing = "", $tableborder = "", $width = "", $tbclass = "", $style = "")
{
$this->cellpadding = $cellpadding;
$this->cellspacing = $cellspacing;
$this->tableborder = $tableborder;
$this->width = $width;
$this->tbclass = $tbclass;
$this->style = $style;
}
/**
* @access private
* @return void this is the main function, which should be called by
* the application do display the html table
*/
function printTable()
{
$this->sortby = isset($_GET['sortby'])?$_GET['sortby']:''; // column to sort
$this->rows = isset($_GET['rows'])?$_GET['rows']:''; // amount of rows to be shown
$this->begin = isset($_GET['begin'])?$_GET['begin']:''; // where to begin in the total of rows
$this->sortdir = isset($_GET['sortdir'])?$_GET['sortdir']:''; // sort direction
# picks the url vars from the application, if they exist
$this->selfLink = $_SERVER['SCRIPT_NAME'] . "?";
$this->urlVars = "";
foreach ($_GET as $key => $value)
{
if(($key != "sortby") && ($key != "rows") && ($key != "begin") && ($key != "sortdir")) {
$this->selfLink .= '&' . $key . '=' . $value;
$this->urlVars .= '&' . $key . '=' . $value;
}
}
if (strlen($this->begin) < 1){$this->begin = 0;}
if (strlen($this->sortdir) < 1){$this->sortdir = "ASC";}
if (strlen($this->rows) < 1){
$this->rows = $this->defaultRowsNum;
$this->begin = 0;
}
# executes the db connection
$connection = $this->connect();
# build the SQL Query
$sql = "SELECT * FROM " . $this->tableName;
#appends the WHERE clause if it exists
if (strlen($this->whereClause) > 0)
$sql .= $this->whereClause;
# appends ORDER BY clause if it is set
if (strlen($this->sortby) > 0)
$sql .= " ORDER BY " . $this->sortby . " " . $this->sortdir;
# appends LIMIT clause
$sql .= " LIMIT " . $this->begin . ", " . $this->rows;
# builds the query for total rows
$sqlT = "SELECT * FROM " . $this->tableName;
#appends the WHERE clause if it exists
if (strlen($this->whereClause) > 0)
$sqlT .= $this->whereClause;
# executes the queries
$select = mysql_query($sql, $connection) or die(mysql_error());
$selectT = mysql_query($sqlT, $connection) or die(mysql_error());
# changes the sort direction now for the Columns
$this->sortdir = ($this->sortdir == "ASC") ? "ASC" : "DESC";
$this->sortimg = ($this->sortdir == "ASC") ? $this->asc_img : $this->desc_img;
$this->totalRows = mysql_num_rows($selectT);
$this->shownRows = mysql_num_rows($select);
$this->colsNum = count($this->columns);
/* echo "\n\n\n"; */
# declare the css file if it is defined, else use the default
echo '<link href="'.$this->cssFilePath.'" rel="stylesheet" type="text/css">';
/* $this->printTitle(); */
# if table is empty, shows the Empty Message
if ($this->totalRows < 1) {
$this->printEmptyMsg();
}else{
$this->printHeader();
$this->printContent($select);
}
$this->printFooter();
# close the connection
mysql_close($connection);
}
function printHeader()
{
echo '<table cellpadding="'.$this->cellpadding.'" cellspacing="'.$this->cellspacing.'" border="'.$this->tableborder.'" width="'.$this->width .'" class="'.$this->tbclass.'" style="'.$this->style.'">';
if(count($this->columHeader) > 0)
{
echo "<thead>";
echo "<tr>";
for($ii=0; $ii<count($this->columHeader); $ii++){
echo '<td id = "tab'.$this->columHeader[$ii].'"
class = "'.$this->columHeader[$ii]['class'].'"
width = "'.$this->columHeader[$ii]['width'].'"
height = "'.$this->columHeader[$ii]['height'].'"
colspan = "'.$this->columHeader[$ii]['colspan'].'"
align = "'.$this->columHeader[$ii]['align'].'"
valign = "'.$this->columHeader[$ii]['valign'].'" nowrap>
'.$this->columHeader[$ii]['title'].'</td>';
}
echo "</tr>";
echo "</thead>";
}
$index=0;
echo '<tr id="headerRow">';
foreach($this->columns as $column)
{
$sortLink = $this->selfLink . '&rows=' .$this->rows.'&begin='.$this->begin;
$sortLink .= ($this->sortdir == 'ASC') ? '&sortdir=DESC' : '&sortdir=ASC';
$sortLink .= '&sortby='.$column->name;
echo '<td id="headerCell"
class = "'.$this->columContent[$index]['class'].'"
width = "'.$this->columContent[$index]['width'].'"
height = "'.$this->columContent[$index]['height'].'"
colspan = "'.$this->columContent[$index]['colspan'].'"
align = "'.$this->columContent[$index]['align'].'"
valign = "'.$this->columContent[$index]['valign'].'" nowrap>';
echo '[url='. $sortLink . ']'.$column->title .'[/url]';
if($this->sortby == $column->name)
echo '[img]'.$this->imgFilePath . $this->sortimg .'[/img]';
echo '</td>';
}
if (strlen($this->editLink) > 0)
echo "<td></td>";
if (strlen($this->deleteLink) > 0)
echo "<td></td>";
echo "</tr>";
$index++;
}
function printContent($query)
{
$count = 0;
while($row = mysql_fetch_array($query))
{
# changes the row color with css style
$style = ($count % 2 == 0) ? "contentRow1" : "contentRow2";
echo '<tr id="'. $style .'" >';
foreach ($this->columns as $key => $column)
{
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # PRINT THE COLUMN DATA # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo '<td id="contentCell">';
echo htmlspecialchars($row[$column->name]);
echo '</td>';
}
# gets the key and its value for this row
$key = $this->urlKeyName;
$keyVal = $row[$this->tableKeyName];
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # PRINT THE EDIT AND DELETE BUTTONS DATA # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # PRINT THE EDIT BUTTON # # # # # #
if (strlen($this->editLink) > 0){
$eLink = $this->editLink . "?" . $this->urlKeyName . "=" . $row[$this->tableKeyName] . $this->urlVars;
echo '<td width="2%" alt="edit" title="edit">';
echo '<a';
echo ' href='.$eLink.'"';
if (strlen($this->editTarget) > 0){
echo ' target="'.$this->editTarget.'"';
}
echo '>';
echo '[img]'.$this->imgFilePath .$this->edit_img . '[/img]';
echo "</a>";
echo "</td>";
}
# # # # # # PRINT THE DELETE BUTTON # # # # # #
if (strlen($this->deleteLink) > 0){
$dLink = $this->deleteLink . '?' . $this->urlKeyName . '=' . $row[$this->tableKeyName] . $this->urlVars;
echo '<td width="2%" alt="delete" title="delete">';
echo '<a href='.$dLink.'>';
echo '[img]'.$this->imgFilePath.$this->delete_img.'[/img]';
echo '</a>';
echo '</td>';
}
echo '</tr>';
$count++;
}
echo '<table>';
}
/**
* @access private
* @return string print the empty message
*/
function printEmptyMsg() {
echo '<table id="contentTable" "'.$this->formatString.'">';
echo '<tr id="contentRow1"><td></td></tr>';
echo '<tr id="contentRow1">';
echo '<td id="emptyMsg">"'.$this->emptyMsg. '"</td>';
echo '</tr>';
echo '<tr id="contentRow1"><td></td></tr>';
echo '</table>';
}
}
class grid {
var $name;
function __construct ($name, $title) {
$this->name = $name;
$this->title = $title;
}
}
?>
e la richiamo cosi :
Codice PHP:
require "../php_sort_table.php";
$yourHost = "localhost";
$yourDB = "guru";
$yourUser = "root";
$yourPass = "maurizio";
$yourTable = "tblusers";
$dbConnString = $yourHost . "," . $yourDB . "," . $yourUser . "," . $yourPass;
$sortable = new phpSortTable($dbConnString, $yourTable);
# $col = new grid($name,$title,$formatFunction,$link,$img,$appendDataToLink);
$col_0 = new grid("UserId", "ID");
$col_1 = new grid("Name", "Name");
$col_2 = new grid("Email", "Email");
$col_3 = new grid("DOB", "DOB");
$col_4 = new grid("ru_fp", "ru_fp");
$sortable->columns = array(0=>$col_0, 1=>$col_1, 2=>$col_2, 3=>$col_3, 4=>$col_4, );
$sortable->setTableFormat ("2", "2", "0" ,"100%"); // cellpadding, cellspacing, border
$sortable->editLink = "example_01.php";
$sortable->deleteLink = "example_01.php";
$sortable->addLink = "addlink.php";
$sortable->addText = "add a new entry";
$sortable->urlKeyName = "UserId";
$sortable->tableKeyName = "UserId";
$sortable->columHeader[0]['width'] = "100";
$sortable->columHeader[0]['title'] = "prova";
$sortable->columHeader[1]['width'] = "100";
$sortable->columHeader[1]['title'] = "xxxxxxxxxx";
$sortable->editTarget = "_blank";
#define the deafult row number to be displayed
$sortable->defaultRowsNum = "10";
#define the path for the css file
$sortable->cssFilePath = "../php_sort_table.css";
#define the path for of the images directory
$sortable->imgFilePath = "../img/";
$sortable->printTable();