123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- /**
- * [Discuz!] (C)2001-2099 Comsenz Inc.
- * This is NOT a freeware, use is subject to license terms
- *
- * $Id: spacecp_invite.php 25042 2011-10-24 03:27:47Z zhengqingpeng $
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- $creditid = 0;
- $creditnum = $_G['group']['inviteprice'];
- if($_G['setting']['creditstrans']) {
- $creditid = intval($_G['setting']['creditstransextra'][6] ? $_G['setting']['creditstransextra'][6] : $_G['setting']['creditstrans']);
- } elseif($creditnum) {
- showmessage('trade_credit_invalid', '', array(), array('return' => 1));
- }
- space_merge($space, 'count');
- $baseurl = 'home.php?mod=spacecp&ac=invite';
- $siteurl = getsiteurl();
- $maxcount = 50;
- $config = $_G['setting']['inviteconfig'];
- $creditname = $config['inviterewardcredit'];
- $allowinvite = ($_G['setting']['regstatus'] > 1 && $creditname && $_G['group']['allowinvite']) ? 1 : 0;
- $unit = $_G['setting']['extcredits'][$creditname]['unit'];
- $credittitle = $_G['setting']['extcredits'][$creditname]['title'];
- $creditname = 'extcredits'.$creditname;
- $inviteurl = $invite_code = '';
- $appid = empty($_GET['app']) ? 0 : intval($_GET['app']);
- $creditkey = 'extcredits'.$creditid;
- $extcredits = $_G['setting']['extcredits'][$creditid];
- $mailvar = array(
- 'avatar' => avatar($space['uid'], 'middle'),
- 'uid' => $space['uid'],
- 'username' => $space['username'],
- 'sitename' => $_G['setting']['sitename'],
- 'siteurl' => $siteurl
- );
- $appinfo = array();
- if($appid) {
- $appinfo = C::t('common_myapp')->fetch($appid);
- if($appinfo) {
- $inviteapp = "&app=$appid";
- $mailvar['appid'] = $appid;
- $mailvar['appname'] = $appinfo['appname'];
- } else {
- $appid = 0;
- }
- }
- if(!$creditnum) {
- $inviteurl = getinviteurl(0, 0, $appid);
- }
- if(!$allowinvite) {
- showmessage('close_invite', '', array(), $_G['inajax'] ? array('showdialog'=>1, 'showmsg' => true, 'closetime' => true) : array());
- }
- if(submitcheck('emailinvite')) {
- if(!$_G['group']['allowmailinvite']) {
- showmessage('mail_invite_not_allow', $baseurl);
- }
- $_POST['email'] = str_replace("\n", ',', $_POST['email']);
- $newmails = array();
- $mails = explode(",", $_POST['email']);
- foreach ($mails as $value) {
- $value = trim($value);
- if(isemail($value)) {
- $newmails[] = $value;
- }
- }
- $newmails = array_unique($newmails);
- $invitenum = count($newmails);
- if($invitenum < 1) {
- showmessage('mail_can_not_be_empty', $baseurl);
- }
- $msetarr = array();
- if($creditnum) {
- $allcredit = $invitenum * $creditnum;
- if($space[$creditkey] < $allcredit) {
- showmessage('mail_credit_inadequate', $baseurl);
- }
- foreach($newmails as $value) {
- $code = strtolower(random(6));
- $setarr = array(
- 'uid' => $_G['uid'],
- 'code' => $code,
- 'email' => daddslashes($value),
- 'type' => 1,
- 'appid' => $appid,
- 'inviteip' => $_G['clientip'],
- 'dateline' => $_G['timestamp'],
- 'status' => 3,
- 'endtime' => ($_G['group']['maxinviteday']?($_G['timestamp']+$_G['group']['maxinviteday']*24*3600):0)
- );
- $id = C::t('common_invite')->insert($setarr, true);
- $mailvar['inviteurl'] = getinviteurl($id, $code, $appid);
- createmail($value, $mailvar);
- }
- updatemembercount($_G['uid'], array($creditkey => "-$allcredit"));
- } else {
- $mailvar['inviteurl'] = $inviteurl;
- foreach($newmails as $value) {
- createmail($value, $mailvar);
- }
- }
- showmessage('send_result_succeed',$baseurl);
- } else if(submitcheck('invitesubmit')) {
- $invitenum = intval($_POST['invitenum']);
- if($invitenum < 1) $invitenum = 1;
- if($_G['group']['maxinvitenum']) {
- $daytime = $_G['timestamp'] - 24*3600;
- $invitecount = C::t('common_invite')->count_by_uid_dateline($_G['uid'], $daytime);
- if($invitecount + $invitenum > $_G['group']['maxinvitenum']) {
- showmessage('max_invitenum_error', NULL, array('maxnum'=>$_G['group']['maxinvitenum']), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- }
- }
- $allcredit = $invitenum * $creditnum;
- if($space[$creditkey] < $allcredit) {
- showmessage('mail_credit_inadequate', $baseurl, array(), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- }
- $havecode = false;
- $dateline = $_G['timestamp'];
- for($i=0; $i<$invitenum; $i++) {
- $code = strtolower(random(6));
- $havecode = true;
- $invitedata = array(
- 'uid' => $_G['uid'],
- 'code' => $code,
- 'dateline' => $dateline,
- 'endtime' => $_G['group']['maxinviteday'] ? ($_G['timestamp']+$_G['group']['maxinviteday']*24*3600) : 0,
- 'inviteip' => $_G['clientip']
- );
- C::t('common_invite')->insert($invitedata);
- }
- if($havecode) {
- require_once libfile('class/credit');
- $creditobj = new credit();
- $creditobj->updatemembercount(array($creditkey=>0-$allcredit), $_G['uid']);
- }
- showmessage('do_success', $baseurl, array('deduction' => $allcredit, 'dateline' => $dateline), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true, 'return' => false));
- }
- if($_GET['op'] == 'resend') {
- $id = $_GET['id'] ? intval($_GET['id']) : 0;
- if(submitcheck('resendsubmit')) {
- if(empty($id)) {
- showmessage('send_result_resend_error', $baseurl);
- }
- if($value = C::t('common_invite')->fetch_by_id_uid($id, $_G['uid'])) {
- if($creditnum) {
- $inviteurl = getinviteurl($value['id'], $value['code'], $value['appid']);
- }
- $mailvar['inviteurl'] = $inviteurl;
- createmail($value['email'], $mailvar);
- showmessage('send_result_succeed', dreferer(), array('id' => $id), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- } else {
- showmessage('send_result_resend_error', $baseurl, array(), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- }
- }
- } elseif($_GET['op'] == 'delete') {
- $id = $_GET['id'] ? intval($_GET['id']) : 0;
- if(empty($id)) {
- showmessage('there_is_no_record_of_invitation_specified', $baseurl);
- }
- if($value = C::t('common_invite')->fetch_by_id_uid($id, $_G['uid'])) {
- if(submitcheck('deletesubmit')) {
- C::t('common_invite')->delete($id);
- showmessage('do_success', dreferer(), array('id' => $id), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- }
- } else {
- showmessage('there_is_no_record_of_invitation_specified', $baseurl, array(), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
- }
- } elseif ($_GET['op'] == 'showinvite') {
- foreach(C::t('common_invite')->fetch_all_by_uid($_G['uid']) as $value) {
- if(!$value['fuid'] && !$value['type']) {
- $inviteurl = getinviteurl($value['id'], $value['code'], $value['appid']);
- $list[$value[code]] = $inviteurl;
- }
- }
- } else {
- $list = $flist = $dels = array();
- $invitedcount = $count = 0;
- foreach(C::t('common_invite')->fetch_all_by_uid($_G['uid']) as $value) {
- if($value['fuid']) {
- $flist[] = $value;
- $invitedcount++;
- } else {
- if($_G['timestamp'] > $value['endtime']) {
- $dels[] = $value['id'];
- continue;
- }
- $inviteurl = getinviteurl($value['id'], $value['code'], $value['appid']);
- if($value['type']) {
- $maillist[] = array(
- 'email' => $value['email'],
- 'url' => $inviteurl,
- 'id' => $value['id']
- );
- } else {
- $list[$value[code]] = $inviteurl;
- $count++;
- }
- }
- }
- if($dels) {
- C::t('common_invite')->delete($dels);
- }
- $uri = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:($_SERVER['PHP_SELF']?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME']);
- $uri = substr($uri, 0, strrpos($uri, '/')+1);
- $actives = array('invite'=>' class="a"');
- }
- $navtitle = lang('core', 'title_invite_friend');
- include template('home/spacecp_invite');
- function createmail($mail, $mailvar) {
- global $_G, $space, $appinfo;
- $mailvar['saymsg'] = empty($_POST['saymsg'])?'':getstr($_POST['saymsg'], 500);
- require_once libfile('function/mail');
- $subject = lang('spacecp', $appinfo?'app_invite_subject':'invite_subject', $mailvar);
- $message = lang('spacecp', $appinfo?'app_invite_massage':'invite_massage', $mailvar);
- if(!sendmail($mail, $subject, $message)) {
- runlog('sendmail', "$mail sendmail failed.");
- }
- }
- function getinviteurl($inviteid, $invitecode, $appid) {
- global $_G;
- if($inviteid && $invitecode) {
- $inviteurl = getsiteurl()."home.php?mod=invite&id={$inviteid}&c={$invitecode}";
- } else {
- $invite_code = space_key($_G['uid'], $appid);
- $inviteapp = $appid?"&app=$appid":'';
- $inviteurl = getsiteurl()."home.php?mod=invite&u=$_G[uid]&c=$invite_code{$inviteapp}";
- }
- return $inviteurl;
- }
- ?>
|