View | Details | Raw Unified | Return to bug 6269
Collapse All | Expand All

(-)a/labels/label-edit-template.pl (-20 / +16 lines)
Lines 50-58 my $units = get_unit_values(); Link Here
50
if ($op eq 'edit') {
50
if ($op eq 'edit') {
51
    $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
51
    $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
52
    $profile_list = get_all_profiles(field_list => 'profile_id,printer_name,paper_bin',filter => "template_id=$template_id OR template_id=''");
52
    $profile_list = get_all_profiles(field_list => 'profile_id,printer_name,paper_bin',filter => "template_id=$template_id OR template_id=''");
53
    push @$profile_list, {paper_bin => 'N/A', profile_id => 0, printer_name => 'No Profile'};
53
}
54
}
54
elsif ($op eq 'save') {
55
elsif ($op eq 'save') {
55
    my @params = (      profile_id      => $cgi->param('profile_id') || '',
56
    my @params = (      profile_id      => $cgi->param('profile_id'),
56
                        template_code   => $cgi->param('template_code') || 'DEFAULT_TEMPLATE',
57
                        template_code   => $cgi->param('template_code') || 'DEFAULT_TEMPLATE',
57
                        template_desc   => $cgi->param('template_desc') || 'Default description',
58
                        template_desc   => $cgi->param('template_desc') || 'Default description',
58
                        page_width      => $cgi->param('page_width') || 0,
59
                        page_width      => $cgi->param('page_width') || 0,
Lines 69-78 elsif ($op eq 'save') { Link Here
69
                        row_gap         => $cgi->param('row_gap') || 0,
70
                        row_gap         => $cgi->param('row_gap') || 0,
70
                        units           => $cgi->param('units') || 'POINT',
71
                        units           => $cgi->param('units') || 'POINT',
71
                        );
72
                        );
72
    if ($template_id) {   # if a label_id was passed in, this is an update to an existing layout
73
    if ($template_id) {   # if a template_id was passed in, this is an update to an existing template
73
        $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
74
        $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
74
        if ($cgi->param('profile_id') && ($label_template->get_attr('template_id') != $cgi->param('profile_id'))) {
75
        if ($cgi->param('profile_id') && ($label_template->get_attr('template_id') != $cgi->param('profile_id'))) {
75
            if ($label_template->get_attr('profile_id') > 0) {   # no need to get the old one if there was no profile associated
76
            # Release the old profile if one is currently associated
77
            if ($label_template->get_attr('profile_id') > 0) {
76
                my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
78
                my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
77
                $old_profile->set_attr(template_id => 0);
79
                $old_profile->set_attr(template_id => 0);
78
                $old_profile->save();
80
                $old_profile->save();
Lines 81-103 elsif ($op eq 'save') { Link Here
81
            $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
83
            $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
82
            $new_profile->save();
84
            $new_profile->save();
83
        }
85
        }
86
        elsif ($cgi->param('profile_id') == 0) { # Disassociate any printer profile from the template
87
            if ($label_template->get_attr('profile_id') > 0) {
88
                my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
89
                $old_profile->set_attr(template_id => 0);
90
                $old_profile->save();
91
            }
92
        }
84
93
85
#        if ($cgi->param('profile_id')) {
86
#            my $old_profile = ($label_template->get_attr('profile_id') ? C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id')) : undef);
87
#            my $new_profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
88
#            if ($label_template->get_attr('template_id') != $new_profile->get_attr('template_id')) {
89
#                $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
90
#                $new_profile->save();
91
#                if ($old_profile) {
92
#                    $old_profile->set_attr(template_id => 0);
93
#                    $old_profile->save();
94
#                }
95
#            }
96
#        }
97
        $label_template->set_attr(@params);
94
        $label_template->set_attr(@params);
98
        $label_template->save();
95
        $label_template->save();
99
    }
96
    }
100
    else {      # if no label_id, this is a new layout so insert it
97
    else {      # if no template_id, this is a new template so insert it
101
        $label_template = C4::Labels::Template->new(@params);
98
        $label_template = C4::Labels::Template->new(@params);
102
        my $template_id = $label_template->save();
99
        my $template_id = $label_template->save();
103
        if ($cgi->param('profile_id')) {
100
        if ($cgi->param('profile_id')) {
Lines 111-120 elsif ($op eq 'save') { Link Here
111
}
108
}
112
else {  # if we get here, this is a new layout
109
else {  # if we get here, this is a new layout
113
    $label_template = C4::Labels::Template->new();
110
    $label_template = C4::Labels::Template->new();
114
}
111
    $profile_list = get_all_profiles(field_list => 'profile_id,printer_name,paper_bin',filter => "template_id=''");
115
if ($template_id) {
112
    push @$profile_list, {paper_bin => 'N/A', profile_id => 0, printer_name => 'No Profile'};
116
    foreach my $profile (@$profile_list) {
113
    foreach my $profile (@$profile_list) {
117
        if ($profile->{'profile_id'} == $label_template->get_attr('profile_id')) {
114
        if ($profile->{'profile_id'} == 0) {
118
            $profile->{'selected'} = 1;
115
            $profile->{'selected'} = 1;
119
        }
116
        }
120
        else {
117
        else {
121
- 

Return to bug 6269