mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 04:27:22 +08:00
temporary invite
This commit is contained in:
@@ -10,6 +10,7 @@ $validTypeMap = [
|
||||
'attendance_card' => 'Attend card',
|
||||
'invites' => 'Invite',
|
||||
'uploaded' => 'Upload',
|
||||
'tmp_invites' => 'Temporary invite',
|
||||
];
|
||||
$type = $_REQUEST['type'] ?? '';
|
||||
stdhead("Add Bonus/Attend card/Invite/upload", false);
|
||||
@@ -49,6 +50,7 @@ $classes = array_chunk(\App\Models\User::$classes, 4, true);
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td class="rowhead" valign="top">Amount </td><td class="rowfollow"><input type=text name=amount size=10></td></tr>
|
||||
<tr><td class="rowhead" valign="top">Duration </td><td class="rowfollow"><input type=number min="1" name=duration size=10> Only required when Type = 'Temporary invite', Unit: Day</td></tr>
|
||||
<tr>
|
||||
<td class="rowhead" valign="top">Add to Class</td><td class="rowfollow">
|
||||
<table style="border: 0" width="100%" cellpadding="0" cellspacing="0">
|
||||
|
||||
+58
-24
@@ -8,23 +8,31 @@ $id = intval($_GET["id"] ?? 0);
|
||||
$type = unesc($_GET["type"] ?? '');
|
||||
$menuSelected = $_REQUEST['menu'] ?? 'invitee';
|
||||
$pageSize = 50;
|
||||
$userRep = new \App\Repositories\UserRepository();
|
||||
|
||||
function inviteMenu ($selected = "invitee") {
|
||||
global $lang_invite, $id, $CURUSER, $invitesystem;
|
||||
global $lang_invite, $id, $CURUSER, $invitesystem, $userRep;
|
||||
begin_main_frame("", false, "100%");
|
||||
print ("<div id=\"invitenav\" style='position: relative'><ul id=\"invitemenu\" class=\"menu\">");
|
||||
print ("<li" . ($selected == "invitee" ? " class=selected" : "") . "><a href=\"?id=".$id."&menu=invitee\">".$lang_invite['text_invite_status']."</a></li>");
|
||||
print ("<li" . ($selected == "sent" ? " class=selected" : "") . "><a href=\"?id=".$id."&menu=sent\">".$lang_invite['text_sent_invites_status']."</a></li>");
|
||||
if (user_can('sendinvite') && $invitesystem == 'yes') {
|
||||
print ("</ul><form style='position: absolute;top:0;right:0' method=post action=invite.php?id=".htmlspecialchars($id)."&type=new><input type=submit ".($CURUSER['invites'] <= 0 ? "disabled " : "")." value='".$lang_invite['sumbit_invite_someone']."'></form></div>");
|
||||
print ("<li" . ($selected == "tmp" ? " class=selected" : "") . "><a href=\"?id=".$id."&menu=tmp\">".$lang_invite['text_tmp_status']."</a></li>");
|
||||
try {
|
||||
$sendBtnText = $userRep->getInviteBtnText($CURUSER['id']);
|
||||
$disabled = '';
|
||||
} catch (\Exception $exception) {
|
||||
$sendBtnText = $exception->getMessage();
|
||||
$disabled = ' disabled';
|
||||
}
|
||||
print ("</ul><form style='position: absolute;top:0;right:0' method=post action=invite.php?id=".htmlspecialchars($id)."&type=new><input type=submit ".$disabled." value='".$sendBtnText."'></form></div>");
|
||||
end_main_frame();
|
||||
}
|
||||
|
||||
if (($CURUSER['id'] != $id && !user_can('viewinvite')) || !is_valid_id($id))
|
||||
stderr($lang_invite['std_sorry'],$lang_invite['std_permission_denied']);
|
||||
$res = sql_query("SELECT username FROM users WHERE id = ".mysql_real_escape_string($id)) or sqlerr();
|
||||
$user = mysql_fetch_assoc($res);
|
||||
if (!$user) {
|
||||
stderr($lang_invite['std_sorry'], 'Invalid id');
|
||||
}
|
||||
stdhead($lang_invite['head_invites']);
|
||||
print("<table width=100% class=main border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>");
|
||||
|
||||
@@ -46,24 +54,34 @@ if ($inv["invites"] != 1){
|
||||
}
|
||||
|
||||
if ($type == 'new'){
|
||||
if (!user_can('sendinvite'))
|
||||
stderr($lang_invite['std_sorry'],$lang_invite['std_only'].get_user_class_name($sendinvite_class,false,true,true).$lang_invite['std_or_above_can_invite'],false, false);
|
||||
try {
|
||||
$sendBtnText = $userRep->getInviteBtnText($CURUSER['id']);
|
||||
} catch (\Exception $exception) {
|
||||
stdmsg($lang_invite['std_sorry'],$exception->getMessage().
|
||||
" <a class=altlink href=invite.php?id={$CURUSER['id']}>".$lang_invite['here_to_go_back'],false);
|
||||
print("</td></tr></table>");
|
||||
stdfoot();
|
||||
die;
|
||||
}
|
||||
registration_check('invitesystem',true,false);
|
||||
if ($CURUSER['invites'] <= 0) {
|
||||
stdmsg($lang_invite['std_sorry'],$lang_invite['std_no_invites_left'].
|
||||
"<a class=altlink href=invite.php?id={$CURUSER['id']}>".$lang_invite['here_to_go_back'],false);
|
||||
print("</td></tr></table>");
|
||||
stdfoot();
|
||||
die;
|
||||
}
|
||||
$temporaryInvites = \App\Models\Invite::query()->where('inviter', $CURUSER['id'])
|
||||
->where('invitee', '')
|
||||
->where('expired_at', '>', now())
|
||||
->orderBy('expired_at', 'asc')
|
||||
->get()
|
||||
;
|
||||
$invitation_body = $lang_invite['text_invitation_body'].$CURUSER['username'];
|
||||
//$invitation_body_insite = str_replace("<br />","\n",$invitation_body);
|
||||
$inviteSelectOptions = '<option value="permanent">'.$lang_invite['text_permanent'].'</option>';
|
||||
foreach ($temporaryInvites as $tmp) {
|
||||
$inviteSelectOptions .= sprintf('<option value="%s">%s(%s: %s)</option>', $tmp->hash, $tmp->hash, $lang_invite['text_expired_at'], $tmp->expired_at);
|
||||
}
|
||||
print("<form method=post action=takeinvite.php?id=".htmlspecialchars($id).">".
|
||||
"<table border=1 width=100% cellspacing=0 cellpadding=5>".
|
||||
"<tr align=center><td colspan=2><b>".$lang_invite['text_invite_someone']."$SITENAME ({$inv['invites']}".$lang_invite['text_invitation'].$_s.$lang_invite['text_left'] .")</b></td></tr>".
|
||||
"<tr align=center><td colspan=2><b>".$lang_invite['text_invite_someone']."$SITENAME ({$inv['invites']}".$lang_invite['text_invitation'].$_s.$lang_invite['text_left'] .' + '.sprintf($lang_invite['text_temporary_left'], $temporaryInvites->count()).")</b></td></tr>".
|
||||
"<tr><td class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$lang_invite['text_email_address']."</td><td align=left><input type=text size=40 name=email><br /><font align=left class=small>".$lang_invite['text_email_address_note']."</font>".($restrictemaildomain == 'yes' ? "<br />".$lang_invite['text_email_restriction_note'].allowedemails() : "")."</td></tr>".
|
||||
"<tr><td class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$lang_invite['text_message']."</td><td align=left><textarea name=body rows=10 style='width: 100%'>" .$invitation_body.
|
||||
"</textarea></td></tr>".
|
||||
"<tr><td class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$lang_invite['text_consume_invite']."</td><td align=left><select name='hash'>".$inviteSelectOptions."</select></td></tr>".
|
||||
"<tr><td class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$lang_invite['text_message']."</td><td align=left><textarea name=body rows=10 style='width: 100%'>" .$invitation_body. "</textarea></td></tr>".
|
||||
"<tr><td align=center colspan=2><input type=submit value='".$lang_invite['submit_invite']."'></td></tr>".
|
||||
"</form></table></td></tr></table>");
|
||||
|
||||
@@ -94,7 +112,9 @@ if ($type == 'new'){
|
||||
$name, $_GET['status'] == $name ? ' selected' : '', $text
|
||||
);
|
||||
}
|
||||
|
||||
$resetText = nexus_trans('label.reset');
|
||||
$submitText = nexus_trans('label.submit');
|
||||
$filterForm = <<<FORM
|
||||
<div>
|
||||
<form id="filterForm" action="{$_SERVER['REQUEST_URI']}" method="get">
|
||||
@@ -112,7 +132,7 @@ if ($type == 'new'){
|
||||
{$statusOptions}
|
||||
</select>
|
||||
|
||||
<input type="submit">
|
||||
<input type="submit" value="{$submitText}">
|
||||
<input type="button" id="reset" value="{$resetText}">
|
||||
</form>
|
||||
</div>
|
||||
@@ -220,22 +240,32 @@ JS;
|
||||
}
|
||||
print("</table>");
|
||||
print("</td></tr></table>$pagertop");
|
||||
} elseif ($menuSelected == 'sent') {
|
||||
$rul = sql_query("SELECT COUNT(*) FROM invites WHERE inviter =".mysql_real_escape_string($id)) or sqlerr();
|
||||
} elseif (in_array($menuSelected, ['sent', 'tmp'])) {
|
||||
$whereStr = "inviter = " . sqlesc($id);
|
||||
if ($menuSelected == 'sent') {
|
||||
$whereStr .= " and invitee != ''";
|
||||
} elseif ($menuSelected == 'tmp') {
|
||||
$whereStr .= " and invitee = '' and expired_at is not null";
|
||||
}
|
||||
$rul = sql_query("SELECT COUNT(*) FROM invites WHERE $whereStr");
|
||||
$arre = mysql_fetch_row($rul);
|
||||
$number1 = $arre[0];
|
||||
|
||||
print("<table border=1 width=100% cellspacing=0 cellpadding=5>");
|
||||
|
||||
if(!$number1){
|
||||
print("<tr align=center><td colspan=6>".$lang_invite['text_no_invitation_sent']."</tr>");
|
||||
print("<tr align=center><td colspan=6>".$lang_functions['text_none']."</tr>");
|
||||
} else {
|
||||
list($pagertop, $pagerbottom, $limit) = pager($pageSize, $number1, "?id=$id&menu=$menuSelected&");
|
||||
|
||||
$rer = sql_query("SELECT * FROM invites WHERE inviter = ".mysql_real_escape_string($id) . " $limit") or sqlerr();
|
||||
$rer = sql_query("SELECT * FROM invites WHERE $whereStr $limit") or sqlerr();
|
||||
$num1 = mysql_num_rows($rer);
|
||||
|
||||
print("<tr><td class=colhead>".$lang_invite['text_email']."</td><td class=colhead>".$lang_invite['text_hash']."</td><td class=colhead>".$lang_invite['text_send_date']."</td><td class='colhead'>".$lang_invite['text_hash_status']."</td><td class='colhead'>".$lang_invite['text_invitee_user']."</td></tr>");
|
||||
print("<tr><td class=colhead>".$lang_invite['text_email']."</td><td class=colhead>".$lang_invite['text_hash']."</td><td class=colhead>".$lang_invite['text_send_date']."</td><td class='colhead'>".$lang_invite['text_hash_status']."</td><td class='colhead'>".$lang_invite['text_invitee_user']."</td>");
|
||||
if ($menuSelected == 'tmp') {
|
||||
print("<td class='colhead'>".$lang_invite['text_expired_at']."</td>");
|
||||
print("<td class='colhead'>".nexus_trans('label.created_at')."</td>");
|
||||
}
|
||||
print("</tr>");
|
||||
for ($i = 0; $i < $num1; ++$i)
|
||||
{
|
||||
$arr1 = mysql_fetch_assoc($rer);
|
||||
@@ -254,6 +284,10 @@ JS;
|
||||
} else {
|
||||
$tr .= "<td class='rowfollow'></td>";
|
||||
}
|
||||
if ($menuSelected == 'tmp') {
|
||||
$tr .= "<td class=rowfollow>{$arr1['expired_at']}</td>";
|
||||
$tr .= "<td class=rowfollow>{$arr1['created_at']}</td>";
|
||||
}
|
||||
$tr .= "</tr>";
|
||||
print($tr);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ $validTypeMap = [
|
||||
'attendance_card' => 'Attend card',
|
||||
'invites' => 'Invite',
|
||||
'uploaded' => 'Upload',
|
||||
'tmp_invites' => 'Temporary invite',
|
||||
];
|
||||
$sender_id = ($_POST['sender'] == 'system' ? 0 : (int)$CURUSER['id']);
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
@@ -29,8 +30,9 @@ if (!isset($validTypeMap[$type])) {
|
||||
if ($type == 'uploaded') {
|
||||
$amount = sqlesc(getsize_int($amount,"G"));
|
||||
}
|
||||
$isTypeTmpInvite = $type == 'tmp_invites';
|
||||
$subject = trim($_POST['subject']);
|
||||
$size = 10000;
|
||||
$size = 2000;
|
||||
$page = 1;
|
||||
set_time_limit(300);
|
||||
$conditions = [];
|
||||
@@ -41,7 +43,12 @@ $conditions = apply_filter("role_query_conditions", $conditions, $_POST);
|
||||
if (empty($conditions)) {
|
||||
stderr("Error","No valid filter");
|
||||
}
|
||||
if ($isTypeTmpInvite && (empty($_POST['duration']) || $_POST['duration'] < 1)) {
|
||||
stderr("Error","Invalid duration");
|
||||
}
|
||||
$whereStr = implode(' OR ', $conditions);
|
||||
$phpPath = nexus_env('PHP_PATH', 'php');
|
||||
$webRoot = rtrim(ROOT_PATH, '/');
|
||||
while (true) {
|
||||
$msgValues = $idArr = [];
|
||||
$offset = ($page - 1) * $size;
|
||||
@@ -54,10 +61,19 @@ while (true) {
|
||||
if (empty($idArr)) {
|
||||
break;
|
||||
}
|
||||
$idStr = implode(', ', $idArr);
|
||||
$idStr = implode(',', $idArr);
|
||||
if ($isTypeTmpInvite) {
|
||||
$command = sprintf(
|
||||
'%s %s/artisan invite:tmp %s %s %s',
|
||||
$phpPath, $webRoot, $idStr, $_POST['duration'], $amount
|
||||
);
|
||||
$result = exec("$command 2>&1", $output, $result_code);
|
||||
do_log(sprintf('command: %s, result_code: %s, result: %s, output: %s', $command, $result_code, $result, json_encode($output)));
|
||||
} else {
|
||||
sql_query("UPDATE users SET $type = $type + $amount WHERE id in ($idStr)");
|
||||
}
|
||||
$sql = "INSERT INTO messages (sender, receiver, added, subject, msg) VALUES " . implode(', ', $msgValues);
|
||||
sql_query($sql);
|
||||
sql_query("UPDATE users SET $type = $type + $amount WHERE id in ($idStr)");
|
||||
$page++;
|
||||
}
|
||||
|
||||
|
||||
+34
-7
@@ -3,10 +3,12 @@ require_once("../include/bittorrent.php");
|
||||
dbconn();
|
||||
require_once(get_langfile_path());
|
||||
registration_check('invitesystem', true, false);
|
||||
if (!user_can('sendinvite'))
|
||||
stderr($lang_takeinvite['std_error'],$lang_takeinvite['std_invite_denied']);
|
||||
if ($CURUSER['invites'] < 1)
|
||||
stderr($lang_takeinvite['std_error'],$lang_takeinvite['std_no_invite']);
|
||||
$userRep = new \App\Repositories\UserRepository();
|
||||
try {
|
||||
$sendText = $userRep->getInviteBtnText($CURUSER['id']);
|
||||
} catch (\Exception $exception) {
|
||||
stderr($lang_takeinvite['std_error'], $exception->getMessage());
|
||||
}
|
||||
function bark($msg) {
|
||||
stdhead();
|
||||
stdmsg($lang_takeinvite['head_invitation_failed'], $msg);
|
||||
@@ -43,7 +45,24 @@ if ($b[0] != 0)
|
||||
$ret = sql_query("SELECT username FROM users WHERE id = ".sqlesc($id)) or sqlerr();
|
||||
$arr = mysql_fetch_assoc($ret);
|
||||
|
||||
$hash = md5(mt_rand(1,10000).$CURUSER['username'].TIMENOW.$CURUSER['passhash']);
|
||||
if (empty($_POST['hash'])) {
|
||||
bark($lang_takeinvite['std_must_select_invite']);
|
||||
}
|
||||
if ($_POST['hash'] == 'permanent') {
|
||||
$hash = md5(mt_rand(1,10000).$CURUSER['username'].TIMENOW.$CURUSER['passhash']);
|
||||
} else {
|
||||
$hashRecord = \App\Models\Invite::query()->where('inviter', $CURUSER['id'])->where('hash', $_POST['hash'])->first();
|
||||
if (!$hashRecord) {
|
||||
bark($lang_takeinvite['hash_not_exists']);
|
||||
}
|
||||
if ($hashRecord->invitee != '') {
|
||||
bark('hash '.$lang_takeinvite['std_is_in_use']);
|
||||
}
|
||||
if ($hashRecord->expired_at->lt(now())) {
|
||||
bark($lang_takeinvite['hash_expired']);
|
||||
}
|
||||
$hash = $_POST['hash'];
|
||||
}
|
||||
|
||||
$title = $SITENAME.$lang_takeinvite['mail_tilte'];
|
||||
|
||||
@@ -60,8 +79,16 @@ EOD;
|
||||
$sendResult = sent_mail($email,$SITENAME,$SITEEMAIL,$title,$message,"invitesignup",false,false,'');
|
||||
//this email is sent only when someone give out an invitation
|
||||
if ($sendResult === true) {
|
||||
sql_query("INSERT INTO invites (inviter, invitee, hash, time_invited) VALUES ('".mysql_real_escape_string($id)."', '".mysql_real_escape_string($email)."', '".mysql_real_escape_string($hash)."', " . sqlesc(date("Y-m-d H:i:s")) . ")");
|
||||
sql_query("UPDATE users SET invites = invites - 1 WHERE id = ".mysql_real_escape_string($id)) or sqlerr(__FILE__, __LINE__);
|
||||
if (isset($hashRecord)) {
|
||||
$hashRecord->update([
|
||||
'invitee' => $email,
|
||||
'time_invited' => now(),
|
||||
'valid' => 1,
|
||||
]);
|
||||
} else {
|
||||
sql_query("INSERT INTO invites (inviter, invitee, hash, time_invited) VALUES ('".mysql_real_escape_string($id)."', '".mysql_real_escape_string($email)."', '".mysql_real_escape_string($hash)."', " . sqlesc(date("Y-m-d H:i:s")) . ")");
|
||||
sql_query("UPDATE users SET invites = invites - 1 WHERE id = ".mysql_real_escape_string($id)) or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
header("Refresh: 0; url=invite.php?id=".htmlspecialchars($id)."&sent=1");
|
||||
|
||||
Reference in New Issue
Block a user