We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20413
    • 2,877 Posts
    Is it possible to automatically see the records that is added the table from outside (eform2db)
    and manage them from dbedit? smiley


    Never mind I had installed the table wrong! Now I see everything!!! AWESOME!!
    MAN IT ROCKS!!!

    //When installing a new table and do some settings it saves settings _once_, so for me I need
    to remove and re-install table for _new_ settings to be made! E.g. Sort order field keep the values.

    IE 7/8...
    Message: Object doesn’t support this property or method
    Line: 37
    Char: 2
    Code: 0
    URI:.../js/edit.config.json.js


      @hawproductions | http://mrhaw.com/

      Infograph: MODX Advanced Install in 7 steps:
      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
      • 7253
      • 97 Posts
      I too had issues with not being able to save new tables.

      Turns out that my issue was the following column, a string field with a perfectly valid string as a default:

      `color_code` VARCHAR(6) NOT NULL DEFAULT ’000000’,

      The combination of a non-numeric field with a numeric default seemed to be confusing the default validation code in module.save.configuration.inc.php. I’ve re-written this code to check the field type first, then only perform the appropriate type of default evaluation. This has sorted this issue for me, so here’s the re-written module.save.configuration.inc.php:

      <?php
      
      /**
       * module save configuration
       *
       * @package dbEdit Table Editor
       * @version 1.0
       * @author Jelle Jager
       * @copyright 2008 Jelle Jager
       * @license GPL
       *
       * //Permissions!!!
       * //Permissions!!!
       */
      	//* debug */ print __LINE__.': '.$dba.'<br />';
      	include_once('JSON.php');
      	$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
      
      	function findField($fieldName) {
      		global $dbFields;
      		if(is_array($fieldName)):
      			foreach($fieldName as $name)
      				if(!findField($name)) return false;
      			return $fieldName;
      		endif;
      		return (isset($dbFields[$fieldName]))?$fieldName:false;
      	}
      
      	//Need to do some translating from php (display) to mysql types.
      	$allowedFieldTypes = array(
      		'string'=>'string',
      		'int' => 'number',
      		'float' => 'number',
      		'double' => 'number',
      		'blob' => 'string'
      	//	'' => '',
      	);
      	//* debug */ print __LINE__.': <pre>'.print_r($_REQUEST,true) .'</pre><br />';
      
      	unset($dbConfig);
      	//NEED TO DO TYPES!! SEE THROUGH CODE for supported types!!!
      
      	//check if we have a valid json
      	if( !isset($_POST['json_data']) ) die('No data to process!');
      	$dbConfig = $json->decode($_POST['json_data']);
      	if( !$dbConfig ) die('No data or invalid configuration data found.!');
      
      	//get fields info from database
      	$GLOBALS['dbFields'] = $modx->db->getTableMetaData( $dbConfig['tableName'] );
      	global $dbFields;
      	if(!$dbFields) die('Could not verify table data.');
      
      	if(!is_array($dbConfig) || !isset($dbConfig['tableName'])):
      		$ok=false;
      	else:
      		//do some validation...
      		foreach( $dbConfig['fields'] as $fld_name => $props ):
      			//check that field exists in table
      			$ok = (isset($dbFields[$fld_name]))?1:0;
      			//check that (db) data type is the same (otherwise someone is tampering?)
      			$l = strlen($props['dbtype']);
      			$ok = ( $ok && $props['dbtype']==substr($dbFields[$fld_name]['Type'],0,$l))?1:0;
      			//check that (display) data type is appropriate?
      			//HOW?? What datatypes? Especially with bindings!
      			//* debug */ print __LINE__.': <pre>'.print_r($ok,true) .'</pre><br />';
      			//* debug */ print __LINE__.': <pre>'.print_r($props,true) .'</pre><br />';
      			
      			//check that default values are appropriate
      			if($ok && !empty($props['default']) ):
      				if ($props['type']=='date' || $props['type']=='time'):
      					# date/time field, check for invalid default
      					$t = strtotime($props['default']);
      					$ok = ( ($t!=-1 && $t!=false) ) ?1:0;
      				endif;
      				//* debug */ print __LINE__.': <pre>'.print_r($ok,true) .'</pre><br />';
      				
      				if($ok && in_array(strtoupper($props['type']),$modx->db->dataTypes['numeric'])):
      					# numeric field, check for non-numeric default
      					$ok = ( !is_numeric($props['default']) )?0:1;
      				endif;
      				//* debug */ print __LINE__.': <pre>'.print_r($ok,true) .'</pre><br />';
      			endif;
      			//* debug */ print __LINE__.': <pre>'.print_r($ok,true) .'</pre><br />';
      		endforeach;
      	endif;
      
      	if($ok):
      		//need to validate all values here!!
      		$insertFields['name'] = $modx->db->escape($dbConfig['title']);
      		$insertFields['comment'] = $modx->db->escape($dbConfig['description']);
      		$insertFields['config'] = $modx->db->escape(serialize($dbConfig));
      		//update or new?
      	endif;
      	
      	if ($dba==109):
      		$ok = $modx->putIntTableRow($insertFields,$dbe_config_table)?1:0;
      	elseif(($dba==119 || $dba==110) && !empty($db_id) ):
      		$ok = $modx->updIntTableRow($insertFields,$dbe_config_table,"recID=".$db_id)?1:0;
      	else:
      		$msg = "Wrong save action encountered!<br />";
      	endif;
      
      	if ($ok):
      		$msg .= "Configuration for \"".$dbConfig['moduleName']."\" saved succesfully.";
      		$_SESSION['dbedit_message'] = array('succes',$msg);
      		header("location: index.php?a=".$_REQUEST['a']."&id=".$module_id);
      		exit;
      	else:
      		//* debug */ print __LINE__.': <pre>'.print_r($dbConfig,true) .'</pre><br />';
      		$msg .=  "Unable to save configuration. Reason is: <br />".$modx->db->getLastError();
      	endif;
      
      //somehow make this possible???
      //$dbConfig['list']['Select'] = "recID,concat(FirstName,\" \",LastName) as FullName,artistCode,Type";
      //$dbConfig['list']['Where'] = "";
      
      include($basePath.$mod_path.'/header.inc.php');
      ?>
      
      <div class="subTitle">
      	<span class="right"><em>db</em>Edit Table Editor</span>
      </div>
      <div class="sectionHeader"><img src='media/images/misc/dot.gif' alt="." /> Save Configuration</div><div class="sectionBody">
      <?php print $msg; ?>
      <ul>
      	<li><a href="<?php echo $moduleHomeUrl; ?>">Return to dbEdit module</a></li>
      </ul>
      </div>
      <?php include($basePath.$mod_path.'/footer.inc.php'); ?>
      


      The relevant part of the code is lines 69 - 82.

      In the process of figuring this out, I’ve re-formatted some of the code and added in a load more debug lines. I’ve commented out all the debugging code, but it’s still in there if needed.

      Anyway, hope someone finds this useful.
        • 20413
        • 2,877 Posts
        Thanks for sharing!! Will try it! smiley
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 11055 ☆ A M B ☆
          • 3,112 Posts
          When adding new table:
          Select a the table to expose it's properties below.
          « MODx Parse Error »
          MODx encountered the following error while attempting to parse the requested resource:
          « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE Tables_in_modx NOT LIKE 'modx_%'' at line 1 »
                SQL: SHOW TABLES FROM `modx` WHERE Tables_in_modx NOT LIKE 'modx_%'
                [Copy SQL to ClipBoard]

          EDIT: anyway, i’m using MySQL 4.

          Btw, in index.php, line 142:
          case "debugconfig":
          $include_file = "debug.print.table.php";
          

          Where’s the file?
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            ok, I’m notoriously bad at having stuff like this work when I try it... but I can’t get this to work at all. I added the module php code, I added the configuration details (which shows the module path and the date format), but when I go to use the module and add a table, I can’t actually do anything.

            I’m unable to see any tables or save any data... I’m not even sure what this is supposed to look like. See my screenshot.


            I can’t click the "refresh" button, and the save button on this page doesn’t seem to work.

            Also, the image is broken for the page (oiy... modules should have self-contained assets...), but that’s just cosmetic.
              • 30223
              • 1,010 Posts
              Since in your screenshots the <select> is missing I’m guessing that you haven’t made any extra database tables yet or if you have you may have used the modx db prefix. dbEdit will only work with tables that already exist. It won’t help you create them and it won’t let you manage tables that have the same prefix as the modx tables.
                • 10449
                • 956 Posts
                Actually, I’m seeing the same thing. I have at least a dozen non-modx tables in the same DB, but none of them shows up.
                I can see the dbedit_configs table.

                hmm... I just had an idea... is it necessary for this module to use a prefix for the modx tables? My test install doesn’t use a prefix at all. o_O
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  Yeah, my install doesn’t use prefixes either. The table DOES exist... and I’m able to get in and out of it with my scripts and with phpMyEdit (and the Mysql command line of course).

                  Maybe this would work if I had a prefix?
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Since it only works on non-MODx tables, I rather imagine not having a prefix for your MODx tables is causing the problem. With no MODx table prefix to compare against, how can it tell that it’s not a MODx table?
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 9207 ☆ A M B ☆
                      • 2,475 Posts
                      Mmm... I see what you’re saying. How about accessing non-MODx tables in another database? That should be pretty clear. I understand the security implication of preventing access to MODx tables, but I’d rather just have access to my tables, regardless of whether or not they’re native to the MODx install. I’ll take the heat for breaking things. Maybe a better check would be to look for an array of pre-defined "known to be included in a default MODx install" table names. A black list approach...

                      I spend so much time on the MySQL command line writing joins that I HATE using table prefixes, especially when it’s really clear what your objects are. It’s the department of redundancy department all over again...

                      Anyhow... i’m curious to evaluate this module as I work on a CRUD module of my own. I’ve tried the phpMyEdit, and that seems viable for the backend, but probably not a good idea for web users... it doesn’t look skin-able enough. And filtering data...mmm... I should read more of their docs, it’s just a bit heavy for this time of night.