<?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</title>
	<atom:link href="http://www.codeblog.ch/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; improving performance by adding favicon.ico</title>
		<link>http://www.codeblog.ch/2011/09/concrete5-improving-performance-by-adding-favicon-ico/</link>
		<comments>http://www.codeblog.ch/2011/09/concrete5-improving-performance-by-adding-favicon-ico/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 06:23:19 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=528</guid>
		<description><![CDATA[Most browsers are looking for that little favicon to display a 16&#215;16 icon next to the URL in the address bar. How does this work? There are two main ways: They check if a file is available at /favicon.ico They check if a proper link tag has been set:&#60;link rel="shortcut icon" href="http://www.oraclerecipes.com/oraclerecipesicon.ico" /&#62; But what [...]]]></description>
			<content:encoded><![CDATA[<p>Most browsers are looking for that little <a href="http://en.wikipedia.org/wiki/Favicon" target="_blank">favicon</a> to display a 16&#215;16 icon next to the URL in the address bar. How does this work? There are two main ways:</p>
<ul>
<li>They check if a file is available at /favicon.ico</li>
<li>They check if a proper link tag has been set:<code>&lt;link rel="shortcut icon"<br />
 href="http://www.oraclerecipes.com/oraclerecipesicon.ico" /&gt;</code></li>
</ul>
<p>But what happens if you don&#8217;t do anything of the above? The browser will still try to search for favicon.ico. While you don&#8217;t even see that when you open your browsers console, the webserver will notice that. If you check your webservers log file, you&#8217;ll find something like this:</p>
<p><code>www.oraclerecipes.com 88.222.33.111 - - [04/Sep/2011:08:09:23 +0200] "GET /favicon.ico HTTP/1.1" 404 751 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1"</code></p>
<p>The concrete5 URL rewriting rules check if the requested path is a static file but since it doesn&#8217;t exist, the request is forwarded to the dispatcher. This means that concrete5 will search through its database to see if there&#8217;s a concrete5 page available at /favicon.ico but obviously won&#8217;t return anything else but &#8220;Page not found&#8221;. This database lookup can easily consume 100ms which isn&#8217;t a lot but assuming you&#8217;ve got a busy site, this is probably still something you&#8217;d like to get rid! </p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=528&amp;md5=455c17d29bb7cdc8a144f8533f17ef4d" 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/09/concrete5-improving-performance-by-adding-favicon-ico/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle Recipes</title>
		<link>http://www.codeblog.ch/2011/08/oracle-recipes/</link>
		<comments>http://www.codeblog.ch/2011/08/oracle-recipes/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 20:30:47 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=522</guid>
		<description><![CDATA[Despite the fact that most articles on this blog are about concrete5, I mostly work with Oracle and ERP applications with Oracle in the back. In my daily work with Oracle, I often find myself doing more or less the same tasks and sometimes I just want to get that script I wrote a decade [...]]]></description>
			<content:encoded><![CDATA[<p>Despite the fact that most articles on this blog are about concrete5, I mostly work with Oracle and ERP applications with Oracle in the back. In my daily work with Oracle, I often find myself doing more or less the same tasks and sometimes I just want to get that script I wrote a decade ago to finish the task.</p>
<p>It&#8217;s mostly for myself to organize some of my Oracle information but it might get helpful for other people as well.</p>
<p>There&#8217;s not much going on yet but I still launched the site to get some feedback as soon as possible. Check out my new site</p>
<p><a href="http://www.oraclerecipes.com/" target="_blank">http://www.OracleRecipes.com/</a>.</p>
<p><a href="http://www.oraclerecipes.com/" target="_blank"><img src="http://www.codeblog.ch/wp-content/uploads/2011/08/OracleRecipes.png" alt="" title="OracleRecipes" width="467" height="293" class="alignnone size-full wp-image-523" /></a></p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=522&amp;md5=f98719c3a8a7ff601c36e6b49e55327b" 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/08/oracle-recipes/feed/</wfw:commentRss>
		<slash:comments>0</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>Statically linked Linux executables with GCJ, Seed7 and haXe</title>
		<link>http://www.codeblog.ch/2011/06/statically-linked-linux-executables/</link>
		<comments>http://www.codeblog.ch/2011/06/statically-linked-linux-executables/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 19:53:38 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[haXe]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Seed7]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=483</guid>
		<description><![CDATA[While some of you might try to avoid statically linked executables, they can be quite handy. In my case there are situations where I quickly have to run some code on a shared hosting with limited access. Installing libraries isn&#8217;t possible but running binaries is &#8211; at least if you have something like SSH access [...]]]></description>
			<content:encoded><![CDATA[<p>While some of you might try to avoid statically linked executables, they can be quite handy. In my case there are situations where I quickly have to run some code on a shared hosting with limited access. Installing libraries isn&#8217;t possible but running binaries is &#8211; at least if you have something like SSH access like I mostly do.</p>
<p>The exact reasons why I don&#8217;t run a PHP, Ruby or Python script are a bit more difficult. Just believe me that I needed a binary file without the ability to install any additional libraries <img src='http://www.codeblog.ch/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>To do this, I toyed around with a bunch of different languages. This list is certainly not complete but I&#8217;m happy to extend it if you have any suggestions. Please note, I didn&#8217;t include languages like C intentionally because I also didn&#8217;t want to see things like malloc in my code. At this point you probably think that I&#8217;m a rather complicated person and yes, you&#8217;re probably quite right about that.</p>
<p>Enough about that, the first languages/compilers I&#8217;ve had a look at on my Debian box if you following the link..</p>
<p><span id="more-483"></span></p>
<h2>GCJ</h2>
<p>Java is a mature language with great documentation, tuns of tutorials and examples &#8211; certainly good enough to do almost anything one could imagine. The common JRE won&#8217;t work in my case since I&#8217;ve intended to build a static executable.</p>
<p>This is why I&#8217;ve installed GCJ &#8211; the GNU Compiler for Java. This can be done quite easily on Debian with the following command</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> gcj</pre></td></tr></table></div>

<p>A little bit later, everything was installed, ready to create the well known and complicated hello world file hello.java with the following content:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> hello <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello from static executable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A quick look in the documentation shows that as of GCJ version 4.2 there&#8217;s a simplified parameter -static-libgcj which we can use instead of calling gcc with a bunch of different parameters as shown below too. So far everything looked easy.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">gcj hello.java <span style="color: #660033;">-o</span> hello <span style="color: #660033;">--main</span>=hello <span style="color: #660033;">-static-libgcj</span></pre></td></tr></table></div>

<p>The more complicated way before GCJ 4.2:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">gcj <span style="color: #660033;">-c</span> hello.java
gcj <span style="color: #660033;">--main</span>=hello <span style="color: #660033;">-save-temps</span> hello.java
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> hello hello.o hellomain.i <span style="color: #660033;">-shared-libgcc</span> -Wl,-non_shared <span style="color: #660033;">-lgcj</span> -Wl,-call_shared -lsupc++ -Wl,--as-needed <span style="color: #660033;">-lz</span> -lgcc_s <span style="color: #660033;">-lpthread</span> <span style="color: #660033;">-lc</span> <span style="color: #660033;">-lm</span> <span style="color: #660033;">-ldl</span> -Wl,--no-as-needed</pre></td></tr></table></div>

<p>However, when I executed the first command on my Debian I&#8217;ve got an error because libgcj isn&#8217;t available on Debian. I found a few topics about that and didn&#8217;t bother to delve a lot deeper into this when I found a pre compiled version on <a href="http://download.berlin.freifunk.net/sven-ola/freenet/">http://download.berlin.freifunk.net/sven-ola/freenet/</a>.<br />
I quickly downloaded the missing libgcj.a and run the command again.</p>
<p>Voilà, there was an executable without any dependencies. This can be checked with a command like this by the way:</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="bash" style="font-family:monospace;">linuxbox:~<span style="color: #000000; font-weight: bold;">/</span>gcj<span style="color: #666666; font-style: italic;"># readelf -d hello</span>
&nbsp;
Dynamic section at offset 0xb3c848 contains <span style="color: #000000;">28</span> entries:
  Tag        Type                         Name<span style="color: #000000; font-weight: bold;">/</span>Value
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libgcc_s.so.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libm.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libpthread.so.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>librt.so.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libz.so.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libdl.so.2<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libc.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>ld-linux.so.2<span style="color: #7a0874; font-weight: bold;">&#93;</span>
...</pre></td></tr></table></div>

<p>However, I was a bit surprise to see that the file was more than 40MB. This makes sense if you consider that all these Java functionality has been linked into that file, but I don&#8217;t really care, it&#8217;s just a simple hello world and having such big executables on my shared web hosting is a bit too much. There might have been a way to compress that file or remove some unused calls but I wasn&#8217;t in the mood to do that so I moved on to the next language.</p>
<p>UPDATE 08.08.2011: As mentioned by Scott, strip removes quite a lot of stuff from the executable. After running strip, I was able to shrink the file to 34% of its original size:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">linuxbox:~<span style="color: #000000; font-weight: bold;">/</span>gcj<span style="color: #666666; font-style: italic;"># strip hello</span></pre></td></tr></table></div>

<h2>Seed7</h2>
<p><a href="http://seed7.sourceforge.net/">Seed7</a> is not very well known language but if you have a little Pascal, Oberon, PL/SQL background like I do, it will look a bit familiar. The language itself isn&#8217;t difficult to learn, there are now fancy language features, it&#8217;s a nice and simple language. But please note, I&#8217;m not very familiar with Seed7, these are just my first impressions. Happy to take feedback about that!</p>
<p>There wasn&#8217;t a Seed7 Debian package available. I therefore downloaded and compiled everything on my own which is rather easy. There are a lot of releases, you might want to check this page for new versions  <a href="http://sourceforge.net/projects/seed7/files/seed7/">http://sourceforge.net/projects/seed7/files/seed7/</a> and replace the link below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>project<span style="color: #000000; font-weight: bold;">/</span>seed7<span style="color: #000000; font-weight: bold;">/</span>seed7<span style="color: #000000; font-weight: bold;">/</span>seed7_05_20110522<span style="color: #000000; font-weight: bold;">/</span>seed7_05_20110522.tgz?<span style="color: #007800;">r</span>=http<span style="color: #000000; font-weight: bold;">%</span>3A<span style="color: #000000; font-weight: bold;">%</span>2F<span style="color: #000000; font-weight: bold;">%</span>2Fsourceforge.net<span style="color: #000000; font-weight: bold;">%</span>2Fprojects<span style="color: #000000; font-weight: bold;">%</span>2Fseed7<span style="color: #000000; font-weight: bold;">%</span>2Ffiles<span style="color: #000000; font-weight: bold;">%</span>2Fseed7<span style="color: #000000; font-weight: bold;">%</span>2Fseed7_05_20110522<span style="color: #000000; font-weight: bold;">%</span>2F<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">ts</span>=<span style="color: #000000;">1307042936</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">use_mirror</span>=netcologne
<span style="color: #c20cb9; font-weight: bold;">tar</span> xf seed7_05_20110522.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> seed7<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #c20cb9; font-weight: bold;">make</span> depends
<span style="color: #c20cb9; font-weight: bold;">make</span></pre></td></tr></table></div>

<p>Done! There are several examples shipped with the file we&#8217;ve downloaded, let&#8217;s have a look at the first one.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> prg
.<span style="color: #000000; font-weight: bold;">/</span>hi hello.sd7</pre></td></tr></table></div>

<p>This prints &#8220;hello world&#8221; along with some other stuff we don&#8217;t really care about right now. This looks a lot like an interpreter, doesn&#8217;t it? Yes, but there&#8217;s a Seed7 interpreted file which produces C code and automatically calls GCC. Let&#8217;s try this as well:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>hi comp.sd7 hello.sd7 <span style="color: #660033;">-O2</span>
.<span style="color: #000000; font-weight: bold;">/</span>hello</pre></td></tr></table></div>

<p>As Sven pointed out, if you add -O2 the resulting exe will be a bit smaller. In my case the file was 365KB, compared to 461kb without -O2 in size and has a dependency on X11 and ncurses which we can see if we run &#8220;readelf&#8221; again:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">linuxbox:~<span style="color: #000000; font-weight: bold;">/</span>seed7<span style="color: #000000; font-weight: bold;">/</span>seed7<span style="color: #000000; font-weight: bold;">/</span>prg<span style="color: #666666; font-style: italic;"># readelf -d hello</span>
&nbsp;
Dynamic section at offset 0x28014 contains <span style="color: #000000;">24</span> entries:
  Tag        Type                         Name<span style="color: #000000; font-weight: bold;">/</span>Value
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libX11.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libncurses.so.5<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libm.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libc.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 ...</pre></td></tr></table></div>

<p>This looks quite good so far but since Seed7 isn&#8217;t very popular, you might have some difficulties finding tutorials, examples, libraries etc. As Sven mentioned too, there are several libraries Seed7 available on this page <a href="http://seed7.sourceforge.net/libraries/">http://seed7.sourceforge.net/libraries/</a>. I couldn&#8217;t find a lot of examples at first and I still get the impression that most of these libraries haven&#8217;t been widely used yet. I quickly tried to implement a small socket server but stopped when I couldn&#8217;t find any kind of &#8220;select&#8221; method to handle multiple clients the way I want. However, I got a message to Thomas Mertens, the author of Seed7, which caused me to have a third look at Seed7. It&#8217;s important to know that you get several examples when you download Seed7. Among others, there&#8217;s a small webserver as well a basic interpreter which impressed me quite a bit.</p>
<p>Seed7 might still need some popularity but it seems to be quite solid and well thoughout. I also found this page <a href="http://rosettacode.org/wiki/Seed7">http://rosettacode.org/wiki/Seed7</a> which helped me a lot since I was able to compare different languages to Seed7 and get a first impression on how I can implement a few basic things in Seed7.</p>
<p>In my case Seed7 would actually have worked, but just for the fun of it I wanted to try something else, next language!</p>
<h2>haXe</h2>
<p><a href="http://haxe.org/">haXe</a> is also a relatively new language. haXe is a so called multiplatform language which targets different platforms like JavaScript, Flash, NekoVM, PHP, C++, C# and Java. Quite an impressive list I&#8217;d say but unfortunately most of them are still in work which is why you might run into some issues.</p>
<p>The syntax looks a lot like Java, C# and easy to learn for people who have some experience with such languages. Since I&#8217;m trying to build a statically linked executable I went for the C++ target. I&#8217;ll save you the time, there&#8217;s a pre built package available for Debian but hxcpp doesn&#8217;t seem to work with it right now. But don&#8217;t worry, building from source is very easy:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>haxe.org<span style="color: #000000; font-weight: bold;">/</span>file<span style="color: #000000; font-weight: bold;">/</span>hxinst-linux.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> cf hxinst-linux.tgz
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x hxinst-linux
.<span style="color: #000000; font-weight: bold;">/</span>hxinst-linux
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>haxe<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
haxelib setup
haxelib <span style="color: #c20cb9; font-weight: bold;">install</span> hxcpp</pre></td></tr></table></div>

<p>This downloaded and installed haXe, installed the libraries and also installed the hxcpp target by using haxelib. haxelib seems to be the tool which you can use to install, upgrade your haXe tools and a few more things. It&#8217;s very intuitive to use, a bit like RubyGems or PECL for PHP.</p>
<p>Let&#8217;s create our first haXe hello world file &#8220;Test.hx&#8221;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> function main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        trace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World !&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When then create a file called compile.hxml which we&#8217;re going to use to build the executable:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">-cpp</span> <span style="color: #c20cb9; font-weight: bold;">cpp</span>
<span style="color: #660033;">-debug</span>
<span style="color: #660033;">-main</span> Test</pre></td></tr></table></div>

<p>Last but not least, we&#8217;re going to build our executable by running:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">haxe compile.hxml</pre></td></tr></table></div>

<p>A bit later we&#8217;ll find an executable called &#8220;Test&#8221; in the subdirectory &#8220;cpp&#8221;. It&#8217;s only about 200KB and doesn&#8217;t have any fancy libraries included:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">linuxbox:~<span style="color: #000000; font-weight: bold;">/</span>haxe<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">cpp</span><span style="color: #666666; font-style: italic;"># readelf -d Test</span>
&nbsp;
Dynamic section at offset 0x358a0 contains <span style="color: #000000;">26</span> entries:
  Tag        Type                         Name<span style="color: #000000; font-weight: bold;">/</span>Value
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libpthread.so.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libdl.so.2<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libstdc++.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libm.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libgcc_s.so.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
 0x00000001 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NEEDED<span style="color: #7a0874; font-weight: bold;">&#41;</span>                     Shared library: <span style="color: #7a0874; font-weight: bold;">&#91;</span>libc.so.6<span style="color: #7a0874; font-weight: bold;">&#93;</span>
...</pre></td></tr></table></div>

<p>haXe seems like a very interesting concept, as with all new things, there aren&#8217;t too many tutorials or examples around. The forum is also not very active, most of the discussion seems to be in the mailing list. haXe also seems to be a possible choice, I&#8217;m just a bit worried that I might run into some issues which haven&#8217;t been solved yet. Supporting a language with so many different targets isn&#8217;t easy and attracts all kinds of needs.</p>
<p>I&#8217;ll probably try to build a few things with haXe and see where it goes.</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=483&amp;md5=679afe0bc98f4dcccc63e3920acc13a1" 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/statically-linked-linux-executables/feed/</wfw:commentRss>
		<slash:comments>6</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>Remote Lock Computer</title>
		<link>http://www.codeblog.ch/2010/12/remote-lock-computer/</link>
		<comments>http://www.codeblog.ch/2010/12/remote-lock-computer/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 16:40:38 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Microsoft.NET]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=463</guid>
		<description><![CDATA[If you work at home using remote control tools you might have had troubles accessing your computer if the connection has been dropped. Some remote control tools like RDP or Unicenter Remote Control will only allow you to access the computer if it&#8217;s locked. Something which usually makes sense but can be annoying if you [...]]]></description>
			<content:encoded><![CDATA[<p>If you work at home using remote control tools you might have had troubles accessing your computer if the connection has been dropped. Some remote control tools like RDP or Unicenter Remote Control will only allow you to access the computer if it&#8217;s locked. Something which usually makes sense but can be annoying if you lose the connection or if the remote control tool crashes.</p>
<p>There are some VB Scripts out there which you can use to lock the computer from another computer. They work but aren&#8217;t really nice as the have to copy a file to the computer you&#8217;re trying to lock. You also don&#8217;t have a nice interface and sometimes you even have to create some files manually. Not really userfriendly, something which might annoy you &#8211; especially if you just lost your internet connection.</p>
<p><img src="http://www.codeblog.ch/wp-content/uploads/2010/12/remote-lock.png" alt="" title="remote-lock" width="290" height="219" class="alignnone size-full wp-image-465" /></p>
<p>I did some quick work and came up with a rather small C# tool which uses WMI to execute a remote command. There&#8217;s a command you can execute to lock your local computer, just hit Windows+R (or click on Start and select Run) and enter this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rundll32 user32.dll,LockWorkStation</pre></div></div>

<p>Once it has been executed, your computer will be locked and ready for remote access. I only created a small interface which combines WMI and this rundll32 command to make the process of locking a computer in your network a bit easier. Please note, you&#8217;ll need plenty of permissions. I&#8217;m not 100% sure but I think the impersonate option I&#8217;m using will only work if you&#8217;re a domain admin. Enough talking, here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Management</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> RemoteLock
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MainForm <span style="color: #008000;">:</span> Form
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> MainForm<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> btnClose_Click<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Application<span style="color: #008000;">.</span><span style="color: #0000FF;">Exit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> btnLock_Click<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            ConnectionOptions connOptions <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ConnectionOptions<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            connOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Impersonation</span> <span style="color: #008000;">=</span> ImpersonationLevel<span style="color: #008000;">.</span><span style="color: #0000FF;">Impersonate</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>txtUsername<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">!=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span> <span style="color: #008000;">&amp;&amp;</span> txtPassword<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">!=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                connOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Username</span> <span style="color: #008000;">=</span> txtUsername<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
                connOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Password</span> <span style="color: #008000;">=</span> txtPassword<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            connOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">EnablePrivileges</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
            ManagementScope managementScope <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ManagementScope<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;<span style="color: #008080; font-weight: bold;">\\</span>{0}\ROOT\CIMV2&quot;</span>, txtComputer<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">&#41;</span>, connOptions<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            managementScope<span style="color: #008000;">.</span><span style="color: #0000FF;">Connect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ObjectGetOptions objectGetOptions <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ObjectGetOptions<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ManagementPath managementPath <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ManagementPath<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Win32_Process&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ManagementClass processClass <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ManagementClass<span style="color: #008000;">&#40;</span>managementScope, managementPath, objectGetOptions<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ManagementBaseObject inParameters <span style="color: #008000;">=</span> processClass<span style="color: #008000;">.</span><span style="color: #0000FF;">GetMethodParameters</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Create&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            inParameters<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CommandLine&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;rundll32 user32.dll,LockWorkStation&quot;</span><span style="color: #008000;">;</span>
            ManagementBaseObject outParameters <span style="color: #008000;">=</span> processClass<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMethod</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Create&quot;</span>, inParameters, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;WMI process created, return value: &quot;</span> <span style="color: #008000;">+</span> outParameters<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;returnValue&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The project should compile just fine if you open the sln file using the free <a href="http://www.microsoft.com/express/Downloads/">Microsoft Visual C# Express 2010 edition</a>. There&#8217;s a binary file in the zip file for those who don&#8217;t have the time or interest to compile the project on their own. The code is free, improve it, copy it, trash it.. I&#8217;d only appreciate if I&#8217;d get some credits for it!</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2010/12/RemoteLock.zip'>Download RemoteLock</a></p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=463&amp;md5=8a283d69a7e274214399574bbff9897d" 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/2010/12/remote-lock-computer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Concrete5 Beginner&#8217;s Guide</title>
		<link>http://www.codeblog.ch/2010/12/concrete5-beginners-guide-book/</link>
		<comments>http://www.codeblog.ch/2010/12/concrete5-beginners-guide-book/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:25:14 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=457</guid>
		<description><![CDATA[No posts for quite some time on this blog! I don&#8217;t have a new tutorial at the moment, but I still have an explanation and something exciting to tell you! Some of you guys sent me messages telling me that they wish I&#8217;d still be as active in the Concrete5 community as I was a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.packtpub.com/create-and-customize-your-own-website-with-concrete5-beginners-guide/book"><img src="https://www.packtpub.com/sites/default/files/imagecache/productview/4286OS_concrete5%20Beginner's%20Guidecov.jpg" alt="Concrete5 Beginner's Guide" align="left"/></a> No posts for quite some time on this blog! I don&#8217;t have a new tutorial at the moment, but I still have an explanation and something exciting to tell you!</p>
<p>Some of you guys sent me messages telling me that they wish I&#8217;d still be as active in the Concrete5 community as I was a while ago. I was really great to hear that, it&#8217;s always good to know that someone appreciates your work. However, truth is, I&#8217;m still quite active, just not so much in the forums &#8211; there&#8217;s a good reason or two for that!</p>
<p>First, I have been rather busy doing Oracle and ERP related work which has nothing to do with Concrete5 at all. However, I&#8217;ve been spending quite a few evenings, nights and weekends working on a huge tutorial about Concrete5, more like a &#8220;book&#8221;! I was contacted by <a href="https://www.packtpub.com/">Packt Publishing</a> in June and stared writing shortly after that. I&#8217;m currently working on the drafts of the last chapters, I&#8217;ll then go through the reviews and after that the people are Packt are going to make sure that everything looks and reads smoothly. However, you can already get access to the first chapters because the book has been accepted as a RAW book, just have a look at <a href="https://www.packtpub.com/create-and-customize-your-own-website-with-concrete5-beginners-guide/book">https://www.packtpub.com/create-and-customize-your-own-website-with-concrete5-beginners-guide/book</a>. You&#8217;ll get access to each chapter as it gets written in an unfinished state.</p>
<p>The book is aimed for people knowing web technologies like PHP, JavaScript, HTML and CSS but without Concrete5 experience. It starts rather easy, for some of you too easy I assume but different readers, different skills. It the continues with a custom theme and lots of custom templates for some Concrete5 core blocks. We then look at building blocks, packages and a simple dashboard extension which allows you to have a look and modify your files on the server. Making it easier (and a bit dangerous) to quickly modify your Concrete5 configuration or theme files if you&#8217;re out on business without having the FTP credentials with you.</p>
<p>I hope you like it! The final and printed book is expected to be available in April!</p>
<h2>Writing a Book</h2>
<p>A few words about my experience writing a book. First of all, I had quite a few doubts, especially since English is not exactly my first language. I knew that I could explain myself in English in a way most people understand what I&#8217;m trying to say but still.. The people at Packt convinced me that this is not going to be a problem, especially since you never write a book which gets printed without having someone else having a look at it.</p>
<p>After my first doubts, things started very quickly and have gotten a bit stressful from time to time. There&#8217;s a deadline for each chapter to assure that everyone involved in the project is able to do their part in time. Working on a book like I do isn&#8217;t a fulltime job, for most authors at Packt it&#8217;s an evening and weekend job. This makes it sometimes a bit hard to meet all the deadlines with the result that things can be a bit stressful, especially if some unexpected things happen, at work or in your personal life. Nonetheless, I think it&#8217;s absolutely worth the effort, the imagination of finding your own book in your postbox or your favorite bookstore is awesome and drives you to keep working on the book.</p>
<p>Having a tight deadline for every chapter can also be really helpful, especially if you&#8217;re a bit like me. Whatever I do, I&#8217;d like to spend as much time on it as possible to get the best result possible. It also doesn&#8217;t happen very often that I think something is perfect&#8230; No matter what I do, having a limited amount of time is beneficial. Whenver I wrote a tutorial I told someone that it&#8217;s going to be online the next day and it usually was. Being on time is rather important, probably a disease I&#8217;ve got due to the fact that I&#8217;m Swiss. It&#8217;s pretty much the same with the book, you start writing on a chapter and the closer you get to meet the deadline, the more stressful things are but you feel reliefed once you&#8217;ve sent the mail, even if you don&#8217;t think your work&#8217;s as good as it should be.</p>
<p>If you ever get the chance to write a book, make sure you like writing, make sure you have some time or be prepared to sleep less <img src='http://www.codeblog.ch/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  It&#8217;s a great experience!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=457&amp;md5=a2d4d095b174b0c1e610135d31e68fde" 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/2010/12/concrete5-beginners-guide-book/feed/</wfw:commentRss>
		<slash:comments>24</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>Linux Shell in a Browser</title>
		<link>http://www.codeblog.ch/2010/02/linux-shell-in-a-browser/</link>
		<comments>http://www.codeblog.ch/2010/02/linux-shell-in-a-browser/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 12:37:43 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=440</guid>
		<description><![CDATA[If you&#8217;re a *unix admin you probably like SSH a lot. Even if you have to work on a Windows computer you can simply download a small tool like Putty and you&#8217;re ready to work on your server. However, there are situations where not even Putty works &#8211; if you&#8217;re behind a firewall that filters [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a *unix admin you probably like SSH a lot. Even if you have to work on a Windows computer you can simply download a small tool like <a href="http://putty.very.rulez.org/download.html">Putty</a> and you&#8217;re ready to work on your server. However, there are situations where not even Putty works &#8211; if you&#8217;re behind a firewall that filters the outgoing traffic as well. It usually makes sense to block outgoing SSH traffic in a big company because you could easily create an encrypted tunnel to move secret data to any server you want.</p>
<p>But there&#8217;s another way to access your server using SSH like tools without having to worry about encrypted tunnels or any other threats SSH could cause. It&#8217;s called <a href="http://code.google.com/p/shellinabox/">shellinabox</a> and can be found on Google Code.</p>
<p>If you&#8217;re working with debian like I do, you can even download a prebuilt deb file.<br />
<code lang="bash">wget http://shellinabox.googlecode.com/files/shellinabox_2.10-1_i386.deb<br />
dpkg -i shellinabox_2.10-1_i386.deb</code></p>
<p>The installer creates an init script located in /etc/init.d/shellinabox. As soon as it has been started you can access your shell using any webbrowser using an address like this: https://localhost:4200. But the port 4200 is usually not accessible if you&#8217;re working behind a firewall that blocks SSH traffic. Let&#8217;s use apache to redirect traffic from HTTPS to 4200. We have to enable mod_proxy if it&#8217;s not already active:</p>
<p><code lang="bash">/etc/apache2/mods-enabled<br />
ln -s ../mods-available/proxy.conf<br />
ln -s ../mods-available/proxy.load<br />
ln -s ../mods-available/proxy_http.load</code></p>
<p>Edit the site file where you want to add your shell, I used /etc/apache2/sites-available/default-ssl and added these lines:<br />
<code lang="bash">&lt;Location /shell&gt;<br />
ProxyPass	http://localhost:4200/<br />
Order 	allow,deny<br />
Allow	from all<br />
&lt;/Location&gt;</code></p>
<p>Shellinabox uses https by default as well and is accessible by any ip address. We want to change that, let&#8217;s edit this file /etc/init.d/shellinabox and add SHELLINABOX_ARGS (the last line in the following box):<br />
<code># Set some default values<br />
SHELLINABOX_DATADIR="${SHELLINABOX_DATADIR:-/var/lib/shellinabox}"<br />
SHELLINABOX_PORT="${SHELLINABOX_PORT:-4200}"<br />
SHELLINABOX_USER="${SHELLINABOX_USER:-shellinabox}"<br />
SHELLINABOX_GROUP="${SHELLINABOX_GROUP:-shellinabox}"<br />
SHELLINABOX_ARGS="--localhost-only --disable-ssl"</code></p>
<p>If you now restart all the services &#8220;/etc/init.d/shellinabox restart&#8221; and /etc/init.d/apache2 restart&#8221;, you&#8217;re shell can be accessed by https://localhost/shell from anywhere you want!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2010/02/linux-shell-in-a-browser/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

