From 38d397043ea4c86546144b7e10c766468f7258bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 22 Apr 2010 18:26:41 +0200 Subject: [PATCH 01/10] Skeleton for AddPointsController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../controllers/AddPointsController.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 manager/application/controllers/AddPointsController.php diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php new file mode 100644 index 0000000..89ade78 --- /dev/null +++ b/manager/application/controllers/AddPointsController.php @@ -0,0 +1,17 @@ + Date: Mon, 26 Apr 2010 20:57:27 +0200 Subject: [PATCH 02/10] Construct and display the AddPoints view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * define input form (draft) * create the view and make it display the form * add a link to the view in the topNav Signed-off-by: Michael Tänzer --- .../controllers/AddPointsController.php | 40 +++++++++++++- .../views/scripts/add-points/index.phtml | 14 +++++ manager/library/actions/ActionAddPoints.php | 53 +++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 manager/application/views/scripts/add-points/index.phtml create mode 100644 manager/library/actions/ActionAddPoints.php diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index 89ade78..ff66f0b 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -12,6 +12,44 @@ class AddPointsController extends Zend_Controller_Action public function indexAction() { - /* TODO */ + $this->view->assurance_form = $this->getAssuranceForm(); + $this->render('index'); + } + + public function assuranceAction() + { + /* Validate form */ + if (!$this->getRequest()->isPost()) { + return $this->_forward('index'); + } + + $form = $this->getAssuranceForm(); + if (!$form->isValid($_POST)) { + $this->view->assurance_form = $form; + return $this->render('index'); + } + + + /* Form is valid -> get values and process them */ + $values = $form->getValues(); + } + + protected function getAssuranceForm() + { + $form = new Zend_Form(); + $form->setAction('/add-points/assurance')->setMethod('post'); + + $quantity = new Zend_Form_Element_Text('quantity'); + $quantity->setRequired(true) + ->setLabel(I18n::_('Number of Points')) + ->addFilter(new Zend_Filter_Int()) + ->addValidator(new Zend_Validate_Between(0, 100)); + $form->addElement($quantity); + + $submit = new Zend_Form_Element_Submit('submit'); + $submit->setLabel(I18n::_('Assure Me')); + $form->addElement($submit); + + return $form; } } diff --git a/manager/application/views/scripts/add-points/index.phtml b/manager/application/views/scripts/add-points/index.phtml new file mode 100644 index 0000000..b627b78 --- /dev/null +++ b/manager/application/views/scripts/add-points/index.phtml @@ -0,0 +1,14 @@ + + +

+ +

+

+

+assurance_form ?> diff --git a/manager/library/actions/ActionAddPoints.php b/manager/library/actions/ActionAddPoints.php new file mode 100644 index 0000000..ef71b2f --- /dev/null +++ b/manager/library/actions/ActionAddPoints.php @@ -0,0 +1,53 @@ + Date: Thu, 29 Apr 2010 15:27:33 +0200 Subject: [PATCH 03/10] Flesh out AddPointsController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement procedure as in the live code (notification emails are not sent) - Add more elements to the form Signed-off-by: Michael Tänzer --- .../controllers/AddPointsController.php | 117 +++++++++++++++++- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index ff66f0b..95b1d5f 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -5,9 +5,18 @@ class AddPointsController extends Zend_Controller_Action { + const MAX_POINTS_PER_ASSURANCE = 35; + const MAX_ASSURANCE_POINTS = 100; + + protected $db; + public function init() { - /* Initialize action controller here */ + $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', + APPLICATION_ENV); + + $this->db = Zend_Db::factory($config->ca_mgr->db->auth->pdo, + $config->ca_mgr->db->auth); } public function indexAction() @@ -18,7 +27,7 @@ class AddPointsController extends Zend_Controller_Action public function assuranceAction() { - /* Validate form */ + // Validate form if (!$this->getRequest()->isPost()) { return $this->_forward('index'); } @@ -29,9 +38,95 @@ class AddPointsController extends Zend_Controller_Action return $this->render('index'); } - - /* Form is valid -> get values and process them */ + // Form is valid -> get values for processing $values = $form->getValues(); + + + // Check identity of the user + $session = Zend_Registry::get('session'); + if ($session->authdata['authed'] !== true) { + throw new Exception(__METHOD__ . ': you need to log in to use this feature'); + } + $query = 'select `id` from `users` where `id` = :user'; + $query_params['user'] = $session->authdata['authed_id']; + $result = $this->db->query($query, $query_params); + if ($result->rowCount() !== 1) { + throw new Exception(__METHOD__ . ': user ID not found in the data base'); + } + $row = $result->fetch(); + $user['id'] = $row['id']; + + + // Get the first assurer who didn't already assure the user + $query = 'select min(`id`) as `assurer` from `users` ' . + 'where `email` like \'john.doe-___@example.com\' and ' . + '`id` not in (select `from` from `notary` where `to` = :user)'; + $query_params['user'] = $user['id']; + $row = $this->db->query($query, $query_params)->fetch(); + if ($row['assurer'] === NULL) { + throw new Exception(__METHOD__ . ': no more assurers that haven\'t '. + 'already assured this account'); + } + $assurer = $row['assurer']; + + + // Get current points of the user + $query = 'select sum(`points`) as `total` from `notary` where `to` = :user'; + $query_params['user'] = $user['id']; + $row = $this->db->query($query, $query_params)->fetch(); + if ($row['total'] === NULL) $row['total'] = 0; + $user['points'] = $row['total']; + + + // Do the actual assurances + $assurance = array(); // Make sure the array is empty + $assurance['from'] = $assurer; + $assurance['to'] = $user['id']; + $assurance['location'] = $values['location']; + $assurance['date'] = $values['date']; + $assurance['when'] = new Zend_Db_Expr('now()'); + $this->view->assurancesDone = array(); + + $points = $values['quantity']; + do { + // split up into multiple assurances + if ($points > MAX_POINTS_PER_ASSURANCE) { + $assurance['awarded'] = MAX_POINTS_PER_ASSURANCE; + $points -= MAX_POINTS_PER_ASSURANCE; + } else { + $assurance['awarded'] = $points; + $points = 0; + } + + // only assign points whithin the limit + if ($user['points'] + $assurance['awarded'] > MAX_ASSURANCE_POINTS){ + $assurance['points'] = MAX_ASSURANCE_POINTS - $user['points']; + } else { + $assurance['points'] = $assurance['awarded']; + } + + $this->db->insert('notary', $assurance); + + $user['points'] += $assurance['points']; + $this->view->assurancesDone[] = $assurance['points']; + } while ($points > 0); + + + // Fix the assurer flag + $where = array(); + $query = '`users`.`id` = :user'; + $query_params['user'] = $user['id']; + $where[] = $this->db->quoteInto($query, $query_params); + $query = 'exists(select * from `cats_passed` as `cp`, ' . + '`cats_variant` as `cv` where `cp`.`variant_id` = `cv`.`id` and ' . + '`cv`.`type_id` = 1 and `cp`.`user_id` = :user'; + $where[] = $this->db->quoteInto($query, $query_params); + $query = '(select sum(`points`) from `notary` where `to`= :user and ' . + '`expire` > now()) >= 100'; + $where[] = $this->db->quoteInto($query, $query_params); + $this->db->update('users', array('assurer' => 1), $where); + + return; } protected function getAssuranceForm() @@ -46,6 +141,20 @@ class AddPointsController extends Zend_Controller_Action ->addValidator(new Zend_Validate_Between(0, 100)); $form->addElement($quantity); + $location = new Zend_Form_Element_Text('location'); + $location->setRequired(true) + ->setLabel(I18n::_('Location')) + ->setValue(I18n::_('CACert Test Manager')) + ->addValidator(new Zend_Validate_StringLength(1,255)); + $form->addElement($location); + + $date = new Zend_Form_Element_Text('date'); + $date->setRequired(true) + ->setLabel(I18n::_('Date of Assurance')) + ->setValue(date('Y-m-d H:i:s')) + ->addValidator(new Zend_Validate_StringLength(1,255)); + $form->addElement($date); + $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel(I18n::_('Assure Me')); $form->addElement($submit); From 4af9e0a9bb36fb187941f1a397e2548a0472317f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 20:42:37 +0200 Subject: [PATCH 04/10] Add view for add-points/assurance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../views/scripts/add-points/assurance.phtml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 manager/application/views/scripts/add-points/assurance.phtml diff --git a/manager/application/views/scripts/add-points/assurance.phtml b/manager/application/views/scripts/add-points/assurance.phtml new file mode 100644 index 0000000..db45e0a --- /dev/null +++ b/manager/application/views/scripts/add-points/assurance.phtml @@ -0,0 +1,20 @@ + + +

+ +

+ + + + + + + assurancesDone as $i => $points) { + printf('', $i, $points); + }?> + +
#
%1$d %2$d
From ac7f1ba03d7f8349498a5c2cfc8035f82a2729c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 20:49:27 +0200 Subject: [PATCH 05/10] Class constants have to be prefixed with self:: in PHP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../application/controllers/AddPointsController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index 95b1d5f..1b3380b 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -90,17 +90,17 @@ class AddPointsController extends Zend_Controller_Action $points = $values['quantity']; do { // split up into multiple assurances - if ($points > MAX_POINTS_PER_ASSURANCE) { - $assurance['awarded'] = MAX_POINTS_PER_ASSURANCE; - $points -= MAX_POINTS_PER_ASSURANCE; + if ($points > self::MAX_POINTS_PER_ASSURANCE) { + $assurance['awarded'] = self::MAX_POINTS_PER_ASSURANCE; + $points -= self::MAX_POINTS_PER_ASSURANCE; } else { $assurance['awarded'] = $points; $points = 0; } // only assign points whithin the limit - if ($user['points'] + $assurance['awarded'] > MAX_ASSURANCE_POINTS){ - $assurance['points'] = MAX_ASSURANCE_POINTS - $user['points']; + if ($user['points'] + $assurance['awarded'] > self::MAX_ASSURANCE_POINTS){ + $assurance['points'] = self::MAX_ASSURANCE_POINTS - $user['points']; } else { $assurance['points'] = $assurance['awarded']; } From e93541c58f2888a53d8eaf51496b20a2a6256f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 21:18:14 +0200 Subject: [PATCH 06/10] Refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../controllers/AddPointsController.php | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index 1b3380b..86557f3 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -57,17 +57,8 @@ class AddPointsController extends Zend_Controller_Action $user['id'] = $row['id']; - // Get the first assurer who didn't already assure the user - $query = 'select min(`id`) as `assurer` from `users` ' . - 'where `email` like \'john.doe-___@example.com\' and ' . - '`id` not in (select `from` from `notary` where `to` = :user)'; - $query_params['user'] = $user['id']; - $row = $this->db->query($query, $query_params)->fetch(); - if ($row['assurer'] === NULL) { - throw new Exception(__METHOD__ . ': no more assurers that haven\'t '. - 'already assured this account'); - } - $assurer = $row['assurer']; + // Get the first assurer who didn't already assure the user + $assurer = $this->getNewAssurer($user['id']); // Get current points of the user @@ -87,15 +78,15 @@ class AddPointsController extends Zend_Controller_Action $assurance['when'] = new Zend_Db_Expr('now()'); $this->view->assurancesDone = array(); - $points = $values['quantity']; + $quantity = $values['quantity']; do { // split up into multiple assurances - if ($points > self::MAX_POINTS_PER_ASSURANCE) { + if ($quantity > self::MAX_POINTS_PER_ASSURANCE) { $assurance['awarded'] = self::MAX_POINTS_PER_ASSURANCE; - $points -= self::MAX_POINTS_PER_ASSURANCE; + $quantity -= self::MAX_POINTS_PER_ASSURANCE; } else { - $assurance['awarded'] = $points; - $points = 0; + $assurance['awarded'] = $quantity; + $quantity = 0; } // only assign points whithin the limit @@ -109,7 +100,7 @@ class AddPointsController extends Zend_Controller_Action $user['points'] += $assurance['points']; $this->view->assurancesDone[] = $assurance['points']; - } while ($points > 0); + } while ($quantity > 0); // Fix the assurer flag @@ -129,6 +120,28 @@ class AddPointsController extends Zend_Controller_Action return; } + /** + * Get the first assurer who didn't already assure the user + * + * @param int $user_id The ID of the user who should get assured + * @return int The ID of the selected assurer + */ + protected function getNewAssurer($user_id) + { + $query = 'select min(`id`) as `assurer` from `users` ' . + 'where `email` like \'john.doe-___@example.com\' and ' . + '`id` not in (select `from` from `notary` where `to` = :user)'; + $query_params['user'] = $user_id; + $row = $this->db->query($query, $query_params)->fetch(); + + if ($row['assurer'] === NULL) { + throw new Exception(__METHOD__ . ': no more assurers that haven\'t '. + 'already assured this account'); + } + + return $row['assurer']; + } + protected function getAssuranceForm() { $form = new Zend_Form(); From 66174d6fb339cee7014017f10df5d7ce06455382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 21:21:47 +0200 Subject: [PATCH 07/10] A new Assurer has to be selected for every single assurance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- manager/application/controllers/AddPointsController.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index 86557f3..891ee5d 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -57,10 +57,6 @@ class AddPointsController extends Zend_Controller_Action $user['id'] = $row['id']; - // Get the first assurer who didn't already assure the user - $assurer = $this->getNewAssurer($user['id']); - - // Get current points of the user $query = 'select sum(`points`) as `total` from `notary` where `to` = :user'; $query_params['user'] = $user['id']; @@ -71,7 +67,6 @@ class AddPointsController extends Zend_Controller_Action // Do the actual assurances $assurance = array(); // Make sure the array is empty - $assurance['from'] = $assurer; $assurance['to'] = $user['id']; $assurance['location'] = $values['location']; $assurance['date'] = $values['date']; @@ -89,6 +84,9 @@ class AddPointsController extends Zend_Controller_Action $quantity = 0; } + // Get the assurer for this assurance + $assurance['from'] = $this->getNewAssurer($user['id']); + // only assign points whithin the limit if ($user['points'] + $assurance['awarded'] > self::MAX_ASSURANCE_POINTS){ $assurance['points'] = self::MAX_ASSURANCE_POINTS - $user['points']; From e9d2e83670f66050455efda3e17c58c374adf894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 21:32:48 +0200 Subject: [PATCH 08/10] quoteInto() only accepts '?' as place holder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../application/controllers/AddPointsController.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index 891ee5d..b7f3541 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -103,16 +103,15 @@ class AddPointsController extends Zend_Controller_Action // Fix the assurer flag $where = array(); - $query = '`users`.`id` = :user'; - $query_params['user'] = $user['id']; - $where[] = $this->db->quoteInto($query, $query_params); + $query = '`users`.`id` = ?'; + $where[] = $this->db->quoteInto($query, $user['id']); $query = 'exists(select * from `cats_passed` as `cp`, ' . '`cats_variant` as `cv` where `cp`.`variant_id` = `cv`.`id` and ' . - '`cv`.`type_id` = 1 and `cp`.`user_id` = :user'; - $where[] = $this->db->quoteInto($query, $query_params); - $query = '(select sum(`points`) from `notary` where `to`= :user and ' . + '`cv`.`type_id` = 1 and `cp`.`user_id` = ?'; + $where[] = $this->db->quoteInto($query, $user['id']); + $query = '(select sum(`points`) from `notary` where `to`= ? and ' . '`expire` > now()) >= 100'; - $where[] = $this->db->quoteInto($query, $query_params); + $where[] = $this->db->quoteInto($query, $user['id']); $this->db->update('users', array('assurer' => 1), $where); return; From 727e4ff282623ce71df6c3700debf75029e5eb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Thu, 29 Apr 2010 21:55:57 +0200 Subject: [PATCH 09/10] db->update() sucks for complicated where clauses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- .../controllers/AddPointsController.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php index b7f3541..7003e41 100644 --- a/manager/application/controllers/AddPointsController.php +++ b/manager/application/controllers/AddPointsController.php @@ -102,17 +102,16 @@ class AddPointsController extends Zend_Controller_Action // Fix the assurer flag - $where = array(); - $query = '`users`.`id` = ?'; - $where[] = $this->db->quoteInto($query, $user['id']); - $query = 'exists(select * from `cats_passed` as `cp`, ' . - '`cats_variant` as `cv` where `cp`.`variant_id` = `cv`.`id` and ' . - '`cv`.`type_id` = 1 and `cp`.`user_id` = ?'; - $where[] = $this->db->quoteInto($query, $user['id']); - $query = '(select sum(`points`) from `notary` where `to`= ? and ' . - '`expire` > now()) >= 100'; - $where[] = $this->db->quoteInto($query, $user['id']); - $this->db->update('users', array('assurer' => 1), $where); + $query = 'UPDATE `users` SET `assurer` = 1 WHERE `users`.`id` = :user AND '. + + 'EXISTS(SELECT * FROM `cats_passed` AS `cp`, `cats_variant` AS `cv` '. + 'WHERE `cp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 AND '. + '`cp`.`user_id` = :user) AND '. + + '(SELECT SUM(`points`) FROM `notary` WHERE `to` = :user AND '. + '`expire` < now()) >= 100'; + $query_params['user'] = $user['id']; + $this->db->query($query, $query_params); return; } From 9b603df9b0f7caac80a19f4331f63773c0e3e0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Tue, 11 May 2010 19:28:36 +0200 Subject: [PATCH 10/10] Initial version of the create-assurers script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- dbadm/create-assurers.php | 182 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100755 dbadm/create-assurers.php diff --git a/dbadm/create-assurers.php b/dbadm/create-assurers.php new file mode 100755 index 0000000..194ea8b --- /dev/null +++ b/dbadm/create-assurers.php @@ -0,0 +1,182 @@ +#!/usr/bin/php +db = $db; + } + + + public static function echoUsage($script_name){ + print 'Usage: ' . $script_name; ?> + + +Script to create more dummy assurer accounts (for use on the test system) +which can be used by the test manager to create automated assurances + + specifies how many new dummy accounts should be created + +createAssurers($quantity); + + $db->close(); + exit($status); + } + + + public function createAssurers($quantity){ + // get last assurer + $result = $this->db->query('select `mname` from `users` where `id`= + (select max(`id`) from `users` where `email` like + \'john.doe-___@example.com\')'); + $row = $result->fetch_assoc(); + if ($row === NULL){ + $last_assurer = 0; + printf("1\n"); + } else { + $last_assurer = (int)($row['mname']); + printf("2: \$last_assurer: %d\n", $last_assurer); + } + + + // prepare the statements + $insert_user = $this->db->prepare('insert into `users` set + `email` = ? , + `password` = \'invalid\' , + `fname` = ? , + `mname` = ? , + `lname` = \'Doe\' , + `suffix` = \'\' , + `dob` = ? , + `Q1` = SHA1(rand()) , + `Q2` = SHA1(rand()) , + `Q3` = SHA1(rand()) , + `Q4` = SHA1(rand()) , + `Q5` = SHA1(rand()) , + `A1` = SHA1(rand()) , + `A2` = SHA1(rand()) , + `A3` = SHA1(rand()) , + `A4` = SHA1(rand()) , + `A5` = SHA1(rand()) , + `created` = now() , + `uniqueID` = SHA1(rand()) , + `verified` = 1 , + `assurer` = 1 '); + $insert_user->bind_param('ssss', $email, $fname, $mname, $dob); + + $insert_email = $this->db->prepare('insert into `email` set + `email` = ? , + `hash` = \'\' , + `created` = now() , + `modified` = now() , + `memid` = ? '); + $insert_email->bind_param('si', $email, $memid); + + $insert_alerts = $this->db->prepare('insert into `alerts` set + `memid` = ? , + `general` = 0 , + `country` = 0 , + `regional` = 0 , + `radius` = 0 '); + $insert_alerts->bind_param('i', $memid); + + $insert_points = $this->db->prepare('insert into `notary` set + `from` = ? , + `to` = ? , + `points` = 150 , + `awarded` = 150 , + `location` = \'Init Points\' , + `date` = curdate() , + `method` = \'Administrative Increase\' , + `when` = now() '); + $insert_points->bind_param('ii', $memid, $memid); + + $insert_cats = $this->db->prepare('insert into `cats_passed` set + `user_id` = ? , + `pass_date` = now() , + `variant_id` = + (select `id` from `cats_variant` where `type_id` = 1) '); + $insert_cats->bind_param('i', $memid); + + + // do the actual work + for ($i = $last_assurer + 1; $i <= $last_assurer + $quantity; $i++){ + $email = sprintf('john.doe-%03u@example.com', $i); + $fname = sprintf('John %u', $i); + $mname = sprintf('%u', $i); + $dob = sprintf('19%02u-01-%02u', $i % 90, (int)(($i/90) + 1) ); + + $insert_user->execute(); + $memid = $insert_user->insert_id; + if ($memid == 0){ + fwrite(STDERR, "Error: didn't get a valid ID for the user\n"); + return 10; + } + + $insert_email->execute(); + $insert_alerts->execute(); + $insert_points->execute(); + $insert_cats->execute(); + + printf('Assurer number %u %s Doe <%s>'."\n". + 'born on %s with the ID %d has been added'."\n", $i, + $fname, $email, $dob, $memid); + } + + return 0; + } +} + + +CreateAssurers::main(); \ No newline at end of file