Files
Testing/mailservices/admin/js/process_forms.js

831 lines
20 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
var submitlock=0;
var submitlocklength=500;
var submitlocktimeout=0;
var formerrors=0;
function submit_the_form(formname)
{
nogo=0;
theinput=document.getElementById(formname).getElementsByTagName('input');
for(var i=0;i< theinput.length; i++)
{
input_class=theinput[i].className; // input's className
input_id=theinput[i].id; //input's id
pat=new RegExp(theinput[i].getAttribute('pattern')); //input's pattern attribute if any
req=theinput[i].getAttribute('required'); // inputs required attribute if any
emf="e_" + input_id;
emf=document.getElementById(emf); // input's error message containter
if(input_class.search('text') != -1)
{
}
//phone numbers us 10 digit with various formats - reformat if valid
// if it has no value check to see if required and set nogo
// if has value and it validates go on
// if has value and does not validate and is required set nogo
if(input_class.search('phone') != -1)
{
ivalue=theinput[i].value;
if(ivalue=="")
{
//check to see if it is required and if it is display error message on field and set no go
if(req==1)
{
}
}
else
{
if(pat != null)
{
if(validate_input(pat,ivalue))
{
alert("cool on phone");
rfvalue=ivalue.replace(pat, "($1) $2-$3");
theinput[i].value=rfvalue;
emf.style.display="none";
//no action required
}
else
{
//alert("not cool on phone");
if(req==1)
iwidth=document.getElementById(input_id).offsetWidth;
ileft=document.getElementById(input_id).offsetLeft;
emf.style.width=(iwidth - 12) + "px";
emf.style.left=ileft + "px";
emf.style.display="block";
//document.getElementById(input_id).focus();
document.getElementById(input_id).style.backgroundColor='pink';
//input_w=document.getElementById&&!document.all?window.innerHeight:document.documentElement.clientHeight;
//check to see if it is required
} // if valideate
} // if pat exists
} // if has value
} // end if phone
if(input_class.search('zip') != -1)
{
}
if(input_class.search('email') != -1)
{
}
if(input_class.search('int') != -1)
{
}
} // for
}
function validate_input(pat,ivalue)
{
m = pat.exec(ivalue);if(m==null){return false;} else {return true;}
}
function display_error(iid)
{
iwidth=document.getElementById(iid).offsetWidth;
ileft=document.getElementById(iid).offsetLeft;
emf="e_" + iid;
emf=document.getElementById(emf); // input's error message containter
emf.style.width=(iwidth - 12) + "px";
emf.style.left=ileft + "px";
emf.style.display="block";
document.getElementById(iid).style.backgroundColor='pink';
}
function submit_form_item(iid,thecontainer,theurl,thetable,emsg,enc,mn,mx)
{
submitlock=1;
if(typeof emsg == 'undefined') {emsg = '';}
if(typeof mn == 'undefined') {mn = '';}
if(typeof mx == 'undefined') {mx = '';}
if(typeof enc == 'undefined') {enc = 'Y';}
theinput=document.getElementById(iid);
input_class=theinput.className; // input's className
dtype=input_class;
input_id=iid; //input's id
patexist=theinput.getAttribute('pattern');
pat=new RegExp(theinput.getAttribute('pattern')); //input's pattern attribute if any
req=theinput.getAttribute('required'); // inputs required attribute if any
emf="e_" + iid;
emf=document.getElementById(emf); // input's error message containter
ivalue=theinput.value;
ovalue="o_" + iid;
ovalue=document.getElementById(ovalue).value;
emf.innerHTML=emsg;
if(input_class.search('text') != -1 || input_class.search('email') != -1 || input_class.search('password') != -1)
{
if(input_class.search('text') != -1){dtype="text";}
if(ivalue=="")
{
//check to see if it is required and if it is display error message on field and set no go
if(req != null)
{
display_error(iid);
}
else
{
theinput.style.backgroundColor="#f7f7f7";
emf.style.display="none";
//update
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
}// req not eq null
}//if ivalue blank
else
{
if(ivalue != ovalue){
if(patexist != null)
{
if(validate_input(pat,ivalue))
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
//no action required
}
else
{
display_error(iid);
} // if validate
} // if pat exists
else
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
} // if no pat
} // if ivalue != ovalue
}// if has a value
}//end if text
//phone numbers us 10 digit with various formats - reformat if valid
if(input_class.search('phone') != -1)
{
if(ivalue=="")
{
//check to see if it is required and if it is display error message on field and set no go
if(req==1)
{
display_error(iid);
}
else
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
}
}
else
{
if(pat != null)
{
if(validate_input(pat,ivalue))
{
rfvalue=ivalue.replace(pat, "($1) $2-$3");
theinput.value=rfvalue;
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
}
else
{
display_error(iid);
} // if validate
} // if pat exists
} // if has value
} // end if phone
if(input_class.search('zip') != -1)
{
}
if(input_class.search('int') != -1)
{
}
if(input_class.search('radio') != -1)
{
radin=document.forms[0].elements[iid];
for(var i = 0; i < radin.length; i++)
{
if(radin[i].checked)
{
ivalue=radin[i].value;
}
}
if(ovalue != ivalue)
{
dtype="radio";
update_field(iid,ivalue,ovalue,dtype,req,theurl,thetable,enc);
}
}// end radio
}
function check_form_item(iid,emsg)
{
submitlock=1;
theinput=document.getElementById(iid);
input_class=theinput.className; // input's className
dtype=input_class;
input_id=iid; //input's id
patexist=theinput.getAttribute('pattern');
pat=new RegExp(theinput.getAttribute('pattern')); //input's pattern attribute if any
req=theinput.getAttribute('required'); // inputs required attribute if any
emf="e_" + iid;
emf=document.getElementById(emf); // input's error message containter
ivalue=theinput.value;
ovalue="o_" + iid;
ovalue=document.getElementById(ovalue).value;
emf.innerHTML=emsg;
if(input_class.search('text') != -1 || input_class.search('email') != -1 || input_class.search['password'] != -1)
{
if(input_class.search('text') != -1){dtype="text";}
if(ivalue=="")
{
//check to see if it is required and if it is display error message on field and set no go
if(req != null)
{
display_error(iid);
}
else
{
theinput.style.backgroundColor="#f7f7f7";
emf.style.display="none";
submitlock=0;
//update
}// req not eq null
}//if ivalue blank
else
{
if(patexist != null)
{
if(validate_input(pat,ivalue))
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
submitlock=0;
//no action required
}
else
{
display_error(iid);
} // if validate
} // if pat exists
else
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
submitlock=0;
} // if no pat
}// if has a value
}//end if text
//phone numbers us 10 digit with various formats - reformat if valid
if(input_class.search('phone') != -1)
{
if(ivalue=="")
{
//check to see if it is required and if it is display error message on field and set no go
if(req==1)
{
display_error(iid);
}
else
{
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
submitlock=0;
}
}
else
{
if(pat != null)
{
if(validate_input(pat,ivalue))
{
rfvalue=ivalue.replace(pat, "($1) $2-$3");
theinput.value=rfvalue;
emf.style.display="none";
theinput.style.backgroundColor="#f7f7f7";
submitlock=0;
}
else
{
display_error(iid);
} // if validate
} // if pat exists
} // if has value
} // end if phone
if(input_class.search('zip') != -1)
{
}
if(input_class.search('int') != -1)
{
}
}
function display_error_proccess_error(iid,errormsg)
{
emf="e_" + iid;
emf=document.getElementById(emf).innerHTML=errormsg;
display_error(iid);
}
function update_field(field,fvalue,origvalue,dtype,req,doc,thetable,enc,mn,mx){
if(typeof thetable == 'undefined') { thetable = 'users';}
if(typeof mn == 'undefined') {mn = '';}
if(typeof mx == 'undefined') {mx = '';}
errorfield="e_" + field;
errorfield=document.getElementById(errorfield);
var oXMLHttpRequest = new XMLHttpRequest;
nc=gnc();
params="fieldname=" + field + "&fieldvalue=" + fvalue + "&origvalue=" + origvalue + "&dtype=" + dtype + "&req=" + req + "&thetable=" + thetable + "&min=" + mn + "&max=" + mx + "&ncrypt=" + enc;
oXMLHttpRequest.open("POST", doc + "?nc=" + nc + "", true);
oXMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oXMLHttpRequest.setRequestHeader("Content-length", params.length);
oXMLHttpRequest.setRequestHeader("Connection", "close");
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
alert(oXMLHttpRequest.responseText);
// thearray=oXMLHttpRequest.responseText;
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["error"] != "")
{
display_error_proccess_error(field,jsonT["error"]);
submitlock=1;
}
else
{
errorfield.style.display="none";
submitlock=0;
}
}//end ct
} // ready state done
} // readystatechange
oXMLHttpRequest.send(params);
}
////////////////////user rights
var rights_admin_error_field="";
function update_rights(field,req,em,doc,thetable,rn,adm,gid)
{
if(typeof thetable == 'undefined') { thetable = 'user_group';}
fvalue=document.getElementById(field).checked;
if(fvalue==true)
{
fvalue="Y";
}
else
{
fvalue="N";
}
if(adm==1)
{
gcb="group_" + rn;
gcbcheck=document.getElementById(gcb).checked;
if(gcbcheck==false && fvalue=="Y")
{
gacb="group_admin_" + rn;
document.getElementById(gacb).checked=false;
return false;
}
if(gcbcheck==true)
{
submitlock=1;
update_rights_field('admin',fvalue,rn,gid,doc,thetable)
}
}
if(adm==0)
{
fvalue=document.getElementById(field).checked;
if(fvalue==true)
{
fvalue="Y";
}
else
{
gacb="group_admin_" + rn;
fvalue="N";
document.getElementById(gacb).checked=false;
}
submitlock=1;
update_rights_field('gid',fvalue,rn,gid,doc,thetable);
}
}
function update_rights_field(field,fvalue,rn,gid,doc,thetable){
if(typeof thetable == 'undefined') { thetable = 'user_groups';}
var oXMLHttpRequest = new XMLHttpRequest;
nc=gnc();
params="fieldname=" + field + "&fieldvalue=" + fvalue + "&gid=" + gid + "&thetable=" + thetable;
oXMLHttpRequest.open("POST", doc + "?nc=" + nc + "", true);
oXMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oXMLHttpRequest.setRequestHeader("Content-length", params.length);
oXMLHttpRequest.setRequestHeader("Connection", "close");
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
// alert(oXMLHttpRequest.responseText);
// thearray=oXMLHttpRequest.responseText;
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["error"] != "")
{
submitlock=1;
}
else
{
submitlock=0;
}
}//end ct
} // ready state done
} // readystatechange
oXMLHttpRequest.send(params);
}
/////end user rights
/////////////submit form
function submit_form(formname,doc)
{
if(submitlock == 0)
{
clearTimeout(submitlocktimeout);
if(checkdirtyform(formname))
{
submit_form_act(formname,doc);
}
else
{
return false;
}
}
if(submitlock > 0 && submitlock <6)
{
submitlock=submitlock+1;
submitlocktimeout=setTimeout(function(){submit_form(formname,doc)}, submitlocklength);
return false;
}
if(submitlock == 6)
{
submitlock = 0;
submitlocktimeout=setTimeout(function(){submit_form(formname,doc)}, submitlocklength);
return false;
}
}
function submit_group_add_form(formname,doc)
{
if(submitlock == 0)
{
clearTimeout(submitlocktimeout);
if(checkdirtyform(formname))
{
submit_group_add_form_act(formname,doc);
}
else
{
clearTimeout(submitlocktimeout);
submitlock=0;
return false;
}
}
if(submitlock > 0 && submitlock <6)
{
submitlock=submitlock+1;
submitlocktimeout=setTimeout(function(){submit_group_add_form(formname,doc)}, submitlocklength);
return false;
}
if(submitlock == 6)
{
submitlock = 0;
submitlocktimeout=setTimeout(function(){submit_group_add_form(formname,doc)}, submitlocklength);
return false;
}
}
function submit_group_add_form_act(formname,doc)
{
var fd=jQuery('#'+formname+'').serialize();
//doc="/admin/usermgr/add_user_act.php";
var oXMLHttpRequest = new XMLHttpRequest;
nc=gnc();
params=fd;
oXMLHttpRequest.open("POST", doc + "?nc=" + nc + "", true);
oXMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oXMLHttpRequest.setRequestHeader("Content-length", params.length);
oXMLHttpRequest.setRequestHeader("Connection", "close");
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
alert(oXMLHttpRequest.responseText);
// thearray=oXMLHttpRequest.responseText;
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["error"]=="")
{
gettabcontent('/mailservices/admin/usermgr/groups.php','section_content','two','admin_tabs');
}
}//end ct
} // ready state done
} // readystatechange
oXMLHttpRequest.send(params);
}
function checkdirtyform(formname)
{
subform=1;
emsgs=document.getElementById(formname).getElementsByClassName('errormsg');
for(var i=0;i< emsgs.length; i++)
{
if(emsgs[i].style.display=="block")
{
//diplay warning;
subform=0;
break;
}
} // end check for existing error messages
finps=document.getElementById(formname).getElementsByTagName('input');
for(var j=0;j< finps.length; j++)
{
req=finps[j].getAttribute('required');
if(req != null)
{
if(finps[j].value=="")
{
display_error(finps[j].id);
subform=0;
continue;
}
}
}// end check input
if(subform==1){return true;} else{return false;}
}
function submit_form_act(formname,doc)
{
var fd=jQuery('#'+formname+'').serialize();
//doc="/admin/usermgr/add_user_act.php";
var oXMLHttpRequest = new XMLHttpRequest;
nc=gnc();
params=fd;
oXMLHttpRequest.open("POST", doc + "?nc=" + nc + "", true);
oXMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oXMLHttpRequest.setRequestHeader("Content-length", params.length);
oXMLHttpRequest.setRequestHeader("Connection", "close");
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
alert(oXMLHttpRequest.responseText);
// thearray=oXMLHttpRequest.responseText;
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
}//end ct
} // ready state done
} // readystatechange
oXMLHttpRequest.send(params);
}
function submit_update_user(formname,msgcont)
{
if(submitlock == 0)
{
clearTimeout(submitlocktimeout);
if(checkdirtyform(formname))
{
//show all cool message
document.getElementById(msgcont).innerHTML="The user account has been updated";
}
else
{
document.getElementById(msgcont).innerHTML="Errors were encountered updating this user account. Please check " +
"the error message under the any fields with pink backgrounds for additional information.";
}
}
if(submitlock > 0 && submitlock <6)
{
submitlock=submitlock+1;
submitlocktimeout=setTimeout(function(){submit_update_user(formname,msgcont)}, submitlocklength);
return false;
}
if(submitlock == 6)
{
submitlock = 0;
submitlocktimeout=setTimeout(function(){submit_update_user(formname,msgcont)}, submitlocklength);
return false;
}
}
function update_email_notification_field(field,fvalue,doc)
{
dtype="notification";
if(typeof thetable == 'undefined') { thetable = 'se_usersettings';}
var oXMLHttpRequest = new XMLHttpRequest;
nc=gnc();
params="fieldname=" + field + "&fieldvalue=" + fvalue + "&dtype=" + dtype + "&thetable=" + thetable;
oXMLHttpRequest.open("POST", doc + "?nc=" + nc + "", true);
oXMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oXMLHttpRequest.setRequestHeader("Content-length", params.length);
oXMLHttpRequest.setRequestHeader("Connection", "close");
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
alert(oXMLHttpRequest.responseText);
// thearray=oXMLHttpRequest.responseText;
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["error"] != "")
{
}
}//end ct
} // ready state done
} // readystatechange
oXMLHttpRequest.send(params);
}
function update_email_notification(field,doc)
{
fvalue=document.getElementById(field).checked;
if(fvalue==true)
{
fvalue="Y";
}
else
{
fvalue="N";
}
update_email_notification_field(field,fvalue,doc)
}
function verify_email_format_domain(val,resled)
{
pat=new RegExp(document.getElementById(resled).getAttribute('pattern'));
if(!validate_input(pat,val))
{
document.getElementById(resled).style.color="red";
}
else
{
verify_email_doamin(val,resled);
}
}
function verify_email_doamin(ma,resled)
{
doc="/mailservices/bateworld/verify_email.php";
nc=gnc();
var oXMLHttpRequest = new XMLHttpRequest;
//document.getElementById(container).innerHTML="<div style=\"text-align:center;\">Loading...</div>";
nc=gnc();
oXMLHttpRequest.open("GET", doc + "?emailaddress=" + ma + "&nc=" + nc + "", true);
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
//alert(oXMLHttpRequest.responseText);
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["result"]=="good")
{
document.getElementById(resled).style.color="green";
}
if(jsonT["result"]=="bad")
{
document.getElementById(resled).style.color="red";
}
}
}
}
oXMLHttpRequest.send(null);
}
function smtp_validate_internal(val,resled)
{
nc=gnc();
doc="/mailservices/bateworld/smtp_validate.php";
var oXMLHttpRequest = new XMLHttpRequest;
//document.getElementById(container).innerHTML="<div style=\"text-align:center;\">Loading...</div>";
nc=gnc();
oXMLHttpRequest.open("GET", doc + "?emailaddress=" + val + "&nc=" + nc + "", true);
oXMLHttpRequest.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
alert(oXMLHttpRequest.responseText);
var ct=oXMLHttpRequest.getResponseHeader('Content-Type');
if(ct=="application/json")
{
jsonT = eval("("+ oXMLHttpRequest.responseText +")");
if(jsonT["result"]=="cool")
{
document.getElementById(resled).style.color="green";
}
if(jsonT["result"]=="not cool")
{
document.getElementById(resled).style.color="red";
}
}
}
}
oXMLHttpRequest.send(null);
}