PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/controllers/Sites.php

https://bitbucket.org/Naked_Yoshi/tiktrack_beta
PHP | 243 lines | 227 code | 15 blank | 1 comment | 11 complexity | cd7fa12128299589796f65e4229733b4 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, MIT, BSD-3-Clause
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Sites extends MY_Controller {
  4. private $models;
  5. public function __construct(){
  6. parent::__construct();
  7. $this->models = $this->Site;
  8. }
  9. public function index()
  10. {
  11. $this->data["pageName"] = "ไซต์และสาขา";
  12. $this->data["pageactive"] = "<li><a href='".base_url("sites")."' class='active'>ไซต์และสาขา</a></li>";
  13. $this->middle = 'sites/index';
  14. $this->data["CSS_asset"] = "<link href='".base_url("assets/plugins/bower_components/clockpicker/dist/jquery-clockpicker.min.css")."' rel='stylesheet' type='text/css' />";
  15. $this->data["JS_asset"] = "<script src='".base_url("assets/js/cbpFWTabs.js")."'></script>";
  16. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JSite.js")."'></script>";
  17. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JSiteHelpers.js")."'></script>";
  18. $this->data["JS_asset"] .= "<script src='".base_url("assets/plugins/bower_components/moment/moment.js")."'></script>";
  19. $this->data["JS_asset"] .= "<script src='".base_url("assets/plugins/bower_components/clockpicker/dist/jquery-clockpicker.min.js")."'></script>";
  20. $this->data["JS_asset"] .= "<script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyCZKhEPx14ken6ISjjnQT0K4tZ7nlNaJjU&libraries=places' async defer></script>";
  21. $this->layouts();
  22. }
  23. public function load(){
  24. $arraysite = json_decode($_POST["obj"],true);
  25. print_r($arraysite);
  26. $this->models->company = 3;
  27. $this->models->auth = "20170000001";
  28. $load = $this->models->getAll();
  29. $sites = $this->generateTable($load);
  30. // echo json_encode($sites);
  31. return;
  32. }
  33. public function updateLocation(){
  34. $site = base64_decode(base64_decode(base64_decode($_POST["segment"])));
  35. $this->models->lat = $_POST["lat"];
  36. $this->models->lng = $_POST["lng"];
  37. $this->models->area = $_POST["area"];
  38. $this->models->id = $site;
  39. $this->models->auth = "20170000001";
  40. $update = $this->models->updateLocation();
  41. $callback = array(
  42. "success" => false,
  43. "title" => "ผิดพลาด",
  44. "msg" => "ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง"
  45. );
  46. if($update) {
  47. $callback = array(
  48. "success" => true,
  49. "title" => "สำเร็จ",
  50. "msg" => "แก้ไขสถานที่สำเร็จ"
  51. );
  52. }
  53. echo json_encode($callback);
  54. return;
  55. }
  56. public function updateName(){
  57. $site = base64_decode(base64_decode(base64_decode($_POST["segment"])));
  58. $name = $_POST["name"];
  59. $this->models->name = $name;
  60. $this->models->id = $site;
  61. $this->models->auth = "20170000001";
  62. $update = $this->models->updateName();
  63. $callback = array(
  64. "success" => false,
  65. "title" => "ผิดพลาด",
  66. "msg" => "ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง"
  67. );
  68. if($update) {
  69. $callback = array(
  70. "success" => true,
  71. "title" => "สำเร็จ",
  72. "msg" => "แก้ไขชื่อไซต์สำเร็จ"
  73. );
  74. }
  75. echo json_encode($callback);
  76. return;
  77. }
  78. public function Edit(){
  79. $site = base64_decode(base64_decode(base64_decode($this->uri->segments[3])));
  80. $this->models->id = $site;
  81. $detail = $this->models->getBy();
  82. if (!$detail["Has"]) {
  83. exit("<script>alert('ไม่พบไซต์ที่คุณเลือก'); history.back();</script>");
  84. }else{
  85. $this->data["site"] = $site;
  86. $this->data["detail"] = $detail["data"][0];
  87. $this->data["pageName"] = $detail["data"][0]["siteName"];
  88. $this->data["pageSegment"] = $this->uri->segments[3];
  89. $this->data["pageactive"] = "<li><a href='".base_url("sites")."' >ไซต์และสาขา</a></li> <li><a href='".base_url("sites/Edit/".$this->uri->segments[3])."' class='active'>".$detail["data"][0]["siteName"]."</a></li>";
  90. $this->middle = 'sites/edit';
  91. $this->data["CSS_asset"] = "<link href='".base_url("assets/plugins/bower_components/clockpicker/dist/jquery-clockpicker.min.css")."' rel='stylesheet' type='text/css' />";
  92. $this->data["CSS_asset"] .= "<link href='".base_url("assets/plugins/bower_components/switchery/dist/switchery.min.css")."' rel='stylesheet' type='text/css' />";
  93. $this->data["CSS_asset"] .= "<link href='".base_url("assets/css/jquery.auto-complete.css")."' rel='stylesheet' type='text/css' />";
  94. $this->data["JS_asset"] = "<script src='".base_url("assets/js/cbpFWTabs.js")."'></script>";
  95. $this->data["JS_asset"] .= "<script src='".base_url("assets/plugins/bower_components/switchery/dist/switchery.min.js")."'></script>";
  96. $this->data["JS_asset"] .= "<script src='".base_url("assets/plugins/bower_components/moment/moment.js")."'></script>";
  97. $this->data["JS_asset"] .= "<script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyCZKhEPx14ken6ISjjnQT0K4tZ7nlNaJjU&libraries=places' async defer></script>";
  98. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JSiteHelpers.js")."'></script>";
  99. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JSiteEdit.js")."'></script>";
  100. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JHoliday.js")."'></script>";
  101. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JOt.js")."'></script>";
  102. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JBranche.js")."'></script>";
  103. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/apps/JLeave.js")."'></script>";
  104. $this->data["JS_asset"] .= "<script src='".base_url("assets/plugins/bower_components/clockpicker/dist/jquery-clockpicker.min.js")."'></script>";
  105. $this->data["JS_asset"] .= "<script src='".base_url("assets/js/jquery.auto-complete.js")."'></script>";
  106. $this->layouts();
  107. }
  108. }
  109. private function generateTable($data){
  110. $tables = array();
  111. $tables["table"] = array();
  112. $tables["data"] = array();
  113. $tables["Has"] = $data["Has"];
  114. if ($data["Has"]) {
  115. $num = 1;
  116. for ($i=0; $i < count($data["data"]); $i++) {
  117. $siteCode = base64_encode(base64_encode(base64_encode($data["data"][$i]["site_id"])));
  118. $tr = "";
  119. $tr .= "<tr>";
  120. $tr .= "<td class='text-center'>";
  121. $tr .= $num;
  122. $tr .= "</td>";
  123. $tr .= "<td>";
  124. $tr .= $data["data"][$i]["siteName"];
  125. $tr .= "</td>";
  126. $tr .= "<td class='text-center'>";
  127. $tr .= "<div class='btn-group'>";
  128. $tr .= "<button class='btn btn-sm btn-default btn-outline waves-effect btn-site-edit' data-edit='".$siteCode."'><span class='fa fa-edit'></span></button>";
  129. $tr .= "<button class='btn btn-sm btn-default btn-outline waves-effect'><span class='fa fa-trash'></span></button>";
  130. $tr .= "</div>";
  131. $tr .= "</td>";
  132. $tr .= "</tr>";
  133. array_push($tables["table"],$tr);
  134. array_push($tables["data"],
  135. array(
  136. "num"=>$num,
  137. "id"=>$data["data"][$i]["site_id"],
  138. "name"=>$data["data"][$i]["siteName"],
  139. ));
  140. $num ++;
  141. }
  142. }
  143. return $tables;
  144. }
  145. public function addWorking(){
  146. $site = base64_decode(base64_decode(base64_decode($_POST["segment"])));
  147. $this->models->id = $site;
  148. $this->models->company = $_POST["company_id"];
  149. $this->models->auth = "20170000001";
  150. $wk = $_POST["wk"];
  151. for ($i=0; $i < count($wk); $i++) {
  152. $getNo = $this->models->getLastNo();
  153. $newNo = intval($getNo[0]["no"]);
  154. $newNo ++;
  155. $data_setting = array(
  156. "site_id" => $site,
  157. "no" => $newNo,
  158. "site_setting_status" => 1,
  159. "wk_id" => $wk[$i],
  160. "ot_id" => 0,
  161. "hd_id" => 0
  162. );
  163. $add_setting = $this->db->insert('ms_site_setting',$data_setting);
  164. }
  165. $callback = array(
  166. "success" => false,
  167. "title" => "ผิดพลาด",
  168. "msg" => "ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง"
  169. );
  170. if($add_setting) {
  171. $callback = array(
  172. "success" => true,
  173. "title" => "สำเร็จ",
  174. "msg" => "บันทึกข้อมูลวันทำการสำเร็จ"
  175. );
  176. }
  177. echo json_encode($callback);
  178. return;
  179. }
  180. public function create(){
  181. $this->models->company = 3;
  182. $this->models->auth = "20170000001";
  183. $add = $this->models->add($_POST);
  184. $callback = array(
  185. "success" => false,
  186. "title" => "ผิดพลาด",
  187. "msg" => "ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง"
  188. );
  189. if($add){
  190. $callback = array(
  191. "success" => true,
  192. "title" => "สำเร็จ",
  193. "msg" => "บันทึกข้อมูลไซต์สำเร็จ"
  194. );
  195. }
  196. echo json_encode($callback);
  197. }
  198. public function ModalCreate(){
  199. $this->load->view("sites/create");
  200. }
  201. public function getchip(){
  202. $chip = array();
  203. $str_chip = "";
  204. if (isset($_POST["chip"])) {
  205. $chip = $_POST["chip"];
  206. $str_chip = "(".implode(",",$chip).")";
  207. }
  208. $person = $this->Persons;
  209. $person->company = $this->auth[0]["company_id"];
  210. $str = $_POST["str"];
  211. $array = explode(" ",$str);
  212. $count = count($array);
  213. $str_1 = "";
  214. $str_2 = "";
  215. if ($count > 1) {
  216. $str_1 = $array[0];
  217. $str_2 = $array[1];
  218. for ($i=2; $i < count($array); $i++) {
  219. $str_2 .= " ".$array[$i];
  220. }
  221. }else{
  222. $str_1 = $array[0];
  223. }
  224. $data = $person->getEmpChip($str_1,$str_2,$str_chip);
  225. echo json_encode($data);
  226. return;
  227. }
  228. }