bool Fil_RenameFileOrDir (const char *PathOld,const char *PathNew) { extern const char *Txt_There_is_already_a_non_empty_folder_named_X; extern const char *Txt_There_is_already_a_file_named_X; /* Rename the file or directory */ if (rename (PathOld,PathNew) == 0) return true; else { switch (errno) { case ENOTEMPTY: case EEXIST: sprintf (Gbl.Message,Txt_There_is_already_a_non_empty_folder_named_X, PathNew); break; case ENOTDIR: sprintf (Gbl.Message,Txt_There_is_already_a_file_named_X, PathNew); break; case EACCES: Lay_ShowErrorAndExit ("Write is forbidden."); break; default: Lay_ShowErrorAndExit ("Can not rename file or folder."); break; } return false; } }
unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate) { MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; unsigned NumPage; /***** Get last page of received/sent messages from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get last page of messages", "SELECT %s FROM sessions" " WHERE SessionId='%s'", WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" : "LastPageMsgSnt", Gbl.Session.Id); /***** Check number of rows of the result ****/ if (NumRows != 1) Lay_ShowErrorAndExit ("Error when getting last page of messages."); /***** Get last page of messages *****/ row = mysql_fetch_row (mysql_res); if (sscanf (row[0],"%u",&NumPage) == 1) if (NumPage == 0) NumPage = 1; return NumPage; }
static void Par_GetBoundary (void) { const char *PtrToBoundary; /* If data are received ==> the environment variable CONTENT_TYPE will hold: multipart/form-data; boundary=---------------------------7d13ca2e948 Gbl.Boundary.StrWithCRLF will be set to: "\r\n-----------------------------7d13ca2e948" I.e. 0x0D, 0x0A, '-', '-', and boundary. */ /***** Get pointer to boundary string *****/ PtrToBoundary = strstr (getenv ("CONTENT_TYPE"),"boundary=") + strlen ("boundary="); /***** Check that boundary string is not too long *****/ if (2 + 2 + strlen (PtrToBoundary) > Par_MAX_BYTES_BOUNDARY_WITH_CR_LF) Lay_ShowErrorAndExit ("Delimiter string too long."); /***** Create boundary strings *****/ snprintf (Gbl.Boundary.StrWithoutCRLF,sizeof (Gbl.Boundary.StrWithoutCRLF), "--%s", PtrToBoundary); snprintf (Gbl.Boundary.StrWithCRLF,sizeof (Gbl.Boundary.StrWithCRLF), "%c%c%s", 0x0D,0x0A,Gbl.Boundary.StrWithoutCRLF); /***** Compute lengths *****/ Gbl.Boundary.LengthWithoutCRLF = strlen (Gbl.Boundary.StrWithoutCRLF); Gbl.Boundary.LengthWithCRLF = 2 + Gbl.Boundary.LengthWithoutCRLF; }
bool Fil_EndReceptionOfFile (char *FileNameDataTmp) { extern const char *Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML; FILE *FileDataTmp; int Result; // Result of the reception of the file /***** Open a new file temporary *****/ if ((FileDataTmp = fopen (FileNameDataTmp,"wb")) == NULL) Lay_ShowErrorAndExit ("Can not open temporary file."); /***** Skip carriage returns, spaces, etc. *****/ Str_SkipSpacesInFile (Gbl.F.Tmp); /* At this point, the data of the file begin */ /***** Write the file *****/ Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.Tmp,FileDataTmp,(char *) NULL, Gbl.DelimiterStringIncludingInitialRet, Fil_MAX_FILE_SIZE); fclose (FileDataTmp); if (Result != 1) /* 0 ==> File too large; -1 ==> Unfinished transmission */ { unlink (FileNameDataTmp); sprintf (Gbl.Message,Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML, (unsigned long) (Fil_MAX_FILE_SIZE / (1024ULL * 1024ULL))); return false; // Error } return true; // Success }
void Fil_CreateDirIfNotExists (const char *Path) { if (!Fil_CheckIfPathExists (Path)) if (mkdir (Path,(mode_t) 0xFFF) != 0) { sprintf (Gbl.Message,"Can not create folder <strong>%s</strong>.",Path); Lay_ShowErrorAndExit (Gbl.Message); } }
static void Ban_EditingBannerConstructor (void) { /***** Pointer must be NULL *****/ if (Ban_EditingBan != NULL) Lay_ShowErrorAndExit ("Error initializing banner."); /***** Allocate memory for banner *****/ if ((Ban_EditingBan = (struct Banner *) malloc (sizeof (struct Banner))) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for banner."); /***** Reset banner *****/ Ban_EditingBan->BanCod = -1L; Ban_EditingBan->Hidden = true; Ban_EditingBan->ShrtName[0] = '\0'; Ban_EditingBan->FullName[0] = '\0'; Ban_EditingBan->Img[0] = '\0'; Ban_EditingBan->WWW[0] = '\0'; }
static void Ban_GetListBanners (MYSQL_RES **mysql_res,unsigned long NumRows) { MYSQL_ROW row; unsigned NumBan; struct Banner *Ban; /***** Get banners from database *****/ if (NumRows) // Banners found... { Gbl.Banners.Num = (unsigned) NumRows; /***** Create list with banners *****/ if ((Gbl.Banners.Lst = (struct Banner *) calloc (NumRows,sizeof (struct Banner))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the banners *****/ for (NumBan = 0; NumBan < Gbl.Banners.Num; NumBan++) { Ban = &(Gbl.Banners.Lst[NumBan]); /* Get next banner */ row = mysql_fetch_row (*mysql_res); /* Get banner code (row[0]) */ if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong code of banner."); /* Get if banner is hidden (row[1]) */ Ban->Hidden = (row[1][0] == 'Y'); /* Get the short name of the banner (row[2]) */ Str_Copy (Ban->ShrtName,row[2], Ban_MAX_BYTES_SHRT_NAME); /* Get the full name of the banner (row[3]) */ Str_Copy (Ban->FullName,row[3], Ban_MAX_BYTES_FULL_NAME); /* Get the image of the banner (row[4]) */ Str_Copy (Ban->Img,row[4], Ban_MAX_BYTES_IMAGE); /* Get the URL of the banner (row[5]) */ Str_Copy (Ban->WWW,row[5], Cns_MAX_BYTES_WWW); } } else Gbl.Banners.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (mysql_res); }
void Fil_FastCopyOfFiles (const char *PathSrc,const char *PathTgt) { FILE *FileSrc,*FileTgt; /***** Open source file *****/ if ((FileSrc = fopen (PathSrc,"rb")) == NULL) Lay_ShowErrorAndExit ("Can not open source file."); /***** Open destination file *****/ if ((FileTgt = fopen (PathTgt,"wb")) == NULL) Lay_ShowErrorAndExit ("Can not open target file."); /***** Copy source file into destination file *****/ Fil_FastCopyOfOpenFiles (FileSrc,FileTgt); /***** Close the files *****/ fclose (FileTgt); fclose (FileSrc); }
void Fil_CloseUpdateFile (const char *CurrentName,const char *OldName,const char *NewName,FILE *NewFile) { /* Close file */ fclose (NewFile); /* Rename the old file and the new file */ if (rename (CurrentName,OldName)) // mv CurrentName OldName Ej: mv file.html file.old { sprintf (Gbl.Message,"Can not rename the file <strong>%s</strong> as <strong>%s</strong>.", CurrentName,OldName); Lay_ShowErrorAndExit (Gbl.Message); } if (rename (NewName,CurrentName)) // mv NewName CurrentName Ej: mv file.new file.html { sprintf (Gbl.Message,"Can not rename the file <strong>%s</strong> as <strong>%s</strong>.", NewName,CurrentName); Lay_ShowErrorAndExit (Gbl.Message); } }
bool Fil_ReadStdinIntoTmpFile (void) { extern const char *Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML; extern const char *Txt_UPLOAD_FILE_Upload_time_too_long_maximum_X_minutes_NO_HTML; unsigned long long TmpFileSize; bool FileIsTooBig = false; bool TimeExceeded = false; if ((Gbl.F.Tmp = tmpfile ()) == NULL) { Fil_EndOfReadingStdin (); Lay_ShowErrorAndExit ("Can not create temporary file."); } for (TmpFileSize = 0; !feof (stdin) && !FileIsTooBig && !TimeExceeded; TmpFileSize++) if (TmpFileSize < Fil_MAX_FILE_SIZE) { if (!(TmpFileSize % (64ULL*1024ULL))) // Check timeout from time to time if (time (NULL) - Gbl.StartExecutionTimeUTC >= Cfg_TIME_TO_ABORT_FILE_UPLOAD) TimeExceeded = true; fputc (fgetc (stdin),Gbl.F.Tmp); } else FileIsTooBig = true; if (FileIsTooBig || TimeExceeded) { Fil_EndOfReadingStdin (); // If stdin were not fully read, there will be problems with buffers if (FileIsTooBig) sprintf (Gbl.Message,Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML, (unsigned long) (Fil_MAX_FILE_SIZE / (1024ULL * 1024ULL))); else sprintf (Gbl.Message,Txt_UPLOAD_FILE_Upload_time_too_long_maximum_X_minutes_NO_HTML, (unsigned long) (Cfg_TIME_TO_ABORT_FILE_UPLOAD / 60UL)); /* Don't write HTML at all */ Gbl.Layout.HTMLStartWritten = Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true; /* Start HTTP response */ fprintf (stdout,"Content-type: text/plain; charset=windows-1252\n"); /* Status code and message */ fprintf (stdout,"Status: 501 Not Implemented\r\n\r\n" "%s\n", Gbl.Message); return false; } rewind (Gbl.F.Tmp); return true; }
static long Not_GetParamNotCod (void) { char LongStr[1+10+1]; // String that holds the notice code long NotCod; /* Get notice code */ Par_GetParToText ("NotCod",LongStr,1+10); if (sscanf (LongStr,"%ld",&NotCod) != 1) Lay_ShowErrorAndExit ("Wrong code of notice."); return NotCod; }
/* -----------------------------7d113610948 Content-Disposition: form-data; name="Param1" 2000-2001 -----------------------------7d113610948 Content-Disposition: form-data; name="Param2" Estructura de los computadores II -----------------------------7d113610948 Content-Disposition: form-data; name="Param3" ../swad/fichas.htm -----------------------------7d113610948 Content-Disposition: form-data; name="Param4" ../public_html/docencia/ecii/ecii-log.html -----------------------------7d113610948 Content-Disposition: form-data; name="Param5" L384261 -----------------------------7d113610948 Content-Disposition: form-data; name="Param6" 13282 -----------------------------7d113610948 Content-Disposition: form-data; name="Param7" /~acanas/docencia/fotos -----------------------------7d113610948 Content-Disposition: form-data; name="Archivo"; filename="D:\Usr\Antonio\Docencia\Estruct\Notas\Notas 2000-2001.ec\fotos\R157550.jpg" Content-Type: image/pjpeg 000000 FFD8FFE0 00104A46 49460001 01010048 п ЯииJFIFиииииH 000010 00480000 FFDB0043 00030202 03020203 иHии █иCииииииии 000020 03030304 03030405 08050504 04050A07 ииииииииииииииии etc, etc. */ void Fil_StartReceptionOfFile (char *SrcFileName,char *MIMEType) { char *Ptr; int Ch,i; /* At this point, a heading has been read from Gbl.F.Tmp with all the variables passed by form */ rewind (Gbl.F.Tmp); if (!Str_FindStrInFile (Gbl.F.Tmp,Fil_NAME_OF_PARAM_FILENAME_ORG,Str_NO_SKIP_HTML_COMMENTS)) { sprintf (Gbl.Message,"Error uploading file: parameter <strong>%s</strong> not found.", Fil_NAME_OF_PARAM_FILENAME_ORG); Lay_ShowErrorAndExit (Gbl.Message); } /* Go to the name of the source file */ if (!Str_FindStrInFile (Gbl.F.Tmp,"filename=\"",Str_NO_SKIP_HTML_COMMENTS)) Lay_ShowErrorAndExit ("Error uploading file: parameter "filename" not found."); /* Get the name of the source file */ Ptr = SrcFileName; while ((Ch = fgetc (Gbl.F.Tmp)) != (int) '\"') *Ptr++ = Ch; *Ptr = '\0'; /* Get and check the type of data */ if (!Str_FindStrInFile (Gbl.F.Tmp,"Content-Type:",Str_NO_SKIP_HTML_COMMENTS)) Lay_ShowErrorAndExit ("Error uploading file: "Content-Type" not found."); /* Skip spaces and get the type of file */ while (isspace (Ch = fgetc (Gbl.F.Tmp))); for (i=0, Ptr = MIMEType; !isspace (Ch) && i < Brw_MAX_BYTES_MIME_TYPE; i++) { *Ptr++ = Str_ConvertToLowerLetter ((char) Ch); Ch = fgetc (Gbl.F.Tmp); } *Ptr = '\0'; }
static void Par_CreateListOfParamsFromQueryString (void) { unsigned long CurPos; // Current position in query string struct Param *Param = NULL; // Initialized to avoid warning struct Param *NewParam; /***** Check if query string is empty *****/ if (!Gbl.Params.QueryString) return; if (!Gbl.Params.QueryString[0]) return; /***** Go over the query string getting start positions and lengths of parameters *****/ for (CurPos = 0; CurPos < Gbl.Params.ContentLength; ) { /* Allocate space for a new parameter initialized to 0 */ if ((NewParam = (struct Param *) calloc (1,sizeof (struct Param))) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for parameter"); /* Link the previous element in list with the current element */ if (CurPos == 0) Gbl.Params.List = NewParam; // Pointer to first param else Param->Next = NewParam; // Pointer from former param to new param /* Make the current element to be the just created */ Param = NewParam; /* Get parameter name */ Param->Name.Start = CurPos; Param->Name.Length = strcspn (&Gbl.Params.QueryString[CurPos],"="); CurPos += Param->Name.Length; /* Get parameter value */ if (CurPos < Gbl.Params.ContentLength) if (Gbl.Params.QueryString[CurPos] == '=') { CurPos++; // Skip '=' if (CurPos < Gbl.Params.ContentLength) { Param->Value.Start = CurPos; Param->Value.Length = strcspn (&Gbl.Params.QueryString[CurPos],"&"); CurPos += Param->Value.Length; if (CurPos < Gbl.Params.ContentLength) if (Gbl.Params.QueryString[CurPos] == '&') CurPos++; // Skip '&' } } } }
static void Ban_ShowOrHideBanner (bool Hide) { /***** Get banner code *****/ if ((Ban_EditingBan->BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /***** Get data of the banner from database *****/ Ban_GetDataOfBannerByCod (Ban_EditingBan); /***** Mark file as hidden/visible in database *****/ if (Ban_EditingBan->Hidden != Hide) DB_QueryUPDATE ("can not change status of a banner in database", "UPDATE banners SET Hidden='%c'" " WHERE BanCod=%ld", Hide ? 'Y' : 'N', Ban_EditingBan->BanCod); }
void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDirectory) { struct dirent **FileList; int NumFile; int NumFiles; char Path2[PATH_MAX+1]; struct stat FileStatus; lstat (Path,&FileStatus); if (S_ISDIR (FileStatus.st_mode)) // It's a directory { /***** Scan the directory *****/ if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0) // No error { /* Loop over files */ for (NumFile = 0; NumFile < NumFiles; NumFile++) { if (strcmp (FileList[NumFile]->d_name,".") && strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".." { sprintf (Path2,"%s/%s",Path,FileList[NumFile]->d_name); Fil_RemoveOldTmpFiles (Path2,TimeToRemove,true); // Recursive call } free ((void *) FileList[NumFile]); } free ((void *) FileList); if (RemoveDirectory) /* Remove the directory itself */ if (FileStatus.st_mtime < Gbl.StartExecutionTimeUTC - TimeToRemove) rmdir (Path); } else Lay_ShowErrorAndExit ("Error while scanning directory."); } else if (FileStatus.st_mtime < Gbl.StartExecutionTimeUTC - TimeToRemove) unlink (Path); }
void Ban_ChangeBannerWWW (void) { extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_You_can_not_leave_the_web_address_empty; char NewWWW[Cns_MAX_BYTES_WWW + 1]; /***** Banner constructor *****/ Ban_EditingBannerConstructor (); /***** Get parameters from form *****/ /* Get the code of the banner */ if ((Ban_EditingBan->BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /* Get the new WWW for the banner */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get banner data from the database *****/ Ban_GetDataOfBannerByCod (Ban_EditingBan); /***** Check if new WWW is empty *****/ if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ DB_QueryUPDATE ("can not update the web of a banner", "UPDATE banners SET WWW='%s' WHERE BanCod=%ld", NewWWW,Ban_EditingBan->BanCod); /***** Write message to show the change made *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_The_new_web_address_is_X, NewWWW); } else Ale_CreateAlert (Ale_WARNING,NULL, Txt_You_can_not_leave_the_web_address_empty); /***** Update web *****/ Str_Copy (Ban_EditingBan->WWW,NewWWW, Cns_MAX_BYTES_WWW); }
void Ban_ChangeBannerImg (void) { extern const char *Txt_The_new_image_is_X; extern const char *Txt_You_can_not_leave_the_image_empty; char NewImg[Ban_MAX_BYTES_IMAGE + 1]; /***** Banner constructor *****/ Ban_EditingBannerConstructor (); /***** Get parameters from form *****/ /* Get the code of the banner */ if ((Ban_EditingBan->BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /* Get the new WWW for the banner */ Par_GetParToText ("Img",NewImg,Ban_MAX_BYTES_IMAGE); /***** Get banner data from the database *****/ Ban_GetDataOfBannerByCod (Ban_EditingBan); /***** Check if new image is empty *****/ if (NewImg[0]) { /* Update the table changing old image by new image */ DB_QueryUPDATE ("can not update the image of a banner", "UPDATE banners SET Img='%s' WHERE BanCod=%ld", NewImg,Ban_EditingBan->BanCod); /***** Write message to show the change made *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_The_new_image_is_X, NewImg); } else Ale_CreateAlert (Ale_WARNING,NULL, Txt_You_can_not_leave_the_image_empty); /***** Update image *****/ Str_Copy (Ban_EditingBan->Img,NewImg, Ban_MAX_BYTES_IMAGE); }
void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName,char *OldName,char *NewName,FILE **NewFile) { int LongRaizFich = Str_GetLengthRootFileName (CurrentName); strncpy (NewName,CurrentName,LongRaizFich); NewName[LongRaizFich] = '\0'; sprintf (OldName,"%s%s",NewName,ExtensionOldName); strcat (NewName,".new"); /* The new file shouldn't exist. If it exists is due to any error when running this CGI formerly and the file was not renamed successfully. In this case, remove it! */ if (Fil_CheckIfPathExists (NewName)) unlink (NewName); /* Open the new file */ if ((*NewFile = fopen (NewName,"wb")) == NULL) { sprintf (Gbl.Message,"Can not create file <strong>%s</strong>.",NewName); Lay_ShowErrorAndExit (Gbl.Message); } }
void Fil_CreateFileForHTMLOutput (void) { char PathHTMLOutputPriv[PATH_MAX+1]; /***** Check if exists the directory for HTML output. If not exists, create it *****/ sprintf (PathHTMLOutputPriv,"%s/%s",Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_OUT); Fil_CreateDirIfNotExists (PathHTMLOutputPriv); /***** Remove old files *****/ Fil_RemoveOldTmpFiles (PathHTMLOutputPriv,Cfg_TIME_TO_DELETE_HTML_OUTPUT,false); /***** Create a unique name for the file *****/ sprintf (Gbl.HTMLOutput.FileName,"%s/%s.html", PathHTMLOutputPriv,Gbl.UniqueNameEncrypted); /***** Open file for writing and reading *****/ if ((Gbl.F.Out = fopen (Gbl.HTMLOutput.FileName,"w+t")) == NULL) { Gbl.F.Out = stdout; Lay_ShowErrorAndExit ("Can not create output file."); } }
void Ban_ClickOnBanner (void) { struct Banner Ban; /***** Get banner code *****/ if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /***** Get data of the banner from database *****/ Ban_GetDataOfBannerByCod (&Ban); /***** Set banner clicked in order to log it *****/ Gbl.Banners.BanCodClicked = Ban.BanCod; /***** Download the file *****/ fprintf (stdout,"Location: %s\n\n",Ban.WWW); // TODO: Put headers Content-type and Content-disposition: // See: http://stackoverflow.com/questions/381954/how-do-i-fix-firefox-trying-to-save-image-as-htm // http://elouai.com/force-download.php Gbl.Layout.HTMLStartWritten = Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true; // Don't write HTML at all }
void Not_GetSummaryAndContentNotice (char *SummaryStr,char **ContentStr, long NotCod,unsigned MaxChars,bool GetContent) { char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; SummaryStr[0] = '\0'; // Return nothing on error /***** Get subject of message from database *****/ sprintf (Query,"SELECT Content FROM notices WHERE NotCod='%ld'", NotCod); if (!mysql_query (&Gbl.mysql,Query)) if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL) { /***** Result should have a unique row *****/ if (mysql_num_rows (mysql_res) == 1) { /***** Get sumary / content *****/ row = mysql_fetch_row (mysql_res); /***** Copy summary *****/ strcpy (SummaryStr,row[0]); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); /***** Copy content *****/ if (GetContent) { if ((*ContentStr = (char *) malloc (strlen (row[0])+1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for notification content."); strcpy (*ContentStr,row[0]); } } mysql_free_result (mysql_res); } }
void Ban_RemoveBanner (void) { extern const char *Txt_Banner_X_removed; /***** Banner constructor *****/ Ban_EditingBannerConstructor (); /***** Get banner code *****/ if ((Ban_EditingBan->BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /***** Get data of the banner from database *****/ Ban_GetDataOfBannerByCod (Ban_EditingBan); /***** Remove banner *****/ DB_QueryDELETE ("can not remove a banner", "DELETE FROM banners WHERE BanCod=%ld", Ban_EditingBan->BanCod); /***** Write message to show the change made *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_Banner_X_removed, Ban_EditingBan->ShrtName); }
unsigned Not_GetNumNoticesDeleted (Sco_Scope_t Scope,unsigned *NumNotif) { char Query[1024]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumNotices; /***** Get number of notices from database *****/ switch (Scope) { case Sco_SCOPE_SYS: sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" " FROM notices_deleted"); break; case Sco_SCOPE_CTY: sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)" " FROM institutions,centres,degrees,courses,notices_deleted" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=notices_deleted.CrsCod", Gbl.CurrentCty.Cty.CtyCod); break; case Sco_SCOPE_INS: sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)" " FROM centres,degrees,courses,notices_deleted" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=notices_deleted.CrsCod", Gbl.CurrentIns.Ins.InsCod); break; case Sco_SCOPE_CTR: sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)" " FROM degrees,courses,notices_deleted" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=notices_deleted.CrsCod", Gbl.CurrentCtr.Ctr.CtrCod); break; case Sco_SCOPE_DEG: sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)" " FROM courses,notices_deleted" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=notices_deleted.CrsCod", Gbl.CurrentDeg.Deg.DegCod); break; case Sco_SCOPE_CRS: sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" " FROM notices_deleted" " WHERE CrsCod='%ld'", Gbl.CurrentCrs.Crs.CrsCod); break; default: Lay_ShowErrorAndExit ("Wrong scope."); break; } DB_QuerySELECT (Query,&mysql_res,"can not get number of deleted notices"); /***** Get number of notices *****/ row = mysql_fetch_row (mysql_res); if (sscanf (row[0],"%u",&NumNotices) != 1) Lay_ShowErrorAndExit ("Error when getting number of deleted notices."); /***** Get number of notifications by e-mail *****/ if (row[1]) { if (sscanf (row[1],"%u",NumNotif) != 1) Lay_ShowErrorAndExit ("Error when getting number of notifications of deleted notices."); } else *NumNotif = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); return NumNotices; }
void Not_ShowNotices (Not_Listing_t TypeNoticesListing,bool ICanEditNotices) { extern const char *Txt_All_notices; extern const char *Txt_No_notices; char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; char StrWidth[10+2+1]; char PathRelRSSFile[PATH_MAX+1]; long NotCod; unsigned long NumNot; unsigned long NumNotices; char Content[Cns_MAX_BYTES_TEXT+1]; time_t TimeUTC; long UsrCod; unsigned UnsignedNum; Not_Status_t Status; /***** A course must be selected (Gbl.CurrentCrs.Crs.CrsCod > 0) *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) { /***** Get notices from database *****/ switch (TypeNoticesListing) { case Not_LIST_BRIEF_NOTICES: sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" " FROM notices" " WHERE CrsCod='%ld' AND Status='%u'" " ORDER BY CreatTime DESC", Gbl.CurrentCrs.Crs.CrsCod, (unsigned) Not_ACTIVE_NOTICE); break; case Not_LIST_FULL_NOTICES: sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" " FROM notices" " WHERE CrsCod='%ld'" " ORDER BY CreatTime DESC", Gbl.CurrentCrs.Crs.CrsCod); break; } NumNotices = DB_QuerySELECT (Query,&mysql_res,"can not get notices from database"); if (TypeNoticesListing == Not_LIST_FULL_NOTICES) { if (NumNotices) { /***** Start frame *****/ sprintf (StrWidth,"%upx", Not_ContainerWidth[Not_LIST_FULL_NOTICES] + 50); Lay_StartRoundFrame (StrWidth,Txt_All_notices); } else Lay_ShowAlert (Lay_INFO,Txt_No_notices); } /***** Link to RSS file *****/ if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES) { /* Create RSS file if not exists */ sprintf (PathRelRSSFile,"%s/%s/%ld/%s/%s", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,Gbl.CurrentCrs.Crs.CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE); if (!Fil_CheckIfPathExists (PathRelRSSFile)) RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs); /* Put a link to the RSS file */ fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">" "<a href=\""); RSS_WriteRSSLink (Gbl.F.Out,Gbl.CurrentCrs.Crs.CrsCod); fprintf (Gbl.F.Out,"\" target=\"_blank\">" "<img src=\"%s/rss16x16.gif\"" " alt=\"RSS\" title=\"RSS\"" " class=\"ICON20x20\" />" "</a>" "</div>", Gbl.Prefs.IconsURL); } /***** Show the notices *****/ for (NumNot = 0; NumNot < NumNotices; NumNot++) { row = mysql_fetch_row (mysql_res); /* Get notice code (row[0]) */ if (sscanf (row[0],"%ld",&NotCod) != 1) Lay_ShowErrorAndExit ("Wrong code of notice."); /* Get creation time (row[1] holds the UTC date-time) */ TimeUTC = Dat_GetUNIXTimeFromStr (row[1]); /* Get user code (row[2]) */ UsrCod = Str_ConvertStrCodToLongCod (row[2]); /* Get the content (row[3]) and insert links */ strncpy (Content,row[3],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT, Not_MaxCharsURLOnScreen[TypeNoticesListing]); if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES) Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE); /* Get status of the notice (row[4]) */ Status = Not_OBSOLETE_NOTICE; if (sscanf (row[4],"%u",&UnsignedNum) == 1) if (UnsignedNum < Not_NUM_STATUS) Status = (Not_Status_t) UnsignedNum; /* Draw the notice */ Not_DrawANotice (TypeNoticesListing, NotCod, TimeUTC,Content,UsrCod,Status, ICanEditNotices); } if (TypeNoticesListing == Not_LIST_FULL_NOTICES && NumNotices) /***** End frame *****/ Lay_EndRoundFrame (); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); /***** Mark possible notification as seen *****/ Ntf_MarkNotifAsSeen (Ntf_EVENT_NOTICE, -1L,Gbl.CurrentCrs.Crs.CrsCod, Gbl.Usrs.Me.UsrDat.UsrCod); } }
static void Ban_RenameBanner (Cns_ShrtOrFullName_t ShrtOrFullName) { extern const char *Txt_You_can_not_leave_the_name_of_the_banner_X_empty; extern const char *Txt_The_banner_X_already_exists; extern const char *Txt_The_banner_X_has_been_renamed_as_Y; extern const char *Txt_The_name_of_the_banner_X_has_not_changed; const char *ParamName = NULL; // Initialized to avoid warning const char *FieldName = NULL; // Initialized to avoid warning unsigned MaxBytes = 0; // Initialized to avoid warning char *CurrentBanName = NULL; // Initialized to avoid warning char NewBanName[Ban_MAX_BYTES_FULL_NAME + 1]; switch (ShrtOrFullName) { case Cns_SHRT_NAME: ParamName = "ShortName"; FieldName = "ShortName"; MaxBytes = Ban_MAX_BYTES_SHRT_NAME; CurrentBanName = Ban_EditingBan->ShrtName; break; case Cns_FULL_NAME: ParamName = "FullName"; FieldName = "FullName"; MaxBytes = Ban_MAX_BYTES_FULL_NAME; CurrentBanName = Ban_EditingBan->FullName; break; } /***** Get parameters from form *****/ /* Get the code of the banner */ if ((Ban_EditingBan->BanCod = Ban_GetParamBanCod ()) == -1L) Lay_ShowErrorAndExit ("Code of banner is missing."); /* Get the new name for the banner */ Par_GetParToText (ParamName,NewBanName,MaxBytes); /***** Get banner data from the database *****/ Ban_GetDataOfBannerByCod (Ban_EditingBan); /***** Check if new name is empty *****/ if (!NewBanName[0]) Ale_CreateAlert (Ale_WARNING,NULL, Txt_You_can_not_leave_the_name_of_the_banner_X_empty, CurrentBanName); else { /***** Check if old and new names are the same (this happens when return is pressed without changes) *****/ if (strcmp (CurrentBanName,NewBanName)) // Different names { /***** If banner was in database... *****/ if (Ban_CheckIfBannerNameExists (ParamName,NewBanName,Ban_EditingBan->BanCod)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_banner_X_already_exists, NewBanName); else { /* Update the table changing old name by new name */ Ban_UpdateBanNameDB (Ban_EditingBan->BanCod,FieldName,NewBanName); /* Write message to show the change made */ Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_The_banner_X_has_been_renamed_as_Y, CurrentBanName,NewBanName); } } else // The same name Ale_CreateAlert (Ale_INFO,NULL, Txt_The_name_of_the_banner_X_has_not_changed, CurrentBanName); } /***** Update name *****/ Str_Copy (CurrentBanName,NewBanName, MaxBytes); }
static void Par_CreateListOfParamsFromTmpFile (void) { static const char *StringBeforeParam = "Content-Disposition: form-data; name=\""; static const char *StringFilename = "; filename=\""; static const char *StringContentType = "Content-Type: "; unsigned long CurPos; // Current position in temporal file struct Param *Param = NULL; // Initialized to avoid warning struct Param *NewParam; int Ch; char StrAux[Par_MAX_BYTES_STR_AUX + 1]; /***** Go over the file getting start positions and lengths of parameters *****/ if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL, Gbl.Boundary.StrWithoutCRLF, Gbl.Boundary.LengthWithoutCRLF, Fil_MAX_FILE_SIZE) == 1) // Delimiter string found for (CurPos = 0; CurPos < Gbl.Params.ContentLength; ) { /***** Skip \r\n after delimiter string *****/ if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r' if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n' Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux, Par_LENGTH_OF_STR_BEFORE_PARAM); if (!strcasecmp (StrAux,StringBeforeParam)) // Start of a parameter { /* Allocate space for a new parameter initialized to 0 */ if ((NewParam = (struct Param *) calloc (1,sizeof (struct Param))) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for parameter"); /* Link the previous element in list with the current element */ if (CurPos == 0) Gbl.Params.List = NewParam; // Pointer to first param else Param->Next = NewParam; // Pointer from former param to new param /* Make the current element to be the just created */ Param = NewParam; /***** Get parameter name *****/ CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of parameter name Param->Name.Start = CurPos; Ch = Par_ReadTmpFileUntilQuote (); CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote Param->Name.Length = CurPos - 1 - Param->Name.Start; /* Check if last character read after parameter name is a quote */ if (Ch != (int) '\"') break; // '\"' /* Get next char after parameter name */ Ch = fgetc (Gbl.F.Tmp); /***** Check if filename is present *****/ if (Ch == (int) StringFilename[0]) { Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux, Par_LENGTH_OF_STR_FILENAME-1); if (!strcasecmp (StrAux,StringFilename + 1)) // Start of filename { /* Get filename */ CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of filename Param->FileName.Start = CurPos; Ch = Par_ReadTmpFileUntilQuote (); CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote Param->FileName.Length = CurPos - 1 - Param->FileName.Start; /* Check if last character read after filename is a quote */ if (Ch != (int) '\"') break; // '\"' /* Skip \r\n */ if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r' if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n' /* Check if Content-Type is present */ Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux, Par_LENGTH_OF_STR_CONTENT_TYPE); if (!strcasecmp (StrAux,StringContentType)) // Start of Content-Type { /* Get content type */ CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of content type Param->ContentType.Start = CurPos; Ch = Par_ReadTmpFileUntilReturn (); CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after return Param->ContentType.Length = CurPos - 1 - Param->ContentType.Start; } } } /***** Now \r\n\r\n is expected just before parameter value or file content *****/ /* Check if last character read is '\r' */ if (Ch != 0x0D) break; // '\r' /* Skip \n\r\n */ if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n' if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r' if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n' /***** Get parameter value or file content *****/ CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of value or file content if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL, Gbl.Boundary.StrWithCRLF, Gbl.Boundary.LengthWithCRLF, Fil_MAX_FILE_SIZE) != 1) break; // Boundary string not found // Delimiter string found Param->Value.Start = CurPos; CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after delimiter string Param->Value.Length = CurPos - Gbl.Boundary.LengthWithCRLF - Param->Value.Start; } } }
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, char *ParamValue,size_t MaxBytes, struct Param **ParamPtr) // NULL if not used { size_t BytesAlreadyCopied = 0; unsigned i; struct Param *Param; char *PtrDst; unsigned NumTimes; bool ParamFound = false; unsigned ParamNameLength; bool FindMoreThanOneOcurrence; char ErrorTxt[256]; /***** Default values returned *****/ if (ParamValue) ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string /***** Only some selected parameters can be passed by GET method *****/ if (Gbl.Params.GetMethod) if (!Par_CheckIsParamCanBeUsedInGETMethod (ParamName)) return 0; // Return no-parameters-found /***** Initializations *****/ ParamNameLength = strlen (ParamName); PtrDst = ParamValue; FindMoreThanOneOcurrence = (ParamType == Par_PARAM_MULTIPLE); /***** For multiple parameters, loop for any ocurrence of the parameter For unique parameter, find only the first ocurrence *****/ for (Param = Gbl.Params.List, NumTimes = 0; Param != NULL && (FindMoreThanOneOcurrence || NumTimes == 0); ) /***** Find next ocurrence of parameter in list of parameters *****/ for (ParamFound = false; Param != NULL && !ParamFound; Param = Param->Next) { if (Param->Name.Length == ParamNameLength) { // The current element in the list has the length of the searched parameter // Check if the name of the parameter is the same switch (Gbl.ContentReceivedByCGI) { case Act_CONT_NORM: ParamFound = !strncmp (ParamName,&Gbl.Params.QueryString[Param->Name.Start], Param->Name.Length); break; case Act_CONT_DATA: fseek (Gbl.F.Tmp,Param->Name.Start,SEEK_SET); for (i = 0, ParamFound = true; i < Param->Name.Length && ParamFound; i++) if (ParamName[i] != (char) fgetc (Gbl.F.Tmp)) ParamFound = false; break; } if (ParamFound) { NumTimes++; if (NumTimes == 1) // NumTimes == 1 ==> the first ocurrence of this parameter { /***** Get the first ocurrence of this parameter in list *****/ if (ParamPtr) *ParamPtr = Param; /***** If this parameter is a file ==> do not find more ocurrences ******/ if (Param->FileName.Start != 0) // It's a file FindMoreThanOneOcurrence = false; } else // NumTimes > 1 ==> not the first ocurrence of this parameter { /***** Add separator when param multiple *****/ /* Check if there is space to copy separator */ if (BytesAlreadyCopied + 1 > MaxBytes) { snprintf (ErrorTxt,sizeof (ErrorTxt), "Multiple parameter <strong>%s</strong> too large," " it exceed the maximum allowed size (%lu bytes).", ParamName,(unsigned long) MaxBytes); Lay_ShowErrorAndExit (ErrorTxt); } /* Copy separator */ if (PtrDst) *PtrDst++ = Par_SEPARATOR_PARAM_MULTIPLE; // Separator in the destination string BytesAlreadyCopied++; } /***** Copy parameter value *****/ if (Param->Value.Length) { /* Check if there is space to copy the parameter value */ if (BytesAlreadyCopied + Param->Value.Length > MaxBytes) { snprintf (ErrorTxt,sizeof (ErrorTxt), "Parameter <strong>%s</strong> too large," " it exceed the maximum allowed size (%lu bytes).", ParamName,(unsigned long) MaxBytes); Lay_ShowErrorAndExit (ErrorTxt); } /* Copy parameter value */ switch (Gbl.ContentReceivedByCGI) { case Act_CONT_NORM: if (PtrDst) strncpy (PtrDst,&Gbl.Params.QueryString[Param->Value.Start], Param->Value.Length); break; case Act_CONT_DATA: if (Param->FileName.Start == 0 && // Copy into destination only if it's not a file PtrDst) { fseek (Gbl.F.Tmp,Param->Value.Start,SEEK_SET); if (fread ((void *) PtrDst,sizeof (char),Param->Value.Length,Gbl.F.Tmp) != Param->Value.Length) Lay_ShowErrorAndExit ("Error while getting value of parameter."); } break; } BytesAlreadyCopied += Param->Value.Length; if (PtrDst) PtrDst += Param->Value.Length; } } } } if (PtrDst) *PtrDst = '\0'; // Add the final NULL return NumTimes; }
void Net_ShowWebAndSocialNetworksStats (void) { extern const char *Hlp_ANALYTICS_Figures_webs_social_networks; extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES]; extern const char *Txt_Web_social_network; extern const char *Txt_No_of_users; extern const char *Txt_PERCENT_of_users; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumRows = 0; // Initialized to avoid warning unsigned NumRow; Net_WebsAndSocialNetworks_t Web; char NetName[Net_MAX_BYTES_NETWORK_NAME + 1]; unsigned NumUsrsTotal; unsigned NumUsrs; /***** Get total number of users in current scope *****/ NumUsrsTotal = (Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () : Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current, 1 << Rol_STD | 1 << Rol_NET | 1 << Rol_TCH); /***** Get number of users with a web / social network *****/ switch (Gbl.Scope.Current) { case Hie_SYS: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT Web,COUNT(*) AS N" " FROM usr_webs" " GROUP BY Web" " ORDER BY N DESC,Web"); break; case Hie_CTY: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT usr_webs.Web," "COUNT(DISTINCT usr_webs.UsrCod) AS N" " FROM institutions,centres,degrees,courses,crs_usr,usr_webs" " WHERE institutions.CtyCod=%ld" " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_webs.UsrCod" " GROUP BY usr_webs.Web" " ORDER BY N DESC,usr_webs.Web", Gbl.Hierarchy.Cty.CtyCod); break; case Hie_INS: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT usr_webs.Web," "COUNT(DISTINCT usr_webs.UsrCod) AS N" " FROM centres,degrees,courses,crs_usr,usr_webs" " WHERE centres.InsCod=%ld" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_webs.UsrCod" " GROUP BY usr_webs.Web" " ORDER BY N DESC,usr_webs.Web", Gbl.Hierarchy.Ins.InsCod); break; case Hie_CTR: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT usr_webs.Web," "COUNT(DISTINCT usr_webs.UsrCod) AS N" " FROM degrees,courses,crs_usr,usr_webs" " WHERE degrees.CtrCod=%ld" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_webs.UsrCod" " GROUP BY usr_webs.Web" " ORDER BY N DESC,usr_webs.Web", Gbl.Hierarchy.Ctr.CtrCod); break; case Hie_DEG: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT usr_webs.Web," "COUNT(DISTINCT usr_webs.UsrCod) AS N" " FROM courses,crs_usr,usr_webs" " WHERE courses.DegCod=%ld" " AND courses.CrsCod=crs_usr.CrsCod" " AND crs_usr.UsrCod=usr_webs.UsrCod" " GROUP BY usr_webs.Web" " ORDER BY N DESC,usr_webs.Web", Gbl.Hierarchy.Deg.DegCod); break; case Hie_CRS: NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of users" " with webs / social networks", "SELECT usr_webs.Web," "COUNT(DISTINCT usr_webs.UsrCod) AS N" " FROM crs_usr,usr_webs" " WHERE crs_usr.CrsCod=%ld" " AND crs_usr.UsrCod=usr_webs.UsrCod" " GROUP BY usr_webs.Web" " ORDER BY N DESC,usr_webs.Web", Gbl.Hierarchy.Crs.CrsCod); break; default: Lay_WrongScopeExit (); break; } /***** Start box and table *****/ Box_StartBoxTable (NULL,Txt_FIGURE_TYPES[Fig_SOCIAL_NETWORKS],NULL, Hlp_ANALYTICS_Figures_webs_social_networks,Box_NOT_CLOSABLE,2); /***** Write heading *****/ fprintf (Gbl.F.Out,"<tr>" "<th class=\"LEFT_MIDDLE\">" "%s" "</th>" "<th class=\"RIGHT_MIDDLE\">" "%s" "</th>" "<th class=\"RIGHT_MIDDLE\">" "%s" "</th>" "</tr>", Txt_Web_social_network, Txt_No_of_users, Txt_PERCENT_of_users); /***** For each web / social network... *****/ for (NumRow = 0; NumRow < NumRows; NumRow++) { /* Get row */ row = mysql_fetch_row (mysql_res); /* Get web / social network (row[0]) */ Str_Copy (NetName,row[0], Net_MAX_BYTES_NETWORK_NAME); for (Web = (Net_WebsAndSocialNetworks_t) 0; Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS; Web++) if (!strcmp (Net_WebsAndSocialNetworksDB[Web],NetName)) break; if (Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS) { /* Get number of users (row[1]) */ if (sscanf (row[1],"%u",&NumUsrs) != 1) Lay_ShowErrorAndExit ("Error when getting number of files."); fprintf (Gbl.F.Out,"<tr>" "<td class=\"DAT LEFT_MIDDLE\">" "<img src=\"%s/%s\"" " alt=\"%s\" title=\"%s\"" " class=\"CONTEXT_ICO_16x16\"" " style=\"margin-right:6px;\" />" "%s</td>" "<td class=\"DAT RIGHT_MIDDLE\">" "%u" "</td>" "<td class=\"DAT RIGHT_MIDDLE\">" "%.2f%%" "</td>" "</tr>", Cfg_URL_ICON_PUBLIC,Net_WebsAndSocialNetworksIcons[Web], Net_WebsAndSocialNetworksTitle[Web], Net_WebsAndSocialNetworksTitle[Web], Net_WebsAndSocialNetworksTitle[Web], NumUsrs, NumUsrsTotal ? 100.0 * (float) NumUsrs / (float) NumUsrsTotal : 0.0); } } /***** End table and box *****/ Box_EndBoxTable (); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); }