Changeset 2507785
- Timestamp:
- 04/02/2021 01:23:29 AM (5 years ago)
- Location:
- brads-entity-attribute-value-database
- Files:
-
- 5 edited
- 7 copied
-
tags/2.07 (copied) (copied from brads-entity-attribute-value-database/trunk)
-
tags/2.07/entity-attribute-value-database.php (copied) (copied from brads-entity-attribute-value-database/trunk/entity-attribute-value-database.php) (6 diffs)
-
tags/2.07/includes (copied) (copied from brads-entity-attribute-value-database/trunk/includes)
-
tags/2.07/includes/admin_menu.php (copied) (copied from brads-entity-attribute-value-database/trunk/includes/admin_menu.php) (10 diffs)
-
tags/2.07/includes/shortcodes.php (copied) (copied from brads-entity-attribute-value-database/trunk/includes/shortcodes.php) (32 diffs)
-
tags/2.07/readme.txt (copied) (copied from brads-entity-attribute-value-database/trunk/readme.txt) (3 diffs)
-
tags/2.07/uninstall.php (copied) (copied from brads-entity-attribute-value-database/trunk/uninstall.php) (2 diffs)
-
trunk/entity-attribute-value-database.php (modified) (6 diffs)
-
trunk/includes/admin_menu.php (modified) (10 diffs)
-
trunk/includes/shortcodes.php (modified) (32 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/uninstall.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
brads-entity-attribute-value-database/tags/2.07/entity-attribute-value-database.php
r2504902 r2507785 4 4 * Plugin URI: http://mobilebsmith.hopto.org 5 5 * Description: Brad's Entity Attribute Value Database 6 * Version: 2.0 66 * Version: 2.07 7 7 * Author: Bradley Smith 8 8 * Author URI: http://mobilebsmith.hopto.org 9 9 **/ 10 10 11 11 //entity_type defines - don't change 12 define("EAV_REC_FLD", 0); // this shows the value is record/field information 13 define("EAV_SQL", 2); // this shows the value is sql for default field handling 12 14 13 15 register_activation_hook( __FILE__, 'eav_import_init' ); … … 27 29 28 30 $sql2 = "CREATE TABLE " . $wpdb->base_prefix . "eav_entity ( 31 entity_type int, 29 32 entity int, 30 33 entity_id int, 31 34 entity_attrib int, 32 val_char varchar(128),35 val_char text, 33 36 parent_entity int, 34 37 parent_entity_id int, 35 PRIMARY KEY(entity ,entity_id, entity_attrib)38 PRIMARY KEY(entity_type ,entity, entity_id, entity_attrib) 36 39 )"; 37 40 dbDelta( $sql2 ); … … 46 49 entity_desc varchar(256), 47 50 entity_default varchar(256), 51 input_format varchar(32), 52 show_on_browse varchar(1), 48 53 PRIMARY KEY (entity_attrib, entity_name ) 49 54 )"; … … 66 71 )"; 67 72 dbDelta( $sql2 ); 73 68 74 69 75 } … … 74 80 75 81 76 function eav_handle_defaults($value) { 82 // expands #xxxx values in string 83 function 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 } 99 function 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 } 121 function eav_handle_defaults($value, $v_entity, $v_attrib) { 77 122 global $wpdb; 78 123 global $wp; … … 80 125 $current_user = wp_get_current_user(); 81 126 $return = ""; 127 82 128 switch($value) { 83 129 case "#user"; 84 130 $return = $current_user->user_login; 85 131 break; 132 case "#userid"; 133 $return = $current_user->ID; 134 break; 86 135 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 = ""; 91 147 break; 92 148 } -
brads-entity-attribute-value-database/tags/2.07/includes/admin_menu.php
r2504873 r2507785 1 1 <?php 2 3 if (defined('EAV_SQL') == false) { 4 define("EAV_SQL", 0); // this shows the value is record/field information 5 } 6 7 2 8 3 9 function eav_main_page(){ … … 65 71 add_submenu_page( $menu_slug, 'Manage Record Layout', 'Manage Record Layout' 66 72 , '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); 67 83 68 84 } 69 85 86 function 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> <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> <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: </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 226 function 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 } 70 248 71 249 function eav_manage_tbl(){ … … 209 387 $eav_attrib1 = sanitize_text_field($_GET['entity_attribute']); 210 388 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 " . 212 390 " from " . $wpdb->base_prefix . "eav_attrib " . 213 391 " where entity_attrib = " . $eav_attrib1; … … 223 401 <input type="text" id="entity_default" name="entity_default" size="64" value = "' . esc_html($eav_fldupdate->entity_default) . '" ><br> 224 402 <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) . '"> 226 429 <P> 227 430 <input type="submit" id="update" name="eav_submit" value="Update Field"> … … 235 438 #today = current date 236 439 #user = current user 440 #userid = current user id (wordpress id) 237 441 #now = current date/time 442 %sql = uses SQL to find the default, based off sql setup 238 443 </PRE>'; 239 444 } else { … … 244 449 $u_entity_format = strtolower(sanitize_mime_type($_POST['entity_format'])); 245 450 $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'])); 246 453 // sanitize_mime_type strips off the % (percent) sometimes so we just double check that 247 454 if ($u_entity_format[1] != "%") 248 455 $u_entity_format = "%" . $u_entity_format; 249 456 $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); 252 459 253 460 //$prep = $wpdb->prepare ($usql); … … 315 522 <br> </form>'; 316 523 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 "; 318 525 echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >'; 319 526 echo '<tr > … … 323 530 <th style="border: 1px solid black"; onclick="eav_sortTable(3)">Description</th> 324 531 <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> 325 534 </tr> 326 535 '; … … 337 546 echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_desc) . '</td>'; 338 547 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>'; 339 550 echo '</tr>'; 340 551 $row_count = $row_count + 1; … … 600 811 601 812 602 603 813 ?> -
brads-entity-attribute-value-database/tags/2.07/includes/shortcodes.php
r2504902 r2507785 7 7 //eav_endadd - this ends the form and places a submit button 8 8 9 function 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 9 18 function eav_field($atts = [], $content = null) { 10 19 global $wpdb; … … 12 21 ob_start(); // this allows me to use echo instead of using concat all strings 13 22 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 14 28 $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 . "'"; 24 30 $result_tbl = $wpdb->get_row($sql); 31 // handle default 25 32 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); 27 34 else 28 35 $default = ""; 36 //handle format length 29 37 if (isset($result_tbl->entity_format)) 30 38 $int = strlen(sprintf($result_tbl->entity_format, "")); 31 39 else 32 40 $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 33 59 echo ' <input type="' . $typeval . '" size="' . $int . '" name="' . esc_html($fieldname) . '" id="' . esc_html($fieldname) . '" value="' . $default . '" >'; 34 60 … … 62 88 $v_entity = $result_tbl1->entity; 63 89 // 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"; 65 91 $result_tbl1 =$wpdb->get_row($maxid); 66 92 if (isset($result_tbl1->maxid)) … … 79 105 // okay the field is in the post so we need to santize and insert results. 80 106 $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)" 82 108 , $v_entity , $v_entity_id , $v_entity_attrib , $eav_val_char ); 83 109 $return = $wpdb->query($sql ); … … 122 148 // so at this point loop_cnt has how many loops we need to make 123 149 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"; 125 151 $result_tbl1 =$wpdb->get_row($maxid); 126 152 if (isset($result_tbl1->maxid)) … … 138 164 $fld_val = $fld_array[$i]; 139 165 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)" 141 167 , $subv_entity , $subv_entity_id , $subv_entity_attrib , $fld_val, $v_entity , $v_entity_id ); 142 168 $return = $wpdb->query($sql ); … … 156 182 echo '<input type="hidden" id="eav_startadd" name="eav_startadd" value="eav_startadd">'; 157 183 184 get_save_entity($tablename); // this saves table name so we can grab it if needed 185 158 186 $content = ob_get_contents(); 159 187 ob_end_clean(); … … 195 223 $v_entity = $result_tbl1->entity; 196 224 // 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"; 198 226 $result_tbl1 =$wpdb->get_row($maxid); 199 227 $v_entity_id = sanitize_text_field($result_tbl1->maxid) + 1; … … 210 238 211 239 $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)" 213 241 , $v_entity . '' 214 242 , $v_entity_id . '' … … 254 282 ob_start(); // this allows me to use echo instead of using concat all strings 255 283 256 257 258 284 259 285 $tablename = sanitize_text_field($atts['table']); … … 278 304 279 305 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) . '[]"/>\';'; 281 308 $cellno = $cellno + 1; 282 309 } … … 287 314 echo '<style> 288 315 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 } 289 330 </style>'; 290 331 332 echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable 291 333 292 334 echo '<table id="tbl-' . esc_html($tablename) . '">'; … … 304 346 else 305 347 $int = 20; 348 // need to handle defaults on subrecord field here 306 349 echo '<th style= "width: ' . $int . 'px" >' . esc_html($element->entity_name) . '</th>'; 307 350 } … … 322 365 echo '</tr>'; 323 366 echo '</table >'; 367 echo '</div>'; //end scroll 368 echo '<P>'; 324 369 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>"; 326 371 327 372 $content = ob_get_contents(); … … 371 416 // need to first check if the value is there, if not we insert 372 417 $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"; 374 419 $chkresult=$wpdb->get_row($sqlchk); 375 420 if ($chkresult->x == 1) { … … 378 423 } else { 379 424 // 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)" 381 426 , $v_entity , $v_id , $v_attrib , $val ); 382 427 } … … 393 438 exit; 394 439 } 395 if (isset($atts['allowadd']))396 $allowadd = sanitize_text_field($atts['allowadd']);397 else398 $ allowadd = "";399 400 if (isset($atts['allowupd']))401 $allowupd = sanitize_text_field($atts['allowupd']);402 else403 $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 406 451 // get table id # 407 452 $tblid = "select entity, tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl where tblname = '" . $tablename . "'"; … … 416 461 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b where a.entity = " . sanitize_text_field($result_tbl->entity) . 417 462 " 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 )" . 419 465 " order by entity_id,b.entity_order "; 420 466 } else { … … 423 469 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 424 470 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . 471 " and a.entity_type = 0 " . 425 472 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 426 473 } … … 430 477 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 431 478 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . 479 " and a.entity_type = 0 " . 432 480 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 433 481 } … … 448 496 echo '</table>'; 449 497 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 450 509 //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, " . 452 511 " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " . 453 512 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . ' order by b.entity_order' ; 454 513 $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" >'; 456 516 echo '<tr ><th></th>'; 457 517 $colid = 0; 458 518 foreach($results as $element) { 459 519 $int = strlen(sprintf($element->entity_format, "")); 520 460 521 //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 } 463 527 } 464 528 echo '</tr>'; 465 529 $new_row = 0; 466 530 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; 470 535 471 536 $sql_limit_q = $sql_limit * $colid; … … 476 541 echo "<tr>"; 477 542 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)) { 479 548 //finish out row if no data 480 549 for($ii = $colno; $ii < $max_col; $ii++) { … … 497 566 echo '</td>'; 498 567 } 499 } else if (($colno == 1)&& ($new_row == 0)) { // first time568 } else if (($colno == 1)&& ($new_row == 0)) { // first time 500 569 if ($allowupd != "y") { 501 570 echo '<td style="border: 1px solid black">'; … … 510 579 echo '</td>'; 511 580 } 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)) { 516 586 // missing columns 517 587 for($ii = ($colno +1); $ii < $newcol; $ii++) 518 588 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 } 523 594 } 524 595 //Finish out last row … … 527 598 528 599 echo '</tr></table>'; 529 600 echo '</div>'; // this ends makes row horizontal scrollable 530 601 $content = ob_get_contents(); 531 602 ob_end_clean(); … … 545 616 echo '<form action="" method="post">' ; 546 617 //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, " . 548 619 " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " . 549 620 " where a.entity_attrib=b.entity_attrib " . … … 554 625 555 626 $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"; 557 628 $v_results = $wpdb->get_row($vsql); 558 629 if (isset($v_results->val_char)) … … 560 631 else 561 632 $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 ; 563 640 echo ' value="' . esc_html($val) . '" >'; 564 641 echo '<br>'; … … 573 650 // show child records - $v_entity, $v_id 574 651 // 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 575 667 $c1sql= "select entity, tblname from " . $wpdb->base_prefix . "eav_tbl where parent_entity = " . $v_entity ; 576 668 $result_tbl = $wpdb->get_row($c1sql); … … 583 675 " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity . ' order by b.entity_order' ; 584 676 $results = $wpdb->get_results($hsql); 677 echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable 585 678 echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >'; 586 679 echo '<tr ><th style="border: 1px solid black"></th>'; // first column is for view data … … 599 692 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 600 693 " 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 " . 602 695 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 603 696 … … 638 731 639 732 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 646 734 } 647 735 } 736 echo '<P><a href="javascript:history.back()">Go Back</a>'; 648 737 } 649 738 -
brads-entity-attribute-value-database/tags/2.07/readme.txt
r2504902 r2507785 6 6 Author: Bradley Smith 7 7 Requires PHP: 7.0 8 Requires at least: 5. 79 Tested up to: 5. 710 Stable tag: 2.0 611 Version: 2.0 68 Requires at least: 5.6 9 Tested up to: 5.6 10 Stable tag: 2.07 11 Version: 2.07 12 12 License: GPLv2 or later 13 13 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 36 36 Mange Attributes - This is where you will define your fields 37 37 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 38 39 39 40 shortcodes - standalone … … 79 80 80 81 == 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 81 88 = v2.06 [3/28/2021] 82 89 * bug fixes on shortcodes for eav_tbl and eav_subrec -
brads-entity-attribute-value-database/tags/2.07/uninstall.php
r2504282 r2507785 6 6 remove_shortcode('eav_endadd'); 7 7 remove_shortcode('eav_add'); 8 remove_shortcode('eav_field'); 9 remove_shortcode('eav_subrec'); 8 10 9 11 //execute the query deleting the table … … 27 29 $wpdb->show_errors(); 28 30 $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 37 32 remove_menu_page( 'eav_main_menu'); 38 39 //wp_redirect('/wp-admin/plugins.php');40 33 ?> -
brads-entity-attribute-value-database/trunk/entity-attribute-value-database.php
r2504902 r2507785 4 4 * Plugin URI: http://mobilebsmith.hopto.org 5 5 * Description: Brad's Entity Attribute Value Database 6 * Version: 2.0 66 * Version: 2.07 7 7 * Author: Bradley Smith 8 8 * Author URI: http://mobilebsmith.hopto.org 9 9 **/ 10 10 11 11 //entity_type defines - don't change 12 define("EAV_REC_FLD", 0); // this shows the value is record/field information 13 define("EAV_SQL", 2); // this shows the value is sql for default field handling 12 14 13 15 register_activation_hook( __FILE__, 'eav_import_init' ); … … 27 29 28 30 $sql2 = "CREATE TABLE " . $wpdb->base_prefix . "eav_entity ( 31 entity_type int, 29 32 entity int, 30 33 entity_id int, 31 34 entity_attrib int, 32 val_char varchar(128),35 val_char text, 33 36 parent_entity int, 34 37 parent_entity_id int, 35 PRIMARY KEY(entity ,entity_id, entity_attrib)38 PRIMARY KEY(entity_type ,entity, entity_id, entity_attrib) 36 39 )"; 37 40 dbDelta( $sql2 ); … … 46 49 entity_desc varchar(256), 47 50 entity_default varchar(256), 51 input_format varchar(32), 52 show_on_browse varchar(1), 48 53 PRIMARY KEY (entity_attrib, entity_name ) 49 54 )"; … … 66 71 )"; 67 72 dbDelta( $sql2 ); 73 68 74 69 75 } … … 74 80 75 81 76 function eav_handle_defaults($value) { 82 // expands #xxxx values in string 83 function 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 } 99 function 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 } 121 function eav_handle_defaults($value, $v_entity, $v_attrib) { 77 122 global $wpdb; 78 123 global $wp; … … 80 125 $current_user = wp_get_current_user(); 81 126 $return = ""; 127 82 128 switch($value) { 83 129 case "#user"; 84 130 $return = $current_user->user_login; 85 131 break; 132 case "#userid"; 133 $return = $current_user->ID; 134 break; 86 135 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 = ""; 91 147 break; 92 148 } -
brads-entity-attribute-value-database/trunk/includes/admin_menu.php
r2504873 r2507785 1 1 <?php 2 3 if (defined('EAV_SQL') == false) { 4 define("EAV_SQL", 0); // this shows the value is record/field information 5 } 6 7 2 8 3 9 function eav_main_page(){ … … 65 71 add_submenu_page( $menu_slug, 'Manage Record Layout', 'Manage Record Layout' 66 72 , '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); 67 83 68 84 } 69 85 86 function 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> <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> <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: </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 226 function 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 } 70 248 71 249 function eav_manage_tbl(){ … … 209 387 $eav_attrib1 = sanitize_text_field($_GET['entity_attribute']); 210 388 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 " . 212 390 " from " . $wpdb->base_prefix . "eav_attrib " . 213 391 " where entity_attrib = " . $eav_attrib1; … … 223 401 <input type="text" id="entity_default" name="entity_default" size="64" value = "' . esc_html($eav_fldupdate->entity_default) . '" ><br> 224 402 <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) . '"> 226 429 <P> 227 430 <input type="submit" id="update" name="eav_submit" value="Update Field"> … … 235 438 #today = current date 236 439 #user = current user 440 #userid = current user id (wordpress id) 237 441 #now = current date/time 442 %sql = uses SQL to find the default, based off sql setup 238 443 </PRE>'; 239 444 } else { … … 244 449 $u_entity_format = strtolower(sanitize_mime_type($_POST['entity_format'])); 245 450 $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'])); 246 453 // sanitize_mime_type strips off the % (percent) sometimes so we just double check that 247 454 if ($u_entity_format[1] != "%") 248 455 $u_entity_format = "%" . $u_entity_format; 249 456 $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); 252 459 253 460 //$prep = $wpdb->prepare ($usql); … … 315 522 <br> </form>'; 316 523 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 "; 318 525 echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >'; 319 526 echo '<tr > … … 323 530 <th style="border: 1px solid black"; onclick="eav_sortTable(3)">Description</th> 324 531 <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> 325 534 </tr> 326 535 '; … … 337 546 echo '<td style="border: 1px solid black; vertical-align: top; padding: 0px;">' . esc_html($element->entity_desc) . '</td>'; 338 547 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>'; 339 550 echo '</tr>'; 340 551 $row_count = $row_count + 1; … … 600 811 601 812 602 603 813 ?> -
brads-entity-attribute-value-database/trunk/includes/shortcodes.php
r2504902 r2507785 7 7 //eav_endadd - this ends the form and places a submit button 8 8 9 function 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 9 18 function eav_field($atts = [], $content = null) { 10 19 global $wpdb; … … 12 21 ob_start(); // this allows me to use echo instead of using concat all strings 13 22 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 14 28 $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 . "'"; 24 30 $result_tbl = $wpdb->get_row($sql); 31 // handle default 25 32 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); 27 34 else 28 35 $default = ""; 36 //handle format length 29 37 if (isset($result_tbl->entity_format)) 30 38 $int = strlen(sprintf($result_tbl->entity_format, "")); 31 39 else 32 40 $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 33 59 echo ' <input type="' . $typeval . '" size="' . $int . '" name="' . esc_html($fieldname) . '" id="' . esc_html($fieldname) . '" value="' . $default . '" >'; 34 60 … … 62 88 $v_entity = $result_tbl1->entity; 63 89 // 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"; 65 91 $result_tbl1 =$wpdb->get_row($maxid); 66 92 if (isset($result_tbl1->maxid)) … … 79 105 // okay the field is in the post so we need to santize and insert results. 80 106 $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)" 82 108 , $v_entity , $v_entity_id , $v_entity_attrib , $eav_val_char ); 83 109 $return = $wpdb->query($sql ); … … 122 148 // so at this point loop_cnt has how many loops we need to make 123 149 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"; 125 151 $result_tbl1 =$wpdb->get_row($maxid); 126 152 if (isset($result_tbl1->maxid)) … … 138 164 $fld_val = $fld_array[$i]; 139 165 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)" 141 167 , $subv_entity , $subv_entity_id , $subv_entity_attrib , $fld_val, $v_entity , $v_entity_id ); 142 168 $return = $wpdb->query($sql ); … … 156 182 echo '<input type="hidden" id="eav_startadd" name="eav_startadd" value="eav_startadd">'; 157 183 184 get_save_entity($tablename); // this saves table name so we can grab it if needed 185 158 186 $content = ob_get_contents(); 159 187 ob_end_clean(); … … 195 223 $v_entity = $result_tbl1->entity; 196 224 // 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"; 198 226 $result_tbl1 =$wpdb->get_row($maxid); 199 227 $v_entity_id = sanitize_text_field($result_tbl1->maxid) + 1; … … 210 238 211 239 $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)" 213 241 , $v_entity . '' 214 242 , $v_entity_id . '' … … 254 282 ob_start(); // this allows me to use echo instead of using concat all strings 255 283 256 257 258 284 259 285 $tablename = sanitize_text_field($atts['table']); … … 278 304 279 305 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) . '[]"/>\';'; 281 308 $cellno = $cellno + 1; 282 309 } … … 287 314 echo '<style> 288 315 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 } 289 330 </style>'; 290 331 332 echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable 291 333 292 334 echo '<table id="tbl-' . esc_html($tablename) . '">'; … … 304 346 else 305 347 $int = 20; 348 // need to handle defaults on subrecord field here 306 349 echo '<th style= "width: ' . $int . 'px" >' . esc_html($element->entity_name) . '</th>'; 307 350 } … … 322 365 echo '</tr>'; 323 366 echo '</table >'; 367 echo '</div>'; //end scroll 368 echo '<P>'; 324 369 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>"; 326 371 327 372 $content = ob_get_contents(); … … 371 416 // need to first check if the value is there, if not we insert 372 417 $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"; 374 419 $chkresult=$wpdb->get_row($sqlchk); 375 420 if ($chkresult->x == 1) { … … 378 423 } else { 379 424 // 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)" 381 426 , $v_entity , $v_id , $v_attrib , $val ); 382 427 } … … 393 438 exit; 394 439 } 395 if (isset($atts['allowadd']))396 $allowadd = sanitize_text_field($atts['allowadd']);397 else398 $ allowadd = "";399 400 if (isset($atts['allowupd']))401 $allowupd = sanitize_text_field($atts['allowupd']);402 else403 $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 406 451 // get table id # 407 452 $tblid = "select entity, tblname, tbldescr from " . $wpdb->base_prefix . "eav_tbl where tblname = '" . $tablename . "'"; … … 416 461 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b where a.entity = " . sanitize_text_field($result_tbl->entity) . 417 462 " 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 )" . 419 465 " order by entity_id,b.entity_order "; 420 466 } else { … … 423 469 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 424 470 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . 471 " and a.entity_type = 0 " . 425 472 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 426 473 } … … 430 477 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 431 478 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . 479 " and a.entity_type = 0 " . 432 480 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 433 481 } … … 448 496 echo '</table>'; 449 497 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 450 509 //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, " . 452 511 " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " . 453 512 " where a.entity_attrib=b.entity_attrib and b.entity = " . sanitize_text_field($result_tbl->entity) . ' order by b.entity_order' ; 454 513 $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" >'; 456 516 echo '<tr ><th></th>'; 457 517 $colid = 0; 458 518 foreach($results as $element) { 459 519 $int = strlen(sprintf($element->entity_format, "")); 520 460 521 //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 } 463 527 } 464 528 echo '</tr>'; 465 529 $new_row = 0; 466 530 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; 470 535 471 536 $sql_limit_q = $sql_limit * $colid; … … 476 541 echo "<tr>"; 477 542 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)) { 479 548 //finish out row if no data 480 549 for($ii = $colno; $ii < $max_col; $ii++) { … … 497 566 echo '</td>'; 498 567 } 499 } else if (($colno == 1)&& ($new_row == 0)) { // first time568 } else if (($colno == 1)&& ($new_row == 0)) { // first time 500 569 if ($allowupd != "y") { 501 570 echo '<td style="border: 1px solid black">'; … … 510 579 echo '</td>'; 511 580 } 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)) { 516 586 // missing columns 517 587 for($ii = ($colno +1); $ii < $newcol; $ii++) 518 588 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 } 523 594 } 524 595 //Finish out last row … … 527 598 528 599 echo '</tr></table>'; 529 600 echo '</div>'; // this ends makes row horizontal scrollable 530 601 $content = ob_get_contents(); 531 602 ob_end_clean(); … … 545 616 echo '<form action="" method="post">' ; 546 617 //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, " . 548 619 " b.entity_order from " . $wpdb->base_prefix . "eav_attrib a, " . $wpdb->base_prefix . "eav_layout b " . 549 620 " where a.entity_attrib=b.entity_attrib " . … … 554 625 555 626 $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"; 557 628 $v_results = $wpdb->get_row($vsql); 558 629 if (isset($v_results->val_char)) … … 560 631 else 561 632 $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 ; 563 640 echo ' value="' . esc_html($val) . '" >'; 564 641 echo '<br>'; … … 573 650 // show child records - $v_entity, $v_id 574 651 // 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 575 667 $c1sql= "select entity, tblname from " . $wpdb->base_prefix . "eav_tbl where parent_entity = " . $v_entity ; 576 668 $result_tbl = $wpdb->get_row($c1sql); … … 583 675 " where a.entity_attrib=b.entity_attrib and b.entity = " . $vc_entity . ' order by b.entity_order' ; 584 676 $results = $wpdb->get_results($hsql); 677 echo '<div class="horizontal-snap">'; // this makes row horizontal scrollable 585 678 echo '<table style="margin-left: auto; margin-right: auto; width: 80%; border: 1px solid black" id="myTable" >'; 586 679 echo '<tr ><th style="border: 1px solid black"></th>'; // first column is for view data … … 599 692 " from " . $wpdb->base_prefix . "eav_entity a, " . $wpdb->base_prefix . "eav_layout b " . 600 693 " 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 " . 602 695 " and a.entity_attrib=b.entity_attrib and a.entity=b.entity " . ' order by entity_id,b.entity_order' ; 603 696 … … 638 731 639 732 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 646 734 } 647 735 } 736 echo '<P><a href="javascript:history.back()">Go Back</a>'; 648 737 } 649 738 -
brads-entity-attribute-value-database/trunk/readme.txt
r2504902 r2507785 6 6 Author: Bradley Smith 7 7 Requires PHP: 7.0 8 Requires at least: 5. 79 Tested up to: 5. 710 Stable tag: 2.0 611 Version: 2.0 68 Requires at least: 5.6 9 Tested up to: 5.6 10 Stable tag: 2.07 11 Version: 2.07 12 12 License: GPLv2 or later 13 13 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 36 36 Mange Attributes - This is where you will define your fields 37 37 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 38 39 39 40 shortcodes - standalone … … 79 80 80 81 == 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 81 88 = v2.06 [3/28/2021] 82 89 * bug fixes on shortcodes for eav_tbl and eav_subrec -
brads-entity-attribute-value-database/trunk/uninstall.php
r2504282 r2507785 6 6 remove_shortcode('eav_endadd'); 7 7 remove_shortcode('eav_add'); 8 remove_shortcode('eav_field'); 9 remove_shortcode('eav_subrec'); 8 10 9 11 //execute the query deleting the table … … 27 29 $wpdb->show_errors(); 28 30 $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 37 32 remove_menu_page( 'eav_main_menu'); 38 39 //wp_redirect('/wp-admin/plugins.php');40 33 ?>
Note: See TracChangeset
for help on using the changeset viewer.