Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Fri, 19 Apr 2013 20:54:03 +0000 (13:54 -0700)
committerIvan Kohler <ivan@freeside.biz>
Fri, 19 Apr 2013 20:54:03 +0000 (13:54 -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 c3b161b..9312991 100644 (file)
@@ -1,18 +1,15 @@
 % if ( $contact ) {
     <% $contact->line |h %>
+% if ( $show_link ) {
+        <FONT SIZE=-1>
+          (&nbsp;<%pkg_change_contact_link($cust_pkg)%>&nbsp;)
+        </FONT>
+%    }
+% } elsif ( $show_link ) {
+        <FONT SIZE=-1>
+          (&nbsp;<%pkg_add_contact_link($cust_pkg)%>&nbsp;)
+        </FONT>
 % }
-
-% if ( ! $cust_pkg->get('cancel')
-%      && $FS::CurrentUser::CurrentUser->access_right('Change customer package')
-%    )
-% {
-  <FONT SIZE=-1>
-%#XXX    (&nbsp;<%pkg_change_contact_link($cust_pkg)%>&nbsp;)
-%#  %   if ( $cust_pkg->contactnum ) {
-%#          (&nbsp;<%edit_contact_link($cust_pkg->contactnum)%>&nbsp;)
-%#  %   }
-  </FONT>
-% } 
 <%init>
 
 my $conf = new FS::Conf;
@@ -20,27 +17,45 @@ my %opt = @_;
 
 my $cust_pkg       = $opt{'cust_pkg'};
 
+my $show_link = 
+  ! $cust_pkg->get('cancel')
+  && $FS::CurrentUser::CurrentUser->access_right('Change customer package');
+
 my $contact = $cust_pkg->contact_obj;
 
 sub pkg_change_contact_link {
   my $cust_pkg = shift;
-  my $pkgpart = $cust_pkg->pkgpart;
+  #my $pkgpart = $cust_pkg->pkgpart;
   include( '/elements/popup_link-cust_pkg.html',
-#XXX
-    'action'      => $p. "misc/change_pkg.cgi?contactnum=-1",
-    'label'       => emt('Change contact'),
+    'action'      => $p. "misc/change_pkg_contact.html",
+    'label'       => emt('Change'), # contact'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
+    'width'       => 616,
+    'height'      => 220,
   );
 }
 
-sub edit_contact_link {
-  my $contactnum = shift;
-  include( '/elements/popup_link.html',
-    'action'      => $p. "edit/cust_contact.cgi?contactnum=$contactnum",
-    'label'       => emt('Edit contact'),
-    'actionlabel' => emt('Edit'),
+sub pkg_add_contact_link {
+  my $cust_pkg = shift;
+  #my $pkgpart = $cust_pkg->pkgpart;
+  include( '/elements/popup_link-cust_pkg.html',
+    'action'      => $p. "misc/change_pkg_contact.html",
+    'label'       => emt('Add contact'),
+    'actionlabel' => emt('Change'),
+    'cust_pkg'    => $cust_pkg,
+    'width'       => 616,
+    'height'      => 192,
   );
 }
 
+#sub edit_contact_link {
+#  my $contactnum = shift;
+#  include( '/elements/popup_link.html',
+#    'action'      => $p. "edit/cust_contact.cgi?contactnum=$contactnum",
+#    'label'       => emt('Edit contact'),
+#    'actionlabel' => emt('Edit'),
+#  );
+#}
+
 </%init>