<?php
$daySize = "100";
require "View/Planning_view.inc.php";
class CalendarFactoryView extends CalendarFactory {
function & newTask($arguments) {
// Create the object
$object = & parent::newTask($arguments);
// Create the associated view
new XPCalTaskView($object);
CalendarFactory::initItem($object);
return $object;
}
function & newStory($arguments) {
// Create the object
$object = & parent::newStory($arguments);
// Create the associated view
new XPCalStoryView($object);
CalendarFactory::initItem($object);
return $object;
}
function & newIteration($arguments) {
// Create the object
$object = & parent::newIteration($arguments);
// Create the associated view
new XPCalIterationView($object);
CalendarFactory::initItem($object);
return $object;
}
function & newCalDay($arguments) {
// Create the object
$object = & parent::newCalDay($arguments);
// Create the associated view
new XPCalDayView($object);
return $object;
}
function & newXPCalendar($arguments) {
// Create the object
$object = & parent::newXPCalendar($arguments);
// Create the associated view
new XPCalendarView($object);
return $object;
}
}
$GLOBALS["gPlanningFactory"] = & new CalendarFactoryView();
// *********************************************************************
// Class XPCalendarView
// *********************************************************************
class XPCalendarView extends PlanningView {
var $availableColors;
function XPCalendarView(& $item) {
parent::XPItemView($item);
$this->availableColors =
array(
"#c8d9ea",
"#f9cf91",
"#ffdec8",
"#a0d0f4",
"#9fdebf",
"#c5b4e6",
"#ffc2c8",
"#f4f4c2",
"#b5d0be",
"#ccf4f8"
);
}
function displayChoosePrintOptions() {
$this->setPrint();
displayPrintParamFormStart(false);
$this->displayBasicOptions();
?>
<br/>
<br/>
<table>
<tr>
<td>
<?php
$this->displaySpecificOptions();
?>
</td>
</tr>
</table>
<?php
displayPrintParamFormEnd();
}
function displaySpecificOptions() {
global $XP_WEEK_FORMAT;
$calendarTypes = & new HTMLSelect(XP_CALENDAR_CAL_TYPE, "xpcalChangeType(this);", "planningOptionsSelect");
$calendarTypes->add(new HTMLSelectOption(
CALENDAR_MONTH,
getLang("month"),
$this->item->type == CALENDAR_MONTH
));
$calendarTypes->add(new HTMLSelectOption(
CALENDAR_WEEK,
getLang("week"),
$this->item->type == CALENDAR_WEEK
));
$calendarTypes->add(new HTMLSelectOption(
CALENDAR_ITERATION,
getLang("type_iteration"),
$this->item->type == CALENDAR_ITERATION
));
$calendarTypes->add(new HTMLSelectOption(
CALENDAR_DATES,
getLang("specific_dates"),
$this->item->type == CALENDAR_DATES
));
//displayDivStart("xpcalOptions");
// Show the select HTML element
$calendarTypes->display();
?>
</td>
<td class="planningOptionsSep">
<?php
displayDivStart("calOptionSelect");
// The hidden input that will be updated by calendar
displaySimpleInputHidden(XP_CALENDAR_CAL_DATE, date("Y-m-d", $this->item->theTime));
// We allow for all dates to be chosen
$workingPace = "";
for ($i=0; $i < sizeOf($XP_WEEK_FORMAT); $i ++) {
$dayToCheck = $XP_WEEK_FORMAT[$i];
$workingPace .= "|$dayToCheck|";
}
displaySimpleInputHidden("wp", $workingPace);
// Display specific divs
foreach ($calendarTypes->options as $calendarType) {
displayDivStart("inv", "period_".$calendarType->value);
switch($calendarType->value) {
case CALENDAR_MONTH:
?>
<button class="less" type="button" title="<" onclick="xpcalAdd(this, 'month', false);"> </button>
<input class="planningOptionsSelect" type="text" name="month" value="zoub" size="15" readonly="readonly"
onclick="popupCalendar(this.form.<?=XP_CALENDAR_CAL_DATE?>, 'xpcalUpdateDate(\'month\');', this);"/>
<button class="more" type="button" title=">" onclick="xpcalAdd(this, 'month', true);"> </button>
<?php
break;
case CALENDAR_WEEK:
?>
<button class="less" type="button" title="<" onclick="xpcalAdd(this, 'week', false);"> </button>
<input class="planningOptionsSelect" type="text" name="week" value="zoub" size="15" readonly="readonly"
onclick="popupCalendar(this.form.<?=XP_CALENDAR_CAL_DATE?>, 'xpcalUpdateDate(\'week\');', this);"/>
<button class="more" type="button" title=">" onclick="xpcalAdd(this, 'week', true);"> </button>
<?php
break;
case CALENDAR_ITERATION:
displayIterationSelect($this->item->iterationId, XP_CALENDAR_CAL_ITE_ID, "planningOptionsSelect");
break;
case CALENDAR_DATES:
list($startYear,$startMonth,$startDay) = explode("-",$this->item->calStart);
$startWeekDay = date("D",strtotime($this->item->calStart));
list($endYear,$endMonth,$endDay) = explode("-",$this->item->calEnd);
$endWeekDay = date("D",strtotime($this->item->calEnd));
echoSpan("calChooseDate", getLang("from"));
echo displayChooseCalDate(XP_CALENDAR_CAL_START, $startWeekDay, $startDay, $startMonth, $startYear);
echoSpan("calChooseDate", getLang("to"));
echo displayChooseCalDate(XP_CALENDAR_CAL_END, $endWeekDay, $endDay, $endMonth, $endYear);
break;
}
displayDivEnd();
}
displayDivEnd();
}
function displayJSVars() {
parent::displayJSVars();
?>
gWeekText = "<?=getLang("week")?>";
<?php
}
function display() {
global $daySize;
global $XP_WEEK_FORMAT;
global $gMaxIndex;
$totalSize = ($daySize + 1)* 7;
?>
<table class="xpCalendar" align="center" width="<?=$totalSize?>" cellpadding="0" cellspacing="1">
<tr>
<td colspan="8">
<h2>
<?php
switch($this->item->type) {
case CALENDAR_MONTH:
echo displayDateMonth(
date("m", $this->item->theTime),
date("Y", $this->item->theTime));
break;
case CALENDAR_WEEK:
echo date("Y", $this->item->theTime)." - ".
getLang("week")." ".
date("W", $this->item->periods[0][3]->time);
break;
case CALENDAR_ITERATION:
// Find the correct iteration
for ($j = 0; $j < sizeOf($this->item->multiIncludedItems["iteration"]); $j ++) {
$iteration = & $this->item->multiIncludedItems["iteration"][$j];
if ($iteration->id == $this->item->iterationId) {
break;
}
}
echo getLang("type_iteration")." ".$iteration->id;
echo " - ".$iteration->title;
if ($iteration->isCurrent) {
echo " [".getLang("curr_iteration")."]";
}
break;
case CALENDAR_DATES:
list($startYear,$startMonth,$startDay) = explode("-",$this->item->calStart);
$startWeekDay = date("D",strtotime($this->item->calStart));
list($endYear,$endMonth,$endDay) = explode("-",$this->item->calEnd);
$endWeekDay = date("D",strtotime($this->item->calEnd));
echo displayDate($startWeekDay, $startDay, $startMonth, $startYear);
echo " -> ";
echo displayDate($endWeekDay, $endDay, $endMonth, $endYear);
break;
}
?>
</h2>
<h3><?=$this->getFromMemberLegend()==""?" ":$this->getFromMemberLegend()?></h3>
</td>
</tr>
<tr>
<td><div class="weekDay"><?=getLang("week")?></div></td>
<?php
reset($XP_WEEK_FORMAT);
for($iDay = 0; $iDay < sizeof($XP_WEEK_FORMAT); $iDay ++) {
$weekDay = & $XP_WEEK_FORMAT[$iDay];
?>
<td width="<?=$daySize?>"><div class="weekDay" style="width: <?=$daySize?>px;"><?=getLang($weekDay)?></div></td>
<?php
}
?>
</tr>
<?php
reset($this->item->periods);
for($iPeriod = 0; $iPeriod < sizeof($this->item->periods); $iPeriod ++) {
$days = & $this->item->periods[$iPeriod];
// Display day dates
$this->displayPeriodHeader($days);
for ($iRow = 0; $iRow <= $gMaxIndex; $iRow ++) {
// For each row
$this->displayRow($iRow, $days);
}
}
?>
</table>
<?php
$this->displayHiddenTasks();
}
function displayRow(& $iRow, & $days) {
?>
<tr>
<td> </td>
<?php
$iDays = 0;
$size = sizeof($days);
while ($iDays < $size) {
$this->displayNoTaskCells($days, $iDays, $iRow);
$this->displayObjectCells($days, $iDays, $iRow);
}
?>
</tr>
<?php
}
function displayObjectCells($days, & $iDays, & $iRow) {
global $daySize;
$widthLeft = 20;
$size = sizeof($days);
$notInTaskColor = "#eeeeee";
$realSize = $size;
$lastDate = $days[$size - 1]->date;
if ($lastDate > $this->item->calEnd) {
$realSize -= (strtotime($lastDate) - strtotime($this->item->calEnd)) / ONEHOUR / 24;
}
while ($iDays < $size && ($day = & $days[$iDays])
&& isset($day->indexedObjects[$iRow])) {
$object = $day->indexedObjects[$iRow];
if (!isset($object->type)) {
$iDays++;
} elseif ($object->type == "task") {
$task = & $object;
$taskLength = (($task->endTime - $days[$iDays]->time) / ONEHOUR / 24) + 1;
$colspan = min($taskLength, ($realSize - $iDays));
if ($colspan > 0) {
$printText = true;
$extraTextStyle = "";
while($iDays < $realSize && ($day = & $days[$iDays])) {
$status = $task->dayStatus($day);
list(
$isFirstDay,
$isBegining,
$isLastDay,
$isFinished) = $this->item->getComplexStatus($day, $status);
$text = "";
$width = $daySize + 2;//100 / $colspan; //$daySize - 1;
$zoub = substr($task->id, -1);
$color = $this->availableColors[$zoub];
if ($status < ON_DAY_NOT_WORKING) {
break;
} else {
// Is ON
$style = "";
if ($status == ON_DAY_NOT_WORKING) {
$style = "notWorking";
$color = PlanningCardView::darkenColor($color);
//$width ++;
} elseif ($status >= ON_DAY_WORKING) {
$style = "working";
}
$extraStyle = "border-color: ".
getColorFromCompletion($task->theoryCompletion, $task->actualCompletion).";";
$textColor = "black";
if ($task->actualCompletion >= 100) {
$extraStyle = "border-color: #eeeeee;";
$textColor = "#aaaaaa";
} elseif ($task->theoryCompletion == 0 && $task->actualCompletion == 0) {
$extraTextStyle = "font-style: italic;";
//$textColor = "#777777";
}
if ($isBegining) {
$width --;
$style = $isFirstDay?"first":"notFirst";
$text = $isFirstDay?" ":"<<";
$extraStyle .= $isFirstDay?"":"border-left-color: $color;";
}
if ($isFinished) {
$width --;
if ($isFirstDay && $isLastDay) {
$style = "oneDay";
} else {
$style = $isLastDay?"last":"notLast";
}
$text = $isLastDay?" ":">>";
$extraStyle .= $isLastDay?"":"border-right-color: $color;";
}
if (($isFirstDay) && ($isLastDay)) {
$extraStyle .= "-moz-border-radius: 7px 7px 7px 7px;";
} else {
if ($isFirstDay) {
$extraStyle .= "-moz-border-radius: 7px 0 0 7px;";
}
if ($isLastDay) {
$extraStyle .= "-moz-border-radius: 0 7px 7px 0;";
}
}
if (!empty($task->iterationDeadlineTime) && $day->time > $task->iterationDeadlineTime) {
// We are after the iteration deadline!!
$style .= " afterIteration";
}
}
if ($printText) {
$printText = false;
$divWidth = ($colspan * $daySize) + (2 * ($colspan - 1) - 4);
$taskText = " ";
if ($isBegining) {
$taskText = forceNbSpaces("[".$task->id."] ".$task->title);
if (!$isFirstDay) {
$taskText = "...".$taskText;
}
if ($task->outOfTime > 0) {
$taskText = "<span class=\"notOnTime\">$taskText</span>";
}
}
$height = 14;
$statusEnd = $task->dayStatus($days[$realSize-1]);
$isLastLine = $days[$realSize-1]->date >= $this->item->calEnd
&& $statusEnd >= ON_DAY_NOT_WORKING
&& $statusEnd != ON_DAY_WORKING_LAST
&& $statusEnd != ON_DAY_WORKING_ONEDAY;
if ($isLastLine) {
$divWidth -= + 2;
$height *= 2;
}
$xDev = 0;
if ($iDays >= 3) {
// The task will be displayed to the left...
$xDev = $divWidth + 4 - 500;
}
?>
<!-- REMOVED FROM DIV onclick="onClickCalTask(<?=$task->id?>);" -->
<td <?=($colspan>1)?"colspan=\"$colspan\"":""?>><div style="height: 19px; overflow: hidden;">
<div id="calTask_<?=$task->id?>" <?=displayMouseOverCalTask1($task, $xDev)?> <?=displayMouseOutCalTask($task)?> class="calTaskText" style="color: <?=$textColor?>; width: <?=$divWidth?>px;<?=$extraTextStyle?>"><?=$taskText?></div>
<?php if ($isLastLine) { ?>
<div class="calToBeCont" style="color: <?=$textColor?>; left: <?=$divWidth?>px; width: <?=$widthLeft?>px;">...</div>
<?php } ?>
<table <?=displayMouseOverCalTask1($task, 2 + $xDev, 1)?> <?=displayMouseOutCalTask($task)?> class="" style="position: relative; left: 0px; top: -<?=$height?>px; z-index: 0; width: 100%;" cellpadding="0" cellspacing="0">
<tr>
<?php
}
?>
<td width="<?=$width?>" class="<?=$style?>" bgcolor="<?=$color?>" style="<?=$extraStyle?>"> </td>
<?php
$iDays++;
}
?>
</tr>
</table></div></td>
<?php
} else {
//echo "task ".$task->id." is corrupted : <br/>".$task->endTime."/".strtotime($task->endDate)."<ul><li>start: ".$task->startDate."</li><li>end: ".$task->endDate."</li></ul>";
$iDays++;
}
} elseif ($object->type == "iteration") {
$iteration = & $object;
$text = getLang("type_iteration")." ".$iteration->id;
$outOfDate = max($iteration->outOfDateStories, $iteration->outOfDateTasks);
if ($outOfDate > 0) {
$iteration->view->getWarningText($text, $outOfDate);
}
?>
<td title="<?=$iteration->title?>" rowspan="2" width="<?=$daySize?>" class="calDeadline"><?=$text?></td>
<?php
$iDays++;
}
}
}
function displayNoTaskCells(& $days, & $iDays, & $iRow) {
global $gMaxIndex;
$size = sizeof($days);
$notInTaskColor = "#eeeeee";
while (($iRow <= $gMaxIndex) && ($iDays < $size) && ($day = & $days[$iDays])
&& !isset($day->indexedObjects[$iRow])) {
$dayClass = "";
if ($day->date < $this->item->calStart
|| $day->date > $this->item->calEnd) {
$color = "white";
} else {
$color = $notInTaskColor;
$dayClass = "dayNoTask";
if ($day->isToday) {
$dayClass .= " today";
} elseif ($day->isHoliday) {
$dayClass .= " holiday";
}
}
?>
<td bgcolor="<?=$color?>" class="<?=$dayClass?>"> </td>
<?php
$iDays++;
}
}
function displayPeriodHeader($days) {
global $daySize;
reset($days);
$totalSize = $daySize * sizeof($days);
?>
<tr>
<td><div class="weekDay"><?=getLink("", date("W", $days[0]->time), $GLOBALS["gThisPage"]."?".XP_CALENDAR_CAL_TYPE."=".CALENDAR_WEEK."&".XP_CALENDAR_CAL_DATE."=".urlencode(displayDateFromTime($days[0]->time)))?>
</div></td>
<?php
for($iDay = 0; $iDay < sizeof($days); $iDay ++) {
$day = & $days[$iDay];
if ($day->date >= $this->item->calStart
&& $day->date <= $this->item->calEnd) {
$dayClass = "calDayHead";
if ($day->isToday) {
$dayClass .= " todayHead";
} elseif ($day->isHoliday) {
$dayClass .= " holidayHead";
}
switch($this->item->type) {
case CALENDAR_MONTH:
$dayText = date("j", $day->time);
break;
default:
$dayText = date("j", $day->time);
$dayText = displayDateNoYear(
date("d", $day->time),
date("m", $day->time));
break;
}
?>
<td class="<?=$dayClass?>"><?=$dayText?></td>
<?php
} else {
?>
<td> </td>
<?php
}
}
?>
</tr>
<?php
}
function displayHiddenTasks() {
for($iTask = 0; $iTask < sizeof($this->item->multiIncludedItems["task"]); $iTask ++) {
$task = & $this->item->multiIncludedItems["task"][$iTask];
$task->view->item = & $task;
?><div <?=displayMouseOverCalTask2($task)?> <?=displayMouseOutCalTask($task)?> class="<?=XP_INVISIBLE?>" style="z-index: 2;width: 500px;" id="calTask<?=$task->id?>"><?php
$task->view->display();
?></div><?php
}
}
}
// *********************************************************************
// Class XPCalIterationView
// *********************************************************************
class XPCalIterationView extends IterationView {
}
// *********************************************************************
// Class XPCalStoryView
// *********************************************************************
class XPCalStoryView extends StoryView {
}
// *********************************************************************
// Class XPCalTaskView
// *********************************************************************
class XPCalTaskView extends TaskView {
var $color;
function display() {
// @todo should be re-activated or replaced at some point?
//$this->displayChooseDate();
parent::display();
}
/**
* We don't want to have the check button for calendar
*/
function checkItemStart() {
}
function checkItemEnd() {
}
/*
function displayChooseDate($visibility = XP_VISIBLE) {
global $XP_WEEK_FORMAT;
$formName = $this->getFormName();
if ($this->item->isAllowedToUpdate()) {
displayDivStart("chooseDate");
$startDay = date("D", $this->item->startTime);
$dec = 0;
// Look for position of start date in week array
for ($i=0; $i < sizeOf($XP_WEEK_FORMAT); $i ++) {
$day = $XP_WEEK_FORMAT[$i];
if ($day == $startDay) {
// Current start date
break;
}
$value = $this->item->workingDays[$day];
if ($value == 1) {
// Working day
$dec ++;
}
}
$startPos = array_search($startDay, $XP_WEEK_FORMAT);
$chg = - $dec;
for ($i=0; $i < sizeOf($XP_WEEK_FORMAT); $i ++) {
$dayToCheck = $XP_WEEK_FORMAT[$i];
$value = $this->item->workingDays[$dayToCheck];
$extraStyle = "";
if ($value == 1) {
// Working day
$class = "wd";
$onclick = "calChgSD('$formName', $chg);";
$chg ++;
} else {
$class = "nWd";
$onclick = "doNothing();";
}
if ($dayToCheck == $startDay) {
$class .= " currentStart";
$onclick = "doNothing();";
}
?><span><a class="<?=$class?>" href="javascript:<?=$onclick?>;" title=""><?=getLang($dayToCheck)?></a></span><?php
}
displayDivEnd();
?><br/>
<?php
}
}
*/
}
// *********************************************************************
// Class XPCalDayView
// *********************************************************************
class XPCalDayView extends XPItemView {
}
// *********************************************************************
// OTHERS
// *********************************************************************
function displayMouseOutCalTask($task) {
?>onmouseout="mouseoutCal('<?=$task->id?>');"<?php
}
function displayMouseOverCalTask1($task, $plusx = 0, $plusy = 0) {
?>onmouseover="showCalTask('<?=$task->id?>', this, <?=$plusx?>, <?=$plusy?>);"<?php
}
function displayMouseOverCalTask2($task) {
?>onmouseover="refreshCalTask('<?=$task->id?>');"<?php
}
function displayChooseCalDate($name, $weekDay, $dateDay, $dateMonth, $dateYear) {
$value = displayDate($weekDay, $dateDay, $dateMonth, $dateYear);
?><button class="less" type="button" title="<" onclick="modDate(this, '<?=$name?>', -ONE_IDEAL_DAY);"> </button>
<input class="planningOptionsSelect" type="text" name="<?=$name?>" value="<?=$value?>" size="15" readonly="readonly" onclick="popupCalendar(this, 'doNothing();');"
onfocus="allowAllDates = true;" onblur="allowAllDates = false;"/>
<button class="more" type="button" title=">" onclick="modDate(this, '<?=$name?>', ONE_IDEAL_DAY);"> </button><?php
}
function getCookieCalendarParams() {
global $CALENDAR_TYPE;
// Calendar type
if (isSet($_COOKIE[XP_CALENDAR_CAL_TYPE])) {
$CALENDAR_TYPE = $_COOKIE[XP_CALENDAR_CAL_TYPE];
} else {
$CALENDAR_TYPE = CALENDAR_MONTH;
}
}
function setCookieCalendarParams() {
XPItemControler::setCookieIfGet(XP_CALENDAR_CAL_TYPE);
getPostedCalendarParams();
}
function getPostedCalendarParams() {
global $CALENDAR_TYPE;
if (isSet($_GET[XP_CALENDAR_CAL_TYPE])) {
$CALENDAR_TYPE = $_GET[XP_CALENDAR_CAL_TYPE];
}
}
$onLoadText .= "calendarOptionsInit();";
?>