You are here

function regcode_admin_list_getwhere in Registration codes 6

Create an SQL WHERE string

2 calls to regcode_admin_list_getwhere()
regcode_admin_list_action_delete in ./regcode.admin.php
Mass delete rules
regcode_admin_list_getresource in ./regcode.admin.php
Grab the result resource based on the form state

File

./regcode.admin.php, line 543
Functions and pages needed for the administration interface for the regcode module.

Code

function regcode_admin_list_getwhere() {

  // Grab a list of current filters
  $resource = db_query("SELECT name,value FROM {variable} WHERE name LIKE 'regcode_filter_%'");

  // Build array of applicable conditions
  $conditions = array();
  while ($row = db_fetch_array($resource)) {
    $value = unserialize($row['value']);
    $filter = substr($row['name'], 15);

    // A value which is __all__ can be ignored
    if ($value === '__all__') {
      continue;
    }
    $conditions[$filter] = $value;
  }

  // Build the condition query string
  $cond = array();
  foreach ($conditions as $filter => $value) {
    $value = preg_replace('/[^a-zA-Z0-9\\s]+/', '', $value);
    $cond[] = sprintf("%s = '%s'", $filter, $value);
  }

  // Return the string
  $string = ' WHERE ';
  if (!empty($cond)) {
    $string .= implode($cond, ' AND ');
  }
  else {
    $string .= 'TRUE';
  }
  return $string;
}