tools.class.php 91 KB

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