<!DOCTYPE html>
<html lang='en'>
<head>
<title>ikiwiki-upstream - Unnamed repository; edit this file to name it for gitweb.</title>
<meta name='generator' content='cgit v1.2.3'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/cgit-css/cgit.css'/>
<link rel='stylesheet' type='text/css' href='/cgit-local/local.css'/>
<script type='text/javascript' src='/cgit.js'></script>
<link rel='shortcut icon' href='/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='https://source.jones.dk/ikiwiki-upstream/atom/doc/ikiwiki/directive/table?h=master' type='application/atom+xml'/>
<link rel='vcs-git' href='https://source.jones.dk/ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
<link rel='vcs-git' href='user@source.jones.dk:ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/'><img src='/cgit-css/cgit.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/'>index</a> : <a href='/ikiwiki-upstream/'>ikiwiki-upstream</a></td><td class='form'><form method='get'>
<input type='hidden' name='id' value='0e7b18d909bb70b407c9da14140e69dd80116385'/><select name='h' onchange='this.form.submit();'>
<option value='layoutgala'>layoutgala</option>
<option value='master' selected='selected'>master</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Unnamed repository; edit this file to name it for gitweb.</td><td class='sub right'>Jonas Smedegaard</td></tr></table>
<table class='tabs'><tr><td>
<a href='/ikiwiki-upstream/'>summary</a><a href='/ikiwiki-upstream/refs/?id=0e7b18d909bb70b407c9da14140e69dd80116385'>refs</a><a href='/ikiwiki-upstream/log/doc/ikiwiki/directive/table'>log</a><a href='/ikiwiki-upstream/tree/doc/ikiwiki/directive/table?id=0e7b18d909bb70b407c9da14140e69dd80116385'>tree</a><a href='/ikiwiki-upstream/commit/doc/ikiwiki/directive/table?id=0e7b18d909bb70b407c9da14140e69dd80116385'>commit</a><a class='active' href='/ikiwiki-upstream/diff/doc/ikiwiki/directive/table?id=0e7b18d909bb70b407c9da14140e69dd80116385'>diff</a></td><td class='form'><form class='right' method='get' action='/ikiwiki-upstream/log/doc/ikiwiki/directive/table'>
<input type='hidden' name='id' value='0e7b18d909bb70b407c9da14140e69dd80116385'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/ikiwiki-upstream/diff/?id=0e7b18d909bb70b407c9da14140e69dd80116385'>root</a>/<a href='/ikiwiki-upstream/diff/doc?id=0e7b18d909bb70b407c9da14140e69dd80116385'>doc</a>/<a href='/ikiwiki-upstream/diff/doc/ikiwiki?id=0e7b18d909bb70b407c9da14140e69dd80116385'>ikiwiki</a>/<a href='/ikiwiki-upstream/diff/doc/ikiwiki/directive?id=0e7b18d909bb70b407c9da14140e69dd80116385'>directive</a>/<a href='/ikiwiki-upstream/diff/doc/ikiwiki/directive/table?id=0e7b18d909bb70b407c9da14140e69dd80116385'>table</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='0e7b18d909bb70b407c9da14140e69dd80116385'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><div class='diffstat-header'><a href='/ikiwiki-upstream/diff/?id=0e7b18d909bb70b407c9da14140e69dd80116385'>Diffstat</a> (limited to 'doc/ikiwiki/directive/table')</div><table summary='diffstat' class='diffstat'></table><div class='diffstat-summary'>0 files changed, 0 insertions, 0 deletions</div><table summary='diff' class='diff'><tr><td></td></tr></table></div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-06-22 17:14:52 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
ight (C) 2000</span></li>
<li id="n_18" class="hl"><span class="hl slc">#</span></li>
<li id="n_19" class="hl"><span class="hl slc">#  Author: DWS Systems Inc.</span></li>
<li id="n_20" class="hl"><span class="hl slc">#     Web: http://www.sql-ledger.org</span></li>
<li id="n_21" class="hl"><span class="hl slc">#</span></li>
<li id="n_22" class="hl"><span class="hl slc"># Contributors: Thomas Bayen &lt;bayen&#64;gmx.de&gt;</span></li>
<li id="n_23" class="hl"><span class="hl slc">#               Antti Kaihola &lt;akaihola&#64;siba.fi&gt;</span></li>
<li id="n_24" class="hl"><span class="hl slc">#               Moritz Bunkus (tex)</span></li>
<li id="n_25" class="hl"><span class="hl slc">#               Jim Rawlings &lt;jim&#64;your-dba.com&gt; (DB2)</span></li>
<li id="n_26" class="hl"><span class="hl slc">#======================================================================</span></li>
<li id="n_27" class="hl"><span class="hl slc">#</span></li>
<li id="n_28" class="hl"><span class="hl slc"># This file has undergone whitespace cleanup.</span></li>
<li id="n_29" class="hl"><span class="hl slc">#</span></li>
<li id="n_30" class="hl"><span class="hl slc">#======================================================================</span></li>
<li id="n_31" class="hl"><span class="hl slc">#</span></li>
<li id="n_32" class="hl"><span class="hl slc"># main package</span></li>
<li id="n_33" class="hl"><span class="hl slc">#</span></li>
<li id="n_34" class="hl"><span class="hl slc">#======================================================================</span></li>
<li id="n_35" class="hl"></li>
<li id="n_36" class="hl"><span class="hl kwa">use </span>Math<span class="hl opt">::</span>BigFloat lib<span class="hl opt">=&gt;</span><span class="hl sng">&#39;GMP&#39;</span><span class="hl opt">;</span></li>
<li id="n_37" class="hl"><span class="hl kwa">use </span>LedgerSMB<span class="hl opt">::</span>Sysconfig<span class="hl opt">;</span></li>
<li id="n_38" class="hl"></li>
<li id="n_39" class="hl"><span class="hl kwa">package </span>Form<span class="hl opt">;</span></li>
<li id="n_40" class="hl"></li>
<li id="n_41" class="hl"></li>
<li id="n_42" class="hl"><span class="hl kwa">sub </span>new <span class="hl opt">{</span></li>
<li id="n_43" class="hl"></li>
<li id="n_44" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$type </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_45" class="hl"></li>
<li id="n_46" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$argstr </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_47" class="hl"></li>
<li id="n_48" class="hl">    <span class="hl kwc">read</span><span class="hl opt">(</span>STDIN<span class="hl opt">, </span><span class="hl kwb">$_</span><span class="hl opt">, </span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>CONTENT_LENGTH<span class="hl opt">});</span></li>
<li id="n_49" class="hl"></li>
<li id="n_50" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$argstr</span><span class="hl opt">){</span></li>
<li id="n_51" class="hl">         <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$argstr</span><span class="hl opt">;</span></li>
<li id="n_52" class="hl">    <span class="hl opt">}</span></li>
<li id="n_53" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>QUERY_STRING<span class="hl opt">}) {</span></li>
<li id="n_54" class="hl">        <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>QUERY_STRING<span class="hl opt">};</span></li>
<li id="n_55" class="hl">    <span class="hl opt">}</span></li>
<li id="n_56" class="hl"></li>
<li id="n_57" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$ARGV</span><span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">]) {</span></li>
<li id="n_58" class="hl">        <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$ARGV</span><span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">];</span></li>
<li id="n_59" class="hl">    <span class="hl opt">}</span></li>
<li id="n_60" class="hl"></li>
<li id="n_61" class="hl">    <span class="hl kwb">%$self </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/[&amp;=]/</span><span class="hl opt">;</span></li>
<li id="n_62" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%$self</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span>unescape<span class="hl opt">(</span><span class="hl sng">&quot;&quot;</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">}) }</span></li>
<li id="n_63" class="hl"></li>
<li id="n_64" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">}, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">) !~ </span><span class="hl kwd">/( |\.)/</span><span class="hl opt">) {</span></li>
<li id="n_65" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">} = </span><span class="hl kwc">lc </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">};</span></li>
<li id="n_66" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">} =~ </span><span class="hl kwd">s/( |-|,|\#|\/|\.$)/</span>_<span class="hl opt">/</span>g<span class="hl opt">;</span></li>
<li id="n_67" class="hl">    <span class="hl opt">}</span></li>
<li id="n_68" class="hl"></li>
<li id="n_69" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>menubar<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>path<span class="hl opt">} =~ </span><span class="hl kwd">/lynx/i</span><span class="hl opt">;</span></li>
<li id="n_70" class="hl">    <span class="hl slc">#menubar will be deprecated, replaced with below</span></li>
<li id="n_71" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>lynx<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>path<span class="hl opt">} =~ </span><span class="hl kwd">/lynx/i</span><span class="hl opt">;</span></li>
<li id="n_72" class="hl"></li>
<li id="n_73" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>version<span class="hl opt">} = </span><span class="hl sng">&quot;1.2.0 Beta 2&quot;</span><span class="hl opt">;</span></li>
<li id="n_74" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbversion<span class="hl opt">} = </span><span class="hl sng">&quot;1.2.0&quot;</span><span class="hl opt">;</span></li>
<li id="n_75" class="hl"></li>
<li id="n_76" class="hl">    <span class="hl kwc">bless </span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$type</span><span class="hl opt">;</span></li>
<li id="n_77" class="hl"></li>
<li id="n_78" class="hl"><span class="hl opt">}</span></li>
<li id="n_79" class="hl"></li>
<li id="n_80" class="hl"></li>
<li id="n_81" class="hl"><span class="hl kwa">sub </span>debug <span class="hl opt">{</span></li>
<li id="n_82" class="hl"></li>
<li id="n_83" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$file</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_84" class="hl"></li>
<li id="n_85" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$file</span><span class="hl opt">) {</span></li>
<li id="n_86" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>FH<span class="hl opt">, </span><span class="hl sng">&quot;&gt; </span><span class="hl ipl">$file</span><span class="hl sng">&quot;</span><span class="hl opt">) </span><span class="hl kwc">or die </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_87" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">sort keys </span><span class="hl kwb">%$self</span><span class="hl opt">) { </span><span class="hl kwc">print </span>FH <span class="hl sng">&quot;</span><span class="hl ipl">$_ </span><span class="hl sng">= </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$_</span><span class="hl sng">}</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span> <span class="hl opt">}</span></li>
<li id="n_88" class="hl">        <span class="hl kwc">close</span><span class="hl opt">(</span>FH<span class="hl opt">);</span></li>
<li id="n_89" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_90" class="hl">        <span class="hl kwc">print </span><span class="hl sng">&quot;</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_91" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">sort keys </span><span class="hl kwb">%$self</span><span class="hl opt">) { </span><span class="hl kwc">print </span><span class="hl sng">&quot;</span><span class="hl ipl">$_ </span><span class="hl sng">= </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$_</span><span class="hl sng">}</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span> <span class="hl opt">}</span></li>
<li id="n_92" class="hl">    <span class="hl opt">}</span></li>
<li id="n_93" class="hl"></li>
<li id="n_94" class="hl"><span class="hl opt">} </span></li>
<li id="n_95" class="hl"></li>
<li id="n_96" class="hl"></li>
<li id="n_97" class="hl"><span class="hl kwa">sub </span>escape <span class="hl opt">{</span></li>
<li id="n_98" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl kwb">$beenthere</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_99" class="hl"></li>
<li id="n_100" class="hl">    <span class="hl slc"># for Apache 2 we escape strings twice</span></li>
<li id="n_101" class="hl">    <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>SERVER_SIGNATURE<span class="hl opt">} =~ </span><span class="hl kwd">/Apache\/</span><span class="hl num">2</span>\<span class="hl opt">.(</span>\d<span class="hl opt">+)</span>\<span class="hl opt">.(</span>\d<span class="hl opt">+)/) &amp;&amp; !</span><span class="hl kwb">$beenthere</span><span class="hl opt">) {</span></li>
<li id="n_102" class="hl">        <span class="hl kwb">$str </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">escape</span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$1 </span><span class="hl opt">== </span><span class="hl num">0 </span><span class="hl opt">&amp;&amp; </span><span class="hl kwb">$2 </span><span class="hl opt">&lt; </span><span class="hl num">44</span><span class="hl opt">;</span></li>
<li id="n_103" class="hl">    <span class="hl opt">}</span></li>
<li id="n_104" class="hl"></li>
<li id="n_105" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/([^a-zA-Z0-9_.-])/sprintf(&quot;%%%02x&quot;, ord($1))/ge</span><span class="hl opt">;</span></li>
<li id="n_106" class="hl">    <span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_107" class="hl"></li>
<li id="n_108" class="hl"><span class="hl opt">}</span></li>
<li id="n_109" class="hl"></li>
<li id="n_110" class="hl"></li>
<li id="n_111" class="hl"><span class="hl kwa">sub </span>unescape <span class="hl opt">{</span></li>
<li id="n_112" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_113" class="hl"></li>
<li id="n_114" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">tr/+/ /</span><span class="hl opt">;</span></li>
<li id="n_115" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/\\$//</span><span class="hl opt">;</span></li>
<li id="n_116" class="hl"></li>
<li id="n_117" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/%([0-9a-fA-Z]{2})/pack(&quot;c&quot;,hex($1))/eg</span><span class="hl opt">;</span></li>
<li id="n_118" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/\r?\n/\n/g</span><span class="hl opt">;</span></li>
<li id="n_119" class="hl"></li>
<li id="n_120" class="hl">    <span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_121" class="hl"></li>
<li id="n_122" class="hl"><span class="hl opt">}</span></li>
<li id="n_123" class="hl"></li>
<li id="n_124" class="hl"></li>
<li id="n_125" class="hl"><span class="hl kwa">sub </span>quote <span class="hl opt">{</span></li>
<li id="n_126" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_127" class="hl"></li>
<li id="n_128" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str </span><span class="hl opt">&amp;&amp; ! </span><span class="hl kwc">ref</span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">)) {</span></li>
<li id="n_129" class="hl">        <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/&quot;/&amp;quot;/g</span><span class="hl opt">;</span></li>
<li id="n_130" class="hl">    <span class="hl opt">}</span></li>
<li id="n_131" class="hl"></li>
<li id="n_132" class="hl">    <span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_133" class="hl"></li>
<li id="n_134" class="hl"><span class="hl opt">}</span></li>
<li id="n_135" class="hl"></li>
<li id="n_136" class="hl"></li>
<li id="n_137" class="hl"><span class="hl kwa">sub </span>unquote <span class="hl opt">{</span></li>
<li id="n_138" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_139" class="hl"></li>
<li id="n_140" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str </span><span class="hl opt">&amp;&amp; ! </span><span class="hl kwc">ref</span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">)) {</span></li>
<li id="n_141" class="hl">        <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/&amp;quot;/&quot;/g</span><span class="hl opt">;</span></li>
<li id="n_142" class="hl">    <span class="hl opt">}</span></li>
<li id="n_143" class="hl"></li>
<li id="n_144" class="hl">    <span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_145" class="hl"></li>
<li id="n_146" class="hl"><span class="hl opt">}</span></li>
<li id="n_147" class="hl"></li>
<li id="n_148" class="hl"></li>
<li id="n_149" class="hl"><span class="hl kwa">sub </span>hide_form <span class="hl opt">{</span></li>
<li id="n_150" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$self </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_151" class="hl"></li>
<li id="n_152" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">) {</span></li>
<li id="n_153" class="hl"></li>
<li id="n_154" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">) { </span></li>
<li id="n_155" class="hl">            <span class="hl kwc">print </span>qq<span class="hl opt">|&lt;</span>input type<span class="hl opt">=</span><span class="hl sng">&quot;hidden&quot;</span> name<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span> value<span class="hl opt">=</span><span class="hl sng">&quot;|.</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;quote(</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$_</span><span class="hl sng">}).qq|&quot;</span> <span class="hl opt">/&gt;</span><span class="hl esc">\n</span><span class="hl opt">| </span></li>
<li id="n_156" class="hl">        <span class="hl opt">}</span></li>
<li id="n_157" class="hl"></li>
<li id="n_158" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_159" class="hl">        <span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">};</span></li>
<li id="n_160" class="hl"></li>
<li id="n_161" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">sort keys </span><span class="hl kwb">%$self</span><span class="hl opt">) { </span></li>
<li id="n_162" class="hl">            <span class="hl kwc">print </span>qq<span class="hl opt">|&lt;</span>input type<span class="hl opt">=</span><span class="hl sng">&quot;hidden&quot;</span> name<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span> value<span class="hl opt">=</span><span class="hl sng">&quot;|.</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;quote(</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$_</span><span class="hl sng">}).qq|&quot;</span> <span class="hl opt">/&gt;</span><span class="hl esc">\n</span><span class="hl opt">| </span></li>
<li id="n_163" class="hl">        <span class="hl opt">}</span></li>
<li id="n_164" class="hl">    <span class="hl opt">}</span></li>
<li id="n_165" class="hl"><span class="hl opt">}</span></li>
<li id="n_166" class="hl"></li>
<li id="n_167" class="hl"></li>
<li id="n_168" class="hl"><span class="hl kwa">sub </span>error <span class="hl opt">{</span></li>
<li id="n_169" class="hl"></li>
<li id="n_170" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$msg</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_171" class="hl"></li>
<li id="n_172" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>HTTP_USER_AGENT<span class="hl opt">}) {</span></li>
<li id="n_173" class="hl"></li>
<li id="n_174" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>msg<span class="hl opt">} = </span><span class="hl kwb">$msg</span><span class="hl opt">;</span></li>
<li id="n_175" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} = </span><span class="hl sng">&quot;html&quot;</span><span class="hl opt">;</span></li>
<li id="n_176" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">format_string</span><span class="hl opt">(</span><span class="hl sng">&#39;msg&#39;</span><span class="hl opt">);</span></li>
<li id="n_177" class="hl"></li>
<li id="n_178" class="hl">        <span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>pre<span class="hl opt">};</span></li>
<li id="n_179" class="hl"></li>
<li id="n_180" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(!</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">}) {</span></li>
<li id="n_181" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">header</span><span class="hl opt">;</span></li>
<li id="n_182" class="hl">        <span class="hl opt">}</span></li>
<li id="n_183" class="hl"></li>
<li id="n_184" class="hl">        <span class="hl kwc">print </span>qq<span class="hl opt">|&lt;</span>body<span class="hl opt">&gt;&lt;</span>h2 <span class="hl kwa">class</span><span class="hl opt">=</span><span class="hl sng">&quot;error&quot;</span><span class="hl opt">&gt;</span>Error<span class="hl opt">!&lt;</span><span class="hl kwd">/h2&gt; &lt;p&gt;&lt;b&gt;$self-&gt;{msg}&lt;/</span>b<span class="hl opt">&gt;&lt;/</span>body<span class="hl opt">&gt;|;</span></li>
<li id="n_185" class="hl"></li>
<li id="n_186" class="hl">        <span class="hl kwa">exit</span><span class="hl opt">;</span></li>
<li id="n_187" class="hl"></li>
<li id="n_188" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_189" class="hl"></li>
<li id="n_190" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>error_function<span class="hl opt">}) {</span></li>
<li id="n_191" class="hl">            <span class="hl opt">&amp;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>error_function<span class="hl opt">} }(</span><span class="hl kwb">$msg</span><span class="hl opt">);</span></li>
<li id="n_192" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_193" class="hl">            <span class="hl kwc">die </span><span class="hl sng">&quot;Error: </span><span class="hl ipl">$msg</span><span class="hl sng"></span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_194" class="hl">        <span class="hl opt">}</span></li>
<li id="n_195" class="hl">    <span class="hl opt">}</span></li>
<li id="n_196" class="hl"><span class="hl opt">}</span></li>
<li id="n_197" class="hl"></li>
<li id="n_198" class="hl"></li>
<li id="n_199" class="hl"><span class="hl kwa">sub </span>info <span class="hl opt">{</span></li>
<li id="n_200" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$msg</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_201" class="hl"></li>
<li id="n_202" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>HTTP_USER_AGENT<span class="hl opt">}) {</span></li>
<li id="n_203" class="hl">        <span class="hl kwb">$msg </span><span class="hl opt">=~ </span><span class="hl kwd">s/\n/&lt;br&gt;/g</span><span class="hl opt">;</span></li>
<li id="n_204" class="hl"></li>
<li id="n_205" class="hl">        <span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>pre<span class="hl opt">};</span></li>
<li id="n_206" class="hl"></li>
<li id="n_207" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(!</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">}) {</span></li>
<li id="n_208" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">header</span><span class="hl opt">;</span></li>
<li id="n_209" class="hl">            <span class="hl kwc">print </span>qq<span class="hl opt">| &lt;</span>body<span class="hl opt">&gt;|;</span></li>
<li id="n_210" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">} = </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_211" class="hl">        <span class="hl opt">}</span></li>
<li id="n_212" class="hl"></li>
<li id="n_213" class="hl">        <span class="hl kwc">print </span><span class="hl sng">&quot;&lt;b&gt;</span><span class="hl ipl">$msg</span><span class="hl sng">&lt;/b&gt;&quot;</span><span class="hl opt">;</span></li>
<li id="n_214" class="hl"></li>
<li id="n_215" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_216" class="hl"></li>
<li id="n_217" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>info_function<span class="hl opt">}) {</span></li>
<li id="n_218" class="hl">            <span class="hl opt">&amp;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>info_function<span class="hl opt">} }(</span><span class="hl kwb">$msg</span><span class="hl opt">);</span></li>
<li id="n_219" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_220" class="hl">            <span class="hl kwc">print </span><span class="hl sng">&quot;</span><span class="hl ipl">$msg</span><span class="hl sng"></span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_221" class="hl">        <span class="hl opt">}</span></li>
<li id="n_222" class="hl">    <span class="hl opt">}</span></li>
<li id="n_223" class="hl"><span class="hl opt">}</span></li>
<li id="n_224" class="hl"></li>
<li id="n_225" class="hl"></li>
<li id="n_226" class="hl"><span class="hl kwa">sub </span>numtextrows <span class="hl opt">{</span></li>
<li id="n_227" class="hl"></li>
<li id="n_228" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl kwb">$cols</span><span class="hl opt">, </span><span class="hl kwb">$maxrows</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_229" class="hl"></li>
<li id="n_230" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$rows </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_231" class="hl"></li>
<li id="n_232" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/\n/</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) { </span></li>
<li id="n_233" class="hl">        <span class="hl kwb">$rows </span><span class="hl opt">+= </span><span class="hl kwc">int </span><span class="hl opt">(((</span><span class="hl kwc">length</span><span class="hl opt">) - </span><span class="hl num">2</span><span class="hl opt">)/</span><span class="hl kwb">$cols</span><span class="hl opt">) + </span><span class="hl num">1 </span></li>
<li id="n_234" class="hl">    <span class="hl opt">}</span></li>
<li id="n_235" class="hl"></li>
<li id="n_236" class="hl">    <span class="hl kwb">$maxrows </span><span class="hl opt">= </span><span class="hl kwb">$rows </span><span class="hl kwa">unless </span><span class="hl kwc">defined </span><span class="hl kwb">$maxrows</span><span class="hl opt">;</span></li>
<li id="n_237" class="hl"></li>
<li id="n_238" class="hl">    <span class="hl kwa">return </span><span class="hl opt">(</span><span class="hl kwb">$rows </span><span class="hl opt">&gt; </span><span class="hl kwb">$maxrows</span><span class="hl opt">) ? </span><span class="hl kwb">$maxrows </span><span class="hl opt">: </span><span class="hl kwb">$rows</span><span class="hl opt">;</span></li>
<li id="n_239" class="hl"></li>
<li id="n_240" class="hl"><span class="hl opt">}</span></li>
<li id="n_241" class="hl"></li>
<li id="n_242" class="hl"></li>
<li id="n_243" class="hl"><span class="hl kwa">sub </span>dberror <span class="hl opt">{</span></li>
<li id="n_244" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$msg</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_245" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$msg</span><span class="hl sng"></span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">.</span><span class="hl kwb">$DBI</span><span class="hl opt">::</span>errstr<span class="hl opt">);</span></li>
<li id="n_246" class="hl"><span class="hl opt">}</span></li>
<li id="n_247" class="hl"></li>
<li id="n_248" class="hl"></li>
<li id="n_249" class="hl"><span class="hl kwa">sub </span>isblank <span class="hl opt">{</span></li>
<li id="n_250" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$name</span><span class="hl opt">, </span><span class="hl kwb">$msg</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_251" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$msg</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$name</span><span class="hl opt">} =~ </span><span class="hl kwd">/^\s*$/</span><span class="hl opt">;</span></li>
<li id="n_252" class="hl"><span class="hl opt">}</span></li>
<li id="n_253" class="hl"></li>
<li id="n_254" class="hl"></li>
<li id="n_255" class="hl"><span class="hl kwa">sub </span>header <span class="hl opt">{</span></li>
<li id="n_256" class="hl"></li>
<li id="n_257" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$init</span><span class="hl opt">, </span><span class="hl kwb">$headeradd</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_258" class="hl"></li>
<li id="n_259" class="hl">    <span class="hl kwa">return if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">};</span></li>
<li id="n_260" class="hl"></li>
<li id="n_261" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$stylesheet</span><span class="hl opt">, </span><span class="hl kwb">$favicon</span><span class="hl opt">, </span><span class="hl kwb">$charset</span><span class="hl opt">);</span></li>
<li id="n_262" class="hl"></li>
<li id="n_263" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>HTTP_USER_AGENT<span class="hl opt">}) {</span></li>
<li id="n_264" class="hl"></li>
<li id="n_265" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>stylesheet<span class="hl opt">} &amp;&amp; (-</span>f <span class="hl sng">&quot;css/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{stylesheet}&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_266" class="hl">            <span class="hl kwb">$stylesheet </span><span class="hl opt">= </span>qq<span class="hl opt">|&lt;</span><span class="hl kwc">link </span>rel<span class="hl opt">=</span><span class="hl sng">&quot;stylesheet&quot;</span> href<span class="hl opt">=</span><span class="hl sng">&quot;css/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{stylesheet}&quot;</span> type<span class="hl opt">=</span><span class="hl sng">&quot;text/css&quot;</span> title<span class="hl opt">=</span><span class="hl sng">&quot;LedgerSMB stylesheet&quot;</span> <span class="hl opt">/&gt;</span><span class="hl esc">\n</span><span class="hl opt">|;</span></li>
<li id="n_267" class="hl">        <span class="hl opt">}</span></li>
<li id="n_268" class="hl"></li>
<li id="n_269" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>charset<span class="hl opt">}) {</span></li>
<li id="n_270" class="hl">            <span class="hl kwb">$charset </span><span class="hl opt">= </span>qq<span class="hl opt">|&lt;</span>meta http-equiv<span class="hl opt">=</span><span class="hl sng">&quot;content-type&quot;</span> content<span class="hl opt">=</span><span class="hl sng">&quot;text/html; charset=</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{charset}&quot;</span> <span class="hl opt">/&gt;</span><span class="hl esc">\n</span><span class="hl opt">|;</span></li>
<li id="n_271" class="hl">        <span class="hl opt">}</span></li>
<li id="n_272" class="hl"></li>
<li id="n_273" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>titlebar<span class="hl opt">} = (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>title<span class="hl opt">}) ? </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{title} - </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{titlebar}&quot;</span> <span class="hl opt">: </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>titlebar<span class="hl opt">};</span></li>
<li id="n_274" class="hl"></li>
<li id="n_275" class="hl">        <span class="hl kwc">print </span>qq<span class="hl opt">|</span>Content-Type<span class="hl opt">: </span>text<span class="hl opt">/</span>html<span class="hl esc">\n\n</span></li>
<li id="n_276" class="hl"><span class="hl opt">&lt;!</span>DOCTYPE html PUBLIC <span class="hl sng">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> </li>
<li id="n_277" class="hl">        <span class="hl sng">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span class="hl opt">&gt;</span></li>
<li id="n_278" class="hl"><span class="hl opt">&lt;</span>html xmlns<span class="hl opt">=</span><span class="hl sng">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml<span class="hl opt">:</span>lang<span class="hl opt">=</span><span class="hl sng">&quot;en&quot;</span> lang<span class="hl opt">=</span><span class="hl sng">&quot;en&quot;</span><span class="hl opt">&gt;</span></li>
<li id="n_279" class="hl"><span class="hl opt">&lt;</span>head<span class="hl opt">&gt;</span></li>
<li id="n_280" class="hl">    <span class="hl opt">&lt;</span>title<span class="hl opt">&gt;</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>titlebar<span class="hl opt">}&lt;/</span>title<span class="hl opt">&gt;</span></li>
<li id="n_281" class="hl">    <span class="hl opt">&lt;</span>meta http-equiv<span class="hl opt">=</span><span class="hl sng">&quot;Pragma&quot;</span> content<span class="hl opt">=</span><span class="hl sng">&quot;no-cache&quot;</span> <span class="hl opt">/&gt;</span></li>
<li id="n_282" class="hl">    <span class="hl opt">&lt;</span>meta http-equiv<span class="hl opt">=</span><span class="hl sng">&quot;Expires&quot;</span> content<span class="hl opt">=</span><span class="hl sng">&quot;-1&quot;</span> <span class="hl opt">/&gt;</span></li>
<li id="n_283" class="hl">    <span class="hl opt">&lt;</span><span class="hl kwc">link </span>rel<span class="hl opt">=</span><span class="hl sng">&quot;shortcut icon&quot;</span> href<span class="hl opt">=</span><span class="hl sng">&quot;favicon.ico&quot;</span> type<span class="hl opt">=</span><span class="hl sng">&quot;image/x-icon&quot;</span> <span class="hl opt">/&gt;</span></li>
<li id="n_284" class="hl">    <span class="hl kwb">$stylesheet</span></li>
<li id="n_285" class="hl">    <span class="hl kwb">$charset</span></li>
<li id="n_286" class="hl">    <span class="hl opt">&lt;</span>meta name<span class="hl opt">=</span><span class="hl sng">&quot;robots&quot;</span> content<span class="hl opt">=</span><span class="hl sng">&quot;noindex,nofollow&quot;</span> <span class="hl opt">/&gt;</span></li>
<li id="n_287" class="hl">        <span class="hl kwb">$headeradd</span></li>
<li id="n_288" class="hl"><span class="hl opt">&lt;/</span>head<span class="hl opt">&gt;</span></li>
<li id="n_289" class="hl"></li>
<li id="n_290" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>pre<span class="hl opt">} </span><span class="hl esc">\n</span><span class="hl opt">|;</span></li>
<li id="n_291" class="hl">    <span class="hl opt">}</span></li>
<li id="n_292" class="hl"></li>
<li id="n_293" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>header<span class="hl opt">} = </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_294" class="hl"><span class="hl opt">}</span></li>
<li id="n_295" class="hl"></li>
<li id="n_296" class="hl"><span class="hl kwa">sub </span>redirect <span class="hl opt">{</span></li>
<li id="n_297" class="hl"></li>
<li id="n_298" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$msg</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_299" class="hl">    <span class="hl kwa">use </span>List<span class="hl opt">::</span>Util <span class="hl sng">qw(first)</span><span class="hl opt">;</span></li>
<li id="n_300" class="hl"></li>
<li id="n_301" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>callback<span class="hl opt">}) {</span></li>
<li id="n_302" class="hl"></li>
<li id="n_303" class="hl">        main<span class="hl opt">::</span>redirect<span class="hl opt">();</span></li>
<li id="n_304" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_305" class="hl"></li>
<li id="n_306" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">info</span><span class="hl opt">(</span><span class="hl kwb">$msg</span><span class="hl opt">);</span></li>
<li id="n_307" class="hl">    <span class="hl opt">}</span></li>
<li id="n_308" class="hl"><span class="hl opt">}</span></li>
<li id="n_309" class="hl"></li>
<li id="n_310" class="hl"></li>
<li id="n_311" class="hl"><span class="hl kwa">sub </span>sort_columns <span class="hl opt">{</span></li>
<li id="n_312" class="hl"></li>
<li id="n_313" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">&#64;columns</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_314" class="hl"></li>
<li id="n_315" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwc">sort</span><span class="hl opt">}) {</span></li>
<li id="n_316" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">&#64;columns</span><span class="hl opt">) {</span></li>
<li id="n_317" class="hl">            <span class="hl kwb">&#64;columns </span><span class="hl opt">= </span><span class="hl kwc">grep </span><span class="hl opt">!</span><span class="hl kwd">/^$self-&gt;{sort}$/</span><span class="hl opt">, </span><span class="hl kwb">&#64;columns</span><span class="hl opt">;</span></li>
<li id="n_318" class="hl">            <span class="hl kwc">splice </span><span class="hl kwb">&#64;columns</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwc">sort</span><span class="hl opt">};</span></li>
<li id="n_319" class="hl">        <span class="hl opt">}</span></li>
<li id="n_320" class="hl">    <span class="hl opt">}</span></li>
<li id="n_321" class="hl"></li>
<li id="n_322" class="hl">    <span class="hl kwb">&#64;columns</span><span class="hl opt">;</span></li>
<li id="n_323" class="hl"><span class="hl opt">}</span></li>
<li id="n_324" class="hl"></li>
<li id="n_325" class="hl"></li>
<li id="n_326" class="hl"><span class="hl kwa">sub </span>sort_order <span class="hl opt">{</span></li>
<li id="n_327" class="hl"></li>
<li id="n_328" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$columns</span><span class="hl opt">, </span><span class="hl kwb">$ordinal</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_329" class="hl"></li>
<li id="n_330" class="hl">    <span class="hl slc"># setup direction</span></li>
<li id="n_331" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>direction<span class="hl opt">}) {</span></li>
<li id="n_332" class="hl"></li>
<li id="n_333" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwc">sort</span><span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>oldsort<span class="hl opt">}) {</span></li>
<li id="n_334" class="hl"></li>
<li id="n_335" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>direction<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;ASC&#39;</span><span class="hl opt">) {</span></li>
<li id="n_336" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>direction<span class="hl opt">} = </span><span class="hl sng">&quot;DESC&quot;</span><span class="hl opt">;</span></li>
<li id="n_337" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_338" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>direction<span class="hl opt">} = </span><span class="hl sng">&quot;ASC&quot;</span><span class="hl opt">;</span></li>
<li id="n_339" class="hl">            <span class="hl opt">}</span></li>
<li id="n_340" class="hl">        <span class="hl opt">}</span></li>
<li id="n_341" class="hl"></li>
<li id="n_342" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_343" class="hl"></li>
<li id="n_344" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>direction<span class="hl opt">} = </span><span class="hl sng">&quot;ASC&quot;</span><span class="hl opt">;</span></li>
<li id="n_345" class="hl">    <span class="hl opt">}</span></li>
<li id="n_346" class="hl"></li>
<li id="n_347" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>oldsort<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwc">sort</span><span class="hl opt">};</span></li>
<li id="n_348" class="hl"></li>
<li id="n_349" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;a </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">sort_columns</span><span class="hl opt">(&#64;{</span><span class="hl kwb">$columns</span><span class="hl opt">});</span></li>
<li id="n_350" class="hl"></li>
<li id="n_351" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">%$ordinal</span><span class="hl opt">) {</span></li>
<li id="n_352" class="hl">        <span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">] = (</span><span class="hl kwb">$ordinal</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$_</span><span class="hl opt">]}) ? </span><span class="hl sng">&quot;</span><span class="hl ipl">$ordinal</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$a</span><span class="hl sng">[0]} </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{direction}&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;</span><span class="hl ipl">$a</span><span class="hl sng">[0] </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{direction}&quot;</span><span class="hl opt">;</span></li>
<li id="n_353" class="hl"></li>
<li id="n_354" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl num">1 </span><span class="hl opt">.. </span><span class="hl kwb">$#a</span><span class="hl opt">) { </span></li>
<li id="n_355" class="hl">            <span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$_</span><span class="hl opt">] = </span><span class="hl kwb">$ordinal</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$_</span><span class="hl opt">]} </span><span class="hl kwa">if </span><span class="hl kwb">$ordinal</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$_</span><span class="hl opt">]} </span></li>
<li id="n_356" class="hl">        <span class="hl opt">}</span></li>
<li id="n_357" class="hl"></li>
<li id="n_358" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_359" class="hl">        <span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">] .= </span><span class="hl sng">&quot; </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{direction}&quot;</span><span class="hl opt">;</span></li>
<li id="n_360" class="hl">    <span class="hl opt">}</span></li>
<li id="n_361" class="hl"></li>
<li id="n_362" class="hl">    <span class="hl kwb">$sortorder </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;,&#39;</span><span class="hl opt">, </span><span class="hl kwb">&#64;a</span><span class="hl opt">;</span></li>
<li id="n_363" class="hl">    <span class="hl kwb">$sortorder</span><span class="hl opt">;</span></li>
<li id="n_364" class="hl"><span class="hl opt">}</span></li>
<li id="n_365" class="hl"></li>
<li id="n_366" class="hl"></li>
<li id="n_367" class="hl"><span class="hl kwa">sub </span>format_amount <span class="hl opt">{</span></li>
<li id="n_368" class="hl"></li>
<li id="n_369" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">, </span><span class="hl kwb">$places</span><span class="hl opt">, </span><span class="hl kwb">$dash</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_370" class="hl"></li>
<li id="n_371" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$negative </span><span class="hl opt">;</span></li>
<li id="n_372" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">){</span></li>
<li id="n_373" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">parse_amount</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">);</span></li>
<li id="n_374" class="hl">        <span class="hl kwb">$negative </span><span class="hl opt">= (</span><span class="hl kwb">$amount </span><span class="hl opt">&lt; </span><span class="hl num">0</span><span class="hl opt">);</span></li>
<li id="n_375" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/-//</span><span class="hl opt">;</span></li>
<li id="n_376" class="hl">    <span class="hl opt">}</span></li>
<li id="n_377" class="hl"></li>
<li id="n_378" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$places </span><span class="hl opt">=~ </span><span class="hl kwd">/\d+/</span><span class="hl opt">) {</span></li>
<li id="n_379" class="hl">        <span class="hl slc">#$places = 4 if $places == 2;</span></li>
<li id="n_380" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">round_amount</span><span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">, </span><span class="hl kwb">$places</span><span class="hl opt">);</span></li>
<li id="n_381" class="hl">    <span class="hl opt">}</span></li>
<li id="n_382" class="hl"></li>
<li id="n_383" class="hl">    <span class="hl slc"># is the amount negative</span></li>
<li id="n_384" class="hl"></li>
<li id="n_385" class="hl">    <span class="hl slc"># Parse $myconfig-&gt;{numberformat}</span></li>
<li id="n_386" class="hl"></li>
<li id="n_387" class="hl"></li>
<li id="n_388" class="hl"></li>
<li id="n_389" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$ts</span><span class="hl opt">, </span><span class="hl kwb">$ds</span><span class="hl opt">) = (</span><span class="hl kwb">$1</span><span class="hl opt">, </span><span class="hl kwb">$2</span><span class="hl opt">);</span></li>
<li id="n_390" class="hl"></li>
<li id="n_391" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">) {</span></li>
<li id="n_392" class="hl"></li>
<li id="n_393" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">}) {</span></li>
<li id="n_394" class="hl"></li>
<li id="n_395" class="hl">            <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$whole</span><span class="hl opt">, </span><span class="hl kwb">$dec</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\./</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$amount</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_396" class="hl">            <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">, </span><span class="hl kwc">reverse split </span><span class="hl kwd">//</span><span class="hl opt">, </span><span class="hl kwb">$whole</span><span class="hl opt">;</span></li>
<li id="n_397" class="hl"></li>
<li id="n_398" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$places</span><span class="hl opt">) {</span></li>
<li id="n_399" class="hl">                <span class="hl kwb">$dec </span><span class="hl opt">.= </span><span class="hl sng">&quot;0&quot;</span> x <span class="hl kwb">$places</span><span class="hl opt">;</span></li>
<li id="n_400" class="hl">                <span class="hl kwb">$dec </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$dec</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl kwb">$places</span><span class="hl opt">);</span></li>
<li id="n_401" class="hl">            <span class="hl opt">}</span></li>
<li id="n_402" class="hl"></li>
<li id="n_403" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1,000.00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_404" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\d{3,}?/$&amp;,/g</span><span class="hl opt">;</span></li>
<li id="n_405" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/,$//</span><span class="hl opt">;</span></li>
<li id="n_406" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">, </span><span class="hl kwc">reverse split </span><span class="hl kwd">//</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_407" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;\.</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_408" class="hl">            <span class="hl opt">}</span></li>
<li id="n_409" class="hl"></li>
<li id="n_410" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1 000.00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_411" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\d{3,}?/$&amp; /g</span><span class="hl opt">;</span></li>
<li id="n_412" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\s$//</span><span class="hl opt">;</span></li>
<li id="n_413" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">, </span><span class="hl kwc">reverse split </span><span class="hl kwd">//</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_414" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;\.</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_415" class="hl">            <span class="hl opt">}</span></li>
<li id="n_416" class="hl"></li>
<li id="n_417" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&quot;1&#39;000.00&quot;</span><span class="hl opt">) {</span></li>
<li id="n_418" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\d{3,}?/$&amp;&#39;/g</span><span class="hl opt">;</span></li>
<li id="n_419" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/&#39;$//</span><span class="hl opt">;</span></li>
<li id="n_420" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">, </span><span class="hl kwc">reverse split </span><span class="hl kwd">//</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_421" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;\.</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_422" class="hl">            <span class="hl opt">}</span></li>
<li id="n_423" class="hl"></li>
<li id="n_424" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1.000,00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_425" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\d{3,}?/$&amp;./g</span><span class="hl opt">;</span></li>
<li id="n_426" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\.$//</span><span class="hl opt">;</span></li>
<li id="n_427" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">, </span><span class="hl kwc">reverse split </span><span class="hl kwd">//</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_428" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;,</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_429" class="hl">            <span class="hl opt">}</span></li>
<li id="n_430" class="hl"></li>
<li id="n_431" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1000,00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_432" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$whole</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_433" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;,</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_434" class="hl">            <span class="hl opt">}</span></li>
<li id="n_435" class="hl"></li>
<li id="n_436" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1000.00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_437" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$whole</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_438" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">.= </span><span class="hl sng">&quot;.</span><span class="hl ipl">$dec</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dec </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_439" class="hl">            <span class="hl opt">}</span></li>
<li id="n_440" class="hl"></li>
<li id="n_441" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dash </span><span class="hl opt">=~ </span><span class="hl kwd">/-/</span><span class="hl opt">) {</span></li>
<li id="n_442" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= (</span><span class="hl kwb">$negative</span><span class="hl opt">) ? </span><span class="hl sng">&quot;(</span><span class="hl ipl">$amount</span><span class="hl sng">)&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;</span><span class="hl ipl">$amount</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_443" class="hl">            <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$dash </span><span class="hl opt">=~ </span><span class="hl kwd">/DRCR/</span><span class="hl opt">) {</span></li>
<li id="n_444" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= (</span><span class="hl kwb">$negative</span><span class="hl opt">) ? </span><span class="hl sng">&quot;</span><span class="hl ipl">$amount </span><span class="hl sng">DR&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;</span><span class="hl ipl">$amount </span><span class="hl sng">CR&quot;</span><span class="hl opt">;</span></li>
<li id="n_445" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_446" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= (</span><span class="hl kwb">$negative</span><span class="hl opt">) ? </span><span class="hl sng">&quot;-</span><span class="hl ipl">$amount</span><span class="hl sng">&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;</span><span class="hl ipl">$amount</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_447" class="hl">            <span class="hl opt">}</span></li>
<li id="n_448" class="hl">        <span class="hl opt">}</span></li>
<li id="n_449" class="hl"></li>
<li id="n_450" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_451" class="hl"></li>
<li id="n_452" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dash </span><span class="hl kwc">eq </span><span class="hl sng">&quot;0&quot;</span> <span class="hl opt">&amp;&amp; </span><span class="hl kwb">$places</span><span class="hl opt">) {</span></li>
<li id="n_453" class="hl"></li>
<li id="n_454" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1.000,00&#39;</span><span class="hl opt">) {</span></li>
<li id="n_455" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;,&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;0&quot;</span> x <span class="hl kwb">$places</span><span class="hl opt">;</span></li>
<li id="n_456" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_457" class="hl">                <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;.&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;0&quot;</span> x <span class="hl kwb">$places</span><span class="hl opt">;</span></li>
<li id="n_458" class="hl">            <span class="hl opt">}</span></li>
<li id="n_459" class="hl"></li>
<li id="n_460" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_461" class="hl">            <span class="hl kwb">$amount </span><span class="hl opt">= (</span><span class="hl kwb">$dash </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">) ? </span><span class="hl sng">&quot;</span><span class="hl ipl">$dash</span><span class="hl sng">&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_462" class="hl">        <span class="hl opt">}</span></li>
<li id="n_463" class="hl">    <span class="hl opt">}</span></li>
<li id="n_464" class="hl"></li>
<li id="n_465" class="hl">    <span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_466" class="hl"><span class="hl opt">}</span></li>
<li id="n_467" class="hl"></li>
<li id="n_468" class="hl"></li>
<li id="n_469" class="hl"><span class="hl kwa">sub </span>parse_amount <span class="hl opt">{</span></li>
<li id="n_470" class="hl"></li>
<li id="n_471" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_472" class="hl"></li>
<li id="n_473" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$amount </span><span class="hl kwc">eq </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">) {</span></li>
<li id="n_474" class="hl">        <span class="hl kwa">return </span><span class="hl kwc">undef</span><span class="hl opt">;</span></li>
<li id="n_475" class="hl">    <span class="hl opt">}</span></li>
<li id="n_476" class="hl"></li>
<li id="n_477" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span>UNIVERSAL<span class="hl opt">::</span>isa<span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">, </span><span class="hl sng">&#39;Math::BigFloat&#39;</span><span class="hl opt">)){ </span><span class="hl slc"># Amount may not be an object   </span></li>
<li id="n_478" class="hl">        <span class="hl kwa">return </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_479" class="hl">    <span class="hl opt">}</span></li>
<li id="n_480" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$numberformat </span><span class="hl opt">= </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>numberformat<span class="hl opt">};</span></li>
<li id="n_481" class="hl"></li>
<li id="n_482" class="hl"></li>
<li id="n_483" class="hl">    <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$numberformat </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1.000,00&#39;</span><span class="hl opt">) ||</span></li>
<li id="n_484" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$numberformat </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1000,00&#39;</span><span class="hl opt">)) {</span></li>
<li id="n_485" class="hl"></li>
<li id="n_486" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\.//g</span><span class="hl opt">;</span></li>
<li id="n_487" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/,/./</span><span class="hl opt">;</span></li>
<li id="n_488" class="hl">    <span class="hl opt">}</span></li>
<li id="n_489" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$numberformat </span><span class="hl kwc">eq </span><span class="hl sng">&#39;1 000.00&#39;</span><span class="hl opt">){</span></li>
<li id="n_490" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\s//g</span><span class="hl opt">;</span></li>
<li id="n_491" class="hl">    <span class="hl opt">}</span></li>
<li id="n_492" class="hl"></li>
<li id="n_493" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$numberformat </span><span class="hl kwc">eq </span><span class="hl sng">&quot;1&#39;000.00&quot;</span><span class="hl opt">) {</span></li>
<li id="n_494" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/&#39;//g</span><span class="hl opt">;</span></li>
<li id="n_495" class="hl">    <span class="hl opt">}</span></li>
<li id="n_496" class="hl"></li>
<li id="n_497" class="hl"></li>
<li id="n_498" class="hl">    <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/,//g</span><span class="hl opt">;</span></li>
<li id="n_499" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\((\d*\.?\d*)\)/$1/</span><span class="hl opt">){</span></li>
<li id="n_500" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwb">$1 </span><span class="hl opt">* -</span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_501" class="hl">    <span class="hl opt">}</span></li>
<li id="n_502" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/(\d*\.?\d*)\s?DR/$1/</span><span class="hl opt">){</span></li>
<li id="n_503" class="hl">        <span class="hl kwb">$amount </span><span class="hl opt">= </span><span class="hl kwb">$1 </span><span class="hl opt">* -</span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_504" class="hl">    <span class="hl opt">}</span></li>
<li id="n_505" class="hl">    <span class="hl kwb">$amount </span><span class="hl opt">=~ </span><span class="hl kwd">s/\s?CR//</span><span class="hl opt">;</span></li>
<li id="n_506" class="hl">    <span class="hl kwb">$amount </span><span class="hl opt">= </span>new Math<span class="hl opt">::</span>BigFloat<span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">);</span></li>
<li id="n_507" class="hl">    <span class="hl kwa">return </span><span class="hl opt">(</span><span class="hl kwb">$amount </span><span class="hl opt">* </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_508" class="hl"><span class="hl opt">}</span></li>
<li id="n_509" class="hl"></li>
<li id="n_510" class="hl"></li>
<li id="n_511" class="hl"><span class="hl kwa">sub </span>round_amount <span class="hl opt">{</span></li>
<li id="n_512" class="hl"></li>
<li id="n_513" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$amount</span><span class="hl opt">, </span><span class="hl kwb">$places</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_514" class="hl"></li>
<li id="n_515" class="hl">    <span class="hl slc"># These rounding rules follow from the previous implementation.</span></li>
<li id="n_516" class="hl">    <span class="hl slc"># They should be changed to allow different rules for different accounts.</span></li>
<li id="n_517" class="hl">    Math<span class="hl opt">::</span>BigFloat-<span class="hl opt">&gt;</span><span class="hl kwd">round_mode</span><span class="hl opt">(</span><span class="hl sng">&#39;+inf&#39;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$amount </span><span class="hl opt">&gt;= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_518" class="hl">    Math<span class="hl opt">::</span>BigFloat-<span class="hl opt">&gt;</span><span class="hl kwd">round_mode</span><span class="hl opt">(</span><span class="hl sng">&#39;-inf&#39;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$amount </span><span class="hl opt">&lt; </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_519" class="hl"></li>
<li id="n_520" class="hl">    <span class="hl kwb">$amount </span><span class="hl opt">= </span>Math<span class="hl opt">::</span>BigFloat-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">)-&gt;</span><span class="hl kwd">ffround</span><span class="hl opt">(-</span><span class="hl kwb">$places</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$places </span><span class="hl opt">&gt;= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_521" class="hl">    <span class="hl kwb">$amount </span><span class="hl opt">= </span>Math<span class="hl opt">::</span>BigFloat-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span><span class="hl kwb">$amount</span><span class="hl opt">)-&gt;</span><span class="hl kwd">ffround</span><span class="hl opt">(-(</span><span class="hl kwb">$places</span><span class="hl opt">-</span><span class="hl num">1</span><span class="hl opt">)) </span><span class="hl kwa">if </span><span class="hl kwb">$places </span><span class="hl opt">&lt; </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_522" class="hl"></li>
<li id="n_523" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">$amount</span><span class="hl opt">;</span></li>
<li id="n_524" class="hl"><span class="hl opt">}</span></li>
<li id="n_525" class="hl"></li>
<li id="n_526" class="hl"><span class="hl kwa">sub </span>callproc <span class="hl opt">{</span></li>
<li id="n_527" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$procname </span><span class="hl opt">= </span><span class="hl kwc">shift </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_528" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$argstr </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_529" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;results</span><span class="hl opt">;</span></li>
<li id="n_530" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl num">1 </span><span class="hl opt">.. </span><span class="hl kwb">$#_</span><span class="hl opt">){</span></li>
<li id="n_531" class="hl">        <span class="hl kwb">$argstr </span><span class="hl opt">.= </span><span class="hl sng">&quot;?, &quot;</span><span class="hl opt">;</span></li>
<li id="n_532" class="hl">    <span class="hl opt">}</span></li>
<li id="n_533" class="hl">    <span class="hl kwb">$argstr </span><span class="hl opt">=~ </span><span class="hl kwd">s/\, $//</span><span class="hl opt">;</span></li>
<li id="n_534" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl sng">&quot;SELECT </span><span class="hl ipl">$procname</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_535" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">=~ </span><span class="hl kwd">s/\(\)/$argstr/</span><span class="hl opt">;</span></li>
<li id="n_536" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_537" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)){</span></li>
<li id="n_538" class="hl">        <span class="hl kwc">push </span><span class="hl kwb">&#64;results</span><span class="hl opt">, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_539" class="hl">    <span class="hl opt">}</span></li>
<li id="n_540" class="hl">    <span class="hl kwb">&#64;results</span><span class="hl opt">;</span></li>
<li id="n_541" class="hl"><span class="hl opt">}</span></li>
<li id="n_542" class="hl"></li>
<li id="n_543" class="hl"><span class="hl kwa">sub </span>get_my_emp_num <span class="hl opt">{</span></li>
<li id="n_544" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$form</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_545" class="hl">    <span class="hl kwb">%myconfig </span><span class="hl opt">= %{</span><span class="hl kwb">$myconfig</span><span class="hl opt">};</span></li>
<li id="n_546" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_547" class="hl">    <span class="hl slc"># we got a connection, check the version</span></li>
<li id="n_548" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_549" class="hl">        SELECT employeenumber FROM employee </li>
<li id="n_550" class="hl">         WHERE login <span class="hl opt">= ?|;</span></li>
<li id="n_551" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_552" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;{</span>login<span class="hl opt">}) || </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_553" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">;</span></li>
<li id="n_554" class="hl"></li>
<li id="n_555" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$id</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_556" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_557" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;{</span><span class="hl sng">&#39;emp_num&#39;</span><span class="hl opt">} = </span><span class="hl kwb">$id</span><span class="hl opt">;</span></li>
<li id="n_558" class="hl"><span class="hl opt">}</span></li>
<li id="n_559" class="hl"></li>
<li id="n_560" class="hl"><span class="hl kwa">sub </span>parse_template <span class="hl opt">{</span></li>
<li id="n_561" class="hl"></li>
<li id="n_562" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_563" class="hl"></li>
<li id="n_564" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$chars_per_line</span><span class="hl opt">, </span><span class="hl kwb">$lines_on_first_page</span><span class="hl opt">, </span><span class="hl kwb">$lines_on_second_page</span><span class="hl opt">) = (</span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">);</span></li>
<li id="n_565" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$current_page</span><span class="hl opt">, </span><span class="hl kwb">$current_line</span><span class="hl opt">) = (</span><span class="hl num">1</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_566" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$pagebreak </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_567" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sum </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_568" class="hl"></li>
<li id="n_569" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$subdir </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_570" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_571" class="hl"></li>
<li id="n_572" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%include </span><span class="hl opt">= ();</span></li>
<li id="n_573" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$ok</span><span class="hl opt">;</span></li>
<li id="n_574" class="hl"></li>
<li id="n_575" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>language_code<span class="hl opt">}) {</span></li>
<li id="n_576" class="hl"></li>
<li id="n_577" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(-</span>f <span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{language_code}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN}&quot;</span><span class="hl opt">) {</span></li>
<li id="n_578" class="hl">            <span class="hl kwc">open</span><span class="hl opt">(</span>IN<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{language_code}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN}&quot;</span><span class="hl opt">) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN} : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_579" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_580" class="hl">            <span class="hl kwc">open</span><span class="hl opt">(</span>IN<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN}&quot;</span><span class="hl opt">) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN} : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_581" class="hl">        <span class="hl opt">}</span></li>
<li id="n_582" class="hl"></li>
<li id="n_583" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_584" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>IN<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN}&quot;</span><span class="hl opt">) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{IN} : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_585" class="hl">    <span class="hl opt">}</span></li>
<li id="n_586" class="hl"></li>
<li id="n_587" class="hl">    <span class="hl kwb">&#64;_ </span><span class="hl opt">= &lt;</span>IN<span class="hl opt">&gt;;</span></li>
<li id="n_588" class="hl">    <span class="hl kwc">close</span><span class="hl opt">(</span>IN<span class="hl opt">);</span></li>
<li id="n_589" class="hl"></li>
<li id="n_590" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>copies<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>copies<span class="hl opt">} *= </span><span class="hl num">1</span><span class="hl opt">) &lt;= </span><span class="hl num">0</span><span class="hl opt">);</span></li>
<li id="n_591" class="hl"></li>
<li id="n_592" class="hl">    <span class="hl slc"># OUT is used for the media, screen, printer, email</span></li>
<li id="n_593" class="hl">    <span class="hl slc"># for postscript we store a copy in a temporary file</span></li>
<li id="n_594" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$fileid </span><span class="hl opt">= </span><span class="hl kwc">time</span><span class="hl opt">;</span></li>
<li id="n_595" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$tmpfile </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>IN<span class="hl opt">};</span></li>
<li id="n_596" class="hl">    <span class="hl kwb">$tmpfile </span><span class="hl opt">=~ </span><span class="hl kwd">s/\./_$self-&gt;{fileid}./ </span><span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>fileid<span class="hl opt">};</span></li>
<li id="n_597" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} = </span><span class="hl sng">&quot;${LedgerSMB::Sysconfig::userspath}/${fileid}_${tmpfile}&quot;</span><span class="hl opt">;</span></li>
<li id="n_598" class="hl"></li>
<li id="n_599" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} =~ </span><span class="hl kwd">/(postscript|pdf)/ </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>media<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">) {</span></li>
<li id="n_600" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$out </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">};</span></li>
<li id="n_601" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">} = </span><span class="hl sng">&quot;&gt;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile}&quot;</span><span class="hl opt">;</span></li>
<li id="n_602" class="hl">    <span class="hl opt">}</span></li>
<li id="n_603" class="hl"></li>
<li id="n_604" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">}) {</span></li>
<li id="n_605" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>OUT<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{OUT}&quot;</span><span class="hl opt">) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{OUT} : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_606" class="hl"></li>
<li id="n_607" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_608" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>OUT<span class="hl opt">, </span><span class="hl sng">&quot;&gt;-&quot;</span><span class="hl opt">) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;STDOUT : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_609" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">header</span><span class="hl opt">;</span></li>
<li id="n_610" class="hl">    <span class="hl opt">}</span></li>
<li id="n_611" class="hl"></li>
<li id="n_612" class="hl">    <span class="hl slc"># first we generate a tmpfile</span></li>
<li id="n_613" class="hl">    <span class="hl slc"># read file and replace &lt;?lsmb variable ?&gt;</span></li>
<li id="n_614" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_615" class="hl"></li>
<li id="n_616" class="hl">        <span class="hl kwb">$par </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_617" class="hl">        <span class="hl kwb">$var </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_618" class="hl"></li>
<li id="n_619" class="hl">        <span class="hl slc"># detect pagebreak block and its parameters</span></li>
<li id="n_620" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb pagebreak ([0-9]+) ([0-9]+) ([0-9]+) \?&gt;/</span><span class="hl opt">) {</span></li>
<li id="n_621" class="hl">            <span class="hl kwb">$chars_per_line </span><span class="hl opt">= </span><span class="hl kwb">$1</span><span class="hl opt">;</span></li>
<li id="n_622" class="hl">            <span class="hl kwb">$lines_on_first_page </span><span class="hl opt">= </span><span class="hl kwb">$2</span><span class="hl opt">;</span></li>
<li id="n_623" class="hl">            <span class="hl kwb">$lines_on_second_page </span><span class="hl opt">= </span><span class="hl kwb">$3</span><span class="hl opt">;</span></li>
<li id="n_624" class="hl"></li>
<li id="n_625" class="hl">            <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_626" class="hl">                <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end pagebreak \?&gt;/</span><span class="hl opt">);</span></li>
<li id="n_627" class="hl">                <span class="hl kwb">$pagebreak </span><span class="hl opt">.= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_628" class="hl">            <span class="hl opt">}</span></li>
<li id="n_629" class="hl">        <span class="hl opt">}</span></li>
<li id="n_630" class="hl"></li>
<li id="n_631" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb foreach /</span><span class="hl opt">) {</span></li>
<li id="n_632" class="hl"></li>
<li id="n_633" class="hl">            <span class="hl slc"># this one we need for the count</span></li>
<li id="n_634" class="hl">            <span class="hl kwc">chomp </span><span class="hl kwb">$var</span><span class="hl opt">;</span></li>
<li id="n_635" class="hl">            <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/.*?&lt;\?lsmb foreach (.+?) \?&gt;/$1/</span><span class="hl opt">;</span></li>
<li id="n_636" class="hl">            <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_637" class="hl">                <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end $var \?&gt;/</span><span class="hl opt">);</span></li>
<li id="n_638" class="hl"></li>
<li id="n_639" class="hl">                <span class="hl slc"># store line in $par</span></li>
<li id="n_640" class="hl">                <span class="hl kwb">$par </span><span class="hl opt">.= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_641" class="hl">            <span class="hl opt">}</span></li>
<li id="n_642" class="hl"></li>
<li id="n_643" class="hl">            <span class="hl slc"># display contents of $self-&gt;{number}[] array</span></li>
<li id="n_644" class="hl">            <span class="hl kwa">for </span><span class="hl kwb">$i </span><span class="hl opt">(</span><span class="hl num">0 </span><span class="hl opt">.. </span><span class="hl kwb">$#</span><span class="hl opt">{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$var</span><span class="hl opt">} }) {</span></li>
<li id="n_645" class="hl"></li>
<li id="n_646" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">/^(part|service)$/</span><span class="hl opt">) {</span></li>
<li id="n_647" class="hl">                    <span class="hl kwa">next if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$var</span><span class="hl opt">}[</span><span class="hl kwb">$i</span><span class="hl opt">] </span><span class="hl kwc">eq </span><span class="hl sng">&#39;NULL&#39;</span><span class="hl opt">;</span></li>
<li id="n_648" class="hl">                <span class="hl opt">}</span></li>
<li id="n_649" class="hl"></li>
<li id="n_650" class="hl">                <span class="hl slc"># Try to detect whether a manual page break is necessary</span></li>
<li id="n_651" class="hl">                <span class="hl slc"># but only if there was a &lt;?lsmb pagebreak ... ?&gt; block before</span></li>
<li id="n_652" class="hl"></li>
<li id="n_653" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl kwc">eq </span><span class="hl sng">&#39;number&#39;</span> <span class="hl opt">|| </span><span class="hl kwb">$var </span><span class="hl kwc">eq </span><span class="hl sng">&#39;part&#39;</span> <span class="hl opt">|| </span><span class="hl kwb">$var </span><span class="hl kwc">eq </span><span class="hl sng">&#39;service&#39;</span><span class="hl opt">) {</span></li>
<li id="n_654" class="hl"></li>
<li id="n_655" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$chars_per_line </span><span class="hl opt">&amp;&amp; </span><span class="hl kwc">defined </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$var</span><span class="hl opt">}) {</span></li>
<li id="n_656" class="hl"></li>
<li id="n_657" class="hl">                        <span class="hl kwc">my </span><span class="hl kwb">$line</span><span class="hl opt">;</span></li>
<li id="n_658" class="hl">                        <span class="hl kwc">my </span><span class="hl kwb">$lines </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_659" class="hl">                        <span class="hl kwc">my </span><span class="hl kwb">&#64;d </span><span class="hl opt">= </span><span class="hl sng">qw(description)</span><span class="hl opt">;</span></li>
<li id="n_660" class="hl">                        <span class="hl kwc">push </span><span class="hl kwb">&#64;d</span><span class="hl opt">, </span><span class="hl sng">&quot;itemnotes&quot;</span> <span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>countitemnotes<span class="hl opt">};</span></li>
<li id="n_661" class="hl"></li>
<li id="n_662" class="hl">                        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$item </span><span class="hl opt">(</span><span class="hl kwb">&#64;d</span><span class="hl opt">) {</span></li>
<li id="n_663" class="hl"></li>
<li id="n_664" class="hl">                            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$item</span><span class="hl opt">}[</span><span class="hl kwb">$i</span><span class="hl opt">]) {</span></li>
<li id="n_665" class="hl"></li>
<li id="n_666" class="hl">                                <span class="hl kwa">foreach </span><span class="hl kwb">$line </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/\r?\n/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$item</span><span class="hl opt">}[</span><span class="hl kwb">$i</span><span class="hl opt">]) {</span></li>
<li id="n_667" class="hl">                                    <span class="hl kwb">$lines++</span><span class="hl opt">;</span></li>
<li id="n_668" class="hl">                                    <span class="hl kwb">$lines </span><span class="hl opt">+= </span><span class="hl kwc">int</span><span class="hl opt">(</span><span class="hl kwc">length</span><span class="hl opt">(</span><span class="hl kwb">$line</span><span class="hl opt">) / </span><span class="hl kwb">$chars_per_line</span><span class="hl opt">);</span></li>
<li id="n_669" class="hl">                                <span class="hl opt">}</span></li>
<li id="n_670" class="hl">                            <span class="hl opt">}</span></li>
<li id="n_671" class="hl">                        <span class="hl opt">}</span></li>
<li id="n_672" class="hl"></li>
<li id="n_673" class="hl">                        <span class="hl kwc">my </span><span class="hl kwb">$lpp</span><span class="hl opt">;</span></li>
<li id="n_674" class="hl"></li>
<li id="n_675" class="hl">                        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$current_page </span><span class="hl opt">== </span><span class="hl num">1</span><span class="hl opt">) {</span></li>
<li id="n_676" class="hl">                            <span class="hl kwb">$lpp </span><span class="hl opt">= </span><span class="hl kwb">$lines_on_first_page</span><span class="hl opt">;</span></li>
<li id="n_677" class="hl">                        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_678" class="hl">                            <span class="hl kwb">$lpp </span><span class="hl opt">= </span><span class="hl kwb">$lines_on_second_page</span><span class="hl opt">;</span></li>
<li id="n_679" class="hl">                        <span class="hl opt">}</span></li>
<li id="n_680" class="hl"></li>
<li id="n_681" class="hl">                        <span class="hl slc"># Yes we need a manual page break</span></li>
<li id="n_682" class="hl">                        <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$current_line </span><span class="hl opt">+ </span><span class="hl kwb">$lines</span><span class="hl opt">) &gt; </span><span class="hl kwb">$lpp</span><span class="hl opt">) {</span></li>
<li id="n_683" class="hl">                            <span class="hl kwc">my </span><span class="hl kwb">$pb </span><span class="hl opt">= </span><span class="hl kwb">$pagebreak</span><span class="hl opt">;</span></li>
<li id="n_684" class="hl"></li>
<li id="n_685" class="hl">                            <span class="hl slc"># replace the special variables &lt;?lsmb sumcarriedforward ?&gt;</span></li>
<li id="n_686" class="hl">                            <span class="hl slc"># and &lt;?lsmb lastpage ?&gt;</span></li>
<li id="n_687" class="hl">                            <span class="hl kwc">my </span><span class="hl kwb">$psum </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">format_amount</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$sum</span><span class="hl opt">, </span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_688" class="hl">                            <span class="hl kwb">$pb </span><span class="hl opt">=~ </span><span class="hl kwd">s/&lt;\?lsmb sumcarriedforward \?&gt;/$psum/g</span><span class="hl opt">;</span></li>
<li id="n_689" class="hl">                            <span class="hl kwb">$pb </span><span class="hl opt">=~ </span><span class="hl kwd">s/&lt;\?lsmb lastpage \?&gt;/$current_page/g</span><span class="hl opt">;</span></li>
<li id="n_690" class="hl"></li>
<li id="n_691" class="hl">                            <span class="hl slc"># only &quot;normal&quot; variables are supported here</span></li>
<li id="n_692" class="hl">                            <span class="hl slc"># (no &lt;?lsmb if, no &lt;?lsmb foreach, no &lt;?lsmb include)</span></li>
<li id="n_693" class="hl">                            <span class="hl kwb">$pb </span><span class="hl opt">=~ </span><span class="hl kwd">s/&lt;\?lsmb (.+?) \?&gt;/$self-&gt;{$1}/g</span><span class="hl opt">;</span></li>
<li id="n_694" class="hl"></li>
<li id="n_695" class="hl">                            <span class="hl slc"># page break block is ready to rock</span></li>
<li id="n_696" class="hl">                            <span class="hl kwc">print</span><span class="hl opt">(</span>OUT <span class="hl kwb">$pb</span><span class="hl opt">);</span></li>
<li id="n_697" class="hl">                            <span class="hl kwb">$current_page++</span><span class="hl opt">;</span></li>
<li id="n_698" class="hl">                            <span class="hl kwb">$current_line </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_699" class="hl">                            <span class="hl kwb">$lines </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_700" class="hl">                        <span class="hl opt">}</span></li>
<li id="n_701" class="hl"></li>
<li id="n_702" class="hl">                        <span class="hl kwb">$current_line </span><span class="hl opt">+= </span><span class="hl kwb">$lines</span><span class="hl opt">;</span></li>
<li id="n_703" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_704" class="hl"></li>
<li id="n_705" class="hl">                    <span class="hl kwb">$sum </span><span class="hl opt">+= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">parse_amount</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>linetotal<span class="hl opt">}[</span><span class="hl kwb">$i</span><span class="hl opt">]);</span></li>
<li id="n_706" class="hl">                <span class="hl opt">}</span></li>
<li id="n_707" class="hl"></li>
<li id="n_708" class="hl">                <span class="hl slc"># don&#39;t parse par, we need it for each line</span></li>
<li id="n_709" class="hl">                <span class="hl kwc">print </span>OUT <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">format_line</span><span class="hl opt">(</span><span class="hl kwb">$par</span><span class="hl opt">, </span><span class="hl kwb">$i</span><span class="hl opt">);</span></li>
<li id="n_710" class="hl">            <span class="hl opt">}</span></li>
<li id="n_711" class="hl">            <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_712" class="hl">        <span class="hl opt">}</span></li>
<li id="n_713" class="hl"></li>
<li id="n_714" class="hl">        <span class="hl slc"># if not comes before if!</span></li>
<li id="n_715" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb if not /</span><span class="hl opt">) {</span></li>
<li id="n_716" class="hl"></li>
<li id="n_717" class="hl">            <span class="hl slc"># check if it is not set and display</span></li>
<li id="n_718" class="hl">            <span class="hl kwc">chop</span><span class="hl opt">;</span></li>
<li id="n_719" class="hl">            <span class="hl kwd">s/.*?&lt;\?lsmb if not (.+?) \?&gt;/$1/</span><span class="hl opt">;</span></li>
<li id="n_720" class="hl"></li>
<li id="n_721" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">}) {</span></li>
<li id="n_722" class="hl"></li>
<li id="n_723" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_724" class="hl">                    <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end /</span><span class="hl opt">);</span></li>
<li id="n_725" class="hl"></li>
<li id="n_726" class="hl">                    <span class="hl slc"># store line in $par</span></li>
<li id="n_727" class="hl">                    <span class="hl kwb">$par </span><span class="hl opt">.= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_728" class="hl">                <span class="hl opt">}</span></li>
<li id="n_729" class="hl"></li>
<li id="n_730" class="hl">                <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$par</span><span class="hl opt">;</span></li>
<li id="n_731" class="hl"></li>
<li id="n_732" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_733" class="hl"></li>
<li id="n_734" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_735" class="hl">                    <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end /</span><span class="hl opt">);</span></li>
<li id="n_736" class="hl">                <span class="hl opt">}</span></li>
<li id="n_737" class="hl"></li>
<li id="n_738" class="hl">                <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_739" class="hl">            <span class="hl opt">}</span></li>
<li id="n_740" class="hl">        <span class="hl opt">}</span></li>
<li id="n_741" class="hl"></li>
<li id="n_742" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\? lsmb if /</span><span class="hl opt">) {</span></li>
<li id="n_743" class="hl"></li>
<li id="n_744" class="hl">            <span class="hl slc"># check if it is set and display</span></li>
<li id="n_745" class="hl">            <span class="hl kwc">chop</span><span class="hl opt">;</span></li>
<li id="n_746" class="hl">            <span class="hl kwd">s/.*?&lt;\?lsmb if (.+?) \?&gt;/$1/</span><span class="hl opt">;</span></li>
<li id="n_747" class="hl"></li>
<li id="n_748" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/\s/</span><span class="hl opt">) {</span></li>
<li id="n_749" class="hl">                <span class="hl kwb">&#64;a </span><span class="hl opt">= </span><span class="hl kwc">split</span><span class="hl opt">;</span></li>
<li id="n_750" class="hl">                <span class="hl kwb">$ok </span><span class="hl opt">= </span><span class="hl kwc">eval </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$a</span><span class="hl sng">[0]} </span><span class="hl ipl">$a</span><span class="hl sng">[1] </span><span class="hl ipl">$a</span><span class="hl sng">[2]&quot;</span><span class="hl opt">;</span></li>
<li id="n_751" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_752" class="hl">                <span class="hl kwb">$ok </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">};</span></li>
<li id="n_753" class="hl">            <span class="hl opt">}</span></li>
<li id="n_754" class="hl"></li>
<li id="n_755" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$ok</span><span class="hl opt">) {</span></li>
<li id="n_756" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_757" class="hl">                    <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end /</span><span class="hl opt">);</span></li>
<li id="n_758" class="hl">                    <span class="hl slc"># store line in $par</span></li>
<li id="n_759" class="hl">                    <span class="hl kwb">$par </span><span class="hl opt">.= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_760" class="hl">                <span class="hl opt">}</span></li>
<li id="n_761" class="hl"></li>
<li id="n_762" class="hl">                <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$par</span><span class="hl opt">;</span></li>
<li id="n_763" class="hl"></li>
<li id="n_764" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_765" class="hl"></li>
<li id="n_766" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">) {</span></li>
<li id="n_767" class="hl">                    <span class="hl kwa">last if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb end /</span><span class="hl opt">);</span></li>
<li id="n_768" class="hl">                <span class="hl opt">}</span></li>
<li id="n_769" class="hl"></li>
<li id="n_770" class="hl">                <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_771" class="hl">            <span class="hl opt">}</span></li>
<li id="n_772" class="hl">        <span class="hl opt">}</span></li>
<li id="n_773" class="hl"></li>
<li id="n_774" class="hl">        <span class="hl slc"># check for &lt;?lsmb include filename ?&gt;</span></li>
<li id="n_775" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb include /</span><span class="hl opt">) {</span></li>
<li id="n_776" class="hl"></li>
<li id="n_777" class="hl">            <span class="hl slc"># get the filename</span></li>
<li id="n_778" class="hl">            <span class="hl kwc">chomp </span><span class="hl kwb">$var</span><span class="hl opt">;</span></li>
<li id="n_779" class="hl">            <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/.*?&lt;\?lsmb include (.+?) \?&gt;/$1/</span><span class="hl opt">;</span></li>
<li id="n_780" class="hl"></li>
<li id="n_781" class="hl">            <span class="hl slc"># remove / .. for security reasons</span></li>
<li id="n_782" class="hl">            <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/(\/|\.\.)/</span><span class="hl opt">/</span>g<span class="hl opt">;</span></li>
<li id="n_783" class="hl"></li>
<li id="n_784" class="hl">            <span class="hl slc"># assume loop after 10 includes of the same file</span></li>
<li id="n_785" class="hl">            <span class="hl kwa">next if </span><span class="hl opt">(</span><span class="hl kwb">$include</span><span class="hl opt">{</span><span class="hl kwb">$var</span><span class="hl opt">} &gt; </span><span class="hl num">10</span><span class="hl opt">);</span></li>
<li id="n_786" class="hl"></li>
<li id="n_787" class="hl">            <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">open</span><span class="hl opt">(</span>INC<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{language_code}/</span><span class="hl ipl">$var</span><span class="hl sng">&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_788" class="hl">                <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_789" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_790" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{templates}/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{language_code}/</span><span class="hl ipl">$var </span><span class="hl sng">: </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_791" class="hl">            <span class="hl opt">}</span></li>
<li id="n_792" class="hl"></li>
<li id="n_793" class="hl">            <span class="hl kwc">unshift</span><span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">, &lt;</span>INC<span class="hl opt">&gt;);</span></li>
<li id="n_794" class="hl">            <span class="hl kwc">close</span><span class="hl opt">(</span>INC<span class="hl opt">);</span></li>
<li id="n_795" class="hl"></li>
<li id="n_796" class="hl">            <span class="hl kwb">$include</span><span class="hl opt">{</span><span class="hl kwb">$var</span><span class="hl opt">}++;</span></li>
<li id="n_797" class="hl"></li>
<li id="n_798" class="hl">            <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_799" class="hl">        <span class="hl opt">}</span></li>
<li id="n_800" class="hl"></li>
<li id="n_801" class="hl">        <span class="hl kwc">print </span>OUT <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">format_line</span><span class="hl opt">(</span><span class="hl kwb">$_</span><span class="hl opt">);</span></li>
<li id="n_802" class="hl"></li>
<li id="n_803" class="hl">    <span class="hl opt">}</span></li>
<li id="n_804" class="hl"></li>
<li id="n_805" class="hl">    <span class="hl kwc">close</span><span class="hl opt">(</span>OUT<span class="hl opt">);</span></li>
<li id="n_806" class="hl"></li>
<li id="n_807" class="hl">    <span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>countitemnotes<span class="hl opt">};</span></li>
<li id="n_808" class="hl"></li>
<li id="n_809" class="hl">    <span class="hl slc"># Convert the tex file to postscript</span></li>
<li id="n_810" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} =~ </span><span class="hl kwd">/(postscript|pdf)/</span><span class="hl opt">) {</span></li>
<li id="n_811" class="hl"></li>
<li id="n_812" class="hl">        <span class="hl kwa">use </span>Cwd<span class="hl opt">;</span></li>
<li id="n_813" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>cwd<span class="hl opt">} = </span>cwd<span class="hl opt">();</span></li>
<li id="n_814" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpdir<span class="hl opt">} = </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{cwd}/${LedgerSMB::Sysconfig::userspath}&quot;</span><span class="hl opt">;</span></li>
<li id="n_815" class="hl"></li>
<li id="n_816" class="hl">        <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">chdir</span><span class="hl opt">(</span><span class="hl sng">&quot;${LedgerSMB::Sysconfig::userspath}&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_817" class="hl">            <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_818" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_819" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;chdir : </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_820" class="hl">        <span class="hl opt">}</span></li>
<li id="n_821" class="hl"></li>
<li id="n_822" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} =~ </span><span class="hl kwd">s/${LedgerSMB::Sysconfig::userspath}\//</span><span class="hl opt">/</span>g<span class="hl opt">;</span></li>
<li id="n_823" class="hl"></li>
<li id="n_824" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>errfile<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">};</span></li>
<li id="n_825" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>errfile<span class="hl opt">} =~ </span><span class="hl kwd">s/tex$/err/</span><span class="hl opt">;</span></li>
<li id="n_826" class="hl"></li>
<li id="n_827" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$r </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_828" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;postscript&#39;</span><span class="hl opt">) {</span></li>
<li id="n_829" class="hl"></li>
<li id="n_830" class="hl">        <span class="hl kwc">system</span><span class="hl opt">(</span><span class="hl sng">&quot;latex --interaction=nonstopmode </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} &gt; </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_831" class="hl"></li>
<li id="n_832" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">rerun_latex</span><span class="hl opt">) {</span></li>
<li id="n_833" class="hl">            <span class="hl kwc">system</span><span class="hl opt">(</span><span class="hl sng">&quot;latex --interaction=nonstopmode </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} &gt; </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_834" class="hl">            <span class="hl kwa">last if </span><span class="hl opt">++</span><span class="hl kwb">$r </span><span class="hl opt">&gt; </span><span class="hl num">4</span><span class="hl opt">;</span></li>
<li id="n_835" class="hl">        <span class="hl opt">}</span></li>
<li id="n_836" class="hl"></li>
<li id="n_837" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} =~ </span><span class="hl kwd">s/tex$/dvi/</span><span class="hl opt">;</span></li>
<li id="n_838" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl opt">! (-</span>f <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">});</span></li>
<li id="n_839" class="hl"></li>
<li id="n_840" class="hl">        <span class="hl kwc">system</span><span class="hl opt">(</span><span class="hl sng">&quot;dvips </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} -o -q&quot;</span><span class="hl opt">);</span></li>
<li id="n_841" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">.</span><span class="hl sng">&quot;dvips : </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$?</span><span class="hl opt">);</span></li>
<li id="n_842" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} =~ </span><span class="hl kwd">s/dvi$/ps/</span><span class="hl opt">;</span></li>
<li id="n_843" class="hl">        <span class="hl opt">}</span></li>
<li id="n_844" class="hl"></li>
<li id="n_845" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;pdf&#39;</span><span class="hl opt">) {</span></li>
<li id="n_846" class="hl">            <span class="hl kwc">system</span><span class="hl opt">(</span><span class="hl sng">&quot;pdflatex --interaction=nonstopmode </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} &gt; </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_847" class="hl"></li>
<li id="n_848" class="hl">            <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">rerun_latex</span><span class="hl opt">) {</span></li>
<li id="n_849" class="hl">                <span class="hl kwc">system</span><span class="hl opt">(</span><span class="hl sng">&quot;pdflatex --interaction=nonstopmode </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} &gt; </span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_850" class="hl">                <span class="hl kwa">last if </span><span class="hl opt">++</span><span class="hl kwb">$r </span><span class="hl opt">&gt; </span><span class="hl num">4</span><span class="hl opt">;</span></li>
<li id="n_851" class="hl">            <span class="hl opt">}</span></li>
<li id="n_852" class="hl"></li>
<li id="n_853" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} =~ </span><span class="hl kwd">s/tex$/pdf/</span><span class="hl opt">;</span></li>
<li id="n_854" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl opt">! (-</span>f <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">});</span></li>
<li id="n_855" class="hl">        <span class="hl opt">}</span></li>
<li id="n_856" class="hl">    <span class="hl opt">}</span></li>
<li id="n_857" class="hl"></li>
<li id="n_858" class="hl"></li>
<li id="n_859" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} =~ </span><span class="hl kwd">/(postscript|pdf)/ </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>media<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">) {</span></li>
<li id="n_860" class="hl"></li>
<li id="n_861" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>media<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">) {</span></li>
<li id="n_862" class="hl"></li>
<li id="n_863" class="hl">            <span class="hl kwa">use </span>LedgerSMB<span class="hl opt">::</span>Mailer<span class="hl opt">;</span></li>
<li id="n_864" class="hl"></li>
<li id="n_865" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$mail </span><span class="hl opt">= </span>new Mailer<span class="hl opt">;</span></li>
<li id="n_866" class="hl"></li>
<li id="n_867" class="hl">            <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(cc bcc subject message version format charset)</span><span class="hl opt">) { </span></li>
<li id="n_868" class="hl">                <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} </span></li>
<li id="n_869" class="hl">            <span class="hl opt">}</span></li>
<li id="n_870" class="hl"></li>
<li id="n_871" class="hl">            <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>to<span class="hl opt">} = </span>qq<span class="hl opt">|</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>email<span class="hl opt">}|;</span></li>
<li id="n_872" class="hl">            <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>from<span class="hl opt">} = </span>qq<span class="hl opt">|</span><span class="hl sng">&quot;</span><span class="hl ipl">$myconfig</span><span class="hl sng">-&gt;{name}&quot;</span> <span class="hl opt">&lt;</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>email<span class="hl opt">}&gt;|;</span></li>
<li id="n_873" class="hl">            <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>notify<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>notify<span class="hl opt">};</span></li>
<li id="n_874" class="hl">            <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>fileid<span class="hl opt">} = </span><span class="hl sng">&quot;</span><span class="hl ipl">$fileid</span><span class="hl sng">.&quot;</span><span class="hl opt">;</span></li>
<li id="n_875" class="hl"></li>
<li id="n_876" class="hl">            <span class="hl slc"># if we send html or plain text inline</span></li>
<li id="n_877" class="hl">            <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} =~ </span><span class="hl kwd">/(html|txt)/</span><span class="hl opt">) &amp;&amp; </span></li>
<li id="n_878" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>sendmode<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;inline&#39;</span><span class="hl opt">)) {</span></li>
<li id="n_879" class="hl"></li>
<li id="n_880" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$br </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_881" class="hl">                <span class="hl kwb">$br </span><span class="hl opt">= </span><span class="hl sng">&quot;&lt;br&gt;&quot;</span> <span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;html&#39;</span><span class="hl opt">;</span></li>
<li id="n_882" class="hl"></li>
<li id="n_883" class="hl">                <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>contenttype<span class="hl opt">} = </span><span class="hl sng">&quot;text/</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{format}&quot;</span><span class="hl opt">;</span></li>
<li id="n_884" class="hl"></li>
<li id="n_885" class="hl">                <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>message<span class="hl opt">} =~ </span><span class="hl kwd">s/\r?\n/$br\n/g</span><span class="hl opt">;</span></li>
<li id="n_886" class="hl">                <span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>signature<span class="hl opt">} =~ </span><span class="hl kwd">s/\\n/$br\n/g</span><span class="hl opt">;</span></li>
<li id="n_887" class="hl">                <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>message<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$br</span><span class="hl sng"></span><span class="hl esc">\n</span><span class="hl sng">-- </span><span class="hl ipl">$br</span><span class="hl sng"></span><span class="hl esc">\n</span><span class="hl sng"></span><span class="hl ipl">$myconfig</span><span class="hl sng">-&gt;{signature}</span><span class="hl esc">\n</span><span class="hl sng"></span><span class="hl ipl">$br</span><span class="hl sng">&quot;</span> <span class="hl kwa">if </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>signature<span class="hl opt">};</span></li>
<li id="n_888" class="hl"></li>
<li id="n_889" class="hl">                <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">open</span><span class="hl opt">(</span>IN<span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">})) {</span></li>
<li id="n_890" class="hl">                    <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_891" class="hl">                    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_892" class="hl">                    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} : </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_893" class="hl">                <span class="hl opt">}</span></li>
<li id="n_894" class="hl"></li>
<li id="n_895" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(&lt;</span>IN<span class="hl opt">&gt;) {</span></li>
<li id="n_896" class="hl">                    <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>message<span class="hl opt">} .= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_897" class="hl">                <span class="hl opt">}</span></li>
<li id="n_898" class="hl"></li>
<li id="n_899" class="hl">                <span class="hl kwc">close</span><span class="hl opt">(</span>IN<span class="hl opt">);</span></li>
<li id="n_900" class="hl"></li>
<li id="n_901" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_902" class="hl"></li>
<li id="n_903" class="hl">                <span class="hl opt">&#64;{ </span><span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>attachments<span class="hl opt">} } = (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">});</span></li>
<li id="n_904" class="hl"></li>
<li id="n_905" class="hl">                <span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>signature<span class="hl opt">} =~ </span><span class="hl kwd">s/\\n/\n/g</span><span class="hl opt">;</span></li>
<li id="n_906" class="hl">                <span class="hl kwb">$mail</span><span class="hl opt">-&gt;{</span>message<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl esc">\n</span><span class="hl sng">-- </span><span class="hl esc">\n</span><span class="hl sng"></span><span class="hl ipl">$myconfig</span><span class="hl sng">-&gt;{signature}&quot;</span> <span class="hl kwa">if </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>signature<span class="hl opt">};</span></li>
<li id="n_907" class="hl"></li>
<li id="n_908" class="hl">            <span class="hl opt">}</span></li>
<li id="n_909" class="hl"></li>
<li id="n_910" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$mail</span><span class="hl opt">-&gt;</span><span class="hl kwc">send</span><span class="hl opt">) {</span></li>
<li id="n_911" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_912" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$err</span><span class="hl opt">);</span></li>
<li id="n_913" class="hl">            <span class="hl opt">}</span></li>
<li id="n_914" class="hl"></li>
<li id="n_915" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_916" class="hl"></li>
<li id="n_917" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">} = </span><span class="hl kwb">$out</span><span class="hl opt">;</span></li>
<li id="n_918" class="hl"></li>
<li id="n_919" class="hl">            <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">open</span><span class="hl opt">(</span>IN<span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">})) {</span></li>
<li id="n_920" class="hl">                <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_921" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_922" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile} : </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_923" class="hl">            <span class="hl opt">}</span></li>
<li id="n_924" class="hl"></li>
<li id="n_925" class="hl">            <span class="hl kwc">binmode</span><span class="hl opt">(</span>IN<span class="hl opt">);</span></li>
<li id="n_926" class="hl"></li>
<li id="n_927" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>copies<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>media<span class="hl opt">} =~ </span><span class="hl kwd">/(screen|email|queue)/</span><span class="hl opt">;</span></li>
<li id="n_928" class="hl"></li>
<li id="n_929" class="hl">            <span class="hl kwc">chdir</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{cwd}&quot;</span><span class="hl opt">);</span></li>
<li id="n_930" class="hl"></li>
<li id="n_931" class="hl">            <span class="hl kwa">for </span><span class="hl kwc">my </span><span class="hl kwb">$i </span><span class="hl opt">(</span><span class="hl num">1 </span><span class="hl opt">.. </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>copies<span class="hl opt">}) {</span></li>
<li id="n_932" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">}) {</span></li>
<li id="n_933" class="hl"></li>
<li id="n_934" class="hl">                    <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">open</span><span class="hl opt">(</span>OUT<span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>OUT<span class="hl opt">})) {</span></li>
<li id="n_935" class="hl">                        <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_936" class="hl">                        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_937" class="hl">                        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{OUT} : </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_938" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_939" class="hl"></li>
<li id="n_940" class="hl">                <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_941" class="hl"></li>
<li id="n_942" class="hl">                    <span class="hl slc"># launch application</span></li>
<li id="n_943" class="hl">                    <span class="hl kwc">print </span>qq<span class="hl opt">|</span>Content-Type<span class="hl opt">: </span>application<span class="hl opt">/</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">}</span><span class="hl esc">\n</span><span class="hl opt">|.</span></li>
<li id="n_944" class="hl">                          qq<span class="hl opt">|</span>Content-Disposition<span class="hl opt">: </span>attachment<span class="hl opt">; </span>filename<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpfile}&quot;</span><span class="hl esc">\n\n</span><span class="hl opt">|;</span></li>
<li id="n_945" class="hl"></li>
<li id="n_946" class="hl">                    <span class="hl kwa">unless </span><span class="hl opt">(</span><span class="hl kwc">open</span><span class="hl opt">(</span>OUT<span class="hl opt">, </span><span class="hl sng">&quot;&gt;-&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_947" class="hl">                        <span class="hl kwb">$err </span><span class="hl opt">= </span><span class="hl kwb">$!</span><span class="hl opt">;</span></li>
<li id="n_948" class="hl">                        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_949" class="hl">                        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl sng">&quot;STDOUT : </span><span class="hl ipl">$err</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_950" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_951" class="hl">                <span class="hl opt">}</span></li>
<li id="n_952" class="hl"></li>
<li id="n_953" class="hl">                <span class="hl kwc">binmode</span><span class="hl opt">(</span>OUT<span class="hl opt">);</span></li>
<li id="n_954" class="hl"></li>
<li id="n_955" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(&lt;</span>IN<span class="hl opt">&gt;) {</span></li>
<li id="n_956" class="hl">                    <span class="hl kwc">print </span>OUT <span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_957" class="hl">                <span class="hl opt">}</span></li>
<li id="n_958" class="hl"></li>
<li id="n_959" class="hl">                <span class="hl kwc">close</span><span class="hl opt">(</span>OUT<span class="hl opt">);</span></li>
<li id="n_960" class="hl">                <span class="hl kwc">seek </span>IN<span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_961" class="hl">            <span class="hl opt">}</span></li>
<li id="n_962" class="hl"></li>
<li id="n_963" class="hl">            <span class="hl kwc">close</span><span class="hl opt">(</span>IN<span class="hl opt">);</span></li>
<li id="n_964" class="hl">        <span class="hl opt">}</span></li>
<li id="n_965" class="hl"></li>
<li id="n_966" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">cleanup</span><span class="hl opt">;</span></li>
<li id="n_967" class="hl">    <span class="hl opt">}</span></li>
<li id="n_968" class="hl"><span class="hl opt">}</span></li>
<li id="n_969" class="hl"></li>
<li id="n_970" class="hl"></li>
<li id="n_971" class="hl"><span class="hl kwa">sub </span>format_line <span class="hl opt">{</span></li>
<li id="n_972" class="hl"></li>
<li id="n_973" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$self </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_974" class="hl"></li>
<li id="n_975" class="hl">    <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_976" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_977" class="hl"></li>
<li id="n_978" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_979" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$newstr</span><span class="hl opt">;</span></li>
<li id="n_980" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$pos</span><span class="hl opt">;</span></li>
<li id="n_981" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$l</span><span class="hl opt">;</span></li>
<li id="n_982" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$lf</span><span class="hl opt">;</span></li>
<li id="n_983" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$line</span><span class="hl opt">;</span></li>
<li id="n_984" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$var </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_985" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%a</span><span class="hl opt">;</span></li>
<li id="n_986" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$offset</span><span class="hl opt">;</span></li>
<li id="n_987" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$pad</span><span class="hl opt">;</span></li>
<li id="n_988" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$item</span><span class="hl opt">;</span></li>
<li id="n_989" class="hl"></li>
<li id="n_990" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb (.+?) \?&gt;/</span><span class="hl opt">) {</span></li>
<li id="n_991" class="hl"></li>
<li id="n_992" class="hl">        <span class="hl kwb">%a </span><span class="hl opt">= ();</span></li>
<li id="n_993" class="hl"></li>
<li id="n_994" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwb">$item </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/ /</span><span class="hl opt">, </span><span class="hl kwb">$1</span><span class="hl opt">) {</span></li>
<li id="n_995" class="hl">            <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$key</span><span class="hl opt">, </span><span class="hl kwb">$value</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/=/</span><span class="hl opt">, </span><span class="hl kwb">$item</span><span class="hl opt">;</span></li>
<li id="n_996" class="hl"></li>
<li id="n_997" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$value </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">) {</span></li>
<li id="n_998" class="hl">                <span class="hl kwb">$a</span><span class="hl opt">{</span><span class="hl kwb">$key</span><span class="hl opt">} = </span><span class="hl kwb">$value</span><span class="hl opt">;</span></li>
<li id="n_999" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1000" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">= </span><span class="hl kwb">$item</span><span class="hl opt">;</span></li>
<li id="n_1001" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1002" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1003" class="hl"></li>
<li id="n_1004" class="hl">        <span class="hl kwb">$str </span><span class="hl opt">= (</span><span class="hl kwc">defined </span><span class="hl kwb">$i</span><span class="hl opt">) ? </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$var</span><span class="hl opt">}[</span><span class="hl kwb">$i</span><span class="hl opt">] : </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$var</span><span class="hl opt">};</span></li>
<li id="n_1005" class="hl">        <span class="hl kwb">$newstr </span><span class="hl opt">= </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_1006" class="hl"></li>
<li id="n_1007" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>countitemnotes<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl kwb">$var </span><span class="hl kwc">eq </span><span class="hl sng">&#39;itemnotes&#39;</span><span class="hl opt">;</span></li>
<li id="n_1008" class="hl"></li>
<li id="n_1009" class="hl">        <span class="hl kwb">$var </span><span class="hl opt">= </span><span class="hl kwb">$1</span><span class="hl opt">;</span></li>
<li id="n_1010" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">/^if\s+not\s+/</span><span class="hl opt">) {</span></li>
<li id="n_1011" class="hl"></li>
<li id="n_1012" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">) {</span></li>
<li id="n_1013" class="hl"></li>
<li id="n_1014" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/if\s+not\s+//</span><span class="hl opt">;</span></li>
<li id="n_1015" class="hl">                <span class="hl kwd">s/&lt;\?lsmb if\s+not\s+$var \?&gt;.*?(&lt;\?lsmb end\s+$var \?&gt;|$)//s</span><span class="hl opt">;</span></li>
<li id="n_1016" class="hl"></li>
<li id="n_1017" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1018" class="hl">                <span class="hl kwd">s/&lt;\?lsmb $var \?&gt;//</span><span class="hl opt">;</span></li>
<li id="n_1019" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1020" class="hl"></li>
<li id="n_1021" class="hl">            <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_1022" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1023" class="hl"></li>
<li id="n_1024" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">/^if\s+/</span><span class="hl opt">) {</span></li>
<li id="n_1025" class="hl"></li>
<li id="n_1026" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">) {</span></li>
<li id="n_1027" class="hl">                <span class="hl kwd">s/&lt;\?lsmb $var \?&gt;//</span><span class="hl opt">;</span></li>
<li id="n_1028" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1029" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/if\s+//</span><span class="hl opt">;</span></li>
<li id="n_1030" class="hl">                <span class="hl kwd">s/&lt;\?lsmb if\s+$var \?&gt;.*?(&lt;\?lsmb end\s+$var \?&gt;|$)//s</span><span class="hl opt">;</span></li>
<li id="n_1031" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1032" class="hl"></li>
<li id="n_1033" class="hl">            <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_1034" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1035" class="hl"></li>
<li id="n_1036" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">/^end\s+/</span><span class="hl opt">) {</span></li>
<li id="n_1037" class="hl">            <span class="hl kwd">s/&lt;\?lsmb $var \?&gt;//</span><span class="hl opt">;</span></li>
<li id="n_1038" class="hl">            <span class="hl kwa">next</span><span class="hl opt">;</span></li>
<li id="n_1039" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1040" class="hl"></li>
<li id="n_1041" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$a</span><span class="hl opt">{</span>align<span class="hl opt">} || </span><span class="hl kwb">$a</span><span class="hl opt">{</span>width<span class="hl opt">} || </span><span class="hl kwb">$a</span><span class="hl opt">{</span>offset<span class="hl opt">}) {</span></li>
<li id="n_1042" class="hl"></li>
<li id="n_1043" class="hl">            <span class="hl kwb">$newstr </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_1044" class="hl">            <span class="hl kwb">$offset </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1045" class="hl">            <span class="hl kwb">$lf </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_1046" class="hl"></li>
<li id="n_1047" class="hl">            <span class="hl kwa">foreach </span><span class="hl kwb">$str </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/\n/</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) {</span></li>
<li id="n_1048" class="hl"></li>
<li id="n_1049" class="hl">                <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_1050" class="hl">                <span class="hl kwb">$l </span><span class="hl opt">= </span><span class="hl kwc">length </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_1051" class="hl"></li>
<li id="n_1052" class="hl">                <span class="hl kwa">do </span><span class="hl opt">{</span></li>
<li id="n_1053" class="hl"></li>
<li id="n_1054" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$pos </span><span class="hl opt">= </span><span class="hl kwc">length </span><span class="hl kwb">$str</span><span class="hl opt">) &gt; </span><span class="hl kwb">$a</span><span class="hl opt">{</span>width<span class="hl opt">}) {</span></li>
<li id="n_1055" class="hl"></li>
<li id="n_1056" class="hl">                        <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$pos </span><span class="hl opt">= </span><span class="hl kwc">rindex </span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl sng">&quot; &quot;</span><span class="hl opt">, </span><span class="hl kwb">$a</span><span class="hl opt">{</span>width<span class="hl opt">}) &gt; </span><span class="hl num">0</span><span class="hl opt">) {</span></li>
<li id="n_1057" class="hl">                            <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl kwb">$pos</span><span class="hl opt">);</span></li>
<li id="n_1058" class="hl">                        <span class="hl opt">}</span></li>
<li id="n_1059" class="hl"></li>
<li id="n_1060" class="hl">                        <span class="hl kwb">$pos </span><span class="hl opt">= </span><span class="hl kwc">length </span><span class="hl kwb">$str </span><span class="hl kwa">if </span><span class="hl kwb">$pos </span><span class="hl opt">== -</span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1061" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_1062" class="hl"></li>
<li id="n_1063" class="hl">                    <span class="hl kwb">$l </span><span class="hl opt">= </span><span class="hl kwc">length </span><span class="hl kwb">$line</span><span class="hl opt">;</span></li>
<li id="n_1064" class="hl"></li>
<li id="n_1065" class="hl">                    <span class="hl slc"># pad left, right or center</span></li>
<li id="n_1066" class="hl">                    <span class="hl kwb">$l </span><span class="hl opt">= (</span><span class="hl kwb">$a</span><span class="hl opt">{</span>width<span class="hl opt">} - </span><span class="hl kwb">$l</span><span class="hl opt">);</span></li>
<li id="n_1067" class="hl"></li>
<li id="n_1068" class="hl">                    <span class="hl kwb">$pad </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl kwb">$l</span><span class="hl opt">;</span></li>
<li id="n_1069" class="hl"></li>
<li id="n_1070" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$a</span><span class="hl opt">{</span>align<span class="hl opt">} =~ </span><span class="hl kwd">/right/i</span><span class="hl opt">) {</span></li>
<li id="n_1071" class="hl">                        <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl kwb">$offset </span><span class="hl opt">. </span><span class="hl kwb">$pad </span><span class="hl opt">. </span><span class="hl kwb">$line</span><span class="hl opt">;</span></li>
<li id="n_1072" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_1073" class="hl"></li>
<li id="n_1074" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$a</span><span class="hl opt">{</span>align<span class="hl opt">} =~ </span><span class="hl kwd">/left/i</span><span class="hl opt">) {</span></li>
<li id="n_1075" class="hl">                        <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl kwb">$offset </span><span class="hl opt">. </span><span class="hl kwb">$line </span><span class="hl opt">. </span><span class="hl kwb">$pad</span><span class="hl opt">;</span></li>
<li id="n_1076" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_1077" class="hl"></li>
<li id="n_1078" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$a</span><span class="hl opt">{</span>align<span class="hl opt">} =~ </span><span class="hl kwd">/center/i</span><span class="hl opt">) {</span></li>
<li id="n_1079" class="hl">                        <span class="hl kwb">$pad </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl opt">(</span><span class="hl kwb">$l/2</span><span class="hl opt">);</span></li>
<li id="n_1080" class="hl">                        <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl kwb">$offset </span><span class="hl opt">. </span><span class="hl kwb">$pad </span><span class="hl opt">. </span><span class="hl kwb">$line</span><span class="hl opt">;</span></li>
<li id="n_1081" class="hl">                        <span class="hl kwb">$pad </span><span class="hl opt">= </span><span class="hl sng">&quot; &quot;</span> x <span class="hl opt">(</span><span class="hl kwb">$l/2</span><span class="hl opt">);</span></li>
<li id="n_1082" class="hl">                        <span class="hl kwb">$line </span><span class="hl opt">.= </span><span class="hl kwb">$pad</span><span class="hl opt">;</span></li>
<li id="n_1083" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_1084" class="hl"></li>
<li id="n_1085" class="hl">                    <span class="hl kwb">$newstr </span><span class="hl opt">.= </span><span class="hl sng">&quot;</span><span class="hl ipl">$lf$line</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1086" class="hl"></li>
<li id="n_1087" class="hl">                    <span class="hl kwb">$str </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">, </span><span class="hl kwb">$pos </span><span class="hl opt">+ </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_1088" class="hl">                    <span class="hl kwb">$line </span><span class="hl opt">= </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_1089" class="hl">                    <span class="hl kwb">$lf </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1090" class="hl"></li>
<li id="n_1091" class="hl">                    <span class="hl kwb">$offset </span><span class="hl opt">= </span><span class="hl kwb">$a</span><span class="hl opt">{</span>offset<span class="hl opt">};</span></li>
<li id="n_1092" class="hl"></li>
<li id="n_1093" class="hl">                <span class="hl opt">} </span><span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">);</span></li>
<li id="n_1094" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1095" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1096" class="hl"></li>
<li id="n_1097" class="hl">        <span class="hl kwd">s/&lt;\?lsmb (.+?) \?&gt;/$newstr/</span><span class="hl opt">;</span></li>
<li id="n_1098" class="hl"></li>
<li id="n_1099" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1100" class="hl"></li>
<li id="n_1101" class="hl">    <span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_1102" class="hl"><span class="hl opt">}</span></li>
<li id="n_1103" class="hl"></li>
<li id="n_1104" class="hl"></li>
<li id="n_1105" class="hl"><span class="hl kwa">sub </span>cleanup <span class="hl opt">{</span></li>
<li id="n_1106" class="hl"></li>
<li id="n_1107" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$self </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_1108" class="hl"></li>
<li id="n_1109" class="hl">    <span class="hl kwc">chdir</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{tmpdir}&quot;</span><span class="hl opt">);</span></li>
<li id="n_1110" class="hl"></li>
<li id="n_1111" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;err </span><span class="hl opt">= ();</span></li>
<li id="n_1112" class="hl"></li>
<li id="n_1113" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(-</span>f <span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">) {</span></li>
<li id="n_1114" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>FH<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_1115" class="hl">        <span class="hl kwb">&#64;err </span><span class="hl opt">= &lt;</span>FH<span class="hl opt">&gt;;</span></li>
<li id="n_1116" class="hl">        <span class="hl kwc">close</span><span class="hl opt">(</span>FH<span class="hl opt">);</span></li>
<li id="n_1117" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1118" class="hl"></li>
<li id="n_1119" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">}) {</span></li>
<li id="n_1120" class="hl">        <span class="hl slc"># strip extension</span></li>
<li id="n_1121" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">} =~ </span><span class="hl kwd">s/\.\w+$//g</span><span class="hl opt">;</span></li>
<li id="n_1122" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$tmpfile </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>tmpfile<span class="hl opt">};</span></li>
<li id="n_1123" class="hl">        <span class="hl kwc">unlink</span><span class="hl opt">(&lt;</span><span class="hl kwb">$tmpfile</span><span class="hl opt">.*&gt;);</span></li>
<li id="n_1124" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1125" class="hl"></li>
<li id="n_1126" class="hl">    <span class="hl kwc">chdir</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{cwd}&quot;</span><span class="hl opt">);</span></li>
<li id="n_1127" class="hl"></li>
<li id="n_1128" class="hl">    <span class="hl sng">&quot;</span><span class="hl ipl">&#64;err</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1129" class="hl"><span class="hl opt">}</span></li>
<li id="n_1130" class="hl"></li>
<li id="n_1131" class="hl"></li>
<li id="n_1132" class="hl"><span class="hl kwa">sub </span>rerun_latex <span class="hl opt">{</span></li>
<li id="n_1133" class="hl"></li>
<li id="n_1134" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$self </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_1135" class="hl"></li>
<li id="n_1136" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$a </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1137" class="hl"></li>
<li id="n_1138" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(-</span>f <span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">) {</span></li>
<li id="n_1139" class="hl">        <span class="hl kwc">open</span><span class="hl opt">(</span>FH<span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{errfile}&quot;</span><span class="hl opt">);</span></li>
<li id="n_1140" class="hl">        <span class="hl kwb">$a </span><span class="hl opt">= </span><span class="hl kwc">grep </span><span class="hl kwd">/(longtable Warning:|Warning:.*?LastPage)/</span><span class="hl opt">, &lt;</span>FH<span class="hl opt">&gt;;</span></li>
<li id="n_1141" class="hl">        <span class="hl kwc">close</span><span class="hl opt">(</span>FH<span class="hl opt">);</span></li>
<li id="n_1142" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1143" class="hl"></li>
<li id="n_1144" class="hl">    <span class="hl kwb">$a</span><span class="hl opt">;</span></li>
<li id="n_1145" class="hl"><span class="hl opt">}</span></li>
<li id="n_1146" class="hl"></li>
<li id="n_1147" class="hl"></li>
<li id="n_1148" class="hl"><span class="hl kwa">sub </span>format_string <span class="hl opt">{</span></li>
<li id="n_1149" class="hl"></li>
<li id="n_1150" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">&#64;fields</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1151" class="hl"></li>
<li id="n_1152" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$format </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">};</span></li>
<li id="n_1153" class="hl"></li>
<li id="n_1154" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>format<span class="hl opt">} =~ </span><span class="hl kwd">/(postscript|pdf)/</span><span class="hl opt">) {</span></li>
<li id="n_1155" class="hl">        <span class="hl kwb">$format </span><span class="hl opt">= </span><span class="hl sng">&#39;tex&#39;</span><span class="hl opt">;</span></li>
<li id="n_1156" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1157" class="hl"></li>
<li id="n_1158" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%replace </span><span class="hl opt">= ( </span></li>
<li id="n_1159" class="hl">        <span class="hl sng">&#39;order&#39;</span> <span class="hl opt">=&gt; { </span></li>
<li id="n_1160" class="hl">            html <span class="hl opt">=&gt; [ </span><span class="hl sng">&#39;&lt;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&gt;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span> <span class="hl opt">],</span></li>
<li id="n_1161" class="hl">            txt  <span class="hl opt">=&gt; [ </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span> <span class="hl opt">],</span></li>
<li id="n_1162" class="hl">            tex  <span class="hl opt">=&gt; [ </span><span class="hl kwc">quotemeta</span><span class="hl opt">(</span><span class="hl sng">&#39;</span><span class="hl esc">\\</span><span class="hl sng">&#39;</span><span class="hl opt">), </span><span class="hl sng">&#39;&amp;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span><span class="hl opt">,</span><span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span><span class="hl opt">, </span></li>
<li id="n_1163" class="hl">                <span class="hl sng">&#39;\$&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;%&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;_&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;#&#39;</span><span class="hl opt">,</span></li>
<li id="n_1164" class="hl">                <span class="hl kwc">quotemeta</span><span class="hl opt">(</span><span class="hl sng">&#39;^&#39;</span><span class="hl opt">), </span><span class="hl sng">&#39;{&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;}&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&lt;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&gt;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;£&#39;</span> </li>
<li id="n_1165" class="hl">                <span class="hl opt">] },</span></li>
<li id="n_1166" class="hl">        html <span class="hl opt">=&gt; { </span><span class="hl sng">&#39;&lt;&#39;</span>  <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&amp;lt;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&gt;&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&amp;gt;&#39;</span><span class="hl opt">,</span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&lt;br /&gt;&#39;</span><span class="hl opt">, </span></li>
<li id="n_1167" class="hl">            <span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&lt;br /&gt;&#39;</span> <span class="hl opt">},</span></li>
<li id="n_1168" class="hl">        txt  <span class="hl opt">=&gt; { </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&quot;</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&quot;</span><span class="hl esc">\r</span><span class="hl sng">&quot;</span> <span class="hl opt">},</span></li>
<li id="n_1169" class="hl">        tex  <span class="hl opt">=&gt; {</span><span class="hl sng">&#39;&amp;&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\&amp;&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;$&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\$&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;%&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\%&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;_&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\_&#39;</span><span class="hl opt">,</span></li>
<li id="n_1170" class="hl">            <span class="hl sng">&#39;#&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\#&#39;</span><span class="hl opt">, </span><span class="hl kwc">quotemeta</span><span class="hl opt">(</span><span class="hl sng">&#39;^&#39;</span><span class="hl opt">) =&gt; </span><span class="hl sng">&#39;\^</span><span class="hl esc">\\</span><span class="hl sng">&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;{&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\{&#39;</span><span class="hl opt">, </span></li>
<li id="n_1171" class="hl">            <span class="hl sng">&#39;}&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\}&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&lt;&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;$&lt;$&#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;&gt;&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;$&gt;$&#39;</span><span class="hl opt">,</span></li>
<li id="n_1172" class="hl">            <span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">ewline &#39;</span><span class="hl opt">, </span><span class="hl sng">&#39;</span><span class="hl esc">\r</span><span class="hl sng">&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;</span><span class="hl esc">\n</span><span class="hl sng">ewline &#39;</span><span class="hl opt">, </span></li>
<li id="n_1173" class="hl">            <span class="hl sng">&#39;£&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;\pounds &#39;</span><span class="hl opt">, </span><span class="hl kwc">quotemeta</span><span class="hl opt">(</span><span class="hl sng">&#39;</span><span class="hl esc">\\</span><span class="hl sng">&#39;</span><span class="hl opt">) =&gt; </span><span class="hl sng">&#39;/&#39;</span><span class="hl opt">} </span></li>
<li id="n_1174" class="hl">    <span class="hl opt">);</span></li>
<li id="n_1175" class="hl"></li>
<li id="n_1176" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$key</span><span class="hl opt">;</span></li>
<li id="n_1177" class="hl"></li>
<li id="n_1178" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwb">$key </span><span class="hl opt">(&#64;{ </span><span class="hl kwb">$replace</span><span class="hl opt">{</span>order<span class="hl opt">}{</span><span class="hl kwb">$format</span><span class="hl opt">} }) {</span></li>
<li id="n_1179" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;fields</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} =~ </span><span class="hl kwd">s/$key/$replace{$format}{$key}/g </span><span class="hl opt">}</span></li>
<li id="n_1180" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1181" class="hl"></li>
<li id="n_1182" class="hl"><span class="hl opt">}</span></li>
<li id="n_1183" class="hl"></li>
<li id="n_1184" class="hl"></li>
<li id="n_1185" class="hl"><span class="hl kwa">sub </span>datetonum <span class="hl opt">{</span></li>
<li id="n_1186" class="hl"></li>
<li id="n_1187" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">, </span><span class="hl kwb">$picture</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1188" class="hl"></li>
<li id="n_1189" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">&amp;&amp; </span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_1190" class="hl"></li>
<li id="n_1191" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^yy/</span><span class="hl opt">) {</span></li>
<li id="n_1192" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1193" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1194" class="hl"></li>
<li id="n_1195" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^mm/</span><span class="hl opt">) {</span></li>
<li id="n_1196" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1197" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1198" class="hl"></li>
<li id="n_1199" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^dd/</span><span class="hl opt">) {</span></li>
<li id="n_1200" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1201" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1202" class="hl"></li>
<li id="n_1203" class="hl">        <span class="hl kwb">$dd </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1204" class="hl">        <span class="hl kwb">$mm </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1205" class="hl">        <span class="hl kwb">$yy </span><span class="hl opt">+= </span><span class="hl num">2000 </span><span class="hl kwa">if </span><span class="hl kwc">length </span><span class="hl kwb">$yy </span><span class="hl opt">== </span><span class="hl num">2</span><span class="hl opt">;</span></li>
<li id="n_1206" class="hl"></li>
<li id="n_1207" class="hl">        <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$dd</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_1208" class="hl">        <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$mm</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_1209" class="hl"></li>
<li id="n_1210" class="hl">        <span class="hl kwb">$date </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$mm$dd</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1211" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1212" class="hl"></li>
<li id="n_1213" class="hl">    <span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1214" class="hl"><span class="hl opt">}</span></li>
<li id="n_1215" class="hl"></li>
<li id="n_1216" class="hl"></li>
<li id="n_1217" class="hl"><span class="hl kwa">sub </span>add_date <span class="hl opt">{</span></li>
<li id="n_1218" class="hl"></li>
<li id="n_1219" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">, </span><span class="hl kwb">$repeat</span><span class="hl opt">, </span><span class="hl kwb">$unit</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1220" class="hl"></li>
<li id="n_1221" class="hl">    <span class="hl kwa">use </span>Time<span class="hl opt">::</span>Local<span class="hl opt">;</span></li>
<li id="n_1222" class="hl"></li>
<li id="n_1223" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$diff </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1224" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$spc </span><span class="hl opt">= </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">};</span></li>
<li id="n_1225" class="hl">    <span class="hl kwb">$spc </span><span class="hl opt">=~ </span><span class="hl kwd">s/\w//g</span><span class="hl opt">;</span></li>
<li id="n_1226" class="hl">    <span class="hl kwb">$spc </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$spc</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_1227" class="hl"></li>
<li id="n_1228" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date</span><span class="hl opt">) {</span></li>
<li id="n_1229" class="hl"></li>
<li id="n_1230" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_1231" class="hl"></li>
<li id="n_1232" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^yy/</span><span class="hl opt">) {</span></li>
<li id="n_1233" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1234" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1235" class="hl"></li>
<li id="n_1236" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^mm/</span><span class="hl opt">) {</span></li>
<li id="n_1237" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1238" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1239" class="hl"></li>
<li id="n_1240" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^dd/</span><span class="hl opt">) {</span></li>
<li id="n_1241" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1242" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1243" class="hl"></li>
<li id="n_1244" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1245" class="hl">            <span class="hl slc"># ISO</span></li>
<li id="n_1246" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">) =~ </span><span class="hl kwd">/(....)(..)(..)/</span><span class="hl opt">;</span></li>
<li id="n_1247" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1248" class="hl"></li>
<li id="n_1249" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$unit </span><span class="hl kwc">eq </span><span class="hl sng">&#39;days&#39;</span><span class="hl opt">) {</span></li>
<li id="n_1250" class="hl">            <span class="hl kwb">$diff </span><span class="hl opt">= </span><span class="hl kwb">$repeat </span><span class="hl opt">* </span><span class="hl num">86400</span><span class="hl opt">;</span></li>
<li id="n_1251" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1252" class="hl"></li>
<li id="n_1253" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$unit </span><span class="hl kwc">eq </span><span class="hl sng">&#39;weeks&#39;</span><span class="hl opt">) {</span></li>
<li id="n_1254" class="hl">            <span class="hl kwb">$diff </span><span class="hl opt">= </span><span class="hl kwb">$repeat </span><span class="hl opt">* </span><span class="hl num">604800</span><span class="hl opt">;</span></li>
<li id="n_1255" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1256" class="hl"></li>
<li id="n_1257" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$unit </span><span class="hl kwc">eq </span><span class="hl sng">&#39;months&#39;</span><span class="hl opt">) {</span></li>
<li id="n_1258" class="hl">            <span class="hl kwb">$diff </span><span class="hl opt">= </span><span class="hl kwb">$mm </span><span class="hl opt">+ </span><span class="hl kwb">$repeat</span><span class="hl opt">;</span></li>
<li id="n_1259" class="hl"></li>
<li id="n_1260" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$whole </span><span class="hl opt">= </span><span class="hl kwc">int</span><span class="hl opt">(</span><span class="hl kwb">$diff </span><span class="hl opt">/ </span><span class="hl num">12</span><span class="hl opt">);</span></li>
<li id="n_1261" class="hl">            <span class="hl kwb">$yy </span><span class="hl opt">+= </span><span class="hl kwb">$whole</span><span class="hl opt">;</span></li>
<li id="n_1262" class="hl"></li>
<li id="n_1263" class="hl">            <span class="hl kwb">$mm </span><span class="hl opt">= (</span><span class="hl kwb">$diff </span><span class="hl opt">% </span><span class="hl num">12</span><span class="hl opt">) + </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1264" class="hl">            <span class="hl kwb">$diff </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1265" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1266" class="hl"></li>
<li id="n_1267" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$unit </span><span class="hl kwc">eq </span><span class="hl sng">&#39;years&#39;</span><span class="hl opt">) {</span></li>
<li id="n_1268" class="hl">            <span class="hl kwb">$yy++</span><span class="hl opt">;</span></li>
<li id="n_1269" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1270" class="hl"></li>
<li id="n_1271" class="hl">        <span class="hl kwb">$mm</span><span class="hl opt">--;</span></li>
<li id="n_1272" class="hl"></li>
<li id="n_1273" class="hl">        <span class="hl kwb">&#64;t </span><span class="hl opt">= </span><span class="hl kwc">localtime</span><span class="hl opt">(</span>timelocal<span class="hl opt">(</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl kwb">$dd</span><span class="hl opt">,</span><span class="hl kwb">$mm</span><span class="hl opt">,</span><span class="hl kwb">$yy</span><span class="hl opt">) + </span><span class="hl kwb">$diff</span><span class="hl opt">);</span></li>
<li id="n_1274" class="hl"></li>
<li id="n_1275" class="hl">        <span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">]++;</span></li>
<li id="n_1276" class="hl">        <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$t</span><span class="hl sng">[4]&quot;</span><span class="hl opt">,-</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_1277" class="hl">        <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$t</span><span class="hl sng">[3]&quot;</span><span class="hl opt">,-</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_1278" class="hl">        <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">5</span><span class="hl opt">] + </span><span class="hl num">1900</span><span class="hl opt">;</span></li>
<li id="n_1279" class="hl"></li>
<li id="n_1280" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_1281" class="hl"></li>
<li id="n_1282" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^yy/</span><span class="hl opt">) {</span></li>
<li id="n_1283" class="hl">                <span class="hl kwb">$date </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$spc$mm$spc$dd</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1284" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1285" class="hl"></li>
<li id="n_1286" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^mm/</span><span class="hl opt">) {</span></li>
<li id="n_1287" class="hl">                <span class="hl kwb">$date </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$mm$spc$dd$spc$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1288" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1289" class="hl"></li>
<li id="n_1290" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^dd/</span><span class="hl opt">) {</span></li>
<li id="n_1291" class="hl">                <span class="hl kwb">$date </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$dd$spc$mm$spc$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1292" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1293" class="hl"></li>
<li id="n_1294" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1295" class="hl">            <span class="hl kwb">$date </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$mm$dd</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1296" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1297" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1298" class="hl"></li>
<li id="n_1299" class="hl">    <span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_1300" class="hl"><span class="hl opt">}</span></li>
<li id="n_1301" class="hl"></li>
<li id="n_1302" class="hl"></li>
<li id="n_1303" class="hl"><span class="hl kwa">sub </span>print_button <span class="hl opt">{</span></li>
<li id="n_1304" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$button</span><span class="hl opt">, </span><span class="hl kwb">$name</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1305" class="hl"></li>
<li id="n_1306" class="hl">    <span class="hl kwc">print </span>qq<span class="hl opt">|&lt;</span>button <span class="hl kwa">class</span><span class="hl opt">=</span><span class="hl sng">&quot;submit&quot;</span> type<span class="hl opt">=</span><span class="hl sng">&quot;submit&quot;</span> name<span class="hl opt">=</span><span class="hl sng">&quot;action&quot;</span> value<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$name</span><span class="hl sng">&quot;</span> accesskey<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$button</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$name</span><span class="hl sng">}{key}&quot;</span> title<span class="hl opt">=</span><span class="hl sng">&quot;</span><span class="hl ipl">$button</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$name</span><span class="hl sng">}{value} [Alt-</span><span class="hl ipl">$button</span><span class="hl sng">-&gt;{</span><span class="hl ipl">$name</span><span class="hl sng">}{key}]&quot;</span><span class="hl opt">&gt;</span><span class="hl kwb">$button</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$name</span><span class="hl opt">}{</span>value<span class="hl opt">}&lt;/</span>button<span class="hl opt">&gt;</span><span class="hl esc">\n</span><span class="hl opt">|;</span></li>
<li id="n_1307" class="hl"><span class="hl opt">}          </span></li>
<li id="n_1308" class="hl"></li>
<li id="n_1309" class="hl"></li>
<li id="n_1310" class="hl"><span class="hl slc"># Database routines used throughout</span></li>
<li id="n_1311" class="hl"></li>
<li id="n_1312" class="hl"><span class="hl kwa">sub </span>db_init <span class="hl opt">{</span></li>
<li id="n_1313" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1314" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dbconnect_noauto</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">();</span></li>
<li id="n_1315" class="hl"></li>
<li id="n_1316" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span></li>
<li id="n_1317" class="hl">        <span class="hl sng">&quot;SELECT t.extends, </span></li>
<li id="n_1318" class="hl"><span class="hl sng">            coalesce (t.table_name, &#39;custom_&#39; || extends) </span></li>
<li id="n_1319" class="hl"><span class="hl sng">            || &#39;:&#39; || f.field_name as field_def</span></li>
<li id="n_1320" class="hl"><span class="hl sng">        FROM custom_table_catalog t</span></li>
<li id="n_1321" class="hl"><span class="hl sng">        JOIN custom_field_catalog f USING (table_id)&quot;</span><span class="hl opt">;</span></li>
<li id="n_1322" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1323" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">;</span></li>
<li id="n_1324" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1325" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)){</span></li>
<li id="n_1326" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>custom_db_fields<span class="hl opt">}{</span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>extends<span class="hl opt">}}},</span></li>
<li id="n_1327" class="hl">            <span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>field_def<span class="hl opt">};</span></li>
<li id="n_1328" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1329" class="hl"><span class="hl opt">}</span></li>
<li id="n_1330" class="hl"></li>
<li id="n_1331" class="hl"><span class="hl kwa">sub </span>run_custom_queries <span class="hl opt">{</span></li>
<li id="n_1332" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$tablename</span><span class="hl opt">, </span><span class="hl kwb">$query_type</span><span class="hl opt">, </span><span class="hl kwb">$linenum</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1333" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1334" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl opt">!~ </span><span class="hl kwd">/^(select|insert|update)$/i</span><span class="hl opt">){</span></li>
<li id="n_1335" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">error</span><span class="hl opt">(</span><span class="hl kwb">$locale</span><span class="hl opt">-&gt;</span><span class="hl kwd">text</span><span class="hl opt">(</span></li>
<li id="n_1336" class="hl">            <span class="hl sng">&quot;Passed incorrect query type to get_cutstom_queries.&quot;</span></li>
<li id="n_1337" class="hl">        <span class="hl opt">));</span></li>
<li id="n_1338" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1339" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;rc</span><span class="hl opt">;</span></li>
<li id="n_1340" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%temphash</span><span class="hl opt">;</span></li>
<li id="n_1341" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;templist</span><span class="hl opt">;</span></li>
<li id="n_1342" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;elements</span><span class="hl opt">;</span></li>
<li id="n_1343" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query</span><span class="hl opt">;</span></li>
<li id="n_1344" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$ins_values</span><span class="hl opt">;</span></li>
<li id="n_1345" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$linenum</span><span class="hl opt">){</span></li>
<li id="n_1346" class="hl">        <span class="hl kwb">$linenum </span><span class="hl opt">= </span><span class="hl sng">&quot;_</span><span class="hl ipl">$linenum</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1347" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1348" class="hl"></li>
<li id="n_1349" class="hl">    <span class="hl kwb">$query_type </span><span class="hl opt">= </span><span class="hl kwc">uc</span><span class="hl opt">(</span><span class="hl kwb">$query_type</span><span class="hl opt">);</span></li>
<li id="n_1350" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(&#64;{</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>custom_db_fields<span class="hl opt">}{</span><span class="hl kwb">$tablename</span><span class="hl opt">}}){</span></li>
<li id="n_1351" class="hl">        <span class="hl kwb">&#64;elements </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl opt">(</span><span class="hl kwd">/:/</span><span class="hl opt">, </span><span class="hl kwb">$_</span><span class="hl opt">);</span></li>
<li id="n_1352" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{</span><span class="hl kwb">$temphash</span><span class="hl opt">{</span><span class="hl kwb">$elements</span><span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">]}}, </span><span class="hl kwb">$elements</span><span class="hl opt">[</span><span class="hl num">1</span><span class="hl opt">];</span></li>
<li id="n_1353" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1354" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%temphash</span><span class="hl opt">){</span></li>
<li id="n_1355" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_1356" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$ins_values</span><span class="hl opt">;</span></li>
<li id="n_1357" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$query_type </span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1358" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;UPDATE&#39;</span><span class="hl opt">){</span></li>
<li id="n_1359" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl sng">&quot;DELETE FROM </span><span class="hl ipl">$_ </span><span class="hl sng">WHERE row_id = ?&quot;</span><span class="hl opt">;</span></li>
<li id="n_1360" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1361" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">-&gt;(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;id&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;</span><span class="hl ipl">$linenum</span><span class="hl sng">&quot;</span><span class="hl opt">})</span></li>
<li id="n_1362" class="hl">                <span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1363" class="hl">        <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1364" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot; INTO </span><span class="hl ipl">$_ </span><span class="hl sng">(&quot;</span><span class="hl opt">;</span></li>
<li id="n_1365" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1366" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$first </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1367" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(&#64;{</span><span class="hl kwb">$temphash</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">}}){</span></li>
<li id="n_1368" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot;</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1369" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;UPDATE&#39;</span><span class="hl opt">){</span></li>
<li id="n_1370" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&#39;= ?&#39;</span><span class="hl opt">;</span></li>
<li id="n_1371" class="hl">            <span class="hl opt">}   </span></li>
<li id="n_1372" class="hl">            <span class="hl kwb">$ins_values </span><span class="hl opt">.= </span><span class="hl sng">&quot;?, &quot;</span><span class="hl opt">;</span></li>
<li id="n_1373" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot;, &quot;</span><span class="hl opt">;</span></li>
<li id="n_1374" class="hl">            <span class="hl kwb">$first </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1375" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;UPDATE&#39;</span> <span class="hl kwc">or </span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1376" class="hl">                <span class="hl kwc">push </span><span class="hl kwb">&#64;data</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;</span><span class="hl ipl">$_$linenum</span><span class="hl sng">&quot;</span><span class="hl opt">}; </span></li>
<li id="n_1377" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1378" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1379" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">ne </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1380" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">=~ </span><span class="hl kwd">s/, $//</span><span class="hl opt">;</span></li>
<li id="n_1381" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1382" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;SELECT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1383" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot; FROM </span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1384" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1385" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;SELECT&#39;</span> <span class="hl kwc">or </span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;UPDATE&#39;</span><span class="hl opt">){</span></li>
<li id="n_1386" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot; WHERE row_id = ?&quot;</span><span class="hl opt">;</span></li>
<li id="n_1387" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1388" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1389" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">.= </span><span class="hl sng">&quot; row_id) VALUES (</span><span class="hl ipl">$ins_values </span><span class="hl sng">?)&quot;</span><span class="hl opt">;</span></li>
<li id="n_1390" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1391" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;SELECT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1392" class="hl">            <span class="hl kwc">push </span><span class="hl kwb">&#64;rc</span><span class="hl opt">, [ </span><span class="hl kwb">$query </span><span class="hl opt">];</span></li>
<li id="n_1393" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1394" class="hl">            <span class="hl kwc">unshift </span><span class="hl opt">(</span><span class="hl kwb">&#64;data</span><span class="hl opt">, </span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1395" class="hl">            <span class="hl kwc">push </span><span class="hl kwb">&#64;rc</span><span class="hl opt">, [ </span><span class="hl kwb">&#64;data </span><span class="hl opt">];</span></li>
<li id="n_1396" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1397" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1398" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1399" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;rc</span><span class="hl opt">){</span></li>
<li id="n_1400" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl kwc">shift </span><span class="hl opt">(&#64;{</span><span class="hl kwb">$_</span><span class="hl opt">});</span></li>
<li id="n_1401" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) </span></li>
<li id="n_1402" class="hl">                <span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">db_error</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1403" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(&#64;{</span><span class="hl kwb">$_</span><span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">})</span></li>
<li id="n_1404" class="hl">                <span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);;</span></li>
<li id="n_1405" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1406" class="hl">            <span class="hl kwb">$did_insert </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1407" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1408" class="hl">    <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;UPDATE&#39;</span><span class="hl opt">){</span></li>
<li id="n_1409" class="hl">        <span class="hl kwb">&#64;rc </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">run_custom_queries</span><span class="hl opt">(</span></li>
<li id="n_1410" class="hl">            <span class="hl kwb">$tablename</span><span class="hl opt">, </span><span class="hl sng">&#39;INSERT&#39;</span><span class="hl opt">, </span><span class="hl kwb">$linenum</span><span class="hl opt">);</span></li>
<li id="n_1411" class="hl">    <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$query_type </span><span class="hl kwc">eq </span><span class="hl sng">&#39;SELECT&#39;</span><span class="hl opt">){</span></li>
<li id="n_1412" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;rc</span><span class="hl opt">){</span></li>
<li id="n_1413" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl kwc">shift </span><span class="hl opt">&#64;{</span><span class="hl kwb">$_</span><span class="hl opt">};</span></li>
<li id="n_1414" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1415" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">});</span></li>
<li id="n_1416" class="hl">            <span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">);</span></li>
<li id="n_1417" class="hl">            <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl opt">%{</span><span class="hl kwb">$ref</span><span class="hl opt">}){</span></li>
<li id="n_1418" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">};</span></li>
<li id="n_1419" class="hl">            <span class="hl opt">}</span></li>
<li id="n_1420" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1421" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1422" class="hl">    <span class="hl kwb">&#64;rc</span><span class="hl opt">;</span></li>
<li id="n_1423" class="hl"><span class="hl opt">}</span></li>
<li id="n_1424" class="hl"></li>
<li id="n_1425" class="hl"></li>
<li id="n_1426" class="hl"><span class="hl kwa">sub </span>dbconnect <span class="hl opt">{</span></li>
<li id="n_1427" class="hl"></li>
<li id="n_1428" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1429" class="hl"></li>
<li id="n_1430" class="hl">    <span class="hl slc"># connect to database</span></li>
<li id="n_1431" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span>DBI-<span class="hl opt">&gt;</span><span class="hl kwc">connect</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbconnect<span class="hl opt">}, </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbuser<span class="hl opt">}, </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbpasswd<span class="hl opt">}) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">;</span></li>
<li id="n_1432" class="hl"></li>
<li id="n_1433" class="hl">    <span class="hl slc"># set db options</span></li>
<li id="n_1434" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dboptions<span class="hl opt">}) {</span></li>
<li id="n_1435" class="hl">        <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwa">do</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dboptions<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dboptions<span class="hl opt">});</span></li>
<li id="n_1436" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1437" class="hl"></li>
<li id="n_1438" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">;</span></li>
<li id="n_1439" class="hl"><span class="hl opt">}</span></li>
<li id="n_1440" class="hl"></li>
<li id="n_1441" class="hl"></li>
<li id="n_1442" class="hl"><span class="hl kwa">sub </span>dbconnect_noauto <span class="hl opt">{</span></li>
<li id="n_1443" class="hl"></li>
<li id="n_1444" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1445" class="hl"></li>
<li id="n_1446" class="hl">    <span class="hl slc"># connect to database</span></li>
<li id="n_1447" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span>DBI-<span class="hl opt">&gt;</span><span class="hl kwc">connect</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbconnect<span class="hl opt">}, </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbuser<span class="hl opt">}, </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbpasswd<span class="hl opt">}, {</span>AutoCommit <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">}) </span><span class="hl kwc">or </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">;</span></li>
<li id="n_1448" class="hl"></li>
<li id="n_1449" class="hl">    <span class="hl slc"># set db options</span></li>
<li id="n_1450" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dboptions<span class="hl opt">}) {</span></li>
<li id="n_1451" class="hl">        <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwa">do</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dboptions<span class="hl opt">});</span></li>
<li id="n_1452" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1453" class="hl"></li>
<li id="n_1454" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">;</span></li>
<li id="n_1455" class="hl"><span class="hl opt">}</span></li>
<li id="n_1456" class="hl"></li>
<li id="n_1457" class="hl"></li>
<li id="n_1458" class="hl"><span class="hl kwa">sub </span>dbquote <span class="hl opt">{</span></li>
<li id="n_1459" class="hl"></li>
<li id="n_1460" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$var</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1461" class="hl"></li>
<li id="n_1462" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$var </span><span class="hl kwc">eq </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">){</span></li>
<li id="n_1463" class="hl">        <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl sng">&quot;NULL&quot;</span><span class="hl opt">;</span></li>
<li id="n_1464" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1465" class="hl">        <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">quote</span><span class="hl opt">(</span><span class="hl kwb">$var</span><span class="hl opt">);</span></li>
<li id="n_1466" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1467" class="hl">    <span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_1468" class="hl"><span class="hl opt">}</span></li>
<li id="n_1469" class="hl"></li>
<li id="n_1470" class="hl"></li>
<li id="n_1471" class="hl"><span class="hl kwa">sub </span>update_balance <span class="hl opt">{</span></li>
<li id="n_1472" class="hl">    <span class="hl slc"># This is a dangerous private function.  All apps calling it must</span></li>
<li id="n_1473" class="hl">    <span class="hl slc"># be careful to avoid SQL injection issues</span></li>
<li id="n_1474" class="hl"></li>
<li id="n_1475" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$table</span><span class="hl opt">, </span><span class="hl kwb">$field</span><span class="hl opt">, </span><span class="hl kwb">$where</span><span class="hl opt">, </span><span class="hl kwb">$value</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1476" class="hl"></li>
<li id="n_1477" class="hl">    <span class="hl slc"># if we have a value, go do it</span></li>
<li id="n_1478" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$value</span><span class="hl opt">) {</span></li>
<li id="n_1479" class="hl">        <span class="hl slc"># retrieve balance from table</span></li>
<li id="n_1480" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl sng">&quot;SELECT </span><span class="hl ipl">$field </span><span class="hl sng">FROM </span><span class="hl ipl">$table </span><span class="hl sng">WHERE </span><span class="hl ipl">$where </span><span class="hl sng">FOR UPDATE&quot;</span><span class="hl opt">;</span></li>
<li id="n_1481" class="hl">        <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$balance</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1482" class="hl"></li>
<li id="n_1483" class="hl">        <span class="hl kwb">$balance </span><span class="hl opt">+= </span><span class="hl kwb">$value</span><span class="hl opt">;</span></li>
<li id="n_1484" class="hl">        <span class="hl slc"># update balance</span></li>
<li id="n_1485" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span><span class="hl sng">&quot;UPDATE </span><span class="hl ipl">$table </span><span class="hl sng">SET </span><span class="hl ipl">$field </span><span class="hl sng">= </span><span class="hl ipl">$balance </span><span class="hl sng">WHERE </span><span class="hl ipl">$where</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_1486" class="hl">        <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwa">do</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1487" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1488" class="hl"><span class="hl opt">}</span></li>
<li id="n_1489" class="hl"></li>
<li id="n_1490" class="hl"></li>
<li id="n_1491" class="hl"><span class="hl kwa">sub </span>update_exchangerate <span class="hl opt">{</span></li>
<li id="n_1492" class="hl"></li>
<li id="n_1493" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$buy</span><span class="hl opt">, </span><span class="hl kwb">$sell</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1494" class="hl"></li>
<li id="n_1495" class="hl">    <span class="hl slc"># some sanity check for currency</span></li>
<li id="n_1496" class="hl">    <span class="hl kwa">return if </span><span class="hl opt">(</span><span class="hl kwb">$curr </span><span class="hl kwc">eq </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">);</span></li>
<li id="n_1497" class="hl"></li>
<li id="n_1498" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1499" class="hl">        SELECT curr </li>
<li id="n_1500" class="hl">        FROM exchangerate</li>
<li id="n_1501" class="hl">        WHERE curr <span class="hl opt">= ?</span></li>
<li id="n_1502" class="hl">        AND transdate <span class="hl opt">= ?</span></li>
<li id="n_1503" class="hl">        FOR UPDATE<span class="hl opt">|;</span></li>
<li id="n_1504" class="hl"></li>
<li id="n_1505" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1506" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1507" class="hl"></li>
<li id="n_1508" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$set</span><span class="hl opt">;</span></li>
<li id="n_1509" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">;</span></li>
<li id="n_1510" class="hl"></li>
<li id="n_1511" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$buy </span><span class="hl opt">&amp;&amp; </span><span class="hl kwb">$sell</span><span class="hl opt">) {</span></li>
<li id="n_1512" class="hl">        <span class="hl kwb">$set </span><span class="hl opt">= </span><span class="hl sng">&quot;buy = ?, sell = ?&quot;</span><span class="hl opt">;</span></li>
<li id="n_1513" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$buy</span><span class="hl opt">, </span><span class="hl kwb">$sell</span><span class="hl opt">);</span></li>
<li id="n_1514" class="hl">    <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$buy</span><span class="hl opt">) {</span></li>
<li id="n_1515" class="hl">        <span class="hl kwb">$set </span><span class="hl opt">= </span><span class="hl sng">&quot;buy = ?&quot;</span><span class="hl opt">;</span></li>
<li id="n_1516" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$buy</span><span class="hl opt">);</span></li>
<li id="n_1517" class="hl">    <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$sell</span><span class="hl opt">) {</span></li>
<li id="n_1518" class="hl">        <span class="hl kwb">$set </span><span class="hl opt">= </span><span class="hl sng">&quot;sell = ?&quot;</span><span class="hl opt">;</span></li>
<li id="n_1519" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$sell</span><span class="hl opt">);</span></li>
<li id="n_1520" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1521" class="hl"></li>
<li id="n_1522" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">) {</span></li>
<li id="n_1523" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>UPDATE exchangerate</li>
<li id="n_1524" class="hl">                       SET <span class="hl kwb">$set</span></li>
<li id="n_1525" class="hl">                     WHERE curr <span class="hl opt">= ?</span></li>
<li id="n_1526" class="hl">                       AND transdate <span class="hl opt">= ?|;</span></li>
<li id="n_1527" class="hl">        <span class="hl kwc">push </span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1528" class="hl"></li>
<li id="n_1529" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1530" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1531" class="hl">            INSERT INTO exchangerate <span class="hl opt">(</span></li>
<li id="n_1532" class="hl">            curr<span class="hl opt">, </span>buy<span class="hl opt">, </span>sell<span class="hl opt">, </span>transdate<span class="hl opt">)</span></li>
<li id="n_1533" class="hl">            VALUES <span class="hl opt">(?, ?, ?, ?)|;</span></li>
<li id="n_1534" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$buy</span><span class="hl opt">, </span><span class="hl kwb">$sell</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1535" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1536" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1537" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1538" class="hl"></li>
<li id="n_1539" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1540" class="hl"></li>
<li id="n_1541" class="hl"><span class="hl opt">}</span></li>
<li id="n_1542" class="hl"></li>
<li id="n_1543" class="hl"></li>
<li id="n_1544" class="hl"><span class="hl kwa">sub </span>save_exchangerate <span class="hl opt">{</span></li>
<li id="n_1545" class="hl"></li>
<li id="n_1546" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$currency</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$rate</span><span class="hl opt">, </span><span class="hl kwb">$fld</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1547" class="hl"></li>
<li id="n_1548" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$buy</span><span class="hl opt">, </span><span class="hl kwb">$sell</span><span class="hl opt">) = (</span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">);</span></li>
<li id="n_1549" class="hl">    <span class="hl kwb">$buy </span><span class="hl opt">= </span><span class="hl kwb">$rate </span><span class="hl kwa">if </span><span class="hl kwb">$fld </span><span class="hl kwc">eq </span><span class="hl sng">&#39;buy&#39;</span><span class="hl opt">;</span></li>
<li id="n_1550" class="hl">    <span class="hl kwb">$sell </span><span class="hl opt">= </span><span class="hl kwb">$rate </span><span class="hl kwa">if </span><span class="hl kwb">$fld </span><span class="hl kwc">eq </span><span class="hl sng">&#39;sell&#39;</span><span class="hl opt">;</span></li>
<li id="n_1551" class="hl"></li>
<li id="n_1552" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">update_exchangerate</span><span class="hl opt">(</span></li>
<li id="n_1553" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}, </span></li>
<li id="n_1554" class="hl">            <span class="hl kwb">$currency</span><span class="hl opt">, </span></li>
<li id="n_1555" class="hl">            <span class="hl kwb">$transdate</span><span class="hl opt">, </span></li>
<li id="n_1556" class="hl">            <span class="hl kwb">$buy</span><span class="hl opt">, </span></li>
<li id="n_1557" class="hl">            <span class="hl kwb">$sell</span><span class="hl opt">);</span></li>
<li id="n_1558" class="hl"></li>
<li id="n_1559" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1560" class="hl"><span class="hl opt">}</span></li>
<li id="n_1561" class="hl"></li>
<li id="n_1562" class="hl"></li>
<li id="n_1563" class="hl"><span class="hl kwa">sub </span>get_exchangerate <span class="hl opt">{</span></li>
<li id="n_1564" class="hl"></li>
<li id="n_1565" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$fld</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1566" class="hl"></li>
<li id="n_1567" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$exchangerate </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1568" class="hl"></li>
<li id="n_1569" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1570" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1571" class="hl">            SELECT <span class="hl kwb">$fld </span>FROM exchangerate</li>
<li id="n_1572" class="hl">            WHERE curr <span class="hl opt">= ? </span>AND transdate <span class="hl opt">= ?|;</span></li>
<li id="n_1573" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1574" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$curr</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1575" class="hl"></li>
<li id="n_1576" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$exchangerate</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_1577" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1578" class="hl"></li>
<li id="n_1579" class="hl">    <span class="hl kwb">$exchangerate</span><span class="hl opt">;</span></li>
<li id="n_1580" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1581" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1582" class="hl"><span class="hl opt">}</span></li>
<li id="n_1583" class="hl"></li>
<li id="n_1584" class="hl"></li>
<li id="n_1585" class="hl"><span class="hl kwa">sub </span>check_exchangerate <span class="hl opt">{</span></li>
<li id="n_1586" class="hl"></li>
<li id="n_1587" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$currency</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$fld</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1588" class="hl"></li>
<li id="n_1589" class="hl">    <span class="hl kwa">return </span><span class="hl sng">&quot;&quot;</span> <span class="hl kwa">unless </span><span class="hl kwb">$transdate</span><span class="hl opt">;</span></li>
<li id="n_1590" class="hl"></li>
<li id="n_1591" class="hl"></li>
<li id="n_1592" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1593" class="hl">        SELECT <span class="hl kwb">$fld </span></li>
<li id="n_1594" class="hl">        FROM exchangerate</li>
<li id="n_1595" class="hl">        WHERE curr <span class="hl opt">= ? </span>AND transdate <span class="hl opt">= ?|;</span></li>
<li id="n_1596" class="hl"></li>
<li id="n_1597" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1598" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$currenct</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1599" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$exchangerate</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_1600" class="hl"></li>
<li id="n_1601" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1602" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1603" class="hl"></li>
<li id="n_1604" class="hl">    <span class="hl kwb">$exchangerate</span><span class="hl opt">;</span></li>
<li id="n_1605" class="hl"><span class="hl opt">}</span></li>
<li id="n_1606" class="hl"></li>
<li id="n_1607" class="hl"></li>
<li id="n_1608" class="hl"><span class="hl kwa">sub </span>add_shipto <span class="hl opt">{</span></li>
<li id="n_1609" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$id</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1610" class="hl"></li>
<li id="n_1611" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$shipto</span><span class="hl opt">;</span></li>
<li id="n_1612" class="hl"></li>
<li id="n_1613" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$item </span><span class="hl opt">(</span><span class="hl sng">qw(name address1 address2 city state </span></li>
<li id="n_1614" class="hl"><span class="hl sng">                         zipcode country contact phone fax email)</span><span class="hl opt">) {</span></li>
<li id="n_1615" class="hl"></li>
<li id="n_1616" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;shipto</span><span class="hl ipl">$item</span><span class="hl sng">&quot;</span><span class="hl opt">} </span><span class="hl kwc">ne </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">) {</span></li>
<li id="n_1617" class="hl">            <span class="hl kwb">$shipto </span><span class="hl opt">= </span><span class="hl num">1 </span><span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$item</span><span class="hl opt">} </span><span class="hl kwc">ne </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;shipto</span><span class="hl ipl">$item</span><span class="hl sng">&quot;</span><span class="hl opt">});</span></li>
<li id="n_1618" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1619" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1620" class="hl"></li>
<li id="n_1621" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$shipto</span><span class="hl opt">) {</span></li>
<li id="n_1622" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1623" class="hl">            INSERT INTO shipto </li>
<li id="n_1624" class="hl">            <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>shiptoname<span class="hl opt">, </span>shiptoaddress1<span class="hl opt">,</span></li>
<li id="n_1625" class="hl">                shiptoaddress2<span class="hl opt">, </span>shiptocity<span class="hl opt">, </span>shiptostate<span class="hl opt">,</span></li>
<li id="n_1626" class="hl">                shiptozipcode<span class="hl opt">, </span>shiptocountry<span class="hl opt">, </span>shiptocontact<span class="hl opt">,</span></li>
<li id="n_1627" class="hl">                shiptophone<span class="hl opt">, </span>shiptofax<span class="hl opt">, </span>shiptoemail<span class="hl opt">) </span></li>
<li id="n_1628" class="hl">            VALUES <span class="hl opt">( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</span></li>
<li id="n_1629" class="hl">            <span class="hl opt">|;</span></li>
<li id="n_1630" class="hl"></li>
<li id="n_1631" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1632" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span></li>
<li id="n_1633" class="hl">            <span class="hl kwb">$id</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptoname<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptoaddress1<span class="hl opt">},</span></li>
<li id="n_1634" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptoaddress2<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptocity<span class="hl opt">},</span></li>
<li id="n_1635" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptostate<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptostate<span class="hl opt">}, </span></li>
<li id="n_1636" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptozipcode<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptocountry<span class="hl opt">},</span></li>
<li id="n_1637" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptocontact<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptophone<span class="hl opt">},</span></li>
<li id="n_1638" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptofax<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>shiptoemail<span class="hl opt">}</span></li>
<li id="n_1639" class="hl">        <span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1640" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1641" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1642" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1643" class="hl"><span class="hl opt">}</span></li>
<li id="n_1644" class="hl"></li>
<li id="n_1645" class="hl"></li>
<li id="n_1646" class="hl"><span class="hl kwa">sub </span>get_employee <span class="hl opt">{</span></li>
<li id="n_1647" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1648" class="hl"></li>
<li id="n_1649" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$login </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>login<span class="hl opt">};</span></li>
<li id="n_1650" class="hl">    <span class="hl kwb">$login </span><span class="hl opt">=~ </span><span class="hl kwd">s/&#64;.*//</span><span class="hl opt">;</span></li>
<li id="n_1651" class="hl"></li>
<li id="n_1652" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT name<span class="hl opt">, </span>id </li>
<li id="n_1653" class="hl">                     FROM employee </li>
<li id="n_1654" class="hl">                    WHERE login <span class="hl opt">= ?|;</span></li>
<li id="n_1655" class="hl"></li>
<li id="n_1656" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1657" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$login</span><span class="hl opt">);</span></li>
<li id="n_1658" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">&#64;a</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">();</span></li>
<li id="n_1659" class="hl">    <span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl num">1</span><span class="hl opt">] *= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1660" class="hl"></li>
<li id="n_1661" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1662" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1663" class="hl"></li>
<li id="n_1664" class="hl">    <span class="hl kwb">&#64;a</span><span class="hl opt">;</span></li>
<li id="n_1665" class="hl"><span class="hl opt">}</span></li>
<li id="n_1666" class="hl"></li>
<li id="n_1667" class="hl"></li>
<li id="n_1668" class="hl"><span class="hl slc"># this sub gets the id and name from $table</span></li>
<li id="n_1669" class="hl"><span class="hl kwa">sub </span>get_name <span class="hl opt">{</span></li>
<li id="n_1670" class="hl"></li>
<li id="n_1671" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$table</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1672" class="hl"></li>
<li id="n_1673" class="hl">    <span class="hl slc"># connect to database</span></li>
<li id="n_1674" class="hl"></li>
<li id="n_1675" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">;</span></li>
<li id="n_1676" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where</span><span class="hl opt">;</span></li>
<li id="n_1677" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1678" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1679" class="hl">            AND <span class="hl opt">(</span>startdate IS NULL OR startdate <span class="hl opt">&lt;= ?)</span></li>
<li id="n_1680" class="hl">                    AND <span class="hl opt">(</span>enddate IS NULL OR enddate <span class="hl opt">&gt;= ?)|;</span></li>
<li id="n_1681" class="hl"></li>
<li id="n_1682" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1683" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1684" class="hl"></li>
<li id="n_1685" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$name </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">like</span><span class="hl opt">(</span><span class="hl kwc">lc </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$table</span><span class="hl opt">});</span></li>
<li id="n_1686" class="hl"></li>
<li id="n_1687" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1688" class="hl">        SELECT <span class="hl opt">* </span>FROM <span class="hl kwb">$table</span></li>
<li id="n_1689" class="hl">        WHERE <span class="hl opt">(</span>lower<span class="hl opt">(</span>name<span class="hl opt">) </span>LIKE <span class="hl opt">? </span>OR <span class="hl opt">${</span>table<span class="hl opt">}</span>number LIKE <span class="hl opt">?)</span></li>
<li id="n_1690" class="hl">        <span class="hl kwb">$where</span></li>
<li id="n_1691" class="hl">        ORDER BY name<span class="hl opt">|;</span></li>
<li id="n_1692" class="hl"></li>
<li id="n_1693" class="hl">    <span class="hl kwc">unshift</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$name</span><span class="hl opt">, </span><span class="hl kwb">$name</span><span class="hl opt">);</span></li>
<li id="n_1694" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1695" class="hl"></li>
<li id="n_1696" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1697" class="hl"></li>
<li id="n_1698" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1699" class="hl">    <span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>name_list<span class="hl opt">} } = ();</span></li>
<li id="n_1700" class="hl"></li>
<li id="n_1701" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1702" class="hl">        <span class="hl kwc">push</span><span class="hl opt">(&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>name_list<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">);</span></li>
<li id="n_1703" class="hl">        <span class="hl kwb">$i++</span><span class="hl opt">;</span></li>
<li id="n_1704" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1705" class="hl"></li>
<li id="n_1706" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1707" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1708" class="hl"></li>
<li id="n_1709" class="hl">    <span class="hl kwb">$i</span><span class="hl opt">;</span></li>
<li id="n_1710" class="hl"></li>
<li id="n_1711" class="hl"><span class="hl opt">}</span></li>
<li id="n_1712" class="hl"></li>
<li id="n_1713" class="hl"></li>
<li id="n_1714" class="hl"><span class="hl kwa">sub </span>all_vc <span class="hl opt">{</span></li>
<li id="n_1715" class="hl"></li>
<li id="n_1716" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">, </span><span class="hl kwb">$module</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$job</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1717" class="hl"></li>
<li id="n_1718" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1719" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$disconnect </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_1720" class="hl"></li>
<li id="n_1721" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1722" class="hl"></li>
<li id="n_1723" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth</span><span class="hl opt">;</span></li>
<li id="n_1724" class="hl"></li>
<li id="n_1725" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT count<span class="hl opt">(*) </span>FROM <span class="hl kwb">$vc</span><span class="hl opt">|;</span></li>
<li id="n_1726" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where</span><span class="hl opt">;</span></li>
<li id="n_1727" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_1728" class="hl"></li>
<li id="n_1729" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1730" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>WHERE <span class="hl opt">(</span>startdate IS NULL OR startdate <span class="hl opt">&lt;= ?)</span></li>
<li id="n_1731" class="hl">                    AND <span class="hl opt">(</span>enddate IS NULL OR enddate <span class="hl opt">&gt;= ?)|;</span></li>
<li id="n_1732" class="hl"></li>
<li id="n_1733" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);      </span></li>
<li id="n_1734" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1735" class="hl"></li>
<li id="n_1736" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1737" class="hl"></li>
<li id="n_1738" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">);</span></li>
<li id="n_1739" class="hl"></li>
<li id="n_1740" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$count</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_1741" class="hl"></li>
<li id="n_1742" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1743" class="hl">    <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_1744" class="hl">    <span class="hl slc"># build selection list</span></li>
<li id="n_1745" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$count </span><span class="hl opt">&lt; </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>vclimit<span class="hl opt">}) {</span></li>
<li id="n_1746" class="hl"></li>
<li id="n_1747" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${vc}_id&quot;</span><span class="hl opt">} *= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_1748" class="hl"></li>
<li id="n_1749" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT id<span class="hl opt">, </span>name</li>
<li id="n_1750" class="hl">                      FROM <span class="hl kwb">$vc</span></li>
<li id="n_1751" class="hl">                     WHERE <span class="hl num">1</span><span class="hl opt">=</span><span class="hl num">1</span></li>
<li id="n_1752" class="hl">                           <span class="hl kwb">$where</span></li>
<li id="n_1753" class="hl"></li>
<li id="n_1754" class="hl">                     UNION </li>
<li id="n_1755" class="hl"></li>
<li id="n_1756" class="hl">                    SELECT id<span class="hl opt">,</span>name</li>
<li id="n_1757" class="hl">                      FROM <span class="hl kwb">$vc</span></li>
<li id="n_1758" class="hl">                     WHERE id <span class="hl opt">= ?</span></li>
<li id="n_1759" class="hl">                  ORDER BY name<span class="hl opt">|;</span></li>
<li id="n_1760" class="hl"></li>
<li id="n_1761" class="hl">        <span class="hl kwc">push</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${vc}_id&quot;</span><span class="hl opt">});</span></li>
<li id="n_1762" class="hl"></li>
<li id="n_1763" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1764" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1765" class="hl"></li>
<li id="n_1766" class="hl">        <span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;all_</span><span class="hl ipl">$vc</span><span class="hl sng">&quot;</span><span class="hl opt">} } = ();</span></li>
<li id="n_1767" class="hl"></li>
<li id="n_1768" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1769" class="hl">            <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;all_</span><span class="hl ipl">$vc</span><span class="hl sng">&quot;</span><span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1770" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1771" class="hl"></li>
<li id="n_1772" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1773" class="hl"></li>
<li id="n_1774" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1775" class="hl"></li>
<li id="n_1776" class="hl">    <span class="hl slc"># get self</span></li>
<li id="n_1777" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee_id<span class="hl opt">}) {</span></li>
<li id="n_1778" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee_id<span class="hl opt">}) = </span><span class="hl kwc">split </span><span class="hl kwd">/--/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee<span class="hl opt">};</span></li>
<li id="n_1779" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee_id<span class="hl opt">}) = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">get_employee</span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">) </span><span class="hl kwa">unless </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>employee_id<span class="hl opt">};</span></li>
<li id="n_1780" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1781" class="hl"></li>
<li id="n_1782" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_employees</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_1783" class="hl"></li>
<li id="n_1784" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_departments</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">);</span></li>
<li id="n_1785" class="hl"></li>
<li id="n_1786" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_projects</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$job</span><span class="hl opt">);</span></li>
<li id="n_1787" class="hl"></li>
<li id="n_1788" class="hl">    <span class="hl slc"># get language codes</span></li>
<li id="n_1789" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT <span class="hl opt">*</span></li>
<li id="n_1790" class="hl">                  FROM language</li>
<li id="n_1791" class="hl">              ORDER BY <span class="hl num">2</span><span class="hl opt">|;</span></li>
<li id="n_1792" class="hl"></li>
<li id="n_1793" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1794" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1795" class="hl"></li>
<li id="n_1796" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_language<span class="hl opt">} = ();</span></li>
<li id="n_1797" class="hl"></li>
<li id="n_1798" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1799" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_language<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1800" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1801" class="hl"></li>
<li id="n_1802" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1803" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_taxaccounts</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1804" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1805" class="hl"><span class="hl opt">}</span></li>
<li id="n_1806" class="hl"></li>
<li id="n_1807" class="hl"></li>
<li id="n_1808" class="hl"><span class="hl kwa">sub </span>all_taxaccounts <span class="hl opt">{</span></li>
<li id="n_1809" class="hl"></li>
<li id="n_1810" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1811" class="hl"></li>
<li id="n_1812" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1813" class="hl"></li>
<li id="n_1814" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth</span><span class="hl opt">;</span></li>
<li id="n_1815" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query</span><span class="hl opt">;</span></li>
<li id="n_1816" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where</span><span class="hl opt">;</span></li>
<li id="n_1817" class="hl"></li>
<li id="n_1818" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_1819" class="hl"></li>
<li id="n_1820" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1821" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>AND <span class="hl opt">(</span>t<span class="hl opt">.</span>validto <span class="hl opt">&gt;= ? </span>OR t<span class="hl opt">.</span>validto IS NULL<span class="hl opt">)|;</span></li>
<li id="n_1822" class="hl">        <span class="hl kwc">push</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1823" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1824" class="hl"></li>
<li id="n_1825" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>taxaccounts<span class="hl opt">}) {</span></li>
<li id="n_1826" class="hl"></li>
<li id="n_1827" class="hl">        <span class="hl slc"># rebuild tax rates</span></li>
<li id="n_1828" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT t<span class="hl opt">.</span>rate<span class="hl opt">, </span>t<span class="hl opt">.</span>taxnumber </li>
<li id="n_1829" class="hl">                      FROM tax t </li>
<li id="n_1830" class="hl">                      JOIN chart c ON <span class="hl opt">(</span>c<span class="hl opt">.</span>id <span class="hl opt">= </span>t<span class="hl opt">.</span>chart_id<span class="hl opt">) </span></li>
<li id="n_1831" class="hl">                     WHERE c<span class="hl opt">.</span>accno <span class="hl opt">= ?</span></li>
<li id="n_1832" class="hl">                    <span class="hl kwb">$where</span></li>
<li id="n_1833" class="hl">                  ORDER BY accno<span class="hl opt">, </span>validto<span class="hl opt">|;</span></li>
<li id="n_1834" class="hl"></li>
<li id="n_1835" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1836" class="hl"></li>
<li id="n_1837" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$accno </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/ /</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>taxaccounts<span class="hl opt">}) {</span></li>
<li id="n_1838" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$accno</span><span class="hl opt">, </span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">); </span></li>
<li id="n_1839" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${accno}_rate&quot;</span><span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${accno}_taxnumber&quot;</span><span class="hl opt">}) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_1840" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1841" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1842" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1843" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1844" class="hl"><span class="hl opt">}</span></li>
<li id="n_1845" class="hl"></li>
<li id="n_1846" class="hl"></li>
<li id="n_1847" class="hl"><span class="hl kwa">sub </span>all_employees <span class="hl opt">{</span></li>
<li id="n_1848" class="hl"></li>
<li id="n_1849" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$sales</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1850" class="hl"></li>
<li id="n_1851" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1852" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;whereargs </span><span class="hl opt">= ();</span></li>
<li id="n_1853" class="hl">    <span class="hl slc"># setup employees/sales contacts</span></li>
<li id="n_1854" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT id<span class="hl opt">, </span>name</li>
<li id="n_1855" class="hl">                     FROM employee</li>
<li id="n_1856" class="hl">                    WHERE <span class="hl num">1 </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">|;</span></li>
<li id="n_1857" class="hl"></li>
<li id="n_1858" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1859" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>AND <span class="hl opt">(</span>startdate IS NULL OR startdate <span class="hl opt">&lt;= ?)</span></li>
<li id="n_1860" class="hl">        AND <span class="hl opt">(</span>enddate IS NULL OR enddate <span class="hl opt">&gt;= ?)|;</span></li>
<li id="n_1861" class="hl">        <span class="hl kwb">&#64;whereargs </span><span class="hl opt">= (</span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1862" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_1863" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>AND enddate IS NULL<span class="hl opt">|;</span></li>
<li id="n_1864" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1865" class="hl"></li>
<li id="n_1866" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$sales</span><span class="hl opt">) {</span></li>
<li id="n_1867" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>AND sales <span class="hl opt">= </span><span class="hl sng">&#39;1&#39;</span><span class="hl opt">|;</span></li>
<li id="n_1868" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1869" class="hl"></li>
<li id="n_1870" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>ORDER BY name<span class="hl opt">|;</span></li>
<li id="n_1871" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1872" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;whereargs</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1873" class="hl"></li>
<li id="n_1874" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1875" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_employee<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1876" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1877" class="hl"></li>
<li id="n_1878" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1879" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1880" class="hl"><span class="hl opt">}</span></li>
<li id="n_1881" class="hl"></li>
<li id="n_1882" class="hl"></li>
<li id="n_1883" class="hl"></li>
<li id="n_1884" class="hl"><span class="hl kwa">sub </span>all_projects <span class="hl opt">{</span></li>
<li id="n_1885" class="hl"></li>
<li id="n_1886" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$job</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1887" class="hl"></li>
<li id="n_1888" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1889" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_1890" class="hl"></li>
<li id="n_1891" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot;1 = 1&quot;</span><span class="hl opt">;</span></li>
<li id="n_1892" class="hl"></li>
<li id="n_1893" class="hl">    <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>id NOT IN <span class="hl opt">(</span>SELECT id</li>
<li id="n_1894" class="hl">                             FROM parts</li>
<li id="n_1895" class="hl">                            WHERE project_id <span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">)| </span><span class="hl kwa">if </span><span class="hl opt">! </span><span class="hl kwb">$job</span><span class="hl opt">;</span></li>
<li id="n_1896" class="hl"></li>
<li id="n_1897" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT <span class="hl opt">*</span></li>
<li id="n_1898" class="hl">                     FROM project</li>
<li id="n_1899" class="hl">                    WHERE <span class="hl kwb">$where</span><span class="hl opt">|;</span></li>
<li id="n_1900" class="hl"></li>
<li id="n_1901" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>language_code<span class="hl opt">}) {</span></li>
<li id="n_1902" class="hl"></li>
<li id="n_1903" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1904" class="hl">            SELECT pr<span class="hl opt">.*, </span>t<span class="hl opt">.</span>description AS translation</li>
<li id="n_1905" class="hl">            FROM project pr</li>
<li id="n_1906" class="hl">            LEFT JOIN translation t ON <span class="hl opt">(</span>t<span class="hl opt">.</span>trans_id <span class="hl opt">= </span>pr<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_1907" class="hl">            WHERE t<span class="hl opt">.</span>language_code <span class="hl opt">= ?|;</span></li>
<li id="n_1908" class="hl">        <span class="hl kwc">push</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>language_code<span class="hl opt">});</span></li>
<li id="n_1909" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1910" class="hl"></li>
<li id="n_1911" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$transdate</span><span class="hl opt">) {</span></li>
<li id="n_1912" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>AND <span class="hl opt">(</span>startdate IS NULL OR startdate <span class="hl opt">&lt;= ?)</span></li>
<li id="n_1913" class="hl">                AND <span class="hl opt">(</span>enddate IS NULL OR enddate <span class="hl opt">&gt;= ?)|;</span></li>
<li id="n_1914" class="hl">        <span class="hl kwc">push</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">, </span><span class="hl kwb">$transdate</span><span class="hl opt">);</span></li>
<li id="n_1915" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1916" class="hl"></li>
<li id="n_1917" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span>ORDER BY projectnumber<span class="hl opt">|;</span></li>
<li id="n_1918" class="hl"></li>
<li id="n_1919" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1920" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">)|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1921" class="hl"></li>
<li id="n_1922" class="hl">    <span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_project<span class="hl opt">} } = ();</span></li>
<li id="n_1923" class="hl"></li>
<li id="n_1924" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1925" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_project<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1926" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1927" class="hl"></li>
<li id="n_1928" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1929" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1930" class="hl"><span class="hl opt">}</span></li>
<li id="n_1931" class="hl"></li>
<li id="n_1932" class="hl"></li>
<li id="n_1933" class="hl"><span class="hl kwa">sub </span>all_departments <span class="hl opt">{</span></li>
<li id="n_1934" class="hl"></li>
<li id="n_1935" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1936" class="hl"></li>
<li id="n_1937" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1938" class="hl"></li>
<li id="n_1939" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot;1 = 1&quot;</span><span class="hl opt">;</span></li>
<li id="n_1940" class="hl"></li>
<li id="n_1941" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$vc</span><span class="hl opt">) {</span></li>
<li id="n_1942" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$vc </span><span class="hl kwc">eq </span><span class="hl sng">&#39;customer&#39;</span><span class="hl opt">) {</span></li>
<li id="n_1943" class="hl">            <span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot; role = &#39;P&#39;&quot;</span><span class="hl opt">;</span></li>
<li id="n_1944" class="hl">        <span class="hl opt">}</span></li>
<li id="n_1945" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1946" class="hl"></li>
<li id="n_1947" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT id<span class="hl opt">, </span>description</li>
<li id="n_1948" class="hl">                     FROM department</li>
<li id="n_1949" class="hl">                    WHERE <span class="hl kwb">$where</span></li>
<li id="n_1950" class="hl">                 ORDER BY <span class="hl num">2</span><span class="hl opt">|;</span></li>
<li id="n_1951" class="hl"></li>
<li id="n_1952" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1953" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1954" class="hl"></li>
<li id="n_1955" class="hl">    <span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_department<span class="hl opt">} } = ();</span></li>
<li id="n_1956" class="hl"></li>
<li id="n_1957" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_1958" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_department<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_1959" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1960" class="hl"></li>
<li id="n_1961" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_1962" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_years</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">);</span></li>
<li id="n_1963" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_1964" class="hl"><span class="hl opt">}</span></li>
<li id="n_1965" class="hl"></li>
<li id="n_1966" class="hl"></li>
<li id="n_1967" class="hl"><span class="hl kwa">sub </span>all_years <span class="hl opt">{</span></li>
<li id="n_1968" class="hl"></li>
<li id="n_1969" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_1970" class="hl"></li>
<li id="n_1971" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_1972" class="hl"></li>
<li id="n_1973" class="hl">    <span class="hl slc"># get years</span></li>
<li id="n_1974" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_1975" class="hl">        SELECT <span class="hl opt">(</span>SELECT MIN<span class="hl opt">(</span>transdate<span class="hl opt">) </span>FROM acc_trans<span class="hl opt">),</span></li>
<li id="n_1976" class="hl">               <span class="hl opt">(</span>SELECT MAX<span class="hl opt">(</span>transdate<span class="hl opt">) </span>FROM acc_trans<span class="hl opt">)|;</span></li>
<li id="n_1977" class="hl"></li>
<li id="n_1978" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$startdate</span><span class="hl opt">, </span><span class="hl kwb">$enddate</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_1979" class="hl"></li>
<li id="n_1980" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} =~ </span><span class="hl kwd">/^yy/</span><span class="hl opt">) {</span></li>
<li id="n_1981" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$startdate</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\W/</span><span class="hl opt">, </span><span class="hl kwb">$startdate</span><span class="hl opt">;</span></li>
<li id="n_1982" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$enddate</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\W/</span><span class="hl opt">, </span><span class="hl kwb">$enddate</span><span class="hl opt">;</span></li>
<li id="n_1983" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{ </span></li>
<li id="n_1984" class="hl">        <span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\W/</span><span class="hl opt">, </span><span class="hl kwb">$startdate</span><span class="hl opt">;</span></li>
<li id="n_1985" class="hl">        <span class="hl kwb">$startdate </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">];</span></li>
<li id="n_1986" class="hl">        <span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\W/</span><span class="hl opt">, </span><span class="hl kwb">$enddate</span><span class="hl opt">;</span></li>
<li id="n_1987" class="hl">        <span class="hl kwb">$enddate </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">]; </span></li>
<li id="n_1988" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1989" class="hl"></li>
<li id="n_1990" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_years<span class="hl opt">} = ();</span></li>
<li id="n_1991" class="hl">    <span class="hl kwb">$startdate </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$startdate</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">4</span><span class="hl opt">);</span></li>
<li id="n_1992" class="hl">    <span class="hl kwb">$enddate </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$enddate</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">4</span><span class="hl opt">);</span></li>
<li id="n_1993" class="hl"></li>
<li id="n_1994" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$enddate </span><span class="hl opt">&gt;= </span><span class="hl kwb">$startdate</span><span class="hl opt">) {</span></li>
<li id="n_1995" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_years<span class="hl opt">} }, </span><span class="hl kwb">$enddate</span><span class="hl opt">--;</span></li>
<li id="n_1996" class="hl">    <span class="hl opt">}</span></li>
<li id="n_1997" class="hl"></li>
<li id="n_1998" class="hl">    <span class="hl slc">#this should probably be changed to use locale</span></li>
<li id="n_1999" class="hl">    <span class="hl opt">%{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_month<span class="hl opt">} } = ( </span></li>
<li id="n_2000" class="hl">        <span class="hl sng">&#39;01&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;January&#39;</span><span class="hl opt">,</span></li>
<li id="n_2001" class="hl">        <span class="hl sng">&#39;02&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;February&#39;</span><span class="hl opt">,</span></li>
<li id="n_2002" class="hl">        <span class="hl sng">&#39;03&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;March&#39;</span><span class="hl opt">,</span></li>
<li id="n_2003" class="hl">        <span class="hl sng">&#39;04&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;April&#39;</span><span class="hl opt">,</span></li>
<li id="n_2004" class="hl">        <span class="hl sng">&#39;05&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;May &#39;</span><span class="hl opt">,</span></li>
<li id="n_2005" class="hl">        <span class="hl sng">&#39;06&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;June&#39;</span><span class="hl opt">,</span></li>
<li id="n_2006" class="hl">        <span class="hl sng">&#39;07&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;July&#39;</span><span class="hl opt">,</span></li>
<li id="n_2007" class="hl">        <span class="hl sng">&#39;08&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;August&#39;</span><span class="hl opt">,</span></li>
<li id="n_2008" class="hl">        <span class="hl sng">&#39;09&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;September&#39;</span><span class="hl opt">,</span></li>
<li id="n_2009" class="hl">        <span class="hl sng">&#39;10&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;October&#39;</span><span class="hl opt">,</span></li>
<li id="n_2010" class="hl">        <span class="hl sng">&#39;11&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;November&#39;</span><span class="hl opt">,</span></li>
<li id="n_2011" class="hl">        <span class="hl sng">&#39;12&#39;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;December&#39;</span> <span class="hl opt">);</span></li>
<li id="n_2012" class="hl"></li>
<li id="n_2013" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2014" class="hl"><span class="hl opt">}</span></li>
<li id="n_2015" class="hl"></li>
<li id="n_2016" class="hl"></li>
<li id="n_2017" class="hl"><span class="hl kwa">sub </span>create_links <span class="hl opt">{</span></li>
<li id="n_2018" class="hl"></li>
<li id="n_2019" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$module</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">, </span><span class="hl kwb">$job</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2020" class="hl"></li>
<li id="n_2021" class="hl">    <span class="hl slc"># get last customers or vendors</span></li>
<li id="n_2022" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">, </span><span class="hl kwb">$sth</span><span class="hl opt">);</span></li>
<li id="n_2023" class="hl"></li>
<li id="n_2024" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2025" class="hl"></li>
<li id="n_2026" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%xkeyref </span><span class="hl opt">= ();</span></li>
<li id="n_2027" class="hl"></li>
<li id="n_2028" class="hl"></li>
<li id="n_2029" class="hl">    <span class="hl slc"># now get the account numbers</span></li>
<li id="n_2030" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT accno<span class="hl opt">, </span>description<span class="hl opt">, </span><span class="hl kwc">link</span></li>
<li id="n_2031" class="hl">                  FROM chart</li>
<li id="n_2032" class="hl">                 WHERE <span class="hl kwc">link </span>LIKE <span class="hl opt">?</span></li>
<li id="n_2033" class="hl">              ORDER BY accno<span class="hl opt">|;</span></li>
<li id="n_2034" class="hl"></li>
<li id="n_2035" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2036" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl sng">&quot;%&quot;</span><span class="hl opt">.</span><span class="hl sng">&quot;</span><span class="hl ipl">$module%</span><span class="hl sng">&quot;</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2037" class="hl"></li>
<li id="n_2038" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>accounts<span class="hl opt">} = </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2039" class="hl"></li>
<li id="n_2040" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_2041" class="hl"></li>
<li id="n_2042" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$key </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/:/</span><span class="hl opt">, </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span><span class="hl kwc">link</span><span class="hl opt">}) {</span></li>
<li id="n_2043" class="hl"></li>
<li id="n_2044" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$key </span><span class="hl opt">=~ </span><span class="hl kwd">/$module/</span><span class="hl opt">) {</span></li>
<li id="n_2045" class="hl">                <span class="hl slc"># cross reference for keys</span></li>
<li id="n_2046" class="hl">                <span class="hl kwb">$xkeyref</span><span class="hl opt">{</span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>accno<span class="hl opt">}} = </span><span class="hl kwb">$key</span><span class="hl opt">;</span></li>
<li id="n_2047" class="hl"></li>
<li id="n_2048" class="hl">                <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${module}_links&quot;</span><span class="hl opt">}{</span><span class="hl kwb">$key</span><span class="hl opt">} }, </span></li>
<li id="n_2049" class="hl">                    <span class="hl opt">{ </span>accno <span class="hl opt">=&gt; </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>accno<span class="hl opt">},</span></li>
<li id="n_2050" class="hl">                    description <span class="hl opt">=&gt; </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>description<span class="hl opt">} };</span></li>
<li id="n_2051" class="hl"></li>
<li id="n_2052" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>accounts<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{accno} &quot;</span> </li>
<li id="n_2053" class="hl">                    <span class="hl kwa">unless </span><span class="hl kwb">$key </span><span class="hl opt">=~ </span><span class="hl kwd">/tax/</span><span class="hl opt">;</span></li>
<li id="n_2054" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2055" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2056" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2057" class="hl"></li>
<li id="n_2058" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2059" class="hl"></li>
<li id="n_2060" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$arap </span><span class="hl opt">= (</span><span class="hl kwb">$vc </span><span class="hl kwc">eq </span><span class="hl sng">&#39;customer&#39;</span><span class="hl opt">) ? </span><span class="hl sng">&#39;ar&#39;</span> <span class="hl opt">: </span><span class="hl sng">&#39;ap&#39;</span><span class="hl opt">;</span></li>
<li id="n_2061" class="hl"></li>
<li id="n_2062" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) {</span></li>
<li id="n_2063" class="hl"></li>
<li id="n_2064" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2065" class="hl">            SELECT a<span class="hl opt">.</span>invnumber<span class="hl opt">, </span>a<span class="hl opt">.</span>transdate<span class="hl opt">,</span></li>
<li id="n_2066" class="hl">                a<span class="hl opt">.${</span>vc<span class="hl opt">}</span>_id<span class="hl opt">, </span>a<span class="hl opt">.</span>datepaid<span class="hl opt">, </span>a<span class="hl opt">.</span>duedate<span class="hl opt">, </span>a<span class="hl opt">.</span>ordnumber<span class="hl opt">,</span></li>
<li id="n_2067" class="hl">                a<span class="hl opt">.</span>taxincluded<span class="hl opt">, </span>a<span class="hl opt">.</span>curr AS currency<span class="hl opt">, </span>a<span class="hl opt">.</span>notes<span class="hl opt">, </span></li>
<li id="n_2068" class="hl">                a<span class="hl opt">.</span>intnotes<span class="hl opt">, </span>c<span class="hl opt">.</span>name AS <span class="hl kwb">$vc</span><span class="hl opt">, </span>a<span class="hl opt">.</span>department_id<span class="hl opt">, </span></li>
<li id="n_2069" class="hl">                d<span class="hl opt">.</span>description AS department<span class="hl opt">,</span></li>
<li id="n_2070" class="hl">                a<span class="hl opt">.</span>amount AS oldinvtotal<span class="hl opt">, </span>a<span class="hl opt">.</span>paid AS oldtotalpaid<span class="hl opt">,</span></li>
<li id="n_2071" class="hl">                a<span class="hl opt">.</span>employee_id<span class="hl opt">, </span>e<span class="hl opt">.</span>name AS employee<span class="hl opt">, </span></li>
<li id="n_2072" class="hl">                c<span class="hl opt">.</span>language_code<span class="hl opt">, </span>a<span class="hl opt">.</span>ponumber</li>
<li id="n_2073" class="hl">            FROM <span class="hl kwb">$arap </span>a</li>
<li id="n_2074" class="hl">            JOIN <span class="hl kwb">$vc </span>c ON <span class="hl opt">(</span>a<span class="hl opt">.${</span>vc<span class="hl opt">}</span>_id <span class="hl opt">= </span>c<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2075" class="hl">            LEFT JOIN employee e ON <span class="hl opt">(</span>e<span class="hl opt">.</span>id <span class="hl opt">= </span>a<span class="hl opt">.</span>employee_id<span class="hl opt">)</span></li>
<li id="n_2076" class="hl">            LEFT JOIN department d ON <span class="hl opt">(</span>d<span class="hl opt">.</span>id <span class="hl opt">= </span>a<span class="hl opt">.</span>department_id<span class="hl opt">)</span></li>
<li id="n_2077" class="hl">            WHERE a<span class="hl opt">.</span>id <span class="hl opt">= ?|;</span></li>
<li id="n_2078" class="hl"></li>
<li id="n_2079" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2080" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2081" class="hl"></li>
<li id="n_2082" class="hl">        <span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">);</span></li>
<li id="n_2083" class="hl"></li>
<li id="n_2084" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwb">$key </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%$ref</span><span class="hl opt">) {</span></li>
<li id="n_2085" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$key</span><span class="hl opt">} = </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$key</span><span class="hl opt">};</span></li>
<li id="n_2086" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2087" class="hl"></li>
<li id="n_2088" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2089" class="hl"></li>
<li id="n_2090" class="hl"></li>
<li id="n_2091" class="hl">        <span class="hl slc"># get printed, emailed</span></li>
<li id="n_2092" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2093" class="hl">            SELECT s<span class="hl opt">.</span>printed<span class="hl opt">, </span>s<span class="hl opt">.</span>emailed<span class="hl opt">, </span>s<span class="hl opt">.</span>spoolfile<span class="hl opt">, </span>s<span class="hl opt">.</span>formname</li>
<li id="n_2094" class="hl">            FROM status s WHERE s<span class="hl opt">.</span>trans_id <span class="hl opt">= ?|;</span></li>
<li id="n_2095" class="hl"></li>
<li id="n_2096" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2097" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2098" class="hl"></li>
<li id="n_2099" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_2100" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>printed<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{formname} &quot;</span> </li>
<li id="n_2101" class="hl">                <span class="hl kwa">if </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>printed<span class="hl opt">};</span></li>
<li id="n_2102" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>emailed<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{formname} &quot;</span> </li>
<li id="n_2103" class="hl">                <span class="hl kwa">if </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>emailed<span class="hl opt">};</span></li>
<li id="n_2104" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>queued<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{formname} &quot;</span><span class="hl opt">.</span></li>
<li id="n_2105" class="hl">                <span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{spoolfile} &quot;</span> <span class="hl kwa">if </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>spoolfile<span class="hl opt">};</span></li>
<li id="n_2106" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2107" class="hl"></li>
<li id="n_2108" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2109" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(printed emailed queued)</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} =~ </span><span class="hl kwd">s/ +$//g </span><span class="hl opt">}</span></li>
<li id="n_2110" class="hl"></li>
<li id="n_2111" class="hl">        <span class="hl slc"># get recurring</span></li>
<li id="n_2112" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">get_recurring</span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">);</span></li>
<li id="n_2113" class="hl"></li>
<li id="n_2114" class="hl">        <span class="hl slc"># get amounts from individual entries</span></li>
<li id="n_2115" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2116" class="hl">            SELECT c<span class="hl opt">.</span>accno<span class="hl opt">, </span>c<span class="hl opt">.</span>description<span class="hl opt">, </span>a<span class="hl opt">.</span>source<span class="hl opt">, </span>a<span class="hl opt">.</span>amount<span class="hl opt">,</span></li>
<li id="n_2117" class="hl">                a<span class="hl opt">.</span>memo<span class="hl opt">, </span>a<span class="hl opt">.</span>transdate<span class="hl opt">, </span>a<span class="hl opt">.</span>cleared<span class="hl opt">, </span>a<span class="hl opt">.</span>project_id<span class="hl opt">,</span></li>
<li id="n_2118" class="hl">                p<span class="hl opt">.</span>projectnumber</li>
<li id="n_2119" class="hl">            FROM acc_trans a</li>
<li id="n_2120" class="hl">            JOIN chart c ON <span class="hl opt">(</span>c<span class="hl opt">.</span>id <span class="hl opt">= </span>a<span class="hl opt">.</span>chart_id<span class="hl opt">)</span></li>
<li id="n_2121" class="hl">            LEFT JOIN project p ON <span class="hl opt">(</span>p<span class="hl opt">.</span>id <span class="hl opt">= </span>a<span class="hl opt">.</span>project_id<span class="hl opt">)</span></li>
<li id="n_2122" class="hl">            WHERE a<span class="hl opt">.</span>trans_id <span class="hl opt">= ?</span></li>
<li id="n_2123" class="hl">                AND a<span class="hl opt">.</span>fx_transaction <span class="hl opt">= </span><span class="hl sng">&#39;0&#39;</span></li>
<li id="n_2124" class="hl">            ORDER BY transdate<span class="hl opt">|;</span></li>
<li id="n_2125" class="hl"></li>
<li id="n_2126" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2127" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2128" class="hl"></li>
<li id="n_2129" class="hl"></li>
<li id="n_2130" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$fld </span><span class="hl opt">= (</span><span class="hl kwb">$vc </span><span class="hl kwc">eq </span><span class="hl sng">&#39;customer&#39;</span><span class="hl opt">) ? </span><span class="hl sng">&#39;buy&#39;</span> <span class="hl opt">: </span><span class="hl sng">&#39;sell&#39;</span><span class="hl opt">;</span></li>
<li id="n_2131" class="hl"></li>
<li id="n_2132" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>exchangerate<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">get_exchangerate</span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">, </span></li>
<li id="n_2133" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>currency<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}, </span><span class="hl kwb">$fld</span><span class="hl opt">);</span></li>
<li id="n_2134" class="hl"></li>
<li id="n_2135" class="hl">        <span class="hl slc"># store amounts in {acc_trans}{$key} for multiple accounts</span></li>
<li id="n_2136" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_2137" class="hl">            <span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>exchangerate<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">get_exchangerate</span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">, </span></li>
<li id="n_2138" class="hl">                    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>currency<span class="hl opt">}, </span></li>
<li id="n_2139" class="hl">                    <span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}, </span></li>
<li id="n_2140" class="hl">                    <span class="hl kwb">$fld</span><span class="hl opt">);</span></li>
<li id="n_2141" class="hl"></li>
<li id="n_2142" class="hl">            <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>acc_trans<span class="hl opt">}{</span><span class="hl kwb">$xkeyref</span><span class="hl opt">{</span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span>accno<span class="hl opt">}}} }, </span></li>
<li id="n_2143" class="hl">                <span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_2144" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2145" class="hl"></li>
<li id="n_2146" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2147" class="hl"></li>
<li id="n_2148" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(curr closedto revtrans)</span><span class="hl opt">){</span></li>
<li id="n_2149" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2150" class="hl">                SELECT value FROM defaults </li>
<li id="n_2151" class="hl">                 WHERE setting_key <span class="hl opt">= </span><span class="hl sng">&#39;</span><span class="hl ipl">$_</span><span class="hl sng">&#39;</span><span class="hl opt">|;</span></li>
<li id="n_2152" class="hl"></li>
<li id="n_2153" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2154" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2155" class="hl"></li>
<li id="n_2156" class="hl">            <span class="hl opt">(</span><span class="hl kwc">undef</span><span class="hl opt">, </span><span class="hl kwb">$val</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">();</span></li>
<li id="n_2157" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl kwc">eq </span><span class="hl sng">&#39;curr&#39;</span><span class="hl opt">){</span></li>
<li id="n_2158" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>currencies<span class="hl opt">} = </span><span class="hl kwb">$val</span><span class="hl opt">;</span></li>
<li id="n_2159" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2160" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$val</span><span class="hl opt">;</span></li>
<li id="n_2161" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2162" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2163" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2164" class="hl"></li>
<li id="n_2165" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2166" class="hl"></li>
<li id="n_2167" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(current_date curr closedto revtrans)</span><span class="hl opt">){</span></li>
<li id="n_2168" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2169" class="hl">                SELECT value FROM defaults </li>
<li id="n_2170" class="hl">                 WHERE setting_key <span class="hl opt">= </span><span class="hl sng">&#39;</span><span class="hl ipl">$_</span><span class="hl sng">&#39;</span><span class="hl opt">|;</span></li>
<li id="n_2171" class="hl"></li>
<li id="n_2172" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2173" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2174" class="hl"></li>
<li id="n_2175" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$val</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">();</span></li>
<li id="n_2176" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl kwc">eq </span><span class="hl sng">&#39;curr&#39;</span><span class="hl opt">){</span></li>
<li id="n_2177" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>currencies<span class="hl opt">} = </span><span class="hl kwb">$val</span><span class="hl opt">;</span></li>
<li id="n_2178" class="hl">            <span class="hl opt">} </span><span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$_ </span><span class="hl kwc">eq </span><span class="hl sng">&#39;current_date&#39;</span><span class="hl opt">){</span></li>
<li id="n_2179" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">} = </span><span class="hl kwb">$val</span><span class="hl opt">;</span></li>
<li id="n_2180" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2181" class="hl">                <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$val</span><span class="hl opt">;</span></li>
<li id="n_2182" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2183" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2184" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2185" class="hl"></li>
<li id="n_2186" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{vc}_id&quot;</span><span class="hl opt">}) {</span></li>
<li id="n_2187" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">lastname_used</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">, </span><span class="hl kwb">$module</span><span class="hl opt">);</span></li>
<li id="n_2188" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2189" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2190" class="hl"></li>
<li id="n_2191" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">all_vc</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">, </span><span class="hl kwb">$module</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}, </span><span class="hl kwb">$job</span><span class="hl opt">);</span></li>
<li id="n_2192" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">}-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2193" class="hl"><span class="hl opt">}</span></li>
<li id="n_2194" class="hl"></li>
<li id="n_2195" class="hl"></li>
<li id="n_2196" class="hl"><span class="hl kwa">sub </span>lastname_used <span class="hl opt">{</span></li>
<li id="n_2197" class="hl"></li>
<li id="n_2198" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">, </span><span class="hl kwb">$module</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2199" class="hl"></li>
<li id="n_2200" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2201" class="hl"></li>
<li id="n_2202" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$arap </span><span class="hl opt">= (</span><span class="hl kwb">$vc </span><span class="hl kwc">eq </span><span class="hl sng">&#39;customer&#39;</span><span class="hl opt">) ? </span><span class="hl sng">&quot;ar&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;ap&quot;</span><span class="hl opt">;</span></li>
<li id="n_2203" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot;1 = 1&quot;</span><span class="hl opt">;</span></li>
<li id="n_2204" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth</span><span class="hl opt">;</span></li>
<li id="n_2205" class="hl"></li>
<li id="n_2206" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>type<span class="hl opt">} =~ </span><span class="hl kwd">/_order/</span><span class="hl opt">) {</span></li>
<li id="n_2207" class="hl">        <span class="hl kwb">$arap </span><span class="hl opt">= </span><span class="hl sng">&#39;oe&#39;</span><span class="hl opt">;</span></li>
<li id="n_2208" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot;quotation = &#39;0&#39;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2209" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2210" class="hl"></li>
<li id="n_2211" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>type<span class="hl opt">} =~ </span><span class="hl kwd">/_quotation/</span><span class="hl opt">) {</span></li>
<li id="n_2212" class="hl">        <span class="hl kwb">$arap </span><span class="hl opt">= </span><span class="hl sng">&#39;oe&#39;</span><span class="hl opt">; </span></li>
<li id="n_2213" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span><span class="hl sng">&quot;quotation = &#39;1&#39;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2214" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2215" class="hl"></li>
<li id="n_2216" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2217" class="hl">        SELECT id </li>
<li id="n_2218" class="hl">        FROM <span class="hl kwb">$arap</span></li>
<li id="n_2219" class="hl">        WHERE id IN </li>
<li id="n_2220" class="hl">            <span class="hl opt">(</span>SELECT MAX<span class="hl opt">(</span>id<span class="hl opt">) </span></li>
<li id="n_2221" class="hl">            FROM <span class="hl kwb">$arap</span></li>
<li id="n_2222" class="hl">            WHERE <span class="hl kwb">$where </span>AND <span class="hl opt">${</span>vc<span class="hl opt">}</span>_id <span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">)|;</span></li>
<li id="n_2223" class="hl"></li>
<li id="n_2224" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$trans_id</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2225" class="hl"></li>
<li id="n_2226" class="hl">    <span class="hl kwb">$trans_id </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2227" class="hl"></li>
<li id="n_2228" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$DAYS </span><span class="hl opt">= (</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbdriver<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;DB2&#39;</span><span class="hl opt">) ? </span><span class="hl sng">&quot;DAYS&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2229" class="hl"></li>
<li id="n_2230" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2231" class="hl">        SELECT ct<span class="hl opt">.</span>name AS <span class="hl kwb">$vc</span><span class="hl opt">, </span>a<span class="hl opt">.</span>curr AS currency<span class="hl opt">, </span>a<span class="hl opt">.${</span>vc<span class="hl opt">}</span>_id<span class="hl opt">,</span></li>
<li id="n_2232" class="hl">            current_date <span class="hl opt">+ </span>ct<span class="hl opt">.</span>terms <span class="hl kwb">$DAYS </span>AS duedate<span class="hl opt">, </span></li>
<li id="n_2233" class="hl">            a<span class="hl opt">.</span>department_id<span class="hl opt">, </span>d<span class="hl opt">.</span>description AS department<span class="hl opt">, </span>ct<span class="hl opt">.</span>notes<span class="hl opt">, </span></li>
<li id="n_2234" class="hl">            ct<span class="hl opt">.</span>curr AS currency</li>
<li id="n_2235" class="hl">        FROM <span class="hl kwb">$arap </span>a</li>
<li id="n_2236" class="hl">        JOIN <span class="hl kwb">$vc </span>ct ON <span class="hl opt">(</span>a<span class="hl opt">.${</span>vc<span class="hl opt">}</span>_id <span class="hl opt">= </span>ct<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2237" class="hl">        LEFT JOIN department d ON <span class="hl opt">(</span>a<span class="hl opt">.</span>department_id <span class="hl opt">= </span>d<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2238" class="hl">        WHERE a<span class="hl opt">.</span>id <span class="hl opt">= ?|;</span></li>
<li id="n_2239" class="hl"></li>
<li id="n_2240" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2241" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$trans_id</span><span class="hl opt">)|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2242" class="hl"></li>
<li id="n_2243" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">);</span></li>
<li id="n_2244" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%$ref</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} }</span></li>
<li id="n_2245" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2246" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2247" class="hl"><span class="hl opt">}</span></li>
<li id="n_2248" class="hl"></li>
<li id="n_2249" class="hl"></li>
<li id="n_2250" class="hl"></li>
<li id="n_2251" class="hl"><span class="hl kwa">sub </span>current_date <span class="hl opt">{</span></li>
<li id="n_2252" class="hl"></li>
<li id="n_2253" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$thisdate</span><span class="hl opt">, </span><span class="hl kwb">$days</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2254" class="hl"></li>
<li id="n_2255" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2256" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query</span><span class="hl opt">;</span></li>
<li id="n_2257" class="hl"></li>
<li id="n_2258" class="hl">    <span class="hl kwb">$days </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2259" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$thisdate</span><span class="hl opt">) {</span></li>
<li id="n_2260" class="hl"></li>
<li id="n_2261" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$dateformat </span><span class="hl opt">= </span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">};</span></li>
<li id="n_2262" class="hl"></li>
<li id="n_2263" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">} !~ </span><span class="hl kwd">/^y/</span><span class="hl opt">) {</span></li>
<li id="n_2264" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">&#64;a </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$thisdate</span><span class="hl opt">;</span></li>
<li id="n_2265" class="hl">            <span class="hl kwb">$dateformat </span><span class="hl opt">.= </span><span class="hl sng">&quot;yy&quot;</span> <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">length </span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">] &gt; </span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2266" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2267" class="hl"></li>
<li id="n_2268" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$thisdate </span><span class="hl opt">!~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_2269" class="hl">            <span class="hl kwb">$dateformat </span><span class="hl opt">= </span><span class="hl sng">&#39;yyyymmdd&#39;</span><span class="hl opt">;</span></li>
<li id="n_2270" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2271" class="hl"></li>
<li id="n_2272" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT to_date<span class="hl opt">(?, ?) </span></li>
<li id="n_2273" class="hl">                <span class="hl opt">+ ?::</span>interval AS thisdate<span class="hl opt">|;</span></li>
<li id="n_2274" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$thisdate</span><span class="hl opt">, </span><span class="hl kwb">$dateformat</span><span class="hl opt">, </span><span class="hl kwb">$days</span><span class="hl opt">);</span></li>
<li id="n_2275" class="hl"></li>
<li id="n_2276" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2277" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT current_date AS thisdate<span class="hl opt">|;</span></li>
<li id="n_2278" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_2279" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2280" class="hl"></li>
<li id="n_2281" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2282" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">);</span></li>
<li id="n_2283" class="hl">    <span class="hl opt">(</span><span class="hl kwb">$thisdate</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_2284" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2285" class="hl">    <span class="hl kwb">$thisdate</span><span class="hl opt">;</span></li>
<li id="n_2286" class="hl"><span class="hl opt">}</span></li>
<li id="n_2287" class="hl"></li>
<li id="n_2288" class="hl"></li>
<li id="n_2289" class="hl"><span class="hl kwa">sub </span>like <span class="hl opt">{</span></li>
<li id="n_2290" class="hl"></li>
<li id="n_2291" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$str</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2292" class="hl"></li>
<li id="n_2293" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str </span><span class="hl opt">!~ </span><span class="hl kwd">/(%|_)/</span><span class="hl opt">) {</span></li>
<li id="n_2294" class="hl"></li>
<li id="n_2295" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">/(^&quot;).*(&quot;$)/</span><span class="hl opt">) {</span></li>
<li id="n_2296" class="hl">            <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/(^&quot;|&quot;$)//g</span><span class="hl opt">; </span></li>
<li id="n_2297" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{ </span></li>
<li id="n_2298" class="hl">            <span class="hl kwb">$str </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">%$str%</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2299" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2300" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2301" class="hl"></li>
<li id="n_2302" class="hl">    <span class="hl kwb">$str </span><span class="hl opt">=~ </span><span class="hl kwd">s/&#39;/&#39;&#39;/g</span><span class="hl opt">;</span></li>
<li id="n_2303" class="hl">    <span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_2304" class="hl"><span class="hl opt">}</span></li>
<li id="n_2305" class="hl"></li>
<li id="n_2306" class="hl"></li>
<li id="n_2307" class="hl"><span class="hl kwa">sub </span>redo_rows <span class="hl opt">{</span></li>
<li id="n_2308" class="hl"></li>
<li id="n_2309" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$flds</span><span class="hl opt">, </span><span class="hl kwb">$new</span><span class="hl opt">, </span><span class="hl kwb">$count</span><span class="hl opt">, </span><span class="hl kwb">$numrows</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2310" class="hl"></li>
<li id="n_2311" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;ndx </span><span class="hl opt">= ();</span></li>
<li id="n_2312" class="hl"></li>
<li id="n_2313" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl num">1 </span><span class="hl opt">.. </span><span class="hl kwb">$count</span><span class="hl opt">) { </span></li>
<li id="n_2314" class="hl">        <span class="hl kwc">push </span><span class="hl kwb">&#64;ndx</span><span class="hl opt">, { </span>num <span class="hl opt">=&gt; </span><span class="hl kwb">$new</span><span class="hl opt">-&gt;[</span><span class="hl kwb">$_</span><span class="hl opt">-</span><span class="hl num">1</span><span class="hl opt">]-&gt;{</span>runningnumber<span class="hl opt">}, </span>ndx <span class="hl opt">=&gt; </span><span class="hl kwb">$_ </span><span class="hl opt">} </span></li>
<li id="n_2315" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2316" class="hl"></li>
<li id="n_2317" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_2318" class="hl">    <span class="hl slc"># fill rows</span></li>
<li id="n_2319" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$item </span><span class="hl opt">(</span><span class="hl kwc">sort </span><span class="hl opt">{ </span><span class="hl kwb">$a</span><span class="hl opt">-&gt;{</span>num<span class="hl opt">} &lt;=&gt; </span><span class="hl kwb">$b</span><span class="hl opt">-&gt;{</span>num<span class="hl opt">} } </span><span class="hl kwb">&#64;ndx</span><span class="hl opt">) {</span></li>
<li id="n_2320" class="hl">        <span class="hl kwb">$i++</span><span class="hl opt">;</span></li>
<li id="n_2321" class="hl">        <span class="hl kwb">$j </span><span class="hl opt">= </span><span class="hl kwb">$item</span><span class="hl opt">-&gt;{</span>ndx<span class="hl opt">} - </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2322" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(&#64;{</span><span class="hl kwb">$flds</span><span class="hl opt">}) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${_}_</span><span class="hl ipl">$i</span><span class="hl sng">&quot;</span><span class="hl opt">} = </span><span class="hl kwb">$new</span><span class="hl opt">-&gt;[</span><span class="hl kwb">$j</span><span class="hl opt">]-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} }</span></li>
<li id="n_2323" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2324" class="hl"></li>
<li id="n_2325" class="hl">    <span class="hl slc"># delete empty rows</span></li>
<li id="n_2326" class="hl">    <span class="hl kwa">for </span><span class="hl kwb">$i </span><span class="hl opt">(</span><span class="hl kwb">$count </span><span class="hl opt">+ </span><span class="hl num">1 </span><span class="hl opt">.. </span><span class="hl kwb">$numrows</span><span class="hl opt">) {</span></li>
<li id="n_2327" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(&#64;{</span><span class="hl kwb">$flds</span><span class="hl opt">}) { </span><span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;${_}_</span><span class="hl ipl">$i</span><span class="hl sng">&quot;</span><span class="hl opt">} }</span></li>
<li id="n_2328" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2329" class="hl"><span class="hl opt">}</span></li>
<li id="n_2330" class="hl"></li>
<li id="n_2331" class="hl"></li>
<li id="n_2332" class="hl"><span class="hl kwa">sub </span>get_partsgroup <span class="hl opt">{</span></li>
<li id="n_2333" class="hl"></li>
<li id="n_2334" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$p</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2335" class="hl"></li>
<li id="n_2336" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2337" class="hl"></li>
<li id="n_2338" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT DISTINCT pg<span class="hl opt">.</span>id<span class="hl opt">, </span>pg<span class="hl opt">.</span>partsgroup</li>
<li id="n_2339" class="hl">                     FROM partsgroup pg</li>
<li id="n_2340" class="hl">                     JOIN parts p ON <span class="hl opt">(</span>p<span class="hl opt">.</span>partsgroup_id <span class="hl opt">= </span>pg<span class="hl opt">.</span>id<span class="hl opt">)|;</span></li>
<li id="n_2341" class="hl"></li>
<li id="n_2342" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$where</span><span class="hl opt">;</span></li>
<li id="n_2343" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sortorder </span><span class="hl opt">= </span><span class="hl sng">&quot;partsgroup&quot;</span><span class="hl opt">;</span></li>
<li id="n_2344" class="hl"></li>
<li id="n_2345" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>searchitems<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;part&#39;</span><span class="hl opt">) {</span></li>
<li id="n_2346" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>WHERE <span class="hl opt">(</span>p<span class="hl opt">.</span>inventory_accno_id <span class="hl opt">&gt; </span><span class="hl num">0</span></li>
<li id="n_2347" class="hl">                       AND p<span class="hl opt">.</span>income_accno_id <span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">)|;</span></li>
<li id="n_2348" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2349" class="hl"></li>
<li id="n_2350" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>searchitems<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;service&#39;</span><span class="hl opt">) {</span></li>
<li id="n_2351" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>WHERE p<span class="hl opt">.</span>inventory_accno_id IS NULL<span class="hl opt">|;</span></li>
<li id="n_2352" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2353" class="hl"></li>
<li id="n_2354" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>searchitems<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;assembly&#39;</span><span class="hl opt">) {</span></li>
<li id="n_2355" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>WHERE p<span class="hl opt">.</span>assembly <span class="hl opt">= </span><span class="hl sng">&#39;1&#39;</span><span class="hl opt">|;</span></li>
<li id="n_2356" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2357" class="hl"></li>
<li id="n_2358" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>searchitems<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;labor&#39;</span><span class="hl opt">) {</span></li>
<li id="n_2359" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>WHERE p<span class="hl opt">.</span>inventory_accno_id <span class="hl opt">&gt; </span><span class="hl num">0 </span>AND p<span class="hl opt">.</span>income_accno_id IS NULL<span class="hl opt">|;</span></li>
<li id="n_2360" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2361" class="hl"></li>
<li id="n_2362" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>searchitems<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;nolabor&#39;</span><span class="hl opt">) {</span></li>
<li id="n_2363" class="hl">        <span class="hl kwb">$where </span><span class="hl opt">= </span>qq<span class="hl opt">| </span>WHERE p<span class="hl opt">.</span>income_accno_id <span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">|;</span></li>
<li id="n_2364" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2365" class="hl"></li>
<li id="n_2366" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>all<span class="hl opt">}) {</span></li>
<li id="n_2367" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT id<span class="hl opt">, </span>partsgroup</li>
<li id="n_2368" class="hl">                      FROM partsgroup<span class="hl opt">|;</span></li>
<li id="n_2369" class="hl">    <span class="hl opt">} </span></li>
<li id="n_2370" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs </span><span class="hl opt">= ();</span></li>
<li id="n_2371" class="hl"></li>
<li id="n_2372" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>language_code<span class="hl opt">}) {</span></li>
<li id="n_2373" class="hl">        <span class="hl kwb">$sortorder </span><span class="hl opt">= </span><span class="hl sng">&quot;translation&quot;</span><span class="hl opt">;</span></li>
<li id="n_2374" class="hl"></li>
<li id="n_2375" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2376" class="hl">            SELECT DISTINCT pg<span class="hl opt">.</span>id<span class="hl opt">, </span>pg<span class="hl opt">.</span>partsgroup<span class="hl opt">,</span></li>
<li id="n_2377" class="hl">                t<span class="hl opt">.</span>description AS translation</li>
<li id="n_2378" class="hl">            FROM partsgroup pg</li>
<li id="n_2379" class="hl">            JOIN parts p ON <span class="hl opt">(</span>p<span class="hl opt">.</span>partsgroup_id <span class="hl opt">= </span>pg<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2380" class="hl">            LEFT JOIN translation t ON <span class="hl opt">(</span>t<span class="hl opt">.</span>trans_id <span class="hl opt">= </span>pg<span class="hl opt">.</span>id </li>
<li id="n_2381" class="hl">                AND t<span class="hl opt">.</span>language_code <span class="hl opt">= ?)|;</span></li>
<li id="n_2382" class="hl">        <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span><span class="hl kwb">$p</span><span class="hl opt">-&gt;{</span>language_code<span class="hl opt">});</span></li>
<li id="n_2383" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2384" class="hl"></li>
<li id="n_2385" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">.= </span>qq<span class="hl opt">| </span><span class="hl kwb">$where </span>ORDER BY <span class="hl kwb">$sortorder</span><span class="hl opt">|;</span></li>
<li id="n_2386" class="hl"></li>
<li id="n_2387" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2388" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">)|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2389" class="hl"></li>
<li id="n_2390" class="hl">    <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_partsgroup<span class="hl opt">} = ();</span></li>
<li id="n_2391" class="hl"></li>
<li id="n_2392" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_2393" class="hl">        <span class="hl kwc">push </span><span class="hl opt">&#64;{ </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>all_partsgroup<span class="hl opt">} }, </span><span class="hl kwb">$ref</span><span class="hl opt">;</span></li>
<li id="n_2394" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2395" class="hl"></li>
<li id="n_2396" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2397" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2398" class="hl"><span class="hl opt">}</span></li>
<li id="n_2399" class="hl"></li>
<li id="n_2400" class="hl"></li>
<li id="n_2401" class="hl"><span class="hl kwa">sub </span>update_status <span class="hl opt">{</span></li>
<li id="n_2402" class="hl"></li>
<li id="n_2403" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2404" class="hl"></li>
<li id="n_2405" class="hl">    <span class="hl slc"># no id return</span></li>
<li id="n_2406" class="hl">    <span class="hl kwa">return unless </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">};</span></li>
<li id="n_2407" class="hl"></li>
<li id="n_2408" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2409" class="hl"></li>
<li id="n_2410" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%queued </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/ +/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>queued<span class="hl opt">};</span></li>
<li id="n_2411" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$spoolfile </span><span class="hl opt">= (</span><span class="hl kwb">$queued</span><span class="hl opt">{</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>formname<span class="hl opt">}}) ? </span><span class="hl sng">&quot;&#39;</span><span class="hl ipl">$queued</span><span class="hl sng">{</span><span class="hl ipl">$self</span><span class="hl sng">-&gt;{formname}}&#39;&quot;</span> <span class="hl opt">: </span><span class="hl sng">&#39;NULL&#39;</span><span class="hl opt">;</span></li>
<li id="n_2412" class="hl"></li>
<li id="n_2413" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>DELETE FROM status</li>
<li id="n_2414" class="hl">                    WHERE formname <span class="hl opt">= ?</span></li>
<li id="n_2415" class="hl">                      AND trans_id <span class="hl opt">= ?|;</span></li>
<li id="n_2416" class="hl"></li>
<li id="n_2417" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">=</span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2418" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>formname<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2419" class="hl"></li>
<li id="n_2420" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2421" class="hl"></li>
<li id="n_2422" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$printed </span><span class="hl opt">= (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>printed<span class="hl opt">} =~ </span><span class="hl kwd">/$self-&gt;{formname}/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2423" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$emailed </span><span class="hl opt">= (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>emailed<span class="hl opt">} =~ </span><span class="hl kwd">/$self-&gt;{formname}/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2424" class="hl"></li>
<li id="n_2425" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2426" class="hl">        INSERT INTO status </li>
<li id="n_2427" class="hl">            <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>printed<span class="hl opt">, </span>emailed<span class="hl opt">, </span>spoolfile<span class="hl opt">, </span>formname<span class="hl opt">) </span></li>
<li id="n_2428" class="hl">        VALUES <span class="hl opt">(?, ?, ?, ?, ?)|;</span></li>
<li id="n_2429" class="hl"></li>
<li id="n_2430" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2431" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$printed</span><span class="hl opt">, </span><span class="hl kwb">$emailed</span><span class="hl opt">, </span><span class="hl kwb">$spoolfile</span><span class="hl opt">, </span></li>
<li id="n_2432" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>formname<span class="hl opt">});</span></li>
<li id="n_2433" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2434" class="hl"></li>
<li id="n_2435" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2436" class="hl"><span class="hl opt">}</span></li>
<li id="n_2437" class="hl"></li>
<li id="n_2438" class="hl"></li>
<li id="n_2439" class="hl"><span class="hl kwa">sub </span>save_status <span class="hl opt">{</span></li>
<li id="n_2440" class="hl"></li>
<li id="n_2441" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2442" class="hl"></li>
<li id="n_2443" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2444" class="hl"></li>
<li id="n_2445" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$formnames </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>printed<span class="hl opt">};</span></li>
<li id="n_2446" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$emailforms </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>emailed<span class="hl opt">};</span></li>
<li id="n_2447" class="hl"></li>
<li id="n_2448" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>DELETE FROM status</li>
<li id="n_2449" class="hl">                    WHERE trans_id <span class="hl opt">= ?|;</span></li>
<li id="n_2450" class="hl"></li>
<li id="n_2451" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2452" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">});</span></li>
<li id="n_2453" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2454" class="hl"></li>
<li id="n_2455" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%queued</span><span class="hl opt">;</span></li>
<li id="n_2456" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$formname</span><span class="hl opt">;</span></li>
<li id="n_2457" class="hl"></li>
<li id="n_2458" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>queued<span class="hl opt">}) {</span></li>
<li id="n_2459" class="hl"></li>
<li id="n_2460" class="hl">        <span class="hl kwb">%queued </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/ +/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>queued<span class="hl opt">};</span></li>
<li id="n_2461" class="hl"></li>
<li id="n_2462" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwb">$formname </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%queued</span><span class="hl opt">) {</span></li>
<li id="n_2463" class="hl"></li>
<li id="n_2464" class="hl">            <span class="hl kwb">$printed </span><span class="hl opt">= (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>printed<span class="hl opt">} =~ </span><span class="hl kwd">/$formname/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2465" class="hl">            <span class="hl kwb">$emailed </span><span class="hl opt">= (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>emailed<span class="hl opt">} =~ </span><span class="hl kwd">/$formname/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2466" class="hl"></li>
<li id="n_2467" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$queued</span><span class="hl opt">{</span><span class="hl kwb">$formname</span><span class="hl opt">}) {</span></li>
<li id="n_2468" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2469" class="hl">                    INSERT INTO status </li>
<li id="n_2470" class="hl">                        <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>printed<span class="hl opt">, </span>emailed<span class="hl opt">,</span></li>
<li id="n_2471" class="hl">                        spoolfile<span class="hl opt">, </span>formname<span class="hl opt">)</span></li>
<li id="n_2472" class="hl">                    VALUES <span class="hl opt">(?, ?, ?, ?, ?)|;</span></li>
<li id="n_2473" class="hl"></li>
<li id="n_2474" class="hl">                <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2475" class="hl">                <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$pinted</span><span class="hl opt">, </span><span class="hl kwb">$emailed</span><span class="hl opt">,</span></li>
<li id="n_2476" class="hl">                    <span class="hl kwb">$queued</span><span class="hl opt">{</span><span class="hl kwb">$formname</span><span class="hl opt">}, </span><span class="hl kwb">$formname</span><span class="hl opt">)</span></li>
<li id="n_2477" class="hl">                    <span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2478" class="hl">                <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2479" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2480" class="hl"></li>
<li id="n_2481" class="hl">            <span class="hl kwb">$formnames </span><span class="hl opt">=~ </span><span class="hl kwd">s/$formname//</span><span class="hl opt">;</span></li>
<li id="n_2482" class="hl">            <span class="hl kwb">$emailforms </span><span class="hl opt">=~ </span><span class="hl kwd">s/$formname//</span><span class="hl opt">;</span></li>
<li id="n_2483" class="hl"></li>
<li id="n_2484" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2485" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2486" class="hl"></li>
<li id="n_2487" class="hl">    <span class="hl slc"># save printed, emailed info</span></li>
<li id="n_2488" class="hl">    <span class="hl kwb">$formnames </span><span class="hl opt">=~ </span><span class="hl kwd">s/^ +//g</span><span class="hl opt">;</span></li>
<li id="n_2489" class="hl">    <span class="hl kwb">$emailforms </span><span class="hl opt">=~ </span><span class="hl kwd">s/^ +//g</span><span class="hl opt">;</span></li>
<li id="n_2490" class="hl"></li>
<li id="n_2491" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%status </span><span class="hl opt">= ();</span></li>
<li id="n_2492" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/ +/</span><span class="hl opt">, </span><span class="hl kwb">$formnames</span><span class="hl opt">) { </span><span class="hl kwb">$status</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">}{</span>printed<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl opt">}</span></li>
<li id="n_2493" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">split </span><span class="hl kwd">/ +/</span><span class="hl opt">, </span><span class="hl kwb">$emailforms</span><span class="hl opt">) { </span><span class="hl kwb">$status</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">}{</span>emailed<span class="hl opt">} = </span><span class="hl num">1 </span><span class="hl opt">}</span></li>
<li id="n_2494" class="hl"></li>
<li id="n_2495" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$formname </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%status</span><span class="hl opt">) {</span></li>
<li id="n_2496" class="hl">        <span class="hl kwb">$printed </span><span class="hl opt">= (</span><span class="hl kwb">$formnames </span><span class="hl opt">=~ </span><span class="hl kwd">/$self-&gt;{formname}/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2497" class="hl">        <span class="hl kwb">$emailed </span><span class="hl opt">= (</span><span class="hl kwb">$emailforms </span><span class="hl opt">=~ </span><span class="hl kwd">/$self-&gt;{formname}/</span><span class="hl opt">) ? </span><span class="hl sng">&quot;1&quot;</span> <span class="hl opt">: </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">;</span></li>
<li id="n_2498" class="hl"></li>
<li id="n_2499" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2500" class="hl">            INSERT INTO status <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>printed<span class="hl opt">, </span>emailed<span class="hl opt">, </span></li>
<li id="n_2501" class="hl">                formname<span class="hl opt">)</span></li>
<li id="n_2502" class="hl">            VALUES <span class="hl opt">(?, ?, ?, ?)|;</span></li>
<li id="n_2503" class="hl"></li>
<li id="n_2504" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2505" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$printed</span><span class="hl opt">, </span><span class="hl kwb">$emailed</span><span class="hl opt">, </span><span class="hl kwb">$formname</span><span class="hl opt">);</span></li>
<li id="n_2506" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2507" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2508" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2509" class="hl"><span class="hl opt">}</span></li>
<li id="n_2510" class="hl"></li>
<li id="n_2511" class="hl"></li>
<li id="n_2512" class="hl"><span class="hl kwa">sub </span>get_recurring <span class="hl opt">{</span></li>
<li id="n_2513" class="hl"></li>
<li id="n_2514" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2515" class="hl"></li>
<li id="n_2516" class="hl">    <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2517" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">/</span></li>
<li id="n_2518" class="hl">        SELECT s<span class="hl opt">.*, </span>se<span class="hl opt">.</span>formname <span class="hl opt">|| </span><span class="hl sng">&#39;:&#39;</span> <span class="hl opt">|| </span>se<span class="hl opt">.</span>format AS emaila<span class="hl opt">,</span></li>
<li id="n_2519" class="hl">            se<span class="hl opt">.</span>message<span class="hl opt">, </span>sp<span class="hl opt">.</span>formname <span class="hl opt">|| </span><span class="hl sng">&#39;:&#39;</span> <span class="hl opt">|| </span></li>
<li id="n_2520" class="hl">                sp<span class="hl opt">.</span>format <span class="hl opt">|| </span><span class="hl sng">&#39;:&#39;</span> <span class="hl opt">|| </span>sp<span class="hl opt">.</span>printer AS printa</li>
<li id="n_2521" class="hl">        FROM recurring s</li>
<li id="n_2522" class="hl">        LEFT JOIN recurringemail se ON <span class="hl opt">(</span>s<span class="hl opt">.</span>id <span class="hl opt">= </span>se<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2523" class="hl">        LEFT JOIN recurringprint sp ON <span class="hl opt">(</span>s<span class="hl opt">.</span>id <span class="hl opt">= </span>sp<span class="hl opt">.</span>id<span class="hl opt">)</span></li>
<li id="n_2524" class="hl">        WHERE s<span class="hl opt">.</span>id <span class="hl opt">= ?/;</span></li>
<li id="n_2525" class="hl"></li>
<li id="n_2526" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2527" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2528" class="hl"></li>
<li id="n_2529" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(email print)</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;recurring</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">} = </span><span class="hl sng">&quot;&quot;</span> <span class="hl opt">}</span></li>
<li id="n_2530" class="hl"></li>
<li id="n_2531" class="hl">    <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$ref </span><span class="hl opt">= </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_hashref</span><span class="hl opt">(</span>NAME_lc<span class="hl opt">)) {</span></li>
<li id="n_2532" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">keys </span><span class="hl kwb">%$ref</span><span class="hl opt">) { </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;recurring</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">} = </span><span class="hl kwb">$ref</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} }</span></li>
<li id="n_2533" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringemail<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{emaila}:&quot;</span><span class="hl opt">;</span></li>
<li id="n_2534" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringprint<span class="hl opt">} .= </span><span class="hl sng">&quot;</span><span class="hl ipl">$ref</span><span class="hl sng">-&gt;{printa}:&quot;</span><span class="hl opt">;</span></li>
<li id="n_2535" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(emaila printa)</span><span class="hl opt">) { </span><span class="hl kwc">delete </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;recurring</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">} }</span></li>
<li id="n_2536" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2537" class="hl"></li>
<li id="n_2538" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2539" class="hl">    <span class="hl kwc">chop </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringemail<span class="hl opt">};</span></li>
<li id="n_2540" class="hl">    <span class="hl kwc">chop </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringprint<span class="hl opt">};</span></li>
<li id="n_2541" class="hl"></li>
<li id="n_2542" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringstartdate<span class="hl opt">}) {</span></li>
<li id="n_2543" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringreference<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">escape</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringreference<span class="hl opt">},</span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_2544" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringmessage<span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">escape</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringmessage<span class="hl opt">},</span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_2545" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(reference startdate repeat unit howmany </span></li>
<li id="n_2546" class="hl"><span class="hl sng">                payment print email message)</span><span class="hl opt">) { </span></li>
<li id="n_2547" class="hl"></li>
<li id="n_2548" class="hl">            <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurring<span class="hl opt">} .= </span>qq<span class="hl opt">|</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl sng">&quot;recurring</span><span class="hl ipl">$_</span><span class="hl sng">&quot;</span><span class="hl opt">},| </span></li>
<li id="n_2549" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2550" class="hl"></li>
<li id="n_2551" class="hl">        <span class="hl kwc">chop </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurring<span class="hl opt">};</span></li>
<li id="n_2552" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2553" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2554" class="hl"><span class="hl opt">}</span></li>
<li id="n_2555" class="hl"></li>
<li id="n_2556" class="hl"></li>
<li id="n_2557" class="hl"><span class="hl kwa">sub </span>save_recurring <span class="hl opt">{</span></li>
<li id="n_2558" class="hl"></li>
<li id="n_2559" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh2</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2560" class="hl"></li>
<li id="n_2561" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2562" class="hl"></li>
<li id="n_2563" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query</span><span class="hl opt">;</span></li>
<li id="n_2564" class="hl"></li>
<li id="n_2565" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>DELETE FROM recurring</li>
<li id="n_2566" class="hl">                 WHERE id <span class="hl opt">= ?|;</span></li>
<li id="n_2567" class="hl"></li>
<li id="n_2568" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">); </span></li>
<li id="n_2569" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2570" class="hl"></li>
<li id="n_2571" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>DELETE FROM recurringemail</li>
<li id="n_2572" class="hl">                 WHERE id <span class="hl opt">= ?|;</span></li>
<li id="n_2573" class="hl"></li>
<li id="n_2574" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">); </span></li>
<li id="n_2575" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2576" class="hl"></li>
<li id="n_2577" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>DELETE FROM recurringprint</li>
<li id="n_2578" class="hl">                 WHERE id <span class="hl opt">= ?|;</span></li>
<li id="n_2579" class="hl"></li>
<li id="n_2580" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">); </span></li>
<li id="n_2581" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2582" class="hl"></li>
<li id="n_2583" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurring<span class="hl opt">}) {</span></li>
<li id="n_2584" class="hl"></li>
<li id="n_2585" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">%s </span><span class="hl opt">= ();</span></li>
<li id="n_2586" class="hl">        <span class="hl opt">(</span><span class="hl kwb">$s</span><span class="hl opt">{</span>reference<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>startdate<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>repeat<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>unit<span class="hl opt">}, </span></li>
<li id="n_2587" class="hl">            <span class="hl kwb">$s</span><span class="hl opt">{</span>howmany<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>payment<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwc">print</span><span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>email<span class="hl opt">}, </span></li>
<li id="n_2588" class="hl">            <span class="hl kwb">$s</span><span class="hl opt">{</span>message<span class="hl opt">}) </span></li>
<li id="n_2589" class="hl">                <span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/,/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurring<span class="hl opt">};</span></li>
<li id="n_2590" class="hl"></li>
<li id="n_2591" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(reference message)</span><span class="hl opt">) { </span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">} = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">unescape</span><span class="hl opt">(</span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">}) }</span></li>
<li id="n_2592" class="hl">        <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl sng">qw(repeat howmany payment)</span><span class="hl opt">) { </span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">} *= </span><span class="hl num">1 </span><span class="hl opt">}</span></li>
<li id="n_2593" class="hl"></li>
<li id="n_2594" class="hl">        <span class="hl slc"># calculate enddate</span></li>
<li id="n_2595" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$advance </span><span class="hl opt">= </span><span class="hl kwb">$s</span><span class="hl opt">{</span>repeat<span class="hl opt">} * (</span><span class="hl kwb">$s</span><span class="hl opt">{</span>howmany<span class="hl opt">} - </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_2596" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">%interval</span><span class="hl opt">;</span></li>
<li id="n_2597" class="hl">        <span class="hl kwb">$interval</span><span class="hl opt">{</span><span class="hl sng">&#39;Pg&#39;</span><span class="hl opt">} = </span></li>
<li id="n_2598" class="hl">            <span class="hl sng">&quot;(date &#39;</span><span class="hl ipl">$s</span><span class="hl sng">{startdate}&#39; + interval &#39;</span><span class="hl ipl">$advance </span><span class="hl sng"></span><span class="hl ipl">$s</span><span class="hl sng">{unit}&#39;)&quot;</span><span class="hl opt">;</span></li>
<li id="n_2599" class="hl"></li>
<li id="n_2600" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT <span class="hl kwb">$interval</span><span class="hl opt">{</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbdriver<span class="hl opt">}}|;</span></li>
<li id="n_2601" class="hl"></li>
<li id="n_2602" class="hl">        <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$enddate</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2603" class="hl"></li>
<li id="n_2604" class="hl">        <span class="hl slc"># calculate nextdate</span></li>
<li id="n_2605" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2606" class="hl">            SELECT current_date <span class="hl opt">- </span>date <span class="hl opt">? </span>AS a<span class="hl opt">,</span></li>
<li id="n_2607" class="hl">                date <span class="hl opt">? - </span>current_date AS b<span class="hl opt">|;</span></li>
<li id="n_2608" class="hl"></li>
<li id="n_2609" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2610" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$s</span><span class="hl opt">{</span>startdate<span class="hl opt">}, </span><span class="hl kwb">$enddate</span><span class="hl opt">);</span></li>
<li id="n_2611" class="hl">        <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$a</span><span class="hl opt">, </span><span class="hl kwb">$b</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">;</span></li>
<li id="n_2612" class="hl"></li>
<li id="n_2613" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$a </span><span class="hl opt">+ </span><span class="hl kwb">$b</span><span class="hl opt">) {</span></li>
<li id="n_2614" class="hl">            <span class="hl kwb">$advance </span><span class="hl opt">= </span><span class="hl kwc">int</span><span class="hl opt">((</span><span class="hl kwb">$a </span><span class="hl opt">/ (</span><span class="hl kwb">$a </span><span class="hl opt">+ </span><span class="hl kwb">$b</span><span class="hl opt">)) * (</span><span class="hl kwb">$s</span><span class="hl opt">{</span>howmany<span class="hl opt">} - </span><span class="hl num">1</span><span class="hl opt">) + </span><span class="hl num">1</span><span class="hl opt">) * </span><span class="hl kwb">$s</span><span class="hl opt">{</span>repeat<span class="hl opt">};</span></li>
<li id="n_2615" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2616" class="hl">            <span class="hl kwb">$advance </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_2617" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2618" class="hl"></li>
<li id="n_2619" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$nextdate </span><span class="hl opt">= </span><span class="hl kwb">$enddate</span><span class="hl opt">;</span></li>
<li id="n_2620" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$advance </span><span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">) {</span></li>
<li id="n_2621" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$advance </span><span class="hl opt">&lt; (</span><span class="hl kwb">$s</span><span class="hl opt">{</span>repeat<span class="hl opt">} * </span><span class="hl kwb">$s</span><span class="hl opt">{</span>howmany<span class="hl opt">})) {</span></li>
<li id="n_2622" class="hl">                <span class="hl kwb">%interval </span><span class="hl opt">= ( </span><span class="hl sng">&#39;Pg&#39;</span>  <span class="hl opt">=&gt; </span><span class="hl sng">&quot;(date &#39;</span><span class="hl ipl">$s</span><span class="hl sng">{startdate}&#39; + interval &#39;</span><span class="hl ipl">$advance </span><span class="hl sng"></span><span class="hl ipl">$s</span><span class="hl sng">{unit}&#39;)&quot;</span><span class="hl opt">,</span></li>
<li id="n_2623" class="hl">                              <span class="hl sng">&#39;DB2&#39;</span> <span class="hl opt">=&gt; </span>qq<span class="hl opt">|(</span>date <span class="hl opt">(</span><span class="hl sng">&#39;</span><span class="hl ipl">$s</span><span class="hl sng">{startdate}&#39;</span><span class="hl opt">) + </span><span class="hl sng">&quot;</span><span class="hl ipl">$advance </span><span class="hl sng"></span><span class="hl ipl">$s</span><span class="hl sng">{unit}&quot;</span><span class="hl opt">)|,);</span></li>
<li id="n_2624" class="hl"></li>
<li id="n_2625" class="hl">                <span class="hl kwb">$interval</span><span class="hl opt">{</span>Oracle<span class="hl opt">} = </span><span class="hl kwb">$interval</span><span class="hl opt">{</span>PgPP<span class="hl opt">} = </span><span class="hl kwb">$interval</span><span class="hl opt">{</span>Pg<span class="hl opt">};</span></li>
<li id="n_2626" class="hl"></li>
<li id="n_2627" class="hl"></li>
<li id="n_2628" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT <span class="hl kwb">$interval</span><span class="hl opt">{</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dbdriver<span class="hl opt">}}|;</span></li>
<li id="n_2629" class="hl"></li>
<li id="n_2630" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$nextdate</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2631" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2632" class="hl"></li>
<li id="n_2633" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2634" class="hl">            <span class="hl kwb">$nextdate </span><span class="hl opt">= </span><span class="hl kwb">$s</span><span class="hl opt">{</span>startdate<span class="hl opt">};</span></li>
<li id="n_2635" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2636" class="hl"></li>
<li id="n_2637" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringnextdate<span class="hl opt">}) {</span></li>
<li id="n_2638" class="hl"></li>
<li id="n_2639" class="hl">            <span class="hl kwb">$nextdate </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringnextdate<span class="hl opt">};</span></li>
<li id="n_2640" class="hl"></li>
<li id="n_2641" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT <span class="hl sng">&#39;</span><span class="hl ipl">$enddate</span><span class="hl sng">&#39;</span> <span class="hl opt">- </span>date <span class="hl sng">&#39;</span><span class="hl ipl">$nextdate</span><span class="hl sng">&#39;</span><span class="hl opt">|;</span></li>
<li id="n_2642" class="hl"></li>
<li id="n_2643" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) &lt; </span><span class="hl num">0</span><span class="hl opt">) {</span></li>
<li id="n_2644" class="hl">                <span class="hl kwc">undef </span><span class="hl kwb">$nextdate</span><span class="hl opt">;</span></li>
<li id="n_2645" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2646" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2647" class="hl"></li>
<li id="n_2648" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>recurringpayment<span class="hl opt">} *= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2649" class="hl"></li>
<li id="n_2650" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2651" class="hl">            INSERT INTO recurring </li>
<li id="n_2652" class="hl">                <span class="hl opt">(</span>id<span class="hl opt">, </span>reference<span class="hl opt">, </span>startdate<span class="hl opt">, </span>enddate<span class="hl opt">, </span>nextdate<span class="hl opt">, </span></li>
<li id="n_2653" class="hl">                repeat<span class="hl opt">, </span>unit<span class="hl opt">, </span>howmany<span class="hl opt">, </span>payment<span class="hl opt">)</span></li>
<li id="n_2654" class="hl">            VALUES <span class="hl opt">(?, ?, ?, ?, ?, ?, ?, ?, ?)|;</span></li>
<li id="n_2655" class="hl"></li>
<li id="n_2656" class="hl">        <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2657" class="hl">        <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>reference<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>startdate<span class="hl opt">},</span></li>
<li id="n_2658" class="hl">            <span class="hl kwb">$enddate</span><span class="hl opt">, </span><span class="hl kwb">$nextdate</span><span class="hl opt">, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>repeat<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>unit<span class="hl opt">}, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>howmany<span class="hl opt">},</span></li>
<li id="n_2659" class="hl">            <span class="hl kwb">$s</span><span class="hl opt">{</span>payment<span class="hl opt">});</span></li>
<li id="n_2660" class="hl"></li>
<li id="n_2661" class="hl"></li>
<li id="n_2662" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">&#64;p</span><span class="hl opt">;</span></li>
<li id="n_2663" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$p</span><span class="hl opt">;</span></li>
<li id="n_2664" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$i</span><span class="hl opt">;</span></li>
<li id="n_2665" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$sth</span><span class="hl opt">;</span></li>
<li id="n_2666" class="hl"></li>
<li id="n_2667" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$s</span><span class="hl opt">{</span>email<span class="hl opt">}) {</span></li>
<li id="n_2668" class="hl">            <span class="hl slc"># formname:format</span></li>
<li id="n_2669" class="hl">            <span class="hl kwb">&#64;p </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/:/</span><span class="hl opt">, </span><span class="hl kwb">$s</span><span class="hl opt">{</span>email<span class="hl opt">};</span></li>
<li id="n_2670" class="hl"></li>
<li id="n_2671" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>INSERT INTO recurringemail <span class="hl opt">(</span>id<span class="hl opt">, </span>formname<span class="hl opt">, </span>format<span class="hl opt">, </span>message<span class="hl opt">)</span></li>
<li id="n_2672" class="hl">                        VALUES <span class="hl opt">(?, ?, ?, ?)|;</span></li>
<li id="n_2673" class="hl"></li>
<li id="n_2674" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2675" class="hl"></li>
<li id="n_2676" class="hl">            <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">; </span><span class="hl kwb">$i </span><span class="hl opt">&lt;= </span><span class="hl kwb">$#p</span><span class="hl opt">; </span><span class="hl kwb">$i </span><span class="hl opt">+= </span><span class="hl num">2</span><span class="hl opt">) {</span></li>
<li id="n_2677" class="hl">                <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i</span><span class="hl opt">], </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i+1</span><span class="hl opt">], </span></li>
<li id="n_2678" class="hl">                    <span class="hl kwb">$s</span><span class="hl opt">{</span>message<span class="hl opt">});</span></li>
<li id="n_2679" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2680" class="hl"></li>
<li id="n_2681" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2682" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2683" class="hl"></li>
<li id="n_2684" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwc">print</span><span class="hl opt">}) {</span></li>
<li id="n_2685" class="hl">            <span class="hl slc"># formname:format:printer</span></li>
<li id="n_2686" class="hl">            <span class="hl kwb">&#64;p </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/:/</span><span class="hl opt">, </span><span class="hl kwb">$s</span><span class="hl opt">{</span><span class="hl kwc">print</span><span class="hl opt">};</span></li>
<li id="n_2687" class="hl"></li>
<li id="n_2688" class="hl">            <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>INSERT INTO recurringprint <span class="hl opt">(</span>id<span class="hl opt">, </span>formname<span class="hl opt">, </span>format<span class="hl opt">, </span>printer<span class="hl opt">)</span></li>
<li id="n_2689" class="hl">                        VALUES <span class="hl opt">(?, ?, ?, ?)|;</span></li>
<li id="n_2690" class="hl"></li>
<li id="n_2691" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2692" class="hl"></li>
<li id="n_2693" class="hl">            <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">; </span><span class="hl kwb">$i </span><span class="hl opt">&lt;= </span><span class="hl kwb">$#p</span><span class="hl opt">; </span><span class="hl kwb">$i </span><span class="hl opt">+= </span><span class="hl num">3</span><span class="hl opt">) {</span></li>
<li id="n_2694" class="hl">                <span class="hl kwb">$p </span><span class="hl opt">= (</span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i+2</span><span class="hl opt">]) ? </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i+2</span><span class="hl opt">] : </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2695" class="hl">                <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i</span><span class="hl opt">], </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i+1</span><span class="hl opt">], </span><span class="hl kwb">$p</span><span class="hl opt">);</span></li>
<li id="n_2696" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2697" class="hl"></li>
<li id="n_2698" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_2699" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2700" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2701" class="hl"></li>
<li id="n_2702" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2703" class="hl"><span class="hl opt">}</span></li>
<li id="n_2704" class="hl"></li>
<li id="n_2705" class="hl"></li>
<li id="n_2706" class="hl"><span class="hl kwa">sub </span>save_intnotes <span class="hl opt">{</span></li>
<li id="n_2707" class="hl"></li>
<li id="n_2708" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$vc</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2709" class="hl"></li>
<li id="n_2710" class="hl">    <span class="hl slc"># no id return</span></li>
<li id="n_2711" class="hl">    <span class="hl kwa">return unless </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">};</span></li>
<li id="n_2712" class="hl"></li>
<li id="n_2713" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dbconnect</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">);</span></li>
<li id="n_2714" class="hl"></li>
<li id="n_2715" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>UPDATE <span class="hl kwb">$vc </span>SET intnotes <span class="hl opt">= ? </span>WHERE id <span class="hl opt">= ?|;</span></li>
<li id="n_2716" class="hl"></li>
<li id="n_2717" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">=</span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2718" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>intnotes<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2719" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2720" class="hl"><span class="hl opt">}</span></li>
<li id="n_2721" class="hl"></li>
<li id="n_2722" class="hl"></li>
<li id="n_2723" class="hl"><span class="hl kwa">sub </span>update_defaults <span class="hl opt">{</span></li>
<li id="n_2724" class="hl"></li>
<li id="n_2725" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$fld</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2726" class="hl"></li>
<li id="n_2727" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(!</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">} &amp;&amp; </span><span class="hl kwb">$self</span><span class="hl opt">){</span></li>
<li id="n_2728" class="hl">        <span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">db_init</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">);</span></li>
<li id="n_2729" class="hl">    <span class="hl opt">} </span></li>
<li id="n_2730" class="hl">        </li>
<li id="n_2731" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_2732" class="hl"></li>
<li id="n_2733" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(!</span><span class="hl kwb">$self</span><span class="hl opt">){</span></li>
<li id="n_2734" class="hl">        <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">[</span><span class="hl num">3</span><span class="hl opt">];</span></li>
<li id="n_2735" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2736" class="hl"></li>
<li id="n_2737" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2738" class="hl">        SELECT value FROM defaults </li>
<li id="n_2739" class="hl">         WHERE setting_key <span class="hl opt">= ? </span>FOR UPDATE<span class="hl opt">|;</span></li>
<li id="n_2740" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2741" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$fld</span><span class="hl opt">);</span></li>
<li id="n_2742" class="hl">    <span class="hl opt">(</span><span class="hl kwb">$_</span><span class="hl opt">) = </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">fetchrow_array</span><span class="hl opt">();</span></li>
<li id="n_2743" class="hl"></li>
<li id="n_2744" class="hl">    <span class="hl kwb">$_ </span><span class="hl opt">= </span><span class="hl sng">&quot;0&quot;</span> <span class="hl kwa">unless </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_2745" class="hl"></li>
<li id="n_2746" class="hl">    <span class="hl slc"># check for and replace</span></li>
<li id="n_2747" class="hl">    <span class="hl slc"># &lt;?lsmb DATE ?&gt;, &lt;?lsmb YYMMDD ?&gt;, &lt;?lsmb YEAR ?&gt;, &lt;?lsmb MONTH ?&gt;, &lt;?lsmb DAY ?&gt; or variations of</span></li>
<li id="n_2748" class="hl">    <span class="hl slc"># &lt;?lsmb NAME 1 1 3 ?&gt;, &lt;?lsmb BUSINESS ?&gt;, &lt;?lsmb BUSINESS 10 ?&gt;, &lt;?lsmb CURR... ?&gt;</span></li>
<li id="n_2749" class="hl">    <span class="hl slc"># &lt;?lsmb DESCRIPTION 1 1 3 ?&gt;, &lt;?lsmb ITEM 1 1 3 ?&gt;, &lt;?lsmb PARTSGROUP 1 1 3 ?&gt; only for parts</span></li>
<li id="n_2750" class="hl">    <span class="hl slc"># &lt;?lsmb PHONE ?&gt; for customer and vendors</span></li>
<li id="n_2751" class="hl"></li>
<li id="n_2752" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$num </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_2753" class="hl">    <span class="hl opt">(</span><span class="hl kwb">$num</span><span class="hl opt">) = </span><span class="hl kwb">$num </span><span class="hl opt">=~ </span><span class="hl kwd">/(\d+)/</span><span class="hl opt">;</span></li>
<li id="n_2754" class="hl"></li>
<li id="n_2755" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$num</span><span class="hl opt">) {</span></li>
<li id="n_2756" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$incnum</span><span class="hl opt">;</span></li>
<li id="n_2757" class="hl">        <span class="hl slc"># if we have leading zeros check how long it is</span></li>
<li id="n_2758" class="hl"></li>
<li id="n_2759" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$num </span><span class="hl opt">=~ </span><span class="hl kwd">/^0/</span><span class="hl opt">) {</span></li>
<li id="n_2760" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$l </span><span class="hl opt">= </span><span class="hl kwc">length </span><span class="hl kwb">$num</span><span class="hl opt">;</span></li>
<li id="n_2761" class="hl">            <span class="hl kwb">$incnum </span><span class="hl opt">= </span><span class="hl kwb">$num </span><span class="hl opt">+ </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2762" class="hl">            <span class="hl kwb">$l </span><span class="hl opt">-= </span><span class="hl kwc">length </span><span class="hl kwb">$incnum</span><span class="hl opt">;</span></li>
<li id="n_2763" class="hl"></li>
<li id="n_2764" class="hl">            <span class="hl slc"># pad it out with zeros</span></li>
<li id="n_2765" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$padzero </span><span class="hl opt">= </span><span class="hl sng">&quot;0&quot;</span> x <span class="hl kwb">$l</span><span class="hl opt">;</span></li>
<li id="n_2766" class="hl">            <span class="hl kwb">$incnum </span><span class="hl opt">= (</span><span class="hl sng">&quot;0&quot;</span> x <span class="hl kwb">$l</span><span class="hl opt">) . </span><span class="hl kwb">$incnum</span><span class="hl opt">;</span></li>
<li id="n_2767" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2768" class="hl">            <span class="hl kwb">$incnum </span><span class="hl opt">= </span><span class="hl kwb">$num </span><span class="hl opt">+ </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2769" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2770" class="hl"></li>
<li id="n_2771" class="hl">        <span class="hl kwd">s/$num/$incnum/</span><span class="hl opt">;</span></li>
<li id="n_2772" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2773" class="hl"></li>
<li id="n_2774" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dbvar </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_2775" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$var </span><span class="hl opt">= </span><span class="hl kwb">$_</span><span class="hl opt">;</span></li>
<li id="n_2776" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$str</span><span class="hl opt">;</span></li>
<li id="n_2777" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$param</span><span class="hl opt">;</span></li>
<li id="n_2778" class="hl"></li>
<li id="n_2779" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb /</span><span class="hl opt">) {</span></li>
<li id="n_2780" class="hl"></li>
<li id="n_2781" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwd">/&lt;\?lsmb /</span><span class="hl opt">) {</span></li>
<li id="n_2782" class="hl"></li>
<li id="n_2783" class="hl">            <span class="hl kwd">s/&lt;\?lsmb .*? \?&gt;//</span><span class="hl opt">;</span></li>
<li id="n_2784" class="hl">            <span class="hl kwa">last unless </span><span class="hl kwb">$&amp;</span><span class="hl opt">;</span></li>
<li id="n_2785" class="hl">        <span class="hl kwb">$param </span><span class="hl opt">= </span><span class="hl kwb">$&amp;</span><span class="hl opt">;</span></li>
<li id="n_2786" class="hl">            <span class="hl kwb">$str </span><span class="hl opt">= </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_2787" class="hl"></li>
<li id="n_2788" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$param </span><span class="hl opt">=~ </span><span class="hl kwd">/&lt;\?lsmb date \?&gt;/i</span><span class="hl opt">) {</span></li>
<li id="n_2789" class="hl">                <span class="hl kwb">$str </span><span class="hl opt">= (</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">split_date</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}))[</span><span class="hl num">0</span><span class="hl opt">];</span></li>
<li id="n_2790" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/$param/$str/</span><span class="hl opt">;</span></li>
<li id="n_2791" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2792" class="hl"></li>
<li id="n_2793" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$param </span><span class="hl opt">=~ </span><span class="hl kwd">/&lt;\?lsmb (name|business|description|item|partsgroup|phone|custom)/i</span><span class="hl opt">) {</span></li>
<li id="n_2794" class="hl"></li>
<li id="n_2795" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$fld </span><span class="hl opt">= </span><span class="hl kwc">lc </span><span class="hl kwb">$&amp;</span><span class="hl opt">;</span></li>
<li id="n_2796" class="hl">                <span class="hl kwb">$fld </span><span class="hl opt">=~ </span><span class="hl kwd">s/&lt;\?lsmb //</span><span class="hl opt">;</span></li>
<li id="n_2797" class="hl"></li>
<li id="n_2798" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$fld </span><span class="hl opt">=~ </span><span class="hl kwd">/name/</span><span class="hl opt">) {</span></li>
<li id="n_2799" class="hl">                    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>type<span class="hl opt">}) {</span></li>
<li id="n_2800" class="hl">                        <span class="hl kwb">$fld </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>vc<span class="hl opt">};</span></li>
<li id="n_2801" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_2802" class="hl">                <span class="hl opt">}</span></li>
<li id="n_2803" class="hl"></li>
<li id="n_2804" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$p </span><span class="hl opt">= </span><span class="hl kwb">$param</span><span class="hl opt">;</span></li>
<li id="n_2805" class="hl">                <span class="hl kwb">$p </span><span class="hl opt">=~ </span><span class="hl kwd">s/(&lt;|&gt;|%)//g</span><span class="hl opt">;</span></li>
<li id="n_2806" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;p </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/ /</span><span class="hl opt">, </span><span class="hl kwb">$p</span><span class="hl opt">;</span></li>
<li id="n_2807" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;n </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/ /</span><span class="hl opt">, </span><span class="hl kwc">uc </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$fld</span><span class="hl opt">};</span></li>
<li id="n_2808" class="hl"></li>
<li id="n_2809" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$#p </span><span class="hl opt">&gt; </span><span class="hl num">0</span><span class="hl opt">) {</span></li>
<li id="n_2810" class="hl"></li>
<li id="n_2811" class="hl">                    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">; </span><span class="hl kwb">$i </span><span class="hl opt">&lt;= </span><span class="hl kwb">$#p</span><span class="hl opt">; </span><span class="hl kwb">$i++</span><span class="hl opt">) {</span></li>
<li id="n_2812" class="hl">                        <span class="hl kwb">$str </span><span class="hl opt">.= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$n</span><span class="hl opt">[</span><span class="hl kwb">$i</span><span class="hl opt">-</span><span class="hl num">1</span><span class="hl opt">], </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl kwb">$p</span><span class="hl opt">[</span><span class="hl kwb">$i</span><span class="hl opt">]);</span></li>
<li id="n_2813" class="hl">                    <span class="hl opt">}</span></li>
<li id="n_2814" class="hl"></li>
<li id="n_2815" class="hl">                <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2816" class="hl">                    <span class="hl opt">(</span><span class="hl kwb">$str</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/--/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$fld</span><span class="hl opt">};</span></li>
<li id="n_2817" class="hl">                <span class="hl opt">}</span></li>
<li id="n_2818" class="hl"></li>
<li id="n_2819" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/$param/$str/</span><span class="hl opt">;</span></li>
<li id="n_2820" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/\W//g </span><span class="hl kwa">if </span><span class="hl kwb">$fld </span><span class="hl kwc">eq </span><span class="hl sng">&#39;phone&#39;</span><span class="hl opt">;</span></li>
<li id="n_2821" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2822" class="hl"></li>
<li id="n_2823" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$param </span><span class="hl opt">=~ </span><span class="hl kwd">/&lt;\?lsmb (yy|mm|dd)/i</span><span class="hl opt">) {</span></li>
<li id="n_2824" class="hl"></li>
<li id="n_2825" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$p </span><span class="hl opt">= </span><span class="hl kwb">$param</span><span class="hl opt">;</span></li>
<li id="n_2826" class="hl">                <span class="hl kwb">$p </span><span class="hl opt">=~ </span><span class="hl kwd">s/(&lt;|&gt;|%)//g</span><span class="hl opt">;</span></li>
<li id="n_2827" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$spc </span><span class="hl opt">= </span><span class="hl kwb">$p</span><span class="hl opt">;</span></li>
<li id="n_2828" class="hl">                <span class="hl kwb">$spc </span><span class="hl opt">=~ </span><span class="hl kwd">s/\w//g</span><span class="hl opt">;</span></li>
<li id="n_2829" class="hl">                <span class="hl kwb">$spc </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$spc</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_2830" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">%d </span><span class="hl opt">= ( </span>yy <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">, </span>mm <span class="hl opt">=&gt; </span><span class="hl num">2</span><span class="hl opt">, </span>dd <span class="hl opt">=&gt; </span><span class="hl num">3 </span><span class="hl opt">);</span></li>
<li id="n_2831" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;p </span><span class="hl opt">= ();</span></li>
<li id="n_2832" class="hl"></li>
<li id="n_2833" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;a </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">split_date</span><span class="hl opt">(</span><span class="hl kwb">$myconfig</span><span class="hl opt">-&gt;{</span>dateformat<span class="hl opt">}, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">});</span></li>
<li id="n_2834" class="hl">                <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">sort keys </span><span class="hl kwb">%d</span><span class="hl opt">) { </span><span class="hl kwc">push </span><span class="hl kwb">&#64;p</span><span class="hl opt">, </span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$d</span><span class="hl opt">{</span><span class="hl kwb">$_</span><span class="hl opt">}] </span><span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$p </span><span class="hl opt">=~ </span><span class="hl kwd">/$_/</span><span class="hl opt">) }</span></li>
<li id="n_2835" class="hl">                <span class="hl kwb">$str </span><span class="hl opt">= </span><span class="hl kwc">join </span><span class="hl kwb">$spc</span><span class="hl opt">, </span><span class="hl kwb">&#64;p</span><span class="hl opt">;</span></li>
<li id="n_2836" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/$param/$str/</span><span class="hl opt">;</span></li>
<li id="n_2837" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2838" class="hl"></li>
<li id="n_2839" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$param </span><span class="hl opt">=~ </span><span class="hl kwd">/&lt;\?lsmb curr/i</span><span class="hl opt">) {</span></li>
<li id="n_2840" class="hl">                <span class="hl kwb">$var </span><span class="hl opt">=~ </span><span class="hl kwd">s/$param/$self-&gt;{currency}/</span><span class="hl opt">;</span></li>
<li id="n_2841" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2842" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2843" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2844" class="hl"></li>
<li id="n_2845" class="hl">    <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_2846" class="hl">        UPDATE defaults</li>
<li id="n_2847" class="hl">           SET value <span class="hl opt">= ?</span></li>
<li id="n_2848" class="hl">         WHERE setting_key <span class="hl opt">= ?|;</span></li>
<li id="n_2849" class="hl"></li>
<li id="n_2850" class="hl">    <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">); </span></li>
<li id="n_2851" class="hl">    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">$dbvar</span><span class="hl opt">, </span><span class="hl kwb">$fld</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_2852" class="hl"></li>
<li id="n_2853" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_2854" class="hl"></li>
<li id="n_2855" class="hl">    <span class="hl kwb">$var</span><span class="hl opt">;</span></li>
<li id="n_2856" class="hl"><span class="hl opt">}</span></li>
<li id="n_2857" class="hl"></li>
<li id="n_2858" class="hl"><span class="hl kwa">sub </span>db_prepare_vars <span class="hl opt">{</span></li>
<li id="n_2859" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;_</span><span class="hl opt">){</span></li>
<li id="n_2860" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(!</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} </span><span class="hl kwc">and </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">} </span><span class="hl kwc">ne </span><span class="hl sng">&quot;0&quot;</span><span class="hl opt">){</span></li>
<li id="n_2861" class="hl">            <span class="hl kwc">undef </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span><span class="hl kwb">$_</span><span class="hl opt">};</span></li>
<li id="n_2862" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2863" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2864" class="hl"><span class="hl opt">}</span></li>
<li id="n_2865" class="hl"></li>
<li id="n_2866" class="hl"><span class="hl kwa">sub </span>split_date <span class="hl opt">{</span></li>
<li id="n_2867" class="hl"></li>
<li id="n_2868" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dateformat</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2869" class="hl"></li>
<li id="n_2870" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;d </span><span class="hl opt">= </span><span class="hl kwc">localtime</span><span class="hl opt">;</span></li>
<li id="n_2871" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$mm</span><span class="hl opt">;</span></li>
<li id="n_2872" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dd</span><span class="hl opt">;</span></li>
<li id="n_2873" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$yy</span><span class="hl opt">;</span></li>
<li id="n_2874" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$rv</span><span class="hl opt">;</span></li>
<li id="n_2875" class="hl"></li>
<li id="n_2876" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$date</span><span class="hl opt">) {</span></li>
<li id="n_2877" class="hl">        <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwb">$d</span><span class="hl opt">[</span><span class="hl num">3</span><span class="hl opt">];</span></li>
<li id="n_2878" class="hl">        <span class="hl kwb">$mm </span><span class="hl opt">= ++</span><span class="hl kwb">$d</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">];</span></li>
<li id="n_2879" class="hl">        <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$d</span><span class="hl opt">[</span><span class="hl num">5</span><span class="hl opt">],-</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2880" class="hl">        <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$mm</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2881" class="hl">        <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$dd</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2882" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2883" class="hl"></li>
<li id="n_2884" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dateformat </span><span class="hl opt">=~ </span><span class="hl kwd">/^yy/</span><span class="hl opt">) {</span></li>
<li id="n_2885" class="hl"></li>
<li id="n_2886" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date</span><span class="hl opt">) {</span></li>
<li id="n_2887" class="hl"></li>
<li id="n_2888" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_2889" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2890" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2891" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2892" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$mm</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2893" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$dd</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2894" class="hl">                <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2895" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$mm$dd</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2896" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2897" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2898" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2899" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2900" class="hl">            <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$mm$dd</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2901" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2902" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2903" class="hl"></li>
<li id="n_2904" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dateformat </span><span class="hl opt">=~ </span><span class="hl kwd">/^mm/</span><span class="hl opt">) {</span></li>
<li id="n_2905" class="hl"></li>
<li id="n_2906" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date</span><span class="hl opt">) { </span></li>
<li id="n_2907" class="hl"></li>
<li id="n_2908" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_2909" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2910" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2911" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2912" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$mm</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2913" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$dd</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2914" class="hl">                <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2915" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$mm$dd$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2916" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2917" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2918" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2919" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2920" class="hl">            <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$mm$dd$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2921" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2922" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2923" class="hl"></li>
<li id="n_2924" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dateformat </span><span class="hl opt">=~ </span><span class="hl kwd">/^dd/</span><span class="hl opt">) {</span></li>
<li id="n_2925" class="hl"></li>
<li id="n_2926" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date</span><span class="hl opt">) {</span></li>
<li id="n_2927" class="hl"></li>
<li id="n_2928" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$date </span><span class="hl opt">=~ </span><span class="hl kwd">/\D/</span><span class="hl opt">) {</span></li>
<li id="n_2929" class="hl">                <span class="hl opt">(</span><span class="hl kwb">$dd</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">) = </span><span class="hl kwc">split </span><span class="hl kwd">/\D/</span><span class="hl opt">, </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2930" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2931" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">*= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2932" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$mm</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2933" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$dd</span><span class="hl sng">&quot;</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2934" class="hl">                <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl kwb">$yy</span><span class="hl opt">, -</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2935" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$dd$mm$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2936" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2937" class="hl">                <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl kwb">$date</span><span class="hl opt">;</span></li>
<li id="n_2938" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2939" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2940" class="hl">            <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$dd$mm$yy</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_2941" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2942" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2943" class="hl"></li>
<li id="n_2944" class="hl">    <span class="hl opt">(</span><span class="hl kwb">$rv</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$dd</span><span class="hl opt">);</span></li>
<li id="n_2945" class="hl"><span class="hl opt">}</span></li>
<li id="n_2946" class="hl"></li>
<li id="n_2947" class="hl"></li>
<li id="n_2948" class="hl"><span class="hl kwa">sub </span>from_to <span class="hl opt">{</span></li>
<li id="n_2949" class="hl"></li>
<li id="n_2950" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$yy</span><span class="hl opt">, </span><span class="hl kwb">$mm</span><span class="hl opt">, </span><span class="hl kwb">$interval</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_2951" class="hl"></li>
<li id="n_2952" class="hl">    <span class="hl kwa">use </span>Time<span class="hl opt">::</span>Local<span class="hl opt">;</span></li>
<li id="n_2953" class="hl"></li>
<li id="n_2954" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;t</span><span class="hl opt">;</span></li>
<li id="n_2955" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2956" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$fromdate </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$yy$</span><span class="hl sng">{mm}01&quot;</span><span class="hl opt">;</span></li>
<li id="n_2957" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$bd </span><span class="hl opt">= </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2958" class="hl"></li>
<li id="n_2959" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$interval</span><span class="hl opt">) {</span></li>
<li id="n_2960" class="hl"></li>
<li id="n_2961" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$interval </span><span class="hl opt">== </span><span class="hl num">12</span><span class="hl opt">) {</span></li>
<li id="n_2962" class="hl">            <span class="hl kwb">$yy++</span><span class="hl opt">;</span></li>
<li id="n_2963" class="hl">        <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2964" class="hl"></li>
<li id="n_2965" class="hl">            <span class="hl kwa">if </span><span class="hl opt">((</span><span class="hl kwb">$mm </span><span class="hl opt">+= </span><span class="hl kwb">$interval</span><span class="hl opt">) &gt; </span><span class="hl num">12</span><span class="hl opt">) {</span></li>
<li id="n_2966" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">-= </span><span class="hl num">12</span><span class="hl opt">;</span></li>
<li id="n_2967" class="hl">                <span class="hl kwb">$yy++</span><span class="hl opt">;</span></li>
<li id="n_2968" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2969" class="hl"></li>
<li id="n_2970" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$interval </span><span class="hl opt">== </span><span class="hl num">0</span><span class="hl opt">) {</span></li>
<li id="n_2971" class="hl">                <span class="hl kwb">&#64;t </span><span class="hl opt">= </span><span class="hl kwc">localtime</span><span class="hl opt">(</span><span class="hl kwc">time</span><span class="hl opt">);</span></li>
<li id="n_2972" class="hl">                <span class="hl kwb">$dd </span><span class="hl opt">= </span><span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">3</span><span class="hl opt">];</span></li>
<li id="n_2973" class="hl">                <span class="hl kwb">$mm </span><span class="hl opt">= </span><span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">] + </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_2974" class="hl">                <span class="hl kwb">$yy </span><span class="hl opt">= </span><span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">5</span><span class="hl opt">] + </span><span class="hl num">1900</span><span class="hl opt">;</span></li>
<li id="n_2975" class="hl">                <span class="hl kwb">$bd </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_2976" class="hl">            <span class="hl opt">}</span></li>
<li id="n_2977" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2978" class="hl"></li>
<li id="n_2979" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_2980" class="hl"></li>
<li id="n_2981" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(++</span><span class="hl kwb">$mm </span><span class="hl opt">&gt; </span><span class="hl num">12</span><span class="hl opt">) {</span></li>
<li id="n_2982" class="hl">            <span class="hl kwb">$mm </span><span class="hl opt">-= </span><span class="hl num">12</span><span class="hl opt">;</span></li>
<li id="n_2983" class="hl">            <span class="hl kwb">$yy++</span><span class="hl opt">;</span></li>
<li id="n_2984" class="hl">        <span class="hl opt">}</span></li>
<li id="n_2985" class="hl">    <span class="hl opt">}</span></li>
<li id="n_2986" class="hl"></li>
<li id="n_2987" class="hl">    <span class="hl kwb">$mm</span><span class="hl opt">--;</span></li>
<li id="n_2988" class="hl">    <span class="hl kwb">&#64;t </span><span class="hl opt">= </span><span class="hl kwc">localtime</span><span class="hl opt">(</span>timelocal<span class="hl opt">(</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl num">0</span><span class="hl opt">,</span><span class="hl kwb">$dd</span><span class="hl opt">,</span><span class="hl kwb">$mm</span><span class="hl opt">,</span><span class="hl kwb">$yy</span><span class="hl opt">) - </span><span class="hl kwb">$bd</span><span class="hl opt">);</span></li>
<li id="n_2989" class="hl"></li>
<li id="n_2990" class="hl">    <span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">]++;</span></li>
<li id="n_2991" class="hl">    <span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">] = </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$t</span><span class="hl sng">[4]&quot;</span><span class="hl opt">,-</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2992" class="hl">    <span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">3</span><span class="hl opt">] = </span><span class="hl kwc">substr</span><span class="hl opt">(</span><span class="hl sng">&quot;0</span><span class="hl ipl">$t</span><span class="hl sng">[3]&quot;</span><span class="hl opt">,-</span><span class="hl num">2</span><span class="hl opt">);</span></li>
<li id="n_2993" class="hl">    <span class="hl kwb">$t</span><span class="hl opt">[</span><span class="hl num">5</span><span class="hl opt">] += </span><span class="hl num">1900</span><span class="hl opt">;</span></li>
<li id="n_2994" class="hl"></li>
<li id="n_2995" class="hl">    <span class="hl opt">(</span><span class="hl kwb">$fromdate</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl ipl">$t</span><span class="hl sng">[5]</span><span class="hl ipl">$t</span><span class="hl sng">[4]</span><span class="hl ipl">$t</span><span class="hl sng">[3]&quot;</span><span class="hl opt">);</span></li>
<li id="n_2996" class="hl"><span class="hl opt">}</span></li>
<li id="n_2997" class="hl"></li>
<li id="n_2998" class="hl"></li>
<li id="n_2999" class="hl"><span class="hl kwa">sub </span>audittrail <span class="hl opt">{</span></li>
<li id="n_3000" class="hl"></li>
<li id="n_3001" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">, </span><span class="hl kwb">$dbh</span><span class="hl opt">, </span><span class="hl kwb">$myconfig</span><span class="hl opt">, </span><span class="hl kwb">$audittrail</span><span class="hl opt">) = </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_3002" class="hl"></li>
<li id="n_3003" class="hl">    <span class="hl slc"># table, $reference, $formname, $action, $id, $transdate) = &#64;_;</span></li>
<li id="n_3004" class="hl"></li>
<li id="n_3005" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$query</span><span class="hl opt">;</span></li>
<li id="n_3006" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$rv</span><span class="hl opt">;</span></li>
<li id="n_3007" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$disconnect</span><span class="hl opt">;</span></li>
<li id="n_3008" class="hl"></li>
<li id="n_3009" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$dbh</span><span class="hl opt">) {</span></li>
<li id="n_3010" class="hl">        <span class="hl kwb">$dbh </span><span class="hl opt">= </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>dbh<span class="hl opt">};</span></li>
<li id="n_3011" class="hl">    <span class="hl opt">}</span></li>
<li id="n_3012" class="hl"></li>
<li id="n_3013" class="hl">    <span class="hl slc"># if we have an id add audittrail, otherwise get a new timestamp</span></li>
<li id="n_3014" class="hl"></li>
<li id="n_3015" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">;</span></li>
<li id="n_3016" class="hl"></li>
<li id="n_3017" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}) {</span></li>
<li id="n_3018" class="hl"></li>
<li id="n_3019" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_3020" class="hl">            SELECT value FROM defaults </li>
<li id="n_3021" class="hl">             WHERE setting_key <span class="hl opt">= </span><span class="hl sng">&#39;audittrail&#39;</span><span class="hl opt">|;</span></li>
<li id="n_3022" class="hl"></li>
<li id="n_3023" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">)) {</span></li>
<li id="n_3024" class="hl"></li>
<li id="n_3025" class="hl">            <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$null</span><span class="hl opt">, </span><span class="hl kwb">$employee_id</span><span class="hl opt">) = </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">get_employee</span><span class="hl opt">(</span><span class="hl kwb">$dbh</span><span class="hl opt">);</span></li>
<li id="n_3026" class="hl"></li>
<li id="n_3027" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>audittrail<span class="hl opt">} &amp;&amp; !</span><span class="hl kwb">$myconfig</span><span class="hl opt">) {</span></li>
<li id="n_3028" class="hl"></li>
<li id="n_3029" class="hl">                <span class="hl kwc">chop </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>audittrail<span class="hl opt">};</span></li>
<li id="n_3030" class="hl"></li>
<li id="n_3031" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;a </span><span class="hl opt">= </span><span class="hl kwc">split </span><span class="hl kwd">/\|/</span><span class="hl opt">, </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;{</span>audittrail<span class="hl opt">};</span></li>
<li id="n_3032" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">%newtrail </span><span class="hl opt">= ();</span></li>
<li id="n_3033" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$key</span><span class="hl opt">;</span></li>
<li id="n_3034" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$i</span><span class="hl opt">;</span></li>
<li id="n_3035" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">&#64;flds </span><span class="hl opt">= </span><span class="hl sng">qw(tablename reference formname action transdate)</span><span class="hl opt">;</span></li>
<li id="n_3036" class="hl"></li>
<li id="n_3037" class="hl">                <span class="hl slc"># put into hash and remove dups</span></li>
<li id="n_3038" class="hl">                <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">&#64;a</span><span class="hl opt">) {</span></li>
<li id="n_3039" class="hl">                    <span class="hl kwb">$key </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$a</span><span class="hl sng">[2]</span><span class="hl ipl">$a</span><span class="hl sng">[3]&quot;</span><span class="hl opt">;</span></li>
<li id="n_3040" class="hl">                    <span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_3041" class="hl">                    <span class="hl kwb">$newtrail</span><span class="hl opt">{</span><span class="hl kwb">$key</span><span class="hl opt">} = { </span><span class="hl kwc">map </span><span class="hl opt">{ </span><span class="hl kwb">$_ </span><span class="hl opt">=&gt; </span><span class="hl kwb">$a</span><span class="hl opt">[</span><span class="hl kwb">$i++</span><span class="hl opt">] } </span><span class="hl kwb">&#64;flds </span><span class="hl opt">};</span></li>
<li id="n_3042" class="hl">                    <span class="hl kwc">splice </span><span class="hl kwb">&#64;a</span><span class="hl opt">, </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl num">5</span><span class="hl opt">;</span></li>
<li id="n_3043" class="hl">                <span class="hl opt">}</span></li>
<li id="n_3044" class="hl"></li>
<li id="n_3045" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_3046" class="hl">                    INSERT INTO audittrail </li>
<li id="n_3047" class="hl">                        <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>tablename<span class="hl opt">, </span>reference<span class="hl opt">,</span></li>
<li id="n_3048" class="hl">                        formname<span class="hl opt">, </span>action<span class="hl opt">, </span>transdate<span class="hl opt">, </span></li>
<li id="n_3049" class="hl">                        employee_id<span class="hl opt">)</span></li>
<li id="n_3050" class="hl">                    VALUES <span class="hl opt">(?, ?, ?, ?, ?, ?, ?)|;</span></li>
<li id="n_3051" class="hl"></li>
<li id="n_3052" class="hl">                <span class="hl kwc">my </span><span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">) || </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_3053" class="hl"></li>
<li id="n_3054" class="hl">                <span class="hl kwa">foreach </span><span class="hl kwb">$key </span><span class="hl opt">(</span><span class="hl kwc">sort </span><span class="hl opt">{ </span><span class="hl kwb">$newtrail</span><span class="hl opt">{</span><span class="hl kwb">$a</span><span class="hl opt">}{</span>transdate<span class="hl opt">} </span><span class="hl kwc">cmp </span><span class="hl kwb">$newtrail</span><span class="hl opt">{</span><span class="hl kwb">$b</span><span class="hl opt">}{</span>transdate<span class="hl opt">} } </span><span class="hl kwc">keys </span><span class="hl kwb">%newtrail</span><span class="hl opt">) {</span></li>
<li id="n_3055" class="hl"></li>
<li id="n_3056" class="hl">                    <span class="hl kwb">$i </span><span class="hl opt">= </span><span class="hl num">2</span><span class="hl opt">;</span></li>
<li id="n_3057" class="hl">                    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">bind_param</span><span class="hl opt">(</span><span class="hl num">1</span><span class="hl opt">, </span><span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">});</span></li>
<li id="n_3058" class="hl"></li>
<li id="n_3059" class="hl">                    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwb">&#64;flds</span><span class="hl opt">) { </span><span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">bind_param</span><span class="hl opt">(</span><span class="hl kwb">$i++</span><span class="hl opt">, </span><span class="hl kwb">$newtrail</span><span class="hl opt">{</span><span class="hl kwb">$key</span><span class="hl opt">}{</span><span class="hl kwb">$_</span><span class="hl opt">}) }</span></li>
<li id="n_3060" class="hl">                    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">bind_param</span><span class="hl opt">(</span><span class="hl kwb">$i++</span><span class="hl opt">, </span><span class="hl kwb">$employee_id</span><span class="hl opt">);</span></li>
<li id="n_3061" class="hl">                    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute </span><span class="hl opt">|| </span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">;</span></li>
<li id="n_3062" class="hl">                    <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">finish</span><span class="hl opt">;</span></li>
<li id="n_3063" class="hl">                <span class="hl opt">}</span></li>
<li id="n_3064" class="hl">            <span class="hl opt">}</span></li>
<li id="n_3065" class="hl"></li>
<li id="n_3066" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}) {</span></li>
<li id="n_3067" class="hl"></li>
<li id="n_3068" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_3069" class="hl">                    INSERT INTO audittrail <span class="hl opt">(</span></li>
<li id="n_3070" class="hl">                        trans_id<span class="hl opt">, </span>tablename<span class="hl opt">, </span>reference<span class="hl opt">,</span></li>
<li id="n_3071" class="hl">                        formname<span class="hl opt">, </span>action<span class="hl opt">, </span>employee_id<span class="hl opt">, </span></li>
<li id="n_3072" class="hl">                        transdate<span class="hl opt">)</span></li>
<li id="n_3073" class="hl">                    VALUES <span class="hl opt">(?, ?, ?, ?, ?, ?)|;</span></li>
<li id="n_3074" class="hl">                <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span></li>
<li id="n_3075" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span></li>
<li id="n_3076" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>tablename<span class="hl opt">},</span></li>
<li id="n_3077" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>reference<span class="hl opt">},</span></li>
<li id="n_3078" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>formname<span class="hl opt">},</span></li>
<li id="n_3079" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">}.</span></li>
<li id="n_3080" class="hl">                    <span class="hl kwb">$employee_id</span><span class="hl opt">,</span></li>
<li id="n_3081" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>transdate<span class="hl opt">}</span></li>
<li id="n_3082" class="hl">                <span class="hl opt">);</span></li>
<li id="n_3083" class="hl">            <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_3084" class="hl">                <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span></li>
<li id="n_3085" class="hl">                    INSERT INTO audittrail </li>
<li id="n_3086" class="hl">                        <span class="hl opt">(</span>trans_id<span class="hl opt">, </span>tablename<span class="hl opt">, </span>reference<span class="hl opt">,</span></li>
<li id="n_3087" class="hl">                        formname<span class="hl opt">, </span>action<span class="hl opt">, </span>employee_id<span class="hl opt">)</span></li>
<li id="n_3088" class="hl">                    VALUES <span class="hl opt">(?, ?, ?, ?, ?)|;</span></li>
<li id="n_3089" class="hl">                <span class="hl kwb">&#64;queryargs </span><span class="hl opt">= (</span></li>
<li id="n_3090" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>id<span class="hl opt">}, </span></li>
<li id="n_3091" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>tablename<span class="hl opt">},</span></li>
<li id="n_3092" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>reference<span class="hl opt">},</span></li>
<li id="n_3093" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>formname<span class="hl opt">},</span></li>
<li id="n_3094" class="hl">                    <span class="hl kwb">$audittrail</span><span class="hl opt">-&gt;{</span>action<span class="hl opt">}.</span></li>
<li id="n_3095" class="hl">                    <span class="hl kwb">$employee_id</span><span class="hl opt">,</span></li>
<li id="n_3096" class="hl">                <span class="hl opt">);</span></li>
<li id="n_3097" class="hl">            <span class="hl opt">}</span></li>
<li id="n_3098" class="hl"></li>
<li id="n_3099" class="hl">            <span class="hl kwb">$sth </span><span class="hl opt">= </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">prepare</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_3100" class="hl">            <span class="hl kwb">$sth</span><span class="hl opt">-&gt;</span><span class="hl kwd">execute</span><span class="hl opt">(</span><span class="hl kwb">&#64;queryargs</span><span class="hl opt">)||</span><span class="hl kwb">$self</span><span class="hl opt">-&gt;</span><span class="hl kwd">dberror</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_3101" class="hl">        <span class="hl opt">}</span></li>
<li id="n_3102" class="hl"></li>
<li id="n_3103" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_3104" class="hl"></li>
<li id="n_3105" class="hl">        <span class="hl kwb">$query </span><span class="hl opt">= </span>qq<span class="hl opt">|</span>SELECT current_timestamp<span class="hl opt">|;</span></li>
<li id="n_3106" class="hl">        <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$timestamp</span><span class="hl opt">) = </span><span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">selectrow_array</span><span class="hl opt">(</span><span class="hl kwb">$query</span><span class="hl opt">);</span></li>
<li id="n_3107" class="hl"></li>
<li id="n_3108" class="hl">        <span class="hl kwb">$rv </span><span class="hl opt">= </span><span class="hl sng">&quot;</span><span class="hl ipl">$audittrail</span><span class="hl sng">-&gt;{tablename}|</span><span class="hl ipl">$audittrail</span><span class="hl sng">-&gt;{reference}|</span><span class="hl ipl">$audittrail</span><span class="hl sng">-&gt;{formname}|</span><span class="hl ipl">$audittrail</span><span class="hl sng">-&gt;{action}|</span><span class="hl ipl">$timestamp</span><span class="hl sng">|&quot;</span><span class="hl opt">;</span></li>
<li id="n_3109" class="hl">    <span class="hl opt">}</span></li>
<li id="n_3110" class="hl"></li>
<li id="n_3111" class="hl">    <span class="hl kwb">$dbh</span><span class="hl opt">-&gt;</span><span class="hl kwd">commit</span><span class="hl opt">;</span></li>
<li id="n_3112" class="hl">    <span class="hl kwb">$rv</span><span class="hl opt">;</span></li>
<li id="n_3113" class="hl"><span class="hl opt">}</span></li>
<li id="n_3114" class="hl"></li>
<li id="n_3115" class="hl"><span class="hl num">1</span><span class="hl opt">;</span></li>
</ol></code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-06-22 17:14:52 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
