+elsif ($op eq 'save') {
+ my @params = ( profile_id => $cgi->param('profile_id'),
+ template_code => $cgi->param('template_code') || 'DEFAULT_TEMPLATE',
+ template_desc => $cgi->param('template_desc') || 'Default description',
+ page_width => $cgi->param('page_width') || 0,
+ page_height => $cgi->param('page_height') || 0,
+ label_width => $cgi->param('label_width') || 0,
+ label_height => $cgi->param('label_height') || 0,
+ top_text_margin => $cgi->param('top_text_margin') || 0,
+ left_text_margin=> $cgi->param('left_text_margin') || 0,
+ top_margin => $cgi->param('top_margin') || 0,
+ left_margin => $cgi->param('left_margin') || 0,
+ cols => $cgi->param('cols') || 0,
+ rows => $cgi->param('rows') || 0,
+ col_gap => $cgi->param('col_gap') || 0,
+ row_gap => $cgi->param('row_gap') || 0,
+ units => $cgi->param('units') || 'POINT',
+ );
+ if ($template_id) { # if a template_id was passed in, this is an update to an existing template
+ $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
+ if ($cgi->param('profile_id') && ($label_template->get_attr('template_id') != $cgi->param('profile_id'))) {
+ # Release the old profile if one is currently associated
+ if ($label_template->get_attr('profile_id') > 0) {
+ my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
+ $old_profile->set_attr(template_id => 0);
+ $old_profile->save();
+ }
+ my $new_profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
+ $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
+ $new_profile->save();
+ }
+ elsif ($cgi->param('profile_id') == 0) { # Disassociate any printer profile from the template
+ if ($label_template->get_attr('profile_id') > 0) {
+ my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
+ $old_profile->set_attr(template_id => 0);
+ $old_profile->save();
+ }
+ }