Beispiel #1
0
function getClassgroupListsForGroupsContainingClasses($classesArray)
{
    global $dbhost, $dbuser, $dbpass, $dbdb;
    $classgroupLists = array();
    if (!count($classesArray)) {
        return $classgroupLists;
    }
    $query = "\nSELECT\n\tclassgroup_name,\n\tclass_department,\n\tclass_number,\n\tclass_section,\n\tclass_semester,\n\tclass_year\nFROM\n\tclass\n\t\tINNER JOIN\n\t\t\tclassgroup ON FK_classgroup = classgroup_id\nWHERE\n";
    $i = 0;
    foreach ($classesArray as $className) {
        $query .= "\n\t";
        if ($i > 0) {
            $query .= "OR ";
        }
        $query .= "(";
        $query .= generateTermsFromCode($className);
        $query .= ")";
        $i++;
    }
    $query .= "\nORDER BY\n\tclassgroup_name\n";
    $r = db_query($query);
    if (db_num_rows($r)) {
        while ($a = db_fetch_assoc($r)) {
            if (!isset($classgroupLists[$a['classgroup_name']])) {
                $classgroupLists[$a['classgroup_name']] = array();
            }
            $code = generateCodeFromData($a['class_department'], $a['class_number'], $a['class_section'], $a['class_semester'], $a['class_year']);
            $classgroupLists[$a['classgroup_name']][$code] = array('code' => $a['class_department'] . $a['class_number'], 'sect' => $a['class_section'], 'sem' => $a['class_semester'], 'year' => $a['class_year']);
        }
    }
    return $classgroupLists;
}
Beispiel #2
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;
}
Beispiel #3
0
            $obj->number = $_REQUEST['number'];
            $obj->section = $_REQUEST['section'];
            $obj->semester = $_REQUEST['semester'];
            $obj->year = $_REQUEST['year'];
            $obj->name = $_REQUEST['name'];
            $obj->owner = $owner_id;
            //		$obj->ugroup = $ugroup_id;
            //		$obj->classgroup = $_REQUEST['classgroup'];
            $obj->updateDB();
            $query = "\n\t\t\t\tUPDATE\n\t\t\t\t\tugroup\n\t\t\t\tSET\n\t\t\t\t\tugroup_name='" . generateCodeFromData($_REQUEST['department'], $_REQUEST['number'], $_REQUEST['section'], $_REQUEST['semester'], $_REQUEST['year']) . "'\n\t\t\t\tWHERE\n\t\t\t\t\tugroup_id='" . addslashes($obj->ugroup) . "'\n\t\t\t";
            db_query($query);
            if ($owner_id && !db_get_line("ugroup_user", "FK_user='******' AND FK_ugroup = '" . addslashes($obj->ugroup) . "'")) {
                $query = "\n\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\tugroup_user\n\t\t\t\t\tSET\n\t\t\t\t\t\tFK_ugroup = '" . addslashes($obj->ugroup) . "',\n\t\t\t\t\t\tFK_user = '******'\n\t\t\t\t";
                db_query($query);
            }
            $message = "Class '" . generateCodeFromData($_REQUEST['department'], $_REQUEST['number'], $_REQUEST['section'], $_REQUEST['semester'], $_REQUEST['year']) . "' updated successfully.";
            unset($_REQUEST['external_id'], $_REQUEST['name'], $_REQUEST['department'], $_REQUEST['number'], $_REQUEST['section'], $_REQUEST['semester'], $_REQUEST['year'], $_REQUEST['owner'], $_REQUEST['ugroup']);
        }
    }
}
/* if ($curraction == 'resetpw') { */
/* 	$id = $_REQUEST['id']; */
/* 	if ($id > 0) { */
/* 		$obj = &new user(); */
/* 		$obj->fetchUserID($id); */
/* 		$obj->randpass(5,3); */
/* 		$obj->updateDB(); */
/* 		$obj->sendemail(1); */
/* 		$message = "A random password has been generated for '".$obj->uname."' and an email has been sent to them."; */
/* 	} */
/* } */
Beispiel #4
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;
}