<commit_before><?php

class Admin extends CI_Controller {
  public function __construct() {
      parent::__construct();
      $this->load->model('user_model');
      $this->load->helper('upload_helper');
  }

  public function view_users() {
    if (!(isset($this->session->logged_in) && $this->session->user_type > 0)) {
        show_404();
        exit;
    }
    $data['from'] = isset($_REQUEST["from"]) ? $_REQUEST["from"] : 0;
    $data['amount'] = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : 20;
    $data['users'] = $this->user_model->get_users($data['from'], $data['amount'] + 1);
    if (count($data['users']) == $data['amount']+1) {
      $data['is_more'] = TRUE;
      array_pop($data['users']);
    } else {
      $data['is_more'] = FALSE;
    }

    $data['username'] = $this->session->username;

    $this->load->view('pages/users', $data);
  }

  public function view_usersJSON() {
    if (!(isset($this->session->logged_in) && $this->session->user_type > 0)) {
        show_404();
        exit;
    }
    $from = isset($_REQUEST["from"]) ? $_REQUEST["from"] : 0;
    $amount = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : 20;
    $users = $this->user_model->get_users($from, $amount);

    echo json_encode($users);
  }

  public function delete_user() {
    $id = $_REQUEST['userid'];
    if (!isset($id) && !(isset($this->session->logged_in) && $this->session->user_type > 0)) {
      show_404();
      exit;
    }
    $user = $this->user_model->retrieve_id($id);
    if ($user->ProfileImg_Id !== 'noprofileimg.jpg') {
      delete_image(substr($user->ProfileImg_Id, 0, -4));
    }
    $memes = $this->user_model->get_memes($id);
    if (count($memes) > 0) {
      foreach ($memes as $meme) {
        if ($meme->Data_Type === 'P') {
          delete_image(substr($meme->Data, 0, -4));
        }
      }
    }

    //if (isset($user->FB_Id)) {
    // //TODO
    //}
    $this->user_model->delete($id);
    redirect(site_url('admin/view_users'));
  }
}<commit_msg>users can be deleted by username<commit_after><?php

class Admin extends CI_Controller {
  public function __construct() {
      parent::__construct();
      $this->load->model('user_model');
      $this->load->helper('upload_helper');
  }

  public function view_users() {
    if (!(isset($this->session->logged_in) && $this->session->user_type > 0)) {
        show_404();
        exit;
    }
    $data['from'] = isset($_REQUEST["from"]) ? $_REQUEST["from"] : 0;
    $data['amount'] = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : 20;
    $data['users'] = $this->user_model->get_users($data['from'], $data['amount'] + 1);
    if (count($data['users']) == $data['amount']+1) {
      $data['is_more'] = TRUE;
      array_pop($data['users']);
    } else {
      $data['is_more'] = FALSE;
    }

    $data['username'] = $this->session->username;

    $this->load->view('pages/users', $data);
  }

  public function view_usersJSON() {
    if (!(isset($this->session->logged_in) && $this->session->user_type > 0)) {
        show_404();
        exit;
    }
    $from = isset($_REQUEST["from"]) ? $_REQUEST["from"] : 0;
    $amount = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : 20;
    $users = $this->user_model->get_users($from, $amount);

    echo json_encode($users);
  }

  public function delete_user() {
    $id = $_REQUEST['userid'];
    $username = $_REQUEST['username'];
    if (!(isset($id) || isset($username)) && !(isset($this->session->logged_in) && $this->session->user_type > 0)) {
      show_404();
      exit;
    }
    if (isset($id)) {
      $user = $this->user_model->retrieve_id($id);
    } else {
      $user = $this->user_model->retrieve($username);
    }
    if (!isset($user)) {
      show_404();
    }
    if ($user->ProfileImg_Id !== 'noprofileimg.jpg') {
      delete_image(substr($user->ProfileImg_Id, 0, -4));
    }
    $memes = $this->user_model->get_memes($user->Id);
    if (count($memes) > 0) {
      foreach ($memes as $meme) {
        if ($meme->Data_Type === 'P') {
          delete_image(substr($meme->Data, 0, -4));
        }
      }
    }

    //if (isset($user->FB_Id)) {
    // //TODO
    //}
    $this->user_model->delete($id);
    redirect(site_url('admin/view_users'));
  }
}
{'fraction_non_alphanumeric': 0.22180094786729856, 'fraction_numerical': 0.012559241706161137, 'mean_word_length': 3.0703953712632592, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '6417470', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1448, 'n_words': 230}