<commit_before><?php 

namespace clientcal;

   function getuserkey($username) {
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql = "
      SELECT
         user_key 
      FROM
         user 
      WHERE
         username='$username'
      LIMIT 0,1
      ";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      $row = mysql_fetch_assoc($result);
      if (mysql_num_rows($result) < 1)
         return -1;
      return $row['user_key'];
   }
   function adduserprivilege($userkey,$privkey) {
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql = "INSERT INTO user_privilege SET user_key=$userkey,privilegetype_key=$privkey";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      return 0;
   }
   function enumerategrantableprivs($username,$privkey,$privapi,$privname,$privdesc,$privcount) {

      $privkey = array();   $privapi = array();   $privname = array();   $privdesc = array();
      
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql =
      "SELECT
          user_grantright.privilegetype_key AS privkey,
          privilegetype.api AS api,
	  privilegetype.value AS name,
	  privilegetype.description AS description
             FROM user_grantright
                LEFT JOIN privilegetype
                   ON privilegetype.privilegetype_key=user_grantright.privilegetype_key
                LEFT JOIN user
                   ON user_grantright.user_key=user.user_key
             WHERE user.username='$username'";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      $i = 0;
      while($row = mysql_fetch_assoc($result)) {
         $privkey[$i] = $row['privkey'];
	 $privapi[$i] = $row['api'];
	 $privname[$i] = $row['name'];
	 $privdesc[$i] = $row['description'];
	 $i++;
      }
      $privcount = $i;
      return 0;
   }
   function userexists($user) {
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysql_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password']))) {
         throw new error(-4,"while connect: " . mysql_error());
      }
      if (!mysql_select_db($myconfig['dbname'],$my)) {
         throw new error(-4,"while select: " . mysql_error());
      }
         
      $sql = "SELECT user_key FROM user WHERE username='$user' LIMIT 0,1";
      if (!($result = mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      if (mysql_num_rows($result) > 0)
         return 1;
      return 0;
   }
   function submitnewuser($username,$passwd) {
      if (userexists($username)) {
         throw new error(-3,"that username allready exists ($username)");
      }
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      
             
            $username = mysqli_real_escape_string($my,$username);
      
            $passwd = mysqli_real_escape_string($my,$passwd);
      
            $sql = "INSERT INTO user SET username='$username',password=PASSWORD('$<PASSWORD>')";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      return 0;
   }
   function verifyuserinfo($username,$passwd,&$pUsername) {
      $pUsername = "";
      
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
      if (!mysqli_select_db($my,$myconfig['dbname']))
         throw new error(-4,"while db: " . mysql_error($my));
      
         
      $username = mysqli_real_escape_string($my,$username);
      
      $passwd = mysqli_real_escape_string($my,$passwd);
      
      $sMajorVersion = substr(mysqli_get_server_info($my),0,1);
      
      if ($sMajorVersion < 4) { //no abstraction :|
         $sql = "SELECT user_key,username FROM user WHERE username='$username' AND password=PASSWORD('$<PASSWORD>')";
      } else {
         $sql = "SELECT user_key,username FROM user WHERE username='$username' AND password=OLD_PASSWORD('$<PASSWORD>')";
      }
      
      if (!($result = mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error($my));
         
      if (mysql_num_rows($result) == 0) {
         return FALSE;
      } else {<commit_msg>mysql fix<commit_after><?php 

namespace clientcal;

   function getuserkey($username) {
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql = "
      SELECT
         user_key 
      FROM
         user 
      WHERE
         username='$username'
      LIMIT 0,1
      ";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      $row = mysql_fetch_assoc($result);
      if (mysql_num_rows($result) < 1)
         return -1;
      return $row['user_key'];
   }
   function adduserprivilege($userkey,$privkey) {
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql = "INSERT INTO user_privilege SET user_key=$userkey,privilegetype_key=$privkey";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      return 0;
   }
   function enumerategrantableprivs($username,$privkey,$privapi,$privname,$privdesc,$privcount) {

      $privkey = array();   $privapi = array();   $privname = array();   $privdesc = array();
      
      $myconfig=(new config("mysql"))->getAssoc();
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      $sql =
      "SELECT
          user_grantright.privilegetype_key AS privkey,
          privilegetype.api AS api,
	  privilegetype.value AS name,
	  privilegetype.description AS description
             FROM user_grantright
                LEFT JOIN privilegetype
                   ON privilegetype.privilegetype_key=user_grantright.privilegetype_key
                LEFT JOIN user
                   ON user_grantright.user_key=user.user_key
             WHERE user.username='$username'";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      $i = 0;
      while($row = mysql_fetch_assoc($result)) {
         $privkey[$i] = $row['privkey'];
	 $privapi[$i] = $row['api'];
	 $privname[$i] = $row['name'];
	 $privdesc[$i] = $row['description'];
	 $i++;
      }
      $privcount = $i;
      return 0;
   }
   function userexists($user) {
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysql_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password']))) {
         throw new error(-4,"while connect: " . mysql_error());
      }
      if (!mysql_select_db($myconfig['dbname'],$my)) {
         throw new error(-4,"while select: " . mysql_error());
      }
         
      $sql = "SELECT user_key FROM user WHERE username='$user' LIMIT 0,1";
      if (!($result = mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      if (mysql_num_rows($result) > 0)
         return 1;
      return 0;
   }
   function submitnewuser($username,$passwd) {
      if (userexists($username)) {
         throw new error(-3,"that username allready exists ($username)");
      }
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
         if (!mysqli_select_db($my,$myconfig['dbname']))
            throw new error(-4,"while db: " . mysql_error($my));
      
             
            $username = mysqli_real_escape_string($my,$username);
      
            $passwd = mysqli_real_escape_string($my,$passwd);
      
            $sql = "INSERT INTO user SET username='$username',password=PASSWORD('$<PASSWORD>')";
      if (!($result = @mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error());
      return 0;
   }
   function verifyuserinfo($username,$passwd,&$pUsername) {
      $pUsername = "";
      
      $myconfig=(new config("mysql"))->getAssoc();
      
      if (!($my = mysqli_connect($myconfig['dbhost'],$myconfig['username'],$myconfig['password'])))
         throw new error(-4,"while connect: " . mysql_error($my));
      if (!mysqli_select_db($my,$myconfig['dbname']))
         throw new error(-4,"while db: " . mysql_error($my));
      
         
      $username = mysqli_real_escape_string($my,$username);
      
      $passwd = mysqli_real_escape_string($my,$passwd);
      
      $sMajorVersion = substr(mysqli_get_server_info($my),0,1);
      
      $sql = "SELECT user_key,username FROM user WHERE username='$username' AND password=PASSWORD('$<PASSWORD>')";
      
      if (!($result = mysql_query($sql,$my)))
         throw new error(-4,"while get: " . mysql_error($my));
         
      if (mysql_num_rows($result) == 0) {
         return FALSE;
      } else {
{'fraction_non_alphanumeric': 0.17274226048726873, 'fraction_numerical': 0.006503022531599194, 'mean_word_length': 2.804529616724739, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, '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': '2921694', 'n_tokens_mistral': 3451, 'n_tokens_neox': 3350, 'n_words': 622}