<?php
$keyMaster= $_SESSION['project_id'];

// unset($_SESSION['project_id']); // Not delete

$trunk1="<link rel=\"stylesheet\" type=\"text/css\" href=\"jsgantt/jsgantt.css\" />
<script language=\"javascript\" src=\"jsgantt/jsgantt.js\"></script>
<div style=\"position:relative\" class=\"gantt\" id=\"GanttChartDIV\"></div>
<script>";

if ($_SESSION['language'] == "Spanish") {
$trunk1 .= "
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'week');
if (g.getDivId() != null) {
  g.setCaptionType('Complete');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
  g.setQuarterColWidth(36);
	g.setShowDur(0); // Show/Hide Duration (0/1)
	g.setShowComp(0); // Show/Hide % Compl. (0/1)
	g.setDateInputFormat('yyyy-mm-dd');  // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')
	g.setDateTaskTableDisplayFormat('dd/mm/yyyy'); // Set format to display dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')
  g.setDateTaskDisplayFormat('day dd month yyyy'); // Shown in tool tip box
  g.setDayMajorDateDisplayFormat('mon yyyy - Week ww') // Set format to display dates in the \"Major\" header of the \"Day\" view
  g.setWeekMinorDateDisplayFormat('dd mon') // Set format to display dates in the \"Minor\" header of the \"Week\" view
  g.setShowTaskInfoLink(1); // Show link in tool tip (0/1)
  g.setShowEndWeekDate(0); // Show/Hide the date for the last day of the week in header for daily view (1/0)
  g.setUseSingleCell(10000); // Set the threshold at which we will only use one cell per table row (0 disables).  Helps with rendering performance for large charts.
  g.setFormatArr('Day', 'Week', 'Month', 'Quarter'); // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers

// Language
  g.addLang('es',{
'january': 'Enero',
'february': 'Febrero',
'march': 'Marzo',
'april': 'Abril',
'maylong': 'Mayo',
'june': 'Junio',
'july': 'Julio',
'august': 'Agosto',
'september': 'Septiembre',
'october':'Octubre',
'november':'Noviembre',
'december':'Diciembre',
'jan':'Ene',
'feb':'Feb',
'mar':'Mar',
'apr':'Abr',
'may':'May',
'jun':'Jun',
'jul':'Jul',
'aug':'Ago',
'sep':'Sep',
'oct':'Oct',
'nov':'Nov',
'dec':'Dic',

'sunday':'Domingo',
'monday':'Lunes',
'tuesday':'Martes',
'wednesday':'Miércoles',
'thursday':'Jueves',
'friday':'Viernes',
'saturday':'Sábado',
'sun':'	Dom',
'mon':'	Lun',
'tue':'	Mar',
'wed':'	Mie',
'thu':'	Jue',
'fri':'	Vie',
'sat':'	Sab',
'resource':'Recurso',
'duration':'Duración',
'comp':'% Compl.',
'completion':'Terminado',
'startdate':'Inicio',
'enddate':'Fin',
'moreinfo':'+información',
'notes':'Notas',

'format':'Formato',
'hour':'Hora',
'day':'Dia',
'week':'Semana',
'month':'Mes',
'quarter':'Trimestre',
'hours':'Horas',
'days':'Días',
'weeks':'Semanas',
'months':'Meses',
'quarters':'Trimestres',
'hr':'Hr',
'dy':'D',
'wk':'Sem',
'mth':'Mes',
'qtr':'Trim',
'hrs':'Hrs',
'dys':'Dias',
'wks':'Sems',
'mths':'Meses',
'qtrs':'Trims'});

  g.setLang('es');
  // Parameters(pID, pName,pStart,pEnd,pStyle,pLink (unused), pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt)
";
} else {
$trunk1 .= "
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'week');
if (g.getDivId() != null) {
  g.setCaptionType('Complete');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
  g.setQuarterColWidth(36);
	g.setShowDur(0); // Show/Hide Duration (0/1)
	g.setShowComp(0); // Show/Hide % Compl. (0/1)
	g.setDateInputFormat('yyyy-mm-dd');  // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')
	g.setDateTaskTableDisplayFormat('mm.dd.yyyy'); // Set format to display dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')

  // g.setDateTaskDisplayFormat('day dd month yyyy'); // Shown in tool tip box
  // g.setDayMajorDateDisplayFormat('yyyy mon- Week ww') // Set format to display dates in the \"Major\" header of the \"Day\" view
  // g.setWeekMinorDateDisplayFormat('mon dd') // Set format to display dates in the \"Minor\" header of the \"Week\" view
  g.setShowTaskInfoLink(1); // Show link in tool tip (0/1)
  g.setShowEndWeekDate(0); // Show/Hide the date for the last day of the week in header for daily view (1/0)
  g.setUseSingleCell(10000); // Set the threshold at which we will only use one cell per table row (0 disables).  Helps with rendering performance for large charts.
  g.setFormatArr('Day', 'Week', 'Month', 'Quarter'); // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers
  // Parameters(pID, pName,pStart,pEnd,pStyle,pLink (unused), pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt)
";
		}
;

$trunk2='';
// Read Task the Project
$sql="SELECT
t.`task_id`,
t.`name`,
DATE_FORMAT(t.`start_date`,'%Y-%m-%d') `start_date`,
DATE_FORMAT(t.`end_date`,'%Y-%m-%d') `end_date`,
t.`dynamic`,
t.`related_url`,
t.`milestone`,
t.`percent_complete`,
ifnull(t.`parent`,0) parent,
ifnull(t.`dependent`,0) dependent,
t.`description`,
ifnull(u.login,'') creator
FROM tasks t
inner join users u on (t.creator=u.user_id)
WHERE t.`projects_project_id` = $keyMaster
ORDER BY t.`order`";
$resql = DB::Query($sql);

 while ($row = $resql->fetchAssoc()) {
		$task_id = $row['task_id'];
		$task_name = addslashes($row['name']);
		$task_start_date = $row['start_date'];
		$task_end_date = $row['end_date'];
		$task_color = 'gtaskblue';
		if ($row['dynamic'] == 1){
				$task_color = 'ggroupblack';
				}
		$task_link = $row['related_url'];
		$task_mile = $row['milestone'];
		$task_resource = $row['creator'];
		$task_completion= $row['percent_complete'];
		$task_group = $row['dynamic'];
		$task_parent = $row['parent'];
		$task_open = '0';
		$task_depend = $row['dependent'];
		$task_caption = '';
		$task_description = $row['description'];
		$task_note = addslashes(
						str_replace(hex2bin('0a'),'',
						str_replace(hex2bin('0d'),'',
						str_replace(PHP_EOL,'<br />',$task_description)
						)
						)
						);

		$trunk2.="g.AddTaskItem(new JSGantt.TaskItem(
		";
		$trunk2.="$task_id,'$task_name','$task_start_date','$task_end_date','$task_color','$task_link',$task_mile,'$task_resource',$task_completion,$task_group,$task_parent,$task_open,'$task_depend','$task_caption','$task_note',g));
		";
    }
$trunk3="
    g.Draw();	
    g.DrawDependencies();


  }
  else
  {
    alert(\"not defined\");
  }

</script>";
$value=$trunk1.$trunk2.$trunk3;
echo $value;

?>