diff --git a/htdocs/conf/conf.php.example b/htdocs/conf/conf.php.example index 50a575c04cd..69523435ff1 100644 --- a/htdocs/conf/conf.php.example +++ b/htdocs/conf/conf.php.example @@ -196,6 +196,14 @@ $dolibarr_main_force_https='0'; # $dolibarr_main_prod='1'; +# dolibarr_main_limit_users +# Can set a limit on the number of users it will be possible to create +# (the superadmin not included), can be used for a restricted mode. +# Default value: 0 (unlimited) +# Examples: +# $dolibarr_main_limit_users='0'; + + # This is an development feature to allow external components to overwrite # some Dolibarr kernel files to be overwritten by versions provided by # third parties modules. diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index 66babbcdf49..d9faa4b5a1a 100755 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -107,4 +107,5 @@ ConfirmCreateLogin=Are you sure you want to create a Dolibarr account for this m ConfirmCreateThirdParty=Are you sure you want to create a third party for this member ? LoginToCreate=Login to create NameToCreate=Name of third party to create -YourRole=Your roles \ No newline at end of file +YourRole=Your roles +YourQuotaOfUsersIsReached=Your quota of users is reached ! \ No newline at end of file diff --git a/htdocs/langs/fr_FR/users.lang b/htdocs/langs/fr_FR/users.lang index 0cd85cacb6b..0eed4607c43 100755 --- a/htdocs/langs/fr_FR/users.lang +++ b/htdocs/langs/fr_FR/users.lang @@ -107,4 +107,5 @@ ConfirmCreateLogin=Êtes-vous sûr de vouloir créer un compte Dolibarr pour cet ConfirmCreateThirdParty=Êtes-vous sûr de vouloir créer un tiers pour cet adhérent ? LoginToCreate=Login à créer NameToCreate=Nom du tiers à créer -YourRole=Vos rôles \ No newline at end of file +YourRole=Vos rôles +YourQuotaOfUsersIsReached=Votre quota d'utilisateurs est atteint ! \ No newline at end of file diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 1d3a4b077d3..59c25e2a37d 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -162,6 +162,8 @@ if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0; $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey=''; $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; +if (empty($dolibarr_main_limit_users)) $dolibarr_main_limit_users=0; +$conf->file->main_limit_users = $dolibarr_main_limit_users; if (defined('TEST_DB_FORCE_TYPE')) $conf->db->type=constant('TEST_DB_FORCE_TYPE'); // For test purpose // Identifiant autres $conf->file->main_authentication = empty($dolibarr_main_authentication)?'':$dolibarr_main_authentication; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 824e01dc5ad..8517c2c0f78 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -4,7 +4,7 @@ * Copyright (c) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2005 Lionel Cousteix * * This program is free software; you can redistribute it and/or modify @@ -23,16 +23,9 @@ */ /** - \file htdocs/user.class.php - \brief Fichier de la classe utilisateur - \author Rodolphe Quiedeville - \author Jean-Louis Bergamo - \author Laurent Destailleur - \author Sebastien Di Cintio - \author Benoit Mortier - \author Regis Houssin - \author Lionel Cousteix - \version $Id$ + * \file htdocs/user.class.php + * \brief Fichier de la classe utilisateur + * \version $Id$ */ require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); @@ -1799,6 +1792,36 @@ class User extends CommonObject return -1; } } + + /** + * \brief Return number of existing users + * \param limitToActive limit to active users + * \return int Number of users + */ + function getNbOfUsers($limitToActive=0) + { + global $conf; + + $sql = "SELECT count(rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."user"; + $sql.= " WHERE entity = ".$conf->entity; + if ($limitToActive) $sql.= " AND statut = 1"; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $nb=$obj->nb; + + $this->db->free($resql); + return $nb; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } } diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 5da9d3539df..1cf79b24cc1 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -3,7 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2005 Lionel Cousteix * * This program is free software; you can redistribute it and/or modify @@ -150,11 +150,21 @@ if ($_POST["action"] == 'add' && $canadduser) $message='
'.$langs->trans("LoginNotDefined").'
'; $action="create"; // Go back to create page } + + $edituser = new User($db); + + if (!empty($conf->file->main_limit_users)) + { + $nb = $edituser->getNbOfUsers(1); + if ($nb >= $conf->file->main_limit_users) + { + $message='
'.$langs->trans("YourQuotaOfUsersIsReached").'
'; + $action="create"; // Go back to create page + } + } if (! $message) { - $edituser = new User($db); - $edituser->nom = $_POST["nom"]; $edituser->prenom = $_POST["prenom"]; $edituser->login = $_POST["login"];