Plugin Directory

Changeset 2507785


Ignore:
Timestamp:
04/02/2021 01:23:29 AM (5 years ago)
Author:
mobilebsmith
Message:

tagging version 2.07

Location:
brads-entity-attribute-value-database
Files:
5 edited
7 copied

Legend:

Unmodified
Added
Removed
  • brads-entity-attribute-value-database/tags/2.07/entity-attribute-value-database.php

    r2504902 r2507785  
    44* Plugin URI: http://mobilebsmith.hopto.org
    55* Description: Brad's Entity Attribute Value Database
    6 * Version: 2.06
     6* Version: 2.07
    77* Author: Bradley Smith
    88* Author URI: http://mobilebsmith.hopto.org
    99**/
    1010
    11 
     11//entity_type defines - don't change
     12define("EAV_REC_FLD", 0);   // this shows the value is record/field information
     13define("EAV_SQL", 2);       // this shows the value is sql for default field handling
    1214 
    1315register_activation_hook( __FILE__, 'eav_import_init' );
     
    2729   
    2830    $sql2 = "CREATE TABLE " . $wpdb->base_prefix . "eav_entity (
     31        entity_type     int,
    2932        entity          int,   
    3033        entity_id       int,
    3134        entity_attrib   int,   
    32         val_char        varchar(128),
     35        val_char        text,
    3336        parent_entity   int,
    3437        parent_entity_id    int,
    35     PRIMARY KEY(entity,entity_id, entity_attrib)       
     38    PRIMARY KEY(entity_type ,entity, entity_id, entity_attrib)     
    3639    )";
    3740    dbDelta( $sql2 );
     
    4649        entity_desc     varchar(256),
    4750        entity_default  varchar(256),
     51        input_format    varchar(32),
     52        show_on_browse  varchar(1),
    4853    PRIMARY KEY (entity_attrib, entity_name )
    4954    )";
     
    6671    )";
    6772    dbDelta( $sql2 );
     73   
    6874
    6975}
     
    7480
    7581
    76 function eav_handle_defaults($value) {
     82// expands #xxxx values in string
     83function eav_handle_string($sql_string) {
     84
     85    // #userid must come before #user, because #user is contained in #userid
     86    $input_f_array = array( "#userid", "#user", "#today", "#now");
     87    $newstring = $sql_string;
     88    for($i = 0; $i < count($input_f_array); $i++) {
     89        $u_contain = stripos  ($newstring, $input_f_array[$i], 0);
     90        if ($u_contain !== false ) {
     91            $middle = "'" . eav_handle_defaults($input_f_array[$i], 0, 0) . "'";
     92            $v_string = str_ireplace($input_f_array[$i], $middle, $newstring);
     93            $newstring = $v_string;
     94        }
     95    }
     96    return $newstring;
     97   
     98}
     99function eav_handle_sql ($v_entity, $v_attrib)
     100{
     101    global $wpdb;
     102    global $wp;
     103   
     104    $sql = sprintf("select val_char from " . $wpdb->base_prefix . "eav_entity " .
     105            "where entity_type=%d and entity=%d and entity_id=0 and entity_attrib=%d ",
     106                EAV_SQL, $v_entity, $v_attrib);
     107    $eav_sql = $wpdb->get_row($sql);
     108    if (isset($eav_sql->val_char)) {
     109        $v_text = $eav_sql->val_char;   
     110        $sql = eav_handle_string($eav_sql->val_char);
     111        $testout = $wpdb->get_row($sql);
     112        //$datat = array_shift($testout);
     113        $array = json_decode(json_encode($testout), true);
     114        $single_val = array_shift($array);
     115        return $single_val;
     116    }
     117    return "";
     118   
     119   
     120}
     121function eav_handle_defaults($value, $v_entity, $v_attrib) {
    77122        global $wpdb;
    78123        global $wp;
     
    80125        $current_user =  wp_get_current_user();
    81126        $return = "";
     127
    82128        switch($value) {
    83129            case "#user";
    84130                $return = $current_user->user_login;
    85131                break;
     132            case "#userid";
     133                $return = $current_user->ID;
     134                break;
    86135            case "#today";
    87                 $return = date("m/d/Y");
    88                 break;
    89             case "#now";
    90                 $return = date ("m/d/Y H:i:s");
     136                $return = date("Y-m-d");
     137                break;
     138            case "#now";  //2000-01-01T00:00:00
     139                //date_default_timezone_set('America/New_York');
     140                $return = current_time ("Y-m-d\TH:i:s", false);
     141                break;
     142            case "%sql";
     143                if(($v_entity != 0) && ($v_attrib != 0))
     144                    $return = eav_handle_sql($v_entity, $v_attrib);
     145                else
     146                    $return = "";
    91147                break;
    92148        }
  • brads-entity-attribute-value-database/tags/2.07/includes/admin_menu.php

    r2504873 r2507785  
    11<?php
     2
     3if (defined('EAV_SQL') == false) {
     4    define("EAV_SQL", 0);   // this shows the value is record/field information
     5}
     6 
     7
    28
    39function eav_main_page(){
     
    6571    add_submenu_page( $menu_slug, 'Manage Record Layout', 'Manage Record Layout'
    6672        , 'manage_options', $submenu2_slug, $submenu2_slug);
     73       
     74// this option allows you to setup to use some sql to grab data for default values
     75    $submenu2_slug = 'eav_manage_sql';
     76    add_submenu_page( $menu_slug, 'SQL Default', 'SQL Default'
     77        , 'manage_options', $submenu2_slug, $submenu2_slug);
     78       
     79// future coding
     80//  $submenu2_slug = 'eav_manage_apps';
     81//  add_submenu_page( $menu_slug, 'Install Demo Apps', 'Install Demo Apps'
     82//      , 'manage_options', $submenu2_slug, $submenu2_slug);
    6783
    6884}
    6985
     86function eav_manage_sql ()
     87{
     88    global $wpdb;
     89
     90    ob_start(); // this allows me to use echo and then use sanitize_text_field() at the end
     91   
     92    $_POST = array_map( 'stripslashes_deep', $_POST ); // strips off wordpress escaping quotes
     93
     94
     95    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div>
     96        <h2>Manage SQL defaults</h2></div>';
     97    // initialize variables
     98    $v_entity="";
     99    $v_attrib ="";
     100    $v_text = "";
     101    $v_results = "";
     102    $update = false;
     103
     104    //user selected a record
     105    if (isset($_POST['selrec'])) {
     106        $v_entity = sanitize_text_field($_POST['recname']);
     107    }
     108    //user selected a fild after selecting a record
     109    if (isset($_POST['selfld'])) {
     110        $v_entity = sanitize_text_field($_POST['entity']);
     111        $v_attrib = sanitize_text_field($_POST['fldname']);
     112        // need to check if we have sql already
     113        $sql = sprintf("select val_char from " . $wpdb->base_prefix . "eav_entity " .
     114            "where entity_type=%d and entity=%d and entity_id=0 and entity_attrib=%d ",
     115                EAV_SQL, $v_entity, $v_attrib);
     116        $eav_sql = $wpdb->get_row($sql);
     117        if (isset($eav_sql->val_char)) {
     118                $v_text = $eav_sql->val_char;
     119                $update = true;
     120        }
     121    }
     122    //user is adding sql
     123    if (isset($_POST['addsql'])) {
     124        $v_entity = sanitize_text_field($_POST['entity']);
     125        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     126        $v_text = sanitize_text_field($_POST['sqltext']);
     127            $sql_insert =sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity_type, entity, entity_id, entity_attrib, " .
     128                " val_char, parent_entity, parent_entity_id) values (%d, %d, 0, %d, '%s', 0, 0)",
     129                    EAV_SQL, $v_entity, $v_attrib, $v_text);
     130            $return = $wpdb->query($sql_insert  );
     131            if ($return == false) {
     132                echo "<P>Insert into eav_entity failed: " . ' - wpdb->last_error : ' . $wpdb->last_error;
     133            }       
     134        $wpdb->flush();
     135        $update=true;
     136    }
     137    //user is updating  sql
     138    if (isset($_POST['updatesql'])) {
     139        $v_entity = sanitize_text_field($_POST['entity']);
     140        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     141        $v_text = sanitize_text_field($_POST['sqltext']);
     142            $prep = $wpdb->prepare (
     143            "update " . $wpdb->base_prefix . "eav_entity set val_char=%s where entity_type=%d and entity=%d " .
     144            " and entity_attrib=%d and entity_id=0 "
     145                , $v_text . ''
     146                , EAV_SQL
     147                , $v_entity
     148                , $v_attrib
     149            );
     150            $return = $wpdb->query($prep );
     151        $wpdb->flush();
     152        $update=true;
     153    }
     154    //user is testing sql
     155    if (isset($_POST['testsql'])) {
     156        $v_entity = sanitize_text_field($_POST['entity']);
     157        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     158        $v_text = sanitize_text_field($_POST['sqltext']);
     159        $sql = eav_handle_string($v_text);
     160        $testout = $wpdb->get_row($sql);
     161        $array = json_decode(json_encode($testout), true);
     162        $v_results = array_shift($array);
     163        $update=true;
     164    }
     165
     166    echo '<form action="" method="post">';
     167    echo '<select name="recname" id="recname" >';
     168    echo '<option value=""></option>';
     169    $sql = "select entity,tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl ";
     170    $results = $wpdb->get_results($sql);
     171    foreach($results as $element) {
     172        if ($v_entity == $element->entity)
     173            echo '<option value="' . esc_html($element->entity) .'" selected>' . esc_html($element->tblname) . '</option>';
     174        else
     175            echo '<option value="' . esc_html($element->entity) .'">' . esc_html($element->tblname) . '</option>';
     176    }
     177    echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="selrec" value="Select Record">';
     178    echo '</form>';
     179   
     180    if ($v_entity != "") {
     181        echo '<form action="" method="post">';
     182        echo '<input type="hidden" id="entity" name="entity" value ="' . esc_html($v_entity) . '">';
     183        echo '<select name="fldname" id="fldname" >';
     184        echo '<option value=""></option>';
     185        $sql = "select a.entity_attrib ,b.entity_name from " . $wpdb->base_prefix . "eav_layout a, " . $wpdb->base_prefix . "eav_attrib b " .
     186            " where a.entity_attrib=b.entity_attrib and a.entity=" . esc_html($v_entity) ;
     187        $results = $wpdb->get_results($sql);
     188        foreach($results as $element) {
     189            if ( $v_attrib == $element->entity_attrib)
     190                echo '<option value="' . esc_html($element->entity_attrib) .'" selected >' . esc_html($element->entity_name) . '</option>';
     191            else
     192                echo '<option value="' . esc_html($element->entity_attrib) .'">' . esc_html($element->entity_name) . '</option>';
     193        }
     194        echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="selfld" value="Select Field">';
     195        echo '</form>';
     196        echo '<P>' ;
     197       
     198        if (($v_entity != "") && ($v_attrib != "")) {
     199
     200            echo '<form action="" method="post">';
     201            echo '<input type="hidden" id="entity" name="entity" value ="' . esc_html($v_entity) . '">';
     202            echo '<input type="hidden" id="entity_attrib" name="entity_attrib" value ="' . esc_html($v_attrib) . '">';
     203            echo '<table>';
     204            echo '<tr><td><label for="l_sqltext">SQL Text:</label>';
     205            echo '</td><td>';
     206            echo '<textarea id="sqltext" name="sqltext" rows="8" cols="70" >' . esc_html($v_text) . '</textarea>';
     207            echo '</td><td><B>Test Result:&nbsp;&nbsp;</B>' . esc_html($v_results) . '</td>';
     208            echo '</tr></table>';
     209            echo '<P>';
     210            if($update == true)
     211                echo '<input type="submit" name="updatesql" value="Update SQL">';
     212            else
     213                echo '<input type="submit" name="addsql" value="Add SQL">';
     214            echo '<input type="submit" name="testsql" value="Test SQL">
     215                <br> </form>';
     216        }
     217    }
     218    $content = ob_get_contents();
     219    ob_end_clean();
     220    echo $content; 
     221
     222}
     223
     224
     225
     226function eav_manage_apps() {
     227   
     228    ob_start(); // this allows me to use echo and then use sanitize_text_field() at the end
     229   
     230
     231    if (isset($_POST['guest_reg'])) {
     232        // install the demo guest registration system
     233        install_guest_reg();
     234    }
     235   
     236    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div><h2>Install Demo Apps</h2></div><P>';
     237    echo '<form action="" method="post">
     238        <label>
     239        <input type="checkbox" id="guest_reg" name="guest_reg" value="guest_reg">
     240        Install demo guest registration
     241        <P><input type="submit" value="Install Demo Apps" name="install_demo_app">
     242         </form>';
     243   
     244    $content = ob_get_contents();
     245    ob_end_clean();
     246    echo $content;
     247}
    70248
    71249function eav_manage_tbl(){
     
    209387        $eav_attrib1 = sanitize_text_field($_GET['entity_attribute']);
    210388        echo "<H1>Edit Field " . esc_html($eav_attrib1)  . "</H1><br>";
    211         $sql_edit = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default " .
     389        $sql_edit = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format, show_on_browse " .
    212390            " from " . $wpdb->base_prefix . "eav_attrib " .
    213391            " where entity_attrib = " . $eav_attrib1;
     
    223401        <input type="text" id="entity_default" name="entity_default" size="64" value = "' . esc_html($eav_fldupdate->entity_default) . '"  ><br>
    224402        <input type="hidden" id="updfld" name="updfld" value ="updfld">
    225         <input type="hidden" id="entity_attrib" name="entity_attrib" value="' . esc_html($eav_attrib1) . '">
     403        <label for="seachlabel">Input Format:</label> ';
     404        // handle default if there
     405        if (isset($eav_fldupdate->input_format) && (strlen(trim($eav_fldupdate->input_format)) > 0))
     406            $def_input = $eav_fldupdate->input_format;
     407        else
     408            $def_input = "";
     409       
     410
     411        $input_f_array = array("text", "date", "datetime-local");
     412        echo '<select name="input_format" id="input_format" >';
     413        for($i = 0; $i < count($input_f_array); $i++) { // for each format type we support
     414            if($def_input == $input_f_array[$i]) {
     415                echo '<option value="' . esc_html($input_f_array[$i]) .'" selected >' .  esc_html($input_f_array[$i]) . '</option>';
     416            }else {
     417                echo '<option value="' . esc_html($input_f_array[$i]) .'" >' .  esc_html($input_f_array[$i]) . '</option>';
     418            }
     419        }
     420        echo '</select><br>';
     421        echo '<label for="seachlabel">Show on Browse/Update:</label> ';
     422        echo '<select name="show_on_browse" id="show_on_browse">';
     423        if ($eav_fldupdate->show_on_browse == 'n')
     424            echo '<option value="y" >Yes</option><option value="n" selected>No</option>';
     425        else
     426            echo '<option value="y" selected>Yes</option><option value="n">No</option>';
     427        echo '</select><br>';
     428        echo '<input type="hidden" id="entity_attrib" name="entity_attrib" value="' . esc_html($eav_attrib1) . '">
    226429        <P>
    227430        <input type="submit" id="update" name="eav_submit" value="Update Field">
     
    235438        #today = current date
    236439        #user = current user
     440        #userid = current user id (wordpress id)
    237441        #now = current date/time
     442        %sql = uses SQL to find the default, based off sql setup
    238443        </PRE>';
    239444    } else {
     
    244449                $u_entity_format = strtolower(sanitize_mime_type($_POST['entity_format']));
    245450                $u_entity_default = strtolower(sanitize_text_field($_POST['entity_default']));
     451                $u_entity_input = strtolower(sanitize_text_field($_POST['input_format']));
     452                $u_show = strtolower(sanitize_text_field($_POST['show_on_browse']));
    246453                // sanitize_mime_type strips off the % (percent) sometimes so we just double check that
    247454                if ($u_entity_format[1] != "%")
    248455                    $u_entity_format = "%" . $u_entity_format;
    249456                $u_entity_desc = sanitize_text_field($_POST['entity_desc']);
    250                 $usql = sprintf("update " . $wpdb->base_prefix . "eav_attrib set entity_name='%s', entity_format='%s', entity_desc='%s', entity_default='%s' where  entity_attrib = %s"
    251                         ,$u_entity_name ,$u_entity_format,$u_entity_desc, $u_entity_default, $u_entity_attrib);
     457                $usql = sprintf("update " . $wpdb->base_prefix . "eav_attrib set entity_name='%s', entity_format='%s', entity_desc='%s', entity_default='%s', input_format='%s',show_on_browse='%s' where  entity_attrib = %s"
     458                        ,$u_entity_name ,$u_entity_format,$u_entity_desc, $u_entity_default, $u_entity_input, $u_show, $u_entity_attrib);
    252459               
    253460                //$prep = $wpdb->prepare ($usql);
     
    315522         <br> </form>';
    316523
    317         $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default from " . $wpdb->base_prefix . "eav_attrib ";
     524        $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format, show_on_browse from " . $wpdb->base_prefix . "eav_attrib ";
    318525        echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
    319526        echo '<tr >
     
    323530            <th style="border: 1px solid black"; onclick="eav_sortTable(3)">Description</th>
    324531            <th style="border: 1px solid black"; onclick="eav_sortTable(4)">Default</th>
     532            <th style="border: 1px solid black"; onclick="eav_sortTable(5)">Input Format</th>
     533            <th style="width: 60px; border: 1px solid black"; onclick="eav_sortTable(6)">Show on Browse</th>
    325534            </tr>
    326535        ';
     
    337546            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_desc) . '</td>';
    338547            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_default) . '</td>';
     548            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->input_format) . '</td>';
     549            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->show_on_browse) . '</td>';
    339550            echo '</tr>';
    340551            $row_count = $row_count + 1;
     
    600811
    601812
    602 
    603813?>
  • brads-entity-attribute-value-database/tags/2.07/includes/shortcodes.php

    r2504902 r2507785  
    77//eav_endadd - this ends the form and places a submit button
    88
     9function get_save_entity($t_entity = '') {
     10    static $gs_entity;
     11   
     12    if (!empty($t_entity)) {
     13        $gs_entity = $t_entity;
     14    }
     15    return $gs_entity;
     16}
     17
    918function eav_field($atts = [], $content = null) {
    1019    global $wpdb;
     
    1221    ob_start(); // this allows me to use echo instead of using concat all strings
    1322
     23    $tablename = get_save_entity();
     24    $tblsql = "select entity from " . $wpdb->base_prefix . "eav_tbl where tblname='" . $tablename . "'";
     25    $res1 = $wpdb->get_row($tblsql);
     26    $v_res1 = $res1->entity;
     27
    1428    $fieldname = sanitize_text_field($atts['field']);
    15     if (isset($atts['hidden'])) {
    16         if (sanitize_text_field($atts['hidden']) == "y")
    17             $typeval="hidden";
    18         else
    19             $typeval="text";
    20     }else {
    21         $typeval="text";
    22     }
    23     $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default from " . $wpdb->base_prefix . "eav_attrib where entity_name = '" . $fieldname . "'";
     29    $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format from " . $wpdb->base_prefix . "eav_attrib where entity_name = '" . $fieldname . "'";
    2430    $result_tbl = $wpdb->get_row($sql);
     31    // handle default
    2532    if (isset($result_tbl->entity_default))
    26         $default = eav_handle_defaults($result_tbl->entity_default);
     33        $default = eav_handle_defaults($result_tbl->entity_default, $v_res1, $result_tbl->entity_attrib);
    2734    else
    2835        $default = "";
     36    //handle format length
    2937    if (isset($result_tbl->entity_format))
    3038        $int = strlen(sprintf($result_tbl->entity_format, ""));
    3139    else
    3240        $int = 20; //default length
     41       
     42    // handle input type
     43    if (isset($atts['hidden'])) {
     44        if (sanitize_text_field($atts['hidden']) == "y")
     45            $typeval="hidden";
     46        else {
     47            if (isset($result_tbl->input_format))
     48                $typeval = $result_tbl->input_format;
     49            else
     50                $typeval = "text";
     51        }
     52    }else {
     53        if (isset($result_tbl->input_format))
     54            $typeval = $result_tbl->input_format;
     55        else
     56            $typeval = "text";
     57    }
     58
    3359    echo '&nbsp;<input type="' . $typeval . '" size="' . $int . '" name="' .  esc_html($fieldname) . '" id="' .  esc_html($fieldname) . '" value="' . $default . '" >';
    3460   
     
    6288        $v_entity = $result_tbl1->entity;
    6389        // find new row number
    64                 $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $v_entity;
     90                $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $v_entity . "and entity_type = 0";
    6591                $result_tbl1 =$wpdb->get_row($maxid);   
    6692                if (isset($result_tbl1->maxid))
     
    79105                // okay the field is in the post so we need to santize and insert results.
    80106                $eav_val_char = sanitize_text_field($_POST[$result_fld->entity_name]);
    81                 $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', 0, 0)"
     107                $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id , entity_type ) values (%s, %s, %s, '%s', 0, 0, 0)"
    82108                        , $v_entity , $v_entity_id , $v_entity_attrib , $eav_val_char );
    83109                $return = $wpdb->query($sql );
     
    122148            // so at this point loop_cnt has how many loops we need to make
    123149            for($i = 0; $i < $loop_cnt; $i++) {
    124                 $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $subv_entity;
     150                $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $subv_entity . " and entity_type = 0";
    125151                $result_tbl1 =$wpdb->get_row($maxid);   
    126152                if (isset($result_tbl1->maxid))
     
    138164                        $fld_val = $fld_array[$i];
    139165
    140                         $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', %s, %s)"
     166                        $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id, entity_type ) values (%s, %s, %s, '%s', %s, %s, 0)"
    141167                            , $subv_entity , $subv_entity_id , $subv_entity_attrib , $fld_val, $v_entity , $v_entity_id );
    142168                        $return = $wpdb->query($sql );
     
    156182    echo '<input type="hidden" id="eav_startadd" name="eav_startadd" value="eav_startadd">';
    157183   
     184    get_save_entity($tablename); // this saves table name so we can grab it if needed
     185   
    158186    $content = ob_get_contents();
    159187    ob_end_clean();
     
    195223        $v_entity = $result_tbl1->entity;
    196224        // find new row number
    197         $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . sanitize_text_field($v_entity);
     225        $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . sanitize_text_field($v_entity)  . " and entity_type = 0";
    198226        $result_tbl1 =$wpdb->get_row($maxid);
    199227        $v_entity_id = sanitize_text_field($result_tbl1->maxid) + 1;   
     
    210238               
    211239                $prep = $wpdb->prepare (
    212                 "INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char) values (%s, %s, %s, %s)"
     240                "INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, entity_type) values (%s, %s, %s, %s, 0)"
    213241                , $v_entity . ''
    214242                , $v_entity_id . ''
     
    254282    ob_start(); // this allows me to use echo instead of using concat all strings
    255283   
    256 
    257    
    258284   
    259285    $tablename = sanitize_text_field($atts['table']);
     
    278304       
    279305        echo 'var cell' . $cellno . ' = row.insertCell(' . ($cellno -1 ) . ');';
    280         echo 'cell'. $cellno . '.innerHTML = \'<input type="text"  size="' . $int . '" name="' . esc_html($element->entity_name) . '[]"/>\';';
     306        echo 'cell'. $cellno . '.innerHTML = \'<input type="text"  size="' . $int . '" name="' .
     307            esc_html($element->entity_name) . '[]"/>\';';
    281308        $cellno = $cellno + 1;
    282309        }
     
    287314    echo '<style>
    288315        table, th, td { border: 2px solid black;}
     316    </style>';
     317   
     318    // This allows us a horizontal scrollable grid
     319    echo '<style>
     320        .horizontal-snap {
     321            margin: 0 auto;
     322            display: grid;
     323            grid-auto-flow: column;
     324            gap: 1rem;
     325            padding: 1rem;
     326            overflow-y: auto;
     327            overscroll-behavior-x: contain;
     328            scroll-snap-type: x mandatory;
     329        }       
    289330        </style>';
    290331
     332    echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
    291333
    292334    echo '<table id="tbl-' . esc_html($tablename) . '">';
     
    304346        else
    305347            $int = 20;
     348        // need to handle defaults on subrecord field here
    306349        echo '<th style= "width: ' . $int . 'px" >' . esc_html($element->entity_name) . '</th>';
    307350    }
     
    322365    echo '</tr>';
    323366    echo '</table >';
     367    echo '</div>';  //end scroll
     368    echo '<P>';
    324369    echo '<input type="button" id="add-' . esc_html($tablename) . '" name="add-' . esc_html($tablename) . '" value="Add Row" onclick="MyAddRow' . esc_html($tablename)  . '()"/>';
    325 
     370    echo "<P>";
    326371   
    327372    $content = ob_get_contents();
     
    371416                    // need to first check if the value is there, if not we insert
    372417                    $sqlchk = "select count(*) as x from " . $wpdb->base_prefix . "eav_entity where entity=" . $v_entity . " and entity_id= " . $v_id .
    373                         " and entity_attrib=" . $v_attrib;
     418                        " and entity_attrib=" . $v_attrib  . " and entity_type = 0";
    374419                    $chkresult=$wpdb->get_row($sqlchk);
    375420                    if ($chkresult->x == 1) {
     
    378423                    } else {
    379424                        // need to find parent value down the road
    380                         $sqlupd = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', 0,0)"
     425                        $sqlupd = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id, entity_type ) values (%s, %s, %s, '%s', 0,0, 0)"
    381426                            , $v_entity , $v_id , $v_attrib , $val );
    382427                    }                       
     
    393438            exit;
    394439        }
    395         if (isset($atts['allowadd']))
    396             $allowadd = sanitize_text_field($atts['allowadd']);
    397         else
    398             $allowadd = "";
    399            
    400         if (isset($atts['allowupd']))
    401             $allowupd = sanitize_text_field($atts['allowupd']);
    402         else
    403             $allowupd = "";
    404        
    405        
     440        $allowadd = "";
     441        $allowupd = "";
     442        if (isset($atts['0'])) {
     443            $value = sanitize_text_field($atts['0']);
     444            if($value == "allowadd")
     445                $allowadd = "y";
     446            if($value == "allowupd")
     447                $allowupd = "y";
     448        }
     449           
     450
    406451        // get table id #
    407452        $tblid = "select entity, tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl where tblname = '" . $tablename . "'";
     
    416461                    " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b where a.entity = " . sanitize_text_field($result_tbl->entity) .
    417462                    " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " .
    418                     " and a.entity_id in (select distinct entity_id from " . $wpdb->base_prefix . "eav_entity where val_char like '%" . $lookfor . "%' )" .
     463                    " and a.entity_type = 0 " .
     464                    " and a.entity_id in (select distinct entity_id from " . $wpdb->base_prefix . "eav_entity where val_char like '%" . $lookfor . "%' and entity_type = 0 )" .
    419465                    "  order by entity_id,b.entity_order ";
    420466            } else {
     
    423469                        " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    424470                        " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) .
     471                        " and a.entity_type = 0 " .
    425472                        " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    426473            }
     
    430477            " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    431478            " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) .
     479            " and a.entity_type = 0 " .
    432480            " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    433481        }
     
    448496        echo '</table>';
    449497   
     498        // This allows us a horizontal scrollable grid
     499        echo '<style>
     500        .horizontal-snap {         
     501            display: grid;
     502            grid-auto-flow: column;
     503            overflow-y: auto;
     504            overscroll-behavior-x: contain;
     505            scroll-snap-type: x mandatory;
     506        }       
     507        </style>'; 
     508   
    450509        //show all database fields in table
    451         $hsql = "select a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, " .
     510        $hsql = "select a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, a.show_on_browse, " .
    452511            " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " .
    453512            " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . ' order by b.entity_order' ;
    454513        $results = $wpdb->get_results($hsql);
    455         echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
     514        echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
     515        echo '<table style="margin-left: auto; margin-right: auto; border: 1px solid black" id="myTable" >';
    456516        echo '<tr ><th></th>';
    457517        $colid = 0;
    458518        foreach($results as $element) {
    459519            $int = strlen(sprintf($element->entity_format, ""));
     520           
    460521            //echo '<th style="width: ' . $int . 'px; border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
    461             echo '<th style="border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
    462             $colid = $colid + 1;
     522            //check if we want to show data
     523            if ( $element->show_on_browse != "n" ) {
     524                echo '<th style="border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
     525                $colid = $colid + 1;
     526            }
    463527        }
    464528        echo '</tr>';
    465529        $new_row = 0;
    466530   
    467         $sql="select max(entity_order) as max from " . $wpdb->base_prefix . "eav_layout where entity = " . sanitize_text_field($result_tbl->entity);
    468         $result_tbl =$wpdb->get_row($sql);
    469         $max_col = $result_tbl->max;
     531        //$sql="select max(entity_order) as max from " . $wpdb->base_prefix . "eav_layout where entity = " . sanitize_text_field($result_tbl->entity);
     532        //$result_tbl =$wpdb->get_row($sql);
     533        //$max_col = $result_tbl->max;
     534        $max_col = $colid;
    470535   
    471536        $sql_limit_q = $sql_limit * $colid;
     
    476541        echo "<tr>";
    477542        foreach($results as $element) {
    478             if (( $new_row <> sanitize_text_field($element->entity_id)) && ( $new_row <> 0)) {
     543            // determine if we want to show based on show_on_browse
     544            $sql_show="select show_on_browse from " . $wpdb->base_prefix . "eav_attrib where entity_attrib = " . $element->entity_attrib;
     545            $show = $wpdb->get_row($sql_show);
     546            if ($show->show_on_browse != "n") {
     547             if (( $new_row <> sanitize_text_field($element->entity_id)) && ( $new_row <> 0)) {
    479548                //finish out row if no data
    480549                for($ii = $colno; $ii < $max_col; $ii++) {
     
    497566                    echo '</td>';
    498567                }
    499             } else if (($colno == 1)&& ($new_row == 0)) { // first time
     568             } else if (($colno == 1)&& ($new_row == 0)) { // first time
    500569                if ($allowupd != "y") {
    501570                    echo '<td style="border: 1px solid black">';
     
    510579                    echo '</td>';
    511580                }
    512             }
    513             $new_row = sanitize_text_field($element->entity_id);
    514             $newcol = sanitize_text_field($element->entity_order);
    515             if ($newcol != ($colno +1)) {
     581             }
     582           
     583             $new_row = sanitize_text_field($element->entity_id);
     584             $newcol = sanitize_text_field($element->entity_order);
     585             if ($newcol != ($colno +1)) {
    516586                // missing columns
    517587                for($ii = ($colno +1); $ii < $newcol; $ii++)
    518588                    echo '<td style="border: 1px solid black"></td>';
    519             }                   
    520             echo '<td style="border: 1px solid black">';
    521             echo esc_html($element->val_char) . '</td>';
    522             $colno = $newcol;
     589             }                 
     590             echo '<td style="border: 1px solid black">';
     591             echo esc_html($element->val_char) . '</td>';
     592             $colno = $newcol;
     593            }
    523594        }
    524595        //Finish out last row
     
    527598   
    528599        echo '</tr></table>';
    529 
     600        echo '</div>'; // this ends makes row horizontal scrollable
    530601        $content = ob_get_contents();
    531602        ob_end_clean();
     
    545616    echo '<form action="" method="post">' ;
    546617    //show all database fields in table
    547     $hsql = "select  a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, " .
     618    $hsql = "select  a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, a.input_format, a.show_on_browse, " .
    548619        " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " .
    549620        " where a.entity_attrib=b.entity_attrib " .
     
    554625       
    555626        $vsql="select val_char from " . $wpdb->base_prefix . "eav_entity where entity=" . $v_entity .
    556             " and entity_id = " . $v_id . " and entity_attrib = " . $element->entity_attrib;
     627            " and entity_id = " . $v_id . " and entity_attrib = " . $element->entity_attrib  . " and entity_type = 0";
    557628        $v_results = $wpdb->get_row($vsql);
    558629        if (isset($v_results->val_char))
     
    560631        else
    561632            $val = "";
    562         echo '<input type="text" name="' . esc_html($element->entity_attrib) . '" size="50" ' . $update ;
     633       
     634        if (isset($element->input_format))
     635            $typeval = $element->input_format;
     636        else
     637            $typeval = "text";
     638
     639        echo '<input type="' . $typeval . '" name="' . esc_html($element->entity_attrib) . '" size="50" ' . $update ;
    563640        echo ' value="' . esc_html($val) . '" >';
    564641        echo '<br>';
     
    573650        // show child records - $v_entity, $v_id
    574651        // get child records
     652       
     653        // This allows us a horizontal scrollable grid
     654        echo '<style>
     655        .horizontal-snap {
     656            margin: 0 auto;
     657            display: grid;
     658            grid-auto-flow: column;
     659            gap: 1rem;
     660            padding: 1rem;
     661            overflow-y: auto;
     662            overscroll-behavior-x: contain;
     663            scroll-snap-type: x mandatory;
     664        }       
     665        </style>'; 
     666       
    575667        $c1sql= "select entity, tblname from " . $wpdb->base_prefix . "eav_tbl where parent_entity = " . $v_entity ;
    576668        $result_tbl = $wpdb->get_row($c1sql);
     
    583675                " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity . ' order by b.entity_order' ;
    584676            $results = $wpdb->get_results($hsql);
     677            echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
    585678            echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
    586679            echo '<tr ><th style="border: 1px solid black"></th>';  // first column is for view data
     
    599692            " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    600693            " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity .
    601             " and a.parent_entity = " .  $v_entity . " and a.parent_entity_id = " . $v_id .
     694            " and a.parent_entity = " .  $v_entity . " and a.parent_entity_id = " . $v_id . " and a.entity_type = 0 " .
    602695            " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    603696
     
    638731   
    639732            echo '</tr></table>';
    640 
    641        
    642             $c2sql = "select entity, entity_id, entity_attrib, val_cha, parent_entity, parent_entity_id
    643                 from " . $wpdb->base_prefix . "eav_entity where parent_entity = " . $v_entity .
    644                 " and parent_entity_id = " . $v_id;
    645             echo '<a href="javascript:history.back()">Go Back</a>';
     733            echo '</div>'; // end of this makes row horizontal scrollable
    646734        }
    647735    }
     736    echo '<P><a href="javascript:history.back()">Go Back</a>';
    648737}
    649738
  • brads-entity-attribute-value-database/tags/2.07/readme.txt

    r2504902 r2507785  
    66Author: Bradley Smith
    77Requires PHP: 7.0
    8 Requires at least: 5.7
    9 Tested up to: 5.7
    10 Stable tag: 2.06
    11 Version: 2.06
     8Requires at least: 5.6
     9Tested up to: 5.6
     10Stable tag: 2.07
     11Version: 2.07
    1212License: GPLv2 or later
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3636    Mange Attributes - This is where you will define your fields
    3737    Manage Record Layout - This is where you will define what fields are in each of your records
     38    SQL Default - This is where you will define sql for defaulting values
    3839
    3940shortcodes - standalone
     
    7980
    8081== Changelog ==
     82
     83= v2.07 [4/1/2021]
     84* added being able to default field values via SQL
     85* subrecords and table view now have scroll bar if the screen is not large enough
     86* tested on older version of wordpress
     87
    8188= v2.06 [3/28/2021]
    8289* bug fixes on shortcodes for eav_tbl and eav_subrec
  • brads-entity-attribute-value-database/tags/2.07/uninstall.php

    r2504282 r2507785  
    66    remove_shortcode('eav_endadd');
    77    remove_shortcode('eav_add');
     8    remove_shortcode('eav_field');
     9    remove_shortcode('eav_subrec');
    810
    911    //execute the query deleting the table
     
    2729    $wpdb->show_errors();
    2830    $wpdb->flush();
    29 
    30 //  $sql = "select id from wp_posts where post_name = 'jira-import';";
    31 //  $my_id = $wpdb->get_var($sql);
    32 //  wp_delete_post( $my_id, true );
    33 //  wp_trash_post( $my_id );   
    34 
    35     //remove_submenu_page('eav_manage_tbl');  // value from the add_submenu slug
    36     //remove_submenu_page('eav_manage_attrib'); // value from the add_submenu slug
     31   
    3732    remove_menu_page( 'eav_main_menu');
    38 
    39     //wp_redirect('/wp-admin/plugins.php');
    4033?>
  • brads-entity-attribute-value-database/trunk/entity-attribute-value-database.php

    r2504902 r2507785  
    44* Plugin URI: http://mobilebsmith.hopto.org
    55* Description: Brad's Entity Attribute Value Database
    6 * Version: 2.06
     6* Version: 2.07
    77* Author: Bradley Smith
    88* Author URI: http://mobilebsmith.hopto.org
    99**/
    1010
    11 
     11//entity_type defines - don't change
     12define("EAV_REC_FLD", 0);   // this shows the value is record/field information
     13define("EAV_SQL", 2);       // this shows the value is sql for default field handling
    1214 
    1315register_activation_hook( __FILE__, 'eav_import_init' );
     
    2729   
    2830    $sql2 = "CREATE TABLE " . $wpdb->base_prefix . "eav_entity (
     31        entity_type     int,
    2932        entity          int,   
    3033        entity_id       int,
    3134        entity_attrib   int,   
    32         val_char        varchar(128),
     35        val_char        text,
    3336        parent_entity   int,
    3437        parent_entity_id    int,
    35     PRIMARY KEY(entity,entity_id, entity_attrib)       
     38    PRIMARY KEY(entity_type ,entity, entity_id, entity_attrib)     
    3639    )";
    3740    dbDelta( $sql2 );
     
    4649        entity_desc     varchar(256),
    4750        entity_default  varchar(256),
     51        input_format    varchar(32),
     52        show_on_browse  varchar(1),
    4853    PRIMARY KEY (entity_attrib, entity_name )
    4954    )";
     
    6671    )";
    6772    dbDelta( $sql2 );
     73   
    6874
    6975}
     
    7480
    7581
    76 function eav_handle_defaults($value) {
     82// expands #xxxx values in string
     83function eav_handle_string($sql_string) {
     84
     85    // #userid must come before #user, because #user is contained in #userid
     86    $input_f_array = array( "#userid", "#user", "#today", "#now");
     87    $newstring = $sql_string;
     88    for($i = 0; $i < count($input_f_array); $i++) {
     89        $u_contain = stripos  ($newstring, $input_f_array[$i], 0);
     90        if ($u_contain !== false ) {
     91            $middle = "'" . eav_handle_defaults($input_f_array[$i], 0, 0) . "'";
     92            $v_string = str_ireplace($input_f_array[$i], $middle, $newstring);
     93            $newstring = $v_string;
     94        }
     95    }
     96    return $newstring;
     97   
     98}
     99function eav_handle_sql ($v_entity, $v_attrib)
     100{
     101    global $wpdb;
     102    global $wp;
     103   
     104    $sql = sprintf("select val_char from " . $wpdb->base_prefix . "eav_entity " .
     105            "where entity_type=%d and entity=%d and entity_id=0 and entity_attrib=%d ",
     106                EAV_SQL, $v_entity, $v_attrib);
     107    $eav_sql = $wpdb->get_row($sql);
     108    if (isset($eav_sql->val_char)) {
     109        $v_text = $eav_sql->val_char;   
     110        $sql = eav_handle_string($eav_sql->val_char);
     111        $testout = $wpdb->get_row($sql);
     112        //$datat = array_shift($testout);
     113        $array = json_decode(json_encode($testout), true);
     114        $single_val = array_shift($array);
     115        return $single_val;
     116    }
     117    return "";
     118   
     119   
     120}
     121function eav_handle_defaults($value, $v_entity, $v_attrib) {
    77122        global $wpdb;
    78123        global $wp;
     
    80125        $current_user =  wp_get_current_user();
    81126        $return = "";
     127
    82128        switch($value) {
    83129            case "#user";
    84130                $return = $current_user->user_login;
    85131                break;
     132            case "#userid";
     133                $return = $current_user->ID;
     134                break;
    86135            case "#today";
    87                 $return = date("m/d/Y");
    88                 break;
    89             case "#now";
    90                 $return = date ("m/d/Y H:i:s");
     136                $return = date("Y-m-d");
     137                break;
     138            case "#now";  //2000-01-01T00:00:00
     139                //date_default_timezone_set('America/New_York');
     140                $return = current_time ("Y-m-d\TH:i:s", false);
     141                break;
     142            case "%sql";
     143                if(($v_entity != 0) && ($v_attrib != 0))
     144                    $return = eav_handle_sql($v_entity, $v_attrib);
     145                else
     146                    $return = "";
    91147                break;
    92148        }
  • brads-entity-attribute-value-database/trunk/includes/admin_menu.php

    r2504873 r2507785  
    11<?php
     2
     3if (defined('EAV_SQL') == false) {
     4    define("EAV_SQL", 0);   // this shows the value is record/field information
     5}
     6 
     7
    28
    39function eav_main_page(){
     
    6571    add_submenu_page( $menu_slug, 'Manage Record Layout', 'Manage Record Layout'
    6672        , 'manage_options', $submenu2_slug, $submenu2_slug);
     73       
     74// this option allows you to setup to use some sql to grab data for default values
     75    $submenu2_slug = 'eav_manage_sql';
     76    add_submenu_page( $menu_slug, 'SQL Default', 'SQL Default'
     77        , 'manage_options', $submenu2_slug, $submenu2_slug);
     78       
     79// future coding
     80//  $submenu2_slug = 'eav_manage_apps';
     81//  add_submenu_page( $menu_slug, 'Install Demo Apps', 'Install Demo Apps'
     82//      , 'manage_options', $submenu2_slug, $submenu2_slug);
    6783
    6884}
    6985
     86function eav_manage_sql ()
     87{
     88    global $wpdb;
     89
     90    ob_start(); // this allows me to use echo and then use sanitize_text_field() at the end
     91   
     92    $_POST = array_map( 'stripslashes_deep', $_POST ); // strips off wordpress escaping quotes
     93
     94
     95    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div>
     96        <h2>Manage SQL defaults</h2></div>';
     97    // initialize variables
     98    $v_entity="";
     99    $v_attrib ="";
     100    $v_text = "";
     101    $v_results = "";
     102    $update = false;
     103
     104    //user selected a record
     105    if (isset($_POST['selrec'])) {
     106        $v_entity = sanitize_text_field($_POST['recname']);
     107    }
     108    //user selected a fild after selecting a record
     109    if (isset($_POST['selfld'])) {
     110        $v_entity = sanitize_text_field($_POST['entity']);
     111        $v_attrib = sanitize_text_field($_POST['fldname']);
     112        // need to check if we have sql already
     113        $sql = sprintf("select val_char from " . $wpdb->base_prefix . "eav_entity " .
     114            "where entity_type=%d and entity=%d and entity_id=0 and entity_attrib=%d ",
     115                EAV_SQL, $v_entity, $v_attrib);
     116        $eav_sql = $wpdb->get_row($sql);
     117        if (isset($eav_sql->val_char)) {
     118                $v_text = $eav_sql->val_char;
     119                $update = true;
     120        }
     121    }
     122    //user is adding sql
     123    if (isset($_POST['addsql'])) {
     124        $v_entity = sanitize_text_field($_POST['entity']);
     125        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     126        $v_text = sanitize_text_field($_POST['sqltext']);
     127            $sql_insert =sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity_type, entity, entity_id, entity_attrib, " .
     128                " val_char, parent_entity, parent_entity_id) values (%d, %d, 0, %d, '%s', 0, 0)",
     129                    EAV_SQL, $v_entity, $v_attrib, $v_text);
     130            $return = $wpdb->query($sql_insert  );
     131            if ($return == false) {
     132                echo "<P>Insert into eav_entity failed: " . ' - wpdb->last_error : ' . $wpdb->last_error;
     133            }       
     134        $wpdb->flush();
     135        $update=true;
     136    }
     137    //user is updating  sql
     138    if (isset($_POST['updatesql'])) {
     139        $v_entity = sanitize_text_field($_POST['entity']);
     140        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     141        $v_text = sanitize_text_field($_POST['sqltext']);
     142            $prep = $wpdb->prepare (
     143            "update " . $wpdb->base_prefix . "eav_entity set val_char=%s where entity_type=%d and entity=%d " .
     144            " and entity_attrib=%d and entity_id=0 "
     145                , $v_text . ''
     146                , EAV_SQL
     147                , $v_entity
     148                , $v_attrib
     149            );
     150            $return = $wpdb->query($prep );
     151        $wpdb->flush();
     152        $update=true;
     153    }
     154    //user is testing sql
     155    if (isset($_POST['testsql'])) {
     156        $v_entity = sanitize_text_field($_POST['entity']);
     157        $v_attrib = sanitize_text_field($_POST['entity_attrib']);
     158        $v_text = sanitize_text_field($_POST['sqltext']);
     159        $sql = eav_handle_string($v_text);
     160        $testout = $wpdb->get_row($sql);
     161        $array = json_decode(json_encode($testout), true);
     162        $v_results = array_shift($array);
     163        $update=true;
     164    }
     165
     166    echo '<form action="" method="post">';
     167    echo '<select name="recname" id="recname" >';
     168    echo '<option value=""></option>';
     169    $sql = "select entity,tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl ";
     170    $results = $wpdb->get_results($sql);
     171    foreach($results as $element) {
     172        if ($v_entity == $element->entity)
     173            echo '<option value="' . esc_html($element->entity) .'" selected>' . esc_html($element->tblname) . '</option>';
     174        else
     175            echo '<option value="' . esc_html($element->entity) .'">' . esc_html($element->tblname) . '</option>';
     176    }
     177    echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="selrec" value="Select Record">';
     178    echo '</form>';
     179   
     180    if ($v_entity != "") {
     181        echo '<form action="" method="post">';
     182        echo '<input type="hidden" id="entity" name="entity" value ="' . esc_html($v_entity) . '">';
     183        echo '<select name="fldname" id="fldname" >';
     184        echo '<option value=""></option>';
     185        $sql = "select a.entity_attrib ,b.entity_name from " . $wpdb->base_prefix . "eav_layout a, " . $wpdb->base_prefix . "eav_attrib b " .
     186            " where a.entity_attrib=b.entity_attrib and a.entity=" . esc_html($v_entity) ;
     187        $results = $wpdb->get_results($sql);
     188        foreach($results as $element) {
     189            if ( $v_attrib == $element->entity_attrib)
     190                echo '<option value="' . esc_html($element->entity_attrib) .'" selected >' . esc_html($element->entity_name) . '</option>';
     191            else
     192                echo '<option value="' . esc_html($element->entity_attrib) .'">' . esc_html($element->entity_name) . '</option>';
     193        }
     194        echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="selfld" value="Select Field">';
     195        echo '</form>';
     196        echo '<P>' ;
     197       
     198        if (($v_entity != "") && ($v_attrib != "")) {
     199
     200            echo '<form action="" method="post">';
     201            echo '<input type="hidden" id="entity" name="entity" value ="' . esc_html($v_entity) . '">';
     202            echo '<input type="hidden" id="entity_attrib" name="entity_attrib" value ="' . esc_html($v_attrib) . '">';
     203            echo '<table>';
     204            echo '<tr><td><label for="l_sqltext">SQL Text:</label>';
     205            echo '</td><td>';
     206            echo '<textarea id="sqltext" name="sqltext" rows="8" cols="70" >' . esc_html($v_text) . '</textarea>';
     207            echo '</td><td><B>Test Result:&nbsp;&nbsp;</B>' . esc_html($v_results) . '</td>';
     208            echo '</tr></table>';
     209            echo '<P>';
     210            if($update == true)
     211                echo '<input type="submit" name="updatesql" value="Update SQL">';
     212            else
     213                echo '<input type="submit" name="addsql" value="Add SQL">';
     214            echo '<input type="submit" name="testsql" value="Test SQL">
     215                <br> </form>';
     216        }
     217    }
     218    $content = ob_get_contents();
     219    ob_end_clean();
     220    echo $content; 
     221
     222}
     223
     224
     225
     226function eav_manage_apps() {
     227   
     228    ob_start(); // this allows me to use echo and then use sanitize_text_field() at the end
     229   
     230
     231    if (isset($_POST['guest_reg'])) {
     232        // install the demo guest registration system
     233        install_guest_reg();
     234    }
     235   
     236    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div><h2>Install Demo Apps</h2></div><P>';
     237    echo '<form action="" method="post">
     238        <label>
     239        <input type="checkbox" id="guest_reg" name="guest_reg" value="guest_reg">
     240        Install demo guest registration
     241        <P><input type="submit" value="Install Demo Apps" name="install_demo_app">
     242         </form>';
     243   
     244    $content = ob_get_contents();
     245    ob_end_clean();
     246    echo $content;
     247}
    70248
    71249function eav_manage_tbl(){
     
    209387        $eav_attrib1 = sanitize_text_field($_GET['entity_attribute']);
    210388        echo "<H1>Edit Field " . esc_html($eav_attrib1)  . "</H1><br>";
    211         $sql_edit = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default " .
     389        $sql_edit = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format, show_on_browse " .
    212390            " from " . $wpdb->base_prefix . "eav_attrib " .
    213391            " where entity_attrib = " . $eav_attrib1;
     
    223401        <input type="text" id="entity_default" name="entity_default" size="64" value = "' . esc_html($eav_fldupdate->entity_default) . '"  ><br>
    224402        <input type="hidden" id="updfld" name="updfld" value ="updfld">
    225         <input type="hidden" id="entity_attrib" name="entity_attrib" value="' . esc_html($eav_attrib1) . '">
     403        <label for="seachlabel">Input Format:</label> ';
     404        // handle default if there
     405        if (isset($eav_fldupdate->input_format) && (strlen(trim($eav_fldupdate->input_format)) > 0))
     406            $def_input = $eav_fldupdate->input_format;
     407        else
     408            $def_input = "";
     409       
     410
     411        $input_f_array = array("text", "date", "datetime-local");
     412        echo '<select name="input_format" id="input_format" >';
     413        for($i = 0; $i < count($input_f_array); $i++) { // for each format type we support
     414            if($def_input == $input_f_array[$i]) {
     415                echo '<option value="' . esc_html($input_f_array[$i]) .'" selected >' .  esc_html($input_f_array[$i]) . '</option>';
     416            }else {
     417                echo '<option value="' . esc_html($input_f_array[$i]) .'" >' .  esc_html($input_f_array[$i]) . '</option>';
     418            }
     419        }
     420        echo '</select><br>';
     421        echo '<label for="seachlabel">Show on Browse/Update:</label> ';
     422        echo '<select name="show_on_browse" id="show_on_browse">';
     423        if ($eav_fldupdate->show_on_browse == 'n')
     424            echo '<option value="y" >Yes</option><option value="n" selected>No</option>';
     425        else
     426            echo '<option value="y" selected>Yes</option><option value="n">No</option>';
     427        echo '</select><br>';
     428        echo '<input type="hidden" id="entity_attrib" name="entity_attrib" value="' . esc_html($eav_attrib1) . '">
    226429        <P>
    227430        <input type="submit" id="update" name="eav_submit" value="Update Field">
     
    235438        #today = current date
    236439        #user = current user
     440        #userid = current user id (wordpress id)
    237441        #now = current date/time
     442        %sql = uses SQL to find the default, based off sql setup
    238443        </PRE>';
    239444    } else {
     
    244449                $u_entity_format = strtolower(sanitize_mime_type($_POST['entity_format']));
    245450                $u_entity_default = strtolower(sanitize_text_field($_POST['entity_default']));
     451                $u_entity_input = strtolower(sanitize_text_field($_POST['input_format']));
     452                $u_show = strtolower(sanitize_text_field($_POST['show_on_browse']));
    246453                // sanitize_mime_type strips off the % (percent) sometimes so we just double check that
    247454                if ($u_entity_format[1] != "%")
    248455                    $u_entity_format = "%" . $u_entity_format;
    249456                $u_entity_desc = sanitize_text_field($_POST['entity_desc']);
    250                 $usql = sprintf("update " . $wpdb->base_prefix . "eav_attrib set entity_name='%s', entity_format='%s', entity_desc='%s', entity_default='%s' where  entity_attrib = %s"
    251                         ,$u_entity_name ,$u_entity_format,$u_entity_desc, $u_entity_default, $u_entity_attrib);
     457                $usql = sprintf("update " . $wpdb->base_prefix . "eav_attrib set entity_name='%s', entity_format='%s', entity_desc='%s', entity_default='%s', input_format='%s',show_on_browse='%s' where  entity_attrib = %s"
     458                        ,$u_entity_name ,$u_entity_format,$u_entity_desc, $u_entity_default, $u_entity_input, $u_show, $u_entity_attrib);
    252459               
    253460                //$prep = $wpdb->prepare ($usql);
     
    315522         <br> </form>';
    316523
    317         $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default from " . $wpdb->base_prefix . "eav_attrib ";
     524        $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format, show_on_browse from " . $wpdb->base_prefix . "eav_attrib ";
    318525        echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
    319526        echo '<tr >
     
    323530            <th style="border: 1px solid black"; onclick="eav_sortTable(3)">Description</th>
    324531            <th style="border: 1px solid black"; onclick="eav_sortTable(4)">Default</th>
     532            <th style="border: 1px solid black"; onclick="eav_sortTable(5)">Input Format</th>
     533            <th style="width: 60px; border: 1px solid black"; onclick="eav_sortTable(6)">Show on Browse</th>
    325534            </tr>
    326535        ';
     
    337546            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_desc) . '</td>';
    338547            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_default) . '</td>';
     548            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->input_format) . '</td>';
     549            echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->show_on_browse) . '</td>';
    339550            echo '</tr>';
    340551            $row_count = $row_count + 1;
     
    600811
    601812
    602 
    603813?>
  • brads-entity-attribute-value-database/trunk/includes/shortcodes.php

    r2504902 r2507785  
    77//eav_endadd - this ends the form and places a submit button
    88
     9function get_save_entity($t_entity = '') {
     10    static $gs_entity;
     11   
     12    if (!empty($t_entity)) {
     13        $gs_entity = $t_entity;
     14    }
     15    return $gs_entity;
     16}
     17
    918function eav_field($atts = [], $content = null) {
    1019    global $wpdb;
     
    1221    ob_start(); // this allows me to use echo instead of using concat all strings
    1322
     23    $tablename = get_save_entity();
     24    $tblsql = "select entity from " . $wpdb->base_prefix . "eav_tbl where tblname='" . $tablename . "'";
     25    $res1 = $wpdb->get_row($tblsql);
     26    $v_res1 = $res1->entity;
     27
    1428    $fieldname = sanitize_text_field($atts['field']);
    15     if (isset($atts['hidden'])) {
    16         if (sanitize_text_field($atts['hidden']) == "y")
    17             $typeval="hidden";
    18         else
    19             $typeval="text";
    20     }else {
    21         $typeval="text";
    22     }
    23     $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default from " . $wpdb->base_prefix . "eav_attrib where entity_name = '" . $fieldname . "'";
     29    $sql = "select entity_attrib, entity_name, entity_format, entity_desc, entity_default, input_format from " . $wpdb->base_prefix . "eav_attrib where entity_name = '" . $fieldname . "'";
    2430    $result_tbl = $wpdb->get_row($sql);
     31    // handle default
    2532    if (isset($result_tbl->entity_default))
    26         $default = eav_handle_defaults($result_tbl->entity_default);
     33        $default = eav_handle_defaults($result_tbl->entity_default, $v_res1, $result_tbl->entity_attrib);
    2734    else
    2835        $default = "";
     36    //handle format length
    2937    if (isset($result_tbl->entity_format))
    3038        $int = strlen(sprintf($result_tbl->entity_format, ""));
    3139    else
    3240        $int = 20; //default length
     41       
     42    // handle input type
     43    if (isset($atts['hidden'])) {
     44        if (sanitize_text_field($atts['hidden']) == "y")
     45            $typeval="hidden";
     46        else {
     47            if (isset($result_tbl->input_format))
     48                $typeval = $result_tbl->input_format;
     49            else
     50                $typeval = "text";
     51        }
     52    }else {
     53        if (isset($result_tbl->input_format))
     54            $typeval = $result_tbl->input_format;
     55        else
     56            $typeval = "text";
     57    }
     58
    3359    echo '&nbsp;<input type="' . $typeval . '" size="' . $int . '" name="' .  esc_html($fieldname) . '" id="' .  esc_html($fieldname) . '" value="' . $default . '" >';
    3460   
     
    6288        $v_entity = $result_tbl1->entity;
    6389        // find new row number
    64                 $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $v_entity;
     90                $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $v_entity . "and entity_type = 0";
    6591                $result_tbl1 =$wpdb->get_row($maxid);   
    6692                if (isset($result_tbl1->maxid))
     
    79105                // okay the field is in the post so we need to santize and insert results.
    80106                $eav_val_char = sanitize_text_field($_POST[$result_fld->entity_name]);
    81                 $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', 0, 0)"
     107                $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id , entity_type ) values (%s, %s, %s, '%s', 0, 0, 0)"
    82108                        , $v_entity , $v_entity_id , $v_entity_attrib , $eav_val_char );
    83109                $return = $wpdb->query($sql );
     
    122148            // so at this point loop_cnt has how many loops we need to make
    123149            for($i = 0; $i < $loop_cnt; $i++) {
    124                 $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $subv_entity;
     150                $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . $subv_entity . " and entity_type = 0";
    125151                $result_tbl1 =$wpdb->get_row($maxid);   
    126152                if (isset($result_tbl1->maxid))
     
    138164                        $fld_val = $fld_array[$i];
    139165
    140                         $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', %s, %s)"
     166                        $sql = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id, entity_type ) values (%s, %s, %s, '%s', %s, %s, 0)"
    141167                            , $subv_entity , $subv_entity_id , $subv_entity_attrib , $fld_val, $v_entity , $v_entity_id );
    142168                        $return = $wpdb->query($sql );
     
    156182    echo '<input type="hidden" id="eav_startadd" name="eav_startadd" value="eav_startadd">';
    157183   
     184    get_save_entity($tablename); // this saves table name so we can grab it if needed
     185   
    158186    $content = ob_get_contents();
    159187    ob_end_clean();
     
    195223        $v_entity = $result_tbl1->entity;
    196224        // find new row number
    197         $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . sanitize_text_field($v_entity);
     225        $maxid = "select max(entity_id) as maxid from " . $wpdb->base_prefix . "eav_entity where entity = " . sanitize_text_field($v_entity)  . " and entity_type = 0";
    198226        $result_tbl1 =$wpdb->get_row($maxid);
    199227        $v_entity_id = sanitize_text_field($result_tbl1->maxid) + 1;   
     
    210238               
    211239                $prep = $wpdb->prepare (
    212                 "INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char) values (%s, %s, %s, %s)"
     240                "INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, entity_type) values (%s, %s, %s, %s, 0)"
    213241                , $v_entity . ''
    214242                , $v_entity_id . ''
     
    254282    ob_start(); // this allows me to use echo instead of using concat all strings
    255283   
    256 
    257    
    258284   
    259285    $tablename = sanitize_text_field($atts['table']);
     
    278304       
    279305        echo 'var cell' . $cellno . ' = row.insertCell(' . ($cellno -1 ) . ');';
    280         echo 'cell'. $cellno . '.innerHTML = \'<input type="text"  size="' . $int . '" name="' . esc_html($element->entity_name) . '[]"/>\';';
     306        echo 'cell'. $cellno . '.innerHTML = \'<input type="text"  size="' . $int . '" name="' .
     307            esc_html($element->entity_name) . '[]"/>\';';
    281308        $cellno = $cellno + 1;
    282309        }
     
    287314    echo '<style>
    288315        table, th, td { border: 2px solid black;}
     316    </style>';
     317   
     318    // This allows us a horizontal scrollable grid
     319    echo '<style>
     320        .horizontal-snap {
     321            margin: 0 auto;
     322            display: grid;
     323            grid-auto-flow: column;
     324            gap: 1rem;
     325            padding: 1rem;
     326            overflow-y: auto;
     327            overscroll-behavior-x: contain;
     328            scroll-snap-type: x mandatory;
     329        }       
    289330        </style>';
    290331
     332    echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
    291333
    292334    echo '<table id="tbl-' . esc_html($tablename) . '">';
     
    304346        else
    305347            $int = 20;
     348        // need to handle defaults on subrecord field here
    306349        echo '<th style= "width: ' . $int . 'px" >' . esc_html($element->entity_name) . '</th>';
    307350    }
     
    322365    echo '</tr>';
    323366    echo '</table >';
     367    echo '</div>';  //end scroll
     368    echo '<P>';
    324369    echo '<input type="button" id="add-' . esc_html($tablename) . '" name="add-' . esc_html($tablename) . '" value="Add Row" onclick="MyAddRow' . esc_html($tablename)  . '()"/>';
    325 
     370    echo "<P>";
    326371   
    327372    $content = ob_get_contents();
     
    371416                    // need to first check if the value is there, if not we insert
    372417                    $sqlchk = "select count(*) as x from " . $wpdb->base_prefix . "eav_entity where entity=" . $v_entity . " and entity_id= " . $v_id .
    373                         " and entity_attrib=" . $v_attrib;
     418                        " and entity_attrib=" . $v_attrib  . " and entity_type = 0";
    374419                    $chkresult=$wpdb->get_row($sqlchk);
    375420                    if ($chkresult->x == 1) {
     
    378423                    } else {
    379424                        // need to find parent value down the road
    380                         $sqlupd = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id ) values (%s, %s, %s, '%s', 0,0)"
     425                        $sqlupd = sprintf("INSERT INTO " . $wpdb->base_prefix . "eav_entity (entity, entity_id, entity_attrib, val_char, parent_entity, parent_entity_id, entity_type ) values (%s, %s, %s, '%s', 0,0, 0)"
    381426                            , $v_entity , $v_id , $v_attrib , $val );
    382427                    }                       
     
    393438            exit;
    394439        }
    395         if (isset($atts['allowadd']))
    396             $allowadd = sanitize_text_field($atts['allowadd']);
    397         else
    398             $allowadd = "";
    399            
    400         if (isset($atts['allowupd']))
    401             $allowupd = sanitize_text_field($atts['allowupd']);
    402         else
    403             $allowupd = "";
    404        
    405        
     440        $allowadd = "";
     441        $allowupd = "";
     442        if (isset($atts['0'])) {
     443            $value = sanitize_text_field($atts['0']);
     444            if($value == "allowadd")
     445                $allowadd = "y";
     446            if($value == "allowupd")
     447                $allowupd = "y";
     448        }
     449           
     450
    406451        // get table id #
    407452        $tblid = "select entity, tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl where tblname = '" . $tablename . "'";
     
    416461                    " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b where a.entity = " . sanitize_text_field($result_tbl->entity) .
    417462                    " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " .
    418                     " and a.entity_id in (select distinct entity_id from " . $wpdb->base_prefix . "eav_entity where val_char like '%" . $lookfor . "%' )" .
     463                    " and a.entity_type = 0 " .
     464                    " and a.entity_id in (select distinct entity_id from " . $wpdb->base_prefix . "eav_entity where val_char like '%" . $lookfor . "%' and entity_type = 0 )" .
    419465                    "  order by entity_id,b.entity_order ";
    420466            } else {
     
    423469                        " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    424470                        " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) .
     471                        " and a.entity_type = 0 " .
    425472                        " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    426473            }
     
    430477            " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    431478            " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) .
     479            " and a.entity_type = 0 " .
    432480            " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    433481        }
     
    448496        echo '</table>';
    449497   
     498        // This allows us a horizontal scrollable grid
     499        echo '<style>
     500        .horizontal-snap {         
     501            display: grid;
     502            grid-auto-flow: column;
     503            overflow-y: auto;
     504            overscroll-behavior-x: contain;
     505            scroll-snap-type: x mandatory;
     506        }       
     507        </style>'; 
     508   
    450509        //show all database fields in table
    451         $hsql = "select a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, " .
     510        $hsql = "select a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, a.show_on_browse, " .
    452511            " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " .
    453512            " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . ' order by b.entity_order' ;
    454513        $results = $wpdb->get_results($hsql);
    455         echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
     514        echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
     515        echo '<table style="margin-left: auto; margin-right: auto; border: 1px solid black" id="myTable" >';
    456516        echo '<tr ><th></th>';
    457517        $colid = 0;
    458518        foreach($results as $element) {
    459519            $int = strlen(sprintf($element->entity_format, ""));
     520           
    460521            //echo '<th style="width: ' . $int . 'px; border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
    461             echo '<th style="border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
    462             $colid = $colid + 1;
     522            //check if we want to show data
     523            if ( $element->show_on_browse != "n" ) {
     524                echo '<th style="border: 1px solid black"; onclick="eav_sortTable(' . $colid . ')">' . esc_html($element->entity_desc) . '</th>';
     525                $colid = $colid + 1;
     526            }
    463527        }
    464528        echo '</tr>';
    465529        $new_row = 0;
    466530   
    467         $sql="select max(entity_order) as max from " . $wpdb->base_prefix . "eav_layout where entity = " . sanitize_text_field($result_tbl->entity);
    468         $result_tbl =$wpdb->get_row($sql);
    469         $max_col = $result_tbl->max;
     531        //$sql="select max(entity_order) as max from " . $wpdb->base_prefix . "eav_layout where entity = " . sanitize_text_field($result_tbl->entity);
     532        //$result_tbl =$wpdb->get_row($sql);
     533        //$max_col = $result_tbl->max;
     534        $max_col = $colid;
    470535   
    471536        $sql_limit_q = $sql_limit * $colid;
     
    476541        echo "<tr>";
    477542        foreach($results as $element) {
    478             if (( $new_row <> sanitize_text_field($element->entity_id)) && ( $new_row <> 0)) {
     543            // determine if we want to show based on show_on_browse
     544            $sql_show="select show_on_browse from " . $wpdb->base_prefix . "eav_attrib where entity_attrib = " . $element->entity_attrib;
     545            $show = $wpdb->get_row($sql_show);
     546            if ($show->show_on_browse != "n") {
     547             if (( $new_row <> sanitize_text_field($element->entity_id)) && ( $new_row <> 0)) {
    479548                //finish out row if no data
    480549                for($ii = $colno; $ii < $max_col; $ii++) {
     
    497566                    echo '</td>';
    498567                }
    499             } else if (($colno == 1)&& ($new_row == 0)) { // first time
     568             } else if (($colno == 1)&& ($new_row == 0)) { // first time
    500569                if ($allowupd != "y") {
    501570                    echo '<td style="border: 1px solid black">';
     
    510579                    echo '</td>';
    511580                }
    512             }
    513             $new_row = sanitize_text_field($element->entity_id);
    514             $newcol = sanitize_text_field($element->entity_order);
    515             if ($newcol != ($colno +1)) {
     581             }
     582           
     583             $new_row = sanitize_text_field($element->entity_id);
     584             $newcol = sanitize_text_field($element->entity_order);
     585             if ($newcol != ($colno +1)) {
    516586                // missing columns
    517587                for($ii = ($colno +1); $ii < $newcol; $ii++)
    518588                    echo '<td style="border: 1px solid black"></td>';
    519             }                   
    520             echo '<td style="border: 1px solid black">';
    521             echo esc_html($element->val_char) . '</td>';
    522             $colno = $newcol;
     589             }                 
     590             echo '<td style="border: 1px solid black">';
     591             echo esc_html($element->val_char) . '</td>';
     592             $colno = $newcol;
     593            }
    523594        }
    524595        //Finish out last row
     
    527598   
    528599        echo '</tr></table>';
    529 
     600        echo '</div>'; // this ends makes row horizontal scrollable
    530601        $content = ob_get_contents();
    531602        ob_end_clean();
     
    545616    echo '<form action="" method="post">' ;
    546617    //show all database fields in table
    547     $hsql = "select  a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, " .
     618    $hsql = "select  a.entity_desc, a.entity_name, a.entity_attrib, a.entity_format, a.input_format, a.show_on_browse, " .
    548619        " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " .
    549620        " where a.entity_attrib=b.entity_attrib " .
     
    554625       
    555626        $vsql="select val_char from " . $wpdb->base_prefix . "eav_entity where entity=" . $v_entity .
    556             " and entity_id = " . $v_id . " and entity_attrib = " . $element->entity_attrib;
     627            " and entity_id = " . $v_id . " and entity_attrib = " . $element->entity_attrib  . " and entity_type = 0";
    557628        $v_results = $wpdb->get_row($vsql);
    558629        if (isset($v_results->val_char))
     
    560631        else
    561632            $val = "";
    562         echo '<input type="text" name="' . esc_html($element->entity_attrib) . '" size="50" ' . $update ;
     633       
     634        if (isset($element->input_format))
     635            $typeval = $element->input_format;
     636        else
     637            $typeval = "text";
     638
     639        echo '<input type="' . $typeval . '" name="' . esc_html($element->entity_attrib) . '" size="50" ' . $update ;
    563640        echo ' value="' . esc_html($val) . '" >';
    564641        echo '<br>';
     
    573650        // show child records - $v_entity, $v_id
    574651        // get child records
     652       
     653        // This allows us a horizontal scrollable grid
     654        echo '<style>
     655        .horizontal-snap {
     656            margin: 0 auto;
     657            display: grid;
     658            grid-auto-flow: column;
     659            gap: 1rem;
     660            padding: 1rem;
     661            overflow-y: auto;
     662            overscroll-behavior-x: contain;
     663            scroll-snap-type: x mandatory;
     664        }       
     665        </style>'; 
     666       
    575667        $c1sql= "select entity, tblname from " . $wpdb->base_prefix . "eav_tbl where parent_entity = " . $v_entity ;
    576668        $result_tbl = $wpdb->get_row($c1sql);
     
    583675                " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity . ' order by b.entity_order' ;
    584676            $results = $wpdb->get_results($hsql);
     677            echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable
    585678            echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >';
    586679            echo '<tr ><th style="border: 1px solid black"></th>';  // first column is for view data
     
    599692            " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " .
    600693            " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity .
    601             " and a.parent_entity = " .  $v_entity . " and a.parent_entity_id = " . $v_id .
     694            " and a.parent_entity = " .  $v_entity . " and a.parent_entity_id = " . $v_id . " and a.entity_type = 0 " .
    602695            " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ;
    603696
     
    638731   
    639732            echo '</tr></table>';
    640 
    641        
    642             $c2sql = "select entity, entity_id, entity_attrib, val_cha, parent_entity, parent_entity_id
    643                 from " . $wpdb->base_prefix . "eav_entity where parent_entity = " . $v_entity .
    644                 " and parent_entity_id = " . $v_id;
    645             echo '<a href="javascript:history.back()">Go Back</a>';
     733            echo '</div>'; // end of this makes row horizontal scrollable
    646734        }
    647735    }
     736    echo '<P><a href="javascript:history.back()">Go Back</a>';
    648737}
    649738
  • brads-entity-attribute-value-database/trunk/readme.txt

    r2504902 r2507785  
    66Author: Bradley Smith
    77Requires PHP: 7.0
    8 Requires at least: 5.7
    9 Tested up to: 5.7
    10 Stable tag: 2.06
    11 Version: 2.06
     8Requires at least: 5.6
     9Tested up to: 5.6
     10Stable tag: 2.07
     11Version: 2.07
    1212License: GPLv2 or later
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3636    Mange Attributes - This is where you will define your fields
    3737    Manage Record Layout - This is where you will define what fields are in each of your records
     38    SQL Default - This is where you will define sql for defaulting values
    3839
    3940shortcodes - standalone
     
    7980
    8081== Changelog ==
     82
     83= v2.07 [4/1/2021]
     84* added being able to default field values via SQL
     85* subrecords and table view now have scroll bar if the screen is not large enough
     86* tested on older version of wordpress
     87
    8188= v2.06 [3/28/2021]
    8289* bug fixes on shortcodes for eav_tbl and eav_subrec
  • brads-entity-attribute-value-database/trunk/uninstall.php

    r2504282 r2507785  
    66    remove_shortcode('eav_endadd');
    77    remove_shortcode('eav_add');
     8    remove_shortcode('eav_field');
     9    remove_shortcode('eav_subrec');
    810
    911    //execute the query deleting the table
     
    2729    $wpdb->show_errors();
    2830    $wpdb->flush();
    29 
    30 //  $sql = "select id from wp_posts where post_name = 'jira-import';";
    31 //  $my_id = $wpdb->get_var($sql);
    32 //  wp_delete_post( $my_id, true );
    33 //  wp_trash_post( $my_id );   
    34 
    35     //remove_submenu_page('eav_manage_tbl');  // value from the add_submenu slug
    36     //remove_submenu_page('eav_manage_attrib'); // value from the add_submenu slug
     31   
    3732    remove_menu_page( 'eav_main_menu');
    38 
    39     //wp_redirect('/wp-admin/plugins.php');
    4033?>
Note: See TracChangeset for help on using the changeset viewer.