PageRenderTime 27ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/install/index.php

https://github.com/jomartigcal/cvsea
PHP | 239 lines | 210 code | 7 blank | 22 comment | 17 complexity | 54921f1149fb93e4d95530e746ae0f58 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2006-2011 University of the Philippines Linux Users' Group
  4. *
  5. * This file is part of Halalan.
  6. *
  7. * Halalan is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Halalan is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Halalan. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. // define BASEPATH so we can access application/config/database.php
  21. // yes, that is the only purpose of this
  22. // so we can put any value here
  23. define('BASEPATH', '');
  24. require_once('../system/application/config/database.php');
  25. extract($db['default']);
  26. $missing_driver = false;
  27. if (empty($dbdriver) || $dbdriver != 'mysql')
  28. {
  29. $missing_driver = true;
  30. }
  31. else
  32. {
  33. $misconfigured_settings = false;
  34. $link = @mysql_connect($hostname, $username, $password);
  35. if (!$link)
  36. {
  37. $misconfigured_settings = true;
  38. }
  39. else
  40. {
  41. $db_selected = @mysql_select_db($database, $link);
  42. if (!$db_selected)
  43. {
  44. $misconfigured_settings = true;
  45. }
  46. else
  47. {
  48. $query = "SELECT * FROM admins";
  49. $result = @mysql_query($query);
  50. $test = FALSE;
  51. while ($row = @mysql_fetch_array($result))
  52. {
  53. if (!empty($row))
  54. {
  55. $test = TRUE;
  56. break;
  57. }
  58. }
  59. if ($test)
  60. {
  61. echo "Halalan is already installed.";
  62. exit;
  63. }
  64. }
  65. }
  66. }
  67. ?>
  68. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  69. <html xmlns="http://www.w3.org/1999/xhtml">
  70. <head>
  71. <title>Halalan - Install</title>
  72. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  73. <link rel="stylesheet" type="text/css" href="stylesheets/main.css" />
  74. </head>
  75. <body>
  76. <div id="wrap">
  77. <div id="header">
  78. <img src="images/logo.png" alt="logo" />
  79. </div>
  80. <div class="body">
  81. <div class="center_body">
  82. <?php
  83. if ($missing_driver)
  84. {
  85. ?>
  86. <fieldset>
  87. <legend class="position">Error</legend>
  88. <p>It seems like your database driver is missing or misconfigured.<br />Please correct it at system/application/config/database.php.</p>
  89. </fieldset>
  90. <?php
  91. }
  92. else if ($misconfigured_settings)
  93. {
  94. ?>
  95. <fieldset>
  96. <legend class="position">Error</legend>
  97. <p>It seems like your database settings are misconfigured.<br />Please correct it at system/application/config/database.php.</p>
  98. </fieldset>
  99. <?php
  100. }
  101. else
  102. {
  103. ?>
  104. <fieldset>
  105. <legend class="position">Welcome to the Halalan Installer!</legend>
  106. <table cellspacing="2" cellpadding="2" width="100%">
  107. <tr>
  108. <td><p>Halalan is an open-source voting system designed for student elections. It aims to automate the manual processes of elections such as counting, archiving, and voting. It is designed to be easy-to-use and secure.</p><p>Please fill up the form below. All fields are required. Take note that <span style="color : red; ">changing the election settings after you have entered some data will break the system</span> so please review them carefully.</p></td>
  109. </tr>
  110. </table>
  111. </fieldset>
  112. <form method="post" action="ok.php">
  113. <fieldset>
  114. <legend class="position">Administrator Settings</legend>
  115. <table cellspacing="2" cellpadding="2" width="100%">
  116. <tr>
  117. <td class="w35">First Name</td>
  118. <td><input type="text" name="first_name" maxlength="63" /></td>
  119. </tr>
  120. <tr>
  121. <td class="w35">Last Name</td>
  122. <td><input type="text" name="last_name" maxlength="31" /></td>
  123. </tr>
  124. <tr>
  125. <td class="w35">Email</td>
  126. <td><input type="text" name="email" maxlength="63" /></td>
  127. </tr>
  128. </table>
  129. </fieldset>
  130. <fieldset>
  131. <legend class="position">Election Settings</legend>
  132. <table cellspacing="2" cellpadding="2" width="100%">
  133. <tr>
  134. <td class="w35">URL</td>
  135. <td>
  136. <?php
  137. // simple URL autodetection; cannot cover all use cases so give the user freedom to edit
  138. $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
  139. $url = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  140. $url = substr($url, 0, mb_strrpos($url, 'install'));
  141. ?>
  142. <input type="text" name="url" size="40" value="<?php echo $url; ?>" /><br />with trailing slash
  143. </td>
  144. </tr>
  145. <tr>
  146. <td class="w35">PIN</td>
  147. <td><label><input type="checkbox" name="pin" value="TRUE" /> use in ballot validation?</label></td>
  148. </tr>
  149. <tr>
  150. <td class="w35">Password and PIN Generation</td>
  151. <td><select name="password_pin_generation"><option value="web" selected="selected">Web</option><option value="email">Email</option></select></td>
  152. </tr>
  153. <tr>
  154. <td class="w35">Password and PIN Characters</td>
  155. <td><select name="password_pin_characters"><option value="alnum" selected="selected">Alphanumeric</option><option value="numeric">Numeric</option><option value="nozero">No Zero</option></select></td>
  156. </tr>
  157. <tr>
  158. <td class="w35">Password Length</td>
  159. <td><select name="password_length">
  160. <?php for ($i = 4; $i < 11; $i++) { ?>
  161. <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  162. <?php } ?>
  163. </select></td>
  164. </tr>
  165. <tr>
  166. <td class="w35">PIN Length</td>
  167. <td><select name="pin_length">
  168. <?php for ($i = 4; $i < 11; $i++) { ?>
  169. <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  170. <?php } ?>
  171. </select></td>
  172. </tr>
  173. <tr>
  174. <td class="w35">CAPTCHA</td>
  175. <td><label><input type="checkbox" name="captcha" value="TRUE" /> use in ballot validation?</label></td>
  176. </tr>
  177. <tr>
  178. <td class="w35">CAPTCHA Length</td>
  179. <td><select name="captcha_length">
  180. <?php for ($i = 4; $i < 11; $i++) { ?>
  181. <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  182. <?php } ?>
  183. </select></td>
  184. </tr>
  185. <!--<tr>
  186. <td class="w35">Language</td>
  187. <td><select name="language"><option value="english">English</option><option value="filipino">Filipino</option></select></td>
  188. </tr>-->
  189. <tr>
  190. <td class="w35">Candidate Details</td>
  191. <td><label><input type="checkbox" name="details" value="TRUE" /> show in ballot?</label></td>
  192. </tr>
  193. <!--<tr>
  194. <td class="w35">Candidate Order</td>
  195. <td><label><input type="checkbox" name="random" value="TRUE" /> randomize order in ballot?</label></td>
  196. </tr>-->
  197. <tr>
  198. <td class="w35">Virtual Paper Trail</td>
  199. <td><label><input type="checkbox" name="image_trail" value="TRUE" /> generate virtual paper trail (image file)?</label></td>
  200. </tr>
  201. <tr>
  202. <td class="w35">Virtual Paper Trail Path</td>
  203. <td><input type="text" name="image_trail_path" size="40" value="/var/www/html/w/" /><br />with trailing slash</td>
  204. </tr>
  205. <!--<tr>
  206. <td class="w35">Real-time Results</td>
  207. <td><label><input type="checkbox" name="realtime_results" value="TRUE" /> enable real-time results (for admins only)?</label></td>
  208. </tr>-->
  209. </table>
  210. </fieldset>
  211. <fieldset>
  212. <legend class="position"></legend>
  213. <table cellspacing="2" cellpadding="2" width="100%">
  214. <tr>
  215. <td align="center"><input type="submit" value="Install" /></td>
  216. </tr>
  217. </table>
  218. </fieldset>
  219. </form>
  220. <?php
  221. }
  222. ?>
  223. </div>
  224. <div class="clear"></div>
  225. </div>
  226. <div id="footer">
  227. <br />
  228. &copy; University of the Philippines Linux Users' Group (UnPLUG)
  229. </div>
  230. </div>
  231. </body>
  232. </html>