App-PhotoDB
view release on metacpan or search on metacpan
lib/App/PhotoDB/handlers.pm view on Meta::CPAN
my $db = $href->{db};
my %where;
$where{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$where{format_id} = $href->{format_id} // &listchoices({db=>$db, cols=>['format_id as id', 'format as opt'], table=>'FORMAT'});
$where{bulb} = $href->{bulb} // &prompt({prompt=>'Do you need Bulb (B) shutter speed?', type=>'boolean'});
$where{time} = $href->{time} // &prompt({prompt=>'Do you need Time (T) shutter speed?', type=>'boolean'});
$where{fixed_mount} = $href->{fixed_mount} // &prompt({prompt=>'Do you need a camera with an interchangeable lens?', type=>'boolean'});
if ($where{fixed_mount} && $where{fixed_mount} != 1) {
$where{mount_id} = $href->{mount_id} // &listchoices({db=>$db, cols=>['mount_id as id', 'mount as opt'], table=>'choose_mount', where=>{'purpose'=>'Camera'}});
}
$where{focus_type_id} = $href->{focus_type_id} // &listchoices({db=>$db, cols=>['focus_type_id as id', 'focus_type as opt'], table=>'FOCUS_TYPE', 'integer'});
$where{metering} = $href->{metering} // &prompt({prompt=>'Do you need a camera with metering?', type=>'boolean'});
if ($where{metering} && $where{metering} == 1) {
$where{coupled_metering} = $href->{coupled_metering} // &prompt({prompt=>'Do you need coupled metering?', type=>'boolean'});
$where{metering_type_id} = $href->{metering_type_id} // &listchoices({db=>$db, cols=>['metering_type_id as id', 'metering as opt'], table=>'METERING_TYPE'});
}
$where{body_type_id} = $href->{body_type_id} // &listchoices({db=>$db, cols=>['body_type_id as id', 'body_type as opt'], table=>'BODY_TYPE'});
$where{negative_size_id} = $href->{negative_size_id} // &listchoices({db=>$db, cols=>['negative_size_id as id', 'negative_size as opt'], table=>'NEGATIVE_SIZE'});
$where{cable_release} = $href->{cable_release} // &prompt({prompt=>'Do you need a camera with cable release?', type=>'boolean'});
$where{power_drive} = $href->{power_drive} // &prompt({prompt=>'Do you need a camera with power drive?', type=>'boolean'});
$where{int_flash} = $href->{int_flash} // &prompt({prompt=>'Do you need a camera with internal flash?', type=>'boolean'});
$where{ext_flash} = $href->{ext_flash} // &prompt({prompt=>'Do you need a camera that supports an external flash?', type=>'boolean'});
if ($where{ext_flash} && $where{ext_flash} == 1) {
$where{pc_sync} = $href->{pc_sync} // &prompt({prompt=>'Do you need a PC sync socket?', type=>'boolean'});
$where{hotshoe} = $href->{hotshoe} // &prompt({prompt=>'Do you need a hot shoe?', type=>'boolean'});
}
if (($where{int_flash} && $where{int_flash} == 1) || ($where{ext_flash} && $where{ext_flash} == 1)) {
$where{coldshoe} = $href->{coldshoe} // &prompt({prompt=>'Do you need a cold/accessory shoe?', type=>'boolean'});
$where{flash_metering} = $href->{flash_metering} // &listchoices({db=>$db, table=>'choose_flash_protocol'});
}
$where{dof_preview} = $href->{dof_preview} // &prompt({prompt=>'Do you need a depth-of-field preview feature?', type=>'boolean'});
$where{tripod} = $href->{tripod} // &prompt({prompt=>'Do you need a tripod bush?', type=>'boolean'});
my $thinwhere = &thin(\%where);
&printlist({db=>$db, msg=>"cameras that match your criteria", table=>'camera_chooser', where=>$thinwhere});
return;
}
# Add a new negative to the database as part of a film
sub negative_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{film_id} = $href->{film_id} // &film_choose({db=>$db});
if (!&lookupval({db=>$db, col=>'camera_id', table=>'FILM', where=>{film_id=>$data{film_id}}})) {
print 'Film must be loaded into a camera before you can add negatives\n';
if (&prompt({default=>'yes', prompt=>'Load film into a camera now?', type=>'boolean'})) {
&film_load({db=>$db, film_id=>$data{film_id}});
} else {
return;
}
}
$data{frame} = $href->{frame} // &prompt({prompt=>'Frame number'});
$data{description} = $href->{description} // &prompt({prompt=>'Caption'});
$data{date} = $href->{date} // &prompt({default=>&today, prompt=>'What date was this negative taken?', type=>'date'});
$data{lens_id} = $href->{lens_id} // &listchoices({db=>$db, keyword=>'lens', table=>'choose_lens_by_film', where=>{film_id=>$data{film_id}}});
$data{shutter_speed} = $href->{shutter_speed} // &choose_shutterspeed({db=>$db, film_id=>$data{film_id}});
$data{aperture} = $href->{aperture} // &prompt({prompt=>'Aperture', type=>'decimal'});
my $filter_dia = 0;
if ($data{lens_id}) {
$filter_dia = &lookupval({db=>$db, col=>'if(filter_thread, filter_thread, 0)', table=>'LENS join LENSMODEL on LENS.lensmodel_id=LENSMODEL.lensmodel_id', where=>{lens_id=>$data{lens_id}}});
}
$data{filter_id} = $href->{filter_id} // &listchoices({db=>$db, table=>'choose_filter', where=>{'thread'=>{'>=', $filter_dia}}, inserthandler=>\&filter_add, skipok=>1, autodefault=>0});
$data{teleconverter_id} = $href->{teleconverter_id} // &listchoices({db=>$db, keyword=>'teleconverter', table=>'choose_teleconverter_by_film', where=>{film_id=>$data{film_id}}, inserthandler=>\&teleconverter_add, skipok=>1, autodefault=>0});
$data{notes} = $href->{notes} // &prompt({prompt=>'Extra notes'});
$data{mount_adapter_id} = $href->{mount_adapter_id} // &listchoices({db=>$db, table=>'choose_mount_adapter_by_film', where=>{film_id=>$data{film_id}}, skipok=>1});
$data{focal_length} = $href->{focal_length} // &prompt({default=>&lookupval({db=>$db, col=>'min_focal_length', table=>'LENS', where=>{lens_id=>$data{'lens_id'}}}), prompt=>'Focal length', type=>'integer'});
$data{latitude} = $href->{latitude} // &prompt({prompt=>'Latitude', type=>'decimal'});
$data{longitude} = $href->{longitude} // &prompt({prompt=>'Longitude', type=>'decimal'});
$data{flash} = $href->{flash} // &prompt({default=>'no', prompt=>'Was flash used?', type=>'boolean'});
$data{metering_mode} = $href->{metering_mode} // &listchoices({db=>$db, cols=>['metering_mode_id as id', 'metering_mode as opt'], table=>'METERING_MODE'});
$data{exposure_program} = $href->{exposure_program} // &listchoices({db=>$db, cols=>['exposure_program_id as id', 'exposure_program as opt'], table=>'EXPOSURE_PROGRAM'});
$data{photographer_id} = $href->{photographer_id} // &listchoices({db=>$db, keyword=>'photographer', cols=>['person_id as id', 'name as opt'], table=>'PERSON', inserthandler=>\&person_add});
if (&prompt({prompt=>'Is this negative duplicated from another?', type=>'boolean', default=>'no'})) {
$data{copy_of} = $href->{copy_of} // &chooseneg({db=>$db, oktoreturnundef=>1});
}
return &newrecord({db=>$db, data=>\%data, table=>'NEGATIVE'});
}
# Bulk add multiple negatives to the database as part of a film
sub negative_bulkadd {
my $href = shift;
my $db = $href->{db};
my %data;
$data{film_id} = $href->{film_id} // &film_choose({db=>$db});
my $num = &prompt({prompt=>'How many frames to add?', type=>'integer'});
if (&prompt({default=>'no', prompt=>"Add any other attributes to all $num negatives?", type=>'boolean'})) {
$data{description} = $href->{description} // &prompt({prompt=>'Caption'});
$data{date} = $href->{date} // &prompt({default=>&today, prompt=>'What date was this negative taken?', type=>'date'});
$data{lens_id} = $href->{lens_id} // &listchoices({db=>$db, keyword=>'lens', table=>'choose_lens_by_film', where=>{film_id=>$data{film_id}}, skipok=>1});
$data{shutter_speed} = $href->{shutter_speed} // &choose_shutterspeed({db=>$db, film_id=>$data{film_id}});
$data{aperture} = $href->{aperture} // &prompt({prompt=>'Aperture', type=>'decimal'});
$data{filter_id} = $href->{filter_id} // &listchoices({db=>$db, table=>'choose_filter', inserthandler=>\&filter_add, skipok=>1, autodefault=>0});
$data{teleconverter_id} = $href->{teleconverter_id} // &listchoices({db=>$db, keyword=>'teleconverter', table=>'choose_teleconverter_by_film', where=>{film_id=>$data{film_id}}, inserthandler=>\&teleconverter_add, skipok=>1, autodefault=>0});
$data{notes} = $href->{notes} // &prompt({prompt=>'Extra notes'});
$data{mount_adapter_id} = $href->{mount_adapter_id} // &listchoices({db=>$db, table=>'choose_mount_adapter_by_film', where=>{film_id=>$data{film_id}}, skipok=>1});
$data{focal_length} = $href->{focal_length} // &prompt({default=>&lookupval({db=>$db, col=>'min_focal_length', table=>'LENS', where=>{lens_id=>$data{lens_id}}}), prompt=>'Focal length', type=>'integer'});
$data{latitude} = $href->{latitude} // &prompt({prompt=>'Latitude', type=>'decimal'});
$data{longitude} = $href->{longitude} // &prompt({prompt=>'Longitude', type=>'decimal'});
$data{flash} = $href->{flash} // &prompt({default=>'no', prompt=>'Was flash used?', type=>'boolean'});
$data{metering_mode} = $href->{metering_mode} // &listchoices({db=>$db, cols=>['metering_mode_id as id', 'metering_mode as opt'], table=>'METERING_MODE'});
$data{exposure_program} = $href->{exposure_program} // &listchoices({db=>$db, cols=>['exposure_program_id as id', 'exposure_program as opt'], table=>'EXPOSURE_PROGRAM'});
$data{photographer_id} = $href->{photographer_id} // &listchoices({db=>$db, keyword=>'photographer', cols=>['person_id as id', 'name as opt'], table=>'PERSON', inserthandler=>\&person_add});
}
# Delete empty strings from data hash
my $thindata = &thin(\%data);
# Build query
my $sql = SQL::Abstract->new;
# Final confirmation
if (!&prompt({default=>'yes', prompt=>'Proceed?', type=>'boolean'})) {
print "Aborted!\n";
return;
}
# Execute query
for my $i (1..$num) {
# Now inside the loop, add an incremented frame number for each neg
$$thindata{frame} = $i;
# Create a new row
lib/App/PhotoDB/handlers.pm view on Meta::CPAN
&lensmodel_accessory({db=>$db, lensmodel_id=>$lensmodel_id});
}
if (&prompt({default=>'no', prompt=>'Add this lens model to a series?', type=>'boolean'})) {
&lensmodel_series({db=>$db, lensmodel_id=>$lensmodel_id});
}
return $lensmodel_id;
}
# Edit an existing lens model
sub lensmodel_edit {
my $href = shift;
my $db = $href->{db};
my $lens_id = $href->{lens_id} // &listchoices({db=>$db, table=>'choose_lens', required=>1});
my $existing = &lookupcol({db=>$db, table=>'LENS', where=>{lens_id=>$lens_id}});
$existing = @$existing[0];
# Gather data from user
my $data = &lens_prompt({db=>$db, defaults=>$existing});
# Compare new and old data to find changed fields
my $changes = &hashdiff($existing, $data);
# Update the DB
return &updaterecord({db=>$db, data=>$changes, table=>'LENS', where=>{lens_id=>$lens_id}});
}
sub lensmodel_prompt {
my $href = shift;
my $db = $href->{db};
my $defaults = $href->{defaults};
my %data;
$data{manufacturer_id} = &choose_manufacturer({db=>$db, default=>$$defaults{manufacturer_id}});
$data{model} = &prompt({prompt=>'What is the lens model?', default=>$$defaults{model}});
$data{zoom} = &prompt({prompt=>'Is this a zoom lens?', type=>'boolean', default=>$$defaults{zoom}//&parselensmodel($data{model}, 'zoom')});
if ($data{zoom} == 0) {
$data{min_focal_length} = &prompt({prompt=>'What is the focal length?', type=>'integer', default=>$$defaults{min_focal_length}//&parselensmodel($data{model}, 'minfocal')});
$data{max_focal_length} = $data{min_focal_length};
$data{nominal_min_angle_diag} = &prompt({prompt=>'What is the diagonal angle of view?', type=>'integer', default=>$$defaults{nominal_min_angle_diag}});
$data{nominal_max_angle_diag} = $data{nominal_min_angle_diag};
} else {
$data{min_focal_length} = &prompt({prompt=>'What is the minimum focal length?', type=>'integer', default=>$$defaults{min_focal_length}//&parselensmodel($data{model}, 'minfocal')});
$data{max_focal_length} = &prompt({prompt=>'What is the maximum focal length?', type=>'integer', default=>$$defaults{max_focal_length}//&parselensmodel($data{model}, 'maxfocal')});
$data{nominal_min_angle_diag} = &prompt({prompt=>'What is the minimum diagonal angle of view?', type=>'integer', default=>$$defaults{nominal_min_angle_diag}});
$data{nominal_max_angle_diag} = &prompt({prompt=>'What is the maximum diagonal angle of view?', type=>'integer', default=>$$defaults{nominal_max_angle_diag}});
}
$data{fixed_mount} = &prompt({prompt=>'Does this lens have a fixed mount?', type=>'boolean', default=>$$defaults{fixed_mount}//'no'});
if ($data{fixed_mount} == 0) {
$data{mount_id} = &listchoices({db=>$db, cols=>['mount_id as id', 'mount as opt'], table=>'choose_mount', inserthandler=>\&mount_add, default=>$$defaults{mount_id}});
$data{weight} = &prompt({prompt=>'What is the weight of the lens? (g)', type=>'integer', default=>$$defaults{weight}});
$data{length} = &prompt({prompt=>'How long is this lens? (mm)', type=>'integer', default=>$$defaults{length}});
$data{diameter} = &prompt({prompt=>'How wide is this lens? (mm)', type=>'integer', default=>$$defaults{diameter}});
}
$data{max_aperture} = &prompt({prompt=>'What is the largest lens aperture?', type=>'decimal', default=>$$defaults{max_aperture}//&parselensmodel($data{model}, 'aperture')});
$data{min_aperture} = &prompt({prompt=>'What is the smallest lens aperture?', type=>'decimal', default=>$$defaults{min_aperture}});
$data{closest_focus} = &prompt({prompt=>'How close can the lens focus? (cm)', type=>'integer', default=>$$defaults{closest_focus}});
$data{elements} = &prompt({prompt=>'How many elements does the lens have?', type=>'integer', default=>$$defaults{elements}});
$data{groups} = &prompt({prompt=>'How many groups are these elements in?', type=>'integer', default=>$$defaults{groups}});
$data{aperture_blades} = &prompt({prompt=>'How many aperture blades does the lens have?', type=>'integer', default=>$$defaults{aperture_blades}});
$data{autofocus} = &prompt({prompt=>'Does this lens have autofocus?', type=>'boolean', default=>$$defaults{autofocus}});
$data{filter_thread} = &prompt({prompt=>'What is the diameter of the filter thread? (mm)', type=>'decimal', default=>$$defaults{filter_thread}});
$data{magnification} = &prompt({prompt=>'What is the maximum magnification possible with this lens?', type=>'decimal', default=>$$defaults{magnification}});
$data{url} = &prompt({prompt=>'Informational URL for this lens', default=>$$defaults{url}});
$data{introduced} = &prompt({prompt=>'When was this lens introduced?', type=>'integer', default=>$$defaults{introduced}});
$data{discontinued} = &prompt({prompt=>'When was this lens discontinued?', type=>'integer', default=>$$defaults{discontinued}});
$data{negative_size_id} = &listchoices({db=>$db, cols=>['negative_size_id as id', 'negative_size as opt'], table=>'NEGATIVE_SIZE', inserthandler=>\&negativesize_add, default=>$$defaults{negative_size_id}});
$data{notes} = &prompt({prompt=>'Notes', default=>$$defaults{notes}});
$data{coating} = &prompt({prompt=>'What coating does this lens have?', default=>$$defaults{coating}});
$data{hood} = &prompt({prompt=>'What is the model number of the suitable hood for this lens?', default=>$$defaults{hood}});
$data{exif_lenstype} = &prompt({prompt=>'EXIF lens type code', default=>$$defaults{exif_lenstype}});
$data{rectilinear} = &prompt({prompt=>'Is this a rectilinear lens?', type=>'boolean', default=>$$defaults{rectilinear}//'yes'});
$data{image_circle} = &prompt({prompt=>'What is the diameter of the image circle?', type=>'integer', default=>$$defaults{image_circle}});
$data{formula} = &prompt({prompt=>'Does this lens have a named optical formula?', default=>$$defaults{formula}});
$data{shutter_model} = &prompt({prompt=>'What shutter does this lens incorporate?', default=>$$defaults{shutter_model}});
return \%data;
}
# Add accessory compatibility info to a lens
sub lensmodel_accessory {
my $href = shift;
my $db = $href->{db};
my $lensmodel_id = $href->{lensmodel_id} // &listchoices({db=>$db, table=>'choose_lensmodel', required=>1});
while (1) {
my %compatdata;
$compatdata{accessory_id} = $href->{accessory_id} // &listchoices({db=>$db, table=>'choose_accessory'});
$compatdata{lensmodel_id} = $lensmodel_id;
&newrecord({db=>$db, data=>\%compatdata, table=>'ACCESSORY_COMPAT'});
last if (!&prompt({default=>'yes', prompt=>'Add more accessory compatibility info?', type=>'boolean'}));
}
return;
}
# Add a lensmodel to a series
sub lensmodel_series {
my $href = shift;
my $db = $href->{db};
my %data;
$data{lensmodel_id} = $href->{lensmodel_id} // &listchoices({db=>$db, table=>'choose_lensmodel', required=>1});
$data{series_id} = $href->{series_id} // &listchoices({db=>$db, cols=>['series_id as id', 'name as opt'], table=>'SERIES', required=>1, inserthandler=>\&series_add});
return &newrecord({db=>$db, data=>\%data, table=>'SERIES_MEMBER'});
}
# Show information about a lensmodel
sub lensmodel_info {
my $href = shift;
my $db = $href->{db};
# Choose lens
my $lensmodel_id = $href->{lens_id} // &listchoices({db=>$db, table=>'choose_lensmodel', required=>1});
# Get lens data
my $lensdata = &lookupcol({db=>$db, table=>'info_lensmodel', where=>{'`Lens Model ID`'=>$lensmodel_id}});
# Show compatible accessories
my $accessories = &lookuplist({db=>$db, col=>'opt', table=>'choose_accessory_compat', where=>{lensmodel_id=>$lensmodel_id}});
${@$lensdata[0]}{'Accessories'} = $accessories;
# Show compatible cameras
my $cameras = &lookuplist({db=>$db, col=>'camera', table=>'cameralens_compat', where=>{lensmodel_id=>$lensmodel_id}});
${@$lensdata[0]}{'Cameras'} = $cameras;
lib/App/PhotoDB/handlers.pm view on Meta::CPAN
my $mount = &lookupval({db=>$db, col=>'mount', table=>'choose_mount', where=>{mount_id=>${mountid}}});
print "Showing data for $mount mount\n";
&printlist({db=>$db, msg=>"cameras with $mount mount", cols=>"distinct camera_id as id, camera as opt", table=>'cameralens_compat', where=>{mount_id=>$mountid}, order=>'opt'});
&printlist({db=>$db, msg=>"lenses with $mount mount", cols=>"distinct lens_id as id, lens as opt", table=>'cameralens_compat', where=>{mount_id=>$mountid}, order=>'opt'});
return;
}
# Add a new chemical toner to the database
sub toner_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$data{toner} = $href->{toner} // &prompt({prompt=>'What is the name of this toner?'});
$data{formulation} = $href->{formulation} // &prompt({prompt=>'What is the chemical formulation of this toner?'});
$data{stock_dilution} = $href->{stock_dilution} // &prompt({prompt=>'What is the stock dilution of this toner?'});
return &newrecord({db=>$db, data=>\%data, table=>'TONER'});
}
# Add a new type of filmstock to the database
sub filmstock_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$data{name} = $href->{name} // &prompt({prompt=>'What is the name of this filmstock?'});
$data{iso} = $href->{iso} // &prompt({prompt=>'What is the box ISO/ASA speed of this filmstock?', type=>'integer'});
$data{colour} = $href->{colour} // &prompt({prompt=>'Is this a colour film?', type=>'boolean'});
if ($data{colour} == 1) {
$data{panchromatic} = 1;
} else {
$data{panchromatic} = $href->{panchromatic} // &prompt({default=>'yes', prompt=>'Is this a panchromatic film?', type=>'boolean'});
}
$data{process_id} = $href->{process_id} // &listchoices({db=>$db, cols=>['process_id as id', 'name as opt'], table=>'PROCESS', inserthandler=>\&process_add});
return &newrecord({db=>$db, data=>\%data, table=>'FILMSTOCK'});
}
# Add a new teleconverter to the database
sub teleconverter_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$data{model} = $href->{model} // &prompt({prompt=>'What is the model of this teleconverter?'});
$data{factor} = $href->{factor} // &prompt('', 'What is the magnification factor of this teleconverter?', 'decimal');
$data{mount_id} = $href->{mount_id} // &listchoices({db=>$db, cols=>['mount_id as id', 'mount as opt'], table=>'choose_mount', where=>{'purpose'=>'Camera'}, inserthandler=>\&mount_add});
$data{elements} = $href->{elements} // &prompt({prompt=>'How many elements does this teleconverter have?', type=>'integer'});
$data{groups} = $href->{groups} // &prompt({prompt=>'How many groups are the elements arranged in?', type=>'integer'});
$data{multicoated} = $href->{multicoated} // &prompt({prompt=>'Is this teleconverter multicoated?', type=>'boolean'});
return &newrecord({db=>$db, data=>\%data, table=>'TELECONVERTER'});
}
# Add a new (optical) filter to the database
sub filter_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{type} = $href->{type} // &prompt({prompt=>'What type of filter is this?'});
$data{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$data{attenuation} = $href->{attenuation} // &prompt({prompt=>'What attenutation (in stops) does this filter have?', type=>'decimal'});
$data{thread} = $href->{thread} // &prompt({prompt=>'What diameter mounting thread does this filter have?', type=>'decimal'});
$data{qty} = $href->{qty} // &prompt({default=>1, prompt=>'How many of these filters do you have?', type=>'integer'});
return &newrecord({db=>$db, data=>\%data, table=>'FILTER'});
}
# Add a new development process to the database
sub process_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{name} = $href->{name} // &prompt({prompt=>'What is the name of this film process?'});
$data{colour} = $href->{colour} // &prompt({prompt=>'Is this a colour process?', type=>'boolean'});
$data{positive} = $href->{positive} // &prompt({prompt=>'Is this a reversal process?', type=>'boolean'});
return &newrecord({db=>$db, data=>\%data, table=>'PROCESS'});
}
# Add a filter adapter to the database
sub filter_adapt {
my $href = shift;
my $db = $href->{db};
my %data;
$data{camera_thread} = $href->{camera_thread} // &prompt({prompt=>'What diameter thread faces the camera on this filter adapter?', type=>'decimal'});
$data{filter_thread} = $href->{filter_thread} // &prompt({prompt=>'What diameter thread faces the filter on this filter adapter?', type=>'decimal'});
return &newrecord({db=>$db, data=>\%data, table=>'FILTER_ADAPTER'});
}
# Add a new manufacturer to the database
sub manufacturer_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{manufacturer} = $href->{manufacturer} // &prompt({prompt=>'What is the name of the manufacturer?', required=>1});
$data{country} = $href->{country} // &prompt({prompt=>'What country is the manufacturer based in?'});
$data{city} = $href->{city} // &prompt({prompt=>'What city is the manufacturer based in?'});
$data{url} = $href->{url} // &prompt({prompt=>'What is the main website of the manufacturer?'});
$data{founded} = $href->{founded} // &prompt({prompt=>'When was the manufacturer founded?', type=>'integer'});
$data{dissolved} = $href->{dissolved} // &prompt({prompt=>'When was the manufacturer dissolved?', type=>'integer'});
return &newrecord({db=>$db, data=>\%data, table=>'MANUFACTURER'});
}
# Add a new "other" accessory to the database
sub accessory_add {
my $href = shift;
my $db = $href->{db};
my %data;
$data{accessory_type_id} = $href->{accessory_type_id} // &listchoices({db=>$db, cols=>['accessory_type_id as id', 'accessory_type as opt'], table=>'ACCESSORY_TYPE', inserthandler=>\&accessory_type});
$data{manufacturer_id} = $href->{manufacturer_id} // &choose_manufacturer({db=>$db});
$data{model} = $href->{model} // &prompt({prompt=>'What is the model of this accessory?'});
$data{acquired} = $href->{acquired} // &prompt({default=>&today, prompt=>'When was this accessory acquired?', type=>'date'});
$data{cost} = $href->{cost} // &prompt({prompt=>'What did this accessory cost?', type=>'decimal'});
my $accessoryid = &newrecord({db=>$db, data=>\%data, table=>'ACCESSORY'});
if (&prompt({default=>'yes', prompt=>'Add camera compatibility info for this accessory?', type=>'boolean'})) {
while (1) {
my %compatdata;
$compatdata{accessory_id} = $accessoryid;
$compatdata{camera_id} = &listchoices({db=>$db, table=>'choose_camera', required=>1});
&newrecord({db=>$db, data=>\%compatdata, table=>'ACCESSORY_COMPAT', silent=>1});
last if (!&prompt({default=>'yes', prompt=>'Add another compatible camera?', type=>'boolean'}));
}
}
if (&prompt({default=>'yes', prompt=>'Add lens compatibility info for this accessory?', type=>'boolean'})) {
while (1) {
my %compatdata;
$compatdata{accessory_id} = $accessoryid;
$compatdata{lens_id} = &listchoices({db=>$db, table=>'choose_lens', required=>1});
&newrecord({db=>$db, data=>\%compatdata, table=>'ACCESSORY_COMPAT', silent=>1});
last if (!&prompt({default=>'yes', prompt=>'Add another compatible lens?', type=>'boolean'}));
}
}
return $accessoryid;
}
# Add a new type of "other" accessory to the database
sub accessory_category {
my $href = shift;
my $db = $href->{db};
my %data;
$data{accessory_type} = $href->{accessory_type} // &prompt({prompt=>'What category of accessory do you want to add?'});
return &newrecord({db=>$db, data=>\%data, table=>'ACCESSORY_TYPE'});
}
# Display info about an accessory
( run in 0.439 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )