<?php
/**
 * functions.inc.php -- Functions
 */

// File Name Randomizer
function randDoc( $fileName ){
    $fileName = $fileName;
    $tmp = explode('.', $fileName);
    $fileExtension = end($tmp);
    $uploadable_file = md5(uniqid(rand(), true)) . '.' . $fileExtension;

    return $uploadable_file; // Random generated File Name
}



// Input Null Checker
function nullCheck( $input ){
    if ( $input == NULL OR $input == 'null' ){
        $updateInput = '';
    } else {
        $updateInput = $input;
    }
    return $updateInput;
}



// Code Generator
function codeGen($fullname, $username, $email){
//function codeGen(){
    // Generate 24 Characters
    /*$seed = str_split('AaBb'.$fullname.'CcDd'.$username.'EeFf'.$email.'GgHh'); // characters
    $rand = '';
    foreach (array_rand($seed, 24) as $k) $rand .= $seed[$k];
 
    return $rand;*/

    $num = "1234567890"; // Numbers
	$alphaS = "abcdefghjkmnopqrstuvwxyz"; // Alphabets = Small Letters
	$alphaC = "ABCDEFGHJKLMNOPQRSTUVWXYZ"; // Alphabets = Capital Letters
	//$chars = "!@#$%^&*()_-+=<,>.?/:;{[}]"; // General Characters
	$rand = ''; // Initialize the generated password variable
	
	//$randValues = str_split($alphaS . $alphaC . $num . $chars); // Split all the concatenated characters
	$randValues = str_split($alphaS . $alphaC . $num . $fullname . $username . $email); // Split all the concatenated characters
	shuffle($randValues); // Shuffle the characters in $randValues

	for ( $i=0; $i < 24; $i++ ){
		$rand .= $randValues[rand() % 24]; // generate random alphanumeric characters
	}
	return $rand; // Send the generated alphanumeric characters
}
