예제 #1
0
function getuserclasses($user, $time = "all")
{
    $user = strtolower($user);
    $classes = array();
    $semester = currentsemester();
    // add in the DB classes
    $query = "\n\t\tSELECT\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\tFROM\n\t\t\tuser\n\t\t\t\tINNER JOIN\n\t\t\tugroup_user\n\t\t\t\tON\n\t\t\tuser_id = FK_user\n\t\t\t\tINNER JOIN\n\t\t\tclass\n\t\t\t\tON\n\t\t\tclass.FK_ugroup = ugroup_user.FK_ugroup\n\t\tWHERE\n\t\t\tuser_uname = '" . addslashes($user) . "'\n\t";
    $semester = currentsemester();
    $r = db_query($query);
    while ($a = db_fetch_assoc($r)) {
        $class_code = generateCodeFromData($a[class_department], $a[class_number], $a[class_section], $a[class_semester], $a[class_year]);
        if (!$classes[$class_code]) {
            if ($time == "now" && isSemesterNow($a[class_semester], $a[class_year])) {
                $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
            } else {
                if ($time == "past" && isSemesterPast($a[class_semester], $a[class_year])) {
                    $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                } else {
                    if ($time == "future" && isSemesterFuture($a[class_semester], $a[class_year])) {
                        $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                    } else {
                        if ($time == "all") {
                            $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                        }
                    }
                }
            }
        }
    }
    return $classes;
}
예제 #2
0
/**
 * Determin if the semester and year specified are in the future
 * 
 * @param string $semester The semester in question.
 * @param integer $year		The year of the semester in question.
 * @return boolean
 * @access public
 * @date 9/9/04
 */
function isSemesterFuture($semester, $year)
{
    // If we are in the semester that is specified or it is past, don't bother
    // continuing.
    if (isSemesterNow($semester, $year) || isSemesterPast($semester, $year)) {
        return FALSE;
    } else {
        return TRUE;
    }
}
예제 #3
0
function getuserclasses($user, $time = "all")
{
    $user = strtolower($user);
    global $cfg;
    $ldap_user = $cfg[ldap_voadmin_user_dn];
    $ldap_pass = $cfg[ldap_voadmin_pass];
    $classes = array();
    if (!$user) {
        return $classes;
    }
    $c = ldap_connect($cfg[ldap_server]);
    $r = @ldap_bind($c, $ldap_user, $ldap_pass);
    if ($r && true) {
        // connected & logged in
        $return = 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];
        $searchFilter = "(" . $cfg[ldap_username_attribute] . "=" . $user . ")";
        $sr = ldap_search($c, $userSearchDN, $searchFilter, $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 ($num) {
                for ($i = 0; $i < $res[0][strtolower($cfg[ldap_group_attribute])]['count']; $i++) {
                    $f = $res[0][strtolower($cfg[ldap_group_attribute])][$i];
                    //				print "$f<br />";
                    $parts = explode(",", $f);
                    foreach ($parts as $p) {
                        if (eregi($cfg[ldap_groupname_attribute] . "=([a-zA-Z]{0,4})([0-9]{1,4})([a-zA-Z]{0,1})-([a-zA-Z]{1,})([0-9]{2})", $p, $r)) {
                            //						print "goood!";
                            $semester = currentsemester();
                            /* 						print "<pre>"; */
                            /* 						print_r($r); */
                            /* 						print "</pre>"; */
                            $class = $r[1] . $r[2] . $r[3] . "-" . $r[4] . $r[5];
                            /******************************************************************************
                             * update the classes table with the ldap information
                             ******************************************************************************/
                            $sem = $r[4];
                            $year = $r[5];
                            $user_id = db_get_value("user", "user_id", "user_uname = '" . addslashes($user) . "'");
                            $ugroup_id = db_get_value("ugroup", "ugroup_id", "ugroup_name='" . addslashes($class) . "'");
                            $classinfo = db_get_line("class", "\n\t\t\t\t\t\t\t\t\t\tclass_department='" . addslashes($r[1]) . "' AND\n\t\t\t\t\t\t\t\t\t\tclass_number='" . addslashes($r[2]) . "' AND\n\t\t\t\t\t\t\t\t\t\tclass_section='" . addslashes($r[3]) . "' AND\n\t\t\t\t\t\t\t\t\t\tclass_semester='" . addslashes($sem) . "' AND\n\t\t\t\t\t\t\t\t\t\tclass_year='20" . addslashes($r[5]) . "'");
                            if (!$ugroup_id) {
                                $query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t\tugroup\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tugroup_name = '" . addslashes($class) . "',\n\t\t\t\t\t\t\t\t\t\tugroup_type = 'class'\n\t\t\t\t\t\t\t\t";
                                db_query($query);
                                $ugroup_id = lastid();
                            }
                            if (!$classinfo) {
                                $query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t\tclass\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tclass_external_id='" . addslashes($class) . "',\n\t\t\t\t\t\t\t\t\t\tclass_department='" . addslashes($r[1]) . "',\n\t\t\t\t\t\t\t\t\t\tclass_number='" . addslashes($r[2]) . "',\n\t\t\t\t\t\t\t\t\t\tclass_section='" . addslashes($r[3]) . "',\n\t\t\t\t\t\t\t\t\t\tclass_semester='" . addslashes($sem) . "',\n\t\t\t\t\t\t\t\t\t\tclass_year='20" . addslashes($r[5]) . "',\n\t\t\t\t\t\t\t\t\t\tclass_name='',\n\t\t\t\t\t\t\t\t\t\tFK_owner=NULL,\n\t\t\t\t\t\t\t\t\t\tFK_ugroup='" . addslashes($ugroup_id) . "'\n\t\t\t\t\t\t\t\t";
                                db_query($query);
                            }
                            $ugroup_userinfo = db_get_line("ugroup_user", "FK_ugroup='" . addslashes($ugroup_id) . "' AND FK_user='******'");
                            if (!$ugroup_userinfo) {
                                $query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t\tugroup_user\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tFK_ugroup = '" . addslashes($ugroup_id) . "',\n\t\t\t\t\t\t\t\t\t\tFK_user = '******'\n\t\t\t\t\t\t\t\t";
                                db_query($query);
                            }
                            /******************************************************************************
                             * end update
                             ******************************************************************************/
                            if ($time == "now" && isSemesterNow($r[4], $r[5])) {
                                $classes[$class] = array("code" => "{$r['1']}{$r['2']}", "sect" => $r[3], "sem" => $r[4], "year" => $r[5]);
                            } else {
                                if ($time == "past" && isSemesterPast($r[4], $r[5])) {
                                    $classes[$r[1] . $r[2] . $r[3] . "-" . $r[4] . $r[5]] = array("code" => "{$r['1']}{$r['2']}", "sect" => $r[3], "sem" => $r[4], "year" => $r[5]);
                                } else {
                                    if ($time == "future" && isSemesterFuture($r[4], $r[5])) {
                                        $classes[$r[1] . $r[2] . $r[3] . "-" . $r[4] . $r[5]] = array("code" => "{$r['1']}{$r['2']}", "sect" => $r[3], "sem" => $r[4], "year" => $r[5]);
                                    } else {
                                        if ($time == "all") {
                                            $classes[$r[1] . $r[2] . $r[3] . "-" . $r[4] . $r[5]] = array("code" => "{$r['1']}{$r['2']}", "sect" => $r[3], "sem" => $r[4], "year" => $r[5]);
                                        }
                                    }
                                }
                            }
                            /******************************************************************************
                             * if not a class group then get group name and add to ugroup table
                             ******************************************************************************/
                        } else {
                            if (eregi('^' . $cfg[ldap_groupname_attribute] . '=(.+)$', $p, $matches)) {
                                $group_name = $matches[1];
                                $user_id = db_get_value("user", "user_id", "user_uname = '" . addslashes($user) . "'");
                                $ugroup_id = db_get_value("ugroup", "ugroup_id", "ugroup_name='" . addslashes($group_name) . "'");
                                /******************************************************************************
                                 * insert group_name into ugroup table with group if not already in table
                                 ******************************************************************************/
                                if (!$ugroup_id) {
                                    $query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t\tugroup\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tugroup_name = '" . addslashes($group_name) . "',\n\t\t\t\t\t\t\t\t\t\tugroup_type = 'other'\n\t\t\t\t\t\t\t\t";
                                    //printpre($query);
                                    db_query($query);
                                    $ugroup_id = lastid();
                                }
                                /******************************************************************************
                                 * if user not part of group then add to ugroup_user table
                                 ******************************************************************************/
                                $ugroup_userinfo = db_get_line("ugroup_user", "FK_ugroup='" . addslashes($ugroup_id) . "' AND FK_user='******'");
                                if (!$ugroup_userinfo) {
                                    $query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t\tugroup_user\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tFK_ugroup = '" . addslashes($ugroup_id) . "',\n\t\t\t\t\t\t\t\t\t\tFK_user = '******'\n\t\t\t\t\t\t\t\t";
                                    //printpre($query);
                                    db_query($query);
                                }
                                /******************************************************************************
                                 * get other members of this ugroup and add to ugroup_user table
                                 * (this may not be necessary since users will be added when they log in...)
                                 ******************************************************************************/
                            }
                        }
                    }
                }
            }
        }
    }
    // add in the DB classes
    $query = "\n\t\tSELECT\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\tFROM\n\t\t\tuser\n\t\t\t\tINNER JOIN\n\t\t\tugroup_user\n\t\t\t\tON\n\t\t\tuser_id = FK_user\n\t\t\t\tINNER JOIN\n\t\t\tclass\n\t\t\t\tON\n\t\t\tclass.FK_ugroup = ugroup_user.FK_ugroup\n\t\tWHERE\n\t\t\tuser_uname = '" . addslashes($user) . "'\n\t";
    $semester = currentsemester();
    $r = db_query($query);
    while ($a = db_fetch_assoc($r)) {
        $class_code = generateCodeFromData($a[class_department], $a[class_number], $a[class_section], $a[class_semester], $a[class_year]);
        if (!$classes[$class_code]) {
            if ($time == "now" && isSemesterNow($a[class_semester], $a[class_year])) {
                $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
            } else {
                if ($time == "past" && isSemesterPast($a[class_semester], $a[class_year])) {
                    $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                } else {
                    if ($time == "future" && isSemesterFuture($a[class_semester], $a[class_year])) {
                        $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                    } else {
                        if ($time == "all") {
                            $classes[$class_code] = array("code" => "{$class_code}", "sect" => $a[class_section], "sem" => $a[class_semester], "year" => $a[class_year]);
                        }
                    }
                }
            }
        }
    }
    return $classes;
}