[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 audience.php

Zen Cart 源代码 audience.php




下载文件

文件名: audience.php
文件类型: PHP文件
文件大小: 6.58 KiB
MD5: b90af8d040145a52ea843a5c7473a005

audience.php - 关闭高亮
  1. <?php
  2. /**
  3.  * functions/audience.php
  4.  * Builds output queries for customer segments
  5.  *
  6.  * @package functions
  7.  * @copyright Copyright 2003-2014 Zen Cart Development Team
  8.  * @copyright Portions Copyright 2003 osCommerce
  9.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  10.  * @version GIT: $Id: Author: DrByte  Thu Apr 17 14:57:10 2014 -0400 Modified in v1.5.3 $
  11.  */
  12.  
  13. //
  14. // @TODO turn into a class in later release...
  15.  
  16.   function get_audiences_list($query_category='email', $display_count='', $lookup_email_address ='') {
  17.   // used to display drop-down list of available audiences in emailing modules:
  18.   // ie: mail, gv_main, coupon_admin... and eventually newsletters too.
  19.   // gets info from query_builder table
  20.  
  21.   include_once(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . 'audience.php');  //$current_page
  22.   global $db;
  23.   $count_array = array();
  24.   $count = 0;
  25.   if ($display_count == '') $display_count = AUDIENCE_SELECT_DISPLAY_COUNTS;
  26.  
  27.   // get list of queries in database table, based on category supplied
  28.   $queries_list = $db->Execute("select query_name, query_string from " . TABLE_QUERY_BUILDER . " " .
  29.                   "where query_category like '%" . $query_category . "%'");
  30.  
  31.   $audience_list = array();
  32.   if ($queries_list->RecordCount() > 1) {  // if more than one query record found
  33.     $audience_list[] = array('id' => '', 'text' => TEXT_SELECT_AN_OPTION); //provide a "not-selected" value
  34.   }
  35.  
  36.   reset($queries_list);
  37.   while (!$queries_list->EOF) {
  38.     // if requested, show recordcounts at end of descriptions of each entry
  39.     // This could slow things down considerably, so use sparingly !!!!
  40.     if ($display_count=='true' || $display_count ==true ) {  // if it's literal 'true' or logical true
  41.     $count_array = $db->Execute(parsed_query_string($queries_list->fields['query_string']) );
  42.     $count = $count_array->RecordCount();
  43.     }
  44.  
  45.     // generate an array consisting of 2 columns which are identical. Key and Text are same.
  46.     // Thus, when the array is used in a Select Box, the key is the same as the displayed description
  47.     // The key can then be used to get the actual select SQL statement using the get...addresses_query function, below.
  48.     $audience_list[] = array('id' => $queries_list->fields['query_name'], 'text' => $queries_list->fields['query_name'] . ' (' . $count . ')');
  49.     $queries_list->MoveNext();
  50.   }
  51.  
  52.   //if this is called by an emailing module which offers individual customers as an option, add all customers email addresses as well.
  53.   if ($query_category=='email') {
  54.     $lookup_filter = ($lookup_email_address != '') ? ' AND customers_email_address= :lookupAddress: ' : '';
  55.     $lookup_filter = $db->bindVars($lookup_filter, ':lookupAddress:', $lookup_email_address, 'string');
  56.     $customers_values = $db->Execute("select customers_email_address, customers_firstname, customers_lastname " .
  57.                   "from " . TABLE_CUSTOMERS . " WHERE customers_email_format != 'NONE' " .
  58.                   $lookup_filter .
  59.                   "order by customers_lastname, customers_firstname, customers_email_address");
  60.     while(!$customers_values->EOF) {
  61.       $audience_list[] = array('id' => $customers_values->fields['customers_email_address'],
  62.                  'text' => $customers_values->fields['customers_lastname'] . ', ' . $customers_values->fields['customers_firstname'] . ' (' . $customers_values->fields['customers_email_address'] . ')');
  63.       $customers_values->MoveNext();
  64.     }
  65.   }
  66.   // send back the array for display in the SELECT drop-down menu
  67.   return $audience_list;
  68.   }
  69.  
  70.   function get_audience_sql_query($selected_entry, $query_category='email') {
  71.     // This is used to take the query_name selected in the drop-down menu or singular customer email address and
  72.   // generate the SQL Select query to be used to build the list of email addresses to be sent to
  73.   // it only returns a query name and query string (SQL SELECT statement)
  74.   // the query string is then used in a $db->Execute() command for later parsing and emailing.
  75.   global $db;
  76.   $query_name='';
  77.   $queries_list = $db->Execute("select query_name, query_string from " . TABLE_QUERY_BUILDER . " " .
  78.                  "where query_category like '%" . $query_category . "%'");
  79. //                 "where query_category = '" . $query_category . "'");
  80.  
  81.   while (!$queries_list->EOF) {
  82.       if ($selected_entry == $queries_list->fields['query_name']) {
  83.       $query_name   = $queries_list->fields['query_name'];
  84.         $query_string = parsed_query_string($queries_list->fields['query_string']);
  85. //echo 'GET_AUD_EM_ADDR_QRY:<br />query_name='.$query_name.'<br />query_string='.$query_string;
  86.       }
  87.     $queries_list->MoveNext();
  88.   }
  89.   //if no match found against queries listed in database, then $selected_entry must be an email address
  90.   if ($query_name=='' && $query_category=='email') {
  91.         $cust_email_address = zen_db_prepare_input($selected_entry);
  92.         $query_name   = $cust_email_address;
  93.         $query_string = "select customers_firstname, customers_lastname, customers_email_address
  94.                              from " . TABLE_CUSTOMERS . "
  95.                              where customers_email_address = '" . zen_db_input($cust_email_address) . "'";
  96.     }
  97.   //send back a 1-row array containing the query_name and the SQL query_string
  98.   return array('query_name'=>$query_name, 'query_string'=>$query_string);
  99. }
  100.  
  101. function parsed_query_string($read_string) {
  102.   // extract table names from sql strings, so that prefixes are supported.
  103.   // this will also in the future be used to reconstruct queries from query_keys_list field in query_builder table.
  104.  
  105.   $allwords = explode( " ", $read_string );
  106.   reset( $allwords );
  107.   while( list( $key, $val ) = each( $allwords ) ) {
  108.     // find "{TABLE_" and extract that tablename
  109.     if( substr( $val, 0, 7) == "{TABLE_"  && substr( $val, -1) == "}" ) { //check for leading and trailing {} braces
  110.       $val = substr( $val, 2, strlen($val)-2);  // strip off braces.  Could also use str_replace(array('{','}'),'',$val);
  111.       //now return the value of the CONSTANT with the name that $val has.  ie: TABLE_CUSTOMERS = zen_customers
  112.       $val = constant($val);
  113.     } elseif ( substr( $val, 0, 6) == "TABLE_" ) {
  114.     //return the value of the CONSTANT with the name that $val has.  ie: TABLE_CUSTOMERS = zen_customers
  115.       $val = constant($val);
  116.     } elseif ( substr( $val, 0, 9) == '$SESSION:' ) {
  117.       //return the value of the SESSION var indicated
  118.       $param = str_replace('$SESSION:', '', $val);
  119.       $val = $_SESSION[$param];
  120.     }
  121.     $good_string .= $val.' ';
  122.    }
  123.    return $good_string;
  124. }
  125.