login.class.php 69 KB

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