/** * @file common/js/xml_handler.js * @author zero * @brief zbxe내에서 ajax기능을 이용함에 있어 module, act를 잘 사용하기 위한 자바스크립트 **/ // xml handler을 이용하는 user function var show_waiting_message = true; function exec_xml(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj) { var oXml = new xml_handler(); oXml.reset(); if(typeof(params)!='undefined') { for(var key in params) { if(!params.hasOwnProperty(key)) continue; var val = params[key]; oXml.addParam(key, val); } } oXml.addParam("module", module); oXml.addParam("act", act); if(typeof(response_tags)=="undefined" || response_tags.length<1) response_tags = new Array('error','message'); oXml.request(xml_response_filter, oXml, callback_func, response_tags, callback_func_arg, fo_obj); } // 결과 처리 후 callback_func에 넘겨줌 function xml_response_filter(oXml, callback_func, response_tags, callback_func_arg, fo_obj) { var xmlDoc = oXml.getResponseXml(); if(!xmlDoc) return null; var waiting_obj = xGetElementById("waitingforserverresponse"); if(waiting_obj) waiting_obj.style.visibility = "hidden"; var ret_obj = oXml.toZMsgObject(xmlDoc, response_tags); if(ret_obj["error"]!=0) { alert(ret_obj["message"]); return null; } if(ret_obj["redirect_url"]) { location.href=ret_obj["redirect_url"]; return null; } if(!callback_func) return null; callback_func(ret_obj, response_tags, callback_func_arg, fo_obj); return null; } // xml handler function xml_handler() { this.objXmlHttp = null; this.method_name = null; this.xml_path = request_uri+"index.php"; this.params = new Array(); this.reset = xml_handlerReset; this.getXmlHttp = zGetXmlHttp; this.request = xml_handlerRequest; this.setPath = xml_handlerSetPath; this.addParam = xml_handlerAddParam; this.getResponseXml = xml_handlerGetResponseXML; this.toZMsgObject = xml_handlerToZMsgObject; this.parseXMLDoc = xml_parseXmlDoc; this.objXmlHttp = this.getXmlHttp(); } function zGetXmlHttp() { if (window.XMLHttpRequest) return new XMLHttpRequest(); else if (window.ActiveXObject) { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { return new ActiveXObject("Microsoft.XMLHTTP"); } } return null; } function xml_handlerRequest(callBackFunc, xmlObj, callBackFunc2, response_tags, callback_func_arg, fo_obj) { var rd = ""; rd += "\n" + "\n" + "\n" for (var key in this.params) { if(!this.params.hasOwnProperty(key)) continue; var val = this.params[key]; rd += "<"+key+">\n"; } rd += "\n" + "\n"; // ssl action if(typeof(ssl_actions)!='undefined' && typeof(ssl_actions.length)!='undefined' && typeof(this.params['act'])!='undefined' && /^https:\/\//i.test(location.href) ) { var action = this.params['act']; for(i=0;i0) { ret_obj[name][ret_obj[name].length] = value; } else { var tmp_value = ret_obj[name]; ret_obj[name] = new Array(); ret_obj[name][ret_obj[name].length] = tmp_value; ret_obj[name][ret_obj[name].length] = value; } } } obj = obj.nextSibling; } return ret_obj; } function xml_handlerToZMsgObject(xmlDoc, tags) { if(!xmlDoc) return null; if(!tags) tags = new Array("error","message"); tags[tags.length] = "redirect_url"; tags[tags.length] = "act"; var parsed_array = this.parseXMLDoc(xmlDoc.getElementsByTagName('response')[0]); var obj_ret = new Array(); for(var i=0; i