*/
public static boolean delete(JDCConnection oConn, String sUserGUID) throws SQLException,IOException {
boolean bRetVal;
int iCats, iConts, iMsgs;
DBSubset oCats, oProds, oConts, oMsgs;
Statement oStmt;
PreparedStatement oPtmt;
ResultSet oRSet;
CallableStatement oCall;
if (DebugFile.trace) {
DebugFile.writeln("Begin ACLUser.delete([Connection], " + sUserGUID + ")");
DebugFile.incIdent();
}
// -----------------------------------------------------------------------------------
// Verify that user exists before proceeding and, also, avoid deleting more registers
// than should by a malicious inyection of SQL code at sUserGUID
oPtmt = oConn.prepareStatement("SELECT "+DB.gu_user+" FROM "+DB.k_users+" WHERE "+DB.gu_user+"=?",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
oPtmt.setString(1, sUserGUID);
oRSet = oPtmt.executeQuery();
boolean bExists = oRSet.next();
oRSet.close();
oPtmt.close();
if (!bExists) {
if (DebugFile.trace) {
DebugFile.writeln("user " + sUserGUID + " not found");
DebugFile.decIdent();
DebugFile.writeln("End ACLUser.delete() : false");
}
return false;
}
// ************
// New for v5.0
if (DBBind.exists(oConn, DB.k_activities, "U")) {
oStmt = oConn.createStatement();
oStmt.executeUpdate("UPDATE "+DB.k_x_activity_audience+" SET "+DB.gu_writer+"=NULL WHERE "+DB.gu_writer+"='"+sUserGUID+"'");
oStmt.executeUpdate("UPDATE "+DB.k_activities+" SET "+DB.gu_writer+"=NULL WHERE "+DB.gu_writer+"='"+sUserGUID+"'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_sms_audit, "U")) {
oStmt = oConn.createStatement();
oStmt.executeUpdate("UPDATE "+DB.k_sms_audit+" SET "+DB.gu_writer+"=NULL WHERE "+DB.gu_writer+"='"+sUserGUID+"'");
oStmt.close();
}
// End new for v5.0
// ****************
// ************
// New for v4.0
if (DBBind.exists(oConn, DB.k_working_calendar, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_working_time + " WHERE " + DB.gu_calendar + " IN (SELECT " + DB.gu_calendar + " FROM " + DB.k_working_calendar + " WHERE " + DB.gu_user + "='" + sUserGUID + "'))");
oStmt.executeUpdate("DELETE FROM " + DB.k_working_time + " WHERE " + DB.gu_calendar + " IN (SELECT " + DB.gu_calendar + " FROM " + DB.k_working_calendar + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.close();
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_working_calendar + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_working_calendar + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
// ************
// New for v3.0
if (DBBind.exists(oConn, DB.k_user_pwd, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_cat_objs + " WHERE " + DB.gu_object + " IN (SELECT "+DB.gu_pwd+" FROM "+DB.k_user_pwd+" WHERE " + DB.gu_user + "='" + sUserGUID + "'))");
oStmt.executeUpdate("DELETE FROM " + DB.k_x_cat_objs + " WHERE " + DB.gu_object + " IN (SELECT "+DB.gu_pwd+" FROM "+DB.k_user_pwd+" WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.close();
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_user_pwd + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_user_pwd + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
} // fi
if (DBBind.exists(oConn, DB.k_user_mail, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_user_mail + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_user_mail + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
/* Actualizar los estados de negocio creados por el usuario */
if (DBBind.exists(oConn, DB.k_business_states, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace)
DebugFile.writeln("UPDATE " + DB.k_business_states + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_business_states + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
/* Borrar la referencia este usuario desde los cuestionarios que haya rellenado */
if (DBBind.exists(oConn, DB.k_pageset_answers, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace)
DebugFile.writeln("UPDATE " + DB.k_pageset_answers + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_pageset_answers + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
/* Desasociar las evaluaciones */
if (DBBind.exists(oConn, DB.k_evaluations, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace)
DebugFile.writeln("UPDATE " + DB.k_evaluations + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_evaluations + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
/* Desasociar los partes de absentismo */
if (DBBind.exists(oConn, DB.k_absentisms, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace)
DebugFile.writeln("UPDATE " + DB.k_absentisms + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_absentisms + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
// End new for v3.0
// ****************
// ************
// New for v6.0
/* Eliminar los permisos sobre cursos */
if (DBBind.exists(oConn, DB.k_x_user_acourse, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_user_acourse + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_x_user_acourse + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
// End new for v6.0
// ****************
// ************
// New for v2.1
/* Desasociar los e-mails */
if (DBBind.exists(oConn, DB.k_inet_addrs, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace)
DebugFile.writeln("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_user + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_user + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_x_portlet_user, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_images, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_images + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_images + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_bugs_lookup, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_bugs + " SET " + DB.nm_assigned + "=NULL WHERE " + DB.nm_assigned + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_bugs + " SET " + DB.nm_assigned + "=NULL WHERE " + DB.nm_assigned + "='" + sUserGUID + "'");
oStmt.close();
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_bugs_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_bugs_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_x_duty_resource, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_duty_resource + " WHERE " + DB.nm_resource + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_x_duty_resource + " WHERE " + DB.nm_resource + "='" + sUserGUID + "'");
oStmt.close();
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_duties_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_duties_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "'");
oStmt.close();
}
// End new for v2.1
// ****************
// ************
// New for v4.0
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_duties + " SET " + DB.gu_writer + "=NULL WHERE "+ DB.gu_writer + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_duties + " SET " + DB.gu_writer + "=NULL WHERE "+ DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
// End new for v4.0
// ****************
// ************
// New for v2.0
if (DBBind.exists(oConn, DB.k_newsgroup_subscriptions, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
// End new for v2.0
// ****************
if (DBBind.exists(oConn, DB.k_newsmsgs, "U")) {
oStmt = oConn.createStatement();
// Remove user GUID from messages he validated
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_newsmsgs + " SET " + DB.gu_validator + "=NULL WHERE " + DB.gu_validator + "='" + sUserGUID + "'");
oStmt.executeUpdate("UPDATE " + DB.k_newsmsgs + " SET " + DB.gu_validator + "=NULL WHERE " + DB.gu_validator + "='" + sUserGUID + "'");
// Delete forum messages written by this user without file attachments
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_newsmsgs + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.gu_product + " IS NULL");
oStmt.executeUpdate("DELETE FROM " + DB.k_newsmsgs + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.gu_product + " IS NULL");
oStmt.close();
// Delete forum messages written by this user with file attachments
oMsgs = new DBSubset(DB.k_newsmsgs, DB.gu_msg, DB.gu_writer + "='" + sUserGUID + "'", 100);
iMsgs = oMsgs.load(oConn);
for (int m=0; m<iMsgs; m++)
com.knowgate.forums.NewsMessage.delete(oConn, oMsgs.getString(0,m));
oMsgs = null;
} // fi (exists(k_newsmsgs,))
if (DBBind.exists(oConn, DB.k_member_address, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_member_address + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_member_address + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_member_address + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_member_address + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_companies_recent, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_companies_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_companies_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_companies, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_companies + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_companies + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_contacts_recent, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_contacts_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "')");
oStmt.executeUpdate("DELETE FROM " + DB.k_contacts_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_contacts, "U")) {
oConts = new DBSubset(DB.k_contacts, DB.gu_contact, DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0", 100);
iConts = oConts.load(oConn);
for (int t=0; t<iConts; t++)
com.knowgate.crm.Contact.delete(oConn, oConts.getString(0,t));
oConts = null;
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contacts + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0)");
oStmt.executeUpdate("UPDATE " + DB.k_contacts + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0");
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contact_notes + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_contact_notes + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contact_attachs + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')");
oStmt.executeUpdate("UPDATE " + DB.k_contact_attachs + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_oportunities, "U")) {
oStmt = oConn.createStatement();
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_oportunities + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0)");
oStmt.executeUpdate("DELETE FROM " + DB.k_oportunities + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0");
if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_oportunities + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0)");
oStmt.executeUpdate("UPDATE " + DB.k_oportunities + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0");
oStmt.close();
}
if (DBBind.exists(oConn, DB.k_sales_men, "U")) {
if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_sales_man ('" + sUserGUID + "') })");
oCall = oConn.prepareCall("{call k_sp_del_sales_man ('" + sUserGUID + "')}");
bRetVal = oCall.execute();
oCall.close();
}
if (DBBind.exists(oConn, DB.k_products, "U")) {
oProds = new DBSubset(DB.k_products, DB.gu_product, DB.gu_owner + "='" + sUserGUID + "'", 100);
int iProds = oProds.load(oConn);
for (int p=0; p<iProds; p++)
new com.knowgate.hipergate.Product(oConn, oProds.getString(0, p)).delete(oConn);
oProds = null;
} // fi (exists(DB.k_products))
// Delete categories associated with user
if (DBBind.exists(oConn, DB.k_categories, "U")) {
String sGuRootCat = null;
oStmt = oConn.createStatement();
ResultSet oRCat = oStmt.executeQuery("SELECT " + DB.gu_category + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
if (oRCat.next())
sGuRootCat = oRCat.getString(1);
oRCat.close();
oStmt.close();
if (sGuRootCat!=null) {
oStmt = oConn.createStatement();
oStmt.executeUpdate("UPDATE " + DB.k_users + " SET " + DB.gu_category + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'");
oStmt.close();
Category.delete(oConn, sGuRootCat);
}
oCats = new DBSubset(DB.k_categories, DB.gu_category, DB.gu_owner + "=?", 10);
iCats = oCats.load(oConn, new Object[]{sUserGUID});
for (int r=0; r<iCats; r++)
Category.delete(oConn, oCats.getString(0,r));
oCats = null;
} // fi (exists(oConn, DB.k_categories))
if (DBBind.exists(oConn, DB.k_phone_calls, "U")) {