Showing posts with label PHP Web Application. Show all posts
Showing posts with label PHP Web Application. Show all posts

10/03/2024

Function Checkbox checked by scrip.

 Function Checkbox checked by scrip.

  1. <!DOCTYPE html>
  2. <html>
  3.     <title>Test</title>
  4.     <meta charset="UTF-8">
  5.  
  6.     <body>
  7.         <div align='center'>
  8.             <form id="myForm" align='center'>
  9.                 <label><input type="checkbox" name="OD" id="OD" value="1" onchange="CheckedBox(this.value)"> ฝพอ.</label><br>
  10.                 <label><input type="checkbox" name="IF" id="IF" value="2" onchange="CheckedBox(this.value)"> ฝบง.</label><br>
  11.                 <label><input type="checkbox" name="DS" id="DS" value="3" onchange="CheckedBox(this.value)"> ฝอบ.</label><br>
  12.                 <br><hr>
  13.             </form>
  14.             <br>
  15.             <form id="myForm2" align='center'>
  16.                 <label><input type="checkbox" name="checkbox3" id="checkbox3" value=""> หน.งทส.</label><br>
  17.                 <label><input type="checkbox" name="checkbox4" id="checkbox4" value=""> หน.งพม.</label><br>
  18.                 <label><input type="checkbox" name="checkbox5" id="checkbox5" value=""> หน.งสป.</label><br>
  19.                 <label><input type="checkbox" name="checkbox6" id="checkbox6" value=""> หน.งบง.</label><br>
  20.                 <label><input type="checkbox" name="checkbox7" id="checkbox7" value=""> หน.งอบ 1.</label><br>
  21.                 <label><input type="checkbox" name="checkbox8" id="checkbox8" value=""> หน.งอบ 2.</label><br>
  22.             </form>
  23.         </div> 
  24.         <script></script>
  25.     </body>
  26. </html>

  1.  
  2.     function CheckedBox(value) {
  3.             if(value == 1){
  4.                 if(document.getElementById("OD").checked){
  5.                     document.getElementById("checkbox3").checked = true;
  6.                     document.getElementById("checkbox4").checked = true;
  7.                     document.getElementById("checkbox5").checked = true;
  8.                 } else {
  9.                     document.getElementById("checkbox3").checked = false;
  10.                     document.getElementById("checkbox4").checked = false;
  11.                     document.getElementById("checkbox5").checked = false;
  12.                 }
  13.             } else if (value == 2){
  14.                 if(document.getElementById("IF").checked){
  15.                     document.getElementById("checkbox6").checked = true;   
  16.                 } else {
  17.                     document.getElementById("checkbox6").checked = false;
  18.                 }
  19.  
  20.             } else if (value == 3){
  21.                 if(document.getElementById("DS").checked){
  22.                     document.getElementById("checkbox7").checked = true;
  23.                     document.getElementById("checkbox8").checked = true;   
  24.                 } else {
  25.                     document.getElementById("checkbox7").checked = false;
  26.                     document.getElementById("checkbox8").checked = false;                      
  27.                 }
  28.             } else {
  29.                 document.getElementById("OD").checked = false;
  30.                 document.getElementById("IF").checked = false;
  31.                 document.getElementById("DS").checked = false;
  32.                 document.getElementById("checkbox3").checked = false;
  33.                 document.getElementById("checkbox4").checked = false;
  34.                 document.getElementById("checkbox5").checked = false;
  35.                 document.getElementById("checkbox6").checked = false;
  36.                 document.getElementById("checkbox7").checked = false;
  37.                 document.getElementById("checkbox8").checked = false;
  38.             }   
  39.         }  

Code function validate Input number in textbox only.

 

Code function validate Input number in textbox only.
html
  1. <input type="text" id="test_id" name="test" value="" oninput="validateInput(event)">

js function

  1. function validateInput(event) {
  2.    var input = event.target.value;
  3.    if (!/^[0123456789 ]*$/.test(input)) {
  4.       event.target.value = input.replace(/[^0123456789 ]/g, '');
  5.    }
  6. }

1/17/2022

PHP : php ส่งค่าออก Libreoffice Calc ด้วย TBS

PHP : php ส่งค่าออก Libreoffice Calc ด้วย TBS
ตัวอย่าง
https://www.tinybutstrong.com/opentbs.php?demo

ต้องการส่งค่า ตั้งค่า ใน Template
1. Sting ใช้เป็น [Block.ArrayName]
2. Date ต้องใส่ ;ope=tbs:date ต่อท้าย เช่น [Block.ArrayDate;ope=tbs:date]
3. Number ต้องใส่ ;ope=tbs:num ต่อท้าย เช่น [Block.ArrayDate;ope=tbs:num]
ข้อ 2, 3 ก็จะไม่มี ' และจัด Format ได้
4. ต้องการใส่เลข Run Line ใช้ #;ope=tbs:num ต่อท้าย เช่น [Block.#;ope=tbs:num]

10/27/2020

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

 PHP : การนำวันที่ต่อด้วยเวลาปัจจุบัน และการ Set ค่า NULL เข้าDB
รับ Get หรือ Post มาจาก Form วันที่

  1. list($dd, $mm, $yyyy) = explode("/", $_POST["S_FinishDate_Edit"]);
  2. $S_FinishDate_Edit = "'".$yyyy."-".$mm."-".$dd." ".date("h:i:s")."'";   

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

การ Set ค่า NULL ให้กับวันที่
ประกาศตัวแปรรับค่า NULL สำคัญต้องใส่ "" ด้วย
  1. $S_FinishDate_Edit = "NULL"


SQL String ไม่ต้องใส่ ' ' หรือ " " ถ้าใส่จะ Error เพราะช่องรับค่า NULL เช่น
  1. $SQL .=" `S_SectionDate`=".$S_SectionDate_Edit.",`S_DoneDate`=".$S_DoneDate_Edit.";


ตัวอย่างใน ข้อเสนอแนะตอนแก้ไข
https://intranet.sci.com/sci/suggestion/qp_start.php?YR=2020

6/25/2020

สร้าง QR Code ด้วย Google API

สร้าง QR Code ด้วย Google API
https://developers.google.com/chart/infographics/docs/qr_codes

Code ตัวอย่าง
$Action คือค่าข้อมูลที่เราต้องการส่งไป ตอน Save ข้อมูล จะได้ QR Code มา เมื่ออ่าน QR Code ก็จะไปทำงานใน File ตาม Link ที่กำหนด และส่งตัวแปรไปด้วย
  1. <?php
  2.     $Link = "https://intranet.scivalve.com/sci/QRCode/qr_save.php?ACTION=".$Action."&chld=L|0";
  3.     //$Link = "https://intranet.sci.com/sci/QRCode/qr_get.php?ACTION=1,3842-7,2020-06-25";
  4.     $qr = "<img src='https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=$Link' alt=''>";
  5.     echo $qr;
  6. ?>

อธิบาย Parameter ที่ส่งค่าไป
cht=qr ต้องระบุเป็น qr
chs=<width>x<height> ขนาด กว้าง x สูง ไม่ต้องใส่หน่วยใส่แค่ตัวเลข
chl=<data> ข้อความหรือ URL ที่เราต้องการทำ QR Code

Parameter เพิ่มเติม
choe=<output_encoding> การเข้ารหัสค่าเดิมเป็น UTF-8
chld=<error_correction_level>|<margin> ระดับความคลาดเคลื่อนค่าเดิมอยู่ที่ 7 %

11/25/2019

PHPmyadmin Error เพราะ Bug php.ini ที่พบตอนจะ Restore

PHPmyadmin Error เพราะ Bug php.ini ที่พบตอนจะ Restore Database พบ 2 Case
1.
Warning in ./libraries/plugin_interface.lib.php#551
count(): Parameter must be an array or an object that implements Countable

Backtrace

./libraries/display_import.lib.php#371: PMA_pluginGetOptions(
string 'Import',
array,
)
./libraries/display_import.lib.php#456: PMA_getHtmlForImportOptionsFormat(array)
./libraries/display_import.lib.php#691: PMA_getHtmlForImport(
string '5dd649bc92f3e',
string 'database',
string 'sci_phpbb',
string '',
integer 8388608,
array,
NULL,
NULL,
string '',
)
./db_import.php#43: PMA_getImportDisplay(
string 'database',
string 'sci_phpbb',
string '',
integer 8388608,
)

วิธีแก้
  1. nano /usr/share/phpmyadmin/libraries/plugin_interface.lib.php
  1. ctrl+w
count($options)
if ($options != null && count($options) > 0) {
แก้เป็น
if ($options != null && count((array)$options) > 0) {

2.
Warning in ./libraries/sql.lib.php#613
count(): Parameter must be an array or an object that implements Countable

Backtrace

./libraries/sql.lib.php#2128: PMA_isRememberSortingOrder(array)
./libraries/sql.lib.php#2079: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'sci_phpbb',
string 'phpbb_blogs_plugins',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `phpbb_blogs_plugins`',
NULL,
NULL,
)
./sql.php#221: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'sci_phpbb',
string 'phpbb_blogs_plugins',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `phpbb_blogs_plugins`',
NULL,
NULL,
)

วิธีแก้
  1. nano /usr/share/phpmyadmin/libraries/sql.lib.php

go to line 613
|| (count($analyzed_sql_results['select_expr'] == 1)
&& ($analyzed_sql_results['select_expr'][0] == '*')))
&& count($analyzed_sql_results['select_tables']) == 1;
แทนที่ด้วย
|| count($analyzed_sql_results['select_expr']) == 1
&& ($analyzed_sql_results['select_expr'][0] == '*'))
&& count($analyzed_sql_results['select_tables']) == 1;

แล้ว Restart apache
  1. /etc/init.d/apache2 restart


Fix Bug Phpmyadmin [plugin_interface.lib.php] + Php7.2 + Ubuntu 18.04
http://libtechnophile.blogspot.com/2019/08/m.html
https://medium.com/@chaloemphonthipkasorn/%E0%B9%81%E0%B8%81%E0%B9%89-bug-phpmyadmin-php7-2-ubuntu-16-04-92b287090b01

10/28/2019

Directadmin API Command

Directadmin API Command Directadmin สามารถใช้ Command ที่เป็น API เข้าไปเรียกข้อมูลมาใช้งานได้
https://www.directadmin.com/search_versions.php?help=no&versions=yes&query=CMD_API_

เช่น อ่านค่าเมล์ ของ User ว่าเต็มหรือไม่แล้วแจ้งเตือนในเมล์
ใช้ httpsocket.php ร่วมกับ CMD_API_POP

ไฟล์อยู่ที่
http://www.scivalve.com/checkuse/checkmail.php

Code:
  1.  
  2.  
  3. include("httpsocket.php");
  4. //nou de socket is geinclude kunnen we hem starten
  5. $sock = new HTTPSocket;
  6.  
  7. //nu gaan we inloggen in Direct Admin (verander wel de gegevens)
  8. $sock->connect('127.0.0.1',2222);
  9. $sock->set_login('XXXXX','XXXXXXXX');
  10.  
  11. $domain='scivalve.com' ;
  12.  
  13. function formatSizeUnits($bytes)
  14. {
  15.    if($bytes >= 1099511627776){
  16.     $bytes = number_format($bytes / 1099511627776, 2) . ' TB';
  17.    } elseif($bytes >= 1073741824){
  18.     $bytes = number_format($bytes / 1073741824, 2) . ' GB';
  19.    } elseif($bytes >= 1048576){
  20.       $bytes = number_format($bytes / 1048576, 2) . ' MB';
  21.    } elseif ($bytes >= 1024){
  22.       $bytes = number_format($bytes / 1024, 2) . ' KB';
  23.    } elseif ($bytes > 1){
  24.       $bytes = $bytes . ' bytes';
  25.    } elseif ($bytes == 1){
  26.       $bytes = $bytes . ' byte';
  27.    } else {
  28.       $bytes = '-';
  29.    }
  30. return $bytes;
  31. }//Close Functions.
  32.  
  33. //User Susspende เช็คไม่ได้ต้องเขียนไว้เทียบเอา
  34. $UserSuspended="chanakan
  35. jirasak
  36. julalak
  37. kongsit
  38. mathuros
  39. monthon
  40. nattapol
  41. nontiwa
  42. pattanan
  43. porramate
  44. sarawut
  45. sarawut_e
  46. sudjai
  47. tanupat
  48. thanyalak";
  49.  
  50. $sock->query('/CMD_API_POP', array(
  51.    'action'     => 'full_list',
  52.    'type'       => 'quota',
  53.    //'suspended'    => 'yes',
  54.    'domain'     => $domain
  55. ));
  56. $user_quota = $sock->fetch_parsed_body();
  57. //print_r($user_quota);
  58. $i = 0;
  59. foreach ($user_quota as $key => $value) {
  60.     //echo $key.":".$value."<br>";
  61.     //ใช้ List Run บน Crontab แล้ว Error
  62.     //list($quota, $sent, $usage, $Use, $usage_bytes) = explode('&', $value);  
  63.     $pieces = explode("&", $value);
  64.     $quota = $pieces[0];
  65.     //$sent = $pieces[1];
  66.     $usage = $pieces[2];
  67.     //$Use = $pieces[3];
  68.     //$usage_bytes = $pieces[4];
  69.     //echo $key.":".$quota.":".$usage;
  70.     $quotaValue = explode('=', $quota);
  71.     $usageValue = explode('=', $usage);
  72.  
  73.     if (strpos($UserSuspended, "'".$key."'") !== false) {
  74.         if((($quotaValue[1] - $usageValue[1]) <= 0) && ($quotaValue[1] != 0)){
  75.             //echo $key." : ส่งเมล์ <br>";
  76.             $i = $i+1;
  77.             if($i == 1){
  78.                 $EmailUser = $i." : ".$key."@scivalve.com  ".formatSizeUnits($quotaValue[1])."/".formatSizeUnits($usageValue[1])."<br>";   
  79.             } else {   
  80.                 $EmailUser = $EmailUser.$i." : ".$key."@scivalve.com  ".formatSizeUnits($quotaValue[1])."/".formatSizeUnits($usageValue[1])."<br>"; 
  81.             }     
  82.         }//Close if.
  83.     }//Close if.
  84. }//Close for.
  85. //echo $EmailUser;
  86.  
  87. if($i > 0){
  88.     //ส่งเมล์ 
  89.     //อ้าง Path Run บนเว็บผ่าน แต่ Run ผ่าน Crontab Error 
  90.     require("/home/scivalve/public_html/mailer/class.phpmailer.php");
  91.     $mail = new PHPMailer();
  92.     $body = " พบเมล์ scivalve ของ User ใกล้เต็ม กรุณาตรวจสอบ ดังนี้ Quota/Used<br> $EmailUser "; 
  93.    
  94.     $mail->CharSet = "utf-8";
  95.     $mail->IsSMTP();
  96.     $mail->SMTPDebug = 0;
  97.     $mail->SMTPAuth = true;
  98.     $mail->Host = "ssl://smtp.gmail.com"; // SMTP server
  99.     $mail->Port = 465; // พอร์ท
  100.     $mail->Username = "XXXXXX@gmail.com"; // account SMTP
  101.     $mail->Password = "XXXXXX"; // รหัสผ่าน SMTP   
  102.    
  103.     $mail->SetFrom("scivalvethailand@gmail.com", "scivalve.com");
  104.     $mail->AddReplyTo("scivalvethailand@gmail.com", "scivalve.com");
  105.     $mail->Subject = "Check Mail Full @scivalve.com";
  106.    
  107.     $mail->MsgHTML($body);
  108.    
  109.     //if($fileRename0 != ""){   
  110.     //  $file = "message/".$fileRename0;   
  111.     //  $mail->addAttachment($file, $fileRename0);
  112.     //}
  113.     $mail->AddAddress("suwit@scivalve.com", "SCI"); // ผู้รับคนที่ 1
  114.     $mail->AddAddress("nikom@scivalve.com", "SCI"); // ผู้รับคนที่ 2
  115.     $mail->AddAddress("seksan@scivalve.com", "SCI"); // ผู้รับคนที่ 3
  116.     $mail->Send();
  117.  
  118.     //if(!$mail->Send()) {
  119.     //  $report= "Mailer Error: " . $mail->ErrorInfo;
  120.     //} else {
  121.     //  $report=    " <center><br><font =class='txt1'><b>Send message complete<br>Please wait for back to home page<b></font>";
  122.     //} 
  123. }


Test Run command
  1. /usr/local/bin/php /home/scivalve/public_html/checkuse/checkmail.php


ssh ไปที่ Server VPS สร้าง Crontab ใช้ Vi ยาก ใช้ nana ไฟล์อยู่ที่
  1. nano /var/spool/cron/root

ตั้งไว้ เช็คทุกวัน หกโมงเช้า จันทร์ - เสาร์
0 6 * * 1-6 /usr/local/bin/php /home/scivalve/public_html/checkuse/checkmail.php

เมล์ที่แจ้งเตือน ตัวอย่าง

9/26/2019

Extranet : Load Drawing ไม่ได้

Extranet : Load Drawing ไม่ได้
Error
Fatal error: Call to undefined function imagecreatefromjpeg() in /var/www/extranet/getimage.php on line 23


ใช้ php5 ติดตั้ง php5-gd ubuntu 18.04
  1. sudo apt-get update

For 5.6 PHP
  1. sudo apt-get install php5.6-gd


ถ้าใช้ php 7 For 7.0 PHP
  1. sudo apt-get install php7.0-gd

https://stackoverflow.com/questions/44718896/how-to-install-php-gd-in-ubuntu

5/29/2019

PHP :: สร้างกราฟต่าง ๆ ด้วย PHP

PHP :: สร้างกราฟต่าง ๆ ด้วย PHP

ตัวอย่าง
https://intranet.sci.com/sci/AF/ConsumeChart/OT1.php?Year=2018

1. Download lib มาไว้ที่เครื่อง ที่ Run Web apache
https://www.highcharts.com/blog/download/

2. เข้าดูตัวอย่างใน examples จะมีตัวอย่างกราฟต่าง ๆ
PHP ตัวอย่าง เช่น
  1. <?php
  2. error_reporting(E_ERROR);
  3. define('IN_PHPBB', true);
  4. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../../';
  5. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  6. include($phpbb_root_path . 'common.' . $phpEx);
  7.  
  8. include($phpbb_root_path ."sci/include/config.php");
  9. //include($phpbb_root_path ."sci/include/db.php");
  10. include($phpbb_root_path ."sci/include/functions.php");
  11. include($phpbb_root_path ."sci/include/db2.php");
  12.  
  13. $dep = array('DS', 'IF', 'OD', 'PD', 'QA', 'SS2', 'SS1:SS', 'SS1', 'PR', 'WH');
  14. $depTH = array('ฝอบ.', 'ฝทง.', 'ฝพอ.', 'ฝผล.', 'ฝปค.', 'ฝข.2', 'งสข.', 'ฝข.1', 'ฝวจ.', 'งคส.');
  15. //$SQL = "SELECT AccountNum,AccountName,SUM(AMOUNT),Department FROM sci_AxUsedWaste.Data";
  16.  
  17. $curYear = $_GET["Year"];
  18. if($curYear == ""){
  19.     $curYear = date("Y");
  20.     $yearLoop = array('2019', '2018', '2017');
  21. } else {
  22.     $yearLoop = array($curYear);
  23. }
  24.  
  25. ?>
  26. <!DOCTYPE HTML>
  27. <html>
  28.     <head>
  29.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  30.         <meta name="viewport" content="width=device-width, initial-scale=1">
  31.         <title>Highcharts Example</title>
  32.  
  33.         <style type="text/css">
  34.  
  35.         </style>
  36.     </head>
  37.     <body>
  38. <script src="../lib/code/highcharts.js"></script>
  39. <script src="../lib/code/modules/exporting.js"></script>
  40. <script src="../lib/code/modules/export-data.js"></script>
  41.  
  42. <!-- ---------------------------------------- 1 ------------------------------------------------------ --> 
  43. <div id="container" style="min-width: 310px; max-width: 1000px; margin: 0 auto"></div>
  44.  
  45.         <script type="text/javascript">
  46. Highcharts.setOptions({
  47.     lang: {
  48.       decimalPoint: '.',
  49.       thousandsSep: ','
  50.     }
  51. });
  52. var chart = new Highcharts.Chart({
  53.       chart: {
  54.          renderTo: 'container',
  55.          type: 'line'
  56.       },
  57.         title: {
  58.                 text: "กราฟแสดงจำนวน OT แยกฝ่าย"
  59.         },
  60.  
  61.         xAxis: {
  62.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  63.         max: 11
  64.         },
  65.  
  66.         yAxis: {
  67.         title: {
  68.             text: 'บาท'
  69.         }
  70.       },       
  71.         tooltip: {
  72.         crosshairs: true,
  73.         shared: true
  74.         },
  75.        
  76.         plotOptions: {
  77.         line: {
  78.             dataLabels: {
  79.                 enabled: true
  80.             },
  81.             marker: {
  82.                 radius: 4,
  83.                 lineColor: '#666666',
  84.                 lineWidth: 1
  85.             }
  86.         },
  87.         /*series: {
  88.             cursor: 'pointer',
  89.             point: {
  90.                 events: {
  91.                     click: function () {
  92.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  93.                         location.href = 'consumeByMonth.php?acc=<?php echo $acc ?>' + '&mm=' + this.category + '&yy=' + <?php echo $curYear ?>;
  94.                     }
  95.                 }
  96.             }
  97.         }*/
  98.         },     
  99.         series: [
  100. <?php
  101.     for($i = 0; $i < 10; $i++ ){
  102.         $data = [];
  103.         $SQL = "SELECT * FROM sci_consume_chart.ot";
  104.         $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  105.         $SQL .= " AND Department LIKE '$depTH[$i]%'";
  106.         $SQL .= " ORDER BY Department";
  107.         $result = $mysqli->query($SQL);
  108. //      echo $SQL;
  109. //      exit;
  110.         while($row = $result->fetch_array()){
  111.             $data += [ $row["YearMonth"] => $row["OTCost"] ];
  112.         }
  113.        
  114.         for($n = 1; $n < date(m); $n++){
  115.             $date = sprintf($curYear."-%02s", $n);
  116.             if(!array_key_exists($date, $data)){
  117.                 $data += [ $date => 0 ];
  118.             }      
  119.         }
  120.         ksort($data);
  121. ?>         
  122.       {
  123.         name: <?php echo "'".$depTH[$i]."'" ?>,
  124.          data: [<?php echo join($data, ',') ?>]
  125.       },
  126. <?php
  127.     }
  128. ?>      
  129.       ]  
  130. });
  131.         </script>
  132.  
  133. <!-- --------------------------------------------- 2 ---------------------------------------------------- -->   
  134. <br>
  135. <br>       
  136.  
  137. <?php
  138. //############# Line 1 PD Weight ##################//
  139. $data1 = [];   
  140. $SQL = "SELECT * FROM sci_consume_chart.PD_weight";
  141. $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  142. $SQL .= " ORDER BY YearMonth";
  143. $result = $mysqli->query($SQL);
  144. while($row = $result->fetch_array()){
  145.     $data1 += [ $row["YearMonth"] => $row["Weight"] ];
  146. }
  147.  
  148. for($n = 1; $n <= 12; $n++){
  149.     $date = sprintf($curYear."-%02s", $n);
  150.     if(!array_key_exists($date, $data1)){
  151.         $data1 += [ $date => 0 ];
  152.     }      
  153. }
  154. ksort($data1);
  155. //print_r($dataColumn);    
  156.  
  157. //############# Line 2 OTHour ##################//
  158. for($i = 0; $i < 10; $i++ ){
  159.     $data2 = [];    //Reset.
  160.     $SQL = "SELECT SUM(OTHour) AS SumOTHour, YearMonth FROM sci_consume_chart.ot";
  161.     $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  162.     $SQL .= " GROUP BY YearMonth";
  163.     $SQL .= " ORDER BY Department";
  164.     $result = $mysqli->query($SQL);
  165.     while($row = $result->fetch_array()){
  166.         $data2 += [ $row["YearMonth"] => $row["SumOTHour"] ];
  167.     }
  168.    
  169.     for($n = 1; $n <= 12; $n++){
  170.         $date = sprintf($curYear."-%02s", $n);
  171.         if(!array_key_exists($date, $data2)){
  172.             $data2 += [ $date => 0 ];
  173.         }      
  174.     }
  175.     ksort($data2);
  176.    $data2 = join($data2, ',');
  177. }
  178.  
  179.  
  180. ?>
  181. <div id="container2" style="min-width: 310px; max-width: 1180px; margin: 0 auto"></div>
  182. <script type="text/javascript">
  183. var chart2 = new Highcharts.chart('container2', {
  184.     chart: {
  185.         zoomType: 'xy'
  186.     },
  187.     title: {
  188.         text: "กราฟแสดงน้ำหนักผลิต (กก.) และ OT (ชั่วโมง)"
  189.     },
  190.     subtitle: {
  191.         text: ''
  192.     },
  193.     xAxis: [{
  194.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  195.             'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  196.         crosshair: true
  197.     }],
  198.     yAxis: [{ // Primary yAxis
  199.         labels: {
  200.             format: '{value} กิโลกรัม',
  201.             style: {
  202.                 color: Highcharts.getOptions().colors[1]
  203.             }
  204.         },
  205.         title: {
  206.             text: 'น้ำหนักผลิต',
  207.             style: {
  208.                 color: Highcharts.getOptions().colors[1]
  209.             }
  210.         },
  211.         opposite: true
  212.  
  213.     }, { // Secondary yAxis
  214.         gridLineWidth: 0,
  215.         title: {
  216.             text: 'OT',
  217.             style: {
  218.                 color: Highcharts.getOptions().colors[1]
  219.             }
  220.         },
  221.         labels: {
  222.             format: '{value} ชั่วโมง',
  223.             style: {
  224.                 color: Highcharts.getOptions().colors[1]
  225.             }
  226.         }
  227.     }],
  228.     tooltip: {
  229.         shared: true
  230.     },
  231.     legend: {
  232.           //layout: 'vertical', 
  233.         layout: 'horizontal',
  234.         align: 'left',
  235.         x: 100,
  236.         verticalAlign: 'top',
  237.         y: 20,
  238.         floating: true,
  239.         backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255,255,255,0.25)'
  240.     },
  241.         plotOptions: {
  242.         column: {
  243.             dataLabels: {
  244.                 enabled: true,
  245.                 color: 'red'        
  246.             }
  247.         },
  248.         line: {
  249.             dataLabels: {
  250.                 enabled: true
  251.             },
  252.             marker: {
  253.                 radius: 4,
  254.                 lineColor: '#666666',
  255.                 lineWidth: 1
  256.             }
  257.         },/*
  258.         series: {
  259.             cursor: 'pointer',
  260.             point: {
  261.                 events: {
  262.                     click: function () {
  263.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  264.                         location.href = 'TopItemByMonth.php?itemid=<?php echo $itemid ?>' + '&mm=' + this.category + '&yy=' + <?php echo $prvYear ?>;
  265.                     }
  266.                 }
  267.             }
  268.         }*/
  269.         },    
  270.     series: [{
  271.         name: 'น้ำหนักผลิต',
  272.         type: 'column',
  273.         data: [<?php echo join($data1, ',') ?>],
  274.         tooltip: {
  275.             valueSuffix: ' กิโลกรัม'
  276.         }
  277.  
  278.     }, {
  279.         name: 'Sum ทุกฝ่าย',
  280.         type: 'line',
  281.         yAxis: 1,
  282.         data: [<?php echo $data2; ?>],
  283.         tooltip: {
  284.             valueSuffix: ' บาท'
  285.         }
  286.                    
  287.     }]
  288. });
  289.  
  290. </script>   
  291. <br>
  292. <br>
  293. <!-- ---------------------------------------- 3 ------------------------------------------------------ --> 
  294. <div id="container3" style="min-width: 310px; max-width: 1000px; margin: 0 auto"></div>
  295.  
  296.         <script type="text/javascript">
  297. Highcharts.setOptions({
  298.     lang: {
  299.       decimalPoint: '.',
  300.       thousandsSep: ','
  301.     }
  302. });
  303. var chart3 = new Highcharts.Chart({
  304.       chart: {
  305.          renderTo: 'container3',
  306.          type: 'line'
  307.       },
  308.         title: {
  309.                 text: "กราฟแสดงอัตราส่วน OT/น้ำหนักผลิต (ชั่วโมง/ตัน)"
  310.         },
  311.  
  312.         xAxis: {
  313.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  314.         max: 11
  315.         },
  316.  
  317.         yAxis: {
  318.         title: {
  319.             text: 'ชั่วโมง'
  320.         }
  321.       },       
  322.         tooltip: {
  323.         crosshairs: true,
  324.         shared: true
  325.         },
  326.        
  327.         plotOptions: {
  328.         line: {
  329.             dataLabels: {
  330.                 enabled: true
  331.             },
  332.             marker: {
  333.                 radius: 4,
  334.                 lineColor: '#666666',
  335.                 lineWidth: 1
  336.             }
  337.         },
  338.         /*series: {
  339.             cursor: 'pointer',
  340.             point: {
  341.                 events: {
  342.                     click: function () {
  343.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  344.                         location.href = 'consumeByMonth.php?acc=<?php echo $acc ?>' + '&mm=' + this.category + '&yy=' + <?php echo $curYear ?>;
  345.                     }
  346.                 }
  347.             }
  348.         }*/
  349.         },     
  350.         series: [
  351. <?php
  352. if($curYear == date(Y)){
  353.     $loop = 3;
  354. } else {
  355.     $loop = 1;
  356. }   
  357.  
  358. for($i = 0; $i < $loop; $i++ ){
  359.     $data3 = [];
  360.     $SQL = "SELECT * FROM sci_consume_chart.PD_weight";
  361.     $SQL .= " WHERE YearMonth LIKE '$yearLoop[$i]-%'";
  362.     $SQL .= " ORDER BY YearMonth";
  363.     $result = $mysqli->query($SQL);
  364.     //$x = 1;
  365.     while($row = $result->fetch_array()){
  366.         //echo $x.":".$row["Weight"]."<br>";
  367.         $SQL2 = "SELECT SUM(OTHour) AS SumOTHour FROM sci_consume_chart.ot";
  368.         $SQL2 .= " WHERE YearMonth = '".$row["YearMonth"]."'";
  369.         $SQL2 .= " GROUP BY '".$row["YearMonth"]."'";
  370.         $result2 = $mysqli->query($SQL2);
  371.         //echo $SQL2."<br>";
  372.          
  373.         $row2 = $result2->fetch_array();
  374.         $ValuePrint = number_format($row2["SumOTHour"] / ($row["Weight"] / 1000), 2, ".", "");
  375.         $data3 += [ $row["YearMonth"] => $ValuePrint ];
  376.         //$x++; 
  377.     }
  378.    
  379.     if($curYear == $yearLoop[$i]){
  380.         for($n = 1; $n < date(m); $n++){
  381.             $date = sprintf($curYear."-%02s", $n);
  382.             if(!array_key_exists($date, $data3)){
  383.                 $data3 += [ $date => 0 ];
  384.             }      
  385.         }
  386.     }   
  387.     ksort($data3);
  388. ?>         
  389.       {
  390.         name: <?php echo "'".$yearLoop[$i]."'" ?>, 
  391.          data: [<?php echo join($data3, ',') ?>]
  392.       },
  393. <?php
  394. }
  395. ?>          
  396.       ]  
  397. });
  398.         </script>   
  399.        
  400.     </body>
  401. </html>