tools.class.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of operation_log
  7. *
  8. * @author Administrator
  9. */
  10. class tools {
  11. private static $_tools;
  12. public static function getInstance() {
  13. if (!self::$_tools) {
  14. $c = __CLASS__;
  15. self::$_tools = new $c;
  16. }
  17. return self::$_tools;
  18. }
  19. /*
  20. * update password when login success
  21. */
  22. public function updatePassword() {
  23. if ($_SESSION['ONLINE_USER']['is_demo'] == "t") {
  24. $str = "DEMO cannot update password.";
  25. } else {
  26. $opsw = common::check_input($_POST ['opsw']);
  27. $npsw = common::check_input($_POST ['npsw']);
  28. $username = _getLoginName();
  29. $msg = common::checkPasswordRule($username, $npsw);
  30. //为空代表验证通过
  31. if (empty($msg)) {
  32. $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($username) . "'";
  33. $rs = common::excuteObjectSql($sql);
  34. $str = '';
  35. if (!empty($rs)) {
  36. if ($rs['password'] == $opsw) {
  37. $sql = "UPDATE ra_online_user SET ra_password = '" . $npsw . "', last_pwd_change = now() WHERE lower(user_login) = '" . strtolower($username) . "'";
  38. $rls = common::excuteUpdateSql($sql);
  39. if (!$rls) {
  40. $str = "Password modification failed!";
  41. } else {
  42. $str = " Your password has been modified!";
  43. }
  44. } else {
  45. $str = "Old password is incorrect!";
  46. }
  47. } else {
  48. $str = "Old password is incorrect!";
  49. }
  50. } else {
  51. $str = $msg;
  52. }
  53. }
  54. $returnData = array("msg" => $str);
  55. common::echo_json_encode(200, $returnData);
  56. exit();
  57. }
  58. public function markSystem(){
  59. $operate = utils::_get('operate');
  60. $operate = strtolower($operate);
  61. if ($operate == "mark_save") {
  62. $suggestion = utils::implode(",",$_POST['suggestion']);
  63. $proposal = common::check_input($_POST['proposal']);
  64. $expression = common::check_input($_POST['expression']);
  65. $complete_funtionality = common::check_input($_POST['Complete_funtionality']);
  66. $accurate_data = common::check_input($_POST['Accurate_data']);
  67. $clear_information = common::check_input($_POST['Clear_information']);
  68. $easy_to_use = common::check_input($_POST['Easy_to_use']);
  69. $system_Performance = common::check_input($_POST['System_Performance']);
  70. $username = common::check_input($_POST['username']);
  71. $user_type = _isApexLogin() ? "employee" : "customer";
  72. if(!isset($_SESSION['ONLINE_USER'])){
  73. $user_type = "other";
  74. }
  75. $loginName = _getLoginName();
  76. $loginEamil = _getLoginEamil();
  77. //如果在没有登录前,没有登录信息,指定用户-- 这里逻辑取消,没有登录相当于匿名用户的评价,无法获取用户名
  78. // if(!isset($_SESSION['ONLINE_USER'])){
  79. // $user_type = "Customer";
  80. // if(!empty($username)){
  81. // $loginName = $username;
  82. // $loginEamil = common::excuteOneSql("select email from public.ra_online_user u where lower(user_login) = '" . strtolower($username) . "'");
  83. // }
  84. // }
  85. $sql = "INSERT INTO public.customer_service_user_mark(user_type, user_name, suggestion, proposal, expression, complete_funtionality,
  86. accurate_data, clear_information, easy_to_use, system_performance,
  87. created_time,email)
  88. VALUES ('$user_type', '$loginName', '$suggestion', '$proposal', '$expression', '$complete_funtionality',
  89. '$accurate_data', '$clear_information', '$easy_to_use', '$system_Performance', now(),'$loginEamil')";
  90. common::excuteUpdateSql($sql);
  91. $data = array("msg" =>"success");
  92. common::echo_json_encode(200,$data);
  93. exit();
  94. }
  95. }
  96. public function user_system_setting(){
  97. $operate = utils::_get('operate');
  98. $operate = strtolower($operate);
  99. if ($operate == "personal_profile_init") {
  100. // get system config
  101. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_password_change_cycle', 'customer_password_change_cycle')";
  102. $rs1s = common::excuteListSql($sql);
  103. foreach ($rs1s as $rs1) {
  104. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  105. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  106. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  107. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  108. }
  109. $sql="select item_value from config where item='passwordChangePeriod'";
  110. $pcp = common::excuteObjectSql($sql);
  111. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  112. if (_isApexLogin()) {
  113. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  114. //如果有新配置,则采用新配置
  115. if (!empty($pcp)) {
  116. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  117. }
  118. } else {
  119. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  120. //如果有新配置,则采用新配置
  121. if (!empty($pcp)) {
  122. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  123. }
  124. }
  125. $sql = "select u.first_name,u.last_name,u.user_login,u.email,EXTRACT(DAY from (now() - u.last_pwd_change)) as last_pwd_change_date,
  126. ue.date_format,ue.numbers_format
  127. from ra_online_user u
  128. left join kln_user_extend ue on u.user_login = ue.user_login
  129. where lower(u.user_login) = '".strtolower(_getLoginName())."' ";
  130. $data = common::excuteObjectSql($sql);
  131. $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
  132. common::echo_json_encode(200,$data);
  133. exit();
  134. }
  135. if ($operate == "personal_profile_save") {
  136. $save_model = common::check_input($_POST['save_model']);
  137. if ($save_model == "profile"){
  138. $user_name = common::check_input($_POST['user_name']);
  139. $email = common::check_input($_POST['email']);
  140. $sql = "update public.ra_online_user set user_login = '$user_name',email = '$email' where lower(user_login) = '".strtolower(_getLoginName())."'";
  141. }else{
  142. $date_fromat = common::check_input($_POST['date_fromat']);
  143. $numbers_format = common::check_input($_POST['numbers_format']);
  144. $exist_kln_user = common::excuteObjectSql("select user_login from public.kln_user_extend where lower(user_login) = '".strtolower(_getLoginName())."'");
  145. if (!empty($exist_kln_user['user_login'])){
  146. $sql = "update public.kln_user_extend set date_fromat = '$date_fromat',numbers_format = '$numbers_format' where lower(user_login) = '".strtolower(_getLoginName())."'";
  147. } else {
  148. $sql = "INSERT INTO public.kln_user_extend(user_login, date_format, numbers_format, subscribe_hbol)
  149. VALUES ('"._getLoginName()."', '$date_fromat', '$numbers_format', null);";
  150. }
  151. }
  152. common::excuteUpdateSql($sql);
  153. $data = array("msg" => "save Successful");
  154. common::echo_json_encode(200,$data);
  155. exit();
  156. }
  157. if ($operate == "subscribe_notification_init") {
  158. $subscribur_data =array();
  159. //查询用户对应的Rule
  160. $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
  161. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  162. $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
  163. foreach($all_rules as $rule_name){
  164. $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
  165. $subscribur_data[$rule_name] = $rules;
  166. }
  167. //整合拼接addedRules
  168. $addedRules = array();
  169. foreach($subscribe_rules as $addedRule){
  170. $addedRules[] = array(
  171. "visible" => false,
  172. "id" =>$addedRule['id'],
  173. "Event" =>$addedRule['rules_type'],
  174. "Event Details" =>$addedRule['event_details'],
  175. "Frequency" =>$addedRule['frequency_display'],
  176. "Methods" =>$addedRule['method_display']);
  177. }
  178. $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
  179. //获取subscribe shipment 当前页数cp,每页ps
  180. $subscribeShipmentWithPage = $this->getSubscribeShipment(1,20);
  181. $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
  182. common::echo_json_encode(200,$subscribur_data);
  183. exit();
  184. }
  185. if ($operate == "subscribe_notification_event_update"){
  186. $rules_type = common::check_input($_POST["rules_type"]);
  187. //判断该规则是否存在
  188. $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
  189. and lower(user_login) = '".strtolower(_getLoginName())."'");
  190. $updateOrInsert = empty($exist) ? "insert" : "update";
  191. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
  192. $rs = common::excuteUpdateSql($sql);
  193. if ($rs === FALSE){
  194. $data = array("msg" => "Update Error");
  195. } else{
  196. $data = array("msg" => "Update Successful");
  197. //返回addedRules 全部列表
  198. $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
  199. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  200. //整合拼接addedRules
  201. $addedRules = array();
  202. foreach($subscribe_rules as $addedRule){
  203. $addedRules[] = array(
  204. "id" =>$addedRule['id'],
  205. "Event" =>$addedRule['rules_type'],
  206. "Event Details" =>$addedRule['event_details'],
  207. "Frequency" =>$addedRule['frequency_display'],
  208. "Methods" =>$addedRule['method_display']);
  209. }
  210. $data['addedRules'] = array("tableData"=>$addedRules);
  211. }
  212. common::echo_json_encode(200,$data);
  213. exit();
  214. }
  215. if ($operate == "subscribe_notification_rules_delete"){
  216. $rules_type = common::check_input($_POST['rules_type']);
  217. $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
  218. and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
  219. common::excuteUpdateSql($sql);
  220. $data = array("msg" => "Delete Successful");
  221. common::echo_json_encode(200,$data);
  222. exit();
  223. }
  224. if ($operate == "subscribe_shipment"){
  225. $serial_no = common::check_input($_POST['serial_no']);
  226. $is_subscribe = common::check_input($_POST['is_subscribe']);
  227. if($is_subscribe == "yes"){
  228. $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
  229. if(!empty($exist)){
  230. $data = array("msg" => "Subscribe exist,Please check");
  231. common::echo_json_encode(200,$data);
  232. exit();
  233. }
  234. $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
  235. VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
  236. common::excuteUpdateSql($sql);
  237. $data = array("msg" => "Subscribe Successful");
  238. common::echo_json_encode(200,$data);
  239. exit();
  240. }else{
  241. //取消订阅
  242. $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
  243. common::excuteUpdateSql($sql);
  244. $data = array("msg" => "Cancel successfully");
  245. common::echo_json_encode(200,$data);
  246. exit();
  247. }
  248. }
  249. }
  250. public function user_monitoring_setting(){
  251. $operate = utils::_get('operate');
  252. $operate = strtolower($operate);
  253. if ($operate == "monitoring_rules_search") {
  254. $cp = common::check_input($_POST ['cp']); //current_page
  255. $ps = common::check_input($_POST ['ps']); //ps
  256. if (empty($ps))
  257. $ps = 50;
  258. $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
  259. $rc = common::excuteOneSql($sql);
  260. $tp = ceil($rc / $ps);
  261. if ($rc > 0) {
  262. $sql = "select count(1) from public.notifications_rules
  263. where lower(user_login) = '".strtolower(_getLoginName())."'
  264. and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  265. $monitoringRules = common::excuteObjectSql($sql);
  266. $arrTmp = array('monitoringRules' => $monitoringRules,
  267. 'rc' => intval($rc),
  268. 'ps' => $ps,
  269. 'cp' => $cp,
  270. 'tp' => $tp
  271. );
  272. } else {
  273. $arrTmp = array('searchData' => array(),
  274. 'rc' => $rc,
  275. 'ps' => $ps,
  276. 'cp' => $cp,
  277. 'tp' => $tp,
  278. );
  279. }
  280. common::echo_json_encode(200,$arrTmp);
  281. exit();
  282. }
  283. if ($operate == "monitoring_rules_do") {
  284. $rules_type = common::check_input($_POST["rules_type"]);
  285. //检查编辑提交的Monitoring规则,是否允许保存
  286. $msg = $this->checkedMonitoringRulesSave($rules_type);
  287. if(!empty($msg)){
  288. $data = array("msg" =>$msg);
  289. common::echo_json_encode(200,$data);
  290. exit();
  291. }
  292. $updateOrInsert = "insert";
  293. if(isset($_POST['id']) && !empty($_POST['id'])){
  294. $updateOrInsert = "update";
  295. }
  296. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
  297. $rs = common::excuteUpdateSql($sql);
  298. if ($rs === FALSE){
  299. $data = array("msg" => "Update Error");
  300. } else{
  301. $data = array("msg" => "Update Successful");
  302. }
  303. common::echo_json_encode(200,$data);
  304. exit();
  305. }
  306. if ($operate == "monitoring_rules_delete"){
  307. $id = common::check_input($_POST['id']);
  308. $rules_type = common::check_input($_POST['rules_type']);
  309. $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
  310. and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id '";
  311. common::excuteUpdateSql($sql);
  312. $data = array("msg" => "Delete Successful");
  313. common::echo_json_encode(200,$data);
  314. exit();
  315. }
  316. }
  317. /**
  318. * 遍历查找对应的rule。
  319. */
  320. public function getSubscribeRules($rule_name,$subscribe_rules){
  321. //初始是不显示,没有值的情况
  322. $ret = array("is_display" => false);
  323. foreach($subscribe_rules as $rules){
  324. if($rules['rules_type'] == $rule_name){
  325. $rules["is_display"] = true;
  326. $ret = $rules;
  327. }
  328. }
  329. //Milestone Update的结构处理,处理init page load
  330. if($rule_name == "Milestone_Update"){
  331. //Milestone Update的页面配置数据
  332. $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
  333. $oceanMilestone = array();
  334. $airMilestone = array();
  335. foreach($milestones as $milestone){
  336. if($milestone['type'] == "air"){
  337. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
  338. "code"=>$milestone['code'],"description"=>$milestone['description']);
  339. }
  340. if($milestone['type'] == "ocean"){
  341. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
  342. "code"=>$milestone['code'],"description"=>$milestone['description']);
  343. }
  344. }
  345. $ret["OceanCheckBoxList"] = $oceanMilestone;
  346. $ret["AirCheckBoxList"] = $airMilestone;
  347. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  348. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  349. //转换描述,因为前端支持description,没有code的对应
  350. $oceanMilestoneDescription = $this->convertDescriptionForMilestoneAndCtnr("Milestone_Update",$oceanMilestoneSetting,$oceanMilestone);
  351. //转换描述,因为前端支持description,没有code的对应
  352. $airMilestoneDescription = $this->convertDescriptionForMilestoneAndCtnr("Milestone_Update",$airMilestoneSetting,$airMilestone);
  353. $ret["OceanCheckedList"] = $oceanMilestoneDescription;
  354. $ret["AirCheckedList"] = $airMilestoneDescription;
  355. }
  356. //Milestone Update的结构处理
  357. if($rule_name == "Container_Status_Update"){
  358. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  359. $event =$this->getEDICtnrEvent();
  360. $ctnrStatus = array();
  361. foreach($event as $e){
  362. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['description']);
  363. }
  364. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  365. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  366. //转换描述,因为前端支持description,没有code的对应
  367. $ctnrStatusDescription = $this->convertDescriptionForMilestoneAndCtnr("Container_Status_Update",$ctnrStatusSetting,$event);
  368. $ret["CtnrCheckedList"] = $ctnrStatusDescription;
  369. }
  370. return $ret;
  371. }
  372. /**
  373. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  374. * cp current_page
  375. */
  376. public function getSubscribeShipment($cp,$ps){
  377. if (empty($ps)){
  378. $ps = 20;
  379. }
  380. $sql = "select count(1) from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."'";
  381. $rc = common::excuteOneSql($sql);
  382. $tp = ceil($rc / $ps);
  383. if ($rc > 0) {
  384. $sql = "select o.h_bol,
  385. o.shipper,o.consignee,o.etd,o.eta,
  386. case when transport_mode = 'sea'
  387. then (select sn.description
  388. from public.ocean_milestone a
  389. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  390. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  391. when transport_mode = 'air' and order_from = 'public'
  392. then (select sn.description
  393. from public.air_milestone a
  394. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  395. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  396. when transport_mode = 'air' and order_from = 'sfs'
  397. then (select sn.description
  398. from sfs.air_milestone a
  399. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  400. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  401. else '' end as recent_milestone
  402. from public.kln_user_subscribed u
  403. left join public.kln_ocean o on o.serial_no in (SELECT regexp_split_to_table(subscribed_serial_no,';'))
  404. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  405. $subscribeShipment = common::excuteListSql($sql);
  406. $arrTmp = array('tableData' => $subscribeShipment,
  407. 'rc' => intval($rc),
  408. 'ps' => $ps,
  409. 'cp' => $cp,
  410. 'tp' => $tp
  411. );
  412. } else {
  413. $arrTmp = array('tableData' => array(),
  414. 'rc' => $rc,
  415. 'ps' => $ps,
  416. 'cp' => $cp,
  417. 'tp' => $tp,
  418. );
  419. }
  420. return $arrTmp;
  421. }
  422. /**
  423. * 转换描述,因为前端支持description,没有code的对应
  424. */
  425. public function convertDescriptionForMilestoneAndCtnr($type,$codeArr,$mappingData){
  426. $descriptions = array();
  427. $key = $type == "Milestone_Update" ? "code" : "event_name";
  428. foreach($codeArr as $code){
  429. foreach($mappingData as $md){
  430. if($md[$key] == $code){
  431. $descriptions[] = common::check_input($md['description']);
  432. }
  433. }
  434. }
  435. return $descriptions;
  436. }
  437. /**
  438. * 转换code,因为前端提交的是description,没有code的
  439. */
  440. public function convertCodeForMilestoneAndCtnr($type,$descriptionArr,$mappingData){
  441. $codes = array();
  442. $key = $type == "Milestone_Update" ? "code" : "event_name";
  443. foreach($descriptionArr as $description){
  444. foreach($mappingData as $md){
  445. if($md['description'] == $description){
  446. $codes[] = common::check_input($md[$key]);
  447. }
  448. }
  449. }
  450. return $codes;
  451. }
  452. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  453. $sql = "";
  454. //先删后加
  455. if($updateOrInsert == "update"){
  456. $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  457. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  458. and id = '$id';";
  459. }
  460. //这个几个参数是所有规则都有的参数
  461. $frequency_type = common::check_input($_POST['frequency_type']);
  462. $daily_time = "null";
  463. $daily_time_zone = "";
  464. $weekly_week = "";
  465. $weekly_time = "null";
  466. $weekly_time_zone = "";
  467. if(strtolower($frequency_type) == "daily"){
  468. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  469. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  470. } elseif (strtolower($frequency_type) == "weekly"){
  471. $weekly_week = common::check_input($_POST['weekly_week']);
  472. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  473. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  474. }
  475. $method_by_email = common::check_input($_POST['method_by_email']);
  476. $method_by_message = common::check_input($_POST['method_by_message']);
  477. $event_details = common::check_input($_POST['event_details']);
  478. $frequency_display = common::check_input($_POST['frequency_display']);
  479. $method_display = common::check_input($_POST['method_display']);
  480. //当规则是 Monitoring类型是,需要配置的range
  481. $shipment_transport_mode = "";
  482. $shipment_etd_limit = "";
  483. $shipment_eta_limit = "";
  484. if($notifications_type == "Monitoring"){
  485. $shipment_transport_mode = utils::implode(";",$_POST['shipment_transport_mode']);
  486. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  487. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  488. }
  489. if ($rules_type == "Milestone_Update"){
  490. //提交的description 的转换code
  491. $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
  492. $oceanMilestone = array();
  493. $airMilestone = array();
  494. foreach($milestones as $milestone){
  495. if($milestone['type'] == "air"){
  496. $airMilestone[] = $milestone;
  497. }
  498. if($milestone['type'] == "ocean"){
  499. $oceanMilestone[] = $milestone;
  500. }
  501. }
  502. $ocean_milestone = $this->convertCodeForMilestoneAndCtnr("Milestone_Update",$_POST['ocean_milestone'],$oceanMilestone);
  503. $air_milestone = $this->convertCodeForMilestoneAndCtnr("Milestone_Update",$_POST['air_milestone'],$airMilestone);
  504. $ocean_milestone = utils::implode(";",$ocean_milestone);
  505. $air_milestone = utils::implode(";",$air_milestone);
  506. $sql.="INSERT INTO public.notifications_rules(
  507. user_login, notifications_type, rules_type, ocean_milestone,
  508. air_milestone, frequency_type, daily_time, daily_time_zone,
  509. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  510. event_details, frequency_display, method_display,
  511. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  512. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  513. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  514. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  515. '$event_details', '$frequency_display', '$method_display',
  516. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  517. }
  518. if ($rules_type == "Container_Status_Update"){
  519. $event = $this->getEDICtnrEvent();
  520. $ocean_ctnr_status = $this->convertCodeForMilestoneAndCtnr("Container_Status_Update",$_POST['ocean_ctnr_status'],$event);
  521. $ocean_ctnr_status = utils::implode(";",$ocean_ctnr_status);
  522. $sql.="INSERT INTO public.notifications_rules(
  523. user_login, notifications_type, rules_type, ocean_ctnr_status,
  524. frequency_type, daily_time, daily_time_zone,
  525. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  526. event_details, frequency_display, method_display,
  527. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  528. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  529. '$frequency_type', $daily_time, '$daily_time_zone',
  530. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  531. '$event_details', '$frequency_display', '$method_display',
  532. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  533. }
  534. if ($rules_type == "Departure/Arrival_Delay"){
  535. $ocean_atd_sub_etd = $_POST['ocean_atd_sub_etd'];
  536. $ocean_atd_sub_etd_unit = $_POST['ocean_atd_sub_etd_unit'];
  537. if(!empty($ocean_atd_sub_etd_unit)){
  538. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  539. }
  540. $ocean_ata_sub_eta = $_POST['ocean_ata_sub_eta'];
  541. $ocean_ata_sub_eta_unit = $_POST['ocean_ata_sub_eta_unit'];
  542. if(!empty($ocean_ata_sub_eta_unit)){
  543. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  544. }
  545. $air_atd_sub_etd = $_POST['air_atd_sub_etd'];
  546. $air_atd_sub_etd_unit = $_POST['air_atd_sub_etd_unit'];
  547. if(!empty($air_atd_sub_etd_unit)){
  548. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  549. }
  550. $air_ata_sub_eta = $_POST['air_ata_sub_eta'];
  551. $air_ata_sub_eta_unit = $_POST['air_ata_sub_eta_unit'];
  552. if(!empty($air_ata_sub_eta_unit)){
  553. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  554. }
  555. $sql.="INSERT INTO public.notifications_rules(
  556. user_login, notifications_type, rules_type,
  557. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  558. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  559. frequency_type, daily_time, daily_time_zone,
  560. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  561. event_details, frequency_display, method_display,
  562. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  563. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  564. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  565. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  566. '$frequency_type', $daily_time, '$daily_time_zone',
  567. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  568. '$event_details', '$frequency_display', '$method_display',
  569. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  570. }
  571. if ($rules_type == "ETD/ETA_Change"){
  572. $ocean_etd_change = $_POST['ocean_etd_change'];
  573. $ocean_etd_old_sub_new = $_POST['ocean_etd_old_sub_new'];
  574. $ocean_etd_old_sub_new_unit = $_POST['ocean_etd_old_sub_new_unit'];
  575. $ocean_eta_change = $_POST['ocean_eta_change'];
  576. $ocean_eta_old_sub_new = $_POST['ocean_eta_old_sub_new'];
  577. $ocean_eta_old_sub_new_unit = $_POST['ocean_eta_old_sub_new_unit'];
  578. $air_etd_change = $_POST['air_etd_change'];
  579. $air_etd_old_sub_new = $_POST['air_etd_old_sub_new'];
  580. $air_etd_old_sub_new_unit = $_POST['air_etd_old_sub_new_unit'];
  581. $air_eta_change = $_POST['air_eta_change'];
  582. $air_eta_old_sub_new = $_POST['air_eta_old_sub_new'];
  583. $air_eta_old_sub_new_unit = $_POST['air_eta_old_sub_new_unit'];
  584. $sql.="INSERT INTO public.notifications_rules(
  585. user_login, notifications_type, rules_type,
  586. ocean_etd_change, ocean_etd_old_sub_new,ocean_etd_old_sub_new_unit,ocean_eta_change,ocean_eta_old_sub_new,ocean_eta_old_sub_new_unit,
  587. air_etd_change, air_etd_old_sub_new,air_etd_old_sub_new_unit,air_eta_change,air_eta_old_sub_new,air_eta_old_sub_new_unit,
  588. frequency_type, daily_time, daily_time_zone,
  589. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  590. event_details, frequency_display, method_display,
  591. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  592. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  593. '$ocean_etd_change','$ocean_etd_old_sub_new','$ocean_etd_old_sub_new_unit','$ocean_eta_change','$ocean_eta_old_sub_new','$ocean_eta_old_sub_new_unit',
  594. '$air_etd_change','$air_etd_old_sub_new','$air_etd_old_sub_new_unit','$air_eta_change','$air_eta_old_sub_new','$air_eta_old_sub_new_unit',
  595. '$frequency_type', $daily_time, '$daily_time_zone',
  596. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  597. '$event_details', '$frequency_display', '$method_display',
  598. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  599. }
  600. return $sql;
  601. }
  602. /**
  603. * 检查编辑提交的Monitoring规则,是否允许保存
  604. */
  605. public function checkedMonitoringRulesSave($rules_type){
  606. $sql_where = "";
  607. if(isset($_POST['id']) && !empty($_POST['id'])){
  608. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  609. }
  610. $rules = common::excuteOneSql("select * from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  611. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  612. foreach($rules as $rule){
  613. //判断range 是否一样
  614. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit");
  615. $range_flag = true;
  616. foreach($checkRangeFiled as $filed){
  617. if($filed == "shipment_transport_mode"){
  618. $postValue = utils::implode(";",$_POST[$filed]);
  619. }else{
  620. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  621. }
  622. if($postValue != $rule[$filed]){
  623. $range_flag = false;
  624. }
  625. }
  626. //判断details 是否一样
  627. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  628. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  629. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  630. "ocean_etd_change","ocean_etd_old_sub_new","ocean_etd_old_sub_new_unit","ocean_eta_change","ocean_eta_old_sub_new","ocean_eta_old_sub_new_unit",
  631. "air_etd_change","air_etd_old_sub_new","air_etd_old_sub_new_unit","air_eta_change","air_eta_old_sub_new","air_eta_old_sub_new_unit");
  632. $details_flag = true;
  633. foreach($checkDetailsFiled as $filed){
  634. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  635. $postValue = utils::implode(";",$_POST[$filed]);
  636. }else{
  637. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  638. }
  639. if($postValue != $rule[$filed]){
  640. $details_flag = false;
  641. }
  642. }
  643. //判断frequency 是否一样
  644. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  645. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  646. $frequency_flag = true;
  647. foreach($checkFrequencyFiled as $filed){
  648. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  649. if($postValue != $rule[$filed]){
  650. $frequency_flag = false;
  651. }
  652. }
  653. //判断通知方式是否一样
  654. $checkMethodFiled = array("method_by_email","method_by_message");
  655. $method_flag = true;
  656. foreach($checkMethodFiled as $filed){
  657. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  658. if($postValue != $rule[$filed]){
  659. $method_flag = false;
  660. }
  661. }
  662. //五个条件一样,不允许保存
  663. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  664. $msg = "Unable to Save";
  665. continue;
  666. }
  667. //前三个重回,后面不重合,提示但允许保存
  668. if($range_flag && $details_flag){
  669. $msg = "Similar Rule Detected";
  670. continue;
  671. }
  672. }
  673. return $msg;
  674. }
  675. /**
  676. * 这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  677. */
  678. public function getEDICtnrEvent(){
  679. $event =array(array("event_name"=>"EE","description"=>"Empty Equipment Dispatched"),array("event_name"=>"I","description"=>"Gate in full for a booking"),array("event_name"=>"AE","description"=>"Container loaded on vessel"),
  680. array("event_name"=>"VD","description"=>"Vessel Departure"),array("event_name"=>"VA_RELAY","description"=>"Arrive Relay Port"),array("event_name"=>"UV_RELAY","description"=>"Unloaded at Relay Port"),
  681. array("event_name"=>"AE_RELAY","description"=>"Loaded at Relay Port"),array("event_name"=>"VD_RELAY","description"=>"Depart Relay Port"),array("event_name"=>"CU","description"=>"Carrier and Customs Release"),
  682. array("event_name"=>"CT","description"=>"Customs release"),array("event_name"=>"CR","description"=>"Carrier release"),array("event_name"=>"VA","description"=>"Vessel Arrival"),
  683. array("event_name"=>"UV","description"=>"Unloaded From Vessel"),array("event_name"=>"AG","description"=>"Estimated Delivery"),array("event_name"=>"OA","description"=>"Gate out full from final discharge port"),
  684. array("event_name"=>"FT","description"=>"Free Time Expired"),array("event_name"=>"AL","description"=>"Container loaded on Rail"),array("event_name"=>"AR","description"=>"Container unloaded from Rail"),
  685. array("event_name"=>"AV","description"=>"Shipment available for pickup or delivery"),array("event_name"=>"D","description"=>"Gate out for delivery to customer"),array("event_name"=>"RD","description"=>"Container returned empty"),
  686. array("event_name"=>"C","description"=>"Vessel Estimated Time of Departure"),array("event_name"=>"C_RELAY","description"=>"Estimated Time of Departure from Tranship Port"),array("event_name"=>"AG_DES","description"=>"Estimated Delivery Destination"),
  687. array("event_name"=>"IFFADW","description"=>"Shipment in CFS warehouse"),array("event_name"=>"IFFDDW","description"=>"Shipment Out from CFS House"));
  688. return $event;
  689. }
  690. }
  691. ?>