//print '<pre>'.print_r($args,true).'</pre>'; exit;
// Set pagination tpls
$tpls = array('firstTpl' => '<span class="linklike" onclick="javascript:change_page(1);">&laquo; First</span> &nbsp;', 'lastTpl' => '&nbsp;<span class="linklike" onclick="javascript:change_page([+page_number+]);" >Last &raquo;</span>', 'prevTpl' => '<span class="linklike" onclick="javascript:change_page([+page_number+]);">&lsaquo; Prev.</span>&nbsp;', 'nextTpl' => '&nbsp;<span class="linklike" onclick="javascript:change_page([+page_number+]);">Next &rsaquo;</span>', 'currentPageTpl' => '&nbsp;<span class="post_selector_pagination_active_page">[+page_number+]</span>&nbsp;', 'pageTpl' => '&nbsp;<span class="linklike" title="[+page_number+]" onclick="javascript:change_page([+page_number+]);">[+page_number+]</span>&nbsp;', 'outerTpl' => '<div id="pagination">[+content+] &nbsp; &nbsp;
		Page [+current_page+] of [+page_count+]<br/>
	</div>');
$Q->set_tpls($tpls);
// Get the results
//print '<pre>'.print_r(CCTM::$search_by, true) . '</pre>';
$results = $Q->get_posts($args);
//print '<pre>'.$Q->debug().'</pre>';
$search_form_tpl = CCTM::load_tpl(array('post_selector/search_forms/' . $fieldname . '.tpl', 'post_selector/search_forms/_' . $def['type'] . '.tpl', 'post_selector/search_forms/_default.tpl'));
$Form->set_tpl($search_form_tpl);
$Form->set_name_prefix('');
// blank out the prefixes
$Form->set_id_prefix('');
$d['search_form'] = $Form->generate(CCTM::$search_by, $args);
$item_tpl = '';
$wrapper_tpl = '';
// Multi Field (contains an array of values.
if (isset($def['is_repeatable']) && $def['is_repeatable'] == 1) {
    $item_tpl = CCTM::load_tpl(array('post_selector/items/' . $fieldname . '.tpl', 'post_selector/items/_' . $def['type'] . '_multi.tpl', 'post_selector/items/_relation_multi.tpl'));
    $wrapper_tpl = CCTM::load_tpl(array('post_selector/wrappers/' . $fieldname . '.tpl', 'post_selector/wrappers/_' . $def['type'] . '_multi.tpl', 'post_selector/wrappers/_relation_multi.tpl'));
} else {
    $item_tpl = CCTM::load_tpl(array('post_selector/items/' . $fieldname . '.tpl', 'post_selector/items/_' . $def['type'] . '.tpl', 'post_selector/items/_default.tpl'));
    $wrapper_tpl = CCTM::load_tpl(array('post_selector/wrappers/' . $fieldname . '.tpl', 'post_selector/wrappers/_' . $def['type'] . '.tpl', 'post_selector/wrappers/_default.tpl'));
}
// Placeholders for the wrapper tpl
$hash = array();
$hash['post_title'] = __('Title', CCTM_TXTDOMAIN);
$hash['post_date'] = __('Date', CCTM_TXTDOMAIN);
$hash['post_status'] = __('Status', CCTM_TXTDOMAIN);
// Load up the config...
$possible_configs = array();
$possible_configs[] = '/config/search_parameters/_widget.php';
if (!CCTM::load_file($possible_configs)) {
    print '<p>' . __('Search parameter configuration file not found.', CCTM_TXTDOMAIN) . '</p>';
}
$form_tpl = CCTM::load_tpl('summarize_posts/widget.tpl');
$Form->set_name_prefix('');
$Form->set_id_prefix('');
$Form->set_tpl($form_tpl);
$custom_fields = CCTM::get_custom_field_defs();
$custom_field_options = '';
foreach ($custom_fields as $cf) {
    $custom_field_options .= sprintf('<option value="%s:%s">%s</option>', $cf['name'], $cf['label'], $cf['label']);
}
if (!isset($existing_values['limit']) || $existing_values['limit'] == 0) {
    $existing_values['limit'] = 5;
}
$Form->set_placeholder('custom_fields', $custom_field_options);
$Form->set_placeholder('cctm_url', CCTM_URL);
$Form->set_placeholder('storage_field', $storage_field);
// I18n for the widget
$Form->set_placeholder('widget_desc', __('Dynamically list posts according to the criteria below.', CCTM_TXTDOMAIN));
$Form->set_placeholder('post_title_label', __('Post Title', CCTM_TXTDOMAIN));
$Form->set_placeholder('author_id_label', __('Author ID', CCTM_TXTDOMAIN));
$Form->set_placeholder('add_filter_label', __('Add Filter', CCTM_TXTDOMAIN));
$Form->set_placeholder('save_criteria_label', __('Save Criteria', CCTM_TXTDOMAIN));
$Form->set_placeholder('cancel_label', __('Cancel', CCTM_TXTDOMAIN));
print $Form->generate(CCTM::$search_by, $existing_values);
exit;
/*EOF*/
    function testSearchBy3()
    {
        $Q = new GetPostsForm();
        $Q->set_nonce_field('');
        // override nonce
        $Q->set_css('', false);
        // blank out CSS
        $Q->set_tpl('[+post_type.options+]');
        $actual = $Q->generate(array('post_type'));
        //print $Q->placeholders['post_type.options']; exit;
        //print $actual; exit;
        //print '<pre>'; print_r($Q->placeholders); print '</pre>';exit;
        $expected = '<option value="" >Select post-type</option>
			<option value="attachment" >attachment</option>
			<option value="house" >house</option>
			<option value="movie" >movie</option>
			<option value="page" >page</option>
			<option value="people" >people</option>
			<option value="post" >post</option>
			<option value="room" >room</option>
			<option value="snake" >snake</option>
			<option value="test" >test</option>';
        $this->assertTrue(in_html($expected, $actual));
    }
 /**
  * This is the tie-into the GetPostsForm object: it returns (not prints) a form
  * OR it handles form submissions and returns results.
  * 
  * @param array $args        (optional) defines which controls should be displayed
  * @param string $content_tpl (optional) passed to the get_posts() function, this defines how each result will be formatted.
  * @return string HTML form, or HTML results if the form was property submitted.
  */
 public static function search($args = array(), $content_tpl = null)
 {
     $Form = new GetPostsForm($args);
     $nonce = self::get_from_array($_POST, $Form->nonce_name);
     // Draw the search form
     if (empty($_POST)) {
         return $Form->generate();
     } elseif (wp_verify_nonce($nonce, $Form->nonce_action)) {
         unset($_POST[$Form->nonce_name]);
         unset($_POST['_wp_http_referer']);
         $search_args = array();
         foreach ($_POST as $k => $v) {
             // Strip the prefix
             $new_key = preg_replace('/^' . $Form->name_prefix . '/', '', $k);
             $search_args[$new_key] = $v;
         }
         $results = self::get_posts($search_args);
         if (empty($results)) {
             print $Form->get_no_results_msg();
         } else {
             print $results;
         }
     } else {
         return "Invalid Submission.";
     }
 }
require_once CCTM_PATH . '/includes/GetPostsQuery.php';
require_once CCTM_PATH . '/includes/GetPostsForm.php';
$Form = new GetPostsForm();
// What options should be displayed on the form that defines the search?
// Load up the config...
$possible_configs = array();
$possible_configs[] = '/config/search_parameters/_summarize_posts.php';
if (!CCTM::load_file($possible_configs)) {
    print '<p>' . __('Search parameter configuration file not found.', CCTM_TXTDOMAIN) . '</p>';
}
$form_tpl = CCTM::load_tpl('summarize_posts/search.tpl');
$Form->set_name_prefix('');
$Form->set_id_prefix('');
$Form->set_placeholder('cctm_url', CCTM_URL);
$Form->set_tpl($form_tpl);
$custom_fields = CCTM::get_custom_field_defs();
$custom_field_options = '';
foreach ($custom_fields as $cf) {
    $custom_field_options .= sprintf('<option value="%s:%s">%s</option>', $cf['name'], $cf['label'], $cf['label']);
}
$Form->set_placeholder('custom_fields', $custom_field_options);
// I18n for the search form
$Form->set_placeholder('widget_desc', __('Dynamically list posts according to the criteria below.', CCTM_TXTDOMAIN));
$Form->set_placeholder('post_title_label', __('Post Title', CCTM_TXTDOMAIN));
$Form->set_placeholder('author_id_label', __('Author ID', CCTM_TXTDOMAIN));
$Form->set_placeholder('add_filter_label', __('Add Filter', CCTM_TXTDOMAIN));
$Form->set_placeholder('generate_shortcode_label', __('Generate Shortcode', CCTM_TXTDOMAIN));
$Form->set_placeholder('cancel_label', __('Cancel', CCTM_TXTDOMAIN));
print $Form->generate(CCTM::$search_by);
//print '<pre>hey...</pre>';
/*EOF*/