tools.class.php 92 KB

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