swad-core/swad_search.c

1370 lines
50 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_search.c: search for courses and teachers
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
#include <stdio.h> // For fprintf...
2017-01-16 01:51:01 +01:00
#include <string.h> // For string functions...
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
#include "swad_global.h"
#include "swad_layout.h"
#include "swad_parameter.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal constants ****************************/
/*****************************************************************************/
#define Sch_MIN_LENGTH_LONGEST_WORD 3
2016-12-19 09:39:08 +01:00
#define Sch_MIN_LENGTH_TOTAL 3 // "A An" is not valid; "A An Ann" is valid
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Internal prototypes ***************************/
/*****************************************************************************/
static void Sch_PutFormToSearchWithWhatToSearchAndScope (Act_Action_t Action,Sco_Scope_t DefaultScope);
static bool Sch_CheckIfIHavePermissionToSearch (Sch_WhatToSearch_t WhatToSearch);
2017-03-12 21:15:32 +01:00
static void Sch_GetParamSearch (void);
2014-12-01 23:55:08 +01:00
static void Sch_SearchInDB (void);
2017-02-28 00:59:01 +01:00
static unsigned Sch_SearchCountriesInDB (const char *RangeQuery);
2014-12-01 23:55:08 +01:00
static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery);
static unsigned Sch_SearchCentresInDB (const char *RangeQuery);
static unsigned Sch_SearchDegreesInDB (const char *RangeQuery);
static unsigned Sch_SearchCoursesInDB (const char *RangeQuery);
static unsigned Sch_SearchUsrsInDB (Rol_Role_t Role);
static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery);
static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery);
static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery);
static void Sch_SaveLastSearchIntoSession (void);
/*****************************************************************************/
/*********************** Request search in system tab ************************/
/*****************************************************************************/
void Sch_ReqSysSearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActSysSch,Sco_SCOPE_SYS);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Request search in country tab ************************/
/*****************************************************************************/
void Sch_ReqCtySearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCtySch,Sco_SCOPE_CTY);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Request search in institution tab **********************/
/*****************************************************************************/
void Sch_ReqInsSearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActInsSch,Sco_SCOPE_INS);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Request search in centre tab ************************/
/*****************************************************************************/
void Sch_ReqCtrSearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCtrSch,Sco_SCOPE_CTR);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Request search in degree tab ************************/
/*****************************************************************************/
void Sch_ReqDegSearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActDegSch,Sco_SCOPE_DEG);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Request search in course tab ************************/
/*****************************************************************************/
void Sch_ReqCrsSearch (void)
{
/***** Select one of my courses *****/
if (Gbl.Usrs.Me.Logged)
{
2015-04-02 14:22:21 +02:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2014-12-13 20:32:10 +01:00
Crs_PutFormToSelectMyCourses ();
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/***** Search courses, teachers, documents... *****/
2014-12-15 00:05:10 +01:00
Sch_GetParamWhatToSearch ();
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCrsSch,Sco_SCOPE_CRS);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Put a form to search, including scope ********************/
/*****************************************************************************/
static void Sch_PutFormToSearchWithWhatToSearchAndScope (Act_Action_t Action,Sco_Scope_t DefaultScope)
{
2016-11-27 19:21:56 +01:00
extern const char *Hlp_Search;
2015-07-28 00:16:09 +02:00
extern const char *The_ClassForm[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Scope;
2016-04-18 10:22:56 +02:00
extern const char *Txt_SEARCH_X_in_Y;
extern const char *Txt_all;
2017-02-28 00:59:01 +01:00
extern const char *Txt_countries;
2016-04-18 10:22:56 +02:00
extern const char *Txt_institutions;
extern const char *Txt_centres;
extern const char *Txt_degrees;
extern const char *Txt_courses;
2016-06-27 12:35:15 +02:00
extern const char *Txt_users[Usr_NUM_SEXS];
2016-04-18 10:22:56 +02:00
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_my_documents;
extern const char *Txt_documents_in_my_courses;
extern const char *Txt_open_documents;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Search;
const char *Titles[Sch_NUM_WHAT_TO_SEARCH] =
{
2017-01-29 12:42:19 +01:00
"", // Sch_SEARCH_UNKNOWN
2016-04-18 10:22:56 +02:00
Txt_all, // Sch_SEARCH_ALL
2017-02-28 00:59:01 +01:00
Txt_countries, // Sch_SEARCH_COUNTRIES
2016-10-28 10:03:37 +02:00
Txt_institutions, // Sch_SEARCH_INSTITS
2016-04-18 10:22:56 +02:00
Txt_centres, // Sch_SEARCH_CENTRES
Txt_degrees, // Sch_SEARCH_DEGREES
Txt_courses, // Sch_SEARCH_COURSES
2016-06-27 12:35:15 +02:00
Txt_users[Usr_SEX_UNKNOWN], // Sch_SEARCH_USERS
2016-04-18 10:22:56 +02:00
Txt_ROLES_PLURAL_abc[Rol_TEACHER][Usr_SEX_UNKNOWN], // Sch_SEARCH_TEACHERS
Txt_ROLES_PLURAL_abc[Rol_STUDENT][Usr_SEX_UNKNOWN], // Sch_SEARCH_STUDENTS
Txt_ROLES_PLURAL_abc[Rol__GUEST_][Usr_SEX_UNKNOWN], // Sch_SEARCH_GUESTS
Txt_open_documents, // Sch_SEARCH_OPEN_DOCUMENTS
Txt_documents_in_my_courses, // Sch_SEARCH_DOCUM_IN_MY_COURSES
Txt_my_documents, // Sch_SEARCH_MY_DOCUMENTS
2014-12-01 23:55:08 +01:00
};
Sch_WhatToSearch_t WhatToSearch;
2015-04-11 17:33:14 +02:00
/***** Start form *****/
2015-08-24 12:29:00 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
2014-12-01 23:55:08 +01:00
Act_FormStart (Action);
2016-11-27 19:21:56 +01:00
Lay_StartRoundFrame (NULL,Txt_Search,NULL,Hlp_Search);
2014-12-01 23:55:08 +01:00
2016-06-24 20:16:06 +02:00
/***** Scope (whole platform, current country, current institution,
current centre, current degree or current course) *****/
2016-03-27 21:36:52 +02:00
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">"
2016-12-20 02:18:50 +01:00
"<label class=\"%s\">%s:&nbsp;",
2015-07-28 00:16:09 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_Scope);
2015-07-26 10:11:55 +02:00
Gbl.Scope.Allowed = 1 << Sco_SCOPE_SYS |
1 << Sco_SCOPE_CTY |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_INS |
2015-07-26 10:11:55 +02:00
1 << Sco_SCOPE_CTR |
1 << Sco_SCOPE_DEG |
2015-02-01 20:17:24 +01:00
1 << Sco_SCOPE_CRS;
2014-12-01 23:55:08 +01:00
Gbl.Scope.Default = DefaultScope;
2016-06-24 20:34:58 +02:00
Sco_GetScope ("ScopeSch");
Sco_PutSelectorScope ("ScopeSch",false);
2016-12-20 02:18:50 +01:00
fprintf (Gbl.F.Out,"</label>"
"</div>");
2014-12-01 23:55:08 +01:00
2016-04-18 10:22:56 +02:00
/***** String to find *****/
Sch_PutInputStringToSearch (NULL);
2014-12-01 23:55:08 +01:00
/***** What to search? *****/
2016-12-25 21:43:59 +01:00
fprintf (Gbl.F.Out,"<label class=\"%s\">"
" %s&nbsp;",
2016-04-18 10:22:56 +02:00
The_ClassForm[Gbl.Prefs.Theme],Txt_SEARCH_X_in_Y);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"WhatToSearch\" style=\"width:186px;\">");
2014-12-01 23:55:08 +01:00
for (WhatToSearch = (Sch_WhatToSearch_t) 0;
WhatToSearch < Sch_NUM_WHAT_TO_SEARCH;
WhatToSearch++)
if (Sch_CheckIfIHavePermissionToSearch (WhatToSearch))
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",
(unsigned) WhatToSearch);
if (Gbl.Search.WhatToSearch == WhatToSearch)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",
Titles[WhatToSearch]);
}
2016-12-25 21:43:59 +01:00
fprintf (Gbl.F.Out,"</select>"
"</label>");
2014-12-01 23:55:08 +01:00
2016-04-18 10:22:56 +02:00
/***** Magnifying glass icon *****/
Sch_PutMagnifyingGlassButton ("search64x64.png");
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +02:00
/***** Send button and end frame *****/
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameWithButton (Lay_CONFIRM_BUTTON,Txt_Search);
2014-12-01 23:55:08 +01:00
2015-04-11 17:33:14 +02:00
/***** End form *****/
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Check if I have permission to execute an action ***************/
/*****************************************************************************/
static bool Sch_CheckIfIHavePermissionToSearch (Sch_WhatToSearch_t WhatToSearch)
{
unsigned Permissions[Sch_NUM_WHAT_TO_SEARCH] =
{
2017-01-29 12:42:19 +01:00
0x000, // Sch_SEARCH_UNKNOWN
2014-12-01 23:55:08 +01:00
0x1FF, // Sch_SEARCH_ALL
2017-02-28 00:59:01 +01:00
0x1FF, // Sch_SEARCH_COUNTRIES
2016-10-28 10:03:37 +02:00
0x1FF, // Sch_SEARCH_INSTITS
2014-12-01 23:55:08 +01:00
0x1FF, // Sch_SEARCH_CENTRES
0x1FF, // Sch_SEARCH_DEGREES
0x1FF, // Sch_SEARCH_COURSES
2016-06-27 12:35:15 +02:00
0x1FF, // Sch_SEARCH_USERS
2014-12-01 23:55:08 +01:00
0x1FF, // Sch_SEARCH_TEACHERS
2016-06-23 19:02:57 +02:00
0x1FF, // Sch_SEARCH_STUDENTS
2016-06-24 19:00:56 +02:00
0x1FF, // Sch_SEARCH_GUESTS
2014-12-01 23:55:08 +01:00
0x1FF, // Sch_SEARCH_OPEN_DOCUMENTS
2015-01-26 12:39:48 +01:00
0x1FE, // Sch_SEARCH_DOCUM_IN_MY_COURSES Only if I am logged
2014-12-01 23:55:08 +01:00
0x1FE, // Sch_SEARCH_MY_DOCUMENTS Only if I am logged
};
return (Permissions[WhatToSearch] & (1 << Gbl.Usrs.Me.LoggedRole));
}
2016-06-24 20:16:06 +02:00
/*****************************************************************************/
/**************** Put a form to search in page top heading *******************/
/*****************************************************************************/
void Sch_PutFormToSearchInPageTopHeading (void)
{
2017-02-28 00:59:01 +01:00
Act_Action_t ActionSearch =
(Gbl.CurrentCrs.Crs.CrsCod > 0 ? ActCrsSch :
(Gbl.CurrentDeg.Deg.DegCod > 0 ? ActDegSch :
(Gbl.CurrentCtr.Ctr.CtrCod > 0 ? ActCtrSch :
(Gbl.CurrentIns.Ins.InsCod > 0 ? ActInsSch :
(Gbl.CurrentCty.Cty.CtyCod > 0 ? ActCtySch :
ActSysSch)))));
2017-02-26 23:44:50 +01:00
/***** Put form *****/
fprintf (Gbl.F.Out,"<div id=\"head_row_1_search\">");
2016-06-24 20:16:06 +02:00
Act_FormStart (ActionSearch);
2017-02-26 23:44:50 +01:00
Sco_PutParamScope ("ScopeSch",Sco_SCOPE_SYS);
2016-06-24 20:16:06 +02:00
Sch_PutInputStringToSearch ("head_search_text");
Sch_PutMagnifyingGlassButton ("search-white64x64.png");
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>"); // head_row_1_search
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-04-18 10:22:56 +02:00
/********************* Put string to search inside form **********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-04-18 10:22:56 +02:00
void Sch_PutInputStringToSearch (const char *IdInputText)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Search;
/***** String to find *****/
2016-12-20 10:03:00 +01:00
// Input field not required, because it can be hidden (display:none)
2015-11-27 11:54:56 +01:00
fprintf (Gbl.F.Out,"<input");
if (IdInputText)
fprintf (Gbl.F.Out," id=\"%s\"",IdInputText);
2016-12-19 09:39:08 +01:00
fprintf (Gbl.F.Out," type=\"search\" name=\"Search\""
2016-12-10 18:32:35 +01:00
" size=\"18\" maxlength=\"%u\" value=\"%s\"",
2017-03-07 11:03:05 +01:00
Sch_MAX_CHARS_STRING_TO_FIND,
2014-12-01 23:55:08 +01:00
Gbl.Search.Str);
if (!Gbl.Search.Str[0])
2016-01-15 11:41:45 +01:00
fprintf (Gbl.F.Out," placeholder=\"%s&hellip;\"",
2014-12-01 23:55:08 +01:00
Txt_Search);
2016-12-20 10:03:00 +01:00
fprintf (Gbl.F.Out," style=\"margin:0;\" />");
2016-04-18 10:22:56 +02:00
}
/*****************************************************************************/
/******************* Put magnifying glass button inside form *****************/
/*****************************************************************************/
void Sch_PutMagnifyingGlassButton (const char *Icon)
{
extern const char *Txt_Search;
2014-12-01 23:55:08 +01:00
/***** Send button *****/
2015-12-08 19:21:40 +01:00
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s\""
2015-09-05 11:48:44 +02:00
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />",
2015-12-08 19:21:40 +01:00
Gbl.Prefs.IconsURL,
Icon,
2014-12-01 23:55:08 +01:00
Txt_Search,
Txt_Search);
}
/*****************************************************************************/
/************* Get parameter "what to search" from search form ***************/
/*****************************************************************************/
2014-12-13 21:38:31 +01:00
void Sch_GetParamWhatToSearch (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 12:42:19 +01:00
Sch_WhatToSearch_t WhatToSearch;
2014-12-01 23:55:08 +01:00
2014-12-15 00:05:10 +01:00
/***** Get what to search from form *****/
2017-01-29 12:42:19 +01:00
WhatToSearch = (Sch_WhatToSearch_t)
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong ("WhatToSearch",
0,
Sch_NUM_WHAT_TO_SEARCH - 1,
(unsigned long) Sch_SEARCH_UNKNOWN);
2014-12-01 23:55:08 +01:00
2014-12-15 00:05:10 +01:00
// If parameter WhatToSearch is not present, use parameter from session
2017-01-29 12:42:19 +01:00
if (WhatToSearch != Sch_SEARCH_UNKNOWN)
Gbl.Search.WhatToSearch = WhatToSearch;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get string from search form *************************/
/*****************************************************************************/
2017-03-12 21:15:32 +01:00
static void Sch_GetParamSearch (void)
2014-12-01 23:55:08 +01:00
{
/***** Get string to search *****/
2017-03-12 21:15:32 +01:00
Par_GetParToText ("Search",Gbl.Search.Str,Sch_MAX_BYTES_STRING_TO_FIND);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Get parameters to search **************************/
/*****************************************************************************/
void Sch_GetParamsSearch (void)
{
/***** What to search? *****/
2014-12-13 21:38:31 +01:00
Sch_GetParamWhatToSearch ();
2014-12-01 23:55:08 +01:00
/***** Get search string *****/
2017-03-12 21:15:32 +01:00
Sch_GetParamSearch ();
2014-12-01 23:55:08 +01:00
/***** Save my search in order to show it in current session *****/
if (Gbl.Usrs.Me.Logged)
Sch_SaveLastSearchIntoSession ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_SysSearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActSysSch,Sco_SCOPE_SYS);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqSysSearch ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_CtySearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCtySch,Sco_SCOPE_CTY);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqCtySearch ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_InsSearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActInsSch,Sco_SCOPE_INS);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqInsSearch ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_CtrSearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCtrSch,Sco_SCOPE_CTR);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqCtrSearch ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_DegSearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActDegSch,Sco_SCOPE_DEG);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqDegSearch ();
}
/*****************************************************************************/
/****************** Search courses, teachers, documents... *******************/
/*****************************************************************************/
void Sch_CrsSearch (void)
{
if (Gbl.Search.Str[0])
{
/***** Show search form again *****/
2015-02-01 20:17:24 +01:00
Sch_PutFormToSearchWithWhatToSearchAndScope (ActCrsSch,Sco_SCOPE_CRS);
2014-12-01 23:55:08 +01:00
/***** Show results of search *****/
Sch_SearchInDB ();
}
else
/***** Show search form and selectors *****/
Sch_ReqCrsSearch ();
}
/*****************************************************************************/
/**** Search institutions, centres, degrees, courses, teachers, documents ****/
/*****************************************************************************/
static void Sch_SearchInDB (void)
{
extern const char *Txt_No_results;
char RangeQuery[256];
unsigned NumResults = 0; // Initialized to avoid warning
2017-02-27 01:41:46 +01:00
Gbl.Search.LogSearch = true;
2014-12-01 23:55:08 +01:00
/***** Select courses in all the degrees or in current degree *****/
switch (Gbl.Scope.Current)
{
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_UNK:
2014-12-01 23:55:08 +01:00
// Not aplicable
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_SYS:
2014-12-01 23:55:08 +01:00
RangeQuery[0] = '\0';
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTY:
2017-03-24 01:09:27 +01:00
sprintf (RangeQuery," AND countries.CtyCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCty.Cty.CtyCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_INS:
2017-03-24 01:09:27 +01:00
sprintf (RangeQuery," AND institutions.InsCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentIns.Ins.InsCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CTR:
2017-03-24 01:09:27 +01:00
sprintf (RangeQuery," AND centres.CtrCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_DEG:
2017-03-24 01:09:27 +01:00
sprintf (RangeQuery," AND degrees.DegCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentDeg.Deg.DegCod);
break;
2015-02-01 20:17:24 +01:00
case Sco_SCOPE_CRS:
2017-03-24 01:09:27 +01:00
sprintf (RangeQuery," AND courses.CrsCod=%ld",
2014-12-01 23:55:08 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
break;
}
2017-01-29 12:42:19 +01:00
if (Gbl.Search.WhatToSearch == Sch_SEARCH_UNKNOWN)
Gbl.Search.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
2014-12-01 23:55:08 +01:00
switch (Gbl.Search.WhatToSearch)
{
case Sch_SEARCH_ALL:
2017-02-28 00:59:01 +01:00
NumResults = Sch_SearchCountriesInDB (RangeQuery);
NumResults += Sch_SearchInstitutionsInDB (RangeQuery);
2014-12-01 23:55:08 +01:00
NumResults += Sch_SearchCentresInDB (RangeQuery);
NumResults += Sch_SearchDegreesInDB (RangeQuery);
NumResults += Sch_SearchCoursesInDB (RangeQuery);
2015-04-07 21:44:24 +02:00
NumResults += Sch_SearchUsrsInDB (Rol_TEACHER);
NumResults += Sch_SearchUsrsInDB (Rol_STUDENT);
NumResults += Sch_SearchUsrsInDB (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
NumResults += Sch_SearchOpenDocumentsInDB (RangeQuery);
NumResults += Sch_SearchDocumentsInMyCoursesInDB (RangeQuery);
NumResults += Sch_SearchMyDocumentsInDB (RangeQuery);
break;
2017-02-28 00:59:01 +01:00
case Sch_SEARCH_COUNTRIES:
NumResults = Sch_SearchCountriesInDB (RangeQuery);
break;
2016-10-28 10:03:37 +02:00
case Sch_SEARCH_INSTITS:
2014-12-01 23:55:08 +01:00
NumResults = Sch_SearchInstitutionsInDB (RangeQuery);
break;
case Sch_SEARCH_CENTRES:
NumResults = Sch_SearchCentresInDB (RangeQuery);
break;
case Sch_SEARCH_DEGREES:
NumResults = Sch_SearchDegreesInDB (RangeQuery);
break;
case Sch_SEARCH_COURSES:
NumResults = Sch_SearchCoursesInDB (RangeQuery);
break;
2016-06-27 12:35:15 +02:00
case Sch_SEARCH_USERS:
NumResults = Sch_SearchUsrsInDB (Rol_UNKNOWN); // Here Rol_UNKNOWN means any user
break;
2014-12-01 23:55:08 +01:00
case Sch_SEARCH_TEACHERS:
2015-04-07 21:44:24 +02:00
NumResults = Sch_SearchUsrsInDB (Rol_TEACHER);
2014-12-01 23:55:08 +01:00
break;
case Sch_SEARCH_STUDENTS:
2015-04-07 21:44:24 +02:00
NumResults = Sch_SearchUsrsInDB (Rol_STUDENT);
2014-12-01 23:55:08 +01:00
break;
case Sch_SEARCH_GUESTS:
2015-04-07 21:44:24 +02:00
NumResults = Sch_SearchUsrsInDB (Rol__GUEST_);
2014-12-01 23:55:08 +01:00
break;
case Sch_SEARCH_OPEN_DOCUMENTS:
NumResults = Sch_SearchOpenDocumentsInDB (RangeQuery);
break;
2015-01-26 12:39:48 +01:00
case Sch_SEARCH_DOCUM_IN_MY_COURSES:
2014-12-01 23:55:08 +01:00
NumResults = Sch_SearchDocumentsInMyCoursesInDB (RangeQuery);
break;
case Sch_SEARCH_MY_DOCUMENTS:
NumResults = Sch_SearchMyDocumentsInDB (RangeQuery);
break;
2017-01-29 12:42:19 +01:00
default:
NumResults = 0;
break;
2014-12-01 23:55:08 +01:00
}
if (NumResults == 0)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_No_results);
2014-12-01 23:55:08 +01:00
}
2017-02-28 00:59:01 +01:00
/*****************************************************************************/
/************************ Search countries in database ***********************/
/*****************************************************************************/
// Returns number of countries found
static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
{
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[1024 + Sch_MAX_BYTES_SEARCH_QUERY * 2];
2017-02-28 00:59:01 +01:00
char FieldName[4+1+2+1]; // Example: Name_en
/***** Check scope *****/
if (Gbl.Scope.Current != Sco_SCOPE_INS &&
Gbl.Scope.Current != Sco_SCOPE_CTR &&
Gbl.Scope.Current != Sco_SCOPE_DEG &&
Gbl.Scope.Current != Sco_SCOPE_CRS)
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COUNTRIES))
{
/***** Split countries string into words *****/
sprintf (FieldName,"Name_%s",Txt_STR_LANG_ID[Gbl.Prefs.Language]);
if (Sch_BuildSearchQuery (SearchQuery,FieldName,NULL,NULL))
{
/***** Query database and list institutions found *****/
sprintf (Query,"SELECT CtyCod"
" FROM countries"
" WHERE %s%s"
" ORDER BY Name_%s",
SearchQuery,RangeQuery,
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
return Cty_ListCtysFound (Query);
}
}
return 0;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Search institutions in database **********************/
/*****************************************************************************/
// Returns number of institutions found
static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
{
2017-01-28 15:58:46 +01:00
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[1024 + Sch_MAX_BYTES_SEARCH_QUERY * 2];
2014-12-01 23:55:08 +01:00
/***** Check scope *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current != Sco_SCOPE_CTR &&
Gbl.Scope.Current != Sco_SCOPE_DEG &&
Gbl.Scope.Current != Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
2016-10-28 10:03:37 +02:00
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_INSTITS))
2014-12-01 23:55:08 +01:00
/***** Split institutions string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"institutions.FullName",NULL,NULL))
{
/***** Query database and list institutions found *****/
sprintf (Query,"SELECT institutions.InsCod"
" FROM institutions,countries"
" WHERE %s"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" ORDER BY institutions.FullName,countries.Name_%s",
SearchQuery,RangeQuery,
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
return Ins_ListInssFound (Query);
}
return 0;
}
/*****************************************************************************/
/************************* Search centres in database ************************/
/*****************************************************************************/
// Returns number of centres found
static unsigned Sch_SearchCentresInDB (const char *RangeQuery)
{
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[1024 + Sch_MAX_BYTES_SEARCH_QUERY * 2];
2014-12-01 23:55:08 +01:00
/***** Check scope *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current != Sco_SCOPE_DEG &&
Gbl.Scope.Current != Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_CENTRES))
/***** Split centre string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"centres.FullName",NULL,NULL))
{
/***** Query database and list centres found *****/
sprintf (Query,"SELECT centres.CtrCod"
" FROM centres,institutions,countries"
" WHERE %s"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" ORDER BY centres.FullName,institutions.FullName",
SearchQuery,RangeQuery);
return Ctr_ListCtrsFound (Query);
}
return 0;
}
/*****************************************************************************/
/************************* Search degrees in database ************************/
/*****************************************************************************/
// Returns number of degrees found
static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
{
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[1024 + Sch_MAX_BYTES_SEARCH_QUERY * 2];
2014-12-01 23:55:08 +01:00
/***** Check scope *****/
2015-02-01 20:17:24 +01:00
if (Gbl.Scope.Current != Sco_SCOPE_CRS)
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DEGREES))
/***** Split degree string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"degrees.FullName",NULL,NULL))
{
/***** Query database and list degrees found *****/
sprintf (Query,"SELECT degrees.DegCod"
" FROM degrees,centres,institutions,countries"
" WHERE %s"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" ORDER BY degrees.FullName,institutions.FullName",
SearchQuery,RangeQuery);
return Deg_ListDegsFound (Query);
}
return 0;
}
/*****************************************************************************/
/************************* Search courses in database ************************/
/*****************************************************************************/
// Returns number of courses found
static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
{
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[1024 + Sch_MAX_BYTES_SEARCH_QUERY * 2];
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COURSES))
/***** Split course string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"courses.FullName",NULL,NULL))
{
/***** Query database and list courses found *****/
2015-01-17 19:31:21 +01:00
sprintf (Query,"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
2015-12-06 01:02:47 +01:00
"courses.Year,courses.FullName,centres.ShortName"
2014-12-01 23:55:08 +01:00
" FROM courses,degrees,centres,institutions,countries"
" WHERE %s"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
2015-12-06 01:02:47 +01:00
" ORDER BY courses.FullName,institutions.FullName,degrees.FullName,courses.Year",
2014-12-01 23:55:08 +01:00
SearchQuery,RangeQuery);
return Crs_ListCrssFound (Query);
}
return 0;
}
/*****************************************************************************/
2016-06-29 18:27:49 +02:00
/*************************** Search users in database ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-06-29 18:27:49 +02:00
// Returns number of users found
2014-12-01 23:55:08 +01:00
static unsigned Sch_SearchUsrsInDB (Rol_Role_t Role)
{
2016-06-29 18:27:49 +02:00
extern const char *Txt_The_search_text_must_be_longer;
static bool WarningMessageWritten = false;
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
2014-12-01 23:55:08 +01:00
2016-06-29 18:27:49 +02:00
/***** Split user string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,
"CONCAT_WS(' ',FirstName,Surname1,Surname2)",
NULL,NULL))
/***** Query database and list users found *****/
return Usr_ListUsrsFound (Role,SearchQuery);
else
// Too short
if (!WarningMessageWritten) // To avoid repetitions
{
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_search_text_must_be_longer);
2016-06-29 18:27:49 +02:00
WarningMessageWritten = true;
}
2014-12-01 23:55:08 +01:00
return 0;
}
/*****************************************************************************/
/********************** Search open documents in database ********************/
/*****************************************************************************/
// Returns number of documents found
static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
{
2016-04-18 09:46:16 +02:00
extern const char *Txt_open_document;
extern const char *Txt_open_documents;
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[(512 + Sch_MAX_BYTES_SEARCH_QUERY) * 4];
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_OPEN_DOCUMENTS))
/***** Split document string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
"_latin1 "," COLLATE latin1_general_ci"))
{
/***** Build the query *****/
2015-01-26 01:58:40 +01:00
sprintf (Query,"SELECT * FROM "
"("
"SELECT files.FilCod," // Institution
2014-12-01 23:55:08 +01:00
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS CtrCod,'' AS CtrShortName,"
"-1 AS DegCod,'' AS DegShortName,"
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2015-07-13 12:34:26 +02:00
" FROM files,courses,degrees,centres,institutions,countries"
2015-01-26 01:58:40 +01:00
" WHERE files.Public='Y' AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Centre
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS DegCod,'' AS DegShortName,"
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2015-07-13 12:34:26 +02:00
" FROM files,courses,degrees,centres,institutions,countries"
2015-01-26 01:58:40 +01:00
" WHERE files.Public='Y' AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Degree
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
"degrees.DegCod,degrees.ShortName AS DegShortName,"
2017-03-24 01:09:27 +01:00
"-1,'' AS CrsShortName,"
"-1"
2015-07-13 12:34:26 +02:00
" FROM files,courses,degrees,centres,institutions,countries"
2015-01-26 01:58:40 +01:00
" WHERE files.Public='Y' AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Course
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
"degrees.DegCod,degrees.ShortName AS DegShortName,"
"courses.CrsCod,courses.ShortName AS CrsShortName,"
2017-03-24 01:09:27 +01:00
"-1"
2014-12-01 23:55:08 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
" WHERE files.Public='Y' AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u)"
2015-01-25 18:50:43 +01:00
" AND files.Cod=courses.CrsCod"
2014-12-01 23:55:08 +01:00
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
2015-01-26 01:58:40 +01:00
") AS selected_files"
" WHERE PathFromRoot<>''"
" ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_INS,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_INS,
2015-01-26 01:58:40 +01:00
RangeQuery,
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CTR,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_CTR,
2015-01-26 01:58:40 +01:00
RangeQuery,
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_DEG,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_DEG,
2015-01-26 01:58:40 +01:00
RangeQuery,
2014-12-01 23:55:08 +01:00
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CRS,
(unsigned) Brw_ADMI_SHARE_CRS,
2014-12-01 23:55:08 +01:00
RangeQuery);
/***** Query database and list documents found *****/
2015-02-01 20:17:24 +01:00
/* if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_INFO,Query); */
2016-04-18 09:46:16 +02:00
return Brw_ListDocsFound (Query,
Txt_open_document,
Txt_open_documents);
2014-12-01 23:55:08 +01:00
}
return 0;
}
/*****************************************************************************/
/**************** Search documents in my courses in database *****************/
/*****************************************************************************/
static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
{
2016-04-18 09:46:16 +02:00
extern const char *Txt_document_in_my_courses;
extern const char *Txt_documents_in_my_courses;
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[(1024 + Sch_MAX_BYTES_SEARCH_QUERY) * 2];
2014-12-01 23:55:08 +01:00
unsigned NumDocs;
/***** Check user's permission *****/
2015-01-26 12:39:48 +01:00
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DOCUM_IN_MY_COURSES))
2014-12-01 23:55:08 +01:00
/***** Split document string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
"_latin1 "," COLLATE latin1_general_ci"))
{
/***** Create temporary table with codes of files in documents and shared areas accessible by me.
It is necessary to speed up the second query *****/
2016-01-01 20:19:43 +01:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary table");
2016-04-22 09:47:25 +02:00
sprintf (Query,"CREATE TEMPORARY TABLE my_files_crs"
" (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
2014-12-01 23:55:08 +01:00
" SELECT files.FilCod FROM crs_usr,files"
2017-03-24 01:09:27 +01:00
" WHERE crs_usr.UsrCod=%ld"
2015-01-25 18:50:43 +01:00
" AND crs_usr.CrsCod=files.Cod"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u,%u,%u)",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CRS,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_CRS,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_CRS,
(unsigned) Brw_ADMI_MARKS_CRS);
2015-01-26 01:58:40 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
2016-01-01 20:19:43 +01:00
2016-04-22 09:47:25 +02:00
sprintf (Query,"CREATE TEMPORARY TABLE my_files_grp"
" (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
2015-01-26 01:58:40 +01:00
" SELECT files.FilCod FROM crs_grp_usr,files"
2017-03-24 01:09:27 +01:00
" WHERE crs_grp_usr.UsrCod=%ld"
2015-01-26 01:58:40 +01:00
" AND crs_grp_usr.GrpCod=files.Cod"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u,%u,%u)",
2014-12-01 23:55:08 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_GRP,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_GRP,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_GRP,
(unsigned) Brw_ADMI_MARKS_GRP);
2015-02-01 20:17:24 +01:00
/* if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_INFO,Query); */
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
/***** Build the query *****/
2015-01-26 01:58:40 +01:00
sprintf (Query,"SELECT * FROM "
"("
"SELECT files.FilCod,"
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
"degrees.DegCod,degrees.ShortName AS DegShortName,"
"courses.CrsCod,courses.ShortName AS CrsShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS GrpCod"
2015-01-26 01:58:40 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
" WHERE files.FilCod IN (SELECT FilCod FROM my_files_crs) AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u,%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod,"
2014-12-01 23:55:08 +01:00
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
"degrees.DegCod,degrees.ShortName AS DegShortName,"
"courses.CrsCod,courses.ShortName AS CrsShortName,"
"crs_grp.GrpCod"
2015-01-25 18:50:43 +01:00
" FROM files,crs_grp,crs_grp_types,courses,degrees,centres,institutions,countries"
2015-01-26 01:58:40 +01:00
" WHERE files.FilCod IN (SELECT FilCod FROM my_files_grp) AND %s"
2017-03-24 01:09:27 +01:00
" AND files.FileBrowser IN (%u,%u,%u,%u)"
2015-01-25 18:50:43 +01:00
" AND files.Cod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
2015-01-26 01:58:40 +01:00
" AND crs_grp_types.CrsCod=courses.CrsCod"
2014-12-01 23:55:08 +01:00
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
2015-01-26 01:58:40 +01:00
") AS selected_files"
" WHERE PathFromRoot<>''"
" ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
2014-12-01 23:55:08 +01:00
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CRS,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_CRS,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_CRS,
(unsigned) Brw_ADMI_MARKS_CRS,
2015-01-26 01:58:40 +01:00
RangeQuery,
SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_GRP,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_GRP,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_GRP,
(unsigned) Brw_ADMI_MARKS_GRP,
2014-12-01 23:55:08 +01:00
RangeQuery);
/***** Query database and list documents found *****/
2015-02-01 20:17:24 +01:00
/* if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_INFO,Query); */
2016-04-18 09:46:16 +02:00
NumDocs = Brw_ListDocsFound (Query,
Txt_document_in_my_courses,
Txt_documents_in_my_courses);
2014-12-01 23:55:08 +01:00
/***** Drop temporary table *****/
2015-01-26 01:58:40 +01:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp");
2014-12-01 23:55:08 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary table");
return NumDocs;
}
return 0;
}
/*****************************************************************************/
/********************** Search my documents in database **********************/
/*****************************************************************************/
static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
{
2016-04-18 09:46:16 +02:00
extern const char *Txt_document_from_me;
extern const char *Txt_documents_from_me;
2017-03-07 11:03:05 +01:00
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char Query[(512 + Sch_MAX_BYTES_SEARCH_QUERY) * 5];
2014-12-01 23:55:08 +01:00
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_MY_DOCUMENTS))
/***** Split document string into words *****/
if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)",
"_latin1 "," COLLATE latin1_general_ci"))
{
/***** Build the query *****/
2015-01-25 23:40:07 +01:00
sprintf (Query,"SELECT * FROM "
"("
"SELECT files.FilCod," // Institution
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS CtrCod,'' AS CtrShortName,"
"-1 AS DegCod,'' AS DegShortName,"
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2016-02-17 01:40:28 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser IN (%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=institutions.InsCod"
2015-01-25 23:40:07 +01:00
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Centre
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS DegCod,'' AS DegShortName,"
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2016-02-17 01:40:28 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser IN (%u,%u)"
2015-01-26 01:58:40 +01:00
" AND files.Cod=centres.CtrCod"
2015-01-25 23:40:07 +01:00
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Degree
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
2015-01-25 23:40:07 +01:00
"degrees.DegCod,degrees.ShortName AS DegShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2016-02-17 01:40:28 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser IN (%u,%u)"
2015-01-25 23:40:07 +01:00
" AND files.Cod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Course
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
2015-01-25 23:40:07 +01:00
"degrees.DegCod,degrees.ShortName AS DegShortName,"
2015-01-26 01:58:40 +01:00
"courses.CrsCod,courses.ShortName AS CrsShortName,"
2017-03-24 01:09:27 +01:00
"-1 AS GrpCod"
2015-01-25 23:40:07 +01:00
" FROM files,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser IN (%u,%u,%u,%u)"
2015-01-25 23:40:07 +01:00
" AND files.Cod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Group
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2015-01-26 01:58:40 +01:00
"institutions.InsCod,institutions.ShortName AS InsShortName,"
"centres.CtrCod,centres.ShortName AS CtrShortName,"
2015-01-25 23:40:07 +01:00
"degrees.DegCod,degrees.ShortName AS DegShortName,"
2015-01-26 01:58:40 +01:00
"courses.CrsCod,courses.ShortName AS CrsShortName,"
"crs_grp.GrpCod"
2015-01-25 23:40:07 +01:00
" FROM files,crs_grp,crs_grp_types,courses,degrees,centres,institutions,countries"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser IN (%u,%u,%u,%u)"
2015-01-25 23:40:07 +01:00
" AND files.Cod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" AND crs_grp_types.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" UNION "
"SELECT files.FilCod," // Briefcase
"SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot,"
2017-03-24 01:09:27 +01:00
"-1 AS InsCod,'' AS InsShortName,"
"-1 AS CtrCod,'' AS CtrShortName,"
"-1 AS DegCod,'' AS DegShortName,"
"-1 AS CrsCod,'' AS CrsShortName,"
"-1 AS GrpCod"
2015-01-25 23:40:07 +01:00
" FROM files"
2017-03-24 01:09:27 +01:00
" WHERE files.PublisherUsrCod=%ld AND %s"
" AND files.FileBrowser=%u"
2015-01-26 01:58:40 +01:00
") AS selected_files"
2015-01-25 23:40:07 +01:00
" WHERE PathFromRoot<>''"
2015-01-26 01:58:40 +01:00
" ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot",
2015-01-25 23:40:07 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_INS,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_INS,
2015-01-25 23:40:07 +01:00
RangeQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CTR,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_CTR,
2015-01-25 23:40:07 +01:00
RangeQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_DEG,
2015-02-05 22:59:48 +01:00
(unsigned) Brw_ADMI_SHARE_DEG,
2015-01-25 23:40:07 +01:00
RangeQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_CRS,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_CRS,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_CRS,
(unsigned) Brw_ADMI_MARKS_CRS,
2015-01-25 23:40:07 +01:00
RangeQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_DOCUM_GRP,
2016-04-22 09:47:25 +02:00
(unsigned) Brw_ADMI_TEACH_GRP,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_SHARE_GRP,
(unsigned) Brw_ADMI_MARKS_GRP,
2015-01-25 23:40:07 +01:00
RangeQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,SearchQuery,
2015-01-26 12:39:48 +01:00
(unsigned) Brw_ADMI_BRIEF_USR);
2014-12-01 23:55:08 +01:00
/***** Query database and list documents found *****/
2015-02-01 20:17:24 +01:00
/* if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_INFO,Query); */
2016-04-18 09:46:16 +02:00
return Brw_ListDocsFound (Query,
Txt_document_from_me,
Txt_documents_from_me);
2014-12-01 23:55:08 +01:00
}
return 0;
}
/*****************************************************************************/
/****** Build a search query by splitting a string to search into words ******/
/*****************************************************************************/
2016-06-23 19:02:57 +02:00
// Returns true if a valid search query is built
2014-12-01 23:55:08 +01:00
// Returns false when no valid search query
2017-03-07 11:03:05 +01:00
bool Sch_BuildSearchQuery (char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1],
2017-01-16 01:51:01 +01:00
const char *FieldName,
2016-06-29 18:27:49 +02:00
const char *CharSet,const char *Collate)
2014-12-01 23:55:08 +01:00
{
const char *Ptr;
unsigned NumWords;
2016-06-27 18:51:09 +02:00
unsigned NumWord;
2014-12-01 23:55:08 +01:00
size_t LengthWord;
2016-06-27 18:51:09 +02:00
size_t LengthTotal = 0;
2014-12-01 23:55:08 +01:00
size_t MaxLengthWord = 0;
2017-03-07 11:03:05 +01:00
char SearchWords[Sch_MAX_WORDS_IN_SEARCH][Sch_MAX_BYTES_SEARCH_WORD + 1];
2014-12-01 23:55:08 +01:00
bool SearchWordIsValid = true;
2016-06-29 18:27:49 +02:00
if (Gbl.Search.Str[0])
2014-12-01 23:55:08 +01:00
{
2016-06-29 18:27:49 +02:00
SearchQuery[0] = '\0';
Ptr = Gbl.Search.Str;
for (NumWords = 0;
NumWords < Sch_MAX_WORDS_IN_SEARCH && *Ptr;
NumWords++)
{
/* Get next word */
2017-03-07 11:03:05 +01:00
Str_GetNextStringUntilSpace (&Ptr,SearchWords[NumWords],Sch_MAX_BYTES_SEARCH_WORD);
2016-06-29 18:27:49 +02:00
/* Is this word valid? */
switch (Gbl.Search.WhatToSearch)
{
case Sch_SEARCH_OPEN_DOCUMENTS:
case Sch_SEARCH_DOCUM_IN_MY_COURSES:
case Sch_SEARCH_MY_DOCUMENTS:
SearchWordIsValid = Str_ConvertFilFolLnkNameToValid (SearchWords[NumWords]);
break;
default:
SearchWordIsValid = true;
break;
}
2014-12-01 23:55:08 +01:00
2016-06-29 18:27:49 +02:00
/* Check if this word is repeated (case insensitive) */
for (NumWord = 0;
SearchWordIsValid && NumWord < NumWords;
NumWord++)
if (!strcasecmp (SearchWords[NumWord],SearchWords[NumWords]))
SearchWordIsValid = false;
2016-06-27 18:51:09 +02:00
2016-06-29 18:27:49 +02:00
/* Concatenate word to search string */
if (SearchWordIsValid)
{
LengthWord = strlen (SearchWords[NumWords]);
LengthTotal += LengthWord;
if (LengthWord > MaxLengthWord)
MaxLengthWord = LengthWord;
2017-03-12 21:15:32 +01:00
if (strlen (SearchQuery) + 128 + LengthWord >
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY) // Prevent string overflow
2016-06-29 18:27:49 +02:00
break;
if (NumWords)
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery," AND ",
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,FieldName,
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery," LIKE ",
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2016-06-29 18:27:49 +02:00
if (CharSet)
if (CharSet[0])
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,CharSet,
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,"'%",
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,SearchWords[NumWords],
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,"%'",
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2016-06-29 18:27:49 +02:00
if (Collate)
if (Collate[0])
2017-01-17 03:33:05 +01:00
Str_Concat (SearchQuery,Collate,
2017-03-07 11:03:05 +01:00
Sch_MAX_BYTES_SEARCH_QUERY);
2016-06-29 18:27:49 +02:00
}
2014-12-01 23:55:08 +01:00
}
2016-06-29 18:27:49 +02:00
/***** If search string valid? *****/
if (LengthTotal < Sch_MIN_LENGTH_TOTAL ||
MaxLengthWord < Sch_MIN_LENGTH_LONGEST_WORD)
return false;
2016-06-27 18:51:09 +02:00
return true;
2016-06-29 18:27:49 +02:00
}
return false;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Save last search into session ************************/
/*****************************************************************************/
static void Sch_SaveLastSearchIntoSession (void)
{
2017-03-12 21:15:32 +01:00
char Query[256 +
Sch_MAX_BYTES_STRING_TO_FIND +
2017-03-13 14:22:36 +01:00
Ses_BYTES_SESSION_ID];
2014-12-01 23:55:08 +01:00
if (Gbl.Usrs.Me.Logged)
{
2017-01-29 12:42:19 +01:00
if (Gbl.Search.WhatToSearch == Sch_SEARCH_UNKNOWN)
Gbl.Search.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
2014-12-01 23:55:08 +01:00
/***** Save last search in session *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE sessions SET WhatToSearch=%u,SearchStr='%s'"
2014-12-01 23:55:08 +01:00
" WHERE SessionId='%s'",
(unsigned) Gbl.Search.WhatToSearch,
Gbl.Search.Str,
Gbl.Session.Id);
DB_QueryUPDATE (Query,"can not update last search in session");
/***** Update my last type of search *****/
// WhatToSearch is stored in usr_last for next time I log in
// In other existing sessions distinct to this, WhatToSearch will remain unchanged
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE usr_last SET WhatToSearch=%u WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
(unsigned) Gbl.Search.WhatToSearch,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update type of search in user's last data");
}
}