tools.class.php 88 KB

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