-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify.php
1448 lines (1214 loc) · 76.5 KB
/
modify.php
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
<?php
// Project: Web Reference Database (refbase) <http://www.refbase.net>
// Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
// original author(s).
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY. Please see the GNU General Public
// License for more details.
//
// File: ./modify.php
// Repository: $HeadURL: http://svn.code.sf.net/p/refbase/code/trunk/modify.php $
// Author(s): Matthias Steffens <mailto:refbase@extracts.de>
//
// Created: 18-Dec-02, 23:08
// Modified: $Date: 2013-04-16 14:23:55 -0700 (Tue, 16 Apr 2013) $
// $Author: msteffens $
// $Revision: 1374 $
// This php script will perform adding, editing & deleting of records.
// It then calls 'receipt.php' which displays links to the modified/added record
// as well as to the previous search results page (if any).
// TODO: I18n
// Incorporate some include files:
include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
include 'includes/include.inc.php'; // include common functions
include 'initialize/ini.inc.php'; // include common variables
// --------------------------------------------------------------------
// START A SESSION:
// call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
start_session(true);
// --------------------------------------------------------------------
// Initialize preferred display language:
// (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
include 'includes/locales.inc.php'; // include the locales
// --------------------------------------------------------------------
// Clear any errors that might have been found previously:
$errors = array();
// We check the '$_GET['proc']' variable in addition to '$_POST' in order to catch the case where the POSTed data are
// greater than the value given in 'post_max_size' (in 'php.ini'). This may happen if the user uploads a large file.
// Relevant quote from <http://de.php.net/ini.core>:
// "If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.
// This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data,
// i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set."
if (isset($_GET['proc']) AND empty($_POST))
{
$maxPostDataSize = ini_get("post_max_size");
// inform the user that the maximum post data size was exceeded:
$HeaderString = returnMsg($loc["Warning_PostDataSizeMustNotExceed"] . " " . $maxPostDataSize . "!", "warning", "strong", "HeaderString"); // function 'returnMsg()' is defined in 'include.inc.php'
header("Location: " . $referer); // redirect to 'record.php' (variable '$referer' is globally defined in function 'start_session()' in 'include.inc.php')
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// Write the (POST) form variables into an array:
foreach($_POST as $varname => $value)
$formVars[$varname] = trim($value); // remove any leading or trailing whitespace from the field's contents & copy the trimmed string to the '$formVars' array
// $formVars[$varname] = trim(clean($value, 50)); // the use of the clean function would be more secure!
// --------------------------------------------------------------------
// Extract form variables sent through POST:
// Note: Although we could use the '$formVars' array directly below (e.g.: $formVars['pageLoginStatus'] etc., like in 'user_validation.php'), we'll read out
// all variables individually again. This is done to enhance readability. (A smarter way of doing so seems be the use of the 'extract()' function, but that
// may expose yet another security hole...)
// Extract the page's login status (which indicates the user's login status at the time the page was loaded):
$pageLoginStatus = $formVars['pageLoginStatus'];
// First of all, check if this script was called by something else than 'record.php':
if (!preg_match("#/record\.php\?.+#", $referer))
{
// return an appropriate error message:
$HeaderString = returnMsg($loc["Warning_InvalidCallToScript"] . " '" . scriptURL() . "'!", "warning", "strong", "HeaderString"); // functions 'returnMsg()' and 'scriptURL()' are defined in 'include.inc.php'
header("Location: " . $referer); // redirect to calling page
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// If the referring page is 'record.php' (i.e., if this script was called by 'record.php'), check if the user is logged in:
elseif ((!isset($_SESSION['loginEmail'])) OR ($pageLoginStatus != "logged in")) // if the user isn't logged in -OR- the page's login status still does NOT state "logged in" (since the page wasn't reloaded after the user logged in elsewhere)
{
// the user is logged in BUT the page's login status still does NOT state "logged in" (since the page wasn't reloaded after the user logged IN elsewhere):
if ((isset($_SESSION['loginEmail'])) AND ($pageLoginStatus != "logged in"))
{
// return an appropriate error message:
$HeaderString = returnMsg($loc["Warning_PageStatusOutDated"] . "!", "warning", "strong", "HeaderString", "", "<br>" . $loc["Warning_RecordDataReloaded"] . ":"); // function 'returnMsg()' is defined in 'include.inc.php'
header("Location: " . $referer); // redirect to 'record.php'
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// the user is NOT logged in BUT the page's login status still states that he's "logged in" (since the page wasn't reloaded after the user logged OUT elsewhere):
if ((!isset($_SESSION['loginEmail'])) AND ($pageLoginStatus == "logged in"))
{
// return an appropriate error message:
$HeaderString = returnMsg($loc["Warning_NotLoggedInAnymore"] . "!", "warning", "strong", "HeaderString", "", "<br>" . $loc["Warning_TimeOutPleaseLoginAgain"] . ":"); // function 'returnMsg()' is defined in 'include.inc.php'
}
// else if the user isn't logged in yet: ((!isset($_SESSION['loginEmail'])) AND ($pageLoginStatus != "logged in"))
header("Location: user_login.php?referer=" . rawurlencode($referer)); // ask the user to login first, then he'll get directed back to 'record.php'
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// if we made it here, the user is regularly logged in: (isset($_SESSION['loginEmail'] == true) AND ($pageLoginStatus == "logged in")
// Extract the form used by the user:
$formType = $formVars['formType'];
// Extract the type of action requested by the user (either 'add', 'edit' or ''):
$recordAction = $formVars['recordAction'];
// $recordAction == '' will be treated equal to 'add':
if (empty($recordAction))
$recordAction = "add"; // we set it explicitly here so that we can employ this variable within message strings, etc
// Determine the button that was hit by the user (either 'Add Record', 'Edit Record', 'Delete Record' or ''):
// '$submitAction' is only used to determine any 'delet' action! (where '$submitAction' = 'Delete Record')
// (otherwise, only '$recordAction' controls how to proceed)
$submitAction = $formVars['submit'];
if (encodeHTML($submitAction) == $loc["ButtonTitle_DeleteRecord"]) // note that we need to HTML encode '$submitAction' for comparison with the HTML encoded locales
$recordAction = "delet"; // *delete* record
// now, check if the (logged in) user is allowed to perform the current record action (i.e., add, edit or delete a record):
$notPermitted = false;
// if the (logged in) user...
if ($recordAction == "edit") // ...wants to edit the current record...
{
if (isset($_SESSION['user_permissions']) AND !preg_match("/allow_edit/", $_SESSION['user_permissions'])) // ...BUT the 'user_permissions' session variable does NOT contain 'allow_edit'...
{
$notPermitted = true;
$HeaderString = $loc["NoPermission"] . $loc["NoPermission_ForEditRecord"] . "!";
}
}
elseif ($recordAction == "delet") // ...wants to delete the current record...
{
if (isset($_SESSION['user_permissions']) AND !preg_match("/allow_delete/", $_SESSION['user_permissions'])) // ...BUT the 'user_permissions' session variable does NOT contain 'allow_delete'...
{
$notPermitted = true;
$HeaderString = $loc["NoPermission"] . $loc["NoPermission_ForDeleteRecord"] . "!";
}
}
else // if ($recordAction == "add" OR $recordAction == "") // ...wants to add the current record...
{
if (isset($_SESSION['user_permissions']) AND !preg_match("/allow_add/", $_SESSION['user_permissions'])) // ...BUT the 'user_permissions' session variable does NOT contain 'allow_add'...
{
$notPermitted = true;
$HeaderString = $loc["NoPermission"] . $loc["NoPermission_ForAddRecords"] . "!";
}
}
if ($notPermitted)
{
// return an appropriate error message:
$HeaderString = returnMsg($HeaderString, "warning", "strong", "HeaderString"); // function 'returnMsg()' is defined in 'include.inc.php'
header("Location: " . $referer); // redirect to 'record.php'
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// if we made it here, we assume that the user is allowed to perform the current record action
// Get the query URL of the formerly displayed results page:
if (isset($_SESSION['oldQuery']))
$oldQuery = $_SESSION['oldQuery'];
else
$oldQuery = array();
// Get the query URL of the last multi-record query:
if (isset($_SESSION['oldMultiRecordQuery']))
$oldMultiRecordQuery = $_SESSION['oldMultiRecordQuery'];
else
$oldMultiRecordQuery = "";
// (1) OPEN CONNECTION, (2) SELECT DATABASE
connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
// Extract all form values provided by 'record.php':
if (isset($formVars['authorName']))
$authorName = $formVars['authorName'];
else
$authorName = "";
if (isset($formVars['isEditorCheckBox']))
$isEditorCheckBox = $formVars['isEditorCheckBox'];
else
$isEditorCheckBox = "";
if (isset($formVars['titleName']))
$titleName = $formVars['titleName'];
else
$titleName = "";
if (isset($formVars['yearNo']))
$yearNo = $formVars['yearNo'];
else
$yearNo = "";
if (isset($formVars['publicationName']))
$publicationName = $formVars['publicationName'];
else
$publicationName = "";
if (isset($formVars['abbrevJournalName']))
$abbrevJournalName = $formVars['abbrevJournalName'];
else
$abbrevJournalName = "";
if (isset($formVars['volumeNo']))
$volumeNo = $formVars['volumeNo'];
else
$volumeNo = "";
if (isset($formVars['issueNo']))
$issueNo = $formVars['issueNo'];
else
$issueNo = "";
if (isset($formVars['pagesNo']))
$pagesNo = $formVars['pagesNo'];
else
$pagesNo = "";
if (isset($formVars['addressName']))
$addressName = $formVars['addressName'];
else
$addressName = "";
if (isset($formVars['corporateAuthorName']))
$corporateAuthorName = $formVars['corporateAuthorName'];
else
$corporateAuthorName = "";
if (isset($formVars['keywordsName']))
$keywordsName = $formVars['keywordsName'];
else
$keywordsName = "";
if (isset($formVars['abstractName']))
$abstractName = $formVars['abstractName'];
else
$abstractName = "";
if (isset($formVars['publisherName']))
$publisherName = $formVars['publisherName'];
else
$publisherName = "";
if (isset($formVars['placeName']))
$placeName = $formVars['placeName'];
else
$placeName = "";
if (isset($formVars['editorName']))
$editorName = $formVars['editorName'];
else
$editorName = "";
if (isset($formVars['languageName']))
$languageName = $formVars['languageName'];
else
$languageName = "";
if (isset($formVars['summaryLanguageName']))
$summaryLanguageName = $formVars['summaryLanguageName'];
else
$summaryLanguageName = "";
if (isset($formVars['origTitleName']))
$origTitleName = $formVars['origTitleName'];
else
$origTitleName = "";
if (isset($formVars['seriesEditorName']))
$seriesEditorName = $formVars['seriesEditorName'];
else
$seriesEditorName = "";
if (isset($formVars['seriesTitleName']))
$seriesTitleName = $formVars['seriesTitleName'];
else
$seriesTitleName = "";
if (isset($formVars['abbrevSeriesTitleName']))
$abbrevSeriesTitleName = $formVars['abbrevSeriesTitleName'];
else
$abbrevSeriesTitleName = "";
if (isset($formVars['seriesVolumeNo']))
$seriesVolumeNo = $formVars['seriesVolumeNo'];
else
$seriesVolumeNo = "";
if (isset($formVars['seriesIssueNo']))
$seriesIssueNo = $formVars['seriesIssueNo'];
else
$seriesIssueNo = "";
if (isset($formVars['editionNo']))
$editionNo = $formVars['editionNo'];
else
$editionNo = "";
if (isset($formVars['issnName']))
$issnName = $formVars['issnName'];
else
$issnName = "";
if (isset($formVars['isbnName']))
$isbnName = $formVars['isbnName'];
else
$isbnName = "";
if (isset($formVars['mediumName']))
$mediumName = $formVars['mediumName'];
else
$mediumName = "";
if (isset($formVars['areaName']))
$areaName = $formVars['areaName'];
else
$areaName = "";
if (isset($formVars['expeditionName']))
$expeditionName = $formVars['expeditionName'];
else
$expeditionName = "";
if (isset($formVars['conferenceName']))
$conferenceName = $formVars['conferenceName'];
else
$conferenceName = "";
if (isset($formVars['notesName']))
$notesName = $formVars['notesName'];
else
$notesName = "";
if (isset($formVars['approvedRadio']))
$approvedRadio = $formVars['approvedRadio'];
else
$approvedRadio = "";
if (isset($formVars['locationName']))
$locationName = $formVars['locationName'];
else
$locationName = "";
$callNumberName = $formVars['callNumberName'];
if (preg_match("/%40|%20/", $callNumberName)) // if '$callNumberName' still contains URL encoded data... ('%40' is the URL encoded form of the character '@', '%20' a space, see note below!)
$callNumberName = rawurldecode($callNumberName); // ...URL decode 'callNumberName' variable contents (it was URL encoded before incorporation into a hidden tag of the 'record' form to avoid any HTML syntax errors)
// NOTE: URL encoded data that are included within a *link* will get URL decoded automatically *before* extraction via '$_POST'!
// But, opposed to that, URL encoded data that are included within a form by means of a *hidden form tag* will NOT get URL decoded automatically! Then, URL decoding has to be done manually (as is done here)!
if (isset($formVars['callNumberNameUserOnly']))
$callNumberNameUserOnly = $formVars['callNumberNameUserOnly'];
else
$callNumberNameUserOnly = "";
if (isset($formVars['serialNo']))
$serialNo = $formVars['serialNo'];
else
$serialNo = "";
if (isset($formVars['typeName']))
$typeName = $formVars['typeName'];
else
$typeName = "";
if (isset($formVars['thesisName']))
$thesisName = $formVars['thesisName'];
else
$thesisName = "";
if (isset($formVars['markedRadio']))
$markedRadio = $formVars['markedRadio'];
else
$markedRadio = "";
if (isset($formVars['copyName']))
$copyName = $formVars['copyName'];
else
$copyName = "";
if (isset($formVars['selectedRadio']))
$selectedRadio = $formVars['selectedRadio'];
else
$selectedRadio = "";
if (isset($formVars['userKeysName']))
$userKeysName = $formVars['userKeysName'];
else
$userKeysName = "";
if (isset($formVars['userNotesName']))
$userNotesName = $formVars['userNotesName'];
else
$userNotesName = "";
if (isset($formVars['userFileName']))
$userFileName = $formVars['userFileName'];
else
$userFileName = "";
if (isset($formVars['userGroupsName']))
$userGroupsName = $formVars['userGroupsName'];
else
$userGroupsName = "";
if (isset($formVars['citeKeyName']))
$citeKeyName = $formVars['citeKeyName'];
else
$citeKeyName = "";
if (isset($formVars['relatedName']))
$relatedName = $formVars['relatedName'];
else
$relatedName = "";
// if the current user has no permission to download (and hence view) any files, 'record.php' does only show an empty string
// in the 'file' field (no matter if a file exists for the given record or not). Thus, we need to make sure that the empty
// form value won't overwrite any existing contents of the 'file' field on UPDATE and that the correct field value gets
// transferred to table 'deleted' on DELETE:
// Therefore, we re-fetch the contents of the 'file' field if NONE of the following conditions are met:
// - the variable '$fileVisibility' (defined in 'ini.inc.php') is set to 'everyone'
// - the variable '$fileVisibility' is set to 'login' AND the user is logged in
// - the variable '$fileVisibility' is set to 'user-specific' AND the 'user_permissions' session variable contains 'allow_download'
if (preg_match("/^(edit|delet)$/", $recordAction) AND (!($fileVisibility == "everyone" OR ($fileVisibility == "login" AND isset($_SESSION['loginEmail'])) OR ($fileVisibility == "user-specific" AND (isset($_SESSION['user_permissions']) AND preg_match("/allow_download/", $_SESSION['user_permissions'])))))) // user has NO permission to download (and view) any files
{
$queryFile = "SELECT file FROM $tableRefs WHERE serial = " . quote_smart($serialNo);
$result = queryMySQLDatabase($queryFile); // RUN the query on the database through the connection
$row = @ mysql_fetch_array($result);
$fileName = $row["file"];
}
else // user has permission to download (and view) any files
$fileName = $formVars['fileName'];
if (isset($formVars['urlName']))
$urlName = $formVars['urlName'];
else
$urlName = "";
if (isset($formVars['doiName']))
$doiName = $formVars['doiName'];
else
$doiName = "";
if (isset($formVars['contributionIDName']))
$contributionID = $formVars['contributionIDName'];
else
$contributionID = "";
$contributionID = rawurldecode($contributionID); // URL decode 'contributionID' variable contents (it was URL encoded before incorporation into a hidden tag of the 'record' form to avoid any HTML syntax errors) [see above!]
if (isset($formVars['contributionIDCheckBox']))
$contributionIDCheckBox = $formVars['contributionIDCheckBox'];
else
$contributionIDCheckBox = "";
if (isset($formVars['locationSelectorName']))
$locationSelectorName = $formVars['locationSelectorName'];
else
$locationSelectorName = "";
if (isset($formVars['onlinePublicationCheckBox']))
$onlinePublicationCheckBox = $formVars['onlinePublicationCheckBox'];
else
$onlinePublicationCheckBox = "";
if (isset($formVars['onlineCitationName']))
$onlineCitationName = $formVars['onlineCitationName'];
else
$onlineCitationName = "";
if (isset($formVars['createdDate']))
$createdDate = $formVars['createdDate'];
else
$createdDate = "";
if (isset($formVars['createdTime']))
$createdTime = $formVars['createdTime'];
else
$createdTime = "";
if (isset($formVars['createdBy']))
$createdBy = $formVars['createdBy'];
else
$createdBy = "";
if (isset($formVars['modifiedDate']))
$modifiedDate = $formVars['modifiedDate'];
else
$modifiedDate = "";
if (isset($formVars['modifiedTime']))
$modifiedTime = $formVars['modifiedTime'];
else
$modifiedTime = "";
if (isset($formVars['modifiedBy']))
$modifiedBy = $formVars['modifiedBy'];
else
$modifiedBy = "";
if (isset($formVars['origRecord']))
$origRecord = $formVars['origRecord'];
else
$origRecord = "";
// check if a file was uploaded:
// (note that to have file uploads work, HTTP file uploads must be allowed within your 'php.ini' configuration file
// by setting the 'file_uploads' parameter to 'On'!)
// extract file information into a four (or five) element associative array containing the following information about the file:
// name - original name of file on client
// type - MIME type of file
// tmp_name - name of temporary file on server
// error - holds an error number >0 if something went wrong, otherwise 0 (I don't know when this element was added. It may not be present in your PHP version... ?:-/)
// size - size of file in bytes
// depending what happend on upload, they will contain the following values (PHP 4.1 and above):
// no file upload upload exceeds 'upload_max_filesize' successful upload
// -------------- ------------------------------------ -----------------
// name "" [name] [name]
// type "" "" [type]
// tmp_name "" OR "none" "" [tmp_name]
// error 4 1 0
// size 0 0 [size]
$uploadFile = getUploadInfo("uploadFile"); // function 'getUploadInfo()' is defined in 'include.inc.php'
// --------------------------------------------------------------------
// VALIDATE data fields:
// NOTE: for all fields that are validated here must exist error parsing code (of the form: " . fieldError("languageName", $errors) . ")
// in front of the respective <input> form field in 'record.php'! Otherwise the generated error won't be displayed!
// Validate fields that MUST not be empty:
// Validate the 'Call Number' field:
if (preg_match("/[@;]/", $callNumberNameUserOnly))
$errors["callNumberNameUserOnly"] = "Your call number cannot contain the characters '@' and ';' (since they function as delimiters):"; // the user's personal reference ID cannot contain the characters '@' and ';' since they are used as delimiters (within or between call numbers)
elseif ($recordAction == "edit" AND !empty($callNumberNameUserOnly) AND !preg_match("/$loginEmail/", $locationName) AND !preg_match("/^(add|remove)$/", $locationSelectorName)) // if the user specified some reference ID within an 'edit' action -BUT- there's no existing call number for this user within the contents of the 'location' field -AND- the user doesn't want to add it either...
$errors["callNumberNameUserOnly"] = "You cannot specify a call number unless you add this record to your personal literature set! This can be done by setting the 'Location Field' popup below to 'add'."; // warn the user that he/she has to set the Location Field popup to 'add' if he want's to add this record to his personal literature set
// Validate the 'uploadFile' field:
// (whose file name characters must be within [a-zA-Z0-9+_.-] and which must not exceed
// the 'upload_max_filesize' specified within your 'php.ini' configuration file)
if (!empty($uploadFile) && !empty($uploadFile["name"])) // if the user attempted to upload a file
{
// The 'is_uploaded_file()' function returns 'true' if the file indicated by '$uploadFile["tmp_name"]' was uploaded via HTTP POST. This is useful to help ensure
// that a malicious user hasn't tried to trick the script into working on files upon which it should not be working - for instance, /etc/passwd.
if (is_uploaded_file($uploadFile["tmp_name"]))
{
if (empty($uploadFile["tmp_name"])) // no tmp file exists => we assume that the maximum upload file size was exceeded!
// or check via 'error' element instead: "if ($uploadFile["error"] == 1)" (the 'error' element exists since PHP 4.2.0)
{
$maxFileSize = ini_get("upload_max_filesize");
$fileError = "File size must not be greater than " . $maxFileSize . ":";
$errors["uploadFile"] = $fileError; // inform the user that the maximum upload file size was exceeded
}
else // a tmp file exists...
{
// prevent hackers from gaining access to the systems 'passwd' file (this should be prevented by the 'is_uploaded_file()' function but anyhow):
if (preg_match("/^passwd$/i", $uploadFile["name"])) // file name must not be 'passwd'
$errors["uploadFile"] = "This file name is not allowed!";
// check for invalid file name extensions:
if (preg_match("#\.(exe|com|bat|zip|php|phps|php3|phtml|phtm|cgi)$#i", $uploadFile["name"])) // file name has an invalid file name extension (adjust the regex pattern if you want more relaxed file name validation)
$errors["uploadFile"] = "You cannot upload this type of file!"; // file name must not end with .exe, .com, .bat, .zip, .php, .phps, .php3, .phtml, .phtm or .cgi
if ($renameUploadedFiles != "yes") // if we do NOT rename files according to a standard naming scheme (variable '$renameUploadedFiles' is defined in 'ini.inc.php')
{
// check for invalid file name characters:
if (!preg_match("/^[" . $allowedFileNameCharacters . "]+$/", $uploadFile["name"])) // file name contains invalid characters (variable '$allowedFileNameCharacters' is defined in 'ini.inc.php')
$errors["uploadFile"] = "File name characters can only be within " . $allowedFileNameCharacters; // characters of file name must be within range given in '$allowedFileNameCharacters'
// previous error message was a bit more user-friendly: "File name characters can only be alphanumeric ('a-zA-Z0-9'), plus ('+'), minus ('-'), substring ('_') or a dot ('.'):"
}
}
}
else
{
// I'm not sure if this actually works --RAK
switch($uploadFile["error"])
{
case 0: // no error; possible file attack!
$errors["uploadFile"] = "There was a problem with your upload.";
break;
case 1: // uploaded file exceeds the 'upload_max_filesize' directive in 'php.ini'
$maxFileSize = ini_get("upload_max_filesize");
$fileError = "File size must not be greater than " . $maxFileSize . ":";
$errors["uploadFile"] = $fileError;
break;
case 2: // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form (Note: refbase doesn't currently specify MAX_FILE_SIZE but anyhow...)
$errors["uploadFile"] = "The file you are trying to upload is too big.";
break;
case 3: // uploaded file was only partially uploaded
$errors["uploadFile"] = "The file you are trying to upload was only partially uploaded.";
break;
case 4: // no file was uploaded
$errors["uploadFile"] = "You must select a file for upload.";
break;
case 6:
$errors["uploadFile"] = "Missing a temporary folder.";
break;
default: // a default error, just in case! :)
$errors["uploadFile"] = "There was a problem with your upload.";
break;
}
}
}
// CAUTION: validation of other fields is currently disabled, since, IMHO, there are too many open questions how to implement this properly
// and without frustrating the user! Uncomment the commented code below to enable the current validation features:
// // Validate fields that SHOULD not be empty:
// // Validate the 'Author' field:
// if (empty($authorName))
// $errors["authorName"] = "Is there really no author info for this record? Enter NULL to force empty:"; // Author should not be a null string
//
// // Validate the 'Title' field:
// if (empty($titleName))
// $errors["titleName"] = "Is there really no title info for this record? Enter NULL to force empty:"; // Title should not be a null string
//
// // Validate the 'Year' field:
// if (empty($yearNo))
// $errors["yearNo"] = "Is there really no year info for this record? Enter NULL to force empty:"; // Year should not be a null string
//
// // Validate the 'Publication' field:
// if (empty($publicationName))
// $errors["publicationName"] = "Is there really no publication info for this record? Enter NULL to force empty:"; // Publication should not be a null string
//
// // Validate the 'Abbrev Journal' field:
// if (empty($abbrevJournalName))
// $errors["abbrevJournalName"] = "Is there really no abbreviated journal info for this record? Enter NULL to force empty:"; // Abbrev Journal should not be a null string
//
// // Validate the 'Volume' field:
// if (empty($volumeNo))
// $errors["volumeNo"] = "Is there really no volume info for this record? Enter NULL to force empty:"; // Volume should not be a null string
//
// // Validate the 'Pages' field:
// if (empty($pagesNo))
// $errors["pagesNo"] = "Is there really no pages info for this record? Enter NULL to force empty:"; // Pages should not be a null string
//
//
// // Validate fields that MUST not be empty:
// // Validate the 'Language' field:
// if (empty($languageName))
// $errors["languageName"] = "The language field cannot be blank:"; // Language cannot be a null string
//
//
// // Remove 'NULL' values that were entered by the user in order to force empty values for required text fields:
// // (for the required number fields 'yearNo' & 'volumeNo' inserting 'NULL' will cause '0000' or '0' as value, respectively)
// if ($authorName == "NULL")
// $authorName = "";
//
// if ($titleName == "NULL")
// $titleName = "";
//
// if ($publicationName == "NULL")
// $publicationName = "";
//
// if ($abbrevJournalName == "NULL")
// $abbrevJournalName = "";
//
// if ($pagesNo == "NULL")
// $pagesNo = "";
// --------------------------------------------------------------------
// Now the script has finished the validation, check if there were any errors:
if (count($errors) > 0)
{
// Write back session variables:
saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php'
saveSessionVariable("formVars", $formVars);
// There are errors. Relocate back to the record entry form:
header("Location: " . $referer);
exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
// --------------------------------------------------------------------
// If we made it here, then the data is considered valid!
// CONSTRUCT SQL QUERY:
// First, setup some required variables:
// Get the current date (e.g. '2003-12-31'), time (e.g. '23:59:49') and user name & email address (e.g. 'Matthias Steffens (refbase@extracts.de)'):
list ($currentDate, $currentTime, $currentUser) = getCurrentDateTimeUser(); // function 'getCurrentDateTimeUser()' is defined in 'include.inc.php'
// Build a correct call number prefix for the currently logged-in user (e.g. 'IP� @ msteffens'):
$callNumberPrefix = getCallNumberPrefix(); // function 'getCallNumberPrefix()' is defined in 'include.inc.php'
// provide some magic that figures out what do to depending on the state of the 'is Editor' check box
// and the content of the 'author', 'editor' and 'type' fields:
if ($isEditorCheckBox == "1" OR preg_match("/^(Book Whole|Conference Volume|Journal|Manuscript|Map)$/", $typeName)) // if the user did mark the 'is Editor' checkbox -OR- if the record type is either 'Book Whole', 'Conference Volume', 'Journal', 'Map' or 'Manuscript'...
if (!empty($editorName) AND empty($authorName)) // ...and if the 'Editor' field has some content while the 'Author' field is blank...
{
$authorName = $editorName; // duplicate field contents from 'editor' to 'author' field
$isEditorCheckBox = "1"; // since the user entered something in the 'editor' field (but not the 'author' field), we need to make sure that the 'is Editor' is marked
}
if ($isEditorCheckBox == "1" AND preg_match("/^(Book Whole|Conference Volume|Journal|Manuscript|Map)$/", $typeName)) // if the user did mark the 'is Editor' checkbox -AND- the record type is either 'Book Whole', 'Conference Volume', 'Journal', 'Map' or 'Manuscript'...
{
$authorName = preg_replace("/ *\(eds?\)$/i","",$authorName); // ...remove any existing editor info from the 'author' string, i.e., kill any trailing " (ed)" or " (eds)"
if (!empty($authorName)) // if the 'Author' field has some content...
$editorName = $authorName; // ...duplicate field contents from 'author' to 'editor' field (CAUTION: this will overwrite any existing contents in the 'editor' field!)
if (!empty($authorName)) // if 'author' field isn't empty
{
if (!preg_match("/;/", $authorName)) // if the 'author' field does NOT contain a ';' (which would delimit multiple authors) => single author
$authorName .= " (ed)"; // append " (ed)" to the end of the 'author' string
else // the 'author' field does contain at least one ';' => multiple authors
$authorName .= " (eds)"; // append " (eds)" to the end of the 'author' string
}
}
else // the 'is Editor' checkbox is NOT checked -OR- the record type is NOT 'Book Whole', 'Conference Volume', 'Journal', 'Map' or 'Manuscript'...
{
if (preg_match("/ *\(eds?\)$/", $authorName)) // if 'author' field ends with either " (ed)" or " (eds)"
$authorName = preg_replace("/ *\(eds?\)$/i","",$authorName); // remove any existing editor info from the 'author' string, i.e., kill any trailing " (ed)" or " (eds)"
if ($authorName == $editorName) // if the 'Author' field contents equal the 'Editor' field contents...
$editorName = ""; // ...clear contents of 'editor' field (that is, we assume that the user did uncheck the 'is Editor' checkbox, which was previously marked)
}
// Assign correct values to the calculation fields 'first_author', 'author_count', 'first_page', 'volume_numeric' and 'series_volume_numeric':
// function 'generateCalculationFieldContent()' is defined in 'include.inc.php'
// NOTE: this function call won't be necessary anymore when we've also moved database INSERTs and DELETEs to dedicated functions (which would take care of calculation fields then) -> compare with 'addRecords()' function
list ($firstAuthor, $authorCount, $firstPage, $volumeNumericNo, $seriesVolumeNumericNo) = generateCalculationFieldContent($authorName, $pagesNo, $volumeNo, $seriesVolumeNo);
// manage 'location' field data:
if ((($locationSelectorName == "add") OR ($locationSelectorName == "")) AND (!preg_match("/$loginEmail/", $locationName))) // add the current user to the 'location' field (if he/she isn't listed already within the 'location' field):
// note: if the current user is NOT logged in -OR- if any normal user is logged in, the value for '$locationSelectorName' will be always '' when performing an INSERT,
// since the popup is fixed to 'add' and disabled (which, in turn, will result in an empty value to be returned)
{
// if the 'location' field is either completely empty -OR- does only contain the information string (that shows up on 'add' for normal users):
if (preg_match("/^(" . $loc["your name & email address will be filled in automatically"] . ")?$/", encodeHTML($locationName))) // note that we need to HTML encode '$locationName' for comparison with the HTML encoded locales
$locationName = preg_replace("/^.*$/i", "$currentUser", $locationName);
else // if the 'location' field does already contain some user content:
$locationName = preg_replace("/^(.+)$/i", "\\1; $currentUser", $locationName);
}
elseif ($locationSelectorName == "remove") // remove the current user from the 'location' field:
{ // the only pattern that's really unique is the users email address, the user's name may change (since it can be modified by the user). This is why we dont use '$currentUser' here:
$locationName = preg_replace("/^[^;]*\( *$loginEmail *\) *; */i", "", $locationName); // the current user is listed at the very beginning of the 'location' field
$locationName = preg_replace("/ *;[^;]*\( *$loginEmail *\) */i", "", $locationName); // the current user occurs after some other user within the 'location' field
$locationName = preg_replace("/^[^;]*\( *$loginEmail *\) *$/i", "", $locationName); // the current user is the only one listed within the 'location' field
}
// else if '$locationSelectorName' == "don't touch" -OR- if the user is already listed within the 'location' field, we just accept the contents of the 'location' field as entered by the user
// manage 'call_number' field data:
if ($loginEmail != $adminLoginEmail) // if any normal user is logged in (not the admin):
{
if (preg_match("/$loginEmail/", $locationName)) // we only process the user's call number information if the current user is listed within the 'location' field:
{
// Note that, for normal users, we process the user's call number information even if the '$locationSelectorName' is NOT set to 'add'.
// This is done, since the user should be able to update his/her personal reference ID while the '$locationSelectorName' is set to 'don't touch'.
// If the '$locationSelectorName' is set to 'remove', then any changes made to the personal reference ID will be discarded anyhow.
// build a correct call number string for the current user & record:
if ($callNumberNameUserOnly == "") // if the user didn't enter any personal reference ID for this record...
$callNumberNameUserOnly = $callNumberPrefix . " @ "; // ...insert the user's call number prefix only
else // if the user entered (or modified) his/her personal reference ID for this record...
$callNumberNameUserOnly = $callNumberPrefix . " @ " . $callNumberNameUserOnly; // ...prefix the entered reference ID with the user's call number prefix
// insert or update the user's call number within the full contents of the 'call_number' field:
if ($callNumberName == "") // if the 'call_number' field is empty...
$callNumberName = $callNumberNameUserOnly; // ...insert the user's call number prefix
elseif (preg_match("/$callNumberPrefix/", $callNumberName)) // if the user's call number prefix occurs within the contents of the 'call_number' field...
$callNumberName = preg_replace("/$callNumberPrefix *@ *[^@;]*/i", "$callNumberNameUserOnly", $callNumberName); // ...replace the user's *own* call number within the full contents of the 'call_number' field
else // if the 'call_number' field does already have some content -BUT- there's no existing call number prefix for the current user...
$callNumberName = $callNumberName . "; " . $callNumberNameUserOnly; // ...append the user's call number to any existing call numbers
}
}
else // if the admin is logged in:
if ($locationSelectorName == "add") // we only add the admin's call number information if he/she did set the '$locationSelectorName' to 'add'
{
if ($callNumberName == "") // if there's no call number info provided by the admin...
$callNumberName = $callNumberPrefix . " @ "; // ...insert the admin's call number prefix
elseif (!preg_match("/@/", $callNumberName)) // if there's a call number provided by the admin that does NOT contain any '@' already...
$callNumberName = $callNumberPrefix . " @ " . $callNumberName; // ...then we assume the admin entered a personal refernce ID for this record which should be prefixed with his/her call number prefix
// the contents of the 'call_number' field do contain the '@' character, i.e. we assume one or more full call numbers to be present
elseif (!preg_match("/$callNumberPrefix/", $callNumberName)) // if the admin's call number prefix does NOT already occur within the contents of the 'call_number' field...
{
if (preg_match("/; *[^ @;][^@;]*$/", $callNumberName)) // for the admin we offer autocompletion of the call number prefix if he/she just enters his/her reference ID after the last full call number (separated by '; ')
// e.g., the string 'IP� @ mschmid @ 123; 1778' will be autocompleted to 'IP� @ mschmid @ 123; IP� @ msteffens @ 1778' (with 'msteffens' being the admin user)
$callNumberName = preg_replace("/^(.+); *([^@;]+)$/i", "\\1; $callNumberPrefix @ \\2", $callNumberName); // insert the admin's call number prefix before any reference ID that stand's at the end of the string of call numbers
else
$callNumberName = $callNumberName . "; " . $callNumberPrefix . " @ "; // ...append the admin's call number prefix to any existing call numbers
}
}
// otherwise we simply use the information as entered by the admin
if ($locationSelectorName == "remove") // remove the current user's call number from the 'call_number' field:
{
$callNumberName = preg_replace("/^ *$callNumberPrefix *@ *[^@;]*; */i", "", $callNumberName); // the user's call number is listed at the very beginning of the 'call_number' field
$callNumberName = preg_replace("/ *; *$callNumberPrefix *@ *[^@;]*/i", "", $callNumberName); // the user's call number occurs after some other call number within the 'call_number' field
$callNumberName = preg_replace("/^ *$callNumberPrefix *@ *[^@;]*$/i", "", $callNumberName); // the user's call number is the only one listed within the 'call_number' field
}
// handle file uploads:
if (preg_match("/^(edit|delet)$/", $recordAction)) // we exclude '$recordAction = "add"' here, since file name generation needs to be done *after* the record has been created and a serial number is available
{
if (!empty($uploadFile) && !empty($uploadFile["tmp_name"])) // if there was a file uploaded successfully
// process information of any file that was uploaded, auto-generate a file name if required and move the file to the appropriate directory:
$fileName = handleFileUploads($uploadFile, $formVars);
}
// check if we need to set the 'contribution_id' field:
// (we'll make use of the session variable '$abbrevInstitution' here)
if ($contributionIDCheckBox == "1") // the user want's to add this record to the list of publications that were published by a member of his institution
{
if (!empty($contributionID)) // if the 'contribution_id' field is NOT empty...
{
if (!preg_match("/$abbrevInstitution/", $contributionID)) // ...and the current user's 'abbrev_institution' value isn't listed already within the 'contribution_id' field
$contributionID = $contributionID . "; " . $abbrevInstitution; // append the user's 'abbrev_institution' value to the end of the 'contribution_id' field
}
else // the 'contribution_id' field is empty
$contributionID = $abbrevInstitution; // insert the current user's 'abbrev_institution' value
}
else // if present, remove the current user's abbreviated institution name from the 'contribution_id' field:
{
if (preg_match("/$abbrevInstitution/", $contributionID)) // if the current user's 'abbrev_institution' value is listed within the 'contribution_id' field, we'll remove it:
{
$contributionID = preg_replace("/^ *$abbrevInstitution *[^;]*; */i", "", $contributionID); // the user's abbreviated institution name is listed at the very beginning of the 'contribution_id' field
$contributionID = preg_replace("/ *; *$abbrevInstitution *[^;]*/i", "", $contributionID); // the user's abbreviated institution name occurs after some other institutional abbreviation within the 'contribution_id' field
$contributionID = preg_replace("/^ *$abbrevInstitution *[^;]*$/i", "", $contributionID); // the user's abbreviated institution name is the only one listed within the 'contribution_id' field
}
}
// check if we need to set the 'online_publication' field:
if ($onlinePublicationCheckBox == "1") // the user did mark the "Online publication" checkbox
$onlinePublication = "yes";
else
$onlinePublication = "no";
// remove any meaningless delimiter(s) from the beginning or end of a field string:
// Note: - this cleanup is only done for fields that may contain sub-elements, which are the fields:
// 'author', 'keywords', 'place', 'language', 'summary_language', 'area', 'user_keys' and 'user_groups'
// - currently, only the semicolon (optionally surrounded by whitespace) is supported as sub-element delimiter
$authorName = trimTextPattern($authorName, "( *; *)+", true, true); // function 'trimTextPattern()' is defined in 'include.inc.php'
$keywordsName = trimTextPattern($keywordsName, "( *; *)+", true, true);
$placeName = trimTextPattern($placeName, "( *; *)+", true, true);
$languageName = trimTextPattern($languageName, "( *; *)+", true, true);
$summaryLanguageName = trimTextPattern($summaryLanguageName, "( *; *)+", true, true);
$areaName = trimTextPattern($areaName, "( *; *)+", true, true);
$userKeysName = trimTextPattern($userKeysName, "( *; *)+", true, true);
$userGroupsName = trimTextPattern($userGroupsName, "( *; *)+", true, true);
$queryDeleted = ""; // initialize the '$queryDeleted' variable in order to prevent 'Undefined variable...' messages
// Is this an update?
if ($recordAction == "edit") // alternative method to check for an 'edit' action: if (preg_match("/^[0-9]+$/",$serialNo)) // a valid serial number must be an integer
// yes, the form already contains a valid serial number, so we'll have to update the relevant record:
{
// UPDATE - construct queries to update the relevant record
$queryRefs = "UPDATE $tableRefs SET "
. "author = " . quote_smart($authorName) . ", "
. "first_author = " . quote_smart($firstAuthor) . ", "
. "author_count = " . quote_smart($authorCount) . ", "
. "title = " . quote_smart($titleName) . ", "
. "year = " . quote_smart($yearNo) . ", "
. "publication = " . quote_smart($publicationName) . ", "
. "abbrev_journal = " . quote_smart($abbrevJournalName) . ", "
. "volume = " . quote_smart($volumeNo) . ", "
. "volume_numeric = " . quote_smart($volumeNumericNo) . ", "
. "issue = " . quote_smart($issueNo) . ", "
. "pages = " . quote_smart($pagesNo) . ", "
. "first_page = " . quote_smart($firstPage) . ", "
. "address = " . quote_smart($addressName) . ", "
. "corporate_author = " . quote_smart($corporateAuthorName) . ", "
. "keywords = " . quote_smart($keywordsName) . ", "
. "abstract = " . quote_smart($abstractName) . ", "
. "publisher = " . quote_smart($publisherName) . ", "
. "place = " . quote_smart($placeName) . ", "
. "editor = " . quote_smart($editorName) . ", "
. "language = " . quote_smart($languageName) . ", "
. "summary_language = " . quote_smart($summaryLanguageName) . ", "
. "orig_title = " . quote_smart($origTitleName) . ", "
. "series_editor = " . quote_smart($seriesEditorName) . ", "
. "series_title = " . quote_smart($seriesTitleName) . ", "
. "abbrev_series_title = " . quote_smart($abbrevSeriesTitleName) . ", "
. "series_volume = " . quote_smart($seriesVolumeNo) . ", "
. "series_volume_numeric = " . quote_smart($seriesVolumeNumericNo) . ", "
. "series_issue = " . quote_smart($seriesIssueNo) . ", "
. "edition = " . quote_smart($editionNo) . ", "
. "issn = " . quote_smart($issnName) . ", "
. "isbn = " . quote_smart($isbnName) . ", "
. "medium = " . quote_smart($mediumName) . ", "
. "area = " . quote_smart($areaName) . ", "
. "expedition = " . quote_smart($expeditionName) . ", "
. "conference = " . quote_smart($conferenceName) . ", "
. "location = " . quote_smart($locationName) . ", "
. "call_number = " . quote_smart($callNumberName) . ", "
. "approved = " . quote_smart($approvedRadio) . ", "
. "file = " . quote_smart($fileName) . ", "
. "type = " . quote_smart($typeName) . ", "
. "thesis = " . quote_smart($thesisName) . ", "
. "notes = " . quote_smart($notesName) . ", "
. "url = " . quote_smart($urlName) . ", "
. "doi = " . quote_smart($doiName) . ", "
. "contribution_id = " . quote_smart($contributionID) . ", "
. "online_publication = " . quote_smart($onlinePublication) . ", "
. "online_citation = " . quote_smart($onlineCitationName) . ", "
. "modified_date = " . quote_smart($currentDate) . ", "
. "modified_time = " . quote_smart($currentTime) . ", "
. "modified_by = " . quote_smart($currentUser) . " "
. "WHERE serial = " . quote_smart($serialNo);
// first, we need to check if there's already an entry for the current record & user within the 'user_data' table:
// CONSTRUCT SQL QUERY:
$query = "SELECT data_id FROM $tableUserData WHERE record_id = " . quote_smart($serialNo) . " AND user_id = " . quote_smart($loginUserID); // '$loginUserID' is provided as session variable
// (3) RUN the query on the database through the connection:
$result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
if (mysql_num_rows($result) == 1) // if there's already an existing user_data entry, we perform an UPDATE action:
$queryUserData = "UPDATE $tableUserData SET "
. "marked = " . quote_smart($markedRadio) . ", "
. "copy = " . quote_smart($copyName) . ", "
. "selected = " . quote_smart($selectedRadio) . ", "
. "user_keys = " . quote_smart($userKeysName) . ", "
. "user_notes = " . quote_smart($userNotesName) . ", "
. "user_file = " . quote_smart($userFileName) . ", "
. "user_groups = " . quote_smart($userGroupsName) . ", "
. "cite_key = " . quote_smart($citeKeyName) . ", "
. "related = " . quote_smart($relatedName) . " "
. "WHERE record_id = " . quote_smart($serialNo) . " AND user_id = " . quote_smart($loginUserID); // '$loginUserID' is provided as session variable
else // otherwise we perform an INSERT action:
$queryUserData = "INSERT INTO $tableUserData SET "
. "marked = " . quote_smart($markedRadio) . ", "
. "copy = " . quote_smart($copyName) . ", "
. "selected = " . quote_smart($selectedRadio) . ", "
. "user_keys = " . quote_smart($userKeysName) . ", "
. "user_notes = " . quote_smart($userNotesName) . ", "
. "user_file = " . quote_smart($userFileName) . ", "
. "user_groups = " . quote_smart($userGroupsName) . ", "
. "cite_key = " . quote_smart($citeKeyName) . ", "
. "related = " . quote_smart($relatedName) . ", "
. "record_id = " . quote_smart($serialNo) . ", "
. "user_id = " . quote_smart($loginUserID) . ", " // '$loginUserID' is provided as session variable
. "data_id = NULL"; // inserting 'NULL' into an auto_increment PRIMARY KEY attribute allocates the next available key value
}
elseif ($recordAction == "delet") // (Note that if you delete the mother record within the 'refs' table, the corresponding child entry within the 'user_data' table will remain!)
{
// Instead of deleting data, deleted records will be moved to the "deleted" table. Data will be stored within the "deleted" table
// until they are removed manually. This is to provide the admin with a simple recovery method in case a user did delete some data by accident...
// INSERT - construct queries to add data as new record
$queryDeleted = "INSERT INTO $tableDeleted SET "
. "author = " . quote_smart($authorName) . ", "
. "first_author = " . quote_smart($firstAuthor) . ", "
. "author_count = " . quote_smart($authorCount) . ", "
. "title = " . quote_smart($titleName) . ", "
. "year = " . quote_smart($yearNo) . ", "
. "publication = " . quote_smart($publicationName) . ", "
. "abbrev_journal = " . quote_smart($abbrevJournalName) . ", "
. "volume = " . quote_smart($volumeNo) . ", "
. "volume_numeric = " . quote_smart($volumeNumericNo) . ", "
. "issue = " . quote_smart($issueNo) . ", "
. "pages = " . quote_smart($pagesNo) . ", "
. "first_page = " . quote_smart($firstPage) . ", "
. "address = " . quote_smart($addressName) . ", "
. "corporate_author = " . quote_smart($corporateAuthorName) . ", "
. "keywords = " . quote_smart($keywordsName) . ", "
. "abstract = " . quote_smart($abstractName) . ", "