<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Add stamp or watermark to reports on the fly – ad hoc. V2]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=8168</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8168&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Add stamp or watermark to reports on the fly – ad hoc. V2.]]></description>
		<lastBuildDate>Mon, 10 Jun 2019 17:42:39 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Add stamp or watermark to reports on the fly – ad hoc. V2]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35144#p35144</link>
			<description><![CDATA[<p>@joe: good for the core?</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Mon, 10 Jun 2019 17:42:39 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35144#p35144</guid>
		</item>
		<item>
			<title><![CDATA[Re: Add stamp or watermark to reports on the fly – ad hoc. V2]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35126#p35126</link>
			<description><![CDATA[<p>I have added this to my portal. Thanks @poncho1234</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sat, 08 Jun 2019 11:05:02 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35126#p35126</guid>
		</item>
		<item>
			<title><![CDATA[Add stamp or watermark to reports on the fly – ad hoc. V2]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35007#p35007</link>
			<description><![CDATA[<p>Another way; but with a lot less changes to core:-</p><p>Add a third file to merge in \reporting\includes\pdf_report.inc</p><div class="codebox"><pre><code>--- \reporting\includes\pdf_report ORIGINAL.inc
+++ \reporting\includes\pdf_report.inc
@@ -62,6 +62,7 @@
     var $footerEnable;  // select whether to print a page footer or not
     var $footerText;  // store user-generated footer text
     var $headerTmpl;  // store the name of the currently selected header template
+    var $sheaderTmpl;
     var $tmplSize; // pdf header template size in pages
 
     var $rep_id;
@@ -944,8 +945,17 @@
             include($tmpl_php);
         }
 
+        // include related php file if any
+        $stmpl_php = find_custom_file(&quot;/reporting/forms/&quot;.$this-&gt;sheaderTmpl.&quot;watermark.php&quot;);
+        if ($stmpl_php) {
+            include($stmpl_php);
+        }
+
         if (method_exists($this, $this-&gt;headerTmpl))    // draw predefined page layout if any
             $this-&gt;{$this-&gt;headerTmpl}();
+
+        if (method_exists($this, $this-&gt;sheaderTmpl))    // draw predefined page layout if any
+            $this-&gt;{$this-&gt;sheaderTmpl}();
     }
 
     function End($email=0, $subject=&#039;&#039;) </code></pre></div><p>Add a link for a popup window in \reporting\includes\reports_classes.inc<br /></p><div class="codebox"><pre><code>--- \reporting\includes\reports_classes ORIGINAL.inc
+++ \reporting\includes\reports_classes.inc
@@ -103,7 +103,7 @@
                         false, &#039;&#039;, $SysPrefs-&gt;pdf_debug ? false : &#039;default process&#039;) . hidden(&#039;REP_ID&#039;, $report-&gt;id, false).&#039;&lt;br&gt;&lt;br&gt;&#039;;
                     $st_params .= $this-&gt;getOptions($report-&gt;get_controls(), $report-&gt;id);
                     $st_params .= &quot;\n&lt;input type=hidden name=&#039;Class&#039; value=&quot;.$cur_class.&quot;&gt;&quot;
-                        .&quot;\n&lt;/form&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\n&quot;;
+                        .&quot;\n&quot;.label_cell(viewer_link(_(&#039;Add Watermark/Stamp&#039;), &#039;reporting/includes/watermark_form.php?popup=1&#039;)).&quot;&lt;/form&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\n&quot;;
                     set_focus(&#039;Rep&#039;.$report-&gt;id);
                     $Ajax-&gt;addUpdate(true, &#039;rep_form&#039;, $st_params);
                 }
@@ -111,6 +111,7 @@
             $st_reports .= &quot;&lt;/table&gt;&quot;;
         }
 
+        $_SESSION[&quot;watermark&quot;][0] = 0;
         $st_params = &quot;&lt;div id=&#039;rep_form&#039;&gt;&quot;.
             &quot;$st_params&lt;/div&gt;&quot;;
         </code></pre></div><p>No more changes to core files</p><p>Create a file called \reporting\forms\watermark.php<br /></p><div class="codebox"><pre><code>&lt;?php
if ($_SESSION[&quot;watermark&quot;][0] == 1) {
    $wm_text = $_SESSION[&quot;watermark&quot;][1];
    $wm_color = $_SESSION[&quot;watermark&quot;][2];
    $wm_font_size = $_SESSION[&quot;watermark&quot;][3];
    $wm_setx = $_SESSION[&quot;watermark&quot;][4];
    $wm_sety = $_SESSION[&quot;watermark&quot;][5];
    $wm_rotate = $_SESSION[&quot;watermark&quot;][6];
    $wm_alpha = $_SESSION[&quot;watermark&quot;][7];

    $this-&gt;SetX($wm_setx);
    $this-&gt;SetY($wm_sety);
    $this-&gt;SetFont(&#039;&#039;,&#039;B&#039;, $wm_font_size);
    $this-&gt;setAlpha($wm_alpha);
    $this-&gt;SetTextColorArray($this-&gt;convertHTMLColorToDec($wm_color));
    $this-&gt;StartTransform();
    $this-&gt;Rotate($wm_rotate);
    $this-&gt;MultiCell(0,10, $wm_text,0,&#039;C&#039;,0,1,0,0);
    $this-&gt;StopTransform();
    $this-&gt;setAlpha(1);
    $this-&gt;SetTextColor(0, 0, 0);
    $this-&gt;SetFont(&#039;&#039;,&#039;B&#039;, 9);
}</code></pre></div><p>Create a file called \reporting\includes\watermark_form.php<br /></p><div class="codebox"><pre><code>&lt;?php
$page_security = &#039;SA_OPEN&#039;;
$path_to_root=&quot;../..&quot;;

include_once($path_to_root . &quot;/includes/session.inc&quot;);
$js = &quot;&quot;;
page(_($help_context = &quot;Add Watermark or Stamp&quot;), @$_REQUEST[&#039;popup&#039;], false, &quot;&quot;, $js);

include_once($path_to_root . &quot;/includes/ui.inc&quot;);

//--------------------------------------------------------------------------------------------

function html_type_input_cells_ex($label, $input_type, $name, $min, $max, $step, $init=null, $title=null,
    $labparams=null, $post_label=null, $submit_on_change=false)
{
    global $Ajax;

    default_focus($name);
    if (!isset($_POST[$name]) || $_POST[$name] == &quot;&quot;)
    {
        if ($init)
            $_POST[$name] = $init;
        else
            $_POST[$name] = &quot;&quot;;
    }
    if ($label != null)
        label_cell($label, $labparams);

    echo &quot;&lt;td&gt;&quot;;
    $class = $submit_on_change ? &#039;class=&quot;searchbox&quot;&#039; : &#039;&#039;;
    echo &quot;&lt;input $class type=\&quot;$input_type\&quot; name=\&quot;$name\&quot; min=\&quot;$min\&quot; max=\&quot;$max\&quot; step=\&quot;$step\&quot; value=\&quot;&quot; . $_POST[$name]. &quot;\&quot;&quot;
     .($title ? &quot; title=&#039;$title&#039;&quot;: &#039;&#039;).&quot; &gt;&quot;;
    

    if ($post_label)
        echo &quot; &quot; . $post_label;

    echo &quot;&lt;/td&gt;\n&quot;;
    $Ajax-&gt;addUpdate($name, $name, $_POST[$name]);
}

function html_type_input_row_ex($label, $input_type, $name, $min, $max, $step, $title=null, $value=null, $params=null, $post_label=null)
{
    echo &quot;&lt;tr&gt;&lt;td class=&#039;label&#039;&gt;$label&lt;/td&gt;&quot;;
    html_type_input_cells_ex(null, $input_type, $name, $min, $max, $step, $value, $title, $params, $post_label);

    echo &quot;&lt;/tr&gt;\n&quot;;
}
//--------------------------------------------------------------------------------------------

function can_process()
{
    if (strlen($_POST[&#039;wm_text&#039;]) == 0) 
    {
        display_error(_(&quot;The Watermark/Stamp Text cannot be empty.&quot;));
        set_focus(&#039;wm_text&#039;);
        return false;
    }

    if (!preg_match(&#039;/#([a-f0-9]{3}){1,2}\b/i&#039;, $_POST[&#039;wm_color&#039;]))
    {
        display_error(_(&quot;The input value - &quot;.$_POST[&#039;wm_color&#039;].&quot; is not a valid HTML colour. Input required #000 - #fff OR #000000 - #ffffff&quot;));
        set_focus(&#039;wm_color&#039;);
        return false;
    } 

    if (!check_num(&#039;wm_font_size&#039;, 4, 96)) 
    {
        display_error(_(&quot;The font size must be between 4 and 96.&quot;));
        set_focus(&#039;wm_font_size&#039;);
        return false;
    }

    if (!check_num(&#039;wm_setx&#039;, 1, 200))
    {
        display_error(_(&quot;Start Point from Left must be between 1 and 200.&quot;));
        set_focus(&#039;wm_setx&#039;);
        return false;
    }

    if (!check_num(&#039;wm_sety&#039;, 200, 612))
    {
        display_error(_(&quot;Start Point from Top must be between 200 and 612.&quot;));
        set_focus(&#039;wm_sety&#039;);
        return false;
    }

    if (!check_num(&#039;wm_rotate&#039;, 1, 360))
    {
        display_error(_(&quot;Rotation angle must be between 1 and 360.&quot;));
        set_focus(&#039;wm_rotate&#039;);
        return false;
    }

    if (!check_num(&#039;wm_alpha&#039;, 0.05, 1))
    {
        display_error(_(&quot;Transparency must be between 0.05 and 1 in steps of 0.05.&quot;));
        set_focus(&#039;wm_alpha&#039;);
        return false;
    }

    return true;
}

// unset($_SESSION[&#039;watermark&#039;]);// fixit TESTING ONLY
if(isset($_SESSION[&quot;watermark&quot;][1]) &amp;&amp; ($_SESSION[&quot;watermark&quot;][1]) != &#039;&#039;) {
    $wm_on = $_SESSION[&quot;watermark&quot;][0];
    $wm_text  = $_SESSION[&quot;watermark&quot;][1];
    $wm_color = $_SESSION[&quot;watermark&quot;][2];
    $wm_font_size = $_SESSION[&quot;watermark&quot;][3];
    $wm_setx = $_SESSION[&quot;watermark&quot;][4];
    $wm_sety = $_SESSION[&quot;watermark&quot;][5];
    $wm_rotate = $_SESSION[&quot;watermark&quot;][6];
    $wm_alpha = $_SESSION[&quot;watermark&quot;][7];
} else {
    $wm_text = &#039;&#039;;
    $wm_color = &#039;#dddddd&#039;;
    $wm_font_size = &#039;48&#039;;
    $wm_setx = &#039;30&#039;;
    $wm_sety = &#039;550&#039;;
    $wm_rotate = &#039;45&#039;;
    $wm_alpha = &#039;.5&#039;;
}

$def = get_post(array(&#039;wm_text&#039;, &#039;wm_color&#039;, &#039;wm_font_size&#039;, &#039;wm_setx&#039;, &#039;wm_sety&#039;, &#039;wm_rotate&#039;, &#039;wm_alpha&#039;));

$_POST[&#039;wm_text&#039;] = $def[&quot;wm_text&quot;];
$_POST[&#039;wm_color&#039;] = $def[&quot;wm_color&quot;];
$_POST[&#039;wm_font_size&#039;] = $def[&quot;wm_font_size&quot;];
$_POST[&#039;wm_setx&#039;] = $def[&quot;wm_setx&quot;];
$_POST[&#039;wm_sety&#039;] = $def[&quot;wm_sety&quot;];
$_POST[&#039;wm_rotate&#039;] = $def[&quot;wm_rotate&quot;];
$_POST[&#039;wm_alpha&#039;] = $def[&quot;wm_alpha&quot;];

start_form();

start_outer_table(TABLESTYLE);
table_section(1);

check_row(_(&quot;Turn Off Color Picker&quot;), &#039;color_input&#039;, null, true);
$cp_toggle = isset($_POST[&#039;color_input&#039;]) ? intval($_POST[&#039;color_input&#039;]) : 0;
$Ajax-&gt;activate(&#039;_page_body&#039;);
if (!$cp_toggle) {
    $typecolor = &#039;color&#039;;
    $input_html_text = &#039;&amp;nbsp&#039;;
} else {
    $typecolor = &#039;text&#039;;
    $input_html_text = &#039;#000 - #fff OR #000000 - #ffffff&#039;;
}

end_outer_table(1);

start_outer_table(TABLESTYLE);

table_section(1);
table_section_title(_(&quot;Quick Settings&quot;));

textarea_row(_(&quot;Watermark/Stamp Text:&quot;), &#039;wm_text&#039;, $wm_text, 35, 3);
html_type_input_row_ex(_(&quot;Watermark/Stamp Colour:&quot;), $typecolor, &#039;wm_color&#039;, 4, 7, &#039;&#039;, &#039;&#039;, $wm_color, null, $input_html_text);

table_section_title(_(&quot;Position &amp; Visibility Settings&quot;));

html_type_input_row_ex(_(&quot;Font Size:&quot;), &#039;number&#039;, &#039;wm_font_size&#039;, 4, 96, &#039;&#039;, &#039;&#039;, $wm_font_size, null, _(&quot;pt (point): 4 - 96&quot;));
html_type_input_row_ex(_(&quot;Start Point from Left:&quot;), &#039;number&#039;, &#039;wm_setx&#039;, 1, 400, &#039;&#039;, &#039;&#039;, $wm_setx, null, _(&quot;pt (point): 1 - 400&quot;));
html_type_input_row_ex(_(&quot;Start Point from Top:&quot;), &#039;number&#039;, &#039;wm_sety&#039;, 200, 612, &#039;&#039;, &#039;&#039;, $wm_sety, null, _(&quot;pt (point): 200 - 612&quot;));
html_type_input_row_ex(_(&quot;Rotation Angle:&quot;), &#039;number&#039;, &#039;wm_rotate&#039;, 1, 360, &#039;&#039;, &#039;&#039;, $wm_rotate, null, _(&quot;Degrees: 1 - 360&quot;));
html_type_input_row_ex(_(&quot;Transparency:&quot;), &#039;number&#039;, &#039;wm_alpha&#039;, 0.05, 1, 0.05, &#039;&#039;, $wm_alpha, null, _(&quot;Transparency: 0.05 - 1&quot;));

if (isset($_POST[&#039;submit&#039;]) &amp;&amp; can_process()) {
    $wm_on = 1;
    $wm_text = ($_POST[&#039;wm_text&#039;]);
    $wm_color = ($_POST[&#039;wm_color&#039;]);
    $wm_font_size = ($_POST[&#039;wm_font_size&#039;]);
    $wm_setx = ($_POST[&#039;wm_setx&#039;]);
    $wm_sety = ($_POST[&#039;wm_sety&#039;]);
    $wm_rotate = ($_POST[&#039;wm_rotate&#039;]);
    $wm_alpha = ($_POST[&#039;wm_alpha&#039;]);
    
    $wm_array=array($wm_on, $wm_text, $wm_color, $wm_font_size, $wm_setx, $wm_sety, $wm_rotate, $wm_alpha);
    
    $_SESSION[&#039;watermark&#039;]=$wm_array;
    $Ajax-&gt;activate(&#039;_page_body&#039;);
    display_notification(_(&quot;Watermark/Stamp has been added, now close window and print report.&quot;));
}

end_outer_table(1);

submit_center(&#039;submit&#039;, _(&quot;Add Watermark/Stamp&quot;), true, &#039;&#039;, &#039;default&#039;);

// submit_center(&#039;submit&#039;, _(&quot;Add Watermark/Stamp&quot;), true, _(&quot;Add Watermark/Stamp&quot;), &#039;selector&#039;); // fixit does not work
// echo &quot;&lt;pre&gt;&quot;;
// print_r ($_SESSION);
// echo &quot;&lt;pre&gt;&quot;;
end_form(2);
end_page(); </code></pre></div><p>Notes:<br />1.&nbsp; &nbsp; I cannot get popup window to close by using the submit button; currently you have close window or press ‘Back’ after pressing submit button.<br />2.&nbsp; &nbsp; Previous settings are retained for session life, so will return to ‘default’ on next login .<br />3.&nbsp; &nbsp; Will work for ALL reports including extensions.<br />4.&nbsp; &nbsp; Existing header, header2 .php &amp; .pdf if present still merge.<br />Demo <a href="https://colombiaonline.net.co/sbox/fa/tmin/index.php">here</a><br />username: demo<br />Password: password</p><p>Screenshots<br /><a href="https://imgur.com/6c7p0q0">Interface</a></p><p><a href="https://imgur.com/OK7NUZR">Result</a></p>]]></description>
			<author><![CDATA[null@example.com (poncho1234)]]></author>
			<pubDate>Wed, 22 May 2019 22:29:57 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35007#p35007</guid>
		</item>
	</channel>
</rss>
