[Astpp-commit] SF.net SVN: astpp:[2292] trunk
Brought to you by:
darrenkw
From: <dar...@us...> - 2009-10-17 20:41:46
|
Revision: 2292 http://astpp.svn.sourceforge.net/astpp/?rev=2292&view=rev Author: darrenkw Date: 2009-10-17 20:41:31 +0000 (Sat, 17 Oct 2009) Log Message: ----------- Add the ability to edit the database configuration items from within the gui. Modified Paths: -------------- trunk/Makefile trunk/freeswitch/astpp-callingcards.pl trunk/templates/configuration-list.tpl trunk/web_interface/astpp-admin.cgi Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2009-10-15 02:08:55 UTC (rev 2291) +++ trunk/Makefile 2009-10-17 20:41:31 UTC (rev 2292) @@ -65,7 +65,6 @@ install_samples: install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-config.conf $(DESTDIR)$(ASTPPDIR)/astpp-config.conf - install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-dialplan.conf $(DESTDIR)$(ASTERISKDIR)/astpp-dialplan.conf install_php: mkdir -p $(DESTDIR)$(WWWDIR)/html/astpp Modified: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl 2009-10-15 02:08:55 UTC (rev 2291) +++ trunk/freeswitch/astpp-callingcards.pl 2009-10-17 20:41:31 UTC (rev 2292) @@ -228,7 +228,7 @@ ); } elsif ( $cc == 1 ) { - $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); + $balance = $ASTPP->accountbalance( $cardinfo->{number} ); $balance = ( $balance * -1 ) + ( $cardinfo->{credit_limit} ); $available = ( $balance - $numberinfo->{connectfee} ) / 100; } Modified: trunk/templates/configuration-list.tpl =================================================================== --- trunk/templates/configuration-list.tpl 2009-10-15 02:08:55 UTC (rev 2291) +++ trunk/templates/configuration-list.tpl 2009-10-17 20:41:31 UTC (rev 2292) @@ -4,6 +4,7 @@ <input name="mode" value="Configuration" type="hidden"> </tr> <tr class="header"> + <td>ID</td> <td>Reseller</td> <td>Brand</td> <td>Name</td> @@ -12,28 +13,31 @@ <td>Action</td> </tr> <tr class="header"> - <td colspan=6>Add Item</td> + <td colspan=7 align="center">Add / Edit Item</td> </tr> <tr class="rowone"> + <input name="id" value="<TMPL_VAR NAME="id">" type="hidden"> + <td><TMPL_VAR NAME="id"></td> <td><TMPL_VAR NAME="resellers"></td> <td><TMPL_VAR NAME="brands"></td> - <td><input name="name" size="20" type="text"></td> - <td><input name="value" size="20" type="text"></td> - <td><input name="comment" size="50" type="text"></td> - <td><input name="action" value="Add Item" type="submit"></td> + <td><input name="name" size="20" type="text" value="<TMPL_VAR NAME="name">"></td> + <td><input name="value" size="20" type="text" value="<TMPL_VAR NAME="value">"></td> + <td><input name="comment" size="50" type="text" value="<TMPL_VAR NAME="comment">"></td> + <td><TMPL_VAR NAME="action"></td> </tr> <tr class="header"> - <td colspan=5>List</td> + <td colspan=7>List</td> </tr> <TMPL_LOOP NAME="configuration_list"> <TR> + <TD><TMPL_VAR NAME="id"></TD> <TD><TMPL_VAR NAME="reseller"></TD> <TD><TMPL_VAR NAME="brand"></TD> <TD><TMPL_VAR NAME="name"></TD> <TD><TMPL_VAR NAME="value"></TD> <TD><TMPL_VAR NAME="comment"></TD> - <TD><a href="astpp-admin.cgi?mode=Configuration&action=Delete&name=<TMPL_VAR NAME="name">&reseller=<TMPL_VAR NAME="Reseller">">Delete</a> - <a href="astpp-admin.cgi?mode=Configuration&action=Edit&name=<TMPL_VAR NAME="name">&reseller=<TMPL_VAR NAME="Reseller">">Edit</a></TD> + <TD><a href="astpp-admin.cgi?mode=Configuration&action=Delete&id=<TMPL_VAR NAME="id">">Delete</a> + <a href="astpp-admin.cgi?mode=Configuration&action=Edit&id=<TMPL_VAR NAME="id">">Edit</a></TD> </TR> </TMPL_LOOP> </table> Modified: trunk/web_interface/astpp-admin.cgi =================================================================== --- trunk/web_interface/astpp-admin.cgi 2009-10-15 02:08:55 UTC (rev 2291) +++ trunk/web_interface/astpp-admin.cgi 2009-10-17 20:41:31 UTC (rev 2292) @@ -226,19 +226,19 @@ print header(); } $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-USER:") . " $params->{username}" ); $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-PASS:") . " $params->{password}" ); $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-AUTHCODE:") . " $config->{auth}" ); $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-USER-COUNT:") . " $count" ); return ( $params->{mode}, $count ); @@ -286,19 +286,19 @@ $count = 0; } $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-USER:") . " $params->{username}" ) if $config->{debug} == 1 && $params->{username}; $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-PASS:") . " $params->{password}" ) if $config->{debug} == 1 && $params->{password}; $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-AUTHCODE:") . " $config->{auth}" ) if $config->{debug} == 1; $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => gettext("ASTPP-USER-COUNT:") . " $count" ) if $config->{debug} == 1; print header(); @@ -1024,7 +1024,7 @@ } } -# $where = 0 if $param->{$name} eq "" && $destination eq "" && $pattern eq ""; +# $where = 0 if $params->{$name} eq "" && $destination eq "" && $pattern eq ""; $body .= start_form() @@ -1074,7 +1074,7 @@ print STDERR $query ."\n" if $config->{debug} == 1; $sth = $astpp_db->do($query) || return gettext("Something is wrong with astpp database") . "\n"; - $ASTPP->debug( user => $param->{username}, debug => " SQL: $query " ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $query " ); my $sql = $astpp_db->prepare("SELECT DISTINCT cardnum AS $name FROM $table"); @@ -1262,7 +1262,7 @@ . " and (dstchannel like '$row->{tech}/$row->{path}%'" . " or lastdata like '" . $freeswitch_trunk . "'" . "or dstchannel like '$row->{tech}\[$row->{path}\]%' ) "; - $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql1 \n " ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $sql1 \n " ); my $sth1 = $cdr_db->prepare($sql1); $sth1->execute(); my $ref1 = $sth1->fetchrow_hashref(); @@ -1275,7 +1275,7 @@ . " or lastdata like '" . $freeswitch_trunk . "'" . " OR dstchannel like '$row->{tech}\[$row->{path}\]%' )"; my $sth2 = $cdr_db->prepare($sql2); - $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql2" ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $sql2" ); $sth2->execute(); my $ref2 = $sth2->fetchrow_hashref(); $sth2->finish; @@ -1287,7 +1287,7 @@ . " OR lastdata like '" . $freeswitch_trunk . "'" . " OR dstchannel like '$row->{tech}\[$row->{path}\]%' )"; my $sth3 = $cdr_db->prepare($sql3); - $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql3" ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $sql3" ); $sth3->execute(); my $ref3 = $sth3->fetchrow_hashref(); $sth3->finish; @@ -1298,7 +1298,7 @@ . " or lastdata like '" . $freeswitch_trunk . "'" . " OR dstchannel like '$row->{tech}\[$row->{path}\]%' )"; my $sth4 = $cdr_db->prepare($sql4); - $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql4" ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $sql4" ); $sth4->execute(); my $ref4 = $sth4->fetchrow_hashref(); $sth4->finish; @@ -1437,7 +1437,7 @@ . $cdr_db->quote($sd) . " and calldate <= " . $cdr_db->quote($ed); - $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $tmp" ); } else { $tmp = @@ -1445,7 +1445,7 @@ . $cdr_db->quote($sd) . " and calldate <= " . $cdr_db->quote($ed); - $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" ); + $ASTPP->debug( user => $params->{username}, debug => " SQL: $tmp" ); } if ( $params->{accountcode} && $params->{logintype} == 2 ) { $tmp .= @@ -1457,7 +1457,7 @@ "SELECT * FROM trunks WHERE name = " . $astpp_db->quote( $params->{trunk} ) . " LIMIT 1"; - $ASTPP->debug( user => $param->{username}, debug => $tmpsql ); + $ASTPP->debug( user => $params->{username}, debug => $tmpsql ); $sql = $astpp_db->prepare($tmpsql); $sql->execute || return gettext("Something is wrong with the trunks database") @@ -1478,7 +1478,7 @@ . " or dstchannel like ". $astpp_db->quote($freeswitch_trunk) . " or dstchannel like '$row->{tech}\[$row->{path}\]\%')"; } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); $sql = $cdr_db->prepare($tmp); $sql->execute; $results = $sql->rows; @@ -1618,7 +1618,7 @@ $accounts .= ","; } } - $ASTPP->debug( user => $param->{username}, debug => $accounts ); + $ASTPP->debug( user => $params->{username}, debug => $accounts ); $template->param( customer_count => &count_accounts( $astpp_db, "WHERE type = 0 AND reseller = '$params->{username}'" @@ -1887,7 +1887,7 @@ . $astpp_db->quote($number) . ", " . $astpp_db->quote( $params->{prefix} ) . ", " . $astpp_db->quote( $params->{ipcontext} ) . ")"; - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("IP") . " '" @@ -2296,7 +2296,7 @@ } my $brandinfo = &get_cc_brand( $astpp_db, $params->{brand} ); $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => "BRAND: $params->{brand}" ); while ( $count < $params->{count} ) { @@ -2682,7 +2682,7 @@ $tmp = "DELETE FROM callingcardbrands WHERE name = " . $astpp_db->quote( $params->{name} ); } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("Brand Deleted!"); } @@ -2729,7 +2729,7 @@ . $astpp_db->quote( $params->{min_length_minutes} ) . ", " . $astpp_db->quote( $params->{min_length_pennies} ) . ")"; } - $ASTPP->debug( user => $param->{username}, debug => "sql" ); + $ASTPP->debug( user => $params->{username}, debug => "sql" ); if ( $astpp_db->do($sql) ) { $status .= gettext("Brand Added!"); } @@ -2869,7 +2869,7 @@ . " WHERE name =" . $astpp_db->quote( $params->{name} ); } - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); if ( $astpp_db->do($sql) ) { $status .= gettext("Brand Updated!"); } @@ -3033,7 +3033,7 @@ $tmp = "SELECT name FROM callingcardbrands WHERE status < 2 AND (reseller IS NULL OR reseller = '')"; } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); $sql = $astpp_db->prepare($tmp); $sql->execute || return gettext( @@ -3055,7 +3055,7 @@ $tmp = "SELECT * FROM callingcardbrands WHERE status < 2 AND (reseller IS NULL OR reseller = '') ORDER BY name limit $params->{limit} , $results_per_page"; } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); $sql = $astpp_db->prepare($tmp); $sql->execute || return gettext( @@ -3350,7 +3350,7 @@ . $astpp_db->quote( $cardinfo->{cardnumber} ) . " AND brand " . $brandsql; - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); $astpp_db->do($sql) || print "$sql " . gettext("FAILED"); } @@ -3361,7 +3361,7 @@ $cardinfo = &get_callingcard( $astpp_db, $params->{cardnumber}, $config ); $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => "CARDNUMBER: " . $cardinfo->{cardnumber} ); &update_balance( $cardinfo, $params->{pennies} * 100 ); @@ -3553,7 +3553,7 @@ "SELECT * FROM callingcards WHERE status < 2 AND brand $brandsql ORDER BY id LIMIT " . ( $pgr->get_first() - 1 ) . ", " . $pgr->get_entries_on_this_page(); - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); $sql = $astpp_db->prepare($sql); $sql->execute; @@ -4092,14 +4092,14 @@ mode => $params->{mode}, ); - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); $results = $cdr_db->prepare($sql); $results->execute; while ( my $record = $results->fetchrow_hashref ) { $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => $record->{uniqueid} ); $count++; @@ -4121,7 +4121,7 @@ my (%stuff) = @_; foreach ( keys %stuff ) { $ASTPP->debug( - user => $param->{username}, + user => $params->{username}, debug => "$_: " . $stuff{$_} ); } @@ -4836,7 +4836,7 @@ . $astpp_db->quote( $params->{desc} ) . ", " . $astpp_db->quote( $params->{charge} ) . ", " . $astpp_db->quote( $params->{sweep} ) . ", 1)"; - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); if ( $astpp_db->do($sql) ) { $status .= gettext("Periodic Charge Added!"); } @@ -4971,7 +4971,7 @@ . $astpp_db->quote( $params->{sweep} ) . ", status = '1' WHERE id = " . $astpp_db->quote( $params->{chargeid} ); - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); if ( $astpp_db->do($sql) ) { $status .= gettext("Periodic Charge Updated!"); } @@ -4984,7 +4984,7 @@ elsif ( $params->{action} eq gettext("Delete...") ) { my $sql = "DELETE FROM charges WHERE id = " . $astpp_db->quote( $params->{chargeid} ); - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); if ( $astpp_db->do($sql) ) { $status .= gettext("Periodic Charge Deleted!"); } @@ -4994,7 +4994,7 @@ } $sql = "DELETE FROM charge_to_account WHERE charge_id = " . $astpp_db->quote( $params->{chargeid} ); - $ASTPP->debug( user => $param->{username}, debug => $sql ); + $ASTPP->debug( user => $params->{username}, debug => $sql ); if ( $astpp_db->do($sql) ) { $status .= gettext("Periodic Charge Deleted!"); } @@ -5169,7 +5169,7 @@ my $uploaded = upload('rateimport'); my ( @data, $record ); while ( my $record = <$uploaded> ) { - $ASTPP->debug( user => $param->{username}, debug => $record ); + $ASTPP->debug( user => $params->{username}, debug => $record ); chomp; push @data, $record; } @@ -5211,7 +5211,7 @@ . $astpp_db->quote( $columns[9] ) . "," . $astpp_db->quote( $columns[1] ) . ", 1," . $astpp_db->quote( $columns[10] ) . ")"; - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("Pattern: ") . " '" @@ -5303,7 +5303,7 @@ $uploaded = upload('rateimport'); my ( @data, $record ); while ( my $record = <$uploaded> ) { - $ASTPP->debug( user => $param->{username}, debug => $record ); + $ASTPP->debug( user => $params->{username}, debug => $record ); chomp; push @data, $record; } @@ -5335,7 +5335,7 @@ . " AND pricelist = " . $astpp_db->quote( $resellerdata->{pricelist} ) . " LIMIT 1"; - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); my $sql = $astpp_db->prepare($tmp); my ($routeinfo,$row); $sql->execute; @@ -5530,7 +5530,7 @@ . $astpp_db->quote( $columns[13] ) . "," . $astpp_db->quote( $columns[14] ) . "," . $astpp_db->quote( $columns[15] ) . ")"; - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("DID: ") . " '" @@ -5560,7 +5560,7 @@ gettext("The old pattern for") . " '" . $params->{number} . "' " . gettext("FAILED to remove!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } $tmp = "INSERT INTO routes (pattern,comment,pricelist,connectcost,includedseconds,cost) VALUES (" @@ -5853,7 +5853,7 @@ gettext("Pricelist: ") . $params->{name} . gettext(" Failed to Reactivate!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } } else { @@ -5891,7 +5891,7 @@ gettext("Pricelist: ") . $params->{name} . gettext(" Failed to Add!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } } $params->{action} = gettext("Information..."); @@ -5933,7 +5933,7 @@ gettext("Pricelist: ") . $params->{name} . gettext(" Failed to Update!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } } else { @@ -5971,7 +5971,7 @@ gettext("Pricelist: ") . $params->{name} . gettext(" Failed to Deactivate!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } } $params->{action} = gettext("Information..."); @@ -6038,7 +6038,7 @@ $tmp = "SELECT * FROM pricelists WHERE status < 2 AND reseller IS NULL"; } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); $sql = $astpp_db->prepare($tmp); $sql->execute || return gettext("Something is wrong with the ASTPP database!") @@ -6060,7 +6060,7 @@ $tmp = "SELECT * FROM pricelists WHERE status < 2 AND reseller IS NULL ORDER BY name limit $params->{limit} , $results_per_page"; } - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); $sql = $astpp_db->prepare($tmp); $sql->execute || return gettext("Something is wrong with the ASTPP database!") @@ -6433,7 +6433,7 @@ gettext("DID") . " '" . $params->{number} . "' " . gettext("FAILED to create!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } $tmp = "DELETE FROM routes WHERE pattern = " @@ -6451,7 +6451,7 @@ gettext("The old pattern for") . " '" . $params->{number} . "' " . gettext("FAILED to remove!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } $tmp = "INSERT INTO routes (pattern,comment,pricelist,connectcost,includedseconds,cost,inc,reseller) VALUES (" @@ -6465,7 +6465,7 @@ . $astpp_db->quote( $params->{included} ) . "," . $astpp_db->quote( $params->{cost} ) . "," . $astpp_db->quote( $params->{inc} ) . ",'')"; - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("Pattern") . " '" @@ -6477,7 +6477,7 @@ gettext("Pattern") . " '" . $params->{number} . "' " . gettext("FAILED to create!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } $params->{action} = gettext("Information..."); } @@ -6534,7 +6534,7 @@ gettext("DID") . " '" . $params->{number} . "' " . gettext("FAILED to update!"); - $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $ASTPP->debug( user => $params->{username}, debug => $tmp ); } $tmp = "UPDATE routes SET" @@ -9540,42 +9540,103 @@ } sub build_configuration() { - my ( @brands, @resellerlist, $tmp, $template, @configuration_list ); + my ( $action, @brands, @resellerlist, $tmp, $template, @configuration_list ); + $action = "<input name=\"action\" value=\"Add Item\" type=\"submit\">"; $template = HTML::Template->new( filename => '/var/lib/astpp/templates/configuration-list.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); if ( $params->{logintype} == 1 ) { - push( @resellerlist, $params->{username} ); + unshift( @resellerlist, $params->{username} ); } else { @resellerlist = &list_resellers($astpp_db); - push( @resellerlist, "" ); + unshift( @resellerlist, "" ); } - $template->param( - resellers => popup_menu( - -name => "resellers", - -values => \@resellerlist - ) - ); if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { @brands = &list_cc_brands_reseller( $astpp_db, $params->{username} ); - push( @brands, "" ); + unshift( @brands, "" ); } else { @brands = &list_cc_brands($astpp_db); - push( @brands, "" ); + unshift( @brands, "" ); } + + + if ( !$params->{action} ) { $params->{action} = "List"; } + if ( $params->{action} eq "Edit" ) { + my ($tmp,$sql); + if ( $params->{logintype} == 1 ) { + $tmp = + "SELECT * FROM system WHERE reseller = " + . $astpp_db->quote( $params->{username} ) + . " AND id = " + . $astpp_db->quote( $params->{id} ); + } else { + $tmp = + "SELECT * FROM system WHERE id = " + . $astpp_db->quote( $params->{id} ); + + } + $ASTPP->debug( user => $param->{username}, debug => $tmp ); + $sql = $astpp_db->prepare($tmp); + $sql->execute; + my $config_item = $sql->fetchrow_hashref; + $sql->finish; + + $action = "<input name=\"action\" value=\"Save Item\" type=\"submit\">"; + $template->param(id => $config_item->{id}); + $template->param(name => $config_item->{name}); + $template->param(value => $config_item->{value}); + $template->param(comment => $config_item->{comment}); $template->param( brands => popup_menu( -name => "brands", - -values => \@brands + -values => \@brands, + -default => $config_item->{brand} ) ); + $template->param( + resellers => popup_menu( + -name => "resellers", + -values => \@resellerlist, + -default => $config_item->{reseller} + ) + ); - if ( !$params->{action} ) { $params->{action} = "List"; } - if ( $params->{action} eq "Edit" ) { + } + elsif ( $params->{action} eq "Save Item" ) { + if ( $params->{logintype} == 1 ) { + $params->{reseller} = $params->{username}; + } + $tmp = + "UPDATE system SET " + . " reseller = " + . $astpp_db->quote( $params->{reseller} ) . "," + . " brand = " + . $astpp_db->quote( $params->{brand} ) . "," + . " name = " + . $astpp_db->quote( $params->{name} ) . "," + . " value = " + . $astpp_db->quote( $params->{value} ) . "," + . " comment = " + . $astpp_db->quote( $params->{comment} ) + . " WHERE id = " + . $astpp_db->quote( $params->{id} ); + if ($params->{resller}) { + $tmp .= " AND reseller = " + . $astpp_db->quote( $params->{reseller} ); + } + $ASTPP->debug( user => $param->{username}, debug => $tmp ); + if ( $astpp_db->do($tmp) ) { + $status .= "Saved Configuration Item!"; + } + else { + $status .= "Failed to Save Configuration Item!"; + } + $params->{action} = "List"; + } elsif ( $params->{action} eq "Add Item" ) { if ( $params->{logintype} == 1 ) { $params->{reseller} = $params->{username}; @@ -9600,23 +9661,23 @@ if ( $params->{logintype} == 2 ) { if ( $params->{reseller} ne "" ) { $tmp = - "DELETE FROM system WHERE name = " - . $astpp_db->quote( $params->{name} ) + "DELETE FROM system WHERE id = " + . $astpp_db->quote( $params->{id} ) . " AND reseller = " . $astpp_db->quote( $params->{reseller} ) . " LIMIT 1"; } else { $tmp = - "DELETE FROM system WHERE name = " - . $astpp_db->quote( $params->{name} ) + "DELETE FROM system WHERE id = " + . $astpp_db->quote( $params->{id} ) . " AND reseller IS NULL LIMIT 1"; } } elsif ( $params->{logintype} == 1 ) { $tmp = - "DELETE FROM system WHERE name = " - . $astpp_db->quote( $params->{name} ) + "DELETE FROM system WHERE id = " + . $astpp_db->quote( $params->{id} ) . " AND reseller = " . $astpp_db->quote( $params->{username} ) . " LIMIT 1"; @@ -9631,6 +9692,18 @@ $params->{action} = "List"; } if ( $params->{action} eq "List" ) { + $template->param( + brands => popup_menu( + -name => "brands", + -values => \@brands + ) + ); + $template->param( + resellers => popup_menu( + -name => "resellers", + -values => \@resellerlist + ) + ); if ( $params->{logintype} == 2 ) { $tmp = "SELECT * FROM system ORDER BY reseller,name"; } @@ -9651,11 +9724,13 @@ $row{value} = $record->{value}; $row{comment} = $record->{comment}; $row{timestamp} = $record->{timestamp}; + $row{id} = $record->{id}; push( @configuration_list, \%row ); } $sql->finish; $template->param( configuration_list => \@configuration_list ); } + $template->param(action => $action ); return $template->output; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |