default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / process / part_virtual_field.html
1 <% include( 'elements/process.html',
2     'table'          => 'part_virtual_field',
3     'viewall_dir'    => 'browse',
4     'message'        => [ 'Your custom field has been created, but will not be available untill Apache has been restarted.=warning', ],
5     'precheck_callback' => sub {
6         my ($cgi) = @_;
7         $act = 'edit' if $cgi->param('vfieldpart');
8         my @permitted_tables = qw( svc_broadband router cust_main );
9         return 'Table not in list of permitted tables' 
10             unless $cgi->param('dbtable') 
11                 && grep { $_ eq $cgi->param('dbtable') } @permitted_tables;
12         '';
13     },
14     'noerror_callback' => sub {
15         my ($cgi, $object) = @_;
16         if ( $act eq 'add' ) {
17             use FS::Schema qw( reload_dbdef );
18             warn "cf add started schema modification, time=".time;
19             my $dbh = dbh;
20             my $sql = "ALTER TABLE ".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")";
21             $dbh->do($sql) or die $dbh->errstr;
22             $sql = "ALTER TABLE h_".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")";
23             $dbh->do($sql) or die $dbh->errstr;
24
25             # apparently nothing happens w/o commit here - but is this OK?
26             $dbh->commit or die $dbh->errstr; 
27
28             # reload schema
29             my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc;
30             my $dbdef = new_native DBIx::DBSchema $dbh;
31             $dbdef->save($dbdef_file);
32             ## Stop reload of db schema as only reload current process and not others. Could be a pain to diagnose error.  
33             ## Restart Apache to reload DB Schema for all.
34             #delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
35             #reload_dbdef($dbdef_file);
36             
37             warn "cf add done schema modification, time=".time;
38         }
39         # XXX: edit is going to be harder: possibly add editing length and renaming column
40         '';
41     },
42 )
43 %>
44 <%init>
45
46 my $act = 'add';
47
48 ## make cgi->param("name") lowercase
49 my $vcf_name = $cgi->param('name');
50 $vcf_name =~ s/\s/_/g; $vcf_name =~ s/[^A-Za-z0-9\-_]//g;
51 $cgi->param('name' => lc $vcf_name);
52
53 die "access denied"
54   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
55
56 </%init>