science-ation/scripts/populate_fake.php

138 lines
4.5 KiB
PHP
Raw Permalink Normal View History

<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
2005-01-24 18:00:03 +00:00
?>
<?
echo "To run this script, edit it and comment out the 'exit' (and this message) at the beginning";
// exit;
include '../common.inc.php';
$numprojects = 150;
function getrand($ar)
{
return $ar[rand(0, count($ar) - 1)];
}
// the following work as one in x where x is the number below
$prob_dual = 3;
$prob_unpaid = 10;
$firstnames = array('James', 'Bob', 'Ali', 'Erin', 'Julia', 'Dave', 'Steve', 'Bryan', 'Jane', 'Elizabeth', 'Norm', 'Sue', 'Eric', 'Terry', 'Arthur', 'Angel', 'Allison', 'Jeremy', 'Jacqueline', 'Derek', 'Kristen', 'Greg', 'Cheryl', 'Debbie', 'Heather', 'Donald', 'Linda', 'George', 'Patrica', 'Carmel', 'Dawn', 'Scott', 'Brad', 'Bruce', 'Paul', 'Guillaume');
$lastnames = array('Grant', 'Browning', 'Mehdi', 'Borque', 'Temple', 'Culhane', 'Sargent', 'Sing', 'Belanger', 'Desjardin', 'Jones', 'Smith', 'Brown', 'Johnson', 'Williams', 'White', 'Thompson', 'Baker');
$domains = array('lightbox.org', 'microsoft.com', 'yahoo.com', 'msn.com', 'gmail.com', 'reach.net', 'slicer.ca', 'cwsf.ca', 'sfiab.ca');
$nouns = array('age', 'animal', 'arm', 'baby', 'ball', 'bat', 'bear', 'boat', 'camp', 'car', 'child', 'circle', 'city', 'cotton', 'design', 'dog', 'dress', 'duck', 'ear', 'egg', 'enemy');
$starters = array('effects of', 'study of', 'analysis of');
$joiners = array('on', 'combined with', 'broken apart by', 'burned with', 'attacked by', 'left alone with');
$numschools = $pdo->prepare("SELECT id FROM schools WHERE year='2011'");
2024-12-10 19:40:23 -05:00
$numschools->execute();
while ($s = $numschools->fetch(PDO::FETCH_OBJ)) {
// 1 in 4 chance of actually using this school
$o = rand(1, 4);
if ($o == 1)
$schools[] = $s->id;
}
$ns = count($schools);
for ($x = 0; $x < $numprojects; $x++) {
$id = 0;
$regnum = rand(100000, 999999);
$email = strtolower(getrand($firstnames) . '@' . getrand($domains));
$pd = rand(1, $prob_unpaid);
if ($pd == 1)
$status = 'paymentpending';
else
$status = 'complete';
2025-02-09 17:24:37 +00:00
$q = $pdo->prepare("INSERT INTO registrations (num,email,start,status,year) VALUES (?,?,NOW(),?,2011)");
$q->execute([$regnum,$email,$status]);
if ($id = $pdo->lastInsertId()) {
$peeps = rand(1, $prob_dual);
if ($peeps == 1)
$num = 2;
else
$num = 1;
$gradenum = rand(1, 10);
if ($gradenum < 7) {
$grade = rand(7, 8);
$cat = 1;
} else if ($gradenum < 9) {
$grade = rand(9, 10);
$cat = 2;
} else if ($gradenum < 10) {
$grade = rand(11, 12);
$cat = 3;
}
$schools_id = $schools[rand(0, $ns)];
for ($a = 1; $a <= $num; $a++) {
$sexnum = rand(1, 3);
if ($sexnum < 3)
$sex = 'male';
else
$sex = 'female';
$firstname = getrand($firstnames);
$email = strtolower($firstname) . '@' . getrand($domains);
2025-02-09 17:24:37 +00:00
$stmt = $pdo->prepare("INSERT INTO students (registrations_id,firstname,lastname,email,sex,grade,year,schools_id) VALUES (?,?,?,?,?,?,'2011',?)");
$stmt->execute([$id,$firstname,getrand($lastnames),$email,$sex,$grade,$schools_id]);
}
$div = rand(1, 6);
$title = ucwords(getrand($starters) . ' ' . getrand($nouns) . ' ' . getrand($joiners) . ' ' . getrand($nouns));
$req_enum = rand(1, 4);
if ($req_enum == 1)
$req_e = 'yes';
else
$req_e = 'no';
$req_tnum = rand(1, 30);
if ($req_tnum == 1)
$req_t = 'no';
else
$req_t = 'yes';
$langnum = rand(1, 10);
if ($langnum < 4)
$lang = 'fr';
else
$lang = 'en';
2025-02-09 17:24:37 +00:00
$stmt = $pdo->prepare("INSERT INTO projects (registrations_id,projectcategories_id,projectdivisions_id,title,year,req_electricity,req_table,language) VALUES (?,?,?,? ?,2011,?,?,?)");
$stmt->execute([$id,$cat,$div,$title,$lang,$req_e,$req_t,$lang]);
}
}
?>