summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2010-06-29 20:00:03 +0200
committerMichael Tänzer <neo@nhng.de>2010-06-29 20:00:03 +0200
commit93f7bf20f649382446784ad2b000394fe63f5010 (patch)
tree757be1ad95a297eb2c1cb5f6d7d0f3cc5b900f1e
parent1169be1f5812fd0dec4f13d89aff4fff83e8251c (diff)
downloadcacert-mgr-93f7bf20f649382446784ad2b000394fe63f5010.tar.gz
cacert-mgr-93f7bf20f649382446784ad2b000394fe63f5010.tar.xz
cacert-mgr-93f7bf20f649382446784ad2b000394fe63f5010.zip
New admin increase feature
TODO: Add to the menu somewhere TODO: Test ;-) Signed-off-by: Michael Tänzer <neo@nhng.de>
-rw-r--r--manager/application/controllers/ManageAccountController.php69
-rw-r--r--manager/application/views/scripts/manage-account/admin-increase-form.phtml8
-rw-r--r--manager/application/views/scripts/manage-account/admin-increase.phtml19
3 files changed, 96 insertions, 0 deletions
diff --git a/manager/application/controllers/ManageAccountController.php b/manager/application/controllers/ManageAccountController.php
index 98147ba..6cb238a 100644
--- a/manager/application/controllers/ManageAccountController.php
+++ b/manager/application/controllers/ManageAccountController.php
@@ -7,6 +7,11 @@ class ManageAccountController extends Zend_Controller_Action
{
const MAX_POINTS_PER_ASSURANCE = 35;
const MAX_ASSURANCE_POINTS = 100;
+ const MAX_POINTS_TOTAL = 150;
+ const ADMIN_INCREASE_FRAGMENT_SIZE = 2;
+
+ // Value used in the database to identify a admin increase
+ const ADMIN_INCREASE_METHOD = 'Administrative Increase';
protected $db;
@@ -84,6 +89,70 @@ class ManageAccountController extends Zend_Controller_Action
return;
}
+ public function adminIncreaseAction()
+ {
+ // Validate form
+ $form = $this->getAdminIncreaseForm();
+ if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
+ $this->view->admin_increase_form = $form;
+ return $this->render('admin-increase-form');
+ }
+
+ // Form is valid -> get values for processing
+ $values = $form->getValues();
+
+ // Get user data
+ $user['id'] = $this->getUserId();
+ $user['points'] = $this->getPoints($user['id']);
+
+
+ // Do the actual increase
+ $increase = array(); // Make sure the array is empty
+ $increase['from'] = $user['id'];
+ $increase['to'] = $user['id'];
+ $increase['location'] = $values['location'];
+ $increase['date'] = $values['date'];
+ $increase['method'] = self::ADMIN_INCREASE_METHOD;
+ $increase['when'] = new Zend_Db_Expr('now()');
+ $this->view->adminIncreasesDone = array();
+
+ $quantity = $values['quantity'];
+ do {
+ // Split up into multiple increases if fragment flag is set
+ if ($values['fragment'] == '1' &&
+ $quantity > self::ADMIN_INCREASE_FRAGMENT_SIZE) {
+ $increase['awarded'] = self::ADMIN_INCREASE_FRAGMENT_SIZE;
+ $quantity -= self::ADMIN_INCREASE_FRAGMENT_SIZE;
+ } else {
+ $increase['awarded'] = $quantity;
+ $quantity = 0;
+ }
+
+ // Only assign points within the limit if unlimited flag is not set
+ if ($values['unlimited'] != '1') {
+ if ($user['points'] >= self::MAX_POINTS_TOTAL) {
+ // No more administrative increases should be done
+ break;
+ } elseif ($user['points'] + $increase['awarded'] > self::MAX_POINTS_TOTAL) {
+ $increase['awarded'] = self::MAX_POINTS_TOTAL - $user['points'];
+ }
+ }
+
+ // Admin increases always have `points` == `awarded`
+ $increase['points'] = $increase['awarded'];
+
+ $this->db->insert('notary', $increase);
+
+ $user['points'] += $increase['points'];
+ $this->view->adminIncreasesDone[] = $increase['points'];
+ } while ($quantity > 0);
+
+ // Maybe user is now assurer
+ $this->fixAssurerFlag($user['id']);
+
+ return;
+ }
+
/**
* Get and check the user ID of the current user
*
diff --git a/manager/application/views/scripts/manage-account/admin-increase-form.phtml b/manager/application/views/scripts/manage-account/admin-increase-form.phtml
new file mode 100644
index 0000000..16d6f31
--- /dev/null
+++ b/manager/application/views/scripts/manage-account/admin-increase-form.phtml
@@ -0,0 +1,8 @@
+<?php
+/**
+ * @author Michael Tänzer
+ * @todo Text
+ */
+?>
+
+<?php print $this->admin_increase_form ?>
diff --git a/manager/application/views/scripts/manage-account/admin-increase.phtml b/manager/application/views/scripts/manage-account/admin-increase.phtml
new file mode 100644
index 0000000..bf984d3
--- /dev/null
+++ b/manager/application/views/scripts/manage-account/admin-increase.phtml
@@ -0,0 +1,19 @@
+<?php
+/**
+ * @author Michael Tänzer
+ * @todo Text
+ */
+?>
+
+<h1><?php print I18n::_('Points added successfully')?></h1>
+
+<table>
+ <thead>
+ <tr><th>#</th><th><?php print I18n::_('Number of points')?></th></tr>
+ </thead>
+ <tbody>
+ <?php foreach ($this->adminIncreasesDone as $i => $points) {
+ printf('<tr><td> %1$d </td><td> %2$d </td></tr>', $i, $points);
+ }?>
+ </tbody>
+</table>