This repository has been archived by the owner. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #1 from szk11001/master
Replicate ECE preadvising dropdowns
- Loading branch information
Showing
3 changed files
with
285 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,79 @@ | ||
<?php | ||
<?php | ||
|
||
function ece_scripts() { | ||
wp_enqueue_style( 'ece-style', get_stylesheet_directory_uri() . '/css/ece.css'); | ||
wp_enqueue_script('ece-custom', get_stylesheet_directory_uri().'/js/custom.js', array('jquery')); | ||
wp_localize_script( 'ece-custom', 'ece_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'siteurl' => site_url() ) ); | ||
} | ||
add_action( 'wp_enqueue_scripts', 'ece_scripts'); | ||
|
||
function ece_get_courses( $discipline ){ | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,"http://web2.uconn.edu/ece/preadvising/pread_course.php"); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'discipline='.$discipline); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$courses = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
return json_decode($courses); | ||
} | ||
|
||
function ajax_ece_discipline_courses(){ | ||
$discipline = $_POST['discipline']; | ||
|
||
$courses = ece_get_courses( urlencode($discipline) ); | ||
|
||
echo wp_json_encode( $courses ); | ||
wp_die(); | ||
} | ||
add_action( 'wp_ajax_ece_discipline_courses', 'ajax_ece_discipline_courses' ); | ||
add_action('wp_ajax_nopriv_ece_discipline_courses', 'ajax_ece_discipline_courses'); | ||
|
||
function ece_get_course_info( $discipline, $course ){ | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,"http://web2.uconn.edu/ece/preadvising/pread_course.php"); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'course='.$course.'&discipline='.$discipline); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$courses = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
return json_decode($courses); | ||
} | ||
|
||
function ajax_ece_course_info(){ | ||
$discipline = $_POST['discipline']; | ||
$course = $_POST['course']; | ||
|
||
$courseInfo = ece_get_course_info( urlencode($discipline), urlencode($course) ); | ||
|
||
echo wp_json_encode( $courseInfo ); | ||
wp_die(); | ||
} | ||
add_action( 'wp_ajax_ece_course_info', 'ajax_ece_course_info' ); | ||
add_action('wp_ajax_nopriv_ece_course_info', 'ajax_ece_course_info'); | ||
|
||
function ece_get_major_info( $major ){ | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,"http://web2.uconn.edu/ece/preadvising/pread_major.php"); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'major='.$major); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$info = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
return json_decode($info); | ||
} | ||
|
||
function ajax_ece_major_info(){ | ||
$major = $_POST['major']; | ||
|
||
$majorInfo = ece_get_major_info( urlencode($major) ); | ||
|
||
echo wp_json_encode( $majorInfo ); | ||
wp_die(); | ||
} | ||
add_action( 'wp_ajax_ece_major_info', 'ajax_ece_major_info' ); | ||
add_action('wp_ajax_nopriv_ece_major_info', 'ajax_ece_major_info'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,137 @@ | ||
jQuery(document).ready(function($) { | ||
|
||
$( ".social-vimeo > a" ).html( "DONATE" ); | ||
|
||
var search = ''; | ||
var active = false; | ||
$('.search').on('click',function(e){ | ||
if($(e.target).attr('id')=='s') return; | ||
active = true; | ||
search = $(e.target).parent().html(); | ||
$('.search').fadeOut(500,function(){ | ||
$(this).html('<form class="form-inline" role="form" method="get" action="http://ece.uconn.edu/"><input id="s" type="text" onfocus="this.value = \'\'" name="s" value="Search ECE"></form>').fadeIn(500); | ||
$('.search').fadeOut(500,function(){ | ||
$(this).html('<form class="form-inline" role="form" method="get" action="http://ece.uconn.edu/"><input id="s" type="text" onfocus="this.value = \'\'" name="s" value="Search ECE"></form>').fadeIn(500); | ||
$(this).addClass('search-field'); | ||
}); | ||
}); | ||
|
||
$('body').on('click',function(e){ | ||
if($(e.target).attr('id')=='s') return; | ||
if($(e.target).parent().html()== search) return; | ||
if(!active) return; | ||
active = false; | ||
$('.search').fadeOut(500,function(){ | ||
$(this).html(search).fadeIn(500); | ||
$('.search').fadeOut(500,function(){ | ||
$(this).html(search).fadeIn(500); | ||
$('.search').removeClass('search-field'); | ||
}); | ||
}); | ||
|
||
$( "#footers" ).before( "<div class='container'><div class='col-sm-12 footer-img'></div></div>" ); | ||
|
||
|
||
|
||
}); | ||
$('select[name="discipline"] option:eq(0)').prop("selected", true); | ||
$('select[name="major"] option:eq(0)').prop("selected", true); | ||
|
||
var isCourseSelectActive = false; | ||
var selectedDiscipline; | ||
$('select[name="discipline"]').change(function(e){ | ||
var discipline = $(this).find(":selected").text(); | ||
selectedDiscipline = discipline; | ||
$.ajax({ | ||
type: "POST", | ||
url: ece_object.ajaxurl, | ||
data: { | ||
action: "ece_discipline_courses", | ||
discipline : discipline | ||
}, | ||
success: function(response){ | ||
if( isCourseSelectActive == true ){ | ||
$('.course-option').remove(); | ||
} | ||
$.each(response, function(i,v){ | ||
$('select[name="course"]').append( | ||
$('<option />', { | ||
'value': v, | ||
'text': v, | ||
'class': "course-option" | ||
}) | ||
); | ||
}); | ||
$('select[name="course"]').show(); | ||
isCourseSelectActive = true; | ||
}, dataType: "json" | ||
}); | ||
}); | ||
|
||
var isCourseInfoVisible = false; | ||
$('select[name="course"]').change(function(e){ | ||
if( isCourseSelectActive == false || selectedDiscipline == undefined ){ | ||
return false; | ||
} | ||
var course = $(this).find(":selected").text(); | ||
$.ajax({ | ||
type: "POST", | ||
url: ece_object.ajaxurl, | ||
data: { | ||
action: "ece_course_info", | ||
discipline: selectedDiscipline, | ||
course: course | ||
}, | ||
success: function(response){ | ||
if( isCourseInfoVisible == true ){ | ||
$('#ece-course-learnmore').empty(); | ||
$('.major-requiredcourses').remove(); | ||
} | ||
|
||
var courseInfo = response[0]; | ||
$('#ece-course-name').text(courseInfo.discipline + " " + courseInfo.course); | ||
$('#ece-course-learnmore').html( $('#ece-course-learnmore').text() + ' <a href="'+courseInfo.url+'">'+courseInfo.url+'</a>' ); | ||
$.each(courseInfo.majors, function(i,v){ | ||
$('#ece-course-required ul').append( | ||
$('<li />', { | ||
'text': v.major, | ||
'class': "major-requiredcourses" | ||
}) | ||
); | ||
}); | ||
$('#ece-course').show(); | ||
isCourseInfoVisible = true; | ||
}, dataType: "json" | ||
}); | ||
}); | ||
|
||
var isListVisible = false; | ||
$('select[name="major"]').change(function(e){ | ||
var major = $(this).find(":selected").text(); | ||
$.ajax({ | ||
type: "POST", | ||
url: ece_object.ajaxurl, | ||
data: { | ||
action: "ece_major_info", | ||
major: major, | ||
}, | ||
success: function(response){ | ||
if( isListVisible == true ){ | ||
$('.major-courses').remove(); | ||
} | ||
|
||
var majorInfo = response[0]; | ||
$('#ece-major-name').text(majorInfo.major); | ||
$('#ece-major-url').html('<a href="'+majorInfo.url+'">'+majorInfo.url+'</a>'); | ||
$('ece-major-text').text("UConn ECE offers the following courses which lead to a major in "+majorInfo.major); | ||
$.each(majorInfo.courses, function(i,v){ | ||
$('#ece-major-courses ul').append( | ||
$('<li />', { | ||
'text': v.discipline + " " + v.course, | ||
'class': "major-courses" | ||
}) | ||
); | ||
}); | ||
$('#ece-major').show(); | ||
isListVisible = true; | ||
}, dataType: "json" | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/* | ||
Template Name: Pre-Advising | ||
*/ | ||
|
||
function getByCourse(){ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL,"http://web2.uconn.edu/ece/preadvising/pread_course.php"); | ||
curl_setopt($ch, CURLOPT_HTTPGET, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$output = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
libxml_use_internal_errors(true); | ||
$dom = new DOMDocument; | ||
$dom->loadHTML($output); | ||
$xpath = new DOMXPath($dom); | ||
$majorOptions = $xpath->query('//select[@name="discipline"]/option'); | ||
|
||
$majors = array(); | ||
foreach( $majorOptions as $m ){ | ||
$majors[] = $m->getAttribute('value'); | ||
} | ||
|
||
return $majors; | ||
} | ||
|
||
function getByMajor(){ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL,"http://web2.uconn.edu/ece/preadvising/pread_major.php"); | ||
curl_setopt($ch, CURLOPT_HTTPGET, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$output = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
libxml_use_internal_errors(true); | ||
$dom = new DOMDocument; | ||
$dom->loadHTML($output); | ||
$xpath = new DOMXPath($dom); | ||
$majorOptions = $xpath->query('//select[@name="major"]/option'); | ||
|
||
$majors = array(); | ||
foreach( $majorOptions as $m ){ | ||
$majors[] = $m->getAttribute('value'); | ||
} | ||
|
||
return $majors; | ||
} | ||
|
||
get_header(); | ||
|
||
$majors = getByCourse(); | ||
echo '<select name="discipline">'; | ||
foreach( $majors as $k=>$m ){ | ||
if( empty($m) ){ | ||
$m = "Select a discipline"; | ||
} | ||
echo '<option value="'.$k.'">'.$m.'</option>'; | ||
} | ||
echo '</select>'; | ||
?> | ||
|
||
<br> | ||
<select name="course" style="display:none"><option value="0">Select a course</option></select> | ||
<div id="ece-course" style="display:none"> | ||
<p id="ece-course-name"></p> | ||
<p id="ece-course-learnmore">Learn more about the department at: </p> | ||
<div id="ece-course-required"> | ||
<p>This course is also a required course for the following majors:</p> | ||
<ul></ul> | ||
</div> | ||
</div> | ||
|
||
<br><br> | ||
|
||
<?php | ||
$getByMajor = getByMajor(); | ||
echo '<select name="major">'; | ||
foreach( $getByMajor as $k=>$m ){ | ||
if( empty($m) ){ | ||
$m = "Select a major"; | ||
} | ||
echo '<option value="'.$k.'">'.$m.'</option>'; | ||
} | ||
echo '</select>'; | ||
?> | ||
<div id="ece-major" style="display:none"> | ||
<p id="ece-major-name"></p> | ||
<p id="ece-major-url"></p> | ||
<div id="ece-major-courses"> | ||
<p id="ece-major-text"></p> | ||
<ul></ul> | ||
</div> | ||
<p>To see if your schools offers these courses, see the Guidance Director at your high school.</p> | ||
</div> | ||
<?php | ||
get_footer(); | ||
?> |