<?
/*
include getenv("DOCUMENT_ROOT")."/include/session_include.php";


// Level 1 이하만 사용 가능
$func->checkLevelModal(1);






// ################# 차후 uptype 에 따른 if 구분이 필요함
// echo "[action=$action]";
// log file upload
if ($mode == "insert") {
	
	$uploaddir = getenv("DOCUMENT_ROOT").'/upload/'; 	
	$upfilename = "userdata_i.csv";
	
	$existFlag = file_exists($uploaddir.$upfilename);
	
	if (!file_exists($uploaddir.$upfilename)) {
		echo "The file $uploaddir.$upfilename does not exist";
	}

	//$rt = chmod ($uploaddir.$upfilename, 0755);
	
	$lineCnt = 0;
	$successRowCnt = 0;

	echo " ##############################################################<br>";

		
	if (($handle = fopen($uploaddir.$upfilename, "r")) !== FALSE) {
	    while (($getCSV = fgetcsv($handle, 1000, ",")) !== FALSE) {
	        //$num = count($getCSV);
	        //echo "<p> $num fields in line $row: <br /></p>\n";
	        //$row++;
	        //for ($c=0; $c < $num; $c++) {

						//echo $getCSV[$i]['c']."<br>";
						
						$runFlag = 1;
		
				
						$lineCnt++;
						//$runFlag = 0; 
						
						// $runFlag != 0 인 경우에만 DB에 저장
						if ($runFlag != 0)	{

										$columns = array();
										$values = array();
										
										$columns[] = "c_accountno";
										$columns[] = "c_createddate";
										$columns[] = "c_form_us";
										$columns[] = "c_form_eu";
										$columns[] = "c_form_new";
										//$columns[] = "c_driveruid";
										$columns[] = "c_name";
										$columns[] = "c_paymenttype";
										$columns[] = "c_payableto";
										
										$columns[] = "c_mailingaddr";
										$columns[] = "c_rate";
										$columns[] = "c_maincontainer";
										$columns[] = "c_container";
										$columns[] = "c_location";
										$columns[] = "c_phone";
										$columns[] = "c_cell";
										$columns[] = "c_email";
										$columns[] = "c_address";
										$columns[] = "c_city";
										$columns[] = "c_postal";
										$columns[] = "c_province";
										$columns[] = "c_contractdate";
										$columns[] = "c_contractby";
										$columns[] = "c_installdate";
										$columns[] = "c_schedule";
										$columns[] = "c_scheduleday";
										//$columns[] = "c_schedulebasic";
										$columns[] = "c_fpickup";
										$columns[] = "c_salesperson";
										$columns[] = "c_salescommissiondate";
										$columns[] = "c_salesmethod";
										$columns[] = "c_removaldate";
										$columns[] = "c_status";

										$columns[] = "c_comment_ri";
										$columns[] = "c_comment_ci";
										//$columns[] = "c_fullcycle";



										////////////	
										// data
										////////////	

										$values[] = trim ($getCSV[14]);  // $c_accountno
										
										$values[] = "20230301000000";

										if (trim ($getCSV[1]) == "Yes") $c_form_us = "Y";
										else $c_form_us = "N";
										$values[] = $c_form_us;
										
										if (trim ($getCSV[2]) == "Not Yet" || trim ($getCSV[2]) == "") $c_form_eu = "";
										else $c_form_eu = str_replace("-", "", trim ($getCSV[2]));
										$values[] = $c_form_eu;

										$values[] = trim ($getCSV[3]);  // $c_form_new;

										// Get Driver Info
										$qry_driver = "SELECT m_uid FROM tbl_member WHERE m_initial = '".trim($getCSV[11])."' ";
										$rt_driver = $jdb->fQuery($qry_driver, "query error");
//echo "[$qry_driver]<br>";
										//$values[] = $rt_driver['m_uid'];  // $c_driveruid
										
										$values[] = str_replace("\\", "", trim($getCSV[12]));  // $c_name
										
										$values[] = strtoupper(trim ($getCSV[4]));  // $c_paymenttype
										$values[] = str_replace("\\", "", trim($getCSV[5])); // $c_payableto
										
										$values[] = str_replace("\\", "", trim($getCSV[6])); // $c_mailingaddr
										
										if (strtoupper(trim ($getCSV[8])) == "FREE") $values[] = 0; // $c_rate;
										else $values[] = trim($getCSV[8]); // $c_rate;
										
										$values[] = str_replace("\\", "", trim($getCSV[9])); // $c_maincontainer
										$values[] = str_replace("\\", "", trim($getCSV[10]));  // $c_container
										$values[] = str_replace("\\", "", trim($getCSV[22]));  // $c_location
										$values[] = str_replace(" ", "", trim($getCSV[19]));  // $c_phone

										$values[] = str_replace("\\", "", trim($getCSV[20]));  // $c_cell
										$values[] = str_replace("\\", "", trim($getCSV[21]));  // $c_email
										$values[] = str_replace("\\", "", trim($getCSV[15]));  // $c_address
										$values[] = str_replace("\\", "", trim($getCSV[16]));  // $c_city
										$values[] = str_replace(" ", "", trim($getCSV[18]));  // $c_postal

										$values[] = "ON";
										$values[] = str_replace("-", "", trim($getCSV[23]));  // $c_contractdate
										$values[] = str_replace("\\", "", trim($getCSV[24]));  // $c_contractby
										
										$c_installdate = str_replace("-", "", trim($getCSV[25]));
										if ($c_installdate == "N/A") $c_installdate = "";
										$values[] = $c_installdate;  // $c_installdate
										
										if (trim($getCSV[26]) == "") $c_schedule = "None";
										$values[] = $c_schedule; //$c_schedule

										
										$values[] = trim($getCSV[27]);  // $c_scheduleday_vals;
										//$values[] = $c_schedulebasic;
										$values[] = str_replace("-", "", trim($getCSV[28]));  // $c_fpickup
										$values[] = str_replace("\\", "", trim($getCSV[29]));  // $c_salesperson
										$values[] = str_replace("-", "", trim($getCSV[30]));  // $c_salescommissiondate
										$values[] = str_replace("\\", "", trim($getCSV[31]));  // $c_salesmethod
										$values[] = str_replace("-", "", trim($getCSV[32]));  // $c_removaldate
										$values[] = "I";  // $c_status
										$values[] = str_replace("\\", "", trim($getCSV[13])); // $c_comment_ri
										$values[] = str_replace("\\", "", trim($getCSV[7])); // $c_comment_ci
										//$values[] = $c_fullcycle;
										
if ($lineCnt >=3) {
						//echo "Line <b>$lineCnt</b><br>";
						for ($i=0; $i < count($columns); $i++)
						echo "[$columns[$i]][$values[$i]]<br>";
						//echo "[UID=$uid][ID=$userid][MAXUID=$maxuid]";
						//exit;	
			
						$rtvalue = $jdb->iQuery("tbl_customer", $columns, $values);
						//$msg = "Created successfully.";


						$query = "SELECT max(c_uid) FROM tbl_customer ";
						$rt=$jdb->fQuery($query, "fetch query error");


						if (trim($getCSV[33]) != "") {
												$ccolumns = array();
												$vvalues = array();
												
												$ccolumns[] = "n_type";
												$ccolumns[] = "n_customeruid";
												$ccolumns[] = "n_view";
												$ccolumns[] = "n_note";
												$ccolumns[] = "n_createddate";
												
												
												$vvalues[] = "A";
												$vvalues[] = $rt[0];
												$vvalues[] = 1;
												$vvalues[] = str_replace("\\", "", trim($getCSV[33]));
												$vvalues[] = "20230301000000";
												
												$rtvalue = $jdb->iQuery("tbl_note", $ccolumns, $vvalues);
												
												unset ($ccolumns);
												unset ($vvalues);												
						}

						if (trim($getCSV[34]) != "") {
												$ccolumns = array();
												$vvalues = array();
												
												$ccolumns[] = "n_type";
												$ccolumns[] = "n_customeruid";
												$ccolumns[] = "n_view";
												$ccolumns[] = "n_note";
												$ccolumns[] = "n_createddate";
												
												
												$vvalues[] = "A";
												$vvalues[] = $rt[0];
												$vvalues[] = 1;
												$vvalues[] = str_replace("\\", "", trim($getCSV[34]));
												$vvalues[] = "20230301000000";
												
												$rtvalue = $jdb->iQuery("tbl_note", $ccolumns, $vvalues);
												
												unset ($ccolumns);
												unset ($vvalues);															
						}
						
						if (trim($getCSV[35]) != "") {
												$ccolumns = array();
												$vvalues = array();
												
												$ccolumns[] = "n_type";
												$ccolumns[] = "n_customeruid";
												$ccolumns[] = "n_view";
												$ccolumns[] = "n_note";
												$ccolumns[] = "n_createddate";
												
												
												$vvalues[] = "A";
												$vvalues[] = $rt[0];
												$vvalues[] = 1;
												$vvalues[] = str_replace("\\", "", trim($getCSV[35]));
												$vvalues[] = "20230301000000";
												
												$rtvalue = $jdb->iQuery("tbl_note", $ccolumns, $vvalues);
												
												unset ($ccolumns);
												unset ($vvalues);															
						}						
								//echo "[$query_up]<br>";
								//$jdb->nQuery($query_up, "update error");					

echo " --------------------------------------------------------------<br>";	
								echo "Line <b>$lineCnt</b> [$rtvalue][".trim ($getCSV[14])."]<br>"; 
echo " --------------------------------------------------------------<br><br>";	
								$successRowCnt ++;
}								
								
								//if ($lineCnt == 100) break;
						}
					//}		// End of For

	    }
	    fclose($handle);
	}
	

	
	echo " ##############################################################<br>";
	echo " Total : $lineCnt, Success : $successRowCnt. Fail : ".($lineCnt-$successRowCnt)."<br>";
	echo " ##############################################################<br><br>";
	
}			// End of Modify Inventory status


		*/
?>
