Gossamer Forum
Quote Reply
editor.cgi
alex.. i was thinking about something i mentioned like when Links was 1.1b1.. it was something that moved around the fields in the MySQL database for "cosmetic" reasons.

I just now thought of something else that could probably be more easily done (instead of going through a whole database rehaul). In the edit table definition section or perhaps another page you can just have another field number in the hash array and when you print out the form in build_html_record_form or whatever you just sort by that field..

better than reading the data.. putting it in memory.. dropping the table.. creating a new table and then pasting it back together..

the reason again why i would like this is cause when i add a IMPORTANT new field.. i don't like having it all the way at the bottom on the page..

i might go into this myself next tuesday when i finish a science project i need to do by tuesday..

also.. the first field in the hash arrays in the .def files.. does it represent the field position? unlike Links 2.0 it starts from 1.. so is this used for backups when it writes to the tab deliminated file? what else is it used for?

jerry
Quote Reply
Re: editor.cgi In reply to
ok.. i'm looking at DBSQL.pm and i hope i am right about this.. but the only place that "reads" %db_def in all the .def files is in sub initialize..

correct? if so a few knicks to DBSQL.pm, editor.cgi, DB_Utils.pm should do it.. (i'll see if i can get this done by tonight)

jerry
Quote Reply
Re: editor.cgi In reply to
alex.. i found a semi bug..

when you delete a field it shows up in the select list again because you didn't create a new database object after deleting the field..

i don't think it really matters.. but i was a little confused when i delete my contact_name field it showed up again so i thought it didn't work.. i deleted again to get an error saying it didn't exist.. so then i was like "oh.. duh" put

Code:
$db = new Links::DBSQL $LINKS{admin_root_path} . "/defs/" . ($in->param('db') || "Links") . ".def";

before the page is printed again..

jerry

[This message has been edited by widgetz (edited December 04, 1999).]
Quote Reply
Re: editor.cgi In reply to
nevermind.. i did it modding editor.cgi a few lines in editor.cgi and adding 2 lines and adding 3 lines in DBSQL.pm

jerry
Quote Reply
Re: editor.cgi In reply to
Jerry:

I think this would be a cool mod... can you post it when it is all worked out?

Dave
Quote Reply
Re: editor.cgi In reply to
carfac..

it's actually all done already.. but i have no clue how i am gonna tell you guys how to install it Smile

anyways.. since it was easy to make.. i'll start out with the code.. all i can say is if you install this.. don't use setup.cgi until alex says it will work or until i come out with a mod to setup.cgi Smile i haven't looked at setup.cgi so i don't know if it needs any modding..

DBSQL.PM
(sub intialize)

under:
Code:
$self->{'db_indexed'} = {}; $self->{'db_is_indexed'} = 0;

add:
Code:
$self->{'db_order'} = {};

under:
Code:
$self->{'db_indexed'}{$_} = $db_def{$_}[7];

add:
Code:
$self->{'db_order'}{$_} = $db_def{$_}[8];

(in sub build_html_record AND build_html_record_form)
[it appears once in each of them..]

find:
Code:
foreach my $field (@{$self->{'db_cols'}}) {

replace with:
Code:
my %columns = %{$self->{'db_order'}};
foreach my $field (sort { $columns{$a} <=> $columns{$b} } keys %columns) {

EDITOR.CGI

there are two of these... find them both:
Code:
foreach my $column (@{$db->{'db_cols'}}) {

replace them with:
Code:
my %columns = %{$db->{'db_order'}};
foreach my $column (sort { $columns{$a} <=> $columns{$b} } keys %columns) {

find this (it is one really LONG line):
Code:
<th>Update</th><th>Column</th>

change it to this (not the whole line):
Code:
<th>Update</th><th>Order</th><th>Column</th>

a few lines down, find this:
Code:
<td><input type=checkbox name="$column" value="update">

add this below:
Code:
<td><input type=text name="order-$column" value="$order" size=3></td>

go to sub add_field..

find:
Code:
$db->{db_def}{$column} = [ $last_f, $type, $fmax, $max, $null, $def, $val, $index ];

replace with:
Code:
my @order = sort { $b <=> $a } values %{$db->{'db_order'}};
my $last_o = $order[0] + 1;
$db->{db_def}{$column} = [ $last_f, $type, $fmax, $max, $null, $def, $val, $index, $last_o ];

go to sub update_fields..

add this to the list of variables in the my listy thingy.. Smile
Code:
, %order

above:
Code:
/^form-(.+)$/ and ($form{$1} = $in->param($_)) and next;

add:

Code:
/^order-(.+)$/ and ($order{$1} = $in->param($_)) and next;

find:
Code:
$db->{db_def}{$field} = [$org->[0], $org->[1], $form{$field}, $max{$field}, $null{$field}, $default{$field}, $validate{$field}, $indexed{$field}}];

replace with:
Code:
$db->{db_def}{$field} = [$org->[0], $org->[1], $form{$field}, $max{$field}, $null{$field}, $default{$field}, $validate{$field}, $indexed{$field}, $order{$field}];

ok now all the modding is done.. you are going to go through an annoying process of setting up all the order numbers..

i suggest to go through all the tables edit table definitions and just do them equal to their position numbers.. and then after you are all done and can confirm that it sorts according to those numbers you can start changing them..

sorry i couldn't figure out a better interface to do it.. when you add a field.. it automatically goes to the end and you have to adjust them yourself..

don't forget.. when you want a field to be the 13th field in the admin.. you have to update all the fields starting from 14 to TOTAL FIELDS.. you just increase them all by one..

jerry

[This message has been edited by widgetz (edited December 04, 1999).]