var debug_controller =false; var files = new Array(); var progressBar; var handlerExecuteForm = null; if (document.all) { navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false; is_ie = true; is_moz1_6 = false; is_mozilla = false; is_ns4 = false; } else if (document.getElementById) { navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false; is_ie = false; is_ie5 = false; is_mozilla = true; is_ns4 = false; } else if (document.layers) { is_ie = false; is_ie5 = false; is_moz1_6 = false; is_mozilla = false; is_ns4 = true; } /****************************************** Connector Class *************************************************/ // Constructor function cConnector() { this.requests = new Array(); this.hold_session = false; this.oxmlhttp = null; this.isVisibleBar = false; this.tid = 0; this.progressBar = null; this.oldX = 0; this.oldY = 0; this.updateVersion = ""; this.cacheRequest = false; this.xconnector = new XConnector( { "path" : URL_SERVER, "controller" : "controller.php?action=" } ); }; cConnector.prototype.verify_session = function(data) { if(data && data.nosession){ // If hold session is setted, dont reload the page ... if(expresso.connector.hold_session) { if(typeof(write_msg) == "function" && typeof(get_lang) == "function") write_msg(get_lang("your session could not be verified.")); else alert("your session could not be verified."); } else window.location.reload(); return false; } else return true; }; cConnector.prototype.buildBar = function() { var div = document.getElementById('divProgressBar'); if(! div) { div = document.createElement("DIV"); div.style.visibility = "hidden"; div.style.width = "103px"; div.id = 'divProgressBar'; div.align = "center"; var loadingTitle = document.getElementById('txt_loading'); if (loadingTitle == null) loadingTitle = document.createElement('DIV'); div.innerHTML = '  '+loadingTitle.value+'... '; div.style.background = "#cc4444"; div.style.position = 'fixed'; div.style.top = '0px'; div.style.right = '0px'; document.body.appendChild(div); if(is_ie) { var elem = document.all[div.id]; elem.style.position="absolute"; var root = document.body; var posX = elem.offsetLeft-root.scrollLeft; var posY = elem.offsetTop-root.scrollTop; root.onscroll = function() { elem.style.right = '0px'; elem.style.top = (posY + root.scrollTop) + "px"; }; } if(debug_controller) { div = document.createElement("DIV"); div.style.width = "800px"; div.style.height= "400px"; div.id = "debug_controller"; div.align='right'; document.body.appendChild(div); } } }; //------------------------------------ BEGIN: Functions for Connector HTTPRequest -------------------------------------------------// // Serialize Data Method cConnector.prototype.serialize = function(data) { var _thisObject = this; var f = function(data) { var str_data; if (data == null || (typeof(data) == 'string' && data == '')) { str_data = 'N;'; } else switch(typeof(data)) { case 'object': var arrayCount = 0; str_data = ''; for (i in data) { if (i == 'length') { continue; } arrayCount++; switch (typeof(i)) { case 'number': str_data += 'i:' + i + ';' + f(data[i]); break; case 'string': str_data += 's:' + i.length + ':"' + i + '";' + f(data[i]); break; default: showMessage(Element('cc_msg_err_serialize_data_unknown').value); break; }; } if (!arrayCount) { str_data = 'N;'; } else { str_data = 'a:' + arrayCount + ':{' + str_data + '}'; } break; case 'string': str_data = 's:' + data.length + ':"' + data + '";'; break; case 'number': str_data = 'i:' + data + ';'; break; case 'boolean': str_data = 'b:' + (data ? '1' : '0') + ';'; break; // default: // //showMessage(Element('cc_msg_err_serialize_data_unknown').value); // //return null; }; return str_data; }; return f(data); }; //Unserialize Data Method cConnector.prototype.unserialize = function(str) { _thisObject = this; var matchB = function (str, iniPos) { var nOpen, nClose = iniPos; do { nOpen = str.indexOf('{', nClose+1); nClose = str.indexOf('}', nClose+1); if (nOpen == -1) { return nClose; } if (nOpen < nClose ) { nClose = matchB(str, nOpen); } } while (nOpen < nClose); return nClose; }; var f = function (str) { switch (str.toString().charAt(0)) { case 'a': var data = new Array(); var n = parseInt( str.substring( str.indexOf(':')+1, str.indexOf(':',2) ) ); var arrayContent = str.substring(str.indexOf('{')+1, str.lastIndexOf('}')); for (var i = 0; i < n; i++) { var pos = 0; /* Process Index */ var indexStr = arrayContent.substr(pos, arrayContent.indexOf(';')+1); var index = f(indexStr); pos = arrayContent.indexOf(';', pos)+1; /* Process Content */ var part = null; switch (arrayContent.charAt(pos)) { case 'a': var pos_ = matchB(arrayContent, arrayContent.indexOf('{', pos))+1; part = arrayContent.substring(pos, pos_); pos = pos_; data[index] = f(part); break; case 's': var pval = arrayContent.indexOf(':', pos+2); var val = parseInt(arrayContent.substring(pos+2, pval)); pos = pval + val + 4; data[index] = arrayContent.substr(pval+2, val); break; default: part = arrayContent.substring(pos, arrayContent.indexOf(';', pos)+1); pos = arrayContent.indexOf(';', pos)+1; data[index] = f(part); break; } arrayContent = arrayContent.substr(pos); } break; case 's': var pos = str.indexOf(':', 2); var val = parseInt(str.substring(2,pos)); var data = str.substr(pos+2, val); str = str.substr(pos + 4 + val); break; case 'i': case 'd': var pos = str.indexOf(';'); var data = parseInt(str.substring(2,pos)); str = str.substr(pos + 1); break; case 'N': var data = null; str = str.substr(str.indexOf(';') + 1); break; case 'b': var data = str.charAt(2) == '1' ? true : false; break; }; return data; }; return f(str); }; // Request Constructor Connector cConnector.prototype.newRequest = function (id, target, method, handler, data) { this.xconnector.go( { "access" : target, "handler" : function( data ) { handler( expresso.connector.unserialize( data ) ); }, "cache": expresso.connector.cacheRequest } ); this.cacheRequest=false; }; // Cancel Request Connector cConnector.prototype.cancelRequest = function (){ return false; }; //------------------------------------ END: Functions for Connector HTTPRequest -------------------------------------------------// // ----------------------------------- BEGIN: Functions for build Bar Progress ---------------------------------------------------------// cConnector.prototype.hideProgressBar = function () { var div = document.getElementById('divProgressBar'); div.style.visibility = 'hidden'; this.isVisibleBar = false; }; cConnector.prototype.showProgressBar = function(){ var div = document.getElementById('divProgressBar'); div.style.visibility = 'visible'; this.isVisibleBar = true; }; cConnector.prototype.loadAllScripts = function(scripts) { for(var i = 0; i < scripts.length; i++){ this.loadScript(scripts[i]); } }; cConnector.prototype.loadScript = function(scriptPath) { if (document.getElementById('uploadscript_'+scriptPath)) { return; } var head = document.getElementsByTagName("head")[0]; var script = document.createElement("SCRIPT"); script.id = 'uploadscript_'+scriptPath; script.type = 'text/javascript'; if(is_ie) { this.oxmlhttp.open("GET", URL_SERVER + "expressoMail1_2/js/"+scriptPath+".js?"+this.updateVersion, false); this.oxmlhttp.setRequestHeader('Content-Type','text/plain'); this.oxmlhttp.send(null); if(this.oxmlhttp.status != 0 && this.oxmlhttp.status != 200 || this.oxmlhttp.status == 0 && this.oxmlhttp.responseText.length == 0) throw new Error("Error " + this.oxmlhttp.status + "("+this.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); script.text = this.oxmlhttp.responseText; } else { script.src = URL_SERVER + "expressoMail1_2/js/"+scriptPath+".js?"+this.updateVersion; } head.appendChild(script); return; }; //------------------------------------ END: Functions for Progress Bar -------------------------------------------------// // Default Controller File var URL_DEFAULT = URL_SERVER + "controller.php?menuaction="; // connector object var _onmouseup = document.onmouseup; var isExecuteForm = false; var id = null; cConnector.prototype.cacheNextRequest = function(){ this.cacheRequest=true; }; // Function executes AJAX // cExecute (url, handler, params) // url: 'module.class.method' // handle: function handle() receive response. // params: parameters for POST method // form: form element (for upload files) function cExecute(url, handler, params, form) { if(isExecuteForm){ isExecuteForm = false; document.onmouseup = _onmouseup; } if(form) { cExecuteForm(url, form); return; } //url = URL_DEFAULT + url; if(params) method = "POST"; else method = "GET"; id = url; expresso.connector.newRequest(id, url, method, handler, params); }; // This function executes submit values to Controller (POST) // The return is void. // cExecuteForm (url, form) // url: 'module.class.method' // form: form element (for upload files) function cExecuteForm(url, form, handler,id){ expresso.connector.buildBar(); isExecuteForm = true; document.onmouseup = alertBut; expresso.connector.showProgressBar(); if(! (divUpload = document.getElementById('divUpload'))) { divUpload = document.createElement('DIV'); divUpload.id = 'divUpload'; document.body.appendChild(divUpload); } if(! (el = document.getElementById('_action'))) { el = document.createElement('input'); el.type = 'hidden'; el.id = '_action'; el.name = '_action'; form.appendChild(el); } var divFiles = document.getElementById("divFiles_"+id); if (divFiles && divFiles.firstChild) { el = document.createElement('input'); el.type = 'hidden'; el.name = 'countFiles'; var countDivFiles = 0; try{ countDivFiles = parseInt(divFiles.lastChild.firstChild.id.split('_')[2]) + 1; // The id of last file } catch (e) { var countDivFiles = 0; }; el.value = countDivFiles ; form.appendChild(el); } form._action.value = url; // Connector Bug fixing: Encapsulating returned handler function handlerExecuteForm = handler; var form_handler = function (data){ handlerExecuteForm(data); handlerExecuteForm = null; }; divUpload.innerHTML= ""; form.action = URL_DEFAULT + url; form.target ="uploadFile"; form.submit(); // Connector Bug fixing: Exclude '_action' element after cExecuteForm execution if(el && el.id == '_action'){ el.parentNode.removeChild(el); } }; function alertBut(e) { if(!e) e = window.event; if(_onmouseup) _onmouseup(e); if(isExecuteForm) { if(confirm(get_lang("There's an action processing. Do you want abort it?"))) { expresso.connector.hideProgressBar(); isExecuteForm = false; delete expresso.connector.requests[id]; expresso.connector.requests[id] = null; stop(); return; } else return false; } }; function expressoAjax(){ this.connector = new cConnector(); }; expressoAjax.prototype.require = function (module){ expresso.connector.loadScript(module); }; (function( ) { var sec_key = null; var mod = null; function encode( data ) { var result = ""; var val = ""; var packsize = 3; for (i=0; i < data.length; i+=packsize){ for (j=i; j < i+packsize; j++) if (data.charCodeAt(j) > 1) val += ""+data.charCodeAt(j); else val += "000"; bigVal = int2bigInt(val,50,10); val = ""; bigKey = int2bigInt(sec_key,50,10); bigN = int2bigInt(mod,50,10); bigResult = powMod(bigVal,bigKey,bigN); result += bigInt2str(bigResult,10)+" "; } return result; } function crypt( input, modulus ) { sec_key = input; mod = modulus; } crypt.prototype.encode = encode; window.crypt = crypt; })( ); expressoAjax.prototype.crypt = new crypt(keys[0],keys[1]); delete(keys); var expresso = new expressoAjax();