[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.31 KiB
MD5: a491af0374d3b0684ad8912e5957aa84

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