Connecting Tech Pros Worldwide Forums | Help | Site Map

Newsletter

Banned
 
Join Date: Aug 2009
Posts: 14
#1: Sep 1 '09
Dear sir
I am working below script update mailadress to database but not send email addres any correction its there

<?php

//
// Copyright (c) 2009 Michal Šimonfy http://virae.org | i@virae.org
// NEWSLETTER MODULE | http://virae.org/newsletter_module
// Licenced under Creative Commons Attribution-Noncommercial-Share Alike 3.0
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// Version: .9 (Feb 29, 2009)

// Hi! and thanks for downloading my newsletter module,
// please, notice the settings section just a few lines below,
// where you can configure some of module preferences.
// [ f.e optional password protection, custom template for e-mails, custom css, ... ]

// Please feel free to use the plugin for your personal use, or for non-comercial
// projects. Please, always keep this header included and if you like this plugin,
// feel free to write me an e-mail. Thank you !

// Common mistakes: If You get an error "SyntaxError: missing } in XML expression,"
// please, set your directory for attachments writable.

Expand|Select|Wrap|Line Numbers
  1. ?>
  2. <?php
  3.     header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  4.     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  5. ?><?php
  6.  
  7. // ============
  8. // = SETTINGS =
  9. // ============
  10.  
  11. // SCRIPT URL
  12.  
  13.     $script_url = 'http://noveidey.sk/newsletter/index.php';
  14.  
  15. // PASSWORD PROTECTION
  16.  
  17.     $password_protection = false;
  18.     // password
  19.     $password = "mypassword";
  20.     $password_hash = sha1($password);
  21.  
  22. // E-MAIL
  23.     //your e-mail
  24.     $your_email = "aajayaprakash@yahoo.com";
  25.     //your e-mail
  26.     $your_name = "AIDINDIA";
  27.     //email check - your address will be added to recipients everytime
  28.     $mailcheck = false;
  29.  
  30. // DATABASE
  31.  
  32.     $host = "localhost";
  33.     $user = "root";
  34.     $password = "aid";
  35.     $database = "newsletter";
  36.  
  37. // TABLES
  38.  
  39.     $table_emails = "newsletter_emails";
  40.     $table_categories = "newsletter_categories";
  41.     $table_sent = "newsletter_sent_mails";
  42.  
  43. // PROTECTED CATEGORIES 
  44.  
  45.     $protected = Array(1);
  46.  
  47. // ATTACHMENT DIR
  48.  
  49.     //directory Where To Upload Files - MUST BE SET WRITABLE !!!
  50.     $dir = "attachments/";
  51.     $jquery_src = "images/jquery.min.js";
  52.  
  53. // SESSION
  54.  
  55.     $session_name = 'newsletter';
  56.     // session timeout in seconds
  57.     $session_timeout = 3600; 
  58.  
  59. // OPTIONAL E-MAIL TEMPLATE
  60.  
  61.     // SET THIS TO TRUE IF YOU LIKE TO USE THE TEMPLATE FOR SENT E-MAILS
  62.     $use_template = true;
  63.  
  64.     // IF SET TO TRUE, EMAIL MESSAGE WILL BE WRAPPED WITH THESE HTML STRINGS
  65.  
  66.     $template_top = '
  67.     <html>
  68.         <body>
  69.             <div style="background-color:#fff;padding:10px;width:700px;margin:0;" id="name">
  70.                 <div style="border-top:20px solid #ECECEC;border-bottom:5px solid #37B7D3;">
  71.                     <img src="http://virae.org/screenshots/2009-06-21_143148.jpg" />    
  72.                 </div>
  73.                 <div style="font-size:15px; padding-top:20px;font-family:arial; color:#444; ">';
  74.  
  75.     $template_bottom = '
  76.                 </div>
  77.             </div>
  78.         </body>
  79.     </html>';
  80.  
  81.  
  82. // CSS
  83.  
  84.     $css = "
  85.                 body {
  86.                     font-family: arial, verdana;
  87.                     font-size:15px;
  88.                     background:url(images/background.png) repeat-x;
  89.                 }
  90.                 h1 {
  91.                     color:#fff;
  92.                     font-size:45px;
  93.                 }
  94.                 h1, h2, h3, h4 {
  95.                     font-family:'myriad pro';
  96.                     color:#444;
  97.                     display:inline;
  98.                     font-weight:normal;
  99.                 }
  100.                 h2 {
  101.                     color:#666;
  102.                     font-weight:bold;
  103.                 }
  104.                 h4{
  105.                     font-size:small;
  106.                 }
  107.                 input[type=password],input[type=text],textarea {
  108.                     background-color: #f8f8f8;
  109.                     border-color: #fff #ddd #ddd #fff;
  110.                     border: 1px solid #ccc;
  111.                     color:#222;
  112.                 }
  113.                 input[type=password]:focus,textarea:focus,input[type=text]:focus {
  114.                     background-color: #fff;
  115.                     border: 1px solid #66CFFF;
  116.                 }           
  117.                 small{
  118.                   font-size:small;
  119.                   color:#777;
  120.                 }
  121.                 /* working indicator */
  122.                 #processing {
  123.                     background-color:#fff;
  124.                     border:1px solid #777;
  125.                     -moz-border-radius:3px;
  126.                     color:#666;
  127.                 }
  128.  
  129.                 .h2emails {
  130.                     color:#7CB4C6;
  131.                 }
  132.                 .backlink{
  133.                     color:#da5050;
  134.                     font-size:medium;
  135.                     font-weight:bold;
  136.                     opacity:.75
  137.                 }
  138.                 .backlink:hover{opacity:1;}
  139.                 .g{
  140.                 color:#339900;
  141.                 }
  142.                 .b{
  143.                 color:#0099CC;
  144.                 }
  145.                 .r{
  146.                 color:#CC0000;
  147.                 }
  148.                 .button{padding:4px 10px 4px 10px;background-color:#FFF;color:#222;-moz-border-radius:5px;}
  149.                 .mails {display:none;}
  150.  
  151.     ";
  152.  
  153. ?><?php
  154.  
  155.  
  156. // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  157.  
  158.  
  159. // <!-- =============================== -->
  160. // <!-- = FILE:  AJAX FILE UPLOAD PHP = -->
  161. // <!-- =============================== -->
  162.  
  163.     error_reporting(E_ALL ^ E_NOTICE);
  164.  
  165.     $error = "";
  166.     $msg = "";
  167.     $fileElementName = 'fileToUpload';
  168.  
  169.     // continue if there's file upload posted
  170.     if(!empty($_FILES[$fileElementName]['error']) || !empty($_FILES[$fileElementName]['tmp_name'])) {
  171.  
  172.         if(!empty($_FILES[$fileElementName]['error']))
  173.         {
  174.             switch($_FILES[$fileElementName]['error'])
  175.             {
  176.  
  177.                 case '1':
  178.                     $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
  179.                     break;
  180.                 case '2':
  181.                     $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
  182.                     break;
  183.                 case '3':
  184.                     $error = 'The uploaded file was only partially uploaded';
  185.                     break;
  186.                 case '4':
  187.                     $error = 'No file was uploaded.';
  188.                     break;
  189.  
  190.                 case '6':
  191.                     $error = 'Missing a temporary folder';
  192.                     break;
  193.                 case '7':
  194.                     $error = 'Failed to write file to disk';
  195.                     break;
  196.                 case '8':
  197.                     $error = 'File upload stopped by extension';
  198.                     break;
  199.                 case '999':
  200.                 default:
  201.                     $error = 'No error code avaiable';
  202.             }
  203.         }
  204.           else if (empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')
  205.         {
  206.             $error = 'No file was uploaded..';
  207.         }
  208.         else
  209.         {
  210.  
  211.           $file=$_FILES['fileToUpload']['name'];
  212.           $tempfile=$_FILES['fileToUpload']['tmp_name'];
  213.  
  214.           move_uploaded_file($tempfile, $dir.$file );
  215.  
  216.           $msg .= " File Name: " . $_FILES['fileToUpload']['name'];
  217.           $msg .= " File Size: " . @filesize($_FILES['fileToUpload']['tmp_name']);
  218.  
  219.        }
  220.  
  221.         echo "{";
  222.         echo                "error: '" . $error . "',\n";
  223.         echo                "file: '" . $file . "',\n";
  224.         echo                "msg: '" . $msg . "'\n";
  225.         echo "}";
  226.  
  227.         // stop output here
  228.         exit();
  229.  
  230.     }
  231. ?><?php
  232.  
  233.     //make connection
  234.     $server = mysql_connect($host, $user, $password);
  235.     $connection = mysql_select_db($database, $server);
  236.  
  237.     // CUSTOM SQL FUNCTIONS
  238.     function sql_quote($value) {
  239.  
  240.     $value = str_replace('<?','',$value);
  241.     $value = str_replace('script','',$value);
  242.  
  243.     if (get_magic_quotes_gpc()) {
  244.         $value = stripslashes($value);
  245.     }
  246.     if (!is_numeric($value)) {
  247.         $value = "'" . mysql_real_escape_string($value) . "'";
  248.     } else {
  249.         if ((string)$value[0] == '0') {
  250.             $value = "'" . mysql_real_escape_string($value) . "'";
  251.     }}
  252.     return $value;
  253.     }
  254.     function sql_lastinsertid() {
  255.         $result = mysql_query("SELECT LAST_INSERT_ID()");
  256.         $row = mysql_fetch_row($result);
  257.         return $row[0];
  258.     }
  259.     function sql_getfield($table, $field, $where_cond = "") {
  260.         $q = "SELECT ".$field." FROM ".$table." ".$where_cond;
  261.         $r = mysql_query($q);
  262.         $row = mysql_fetch_row($r);
  263.         return $row[0];
  264.     }
  265.  
  266. ?><?php
  267.  
  268. // <!-- ========================= -->
  269. // <!-- = UNSUBSCRIBE ACTION ==== -->
  270. // <!-- ========================= -->
  271.  
  272. if (isset($_GET['unsubscribe']) && sql_getfield($table_emails,'id','WHERE email = '.sql_quote($_GET['unsubscribe']))) {
  273.         $q = "DELETE from $table_emails WHERE email = ".sql_quote($_GET['unsubscribe']);
  274.         mysql_query($q);
  275.         echo 'Your e-mail has been removed !<br />Thank You.';
  276.         exit();
  277. }
  278.  
  279. ?><?php
  280.  
  281. // <!-- ======================= -->
  282. // <!-- = PASSWORD PROTECTION = -->
  283. // <!-- ======================= -->
  284.  
  285. if ($password_protection == true) {
  286.  
  287.     session_name($session_name);
  288.     session_start();
  289.  
  290.     // if (isset($_SESSION['last_ts'])) {$_SESSION['last_ts'];}
  291.  
  292.     if (!isset($_SESSION['last_ts']) && !isset($_POST['login'])) {
  293.  
  294.         // LOGIN FORM 
  295.  
  296.         echo '
  297.         <body style="background:url(images/background.png) repeat-x;">
  298.         <div style="position:fixed;top:35%;left:35%;width:50%">
  299.         <form action="index.php" method="post" accept-charset="utf-8">
  300.             <img src="images/logo.png" alt="logo" id="logo" name="logo" align="left" style="margin-right:20px;" />
  301.             <br /><h1 style="font-family: arial, verdana;font-size:20px;color:#222;margin:0;color:#777;display:inline;">Newsletter module </h1> <small> pre 0.9</small><br />
  302.             <br /><input type="password" name="login" id="login" style="padding:5px;display:inline;" />
  303.             <input type="submit" style="background-color:#E61056;color:#fff;border:0;padding:5px;-moz-border-radius:3px;" value="Login">
  304.         </form>
  305.         </div>
  306.         </body>
  307.         ';
  308.         exit(); 
  309.  
  310.     }
  311.  
  312.     if ($_POST['login'] && sha1($_POST['login'])==$password_hash) {
  313.  
  314.         $_SESSION['auth'] = substr(md5(microtime(true).mt_rand()), 0, 16);
  315.         $_SESSION['last_ts'] = time();
  316.         // to destroy the post variable
  317.         header('Location: index.php');
  318.  
  319.     }
  320.  
  321.     if ($_POST['login'] && sha1($_POST['login'])!=$password_hash) {
  322.         header('Location: index.php?info=invalidlogin');    
  323.     }
  324.  
  325.     else if ((time() - $_SESSION['last_ts'] > $session_timeout) || isset($_GET['logout'])) {
  326.         session_destroy();
  327.         header('Location: index.php');
  328.     }
  329.  
  330.     else if ((time() - $_SESSION['last_ts'] < $session_timeout)) {
  331.         $_SESSION['last_ts'] = time();
  332.     }
  333.  
  334.  
  335. }
  336. ?><?php
  337.  
  338. // <!-- ========================= -->
  339. // <!-- = FILE: AJAX PROCESSING = -->
  340. // <!-- ========================= -->
  341.  
  342.     // Setup
  343.     $error='';
  344.  
  345.     // DELETE E-MAILS
  346.  
  347.     if ($_POST['action']=='delmail') {
  348.  
  349.           $count = 0;
  350.           $category = $_POST["cat"];
  351.           $emails = $_POST["emails"];
  352.           if (!empty($emails)) {
  353.  
  354.               $email = explode("|",$emails);
  355.               foreach ($email as $value) {
  356.  
  357.                   if (!empty($value) && sql_getfield($table_emails,'id','WHERE id = '.sql_quote($value))) {
  358.                       $q = "DELETE from $table_emails WHERE id = ".sql_quote($value)." LIMIT 1";
  359.                       mysql_query($q);
  360.                       $count+=1;
  361.                   }
  362.               }
  363.           }
  364.           else {
  365.             $error = 'No emails are selected !';
  366.           }
  367.  
  368.           echo "{";
  369.           echo "error: '" . $error . "',\n";
  370.           echo "count: '" . $count . "'\n";
  371.           echo "}";
  372.  
  373.           exit();
  374.  
  375.     }
  376.  
  377.     // ***
  378.  
  379.     // DELETE CATEGORY
  380.  
  381.     if ($_POST['action']=='delcat') {
  382.  
  383.           $kategorie = $_POST["categories"];
  384.           if (!empty($kategorie)) {
  385.  
  386.               $category = explode("|",$kategorie);
  387.               foreach ($category as $value) {
  388.                   if (!empty($value) && sql_getfield($table_categories,'name','WHERE id = '.sql_quote($value))) {
  389.  
  390.                         if (!in_array($value,$protected)) {                
  391.  
  392.                               $q = "DELETE from $table_categories WHERE id = ".sql_quote($value)." LIMIT 1";
  393.                               mysql_query($q);
  394.                               $q = "DELETE from $table_emails WHERE category = ".sql_quote($value);
  395.                               mysql_query($q);
  396.                         }
  397.                         else {
  398.  
  399.                             $error = 'This category is protected';
  400.  
  401.                         }    
  402.                   }
  403.               }
  404.           }
  405.           else {
  406.             $error = 'Nie sú označené žiadne kategórie !';
  407.           }
  408.  
  409.           echo "{";
  410.         echo "error: '" . $error . "'\n";
  411.         echo "}";
  412.  
  413.         exit();
  414.  
  415.     }
  416.  
  417.     // ***
  418.  
  419.  
  420.     // RENAME CATEGORY
  421.  
  422.     if ($_POST['action']=='rncat') {
  423.  
  424.           $category = $_POST["category"];
  425.           $newname = $_POST["newname"];
  426.  
  427.           if (!empty($category) && !empty($newname) && sql_getfield($table_categories,'name','WHERE id = '.sql_quote($category)) ) {
  428.               $q = "UPDATE $table_categories SET name = ".sql_quote($newname)." WHERE id = ".sql_quote($category)." LIMIT 1";
  429.               mysql_query($q);
  430.           }
  431.           else {
  432.  
  433.               $error = 'Chyba pri premenovaní !';
  434.  
  435.           }
  436.  
  437.           echo "{";
  438.           echo "error: '" . $error . "'\n";
  439.           echo "}";
  440.  
  441.           exit();
  442.  
  443.     }
  444.  
  445.     // ***
  446.  
  447.  
  448.  
  449.     // NEW EMAIL
  450.  
  451.     if ($_POST['action']=='newemail') {
  452.  
  453.             $category = $_POST["cat"];
  454.             $emails = $_POST["emails"];
  455.             $append ='';
  456.  
  457.             if (!empty($emails)) {
  458.  
  459.               $emails = str_replace('"',"",$emails);
  460.               $emails = str_replace(','," ",$emails);
  461.               $emails = str_replace(';'," ",$emails);
  462.               $emails = str_replace('<'," ",$emails);
  463.               $emails = str_replace('>'," ",$emails);
  464.               $emails = str_replace("\n"," ",$emails);
  465.               $emails = str_replace("\t"," ",$emails);
  466.               $emails = str_replace("\r"," ",$emails);
  467.               $emails = str_replace("\0"," ",$emails);
  468.  
  469.               $email = explode(" ",$emails);
  470.  
  471.               foreach ($email as $value) {
  472.  
  473.                 if (stristr($value,'@') && !sql_getfield($table_emails,'email','WHERE email = '.sql_quote($value).' AND category = '.sql_quote($category))) {
  474.  
  475.                   $q = "INSERT into $table_emails (category,email) VALUES (".sql_quote($category).",".sql_quote($value).")";
  476.                   if (!mysql_query($q)) {
  477.                     $error = 'ERR';
  478.                   }
  479.                   else  {
  480.                     $id = sql_lastinsertid();
  481.                     $append.= '<div><input value="'.$id.'" id="'.$id.'" name="'.$id.'" type="checkbox" /> '.$value.'</div>';
  482.  
  483.                 }
  484.               }
  485.             }
  486.             }
  487.             else {
  488.               $error = 'Zadajte emailové adresy';
  489.             }
  490.  
  491.           echo "{";
  492.           echo              "error: '" . $error . "',\n";
  493.           echo              "toappend: '" . $append . "'\n";
  494.           echo "}";
  495.  
  496.           exit();
  497.  
  498.     }
  499.     // ***
  500.  
  501.  
  502.  
  503.     // NEW CATEGORY
  504.  
  505.     if ($_POST['action']=='newcategory') {
  506.  
  507.           $newcat = $_POST["catname"];
  508.           if (!empty($newcat)) {
  509.  
  510.             $q = "INSERT into $table_categories (name) VALUES (".sql_quote($newcat).")";
  511.             $result = mysql_query($q);
  512.             if (!$result) {
  513.               $error = 'ERR';
  514.             }
  515.             else {
  516.               $name = $newcat;
  517.               $id = sql_lastinsertid();
  518.             }
  519.           } else {
  520.             $error = "Please, enter the name !";
  521.           }
  522.  
  523.           echo "{";
  524.           echo              "error: '" . $error . "',\n";
  525.           echo              "name: '" . $name . "',\n";
  526.           echo              "id: '" . $id . "'\n";
  527.           echo "}";
  528.  
  529.           exit();
  530.  
  531.     }
  532.     // ***
  533.  
  534.  
  535.     // SENDMAIL
  536.  
  537.     if ($_POST['action']=='sendmail') {
  538.  
  539.         if ($use_template == false ) { $template_top = ''; $template_bottom = '';}
  540.  
  541.           $emails = $_POST['adresses'];
  542.           $body = $_POST['ebody'];
  543.           $subject = $_POST['subject'];
  544.           $message = str_replace("\n","<br />",$body);
  545.  
  546.         /* ERRORS */
  547.         if ($message == '') {$error = 'Please, fill the message field !';}
  548.         if ($subject == '') {$error = 'Please, fill the subject field !';}
  549.         if (empty($emails)) {$error = 'No recipient defined ! ';}
  550.  
  551.         if (!empty($emails) && empty($error)) {
  552.  
  553.             /* ZAPIS DO ODOSLANÝCH NEWSLETTROV */
  554.  
  555.                 $q = "INSERT INTO $table_sent (time, subject, body, attachment) VALUES (
  556.                 ".sql_quote(time()).",
  557.                 ".sql_quote($subject).",
  558.                 ".sql_quote($message).",
  559.                 ".sql_quote($_POST["attachment"]).")";
  560.                 mysql_query($q);
  561.  
  562.             $from = "$your_name <$your_email>";
  563.  
  564.             if (!empty($_POST["attachment"])) {
  565.  
  566.                   $suffix  =strtolower(substr($dir.$_POST["attachment"], -3));
  567.                       switch($suffix) {
  568.                         case 'gif': $typ = "image/gif"; break;
  569.                         case 'jpg': $typ = "image/jpg"; break;
  570.                         case 'peg': $typ = "image/jpeg";break;
  571.                         case 'png': $typ = "image/png"; break;
  572.                         case 'pdf': $typ = "application/pdf"; break;
  573.                         case 'zip': $typ = "application/zip"; break;
  574.                       }
  575.  
  576.                   $subject = $_POST['subject'];
  577.  
  578.                   $fileatt = $dir.$_POST["attachment"];
  579.                   $fileatttype = $typ;
  580.                   $fileattname = $_POST["attachment"];
  581.  
  582.                   $headers = "From: $from";
  583.  
  584.                   $file = fopen( $fileatt, 'rb' );
  585.                   $data = fread( $file, filesize( $fileatt ) );
  586.                   fclose( $file );
  587.  
  588.                   $semi_rand = md5( time() );
  589.                   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  590.  
  591.                   $headers .= "\nMIME-Version: 1.0\n" .
  592.                               "Content-Type: multipart/mixed;\n" .
  593.                               " boundary=\"{$mime_boundary}\"";
  594.  
  595.                   $message = "This is a multi-part message in MIME format.\n\n" .
  596.                           "--{$mime_boundary}\n" .
  597.                           "Content-Type: text/html; charset=\"utf-8\"\n" .
  598.                           "Content-Transfer-Encoding: 7bit\n\n" .
  599.                           $template_top.$message.$template_bottom . "\n\n";
  600.  
  601.                   $data = chunk_split( base64_encode( $data ) );
  602.  
  603.                   $message .= "--{$mime_boundary}\n" .
  604.                            "Content-Type: {$fileatttype};\n" .
  605.                            " name=\"{$fileattname}\"\n" .
  606.                            "Content-Disposition: attachment;\n" .
  607.                            " filename=\"{$fileattname}\"\n" .
  608.                            "Content-Transfer-Encoding: base64\n\n" .
  609.                            $data . "\n\n" .
  610.                            "--{$mime_boundary}--\n";
  611.  
  612.           }
  613.           else
  614.           {
  615.  
  616.                   $subject = $subject." \n";
  617.  
  618.                   /* HEADERS */
  619.  
  620.                     $headers = "MIME-Version: 1.0\n";
  621.                     $headers .= "Content-Type: text/html; charset=\"utf-8\"\n";
  622.                     $headers .= "Content-Transfer-Encoding: 7bit \n";
  623.                     $headers .= "From: ".$from." \n";
  624.                     $headers .= "Return-Path: ".$from." \n";
  625.                     $headers .= "X-Mailer: PHP/" . phpversion();
  626.  
  627.                     $message = $template_top.$message.$template_bottom;
  628.  
  629.           }
  630.  
  631.             if ($_POST['sendto']=='emails') {
  632.  
  633.                 $email = explode(',',$emails);
  634.                 $email = array_unique($email);
  635.             }
  636.             else if ($_POST['sendto']=='categories') {
  637.  
  638.                 $query = "SELECT * from $table_emails WHERE category IN (".$emails.")";
  639.                 $select = mysql_query($query);
  640.                 while ($mail_row = mysql_fetch_assoc($select)) {
  641.                     $email[] = $mail_row['id'];
  642.                 }
  643.             }
  644.  
  645.             /* ADMIN CHECK */
  646.             if ($mailcheck == true && !in_array($your_email,$email )) {
  647.                 $email[] = $your_email;
  648.             }
  649.  
  650.             foreach ($email as $value) {
  651.  
  652.                 $emailaddress = sql_getfield($table_emails,'email','WHERE id = '.sql_quote($value));
  653.                 $unsubscribe_link = "<br /><br /><span style=\"font-size:10px;color:#555;\">If you prefer not to receive future promotional e-mails of this type, please click 
  654.                 <a href=\"".$script_url."?unsubscribe=".$emailaddress."\" style=\"color:#ED008C;\">here</a> to unsubscribe.";
  655.                 mail($emailaddress, "=?UTF-8?B?".base64_encode($subject)."?=", $message.$unsubscribe_link, $headers);
  656.                 $count+=1;
  657.  
  658.             }
  659.  
  660.           }
  661.  
  662.               echo "{";
  663.               echo "error: '" . $error . "',\n";
  664.               echo "count: '" . $count . "'\n";
  665.               echo "}";
  666.  
  667.         exit();
  668.  
  669.     }
  670.  
  671.     // ***
  672.  
  673. ?><?php
  674. // <!-- ======================= -->
  675. // <!-- = FILE: MAIN PHP FILE = -->
  676. // <!-- ======================= -->
  677. ?>
  678. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  679.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  680. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  681.     <head>
  682.         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  683.         <meta http-equiv="expires" content="mon, 22 jul 2002 11:12:01 gmt" />
  684.         <title>
  685.             Newsletter module
  686.         </title>
  687.  
  688.         <!-- ================== -->
  689.         <!-- = FILE: CSS FILE = -->
  690.         <!-- ================== -->
  691.  
  692.     <style type="text/css" media="screen">
  693.     /*<![CDATA[*/
  694.  
  695.             /* HERE GOES YOUR CUSTOM CSS */
  696.  
  697.             <?php echo $css; ?>
  698.  
  699.             /* THIS PART OF CSS SHOULD STAY UNTOUCHED TO PRESERVE ORIGINAL LAYOUT 
  700.                BUT - FEEL FREE TO CHANGE IT IF YOU KNOW WHAT YOU'RE DOING          */
  701.  
  702.             body {
  703.                 cursor:default;
  704.             }
  705.  
  706.             h1, h2, h3, h4 {
  707.                 margin:0;
  708.                 padding:0;
  709.             }
  710.             #logo {vertical-align:middle;cursor:pointer;}
  711.             a {
  712.                 cursor:pointer;
  713.             }
  714.             a:hover{
  715.                 text-decoration:underline;
  716.             }
  717.             input[type=password],input[type=text],textarea {
  718.                 padding:3px;
  719.             }
  720.             #categories{
  721.                 padding:10px;
  722.             }
  723.             .tiny {
  724.                 font-size:xx-small;color:#222;
  725.                 text-decoration:none;
  726.                 border:none;
  727.             }
  728.             .sign {
  729.                 font-size:xx-large;
  730.                 vertical-align:absmiddle;
  731.                 text-align:center;
  732.                 font-size:xx-large;
  733.                 display:inline;
  734.                 width:20px;
  735.             }
  736.             #processing {
  737.                 display:none;
  738.                 position:fixed;
  739.                 top:45%;
  740.                 left:45%;
  741.                 padding:10px 20px 10px 20px;
  742.                 margin:0 auto;
  743.                 text-align:center;
  744.             }
  745.             #filename {
  746.                 background:transparent;border:0;
  747.             }
  748.             #about {
  749.                 display:none;
  750.                 border:1px dotted #CCC;
  751.                 -moz-border-radius:10px;
  752.                 background-color:#3D3435;
  753.                 color:#fff;
  754.                 z-index:2;
  755.                 position:fixed;
  756.                 top:20%;
  757.                 left:32%;
  758.                 width:30%;
  759.                 padding:2%;
  760.             }
  761.  
  762.     /*]]>*/
  763.     </style>
  764.     </head>
  765.     <body>
  766.         <!-- = PHP ARRAYS = -->
  767.         <?php
  768.  
  769.                 // LOAD DATA INTO ARRAYS
  770.                 $result = mysql_query("SELECT * from $table_categories");
  771.                 while ($row = mysql_fetch_assoc($result)) {
  772.  
  773.                     $emails_result = mysql_query("SELECT * from $table_emails WHERE category = ".$row['id']);
  774.                     while ($subrow = mysql_fetch_assoc($emails_result)) {
  775.  
  776.                         $row['emails'][] = $subrow;
  777.  
  778.                     }
  779.                     mysql_free_result($emails_result);
  780.                     $categories[] = $row;
  781.                 }
  782.                 mysql_free_result($result);
  783.  
  784.                 $result = mysql_query("SELECT * from $table_sent");
  785.                 while ($row = mysql_fetch_assoc($result)) {
  786.  
  787.                     $sent[] = $row;
  788.                 }
  789.                 mysql_free_result($result);
  790.             ?><!-- LOADING INDICATOR -->
  791.         <div id="processing">
  792.             <img src="images/ajax-loader.gif" alt="loading" style="vertical-align:middle;margin-right:10px;" /> PROCESSING
  793.         </div>
  794.         <div style="clear:both;margin:0 auto;width:1000px;margin-top:60px;">
  795.             <!-- HEADER / SUBHEADER -->
  796.             <img src="images/logo.png" alt="logo" id="logo" onclick="$('.maincontainers').hide(300);$('#newsletter').show(300)" />
  797.             <h1 style="padding-left:20px;color:#444;font-size:15px;">
  798.                 Newsletter module
  799.             </h1><small onclick="top.location.href='http://virae.org/webdesign'">pre 0.9</small><br />
  800.             <br />
  801.             <div style="position:fixed;bottom:5%;right:3%;">
  802.             <a class="button" id="sent_mails_link" onclick="$('.maincontainers').hide(200);$('#sent_mails').show(200);" name="sent_mails_link">SENT E-MAILS</a>
  803.              | <a class="button" id="about_toggle" onclick="$('#about').fadeIn(300);">ABOUT</a>
  804.             <?php if ($password_protection==true): ?>
  805.              | <a class="button" id="logout" onclick="top.location.href='?logout=true'">LOGOUT</a><br />
  806.             <?php endif ?>
  807.             </div>
  808.             <br />
  809.             <div id="newsletter" class="maincontainers" style="clear:both;">
  810.                 <!-- CATEFORIES CONTAINER -->
  811.                 <div id="categories_container" style="width:200px;float:left;margin-right:20px;">
  812.                     <h2>
  813.                         CATEGORIES
  814.                     </h2><br />
  815.                     <br />
  816.                     <div id="categories">
  817.                         <?php 
  818.                                             if (isset($categories) && is_array($categories)) {
  819.                                             foreach ($categories as $key => $value) {
  820.  
  821.                                                 echo '
  822.                                                 <div id="cat_'.$value['id'].'">
  823.                                                     <input type="checkbox" value="'.$value['id'].'" />
  824.                                                     <h3 style="cursor:pointer;" onclick="adr_show(\'category_'.$value['id'].'\');">
  825.                                                         '.$value['name'].'
  826.                                                     </h3>
  827.                                                 </div>';
  828.  
  829.                                             }
  830.                                             }
  831.                                             ?>
  832.                     </div><br />
  833.                     <br />
  834.                     <br />
  835.                     <!-- operations with categories -->
  836.                      <a onclick="$('#newcategory').slideToggle(200)" class="tiny">ADD CATEGORY</a><br />
  837.                     <a onclick="delcat();" class="tiny">DELETE SELECTED</a><br />
  838.                     <a onclick="rncat();" class="tiny">RENAME CATEGORY</a><br />
  839.                     <div id="newcategory" style="text-align:left;display:none;">
  840.                         <br />
  841.                         <small>Create category with name:</small><br />
  842.                         <br />
  843.                         <input type="text" maxlength="40" id="newcategoryname" style="width:135px;border:1px solid #222;" /> <a onclick="newcategory()" class="tiny">OK</a><br />
  844.                     </div>
  845.                 </div><!-- EMAILS CONTAINER -->
  846.                 <div id="emails_container" style="float:left;">
  847.                     <?php 
  848.  
  849.                                         if (isset($categories) && is_array($categories)) {  
  850.                                         foreach ($categories as $key => $value) {
  851.  
  852.                                         echo '
  853.                                         <div id="category_'.$value['id'].'" class="mails">
  854.                                             <h2 class="h2emails">E-MAILS</h2><br />
  855.  
  856.                                             <div id="category_'.$value['id'].'_emails"><br />
  857.  
  858.                                                 <a style="font-size:small;margin-top:15px;" onclick="selectAll(\'category_'.$value['id'].'\',true);" ><small class="tiny">Select all</small></a> |
  859.                                                 <a style="font-size:small;margin-top:15px;" onclick="selectAll(\'category_'.$value['id'].'\',false);" ><small class="tiny">Select none</small></a><br /><br />';
  860.  
  861.                                                 if (isset($value['emails'])) {
  862.  
  863.                                                     foreach ($value['emails'] as $subkey => $subvalue) {
  864.  
  865.                                                         // EMAILS ARE PROTECTED BY ROT13 ENCRYPTION
  866.  
  867.                                                         echo '
  868.                                                             <div><input type="checkbox" name="'.$subvalue['id'].'" value="'.$subvalue['id'].'" />
  869.                                                             <script type="text/javascript">
  870.                                                             <!--
  871.                                                                 document.write("'.str_rot13($subvalue['email']).'".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);})); 
  872.                                                             -->
  873.                                                             </script>
  874.                                                             <br /></div>';
  875.                                                     }
  876.                                                 }
  877.                                                 else {
  878.  
  879.                                                     echo '<span id="no_mails_'.$value['id'].'">No emails</span><br />';
  880.  
  881.                                                 }
  882.  
  883.                                                 echo '
  884.  
  885.                                             </div>
  886.  
  887.                                             <br />___<br /><br />
  888.  
  889.                                         <!-- operations with emails -->
  890.  
  891.                                             <a onclick="$(\'#new_emails_'.$value['id'].'\').slideToggle(200)" class="tiny"><font class="sign g">&bull;</font> ADD E-MAILS</a>&nbsp;&nbsp;
  892.                                             <a onclick="delmail(\''.$value['id'].'\');" class="tiny"><font class="sign r">-</font> DELTE SELECTED</a>&nbsp;&nbsp;
  893.  
  894.                                             <div id="new_emails_'.$value['id'].'" align="left" style="display:none;padding:15px;">
  895.                                                 enter e-mails to add:<br /><br />
  896.                                                 <textarea id="to_add_'.$value['id'].'" cols="30" rows="4" style="font-size:small;border:1px solid #222;"></textarea>&nbsp;&nbsp;
  897.                                                 <a class="tiny" onclick="add_mails(\''.$value['id'].'\')">OK</a><br />
  898.                                             </div>
  899.  
  900.                                         </div>';
  901.                                         }
  902.                                     }                        
  903.                                 ?>
  904.                 </div>
  905.                 <div style="float:right;">
  906.                     <img src="images/send.gif" onclick="$('#newsletter').hide(350);$('#mailform').show(350);serializeSelection();" alt="next" style="cursor:pointer;" />
  907.                 </div>
  908.             </div><!-- NEXT PAGE - E-MAIL FORM -->
  909.             <div id="mailform" class="maincontainers" style="display:none;float:left;">
  910.                 <h2>
  911.                     WRITE YOUR MESSAGE
  912.                 </h2>
  913.                 <div>
  914.                     <div style="float:left;padding:20px;border:1px dotted #ddd;">
  915.                         <br />
  916.                         <h3>
  917.                             SUBJECT
  918.                         </h3><br />
  919.                         <br />
  920.                         <input type="text" id="subject" style="width:400px;" /><br />
  921.                         <br />
  922.                         <h3>
  923.                             MESSAGE
  924.                         </h3><br />
  925.                         <br />
  926.                         <textarea id="emailbody" name="emailbody" cols="40" onfocus="if (this.value=='Write your message here ...') this.value='';" rows="8" style="width:400px;">Write your message here ...</textarea><br />
  927.                         <br />
  928.                         <input type="file" name="fileToUpload" id="fileToUpload" onchange="return ajaxFileUpload();" /> <input type="text" readonly="readonly" id="filename" style="color:#83B440;font-weight:bold;" value="" /><br />
  929.                         <br />
  930.                     </div>
  931.                     <div style="float:right;width:500px;text-align:center;padding-top:120px;">
  932.                         <a class="backlink"><img onclick="sendmail();" src="images/go.png" alt="send!" /></a><br />
  933.                         <br />
  934.                         <span id="info_msg" class="tiny"></span>
  935.                     </div>
  936.                 </div><br style="clear:both" />
  937.                 <br />
  938.                 <a class="backlink" onclick="$('#newsletter').show(350);$('#mailform').hide(350)"><img src="images/back.gif" alt="go back" /></a>
  939.             </div>
  940.             <div id="sent_mails" class="maincontainers" style="display:none;float:left;">
  941.                 <h2>
  942.                     SENT E-MAILS
  943.                 </h2>
  944.                 <div>
  945.                     <div style="float:left;padding:20px;border:0px dotted #ddd;">
  946.                         <?php 
  947.  
  948.                                         if (is_array($sent)) { foreach ($sent as $key => $value) {
  949.                                             echo '<h3>'.$value['subject'].'</h3><br />';
  950.                                             echo '<small>'.$value['body'].'</small><br />';
  951.                                             echo '<small style="color:#ccc;">'.date('d.m.Y',$value['time']).'</small>';
  952.                                             if(isset($value['attachment'])) {
  953.  
  954.                                                 echo '&nbsp;&nbsp;<a style="color:#f30;text-decoration:none;" href="'.$dir.$value['attachment'].'" target="_blank"><small style="color:#f30;text-decoration:none;">'.$value['attachment'].'</small><br /></a>';
  955.  
  956.                                             }
  957.                                             echo '<br /><br />';
  958.                                         }}
  959.  
  960.                                         ?>
  961.                     </div>
  962.                 </div><br style="clear:both" />
  963.                 <br />
  964.                 <a class="backlink" onclick="$('.maincontainers').hide();$('#sent_mails_link').show(50);$('#newsletter').show(350);$('#mailform').hide(350)"><img src="images/back.gif" alt="go back" /></a>
  965.             </div>
  966.         </div><!-- JQUERY -->
  967.         <p>
  968.  
  969.             <script type="text/javascript" src="<?php echo $jquery_src; ?>"></script>  
  970.  
  971.  
  972.     <!-- =========================== -->
  973.     <!-- = FILE: AJAXFILEUPLOAD.JS = -->
  974.     <!-- =========================== -->
  975.  
  976.  
  977.             <script type="text/javascript" charset="utf-8">
  978. <!--
  979. //<![CDATA[
  980.  
  981.         jQuery.extend({
  982.  
  983.             createUploadIframe: function(id, uri)
  984.             {
  985.                     //create frame
  986.                     var frameId = 'jUploadFrame' + id;
  987.  
  988.                     if(window.ActiveXObject) {
  989.                         var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
  990.                         if(typeof uri== 'boolean'){
  991.                             io.src = 'javascript:false';
  992.                         }
  993.                         else if(typeof uri== 'string'){
  994.                             io.src = uri;
  995.                         }
  996.                     }
  997.                     else {
  998.                         var io = document.createElement('iframe');
  999.                         io.id = frameId;
  1000.                         io.name = frameId;
  1001.                     }
  1002.                     io.style.position = 'absolute';
  1003.                     io.style.top = '-1000px';
  1004.                     io.style.left = '-1000px';
  1005.  
  1006.                     document.body.appendChild(io);
  1007.  
  1008.                     return io           
  1009.             },
  1010.             createUploadForm: function(id, fileElementId)
  1011.             {
  1012.                 //create form   
  1013.                 var formId = 'jUploadForm' + id;
  1014.                 var fileId = 'jUploadFile' + id;
  1015.                 var form = $('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"><\/form>'); 
  1016.                 var oldElement = $('#' + fileElementId);
  1017.                 var newElement = $(oldElement).clone();
  1018.                 $(oldElement).attr('id', fileId);
  1019.                 $(oldElement).before(newElement);
  1020.                 $(oldElement).appendTo(form);
  1021.                 //set attributes
  1022.                 $(form).css('position', 'absolute');
  1023.                 $(form).css('top', '-1200px');
  1024.                 $(form).css('left', '-1200px');
  1025.                 $(form).appendTo('body');       
  1026.                 return form;
  1027.             },
  1028.  
  1029.             ajaxFileUpload: function(s) {
  1030.                 // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout        
  1031.                 s = jQuery.extend({}, jQuery.ajaxSettings, s);
  1032.                 var id = new Date().getTime()        
  1033.                 var form = jQuery.createUploadForm(id, s.fileElementId);
  1034.                 var io = jQuery.createUploadIframe(id, s.secureuri);
  1035.                 var frameId = 'jUploadFrame' + id;
  1036.                 var formId = 'jUploadForm' + id;        
  1037.                 // Watch for a new set of requests
  1038.                 if ( s.global && ! jQuery.active++ )
  1039.                 {
  1040.                     jQuery.event.trigger( "ajaxStart" );
  1041.                 }            
  1042.                 var requestDone = false;
  1043.                 // Create the request object
  1044.                 var xml = {}   
  1045.                 if ( s.global )
  1046.                     jQuery.event.trigger("ajaxSend", [xml, s]);
  1047.                 // Wait for a response to come back
  1048.                 var uploadCallback = function(isTimeout)
  1049.                 {           
  1050.                     var io = document.getElementById(frameId);
  1051.                     try 
  1052.                     {               
  1053.                         if(io.contentWindow)
  1054.                         {
  1055.                              xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
  1056.                              xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
  1057.  
  1058.                         }else if(io.contentDocument)
  1059.                         {
  1060.                              xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
  1061.                             xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
  1062.                         }                       
  1063.                     }catch(e)
  1064.                     {
  1065.                         jQuery.handleError(s, xml, null, e);
  1066.                     }
  1067.                     if ( xml || isTimeout == "timeout") 
  1068.                     {               
  1069.                         requestDone = true;
  1070.                         var status;
  1071.                         try {
  1072.                             status = isTimeout != "timeout" ? "success" : "error";
  1073.                             // Make sure that the request was successful or notmodified
  1074.                             if ( status != "error" )
  1075.                             {
  1076.                                 // process the data (runs the xml through httpData regardless of callback)
  1077.                                 var data = jQuery.uploadHttpData( xml, s.dataType );    
  1078.                                 // If a local callback was specified, fire it and pass it the data
  1079.                                 if ( s.success )
  1080.                                     s.success( data, status );
  1081.  
  1082.                                 // Fire the global callback
  1083.                                 if( s.global )
  1084.                                     jQuery.event.trigger( "ajaxSuccess", [xml, s] );
  1085.                             } else
  1086.                                 jQuery.handleError(s, xml, status);
  1087.                         } catch(e) 
  1088.                         {
  1089.                             status = "error";
  1090.                             jQuery.handleError(s, xml, status, e);
  1091.                         }
  1092.  
  1093.                         // The request was completed
  1094.                         if( s.global )
  1095.                             jQuery.event.trigger( "ajaxComplete", [xml, s] );
  1096.  
  1097.                         // Handle the global AJAX counter
  1098.                         if ( s.global && ! -jQuery.active )
  1099.  
  1100.                             jQuery.event.trigger( "ajaxStop" );
  1101.  
  1102.                         // Process result
  1103.                         if ( s.complete )
  1104.                             s.complete(xml, status);
  1105.  
  1106.                         jQuery(io).unbind()
  1107.  
  1108.                         setTimeout(function()
  1109.                                             {   try 
  1110.                                                 {
  1111.                                                     $(io).remove();
  1112.                                                     $(form).remove();   
  1113.  
  1114.                                                 } catch(e) 
  1115.                                                 {
  1116.                                                     jQuery.handleError(s, xml, null, e);
  1117.                                                 }                                   
  1118.  
  1119.                                             }, 100)
  1120.  
  1121.                         xml = null
  1122.  
  1123.                     }
  1124.                 }
  1125.                 // Timeout checker
  1126.                 if ( s.timeout > 0 ) 
  1127.                 {
  1128.                     setTimeout(function(){
  1129.                         // Check to see if the request is still happening
  1130.                         if( !requestDone ) uploadCallback( "timeout" );
  1131.                     }, s.timeout);
  1132.                 }
  1133.                 try 
  1134.                 {
  1135.                    // var io = $('#' + frameId);
  1136.                     var form = $('#' + formId);
  1137.                     $(form).attr('action', s.url);
  1138.                     $(form).attr('method', 'POST');
  1139.                     $(form).attr('target', frameId);
  1140.                     if(form.encoding)
  1141.                     {
  1142.                         form.encoding = 'multipart/form-data';              
  1143.                     }
  1144.                     else
  1145.                     {               
  1146.                         form.enctype = 'multipart/form-data';
  1147.                     }           
  1148.                     $(form).submit();
  1149.  
  1150.                 } catch(e) 
  1151.                 {           
  1152.                     jQuery.handleError(s, xml, null, e);
  1153.                 }
  1154.                 if(window.attachEvent){
  1155.                     document.getElementById(frameId).attachEvent('onload', uploadCallback);
  1156.                 }
  1157.                 else{
  1158.                     document.getElementById(frameId).addEventListener('load', uploadCallback, false);
  1159.                 }       
  1160.                 return {abort: function () {}}; 
  1161.  
  1162.             },
  1163.  
  1164.             uploadHttpData: function( r, type ) {
  1165.                 var data = !type;
  1166.                 data = type == "xml" || data ? r.responseXML : r.responseText;
  1167.                 // If the type is "script", eval it in global context
  1168.                 if ( type == "script" )
  1169.                     jQuery.globalEval( data );
  1170.                 // Get the JavaScript object, if JSON is used.
  1171.                 if ( type == "json" )
  1172.                     eval( "data = " + data );
  1173.                 // evaluate scripts within html
  1174.                 if ( type == "html" )
  1175.                     jQuery("<div>").html(data).evalScripts();
  1176.                     //alert($('param', data).each(function(){alert($(this).attr('value'));}));
  1177.                 return data;
  1178.             }
  1179.         });
  1180.  
  1181.         function ajaxFileUpload()
  1182.         {
  1183.             //starting setting some animation when the ajax starts and completes
  1184.  
  1185.             // IMPORTANT DOM REFERENCE VALUE //
  1186.  
  1187.             $("#processing")
  1188.             .ajaxStart(function(){
  1189.                 $(this).show();
  1190.             })
  1191.             .ajaxComplete(function(){
  1192.                 $(this).hide();
  1193.             });
  1194.  
  1195.             $.ajaxFileUpload
  1196.             (
  1197.                 {
  1198.  
  1199.             // !!!!!!!!!!!!!!!!//
  1200.             // IMPORTANT VALUE //
  1201.             // !!!!!!!!!!!!!!!!//
  1202.  
  1203.                     url:'index.php',
  1204.                     secureuri:false,
  1205.                     fileElementId:'fileToUpload',
  1206.                     dataType: 'json',
  1207.                     success: function (data, status)
  1208.                     {
  1209.                         if(typeof(data.error) != 'undefined')
  1210.                         {
  1211.                             if(data.error != '')
  1212.                             {
  1213.                                 alert(data.error);
  1214.                             }else
  1215.                             {
  1216.                                 var uplfilename = data.file;
  1217.                                 if (uplfilename.indexOf('.php')>(-1) || uplfilename.indexOf('.htm')>(-1)  || uplfilename.indexOf('.js')>(-1)) {
  1218.                                     alert('Filetype not allowed !');
  1219.                                 }
  1220.                                 else {
  1221.                                     $('#filename').val(data.file);
  1222.                                 }
  1223.                             }
  1224.                         }
  1225.                     },
  1226.                     error: function (data, status, e)
  1227.                     {
  1228.                         alert(e);
  1229.                     }
  1230.                 }
  1231.             )
  1232.         return false;
  1233.         }       
  1234. //]]>
  1235. -->
  1236. </script>
  1237.  
  1238.     <!-- ============= -->
  1239.     <!-- = FUNCTIONS = -->
  1240.     <!-- ============= -->
  1241.  
  1242.             <script type="text/javascript">
  1243. <!--
  1244. //<![CDATA[    
  1245.  
  1246.     var emails = new Array() ;
  1247.     var adresses = new Array() ;
  1248.     var sendto = '';
  1249.  
  1250.     // display e-mails of selected category
  1251.     function adr_show(adr_id) {
  1252.         $('.mails').hide();
  1253.         $('#emails_container :checkbox').attr('checked','');
  1254.         $('#'+adr_id).fadeIn(500);
  1255.     }
  1256.  
  1257.     // toggle checkboxes
  1258.     function selectAll(id,state) {
  1259.         $( "#" + id + "_emails :checkbox").attr('checked', state);
  1260.     }
  1261.  
  1262.     // serialize selected emails
  1263.     function serializeSelection() {
  1264.  
  1265.         var categories = new Array() ;
  1266.         $( "#categories_container :checkbox:checked").each(function(){
  1267.             categories.push($(this).val());
  1268.         });
  1269.  
  1270.         if (categories.length < 1) {
  1271.  
  1272.             $( "#emails_container :checkbox:checked").each(function(){
  1273.                     emails.push($(this).val());
  1274.             });
  1275.  
  1276.             if (emails.length > 0) {
  1277.                 $('#info_msg').text('Email will be sent to '+(emails.length)+' selected emails');
  1278.                 adresses = emails.join(",");
  1279.                 sendto = 'emails';
  1280.             }
  1281.             else {
  1282.                 $('#info_msg').text('No recipients are selected !');
  1283.                 sendto = '';
  1284.             }
  1285.  
  1286.         }
  1287.         else {
  1288.             $('#info_msg').text('Email will be sent to '+(categories.length)+' selected categories');
  1289.             sendto = 'categories';
  1290.             adresses = categories.join(",");
  1291.         }
  1292.     }
  1293.  
  1294.     /* //////////////////////////////////////  ADD EMAILS */
  1295.     function add_mails(id) {
  1296.  
  1297.         // load new e-mails as string
  1298.         var newmails = $('#to_add_'+id).val();
  1299.  
  1300.         if (newmails) {
  1301.  
  1302.             $('#processing').fadeIn(500);
  1303.  
  1304.             $.post("index.php", {
  1305.                 action: 'newemail', cat: id, emails: newmails }, function(response){
  1306.                 // alert(response);
  1307.                 var response = eval('(' + response + ')');
  1308.                 // error
  1309.                 if (response.error != '') {alert(response.error);}
  1310.                 // else append new e-mails
  1311.                 else {
  1312.  
  1313.                     $("#category_"+id+"_emails").append(response.toappend);    
  1314.                     $('#new_emails_'+id).slideToggle();
  1315.                     $('#no_mails_'+id).hide();
  1316.                     $('#to_add_'+id).val('');
  1317.  
  1318.                 }
  1319.             });
  1320.  
  1321.             $('#processing').fadeOut(800);
  1322.         }
  1323.         else {
  1324.             alert('Please write e-mails to add.');
  1325.         }
  1326.     }
  1327.     // ***
  1328.  
  1329.     /* ////////////////////////////////////// DELETE EMAILS */
  1330.     function delmail(id) {
  1331.         var emails_to_del = "", count = 0, word;
  1332.  
  1333.         // load checked emails to string separated by | and count them
  1334.         $( "#category_" + id + " :checkbox:checked").each(function() {
  1335.             emails_to_del+=$(this).val()+"|";
  1336.             count+=1;
  1337.         });
  1338.  
  1339.         // CHECK IF ANY MAILS ARE SELECTED AND CONSTRUT THE QUESTION
  1340.         if (count == 0) { alert('No emails are selected'); return false;}
  1341.         if (count == 1) { word = 'selected e-mail ?'; count = ''}
  1342.         if (count > 1) { word = 'selected e-mails ?';}
  1343.  
  1344.         if (confirm('Do your really want to remove '+count+' '+word) ) {
  1345.  
  1346.             // show processing dialog
  1347.             $('#processing').fadeIn(500);
  1348.  
  1349.             $.post("index.php", {
  1350.                 action: 'delmail', cat: id, emails: emails_to_del }, function(response){
  1351.                 var response = eval('(' + response + ')');
  1352.                 // error
  1353.                 if (response.error != '') {alert(response.error);}
  1354.                 // else remove checked e-mails
  1355.                 else {
  1356.                     $( "#category_" + id + "_emails :checkbox:checked").parent().each(function(){
  1357.                         $(this).remove();
  1358.                     })
  1359.                 }
  1360.  
  1361.             $('#processing').fadeOut(500);
  1362.  
  1363.             });
  1364.         }
  1365.     }
  1366.     // ***
  1367.  
  1368.     /* //////////////////////////////////////  CREATE CATEGORY */
  1369.     function newcategory() {
  1370.         if ($("#newcategoryname").val()!='') {
  1371.         $.post("index.php", {
  1372.             action: 'newcategory', catname: $("#newcategoryname").val() }, function(response){
  1373.                 var response = eval('(' + response + ')');
  1374.                 // error
  1375.                 if (response.error != '') {alert(response.error);}
  1376.                 // else reload page
  1377.                 else { window.location.reload(); }
  1378.             });
  1379.         }
  1380.         else {
  1381.             alert ('Please select a name !');
  1382.         }
  1383.         }
  1384.     // ***
  1385.  
  1386.     /* ////////////////////////////////////// RENAME CATEGORIES */
  1387.     function rncat() {
  1388.  
  1389.         var cat_to_rn = "", count = 0;
  1390.  
  1391.         $("#categories :checkbox:checked").each(function() {
  1392.             cat_to_rn+=$(this).val();
  1393.             count+=1;
  1394.         });
  1395.  
  1396.         if (count >= 2 ) {alert('Select one category only !'); return false;}
  1397.         if (count == 0 ) {alert('Select desired category !'); return false;}
  1398.         var newname = prompt('Zadajte nové meno:');
  1399.  
  1400.         if (newname) {
  1401.  
  1402.             $.post("index.php", {
  1403.                 action: 'rncat', category: cat_to_rn, newname: newname }, function(response){
  1404.                     var response = eval('(' + response + ')');
  1405.                     // error
  1406.                     if (response.error != '') {alert(response.error);}
  1407.                     // else reload page
  1408.                     else {history.go(0);}
  1409.             });
  1410.         }
  1411.     }
  1412.     // ***
  1413.  
  1414.     /* ////////////////////////////////////// DELETE CATEGORIES */
  1415.     function delcat() {
  1416.  
  1417.         var catz_to_del = "", count = 0, word;
  1418.  
  1419.         $("#categories :checkbox:checked").each(function() {
  1420.             catz_to_del+=$(this).val()+"|";
  1421.             count+=1;
  1422.         });
  1423.  
  1424.         // construct a question
  1425.         if (count == 0) { alert('Select desired category');return false;}
  1426.         if (count == 1) { word = 'selected category ?'; count = ''}
  1427.         if (count > 1 ) { word = 'selected categories ?';}
  1428.  
  1429.         if (confirm('Do you really want to delete '+word) ) {
  1430.  
  1431.             $.post("index.php", {
  1432.  
  1433.                 action: 'delcat', categories: catz_to_del }, function(response){
  1434.                 var response = eval('(' + response + ')');
  1435.                 // error
  1436.                 if (response.error != '') {alert(response.error);}
  1437.                 // if no errors, remove checked categories
  1438.                 else {
  1439.                     $( "#categories :checkbox:checked").parent().each(function(){$(this).remove();})
  1440.                     history.go(0);
  1441.                 }
  1442.             });
  1443.         }
  1444.     }
  1445.     // ***
  1446.  
  1447.     /* ////////////////////////////////////// DELETE CATEGORIES */
  1448.     function sendmail() {
  1449.       $('#processing').fadeIn(500);
  1450.       $.post("index.php", {
  1451.               action: 'sendmail', sendto: sendto, attachment: $('#filename').val(), subject: $('#subject').val(), ebody: $('#emailbody').val(), adresses: adresses }, function(response){
  1452.  
  1453.                 var response = eval('(' + response + ')');
  1454.                 if (response.error != '') {alert(response.error);}
  1455.                 else {
  1456.                   var previoushtml = $('#processing').html();
  1457.                 }
  1458.               }
  1459.         );
  1460.       setTimeout("$('#processing').fadeOut(1000)",2500);
  1461.     }   
  1462.     // ***
  1463.  
  1464.     // DOC READY
  1465.     $(document).ready(function() {
  1466.         // hide processing div
  1467.             $('#processing').hide();
  1468.         // hide all e-mail divs
  1469.             $('.mails').hide();
  1470.         // show the first div
  1471.             $('#category_<?php echo $categories[0]['id'];?>').show();
  1472.     });
  1473. //]]>
  1474. -->
  1475. </script><!-- CLOSE DB CONNECTION -->
  1476.             <?php mysql_close($server); ?>
  1477.         </p>
  1478.  
  1479. <div id="about" style="display:none;">
  1480.     <h1 style="color:#fff;">About</h1><br />
  1481.     <p>
  1482.         Newsletter module .9<br /><br />
  1483.         Licenced under: <span style="color:#86E029">CC Attribution-Noncommercial-Share Alike 3.0</span><br /><br />
  1484.         PHP, jQuery and AJAX module, which should be great for any newsletter management needs. <br /><br /> Copy this <strong style="color:#4CCFD7">one file!</strong> onto your site, and you're ready to send and archive all newsletters, manage e-mail addresses and categories, and configure a template for your e-mails. Also have an ability of optional password protection. All options can be easily configured at the top of included .php file<br /><br />
  1485.         Feel free to use the <a style="color:#f30" href="http://virae.org/newsletter_module/source/">source</a> for non-comercial purposes. <br /><br />
  1486.         Please, <script type="text/javascript">
  1487.         <!--    
  1488.         document.write(
  1489.         "<n uers=\"znvygb:ivenry\056f\100tznvy\056pbz\" fglyr=\"pbybe:#s30;\">yrg zr xabj<\057n>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
  1490.         -->
  1491.         </script> if you like it !
  1492.         Thanks !
  1493.         <br /><br />
  1494.     </p>
  1495.     <a class="button" onclick="$('#about').fadeOut(500)">Close</a><br />
  1496. </div>    
  1497.  
  1498.  
  1499.     </body>
  1500. </html>

please tell me any corrections

Regards
A. Jaya prakash

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Sep 1 '09

re: Newsletter


Debug your own code and tell us where it's broken if you don't know how to fix it.



Dan
Reply