Просмотр поста

.
jimy
# citybooks (09.06.2017 / 18:24)
How about users sharing there point, cod with admin function to share point for all users too, and admin ability to close and open the sharing page.
maybe like this,
.''")->fetchColumn();

/* executor */
if (isset($_POST['submit'])) {
	$error = [];
	$point = isset($_POST['point']) ? trim($_POST['point']) : false;
	if (empty($_POST['text'])) {
		$error['point'][] = _t('You cant send empty point!','system');
	}
	if ($point >= $pointgiver) {
		$error['point'][] = _t('You cant send more than your point!','system');
	}
	if ($user['id'] == $systemUser->id) {
		$error['point'][] = _t('You cant send to your self!','system');
	}
	$flood = $tools->antiflood();
	if ($flood) {
		$error['flood'][] = sprintf(_t('You cannot add point so often. Please, wait %d seconds.','system'), $flood);
	}
	/* update data for receiver */
	if (!$error) {
		$receive = $pointreceive + $point;
		$db->prepare('
		UPDATE `point` SET
			`total` = ?
			WHERE `user` = ?
		')->execute([
			$receive,
			$user['id'],
		]);
	}
	
	/* update data for giver */
	if (!$error) {
		$given = $pointgiver - $point;
		$db->prepare('
		UPDATE `point` SET
			`total` = ?
			WHERE `user` = ?
		')->execute([
			$given,
			$user['id'],
		]);
	}
	$db->query("OPTIMIZE TABLE `point`");
}

/* form (edit form action) */
echo '<form action="?" method="post" name="form">'.
	(isset($error['flood']) ? '<p class="red">'.implode($error['flood']).'</p>' : '').
	(isset($error['point']) ? '<p class="red">'.implode($error['point']).'</p>' : '');
echo '<p>Point giver</p>';
echo '<p><input type="number" name="point" value="'.$point.'"/></p>';
echo '<input type="submit" name="submit" value="'._t('Send','system').'"/></form>';