RT#18834: Cacti integration [database storage]
[freeside.git] / httemplate / misc / cacti_graphs.html
index 9cc5e24..90a4350 100644 (file)
 process();
 </SCRIPT>
 
-% } else {
-%   if ($error) {
+% } elsif ($error) {
 
-<P><% $error %></P>
+<P><% emt($error) %></P>
+<FORM NAME="CactiGraphForm" ID="CactiGraphForm" style="margin-top: 0">
+<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
+<INPUT TYPE="hidden" NAME="load" VALUE="1">
+<INPUT TYPE="submit" VALUE="Reload Graphs">
+</FORM>
 
-%   } else {
+% } else {
 
-<% slurp($htmlfile) %>
+<% $content %>
 
-%   }
 % }
 
 <%init>
 use File::Slurp qw( slurp );
 
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
+
 my $svcnum    = $cgi->param('svcnum') or die 'Illegal svcnum';
 my $load      = $cgi->param('load');
-my $graphnum  = $cgi->param('graphnum');
-
-my $htmlfile = $FS::UID::cache_dir 
-             . '/cacti-graphs/'
-             . 'svc_'
-             . $svcnum;
-$htmlfile .= '_graph_' . $graphnum
-  if $graphnum;
-$htmlfile .= '.html';
+my $graphnum  = $cgi->param('graphnum') || '';
+
+my ($content,$error);
+unless ($load) {
+  my $page = qsearchs({
+    'table'    => 'cacti_page',
+    'hashref'  => { 'svcnum' => $svcnum, 'graphnum' => $graphnum },
+  });
+  if ($page) {
+    $content = $page->content;
+  } else {
+    $error = 'No graphs found in import cache.  Click below to retry import.';
+  }
+}
 
-my $error = (-e $htmlfile) ? '' : 'File not found';
 </%init>