login.class.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of login
  7. *
  8. * @author Administrator
  9. */
  10. class login {
  11. private static $_login;
  12. public static function getInstance() {
  13. if (!self::$_login) {
  14. $c = __CLASS__;
  15. self::$_login = new $c;
  16. }
  17. return self::$_login;
  18. }
  19. private function getLoginSql($uname) {
  20. return "select user_login,(select active from public.employee ee where ee.employee_id=u.employee_id) as employee_id_active, can_visit_vgm,can_add_booking, can_add_tk_status,truck_driver,po_booking,o_final_delivery_u,ipad_view_po,can_view_doc,can_upload_doc,can_add_catalog,can_add_po,packing_list_company,is_only_vgm,contact_id_user,is_demo, ra_password as password,employee_id, contact_id, user_type, last_pwd_change, EXTRACT(DAY from (now() - last_pwd_change)) as last_pwd_change_date, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  21. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  22. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  23. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, belong_schemas, main_schemas, error_login_count, EXTRACT(EPOCH FROM (now()-COALESCE(error_login_time, now()))) as second, po_status, view_air_file_format,
  24. special_customer_event, can_edi_vgm, isf_aci_ams_station,login_version,is_kerry_shipment,can_visit_delivery,currency_group from public.ra_online_user u where lower(user_login) = '" . strtolower($uname) . "'";
  25. }
  26. public function do_login() {
  27. $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
  28. $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
  29. if (!empty($uname) || !empty($password)) {
  30. } else {
  31. $uname = common::check_input($_POST['uname']);
  32. $verifcation_code = common::check_input($_POST['verifcation_code']);
  33. //首先校验验证码
  34. if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
  35. $data = array(
  36. 'msg' => 'verifcation_error',
  37. 'data' => ''
  38. );
  39. common::echo_json_encode(400, $data);
  40. exit();
  41. }
  42. $sql = $this->getLoginSql($uname);
  43. $rs = common::excuteObjectSql($sql);
  44. if (empty($rs['belong_schemas'])) {
  45. $rs['belong_schemas'] = "public";
  46. }
  47. if (empty($rs['main_schemas'])) {
  48. $rs['main_schemas'] = "public";
  49. }
  50. if (!empty($rs)) {
  51. //验证employee是否active
  52. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  53. if (strtolower(Soure) =='topocean'){
  54. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  55. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  56. }else{
  57. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  58. }
  59. }
  60. if (strtolower(Soure) =='apex'){
  61. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  62. }
  63. $data = array(
  64. 'msg' => 'no_active',
  65. 'login_version' => $rs["login_version"],
  66. 'data' => $data,
  67. 'desc' => "Please check with Doc Center $data for searching function"
  68. );
  69. common::echo_json_encode(500, $data);
  70. $this->failedLogin($uname, 'Employee not active');
  71. exit();
  72. }
  73. //处理登录状态
  74. $userInfo = common::check_input($_COOKIE['userInfo']);
  75. $noCheckPwd = false;
  76. if (!empty($userInfo)) {
  77. $userInfoSplit = explode("_", $userInfo);
  78. if ($uname == $userInfoSplit[0]) {
  79. if ($userInfoSplit[1] == md5($rs['password'])) {
  80. $noCheckPwd = true;
  81. }
  82. }
  83. }
  84. if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
  85. $data = array(
  86. 'msg' => 'error_times',
  87. 'login_version' => $rs["login_version"],
  88. 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
  89. );
  90. common::echo_json_encode(400, $data);
  91. $this->failedLogin($uname, 'Failed login too times');
  92. exit();
  93. }
  94. if ($rs['is_online'] != 't') {
  95. if (strtolower($rs['user_type']) != "employee") {
  96. $data =array(
  97. 'msg' => 'no_online',
  98. 'login_version' => $rs["login_version"],
  99. 'data' => '',
  100. 'desc' => 'No activation or insufficient permissions'
  101. );
  102. common::echo_json_encode(500, $data);
  103. $this->failedLogin($uname, 'Online is not active');
  104. exit();
  105. }
  106. }
  107. //if ($rs['decrypt_password'] != $_POST['psw']) {
  108. if ($noCheckPwd) {
  109. }else{
  110. if ($rs['password'] != $_POST['psw']) {
  111. common::excuteUpdateSql("update public.ra_online_user set error_login_count=error_login_count+1, error_login_time=now() where lower(user_login) = '" . strtolower($uname) . "'");
  112. $data = array(
  113. 'msg' => 'password_error',
  114. 'login_version' => $rs["login_version"],
  115. 'data' => ''
  116. );
  117. common::echo_json_encode(400, $data);
  118. $this->failedLogin($uname, 'Password is wrong');
  119. exit();
  120. }
  121. }
  122. if ($rs['online_active'] != 't') {
  123. $data = array(
  124. 'msg' => 'no_active',
  125. 'login_version' => $rs["login_version"],
  126. 'data' => '',
  127. 'desc' => 'Please check with Doc Center for searching function'
  128. );
  129. common::echo_json_encode(500, $data);
  130. $this->failedLogin($uname, 'Online is not active');
  131. exit();
  132. }
  133. //check password length
  134. $tar = utils::checkPassword($rs['password']);
  135. if (!empty($tar)) {
  136. $data = array(
  137. 'msg' => $tar,
  138. 'login_version' => $rs["login_version"],
  139. 'data' => '',
  140. 'desc' => $tar
  141. );
  142. common::echo_json_encode(500, $data);
  143. exit();
  144. }
  145. if (empty($rs['last_pwd_change'])) {
  146. $data = array(
  147. 'msg' => 'first_login',
  148. 'login_version' => $rs["login_version"],
  149. 'data' => '',
  150. 'desc' => 'First login, please change your password'
  151. );
  152. common::echo_json_encode(500, $data);
  153. exit();
  154. }
  155. //get more infor by employee_id or contact_id
  156. $sql = '';
  157. $diffdate = $rs['last_pwd_change_date'];
  158. $user_type = $rs['user_type'];
  159. //if user is customer, check company
  160. if (strtolower($user_type) == 'customer') {
  161. $company = $rs['company_name'];
  162. } else {
  163. if (!empty($rs['station']))
  164. $company = $rs['station'];
  165. }
  166. if (strtolower($uname) == 'ra.admin') {
  167. $company = 'Admin';
  168. }
  169. // get system config
  170. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_session_timeout', 'customer_session_timeout', 'password_change_alert', 'employee_password_change_cycle', 'customer_password_change_cycle')";
  171. $rs1s = common::excuteListSql($sql);
  172. foreach ($rs1s as $rs1) {
  173. if ($rs1['ra_name'] == 'employee_session_timeout')
  174. $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
  175. if ($rs1['ra_name'] == 'customer_session_timeout')
  176. $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
  177. if ($rs1['ra_name'] == 'password_change_alert')
  178. $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
  179. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  180. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  181. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  182. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  183. }
  184. $sql="select item_value from config where item='passwordChangePeriod'";
  185. $pcp = common::excuteObjectSql($sql);
  186. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  187. if (strtolower($rs['user_type']) == 'employee') {
  188. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  189. $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
  190. //如果有新配置,则采用新配置
  191. if (!empty($pcp)) {
  192. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  193. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
  194. }
  195. } else {
  196. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  197. $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
  198. //如果有新配置,则采用新配置
  199. if (!empty($pcp)) {
  200. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  201. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
  202. }
  203. }
  204. $loginName = $rs['user_login'];
  205. $email = $rs['email'];
  206. //Timeout
  207. if ($diffdate > $PASSWORD_CHANGE_CYCLE) {
  208. if(empty($email)){
  209. $data = array(
  210. 'status' => '0',
  211. 'msg' => 'login user email is empty',
  212. 'login_version' => $rs["login_version"],
  213. 'desc' => 'login user email is empty'
  214. );
  215. common::echo_json_encode(500, $data);
  216. exit();
  217. }else{
  218. $this -> passwordExpires($loginName,$email,$uname);
  219. }
  220. }
  221. if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
  222. $login_tmp = array(
  223. 'msg' => 'today',
  224. 'uname' => $uname,
  225. 'login_version' => $rs["login_version"],
  226. 'data' => ''
  227. );
  228. } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
  229. $login_tmp = array(
  230. 'msg' => 'last',
  231. 'uname' => $uname,
  232. 'login_version' => $rs["login_version"],
  233. 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
  234. 'is_only_vgm' => $rs["is_only_vgm"]
  235. );
  236. }
  237. //insert into log table
  238. $ip = common::ip();
  239. $sql = "insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')";
  240. if (common::excuteUpdateSql($sql)) {
  241. common::excuteUpdateSql("update public.ra_online_user set Last_Login_Time = now(), error_login_count=0, error_login_time=null where lower(user_login) = '" . strtolower($uname) . "'");
  242. if (isset($login_tmp)) {
  243. common::echo_json_encode(200, $login_tmp);
  244. } else {
  245. $data = array(
  246. 'msg' => 'success',
  247. 'uname' => $uname,
  248. 'login_version' => $rs["login_version"],
  249. 'data' => '',
  250. 'is_only_vgm' => $rs["is_only_vgm"]
  251. );
  252. common::echo_json_encode(200, $data);
  253. }
  254. $online_user = $rs;
  255. $online_user['user_login'] = $uname;
  256. $online_user['company'] = $company;
  257. $online_user['password'] = "";
  258. if (!_isAdmin()) {
  259. if ($rs["is_only_vgm"] == "t") {//VGM用户写死
  260. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where url_action in ('ocean_order','password','vgm') and menu_id in ('ship','profile') order by order_by asc), ',')";
  261. $rrrs = common::excuteOneSql($sql);
  262. } else {
  263. $sql = "select array_to_string(ARRAY(select p.url_action from public.ra_online_user_permission up left join public.ra_online_user u on up.user_name = u.user_login left join public.ra_online_permission p on up.p_id = p.id where lower(u.user_login) = '" . common::check_input(strtolower($uname)) . "'), ',')";
  264. $rrrs = common::excuteOneSql($sql);
  265. if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
  266. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
  267. $rrrs = common::excuteOneSql($sql);
  268. }
  269. }
  270. $online_user['permission'] = $rrrs;
  271. }
  272. if (!empty($online_user['docdownload']))
  273. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
  274. else {
  275. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where active = true";
  276. if (strtolower($online_user['user_type']) == "customer")
  277. $sql .= " and client_display = true";
  278. $sql .= " group by display_name order by min(id)";
  279. }
  280. $online_user['view_doc_type'] = common::excuteListSql($sql);
  281. if (!empty($online_user['view_air_file_format']))
  282. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  283. else {
  284. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where active = true";
  285. if (strtolower($online_user['user_type']) == "customer")
  286. $sql .= " and client_display = true";
  287. $sql .= " group by display_name order by min(id)";
  288. }
  289. $online_user['view_air_doc_type'] = common::excuteListSql($sql);
  290. //补充aci and ams CustomerLogin station - public
  291. $ocean_station_temp = $online_user['ocean_station'];
  292. $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  293. $ocean_agent_temp = $online_user['ocean_agent'];
  294. $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  295. $_SESSION['ONLINE_USER'] = $online_user;
  296. $_SESSION['LAST_OPERATE_TIME'] = time();
  297. $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
  298. //判断是否记录密码 add
  299. if ($_POST['rememberpwd'] === 'true') {
  300. if (!$noCheckPwd) {
  301. $user_info = $uname . "_" . md5($rs['password']);
  302. setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
  303. }
  304. } else {
  305. setcookie('userInfo', '', time() - 1, "/");
  306. }
  307. if ($rs['is_super'] == "t") {
  308. $schemas_list = common::excuteListSql("select * from schemas_list");
  309. } else {
  310. $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
  311. }
  312. ///if (count($schemas_list) > 1) {
  313. foreach ($schemas_list as $sk => $sv) {
  314. if ($sv['schemas_name'] == "public") {
  315. continue;
  316. }
  317. $ttdd = common::excuteObjectSql("select contact_id_user, employee_id, contact_id, user_type, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  318. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  319. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  320. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, po_status, view_air_file_format, special_customer_event, can_edi_vgm, isf_aci_ams_station, is_kerry_shipment from " . $sv['schemas_name'] . ".ra_online_user where lower(user_login) = '" . strtolower($uname) . "'");
  321. if (empty($ttdd)) {
  322. unset($schemas_list[$sk]);
  323. continue;
  324. }
  325. if (!empty($ttdd['docdownload'])) {
  326. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
  327. } else {
  328. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
  329. if (strtolower($ttdd['user_type']) == "customer")
  330. $sql .= " and client_display = true";
  331. $sql .= " group by display_name order by min(id)";
  332. }
  333. $ttdd['view_doc_type'] = common::excuteListSql($sql);
  334. if (!empty($ttdd['view_air_file_format'])) {
  335. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  336. } else {
  337. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where active = true";
  338. if (strtolower($ttdd['user_type']) == "customer")
  339. $sql .= " and client_display = true";
  340. $sql .= " group by display_name order by min(id)";
  341. }
  342. $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
  343. //补充aci and ams CustomerLogin station - other like sfs
  344. $ocean_station_temp = $ttdd['ocean_station'];
  345. $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  346. $ocean_agent_temp = $ttdd['ocean_agent'];
  347. $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  348. $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
  349. }
  350. //}
  351. $_SESSION['schemas_list'] = $schemas_list;
  352. //不再返回登录页面,直接跳转
  353. if (isset($_GET['up'])) {
  354. if($_GET['v'] == 'new'){
  355. header("Location: main_new_version.php?action=main");
  356. }else{
  357. header("Location: main.php?action=main");
  358. }
  359. }
  360. exit();
  361. } else {
  362. $data = array(
  363. 'msg' => 'database_error',
  364. 'login_version' => $rs["login_version"],
  365. 'desc' => 'database_error'
  366. );
  367. common::echo_json_encode(500, $data);
  368. exit();
  369. }
  370. } else {
  371. $data = array(
  372. 'msg' => 'no_exist',
  373. 'login_version' => $rs["login_version"],
  374. 'desc' => 'The username or password you entered is incorrect'
  375. );
  376. common::echo_json_encode(500, $data);
  377. exit();
  378. }
  379. }
  380. }
  381. public function check_uname(){
  382. $uname = common::check_input($_POST['uname']);
  383. $sql = $this->getLoginSql($uname);
  384. $rs = common::excuteObjectSql($sql);
  385. if (!empty($rs)) {
  386. //只是验证用户是否存在,是否激活
  387. //验证employee是否active
  388. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  389. if (strtolower(Soure) =='topocean'){
  390. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  391. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  392. }else{
  393. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  394. }
  395. }
  396. if (strtolower(Soure) =='apex'){
  397. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  398. }
  399. $data = array(
  400. 'msg' => 'no_active',
  401. );
  402. common::echo_json_encode(200, $data);
  403. exit();
  404. }
  405. if ($rs['is_online'] != 't') {
  406. if (strtolower($rs['user_type']) != "employee") {
  407. $data =array(
  408. 'msg' => 'no_online',
  409. );
  410. common::echo_json_encode(200, $data);
  411. exit();
  412. }
  413. }
  414. if ($rs['online_active'] != 't') {
  415. $data = array(
  416. 'msg' => 'no_active',
  417. );
  418. common::echo_json_encode(200, $data);
  419. exit();
  420. }
  421. //验证成功
  422. $data = array(
  423. 'msg' => 'success',
  424. );
  425. common::echo_json_encode(200, $data);
  426. exit();
  427. } else {
  428. $data = array(
  429. 'msg' => 'no_exist',
  430. );
  431. common::echo_json_encode(200, $data);
  432. exit();
  433. }
  434. }
  435. public function verifcation_code(){
  436. // 生成一个4位随机数作为验证码
  437. //$random_num = mt_rand(1000, 9999);
  438. $random_num = $this->generateCaptcha(6);
  439. $_SESSION['captcha'] = $random_num;
  440. // 创建一个宽度为80像素、高度为30像素的图片
  441. $width = 130;
  442. $height = 40;
  443. $image = imagecreate($width, $height);
  444. // 设置颜色
  445. $white = imagecolorallocate($image, 255, 255, 255); // 白色作为背景
  446. $black = imagecolorallocate($image, 0, 0, 0); // 黑色作为文字
  447. // 填充背景
  448. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  449. // 在图片上绘制四个字符
  450. $font_size = 18;
  451. $x = 14;
  452. $y = 12;
  453. for ($i = 0; $i < 6; $i++) {
  454. $char = substr($random_num, $i, 1);
  455. imagestring($image, $font_size, $x, $y, $char, $black);
  456. $x += $font_size+1;
  457. }
  458. // 返回Base64编码
  459. ob_start();
  460. imagepng($image);
  461. $image_data = ob_get_clean();
  462. // 释放内存
  463. imagedestroy($image);
  464. $data = array("imagePngBase64" =>base64_encode($image_data));
  465. common::echo_json_encode(200, $data);
  466. exit();
  467. }
  468. //邮件密码原文
  469. public function forgot_password() {
  470. $login = common::check_input($_POST['login']);
  471. $email = common::check_input($_POST['email']);
  472. $verifcation_code = common::check_input($_POST['verifcation_code']);
  473. //首先校验验证码
  474. if ($_SESSION['captcha'] != $verifcation_code) {
  475. $data = array(
  476. 'msg' => 'verifcation_error',
  477. 'data' => ''
  478. );
  479. common::echo_json_encode(500, $data);
  480. exit();
  481. }
  482. $msg = "";
  483. if (!empty($email) || !empty($login)) {
  484. $sql_p = "select User_Login, ra_password as password from public.ra_online_user where lower(user_login) = '" . strtolower($login) . "' and lower(email) = '" . strtolower($email) . "'";
  485. $rs = common::excuteObjectSql($sql_p);
  486. if (!empty($rs)) {
  487. $r = utils::sendEmailByPassword($login, $rs['password'], $email);
  488. if ($r == 'success') {
  489. $msg = "success";
  490. } else {
  491. $msg = $r;
  492. }
  493. } else {
  494. $msg = "Can not find this user with give login id and email, please confirm!";
  495. }
  496. } else {
  497. $msg = "Login Name or Email Required !";
  498. }
  499. $data = array(
  500. 'msg' => $msg,
  501. );
  502. common::echo_json_encode(200, $data);
  503. exit();
  504. }
  505. public function generateCaptcha($length = 6) {
  506. $captcha = '';
  507. $chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789";
  508. for ($i = 0; $i < $length; $i++) {
  509. // 随机选择字母或数字
  510. $char = $chars[mt_rand(0, strlen($chars) - 1)];
  511. $captcha .= strval($char);
  512. }
  513. return $captcha;
  514. }
  515. public function do_login_auto() {
  516. $uname = common::check_input($_GET['u']);
  517. $password = common::check_input($_GET['p']);
  518. $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
  519. $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
  520. if (!empty($uname) || !empty($password)) {
  521. } else {
  522. $uname = common::check_input($_POST['uname']);
  523. $sql = $this->getLoginSql($uname);
  524. $rs = common::excuteObjectSql($sql);
  525. if (empty($rs['belong_schemas'])) {
  526. $rs['belong_schemas'] = "public";
  527. }
  528. if (empty($rs['main_schemas'])) {
  529. $rs['main_schemas'] = "public";
  530. }
  531. if (!empty($rs)) {
  532. //验证employee是否active
  533. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  534. if (strtolower(Soure) =='topocean'){
  535. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  536. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  537. }else{
  538. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  539. }
  540. }
  541. if (strtolower(Soure) =='apex'){
  542. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  543. }
  544. $data = array(
  545. 'msg' => 'no_active',
  546. 'login_version' => $rs["login_version"],
  547. 'data' => $data
  548. );
  549. common::echo_json_encode(500, $data);
  550. $this->failedLogin($uname, 'Employee not active');
  551. exit();
  552. }
  553. //add 处理登录状态
  554. $userInfo = common::check_input($_COOKIE['userInfo']);
  555. $noCheckPwd = false;
  556. if (!empty($userInfo)) {
  557. $userInfoSplit = explode("_", $userInfo);
  558. if ($uname == $userInfoSplit[0]) {
  559. if ($userInfoSplit[1] == md5($rs['password'])) {
  560. $noCheckPwd = true;
  561. }
  562. }
  563. }
  564. //if (!$noCheckPwd) {
  565. if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
  566. $data = array(
  567. 'msg' => 'error_times',
  568. 'login_version' => $rs["login_version"],
  569. 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
  570. );
  571. common::echo_json_encode(500, $data);
  572. $this->failedLogin($uname, 'Failed login too times');
  573. exit();
  574. }
  575. if ($rs['is_online'] != 't') {
  576. if (strtolower($rs['user_type']) != "employee") {
  577. $data =array(
  578. 'msg' => 'no_online',
  579. 'login_version' => $rs["login_version"],
  580. 'data' => ''
  581. );
  582. common::echo_json_encode(500, $data);
  583. $this->failedLogin($uname, 'Online is not active');
  584. exit();
  585. }
  586. }
  587. //if ($rs['decrypt_password'] != $_POST['psw']) {
  588. if ($noCheckPwd) {
  589. }else{
  590. if ($rs['password'] != $_POST['psw']) {
  591. common::excuteUpdateSql("update public.ra_online_user set error_login_count=error_login_count+1, error_login_time=now() where lower(user_login) = '" . strtolower($uname) . "'");
  592. $data = array(
  593. 'msg' => 'password_error',
  594. 'login_version' => $rs["login_version"],
  595. 'data' => ''
  596. );
  597. common::echo_json_encode(500, $data);
  598. $this->failedLogin($uname, 'Password is wrong');
  599. exit();
  600. }
  601. }
  602. if ($rs['online_active'] != 't') {
  603. $data = array(
  604. 'msg' => 'no_active',
  605. 'login_version' => $rs["login_version"],
  606. 'data' => ''
  607. );
  608. common::echo_json_encode(500, $data);
  609. $this->failedLogin($uname, 'Online is not active');
  610. exit();
  611. }
  612. //check password length
  613. $tar = utils::checkPassword($rs['password']);
  614. if (!empty($tar)) {
  615. $data = array(
  616. 'msg' => $tar,
  617. 'login_version' => $rs["login_version"],
  618. 'data' => ''
  619. );
  620. common::echo_json_encode(500, $data);
  621. exit();
  622. }
  623. if (empty($rs['last_pwd_change'])) {
  624. $data = array(
  625. 'msg' => 'first_login',
  626. 'login_version' => $rs["login_version"],
  627. 'data' => ''
  628. );
  629. common::echo_json_encode(500, $data);
  630. exit();
  631. }
  632. //}
  633. //get more infor by employee_id or contact_id
  634. $sql = '';
  635. $diffdate = $rs['last_pwd_change_date'];
  636. $user_type = $rs['user_type'];
  637. //if user is customer, check company
  638. if (strtolower($user_type) == 'customer') {
  639. $company = $rs['company_name'];
  640. } else {
  641. if (!empty($rs['station']))
  642. $company = $rs['station'];
  643. }
  644. if (strtolower($uname) == 'ra.admin') {
  645. $company = 'Admin';
  646. }
  647. // get system config
  648. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_session_timeout', 'customer_session_timeout', 'password_change_alert', 'employee_password_change_cycle', 'customer_password_change_cycle')";
  649. $rs1s = common::excuteListSql($sql);
  650. foreach ($rs1s as $rs1) {
  651. if ($rs1['ra_name'] == 'employee_session_timeout')
  652. $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
  653. if ($rs1['ra_name'] == 'customer_session_timeout')
  654. $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
  655. if ($rs1['ra_name'] == 'password_change_alert')
  656. $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
  657. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  658. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  659. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  660. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  661. }
  662. $sql="select item_value from config where item='passwordChangePeriod'";
  663. $pcp = common::excuteObjectSql($sql);
  664. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  665. if (strtolower($rs['user_type']) == 'employee') {
  666. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  667. $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
  668. //如果有新配置,则采用新配置
  669. if (!empty($pcp)) {
  670. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  671. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
  672. }
  673. } else {
  674. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  675. $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
  676. //如果有新配置,则采用新配置
  677. if (!empty($pcp)) {
  678. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  679. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
  680. }
  681. }
  682. /* if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
  683. echo json_encode(array(
  684. 'msg' => 'password_require_change',
  685. 'login_version' => $rs["login_version"],
  686. 'data' => ''
  687. ));
  688. $this->failedLogin($uname, 'Required password change');
  689. exit();
  690. }*/
  691. $loginName = $rs['user_login'];
  692. $email = $rs['email'];
  693. if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
  694. if(empty($email)){
  695. $data = array(
  696. 'status' => '0',
  697. 'msg' => 'login user email is empty',
  698. 'login_version' => $rs["login_version"],
  699. 'data' => ''
  700. );
  701. common::echo_json_encode(500, $data);
  702. exit();
  703. }else{
  704. //$this -> passwordExpires($loginName,$email);
  705. }
  706. }
  707. if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
  708. $login_tmp = array(
  709. 'msg' => 'today',
  710. 'login_version' => $rs["login_version"],
  711. 'data' => ''
  712. );
  713. } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
  714. $login_tmp = array(
  715. 'msg' => 'last',
  716. 'login_version' => $rs["login_version"],
  717. 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
  718. 'is_only_vgm' => $rs["is_only_vgm"]
  719. );
  720. }
  721. //insert into log table
  722. $ip = common::ip();
  723. $sql = "insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')";
  724. if (common::excuteUpdateSql($sql)) {
  725. common::excuteUpdateSql("update public.ra_online_user set Last_Login_Time = now(), error_login_count=0, error_login_time=null where lower(user_login) = '" . strtolower($uname) . "'");
  726. //自动登录。为了方便调用,先注销掉
  727. if (isset($login_tmp)) {
  728. //common::echo_json_encode(500, $login_tmp);
  729. } else {
  730. $data = array(
  731. 'msg' => 'success',
  732. 'login_version' => $rs["login_version"],
  733. 'data' => '',
  734. 'is_only_vgm' => $rs["is_only_vgm"]
  735. );
  736. //common::echo_json_encode("200", $data);
  737. }
  738. $online_user = $rs;
  739. $online_user['user_login'] = $uname;
  740. $online_user['company'] = $company;
  741. $online_user['password'] = "";
  742. if (!_isAdmin()) {
  743. if ($rs["is_only_vgm"] == "t") {//VGM用户写死
  744. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where url_action in ('ocean_order','password','vgm') and menu_id in ('ship','profile') order by order_by asc), ',')";
  745. $rrrs = common::excuteOneSql($sql);
  746. } else {
  747. $sql = "select array_to_string(ARRAY(select p.url_action from public.ra_online_user_permission up left join public.ra_online_user u on up.user_name = u.user_login left join public.ra_online_permission p on up.p_id = p.id where lower(u.user_login) = '" . common::check_input(strtolower($uname)) . "'), ',')";
  748. $rrrs = common::excuteOneSql($sql);
  749. if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
  750. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
  751. $rrrs = common::excuteOneSql($sql);
  752. }
  753. }
  754. $online_user['permission'] = $rrrs;
  755. }
  756. if (!empty($online_user['docdownload']))
  757. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
  758. else {
  759. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where active = true";
  760. if (strtolower($online_user['user_type']) == "customer")
  761. $sql .= " and client_display = true";
  762. $sql .= " group by display_name order by min(id)";
  763. }
  764. $online_user['view_doc_type'] = common::excuteListSql($sql);
  765. if (!empty($online_user['view_air_file_format']))
  766. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  767. else {
  768. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where active = true";
  769. if (strtolower($online_user['user_type']) == "customer")
  770. $sql .= " and client_display = true";
  771. $sql .= " group by display_name order by min(id)";
  772. }
  773. $online_user['view_air_doc_type'] = common::excuteListSql($sql);
  774. //补充aci and ams CustomerLogin station - public
  775. $ocean_station_temp = $online_user['ocean_station'];
  776. $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  777. $ocean_agent_temp = $online_user['ocean_agent'];
  778. $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  779. $_SESSION['ONLINE_USER'] = $online_user;
  780. $_SESSION['LAST_OPERATE_TIME'] = time();
  781. $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
  782. //判断是否记录密码 add
  783. if ($_POST['rememberpwd'] === 'true') {
  784. if (!$noCheckPwd) {
  785. $user_info = $uname . "_" . md5($rs['password']);
  786. setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
  787. }
  788. } else {
  789. setcookie('userInfo', '', time() - 1, "/");
  790. }
  791. if ($rs['is_super'] == "t") {
  792. $schemas_list = common::excuteListSql("select * from schemas_list");
  793. } else {
  794. $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
  795. }
  796. ///if (count($schemas_list) > 1) {
  797. foreach ($schemas_list as $sk => $sv) {
  798. if ($sv['schemas_name'] == "public") {
  799. continue;
  800. }
  801. $ttdd = common::excuteObjectSql("select contact_id_user, employee_id, contact_id, user_type, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  802. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  803. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  804. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, po_status, view_air_file_format, special_customer_event, can_edi_vgm, isf_aci_ams_station, is_kerry_shipment from " . $sv['schemas_name'] . ".ra_online_user where lower(user_login) = '" . strtolower($uname) . "'");
  805. if (empty($ttdd)) {
  806. unset($schemas_list[$sk]);
  807. continue;
  808. }
  809. if (!empty($ttdd['docdownload'])) {
  810. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
  811. } else {
  812. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
  813. if (strtolower($ttdd['user_type']) == "customer")
  814. $sql .= " and client_display = true";
  815. $sql .= " group by display_name order by min(id)";
  816. }
  817. $ttdd['view_doc_type'] = common::excuteListSql($sql);
  818. if (!empty($ttdd['view_air_file_format'])) {
  819. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  820. } else {
  821. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where active = true";
  822. if (strtolower($ttdd['user_type']) == "customer")
  823. $sql .= " and client_display = true";
  824. $sql .= " group by display_name order by min(id)";
  825. }
  826. $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
  827. //补充aci and ams CustomerLogin station - other like sfs
  828. $ocean_station_temp = $ttdd['ocean_station'];
  829. $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  830. $ocean_agent_temp = $ttdd['ocean_agent'];
  831. $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  832. $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
  833. }
  834. //}
  835. $_SESSION['schemas_list'] = $schemas_list;
  836. //不再返回登录页面,直接跳转
  837. if (isset($_GET['up'])) {
  838. if($_GET['v'] == 'new'){
  839. header("Location: main_new_version.php?action=main");
  840. }else{
  841. header("Location: main.php?action=main");
  842. }
  843. }
  844. //自动登录。为了方便调用,先注销掉
  845. //exit();
  846. } else {
  847. $data = array(
  848. 'msg' => 'database_error',
  849. 'login_version' => $rs["login_version"],
  850. 'data' => ''
  851. );
  852. common::echo_json_encode(500, $data);
  853. exit();
  854. }
  855. } else {
  856. $data = array(
  857. 'msg' => 'no_exist',
  858. 'login_version' => $rs["login_version"],
  859. 'data' => ''
  860. );
  861. common::echo_json_encode(500, $data);
  862. exit();
  863. }
  864. }
  865. }
  866. private function failedLogin($uname, $company){
  867. $ip = common::ip();
  868. common::excuteUpdateSql("insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')");
  869. }
  870. //重置密码
  871. public function passwordExpires($loginName,$email,$uname){
  872. $result = array(
  873. 'msg' => "passwordExpires",
  874. 'uname' => $uname,
  875. );
  876. common::echo_json_encode(400, $result);
  877. exit();
  878. }
  879. //submit change form -- change expires password
  880. public function update_pwd_expires(){
  881. $loginName = common::check_input($_POST['uname']);
  882. $old_password = common::check_input($_POST['old_password']);
  883. $password = common::check_input($_POST['password']);
  884. //首先校验验证码 展示注销掉
  885. // $verifcation_code =
  886. // $verifcation_code = common::check_input($_POST['verifcation_code']);
  887. // if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
  888. // $data = array(
  889. // 'msg' => 'verifcation_error',
  890. // 'data' => ''
  891. // );
  892. // common::echo_json_encode(400, $data);
  893. // exit();
  894. // }
  895. $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($loginName) . "'";
  896. $rs = common::excuteObjectSql($sql);
  897. $str = '';
  898. if (!empty($rs)) {
  899. if ($rs['password'] != $old_password) {
  900. $str = "Old password is incorrect!";
  901. }
  902. } else {
  903. $str = "Old password is incorrect!";
  904. }
  905. if(!empty($str)){
  906. $data = array(
  907. 'msg' => $str,
  908. 'data' => ''
  909. );
  910. common::echo_json_encode(400, $data);
  911. exit();
  912. }
  913. //验证通过,进行修改密码
  914. $msg = $this->updateExpirePassword($loginName, $password);
  915. if($msg == "success"){
  916. $data = array(
  917. 'msg' => "success",
  918. 'data' => ''
  919. );
  920. common::echo_json_encode(200, $data);
  921. exit();
  922. } else {
  923. $data = array(
  924. 'msg' => $msg,
  925. 'data' => ''
  926. );
  927. common::echo_json_encode(400, $data);
  928. exit();
  929. }
  930. }
  931. //更新密码
  932. public function updateExpirePassword($login,$new_password) {
  933. $str = common::checkPasswordRule($login, $new_password);
  934. //更新密码,擦除expire pwd痕迹
  935. if (empty($str)) {
  936. $sql = "UPDATE public.ra_online_user SET ra_password = '" . common::check_input($new_password) . "',password_new=redant_encode('".$new_password."'),
  937. last_pwd_change = now(),password_expires_keycode = null,password_expires_time = null
  938. WHERE lower(user_login) = '" . common::check_input(strtolower($login)) . "';";
  939. $rls = common::excuteUpdateSql($sql);
  940. if (!$rls) {
  941. $str = "Database Error, Try Later.";
  942. } else {
  943. $sql = "INSERT INTO public.ra_online_user_password_history (user_login, password, create_user, create_date) VALUES ('" . $login . "', " . common::check_input($new_password) . ", '" . $login . "', now());";
  944. common::excuteUpdateSql($sql);
  945. $str = "success";
  946. }
  947. }
  948. return $str;
  949. }
  950. public function getOriginOrAgent($ocean_station_temp){
  951. $session_ocean_station = "";
  952. if (strtolower($ocean_station_temp) == 'all'){
  953. $session_ocean_station = $ocean_station_temp;
  954. }
  955. if (!(strtolower($ocean_station_temp) == 'all' || empty($ocean_station_temp))){
  956. if (utils::checkExist($ocean_station_temp, ";")) {
  957. $ost = str_replace(";","','",strtolower($ocean_station_temp));
  958. $sql="select kerry_station_id,contact_id from ocean.contacts where coalesce(kerry_station_id,'') <>''and lower(contact_id) in ('".$ost."')";
  959. $tar = common::excuteListSql($sql);
  960. foreach ($tar as $tk => $tv) {
  961. $tar[$tv['contact_id']] = $tv['kerry_station_id'];
  962. }
  963. $_tt = explode(";", $ocean_station_temp);
  964. foreach ($_tt as $vv) {
  965. if (!empty($vv)){
  966. $session_ocean_station .= trim($vv).';';
  967. if (!empty($tar[$vv])) {
  968. $session_ocean_station .= $tar[trim($vv)].';';
  969. }
  970. }
  971. }
  972. } else {
  973. $session_ocean_station .= trim($ocean_station_temp).';';
  974. $temp_contacts = common::excuteObjectSql("select kerry_station_id from ocean.contacts where lower(contact_id)='".strtolower(common::check_input($ocean_station_temp))."'");
  975. if (!empty($temp_contacts['kerry_station_id'])){
  976. $session_ocean_station .= $temp_contacts['kerry_station_id'].';';
  977. }
  978. }
  979. }
  980. return $session_ocean_station;
  981. }
  982. public function logout() {
  983. unset($_SESSION['ONLINE_USER']);
  984. unset($_SESSION['LAST_OPERATE_TIME']);
  985. unset($_SESSION['SESSION_TIMEOUT']);
  986. common::sessionDestroy();
  987. $data = array("msg" =>"logout Successful");
  988. common::echo_json_encode(200, $data);
  989. exit();
  990. }
  991. public function tracking_checked(){
  992. $reference_number = common::check_input($_POST['reference_number']);
  993. $is_verify = common::check_input($_POST['verifcation_code']);
  994. if($this->signUpAndTrackingChecked($is_verify)){
  995. $data = array("msg" =>"visit limit");
  996. common::echo_json_encode(200, $data);
  997. exit();
  998. }else{
  999. $data = $this->getTrackingInfo($reference_number);
  1000. common::echo_json_encode(200, $data);
  1001. exit();
  1002. }
  1003. }
  1004. private function signUpAndTrackingChecked($is_verify){
  1005. $Tracking_Search_Count = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Tracking_Search_Count'");
  1006. $ip = common::ip();
  1007. global $db;
  1008. $db->StartTrans();
  1009. $db->Execute("update tracking_login_record set visit_count = 1, visit_time=now() "
  1010. . " where ip = '$ip' and type ilike '".common::check_input($_POST['type'])."' and visit_time + '5 min' < NOW()::timestamp ") or ( (!$db->ErrorMsg()) or error_log($db->ErrorMsg(), 0));
  1011. $ipInfo = $db->GetRow("select ip, visit_count from tracking_login_record where ip = '$ip' and type ilike '".common::check_input($_POST['type'])."' and visit_time + '5 min' > NOW()::timestamp");
  1012. if(empty($ipInfo)){
  1013. $db->Execute("INSERT INTO public.tracking_login_record(ip, visit_count,visit_time,type)VALUES ('$ip', '1', now(),'".common::check_input($_POST['type'])."');") or ( (!$db->ErrorMsg()) or error_log($db->ErrorMsg(), 0));
  1014. }else{
  1015. if ($ipInfo['visit_count'] > $Tracking_Search_Count){
  1016. if(strtolower($_SESSION['captcha']) == strtolower($is_verify) || true ){
  1017. //归零验证次数
  1018. $db->Execute("update tracking_login_record set visit_count = 1 "
  1019. . " where ip = '$ip' and type ilike '".common::check_input($_POST['type'])."' and visit_time + '5 min' > NOW()::timestamp ") or ( (!$db->ErrorMsg()) or error_log($db->ErrorMsg(), 0));
  1020. }else{
  1021. return TRUE;
  1022. }
  1023. }else{
  1024. $db->Execute("update tracking_login_record set visit_count = visit_count::integer + 1 "
  1025. . " where ip = '$ip' and type ilike '".common::check_input($_POST['type'])."' and visit_time + '5 min' > NOW()::timestamp ") or ( (!$db->ErrorMsg()) or error_log($db->ErrorMsg(), 0));
  1026. }
  1027. }
  1028. if ($db->CompleteTrans() === FALSE) {
  1029. //出错拦截
  1030. return TRUE;
  1031. } else {
  1032. return FALSE;
  1033. }
  1034. }
  1035. private function getTrackingInfo($reference_number){
  1036. $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.* ,cc.status as new_status
  1037. from ocean o
  1038. left join LATERAL (select case when a.code='IFFBCF' then 'Booked'
  1039. when a.code='IFFCPU' then 'Cargo Received'
  1040. when a.code='IFFREC' then 'Cargo Received'
  1041. when a.code='IFFDEP' then 'Departed'
  1042. when a.code='IFFARR' then 'Arrived'
  1043. when a.code='IFFAFD' then 'Completed'
  1044. else 'Booked' END as status,
  1045. from ocean_milestone a
  1046. where a.serial_no=o.serial_no
  1047. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  1048. order by id desc limit 1) cc on true
  1049. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1050. address_1 as cn_address_1,
  1051. address_2 as cn_address_2,
  1052. address_3 as cn_address_3,
  1053. address_4 as cn_address_4,
  1054. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1055. phone_1 as cn_phone
  1056. FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1057. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1058. address_1 as sh_address_1,
  1059. address_2 as sh_address_2,
  1060. address_3 as sh_address_3,
  1061. address_4 as sh_address_4,
  1062. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1063. phone_1 as sh_phone
  1064. FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1065. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1066. address_1 as aa_address_1,
  1067. address_2 as aa_address_2,
  1068. address_3 as aa_address_3,
  1069. address_4 as aa_address_4,
  1070. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1071. phone_1 as aa_phone
  1072. FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1073. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1074. address_1 as dd_address_1,
  1075. address_2 as dd_address_2,
  1076. address_3 as dd_address_3,
  1077. address_4 as dd_address_4,
  1078. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1079. phone_1 as dd_phone
  1080. FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1081. where (lower(tracking_no) = '" . strtolower($reference_number) . "'
  1082. or lower(booking_no) = '" . strtolower($reference_number) . "'
  1083. or lower(h_bol) = '" . strtolower($reference_number) . "'
  1084. or lower(m_bol) = '" . strtolower($reference_number) . "'
  1085. or lower(po_no) = '" . strtolower($reference_number) . "'
  1086. or lower(quote_no) = '" . strtolower($reference_number) . "'
  1087. or lower(invoice_no) = '" . strtolower($reference_number) . "'
  1088. or exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number'))";
  1089. $ocean_arr = common::excuteListSql($sql);
  1090. if(empty($ocean_arr)){
  1091. $data = array("msg" =>"No matches");
  1092. return $data;
  1093. }
  1094. if(!empty($ocean_arr) && count($ocean_arr) > 1){
  1095. $data = array("msg" =>"Multiple results");
  1096. return $data;
  1097. }
  1098. $ocean = $ocean_arr[0];
  1099. //处理transportInfo信息数据
  1100. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  1101. "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  1102. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  1103. //处理basicInfo信息数据
  1104. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  1105. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  1106. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  1107. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1108. "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
  1109. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1110. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1111. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1112. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1113. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1114. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1115. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1116. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1117. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1118. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1119. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1120. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1121. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1122. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1123. //处理marksAndDescription
  1124. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  1125. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
  1126. $rss = common::excuteListSql($sql);
  1127. $quantity_tolal = 0;
  1128. $packages = "CTN";
  1129. $g_weight_tolal = 0;
  1130. $ch_weight_tolal = 0;
  1131. $cbm_tolal = 0;
  1132. foreach ($rss as $key => $rs) {
  1133. $quantity_tolal += $rs['qty'];
  1134. $g_weight_tolal += $rs['grs_kgs'];
  1135. $ch_weight_tolal += $rs['grs_lbs'];
  1136. $cbm_tolal += $rs['cbm'];
  1137. $packages = " ".$rs['unit'];
  1138. }
  1139. //Packing 不确定信息
  1140. $packing = array("Quantity/Unit"=>$quantity_tolal.$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  1141. //Milestones 数据信息待定
  1142. $Milestones = common::getMilestonesInfo($ocean);
  1143. global $_COPYRIGHT;
  1144. $data = array('transportInfo' => $transportInfo,
  1145. 'basicInfo' => $basicInfo,
  1146. 'businessPartners' => $businessPartners,
  1147. 'packing' => $packing,
  1148. 'marksAndDescription' => $marksAndDescription,
  1149. 'Milestones' => $Milestones,
  1150. 'copyright' =>$_COPYRIGHT);
  1151. return array("msg" =>"success","data" =>$data);
  1152. }
  1153. }
  1154. ?>