-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathswad_bibliography_database.c
173 lines (154 loc) · 6.75 KB
/
swad_bibliography_database.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// swad_bibliography_database.c: bibliographic references, 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.
Copyright (C) 1999-2025 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public 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_bibliography.h"
#include "swad_bibliography_database.h"
#include "swad_database.h"
#include "swad_error.h"
#include "swad_global.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************* Create a new bibliographic reference ********************/
/*****************************************************************************/
long Bib_DB_CreateRef (const struct Tre_Node *Node)
{
return
DB_QueryINSERTandReturnCode ("can not create new bibliographic reference",
"INSERT INTO crs_bibliography"
" (NodCod,ItmInd,Hidden,"
"Authors,Title,Source,Publisher,Date,Id,URL)"
" SELECT %ld,COALESCE(MAX(t2.ItmInd),0)+1,'N',"
"'%s','%s','%s','%s','%s','%s','%s'"
" FROM crs_bibliography AS t2"
" WHERE t2.NodCod=%ld",
Node->Hierarchy.NodCod,
Node->Item.Bib.Fields[Bib_AUTHORS ],
Node->Item.Bib.Fields[Bib_TITLE ],
Node->Item.Bib.Fields[Bib_SOURCE ],
Node->Item.Bib.Fields[Bib_PUBLISHER ],
Node->Item.Bib.Fields[Bib_DATE ],
Node->Item.Bib.Fields[Bib_ID ],
Node->Item.Bib.URL,
Node->Hierarchy.NodCod);
}
/*****************************************************************************/
/******** Get list of node bibliographic references from database ************/
/*****************************************************************************/
unsigned Bib_DB_GetListRefs (MYSQL_RES **mysql_res,long NodCod,
bool ShowHiddenBibRefs)
{
extern const char *Tre_DB_Types[Inf_NUM_TYPES];
static const char *HiddenSubQuery[2] =
{
[false] = " AND crs_bibliography.Hidden='N'",
[true ] = "",
};
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get node bibliographic references",
"SELECT crs_bibliography.NodCod," // row[ 0]
"crs_bibliography.ItmCod," // row[ 1]
"crs_bibliography.ItmInd," // row[ 2]
"crs_bibliography.Hidden," // row[ 3]
"crs_bibliography.Authors," // row[ 4]
"crs_bibliography.Title," // row[ 5]
"crs_bibliography.Source," // row[ 6]
"crs_bibliography.Publisher," // row[ 7]
"crs_bibliography.Date," // row[ 8]
"crs_bibliography.Id," // row[ 9]
"crs_bibliography.URL" // row[10]
" FROM crs_bibliography,"
"tre_nodes"
" WHERE crs_bibliography.NodCod=%ld"
"%s"
" AND crs_bibliography.NodCod=tre_nodes.NodCod"
" AND tre_nodes.CrsCod=%ld" // Extra check
" AND tre_nodes.Type='%s'" // Extra check
" ORDER BY crs_bibliography.ItmInd",
NodCod,
HiddenSubQuery[ShowHiddenBibRefs],
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
Tre_DB_Types[Inf_BIBLIOGRAPHY]);
}
/*****************************************************************************/
/************* Get bibliographic reference data using its code ***************/
/*****************************************************************************/
unsigned Bib_DB_GetRefDataByCod (MYSQL_RES **mysql_res,long ItmCod)
{
extern const char *Tre_DB_Types[Inf_NUM_TYPES];
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get node bibliographic reference data",
"SELECT crs_bibliography.NodCod," // row[ 0]
"crs_bibliography.ItmCod," // row[ 1]
"crs_bibliography.ItmInd," // row[ 2]
"crs_bibliography.Hidden," // row[ 3]
"crs_bibliography.Authors," // row[ 4]
"crs_bibliography.Title," // row[ 5]
"crs_bibliography.Source," // row[ 6]
"crs_bibliography.Publisher," // row[ 7]
"crs_bibliography.Date," // row[ 8]
"crs_bibliography.Id," // row[ 9]
"crs_bibliography.URL" // row[10]
" FROM crs_bibliography,"
"tre_nodes"
" WHERE crs_bibliography.ItmCod=%ld"
" AND crs_bibliography.NodCod=tre_nodes.NodCod"
" AND tre_nodes.CrsCod=%ld" // Extra check
" AND tre_nodes.Type='%s'", // Extra check
ItmCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
Tre_DB_Types[Inf_BIBLIOGRAPHY]);
}
/*****************************************************************************/
/*************** Update bibliographic reference given its code ***************/
/*****************************************************************************/
void Bib_DB_UpdateRef (const struct Tre_Node *Node)
{
extern const char *Tre_DB_Types[Inf_NUM_TYPES];
DB_QueryUPDATE ("can not update bibliographic reference",
"UPDATE crs_bibliography,"
"tre_nodes"
" SET crs_bibliography.Authors='%s',"
"crs_bibliography.Title='%s',"
"crs_bibliography.Source='%s',"
"crs_bibliography.Publisher='%s',"
"crs_bibliography.Date='%s',"
"crs_bibliography.Id='%s',"
"crs_bibliography.URL='%s'"
" WHERE crs_bibliography.ItmCod=%ld"
" AND crs_bibliography.NodCod=%ld"
" AND crs_bibliography.NodCod=tre_nodes.NodCod"
" AND tre_nodes.CrsCod=%ld" // Extra check
" AND tre_nodes.Type='%s'", // Extra check
Node->Item.Bib.Fields[Bib_AUTHORS ],
Node->Item.Bib.Fields[Bib_TITLE ],
Node->Item.Bib.Fields[Bib_SOURCE ],
Node->Item.Bib.Fields[Bib_PUBLISHER ],
Node->Item.Bib.Fields[Bib_DATE ],
Node->Item.Bib.Fields[Bib_ID ],
Node->Item.Bib.URL,
Node->Item.Cod,
Node->Hierarchy.NodCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
Tre_DB_Types[Inf_BIBLIOGRAPHY]);
}