
<%@ page language="java" contentType="application/json" pageEncoding="UTF-8"%>
<%@page import="net.sf.json.*"%>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.file.*" %>
<%@ page import="weaver.conn.*" %>
<%@ page import="weaver.mobile.rong.*" %><%@ page import="weaver.security.classLoader.ReflectMethodCall"%>
<jsp:useBean id="ps" class="weaver.mobile.plugin.ecology.service.PluginServiceImpl" scope="page" />
<%
	response.setContentType("application/json;charset=UTF-8");

	FileUpload fu = new FileUpload(request); 
	String type = Util.null2String(fu.getParameter("type"));
	
	Map result = new HashMap();
	
	if("checkPluginFile".equalsIgnoreCase(type)) {
		String fileHash = fu.getParameter("fileHash");
		result = ps.checkPluginFile(fileHash);
	} else if("mobileSetting".equalsIgnoreCase(type)) {
		String settings = fu.getParameter("settings");
		if(settings!=null){
			ReflectMethodCall rmc = new ReflectMethodCall();
			Boolean res = (Boolean)rmc.call("weaver.security.validators.MobileSettingsValidator","validate", new Class[]{String.class, String.class,String.class}, "/mobile/plugin/CheckServer.jsp", "settings", settings);
		    if(res!=null && !res){
		        result.put("status",false);
		        result.put("msg","error");
		    }else{
		        result = ps.syncMobileSetting(settings, "0");
		    }
		}else{
		    result = ps.syncMobileSetting(settings, "0");
		}
	} else if("serverSetting".equalsIgnoreCase(type)){
		RongConfig rc = RongService.getRongConfig();
	    result.put("rongAppUDID", rc.getAppUDID());
	    result.put("rongAppKey", rc.getAppKey());
	    result.put("rongAppSecret", rc.getAppSecret());
	    result.put("rongAppUDIDNew", rc.getAppUDIDNew());
	    result.put("openfireModule", rc.getOpenfire());
	    result.put("openfireServerSecrect", rc.getServerSecrect());
	    result.put("openfireDomain", rc.getOpenfireDomain());
	    result.put("openfireEMobileUrl", rc.getOpenfireEMobileUrl());
	    result.put("openfireMobileClientUrl", rc.getOpenfireMobileClientUrl());
	    RecordSet rs = new RecordSet();
		rs.executeSql("select name,propvalue from mobileProperty where name='hrmorgbtnshow' or name='allPeopleshow' or name='sameDepartment' or name='commonGroup' or name='groupChat' or name='mysubordinateshow'");
		while(rs.next()){
			String name = rs.getString("name");
			String propValue = rs.getString("propValue");
			if(name.equals("hrmorgbtnshow")){
				result.put("hrmorgbtnshow", Util.getIntValue(propValue, 0)+"");
			}else if(name.equals("allPeopleshow")){
				result.put("allPeopleshow", Util.getIntValue(propValue, 0)+"");
			}else if(name.equals("mysubordinateshow")){
				result.put("mysubordinateshow", Util.getIntValue(propValue, 0)+"");
			}else if(name.equals("sameDepartment")){
				result.put("sameDepartment", Util.getIntValue(propValue, 0)+"");
			}else if(name.equals("commonGroup")){
				result.put("commonGroup", Util.getIntValue(propValue, 0)+"");
			}else if(name.equals("groupChat")){
				result.put("groupChat", Util.getIntValue(propValue, 0)+"");
			}
		}
	} else if("mobileEncode".equalsIgnoreCase(type)) {
	    ReflectMethodCall rmc = new ReflectMethodCall();
		result = (Map)rmc.call("weaver.mobile.plugin.ecology.service.PluginServiceImpl",ps, "mobileEncode",null,null);//ps.mobileEncode();
	} else{
		result.put("status",true);
		result.put("syncSetting",0);
	}
	
	if(result!=null) {
		JSONObject jo = JSONObject.fromObject(result);
		//System.out.println(jo);
		out.println(jo.toString());
	}
%>
