<html>
<head>
</head>
<body>
<script language="javascript">
// *****************************************************
// *****************************************************
// *****************************************************
// *****************************************************
// this can be in a js file to be included in a html page
// *****************************************************
// *****************************************************
// *****************************************************
// *****************************************************
function appt( Subject, Location, Start,End, ReminderMinutesBeforeStart,BillingInformation, toUpdate ){
// TODO: strAddrecip is the text displayed when the user is asked if he or she wants to add recipients in theire outlook appt
// TODO: to use Billing Information to fill out a unique number (database) so the web application can find it later
// is not one of the most stable ways but since FileAs is not available this seems appropriate (for lack of better)
this.strAddrecip = "You want to add the attandees in your outlook calendar?";
this.Subject = Subject;
this.Location = Location;
this.Start = Start;
this.End = End;
this.ReminderMinutesBeforeStart = ReminderMinutesBeforeStart;
this.ItemType = 1;
this.Recipients = new Array();
this.BillingInformation = BillingInformation
this.toUpdate = toUpdate
this.AppointmentItem = null;
this.addRecipient = function(strName){
this.Recipients[this.Recipients.length] = strName;
}
this.saveInOutlook = function(){
/* Create the Outlook Object and Appointment Item */
// TODO: try and catch this, when caught the client
// probably has a security restriction
out = new ActiveXObject( "Outlook.Application" );
// Do not insert the item if an item with the same billing information allready exist
var f = out.GetNamespace("MAPI").GetDefaultFolder(9);
var aItem = f.Items.Find("[BillingInformation] = \"" + this.BillingInformation + "\"");
if(aItem!=null){
if(this.toUpdate==0){ // item is to be inserted, check if it exist allready
// TODO: make this a slick looking modaldialog
alert("Item allready exist");
return;
}
}
/* Create an Appointment Item */
if(this.toUpdate==0){
aItem = out.CreateItem(this.ItemType);
}else{
aItem = this.AppointmentItem;
}
/* Transfer the data */
aItem.Subject = this.Subject;
aItem.Location = this.Location;
aItem.Start = this.Start;
aItem.End = this.End;
aItem.ReminderMinutesBeforeStart = this.ReminderMinutesBeforeStart;
aItem.BillingInformation = this.BillingInformation;
// TODO: replace the confirm with a slick looking modal dialog
if(this.Recipients.length!=0){
if(confirm(this.strAddrecip)){
var i = 0
while(i<this.Recipients.length){
try{
aItem.Recipients.Add (this.Recipients[i]).resolve;
}catch(e){
// TODO: make this a slick modaldialog enabling the uer for a 2nd change in getting the user to invite
alert(e.message);
}
i++;
}
aItem.MeetingStatus = 1
// aItem.Display();
aItem.Send();
return;
}
}
aItem.Save();
/* If you want to save instead of viewing it change to aItem.Save();*/
}
this.upDate = function(){
// TODO: try and catch this, when caught the client
// probably has a security restriction
out = new ActiveXObject( "Outlook.Application" );
var f = out.GetNamespace("MAPI").GetDefaultFolder(9);
var aItem = f.Items.Find("[BillingInformation] = \"" + this.BillingInformation + "\"");
if(aItem!=null){
this.AppointmentItem = aItem;
this.saveInOutlook();
}else{
// TODO: make this a slick looking modaldialog
alert("Could not update the appointment item");
}
}
this.checkDateFormat = function(){
// TODO: try and catch this, when caught the client
// probably has a security restriction
out = new ActiveXObject( "Outlook.Application" );
aItem = out.CreateItem(1);
aItem.Start="01-03-2005";
var d = new Date(aItem.Start);
aItem.Close(1);
if(d.getMonth()==2){
return "dmy";
}else{
return "mdy";
}
}
}
// *****************************************************
// *****************************************************
// *****************************************************
// *****************************************************
// page specific code to enter the appointment in a calendar
// *****************************************************
// *****************************************************
// *****************************************************
// *****************************************************
function saveCalItem(forUpdate){
var fru = new Number(forUpdate);
var ds = new Date(document.getElementById("txtdteStart").value) // verry verry unwize to let a user type a date, this should be a (popup) calendar
if(ds=="NaN"){
alert("Value for start date is not valid");
return;
}
var de = new Date(document.getElementById("txtdteEnd").value) // verry verry unwize to let a user type a date, this should be a (popup) calendar
if(de=="NaN"){
alert("Value for End date is not valid");
return;
}
var start = ""; // string value that will be passed to Outlook serving as the start date
var end = ""; // string value that will be passed to Outlook serving as the end date
var subj = document.getElementById("txtSubject").value;
var loc = document.getElementById("txtLocation").value;
// check local settings, if local settings are
// dmy than reverse the day and month value
var tmpCal = new appt(null,null,null,null,null,null,null);
// TODO: getyear has been made y2k compient by MS and netscape (it now returns 4 digit number)
// later it has been removed from java specs alltoghether and replaced with getFullYear but
// getFullYear might not be available in all browsers (IE6 has no problems with it)
if(tmpCal.checkDateFormat()=="mdy"){
// format is mdy
start = new String(ds.getMonth() + 1) + "-" + new String(ds.getDate()) + "-" + new String(ds.getFullYear()) + " " + new String(document.getElementById("lstHourStart").value) + ":" + new String(document.getElementById("lstMinutesStart").value);
end = new String(de.getMonth() + 1) + "-" + new String(de.getDate()) + "-" + new String(de.getFullYear()) + " " + new String(document.getElementById("lstHourEnd").value) + ":" + new String(document.getElementById("lstMinutesEnd").value);
}else{
start = new String(ds.getDate()) + "-" + new String(ds.getMonth() + 1) + "-" + new String(ds.getFullYear()) + " " + new String(document.getElementById("lstHourStart").value) + ":" + new String(document.getElementById("lstMinutesStart").value);
end = new String(de.getDate()) + "-" + new String(de.getMonth() + 1) + "-" + new String(de.getFullYear()) + " " + new String(document.getElementById("lstHourEnd").value) + ":" + new String(document.getElementById("lstMinutesEnd").value);
}
// Note that the toUpdate value here is set to 1
var o = new appt(subj,loc,start,end,"5","unique ID of the MRRS with some description",fru);
// currently I don't want to bother with code retreiving all selected users but it is possible to do so'
if(document.getElementById("lstUsers").value!="none"){
// var i = 0;
// while i < selectlist.items.........
o.addRecipient(document.getElementById("lstUsers").value);
}
if(fru==1){
o.upDate();
}else{
o.saveInOutlook();
}
}
</script>
<table>
<tr>
<td colspan=2>
Subject: <input type=text id="txtSubject" value="dinner">
</td>
</tr>
<tr>
<td colspan=2>
Location: <input type=text id="txtLocation" value="home or some terras">
</td>
</tr>
<tr>
<td>
Start Date (mdy) <input type=text id="txtdteStart" value="26 may 2005" >
</td>
<td>
Time:
<select name="lstHourStart" id="lstHourStart" tabindex="1" >
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option selected="selected" value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18" selected>18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
</select>
<select name="lstMinutesStart" id="lstMinutesStart" tabindex="2" >
<option selected="selected" value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
</td>
</tr>
<tr>
<td>
End Date (mdy) <input type=text id="txtdteEnd" value="5-26-2005" >
</td>
<td>
Time:
<select name="lstHourEnd" id="lstHourEnd" tabindex="1" >
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option selected="selected" value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19" selected>19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
</select>
<select name="lstMinutesEnd" id="lstMinutesEnd" tabindex="2" >
<option selected="selected" value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
</td>
</tr>
<tr>
<td colspan=2>
<select name="lstUsers" size="4" id="lstUsers">
<option value="none" selected>none</option>
<option value="some.name@somecompany.com">Harm Meijer</option>
</select>
</td>
</tr>
</table>
<input type=button onclick="saveCalItem(0);" value="Click here to add the item to your calendar" />
<input type=button onclick="saveCalItem(1);" value="Click here to update the item to your calendar" />
</body>
</html>