Clan Adverts

www.afgserv.com

 

Toggle user registrations on or off

Description: This mod will allow you to toggle on or off the ability of new users to register on your site.
Version: 1
Added on: 13 May 2007
Author: DBF_Tim
Difficulty Level: Intermediate
Views: 560
Rating: 10.0 (3 Votes)
Detailed ProfileView Comments (2)

In your mainfile.php find

Code:
$result = $db->sql_query("SELECT * FROM ".$prefix."_config");
$row = $db->sql_fetchrow($result);

After it add the line
Code:
$allowreg = intval($row['allowreg']);
close and save the file.

in the file modules/Your_Account/index.php find
Code:
if(is_user($user)) {
  include("modules/$module_name/navbar.php");
}

afterwards add
Code:
function no_reg() {
     include("header.php");
         OpenTable();
      echo "<BR /><center><H2>Sorry we are not accepting new members at this time</H2></center><BR />";
         CloseTable();
         include("footer.php");
         die();
}

Find
Code:
if (!isset($hid)) { $hid = ""; }
if (!isset($url)) { $url = ""; }
if (!isset($bypass)) { $bypass = ""; }

After add
Code:
if (($allowreg == False) && (($op == "new_user") || ($op == "new user")))
{
  $op = "noreg";
}
After the line
Code:
switch($op) {
add
Code:
  case "noreg":
  no_reg();
  break;

Save and close the file.
In the file modules/Your_Account/admin/index.php find
Code:
global $prefix, $db, $admin_file;
and replace it with
Code:
global $prefix, $db, $admin_file, $allowregs;
Find
Code:
if ($row2['radminsuper'] == 1 || $auth_user == 1) {
Afterwards add
Code:
  function set_regs(){
  global $prefix, $db, $admin_file, $allowregs;

    $regsql = $db->sql_fetchrow($db->sql_query("SELECT * FROM ".$prefix."_config"));
    if ($regsql['allowreg'])
    {
      $allowregs = False;
    }
    else
    {
      $allowregs = True;
    }
    $regsql = $db->sql_fetchrow($db->sql_query("UPDATE ".$prefix."_config SET allowreg='$allowregs'"));
    $op = "mod_users";
    return;
  }
Find
Code:
      OpenTable();
      echo "<center><font class="title"><b>" . _USERADMIN . "</b></font></center>";
      CloseTable();
Afterward add
Code:
      echo "<br>";
      OpenTable();
      echo "<center><font class=\"option\"><b>Toggle User registration ";
    if ($allowreg)
    {
      echo " OFF ";
    }
    else
    {
      echo " ON ";
    }
    echo "</b></font> "
      ."<form method=\"post\" action=\"".$admin_file.".php\">";
      echo "<INPUT TYPE=HIDDEN NAME=\"op\" value=\"set_regs\">";
      echo "<input type=\"submit\" value=\"Toggle\"></form></center>";
      CloseTable();
Find
Code:
   switch($op) {
afterwards add
Code:
    case "set_regs":
    set_regs();

Save and close file.
In the file modules/Your_Account/admin/case.php find
Code:
switch($op) {
afterwards add
Code:
    case "set_regs";
Save and close the file.
In your favorite MySql administration program (like PHPMyAdmin) open your database, go to the _config table and add the field 'allowreg' as tinyint(1).

You should be all set now. I'm sure you noticed in this tutorial where I had placed the message "Sorry we are not accepting new members at this time" Obviuosly you can edit that to suit your needs.