mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 17:59:22 +02:00
Suggest account number option
This commit is contained in:
parent
6f3ba9c34b
commit
e47bb11883
@ -34,6 +34,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="LabelV" style="width: 150px">
|
<td class="LabelV" style="width: 150px">
|
||||||
<span{% if errors.account is defined %} class="red"{% endif %}>Account {% if constant('USE_ACCOUNT_NAME') %}Name{% else %}Number{% endif %}:</span>
|
<span{% if errors.account is defined %} class="red"{% endif %}>Account {% if constant('USE_ACCOUNT_NAME') %}Name{% else %}Number{% endif %}:</span>
|
||||||
|
{% if not constant('USE_ACCOUNT_NAME') %}
|
||||||
|
<div id="SuggestAccountNumber">[<a href="#">suggest number</a>]</div>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="account" id="account_input" size="30" maxlength="{% if constant('USE_ACCOUNT_NAME') %}30{% else %}10{% endif %}" value="{{ account }}" autofocus/>
|
<input type="text" name="account" id="account_input" size="30" maxlength="{% if constant('USE_ACCOUNT_NAME') %}30{% else %}10{% endif %}" value="{{ account }}" autofocus/>
|
||||||
@ -336,3 +339,8 @@
|
|||||||
</form>
|
</form>
|
||||||
{{ hook('HOOK_ACCOUNT_CREATE_AFTER_FORM') }}
|
{{ hook('HOOK_ACCOUNT_CREATE_AFTER_FORM') }}
|
||||||
<script type="text/javascript" src="tools/check_name.js"></script>
|
<script type="text/javascript" src="tools/check_name.js"></script>
|
||||||
|
<style>
|
||||||
|
#SuggestAccountNumber {
|
||||||
|
font-size: 7pt;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
$('#password2').blur(function() {
|
$('#password2').blur(function() {
|
||||||
checkPassword();
|
checkPassword();
|
||||||
});
|
});
|
||||||
|
$('#SuggestAccountNumber a').click(function (event) {
|
||||||
|
generateAccountNumber(event);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateFlag()
|
function updateFlag()
|
||||||
@ -192,4 +195,18 @@
|
|||||||
|
|
||||||
lastSend = timeNow;
|
lastSend = timeNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateAccountNumber(event)
|
||||||
|
{
|
||||||
|
event.preventDefault();
|
||||||
|
$.getJSON("tools/generate_account_number.php", { uid: Math.random() },
|
||||||
|
function(data){
|
||||||
|
if(data.hasOwnProperty('success')) {
|
||||||
|
$('#account_input').val(data.success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
setTimeout(checkAccount, 1000);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
54
tools/generate_account_number.php
Normal file
54
tools/generate_account_number.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Account Number Generator
|
||||||
|
* Returns json with result
|
||||||
|
*
|
||||||
|
* @package MyAAC
|
||||||
|
* @author Slawkens <slawkens@gmail.com>
|
||||||
|
* @copyright 2021 MyAAC
|
||||||
|
* @link https://my-aac.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
// we need some functions
|
||||||
|
require '../common.php';
|
||||||
|
require SYSTEM . 'functions.php';
|
||||||
|
require SYSTEM . 'init.php';
|
||||||
|
|
||||||
|
if(USE_ACCOUNT_NAME) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasNumberColumn = $db->hasColumn('accounts', 'number');
|
||||||
|
do {
|
||||||
|
$length = 10;
|
||||||
|
$min = (int)(1 . str_repeat(0, $length - 1));
|
||||||
|
$max = (int)str_repeat(9, $length);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$number = random_int($min, $max);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_('');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $db->query('SELECT `id` FROM `accounts` WHERE `' . ($hasNumberColumn ? 'number' : 'id') . '` = ' . $db->quote($number));
|
||||||
|
} while($query->rowCount() >= 1);
|
||||||
|
|
||||||
|
success_($number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output message & exit.
|
||||||
|
*
|
||||||
|
* @param string $desc Description
|
||||||
|
*/
|
||||||
|
function success_($desc) {
|
||||||
|
echo json_encode([
|
||||||
|
'success' => $desc
|
||||||
|
]);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
function error_($desc) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => $desc
|
||||||
|
]);
|
||||||
|
exit();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user