Location: PHPKode > projects > XMail PHP Admin Interface (XPAI) > xpai/includes/functions.php
<?php
if (!$in_xpai)
  die;

function pre_del_domain($mail_server, $domainname, $action)
{
  if ($action == 'domaindel')
  {
    echo "<p>You are about to delete mail domain <strong>".$_REQUEST['sel_domain']."</strong>.</p>";
    echo "This domain has the following users:</p>";
    echo "<ol>";

    foreach($mail_server->userlist($domainname) as $user) 
    {
      echo "<li>$user[1]@".$domainname."</li>";
    }
    echo "</ol>";
    echo "<p>Do you really want to delete this domain and all users?</p>";
  } else {
    echo "<p>You are about to delete custom domain <strong>".$domainname."</strong>.</p>";
    echo "<p>Do you really want to delete this domain?</p>";
  }
}

function del_domain($mail_server, $domainname, $action, $enable_filters, $filter_files, $enable_IMAP, $handle_secondaries)
{
  if ($action == 'domaindel')
  {
    $multi_success = true;
    $restore_secondaries = false;
    if (isset($handle_secondaries) && $handle_secondaries)
    {
      foreach ($_SESSION['secondary-ip'] as $secondary)
      {
        if (!$mail_server->custdomset($domainname, "", $secondary['ip'], $secondary['port']))
        {
          $multi_success = false;
          $restore_secondaries = true;
          $secondary_error_source = $secondary['ip']." ".$secondary['port'];
          echo "Error deleting domain <b>".$domainname."</b> from secondary ".$secondary['ip'].".<br>";
          break;
        } else {
          echo "Deleted custom domain <b>".$domainname."</b> from secondary ".$secondary['ip'].".<br>";
        }
      }
    }
    if ($multi_success)
    {
      foreach($mail_server->userlist($domainname) as $user)
      {
        if ($mail_server->userdel($domainname, $user[1]))
        {
          echo "User <strong>".$user[1]."@".$domainname."</strong> was deleted successfully.<br>";
          echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
        }
        if (isset($enable_filters) && $enable_filters && count($filter_files))
        {
          foreach ($filter_files as $filter_value)
          {
            $mail_server->upd_filtersin($user[1]."@".$domainname, $filter_value, 0); 
          }
          echo "Filter settings for <strong>".$user[1]."@".$domainname."</strong> were deleted successfully.<br>";
          echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
        }
        if (isset($enable_IMAP) && $enable_IMAP && ($user[3] != "M"))
        {
          $mail_server->update_IMAP($user[1]."@".$domainname, $user[1], $domainname, "unknown", "DELETE", true, true, true);
          echo "IMAP settings for <strong>".$user[1]."@".$domainname."</strong> were deleted successfully.<br>";
          echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
        }
      }
      if ($mail_server->domaindel($domainname))
      {
        echo "Domain <strong>".$domainname."</strong> was deleted successfully.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      } else {
        echo "Domain <strong>".$domainname."</strong> could not be deleted.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      }
      $do_menu_update = true;
    }
    if (isset($handle_secondaries) && $handle_secondaries && $restore_secondaries)
    {
      foreach ($_SESSION['secondary-ip'] as $secondary)
      {
        $mail_server->custdomset($domainname, $_SESSION['secondary-mode']."\t".$_SESSION['secondary-dest'], $secondary['ip'], $secondary['port']);
      }
    } 
    if (isset($handle_secondaries) && $handle_secondaries && !$multi_success)
    {
      echo "Could not delete domain <b>".$_REQUEST['sel_domain']."</b>.<br>";
      echo "Error on secondary server <strong>".$secondary_error_source."</strong><br>";
    }
  } else {
    $multi_success = true;
    $restore_secondaries = false;
    if (isset($handle_secondaries) && $handle_secondaries)
    {
      foreach ($_SESSION['secondary-ip'] as $secondary)
      {
        if (!$mail_server->custdomset($domainname, "", $secondary['ip'], $secondary['port']))
        {
          $multi_success = false;
          $restore_secondaries = true;
          $secondary_error_source = $secondary['ip']." ".$secondary['port'];
          echo "Error deleting custom domain <b>".$domainname."</b> from secondary ".$secondary['ip'].".<br>";
          break;
        } else {
          echo "Deleted custom domain <b>".$domainname."</b> from secondary ".$secondary['ip'].".<br>";
        }
      }
     }
    if ($multi_success)
    {
      $vars = array();
      if ($mail_server->custdomset($domainname, $vars))
      {
        echo "Custom domain <b>".$domainname."</b> was deleted successfully.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      } else {
        $restore_secondaries = true;
        echo "Custom domain <b>".$domainname."</b> could not be deleted.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      }
      $do_menu_update = true;
    }
    if (isset($handle_secondaries) && $handle_secondaries && $restore_secondaries)
    {
      foreach ($_SESSION['secondary-ip'] as $secondary)
      {
        $mail_server->custdomset($domainname, $_SESSION['secondary-mode']."\t".$_SESSION['secondary-dest'], $secondary['ip'], $secondary['port']);
      }
    } 
    if (isset($handle_secondaries) && $handle_secondaries && !$multi_success)
    {
      echo "Could not delete custom domain <b>".$domainname."</b>.<br>";
      echo "Error on secondary server <strong>".$secondary_error_source."</strong><br><br>";
    }
  }
}

function del_user($mail_server, $domainname, $username, $usertype, $enable_filters, $filter_files, $enable_IMAP)
{
  if (strcasecmp($username, "postmaster"))
  {
    if ($mail_server->userdel($domainname, $username))
    {
      echo "User <b>".$username."@".$domainname."</b> was deleted successfully.<br>";
      echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      if (isset($enable_filters) && $enable_filters && count($filter_files))
      {
        foreach ($filter_files as $filter_value)
        {
          $mail_server->upd_filtersin($username."@".$domainname, $filter_value, 0); 
        }
        echo "Filter settings for <b>".$username."@".$domainname."</b> were deleted successfully.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      }
      if (isset($enable_IMAP) && $enable_IMAP && ($usertype != "M"))
      {
        $mail_server->update_IMAP($username."@".$domainname, $username, $domainname, "unknown", "DELETE", true, true, true);
        echo "IMAP settings for <b>".$username."@".$domainname."</b> were deleted successfully.<br>";
        echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
      }
      $_SESSION['edit_user'] = "*";
      $_SESSION['edit_user_type'] = "U";
    } else {
      echo "User <b>".$username."@".$domainname."</b> could not be deleted.<br>";
      echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
    }
  } else {
    echo "<br>User <b>".$username."@".$domainname."</b> is postmaster and cannot be deleted.<br>";
  }
  echo "<br>";
}

function array_search_value($value,&$arr) {
  if (is_array($arr)) {
    $arr_i = -1;
    $arr_count = count($arr);
    while (++$arr_i < $arr_count) {
      if (is_string($value))
        if (!strcasecmp($arr[$arr_i], $value))
          return $arr_i;
    }
  }
  return -1;
}

?>
Return current item: XMail PHP Admin Interface (XPAI)