public/wordpress/wp-content/plugins/front-end-only-users/Functions/Prepare_Data_For_Insertion.php
/* Prepare the data to add multiple users from a spreadsheet */
Prepare the data to add multiple users from a spreadsheet
Prepare the data to add multiple users from a spreadsheet
function Add_Users_From_Spreadsheet() {
	if (!is_user_logged_in()) {exit();}
	if (!empty($_FILES['Users_Spreadsheet']['error']))
	{
		switch($_FILES['Users_Spreadsheet']['error'])	{
			case '1':
				$error = __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'front-end-only-users');
				break;
			case '2':
				$error = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'front-end-only-users');
				break;
			case '3':
				$error = __('The uploaded file was only partially uploaded', 'front-end-only-users');
				break;
			case '4':
				$error = __('No file was uploaded.', 'front-end-only-users');
				break;
			case '6':
				$error = __('Missing a temporary folder', 'front-end-only-users');
				break;
			case '7':
				$error = __('Failed to write file to disk', 'front-end-only-users');
				break;
			case '8':
				$error = __('File upload stopped by extension', 'front-end-only-users');
				break;
			case '999':
				default:
				$error = __('No error code avaiable', 'front-end-only-users');
			}
	}
		elseif (empty($_FILES['Users_Spreadsheet']['tmp_name']) || $_FILES['Users_Spreadsheet']['tmp_name'] == 'none') {
				$error = __('No file was uploaded here..', 'front-end-only-users');
		}
		if(!preg_match("/\.(xls.?)$/", $_FILES['Users_Spreadsheet']['name']) and !preg_match("/\.(csv.?)$/", $_FILES['Users_Spreadsheet']['name'])) {
			$error = __('File must be .csv, .xls or .xlsx', 'front-end-only-users');
		}
		else {				 
				 	  $msg .= $_FILES['Users_Spreadsheet']['name'];
						$target_path = ABSPATH . 'wp-content/plugins/front-end-only-users/user-sheets/';
						$target_path = $target_path . basename( $_FILES['Users_Spreadsheet']['name']); 
						if (!move_uploaded_file($_FILES['Users_Spreadsheet']['tmp_name'], $target_path)) {
				 			  $error .= "There was an error uploading the file, please try again!";
						}
						else {
				 				$Excel_File_Name = basename( $_FILES['Users_Spreadsheet']['name']);
						}	
		}
		if (!isset($error)) {
				$user_update = Add_FEUP_Users_From_Spreadsheet($Excel_File_Name);
				return $user_update;
		}
		else {
				$output_error = array("Message_Type" => "Error", "Message" => $error);
				return $output_error;
		}
}
function Add_Users_From_Spreadsheet ( ) { if ( ! is_user_logged_in ( ) ) { exit ( ) ; } if ( ! empty ( $ _FILES [ 'Users_Spreadsheet' ] [ 'error' ] ) ) { switch ( $ _FILES [ 'Users_Spreadsheet' ] [ 'error' ] ) { case '1' : $ error = __ ( 'The uploaded file exceeds the upload_max_filesize directive in php.ini' , 'front-end-only-users' ) ; break ; case '2' : $ error = __ ( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form' , 'front-end-only-users' ) ; break ; case '3' : $ error = __ ( 'The uploaded file was only partially uploaded' , 'front-end-only-users' ) ; break ; case '4' : $ error = __ ( 'No file was uploaded.' , 'front-end-only-users' ) ; break ; case '6' : $ error = __ ( 'Missing a temporary folder' , 'front-end-only-users' ) ; break ; case '7' : $ error = __ ( 'Failed to write file to disk' , 'front-end-only-users' ) ; break ; case '8' : $ error = __ ( 'File upload stopped by extension' , 'front-end-only-users' ) ; break ; case '999' : default : $ error = __ ( 'No error code avaiable' , 'front-end-only-users' ) ; } } elseif ( empty ( $ _FILES [ 'Users_Spreadsheet' ] [ 'tmp_name' ] ) || $ _FILES [ 'Users_Spreadsheet' ] [ 'tmp_name' ] == 'none' ) { $ error = __ ( 'No file was uploaded here..' , 'front-end-only-users' ) ; } if ( ! preg_match ( " /\.(xls.?)$/ " , $ _FILES [ 'Users_Spreadsheet' ] [ 'name' ] ) and ! preg_match ( " /\.(csv.?)$/ " , $ _FILES [ 'Users_Spreadsheet' ] [ 'name' ] ) ) { $ error = __ ( 'File must be .csv, .xls or .xlsx' , 'front-end-only-users' ) ; } else { $ msg .= $ _FILES [ 'Users_Spreadsheet' ] [ 'name' ] ; $ target_path = ABSPATH . 'wp-content/plugins/front-end-only-users/user-sheets/' ; $ target_path = $ target_path . basename ( $ _FILES [ 'Users_Spreadsheet' ] [ 'name' ] ) ; if ( ! move_uploaded_file ( $ _FILES [ 'Users_Spreadsheet' ] [ 'tmp_name' ] , $ target_path ) ) { $ error .= " There was an error uploading the file, please try again! " ; } else { $ Excel_File_Name = basename ( $ _FILES [ 'Users_Spreadsheet' ] [ 'name' ] ) ; } } if ( ! isset ( $ error ) ) { $ user_update = Add_FEUP_Users_From_Spreadsheet ( $ Excel_File_Name ) ; return $ user_update ; } else { $ output_error = array ( " Message_Type " => " Error " , " Message " => $ error ) ; return $ output_error ; } }
Prepare the data to add multiple users from a spreadsheet
Prepare the data to add multiple users from a spreadsheet
/* Test if there is an error with the uploaded spreadsheet and return that error if there is */ /* Make sure that the file exists */ /* Check that it is a .xls or .xlsx file */ /* Move the file and store the URL to pass it onwards*/ //for security reason, we force to remove all uploaded file //if (!$upload = wp_upload_bits($_FILES["Item_Image"]["name"], null, file_get_contents($_FILES["Item_Image"]["tmp_name"]))) { /* Pass the data to the appropriate function in Update_Admin_Databases.php to create the users */