annotate createdb.php @ 123:5837b9333964

Add new "about" page, and setting for default page.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Oct 2013 15:18:09 +0300
parents 2c594958050e
children 75cf14ee99a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/php
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 <?
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 require "mconfig.inc.php";
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 require "msite.inc.php";
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
50
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
6 // Check if we are running from commandline or not
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
7 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
8 {
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
9 header("Status: 404 Not Found");
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
10 die();
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
11 }
184a4188555c Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
12
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 // The defaults we put in
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 $siteDefaults = array(
103
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
16 "maxAttendeesHard" => array(VT_INT, 60, "Maximum attendees (HARD limit, 0 = no limit)"),
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
17 "maxAttendeesSoft" => array(VT_INT, 50, "Maximum attendees (soft limit, 0 = no limit)"),
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
19 "userTimeout" => array(VT_INT, 120, "User pages (voting, entry submission) timeout in minutes"),
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
20 "admTimeout" => array(VT_INT, 15, "Administration interface timeout in minutes"),
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
21
62
101cde58b267 Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
22 "showAdmin" => array(VT_BOOL, false, "Always show administration interface link on the menu"),
119
99e7569c9f4f Change the default of some boolean settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
23 "showAttendees" => array(VT_BOOL, true, "Show attendees list"),
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
24 "allowRegister" => array(VT_BOOL, false, "Enable event registration"),
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
25 "allowVoting" => array(VT_BOOL, false, "Enable voting (individual compos must be enabled as well)"),
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
26
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
27 "showResults" => array(VT_BOOL, false, "Enable results page"),
62
101cde58b267 Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
28 "showResultsASCII" => array(VT_BOOL, true, "Show results as ASCII instead of HTML table"),
119
99e7569c9f4f Change the default of some boolean settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
29 "showResAuthors" => array(VT_BOOL, true, "Show entry authors on results page"),
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
31 "requireEMail" => array(VT_BOOL, false, "Require e-mail address in registrations"),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
32
123
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
33 "showNews" => array(VT_BOOL, true, "Enable News link on main menu"),
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
34 "showNewsOnAbout" => array(VT_BOOL, true, "Show latest news item on About page"),
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
35
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
36 "registerInfoText" => array(VT_TEXT, "<p>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
37 Only your <b>handle</b> and the answer to the botcheck are strictly required.
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
38 If you plan on joining the IRC channel
63
922b5192b2ff Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
39 (<a href=\"irc://#fap2013@ircnet\">#fap2013 @ IRCNet</a>) or staying up to date by other means,
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
40 <b>e-mail</b> is not required either.
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
41 </p>", "Registration page info text"),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
42
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
43 "registerPostText" => array(VT_TEXT, "<p>Now go make a demo about it!</p>", "Successful post-registration note text"),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
44
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
45 "registerPostNoEmail" => array(VT_TEXT, "
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
46 <h2>By the way ...</h2>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
47 <p>As you did not specify an e-mail contact address, you'll have to get updates
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
48 and information about the location (if you don't already know it) by
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
49 some other means (IRC, for example.)</p>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
50 ", "No e-mail address registration note"),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
51
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
52 "eventDescription" => array(VT_TEXT, "
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
53 <h1>Event program &amp; schedule</h1>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
54 <ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
55 <li><b>Aegis</b> of DSS and FAG will be performing a DJ gig.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
56 <li>.. and possible additional live acts. More info to come.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
57 </ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
58
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
59 <h2>Friday 30.11.</h2>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
60 <ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
61 <li><b>18:00</b> - <i>Doors open</i>.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
62 <li><b>22:00</b> - DJ set by Aegis.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
63 </ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
64
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
65 <h2>Saturday 1.12.</h2>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
66 <ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
67 <li><b>14:00</b> - Deadline for remote entries.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
68 <li><b>18:00</b> - Deadline for the entries delivered on location.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
69 <li><b>20:00</b> - Competitions start.</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
70 </ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
71
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
72 Competition schedule and voting deadline will depend on number of entries.
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
73
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
74 <h2>Sunday 2.12.</h2>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
75 <ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
76 <li><b>12:00</b> - Party over?</li>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
77 </ul>
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
78 ", "Event general description / timetables etc."),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
79
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
80
14
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
81 "compoDescription" => array(VT_TEXT, "
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
82 <h1>General</h1>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
83 <p class=\"notice\">
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
84 YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY.
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
85 </p>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
86
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
87 <p class=\"note\">
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
88 If there are enough entries, then AGA/OCS/ECS demos will be run in separate compos.
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
89 <br />
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
90 Remote entries are welcome!
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
91 </p>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
92
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
93 <p>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
94 The compo machine will be an <b>A1200 with an 060/50 and lots of
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
95 RAM</b>. An <b>A500 1.3 512k/512k</b> will also be available if your
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
96 prod is not AGA compatible.
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
97 </p>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
98
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
99 <h1>Compos</h1>
e36c4d2b09c4 Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
100 ", "Compo general description"),
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
101
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
102
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
103 "siteInfoText" => array(VT_TEXT, "
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
104 <a href=\"news\">
47
73123e322133 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
105 <img src=\"img/fapsm.png\" alt=\"Finnish Amiga Party 2013\" class=\"logo\" /></a>
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
106 <div id=\"date\">
47
73123e322133 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
107 5.-8.12.2013<br />
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
108 Helsinki, Finland<br />
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
109 @ old location<br />
47
73123e322133 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
110 <span class=\"notice\">Entry 15 EUR + prod</span>
16
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
111 </div>", "Site header text"),
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
112
6da681d1f62a Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
113
123
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
114 "newsHeader" => array(VT_TEXT, "", "News page header text"),
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
115
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
116
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
117 "aboutDescription" => array(VT_TEXT, "
9
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
118 <div style=\"text-align: center;\">
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
119 <img src=\"img/fap.png\" alt=\"FAP\" />
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
120 <p>
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
121 Pure Amiga demoscene party, all traditional Amiga compos and purely Amiga-oriented program.
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
122 <br />
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
123 <span class=\"notice\">
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
124 YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY.
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
125 </span>
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
126 </p>
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
127 </div>",
123
5837b9333964 Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
128 "About page text"),
29
4b5a176805e2 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
129
4b5a176805e2 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
130
4b5a176805e2 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
131 "entrySubmitInfo" => array(VT_TEXT, "Rules for entry submission ... ", "Entry submission information blurb"),
43
66ab7d43f8a1 Add a new setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
132
104
c7b1eb993240 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
133 "siteMenuHeader" => array(VT_TEXT, "<div>13.FAP:&gt; <span class=\"mblink\">&#9632;</span></div>", "Site menu header text"),
47
73123e322133 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
134 "siteMenuFooter" => array(VT_TEXT, "", "Site menu footer text"),
106
324f3a415237 Add extra HTML + sponsors box to layout.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
135 "siteExtraHTML" => array(VT_TEXT, "<div id=\"sponsors\">Gentle Eye</div>", "Extra global HTML code (f.e. sponsors box)"),
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 );
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 $sqlTables = array(
73
c70c2650f790 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
139 "settings" => "key VARCHAR(32) PRIMARY KEY, vtype INT, vstr VARCHAR(128), vtext TEXT, vint INT, desc VARCHAR(128)",
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 "news" => "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, title VARCHAR(128), text VARCHAR(4096), author VARCHAR(64), persist INT DEFAULT 0",
55
4fac95384753 Make visibility of entry authors per compo.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
141 "compos" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(128), description VARCHAR(4096), visible INT DEFAULT 0, voting INT DEFAULT 0, showAuthors INT DEFAULT 0",
113
671330b7f5d1 Add "show_id" to compo entries, to designate the position they were shown at
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
142 "entries" => "id INTEGER PRIMARY KEY AUTOINCREMENT, show_id INT DEFAULT 0, name VARCHAR(64), author VARCHAR(64), compo_id INT DEFAULT NULL, filename VARCHAR(256) DEFAULT NULL",
73
c70c2650f790 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
143
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
144 "attendees" => "id INTEGER PRIMARY KEY AUTOINCREMENT, regtime INT, name VARCHAR(64), groups VARCHAR(64), oneliner VARCHAR(64), email VARCHAR(80), key_id INT DEFAULT NULL",
73
c70c2650f790 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
145
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
146 "votekeys" => "id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR(64), active INT DEFAULT 0",
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
147
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 "votes" => "id INTEGER PRIMARY KEY AUTOINCREMENT, entry_id INT DEFAULT NULL, voter_id INT DEFAULT NULL, value INT DEFAULT 0",
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 );
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
151 $siteTestData = array(
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
152 "news" => array(
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
153 "utime,title,text,author",
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
154 time().",%s,%s,%s",
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
155 array("Today's news", "We. Are. Back.", "orgaz"),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
156 array("Good news, everybody!", "...", "The Professor"),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
157 ),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
158
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
159 "votekeys" => array(
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
160 "key",
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
161 "%s",
120
2c594958050e Make test vote keys "testN" where N >= 1
Matti Hamalainen <ccr@tnsp.org>
parents: 119
diff changeset
162 array("test1"),
2c594958050e Make test vote keys "testN" where N >= 1
Matti Hamalainen <ccr@tnsp.org>
parents: 119
diff changeset
163 array("test2"),
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
164 array("7jjnqt5z"),
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
165 array("c7jcfk1G"),
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
166 ),
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
167
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
168 "attendees" => array(
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
169 "regtime,name,groups,oneliner,email",
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
170 "%d,%s,%s,%s,%s",
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
171 array(time()-0, "man with no alias", "supergroup", "foo-bar", "c@supergroup.com"),
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
172 array(time()-15, "man with alias", "supergroup", "hi!", "c@supergroup.com"),
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
173 array(time()-30, "alias with a man", "supergroup", "mega super kewl rulets", "x@microsoft.com"),
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
174 ),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
175
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
176 "compos" => array(
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
177 "name,description,visible,voting",
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
178 "%s,%s,1,1",
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
179 array("Graphics", "Anything in standard resolutions."),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
180 array("Protracker music", "Standard 4-channel Protracker MOD music."),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
181 ),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
182
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
183 "entries" => array(
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
184 "name,author,compo_id,filename",
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
185 "%s,%s,%d,%s",
89
6fdde6aca7ba More test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
186 array("my dong", "visualice/hjb", 1, "juice.lbm"),
6fdde6aca7ba More test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
187 array("kondom", "ccr/TNSP", 1, "kondom.lbm"),
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
188 array("penis song", "reed/flt", 2, "penis.mod"),
89
6fdde6aca7ba More test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
189 array("jenkka", "aegis", 2, "jenkka.mod"),
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
190 ),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
191 );
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
193
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 //
36
ace577c92a32 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
195 // Helper functions
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 //
100
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
197 function stCArg($index)
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
198 {
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
199 global $argc, $argv;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
200 if ($index < $argc)
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
201 return $argv[$index];
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
202 else
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
203 return FALSE;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
204 }
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
205
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
206 function stCArgLC($index)
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
207 {
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
208 global $argc, $argv;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
209 if ($index < $argc)
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
210 return strtolower($argv[$index]);
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
211 else
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
212 return FALSE;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
213 }
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
214
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
215
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
216 function stCSQLError($sql)
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
217 {
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
218 global $db;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
219 die("Error executing SQL query: ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"\n");
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
220 exit;
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
221 }
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
222
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
223
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 function stConnectDB($dbspec)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 global $db;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 try {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 $db = new PDO($dbspec);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 catch (PDOException $e) {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 error_log("Could not connect to SQL database '".$dbspec."': ".$e->getMessage().".");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 return FALSE;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 return TRUE;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
238 function stCreateOneTable($name, $schema)
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
239 {
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
240 return (stExecSQL("CREATE TABLE ".$name." (".$schema.")") !== FALSE) ? TRUE : FALSE;
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
241 }
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
242
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
243
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 function stCreateTables()
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 global $sqlTables;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 echo "Creating tables...\n";
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 foreach ($sqlTables as $name => $schema)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 echo " - '".$name."'\n";
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
251 if (!stCreateOneTable($name, $schema))
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 return FALSE;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 return TRUE;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 function stAddSettings()
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 global $siteDefaults;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 echo "Adding settings to settings table.\n";
80
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
262
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
263 foreach ($siteDefaults as $key => $data)
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 {
80
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
265 switch ($data[0])
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 case VT_TEXT: $type = "%s"; $var = "vtext"; break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 case VT_STR: $type = "%s"; $var = "vstr"; break;
72
63a6caf59e5c Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
269 case VT_BOOL: $type = "%b"; $var = "vint"; break;
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 case VT_INT: $type = "%d"; $var = "vint"; break;
80
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
271 default: die("Invalid type in default settings '".$key."', type=".$data[0]."\n");
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 $sql = stPrepareSQL(
11
c10bf196390f Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
275 "INSERT INTO settings (key,vtype,".$var.",desc) VALUES (%s,%d,".$type.",%s)",
80
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
276 $key, $data[0], $data[1], $data[2]);
e51205f2bdd0 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
277
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 stExecSQL($sql);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
283 function stAddTestData()
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
284 {
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
285 global $siteTestData;
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
286 echo "Adding test data.\n";
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
287
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
288 foreach ($siteTestData as $table => $data)
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
289 {
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
290 echo " - ".$table."...\n";
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
291 if (count($data) >= 3)
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
292 {
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
293 for ($n = 2; $n < count($data); $n++)
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
294 {
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
295 $arr = array_merge(
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
296 array("INSERT INTO ".$table." (".$data[0].") VALUES (".$data[1].")"),
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
297 $data[$n]);
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
298
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
299 $sql = call_user_func_array('stPrepareSQL', $arr);
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
300 stExecSQL($sql);
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
301 }
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
302 }
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
303 else
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
304 {
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
305 echo " Invalid table / data definition.\n";
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
306 }
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
307 }
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
308 }
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
309
36
ace577c92a32 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
310 //
ace577c92a32 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
311 // Main program starts
ace577c92a32 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
312 //
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 if ($argc < 2)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 echo "Usage: ".$argv[0]." <mode> [args]\n".
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 "Where mode is one of following:\n".
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 "\n".
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 " new [dbspec] Create a new database with given PDO spec\n".
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 " or default to the one in mconfig.inc.php\n".
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 "\n".
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
321 " test [dbspec] Like new, but add initial test data.\n".
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 "\n";
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 exit;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
327 if (!isset($siteSettings["voteKeyMode"]) || $siteSettings["voteKeyMode"] < 0)
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
328 {
100
3939cb04bdce Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
329 echo "FATAL ERROR! VoteKeyMode not set in site settings! This setting ".
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
330 "MUST be defined and should not be changed after database creation.\n";
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
331 exit;
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
332 }
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
333
81
491c03e3a2bc Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
334 // Check if database spec provided, if not use default
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 if (($spec = stCArg(2)) === FALSE)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 $spec = $siteSettings["sqlDB"];
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338
81
491c03e3a2bc Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
339 // Try to connect to database
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 if (!stConnectDB($spec))
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 die("Could not connect to SQL database '".$spec."'.\n");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 echo "Using database spec '".$spec."'.\n";
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
345
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
346 // Act according to specified command
88
784953d60ba5 More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
347 $addData = FALSE;
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
348 switch (stCArgLC(1))
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 {
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
350 case "test":
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
351 $addData = TRUE;
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
352
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 case "new":
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 if (stCreateTables())
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 stAddSettings();
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
356
85
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
357 if ($addData)
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
358 stAddTestData();
50d6c69836a1 Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
359
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
360 if (substr($spec, 0, 7) == "sqlite:")
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
361 {
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
362 $filename = substr($spec, 7);
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
363 echo "NOTICE! It seems you have SQLite database in use, changing permission ".
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
364 "of the target file '".$filename."' to 0600, for security. You may have to ".
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
365 "loosen up that for the things to actually work, but be careful. Having your ".
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
366 "database world-readable in the web is NOT good.\n";
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
367
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
368 if (chmod($filename, 0600) === FALSE)
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
369 {
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
370 echo "ERROR! Could not set permissions!\n";
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
371 }
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
372 }
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374
27
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
375 default:
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
376 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
b27204653615 Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
377 break;
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
28
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
380
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
381 //
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
382 // Clean up permissions
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
383 //
67
23eba98e1575 Remove keygen.php from permission cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
384 foreach (array("createdb.php") as $filename)
28
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
385 {
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
386 if (chmod($filename, 0700) === FALSE)
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
387 {
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
388 echo "ERROR! Could not set permissions for '$filename'!\n";
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
389 }
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
390 }
bf567e6402bf Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
391
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 ?>