summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authormark <mark>2009-08-09 09:05:38 +0000
committermark <mark>2009-08-09 09:05:38 +0000
commit283ea2b5137ae3ec36882b492e6de024b0ce6027 (patch)
tree25edd2e6f0ba3446c13a5b3e4417cfba0447d62f /httemplate/edit
parentc183de0b7e942672cafdc1c14a203e389ffd2c43 (diff)
Add cust_attachment stuff
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-xhttemplate/edit/cust_main_attach.cgi58
-rw-r--r--httemplate/edit/process/cust_main_attach.cgi88
2 files changed, 146 insertions, 0 deletions
diff --git a/httemplate/edit/cust_main_attach.cgi b/httemplate/edit/cust_main_attach.cgi
new file mode 100755
index 000000000..7c9e407d9
--- /dev/null
+++ b/httemplate/edit/cust_main_attach.cgi
@@ -0,0 +1,58 @@
+<% include('/elements/header-popup.html', "$action File Attachment") %>
+
+<% include('/elements/error.html') %>
+
+<FORM ACTION="<% popurl(1) %>process/cust_main_attach.cgi" METHOD=POST ENCTYPE="multipart/form-data">
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
+<INPUT TYPE="hidden" NAME="attachnum" VALUE="<% $attachnum %>">
+
+<BR><BR>
+
+% if(defined $attach) {
+Filename <INPUT TYPE="text" NAME="filename" VALUE="<% $attach->filename %>"><BR>
+MIME type <INPUT TYPE="text" NAME="mime_type" VALUE="<% $attach->mime_type %>"<BR>
+Size: <% $attach->size %><BR>
+
+% }
+% else { # !defined $attach
+
+Filename <INPUT TYPE="file" NAME="file"><BR>
+
+% }
+
+<BR>
+<INPUT TYPE="submit" NAME="submit"
+ VALUE="<% $attachnum ? "Apply Changes" : "Upload File" %>">
+
+% if(defined $attach) {
+<BR>
+<INPUT TYPE="submit" NAME="delete" value="Delete File">
+% }
+
+</FORM>
+</BODY>
+</HTML>
+
+<%init>
+
+my $attachnum = '';
+my $attach;
+if ( $cgi->param('error') ) {
+ #$comment = $cgi->param('comment');
+} elsif ( $cgi->param('attachnum') =~ /^(\d+)$/ ) {
+ $attachnum = $1;
+ die "illegal query ". $cgi->keywords unless $attachnum;
+ $attach = qsearchs('cust_attachment', { 'attachnum' => $attachnum });
+ die "no such attachment: ". $attachnum unless $attach;
+}
+
+$cgi->param('custnum') =~ /^(\d+)$/ or die "illegal custnum";
+my $custnum = $1;
+
+my $action = $attachnum ? 'Edit' : 'Add';
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right("$action customer note");
+
+</%init>
+
diff --git a/httemplate/edit/process/cust_main_attach.cgi b/httemplate/edit/process/cust_main_attach.cgi
new file mode 100644
index 000000000..51eead076
--- /dev/null
+++ b/httemplate/edit/process/cust_main_attach.cgi
@@ -0,0 +1,88 @@
+%if ($error) {
+% $cgi->param('error', $error);
+<% $cgi->redirect(popurl(2). 'cust_main_attach.cgi?'. $cgi->query_string ) %>
+%} else {
+% my $act = 'added';
+% $act = 'updated' if ($attachnum);
+% $act = 'undeleted' if($attachnum and $undelete);
+% $act = 'deleted' if($attachnum and $delete);
+<% header('Attachment ' . $act ) %>
+ <SCRIPT TYPE="text/javascript">
+ window.top.location.reload();
+ </SCRIPT>
+ </BODY></HTML>
+% }
+<%init>
+
+my $error;
+$cgi->param('custnum') =~ /^(\d+)$/
+ or die "Illegal custnum: ". $cgi->param('custnum');
+my $custnum = $1;
+
+$cgi->param('attachnum') =~ /^(\d*)$/
+ or die "Illegal attachnum: ". $cgi->param('attachnum');
+my $attachnum = $1;
+
+my $otaker = $FS::CurrentUser::CurrentUser->name;
+$otaker = $FS::CurrentUser::CurrentUser->username
+ if ($otaker eq "User, Legacy");
+
+my $delete = $cgi->param('delete');
+my $undelete = $cgi->param('undelete');
+
+my $new = new FS::cust_attachment ( {
+ attachnum => $attachnum,
+ custnum => $custnum,
+ _date => time,
+ otaker => $otaker,
+ disabled => '',
+});
+my $old;
+
+if($attachnum) {
+ $old = qsearchs('cust_attachment', { attachnum => $attachnum });
+ if(!$old) {
+ $error = "Attachnum '$attachnum' not found";
+ }
+ else {
+ map { $new->$_($old->$_) }
+ ('_date', 'otaker', 'body', 'disabled');
+ $new->filename($cgi->param('filename') || $old->filename);
+ $new->mime_type($cgi->param('mime_type') || $old->mime_type);
+ if($delete and not $old->disabled) {
+ $new->disabled(time);
+ }
+ if($undelete and $old->disabled) {
+ $new->disabled('');
+ }
+ }
+}
+else { # This is a new attachment, so require a file.
+
+ my $filename = $cgi->param('file');
+ if($filename) {
+ $new->filename($filename);
+ $new->mime_type($cgi->uploadInfo($filename)->{'Content-Type'});
+
+ local $/;
+ my $fh = $cgi->upload('file');
+ $new->body(<$fh>);
+ }
+ else {
+ $error = 'No file uploaded';
+ }
+}
+my $user = $FS::CurrentUser::CurrentUser;
+
+$error = 'access denied' unless $user->access_right(($old ? 'Edit' : 'Add') . ' attachment');
+
+if(!$error) {
+ if($old) {
+ $error = $new->replace($old);
+ }
+ else {
+ $error = $new->insert;
+ }
+}
+
+</%init>