<commit_before><?php
/**
 * Users Definition
 *
 * @author <NAME> 
 * @version $Id: Class.User.php,v 1.65 2008/08/11 14:14:14 marc Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */



include_once('Class.DbObj.php');
include_once('Class.QueryDb.php');
include_once('Class.Log.php');
include_once('Class.Application.php');
include_once('Class.Group.php');

require_once 'PEAR.php';
require_once 'Crypt/CHAP.php';

define("GALL_ID", 2);
define("ANONYMOUS_ID", 3);
define("GADMIN_ID", 4);

Class User extends DbObj
{
  var $fields = array ( "id","iddomain","lastname","firstname","login","password","isgroup","expires","passdelay","status","mail","ntpasswordhash","lmpasswordhash","fid");

  var $id_fields = array ("id");

  var $dbtable = "users";

  var $order_by="lastname, isgroup desc";

  var $fulltextfields = array ("login","lastname","firstname");

  var $sqlcreate = "
create table users ( id      int not null,
                     iddomain int not null,
                primary key (id),
                        lastname   text,
                        firstname  text,
                        login      text not null,
                        password   varchar(30) not null,
                        isgroup    char,
                        expires    int,
                        passdelay  int,
                        status     char,
                        mail       text,
                        ntpasswordhash text,
                        lmpasswordhash text,
                        fid int);
create index users_idx2 on users(lastname);
create index users_idx3 on users(login);
CREATE UNIQUE INDEX uni_users on users (login,iddomain);
create sequence seq_id_users start 10";


  /** 
   * affect user from login name
   */ 
  function SetLoginName($loginDomain)  {
    include_once("Class.Domain.php");
    $loginDomain=trim(strtolower($loginDomain));
    $query = new QueryDb($this->dbaccess,"User");
    $query->AddQuery("login='".pg_escape_string($loginDomain)."'");
    $query->order_by='iddomain';
    $list = $query->Query(0,0,"TABLE");
    if ($query->nb > 0) {
      $this->Affect($list[0]);
    } else {
      if (preg_match("/(.*)@(.*)/",$loginDomain, $reg)) {
	  
	$queryd = new QueryDb($this->dbaccess,"Domain");
	$queryd->AddQuery("name='".$reg[2]."'");
	$list = $queryd->Query();

	if ($queryd->nb == 1) {
	  $domainId=$list[0]->iddomain;
	  $query->AddQuery("iddomain='$domainId'");
	  $query->AddQuery("login='".pg_escape_string($reg[1])."'");
	} else {
	  return false;
	}    
      }
      return FALSE;
    }

    return TRUE;
  }

  function SetLogin($login,$domain)
    {
      $login=strtolower($login);
      $domain=strtolower($domain);
      $query = new QueryDb($this->dbaccess,"User");

      $query->basic_elem->sup_where=array("login='".pg_escape_string($login)."'",
					  "iddomain=$domain");

      $list = $query->Query(0,0,"TABLE");

      if ($query->nb != 0) {
	$this->Affect($list[0]);
      } else {
	return FALSE;
      }

      return TRUE;
    }

  function PreInsert()    {
    if ($this->Setlogin($this->login,$this->iddomain)) return "this login exists";                                            
    if ($this->login=="") return _("login must not be empty");                                          
    if ($this->id == "") {
      $res = pg_exec($this->dbid, "select nextval ('seq_id_users')");
      $arr = pg_fetch_array ($res, 0);
      $this->id = $arr["nextval"];
    }
                                                                                      
                                                                                        
                                                                                     
    if (isset($this->isgroup) && ($this->isgroup == "Y")) {
      $this->password_new="no"; // no passwd for group
    } else {
      $this->isgroup = "N";
    }

 

    $this->login = strtolower($this->login);

    if (isset($this->password_new) && ($this->password_new!="")) {
      $this->computepass($this->password_new, $this->password);
    }
<commit_msg>s/strtolower/mb_strtolower/ in Class.User.php (closes #1492)<commit_after><?php
/**
 * Users Definition
 *
 * @author Anakeen 2000 
 * @version $Id: Class.User.php,v 1.65 2008/08/11 14:14:14 marc Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */



include_once('Class.DbObj.php');
include_once('Class.QueryDb.php');
include_once('Class.Log.php');
include_once('Class.Application.php');
include_once('Class.Group.php');

require_once 'PEAR.php';
require_once 'Crypt/CHAP.php';

define("GALL_ID", 2);
define("ANONYMOUS_ID", 3);
define("GADMIN_ID", 4);

Class User extends DbObj
{
  var $fields = array ( "id","iddomain","lastname","firstname","login","password","isgroup","expires","passdelay","status","mail","ntpasswordhash","lmpasswordhash","fid");

  var $id_fields = array ("id");

  var $dbtable = "users";

  var $order_by="lastname, isgroup desc";

  var $fulltextfields = array ("login","lastname","firstname");

  var $sqlcreate = "
create table users ( id      int not null,
                     iddomain int not null,
                primary key (id),
                        lastname   text,
                        firstname  text,
                        login      text not null,
                        password   varchar(30) not null,
                        isgroup    char,
                        expires    int,
                        passdelay  int,
                        status     char,
                        mail       text,
                        ntpasswordhash text,
                        lmpasswordhash text,
                        fid int);
create index users_idx2 on users(lastname);
create index users_idx3 on users(login);
CREATE UNIQUE INDEX uni_users on users (login,iddomain);
create sequence seq_id_users start 10";


  /** 
   * affect user from login name
   */ 
  function SetLoginName($loginDomain)  {
    include_once("Class.Domain.php");
    $loginDomain=trim(mb_strtolower($loginDomain));
    $query = new QueryDb($this->dbaccess,"User");
    $query->AddQuery("login='".pg_escape_string($loginDomain)."'");
    $query->order_by='iddomain';
    $list = $query->Query(0,0,"TABLE");
    if ($query->nb > 0) {
      $this->Affect($list[0]);
    } else {
      if (preg_match("/(.*)@(.*)/",$loginDomain, $reg)) {
	  
	$queryd = new QueryDb($this->dbaccess,"Domain");
	$queryd->AddQuery("name='".$reg[2]."'");
	$list = $queryd->Query();

	if ($queryd->nb == 1) {
	  $domainId=$list[0]->iddomain;
	  $query->AddQuery("iddomain='$domainId'");
	  $query->AddQuery("login='".pg_escape_string($reg[1])."'");
	} else {
	  return false;
	}    
      }
      return FALSE;
    }

    return TRUE;
  }

  function SetLogin($login,$domain)
    {
      $login=mb_strtolower($login);
      $domain=mb_strtolower($domain);
      $query = new QueryDb($this->dbaccess,"User");

      $query->basic_elem->sup_where=array("login='".pg_escape_string($login)."'",
					  "iddomain=$domain");

      $list = $query->Query(0,0,"TABLE");

      if ($query->nb != 0) {
	$this->Affect($list[0]);
      } else {
	return FALSE;
      }

      return TRUE;
    }

  function PreInsert()    {
    if ($this->Setlogin($this->login,$this->iddomain)) return "this login exists";                                            
    if ($this->login=="") return _("login must not be empty");                                          
    if ($this->id == "") {
      $res = pg_exec($this->dbid, "select nextval ('seq_id_users')");
      $arr = pg_fetch_array ($res, 0);
      $this->id = $arr["nextval"];
    }
                                                                                      
                                                                                        
                                                                                     
    if (isset($this->isgroup) && ($this->isgroup == "Y")) {
      $this->password_new="no"; // no passwd for group
    } else {
      $this->isgroup = "N";
    }

 

    $this->login = mb_strtolower($this->login);

    if (isset($this->password_new) && ($this->password_new!="")) {
      $this->computepass($this->password_new, $this->password);
    }

{'fraction_non_alphanumeric': 0.16288194031625253, 'fraction_numerical': 0.010700273451432648, 'mean_word_length': 1.971388202048746, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4482372', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2486, 'n_words': 483}