tools.class.php 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  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. $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. //字符串转数字
  648. $rules["ocean_atd_sub_etd"] = common::convertoint($rules["ocean_atd_sub_etd"]);
  649. $rules["ocean_ata_sub_eta"] = common::convertoint($rules["ocean_ata_sub_eta"]);
  650. $rules["air_atd_sub_etd"] = common::convertoint($rules["air_atd_sub_etd"]);
  651. $rules["air_ata_sub_eta"] = common::convertoint($rules["air_ata_sub_eta"]);
  652. $rules["ocean_etd_old_sub_new"] = common::convertoint($rules["ocean_etd_old_sub_new"]);
  653. $rules["ocean_eta_old_sub_new"] = common::convertoint($rules["ocean_eta_old_sub_new"]);
  654. $rules["air_etd_old_sub_new"] = common::convertoint($rules["air_etd_old_sub_new"]);
  655. $rules["air_eta_old_sub_new"] = common::convertoint($rules["air_eta_old_sub_new"]);
  656. $rules["shipment_etd_limit"] = common::convertoint($rules["shipment_etd_limit"]);
  657. $rules["shipment_eta_limit"] = common::convertoint($rules["shipment_eta_limit"]);
  658. $rules["shipment_etd_limit_from"] = common::convertoint($rules["shipment_etd_limit_from"]);
  659. $rules["shipment_eta_limit_from"] = common::convertoint($rules["shipment_eta_limit_from"]);
  660. // $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  661. $rules["ocean_atd_sub_etd_unit"] = common::convertoVue($rules["ocean_atd_sub_etd_unit"]);
  662. $rules["ocean_ata_sub_eta_unit"] = common::convertoVue($rules["ocean_ata_sub_eta_unit"]);
  663. $rules["air_atd_sub_etd_unit"] = common::convertoVue($rules["air_atd_sub_etd_unit"]);
  664. $rules["air_ata_sub_eta_unit"] = common::convertoVue($rules["air_ata_sub_eta_unit"]);
  665. $rules["ocean_etd_old_sub_new_unit"] = common::convertoVue($rules["ocean_etd_old_sub_new_unit"]);
  666. $rules["ocean_eta_old_sub_new_unit"] = common::convertoVue($rules["ocean_eta_old_sub_new_unit"]);
  667. $rules["air_etd_old_sub_new_unit"] = common::convertoVue($rules["air_etd_old_sub_new_unit"]);
  668. $rules["air_eta_old_sub_new_unit"] = common::convertoVue($rules["air_eta_old_sub_new_unit"]);
  669. $ret = $rules;
  670. }
  671. }
  672. //Milestone Update的结构处理,处理init page load
  673. if($rule_name == "Milestone_Update"){
  674. //Milestone Update的页面配置数据
  675. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  676. $oceanMilestone = array();
  677. $airMilestone = array();
  678. foreach($milestones as $milestone){
  679. if($milestone['type'] == "air"){
  680. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  681. }
  682. if($milestone['type'] == "sea"){
  683. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  684. }
  685. }
  686. $ret["OceanCheckBoxList"] = $oceanMilestone;
  687. $ret["AirCheckBoxList"] = $airMilestone;
  688. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  689. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  690. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  691. $ret["AirCheckedList"] = $airMilestoneSetting;
  692. }
  693. //Milestone Update的结构处理
  694. if($rule_name == "Container_Status_Update"){
  695. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  696. //$event =common::getEDICtnrEvent();
  697. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  698. from public.ra_online_edi_event e
  699. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  700. $ctnrStatus = array();
  701. foreach($event as $e){
  702. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  703. }
  704. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  705. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  706. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  707. }
  708. return $ret;
  709. }
  710. /**
  711. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  712. * cp current_page
  713. */
  714. public function getSubscribeShipment($cp,$ps){
  715. if (empty($cp)){
  716. $cp = 1;
  717. }
  718. if (empty($ps)){
  719. $ps = 15;
  720. }
  721. $sql = "select count(1) from public.kln_user_subscribed u
  722. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  723. where lower(user_login) = '".strtolower(_getLoginName())."'";
  724. $rc = common::excuteOneSql($sql);
  725. $tp = ceil($rc / $ps);
  726. if ($rc > 0) {
  727. $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
  728. o.shipper,o.consignee,o.etd,o.eta,
  729. case when transport_mode = 'sea'
  730. then (select sn.description
  731. from public.ocean_milestone a
  732. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  733. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  734. when transport_mode = 'air' and order_from = 'public'
  735. then (select sn.description
  736. from public.air_milestone a
  737. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  738. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  739. when transport_mode = 'air' and order_from = 'sfs'
  740. then (select sn.description
  741. from sfs.air_milestone a
  742. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  743. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  744. else '' end as recent_milestone
  745. from public.kln_user_subscribed u
  746. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  747. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  748. $subscribeShipment = common::excuteListSql($sql);
  749. foreach($subscribeShipment as $key => $val){
  750. $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
  751. }
  752. $arrTmp = array('tableData' => $subscribeShipment,
  753. 'rc' => intval($rc),
  754. 'ps' => intval($ps),
  755. 'cp' => intval($cp),
  756. 'tp' => intval($tp)
  757. );
  758. } else {
  759. $arrTmp = array('tableData' => array(),
  760. 'rc' => intval($rc),
  761. 'ps' => intval($ps),
  762. 'cp' => intval($cp),
  763. 'tp' => intval($tp),
  764. );
  765. }
  766. return $arrTmp;
  767. }
  768. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  769. $sql = "";
  770. //先删后加 这个逻辑有移除
  771. // if($updateOrInsert == "update"){
  772. // $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  773. // and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  774. // and id = '$id';";
  775. // }
  776. //这个几个参数是所有规则都有的参数
  777. $frequency_type = common::check_input($_POST['frequency_type']);
  778. $daily_time = "null";
  779. $daily_time_zone = "";
  780. $weekly_week = "";
  781. $weekly_time = "null";
  782. $weekly_time_zone = "";
  783. if(strtolower($frequency_type) == "daily"){
  784. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  785. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  786. } elseif (strtolower($frequency_type) == "weekly"){
  787. $weekly_week = common::check_input($_POST['weekly_week']);
  788. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  789. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  790. }
  791. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  792. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  793. $event_details = common::check_input($_POST['event_details']);
  794. $frequency_display = common::check_input($_POST['frequency_display']);
  795. $method_display = common::check_input($_POST['method_display']);
  796. $shipment_detail = common::check_input($_POST['shipment_details']);
  797. //当规则是 Monitoring类型是,需要配置的range
  798. $shipment_transport_mode = "";
  799. $shipment_etd_limit = "";
  800. $shipment_eta_limit = "";
  801. $shipment_etd_limit_from = "";
  802. $shipment_eta_limit_from = "";
  803. if($notifications_type == "Monitoring"){
  804. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  805. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  806. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  807. $shipment_etd_limit_from = common::check_input($_POST['shipment_etd_limit_from']);
  808. $shipment_eta_limit_from = common::check_input($_POST['shipment_eta_limit_from']);
  809. }
  810. if ($rules_type == "Milestone_Update"){
  811. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  812. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  813. //改为update 不在是删除后添加,为了保留原始顺序
  814. if ($updateOrInsert == "update"){
  815. $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
  816. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  817. 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',
  818. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  819. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  820. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  821. where rules_type = '$rules_type'
  822. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  823. and id = '$id';";
  824. } else {
  825. $sql.="INSERT INTO public.notifications_rules(
  826. user_login, notifications_type, rules_type, ocean_milestone,
  827. air_milestone, frequency_type, daily_time, daily_time_zone,
  828. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  829. event_details, frequency_display, method_display,shipment_details,
  830. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  831. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  832. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  833. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  834. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  835. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  836. }
  837. }
  838. if ($rules_type == "Container_Status_Update"){
  839. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  840. //改为update 不在是删除后添加,为了保留原始顺序
  841. if ($updateOrInsert == "update"){
  842. $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
  843. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  844. 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',
  845. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  846. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  847. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  848. where rules_type = '$rules_type'
  849. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  850. and id = '$id';";
  851. }else{
  852. $sql.="INSERT INTO public.notifications_rules(
  853. user_login, notifications_type, rules_type, ocean_ctnr_status,
  854. frequency_type, daily_time, daily_time_zone,
  855. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  856. event_details, frequency_display, method_display,shipment_details,
  857. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  858. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  859. '$frequency_type', $daily_time, '$daily_time_zone',
  860. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  861. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  862. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  863. }
  864. }
  865. if ($rules_type == "Departure/Arrival_Delay"){
  866. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  867. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  868. if(!empty($ocean_atd_sub_etd_unit)){
  869. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  870. }
  871. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  872. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  873. if(!empty($ocean_ata_sub_eta_unit)){
  874. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  875. }
  876. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  877. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  878. if(!empty($air_atd_sub_etd_unit)){
  879. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  880. }
  881. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  882. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  883. if(!empty($air_ata_sub_eta_unit)){
  884. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  885. }
  886. //改为update 不在是删除后添加,为了保留原始顺序
  887. if ($updateOrInsert == "update"){
  888. $sql.="update public.notifications_rules set
  889. ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
  890. ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
  891. air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
  892. air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
  893. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  894. 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',
  895. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  896. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  897. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  898. where rules_type = '$rules_type'
  899. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  900. and id = '$id';";
  901. }else{
  902. $sql.="INSERT INTO public.notifications_rules(
  903. user_login, notifications_type, rules_type,
  904. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  905. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  906. 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',
  911. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  912. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  913. '$frequency_type', $daily_time, '$daily_time_zone',
  914. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  915. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  916. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  917. }
  918. }
  919. if ($rules_type == "ETD/ETA_Change"){
  920. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  921. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  922. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  923. if(!empty($ocean_etd_old_sub_new_unit)){
  924. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  925. }
  926. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  927. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  928. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  929. if(!empty($ocean_eta_old_sub_new_unit)){
  930. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  931. }
  932. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  933. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  934. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  935. if(!empty($air_etd_old_sub_new_unit)){
  936. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  937. }
  938. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  939. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  940. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  941. if(!empty($air_eta_old_sub_new_unit)){
  942. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  943. }
  944. //改为update 不在是删除后添加,为了保留原始顺序
  945. if ($updateOrInsert == "update"){
  946. $sql.="update public.notifications_rules set
  947. 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',
  948. 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',
  949. 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',
  950. 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',
  951. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  952. 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',
  953. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  954. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  955. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  956. where rules_type = '$rules_type'
  957. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  958. and id = '$id';";
  959. }else{
  960. $sql.="INSERT INTO public.notifications_rules(
  961. user_login, notifications_type, rules_type,
  962. 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,
  963. 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,
  964. frequency_type, daily_time, daily_time_zone,
  965. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  966. event_details, frequency_display, method_display,shipment_details,
  967. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  968. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  969. '$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',
  970. '$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',
  971. '$frequency_type', $daily_time, '$daily_time_zone',
  972. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  973. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  974. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  975. }
  976. }
  977. return $sql;
  978. }
  979. /**
  980. * 检查编辑提交的Monitoring规则,是否允许保存
  981. */
  982. public function checkedMonitoringRulesSave($rules_type){
  983. $sql_where = "";
  984. if(isset($_POST['id']) && !empty($_POST['id'])){
  985. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  986. }
  987. $rules = common::excuteListSql("select *,
  988. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  989. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  990. from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  991. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  992. foreach($rules as $rule){
  993. //判断range 是否一样
  994. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit","shipment_etd_limit_from","shipment_eta_limit_from");
  995. $range_flag = true;
  996. foreach($checkRangeFiled as $filed){
  997. if($filed == "shipment_transport_mode"){
  998. $postValue = utils::converModeToDB($_POST[$filed]);
  999. $rule_mode_arr = explode(";", $rule[$filed]);
  1000. $post_mode_arr = explode(";", $postValue);
  1001. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1002. $range_flag = false;
  1003. }
  1004. }else{
  1005. //正常字段直接比较就行
  1006. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1007. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1008. if($postValue != $dbValue){
  1009. $range_flag = false;
  1010. }
  1011. }
  1012. }
  1013. //判断details 是否一样
  1014. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  1015. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  1016. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  1017. "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",
  1018. "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");
  1019. $details_flag = true;
  1020. foreach($checkDetailsFiled as $filed){
  1021. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  1022. $rule_mode_arr = empty($rule[$filed])? array() :explode(";", $rule[$filed]);
  1023. $post_mode_arr = $_POST[$filed];
  1024. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1025. $details_flag = false;
  1026. }
  1027. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  1028. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  1029. if($post_boolean != $rule[$filed]){
  1030. $details_flag = false;
  1031. }
  1032. } elseif ($filed == "ocean_atd_sub_etd_unit" || $filed == "ocean_ata_sub_eta_unit"
  1033. || $filed == "air_atd_sub_etd_unit" || $filed == "air_ata_sub_eta_unit"
  1034. || $filed == "ocean_etd_old_sub_new_unit" || $filed == "ocean_eta_old_sub_new_unit"
  1035. || $filed == "air_etd_old_sub_new_unit" || $filed == "air_eta_old_sub_new_unit"){
  1036. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1037. if(!empty($postValue)){
  1038. $postValue = $postValue=="Day(s)" ? "days":"hours";
  1039. }
  1040. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1041. if($postValue != $dbValue){
  1042. $details_flag = false;
  1043. }
  1044. } else {
  1045. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1046. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1047. if($postValue != $dbValue){
  1048. $details_flag = false;
  1049. }
  1050. }
  1051. }
  1052. //判断frequency 是否一样
  1053. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  1054. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  1055. $frequency_flag = true;
  1056. foreach($checkFrequencyFiled as $filed){
  1057. if($filed == "daily_time" || $filed == "weekly_time"){
  1058. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1059. //_daily_time _weekly_time
  1060. $dbValue = !empty($rule["_".$filed]) ? $rule["_".$filed] : "";
  1061. if($postValue != $dbValue){
  1062. $frequency_flag = false;
  1063. }
  1064. } else {
  1065. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1066. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1067. if($postValue != $dbValue){
  1068. $frequency_flag = false;
  1069. }
  1070. }
  1071. }
  1072. //判断通知方式是否一样
  1073. $checkMethodFiled = array("method_by_email","method_by_message");
  1074. $method_flag = true;
  1075. foreach($checkMethodFiled as $filed){
  1076. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  1077. if($postValue != $rule[$filed]){
  1078. $method_flag = false;
  1079. }
  1080. }
  1081. //五个条件一样,不允许保存
  1082. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  1083. $msg = "Unable to Save";
  1084. break;
  1085. }
  1086. //前三个重回,后面不重合,提示但允许保存
  1087. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  1088. $msg = "Similar Rule Detected";
  1089. break;
  1090. }
  1091. }
  1092. return $msg;
  1093. }
  1094. public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
  1095. if ($frequency_type == "all"){
  1096. $sql_where = " and (ni.frequency_type = 'Instant'
  1097. or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
  1098. or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  1099. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
  1100. } elseif($frequency_type == "Daily"){
  1101. $sql_where = " and (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
  1102. } elseif($frequency_type == "Weekly"){
  1103. $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  1104. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
  1105. }
  1106. if (!empty($_REQUEST['current_time'])){
  1107. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1108. // and ni.is_send_message = false";
  1109. //这里都以服务器时间,检查标准
  1110. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes'
  1111. and ni.is_send_message = false";
  1112. }
  1113. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1114. $sql_where .= " and ni.is_send_message = false";
  1115. }
  1116. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  1117. $aa_where = "";
  1118. if (!empty($insert_date_format)){
  1119. $aa_where = " where insert_date_format = '$insert_date_format'";
  1120. }
  1121. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1122. $sql = "select *
  1123. from (select ni.*,
  1124. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1125. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1126. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1127. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1128. else 0
  1129. end as _delay_diff,
  1130. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1131. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1132. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1133. 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')
  1134. else ''
  1135. end as insert_date_format,
  1136. case when ni.notifiation_type ='Milestone_Update'
  1137. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1138. else ''
  1139. end as milestone_previous_json,
  1140. case when ni.notifiation_type ='Container_Status_Update'
  1141. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1142. else ''
  1143. end as ctnr_previous_json,
  1144. case when ni.notifiation_type ='Container_Status_Update'
  1145. then (select description
  1146. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1147. else ''
  1148. end as ctnr_desc,
  1149. ccc.order_from,ccc.h_bol,ccc.transport_mode
  1150. from public.kln_notifiation_info ni
  1151. left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from
  1152. from public.kln_ocean oo
  1153. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1154. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1155. and lower(ni.notifiation_type) in ($more_param)
  1156. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
  1157. error_log($sql);
  1158. $data_all_type = common::excuteListSql($sql);
  1159. $data_group = array();
  1160. $data_group_uniqe = array();
  1161. foreach($data_all_type as $dat){
  1162. $uniqe_group_str = $dat['notifiation_type'];
  1163. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  1164. $tempArr = $data_group[$uniqe_group_str];
  1165. $tempArr[] = $dat;
  1166. $data_group[$uniqe_group_str] = $tempArr;
  1167. } else {
  1168. $data_group[$uniqe_group_str] = array($dat);
  1169. $data_group_uniqe[] = $uniqe_group_str;
  1170. }
  1171. }
  1172. $retData = array();
  1173. foreach($data_group as $key => $data){
  1174. $notifiation_type_db = $key;
  1175. //统一处理数据Instant Daily weekly_week 先分开在处理
  1176. $instant = array();
  1177. $daily = array();
  1178. $daily_uniqe = array();
  1179. $weekly = array();
  1180. $weekly_uniqe = array();
  1181. foreach($data as $d){
  1182. if ($d['frequency_type'] == "Instant"){
  1183. $instant[] = $d;
  1184. }
  1185. //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  1186. $uniqe_str = $d['serial_no'];
  1187. if ($notifiation_type_db == "Milestone_Update"){
  1188. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
  1189. }else if ($notifiation_type_db == "Container_Status_Update"){
  1190. $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
  1191. }else if($notifiation_type_db == "Departure/Arrival_Delay"){
  1192. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
  1193. }else if($notifiation_type_db == "ETD/ETA_Change"){
  1194. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
  1195. }
  1196. if ($d['frequency_type'] == "Daily"){
  1197. if(!utils::in_array($uniqe_str,$daily_uniqe)){
  1198. $daily[$uniqe_str] = $d;
  1199. $daily_uniqe[] = $uniqe_str;
  1200. }
  1201. }
  1202. if ($d['frequency_type'] == "Weekly"){
  1203. if(!utils::in_array($uniqe_str,$weekly_uniqe)){
  1204. $weekly[$uniqe_str] = $d;
  1205. $weekly_uniqe[] = $uniqe_str;
  1206. }
  1207. }
  1208. }
  1209. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
  1210. }
  1211. return $retData;
  1212. }
  1213. public function getEventCard($mInfo){
  1214. $eventCard = array();
  1215. $notifiation_type = $mInfo['notifiation_type'];
  1216. if($notifiation_type == "Milestone_Update"){
  1217. $eventCard = array("type" =>'milestone',
  1218. "numericRecords"=>0,
  1219. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1220. "title"=>"Milestone Update",
  1221. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1222. "no"=>$mInfo["h_bol"],
  1223. "tag"=>$mInfo["milestone_description"],
  1224. "location"=>$mInfo["milestone_locations"],
  1225. "timezone"=>$mInfo["milestone_timezone"],
  1226. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  1227. "timeLabel"=>"",
  1228. "previous"=>"",
  1229. "frequency_type"=>$mInfo["frequency_type"],
  1230. "serial_no"=>$mInfo["serial_no"],
  1231. "order_from"=>$mInfo["order_from"],
  1232. "id"=>$mInfo["id"],
  1233. "insert_date_format"=>'',
  1234. "rules_type"=>$mInfo["notifiation_type"],
  1235. "info"=>new stdClass());
  1236. if ($mInfo["frequency_type"] == "Daily"){
  1237. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1238. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  1239. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1240. //seeall 的时候,前端不需要id
  1241. $eventCard["id"] = '';
  1242. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1243. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1244. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1245. "date" => $milestone_previous['milestone']['milestone_date'],
  1246. "time" => $milestone_previous['milestone']['milestone_time'],
  1247. "timezone" =>$milestone_previous['milestone']['timezone']);
  1248. }
  1249. } else if($mInfo["frequency_type"] == "Weekly"){
  1250. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1251. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1252. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1253. //seeall 的时候,前端不需要id
  1254. $eventCard["id"] = '';
  1255. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1256. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1257. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1258. "date" => $milestone_previous['milestone']['milestone_date'],
  1259. "time" => $milestone_previous['milestone']['milestone_time'],
  1260. "timezone" =>$milestone_previous['milestone']['timezone']);
  1261. }
  1262. }
  1263. }
  1264. if($notifiation_type == "Container_Status_Update"){
  1265. //当前状态的描述ctnr_desc
  1266. //$ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  1267. $eventCard = array("type" =>'container',
  1268. "numericRecords"=>0,
  1269. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1270. "title"=>"Container_Status_Update",
  1271. "mode"=>"Ocean Freight",
  1272. "no"=>$mInfo["ctnr"],
  1273. "tag"=>$mInfo["ctnr_desc"],
  1274. "location"=>$mInfo["ctnr_status_locations"],
  1275. "timezone"=>$mInfo["ctnr_status_timezone"],
  1276. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  1277. "timeLabel"=>"",
  1278. "previous"=>"",
  1279. "frequency_type"=>$mInfo["frequency_type"],
  1280. "serial_no"=>$mInfo["serial_no"],
  1281. "order_from"=>$mInfo["order_from"],
  1282. "id"=>$mInfo["id"],
  1283. "insert_date_format"=>'',
  1284. "rules_type"=>$mInfo["notifiation_type"],
  1285. "info"=>new stdClass());
  1286. if ($mInfo["frequency_type"] == "Daily"){
  1287. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1288. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1289. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1290. //seeall 的时候,前端不需要id
  1291. $eventCard["id"] = '';
  1292. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  1293. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  1294. //当前状态 前一个的描述
  1295. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  1296. "date" => $ctnr_previous["ctnrStatus"]["date"],
  1297. "time" => $ctnr_previous["ctnrStatus"]["time"],
  1298. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  1299. }
  1300. } else if($mInfo["frequency_type"] == "Weekly"){
  1301. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1302. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1303. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1304. //seeall 的时候,前端不需要id
  1305. $eventCard["id"] = '';
  1306. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  1307. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  1308. //当前状态 前一个的描述
  1309. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  1310. "date" => $ctnr_previous["ctnrStatus"]["date"],
  1311. "time" => $ctnr_previous["ctnrStatus"]["time"],
  1312. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  1313. }
  1314. }
  1315. }
  1316. if($notifiation_type == "Departure/Arrival_Delay"){
  1317. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  1318. $title = $mInfo["delay_name"];
  1319. $outsideLocation = "";
  1320. $outsideTimezone = "";
  1321. $outsideTimeLabel= "";
  1322. $insideTimeLabel= "";
  1323. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  1324. $outsideTimeLabel = "ETD";
  1325. $insideTimeLabel = "ATD";
  1326. }
  1327. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  1328. $outsideTimeLabel = "ETA";
  1329. $insideTimeLabel = "ATA";
  1330. }
  1331. //直航的的
  1332. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  1333. $outsideLocation = $mInfo["delay_locations_from"];
  1334. }
  1335. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  1336. $outsideLocation = $mInfo["delay_locations_to"];
  1337. }
  1338. $route = array();
  1339. $leg = array();
  1340. if($mInfo["delay_is_direct"] <>'t'){
  1341. $title = substr($mInfo["delay_name"],8);
  1342. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1343. //当前current Leg
  1344. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  1345. if($mInfo["delay_current"] == "2"){
  1346. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1347. }
  1348. }
  1349. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  1350. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  1351. $delay_diff = $mInfo["_delay_diff"];
  1352. $delay_unit = $mInfo["delay_unit"];
  1353. $eventCard = array("type" =>'delay',
  1354. "numericRecords"=>0,
  1355. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1356. "title"=>$title,
  1357. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1358. "no"=>$mInfo["h_bol"],
  1359. "tag"=>$mInfo["delay_name"],
  1360. "location"=>$outsideLocation,
  1361. "timezone"=>$mInfo["delay_timezone"],
  1362. "time"=>$est_date,
  1363. "timeLabel"=>$outsideTimeLabel,
  1364. "previous"=>"",
  1365. "frequency_type"=>$mInfo["frequency_type"],
  1366. "serial_no"=>$mInfo["serial_no"],
  1367. "order_from"=>$mInfo["order_from"],
  1368. "id"=>$mInfo["id"],
  1369. "insert_date_format"=>'',
  1370. "rules_type"=>$mInfo["notifiation_type"],
  1371. "info"=>array("route"=>$route,
  1372. "leg"=>$leg,
  1373. "etdOrdeparturNum"=>0,
  1374. "etaOrarrivalNum"=>0,
  1375. "time"=>$act_date,
  1376. "timeLabel"=>$insideTimeLabel,
  1377. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  1378. "timezone"=>$mInfo["delay_timezone"]
  1379. ));
  1380. if ($mInfo["frequency_type"] == "Daily"){
  1381. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1382. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1383. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1384. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1385. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1386. //seeall 的时候,前端不需要id
  1387. $eventCard["id"] = '';
  1388. } else if($mInfo["frequency_type"] == "Weekly"){
  1389. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1390. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1391. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1392. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1393. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1394. //seeall 的时候,前端不需要id
  1395. $eventCard["id"] = '';
  1396. }
  1397. }
  1398. if($notifiation_type == "ETD/ETA_Change"){
  1399. $title = $mInfo["date_change_name"];
  1400. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  1401. $outsideTimeLabel = "Original ETD";
  1402. $insideTimeLabel = "Upoated ETD";
  1403. }
  1404. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  1405. $outsideTimeLabel = "Original ETA";
  1406. $insideTimeLabel = "Upoated ETA";
  1407. }
  1408. if($mInfo["date_change_is_direct"] <>'t'){
  1409. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  1410. $title = substr($mInfo["date_change_name"],8);
  1411. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1412. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  1413. if($mInfo["date_change_current"] == "2"){
  1414. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1415. }
  1416. }
  1417. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  1418. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  1419. $eventCard = array("type" =>'change',
  1420. "numericRecords"=>0,
  1421. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1422. "title"=>$title,
  1423. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1424. "no"=>$mInfo["h_bol"],
  1425. "tag"=>$mInfo["date_change_name"],
  1426. "location"=>"",
  1427. "timezone"=>$mInfo["date_change_timezone"],
  1428. "time"=>$original_date,
  1429. "timeLabel"=>$outsideTimeLabel,
  1430. "previous"=>"",
  1431. "frequency_type"=>$mInfo["frequency_type"],
  1432. "serial_no"=>$mInfo["serial_no"],
  1433. "order_from"=>$mInfo["order_from"],
  1434. "id"=>$mInfo["id"],
  1435. "insert_date_format"=>'',
  1436. "rules_type"=>$mInfo["notifiation_type"],
  1437. "info"=>array("route"=>$route,
  1438. "leg"=>$leg,
  1439. "etdOrdeparturNum"=>0,
  1440. "etaOrarrivalNum"=>0,
  1441. "time"=>$updated_date,
  1442. "timeLabel"=>$insideTimeLabel,
  1443. "delayTimeTip"=>"",
  1444. "timezone"=>$mInfo["date_change_timezone"]
  1445. ));
  1446. if ($mInfo["frequency_type"] == "Daily"){
  1447. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1448. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1449. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1450. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  1451. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1452. $eventCard["id"] = "";
  1453. } else if($mInfo["frequency_type"] == "Weekly"){
  1454. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1455. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1456. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1457. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  1458. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1459. $eventCard["id"] = "";
  1460. }
  1461. }
  1462. if($notifiation_type == "Feature_Update" || $notifiation_type == "Passwond_Notifcations"){
  1463. $title = $mInfo["other_type"] == "password" ? "Password Notifications" : "Feature Update";
  1464. $isExpiration = false;
  1465. if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
  1466. $isExpiration = true;
  1467. }
  1468. $eventCard = array(
  1469. "title" => $title,
  1470. "id"=> $mInfo["id"],
  1471. "header"=> $mInfo["other_name"],
  1472. "content"=>$mInfo["other_desc"],
  1473. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1474. "isExpiration"=> $isExpiration,
  1475. "rules_type"=>$mInfo["notifiation_type"],
  1476. "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$mInfo["id"].".jpg",
  1477. "view_more_link" =>"main_new_version.php?action=feature_update&id=".$mInfo["id"]
  1478. );
  1479. }
  1480. return $eventCard;
  1481. }
  1482. /**
  1483. * 返回当前柜子的status信息描述,目前作废
  1484. */
  1485. public static function getContainerStatusDesc($ctnr_status_code){
  1486. $event =common::getEDICtnrEvent();
  1487. $ctnrStatusdesc = "";
  1488. foreach($event as $e){
  1489. if($e['event_name'] == $ctnr_status_code){
  1490. $ctnrStatusdesc = $e['description'];
  1491. }
  1492. }
  1493. return $ctnrStatusdesc;
  1494. }
  1495. }
  1496. ?>