Guest User

Untitled

a guest
Jun 12th, 2012
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 16.06 KB | None | 0 0
  1. <?php
  2. include('definition.php');
  3. include('functions.php');
  4. if (phpversion() >= '4.1.0') {
  5.     include_once('vars4.1.0.php');
  6. } else {
  7.     include_once('vars4.0.6.php');
  8. }
  9. include_once('functions.php');
  10. include_once('mysql.php');
  11. $dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
  12.  
  13.  
  14.  
  15. if ( isset( $_GET['sEcho'] ) ) {
  16.     /* MySQL connection */
  17.     mysql_select_db("prodschd") or die(_ERROR17.": ".mysql_error());
  18.    
  19.     /* Paging */
  20.     $sLimit = "";
  21.     if ( isset( $_GET['iDisplayStart'] ) )
  22.     {
  23.         $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
  24.             mysql_real_escape_string( $_GET['iDisplayLength'] );
  25.     }
  26.    
  27.     /* Ordering */
  28.     if ( isset( $_GET['iSortCol_0'] ) )
  29.     {
  30.         $sOrder = "ORDER BY  ";
  31.         for ( $i=0 ; $i<mysql_real_escape_string( $_GET['iSortingCols'] ) ; $i++ )
  32.         {
  33.             $sOrder .= fnColumnToField(mysql_real_escape_string( $_GET['iSortCol_'.$i] ))."
  34.                 ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
  35.         }
  36.         $sOrder = substr_replace( $sOrder, "", -2 );
  37.     }
  38.    
  39.     /* Filtering - NOTE this does not match the built-in DataTables filtering which does it
  40.      * word by word on any field. It's possible to do here, but concerned about efficiency
  41.      * on very large tables, and MySQL's regex functionality is very limited
  42.      */
  43.     $sWhere = "";
  44.     if ( $_GET['sSearch'] != "" )
  45.     {
  46.         $sWhere = " WHERE No_ LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  47.                         "Model_Code LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  48.                         "Model_Name LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  49.                         "Lot_No_ LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  50.                         "Start_Seq_No_ LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  51.                         "Quantity LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  52.                         "Lot_Quantity LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  53.                         "Line_Code LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  54.                         "Line_Name LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
  55.                         "Production_Start_Date LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%'";
  56.     } else {
  57.        
  58.         if ( $_GET['sSearch_0'] != "" ){
  59.             if ($sWhere != "") $sWhere.=" AND ";
  60.             $sWhere .= " No_ LIKE '%".mysql_real_escape_string( $_GET['sSearch_0'] )."%' ";
  61.         }
  62.         if ( $_GET['sSearch_1'] != "" ){
  63.             if ($sWhere != "") $sWhere.=" AND ";
  64.             $sWhere .= " Model_Code LIKE '%".mysql_real_escape_string( $_GET['sSearch_1'] )."%' ";
  65.         }
  66.         if ( $_GET['sSearch_2'] != "" ){
  67.             if ($sWhere != "") $sWhere.=" AND ";
  68.             $sWhere .= " Model_Name LIKE '%".mysql_real_escape_string( $_GET['sSearch_2'] )."%' ";
  69.         }
  70.         if ( $_GET['sSearch_3'] != "" ){
  71.             if ($sWhere != "") $sWhere.=" AND ";
  72.             $sWhere .= " Lot_No_ like '%".mysql_real_escape_string( $_GET['sSearch_3'] )."%' ";
  73.         }
  74.         if ( $_GET['sSearch_4'] != "" ){
  75.             if ($sWhere != "") $sWhere.=" AND ";
  76.             $sWhere .= " Start_Seq_No_ LIKE '%".mysql_real_escape_string( $_GET['sSearch_4'] )."%' ";
  77.         }
  78.         if ( $_GET['sSearch_5'] != "" ){
  79.             if ($sWhere != "") $sWhere.=" AND ";
  80.             $sWhere .= " Quantity LIKE '%".mysql_real_escape_string( $_GET['sSearch_5'] )."%' ";
  81.         }
  82.         if ( $_GET['sSearch_6'] != "" ){
  83.             if ($sWhere != "") $sWhere.=" AND ";
  84.             $sWhere .= " Lot_Quantity LIKE '%".mysql_real_escape_string( $_GET['sSearch_6'] )."%' ";
  85.         }
  86.         if ( $_GET['sSearch_7'] != "" ){
  87.             if ($sWhere != "") $sWhere.=" AND ";
  88.             $sWhere .= " Line_Code LIKE '%".mysql_real_escape_string( $_GET['sSearch_7'] )."%' ";
  89.         }
  90.         if ( $_GET['sSearch_8'] != "" ){
  91.             if ($sWhere != "") $sWhere.=" AND ";
  92.             $sWhere .= " Line_Name LIKE '%".mysql_real_escape_string( $_GET['sSearch_8'] )."%' ";
  93.         }
  94.         if ( $_GET['sSearch_9'] != "" ){
  95.             if ($sWhere != "") $sWhere.=" AND ";
  96.             $sWhere .= " Production_Start_Date LIKE '%".mysql_real_escape_string( $_GET['sSearch_9'] )."%' ";
  97.         }
  98.         if ($sWhere != "") $sWhere=" WHERE ".$sWhere;
  99.     }
  100.    
  101.  
  102.     $sQuery = "
  103.         SELECT SQL_CALC_FOUND_ROWS No_,Model_Code,Model_Name,Lot_No_,Start_Seq_No_,Quantity,Lot_Quantity,Line_Code,Line_Name,Production_Start_Date
  104.         FROM   prod_sch
  105.         $sWhere
  106.         $sOrder
  107.         $sLimit
  108.     ";
  109.     $rResult = mysql_query( $sQuery ) or die(mysql_error());
  110.    
  111.     $sQuery = "
  112.         SELECT FOUND_ROWS()
  113.     ";
  114.     $rResultFilterTotal = mysql_query( $sQuery ) or die(mysql_error());
  115.     $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
  116.     $iFilteredTotal = $aResultFilterTotal[0];
  117.    
  118.     $sQuery = "
  119.         SELECT COUNT(No_)
  120.         FROM   prod_sch
  121.     ";
  122.     $rResultTotal = mysql_query( $sQuery ) or die(mysql_error());
  123.     $aResultTotal = mysql_fetch_array($rResultTotal);
  124.     $iTotal = $aResultTotal[0];
  125.    
  126.     $data = array(
  127.         "sEcho" => $_GET['sEcho'],
  128.         "iTotalRecords" => $iTotal,
  129.         "iTotalDisplayRecords" => $iFilteredTotal // you had two times iTotalDisplayRecords
  130.     );
  131.  
  132.     $aaData = array();
  133.     while ( $aRow = mysql_fetch_array( $rResult ) ) {
  134.         $aaData[] = array($aRow['No_'],$aRow['Model_Code'],$aRow['Model_Name'],$aRow['Lot_No_'],$aRow['Start_Seq_No_'],$aRow['Quantity'],$aRow['Lot_Quantity'],$aRow['Line_Code'],  $aRow['Line_Name'],$aRow['Production_Start_Date']);
  135.     }
  136.     $data['aaData'] = $aaData;
  137.     echo json_encode($data);
  138.  
  139. } else {
  140.     // check databae, if no exist, create
  141.    
  142.     $sql="CREATE DATABASE IF NOT EXISTS prodschd;";
  143.     $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  144.    
  145.     // select the database
  146.     mysql_select_db("prodschd") or die(_ERROR17.": ".mysql_error());
  147.    
  148.    
  149.     // check table, if not exist, create
  150.     $sql="CREATE TABLE IF NOT EXISTS `prod_sch` (
  151.   `No_` int(11) NOT NULL,
  152.   `Model_Code` varchar(20) NOT NULL,
  153.   `Model_Name` varchar(20) DEFAULT NULL,
  154.   `Lot_No_` int(11) NOT NULL,
  155.   `Start_Seq_No_` int(11) NOT NULL,
  156.   `Quantity` int(11) NOT NULL,
  157.   `Lot_Quantity` int(11) NOT NULL,
  158.   `Line_Code` varchar(7) DEFAULT NULL,
  159.   `Line_Name` varchar(10) DEFAULT NULL,
  160.   `Production_Start_Date` date NOT NULL,
  161.   `Shift_No1` int(3) DEFAULT NULL,
  162.   `Production_Finish_Date` date NOT NULL,
  163.   `Shift_No2` int(3) DEFAULT NULL,
  164.   `Due_date` date NOT NULL,
  165.   `Production_Mngm_Type` varchar(5) DEFAULT NULL,
  166.   `Model_Group` varchar(15) DEFAULT NULL,
  167.   `Model_Category` varchar(6) DEFAULT NULL,
  168.   `Actual_Results` int(11) DEFAULT NULL,
  169.   `MPS_Mngm_Code` varchar(10) DEFAULT NULL,
  170.   `Production_Mngm_Code` varchar(6) DEFAULT NULL,
  171.   `Comment` varchar(50) DEFAULT NULL
  172. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
  173.    
  174.     $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  175.    
  176.     $sql="CREATE TABLE IF NOT EXISTS settingdata (
  177.       itemID mediumint(9) NOT NULL AUTO_INCREMENT,
  178.       itemname varchar(255) DEFAULT NULL,
  179.       itemdata varchar(255) DEFAULT NULL,
  180.       remark varchar(255) DEFAULT NULL,
  181.       PRIMARY KEY (itemID)
  182.     ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=45 ;";
  183.    
  184.     $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  185.    
  186. //  $sql="SELECT IF(count(*)=0,'1','0') from settingdata";
  187. //  $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  188. //  $dat=mysql_fetch_array($result, MYSQL_NUM);
  189. //  if ($dat[0] = 0){
  190.         $sql="INSERT INTO settingdata (itemID, itemname, itemdata, remark) VALUES
  191.             (1, 'URL 6month schedule', 'http://136.198.117.2/prodschweb/Files/Arsip/PSO.txt', NULL),
  192.             (2, 'Use Proxy','no',NULL),
  193.             (3, 'Proxy', 'yps01.jvc-victor.co.jp:8080', NULL),
  194.             (4, 'Sch RUN DATE', '', NULL)";
  195.         $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  196. //  }
  197.    
  198.    
  199.    
  200.    
  201.    
  202.    
  203.     $sql="SELECT itemdata FROM settingdata WHERE itemname='URL 6month schedule'";  // set up URL of schedule
  204.     $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  205.     $row = mysql_fetch_array($result,MYSQL_ASSOC);
  206.     $url = $row['itemdata'];
  207.    
  208. //  echo "Production schedule will be downloded from ".$url."<BR>";
  209.    
  210.     $sql="SELECT itemdata FROM settingdata WHERE itemname='Use Proxy'";  // set up URL of schedule
  211.     $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  212.     $row = mysql_fetch_array($result,MYSQL_ASSOC);
  213.     $Proxyuse = $row['itemdata'];
  214.  
  215.     if ($Proxyuse!="no") {
  216.         $Proxy = $row['itemdata'];  $sql="SELECT itemdata FROM settingdata WHERE itemname='Proxy'";  // set up URL of schedule
  217.         $result = mysql_query( $sql ) ;// or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  218.         $row = mysql_fetch_array($result,MYSQL_ASSOC);
  219.         $Proxy = $row['itemdata'];
  220. //      echo "By using proxy server  ".$Proxy."<BR>";
  221.  
  222.        
  223.         // Define a context for HTTP.
  224.         $aContext = array(
  225.             'http' => array(
  226.                 'proxy' => 'tcp://'.$Proxy, // This needs to be the server and the port of the NTLM Authentication Proxy Server.
  227.                 'request_fulluri' => True,
  228.                 ),
  229.             );
  230.         $cxContext = stream_context_create($aContext);
  231.        
  232.         // Now all file stream functions can use this context.
  233.        
  234.         $httpfile = file_get_contents($url, False, $cxContext);
  235.     } else {
  236.         $httpfile = file_get_contents($url);
  237.     }
  238.    
  239. //$httpfile  = file_get_contents($url);         // open schedule file
  240. //$httpfile  = file_get_contents('http://136.198.117.2/prodschweb/Import/src/PSO.txt');         // open schedule file
  241. //echo "connected"." <BR>";
  242. $temp_file = tempnam(sys_get_temp_dir(), '3sch.jofcial.txt');  // make temporary file name
  243. //echo $temp_file;
  244. $fp = fopen($temp_file, "wb");      // open temprary file
  245. if (!$fp) die(_ERROR14);
  246. //echo "Opened"." <BR>";
  247.  
  248. fwrite($fp, $httpfile);             // copy to temporary file from schedule file
  249. fclose($fp);
  250. //echo "Downloaded"." <BR>";
  251.  
  252. chmod($temp_file, 0644);            // file mode change for read only
  253. //$temp_file=str_replace("\\","/",$temp_file);  
  254. $sql="TRUNCATE TABLE `prod_sch`";
  255. $res=mysql_query($sql) ;//or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  256. $sql="LOAD DATA LOCAL INFILE '".$temp_file."' REPLACE INTO TABLE `prod_sch` FIELDS TERMINATED BY ',' IGNORE 1 LINES "; // FIELDS ENCLOSED BY '\"' ";
  257. $sql.="(No_ ,Model_Code,Model_Name ,Lot_No_ ,Start_Seq_No_ ,Quantity ,Lot_Quantity ,Line_Code ,Line_Name ,@var10, ";
  258. $sql.="Shift_No1,@var12,Shift_No2,@var14,Production_Mngm_Type,Model_Group,Model_Category,Actual_Results,MPS_Mngm_Code, ";
  259. $sql.="Production_Mngm_Code,Comment) ";
  260. $sql.="SET Production_Start_Date=STR_TO_DATE(@var10,'%m/%d/%Y'), ";
  261. $sql.="Production_Finish_Date=STR_TO_DATE(@var12,'%m/%d/%Y'), ";
  262. $sql.="Due_date=STR_TO_DATE(@var14,'%m/%d/%Y')";
  263. //echo $sql;
  264.  
  265. $res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL and error trap.
  266. unlink($temp_file);
  267. //echo "Copied"." <BR>";
  268.  
  269. ?>
  270. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  271. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  272.     <head>
  273.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  274.         <title>Production shedule search</title>
  275.         <style>
  276.             @import "css/demo_page.css";
  277.             @import "css/demo_table.css";
  278.             @import "css/demo_table_jui.css";
  279.             @import "js/media/css/TableTools.css";
  280.             .right {
  281.                     text-align: right;
  282.                     vertical-align: top;
  283.                     }
  284.         </style>
  285.         <script src="js/jquery-1.4.2.min.js"            type="text/javascript"></script>
  286.         <script src="js/jquery.dataTables.min.js"   type="text/javascript"></script>
  287.         <script type="text/javascript" language="javascript" src="js/media/ZeroClipboard/ZeroClipboard.js"></script>
  288.         <script type="text/javascript" language="javascript" src="js/TableTools.js         "></script>
  289.         <script type="text/javascript">
  290.         var asInitVals = new Array();
  291.         TableToolsInit.sSwfPath = "js/media/swf/ZeroClipboard.swf";
  292.  
  293.         $(document).ready(function() {
  294.             var oTable = $('#schedtbl').dataTable( {
  295.                 "sDom": 'T<"clear">lfrtip',
  296.                 "bProcessing": true,
  297.                 "bServerSide": true,
  298.                 "sAjaxSource": "index.php",
  299.                 "aaSorting": [[ 9, "asc" ]],
  300.                 "sPaginationType": "full_numbers",
  301. //              "bAutoWidth": false,
  302.                 "oLanguage": {
  303.                                 "sSearch": "Search all columns:"
  304.                             },
  305.                 "aoColumns": [
  306.                             { "sClass": "right" },
  307.                             { "sWidth" : "17%" },
  308.                             null,
  309.                             { "sClass": "right" },
  310.                             { "sClass": "right" },
  311.                             { "sClass": "right" },
  312.                             { "sClass": "right" },
  313.                             null,
  314.                             null,
  315.                             null
  316.                             ]
  317.             } );
  318.             $("tfoot input").keyup( function () {
  319.                 /* Filter on the column (the index) of this element */
  320.                 oTable.fnFilter( this.value, $("tfoot input").index(this) );
  321.             } );
  322.             /*
  323.              * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
  324.              * the footer
  325.              */
  326.             $("tfoot input").each( function (i) {
  327.                 asInitVals[i] = this.value;
  328.             } );
  329.             $("tfoot input").focus( function () {
  330.                 if ( this.className == "search_init" )
  331.                 {
  332.                     this.className = "";
  333.                     this.value = "";
  334.                 }
  335.             } );
  336.             $("tfoot input").blur( function (i) {
  337.                 if ( this.value == "" )
  338.                 {
  339.                     this.className = "search_init";
  340.                     this.value = asInitVals[$("tfoot input").index(this)];
  341.                 }
  342.             } );
  343.         });
  344.         </script>
  345.     </head>
  346.     <body>
  347.     <h1>Production schedule search</h1>
  348.     <div id="dt_example">
  349.         <div id="container">
  350.             <div id="ref" style="text-align: right;">
  351.                 <a href="javascript:void(0)" id="clrfilt">Show all data</a>
  352.             </div>
  353.             <div style="text-align:right; padding-bottom:1em;"></div>
  354.             <div id="demo"></div>
  355.             <table cellpadding="0" cellspacing="0" border="0" class="display" id='schedtbl'>
  356.                 <thead>
  357.                     <tr>
  358.                         <th>No_</th>
  359.                         <th>Model_Code</th>
  360.                         <th>Model_Name</th>
  361.                         <th>Lot_No_</th>
  362.                         <th>Start_Seq_No_</th>
  363.                         <th>Quantity</th>
  364.                         <th>Lot_Quantity</th>
  365.                         <th>Line_Code</th>
  366.                         <th>Line_Name</th>
  367.                         <th>Production_Start_Date</th>
  368.                     </tr>
  369.                 </thead>
  370.                 <tfoot>
  371.                     <tr>
  372.                         <th><input type="text" name="search_No_" value="Search No" class="search_init" /></th>
  373.                         <th><input type="text" name="search_Model_Code" value="Search Model_Code" class="search_init" /></th>
  374.                         <th><input type="text" name="search_Model_Name" value="Search Model_Name" class="search_init" /></th>
  375.                         <th><input type="text" name="search_Lot_No_" value="Search Lot_No_" class="search_init" /></th>
  376.                         <th><input type="text" name="search_Start_Seq_No_" value="Search Start_Seq_No_" class="search_init" /></th>
  377.                         <th><input type="text" name="search_Quantity" value="Search Quantity" class="search_init" /></th>
  378.                         <th><input type="text" name="search_Lot_Quantity" value="Search Lot_Quantity" class="search_init" /></th>
  379.                         <th><input type="text" name="search_Line_Code_" value="Search Line_Code" class="search_init" /></th>
  380.                         <th><input type="text" name="search_Line_Name" value="Search Line_Name" class="search_init" /></th>
  381.                         <th><input type="text" name="search_Production_Start_Date" value="Search Production_Start_Date" class="search_init" /></th>
  382.                     </tr>
  383.                 </tfoot>
  384.                 <tbody></tbody>
  385.             </table>
  386.             <div id="ref"></div>
  387.         </div>
  388.     </div>
  389.  
  390.    
  391.    
  392.    
  393.    
  394.    
  395.    
  396.     </body>
  397. </html>
  398. <?php
  399. }
  400.  
  401.  
  402.     function fnColumnToField( $i )
  403.     {
  404.         if ( $i == 0 )
  405.             return "No_";
  406.         else if ( $i == 1 )
  407.             return "Model_Code";
  408.         else if ( $i == 2 )
  409.             return "Model_Name";
  410.         else if ( $i == 3 )
  411.             return "Lot_No_";
  412.         else if ( $i == 4 )
  413.             return "Start_Seq_No_";
  414.         else if ( $i == 5 )
  415.             return "Quantity";
  416.         else if ( $i == 6 )
  417.             return "Lot_Quantity";
  418.         else if ( $i == 7 )
  419.             return "Line_Code";
  420.         else if ( $i == 8 )
  421.             return "Line_Name";
  422.         else if ( $i == 9 )
  423.             return "Production_Start_Date";
  424.     }
  425.  
  426.  
  427. ?>
Advertisement
Add Comment
Please, Sign In to add comment