| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:14:24 2008 ] | [ Segue 1.5.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <? /* $Id: midd.inc.php,v 1.30.2.2 2005/07/18 20:18:27 achapin Exp $ */ 2 3 // include the common class functions 4 require_once(dirname(__FILE__)."/common.inc.php"); 5 6 function isclass ($class) { 7 global $auser,$_isclass_cache; 8 9 if (isset($_isclass_cache[$class])) 10 return $_isclass_cache[$class]; 11 12 $auser = strtolower($auser); 13 14 // Check the name against the form of our class codes 15 $isClass = ereg("^(([a-zA-Z]{0,})([0-9]{1,})([a-zA-Z]{0,})-([a-zA-Z]{1,})([0-9]{2}))$",$class); 16 17 // If this isn't a class, but itself, but is a class group, then it is a class. 18 if (!$isClass && isgroup($class)) 19 $isClass = TRUE; 20 21 $_isclass_cache[$class] = $isClass; 22 return $isClass; 23 } 24 25 /****************************************************************************** 26 * getclassstudents queries LDAP for all the students in a class 27 ******************************************************************************/ 28 29 function getclassstudents($class_id) { 30 global $cfg; 31 32 $whereClassParts = getClassWhereClauseForSitename($class_id); 33 34 $classes = array(); 35 $query = " 36 SELECT 37 ugroup_name, 38 class_external_id, 39 class_department, 40 class_number, 41 class_section, 42 class_semester, 43 class_year, 44 class.FK_owner AS class_owner_id, 45 classgroup.FK_owner AS classgroup_owner_id 46 FROM 47 class 48 LEFT JOIN 49 classgroup ON FK_classgroup = classgroup_id 50 LEFT JOIN 51 ugroup ON FK_ugroup = ugroup_id 52 WHERE 53 classgroup_name = '$class_id' 54 OR class_external_id = '$class_id' 55 OR $whereClassParts 56 "; 57 58 $r = db_query($query); 59 while ($resultArray = db_fetch_assoc($r)) { 60 $classes[] = array ( 61 'class_owner_id' => $resultArray['class_owner_id'], 62 'classgroup_owner_id' => $resultArray['classgroup_owner_id'], 63 'class_id' => $resultArray['ugroup_name'] 64 ); 65 } 66 67 /****************************************************************************** 68 * DB Class info: queries ugroup_user table for all users who are part 69 * of the $class_id group 70 ******************************************************************************/ 71 72 $allparticipants = array(); 73 foreach ($classes as $class_array) { 74 $class_id = $class_array['class_id']; 75 76 if ($class_array['classgroup_owner_id']) 77 $owner_id = $class_array['classgroup_owner_id']; 78 else 79 $owner_id = $class_array['class_owner_id']; 80 81 $ugroup_id = getClassUGroupId($class_id); 82 $participant = array(); 83 $db_participants = array(); 84 $external_memberlist_participants = array(); 85 $participants = array(); 86 87 $query = " 88 SELECT 89 user_id, 90 user_fname, 91 user_uname, 92 user_email, 93 user_type 94 FROM 95 ugroup_user 96 INNER JOIN 97 user 98 ON 99 FK_user = user_id 100 WHERE 101 FK_ugroup = $ugroup_id 102 ORDER BY 103 user_type DESC, user_uname 104 "; 105 // printpre($query); 106 $r = db_query($query); 107 108 while ($a = db_fetch_assoc($r)) { 109 110 $participant[id] = $a[user_id]; 111 $participant[fname] = $a[user_fname]; 112 $participant[uname] = $a[user_uname]; 113 $participant[email] = $a[user_email]; 114 $participant[type] = $a[user_type]; 115 $participant[memberlist] = "db"; 116 $db_participants[$participant[id]]= $participant; 117 } 118 119 /****************************************************************************** 120 * External member list source (e.g. LDAP group member 121 * LDAP Class info: queries LDAP for users in class group 122 ******************************************************************************/ 123 124 125 ereg("([a-zA-Z]{0,})([0-9]{1,})([a-zA-Z]{0,})-([a-zA-Z]{1,})([0-9]{2})",$class_id,$r); 126 $department = $r[1]; 127 $number = $r[2]; 128 $section = $r[3]; 129 $semester = $r[4]; 130 $year = $r[5]; 131 132 if ($semester == "f") { 133 $semester = "Fall"; 134 } else if ($semester == "s"){ 135 $semester = "Spring"; 136 } else if ($semester == "w"){ 137 $semester = "Winter"; 138 } else if ($semester == "l"){ 139 $semester = "Summer"; 140 } 141 142 /****************************************************************************** 143 * create class search dn with appropriate semester information 144 ******************************************************************************/ 145 146 $ldap_search_semester = "ou=".$semester.$year.",ou=classes,ou=groups,"; 147 //printpre ($ldap_search_semester); 148 149 $ldap_user = $cfg[ldap_voadmin_user_dn]; 150 $ldap_pass = $cfg[ldap_voadmin_pass]; 151 152 $c = ldap_connect($cfg[ldap_server]); 153 $r = @ldap_bind($c,$ldap_user,$ldap_pass); 154 if ($r && true) { // connected & logged in 155 156 $return = array( 157 $cfg[ldap_groupmember_attribute] 158 ); 159 160 /****************************************************************************** 161 * create class search dn and filter 162 * needs to search semester, classes, groups within base domain 163 ******************************************************************************/ 164 165 $classSearchDN = $ldap_search_semester.$cfg[ldap_base_dn]; 166 //printpre ("classSearchDN: ".$classSearchDN); 167 $classSearchFilter = "(".$cfg[ldap_groupname_attribute]."=".$class_id.")"; 168 //printpre ("classSearchFilter:".$classSearchFilter); 169 170 /****************************************************************************** 171 * search ldap with search dn and filter, get results, close ldap connection 172 * results will be list of members of group within a class within a semester 173 ******************************************************************************/ 174 $sr = ldap_search($c,$classSearchDN,$classSearchFilter,$return); 175 $res = ldap_get_entries($c,$sr); 176 if ($res['count']) { 177 $res[0] = array_change_key_case($res[0], CASE_LOWER); 178 // print "<pre>";print_r($res);print"</pre>"; 179 $num = ldap_count_entries($c,$sr); 180 // print "num: $num<br />"; 181 ldap_close($c); 182 183 /****************************************************************************** 184 * if class found, then get groupmember attributes 185 * these will be list of students in class 186 ******************************************************************************/ 187 188 if ($num) { 189 //$groupmembers = array(); 190 for ($i = 0; $i<$res[0][strtolower($cfg[ldap_groupmember_attribute])]['count']; $i++) { 191 $nextmember = $res[0][strtolower($cfg[ldap_groupmember_attribute])][$i]; 192 193 /****************************************************************************** 194 * for each member (ie student) found, search ldap for their attributes 195 * need, username, fullname at least 196 * (could add group attributes which would list groups they are members of) 197 ******************************************************************************/ 198 199 $c = ldap_connect($cfg[ldap_server]); 200 $r = @ldap_bind($c,$ldap_user,$ldap_pass); 201 if ($r && true) { // connected & logged in 202 203 $return2 = array ( 204 $cfg[ldap_username_attribute], 205 $cfg[ldap_fullname_attribute], 206 $cfg[ldap_email_attribute], 207 $cfg[ldap_group_attribute] 208 ); 209 210 $userSearchDN = (($cfg[ldap_user_dn])?$cfg[ldap_user_dn].",":"").$cfg[ldap_base_dn]; 211 //printpre ("userSearchDN: ".$userSearchDN); 212 213 //not sure user search filter below will work 214 //search filter user in ldap.inc.php is 215 //$searchFilter = "(".$cfg[ldap_username_attribute]."=".$name.")"; 216 217 $userSearchFilter = "(".$nextmember.")"; 218 $userSearchFilter = eregi_replace("(,)\s?".$userSearchDN,"", $userSearchFilter); 219 $userSearchFilter = str_replace("\\", "", $userSearchFilter); 220 //printpre($userSearchFilter); 221 // search ldap with filter set to full name... 222 //$sr2 = ldap_search($c,$userSearchDN,$userSearchFilter,$return2); 223 //print "<hr>"; 224 //printpre("$sr2 = ldap_search($c :: $userSearchDN :: $userSearchFilter :: $return2);"); 225 //printpre($return2); 226 $sr2 = ldap_search($c,$userSearchDN,$userSearchFilter,$return2); 227 $res2 = ldap_get_entries($c,$sr2); 228 //printpre($res2); 229 $res2[0] = array_change_key_case($res2[0], CASE_LOWER); 230 //printpre($cfg[ldap_fullname_attribute]); 231 $num = ldap_count_entries($c,$sr); 232 ldap_close($c); 233 $participant = array(); 234 if ($num) { 235 //printpre($cfg[ldap_username_attribute]); 236 $participant[id] = 0; 237 $participant[fname] = $res2[0][strtolower($cfg[ldap_fullname_attribute])][0]; 238 $participant[uname] = $res2[0][strtolower($cfg[ldap_username_attribute])][0]; 239 $participant[email] = $res2[0][strtolower($cfg[ldap_email_attribute])][0]; 240 $participant[memberlist] = "external"; 241 // printpre("uname: ".$participant[uname]); 242 $areprof = 0; 243 if (is_array($res2[0][strtolower($cfg[ldap_group_attribute])])) { 244 $isProfSearchString = implode("|", $cfg[ldap_prof_groups]); 245 foreach ($res2[0][strtolower($cfg[ldap_group_attribute])] as $item) { 246 if (eregi($isProfSearchString,$item)) { 247 $areprof=1; 248 } 249 } 250 } 251 $participant[type] = ($areprof)?"prof":"stud"; 252 253 //$student[email] = $res2[0][strtolower($cfg[ldap_email_attribute])][0]; 254 //printpre("found ".$studentname); 255 } 256 } // end if 257 $external_memberlist_participant_unames[]= $participant[uname]; 258 259 $external_memberlist_participants[$participant[uname]]= $participant; 260 } //end for loop 261 } // end num 262 }// end result count 263 264 } // ends if bind 265 $external_memberlist_participant_unames = array(); 266 $external_memberlist_participant_unames = array_unique($external_memberlist_participant_unames); 267 268 /****************************************************************************** 269 * Check to see if $external_memberlist_participant are already in database 270 * if not add them to database 271 ******************************************************************************/ 272 foreach (array_keys($external_memberlist_participants) as $key) { 273 $student_uname = $external_memberlist_participants[$key][uname]; 274 //printpre ($cfg[auth_mods]); 275 //$cfg[auth_mods] 276 $valid = 0; 277 foreach ($cfg[auth_mods] as $_auth) { 278 $func = "_valid_".$_auth; 279 //printpre ("<br />AUTH: trying ".$_auth ."..."); //debug 280 if ($x = $func($student_uname,"",1)) { 281 $valid = 1; 282 break; 283 } 284 } 285 } 286 287 288 /****************************************************************************** 289 * Compile definitive participant list from: 290 * $db_participants = all group members whose membership is defined in ugroup_user 291 * $external_memberlist_participants = all group members whose membership is 292 * determined by an external membership list (e.g. ldap group) 293 * if participant is in ugroup_user only then memberlist is db 294 * if participant is in external member list only then memberlist is external 295 * if participant is in both ugroup_user and external member list then 296 * member list is external 297 ******************************************************************************/ 298 299 $participants = $external_memberlist_participants; 300 $participants_unames = $external_memberlist_participant_unames; 301 302 foreach (array_keys($db_participants) as $key) { 303 if (!in_array($db_participants[$key][uname], $external_memberlist_participant_unames)) { 304 $participants[$db_participants[$key][uname]] = $db_participants[$key]; 305 $participants_unames = $db_participants[$key][uname]; 306 } 307 } 308 309 /****************************************************************************** 310 * add participants of current class to array of participants from all classes 311 * (relevant when a site is a group of classes...) 312 ******************************************************************************/ 313 $allparticipants = array_merge($allparticipants,$participants); 314 315 316 } 317 //return $participants; 318 return $allparticipants; 319 320 } 321 322 323 function getuserclasses($user,$time="all") { 324 $user = strtolower($user); 325 global $cfg; 326 327 $ldap_user = $cfg[ldap_voadmin_user_dn]; 328 $ldap_pass = $cfg[ldap_voadmin_pass]; 329 330 $classes = array(); 331 332 if (!$user) 333 return $classes; 334 335 $c = ldap_connect($cfg[ldap_server]); 336 $r = @ldap_bind($c,$ldap_user,$ldap_pass); 337 if ($r && true) { // connected & logged in 338 339 $return = array( 340 $cfg[ldap_username_attribute], 341 $cfg[ldap_fullname_attribute], 342 $cfg[ldap_email_attribute], 343 $cfg[ldap_group_attribute] 344 ); 345 $userSearchDN = (($cfg[ldap_user_dn])?$cfg[ldap_user_dn].",":"").$cfg[ldap_base_dn]; 346 $searchFilter = "(".$cfg[ldap_username_attribute]."=".$user.")"; 347 348 $sr = ldap_search($c,$userSearchDN,$searchFilter,$return); 349 $res = ldap_get_entries($c,$sr); 350 if ($res['count']) { 351 $res[0] = array_change_key_case($res[0], CASE_LOWER); 352 // print "<pre>";print_r($res);print"</pre>"; 353 $num = ldap_count_entries($c,$sr); 354 // print "num: $num<br />"; 355 ldap_close($c); 356 if ($num) { 357 for ($i = 0; $i<$res[0][strtolower($cfg[ldap_group_attribute])]['count']; $i++) { 358 $f = $res[0][strtolower($cfg[ldap_group_attribute])][$i]; 359 // print "$f<br />"; 360 $parts = explode(",",$f); 361 foreach ($parts as $p) { 362 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)) { 363 // print "goood!"; 364 $semester = currentsemester (); 365 /* print "<pre>"; */ 366 /* print_r($r); */ 367 /* print "</pre>"; */ 368 $class = $r[1].$r[2].$r[3]."-".$r[4].$r[5]; 369 /****************************************************************************** 370 * update the classes table with the ldap information 371 ******************************************************************************/ 372 $sem = $r[4]; 373 $year = $r[5]; 374 $user_id = db_get_value("user","user_id","user_uname = '$user'"); 375 $ugroup_id = db_get_value("ugroup","ugroup_id","ugroup_name='$class'"); 376 $classinfo = db_get_line("class"," 377 class_department='$r[1]' AND 378 class_number='$r[2]' AND 379 class_section='$r[3]' AND 380 class_semester='$sem' AND 381 class_year='20$r[5]'"); 382 383 if (!$ugroup_id) { 384 385 $query = " 386 INSERT INTO 387 ugroup 388 SET 389 ugroup_name = '$class', 390 ugroup_type = 'class' 391 "; 392 db_query($query); 393 $ugroup_id = lastid(); 394 } 395 396 if (!$classinfo) { 397 $query = " 398 INSERT INTO 399 class 400 SET 401 class_external_id='$class', 402 class_department='$r[1]', 403 class_number='$r[2]', 404 class_section='$r[3]', 405 class_semester='$sem', 406 class_year='20$r[5]', 407 class_name='', 408 FK_owner=NULL, 409 FK_ugroup=$ugroup_id 410 "; 411 db_query($query); 412 } 413 414 $ugroup_userinfo = db_get_line("ugroup_user","FK_ugroup=$ugroup_id AND FK_user=$user_id"); 415 416 if (!$ugroup_userinfo) { 417 $query = " 418 INSERT INTO 419 ugroup_user 420 SET 421 FK_ugroup = $ugroup_id, 422 FK_user = $user_id 423 "; 424 db_query($query); 425 } 426 427 /****************************************************************************** 428 * end update 429 ******************************************************************************/ 430 431 432 if ($time == "now" && isSemesterNow($r[4], $r[5])) { 433 $classes[$class] = array("code"=>"$r[1]$r[2]","sect"=>$r[3],"sem"=>$r[4],"year"=>$r[5]); 434 435 } else if ($time == "past" && isSemesterPast($r[4], $r[5])) { 436 $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]); 437 438 } else if ($time == "future" && isSemesterFuture($r[4], $r[5])) { 439 $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]); 440 441 } else if ($time == "all") { 442 $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]); 443 } 444 } 445 } 446 } 447 } 448 } 449 } 450 // add in the DB classes 451 $query = " 452 SELECT 453 class_department, 454 class_number, 455 class_section, 456 class_semester, 457 class_year 458 FROM 459 user 460 INNER JOIN 461 ugroup_user 462 ON 463 user_id = FK_user 464 INNER JOIN 465 class 466 ON 467 class.FK_ugroup = ugroup_user.FK_ugroup 468 WHERE 469 user_uname = '$user' 470 "; 471 $semester = currentsemester (); 472 $r = db_query($query); 473 while ($a = db_fetch_assoc($r)) { 474 $class_code = generateCodeFromData($a[class_department],$a[class_number],$a[class_section],$a[class_semester],$a[class_year]); 475 if (!$classes[$class_code]) { 476 if ($time == "now" && isSemesterNow($a[class_semester], $a[class_year])) { 477 $classes[$class_code] = array("code"=>"$class_code","sect"=>$a[class_section],"sem"=>$a[class_semester],"year"=>$a[class_year]); 478 479 } else if ($time == "past" && isSemesterPast($a[class_semester], $a[class_year])) { 480 $classes[$class_code] = array("code"=>"$class_code","sect"=>$a[class_section],"sem"=>$a[class_semester],"year"=>$a[class_year]); 481 482 } else if ($time == "future" && isSemesterFuture($a[class_semester], $a[class_year])) { 483 $classes[$class_code] = array("code"=>"$class_code","sect"=>$a[class_section],"sem"=>$a[class_semester],"year"=>$a[class_year]); 484 485 } else if ($time == "all") { 486 $classes[$class_code] = array("code"=>"$class_code","sect"=>$a[class_section],"sem"=>$a[class_semester],"year"=>$a[class_year]); 487 } 488 } 489 } 490 return $classes; 491 } 492 493 function generateCourseCode($id) { 494 $query = " 495 SELECT 496 class_department, 497 class_number, 498 class_section, 499 class_semester, 500 class_year 501 FROM 502 class 503 WHERE 504 class_id = $id 505 "; 506 $r = db_query($query); 507 $a = db_fetch_assoc($r); 508 $code = $a[class_department].$a[class_number].$a[class_section]."-".$a[class_semester].substr($a[class_year],2); 509 return $code; 510 } 511 512 function generateCodeFromData($dept,$number,$section,$semester,$year,$ext_id="",$owner="") { 513 $code = $dept.$number.$section."-".$semester.substr($year,2); 514 return $code; 515 } 516 517 function generateTermsFromCode($code) { 518 ereg("([a-zA-Z]{0,})([0-9]{1,})([a-zA-Z]{0,})-([a-zA-Z]{1,})([0-9]{2})",$code,$r); 519 $department = $r[1]; 520 $number = $r[2]; 521 $section = $r[3]; 522 $semester = $r[4]; 523 $year = "20".$r[5]; 524 525 $terms = " 526 class_department='$department' AND 527 class_number='$number' AND 528 class_section='$section' AND 529 class_semester='$semester' AND 530 class_year='$year' 531 "; 532 return $terms; 533 } 534 535 //This function checks for non-Segue sites (those in web courses database created in course folders) 536 function coursefoldersite($cl) { 537 global $cfg; 538 db_connect($cfg[coursefolders_host],$cfg[coursefolders_username],$cfg[coursefolders_password],$cfg[coursefolders_db]); 539 if (ereg("([a-zA-Z]{2})([0-9]{3})([a-zA-Z]{0,1})-([a-zA-Z]{1,})([0-9]{2})",$cl,$regs)) { 540 $class = $regs[1].$regs[2].$regs[3]; 541 542 $curr_semester = $regs[4]; 543 if ($curr_semester == "f") { 544 $semester = "Fall"; 545 } else if ($curr_semester == "s"){ 546 $semester = "Spring"; 547 } else if ($curr_semester == "w"){ 548 $semester = "Winter"; 549 } else if ($curr_semester == "l"){ 550 $semester = "Summer"; 551 } 552 553 $curr_year = $regs[5]; 554 if ($curr_year > 95) { 555 $year = "19".$curr_year; 556 } else { 557 $year = "20".$curr_year; 558 } 559 } 560 $query = ("select * from ".$cfg[coursefolders_table]." where ".$cfg[coursefolders_coursecode_column]." = '$class' and ".$cfg[coursefolders_semester_column]." = '$semester' and ".$cfg[coursefolders_year_column]." = '$year'"); 561 $r = db_query($query); 562 if (db_num_rows($r)) { 563 $a = db_fetch_assoc($r); 564 $title = $a[$cfg[coursefolders_title_column]]; 565 $url = $a[$cfg[coursefolders_url_column]]; 566 $site_info = array('title' => $title, 'url' => $url); 567 return $site_info; 568 } 569 } 570 571 function ldapfname($uname) { 572 $uname = strtolower($uname); 573 if (isgroup($uname)) return "Students in group"; 574 if (isclass($uname)) return "Students in class"; 575 if ($fname = db_get_value("user","user_fname","user_uname='$uname'")) return $fname; 576 $r = userlookup($uname,LDAP_USER,LDAP_EXACT,LDAP_LASTNAME,1); 577 return $r[$uname]; 578 } 579 580 define("LDAP_USER",1); 581 define("LDAP_FNAME",2); 582 define("LDAP_BOTH",3); 583 define("LDAP_WILD",1); 584 define("LDAP_EXACT",0); 585 define("LDAP_LASTNAME",0); 586 define("LDAP_FIRSTNAME",1); 587 588 function userlookup($name,$type=LDAP_BOTH,$wild=LDAP_WILD,$n=LDAP_LASTNAME,$lc=0,$extra=false) { 589 $name = strtolower($name); 590 global $cfg; 591 $ldap_user = $cfg[ldap_voadmin_user_dn]; 592 $ldap_pass = $cfg[ldap_voadmin_pass]; 593 594 $wc = ($wild==LDAP_WILD)?"*":""; 595 596 $c = ldap_connect($cfg[ldap_server]); 597 $r = ldap_bind($c,$ldap_user,$ldap_pass); 598 if ($r) { 599 $return = array( 600 $cfg[ldap_username_attribute], 601 $cfg[ldap_fullname_attribute] 602 ); 603 604 if ($extra) { 605 $return[] = $cfg[ldap_email_attribute]; 606 $return[] = $cfg[ldap_group_attribute]; 607 } 608 $dn = (($cfg[ldap_user_dn])?$cfg[ldap_user_dn].",":"").$cfg[ldap_base_dn]; 609 if ($type == LDAP_USER) $filter = $cfg[ldap_username_attribute]."=$wc$name$wc"; 610 if ($type == LDAP_FNAME) $filter = $cfg[ldap_fullname_attribute]."=$wc$name$wc"; 611 if ($type == LDAP_BOTH) $filter = "(|(".$cfg[ldap_username_attribute]."=$wc$name$wc)(".$cfg[ldap_fullname_attribute]."=$wc$name$wc))"; 612 613 $sr = ldap_search($c,$dn,$filter,$return); 614 $res = ldap_get_entries($c,$sr); 615 if ($res['count']) { 616 $res[0] = array_change_key_case($res[0], CASE_LOWER); 617 $num = ldap_count_entries($c,$sr); 618 ldap_close($c); 619 /* print "<pre>"; */ 620 /* print_r($res); */ 621 /* print "</pre>"; */ 622 if ($num) { 623 $usernames = array(); 624 for ($i = 0; $i<$res['count'];$i++) { 625 $uid = $res[$i][strtolower($cfg[ldap_username_attribute])][0]; 626 $fname = $res[$i][strtolower($cfg[ldap_fullname_attribute])][0]; 627 if (!ereg(",",$fname) && !$n) { 628 $vars = split(" ",$fname); 629 if (count($vars) == 2) 630 $fname = $vars[1] . ", " . $vars[0]; 631 if (count($vars) == 3) 632 $fname = $vars[2] . ", " . $vars[0] . " " . $vars[1]; // for Gabriel B. Schine names 633 } 634 // $res[$i]['cn'][0] = $fname; 635 if ($extra) { 636 // we must find out if they are a professor or a student. 637 $areprof = false; 638 if (is_array($res[0][strtolower($cfg[ldap_group_attribute])])) { 639 $isProfSearchString = implode("|", $cfg[ldap_prof_groups]); 640 foreach ($res[0][strtolower($cfg[ldap_group_attribute])] as $item) { 641 if (eregi($isProfSearchString,$item)) { 642 $areprof=1; 643 } 644 } 645 } 646 $userType = ($areprof)?"prof":"stud"; 647 $usernames[strtolower($uid)] = array($fname,$res[$i][strtolower($cfg[ldap_email_attribute])][0],$userType); 648 } 649 else $usernames[strtolower($uid)] = $fname; 650 } 651 } 652 } 653 } 654 655 /****************************************************************************** 656 * add in the db users 657 ******************************************************************************/ 658 $query = " 659 SELECT 660 user_uname, 661 user_fname 662 FROM 663 user 664 WHERE 665 user_uname LIKE '%$name%' 666 OR 667 user_fname LIKE '%$name%' 668 "; 669 global $dbhost, $dbuser,$dbpass, $dbdb; 670 db_connect($dbhost, $dbuser, $dbpass, $dbdb); 671 $r = db_query($query); 672 $db_users = array(); 673 while ($a = db_fetch_assoc($r)) { 674 $db_users[$a[user_uname]] = $a[user_fname]; 675 } 676 677 /****************************************************************************** 678 * add in the ugroups 679 ******************************************************************************/ 680 $query = " 681 SELECT 682 ugroup_name 683 FROM 684 ugroup 685 WHERE 686 ugroup_name LIKE '%$name%' 687 "; 688 $r = db_query($query); 689 $ugroups = array(); 690 while ($a = db_fetch_assoc($r)) { 691 $ugroups[$a[ugroup_name]] = $a[ugroup_name]." (Group)"; 692 } 693 694 $usernames = array_merge($db_users,$usernames,$ugroups); 695 696 if ($lc && $usernames) { 697 foreach ($usernames as $u=>$f) 698 $usernames[strtoupper($u)] = $usernames[strtolower($u)] = $f; 699 } 700 701 return $usernames; 702 } 703 704 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |