2021-10-13 19:02:22 +02:00
|
|
|
|
// swad_role_database.c: user's roles, operations with database
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-10-13 19:02:22 +02: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 "swad_database.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************* Update the role of a user in the current course ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Rol_DB_UpdateUsrRoleInCrs (long CrsCod,long UsrCod,Rol_Role_t NewRole)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not modify user's role in course",
|
|
|
|
|
"UPDATE crs_users"
|
|
|
|
|
" SET Role=%u"
|
|
|
|
|
" WHERE CrsCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
(unsigned) NewRole,
|
|
|
|
|
CrsCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Get role of a user in a course ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
Rol_Role_t Rol_DB_GetRoleUsrInCrs (long UsrCod,long CrsCod)
|
|
|
|
|
{
|
|
|
|
|
return
|
2021-11-08 17:18:36 +01:00
|
|
|
|
DB_QuerySELECTRole ("can not get user's role",
|
2021-10-13 19:02:22 +02:00
|
|
|
|
"SELECT Role"
|
|
|
|
|
" FROM crs_users"
|
|
|
|
|
" WHERE CrsCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
CrsCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-11-08 17:18:36 +01:00
|
|
|
|
/**************** Get the maximum role of a user in any course ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
Rol_Role_t Rol_DB_GetMaxRoleUsrInCrss (long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
DB_QuerySELECTRole ("can not get user's role",
|
|
|
|
|
"SELECT MAX(Role)"
|
|
|
|
|
" FROM crs_users"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-13 19:02:22 +02:00
|
|
|
|
/*************** Get distinct roles in all courses of a user *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Rol_DB_GetRolesInAllCrss (MYSQL_RES **mysql_res,long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get user's roles in all courses",
|
2021-11-06 12:13:05 +01:00
|
|
|
|
"SELECT DISTINCT Role" // row[0]
|
2021-10-13 19:02:22 +02:00
|
|
|
|
" FROM crs_users"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Get requested role of a user in current course *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
Rol_Role_t Rol_DB_GetRequestedRole (long CrsCod,long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
return DB_QuerySELECTRole ("can not get requested role",
|
|
|
|
|
"SELECT Role"
|
|
|
|
|
" FROM crs_requests"
|
|
|
|
|
" WHERE CrsCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
CrsCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|