Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('install_lang_japanese.php');
- include_once('functions.php');
- include("mysql2json.class.php");
- if (phpversion() >= '4.1.0') {
- include_once('vars4.1.0.php');
- } else {
- include_once('vars4.0.6.php');
- }
- $jsonhead=getVar('jhead');//'results' results
- $sqlwhere=getVar('q');
- switch($jsonhead) {
- case 'aaData' :
- $needfieldname=false;
- $sql="SELECT SQL_CALC_FOUND_ROWS ID as id, name, CASE nowuse WHEN 1 THEN 'yes' ELSE 'no' END AS nowuse , uPrice as 'Unit_price',
- remark, CASE useQAstock WHEN 1 THEN 'yes' ELSE 'no' END AS useQAstock , avrusepmonth as 'Avg_use_a_month',
- moq as MOQ, leadtime as 'Lead_Time'
- FROM test_media ";
- break;
- case 'results' :
- $needfieldname=true;
- $sql="SELECT ID as id, name FROM test_media WHERE nowuse=1 ";
- if ($sqlwhere != "") {
- $sql.= "AND name like '%".$sqlwhere."%'";
- }
- break;
- case 'average' :
- $needfieldname=false;
- $month=getVar('calcmonth');
- $sql="SELECT SQL_CALC_FOUND_ROWS ID,name,remark,avrusepmonth
- , CONCAT('<input type=''checkbox''id=''cb' , ID ,''' name=''check[]'' value=''',ID,''' >'
- ,'<label class=''lbcb'' for=''cb', ID,'''><=update=</label>') as checkb
- , moq, leadtime
- FROM test_media ";
- break;
- }
- switch($jsonhead) {
- case 'aaData' :
- /* Paging */
- $sLimit = "";
- if ( isset( $_GET['iDisplayStart'] ) )
- {
- $sLimit = " LIMIT ".mysql_real_escape_string( getVar('iDisplayStart') ).", ".
- mysql_real_escape_string( getVar('iDisplayLength') );
- }
- /* Ordering */
- if ( isset( $_GET['iSortCol_0'] ) )
- {
- $sOrder = " ORDER BY ";
- for ( $i=0 ; $i<=mysql_real_escape_string( getVar('iSortingCols') ) ; $i++ )
- {
- $sOrder .= fnColumnToField4medialist(mysql_real_escape_string( getVar('iSortCol_'.$i) ))."
- ".mysql_real_escape_string( getVar('sSortDir_'.$i) ) .", ";
- }
- $sOrder = substr_replace( $sOrder, "", -2 );
- }
- /* Filtering - NOTE this does not match the built-in DataTables filtering which does it
- * word by word on any field. It's possible to do here, but concerned about efficiency
- * on very large tables, and MySQL's regex functionality is very limited
- */
- $sWhere = "";
- if ( getVar('sSearch') != "" )
- {
- $sWhere = " WHERE name LIKE '%".mysql_real_escape_string( getVar('sSearch') )."%' OR ".
- "remark LIKE '%".mysql_real_escape_string( getVar('sSearch') )."%' ";
- }
- $num=0;
- $sql.= $sWhere.$sOrder.$sLimit;
- $dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
- mysql_select_db("TestMediaControl") or die(_ERROR17.": ".mysql_error());
- $res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $num=mysql_affected_rows();
- // -------------added from data tables sample
- $sql = "SELECT FOUND_ROWS()";
- $rResultFilterTotal = mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
- $iFilteredTotal = $aResultFilterTotal[0];
- $sql = "SELECT COUNT(id) FROM `test_media` ";
- $rResultTotal = mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $aResultTotal = mysql_fetch_array($rResultTotal);
- $iTotal = $aResultTotal[0];
- $data = array(
- "sEcho" => getVar('sEcho'),
- "iTotalRecords" => $iTotal,
- "iTotalDisplayRecords" => $iFilteredTotal // you had two times iTotalDisplayRecords
- );
- $aaData = array();
- while ( $aRow = mysql_fetch_array( $res ) ) {
- $aaData[] = array(
- $aRow['id'],
- $aRow['name'],
- $aRow['nowuse'],
- $aRow['Unit_price'],
- $aRow['remark'],
- $aRow['useQAstock'],
- $aRow['Avg_use_a_month'],
- $aRow['MOQ'],
- $aRow['Lead_Time']
- );
- }
- $data['aaData'] = $aaData;
- echo json_encode($data);
- mysql_free_result($res);
- break;
- case 'average' :
- /* Paging */
- $sLimit = "";
- if ( isset( $_GET['iDisplayStart'] ) )
- {
- $sLimit = " LIMIT ".mysql_real_escape_string( getVar('iDisplayStart') ).", ".
- mysql_real_escape_string( getVar('iDisplayLength') );
- }
- /* Ordering */
- if ( isset( $_GET['iSortCol_0'] ) )
- {
- $sOrder = " ORDER BY ";
- for ( $i=0 ; $i<=mysql_real_escape_string( getVar('iSortingCols') ) ; $i++ )
- {
- $sOrder .= fnColumnToField4medialistaverage(mysql_real_escape_string( getVar('iSortCol_'.$i) ))."
- ".mysql_real_escape_string( getVar('sSortDir_'.$i) ) .", ";
- }
- $sOrder = substr_replace( $sOrder, "", -2 );
- }
- /* Filtering - NOTE this does not match the built-in DataTables filtering which does it
- * word by word on any field. It's possible to do here, but concerned about efficiency
- * on very large tables, and MySQL's regex functionality is very limited
- */
- $sWhere = " WHERE nowuse=1 and monthavrage(ID,".$month.") > 0 ";
- if ( getVar('sSearch') != "" )
- {
- $sWhere = " AND name LIKE '%".mysql_real_escape_string( getVar('sSearch') )."%' OR
- remark LIKE '%".mysql_real_escape_string( getVar('sSearch') )."%' ";
- }
- $num=0;
- $sql.= $sWhere.$sOrder.$sLimit;
- $dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
- mysql_select_db("TestMediaControl") or die(_ERROR17.": ".mysql_error());
- $res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $num=mysql_affected_rows();
- // -------------added from data tables sample
- $sql = "SELECT FOUND_ROWS()";
- $rResultFilterTotal = mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
- $iFilteredTotal = $aResultFilterTotal[0];
- $sql = "SELECT COUNT(id) FROM `test_media` ";
- $rResultTotal = mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $aResultTotal = mysql_fetch_array($rResultTotal);
- $iTotal = $aResultTotal[0];
- $data = array(
- "sEcho" => getVar('sEcho'),
- "iTotalRecords" => $iTotal,
- "iTotalDisplayRecords" => $iFilteredTotal // you had two times iTotalDisplayRecords
- );
- $aaData = array();
- while ( $aRow = mysql_fetch_array( $res ) ) {
- $aaData[] = array(
- $aRow['ID'],
- $aRow['name'],
- $aRow['remark'],
- $aRow['avrusepmonth'],
- $aRow['checkb'],
- // $aRow['latestavr'],
- $aRow['moq'],
- $aRow['leadtime']
- );
- }
- $data['aaData'] = $aaData;
- echo json_encode($data);
- mysql_free_result($res);
- break;
- default:
- $dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
- mysql_select_db("TestMediaControl") or die(_ERROR17.": ".mysql_error());
- $res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() ); // submit SQL to MySQL and error trap.
- $num=mysql_affected_rows();
- $objJSON=new mysql2json();
- print(trim($objJSON->getJSON($res,$num,$jsonhead,$needfieldname)));
- mysql_free_result($res);
- break;
- }
- function fnColumnToField4medialist( $i ) {
- if ( $i == 0 )
- return "id";
- else if ( $i == 1 )
- return "name";
- else if ( $i == 2 )
- return "nowuse";
- else if ( $i == 3 )
- return "Unit_price";
- else if ( $i == 4 )
- return "remark";
- else if ( $i == 5 )
- return "useQAstock";
- else if ( $i == 6 )
- return "Avg_use_a_month";
- else if ( $i == 7 )
- return "MOQ";
- else if ( $i == 8 )
- return "Lead_Time";
- }
- function fnColumnToField4medialistaverage( $i ) {
- if ( $i == 0 )
- return "ID";
- else if ( $i == 1 )
- return "name";
- else if ( $i == 2 )
- return "remark";
- else if ( $i == 3 )
- return "avrusepmonth";
- else if ( $i == 4 )
- return "checkb";
- /* else if ( $i == 5 )
- return "latestavr";
- */ else if ( $i == 5 )
- return "moq";
- else if ( $i == 6 )
- return "leadtime";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement