diff --git a/client.php b/client.php index 9e87d1c3..f2d895e2 100644 --- a/client.php +++ b/client.php @@ -22,22 +22,6 @@ if(isset($_GET['client_id'])){ $row = mysqli_fetch_array($sql); $client_name = $row['client_name']; $client_type = $row['client_type']; - $client_address = $row['client_address']; - $client_city = $row['client_city']; - $client_state = $row['client_state']; - $client_zip = $row['client_zip']; - $client_country = $row['client_country']; - $client_contact = $row['client_contact']; - $client_email = $row['client_email']; - $client_phone = $row['client_phone']; - if(strlen($client_phone)>2){ - $client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4); - } - $client_extension = $row['client_extension']; - $client_mobile = $row['client_mobile']; - if(strlen($client_mobile)>2){ - $client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4); - } $client_website = $row['client_website']; $client_referral = $row['client_referral']; $client_currency_code = $row['client_currency_code']; @@ -53,14 +37,8 @@ if(isset($_GET['client_id'])){ $contact_title = $row['contact_title']; $contact_email = $row['contact_email']; $contact_phone = $row['contact_phone']; - if(strlen($contact_phone)>2){ - $contact_phone = substr($row['contact_phone'],0,3)."-".substr($row['contact_phone'],3,3)."-".substr($row['contact_phone'],6,4); - } $contact_extension = $row['contact_extension']; $contact_mobile = $row['contact_mobile']; - if(strlen($contact_mobile)>2){ - $contact_mobile = substr($row['contact_mobile'],0,3)."-".substr($row['contact_mobile'],3,3)."-".substr($row['contact_mobile'],6,4); - } $location_name = $row['location_name']; $location_address = $row['location_address']; $location_city = $row['location_city']; @@ -68,9 +46,6 @@ if(isset($_GET['client_id'])){ $location_zip = $row['location_zip']; $location_country = $row['location_country']; $location_phone = $row['location_phone']; - if(strlen($location_phone)>2){ - $location_phone = substr($row['location_phone'],0,3)."-".substr($row['location_phone'],3,3)."-".substr($row['location_phone'],6,4); - } //Add up all the payments for the invoice and get the total amount paid to the invoice $sql_invoice_amounts = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE invoice_client_id = $client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled'"); diff --git a/client_contacts.php b/client_contacts.php index a7db1c15..95fc45a8 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -102,9 +102,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $contact_title_display = $contact_title; } $contact_phone = $row['contact_phone']; - if(strlen($contact_phone)>2){ - $contact_phone = substr($row['contact_phone'],0,3)."-".substr($row['contact_phone'],3,3)."-".substr($row['contact_phone'],6,4); - } if(empty($contact_phone)){ $contact_phone_display = "-"; }else{ @@ -112,9 +109,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); } $contact_extension = $row['contact_extension']; $contact_mobile = $row['contact_mobile']; - if(strlen($contact_mobile)>2){ - $contact_mobile = substr($row['contact_mobile'],0,3)."-".substr($row['contact_mobile'],3,3)."-".substr($row['contact_mobile'],6,4); - } if(empty($contact_mobile)){ $contact_mobile_display = "-"; }else{ diff --git a/client_locations.php b/client_locations.php index 74cb8ff2..f8a7d12e 100644 --- a/client_locations.php +++ b/client_locations.php @@ -103,10 +103,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $location_state = $row['location_state']; $location_zip = $row['location_zip']; $location_phone = $row['location_phone']; - - if(strlen($location_phone)>2){ - $location_phone = substr($row['location_phone'],0,3)."-".substr($row['location_phone'],3,3)."-".substr($row['location_phone'],6,4); - } if(empty($location_phone)){ $location_phone_display = "-"; }else{ diff --git a/client_vendors.php b/client_vendors.php index c7e83b60..849c7040 100644 --- a/client_vendors.php +++ b/client_vendors.php @@ -115,9 +115,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $vendor_contact_name_display = $vendor_contact_name; } $vendor_phone = $row['vendor_phone']; - if(strlen($vendor_phone)>2){ - $vendor_phone = substr($row['vendor_phone'],0,3)."-".substr($row['vendor_phone'],3,3)."-".substr($row['vendor_phone'],6,4); - } $vendor_extension = $row['vendor_extension']; $vendor_email = $row['vendor_email']; $vendor_website = $row['vendor_website']; diff --git a/clients.php b/clients.php index 79ce404c..63e2a049 100644 --- a/clients.php +++ b/clients.php @@ -182,14 +182,8 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $contact_name = $row['contact_name']; $contact_title = $row['contact_title']; $contact_phone = $row['contact_phone']; - if(strlen($client_phone)>2){ - $contact_phone = substr($row['contact_phone'],0,3)."-".substr($row['contact_phone'],3,3)."-".substr($row['contact_phone'],6,4); - } $contact_extension = $row['contact_extension']; $contact_mobile = $row['contact_mobile']; - if(strlen($contact_mobile)>2){ - $contact_mobile = substr($row['contact_mobile'],0,3)."-".substr($row['contact_mobile'],3,3)."-".substr($row['contact_mobile'],6,4); - } $contact_email = $row['contact_email']; $client_website = $row['client_website']; $client_currency_code = $row['client_currency_code']; diff --git a/functions.php b/functions.php index 940f50a0..e2ea2ee7 100644 --- a/functions.php +++ b/functions.php @@ -254,4 +254,32 @@ function get_otp($secret_seed) { return $otp; } +function formatPhoneNumber($phoneNumber) { + $phoneNumber = preg_replace('/[^0-9]/','',$phoneNumber); + + if(strlen($phoneNumber) > 10) { + $countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10); + $areaCode = substr($phoneNumber, -10, 3); + $nextThree = substr($phoneNumber, -7, 3); + $lastFour = substr($phoneNumber, -4, 4); + + $phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour; + } + else if(strlen($phoneNumber) == 10) { + $areaCode = substr($phoneNumber, 0, 3); + $nextThree = substr($phoneNumber, 3, 3); + $lastFour = substr($phoneNumber, 6, 4); + + $phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour; + } + else if(strlen($phoneNumber) == 7) { + $nextThree = substr($phoneNumber, 0, 3); + $lastFour = substr($phoneNumber, 3, 4); + + $phoneNumber = $nextThree.'-'.$lastFour; + } + + return $phoneNumber; +} + ?> \ No newline at end of file diff --git a/invoice.php b/invoice.php index 2d7ddec3..9bbc64f7 100644 --- a/invoice.php +++ b/invoice.php @@ -40,14 +40,8 @@ if(isset($_GET['invoice_id'])){ $location_zip = $row['location_zip']; $contact_email = $row['contact_email']; $contact_phone = $row['contact_phone']; - if(strlen($contact_phone)>2){ - $contact_phone = substr($row['contact_phone'],0,3)."-".substr($row['contact_phone'],3,3)."-".substr($row['contact_phone'],6,4); - } $contact_extension = $row['contact_extension']; $contact_mobile = $row['contact_mobile']; - if(strlen($contact_mobile)>2){ - $contact_mobile = substr($row['contact_mobile'],0,3)."-".substr($row['contact_mobile'],3,3)."-".substr($row['contact_mobile'],6,4); - } $client_website = $row['client_website']; $client_currency_code = $row['client_currency_code']; $client_currency_symbol = get_currency_symbol($client_currency_code); diff --git a/login.php b/login.php index 823234e9..1d4cf867 100644 --- a/login.php +++ b/login.php @@ -42,7 +42,7 @@ if(isset($_POST['login'])){ if(empty($token)){ $_SESSION['logged'] = TRUE; - mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Login', log_action = 'Success', log_description = '$ip - $os - $browser - $device', log_created_at = NOW(), user_id = $user_id"); + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Login', log_action = 'Success', log_description = '$ip - $os - $browser - $device', log_created_at = NOW(), log_user_id = $user_id"); header("Location: dashboard.php"); }else{ diff --git a/vendors.php b/vendors.php index 0ec2b721..994428a1 100644 --- a/vendors.php +++ b/vendors.php @@ -136,9 +136,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $vendor_contact_name_display = $vendor_contact_name; } $vendor_phone = $row['vendor_phone']; - if(strlen($vendor_phone)>2){ - $vendor_phone = substr($row['vendor_phone'],0,3)."-".substr($row['vendor_phone'],3,3)."-".substr($row['vendor_phone'],6,4); - } $vendor_extension = $row['vendor_extension']; $vendor_email = $row['vendor_email']; $vendor_website = $row['vendor_website'];