<?
//***************************************************
// http://www.scriptindonesia.com
// Solusi Hemat Script Bisnis Online Anda
// Menerima Jasa Pembuatan Website & Template Website
//***************************************************
?>
<?
//Edit Script AW 20160221
//if (session_is_registered("valid_admin")) {
  if (isset($_SESSION['valid_admin'])) {
?>

<title>Admin Kirim Email Massal</title>

<!--- Start TinyMCE -->
	<script src="../tinymcpuk/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
	<script src="../tinymcpuk/jscripts/tiny_mce/tiny_lokomedia.js" type="text/javascript"></script>
<!-- Finish TinyMCE -->

<?
//---------- free member-------------
$sfm="SELECT username FROM member WHERE status='0'";
$mqry=mysql_query($sfm);
$j_fm=mysql_num_rows($mqry);

//---------- member biasa-------------
$sbm="SELECT username FROM member WHERE status='1'";
$bqry=mysql_query($sbm);
$j_bm=mysql_num_rows($bqry);
//---------- xtra member-------------
$xfm="SELECT username FROM member WHERE status='2'";
$xqry=mysql_query($xfm);
$j_xm=mysql_num_rows($xqry);
$tot_mbr = $j_fm + $j_bm + $j_xm;

//--------newest member-------------
$nbr="SELECT username FROM member ORDER BY id DESC limit 1";
$dqr=mysql_query($nbr);
$new=mysql_fetch_array($dqr);

$emailadmin = $db->config("email");
$cs_domain  = $db->config("bank2");
?><table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#bfd6ed">
  <tr bgcolor="#8c759a">
    <td colspan="3" height="30"><p align="center" class="title"><strong><u>Kirim Email Massal</u></strong><u></u></p></td>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#7fa1c2"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
  </tr>
  <tr>
    <td width="1" rowspan="4" bgcolor="#7fa1c2"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
    <td width="100%" height="4" bgcolor="#EF9400"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
    <td width="1" rowspan="4" bgcolor="#7fa1c2"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
  </tr>
  <tr>
    <td valign="top">
<?
switch($page) {
	default :
?>      
	<p align="center">Halaman ini digunakan untuk mengirimkan informasi kepada  free member, active member atau kepada semuanya secara sekaligus.<br />
	Hati-hati pada penggunaan fasilitas kirim email massal ini. Cukup sekali saja klik tombol <strong>KIRIM EMAIL</strong> karena jika terlalu sering maka akan dianggap <strong>SPAM</strong>.</p>
        <hr />
      <form name="form1" method="post" action="?m=mailmass&page=kirim">
        <table width="90%" border="0" align="center" cellpadding="2" cellspacing="1">
          <tr>
            <td width="32%" align="right">Ditujukan ke : </td>
            <td width="68%"><label>
            <?
	if($tujuan <> "") {
	?>
            <input name="tujuan" type="text" class="form" id="tujuan" value="<?= $tujuan; ?>" size="20">
            <?
	} else {
	?>
            <select name="tujuan" id="tujuan" class="form">
              <option value="0">-- Silahkan Pilih --</option>
              <option value="1">Free Member</option>
              <option value="2">Member Aktif</option>
              <option value="3">Semua Member</option>
            </select>
            <?
	}
	?>
</label></td>
          </tr>
          <tr>
            <td align="right">Subjek : </td>
            <td><input name="subjek" type="text" class="form" id="subjek" size="50"></td>
          </tr>
          <tr>
            <td align="right" valign="top">Isi Pesan : </td>
            <td><textarea id='loko' name="pesan" cols="50" rows="8" class="form" id="pesan"></textarea></td>
            <!--<td><textarea id='loko' name='isi_berita' style='width: 120px; height: 350px;'></textarea></td>-->
          </tr>
          <tr>
            <td valign="top">&nbsp;</td>
            <td>ket : kirim email dengan kalimat saja, krn gambar tidak akan terkirim.<p>
                <label>
                <input type="submit" name="Submit" value="KIRIM EMAIL" class="tombol">
                </label>
              </p>
              </td>
          </tr>
        </table>
      </form>
      
<?
	break;

	case kirim :
	if($tujuan == 0 or $pesan == "") {
		echo "<p align=center><br><br><b>Kepada siapa informasi ini akan dikirimkan dan apa pesannya?<br>Klik BACK untuk mengulang!</b></p>";
                echo "
                <center>
                    <input type='button' name='kembali' id='kembali' value='KEMBALI' class='tombol' onclick='javascript:history.go(-1)' />
                </center>
                ";
	} else {

		if($tujuan == 1) {
			$sql=mysql_query("SELECT nama, email FROM member WHERE status=0");
		}
		//-------paid member------
		if($tujuan == 2) {
			$sql=mysql_query("SELECT nama, email FROM member WHERE status=1");
		}
		//------semua----------
		if($tujuan == 3) {
			$sql=mysql_query("SELECT nama, email FROM member");
		}
		$cek=mysql_num_rows($sql);
		//for($i=0;$i<$cek;$i++) {
                $from       =  $db->config("email_noreply");
                $headers    = "From: $cs_domain <".$from.">\nX-Sender: ".$from."\n";
	      //$headers    = "From: www.scriptindonesia.com<$emailadmin>\nX-Sender: $emailadmin\n";
		while($data=mysql_fetch_row($sql)) {
			$email      = $data[1];
			$nama       = $data[0];
                        $isi_pesan  = "
                        <html>
                            $pesan
                        </html>
                        ";

                        $headers    = "MIME-Version: 1.0" . "\r\n";
                        $headers   .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                      //$headers   .= 'From:' . $from . "\r\n";
                        $headers   .= "From: $cs_domain <".$db->config("email_noreply").">\nX-Sender: ".$db->config("email_noreply")."\r\n";
			@mail($email, $subjek, $isi_pesan, $headers);
		}
		echo "<p align=center><b>Informasi telah berhasil dikirimkan!</b></p>";
	}
	break;
}
?>
    </td>
  </tr>
  <tr>
    <td background="../images/t_fon.gif" height="28"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
  </tr>
  <tr>
    <td colspan="3" align="right"><img src="../images/t_bot.gif" width="229" height="10" alt="" border="0"></td>
  </tr>

  <tr>
    <td colspan="3" bgcolor="#7fa1c2"><img src="../images/px1.gif" width="1" height="1" alt="" border="0"></td>
  </tr>

</table>
<?
} else {
echo "<meta http-equiv=\"refresh\" content=\"1; url=illegal.html\">";
}
?>