annotate msite.inc.php @ 889:0fbf63bbb8f4

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Nov 2014 19:14:09 +0200
parents e0903d0c3954
children d6548ad68134
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?
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
565
ed2247111fdd Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 558
diff changeset
5 // (C) Copyright 2012-2014 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.
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
17 define("SET_LEN_USERNAME", 32);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
18 define("SET_LEN_GROUPS", 64);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
19 define("SET_LEN_ONELINER", 64);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
20 define("SET_LEN_EMAIL", 80);
716
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
21 define("SET_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
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
23 define("SET_LEN_NEWS_TITLE", 128);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
24 define("SET_LEN_NEWS_TEXT", 4096);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
25 define("SET_LEN_NEWS_AUTHOR", 64);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
26
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
27 define("SET_LEN_COMPO_NAME", 128);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
28 define("SET_LEN_COMPO_DESC", 4096);
533
f872843ae396 Add file path to compo data.
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
29 define("SET_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
30
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
31 define("SET_LEN_ENTRY_NAME", 64);
1b30c2107e5b Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
32 define("SET_LEN_ENTRY_AUTHOR", 64);
526
e074775d853e Make filename field shorter.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
33 define("SET_LEN_ENTRY_FILENAME", 128);
796
589cb2d88332 Make entry info field shorter.
Matti Hamalainen <ccr@tnsp.org>
parents: 792
diff changeset
34 define("SET_LEN_ENTRY_INFO", 40*3);
527
d6726a4883a6 Add "notes" field for entries, to contain notes private to organizers.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
35 define("SET_LEN_ENTRY_NOTES", 1024);
528
dd5c5577c495 Add preview file and file type fields for entry, for screenshots etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
36 define("SET_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
37
506
d29166d97b46 Change some database field sizes.
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
38 define("SET_LEN_DISP_SLIDE_TITLE", 64);
420
e9f6e242c4b9 Define some more SQL field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
39 define("SET_LEN_DISP_SLIDE_TEXT", 4096);
e9f6e242c4b9 Define some more SQL field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
40 define("SET_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
41
503
3232f682f0d2 Change how table schemas are defined, in preparation for future database
Matti Hamalainen <ccr@tnsp.org>
parents: 491
diff changeset
42 define("SET_LEN_VOTEKEY", 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
43
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 //
702
c527b42a7857 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
46 // Entry preview type (value)
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
47 //
700
d0418af28559 Add EPREV_NONE define.
Matti Hamalainen <ccr@tnsp.org>
parents: 699
diff changeset
48 define("EPREV_NONE", 0); // No preview
528
dd5c5577c495 Add preview file and file type fields for entry, for screenshots etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
49 define("EPREV_IMAGE", 1); // Preview is image (PNG, JPEG)
700
d0418af28559 Add EPREV_NONE define.
Matti Hamalainen <ccr@tnsp.org>
parents: 699
diff changeset
50 define("EPREV_AUDIO", 2); // Preview is audio (Vorbis, MP3)
528
dd5c5577c495 Add preview file and file type fields for entry, for screenshots etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
51
703
242cb053fbb2 Add array/list of preview types and descriptions for them.
Matti Hamalainen <ccr@tnsp.org>
parents: 702
diff changeset
52 $previewTypeList = array(
752
c714140541d5 Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents: 746
diff changeset
53 EPREV_NONE => array("No previews" , "Default"),
c714140541d5 Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents: 746
diff changeset
54 EPREV_IMAGE => array("Image file" , "Image"),
c714140541d5 Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents: 746
diff changeset
55 EPREV_AUDIO => array("Audio file" , "Audio"),
703
242cb053fbb2 Add array/list of preview types and descriptions for them.
Matti Hamalainen <ccr@tnsp.org>
parents: 702
diff changeset
56 );
242cb053fbb2 Add array/list of preview types and descriptions for them.
Matti Hamalainen <ccr@tnsp.org>
parents: 702
diff changeset
57
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
58 //
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
59 // File format classes
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
60 //
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
61 define("EFILE_UNKNOWN", 0);
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
62 define("EFILE_IMAGE", 1);
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
63 define("EFILE_AUDIO", 2);
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
64 define("EFILE_VIDEO", 3);
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
65 define("EFILE_TEXT", 4);
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
66 define("EFILE_BINARY", 5);
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
67 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
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 //
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
72 define("EFLAG_DISQUALIFIED", 1); // Entry is disqualified
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
73 define("EFLAG_PROBLEMS", 2); // Has some problems
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
74
690
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
75 $entryFlagsList = array(
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
76 EFLAG_DISQUALIFIED => array("Disqualified", "img/disqualified.png"),
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
77 EFLAG_PROBLEMS => array("Has problems", "img/problems.png"),
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
78 );
bad79296eb34 Cleanups, rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
79
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
80
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
81 //
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
82 // Results output flags
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
83 //
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
84 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
85 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
86 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
87
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
88 //
508
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
89 // 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
90 //
606
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
91 define("COMPO_NORMAL", 0); // Normal voting compo, points determine placement
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
92 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
93 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
94
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
95
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
96 $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
97 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
98 "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
99 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
100 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
101 "Assigned points (no voting).",
745
7ac6d1fdc078 Add two new fields to compoModeData.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
102 "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
103 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
104 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
105 "Assigned places (no points, no voting).",
745
7ac6d1fdc078 Add two new fields to compoModeData.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
106 "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
107 ),
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
108 );
b6fe46c86ff3 Add definitions for entry flags and compo types. Not used yet (though the
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
109
641
1a123c6c2241 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 640
diff changeset
110
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
111 //
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
112 // Different voting modes
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 define("VOTE_FREELY", 0);
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
115 define("VOTE_ACTIVATE", 1);
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
116 define("VOTE_ASSIGN", 2);
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
117
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
118 $voteModeData = array(
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
119 VOTE_FREELY => array("Freeform voting",
282
50e52dc43916 Add missing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
120 "Vote 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
121 "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
122 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
123 VOTE_ACTIVATE => array("Key activation",
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
124 "Vote keys are not tied to attendees, but require manual activation. ".
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
125 "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
126 "Give key slip to attendee."
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
127 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
128 VOTE_ASSIGN => array("Assigned keys",
307
c0d573a5de5b Add procedure description to assigned keys mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
129 "Votekeys are tied to attendees, activated by assigning the key to attendee. ".
c0d573a5de5b Add procedure description to assigned keys mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
130 "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
131 "Give key slip to attendee."
274
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
132 ),
81507072f25d Add explanations of the different voting modes.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
133 );
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
134
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
135
535
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
136 //
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
137 // Data about the file types we use
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
138 //
809
a165d2e101f9 Rename array.
Matti Hamalainen <ccr@tnsp.org>
parents: 808
diff changeset
139 $fileTypeData = array(
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
140 "PNG" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
141 "class" => EFILE_IMAGE,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
142 "type" => EPREV_IMAGE,
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
143 "mime" => "image/png",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
144 "fext" => "png",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
145 "test" => "^PNG image data",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
146 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
147 "JPEG" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
148 "class" => EFILE_IMAGE,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
149 "type" => EPREV_IMAGE,
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
150 "mime" => "image/jpeg",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
151 "fext" => "jpg",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
152 "test" => "^JPEG image data",
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,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
156 "type" => EPREV_IMAGE,
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",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
159 "test" => "^GIF image data",
807
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
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
162 "MP3" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
163 "class" => EFILE_AUDIO,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
164 "type" => EPREV_AUDIO,
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
165 "mime" => "audio/mpeg",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
166 "fext" => "mp3",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
167 "test" => "MPEG ADTS, layer III",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
168 ),
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
169 "OggVorbis" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
170 "class" => EFILE_AUDIO,
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
171 "type" => EPREV_AUDIO,
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
172 "mime" => "audio/ogg; codecs=vorbis",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
173 "fext" => "ogg",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
174 "test" => "Ogg data, Vorbis audio",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
175 ),
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
176 "FLAC" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
177 "class" => EFILE_AUDIO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
178 "type" => EPREV_AUDIO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
179 "mime" => "audio/x-flac",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
180 "fext" => "flac",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
181 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
182 "WAV" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
183 "class" => EFILE_AUDIO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
184 "type" => EPREV_AUDIO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
185 "mime" => "audio/x-wav",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
186 "fext" => "wav",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
187 ),
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
188
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
189 // Special cases
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
190 "ILBM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
191 "class" => EFILE_IMAGE,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
192 "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
193 "fext" => "lbm",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
194 "test" => "^IFF data",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
195 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
196 "PCX" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
197 "class" => EFILE_IMAGE,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
198 "mime" => "image/x-pcx",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
199 "fext" => "pcx",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
200 "test" => "^PCX ver\. 3\.0",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
201 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
202
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
203 "PTMOD" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
204 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
205 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
206 "fext" => "mod",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
207 "test" => "^\d+-channel Protracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
208 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
209 "PTMOD" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
210 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
211 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
212 "fext" => "mod",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
213 "test" => "^\d+-channel Fasttracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
214 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
215 "S3M" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
216 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
217 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
218 "fext" => "s3m",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
219 "test" => "^ScreamTracker III Module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
220 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
221 "XM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
222 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
223 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
224 "fext" => "xm",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
225 "test" => "^Fasttracker II module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
226 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
227 "IT" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
228 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
229 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
230 "fext" => "it",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
231 "test" => "^Impulse Tracker module",
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
232 ),
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
233 "PTM" => array(
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
234 "class" => EFILE_AUDIO,
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
235 "mime" => "audio/x-mod",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
236 "fext" => "ptm",
808
887e88fad15a More filetype data.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
237 "test" => "^Poly Tracker PTM Module",
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
238 ),
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
239
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
240 "AVI" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
241 "class" => EFILE_VIDEO,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
242 "mime" => "video/x-msvideo",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
243 "fext" => "avi",
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 "WMV" => 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-ms-asf",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
248 "fext" => "wmv",
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 "MP4" => 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/mp4",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
253 "fext" => "mp4",
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 "MOV" => 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/quicktime",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
258 "fext" => "mov",
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 "MKV" => 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/x-matroska",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
263 "fext" => "mkv",
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
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
266 // Archives
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
267 "LHA" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
268 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
269 "mime" => "application/x-lha",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
270 "fext" => "lha",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
271 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
272 "ZIP" => 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/zip",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
275 "fext" => "zip",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
276 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
277 "7ZIP" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
278 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
279 "mime" => "application/x-7z-compressed",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
280 "fext" => "7z",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
281 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
282 "RAR" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
283 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
284 "mime" => "application/x-rar",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
285 "fext" => "rar",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
286 ),
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
287 "ARJ" => array(
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
288 "class" => EFILE_ARCHIVE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
289 "mime" => "application/x-arj",
844
fcaafeda4faa Remove "." from file extensions in filetype table.
Matti Hamalainen <ccr@tnsp.org>
parents: 841
diff changeset
290 "fext" => "arj",
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
291 ),
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 // Final fallback
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
294 "MISC" => array(
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
295 "class" => EFILE_BINARY,
815
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
296 "mime" => "application/octet-stream",
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
297 "fext" => FALSE,
4df1bfd11131 Add file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
298 ),
839
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
299
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
300 "TEXT" => array(
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
301 "class" => EFILE_TEXT,
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
302 "mime" => "text/plain",
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
303 "fext" => FALSE,
43e4a73deaf3 Add some missing file classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
304 ),
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
305 );
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
306
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
307
888
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
308 function stFileError($userID, $adminMsg, $userMsg)
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
309 {
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
310 stLogError($adminMsg);
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
311 stError(($userID === 0) ? $adminMsg : $userMsg);
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
312 return FALSE;
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
313 }
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
314
e0903d0c3954 Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 887
diff changeset
315
807
0bb4b1973e08 Add file type list.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
316 //
535
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
317 // Party infromation system data/variables handling
88c048f3b9e1 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 533
diff changeset
318 //
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
319 function stReloadDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
320 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
321 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
322
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
323 $displayVars = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
324 $displayVarsChanged = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
325
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
326 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
327 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
328 foreach ($res as $row)
354
1dd598221874 Simplify code by reusing functions from site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 307
diff changeset
329 $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
330 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
331 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
332
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 function stSaveDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
335 {
144
c030c3cf0d80 More work on display system.
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
336 global $db, $displayVars, $displayVarsChanged;
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
337
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
338 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
339 if (isset($displayVarsChanged[$item["key"]]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
340 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
341 $val = $displayVars[$item["key"]];
354
1dd598221874 Simplify code by reusing functions from site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 307
diff changeset
342 stExecSQL(
542
8c1a53532be0 Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
343 "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
344 " 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
345 }
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
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
348
407
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
349 function stDisplayUpdated()
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
350 {
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
351 stSetDisplayVar("lastUpdate", time());
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
352 }
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
353
eaea1ae2bc3d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 396
diff changeset
354
454
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
355 function stSetDisplayVarUpd($name, $value)
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
356 {
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
357 if (stGetDisplayVar($name) != $value)
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
358 {
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
359 stSetDisplayVar($name, $value);
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
360 stDisplayUpdated();
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
361 return TRUE;
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 else
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
364 return FALSE;
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
365 }
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
366
ea7fc4e9f602 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 447
diff changeset
367
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
368 function stGetDisplayVar($name)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
369 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
370 global $displayVars;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
371 if (isset($displayVars[$name]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
372 return $displayVars[$name];
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
373 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
374 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
375 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
376
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
377
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
378 function stSetDisplayVar($name, $value)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
379 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
380 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
381 if (isset($displayVars[$name]))
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 $displayVars[$name] = $value;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
384 $displayVarsChanged[$name] = true;
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 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
387 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
388 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
389
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
390
806
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
391 //
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
392 // Like stExecSQL(), but throws error messages to "userspace".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
393 //
484
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
394 function stExecSQLCond($sql, $msg = FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
395 {
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
396 global $db;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
397 if (($res = stDBExecSQL($db, $sql)) !== FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
398 {
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
399 if ($msg !== FALSE)
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
400 stSetStatus(200, $msg);
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
401 return $res;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
402 }
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
403 else
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 stSetStatus(902, "Error in SQL execution.");
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
406 return FALSE;
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
407 }
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
c8591a8fadbc Move stExecSQLCond() to site module.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
410
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
411 function stPrintAttendee($item, $row, $tr, $full, $edit, $eclass = "")
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
412 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
413 $id = $item["id"];
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
414 $prefix = "at";
677
64d80a7f7e26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 674
diff changeset
415
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
416 if ($tr)
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
417 {
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
418 echo
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
419 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven").$eclass.
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
420 "\" id=\"attendee".$id."\" ".($full ? "onClick=\"activateAttendee(".$id.")\"" : "").">";
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
421 }
677
64d80a7f7e26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 674
diff changeset
422
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
423 echo
679
cbb66cb60930 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 677
diff changeset
424 stGetTDFormTextInput($edit, 20, SET_LEN_USERNAME, "name", $id, $prefix, $item["name"]).
cbb66cb60930 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 677
diff changeset
425 stGetTDFormTextInput($edit, 20, SET_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
426 "<td class=\"regtime\">".date("d.m. H:i", $item["regtime"])."</td>".
679
cbb66cb60930 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 677
diff changeset
427 stGetTDFormTextInput($edit, 30, SET_LEN_ONELINER, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\"");
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
428
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
429 if ($full)
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
430 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
431 echo
716
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
432 stGetTDFormTextInput($edit, 15, SET_LEN_EMAIL, "email", $id, $prefix, $item["email"], "autocomplete=\"off\"").
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
433 stGetTDFormTextInput($edit, 15, SET_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
434
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
435 if ($edit)
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
436 {
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
437 echo
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
438 "<td>".
680
c9b96a7b9dc4 Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
439 stGetFormButtonElement($prefix."upd".$id, "","", "Upd", "updateAttendee(".$id.")").
c9b96a7b9dc4 Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
440 stGetFormButtonElement($prefix."del".$id, "","", "Del", "deleteAttendee(".$id.")").
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
441 "</td>";
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 else
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
444 echo "<td></td>";
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
445 }
205
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
446
77d33161f8be More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
447 if ($tr)
674
3e37a29468bf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 665
diff changeset
448 echo "</tr>\n";
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
449 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
450
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
451
222
b236b4d8d7a9 Remove useless code.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
452 function stPrintNewsItem($item)
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
453 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
454 echo
592
642df17214f6 Improve news item DOM IDs.
Matti Hamalainen <ccr@tnsp.org>
parents: 585
diff changeset
455 "<div class=\"newsItem\" id=\"news".$item["id"]."\">\n".
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
456 " <h2>".chentities($item["title"])."</h2>\n".
592
642df17214f6 Improve news item DOM IDs.
Matti Hamalainen <ccr@tnsp.org>
parents: 585
diff changeset
457 " <div class=\"newsText\">".dhentities($item["text"])."</div>\n".
593
3cceb9f13762 And some more tweaking.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
458 " <div class=\"newsAuthor\"><span class=\"newsSig\">-- ".chentities($item["author"])."</span>".
3cceb9f13762 And some more tweaking.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
459 "<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
460 "</div>\n";
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
461 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
462
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
463
806
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
464 function stGetTDFormTextInput($edit, $size, $len, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
465 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
466 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
467 "<td class=\"".$name."\">".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
468 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
469 "</td>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
470 }
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
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
473 function stGetEditFormTextInput($mode, $title, $size, $len, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
474 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
475 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
476 "<div class=\"editControl\"><span class=\"editControlTitle\">".chentities($title)."</span>".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
477 ($mode ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
478 "</div>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
479 }
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
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
482 function stGetEditFormTextArea($mode, $title, $rows, $cols, $name, $id, $prefix, $value, $extra = "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
483 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
484 return
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
485 "<div class=\"editControl\"><span class=\"editControlTitle\">".chentities($title)."</span>".
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
486 stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, ($mode ? "" : " disabled=\"disabled\" ").$extra).
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
487 "</div>";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
488 }
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
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
491 function stConvSwitchMode(&$str, &$mode, $newMode)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
492 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
493 if ($newMode != $mode)
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 if ($mode != "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
496 $str .= "\n</".$mode.">\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
497
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
498 $mode = $newMode;
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
499
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
500 if ($mode != "")
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
501 $str .= "<".$mode.">\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
502 }
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
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 function stConvertCommonDesc($desc, $chent)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
507 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
508 $str = "";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
509 $mode = "";
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 foreach (explode("\n", $desc) as $line)
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
512 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
513 if (preg_match("/^\s*\s*\*(.+)$/", $line, $m))
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
514 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
515 stConvSwitchMode($str, $mode, "ol");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
516 $str .= "<li>".($chent ? chentities($m[1]) : $m[1])."</li>\n";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
517 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
518 else
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, "ul");
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 {
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
526 stConvSwitchMode($str, $mode, "p");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
527 $str .= ($chent ? chentities($line) : $line);
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
528 }
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
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
531 stConvSwitchMode($str, $mode, "");
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
532
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
533 return $str;
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 function stGetNumberSuffix($val)
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 switch ($val)
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 case 1: return "st";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
542 case 2: return "nd";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
543 case 3: return "rd";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
544 case 4: case 5: case 6:
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
545 case 7: case 8: case 9: return "th";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
546 default: return "th";
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
547 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
548 }
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
549
59528ba5813a Move stuff around.
Matti Hamalainen <ccr@tnsp.org>
parents: 800
diff changeset
550
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
551 function stGenerateUserKey()
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
552 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
553 global $db;
99
2169c3177f47 Limit the vote key character space even more.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
554 $keyChars = "abdefghjkmnpqrstwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
555
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
556 while (TRUE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
557 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
558 // Generate one randomized keycode
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
559 $key = "";
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
560 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
561 $key .= $keyChars[rand() % strlen($keyChars)];
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
562
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
563 // 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
564 // 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
565 // won't work due to it returning FALSE in error cases.
87
3da47d3e6a3c Remove a function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
566 $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", $key);
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
567 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
568 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
569 // Did we get results?
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
570 if ($res->fetchColumn() === FALSE)
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 // Nope, return key
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
573 return $key;
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
574 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
575 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
576 else
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
577 {
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
578 stLogSQLError($sql);
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
579 return FALSE;
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
580 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
581 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
582 }
66
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
583
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
584
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
585 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
586 {
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
587 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
588
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
589 $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
590 $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
591 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
592 $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
593
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
594 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
595 }
135
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
596
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
597
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
598 function stValidateRequestUserData($admin, $id = FALSE)
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
599 {
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
600 $res = TRUE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
601 $chk = 0;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
602
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
603 if (stChkRequestItem("name", $name,
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
604 array(CHK_ISGT, VT_STR, 0, "Handle / name not given."),
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
605 array(CHK_LTEQ, VT_STR, SET_LEN_USERNAME, "Handle / name is too long, should be less than ".SET_LEN_USERNAME." characters.")))
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
606 $chk++;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
607 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
608 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
609
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
610 if (stChkRequestItem("groups", $groups,
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
611 array(CHK_LTEQ, VT_STR, SET_LEN_GROUPS, "Groups are too long, should be less than ".SET_LEN_GROUPS." characters.")))
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
612 $chk++;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
613 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
614 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
615
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
616 if (!stChkRequestItem("oneliner", $oneliner,
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
617 array(CHK_LTEQ, VT_STR, SET_LEN_ONELINER, "Oneliner is too long, should be less than ".SET_LEN_ONELINER." characters.")))
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
618 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
619
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
620 $email = stGetRequestItem("email");
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
621 if (!$admin && stGetSetting("requireEMail") && strlen($email) < 4)
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
622 {
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
623 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
624 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
625 }
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
626
605
f928b0a6e1af Better validation for e-mail addresses.
Matti Hamalainen <ccr@tnsp.org>
parents: 598
diff changeset
627 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
628 {
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
629 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
630 $res = FALSE;
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
631 }
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
632
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
633 if (strlen($email) > SET_LEN_EMAIL)
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
634 {
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
635 stError("E-mail address too long, max ".SET_LEN_EMAIL." characters.");
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
636 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
637 }
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
638
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
639 // Check if another user already exists
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
640 if ($chk >= 2)
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
641 {
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
642 if ($id !== false)
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
643 // 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
644 $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
645 else
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
646 // Or just exists, if adding
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
647 $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
648
648
9e4b8df65879 Oops, fix a 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 647
diff changeset
649 if (($data = stFetchSQL($sql)) !== false)
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
650 {
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
651 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
652 $res = FALSE;
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
653 }
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
654 }
646
2eeca16e9c96 Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 641
diff changeset
655 return $res;
648
9e4b8df65879 Oops, fix a 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 647
diff changeset
656
207
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
657 }
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
658
e31c42a9b574 Slowly work on input validation.
Matti Hamalainen <ccr@tnsp.org>
parents: 205
diff changeset
659
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
660 function stGetCompoResultsSQL($mode, $compo, $flags)
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
661 {
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
662 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
663 // Act based on competition type
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
664 //
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
665 switch ($compo["ctype"])
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
666 {
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
667 case COMPO_NORMAL:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
668 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
669 // "Normal" competition, where results are somehow
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
670 // based on points / voting.
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
671 //
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
672 switch ($mode)
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
673 {
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
674 case VOTE_FREELY:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
675 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
676 "SELECT entries.*,SUM(votes.value) AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
677 "FROM entries ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
678 "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
679 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
680
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
681 case VOTE_ACTIVATE:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
682 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
683 "SELECT entries.*, ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
684 "(SELECT SUM(votes.value) FROM votes ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
685 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
686 "WHERE votes.entry_id=entries.id AND votekeys.active<>0) ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
687 "AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
688 "FROM entries";
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
689 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
690
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
691 case VOTE_ASSIGN:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
692 $sql =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
693 "SELECT entries.*, ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
694 "(SELECT SUM(votes.value) FROM votes ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
695 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
696 "LEFT JOIN attendees ON votekeys.id=attendees.key_id ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
697 "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
698 "AS votesum ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
699 "FROM entries";
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
700 break;
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
701 }
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
702
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
703 $extra =
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
704 "GROUP BY entries.id ".
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
705 "ORDER BY votesum DESC";
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
706 break;
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
707
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
708 case COMPO_POINTS:
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
709 //
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
710 // Points ..
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
711 //
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
712 $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
713 $extra = "ORDER BY entries.evalue DESC";
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
714 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
715
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
716 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
717 //
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
718 // Ascending
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
719 //
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
720 $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
721 $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
722 break;
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
723 }
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
724
623
8e6331d7870d Some work on compo type handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
725 return $sql." ".
606
3d2b70fbeb78 Slight cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
726 "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
727 (($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
728 $extra;
531
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
729 }
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
730
ec30ad303bd1 Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
731
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
732 function stGetCompoResults($flags)
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
733 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
734 $voteKeyMode = stGetSetting("voteKeyMode");
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
735 $out = array();
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
736 $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC";
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
737 if (($res = stExecSQL($sql)) === false)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
738 return $out;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
739
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
740 // For each compo that has been set visible
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
741 foreach ($res as $compo)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
742 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
743 // Check if there are any entries for it
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
744 $sql =
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
745 "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
746 "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
747 (($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
748
798
b97d4b754bc0 Show also empty compos with RFLAG_HIDDEN_COMPOS.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
749 if (($nentries = stFetchSQLColumn($sql)) !== FALSE &&
b97d4b754bc0 Show also empty compos with RFLAG_HIDDEN_COMPOS.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
750 ($nentries > 0 || ($flags & RFLAG_HIDDEN_COMPOS)))
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
751 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
752 // Get voting results by mode
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
753 $sql = stGetCompoResultsSQL($voteKeyMode, $compo, $flags);
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
754
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
755 $out[$compo["id"]] = $compo;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
756 $out[$compo["id"]]["results"] = array();
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
757 $prev = FALSE;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
758 $index = 0;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
759
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
760 foreach (stExecSQL($sql) as $entry)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
761 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
762 if ($entry["votesum"] !== $prev)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
763 $index++;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
764
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
765 $entry["position"] = $index;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
766 $out[$compo["id"]]["results"][] = $entry;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
767
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
768 $prev = $entry["votesum"];
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
769 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
770 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
771 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
772
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
773 return $out;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
774 }
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
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
777 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
778 {
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
779 $name = stStrChopPad($entry["name"], 30);
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
780 $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
781
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
782 $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
783
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
784 // 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
785 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
786 $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
787
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
788 // Points?
698
3f322be347d6 Fix the results display.
Matti Hamalainen <ccr@tnsp.org>
parents: 697
diff changeset
789 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
790 $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
791
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
792 // 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
793 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
794 $out .= " [DISQ]";
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
795
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
796 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
797 }
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
798
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
799
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
800 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
801 {
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
802 $out = "";
792
b42b23073209 Improve printing of results with more options (in the admin interface).
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
803 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
804 {
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
805 // Output compo title / header
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
806 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
807 {
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
808 $out .=
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
809 "<pre>\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
810 "<b> ".chentities($compo["name"])." </b>\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
811 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
812 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
813 else
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
814 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
815 $out .=
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
816 " ".$compo["name"]."\n".
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
817 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
818 }
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
819
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
820 // List results for this compo
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
821 $prev = FALSE;
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
822 foreach ($compo["results"] as $entry)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
823 {
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
824 if ($entry["position"] !== $prev)
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
825 $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
826 else
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
827 $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
828
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
829 $out .= stGetCompoResultLine($html, $entry,
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
830 ($compo["ctype"] != COMPO_ASSIGN) ? $entry["votesum"] : FALSE,
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
831 ($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
832
724
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
833 $prev = $entry["position"];
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
834 }
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
835 $out .= "\n\n".($html ? "</pre>\n" : "");
fd84eb4d8b74 Refactor compo results code for modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
836 }
695
dff9b125f774 Work on results printing and remove "show authors" option as it is rather
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
837
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
838 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
839 }
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
6fe66ea0e954 Move most of the results code to site module, remove the support for HTML
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
841
716
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
842 function stGetAttendeeRegistrationSQL()
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
843 {
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
844 return stPrepareSQL(
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
845 "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
846 time(), "name", "groups", "oneliner", "email", $_SERVER["REMOTE_ADDR"]);
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
847 }
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
848
e7fbcf4190e6 Add registration host.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
849
819
a431fc8a2b9a Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
850 //
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
851 // Filter a path or filename component string
819
a431fc8a2b9a Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
852 //
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
853 function stFilterPathComponent($str)
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
854 {
871
9b9939fce097 Whooops.
Matti Hamalainen <ccr@tnsp.org>
parents: 869
diff changeset
855 return preg_replace("/[^a-zA-Z0-9\,\._-]/", "_", $str);
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
856 }
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
857
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
858
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
859 //
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
860 // Replace or add filename extension
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
861 //
885
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
862 function stReplaceFileExt($filename, $fext = FALSE)
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
863 {
885
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
864 if ($fext === FALSE)
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
865 return $filename;
2ca7f609e480 Allow fext to be FALSE stReplaceFileExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
866
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
867 if (($spos = strrpos($filename, ".")) !== FALSE)
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
868 return substr($filename, 0, $spos).$fext;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
869 else
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
870 return $filename.$fext;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
871 }
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
872
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
873
886
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
874 //
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
875 // Create a path, or URL from specified components
354183f9c6e9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
876 //
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
877 function stMakePath($isURL, $hasFilename, $components)
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
878 {
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
879 $res = array();
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
880
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
881 // 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
882 if ($isURL)
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
883 {
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
884 $res[] = array_shift($components);
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
885 $first = FALSE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
886 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
887 else
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
888 $first = TRUE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
889
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
890 // Handle each path component
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
891 if (count($components) > 0)
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
892 {
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
893 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
894 foreach (explode("/", $components[$i]) as $item)
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
895 {
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
896 if ($item == "..")
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
897 array_pop($res);
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
898 else
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
899 if ($item != "." && ($item != "" || $first))
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
900 $res[] = stFilterPathComponent($item);
780
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
901 $first = FALSE;
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
902 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
903 }
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
904
f8d09e0de027 Properly implement stMakePath() replacing the stub function.
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
905 return implode("/", $res);
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
906 }
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
907
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
908
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
909 function stGetEntryPreviewFile($entry, $previewPath, $previewURL, $type, $addPath)
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
910 {
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
911 global $fileTypeData;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
912 if (!isset($fileTypeData[$type]))
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
913 return stLogError("Invalid file type: ".$type);
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
914
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
915 $fileBase = sprintf("%03d.%s", $entry["id"], $fileTypeData[$type]["fext"]);
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
916 $fileName = stMakePath(FALSE, TRUE, array($previewPath, $addPath, $fileBase));
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
917
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
918 return array(
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
919 "type" => $type,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
920 "mime" => $fileTypeData[$type]["mime"],
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
921 "file" => $fileName,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
922 "exists" => @file_exists($fileName),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
923 "mtime" => @filemtime($fileName),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
924 "url" => stMakePath(TRUE, TRUE, array($previewURL, $addPath, $fileBase)),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
925 );
721
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
926 }
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
927
69a829f687a9 Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 716
diff changeset
928
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
929 function stPrintPreviewElements($compo, $entry)
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
930 {
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
931 if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) === false)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
932 return FALSE;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
933
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
934 $previewPath = stGetSetting("previewPath");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
935 $previewURL = stGetSetting("previewURL");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
936 $previewType = $compo["preview_type"];
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
937 $previewOK = TRUE;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
938
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
939 switch ($previewType)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
940 {
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
941 case EPREV_IMAGE:
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
942 $sprev = stGetEntryPreviewFile(
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
943 $entry, $previewPath, $previewURL,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
944 stGetSetting("previewImageType"), "");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
945
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
946 $sthumb = stGetEntryPreviewFile(
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
947 $entry, $previewPath, $previewURL,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
948 stGetSetting("previewThumbType"),
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
949 stGetSetting("thumbnailSubDir"));
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
950
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
951 if ($sprev["exists"] === false ||
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
952 $sthumb["exists"] === false ||
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
953 $sprev["mtime"] < $efile["utime"] ||
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
954 $sthumb["mtime"] < $efile["utime"])
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
955 $previewOK = FALSE;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
956 break;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
957
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
958 case EPREV_AUDIO:
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
959 $sprev = array();
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
960 foreach (stGetSetting("sampleType") as $type)
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
961 {
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
962 $sres = stGetEntryPreviewFile(
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
963 $entry, $previewPath, $previewURL,
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
964 $type, "");
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
965
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
966 if ($sres["exists"] === false ||
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
967 $sres["mtime"] < $efile["utime"])
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
968 {
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
969 $previewOK = FALSE;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
970 break;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
971 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
972
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
973 $sprev[] = $sres;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
974 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
975 break;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
976
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
977 default:
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
978 return FALSE;
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
979 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
980
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
981 switch ($previewType)
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
982 {
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
983 case EPREV_IMAGE:
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
984 if (!$previewOK)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
985 {
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
986 echo
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
987 "<img class=\"imagePreview\" src=\"img/nopreview_tn.png\" alt=\"Preview\" />";
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
988 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
989 else
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
990 {
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
991 echo
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
992 "<a href=\"".ihentities($sprev["url"]).
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
993 "\" onClick=\"return jsShowPreviewImage('".ihentities($sprev["url"])."');\">".
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
994 "<img class=\"imagePreview\" src=\"".ihentities($sthumb["url"]).
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
995 "\" alt=\"Preview\" /></a>";
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
996 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
997 break;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
998
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
999 case EPREV_AUDIO:
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1000 if ($previewOK && count($sprev) > 0)
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1001 {
889
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1002 echo "<audio controls preload=\"none\" class=\"audioPreview\">";
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1003 foreach ($sprev as $pfile)
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1004 {
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1005 echo "<source src=\"".ihentities($pfile["url"])."\" type=\"".$pfile["mime"]."\">";
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1006 }
0fbf63bbb8f4 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 888
diff changeset
1007 echo "</audio>";
774
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1008 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1009 break;
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1010 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1011 }
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1012
d6668b73bb01 Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
1013
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1014 //
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1015 // Probe file type information
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1016 //
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1017 function stProbeFileInfo($filename)
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1018 {
840
3b9ccc10c9a0 Few 10L's
Matti Hamalainen <ccr@tnsp.org>
parents: 839
diff changeset
1019 global $fileTypeData;
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1020
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1021 // Get file magic info
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1022 if (($finfo = finfo_open()) === false)
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1023 {
874
ffb5643eff4f Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
1024 stLogError("Internal error. Failed to initialize finfo().");
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1025 return stError("Internal error, failed to probe file.");
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1026 }
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1027
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1028 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1029 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1030 finfo_close($finfo);
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1031
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1032 // Did we get anything?
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1033 if ($sdata === FALSE || $smime === FALSE)
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1034 {
874
ffb5643eff4f Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
1035 stLogError("Failed to probe file '".$filename."'.");
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1036 return stError("Internal error, failed to probe file.");
818
5f20e5f1d589 Log errors.
Matti Hamalainen <ccr@tnsp.org>
parents: 817
diff changeset
1037 }
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1038
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1039 // Match through our supported types ..
840
3b9ccc10c9a0 Few 10L's
Matti Hamalainen <ccr@tnsp.org>
parents: 839
diff changeset
1040 foreach ($fileTypeData as $fid => $fdata)
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1041 {
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1042 $fdata["id"] = $fid;
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1043
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1044 if (isset($fdata["test"]))
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1045 {
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1046 if (preg_match("/".$fdata["test"]."/", $sdata))
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1047 return $fdata;
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1048 }
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1049 else
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1050 if ($fdata["mime"] == $smime)
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1051 return $fdata;
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1052 }
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1053
874
ffb5643eff4f Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
1054 stLogError("File '".$filename."' (".$smime.") did not match any allowed file types.");
833
f03c4e9aad29 Improve error logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 824
diff changeset
1055 return stError("No matching allowed file type found for '".$smime."'.");
816
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1056 }
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1057
95c3e0a1058e Add new helper function stProbeFileInfo().
Matti Hamalainen <ccr@tnsp.org>
parents: 815
diff changeset
1058
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1059 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1060 // File table entry adding
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1061 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1062 function stAddFileEntry($entry, $type, $origName, $fileSize, $fileExt, $fileType, $uploaderID)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1063 {
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1064 $field = (($type == "preview") ? "preview" : "file")."_id";
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1065
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1066 // Create new file entry
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1067 $sql = stPrepareSQL(
872
5e9958f78b16 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1068 "INSERT INTO files (origname,filetype,filesize,entry_id,uploader_id,uploadtype,utime) ".
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1069 "VALUES (%s,%s,%d,%d,%d,%d)",
872
5e9958f78b16 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1070 $origName, $fileType, $fileSize, $entry["id"], $uploaderID, $type, time());
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1071
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1072 if (($fileID = stExecSQLInsert($sql)) === false)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1073 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1074 "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
1075 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1076
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1077 // Compute storage filename
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1078 $fileName = sprintf("%03d-%s--%s%s_(%d).%s",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1079 $entry["id"],
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1080 stFilterPathComponent($entry["author"]),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1081 stFilterPathComponent($entry["name"]),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1082 ($type == "preview" ? "_preview" : ""),
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1083 $fileID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1084 $fileExt);
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1085
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1086 // Update entry with generated filename
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1087 $sql = stPrepareSQL("UPDATE files SET filename=%s WHERE id=%d", $fileName, $fileID);
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1088 if (stExecSQL($sql) === false)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1089 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1090 "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
1091 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1092
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1093 // Update entry's reference
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1094 $sql = stPrepareSQL("UPDATE entries SET ".$field."=%d WHERE id=%d", $fileID, $entry["id"]);
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1095 if (stExecSQL($sql) === false)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1096 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1097 "Failed to update entry #".$entry["id"]." ".$type." ID!",
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1098 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1099
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1100 // Return file entry
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1101 if (($res = stFetchSQL("SELECT * FROM files WHERE id=".$fileID)) === false)
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1102 return stFileError($uploaderID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1103 "Failed to fetch newly generated files entry #".$fileID,
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1104 "Internal error. Failed to add new file.");
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1105
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1106 return $res;
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1107 }
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1108
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1109
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1110 //
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1111 // File upload handling
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1112 //
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1113 function stHandleGenericFileUpload($userID)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1114 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1115 global $errorSet;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1116
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1117 // Check basics
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1118 if (!stChkRequestItem("type", $uploadType,
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1119 array(CHK_TYPE, VT_STR, "Invalid upload type."),
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1120 array(CHK_ARRAY, VT_STR, array("entry", "preview"), "Invalid upload type."))
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1121 ||
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1122 !stChkRequestItem("entry_id", $entryID,
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1123 array(CHK_TYPE, VT_INT, "Invalid entry ID.")))
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1124 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1125
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1126 // Check entry existence
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1127 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
1128 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1129 "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
1130 "Entry does not exist??");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1131
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1132 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
1133 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1134 "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
1135 "Compo does not exist??");
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1136
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1137 // Check target path existence / writability
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
1138 $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
1139 if (!file_exists($dstPath))
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1140 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1141 "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
1142 "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
1143
866
db9810510670 s/fileperm(/fileperms(/ :S
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
1144 $dstPerms = fileperms($dstPath);
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1145 if (($dstPerms & 0x4000) === 0)
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1146 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1147 "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
1148 "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
1149
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1150 $needPerms = 0x0100 | 0x0080 | 0x0040;
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1151 if (($dstPerms & $needPerms) !== $needPerms)
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1152 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1153 "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
1154 "Path for entry's compo has no sufficient permissions.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1155
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1156 // Check permissions for non-admins
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1157 if ($userID != 0)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1158 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1159 // Check if the user even exists, just in case
824
6f52c19b00f4 Fix some 10L's.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
1160 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
1161 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1162 "User ID #".$userID." does not exist??",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1163 "You do not exist. Go away.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1164
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1165 if ($entry["owner_id"] != $userID)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1166 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1167 "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
1168 "Attempted to upload file to entry not owned by user.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1169 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1170
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1171 // Check file status data
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1172 $maxFileSize = stGetSetting($uploadType."MaxSize");
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1173
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1174 $index = $uploadType."ToUpload".$entryID;
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1175 $fileSize = $_FILES[$index]["size"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1176 $tmpFilename = $_FILES[$index]["tmp_name"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1177 $orgFilename = $_FILES[$index]["name"];
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1178
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1179 if ($fileSize > $maxFileSize)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1180 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
1181
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1182 if ($fileSize < 128)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1183 stError("File size ".$fileSize." is less than 128 bytes. This can't be right.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1184
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1185 switch ($_FILES[$index]["error"])
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1186 {
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1187 case UPLOAD_ERR_INI_SIZE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1188 stError("File size exceeds PHP's max upload size.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1189 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1190
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1191 case UPLOAD_ERR_PARTIAL:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1192 stError("File only partially uploaded.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1193 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1194
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1195 case UPLOAD_ERR_NO_FILE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1196 stError("No file data received!");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1197 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1198
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1199 case UPLOAD_ERR_NO_TMP_DIR:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1200 stError("Internal error: Temporary file directory not available!");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1201 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1202
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1203 case UPLOAD_ERR_CANT_WRITE:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1204 stError("Internal error: PHP could not write the file to disk.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1205 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1206
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1207 case UPLOAD_ERR_OK:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1208 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1209
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1210 default:
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1211 stError("Unknown PHP file error occured.");
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1212 break;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1213 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1214
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1215 if ($errorSet)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1216 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1217
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1218
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1219 // Check file properties ..
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1220 if (($fileInfo = stProbeFileInfo($tmpFilename)) === false)
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1221 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1222
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1223 if ($uploadType == "preview" && !isset($fileInfo["type"]))
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1224 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
1225
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1226 // Get original extension
847
7fee98f15c3c More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 845
diff changeset
1227 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
1228 {
847
7fee98f15c3c More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 845
diff changeset
1229 $fileExt = ".tmp";
7fee98f15c3c More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 845
diff changeset
1230 if (($epos = strrpos($orgFilename, ".")) !== false)
7fee98f15c3c More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 845
diff changeset
1231 $fileExt = substr($orgFilename, $epos);
841
f007e63f82d6 Use original filename extension if we can't determine a solid file type.
Matti Hamalainen <ccr@tnsp.org>
parents: 840
diff changeset
1232 }
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1233
852
5eda5f9c7437 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 848
diff changeset
1234 // Update current or add new file entry
869
2447673c5d04 Back to the original plan.
Matti Hamalainen <ccr@tnsp.org>
parents: 866
diff changeset
1235 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
1236 return FALSE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1237
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1238 // Set permissions before moving the file
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1239 if (chmod($tmpFilename, stGetSetting($uploadType."PathPerms")) === false)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1240 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1241 "Could not set permissions for uploaded file '".$tmpFilename."'.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1242 "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
1243
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1244 // Move file to its destination
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
1245 $dstFilename = stMakePath(FALSE, TRUE, array(stGetSetting("entryPath"), $compo["cpath"], $fentry["filename"]));
845
123cd6868b1b Rework file upload backend code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 844
diff changeset
1246 if (@move_uploaded_file($tmpFilename, $dstFilename) === false)
864
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1247 return stFileError($userID,
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1248 "Could not move uploaded file '".$tmpFilename."' to '".$dstFilename."'.",
16bc6c1029ee Handle file upload errors more nicely.
Matti Hamalainen <ccr@tnsp.org>
parents: 861
diff changeset
1249 "Internal error. Deploying uploaded file failed! Contact site admins.");
823
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1250
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1251 return TRUE;
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1252 }
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1253
debad9461b00 Add stHandleGenericFileUpload().
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
1254
797
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1255 function stNormalizeListSlideOrder($list_id)
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1256 {
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1257 }
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1258
7126403af18f Move function.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1259
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1260 ?>