var headerMsgLock = false;
function write_msg (message){
if (headerMsgLock){
setTimeout('write_msg("'+message+'");', 300);
return;
}
headerMsgLock = true;
headerDiv = document.getElementById("divAppboxHeader");
var labelBefore = headerDiv.innerHTML;
headerDiv.innerHTML = '
';
setTimeout('headerMsgLock = false; document.getElementById("divAppboxHeader").innerHTML = \"'+labelBefore+'\";', 2000);
}
function write_error (message){
if (headerMsgLock){
setTimeout('write_error("'+message+'");', 300);
return;
}
headerMsgLock = true;
headerDiv = document.getElementById("divAppboxHeader");
var labelBefore = headerDiv.innerHTML;
headerDiv.innerHTML = '';
setTimeout('headerMsgLock = false; document.getElementById("divAppboxHeader").innerHTML = \"'+labelBefore+'\";', 2000);
}
function createButtons(eventDiv) {
var lnk = document.getElementById('remove_'+eventDiv.id);
var lnk2 = document.getElementById('details_'+eventDiv.id);
if (!lnk){
var removeLink = document.createElement('a');
removeLink.id = "remove_" + eventDiv.id;
removeLink.href = "javascript:removeEvent("+eventDiv.id.substr(6)+");";
removeLink.innerHTML = '';
removeLink.style.position = "absolute";
removeLink.style.top = "0px";
removeLink.style.left = "175px";
var showDetailLink = document.createElement('a');
showDetailLink.id = "details_" + eventDiv.id;
showDetailLink.href = "javascript:showDetails("+eventDiv.id+");";
showDetailLink.innerHTML = '';
showDetailLink.style.position = "absolute";
showDetailLink.style.top = "0px";
showDetailLink.style.left = "160px";
eventDiv.appendChild(showDetailLink);
eventDiv.appendChild(removeLink);
}
else{
lnk.style.visibility="visible";
lnk2.style.visibility="visible";
}
}
function submitDetailsHandler () {
var iframe = document.getElementById('nullFrame');
var Fdoc = iframe.contentDocument || iframe.contentWindow;
statusSpan = Fdoc.getElementById('formStatus');
if (statusSpan)
{
var ErMessage = statusSpan.innerHTML.replace(/<[^>]*>/,'');
write_error(ErMessage);
divAddDialog = document.getElementById("divAddDialog");
divAddDialog.appendChild(Fdoc.getElementsByName('app_form')[0]);
divAddDialog.style.display = "block";
}
else
{
if (Fdoc.getElementById('calendar_overlap_table')){
write_error(get_lang('scheduling conflict'));
divAddDialog = document.getElementById("divAddDialog");
document.getElementsByName('app_form')[0].innerHTML = Fdoc.getElementById('divAppbox').innerHTML;
document.getElementById('ignore_button').style.display = "none";
document.getElementById('redit_button').style.display = "none"; // TODO: Update the action to submit in background
divAddDialog.style.display = "block";
}
else
write_msg(get_lang('Event updated successfully'));
}
connector.hideProgressBar();
}
function addDetails(title,description,datetime,edatetime){
if (!edatetime)
edatetime = "";
if (!datetime || datetime.length == 0)
datetime = edatetime;
var handler_embeddedHTML = function (data) {
var divAddDialog = document.getElementById("divAddDialog");
if(!divAddDialog)
{
divAddDialog = document.createElement("DIV");
divAddDialog.id = 'divAddDialog';
divAddDialog.style.zIndex = "10";
divAddDialog.style.position = "absolute";
divAddDialog.style.display = "none";
document.body.appendChild(divAddDialog);
}
divAddDialog.style.left = "100px";
divAddDialog.style.top = "100px";
var xsl = XMLTools.load('xsl/windowDialog.xsl');
xml = "";
divAddDialog.innerHTML = xtools.parse(xml, xsl);
document.getElementById('form_content').innerHTML = data;
submitButton = document.getElementById('submit_button');
submitButton.onclick = function () { cExecuteForm('/index.php?menuaction=calendar.bocalendar.update',document.getElementsByName('app_form')[0],'submitDetailsHandler'); return false; }
cancelButton = document.getElementById('cancel_button');
cancelButton.onclick = function () { calendar.dialog(); return false; }
deleteButton = document.getElementById('delete_button');
deleteButton.onclick = function () { removeEvent(eventId.id.substr(6)); calendar.dialog(); return false; }
divAddDialog.style.display = "block";
}
cExecute('../index.php?menuaction=calendar.uicalendar.add&plain=True&date='+datetime.substr(0,4)+datetime.substr(6,2)+datetime.substr(4,2)+'&hour='+datetime.substr(8,2)+'&minute='+datetime.substr(10,2),handler_embeddedHTML);
}
function showDetails(eventId){
var handler_embeddedHTML = function (data) {
var divAddDialog = document.getElementById("divAddDialog");
var xsl = XMLTools.load('xsl/windowDialog.xsl');
if(!divAddDialog)
{
divAddDialog = document.createElement("DIV");
divAddDialog.id = 'divAddDialog';
divAddDialog.style.zIndex = "10";
divAddDialog.style.position = "absolute";
divAddDialog.style.display = "none";
document.body.appendChild(divAddDialog);
}
divAddDialog.style.left = "100px";
divAddDialog.style.top = "100px";
xml = "";
divAddDialog.innerHTML = xtools.parse(xml, xsl);
document.getElementById('form_content').innerHTML = data;
submitButton = document.getElementById('submit_button');
submitButton.onclick = function () { cExecuteForm('/index.php?menuaction=calendar.bocalendar.update',document.getElementsByName('app_form')[0],'submitDetailsHandler'); calendar.dialog(); return false; }
try
{
cancelButton = document.getElementById('cancel_button');
cancelButton.onclick = function () { calendar.dialog(); return false; }
}
catch (e)
{
cancelButton = document.createElement('INPUT');
cancelButton.type = "submit";
cancelButton.value = get_lang('cancel');
cancelButton.onclick = function () { calendar.dialog(); return false; }
document.getElementsByName('app_form')[0].appendChild(cancelButton);
};
deleteButton = document.getElementById('delete_button');
deleteButton.onclick = function () { removeEvent(eventId.id.substr(6)); calendar.dialog(); return false; }
divAddDialog.style.display = "block";
}
cExecute('../index.php?menuaction=calendar.uicalendar.edit&cal_id='+eventId.id.substr(6)+'&plain=True',handler_embeddedHTML);
}
function removeButtons(eventDiv){
var lnk = document.getElementById('remove_'+eventDiv.id);
var lnk2 = document.getElementById('details_'+eventDiv.id);
if (lnk){
lnk.style.visibility="hidden";
lnk2.style.visibility="hidden";
}
}
function removeEvent (id) {
var handler_removeEvent = function (data) {
var xsl = XMLTools.load('xsl/returnData.xsl?'+ Date.parse(new Date));
var serverRet = xtools.parse(data, xsl);
serverRet = serverRet.substr(serverRet.indexOf('>')+1);
var retStatus = serverRet.substr(0,5);
if (retStatus == "false")
write_msg(get_lang("Error") + ": " + serverRet)
else{
var eventDiv = document.getElementById("event_"+id);
if (viewType == "Day"){
init_ = timeStamp2id(eventDiv.childNodes[1].id).substr(8);
end_ = timeStamp2id(eventDiv.childNodes[2].id).substr(8);
for (var hour = parseInt(init_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30)
screenTable[weekDay][hour]--;
}
eventDiv.parentNode.removeChild(eventDiv);
write_msg(get_lang("Event were deleted"));
}
}
XMLTools.request('$this.uicalendar.removeEvent&id='+id, 'GET', handler_removeEvent);
}
function saveEvent (id, title, description, locat, startTime, endTime){
if (id != null){
return changeEvent(id,'all_fields',locat);
}
var endDate = new Date();
endDate.setTime(id2timeStamp(endTime)+1800000);
var handler_Add = function (data) {
var xsl = XMLTools.load('xsl/returnData.xsl?'+ Date.parse(new Date));
var serverRet = xtools.parse(data, xsl);
serverRet = serverRet.substr(serverRet.indexOf('>')+1);
calendar.dialog('infowindow');
var retStatus = serverRet.substr(0,5);
if (retStatus == "false")
write_msg(get_lang("Error") + ": " +get_lang(serverRet.substr(6)));
else{
var tdElement = document.getElementById(startTime);
var eventDiv = document.createElement('DIV');
eventDiv.id = "event_" + serverRet.substr(6,serverRet.length);
var endDateDiv = document.createElement('DIV');
var startDateDiv = document.createElement('DIV');
endDateDiv.id = endDate.getTime();
startDateDiv.id = id2timeStamp(startTime);
eventDiv.appendChild(startDateDiv);
eventDiv.appendChild(endDateDiv);
eventDiv.innerHTML += title+"
"+description;
createEventDiv(eventDiv);
write_msg(get_lang("Event were added successfully!"));
}
}
XMLTools.request('$this.uicalendar.saveEvent&start='+parseInt(id2timeStamp(startTime)/1000)+'&end='+parseInt(endDate.getTime()/1000)+'&title='+title+'&desc='+description+'&location='+locat, 'GET', handler_Add);
}
function quickAddEvent (title, description, startTime, endTime)
{
var endDate = new Date();
endDate.setTime(id2timeStamp(endTime)+1800000);
var handler_quickAdd = function (data) {
var xsl = XMLTools.load('xsl/returnData.xsl?'+ Date.parse(new Date));
var serverRet = xtools.parse(data, xsl);
serverRet = serverRet.substr(serverRet.indexOf('>')+1);
calendar.dialog('infowindow');
var retStatus = serverRet.substr(0,5);
if (retStatus == "false")
write_msg(get_lang("Error") + ": " +get_lang(serverRet.substr(6)));
else{
var tdElement = document.getElementById(startTime);
var eventDiv = document.createElement('DIV');
eventDiv.id = "event_" + serverRet.substr(6,serverRet.length);
var endDateDiv = document.createElement('DIV');
var startDateDiv = document.createElement('DIV');
endDateDiv.id = endDate.getTime();
startDateDiv.id = id2timeStamp(startTime);
eventDiv.appendChild(startDateDiv);
eventDiv.appendChild(endDateDiv);
eventDiv.innerHTML += title+"
"+description;
createEventDiv(eventDiv);
write_msg(get_lang("Event were added successfully!"));
}
}
XMLTools.request('$this.uicalendar.quickAdd&start='+parseInt(id2timeStamp(startTime)/1000)+'&end='+parseInt(endDate.getTime()/1000)+'&title='+title+'&desc='+description, 'GET', handler_quickAdd);
}
function changeEvent(objEvent,field,value){
init_ = timeStamp2id(objEvent.childNodes[0].id).substr(8);
end_ = timeStamp2id(objEvent.childNodes[1].id).substr(8);
var handler_changeEvent = function (data){
var xsl = XMLTools.load('xsl/returnData.xsl?'+ Date.parse(new Date));
var serverRet = xtools.parse(data, xsl);
serverRet = serverRet.substr(serverRet.indexOf('>')+1);
var retStatus = serverRet.substr(1,5);
if (retStatus == "false")
write_msg(get_lang("Error") + ": " + serverRet)
else
switch (field) {
case 'edatetime':
for (var hour = parseInt(init_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30)
screenTable[weekDay][hour]--;
objEvent.childNodes[1].id = value*1000;
var resizeIcon = document.getElementById("resize_"+objEvent.id);
resizeIcon.parentNode.removeChild(resizeIcon);
createEventDiv(objEvent);
break;
case 'all_fields':
default:
alert(field+': not implemented');
}
}
XMLTools.request('$this.uicalendar.changeEvent&cal_id='+objEvent.id.substr(6)+'&field='+field+'&value='+value, 'GET', handler_changeEvent);
}
// Convert Unix Time Stamp to Div Id used in calendar
function timeStamp2id(timeStamp){
var tmpDate = new Date();
tmpDate.setTime(timeStamp);
return (tmpDate.getYear()+(is_ie?0:1900))+""+
normDec(tmpDate.getDate())+
normDec(tmpDate.getMonth()+1)+
normDec(tmpDate.getHours())+
normDec(tmpDate.getMinutes());
}
// Convert the opposite of function above
function id2timeStamp(id){
objDate = new Date();
objDate.setHours(id.substr(8,2));
objDate.setMinutes(id.substr(10,2));
objDate.setYear(id.substr(0,4));
objDate.setDate(id.substr(4,2));
objDate.setMonth(id.substr(6,2)-1);
return objDate.getTime();
}
function id2String(id){
if (id < 1)
return "";
objDate = new Date();
objDate.setHours(id.substr(8,2));
objDate.setMinutes(id.substr(10,2));
objDate.setYear(id.substr(0,4));
objDate.setDate(id.substr(4,2));
objDate.setMonth(id.substr(6,2)-1);
return objDate.getDate()+"/"+(objDate.getMonth()+1);
}
function get_lang(_key)
{
if (_key == '')
return '';
var key = _key.toLowerCase();
if(array_lang[key])
var _value = array_lang[key];
else
var _value = _key+"*";
if(arguments.length > 1)
for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
_value = _value.replace("%"+j,arguments[j]);
return _value;
}
// Normalize decimal number string
function normDec(value)
{
if (value > 9)
return value.toString();
else
return "0"+value;
}
function resizeEvent (eventDiv) {
_dragArea.pressed = 1;
_dragArea.initEvent = eventDiv.parentNode.id;
_dragArea.resizing = 1;
_dragArea.currentEvent = eventDiv;
}
refreshLang();