aboutsummaryrefslogtreecommitdiff
path: root/mod/uservalidationbyemail
diff options
context:
space:
mode:
Diffstat (limited to 'mod/uservalidationbyemail')
-rw-r--r--mod/uservalidationbyemail/actions/resend_validation.php2
-rw-r--r--mod/uservalidationbyemail/languages/en.php5
-rw-r--r--mod/uservalidationbyemail/lib/functions.php40
-rw-r--r--mod/uservalidationbyemail/start.php2
-rw-r--r--mod/uservalidationbyemail/views/default/admin/users/unvalidated.php5
-rw-r--r--mod/uservalidationbyemail/views/default/forms/uservalidationbyemail/bulk_action.php92
-rw-r--r--mod/uservalidationbyemail/views/default/uservalidationbyemail/js.php27
-rw-r--r--mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php2
8 files changed, 139 insertions, 36 deletions
diff --git a/mod/uservalidationbyemail/actions/resend_validation.php b/mod/uservalidationbyemail/actions/resend_validation.php
index 59a69b0f6..586509b13 100644
--- a/mod/uservalidationbyemail/actions/resend_validation.php
+++ b/mod/uservalidationbyemail/actions/resend_validation.php
@@ -26,7 +26,7 @@ foreach ($user_guids as $guid) {
// don't resend emails to validated users
$is_validated = elgg_get_user_validation_status($guid);
- if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid)) {
+ if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid, true)) {
$error = TRUE;
continue;
}
diff --git a/mod/uservalidationbyemail/languages/en.php b/mod/uservalidationbyemail/languages/en.php
index 0c385cab5..df576a0e0 100644
--- a/mod/uservalidationbyemail/languages/en.php
+++ b/mod/uservalidationbyemail/languages/en.php
@@ -39,7 +39,10 @@ If you can't click on the link, copy and paste it to your browser manually.
'uservalidationbyemail:confirm_validate_user' => 'Validate %s?',
'uservalidationbyemail:confirm_resend_validation' => 'Resend validation email to %s?',
'uservalidationbyemail:confirm_delete' => 'Delete %s?',
- 'uservalidationbyemail:admin:with_checked' => 'With checked:',
+ 'uservalidationbyemail:confirm_validate_checked' => 'Validate checked users?',
+ 'uservalidationbyemail:confirm_resend_validation_checked' => 'Resend validation to checked users?',
+ 'uservalidationbyemail:confirm_delete_checked' => 'Delete checked users?',
+ 'uservalidationbyemail:check_all' => 'All',
'uservalidationbyemail:errors:unknown_users' => 'Unknown users',
'uservalidationbyemail:errors:could_not_validate_user' => 'Could not validate user.',
diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php
index b28e4a127..8a97c40b5 100644
--- a/mod/uservalidationbyemail/lib/functions.php
+++ b/mod/uservalidationbyemail/lib/functions.php
@@ -25,12 +25,13 @@ function uservalidationbyemail_generate_code($user_guid, $email_address) {
* Request user validation email.
* Send email out to the address and request a confirmation.
*
- * @param int $user_guid The user's GUID
+ * @param int $user_guid The user's GUID
+ * @param bool $admin_requested Was it requested by admin
* @return mixed
*/
-function uservalidationbyemail_request_validation($user_guid) {
+function uservalidationbyemail_request_validation($user_guid, $admin_requested = FALSE) {
- $site_url = elgg_get_site_url();
+ $site = elgg_get_site_entity();
$user_guid = (int)$user_guid;
$user = get_entity($user_guid);
@@ -38,15 +39,15 @@ function uservalidationbyemail_request_validation($user_guid) {
if (($user) && ($user instanceof ElggUser)) {
// Work out validate link
$code = uservalidationbyemail_generate_code($user_guid, $user->email);
- $link = "{$site_url}pg/uservalidationbyemail/confirm?u=$user_guid&c=$code";
- $site = elgg_get_site_entity();
+ $link = "{$site->url}pg/uservalidationbyemail/confirm?u=$user_guid&c=$code";
+
// Send validation email
$subject = elgg_echo('email:validate:subject', array($user->name, $site->name));
$body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url));
$result = notify_user($user->guid, $site->guid, $subject, $body, NULL, 'email');
- if ($result) {
+ if ($result && !$admin_requested) {
system_message(elgg_echo('uservalidationbyemail:registerok'));
}
@@ -72,3 +73,30 @@ function uservalidationbyemail_validate_email($user_guid, $code) {
return false;
}
+
+/**
+ * Return a where clause to get entities
+ *
+ * "Unvalidated" means metadata of validated is not set or not truthy.
+ * We can't use elgg_get_entities_from_metadata() because you can't say
+ * "where the entity has metadata set OR it's not equal to 1".
+ *
+ * @return array
+ */
+function uservalidationbyemail_get_unvalidated_users_sql_where() {
+ global $CONFIG;
+
+ $validated_id = get_metastring_id('validated');
+ $one_id = get_metastring_id(1);
+
+ // thanks to daveb@freenode for the SQL tips!
+ $wheres = array();
+ $wheres[] = "e.enabled='no'";
+ $wheres[] = "NOT EXISTS (
+ SELECT 1 FROM {$CONFIG->dbprefix}metadata md
+ WHERE md.entity_guid = e.guid
+ AND md.name_id = $validated_id
+ AND md.value_id = $one_id)";
+
+ return $wheres;
+} \ No newline at end of file
diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php
index 7cd97c1e5..03f204511 100644
--- a/mod/uservalidationbyemail/start.php
+++ b/mod/uservalidationbyemail/start.php
@@ -41,6 +41,8 @@ function uservalidationbyemail_init() {
// admin interface to manually validate users
elgg_add_admin_menu_item('unvalidated', elgg_echo('uservalidationbyemail:admin:unvalidated'), 'users');
+ elgg_extend_view('js/elgg', 'uservalidationbyemail/js');
+
$action_path = dirname(__FILE__) . '/actions';
elgg_register_action('uservalidationbyemail/validate', "$action_path/validate.php", 'admin');
diff --git a/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php b/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php
index 0b94ab039..f34447b65 100644
--- a/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php
+++ b/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php
@@ -1,3 +1,6 @@
<?php
-echo elgg_view_form('uservalidationbyemail/bulk_action');
+echo elgg_view_form('uservalidationbyemail/bulk_action', array(
+ 'name' => 'unvalidated-users',
+ 'action' => 'action/uservalidationbyemail/bulk_action'
+));
diff --git a/mod/uservalidationbyemail/views/default/forms/uservalidationbyemail/bulk_action.php b/mod/uservalidationbyemail/views/default/forms/uservalidationbyemail/bulk_action.php
index d5060d7e5..fb0d9e5b1 100644
--- a/mod/uservalidationbyemail/views/default/forms/uservalidationbyemail/bulk_action.php
+++ b/mod/uservalidationbyemail/views/default/forms/uservalidationbyemail/bulk_action.php
@@ -16,22 +16,33 @@ access_show_hidden_entities(TRUE);
$options = array(
'type' => 'user',
- 'metadata_name' => 'validated',
- 'metadata_value' => 0,
+ 'wheres' => uservalidationbyemail_get_unvalidated_users_sql_where(),
'limit' => $limit,
- 'offset' => $offset
+ 'offset' => $offset,
+ 'count' => TRUE,
);
-$users = elgg_get_entities_from_metadata($options);
+$count = elgg_get_entities($options);
+
+if (!$count) {
+ access_show_hidden_entities($hidden_entities);
+ elgg_set_ignore_access($ia);
+
+ echo elgg_view('page_elements/contentwrapper', array(
+ 'body' => elgg_echo('uservalidationbyemail:admin:no_unvalidated_users')
+ ));
+ return;
+}
-$options['count'] = TRUE;
-$count = elgg_get_entities_from_metadata($options);
+$options['count'] = FALSE;
+
+$users = elgg_get_entities($options);
access_show_hidden_entities($hidden_entities);
elgg_set_ignore_access($ia);
// setup pagination
-$pagination = elgg_view('navigation/pagination', array(
- 'baseurl' => elgg_get_site_url() . 'pg/admin/users/unvalidated',
+$pagination = elgg_view('navigation/pagination',array(
+ 'baseurl' => $vars['url'] . '/pg/uservalidationbyemail/admin/',
'offset' => $offset,
'count' => $count,
'limit' => $limit,
@@ -39,25 +50,54 @@ $pagination = elgg_view('navigation/pagination', array(
echo $pagination;
-if ($users) {
- foreach ($users as $user) {
- $form_body .= elgg_view('uservalidationbyemail/unvalidated_user', array('theuser' => $user));
- }
-} else {
- echo elgg_echo('uservalidationbyemail:admin:no_unvalidated_users');
- return;
-}
+$bulk_actions_checkbox = '<label><input type="checkbox" class="unvalidated-users-checkall" />'
+ . elgg_echo('uservalidationbyemail:check_all') . '</label>';
+
+$validate = elgg_view('output/url', array(
+ 'is_action' => TRUE,
+ 'js' => 'title="' . elgg_echo('uservalidationbyemail:confirm_validate_checked') . '"',
+ 'href' => $vars['url'] . "action/uservalidationbyemail/validate/",
+ 'text' => elgg_echo('uservalidationbyemail:admin:validate'),
+ 'class' => 'unvalidated-users-bulk-post',
+));
-$form_body .= elgg_echo('uservalidationbyemail:admin:with_checked') . elgg_view('input/dropdown', array(
- 'name' => 'action_type',
- 'options_values' => array(
- 'validate' => elgg_echo('uservalidationbyemail:admin:validate'),
- 'resend_validation' => elgg_echo('uservalidationbyemail:admin:resend_validation'),
- 'delete' => elgg_echo('uservalidationbyemail:admin:delete'),
- ),
- 'value' => 'resend_validation',
+$resend_email = elgg_view('output/url', array(
+ 'is_action' => TRUE,
+ 'js' => 'title="' . elgg_echo('uservalidationbyemail:confirm_resend_validation_checked') . '"',
+ 'href' => $vars['url'] . "action/uservalidationbyemail/resend_validation/",
+ 'text' => elgg_echo('uservalidationbyemail:admin:resend_validation'),
+ 'class' => 'unvalidated-users-bulk-post',
));
-$form_body .= '<br />' . elgg_view('input/submit', array('value' => elgg_echo('submit')));
+$delete = elgg_view('output/url', array(
+ 'is_action' => TRUE,
+ 'js' => 'title="' . elgg_echo('uservalidationbyemail:confirm_delete_checked') . '"',
+ 'href' => $vars['url'] . "action/uservalidationbyemail/delete/",
+ 'text' => elgg_echo('uservalidationbyemail:admin:delete'),
+ 'class' => 'unvalidated-users-bulk-post',
+));
+
+$bulk_actions = <<<___END
+<div class="uvbe_bulk_actions">
+ <div class="uvbe_admin_controls">
+ $resend_email | $validate | $delete
+ </div>
+
+ $bulk_actions_checkbox
+</div>
+___END;
+
+//$bulk_actions = elgg_view('page_elements/contentwrapper', array('body' => $bulk_actions));
+
+echo $bulk_actions;
+
+
+foreach ($users as $user) {
+ echo elgg_view('uservalidationbyemail/unvalidated_user', array('user' => $user));
+}
+
+if ($count > 5) {
+ echo $bulk_actions;
+}
-echo $form_body; \ No newline at end of file
+echo $pagination; \ No newline at end of file
diff --git a/mod/uservalidationbyemail/views/default/uservalidationbyemail/js.php b/mod/uservalidationbyemail/views/default/uservalidationbyemail/js.php
new file mode 100644
index 000000000..c1ca58559
--- /dev/null
+++ b/mod/uservalidationbyemail/views/default/uservalidationbyemail/js.php
@@ -0,0 +1,27 @@
+elgg.provide('elgg.uservalidationbyemail');
+
+elgg.uservalidationbyemail.init = function() {
+ $('.unvalidated-users-checkall').click(function() {
+ checked = $(this).attr('checked');
+ $('form[name=unvalidated-users]').find('input[type=checkbox]').attr('checked', checked);
+ });
+
+ $('.unvalidated-users-bulk-post').click(function(event) {
+ $form = $('form[name=unvalidated-users]');
+ event.preventDefault();
+
+ // check there are selected users
+ if ($form.find('input[type=checkbox]:checked').length < 1) {
+ return false;
+ }
+
+ // confirmation
+ if (!confirm($(this).attr('title'))) {
+ return false;
+ }
+
+ $form.attr('action', $(this).attr('href')).submit();
+ });
+};
+
+elgg.register_event_handler('init', 'system', elgg.uservalidationbyemail.init); \ No newline at end of file
diff --git a/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php b/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php
index 295f4170e..209dbe02b 100644
--- a/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php
+++ b/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php
@@ -6,7 +6,7 @@
* @subpackage UserValidationByEmail.Administration
*/
-$user = elgg_extract('theuser', $vars);
+$user = elgg_extract('user', $vars);
// doesn't work.
//$checkbox = elgg_view('input/checkboxes', array(