[ Index ]

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

title

Body

[close]

/include/inc_lib/ -> subscriber.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  //check email 1st
  32  $_POST['subscribe_email']                            = strtolower(clean_slweg($_POST['subscribe_email']));
  33  $_userInfo['error']['email']                         = 1;
  34  
  35  if(is_valid_email($_POST['subscribe_email'])) {
  36  
  37      $_userInfo['subscriber_data']['address_email']    = $_POST['subscribe_email'];
  38      $_userInfo['error']['email']                    = 0;
  39  
  40  } elseif($_POST['subscribe_email']) {
  41  
  42      $_userInfo['subscriber_data']['address_email']    = $_POST['subscribe_email'];
  43  
  44  }
  45  
  46  // user name
  47  $_userInfo['subscriber_data']['address_name']        = clean_slweg($_POST['subscribe_name']);
  48  
  49  // verification
  50  $_userInfo['subscriber_data']['address_verified']    = empty($_POST['subscribe_active']) ? 0 : 1;
  51  
  52  // now run through subscriptions
  53  if(empty($_POST['subscribe_all']) && !empty($_POST['subscribe_to']) && is_array($_POST['subscribe_to']) && count($_POST['subscribe_to'])) {
  54  
  55      // check special subscriptions
  56      $_userInfo['subscriber_data']['address_subscription'] = array();
  57      foreach($_POST['subscribe_to'] as $subscriptions) {
  58      
  59          $subscription = intval($subscriptions);
  60          if($subscription) {
  61              $_userInfo['subscriber_data']['address_subscription'][$subscription] = $subscription;
  62          }
  63      
  64      }
  65      if(count($_userInfo['subscriber_data']['address_subscription'])) {
  66          $_userInfo['subscriber_data']['address_subscription'] = serialize($_userInfo['subscriber_data']['address_subscription']);
  67      } else {
  68          $_userInfo['subscriber_data']['address_subscription'] = '';
  69      }
  70  
  71  } else {
  72  
  73      // means: all subscriptions
  74      $_userInfo['subscriber_data']['address_subscription'] = '';
  75  
  76  }
  77  
  78  // OK lets insert or update
  79  if($_userInfo['error']['email'] == 0) {
  80  
  81      // check if update neccessary in case email still exists
  82      $sql  = "SELECT COUNT(*) FROM ".DB_PREPEND."phpwcms_address ";
  83      $sql .= "WHERE address_email='".aporeplace($_userInfo['subscriber_data']['address_email'])."'";
  84      if($_userInfo['subscriber_data']['address_id']) {
  85          $sql .= " AND address_id != ".$_userInfo['subscriber_data']['address_id'];
  86      }
  87      $_userInfo['count'] = _dbQuery($sql, 'COUNT');
  88      
  89      if($_userInfo['subscriber_data']['address_id'] || $_userInfo['count']) {
  90      
  91          // update
  92          $sql  = 'UPDATE '.DB_PREPEND.'phpwcms_address SET ';
  93          $sql .= "address_email            = '".aporeplace($_userInfo['subscriber_data']['address_email'])."', ";
  94          $sql .= "address_name            = '".aporeplace($_userInfo['subscriber_data']['address_name'])."', ";
  95          $sql .= "address_verified        = ".$_userInfo['subscriber_data']['address_verified'].", ";
  96          $sql .= "address_subscription    = '".aporeplace($_userInfo['subscriber_data']['address_subscription'])."' ";
  97          $sql .= 'WHERE ';
  98          if($_userInfo['count']) {
  99              // update based on email address
 100              $sql .= "address_email='".aporeplace($_userInfo['subscriber_data']['address_email'])."'";
 101          } else {
 102              // update based on email address
 103              $sql .= 'address_id='.$_userInfo['subscriber_data']['address_id'];
 104              $sql .= ' LIMIT 1';
 105          }
 106          
 107          _dbQuery($sql, 'UPDATE');
 108      
 109      } else {
 110      
 111          // insert
 112          $sql  = 'INSERT INTO '.DB_PREPEND.'phpwcms_address ';
 113          $sql .= '(address_key, address_email, address_name, address_verified, address_subscription) VALUES (';
 114          $sql .= "'".aporeplace( shortHash( $_userInfo['subscriber_data']['address_email'] . time() ) )."', ";
 115          $sql .= "'".aporeplace($_userInfo['subscriber_data']['address_email'])."', ";
 116          $sql .= "'".aporeplace($_userInfo['subscriber_data']['address_name'])."', ";
 117          $sql .= $_userInfo['subscriber_data']['address_verified'].", ";
 118          $sql .= "'".aporeplace($_userInfo['subscriber_data']['address_subscription'])."')";
 119          
 120          $_userInfo['result'] = _dbQuery($sql, 'INSERT');
 121          if(!empty($_userInfo['result']['INSERT_ID'])) {
 122              $_userInfo['subscriber_id']                 = $_userInfo['result']['INSERT_ID'];
 123              $_userInfo['subscriber_data']['address_id']    = $_userInfo['result']['INSERT_ID'];
 124          }
 125          
 126      }
 127  
 128  }
 129  
 130  // in case data should be saved and closed then
 131  if($_userInfo['error']['email'] == 0 && (!empty($_POST['save']) || !empty($_userInfo['count']))) {
 132  
 133      $_userInfo['subscriber_data'] = false;
 134  
 135  }
 136  
 137  ?>


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