From d105c55469074b3e182e26f397d06ad0635518d0 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Fri, 2 Sep 2011 00:30:24 +0200 Subject: [PATCH] Only members with a valid membership can migrate through the modal dialog. Note: Newly registered users are still migrated. --- inside/Page.php | 5 +-- inside/functions.php | 13 +++++++ inside/migration/inside_functions.php | 52 +++++++++++++++++---------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/inside/Page.php b/inside/Page.php index dd49bb4..2215810 100644 --- a/inside/Page.php +++ b/inside/Page.php @@ -831,8 +831,9 @@ possibly include it instead? --Thomas Misund, 26. Oct 2009 $form = new Form($title, $enctype, $method, $action, $fields, $id); $form->display("horizontal"); } - // Migration LDAP (nikolark) - if( !is_migrated(getCurrentUser()) ) { + // Migration LDAP (nikolark) + $uid = getCurrentUser(); + if( !is_migrated($uid) && !membership_expired($uid) ) { ?>
diff --git a/inside/functions.php b/inside/functions.php index b40642b..1623ce5 100644 --- a/inside/functions.php +++ b/inside/functions.php @@ -1602,6 +1602,19 @@ function set_migrated($uid) { } return true; } +/* User has valid membership? */ +function membership_expired($uid) { + $conn = db_connect(); + + $sql = sprintf("SELECT expires FROM din_user WHERE id=%s AND expires <= NOW()", $uid); + $result = $conn->query($sql); + + if (DB :: isError($result) == true) { + error("membership_expired: " . $result->toString()); + return false; + } + return $result->numRows() > 0; +} /* Find a users groups */ function find_groups($uid) { $conn = db_connect(); diff --git a/inside/migration/inside_functions.php b/inside/migration/inside_functions.php index 10178b7..ee1b24a 100644 --- a/inside/migration/inside_functions.php +++ b/inside/migration/inside_functions.php @@ -64,26 +64,42 @@ if( !function_exists('is_migrated') ) { return $result->numRows() > 0; } } +/* Note: copied from functions.php */ +if( !function_exists('membership_expired') ) { + function membership_expired($uid) { + $conn = db_connect(); + + $sql = sprintf("SELECT expires FROM din_user WHERE id=%s AND expires <= NOW()", $uid); + $result = $conn->query($sql); + + if (DB :: isError($result) == true) { + error("membership_expired: " . $result->toString()); + return false; + } + return $result->numRows() > 0; + } +} + /* Note: copied from functions.php */ if( !function_exists('find_groups') ) { -function find_groups($uid) { - $conn = db_connect(); - $sql = "SELECT g.posix_group - FROM din_usergrouprelationship ugr, din_user u, din_group g - WHERE ugr.user_id = $uid - AND ugr.user_id = u.id - AND ugr.group_id = g.id"; - $conn->setFetchMode(DB_FETCHMODE_ASSOC); - $result = $conn->getAll($sql); + function find_groups($uid) { + $conn = db_connect(); + $sql = "SELECT g.posix_group + FROM din_usergrouprelationship ugr, din_user u, din_group g + WHERE ugr.user_id = $uid + AND ugr.user_id = u.id + AND ugr.group_id = g.id"; + $conn->setFetchMode(DB_FETCHMODE_ASSOC); + $result = $conn->getAll($sql); - if(DB :: isError($result)) { - return false; - } - $arr = array(); - foreach($result as $column => $group) { - $arr[] = $group['posix_group']; - } + if(DB :: isError($result)) { + return false; + } + $arr = array(); + foreach($result as $column => $group) { + $arr[] = $group['posix_group']; + } - return $arr; -} + return $arr; + } }