tools.class.php 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  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 public.ra_online_user u
  128. left join public.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. $first_name = common::check_input($_POST['first_name']);
  139. $last_name = common::check_input($_POST['last_name']);
  140. $sql = "update public.ra_online_user set first_name = '$first_name',last_name = '$last_name' where lower(user_login) = '".strtolower(_getLoginName())."'";
  141. }else{
  142. $date_format = common::check_input($_REQUEST['date_format']);
  143. $numbers_format = common::check_input($_REQUEST['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_format = '$date_format',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_format', '$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_default_init"){
  158. $default_time_zone = common::check_input($_POST['default_time_zone']);
  159. $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
  160. //检查用户是否是设置过subscribe_notification
  161. $count = common::excuteOneSql("select count(*) from public.notifications_rules where
  162. notifications_type = 'Subscribe'
  163. and lower(user_login) = '".strtolower(_getLoginName())."'");
  164. if( $count > 0){
  165. } else {
  166. //手动的保存两条,通用默认规则
  167. $sql="INSERT INTO public.notifications_rules(
  168. user_login, notifications_type, rules_type, ocean_milestone,
  169. air_milestone, frequency_type, daily_time, daily_time_zone,
  170. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  171. event_details, frequency_display, method_display,shipment_details,
  172. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  173. VALUES ('"._getLoginName()."', 'Subscribe', 'Milestone_Update', 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFDEP;IFFCSN;IFFARR;IFFAFD;IFFECR;IFFDEL',
  174. 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFARR;IFFADW;IFFDDW;IFFDEL', 'Daily', '09:00', '$default_time_zone_db',
  175. '', null, '', 'false', 'true',
  176. 'Ocean Milestones: Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,On Board,Departure,Arrival Notification,Arrived at Final Discharge Port,Arrived at Final Destination,Empty Container Return,Document Turnover / Delivered;
  177. Air Milestones: Booking Confirmation,Cargo Pickup,Cargo Arrived at CFS,Departure,Landed at Destination Port,Arrived Destination Warehouse,Departed Destination Warehouse,Document Turnover / Delivered;', 'Daily, 09:00, ".$default_time_zone."', 'System Message','',
  178. '','','','','');";
  179. $sql.="INSERT INTO public.notifications_rules(
  180. user_login, notifications_type, rules_type,
  181. 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,
  182. 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,
  183. frequency_type, daily_time, daily_time_zone,
  184. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  185. event_details, frequency_display, method_display,shipment_details,
  186. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  187. VALUES ('"._getLoginName()."', 'Subscribe', 'ETD/ETA_Change',
  188. 'false','','','false','1','days',
  189. 'false','','','false','1','days',
  190. 'Daily', '09:00', '$default_time_zone_db',
  191. '', null, '', 'false', 'true',
  192. '[Ocean]ETA: Notify only when time difference ≥ 1 Day(s);
  193. [Air]ETA: Notify only when time difference ≥ 1 Day(s);', 'Daily, 09:00, ".$default_time_zone."', 'System Message','',
  194. '','','','','');";
  195. $rs = common::excuteUpdateSql($sql);
  196. if (!$rs) {
  197. $data = array("msg" => "Subscribe Notification Initialized Error");
  198. common::echo_json_encode(500,$data);
  199. exit();
  200. }
  201. }
  202. $data = array("msg"=>"Has been initialized");
  203. common::echo_json_encode(200,$data);
  204. exit();
  205. }
  206. if ($operate == "subscribe_notification_init") {
  207. $subscribur_data =array();
  208. //查询用户对应的Rule
  209. $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  210. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  211. from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
  212. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  213. $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
  214. foreach($all_rules as $rule_name){
  215. $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
  216. $subscribur_data[$rule_name] = $rules;
  217. }
  218. //整合拼接addedRules
  219. $addedRules = array();
  220. foreach($subscribe_rules as $addedRule){
  221. $addedRules[] = array(
  222. "visible" => false,
  223. "id" =>$addedRule['id'],
  224. "Event" =>$addedRule['rules_type'],
  225. "Event Details" =>$addedRule['event_details'],
  226. "Frequency" =>$addedRule['frequency_display'],
  227. "Methods" =>$addedRule['method_display']);
  228. }
  229. $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
  230. //获取subscribe shipment 当前页数cp,每页ps
  231. $subscribeShipmentWithPage = $this->getSubscribeShipment(1,15);
  232. $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
  233. common::echo_json_encode(200,$subscribur_data);
  234. exit();
  235. }
  236. if ($operate == "subscribe_notification_event_update"){
  237. $rules_type = common::check_input($_POST["rules_type"]);
  238. //判断该规则是否存在
  239. $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
  240. and lower(user_login) = '".strtolower(_getLoginName())."'");
  241. //检查参数是否正常
  242. $err = $this->checkedNotificationParam();
  243. if(!empty($err)){
  244. $data = array("msg" =>"Parameter error: ".$err);
  245. common::echo_json_encode(500,$data);
  246. exit();
  247. }
  248. $updateOrInsert = empty($exist) ? "insert" : "update";
  249. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
  250. $rs = common::excuteUpdateSql($sql);
  251. if ($rs === FALSE){
  252. $data = array("msg" => "Update Error");
  253. } else{
  254. $data = array("msg" => "Update Successful");
  255. //返回addedRules 全部列表
  256. $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
  257. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  258. //整合拼接addedRules
  259. $addedRules = array();
  260. foreach($subscribe_rules as $addedRule){
  261. $addedRules[] = array(
  262. "id" =>$addedRule['id'],
  263. "Event" =>$addedRule['rules_type'],
  264. "Event Details" =>$addedRule['event_details'],
  265. "Frequency" =>$addedRule['frequency_display'],
  266. "Methods" =>$addedRule['method_display']);
  267. }
  268. $data['addedRules'] = array("tableData"=>$addedRules);
  269. }
  270. common::echo_json_encode(200,$data);
  271. exit();
  272. }
  273. if ($operate == "subscribe_notification_rules_delete"){
  274. $rules_type = common::check_input($_POST['rules_type']);
  275. $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
  276. and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
  277. common::excuteUpdateSql($sql);
  278. $data = array("msg" => "Delete Successful");
  279. common::echo_json_encode(200,$data);
  280. exit();
  281. }
  282. if ($operate == "subscribe_shipment"){
  283. $serial_no = common::deCode($_POST['serial_no'], 'D');
  284. $is_subscribe = common::check_input($_POST['is_subscribe']);
  285. if($is_subscribe == "true"){
  286. $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
  287. if(!empty($exist)){
  288. $data = array("msg" => "Subscribe exist,Please check");
  289. common::echo_json_encode(200,$data);
  290. exit();
  291. }
  292. $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
  293. VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
  294. common::excuteUpdateSql($sql);
  295. $data = array("msg" => "Subscribe Successful");
  296. common::echo_json_encode(200,$data);
  297. exit();
  298. }else{
  299. //取消订阅
  300. $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
  301. common::excuteUpdateSql($sql);
  302. $data = array("msg" => "Cancel Subscribe successfully");
  303. common::echo_json_encode(200,$data);
  304. exit();
  305. }
  306. }
  307. if ($operate == "subscribe_shipment_search"){
  308. $cp = common::check_input($_POST ['cp']); //current_page
  309. $ps = common::check_input($_POST ['ps']); //ps
  310. $arrTmp = $this->getSubscribeShipment($cp,$ps);
  311. common::echo_json_encode(200,$arrTmp);
  312. exit();
  313. }
  314. }
  315. public function user_monitoring_setting(){
  316. $operate = utils::_get('operate');
  317. $operate = strtolower($operate);
  318. if ($operate == "monitoring_rules_init"){
  319. $ret = array();
  320. //Milestone Update的页面配置数据
  321. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  322. $oceanMilestone = array();
  323. $airMilestone = array();
  324. foreach($milestones as $milestone){
  325. if($milestone['type'] == "air"){
  326. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  327. }
  328. if($milestone['type'] == "sea"){
  329. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  330. }
  331. }
  332. $ret["OceanCheckBoxList"] = $oceanMilestone;
  333. $ret["AirCheckBoxList"] = $airMilestone;
  334. //Milestone Update的结构处理
  335. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  336. //$event =common::getEDICtnrEvent();
  337. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  338. from public.ra_online_edi_event e
  339. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  340. $ctnrStatus = array();
  341. foreach($event as $e){
  342. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  343. }
  344. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  345. common::echo_json_encode(200,$ret);
  346. exit();
  347. }
  348. if ($operate == "monitoring_rules_search") {
  349. $cp = common::check_input($_POST ['cp']); //current_page
  350. $ps = common::check_input($_POST ['ps']); //ps
  351. if (empty($ps))
  352. $ps = 15;
  353. $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
  354. $rc = common::excuteOneSql($sql);
  355. $tp = ceil($rc / $ps);
  356. if ($rc > 0) {
  357. $sql = "select *,replace(rules_type, '_', ' ') AS _rules_type_display,
  358. case when rules_type = 'Milestone_Update' then 'Milestone'
  359. when rules_type = 'Container_Status_Update' then 'Container'
  360. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  361. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  362. else '' end as notifications_option
  363. from public.notifications_rules
  364. where lower(user_login) = '".strtolower(_getLoginName())."'
  365. and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  366. $monitoringRules = common::excuteListSql($sql);
  367. $arrTmp = array('monitoringRules' => $monitoringRules,
  368. 'rc' => intval($rc),
  369. 'ps' => intval($ps),
  370. 'cp' => intval($cp),
  371. 'tp' => intval($tp)
  372. );
  373. } else {
  374. $arrTmp = array('monitoringRules' => array(),
  375. 'rc' => intval($rc),
  376. 'ps' => intval($ps),
  377. 'cp' => intval($cp),
  378. 'tp' => intval($tp)
  379. );
  380. }
  381. common::echo_json_encode(200,$arrTmp);
  382. exit();
  383. }
  384. if ($operate == "monitoring_rules_edit"){
  385. $id = $_POST['id'];
  386. $rules_type = common::check_input($_POST['rules_type']);
  387. $subscribe_rule_sql = "select *,
  388. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  389. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time,
  390. case when rules_type = 'Milestone_Update' then 'Milestone'
  391. when rules_type = 'Container_Status_Update' then 'Container'
  392. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  393. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  394. else '' end as notifications_option
  395. from public.notifications_rules where notifications_type = 'Monitoring' and lower(user_login) = '".strtolower(_getLoginName())."'
  396. and id = '$id' order by id";
  397. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  398. $rules = $this->getSubscribeRules($rules_type,$subscribe_rules);
  399. //数据转换前端需要的显示的格式
  400. $rules["shipment_transport_mode"] = utils::converModeToDisplay($rules["shipment_transport_mode"]);
  401. $monitoring_data[$rules_type] = $rules;
  402. common::echo_json_encode(200,$monitoring_data);
  403. exit();
  404. }
  405. if ($operate == "monitoring_rules_do") {
  406. $rules_type = common::check_input($_POST["rules_type"]);
  407. //检查参数是否正常
  408. $err = $this->checkedNotificationParam();
  409. if(!empty($err)){
  410. $data = array("msg" =>"Parameter error: ".$err);
  411. common::echo_json_encode(500,$data);
  412. exit();
  413. }
  414. //检查编辑提交的Monitoring规则,是否允许保存
  415. $msg = $this->checkedMonitoringRulesSave($rules_type);
  416. if(!empty($msg)){
  417. $data = array("msg" =>$msg);
  418. common::echo_json_encode(200,$data);
  419. exit();
  420. }
  421. $updateOrInsert = "insert";
  422. if(isset($_POST['id']) && !empty($_POST['id'])){
  423. $updateOrInsert = "update";
  424. }
  425. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
  426. $rs = common::excuteUpdateSql($sql);
  427. if ($rs === FALSE){
  428. $data = array("msg" => "Update Error");
  429. } else{
  430. $data = array("msg" => "Update Successful");
  431. }
  432. common::echo_json_encode(200,$data);
  433. exit();
  434. }
  435. if ($operate == "monitoring_rules_delete"){
  436. $id = common::check_input($_POST['id']);
  437. $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
  438. and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id'";
  439. common::excuteUpdateSql($sql);
  440. $data = array("msg" => "Delete Successful");
  441. common::echo_json_encode(200,$data);
  442. exit();
  443. }
  444. }
  445. public function notifications_rules(){
  446. $operate = utils::_get('operate');
  447. $operate = strtolower($operate);
  448. if ($operate == "notifications_init"){
  449. $rules_type = common::check_input($_REQUEST['rules_type']);
  450. $milestoneData = array();
  451. $containerData = array();
  452. $delayData = array();
  453. $changeData = array();
  454. if ($rules_type == "all"){
  455. $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change;Feature_Update;Passwond_Notifcations";
  456. $allData = $this->getNotifications($rules_type,"all");
  457. $milestoneData = $allData['Milestone_Update'];
  458. $containerData = $allData['Container_Status_Update'];
  459. $delayData = $allData['Departure/Arrival_Delay'];
  460. $changeData = $allData['ETD/ETA_Change'];
  461. $featureUpdate = $allData['Feature_Update'];
  462. $passwond_Notifcations = $allData['Passwond_Notifcations'];
  463. } else {
  464. $data = $this->getNotifications($rules_type,"all");
  465. if($rules_type == "Milestone_Update"){
  466. $milestoneData = $data['Milestone_Update'];
  467. }elseif($rules_type == "Container_Status_Update"){
  468. $containerData = $data['Container_Status_Update'];
  469. }elseif($rules_type == "Departure/Arrival_Delay"){
  470. $delayData = $data['Departure/Arrival_Delay'];
  471. }elseif($rules_type == "ETD/ETA_Change"){
  472. $changeData = $data['ETD/ETA_Change'];
  473. }elseif($rules_type == "Feature_Update"){
  474. $featureUpdate = $data['Feature_Update'];
  475. }elseif($rules_type == "Passwond_Notifcations"){
  476. $passwond_Notifcations = $data['Passwond_Notifcations'];
  477. }
  478. }
  479. $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,
  480. "changeData"=>$changeData,"featureUpdate"=>$featureUpdate,"passwond_Notifcations"=>$passwond_Notifcations);
  481. $instant_sum = array();
  482. foreach($data as $v){
  483. if(!empty($v['instant'])){
  484. foreach($v['instant'] as $instant){
  485. $instant_sum[] = $instant;
  486. }
  487. }
  488. if(!empty($v['daily'])){
  489. $dailys = common::handleDailyWeekedData($v['daily']);
  490. foreach($dailys as $dailyArr){
  491. //取第一组的第一个显示
  492. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
  493. $instant_sum[]= $dailyFristAndFrist;
  494. }
  495. }
  496. if(!empty($v['weekly'])){
  497. $weeklys = common::handleDailyWeekedData($v['weekly']);
  498. foreach($weeklys as $weeklyArr){
  499. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
  500. $instant_sum[]= $weeklyFristAndFrist;
  501. }
  502. }
  503. }
  504. //根据时间顺序排序
  505. $insert_dates = array_column($instant_sum, 'insert_date');
  506. array_multisort($insert_dates, SORT_DESC, $instant_sum);
  507. $info = array();
  508. foreach($instant_sum as $mInfo){
  509. $eventCard = $this->getEventCard($mInfo);
  510. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  511. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  512. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  513. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  514. }else{
  515. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  516. }
  517. }
  518. $returnData = $info;
  519. common::echo_json_encode(200,$returnData);
  520. exit();
  521. }
  522. if($operate == "notifications_see_all"){
  523. $rules_type = common::check_input($_REQUEST['rules_type']);
  524. $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
  525. $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
  526. $notificationsData = $this->getNotifications($rules_type,$frequency_type,$insert_date_format);
  527. $moreData = $notificationsData[$rules_type][strtolower($frequency_type)];
  528. //这个函数里面带有分开计数的信息
  529. $dataInfo =utils::getDailyAndweeklyFrist($moreData);
  530. $returnData = array();
  531. $notificationList = array();
  532. $ids = array();
  533. foreach($moreData as $key => $data){
  534. $eventCard = $this->getEventCard($data);
  535. //sea all的数据格式和查询全部的格式有区别
  536. if($key == 0){
  537. $returnData["title"] = $eventCard["title"];
  538. if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
  539. $returnData["etdOrdeparturNum"] = $dataInfo["numericRecords_one"];
  540. $returnData["etaOrarrivalNum"] =$dataInfo["numericRecords_two"];
  541. $returnData["type"] =$eventCard["type"];
  542. }else{
  543. $returnData["numericRecords"] = $dataInfo["numericRecords"];
  544. }
  545. }
  546. //移除不需要的字段
  547. unset($eventCard["title"]);
  548. $notificationList[] = $eventCard;
  549. $ids[] = $data['id'];
  550. }
  551. if(!empty($notificationList)){
  552. $returnData["notificationList"] = $notificationList;
  553. }
  554. //点击seall会默认全部标记为已读
  555. if(!empty($ids)){
  556. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
  557. $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
  558. common::excuteUpdateSql($markReadSql);
  559. }
  560. common::echo_json_encode(200,$returnData);
  561. exit();
  562. }
  563. if($operate == "notifications_read"){
  564. $read_type = common::check_input($_POST["read_type"]);
  565. $id = $_POST["id"];
  566. //代表改用户下的所有信息全部标记为已读
  567. if ($read_type == "true"){
  568. $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where lower(user_login) = '".strtolower(_getLoginName())."'");
  569. }else{
  570. //处理一下前端提交的不正确参数
  571. $param_id = array();
  572. foreach($id as $_ids){
  573. if(!empty($_ids)){
  574. $param_id[] = $_ids;
  575. }
  576. }
  577. if(empty($param_id)){
  578. //为空直接返回成功
  579. $returnData = array("msg" =>"Success");
  580. common::echo_json_encode(200,$returnData);
  581. }
  582. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$param_id)));
  583. $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
  584. $rs = common::excuteUpdateSql($markReadSql);
  585. }
  586. if ($rs === FALSE){
  587. $returnData = array("msg" =>"Error");
  588. common::echo_json_encode(500,$returnData);
  589. }else{
  590. $returnData = array("msg" =>"Success");
  591. common::echo_json_encode(200,$returnData);
  592. }
  593. exit();
  594. }
  595. if ($operate == "notifications_message_init"){
  596. //查询所有情况得未读情况 查询最近一年的情况
  597. $unreadSql = "with countTbale as (
  598. select ni.notifiation_type,
  599. case when COALESCE(ni.frequency_type,'') = 'Daily'
  600. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  601. when COALESCE(ni.frequency_type,'') = 'Weekly'
  602. then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
  603. || ' - ' ||
  604. to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
  605. else ''
  606. end as insert_date_format
  607. from public.kln_notifiation_info ni
  608. where ni.insert_date > NOW() - INTERVAL '1 year'
  609. and ni.notifications_method = 'true' and ni.is_send_message is null
  610. and lower(ni.user_login) = '".strtolower(_getLoginName())."'
  611. and ((ni.frequency_type = 'Daily'
  612. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  613. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  614. else
  615. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  616. end))
  617. or (ni.frequency_type = 'Weekly'
  618. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  619. and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
  620. then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
  621. else
  622. timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
  623. end)))
  624. group by ni.notifiation_type,insert_date_format
  625. union all
  626. select ni.notifiation_type, '' as insert_date_format
  627. from public.kln_notifiation_info ni
  628. where ni.insert_date > NOW() - INTERVAL '1 year'
  629. and lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  630. and ni.notifications_method = 'true' and ni.is_send_message is null
  631. and frequency_type = 'Instant'
  632. )
  633. select
  634. sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as m_rc,
  635. sum(case when (1<>1 or (notifiation_type='Container_Status_Update')) then 1 else 0 end) as cs_rc,
  636. sum(case when (1<>1 or (notifiation_type='Departure/Arrival_Delay')) then 1 else 0 end) as da_rc,
  637. sum(case when (1<>1 or (notifiation_type='ETD/ETA_Change')) then 1 else 0 end) as ec_rc,
  638. sum(case when (1<>1 or (notifiation_type='Feature_Update')) then 1 else 0 end) as f_rc
  639. from countTbale ";
  640. $count = common::excuteObjectSql($unreadSql);
  641. //单独的选中的数据
  642. $rules_type = common::check_input($_REQUEST['rules_type']);
  643. $data = $this->getNotifications($rules_type,"all");
  644. $unreadCount = 0;
  645. $readCount = 0;
  646. $instant_sum = array();
  647. if(!empty($data[$rules_type]['instant'])){
  648. foreach($data[$rules_type]['instant'] as $instant){
  649. $instant_sum[] = $instant;
  650. if(!empty($instant["is_send_message"])){
  651. $readCount +=1;
  652. }else{
  653. $unreadCount +=1;
  654. }
  655. }
  656. }
  657. if(!empty($data[$rules_type]['daily'])){
  658. $dailys = common::handleDailyWeekedData($data[$rules_type]['daily']);
  659. foreach($dailys as $dailyArr){
  660. //取第一组的第一个显示
  661. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
  662. $instant_sum[]= $dailyFristAndFrist;
  663. if(!empty($dailyFristAndFrist["is_send_message"])){
  664. $readCount +=1;
  665. }else{
  666. $unreadCount +=1;
  667. }
  668. }
  669. }
  670. if(!empty($data[$rules_type]['weekly'])){
  671. $weeklys = common::handleDailyWeekedData($data[$rules_type]['weekly']);
  672. foreach($weeklys as $weeklyArr){
  673. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
  674. $instant_sum[]= $weeklyFristAndFrist;
  675. if(!empty($weeklyFristAndFrist["is_send_message"])){
  676. $readCount +=1;
  677. }else{
  678. $unreadCount +=1;
  679. }
  680. }
  681. }
  682. //根据时间顺序排序
  683. $insert_dates = array_column($instant_sum, 'insert_date');
  684. array_multisort($insert_dates, SORT_DESC, $instant_sum);
  685. $info = array();
  686. foreach($instant_sum as $mInfo){
  687. $eventCard = $this->getEventCard($mInfo);
  688. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  689. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  690. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  691. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  692. }else{
  693. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  694. }
  695. }
  696. //返回数据结构
  697. $returnData = array();
  698. $m_rc = empty($count['m_rc']) ? 0 : intval($count['m_rc']);
  699. $cs_rc = empty($count['cs_rc']) ? 0 : intval($count['cs_rc']);
  700. $da_rc = empty($count['da_rc']) ? 0 : intval($count['da_rc']);
  701. $ec_rc = empty($count['ec_rc']) ? 0 : intval($count['ec_rc']);
  702. $f_rc = empty($count['f_rc']) ? 0 : intval($count['f_rc']);
  703. $returnData['countList'] = array($m_rc,$cs_rc,$da_rc,$ec_rc,$f_rc);
  704. $returnData['allCount'] =count($instant_sum);
  705. $returnData['unreadCount'] =$unreadCount;
  706. $returnData['readCount'] =$readCount;
  707. $returnData['cardList'] =$info;
  708. common::echo_json_encode(200,$returnData);
  709. exit();
  710. }
  711. if ($operate == "check_notifications_message"){
  712. $checkUnread = "select id
  713. from public.kln_notifiation_info ni
  714. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  715. from public.kln_ocean oo
  716. where oo.serial_no = ni.serial_no limit 1) ccc on true
  717. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  718. and (ni.frequency_type = 'Instant'
  719. or (ni.frequency_type = 'Daily'
  720. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  721. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  722. else
  723. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  724. end))
  725. or (ni.frequency_type = 'Weekly'
  726. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  727. and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
  728. then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
  729. else
  730. timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
  731. end)))
  732. and ni.notifications_method = true and is_send_message is null limit 1";
  733. $unread = common::excuteObjectSql($checkUnread);
  734. $returnData = array("has_message" =>!empty($unread));
  735. common::echo_json_encode(200,$returnData);
  736. }
  737. }
  738. /**
  739. * 遍历查找对应的rule。
  740. */
  741. public function getSubscribeRules($rule_name,$subscribe_rules){
  742. //初始是不显示,没有值的情况
  743. $ret = array("is_display" => false);
  744. foreach($subscribe_rules as $rules){
  745. if($rules['rules_type'] == $rule_name){
  746. $rules["is_display"] = true;
  747. $rules["daily_time"] = $rules["_daily_time"];
  748. $rules["weekly_time"] = $rules["_weekly_time"];
  749. $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
  750. $rules["daily_time_zone"] = utils::comvertutcinfo($rules["daily_time_zone"]);
  751. $rules["weekly_time_zone"] = utils::comvertutcinfo($rules["weekly_time_zone"]);
  752. //字符串转数字
  753. $rules["ocean_atd_sub_etd"] = common::convertoint($rules["ocean_atd_sub_etd"]);
  754. $rules["ocean_ata_sub_eta"] = common::convertoint($rules["ocean_ata_sub_eta"]);
  755. $rules["air_atd_sub_etd"] = common::convertoint($rules["air_atd_sub_etd"]);
  756. $rules["air_ata_sub_eta"] = common::convertoint($rules["air_ata_sub_eta"]);
  757. $rules["ocean_etd_old_sub_new"] = common::convertoint($rules["ocean_etd_old_sub_new"]);
  758. $rules["ocean_eta_old_sub_new"] = common::convertoint($rules["ocean_eta_old_sub_new"]);
  759. $rules["air_etd_old_sub_new"] = common::convertoint($rules["air_etd_old_sub_new"]);
  760. $rules["air_eta_old_sub_new"] = common::convertoint($rules["air_eta_old_sub_new"]);
  761. $rules["shipment_etd_limit"] = common::convertoint($rules["shipment_etd_limit"]);
  762. $rules["shipment_eta_limit"] = common::convertoint($rules["shipment_eta_limit"]);
  763. $rules["shipment_etd_limit_from"] = common::convertoint($rules["shipment_etd_limit_from"]);
  764. $rules["shipment_eta_limit_from"] = common::convertoint($rules["shipment_eta_limit_from"]);
  765. // $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  766. $rules["ocean_atd_sub_etd_unit"] = common::convertoVue($rules["ocean_atd_sub_etd_unit"]);
  767. $rules["ocean_ata_sub_eta_unit"] = common::convertoVue($rules["ocean_ata_sub_eta_unit"]);
  768. $rules["air_atd_sub_etd_unit"] = common::convertoVue($rules["air_atd_sub_etd_unit"]);
  769. $rules["air_ata_sub_eta_unit"] = common::convertoVue($rules["air_ata_sub_eta_unit"]);
  770. $rules["ocean_etd_old_sub_new_unit"] = common::convertoVue($rules["ocean_etd_old_sub_new_unit"]);
  771. $rules["ocean_eta_old_sub_new_unit"] = common::convertoVue($rules["ocean_eta_old_sub_new_unit"]);
  772. $rules["air_etd_old_sub_new_unit"] = common::convertoVue($rules["air_etd_old_sub_new_unit"]);
  773. $rules["air_eta_old_sub_new_unit"] = common::convertoVue($rules["air_eta_old_sub_new_unit"]);
  774. $ret = $rules;
  775. }
  776. }
  777. //Milestone Update的结构处理,处理init page load
  778. if($rule_name == "Milestone_Update"){
  779. //Milestone Update的页面配置数据
  780. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  781. $oceanMilestone = array();
  782. $airMilestone = array();
  783. foreach($milestones as $milestone){
  784. if($milestone['type'] == "air"){
  785. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  786. }
  787. if($milestone['type'] == "sea"){
  788. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  789. }
  790. }
  791. $ret["OceanCheckBoxList"] = $oceanMilestone;
  792. $ret["AirCheckBoxList"] = $airMilestone;
  793. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  794. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  795. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  796. $ret["AirCheckedList"] = $airMilestoneSetting;
  797. }
  798. //Milestone Update的结构处理
  799. if($rule_name == "Container_Status_Update"){
  800. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  801. //$event =common::getEDICtnrEvent();
  802. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  803. from public.ra_online_edi_event e
  804. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  805. $ctnrStatus = array();
  806. foreach($event as $e){
  807. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  808. }
  809. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  810. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  811. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  812. }
  813. return $ret;
  814. }
  815. /**
  816. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  817. * cp current_page
  818. */
  819. public function getSubscribeShipment($cp,$ps){
  820. if (empty($cp)){
  821. $cp = 1;
  822. }
  823. if (empty($ps)){
  824. $ps = 15;
  825. }
  826. $sql = "select count(1) from public.kln_user_subscribed u
  827. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  828. where lower(user_login) = '".strtolower(_getLoginName())."'";
  829. $rc = common::excuteOneSql($sql);
  830. $tp = ceil($rc / $ps);
  831. if ($rc > 0) {
  832. $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
  833. o.shipper,o.consignee,o.etd,o.eta,
  834. case when transport_mode = 'sea'
  835. then (select sn.description
  836. from public.ocean_milestone a
  837. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  838. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  839. when transport_mode = 'air' and order_from = 'public'
  840. then (select sn.description
  841. from public.air_milestone a
  842. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  843. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  844. when transport_mode = 'air' and order_from = 'sfs'
  845. then (select sn.description
  846. from sfs.air_milestone a
  847. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  848. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  849. else '' end as recent_milestone
  850. from public.kln_user_subscribed u
  851. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  852. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  853. $subscribeShipment = common::excuteListSql($sql);
  854. foreach($subscribeShipment as $key => $val){
  855. $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
  856. }
  857. $arrTmp = array('tableData' => $subscribeShipment,
  858. 'rc' => intval($rc),
  859. 'ps' => intval($ps),
  860. 'cp' => intval($cp),
  861. 'tp' => intval($tp)
  862. );
  863. } else {
  864. $arrTmp = array('tableData' => array(),
  865. 'rc' => intval($rc),
  866. 'ps' => intval($ps),
  867. 'cp' => intval($cp),
  868. 'tp' => intval($tp),
  869. );
  870. }
  871. return $arrTmp;
  872. }
  873. public function checkedNotificationParam(){
  874. $rules_type = common::check_input($_POST["rules_type"]);
  875. //先判断异常数据
  876. $msg = "";
  877. if ($rules_type == "Departure/Arrival_Delay"){
  878. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  879. if (!empty($ocean_atd_sub_etd) && !ctype_digit($ocean_atd_sub_etd)) {
  880. $msg = "Ocean Delayed(ATD-ETD) is not Number";
  881. }
  882. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  883. if (!empty($ocean_ata_sub_eta) && !ctype_digit($ocean_ata_sub_eta)) {
  884. $msg = "Ocean Delayed(ATA-ETA) is not Number";
  885. }
  886. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  887. if (!empty($air_atd_sub_etd) && !ctype_digit($air_atd_sub_etd)) {
  888. $msg = "Air Delayed(ATD-ETD) is not Number";
  889. }
  890. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  891. if (!empty($air_ata_sub_eta) && !ctype_digit($air_ata_sub_eta)) {
  892. $msg = "Air Delayed(ATA-ETA) is not Number";
  893. }
  894. }
  895. if ($rules_type == "ETD/ETA_Change"){
  896. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  897. if (!empty($ocean_etd_old_sub_new) && !ctype_digit($ocean_etd_old_sub_new)) {
  898. $msg = "Ocean Notify(ETD) is not Number";
  899. }
  900. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  901. if (!empty($ocean_eta_old_sub_new) && !ctype_digit($ocean_eta_old_sub_new)) {
  902. $msg = "Ocean Notify(ETA) is not Number";
  903. }
  904. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  905. if (!empty($air_etd_old_sub_new) && !ctype_digit($air_etd_old_sub_new)) {
  906. $msg = "Air Notify(ETD) is not Number";
  907. }
  908. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  909. if (!empty($air_eta_old_sub_new) && !ctype_digit($air_eta_old_sub_new)) {
  910. $msg = "Air Notify(ETA) is not Number";
  911. }
  912. }
  913. return $msg;
  914. }
  915. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  916. $sql = "";
  917. //先删后加 这个逻辑有移除
  918. // if($updateOrInsert == "update"){
  919. // $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  920. // and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  921. // and id = '$id';";
  922. // }
  923. //这个几个参数是所有规则都有的参数
  924. $frequency_type = common::check_input($_POST['frequency_type']);
  925. $daily_time = "null";
  926. $daily_time_zone = "";
  927. $weekly_week = "";
  928. $weekly_time = "null";
  929. $weekly_time_zone = "";
  930. if(strtolower($frequency_type) == "daily"){
  931. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  932. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  933. $daily_time_zone = utils::comvertutcinfo($daily_time_zone);
  934. } elseif (strtolower($frequency_type) == "weekly"){
  935. $weekly_week = common::check_input($_POST['weekly_week']);
  936. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  937. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  938. $weekly_time_zone = utils::comvertutcinfo($weekly_time_zone);
  939. }
  940. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  941. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  942. $event_details = common::check_input($_POST['event_details']);
  943. $frequency_display = common::check_input($_POST['frequency_display']);
  944. $method_display = common::check_input($_POST['method_display']);
  945. $shipment_detail = common::check_input($_POST['shipment_details']);
  946. //当规则是 Monitoring类型是,需要配置的range
  947. $shipment_transport_mode = "";
  948. $shipment_etd_limit = "";
  949. $shipment_eta_limit = "";
  950. $shipment_etd_limit_from = "";
  951. $shipment_eta_limit_from = "";
  952. if($notifications_type == "Monitoring"){
  953. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  954. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  955. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  956. $shipment_etd_limit_from = common::check_input($_POST['shipment_etd_limit_from']);
  957. $shipment_eta_limit_from = common::check_input($_POST['shipment_eta_limit_from']);
  958. }
  959. if ($rules_type == "Milestone_Update"){
  960. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  961. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  962. //改为update 不在是删除后添加,为了保留原始顺序
  963. if ($updateOrInsert == "update"){
  964. $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
  965. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  966. weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
  967. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  968. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  969. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  970. where rules_type = '$rules_type'
  971. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  972. and id = '$id';";
  973. } else {
  974. $sql.="INSERT INTO public.notifications_rules(
  975. user_login, notifications_type, rules_type, ocean_milestone,
  976. air_milestone, frequency_type, daily_time, daily_time_zone,
  977. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  978. event_details, frequency_display, method_display,shipment_details,
  979. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  980. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  981. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  982. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  983. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  984. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  985. }
  986. }
  987. if ($rules_type == "Container_Status_Update"){
  988. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  989. //改为update 不在是删除后添加,为了保留原始顺序
  990. if ($updateOrInsert == "update"){
  991. $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
  992. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  993. weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
  994. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  995. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  996. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  997. where rules_type = '$rules_type'
  998. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  999. and id = '$id';";
  1000. }else{
  1001. $sql.="INSERT INTO public.notifications_rules(
  1002. user_login, notifications_type, rules_type, ocean_ctnr_status,
  1003. frequency_type, daily_time, daily_time_zone,
  1004. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1005. event_details, frequency_display, method_display,shipment_details,
  1006. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1007. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  1008. '$frequency_type', $daily_time, '$daily_time_zone',
  1009. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1010. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1011. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1012. }
  1013. }
  1014. if ($rules_type == "Departure/Arrival_Delay"){
  1015. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  1016. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  1017. if(!empty($ocean_atd_sub_etd_unit)){
  1018. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1019. }
  1020. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  1021. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  1022. if(!empty($ocean_ata_sub_eta_unit)){
  1023. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1024. }
  1025. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  1026. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  1027. if(!empty($air_atd_sub_etd_unit)){
  1028. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1029. }
  1030. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  1031. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  1032. if(!empty($air_ata_sub_eta_unit)){
  1033. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1034. }
  1035. //改为update 不在是删除后添加,为了保留原始顺序
  1036. if ($updateOrInsert == "update"){
  1037. $sql.="update public.notifications_rules set
  1038. ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
  1039. ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
  1040. air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
  1041. air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
  1042. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1043. weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
  1044. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1045. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1046. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1047. where rules_type = '$rules_type'
  1048. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1049. and id = '$id';";
  1050. }else{
  1051. $sql.="INSERT INTO public.notifications_rules(
  1052. user_login, notifications_type, rules_type,
  1053. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  1054. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  1055. frequency_type, daily_time, daily_time_zone,
  1056. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1057. event_details, frequency_display, method_display,shipment_details,
  1058. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1059. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1060. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  1061. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  1062. '$frequency_type', $daily_time, '$daily_time_zone',
  1063. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1064. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1065. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1066. }
  1067. }
  1068. if ($rules_type == "ETD/ETA_Change"){
  1069. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  1070. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  1071. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  1072. if(!empty($ocean_etd_old_sub_new_unit)){
  1073. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1074. }
  1075. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  1076. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  1077. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  1078. if(!empty($ocean_eta_old_sub_new_unit)){
  1079. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1080. }
  1081. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  1082. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  1083. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  1084. if(!empty($air_etd_old_sub_new_unit)){
  1085. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1086. }
  1087. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  1088. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  1089. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  1090. if(!empty($air_eta_old_sub_new_unit)){
  1091. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1092. }
  1093. //改为update 不在是删除后添加,为了保留原始顺序
  1094. if ($updateOrInsert == "update"){
  1095. $sql.="update public.notifications_rules set
  1096. ocean_etd_change = '$ocean_etd_change',ocean_etd_old_sub_new = '$ocean_etd_old_sub_new',ocean_etd_old_sub_new_unit = '$ocean_etd_old_sub_new_unit',
  1097. ocean_eta_change = '$ocean_eta_change',ocean_eta_old_sub_new = '$ocean_eta_old_sub_new',ocean_eta_old_sub_new_unit = '$ocean_eta_old_sub_new_unit',
  1098. air_etd_change = '$air_etd_change',air_etd_old_sub_new = '$air_etd_old_sub_new',air_etd_old_sub_new_unit = '$air_etd_old_sub_new_unit',
  1099. air_eta_change = '$air_eta_change',air_eta_old_sub_new = '$air_eta_old_sub_new',air_eta_old_sub_new_unit = '$air_eta_old_sub_new_unit',
  1100. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1101. weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
  1102. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1103. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1104. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1105. where rules_type = '$rules_type'
  1106. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1107. and id = '$id';";
  1108. }else{
  1109. $sql.="INSERT INTO public.notifications_rules(
  1110. user_login, notifications_type, rules_type,
  1111. 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,
  1112. 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,
  1113. frequency_type, daily_time, daily_time_zone,
  1114. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1115. event_details, frequency_display, method_display,shipment_details,
  1116. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1117. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1118. '$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',
  1119. '$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',
  1120. '$frequency_type', $daily_time, '$daily_time_zone',
  1121. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1122. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1123. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1124. }
  1125. }
  1126. //保存用户默认的时区
  1127. $default_time_zone = common::check_input($_POST['default_time_zone']);
  1128. $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
  1129. $sql .= "update public.kln_user_extend set default_time_zone = '$default_time_zone_db' where lower(user_login) = '".strtolower(_getLoginName())."';";
  1130. return $sql;
  1131. }
  1132. /**
  1133. * 检查编辑提交的Monitoring规则,是否允许保存
  1134. */
  1135. public function checkedMonitoringRulesSave($rules_type){
  1136. $sql_where = "";
  1137. if(isset($_POST['id']) && !empty($_POST['id'])){
  1138. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  1139. }
  1140. $rules = common::excuteListSql("select *,
  1141. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  1142. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  1143. from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  1144. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  1145. foreach($rules as $rule){
  1146. //判断range 是否一样
  1147. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit","shipment_etd_limit_from","shipment_eta_limit_from");
  1148. $range_flag = true;
  1149. foreach($checkRangeFiled as $filed){
  1150. if($filed == "shipment_transport_mode"){
  1151. $postValue = utils::converModeToDB($_POST[$filed]);
  1152. $rule_mode_arr = explode(";", $rule[$filed]);
  1153. $post_mode_arr = explode(";", $postValue);
  1154. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1155. $range_flag = false;
  1156. }
  1157. }else{
  1158. //正常字段直接比较就行
  1159. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1160. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1161. if($postValue != $dbValue){
  1162. $range_flag = false;
  1163. }
  1164. }
  1165. }
  1166. //判断details 是否一样
  1167. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  1168. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  1169. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  1170. "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",
  1171. "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");
  1172. $details_flag = true;
  1173. foreach($checkDetailsFiled as $filed){
  1174. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  1175. $rule_mode_arr = empty($rule[$filed])? array() :explode(";", $rule[$filed]);
  1176. $post_mode_arr = $_POST[$filed];
  1177. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1178. $details_flag = false;
  1179. }
  1180. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  1181. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  1182. if($post_boolean != $rule[$filed]){
  1183. $details_flag = false;
  1184. }
  1185. } elseif ($filed == "ocean_atd_sub_etd_unit" || $filed == "ocean_ata_sub_eta_unit"
  1186. || $filed == "air_atd_sub_etd_unit" || $filed == "air_ata_sub_eta_unit"
  1187. || $filed == "ocean_etd_old_sub_new_unit" || $filed == "ocean_eta_old_sub_new_unit"
  1188. || $filed == "air_etd_old_sub_new_unit" || $filed == "air_eta_old_sub_new_unit"){
  1189. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1190. if(!empty($postValue)){
  1191. $postValue = $postValue=="Day(s)" ? "days":"hours";
  1192. }
  1193. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1194. if($postValue != $dbValue){
  1195. $details_flag = false;
  1196. }
  1197. } else {
  1198. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1199. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1200. if($postValue != $dbValue){
  1201. $details_flag = false;
  1202. }
  1203. }
  1204. }
  1205. //判断frequency 是否一样
  1206. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  1207. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  1208. $frequency_flag = true;
  1209. foreach($checkFrequencyFiled as $filed){
  1210. if($filed == "daily_time" || $filed == "weekly_time"){
  1211. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1212. //_daily_time _weekly_time
  1213. $dbValue = !empty($rule["_".$filed]) ? $rule["_".$filed] : "";
  1214. if($postValue != $dbValue){
  1215. $frequency_flag = false;
  1216. }
  1217. } else {
  1218. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1219. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1220. if($postValue != $dbValue){
  1221. $frequency_flag = false;
  1222. }
  1223. }
  1224. }
  1225. //判断通知方式是否一样
  1226. $checkMethodFiled = array("method_by_email","method_by_message");
  1227. $method_flag = true;
  1228. foreach($checkMethodFiled as $filed){
  1229. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  1230. if($postValue != $rule[$filed]){
  1231. $method_flag = false;
  1232. }
  1233. }
  1234. //五个条件一样,不允许保存
  1235. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  1236. $msg = "Unable to Save";
  1237. break;
  1238. }
  1239. //前三个重回,后面不重合,提示但允许保存
  1240. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  1241. $msg = "Similar Rule Detected";
  1242. break;
  1243. }
  1244. }
  1245. return $msg;
  1246. }
  1247. public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
  1248. if ($frequency_type == "all"){
  1249. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1250. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1251. $sql_where = " and (ni.frequency_type = 'Instant'
  1252. or (ni.frequency_type = 'Daily'
  1253. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1254. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1255. else
  1256. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1257. end))
  1258. or (ni.frequency_type = 'Weekly'
  1259. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1260. and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
  1261. then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
  1262. else
  1263. timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
  1264. end)))";
  1265. } elseif($frequency_type == "Daily"){
  1266. $sql_where = " and (ni.frequency_type = 'Daily'
  1267. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1268. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1269. else
  1270. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1271. end))";
  1272. } elseif($frequency_type == "Weekly"){
  1273. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1274. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1275. // 如今天是4-14,最小边界值是4.8- 4.14
  1276. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1277. // 当 前时间是 4.15时,但到规定的time,取4.15
  1278. $sql_where = " and (ni.frequency_type = 'Weekly'
  1279. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1280. and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
  1281. then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
  1282. else
  1283. timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
  1284. end))";
  1285. }
  1286. if (!empty($_REQUEST['current_time'])){
  1287. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1288. // and ni.is_send_message is null";
  1289. //这里都以服务器时间,检查标准
  1290. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
  1291. }
  1292. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1293. $sql_where .= " and ni.is_send_message is null";
  1294. }
  1295. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  1296. $aa_where = "";
  1297. if (!empty($insert_date_format)){
  1298. $aa_where = " where insert_date_format = '$insert_date_format'";
  1299. }
  1300. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1301. $sql = "select *
  1302. from (select ni.*,
  1303. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1304. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1305. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1306. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1307. else 0
  1308. end as _delay_diff,
  1309. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1310. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1311. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1312. then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
  1313. || ' - ' ||
  1314. to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
  1315. else ''
  1316. end as insert_date_format,
  1317. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1318. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1319. when COALESCE(ni.frequency_type,'') = 'Daily'
  1320. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1321. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1322. then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
  1323. else ''
  1324. end as first_notifiation_date,
  1325. case when ni.notifiation_type ='Milestone_Update'
  1326. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1327. else ''
  1328. end as milestone_previous_json,
  1329. case when ni.notifiation_type ='Container_Status_Update'
  1330. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1331. else ''
  1332. end as ctnr_previous_json,
  1333. case when ni.notifiation_type ='Container_Status_Update'
  1334. then (select description
  1335. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1336. else ''
  1337. end as ctnr_desc,
  1338. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  1339. from public.kln_notifiation_info ni
  1340. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1341. from public.kln_ocean oo
  1342. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1343. left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
  1344. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1345. and ni.insert_date > NOW() - INTERVAL '1 year'
  1346. and lower(ni.notifiation_type) in ($more_param)
  1347. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
  1348. error_log($sql);
  1349. $data_all_type = common::excuteListSql($sql);
  1350. $data_group = array();
  1351. $data_group_uniqe = array();
  1352. foreach($data_all_type as $dat){
  1353. $uniqe_group_str = $dat['notifiation_type'];
  1354. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  1355. $tempArr = $data_group[$uniqe_group_str];
  1356. $tempArr[] = $dat;
  1357. $data_group[$uniqe_group_str] = $tempArr;
  1358. } else {
  1359. $data_group[$uniqe_group_str] = array($dat);
  1360. $data_group_uniqe[] = $uniqe_group_str;
  1361. }
  1362. }
  1363. $retData = array();
  1364. foreach($data_group as $key => $data){
  1365. $notifiation_type_db = $key;
  1366. //统一处理数据Instant Daily weekly_week 先分开在处理
  1367. $instant = array();
  1368. $daily = array();
  1369. $daily_uniqe = array();
  1370. $weekly = array();
  1371. $weekly_uniqe = array();
  1372. foreach($data as $d){
  1373. if ($d['frequency_type'] == "Instant"){
  1374. $instant[] = $d;
  1375. }
  1376. //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  1377. $uniqe_str = $d['serial_no'];
  1378. if ($notifiation_type_db == "Milestone_Update"){
  1379. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
  1380. }else if ($notifiation_type_db == "Container_Status_Update"){
  1381. $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
  1382. }else if($notifiation_type_db == "Departure/Arrival_Delay"){
  1383. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
  1384. }else if($notifiation_type_db == "ETD/ETA_Change"){
  1385. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
  1386. }
  1387. if ($d['frequency_type'] == "Daily"){
  1388. if(!utils::in_array($uniqe_str,$daily_uniqe)){
  1389. $daily[$uniqe_str] = $d;
  1390. $daily_uniqe[] = $uniqe_str;
  1391. }
  1392. }
  1393. if ($d['frequency_type'] == "Weekly"){
  1394. if(!utils::in_array($uniqe_str,$weekly_uniqe)){
  1395. $weekly[$uniqe_str] = $d;
  1396. $weekly_uniqe[] = $uniqe_str;
  1397. }
  1398. }
  1399. }
  1400. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
  1401. }
  1402. return $retData;
  1403. }
  1404. public function getEventCard($mInfo){
  1405. $eventCard = array();
  1406. $notifiation_type = $mInfo['notifiation_type'];
  1407. if($notifiation_type == "Milestone_Update"){
  1408. $eventCard = array("type" =>'milestone',
  1409. "numericRecords"=>0,
  1410. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1411. "title"=>"Milestone Update",
  1412. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1413. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  1414. "tag"=>$mInfo["milestone_description"],
  1415. "location"=>$mInfo["milestone_locations"],
  1416. "timezone"=>$mInfo["milestone_timezone"],
  1417. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  1418. "timeLabel"=>"",
  1419. "previous"=>"",
  1420. "frequency_type"=>$mInfo["frequency_type"],
  1421. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1422. "order_from"=>$mInfo["order_from"],
  1423. "id"=>$mInfo["id"],
  1424. "insert_date_format"=>'',
  1425. "rules_type"=>$mInfo["notifiation_type"],
  1426. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  1427. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1428. "info"=>new stdClass());
  1429. if ($mInfo["frequency_type"] == "Daily"){
  1430. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1431. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  1432. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1433. //seeall 的时候,前端不需要id
  1434. $eventCard["id"] = '';
  1435. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1436. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1437. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1438. "date" => $milestone_previous['milestone']['milestone_date'],
  1439. "time" => $milestone_previous['milestone']['milestone_time'],
  1440. "timezone" =>$milestone_previous['milestone']['timezone']);
  1441. }
  1442. } else if($mInfo["frequency_type"] == "Weekly"){
  1443. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1444. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1445. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1446. //seeall 的时候,前端不需要id
  1447. $eventCard["id"] = '';
  1448. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1449. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1450. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1451. "date" => $milestone_previous['milestone']['milestone_date'],
  1452. "time" => $milestone_previous['milestone']['milestone_time'],
  1453. "timezone" =>$milestone_previous['milestone']['timezone']);
  1454. }
  1455. }
  1456. }
  1457. if($notifiation_type == "Container_Status_Update"){
  1458. //当前状态的描述ctnr_desc
  1459. //$ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  1460. $eventCard = array("type" =>'container',
  1461. "numericRecords"=>0,
  1462. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1463. "title"=>"Container_Status_Update",
  1464. "mode"=>"Ocean Freight",
  1465. "no"=>$mInfo["ctnr"],
  1466. "tag"=>$mInfo["ctnr_desc"],
  1467. "location"=>$mInfo["ctnr_status_locations"],
  1468. "timezone"=>$mInfo["ctnr_status_timezone"],
  1469. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  1470. "timeLabel"=>"",
  1471. "previous"=>"",
  1472. "frequency_type"=>$mInfo["frequency_type"],
  1473. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1474. "order_from"=>$mInfo["order_from"],
  1475. "id"=>$mInfo["id"],
  1476. "insert_date_format"=>'',
  1477. "rules_type"=>$mInfo["notifiation_type"],
  1478. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1479. "info"=>new stdClass());
  1480. if ($mInfo["frequency_type"] == "Daily"){
  1481. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1482. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1483. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1484. //seeall 的时候,前端不需要id
  1485. $eventCard["id"] = '';
  1486. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  1487. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  1488. //当前状态 前一个的描述
  1489. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  1490. "date" => $ctnr_previous["ctnrStatus"]["date"],
  1491. "time" => $ctnr_previous["ctnrStatus"]["time"],
  1492. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  1493. }
  1494. } else if($mInfo["frequency_type"] == "Weekly"){
  1495. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1496. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1497. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1498. //seeall 的时候,前端不需要id
  1499. $eventCard["id"] = '';
  1500. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  1501. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  1502. //当前状态 前一个的描述
  1503. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  1504. "date" => $ctnr_previous["ctnrStatus"]["date"],
  1505. "time" => $ctnr_previous["ctnrStatus"]["time"],
  1506. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  1507. }
  1508. }
  1509. }
  1510. if($notifiation_type == "Departure/Arrival_Delay"){
  1511. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  1512. $title = $mInfo["delay_name"];
  1513. $outsideLocation = "";
  1514. $outsideTimezone = "";
  1515. $outsideTimeLabel= "";
  1516. $insideTimeLabel= "";
  1517. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  1518. $outsideTimeLabel = "ETD";
  1519. $insideTimeLabel = "ATD";
  1520. }
  1521. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  1522. $outsideTimeLabel = "ETA";
  1523. $insideTimeLabel = "ATA";
  1524. }
  1525. //直航的的
  1526. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  1527. $outsideLocation = $mInfo["delay_locations_from"];
  1528. }
  1529. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  1530. $outsideLocation = $mInfo["delay_locations_to"];
  1531. }
  1532. $route = array();
  1533. $leg = array();
  1534. if($mInfo["delay_is_direct"] <>'t'){
  1535. $title = substr($mInfo["delay_name"],8);
  1536. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1537. //当前current Leg
  1538. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  1539. if($mInfo["delay_current"] == "2"){
  1540. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1541. }
  1542. }
  1543. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  1544. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  1545. $delay_diff = $mInfo["_delay_diff"];
  1546. $delay_unit = $mInfo["delay_unit"];
  1547. $eventCard = array("type" =>'delay',
  1548. "numericRecords"=>0,
  1549. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1550. "title"=>$title,
  1551. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1552. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  1553. //第一个字母大写
  1554. "tag"=>ucfirst($mInfo["delay_name"]),
  1555. "location"=>$outsideLocation,
  1556. "timezone"=>$mInfo["delay_timezone"],
  1557. "time"=>$est_date,
  1558. "timeLabel"=>$outsideTimeLabel,
  1559. "previous"=>"",
  1560. "frequency_type"=>$mInfo["frequency_type"],
  1561. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1562. "order_from"=>$mInfo["order_from"],
  1563. "id"=>$mInfo["id"],
  1564. "insert_date_format"=>'',
  1565. "rules_type"=>$mInfo["notifiation_type"],
  1566. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  1567. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1568. "info"=>array("route"=>$route,
  1569. "leg"=>$leg,
  1570. "etdOrdeparturNum"=>0,
  1571. "etaOrarrivalNum"=>0,
  1572. "time"=>$act_date,
  1573. "timeLabel"=>$insideTimeLabel,
  1574. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  1575. "timezone"=>$mInfo["delay_timezone"]
  1576. ));
  1577. if ($mInfo["frequency_type"] == "Daily"){
  1578. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1579. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1580. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1581. $eventCard["title"] = "Delay Daily Summary(".$mInfo["insert_date_format"].")";
  1582. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1583. //seeall 的时候,前端不需要id
  1584. $eventCard["id"] = '';
  1585. } else if($mInfo["frequency_type"] == "Weekly"){
  1586. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1587. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1588. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1589. $eventCard["title"] = "Delay Weekly Summary(".$mInfo["insert_date_format"].")";
  1590. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1591. //seeall 的时候,前端不需要id
  1592. $eventCard["id"] = '';
  1593. }
  1594. }
  1595. if($notifiation_type == "ETD/ETA_Change"){
  1596. $title = $mInfo["date_change_name"];
  1597. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  1598. $outsideTimeLabel = "Original ETD";
  1599. $insideTimeLabel = "Updated ETD";
  1600. }
  1601. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  1602. $outsideTimeLabel = "Original ETA";
  1603. $insideTimeLabel = "Updated ETA";
  1604. }
  1605. if($mInfo["date_change_is_direct"] <>'t'){
  1606. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  1607. $title = substr($mInfo["date_change_name"],8);
  1608. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1609. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  1610. if($mInfo["date_change_current"] == "2"){
  1611. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1612. }
  1613. }
  1614. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  1615. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  1616. $eventCard = array("type" =>'change',
  1617. "numericRecords"=>0,
  1618. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1619. "title"=>$title,
  1620. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1621. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  1622. "tag"=>ucfirst($mInfo["date_change_name"]),
  1623. "location"=>"",
  1624. "timezone"=>$mInfo["date_change_timezone"],
  1625. "time"=>$original_date,
  1626. "timeLabel"=>$outsideTimeLabel,
  1627. "previous"=>"",
  1628. "frequency_type"=>$mInfo["frequency_type"],
  1629. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1630. "order_from"=>$mInfo["order_from"],
  1631. "id"=>$mInfo["id"],
  1632. "insert_date_format"=>'',
  1633. "rules_type"=>$mInfo["notifiation_type"],
  1634. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  1635. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1636. "info"=>array("route"=>$route,
  1637. "leg"=>$leg,
  1638. "etdOrdeparturNum"=>0,
  1639. "etaOrarrivalNum"=>0,
  1640. "time"=>$updated_date,
  1641. "timeLabel"=>$insideTimeLabel,
  1642. "delayTimeTip"=>"",
  1643. "timezone"=>$mInfo["date_change_timezone"]
  1644. ));
  1645. if ($mInfo["frequency_type"] == "Daily"){
  1646. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1647. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1648. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1649. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  1650. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1651. $eventCard["id"] = "";
  1652. } else if($mInfo["frequency_type"] == "Weekly"){
  1653. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1654. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1655. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1656. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  1657. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1658. $eventCard["id"] = "";
  1659. }
  1660. }
  1661. if($notifiation_type == "Feature_Update" || $notifiation_type == "Passwond_Notifcations"){
  1662. $title = $mInfo["other_type"] == "password" ? "Password Notifications" : "Feature Update";
  1663. $isExpiration = false;
  1664. if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
  1665. $isExpiration = true;
  1666. }
  1667. $eventCard = array(
  1668. "title" => $title,
  1669. "id"=> $mInfo["id"],
  1670. "header"=> $mInfo["other_name"],
  1671. "content"=>$mInfo["other_desc"],
  1672. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1673. "isExpiration"=> $isExpiration,
  1674. "rules_type"=>$mInfo["notifiation_type"],
  1675. "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$mInfo["id"].".jpg",
  1676. "view_more_link" =>"main_new_version.php?action=feature_update&id=".$mInfo["id"]
  1677. );
  1678. }
  1679. return $eventCard;
  1680. }
  1681. /**
  1682. * 返回当前柜子的status信息描述,目前作废
  1683. */
  1684. public static function getContainerStatusDesc($ctnr_status_code){
  1685. $event =common::getEDICtnrEvent();
  1686. $ctnrStatusdesc = "";
  1687. foreach($event as $e){
  1688. if($e['event_name'] == $ctnr_status_code){
  1689. $ctnrStatusdesc = $e['description'];
  1690. }
  1691. }
  1692. return $ctnrStatusdesc;
  1693. }
  1694. }
  1695. ?>