|
From: Chris W. <la...@us...> - 2001-10-14 20:39:26
|
Update of /cvsroot/openinteract/OpenInteract/pkg/classified/OpenInteract/Handler
In directory usw-pr-cvs1:/tmp/cvs-serv2890/OpenInteract/Handler
Modified Files:
Classified.pm
Log Message:
updated handler to use OI::CommonHandler
Index: Classified.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/classified/OpenInteract/Handler/Classified.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Classified.pm 2001/09/10 18:19:51 1.6
--- Classified.pm 2001/10/14 20:39:23 1.7
***************
*** 5,12 ****
use strict;
use Data::Dumper qw( Dumper );
use OpenInteract::Handler::GenericDispatcher qw( DEFAULT_SECURITY_KEY );
use SPOPS::Secure qw( :level );
! @OpenInteract::Handler::Classified::ISA = qw( OpenInteract::Handler::GenericDispatcher SPOPS::Secure );
$OpenInteract::Handler::Classified::VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
--- 5,13 ----
use strict;
use Data::Dumper qw( Dumper );
+ use OpenInteract::CommonHandler;
use OpenInteract::Handler::GenericDispatcher qw( DEFAULT_SECURITY_KEY );
use SPOPS::Secure qw( :level );
! @OpenInteract::Handler::Classified::ISA = qw( OpenInteract::CommonHandler SPOPS::Secure );
$OpenInteract::Handler::Classified::VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
***************
*** 21,168 ****
use constant DEFAULT_EXPIRE => 60 * 60 * 24 * 7 * 12; # 12 weeks
- use constant MAIN_SCRIPT => '/Classified';
! # Simple listing -- you can get a listing of non-active items by
! # passing in 'is_active=no'
! sub listing {
! my ( $class, $p ) = @_;
! my $R = OpenInteract::Request->instance;
! my $params = { main_script => MAIN_SCRIPT,
! error_msg => $p->{error_msg} };
! my $current_date = $R->classified->now;
! my $active = $R->apache->param( 'is_active' ) || 'yes';
! $params->{classified_iterator} =
! eval { $R->classified->fetch_iterator({
! where => "active = ? and " .
! "( deadline is null or deadline > ? )",
! value => [ $active, $current_date ],
! order => 'posted_on DESC' }) };
! if ( $@ ) {
! $R->scrib( 0, "Found error: $@", Dumper( SPOPS::Error->get ) );
! }
! $R->{page}->{title} = 'Classified Listing';
! return $R->template->handler( {}, $params,
! { db => 'classified_list',
! package => 'classified' } );
}
- sub show {
- my ( $class, $p ) = @_;
- my $R = OpenInteract::Request->instance;
- my $params = { main_script => '/Classified', error_msg => $p->{error_msg} };
- my $classified_id = $R->apache->param( 'classified_id' );
- my $classified = $p->{classified} ||
- eval { $R->classified->fetch( $classified_id ) };
! # This is a little different -- we want people to be able to
! # create new records but not edit existing ones unless they have
! # write access to the handler.
! my $do_edit = $R->apache->param( 'edit' );
! if ( $do_edit ) {
! if ( $classified and $p->{level} < SEC_LEVEL_WRITE ) {
! my $user_msg = 'Sorry, you do not have access to edit an ' .
! 'existing classified entry. Returning to listing.';
! return $class->listing({ error_msg => $user_msg });
! }
! if ( $classified and $classified->{active} ne 'yes'
! and $p->{level} < SEC_LEVEL_WRITE ) {
! my $user_msg = 'This classified ad is not currently active and cannot be displayed';
! return $class->listing({ error_msg => $user_msg });
! }
}
! else {
! if ( $classified and $classified->{active} ne 'yes' ) {
! my $user_msg = 'This classified ad is not currently active and cannot be displayed';
! return $class->listing({ error_msg => $user_msg });
! }
}
- # Object security defaults to WRITE: if there is no object,
- # then you're creating it and security then depends on the application
- my $obj_level = ( $classified )
- ? $classified->{tmp_security_level}
- : SEC_LEVEL_WRITE;
! $classified ||= $R->classified->new;
! $params->{classified} = $classified;
! my $tmpl_name = ( $do_edit ) ? 'classified_form' : 'classified_detail';
! $R->{page}->{title} = 'Classified Ad Detail';
! return $R->template->handler( {}, $params,
! { db => $tmpl_name,
! package => 'classified' } );
}
! sub edit {
! my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
- $R->{page}->{return_url} = '/Classified/';
- my $apr = $R->apache;
- my $classified_id = $apr->param( 'classified_id' );
- my $is_new = ( ! $classified_id );
- $R->DEBUG && $R->scrib( 1, "Trying to modify ID <<$classified_id>>" );
- my $classified = eval { $R->classified->fetch( $classified_id ) };
- my $obj_level = ( $classified ) ? eval { $classified->check_security } : SEC_LEVEL_WRITE;
- if ( $obj_level < SEC_LEVEL_WRITE ) {
- my $user_msg = 'Sorry, you do not have access to modify this classified ad. Returning to display.';
- return $class->show({ classified => $classified, error_msg => $user_msg });
- }
! $classified ||= $R->classified->new;
! my %skip = map { $_ => 1 } qw( posted_by classified_id deadline expires_on );
! foreach my $field ( @{ $R->classified->field_list } ) {
! next if ( $skip{ $field } );
! $R->DEBUG && $R->scrib( 1, "Find value for field <<$field>>" );
! $classified->{ $field } = $apr->param( $field );
! }
! # All new objects are NOT active until approved by an admin
! # (unless an admin is the one doing the editing...)
! if ( $is_new and $p->{level} < SEC_LEVEL_WRITE ) {
! $classified->{active} = 'no';
}
! $classified->{deadline} = $class->date_read( 'deadline' );
! unless ( $classified->{expires_on} ) {
! my $expire_time = $R->{time} + DEFAULT_EXPIRE;
! my @time_info = localtime( $expire_time );
! $classified->{expires_on} = join '-', $time_info[5] + 1900, $time_info[4] + 1, $time_info[3];
! }
! $classified->{posted_by} ||= $R->{auth}->{user}->{user_id};
! $classified->{posted_on} ||= $classified->now;
! $classified->{active_on} ||= $classified->now;
! eval { $classified->save };
! if ( $@ ) {
! $p->{error_msg} = 'Cannot save classified object! See error log for details.';
! }
! $p->{classified} = $classified;
! return $class->show( $p );
! }
! sub remove {
! my ( $class, $p ) = @_;
! my $R = OpenInteract::Request->instance;
! if ( my $classified_id = $R->apache->param( 'classified_id' ) ) {
! my $classified = $R->classified->fetch( $classified_id );
! if ( $@ or ! $classified ) {
! return $class->listing( param => { error_msg => 'Cannot remove classified -- object not created properly.' } );
! }
! if ( SEC_LEVEL_WRITE > eval { $classified->check_security } ) {
! my $user_msg = 'Sorry, you do not have access to remove this classified object. Returning to listing.';
! return $class->listing( { error_msg => $user_msg } );
! }
! eval { $classified->remove };
! if ( $@ ) {
! $p->{error_msg} = 'Cannot remove classified object! See error log for details...';
}
}
- return $class->listing( $p );
}
--- 22,135 ----
use constant DEFAULT_EXPIRE => 60 * 60 * 24 * 7 * 12; # 12 weeks
+ sub MY_PACKAGE { return 'classified' }
+ sub MY_HANDLER_PATH { return '/Classified' }
+ sub MY_OBJECT_TYPE { return 'classified' }
+ sub MY_OBJECT_CLASS { return OpenInteract::Request->instance->classified }
+ sub MY_SEARCH_FIELDS { return qw( title organization location description ) }
+ sub MY_SEARCH_FORM_TITLE { return 'Search for Classified Ads' }
+ sub MY_SEARCH_FORM_TEMPLATE { return 'classified_search_form' }
+ sub MY_SEARCH_RESULTS_TITLE { return 'Classified Search Results' }
+ sub MY_SEARCH_RESULTS_TEMPLATE { return 'classified_search_results' }
+ sub MY_OBJECT_FORM_TITLE { return 'Classified Detail' }
! sub MY_OBJECT_FORM_TEMPLATE {
! my ( $class, $params ) = @_;
! return ( $params->{do_edit} ) ? 'classified_form' : 'classified_detail';
! }
! sub MY_EDIT_RETURN_URL { return '/Classified/search_form/' }
!
! sub MY_EDIT_FIELDS {
! return qw( title organization description location
! required_skills recommended_skills
! application_info contact phone fax email url );
}
+ sub MY_EDIT_FIELDS_DATE { return qw( deadline ) }
+ sub MY_ALLOW_SEARCH_FORM { return 1 }
+ sub MY_ALLOW_SEARCH { return 1 }
+ sub MY_ALLOW_SHOW { return 1 }
+ sub MY_ALLOW_EDIT { return 1 }
+ sub MY_ALLOW_REMOVE { return 1 }
+ sub MY_ALLOW_WIZARD { return undef }
! # Read in the 'keyword' search field and set both title and
! # description; also read in the 'posted_after' date and find dates
! # after that
! sub _search_build_where_customize {
! my ( $class, $tables, $where, $value ) = @_;
! my $R = OpenInteract::Request->instance;
! my $apr = $R->apache;
!
! my $keyword = $class->_read_field( $apr, 'keyword' );
! if ( $keyword ) {
! push @{ $where }, '( classified.title LIKE ? OR classified.description LIKE ? )';
! push @{ $value }, "%$keyword%", "%$keyword%";
}
!
! my $post_after = $class->_read_field_date( $apr, 'posted_after' );
! if ( $post_after ) {
! push @{ $where }, 'posted_on >= ?';
! push @{ $value }, $post_after;
}
+ }
! # We present dates to the user in three separate fields
!
! sub _read_field_date {
! my ( $class, $apr, $field ) = @_;
! return join( '-', $apr->param( $field . '_year' ),
! $apr->param( $field . '_month' ),
! $apr->param( $field . '_day' ) );
}
! # If the user has WRITE access to the object, then he/she is an admin
! # and can set active, expires_on and active_on
!
! # All new objects are NOT active until approved by an admin
! # (unless an admin is the one doing the editing...)
!
! # Set 'expires_on' if not set
!
!
! sub _edit_customize {
! my ( $class, $classified, $old_data ) = @_;
my $R = OpenInteract::Request->instance;
! my $now = $classified->now;
! # Set the 'posted_by' and 'posted_on' if a new item
! unless ( $classified->is_saved ) {
! $classified->{posted_by} = $R->{auth}{user}->id;
! $classified->{posted_on} = $now;
! $classified->{active} = 'no';
}
! # User is defined as an administrator if they are a member of the
! # 'site admin' group. This could obviously be changed...
+ my $is_admin = 0;
+ my $site_admin_id = $R->CONFIG->{default_objects}{site_admin_group};
+ foreach my $group ( @{ $R->{auth}{group} } ) {
+ $is_admin++ if ( $group->id == $site_admin_id );
+ }
! if ( $is_admin ) {
! my $apr = $R->apache;
! $classified->{active} = $class->_read_field( $apr, 'active' );
! $classified->{active_on} ||= $now;
! unless ( $classified->{expires_on} ) {
! my $expire_time = $R->{time} + DEFAULT_EXPIRE;
! my @t = localtime( $expire_time );
! $classified->{expires_on} = join '-', $t[5] + 1900, $t[4] + 1, $t[3];
}
}
}
***************
*** 172,189 ****
my $R = OpenInteract::Request->instance;
my @classified_id = $R->apache->param( 'classified_id' );
! my $email = $R->apache->param( 'email' );
! if ( ! $email or ! scalar @classified_id ) {
return '<h2 align="center">Error</h2>' .
'<p>Error: Cannot notify anyone about an object when no ID/email is given.</p>';
}
my @classified_list = ();
! foreach my $nid ( @classified_id ) {
! my $classified = $R->classified->fetch( $nid );
push @classified_list, $classified if ( $classified );
}
! my $rv = $R->classified->notify({ email => $email,
subject => 'Classified notification',
! object => \@classified_list,
! type => 'classified' });
if ( $rv ) {
return '<h2 align="center">Success!</h2>' .
--- 139,156 ----
my $R = OpenInteract::Request->instance;
my @classified_id = $R->apache->param( 'classified_id' );
! my $email = $R->apache->param( 'email' );
! unless ( $email and scalar @classified_id ) {
return '<h2 align="center">Error</h2>' .
'<p>Error: Cannot notify anyone about an object when no ID/email is given.</p>';
}
my @classified_list = ();
! foreach my $notify_id ( @classified_id ) {
! my $classified = $R->classified->fetch( $notify_id );
push @classified_list, $classified if ( $classified );
}
! my $rv = $R->classified->notify({ email => $email,
subject => 'Classified notification',
! object => \@classified_list,
! type => 'classified' });
if ( $rv ) {
return '<h2 align="center">Success!</h2>' .
***************
*** 193,196 ****
--- 160,164 ----
'<p>Error sending email. Please check error logs!</p>';
}
+
1;
|