summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-admin/invites.php
blob: 8b21d7f1d400329697e4905ac10d2bc26821e758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require_once('admin.php');

$title = __('Invites');
$parent_file = 'edit.php';

if( $_POST[ 'action' ] == 'send' ) {
    $invites_left = get_usermeta( $user_ID, 'invites_left' );
    if( $invites_left != false ) {
	if( $_POST[ 'email' ] != '' && is_email( $_POST[ 'email' ] ) ) {
	    $email = $wpdb->escape( strtolower( $_POST[ 'email' ] ) );
	    $invites_list = get_usermeta( $current_user->data->ID, "invites_list" );
	    $pos = strpos( $invites_list, substr( $email, 1 ) );
	    if( $pos == true ) {
		    header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=alreadysent&to=" . urlencode(  $email ) );
		    exit;
	    }
	    $invites_list .= strtolower( $email ) . " ";
	    update_usermeta( $current_user->data->ID, "invites_list", $invites_list );

	    $msg     = get_site_option( "invites_default_message" );
	    $subject = get_site_option( "invites_default_subject" );
	    $from    = $cache_userdata[ $user_ID ]->user_email;

	    $visitor_pass = md5( $email );
	    $msg = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $msg );
	    $msg = str_replace( "LASTNAME", $_POST[ 'lname' ], $msg );
	    $msg = str_replace( "PERSONALMESSAGE", $_POST[ 'personalmessage' ], $msg );
	    $msg = str_replace( "VISITORPASS", $visitor_pass, $msg );
	    $msg = str_replace( "\\r\\n", "\n", stripslashes( str_replace( "REGURL", "http://" . $current_site->domain . "/invite/" . $visitor_pass, $msg ) ) );

	    $subject = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $subject );
	    if( $cache_userdata[ $user_ID ]->display_name != '' ) {
		$username = $cache_userdata[ $user_ID ]->display_name;
	    } elseif( $cache_userdata[ $user_ID ]->first_name != '' ) {
		$username = $cache_userdata[ $user_ID ]->first_name;
	    } elseif( $cache_userdata[ $user_ID ]->nickname != '' ) {
		$username = $cache_userdata[ $user_ID ]->nickname;
	    } else {
		$username = __( 'Someone' );
	    }
	    $subject = str_replace( "USERNAME", ucfirst( $username ), $subject );

	    $query = "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', 'invite' , '".md5( strtolower( $email ) )."')";
	    $wpdb->query( $query );
	    $query = "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_invited_by' , '$user_ID')";
	    $wpdb->query( $query );
	    mail( $_POST[ 'email' ], $subject, $msg, "From: $from" );
	    if( $user_ID != get_site_option( "admin_user_id" ) ) {
		    $invites_left = $invites_left - 1;
		    update_usermeta( $user_ID, "invites_left", $invites_left );
	    }
	    header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=sent&to=" . urlencode(  $email ) );
	    exit;
	}
    } else {
	    header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=notsent&to=" . urlencode(  $email ) );
	    exit;
    }
} elseif( $_POST[ 'personalmessage' ] == '' ) {
    $_POST[ 'personalmessage' ] = "I've been using WordPress and thought you might 
like to try it out.  Here's an invitation to 
create an account.";
}

include('admin-header.php');
if (isset($_GET['result'] ) && $_GET['result'] == 'sent' ) {
    ?><div class="updated"><p><strong><?php echo sprintf( __("Invite Sent to %s."), $wpdb->escape( $_GET[ 'to' ] ) ) ?></strong></p></div><?php
} elseif (isset($_GET['result'] ) && $_GET['result'] == 'notsent' ) {
    ?><div class="updated"><p><strong><?php echo sprintf( __("Invite Not Sent to %s."), $wpdb->escape( $_GET[ 'to' ] ) ) ?></strong></p></div><?php
} elseif (isset($_GET['result'] ) && $_GET['result'] == 'alreadysent' ) {
    ?><div class="updated"><p><strong><?php echo sprintf( __("Invite Already Sent to %s."), $wpdb->escape( $_GET[ 'to' ] ) ) ?></strong></p></div><?php
}
?>
 
<div class="wrap"> 
  <h2><?php _e('Invites') ?></h2> 
  <form name="form1" method="post" action="invites.php"> 
    <input type="hidden" name="action" value="send" /> 
    <fieldset class="options"> 
    <legend><?php _e('Send Invite To') ?></legend> 
    <table width="100%" cellspacing="2" cellpadding="5" class="editform"> 
      <tr valign="top"> 
        <th width="33%" scope="row"><?php _e('First Name:') ?></th> 
        <td><input name="fname" type="text" id="fname" value="<?php echo stripslashes( $_POST[ 'fname' ] ) ?>" size="40" /></td> 
      </tr> 
      <tr valign="top"> 
        <th width="33%" scope="row"><?php _e('Last Name:') ?></th> 
        <td><input name="lname" type="text" id="lname" value="<?php echo stripslashes( $_POST[ 'lname' ] ) ?>" size="40" /></td> 
      </tr> 
      <tr valign="top"> 
        <th width="33%" scope="row"><?php _e('Email:') ?></th> 
        <td><input name="email" type="text" id="email" value="<?php echo stripslashes( $_POST[ 'email' ] ) ?>" size="40" /></td> 
      </tr> 
      <tr valign="top"> 
        <th width="33%" scope="row"><?php _e('Personal Message:') ?></th> 
        <td><textarea rows="5" cols="40" name="personalmessage" tabindex="5" id="defaultmessage"><?php echo stripslashes( $_POST[ 'personalmessage' ] ) ?></textarea></td> 
      </tr> 
    </table> 
    </fieldset> 
    <p class="submit">
      <input type="submit" name="Submit" value="<?php _e('Send Invite') ?> &raquo;" />
    </p>
  </form> 
</div>
<?php
$invites_list = get_usermeta( $current_user->data->ID, "invites_list" );
if( $invites_list != '' )
{
	print '<div class="wrap">';
	print "<h3>Already Invited</h3>";
	print "<p>You already invited: $invites_list</p>";
	print '</div>';
}
?>
<?php include("admin-footer.php") ?>