[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_lib/ -> subscriberimport.form.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  
  31  $_userInfo['delimeter']                = clean_slweg($_POST['delimeter']);
  32  if(empty($_userInfo['delimeter']))     $_userInfo['delimeter'] = ';';
  33  
  34  $_userInfo['subscribe_active']        = empty($_POST['subscribe_active']) ? 0 : 1;
  35  $_userInfo['subscribe_all']            = empty($_POST['subscribe_all']) ? 0 : 1;
  36  
  37  if(isset($_POST['subscribe_select']) && is_array($_POST['subscribe_select'])) {
  38      $_userInfo['subscribe_select']    = $_POST['subscribe_select'];
  39  } else {
  40      $_userInfo['subscribe_select']    = array();
  41      $_userInfo['subscribe_all']        = 1;
  42  }
  43  
  44  // check uploaded FILE
  45  if(getimagesize($_FILES['cvsfile']['tmp_name'])) {
  46  
  47      $_userInfo['csvError'] = 'False MIME TYPE. Be sure to upload CSV file only.';
  48  
  49  } elseif(is_uploaded_file($_FILES['cvsfile']['tmp_name']) && !$_FILES['cvsfile']['error']) {
  50  
  51      $_userInfo['csvFileTyper'] = strtolower(trim($_FILES['cvsfile']['type']));
  52  
  53      switch($_userInfo['csvFileTyper']) {
  54      
  55          case 'application/vnd-ms-excel':
  56          case 'application/vnd.ms-excel':
  57          case 'text/plain':
  58          case 'text/csv':
  59          case 'text/x-csv':
  60          case 'application/x-csv':
  61          case 'application/csv':
  62          case 'text/comma-separated-values':
  63          case 'application/octet-stream':
  64  
  65                      $_userInfo['csv']                 = csvFileToArray($_FILES['cvsfile']['tmp_name'], $_userInfo['delimeter']);
  66                      
  67                      if(is_array($_userInfo['csv'])) {
  68                      
  69                          $_userInfo['nonImported']    = array();
  70                          $c = 1;
  71                          $_userInfo['csvTime']        = time();
  72                      
  73                          foreach($_userInfo['csv'] as $row) {
  74                              
  75                              if(!isset($row[1])) $row[1] = '';
  76                              
  77                              if(!empty($row[0]) && is_valid_email($row[0])) {
  78                              
  79                                  $sql  = "INSERT INTO ".DB_PREPEND."phpwcms_address (";
  80                                  $sql .= "address_email, address_name, address_key, address_subscription, address_verified, address_tstamp) VALUES (";
  81                                  $sql .= "'".aporeplace($row[0])."', ";
  82                                  $sql .= "'".aporeplace($row[1])."', ";
  83                                  $sql .= "'".aporeplace(shortHash($row[0].time()))."', ";
  84                                  $sql .= "'".($_userInfo['subscribe_all'] ? '' : aporeplace(serialize($_userInfo['subscribe_select'])))."', ";
  85                                  $sql .= $_userInfo['subscribe_active'].", FROM_UNIXTIME(".$_userInfo['csvTime'].") )";
  86                                  
  87                                  $sql  = _dbQuery($sql, 'INSERT');
  88                                  if(empty($sql['INSERT_ID'])) {
  89                                      $_userInfo['nonImported'][$c] = $row[0].'; '.$row[1].' ('.mysql_error().')';
  90                                  }
  91                              
  92                              } else {
  93                                  
  94                                  $_userInfo['nonImported'][$c] = $row[0].'; '.$row[1];
  95                              
  96                              }
  97                      
  98                              $c++;
  99                          }
 100                      
 101                      }
 102                      
 103                      break;
 104                      
 105          default:     $_userInfo['csvError'] = 'False MIME TYPE. Be sure to upload CSV file only.';
 106                      @unlink($_FILES['cvsfile']['tmp_name']);
 107      }
 108  
 109  } elseif($_FILES['cvsfile']['error']) {
 110  
 111      $_userInfo['csvError'] = return_upload_errormsg($_FILES['cvsfile']['error']);
 112  
 113  }
 114  
 115  
 116  
 117  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7