<?php
$pageRef='Calendar';
include('includes/header.php');
//Il giorno richiesto
$oDay = $_GET[day];
$oMonth = $_GET[month];
$oYear = $_GET[year];
$myDay = $_GET[day];
$myMonth = $_GET[month];
$myYear = $_GET[year];
//Se non sono riuscito a capire il giorno allora scelgo oggi e ricarico la pagina
if((!$myDay) || (!$myMonth) || (!$myYear)){
$reloadDay = date("d");
$reloadMonth = date("m");
$reloadYear = date("Y");
echo "<script>document.location.href='http://<?php echo $_SERVER['SERVER_ADDR']?>/Oreste/calendar.php?day=" . $reloadDay . "&month=" . $reloadMonth . "&year=" . $reloadYear . "';</script>";
}
//Leggo e utilizzo i dati passati nell'url
$aClient = $_GET[cid];
if(($aClient == '0') || ($aClient == '')){
$aName = $_GET[pro];
$aTelephone = $_GET[tel];
$aMobile = $_GET[cel];
$aOffice = $_GET[uff];
$aAddress = $_GET[add];
$anEmail = $_GET[mai];
}else{
$aName = '#';
$aTelephone = '#';
$aMobile = '#';
$aOffice = '#';
$aAddress = '#';
$anEmail = '#';
}
$aVet = $_GET[vet];
$aLocation = $_GET[loc];
$aDate = $_GET[dat];
$aHour = $_GET[hou];
$aPeriod = $_GET[dur];
$aComment = $_GET[comm];
$milliDate = mktime(0,0,0,$myMonth,$myDay,$myYear);
$dayOfTheWeek = date("D",$milliDate);
if($dayOfTheWeek == 'Mon'){
$myDay=$myDay;
}elseif($dayOfTheWeek == 'Tue'){
$myDay=$myDay-1;
}elseif($dayOfTheWeek == 'Wed'){
$myDay=$myDay-2;
}elseif($dayOfTheWeek == 'Thu'){
$myDay=$myDay-3;
}elseif($dayOfTheWeek == 'Fri'){
$myDay=$myDay-4;
}elseif($dayOfTheWeek == 'Sat'){
$myDay=$myDay-5;
}elseif($dayOfTheWeek == 'Sun'){
$myDay=$myDay-6;
}
//Monday
$startDay = date("d",mktime(0,0,0,$myMonth,$myDay,$myYear));
$startMonth = date("m",mktime(0,0,0,$myMonth,$myDay,$myYear));
$startYear = date("Y",mktime(0,0,0,$myMonth,$myDay,$myYear));
//Sunday
$endDay = date("d",mktime(0,0,0,$myMonth,$myDay+6,$myYear));
$endMonth = date("m",mktime(0,0,0,$myMonth,$myDay+6,$myYear));
$endYear = date("Y",mktime(0,0,0,$myMonth,$myDay+6,$myYear));
?>
<script>
//<CONSTANTS>
var NO_OPERATION = 0;
var CUT_OPERATION = 1;
var COPY_OPERATION = 2;
var calendarPortion = 0.73; //Percentage of the window used to show calendar
var calendarWidth = document.viewport.getWidth() * calendarPortion; //Viewport portion used to show calendar
var divDayWidth = Math.floor((85 * calendarWidth)/1000); //Width of a dayBox
var divDayHeight = 20; //Height of a dayBox
var divHourWidth = Math.floor((34.6 * calendarWidth)/1000); //Width of an hourBox
var divHourHeight = 20; //Height of an hourBox
//</CONSTANTS>
var numOfCalendarTables = 0;
var doctorOfCalendarTables = new Array();
var newClientDetailsFields; //Array of new clients info input. It's initialized in the onLoad function
var appDivs = new Array(); //Array of appointment box
var appNumber = 0; //Number of appointment box
var tabDivs = new Array(); //Array of empty box
var tabNumber = 0; //Number of appointment box
var dragStartTop = 0;
var dragStartLeft = 0;
var resizeStartWidth = 0;
var selectedBox = null; //The box selected
//I must record the boxes position because the div properties left, top and width are not updated after a drag&drop,resize or cut&paste operation.
//So in the future I will record all data in appDivs array.
<?php
mysql_query("BEGIN");
$result = mysql_query("SELECT * FROM cutandpaste WHERE cutId='1'");
if(mysql_num_rows($result)){
while($row = mysql_fetch_array($result)){
$capStatus = $row[status];
}
}else{
$capStatus = 0;
}
mysql_query("COMMIT");
echo "var thereIsAnAppointmentToBeCopied = " . $capStatus . ";";
?>
function num2Place(num){
var place;
switch(num){
case 0:
place = 'visitAppBox';
break;
case 1:
place = 'homeVisitAppBox';
break;
case 2:
place = 'extCommitmentAppBox';
break;
case 3:
place = 'holidayAppBox';
break;
default:
place = 'visitAppBox';
}
return place;
}
function place2Num(place){
var num;
switch(place){
case 'visitAppBox':
num = 0;
break;
case 'homeVisitAppBox':
num = 1;
break;
case 'extCommitmentAppBox':
num = 2;
break;
case 'holidayAppBox':
num = 3;
break;
default:
num = 3;
}
return num;
}
/***************************************** INIT BOXES (START) *****************************************/
/**************************************/
/* Places and records the empty boxes */
/**************************************/
function calendarOnLoad(calendar, doc){
var dIndex = 0;
var hIndex = 0;
var divID = 'div';
var divObj;
var oldTableHeight = parseInt($('calendarTable').style.height);
for(dIndex = 0; dIndex < 8; dIndex++){
for(hIndex = 0; hIndex < 27; hIndex++){
divID = 'div'+calendar+'_'+dIndex+'_'+hIndex;
divObj = $(divID);
tabDivs[tabNumber]=divObj;
tabNumber++;
if(hIndex == 0){
divObj.style.left = 0 + divHourWidth / 2 + "px";
divObj.style.top = (divDayHeight + 1) * dIndex + 130 + 240 * calendar + 3 * divDayHeight + "px";
divObj.style.width = divDayWidth+"px";
}else{
divObj.style.left=(divDayWidth + 1) + (divHourWidth + 1) * (hIndex-1) + divHourWidth / 2 + "px";
divObj.style.top = (divDayHeight + 1) * dIndex + 130 + 240 * calendar + 3 * divDayHeight + "px";
divObj.style.width = divHourWidth+"px";
}
}
}
$('calendarTable').style.height = divDayHeight * 8 + 90 + oldTableHeight + "px";
doctorOfCalendarTables[numOfCalendarTables]=doc;
numOfCalendarTables++;
}
/**************************************/
/* Places and records the app boxes */
/**************************************/
function appOnLoad(elem){
var args = elem.getAttribute("name").split("_");
var appSqlID = args[0];
var calendar = parseInt(args[1]);
var day = parseInt(args[2]);
var startTime = args[3];
var duration = parseInt(args[4]);
var app = args[5];
var appBoxID = 'app'+app;
var appObj = $(appBoxID);
var subStr = new Array();
var ctrlHalf = 0;
var divObj;
var hour;
//resize and place the appBox - start
subStr = startTime.split(":");
if(subStr[1] == 30){
ctrlHalf=1;
}
hour = (subStr[0]-8)*2 + ctrlHalf + 1;
appObj.style.left = (divDayWidth + 1) + (divHourWidth + 1) * (hour-1) + divHourWidth / 2 + "px";
appObj.style.top = (divDayHeight + 1) * day + 130 + 240 * calendar + 3 * divDayHeight + "px";
appObj.style.width =(duration/30)*(divHourWidth) + ((duration/30) - 1) + "px";
//resize and place the appBox - end
//make the appBox draggable and resizeable - start
new Draggable(appBoxID,{zindex: +5, handle: 'handle1', onStart: function (){dragStart(appBoxID)}, onEnd: function (){dragEnd(appBoxID, calendar)}});
new Resizeable(appBoxID, {top: 0, left: 0, right: 6, bottom: 0, minWidth: divHourWidth - 1, delta: divHourWidth+1, deltaFun: function(el){onResizing(el);}, resize: function(el){resizeEnd(el);}});
//make the appBox draggable and resizeable - end
//Event.observe($(appObj),'dblclick', function(e){showAppDetails($(appObj));});
//Event.observe($(appObj),'mousedown', function(e){Event.stop(e); clickOnTable(e, 'div');})});
//record the app - start
appDivs[appNumber]=appObj;
appNumber=appNumber+1;
//record the app - end
}
/***************************************** INIT BOXES ( END ) *****************************************/
/***************************************** Drag & Drop (START) *****************************************/
/****************************/
/* Drag&drop start function */
/****************************/
function dragStart(appBoxID){
var appObj = $(appBoxID);
//Save the start coordinates, they may be usefull at the end
//of the drag&drop operation to restore a wrong placement
dragStartTop = appObj.style.top;
dragStartLeft = appObj.style.left;
}
function successInDraggingAppF(transport){
var args=transport.responseText.evalJSON();
var box=$(selectedBox);
//Success in updating request
//Operation result advice
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
if(parseInt(args.opResult) == 0){
//Success in updating DB
//NOTHING TO DO
}else{
//Failure in updating DB
//The app backs to its old place
box.style.left = dragStartLeft;
box.style.top = dragStartTop;
}
}
function failureInDraggingAppF(){
var box=$(selectedBox);
//Failure in updating request
//The app backs to its old place
box.style.left = dragStartLeft;
box.style.top = dragStartTop;
//Failure advice
alert('<?php echo _T("NI_calendar_") ?>');
}
/**************************/
/* Drag&drop end function */
/**************************/
function dragEnd(appBoxID, calendar){
var draggedObj = $(appBoxID);
var divID;
var divObj;
var newPlace;
var forIndex;
selectionManager(appBoxID);
//position after movement
draggedLeft = parseInt(draggedObj.style.left);
draggedTop = parseInt(draggedObj.style.top);
draggedWidth = parseInt(draggedObj.style.width);
draggedHeight = parseInt(draggedObj.style.height);
draggedLeftValue = draggedLeft;
draggedRightValue = draggedLeft + draggedWidth;
//position table indexes after the movement (the movement must fit a grid)
draggedLeftIndex = Math.floor((draggedLeft - divDayWidth-(divHourWidth/2))/divHourWidth) + 1;
draggedCalendarIndex = Math.floor((draggedTop - 130) / 240);
draggedTopIndex = Math.floor((draggedTop - 130 - 240 * draggedCalendarIndex - 3 * divDayHeight)/divDayHeight);
//May the box changes position? Think positive
newPlace = true;
//Is the box position
appRightValue = draggedLeft+draggedWidth;
calRightValue = parseInt($('div0_0_26').style.left)+parseInt($('div0_0_26').style.width)+ 0.5 * divHourWidth;;
if((draggedLeftIndex < 1) || (draggedLeftIndex > 26) || (draggedTopIndex < 1) || (draggedTopIndex > 7) || (appRightValue > calRightValue)){
newPlace = false;
}
//... Se non ci sono sovrapposizioni con appuntamenti giÓ presenti
for(indice = 0; indice < appNumber; indice = indice + 1){
curObj = appDivs[indice];
if(curObj != draggedObj){
firmLeft = parseInt(curObj.style.left);
firmTop = parseInt(curObj.style.top);
firmWidth = parseInt(curObj.style.width);
firmLeftValue = firmLeft;
firmRightValue = firmLeft + firmWidth;
firmCalendarIndex = Math.floor((firmTop - 130)/240);
firmTopIndex = Math.floor((firmTop - 130 - 240 * firmCalendarIndex - 3 * divDayHeight)/divDayHeight);
if((firmTopIndex == draggedTopIndex) && (firmCalendarIndex == draggedCalendarIndex)){
//if the new app and the old one are on the same row (day) of the same calendar I must check they are not overlapping
// +-----------+
// | FIRM +-----------+
// +----------| DRAGGED |
// +-----------+
if((draggedLeftValue > firmLeftValue) && (draggedLeftValue < firmRightValue)){
newPlace = false;
}
// +-----------+
// +-----------+ FIRM |
// | DRAGGED |---------+
// +-----------+
if((draggedRightValue > firmLeftValue) && (draggedRightValue < firmRightValue)){
newPlace = false;
}
}
}
}
if(newPlace == true){
//The new appointment sticks the closest empty element
divID = 'div'+draggedCalendarIndex+'_'+draggedTopIndex+'_'+draggedLeftIndex;
divObj = $(divID);
draggedObj.style.left = divObj.style.left;
draggedObj.style.top = divObj.style.top;
//New data
//New day
newDay = $('div'+draggedCalendarIndex+'_'+draggedTopIndex+'_0').getAttribute("name");
//New hour
newHour = $('div'+draggedCalendarIndex+'_0_'+draggedLeftIndex).getAttribute("name");
//New vet
newDoctor = doctorOfCalendarTables[draggedCalendarIndex];
//The same ID
idToModify = findAppId(draggedObj);
//pellif: To be tested
OL_draggedAppointmentUpdate(idToModify, newDoctor, newDay, newHour, {onSuccess: successInDraggingAppF, onFailure: failureInDraggingAppF});
}else{
//The new appointment is in a wrong place, it must return in the old position
draggedObj.style.left = dragStartLeft;
draggedObj.style.top = dragStartTop;
}
}
/***************************************** Drag & Drop ( END ) *****************************************/
/***************************/
/* Return the SCROLL value */
/***************************/
function getScrollY(){
var scroll = document.viewport.getScrollOffsets();
return scroll[1];
}
/*************************************************/
/* Manages click event on the tab client details */
/*************************************************/
function clickOnClientDetails(e){
if($('owner').value == '#'){
$('client').value=0;
manageNewClientDetails('client');
}
}
/*************************************/
/* Enable/disable new client details */
/*************************************/
function manageNewClientDetails(client){
var formObj = $('newclientDetails');
var heIsAnOldClient = parseInt($F(client));
if(heIsAnOldClient){
//disable all new client details input element (select included), all inputs value is now '#'
newClientDetailsFields.each(function(s){s.value='#';s.style.color='#BBBBBB';});
}else{
//enable all new client details input element (select included), all inputs value is now ''
newClientDetailsFields.each(function(s){s.value='';s.style.color='#000000';});
}
}
/**********************************/
/* Reloads the page on dateChange */
/**********************************/
function onDateChange(){
var dateText = $F('date');
var datePart = dateText.split("/");
var myDate = new Date(parseInt(datePart[2]), parseInt(datePart[1])-1, parseInt(datePart[0]));
var myDateSecs = myDate.getTime()/1000;
var mondaySecs = <?php echo mktime(0,0,0,$startMonth,$startDay,$startYear); ?>;
var sundaySecs = <?php echo mktime(0,0,0,$endMonth,$endDay,$endYear); ?>;
//alert(mondaySecs+'_'+myDateSecs+'_'+sundaySecs+'_(<?php echo $startDay."/".$startMonth."/".$startYear; ?>)_('+dateText+')_(<?php echo $endDay."/".$endMonth."/".$endYear; ?>)');
if((mondaySecs <= myDateSecs) && (myDateSecs <= sundaySecs)){
}else{
var aClientId = $F('client');
var aName = $F('owner');
var aTelephone = $F('telephone');
var anEmail = $F('email');
var aAddress = $F('address1');
var aVet = $F('vet');
var aLocation = $F('place');
var aDate = $F('date');
var aHour = $F('hour');
var aPeriod = $F('period');
var aComment = $F('note');
document.location.href='calendar.php?day='+datePart[0]+'&month='+datePart[1]+'&year='+datePart[2]+'&mai='+anEmail+'&cid='+aClientId+'&pro='+aName+'&tel='+aTelephone+'&cel=---&uff=---&add='+aAddress+'&vet='+aVet+'&loc='+aLocation+'&dat='+aDate+'&hou='+aHour+'&dur='+aPeriod+'&comm='+aComment;
}
}
/***********************************/
/* Manage the app box just created */
/***********************************/
function successInCreatingAppF(transport){
var newAppObj;
var place;
var args=transport.responseText.evalJSON();
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
//success in creating request
if(parseInt(args.opResult) == 0){
//success in creating app box
place = num2Place(parseInt(args.aPlace));
newAppObj = createNewAppBox(place, args.appId, parseInt(args.aCalendar), args.aDay, args.anHour, args.aPeriod, appNumber);
appOnLoad(newAppObj);
}else{
//failure in creating app box
}
}
/*****************************************/
/* Failure in creating request to server */
/*****************************************/
function failureInCreatingAppF(){
alert('<?php echo _T("NI_calendar_") ?>');
}
/****************************************/
/* Checks infos and creates appointment */
/****************************************/
function createNewApp(){
var isAnOldClient = parseInt($F('client'));
var aClient = $F('client');
var aNote = $F('note');
var aDate = $F('date');
var anHour = $F('hour');
var aPeriod = $F('period');
var aVet = $F('vet');
var aOwner = $F('owner');
var aTelephone = $F('telephone');
var anAddress = $F('address1');
var anEmail = $F('email');
var aPlace;
aPlace = place2Num($F('place'));
if(isAnOldClient){
OL_createNewAppointment(aClient, aOwner, aTelephone, anEmail, anAddress, aVet, aPlace, aDate, anHour, aPeriod, aNote, {onSuccess: successInCreatingAppF, onFailure: failureInCreatingAppF});
}else{
if(formValidationRules.validate()){
OL_createNewAppointment(aClient, aOwner, aTelephone, anEmail, anAddress, aVet, aPlace, aDate, anHour, aPeriod, aNote, {onSuccess: successInCreatingAppF, onFailure: failureInCreatingAppF});
}else{
alert('<?php echo _T("NI_calendar_") ?>');
}
}
}
/************************************************/
/* Find out the appointment ID from the element */
/************************************************/
function findAppId(appElem){
var args = $(appElem).getAttribute("name").split("_");
var appId = args[0];
return appId;
}
/************************************/
/* Link to appointment details page */
/************************************/
function showAppDetails(elem){
document.location.href='viewAppointmentDetails.php?appointmentID='+findAppId($(elem));
}
/****************************************/
/* Manages and shows boxes context menu */
/****************************************/
function showContextMenu(e, element) {
contextMenuObj = $('contextMenu');
pasteObj = $('paste');
copyObj = $('copy');
cancelObj = $('cancel');
cutObj = $('cut');
srcObj = $(element);
if(($(srcObj).getAttribute("class") == 'visitAppBox') || ($(srcObj).getAttribute("class") == 'homeVisitAppBox') || ($(srcObj).getAttribute("class") == 'extCommitmentAppBox') || ($(srcObj).getAttribute("class") == 'holidayAppBox')){
//visitAppBox OR homeVisitAppBox OR extCommitmentAppBox OR holidayAppBox
contextMenuObj.style.left = e.pointerX()+'px';
contextMenuObj.style.top = e.pointerY()+'px';
contextMenuObj.style.visibility = 'visible';
cutObj.style.color = "darkblue";
copyObj.style.color = "darkblue";
pasteObj.style.color = "gray";
cancelObj.style.color = "darkblue";
}
if($(srcObj).getAttribute("class") == 'emptyAppBox'){
//emptyAppBox
contextMenuObj.style.left = e.pointerX()+'px';
contextMenuObj.style.top = e.pointerY()+'px';
contextMenuObj.style.visibility = 'visible';
cutObj.style.color = "gray";
copyObj.style.color = "gray";
if(thereIsAnAppointmentToBeCopied){
pasteObj.style.color = "darkblue";
}else{
pasteObj.style.color = "gray";
}
cancelObj.style.color = "gray";
}
}
/***********************************/
/* Manages boxes select operations */
/***********************************/
function selectionManager(divObj){
if(selectedBox){
selectThis(selectedBox, false);
}
selectedBox = divObj;
selectThis(selectedBox, true);
}
/***********************************/
/* Select/Deselect visual features */
/***********************************/
function selectThis(divObj, cond){
var newColor;
var box = $(divObj);
var getDivClass = box.getAttribute("class");
switch(getDivClass){
case 'visitAppBox':
if(cond){newColor = '#C06C80';}else{newColor = '#FF90AA';}
break;
case 'homeVisitAppBox':
if(cond){newColor = '#303093';}else{newColor = '#5555FF';}
break;
case 'extCommitmentAppBox':
if(cond){newColor = '#C0A92A';}else{newColor = '#FFE138';}
break;
case 'holidayAppBox':
if(cond){newColor = '#009171';}else{newColor = '#00C196';}
break;
case 'emptyAppBox':
if(cond){newColor = '#DDDCFA';}else{newColor = '#FFFEFA';}
break;
default:
}
box.style.backgroundColor = newColor;
}
function successInRetrivingInfoF(transport){
var args=transport.responseText.evalJSON();
var isAClient = parseInt(args.client);
var place;
//Success in retrive request
//I want show the operation result advice only if the retrive operation fails
if(parseInt(args.opResult) == 0){
//Success in retrive operation
$('client').value = args.client;
manageNewClientDetails('client');
if(!(isAClient)){ //If he is not a client I must show all the details
$('owner').value = args.owner;
$('telephone').value = args.telephone;
$('email').value = args.email;
$('address1').value = args.address1;
}
$('vet').value = args.vet;
place = num2Place(parseInt(args.place));
$('place').value = place;
$('date').value = args.date;
$('hour').value = args.hour;
$('period').value = args.period;
$('note').value = args.note;
}else{
//Failure in retrive operation
//Operation result advice
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
}
}
function failureInRetrivingInfoF(){
//Failure in retrive request
}
/****************************************/
/* Manages mousedown event on the table */
/****************************************/
function clickOnTable(e, tagToFind){
srcObj = e.findElement(tagToFind);
if(e.isLeftClick()){
/***********************************/
/* Left click detected (prototype) */
/***********************************/
selectionManager(srcObj);
if(($(srcObj).getAttribute("class") == 'visitAppBox') || ($(srcObj).getAttribute("class") == 'homeVisitAppBox') || ($(srcObj).getAttribute("class") == 'extCommitmentAppBox') || ($(srcObj).getAttribute("class") == 'holidayAppBox')){
OL_retriveAppointmentInfos(findAppId($(srcObj)), {onSuccess: successInRetrivingInfoF, onFailure: failureInRetrivingInfoF});
}
if($(srcObj).getAttribute("class") == 'emptyAppBox'){
divIdParts = srcObj.getAttribute("id").split("_");
calendar = parseInt(divIdParts[0].replace("div",""));
indDay = parseInt(divIdParts[1]);
newDate = $('div'+calendar+'_'+indDay+'_0').getAttribute("name");
$('date').value = newDate;
}
}else if(e.isMiddleClick()){
/*************************************/
/* Middle click detected (prototype) */
/*************************************/
alert('Middle');
}else if(e.isRightClick()){
/************************************/
/* Right click detected (prototype) */
/************************************/
selectionManager(srcObj);
showContextMenu(e, srcObj);
}else{
alert('Other: '+e.button);
}
e.stop();
}
/****************************************/
/* Manages mousedown event on the table */
/****************************************/
function onResizing(el){
var elWidth = parseInt($(el).style.width);
var elLeft = parseInt($(el).style.left);
var elTop = parseInt($(el).style.top);
var calRight = parseInt($('div0_0_26').style.left)+parseInt($('div0_0_26').style.width);
var newWidth;
//within calendars borders
if(elWidth+elLeft > calRight){
newWidth = calRight - elLeft;
el.style.width = newWidth+'px';
}
//app box calendar index
leftIndex = Math.floor((elLeft - divDayWidth-(divHourWidth/2))/divHourWidth) + 1;
calendarIndex = Math.floor((elTop - 130) / 240);
topIndex = Math.floor((elTop - 130 - 240 * calendarIndex - 3 * divDayHeight)/divDayHeight);
//for each app box in calendar...
for(indice = 0; indice < appNumber; indice = indice + 1){
curObj = appDivs[indice];
//...all app boxes except the one we are resizing
if(curObj != el){
cLeftV = parseInt(curObj.style.left);
cTopV = parseInt(curObj.style.top);
cWidthV = parseInt(curObj.style.width);
cHeightV = parseInt(curObj.style.height);
cCalendarIndex = Math.floor((cTopV - 130)/240);
cTopIndex = Math.floor((cTopV - 130 - 240 * cCalendarIndex - 3 * divDayHeight)/divDayHeight);
//if in the same row of the same calendar
if((cTopIndex == topIndex) && (cCalendarIndex == calendarIndex) && (elLeft < cLeftV)){
if(elLeft+elWidth > cLeftV){
// |
// |<-limit
// |
// +------------+ |-----------+
// | RESIZING | | APP BOX |
// +------------+ +-----------+
newWidth = cLeftV - elLeft - 1;
el.style.width = newWidth+'px';
}
}
}
}
}
/********************************************************/
/* Manages update result caused by the resize operation */
/********************************************************/
function successInResizingAppF(transport){
var args=transport.responseText.evalJSON();
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
//Success in resize request
if(parseInt(args.opResult) == 0){
//Success in resize operation
}else{
//Error during resize operation
}
}
/**********************************************************/
/* Manages request failure caused by the resize operation */
/**********************************************************/
function failureInResizingAppF(){
//Failure in resize request
alert('<?php echo _T("NI_calendar_") ?>');
}
/*******************************************/
/* Manages the end of the resize operation */
/*******************************************/
function resizeEnd(el){
var idToModify = findAppId($(el));
var newTimeTo = ((parseInt($(el).style.width) - divHourWidth) / (divHourWidth+1)) * 30 + 30;
OL_resizedAppointmentUpdate(idToModify, newTimeTo, {onSuccess: successInResizingAppF, onFailure: failureInResizingAppF});
}
/**********************************************************/
/* Manages update result caused by the cut© operation */
/**********************************************************/
function successInCopyAndCutOperationF(transport){
var args=transport.responseText.evalJSON();
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
}
/************************************************************/
/* Manages request failure caused by the cut© operation */
/************************************************************/
function failureInCopyAndCutOperationF(){
alert('<?php echo _T("NI_calendar_") ?>');
}
/*****************/
/* Cut operation */
/*****************/
function cutFn(){
$('contextMenu').style.visibility = 'hidden';
if($(selectedBox).getAttribute('class') != 'emptyAppBox'){
thereIsAnAppointmentToBeCopied = CUT_OPERATION;
OL_appointmentCut(findAppId($(selectedBox)), '1', {onSuccess: successInCopyAndCutOperationF, onFailure: failureInCopyAndCutOperationF});
}
}
/******************/
/* Copy operation */
/******************/
function copyFn(){
$('contextMenu').style.visibility = 'hidden';
if($(selectedBox).getAttribute('class') != 'emptyAppBox'){
thereIsAnAppointmentToBeCopied = COPY_OPERATION;
OL_appointmentCopy(findAppId($(selectedBox)), '2', {onSuccess: successInCopyAndCutOperationF, onFailure: failureInCopyAndCutOperationF});
}
}
/*******************************************************/
/* Manages update result caused by the paste operation */
/*******************************************************/
function successInPasteOperationF(transport){
var newAppObj;
var args=transport.responseText.evalJSON();
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
if(parseInt(args.opResult) == 0){
newAppObj = createNewAppBox(num2Place(parseInt(args.place)), args.appId, parseInt(args.aCalendar), args.aDay, args.anHour, args.aPeriod, appNumber);
appOnLoad(newAppObj);
if(thereIsAnAppointmentToBeCopied == CUT_OPERATION){
//Cut operation
thereIsAnAppointmentToBeCopied = NO_OPERATION;
//for each app box in the page minus the pasted one
for(indice = 0; indice < appNumber-1; indice = indice + 1){
curObj = appDivs[indice];
//If a box has the same ID of the pasted box, then is the app box we have to cut
if(findAppId(curObj) == args.appId){
curObj.style.display = 'none';
}
}
}
}else{
//Error during paste operation
}
}
/*********************************************************/
/* Manages request failure caused by the paste operation */
/*********************************************************/
function failureInPasteOperationF(){
alert('<?php echo _T("NI_calendar_") ?>');
}
/***********************/
/* The paste operation */
/***********************/
function pasteFn(){
var emptyDiv = $(selectedBox);
var newAppNumber = appNumber + 1;
$('contextMenu').style.visibility = 'hidden';
if(($(selectedBox).getAttribute('class') == 'emptyAppBox') && (thereIsAnAppointmentToBeCopied != NO_OPERATION)){
/* **************************************************************************** */
/* Calcolo i parametri temporali e il veterianrio da associare al nuovo - Start */
/* **************************************************************************** */
//tutti gli altri parametri verranno mutuati dall'appuntamento copiato o tagliato
divIdParts = emptyDiv.getAttribute("id").split("_");
calendar = parseInt(divIdParts[0].replace("div",""));
newDoctor = doctorOfCalendarTables[calendar];
indDay = parseInt(divIdParts[1]);
resto = (parseInt(divIdParts[2])-1)%2;
indTime = 8 + ((parseInt(divIdParts[2])-1) - resto)/2
if(resto == 1){
startTime = indTime+':30';
}else{
startTime = indTime+':00';
}
newDate = $('div'+calendar+'_'+indDay+'_0').getAttribute("name");
/* ************************************************************************** */
/* Calcolo i parametri temporali e il veterianrio da associare al nuovo - End */
/* ************************************************************************** */
OL_appointmentPaste(startTime, newDate, newDoctor, calendar, indDay, newAppNumber, {onSuccess:successInPasteOperationF, onFailure:failureInPasteOperationF});
}
}
/********************************************************/
/* Manages delete result caused by the cancel operation */
/********************************************************/
function successInDeletingApp(transport){
var args=transport.responseText.evalJSON();
$('qResult').style.display='block';
$('qResult').innerHTML=args.opText;
if(parseInt(args.opResult) == 0){
$(selectedBox).style.display = 'none';
}else{
//Error during paste operation
}
}
/**********************************************************/
/* Manages request failure caused by the cancel operation */
/**********************************************************/
function failureInDeletingApp(){
alert('<?php echo _T("NI_calendar_") ?>');
}
/************************/
/* The cancel operation */
/************************/
function cancelFn(){
appId = findAppId(selectedBox);
$('contextMenu').style.visibility = 'hidden';
if($(selectedBox).getAttribute('class') != 'emptyAppBox'){
thereIsAnAppointmentToBeCopied = NO_OPERATION;
OL_deleteAppointment(appId, {onSuccess: successInDeletingApp, onFailure: failureInDeletingApp});
}
}
/******************************/
/* Create New app box */
/******************************/
/* main div */
/* | */
/* +----------------+ */
/* |O :| */
/* +----------------+ */
/* | | */
/* hdrag&drop hresize */
/* ******************************/
function createNewAppBox(appType, appId, appCalendar, appDay, appTime, appDuration, appNumber){
var commonObject;
var mainDiv;
var ddHandleSpan;
var ddHandleImage;
var rHandleSpan;
var rHandleImage;
var classStr;
//alert(appType+'_'+appId+'_'+appCalendar+'_'+appDay+'_'+appTime+'_'+appDuration+'_'+appNumber);
//Main div
mainDiv = document.createElement("div");
mainDiv.setAttribute("class", appType);
mainDiv.setAttribute("id",'app'+appNumber);
mainDiv.setAttribute("name", appId+'_'+appCalendar+'_'+appDay+'_'+appTime+'_'+appDuration+'_'+appNumber);
document.getElementById('calendarCol').appendChild(mainDiv);
//Drag and drop span
ddHandleSpan = document.createElement("span");
ddHandleSpan.setAttribute("id",'span1app'+appNumber);
ddHandleSpan.setAttribute("class",'handle1');
mainDiv.appendChild(ddHandleSpan);
//Handle drag and drop
ddHandleImage = document.createElement("img");
ddHandleImage.setAttribute("src", "images/handle.png");
ddHandleSpan.appendChild(ddHandleImage);
//Span contenente l'handle resize
rHandleSpan = document.createElement("span");
rHandleSpan.setAttribute("id",'span2app'+appNumber);
rHandleSpan.setAttribute('style', 'float: right');
mainDiv.appendChild(rHandleSpan);
//Handle resize
rHandleImage = document.createElement("img");
rHandleImage.setAttribute("src", "images/handleResize.png");
rHandleSpan.appendChild(rHandleImage);
classStr ='div.'+appType;
$$(classStr).each(function(s){Event.observe(s,'dblclick',function(e){showAppDetails(s);})});
$$(classStr).each(function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
return mainDiv;
}
//handler for keypressed event
//UNUSED - I'm not able to detect CTRL-C.
//To enable this function de-comment its
//"observe" row in the load event observer
//at the end of the page
function detectKeyPressed(e){
var unicode;
//These are for cross-browser compatibility
if(!e){e = window.event;}
if(e.keyCode){unicode = e.keyCode;}else{unicode = e.charCode;}
switch(unicode){
case 46:/* CANCEL */ break;
case 67:/* C */ if (e.ctrlKey){/* CTRL-C */} break;
case 22:/* V */ if (e.ctrlKey){/* CTRL-V */} break;
case 24:/* X */ if (e.ctrlKey){/* CTRL-X */} break;
default:/* c */
}
}
/***************************************************************************************/
/* Set the event handler and the init functions for all the item in the calendar table */
/***************************************************************************************/
function setCalendarEventHandlers(){
<?php
$calendar=0;
mysql_query("BEGIN");
$getDoctors = mysql_query("SELECT * FROM users WHERE userPrivList='Dottore' ORDER BY userFullName");
while($row = mysql_fetch_array($getDoctors)) {
$row[userFullName];
echo "calendarOnLoad('" . $calendar . "', '" . $row[userFullName] . "');\n";
$calendar=$calendar+1;
}
mysql_query("COMMIT");
?>
$$('div.visitAppBox').each( function(s){appOnLoad(s);});
$$('div.homeVisitAppBox').each( function(s){appOnLoad(s);});
$$('div.extCommitmentAppBox').each( function(s){appOnLoad(s);});
$$('div.holidayAppBox').each( function(s){appOnLoad(s);});
$$('div.visitAppBox').each( function(s){Event.observe(s,'dblclick',function(e){showAppDetails(s);})});
$$('div.homeVisitAppBox').each( function(s){Event.observe(s,'dblclick',function(e){showAppDetails(s);})});
$$('div.extCommitmentAppBox').each( function(s){Event.observe(s,'dblclick',function(e){showAppDetails(s);})});
$$('div.holidayAppBox').each( function(s){Event.observe(s,'dblclick',function(e){showAppDetails(s);})});
$$('div.emptyAppBox').each( function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
$$('div.visitAppBox').each( function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
$$('div.homeVisitAppBox').each( function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
$$('div.extCommitmentAppBox').each( function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
$$('div.holidayAppBox').each( function(s){Event.observe(s,'mousedown',function(e){Event.stop(e); clickOnTable(e, 'div');})});
}
</script>
<?php
?>
<div id="qResult" class="OpResult"></div>
<div class="Columns">
<div class="Column1">
<!-- *********************************************************** -->
<!-- * Appointment tab * -->
<!-- *********************************************************** -->
<div class="Block" style="position:fixed; width:19%"><div class="BlockBL"><div></div></div><div class="BlockBR"><div></div></div><div class="BlockTL"></div><div class="BlockTR"><div></div></div><div class="BlockT"></div><div class="BlockR"><div></div></div><div class="BlockB"><div></div></div><div class="BlockL"></div><div class="BlockC"></div><div class="BlockContent"><div class="BlockContentBorder">
<form id="formToValidate">
<table width="100%">
<tr>
<td width="10%"><b><?php echo _T("Client") ?></b></td>
<td colspan="4">
<select name="client" id="client" style="width: 98%;" >
<option value="0"></option>
<?php
mysql_query("BEGIN");
$clientList= mysql_query("SELECT * FROM clients ORDER BY clientName");
while($row = mysql_fetch_array($clientList)) {
if($aClient == $row[clientID]){
echo "<option value=\"" . $row[clientID] . "\" selected=\"selected\">" . $row[clientName] . " " . $row[clientSurname] . "</option>";
}else{
echo "<option value=\"" . $row[clientID] . "\">" . $row[clientName] . " " . $row[clientSurname] . "</option>";
}
}
mysql_query("COMMIT");
?>
</select>
</td>
</tr>
<tr>
<td><?php echo _T("Name") ?></td>
<?php
echo "<td colspan=\"4\"><input class=\"required\" type=\"text\" style=\"width: 93%;\" id=\"owner\" name=\"owner\" value=\"" . $aName . "\"></td>";
?>
</tr>
<tr>
<td><?php echo _T("Telephone") ?></td>
<?php
echo "<td colspan=\"4\"><input class=\"validate-number\" type=\"text\" style=\"width: 93%;\" id=\"telephone\" name=\"telephone\" value=\"" . $aTelephone . "\"></td>";
?>
</tr>
<tr>
<td><?php echo _T("Email") ?></td>
<?php
echo "<td colspan=\"4\"><input class=\"validate-email\" type=\"text\" style=\"width: 93%;\" id=\"email\" name=\"email\" value=\"" . $anEmail . "\"></td>";
?>
</tr>
<tr>
<td><?php echo _T("Address") ?></td>
<?php
echo "<td colspan=\"4\"><input type=\"text\" style=\"width: 93%;\" id=\"address1\" name=\"address1\" value=\"" . $aAddress . "\"></td>";
?>
</tr>
<tr>
<td><b><?php echo _T("Vet") ?></b></td>
<td colspan="4">
<select style="width: 98%;" id="vet" name="vet">
<?php
mysql_query("BEGIN");
$vetList=mysql_query("SELECT * FROM users WHERE userPrivList='Dottore' ORDER BY userFullName");
while($row = mysql_fetch_array($vetList)) {
if($aVet == $row[userFullName]){
echo "<option value=\"" . $row[userFullName] . "\" selected=\"selected\">" . $row[userFullName] . "</option>";
}else{
echo "<option value=\"" . $row[userFullName] . "\">" . $row[userFullName] . "</option>";
}
}
mysql_query("COMMIT");
?>
</select>
</td>
</tr>
<tr>
<td><b><?php echo _T("Place") ?></b></td>
<td colspan="4">
<select style="width: 98%;" id="place" name="place">
<?php
if($aLocation == 0){
echo "<option value=\"visitAppBox\" selected=\"selected\">" . _T("Clinic visit") . "</option>";
}else{
echo "<option value=\"visitAppBox\">" . _T("Clinic visit") . "</option>";
}
if($aLocation == 1){
echo "<option value=\"homeVisitAppBox\" selected=\"selected\">" . _T("Home visit") . "</option>";
}else{
echo "<option value=\"homeVisitAppBox\">" . _T("Home visit") . "</option>";
}
if($aLocation == 2){
echo "<option value=\"extCommitmentAppBox\" selected=\"selected\">" . _T("External commitment") . "</option>";
}else{
echo "<option value=\"extCommitmentAppBox\">" . _T("External commitment") . "</option>";
}
if($aLocation == 3){
echo "<option value=\"holidayAppBox\" selected=\"selected\">" . _T("Holiday") . "</option>";
}else{
echo "<option value=\"holidayAppBox\">" . _T("Holiday") . "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td width="10%"><b><?php echo _T("Date") ?></b></td>
<td colspan="3"><input style="width:95%;" type="text" readonly="readonly" id="date" value="<?php echo $oDay . "/" . $oMonth . "/" . $oYear; ?>"></td><td width="10%" align="right"><a href="javascript:calendarLoad('date');"><img src="./images/calendarIcon.png"/></a></td></tr>
</tr>
<tr>
<td><b><?php echo _T("Hour") ?></b></td>
<td colspan="4"><select id="hour" style="width:40%;" name="hour"><?php $conta=8; while($conta<21){$oraApp=$conta . ":00"; echo "<option value=\"" . $oraApp . "\">" . $oraApp . "</option>"; $oraApp=$conta . ":30"; echo "<option value=\"" . $oraApp . "\">" . $oraApp . "</option>"; $conta=$conta+1;} ?></select>(<select id="period" style="width:35%" name="period"><?php $durata=0; while($durata<780){$durata=$durata+30; $hourCheck = $durata%60; if($hourCheck != 0){$hourToDisplay = ($durata - 30)/60; $hourToDisplay = $hourToDisplay . ":30";}else{$hourToDisplay = $durata/60; $hourToDisplay = $hourToDisplay . ":00";} if($durata!=30){echo "<option value=\"" . $durata . "\">" . $hourToDisplay . "</option>";}else{echo "<option selected=\"selected\" value=\"" . $durata . "\">" . $hourToDisplay . "</option>";}} ?></select>min)</td>
</tr>
<tr>
<td colspan="5"><b><?php echo _T("Note") ?></b></td>
</tr>
<tr valign="top">
<td colspan="5"><textarea rows="4" cols="1" id="note" name="note" style="font-size:1em; width:95%;"><?php echo $aComment; ?></textarea></td>
</tr>
<tr>
<td colspan="5" align="center"><input type="button" id="createNewApp" value="<?php echo _T("New appointment") ?>"></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div><p style="color:#FFFEFA;">p</div>
</div>
<div id="calendarCol" class="MainColumn">
<!-- *********************************************************** -->
<!-- * Calendar table * -->
<!-- *********************************************************** -->
<div id="calendarTable" style="height: 1px">
</div>
<!-- *********************************************************** -->
<!-- * Hidden context menu * -->
<!-- *********************************************************** -->
<div id="contextMenu" this.tid=setTimeout('menu.style.visibility = \'hidden\'', 20);" style="position:absolute; z-index: 5;">
<a href="#" id="cut" class="cmMenuOff" ><?php echo _T("Cut") ?></a><br>
<a href="#" id="copy" class="cmMenuOff" ><?php echo _T("Copy") ?></a><br>
<a href="#" id="paste" class="cmMenuOff" ><?php echo _T("Paste") ?></a><br>
<a href="#" id="cancel" class="cmMenuOff" ><?php echo _T("Cancel") ?></a>
</div>
</div>
</div>
<script>
// ************************************************************
// * Observe window load event to call the init page function *
// ************************************************************
Event.observe(window, 'load', function(){
// ******************************************
// * Load calendar table for the first time *
// ******************************************
OL_calendarTableLoad(<?php echo $startDay; ?>, <?php echo $startMonth; ?>, <?php echo $startYear; ?>,{elementToFill: 'calendarTable', onSuccess: setCalendarEventHandlers});
// ******************
// * Variables init *
// ******************
newClientDetailsFields = new Array($('owner'), $('telephone'), $('email'), $('address1'));
// **************************
// * Install event handlers *
// **************************
//Event.observe(document, 'keypress', function(e){detectKeyPressed(e);});
//Manage the appointment TAB events
Event.observe('client', 'change', function(e){manageNewClientDetails('client');});
Event.observe('owner', 'click', function(e){Event.stop(e); clickOnClientDetails(e);});
Event.observe('telephone', 'click', function(e){Event.stop(e); clickOnClientDetails(e);});
Event.observe('email', 'click', function(e){Event.stop(e); clickOnClientDetails(e);});
Event.observe('address1', 'click', function(e){Event.stop(e); clickOnClientDetails(e);});
Event.observe('date', 'dateChoice:newDateSet', function(e){onDateChange();});
Event.observe('createNewApp', 'click', function(e){createNewApp();});
//Result bar behavior
Event.observe('qResult', 'mouseover', function(){OL_makeThisElementInvisible('qResult');});
//Prevent default context menu
Event.observe(document,'contextmenu',function(e){e.stop();});
//Manage the new context menu
Event.observe('cut', 'click', function(e){cutFn()});
Event.observe('copy', 'click', function(e){copyFn()});
Event.observe('paste', 'click', function(e){pasteFn()});
Event.observe('cancel', 'click', function(e){cancelFn()});
// *********************
// * Install validator *
// *********************
formValidationRules = new Validation('formToValidate',{immediate:true, onSubmit:false, useTitles:true, stopOnFirst:false});
//alert('<?php echo $startDay?>/<?php echo $startMonth?>/<?php echo $startYear?> --> <?php echo $endDay?>/<?php echo $endMonth?>/<?php echo $endYear?>');
});
</script>
<!-- tags opened in the header -->
</div>
</div>
</div>
</body>
</html>