/*
FILE
	$Id: thdquotafunc.h 6 2005-11-24 00:02:59Z ggw $
	(tAuthorize.cPasswd template set member)
PURPOSE

AUTHOR
	Template and mysqlRAD2 author: (c) 2001,2002 Gary Wallis.
	GPL License applies, see www.fsf.org for details

 
*/

//ModuleFunctionProtos()


void tHDQuotaNavList(void);

void ExtProcesstHDQuotaVars(pentry entries[], int x)
{

	/*
	register int i;
	
	for(i=0;i<x;i++)
	{
	
	}
	*/

}//void ExtProcesstHDQuotaVars(pentry entries[], int x)


void ExttHDQuotaCommands(pentry entries[], int x)
{
	if(!strcmp(function,"tHDQuotaTools"))
	{
		//ModuleFunctionProcess()

		//Default wizard like two step creation and deletion
		if(!strcmp(command,LANG_NB_NEW))
                {
	if(uPermLevel>=12)

			{
                        ProcesstHDQuotaVars(entries,x);
			//Check global conditions for new record here
                        mode=2000;
                        tHDQuota(LANG_NB_CONFIRMNEW);
			}
                }
		else if(!strcmp(command,LANG_NB_CONFIRMNEW))
                {
	if(uPermLevel>=12)

			{
			
                        ProcesstHDQuotaVars(entries,x);
			//Check entries here
			uHDQuota=0;
			uCreatedBy=uLoginClient;
			uOwner=uLoginClient;
			uModBy=0;//Never modified
			uModDate=0;
			NewtHDQuota(0);
			}
		}
		else if(!strcmp(command,LANG_NB_DELETE))
                {
                        ProcesstHDQuotaVars(entries,x);
			if(uOwner) GetClientOwner(uOwner,&uReseller);
		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

			{
                        mode=2001;
                        tHDQuota(LANG_NB_CONFIRMDEL);
			}
                }
                else if(!strcmp(command,LANG_NB_CONFIRMDEL))
                {
                        ProcesstHDQuotaVars(entries,x);
			if(uOwner) GetClientOwner(uOwner,&uReseller);
		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

			{
                        mode=5;
                        DeletetHDQuota();
			}
                }
		else if(!strcmp(command,LANG_NB_MODIFY))
                {
                        ProcesstHDQuotaVars(entries,x);
			if(uOwner) GetClientOwner(uOwner,&uReseller);
		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

			{
                        mode=2002;
                        tHDQuota(LANG_NB_CONFIRMMOD);
			}
                }
                else if(!strcmp(command,LANG_NB_CONFIRMMOD))
                {
                        ProcesstHDQuotaVars(entries,x);
			if(uOwner) GetClientOwner(uOwner,&uReseller);
		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

			{
			uModBy=uLoginClient;
                        ModtHDQuota();
			}
                }
	}

}//void ExttHDQuotaCommands(pentry entries[], int x)


void ExttHDQuotaButtons(void)
{
	printf("<table width=260 border=0 bgcolor=#9BC1B3 valign=center>\n");
        printf("<tr><td>");

	printf("<font face=Arial,Helvetica>");
	printf("<font size=2>");

	switch(mode)
        {
                case 2000:
			printf("Enter required data<br>");
                        printf("<font size=1>");
                        printf(LANG_NBB_CONFIRMNEW);
			printf("<br>\n");
                break;

                case 2001:
                        printf("<font size=1>");
                        printf(LANG_NBB_CONFIRMDEL);
			printf("<br>\n");
                break;

                case 2002:
			printf("Review record data<br>");
                        printf("<font size=1>");
                        printf(LANG_NBB_CONFIRMMOD);
			printf("<br>\n");
                break;

	}

	printf("<font size=2>");
        printf("<p><u>tHDQuotaNavList</u><br>\n");
	tHDQuotaNavList();

        printf("</td></tr>\n");
        printf("</table>\n");

}//void ExttHDQuotaButtons(void)


void ExttHDQuotaAuxTable(void)
{

}//void ExttHDQuotaAuxTable(void)


void ExttHDQuotaGetHook(entry gentries[], int x)
{
	register int i;

	for(i=0;i<x;i++)
	{
		if(!strcmp(gentries[i].name,"uHDQuota"))
		{
			sscanf(gentries[i].val,"%u",&uHDQuota);
			mode=6;
		}
	}
	tHDQuota("");

}//void ExttHDQuotaGetHook(entry gentries[], int x)


void ExttHDQuotaSelect(void)
{
        //Set non search query here for tTableName()
	if(uPermLevel>=9)
	sprintf(query,"SELECT %s FROM tHDQuota ORDER BY\
					uHDQuota",
					VAR_LIST_tHDQuota);
	else
	sprintf(query,"SELECT %s FROM tHDQuota WHERE uOwner=%u ORDER BY\
					uHDQuota",
					VAR_LIST_tHDQuota,uLoginClient);

}//void ExttHDQuotaSelect(void)


void ExttHDQuotaSelectRow(void)
{
	if(uPermLevel<10)
                sprintf(query,"SELECT %s FROM tHDQuota,tClient \
                                WHERE tHDQuota.uOwner=tClient.uClient\
                                AND (tClient.uOwner=%u OR tClient.uClient=%u)\
                                AND tHDQuota.uHDQuota=%u",
                        		VAR_LIST_tHDQuota,
					uLoginClient,uLoginClient,uHDQuota);
	else
                sprintf(query,"SELECT %s FROM tHDQuota WHERE uHDQuota=%u",
			VAR_LIST_tHDQuota,uHDQuota);

}//void ExttHDQuotaSelectRow(void)


void ExttHDQuotaListSelect(void)
{
	char cCat[512];

	if(uPermLevel<10)
		sprintf(query,"SELECT %s FROM tHDQuota,tClient \
		WHERE tHDQuota.uOwner=tClient.uClient \
		AND (tClient.uOwner=%u OR tClient.uClient=%u)",
				VAR_LIST_tHDQuota,
				uLoginClient,
				uLoginClient);
	else
                sprintf(query,"SELECT %s FROM tHDQuota",
				VAR_LIST_tHDQuota);

	//Changes here must be reflected below in ExttHDQuotaListFilter()
        if(!strcmp(filter,"uHDQuota"))
        {
                sscanf(command,"%u",&uHDQuota);
		if(uPermLevel<10)
			strcat(query," AND ");
		else
			strcat(query," WHERE ");
		sprintf(cCat,"tHDQuota.uHDQuota=%u \
						ORDER BY uHDQuota",
						uHDQuota);
		strcat(query,cCat);
        }
        else if(1)
        {
                //None NO FILTER
                strcpy(filter,"None");
		strcat(query," ORDER BY uHDQuota");
        }

}//void ExttHDQuotaListSelect(void)


void ExttHDQuotaListFilter(void)
{
        //Filter
        printf("<td align=right >Select ");
        printf("<select name=filter>");
        if(strcmp(filter,"uHDQuota"))
                printf("<option>uHDQuota</option>");
        else
                printf("<option selected>uHDQuota</option>");
        if(strcmp(filter,"None"))
                printf("<option>None</option>");
        else
                printf("<option selected>None</option>");
        printf("</select>");

}//void ExttHDQuotaListFilter(void)


void ExttHDQuotaNavBar(void)
{
	if(uOwner) GetClientOwner(uOwner,&uReseller);

	printf(LANG_NBB_SKIPFIRST);
	printf(LANG_NBB_SKIPBACK);
	printf(LANG_NBB_SEARCH);

	if(uPermLevel>=12)

	printf(LANG_NBB_NEW);
	//printf(LANG_NBB_NEWREV);

		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

	printf(LANG_NBB_MODIFY);

		if( (uPermLevel>=12 && uOwner==uLoginClient)
			|| (uPermLevel>9 && uOwner!=1)
			|| (uPermLevel>7 && uReseller==uLoginClient) )

	printf(LANG_NBB_DELETE);

	printf(LANG_NBB_LIST);

	printf(LANG_NBB_SKIPNEXT);
	printf(LANG_NBB_SKIPLAST);

}//void ExttHDQuotaNavBar(void)


void tHDQuotaNavList(void)
{
        MYSQL_RES *res;
        MYSQL_ROW field;

	if(uPermLevel<10)
		sprintf(query,"SELECT tHDQuota.uHDQuota\
				,tHDQuota.cLabel\
				FROM tHDQuota,tClient\
                                WHERE tHDQuota.uOwner=tClient.uClient\
                                AND (tClient.uOwner=%u OR tClient.uClient=%u)",
					uLoginClient,uLoginClient);
	else
	        sprintf(query,"SELECT uHDQuota,cLabel FROM tHDQuota");

        mysql_query(&mysql,query);
        if(mysql_errno(&mysql))
        {
                printf("%s",mysql_error(&mysql));
                return;
        }

        res=mysql_store_result(&mysql);
        while((field=mysql_fetch_row(res)))
        {
                printf("<a class=darkLink href=mysqlSendmail.cgi?function=tHDQuota\
&uHDQuota=%s>%s</a><br>\n",field[0],field[1]);
        }
        mysql_free_result(res);

}//void tHDQuotaNavList(void)


//sedall patch1
//sedall patch2
