tools.class.php 80 KB

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