Sindbad~EG File Manager

Current Path : /home/numerotech/admin.numerotech.com/admin_app_v1/core/model/
Upload File :
Current File : //home/numerotech/admin.numerotech.com/admin_app_v1/core/model/AbstractAdminModel.py

from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_

from core import app

engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600)

class AbstractAdminModel():  
	def __init__(self):
		try: 
			# conference
			self.meta = MetaData()
			self.society_applications        = Table("society_applications", self.meta, autoload_with=engine)
			self.abs_types = Table("abs_types", self.meta, autoload_with=engine)
			self.abs_settings        = Table("abs_settings", self.meta, autoload_with=engine)
			self.abs_categories        = Table("abs_categories", self.meta, autoload_with=engine)
			self.map_abs_category = Table("map_abs_category", self.meta, autoload_with=engine)
			self.conference = Table("conference", self.meta, autoload_with=engine)
			self.trigger_daily_reports_mails = Table("trigger_daily_reports_mails", self.meta, autoload_with=engine)
			self.abs_templates = Table("abs_templates", self.meta, autoload_with=engine)
			self.mail_templates = Table("mail_templates", self.meta, autoload_with=engine)
			self.abs_roles = Table("abs_roles", self.meta, autoload_with=engine)
			self.schedule_extent_abs_datetime = Table("schedule_extent_abs_datetime", self.meta, autoload_with=engine)
		except Exception as e:
			print(e)
	
	def get_abstract_applications(self,user_mail):
		with engine.connect() as conn:
			stmt    = text("SELECT sa.*, s.society_name,s.society_title,s.society_logo,s.society_key,s.society_intial,s.e_support_mail,s.e_backup_mails,s.e_secretary_mail_id,"
						+" c.conf_id,c.conf_key,c.conf_name,c.header_logo,c.conf_name,c.header_logo,c.support_email,c.backup_email,c.conf_start_time,c.conf_end_time,now() as current_datetime,case"
						+" when sa.is_active = 1 and now()<= c.conf_start_time or c.conf_start_time is null and app_url is not null then 'active'"
						+" when sa.is_active = 1 and now()>= c.conf_end_time and app_url is not null then 'deactive'"
						+" when sa.is_active = 0 and app_url is null then 'inactive'"
						+" when app_url is null then 'incomplete'"
						+" end as abstract_status,u_user_id,u_user_uuid,"
						+" case when date(c.conf_start_time) < current_date() then 0 else  datediff( date(c.conf_start_time) , current_date()) end as no_of_days"
						+" FROM society_applications sa"
						+" left join societies s on s.society_id = sa.society_id"
						+" left join conference c on c.conf_id = sa.conf_id"
						+" LEFT JOIN ("
						+" SELECT u1.*,u2.user_id as u_user_id,u2.user_uuid as u_user_uuid"
						+" FROM users u1"
						+f" LEFT JOIN (SELECT * FROM users WHERE email = '{user_mail}' GROUP BY society_id ) u2 ON u1.society_id = u2.society_id GROUP BY u1.society_id"
						+" ) u ON sa.society_id = u.society_id"
						+" where sa.app_type_id=3"
						+" CASE WHEN DATEDIFF(DATE(c.conf_start_time), CURRENT_DATE) < 0 THEN DATEDIFF(DATE(c.conf_start_time), CURRENT_DATE) END ASC,"
						+" CASE WHEN DATEDIFF(DATE(c.conf_start_time), CURRENT_DATE) >= 0 OR DATEDIFF(DATE(c.conf_start_time), CURRENT_DATE) IS NULL THEN DATEDIFF(DATE(c.conf_start_time), CURRENT_DATE) END ASC;")
			# print(stmt)
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	
	def get_societies(self):
		with engine.connect() as conn:
			stmt    = text("select * from societies s left join society_applications sa on sa.society_id = s.society_id where sa.app_type_id=3 order by s.society_id;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	

	def Get_Conference(self,society_id):
		with engine.connect() as conn:
			if society_id !=None:
				stmt=text("select * from conference where conf_id in (select conf_id from society_applications where app_type_id=3 and conf_id is not null) and society_id='"+str(society_id)+"' ;")
			else:
				stmt=text("select * from conference where conf_id in (select conf_id from society_applications where app_type_id=3 and conf_id is not null);")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_new_conference(self,society_id):
		with engine.connect() as conn:
			if society_id !=None:
				stmt=text("select c.* from conference c" 
					+" left join society_applications sa"
					+" on c.conf_id=sa.conf_id and sa.app_type_id=3 where sa.conf_id is null and c.society_id='"+str(society_id)+"' order by c.conf_id;")
			else:
				stmt=text("select c.* from conference c" 
					+" left join society_applications sa"
					+" on c.conf_id=sa.conf_id and sa.app_type_id=3 where sa.conf_id is null order by c.conf_id;")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_Society(self):
		with engine.connect() as conn:
			stmt=text("select * from societies order by society_name asc")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_app_type(self):
		with engine.connect() as conn:
			stmt=text("select distinct abs_type from abs_types order by abs_type asc ;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Insert_Society_App(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.society_applications.insert(), data)
			conn.commit()
			return result

	def Insert_abs_type(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_types.insert(), data)
			conn.commit()
			return result

	def Insert_ABS_Setting(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_settings.insert(), data)
			conn.commit()
			return result

	def Insert_abs_categories(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_categories.insert(), data)
			conn.commit()
			return result
		
	def Get_app_type_data(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_types abs inner join map_abs_category mac on abs.abs_type_id=mac.abs_type_id where abs.conf_id="+str(conf_id)+" group by abs.abs_type_id;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_Mail_Setting_id(self):
		with engine.connect() as conn:
			stmt=text("SELECT * FROM mail_setting where is_active=1;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_Abs_Types(self,conf_id):
		with engine.connect() as conn:
			# stmt=text("select * from abs_types where conf_id="+str(conf_id)+" order by order_by desc;")
			# stmt=text("select abs.*,c.conf_name,(select ifnull(max(order_by),0)+1 from abs_types where conf_id="+str(conf_id)+") as max_order_by from abs_types abs left join conference c on c.conf_id=abs.conf_id where abs.conf_id="+str(conf_id)+" and c.conf_id="+str(conf_id)+" order by order_by desc;")
			stmt=text("select abs.*,c.conf_name,s.schedule_id,s.scheduled_on,s.extent_on,(ifnull(max(order_by),0)+1) as max_order_by,"
					+" group_concat(name) as cate_name"
					+" from abs_types abs"
					+" left join conference c on c.conf_id=abs.conf_id"
					+" left join map_abs_category map on map.conf_id=abs.conf_id and abs.abs_type_id= map.abs_type_id"
					+" left join abs_categories abc on abc.category_id=map.category_id"
					+" left join schedule_extent_abs_datetime s on s.conf_id = abs.conf_id and s.abs_type_id = abs.abs_type_id"
					+" where abs.conf_id="+str(conf_id)+" and c.conf_id="+str(conf_id)+" group by abs.abs_type_id order by order_by,date(abs.end_date) desc;")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
	
	def Get_All_Abs_Types(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_types where abs_type is not null and abs_type_id>24 group by abs_type ;")
			# stmt=text("select * from abs_types abt left join abs_settings abs on abs.conf_id=abt.conf_id and abs.conf_id="+str(conf_id)+" AND abs.setting_key='Guideline' where abt.abs_type is not null and abt.abs_type_id>24 group by abt.abs_type ;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
	
	def Get_Society_App_Data(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select sa.*,c.conf_id,c.conf_name,c.conf_title,c.conf_key,ms.driver from society_applications sa left join conference c on sa.conf_id=c.conf_id left join mail_setting ms on sa.mail_setting_id=ms.mail_setting_id where sa.conf_id="+str(conf_id)+" and sa.app_type_id=3 ;")		
			# stmt=text("select sa.*,c.conf_id,c.conf_name,c.conf_title,c.conf_key from society_applications sa  left join conference c  on sa.society_id=c.society_id where c.conf_id="+str(conf_id)+" and sa.app_type_id=3;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def Get_Abs_Types_data(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_types where conf_id="+str(conf_id)+";")		
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_Abs_Setting_Data(self,conf_id,abs_type,society_name):
		with engine.connect() as conn:
			# stmt=text("select abs.* from abs_types abt INNER join abs_settings abs on abs.abs_types = abt.abs_type where abs.conf_id="+str(conf_id)+" AND abt.conf_id="+str(conf_id)+" and abs.abs_types='"+str(abs_type)+"' ;")
			if abs_type=='IC':
				stmt=text("SELECT * FROM abs_settings where conf_id="+str(conf_id)+" and (setting_key like '"+str(abs_type)+"_%' or setting_key like '%"+str(society_name)+"_duration%');")
			else:
				stmt=text("SELECT * FROM abs_settings where conf_id="+str(conf_id)+" and setting_key like '"+str(abs_type)+"_%';")
			print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def update_society_app(self,conf_id,app_id,data):
		with engine.connect() as conn:
			stmt   = self.society_applications.update().where(self.society_applications.c.app_id.in_([app_id])).values(data).where(self.society_applications.c.conf_id.in_([conf_id]))
			result = conn.execute(stmt)
			conn.commit()
			return result

	def Update_Abs_Setting(self,setting_id,data):
		with engine.connect() as conn:
			stmt   = self.abs_settings.update().where(self.abs_settings.c.setting_id.in_([setting_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result
	

	def UpdateAbsCategory(self,category_id,data):
		with engine.connect() as conn:
			stmt   = self.abs_categories.update().where(self.abs_categories.c.category_id.in_([category_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result




	def Get_Abs_Categories(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_categories where conf_id="+str(conf_id)+";")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetAbsTypes(self,abs_type_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_types where abs_type_id="+str(abs_type_id)+";")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def Get_Abs_Categories_id(self):
		with engine.connect() as conn:
			stmt=text("select distinct display_name,category_id,name from abs_categories where is_parent=1;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None


	def Get_Map_Categories(self,conf_id,abs_type_id):
		with engine.connect() as conn:
			stmt=text("select mc.order_no,mc.m_abs_category_id,abs.display_name,abt.abs_type_id from map_abs_category mc "+
				"inner join abs_categories abs on abs.category_id=mc.category_id "+
				"inner join abs_types abt on mc.abs_type_id=abt.abs_type_id where mc.conf_id="+str(conf_id)+" and abt.abs_type_id="+str(abs_type_id)+" order by mc.order_no,abs.display_name asc;")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Insert_Map_catergory(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.map_abs_category.insert(), data)
			conn.commit()
			return result

	def Delete_Map_Category(self,m_abs_category_id):
		with engine.connect() as conn:
			stmt=text("DELETE FROM map_abs_category WHERE m_abs_category_id="+str(m_abs_category_id)+";")
			result=conn.execute(stmt)
			conn.commit()
			return result

	def UpdateAbsType(self,abs_type_id,data):
		with engine.connect() as conn:
			stmt   = self.abs_types.update().where(self.abs_types.c.abs_type_id.in_([abs_type_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	# def Delete_Abs_Type(self,abs_type_id):
	# 	with engine.connect() as conn:
	# 		stmt=text("DELETE FROM abs_types WHERE abs_type_id="+str(abs_type_id)+";")
	# 		result=conn.execute(stmt)
	# 		conn.commit()
	# 		return result
	def Delete_Abs_Type(self,abs_type_id,abs_type,conf_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_admin_abs_delete_abstract",[abs_type_id,abs_type,conf_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			connection.commit()
			# Return the connection to the pool (won't actually close).
			connection.close()
		# print(sets)
		return sets[0]



	def Delete_Category(self,category_id):
		with engine.connect() as conn:
			stmt=text("DELETE FROM abs_categories WHERE category_id="+str(category_id)+";")
			result=conn.execute(stmt)
			conn.commit()
			return result

	def GetDeleRole(self):
		with engine.connect() as conn:
			stmt=text("select distinct role from delegates where role is not null;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Insert_conference(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.conference.insert(), data)
			conn.commit()
			return result

	def InsertDailyReport(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.trigger_daily_reports_mails.insert(), data)
			conn.commit()
			return result

	def GetMailReport(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select t.*,c.conf_name,c.conf_key from trigger_daily_reports_mails t left join conference c on t.conf_id=c.conf_id where t.is_abs=1 and t.conf_id="+str(conf_id)+" order by t.full_name asc; ")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetMailReportData(self,report_id):
		with engine.connect() as conn:
			stmt=text("select * from trigger_daily_reports_mails where report_id="+str(report_id)+"; ")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def UpdateMailReportDatas(self,data,report_id):
		with engine.connect() as conn:
			stmt   = self.trigger_daily_reports_mails.update().where(self.trigger_daily_reports_mails.c.report_id.in_([report_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def DeleteMailReportData(self,report_id):
		with engine.connect() as conn:
			stmt=text("DELETE from trigger_daily_reports_mails where report_id="+str(report_id)+"; ")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def AbsTemplateData(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_templates where conf_id="+str(conf_id)+" ;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def InsertAbsTemData(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_templates.insert(), data)
			conn.commit()
			return result

	def GetTemData(self,tem_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_templates where template_id="+str(tem_id)+" ;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def UpdateAbsTem(self,data,tem_id):
		with engine.connect() as conn:
			stmt   = self.abs_templates.update().where(self.abs_templates.c.template_id.in_([tem_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def usp_insert_abs_cate_data(self,display_name,conf_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_admin_abs_insert_abs_cate_data",[display_name,conf_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			connection.commit()
			# Return the connection to the pool (won't actually close).
			connection.close()
		# print(sets)
		return sets[0]

	def GetAbsTypesData(self,abs_type_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_types where abs_type_id="+str(abs_type_id)+" ;")
			# print(stmt)
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def GetAbsSettData(self,setting_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_settings where setting_id="+str(setting_id)+" ;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def GetConference(self,society_id,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from conference ;")
			# stmt=text("SELECT * FROM conference c left join society_applications soc on c.conf_id=soc.conf_id where c.society_id="+str(society_id)+" and soc.app_type_id=3 and c.conf_id != "+str(conf_id)+";")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetConferenceData(self,society_id,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from conference where conf_id="+str(conf_id)+";")
			# stmt=text("SELECT * FROM conference c left join society_applications soc on c.conf_id=soc.conf_id where c.society_id="+str(society_id)+" and soc.app_type_id=3 and c.conf_id != "+str(conf_id)+";")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None


	def DuplicateAbstractData(self,conf_id,abs_type_id,abs_type,select_conf_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			# print(conf_id,abs_type_id,abs_type)
			cursor.callproc("usp_admin_abs_create_duplicate_abstracts",[conf_id,abs_type_id,abs_type,select_conf_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			connection.commit()
			# Return the connection to the pool (won't actually close).
			connection.close()
		# print(sets)
		return sets[0]

	def AddAbsSetting(self,conf_id,setting_id,abs_type):
		with engine.connect() as conn:
			stmt=text("INSERT INTO abs_settings(setting_key, setting_value, title, society_id, description, error_msg, is_active, is_html,conf_id)"
				+" select setting_key, setting_value, title, society_id, description, error_msg, is_active, is_html,"+str(conf_id)+" from abs_settings where setting_id in ("+str(setting_id)+") and setting_key not in (select setting_key from abs_settings where conf_id="+str(conf_id)+") ;")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def InsertAbsSettingData(self,stmt):
		with engine.connect() as conn:
			stmt_1=text(""+str(stmt)+" ;")
			# print(stmt_1)
			result = conn.execute(stmt_1)
			conn.commit()
			return result

	def DeleteAbsSetting(self,setting_id):
		with engine.connect() as conn:
			stmt=text("DELETE from abs_settings where setting_id="+str(setting_id)+";")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def AddMapCategoryData(self,conf_id,m_abs_category_id,abs_type_id,abs_type):
		with engine.connect() as conn:
			# stmt=text("insert into map_abs_category(conf_id, category_id, abs_type_id, is_active, order_no) "
			# 		+" select "+str(conf_id)+", category_id,abs_type_id, is_active, order_no from map_abs_category where m_abs_category_id="+str(conf)+" and abs_type_id=(select abs_type_id from abs_types where conf_id="+str(conf)+" and abs_type='"+str(abs_type)+"') and category_id not in ( select category_id from map_abs_category where abs_type_id ="+str(abs_type_id)+");")
			stmt=text("insert into map_abs_category(category_id, conf_id, abs_type_id, is_active, order_no)"
						+" select distinct category_id ,"+str(conf_id)+", (select abs_type_id from abs_types where conf_id="+str(conf_id)+" and abs_type='"+str(abs_type)+"'), is_active, order_no from map_abs_category" 
						+" where m_abs_category_id in ("+str(m_abs_category_id)+") and"
						+" category_id not in ( select category_id from map_abs_category where abs_type_id ="+str(abs_type_id)+") ;")
			# print(stmt)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def InsertMailTempl(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.mail_templates.insert(), data)
			conn.commit()
			return result

	def GetMailTempName(self):
		with engine.connect() as conn:
			stmt=text("select * from mail_templates where app_type_id=3 group by template_name order by template_name asc;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None


	def GetConfMailData(self,conf):
		with engine.connect() as conn:
			if conf==None:
				stmt=text("select * from mail_templates where app_type_id=3 ;")
			else:
				stmt=text("select * from mail_templates where conf_ids="+str(conf)+" and app_type_id=3 ;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetConfAbsTypeData(self,conf):
		with engine.connect() as conn:
			if conf==None:
				stmt=text("select * from abs_types where abs_type is not null group by abs_type ;")
			else:
				stmt=text("select * from abs_types where conf_id="+str(conf)+" ;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def InsertDuplicateTemp(self,mail_template_id,conf_id,current_dt):
		with engine.connect() as conn:
			stmt=text("insert into mail_templates (app_type_id, conf_ids, is_layout, is_active, template_name, subject_type, subject, from_mail_name, reply_mail_name, from_mail_id, reply_mail_id, bcc_mails, mail_type, mail_content, created_at, is_send_backup)"
					+" select app_type_id,"+str(conf_id)+", is_layout, is_active, template_name, subject_type, subject, from_mail_name, reply_mail_name, from_mail_id, reply_mail_id, bcc_mails, mail_type, mail_content,'"+str(current_dt)+"',is_send_backup from mail_templates where mail_template_id in("+str(mail_template_id)+") and template_name not in (select template_name from mail_templates where find_in_set("+str(conf_id)+",conf_ids)) ")
			# print(stmt)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def GetMailTemp(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from mail_templates where app_type_id=3 and find_in_set("+str(conf_id)+",conf_ids) order by mail_template_id desc;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetMailData(self,mail_template_id):
		with engine.connect() as conn:
			stmt=text("select * from mail_templates where mail_template_id="+str(mail_template_id)+" ;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def UpdateMailTemp(self,mail_template_id,data):
		with engine.connect() as conn:
			stmt   = self.mail_templates.update().where(self.mail_templates.c.mail_template_id.in_([mail_template_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def DeleteMailTemplData(self,mail_template_id):
		with engine.connect() as conn:
			stmt=text("DELETE from mail_templates where mail_template_id="+str(mail_template_id)+"; ")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def CheckAlreadyExsist(self,abs_type,conf_id):
		with engine.connect() as conn:
			stmt=text("select count(*) as total_count from abs_types where conf_id="+str(conf_id)+" and abs_type in ('"+str(abs_type)+"');")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def CheckAlreadyExsistUpdate(self,abs_type_id,abs_type,conf_id):
		with engine.connect() as conn:
			stmt=text("select count(*) as total_count from abs_types where conf_id="+str(conf_id)+" and abs_type in ('"+str(abs_type)+"') and abs_type_id !="+str(abs_type_id)+";")
			# print(stmt)
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def CheckAlreadyExsistMailTemp(self,conf_id,temp_name):
		with engine.connect() as conn:
			stmt=text("select count(*) as count from mail_templates where find_in_set("+str(conf_id)+",conf_ids) and app_type_id=3 and template_name = '"+str(temp_name)+"';")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def CheckAlreadyExsistMailTempUpdate(self,conf_id,temp_name,mail_template_id):
		with engine.connect() as conn:
			stmt=text("select count(*) as count from mail_templates where find_in_set("+str(conf_id)+",conf_ids) and app_type_id=3 and template_name = '"+str(temp_name)+"' and mail_template_id !="+str(mail_template_id)+" ;")
			# print(stmt)
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def GetAlreadyInsertTemplate(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select template_name from mail_templates where find_in_set("+str(conf_id)+",conf_ids) and app_type_id=3;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def InsertAbsGuidline(self,conf_id,data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_settings.insert(), data)
			conn.commit()
			return result

	def GetAllAbsSetting(self,abs_type,conf):
		with engine.connect() as conn:
			if conf:
				stmt=text("select * from abs_settings where setting_key like '%"+str(abs_type)+"_%' and conf_id="+str(conf)+"  group by setting_key order by setting_key asc;")
			else:
				stmt=text("select * from abs_settings where setting_key like '%"+str(abs_type)+"_%' group by setting_key order by setting_key asc;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def CheckAbsSettingAlreadyExsist(self,setting_id,conf_id):
		with engine.connect() as conn:
			stmt=text("select setting_key from abs_settings where conf_id="+str(conf_id)+" and setting_key in ("+str(setting_id)+");")
			# print(stmt)
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def AbsMapcategData(self,conf):
		with engine.connect() as conn:
			stmt=text("select * from map_abs_category map"
						+" inner join abs_categories ac on ac.category_id=map.category_id"
						+" inner join abs_types abt on abt.abs_type_id=map.abs_type_id"
						+" where map.conf_id="+str(conf)+" group by display_name;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None


	def UpdateOrder_No(self,conf_id,abs_type_id):
		with engine.connect() as conn:
# 			stmt=text("set @a=0; update map_abs_category map"
# 					+" inner join abs_categories abc on abc.category_id=map.category_id"
# 					+" set order_no= @a:= (@a+1)"
# 					+" where map.conf_id="+str(conf_id)+" and abs_type_id="+str(abs_type_id)+" order by name asc;")
			stmt = text(f"update map_abs_category map inner join (select  ROW_NUMBER() OVER(ORDER BY c.name) as new_order,c.category_id  from abs_categories c inner join map_abs_category mc on c.category_id = mc.category_id where mc.conf_id= {conf_id} and abs_type_id={abs_type_id}  order by name asc)  abc on abc.category_id=map.category_id set order_no= new_order where map.conf_id= {conf_id} and abs_type_id={abs_type_id} ;")
			# print(stmt)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def GetCategoryWiseList(self,society_id):
		with engine.connect() as conn:
			stmt=text("select ma.*,abc.name,abc.display_name from abs_categories abc"
				+" left join map_abs_category ma on ma.category_id=abc.category_id"
				+" left join conference c on c.conf_id=ma.conf_id"
				+" where c.society_id="+str(society_id)+" group by name order by name asc;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
	
	def GetGuideline(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select * from abs_settings where conf_id="+str(conf_id)+" and setting_key='Guideline';")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def UpdateGuideline(self,data,setting_id):
		with engine.connect() as conn:
			stmt   = self.abs_settings.update().where(self.abs_settings.c.setting_id.in_([setting_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def GetAbsTemplates(self):
		with engine.connect() as conn:
			stmt=text("select * from abs_templates group by template_name ;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def DuplicateAbsTemplate(self,template_id,conf_id):
		with engine.connect() as conn:
			stmt=text("insert abs_templates(template_name, template_data, abs_type, conf_id)"
				+" select template_name, template_data, abs_type,"+str(conf_id)+" from abs_templates" 
				+" WHERE template_id in ("+str(template_id)+") AND template_name not in (select template_name from abs_templates where conf_id="+str(conf_id)+" );")
			# print(stmt)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def DeleteEvalTemplates(self,template_id):
		with engine.connect() as conn:
			stmt=text("DELETE from abs_templates where template_id="+str(template_id)+" ;")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def GetAllMailReport(self):
		with engine.connect() as conn:
			stmt=text("select * from trigger_daily_reports_mails where is_abs=1 group by full_name order by full_name asc;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
	
	def CheckMapCategExsist(self,conf_id,abs_type_id,category_id):
		with engine.connect() as conn:
			stmt=text("select * from map_abs_category where conf_id="+str(conf_id)+" and abs_type_id="+str(abs_type_id)+" and category_id="+str(category_id)+";")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def Get_Society_name(self,society_id):
		with engine.connect() as conn:
			stmt=text("select society_name from societies where society_id="+str(society_id)+"")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def get_societies_byid(self,society_id):
		with engine.connect() as conn:
			stmt = text("select * from societies where society_id="+str(society_id)+" ;")
			# print(stmt)
			results = conn.execute(stmt)
			results=  results.first()
			if results :
				return dict(results._mapping)
			else:
				return None

	def get_trigger_report_emails_data(self):
		with engine.connect() as conn:
			# stmt    = text("select group_concat(c.conf_id) as conf_id,group_concat(c.conf_key) as conf_key,t.full_name,t.email,t.is_separate_mail from trigger_daily_reports_mails t inner join society_applications s on t.conf_id = s.conf_id  and s.app_type_id=3 inner join conference c on s.conf_id = c.conf_id where t.is_abs = 1 and t.is_active = 1 and s.is_daily_report_mail = 1 group by t.email,t.is_separate_mail")
			# stmt=text("select group_concat(c.conf_id) as conf_id,group_concat(c.conf_key) as conf_key,t.full_name,t.email,t.is_separate_mail,ms.driver,c.e_backup_emails,c.e_from_email,c.e_support_email,c.conf_name"
			#   +" from trigger_daily_reports_mails t"
   #                +" inner join society_applications s on t.conf_id = s.conf_id  and s.app_type_id=3"
			#   +" inner join conference c on s.conf_id = c.conf_id"
			#   +" inner join mail_setting ms on ms.mail_setting_id=s.mail_setting_id"
			#   +" where t.is_abs = 1 and t.is_active = 1 and s.is_daily_report_mail = 1 group by t.email,t.is_separate_mail;")
			stmt=text("select dt.full_name,dt.email,dt.mobile,ms.driver from del_trigger_drm dt"
						+" inner join society_applications s on s.app_type_id=dt.app_type_id and dt.active_conf_list_mail=1"
						+" inner join mail_setting ms on ms.mail_setting_id=s.mail_setting_id and ms.is_active=1"
						+" where s.is_active=1 group by dt.email")
			# print(stmt)
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None


	def GetAllActiveConferenceData(self):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("get_daily_mail_for_active_conference")
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets
		
	def get_extended_data_by_conf_id(self,now):
		with engine.connect() as conn:
			# stmt = text(f"select abs_type_id,extent_on,scheduled_on from schedule_extent_abs_datetime WHERE conf_id = {conf_id} and scheduled_on = '{now}';")
			stmt = text(f"select s.conf_id as conference_id, s.abs_type_id as abstract_type_id, s.scheduled_on,s.extent_on,t.abs_type_id,t.conf_id,t.start_date,t.end_date from schedule_extent_abs_datetime s inner join abs_types t on t.abs_type_id = s.abs_type_id and t.conf_id = s.conf_id where DATE_FORMAT(s.scheduled_on, '%Y-%m-%d %H:%i') = '{now}'")
			result = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			return results
			
	def update_extended_date_by_abs_id(self,now):
		with engine.connect() as conn:
			stmt = text(f"update schedule_extent_abs_datetime s inner join abs_types t on t.abs_type_id = s.abs_type_id and t.conf_id = s.conf_id set t.end_date = s.extent_on where DATE_FORMAT(s.scheduled_on, '%Y-%m-%d %H:%i') = '{now}'")
			result = conn.execute(stmt)
			conn.commit()
			return "success"
			
	def get_updated_extended_data(self,now):
		with engine.connect() as conn:
			stmt=text("select s.conf_id as conference_id, s.abs_type_id as abstract_type_id,c.conf_name,t.title,"
						+" s.scheduled_on,s.extent_on,t.abs_type_id,t.start_date,t.end_date from schedule_extent_abs_datetime s"
						+" inner join abs_types t on t.abs_type_id = s.abs_type_id and t.conf_id = s.conf_id" 
						+" left join conference c on c.conf_id = s.conf_id"
						+f" where DATE_FORMAT(s.scheduled_on, '%Y-%m-%d %H:%i') = '{now}';")
			result=conn.execute(stmt).all()
			results=[dict(r._mapping) for r in result] if result else None
			return results
	
	def get_schedule_data(self,abs_type_id):
		with engine.connect() as conn:
			stmt=text("select s.schedule_id,s.scheduled_on,s.extent_on,abt.abs_type_id,abt.abs_type,abt.conf_id from abs_types abt" 
						+" left join schedule_extent_abs_datetime s on abt.abs_type_id = s.abs_type_id and abt.conf_id=s.conf_id"
						+f" where abt.abs_type_id={abs_type_id};")
			result = conn.execute(stmt).first()
			return  dict(result._mapping) if result else None
		
	def InsertSchedule(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.schedule_extent_abs_datetime.insert(), data)
			conn.commit()
			return "success"
	
	def UpdateSchedule(self,schedule_id,data):
		with engine.connect() as conn:
			stmt   = self.schedule_extent_abs_datetime.update().where(self.schedule_extent_abs_datetime.c.schedule_id.in_([schedule_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result
		
	def delete_schedule(self,schedule_id):
		with engine.connect() as conn:
			stmt=text(f"DELETE FROM schedule_extent_abs_datetime WHERE schedule_id={schedule_id};")
			result=conn.execute(stmt)
			conn.commit()
			return result
			
	def GetLogsData(self):
		with engine.connect() as conn:
			stmt=text("select * from logs where host_url is not null group by host_url; ;")
			result=conn.execute(stmt).all()
			results=[dict(r._mapping) for r in result] if result else None
			return results

	def UpdateConference(self,data,conf_id):
		with engine.connect() as conn:
			stmt   = self.conference.update().where(self.conference.c.conf_id.in_([conf_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result

	def usp_filter_logs(self,app_type,logger_name,host_url,before_time,limit):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_filter_logs",[app_type,logger_name,host_url,before_time,limit])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets[0]
		
	def get_abstract_status_count(self):
		with engine.connect() as conn:
			stmt = text("select count(*) as abstract_app,"
					+" sum(case when sa.is_active = 1 and now()<= c.conf_start_time or c.conf_start_time is null and app_url is not null then 1 else 0 end) as active_count,"
					+" sum(case when sa.is_active = 1 and now()>= c.conf_end_time and app_url is not null then 1 else 0 end) as deactive_count,"
					+" sum(case when sa.is_active = 0 and app_url is null then 1 else 0 end) as inactive_count,"
					+" sum(case when sa.conf_id is not null and app_url is null then 1 else 0 end) as incomplete"
					+" from society_applications sa"
					+" left join conference c on c.conf_id = sa.conf_id" 
					+" where app_type_id=3 and sa.society_id is not null and sa.conf_id is not null;")
			result = conn.execute(stmt).first()
			return  dict(result._mapping) if result else None
			
	def get_searched_data(self,search_text):
		connection = engine.raw_connection()
		cursor = connection.cursor()
		cursor.callproc("usp_get_admin_search_users_record",[search_text])
		 
		columns = [column[0] for column in cursor.description]
		results = []
		for row in cursor.fetchall():
			results.append(dict(zip(columns, row)))
		cursor.close()
		connection.commit()
		if results :
			return results
		else :
			return None	
			
	def get_user_data(self,user_id):
		with engine.connect() as conn:
			stmt=text("select u.*,m.member_type,s.state_name,c.country_name,ua.attach_type_id,ua.attach_file_name,ua.attach_path from users u" 
						+" left join m_member_type m on m.member_type_id=u.member_type_id"
						+" left join states s on s.state_id = u.mc_state_id"
						+" left join countries c on c.country_id = u.country_id"
						+" left join m_attachment_type mat on mat.society_id=u.society_id and mat.attach_type='Photograph'"
						+" left join user_attachments ua on ua.attach_type_id = mat.attach_type_id and ua.user_id=u.user_id"
						+f" where u.user_id={user_id}; ")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None
			
	def GetConferenceBySociety(self,society_id):
		with engine.connect() as conn:
			stmt=text(f"select * from conference where society_id={society_id};")
			result=conn.execute(stmt).all()
			results=[dict(r._mapping) for r in result] if result else None
			return results
		
	def get_conf_key_by_id(self,conf_id):
		with engine.connect() as conn:
			stmt=text(f"select conf_key from conference where conf_id={conf_id};")
						
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None
			
	def usp_get_abstracts(self,conf_id,user_ids,abs_ids,abs_status_ids):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_abstracts",[conf_id,user_ids,abs_ids,abs_status_ids])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets
	
	def get_user_commitment_data(self,conf_id,user_id,report_type,start_date,end_date):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor     = connection.cursor()
			cursor.callproc("usp_get_user_commmintment",[conf_id,user_id,report_type,start_date,end_date])
			while 1:
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
					row = dict(zip(names, row_raw))
					set_.append(row)
				sets.append(list(set_))
				if cursor.nextset() is None:
					break
				if cursor.description is None:
					break
		finally:
			connection.close()
		return sets
	
	def get_domain_name(self):
		with engine.connect() as conn:
			stmt=text("select * from m_app_type order by root_path asc;")
			result=conn.execute(stmt).all()
			results=[dict(r._mapping) for r in result] if result else None
			return results
			
	def update_conf(self,conf_id,data):
		with engine.connect() as conn:
			try:
				stmt      = self.conference.update().where(self.conference.c.conf_id.in_([conf_id])).values(data)
				print("--------",stmt)
				restult_1 = conn.execute(stmt)
				conn.commit()
				return "success"
			except Exception as e:
				return str(e)

	def GetConferenceByconf(self,conf_id):
		with engine.connect() as conn:
			stmt=text(f"select * from conference where conf_id={conf_id};")
			result=conn.execute(stmt).all()
			results=[dict(r._mapping) for r in result] if result else None
			return results


	def remove_favicon_data(self,conf_id):
		with engine.connect() as conn:
			stmt   = text("update conference set favicon_url = null where conf_id = "+str(conf_id)+" ;")
			result = conn.execute(stmt)
			conn.commit()
			if result:
				return "success"
			else:
				return "fail"
	def GetConf(self,conf_id):
		with engine.connect() as conn:
			stmt   = text("select * from conference  where conf_id = "+str(conf_id)+"   limit 1;")
			result = conn.execute(stmt)
			result = result.one_or_none()
			return dict(result._mapping) if result else None
			
	def get_conf_data_by_society_id(self,society_id):
		with engine.connect() as conn:
			stmt   = text("select * from conference where society_id="+str(society_id)+";")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None



	def create_duplicate_conf(self,conf_id,society_id):
		connection = engine.raw_connection()
		cursor = connection.cursor()
		cursor.callproc("usp_get_create_duplicate_conf",[conf_id,society_id])
		
		if cursor.description :
			columns = [column[0] for column in cursor.description]
			results = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None
		else :
			cursor.close()
			connection.commit()
			return None 
			
	def insert_new_user_data_by_society_id(self, super_admin_email, society_id):
		with engine.connect() as conn:
			# Check if the user already exists (parameterized query to prevent SQL injection)
			stmt_1 = text("SELECT * FROM users WHERE email = :email AND society_id = :society_id")
			result_1 = conn.execute(stmt_1, {"email": super_admin_email, "society_id": society_id}).first()
			
			if result_1 is None: 
				# Insert the user data if not already present
				stmt_2 = text("INSERT INTO users (email, society_id) VALUES (:email, :society_id)")
				conn.execute(stmt_2, {"email": super_admin_email, "society_id": society_id})
				conn.commit()
				
				# Fetch and return the newly inserted user data
				result_3 = conn.execute(stmt_1, {"email": super_admin_email, "society_id": society_id}).first()
				return dict(result_3._mapping) if result_3 else None
			else:
				# Return the existing user data
				return dict(result_1._mapping)

	def get_all_abstract(self,conf_id):
		with engine.connect() as conn:
			stmt    = text(f"select * from abs_types where conf_id={conf_id} order by  abs_type,abs_config_type")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None

	def get_abstract_data_by_id(self,abs_type_id,conf_id):
		with engine.connect() as conn:
			stmt = text(f"select * from abs_types where abs_type_id = {abs_type_id} and conf_id={conf_id};")
			result = conn.execute(stmt).first()
			if result:
				return dict(result._mapping)
			else:
				return None
#--Update---

	def update_abstract_data(self,abs_type_id,data):
		with engine.connect() as conn:
			stmt   = self.abs_types.update().where(self.abs_types.c.abs_type_id.in_([abs_type_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			return result
			
#--delete---

	def delete_abstract_data_by_id(self,id,conf_id):
		with engine.connect() as conn:
			stmt = text(f"DELETE from abs_types WHERE abs_type_id IN ({id}) and conf_id={conf_id}")
			result = conn.execute(stmt)
			conn.commit()
			return result

	def get_abstract_by_name(self, abs_type,conf_id):
		with engine.connect() as conn:
			stmt = text(f"SELECT * FROM abs_types WHERE abs_type ='{abs_type}' and conf_id = {conf_id}")
			result = conn.execute(stmt).first()  
			if result:
				return dict(result._mapping)  
			return None

#---Insertpage---	

	def insert_abstype(self, data):
		with engine.connect() as conn:
			result = conn.execute(self.abs_types.insert(), data)
			conn.commit()
			if result:
				return result
			else:
				return None
				
#---Abstract-Roles---

	#---Check Role Name---

	def get_role_by_name(self, role_name):
		with engine.connect() as conn:
			stmt = text(f"SELECT * FROM abs_roles WHERE role = :role_name")
			result = conn.execute(stmt, {"role_name": role_name}).first()
			conn.close() 
			return result

	#---Max Order No---

	def get_max_order_no(self):
		with engine.connect() as conn:
			stmt = text("SELECT MAX(order_no) FROM abs_roles")
			result = conn.execute(stmt).scalar() 
			conn.close() 
			return result

	#---Insertpage---	

	def insert_absrole(self, data):
		with engine.connect() as conn:
			stmt = self.abs_roles.insert().values(data)  
			result = conn.execute(stmt) 
			conn.commit() 
			conn.close() 
			return result.rowcount > 0

	#---view_role---

	def get_all_abstractrole(self):
		with engine.connect() as conn:
			stmt = text("SELECT * FROM abs_roles ORDER BY order_no ASC") 
			result = conn.execute(stmt).fetchall()
			conn.close() 
			return [dict(row._mapping) for row in result]
		
	#---EditAbsroles---
	
	def get_abstractroles_data_by_id(self, role_id):
		with engine.connect() as conn:
			stmt = text(f"SELECT * FROM abs_roles WHERE role_id = :role_id;")  
			result = conn.execute(stmt, {"role_id": role_id}).first() 
			conn.close()  
			if result:
				return dict(result._mapping)
			else:
				return None

	#--Update---

	def update_abstractroles_data(self, role_id, data):
		with engine.connect() as conn:
			stmt = self.abs_roles.update().where(self.abs_roles.c.role_id == role_id).values(data)
			result = conn.execute(stmt)
			conn.commit()
			conn.close() 
			return result.rowcount > 0

	#--delete---
		
	def delete_abstractroles_data_by_id(self, role_id):
		with engine.connect() as conn:
			stmt = text(f"DELETE from abs_roles WHERE role_id = :role_id")
			result = conn.execute(stmt, {"role_id": role_id})
			conn.commit()
			conn.close() 
			return result.rowcount > 0  

		

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists