Pandora - Sample - Save Current User and Company

From SmartWiki
Jump to: navigation, search

Sample = Save Current User and Company

The following function provides the ability to save a current user and company. This is a fully functional page.

Sample Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<HTML>
  <HEAD>
    <TITLE></TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="/css/styles_common.jsp">
<style type="text/css">
input {border: 1px solid #aaaaff;}
input.clear {border: none;}
</style>
 
<SCRIPT type="text/javascript" language=JavaScript src="/Ajax/uta/uta.js"></SCRIPT>
<script language="javaScript">
ss_developer_key="9KbwtNK4LPJRFEO6KaHr0dGCgPz+2ycZENBfEc2H1Qw=";
//---------------------------------------Get record---------------------------
function loaddata()
{ rs= session_islogin(false ,''); 
  if(rs.getfieldbyname(1,'userid')=='-1')
   alert('This page is for authorized user only.')
 else{ var d=document.getElementById('profile');
   d.style.visibility='visible';
   d.style.display='block';
   showstatus('Request Contact Information');
   session_getuser(true,'al',"firstname,lastname,email,title");
   showstatus('Request Company Information');
  session_getcompany(true,'al2',null);
  }
 }
 
function al(records)
{if (records.recordcount>0){
    showstatus('Parsing contact record ...');
  frm=document.forms[0];
  frm.userid.value=records.getfieldbyname(1,'userid'); 
  frm.firstname.value=records.getfieldbyname(1,'firstname');
  frm.lastname.value=records.getfieldbyname(1,'lastname');
  frm.email.value=records.getfieldbyname(1,'email');
  frm.title.value=records.getfieldbyname(1,'title');
   showstatus('Done');
  }
}
function al2(records)
{if (records.recordcount>0){
   showstatus('Parsing company record ...');
  frm=document.forms[0];
  frm.companyid.value=records.getfieldbyname(1,'companyid');
  frm.cname.value=records.getfieldbyname(1,'name');
  frm.caddress.value=records.getfieldbyname(1,'address');
  frm.caddress2.value=records.getfieldbyname(1,'address2');
  frm.cprovince.value=records.getfieldbyname(1,'state');
  frm.ccity.value=records.getfieldbyname(1,'city');
  frm.cphone.value=records.getfieldbyname(1,'phone');
  showstatus('Done');
  }
}
function al6(records)
{if (records.recordcount>0){ 
   showstatus('Parsing level 1 record ...');
  frm=document.forms[0];
  frm.subject.value=records.getfieldbyname(1,'name');
  frm.cf_567091.value=records.getfieldbyname(1,'cf_567091');
    showstatus('Done');
  }
}
//---------------------------------------Save record---------------------------
function saverecord()
{ frm=document.forms[0];
  saveuser(frm);
  savecompany(frm);
 }
 
function saveuser(frm)
{ var rset=new ssRecordSet(null);
    showstatus('Saving Contact info ....');
   rset.addfieldnames("userid,firstname,lastname,email,title");
   var idx=rset.getnewrecnumber();
   rset.addfieldvaluebyname(idx,'userid',frm.userid.value);
   rset.addfieldvaluebyname(idx,'firstname',frm.firstname.value);
   rset.addfieldvaluebyname(idx,'lastname',frm.lastname.value);
   rset.addfieldvaluebyname(idx,'email',frm.email.value);
   rset.addfieldvaluebyname(idx,'title',frm.title.value);
    contact_update(true,'al3',rset);
}
 
function savecompany(frm)
{ var rset=new ssRecordSet(null);
   showstatus('Saving Company info ....');
   rset.addfieldnames("companyid,name,address,address2,city,state,phone");
   var idx=rset.getnewrecnumber();
   rset.addfieldvaluebyname(idx,'companyid',frm.companyid.value);
   rset.addfieldvaluebyname(idx,'name',frm.cname.value);
   rset.addfieldvaluebyname(idx,'address',frm.caddress.value);
   rset.addfieldvaluebyname(idx,'address2',frm.caddress2.value);
   rset.addfieldvaluebyname(idx,'city',frm.ccity.value);
   rset.addfieldvaluebyname(idx,'state',frm.cprovince.value);
   rset.addfieldvaluebyname(idx,'phone',frm.cphone.value);
   company_update(true,'al4',rset);
}
 
function al3(records)
{ if (records.recordcount>0)
   showstatus('Contact record saved successfully. Ref#='+records.getfieldbyname(1,'userid'));
  else
   showstatus('Save Error. Error #='+records.getfieldbyname(1,'msg'));
}
 
function al4(records)
{ if (records.recordcount>0)
   showstatus('Company record saved successfully.Ref#='+records.getfieldbyname(1,'companyid'));
  else
   showstatus('Save Error. Error #='+records.getfieldbyname(1,'msg'));
}
 

function showstatus(s)
{  document.forms[0].txtstatus.value=s;
}
</script>
  </HEAD>
  <BODY bgcolor='#FFFFFF' onload="loaddata()">
<br><br>
<div id=profile style="display:none;visibility:hidden">
<form>
<input type=hidden name=userid value="">
<input type=hidden name=companyid value="">
 
<center>
<table width=500px >
 
<tr><th colspan=2 align=left><big>My Team Profile</big></th></tr>
 
<tr><th>Name</th><td><input type=text name=cname value=""
size=50></td></tr>
 
<tr><th>Address</th><td><input type=text name=caddress value=""
size=50></td></tr>
 
<tr><th>Address 2</th><td><input type=text name=caddress2 value=""
size=50></td></tr>
 
<tr><th>City</th><td><input type=text name=ccity value=""
size=50></td></tr>
 
<tr><th>Province</th><td><input type=text name=cprovince value=""
size=50></td></tr>
 
<tr><th>Phone</th><td><input type=text name=cphone value=""
size=50></td></tr>
 

<tr><th colspan=2  align=left><big>My Profile</big></th></tr>
 
<tr><th>First Name</th><td><input type=text name=firstname value=""
size=50></td></tr>
 
<tr><th>Last Name</th><td><input type=text name=lastname value=""
size=50></td></tr>
 
<tr><th>Email</th><td><input type='text' name='email' value="" size=50></td></tr>
 
<tr><th>Title</th><td><input type=text name=title value="" size=50></td></tr>
 
<tr><th colspan=2> </th></tr>
<tr><th colspan=2><input type=button value="Save Record" onclick="saverecord()"></th></tr>
<tr><th colspan=2> </th></tr>
<tr><th colspan=2><input size='80' type=text style="background-color:#ffffaa" name=txtstatus value="Status ......"></th></tr>
</table>
 
</form> 
</div> 
  </BODY>
</HTML>