<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Yet another blog about PHP, HTML and CSS</title>
	
	<link>http://blog.pepa.info</link>
	<description>Petr 'PePa' Pavel</description>
	<pubDate>Tue, 18 Nov 2008 17:17:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/YetAnotherBlogAboutPhpHtmlAndCss" type="application/rss+xml" /><item>
		<title>What you can expect as $results in afterFind()</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/455043095/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 16:48:53 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=71</guid>
		<description><![CDATA[Function afterFind() can be called in various contexts with different types of $results. If you don&#8217;t handle them all properly the function will not work right (which you may not care in some cases) and you&#8217;ll end up with notice level errors.

Here are situations I stumbled upon, let me know if you have found some [...]]]></description>
			<content:encoded><![CDATA[<p>Function afterFind() can be called in various contexts with different types of $results. If you don&#8217;t handle them all properly the function will not work right (which you may not care in some cases) and you&#8217;ll end up with notice level errors.</p>
<p><span id="more-71"></span></p>
<p>Here are situations I stumbled upon, let me know if you have found some more:</p>
<ol>
<li>if your model contains a validation rule &#8216;isUnique&#8217; then afterFind() gets called from $model-&gt;invalidFields() with a result of SELECT COUNT():<br />
<strong> array(array(array(&#8217;count&#8217; =&gt; 1)))</strong></li>
<li>another results scheme is yielded by a model association (e.g. via belongsTo):<br />
<strong> array(&#8217;id&#8217; =&gt; 123, &#8216;first_name&#8217; =&gt; &#8216;Joe&#8217;&#8230;)</strong></li>
<li>and then there&#8217;s the regular $model-&gt;find() which gives<br />
<strong> array(<br />
0 =&gt; array(&#8217;ModelName&#8217; =&gt; array(&#8217;id&#8217; =&gt; 123, &#8230;)),<br />
1 =&gt; array(&#8217;ModelName&#8217; =&gt; array(&#8217;id&#8217; =&gt; 124, &#8230;))<br />
)</strong></li>
</ol>
<p>So what is the best way to work with this omnishaped variable?</p>
<p>First skip everything if there are no results:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$results</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Then check for case 2 (assuming your primary key is &#8216;id&#8217;):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="st0">&#8216;id&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>then for case 3:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">elseif</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="re0">$this</span>-&gt;<span class="me1">alias</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;id&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>and lastly you can check for the count result if you care:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">elseif</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_array"><span class="kw3">is_array</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> &amp;amp;&amp;amp; <a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$results</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;count&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// do your thing</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/455043095" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/what-you-can-expect-as-results-in-afterfind/</feedburner:origLink></item>
		<item>
		<title>Ganymede / PHPEclipse - not a good choice for debugging CakePHP</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/454960706/</link>
		<comments>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 19:57:40 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<category><![CDATA[Debugging]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=62</guid>
		<description><![CDATA[After hours of trying I finally conclude that CakePHP cannot be debugged in Eclipse 3.4.1 (Ganymede) and PHPEclipse 1.2.1.200810130444PRD (XDebug).
My webroot is set to app/webroot and Eclipse stops on a breakpoint only if it&#8217;s in app/webroot/index.php
Even after it stops there it won&#8217;t stop on a next breakpoint that is set in my controller.
The only working [...]]]></description>
			<content:encoded><![CDATA[<p>After hours of trying I finally conclude that CakePHP cannot be debugged in Eclipse 3.4.1 (Ganymede) and PHPEclipse 1.2.1.200810130444PRD (XDebug).</p>
<p>My webroot is set to app/webroot and Eclipse stops on a breakpoint only if it&#8217;s in app/webroot/index.php<br />
Even after it stops there it won&#8217;t stop on a next breakpoint that is set in my controller.</p>
<p>The only working solution I found is downgrading to Eclipse 3.3.2 (Europa) and PDT 1.0.3.v20080603. Fortunately both can run side by side so in theory, I can write new code in Ganymede and debug in Europa but that sucks. Programming is a constant debugging.</p>
<p>I could try to switch from XDebug to DBG. Maybe I will next time I have a day that I can waste.</p>
<h2>Update:</h2>
<p>New PDT 2.0.0.v20081030-1802 works with Ganymede/XDebug just fine. It also has features I have been missing like Mark Occurrences - one more reason for switching. It doesn&#8217;t have support for chm help files though (PHPEclipse does) and is generally slower than PHPEclipse.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/454960706" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/tools/ganymede-phpeclipse-cakephp-debug/</feedburner:origLink></item>
		<item>
		<title>Calculating time difference in months as a decimal number</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/415137182/</link>
		<comments>http://blog.pepa.info/php-html-css/design-patterns/calculating-time-difference-in-months-as-a-decimal-number/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 20:54:21 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=44</guid>
		<description><![CDATA[There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number?
2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230;




function monthCount&#40;$start, $end&#41; &#123;


&#160; list&#40;$startYear, [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number?</p>
<p>2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230;</p>
<p><span id="more-44"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> monthCount<span class="br0">&#40;</span><span class="re0">$start</span>, <span class="re0">$end</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$startYear</span>, <span class="re0">$startMonth</span>, <span class="re0">$startDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$start</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$endYear</span>, <span class="re0">$endMonth</span>, <span class="re0">$endDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$end</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$startMonthCount</span> =</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span><span class="re0">$startYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// number of months since the beginning of our calendar</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$startMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// month number</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$startDay</span> - <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$start</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// day number divided by the number of days in that month</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$endMonthCount</span> = <span class="br0">&#40;</span><span class="re0">$endYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> + <span class="re0">$endMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$endDay</span> - <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$end</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$endMonthCount</span> - <span class="re0">$startMonthCount</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Note: end date is not inclusive.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/415137182" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/design-patterns/calculating-time-difference-in-months-as-a-decimal-number/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/design-patterns/calculating-time-difference-in-months-as-a-decimal-number/</feedburner:origLink></item>
		<item>
		<title>Absolute positioning in HTML e-mails for Outlook 2007</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/409598735/</link>
		<comments>http://blog.pepa.info/php-html-css/html-e-mail/absolute-positioning-outlook-2007/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 19:20:54 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[HTML e-mail]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=21</guid>
		<description><![CDATA[I couldn&#8217;t possibly explain my frustration from Microsoft switching Outlook&#8217;s rendering engine to Word so I better don&#8217;t even try. Instead, I&#8217;m going to tell you how to make Outlook/Word position elements absolutely.
The idea originally came from doublethink (written in Czech) who made a text field in Word, saved it as HTML and then dig [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t possibly explain my frustration from Microsoft switching Outlook&#8217;s rendering engine to Word so I better don&#8217;t even try. Instead, I&#8217;m going to tell you how to make Outlook/Word position elements absolutely.</p>
<p>The idea originally came from <a title="Outlook 2007: HTML templates" href="http://doublethink.cleverweb.cz/1-outlook-2007-html-sablony" target="_blank">doublethink</a> (written in Czech) who made a text field in Word, saved it as HTML and then dig through the mess to extract the essence. I just went a step further and did the same for images as well.<br />
<span id="more-21"></span><br />
Start by adding this to tag HTML:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;html xmlns:v=&quot;urn:schemas-microsoft-com:vml&quot;&gt;</div>
</li>
</ol>
</div>
<h3>Images</h3>
<p>We&#8217;re lucky Word knows how to insert pictures and &#8220;wrap&#8221; the text behind/above the picture.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;!&#8211;[if gte vml 1]&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;v:shape id=&quot;headerShapeImg&quot; type=&quot;#_x0000_t75&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;style=&quot;position: absolute; height: 106px; width: 769px; z-index: -1;&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;v:imagedata src=&quot;/pix/header.png&quot; alt=&quot;this is my header&quot;/&gt;
</div>
</li>
<li class="li2">
<div class="de2">&lt;/v:shape&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;![endif]&#8211;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;![if !vml]&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;img v:shapes=&quot;headerShapeImg&quot; src=&quot;/pix/header.png&quot; id=&quot;headerImg&quot; alt=&quot;this is my header&quot;&gt;
</div>
</li>
<li class="li2">
<div class="de2">&lt;![endif]&gt;</div>
</li>
</ol>
</div>
<p>Place the whole thing directly into BODY, both parts where the image is supposed to be. Please note that the IMG tag will be used only for engines other than Word and MSIE.</p>
<p>ID &#8220;headerImg&#8221; is there to provide reference for further formatting - although don&#8217;t expect it to work in Word/Outlook.The only universal method is to use inline CSS via STYLE. Also like it or not, you&#8217;ll have to duplicate your formatting definition - define it both for V:SHAPE and for IMG (or DIV, see below).</p>
<h3>Others</h3>
<p>Other stuff must be wrapped in a div like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;!&#8211;[if gte vml 1]&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;v:shape id=&quot;tableShape&quot; type=&quot;#_x0000_t202&quot; filled=&quot;f&quot; stroked=&quot;f&quot;
</div>
</li>
<li class="li1">
<div class="de1">style=&quot;position: absolute; margin-left: 280px; margin-top: 76px; z-index: 1; width: 470px;&quot;&gt;&lt;/v:shape&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;![endif]&#8211;&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div v:shape=&quot;tableShape&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&#8230;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>I&#8217;m sure you have already guessed the meaning of attributes filled (background color) and stroked (frame border). Remember, this is Word so we&#8217;re talking about a &#8220;text frame&#8221;.</p>
<p>That&#8217;s also a reason why you have to use margin-left and margin-top instead of top and left, or even margin: top right bottom left. And don&#8217;t forget to add width to every absolutely positioned element - in numbers, &#8220;auto&#8221; doesn&#8217;t count.</p>
<h3>Duplicate formatting</h3>
<p>Sweet, huh? Here&#8217;s what I used to make my life easier. We&#8217;re PHP programmers, remember?</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1"><span class="re0">$tableStyle</span> = &lt;&lt;&lt;HEREDOC</span></div>
</li>
<li class="li1">
<div class="de1">position: absolute;</div>
</li>
<li class="li1">
<div class="de1">margin-left: 280px;</div>
</li>
<li class="li2">
<div class="de2">margin-top: 76px;</div>
</li>
<li class="li1">
<div class="de1">z-index: <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">width: 470px;</div>
</li>
<li class="li1">
<div class="de1">HEREDOC;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li2">
<div class="de2">&lt;v:shape id=<span class="st0">&quot;tableShape&quot;</span> &#8230;</div>
</li>
<li class="li1">
<div class="de1"> style=<span class="st0">&quot;&lt;?php echo $tableStyle; ?&gt;&quot;</span>&gt;&lt;/v:shape&gt;</div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1">&lt;div v:shape=<span class="st0">&quot;tableShape&quot;</span></div>
</li>
<li class="li1">
<div class="de1"> style=<span class="st0">&quot;&lt;?php echo $tableStyle; ?&gt;&quot;</span>&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&#8230;</div>
</li>
</ol>
</div>
<p>The output will still contain duplicated formatting but at least, you have a single place for changes.</p>
<h3>How to debug</h3>
<p>The first method that comes to your mind is probably to run your mailing script and then wait for the e-mail to arrive to your Outlook. Since we&#8217;re in fact debugging for Word I preferred to open it directly in Word. I wrote my script to display the HTML &#8220;e-mail&#8221; as a web page instead of sending it and then I opened the url in Word via CTRL+O. You are allowed to paste a url and Word downloads it.</p>
<p>For command line lovers (like me):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&quot;C:\Program Files\Microsoft Office\Office12\WINWORD.EXE&quot; http://server.com/path/page.php</div>
</li>
</ol>
</div>
<p>You&#8217;ll have to be careful about local cache so append fictitious parameters in order to force reload:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http://server.com/path/page.php&amp;amp;whatever=changing_value</div>
</li>
</ol>
</div>
<p>During early stages debug locally with dummy data, of course. No need for the HTML page to be generated by a script using real data. Note though, that when you open a file in Word you cannot write to it using another editor. And when you save from Word you get  back all the marvellous garble that you have worked so hard to erase. Enjoy!</p>
<h3>Some formatting must be applied to a child element</h3>
<p>Did I mention that text-align: right works only when it&#8217;s NOT in the DIV we position but in its child? The same is true for font-family, font-weight and font-size:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;div v:shape=<span class="st0">&quot;myShape&quot;</span>&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;div style=<span class="st0">&quot;text-align: right; font-family: sans-serif;&quot;</span>&gt;</div>
</li>
<li class="li1">
<div class="de1">hello world</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li2">
<div class="de2">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>will work while if you join the two DIVs together, it will not.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/409598735" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/html-e-mail/absolute-positioning-outlook-2007/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/html-e-mail/absolute-positioning-outlook-2007/</feedburner:origLink></item>
		<item>
		<title>processing IMAP folder on a regular basis</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/269348025/</link>
		<comments>http://blog.pepa.info/php-html-css/imap/processing-imap-folder-on-a-regular-basis/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 08:36:41 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[IMAP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/php-html-css/uncategorized/processing-imap-folder-on-a-regular-basis/</guid>
		<description><![CDATA[When you need to check a mailbox on a regular basis and process messages that has arrived since your last check you may find that some messages were somehow skipped.

It can be caused by (among other things) one of these two reasons:

you ignore time zones
you use message&#8217;s sent date instead of delivery date

Here&#8217;s a piece [...]]]></description>
			<content:encoded><![CDATA[<p>When you need to check a mailbox on a regular basis and process messages that has arrived since your last check you may find that some messages were somehow skipped.</p>
<p><span id="more-17"></span></p>
<p>It can be caused by (among other things) one of these two reasons:</p>
<ul>
<li>you ignore time zones</li>
<li>you use message&#8217;s sent date instead of delivery date</li>
</ul>
<p>Here&#8217;s a piece of code that could put you on a right track:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$mailBox</span> = imap_open<span class="br0">&#40;</span><span class="st0">&quot;{server.com:143}INBOX&quot;</span>, <span class="re0">$userName</span>, <span class="re0">$password</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// SSL alternative:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// $mailBox = imap_open(&quot;{server.com:993/imap/ssl/novalidate-cert}INBOX&quot;, $userName, $password);</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$lastCheckDate</span> = <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d-M-Y&quot;</span>, <span class="br0">&#40;</span><span class="re0">$lastCheckTimestamp</span> - <span class="nu0">60</span>*<span class="nu0">60</span>*<span class="nu0">24</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$messageUIDsArray</span> = imap_search<span class="br0">&#40;</span><span class="re0">$mailBox</span>, <span class="st0">&#8216;SINCE &quot;$lastCheckDate&quot;&#8217;</span>, SE_UID<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$messageUIDsArray</span> <span class="kw1">as</span> <span class="re0">$messageUID</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$message</span> = imap_headerinfo<span class="br0">&#40;</span><span class="re0">$mailBox</span>, imap_msgno<span class="br0">&#40;</span><span class="re0">$mailBox</span>, <span class="re0">$messageUID</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// imap_headerinfo() knows no UIDs so you have to convert UID to message sequence number</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;This is delivery date: &quot;</span>.<span class="re0">$message</span>-&gt;<span class="me1">MailDate</span>.<span class="st0">&quot; and this is sent date: &quot;</span>.<span class="re0">$message</span>-&gt;<span class="me1">date</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$messageTimestamp</span> = <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$message</span>-&gt;<span class="me1">MailDate</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$lastCheckTimestamp</span> &lt;= <span class="re0">$messageTimestamp</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">doYourMagic<span class="br0">&#40;</span><span class="re0">$message</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I could deal with time zones better (finding out what time zone the IMAP server is in and build $lastCheckDate from $lastCheckTimestamp in that time zone). I&#8217;m lazy though so I simply deduct 24 hours. That deals with messages delivered around midnight if you&#8217;re not in GMT.</p>
<p>Using a sent timestamp instead of a delivery timestamp is a common pitfall. As far as I know, all PHP functions that return message date return sent date (i.e. information from header Date:) and no delivery date. A message can travel for a long time before getting to you. If you check the mailbox once in an hour it can easily happen that you skip a message that was held in a queue somewhere on its way for more than an hour. Also sender&#8217;s computer time can be set wrongly. Remember that the information entered into Date: can be anything. It&#8217;s the sender&#8217;s e-mail client who decides about it.</p>
<h3>How to debug</h3>
<p>The last issue I had to deal with was what date format the IMAP server expects in your SEARCH SINCE command. 11-Apr-2008 worked for me (both 01-Apr-2008 and 1-Apr-2008 are fine) but if you&#8217;re getting no results you might want to take a peek under the hood. Here&#8217;s how to telnet to the IMAP server and ask yourself:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">telnet server.com 143</div>
</li>
</ol>
</div>
<p>Enter this into the telnet window to talk to the IMAP server:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">10 LOGIN yourUserName yourPassword
</div>
</li>
<li class="li1">
<div class="de1">40 SELECT INBOX
</div>
</li>
<li class="li1">
<div class="de1">50 UID SEARCH SINCE &quot;11-Apr-2008&quot;</div>
</li>
</ol>
</div>
<p>These are just commands that you say, I don&#8217;t include responses. Please note that you have to start each of your commands with an increasing number. It doesn&#8217;t have to be a regular row of numbers, the next number just has to be bigger than the previous one.The search command returns a list of message UIDs that meet your criteria. To see header of each message try this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">60 UID FETCH messageUIDnumber ALL</div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/269348025" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/imap/processing-imap-folder-on-a-regular-basis/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/imap/processing-imap-folder-on-a-regular-basis/</feedburner:origLink></item>
		<item>
		<title>How to deal with IMMUTABLE error in indexes that work with timestamps</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/254342339/</link>
		<comments>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 12:14:54 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Database]]></category>

		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2008/03/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/</guid>
		<description><![CDATA[Say that in an older version of PostgreSQL you had an index like this:



CREATE INDEX logTypeDay ON myLog &#40;eventType, date_trunc&#40;&#8216;day&#8217;, creationTime&#41;&#41;;



and now after upgrading to 8.1+ you&#8217;re getting:
 ERROR:  functions in index expression must be marked IMMUTABLE
The reason is that date_trunc may return different results based on the current time zone. There&#8217;s an example [...]]]></description>
			<content:encoded><![CDATA[<p>Say that in an older version of PostgreSQL you had an index like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CREATE</span> <span class="kw1">INDEX</span> logTypeDay <span class="kw1">ON</span> myLog <span class="br0">&#40;</span>eventType, date_trunc<span class="br0">&#40;</span><span class="st0">&#8216;day&#8217;</span>, creationTime<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>and now after upgrading to 8.1+ you&#8217;re getting:<br />
<strong> ERROR:  functions in index expression must be marked IMMUTABLE</strong></p>
<p><span id="more-16"></span>The reason is that date_trunc may return different results based on the current time zone. There&#8217;s an example query in <a target="_blank" href="http://archives.postgresql.org/pgsql-hackers/2004-10/msg00030.php">PostgreSQL Mailing List Archives</a> that you can run to believe.</p>
<p>If you are absolutely sure that you will always access your data with the same time zone you can redefine your index like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CREATE</span> <span class="kw1">INDEX</span> logTypeDay <span class="kw1">ON</span> myLog <span class="br0">&#40;</span>eventType, date_trunc<span class="br0">&#40;</span><span class="st0">&#8216;day&#8217;</span>::text, creationTime AT TIME ZONE <span class="st0">&#8216;Europe/Prague&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The whole immutable business with indexes containing functions that process timestamps is well explained in these threads:<br />
<a target="_blank" href="http://archives.postgresql.org/pgsql-interfaces/2004-06/msg00045.php"> http://archives.postgresql.org/pgsql-interfaces/&#8230;/msg00045.php</a><br />
<a target="_blank" href="http://www.webservertalk.com/archive307-2007-2-1817943.html"> http://www.webservertalk.com/archive307-2007-2-1817943.html</a><br />
<a target="_blank" href="http://www.mydatabasesupport.com/forums/postgresql/209895-re-date_trunc-d-timestamp-index-possible.html"> http://www.mydatabasesupport.com/forums/&#8230;-possible.html</a></p>
<p>All credit goes to Tom Lane. I admire him for being always so patient and polite, and for spending so much of his valuable time with talking to users. I would love to link to his homepage but I failed to find it.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/254342339" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/</feedburner:origLink></item>
		<item>
		<title>How to concatenate two object attributes and assign the result to a variable</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/254342340/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/how-to-concatenate-two-object-attributes-and-assign-the-result-to-a-variable/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 18:21:25 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Programming Techniques]]></category>

		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2008/03/smarty/how-to-concatenate-two-object-attributes-and-assign-the-result-to-a-variable/</guid>
		<description><![CDATA[All right, this is really no rocket science it&#8217;s just something I needed and took me some time to figure out.



&#123;assign var=&#34;fullName&#34; value=&#34;`$human-&#62;first` `$human-&#62;last`&#34;&#125;



or more robust version:



&#123;capture assign=&#34;fullName&#34;&#125;


&#123;$human-&#62;first&#125; &#123;$human-&#62;last&#125;


&#123;/capture&#125;



]]></description>
			<content:encoded><![CDATA[<p>All right, this is really no rocket science it&#8217;s just something I needed and took me some time to figure out.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><a href="http://smarty.php.net/assign"><span class="kw3">assign</span></a> var=<span class="st0">&quot;fullName&quot;</span> <span class="kw6">value</span>=<span class="st0">&quot;`$human-&gt;first` `$human-&gt;last`&quot;</span><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>or more robust version:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><a href="http://smarty.php.net/capture"><span class="kw1">capture</span></a> <a href="http://smarty.php.net/assign"><span class="kw3">assign</span></a>=<span class="st0">&quot;fullName&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span>$human-&gt;first<span class="br0">&#125;</span> <span class="br0">&#123;</span>$human-&gt;last<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span>/capture<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/254342340" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/how-to-concatenate-two-object-attributes-and-assign-the-result-to-a-variable/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/how-to-concatenate-two-object-attributes-and-assign-the-result-to-a-variable/</feedburner:origLink></item>
		<item>
		<title>How to delete AppSlipRotate.prc and StatusBarLib.prc if you’re stuck in a reset loop</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/254342341/</link>
		<comments>http://blog.pepa.info/php-html-css/palm-os/how-to-delete-appsliprotateprc-and-statusbarlibprc-if-youre-stuck-in-a-reset-loop/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 15:03:08 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Palm OS]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2007/10/palm-os/how-to-delete-appsliprotateprc-and-statusbarlibprc-if-youre-stuck-in-a-reset-loop/</guid>
		<description><![CDATA[I bought Palm TX recently and I&#8217;m still in that period of time when you install new stuff and discover what&#8217;s out there to try. On my old Palm V I loved a text entry application Fitaly. I just had to have it on my new Palm as well.
Although I should have read the manual [...]]]></description>
			<content:encoded><![CDATA[<p>I bought <a target="_blank" href="http://www.palm.com/us/products/handhelds/tx/">Palm TX</a> recently and I&#8217;m still in that period of time when you install new stuff and discover what&#8217;s out there to try. On my old Palm V I loved a text entry application <a target="_blank" href="http://www.fitaly.com/fitalyvirtualt3/fitalyvirtualannounce.htm">Fitaly</a>. I just had to have it on my new Palm as well.</p>
<p><span id="more-12"></span>Although I should have <a target="_blank" href="http://en.wikipedia.org/wiki/RTFM">read the manual</a> I didn&#8217;t and installed AppSlipRotate.prc and StatusBarLib.prc</p>
<p>After Hotsync my Palm went into a never ending reset loop. A <a target="_blank" href="http://kb.palm.com/SRVS/CGI-BIN/WEBCGI.EXE?New,Kb=PalmSupportKB,ts=Palm_External2001,Case=obj(887)">system reset</a> helped with the loop however, my silk screen area and status bar were gray with nothing on them and when I pressed the Applications button I went into reset again.</p>
<p>I found out that I was able to use my Contacts button to launch my Contacts application. I was also able to access Buttons configuration in Settings so I decided to assign a file manager to my Contact button and remove the two troublesome files.</p>
<p>Soon I discovered that I can run only text-based applications which unfortunately excluded <a target="_blank" href="http://www.resco.net/palm/explorer/">Resco Explorer</a> (probably the best file manager out there).<br />
FileZ and LeftOvers were two recommended solutions I found during my search. FileZ caused my Palm to reset immediately, LeftOvers reset after I tried to delete the files.</p>
<p>So I installed <a target="_blank" href="http://www.sra.co.jp/people/hoshi/palmos/pz.html">pz</a>. I couldn&#8217;t directly delete the two files because my Palm would reset each time pz wanted to display a confirmation pop-up window (Are you sure you want to delete&#8230;). I decided to change their file type first, from aexo to something else that won&#8217;t be executed after reset. I must have been something meaningful so I chose panl (Settings panel).</p>
<p>After another system reset I recovered my silk screen and status bar although, normal reset still threw me into a reset loop. This time though, I was able to get past the confirmation pop-up and finally delete the files with pz.</p>
<p>Next reset was really the last reset I had to do. Things are back to normal. Thank the Palm God!</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/254342341" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/palm-os/how-to-delete-appsliprotateprc-and-statusbarlibprc-if-youre-stuck-in-a-reset-loop/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/palm-os/how-to-delete-appsliprotateprc-and-statusbarlibprc-if-youre-stuck-in-a-reset-loop/</feedburner:origLink></item>
		<item>
		<title>Date formatting in Smarty</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/254342342/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/date-formatting-in-smarty/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 21:23:44 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Programming Techniques]]></category>

		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2007/09/programming-techniques/date-formatting-in-smarty/</guid>
		<description><![CDATA[If you use the so called, German date format (day of month. month. year) you may have wondered how to achieve it with Smarty - without the leading zeroes for month.

You all know the common way to format date in Smarty:



&#123;$myDate&#124;date_format:&#34;%e. %m. %Y&#34;&#125;



If you ever wanted to have month number without the leading zeroes, here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If you use the so called, German date format (day of month. month. year) you may have wondered how to achieve it with Smarty - without the leading zeroes for month.<br />
<span id="more-11"></span><br />
You all know the common way to format date in Smarty:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span>$myDate|date_format:<span class="st0">&quot;%e. %m. %Y&quot;</span><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>If you ever wanted to have month number without the leading zeroes, here&#8217;s how:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span>$myDate|date_format:<span class="st0">&quot;%e. %#m. %Y&quot;</span><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>or even a cooler way:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><a href="http://smarty.php.net/assign"><span class="kw3">assign</span></a> var=<span class="st0">&quot;myDateTimestamp&quot;</span> <span class="kw6">value</span>=$myDate|strtotime<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;j. n. Y&quot;</span>|date:$myDateTimestamp<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>(because you can use almost any PHP function as Smarty variable modifier, just solve the parameters-order problem)</p>
<p><strong>Question</strong></p>
<p>Got any better solution? Tell me about it!</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/254342342" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/date-formatting-in-smarty/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/date-formatting-in-smarty/</feedburner:origLink></item>
		<item>
		<title>How to report messages to user</title>
		<link>http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/254342343/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/how-to-report-messages-to-user/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 10:21:45 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
		
		<category><![CDATA[Programming Techniques]]></category>

		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2007/09/uncategorized/how-to-report-messages-to-user/</guid>
		<description><![CDATA[In the course of executing a program you need to report errors / success messages to the user. But you don&#8217;t want to mix your code with HTML, right? (A quick explanation on separating presentation from business / data logic.)
So here&#8217;s what I use:




class MessageStack &#123;


var $_stack = array&#40;&#41;;


&#8230;


/**


* Factory function, ensures that


* MessageStack is [...]]]></description>
			<content:encoded><![CDATA[<p>In the course of executing a program you need to report errors / success messages to the user. But you don&#8217;t want to mix your code with HTML, right? (A <a target="_blank" href="http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=21">quick explanation on separating presentation from business / data logic</a>.)</p>
<p>So here&#8217;s what I use:<br />
<span id="more-9"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> MessageStack <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> <span class="re0">$_stack</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">* Factory function, ensures that</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* MessageStack is a singleton</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> create<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> add<span class="br0">&#40;</span><span class="re0">$type</span>, <span class="re0">$text</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$this</span>-&gt;_stack<span class="br0">&#91;</span><span class="re0">$type</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="re0">$text</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">* Returns stack contents</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> get<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="re0">$this</span>-&gt;_stack;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>When I want to report something I call:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$messageStack</span> = MessageStack::<span class="me2">create</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$messageStack</span>-&gt;<span class="me1">add</span><span class="br0">&#40;</span><span class="st0">&#8216;ok&#8217;</span>, <span class="st0">&#8216;Record saved.&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Then in your main file you run this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$messageStack</span> = MessageStack::<span class="me2">create</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$smarty</span>-&gt;<span class="me1">assign</span><span class="br0">&#40;</span><span class="st0">&quot;messages&quot;</span>, <span class="re0">$messageStack</span>-&gt;<span class="me1">get</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Include this into template (preferably the part that is included into every template):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><a href="http://smarty.php.net/foreach"><span class="kw1">foreach</span></a> <span class="kw6">from</span>=$messages <span class="kw6">key</span>=type <span class="kw6">item</span>=messagesType<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><a href="http://smarty.php.net/section"><span class="kw1">section</span></a> <span class="kw6">name</span>=pc <span class="kw6">loop</span>=$messagesType<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;message <span class="br0">&#123;</span>$type<span class="br0">&#125;</span>&quot;&gt;<span class="br0">&#123;</span>$messagesType<span class="br0">&#91;</span>pc<span class="br0">&#93;</span><span class="br0">&#125;</span>&lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span>/section<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span>/foreach<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And then in css, define all message types:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.message</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">font-weight</span>: <span class="kw2">bold</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">padding</span>: <span class="re3">5px</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="re1">.critical</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background-color</span>: <span class="kw1">black</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">padding</span>: <span class="re3">2px</span> <span class="re3">5px</span> <span class="re3">3px</span> <span class="re3">5px</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">margin</span>: <span class="re3">3px</span> <span class="re3">0px</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><strong>Question</strong></p>
<p>Do you use something like this or something more clever? Share your wisdom :-)</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/254342343" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/how-to-report-messages-to-user/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/how-to-report-messages-to-user/</feedburner:origLink></item>
	</channel>
</rss>
