-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathswad_browser_database.c
3777 lines (3554 loc) · 138 KB
/
swad_browser_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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// swad_browser_database.c: file browsers 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 <mysql/mysql.h> // To access MySQL databases
#include <string.h> // For string functions
#include "swad_browser.h"
#include "swad_browser_database.h"
#include "swad_database.h"
#include "swad_error.h"
#include "swad_global.h"
#include "swad_project.h"
/*****************************************************************************/
/******************** Global variables from other modules ********************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
// Browsers types for database "files" and "brw_sizes" tables
const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER] =
{
[Brw_UNKNOWN ] = Brw_UNKNOWN,
[Brw_SHOW_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_SHOW_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_ADMI_SHR_CRS] = Brw_ADMI_SHR_CRS,
[Brw_ADMI_SHR_GRP] = Brw_ADMI_SHR_GRP,
[Brw_ADMI_WRK_USR] = Brw_ADMI_WRK_USR,
[Brw_ADMI_WRK_CRS] = Brw_ADMI_WRK_USR,
[Brw_ADMI_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_BRF_USR] = Brw_ADMI_BRF_USR,
[Brw_SHOW_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_ADMI_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_SHOW_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_ASG_USR] = Brw_ADMI_ASG_USR,
[Brw_ADMI_ASG_CRS] = Brw_ADMI_ASG_USR,
[Brw_SHOW_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_ADMI_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_SHOW_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_ADMI_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_SHOW_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_SHR_DEG] = Brw_ADMI_SHR_DEG,
[Brw_ADMI_SHR_CTR] = Brw_ADMI_SHR_CTR,
[Brw_ADMI_SHR_INS] = Brw_ADMI_SHR_INS,
[Brw_ADMI_TCH_CRS] = Brw_ADMI_TCH_CRS,
[Brw_ADMI_TCH_GRP] = Brw_ADMI_TCH_GRP,
[Brw_ADMI_DOC_PRJ] = Brw_ADMI_DOC_PRJ,
[Brw_ADMI_ASS_PRJ] = Brw_ADMI_ASS_PRJ,
};
// Browsers types for database "brw_last" table
// Assignments and works are stored as one in brw_last...
// ...because a user views them at the same time
static Brw_FileBrowser_t Brw_DB_FileBrowserForDB_file_browser_last[Brw_NUM_TYPES_FILE_BROWSER] =
{
[Brw_UNKNOWN ] = Brw_UNKNOWN,
[Brw_SHOW_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_SHOW_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_ADMI_SHR_CRS] = Brw_ADMI_SHR_CRS,
[Brw_ADMI_SHR_GRP] = Brw_ADMI_SHR_GRP,
[Brw_ADMI_WRK_USR] = Brw_ADMI_ASG_USR,
[Brw_ADMI_WRK_CRS] = Brw_ADMI_ASG_CRS,
[Brw_ADMI_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_BRF_USR] = Brw_ADMI_BRF_USR,
[Brw_SHOW_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_ADMI_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_SHOW_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_ASG_USR] = Brw_ADMI_ASG_USR,
[Brw_ADMI_ASG_CRS] = Brw_ADMI_ASG_CRS,
[Brw_SHOW_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_ADMI_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_SHOW_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_ADMI_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_SHOW_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_SHR_DEG] = Brw_ADMI_SHR_DEG,
[Brw_ADMI_SHR_CTR] = Brw_ADMI_SHR_CTR,
[Brw_ADMI_SHR_INS] = Brw_ADMI_SHR_INS,
[Brw_ADMI_TCH_CRS] = Brw_ADMI_TCH_CRS,
[Brw_ADMI_TCH_GRP] = Brw_ADMI_TCH_GRP,
[Brw_ADMI_DOC_PRJ] = Brw_ADMI_DOC_PRJ,
[Brw_ADMI_ASS_PRJ] = Brw_ADMI_ASS_PRJ,
};
// Browsers types for database "expanded_folders" table
static Brw_FileBrowser_t Brw_DB_FileBrowserForDB_expanded_folders[Brw_NUM_TYPES_FILE_BROWSER] =
{
[Brw_UNKNOWN ] = Brw_UNKNOWN,
[Brw_SHOW_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_SHOW_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_DOC_CRS] = Brw_ADMI_DOC_CRS,
[Brw_ADMI_SHR_CRS] = Brw_ADMI_SHR_CRS,
[Brw_ADMI_SHR_GRP] = Brw_ADMI_SHR_GRP,
[Brw_ADMI_WRK_USR] = Brw_ADMI_WRK_USR,
[Brw_ADMI_WRK_CRS] = Brw_ADMI_WRK_CRS,
[Brw_ADMI_MRK_CRS] = Brw_ADMI_MRK_CRS,
[Brw_ADMI_BRF_USR] = Brw_ADMI_BRF_USR,
[Brw_SHOW_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_ADMI_DOC_GRP] = Brw_ADMI_DOC_GRP,
[Brw_SHOW_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_MRK_GRP] = Brw_ADMI_MRK_GRP,
[Brw_ADMI_ASG_USR] = Brw_ADMI_ASG_USR,
[Brw_ADMI_ASG_CRS] = Brw_ADMI_ASG_CRS,
[Brw_SHOW_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_ADMI_DOC_DEG] = Brw_ADMI_DOC_DEG,
[Brw_SHOW_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_ADMI_DOC_CTR] = Brw_ADMI_DOC_CTR,
[Brw_SHOW_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_DOC_INS] = Brw_ADMI_DOC_INS,
[Brw_ADMI_SHR_DEG] = Brw_ADMI_SHR_DEG,
[Brw_ADMI_SHR_CTR] = Brw_ADMI_SHR_CTR,
[Brw_ADMI_SHR_INS] = Brw_ADMI_SHR_INS,
[Brw_ADMI_TCH_CRS] = Brw_ADMI_TCH_CRS,
[Brw_ADMI_TCH_GRP] = Brw_ADMI_TCH_GRP,
[Brw_ADMI_DOC_PRJ] = Brw_ADMI_DOC_PRJ,
[Brw_ADMI_ASS_PRJ] = Brw_ADMI_ASS_PRJ,
};
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
/*****************************************************************************/
/**************** Add a path of file/folder to the database ******************/
/*****************************************************************************/
long Brw_DB_AddPath (long PublisherUsrCod,Brw_FileType_t FileType,
const char *FullPathInTree,bool IsPublic,Brw_License_t License)
{
long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
/***** Add path to the database *****/
return
DB_QueryINSERTandReturnCode ("can not add path to database",
"INSERT INTO brw_files"
" (FileBrowser,Cod,ZoneUsrCod,PublisherUsrCod,"
"FileType,Path,Hidden,Public,License)"
" VALUES"
" (%u,%ld,%ld,%ld,"
"%u,'%s','N','%c',%u)",
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,
ZoneUsrCod,
PublisherUsrCod,
(unsigned) FileType,
FullPathInTree,
IsPublic ? 'Y' :
'N',
(unsigned) License);
}
/*****************************************************************************/
/*************** Rename a file or folder in table of files *******************/
/*****************************************************************************/
void Brw_DB_RenameOneFolder (const char OldPath[PATH_MAX + 1],
const char NewPath[PATH_MAX + 1])
{
/***** Update file or folder in table of common files *****/
DB_QueryUPDATE ("can not update folder name in a common zone",
"UPDATE brw_files"
" SET Path='%s'"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path='%s'",
NewPath,
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Brw_GetCodForFileBrowser (),
Brw_GetZoneUsrCodForFileBrowser (),
OldPath);
}
/*****************************************************************************/
/************** Rename children of a folder in table of files ****************/
/*****************************************************************************/
void Brw_DB_RenameChildrenFilesOrFolders (const char OldPath[PATH_MAX + 1],
const char NewPath[PATH_MAX + 1])
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
unsigned StartFinalSubpathNotChanged = strlen (OldPath) + 2;
/***** Update children of a folder in table of files *****/
DB_QueryUPDATE ("can not rename file or folder names in a common zone",
"UPDATE brw_files"
" SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path LIKE '%s/%%'",
NewPath,StartFinalSubpathNotChanged,
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Brw_GetCodForFileBrowser (),
Brw_GetZoneUsrCodForFileBrowser (),
OldPath);
}
/*****************************************************************************/
/*********************** Get file code using its path ************************/
/*****************************************************************************/
// Path is the full path in tree
// Example: descarga/folder/file.pdf
long Brw_DB_GetFilCodByPath (const char *Path,bool OnlyIfPublic)
{
long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
return DB_QuerySELECTCode ("can not get file code",
"SELECT FilCod"
" FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path='%s'"
"%s"
" ORDER BY FilCod DESC" // Due to errors, there could be old entries for the same path.
" LIMIT 1", // Select the most recent entry.
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,
ZoneUsrCod,
Path,
OnlyIfPublic ? " AND Public='Y'" :
"");
}
/*****************************************************************************/
/********************* Get file metadata using its path **********************/
/*****************************************************************************/
// This function only gets metadata stored in table files,
// does not get size, time, numviews...
unsigned Brw_DB_GetFileMetadataByPath (MYSQL_RES **mysql_res,const char *Path)
{
long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get file metadata",
"SELECT FilCod," // row[0]
"FileBrowser," // row[1]
"Cod," // row[2]
"ZoneUsrCod," // row[3]
"PublisherUsrCod," // row[4]
"FileType," // row[5]
"Path," // row[6]
"Hidden," // row[7]
"Public," // row[8]
"License" // row[9]
" FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path='%s'"
" ORDER BY FilCod DESC" // Due to errors, there could be old entries for the same path.
" LIMIT 1", // Select the most recent entry.
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,
ZoneUsrCod,
Path);
}
/*****************************************************************************/
/********************* Get file metadata using its code **********************/
/*****************************************************************************/
// This function only gets metadata stored in table files,
// does not get size, time, numviews...
unsigned Brw_DB_GetFileMetadataByCod (MYSQL_RES **mysql_res,long FilCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get file metadata",
"SELECT FilCod," // row[0]
"FileBrowser," // row[1]
"Cod," // row[2]
"ZoneUsrCod," // row[3]
"PublisherUsrCod," // row[4]
"FileType," // row[5]
"Path," // row[6]
"Hidden," // row[7]
"Public," // row[8]
"License" // row[9]
" FROM brw_files"
" WHERE FilCod=%ld",
FilCod);
}
/*****************************************************************************/
/************************ Get file path using its code ***********************/
/*****************************************************************************/
void Brw_DB_GetPathByCod (long FilCod,char *Title,size_t TitleSize)
{
DB_QuerySELECTString (Title,TitleSize,"can not get path",
"SELECT Path" // row[0]
" FROM brw_files"
" WHERE FilCod=%ld",
FilCod);
}
/*****************************************************************************/
/************************ Get the publisher of a subtree *********************/
/*****************************************************************************/
long Brw_DB_GetPublisherOfSubtree (const char *Path)
{
/***** Get all common files that are equal to full path (including filename)
or that are under that full path from database *****/
return DB_QuerySELECTCode ("can not get publishers of files",
"SELECT DISTINCT "
"PublisherUsrCod"
" FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND (Path='%s'"
" OR"
" Path LIKE '%s/%%')",
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Brw_GetCodForFileBrowser (),
Path,
Path);
}
/*****************************************************************************/
/************ Get current number of files published by a user ****************/
/*****************************************************************************/
unsigned Brw_DB_GetNumFilesUsr (long UsrCod)
{
return (unsigned)
DB_QueryCOUNT ("can not get number of files from a user",
"SELECT COUNT(*)"
" FROM brw_files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
}
/*****************************************************************************/
/*********** Get the number of files in document zones of a course ***********/
/*****************************************************************************/
unsigned Brw_DB_GetNumFilesInDocumZonesOfCrs (long CrsCod)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
/***** Get number of files in document zones of a course from database *****/
return DB_QuerySELECTUnsigned ("can not get the number of files",
"SELECT"
" (SELECT COALESCE(SUM(NumFiles),0)"
" FROM brw_sizes"
" WHERE FileBrowser=%u AND Cod=%ld) +"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)"
" FROM grp_types,"
"grp_groups,"
"brw_sizes"
" WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND brw_sizes.FileBrowser=%u"
" AND brw_sizes.Cod=grp_groups.GrpCod)",
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_DOC_CRS],
CrsCod,
CrsCod,
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_DOC_GRP]);
}
/*****************************************************************************/
/*********** Get the number of files in shared zones of a course ***********/
/*****************************************************************************/
unsigned Brw_DB_GetNumFilesInShareZonesOfCrs (long CrsCod)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
/***** Get number of files in document zones of a course from database *****/
return DB_QuerySELECTUnsigned ("can not get the number of files",
"SELECT"
" (SELECT COALESCE(SUM(NumFiles),0)"
" FROM brw_sizes"
" WHERE FileBrowser=%u AND Cod=%ld) +"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)"
" FROM grp_types,"
"grp_groups,"
"brw_sizes"
" WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND brw_sizes.FileBrowser=%u"
" AND brw_sizes.Cod=grp_groups.GrpCod)",
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_SHR_CRS],
CrsCod,
CrsCod,
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_SHR_GRP]);
}
/*****************************************************************************/
/********* Get the number of files in assignment zones of a course ***********/
/*****************************************************************************/
unsigned Brw_DB_GetNumFilesInAssigZonesOfCrs (long CrsCod)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
/***** Get number of files in document zones of a course from database *****/
return DB_QuerySELECTUnsigned ("can not get the number of files",
"SELECT COALESCE(SUM(NumFiles),0)"
" FROM brw_sizes"
" WHERE FileBrowser=%u"
" AND Cod=%ld",
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_ASG_USR],
CrsCod);
}
/*****************************************************************************/
/************* Get the number of files in works zones of a course ************/
/*****************************************************************************/
unsigned Brw_DB_GetNumFilesInWorksZonesOfCrs (long CrsCod)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
/***** Get number of files in document zones of a course from database *****/
return DB_QuerySELECTUnsigned ("can not get the number of files",
"SELECT COALESCE(SUM(NumFiles),0)"
" FROM brw_sizes"
" WHERE FileBrowser=%u"
" AND Cod=%ld",
(unsigned) Brw_DB_FileBrowserForDB_files[Brw_ADMI_WRK_USR],
CrsCod);
}
/*****************************************************************************/
/**************** Remove a file or folder from the database ******************/
/*****************************************************************************/
void Brw_DB_RemoveOneFileOrFolder (const char Path[PATH_MAX + 1])
{
long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
Brw_FileBrowser_t FileBrowser = Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type];
/***** Remove from database the entries that store the marks properties *****/
if (FileBrowser == Brw_ADMI_MRK_CRS ||
FileBrowser == Brw_ADMI_MRK_GRP)
DB_QueryDELETE ("can not remove properties of marks from database",
"DELETE FROM mrk_marks"
" USING brw_files,"
"mrk_marks"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=mrk_marks.FilCod",
(unsigned) FileBrowser,
Cod,
Path);
/***** Remove from database the entries that store the file views *****/
DB_QueryDELETE ("can not remove file views from database",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.ZoneUsrCod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) FileBrowser,
Cod,
ZoneUsrCod,
Path);
/***** Remove from database the entry that stores the data of a file *****/
DB_QueryDELETE ("can not remove path from database",
"DELETE FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path='%s'",
(unsigned) FileBrowser,
Cod,
ZoneUsrCod,
Path);
}
/*****************************************************************************/
/************** Remove children of a folder from the database ****************/
/*****************************************************************************/
void Brw_DB_RemoveChildrenOfFolder (const char Path[PATH_MAX + 1])
{
long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
Brw_FileBrowser_t FileBrowser = Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type];
/***** Remove from database the entries that store the marks properties *****/
if (FileBrowser == Brw_ADMI_MRK_CRS ||
FileBrowser == Brw_ADMI_MRK_GRP)
DB_QueryDELETE ("can not remove properties of marks from database",
"DELETE FROM mrk_marks"
" USING brw_files,"
"mrk_marks"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path LIKE '%s/%%'"
" AND brw_files.FilCod=mrk_marks.FilCod",
(unsigned) FileBrowser,
Cod,
Path);
/***** Remove from database the entries that store the file views *****/
DB_QueryDELETE ("can not remove file views from database",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.ZoneUsrCod=%ld"
" AND brw_files.Path LIKE '%s/%%'"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) FileBrowser,
Cod,
ZoneUsrCod,
Path);
/***** Remove from database the entries that store the data of files *****/
DB_QueryDELETE ("can not remove paths from database",
"DELETE FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"
" AND ZoneUsrCod=%ld"
" AND Path LIKE '%s/%%'",
(unsigned) FileBrowser,
Cod,
ZoneUsrCod,
Path);
}
/*****************************************************************************/
/******** Remove files related to an institution from the database ***********/
/*****************************************************************************/
void Brw_DB_RemoveInsFiles (long InsCod)
{
/***** Remove from database the entries that store the file views *****/
DB_QueryDELETE ("can not remove file views to files of an institution",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u)"
" AND brw_files.Cod=%ld"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
/***** Remove from database expanded folders *****/
DB_QueryDELETE ("can not remove expanded folders of an institution",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
/***** Remove from database the entries that store clipboards *****/
DB_QueryDELETE ("can not remove clipboards"
" related to files of an institution",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
/***** Remove from database the entries that store
the last time users visited file zones *****/
DB_QueryDELETE ("can not remove file last visits"
" to files of an institution",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
/***** Remove from database the entries that store
the sizes of the file zones *****/
DB_QueryDELETE ("can not remove sizes of file zones of an institution",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
/***** Remove from database the entries that store the data files *****/
DB_QueryDELETE ("can not remove files of an institution",
"DELETE FROM brw_files"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_INS,
(unsigned) Brw_ADMI_SHR_INS,
InsCod);
}
/*****************************************************************************/
/************ Remove files related to a center from the database *************/
/*****************************************************************************/
void Brw_DB_RemoveCtrFiles (long CtrCod)
{
/***** Remove from database the entries that store the file views *****/
DB_QueryDELETE ("can not remove file views to files of a center",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u)"
" AND brw_files.Cod=%ld"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
/***** Remove from database expanded folders *****/
DB_QueryDELETE ("can not remove expanded folders of a center",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
/***** Remove from database the entries that store clipboards *****/
DB_QueryDELETE ("can not remove clipboards related to files of a center",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
/***** Remove from database the entries that store the last time users visited file zones *****/
DB_QueryDELETE ("can not remove file last visits to files of a center",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
/***** Remove from database the entries that store the sizes of the file zones *****/
DB_QueryDELETE ("can not remove sizes of file zones of a center",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
/***** Remove from database the entries that store the data files *****/
DB_QueryDELETE ("can not remove files of a center",
"DELETE FROM brw_files"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CTR,
(unsigned) Brw_ADMI_SHR_CTR,
CtrCod);
}
/*****************************************************************************/
/************ Remove files related to a degree from the database *************/
/*****************************************************************************/
void Brw_DB_RemoveDegFiles (long DegCod)
{
/***** Remove from database the entries that store the file views *****/
DB_QueryDELETE ("can not remove file views to files of a degree",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u)"
" AND brw_files.Cod=%ld"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
/***** Remove from database expanded folders *****/
DB_QueryDELETE ("can not remove expanded folders of a degree",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
/***** Remove from database the entries that store clipboards *****/
DB_QueryDELETE ("can not remove clipboards related to files of a degree",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
/***** Remove from database the entries that store the last time users visited file zones *****/
DB_QueryDELETE ("can not remove file last visits to files of a degree",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
/***** Remove from database the entries that store the sizes of the file zones *****/
DB_QueryDELETE ("can not remove sizes of file zones of a degree",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
/***** Remove from database the entries that store the data files *****/
DB_QueryDELETE ("can not remove files of a degree",
"DELETE FROM brw_files"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_DEG,
(unsigned) Brw_ADMI_SHR_DEG,
DegCod);
}
/*****************************************************************************/
/************ Remove files related to a course from the database *************/
/*****************************************************************************/
/* Remove information related to files in course,
including groups and projects,
so this function must be called
before removing groups and projects */
void Brw_DB_RemoveCrsFiles (long CrsCod)
{
char SubqueryGrp[256];
char SubqueryPrj[128];
/***** Build subquery for groups *****/
sprintf (SubqueryGrp,"(SELECT grp_groups.GrpCod"
" FROM grp_types,"
"grp_groups"
" WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod)",
CrsCod);
/***** Build subquery for projects *****/
sprintf (SubqueryPrj,"(SELECT PrjCod"
" FROM prj_projects"
" WHERE CrsCod=%ld)",
CrsCod);
/***** Remove format of files of marks *****/
DB_QueryDELETE ("can not remove the properties of marks"
" associated to a course",
"DELETE FROM mrk_marks"
" USING brw_files,"
"mrk_marks"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.FilCod=mrk_marks.FilCod",
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/***** Remove from database the entries that store the file views *****/
/* Remove from course file zones */
DB_QueryDELETE ("can not remove file views to files of a course",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u,%u,%u,%u,%u)"
" AND brw_files.Cod=%ld"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_ASG_USR,
(unsigned) Brw_ADMI_WRK_USR,
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/* Remove from group file zones */
DB_QueryDELETE ("can not remove file views to files of a course",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u,%u,%u)"
" AND brw_files.Cod IN %s"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
SubqueryGrp);
/* Remove from project file zones */
DB_QueryDELETE ("can not remove file views to files of a course",
"DELETE FROM brw_views"
" USING brw_files,"
"brw_views"
" WHERE brw_files.FileBrowser IN (%u,%u)"
" AND brw_files.Cod IN %s"
" AND brw_files.FilCod=brw_views.FilCod",
(unsigned) Brw_ADMI_DOC_PRJ,
(unsigned) Brw_ADMI_ASS_PRJ,
SubqueryPrj);
/***** Remove from database expanded folders *****/
/* Remove from course file zones */
DB_QueryDELETE ("can not remove expanded folders of a course",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u,%u,%u,%u,%u,%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_ASG_USR,
(unsigned) Brw_ADMI_ASG_CRS,
(unsigned) Brw_ADMI_WRK_USR,
(unsigned) Brw_ADMI_WRK_CRS,
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/* Remove from group file zones */
DB_QueryDELETE ("can not remove expanded folders of a course",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
SubqueryGrp);
/* Remove from project file zones */
DB_QueryDELETE ("can not remove expanded folders of a course",
"DELETE LOW_PRIORITY FROM brw_expanded"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_PRJ,
(unsigned) Brw_ADMI_ASS_PRJ,
SubqueryPrj);
/***** Remove from database the entries that store clipboards *****/
/* Remove from course file zones */
DB_QueryDELETE ("can not remove clipboards related to files of a course",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u,%u,%u,%u,%u,%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_ASG_USR,
(unsigned) Brw_ADMI_ASG_CRS,
(unsigned) Brw_ADMI_WRK_USR,
(unsigned) Brw_ADMI_WRK_CRS,
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/* Remove from group file zones */
DB_QueryDELETE ("can not remove clipboards related to files of a course",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
SubqueryGrp);
/* Remove from project file zones */
DB_QueryDELETE ("can not remove clipboards related to files of a course",
"DELETE FROM brw_clipboards"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_PRJ,
(unsigned) Brw_ADMI_ASS_PRJ,
SubqueryPrj);
/***** Remove from database the entries that store the last time users visited file zones *****/
// Assignments and works are stored as one in brw_last...
// ...because a user views them at the same time
/* Remove from course file zones */
DB_QueryDELETE ("can not remove file last visits to files of a course",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u,%u,%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_ASG_USR,
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/* Remove from group file zones */
DB_QueryDELETE ("can not remove file last visits to files of a course",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
SubqueryGrp);
/* Remove from project file zones */
DB_QueryDELETE ("can not remove file last visits to files of a course",
"DELETE FROM brw_last"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_PRJ,
(unsigned) Brw_ADMI_ASS_PRJ,
SubqueryPrj);
/***** Remove from database the entries that store the sizes of the file zones *****/
/* Remove from course file zones */
DB_QueryDELETE ("can not remove sizes of file zones of a course",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u,%u,%u,%u,%u)"
" AND Cod=%ld",
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_ASG_USR,
(unsigned) Brw_ADMI_WRK_USR,
(unsigned) Brw_ADMI_MRK_CRS,
CrsCod);
/* Remove from group file zones */
DB_QueryDELETE ("can not remove sizes of file zones of a course",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
SubqueryGrp);
/* Remove from project file zones */
DB_QueryDELETE ("can not remove sizes of file zones of a course",
"DELETE FROM brw_sizes"
" WHERE FileBrowser IN (%u,%u)"
" AND Cod IN %s",
(unsigned) Brw_ADMI_DOC_PRJ,
(unsigned) Brw_ADMI_ASS_PRJ,
SubqueryPrj);
/***** Remove from database the entries that store the data files *****/
/* Remove from course file zones */
DB_QueryDELETE ("can not remove files of a course",
"DELETE FROM brw_files"