| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of login
- *
- * @author Administrator
- */
- class login {
- private static $_login;
- public static function getInstance() {
- if (!self::$_login) {
- $c = __CLASS__;
- self::$_login = new $c;
- }
- return self::$_login;
- }
- private function getLoginSql($uname) {
- 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,
- 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,
- 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,
- 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,
- 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) . "'";
- }
- public function do_login() {
- $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
- $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
- if (!empty($uname) || !empty($password)) {
-
- } else {
- $uname = common::check_input($_POST['uname']);
- $verifcation_code = common::check_input($_POST['verifcation_code']);
- //首先校验验证码
- if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
- $data = array(
- 'msg' => 'verifcation_error',
- 'data' => ''
- );
- common::echo_json_encode(400, $data);
- exit();
- }
- $sql = $this->getLoginSql($uname);
- $rs = common::excuteObjectSql($sql);
- if (empty($rs['belong_schemas'])) {
- $rs['belong_schemas'] = "public";
- }
- if (empty($rs['main_schemas'])) {
- $rs['main_schemas'] = "public";
- }
- if (!empty($rs)) {
- //验证employee是否active
- if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
- if (strtolower(Soure) =='topocean'){
- if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
- $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
- }else{
- $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
- }
- }
- if (strtolower(Soure) =='apex'){
- $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
- }
-
- $data = array(
- 'msg' => 'no_active',
- 'login_version' => $rs["login_version"],
- 'data' => $data
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Employee not active');
- exit();
- }
- //处理登录状态
- $userInfo = common::check_input($_COOKIE['userInfo']);
- $noCheckPwd = false;
- if (!empty($userInfo)) {
- $userInfoSplit = explode("_", $userInfo);
- if ($uname == $userInfoSplit[0]) {
- if ($userInfoSplit[1] == md5($rs['password'])) {
- $noCheckPwd = true;
- }
- }
- }
-
- if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
- $data = array(
- 'msg' => 'error_times',
- 'login_version' => $rs["login_version"],
- 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
- );
- common::echo_json_encode(400, $data);
-
- $this->failedLogin($uname, 'Failed login too times');
- exit();
- }
- if ($rs['is_online'] != 't') {
- if (strtolower($rs['user_type']) != "employee") {
- $data =array(
- 'msg' => 'no_online',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Online is not active');
- exit();
- }
- }
- //if ($rs['decrypt_password'] != $_POST['psw']) {
- if ($noCheckPwd) {
- }else{
- if ($rs['password'] != $_POST['psw']) {
- 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) . "'");
- $data = array(
- 'msg' => 'password_error',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(400, $data);
- $this->failedLogin($uname, 'Password is wrong');
- exit();
- }
- }
-
- if ($rs['online_active'] != 't') {
- $data = array(
- 'msg' => 'no_active',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Online is not active');
- exit();
- }
- //check password length
- $tar = utils::checkPassword($rs['password']);
- if (!empty($tar)) {
- $data = array(
- 'msg' => $tar,
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- if (empty($rs['last_pwd_change'])) {
- $data = array(
- 'msg' => 'first_login',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
-
- //get more infor by employee_id or contact_id
- $sql = '';
- $diffdate = $rs['last_pwd_change_date'];
- $user_type = $rs['user_type'];
- //if user is customer, check company
- if (strtolower($user_type) == 'customer') {
- $company = $rs['company_name'];
- } else {
- if (!empty($rs['station']))
- $company = $rs['station'];
- }
- if (strtolower($uname) == 'ra.admin') {
- $company = 'Admin';
- }
- // get system config
- $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')";
- $rs1s = common::excuteListSql($sql);
- foreach ($rs1s as $rs1) {
- if ($rs1['ra_name'] == 'employee_session_timeout')
- $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_session_timeout')
- $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'password_change_alert')
- $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'employee_password_change_cycle')
- $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_password_change_cycle')
- $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- }
- $sql="select item_value from config where item='passwordChangePeriod'";
- $pcp = common::excuteObjectSql($sql);
- $passwordChangePeriod = json_decode($pcp["item_value"],true);
- if (strtolower($rs['user_type']) == 'employee') {
- $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
- $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
- $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
- }
- } else {
- $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
- $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
-
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
- $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
- }
- }
- $loginName = $rs['user_login'];
- $email = $rs['email'];
- //Timeout
- if ($diffdate > $PASSWORD_CHANGE_CYCLE) {
- if(empty($email)){
- $data = array(
- 'status' => '0',
- 'msg' => 'login user email is empty',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }else{
- $this -> passwordExpires($loginName,$email);
- }
- }
- if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
- $login_tmp = array(
- 'msg' => 'today',
- 'uname' => $uname,
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
- $login_tmp = array(
- 'msg' => 'last',
- 'uname' => $uname,
- 'login_version' => $rs["login_version"],
- 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
- 'is_only_vgm' => $rs["is_only_vgm"]
- );
- }
- //insert into log table
- $ip = common::ip();
- $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() . "')";
- if (common::excuteUpdateSql($sql)) {
- 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) . "'");
- if (isset($login_tmp)) {
- common::echo_json_encode(200, $login_tmp);
- } else {
- $data = array(
- 'msg' => 'success',
- 'uname' => $uname,
- 'login_version' => $rs["login_version"],
- 'data' => '',
- 'is_only_vgm' => $rs["is_only_vgm"]
- );
- common::echo_json_encode(200, $data);
- }
- $online_user = $rs;
- $online_user['user_login'] = $uname;
- $online_user['company'] = $company;
- $online_user['password'] = "";
- if (!_isAdmin()) {
- if ($rs["is_only_vgm"] == "t") {//VGM用户写死
- $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), ',')";
- $rrrs = common::excuteOneSql($sql);
- } else {
- $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)) . "'), ',')";
- $rrrs = common::excuteOneSql($sql);
- if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
- $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
- $rrrs = common::excuteOneSql($sql);
- }
- }
- $online_user['permission'] = $rrrs;
- }
- if (!empty($online_user['docdownload']))
- $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)";
- else {
- $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";
- if (strtolower($online_user['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $online_user['view_doc_type'] = common::excuteListSql($sql);
- if (!empty($online_user['view_air_file_format']))
- $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)";
- else {
- $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";
- if (strtolower($online_user['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $online_user['view_air_doc_type'] = common::excuteListSql($sql);
- //补充aci and ams CustomerLogin station - public
- $ocean_station_temp = $online_user['ocean_station'];
- $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
-
- $ocean_agent_temp = $online_user['ocean_agent'];
- $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
-
- $_SESSION['ONLINE_USER'] = $online_user;
- $_SESSION['LAST_OPERATE_TIME'] = time();
- $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
-
- //判断是否记录密码 add
- if ($_POST['rememberpwd'] === 'true') {
- if (!$noCheckPwd) {
- $user_info = $uname . "_" . md5($rs['password']);
- setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
- }
- } else {
- setcookie('userInfo', '', time() - 1, "/");
- }
- if ($rs['is_super'] == "t") {
- $schemas_list = common::excuteListSql("select * from schemas_list");
- } else {
- $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
- }
- ///if (count($schemas_list) > 1) {
- foreach ($schemas_list as $sk => $sv) {
- if ($sv['schemas_name'] == "public") {
- continue;
- }
- $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,
- 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,
- 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,
- 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) . "'");
- if (empty($ttdd)) {
- unset($schemas_list[$sk]);
- continue;
- }
- if (!empty($ttdd['docdownload'])) {
- $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)";
- } else {
- $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";
- if (strtolower($ttdd['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $ttdd['view_doc_type'] = common::excuteListSql($sql);
- if (!empty($ttdd['view_air_file_format'])) {
- $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)";
- } else {
- $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";
- if (strtolower($ttdd['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
-
- //补充aci and ams CustomerLogin station - other like sfs
- $ocean_station_temp = $ttdd['ocean_station'];
- $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
- $ocean_agent_temp = $ttdd['ocean_agent'];
- $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
- $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
- }
- //}
- $_SESSION['schemas_list'] = $schemas_list;
- //不再返回登录页面,直接跳转
- if (isset($_GET['up'])) {
- if($_GET['v'] == 'new'){
- header("Location: main_new_version.php?action=main");
- }else{
- header("Location: main.php?action=main");
- }
- }
- exit();
- } else {
- $data = array(
- 'msg' => 'database_error',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- } else {
- $data = array(
- 'msg' => 'no_exist',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- }
- }
- public function check_uname(){
- $uname = common::check_input($_POST['uname']);
- $sql = $this->getLoginSql($uname);
- $rs = common::excuteObjectSql($sql);
- if (!empty($rs)) {
- //只是验证用户是否存在,是否激活
- //验证employee是否active
- if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
- if (strtolower(Soure) =='topocean'){
- if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
- $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
- }else{
- $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
- }
- }
- if (strtolower(Soure) =='apex'){
- $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
- }
- $data = array(
- 'msg' => 'no_active',
- );
- common::echo_json_encode(200, $data);
- exit();
- }
-
- if ($rs['is_online'] != 't') {
- if (strtolower($rs['user_type']) != "employee") {
- $data =array(
- 'msg' => 'no_online',
- );
- common::echo_json_encode(200, $data);
- exit();
- }
- }
- if ($rs['online_active'] != 't') {
- $data = array(
- 'msg' => 'no_active',
- );
- common::echo_json_encode(200, $data);
- exit();
- }
- //验证成功
- $data = array(
- 'msg' => 'success',
- );
- common::echo_json_encode(200, $data);
- exit();
- } else {
- $data = array(
- 'msg' => 'no_exist',
- );
- common::echo_json_encode(200, $data);
- exit();
- }
- }
- public function verifcation_code(){
- // 生成一个4位随机数作为验证码
- //$random_num = mt_rand(1000, 9999);
- $random_num = $this->generateCaptcha(6);
- $_SESSION['captcha'] = $random_num;
-
- // 创建一个宽度为80像素、高度为30像素的图片
- $width = 130;
- $height = 40;
- $image = imagecreate($width, $height);
-
- // 设置颜色
- $white = imagecolorallocate($image, 255, 255, 255); // 白色作为背景
- $black = imagecolorallocate($image, 0, 0, 0); // 黑色作为文字
-
- // 填充背景
- imagefilledrectangle($image, 0, 0, $width, $height, $white);
-
- // 在图片上绘制四个字符
- $font_size = 18;
- $x = 14;
- $y = 12;
- for ($i = 0; $i < 6; $i++) {
- $char = substr($random_num, $i, 1);
- imagestring($image, $font_size, $x, $y, $char, $black);
- $x += $font_size+1;
- }
-
- // 返回Base64编码
- ob_start();
- imagepng($image);
- $image_data = ob_get_clean();
- // 释放内存
- imagedestroy($image);
- $data = array("imagePngBase64" =>base64_encode($image_data));
- common::echo_json_encode(200, $data);
- exit();
- }
- //邮件密码原文
- public function forgot_password() {
- $login = common::check_input($_POST['login']);
- $email = common::check_input($_POST['email']);
- $verifcation_code = common::check_input($_POST['verifcation_code']);
- //首先校验验证码
- if ($_SESSION['captcha'] != $verifcation_code) {
- $data = array(
- 'msg' => 'verifcation_error',
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- $msg = "";
- if (!empty($email) || !empty($login)) {
- $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) . "'";
- $rs = common::excuteObjectSql($sql_p);
- if (!empty($rs)) {
- $r = utils::sendEmailByPassword($login, $rs['password'], $email);
- if ($r == 'success') {
- $msg = "success";
- } else {
- $msg = $r;
- }
- } else {
- $msg = "Can not find this user with give login id and email, please confirm!";
- }
- } else {
- $msg = "Login Name or Email Required !";
- }
- $data = array(
- 'msg' => $msg,
- );
- common::echo_json_encode(200, $data);
- exit();
- }
- public function generateCaptcha($length = 6) {
- $captcha = '';
- $chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789";
- for ($i = 0; $i < $length; $i++) {
- // 随机选择字母或数字
- $char = $chars[mt_rand(0, strlen($chars) - 1)];
- $captcha .= strval($char);
- }
- return $captcha;
- }
- public function do_login_auto() {
- $uname = common::check_input($_GET['u']);
- $password = common::check_input($_GET['p']);
- $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
- $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
- if (!empty($uname) || !empty($password)) {
-
- } else {
- $uname = common::check_input($_POST['uname']);
- $sql = $this->getLoginSql($uname);
- $rs = common::excuteObjectSql($sql);
- if (empty($rs['belong_schemas'])) {
- $rs['belong_schemas'] = "public";
- }
- if (empty($rs['main_schemas'])) {
- $rs['main_schemas'] = "public";
- }
- if (!empty($rs)) {
- //验证employee是否active
- if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
- if (strtolower(Soure) =='topocean'){
- if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
- $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
- }else{
- $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
- }
- }
- if (strtolower(Soure) =='apex'){
- $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
- }
-
- $data = array(
- 'msg' => 'no_active',
- 'login_version' => $rs["login_version"],
- 'data' => $data
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Employee not active');
- exit();
- }
- //add 处理登录状态
- $userInfo = common::check_input($_COOKIE['userInfo']);
- $noCheckPwd = false;
- if (!empty($userInfo)) {
- $userInfoSplit = explode("_", $userInfo);
- if ($uname == $userInfoSplit[0]) {
- if ($userInfoSplit[1] == md5($rs['password'])) {
- $noCheckPwd = true;
- }
- }
- }
-
- //if (!$noCheckPwd) {
- if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
- $data = array(
- 'msg' => 'error_times',
- 'login_version' => $rs["login_version"],
- 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
- );
- common::echo_json_encode(500, $data);
-
- $this->failedLogin($uname, 'Failed login too times');
- exit();
- }
- if ($rs['is_online'] != 't') {
- if (strtolower($rs['user_type']) != "employee") {
- $data =array(
- 'msg' => 'no_online',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Online is not active');
- exit();
- }
- }
- //if ($rs['decrypt_password'] != $_POST['psw']) {
- if ($noCheckPwd) {
- }else{
- if ($rs['password'] != $_POST['psw']) {
- 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) . "'");
- $data = array(
- 'msg' => 'password_error',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Password is wrong');
- exit();
- }
- }
-
- if ($rs['online_active'] != 't') {
- $data = array(
- 'msg' => 'no_active',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- $this->failedLogin($uname, 'Online is not active');
- exit();
- }
- //check password length
- $tar = utils::checkPassword($rs['password']);
- if (!empty($tar)) {
- $data = array(
- 'msg' => $tar,
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- if (empty($rs['last_pwd_change'])) {
- $data = array(
- 'msg' => 'first_login',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- //}
- //get more infor by employee_id or contact_id
- $sql = '';
- $diffdate = $rs['last_pwd_change_date'];
- $user_type = $rs['user_type'];
- //if user is customer, check company
- if (strtolower($user_type) == 'customer') {
- $company = $rs['company_name'];
- } else {
- if (!empty($rs['station']))
- $company = $rs['station'];
- }
- if (strtolower($uname) == 'ra.admin') {
- $company = 'Admin';
- }
- // get system config
- $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')";
- $rs1s = common::excuteListSql($sql);
- foreach ($rs1s as $rs1) {
- if ($rs1['ra_name'] == 'employee_session_timeout')
- $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_session_timeout')
- $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'password_change_alert')
- $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'employee_password_change_cycle')
- $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_password_change_cycle')
- $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- }
- $sql="select item_value from config where item='passwordChangePeriod'";
- $pcp = common::excuteObjectSql($sql);
- $passwordChangePeriod = json_decode($pcp["item_value"],true);
- if (strtolower($rs['user_type']) == 'employee') {
- $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
- $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
- $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
- }
- } else {
- $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
- $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
-
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
- $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
- }
- }
- /* if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
- echo json_encode(array(
- 'msg' => 'password_require_change',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- ));
- $this->failedLogin($uname, 'Required password change');
- exit();
- }*/
- $loginName = $rs['user_login'];
- $email = $rs['email'];
- if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
- if(empty($email)){
- $data = array(
- 'status' => '0',
- 'msg' => 'login user email is empty',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }else{
- //$this -> passwordExpires($loginName,$email);
- }
- }
- if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
- $login_tmp = array(
- 'msg' => 'today',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
- $login_tmp = array(
- 'msg' => 'last',
- 'login_version' => $rs["login_version"],
- 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
- 'is_only_vgm' => $rs["is_only_vgm"]
- );
- }
- //insert into log table
- $ip = common::ip();
- $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() . "')";
- if (common::excuteUpdateSql($sql)) {
- 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) . "'");
- //自动登录。为了方便调用,先注销掉
- if (isset($login_tmp)) {
- //common::echo_json_encode(500, $login_tmp);
- } else {
- $data = array(
- 'msg' => 'success',
- 'login_version' => $rs["login_version"],
- 'data' => '',
- 'is_only_vgm' => $rs["is_only_vgm"]
- );
- //common::echo_json_encode("200", $data);
- }
- $online_user = $rs;
- $online_user['user_login'] = $uname;
- $online_user['company'] = $company;
- $online_user['password'] = "";
- if (!_isAdmin()) {
- if ($rs["is_only_vgm"] == "t") {//VGM用户写死
- $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), ',')";
- $rrrs = common::excuteOneSql($sql);
- } else {
- $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)) . "'), ',')";
- $rrrs = common::excuteOneSql($sql);
- if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
- $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
- $rrrs = common::excuteOneSql($sql);
- }
- }
- $online_user['permission'] = $rrrs;
- }
- if (!empty($online_user['docdownload']))
- $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)";
- else {
- $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";
- if (strtolower($online_user['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $online_user['view_doc_type'] = common::excuteListSql($sql);
- if (!empty($online_user['view_air_file_format']))
- $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)";
- else {
- $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";
- if (strtolower($online_user['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $online_user['view_air_doc_type'] = common::excuteListSql($sql);
- //补充aci and ams CustomerLogin station - public
- $ocean_station_temp = $online_user['ocean_station'];
- $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
-
- $ocean_agent_temp = $online_user['ocean_agent'];
- $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
-
- $_SESSION['ONLINE_USER'] = $online_user;
- $_SESSION['LAST_OPERATE_TIME'] = time();
- $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
-
- //判断是否记录密码 add
- if ($_POST['rememberpwd'] === 'true') {
- if (!$noCheckPwd) {
- $user_info = $uname . "_" . md5($rs['password']);
- setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
- }
- } else {
- setcookie('userInfo', '', time() - 1, "/");
- }
- if ($rs['is_super'] == "t") {
- $schemas_list = common::excuteListSql("select * from schemas_list");
- } else {
- $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
- }
- ///if (count($schemas_list) > 1) {
- foreach ($schemas_list as $sk => $sv) {
- if ($sv['schemas_name'] == "public") {
- continue;
- }
- $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,
- 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,
- 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,
- 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) . "'");
- if (empty($ttdd)) {
- unset($schemas_list[$sk]);
- continue;
- }
- if (!empty($ttdd['docdownload'])) {
- $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)";
- } else {
- $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";
- if (strtolower($ttdd['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $ttdd['view_doc_type'] = common::excuteListSql($sql);
- if (!empty($ttdd['view_air_file_format'])) {
- $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)";
- } else {
- $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";
- if (strtolower($ttdd['user_type']) == "customer")
- $sql .= " and client_display = true";
- $sql .= " group by display_name order by min(id)";
- }
- $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
-
- //补充aci and ams CustomerLogin station - other like sfs
- $ocean_station_temp = $ttdd['ocean_station'];
- $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
- $ocean_agent_temp = $ttdd['ocean_agent'];
- $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
- $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
- }
- //}
- $_SESSION['schemas_list'] = $schemas_list;
- //不再返回登录页面,直接跳转
- if (isset($_GET['up'])) {
- if($_GET['v'] == 'new'){
- header("Location: main_new_version.php?action=main");
- }else{
- header("Location: main.php?action=main");
- }
- }
- //自动登录。为了方便调用,先注销掉
- //exit();
- } else {
- $data = array(
- 'msg' => 'database_error',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- } else {
- $data = array(
- 'msg' => 'no_exist',
- 'login_version' => $rs["login_version"],
- 'data' => ''
- );
- common::echo_json_encode(500, $data);
- exit();
- }
- }
- }
- private function failedLogin($uname, $company){
- $ip = common::ip();
- 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() . "')");
- }
- //重置密码
- public function passwordExpires($loginName,$email){
- $result = array(
- 'msg' => "passwordExpires",
- 'uname' => $loginName,
- );
- common::echo_json_encode(400, $result);
- exit();
- }
- //submit change form -- change expires password
- public function update_pwd_expires(){
- $loginName = common::check_input($_POST['uname']);
- $old_password = common::check_input($_POST['old_password']);
- $password = common::check_input($_POST['password']);
-
- //首先校验验证码 展示注销掉
- // $verifcation_code =
- // $verifcation_code = common::check_input($_POST['verifcation_code']);
- // if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
- // $data = array(
- // 'msg' => 'verifcation_error',
- // 'data' => ''
- // );
- // common::echo_json_encode(400, $data);
- // exit();
- // }
-
- $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($loginName) . "'";
- $rs = common::excuteObjectSql($sql);
- $str = '';
- if (!empty($rs)) {
- if ($rs['password'] != $old_password) {
- $str = "Old password is incorrect!";
- }
- } else {
- $str = "Old password is incorrect!";
- }
- if(!empty($str)){
- $data = array(
- 'msg' => $str,
- 'data' => ''
- );
- common::echo_json_encode(400, $data);
- exit();
- }
- //验证通过,进行修改密码
- $msg = $this->updateExpirePassword($loginName, $password);
- if($msg == "success"){
- $data = array(
- 'msg' => "success",
- 'data' => ''
- );
- common::echo_json_encode(200, $data);
- exit();
- } else {
- $data = array(
- 'msg' => $msg,
- 'data' => ''
- );
- common::echo_json_encode(400, $data);
- exit();
- }
- }
- //更新密码
- public function updateExpirePassword($login,$new_password) {
- $str = common::checkPasswordRule($login, $new_password);
- //更新密码,擦除expire pwd痕迹
- if (empty($str)) {
- $sql = "UPDATE public.ra_online_user SET ra_password = '" . common::check_input($new_password) . "',password_new=redant_encode('".$new_password."'),
- last_pwd_change = now(),password_expires_keycode = null,password_expires_time = null
- WHERE lower(user_login) = '" . common::check_input(strtolower($login)) . "';";
- $rls = common::excuteUpdateSql($sql);
- if (!$rls) {
- $str = "Database Error, Try Later.";
- } else {
- $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());";
- common::excuteUpdateSql($sql);
- $str = "success";
- }
- }
- return $str;
- }
-
- public function getOriginOrAgent($ocean_station_temp){
- $session_ocean_station = "";
- if (strtolower($ocean_station_temp) == 'all'){
- $session_ocean_station = $ocean_station_temp;
- }
- if (!(strtolower($ocean_station_temp) == 'all' || empty($ocean_station_temp))){
- if (utils::checkExist($ocean_station_temp, ";")) {
- $ost = str_replace(";","','",strtolower($ocean_station_temp));
- $sql="select kerry_station_id,contact_id from ocean.contacts where coalesce(kerry_station_id,'') <>''and lower(contact_id) in ('".$ost."')";
- $tar = common::excuteListSql($sql);
- foreach ($tar as $tk => $tv) {
- $tar[$tv['contact_id']] = $tv['kerry_station_id'];
- }
- $_tt = explode(";", $ocean_station_temp);
- foreach ($_tt as $vv) {
- if (!empty($vv)){
- $session_ocean_station .= trim($vv).';';
- if (!empty($tar[$vv])) {
- $session_ocean_station .= $tar[trim($vv)].';';
- }
- }
- }
- } else {
- $session_ocean_station .= trim($ocean_station_temp).';';
- $temp_contacts = common::excuteObjectSql("select kerry_station_id from ocean.contacts where lower(contact_id)='".strtolower(common::check_input($ocean_station_temp))."'");
- if (!empty($temp_contacts['kerry_station_id'])){
- $session_ocean_station .= $temp_contacts['kerry_station_id'].';';
- }
- }
- }
- return $session_ocean_station;
- }
- public function logout() {
- unset($_SESSION['ONLINE_USER']);
- unset($_SESSION['LAST_OPERATE_TIME']);
- unset($_SESSION['SESSION_TIMEOUT']);
- common::sessionDestroy();
- $data = array("msg" =>"logout Successful");
- common::echo_json_encode(200, $data);
- exit();
- }
- public function tracking_checked(){
- $reference_number = common::check_input($_POST['reference_number']);
- $is_verify = common::check_input($_POST['verifcation_code']);
- if($this->signUpAndTrackingChecked($is_verify)){
- $data = array("msg" =>"visit limit");
- common::echo_json_encode(200, $data);
- exit();
- }else{
- $data = $this->getTrackingInfo($reference_number);
- common::echo_json_encode(200, $data);
- exit();
- }
- }
- private function signUpAndTrackingChecked($is_verify){
- $Tracking_Search_Count = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Tracking_Search_Count'");
- $ip = common::ip();
- global $db;
- $db->StartTrans();
- $db->Execute("update tracking_login_record set visit_count = 1, visit_time=now() "
- . " 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));
- $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");
- if(empty($ipInfo)){
- $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));
- }else{
- if ($ipInfo['visit_count'] > $Tracking_Search_Count){
- if(strtolower($_SESSION['captcha']) == strtolower($is_verify) || true ){
- //归零验证次数
- $db->Execute("update tracking_login_record set visit_count = 1 "
- . " 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));
- }else{
- return TRUE;
- }
- }else{
- $db->Execute("update tracking_login_record set visit_count = visit_count::integer + 1 "
- . " 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));
- }
- }
- if ($db->CompleteTrans() === FALSE) {
- //出错拦截
- return TRUE;
- } else {
- return FALSE;
- }
- }
- private function getTrackingInfo($reference_number){
- $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.* ,cc.status as new_status
- from ocean o
- left join LATERAL (select case when a.code='IFFBCF' then 'Booked'
- when a.code='IFFCPU' then 'Cargo Received'
- when a.code='IFFREC' then 'Cargo Received'
- when a.code='IFFDEP' then 'Departed'
- when a.code='IFFARR' then 'Arrived'
- when a.code='IFFAFD' then 'Completed'
- else 'Booked' END as status,
- from ocean_milestone a
- where a.serial_no=o.serial_no
- and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
- order by id desc limit 1) cc on true
- LEFT JOIN LATERAL ( SELECT company as cn_company,
- address_1 as cn_address_1,
- address_2 as cn_address_2,
- address_3 as cn_address_3,
- address_4 as cn_address_4,
- city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
- phone_1 as cn_phone
- FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
- LEFT JOIN LATERAL ( SELECT company as sh_company,
- address_1 as sh_address_1,
- address_2 as sh_address_2,
- address_3 as sh_address_3,
- address_4 as sh_address_4,
- city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
- phone_1 as sh_phone
- FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
- LEFT JOIN LATERAL ( SELECT company as aa_company,
- address_1 as aa_address_1,
- address_2 as aa_address_2,
- address_3 as aa_address_3,
- address_4 as aa_address_4,
- city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
- phone_1 as aa_phone
- FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
- LEFT JOIN LATERAL ( SELECT company as dd_company,
- address_1 as dd_address_1,
- address_2 as dd_address_2,
- address_3 as dd_address_3,
- address_4 as dd_address_4,
- city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
- phone_1 as dd_phone
- FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
- where (lower(tracking_no) = '" . strtolower($reference_number) . "'
- or lower(booking_no) = '" . strtolower($reference_number) . "'
- or lower(h_bol) = '" . strtolower($reference_number) . "'
- or lower(m_bol) = '" . strtolower($reference_number) . "'
- or lower(po_no) = '" . strtolower($reference_number) . "'
- or lower(quote_no) = '" . strtolower($reference_number) . "'
- or lower(invoice_no) = '" . strtolower($reference_number) . "'
- or exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number'))";
- $ocean_arr = common::excuteListSql($sql);
- if(empty($ocean_arr)){
- $data = array("msg" =>"No matches");
- return $data;
- }
- if(!empty($ocean_arr) && count($ocean_arr) > 1){
- $data = array("msg" =>"Multiple results");
- return $data;
- }
- $ocean = $ocean_arr[0];
- //处理transportInfo信息数据
- $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
- "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
- "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
- //处理basicInfo信息数据
- $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
- $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
- $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
- "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
- "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
- //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
- $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
- $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
- $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
- $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
- $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
- $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
- $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
- $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
- $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
- $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
- $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
- $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
- $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
-
- //处理marksAndDescription
- $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
-
- $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
- $rss = common::excuteListSql($sql);
- $quantity_tolal = 0;
- $packages = "CTN";
- $g_weight_tolal = 0;
- $ch_weight_tolal = 0;
- $cbm_tolal = 0;
- foreach ($rss as $key => $rs) {
- $quantity_tolal += $rs['qty'];
- $g_weight_tolal += $rs['grs_kgs'];
- $ch_weight_tolal += $rs['grs_lbs'];
- $cbm_tolal += $rs['cbm'];
- $packages = " ".$rs['unit'];
- }
- //Packing 不确定信息
- $packing = array("Quantity/Unit"=>$quantity_tolal.$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
- //Milestones 数据信息待定
- $Milestones = common::getMilestonesInfo($ocean);
- global $_COPYRIGHT;
- $data = array('transportInfo' => $transportInfo,
- 'basicInfo' => $basicInfo,
- 'businessPartners' => $businessPartners,
- 'packing' => $packing,
- 'marksAndDescription' => $marksAndDescription,
- 'Milestones' => $Milestones,
- 'copyright' =>$_COPYRIGHT);
- return array("msg" =>"success","data" =>$data);
- }
- }
- ?>
|