Newsgroup: it.comp.lang.javascript
Titolo: Need advise on what to do...

Hello all,
I am really really desperate on what I should do, and I am asking for help
from anyone in this newsgroup, here's the situation:
I am creating a form that is being run on a server where there is no scripts
allowed running (the software is from Opentext called Livelink)- therefore I
need javascript to do the tasks listed below:
1. validate the form - this has been completed
2. pop up another window that will go ahead and confirm the
selections/data - this has been completed.
3. Email the new form data to various users - Not done.
    --> I have tried the MAILTO command in the script which I had working,
except there is some sort of line/character limitation that keeps causing
issues.
    --> I have thought of calling a perl script from another server, but my
FORM is setup to execute the current server exectuable and the METHOD POST
is allocated to that script (livelink.exe) - is there a way to post for 2
different scripts so that I can run the livelink script and the one on the
remote node?
    --> Thought of righting a script that will copy the information to the
clipboard and then to the email body.
--> confused, yeah me to...Basically my worst problem is to create and send
the email automatically (well at least pop up the email with all the data
entered). I have managed to setup the receiver list, Subject and a portion
of the body, but there is apparently to much in the body to work, and it
keeps erroring out.
--> I have also tried taking a script that will create a multi-line text
field in the second window, put the data in there, and copy it to a buffer -
but apparently my management thinks that this might be to much...Therefore I
thought if there is a way that the data from the fields can be copied to a
buffer and when the email window pops up automatcially pasted in that
window....I know confusing...
Anyway below is the code I have so far, hopefully you can get the jest of
what I am trying to accomplish - the main goal is to:
1. have user fill in form
2. 2nd window to pop up with quick summary in it and have user confirm data.
3. submit the data
4. have an email pop up with all the information added, subject,
receiptents, body (with no line/charater limitations).
For the line limitations I had thought that it was do to the fact the line
was to long, then I ran a partial script that put a new line in place after
80 characters.This still failed after - therefore I assume it might be a
mailto limitation...
Code - I have snipped out most of the code to ensure I am not breaking any
"corporate laws" :)
====
var FormIsGood="Yes";
var puHTML_1;
var puHTML_2;
var condition = new Array(100);
var loc_id = new Array(100);
var loc_name = new Array(100);
var conditionCounter;
var locationID;
var locationName;
var formName;
var saveAsName;
var newView;
// Reset variables to initial values
function resetValues(){
  FormIsGood="Yes";
  puHTML_1="";
  puHTML_2="";
  condition[0]="Default";
  conditionCounter=0;
  locationID="";
  locationName="";
  newView="";
}
// Format a date to the prescribed format
function formatDate(year,month,day){
if (year < 0){year='0000'};
if (month < 0){month=0};
if (day < 0){day=0};
dt=year+"/";
if(month < 10){dt=dt+"0"+(month)+"/"}else{dt=dt+(month)+"/"};
if(day < 10){dt=dt+"0"+day}else{dt=dt+day};
return dt;
}
// Set a date field to a desired date
function setToday(year_field,month_field,day_field,dt){
  year_field.value=dt.getFullYear();
  month_field.value=dt.getMonth()+1;
  day_field.value=dt.getDate();
}
// Get and format the date and time now
function getNow(){
  var dt=new Date();
  now=dt.getFullYear()+"/";
  // Javascript months start at 0 - not 1
  if((dt.getMonth()+1) <
10){now=now+"0"+(dt.getMonth()+1)+"/"}else{now=now+(dt.getMonth()+1)+"/"};
  if(dt.getDate() <
10){now=now+"0"+dt.getDate()+"-"}else{now=now+dt.getDate()+"-"};
  if(dt.getHours() <
10){now=now+"0"+dt.getHours()+"."}else{now=now+dt.getHours()+"."};
  if(dt.getMinutes() <
10){now=now+"0"+dt.getMinutes()+"."}else{now=now+dt.getMinutes()+"."};
  if(dt.getSeconds() <
10){now=now+"0"+dt.getSeconds()}else{now=now+dt.getSeconds()};
  return now;
}
// Check for required fields
function required(label, field){
  if(field.value.length == 0){
    FormIsGood="No";
    window.alert(label+' is a required field.  Please enter a value for
it.');
  }
}
// Add conditions for setting the saved form folder location
function setLocation(text,id,nm){
  conditionCounter=conditionCounter+1;
  condition[conditionCounter]=text;
  loc_id[conditionCounter]=id;
  loc_name[conditionCounter]=nm;
}
// Create an HTML string
function addPopupHTML_1(t){
  puHTML_1=puHTML_1+t;
}
// Create an HTML string
function addPopupHTML_2(t){
  puHTML_2=puHTML_2+t;
}
// Set the default storage location
function setDefaultLocation(id,nm){
  condition[0]="Default";
  loc_id[0]=id;
  loc_name[0]=nm;
}
// Find and set the form storage location
function findLocation(text){
  // Set defaults
  locationID=loc_id[0];
  locationName=loc_name[0];
  // Check for a specific location
  for (i=0; i<=conditionCounter; i++)
  {
  if(text==condition[i]){locationID=loc_id[i];locationName=loc_name[i];};
  }
}
// Set a new form view upon submission
function setNewView(view){
  if (view.length > 0){newView=view;};
}
// Implement the Livelink screen bypass
function openPopup(){
// Determine first save or edit save
s = document.myForm.LL_FUNC_VALUES.value;
index1=0;
index2=9999;
index1=s.indexOf("'func'='")+8;
func=s.substr(index1,index2);
index1=0;
index2=func.indexOf(",")-1;
func=func.substr(index1,index2);
// Submit the Livelink webform
document.myForm.submit();
// For the first save, calculate the form name and display the popup screen,
otherwise, don't
if (func!="Form.SaveForm")
{
// Define the code that is sent to the popup screen
// Define the statement to load the info to the Livelink screen
(opener.document)
folder='opener.document.CreateForm.CTT_ID.value="'+locationID+'";opener.document.CreateForm.CTT_PathSaved.value="'+locationName+'";opener.document.CreateForm.CTT_Path.value="'+locationName+'"';
// If a new view has been defined, use it, otherwise use the view that was
used to create the form
if (newView.length >
0){folder=folder+';opener.document.CreateForm.LL_FormView.value="'+newView+'"';}
// Define the HTML for the popup screen, starting with standard HTML
s='<html><head><title>'+saveAsName+'</title></head><body
onblur="self.focus();"> ';
s=s+"<script> ";
//Begin Display summary script
s=s+'  function display_summary(){';
s=s+'  var t;';
s=s+'  var d;';
s=s+'  var label = new Array(100);';
s=s+'  var data = new Array(100);';
s=s+'  var fieldCounter = 0;';
s=s+'  tab="\t";';
s=s+'  cr="\n";';
s=s+'  // Define the output values';
s=s+'  function setField(fieldLabel, fieldData)';
s=s+'  {';
s=s+'  fieldCounter = fieldCounter + 1;';
s=s+'  label[fieldCounter] = fieldLabel;';
s=s+'  data[fieldCounter] = fieldData;';
s=s+'  }';
s=s+'setField("Name:", "'+document.myForm._1_1_3_1.value+"
"+document.myForm._1_1_4_1.value+");';
s=s+' //do not change anything in this section)*******************';
s=s+'  var whole_data ="";';
s=s+'  t="";';
s=s+'  for (i=1; i<=fieldCounter; i++)';
s=s+'  {';
s=s+'    whole_data = whole_data + label[i] +cr+
"==========================" +cr+ data[i]+cr+cr;';
s=s+'  }';
s=s+'document.summary.data_summary.value = whole_data;';
s=s+'}';
//End Display summary script
s=s+'function doSubmit(){opener.document.CreateForm.name.value =
document.temp.name.value;'+folder+';opener.doSubmit(opener.document.CreateForm);window.close();}
';
s=s+'function reload(){window.location.reload( false );} ';
s=s+"</"+"script> ";
// Begin user-defined HTML
s=s+puHTML_1;
// Display the form name as HTML and keep the input field hidden
s=s+'<input type="hidden" name="name" value="'+formName+'"
size="90">'+formName+' ';
s=s+puHTML_2;
// End user-defined HTML
// Display the submit button
s=s+'<form name="temp"> ';
s=s+'<p align="center"><button onClick="doSubmit()">Submit
Form</button>&nbsp;&nbsp;<button
onClick="opener.history.go(-2);self.close()">Cancel</button></p> ';
s=s+'</form>';
s=s+'</body></html> ';
// Popup a screen
var att = 'menubar=yes,scrollbars=no,resizable=yes';
var pu = window.open('','pop',att);
pu.window.moveTo(0,0);
pu.window.resizeTo(screen.Width,screen.Height);
// Write the code to the popup screen
pu.document.write(s);
// Refresh the popup screen to force the screen to stay on top of other
windows by activating the onBlur event
pu.reload();
}
}
function definePopupHTML(){
//+++ Change the following addPopupHTML statements as needed.
addPopupHTML_1('<font size="2" face="Arial">This is a summary of what will
be submitted, please click on "O.K." to accept or "Cancel" to cancel this
submission <br>');
addPopupHTML_1('<font size="2" face="Arial"><b><u><br>File will be saved as:
</u></b>');
addPopupHTML_2('<br><font size="2" face="Arial"><ul>');
addPopupHTML_2('<li>Submitters First Name:
'+document.myForm._1_1_3_1.value+'</li>');
addPopupHTML_2('<li>Submitters Last Name:
'+document.myForm._1_1_4_1.value+'</li>');
}
function setLocations(){
//+++ Update define the setDefaultLocation and setLocation statements as
appropriate
  setDefaultLocation('2005day','12987962','day');
  setLocation('2005month','12987932','Month');
  }
// Specify various values
function setValues(){
  // Specify the form field that determines the form storage location
  // Use "Default" if there is only one possible location
//+++ Update the following statement with the form field or plain text that
specifies the location to save the form
  findLocation(document.myForm._1_1_10_1_year.value+document.myForm._1_1_2_1.value);
  // Define the form name.  This can be anything or any combination of fixed
text, field values, and dates.
  //   Use formatDate(year,month,day) function to return a formatted date
  //   Use the getNow() function to return the current date and time as
formatted text
  //   Use document.myForm._1_1_6_1.value (use an appropriate field
name/number) to use form field values in the form name
//+++ Update the formName equation to define the form name.  You should
include the "Submitted-"+getNow()to ensure no duplicate form names are used.
        //Document name is composed of:
        formName=document.myForm._1_1_2_1.value+'-'+cust_name+'-'+document.myForm._1_1_9_1.value;
    // Define the default name of the file when a user wants to save the
data to their local hard drive.
    //+++ Update the following statement
    saveAsName=document.myForm._1_1_2_1.value+'-'+cust_name+'-'+document.myForm._1_1_9_1.value;
  setNewView("form_ReadOnly");
}
// Validate required fields.  If all required fields are OK, then complete
the form submission.
function submitForm(){
  // Do not change the following line
  resetValues();
//+++ Update, add or remove the required() statements as necessary
//Start of Validation
//=====================
//Ensure the FNAME & LNAME is filled in, even though it is automatic, just
check
//===============================================================================
 required("First Name", document.myForm._1_1_3_1 );
 required("Last Name", document.myForm._1_1_4_1 );
// End of all the validation
  // Do not change the following lines
  setLocations();
  setValues();
  definePopupHTML();
  if (FormIsGood=="Yes"){openPopup()};
}
</javascript>
<FORM  TYPE="HIDDEN" NAME="myForm" ACTION="/livelink/livelink.exe"
ENCTYPE="multipart/form-data" METHOD="POST">
...Snip...
<INPUT TYPE="BUTTON" VALUE="Apply" NAME="IgnoreMe" ONCLICK="submitForm();">

Do you have access to the Livelink SDK? Livelink does have the ability
to email items itself, so you could hook into that. I've done it, and
it wasn't too hard, although it does mean that you need to have
notifications enabled.
Alternative, yes, popup a new window, and submit that form to another
script on the server.
In terms of controlling the Mail client - tricky. I've been trying to
figure out how to do this. If you're dealing with Outlook you could use
ActiveX - provided the customer allows this...
Otherwise, I suspect that you're not going to be able to use the client
mail programme. MAILTO just isn't designed to do that really. It can
handle short bodies, but no formatting, and there is a character limit
on it - according to the specs, 256 characters, but some applications
will handle more (Outlook handles 2 Mb, I read somewhere)