"); Pho_ShowUsrPhoto (UsrDat,PhotoURL, "PHOTO186x248",Pho_NO_ZOOM,false); fprintf (Gbl.F.Out,"
"); Ale_ShowAlert (Ale_INFO,Txt_You_can_send_a_file_with_an_image_in_JPEG_format_); /***** Form to upload photo *****/ fprintf (Gbl.F.Out,"", The_ClassForm[Gbl.Prefs.Theme], Txt_File_with_the_photo, Fil_NAME_OF_PARAM_FILENAME_ORG, Gbl.Form.Id); /***** End form *****/ Act_FormEnd (); /***** End box *****/ Box_EndBox (); } /*****************************************************************************/ /*********************** Send another user's photograph **********************/ /*****************************************************************************/ void Pho_SendPhotoUsr (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; /***** Get user whose photo must be sent or removed *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { if (Pho_ICanChangeOtherUsrPhoto (&Gbl.Usrs.Other.UsrDat)) // If I have permission to change user's photo... { Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Gbl.Usrs.Other.UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me /***** Form to send my photo *****/ Pho_ReqMyPhotoWithContextLinks (); else /***** Form to send another user's photo *****/ Pho_ReqOtherUsrPhoto (); } else Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } else // User not found Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } /*****************************************************************************/ /**************** Receive my photo and detect faces on it ********************/ /*****************************************************************************/ void Pho_RecMyPhotoDetFaces (void) { /***** Receive my photo and detect faces on it *****/ if (!Pho_ReceivePhotoAndDetectFaces (true,&Gbl.Usrs.Me.UsrDat)) Pho_ReqMyPhoto (); // Request my photograph again } /*****************************************************************************/ /********** Receive another user's photo and detect faces on it **************/ /*****************************************************************************/ void Pho_RecOtherUsrPhotoDetFaces (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; /***** Get user's code from form *****/ Usr_GetParamOtherUsrCodEncryptedAndGetListIDs (); /***** Get password, user type and user's data from database *****/ if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) { /***** Receive photo *****/ if (!Pho_ReceivePhotoAndDetectFaces (false,&Gbl.Usrs.Other.UsrDat)) Pho_ReqOtherUsrPhoto (); // Request user's photograph again } else Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } /*****************************************************************************/ /********************** Request the removal of my photo **********************/ /*****************************************************************************/ void Pho_ReqRemoveMyPhoto (void) { extern const char *Txt_Do_you_really_want_to_remove_your_photo; extern const char *Txt_Remove_photo; extern const char *Txt_The_photo_no_longer_exists; /***** Show current photo and help message *****/ if (Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,Gbl.Usrs.Me.PhotoURL)) { /***** Show question and button to remove my photo *****/ /* Start alert */ Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_remove_your_photo); /* Show current photo */ Pho_ShowUsrPhoto (&Gbl.Usrs.Me.UsrDat,Gbl.Usrs.Me.PhotoURL, "PHOTO186x248",Pho_NO_ZOOM,false); /* End alert */ Ale_ShowAlertAndButton2 (ActRemMyPho,NULL,NULL,NULL, Btn_REMOVE_BUTTON,Txt_Remove_photo); } else Ale_ShowAlert (Ale_INFO,Txt_The_photo_no_longer_exists); } /*****************************************************************************/ /****************************** Remove my photo ******************************/ /*****************************************************************************/ void Pho_RemoveMyPhoto1 (void) { /***** Remove photo *****/ Pho_RemovePhoto (&Gbl.Usrs.Me.UsrDat); /***** The link to my photo is not valid now, so build it again before writing the web page *****/ Gbl.Usrs.Me.MyPhotoExists = Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,Gbl.Usrs.Me.PhotoURL); } void Pho_RemoveMyPhoto2 (void) { /***** Write success / warning message *****/ Ale_ShowPendingAlert (); } /*****************************************************************************/ /**************** Request the removal of another user's photo ****************/ /*****************************************************************************/ void Pho_ReqRemoveUsrPhoto (void) { extern const char *Txt_Photo; extern const char *Txt_Do_you_really_want_to_remove_the_photo_of_X; extern const char *Txt_Remove_photo; extern const char *Txt_The_photo_no_longer_exists; extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char PhotoURL[PATH_MAX + 1]; Act_Action_t NextAction; /***** Get user's code from form *****/ Usr_GetParamOtherUsrCodEncryptedAndGetListIDs (); /***** Get password, user type and user's data from database *****/ if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) { if (Pho_ICanChangeOtherUsrPhoto (&Gbl.Usrs.Other.UsrDat)) { /***** Show current photo and help message *****/ if (Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL)) { /***** Show question and button to remove user's photo *****/ /* Start alert */ sprintf (Gbl.Alert.Txt,Txt_Do_you_really_want_to_remove_the_photo_of_X, Gbl.Usrs.Other.UsrDat.FullName); Ale_ShowAlertAndButton1 (Ale_QUESTION,Gbl.Alert.Txt); /* Show current photo */ Pho_ShowUsrPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL, "PHOTO186x248",Pho_NO_ZOOM,false); /* End alert */ switch (Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role) { case Rol_STD: NextAction = ActRemStdPho; break; case Rol_NET: case Rol_TCH: NextAction = ActRemTchPho; break; default: // Guest, user or admin NextAction = ActRemOthPho; break; } Ale_ShowAlertAndButton2 (NextAction,NULL,NULL, Usr_PutParamOtherUsrCodEncrypted, Btn_REMOVE_BUTTON,Txt_Remove_photo); } else Ale_ShowAlert (Ale_INFO,Txt_The_photo_no_longer_exists); } else Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } else Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } /*****************************************************************************/ /************************ Remove another user's photo ************************/ /*****************************************************************************/ void Pho_RemoveUsrPhoto (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; /***** Get user's code from form *****/ Usr_GetParamOtherUsrCodEncryptedAndGetListIDs (); /***** Get password, user type and user's data from database *****/ if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) { /***** Remove photo *****/ if (Pho_RemovePhoto (&Gbl.Usrs.Other.UsrDat)) Ale_ShowPendingAlert (); } else Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } /*****************************************************************************/ /***************** Receive a photo and detect faces on it ********************/ /*****************************************************************************/ // Return false if no "green" faces detected static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *UsrDat) { extern const char *Txt_The_file_is_not_X; extern const char *Txt_Could_not_detect_any_face_in_front_position_; extern const char *Txt_A_face_marked_in_green_has_been_detected_; extern const char *Txt_A_face_marked_in_red_has_been_detected_; extern const char *Txt_X_faces_marked_in_green_have_been_detected_; extern const char *Txt_X_faces_marked_in_red_have_been_detected_; extern const char *Txt_X_faces_have_been_detected_in_front_position_1_Z_; extern const char *Txt_X_faces_have_been_detected_in_front_position_Y_Z_; extern const char *Txt_Faces_detected; char PathPhotosPriv[PATH_MAX + 1]; char PathPhotosPubl[PATH_MAX + 1]; struct Param *Param; char FileNamePhotoSrc[PATH_MAX + 1]; char FileNamePhotoTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination temporary file char FileNamePhotoMap[PATH_MAX + 1]; // Full name (including path) of the temporary file with the original image with faces char FileNameTxtMap[PATH_MAX + 1]; // Full name (including path) of the temporary file with the text neccesary to make the image map char PathRelPhoto[PATH_MAX + 1]; FILE *FileTxtMap = NULL; // Temporary file with the text neccesary to make the image map. Initialized to avoid warning char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; bool WrongType = false; char Command[256 + PATH_MAX]; // Command to call the program of preprocessing of photos int ReturnCode; int NumLastForm = 0; // Initialized to avoid warning char FormId[32]; unsigned NumFacesTotal = 0; unsigned NumFacesGreen = 0; unsigned NumFacesRed = 0; unsigned NumFace; unsigned X; unsigned Y; unsigned Radius; unsigned BackgroundCode; char StrFileName[NAME_MAX + 1]; Act_Action_t NextAction; /***** Creates directories if not exist *****/ sprintf (PathPhotosPriv,"%s/%s", Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_PHOTO); Fil_CreateDirIfNotExists (PathPhotosPriv); sprintf (PathPhotosPriv,"%s/%s/%02u", Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_PHOTO, (unsigned) (UsrDat->UsrCod % 100)); Fil_CreateDirIfNotExists (PathPhotosPriv); /***** Create directories if not exists and remove old temporary files *****/ /* Create public directory for photos */ sprintf (PathPhotosPubl,"%s/%s", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO); Fil_CreateDirIfNotExists (PathPhotosPubl); /* Create temporary directory for photos */ sprintf (PathPhotosPubl,"%s/%s/%s", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO,Cfg_FOLDER_PHOTO_TMP); Fil_CreateDirIfNotExists (PathPhotosPubl); /* Remove old temporary files */ Fil_RemoveOldTmpFiles (PathPhotosPubl,Cfg_TIME_TO_DELETE_PHOTOS_TMP_FILES,false); /***** First of all, copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/ Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG, FileNamePhotoSrc,MIMEType); /* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */ if (strcmp (MIMEType,"image/jpeg")) if (strcmp (MIMEType,"image/pjpeg")) if (strcmp (MIMEType,"application/octet-stream")) if (strcmp (MIMEType,"application/octetstream")) if (strcmp (MIMEType,"application/octet")) WrongType = true; if (WrongType) { sprintf (Gbl.Alert.Txt,Txt_The_file_is_not_X,"jpg"); Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt); return false; } /* End the reception of photo in a temporary file */ sprintf (FileNamePhotoTmp,"%s/%s/%s/%s.jpg", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO, Cfg_FOLDER_PHOTO_TMP,Gbl.UniqueNameEncrypted); if (!Fil_EndReceptionOfFile (FileNamePhotoTmp,Param)) { Ale_ShowAlert (Ale_WARNING,"Error copying file."); return false; } /* Copy the original photo received to private directory. The purpose of this copy is only to have a backup used for researching better methods to detect faces in images */ sprintf (PathRelPhoto,"%s/%s/%02u/%ld_original.jpg", Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_PHOTO, (unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod); Fil_FastCopyOfFiles (FileNamePhotoTmp,PathRelPhoto); /***** Call to program that makes photo processing / face detection *****/ sprintf (Command,Cfg_COMMAND_FACE_DETECTION,FileNamePhotoTmp); ReturnCode = system (Command); if (ReturnCode == -1) Lay_ShowErrorAndExit ("Error when running command to process photo and detect faces."); /***** Write message depending on return code *****/ ReturnCode = WEXITSTATUS(ReturnCode); switch (ReturnCode) { case 0: // Faces detected /***** Open text file with text for image map *****/ sprintf (FileNameTxtMap,"%s/%s/%s/%s_map.txt", Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO, Cfg_FOLDER_PHOTO_TMP,Gbl.UniqueNameEncrypted); if ((FileTxtMap = fopen (FileNameTxtMap,"rb")) == NULL) Lay_ShowErrorAndExit ("Can not read text file with coordinates of detected faces."); /***** Read file with coordinates for image map and compute the number of faces *****/ NumLastForm = Gbl.Form.Num; while (!feof (FileTxtMap)) { if (fscanf (FileTxtMap,"%u %u %u %u %s\n",&X,&Y,&Radius,&BackgroundCode,StrFileName) != 5) // Example of StrFileName = "4924a838630e_016" break; if (BackgroundCode == 1) { NumFacesGreen++; if (ItsMe) Act_FormStart (ActUpdMyPho); else { switch (Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role) { case Rol_STD: NextAction = ActUpdStdPho; break; case Rol_NET: case Rol_TCH: NextAction = ActUpdTchPho; break; default: // Guest, user or admin NextAction = ActUpdOthPho; break; } Act_FormStart (NextAction); Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod); } Par_PutHiddenParamString ("FileName",StrFileName); Act_FormEnd (); } else NumFacesRed++; } NumFacesTotal = NumFacesGreen + NumFacesRed; break; case 1: // No faces detected NumFacesTotal = NumFacesGreen = NumFacesRed = 0; break; default: // Error sprintf (Gbl.Alert.Txt,"Photo could not be processed successfully.