| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of utilsclass
- *
- * @author Administrator
- */
- class utils {
- public static function checkPassword($password,$rule="",$user_login="") {
- $str ="";
- if (!empty($rule)) {
- //是否校验大小写
- if (!empty($rule["hasOneUpperChar"])&&$rule["hasOneUpperChar"]) {
- if (!preg_match('/[A-Z]/',$password)) {
- $str ="Password must contain uppercase letters";
- }
- }
- //是否校验小写
- if (!empty($rule["hasOneLowerChar"])&&$rule["hasOneLowerChar"]) {
- if (!preg_match('/[a-z]/',$password)) {
- $str ="Password must contain lowercase letters";
- }
- }
- //是否存在数字
- if (!empty($rule["hasOneNumberChar"])&&$rule["hasOneNumberChar"]) {
- if (!preg_match('/[0-9]/',$password)) {
- $str ="Password must contain numbers";
- }
- }
- $sql = "select user_type from ra_online_user_roles_rel where upper(user_login)=upper('".$user_login."') and exists(select count(0) from ra_online_user where upper(user_login)=upper('".$user_login."') and is_desktop=true) order by id desc limit 1;";
- $user_type = common::excuteOneSql($sql);
- if (!empty($user_type)&&$user_type=="Super User") {
- if (strlen($password)<$rule["SuperMinLen"]||strlen($password)>$rule["SuperMaxLen"]) {
- $str ="Super user password length between ".$rule["SuperMinLen"]." and ".$rule["SuperMaxLen"];
- }
- }else{
- //校验密码长度
- if (strlen($password)<$rule["MinLen"]||strlen($password)>$rule["MaxLen"]) {
- $str ="Password length between ".$rule["MinLen"]." and ".$rule["MaxLen"];
- }
- }
- return $str;
- }else{
- if (preg_match('/^\d*$/', $password) || preg_match('/^[a-zA-Z]+$/', $password)) {
- $str ="Must include letters and numbers";
- }
- $len = strlen($password);
- $t = substr($password, 0, 1);
- for ($i = 1; $i < $len; $i++) {
- $t1 = substr($password, $i, 1);
- if ($t != $t1) {
- return "";
- }
- }
- return "error";
- }
- }
- //隐藏邮箱地址
- public static function maskEmail($email) {
- $idex = strlen($email) - strrpos($email, ".");
- $mask = substr($email, 0, 1) . str_repeat('*', 6) . "@" . str_repeat('*', 3) . substr($email, -$idex);
- return $mask;
- }
- public static function getInSql($str, $not = false, $sep = ";") {
- $str = trim($str);
- $str = trim($str, $sep);
- $str = trim($str);
- if (empty($str) && $str !== "0" && $str !== 0)
- return "1<>1";
- $str = strtolower($str);
- if (utils::checkExist($str, $sep)) {
- $aa = explode($sep, $str);
- $msg = "";
- foreach ($aa as $value) {
- $value = trim($value);
- if (empty($value))
- continue;
- if (empty($msg))
- $msg = "'" . common::check_input($value) . "'";
- else
- $msg .= ",'" . common::check_input($value) . "'";
- }
- if ($not !== FALSE)
- return " not in (" . $msg . ")";
- else
- return " in (" . $msg . ")";
- } else {
- if ($not !== FALSE)
- return " != '" . common::check_input(trim($str)) . "'";
- else
- return " = '" . common::check_input(trim($str)) . "'";
- }
- }
- public static function checkExist($string, $search, $u = TRUE) {
- if ($u === TRUE) {
- if (stripos($string, $search) !== false)
- return TRUE;
- }else {
- if (strpos($string, $search) !== false)
- return TRUE;
- }
- return FALSE;
- }
- public static function endWith($string, $end, $u = TRUE) {
- if ($u === TRUE) {
- $string = strtolower($string);
- $end = strtolower($end);
- return strrchr($string, $end) == $end;
- }
- return strrchr($string, $end) == $end;
- }
- public static function _get($str) {
- $rs = isset($_POST[$str]) ? $_POST[$str] : null;
- if (empty($rs))
- $rs = isset($_GET[$str]) ? $_GET[$str] : null;
- return $rs;
- }
- public static function startWith($string, $start, $u = TRUE) {
- if ($u === TRUE)
- return stripos($string, $start) === 0;
- return strpos($string, $start) === 0;
- }
- public static function outDisplay($content, $is_time = 'f', $is_first = 'f', $is_boolean = 'f', $excel_export = FALSE) {
- if (empty($content) && $content !== 0 && $content !== "0")
- return "";
- if (strtolower($is_time) == 't')
- return utils::dealTimeDisplay($content);
- if (strtolower($is_first) == 't') {
- if ($excel_export !== FALSE)
- return utils::getCompanyName($content);
- else
- return '<span title="' . $content . '">' . utils::getCompanyName($content) . '</span>';
- }
- if (strtolower($is_boolean) == 't')
- return utils::outTrue($content);
- return nl2br($content);
- }
- public static function _output($value) {
- if (empty($value))
- return " ";
- else
- return $value;
- }
- public static function dealTimeDisplay($date) {
- if (empty($date))
- return "";
- if (strlen($date) > 10)
- return date("m/d/Y H:i:s", strtotime($date));
- return date("m/d/Y", strtotime($date));
- }
- public static function outDisplayForMerge($frist,$last,$split = "/") {
- if (!empty($frist)){
- if(!empty($last)){
- return $frist.$split.$last;
- }else{
- return $frist;
- }
- }else{
- return $last;
- }
- }
- public static function outTrue($r) {
- if (empty($r))
- return "No";
- $r = strtolower($r);
- if ($r == "t")
- return "Yes";
- elseif ($r == "f")
- return "No";
- else
- return $r;
- }
- public static function getCompanyName($detail) {
- $detail = nl2br($detail);
- if (strpos($detail, '<br />') === FALSE)
- return $detail;
- return substr($detail, 0, strpos($detail, '<br />'));
- }
- public static function getEmail($serial_no) {
- $ocean = common::excuteObjectSql("select sales_rep, last_user, created_by, order_from, h_bol, consignee, dest_op, agent from public.online_ocean where md5(serial_no)=md5('$serial_no') "
- . "order by schem_not_display nulls last limit 1");
- $schema = $ocean["order_from"] . ".";
- $dest_op_from_agent = common::excuteOneSql("select dest_op_from_agent from " . $schema . "ocean where md5(serial_no)=md5('$serial_no')");
- if ($ocean["agent"] == "KYMTL" || $ocean["agent"] == "KYYYZ") {
- $email = array();
- $email["email"] = "";
- if (!empty($dest_op_from_agent)) {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
- }
- if (!empty($so_email)) {
- if (empty($email["email"])) {
- $email["email"] = $so_email;
- } else {
- $email["email"] .= ";" . $so_email;
- }
- }
- if (!empty($ocean["sales_rep"])) {
- $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
- if (!empty($rep_email)) {
- if (empty($email["email"])) {
- $email["email"] = $rep_email;
- } else {
- $email["email"] .= ";" . $rep_email;
- }
- }
- }
- } else {
- $email = common::excuteObjectSql("select string_agg(e.email, ';') as email, string_agg(e.first_name, ';') as name from " . $schema . "ra_online_user u, " . $schema . "employee e WHERE u.employee_id = e.employee_id and "
- . "lower(u.user_login) in ('" . strtolower($ocean["created_by"]) . "', '" . strtolower($ocean["last_user"]) . "')");
- if (empty($dest_op_from_agent)) {
- if (!empty($ocean["dest_op"])) {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $ocean["dest_op"] . "' and active=true");
- }
- } else {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
- }
- if (empty($so_email)) {
- if ($ocean["agent"] == "APEXSFO") {
- $so_email = "oid2@apexshipping.com";
- }
- if ($ocean["agent"] == "APEXLAX") {
- $so_email = "laxoid@apexshipping.com";
- }
- if ($ocean["agent"] == "APEXNYC") {
- $so_email = "NYCOID@APEXSHIPPING.COM";
- }
- if ($ocean["agent"] == "APEXPNW") {
- $so_email = "pnwoid@apexshipping.com";
- }
- if ($ocean["agent"] == "STLUTA") {
- $so_email = "starlinkOID@apexshipping.com ";
- }
- if ($ocean["agent"] == "APEXORD") {
- $so_email = "ordoid@apexshipping.com";
- }
- }
- if (!empty($so_email)) {
- if (empty($email["email"])) {
- $email["email"] = $so_email;
- } else {
- $email["email"] .= ";" . $so_email;
- }
- }
- if (!empty($ocean["sales_rep"])) {
- $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
- if (!empty($rep_email)) {
- if (empty($email["email"])) {
- $email["email"] = $rep_email;
- } else {
- $email["email"] .= ";" . $rep_email;
- }
- }
- }
- }
- $email["h_bol"] = $ocean["h_bol"];
- $email["consignee"] = $ocean["consignee"];
- return $email;
- }
- /***
- * 过滤json中的某个数据
- * @param unknown $json
- * @param unknown $search
- * @param unknown $replace
- * @return mixed
- */
- public static function jsonFiltration($search,$replace,$json){
- //处理json中将斜杠转义问题
- $json = str_replace("\\/", "/", $json);
- return str_replace($search, $replace, $json);
- }
- /*
- * calculate eta destination by etd port
- */
- public static function calculate_ETA_Des($serial_no) {
- $sql = "SELECT m_eta as eat, mport_of_discharge as poul, place_of_delivery as pod,service from ocean where lower(serial_no) = '" . strtolower($serial_no) . "'";
- $rs = common::excuteObjectSql($sql);
- $date = "";
- if (!empty($rs['eat'])) {
- $date = utils::calculate_ETA_Dest($rs['eat'], $rs['poul'], $rs['pod'], $rs['service']);
- }
- return $date;
- }
- public static function calculate_ETA_Dest($eta, $poul, $pod, $service) {
- if (empty($poul) || empty($pod))
- return $eta;
- $sql = "SELECT door_days, cy_days
- FROM eta_dest
- WHERE eta_dest.state::text = ((( SELECT unlocode.state
- FROM ports, unlocode
- WHERE ports.uncode::text = unlocode.uncode::text AND ports.code::text = '" . common::check_input($pod) . "'
- LIMIT 1))::text) AND (','::text || eta_dest.pod::text) ~~* (('%,'::text || '" . common::check_input($poul) . "') || '%'::text)
- LIMIT 1";
- //$sql = "select door_days, cy_days from eta_dest where state = (select state from ports where code = '" . common::check_input($poul) . "' limit 1) and ','||pod ilike '%," . common::check_input($pod) . "%'";
- $rs = common::excuteObjectSql($sql);
- if (empty($rs))
- return $eta;
- if (utils::endWith($service, "cy"))
- return common::addDays($eta, $rs['cy_days']);
- else
- return common::addDays($eta, $rs['door_days']);
- }
- /*
- * password change, email alert
- */
- public static function sendEmailByPassword($username, $password, $email, $companyname='') {
- $sql = "select subject, ra_content as content from ra_online_email_tpl where lower(ra_type) = 'forgotpw'";
- $rs = common::excuteObjectSql($sql);
- if (!empty($rs)) {
- $subject = $rs['subject'];
- $content = $rs['content'];
- }
- if (!empty($subject) && !empty($content)) {
- $content = str_replace('<{username}>', $username, $content);
- $content = str_replace('<{password}>', $password, $content);
- $content = str_replace('<{companyname}>', $companyname, $content);
- global $db;
- common::excuteUpdateSql("INSERT INTO public.email_record_forgotpassword(type, title, from_email, to_email, content, insert_date,
- cc_email) VALUES ('forgot_password', '" . common::check_input($subject) . "', 'US.KApex.Online@kerryapex.com', '" .
- common::check_input($email) . "', '" . common::check_input($content) . "', now(), '');");
- return "success";
- //return Mail::sendMail($email, $subject, $content);
- } else
- return null;
- }
- public static function operation_log_records(){
- //排除opreation_log操作
- if($_REQUEST["action"] == "opreation_log"
- || empty($_REQUEST["operate"])
- || ($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "verifcation_code")){
- return;
- }
- $user_type = _isCustomerLogin() ? "Customer" : "Employee";
- $user_name = _getLoginName();
- $page = utils::getPageByAction($_REQUEST["action"]);
- $operation = $_REQUEST["operate"];
- $operation_detail = utils::jsonFiltration("null", "\"\"", json_encode($_REQUEST));
- $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
- operation_time)
- VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
- common::excuteUpdateSql($sql);
- }
- public static function getPageByAction($action){
- if($action == "ocean_booking"){
- $action = "Booking";
- }elseif($action == "ocean_order"){
- $action = "Tracking";
- }
- return ucfirst($action);
- }
- public static function calculateTicks($minValue, $maxValue, $targetTickCount = 10) {
- $tickSpacing = ($maxValue - $minValue);
- $len = strlen($tickSpacing);
- if($len >=2 ){
- $interval = ceil($tickSpacing/pow(10,$len-2)/10) *pow(10,$len-2);
- }else{
- $interval = ceil($tickSpacing/10);
- }
- return $interval;
- }
- }
- ?>
|