File manager - Edit - /home/autoph/public_html/data03252025consolidation/api/controllers/import_reassign_nob.php
Back
<?php class Import { function getArrayFields($id, $db){ $field_array = ['MOBILE', 'EMAIL', 'CATEGORY']; $return_array = array(); $return_array = array_merge($return_array, array($field_array[$id-1])); // print_r($return_array); exit; return $return_array; } function getIssueSummaryField($str, $ColumnNumber, $array_data){ for($i = 0; $i < $ColumnNumber; $i++){ if(in_array($str, $array_data, true)){ return $i; } } return "-5"; } function getFieldFromExcel($row, $ColumnNumber, $array_data){ for($i = 0; $i < $ColumnNumber; $i++){ if(in_array(trim($row[$i]), $array_data, true)){ return $row[$i]; } } return ""; } function checkExist($row, $field, $utility){ if(!$utility->isNotEmpty($field)){ return ""; } $key = array_search($field, $GLOBALS['row_headers']); return isset($row[$key]) ? $row[$key] : '' ; } function in_array_r($needle, $haystack, $strict = false) { foreach ($haystack as $item) { if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && $this->in_array_r($needle, $item, $strict))) { return true; } } return false; } function alphaNumericOnly($s){ $str = preg_replace("/[^a-zA-Z0-9]+/", "", $s); if(strlen($str) < 5){ return ""; } return $str; } function check_string_exist($str){ $str = strtolower($str); $none = array("na", "n/a", "none"); if(in_array($str, $none)){ return true; } return false; } function start_import($row, $customer_class, $utility, $db){ $data_mobile = $this->checkExist($row, $GLOBALS['mobile'], $utility); $data_email = $this->checkExist($row, $GLOBALS['email'], $utility); $data_given_category = $this->checkExist($row, $GLOBALS['category'], $utility); $data_uploader = $_SESSION['user']['id']; // validate required data if((!$utility->isNotEmpty($data_mobile))){ // check mobile $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['no_mobile']), $row); $GLOBALS['no_mobile_count']++; $GLOBALS['not_updated_count']++; return 0; } if((!$utility->isNotEmpty($data_email))){ // check email $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['no_email']), $row); $GLOBALS['no_email_count']++; $GLOBALS['not_updated_count']++; return 0; } if(!$utility->isNotEmpty($data_given_category)){ // check category $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['no_category']), $row); $GLOBALS['no_category_count']++; $GLOBALS['not_updated_count']++; return 0; } // validate given category // echo "SELECT COUNT(1) FROM `source_nature_of_business` WHERE `name` = '$data_given_category' AND `is_parent` = 1"; exit; $data_category_count = $db->select("SELECT COUNT(1) FROM `source_nature_of_business` WHERE `name` = '$data_given_category' AND `is_parent` = 1"); $category_id = 0; $customer_id = array(); if(intval($data_category_count) == 0){ $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['unknown_category']), $row); $GLOBALS['unknown_category_count']++; $GLOBALS['not_updated_count']++; return 0; } else { $category_id = $db->select("SELECT `id` FROM `source_nature_of_business` WHERE `name` = '$data_given_category' AND `is_parent` = 1"); $check_customer = $db->select("SELECT COUNT(1) FROM `customer_contact` WHERE `mobile_phone_1` = '$data_mobile' AND `email_1` = '$data_email'"); if($check_customer == 0){ // echo "UPDATE `source_nature_of_business` SET `category_id` = '$category_id' WHERE `id` = '$data_nob_id'"; exit; $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['no_customer_existing']), $row); $GLOBALS['no_customer_count']++; $GLOBALS['not_updated_count']++; return 0; } else { $customer_id_list = $db->sql_query("SELECT `customer_id` FROM `customer_contact` WHERE `mobile_phone_1` = '$data_mobile' AND `email_1` = '$data_email'"); foreach($customer_id_list AS $data){ $row_id = $data['customer_id']; array_push($customer_id, $row_id); } // array_push($customer_id, $db->select("SELECT `customer_id` FROM `customer_contact` WHERE `mobile_phone_1` = '$data_mobile' AND `email_1` = '$data_email'")); } } //end validate given category // echo $category_id; exit; // print_r($customer_id); exit; //============================================================================================= check if already done/set ====> $already_done = checkIfAlreadyDone($customer_id, $category_id, $db); if($already_done == count($customer_id)){ $GLOBALS['not_inserted_list_v2'][] = array_merge(array($GLOBALS['done']), $row); $GLOBALS['done_count']++; $GLOBALS['not_updated_count']++; return 0; } else { $in_clause = implode("', '", $customer_id); $db->sql_query("UPDATE `customer` SET `nature_of_business_id` = '$category_id' WHERE `id` IN('".$in_clause."')"); $GLOBALS['updated_count']++; } // $db->sql_query("UPDATE `customer` SET `nature_of_business_id` = '$category_id' WHERE `id` = $customer_id"); } } function checkIfAlreadyDone($customer_id, $category_id, $db){ $counter = 0; for($i=0; $i<count($customer_id); $i++){ $cust_id = $customer_id[$i]; $check = $db->select("SELECT COUNT(1) FROM `customer` WHERE `id` = $cust_id AND `nature_of_business_id` = $category_id"); if($check > 0){ $counter++; } } return $counter; } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings