#include "ui.h" #include void archive_db_confirm(mySession *session, char *name, int type) { if ( session->textonly == 0 ) { Body("SGI Embedded Support Partner - ver.1.0\n"); Body("\n"); TableBegin("border=0 cellpadding=0 cellspacing=0 width=100%"); RowBegin(""); CellBegin("bgcolor=\"#C7CDB5\" width=\"15\""); Body("    \n"); CellEnd(); CellBegin("bgcolor=\"#C7CDB5\""); Body("Archive Database\n"); CellEnd(); RowEnd(); RowBegin(""); CellBegin("colspan=2"); Body(" 

 \n"); CellEnd(); RowEnd(); RowBegin(""); CellBegin(""); Body(" \n"); CellEnd(); CellBegin(""); FormatedBody("Archive %s was successfully removed.",name); CellEnd(); RowEnd(); TableEnd(); Body("\n"); } else { Body("SGI Embedded Support Partner - ver.1.0\n"); Body("\n"); Body("

   Archive Database
\n"); Body("
\n"); FormatedBody("

Archive %s was successfully removed.",name); Body("\n"); } } void archive_list(sscErrorHandle hError, mySession *session,ssdb_Connection_Handle connection, ssdb_Error_Handle error_handle,CMDPAIR *cmdp) { ssdb_Request_Handle req_handle; const char **vector; int number_of_records,rec_sequence; if (!(req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_SELECT, "select arc_id,dbname,startdate,enddate from archive_list order by arc_id"))) { sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle)); return; } if((number_of_records = getnumrecords(hError,error_handle,req_handle)) > 0) { if ( session->textonly == 0 ) { Body("Choose the database to be deleted: \n"); Body("\n"); Body("

\n"); } else { if ( session->textonly == 0 ) { Body("There are no archives at this time.\n"); } else { Body("

There are no archives at this time.\n"); } } } void archive_table(sscErrorHandle hError, mySession *session,ssdb_Connection_Handle connection, ssdb_Error_Handle error_handle,CMDPAIR *cmdp) { ssdb_Request_Handle req_handle; const char **vector; int number_of_records,rec_sequence; char startdate[40],event_time[16],enddate[40]; if ( session->textonly == 0 ) { TableBegin("border=4 cellpadding=6 cellspacing=1"); RowBegin("align=center"); CellBegin("colspan=2 "); Body("Database Name\n"); CellEnd(); CellBegin(""); Body("Start Date\n"); CellEnd(); CellBegin(""); Body("End Date\n"); CellEnd(); RowEnd(); RowBegin(""); CellBegin(""); Body("\n"); CellEnd(); CellBegin(""); Body("Active Database\n"); CellEnd(); CellBegin(""); } else { Body("

\n");
	        FormatedBody("   -------------------------------------------------------\n");
	        FormatedBody("   |     Database Name     |  Start Date  |  End  Date   |\n");
	        FormatedBody("   |-----------------------------------------------------|\n");
		FormatedBody("   | | Active Database |");
	}
	
			if (!(req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_SELECT,
			"select event_start from event where event_id=1")))
			{
				sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle));
				return;
			}
			if((number_of_records = getnumrecords(hError,error_handle,req_handle)) > 0)
			{
				vector = ssdbGetRow(error_handle,req_handle);
				if(vector)
				{
 				     makedate(atoi(vector[0]),startdate,event_time);
				     if ( session->textonly == 0 )
					FormatedBody("%s",startdate);
				     else 
					FormatedBody("  %-10.10s  |",startdate);
				}
				else
				{
				     if ( session->textonly == 0 )
					Body("Current	\n");
				     else
				        FormatedBody("   Current    |");
				}
			}
			else
			{
				     if ( session->textonly == 0 )
					Body("Current	\n");
				     else
				        FormatedBody("   Current    |");
			}
			ssdbFreeRequest(error_handle,req_handle);			

        if ( session->textonly == 0 )
        {
		CellEnd();
		CellBegin("");
			Body("Current\n");
		CellEnd();
	RowEnd();
	}
	else
	{
         FormatedBody("   Current    |\n");
	}
	
		if (!(req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_SELECT,
		"select arc_id,dbname,startdate,enddate from archive_list order by arc_id")))
		{
			sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle));
			return;
		}
		if((number_of_records = getnumrecords(hError,error_handle,req_handle)) > 0)
		{
			for(rec_sequence = 0; rec_sequence < number_of_records; rec_sequence++)
			{
				vector = ssdbGetRow(error_handle,req_handle);
				if(vector)
				{
				   if ( session->textonly == 0 )
				   {
					RowBegin("");
					CellBegin("");
						FormatedBody("",vector[1]);
					CellEnd();
					CellBegin("");
						FormatedBody("%s",vector[1]);
					CellEnd();
					CellBegin("");
						FormatedBody("%s",vector[2]);
					CellEnd();
					CellBegin("");
						FormatedBody("%s",vector[3]);
					CellEnd();
					RowEnd();
				    }
				    else
				    {
	                                       FormatedBody("   |-----------------------------------------------------|\n");
		                               FormatedBody("   | |",vector[1]);
		                               FormatedBody(" %-15.15s |",vector[1]);
		                               
					       FormatedBody("  %-10.10s  |",vector[2]);
					       
					       FormatedBody("  %-10.10s  |\n",vector[3]);
				    }
				}
			}
			ssdbFreeRequest(error_handle,req_handle);
		}
	if ( session->textonly == 0 )
	{
	TableEnd();
	}
	else
	{
	  FormatedBody("   -------------------------------------------------------
\n"); } } void delete_archive(sscErrorHandle hError, mySession *session,ssdb_Connection_Handle connection, ssdb_Error_Handle error_handle,CMDPAIR *cmdp) { ssdb_Request_Handle req_handle; const char **vector; int number_of_records,rec_sequence,common_int; char dbnames[80]; if(!get_variable(hError,cmdp,CHARTYPE,"ssdbs",dbnames,&common_int,1000)) return; /* We are going to delete archive logicaly */ req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_DELETE, "delete from archive_list where dbname='%s'",dbnames); if ( req_handle == NULL ) { sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle)); return; } ssdbFreeRequest(error_handle,req_handle); /* Then physicaly */ if (!(req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_DROPDATABASE, "drop database if exists %s",dbnames))) { sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle)); return; } ssdbFreeRequest(error_handle,req_handle); /* Then References */ req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_DELETE, "delete from mysql.db where Db='%s'",dbnames); if ( req_handle == NULL ) { sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle)); return; } ssdbFreeRequest(error_handle,req_handle); req_handle = ssdbSendRequest(error_handle,connection,SSDB_REQTYPE_DELETE, "delete from mysql.host where Db='%s'",dbnames); if (req_handle == NULL ) { sscError(hError,"Database API Error: \"%s\"\n\n",ssdbGetLastErrorString(error_handle)); return; } ssdbFreeRequest(error_handle,req_handle); system("/usr/sbin/ssdbadmin reload"); archive_db_confirm(session,dbnames,0); }