1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 19 import org.compiere.model.*; 20 import org.compiere.util.*; 21 22 28 public class CalloutRequest extends CalloutEngine 29 { 30 41 public String action (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value) 42 { 43 String colName = mField.getColumnName(); 44 log.info("action - " + colName + "=" + value); 45 if (value == null) 46 return ""; 47 String action = (String )value; 48 if (action.equals(MRequest.ACTIONTYPE_EMail)) 50 return actionCheckEMail(ctx, mTab); 51 return ""; 52 } 54 55 65 public String copyText (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value) 66 { 67 String colName = mField.getColumnName(); 68 log.info("copyText - " + colName + "=" + value); 69 if (value == null) 70 return ""; 71 72 Integer R_MailText_ID = (Integer )value; 73 String sql = "SELECT MailHeader, MailText FROM R_MailText WHERE R_MailText_ID=?"; 74 try 75 { 76 PreparedStatement pstmt = DB.prepareStatement(sql); 77 pstmt.setInt(1, R_MailText_ID.intValue()); 78 ResultSet rs = pstmt.executeQuery(); 79 if (rs.next()) 80 { 81 String hdr = rs.getString(1); 82 String txt = rs.getString(2); 83 hdr = Env.parseContext(ctx, WindowNo, hdr, false, true); 85 txt = Env.parseContext(ctx, WindowNo, txt, false, true); 86 mTab.setValue("MailSubject", hdr); 88 mTab.setValue("MailText", txt); 89 } 90 rs.close(); 91 pstmt.close(); 92 } 93 catch (SQLException e) 94 { 95 log.error("copyText", e); 96 } 97 return ""; 98 } 100 106 private static String actionCheckEMail(Properties ctx, MTab mTab) 107 { 108 String host = EMailUtil.getSmtpHost(ctx); 110 if (host == null || host.length() == 0) 111 return "RequestActionEMailNoSMTP"; 112 113 Object toAddr = mTab.getValue("C_BPartner_ID"); 115 if (toAddr == null) 116 return "RequestActionEMailNoTo"; 117 int C_BPartner_ID = ((Integer )toAddr).intValue(); 118 if (C_BPartner_ID == 0) 119 return "RequestActionEMailNoTo"; 120 int AD_User_ID = 0; 121 toAddr = mTab.getValue("AD_User_ID"); 122 if (toAddr != null) 123 AD_User_ID = ((Integer )toAddr).intValue(); 124 String emailTo = EMailUtil.getEMail_BPartner (C_BPartner_ID, AD_User_ID); 125 if (emailTo == null || emailTo.length() == 0) 126 return "RequestActionEMailNoTo"; 127 128 String emailFrom = EMailUtil.getEMail_User (ctx, false); 130 if (emailFrom == null || emailFrom.length() == 0) 131 return "RequestActionEMailNoFrom"; 132 int user = 0; Object reqUser = mTab.getValue("SalesRep_ID"); 134 if (reqUser != null) 135 user = ((Integer )reqUser).intValue(); 136 int SalesRep_ID = Env.getContextAsInt (ctx, "#AD_User_ID"); 137 if (user != AD_User_ID) 138 mTab.setValue("SalesRep_ID", new Integer (AD_User_ID)); 139 140 Object [] args = new Object [] {emailFrom, emailTo}; 142 String msg = Msg.getMsg(ctx, "RequestActionEMailInfo", args); 143 mTab.setValue("Result", msg); 144 return ""; 145 } 147 148 149 }
| Popular Tags
|