Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. <?php
  2.  
  3. #ini_set('error_reporting', E_ALL & ~E_NOTICE);
  4. #ini_set('display_errors', 1);
  5.  
  6. if (isset($_POST['del'])) {
  7. include('includes/functions.php');
  8. include('includes/login/auth.php');
  9.  
  10. $emails_del_all = array();
  11. switch ($_POST['del']) {
  12. case 'csv':
  13. $csvfile = $_FILES['csv_file']['tmp_name'];
  14. if (!file_exists($csvfile)) {
  15. header('Location: delete-from-all-lists?e=3');
  16. exit;
  17. }
  18. ini_set('auto_detect_line_endings', true);
  19. $file = fopen($csvfile,"r");
  20. if(!$file) {
  21. echo _('Error opening data file.'), "\n";
  22. exit;
  23. }
  24. while ($row = fgetcsv($file)) {
  25. $row = array_filter($row, 'strlen');
  26. switch (count($row)) {
  27. case 1:
  28. $emails_del_all[] = reset($row);
  29. case 0:
  30. continue 2;
  31. default:
  32. header('Location: delete-from-all-lists?e=1');
  33. exit;
  34. }
  35. }
  36. break;
  37. case 'input':
  38. $emails_del_all = preg_split('/\\s*?[\\r\\n]++\\s*/', $_POST['line'], null, PREG_SPLIT_NO_EMPTY);
  39. break;
  40. }
  41. if (!$emails_del_all) {
  42. echo _('Nothing provided to delete.'), "\n";
  43. exit;
  44. }
  45. $emails_del_count_last = 0;
  46. while ($emails_del_all) {
  47. $emails_del = array_splice($emails_del_all, 0, 20);# delete in batches of 20 at most
  48. $emails_del_count = count($emails_del);
  49. if ($emails_del_count != $emails_del_count_last) {
  50. $mysqli_stmt = $mysqli->prepare(
  51. 'DELETE FROM subscribers
  52. WHERE email IN (' . implode(', ', array_fill(0, $emails_del_count, '?')) . ')'
  53. );
  54. $bind_param_types = str_repeat('s', $emails_del_count);
  55. $emails_del_count_last = $emails_del_count;
  56. }
  57.  
  58. $bind_param_args = array(
  59. $bind_param_types,
  60. );
  61. foreach ($emails_del as $i => $email_del) {
  62. $bind_param_args[] = &$emails_del[$i];
  63. }
  64. call_user_func_array(array(&$mysqli_stmt, 'bind_param'), $bind_param_args);
  65. if (!$mysqli_stmt->execute()) {
  66. echo $mysqli_stmt->error, "\n";
  67. exit;
  68. }
  69. }
  70. header('Location: delete-from-all-lists', true, 303);
  71. exit;
  72. }
  73.  
  74. include('includes/header.php');
  75. include('includes/login/auth.php');
  76. include('includes/subscribers/main.php');
  77.  
  78. if(isset($_GET['e'])) $err = $_GET['e'];
  79. else $err = '';
  80. ?>
  81.  
  82. <!-- Validation -->
  83. <script type="text/javascript" src="js/validate.js"></script>
  84. <script type="text/javascript">
  85. $(document).ready(function() {
  86. $("#import-delete-form").validate({
  87. rules: {
  88. csv_file: {
  89. required: true
  90. }
  91. },
  92. messages: {
  93. csv_file: "<?php echo addslashes(_('Please upload a CSV file'));?>"
  94. }
  95. });
  96. $("#line-import-form").validate({
  97. rules: {
  98. line: {
  99. required: true
  100. }
  101. },
  102. messages: {
  103. line: "<?php echo addslashes(_('Please enter at least one combination of name & email'));?>"
  104. }
  105. });
  106. });
  107. </script>
  108.  
  109. <h2><?php echo _('Mass delete via CSV file');?></h2><br/>
  110. <form action="" method="POST" accept-charset="utf-8" class="form-vertical" enctype="multipart/form-data" id="import-delete-form">
  111. <input type="hidden" name="del" value="csv">
  112.  
  113. <?php if($_GET['e']==1):?>
  114. <div class="alert alert-error">
  115. <button type="button" class="close" data-dismiss="alert">×</button>
  116. <strong><?php echo _('There should only be 1 column in your CSV containing emails.');?></strong>
  117. </div>
  118. <?php elseif($_GET['e']==3):?>
  119. <div class="alert alert-error">
  120. <button type="button" class="close" data-dismiss="alert">×</button>
  121. <strong><?php echo _('Please upload a CSV file.');?></strong>
  122. </div>
  123. <?php endif;?>
  124.  
  125. <label class="control-label" for="csv_file"><em><?php echo _('CSV format example');?>:</em></label>
  126. <table class="table table-bordered table-striped table-condensed" style="width: 300px;">
  127. <tbody>
  128. <tr>
  129. <td>pmorris@gmail.com</td>
  130. </tr>
  131. <tr>
  132. <td>jwebster@gmail.com</td>
  133. </tr>
  134. </tbody>
  135. </table>
  136. <div class="control-group">
  137. <div class="controls">
  138. <input type="file" class="input-xlarge" id="csv_file" name="csv_file">
  139. </div>
  140. </div>
  141.  
  142. <br/>
  143. <button type="submit" class="btn btn-inverse"><?php echo _('Import');?></button>
  144. </form>
  145.  
  146. <br/>
  147.  
  148. <h2><?php echo _('Delete email per line');?></h2><br/>
  149. <form action="" method="POST" accept-charset="utf-8" class="form-vertical" enctype="multipart/form-data" id="line-import-form">
  150. <input type="hidden" name="del" value="input">
  151.  
  152. <?php if($_GET['e']==2):?>
  153. <div class="alert alert-error">
  154. <button type="button" class="close" data-dismiss="alert">×</button>
  155. <strong><?php echo _('Sorry, we didn\'t receive any input.');?></strong>
  156. </div>
  157. <?php endif;?>
  158.  
  159. <label class="control-label" for="line"><?php echo _('Email to delete');?></label>
  160. <div class="control-group">
  161. <div class="controls">
  162. <textarea class="input-xlarge" id="line" name="line" rows="10" placeholder="Eg. hermanmiller@gmail.com"></textarea>
  163. </div>
  164. </div>
  165.  
  166. <br/>
  167. <button type="submit" class="btn btn-inverse"><?php echo _('Delete');?></button>
  168. </form>
  169. <?php include('includes/footer.php');?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement