package contacts / "name per packages", RT#22185
authorIvan Kohler <ivan@freeside.biz>
Fri, 19 Apr 2013 20:05:56 +0000 (13:05 -0700)
committerIvan Kohler <ivan@freeside.biz>
Fri, 19 Apr 2013 20:05:56 +0000 (13:05 -0700)
httemplate/misc/change_pkg_contact.html [new file with mode: 0755]
httemplate/misc/process/change_pkg_contact.html [new file with mode: 0644]
httemplate/view/cust_main/packages/contact.html

diff --git a/httemplate/misc/change_pkg_contact.html b/httemplate/misc/change_pkg_contact.html
new file mode 100755 (executable)
index 0000000..d9da5be
--- /dev/null
@@ -0,0 +1,70 @@
+<& /elements/header-popup.html, mt("Change Package Contact") &>
+
+<& /elements/error.html &>
+
+<FORM ACTION="<% $p %>misc/process/change_pkg_contact.html" METHOD=POST>
+<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
+
+<% ntable('#cccccc') %>
+
+  <TR>
+    <TH ALIGN="right"><% mt('Package') |h %></TH>
+    <TD COLSPAN=7>
+      <% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B> - <% $part_pkg->comment |h %>
+    </TD>
+  </TR>
+
+% if ( $cust_pkg->contactnum ) {
+    <TR>
+      <TH ALIGN="right"><% mt('Current Contact') %></TH>
+      <TD COLSPAN=7>
+        <% $cust_pkg->contact_obj->line |h %>
+      </TD>
+    </TR>
+% }
+
+<& /elements/tr-select-contact.html,
+             'label'         => mt('New Contact'), #XXX test
+             'cgi'           => $cgi,
+             'cust_main'     => $cust_pkg->cust_main,
+&>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE    = "submit"
+       VALUE   = "<% $cust_pkg->contactnum ? mt("Change contact") : mt("Add contact") |h %>"
+>
+
+</FORM>
+</BODY>
+</HTML>
+
+<%init>
+
+my $conf = new FS::Conf;
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+  unless $curuser->access_right('Change customer package');
+
+my $pkgnum = scalar($cgi->param('pkgnum'));
+$pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum";
+$pkgnum = $1;
+
+my $cust_pkg =
+  qsearchs({
+    'table'     => 'cust_pkg',
+    'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
+    'hashref'   => { 'pkgnum' => $pkgnum },
+    'extra_sql' => ' AND '. $curuser->agentnums_sql,
+  }) or die "unknown pkgnum $pkgnum";
+
+my $cust_main = $cust_pkg->cust_main
+  or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
+         " ( pkgnum ". cust_pkg->pkgnum. ")";
+
+my $part_pkg = $cust_pkg->part_pkg;
+
+</%init>
diff --git a/httemplate/misc/process/change_pkg_contact.html b/httemplate/misc/process/change_pkg_contact.html
new file mode 100644 (file)
index 0000000..2795c11
--- /dev/null
@@ -0,0 +1,49 @@
+<% header(emt("Package contact $past_method")) %>
+  <SCRIPT TYPE="text/javascript">
+    window.top.location.reload();
+  </SCRIPT>
+  </BODY>
+</HTML>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Change customer package');
+
+#untaint pkgnum
+my $pkgnum = $cgi->param('pkgnum');
+$pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
+$pkgnum = $1;
+
+my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} ); #needs agent virt
+
+my $contactnum = $cgi->param('contactnum');
+$contactnum =~ /^(-?\d*)$/ or die "Illegal contactnum";
+$contactnum = $1;
+
+my $past_method = $cust_pkg->contactnum ? 'changed' : 'added';
+
+my $error = '';
+
+if ( $contactnum == -1 ) {
+
+  #little false laziness w/edit/process/quick-cust_pkg.cgi, also the whole
+  # thing should be a single transaction
+  my $contact = new FS::contact {
+    'custnum' => $cust_pkg->custnum,
+    map { $_ => scalar($cgi->param("contactnum_$_")) } qw( first last )
+  };
+  $error = $contact->insert;
+  $cust_pkg->contactnum( $contact->contactnum );
+
+} else {
+  $cust_pkg->contactnum($contactnum);
+}
+
+$error ||= $cust_pkg->replace;
+
+if ($error) {
+  $cgi->param('error', $error);
+  print $cgi->redirect(popurl(2). "change_pkg_contact.html?". $cgi->query_string );
+}
+
+</%init>
index dd78239..9312991 100644 (file)
@@ -31,6 +31,8 @@ sub pkg_change_contact_link {
     'label'       => emt('Change'), # contact'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
+    'width'       => 616,
+    'height'      => 220,
   );
 }
 
@@ -42,6 +44,8 @@ sub pkg_add_contact_link {
     'label'       => emt('Add contact'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
+    'width'       => 616,
+    'height'      => 192,
   );
 }