PDA

View Full Version : How can we implement a new database table in flynax



Steffen Buschkemper
May 14, 2012, 11:12 AM
Hello Flynax team.

I have created a new table fl_citys in the database.
In this table there are the complete zip codes and citys from germany.
How can i integrate this in flynax admin panel.

I wrote a jQuery and php script that will simplify the user input.



{literal}
<script type="text/javascript">
//<![CDATA[
$(function(){
function get() {
$("#zip_code").blur(function(){
$.post('http://localhost/plz/plz.php', { name: $("#zip_code").val() },
function(output) {
$('#city').val(output);
});
});
}
get();
});
//]]>
</script>
{/literal}


All works fine and The city is automatically inserted after the zip code input.
How can I integrate into flynax admin panel? The plz.php makes the database query.

The picture is the table structur.

Mike
May 15, 2012, 06:16 AM
Hi,

You have to implement manager for this data to the admin panel. I can't write all steps of it as it's not quick job, just main steps for creating new manager in AP.

Insert entry to admin_controls, lang_keys table

create two files with same name as database entries key

one file is php to get and save data to table
another file is tpl to display grid and other layout.

You can check how other pages in admin panel implemented and easier would be copy existing page and then change to make working with your table.

By the way:
Very nice feature, i like it :)

it's very useful feature and as well can be done even if you don't have zip codes database for your region (for others who interested better to create ticket) . or i can try to post solution similar to Steffen's here

Steffen Buschkemper
May 16, 2012, 01:56 PM
Hi Mike,

Thanks for your answer.
I need some help for this.
I have create 2 Files and insert phrase to lang_keys and extJs.
As example files i took transactions.tpl and transactions.inc.php.
Now i can see in Admin panel the new category -> PLZ & Stadt
Also i can see the search button and the search fields - all be fine.
But i can not see the table and entries.

This is my PHP Code


/* ext js action */
if ($_GET['q'] == 'ext')
{
/* system config */
require_once( '../../includes/config.inc.php' );
require_once( RL_ADMIN_CONTROL . 'ext_header.inc.php' );

/* load system lib */
require_once( RL_LIBS . 'system.lib.php' );

/* date update */
if ($_GET['action'] == 'update' )
{
$reefless -> loadClass( 'Actions' );

$type = $rlValid -> xSql( $_GET['type'] );
$field = $rlValid -> xSql( $_GET['field'] );
$value = $rlValid -> xSql( nl2br($_GET['value']) );
$id = $rlValid -> xSql( $_GET['id'] );
$key = $rlValid -> xSql( $_GET['key'] );

$updateData = array(
'fields' => array(
$field => $value
),
'where' => array(
'ID' => $id
)
);

$rlHook -> load('apExtZip2CountriesUpdate');
$rlActions -> updateOne( $updateData, 'zip2countries');
exit;
}

/* data read */
$limit = $rlValid -> xSql( $_GET['limit'] );
$start = $rlValid -> xSql( $_GET['start'] );
$sort = $rlValid -> xSql( $_GET['sort'] );
$sortDir = $rlValid -> xSql( $_GET['dir'] );

$langCode = $rlValid -> xSql( $_GET['lang_code'] );
$phrase = $rlValid -> xSql( $_GET['phrase'] );

$search_fields = array(
'zip' => '`T1`.`Zip`',
'city' => '`T1`.`City`',
'district' => '`T1`.`District`',
'state' => '`T1`.`State`',
);

$sql = "SELECT SQL_CALC_FOUND_ROWS `T1`.*, ";
$sql .= "FROM `".RL_DBPREFIX."zip2countries` AS `T1` ";
$sql .= "WHERE `T1`.`Status` <> 'trash' ";
if ( $_GET['search'] )
{
foreach ($search_fields as $sf_key => $sf_field)
{
$field = $_GET[$sf_key];
if ( !empty($field) )
{
switch ($sf_key){
default:
$sql .= "AND {$sf_field} = '{$field}' ";
break;
}
}
}
}

if ( $sort )
{
switch ($sort){
case 'Zip':
$sortField = "`T1`.`Zip`";
break;

case 'City':
$sortField = "`T1`.`City`";
break;

case 'District':
$sortField = "`T1`.`District`";
break;

case 'State':
$sortField = "`T1`.`State`";
break;

default:
$sortField = "`T1`.`{$sort}`";
break;
}

$sql .= "ORDER BY {$sortField} {$sortDir} ";
}
$sql .= "LIMIT {$start}, {$limit}";

$rlHook -> load('apExtZip2CountriesSql');

$data = $rlDb -> getAll($sql);

$count = $rlDb -> getRow( "SELECT FOUND_ROWS() AS `count`" );

foreach ( $data as $key => $value )

$reefless -> loadClass( 'Json' );

$output['total'] = $count['count'];
$output['data'] = $data;

echo $rlJson -> encode( $output );
}
/* ext js action end */

else
{
$rlDb -> setTable('zip2countries');
/* register ajax methods */
$rlXajax -> registerFunction( array( 'deleteZip2Country', $rlAdmin, 'ajaxDeleteZip2Country' ) );
$rlHook -> load('apPhpZip2CountriesBottom');
}


Where is the Problem?

Best regards
Steffen