createvoteids1.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <link rel="stylesheet" type="text/css" href="css/style.css">
  6. <head>
  7. <title>An African Language Short Story Competition</title>
  8. </head>
  9. <body>
  10. <?php include 'submitdatabaseinfo1.php';?>
  11. <?php
  12. $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  13. function generate_string($input, $strength = 18) {
  14. $input_length = strlen($input);
  15. $random_string = '';
  16. for($i = 0; $i < $strength; $i++) {
  17. $random_character = $input[mt_rand(0, $input_length - 1)];
  18. $random_string .= $random_character;
  19. }
  20. return $random_string;
  21. }
  22. if (isset($_POST['createandmailids'])) {
  23. // Create connections
  24. $conn = mysqli_connect($servername, $username, $password, $dbname);
  25. mysqli_set_charset($conn, "utf8");
  26. // Check connection
  27. if (!$conn) {
  28. die("Database connection failed: " . mysqli_connect_error());
  29. }
  30. $connvoteid = mysqli_connect($servername, $username, $password, $dbvoteid);
  31. mysqli_set_charset($connvoteid, "utf8");
  32. // Check connection
  33. if (!$connvoteid) {
  34. die("Database connection failed: " . mysqli_connect_error());
  35. }
  36. $sql = "SELECT DISTINCT email FROM originalstories WHERE checked = 'yes'";
  37. $result = mysqli_query($conn,$sql);
  38. $rows = mysqli_num_rows($result);
  39. if ( $rows > 0 ) {
  40. while($row = mysqli_fetch_array($result)){
  41. $rows2 = 1;
  42. while ($rows2 > 0){
  43. $voteid = generate_string($permitted_chars, 180);
  44. $sql2 = "SELECT PrimaryKey FROM voteid WHERE voteid = '.$voteid.'";
  45. $result2 = mysqli_query($connvoteid,$sql2);
  46. $rows2 = mysqli_num_rows($result2);
  47. }
  48. $sql2 = "SELECT DISTINCT language FROM originalstories WHERE email = '".$row["email"]."'";
  49. $result2 = mysqli_query($conn,$sql2);
  50. $numlangs = mysqli_num_rows($result2);
  51. $languages = "";
  52. while( $row2 = mysqli_fetch_array($result2)){
  53. $languages .= $row2["language"] . " ";
  54. }
  55. $email = $row["email"];
  56. $sql2 = "INSERT INTO voteid (email, voteid, languages) VALUES ('" . $row["email"] . "','" . $voteid . "','" .$languages . "')";
  57. if (mysqli_query($connvoteid, $sql2)) {
  58. echo "New record created successfully";
  59. $to = $email;
  60. $subject = "Story Evaluation";
  61. $txt = "The evaluation phase has begun. You may evaluate stories in languages in which you have made a submission. Please go to https://tuvutepamoja.africa/evaluate.php and enter your personal and private voting code:\n" . $voteid . "\n to find stories you can evaluate. If you submit multiple evaluations of the same story, your last evaluation for each story will be the one that is counted, so please save this email with your voter identification number. In some languages, only a few stories were submitted, so it will not be possible for your evaluation to be anonymous. In cases where several submissions were made, competition organizers do have access to voting information, but will only make average scores and comments public. We hope to implement fully anonymous voting in future. Please also let us know if you have any other suggestions for improvements as we will shortly be running this competition again. Should you have any questions, please contact us at \n lugha@tuvutepamoja.africa \n Sincerely,\nThe organizing committee.\n\n";
  62. $txt = wordwrap($txt , 70);
  63. $headers = "From: lugha@tuvutepamoja.africa" . "\r\nContent-Type: text/plain; charset=UTF-8";
  64. mail($to,$subject,$txt,$headers);
  65. } else {
  66. echo "Error creating database record, please contact lugha@tuvutepamoja.africa.";
  67. //echo $sql2 . "<br>" . mysqli_error($connvoteid);
  68. }
  69. }
  70. }
  71. mysqli_close($connvoteid);
  72. mysqli_close($conn);
  73. exit;
  74. }
  75. ?>
  76. <header>
  77. <h1>Tuvute Pamoja
  78. <a href="https://deeplearningindaba.com">
  79. <img src="images/deeplearningindaba.svg" alt="Deeplearning Indaba" style="height:60px">
  80. </a></h1>
  81. </header>
  82. <form method="post">
  83. <input type="submit" name="createandmailids" value="Create and Mail Ids"/>
  84. </form>
  85. </body>
  86. </html>