substr($OC_fieldAR[$f]['short'], 0, 30), 'type' => $OC_fieldAR[$f]['type'], 'fieldset' => $fsAR['fieldset'] ); if ($OC_fieldAR[$f]['type'] == 'date') { $dateFieldsAR[] = $f; } if (isset($OC_fieldAR[$f]['values']) && is_array($OC_fieldAR[$f]['values']) && (count($OC_fieldAR[$f]['values']) > 0)) { if (!isset($OC_fieldAR[$f]['usekey']) || $OC_fieldAR[$f]['usekey']) { $fieldsAR[$f]['values'] = $OC_fieldAR[$f]['values']; } else { $fieldsAR[$f]['values'] = array(); foreach ($OC_fieldAR[$f]['values'] as $v) { $fieldsAR[$f]['values'][$v] = $v; } } } } } } } function queryFieldWrapper($table, $field, $fieldType, $fieldValue, $operator, $tableFieldOverride=null) { if ($tableFieldOverride !== null) { $tableField = $tableFieldOverride; } else { $tableField = "`" . $table . "`.`" . safeSQLstr($field) . "`"; } $qf = ''; if (($fieldType == 'checkbox') || ($fieldType == 'picklist')) { $qf = "FIND_IN_SET('" . safeSQLstr($fieldValue) . "', " . $tableField . ") "; } else { if ($operator == 'contains') { $qf = $tableField . " LIKE '%" . safeSQLstr(preg_replace(array('/_/', '/%/'), array('\\_', '\\%'), oc_strtolower($fieldValue))) . "%'" ; } elseif ($operator == 'before') { $qf = "( (" . $tableField . "<'" . safeSQLstr(oc_strtolower($fieldValue)) . "') OR (" . $tableField . " IS NULL) )"; } elseif ($operator == 'after') { $qf = $tableField . ">'" . safeSQLstr(oc_strtolower($fieldValue)) . "'"; } elseif ($operator == 'onbefore') { $qf = "( (" . $tableField . "<='" . safeSQLstr(oc_strtolower($fieldValue)) . "') OR (" . $tableField . " IS NULL) )"; } elseif ($operator == 'onafter') { $qf = $tableField . ">='" . safeSQLstr(oc_strtolower($fieldValue)) . "'"; } else { $qf = $tableField . "='" . safeSQLstr(oc_strtolower($fieldValue)) . "'"; } } return($qf); } function displayResultsHeader() { header('Content-type: text/html; charset=utf-8'); print ' Search ' . ( ( defined('OCC_LANGUAGE_LTR') && ( ! OCC_LANGUAGE_LTR ) ) ? '' : '' ) . ' '; } function displayResultsFooter() { print ' '; } function validateSearchFields($i, &$fieldsAR, &$intFieldsAR, &$dateFieldsAR, $decFieldsAR=array()) { if ( // field selected exists and is valid isset($_POST['searchfield'.$i]) && isset($fieldsAR[$_POST['searchfield'.$i]]) && // field operator exists and is valid isset($_POST['searchoperator'.$i]) && preg_match("/^(?:is|contains|before|after)$/", $_POST['searchoperator'.$i]) && // field value entered/selected isset($_POST['searchvalue'.$i]) && !empty($_POST['searchvalue'.$i]) && // field value exists if selection ( !isset($fieldsAR[$_POST['searchvalue'.$i]]['values']) || isset($fieldsAR[$_POST['searchvalue'.$i]]['values'][$_POST['searchvalue'.$i]]) ) && // int field format valid ( !in_array($_POST['searchfield'.$i], $intFieldsAR) || preg_match("/^\d+$/", $_POST['searchvalue'.$i]) ) && // decimal field format valid ( !in_array($_POST['searchfield'.$i], $decFieldsAR) || preg_match("/^\d+(\.\d{1,2})?$/", $_POST['searchvalue'.$i]) ) && // date field format valid ( !in_array($_POST['searchfield'.$i], $dateFieldsAR) || preg_match("/^\d{4}-\d\d-\d\d$/", $_POST['searchvalue'.$i]) ) ) { return(true); } else { return(false); } } function displayEmailForm(&$emailAddresses, $recipient, $submitText) { print '
'; foreach ($emailAddresses as $eAddress) { print ''; } print '

'; } function displaySearchForm(&$fieldsAR, &$dateFieldsAR, &$intFieldsAR, &$decFieldsAR, &$searchFieldNum) { print '

Select one or more fields to search on and enter your query, then click the Search button. The search will find submissions matching all non-empty queries. When selecting fields with pre-defined values, the text query box will be replaced with a drop-down list of the values.

'; for ($i=1; $i <= $searchFieldNum; $i++) { print '
'; } print '

'; }