<file_sep><?php
/**
 * Initialise Taxonmies used for the MACS students pages
 * i.e.: location, department, semester, level, delivery level
 *
 * posts_by_taxon() : return list of posts as classified by these txnms
 */

function location_init() 
{
	$name ='location';
	$object_type = array('cs-course', 
						'maths-course', 
						'ams-course', 
						'person');
	$args = array(
		'label'=> 'Locations',
		'hierarchical' => true,
		'show_ui' => true,
		'show_in_menu' => false,
		'show_in_nav_menus' => true		
	);
	register_taxonomy( $name, $object_type, $args);
}
add_action( 'init', 'location_init' );

function department_init() 
{
	$name ='department';
	$object_type = 'person';
	$args = array(
		'label'=> 'Department',
		'hierarchical' => true,
		'show_ui' => true,
		'show_in_menu' => false,
		'show_in_nav_menus' => true		
	);
	register_taxonomy( $name, $object_type, $args);
}
add_action( 'init', 'department_init' );

function semester_init() 
{
	$name ='semester';
	$object_type = array('cs-course', 
						'maths-course', 
						'ams-course', 
						);
	$args = array(
		'label'=> 'Semester',
		'hierarchical' => true,
		'show_ui' => true,
		'show_in_menu' => false,
		'show_in_nav_menus' => true		
	);
	register_taxonomy( $name, $object_type, $args);
}
add_action( 'init', 'semester_init' );

function level_init() 
{
	$name ='level';
	$object_type = array('cs-course', 
						'maths-course', 
						'ams-course', 
						);
	$args = array(
		'label'=> 'SCQF Level',
		'hierarchical' => true,
		'show_ui' => true,
		'show_in_menu' => false,
		'show_in_nav_menus' => true		
	);
	register_taxonomy( $name, $object_type, $args);
}
add_action( 'init', 'level_init' );

function delivery_level_init() 
{
	$name ='deliveryLevel';
	$object_type = array('cs-course', 
						'maths-course', 
						'ams-course', 
						);
	$args = array(
		'label'=> 'Delivery Levels',
		'hierarchical' => true,
		'show_ui' => true,
		'show_in_menu' => false,
		'show_in_nav_menus' => true		
	);
	register_taxonomy( $name, $object_type, $args);
}
add_action( 'init', 'delivery_level_init' );

function posts_by_taxon ( $atts ) 
{
	$results = '<p>';
	$query = array();
	$query['posts_per_page'] = -1;
	$query['tax_query'] = array();
	$taxonomies = get_taxonomies();
	
	if ( array_key_exists( 'debug', $atts ) )
	{
		$debug = ('true' === $atts['debug']);
	} else {
		$debug = false;
	}

	foreach ($taxonomies as $taxonomy) 
	{
		if ( array_key_exists( $taxonomy, $atts ) )
		{
			if ($debug)
			{
				$results = $results.'Posts by taxon: '.$taxonomy.' = '.$atts[$taxonomy];
			}
			$tax_query = array(
				'taxonomy' => $taxonomy,
				'field' => 'name',
				'terms' => $atts[$taxonomy]
			);
			$query['tax_query'][] = $tax_query;
		}
	}

	if ( array_key_exists( 'type', $atts ) )
	{
		$query['post_type'] = $atts['type'];
	} else {
		$query['post_type'] = get_post_types();
	}		

	if ( array_key_exists( 'orderby', $atts ) )
	{
		$query['orderby'] = $atts['orderby'];
		if ( array_key_exists( 'order', $atts ) )
		{
			$query['order'] = strtoupper( $atts['order'] );
		} else {
			$query['order'] = 'ASC';
		}
	}		


	$posts_array = get_posts( $query );

	$results = $results.'</p><ul>';
	foreach ( $posts_array as $post ) 
	{
		$url = esc_url( get_permalink( $post->ID ) );
		$title = $post->post_title;
		$linkitem = '<li><a href="'.$url.'">'.$title.'</a></li>';
		$results = $results.$linkitem;
	}
	$results = $results.'</ul>';
	return $results;
}
add_shortcode( 'posts-by-taxon', 'posts_by_taxon' );

function macs_print_taxon( $taxonomy, $headword = NULL )
{
	$taxon = implode( ', ', wp_get_post_terms( get_the_ID(),
											$taxonomy, 
											array('fields'=>'names') )
					);
	if (NULL === $headword)
	{
		$headword = '<p><strong>'.ucfirst($taxonomy).': </strong>';
	} else {
		$headword = '<p><strong>'.$headword.': </strong>';
	}
	if ($taxon != '') 
	{
		echo $headword.$taxon.'.</p>';
	}
}
<file_sep><?php
/**
* Custom field functionality for student site
* Requires metabox plugin https://metabox.io
*/


/**
* Create custom post type for storing (links to) people's details
*/
add_action( 'init', 'macs_create_person_type' );
function macs_create_person_type() {
  register_post_type( 'person',
    array(
        'labels' => array(
        'name' => __( 'People' ),
        'singular_name' => __( 'Person' ),
		'add_new' => __( 'New person' ),
		'add_new_item' => __( 'Add new person' ),
		'edit_item' => __( 'Edit person' ),
		'view_item' => __( 'View person' )
      ),
      'public' => false,
      'has_archive' => false,
	  'exclude_from_search' => true,
	  'show_ui' => true,
      'rewrite' => array('slug' => 'person'),
      'supports' => array('title', 'revisions' ),
	  'menu_position' => 22,
	  'menu_icon' => 'dashicons-admin-users'
    )
  );
}

function wpb_change_person_title_text( $title ){
     $screen = get_current_screen();
     if  ( 'person' == $screen->post_type ) {
          $title = 'Name';
     }
     return $title;
}
add_filter( 'enter_title_here', 'wpb_change_person_title_text' );


/**
* Register meta box for person metadata
*/
add_filter( 'rwmb_meta_boxes', 'macs_person_meta_boxes' );
function macs_person_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array(
        'title'	     => 'Person metadata',
        'post_types' => 'person',
        'fields'     => array(
			array(
                'id'   => 'staffDirURL',
                'name' => 'Staff directory URL',
                'type' => 'url',
                'desc' => 'The URL for this person\'s page in the staff directory.'
            ),
			array(
                'id'   => 'photoURL',
                'name' => 'Photo URL',
                'type' => 'url',
                'desc' => 'The URL of the Profile Picture in the staff directory.'
            ),
		)
	);
    return $meta_boxes;
}


/**
* Helper functions for printing out metadata fields
*
**/

function macs_print_person_link( $person_id ) {
    $name = get_the_title( $person_id );
	$url  = esc_url( rwmb_meta( 'staffDirURL', array(), $person_id ) );
	$location =  implode(', ', wp_get_post_terms( $person_id, 
												'location', 
												array('fields' => 'names' ) 
												) );
	echo sprintf( '<a href="%s">%s</a> (%s)', $url, $name, $location);

}

function macs_print_person_img( $person_id ) {
    $imgref = esc_url( rwmb_meta( 'photoURL', array(), $person_id ) );
	if ($imgref != '') {
	    $name = get_the_title( $person_id );
		$url  = esc_url( rwmb_meta( 'staffDirURL', array(), $person_id ) ); 
		echo sprintf( '<a href="%s"><img src="%s" alt="%s" class="MACSpersonimg"
                                         style="width:135px;height:180px;"/></a>', 
					$url, $imgref, $name );
#Quick fix. Yes, the style info should go in the stylesheet
	}
}
<file_sep><?php
/**
 * The template used for displaying course info for all course types
 * Called from single-*-course.php
 *
 * @package ThemeGrill
 * @subpackage Accelerate
 * @subpackage macs-student
 * @since macs-student 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php do_action( 'accelerate_before_post_content' ); ?>

	<header class="entry-header">
		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
	</header>

	<div class="entry-content clearfix">
		<?php macs_print_course_leader_img(); ?>
		<?php macs_print_course_leader(); ?>
		<?php macs_print_course_aims(); ?>
		<?php macs_print_course_summary(); ?>
		<h2>Detailed Information</h2>
		<?php macs_print_course_prereqs(); ?>
		<?php macs_print_linked_courses(); ?>
		<?php macs_print_taxon( 'location' ); ?>
		<?php macs_print_taxon( 'semester' ); ?>
		<?php macs_print_course_details(); ?> 
		<?php macs_print_course_contact_hours(); ?>
		<?php macs_print_taxon( 'level', 'SCQF Level' ); ?>
		<?php macs_print_course_scqf_credits(); ?>
		<?php macs_print_boiler_text(); ?>
	</div>

	<?php do_action( 'accelerate_after_post_content' ); ?>
</article>
<file_sep><?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . 
'/style.css' );
}


@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M' );
@ini_set( 'max_execution_time', '300' );


add_action( 'widgets_init', 'my_register_sidebars' );

function macs_print_html_metadata($field_id, $lead_text)
{

	if ( rwmb_meta( $field_id ) )
	{
// to do: write style to support:
//	echo '<h3 class="subhead">'.$lead_text.'</h3> '.rwmb_meta( $field_id );
		echo '<p><strong>'.$lead_text.'</strong></p>'.rwmb_meta( $field_id );
	}
}

include 'macs-course-type.php';
include 'macs-person-type.php';
include 'macs-taxonomies.php';

function my_register_sidebars() {
 
    register_sidebar(array(
        'id' => 'ams',
        'name' => __('AMS_Sidebar'),
        'description' => __('Sidebar used on AMS pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
    register_sidebar(array(
        'id' => 'maths',
        'name' => __('Maths_Sidebar'),
        'description' => __('Sidebar used on Maths pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
    register_sidebar(array(
        'id' => 'cs',
        'name' => __('CS_Sidebar'),
        'description' => __('Sidebar used on CS Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
	register_sidebar(array(
        'id' => 'edinburgh',
        'name' => __('Edinburgh_Sidebar'),
        'description' => __('Sidebar used on Edinburgh Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
	register_sidebar(array(
        'id' => 'dubai',
        'name' => __('Dubai_Sidebar'),
        'description' => __('Sidebar used on Dubai Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
	register_sidebar(array(
        'id' => 'malaysia',
        'name' => __('Malaysia_Sidebar'),
        'description' => __('Sidebar used on Malaysia Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
	register_sidebar(array(
        'id' => 'alp',
        'name' => __('ALP_Sidebar'),
        'description' => __('Sidebar used on ALP Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
	register_sidebar(array(
        'id' => 'pgr',
        'name' => __('PGR_Sidebar'),
        'description' => __('Sidebar used on PGR Pages'),
		'before_widget' 	=> '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  	=> '</aside>',
		'before_title'  	=> '<h3 class="widget-title"><span>',
		'after_title'   	=> '</span></h3>'
    ));
}


?>
<file_sep><?php
/**
* Functions to support the Course type in MACS Students WP site.
* Requires metabox plugin https://metabox.io
*/

/**
* Create custom post types for courses per discipline
*/
add_action( 'init', 'macs_create_course_type' );
function macs_create_course_type() {
  register_post_type( 'cs-course',
    array(
        'labels' => array(
        	'name' => __( 'CS Courses' ),
        	'singular_name' => __( 'CS Course' ),
		'add_new' => __( 'New CS course' ),
		'add_new_item' => __( 'Add new CS course' ),
		'edit_item' => __( 'Edit CS course data' ),
		'view_item' => __( 'View CS course data' )
      		),
      	'public' => true,
      	'has_archive' => false,
      	'rewrite' => array('slug' => 'cs/courses', 'with_front' => false),
      	'supports' => array('title', 'revisions' ),
	'menu_position' => 20,
	'capability_type' => 'page',
	'hierachical' => true,
	'taxonomies'=> array(),
	'menu_position' => 20,
	'menu_icon' => 'dashicons-admin-page'
    )
  );
  register_post_type( 'maths-course',
    array(
        'labels' => array(
        	'name' => __( 'Maths Courses' ),
        	'singular_name' => __( 'Maths Course' ),
		'add_new' => __( 'New Maths course' ),
		'add_new_item' => __( 'Add new Maths course' ),
		'edit_item' => __( 'Edit Maths course data' ),
		'view_item' => __( 'View Maths course data' )
      		),
      	'public' => true,
      	'has_archive' => false,
      	'rewrite' => array('slug' => 'maths/courses'),
      	'supports' => array('title', 'revisions' ),
	'menu_position' => 20,
	'capability_type' => 'page',
	'hierachical' => true,
	'taxonomies'=> array(),
	'menu_position' => 20,
	'menu_icon' => 'dashicons-admin-page'
    )
  );
  register_post_type( 'ams-course',
    array(
        'labels' => array(
        	'name' => __( 'AMS Courses' ),
        	'singular_name' => __( 'AMS Course' ),
		'add_new' => __( 'New AMS course' ),
		'add_new_item' => __( 'Add new AMS course' ),
		'edit_item' => __( 'Edit AMS course data' ),
		'view_item' => __( 'View AMS course data' )
      		),
      	'public' => true,
      	'has_archive' => false,
      	'rewrite' => array('slug' => 'ams/courses'),
      	'supports' => array('title', 'revisions' ),
	'menu_position' => 20,
	'capability_type' => 'page',
	'hierachical' => true,
	'taxonomies'=> array(),
	'menu_position' => 20,
	'menu_icon' => 'dashicons-admin-page'
    )
  );
}

function macs_rewrite_flush() {
	macs_create_course_type();
	flush_rewrite_rules();
}
add_action('after_switch_theme', 'macs_rewrite_flush');

function wpb_change_course_title_text( $title ){
     $screen = get_current_screen();
     if  ( 'course' == $screen->post_type ) {
          $title = 'Course code and title';
     }
     return $title;
}
add_filter( 'enter_title_here', 'wpb_change_course_title_text' );


add_filter( 'rwmb_meta_boxes', 'macs_courses_meta_boxes' );
function macs_courses_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array(
        'title'	     => 'Basic course metadata',
        'post_types' => array('cs-course', 'ams-course', 'maths-course'),
        'fields'     => array(
            array(
                'id'   => 'courseCode',
                'name' => 'Course Code',
                'type' => 'text',
                'size' => '5',
                'desc' => 'The course code, e.g. F29EG'
            ),
			array(
                'id'   => 'courseLeader',
                'name' => 'Course co-ordinator',
                'type' => 'post',
				'post_type' => 'person',
				'field_type'  => 'select_advanced',
				'placeholder' => __( 'Select a person'),
				'query_args'  => array(
					'post_status'    => 'publish',
					'posts_per_page' => - 1,
				),	
				'clone' => 'true',
                'desc' => 'Link to the entry for the course coordinator'
            ),
			array(
                'id'   => 'courseSCQFcredits',
                'name' => 'Course SCQF Credits',
                'type' => 'text',
				'size' => '3',
                'desc' => 'The SCQF Level, e.g. 15'
            ),
			array(
                'id'   => 'courseElective',
                'name' => 'Course Elective',
                'type' => 'radio',
				'options' => array('true' => 'yes', 'false' => 'no'),
                'desc' => 'Is this an Elective Course, Yes or No'
            ),
			array(
                'id'   => 'coursePrerequisiteCourses',
                'name' => 'Prerequisite Courses',
                'type' => 'post',
		        'post_type' => array('cs-course', 'ams-course', 'maths-course'),
				'field_type'  => 'select_advanced',
				'placeholder' => __( 'Select a course'),
				'query_args'  => array(
					'post_status'    => 'publish',
					'posts_per_page' => - 1,
				),	
				'clone' => 'true',
                'desc' => 'Course Pre-requisites, e.g F27EG'
            ),
			array(
                'id'   => 'coursePrerequisitesText',
                'name' => 'Other Course Prerequisites',
                'type' => 'text',
                'desc' => 'Or equivalent for F27EG'
            ),
			array(
                'id'   => 'courseLinkedCourses',
                'name' => 'Course Linked Courses',
                'type' => 'post',
		        'post_type' => array('cs-course', 'ams-course', 'maths-course'),
				'field_type'  => 'select_advanced',
				'placeholder' => __( 'Select a course'),
				'query_args'  => array(
					'post_status'    => 'publish',
					'posts_per_page' => - 1,
				),	
				'clone' => 'true',
                'desc' => 'Linked Course e.g F27EF'
            ),
			array(
                'id'   => 'courseLinkedCoursesText',
                'name' => 'Linked Courses notes',
                'type' => 'text',
                'desc' => 'e.g. synoptic courses'
            ),
			array(
                'id'   => 'courseAims',
                'name' => 'Course Aims',
                'type' => 'wysiwyg',
                'desc' => 'The course Aims',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseSyllabus',
                'name' => 'Course Syllabus',
                'type' => 'wysiwyg',
                'desc' => 'The course Syllabus',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseLOSM',
                'name' => 'Course Learning Outcomes: Subject Mastery',
                'type' => 'wysiwyg',
                'desc' => 'The course Learning Outcomes: Subject Mastery',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseLOPA',
                'name' => 'Course Learning Outcomes: Personal Abilities',
                'type' => 'wysiwyg',
                'desc' => 'The course Learning Outcomes: Personal Abilities',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseAssessmentMethods',
                'name' => 'Course Assessment Methods',
                'type' => 'wysiwyg',
                'desc' => 'The course Assessment (and Reassessment Methods), e.g Assessment: Examination: (weighting 70%) Coursework (weighting 30%); Re-assessment: Examination: (weighting 100%)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
        ),
    );

    $meta_boxes[] = array(
        'title'	     => 'Extended course metadata (Maths & AMS)',
        'post_types' => array('ams-course', 'maths-course'),
        'fields'     => array(
			array(
                'id'   => 'courseSummary',
                'name' => 'Course Summary',
                'type' => 'wysiwyg',
                'desc' => 'Provides a summary field (used by Maths and AMS)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseDetailedAims',
                'name' => 'Course Detailed Aims',
                'type' => 'wysiwyg',
                'desc' => 'Provides a more detailed aims field (used by Maths and AMS)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseDetailedSyllabus',
                'name' => 'Course Detailed Syllabus',
                'type' => 'wysiwyg',
                'desc' => 'Provides a more detailed syllabus field (used by Maths and AMS)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseReadingList',
                'name' => 'Course Reading List',
                'type' => 'wysiwyg',
                'desc' => 'Provides a reading list field (used by Maths and AMS)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseDetailedLOs',
                'name' => 'Course Detailed Learning Outcomes',
                'type' => 'wysiwyg',
                'desc' => 'Provides a more detailed Learning Outcomes field 
				           (used by Maths and AMS)',
				'options' => array(
					'media_buttons' => false,
					'textarea_rows' => 6
				)
            ),
			array(
                'id'   => 'courseContactHours',
                'name' => 'Course Contact Hours',
                'type' => 'text',
                'desc' => 'The contact Hours for the course, (used by Maths)'
            ),
			array(
                'id'   => 'suppressPDFLink',
                'name' => 'Suppres pdf link',
                'type' => 'checkbox',
                'desc' => 'Do not automatically generate a link to a pdf with 
				           more information about course (check this only if 
				           you know such a file does not exist).',
				'std'  => 0
            )
		)
	);
	
    return $meta_boxes;
}


/**
* Helper functions for printing out metadata fields
*
**/
function macs_print_course_code( )
{
	if ( rwmb_meta( 'courseCode' ) )
	{
		echo '<p><strong>Course code:</strong> '.rwmb_meta( 'courseCode' ).'</p>';
	}
}

function macs_print_course_link( $course_id )
{
    $name = get_the_title( $course_id );
	$url  = esc_url( get_permalink( $course_id ) ); 
	echo sprintf( '<a href="%s">%s</a>', $url, $name );
}


function macs_print_course_leader( )
{
	if ( implode( '', rwmb_meta( 'courseLeader' ) ) )
	{
		echo '<p><strong>Course co-ordinator(s):</strong> ';
        $people = rwmb_meta( 'courseLeader' );
        foreach ( $people as $person )
		{
			macs_print_person_link( $person );
			if ($person === end( $people) )
			{ 
			echo '. '; 
			} else {
		  	echo ', ';  
			}
		}
		echo '</p>';
	}

}

function macs_print_course_leader_img( )
{
	if ( implode( '', rwmb_meta( 'courseLeader' ) ) )
	{
		echo '<div class="alignright" >';
        $people = rwmb_meta( 'courseLeader' );
        foreach ( $people as $person )
		{
			macs_print_person_img( $person );
		}
		echo '</div>';
	}

}

function macs_print_course_prereqs( )
{
	if ( implode( '', rwmb_meta( 'coursePrerequisiteCourses' ) ) )
	{
		echo '<p><strong>Pre-requisite course(s):</strong> ';
        $prereq_courses = rwmb_meta( 'coursePrerequisiteCourses' );
        foreach ( $prereq_courses as $prereq )
		{
			macs_print_course_link( $prereq );
			if ($prereq === end( $prereq_courses ) )
			{ 
			echo ' '; 
			} else {
		  	echo ' &amp; ';  
			}
		}
		if ( rwmb_meta( 'coursePrerequisitesText' ) )
		{
			echo ' '.rwmb_meta( 'coursePrerequisitesText' );
		}
		echo '.</p>';
	}
	elseif ( rwmb_meta( 'coursePrerequisitesText' ) )
	{
		echo '<p><strong>Pre-requisites:</strong> './/
			rwmb_meta( 'coursePrerequisitesText' ).'.</p>';
	}
	else 
	{
		echo '<p><strong>Pre-requisites:</strong> none.</p>';
	}
}

function macs_print_linked_courses( )
{
	if ( implode( '', rwmb_meta( 'courseLinkedCourses' ) ) )
	{
		echo '<p><strong>Linked course(s):</strong> ';
        $linked_courses = rwmb_meta( 'courseLinkedCourses' );
        foreach ( $linked_courses as $linked_course )
		{
			macs_print_course_link( $linked_course );
			if ($linked_course === end( $linked_courses ) )
			{ 
			echo ' ';
			} else {
		  	echo ' &amp; ';  
			}
		}
		if ( rwmb_meta( 'courseLinkedCoursesText' ) )
		{
			echo ' '.rwmb_meta( 'courseLinkedCoursesText' );
		}
		echo '.</p>';
	}
	elseif ( rwmb_meta( 'courseLinkedCoursesText' ) )
	{
		echo '<p><strong>Linked course(s):</strong> './/
			rwmb_meta( 'courseLinkedCoursesText' ).'.</p>';
	}
}

function macs_print_course_summary( )
{
	if ( rwmb_meta( 'courseSummary' ) != '' ) {
	 	macs_print_html_metadata('courseSummary', 'Summary:');
	}
}

function macs_print_course_aims( )
{
	if ( rwmb_meta( 'courseDetailedAims' ) != '' ) {
	 	macs_print_html_metadata('courseDetailedAims', 'Aims:');
	} else {
	 	macs_print_html_metadata('courseAims', 'Aims:');
	}

}

function print_html_course_info( )
{
	if ( rwmb_meta( 'courseDetailedSyllabus' ) != '' ) {
	 	macs_print_html_metadata('courseDetailedSyllabus', 'Syllabus:');
	} else {
	 	macs_print_html_metadata('courseSyllabus', 'Syllabus:');
	}
	if ( rwmb_meta( 'courseDetailedLOs' ) != '' ) {
	 	macs_print_html_metadata('courseDetailedLOs', 'Learning Outcomes:');
	} else {
	 	macs_print_html_metadata('courseLOSM', 'Learning Outcomes: Subject Mastery');
	 	macs_print_html_metadata('courseLOPA', 'Learning Outcomes: Personal Abilities');	
	}
	if ( rwmb_meta( 'courseReadingList' ) != '' ) {
	 	macs_print_html_metadata('courseReadingList', 'Reading list:');
	}

 	macs_print_html_metadata('courseAssessmentMethods', 'Assessment Methods:');
}

function print_link_to_course_info_pdf( )
{
	$base_url = 'http://www.ma.hw.ac.uk/maths/courseinfo/';
	$course_code = rwmb_meta( 'courseCode' );
	$semester = wp_get_post_terms( get_the_ID(),
								    'semester', 
								    array('fields'=>'names') );
	echo '<p><strong>Further information:</strong> ';
	foreach ( $semester as $s ) 
	{
		$pdf_url = $base_url.$course_code.$s.'.pdf';
		echo '<a href="'.$pdf_url.'">';
		echo 'Syllabus, Number of lectures, Assessment, Learning Outcomes';
		echo '</a>.<br />';
	}
	echo '</p>';
}


function macs_print_course_details( )
{
	$post_type = get_post_type();
	if  ( 'maths-course' == $post_type )
	{ 
		if (   (0 == rwmb_meta( 'suppressPDFLink') )
            && ('' ==  rwmb_meta( 'courseDetailedSyllabus' ) ) 
            && ('' ==  rwmb_meta( 'courseDetailedLOs' ) )
			)
		{
			print_link_to_course_info_pdf( ); 
		} else {
			print_html_course_info( );
		}
	} else {
		print_html_course_info( );
	}
}

function macs_print_course_contact_hours( )
{
	if ( rwmb_meta( 'courseContactHours' ) != '' ) {
		echo '<p><strong>Contact Hours:</strong> './/
			rwmb_meta( 'courseContactHours' ).'.</p>';
	}
}

function macs_print_course_scqf_credits( )
{
	if ( rwmb_meta( 'courseSCQFcredits' ) != '' ) {
		echo '<p><strong>Credits:</strong> './/
			rwmb_meta( 'courseSCQFcredits' ).'.</p>';
	}
}

function macs_print_boiler_text( )
{
	if ('ams-course' == get_post_type() )
	{
		echo '<h2>Other Information</h2>';
		echo '<p><strong>Help:</strong> If you have any problems or questions
              regarding the course, you are encouraged to contact the lecturer</p>';
		echo '<p><strong>VISION:</strong> further information and course materials
              are available on <a href="http://vision.hw.ac.uk">VISION</a></p>';
	} 
}
<file_sep><?php
/**
 * The Sidebar containing the main widget areas.
 *
 * @package ThemeGrill
 * @subpackage Accelerate
 * @since Accelerate 1.0
 */
?>

<div id="secondary">
	<?php do_action( 'accelerate_before_sidebar' ); ?>
		<?php 
			$post_type = get_post_type();
			if( is_page_template( 'page-templates/contact.php' ) ) {
				$sidebar = 'accelerate_contact_page_sidebar';
				}
				elseif( is_page_template( 'page-templates/ams.php' )  
				|| ( $post_type == 'ams-course' ) ) {
				$sidebar = 'ams';
				}
				elseif( is_page_template( 'page-templates/maths.php' )  
				|| ( $post_type == 'maths-course' ) ) {
				$sidebar = 'maths';
				}
				elseif( is_page_template( 'page-templates/cs.php' ) 
				|| ( $post_type == 'cs-course' ) ) {
				$sidebar = 'cs';
				}
				elseif( is_page_template( 'page-templates/edinburgh.php' ) ) {
				$sidebar = 'edinburgh';
				}
				elseif( is_page_template( 'page-templates/dubai.php' ) ) {
				$sidebar = 'dubai';
				}
				elseif( is_page_template( 'page-templates/malaysia.php' ) ) {
				$sidebar = 'malaysia';
				}
				elseif( is_page_template( 'page-templates/alp.php' ) ) {
				$sidebar = 'alp';
				}
				elseif( is_page_template( 'page-templates/pgr.php' ) ) {
				$sidebar = 'pgr';
				}
			else {
				$sidebar = 'accelerate_right_sidebar';
			}
		?>

		<?php if ( ! dynamic_sidebar( $sidebar ) ) : ?>

			<aside id="search" class="widget widget_search">
				<?php get_search_form(); ?>
			</aside>

			<aside id="archives" class="widget">
				<h3 class="widget-title"><span><?php _e( 'Archives', 'accelerate' ); ?></span></h3>
				<ul>
					<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
				</ul>
			</aside>

			<aside id="meta" class="widget">
				<h3 class="widget-title"><span><?php _e( 'Meta', 'accelerate' ); ?></span></h3>
				<ul>
					<?php wp_register(); ?>
					<li><?php wp_loginout(); ?></li>
					<?php wp_meta(); ?>
				</ul>
			</aside>

		<?php endif; ?>
	<?php do_action( 'accelerate_after_sidebar' ); ?>
</div>
<file_sep><?php
/**
 * The template used for displaying course info for all course types
 * Called from single-*-course.php
 *
 * @package ThemeGrill
 * @subpackage Accelerate
 * @subpackage macs-student
 * @since macs-student 1.0
 */
?>


<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php do_action( 'accelerate_before_post_content' ); ?>
	<header class="entry-header">
		<h2 class="entry-title">
			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"><?php the_title(); ?></a>
		</h2>
	</header>

	<div class="entry-content clearfix">
		<?php macs_print_course_leader(); ?>
		<?php macs_print_course_aims(); ?>
	</div>

	<?php do_action( 'accelerate_after_post_content' ); ?>
</article>
