2
// +------------------------------------------------------------------------+
4
// +------------------------------------------------------------------------+
5
// | Copyright (c) 2000-2003 Fr�d�ric HENNINOT |
6
// | Email fhenninot@freesurf.fr |
7
// | Licence This code is released under GPL |
8
// +------------------------------------------------------------------------+
11
* PHP4 Grid Presentation Data with more feature.
12
* @package SQLiteManager
13
* @author Fr�d�ric HENNINOT <fhenninot@freesurf.fr>
14
* @version $Id: SQLiteToGrid.class.php,v 1.41 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.41 $
44
* SQL expression extract : between 'SELECT' and 'FROM'
57
var $queryOrderDefault;
60
* Nombre d'enregistrement
68
* SQL expression sort var
76
* SQL Init Sort column
83
* Number of record per page
91
* Veritable requ�te execut�e
106
* Identification table, to view many table in one page
114
* boolean array for Enable/Disable sort column
122
* Column title style.
123
* true : button for sort column
124
* false : hyperlink for sort column
129
var $buttonStyle=true;
132
* Add var to hyperlink.
135
* index.php?action=module&module=user
152
* tableau des styles 'CSS'.
153
* if empty, automatic value for TD, TABLE and BUTTON
161
* Alignement of the column result, without title
169
* Formatage d'affichage de la colonne. Le resultat des autres colonne peuvent �tre utilis� dans une m�me colonne mais sur la m�me ligne
170
* a l'aide du masque #%num_colonne%#
177
* List the column to be hide
185
* List of the calculated column
193
* Number of column in the result table and Title table
201
* table result width. also in px or %
209
* view the navigation bar.
218
* theorical number of page
226
* Current page to view
234
* Information on navigate page
240
* older column to sort.
249
* Determine the sort order
258
* Buffer to send to the brother
269
* @var array $tabCaption array("align"=>, "content"=>)
274
* Disable 'OnClick' javascript function on table
276
* @var boolean $onClick
284
* @param resource $connId resource SQLite Connection
285
* @param string $query SQL query to display
286
* @param string $tabId table name for display many table with independante navigate
287
* @param bool $autoTitle if true the class determineless the column title
288
* @param int $nbRecord nb line view per page
289
* @param string $width width of the end table (px or %)
291
function SQLiteToGrid(&$connId, $query, $tabId='', $autoTitle=true, $nbRecord=10, $width=500){
292
if(is_resource($connId) || is_object($connId)) $this->SQLiteConnId = $connId;
293
if($tabId) $this->tabId = $tabId;
294
else $this->setTabId();
295
$this->_fromSession();
296
$posEnd = strrpos(trim($query), ';');
297
if($posEnd) $query = substr(trim($query), 0, $posEnd);
298
$this->query = $query;
299
$this->onClick = true;
300
$this->recordPerPage = $nbRecord;
301
$this->navigate = true;
302
$this->_parseQuery($autoTitle);
303
$this->_definePage();
304
if($width) $this->width = $width;
305
if(empty($this->tabId)) $this->setTabId();
306
$data = $this->_getRecord();
308
foreach($data as $ligne){
309
if(empty($this->nbColonne)) {
310
$this->nbColonne = count($ligne);
311
} elseif(count($ligne)!=$this->nbColonne) {
312
$this->_sendError($GLOBALS['traduct']->get(105));
318
$this->_sendError($GLOBALS['traduct']->get(106));
325
* Affectation of an identification table
328
* @param string $ident identification string
330
function setTabId($ident=''){
332
$this->tabId = $GLOBALS['GridTabId'][] = $ident;
334
// Recherche du plus grand indice
335
$tabIndex = $GLOBALS['GridTabId'];
336
if(!is_array($tabIndex)) {
337
$this->tabId = $GLOBALS['GridTabId'][]='tab1';
340
foreach($tabIndex as $value){
341
if((substr($value, 0, 3) == 'tab') && (($num = substr($value, 3, strlen($value)-3))>$max)) $max = $num;
343
$this->tabId = $GLOBALS['GridTabId'][] = 'tab'.($max+1);
353
* @param array $title tableau des titres du tableau
355
function setTitle($title){
356
if(is_array($title)) $this->title = $title;
357
if(empty($this->nbColonne)) $this->nbColonne = count($title);
361
* Set Alignement for the data table. no the title
364
* @param array $tabAlign String table to set teh column alignement
366
function setAlign($tabAlign){
367
if(is_array($tabAlign)){
368
if(count($tabAlign)!=$this->nbColonne) {
369
$this->_sendError($GLOBALS['traduct']->get(107));
371
foreach($tabAlign as $align) {
372
if( ($align != 'left') && ($align != 'center') && ($align != 'right') ) {
373
$this->_sendError($GLOBALS['traduct']->get(108));
377
$this->align = $tabAlign;
380
$this->_sendError($GLOBALS['traduct']->get(109));
385
* Affecte un format d'affichage pour chaque colonne
388
* @param array $tabFormat tableau de chaine par colonne
390
function setFormat($tabFormat){
391
if(is_array($tabFormat)){
392
$this->format = $tabFormat;
394
$this->_sendError($GLOBALS['traduct']->get(110));
398
* Set the GET var to add into the links
401
* @param string $string example : "?action=module&module=user"
403
function setGetVars($string){
404
$this->getVar = $string;
409
* Allow sortable column. default all column are sortable
412
* @param array $tabSort : bool array true->column sortable ; false->column not sortable
414
function setSort($tabSort){
415
if(is_array($tabSort)){
416
if(count($tabSort)!=$this->nbColonne) {
417
$this->_sendError($GLOBALS['traduct']->get(111));
419
foreach($tabSort as $sort) {
420
if( ($sort != 0) && ($sort != 1) ) {
421
$this->_sendError($GLOBALS['traduct']->get(112));
425
$this->sort = $tabSort;
428
$this->_sendError($GLOBALS['traduct']->get(113));
433
* Default sort action is with button style. If false -> sort action is hyperlinks
436
* @param bool $button
438
function enableSortStyle($button = true){
439
if($button) $this->buttonStyle = true;
440
else $this->buttonStyle = false;
445
* Disable Navigation Barre when is automatically set
449
function disableNavBarre(){
450
$this->navigate = false;
454
* Allow result column to be hide
457
* @param int $num column number. can it a bool array with true->column is hide ; false->column is show
459
function hideColumn($num){
460
if(is_array($num)) $this->hide = $num;
461
else $this->hide[$num] = true;
465
* Same as hideColumn() but to show column
469
* @see hideColumn($num)
471
function showColumn($num){
472
if(is_array($num)) $this->hide = $num;
473
else $this->hide[$num] = false;
477
* This method is to add calculate column. default the position is at end.
478
* The format string, is a template string where you can use all the column result.
481
* @param string $title The column title
482
* @param string $format The string to be parse to set the value. format is #%ColNum%#, replace by the column value
483
* @param string $align Set the data alignement
484
* @param int $pos position de la colonne calcul�e, si 999 alors � la fin par ordre de cr�ation
486
function addCalcColumn($title, $format, $align, $pos=999){
489
if(!is_array($this->calcColumn)) $numCalc = 0;
490
else $numCalc = count($this->calcColumn-1);
491
$this->calcColumn[$numCalc]['title'] = $title;
492
$this->calcColumn[$numCalc]['format'] = $format;
493
$this->calcColumn[$numCalc]['align'] = $align;
494
$this->calcColumn[$numCalc]['position'] = $pos;
496
$this->_sendError($GLOBALS['traduct']->get(114));
499
$this->_sendError($GLOBALS['traduct']->get(115));
504
* Build the table result and buffer behind show
511
$out .= $this->_showHeader();
512
$out .= $this->_showTable();
513
if($this->navigate) $out .= $this->_showNavigate();
514
$out .= $this->_showFooter();
530
* Send error message to brother
533
* @param string $message Error message
535
function _sendError($message){
536
echo '<table width="300" style="border: 2px solid red;">'."\n";
537
echo '<tr><td align="center"><span style="font-size: 16px; color: red;"></span><b>'.$GLOBALS['traduct']->get(9).'</b></span></td></tr>'."\n";
538
echo '<tr><td align="center"><span style="font-size: 14px, color: blue;"><b>'.$message.'</b></span></td></tr>'."\n";
545
* Build the header, use Table and Thead for the title row
550
function _showHeader(){
551
$out = '<!-- SQLiteToGrid.class.php : _showHeader() -->'."\n";
552
$out .= "<div align=\"".$GLOBALS["QueryResultAlign"]."\">\n<table width=".$this->width." cellspacing=0 cellpadding=0 class=\"".$this->tabId."\">\n";
554
if(isset($this->tabCaption) && !empty($this->tabCaption)) {
555
$out .= "<caption style=\"white-space: nowrap\" align=\"".$this->tabCaption["align"]."\">".$this->tabCaption["content"]."</caption>";
557
$out .= "\t<thead>\n\t\t<tr>\n";
558
if(empty($this->getVar)) $this->getVar = '?';
559
else $this->getVar .= '&';
560
if(!is_array($this->sort)) $sortDefault = true;
561
if (count($this->title))
562
while(list($index, $titleColonne) = each($this->title)) {
563
$linkCond = ((!isset($this->sort[$index]) && $sortDefault) || $this->sort[$index]);
565
if(is_array($this->calcColumn)){
566
foreach($this->calcColumn as $calcCol){
567
if($calcCol['position'] == $index){
568
if($this->buttonStyle) $out .= "\t\t\t<td class=\"".$this->tabId."\"><button class=\"button\" type=\"button\">".$calcCol["title"]."</button></td>\n";
569
else $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\">".$calcCol["title"]."</td>\n";
573
if((isset($_GET["sort".$this->tabId]) && ($_GET["sort".$this->tabId] == $index)) || (isset($this->orderInit) && ($this->orderInit==$index))){
574
if($this->orderSens == "ASC") $infoSort = ' <img src="'.IMG_ASC.'" border="0">';
575
else $infoSort = ' <img src="'.IMG_DESC.'" border="0">';
579
if(!is_array($this->hide) || (!isset($this->hide[$index]) || !$this->hide[$index])){
580
$align=($infoSort)?'right':'center';
581
if($this->buttonStyle){
582
if($linkCond) $sort = " onClick=\"document.location='".$this->getVar."sort".$this->tabId."=".$index."'\"";
583
$out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\"><button class=\"button\" type=\"button\"".$sort." class=\"".$this->tabId."\">".$titleColonne.$infoSort."</button></td>\n";
586
$out .= "\t\t\t".'<td align="'.$align.'" class="'.$this->tabId.'" style="white-space: nowrap"><a href="'.$this->getVar.'sort'.$this->tabId."=".$index.'" class="'.$this->tabId.'" style="border: 0px">'.$titleColonne.$infoSort.'</a></td>'."\n";
588
$out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\" style=\"white-space: nowrap\">".$titleColonne."</td>\n";
593
if(is_array($this->calcColumn)){
594
foreach($this->calcColumn as $calcCol){
595
if( isset($index) && ($calcCol["position"] > $index)){
596
if($this->buttonStyle) $out .= "\t\t\t<td class=\"".$this->tabId."\"><button class=\"button\" type=\"button\">".$calcCol["title"]."</button></td>\n";
597
else $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\">".$calcCol["title"]."</td>\n";
601
$out .= "\t\t</tr>\n";
602
$out .= "\t</thead>\n";
607
* Build the data table result
612
function _showTable(){
613
$out = '<!-- SQLiteToGrid.class.php : _showTable() -->'."\n";
615
if(is_array($this->data))
616
foreach($this->data as $ligne){
617
if($pos % 2) $localBgColor = $GLOBALS['browseColor1'];
618
else $localBgColor = $GLOBALS['browseColor2'];
619
$out .= "\t<tr onMouseOver=\"setRowColor(this, $pos, 'over', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\"
620
onMouseOut=\"setRowColor(this, $pos, 'out', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\"";
621
if($this->onClick) $out .= " onMouseDown=\"setRowColor(this, $pos, 'click', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\"";
623
while(list($index, $value) = each($ligne)){
624
if($GLOBALS["allHTML"]) $value = htmlentities($value, ENT_NOQUOTES, $GLOBALS['charset']);
625
if(!$GLOBALS["allFullText"]){
626
if(strlen($value)>PARTIAL_TEXT_SIZE) $value = substr($value, 0, PARTIAL_TEXT_SIZE).'...';
629
if(isset($this->NullInfo[$this->title[$index]]) && ($this->NullInfo[$this->title[$index]]==0)) $value="<i>NULL</i>";
630
else $value=" ";
632
if(is_array($this->calcColumn)) {
633
foreach($this->calcColumn as $calcCol){
634
if($calcCol['position'] == $index) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.((!empty($calcCol['align']))? 'align="'.$calcCol['align'].'"' : '' ).'style="white-space: nowrap" width="10%" class="'.$this->tabId.'">'.$this->_formatCalc($ligne, $calcCol['format'], $pos ).'</td>'."\n";
637
if(!is_array($this->hide) || !isset($this->hide[$index]) || !$this->hide[$index]) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.(($this->align[$index])? 'align="'.$this->align[$index].'"' : '' ).'style="white-space: nowrap" class="'.$this->tabId.'">'.((!empty($this->format[$index]))? $this->_formatCalc($ligne, $this->format[$index]) : $value ).'</td>'."\n";
639
if(is_array($this->calcColumn)) {
640
foreach($this->calcColumn as $calcCol){
641
if($calcCol["position"] > $this->nbColonne) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.((!empty($calcCol['align']))? 'align="'.$calcCol['align'].'"' : '' ).'style="white-space: nowrap" width="10%" class="'.$this->tabId.'">'.$this->_formatCalc($ligne, $calcCol['format'], $pos ).'</td>'."\n";
651
* Build the table footer
656
function _showFooter(){
657
return "</table>\n</div>\n";
661
* Build the navigation bar, it use the Tfoot
666
function _showNavigate(){
667
$out = '<!-- SQLiteToGrid.class.php : _showNavigate() -->'."\n";
668
$out .= "\t<tr class=\"navbarre\"><td colspan=\"".$this->_countVisibleColumn()."\" align=\"center\" class=\"".$this->tabId."\" style=\"white-space: nowrap\">\n";
669
if(NAV_TOP) $top = '<img src="'.NAV_TOP.'" border=0>';
671
if(NAV_PREC) $prec = '<img src="'.NAV_PREC.'" border=0>';
673
if(NAV_SUIV) $suiv = '<img src="'.NAV_SUIV.'" border=0>';
675
if(NAV_END) $end = '<img src="'.NAV_END.'" border=0>';
677
if(isset($_GET['sort'.$this->tabId])) $linkSort = 'sort'.$this->tabId.'='.$_GET['sort'.$this->tabId].'&';
679
if($this->pageStart>1) {
680
$top = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=1\">".$top."</a>";
681
$prec = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->pageStart - 1)."\">".$prec."</a>";
683
if($this->pageStart<$this->nbPage){
684
$suiv = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->pageStart + 1)."\">".$suiv."</a>";
685
$end = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->nbPage)."\">".$end."</a>";
687
if($this->nbPage<NAV_NBLINK){
689
$endLink = $this->nbPage;
691
if(($this->pageStart<($this->nbPage - (int)(NAV_NBLINK/2))) && ($this->pageStart>(int)(NAV_NBLINK/2))) $startLink = $this->pageStart - ((int)(NAV_NBLINK/2));
692
elseif($this->pageStart>=($this->nbPage - (int)(NAV_NBLINK/2))) $startLink = $this->nbPage - (NAV_NBLINK-1);
694
if( ($startLink+NAV_NBLINK-1) > $this->nbPage) {
695
$startLink = $this->nbPage - NAV_NBLINK + 1;
696
$endLink = $this->nbPage;
698
$endLink = $startLink + (NAV_NBLINK-1);
702
for($i=$startLink ; $i<=$endLink ; $i++){
703
if($i == $this->pageStart) $link .= '<span style="font-size: 12px;">'.$i.'</span>';
704
else $link .= "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".$i."\"><span style='font-size: 12px'>".$i."</span></a>";
705
if($i < $endLink) $link .= NAV_SEP;
707
$infoNav = " ".$GLOBALS["traduct"]->get(136)." ".$this->infoNav["start"]."-".$this->infoNav["end"]."/".$this->infoNav["all"];
708
$out .= "<div><div style=\"float: left\">".$infoNav."</div>";
709
$out .= "<div style=\"float: center\">".$top.NAV_SEP.$prec.NAV_SEP.$link.NAV_SEP.$suiv.NAV_SEP.$end."</div></div>";
710
$out .= "\t</td></tr>\n";
715
* Simple template methode to replace var value in the string format for the calc Column
718
* @param array &$ligne reference on the ligne result table
719
* @param string $format template to work with
722
function _formatCalc(&$ligne, $format, $pos=""){
723
preg_match('/#%(.*)%#/', $format, $var);
724
while(isset($var[1])){
725
if((substr($var[1],0,3)!='POS') && (substr($var[1],0,5)!='QUERY')){
726
$format = str_replace('#%'.$var[1].'%#', $ligne[$var[1]], $format);
727
} elseif(substr($var[1],0,3)=='POS'){
728
$format = str_replace('#%POS%#', $pos, $format);
729
} elseif(substr($var[1],0,5)=='QUERY'){
730
$format = str_replace('#%QUERY%#', urlencode($this->getRealQuery()), $format);
732
preg_match('/#%(.*)%#/', $format, $var);
738
* Method for calc paginate
742
function _definePage(){
743
$nbRecord = $this->_countRecord();
744
$this->nbPage = ceil($nbRecord / $this->recordPerPage);
745
if(!isset($_GET['page'.$this->tabId])) $this->pageStart = 1;
746
else $this->pageStart = $_GET['page'.$this->tabId];
747
$this->indexStart = (($this->pageStart - 1) * $this->recordPerPage);
748
$this->infoNav['start'] = $this->indexStart;
749
$this->infoNav['end'] = $this->indexStart + $this->recordPerPage;
750
$this->infoNav['all'] = $nbRecord;
751
if($this->infoNav['end']>$nbRecord) $this->infoNav['end']=$nbRecord;
755
* Methode to set the order sens
759
function _checkOrder(){
760
if(isset($_GET['sort'.$this->tabId]) && ($_GET['sort'.$this->tabId]==$this->oldOrder) && (!isset($_GET['page'.$this->tabId]))){
761
if($this->orderSens == 'ASC') $this->orderSens = 'DESC';
762
else $this->orderSens = 'ASC';
763
} elseif(!isset($_GET['page'.$this->tabId])){
764
$this->orderSens = 'ASC';
769
* retreive session data
773
function _fromSession(){
774
if(session_is_registered('old_order'.$this->tabId) || !empty($_SESSION['old_order'.$this->tabId])){
775
$this->oldOrder = $_SESSION['old_order'.$this->tabId];
777
if(session_is_registered('order_sens'.$this->tabId) || !empty($_SESSION['order_sens'.$this->tabId])){
778
$this->orderSens = $_SESSION['order_sens'.$this->tabId];
789
function _toSession(){
790
if(!session_is_registered('old_order'.$this->tabId)){
791
session_register('old_order'.$this->tabId);
793
if(!isset($oldOrder)) $oldOrder = '';
794
if(isset($_GET['sort'.$this->tabId])) $oldOrder = $_GET['sort'.$this->tabId];
795
elseif(isset($this->orderInit)) $oldOrder = $this->orderInit;
796
$_SESSION['old_order'.$this->tabId] = $oldOrder;
797
if(!session_is_registered('order_sens'.$this->tabId)){
798
session_register('order_sens'.$this->tabId);
800
$_SESSION['order_sens'.$this->tabId] = $this->orderSens;
805
* Return the visible column number
810
function _countVisibleColumn(){
811
if(is_array($this->hide)) $nbHide = array_sum($this->hide); else $nbHide = 0;
812
if(is_array($this->calcColumn)) $nbCalc = count($this->calcColumn); else $nbCalc = 0;
813
return ($this->nbColonne - $nbHide + $nbCalc);
817
* Parsing Original Query for extract information
820
* @param boolean $autoTitle false: extract title from query, true: extract with sql command
822
function _parseQuery($autoTitle){
823
$this->query = ereg_replace('^select[[:space:]]', 'SELECT ', $this->query);
824
$this->query = ereg_replace('[[:space:]]distinct[[:space:]]', ' DISTINCT ', $this->query);
825
$this->query = ereg_replace('[[:space:]]as[[:space:]]', ' AS ', $this->query);
826
$this->query = ereg_replace('[[:space:]]from[[:space:]]', ' FROM ', $this->query);
827
$this->query = ereg_replace('[[:space:]]where[[:space:]]', ' WHERE ', $this->query);
828
$this->query = ereg_replace('[[:space:]]group[[:space:]]+by[[:space:]]', ' GROUP BY ', $this->query);
829
$this->query = ereg_replace('[[:space:]]having[[:space:]]', ' HAVING ', $this->query);
830
$this->query = ereg_replace('[[:space:]]order[[:space:]]+by[[:space:]]', ' ORDER BY ', $this->query);
831
$this->query = ereg_replace('[[:space:]]limit[[:space:]]', ' LIMIT ', $this->query);
833
$queryCalc = $this->query;
834
$queryCalc = str_replace('[[:space:]]DISTINCT[[:space:]]', ' ', $queryCalc);
835
$queryCalc = eregi_replace("\t|\n", ' ', $queryCalc);
836
preg_match('/SELECT[[:space:]](.*)[[:space:]]FROM/', $queryCalc, $listChamp);
837
if(isset($listChamp[1])) $this->listChamp = $listChamp[1];
838
else $this->listChamp = '';
839
preg_match('/ORDER[[:space:]]+BY[[:space:]]+(.*)/', $this->query, $order);
840
if(isset($order[0])) $this->query = str_replace($order[0], '', $this->query);
841
if(isset($order[1]) && (eregi('asc', $order[1]) || eregi('desc', $order[1]))){
842
preg_match('/[[:space:]]+(.*)/', trim($order[1]), $sens);
843
$order[1] = trim(str_replace($sens, '', $order[1]));
844
$this->queryOrderSensDefault = trim($sens[1]);
846
if(isset($order[1])) $this->queryOrderDefault = str_replace('"', '', $order[1]);
848
if((!eregi("\*", $this->listChamp)) && !eregi("PRAGMA|EXPLAIN", $this->query)){
849
$stringChamp = $this->listChamp;
850
while($startPar = strpos($stringChamp, "(")){
851
$endPar = strpos($stringChamp, ")");
852
$chainePar = substr($stringChamp, $startPar, ($endPar-$startPar)+1);
853
$stringChamp = str_replace($chainePar, "", $stringChamp);
855
$this->listChamp = $stringChamp;
856
$listChamp = explode(",", $this->listChamp);
857
foreach($listChamp as $champ){
858
preg_match("/[[:space:]]AS[[:space:]](.*)/i", $champ, $surname);
859
if(isset($surname[1]) && !empty($surname[1])) {
860
$surname[1] = ereg_replace("\"|'", "", $surname[1]);
861
$tabTitle[] = trim($surname[1]);
863
preg_match("/\.(.*)/", $champ, $table);
864
if(isset($table[1]) && !empty($table[1])) $tabTitle[] = $table[1];
865
else $tabTitle[] = trim($champ);
869
$tabTitle = $this->_fetchField();
872
$tabTitle = $this->_fetchField();
874
$this->setTitle($tabTitle);
876
preg_match('/FROM[[:space:]]+(.*)/', $this->query, $from);
877
if(isset($from[1])) $this->queryCount = 'SELECT count(*) FROM '.$from[1];
878
else $this->queryCount = $this->query;
879
if(isset($_GET['sort'.$this->tabId])){
880
while(list($index, $name) = each($tabTitle)){
881
if($index == $_GET['sort'.$this->tabId]) $this->order = $name;
883
} elseif(!empty($this->queryOrderDefault)) {
884
$this->order = $this->queryOrderDefault;
885
$this->orderInit = array_search(trim($this->order), $tabTitle);
887
$this->_checkOrder();
892
* retourne le nombre d'enregistrement
897
function getNbRecord(){
898
return $this->nbRecordQuery;
902
* retourne la requ�te execut�e
907
function getRealQuery(){
908
return $this->realQuery;
912
* Return the column name, when parsing query can't determine it
917
function _fetchField(){
918
if(eregi('^select', $this->query) && !eregi('limit', $this->query)) $queryLoc = $this->query.' LIMIT 0,1';
919
else $queryLoc = $this->query;
920
if($res = $this->SQLiteConnId->query($queryLoc)){
921
for($i=0 ; $i < $this->SQLiteConnId->num_fields() ; $i++){
922
$title[] = $this->SQLiteConnId->field_name(null, $i);
924
if(isset($title)) return $title;
931
* Return the original number of record
936
function _countRecord(){
937
if(!isset($this->nbRecordQuery)){
938
if($this->SQLiteConnId->getVersion()==2) {
939
$qCount = preg_match('/^\s*(UPDATE|DELETE|INSERT|ALTER|JOIN|GROUP|LIMIT|PRAGMA)\s/i', $this->query);
944
if($this->SQLiteConnId->query($this->queryCount)){
945
$this->nbRecordQuery = $this->SQLiteConnId->fetch_single();
946
} else $this->_sendError($GLOBALS['traduct']->get(117));
948
$tabResult = $this->SQLiteConnId->array_query($this->query);
949
$this->nbRecordQuery = count($tabResult);
952
return $this->nbRecordQuery;
956
* Return an array with the data to send
961
function _getRecord(){
962
if(isset($GLOBALS['TableListImpact'])){
963
$tableList = explode(',', $GLOBALS['TableListImpact']);
964
if(count($tableList)>1) $withTableName = true;
965
else $withTableName = false;
966
foreach($tableList as $tableImpact){
967
if(!empty($tableImpact) && !eregi('\.', $tableImpact)){
968
$tempInfoTable = $this->SQLiteConnId->array_query('PRAGMA table_info('.brackets(trim($tableImpact)).');');
969
if(is_array($tempInfoTable)){
970
foreach($tempInfoTable as $infoTable) {
971
if($withTableName) $this->NullInfo[trim($tableImpact).'.'.$infoTable['name']] = $infoTable['notnull'];
972
else $this->NullInfo[$infoTable['name']] = $infoTable['notnull'];
978
if(strpos(trim($this->order), ' ')) $order = '"'.$this->order.'"';
979
else $order = $this->order;
981
$query = $this->query.(($this->order)? ' ORDER BY '.$order.' '.$this->orderSens : '' );
982
if(!eregi('pragma', $this->query) && !eregi('limit', $this->query)) $query .= ' LIMIT '.$this->indexStart.', '.$this->recordPerPage;
984
if($this->SQLiteConnId->query($query)){
986
$tabRecord = array();
987
while($ligne = $this->SQLiteConnId->fetch_array(null, SQLITE_NUM)){
988
$tabRecord[] = $ligne;
991
$this->realQuery = $query;
996
* Add caption to table
999
* @param string $alignement
1000
* @param string $content
1002
function addCaption($align, $content){
1003
$this->tabCaption['align'] = $align;
1004
$this->tabCaption['content'] = $content;
1008
* Disable 'onclick' javascript function on table
1012
function disableOnClick(){
1013
$this->onClick = false;