<commit_before><?php
/**
 * Name:       <NAME>
 * Programmer: <NAME>
 * Date:       7/2/13
 */

//Make sure the session has started
if(!(isset($_SESSION))){
    session_start();
}

//includes
require_once('../../path.php');
require_once(ABSPATH.'includes/data.php');
require_once(ABSPATH.'includes/config/settings.php');
require_once(ABSPATH.'includes/config/users.php');
require_once(ABSPATH.'admin/generate_reset_codes.php');

//Fetch values to populate fields
$set = new settings;
$settings = $set->fetch();

//Setup the user abstraction layer
$users = new users;

//Flags
$found = true;

//make sure the user is logged in and is admin
if(isset($_SESSION['userid'])){

    if($_SESSION['admin'] >= 1){

        //User is logged in

        echo '<pre>';

        //Reset a user's password
        if(isset($_REQUEST['reset'])){
            $reset_code = insert_reset_code($_REQUEST['userid']);
            $users->select($_REQUEST['userid']);
            //Corrupt the user's password
            //(this forces them to use the rest code and stops anyone else from using their password until they do)
            $users->change('password', '<PASSWORD>');
            $users->update();
            echo 'Attemped password reset'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users&c='.$reset_code);
        }

        //Delete a user
        if(isset($_REQUEST['delete'])){
            $users->change('index', $_REQUEST['u']);
            $users->delete();
            echo 'Attempted delete'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users');
        }

        //add a user
        if(isset($_REQUEST['add'])){

            $users->change('index', null);
            $users->change('firstname', $_REQUEST['firstname']);
            $users->change('lastname', $_REQUEST['lastname']);
            $users->change('email', $_REQUEST['email']);
            $users->change('phone_number', $_REQUEST['phone_number']);
            $users->change('password', $_REQUEST['password']);
            $users->change('type', $_REQUEST['type']);

            //Prevent administrators from escalating permissions
            if($_REQUEST['admin'] > $_SESSION['admin']){
                $users->change('admin', $_REQUEST['admin']);
            }else{
                $users->change('admin', $_SESSION['admin']);
            }


            $users->create();
            echo 'Attempted add'."\r\n";

            $_SESSION['success'] = true;

            //Redirect the user
            header('Location: ../../?p=admin&a=users');
        }

        //update user
        if(isset($_REQUEST['update'])){
            $users->select($_REQUEST['userid']);
            $users->change('index', $_REQUEST['userid']);

            $users->change('firstname', $_REQUEST['firstname']);
            $users->change('lastname', $_REQUEST['lastname']);
            $users->change('email', $_REQUEST['email']);
            $users->change('phone_number', $_REQUEST['phone_number']);
            $users->change('password', $users->password);
            $users->change('type', $_REQUEST['type']);

            //Make sure the user is not editing themselves
            if(!($_SESSION['userid'] == $_SESSION['user_lookup'])){
                
                //Prevent administrators from escalating permissions
                if($_REQUEST['admin'] > $_SESSION['admin']){
                    $users->change('admin', $_REQUEST['admin']);
                }else{
                    $users->change('admin', $_SESSION['admin']);
                }

            }

            $users->update();
            echo 'Attempted update'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users');

        }

        //For user locking<commit_msg>Fixed bug in user_save.php.<commit_after><?php
/**
 * Name:       User Save
 * Programmer: <NAME>
 * Date:       7/2/13
 */

//Make sure the session has started
if(!(isset($_SESSION))){
    session_start();
}

//includes
require_once('../../path.php');
require_once(ABSPATH.'includes/data.php');
require_once(ABSPATH.'includes/config/settings.php');
require_once(ABSPATH.'includes/config/users.php');
require_once(ABSPATH.'admin/generate_reset_codes.php');

//Fetch values to populate fields
$set = new settings;
$settings = $set->fetch();

//Setup the user abstraction layer
$users = new users;

//Flags
$found = true;

//make sure the user is logged in and is admin
if(isset($_SESSION['userid'])){

    if($_SESSION['admin'] >= 1){

        //User is logged in

        echo '<pre>';

        //Reset a user's password
        if(isset($_REQUEST['reset'])){
            $reset_code = insert_reset_code($_REQUEST['userid']);
            $users->select($_REQUEST['userid']);
            //Corrupt the user's password
            //(this forces them to use the rest code and stops anyone else from using their password until they do)
            $users->change('password', '<PASSWORD>');
            $users->update();
            echo 'Attemped password reset'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users&c='.$reset_code);
        }

        //Delete a user
        if(isset($_REQUEST['delete'])){
            $users->change('index', $_REQUEST['u']);
            $users->delete();
            echo 'Attempted delete'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users');
        }

        //add a user
        if(isset($_REQUEST['add'])){

            $users->change('index', null);
            $users->change('firstname', $_REQUEST['firstname']);
            $users->change('lastname', $_REQUEST['lastname']);
            $users->change('email', $_REQUEST['email']);
            $users->change('phone_number', $_REQUEST['phone_number']);
            $users->change('password', $_REQUEST['password']);
            $users->change('type', $_REQUEST['type']);

            //Prevent administrators from escalating permissions
            if(!($_REQUEST['admin'] > $_SESSION['admin'])){
                $users->change('admin', $_REQUEST['admin']);
            }else{
                $users->change('admin', $_SESSION['admin']);
            }


            $users->create();
            echo 'Attempted add'."\r\n";

            $_SESSION['success'] = true;

            //Redirect the user
            header('Location: ../../?p=admin&a=users');
        }

        //update user
        if(isset($_REQUEST['update'])){
            $users->select($_REQUEST['userid']);
            $users->change('index', $_REQUEST['userid']);

            $users->change('firstname', $_REQUEST['firstname']);
            $users->change('lastname', $_REQUEST['lastname']);
            $users->change('email', $_REQUEST['email']);
            $users->change('phone_number', $_REQUEST['phone_number']);
            $users->change('password', $users->password);
            $users->change('type', $_REQUEST['type']);

            //Make sure the user is not editing themselves
            if(!($_SESSION['userid'] == $_SESSION['user_lookup'])){

                //Prevent administrators from escalating permissions
                if(!($_REQUEST['admin'] > $_SESSION['admin'])){
                    $users->change('admin', $_REQUEST['admin']);
                }else{
                    $users->change('admin', $_SESSION['admin']);
                }

            }

            $users->update();
            echo 'Attempted update'."\r\n";

            //Redirect the user
            header('Location: ../../?p=admin&a=users');

        }

        //For user locking
{'fraction_non_alphanumeric': 0.18374004958893383, 'fraction_numerical': 0.0013049719431032234, 'mean_word_length': 2.1243375458622094, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 72, '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': '1519308', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1984, 'n_words': 427}