<?php
include 'conector.php';
$js_materias = "var materiasPorDocente = {";
$TABLA_ASIG = mysql_query("SELECT pensum.teacher_id, pensum.subject_id as pensum_id, asignatura.subject_id as asig_id, asignatura.nombre as asig_nombre, pensum.nombre as pensum_nombre 
	FROM pensum, asignatura 
	WHERE pensum.asignatura_id = asignatura.subject_id 
	AND pensum.estado = 'A' 
	AND pensum.teacher_id IS NOT NULL
	ORDER BY pensum.teacher_id, asignatura.nombre");
$js_materias_data = array();
while($row = mysql_fetch_array($TABLA_ASIG)) {
	$current_teacher = $row['teacher_id'];
	if(!isset($js_materias_data[$current_teacher])) {
		$js_materias_data[$current_teacher] = array();
	}
	$js_materias_data[$current_teacher][] = "{id:'" . $row['pensum_id'] . "-" . $row['asig_id'] . "', nombre:'" . addslashes($row['asig_nombre']) . " - " . addslashes($row['pensum_nombre']) . "'}";
}
$first = true;
foreach($js_materias_data as $teacher => $materias) {
	if(!$first) $js_materias .= ", ";
	$js_materias .= "'" . $teacher . "': [" . implode(", ", $materias) . "]";
	$first = false;
}
$js_materias .= "};";
echo $js_materias;
?>