[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/include/clevermail/admin/ -> subscribers_new.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  require_once  'include/settings.php';
  20  
  21  require_once  'design/top.php';
  22  
  23  // Defines help presented in the right column
  24  define('CM_COLUMN_RIGHT', "
  25  <h2>Import</h2>
  26  <p>You can import subscribers...</p>
  27  ");
  28  ?>
  29  
  30  <div class = "content">
  31      <h1> Add new subscribers</h1>
  32  
  33      <?php
  34      $data = array();
  35  
  36      if (isset($_FILES['cm_file']) && is_uploaded_file($_FILES['cm_file']['tmp_name'])) {
  37          $data = array_merge($data, file($_FILES['cm_file']['tmp_name']));
  38      }
  39  
  40      if (isset($_POST['cm_subs']) && strlen($_POST['cm_subs']) > 0) {
  41          $subString = ereg_replace("(\n|\r)+", "#", $_POST['cm_subs']);
  42          $subArray = explode('#', $subString);
  43          $data = array_merge($data, $subArray);
  44      }
  45  
  46      if (count($data) > 0) {
  47          if (isset($_POST['cm_lists']) && is_array($_POST['cm_lists'])) {
  48              $lists = $_POST['cm_lists'];
  49          }
  50  
  51          echo '<p>Importing new subscribers:</p><p>';
  52          $nbSub = 0;
  53  
  54          foreach ($data as $subscriber) {
  55              if (ereg("^([^@ ]+@[^@ ]+\.[^@.; ]+)(;[^;]*)?(;[^;]*)?$", $subscriber, $regs)) {
  56                  // CSV format: user@example.com;last name (optional);first name (optional)
  57                  list($address, $firstName, $lastName) = explode(';', $subscriber);
  58                  $address = trim($regs[1]);
  59                  $lastName = (strlen($regs[2]) > 1 ? trim(substr($regs[2], 1)) : '');
  60                  $firstName = (strlen($regs[3]) > 1 ? trim(substr($regs[3], 1)) : '');
  61  
  62                  if (get_magic_quotes_gpc()) {
  63                      $lastName = stripslashes($lastName);
  64                      $firstName = stripslashes($firstName);
  65                  }
  66  
  67                  if (!$recId = $db->getOne(
  68                                    "SELECT sub_id FROM " . CM_TABLE_PREFIX . "_subscribers WHERE sub_email='" . $address . "'"))
  69                      {
  70                      // New e-mail address
  71                      $recId = $db->nextId(CM_TABLE_PREFIX . '_subscribers');
  72                      $db->query(
  73                          "INSERT INTO " . CM_TABLE_PREFIX . "_subscribers (sub_id, sub_email, sub_first_name, sub_last_name, sub_profile) VALUES (" . $recId . ", '" . $address . "', '" . addslashes(
  74                                                                                                                                                                                                $firstName). "', '" . addslashes(
  75                                                                                                                                                                                                                          $lastName). "', '" . md5($recId . '#' . $address . '#' . time()). "')");
  76                      $nbSub++;
  77                  }
  78                  if (isset($lists)) {
  79                      reset ($lists);
  80                      foreach ($lists as $listId) {
  81                          if ($db->getOne(
  82                                  "SELECT COUNT(*) FROM " . CM_TABLE_PREFIX . "_lists_subscribers WHERE lst_id = " . $listId . " AND sub_id = " . $recId) == 0)
  83                              {
  84                              // New subscription
  85                              $actionId = md5('subscribe#' . $listId . '#' . $recId . '#' . time());
  86                              $db->query(
  87                                  "INSERT INTO " . CM_TABLE_PREFIX . "_lists_subscribers (lst_id, sub_id, lsr_mode, lsr_id) VALUES (" . $listId . ", " . $recId . ", " . $_POST['cm_mode']. ", '" . $actionId . "')");
  88                          }
  89                      }
  90                  }
  91              }
  92              elseif (trim($subscriber) != '') {
  93                  echo '<span class="error">Error: ' . $subscriber . '</span><br />';
  94              }
  95          }
  96          echo '<span class="noerror">' . ($nbSub > 0 ? $nbSub : 'No'). ' new subscriber' . ($nbSub > 1 ? 's'
  97                                                                                                : ''). ' added</span></p>';
  98      }
  99      ?>
 100  
 101      <table width = "100%" class = "form">
 102          <form enctype = "multipart/form-data" action = "subscribers_new.php" method = "post">
 103              <tr>
 104                  <td class = "label">
 105                      Upload CSV file:</td>
 106  
 107                  <td class = "field">
 108                      <input type = "file" name = "cm_file"/>
 109  
 110                      <br/>
 111  
 112                      <span class = "tips"> CSV format: user@example.com[;last name[;first name]]</span>
 113                  </td>
 114              </tr>
 115  
 116              <tr>
 117                  <td class = "label">
 118                      Type addresses:</td>
 119  
 120                  <td class = "field">
 121                      <textarea name = "cm_subs" cols = "50" rows = "10" wrap = "virtual"></textarea>
 122  
 123                      <br/>
 124  
 125                      <span class = "tips"> Format: user@example.com[;last name[;first name]]</span>
 126                  </td>
 127              </tr>
 128  
 129              <tr>
 130                  <td class = "label">
 131                      Subscribe to lists:</td>
 132  
 133                  <td class = "field">
 134                      <select name = "cm_lists[]" multiple = "multiple">
 135  
 136                          <?php
 137                          $lists = $db->query(
 138                                       "SELECT lst_id, lst_name FROM " . CM_TABLE_PREFIX . "_lists ORDER BY lst_name");
 139  
 140                          while ($list = $lists->fetchRow()) {
 141                              echo '<option value="' . $list['lst_id']. '">' . $list['lst_name']. '</option>';
 142                          }
 143                          ?>
 144  
 145                      </select>
 146                  </td>
 147              </tr>
 148  
 149              <tr>
 150                  <td class = "label">
 151                      Mode:</td>
 152  
 153                  <td class = "field">
 154                      <input type = "radio" name = "cm_mode" value = "1" checked = "checked"/>
 155  
 156                      HTML
 157  
 158                      <br/>
 159  
 160                      <input type = "radio" name = "cm_mode" value = "0"/>
 161  
 162                      Text
 163  
 164                      <br/>
 165                  </td>
 166              </tr>
 167  
 168              <tr>
 169                  <td colspan = "2">
 170                      <input type = "submit" value = "Import"/>
 171                  </td>
 172              </tr>
 173          </form>
 174      </table>
 175  </div>
 176  
 177  <?php
 178  require_once  'design/bottom.php';
 179  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7