?
Path : /home/admin/public_html/old/backoffice/user/ |
Current File : /home/admin/public_html/old/backoffice/user/list_data.php |
<?php session_start(); $root_path="../"; include($root_path."header.php"); $db_tm = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false); $template = new Template($process_tpl_path); foreach(${"_" . $_SERVER["REQUEST_METHOD"]} as $k=>$v) $$k=$v; $sql_01 ="SELECT * FROM $selitem where TB_NAME='$TB' "; $result_01 = $db_tm->sql_query("SET NAMES utf8"); $result_01 = $db_tm->sql_query($sql_01); $rows_01 = $db_tm->sql_fetchrow($result_01); $TBTH = $rows_01[TB_NAME_TH]; $w = $rows_01[W]; $h = $rows_01[H]; $fileto = $rows_01[FILETO]; $path_to = $rows_01[PATH]; $notshow = $rows_01[NOTSHOW]; echo "<script>parent.arr_data.length=0;parent.menubarFrame.location.href='./menu_bar.php?TB=$TB&selitem=$selitem&TBTH=$TBTH';</script>"; $chk_notshow=split(",",$notshow); $sql_error = $db_tm->sql_error($result_01); $debug_text = ''; if ( $sql_error['message'] != '' ){ $debug_text .= '<br /><br />ผิดพลาดที่คำสั่ง SQL : ' . $sql_error['message']; echo $debug_text."<br>"; } //--------------------------------[Order By]--------------------------------------- $result_02 = $db_tm->sql_query("SET NAMES utf8"); $result_02 = $db_tm->sql_query($rows_01[SQL]." where 0"); $numfields = $db_tm->sql_numfields($result_02); if(($TB=="order") && ($FI=="" && $AD=="")){$FI=3;$AD="DESC";$FN="`order`.date_shop";} if ((!$FI && !$AD) || ($FI=='' && $AD=='')){ $FI=0; $FN=$db_tm->sql_fieldname($offset=0,$result_02); $AD='ASC'; } $field_date=array(); $b=0; //check fields date for($i=0; $i<$numfields;$i++){ $fieldsname =$db_tm->sql_fieldname($offset=$i,$result_02); if($db_tm->sql_fieldtype($offset=$i,$result_02)=="date"){ $field_date[$b]=$i; $b++; } if($notshow==""){ $chk_field="yes_show"; }else{ $chk_field="no_show"; for ($r=0;$r<sizeof($chk_notshow);$r++){ if ($chk_notshow[$r]==$i){ $chk_field='no_show'; $r=sizeof($chk_notshow); }else{ $chk_field='yes_show'; } } } if ($chk_field=='yes_show'){ if ($FI==$i){ if ($AD=='ASC'){ $img='<IMG SRC="'.$images_path.'/asc_order.png" WIDTH="7" HEIGHT="7" BORDER="0" ALT="">'; $title="Ascending";} if ($AD=='DESC'){ $img='<IMG SRC="'.$images_path.'/desc_order.png" WIDTH="7" HEIGHT="7" BORDER="0" ALT="">'; $title="Descending";} $FN=$fieldsname; } else{ $img=""; } $template->assign_block_vars('fieldnamerow', array( "FIELDNAME"=>$fieldsname, "OBJ"=>"Javascript:OrdByCol('$i','$AD','$page');", "IMG"=>$img, "IMG_PATH"=>$images_path, "TITLE"=>$title )); }//if chk_field } //--------------------------------[Order By]--------------------------------------- //------------------------------------------------------------[ Search ]---------------------------------------------------------------- //echo "[",$search,"] [",$method,"] [",$item_field1,"] [",$item_data1,"]<br>"; //echo "[",$condition,"] [",$method2,"] [",$item_field2,"] [",$item_data2,"]<br>"; if($search!=""){ if($method=="LIKE"){ if($item_field1=="START_DATE" || $item_field1=="EXP_DATE"){ $sel_text=" WHERE DATE_FORMAT(".$item_field1.",'%Y%m%d%H%i%s') ".$method." '%".$item_data1."%' "; }else{ $sel_text=" WHERE ".$item_field1." ".$method." '%".$item_data1."%' "; } }else{ if($item_field1=="START_DATE" || $item_field1=="EXP_DATE"){ $sel_text=" WHERE DATE_FORMAT(".$item_field1.",'%Y%m%d%H%i%s') ".$method." '".$item_data1."' "; }else{ $sel_text=" WHERE ".$item_field1." ".$method." '".$item_data1."' "; } } if($condition!=""){ $sel_text.=" ".$condition." "; if($method2=="LIKE"){ if($item_field2=="START_DATE" || $item_field2=="EXP_DATE"){ $sel_text.=" WHERE DATE_FORMAT(".$item_field2.",'%Y%m%d%H%i%s') ".$method2." '%".$item_data2."%' "; }else{ $sel_text.=" ".$item_field2." ".$method2." '%".$item_data2."%' "; } }else{ if($item_field2=="START_DATE" || $item_field2=="EXP_DATE"){ $sel_text.=" DATE_FORMAT(".$item_field2.",'%Y%m%d%H%i%s') ".$method2." '".$item_data2."' "; }else{ $sel_text.=" ".$item_field2." ".$method2." '".$item_data2."' "; } } } //condition } //------------------------------------------------------------[ Search ]---------------------------------------------------------------- if($TB=="users" && $search==""){ $sel_text.=" where users.USER_ID<>1 "; }else{ $sel_text.=" and users.USER_ID<>1 "; } $sql = $rows_01[SQL]; if($rows_01[GROUP_BY]!=""){$sel_text.=" ".$rows_01[GROUP_BY]." ";} //$sql .= $sel_text." order by `$TB`.$FN $AD"; $sql .= $sel_text." order by $FN $AD"; //echo $sql,"<br>"; list($usec,$sec)=explode(' ',microtime()); $time_before=((float)$usec+(float)$sec); $result_chk = $db_tm->sql_query("SET NAMES utf8"); $result_chk = $db_tm->sql_query($sql); list($usec,$sec)=explode(' ',microtime()); $time_after=((float)$usec+(float)$sec); $show_time="<span style=\"padding-left:5px;\">Time : ".sprintf("%.3f",$time_after-$time_before)." Sec.</span>"; $numrows_chk = $db_tm->sql_numrows($result); if($search!=""){ $data_search="document.location.href='list_data.php?FI=$FI&AD=$AD&selitem=$selitem&TB=$TB&TBTH=$NAME_TITLE&page='+this.value+'&search=search&method=$method&item_field1=$item_field1&item_data1=$item_data1&condition=$condition&method2=$method2&item_field2=$item_field2&item_data2=$item_data2';"; }else{ $data_search="document.location.href='list_data.php?FI=$FI&AD=$AD&selitem=$selitem&TB=$TB&TBTH=$NAME_TITLE&page='+this.value+' ';"; } $design_page = $db_tm->sql_num_pages($page,$list_page,$numrows_chk,$search,$data_search); $show_page = $design_page["show_page"]; $sql .= $design_page["sql_limit"]; //echo $sql; $result = $db_tm->sql_query("SET NAMES utf8"); $result = $db_tm->sql_query($sql); $rows = $db_tm->sql_fetchrow($result); $numrows = $db_tm->sql_numrows($result); $sql_error = $db_tm->sql_error($result); $debug_text = ''; if ( $sql_error['message'] != '' ){ $debug_text .= '<br /><br />ผิดพลาดที่คำสั่ง SQL : ' . $sql_error['message']."<br>".$sql; echo $debug_text."<br>"; } $color1="#DBEAF5"; $color2="#FFFFFF"; $class_rows=$color2; $color_over="#00CCFF"; $b=0; //check fields date if($TB=="order" || $TB=="products" || $TB=="category"){$winpop="open_lookup";}else{$winpop="open_pop";} if($numrows!=0){ for($i=0;$i<$numrows;$i++){ $class_rows=($class_rows==$color2)? $color1:$color2; $data.="<TR style=\"cursor:pointer\" bgcolor=\"$class_rows\" onmouseout=\"bgcout(this,'$class_rows')\" onmouseover=\"bgcover(this,'$color_over')\" OnClick=\"bgc(this,'$class_rows')\">"; if($numrows==1){ $data.="<TD class=\"noborder\" align=\"center\"><INPUT TYPE=\"checkbox\" NAME=\"chkboxid\" OnClick=\"select_item(document.getElementById('item".$i."').value,this);\"></TD>"; }else{ $data.="<TD class=\"noborder\" align=\"center\"><INPUT TYPE=\"checkbox\" NAME=\"chkboxid\" OnClick=\"select_item(document.getElementById('item".$i."').value,this);\"></TD>"; } $list=$i+1; $data.="<TD class=\"noborder\" align=\"\" style=\"padding-left:5px;padding-right:5px\">".$list."</TD>"; for($n=0;$n<$numfields;$n++){ if($n==0){$all_rows.=$rows[$n]."`";} if($notshow==""){ $chk_field="yes_show"; }else{ $chk_field="no_show"; for ($r=0;$r<sizeof($chk_notshow);$r++){ if ($chk_notshow[$r]==$n){ $chk_field='no_show'; $r=sizeof($chk_notshow); }else{ $chk_field='yes_show'; } } } if ($chk_field=='yes_show'){ if(md5($field_date[$b])==md5($n)){ $b++; //check fields date if($numrows==1){ $data.="<TD class=\"noborder\" align=\"left\" noWrap style=\"padding-left:5px;padding-right:5px;\"><A title=\"Edit\" OnClick=\"".$winpop."('".$w."','".$h."','".$path_to."/".$fileto."?flag=edit&index_data='+document.getElementById('item".$i."')+'&TB=".$TB."&TBTH=".$TBTH."&selitem=".$selitem."');\">".convert_date($rows[$n])." </A></TD>"; }else{ $data.="<TD class=\"noborder\" align=\"left\" noWrap style=\"padding-left:5px;padding-right:5px;\"><A title=\"Edit\" OnClick=\"".$winpop."('".$w."','".$h."','".$path_to."/".$fileto."?flag=edit&index_data='+document.getElementById('item".$i."').value+'&TB=".$TB."&TBTH=".$TBTH."&selitem=".$selitem."');\">".convert_date($rows[$n])."</A></TD>"; } }else{//ตรวจสอบ fields วันที่ if($numrows==1){ $data.="<TD class=\"noborder\" align=\"left\" noWrap style=\"padding-left:5px;padding-right:5px;\"><A title=\"Edit\" OnClick=\"".$winpop."('".$w."','".$h."','".$path_to."/".$fileto."?flag=edit&index_data='+document.getElementById('item".$i."').value+'&TB=".$TB."&TBTH=".$TBTH."&selitem=".$selitem."');\">".html_entity_decode(del_tag($rows[$n]))."</A></TD>"; }else{ $data.="<TD class=\"noborder\" align=\"left\" noWrap style=\"padding-left:5px;padding-right:5px;\"><A title=\"Edit\" OnClick=\"".$winpop."('".$w."','".$h."','".$path_to."/".$fileto."?flag=edit&index_data='+document.getElementById('item".$i."').value+'&TB=".$TB."&TBTH=".$TBTH."&selitem=".$selitem."');\">".html_entity_decode(del_tag($rows[$n]))."</A></TD>"; } }//ตรวจสอบ fields วันที่ }//chk_fields }//for $numfields $data.="<TD><INPUT TYPE=\"hidden\" id=\"item".$i."\" NAME=\"item".$i."\" value=\"$all_rows\"></TD>"; echo "<script>parent.arr_selall[$i]='$all_rows';</script>"; $all_rows=""; $data.="</TR>"; $b=0; //check fields date $rows = $db_tm->sql_fetchrow($result); }//for $numrows }else{ echo "<BR><BR><CENTER><FONT COLOR=#FF0000>No Data</FONT></CENTER>"; $data.="<TR>"; for($n=0;$n<sizeof($chk_notshow);$n++){$data.="<TD class=\"noborder\"> </TD>"; } $data.="</TR>"; } $template->set_filenames(array('body' =>'list_data.tpl')); $template->assign_vars(array( "CUR_HOST_BACKEND"=>$cur_host_backend, "STYLE"=>STYLE, "IMAGES_PATH"=>$images_path, "SHOW_PAGE"=>$show_page, "SHOW_TIME"=>$show_time, "DATA"=>$data, "NAME_TITLE"=>$TBTH, "TB"=>$TB, "selitem"=>$selitem, "NUMROWS"=>$numrows, "TOTAL"=>number_format($numrows_chk), "SEARCH"=>$search, "METHOD"=>$method, "ITEM_FIELD1"=>$item_field1, "ITEM_DATA1"=>$item_data1, "CONDITION"=>$condition, "METHOD2"=>$method2, "ITEM_FIELD2"=>$item_field2, "ITEM_DATA2"=>$item_data2, )); $template->pparse('body'); ?>