/* FILE tUsage source code of mysqlSendmail.cgi (built by mysqlRAD2.cgi (c) Gary Wallis 2001,2002 GPL Licensed) $Id: tusage.c 6 2005-11-24 00:02:59Z ggw $ (tAuthorize.cPasswd template set member) PURPOSE */ #include "mysqlrad.h" //Table Variables //uUsage: Primary Key static unsigned uUsage=0; //uUser: Usage for this user static unsigned uUser=0; //uHD: Current HD usage in MB static long unsigned uHD=0; //uTraffic: Yesterdays outgoing traffic in MB static long unsigned uTraffic=0; //uOwner: Record owner static unsigned uOwner=0; //uCreatedBy: uClient for last insert static unsigned uCreatedBy=0; #define ISM3FIELDS //uCreatedDate: Unix seconds date last insert static long unsigned uCreatedDate=0; //uModBy: uClient for last update static unsigned uModBy=0; //uModDate: Unix seconds date last update static long unsigned uModDate=0; #define VAR_LIST_tUsage "tUsage.uUsage,tUsage.uUser,tUsage.uHD,tUsage.uTraffic,tUsage.uOwner,tUsage.uCreatedBy,tUsage.uCreatedDate,tUsage.uModBy,tUsage.uModDate" //Local only void Insert_tUsage(void); void Update_tUsage(char *rowid); int InsertUpdate_tUsage(char *cKey); void ProcesstUsageListVars(pentry entries[], int x); //In tUsagefunc.h file included below void ExtProcesstUsageVars(pentry entries[], int x); void ExttUsageCommands(pentry entries[], int x); void ExttUsageButtons(void); void ExttUsageNavBar(void); void ExttUsageGetHook(entry gentries[], int x); void ExttUsageSelect(void); void ExttUsageSelectRow(void); void ExttUsageListSelect(void); void ExttUsageListFilter(void); void ExttUsageAuxTable(void); #include "tusagefunc.h" //Table Variables Assignment Function void ProcesstUsageVars(pentry entries[], int x) { register int i; for(i=0;i\n"); printf("\n"); printf(""); printf("
"); ExttUsageNavBar(); printf(""); printf("",rowid); if(i) { printf(" "); if(mode==6) //printf(" Found"); printf(LANG_NBR_FOUND); else if(mode==5) //printf(" Modified"); printf(LANG_NBR_MODIFIED); else if(mode==4) //printf(" New"); printf(LANG_NBR_NEW); printf(LANG_NBRF_SHOWING,rowid,i); } else { if(!result[0]) //printf(" No records found"); printf(LANG_NBR_NORECS); } if(result[0]) printf(" %s",result); printf("
"); ExttUsageButtons(); printf(""); printf("\n"); if(mode==2000 || mode==2002) tUsageInputContent(); else tUsageContent(); printf("
\n"); printf("
\n"); //Bottom table ExttUsageAuxTable(); printf("\n"); Footer_ism3(); }//end of tUsage(); void tUsageContent(void) { OpenRow(LANG_FL_tUsage_uUsage,"white"); printf("%u\n",uUsage,uUsage); printf("  "); OpenRow(LANG_FL_tUsage_uUser,"white"); printf("%s\n",ForeignKey("tUser","cLogin",uUser),uUser); printf("  "); OpenRow(LANG_FL_tUsage_uHD,"white"); printf("%lu\n",uHD,uHD); printf("  "); OpenRow(LANG_FL_tUsage_uTraffic,"white"); printf("%lu\n",uTraffic,uTraffic); printf("  "); OpenRow(LANG_FL_tUsage_uOwner,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uOwner),uOwner); printf("  "); OpenRow(LANG_FL_tUsage_uCreatedBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); printf("  "); OpenRow(LANG_FL_tUsage_uCreatedDate,"white"); if(uCreatedDate) printf("%s\n\n",ctime((time_t *)&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); printf("  "); OpenRow(LANG_FL_tUsage_uModBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uModBy),uModBy); printf("  "); OpenRow(LANG_FL_tUsage_uModDate,"white"); if(uModDate) printf("%s\n\n",ctime((time_t *)&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("  "); printf("\n"); }//tUsageContent() void tUsageInputContent(void) { OpenRow(LANG_FL_tUsage_uUsage,"white"); if(uPermLevel>=20) printf("\n",LANG_FT_tUsage_uUsage,uUsage); else printf("%u\n",uUsage,uUsage); OpenRow(LANG_FL_tUsage_uUser,"white"); printf("%s\n",ForeignKey("tUser","cLogin",uUser),uUser); OpenRow(LANG_FL_tUsage_uHD,"white"); if(uPermLevel>=20) printf("\n",LANG_FT_tUsage_uHD,uHD); else printf("%lu\n",uHD,uHD); OpenRow(LANG_FL_tUsage_uTraffic,"white"); if(uPermLevel>=20) printf("\n",LANG_FT_tUsage_uTraffic,uTraffic); else printf("%lu\n",uTraffic,uTraffic); OpenRow(LANG_FL_tUsage_uOwner,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uOwner),uOwner); OpenRow(LANG_FL_tUsage_uCreatedBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); OpenRow(LANG_FL_tUsage_uCreatedDate,"white"); if(uCreatedDate) printf("%s\n\n",ctime((time_t *)&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); OpenRow(LANG_FL_tUsage_uModBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uModBy),uModBy); OpenRow(LANG_FL_tUsage_uModDate,"white"); if(uModDate) printf("%s\n\n",ctime((time_t *)&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("\n"); }//void tUsageInputContent(void) void NewtUsage(unsigned uMode) { register int i=0; MYSQL_RES *res; //New select sprintf(query,"SELECT uUsage FROM tUsage\ WHERE uUsage=%u" ,uUsage); mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); if(i) //tUsage("Record already exists"); tUsage(LANG_NBR_RECEXISTS); //insert query Insert_tUsage(); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //sprintf(query,"New record %u added"); uUsage=mysql_insert_id(&mysql); if(!uMode) { sprintf(query,LANG_NBR_NEWRECADDED,uUsage); tUsage(query); } }//NewtUsage(unsigned uMode) void DeletetUsage(void) { #ifdef ISM3FIELDS sprintf(query,"DELETE FROM tUsage WHERE uUsage=%u AND ( uOwner=%u OR %u>9 )" ,uUsage,uLoginClient,uPermLevel); #else sprintf(query,"DELETE FROM tUsage WHERE uUsage=%u" ,uUsage); #endif mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //tUsage("Record Deleted"); if(mysql_affected_rows(&mysql)>0) tUsage(LANG_NBR_RECDELETED); else tUsage(LANG_NBR_RECNOTDELETED); }//void DeletetUsage(void) void Insert_tUsage(void) { #ifdef ISM3FIELDS time_t clock; time(&clock); #endif //insert query //insert query sprintf(query,"INSERT INTO tUsage SET uUsage=%u, uUser=%u, uHD=%lu, uTraffic=%lu, uOwner=%u, uCreatedBy=%u, uCreatedDate=%lu, uModBy=%u, uModDate=0", uUsage ,uUser ,uHD ,uTraffic ,uOwner ,uCreatedBy ,(long unsigned)clock ,uModBy ); mysql_query(&mysql,query); #ifdef ISM3FIELDS uCreatedDate=clock; #endif }//void Insert_tUsage(void) void Update_tUsage(char *rowid) { #ifdef ISM3FIELDS time_t clock; time(&clock); #endif //update query //update query sprintf(query,"UPDATE tUsage SET uUsage=%u,uUser=%u,uHD=%lu,uTraffic=%lu,uModBy=%u,uModDate=%lu WHERE _rowid=%s", uUsage ,uUser ,uHD ,uTraffic ,uModBy ,(long unsigned)clock ,rowid); mysql_query(&mysql,query); #ifdef ISM3FIELDS uModDate=clock; #endif }//void Update_tUsage(void) void ModtUsage(void) { register int i=0; MYSQL_RES *res; MYSQL_ROW field; #ifdef ISM3FIELDS unsigned uPreModDate=0; //Mod select query if(uPermLevel<10) sprintf(query,"SELECT tUsage.uUsage,\ tUsage.uModDate\ FROM tUsage,tClient\ WHERE tUsage.uUsage=%u\ AND tUsage.uOwner=tClient.uClient\ AND (tClient.uOwner=%u OR tClient.uClient=%u)" ,uUsage,uLoginClient,uLoginClient); else sprintf(query,"SELECT uUsage,uModDate FROM tUsage\ WHERE uUsage=%u" ,uUsage); #else sprintf(query,"SELECT uUsage FROM tUsage\ WHERE uUsage=%u" ,uUsage); #endif mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); //if(i<1) tUsage("Record does not exist"); if(i<1) tUsage(LANG_NBR_RECNOTEXIST); //if(i>1) tUsage("Multiple rows!"); if(i>1) tUsage(LANG_NBR_MULTRECS); field=mysql_fetch_row(res); #ifdef ISM3FIELDS sscanf(field[1],"%u",&uPreModDate); if(uPreModDate!=uModDate) tUsage(LANG_NBR_EXTMOD); #endif Update_tUsage(field[0]); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //sprintf(query,"record %s modified",field[0]); sprintf(query,LANG_NBRF_REC_MODIFIED,field[0]); tUsage(query); }//ModtUsage(void) void tUsageList(void) { MYSQL_RES *res; MYSQL_ROW field; ExttUsageListSelect(); mysql_query(&mysql,query); if(mysql_error(&mysql)[0]) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); PageMachine("tUsageList",1,"");//1 is auto header list mode. Opens table! //Filter select drop down ExttUsageListFilter(); printf("",command); printf("\n"); printf("\n"); printf(""); mysql_data_seek(res,start-1); for(n=0;n<(end-start+1);n++) { field=mysql_fetch_row(res); if(!field) { printf("
uUsageuUseruHDuTrafficuOwneruCreatedByuCreatedDateuModByuModDate
End of data
"); Footer_ism3(); } if(n % 2) printf(""); else printf(""); printf(" %s%s%s%s%s%s%s%s%s" ,field[0] ,field[0] ,field[1] ,field[2] ,field[3] ,field[4] ,field[5] ,field[6] ,field[7] ,field[8] ); } printf("\n"); Footer_ism3(); }//tUsageList() void CreatetUsage(void) { sprintf(query,"CREATE TABLE tUsage ( uUsage int unsigned PRIMARY KEY AUTO_INCREMENT, uHD bigint unsigned NOT NULL DEFAULT 0, uOwner int unsigned NOT NULL DEFAULT 0,index (uOwner), uCreatedBy int unsigned NOT NULL DEFAULT 0, uCreatedDate int unsigned NOT NULL DEFAULT 0, uModBy int unsigned NOT NULL DEFAULT 0, uModDate int unsigned NOT NULL DEFAULT 0, uTraffic bigint unsigned NOT NULL DEFAULT 0, uUser int unsigned NOT NULL DEFAULT 0,index (uUser) )"); mysql_query(&mysql,qstr); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); }//CreatetUsage() //sedall patch1