Beispiel #1
0
function getclassstudents($class_id)
{
    global $cfg;
    $whereClassParts = getClassWhereClauseForSitename($class_id);
    $classes = array();
    $query = "\n\tSELECT\n\t\tugroup_name,\n\t\tclass_external_id,\n\t\tclass_department,\n\t\tclass_number,\n\t\tclass_section,\n\t\tclass_semester,\n\t\tclass_year,\n\t\tclass.FK_owner AS class_owner_id,\n\t\tclassgroup.FK_owner AS classgroup_owner_id\n\tFROM \n\t\tclass\n\t\t\tLEFT JOIN \n\t\tclassgroup ON FK_classgroup = classgroup_id\n\t\t\tLEFT JOIN\n\t\tugroup ON FK_ugroup = ugroup_id\n\tWHERE \n\t\tclassgroup_name = '" . addslashes($class_id) . "'\n\t\tOR class_external_id = '" . addslashes($class_id) . "'\n\t\tOR {$whereClassParts}\n\t";
    $r = db_query($query);
    while ($resultArray = db_fetch_assoc($r)) {
        $classes[] = array('class_owner_id' => $resultArray['class_owner_id'], 'classgroup_owner_id' => $resultArray['classgroup_owner_id'], 'class_id' => $resultArray['ugroup_name']);
    }
    /******************************************************************************
     * DB Class info: queries ugroup_user table for all users who are part
     * of the $class_id group
     ******************************************************************************/
    $allparticipants = array();
    foreach ($classes as $class_array) {
        $class_id = $class_array['class_id'];
        if ($class_array['classgroup_owner_id']) {
            $owner_id = $class_array['classgroup_owner_id'];
        } else {
            $owner_id = $class_array['class_owner_id'];
        }
        $ugroup_id = getClassUGroupId($class_id);
        $db_participants = array();
        $external_memberlist_participants = array();
        $participant = array();
        $participants = array();
        $query = "\n\t\tSELECT\n\t\t\tuser_id,\n\t\t\tuser_fname,\n\t\t\tuser_uname,\n\t\t\tuser_email,\n\t\t\tuser_type\n\t\tFROM\n\t\t\tugroup_user\n\t\t\t\tINNER JOIN\n\t\t\tuser\n\t\t\t\tON\n\t\t\tFK_user = user_id\n\t\tWHERE\n\t\t\tFK_ugroup = '" . addslashes($ugroup_id) . "'\n\t\tORDER BY\n\t\t\tuser_type DESC, user_uname\n\t\t";
        $r = db_query($query);
        while ($a = db_fetch_assoc($r)) {
            $participant[id] = $a[user_id];
            $participant[fname] = $a[user_fname];
            $participant[uname] = $a[user_uname];
            $participant[email] = $a[user_email];
            $participant[type] = $a[user_type];
            $participant[memberlist] = "db";
            $db_participants[$a[user_uname]] = $participant;
        }
        /******************************************************************************
         * External member list source (e.g. LDAP group member
         ******************************************************************************/
        $external_memberlist_participants = array();
        $external_memberlist_participant_unames = array();
        /******************************************************************************
         * Compile definitive participant list from:
         * $db_participants = all group members whose membership is defined in ugroup_user
         * $external_memberlist_participants = all group members whose membership is
         * determined by an external membership list (e.g. ldap group)
         * if participant is in ugroup_user only then memberlist is db
         * if participant is in external member list only then memberlist is external
         * if participant is in both ugroup_user and external member list then
         * member list is external
         ******************************************************************************/
        $participants = $external_memberlist_participants;
        $participants_unames = $external_memberlist_participant_unames;
        foreach (array_keys($db_participants) as $key) {
            if (!in_array($db_participants[$key][uname], $external_memberlist_participant_unames)) {
                $participants[$db_participants[$key][uname]] = $db_participants[$key];
                $participants_unames = $db_participants[$key][uname];
            }
        }
        /******************************************************************************
         * add participants of current class to array of participants from all classes
         * (relevant when a site is a group of classes...)
         ******************************************************************************/
        $allparticipants = array_merge($allparticipants, $participants);
    }
    //return $participants;
    return $allparticipants;
}
Beispiel #2
0
function getclassstudents($class_id)
{
    global $cfg;
    $whereClassParts = getClassWhereClauseForSitename($class_id);
    $classes = array();
    $query = "\n\t\tSELECT\n\t\t\tugroup_name,\n\t\t\tclass_external_id,\n\t\t\tclass_department,\n\t\t\tclass_number,\n\t\t\tclass_section,\n\t\t\tclass_semester,\n\t\t\tclass_year,\n\t\t\tclass.FK_owner AS class_owner_id,\n\t\t\tclassgroup.FK_owner AS classgroup_owner_id\n\t\tFROM \n\t\t\tclass\n\t\t\t\tLEFT JOIN \n\t\t\tclassgroup ON FK_classgroup = classgroup_id\n\t\t\t\tLEFT JOIN\n\t\t\tugroup ON FK_ugroup = ugroup_id\n\t\tWHERE \n\t\t\tclassgroup_name = '" . addslashes($class_id) . "'\n\t\t\tOR class_external_id = '" . addslashes($class_id) . "'\n\t\t\tOR {$whereClassParts}\n\t";
    $r = db_query($query);
    while ($resultArray = db_fetch_assoc($r)) {
        $classes[] = array('class_owner_id' => $resultArray['class_owner_id'], 'classgroup_owner_id' => $resultArray['classgroup_owner_id'], 'class_id' => $resultArray['ugroup_name']);
    }
    /******************************************************************************
     * DB Class info: queries ugroup_user table for all users who are part
     * of the $class_id group
     ******************************************************************************/
    $allparticipants = array();
    foreach ($classes as $class_array) {
        $class_id = $class_array['class_id'];
        if ($class_array['classgroup_owner_id']) {
            $owner_id = $class_array['classgroup_owner_id'];
        } else {
            $owner_id = $class_array['class_owner_id'];
        }
        $ugroup_id = getClassUGroupId($class_id);
        $participant = array();
        $db_participants = array();
        $external_memberlist_participants = array();
        $participants = array();
        $query = "\n\t\t\tSELECT\n\t\t\t\tuser_id,\n\t\t\t\tuser_fname,\n\t\t\t\tuser_uname,\n\t\t\t\tuser_email,\n\t\t\t\tuser_type\n\t\t\tFROM\n\t\t\t\tugroup_user\n\t\t\t\t\tINNER JOIN\n\t\t\t\tuser\n\t\t\t\t\tON\n\t\t\t\tFK_user = user_id\n\t\t\tWHERE\n\t\t\t\tFK_ugroup = '" . addslashes($ugroup_id) . "'\n\t\t\tORDER BY\n\t\t\t\tuser_type DESC, user_uname\n\t\t";
        //		printpre($query);
        $r = db_query($query);
        while ($a = db_fetch_assoc($r)) {
            $participant[id] = $a[user_id];
            $participant[fname] = $a[user_fname];
            $participant[uname] = $a[user_uname];
            $participant[email] = $a[user_email];
            $participant[type] = $a[user_type];
            $participant[memberlist] = "db";
            $db_participants[$participant[id]] = $participant;
        }
        /******************************************************************************
         *  External member list source (e.g. LDAP group member
         *  LDAP Class info: queries LDAP for users in class group
         ******************************************************************************/
        ereg("([a-zA-Z]{0,})([0-9]{1,})([a-zA-Z]{0,})-([a-zA-Z]{1,})([0-9]{2})", $class_id, $r);
        $department = $r[1];
        $number = $r[2];
        $section = $r[3];
        $semester = $r[4];
        $year = $r[5];
        if ($semester == "f") {
            $semester = "Fall";
        } else {
            if ($semester == "s") {
                $semester = "Spring";
            } else {
                if ($semester == "w") {
                    $semester = "Winter";
                } else {
                    if ($semester == "l") {
                        $semester = "Summer";
                    }
                }
            }
        }
        /******************************************************************************
         * create class search dn with appropriate semester information
         ******************************************************************************/
        $ldap_search_semester = "ou=" . $semester . $year . ",ou=classes,ou=groups,";
        //printpre ($ldap_search_semester);
        $ldap_user = $cfg[ldap_voadmin_user_dn];
        $ldap_pass = $cfg[ldap_voadmin_pass];
        $c = ldap_connect($cfg[ldap_server]);
        $r = @ldap_bind($c, $ldap_user, $ldap_pass);
        if ($r && true) {
            // connected & logged in
            $return = array($cfg[ldap_groupmember_attribute]);
            /******************************************************************************
             * create class search dn and filter
             * needs to search semester, classes, groups within base domain
             ******************************************************************************/
            $classSearchDN = $ldap_search_semester . $cfg[ldap_base_dn];
            //printpre ("classSearchDN: ".$classSearchDN);
            $classSearchFilter = "(" . $cfg[ldap_groupname_attribute] . "=" . $class_id . ")";
            //printpre ("classSearchFilter:".$classSearchFilter);
            /******************************************************************************
             * search ldap with search dn and filter, get results, close ldap connection
             * results will be list of members of group within a class within a semester
             ******************************************************************************/
            $sr = ldap_search($c, $classSearchDN, $classSearchFilter, $return);
            $res = ldap_get_entries($c, $sr);
            if ($res['count']) {
                $res[0] = array_change_key_case($res[0], CASE_LOWER);
                //		print "<pre>";print_r($res);print"</pre>";
                $num = ldap_count_entries($c, $sr);
                //		print "num: $num<br />";
                ldap_close($c);
                /******************************************************************************
                 * if class found, then get groupmember attributes
                 * these will be list of students in class
                 ******************************************************************************/
                if ($num) {
                    //$groupmembers = array();
                    for ($i = 0; $i < $res[0][strtolower($cfg[ldap_groupmember_attribute])]['count']; $i++) {
                        $nextmember = $res[0][strtolower($cfg[ldap_groupmember_attribute])][$i];
                        /******************************************************************************
                         * for each member (ie student) found, search ldap for their attributes
                         * need, username, fullname at least
                         * (could add group attributes which would list groups they are members of)
                         ******************************************************************************/
                        $c = ldap_connect($cfg[ldap_server]);
                        $r = @ldap_bind($c, $ldap_user, $ldap_pass);
                        if ($r && true) {
                            // connected & logged in
                            $return2 = array($cfg[ldap_username_attribute], $cfg[ldap_fullname_attribute], $cfg[ldap_email_attribute], $cfg[ldap_group_attribute]);
                            $userSearchDN = ($cfg[ldap_user_dn] ? $cfg[ldap_user_dn] . "," : "") . $cfg[ldap_base_dn];
                            //printpre ("userSearchDN: ".$userSearchDN);
                            //not sure user search filter below will work
                            //search filter user in ldap.inc.php is
                            //$searchFilter = "(".$cfg[ldap_username_attribute]."=".$name.")";
                            $userSearchFilter = "(" . $nextmember . ")";
                            $userSearchFilter = eregi_replace("(,)\\s?" . $userSearchDN, "", $userSearchFilter);
                            $userSearchFilter = str_replace("\\", "", $userSearchFilter);
                            //printpre($userSearchFilter);
                            // search ldap with filter set to full name...
                            //$sr2 = ldap_search($c,$userSearchDN,$userSearchFilter,$return2);
                            //print "<hr />";
                            //printpre("$sr2 = ldap_search($c :: $userSearchDN :: $userSearchFilter :: $return2);");
                            //printpre($return2);
                            $sr2 = ldap_search($c, $userSearchDN, $userSearchFilter, $return2);
                            $res2 = ldap_get_entries($c, $sr2);
                            //printpre($res2);
                            $res2[0] = array_change_key_case($res2[0], CASE_LOWER);
                            //printpre($cfg[ldap_fullname_attribute]);
                            $num = ldap_count_entries($c, $sr);
                            ldap_close($c);
                            $participant = array();
                            if ($num) {
                                //printpre($cfg[ldap_username_attribute]);
                                $participant[id] = 0;
                                $participant[fname] = $res2[0][strtolower($cfg[ldap_fullname_attribute])][0];
                                $participant[uname] = $res2[0][strtolower($cfg[ldap_username_attribute])][0];
                                $participant[email] = $res2[0][strtolower($cfg[ldap_email_attribute])][0];
                                $participant[memberlist] = "external";
                                // 							printpre("uname: ".$participant[uname]);
                                $areprof = 0;
                                if (is_array($res2[0][strtolower($cfg[ldap_group_attribute])])) {
                                    $isProfSearchString = implode("|", $cfg[ldap_prof_groups]);
                                    foreach ($res2[0][strtolower($cfg[ldap_group_attribute])] as $item) {
                                        if (eregi($isProfSearchString, $item)) {
                                            $areprof = 1;
                                        }
                                    }
                                }
                                $participant[type] = $areprof ? "prof" : "stud";
                                //$student[email] = $res2[0][strtolower($cfg[ldap_email_attribute])][0];
                                //printpre("found ".$studentname);
                            }
                        }
                        // end if
                        $external_memberlist_participant_unames[] = $participant[uname];
                        $external_memberlist_participants[$participant[uname]] = $participant;
                    }
                    //end for loop
                }
                // end num
            }
            // end result count
        }
        // ends if bind
        $external_memberlist_participant_unames = array();
        $external_memberlist_participant_unames = array_unique($external_memberlist_participant_unames);
        /******************************************************************************
         * Check to see if $external_memberlist_participant are already in database
         * if not add them to database
         ******************************************************************************/
        foreach (array_keys($external_memberlist_participants) as $key) {
            $student_uname = $external_memberlist_participants[$key][uname];
            //printpre ($cfg[auth_mods]);
            //$cfg[auth_mods]
            $valid = 0;
            foreach ($cfg[auth_mods] as $_auth) {
                $func = "_valid_" . $_auth;
                //printpre ("<br />AUTH: trying ".$_auth ."..."); //debug
                if ($x = $func($student_uname, "", 1)) {
                    $valid = 1;
                    break;
                }
            }
        }
        /******************************************************************************
         * Compile definitive participant list from:
         * $db_participants = all group members whose membership is defined in ugroup_user
         * $external_memberlist_participants = all group members whose membership is
         * determined by an external membership list (e.g. ldap group)
         * if participant is in ugroup_user only then memberlist is db
         * if participant is in external member list only then memberlist is external
         * if participant is in both ugroup_user and external member list then
         * member list is external
         ******************************************************************************/
        $participants = $external_memberlist_participants;
        $participants_unames = $external_memberlist_participant_unames;
        foreach (array_keys($db_participants) as $key) {
            if (!in_array($db_participants[$key][uname], $external_memberlist_participant_unames)) {
                $participants[$db_participants[$key][uname]] = $db_participants[$key];
                $participants_unames = $db_participants[$key][uname];
            }
        }
        /******************************************************************************
         * add participants of current class to array of participants from all classes
         * (relevant when a site is a group of classes...)
         ******************************************************************************/
        $allparticipants = array_merge($allparticipants, $participants);
    }
    //return $participants;
    return $allparticipants;
}