From 1b9ed2326095037ee4a42c62a39ef53e4f6a5b4b Mon Sep 17 00:00:00 2001
From: mlutfy <>
Date: Wed, 28 Jan 2009 20:02:01 +0000
Subject: [PATCH] limit account/member listing to those created by a specific
reseller
---
bureau/admin/adm_list.php | 17 +++++++-
bureau/class/m_admin.php | 82 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 96 insertions(+), 3 deletions(-)
diff --git a/bureau/admin/adm_list.php b/bureau/admin/adm_list.php
index 8824f71c..75563e21 100644
--- a/bureau/admin/adm_list.php
+++ b/bureau/admin/adm_list.php
@@ -37,7 +37,9 @@ if (!$admin->enabled) {
exit();
}
-$r=$admin->get_list($_REQUEST['show'] == 'all' ? 1 : 0);
+$creator_id = intval($_REQUEST['creator']);
+
+$r=$admin->get_list($_REQUEST['show'] == 'all' ? 1 : 0, $creator_id);
include("head.php");
?>
@@ -53,6 +55,19 @@ include("head.php");
' . _('List all the accounts') . '';
+
+ if ($cuid == 2000) {
+ $list_creators = $admin->get_creator_list();
+ $infos_creators = array();
+
+ foreach ($list_creators as $key => $val) {
+ $infos_creators[] = '' . $val['login'] . '';
+ }
+
+ if (count($infos_creators)) {
+ echo ' (' . implode(', ', $infos_creators) . ')';
+ }
+ }
} else {
echo '
' . _('List only my accounts') . '';
} ?>
diff --git a/bureau/class/m_admin.php b/bureau/class/m_admin.php
index 9eee4b6b..0b561f60 100644
--- a/bureau/class/m_admin.php
+++ b/bureau/class/m_admin.php
@@ -114,6 +114,49 @@ class m_admin {
return $c;
}
+ /**
+ * Returns the known information about a specific hosted account
+ * Similar to get_list() but for creators/resellers.
+ */
+ function get_creator($uid) {
+ global $err,$db;
+ // $err->log("admin","get",$uid);
+ if (!$this->enabled) {
+ $err->raise("admin",1);
+ return false;
+ }
+
+ $db->query("SELECT m.*, parent.login as parentlogin FROM membres as m LEFT JOIN membres as parent ON (parent.uid = m.creator) WHERE m.uid='$uid';");
+
+ if ($db->num_rows()) {
+ $db->next_record();
+ $c=$db->Record;
+ } else {
+ $err->raise("admin",2);
+ return false;
+ }
+
+ $db->query("SELECT * FROM local WHERE uid='$uid';");
+ if ($db->num_rows()) {
+ $db->next_record();
+ reset($db->Record);
+ while (list($key,$val)=each($db->Record)) {
+ $c[$key]=$val;
+ }
+ }
+
+ $db->query("SELECT count(*) as nbcreated FROM membres WHERE creator='$uid';");
+ if ($db->num_rows()) {
+ $db->next_record();
+ reset($db->Record);
+ while (list($key,$val)=each($db->Record)) {
+ $c[$key]=$val;
+ }
+ }
+
+ return $c;
+ }
+
/* ----------------------------------------------------------------- */
/**
* @return TRUE if there's only ONE admin account
@@ -146,7 +189,7 @@ class m_admin {
* produite.
*
*/
- function get_list($all=0) {
+ function get_list($all=0,$creator=0) {
// PATCHBEN pour ne voir que les comptes que l'on a créé (sauf admin)
global $err,$mem,$cuid;
$err->log("admin","get_list");
@@ -155,7 +198,10 @@ class m_admin {
return false;
}
$db=new DB_System();
- if ($mem->user[uid]==2000 || $all) {
+ if ($mem->user['uid']==2000 && $creator) {
+ // Limit listing to a specific reseller
+ $db->query("SELECT uid FROM membres WHERE creator='".$creator."' ORDER BY login;");
+ } elseif ($mem->user['uid']==2000 || $all) {
$db->query("SELECT uid FROM membres ORDER BY login;");
} else {
$db->query("SELECT uid FROM membres WHERE creator='".$cuid."' ORDER BY login;");
@@ -170,6 +216,38 @@ class m_admin {
}
}
+ /**
+ * Returns the known information about resellers (uid, login, number of accounts)
+ * May only be called by the admin account (2000)
+ */
+ function get_creator_list() {
+ global $err,$mem,$cuid;
+
+ $err->log("admin","get_reseller_list");
+ if (!$this->enabled) {
+ $err->raise("admin",1);
+ return false;
+ }
+
+ if ($cuid != 2000) {
+ $err->raise("admin",1);
+ return false;
+ }
+
+ $db=new DB_System();
+
+ $db->query("SELECT distinct creator FROM membres WHERE creator <> 0 ORDER BY creator asc;");
+
+ if ($db->num_rows()) {
+ while ($db->next_record()) {
+ $c[]=$this->get_creator($db->f("creator"));
+ }
+ return $c;
+ } else {
+ return false;
+ }
+ }
+
/* ----------------------------------------------------------------- */
/**
* Check if I am the creator of the member $uid