public bool CopyTemplateApp(Hashtable State, string template_app_name, string new_app_name) { DB db = new DB(); //This function assumes that the new_app_name is unique; string sql = "SELECT customer_id FROM customers WHERE username='******'"; string customer_id = db.ViziAppsExecuteScalar(State, sql); StringBuilder b_sql = new StringBuilder("SELECT * FROM applications "); b_sql.Append("WHERE application_name='" + template_app_name + "'"); b_sql.Append(" AND customer_id='" + customer_id + "'"); DataRow[] rows = db.ViziAppsExecuteSql(State, b_sql.ToString()); DataRow row = rows[0]; string previous_application_id = row["application_id"].ToString(); string NOW = DateTime.Now.ToUniversalTime().ToString("u").Replace("Z", ""); b_sql = new StringBuilder("INSERT into applications SET "); string application_id = Guid.NewGuid().ToString(); b_sql.Append("application_id='" + application_id + "',"); b_sql.Append("customer_id='" + State["CustomerID"] + "',"); b_sql.Append("username='******',"); XmlUtil x_util = new XmlUtil(); string new_xml = x_util.RenameAppXmlWithID(State, row["staging_app_xml"].ToString(), new_app_name, application_id); b_sql.Append("staging_app_xml='" + MySqlFilter(new_xml) + "',"); if (row["custom_header_html"] != null) b_sql.Append("custom_header_html='" + MySqlFilter(row["custom_header_html"].ToString()) + "',"); b_sql.Append("application_name='" + new_app_name + "',"); b_sql.Append("application_type='" + row["application_type"].ToString() + "',"); if (row["default_button_image"] != null) b_sql.Append("default_button_image='" + row["default_button_image"].ToString() + "',"); b_sql.Append("description='" + row["description"].ToString().Replace("'", "''").Replace(@"\", @"\\") + "',"); b_sql.Append("date_time_modified='" + NOW + "'"); db.ViziAppsExecuteNonQuery(State, b_sql.ToString()); //get all the pages sql = "SELECT * FROM application_pages WHERE application_id='" + previous_application_id + "'"; rows = db.ViziAppsExecuteSql(State, sql); //insert all the pages into the new app foreach (DataRow page_row in rows) { sql = "INSERT INTO application_pages (application_page_id,application_id,page_name,page_image_url,date_time_modified) VALUES (UUID(),'" + application_id + "','" + page_row["page_name"].ToString() + "','" + page_row["page_image_url"].ToString() + "','" + NOW + "')"; db.ViziAppsExecuteNonQuery(State, sql); } db.CloseViziAppsDatabase(State); //reset State["AppXmlDoc"] = null; return true; }
public void CopyAppToAccount(Hashtable State, string application_name) { DB db = new DB(); StringBuilder b_sql = new StringBuilder("SELECT * FROM applications "); b_sql.Append("WHERE application_name='" + application_name + "'"); b_sql.Append(" AND customer_id='" + State["CopyApplicationFromCustomerID"].ToString() + "'"); DataRow[] rows = db.ViziAppsExecuteSql(State, b_sql.ToString()); DataRow row = rows[0]; string previous_application_id = row["application_id"].ToString(); string application_id = Guid.NewGuid().ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(DecodeMySql(row["staging_app_xml"].ToString())); //delete any app with the same name db.ViziAppsExecuteNonQuery(State, "DELETE FROM applications WHERE application_name='" + application_name + "' AND customer_id='" + State["CopyApplicationToCustomerID"].ToString() + "'"); string username = db.ViziAppsExecuteScalar(State, "SELECT username FROM customers WHERE customer_id='" + State["CopyApplicationToCustomerID"].ToString() + "'"); b_sql = new StringBuilder("INSERT into applications SET "); b_sql.Append("application_id='" + application_id + "',"); b_sql.Append("customer_id='" + State["CopyApplicationToCustomerID"].ToString() + "',"); b_sql.Append("username='******',"); XmlUtil x_util = new XmlUtil(); string new_xml = x_util.RenameAppXmlWithID(State, row["staging_app_xml"].ToString(), application_name, application_id); b_sql.Append("staging_app_xml='" + MySqlFilter(new_xml) + "',"); if (row["custom_header_html"] != null) b_sql.Append("custom_header_html='" + MySqlFilter(row["custom_header_html"].ToString()) + "',"); b_sql.Append("application_name='" + application_name + "',"); b_sql.Append("application_type='" + row["application_type"].ToString() + "',"); if (row["default_button_image"] != null) b_sql.Append("default_button_image='" + row["default_button_image"].ToString() + "',"); b_sql.Append("description='" + row["description"].ToString().Replace("'", "''").Replace(@"\", @"\\") + "',"); string NOW = DateTime.Now.ToUniversalTime().ToString("u").Replace("Z", ""); b_sql.Append("date_time_modified='" + NOW + "'"); db.ViziAppsExecuteNonQuery(State, b_sql.ToString()); //get all the pages string sql = "SELECT * FROM application_pages WHERE application_id='" + previous_application_id + "'"; rows = db.ViziAppsExecuteSql(State, sql); //insert all the pages into the new app foreach (DataRow page_row in rows) { sql = "INSERT INTO application_pages (application_page_id,application_id,page_name,page_image_url,date_time_modified) VALUES (UUID(),'" + application_id + "','" + page_row["page_name"].ToString() + "','" + page_row["page_image_url"].ToString() + "','" + NOW + "')"; db.ViziAppsExecuteNonQuery(State, sql); } db.CloseViziAppsDatabase(State); //reset State["AppXmlDoc"] = null; }