Advertisement
Guest User

functions

a guest
Jul 16th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 73.05 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(0);
  4.  
  5. //เชื่อต่อ Database
  6. $con = mysqli_connect("localhost","root","","soldier");
  7. $con->set_charset("utf8");
  8.  
  9.  
  10.  
  11. //--------------------------------------- Start User ----------------------------------------------------
  12.  
  13. function checkLogin($username,$password){
  14. $data = array();
  15. global $con;
  16. $res = mysqli_query($con,"select * from soldier where username = '".$username."' and password='".$password."'");
  17.  
  18. while($row = mysqli_fetch_array($res)) {
  19. $data['id'] = $row['id'];
  20. $data['soldierid'] = $row['soldierid'];
  21. $data['firstname'] = $row['firstname'];
  22. $data['lastname'] = $row['lastname'];
  23.  
  24.  
  25. }
  26. if (!empty($data)) {
  27.  
  28. session_start();
  29. $id = $data['id'];
  30. $_SESSION['id'] = $data['id'];
  31. echo ("<script language='JavaScript'>
  32. window.location.href='dashboard.php?id=$id';
  33. </script>");
  34.  
  35. }else{
  36. echo ("<script language='JavaScript'>
  37. alert('ช่ือผู้ใช้งาน ไม่ถูกต้อง');
  38. </script>");
  39. }
  40.  
  41. mysqli_close($con);
  42.  
  43. }
  44.  
  45. function logout(){
  46. session_start();
  47. session_unset();
  48. session_destroy();
  49. echo ("<script language='JavaScript'>
  50. window.location.href='index.php';
  51. </script>");
  52. exit();
  53. }
  54.  
  55. function getUser($id){
  56. global $con;
  57. $res = mysqli_query($con,"SELECT * FROM soldier WHERE id = '".$id."'");
  58. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  59. return $result;
  60.  
  61. mysqli_close($con);
  62.  
  63. }
  64.  
  65. function getUserBySoldierid($soldierid){
  66. global $con;
  67. $res = mysqli_query($con,"SELECT * FROM soldier WHERE soldierid = '".$soldierid."'");
  68. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  69. return $result;
  70.  
  71. mysqli_close($con);
  72.  
  73. }
  74. //----------------------------------------------End User-----------------------------------------
  75.  
  76. //----------------------------------------------Start News-----------------------------------------
  77.  
  78.  
  79. function saveNews($news_name,$news_detail,$news_address,$news_picture,$soldierid){
  80. global $con;
  81.  
  82. if($news_picture != null){
  83. if(move_uploaded_file($_FILES["news_picture"]["tmp_name"],"images/news/".$_FILES["news_picture"]["name"]))
  84. {
  85.  
  86. $sql = "INSERT INTO news ( news_name, news_detail, news_address, news_picture, soldierid) VALUES('".$news_name."','".$news_detail."','".$news_address."','".$_FILES["news_picture"]["name"]."','".$soldierid."')";
  87. mysqli_query($con,$sql);
  88. }
  89. }else{
  90.  
  91. $sql = "INSERT INTO news ( news_name, news_detail, news_address, soldierid) VALUES('".$news_name."','".$news_detail."','".$news_address."','".$soldierid."')";
  92. mysqli_query($con,$sql);
  93. mysqli_close($con);
  94.  
  95. }
  96.  
  97. echo ("<script language='JavaScript'>
  98. alert('เพิ่มข่าวสารเรียบร้อย');
  99. window.location.href='manage_news.php';
  100. </script>");
  101.  
  102. }
  103.  
  104. function editNews($newsid,$news_name,$news_detail,$news_address,$news_picture,$soldierid,$old_picture){
  105. global $con;
  106.  
  107. if($news_picture != null){
  108. $delete="images/news/".$old_picture;
  109. @unlink($delete);
  110. if(move_uploaded_file($_FILES["news_picture"]["tmp_name"],"images/news/".$_FILES["news_picture"]["name"]))
  111. {
  112.  
  113. mysqli_query($con,"UPDATE news SET news_name='".$news_name."',news_detail='".$news_detail."',news_address='".$news_address."',news_picture='".$_FILES["news_picture"]["name"]."',soldierid='".$soldierid."' WHERE newsid = '".$newsid."'");
  114. mysqli_close($con);
  115. }
  116. }else{
  117. mysqli_query($con,"UPDATE news SET news_name='".$news_name."',news_detail='".$news_detail."',news_address='".$news_address."',soldierid='".$soldierid."' WHERE newsid = '".$newsid."'");
  118. mysqli_query($con,$sql);
  119. mysqli_close($con);
  120.  
  121. }
  122.  
  123. echo ("<script language='JavaScript'>
  124. alert('แก้ไขข่าวสารเรียบร้อย');
  125. window.location.href='manage_news.php';
  126. </script>");
  127.  
  128. }
  129.  
  130. function deleteNews($newsid){
  131. global $con;
  132.  
  133. //$res = mysqli_query($con,"SELECT * FROM news WHERE newsid = '".$newsid."'");
  134. //$result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  135.  
  136. mysqli_query($con,"DELETE FROM news WHERE newsid='".$newsid."'");
  137. mysqli_close($con);
  138. echo ("<script language='JavaScript'>
  139. alert('ลบข้อมูลเรียบร้อยแล้ว');
  140. window.location.href='manage_news.php';
  141. </script>");
  142.  
  143. }
  144.  
  145. function getAllNews(){
  146. global $con;
  147. $sql = "SELECT *
  148. FROM news n
  149. LEFT JOIN soldier s
  150. ON n.soldierid = s.soldierid
  151. ORDER BY n.newsid DESC";
  152. $res = mysqli_query($con,$sql);
  153.  
  154. $data = array();
  155. while($row = mysqli_fetch_assoc($res)) {
  156. $namesArray[] = array(
  157. 'newsid' => $row['newsid'],
  158. 'news_name' => $row['news_name'],
  159. 'news_detail' => $row['news_detail'],
  160. 'news_address' => $row['news_address'],
  161. 'news_picture' => $row['news_picture'],
  162. 'name' => $row['name'],
  163. 'lastname' => $row['lastname'],
  164. 'createdate' => $row['createdate'],
  165. 'soldierid' => $row['soldierid']);
  166. }
  167.  
  168. $data = $namesArray;
  169.  
  170. return $data;
  171. mysqli_close($con);
  172.  
  173. }
  174.  
  175. function getCurrentNews($newsid){
  176.  
  177. global $con;
  178.  
  179. $res = mysqli_query($con,"SELECT * FROM news WHERE newsid = '".$newsid."'");
  180. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  181. return $result;
  182.  
  183. mysqli_close($con);
  184.  
  185. }
  186.  
  187. //----------------------------------------------End News-----------------------------------------
  188.  
  189. //----------------------------------------------Start Car---------------------------------------
  190.  
  191. function saveCar($carnumber,$dateregis,$carprovince,$datetax,$dateexpiretax,$image_car,$carmodelid,$cartypeid,$soldierid){
  192.  
  193. $carnumber = ereg_replace('[[:space:]]+', '', trim($carnumber));
  194.  
  195. global $con;
  196. $arrDate1 = explode("/", $dateregis);
  197. $convert_dateregis = $arrDate1[2].'-'.$arrDate1[1].'-'.$arrDate1[0];
  198. $arrDate2 = explode("/", $datetax);
  199. $convert_datetax = $arrDate2[2].'-'.$arrDate2[1].'-'.$arrDate2[0];
  200. $arrDate3 = explode("/", $dateexpiretax);
  201. $convert_dateexpiretax = $arrDate3[2].'-'.$arrDate3[1].'-'.$arrDate3[0];
  202.  
  203. $res = mysqli_query($con,"select * from car where carnumber = '".$carnumber."'");
  204.  
  205. while($row = mysqli_fetch_array($res)) {
  206. $data['carnumber'] = $row['carnumber'];
  207.  
  208. }
  209.  
  210. if (empty($data)) {
  211. if($image_car != null){
  212. if(move_uploaded_file($_FILES["image_car"]["tmp_name"],"images/car/".$_FILES["image_car"]["name"]))
  213. {
  214. $sql = "INSERT INTO car ( dateregis, carnumber, carprovince, datetax, dateexpiretax, image_car, carmodelid, cartypeid, soldierid) VALUES('".$convert_dateregis."','".$carnumber."','".$carprovince."','".$convert_datetax."','".$convert_dateexpiretax."','".$_FILES["image_car"]["name"]."','".$carmodelid."','".$cartypeid."','".$soldierid."')";
  215.  
  216. mysqli_query($con,$sql);
  217.  
  218. }
  219. }else{
  220. $sql = "INSERT INTO car ( dateregis, carnumber, carprovince, datetax, dateexpiretax, carmodelid, cartypeid, soldierid) VALUES('".$convert_dateregis."','".$carnumber."','".$carprovince."','".$convert_datetax."','".$convert_dateexpiretax."','".$carmodelid."','".$cartypeid."','".$soldierid."')";
  221. mysqli_query($con,$sql);
  222.  
  223.  
  224. }
  225.  
  226. $last_id = $con->insert_id;
  227. $nameQR = $last_id.".png";
  228. mysqli_query($con,"UPDATE car SET qrcode='".$nameQR."' WHERE carid = '".$last_id."'");
  229. //$qr_name_save = $last_id.".png";
  230. $remoteFile='http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=L|0&chl='.$last_id;
  231. $localFile='images/qr_code/'.$last_id.'.png';
  232.  
  233.  
  234. saveFileFromTheWeb($remoteFile,$localFile); //2225
  235. if($soldierid != 0 || $soldierid != ""){
  236. $sql1 = "INSERT INTO carmanage (carid, soldierid) VALUES('".$last_id."','".$soldierid."')";
  237. mysqli_query($con,$sql1);
  238. }
  239.  
  240. mysqli_close($con);
  241. echo ("<script language='JavaScript'>
  242. alert('เพิ่มข้อมูลรถเรียบร้อย');
  243. window.location.href='manage_car.php';
  244. </script>");
  245.  
  246. }else{
  247. echo ("<script language='JavaScript'>
  248. alert('ทะเบียนถูกใช้ไปแล้ว');
  249. history.go(-1);
  250. </script>");
  251. } // -1 ทำเสร๊จกลับมาหน้าเดิม
  252.  
  253.  
  254. }
  255.  
  256. function editCar($carid,$carnumber,$dateregis,$carprovince,$datetax,$dateexpiretax,$image_car,$carmodelid,$cartypeid,$soldierid){
  257. //print_r($carid);
  258. //die();
  259. global $con;
  260. $arrDate1 = explode("/", $dateregis);
  261. $convert_dateregis = $arrDate1[2].'-'.$arrDate1[1].'-'.$arrDate1[0];
  262. $arrDate2 = explode("/", $datetax);
  263. $convert_datetax = $arrDate2[2].'-'.$arrDate2[1].'-'.$arrDate2[0];
  264. $arrDate3 = explode("/", $dateexpiretax);
  265. $convert_dateexpiretax = $arrDate3[2].'-'.$arrDate3[1].'-'.$arrDate3[0];
  266. if($image_car != null){
  267. if(move_uploaded_file($_FILES["image_car"]["tmp_name"],"images/car/".$_FILES["image_car"]["name"]))
  268. {
  269. $sql = "UPDATE car SET carnumber='".$carnumber."',dateregis='".$convert_dateregis."',carprovince='".$carprovince."',datetax='".$convert_datetax."',dateexpiretax='".$convert_dateexpiretax."',image_car='".$_FILES["image_car"]["name"]."',carmodelid='".$carmodelid."',cartypeid='".$cartypeid."',soldierid='".$soldierid."' WHERE carid = '".$carid."'";
  270. //print_r($sql);
  271. //die();
  272. mysqli_query($con,$sql);
  273.  
  274. //mysqli_close($con);
  275. }
  276. }else{
  277. $sql = "UPDATE car SET carnumber='".$carnumber."',dateregis='".$convert_dateregis."',carprovince='".$carprovince."',datetax='".$convert_datetax."',dateexpiretax='".$convert_dateexpiretax."',carmodelid='".$carmodelid."',cartypeid='".$cartypeid."',soldierid='".$soldierid."' WHERE carid = '".$carid."'";
  278. //print_r($sql);
  279. //die();
  280. mysqli_query($con,$sql);
  281.  
  282. }
  283.  
  284. if($soldierid != 0 || $soldierid != ""){
  285. $sql1 = "INSERT INTO carmanage (carid, soldierid) VALUES('".$carid."','".$soldierid."')";
  286. //print_r($sql1);
  287. //die();
  288. mysqli_query($con,$sql1);
  289. }
  290.  
  291. mysqli_close($con);
  292.  
  293. echo ("<script language='JavaScript'>
  294. alert('แก้ไขข้อมูลรถเรียบร้อย');
  295. window.location.href='manage_car.php';
  296. </script>");
  297.  
  298. }
  299.  
  300. function editTax($carid,$datetax,$dateexpiretax){
  301. //print_r($carid);
  302. //die();
  303. global $con;
  304.  
  305. $arrDate2 = explode("/", $datetax);
  306. $convert_datetax = $arrDate2[2].'-'.$arrDate2[1].'-'.$arrDate2[0];
  307. $arrDate3 = explode("/", $dateexpiretax);
  308. $convert_dateexpiretax = $arrDate3[2].'-'.$arrDate3[1].'-'.$arrDate3[0];
  309.  
  310. $sql = "UPDATE car SET datetax='".$convert_datetax."',dateexpiretax='".$convert_dateexpiretax."' WHERE carid = '".$carid."'";
  311. //print_r($sql);
  312. //die();
  313. mysqli_query($con,$sql);
  314.  
  315. mysqli_close($con);
  316.  
  317. echo ("<script language='JavaScript'>
  318. alert('แก้ไขข้อมูลรถเรียบร้อย');
  319. window.location.href='manage_car.php';
  320. </script>");
  321.  
  322. }
  323.  
  324. function deleteCar($carid){
  325. global $con;
  326.  
  327. //$res = mysqli_query($con,"SELECT * FROM news WHERE newsid = '".$newsid."'");
  328. //$result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  329.  
  330. mysqli_query($con,"DELETE FROM car WHERE carid='".$carid."'");
  331. mysqli_close($con);
  332. echo ("<script language='JavaScript'>
  333. alert('ลบข้อมูลเรียบร้อยแล้ว');
  334. window.location.href='manage_car.php';
  335. </script>");
  336.  
  337. }
  338.  
  339. function getSoldierInCar($carid){
  340. global $con;
  341. $sql = "SELECT * FROM soldier WHERE roleid = 4 AND soldierid not IN(SELECT soldierid as soldierid FROM car WHERE car.soldierid = soldier.soldierid )";
  342. $res = mysqli_query($con,$sql);
  343. $data = array();
  344. while($row = mysqli_fetch_assoc($res)) {
  345. $namesArray[] = array(
  346. 'id' => $row['id'],
  347. 'soldierid' => $row['soldierid'],
  348. 'name' => $row['name'],
  349. 'lastname' => $row['lastname'],
  350. 'nickname' => $row['nickname'],
  351. 'age' => $row['age'],
  352. 'soi' => $row['soi'],
  353. 'amphur' => $row['amphur'],
  354. 'tumbon' => $row['tumbon'],
  355. 'province' => $row['province'],
  356. 'zipcode' => $row['zipcode'],
  357. 'email' => $row['email'],
  358. 'tel' => $row['tel'],
  359. 'username' => $row['username'],
  360. 'password' => $row['password'],
  361. 'picture' => $row['picture'],
  362. 'sex' => $row['sex'],
  363. 'birthday' => $row['birthday'],
  364. 'idcard' => $row['idcard'],
  365. 'sroleid' => $row['sroleid'],
  366. 'spositionid' => $row['spositionid'],
  367. 'rolename' => $row['rolename'],
  368. 'scompanyid' => $row['scompanyid'],
  369. 'positionname' => $row['positionname'],
  370. 'companyname' => $row['companyname'],
  371. 'positionid' => $row['positionid']);
  372. }
  373.  
  374. $data = $namesArray;
  375.  
  376. return $data;
  377. mysqli_close($con);
  378.  
  379. }
  380.  
  381. function getAllCarModel(){
  382. global $con;
  383. $sql = "SELECT * FROM carmodel ORDER BY carmodelid DESC";
  384. $res = mysqli_query($con,$sql);
  385.  
  386. $data = array();
  387. while($row = mysqli_fetch_assoc($res)) {
  388. $namesArray[] = array(
  389. 'carmodelid' => $row['carmodelid'],
  390. 'carmodelname' => $row['carmodelname']);
  391. }
  392.  
  393. $data = $namesArray;
  394.  
  395. return $data;
  396. mysqli_close($con);
  397.  
  398. }
  399.  
  400. function getAllCarType(){
  401. global $con;
  402. $sql = "SELECT * FROM cartype ORDER BY cartypeid DESC";
  403. $res = mysqli_query($con,$sql);
  404. $data = array();
  405. while($row = mysqli_fetch_assoc($res)) {
  406. $namesArray[] = array(
  407. 'cartypeid' => $row['cartypeid'],
  408. 'cartypename' => $row['cartypename']);
  409. }
  410.  
  411. $data = $namesArray;
  412. return $data;
  413. mysqli_close($con);
  414.  
  415. }
  416.  
  417. function getCurrenttype($cartypelid){
  418.  
  419. global $con;
  420.  
  421. $res = mysqli_query($con,"SELECT * FROM cartype WHERE cartypeid = '".$cartypelid."'");
  422. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  423. return $result;
  424.  
  425. mysqli_close($con);
  426.  
  427. }
  428.  
  429. function edittype($cartypeid,$cartypename){
  430. global $con;
  431. mysqli_query($con,"UPDATE cartype SET cartypename ='".$cartypename."' WHERE cartypeid = '".$cartypeid."'");
  432. mysqli_query($con,$sql);
  433. mysqli_close($con);
  434. echo ("<script language='JavaScript'>
  435. alert('แก้ไขข้อมูลเรียบร้อยแล้ว');
  436. window.location.href='manage_modeltype.php';
  437. </script>");
  438. }
  439.  
  440. function getAllCar(){
  441. global $con;
  442. $sql = "SELECT *,c.soldierid as csoldierid
  443. FROM car c
  444. LEFT JOIN carmodel cm
  445. ON c.carmodelid = cm.carmodelid
  446. LEFT JOIN cartype ct
  447. ON c.cartypeid = ct.cartypeid
  448. LEFT JOIN soldier s
  449. ON c.soldierid = s.soldierid
  450. ORDER BY c.carid DESC";
  451. $res = mysqli_query($con,$sql);
  452.  
  453. $data = array();
  454. while($row = mysqli_fetch_assoc($res)) {
  455. $namesArray[] = array(
  456. 'carid' => $row['carid'],
  457. 'qrcode' => $row['qrcode'],
  458. 'dateregis' => $row['dateregis'],
  459. 'carnumber' => $row['carnumber'],
  460. 'carprovince' => $row['carprovince'],
  461. 'datetax' => $row['datetax'],
  462. 'maintenance' => $row['maintenance'],
  463. 'image_car' => $row['image_car'],
  464. 'dateexpiretax' => $row['dateexpiretax'],
  465. 'carmodelid' => $row['carmodelid'],
  466. 'carmodelname' => $row['carmodelname'],
  467. 'cartypename' => $row['cartypename'],
  468. 'name' => $row['name'],
  469. 'csoldierid' => $row['csoldierid'],
  470. 'lastname' => $row['lastname'],
  471. 'cartypeid' => $row['cartypeid']);
  472. }
  473.  
  474. $data = $namesArray;
  475.  
  476. return $data;
  477. mysqli_close($con);
  478.  
  479. }
  480.  
  481. function getCurrentCar($carid){
  482.  
  483. global $con;
  484. $sql = "SELECT *,c.soldierid as csoldierid
  485. FROM car c
  486. LEFT JOIN soldier s
  487. ON c.soldierid = s.soldierid
  488. WHERE c.carid = '".$carid."'";
  489. $res = mysqli_query($con,$sql);
  490.  
  491. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  492. return $result;
  493.  
  494. mysqli_close($con);
  495.  
  496. }
  497.  
  498. function getCurrentSoldierInCar($soldierid){
  499. global $con;
  500. // $sql = "SELECT * FROM soldier WHERE roleid = 4 AND id not IN(SELECT soldierid as soldierid FROM car WHERE car.soldierid = soldier.id AND car.soldierid <> '".$soldierid."')";
  501. $sql = "SELECT * FROM soldier WHERE roleid = 4 AND soldierid not IN(SELECT soldierid FROM car WHERE car.soldierid = soldier.soldierid AND car.soldierid <> '".$soldierid."')"; //เพิ่มใหม่
  502.  
  503. $res = mysqli_query($con,$sql);
  504.  
  505. $data = array();
  506. while($row = mysqli_fetch_assoc($res)) {
  507. $namesArray[] = array(
  508. 'id' => $row['id'],
  509. 'soldierid' => $row['soldierid'],
  510. 'name' => $row['name'],
  511. 'lastname' => $row['lastname'],
  512. 'nickname' => $row['nickname'],
  513. 'age' => $row['age'],
  514. 'soi' => $row['soi'],
  515. 'amphur' => $row['amphur'],
  516. 'tumbon' => $row['tumbon'],
  517. 'province' => $row['province'],
  518. 'zipcode' => $row['zipcode'],
  519. 'email' => $row['email'],
  520. 'tel' => $row['tel'],
  521. 'username' => $row['username'],
  522. 'password' => $row['password'],
  523. 'picture' => $row['picture'],
  524. 'sex' => $row['sex'],
  525. 'birthday' => $row['birthday'],
  526. 'idcard' => $row['idcard'],
  527. 'sroleid' => $row['sroleid'],
  528. 'spositionid' => $row['spositionid'],
  529. 'rolename' => $row['rolename'],
  530. 'scompanyid' => $row['scompanyid'],
  531. 'positionname' => $row['positionname'],
  532. 'companyname' => $row['companyname'],
  533. 'positionid' => $row['positionid']);
  534. }
  535.  
  536. $data = $namesArray;
  537.  
  538. return $data;
  539. mysqli_close($con);
  540.  
  541. }
  542.  
  543. // --------------- เพิ่มใหม่ -------
  544. function getCurrentSolCar($carid){
  545. global $con;
  546. $res = mysqli_query($con,"SELECT *,a.soldierid as solid FROM car a LEFT JOIN soldier b ON a.soldierid = b.id WHERE a.carid = '".$carid."'");
  547. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  548. return $result;
  549. mysqli_close($con);
  550. }
  551. // ---------------------------------
  552.  
  553. function getCurrentCarType($cartypeid){
  554. global $con;
  555.  
  556. $res = mysqli_query($con,"SELECT * FROM cartype WHERE cartypeid = '".$cartypeid."'");
  557. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  558. return $result;
  559.  
  560. mysqli_close($con);
  561.  
  562. }
  563.  
  564. function getCurrentCarModel($modelid){
  565. global $con;
  566.  
  567. $res = mysqli_query($con,"SELECT * FROM carmodel WHERE carmodelid = '".$modelid."'");
  568. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  569. return $result;
  570.  
  571. mysqli_close($con);
  572.  
  573. }
  574.  
  575. function getCurrentCarBySoldier($soldierid){
  576.  
  577. global $con;
  578. $sql = "SELECT * ,c.carid as ccid ,c.soldierid as csoldierid
  579. FROM car c
  580. LEFT JOIN soldier s
  581. ON c.soldierid = s.soldierid
  582. WHERE c.soldierid = '".$soldierid."'";
  583.  
  584. $res = mysqli_query($con,$sql);
  585. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  586. return $result;
  587.  
  588. mysqli_close($con);
  589.  
  590. }
  591. //----------------------------------------------End Car-----------------------------------------
  592.  
  593. //----------------------------------------------Start Soldier-----------------------------------------
  594. /*
  595. function runNumberSoldier(){
  596. global $con;
  597.  
  598. $res = mysqli_query($con,"SELECT id FROM soldier");
  599. $data = array();
  600. while($row = mysqli_fetch_array($res)) {
  601. $data['id'] = $row['id'];
  602. }
  603. $run = intval($data['id']);
  604. $run = $run+1;
  605. //print_r($run);
  606. //die();
  607. if($run=="")
  608. $run=1;
  609. $number_order = "S".sprintf('%05d', $run);
  610.  
  611. return $number_order;
  612. mysqli_close($con);
  613. } */
  614. function runNumberSoldier(){
  615. global $con;
  616.  
  617. $res = mysqli_query($con,"SELECT soldierid FROM soldier");
  618. $data = array();
  619. while($row = mysqli_fetch_array($res)) {
  620. $data['soldierid'] = $row['soldierid'];
  621. }
  622.  
  623. function extract_int($str){
  624. preg_match('/[^0-9]*([0-9]+)[^0-9]*/', $str, $regs);
  625. return (intval($regs[1]));
  626. }
  627. $run = intval(extract_int($data['soldierid']));
  628. $run = $run+1;
  629. //echo extract_int($data['soldierid']);
  630. // echo $run = intval(extract_int($data['soldierid']));
  631. // echo $run = $run+1;
  632. // print_r($run);
  633. // die();
  634.  
  635. if($run=="")
  636. $run=1;
  637. $number_order = "S".sprintf('%05d', $run);
  638.  
  639. return $number_order;
  640. mysqli_close($con);
  641. }
  642.  
  643.  
  644. function saveSoldier($soldierid,$name,$lastname,$nickname,$age,$address,$soi,$tumbon,$amphur,$province,$zipcode,$email,$tel,$username,$password,$picture,$sex,$birthday,$idcard,$companyid,$roleid,$positiontypeid,$positionid){
  645.  
  646.  
  647. global $con;
  648. $arrDate1 = explode("/", $birthday);
  649. $convert_birthdate = $arrDate1[2].'-'.$arrDate1[1].'-'.$arrDate1[0];
  650. /*
  651. if($picture != null){
  652. if(move_uploaded_file($_FILES["picture"]["tmp_name"],"images/soldier/".$_FILES["picture"]["name"]))
  653. {
  654.  
  655. $sql = "INSERT INTO soldier ( soldierid, name, lastname, nickname, age, address, soi, amphur, tumbon, province, zipcode, email, tel, username, password, picture, sex, birthday, idcard, roleid, positionid)
  656. VALUES('".$soldierid."','".$name."','".$lastname."','".$nickname."','".$age."','".$address."','".$soi."','".$amphur."','".$tumbon."','".$province."','".$zipcode."','".$email."','".$tel."','".$username."','".$password."','".$_FILES["picture"]["name"]."','".$sex."','".$convert_birthdate."','".$idcard."','".$roleid."','".$positionid."')";
  657. mysqli_query($con,$sql);
  658. }
  659. }*/
  660.  
  661. if($picture != null){
  662. if(move_uploaded_file($_FILES["picture"]["tmp_name"],"images/soldier/".$_FILES["picture"]["name"]))
  663. {
  664.  
  665. $sql = "INSERT INTO soldier ( soldierid, name, lastname, nickname, age, address, soi, amphur, tumbon, province, zipcode, email, tel, username, password, picture, sex, birthday, idcard, companyid, roleid, positiontypeid, positionid) VALUES('".$soldierid."','".$name."','".$lastname."','".$nickname."','".$age."','".$address."','".$soi."','".$amphur."','".$tumbon."','".$province."','".$zipcode."','".$email."','".$tel."','".$username."','".$password."','".$_FILES["picture"]["name"]."','".$sex."','".$convert_birthdate."','".$idcard."','".$companyid."','".$roleid."','".$positiontypeid."','".$positionid."')";
  666. //print_r($sql);
  667. //die();
  668. mysqli_query($con,$sql);
  669. }
  670. }else{
  671.  
  672. $sql = "INSERT INTO soldier ( soldierid, name, lastname, nickname, age, address, soi, amphur, tumbon, province, zipcode, email, tel, username, password, sex, birthday, idcard, companyid, roleid, positiontypeid, positionid) VALUES('".$soldierid."','".$name."','".$lastname."','".$nickname."','".$age."','".$address."','".$soi."','".$amphur."','".$tumbon."','".$province."','".$zipcode."','".$email."','".$tel."','".$username."','".$password."','".$sex."','".$convert_birthdate."','".$idcard."','".$companyid."','".$roleid."','".$positiontypeid."','".$positionid."')";
  673. mysqli_query($con,$sql);
  674. mysqli_close($con);
  675.  
  676. }
  677.  
  678. echo ("<script language='JavaScript'>
  679. alert('เพิ่มข้อมูลทหารเรียบร้อย');
  680. window.location.href='manage_soldier.php';
  681. </script>");
  682.  
  683. }
  684.  
  685. function editSoldier($id,$soldierid,$name,$lastname,$nickname,$age,$address,$soi,$tumbon,$amphur,$province,$zipcode,$email,$tel,$username,$password,$picture,$sex,$birthday,$idcard,$companyid,$roleid,$positiontypeid,$positionid){
  686. global $con;
  687.  
  688. $arrDate1 = explode("/", $birthday);
  689. $convert_birthdate = $arrDate1[2].'-'.$arrDate1[1].'-'.$arrDate1[0];
  690. if($picture != null){
  691. if(move_uploaded_file($_FILES["picture"]["tmp_name"],"images/soldier/".$_FILES["picture"]["name"]))
  692. {
  693. $sql="UPDATE soldier SET soldierid='".$soldierid."',name='".$name."',lastname='".$lastname."',nickname='".$nickname."',age='".$age."',address='".$address."',soi='".$soi."',tumbon='".$tumbon."',amphur='".$amphur."',province='".$province."',zipcode='".$zipcode."',email='".$email."',tel='".$tel."',username='".$username."',password='".$password."',picture='".$_FILES["picture"]["name"]."',sex='".$sex."',birthday='".$convert_birthdate."',idcard='".$idcard."',companyid='".$companyid."',roleid='".$roleid."',positiontypeid='".$positiontypeid."',positionid='".$positionid."' WHERE id = '".$id."'";
  694. //print_r($sql);
  695. //die();
  696. mysqli_query($con,$sql);
  697.  
  698. }
  699. }else{
  700. $sql = "UPDATE soldier SET soldierid='".$soldierid."',name='".$name."',lastname='".$lastname."',nickname='".$nickname."',age='".$age."',address='".$address."',soi='".$soi."',tumbon='".$tumbon."',amphur='".$amphur."',province='".$province."',zipcode='".$zipcode."',email='".$email."',tel='".$tel."',username='".$username."',password='".$password."',sex='".$sex."',birthday='".$convert_birthdate."',idcard='".$idcard."',companyid='".$companyid."',roleid='".$roleid."',positiontypeid='".$positiontypeid."',positionid='".$positionid."' WHERE id = '".$id."'";
  701. mysqli_query($con,$sql);
  702.  
  703. }
  704.  
  705. mysqli_close($con);
  706.  
  707. echo ("<script language='JavaScript'>
  708. alert('แก้ไขข้อมูลทหารเรียบร้อย');
  709. window.location.href='manage_soldier.php';
  710. </script>");
  711.  
  712. }
  713.  
  714. function deleteSoldier($id){
  715. global $con;
  716.  
  717. //$res = mysqli_query($con,"SELECT * FROM news WHERE newsid = '".$newsid."'");
  718. //$result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  719.  
  720. mysqli_query($con,"DELETE FROM soldier WHERE id='".$id."'");
  721. mysqli_close($con);
  722. echo ("<script language='JavaScript'>
  723. alert('ลบข้อมูลเรียบร้อยแล้ว');
  724. window.location.href='manage_soldier.php';
  725. </script>");
  726.  
  727. }
  728.  
  729. function getAllSoldier(){
  730. global $con;
  731. $sql = "SELECT * ,s.roleid as sroleid,s.positionid as spositionid
  732. FROM soldier s
  733. LEFT JOIN role r
  734. ON s.roleid = r.roleid
  735. LEFT JOIN position p
  736. ON s.positionid = p.positionid
  737. LEFT JOIN company c
  738. ON r.companyid = c.companyid
  739. ORDER BY s.id DESC";
  740. $res = mysqli_query($con,$sql);
  741.  
  742. $data = array();
  743. while($row = mysqli_fetch_assoc($res)) {
  744. $namesArray[] = array(
  745. 'id' => $row['id'],
  746. 'soldierid' => $row['soldierid'],
  747. 'name' => $row['name'],
  748. 'lastname' => $row['lastname'],
  749. 'nickname' => $row['nickname'],
  750. 'age' => $row['age'],
  751. 'soi' => $row['soi'],
  752. 'amphur' => $row['amphur'],
  753. 'tumbon' => $row['tumbon'],
  754. 'province' => $row['province'],
  755. 'zipcode' => $row['zipcode'],
  756. 'email' => $row['email'],
  757. 'tel' => $row['tel'],
  758. 'username' => $row['username'],
  759. 'password' => $row['password'],
  760. 'picture' => $row['picture'],
  761. 'sex' => $row['sex'],
  762. 'birthday' => $row['birthday'],
  763. 'idcard' => $row['idcard'],
  764. 'sroleid' => $row['sroleid'],
  765. 'spositionid' => $row['spositionid'],
  766. 'rolename' => $row['rolename'],
  767. 'scompanyid' => $row['scompanyid'],
  768. 'positionname' => $row['positionname'],
  769. 'companyname' => $row['companyname'],
  770. 'positionid' => $row['positionid']);
  771. }
  772.  
  773. $data = $namesArray;
  774.  
  775. return $data;
  776. mysqli_close($con);
  777.  
  778. }
  779.  
  780. function getAllSoldierLeaderduty(){
  781. global $con;
  782. $sql = "SELECT * ,s.roleid as sroleid,s.positionid as spositionid
  783. FROM soldier s
  784. LEFT JOIN role r
  785. ON s.roleid = r.roleid
  786. LEFT JOIN position p
  787. ON s.positionid = p.positionid
  788. LEFT JOIN company c
  789. ON r.companyid = c.companyid
  790. WHERE s.roleid<>1 AND s.positiontypeid =1
  791. ORDER BY s.id DESC";
  792. $res = mysqli_query($con,$sql);
  793.  
  794. $data = array();
  795. while($row = mysqli_fetch_assoc($res)) {
  796. $namesArray[] = array(
  797. 'id' => $row['id'],
  798. 'soldierid' => $row['soldierid'],
  799. 'name' => $row['name'],
  800. 'lastname' => $row['lastname'],
  801. 'nickname' => $row['nickname'],
  802. 'age' => $row['age'],
  803. 'soi' => $row['soi'],
  804. 'amphur' => $row['amphur'],
  805. 'tumbon' => $row['tumbon'],
  806. 'province' => $row['province'],
  807. 'zipcode' => $row['zipcode'],
  808. 'email' => $row['email'],
  809. 'tel' => $row['tel'],
  810. 'username' => $row['username'],
  811. 'password' => $row['password'],
  812. 'picture' => $row['picture'],
  813. 'sex' => $row['sex'],
  814. 'birthday' => $row['birthday'],
  815. 'idcard' => $row['idcard'],
  816. 'sroleid' => $row['sroleid'],
  817. 'spositionid' => $row['spositionid'],
  818. 'rolename' => $row['rolename'],
  819. 'scompanyid' => $row['scompanyid'],
  820. 'positionname' => $row['positionname'],
  821. 'companyname' => $row['companyname'],
  822. 'positionid' => $row['positionid']);
  823. }
  824.  
  825. $data = $namesArray;
  826.  
  827. return $data;
  828. mysqli_close($con);
  829.  
  830. }
  831.  
  832. function getAllSoldierduty(){
  833. global $con;
  834. $sql = "SELECT * ,s.roleid as sroleid,s.positionid as spositionid
  835. FROM soldier s
  836. LEFT JOIN role r
  837. ON s.roleid = r.roleid
  838. LEFT JOIN position p
  839. ON s.positionid = p.positionid
  840. LEFT JOIN company c
  841. ON r.companyid = c.companyid
  842. WHERE s.roleid<>1 AND s.positiontypeid = 2
  843. ORDER BY s.id DESC";
  844. $res = mysqli_query($con,$sql);
  845.  
  846. $data = array();
  847. while($row = mysqli_fetch_assoc($res)) {
  848. $namesArray[] = array(
  849. 'id' => $row['id'],
  850. 'soldierid' => $row['soldierid'],
  851. 'name' => $row['name'],
  852. 'lastname' => $row['lastname'],
  853. 'nickname' => $row['nickname'],
  854. 'age' => $row['age'],
  855. 'soi' => $row['soi'],
  856. 'amphur' => $row['amphur'],
  857. 'tumbon' => $row['tumbon'],
  858. 'province' => $row['province'],
  859. 'zipcode' => $row['zipcode'],
  860. 'email' => $row['email'],
  861. 'tel' => $row['tel'],
  862. 'username' => $row['username'],
  863. 'password' => $row['password'],
  864. 'picture' => $row['picture'],
  865. 'sex' => $row['sex'],
  866. 'birthday' => $row['birthday'],
  867. 'idcard' => $row['idcard'],
  868. 'sroleid' => $row['sroleid'],
  869. 'spositionid' => $row['spositionid'],
  870. 'rolename' => $row['rolename'],
  871. 'scompanyid' => $row['scompanyid'],
  872. 'positionname' => $row['positionname'],
  873. 'companyname' => $row['companyname'],
  874. 'positionid' => $row['positionid']);
  875. }
  876.  
  877. $data = $namesArray;
  878.  
  879. return $data;
  880. mysqli_close($con);
  881.  
  882. }
  883.  
  884. function getCurrentSoldier($id){
  885.  
  886. global $con;
  887.  
  888. $res = mysqli_query($con,"SELECT * FROM soldier WHERE id = '".$id."'");
  889. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  890. return $result;
  891.  
  892. mysqli_close($con);
  893.  
  894. }
  895.  
  896. function getAllSearchSoldier($companyid,$roleid,$positiontypeid,$positionid,$searchText){
  897. global $con;
  898. if ($companyid != 0 && $roleid == 0 && $positiontypeid == 0 && $positionid == 0 ) {
  899. $whereClause = "WHERE s.companyid = '".$companyid."' ";
  900. }else if($companyid != 0 && $roleid != 0 && $positiontypeid == 0 && $positionid == 0){
  901. $whereClause = "WHERE s.companyid = '".$companyid."' AND s.roleid = '".$roleid."'";
  902. }else if($companyid != 0 && $roleid != 0 && $positiontypeid != 0 && $positionid == 0){
  903. $whereClause = "WHERE s.companyid = '".$companyid."' AND s.roleid = '".$roleid."' AND s.positiontypeid = '".$positiontypeid."'";
  904. }else if($companyid != 0 && $roleid != 0 && $positiontypeid != 0 && $positionid != 0){
  905. $whereClause = "WHERE s.companyid = '".$companyid."' AND s.roleid = '".$roleid."' AND s.positiontypeid = '".$positiontypeid."' AND s.positionid = '".$positionid."'";
  906. }else if($companyid == 0 && $roleid != 0 && $positiontypeid == 0 && $positionid == 0){
  907. $whereClause = "WHERE s.roleid = '".$roleid."' ";
  908. }else if($companyid == 0 && $roleid == 0 && $positiontypeid != 0 && $positionid == 0){
  909. $whereClause = "WHERE s.positiontypeid = '".$positiontypeid."' ";
  910. }else if($companyid == 0 && $roleid == 0 && $positiontypeid == 0 && $positionid != 0){
  911. $whereClause = "WHERE s.positionid = '".$positionid."' ";
  912. }else if($companyid == 0 && $roleid != 0 && $positiontypeid != 0 && $positionid == 0){
  913. $whereClause = "WHERE s.roleid = '".$roleid."' AND s.positiontypeid = '".$positiontypeid."' ";
  914. }else if($companyid == 0 && $roleid == 0 && $positiontypeid != 0 && $positionid != 0){
  915. $whereClause = "WHERE s.positiontypeid = '".$positiontypeid."' AND s.positionid = '".$positionid."' ";
  916. }else if($companyid != 0 && $roleid == 0 && $positiontypeid == 0 && $positionid != 0){
  917. $whereClause = "WHERE s.companyid = '".$companyid."' AND s.positionid = '".$positionid."' "; }
  918. else if($companyid != 0 && $roleid != 0 && $positiontypeid == 0 && $positionid != 0){
  919. $whereClause = "WHERE s.roleid = '".$roleid."' AND s.companyid = '".$companyid."' AND s.positionid = '".$positionid."'"; }
  920.  
  921. //if ($companyid == 0 && $roleid == 0 && $positiontypeid == 0 && $positionid == 0 ) {
  922. $sql = "SELECT * ,s.roleid as sroleid,s.positionid as spositionid
  923. FROM soldier s
  924. LEFT JOIN role r
  925. ON s.roleid = r.roleid
  926. LEFT JOIN position p
  927. ON s.positionid = p.positionid
  928. LEFT JOIN company c
  929. ON r.companyid = c.companyid ".$whereClause."
  930. ORDER BY s.id DESC"; //print_r($sql); die();
  931. $res = mysqli_query($con,$sql);
  932. //}
  933.  
  934.  
  935. /*
  936. $sql ="SELECT * FROM soldier
  937. WHERE companyid = '".$companyid."' and roleid = '".$roleid."' and positiontypeid = '".$positiontypeid."' and positionid = '".$positionid."' and name LIKE '%".$searchText."%' or lastname LIKE '%".$searchText."%'
  938. ORDER BY id DESC"; */
  939.  
  940. // print_r($sql);
  941. // die();
  942.  
  943. $data = array();
  944. while($row = mysqli_fetch_assoc($res)) {
  945. $namesArray[] = array(
  946. 'id' => $row['id'],
  947. 'soldierid' => $row['soldierid'],
  948. 'name' => $row['name'],
  949. 'lastname' => $row['lastname'],
  950. 'nickname' => $row['nickname'],
  951. 'age' => $row['age'],
  952. 'soi' => $row['soi'],
  953. 'amphur' => $row['amphur'],
  954. 'tumbon' => $row['tumbon'],
  955. 'province' => $row['province'],
  956. 'zipcode' => $row['zipcode'],
  957. 'email' => $row['email'],
  958. 'tel' => $row['tel'],
  959. 'username' => $row['username'],
  960. 'password' => $row['password'],
  961. 'picture' => $row['picture'],
  962. 'sex' => $row['sex'],
  963. 'birthday' => $row['birthday'],
  964. 'idcard' => $row['idcard'],
  965. 'sroleid' => $row['sroleid'],
  966. 'spositionid' => $row['spositionid'],
  967. 'rolename' => $row['rolename'],
  968. 'scompanyid' => $row['scompanyid'],
  969. 'positionname' => $row['positionname'],
  970. 'companyname' => $row['companyname'],
  971. 'positionid' => $row['positionid']);
  972. }
  973.  
  974. $data = $namesArray;
  975.  
  976. return $data;
  977. mysqli_close($con);
  978.  
  979. }
  980.  
  981. //----------------------------------------------End Soldier-----------------------------------------
  982.  
  983. //----------------------------------------------Start Duty---------------------------------------
  984.  
  985. function getCheckMonthDuty(){
  986.  
  987. $now_month = date("m");
  988. $now_year = date("Y");
  989. $convert_year = $now_year + 543;
  990. $date_query = $convert_year."-".$now_month;
  991.  
  992. global $con;
  993. $sql = "SELECT * FROM duty WHERE YEAR(duty_date) = '".$convert_year."' AND MONTH(duty_date) = '".$now_month."'";
  994. $res = mysqli_query($con,$sql);
  995. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  996. return $result;
  997.  
  998. mysqli_close($con);
  999.  
  1000. }
  1001.  
  1002. function getAllDuty(){
  1003. global $con;
  1004. // $sql = "SELECT * FROM duty ORDER BY dutyid DESC";
  1005. $sql = "SELECT * FROM duty ORDER BY duty_date DESC";
  1006.  
  1007. $res = mysqli_query($con,$sql);
  1008.  
  1009. $data = array();
  1010. while($row = mysqli_fetch_assoc($res)) {
  1011. $namesArray[] = array(
  1012. 'dutyid' => $row['dutyid'],
  1013. 'duty_date' => $row['duty_date']);
  1014. }
  1015.  
  1016. $data = $namesArray;
  1017.  
  1018. return $data;
  1019. mysqli_close($con);
  1020.  
  1021. }
  1022.  
  1023. function getCurrentDuty($dutyid){
  1024.  
  1025. global $con;
  1026.  
  1027. $res = mysqli_query($con,"SELECT * FROM duty WHERE dutyid = '".$dutyid."'");
  1028. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1029. return $result;
  1030.  
  1031. mysqli_close($con);
  1032.  
  1033. }
  1034.  
  1035. function getAllHeadSoldierInDuty(){
  1036. global $con;
  1037. $sql = "SELECT *
  1038. FROM soldier
  1039. WHERE positionid = 1 or positionid = 2 or positionid = 3 or positionid = 4 or positionid = 5 or positionid = 6
  1040. ORDER BY id DESC";
  1041. $res = mysqli_query($con,$sql);
  1042.  
  1043. $data = array();
  1044. while($row = mysqli_fetch_assoc($res)) {
  1045. $namesArray[] = array(
  1046. 'id' => $row['id'],
  1047. 'soldierid' => $row['soldierid'],
  1048. 'name' => $row['name'],
  1049. 'lastname' => $row['lastname'],
  1050. 'nickname' => $row['nickname'],
  1051. 'age' => $row['age'],
  1052. 'soi' => $row['soi'],
  1053. 'amphur' => $row['amphur'],
  1054. 'tumbon' => $row['tumbon'],
  1055. 'province' => $row['province'],
  1056. 'zipcode' => $row['zipcode'],
  1057. 'email' => $row['email'],
  1058. 'tel' => $row['tel'],
  1059. 'username' => $row['username'],
  1060. 'password' => $row['password'],
  1061. 'picture' => $row['picture'],
  1062. 'sex' => $row['sex'],
  1063. 'birthday' => $row['birthday'],
  1064. 'idcard' => $row['idcard'],
  1065. 'sroleid' => $row['sroleid'],
  1066. 'spositionid' => $row['spositionid'],
  1067. 'rolename' => $row['rolename'],
  1068. 'scompanyid' => $row['scompanyid'],
  1069. 'positionname' => $row['positionname'],
  1070. 'companyname' => $row['companyname'],
  1071. 'positionid' => $row['positionid']);
  1072. }
  1073.  
  1074. $data = $namesArray;
  1075.  
  1076. return $data;
  1077. mysqli_close($con);
  1078.  
  1079. }
  1080.  
  1081. function getAllHeadSoldierInDutyByDutyid($duty_id){ // คิวนี่หาหัว
  1082.  
  1083. global $con;
  1084. $sql = "SELECT *
  1085. FROM duty_leader
  1086. WHERE dutyid = '".$duty_id."'";
  1087. $res = mysqli_query($con,$sql);
  1088. $data = array();
  1089. while($row = mysqli_fetch_assoc($res)) {
  1090. $namesArray[] = array(
  1091. 'duty_leader_id' => $row['duty_leader_id'],
  1092. 'dutyid' => $row['dutyid'],
  1093. 'soldierid' => $row['soldierid'],
  1094. 'date_in' => $row['date_in'],
  1095. 'date_out' => $row['date_out'],
  1096. 'time_in' => $row['time_in'],
  1097. 'time_out' => $row['time_out']);
  1098. }
  1099.  
  1100. $data = $namesArray;
  1101.  
  1102. return $data;
  1103. mysqli_close($con);
  1104.  
  1105. }
  1106.  
  1107. function getAllSoldierInDuty(){
  1108. global $con;
  1109. $sql = "SELECT *
  1110. FROM soldier
  1111. WHERE positionid = 7 or positionid = 8 or positionid = 9 or positionid = 10 or positionid = 11 or positionid = 12
  1112. ORDER BY id DESC";
  1113. $res = mysqli_query($con,$sql);
  1114.  
  1115. $data = array();
  1116. while($row = mysqli_fetch_assoc($res)) {
  1117. $namesArray[] = array(
  1118. 'id' => $row['id'],
  1119. 'soldierid' => $row['soldierid'],
  1120. 'name' => $row['name'],
  1121. 'lastname' => $row['lastname'],
  1122. 'nickname' => $row['nickname'],
  1123. 'age' => $row['age'],
  1124. 'soi' => $row['soi'],
  1125. 'amphur' => $row['amphur'],
  1126. 'tumbon' => $row['tumbon'],
  1127. 'province' => $row['province'],
  1128. 'zipcode' => $row['zipcode'],
  1129. 'email' => $row['email'],
  1130. 'tel' => $row['tel'],
  1131. 'username' => $row['username'],
  1132. 'password' => $row['password'],
  1133. 'picture' => $row['picture'],
  1134. 'sex' => $row['sex'],
  1135. 'birthday' => $row['birthday'],
  1136. 'idcard' => $row['idcard'],
  1137. 'sroleid' => $row['sroleid'],
  1138. 'spositionid' => $row['spositionid'],
  1139. 'rolename' => $row['rolename'],
  1140. 'scompanyid' => $row['scompanyid'],
  1141. 'positionname' => $row['positionname'],
  1142. 'companyname' => $row['companyname'],
  1143. 'positionid' => $row['positionid']);
  1144. }
  1145.  
  1146. $data = $namesArray;
  1147.  
  1148. return $data;
  1149. mysqli_close($con);
  1150.  
  1151. }
  1152.  
  1153. function getAllSoldierInDutyByDutyid($duty_id){
  1154.  
  1155. global $con;
  1156. $sql = "SELECT *
  1157. FROM duty_soldier
  1158. WHERE dutyid = '".$duty_id."'";
  1159. $res = mysqli_query($con,$sql);
  1160. $data = array();
  1161. while($row = mysqli_fetch_assoc($res)) {
  1162. $namesArray[] = array(
  1163. 'duty_sol_id' => $row['duty_sol_id'],
  1164. 'dutyid' => $row['dutyid'],
  1165. 'soldierid' => $row['soldierid'],
  1166. 'date_in' => $row['date_in'],
  1167. 'date_out' => $row['date_out'],
  1168. 'time_in' => $row['time_in'],
  1169. 'time_out' => $row['time_out']);
  1170. }
  1171.  
  1172. $data = $namesArray;
  1173.  
  1174. return $data;
  1175. mysqli_close($con);
  1176.  
  1177. }
  1178.  
  1179. function saveDuty($duty_date,$hsoldierid,$hdate_in,$hdate_out,$htime_in,$htime_out,$soldierid,$date_in,$date_out,$time_in,$time_out){
  1180. global $con;
  1181. $arrDate1 = explode("/", $duty_date);
  1182. $convert_duty_date = $arrDate1[2].'-'.$arrDate1[1].'-'.$arrDate1[0];
  1183.  
  1184.  
  1185. $sql ="INSERT INTO duty (duty_date) VALUES('".$convert_duty_date."')";
  1186. mysqli_query($con,$sql);
  1187.  
  1188. $last_id = $con->insert_id;
  1189.  
  1190. foreach( $hsoldierid as $key => $hsol ) {
  1191. if ($hsol != "") {
  1192.  
  1193. $arrDate2 = explode("/", $hdate_in[$key]);
  1194. $convert_hdate_in = ($arrDate2[2]-543).'-'.$arrDate2[1].'-'.$arrDate2[0];
  1195. $arrDate3 = explode("/", $hdate_out[$key]);
  1196. $convert_hdate_out = ($arrDate3[2]-543).'-'.$arrDate3[1].'-'.$arrDate3[0];
  1197. $hti = $htime_in[$key];
  1198. $hto = $htime_out[$key];
  1199. $sql2 = "INSERT INTO duty_leader (dutyid,soldierid,date_in,date_out,time_in,time_out) VALUES ('".$last_id."','".$hsol."','".$convert_hdate_in."','".$convert_hdate_out."','".$hti."','".$hto."')";
  1200. //echo $sql2.'<br/>';
  1201. $query = mysqli_query($con,$sql2);
  1202.  
  1203. }
  1204. }
  1205.  
  1206. foreach( $soldierid as $key => $sol ) {
  1207. if ($sol != "") {
  1208. //$di = $date_in[$key];
  1209. $arrDate4 = explode("/", $date_in[$key]);
  1210. $convert_date_in = ($arrDate4[2]-543).'-'.$arrDate4[1].'-'.$arrDate4[0];
  1211. //$do = $date_out[$key];
  1212. $arrDate5 = explode("/", $date_out[$key]);
  1213. $convert_date_out = ($arrDate5[2]-543).'-'.$arrDate5[1].'-'.$arrDate5[0];
  1214. $ti = $time_in[$key];
  1215. $to = $time_out[$key];
  1216. $sql3 = "INSERT INTO duty_soldier (dutyid,soldierid,date_in,date_out,time_in,time_out) VALUES ('".$last_id."','".$sol."','".$convert_date_in."','".$convert_date_out."','".$ti."','".$to."')";
  1217. //echo $sql3.'<br/>';
  1218. $query = mysqli_query($con,$sql3);
  1219. }
  1220. }
  1221.  
  1222. mysqli_close($con);
  1223. //exit;
  1224. echo ("<script language='JavaScript'>
  1225. alert('บันทึกมูลเรียบร้อยแล้ว');
  1226. window.location.href='manage_duty.php';
  1227. </script>");
  1228.  
  1229.  
  1230. }
  1231.  
  1232. function editDuty($dutyid,$hsoldierid,$hdate_in,$hdate_out,$htime_in,$htime_out,$soldierid,$date_in,$date_out,$time_in,$time_out){
  1233. global $con;
  1234. /*
  1235. $check= array();
  1236. for ($i=0; $i<count($hsoldierid); $i++) {
  1237. $check[$hsoldierid[$i]]++; //mark array
  1238. if ($check[$hsoldierid[$i]]<=2){
  1239. echo ("<script language='JavaScript'>
  1240. alert('มีรายชื่อที่ซ้ำกันมากกว่า 2 วัน');
  1241. window.location.href='edit_duty.php?dutyid=$dutyid';
  1242. </script>");
  1243. //echo "รายการ $datas[$i] ซ้ำกัน<br />"
  1244. }else{
  1245. echo ("<script language='JavaScript'>
  1246. alert('น้อยกว่า 2 วันทุกตัวบันทึกได้');
  1247. window.location.href='edit_duty.php?dutyid=$dutyid';
  1248. </script>");
  1249. }
  1250.  
  1251. }
  1252. */
  1253.  
  1254. $delete_sql_leader ="DELETE FROM duty_leader WHERE dutyid = '".$dutyid."'";
  1255. mysqli_query($con,$delete_sql_leader);
  1256. $delete_sql_soldier ="DELETE FROM duty_soldier WHERE dutyid = '".$dutyid."'";
  1257. mysqli_query($con,$delete_sql_soldier);
  1258.  
  1259. foreach( $hsoldierid as $key => $hsol ) {
  1260. if ($hsol != "") {
  1261.  
  1262. $arrDate2 = explode("/", $hdate_in[$key]);
  1263. $convert_hdate_in = $arrDate2[2].'-'.$arrDate2[1].'-'.$arrDate2[0];
  1264. $arrDate3 = explode("/", $hdate_out[$key]);
  1265. $convert_hdate_out = $arrDate3[2].'-'.$arrDate3[1].'-'.$arrDate3[0];
  1266. $hti = $htime_in[$key];
  1267. $hto = $htime_out[$key];
  1268. $sql2 = "INSERT INTO duty_leader (dutyid,soldierid,date_in,date_out,time_in,time_out) VALUES ('".$dutyid."','".$hsol."','".$convert_hdate_in."','".$convert_hdate_out."','".$hti."','".$hto."')";
  1269. $query = mysqli_query($con,$sql2);
  1270.  
  1271. }
  1272. }
  1273.  
  1274. foreach( $soldierid as $key => $sol ) {
  1275. if ($sol != "") {
  1276. //$di = $date_in[$key];
  1277. $arrDate4 = explode("/", $date_in[$key]);
  1278. $convert_date_in = $arrDate4[2].'-'.$arrDate4[1].'-'.$arrDate4[0];
  1279. //$do = $date_out[$key];
  1280. $arrDate5 = explode("/", $date_out[$key]);
  1281. $convert_date_out = $arrDate5[2].'-'.$arrDate5[1].'-'.$arrDate5[0];
  1282. $ti = $time_in[$key];
  1283. $to = $time_out[$key];
  1284. $sql3 = "INSERT INTO duty_soldier (dutyid,soldierid,date_in,date_out,time_in,time_out) VALUES ('".$dutyid."','".$sol."','".$convert_date_in."','".$convert_date_out."','".$ti."','".$to."')";
  1285. $query = mysqli_query($con,$sql3);
  1286. }
  1287. }
  1288.  
  1289. mysqli_close($con);
  1290. echo ("<script language='JavaScript'>
  1291. alert('บันทึกมูลเรียบร้อยแล้ว');
  1292. window.location.href='manage_duty.php';
  1293. </script>");
  1294.  
  1295.  
  1296. }
  1297.  
  1298. function getAllDutyLeader($dutyid){
  1299. global $con;
  1300. $sql = "SELECT *,d.soldierid as dsoldierid
  1301. FROM duty_leader d
  1302. LEFT JOIN soldier s
  1303. ON d.soldierid = s.soldierid
  1304. WHERE d.dutyid = '".$dutyid."'
  1305. ORDER BY d.date_in ASC"; //
  1306. $res = mysqli_query($con,$sql);
  1307.  
  1308. $data = array();
  1309. while($row = mysqli_fetch_assoc($res)) {
  1310. $namesArray[] = array(
  1311. 'duty_leader_id' => $row['duty_leader_id'],
  1312. 'dutyid' => $row['dutyid'],
  1313. 'name' => $row['name'],
  1314. 'lastname' => $row['lastname'],
  1315. 'soldierid' => $row['soldierid'],
  1316. 'date_in' => $row['date_in'],
  1317. 'date_out' => $row['date_out'],
  1318. 'dsoldierid' => $row['dsoldierid'],
  1319. 'time_out' => $row['time_out'],
  1320. 'time_in' => $row['time_in']);
  1321. }
  1322.  
  1323. $data = $namesArray;
  1324.  
  1325. return $data;
  1326. mysqli_close($con);
  1327.  
  1328. }
  1329.  
  1330. function getAllDutySoldier($dutyid){
  1331. global $con;
  1332. $sql = "SELECT * ,ds.soldierid as dssoldierid
  1333. FROM duty_soldier ds
  1334. LEFT JOIN soldier s
  1335. ON ds.soldierid = s.soldierid
  1336. WHERE ds.dutyid = '".$dutyid."'
  1337. ORDER BY ds.date_in ASC"; //print_r($sql); die();//
  1338. $res = mysqli_query($con,$sql);
  1339.  
  1340. $data = array();
  1341. while($row = mysqli_fetch_assoc($res)) {
  1342. $namesArray[] = array(
  1343. 'duty_sol_id' => $row['duty_sol_id'],
  1344. 'dutyid' => $row['dutyid'],
  1345. 'name' => $row['name'],
  1346. 'lastname' => $row['lastname'],
  1347. 'soldierid' => $row['soldierid'],
  1348. 'date_in' => $row['date_in'],
  1349. 'date_out' => $row['date_out'],
  1350. 'dssoldierid' => $row['dssoldierid'],
  1351. 'time_out' => $row['time_out'],
  1352. 'time_in' => $row['time_in']);
  1353. }
  1354.  
  1355. $data = $namesArray;
  1356.  
  1357. return $data;
  1358. mysqli_close($con);
  1359.  
  1360. }
  1361.  
  1362. function getLeaderSoldierInDuty(){
  1363. $currentmonth = date('m');
  1364. $month1 = date('m',strtotime('first day of +1 month'));
  1365. $d=cal_days_in_month(CAL_GREGORIAN,$month1,date("Y"));
  1366. //print_r($month1);
  1367. //die();
  1368. $data = array();
  1369. global $con;
  1370. $sql_check = "select * from duty_leader WHERE MONTH(duty_leader.date_in) = '".$currentmonth."'";
  1371. //print_r($sql_check);
  1372. //die();
  1373. // เช็คว่าสร้างไปแล้วหรือยังง
  1374. $res = mysqli_query($con,$sql_check);
  1375.  
  1376.  
  1377. while($row = mysqli_fetch_array($res)) {
  1378. $data['duty_leader_id'] = $row['duty_leader_id'];
  1379. $data['soldierid'] = $row['soldierid'];
  1380.  
  1381.  
  1382.  
  1383. }
  1384. if (empty($data)) { //ยังไม่ได้สร้าง
  1385.  
  1386. $sql_data_empty = "SELECT *
  1387. FROM soldier
  1388. WHERE roleid <> 1 AND soldier.positiontypeid = 1 ORDER BY id ASC";
  1389. $res2 = mysqli_query($con,$sql_data_empty);
  1390.  
  1391. while($row2 = mysqli_fetch_assoc($res2)) {
  1392. $namesArray[] = array(
  1393. 'id' => $row2['id'],
  1394. 'soldierid' => $row2['soldierid'],
  1395. 'positionid' => $row2['positionid']);
  1396. }
  1397. $rowcount_sql_data_empty=mysqli_num_rows($res2);
  1398.  
  1399. $balance_data_empty = $d-$rowcount_sql_data_empty; // มีทั้งหมดกี่คนดึงออกมาก่อน
  1400.  
  1401. if($balance_data_empty != 0){ //ถ้าไม่พอไปดึงคนที่หนึ่งมาใหม่
  1402. $sql_data_empty2 = "SELECT *
  1403. FROM soldier
  1404. WHERE roleid <> 1 AND positiontypeid = 1 ORDER BY id ASC limit 0,".$balance_data_empty;
  1405. $res_data_empty2 = mysqli_query($con,$sql_data_empty2);
  1406.  
  1407. while($row_res_data_empty2 = mysqli_fetch_assoc($res_data_empty2)) {
  1408. $namesArray[] = array(
  1409. 'id' => $row_res_data_empty2['id'],
  1410. 'soldierid' => $row_res_data_empty2['soldierid'],
  1411. 'positionid' => $row_res_data_empty2['positionid']);
  1412. }
  1413. $rowcount_sql_data_empty2 = mysqli_num_rows($res_data_empty2);
  1414. //$row_data_empty2 = $row_res_data_empty2->num_rows;
  1415. $balance_data_empty2 = $balance_data_empty-$rowcount_sql_data_empty2;
  1416.  
  1417. if($balance_data_empty2 != 0){
  1418. $sql_data_empty3 = "SELECT * FROM soldier
  1419. WHERE roleid <> 1 AND positiontypeid = 1 ORDER BY id ASC limit 0,".$balance_data_empty2;
  1420. $res_data_empty3 = mysqli_query($con,$sql_data_empty3);
  1421.  
  1422. while($row_res_data_empty3 = mysqli_fetch_assoc($res_data_empty3)) {
  1423. $namesArray[] = array(
  1424. 'id' => $row_res_data_empty3['id'],
  1425. 'soldierid' => $row_res_data_empty3['soldierid'],
  1426. 'positionid' => $row_res_data_empty3['positionid']);
  1427. }
  1428. $rowcount_sql_data_empty3 = mysqli_num_rows($res_data_empty3);
  1429. //$row_data_empty2 = $row_res_data_empty2->num_rows;
  1430. $balance_data_empty3 = $balance_data_empty2-$rowcount_sql_data_empty3;
  1431. //ลบกันไปหาจนกว่าจะเหลือ 0
  1432. }
  1433.  
  1434. }
  1435.  
  1436. $data = $namesArray;
  1437.  
  1438. return $data;
  1439.  
  1440.  
  1441.  
  1442. }else{ //คนไหนที่เคยทำไปแล้ว
  1443. // หาคนจากเดือนที่แล้วมา
  1444. $data2 = array();
  1445. $sql_check_intersect = "SELECT *
  1446. FROM soldier
  1447. WHERE soldier.roleid <> 1 AND soldier.positiontypeid = 1 AND soldierid NOT IN(SELECT soldierid FROM duty_leader WHERE MONTH(duty_leader.date_in) = '".$currentmonth."' )
  1448. ORDER BY id ASC";
  1449.  
  1450. $res_check_intersect = mysqli_query($con,$sql_check_intersect);
  1451.  
  1452. while($row_intersect = mysqli_fetch_assoc($res_check_intersect)) {
  1453. $namesArray[] = array(
  1454. 'id' => $row_intersect['id'],
  1455. 'soldierid' => $row_intersect['soldierid'],
  1456. 'positionid' => $row_intersect['positionid']);
  1457. }
  1458. $row_cnt = mysqli_num_rows($res_check_intersect);
  1459.  
  1460. $balance_row = $d-$row_cnt;
  1461.  
  1462.  
  1463. if($balance_row != 0 ){
  1464.  
  1465. $sql2 = "SELECT *
  1466. FROM soldier
  1467. WHERE roleid <> 1 AND positiontypeid = 1
  1468. ORDER BY id ASC LIMIT 0,".$balance_row;
  1469. $res2 = mysqli_query($con,$sql2);
  1470.  
  1471. while($row = mysqli_fetch_assoc($res2)) {
  1472. $namesArray[] = array(
  1473. 'id' => $row['id'],
  1474. 'soldierid' => $row['soldierid'],
  1475. 'positionid' => $row['positionid']);
  1476. }
  1477.  
  1478. $row_sql2 = mysqli_num_rows($res2);
  1479.  
  1480. $balance_sql2 = $balance_row-$row_sql2;
  1481.  
  1482. if($balance_sql2 != 0){
  1483. $sql3 = "SELECT *
  1484. FROM soldier
  1485. WHERE roleid <> 1 AND soldier.positiontypeid = 1
  1486. ORDER BY id ASC LIMIT 0,".$balance_sql2;
  1487.  
  1488. $res3 = mysqli_query($con,$sql3);
  1489.  
  1490. $row_cnt2 = $res->num_rows;
  1491.  
  1492. while($row = mysqli_fetch_assoc($res3)) {
  1493. $namesArray[] = array(
  1494. 'id' => $row['id'],
  1495. 'soldierid' => $row['soldierid'],
  1496. 'positionid' => $row['positionid']);
  1497. }
  1498. $row_sql3 = mysqli_num_rows($res3);
  1499.  
  1500. $balance_sql3 = $balance_sql2-$row_sql3;
  1501.  
  1502. if($balance_sql3 != 0){
  1503. $sql4 = "SELECT *
  1504. FROM soldier
  1505. WHERE roleid <> 1 AND soldier.positiontypeid = 1
  1506. ORDER BY id ASC LIMIT 0,".$balance_sql3;
  1507.  
  1508. $res4 = mysqli_query($con,$sql4);
  1509.  
  1510. while($row4 = mysqli_fetch_assoc($res4)) {
  1511. $namesArray[] = array(
  1512. 'id' => $row4['id'],
  1513. 'soldierid' => $row4['soldierid'],
  1514. 'positionid' => $row4['positionid']);
  1515. }
  1516. $row_sql4 = mysqli_num_rows($res4);
  1517.  
  1518. $balance_sql4 = $balance_sql3-$row_sql4;
  1519.  
  1520.  
  1521. }
  1522.  
  1523.  
  1524. }
  1525.  
  1526. $data2 = $namesArray;
  1527. return $data2;
  1528. }
  1529.  
  1530. }
  1531.  
  1532. mysqli_close($con);
  1533.  
  1534. } // close fucntion getLeaderSoldierInDuty
  1535.  
  1536. function getSoldierInDuty(){
  1537. $currentmonth = date('m');
  1538. $month1 = date('m',strtotime('first day of +1 month'));
  1539. $d=cal_days_in_month(CAL_GREGORIAN,$month1,date("Y"));
  1540. //print_r($month1);
  1541. //die();
  1542. $data = array();
  1543. global $con;
  1544. $sql_check = "select * from duty_soldier WHERE MONTH(duty_soldier.date_in) = '".$currentmonth."'";
  1545. //print_r($sql_check);
  1546. //die();
  1547. $res = mysqli_query($con,$sql_check);
  1548.  
  1549.  
  1550. while($row = mysqli_fetch_array($res)) {
  1551. $data['duty_sol_id'] = $row['duty_sol_id'];
  1552. $data['soldierid'] = $row['soldierid'];
  1553.  
  1554.  
  1555.  
  1556. }
  1557. if (empty($data)) {
  1558.  
  1559. $sql_data_empty = "SELECT *
  1560. FROM soldier
  1561. WHERE roleid <> 1 AND positiontypeid = 2 ORDER BY id ASC";
  1562. $res2 = mysqli_query($con,$sql_data_empty);
  1563.  
  1564. while($row = mysqli_fetch_assoc($res2)) {
  1565. $namesArray[] = array(
  1566. 'id' => $row['id'],
  1567. 'soldierid' => $row['soldierid'],
  1568. 'name' => $row['name'],
  1569. 'lastname' => $row['lastname'],
  1570. 'positionid' => $row['positionid']);
  1571. }
  1572.  
  1573. $data = $namesArray;
  1574.  
  1575. return $data;
  1576.  
  1577.  
  1578.  
  1579. }else{
  1580. $sql_check_intersect = "SELECT *
  1581. FROM soldier
  1582. WHERE soldier.roleid <> 1 AND soldier.positiontypeid = 2 AND soldierid NOT IN(SELECT soldierid FROM duty_soldier WHERE MONTH(duty_soldier.date_in) = '".$currentmonth."' )
  1583. ORDER BY id ASC";
  1584.  
  1585. $res_check_intersect = mysqli_query($con,$sql_check_intersect);
  1586.  
  1587. while($row_intersect = mysqli_fetch_assoc($res_check_intersect)) {
  1588. $namesArray[] = array(
  1589. 'id' => $row_intersect['id'],
  1590. 'soldierid' => $row_intersect['soldierid'],
  1591. 'positionid' => $row_intersect['positionid']);
  1592. }
  1593.  
  1594. $row_cnt = $res_check_intersect->num_rows;
  1595. //จำนวนแถวที่เหลือ
  1596. $balance_row = $d-$row_cnt;
  1597. //print_r($balance_row);
  1598. //die();
  1599.  
  1600. if($balance_row == 0 || $balance_row == ""){
  1601.  
  1602. $sql2 = "SELECT *
  1603. FROM soldier
  1604. WHERE roleid <> 1 AND soldier.positiontypeid = 2 AND soldierid NOT IN(SELECT soldierid FROM duty_soldier )
  1605. ORDER BY id ASC LIMIT 0,".$d;
  1606. $res2 = mysqli_query($con,$sql2);
  1607.  
  1608. while($row = mysqli_fetch_assoc($res2)) {
  1609. $namesArray[] = array(
  1610. 'id' => $row['id'],
  1611. 'soldierid' => $row['soldierid'],
  1612. 'positionid' => $row['positionid']);
  1613. }
  1614.  
  1615. $data = $namesArray;
  1616.  
  1617. return $data;
  1618.  
  1619. }else{
  1620.  
  1621. $sql3 = "SELECT *
  1622. FROM soldier
  1623. WHERE roleid <> 1 AND soldier.positiontypeid = 2 AND soldierid NOT IN(SELECT soldierid FROM duty_soldier WHERE MONTH(duty_soldier.date_in) = '".$month1."' )
  1624. ORDER BY id ASC ";
  1625.  
  1626. $res3 = mysqli_query($con,$sql3);
  1627.  
  1628. $row_cnt2 = $res->num_rows;
  1629.  
  1630. while($row = mysqli_fetch_assoc($res3)) {
  1631. $namesArray[] = array(
  1632. 'id' => $row['id'],
  1633. 'soldierid' => $row['soldierid'],
  1634. 'positionid' => $row['positionid']);
  1635. }
  1636.  
  1637. $sql4 = "SELECT *
  1638. FROM soldier
  1639. WHERE roleid <> 1 AND soldier.positiontypeid = 2
  1640. ORDER BY id ASC LIMIT 0,".$row_cnt2;
  1641.  
  1642. $res4 = mysqli_query($con,$sql4);
  1643.  
  1644. while($row = mysqli_fetch_assoc($res4)) {
  1645. $namesArray[] = array(
  1646. 'id' => $row['id'],
  1647. 'soldierid' => $row['soldierid'],
  1648. 'positionid' => $row['positionid']);
  1649. }
  1650.  
  1651. $data = $namesArray;
  1652. return $data;
  1653.  
  1654.  
  1655.  
  1656. }
  1657.  
  1658. }
  1659.  
  1660.  
  1661. mysqli_close($con);
  1662.  
  1663. }
  1664. //----------------------------------------------End Duty-----------------------------------------
  1665.  
  1666. //----------------------------------------------Start Question---------------------------------------
  1667.  
  1668.  
  1669.  
  1670. function saveQuestion($soldierid,$question_name,$question_detail){
  1671. global $con;
  1672.  
  1673.  
  1674. $sql = "INSERT INTO question (soldierid, question_name, question_detail) VALUES('".$soldierid."','".$question_name."','".$question_detail."')";
  1675. mysqli_query($con,$sql);
  1676.  
  1677. mysqli_close($con);
  1678.  
  1679. echo ("<script language='JavaScript'>
  1680. alert('เพิ่มคำถามเรียบร้อย');
  1681. window.location.href='all_post.php';
  1682. </script>");
  1683.  
  1684. }
  1685.  
  1686. function editQuestion($quesid,$soldierid,$question_name,$question_detail,$roleid){
  1687. global $con;
  1688.  
  1689. mysqli_query($con,"UPDATE question SET soldierid='".$soldierid."',question_name='".$question_name."',question_detail='".$question_detail."' WHERE quesid = '".$quesid."'");
  1690. mysqli_query($con,$sql);
  1691. mysqli_close($con);
  1692.  
  1693.  
  1694.  
  1695. echo ("<script language='JavaScript'>
  1696. alert('แก้ไขคำถามเรียบร้อย');
  1697. window.location.href='#.php';
  1698. </script>");
  1699.  
  1700. }
  1701.  
  1702. function deleteQuestion($quesid){
  1703. global $con;
  1704.  
  1705. mysqli_query($con,"DELETE FROM question WHERE quesid ='".$quesid."'");
  1706. mysqli_close($con);
  1707. echo ("<script language='JavaScript'>
  1708. alert('ลบข้อมูลเรียบร้อยแล้ว');
  1709. window.location.href='manage_news.php';
  1710. </script>");
  1711.  
  1712. }
  1713.  
  1714. function getAllQuestion(){
  1715. global $con;
  1716. $sql = "SELECT * FROM question ORDER BY date_create DESC";
  1717. $res = mysqli_query($con,$sql);
  1718.  
  1719. $data = array();
  1720. while($row = mysqli_fetch_assoc($res)) {
  1721. $namesArray[] = array(
  1722. 'quesid' => $row['quesid'],
  1723. 'soldierid' => $row['soldierid'],
  1724. 'name' => $row['name'],
  1725. 'lastname' => $row['lastname'],
  1726. 'question_name' => $row['question_name'],
  1727. 'date_create' => $row['date_create'],
  1728. 'question_detail' => $row['question_detail']);
  1729. }
  1730.  
  1731. $data = $namesArray;
  1732.  
  1733. return $data;
  1734. mysqli_close($con);
  1735.  
  1736. }
  1737.  
  1738. function getCurrentQuestion($quesid){
  1739.  
  1740. global $con;
  1741.  
  1742. $res = mysqli_query($con,"SELECT * FROM question WHERE quesid = '".$quesid."'");
  1743. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1744. return $result;
  1745.  
  1746. mysqli_close($con);
  1747.  
  1748. }
  1749.  
  1750.  
  1751. /*
  1752. function getCurrentQuestion($quesid){
  1753.  
  1754. global $con;
  1755.  
  1756. $res = mysqli_query($con,"SELECT * FROM question a
  1757. LEFT JOIN soldier b
  1758. ON a.soldierid = b.soldierid
  1759. WHERE a.quesid = '".$quesid."'");
  1760. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1761. return $result;
  1762.  
  1763. mysqli_close($con);
  1764.  
  1765. }
  1766. */
  1767. //----------------------------------------------End Question-----------------------------------------
  1768.  
  1769. //----------------------------------------------Start Answer-----------------------------------------
  1770.  
  1771. function saveAnswer($quesid,$soldierid,$answer_question){
  1772. global $con;
  1773.  
  1774. $sql = "INSERT INTO answer (quesid, soldierid, answer_question) VALUES('".$quesid."','".$soldierid."','".$answer_question."')";
  1775. mysqli_query($con,$sql);
  1776.  
  1777. mysqli_close($con);
  1778.  
  1779. echo ("<script language='JavaScript'>
  1780. alert('เพิ่มคำถามเรียบร้อย');
  1781. window.location.href='detail_post.php?quesid=$quesid';
  1782. </script>");
  1783.  
  1784. }
  1785.  
  1786.  
  1787. function getAllAnswer($quesid){
  1788. global $con;
  1789. $sql = "SELECT * FROM answer
  1790. WHERE quesid = '".$quesid."' ORDER BY date_answer asc";
  1791. //print_r($sql);
  1792. //die();
  1793. $res = mysqli_query($con,$sql);
  1794. $data = array();
  1795. while($row = mysqli_fetch_assoc($res)) {
  1796. $namesArray[] = array(
  1797. 'ansid' => $row['ansid'],
  1798. 'quesid' => $row['quesid'],
  1799. 'soldierid' => $row['soldierid'],
  1800. 'name' => $row['name'],
  1801. 'lastname' => $row['lastname'],
  1802. 'answer_question' => $row['answer_question'],
  1803. 'date_answer' => $row['date_answer']);
  1804. }
  1805.  
  1806. $data = $namesArray;
  1807.  
  1808. return $data;
  1809. mysqli_close($con);
  1810.  
  1811. }
  1812.  
  1813. function getCurrentAnswer($quesid){
  1814.  
  1815. global $con;
  1816.  
  1817. $res = mysqli_query($con,"SELECT * FROM answer WHERE quesid = '".$quesid."'");
  1818. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1819. return $result;
  1820.  
  1821. mysqli_close($con);
  1822.  
  1823. }
  1824.  
  1825. //-------------------------------------------------End Answer-----------------------------------------
  1826.  
  1827. //-------------------------------------------------Start Rule---------------------------------------
  1828.  
  1829. function saveRule1($formal1,$formal_type1,$formal_number1){
  1830. global $con;
  1831.  
  1832. $sql = "INSERT INTO sub_formal (formal_id, formal_type, formal_amount) VALUES('".$formal1."','".$formal_type1."','".$formal_number1."')";
  1833. mysqli_query($con,$sql);
  1834.  
  1835. mysqli_close($con);
  1836.  
  1837. echo ("<script language='JavaScript'>
  1838. alert('เพิ่มข้อมูลเรียบร้อย');
  1839. window.location.href='rule.php';
  1840. </script>");
  1841.  
  1842. }
  1843. function saveRule2($formal2,$formal_type21,$formal_number21,$formal_type22,$formal_number22,$formal_type23,$formal_number23){
  1844. global $con;
  1845.  
  1846. $sql1 = "INSERT INTO sub_formal (formal_id, formal_type, formal_amount) VALUES('".$formal2."','".$formal_type21."','".$formal_number21."')";
  1847. $sql2 = "INSERT INTO sub_formal (formal_id, formal_type, formal_amount) VALUES('".$formal2."','".$formal_type22."','".$formal_number22."')";
  1848. $sql3 = "INSERT INTO sub_formal (formal_id, formal_type, formal_amount) VALUES('".$formal2."','".$formal_type23."','".$formal_number23."')";
  1849. mysqli_query($con,$sql1);
  1850. mysqli_query($con,$sql2);
  1851. mysqli_query($con,$sql3);
  1852.  
  1853. mysqli_close($con);
  1854.  
  1855. echo ("<script language='JavaScript'>
  1856. alert('เพิ่มข้อมูลเรียบร้อย');
  1857. window.location.href='rule.php';
  1858. </script>");
  1859.  
  1860. }
  1861.  
  1862.  
  1863. function saveRule3($formal3,$formal_type31,$formal_number32){
  1864. global $con;
  1865.  
  1866. $sql = "INSERT INTO sub_formal (formal_id, formal_type, formal_amount) VALUES('".$formal3."','".$formal_type31."','".$formal_number32."')";
  1867. mysqli_query($con,$sql);
  1868.  
  1869. mysqli_close($con);
  1870.  
  1871. echo ("<script language='JavaScript'>
  1872. alert('เพิ่มข้อมูลเรียบร้อย');
  1873. window.location.href='rule.php';
  1874. </script>");
  1875.  
  1876. }
  1877.  
  1878.  
  1879. //-------------------------------------------------End Rule-----------------------------------------
  1880.  
  1881. //----------------------------------------------Start Model-----------------------------------------
  1882.  
  1883. function saveModel($carmodelname){
  1884. global $con;
  1885. $sql = "INSERT INTO carmodel (carmodelname) VALUES('".$carmodelname."')";
  1886. mysqli_query($con,$sql);
  1887. mysqli_close($con);
  1888.  
  1889. echo ("<script language='JavaScript'>
  1890. alert('เพิ่มข้อมูลเรียบร้อยแล้ว');
  1891. window.location.href='manage_model.php';
  1892. </script>");
  1893. }
  1894.  
  1895. function editModel($carmodelid,$carmodelname){
  1896. global $con;
  1897. mysqli_query($con,"UPDATE carmodel SET carmodelname='".$carmodelname."' WHERE carmodelid = '".$carmodelid."'");
  1898. mysqli_query($con,$sql);
  1899. mysqli_close($con);
  1900. echo ("<script language='JavaScript'>
  1901. alert('แก้ไขข้อมูลเรียบร้อยแล้ว');
  1902. window.location.href='manage_model.php';
  1903. </script>");
  1904. }
  1905.  
  1906. function deleteModel($carmodelid){
  1907. global $con;
  1908. mysqli_query($con,"DELETE FROM carmodel WHERE carmodelid='".$carmodelid."'");
  1909. mysqli_close($con);
  1910. echo ("<script language='JavaScript'>
  1911. alert('ลบข้อมูลเรียบร้อยแล้ว');
  1912. window.location.href='manage_model.php';
  1913. </script>");
  1914. }
  1915.  
  1916. function getCurrentModel($carmodelid){
  1917.  
  1918. global $con;
  1919.  
  1920. $res = mysqli_query($con,"SELECT * FROM carmodel WHERE carmodelid = '".$carmodelid."'");
  1921. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1922. return $result;
  1923.  
  1924. mysqli_close($con);
  1925.  
  1926. }
  1927.  
  1928.  
  1929.  
  1930. //----------------------------------------------End Model-----------------------------------------
  1931.  
  1932. //----------------------------------------------Start formal-----------------------------------------
  1933.  
  1934. function getCurrentFormalType1($quesid){
  1935.  
  1936. global $con;
  1937.  
  1938. $res = mysqli_query($con,"SELECT * FROM sub_formal WHERE formalid = 1");
  1939. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1940. return $result;
  1941.  
  1942. mysqli_close($con);
  1943.  
  1944. }
  1945.  
  1946. function updateFormalType1($formal1,$formal_number1){
  1947. global $con;
  1948. mysqli_query($con,"UPDATE sub_formal SET formalamount='".$formal_number1."' WHERE formalid = '".$formal1."'");
  1949. mysqli_close($con);
  1950. echo ("<script language='JavaScript'>
  1951. alert('แก้ไขข้อมูลเรียบร้อยแล้ว');
  1952. window.location.href='rule.php';
  1953. </script>");
  1954. }
  1955.  
  1956. function getCurrentFormalType21($quesid){
  1957.  
  1958. global $con;
  1959.  
  1960. $res = mysqli_query($con,"SELECT * FROM sub_formal WHERE subformalid = 2");
  1961. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1962. return $result;
  1963.  
  1964. mysqli_close($con);
  1965.  
  1966. }
  1967.  
  1968. function getCurrentFormalType22($quesid){
  1969.  
  1970. global $con;
  1971.  
  1972. $res = mysqli_query($con,"SELECT * FROM sub_formal WHERE subformalid = 3");
  1973. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1974. return $result;
  1975.  
  1976. mysqli_close($con);
  1977.  
  1978. }
  1979.  
  1980. function getCurrentFormalType23($quesid){
  1981.  
  1982. global $con;
  1983.  
  1984. $res = mysqli_query($con,"SELECT * FROM sub_formal WHERE subformalid = 4");
  1985. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  1986. return $result;
  1987.  
  1988. mysqli_close($con);
  1989.  
  1990. }
  1991.  
  1992. function updateFormalType2($formal_type21,$formal_number21,$formal_type22,$formal_number22,$formal_type23,$formal_number23){
  1993. global $con;
  1994. $sql1 ="UPDATE sub_formal SET formalamount='".$formal_number21."' WHERE subformalid = '".$formal_type21."'";
  1995. $sql2 ="UPDATE sub_formal SET formalamount='".$formal_number22."' WHERE subformalid = '".$formal_type22."'";
  1996. $sql3 ="UPDATE sub_formal SET formalamount='".$formal_number23."' WHERE subformalid = '".$formal_type23."'";
  1997. mysqli_query($con,$sql1);
  1998. mysqli_query($con,$sql2);
  1999. mysqli_query($con,$sql3);
  2000. mysqli_close($con);
  2001. echo ("<script language='JavaScript'>
  2002. alert('แก้ไขข้อมูลเรียบร้อยแล้ว');
  2003. window.location.href='rule.php';
  2004. </script>");
  2005. }
  2006.  
  2007.  
  2008. function getCurrentFormalType3($quesid){
  2009.  
  2010. global $con;
  2011.  
  2012. $res = mysqli_query($con,"SELECT * FROM sub_formal WHERE subformalid = 5");
  2013. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  2014. return $result;
  2015.  
  2016. mysqli_close($con);
  2017.  
  2018. }
  2019.  
  2020.  
  2021. function updateFormalType3($formal3,$formal_number31){
  2022. global $con;
  2023. mysqli_query($con,"UPDATE sub_formal SET formalamount='".$formal_number31."' WHERE subformalid = '".$formal3."'");
  2024. mysqli_close($con);
  2025. echo ("<script language='JavaScript'>
  2026. alert('แก้ไขข้อมูลเรียบร้อยแล้ว');
  2027. window.location.href='rule.php';
  2028. </script>");
  2029. }
  2030.  
  2031. //----------------------------------------------Start Another-----------------------------------------
  2032.  
  2033. //----------------------------------------------Start Another-----------------------------------------
  2034.  
  2035. function formatDateFull($date){
  2036. if($date=="0000-00-00"){
  2037. return "";
  2038. }
  2039. if($date=="")
  2040. return $date;
  2041. $raw_date = explode("-", $date);
  2042. $raw_date[0]+=543;
  2043. return $raw_date[2] . "/" . $raw_date[1] . "/" . $raw_date[0];
  2044. }
  2045.  
  2046. function calcformatDateFull($date){
  2047. if($date=="0000-00-00"){
  2048. return "";
  2049. }
  2050. if($date=="")
  2051. return $date;
  2052. $raw_date = explode("-", $date);
  2053. $raw_date[0]+=543;
  2054. return $raw_date[2] . "/" . $raw_date[1] . "/" . $raw_date[0];
  2055. }
  2056.  
  2057. function calcformatDateFull2($date){
  2058. if($date=="0000-00-00"){
  2059. return "";
  2060. }
  2061. if($date=="")
  2062. return $date;
  2063. $raw_date = explode("-", $date);
  2064. $raw_date[0]-=543;
  2065. return $raw_date[0] . "-" . $raw_date[1] . "-" . $raw_date[2];
  2066. }
  2067.  
  2068. function formatDateFull2($date){
  2069. if($date=="0000-00-00"){
  2070. return "";
  2071. }
  2072. if($date=="")
  2073. return $date;
  2074. $raw_date = explode("-", $date);
  2075. return $raw_date[0] . "-" . $raw_date[1] . "-" . $raw_date[2];
  2076. }
  2077.  
  2078. function getAllProvinces(){
  2079. global $con;
  2080. $sql = "SELECT * FROM provinces ORDER BY province_id DESC";
  2081. $res = mysqli_query($con,$sql);
  2082.  
  2083. $data = array();
  2084. while($row = mysqli_fetch_assoc($res)) {
  2085. $namesArray[] = array(
  2086. 'province_id' => $row['province_id'],
  2087. 'province_code' => $row['province_code'],
  2088. 'province_name' => $row['province_name'],
  2089. 'province_name_eng' => $row['province_name_eng'],
  2090. 'geo_id' => $row['geo_id']);
  2091. }
  2092.  
  2093. $data = $namesArray;
  2094.  
  2095. return $data;
  2096. mysqli_close($con);
  2097.  
  2098. }
  2099.  
  2100. function getCurrentProvinces($id){
  2101.  
  2102. global $con;
  2103.  
  2104. $res = mysqli_query($con,"SELECT * FROM provinces WHERE province_id = '".$id."' ");
  2105. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  2106. return $result;
  2107.  
  2108. mysqli_close($con);
  2109.  
  2110. }
  2111.  
  2112. function getAllRoleByCompanyId($companyid){
  2113. global $con;
  2114. $res = mysqli_query($con,"SELECT * FROM soldier WHERE roleid = 3 ");
  2115.  
  2116. while($row = mysqli_fetch_array($res)) {
  2117. $data['id'] = $row['id'];
  2118. $data['soldierid'] = $row['soldierid'];
  2119. $data['firstname'] = $row['firstname'];
  2120. $data['lastname'] = $row['lastname'];
  2121.  
  2122.  
  2123. }
  2124. //print_r($data);
  2125. //die();
  2126. if (!empty($data)) {
  2127.  
  2128. $sql = "SELECT * FROM role WHERE companyid = '".$companyid."' AND roleid <> 3 ORDER BY roleid DESC";
  2129. //print_r($sql);
  2130. //die();
  2131. $res = mysqli_query($con,$sql);
  2132.  
  2133. $data = array();
  2134. while($row = mysqli_fetch_assoc($res)) {
  2135. $namesArray[] = array(
  2136. 'roleid' => $row['roleid'],
  2137. 'rolename' => $row['rolename'],
  2138. 'companyid' => $row['companyid']);
  2139. }
  2140.  
  2141. $data = $namesArray;
  2142.  
  2143. return $data;
  2144.  
  2145. }else{
  2146. $sql = "SELECT * FROM role WHERE companyid = '".$companyid."' ORDER BY roleid DESC";
  2147. $res = mysqli_query($con,$sql);
  2148.  
  2149. $data = array();
  2150. while($row = mysqli_fetch_assoc($res)) {
  2151. $namesArray[] = array(
  2152. 'roleid' => $row['roleid'],
  2153. 'rolename' => $row['rolename'],
  2154. 'companyid' => $row['companyid']);
  2155. }
  2156.  
  2157. $data = $namesArray;
  2158.  
  2159. return $data;
  2160. }
  2161.  
  2162. mysqli_close($con);
  2163.  
  2164.  
  2165. /*$sql = "SELECT * FROM role WHERE companyid = '".$companyid."' ORDER BY roleid DESC";
  2166. $res = mysqli_query($con,$sql);
  2167.  
  2168. $data = array();
  2169. while($row = mysqli_fetch_assoc($res)) {
  2170. $namesArray[] = array(
  2171. 'roleid' => $row['roleid'],
  2172. 'rolename' => $row['rolename'],
  2173. 'companyid' => $row['companyid']);
  2174. }
  2175.  
  2176. $data = $namesArray;
  2177.  
  2178. return $data;
  2179.  
  2180. mysqli_close($con);
  2181. */
  2182. }
  2183.  
  2184. function getAllRole(){
  2185. $data = array();
  2186. global $con;
  2187. $res = mysqli_query($con,"SELECT * FROM soldier WHERE roleid = 3 ");
  2188.  
  2189. while($row = mysqli_fetch_array($res)) {
  2190. $data['soldierid'] = $row['soldierid'];
  2191.  
  2192. }
  2193. if (!empty($data)) {
  2194. $sql = "SELECT * FROM role WHERE roleid <> 3 ORDER BY roleid DESC";
  2195. $res = mysqli_query($con,$sql);
  2196.  
  2197. $data = array();
  2198. while($row = mysqli_fetch_assoc($res)) {
  2199. $namesArray[] = array(
  2200. 'roleid' => $row['roleid'],
  2201. 'rolename' => $row['rolename'],
  2202. 'companyid' => $row['companyid']);
  2203. }
  2204.  
  2205. $data = $namesArray;
  2206.  
  2207. return $data;
  2208.  
  2209. }else{
  2210.  
  2211. $sql = "SELECT * FROM role ORDER BY roleid DESC";
  2212. $res = mysqli_query($con,$sql);
  2213.  
  2214. $data = array();
  2215. while($row = mysqli_fetch_assoc($res)) {
  2216. $namesArray[] = array(
  2217. 'roleid' => $row['roleid'],
  2218. 'rolename' => $row['rolename'],
  2219. 'companyid' => $row['companyid']);
  2220. }
  2221.  
  2222. $data = $namesArray;
  2223.  
  2224. return $data;
  2225.  
  2226. }
  2227.  
  2228. mysqli_close($con);
  2229.  
  2230. }
  2231.  
  2232. function getAllCompany(){
  2233. global $con;
  2234. $sql = "SELECT * FROM company ORDER BY companyid DESC";
  2235. $res = mysqli_query($con,$sql);
  2236.  
  2237. $data = array();
  2238. while($row = mysqli_fetch_assoc($res)) {
  2239. $namesArray[] = array(
  2240. 'companyid' => $row['companyid'],
  2241. 'companyname' => $row['companyname']);
  2242. }
  2243.  
  2244. $data = $namesArray;
  2245.  
  2246. return $data;
  2247. mysqli_close($con);
  2248.  
  2249. }
  2250.  
  2251. function getAllPositionType(){
  2252. global $con;
  2253. $sql = "SELECT * FROM positiontype ORDER BY positiontypeid DESC";
  2254. $res = mysqli_query($con,$sql);
  2255.  
  2256. $data = array();
  2257. while($row = mysqli_fetch_assoc($res)) {
  2258. $namesArray[] = array(
  2259. 'positiontypeid' => $row['positiontypeid'],
  2260. 'positiontypename' => $row['positiontypename']);
  2261. }
  2262.  
  2263. $data = $namesArray;
  2264.  
  2265. return $data;
  2266. mysqli_close($con);
  2267.  
  2268. }
  2269.  
  2270. function getAllPositionByPositiontypeid($positiontypeid){
  2271.  
  2272. global $con;
  2273.  
  2274. $sql = "SELECT * FROM position WHERE positiontypeid = '".$positiontypeid."' ORDER BY positionid DESC";
  2275. $res = mysqli_query($con,$sql);
  2276.  
  2277. $data = array();
  2278. while($row = mysqli_fetch_assoc($res)) {
  2279. $namesArray[] = array(
  2280. 'positionid' => $row['positionid'],
  2281. 'positionname' => $row['positionname'],
  2282. 'positiontypeid' => $row['positiontypeid']);
  2283. }
  2284.  
  2285. $data = $namesArray;
  2286.  
  2287. return $data;
  2288.  
  2289. mysqli_close($con);
  2290.  
  2291.  
  2292. }
  2293.  
  2294. function getAllPosition(){
  2295. global $con;
  2296. $sql = "SELECT * FROM position ORDER BY positionid DESC";
  2297. $res = mysqli_query($con,$sql);
  2298.  
  2299. $data = array();
  2300. while($row = mysqli_fetch_assoc($res)) {
  2301. $namesArray[] = array(
  2302. 'positionid' => $row['positionid'],
  2303. 'positionname' => $row['positionname'],
  2304. 'positiontypeid' => $row['positiontypeid']);
  2305. }
  2306.  
  2307. $data = $namesArray;
  2308.  
  2309. return $data;
  2310. mysqli_close($con);
  2311.  
  2312. }
  2313.  
  2314. function saveFileFromTheWeb($remoteFile,$localFile){
  2315. $ch = curl_init();
  2316. $timeout = 0;
  2317. curl_setopt ($ch, CURLOPT_URL, $remoteFile);
  2318. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  2319. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2320. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  2321. $image = curl_exec($ch);
  2322. curl_close($ch);
  2323. $f = fopen($localFile, 'w');
  2324. fwrite($f, $image);
  2325. fclose($f);
  2326. }
  2327. //----------------------------------------------End Another-----------------------------------------
  2328.  
  2329. //----------------------------------------------Start News-----------------------------------------
  2330.  
  2331. function saveBuild($buildname,$latbox,$lngbox){
  2332. global $con;
  2333. $sql = "INSERT INTO build ( buildname, latitude, longitude) VALUES('".$buildname."','".$latbox."','".$lngbox."')";
  2334. mysqli_query($con,$sql);
  2335. mysqli_close($con);
  2336.  
  2337.  
  2338. echo ("<script language='JavaScript'>
  2339. alert('เพิ่มสถานที่เรียบร้อย');
  2340. window.location.href='manage_build.php';
  2341. </script>");
  2342.  
  2343. }
  2344.  
  2345. function editBuild($buildid,$buildname,$latbox,$lngbox){
  2346. global $con;
  2347.  
  2348. mysqli_query($con,"UPDATE build SET buildname='".$buildname."',latitude='".$latbox."',longitude='".$lngbox."' WHERE buildid = '".$buildid."'");
  2349. mysqli_query($con,$sql);
  2350. mysqli_close($con);
  2351.  
  2352. echo ("<script language='JavaScript'>
  2353. alert('แก้ไขสถานที่เรียบร้อย');
  2354. window.location.href='manage_build.php';
  2355. </script>");
  2356.  
  2357. }
  2358.  
  2359. function deleteBuild($buildid){
  2360. global $con;
  2361.  
  2362. //$res = mysqli_query($con,"SELECT * FROM news WHERE newsid = '".$newsid."'");
  2363. //$result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  2364.  
  2365. mysqli_query($con,"DELETE FROM build WHERE buildid='".$buildid."'");
  2366. mysqli_close($con);
  2367. echo ("<script language='JavaScript'>
  2368. alert('ลบข้อมูลเรียบร้อยแล้ว');
  2369. window.location.href='manage_build.php';
  2370. </script>");
  2371.  
  2372. }
  2373.  
  2374. function getAllBuild(){
  2375. global $con;
  2376. $sql = "SELECT *
  2377. FROM build
  2378. ORDER BY buildid DESC";
  2379. $res = mysqli_query($con,$sql);
  2380.  
  2381. $data = array();
  2382. while($row = mysqli_fetch_assoc($res)) {
  2383. $namesArray[] = array(
  2384. 'buildid' => $row['buildid'],
  2385. 'buildname' => $row['buildname'],
  2386. 'latitude' => $row['latitude'],
  2387. 'longitude' => $row['longitude']);
  2388. }
  2389.  
  2390. $data = $namesArray;
  2391.  
  2392. return $data;
  2393. mysqli_close($con);
  2394.  
  2395. }
  2396.  
  2397. function getCurrentBuild($buildid){
  2398.  
  2399. global $con;
  2400.  
  2401. $res = mysqli_query($con,"SELECT * FROM build WHERE buildid = '".$buildid."'");
  2402. $result=mysqli_fetch_array($res,MYSQLI_ASSOC);
  2403. return $result;
  2404.  
  2405. mysqli_close($con);
  2406.  
  2407. }
  2408.  
  2409. //----------------------------------------------End News-----------------------------------------
  2410.  
  2411. function getAllWorkSoldier(){
  2412. global $con;
  2413. $sql = "SELECT *, MONTH(date_absence_work) as monthAbsence
  2414. FROM absence_work
  2415. GROUP BY MONTH(date_absence_work)";
  2416. $res = mysqli_query($con,$sql);
  2417. $data = array();
  2418. while($row = mysqli_fetch_assoc($res)) {
  2419. $namesArray[] = array(
  2420. 'absence_workid' => $row['absence_workid'],
  2421. 'soldierid' => $row['soldierid'],
  2422. 'monthAbsence' => $row['monthAbsence'],
  2423. 'date_absence_work' => $row['date_absence_work']);
  2424. }
  2425.  
  2426. $data = $namesArray;
  2427.  
  2428. return $data;
  2429. mysqli_close($con);
  2430.  
  2431. }
  2432.  
  2433. function getAllWorkAbsenceSoldierDetail($month){
  2434. global $con;
  2435. $sql = "SELECT * ,s.soldierid as soldierid
  2436. FROM absence_work a
  2437. LEFT JOIN soldier s
  2438. ON s.soldierid = a.soldierid
  2439. WHERE MONTH(a.date_absence_work) = '".$month."'";
  2440. $res = mysqli_query($con,$sql);
  2441. $data = array();
  2442. while($row = mysqli_fetch_assoc($res)) {
  2443. $namesArray[] = array(
  2444. 'absence_workid' => $row['absence_workid'],
  2445. 'soldierid' => $row['soldierid'],
  2446. 'name' => $row['name'],
  2447. 'lastname' => $row['lastname'],
  2448. 'date_absence_work' => $row['date_absence_work']);
  2449. }
  2450.  
  2451. $data = $namesArray;
  2452.  
  2453. return $data;
  2454. mysqli_close($con);
  2455.  
  2456. }
  2457.  
  2458. function getAllWorkNormalSoldierDetail($month){
  2459. global $con;
  2460. $sql = "SELECT * ,s.soldierid as soldierid
  2461. FROM work a
  2462. LEFT JOIN soldier s
  2463. ON s.soldierid = a.soldierid
  2464. JOIN position b
  2465. ON s.positionid = b.positionid
  2466. WHERE MONTH(a.datetime_start) = '".$month."' ORDER BY a.datetime_start ASC";
  2467. $res = mysqli_query($con,$sql);
  2468. $data = array();
  2469. while($row = mysqli_fetch_assoc($res)) {
  2470. $namesArray[] = array(
  2471. 'absence_workid' => $row['absence_workid'],
  2472. 'soldierid' => $row['soldierid'],
  2473. 'name' => $row['name'],
  2474. 'lastname' => $row['lastname'],
  2475. 'datetime_start' => $row['datetime_start'],
  2476. 'datetime_finish' => $row['datetime_finish'],
  2477. 'positionname' => $row['positionname'],
  2478. 'date_absence_work' => $row['date_absence_work']);
  2479. }
  2480.  
  2481. $data = $namesArray;
  2482.  
  2483. return $data;
  2484. mysqli_close($con);
  2485.  
  2486. }
  2487.  
  2488. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement