<commit_before><?php

/**
 * Is this the users first time in using XOT
 * @author <NAME>
 * @version 1.0
 * @params string user's username
 * @return bool - Is this the users first time (have we ever come across this user before in XOT)
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function check_if_first_time($username){
    global $xerte_toolkits_site;
    $query = "select login_id from {$xerte_toolkits_site->database_table_prefix}logindetails where username = ? ";
    $response = db_query_one($query, array($username));

	if(empty($response)) {
		return true;
	}
    return false;
}

/**
 *
 * Function get user id
 * get the user's database ID
 * @author <NAME>
 * @version 1.0
 * @return number - The user's database id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function get_user_info(){

  global $xerte_toolkits_site;

  $row = db_query_one("SELECT firstname,surname,login_id,username,lastlogin FROM {$xerte_toolkits_site->database_table_prefix}logindetails WHERE username = ?", array($_SESSION['toolkits_logon_username']));

  if(!empty($row)) {
    return (array($row['firstname'],$row['surname'],$row['username'],$row['login_id'],$row['lastlogin']));
  }else{
    receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to get users Details", "Failed to get users Details");
  }

}


/**
 * 
 * Function get user id
 * get the user's database ID
 * @author <NAME>
 * @version 1.0
 * @return number - The user's database id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function get_user_id(){

    global $xerte_toolkits_site;

    $row = db_query_one("SELECT login_id FROM {$xerte_toolkits_site->database_table_prefix}logindetails WHERE username = ?", array($_SESSION['toolkits_logon_username']));

    if(!empty($row)) { 
        return $row['login_id'];	
    }else{
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to get users ID", "Failed to get users ID");
    }

}

/**
 * 
 * Function create user id
 * If a new user, create an ID
 * @author <NAME>
 * @version 1.0
 * @return number - the user id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */

function create_user_id($username, $firstname, $surname){

    global $xerte_toolkits_site;

    $query = "insert into {$xerte_toolkits_site->database_table_prefix}logindetails (username, lastlogin, firstname, surname) values (?,?,?,?)";
    $res = db_query($query, array($username, date('Y-m-d'), $firstname, $surname));

    if($res){
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Succeeded in creating users ID", "Succeeded in creating users ID");
        return get_user_id();

    }else{

        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create users ID", "Failed to create users ID");

    }
    return false;
}

/**
 * 
 * Function recycle bin
 * looks for a reycle bin and if can't find one, make it.
 * @author <NAME>
 * @version 1.0
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */

function recycle_bin() {

    global $xerte_toolkits_site;

    $query = "select folder_name from {$xerte_toolkits_site->database_table_prefix}folderdetails where <commit_msg>provide null for the first column (login_id) which is an autoincrement field - given we are not naming columns (website_code/php/user_library.php)<commit_after><?php

/**
 * Is this the users first time in using XOT
 * @author <NAME>
 * @version 1.0
 * @params string user's username
 * @return bool - Is this the users first time (have we ever come across this user before in XOT)
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function check_if_first_time($username){
    global $xerte_toolkits_site;
    $query = "select login_id from {$xerte_toolkits_site->database_table_prefix}logindetails where username = ? ";
    $response = db_query_one($query, array($username));

	if(empty($response)) {
		return true;
	}
    return false;
}

/**
 *
 * Function get user id
 * get the user's database ID
 * @author <NAME>
 * @version 1.0
 * @return number - The user's database id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function get_user_info(){

  global $xerte_toolkits_site;

  $row = db_query_one("SELECT firstname,surname,login_id,username,lastlogin FROM {$xerte_toolkits_site->database_table_prefix}logindetails WHERE username = ?", array($_SESSION['toolkits_logon_username']));

  if(!empty($row)) {
    return (array($row['firstname'],$row['surname'],$row['username'],$row['login_id'],$row['lastlogin']));
  }else{
    receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to get users Details", "Failed to get users Details");
  }

}


/**
 * 
 * Function get user id
 * get the user's database ID
 * @author <NAME>
 * @version 1.0
 * @return number - The user's database id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */
function get_user_id(){

    global $xerte_toolkits_site;

    $row = db_query_one("SELECT login_id FROM {$xerte_toolkits_site->database_table_prefix}logindetails WHERE username = ?", array($_SESSION['toolkits_logon_username']));

    if(!empty($row)) { 
        return $row['login_id'];	
    }else{
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to get users ID", "Failed to get users ID");
    }

}

/**
 * 
 * Function create user id
 * If a new user, create an ID
 * @author <NAME>
 * @version 1.0
 * @return number - the user id
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */

function create_user_id($username, $firstname, $surname){

    global $xerte_toolkits_site;

    $query = "insert into {$xerte_toolkits_site->database_table_prefix}logindetails (username, lastlogin, firstname, surname) values (?,?,?,?)";
    $res = db_query($query, array(null, $username, date('Y-m-d'), $firstname, $surname));

    if($res){
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Succeeded in creating users ID", "Succeeded in creating users ID");
        return $res;

    }else{

        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create users ID", "Failed to create users ID");

    }
    return false;
}

/**
 * 
 * Function recycle bin
 * looks for a reycle bin and if can't find one, make it.
 * @author <NAME>
 * @version 1.0
 * @copyright Copyright (c) 2008,2009 University of Nottingham
 * @package
 */

function recycle_bin() {

    global $xerte_toolkits_site;

    $query = "select folder_name from {$xerte_toolkits_site->database_table_prefix}folderdetails where 
{'fraction_non_alphanumeric': 0.13458162668227033, 'fraction_numerical': 0.014628437682855471, 'mean_word_length': 4.527081649151172, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7639435', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2165, 'n_words': 605}