| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
require '../include/ispcp-lib.php'; |
|---|
| 22 |
|
|---|
| 23 |
check_login(__FILE__); |
|---|
| 24 |
|
|---|
| 25 |
function gen_page_data(&$tpl, &$sql) { |
|---|
| 26 |
if (isset($_POST['uaction']) && $_POST['uaction'] === 'send_circular') { |
|---|
| 27 |
$tpl->assign( |
|---|
| 28 |
array( |
|---|
| 29 |
'MESSAGE_SUBJECT' => clean_input($_POST['msg_subject'], false), |
|---|
| 30 |
'MESSAGE_TEXT' => clean_input($_POST['msg_text'], false), |
|---|
| 31 |
'SENDER_EMAIL' => clean_input($_POST['sender_email'], false), |
|---|
| 32 |
'SENDER_NAME' => clean_input($_POST['sender_name'], false) |
|---|
| 33 |
) |
|---|
| 34 |
); |
|---|
| 35 |
} else { |
|---|
| 36 |
$user_id = $_SESSION['user_id']; |
|---|
| 37 |
|
|---|
| 38 |
$query = <<<SQL_QUERY |
|---|
| 39 |
select |
|---|
| 40 |
fname, lname, email |
|---|
| 41 |
from |
|---|
| 42 |
admin |
|---|
| 43 |
where |
|---|
| 44 |
admin_id = ? |
|---|
| 45 |
group by |
|---|
| 46 |
email |
|---|
| 47 |
SQL_QUERY; |
|---|
| 48 |
|
|---|
| 49 |
$rs = exec_query($sql, $query, array($user_id)); |
|---|
| 50 |
|
|---|
| 51 |
if (isset($rs->fields['fname']) && isset($rs->fields['lname'])) { |
|---|
| 52 |
$sender_name = $rs->fields['fname'] . " " . $rs->fields['lname']; |
|---|
| 53 |
} elseif(isset($rs->fields['fname']) && !isset($rs->fields['lname'])) { |
|---|
| 54 |
$sender_name = $rs->fields['fname']; |
|---|
| 55 |
} elseif(!isset($rs->fields['fname']) && isset($rs->fields['lname'])) { |
|---|
| 56 |
$sender_name = $rs->fields['lname']; |
|---|
| 57 |
} else { |
|---|
| 58 |
$sender_name = ""; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
$tpl->assign( |
|---|
| 62 |
array( |
|---|
| 63 |
'MESSAGE_SUBJECT' => '', |
|---|
| 64 |
'MESSAGE_TEXT' => '', |
|---|
| 65 |
'SENDER_EMAIL' => $rs->fields['email'], |
|---|
| 66 |
'SENDER_NAME' => $sender_name |
|---|
| 67 |
) |
|---|
| 68 |
); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
function check_user_data (&$tpl) { |
|---|
| 73 |
global $msg_subject, $msg_text, $sender_email, $sender_name; |
|---|
| 74 |
|
|---|
| 75 |
$err_message = ''; |
|---|
| 76 |
|
|---|
| 77 |
$msg_subject = clean_input($_POST['msg_subject'], false); |
|---|
| 78 |
$msg_text = clean_input($_POST['msg_text'], false); |
|---|
| 79 |
$sender_email = clean_input($_POST['sender_email'], false); |
|---|
| 80 |
$sender_name = clean_input($_POST['sender_name'], false); |
|---|
| 81 |
|
|---|
| 82 |
if (empty($msg_subject)) { |
|---|
| 83 |
$err_message .= tr('Please specify a message subject!'); |
|---|
| 84 |
} |
|---|
| 85 |
if (empty($msg_text)) { |
|---|
| 86 |
$err_message .= tr('Please specify a message content!'); |
|---|
| 87 |
} |
|---|
| 88 |
if (empty($sender_name)) { |
|---|
| 89 |
$err_message .= tr('Please specify a sender name!'); |
|---|
| 90 |
} |
|---|
| 91 |
if (empty($sender_email)) { |
|---|
| 92 |
$err_message .= tr('Please specify a sender email!'); |
|---|
| 93 |
} |
|---|
| 94 |
else if (!chk_email($sender_email)) { |
|---|
| 95 |
$err_message .= tr("Incorrect email length or syntax!"); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
if (!empty($err_message)) { |
|---|
| 99 |
set_page_message($err_message); |
|---|
| 100 |
return false; |
|---|
| 101 |
} else { |
|---|
| 102 |
return true; |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
function send_circular(&$tpl, &$sql) { |
|---|
| 107 |
if (isset($_POST['uaction']) && $_POST['uaction'] === 'send_circular') { |
|---|
| 108 |
if (check_user_data($tpl)) { |
|---|
| 109 |
send_reseller_users_message ($sql, $_SESSION['user_id']); |
|---|
| 110 |
unset($_POST['uaction']); |
|---|
| 111 |
gen_page_data($tpl, $sql); |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
function send_reseller_users_message (&$sql, $admin_id) { |
|---|
| 117 |
|
|---|
| 118 |
$msg_subject = clean_input($_POST['msg_subject'], false); |
|---|
| 119 |
$msg_text = clean_input($_POST['msg_text'], false); |
|---|
| 120 |
$sender_email = clean_input($_POST['sender_email'], false); |
|---|
| 121 |
$sender_name = clean_input($_POST['sender_name'], false); |
|---|
| 122 |
|
|---|
| 123 |
$query = <<<SQL_QUERY |
|---|
| 124 |
select |
|---|
| 125 |
fname, lname, email |
|---|
| 126 |
from |
|---|
| 127 |
admin |
|---|
| 128 |
where |
|---|
| 129 |
admin_type = 'user' and created_by = ? |
|---|
| 130 |
group by |
|---|
| 131 |
email |
|---|
| 132 |
SQL_QUERY; |
|---|
| 133 |
|
|---|
| 134 |
$rs = exec_query($sql, $query, array($admin_id)); |
|---|
| 135 |
|
|---|
| 136 |
while (!$rs->EOF) { |
|---|
| 137 |
$to = "\"" . encode($rs->fields['fname'] . " " . $rs->fields['lname']) . "\" <" . $rs->fields['email'] . ">"; |
|---|
| 138 |
|
|---|
| 139 |
send_circular_email($to, "\"" . encode($sender_name) . "\" <" . $sender_email . ">", stripslashes($msg_subject), stripslashes($msg_text)); |
|---|
| 140 |
|
|---|
| 141 |
$rs->MoveNext(); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
set_page_message(tr('You send email to your users successfully!')); |
|---|
| 145 |
write_log("Mass email was sended from Reseller " . $sender_name . " <" . $sender_email . ">"); |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
function send_circular_email ($to, $from, $subject, $message) { |
|---|
| 149 |
$subject = encode($subject); |
|---|
| 150 |
|
|---|
| 151 |
$headers = "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n"; |
|---|
| 152 |
$headers .= "From: " . $from . "\n"; |
|---|
| 153 |
$headers .= "X-Mailer: ispCP marketing mailer"; |
|---|
| 154 |
|
|---|
| 155 |
mail($to, $subject, $message, $headers); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
$tpl = new pTemplate(); |
|---|
| 159 |
$tpl->define_dynamic('page', Config::get('RESELLER_TEMPLATE_PATH') . '/circular.tpl'); |
|---|
| 160 |
$tpl->define_dynamic('page_message', 'page'); |
|---|
| 161 |
$tpl->define_dynamic('logged_from', 'page'); |
|---|
| 162 |
|
|---|
| 163 |
$theme_color = Config::get('USER_INITIAL_THEME'); |
|---|
| 164 |
|
|---|
| 165 |
$tpl->assign( |
|---|
| 166 |
array( |
|---|
| 167 |
'TR_RESELLER_CIRCULAR_PAGE_TITLE' => tr('ispCP - Circular'), |
|---|
| 168 |
'THEME_COLOR_PATH' => "../themes/$theme_color", |
|---|
| 169 |
'THEME_CHARSET' => tr('encoding'), |
|---|
| 170 |
|
|---|
| 171 |
'ISP_LOGO' => get_logo($_SESSION['user_id']), |
|---|
| 172 |
) |
|---|
| 173 |
); |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_users_manage.tpl'); |
|---|
| 182 |
gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_users_manage.tpl'); |
|---|
| 183 |
|
|---|
| 184 |
gen_logged_from($tpl); |
|---|
| 185 |
|
|---|
| 186 |
$tpl->assign( |
|---|
| 187 |
array( |
|---|
| 188 |
'TR_CIRCULAR' => tr('Circular'), |
|---|
| 189 |
'TR_CORE_DATA' => tr('Core data'), |
|---|
| 190 |
'TR_SEND_TO' => tr('Send message to'), |
|---|
| 191 |
'TR_ALL_USERS' => tr('All users'), |
|---|
| 192 |
'TR_ALL_RESELLERS' => tr('All resellers'), |
|---|
| 193 |
'TR_ALL_USERS_AND_RESELLERS' => tr('All users & resellers'), |
|---|
| 194 |
'TR_MESSAGE_SUBJECT' => tr('Message subject'), |
|---|
| 195 |
'TR_MESSAGE_TEXT' => tr('Message'), |
|---|
| 196 |
'TR_ADDITIONAL_DATA' => tr('Additional data'), |
|---|
| 197 |
'TR_SENDER_EMAIL' => tr('Senders email'), |
|---|
| 198 |
'TR_SENDER_NAME' => tr('Senders name'), |
|---|
| 199 |
'TR_SEND_MESSAGE' => tr('Send message'), |
|---|
| 200 |
'TR_SENDER_NAME' => tr('Senders name'), |
|---|
| 201 |
) |
|---|
| 202 |
); |
|---|
| 203 |
|
|---|
| 204 |
send_circular($tpl, $sql); |
|---|
| 205 |
|
|---|
| 206 |
gen_page_data ($tpl, $sql); |
|---|
| 207 |
|
|---|
| 208 |
gen_page_message($tpl); |
|---|
| 209 |
|
|---|
| 210 |
$tpl->parse('PAGE', 'page'); |
|---|
| 211 |
$tpl->prnt(); |
|---|
| 212 |
|
|---|
| 213 |
if (Config::get('DUMP_GUI_DEBUG')) |
|---|
| 214 |
dump_gui_debug(); |
|---|
| 215 |
|
|---|
| 216 |
unset_messages(); |
|---|
| 217 |
|
|---|
| 218 |
?> |
|---|