tools.class.php 99 KB

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