<commit_before><?php
if (!isset($website) ) { header('HTTP/1.1 404 Not Found'); die; }
$errors = "";
if ( isset($_GET["search_users"]) ) $s = safeEscape($_GET["search_users"]); else $s=""; 

?>
<div align="center" class="padBottom">
	 <form action="" method="get">
	 <table>
	   <tr>
	    <td width="290">
		  <input type="hidden" name="users" />
		  <input style="width: 180px; height: 24px;" type="text" name="search_users" value="<?=$s?>" />
		  <input class="menuButtons" type="submit" value="Search users" />
		</td>
	   </tr>
	 </table>
	 </form>
</div>
<?php
if ( isset($_GET["activate"]) AND is_numeric($_GET["activate"]) ) {
   $id = safeEscape( $_GET["activate"]);
   $update = $db->prepare("UPDATE ".OSDB_USERS." SET code = '' WHERE user_id = '".(int) $id."' LIMIT 1");
   $result = $update->execute();
   OS_AddLog($_SESSION["username"], "[os_users] Activated user ( #".(int)$id." )");
} 

//delete
  if ( isset( $_GET["del"]) AND is_numeric($_GET["del"]) AND OS_IsRoot() ) {
      $id = safeEscape( (int) $_GET["del"] );
	  $delete = $db->prepare("DELETE FROM ".OSDB_USERS." WHERE user_id ='".(int)$id."' LIMIT 1 ");
	  $result = $delete->execute();
	  $del2 = $db->query("DELETE FROM ".OSDB_COMMENTS." WHERE user_id ='".(int)$id."' ");
	  $result = $del2->execute();
	  OS_AddLog($_SESSION["username"], "[os_deleteuser] Deleted member ( #$id )");
	  ?>
	  <div align="center">
	  <h2>User successfully deleted. <a href="<?=OS_HOME?>adm/?users">&laquo; Back</a></h2>
	  </div>
	  <?php 
  }
//eDIT
  if ( (!OS_IsRoot() AND isset( $_GET["edit"]) AND is_numeric($_GET["edit"]) ) OR (isset($_GET["add"]) AND !OS_IsRoot() ) OR ( isset( $_GET["del"]) AND is_numeric($_GET["del"]) AND !OS_IsRoot() ) ) {
      ?>
	<div align="center" style="margin-bottom: 60px;">
	<h2>You don't have permission to access this page</h2>
	</div>
	<?php
  } else
  if ( (OS_IsRoot() AND isset( $_GET["edit"]) AND is_numeric($_GET["edit"]) ) OR isset($_GET["add"])  ) {
   $name = ""; $email = ""; $bnet = "";
   if ( isset($_GET["edit"])  AND is_numeric($_GET["edit"])  ) $id = safeEscape( (int) $_GET["edit"] ); else $id =0;
   //UPDATE
    if ( isset($_POST["edit_user"]) ) {
	  $name     = safeEscape( $_POST["name"]);
	  $bnet     = safeEscape( $_POST["bnet"]);
	  $email   = safeEscape( $_POST["email"]);
	  //if not root admin do not change access level
	  if ( $_SESSION["level"] <=9) {
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." WHERE user_id = '".$id."' ");
	  $result = $sth->execute();
	  $UserROW = $sth->fetch(PDO::FETCH_ASSOC);
	  $level = $UserROW["user_level"]; 
	  
	    if ( isset($_POST["level"]) AND $level > $_POST["level"] ) {
	    $e_message = 'Only root admins can change user roles'; 
		
	    }
	  }
	  else 
	  $level   = safeEscape( $_POST["level"]);
	  $avatar     = strip_tags( $_POST["avatar"]);
	  $www        = strip_tags( $_POST["www"]);
	  $gender     = safeEscape( $_POST["gender"]);
	  $user_realm = strip_tags( $_POST["user_realm"]);
	  $user_clan  = strip_tags( $_POST["user_clan"]);
	  $admin_realm  = strip_tags( $_POST["admin_realm"]);
	  $sql_update_pw = "";
	  
	  $user_bnet = safeEscape( $_POST["user_bnet"]);
	   
	  if ( isset( $_POST["chpw"]) AND $_POST["chpw"] == 1 AND !isset($_GET["add"]) ) {
	    $password = $_POST["password_"];
	    $password2 = $_POST["password_2"];
		
		if ( strlen($password)<=2 ) $errors.="<div>Field Password does not have enough characters</div>";
		if ($password!=$password2)  $errors.="<div>Password and confirmation password do not match</div>";
		
		if ( empty($errors) ) {
		  $hash = generate_hash(16,1);
		  $password_db = generate_password($password, $hash);
		  $sql_update_pw = ", user_password = '".$<PASSWORD>."', password_hash = '".$hash."' ";
		}
		
	  }
	  
	  if ( isset($_GET["add"]) ) {
	    $password = $_POST["password_"];
	    $password2 = $_POST["<PASSWORD>"];
		
		if ( strlen($password)<=2 ) $errors.="<div>Field Password does not have enough characters</div>";
		if ($password!=$password2)  $errors.="<div>Password and confirmation password do not match</div>";
		$hash = generate_hash(16,1);
		$password_db = generate_password($password, $hash);
		
	  }
	  
	  if ( isset($_POST["ppw"]) AND !empty($_POST["ppw"]) ) {
	    $sql_update_pw.=", user_ppwd = '".trim( safeEscape($_POST["ppw"]) )."'";
	  }
	  
	  if ( strlen( $name)<=2 ) $errors.="<div>Field Name does not have enough characters</div>";
	  if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i", $email)) 
	  $errors.="<div>E-mail address is not valid</div>";
	  
	  $time = date( "Y-m-d H:i:s", time() );
	  
	  if ( isset($_GET["edit"]) ) $sql = "UPDATE ".OSDB_USERS." SET 
	  user_name= '".$name."', user_email = '".$email."', user_level = '".$level."', user_website = '".$www."', user_avatar = '".$avatar."', user_gender = '".$gender."', bnet_username = '".$bnet."', user_bnet = '".$user_bnet."', user_realm = '".$user_realm."', user_clan = '".$user_clan."', admin_realm = '".$admin_realm."'
	  $sql_update_pw 
	  WHERE user_id ='".$id."' LIMIT 1 ";
	  
	  if ( isset($_GET["add"]) ) $sql = "INSERT INTO ".OSDB_USERS."(user_name, user_email, user_password, password_hash, user_joined, bnet_username, user_bnet, user_realm, user_clan) VALUES('".$name."', '".$email."', '".$password_db."', '".$hash."', '".time()."', '".$bnet."', '".$user_bnet."', '".$user_realm."', '".$user_clan."')";
	  
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." WHERE (user_name) = ('".$name."') AND user_id!='".$id."' ");
	  $result = $sth->execute();
	  if ( $sth->rowCount() >=1 )  $errors.="<div>Username already taken</div>";
	  
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." 
	  WHERE (user_email) = ('".$email."') AND user_id!='".$id."' AND user_fbid!='' ");
	  $result = $sth->execute();
	  if ( $sth->rowCount() >=1 AND !isset($_GET["edit"]) )  $errors.="<div>E-mail already taken</div>";
	  
	  if ( empty($errors) ) {
	  $sth = $db->prepare($sql);
	  $result = $sth->execute();
	  if ( isset($_GET["edit"]) ) OS_AddLog($_SESSION["username"], "[os_edituser] Edit member ( $name )");<commit_msg>Small fix - check for duplicated battle net acc<commit_after><?php
if (!isset($website) ) { header('HTTP/1.1 404 Not Found'); die; }
$errors = "";
if ( isset($_GET["search_users"]) ) $s = safeEscape($_GET["search_users"]); else $s=""; 

?>
<div align="center" class="padBottom">
	 <form action="" method="get">
	 <table>
	   <tr>
	    <td width="290">
		  <input type="hidden" name="users" />
		  <input style="width: 180px; height: 24px;" type="text" name="search_users" value="<?=$s?>" />
		  <input class="menuButtons" type="submit" value="Search users" />
		</td>
	   </tr>
	 </table>
	 </form>
</div>
<?php
if ( isset($_GET["activate"]) AND is_numeric($_GET["activate"]) ) {
   $id = safeEscape( $_GET["activate"]);
   $update = $db->prepare("UPDATE ".OSDB_USERS." SET code = '' WHERE user_id = '".(int) $id."' LIMIT 1");
   $result = $update->execute();
   OS_AddLog($_SESSION["username"], "[os_users] Activated user ( #".(int)$id." )");
} 

//delete
  if ( isset( $_GET["del"]) AND is_numeric($_GET["del"]) AND OS_IsRoot() ) {
      $id = safeEscape( (int) $_GET["del"] );
	  $delete = $db->prepare("DELETE FROM ".OSDB_USERS." WHERE user_id ='".(int)$id."' LIMIT 1 ");
	  $result = $delete->execute();
	  $del2 = $db->query("DELETE FROM ".OSDB_COMMENTS." WHERE user_id ='".(int)$id."' ");
	  $result = $del2->execute();
	  OS_AddLog($_SESSION["username"], "[os_deleteuser] Deleted member ( #$id )");
	  ?>
	  <div align="center">
	  <h2>User successfully deleted. <a href="<?=OS_HOME?>adm/?users">&laquo; Back</a></h2>
	  </div>
	  <?php 
  }
//eDIT
  if ( (!OS_IsRoot() AND isset( $_GET["edit"]) AND is_numeric($_GET["edit"]) ) OR (isset($_GET["add"]) AND !OS_IsRoot() ) OR ( isset( $_GET["del"]) AND is_numeric($_GET["del"]) AND !OS_IsRoot() ) ) {
      ?>
	<div align="center" style="margin-bottom: 60px;">
	<h2>You don't have permission to access this page</h2>
	</div>
	<?php
  } else
  if ( (OS_IsRoot() AND isset( $_GET["edit"]) AND is_numeric($_GET["edit"]) ) OR isset($_GET["add"])  ) {
   $name = ""; $email = ""; $bnet = "";
   if ( isset($_GET["edit"])  AND is_numeric($_GET["edit"])  ) $id = safeEscape( (int) $_GET["edit"] ); else $id =0;
   //UPDATE
    if ( isset($_POST["edit_user"]) ) {
	  $name     = safeEscape( $_POST["name"]);
	  $bnet     = safeEscape( $_POST["bnet"]);
	  $email   = safeEscape( $_POST["email"]);
	  //if not root admin do not change access level
	  if ( $_SESSION["level"] <=9) {
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." WHERE user_id = '".$id."' ");
	  $result = $sth->execute();
	  $UserROW = $sth->fetch(PDO::FETCH_ASSOC);
	  $level = $UserROW["user_level"]; 
	  
	    if ( isset($_POST["level"]) AND $level > $_POST["level"] ) {
	    $e_message = 'Only root admins can change user roles'; 
		
	    }
	  }
	  else 
	  $level   = safeEscape( $_POST["level"]);
	  $avatar     = strip_tags( $_POST["avatar"]);
	  $www        = strip_tags( $_POST["www"]);
	  $gender     = safeEscape( $_POST["gender"]);
	  $user_realm = strip_tags( $_POST["user_realm"]);
	  $user_clan  = strip_tags( $_POST["user_clan"]);
	  $admin_realm  = strip_tags( $_POST["admin_realm"]);
	  $sql_update_pw = "";
	  
	  $user_bnet = safeEscape( $_POST["user_bnet"]);
	   
	  if ( isset( $_POST["chpw"]) AND $_POST["chpw"] == 1 AND !isset($_GET["add"]) ) {
	    $password = $_POST["password_"];
	    $password2 = $_POST["password_2"];
		
		if ( strlen($password)<=2 ) $errors.="<div>Field Password does not have enough characters</div>";
		if ($password!=$password2)  $errors.="<div>Password and confirmation password do not match</div>";
		
		if ( empty($errors) ) {
		  $hash = generate_hash(16,1);
		  $password_db = generate_password($password, $hash);
		  $sql_update_pw = ", user_password = '".$password_db."', password_hash = '".$hash."' ";
		}
		
	  }
	  
	  if ( isset($_GET["add"]) ) {
	    $password = $_POST["password_"];
	    $password2 = $_POST["<PASSWORD>"];
		
		if ( strlen($password)<=2 ) $errors.="<div>Field Password does not have enough characters</div>";
		if ($password!=$<PASSWORD>)  $errors.="<div>Password and confirmation password do not match</div>";
		$hash = generate_hash(16,1);
		$password_db = generate_password($password, $hash);
		
	  }
	  
	  if ( isset($_POST["ppw"]) AND !empty($_POST["ppw"]) ) {
	    $sql_update_pw.=", user_ppwd = '".trim( safeEscape($_POST["ppw"]) )."'";
	  }
	  
	  if ( strlen( $name)<=2 ) $errors.="<div>Field Name does not have enough characters</div>";
	  if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i", $email)) 
	  $errors.="<div>E-mail address is not valid</div>";
	  
	  $time = date( "Y-m-d H:i:s", time() );
	  
	  if ( isset($_GET["edit"]) ) $sql = "UPDATE ".OSDB_USERS." SET 
	  user_name= '".$name."', user_email = '".$email."', user_level = '".$level."', user_website = '".$www."', user_avatar = '".$avatar."', user_gender = '".$gender."', bnet_username = '".$bnet."', user_bnet = '".$user_bnet."', user_realm = '".$user_realm."', user_clan = '".$user_clan."', admin_realm = '".$admin_realm."'
	  $sql_update_pw 
	  WHERE user_id ='".$id."' LIMIT 1 ";
	  
	  if ( isset($_GET["add"]) ) $sql = "INSERT INTO ".OSDB_USERS."(user_name, user_email, user_password, password_hash, user_joined, bnet_username, user_bnet, user_realm, user_clan) VALUES('".$name."', '".$email."', '".$password_db."', '".$hash."', '".time()."', '".$bnet."', '".$user_bnet."', '".$user_realm."', '".$user_clan."')";
	  
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." WHERE (user_name) = ('".$name."') AND user_id!='".$id."' ");
	  $result = $sth->execute();
	  if ( $sth->rowCount() >=1 )  $errors.="<div>Username already taken</div>";
	  
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." 
	  WHERE (user_email) = ('".$email."') AND user_id!='".$id."' AND user_fbid!='' ");
	  $result = $sth->execute();
	  if ( $sth->rowCount() >=1 AND !isset($_GET["edit"]) )  $errors.="<div>E-mail already taken</div>";
	  
	  $sth = $db->prepare("SELECT * FROM ".OSDB_USERS." 
	  WHERE (bnet_username) = ('".$bnet."') ");
	  $result = $sth->execute();
	  if ( $sth->rowCount() >=1 AND !isset($_GET["edit"]) )  $errors.="<div>Battle.net account already exists</div>";
	  
	  if ( empty($errors) ) {
	  $sth = $db->prepare($sql);
	  $result = $sth->execute();
	  if ( isset($_GET["edit"]) ) OS_AddLog($_SESSION["username"], "[os_edituser] Edit member ( $name )");
{'fraction_non_alphanumeric': 0.24419916210119239, 'fraction_numerical': 0.007895584917821464, 'mean_word_length': 3.916039603960396, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '7032578', 'n_tokens_mistral': 4887, 'n_tokens_neox': 4600, 'n_words': 949}