Ejemplo n.º 1
0
 function show_filters($show_type = '')
 {
     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     #
     #	show the table filters box
     #	@since 0.0.6
     #
     global $isFilteredData, $filters, $_TBL_DEFS, $_T_TBL_DEFS, $_FLD_DEFS, $_T_FLD_DEFS, $_FIELDS, $_T_FIELDS, $_RESERVED_FIELDS;
     if ($show_type == 'setup') {
         $toggler_label = __('Filters setup', MED_LOCALE);
         $toggler_handle = '_filter_setup';
     } else {
         $toggler_label = __('Filter data', MED_LOCALE);
         $toggler_handle = '_filter_data';
     }
     //var_dump($_TBL_DEFS);echo '<hr>';
     //var_dump($_FLD_DEFS);echo '<hr>';
     //var_dump($_FIELDS);echo '<hr>';
     //unset($_SESSION[EDIT_TABLE_NAME.'_filters']);#debug
     //$html = "<div class='wp-submenu'>".
     //		"<div class='wp-submenu-head'>myEASYdb</div>".
     //		'<ul id="adminmenu">'
     //			.'<li class="wp-first-item"><a href=\'admin.php?page=med_admin\' class="wp-first-item" tabindex="1">myEASYdb</a></li>'
     //			.'<li><a href=\'admin.php?page=citta\' tabindex="1">Citt&agrave;</a></li>'
     //			.'<li class="current"><a href=\'admin.php?page=corsi_calendario\' class="current" tabindex="1">Calendario dei corsi</a></li>'
     //			.'<li><a href=\'admin.php?page=corsi_cat\' tabindex="1">Categorie dei corsi</a></li>'
     //			.'<li><a href=\'admin.php?page=corsi_desc\' tabindex="1">Descrizioni dei corsi</a></li>'
     //		.'</ul>'
     //		.'</div>';
     //return $html;
     $not_filtered_fields = get_not_filtered_fields();
     //var_dump($not_filtered_fields);echo '<hr>';
     //var_dump($_FLD_DEFS);
     //var_dump($_FIELDS[0]);
     $html = '';
     $total_filters_on_screen = 0;
     $_filters = array();
     for ($i = 0; $i < $_T_FLD_DEFS; $i++) {
         #	search for fields defined as filters
         #
         if ($_FLD_DEFS[$i]['isFILTER'] == true) {
             #	this field must be used to filter results
             #
             $total_filters_on_screen++;
             $ii = 0;
             $label = '';
             while ($ii < $_T_FIELDS && $label == '') {
                 #	let's get the field label
                 #
                 if ($_FIELDS[$ii]['Field'] == $_FLD_DEFS[$i]['field']) {
                     if (strlen($_FIELDS[$ii]['Comment']) > 0) {
                         $label = $_FIELDS[$ii]['Comment'];
                     } else {
                         $label = $_FIELDS[$ii]['Field'];
                     }
                     $field = $_FIELDS[$ii]['Field'];
                     $type = $_FIELDS[$ii]['Type'];
                 }
                 $ii++;
             }
             //echo 'type['.$type.']<br>';
             //$filterSuffix = '';
             //if($type=='date')
             //{
             //	$filterSuffix = '_dt';
             //}
             #
             #	if the input field value is empty, fill it with saved data
             #
             if (!isset($_POST['filter_' . $_FLD_DEFS[$i]['field']])) {
                 $_POST['filter_' . $_FLD_DEFS[$i]['field']] = $_SESSION[EDIT_TABLE_NAME . '_filters']['filter_' . $_FLD_DEFS[$i]['field']];
             }
             #
             #	if the filter relation is empty, fill it with saved data
             #
             if (!isset($_POST['_rel_filter_' . $_FLD_DEFS[$i]['field'] . '_'])) {
                 $_POST['_rel_filter_' . $_FLD_DEFS[$i]['field'] . '_'] = $_SESSION[EDIT_TABLE_NAME . '_rel_filters']['_rel_filter_' . $_FLD_DEFS[$i]['field']];
             }
             #
             #	prepare the input field
             #
             $iii = 0;
             $isREFERENCED = false;
             while ($iii < $_T_TBL_DEFS && $isREFERENCED == false) {
                 #	if the field is a referenced in another table, prepare a list of options
                 #
                 if ($_TBL_DEFS[$iii]['referenceField'] == $_FLD_DEFS[$i]['field']) {
                     $isREFERENCED = true;
                     $input = get_referenced_options($_POST['filter_' . $_FLD_DEFS[$i]['field']], $_TBL_DEFS[$iii]['referencedTable'], $_TBL_DEFS[$iii]['referencedID'], $_TBL_DEFS[$iii]['referencedDesc'], 'filter_' . $_FLD_DEFS[$i]['field']);
                 }
                 $iii++;
             }
             if ($isREFERENCED == false) {
                 #	the field is a simple input, format it as needed
                 #
                 if ($type == 'date' || $type == 'datetime') {
                     $input = '<table>' . '<tr>' . '<td nowrap>' . __('From', MED_LOCALE) . ' &raquo;' . '</td>' . '<td>' . show_calendar('table_editor_adm', 'filter_from_' . $_FLD_DEFS[$i]['field'], false, true, 'filter_to_' . $_FLD_DEFS[$i]['field']) . '</td>' . '</tr>' . '<tr>' . '<td nowrap>' . __('To', MED_LOCALE) . ' &raquo;' . '</td>' . '<td>' . show_calendar('table_editor_adm', 'filter_to_' . $_FLD_DEFS[$i]['field'], false, false) . '</td>' . '</tr>' . '</table>';
                 } else {
                     $field_len_info = table_editor_get_field_len_info($type);
                     if ($field_len_info['len'] == 0 && $field_len_info['isTEXT'] == true) {
                         $input = '<textarea class="form" name="filter_' . $_FLD_DEFS[$i]['field'] . '" rows="' . 4 . '" cols="' . 20 . '" style="/*width:100%;*/">' . $_POST['filter_' . $_FLD_DEFS[$i]['field']] . '</textarea>';
                     } else {
                         $input = '<input class="form" type="text" name="filter_' . $_FLD_DEFS[$i]['field'] . '" value="' . $_POST['filter_' . $_FLD_DEFS[$i]['field']] . '" size="20" maxlength="255" />';
                     }
                 }
             }
             $input = '<td width="90%">' . $input . '</td>';
             $selected_and = '';
             $selected_or = '';
             switch ($_POST['_rel_filter_' . $field . '_']) {
                 case 'OR':
                     $selected_or = ' selected="selected"';
                     break;
                 case 'AND':
                 default:
                     $selected_and = ' selected="selected"';
             }
             $filter_relation = '' . '<td width="1%">' . '<select id="_rel_filter_' . $field . '" name="_rel_filter_' . $field . '_">' . '<option value="AND"' . $selected_and . '>' . 'AND' . '</option>' . '<option value="OR"' . $selected_or . '>' . 'OR' . '</option>' . '</select>' . '</td>';
             if ($i == $_T_FLD_DEFS - 1) {
                 $filter_relation = '';
             }
             $setup_only = '';
             if ($show_type == 'setup') {
                 $input = '';
                 $filter_relation = '';
                 $setup_only = '<td width="1%">' . '<div style="display:none;border:0px dotted green;">' . '<input id="__field_' . $i . '" name="__field_' . $i . '_" type="hidden" value="' . $field . '" />' . '</div>' . '<div>' . '<input tabindex="-1" type="button" class="button-secondary" style="margin:4px 0px 0 0;" name="btn" value="&nbsp;' . __('Remove this filter', MED_LOCALE) . '&nbsp;" onclick="javascript:' . 'if(confirm(\'' . __('Are you sure that you want to remove this filter?', MED_LOCALE) . '\')==false) {' . 'return false;' . '};' . 'var t=document.getElementById(\'__total_filters_on_screen_\');' . 't.value=t.value-1;' . 'sndReq(\'delete_filter\',\'update_filters_info\',\'' . $i . AJAX_PARMS_SPLITTER . EDIT_TABLE_NAME . '\');' . '" />' . '</div>' . '</td>';
             }
             $html .= '' . '<tr>' . '<td width="1%" valign="top" nowrap>' . $label . '</td>' . $input . $filter_relation . $setup_only . '</tr>';
             $_SESSION[EDIT_TABLE_NAME . '_filters']['filter_' . $_FLD_DEFS[$i]['field']] = $_POST['filter_' . $_FLD_DEFS[$i]['field']];
             $_SESSION[EDIT_TABLE_NAME . '_rel_filters']['_rel_filter_' . $_FLD_DEFS[$i]['field']] = $_POST['_rel_filter_' . $_FLD_DEFS[$i]['field'] . '_'];
             //var_dump($_POST);echo '<hr>';
         }
     }
     //var_dump($_SESSION[EDIT_TABLE_NAME.'_filters']);
     //	if(strlen($lang)==0)	{ $lang = $_SESSION['table_editor']['lang']; }
     //	if(strlen($lang)==0)	{ $lang = $_SESSION['sitelanguage']; }
     $html_not_filter = '';
     $buttons = '';
     if ($show_type == 'setup') {
         $html_not_filter = '' . '<div id="not_ref_fields_container" style="float:right;">' . '<select id="not_ref_fields" name="not_filtered_fields">' . '<option value="">' . __('Select a new field to use as a filter and click on this button &raquo;', MED_LOCALE) . '</option>';
         foreach ($not_filtered_fields as $field) {
             $html_not_filter .= '<option value="' . $field . '">' . $field . '</option>';
         }
         $html_not_filter .= '</select>' . '</div>';
         $buttons = '' . '<input type="button" class="button-secondary" style="margin-left:8px;" name="btn" value="&nbsp;' . __('Add filter', MED_LOCALE) . '&nbsp;" onclick="javascript:' . 'if(document.getElementById(\'not_ref_fields\').value==\'\'){' . 'alert(\'' . __('Please select the new field you want to set as a filter!', MED_LOCALE) . '\');' . 'return false;' . '}' . 'sndReq(\'filter_add\',\'_filters_add\',\'\'+document.getElementById(\'not_ref_fields\').value+\'' . AJAX_PARMS_SPLITTER . '\'+document.getElementById(\'__total_filters_on_screen_\').value+\'' . AJAX_PARMS_SPLITTER . EDIT_TABLE_NAME . '\');' . '" />' . '<input type="button" class="button-primary" style="margin-left:8px;" name="btn" value="&nbsp;' . __('Apply', MED_LOCALE) . '&nbsp;" onclick="javascript:' . 'sndReq(\'update_filters\',\'update_filters_info\',\'\'+document.getElementById(\'__total_filters_on_screen_\').value+\'' . AJAX_PARMS_SPLITTER . EDIT_TABLE_NAME . '\');' . '" />';
     }
     if (strlen($html) == 0) {
         $html = '<tr><td>' . '<h3><i>' . __('No filters are set for this table yet', MED_LOCALE) . '</i></h3>' . '</td></tr>';
         $info_wildcards = '';
     } else {
         if ($show_type != 'setup') {
             $buttons = '' . '&nbsp;&nbsp;&nbsp;' . '<input type="submit" class="button-primary" id="button-primary-green" name="btn" value="' . FILTER . '" />';
             $info_wildcards = 'Use an * as a wildcard on strings (example: "Tom*" will find "Tommy" and "Tomato")';
         }
     }
     $html = '' . '<div id="' . $toggler_handle . '" class="top_tab_contents">' . '<table cellspacing="6" cellpadding="0" border="0" width="98%" align="right">' . '<tr><td colspan="99" align="right"><i>' . $info_wildcards . '</i></td></tr>' . $html;
     if ($show_type == 'setup') {
         $html .= '' . '<tr>' . '<td id="_filters_add" colspan="99" align="right" style="padding:0;margin:0;background:transparent;">' . '</td>' . '</tr>' . '<tr>' . '<td id="_filters_addChildren" colspan="99" align="right" class="updated" style="border-color:#21759b;background:#298cba;">' . '</td>' . '</tr>';
     }
     $html .= '' . '<tr>' . '<td colspan="99" width="1%" align="right">' . '<div>' . '<div style="float:right;">' . $buttons . '</div>' . $html_not_filter . '<input id="__total_filters_on_screen_" name="__total_filters_on_screen_" type="hidden" value="' . $total_filters_on_screen . '" />' . '</div>' . '</td>' . '</tr>' . '<tr>' . '<td colspan="99">' . '<div id="update_filters_info"></div>' . '</td>' . '</tr>' . '</table>' . '</div>' . '<div style="float:right;margin-right:8px;background:url(' . PLUGIN_LINK . 'img/screen-options-left.gif) repeat-x;cursor:pointer;" ' . 'onclick="javascript:el_display_toggler(\'' . $toggler_handle . '\',\'_filter_TogglerImg' . $toggler_handle . '\');">' . '<span class="vert-scrolling-tab" style="line-height:22px;">' . $toggler_label . '' . '<img id="_filter_TogglerImg' . $toggler_handle . '" style="float:right;margin:0;" src="' . PLUGIN_LINK . 'img/screen-options-right.gif" valign="top" />' . '</span>' . '</div>' . '<script type="text/javascript">' . 'if(getCookie(\'myeasydb' . $toggler_handle . '\')==1) { ' . 'document.getElementById(\'' . $toggler_handle . '\').style.display=\'block\';' . 'document.getElementById(\'_filter_TogglerImg' . $toggler_handle . '\').src=\'' . PLUGIN_LINK . 'img/screen-options-right-up.gif\';' . '} else {' . 'document.getElementById(\'' . $toggler_handle . '\').style.display=\'none\';' . 'document.getElementById(\'_filter_TogglerImg' . $toggler_handle . '\').src=\'' . PLUGIN_LINK . 'img/screen-options-right.gif\';' . '}' . '</script>';
     return $html;
 }
Ejemplo n.º 2
0
     exit;
     break;
     #
     #---------------------------
 #
 #---------------------------
 case 'set_unfiltered_fields_selection':
     #---------------------------
     #
     #	0: database
     #	1: table
     #	2: field (not mandatory), if passed avoid to include it in the select
     #
     define('EDIT_TABLE_NAME', $parms[1]);
     require MED_PATH . 'inc/table_editor.inc.php';
     $not_filtered_fields = get_not_filtered_fields();
     $html_not_filtered = '<select id="not_ref_fields" name="not_filtered_fields">' . '<option value="">' . __('Select a new field to filter and click on this button &raquo;', MED_LOCALE) . '</option>';
     foreach ($not_filtered_fields as $field) {
         if ($field != $parms[2]) {
             $html_not_filtered .= '<option value="' . $field . '">' . $field . '</option>';
         }
     }
     $html_not_filtered .= '</select>';
     echo $html_not_filtered;
     //echo $splitter_block
     //	.$js;
     exit;
     break;
     #
     #---------------------------
 #