File manager - Edit - /home/autoph/public_html/connectv1/api/customer/customerv2_update.php
Back
<?php include_once("../../cfg/db.php"); include_once("../controllers/customer.php"); include_once("../controllers/religion.php"); include_once("../controllers/interest_hobbies.php"); include_once("../controllers/affiliations.php"); include_once("../controllers/school.php"); include_once("../controllers/car_club.php"); include_once("../controllers/political_club.php"); include_once("../controllers/unit_association.php"); include_once("../controllers/network_marketing.php"); include_once("../controllers/media_publication.php"); include_once("../controllers/sme_group.php"); include_once("../controllers/fraternities_sororities.php"); include_once("../controllers/facebook_group.php"); include_once("../controllers/celebrity_influencer.php"); include_once("../controllers/company_dealer.php"); include_once("../controllers/company.php"); include_once("../controllers/dealer.php"); include_once("../controllers/dms.php"); include_once("../controllers/nature_of_business.php"); include_once("../controllers/profession.php"); include_once("../controllers/mode_of_contact.php"); include_once("../controllers/utility.php"); include_once("../controllers/logger.php"); $customer = new Customer(); $religion = new Religion(); $interest_hobbies = new InterestHobbies(); $affiliations = new Affiliations(); $school = new School(); $car_club = new CarClub(); $unit_association = new UnitAssociation(); $political_club = new PoliticalClub(); $network_marketing = new NetworkMarketing(); $media_publication = new MediaPublication(); $sme_group = new SmeGroup(); $fraternities_sororities = new FraternitiesSororities(); $facebook_group = new FacebookGroup(); $celebrity_influencer = new CelebrityInfluencer(); $company_dealer = new CompanyDealer(); $dms = new DMS(); $company = new Company(); $dealer = new Dealer(); $nature_of_business = new NatureOfBusiness(); $profession = new Profession(); $mode_of_contact = new ModeOfContact(); $utility = new Utility(); $logger = new Logger(); if (!isset($_SESSION['user']['id'])) { echo "Session Expired."; exit; } $my_customer_record_id = $_SESSION['user']['id']; $server_method = $_SERVER["REQUEST_METHOD"]; $granted_company_ids = $utility->isNotEmpty($_SESSION['user']['company_permissions_implode']) ? $_SESSION['user']['company_permissions_implode'] : '-1'; $fields_permissions = isset($_SESSION['user']['fields_permissions']['customer_fields']) ? $_SESSION['user']['fields_permissions']['customer_fields'] : false; if (isset($_REQUEST['apiKey'])) { $apiKey = $_REQUEST['apiKey']; if ($apiKey === '7347482808054211') { //Create $customer_id = $utility->generate_uuid($db); $customer_data = isset($_REQUEST['customer_data']) ? $_REQUEST['customer_data'] : '{}'; $customer_data_array = json_decode($customer_data, true); $customer_data_array = array_map(array($utility, 'upperCaseNestedArray'), $customer_data_array); $customer_data_array = array_map(array($db, 'escape'), $customer_data_array); // $customer -> delete_customer_no_connections($db); $customer_type = 1; //Defualt Individual Customer if ($utility->isNotEmpty($customer_data_array["mod-corporation-name"])) { $customer_type = 2; } $customer_data_array["mod-contact"] = $utility->remove_non_numeric($customer_data_array["mod-contact"]); // if($customer_type == 1){ $new_customer_number = (($utility->isNotEmpty($customer_data_array["mod-contact"])) ? '+63' . $customer_data_array["mod-contact"] : ''); $customer_data_array["mod-other-mobile-number1"] = (isset($customer_data_array["mod-other-mobile-number1"]) ? $utility->remove_non_numeric($customer_data_array["mod-other-mobile-number1"]) : ''); // if($customer_type == 1){ // $new_customer_number = (($utility->isNotEmpty($customer_data_array["mod-other-mobile-number1"])) ? '+63' . $customer_data_array["mod-other-mobile-number1"] : ''); // }else if($customer_type == 2){ // $new_customer_number = (($utility->isNotEmpty($customer_data_array["mod-contact-corporation"])) ? $customer_data_array["mod-contact-corporation"] : ''); // $new_customer_number = $utility->fix_mobile_format($new_customer_number); // } $customer_dms = isset($_REQUEST['customer_dms']) ? $_REQUEST['customer_dms'] : ''; $customer_dms = array_map("unserialize", array_unique(array_map("serialize", $customer_dms))); $customer_dms = array_map(array($db, 'escape'), $customer_dms); $force_update = isset($_REQUEST['force_update']) ? $_REQUEST['force_update'] : false; $force_update_reason = isset($_REQUEST['force_update_reason']) ? $db->escape($_REQUEST['force_update_reason']) : ''; if ($customer_type == 2) { if ($customer->read_customer_name_if_exist($customer_data_array["mod-corporation-name"], $db) > 0) { $customer_name = $customer->read_customer_info_and_id_by_name($customer_data_array["mod-corporation-name"], $db); if ($customer_name['corporation_name'] == $customer_data_array["mod-corporation-name"]) { if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $dms_comapny_dealer_count = $customer->read_customer_dms_company_dealer($customer_name['id'], $customer_dms_row['DMS'], $company_dealer_id, $db); if ($dms_comapny_dealer_count > 0) { $customer_dms_company_dealer = $customer->read_customer_dms_company_dealer_name($customer_dms_row['DMS'], $customer_dms_row['Company'], $customer_dms_row['Dealer'], $db); $return_arr["status"] = 4; $return_arr["message"] = "This customer already exist in " . $customer_dms_company_dealer['dms'] . ', ' . $customer_dms_company_dealer['company'] . ' and ' . $customer_dms_company_dealer['dealer'] . '.'; echo json_encode($return_arr); exit; } } } else { $return_arr["status"] = 0; $return_arr["message"] = "Error has occurred."; echo json_encode($return_arr); exit; } } else { $return_arr["status"] = 2; $return_arr["message"] = "Customer already registered."; echo json_encode($return_arr); exit; } $customer_dms_array = array(); if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $customer_dms_array[] = "('" . $customer_name['id'] . "','" . $customer_dms_row['Customer_No'] . '_' . $customer_dms_row['DMS'] . $company_dealer_id . "'," . $company_dealer_id . ",'1')"; } $customer_dms_to_insert = implode(',', $customer_dms_array); $insert_customer_dms = $customer->create_customer_dms($customer_dms_to_insert, $db); } $return_arr["status"] = 1; $return_arr["message"] = "Customer Data Inserted."; echo json_encode($return_arr); exit; } } if ($utility->isNotEmpty($new_customer_number) && $customer_type == 1) { if (!$force_update) { if ($customer->read_customer_mobile_if_exist($new_customer_number, $db) > 0) { /** Logic: if mobile exist if different customer type message: mobile already registered else if name is same if dms,company,dealer is same message: customer already registered -> stop add customer new dms merge from old message: mobile already registered -> stop else insert customer -> stop */ // implementation $customer_name = $customer->read_customer_name_and_id_by_mobile_number($new_customer_number, $db); if ($customer_name['type'] != $customer_type) { $return_arr["status"] = 2; $return_arr["message"] = "Mobile already registered."; echo json_encode($return_arr); exit; } if ($customer_type == 1) { if (($customer_name['first_name'] == $customer_data_array["mod-firstname"]) && ($customer_name['last_name'] == $customer_data_array["mod-lastname"])) { if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $dms_comapny_dealer_count = $customer->read_customer_dms_company_dealer($customer_name['id'], $customer_dms_row['DMS'], $company_dealer_id, $db); if ($dms_comapny_dealer_count > 0) { $customer_dms_company_dealer = $customer->read_customer_dms_company_dealer_name($customer_dms_row['DMS'], $customer_dms_row['Company'], $customer_dms_row['Dealer'], $db); $return_arr["status"] = 4; $return_arr["message"] = "This customer already exist in DMS: " . $customer_dms_company_dealer['dms'] . ', Company: ' . $customer_dms_company_dealer['company'] . ' and Dealer: ' . $customer_dms_company_dealer['dealer'] . '.'; echo json_encode($return_arr); exit; } } } else { $return_arr["status"] = 0; $return_arr["message"] = "Error has occurred."; echo json_encode($return_arr); exit; } } else { $return_arr["status"] = 2; $return_arr["message"] = "Mobile already registered."; echo json_encode($return_arr); exit; } //deprecated } else if ($customer_type == 2) { if ($customer_name['corporation_name'] == $customer_data_array["mod-corporation-name"]) { if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $dms_comapny_dealer_count = $customer->read_customer_dms_company_dealer($customer_name['id'], $customer_dms_row['DMS'], $company_dealer_id, $db); if ($dms_comapny_dealer_count > 0) { $customer_dms_company_dealer = $customer->read_customer_dms_company_dealer_name($customer_dms_row['DMS'], $customer_dms_row['Company'], $customer_dms_row['Dealer'], $db); $return_arr["status"] = 4; $return_arr["message"] = "This customer already exist in " . $customer_dms_company_dealer['dms'] . ', ' . $customer_dms_company_dealer['company'] . ' and ' . $customer_dms_company_dealer['dealer'] . '.'; echo json_encode($return_arr); exit; } } } else { $return_arr["status"] = 0; $return_arr["message"] = "Error has occurred."; echo json_encode($return_arr); exit; } } else { $return_arr["status"] = 2; $return_arr["message"] = "Mobile already registered."; echo json_encode($return_arr); exit; } } $customer_dms_array = array(); if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $customer_dms_array[] = "('" . $customer_name['id'] . "','" . $customer_dms_row['Customer_No'] . '_' . $customer_dms_row['DMS'] . $company_dealer_id . "'," . $company_dealer_id . ",'1')"; } $customer_dms_to_insert = implode(',', $customer_dms_array); $insert_customer_dms = $customer->create_customer_dms($customer_dms_to_insert, $db); } $return_arr["status"] = 1; $return_arr["message"] = "Customer Data Inserted."; echo json_encode($return_arr); exit; } } if (!$force_update) { if ($utility->isNotEmpty($customer_data_array["mod-email"])) { if ($customer->read_customer_email_if_exist($customer_data_array["mod-email"], $db) > 0) { $return_arr["status"] = 3; $return_arr["message"] = "Email already registered"; echo json_encode($return_arr); exit; } } } } if ($force_update) { // $customer->insert_duplicate_reason($customer_id,$customer_data_array["mod-email"],$new_customer_number,$force_update_reason,$_SESSION['user']['id'],$utility,$db); $log_desc = "Duplicate customer: %s %s %s %s"; $logger->create( $_SESSION['user']['id'], sprintf( $log_desc, ($customer_type == 1) ? '[ID:' . $customer_id . ', ' . $customer_data_array["mod-firstname"] . ' ' . $customer_data_array["mod-lastname"] . ']' : '[ID:' . $customer_id . ', ' . $customer_data_array["mod-corporation-name"] . ']', ($utility->isNotEmpty($new_customer_number)) ? '[Mobile: ' . $new_customer_number . ']' : '', ($utility->isNotEmpty($customer_data_array["mod-email"])) ? '[Email: ' . $customer_data_array["mod-email"] . ']' : '', ($utility->isNotEmpty($force_update_reason)) ? '[Reason: ' . $force_update_reason . ']' : '' ), $customer_id, 'duplicate_customer', $db ); } $religion_name = ($customer_data_array["mod-dd-religion"]); if ($utility->isNotEmpty($religion_name)) { $religion_id = $religion->read_religion_id_by_name($religion_name, $db); if (!$utility->isNotEmpty($religion_id)) { $religion_id = $religion->create_religion($religion_name, $db); } } else { $religion_id = 0; } $date_of_birth = ''; if ($utility->isNotEmpty($customer_data_array["mod-birthdate"])) { $date_of_birth = $utility->convert_sql_date($customer_data_array["mod-birthdate"], 'mm/dd/yyyy'); } $nature_of_business_name = ($customer_data_array["mod-nature-of-business"]); if ($utility->isNotEmpty($nature_of_business_name)) { $nature_of_business_id = $nature_of_business->read_nature_of_business_id_by_name($nature_of_business_name, $db); if (!$utility->isNotEmpty($nature_of_business_id)) { $nature_of_business_id = $nature_of_business->create_nature_of_business($nature_of_business_name, $db); } } else { $nature_of_business_id = 0; } $profession_name = ($customer_data_array["mod-dd-profession"]); if ($utility->isNotEmpty($profession_name)) { $profession_id = $profession->read_profession_id_by_name($profession_name, $db); if (!$utility->isNotEmpty($profession_id)) { $profession_id = $profession->create_profession($profession_name, $db); } } else { $profession_id = 0; } $array_data['aha_status'] = intval($customer_data_array['aha-status']); // Insert Customer Informnation $insert_customer = $customer->create_customer( $array_data, $customer_id, $customer_data_array["mod-corporation-name"], 0, //salutation_id $customer_data_array["mod-firstname"], $customer_data_array["mod-middlename"], $customer_data_array["mod-lastname"], $customer_data_array["mod-dd-suffix"], $customer_data_array["mod-dd-gender"], $customer_data_array["mod-dd-nationality"], $date_of_birth, $customer_data_array["mod-dd-marital-status"], 0, //source_id deprecated 0, //mode_of_contact_id deprecated $customer_data_array["mod-spouse"], $customer_data_array["mod-position"], '', //contact_person deprecated 'default.png', $_SESSION['user']['id'], $customer_type, $customer_data_array["mod-dd-customer-category"], $religion_id, $customer_data_array["mod-business-company"], $profession_id, $nature_of_business_id, 1, //status $db ); // Insert Customer Business // $insert_customer_business = $customer->create_customer_business( // $customer_id, // $customer_data_array["mod-dd-profession"], // $customer_data_array["mod-business-company"], // '', //address // '0', //city_id // '', //postal // '1', //status // $db); $mode_of_contact_name = ($customer_data_array["mod-preferred-moc"]); if ($utility->isNotEmpty($mode_of_contact_name)) { $mode_of_contact_id = $mode_of_contact->read_mode_of_contact_id_by_name($mode_of_contact_name, $db); if (!$utility->isNotEmpty($mode_of_contact_id)) { $mode_of_contact_id = $mode_of_contact->create_mode_of_contact($mode_of_contact_name, $db); } } else { $mode_of_contact_id = 0; } // echo'<pre>';print_r($customer_data_array);echo'</pre>'; $insert_customer_contact = $customer->create_customer_contact( $customer_id, $customer_data_array["mod-address-1"], $customer_data_array["mod-address-2"], '0', //state 1 '0', //state 2 $customer_data_array["mod-dd-city-1"], $customer_data_array["mod-dd-city-2"], $customer_data_array["mod-postal-1"], $customer_data_array["mod-postal-2"], $customer_data_array["mod-email"], (isset($customer_data_array["mod-other-email1"]) ? $customer_data_array["mod-other-email1"] : ''), (isset($customer_data_array["mod-other-email2"]) ? $customer_data_array["mod-other-email2"] : ''), $customer_data_array["mod-viber"], $customer_data_array["mod-facebook"], $customer_data_array["mod-instagram"], $customer_data_array["mod-telegram"], $customer_data_array["mod-whatsapp"], '', //other social $customer_data_array["mod-website"], $utility->fix_mobile_format($customer_data_array["mod-business-number"]), '', //fax $new_customer_number, (isset($customer_data_array["mod-other-mobile-number1"]) ? $utility->fix_mobile_format($customer_data_array["mod-other-mobile-number1"]): ''), (isset($customer_data_array["mod-other-mobile-number2"]) ? $utility->fix_mobile_format($customer_data_array["mod-other-mobile-number2"]) : ''), $utility->fix_mobile_format($customer_data_array["mod-home-phone"]), $mode_of_contact_id, $customer_data_array["mod-landline"], '1', $db ); // echo'<pre>';print_r( $insert_customer_contact);echo'</pre>';exit; $customer_dms_array = array(); if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $customer_dms_array[] = "('$customer_id','" . $customer_dms_row['Customer_No'] . '_' . $customer_dms_row['DMS'] . $company_dealer_id . "'," . $company_dealer_id . ",'1')"; } $customer_dms_to_insert = implode(',', $customer_dms_array); $insert_customer_dms = $customer->create_customer_dms($customer_dms_to_insert, $db); } $customer_contact_persons = isset($_REQUEST['customer_contact_person']) ? $_REQUEST['customer_contact_person'] : ''; // print_r($customer_contact_persons);exit; $customer_contact_person_array = array(); if ($customer_contact_persons <> '') { $customer_contact_persons = array_map(array($utility, 'upperCaseNestedArray'), $customer_contact_persons); $customer_contact_persons = array_map(array($db, 'escape'), $customer_contact_persons); foreach ($customer_contact_persons as $customer_contact_person) { $customer_contact_person_array[] = "('$customer_id','" . $customer_contact_person['Fullname'] . "','" . $customer_contact_person['Email'] . "','" . (($utility->isNotEmpty($customer_contact_person["Mobile"])) ? '+63' . $customer_contact_person["Mobile"] : '') . "','1')"; } $contact_person_to_insert = implode(',', $customer_contact_person_array); $customer->create_customer_contact_person($contact_person_to_insert, $db); } $customer_childrens = isset($_REQUEST['customer_children']) ? $_REQUEST['customer_children'] : ''; $customer_children_array = array(); if ($customer_childrens <> '') { $customer_childrens = array_map(array($utility, 'upperCaseNestedArray'), $customer_childrens); $customer_childrens = array_map(array($db, 'escape'), $customer_childrens); foreach ($customer_childrens as $customer_children) { $new_children_date_of_birth = $utility->convert_sql_date($customer_children['Birthday'], 'mm/dd/yyyy'); $customer_children_array[] = "('$customer_id','" . $customer_children['Firstname'] . "', '" . $customer_children['Lastname'] . "','" . $new_children_date_of_birth . "','" . (($utility->isNotEmpty($customer_children['Mobile'])) ? '+63' . $customer_children['Mobile'] : '') . "','1')"; } $customer_children_to_insert = implode(',', $customer_children_array); $customer->create_customer_children($customer_children_to_insert, $db); } $customer_interests = isset($_REQUEST['customer_interest']) ? $_REQUEST['customer_interest'] : ''; $customer_interest_array = array(); if ($customer_interests <> '') { $customer_interests = array_map(array($utility, 'upperCaseNestedArray'), $customer_interests); $customer_interests = array_map(array($db, 'escape'), $customer_interests); foreach ($customer_interests as $customer_interest) { $interest_category_id = $customer_interest['Category']; $interest_name = ($customer_interest['Interest']); $interest_id = $interest_hobbies->read_interest_id_by_name($interest_category_id, $interest_name, $db); if (!$utility->isNotEmpty($interest_id)) { $interest_id = $interest_hobbies->create_interest($interest_category_id, $interest_name, $db); } $customer_interest_array[] = "('" . $interest_id . "','$customer_id','1')"; } $customer_interest_to_insert = implode(',', $customer_interest_array); $customer->create_customer_interest_list($customer_interest_to_insert, $db); } $customer_affiliations = isset($_REQUEST['customer_affiliations']) ? $_REQUEST['customer_affiliations'] : ''; $customer_affiliations_array = array(); if ($customer_affiliations <> '') { $customer_affiliations = array_map(array($utility, 'upperCaseNestedArray'), $customer_affiliations); $customer_affiliations = array_map(array($db, 'escape'), $customer_affiliations); foreach ($customer_affiliations as $customer_affiliation) { $affiliations_category_id = $customer_affiliation['Category']; $affiliations_name = ($customer_affiliation['Affiliations']); $affiliations_id = $affiliations->read_affiliations_id_by_name($affiliations_category_id, $affiliations_name, $db); if (!$utility->isNotEmpty($affiliations_id)) { $affiliations_id = $affiliations->create_affiliations($affiliations_category_id, $affiliations_name, $db); } $customer_affiliations_array[] = "('" . $affiliations_id . "','$customer_id','1')"; } $customer_affiliations_to_insert = implode(',', $customer_affiliations_array); $customer->create_customer_affiliations_list($customer_affiliations_to_insert, $db); } if (intval($insert_customer) > 0 && intval($insert_customer_contact) > 0) { $return_arr["status"] = 1; $return_arr["message"] = "Customer Data Inserted"; $log_desc = "Add customer: %s"; $logger->create( $_SESSION['user']['id'], sprintf( $log_desc, ($customer_type == 1) ? '[ID:' . $customer_id . ', ' . $customer_data_array["mod-firstname"] . ' ' . $customer_data_array["mod-lastname"] . ']' : '[ID:' . $customer_id . ', ' . $customer_data_array["mod-corporation-name"] . ']' ), $customer_id, 'add_customer', $db ); } else { $return_arr["status"] = 0; $return_arr["message"] = "Customer Data Not Inserted"; } // $return_arr["status"]=1; // $return_arr["message"]="Customer Data Inserted"; echo json_encode($return_arr); } else if ($apiKey === '8906433219679554') { //Update customer details $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer_data = isset($_REQUEST['customer_data']) ? $_REQUEST['customer_data'] : '{}'; $customer_data_array = json_decode($customer_data, true); $customer_data_array = array_map(array($utility, 'upperCaseNestedArray'), $customer_data_array); $customer_data_array = array_map(array($db, 'escape'), $customer_data_array); $customer_type = 1; //Defualt Individual Customer if ($utility->isNotEmpty($customer_data_array["mod-corporation-name"])) { $customer_type = 2; } // if($customer_type == 1){ $new_customer_number = (($utility->isNotEmpty($customer_data_array["mod-contact"])) ? '+63' . $customer_data_array["mod-contact"] : ''); //modify $new_customer_number2 =(isset($customer_data_array["mod-other-mobile-number1"]) ? (($utility->isNotEmpty($customer_data_array["mod-other-mobile-number1"])) ? '+63' . $customer_data_array["mod-other-mobile-number1"] : '') : ''); $new_customer_number3 =(isset($customer_data_array["mod-other-mobile-number2"]) ? (($utility->isNotEmpty($customer_data_array["mod-other-mobile-number2"])) ? '+63' . $customer_data_array["mod-other-mobile-number2"] : '') : ''); // }else if($customer_type == 2){ // $new_customer_number = (($utility->isNotEmpty($customer_data_array["mod-contact-corporation"])) ? $customer_data_array["mod-contact-corporation"] : ''); // $new_customer_number = $utility->fix_mobile_format($new_customer_number); // } $customer_dms = isset($_REQUEST['customer_dms']) ? $_REQUEST['customer_dms'] : ''; $customer_dms = array_map("unserialize", array_unique(array_map("serialize", $customer_dms))); $customer_dms = array_map(array($db, 'escape'), $customer_dms); $force_update = isset($_REQUEST['force_update']) ? $_REQUEST['force_update'] : false; $force_update_reason = isset($_REQUEST['force_update_reason']) ? $db->escape($_REQUEST['force_update_reason']) : ''; // if($customer_dms <> ''){ // foreach ($customer_dms as $customer_dms_row){ // $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'],$customer_dms_row['Dealer'],'1',$db); // $customer_dms_id = $customer_dms_row['Customer_No'].'_'.$customer_dms_row['DMS'].$company_dealer_id; // $customer_dms_information = $customer->get_customer_dms_company_dealer_name_by_customer_dms_id($customer_dms_id,$db); // if(count($customer_dms_information) > 0 && $customer_id <> $customer_dms_information['customer_record_id']){ // $customer_dms_information = array_map(array($utility, 'upperCaseNestedArray'), $customer_dms_information); // $customer_dms_information = array_map(array($db, 'escape'), $customer_dms_information); // $return_arr["status"]=4; // $return_arr["message"]="This customer no. ".$customer_dms_row['Customer_No']." is already exist in ".$customer_dms_information['dms_name'].', '.$customer_dms_information['company_name'].' and '.$customer_dms_information['dealer_name']; // echo json_encode($return_arr); // exit; // } // } // } // if($customer->read_customer_name_if_exist($customer_data_array["mod-corporation-name"],$db) > 0){ // $customer_name = $customer->read_customer_info_and_id_by_name($customer_data_array["mod-corporation-name"],$db); // if($customer_name['corporation_name'] == $customer_data_array["mod-corporation-name"]){ $old_infos = $customer->read_customer_info_and_contact($customer_id, $db); $old_info_array = array(); foreach ($old_infos as $old_info) { $old_info_array = $old_info; } if ($db->escape($old_info_array['corporation_name']) <> $customer_data_array["mod-corporation-name"]) { if ($customer->read_customer_name_if_exist($customer_data_array["mod-corporation-name"], $db) > 0) { $return_arr["status"] = 0; $return_arr["message"] = "Customer name already exists."; echo json_encode($return_arr); exit; } } if ($customer_type == 1) { if ($old_info_array['mobile_phone_1'] <> $new_customer_number) { if (!$force_update) { if ($customer->read_customer_mobile_if_exist($new_customer_number, $db) > 0) { $return_arr["status"] = 2; $return_arr["message"] = "Mobile already registered."; echo json_encode($return_arr); exit; } } } // if($customer_type == 1){ if ($utility->isNotEmpty($customer_data_array["mod-email"])) { // if($customer_id == '27563965982706219'){ // echo $old_info_array['email_1'] .' '. $customer_data_array["mod-email"] ; // exit; // } if (strtolower($old_info_array['email_1']) <> strtolower($customer_data_array["mod-email"])) { if (!$force_update) { if ($customer->read_customer_email_if_exist($customer_data_array["mod-email"], $db) > 0) { $return_arr["status"] = 3; $return_arr["message"] = "Email already registered"; echo json_encode($return_arr); exit; } } } } } //reason in force update if ($force_update) { // $customer->insert_duplicate_reason($customer_id,$customer_data_array["mod-email"],$new_customer_number,$force_update_reason,$_SESSION['user']['id'],$utility,$db); $log_desc = "Duplicate customer: %s %s %s %s"; $logger->create( $_SESSION['user']['id'], sprintf( $log_desc, ($customer_type == 1) ? '[ID:' . $customer_id . ', ' . $customer_data_array["mod-firstname"] . ' ' . $customer_data_array["mod-lastname"] . ']' : '[ID:' . $customer_id . ', ' . $customer_data_array["mod-corporation-name"] . ']', ($utility->isNotEmpty($new_customer_number)) ? '[Mobile: ' . $new_customer_number . ']' : '', ($utility->isNotEmpty($customer_data_array["mod-email"])) ? '[Email: ' . $customer_data_array["mod-email"] . ']' : '', ($utility->isNotEmpty($force_update_reason)) ? '[Reason: ' . $force_update_reason . ']' : '' ), $customer_id, 'duplicate_customer', $db ); } $religion_name = ($customer_data_array["mod-dd-religion"]); if ($utility->isNotEmpty($religion_name)) { $religion_id = $religion->read_religion_id_by_name($religion_name, $db); if (!$utility->isNotEmpty($religion_id)) { $religion_id = $religion->create_religion($religion_name, $db); } } else { $religion_id = 0; } $date_of_birth = ''; if ($utility->isNotEmpty($customer_data_array["mod-birthdate"])) { $date_of_birth = $utility->convert_sql_date($customer_data_array["mod-birthdate"], 'mm/dd/yyyy'); } $nature_of_business_name = ($customer_data_array["mod-nature-of-business"]); if ($utility->isNotEmpty($nature_of_business_name)) { $nature_of_business_id = $nature_of_business->read_nature_of_business_id_by_name($nature_of_business_name, $db); if (!$utility->isNotEmpty($nature_of_business_id)) { $nature_of_business_id = $nature_of_business->create_nature_of_business($nature_of_business_name, $db); } } else { $nature_of_business_id = 0; } $profession_name = ($customer_data_array["mod-dd-profession"]); if ($utility->isNotEmpty($profession_name)) { $profession_id = $profession->read_profession_id_by_name($profession_name, $db); if (!$utility->isNotEmpty($profession_id)) { $profession_id = $profession->create_profession($profession_name, $db); } } else { $profession_id = 0; } $array_data['aha_status'] = intval($customer_data_array['aha-status']); // Insert Customer Informnation $update_customer = $customer->update_customer( $array_data, $customer_id, $customer_data_array["mod-corporation-name"], 0, //salutation_id $customer_data_array["mod-firstname"], $customer_data_array["mod-middlename"], $customer_data_array["mod-lastname"], $customer_data_array["mod-dd-suffix"], $customer_data_array["mod-dd-gender"], $customer_data_array["mod-dd-nationality"], $date_of_birth, $customer_data_array["mod-dd-marital-status"], 0, //source_id deprecated 0, //mode_of_contact_id deprecated $customer_data_array["mod-spouse"], $customer_data_array["mod-position"], '', //contact_person deprecated 'default.png', $_SESSION['user']['id'], $customer_type, $customer_data_array["mod-dd-customer-category"], $religion_id, $_SESSION['user']['id'], $customer_data_array["mod-business-company"], $profession_id, $nature_of_business_id, 1, //status $db ); // // Insert Customer Business // $update_customer_business = $customer->update_customer_business( // $customer_id, // $customer_data_array["mod-dd-profession"], // $customer_data_array["mod-business-company"], // '', //address // '0', //city_id // '', //postal // '1', //status // $db); $mode_of_contact_name = ($customer_data_array["mod-preferred-moc"]); if ($utility->isNotEmpty($mode_of_contact_name)) { $mode_of_contact_id = $mode_of_contact->read_mode_of_contact_id_by_name($mode_of_contact_name, $db); if (!$utility->isNotEmpty($mode_of_contact_id)) { $mode_of_contact_id = $mode_of_contact->create_mode_of_contact($mode_of_contact_name, $db); } } else { $mode_of_contact_id = 0; } $update_customer_contact = $customer->update_customer_contact( // var_dump($utility->fix_mobile_format($customer_data_array["mod-other-mobile-number"]));exit; $customer_id, $customer_data_array["mod-address-1"], $customer_data_array["mod-address-2"], '0', //state 1 '0', //state 2 $customer_data_array["mod-dd-city-1"], $customer_data_array["mod-dd-city-2"], $customer_data_array["mod-postal-1"], $customer_data_array["mod-postal-2"], $customer_data_array["mod-email"], (isset($customer_data_array["mod-other-email1"]) ? $customer_data_array["mod-other-email1"] : ''), (isset($customer_data_array["mod-other-email2"]) ? $customer_data_array["mod-other-email2"] : ''), $customer_data_array["mod-viber"], $customer_data_array["mod-facebook"], $customer_data_array["mod-instagram"], $customer_data_array["mod-telegram"], $customer_data_array["mod-whatsapp"], '', //other social $customer_data_array["mod-website"], (isset($customer_data_array["mod-business-number"]) ? $utility->fix_mobile_format($customer_data_array["mod-business-number"]) :''), '', //fax $new_customer_number, (isset($customer_data_array['mod-other-mobile-number1']) ? $utility->fix_mobile_format($customer_data_array["mod-other-mobile-number1"]):''), (isset($customer_data_array['mod-other-mobile-number2']) ? $utility->fix_mobile_format($customer_data_array["mod-other-mobile-number2"]):''), $utility->fix_mobile_format($customer_data_array["mod-home-phone"]), $mode_of_contact_id, $customer_data_array["mod-landline"], '1', $db ); $customer->delete_customer_dms($customer_id, $granted_company_ids, $db); $customer_dms_array = array(); if ($customer_dms <> '') { foreach ($customer_dms as $customer_dms_row) { $company_dealer_id = $company_dealer->read_company_dealer_id($customer_dms_row['Company'], $customer_dms_row['Dealer'], '1', $db); $customer_dms_array[] = "('$customer_id','" . $customer_dms_row['Customer_No'] . '_' . $customer_dms_row['DMS'] . $company_dealer_id . "'," . $company_dealer_id . ",'1')"; } $customer_dms_to_insert = implode(',', $customer_dms_array); $insert_customer_dms = $customer->create_customer_dms($customer_dms_to_insert, $db); } $customer_contact_persons = isset($_REQUEST['customer_contact_person']) ? $_REQUEST['customer_contact_person'] : ''; // print_r($customer_contact_persons);exit; $customer->delete_contact_person($customer_id, $db); $customer_contact_person_array = array(); if ($customer_contact_persons <> '') { $customer_contact_persons = array_map(array($utility, 'upperCaseNestedArray'), $customer_contact_persons); $customer_contact_persons = array_map(array($db, 'escape'), $customer_contact_persons); foreach ($customer_contact_persons as $customer_contact_person) { $customer_contact_person_array[] = "('$customer_id','" . $customer_contact_person['Fullname'] . "','" . $customer_contact_person['Email'] . "','" . (($utility->isNotEmpty($customer_contact_person["Mobile"])) ? '+63' . $customer_contact_person["Mobile"] : '') . "','1')"; } $contact_person_to_insert = implode(',', $customer_contact_person_array); $customer->create_customer_contact_person($contact_person_to_insert, $db); } $customer_childrens = isset($_REQUEST['customer_children']) ? $_REQUEST['customer_children'] : ''; $customer_children_array = array(); $customer->delete_customer_children($customer_id, $db); if ($customer_childrens <> '') { $customer_childrens = array_map(array($utility, 'upperCaseNestedArray'), $customer_childrens); $customer_childrens = array_map(array($db, 'escape'), $customer_childrens); foreach ($customer_childrens as $customer_children) { $new_children_date_of_birth = $utility->convert_sql_date($customer_children['Birthday'], 'mm/dd/yyyy'); $customer_children_array[] = "('$customer_id','" . $customer_children['Firstname'] . "', '" . $customer_children['Lastname'] . "','" . $new_children_date_of_birth . "','" . (($utility->isNotEmpty($customer_children['Mobile'])) ? '+63' . $customer_children['Mobile'] : '') . "','1')"; } $customer_children_to_insert = implode(',', $customer_children_array); $customer->create_customer_children($customer_children_to_insert, $db); } $customer_interests = isset($_REQUEST['customer_interest']) ? $_REQUEST['customer_interest'] : ''; $customer_interest_array = array(); $customer->delete_customer_interest_list($customer_id, $db); if ($customer_interests <> '') { $customer_interests = array_map(array($utility, 'upperCaseNestedArray'), $customer_interests); $customer_interests = array_map(array($db, 'escape'), $customer_interests); foreach ($customer_interests as $customer_interest) { $interest_category_id = $customer_interest['Category']; $interest_name = ($customer_interest['Interest']); $interest_id = $interest_hobbies->read_interest_id_by_name($interest_category_id, $interest_name, $db); if (!$utility->isNotEmpty($interest_id)) { $interest_id = $interest_hobbies->create_interest($interest_category_id, $interest_name, $db); } $customer_interest_array[] = "('" . $interest_id . "','$customer_id','1')"; } $customer_interest_to_insert = implode(',', $customer_interest_array); $customer->create_customer_interest_list($customer_interest_to_insert, $db); } $customer_affiliations = isset($_REQUEST['customer_affiliations']) ? $_REQUEST['customer_affiliations'] : ''; $customer_affiliations_array = array(); $customer->delete_customer_affiliations_list($customer_id, $db); if ($customer_affiliations <> '') { $customer_affiliations = array_map(array($utility, 'upperCaseNestedArray'), $customer_affiliations); $customer_affiliations = array_map(array($db, 'escape'), $customer_affiliations); foreach ($customer_affiliations as $customer_affiliation) { $affiliations_category_id = $customer_affiliation['Category']; $affiliations_name = ($customer_affiliation['Affiliations']); $affiliations_id = $affiliations->read_affiliations_id_by_name($affiliations_category_id, $affiliations_name, $db); if (!$utility->isNotEmpty($affiliations_id)) { $affiliations_id = $affiliations->create_affiliations($affiliations_category_id, $affiliations_name, $db); } $customer_affiliations_array[] = "('" . $affiliations_id . "','$customer_id','1')"; } $customer_affiliations_to_insert = implode(',', $customer_affiliations_array); $customer->create_customer_affiliations_list($customer_affiliations_to_insert, $db); } if (intval($update_customer) > 0 && intval($update_customer_contact) > 0) { $return_arr["status"] = 1; $return_arr["message"] = "Customer Data Updated"; $old_name = ''; $new_name = ''; if ($customer_type == 1) { $old_name = $old_info_array['first_name'] . ' ' . $old_info_array['middle_name'] . ' ' . $old_info_array['last_name']; $new_name = $customer_data_array["mod-firstname"] . ' ' . $customer_data_array["mod-middlename"] . ' ' . $customer_data_array["mod-lastname"]; } else if ($customer_type == 2) { $old_name = $old_info_array['corporation_name']; $new_name = $customer_data_array["mod-corporation-name"]; } // echo'NEW DATA<pre>';print_r($customer_data_array);echo'</pre>'; // echo'OLD DATA : <pre>';print_r($old_info_array); echo'</pre>'; //modify $log_name = ($old_name == $new_name) ? '' : "[Name: " . $old_name . " to " . $new_name . "]\n"; $log_mobile = ($old_info_array["mobile_phone_1"] == $new_customer_number) ? '' : "[Mobile: " . $old_info_array["mobile_phone_1"] . " to " . $new_customer_number . "]\n"; $log_mobile2 = ($old_info_array['mobile_phone_2'] == $new_customer_number2 ? '' : '[Other Mobile 1 :'. $old_info_array['mobile_phone_2'].' to '.$new_customer_number2.']\n'); $log_mobile3 =($old_info_array['mobile_phone_3'] == $new_customer_number3 ? '' : '[Other Mobile 2 :'. $old_info_array['mobile_phone_3'].' to '.$new_customer_number3.']\n'); $log_email = ($old_info_array["email_1"] == $customer_data_array["mod-email"]) ? '' : "[Email: " . $old_info_array["email_1"] . " to " . $customer_data_array["mod-email"] . "]\n"; $log_email2 =(isset($customer_data_array["mod-other-email1"]) ? ($old_info_array["email_2"] == $customer_data_array["mod-other-email1"]) ? '' : "[Email: " . $old_info_array["email_2"] . " to " . $customer_data_array["mod-other-email1"] . "]\n" :''); $log_email3 =(isset($customer_data_array["mod-other-email2"]) ? ($old_info_array["email_3"] == $customer_data_array["mod-other-email2"]) ? '' : "[Email: " . $old_info_array["email_3"] . " to " . $customer_data_array["mod-other-email2"] . "]\n" : ''); $log_address = ($old_info_array["address_1"] == $customer_data_array["mod-address-1"]) ? '' : "[Address: " . $old_info_array["address_1"] . " to " . $customer_data_array["mod-address-1"] . "]\n"; $log_address2 = ($old_info_array["address_2"] == $customer_data_array["mod-address-2"]) ? '' : "[Other address: " . $old_info_array["address_2"] . " to " . $customer_data_array["mod-address-2"] . "]\n"; $log_bday = ($old_info_array["date_of_birth"] == date('Y-m-d',strtotime($customer_data_array["mod-birthdate"]))) ? '' : "[Birthday: " . $old_info_array["date_of_birth"] . " to " . date('Y-m-d',strtotime($customer_data_array["mod-birthdate"])) . "]\n"; $log_gender = ($old_info_array["gender_id"] == $customer_data_array["mod-dd-gender"]) ? '' : "[Gender: " . ($old_info_array["gender_id"]==1 ? 'Male' : 'Female') . " to " . ($customer_data_array["mod-dd-gender"]==1 ? 'Male' : 'Female') . "]\n"; $log_desc = "Update customer: %s%s%s%s%s%s%s%s%s%s%s%s"; //modify $logger->create( $_SESSION['user']['id'], sprintf( $log_desc, "[ID:" . $customer_id . ", " . $new_name . "]\n", $log_name, $log_gender, $log_bday, $log_mobile, $log_mobile2, $log_mobile3, $log_email, $log_email2, $log_email3, $log_address, $log_address2 ), $customer_id, 'update_customer', $db ); } else { $return_arr["status"] = 0; $return_arr["message"] = "Customer Data Not Updated"; } // $return_arr["status"]=1; // $return_arr["message"]="Customer Data Updated"; echo json_encode($return_arr); } else if ($apiKey === '3463916057587803' && $utility->isPostMethod($server_method)) { //Read $customer_id = isset($_REQUEST['customer_id']) ? $db->escape($_REQUEST['customer_id']) : '-1'; $customer_information = $customer->read_customer_profile($customer_id, $db); $customer_information['mod-dd-religion'] = $religion->read_religion_name_by_id($customer_information['mod-dd-religion'], $db); if ($utility->isNotEmpty($customer_information['mod-birthdate'])) { $customer_information['mod-birthdate'] = $utility->convert_sql_date_to_date_picker($customer_information['mod-birthdate']); //$religion->read_religion_name_by_id($customer_information['mod-birthdate-unformat'],$db); } // $customer_business = $customer->read_customer_business($customer_id,$db); $customer_contact = $customer->read_customer_contact($customer_id, $db); $return_information = array_merge($customer_information, $customer_contact); echo json_encode(array($return_information)); } else if ($apiKey === '8361020315855100' && $utility->isPostMethod($server_method)) { //Read Display // echo'aaaaa';exit $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer_information = $customer->read_customer_profile_display($customer_id, $granted_company_ids, $db); $customer_information['main_email'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_email']) ? $utility->mask_email($customer_information['main_email']) : '') : ((isset($fields_permissions['fields_email_1']) && !$fields_permissions['fields_email_1']) ? ($utility->isNotEmpty($customer_information['main_email']) ? $utility->mask_email($customer_information['main_email']) : '') : $customer_information['main_email']); $customer_information['main_customer_email_2'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_email_2']) ? $utility->mask_email($customer_information['main_customer_email_2']) : '') : ((isset($fields_permissions['fields_email_2']) && !$fields_permissions['fields_email_2']) ? ($utility->isNotEmpty($customer_information['main_customer_email_2']) ? $utility->mask_email($customer_information['main_customer_email_2']) : '') : $customer_information['main_customer_email_2']); $customer_information['main_customer_landline'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_landline']) ? $utility->mask($customer_information['main_customer_landline'], 2, 1) : '') : ((isset($fields_permissions['fields_landline']) && !$fields_permissions['fields_landline']) ? ($utility->isNotEmpty($customer_information['main_customer_landline']) ? $utility->mask($customer_information['main_customer_landline'], 2, 1) : '') : $customer_information['main_customer_landline']); $customer_information['main_customer_mobile'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_mobile']) ? $utility->mask($customer_information['main_customer_mobile'], 4, 1) : '') : ((isset($fields_permissions['fields_mobile_1']) && !$fields_permissions['fields_mobile_1']) ? ($utility->isNotEmpty($customer_information['main_customer_mobile']) ? $utility->mask($customer_information['main_customer_mobile'], 4, 1) : '') : $customer_information['main_customer_mobile']); $customer_information['main_customer_mobile_2'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_mobile_2']) ? $utility->mask($customer_information['main_customer_mobile_2'], 4, 1) : '') : ((isset($fields_permissions['fields_mobile_2']) && !$fields_permissions['fields_mobile_2']) ? ($utility->isNotEmpty($customer_information['main_customer_mobile_2']) ? $utility->mask($customer_information['main_customer_mobile_2'], 4, 1) : '') : $customer_information['main_customer_mobile_2']); $customer_information['main_customer_home_mobile'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_home_mobile']) ? $utility->mask($customer_information['main_customer_home_mobile'], 4, 1) : '') : ((isset($fields_permissions['fields_home_phone']) && !$fields_permissions['fields_home_phone']) ? ($utility->isNotEmpty($customer_information['main_customer_home_mobile']) ? $utility->mask($customer_information['main_customer_home_mobile'], 4, 1) : '') : $customer_information['main_customer_home_mobile']); $customer_information['main_customer_business_mobile'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_business_mobile']) ? $utility->mask($customer_information['main_customer_business_mobile'], 4, 1) : '') : ((isset($fields_permissions['fields_business_phone']) && !$fields_permissions['fields_business_phone']) ? ($utility->isNotEmpty($customer_information['main_customer_business_mobile']) ? $utility->mask($customer_information['main_customer_business_mobile'], 4, 1) : '') : $customer_information['main_customer_business_mobile']); $customer_information['main_customer_address_1'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_address_1']) ? $utility->mask($customer_information['main_customer_address_1'], 2, 2) : '') : ((isset($fields_permissions['fields_address_1']) && !$fields_permissions['fields_address_1']) ? ($utility->isNotEmpty($customer_information['main_customer_address_1']) ? $utility->mask($customer_information['main_customer_address_1'], 3, 0) : '') : $customer_information['main_customer_address_1']); $customer_information['main_customer_address_2'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_customer_address_2']) ? $utility->mask($customer_information['main_customer_address_2'], 2, 2) : '') : ((isset($fields_permissions['fields_address_2']) && !$fields_permissions['fields_address_2']) ? ($utility->isNotEmpty($customer_information['main_customer_address_2']) ? $utility->mask($customer_information['main_customer_address_2'], 3, 0) : '') : $customer_information['main_customer_address_2']); $customer_information['main_viber'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_viber']) ? $utility->mask($customer_information['main_viber'], 2, 1) : '') : ((isset($fields_permissions['fields_viber']) && !$fields_permissions['fields_viber']) ? ($utility->isNotEmpty($customer_information['main_viber']) ? $utility->mask($customer_information['main_viber'], 2, 1) : '') : $customer_information['main_viber']); $customer_information['main_facebook'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_facebook']) ? $utility->mask($customer_information['main_facebook'], 2, 1) : '') : ((isset($fields_permissions['fields_facebook']) && !$fields_permissions['fields_facebook']) ? ($utility->isNotEmpty($customer_information['main_facebook']) ? $utility->mask($customer_information['main_facebook'], 2, 1) : '') : $customer_information['main_facebook']); $customer_information['main_instagram'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_instagram']) ? $utility->mask($customer_information['main_instagram'], 2, 1) : '') : ((isset($fields_permissions['fields_instagram']) && !$fields_permissions['fields_instagram']) ? ($utility->isNotEmpty($customer_information['main_instagram']) ? $utility->mask($customer_information['main_instagram'], 2, 1) : '') : $customer_information['main_instagram']); $customer_information['main_whatsapp'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_whatsapp']) ? $utility->mask($customer_information['main_whatsapp'], 2, 1) : '') : ((isset($fields_permissions['fields_whatsapp']) && !$fields_permissions['fields_whatsapp']) ? ($utility->isNotEmpty($customer_information['main_whatsapp']) ? $utility->mask($customer_information['main_whatsapp'], 2, 1) : '') : $customer_information['main_whatsapp']); $customer_information['main_telegram'] = (!$fields_permissions) ? ($utility->isNotEmpty($customer_information['main_telegram']) ? $utility->mask($customer_information['main_telegram'], 2, 1) : '') : ((isset($fields_permissions['fields_telegram']) && !$fields_permissions['fields_telegram']) ? ($utility->isNotEmpty($customer_information['main_telegram']) ? $utility->mask($customer_information['main_telegram'], 2, 1) : '') : $customer_information['main_telegram']); // $customer_information['mod-dd-religion']= $religion->read_religion_name_by_id($customer_information['mod-dd-religion'],$db); // // if($utility->isNotEmpty($customer_information['information_dob'] )){ // $customer_information['information_dob'] = $utility->convert_sql_date_to_date_picker($customer_information['information_dob']); //$religion->read_religion_name_by_id($customer_information['mod-birthdate-unformat'],$db); // } // $customer_business = $customer->read_customer_ business($customer_id,$db); // $customer_contact = $customer->read_customer_contact($customer_id,$db); // $return_information = array_merge($customer_information); echo json_encode(array($customer_information)); // echo'<pre>';print_r($customer_information);echo'</pre>';exit; } else if ($apiKey === '6579442853321353' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_profile_interest($customer_id, $db); } else if ($apiKey === '3099751888433363' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_dms($customer_id, $granted_company_ids, $db); } else if ($apiKey === '4788616921820004' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_contact_person($customer_id, $db); } else if ($apiKey === '8307826786414874' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_children($customer_id, $db); } else if ($apiKey === '2089441825396664' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_education($customer_id, $db); } else if ($apiKey === '5660696728127200' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_affiliations($customer_id, $db); } else if ($apiKey === '5474981987699557' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_unit_association($customer_id, $db); } else if ($apiKey === '2223348764004177' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_car_club($customer_id, $db); } else if ($apiKey === '9526394287040079' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_political_club($customer_id, $db); } else if ($apiKey === '7193296844816864' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_network_marketing($customer_id, $db); } else if ($apiKey === '4432527649394050' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_media_publication($customer_id, $db); } else if ($apiKey === '5103641855052276' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_sme_group($customer_id, $db); } else if ($apiKey === '1773522681941804' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_fraternities_sororities($customer_id, $db); } else if ($apiKey === '1803139298208721' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_facebook_group($customer_id, $db); } else if ($apiKey === '4010640559253012' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_celebrity_influencers($customer_id, $db); } else if ($apiKey === '9707323227112625' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_profile_dms($customer_id, $db); } else if ($apiKey === '4938305064275028' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_profile_company($customer_id, $db); } else if ($apiKey === '7340685518692652' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $customer->read_customer_profile_dealer($customer_id, $db); } else if ($apiKey === '9490540601210798') { //Update } else if ($apiKey === '7472626829226859' && $utility->isPostMethod($server_method)) { //Delete' $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; $vehicle_ids = $customer->read_customer_vehicle_ids($customer_id, $db); // $json_arr['sales_image'] = '<div class="col-12 text-center mt-3"><strong>No Sales Image</strong></div>'; $json_arr['sales_image'] = '<div class="col-12 text-center mt-3" id="grid-page-footer"> <div class="card-footer"> <nav aria-label="Contacts Page Navigation"> <ul class="pagination justify-content-center m-0" id="customer-owned-vehicle-paging">No Record</ul> </nav> </div> </div>'; if (count($vehicle_ids) < 1) { echo json_encode($json_arr); return; } $vehicle_ids_array = array(); foreach ($vehicle_ids as $vehicle_id) { $vehicle_ids_array[] = $vehicle_id['id']; } $vehicle_ids_list = implode(',', $vehicle_ids_array); $customer_images = $customer->read_customer_sales_image_by_vehicle_ids($granted_company_ids, $vehicle_ids_list, $db); if (count($customer_images) < 1) { echo json_encode($json_arr); return; } $json_arr['sales_image'] = ""; foreach ($customer_images as $customer_image) { $json_arr['sales_image'] .= ' <div class="card col-md-4 col-sm-4 p-2"> <div class="thumbnail"> <a class="" href="dist/img/customer/' . $customer_image['name'] . '" data-toggle="lightbox" data-title="' . $customer_image['activity_date'] . '" data-gallery="gallery" data-footer=""> <img src="dist/img/customer/' . $customer_image['name'] . '" class=" img-fluid" alt="" style="height:250px; width:100%;" /> </a> </div> </div> '; } echo json_encode($json_arr); // echo $vehicle_list; } else if ($apiKey === '3975247589935894') { $search = isset($_REQUEST['search']) ? $db->escape($_REQUEST['search']) : ''; $customer->read_customer_corporation($search, $granted_company_ids, $db); } else if ($apiKey === '6817899882858207') { $search = isset($_REQUEST['search']) ? $db->escape($_REQUEST['search']) : ''; $customer->read_customer_names_and_id($granted_company_ids, $search, $db); } else if ($apiKey === '8666264351338448' && $utility->isPostMethod($server_method)) { //customer count $json_arr = array(); $type = (isset($_POST['type']) && $_POST['type'] != '0') ? " AND ci.type = '" . $_POST['type'] . "' " : ""; $gender = (isset($_POST['gender']) && $_POST['gender'] != 'all') ? " AND ci.gender_id = '" . $_POST['gender'] . "' " : ""; $dms = (isset($_POST['dms']) && $_POST['dms'] != '0') ? " AND sc.dms_id = '" . $_POST['dms'] . "' " : ""; $company = (isset($_POST['company']) && $_POST['company'] != '0') ? " AND scd.company_id = '" . $_POST['company'] . "' " : ""; $my_records = (isset($_POST['my_records']) && filter_var($_POST['my_records'], FILTER_VALIDATE_BOOLEAN)) ? " AND (ci.upload_by='$my_customer_record_id' OR ci.modified_by='$my_customer_record_id') " : ""; $age = ""; $where_age = " TIMESTAMPDIFF(YEAR,ci.date_of_birth, CURDATE() ) "; if (isset($_POST['filter_age']) && $_POST['filter_age'] != '0') { switch ($_POST['filter_age']) { case "below": $age = "AND $where_age <= 30 "; break; case "between": $age = "AND $where_age <= 50 AND $where_age >= 31 "; break; case "above": $age = "AND $where_age >= 51 "; break; } } $complete_data = ""; $incomplete_data = ""; $mobile_phone_1 = ""; $email_1 = ""; $address_1 = ""; $date_of_birth = ""; if (isset($_POST['filter_data']) && $_POST['filter_data'] != '0') { switch ($_POST['filter_data']) { case "Complete Data": $complete_data = " AND ((ci.date_of_birth <> '' and ci.gender_id <> 0 and cc.address_1 <> '' and cc.email_1 <> '' and cc.mobile_phone_1 <> '') AND ci.type = 1) OR (cc.address_1 <> '' AND cc.email_1 <> '' AND ci.type = 2) "; break; case "Incomplete Data": $incomplete_data = " AND ((ci.date_of_birth = '' OR ci.gender_id = 0 OR cc.address_1 = '' OR cc.email_1 = '' ) AND ci.type = 1) OR (cc.address_1 = '' or cc.email_1 = '' AND ci.type = 2) "; break; case "No Mobile": $mobile_phone_1 = " AND cc.mobile_phone_1 = '' "; break; case "No Email": $email_1 = " AND cc.email_1 = '' "; break; case "No Address": $address_1 = " AND cc.address_1 = '' "; break; case "No Gender": $gender = " AND ci.gender_id = '0' AND ci.type = '1' "; break; case "No Date of birth": $date_of_birth = " AND ci.date_of_birth = '' AND ci.type = '1' "; break; } } $query = "SELECT SUM( ( SELECT count(1) FROM ( SELECT sc.dms_id FROM inactive_customer ci INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id INNER JOIN customer_contact cc ON ci.id = cc.customer_id INNER JOIN source_company sc ON scd.company_id = sc.id WHERE ci.status = 1 AND scd.company_id IN (" . $granted_company_ids . ") $type $gender $dms $company $age $complete_data $incomplete_data $mobile_phone_1 $email_1 $address_1 $date_of_birth $my_records GROUP BY ci.id ) as t2 WHERE t2.dms_id = source_dms.id ) ) as total_count, SUM( ( SELECT count(1) FROM ( SELECT sc.dms_id FROM inactive_customer ci INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id INNER JOIN source_company sc ON scd.company_id = sc.id INNER JOIN customer_contact cc ON ci.id = cc.customer_id WHERE ci.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 WEEK) AND ci.status = 1 AND scd.company_id IN (" . $granted_company_ids . ") $type $gender $dms $company $age $complete_data $incomplete_data $mobile_phone_1 $email_1 $address_1 $date_of_birth $my_records GROUP BY ci.id ) as t2 WHERE t2.dms_id = source_dms.id ) ) as new_customer_count, SUM( ( SELECT count(1) FROM ( SELECT sc.dms_id FROM inactive_customer ci INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id INNER JOIN source_company sc ON scd.company_id = sc.id INNER JOIN customer_contact cc ON ci.id = cc.customer_id WHERE ci.date_modified > DATE_SUB(NOW(), INTERVAL 1 WEEK) AND ci.status = 1 AND scd.company_id IN (" . $granted_company_ids . ") $type $gender $dms $company $age $complete_data $incomplete_data $mobile_phone_1 $email_1 $address_1 $date_of_birth $my_records GROUP BY ci.id ) as t2 WHERE t2.dms_id = source_dms.id ) ) as updated_customer_count, SUM( ( SELECT count(1) FROM ( SELECT sc.dms_id FROM inactive_customer ci INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id INNER JOIN source_company sc ON scd.company_id = sc.id INNER JOIN customer_contact cc ON ci.id = cc.customer_id WHERE ci.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 DAY) AND ci.status = 1 AND scd.company_id IN (" . $granted_company_ids . ") $type $gender $dms $company $age $complete_data $incomplete_data $mobile_phone_1 $email_1 $address_1 $date_of_birth $my_records GROUP BY ci.id ) as t2 WHERE t2.dms_id = source_dms.id ) ) as new_today_customer_count FROM `source_dms` WHERE status = 1"; // return $query; $counts = $db->sql_query($query); foreach ($counts as $count) { $json_arr['total_count'] = 999;//str_replace( ',', '', $count['total_count']);//number_format($count['total_count']); $json_arr['new_customer_count'] = number_format($count['new_customer_count']); $json_arr['updated_customer_count'] = number_format($count['updated_customer_count']); $json_arr['new_today_customer_count'] = number_format($count['new_today_customer_count']); } // $json_arr['new_customer_count'] = $db -> select("SELECT // SUM( // ( // SELECT count(1) FROM // ( // SELECT cd.dms_id FROM customer ci // INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id // INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id // WHERE ci.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 WEEK) AND ci.status = 1 AND scd.company_id IN (".$granted_company_ids.") GROUP BY ci.id // ) as t2 WHERE t2.dms_id = source_dms.id // ) // ) as total FROM `source_dms` WHERE status = 1"); // $json_arr['updated_customer_count'] = $db -> select("SELECT // SUM( // ( // SELECT count(1) FROM // ( // SELECT cd.dms_id FROM customer ci // INNER JOIN customer_dms cd ON ci.id = cd.customer_record_id // INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id // WHERE ci.date_modified > DATE_SUB(NOW(), INTERVAL 1 WEEK) AND ci.status = 1 AND scd.company_id IN (".$granted_company_ids.") GROUP BY ci.id // ) as t2 WHERE t2.dms_id = source_dms.id // ) // ) as total FROM `source_dms` WHERE status = 1"); echo json_encode($json_arr); } else if ($apiKey === '3394212010636793' && $utility->isPostMethod($server_method)) { //Read Customer Interest $start_date = isset($_REQUEST['startDate']) ? $db->escape($_REQUEST['startDate']) : ''; $end_date = isset($_REQUEST['endDate']) ? $db->escape($_REQUEST['endDate']) : ''; $company = isset($_REQUEST['company']) ? $db->escape($_REQUEST['company']) : '0'; $return_arr["total"] = $customer->read_customer_total_number($start_date, $end_date, $company, $granted_company_ids, $db); echo json_encode($return_arr); } else if ($apiKey === '5441890951433809' && $utility->isPostMethod($server_method)) { //Read Customer Interest $start_date = isset($_REQUEST['startDate']) ? $db->escape($_REQUEST['startDate']) : ''; $end_date = isset($_REQUEST['endDate']) ? $db->escape($_REQUEST['endDate']) : ''; $company = isset($_REQUEST['company']) ? $db->escape($_REQUEST['company']) : '0'; $vehicle_total = isset($_REQUEST['vehicle_total']) ? intval($_REQUEST['vehicle_total']) : 0; $customer->read_customer_summary_count($start_date, $end_date, $company, $granted_company_ids, $vehicle_total, $db); } else if ($apiKey === '8525944844346448' && $utility->isPostMethod($server_method)) { //Read Customer Interest $start_date = isset($_REQUEST['startDate']) ? $db->escape($_REQUEST['startDate']) : ''; $end_date = isset($_REQUEST['endDate']) ? $db->escape($_REQUEST['endDate']) : ''; $company = isset($_REQUEST['company']) ? $db->escape($_REQUEST['company']) : '0'; $customer->read_customer_counts($start_date, $end_date, $company, $granted_company_ids, $db); } else if ($apiKey === '3695340036334748' && $utility->isPostMethod($server_method)) { //Read Customer Interest $customer_id = isset($_REQUEST['customer_id']) ? $db->escape($_REQUEST['customer_id']) : '-1'; $affected_rows = $customer->delete($customer_id, $db); $json_arr = array(); if (intval($affected_rows) !== 0) { $json_arr['status'] = 1; $json_arr['message'] = 'Customer successfully removed.'; } else { $json_arr['status'] = 0; $json_arr['message'] = 'Customer not removed, please try again.'; } echo json_encode($json_arr); } else { $return_arr["message"] = " You are not allowed to do this action."; echo $return_arr["message"]; return; } } else { $return_arr["message"] = " You are not allowed to do this action."; echo $return_arr["message"]; return; }
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings