annotate msite.inc.php @ 1114:51f24cb35fc8

s/SET_LEN_/SQL_LEN_/g
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 14 Oct 2019 10:31:39 +0300
parents 0a2117349f46
children 24e6915fc0fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1071
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1049
diff changeset
1 <?php
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 //
571
ce11ea112a65 Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
3 // FAPWeb - Simple Web-based Demoparty Management System
33
5bf22431176c Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
4 // Generic and miscellaneous site support code
1072
7da8bde9b7be Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 1071
diff changeset
5 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 //
175
8df523e6326a User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
7 require_once "msitegen.inc.php";
51
7bdf89601ba0 Work on session stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
8
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
9 // Define modes of party information display system
410
298822ed0420 Change display mode constant values.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
10 define("SMODE_DISABLED", 0);
298822ed0420 Change display mode constant values.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
11 define("SMODE_ROTATE", 1);
298822ed0420 Change display mode constant values.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
12 define("SMODE_COMPO", 2);
139
75cf14ee99a7 More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
13
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
14
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
15 // Define sizes of database fields, see createdb.php
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
16 // and also the places where input is validated.
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
17 define("SQL_LEN_USERNAME", 32);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
18 define("SQL_LEN_GROUPS", 64);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
19 define("SQL_LEN_ONELINER", 64);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
20 define("SQL_LEN_EMAIL", 80);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
21 define("SQL_LEN_REGHOST", 128);
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
22
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
23 define("SQL_LEN_NEWS_TITLE", 128);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
24 define("SQL_LEN_NEWS_TEXT", 4096);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
25 define("SQL_LEN_NEWS_AUTHOR", 64);
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
26
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
27 define("SQL_LEN_COMPO_NAME", 128);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
28 define("SQL_LEN_COMPO_DESC", 4096);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
29 define("SQL_LEN_COMPO_NOTES", 4096);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
30 define("SQL_LEN_COMPO_PATH", 128);
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
31
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
32 define("SQL_LEN_ENTRY_NAME", 64);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
33 define("SQL_LEN_ENTRY_AUTHOR", 64);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
34 define("SQL_LEN_ENTRY_FILENAME", 128);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
35 define("SQL_LEN_ENTRY_INFO", 50*4);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
36 define("SQL_LEN_ENTRY_NOTES", 1024);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
37 define("SQL_LEN_ENTRY_PREVIEW_FILE", 128);
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
38
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
39 define("SQL_LEN_DISP_SLIDE_TITLE", 64);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
40 define("SQL_LEN_DISP_SLIDE_TEXT", 4096);
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
41 define("SQL_LEN_ROT_LIST_NAME", 128);
184
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
42
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
43 define("SQL_LEN_USERKEY", 64);
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
44
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
45
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
46 //
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
47 // File format classes
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
48 //
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
49 define("EFILE_NONE", 0);
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
50 define("EFILE_IMAGE", 1);
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
51 define("EFILE_AUDIO", 2); // Also preview types
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
52
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
53 define("EFILE_VIDEO", 3);
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
54 define("EFILE_TEXT", 4);
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
55 define("EFILE_BINARY", 5);
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
56 define("EFILE_ARCHIVE", 6);
703
242cb053fbb2 Add array/list of preview types and descriptions for them.
Matti Hamalainen <ccr@tnsp.org>
parents: 702
diff changeset
57
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
58
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
59 //
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
60 // Entry preview type (value)
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
61 //
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
62 $previewTypeList = array(
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
63 EFILE_NONE => array("No previews" , "Default"),
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
64 EFILE_IMAGE => array("Image file" , "Image"),
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
65 EFILE_AUDIO => array("Audio file" , "Audio"),
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
66 );
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
67
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
68
702
c527b42a7857 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
69 //
c527b42a7857 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
70 // Entry flags (bitfield)
c527b42a7857 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
71 //
998
b0ef1c1b0eeb Add a new entry flag, update comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
72 define("EFLAG_DISQUALIFIED" , 1); // Entry is disqualified
b0ef1c1b0eeb Add a new entry flag, update comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
73 define("EFLAG_PROBLEMS" , 2); // Has some problems
b0ef1c1b0eeb Add a new entry flag, update comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
74 define("EFLAG_LOCKED" , 4); // Can't be edited by non-admins
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
75
690
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
76 $entryFlagsList = array(
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
77 EFLAG_DISQUALIFIED => array("Disqualified", "img/disqualified.png"),
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
78 EFLAG_PROBLEMS => array("Has problems", "img/problems.png"),
998
b0ef1c1b0eeb Add a new entry flag, update comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
79 EFLAG_LOCKED => array("LOCKED", "img/locked.png"),
690
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
80 );
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
81
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
82
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
83 //
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
84 // Results output flags
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
85 //
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
86 define("RFLAG_NORMAL", 0);
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
87 define("RFLAG_DISQUALIFIED", 1);
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
88 define("RFLAG_HIDDEN_COMPOS", 2);
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
89
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
90 //
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
91 // Competition types
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
92 //
606
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
93 define("COMPO_NORMAL", 0); // Normal voting compo, points determine placement
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
94 define("COMPO_POINTS", 1); // Assigned points, points determines placement (no voting)
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
95 define("COMPO_ASSIGN", 2); // Assigned places (no voting)
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
96
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
97
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
98 $compoModeData = array(
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
99 COMPO_NORMAL => array("Normal",
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
100 "Normal voting compo.",
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
101 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
102 COMPO_POINTS => array("Points",
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
103 "Assigned points (no voting).",
745
7ac6d1fdc078 Add two new fields to compoModeData.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
104 "Points",
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
105 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
106 COMPO_ASSIGN => array("Assigned",
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
107 "Assigned places (no points, no voting).",
745
7ac6d1fdc078 Add two new fields to compoModeData.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
108 "Place",
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
109 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
110 );
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
111
641
1a123c6c2241 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 640
diff changeset
112
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
113 //
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
114 // Different voting modes
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
115 //
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
116 define("VOTE_FREELY", 0);
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
117 define("VOTE_ACTIVATE", 1);
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
118 define("VOTE_ASSIGN", 2);
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
119
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
120 $voteModeData = array(
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
121 VOTE_FREELY => array("Freeform voting",
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
122 "User keys are not tied to attendees, and do not need to be activated. ".
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
123 "Take one printed key slip, give it to attendee."
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
124 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
125 VOTE_ACTIVATE => array("Key activation",
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
126 "User keys are not tied to attendees, but require manual activation. ".
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
127 "Take one printed key slip, find it by the index number in the list below, set to activated. ".
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
128 "Give key slip to attendee."
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
129 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
130 VOTE_ASSIGN => array("Assigned keys",
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
131 "User keys are tied to attendees, activated by assigning the key to attendee. ".
307
c0d573a5de5b Add procedure description to assigned keys mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
132 "Take one printed key slip, find attendee in the list below, enter key ID number, assign, check. ".
c0d573a5de5b Add procedure description to assigned keys mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
133 "Give key slip to attendee."
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
134 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
135 );
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
136
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
137
535
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
138 //
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
139 // Data about the file types we use
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
140 //
809
a165d2e101f9 Rename array.
Matti Hamalainen <ccr@tnsp.org>
parents: 808
diff changeset
141 $fileTypeData = array(
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
142 "PNG" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
143 "class" => EFILE_IMAGE,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
144 "type" => EFILE_IMAGE,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
145 "mime" => "image/png",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
146 "fext" => "png",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
147 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
148 "JPEG" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
149 "class" => EFILE_IMAGE,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
150 "type" => EFILE_IMAGE,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
151 "mime" => "image/jpeg",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
152 "fext" => "jpg",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
153 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
154 "GIF" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
155 "class" => EFILE_IMAGE,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
156 "type" => EFILE_IMAGE,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
157 "mime" => "image/gif",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
158 "fext" => "gif",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
159 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
160
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
161 "MP3" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
162 "class" => EFILE_AUDIO,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
163 "type" => EFILE_AUDIO,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
164 "mime" => "audio/mpeg",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
165 "fext" => "mp3",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
166 "test" => "MPEG ADTS, layer III",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
167 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
168 "OggVorbis" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
169 "class" => EFILE_AUDIO,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
170 "type" => EFILE_AUDIO,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
171 "mime" => "audio/ogg; codecs=vorbis",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
172 "fext" => "ogg",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
173 "test" => "Ogg data, Vorbis audio",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
174 ),
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
175 "FLAC" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
176 "class" => EFILE_AUDIO,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
177 "type" => EFILE_AUDIO,
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
178 "mime" => "audio/x-flac",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
179 "fext" => "flac",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
180 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
181 "WAV" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
182 "class" => EFILE_AUDIO,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
183 "type" => EFILE_AUDIO,
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
184 "mime" => "audio/x-wav",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
185 "fext" => "wav",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
186 ),
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
187
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
188 // Special cases
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
189 "ILBM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
190 "class" => EFILE_IMAGE,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
191 "mime" => "gfx", // Special cases to be converted through gfxconv ..
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
192 "fext" => "lbm",
936
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
193 "test" => "^IFF data, ILBM",
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
194 ),
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
195 "ANIM" => array(
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
196 "class" => EFILE_IMAGE,
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
197 "mime" => "image/x-anim", // Special cases to be converted through gfxconv ..
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
198 "fext" => "anim",
1a3af0ff70a4 Add ANIM type.
Matti Hamalainen <ccr@tnsp.org>
parents: 932
diff changeset
199 "test" => "^IFF data, ILBM",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
200 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
201 "PCX" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
202 "class" => EFILE_IMAGE,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
203 "mime" => "image/x-pcx",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
204 "fext" => "pcx",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
205 "test" => "^PCX ver\. 3\.0",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
206 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
207
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
208 "PTMOD" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
209 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
210 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
211 "fext" => "mod",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
212 "test" => "^\d+-channel Protracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
213 ),
937
Matti Hamalainen <ccr@tnsp.org>
parents: 936
diff changeset
214 "FTMOD" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
215 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
216 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
217 "fext" => "mod",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
218 "test" => "^\d+-channel Fasttracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
219 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
220 "S3M" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
221 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
222 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
223 "fext" => "s3m",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
224 "test" => "^ScreamTracker III Module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
225 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
226 "XM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
227 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
228 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
229 "fext" => "xm",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
230 "test" => "^Fasttracker II module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
231 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
232 "IT" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
233 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
234 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
235 "fext" => "it",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
236 "test" => "^Impulse Tracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
237 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
238 "PTM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
239 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
240 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
241 "fext" => "ptm",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
242 "test" => "^Poly Tracker PTM Module",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
243 ),
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
244
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
245 "AVI" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
246 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
247 "mime" => "video/x-msvideo",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
248 "fext" => "avi",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
249 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
250 "WMV" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
251 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
252 "mime" => "video/x-ms-asf",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
253 "fext" => "wmv",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
254 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
255 "MP4" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
256 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
257 "mime" => "video/mp4",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
258 "fext" => "mp4",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
259 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
260 "MOV" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
261 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
262 "mime" => "video/quicktime",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
263 "fext" => "mov",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
264 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
265 "MKV" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
266 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
267 "mime" => "video/x-matroska",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
268 "fext" => "mkv",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
269 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
270
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
271 // Archives
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
272 "LHA" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
273 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
274 "mime" => "application/x-lha",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
275 "fext" => "lha",
1049
03f4b70a2ce8 Add LHarc matching.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
276 "test" => "^LHarc 1\.x",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
277 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
278 "ZIP" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
279 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
280 "mime" => "application/zip",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
281 "fext" => "zip",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
282 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
283 "7ZIP" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
284 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
285 "mime" => "application/x-7z-compressed",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
286 "fext" => "7z",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
287 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
288 "RAR" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
289 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
290 "mime" => "application/x-rar",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
291 "fext" => "rar",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
292 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
293 "ARJ" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
294 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
295 "mime" => "application/x-arj",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
296 "fext" => "arj",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
297 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
298
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
299 // Final fallback
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
300 "MISC" => array(
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
301 "class" => EFILE_BINARY,
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
302 "mime" => "application/octet-stream",
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
303 "fext" => FALSE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
304 ),
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
305
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
306 "TEXT" => array(
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
307 "class" => EFILE_TEXT,
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
308 "mime" => "text/plain",
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
309 "fext" => FALSE,
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
310 ),
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
311 );
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
312
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
313
888
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
314 function stFileError($userID, $adminMsg, $userMsg)
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
315 {
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
316 stLogError($adminMsg);
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
317 stError(($userID === 0) ? $adminMsg : $userMsg);
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
318 return FALSE;
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
319 }
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
320
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
321
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
322 //
535
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
323 // Party infromation system data/variables handling
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
324 //
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
325 function stReloadDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
326 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
327 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
328
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
329 $displayVars = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
330 $displayVarsChanged = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
331
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
332 if (($res = stExecSQL("SELECT * FROM display_vars")) !== FALSE)
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
333 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
334 foreach ($res as $row)
354
1dd598221874 Simplify code by reusing functions from site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 307
diff changeset
335 $displayVars[$row["key"]] = stGetSQLSettingData($row);
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
336 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
337 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
338
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
339
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
340 function stSaveDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
341 {
144
c030c3cf0d80 More work on display system.
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
342 global $db, $displayVars, $displayVarsChanged;
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
343
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
344 foreach (stExecSQL("SELECT * FROM display_vars") as $item)
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
345 if (isset($displayVarsChanged[$item["key"]]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
346 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
347 $val = $displayVars[$item["key"]];
354
1dd598221874 Simplify code by reusing functions from site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 307
diff changeset
348 stExecSQL(
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
349 "UPDATE display_vars SET ".stGetSettingSQL($item, $val).
354
1dd598221874 Simplify code by reusing functions from site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 307
diff changeset
350 " WHERE key=".$db->quote($item["key"]));
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
351 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
352 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
353
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
354
407
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
355 function stDisplayUpdated()
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
356 {
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
357 stSetDisplayVar("lastUpdate", time());
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
358 }
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
359
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
360
454
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
361 function stSetDisplayVarUpd($name, $value)
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
362 {
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
363 if (stGetDisplayVar($name) != $value)
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
364 {
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
365 stSetDisplayVar($name, $value);
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
366 stDisplayUpdated();
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
367 return TRUE;
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
368 }
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
369 else
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
370 return FALSE;
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
371 }
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
372
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
373
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
374 function stGetDisplayVar($name)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
375 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
376 global $displayVars;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
377 if (isset($displayVars[$name]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
378 return $displayVars[$name];
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
379 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
380 die("No display var for '".$name."'.\n");
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
381 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
382
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
383
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
384 function stSetDisplayVar($name, $value)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
385 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
386 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
387 if (isset($displayVars[$name]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
388 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
389 $displayVars[$name] = $value;
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
390 $displayVarsChanged[$name] = TRUE;
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
391 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
392 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
393 die("No display var for '".$name."'.\n");
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
394 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
395
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
396
806
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
397 //
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
398 // Like stExecSQL(), but throws error messages to "userspace".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
399 //
484
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
400 function stExecSQLCond($sql, $msg = FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
401 {
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
402 global $db;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
403 if (($res = stDBExecSQL($db, $sql)) !== FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
404 {
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
405 if ($msg !== FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
406 stSetStatus(200, $msg);
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
407 return $res;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
408 }
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
409 else
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
410 {
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
411 stSetStatus(902, "Error in SQL execution.");
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
412 return FALSE;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
413 }
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
414 }
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
415
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
416
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
417 function stPrintAttendee($item, $row, $tr, $full, $edit, $eclass = "")
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
418 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
419 $id = $item["id"];
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
420 $prefix = "at";
677
64d80a7f7e26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 674
diff changeset
421
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
422 if ($tr)
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
423 {
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
424 echo
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
425 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven").$eclass.
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
426 "\" id=\"attendee".$id."\" ".($full ? "onClick=\"activateAttendee(".$id.")\"" : "").">";
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
427 }
677
64d80a7f7e26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 674
diff changeset
428
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
429 echo
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
430 stGetTDFormTextInput($edit, 20, SQL_LEN_USERNAME, "name", $id, $prefix, $item["name"]).
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
431 stGetTDFormTextInput($edit, 20, SQL_LEN_GROUPS, "groups", $id, $prefix, $item["groups"]).
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
432 "<td class=\"regtime\">".date("d.m. H:i", $item["regtime"])."</td>".
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
433 stGetTDFormTextInput($edit, 30, SQL_LEN_ONELINER, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\"");
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
434
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
435 if ($full)
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
436 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
437 echo
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
438 stGetTDFormTextInput($edit, 15, SQL_LEN_EMAIL, "email", $id, $prefix, $item["email"], "autocomplete=\"off\"").
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
439 stGetTDFormTextInput($edit, 15, SQL_LEN_REGHOST, "reghost", $id, $prefix, $item["reghost"], "autocomplete=\"off\"");
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
440
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
441 if ($edit)
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
442 {
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
443 echo
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
444 "<td>".
680
c9b96a7b9dc4 Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
445 stGetFormButtonElement($prefix."upd".$id, "","", "Upd", "updateAttendee(".$id.")").
c9b96a7b9dc4 Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
446 stGetFormButtonElement($prefix."del".$id, "","", "Del", "deleteAttendee(".$id.")").
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
447 "</td>";
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
448 }
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
449 else
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
450 echo "<td></td>";
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
451 }
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
452
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
453 if ($tr)
674
3e37a29468bf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 665
diff changeset
454 echo "</tr>\n";
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
455 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
456
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
457
222
b236b4d8d7a9 Remove useless code.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
458 function stPrintNewsItem($item)
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
459 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
460 echo
592
642df17214f6 Improve news item DOM IDs.
Matti Hamalainen <ccr@tnsp.org>
parents: 585
diff changeset
461 "<div class=\"newsItem\" id=\"news".$item["id"]."\">\n".
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
462 " <h2>".chentities($item["title"])."</h2>\n".
592
642df17214f6 Improve news item DOM IDs.
Matti Hamalainen <ccr@tnsp.org>
parents: 585
diff changeset
463 " <div class=\"newsText\">".dhentities($item["text"])."</div>\n".
593
3cceb9f13762 And some more tweaking.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
464 " <div class=\"newsAuthor\"><span class=\"newsSig\">-- ".chentities($item["author"])."</span>".
3cceb9f13762 And some more tweaking.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
465 "<span class=\"newsDate\">".date("d M Y / H:i", $item["utime"])."</span></div>\n".
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
466 "</div>\n";
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
467 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
468
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
469
806
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
470 function stGetTDFormTextInput($edit, $size, $len, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
471 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
472 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
473 "<td class=\"".$name."\">".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
474 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
475 "</td>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
476 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
477
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
478
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
479 function stGetEditFormTextInput($mode, $title, $size, $len, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
480 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
481 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
482 "<div class=\"editControl\"><span class=\"editControlTitle\">".chentities($title)."</span>".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
483 ($mode ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
484 "</div>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
485 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
486
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
487
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
488 function stGetEditFormTextArea($mode, $title, $rows, $cols, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
489 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
490 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
491 "<div class=\"editControl\"><span class=\"editControlTitle\">".chentities($title)."</span>".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
492 stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, ($mode ? "" : " disabled=\"disabled\" ").$extra).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
493 "</div>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
494 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
495
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
496
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
497 function stConvSwitchMode(&$str, &$mode, $newMode)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
498 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
499 if ($newMode != $mode)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
500 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
501 if ($mode != "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
502 $str .= "\n</".$mode.">\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
503
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
504 $mode = $newMode;
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
505
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
506 if ($mode != "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
507 $str .= "<".$mode.">\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
508 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
509 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
510
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
511
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
512 function stConvertCommonDesc($desc, $chent)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
513 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
514 $str = "";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
515 $mode = "";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
516
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
517 foreach (explode("\n", $desc) as $line)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
518 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
519 if (preg_match("/^\s*\s*\*(.+)$/", $line, $m))
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
520 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
521 stConvSwitchMode($str, $mode, "ol");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
522 $str .= "<li>".($chent ? chentities($m[1]) : $m[1])."</li>\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
523 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
524 else
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
525 if (preg_match("/^\s*-\s*(.+)$/", $line, $m))
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
526 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
527 stConvSwitchMode($str, $mode, "ul");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
528 $str .= "<li>".($chent ? chentities($m[1]) : $m[1])."</li>\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
529 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
530 else
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
531 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
532 stConvSwitchMode($str, $mode, "p");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
533 $str .= ($chent ? chentities($line) : $line);
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
534 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
535 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
536
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
537 stConvSwitchMode($str, $mode, "");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
538
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
539 return $str;
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
540 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
541
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
542
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
543 function stGetNumberSuffix($val)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
544 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
545 switch ($val)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
546 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
547 case 1: return "st";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
548 case 2: return "nd";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
549 case 3: return "rd";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
550 case 4: case 5: case 6:
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
551 case 7: case 8: case 9: return "th";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
552 default: return "th";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
553 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
554 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
555
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
556
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
557 function stGenerateUserKey()
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
558 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
559 global $db;
1089
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
560
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
561 // Default keychars
99
2169c3177f47 Limit the vote key character space even more.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
562 $keyChars = "abdefghjkmnpqrstwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
1089
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
563
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
564 if (($tmp = stGetSetting("userKeyChars", NULL)) !== NULL)
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
565 $keyChars = $tmp;
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
566
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
567 if (($tmp = stGetSetting("userKeyCase", NULL)) !== NULL)
00632d30bafe Implement new settings for making user/votekeys case-insensitive and
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
568 $keyChars = strtoupper($keyChars);
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
569
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
570 while (TRUE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
571 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
572 // Generate one randomized keycode
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
573 $key = "";
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
574 for ($n = 0; $n < stGetSetting("userKeyLength"); $n++)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
575 $key .= $keyChars[rand() % strlen($keyChars)];
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
576
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
577 // Check if it already exists, to avoid duplicates
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
578 // We need custom query code here, because stFetchSQLColumn()
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
579 // won't work due to it returning FALSE in error cases.
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
580 $sql = stPrepareSQL("SELECT * FROM userkeys WHERE key=%s", $key);
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
581 if (($res = @$db->query($sql)) !== FALSE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
582 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
583 // Did we get results?
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
584 if ($res->fetchColumn() === FALSE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
585 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
586 // Nope, return key
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
587 return $key;
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
588 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
589 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
590 else
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
591 {
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
592 stLogSQLError($sql);
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
593 return FALSE;
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
594 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
595 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
596 }
66
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
597
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
598
103
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
599 function stCheckRegistrationAvailable()
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
600 {
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
601 global $maxAttendeesHard, $maxAttendeesSoft, $numAttendees;
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
602
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
603 $maxAttendeesHard = stGetSetting("maxAttendeesHard");
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
604 $maxAttendeesSoft = stGetSetting("maxAttendeesSoft");
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
605 if (($numAttendees = stFetchSQLColumn("SELECT COUNT(*) FROM attendees")) === FALSE)
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
606 $numAttendees = 0;
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
607
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
608 return stChkSetting("allowRegister") && ($maxAttendeesHard <= 0 || $numAttendees < $maxAttendeesHard);
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
609 }
135
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
610
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
611
1014
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
612 function stCheckRequireEmail()
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
613 {
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
614 return stGetSetting("requireEMail");
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
615 }
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
616
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
617
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
618 function stValidateRequestUserData($admin, $id = FALSE)
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
619 {
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
620 $res = TRUE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
621 $chk = 0;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
622
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
623 if (stChkRequestItem("name", $name,
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
624 array(CHK_ISGT, VT_STR, 0, "Handle / name not given."),
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
625 array(CHK_LTEQ, VT_STR, SQL_LEN_USERNAME, "Handle / name is too long, should be less than ".SQL_LEN_USERNAME." characters.")))
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
626 $chk++;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
627 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
628 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
629
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
630 if (stChkRequestItem("groups", $groups,
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
631 array(CHK_LTEQ, VT_STR, SQL_LEN_GROUPS, "Groups are too long, should be less than ".SQL_LEN_GROUPS." characters.")))
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
632 $chk++;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
633 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
634 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
635
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
636 if (!stChkRequestItem("oneliner", $oneliner,
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
637 array(CHK_LTEQ, VT_STR, SQL_LEN_ONELINER, "Oneliner is too long, should be less than ".SQL_LEN_ONELINER." characters.")))
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
638 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
639
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
640 $email = stGetRequestItem("email");
1014
87eda2e9023f Back out the stValidateRequestUserData() parameter change, use separate
Matti Hamalainen <ccr@tnsp.org>
parents: 1012
diff changeset
641 if (!$admin && stCheckRequireEmail() && strlen($email) < 4)
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
642 {
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
643 stError("E-mail address not given, or it is too short.");
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
644 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
645 }
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
646
605
f928b0a6e1af Better validation for e-mail addresses.
Matti Hamalainen <ccr@tnsp.org>
parents: 598
diff changeset
647 if (strlen($email) > 0 && preg_match("/^[a-z0-9][a-z0-9\+\-\.\%_]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $email) != 1)
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
648 {
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
649 stError("E-mail address not in proper format.");
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
650 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
651 }
1015
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
652 else
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
653 if (strlen($email) > SQL_LEN_EMAIL)
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
654 {
1114
51f24cb35fc8 s/SET_LEN_/SQL_LEN_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
655 stError("E-mail address too long, max ".SQL_LEN_EMAIL." characters.");
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
656 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
657 }
1015
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
658 else
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
659 if (strlen($email) > 0)
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
660 {
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
661 if ($id !== FALSE)
1015
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
662 // By another ID, if we are updating an entry
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
663 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND email=%s", $id, $email);
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
664 else
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
665 // Or just exists, if adding
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
666 $sql = stPrepareSQL("SELECT * FROM attendees WHERE email=%s", $email);
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
667
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
668 if (($data = stFetchSQL($sql)) !== FALSE)
1015
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
669 {
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
670 stError("Someone with the same e-mail address is already registered.");
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
671 $res = FALSE;
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
672 }
6e8ae77e1a25 Add better checks for e-mails.
Matti Hamalainen <ccr@tnsp.org>
parents: 1014
diff changeset
673 }
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
674
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
675 // Check if another user already exists
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
676 if ($chk >= 2)
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
677 {
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
678 if ($id !== FALSE)
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
679 // By another ID, if we are updating an entry
647
60b51ab059da Oops, forgot an AND from one SQL clause.
Matti Hamalainen <ccr@tnsp.org>
parents: 646
diff changeset
680 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND name=%s AND groups=%s", $id, $name, $groups);
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
681 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
682 // Or just exists, if adding
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
683 $sql = stPrepareSQL("SELECT * FROM attendees WHERE name=%s AND groups=%s", $name, $groups);
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
684
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
685 if (($data = stFetchSQL($sql)) !== FALSE)
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
686 {
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
687 stError("Someone with the same name and groups is already registered.");
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
688 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
689 }
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
690 }
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
691 return $res;
648
9e4b8df65879 Oops, fix a 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 647
diff changeset
692
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
693 }
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
694
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
695
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
696 function stGetCompoResultsSQL($mode, $compo, $flags)
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
697 {
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
698 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
699 // Act based on competition type
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
700 //
640
c78e11aa3162 Rename a database field, so that it does not conflict with AJAX request item
Matti Hamalainen <ccr@tnsp.org>
parents: 637
diff changeset
701 switch ($compo["ctype"])
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
702 {
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
703 case COMPO_NORMAL:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
704 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
705 // "Normal" competition, where results are somehow
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
706 // based on points / voting.
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
707 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
708 switch ($mode)
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
709 {
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
710 case VOTE_FREELY:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
711 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
712 "SELECT entries.*,SUM(votes.value) AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
713 "FROM entries ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
714 "LEFT JOIN votes ON votes.entry_id=entries.id";
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
715 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
716
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
717 case VOTE_ACTIVATE:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
718 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
719 "SELECT entries.*, ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
720 "(SELECT SUM(votes.value) FROM votes ".
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
721 "LEFT JOIN userkeys ON votes.key_id=userkeys.id ".
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
722 "WHERE votes.entry_id=entries.id AND userkeys.active<>0) ".
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
723 "AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
724 "FROM entries";
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
725 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
726
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
727 case VOTE_ASSIGN:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
728 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
729 "SELECT entries.*, ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
730 "(SELECT SUM(votes.value) FROM votes ".
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
731 "LEFT JOIN userkeys ON votes.key_id=userkeys.id ".
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
732 "LEFT JOIN attendees ON userkeys.id=attendees.key_id ".
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
733 "WHERE votes.entry_id=entries.id AND attendees.key_id<>0) ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
734 "AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
735 "FROM entries";
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
736 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
737 }
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
738
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
739 $extra =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
740 "GROUP BY entries.id ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
741 "ORDER BY votesum DESC";
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
742 break;
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
743
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
744 case COMPO_POINTS:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
745 //
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
746 // Points ..
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
747 //
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
748 $sql = "SELECT entries.*,entries.evalue AS votesum FROM entries";
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
749 $extra = "ORDER BY entries.evalue DESC";
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
750 break;
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
751
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
752 case COMPO_ASSIGN:
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
753 //
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
754 // Ascending
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
755 //
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
756 $sql = "SELECT entries.*,entries.evalue AS votesum FROM entries";
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
757 $extra = "ORDER BY entries.evalue ASC";
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
758 break;
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
759 }
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
760
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
761 return $sql." ".
606
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
762 "WHERE entries.compo_id=".$compo["id"]." ".
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
763 (($flags & RFLAG_DISQUALIFIED) ? "" : "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0 ").
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
764 $extra;
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
765 }
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
766
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
767
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
768 function stGetCompoResults($flags)
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
769 {
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
770 $userKeyMode = stGetSetting("userKeyMode");
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
771 $out = array();
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
772 $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC";
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
773 if (($res = stExecSQL($sql)) === FALSE)
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
774 return $out;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
775
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
776 // For each compo that has been set visible
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
777 foreach ($res as $compo)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
778 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
779 // Check if there are any entries for it
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
780 $sql =
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
781 "SELECT COUNT(*) FROM entries ".
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
782 "WHERE compo_id=".$compo["id"].
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
783 (($flags & RFLAG_DISQUALIFIED) ? "" : " AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0");
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
784
798
b97d4b754bc0 Show also empty compos with RFLAG_HIDDEN_COMPOS.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
785 if (($nentries = stFetchSQLColumn($sql)) !== FALSE &&
b97d4b754bc0 Show also empty compos with RFLAG_HIDDEN_COMPOS.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
786 ($nentries > 0 || ($flags & RFLAG_HIDDEN_COMPOS)))
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
787 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
788 // Get voting results by mode
1092
95b74632cfe2 Rename votekeys table to userkeys, and all related variables and settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1089
diff changeset
789 $sql = stGetCompoResultsSQL($userKeyMode, $compo, $flags);
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
790
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
791 $out[$compo["id"]] = $compo;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
792 $out[$compo["id"]]["results"] = array();
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
793 $prev = FALSE;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
794 $index = 0;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
795
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
796 foreach (stExecSQL($sql) as $entry)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
797 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
798 if ($entry["votesum"] !== $prev)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
799 $index++;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
800
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
801 $entry["position"] = $index;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
802 $out[$compo["id"]]["results"][] = $entry;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
803
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
804 $prev = $entry["votesum"];
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
805 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
806 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
807 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
808
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
809 return $out;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
810 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
811
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
812
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
813 function stGetCompoResultLine($html, $entry, $points, $showAuthor)
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
814 {
965
d5f3a505c73c Make results a bit wider.
Matti Hamalainen <ccr@tnsp.org>
parents: 962
diff changeset
815 $name = stStrChopPad($entry["name"], 40);
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
816 $author = stStrChopPad($entry["author"], 30);
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
817
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
818 $out = sprintf(" %s", $html ? chentities($name) : $name);
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
819
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
820 // Author?
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
821 if ($showAuthor)
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
822 $out .= sprintf(" by %s", $html ? chentities($author) : $author);
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
823
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
824 // Points?
698
3f322be347d6 Fix the results display.
Matti Hamalainen <ccr@tnsp.org>
parents: 697
diff changeset
825 if ($points !== FALSE)
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
826 $out .= sprintf(" (%d pts)", $points);
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
827
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
828 // Add disqualified flag etc.
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
829 if ($entry["flags"] & EFLAG_DISQUALIFIED)
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
830 $out .= " [DISQ]";
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
831
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
832 return $out."\n";
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
833 }
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
834
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
835
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
836 function stGetCompoResultsASCIIStr($html, $flags)
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
837 {
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
838 $out = "";
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
839 foreach (stGetCompoResults($flags) as $compo)
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
840 {
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
841 // Output compo title / header
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
842 if ($html)
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
843 {
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
844 $out .=
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
845 "<pre>\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
846 "<b> ".chentities($compo["name"])." </b>\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
847 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
848 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
849 else
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
850 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
851 $out .=
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
852 " ".$compo["name"]."\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
853 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
854 }
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
855
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
856 // List results for this compo
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
857 $prev = FALSE;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
858 foreach ($compo["results"] as $entry)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
859 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
860 if ($entry["position"] !== $prev)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
861 $out .= sprintf("%3d%s.", $entry["position"], stGetNumberSuffix($entry["position"]));
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
862 else
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
863 $out .= " -''-";
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
864
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
865 $out .= stGetCompoResultLine($html, $entry,
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
866 ($compo["ctype"] != COMPO_ASSIGN) ? $entry["votesum"] : FALSE,
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
867 ($compo["ctype"] != COMPO_NORMAL) ? $compo["show_authors"] : TRUE);
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
868
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
869 $prev = $entry["position"];
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
870 }
979
678b44a20e1a Implement rest of notes.
Matti Hamalainen <ccr@tnsp.org>
parents: 977
diff changeset
871 $out .=
678b44a20e1a Implement rest of notes.
Matti Hamalainen <ccr@tnsp.org>
parents: 977
diff changeset
872 "\n".($compo["notes"] != "" ? "NOTES: ".chentities($compo["notes"])."\n" : "").
678b44a20e1a Implement rest of notes.
Matti Hamalainen <ccr@tnsp.org>
parents: 977
diff changeset
873 "\n".($html ? "</pre>\n" : "");
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
874 }
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
875
511
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
876 return $out;
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
877 }
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
878
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
879
716
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
880 function stGetAttendeeRegistrationSQL()
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
881 {
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
882 return stPrepareSQL(
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
883 "INSERT INTO attendees (regtime,name,groups,oneliner,email,reghost) VALUES (%d,%S,%S,%S,%S,%s)",
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
884 time(), "name", "groups", "oneliner", "email", $_SERVER["REMOTE_ADDR"]);
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
885 }
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
886
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
887
819
a431fc8a2b9a Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
888 //
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
889 // Filter a path or filename component string
819
a431fc8a2b9a Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
890 //
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
891 function stFilterPathComponent($str)
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
892 {
918
2e106ba14190 More adjustments.
Matti Hamalainen <ccr@tnsp.org>
parents: 915
diff changeset
893 $tmp = str_replace(array(" / ", "/", "\$", ), array(" of ", " of ", "S", ), $str);
915
a6b4b7401508 Improve path component filtering.
Matti Hamalainen <ccr@tnsp.org>
parents: 914
diff changeset
894 return preg_replace("/[^a-zA-Z0-9\(\)\,\._-]/", "_", $tmp);
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
895 }
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
896
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
897
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
898 //
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
899 // Replace or add filename extension
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
900 //
885
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
901 function stReplaceFileExt($filename, $fext = FALSE)
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
902 {
885
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
903 if ($fext === FALSE)
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
904 return $filename;
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
905
961
d0c49745f27f Possible fix for certain things!
Matti Hamalainen <ccr@tnsp.org>
parents: 960
diff changeset
906 $dpos = strrpos($filename, "/");
d0c49745f27f Possible fix for certain things!
Matti Hamalainen <ccr@tnsp.org>
parents: 960
diff changeset
907 if (($spos = strrpos($filename, ".")) !== FALSE &&
962
b61c0e7eb52e Bugfix.
Matti Hamalainen <ccr@tnsp.org>
parents: 961
diff changeset
908 ($dpos === FALSE || $dpos < $spos))
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
909 return substr($filename, 0, $spos).$fext;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
910 else
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
911 return $filename.$fext;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
912 }
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
913
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
914
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
915 //
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
916 // Create a path, or URL from specified components
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
917 //
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
918 function stMakePath($isURL, $hasFilename, $components)
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
919 {
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
920 $res = array();
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
921
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
922 // If this is URL, the first component is passed as is
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
923 if ($isURL)
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
924 {
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
925 $res[] = array_shift($components);
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
926 $first = FALSE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
927 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
928 else
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
929 $first = TRUE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
930
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
931 // Handle each path component
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
932 if (count($components) > 0)
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
933 {
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
934 for ($i = 0; $i < count($components); $i++)
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
935 foreach (explode("/", $components[$i]) as $item)
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
936 {
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
937 if ($item == "..")
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
938 array_pop($res);
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
939 else
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
940 if ($item != "." && ($item != "" || $first))
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
941 $res[] = stFilterPathComponent($item);
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
942 $first = FALSE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
943 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
944 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
945
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
946 return implode("/", $res);
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
947 }
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
948
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
949
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
950 function stGetEntryPreviewFile($entry, $compo, $previewPath, $previewURL, $type, $addPath)
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
951 {
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
952 global $fileTypeData;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
953 if (!isset($fileTypeData[$type]))
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
954 die("Invalid file type: ".$type);
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
955
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
956 $fileBase = sprintf("%03d.%s", $entry["id"], $fileTypeData[$type]["fext"]);
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
957 $fileName = stMakePath(FALSE, TRUE, array($previewPath, $compo["cpath"], $addPath, $fileBase));
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
958
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
959 return array(
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
960 "type" => $type,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
961 "mime" => $fileTypeData[$type]["mime"],
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
962 "file" => $fileName,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
963 "exists" => @file_exists($fileName),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
964 "mtime" => @filemtime($fileName),
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
965 "url" => stMakePath(TRUE, TRUE, array($previewURL, $compo["cpath"], $addPath, $fileBase)),
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
966 );
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
967 }
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
968
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
969
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
970 function stGetPreviewFileData($compo, $entry, &$pdata)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
971 {
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
972 global $fileTypeData;
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
973
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
974 if ($compo === FALSE || $entry === FALSE)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
975 return FALSE;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
976
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
977 $previewPath = stGetSetting("previewPath");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
978 $previewURL = stGetSetting("previewURL");
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
979 $pdata = array(
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
980 "type" => $compo["preview_type"],
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
981 "valid" => TRUE,
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
982 "exists" => 0,
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
983 "files" => array(),
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
984 );
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
985
897
d8fa2aecadcc Optimize slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 896
diff changeset
986 if ($entry["preview_id"] != 0 &&
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
987 ($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) !== FALSE)
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
988 {
897
d8fa2aecadcc Optimize slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 896
diff changeset
989 $pdata["file"] = $efile;
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
990 if (isset($fileTypeData[$efile["filetype"]]["type"]))
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
991 $pdata["type"] = $fileTypeData[$efile["filetype"]]["type"];
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
992 }
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
993 else
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
994 if ($entry["file_id"] == 0)
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
995 $pdata["valid"] = $efile = FALSE;
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
996
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
997 switch ($pdata["type"])
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
998 {
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
999 case EFILE_IMAGE:
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1000 $pdata["files"]["image"] = stGetEntryPreviewFile(
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1001 $entry, $compo, $previewPath, $previewURL,
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1002 stGetSetting("previewImageType"), "");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1003
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1004 $pdata["files"]["thumb"] = stGetEntryPreviewFile(
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1005 $entry, $compo, $previewPath, $previewURL,
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1006 stGetSetting("previewThumbType"),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1007 stGetSetting("thumbnailSubDir"));
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1008 break;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1009
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
1010 case EFILE_AUDIO:
895
878e3bd6f385 Moar fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 894
diff changeset
1011 foreach (stGetSetting("sampleTypes") as $type => $fdata)
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1012 {
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1013 $pdata["files"][$type] = stGetEntryPreviewFile(
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1014 $entry, $compo, $previewPath, $previewURL,
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1015 $type, "");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1016 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1017 break;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1018
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1019 default:
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1020 return FALSE;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1021 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1022
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
1023 foreach ($pdata["files"] as $pkey => $pfile)
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1024 {
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
1025 if ($pfile["exists"])
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
1026 $pdata["exists"]++;
894
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1027
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
1028 if (!$pfile["exists"])//
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
1029 $pdata["valid"] = FALSE;
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1030 }
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1031
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1032 return TRUE;
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1033 }
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1034
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1035
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1036 function stPrintPreviewElements($compo, $entry)
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1037 {
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1038 if (!stGetPreviewFileData($compo, $entry, $pdata))
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1039 return FALSE;
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1040
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1041 switch ($pdata["type"])
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1042 {
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
1043 case EFILE_IMAGE:
911
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1044 if ($pdata["exists"] >= 2)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1045 {
911
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1046 if ($pdata["valid"])
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1047 {
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1048 echo
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1049 "<a href=\"".ihentities($pdata["files"]["image"]["url"]).
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1050 "\" onClick=\"return jsShowPreviewImage('".ihentities($pdata["files"]["image"]["url"])."');\">".
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1051 "<img class=\"imagePreview\" src=\"".ihentities($pdata["files"]["thumb"]["url"]).
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1052 "\" alt=\"Preview\" /></a>";
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1053 }
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1054 else
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1055 {
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1056 echo
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1057 "<img class=\"imagePreview\" src=\"".stGetSetting("previewNoImage")."\" alt=\"Preview\" />";
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1058 }
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1059 }
894
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1060 else
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1061 {
911
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1062 echo "<div class=\"noPreview\">No preview</div>";
894
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1063 }
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1064 break;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1065
896
52737f6192bb More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 895
diff changeset
1066 case EFILE_AUDIO:
932
0c1ab858a3c5 Adjust preview file validity logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
1067 if ($pdata["valid"])
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1068 {
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1069 echo "<audio controls preload=\"none\" class=\"audioPreview\">";
891
86ebd378af95 Modularize again.
Matti Hamalainen <ccr@tnsp.org>
parents: 890
diff changeset
1070 foreach ($pdata["files"] as $pkey => $pfile)
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1071 {
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1072 echo "<source src=\"".ihentities($pfile["url"])."\" type=\"".$pfile["mime"]."\">";
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1073 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1074 echo "</audio>";
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1075 }
894
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1076 else
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1077 {
911
f007b3081872 Adjust preview showing.
Matti Hamalainen <ccr@tnsp.org>
parents: 910
diff changeset
1078 echo "<div class=\"noPreview\">No preview</div>";
894
a8fe46a555be Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 892
diff changeset
1079 }
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1080 break;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1081 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1082 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1083
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1084
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1085 //
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1086 // Probe file type information
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1087 //
952
ef0d8615ec06 Add silent option to stProbeFileInfo()
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
1088 function stProbeFileInfo($filename, $silent = FALSE)
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1089 {
840
3b9ccc10c9a0 Few 10L's
Matti Hamalainen <ccr@tnsp.org>
parents: 839
diff changeset
1090 global $fileTypeData;
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1091
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1092 // Get file magic info
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1093 if (($finfo = finfo_open()) === FALSE)
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1094 {
874
ffb5643eff4f Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
1095 stLogError("Internal error. Failed to initialize finfo().");
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1096 return stError("Internal error, failed to probe file.");
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1097 }
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1098
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1099 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1100 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1101 finfo_close($finfo);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1102
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1103 // Did we get anything?
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1104 if ($sdata === FALSE || $smime === FALSE)
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1105 {
874
ffb5643eff4f Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
1106 stLogError("Failed to probe file '".$filename."'.");
952
ef0d8615ec06 Add silent option to stProbeFileInfo()
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
1107 return stError("Failed to probe file.");
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1108 }
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1109
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1110 // Match through our supported types ..
840
3b9ccc10c9a0 Few 10L's
Matti Hamalainen <ccr@tnsp.org>
parents: 839
diff changeset
1111 foreach ($fileTypeData as $fid => $fdata)
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1112 {
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1113 $fdata["id"] = $fid;
914
d42c398d8896 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
1114 if (isset($fdata["test"]) && preg_match("/".$fdata["test"]."/", $sdata))
d42c398d8896 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
1115 return $fdata;
924
22ca7b1aaff4 Fix fileinfo probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 918
diff changeset
1116 }
22ca7b1aaff4 Fix fileinfo probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 918
diff changeset
1117
22ca7b1aaff4 Fix fileinfo probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 918
diff changeset
1118 // Fall back to mime types
22ca7b1aaff4 Fix fileinfo probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 918
diff changeset
1119 foreach ($fileTypeData as $fid => $fdata)
22ca7b1aaff4 Fix fileinfo probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 918
diff changeset
1120 {
957
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
1121 $fdata["id"] = $fid;
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1122 if ($fdata["mime"] == $smime)
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1123 return $fdata;
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1124 }
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1125
952
ef0d8615ec06 Add silent option to stProbeFileInfo()
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
1126 if ($silent)
ef0d8615ec06 Add silent option to stProbeFileInfo()
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
1127 return FALSE;
ef0d8615ec06 Add silent option to stProbeFileInfo()
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
1128
914
d42c398d8896 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
1129 stLogError("File '".$filename."' (".$smime.") did not match any defined file types [".$sdata."].");
d42c398d8896 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
1130 return stError("No matching defined file type found for '".$smime."'.");
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1131 }
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1132
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1133
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1134 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1135 // File table entry adding
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1136 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1137 function stAddFileEntry($entry, $type, $origName, $fileSize, $fileExt, $fileType, $uploaderID)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1138 {
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1139 $field = (($type == "preview") ? "preview" : "file")."_id";
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1140
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1141 // Create new file entry
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1142 $sql = stPrepareSQL(
872
5e9958f78b16 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1143 "INSERT INTO files (origname,filetype,filesize,entry_id,uploader_id,uploadtype,utime) ".
892
c036db2c64a7 Add missing SQL insert parameter. 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
1144 "VALUES (%s,%s,%d,%d,%d,%s,%d)",
872
5e9958f78b16 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1145 $origName, $fileType, $fileSize, $entry["id"], $uploaderID, $type, time());
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1146
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1147 if (($fileID = stExecSQLInsert($sql)) === FALSE)
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1148 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1149 "Failed to add new ".$type." file for entry #".$entry["id"]." '".$origName."'.",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1150 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1151
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1152 // Compute storage filename
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1153 $fileName = sprintf("%03d-%s--%s%s_(%d).%s",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1154 $entry["id"],
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1155 stFilterPathComponent($entry["author"]),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1156 stFilterPathComponent($entry["name"]),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1157 ($type == "preview" ? "_preview" : ""),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1158 $fileID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1159 $fileExt);
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1160
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1161 // Update entry with generated filename
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1162 $sql = stPrepareSQL("UPDATE files SET filename=%s WHERE id=%d", $fileName, $fileID);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1163 if (stExecSQL($sql) === FALSE)
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1164 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1165 "Failed to update newly created files entry #".$fileID." with generated filename '".$fileName."'!",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1166 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1167
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1168 // Update entry's reference
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1169 $sql = stPrepareSQL("UPDATE entries SET ".$field."=%d WHERE id=%d", $fileID, $entry["id"]);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1170 if (stExecSQL($sql) === FALSE)
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1171 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1172 "Failed to update entry #".$entry["id"]." ".$type." ID!",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1173 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1174
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1175 // Return file entry
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1176 if (($res = stFetchSQL("SELECT * FROM files WHERE id=".$fileID)) === FALSE)
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1177 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1178 "Failed to fetch newly generated files entry #".$fileID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1179 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1180
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1181 return $res;
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1182 }
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1183
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1184
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1185 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1186 // File upload handling
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1187 //
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1188 function stHandleGenericFileUpload($userID)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1189 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1190 global $errorSet;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1191
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1192 // Check basics
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1193 if (!stChkRequestItem("type", $uploadType,
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1194 array(CHK_TYPE, VT_STR, "Invalid upload type."),
910
8abd4a908098 Add type into message.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1195 array(CHK_ARRAY_VAL, array("entry", "preview"), "Invalid upload type class '%1'."))
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1196 ||
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1197 !stChkRequestItem("entry_id", $entryID,
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1198 array(CHK_TYPE, VT_INT, "Invalid entry ID.")))
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1199 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1200
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1201 // Check entry existence
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1202 if (($entry = stFetchSQL("SELECT * FROM entries WHERE id=".$entryID)) === FALSE)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1203 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1204 "Entry ID #".$entryID." does not exist in the entries table?",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1205 "Entry does not exist??");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1206
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1207 if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$entry["compo_id"])) === FALSE)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1208 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1209 "Compo ID #".$entry["compo_id"]." in entry ID #".$entryID." does not exist!",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1210 "Compo does not exist??");
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1211
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1212 // Check target path existence / writability
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
1213 $dstPath = stMakePath(FALSE, FALSE, array(stGetSetting("entryPath"), $compo["cpath"]));
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1214 if (!file_exists($dstPath))
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1215 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1216 "Path '".$dstPath."' for compo ID #".$entry["compo_id"]." does not exist.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1217 "The directory for entry's compo does not exist!");
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1218
866
db9810510670 s/fileperm(/fileperms(/ :S
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
1219 $dstPerms = fileperms($dstPath);
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1220 if (($dstPerms & 0x4000) === 0)
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1221 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1222 "Path for entry's compo '".$dstPath."' is not a directory.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1223 "Path for entry's compo is not a directory?");
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1224
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1225 $needPerms = 0x0100 | 0x0080 | 0x0040;
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1226 if (($dstPerms & $needPerms) !== $needPerms)
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1227 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1228 "Path for entry's compo '".$dstPath."' does not have sufficient permissions.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1229 "Path for entry's compo has no sufficient permissions.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1230
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1231 // Check permissions for non-admins
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1232 if ($userID != 0)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1233 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1234 // Check if the user even exists, just in case
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1235 if (($user = stFetchSQL("SELECT * FROM attendees WHERE id=".$userID)) === FALSE)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1236 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1237 "User ID #".$userID." does not exist??",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1238 "You do not exist. Go away.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1239
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1240 if ($entry["owner_id"] != $userID)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1241 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1242 "User ID #".$userID." attempted to upload file to an entry that is not owned by him (@ ".$_SERVER["REMOTE_ADDR"].")",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1243 "Attempted to upload file to entry not owned by user.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1244 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1245
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1246 // Check file status data
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1247 $maxFileSize = stGetSetting($uploadType."MaxSize");
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1248
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1249 $index = $uploadType."ToUpload".$entryID;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1250 $fileSize = $_FILES[$index]["size"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1251 $tmpFilename = $_FILES[$index]["tmp_name"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1252 $orgFilename = $_FILES[$index]["name"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1253
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1254 if ($fileSize > $maxFileSize)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1255 stError("File size ".$fileSize." exceeds FAPWeb's size of ".$maxFileSize." bytes for ".$uploadType." uploads.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1256
959
1b95dcd0b566 Be more lenient about minimum size of uploaded files.
Matti Hamalainen <ccr@tnsp.org>
parents: 957
diff changeset
1257 if ($fileSize < 16)
1b95dcd0b566 Be more lenient about minimum size of uploaded files.
Matti Hamalainen <ccr@tnsp.org>
parents: 957
diff changeset
1258 stError("File size ".$fileSize." is less than 16 bytes. This can't be right.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1259
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1260 switch ($_FILES[$index]["error"])
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1261 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1262 case UPLOAD_ERR_INI_SIZE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1263 stError("File size exceeds PHP's max upload size.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1264 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1265
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1266 case UPLOAD_ERR_PARTIAL:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1267 stError("File only partially uploaded.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1268 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1269
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1270 case UPLOAD_ERR_NO_FILE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1271 stError("No file data received!");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1272 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1273
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1274 case UPLOAD_ERR_NO_TMP_DIR:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1275 stError("Internal error: Temporary file directory not available!");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1276 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1277
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1278 case UPLOAD_ERR_CANT_WRITE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1279 stError("Internal error: PHP could not write the file to disk.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1280 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1281
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1282 case UPLOAD_ERR_OK:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1283 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1284
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1285 default:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1286 stError("Unknown PHP file error occured.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1287 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1288 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1289
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1290 if ($errorSet)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1291 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1292
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1293
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1294 // Check file properties ..
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1295 if (($fileInfo = stProbeFileInfo($tmpFilename)) === FALSE)
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1296 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1297
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1298 if ($uploadType == "preview" && !isset($fileInfo["type"]))
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1299 return stError("Preview file upload is not one of the supported preview file types.");
841
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1300
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1301 // Get original extension
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1302 if (($fileExt = $fileInfo["fext"]) === FALSE)
841
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1303 {
960
af501f585941 Minor fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 959
diff changeset
1304 $fileExt = "bin";
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1305 if (($epos = strrpos($orgFilename, ".")) !== FALSE)
960
af501f585941 Minor fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 959
diff changeset
1306 $fileExt = substr($orgFilename, $epos + 1);
841
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1307 }
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1308
852
5eda5f9c7437 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 848
diff changeset
1309 // Update current or add new file entry
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1310 if (($fentry = stAddFileEntry($entry, $uploadType, $orgFilename, $fileSize, $fileExt, $fileInfo["id"], $userID)) === FALSE)
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1311 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1312
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1313 // Set permissions before moving the file
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1314 if (chmod($tmpFilename, stGetSetting($uploadType."PathPerms")) === FALSE)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1315 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1316 "Could not set permissions for uploaded file '".$tmpFilename."'.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1317 "Internal error. Could not set permissions for uploaded file. Contact site admins.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1318
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1319 // Move file to its destination
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
1320 $dstFilename = stMakePath(FALSE, TRUE, array(stGetSetting("entryPath"), $compo["cpath"], $fentry["filename"]));
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1092
diff changeset
1321 if (@move_uploaded_file($tmpFilename, $dstFilename) === FALSE)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1322 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1323 "Could not move uploaded file '".$tmpFilename."' to '".$dstFilename."'.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1324 "Internal error. Deploying uploaded file failed! Contact site admins.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1325
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1326 return TRUE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1327 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1328
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1329
797
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1330 function stNormalizeListSlideOrder($list_id)
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1331 {
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1332 }
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1333
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1334
1029
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1335 function stAddCompoEntry($compo, $uid)
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1336 {
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1337 switch ($compo["ctype"])
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1338 {
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1339 case COMPO_NORMAL:
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1340 $sql = stPrepareSQL(
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1341 "INSERT INTO entries (name,author,compo_id,info,notes,preview_type,utime,owner_id) VALUES (%S,%S,%d,%Q,%Q,%D,%d,%d)",
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1342 "name", "author", $compo["id"], "info", "notes", "preview_type", time(), $uid);
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1343 break;
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1344
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1345 case COMPO_POINTS:
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1346 case COMPO_ASSIGN:
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1347 $sql = stPrepareSQL(
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1348 "INSERT INTO entries (name,compo_id,notes,evalue,utime,owner_id) VALUES (%S,%d,%Q,%D,%d,%d)",
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1349 "name", $compo["id"], "notes", "evalue", time(), $uid);
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1350 break;
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1351 }
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1352
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1353 return stExecSQLCond($sql, "OK, entry added.");
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1354 }
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1355
35a00a986f79 Factorize compo entry adding into stAddCompoEntry().
Matti Hamalainen <ccr@tnsp.org>
parents: 1015
diff changeset
1356
1032
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1357 function stDeleteCompoEntry($id)
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1358 {
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1359 // Delete entry itself
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1360 $sql = stPrepareSQL("DELETE FROM entries WHERE id=%d", $id);
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1361 stExecSQLCond($sql, "OK, entry ".$id." deleted.");
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1362
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1363 // Delete votes for the entry
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1364 $sql = stPrepareSQL("DELETE FROM votes WHERE entry_id=%d", $id);
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1365 stExecSQLCond($sql, "OK, entry ".$id." votes deleted.");
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1366
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1367 // Mark related files to be deleted
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1368 $sql = stPrepareSQL("UPDATE files SET deleted=%d WHERE entry_id=%d", 1, $id);
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1369 stExecSQLCond($sql, "OK, entry ".$id." files marked.");
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1370 }
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1371
9fffc9e7e1b6 Add stDeleteCompoEntry() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
1372
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1373 ?>