<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeBlog.ch &#187; PHP</title>
	<atom:link href="http://www.codeblog.ch/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeblog.ch</link>
	<description>Coding and more - Concrete5, Flex, JavaScript</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:10:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>concrete5 SooperFish drop down navigation</title>
		<link>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/</link>
		<comments>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:09:26 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=539</guid>
		<description><![CDATA[Creating a drop down navigation is an old technique by now but it&#8217;s still used in a lot of cases to hide parts of a navigation. In addition to the plain CSS menu I wrote more than 2 years ago, I decided to write a new tutorial which uses JavaScript as well. You might ask [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a drop down navigation is an old technique by now but it&#8217;s still used in a lot of cases to hide parts of a navigation. In addition to the plain CSS menu I wrote more than 2 years ago, I decided to write a new tutorial which uses JavaScript as well. You might ask why: Avoiding JavaScript is nice but creating something as complex as a drop down navigation without any JavaScript leads to a few ugly work arounds. You&#8217;ll also have some difficulties to add a fade out and fade in effect unless you&#8217;re using CSS3 which isn&#8217;t well supported yet.</p>
<p>But at the end it&#8217;s up to you, both solutions can work just fine! </p>
<p>Using SooperFish is also a bit easier for us, you&#8217;ll see at the end of the tutorial how little code you needed.<br />
At the end your navigation can look like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/12/drop-down.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/drop-down.png" alt="" title="drop-down" width="445" height="145" class="alignnone size-full wp-image-540" /></a></p>
<p><span id="more-539"></span></p>
<h2>Prerequisite to create your drop down menu</h2>
<p>It&#8217;s rather simple, the only thing you need is the jQuery drop down plugin called SooperFish. You can find a link to download it on this page: <a href="http://www.sooperthemes.com/open-source/jquery/jquery-sooperfish-dropdown-menus" target="_blank">http://www.sooperthemes.com/open-source/jquery/jquery-sooperfish-dropdown-menus</a>.</p>
<p>Once you&#8217;ve got the ZIP file, extract all the files into a folder of your choice, we&#8217;ll later use some (not all) files from it.</p>
<h2>Creating a new block template</h2>
<p>If you worked with concrete5 before you&#8217;ll probably know that you should never modify any files located in the &#8220;concrete&#8221; directory. It&#8217;s part of the CMS core which gets overwritten whenever you update to a newer version of concrete5. Luckily this isn&#8217;t necessary for lots of things! We can easily create an addon, or a block template in this case, without touching the core at all.</p>
<p>In the root of your website, open the folder called &#8220;blocks&#8221; and go though these steps:</p>
<ul>
<li>Create a folder called &#8220;autonav&#8221;</li>
<li>Within &#8220;autonav&#8221;, create a folder called &#8220;templates&#8221;</li>
<li>Within &#8220;templates&#8221;, create a folder called &#8220;sooperfish&#8221;</li>
<li>In the last directory you created, &#8220;sooperfish&#8221;, create a file called &#8220;view.php&#8221; and put the following content in it:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$bvt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BlockViewTemplate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$bvt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBlockCustomTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> callback<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class=&quot;nav&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class=&quot;sf-menu&quot; id=&quot;nav&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;callback&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bvt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ob_end_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<blockquote>
<h3>Background information about the autonav template view.php</h3>
<p> What does this template do?</p>
<p>Since the HTML structure needed by SooperFish is almost identical with the default autonav template, we don&#8217;t copy the whole template which would create a lot of redundant information. Instead we include the default template in our new template. However, there are still a few things we modified. The original template has an element like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>but we want this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf-menu&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>Having this element allows us to use the default CSS files shipped with the Sooperfish plugin. You could modify the CSS files as well and remove all the output buffering functions in the code above.
</p></blockquote>
<ul>
<li>Create another file in the same directory called &#8220;view.js&#8221; and put this content in it:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.sf-menu'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sooperfish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<ul>
<li>In the directory where you created &#8220;view.php&#8221; and &#8220;view.js&#8221;, create another directory called &#8220;js&#8221;</li>
<li>From the SooperFish ZIP, copy &#8220;jquery.sooperfish.min.js&#8221; and &#8220;jquery.easing-sooper.js&#8221; into the &#8220;js&#8221; directory.</li>
<li>On the same level as &#8220;js&#8221;, create another directory called &#8220;css&#8221;</li>
<li>From the Sooperfish ZIP, copy &#8220;sooperfish.css&#8221; and &#8220;sooperfish-theme-black.css&#8221; into the directory called &#8220;css&#8221;</li>
</ul>
<p>We&#8217;ve already created and copied all the files we need, the only thing we have to do is to make sure our new template is used. Your file structure should look like this now:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2011/12/file-structure.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/file-structure.png" alt="" title="file-structure" width="131" height="129" class="alignnone size-full wp-image-545" /></a></p>
<p>Go to your page and start editing the page and modify the autonav block to make these settings:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/12/autonav-settings.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/autonav-settings-470x400.png" alt="" title="autonav-settings" width="470" height="400" class="alignnone size-medium wp-image-544" /></a></p>
<p>It&#8217;s important that you select &#8220;Display all&#8221; in both &#8220;Sub Pages To Display&#8221; and &#8220;Sub-Page Levels&#8221;. When you work with a JavaScript based navigation you usually print all the items into the HTML output, but hide some of them using JavaScript. Click on Update when you&#8217;re done and click on the block you modified again, but this time select &#8220;Custom Template&#8221; and select &#8220;Sooperfish&#8221; and click on &#8220;Update&#8221; again.</p>
<p>Publish the changes and you&#8217;ll see your new drop down navigation!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=539&amp;md5=efd57ee1e4b77af4c9788a0487dceb10" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>concrete5 &#8211; AJAX Add-on to display File Download Statistics</title>
		<link>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/</link>
		<comments>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 14:53:15 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=504</guid>
		<description><![CDATA[Today&#8217;s article is about concrete5 again after a long time without anything about concrete5 on codeblog.ch. The example we&#8217;re going to look at takes a few ideas and code snippets from my book about concrete5. If you ever had a closer look at the file manager you&#8217;ve probably seen that if you open the file [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s article is about concrete5 again after a long time without anything about concrete5 on codeblog.ch. The example we&#8217;re going to look at takes a few ideas and code snippets from <a href="http://bit.ly/huEpPo">my book about concrete5</a>.</p>
<p>If you ever had a closer look at the file manager you&#8217;ve probably seen that if you open the file properties, you can see a small statistics about the downloads of a file. This is quite nice but what if you wanted to see how many file downloads there are in total? Right now, there&#8217;s no such report available in concrete5 which is why we&#8217;re going to build the first part of such an addon.</p>
<p>It will use some AJAX to switch between different views, allowing us to extend it even further in the future. At the end you&#8217;ll have an additional page in the reports section like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/06/file_download_statistics.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/06/file_download_statistics-500x256.png" alt="" title="file_download_statistics" width="500" height="256" class="alignnone size-medium wp-image-505" /></a></p>
<p><span id="more-504"></span></p>
<p>This article uses a few different elements of concrete5, having some experience with blocks, templates, themes and packages is highly recommended. I&#8217;m not going to explain every detail but I&#8217;m happy to answer questions in case something&#8217;s missing.</p>
<p>First, let&#8217;s have a look at the package installer:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>    
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportPackage <span style="color: #000000; font-weight: bold;">extends</span> Package <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$pkgHandle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'remo_file_report'</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$appVersionRequired</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'5.4'</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$pkgVersion</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPackageDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Adds a file download statistic report&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPackageName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File Report&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> install<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$pkg</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">install</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      Loader<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'single_page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$sp</span> <span style="color: #339933;">=</span> SinglePage<span style="color: #339933;">::</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dashboard/reports/remo_file_report'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pkg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$sp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'File Report'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cDescription'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'File Download Statistic'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see, the package controller is pretty small. Beside the usual package information fields and methods, we only override the install method to add a custom page located at /dashboard/reports/remo_file_report. By adding out page beneath the dashboard reports, we&#8217;ll automatically see our new page as a new register in the dashboard. Nothing else has to be done in order to make sure the page appears where it should.</p>
<h2>Page controller &#038; view</h2>
<p>Since we&#8217;re adding a new page, we&#8217;ll have to add a controller as well as a file for the single page output. First, we create a file in packages/remo_file_report/controllers/dashboard/reports/remo_file_report.php with this content:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DashboardReportsRemoFileReportController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> view<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> on_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHeaderItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">css</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remo.filereport.css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remo_file_report'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHeaderItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">javascript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remo.filereport.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remo_file_report'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Again, this file is small, we only make sure that our CSS and JavaScript file are properly included in the head of the page. If you&#8217;ve created single pages before, you&#8217;ve probably added some code to the view method in order to pass some data to the output of the single page. In our case, this is not necessary since we load our content with the help of AJAX.</p>
<p>Next, create a file for our output packages/remo_file_report/single_pages/dashboard/reports/remo_file_report.php and put this content in it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;h1&gt;&lt;span&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File Download Statistics'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/h1&gt;
&nbsp;
&lt;div class=&quot;ccm-dashboard-inner&quot;&gt;
      &lt;div id=&quot;remo-file-report-links-1&quot;&gt;
      &lt;a href=&quot;#&quot; data-action=&quot;day&quot;   class=&quot;remo-file-report-link&quot; id=&quot;remo-file-report-week&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Day'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
      &lt;a href=&quot;#&quot; data-action=&quot;week&quot;  class=&quot;remo-file-report-link&quot; id=&quot;remo-file-report-week&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Week'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
   &lt;/div&gt;
&nbsp;
   &lt;div id=&quot;remo-file-report-content&quot;&gt;
&nbsp;
   &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Besides a caption and two links to switch between the two views &#8220;day&#8221; and &#8220;week&#8221;, there&#8217;s only an empty DIV element with the id &#8220;remo-file-report-content&#8221; where we&#8217;re going to add some content with the help of a little JavaScript.</p>
<h2>CSS to format File Report</h2>
<p>In the page controller, we&#8217;ve included two files, one for a few basic styles and one for the AJAX logic. Let&#8217;s create the CSS file first at this location packages/remo_file_report/css/remo.filereport.css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#remo-file-report-links-1</span> a <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#remo-file-report-</span><span style="color: #000000; font-weight: bold;">content</span> table <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#remo-file-report-</span><span style="color: #000000; font-weight: bold;">content</span> th <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2>JavaScript and PHP backend file to handle the AJAX procedures</h2>
<p>The next file is the one which holds all the JavaScript and thus the AJAX magic. It has to be created here packages/remo_file_report/js/remo.filereport.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.remo-file-report-link&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>CCM_TOOLS_PATH <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/../packages/remo_file_report/get_data/&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>action<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data-action&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #006600; font-style: italic;">// select the correct renderer to print the data</span>
         <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">data</span>.<span style="color: #660066;">renderer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #339933;">:</span>
               <span style="color: #003366; font-weight: bold;">var</span> rowHeader <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> tableBody <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> rowHeaderPrinted <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// loop through all rows</span>
               <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> rowKey <span style="color: #000066; font-weight: bold;">in</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">tableData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  <span style="color: #003366; font-weight: bold;">var</span> rowData <span style="color: #339933;">=</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">tableData</span><span style="color: #009900;">&#91;</span>rowKey<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
                  tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;tr&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                  <span style="color: #006600; font-style: italic;">// loop through all columns</span>
                  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> colKey <span style="color: #000066; font-weight: bold;">in</span> rowData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>rowHeaderPrinted<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        rowHeader <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;th&gt;&quot;</span> <span style="color: #339933;">+</span> colKey.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'_'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/th&gt;&quot;</span><span style="color: #339933;">;</span> 
                     <span style="color: #009900;">&#125;</span>
&nbsp;
                     tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> rowData<span style="color: #009900;">&#91;</span>colKey<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
                  <span style="color: #009900;">&#125;</span>
                  tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                  rowHeaderPrinted <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// put generated markup in DIV</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#remo-file-report-content&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;table&gt;&lt;tr&gt;&quot;</span> <span style="color: #339933;">+</span> rowHeader <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/tr&gt;&quot;</span> <span style="color: #339933;">+</span> tableBody <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/table&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
               <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Unsupported rendered: &quot;</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">renderer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this file we&#8217;re doing the following things:</p>
<ul>
<li>Set an event which is executed when the user clicks on the links (day or week)</li>
<li>Execute an AJAX call by using <a href="http://api.jquery.com/jQuery.post/" target="_blank">$.post</a></li>
<li>Once we get the result back, we&#8217;re detected the correct rendered. Right now, there&#8217;s just &#8220;table&#8221; but this could be extended to create a different output type like a chart</li>
<li>We then loop though all the data we&#8217;ve gotten from the AJAX tool</li>
<li>Last, we&#8217;re going to add the generated content to our DIV element with the ID remo-file-report-content</li>
</ul>
<p>Our AJAX call uses a file which we&#8217;re accessing using this URL: CCM_TOOLS_PATH + &#8220;/../packages/remo_file_report/get_data/&#8221;. This file is located in the tools folder of our package which is probably the most common way in concrete5 to generate data for an AJAX script. Create a new file at this location packages/remo_file_report/tools/get_data.php and put this content in it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$jh</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Loader<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;remo_file_report&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;remo_file_report&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// make sure the user is allowed to access the file download statistic.</span>
   <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Permissions<span style="color: #009900;">&#40;</span>Page<span style="color: #339933;">::</span><span style="color: #004000;">getByPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/dashboard/reports/remo_file_report'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canRead</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Not allowed to access the JSON tools to fetch the file statistics.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// execute action to get the file download data</span>
   <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$actionObject</span> <span style="color: #339933;">=</span> RemoFileReportModel<span style="color: #339933;">::</span><span style="color: #004000;">getActionInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$actionObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$jh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>What&#8217;s in this file?</p>
<ul>
<li>We load two elements, the <a href="http://www.concrete5.org/api/Helpers/JsonHelper.html">JSON helper</a> because we&#8217;re going to return our data in this format,</li>
<li>the remo_file_report model which is where we put all the database logic</li>
<li>We also make sure that only users who are allowed to access the dashboard page are allowed to use this file. Without this check it would be possible to access our download statistics by using a direct URL, even if one doesn&#8217;t have the permission to do so.</li>
<li>Next, we&#8217;re going to call a method from our model from which we&#8217;ll get all the data</li>
<li>Most of the file has been wrapped in a try&#8230;catch block. This is helpful because if you format data in JSON you won&#8217;t be able to parse the output in your JavaScript if there&#8217;s a PHP error message. By using a try and catch block, we can handle all the possible errors and pass them on to our JavaScript where we can show them to the user</li>
<li>At the end we&#8217;re going to use the JSON helper from concrete5 to return the data echo $jh->encode($ret);</li>
</ul>
<h2>Model to fetch Download Statistics from the database</h2>
<p>The only file that&#8217;s missing now, is the model which we&#8217;re calling from the &#8220;tool&#8221; to get our download statistics out of the database. Create this file packages/remo_file_report/models/remo_file_report.php with this content:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportModel <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getActionInstance<span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'day'</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> RemoFileReportDay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'week'</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> RemoFileReportWeek<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Unsupported action in model remo_file_report.php.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportDay implements IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">db</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'renderer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'table'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tableData'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT fv.fvFilename Filename,count(*) Download_Count
         FROM DownloadStatistics ds INNER JOIN FileVersions fv ON ds.fID=fv.fID AND ds.fvID=fv.fvID
         WHERE date(timestamp) = CURRENT_DATE
         GROUP BY fv.fID, fv.fvID, fv.fvFilename
         ORDER BY count(*) DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportWeek implements IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">db</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'renderer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'table'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tableData'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT fv.fvFilename Filename,count(*) Download_Count
         FROM DownloadStatistics ds INNER JOIN FileVersions fv ON ds.fID=fv.fID AND ds.fvID=fv.fvID
         WHERE YEARWEEK(timestamp) = YEARWEEK(CURRENT_DATE) 
         GROUP BY fv.fID, fv.fvID, fv.fvFilename
         ORDER BY count(*) DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This file is a bit bigger but doesn&#8217;t do a lot at all, what&#8217;s in it?</p>
<ul>
<li>The getActionInstance method in the RemoFileReportModel class simply returns the proper class matching the requested action. Splitting every action into a different class isn&#8217;t necessary but could be helpful once we add more parts to our report</li>
<li>Since we&#8217;ve splitted our actions into classes, we also define an interface to assure that action classes implement the necessary getData method</li>
<li>The two classes RemoFileReportDay and RemoFileReportWeek are almost identical, the just execute a simple SQL command to fetch the data and return it as an array</li>
</ul>
<h2>Download and next steps</h2>
<p>After all these words, you can download the code and extract it to the &#8220;packages&#8221; directory of your concrete5 site and install it by using the &#8220;Add Functionality&#8221; section in the dashboard&#8221;.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2011/06/remo_file_report.zip'>Download File Report Add-On</a></p>
<p>This Add-on isn&#8217;t complete, as you&#8217;ve seen on the screenshot at the beginning of this post, you can&#8217;t find a lot of information in the output. A few things which are missing:</p>
<ul>
<li>Pictures are often helpful to get a first and quick impression, some charts would be nice</li>
<li>Different sections to split information into different parts of the report</li>
<li>Automatically display a statistic, right now you have to click on day or week in order to see something</li>
<li>An export which produces an XLS(X) or PDF report</li>
<li>Some information about the file types maybe</li>
</ul>
<p>And a lot more! I&#8217;m you have a lot of ideas yourself, if you want to add something or have any questions about this code / tutorials, don&#8217;t hesitate to leave a comment!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=504&amp;md5=73871456bfab164a212dbe121f424613" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>concrete5 &#8211; Performance Improvement with Block-Cache</title>
		<link>http://www.codeblog.ch/2011/01/concrete5-performance-improvement-with-block-cache/</link>
		<comments>http://www.codeblog.ch/2011/01/concrete5-performance-improvement-with-block-cache/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 10:07:50 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=478</guid>
		<description><![CDATA[There has been an interesting feature in concrete5 which can improve your sites performance noticeably. If you log in to your site and look at the Sitewide Settings screen, you can see this box: As already mentioned on the screenshot, these settings improve the performance by caching various outputs generated by blocks. In order to [...]]]></description>
			<content:encoded><![CDATA[<p>There has been an interesting feature in concrete5 which can improve your sites performance noticeably. If you log in to your site and look at the <em>Sitewide Settings</em> screen, you can see this box:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/01/cache.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/01/cache-277x400.png" alt="concrete5 full page cache settings" title="concrete5 full page cache settings" width="277" height="400" class="alignnone size-medium wp-image-473" /></a></p>
<p>As already mentioned on the screenshot, these settings improve the performance by caching various outputs generated by blocks. In order to get the most out of your own blocks, you should look into this feature a bit closer. Think about this: How does concrete5 know that the output of a block can be cached? It can&#8217;t!</p>
<h2>Block Cache Options</h2>
<p>If you already created your own blocks in the past, your should be familiar with the <a href="http://www.concrete5.org/api/Blocks/BlockController.html">BlockController</a>. You probably also specified properties like $btTable and $btInterfaceWidth. Now, there are a few more properties you can set. Look at the following start of a BlockController:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MusicBlockController <span style="color: #000000; font-weight: bold;">extends</span> BlockController <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btInterfaceWidth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">450</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btInterfaceHeight</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">430</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'btMusicPlayer'</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btCacheBlockRecord</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btCacheBlockOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btCacheBlockOutputOnPost</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btCacheBlockOutputForRegisteredUsers</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$btCacheBlockOutputLifetime</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 30 minutes</span></pre></div></div>

<p>There are a number of variables starting with btCache. All of them are related to the new cache functionality of concrete5. They let you specify if the content changes once a user is logged in ($btCacheBlockOutputForRegisteredUsers) they let you tell concrete5 if the content stays the same if the page is opened using the POST method allowing the cache to be enabled during a form post too ($btCacheBlockOutputOnPost).</p>
<p>You probably won&#8217;t be able to measure a huge impact if you&#8217;re block doesn&#8217;t have to process lots of data in order to print the output. But if there&#8217;s a complex method in the background of your block you can use these variables to easily control the cache of the output making your site feel faster.</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=478&amp;md5=1658b749801f12639f8fc4d7bf2d948c" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2011/01/concrete5-performance-improvement-with-block-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Using TinyMCE Templates</title>
		<link>http://www.codeblog.ch/2010/06/concrete5-using-tinymce-templates/</link>
		<comments>http://www.codeblog.ch/2010/06/concrete5-using-tinymce-templates/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 08:05:06 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=449</guid>
		<description><![CDATA[The Concrete5 content block uses TinyMCE as its WYSIWYG editor. Thanks to this decision, we are able to use several plugins most Concrete5 users haven&#8217;t thought about. One feature I really like is the &#8220;template&#8221; plugin which allows you to create html snippets which you can insert into the content block. In this tutorial I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>The Concrete5 content block uses TinyMCE as its WYSIWYG editor. Thanks to this decision, we are able to use several plugins most Concrete5 users haven&#8217;t thought about.</p>
<p>One feature I really like is the &#8220;template&#8221; plugin which allows you to create html snippets which you can insert into the content block. In this tutorial I&#8217;m going to show you, how you can create a simple 2 and 3 column table template.</p>
<h2>TinyMCE Configuration</h2>
<p>You&#8217;ll find almost anything you have to know on this page: <a href="http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template">http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template</a>. But luckily for you, I&#8217;m going to make this even easier for you.</p>
<p>First, you have to go to the Dashboard &#8211; Sitewide Settings. In the bottom right corner, you can activate a &#8220;Custom&#8221; configuration for the rich text editor. Once you&#8217;ve enabled it, it will show you some options. What do we need to activate the TinyMCE templates:</p>
<ul>
<li>We have to load the template plugin</li>
<li>There must be a button to display the template dialog</li>
<li>We have to create at least one template</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">theme <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;concrete&quot;</span><span style="color: #339933;">,</span> 
plugins<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;inlinepopups,spellchecker,safari,advlink,template&quot;</span><span style="color: #339933;">,</span>
editor_selector <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ccm-advanced-editor&quot;</span><span style="color: #339933;">,</span>
spellchecker_languages <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;+English=en&quot;</span><span style="color: #339933;">,</span>	
theme_concrete_buttons1 <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;template,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,hr,|,styleselect,formatselect,fontsizeselect&quot;</span><span style="color: #339933;">,</span>
theme_concrete_buttons2 <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,forecolor&quot;</span><span style="color: #339933;">,</span>
theme_concrete_blockformats <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;p,address,pre,h1,h2,h3,div,blockquote,cite&quot;</span><span style="color: #339933;">,</span>
theme_concrete_toolbar_align <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span>
theme_concrete_fonts <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats&quot;</span><span style="color: #339933;">,</span>
theme_concrete_font_sizes <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1,2,3,4,5,6,7&quot;</span><span style="color: #339933;">,</span>
theme_concrete_styles<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Note=ccm-note&quot;</span><span style="color: #339933;">,</span>
spellchecker_languages <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;+English=en&quot;</span><span style="color: #339933;">,</span>
template_templates <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #009900;">&#123;</span>
		title <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2 Columns&quot;</span><span style="color: #339933;">,</span>
		src <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;themes/yourTheme/templates/2_columns.html&quot;</span><span style="color: #339933;">,</span>
		description <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Adds a 2 columns table&quot;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span>
		title <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;3 Columns&quot;</span><span style="color: #339933;">,</span>
		src <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;themes/yourTheme/templates/3_columns.html&quot;</span><span style="color: #339933;">,</span>
		description <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Adds a 3 columns table&quot;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span></pre></div></div>

<p>There&#8217;s one thing you probably have to change. In the two templates I&#8217;ve added, there&#8217;s a hardcoded path which won&#8217;t work on your site. Make sure it points to an existing directory. The content of the html file is rather simple. I modified the example for TinyMCE to make it look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;">&lt;!-- This will not be inserted --&gt;
&lt;div class=&quot;mceTmpl&quot;&gt;
&lt;table width=&quot;98%&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tr&gt;
&lt;th scope=&quot;col&quot;&gt;HEADER 1&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;HEADER 2&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sample Data&lt;/td&gt;
&lt;td&gt;Sample Data&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;</pre></div></div>

<h2>How you can insert an HTML snippet</h2>
<p>You&#8217;re already done, but where can you find the snippets? We you add a new content block, you&#8217;ll see a new button:<br />
<img src="http://www.codeblog.ch/wp-content/uploads/2010/06/template-button-492x400.png" alt="" title="template-button" width="492" height="400" class="alignnone size-medium wp-image-451" /></p>
<p>When you click on this button, you&#8217;ll see a dialog where you can select the template:</p>
<p><img src="http://www.codeblog.ch/wp-content/uploads/2010/06/templates-471x400.png" alt="" title="templates" width="471" height="400" class="alignnone size-medium wp-image-452" /></p>
<p>Unfortunately, the insert button is a bit hidden, you have to scroll down to insert the template. You can insert as many snippets into one content block as you want:</p>
<p><img src="http://www.codeblog.ch/wp-content/uploads/2010/06/content-block-489x400.png" alt="" title="content-block" width="489" height="400" class="alignnone size-medium wp-image-453" /></p>
<p>I hope you like it and thanks for completely reading this tutorial! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2010/06/concrete5-using-tinymce-templates/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Custom 404 page</title>
		<link>http://www.codeblog.ch/2010/01/concrete5-custom-404-page/</link>
		<comments>http://www.codeblog.ch/2010/01/concrete5-custom-404-page/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 11:32:55 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=425</guid>
		<description><![CDATA[It hopefullly doesn&#8217;t happen very often but sometimes a user might enter an address which doesn&#8217;t exist. In most situations a simple page is displayed, telling him that the page doesn&#8217;t exist. Having some more detailled information can be very helpful, especially when you just relaunched your website. Google &#038; Co need a while to [...]]]></description>
			<content:encoded><![CDATA[<p>It hopefullly doesn&#8217;t happen very often but sometimes a user might enter an address which doesn&#8217;t exist. In most situations a simple page is displayed, telling him that the page doesn&#8217;t exist. Having some more detailled information can be very helpful, especially when you just relaunched your website. Google &#038; Co need a while to reindex your page and users will probably see &#8220;page not found&#8221; more frequently than usually.</p>
<p>Concrete5 allows you to customize this page but it needs a few modifications. Some of them are probably a bit hard to find &#8211; which is why I wrote this tutorial. The standard Concrete5 &#8220;page not found&#8221; page looks like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-300x194.png" alt="pagenotfound" title="pagenotfound" width="300" height="194" class="alignnone size-medium wp-image-426" /></a> </p>
<p><span id="more-425"></span></p>
<p>As you can see, the layout uses the default concrete5 dashboard theme. First, we&#8217;d like to use our own theme! Open &#8220;config/site_theme_paths.php&#8221;, there are already a few commented examples in the file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  
&nbsp;
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setThemeByPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/page_not_found'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;yourtheme&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
	you can override system layouts here  - but we're not going to by default 
&nbsp;
	For example: if you would like to theme your login page with the Green Salad theme,
	you would uncomment the lines below and change the second argument of setThemeByPath 
	to be the handle of the the Green Salad theme &quot;greensalad&quot; 
&nbsp;
$v = View::getInstance();
&nbsp;
$v-&gt;setThemeByPath('/login', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/403', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/register', &quot;yourtheme&quot;);
 // $v-&gt;setThemeByPath('/dashboard', &quot;yourtheme&quot;);
&nbsp;
*/</span></pre></td></tr></table></div>

<p>In line 5 and 6 you can see the two lines I&#8217;ve added. Make sure that you replace &#8220;yourtheme&#8221; with the name of your theme &#8211; identical to the directory name of your theme in the folder &#8220;themes&#8221;.</p>
<p>Make sure your theme has a file called view.php. It might look similar to this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elements/header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
 	&lt;div id=&quot;content&quot;&gt;
	   &lt;div id=&quot;body&quot;&gt;
	   	&lt;!-- begin --&gt;
	   	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	   	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$innerContent</span><span style="color: #339933;">;</span>
	   	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	   	&lt;!-- end --&gt;
	   &lt;/div&gt;
	&lt;/div&gt;	
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elements/footer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>$innerContent is where all the information is saved. </p>
<p>Once you&#8217;ve saved site_theme_paths.php your error page uses your own theme. In my case like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-custom.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-custom-300x205.png" alt="pagenotfound-custom" title="pagenotfound-custom" width="300" height="205" class="alignnone size-medium wp-image-429" /></a></p>
<h2>Sitemap</h2>
<p>It might make sense to display a sitemap when a users landed on the 404 page. This is also easy to do. Create a copy of /concrete/single_pages/page_not_found.php here /single_pages/page_not_found.php. This makes sure we don&#8217;t modify files within the Concrete5 core. Open the file and make it look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;h1 class=&quot;error&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Page Not Found'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No page could be found at this address.'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;br/&gt;&lt;br/&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Area<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Main&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;br/&gt;&lt;br/&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$bt</span> <span style="color: #339933;">=</span> BlockType<span style="color: #339933;">::</span><span style="color: #004000;">getByHandle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autonav'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'display_asc'</span><span style="color: #339933;">;</span>                    
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displayPages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'top'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displaySubPages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'all'</span><span style="color: #339933;">;</span>     
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displaySubPageLevels</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'all'</span><span style="color: #339933;">;</span>                    
<span style="color: #000088;">$bt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>		
&nbsp;
&lt;br/&gt;&lt;br/&gt;
&nbsp;
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> DIR_REL<span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Back to Home'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;.</pre></td></tr></table></div>

<p>Lines 13 to 20 uses the autonav block to display a sitemap. That&#8217;s it! In my case the &#8220;page not found&#8221; page looks like this:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-sitemap.png"><img src="http://www.codeblog.ch/wp-content/uploads/2010/01/pagenotfound-sitemap-300x203.png" alt="pagenotfound-sitemap" title="pagenotfound-sitemap" width="300" height="203" class="alignnone size-medium wp-image-432" /></a></p>
<p>A bit useless in my case but probably more helpful if you have more pages than I do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2010/01/concrete5-custom-404-page/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Image Navigation Items</title>
		<link>http://www.codeblog.ch/2009/12/image-navigation-items/</link>
		<comments>http://www.codeblog.ch/2009/12/image-navigation-items/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:01:59 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Autonav]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=405</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve posted the last tutorial. Due to some unexpected events I finally found some time to write a new one. The default autonav Block in Concrete5 allows you to add a navigation/menu to your site in almost no time. But as soon as you want to use images it get [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve posted the last tutorial. Due to some unexpected events I finally found some time to write a new one.</p>
<p>The default autonav Block in Concrete5 allows you to add a navigation/menu to your site in almost no time. But as soon as you want to use images it get a bit more difficult. In this tutorial I&#8217;m going to show you, how you can specify pictures for each page and pull them in an autonav template.</p>
<p><span id="more-405"></span></p>
<h2>Page attributes</h2>
<p>Concrete5 allows you do add different kinds of attributes to your page. You can use them to manage meta tags, tags, notes, thumbnails or images for your navigation. First we have to create two new page attributes where we can select the pictures. One which will be shown if the page is currently active and one for inactive pages.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/1_page_attribute.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/1_page_attribute-300x174.png" alt="1_page_attribute" title="1_page_attribute" width="300" height="174" class="alignnone size-medium wp-image-406" /></a></p>
<p>All the important information has a red overlay:</p>
<ul>
<li>Attribute type must be Image/File</li>
<li>The Handle is used in the template, make sure you remember it</li>
<li>The Name is just a description to explain what the use of the attribute is</li>
</ul>
<h2>Assign images</h2>
<p>We have two new attributes where we can assign some images. The following screenshot explains this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/2_set_pictures.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/2_set_pictures-300x186.png" alt="2_set_pictures" title="2_set_pictures" width="300" height="186" class="alignnone size-medium wp-image-407" /></a></p>
<ul>
<li>In the sitemap, open &#8220;Properties&#8221; for the page where you would like to see an image in the navigation</li>
<li>Go to the last tab &#8220;Custom Fields&#8221; and add the two fields you just created</li>
<li>Select the image you want to see if the page is active and inactive</li>
</ul>
<p>Do this for all the pages where you&#8217;d like to have an image instead of a text link. You can always add and modify the images for the pages. Even your end-user can add new image menu item this way. One of many reasons why page attributes are so powerful!</p>
<h2>Custom Autonav Template</h2>
<p>If you haven&#8217;t worked with custom template you should probably read this tutorial first: <a href="http://www.codeblog.ch/2009/03/concrete5-templates/">http://www.codeblog.ch/2009/03/concrete5-templates/</a>.</p>
<p>To create a new custom template, simply copy /concrete/blocks/autonav/view.php to /blocks/autonav/templates/image_navigation.php. You probably have to create the folders autonav and templates first.</p>
<p>Around line 55 you should see this code (might be different, depending on your c5 version:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-selected nav-path-selected&quot;&gt;&lt;a class=&quot;nav-selected nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$selectedPathCIDs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-path-selected&quot;&gt;&lt;a class=&quot;nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>With some HTML and PHP knowledge you probably have already found the place which outputs the link text. It&#8217;s of course &#8220;$ni->getName()&#8221;. This is the code which we have to modify to display images if they&#8217;ve been selected.</p>
<p>We replace $ni->getName() with variables which will hold the html code for the image or the link text:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$picOn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pic_on'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$picOff</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pic_off'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$picOn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$picOn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; alt=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$picOff</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$picOff</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; alt=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-selected nav-path-selected&quot;&gt;&lt;a class=&quot;nav-selected nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollectionID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$selectedPathCIDs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li class=&quot;nav-path-selected&quot;&gt;&lt;a class=&quot;nav-path-selected&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextActive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;li&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pageLink</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkTextInactive</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>Line 1,2: The new variables</li>
<li>Line 4,5: Get the attribute values &#8211; the image</li>
<li>Line 7-12: Checks if the attribute has a value and replaces the link text</li>
</ul>
<p>Now you can add an autonav block, set all the properties and after you&#8217;ve added the block, click on it again an hit &#8220;Set Custom Template&#8221;. If you create our custom template in the correct folder, you should now be able to select it.</p>
<p>If everything worked you should now have a top navigation like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/12/example.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/12/example-300x165.png" alt="example" title="example" width="300" height="165" class="alignnone size-medium wp-image-417" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2009/12/image-navigation-items/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Formular Layout anpassen</title>
		<link>http://www.codeblog.ch/2009/07/concrete5-form-layout/</link>
		<comments>http://www.codeblog.ch/2009/07/concrete5-form-layout/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 11:12:51 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=368</guid>
		<description><![CDATA[Concrete5 has a nice form block which allows you to create a contact form within a few seconds. You don&#8217;t even need to have any html or php skills to create a simple file upload form. Unfortunately this block isn&#8217;t very easy to style. It uses some html markup which makes it a bit tricky [...]]]></description>
			<content:encoded><![CDATA[<p>Concrete5 has a nice form block which allows you to create a contact form within a few seconds. You don&#8217;t even need to have any html or php skills to create a simple file upload form. Unfortunately this block isn&#8217;t very easy to style. It uses some html markup which makes it a bit tricky to use CSS. However, it doesn&#8217;t mean it&#8217;s impossible! I&#8217;m going to show you how you can easily create a styles form using Concrete5 Custom Templates to produce this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2-300x257.png" alt="Styles Form" title="Styles Form" width="300" height="257" class="alignnone size-medium wp-image-370" /></a></p>
<p><span id="more-368"></span></p>
<h2>Custom Templates</h2>
<p>If you don&#8217;t know anything about &#8220;Custom Templates&#8221;, you should probably read this article first: <a href="http://www.codeblog.ch/2009/03/concrete5-templates/">http://www.codeblog.ch/2009/03/concrete5-templates/</a>. In short: Concrete5 allows you to style any block using templates in case you need to change the html output and not only the css rules.</p>
<h2>Core modification</h2>
<p>There&#8217;s one small thing I didn&#8217;t want to modify in the custom template since it shouldn&#8217;t be printed anyways. This might change in a future version, but because it doesn&#8217;t break anything I&#8217;m going to make the &#8220;not recommendable&#8221; core change in this case. Open the file &#8220;concrete/blocks/form/controller.php&#8221; and go to line 667 as shown on this screenshot:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic1.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic1-300x46.png" alt="pic1" title="pic1" width="300" height="46" class="alignnone size-medium wp-image-369" /></a></p>
<p>Remove &#8216;style=&#8221;width:95%&#8221;&#8216; as it makes css styling a bit nasty. Please note that this step isn&#8217;t necessary, it&#8217;s just about the layout!</p>
<h2>The default layout</h2>
<p>If you create a new form, it usually looks like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic3.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic3-300x167.png" alt="pic3" title="pic3" width="300" height="167" class="alignnone size-medium wp-image-371" /></a></p>
<p>It works but doesn&#8217;t look very nice.</p>
<h2>New form style</h2>
<p>In this tutorial I&#8217;m showing you how you can create a form in which the labels are in the textfields and not on top or left. This might especially be useful if you have a very small page and a huge form. It also looks nice. </p>
<p>This is how the result is going to look like:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/07/pic2-300x257.png" alt="Styles Form" title="Styles Form" width="300" height="257" class="alignnone size-medium wp-image-370" /></a></p>
<p>Let me start with the php template view.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>    
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$survey</span><span style="color: #339933;">=</span><span style="color: #000088;">$controller</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> MiniSurvey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">frontEndMode</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;ccm-form&quot; id=&quot;ccm-form-id-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$invalidIP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;ccm-error&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$invalidIP</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form enctype=&quot;multipart/form-data&quot; id=&quot;miniSurveyView<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;miniSurveyView&quot; method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit_form'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'surveySuccess'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qsid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;msg&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thankyouMsg</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$formResponse</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;msg&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$formResponse</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>  
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$error</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;
'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;input name=&quot;qsID&quot; type=&quot;hidden&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
	&lt;input name=&quot;pURI&quot; type=&quot;hidden&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$pURI</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>   	
	<span style="color: #000088;">$questionsRS</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadQuestions</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #339933;">,</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$surveyBlockInfo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMiniSurveyBlockInfoByQuestionId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$survey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionSetId</span><span style="color: #339933;">,</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bID</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$showEdit</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hideQIDs</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #339933;">=</span><span style="color: #000088;">$questionsRS</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hideQIDs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$msqID</span><span style="color: #339933;">=</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msqID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$requiredClass</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'required'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">' required '</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$requiredSymbol</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'required'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">' *'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;ccm-form-element'</span><span style="color: #339933;">.</span><span style="color: #000088;">$requiredClass</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Question'</span><span style="color: #339933;">.</span><span style="color: #000088;">$msqID</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionRow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$requiredSymbol</span><span style="color: #339933;">;</span>				
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$miniSurvey</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadInputType</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$questionRow</span><span style="color: #339933;">,</span>showEdit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$surveyBlockInfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'displayCaptcha'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
		<span style="color: #000088;">$captcha</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validation/captcha'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>ccm-form-captcha<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div class=&quot;required&quot;&gt;'</span><span style="color: #339933;">;</span>		
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; value=&quot;Sicherheitscode hier eingeben&quot; name=&quot;ccmCaptchaCode&quot; class=&quot;ccm-input-captcha&quot;/&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Please note that we need to style our captcha, we therefore create it manually!</span>
		<span style="color: #666666; font-style: italic;">//$captcha-&gt;showInput();</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$captcha</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input class=&quot;formBlockSubmitButton button&quot; name=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;senden&quot; /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span> 
&lt;/form&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>I&#8217;m not explaing each line because I assume you understand PHP, otherwise this tutorial isn&#8217;t made for you &#8211; sorry!<br />
What I changed:</p>
<ul>
<li>Calling some methods found in the controller out of the view</li>
<li>Created a div layout instead of a table layout</li>
<li>Added some CSS classes to indicate required fields</li>
<li>Added a strange line which makes sure that the value attribute of the textfield contain the description</li>
</ul>
<p>Now, we&#8217;ve got a form where we don&#8217;t have any labels next to the input fields. But we need to get rid of these values at some point, otherwise the users are able to submit forms using the default values (labels). To achieve this, we&#8217;re going to use some JavaScript checks:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span>onLeaveField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>These events get raised once a users clicks into a textfield within our form. There we check whether we have to replace the label or not using this code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> onEnterField<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.formError&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> onLeaveField<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;&amp;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We also add some client side checks to make sure the users has entered all the required fields. This allows us to safe a request and a few milliseconds of waiting.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span>onEnterField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView input[type=text], textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span>onLeaveField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.miniSurveyView'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> formErrors <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.formError'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=text], textarea'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> undefined <span style="color: #339933;">||</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'origLabel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				formErrors<span style="color: #339933;">++;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&lt;div class=&quot;formError&quot; id=&quot;formError'</span><span style="color: #339933;">+</span>formErrors<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; style=&quot;height:18px;color:red;font-size:10px;display:none;&quot;&gt;Bitte Wert eingeben:&lt;/div&gt;
'</span><span style="color: #009900;">&#41;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#formError&quot;</span> <span style="color: #339933;">+</span> formErrors<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>					
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>formErrors <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We check for all fields and make sure the have a value in case they&#8217;re underneath a div with the class &#8220;required&#8221;. We simply display a div above the input fields in case there&#8217;s a value missing.</p>
<p>The template also contains some css rules which I&#8217;m not going to show in this article. They&#8217;re pretty straight forward, but you can also find them here:</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2009/07/codeblog.zip'>Download Form Template</a></p>
<p>Extract the zip into &#8220;blocks/form/templates&#8221;. You might have to create the diretories form and templates first!<br />
Enjoy!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=368&amp;md5=ab0f1c111619bee2053c2c7dd5d45da4" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2009/07/concrete5-form-layout/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Smart text trimming with PHP</title>
		<link>http://www.codeblog.ch/2009/06/smart-text-trimming-with-php/</link>
		<comments>http://www.codeblog.ch/2009/06/smart-text-trimming-with-php/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 12:56:46 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=353</guid>
		<description><![CDATA[Have you ever tried to create a short preview text using PHP? Did you just count the characters and ended up having texts with a completely different width like shown on this picture? This tutorial describes a small method which calculates the real width of a string and lets you create better looking preview texts! [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever tried to create a short preview text using PHP? Did you just count the characters and ended up having texts with a completely different width like shown on this picture?</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/text-trimming.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/text-trimming-300x255.png" alt="text-trimming" title="text-trimming" width="300" height="255" class="alignnone size-medium wp-image-354" /></a></p>
<p>This tutorial describes a small method which calculates the real width of a string and lets you create better looking preview texts!</p>
<p><span id="more-353"></span></p>
<h2>Measuring string width</h2>
<p>PHP offers several methods to measure a string width. You can use the built in method <a target="_blank" href="http://ch2.php.net/manual/en/function.imagefontwidth.php">ImageFontWidth</a> to measure the width of a string using the built in PHP fonts. This is quite easy and works well if you want to create a captcha or something similar, using the PHP fonts.</p>
<p>But there&#8217;s another method which you can easily use to get the complete bounding box of a true type font string. It&#8217;s called <a href="http://ch2.php.net/manual/en/function.imagettfbbox.php">imagettfbbox</a>. The return value is an array which contains several values needed for a bounding box.</h2>
<p>The trimming method</h2>
<p>As you&#8217;ve probably seen on the picure at the beginning of the article, I needed a method that cuts off a string after a certain width and adds a string to indicate that the text isn&#8217;t completely shown. Here&#8217;s some code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span><span style="color: #000088;">$append_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$append_string_box</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagettfbbox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$append_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$append_string_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$append_string_box</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$str_len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$str_len</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$trimmed_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$bounding_box</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagettfbbox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$trimmed_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bounding_box</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$append_string_width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str_to_return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_text_width</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$str_len</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$str_to_return</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$append_string</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str_to_return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$trimmed_text</span> <span style="color: #339933;">=</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span> <span style="color: #000088;">$append_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>$text:<br />
<code>The first parameter is the string which you want to trim</code></p>
<p>$width:<br />
<code>This defines the maximum width of the text in pixels! Not in characters or anything else</code></p>
<p>$font_file:<br />
<code>Here you have to specify the location of your true type font file.</code></p>
<p>$font_size:<br />
<code>The font size you want to use. Please note that unit depends on the version of the GD library you're using. GD1 uses pixels, whereas GD2 uses points</code></p>
<p>$append_string:<br />
<code>An optional string to define the text appended at the end of a trimmed text. By default set to "..."</code></p>
<h2>An example</h2>
<p>You can call the method like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> trim_by_width<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'this is a long text'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/verdana.ttf'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It assumes that the file verdana.ttf is in the same directory as the php script. It will cut the text &#8220;this is a long text&#8221; after 55 pixels.</p>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2009/06/smart-text-trimming-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Concrete5 &#8211; Staff listing with two Columns</title>
		<link>http://www.codeblog.ch/2009/06/concrete5-staff-table/</link>
		<comments>http://www.codeblog.ch/2009/06/concrete5-staff-table/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 10:53:30 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[person]]></category>
		<category><![CDATA[staff]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=334</guid>
		<description><![CDATA[Sometimes content should be presented in two columns. In this tutorial I&#8217;ll describe a possible solution that included a very simple block to display a staff/team member with a description on the right side of it. The result will look like this: Table layouts I&#8217;m not going into the details about tableless layouts, just a [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes content should be presented in two columns. In this tutorial I&#8217;ll describe a possible solution that included a very simple block to display a staff/team member with a description on the right side of it. The result will look like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/staff1.jpg"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/staff1-300x212.jpg" alt="staff1" title="staff1" width="300" height="212" class="alignnone size-medium wp-image-335" /></a></p>
<p><span id="more-334"></span></p>
<h2>Table layouts</h2>
<p>I&#8217;m not going into the details about tableless layouts, just a few basic things. The table tag shouldn&#8217;t be used for a layout, using div &#038; css is the way to go. With Concrete5 you could theoretically create two areas but you would then have the problem that the content in the left column doesn&#8217;t have to same margin to the top as the content in the right.</p>
<p>I&#8217;m therefore describing a block that creates a proper div output which you can style using common css rules.</p>
<h2>The staff block</h2>
<p>The block contains only two elements. A picture and a textfield to enter a little note/description about the person.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/06/staff2.jpg"><img src="http://www.codeblog.ch/wp-content/uploads/2009/06/staff2-294x300.jpg" alt="staff2" title="staff2" width="294" height="300" class="alignnone size-medium wp-image-336" /></a></p>
<p>The html output will look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;ccm-person&quot;&gt;
   &lt;div class=&quot;ccm-person-image&quot;&gt;&lt;img src=&quot;http://myserver/remo.jpg&quot; alt=&quot;&quot;&gt;&lt;/div&gt;
   &lt;div class=&quot;ccm-person-description&quot;&gt;Lorem ipsum dolor sit ame.&lt;/div&gt;
   &lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>Please note that I&#8217;ve added div at the end that uses an inline-style to clear the output. You might want to use a class of your theme but since there&#8217;s no class name that&#8217;s available everything, I&#8217;ve decided to use an inline-style to explain the block!</p>
<p>Without any styling this will generate an output where the text is shown underneath the picture. But since we want to have a table-like layout, we add a few lines to our css file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.ccm-person-image</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ccm-person-description</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">385px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>This is usually specific to your layout, change it to suit your needs!</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2009/06/person.zip'>Download block</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2009/06/concrete5-staff-table/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Concrete5 Templates</title>
		<link>http://www.codeblog.ch/2009/03/concrete5-templates/</link>
		<comments>http://www.codeblog.ch/2009/03/concrete5-templates/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 16:52:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=188</guid>
		<description><![CDATA[Concrete5 Custom Templates DEUTSCH The Content Management System Concrete5 supports custom templates for existing blocks. Using this feature enables you to modify the layout of the core elements, without actually touching the core, which offers you an easy to way to modify your layout if css isn&#8217;t enough. In this tutorial we&#8217;re going to modify [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Concrete5 Custom Templates  <a href="http://www.codeblog.ch/2009/03/concrete5-templates/">DEUTSCH</a></strong></p>
<p>The Content Management System Concrete5 supports custom templates for existing blocks. Using this feature enables you to modify the layout of the core elements, without actually touching the core, which offers you an easy to way to modify your layout if css isn&#8217;t enough.</p>
<p><span id="more-188"></span></p>
<p>In this tutorial we&#8217;re going to modify the &#8220;page list&#8221; block. The page list block is quite handy to create a list of sites. Just add a new sub page and the page list block will display it. Could be used for a news list. I already created a list for this tutorial. It looks like this:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte0.png"><br />
<img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte0-300x201.png" alt="delte1" title="delte1" width="300" height="201" class="alignnone size-medium wp-image-190" /></a></p>
<p>The sites &#8220;Untereite A&#8221; and &#8220;Unterseite B&#8221; should be part of a list. To achieve this, we&#8217;ll add a page list block to the parent page:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte2.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte2-300x201.png" alt="delte2" title="delte2" width="300" height="201" class="alignnone size-medium wp-image-191" /></a></p>
<p>We just created a simple list:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/03/delte3.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/03/delte3-300x201.png" alt="delte3" title="delte3" width="300" height="201" class="alignnone size-medium wp-image-192" /></a></p>
<p>The layout isn&#8217;t perfect, but we can modify the CSS! But what if we want to add a thumbnail? CSS isn&#8217;t enough anymore and we need to create a custom template!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2009/03/concrete5-templates/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

