/**
  * Find a template
  *
  * This will look in the module for the specified template to try and find
  * a path to the template. If it cannot be found, each module will be 
  * serched for the file. The the full path to the requested template will
  * be returned.
  * 
  * @param mixed $template Either a template ID or file name
  * @return string The full path to the template including the file name, or false if not found
  */
 public static function findTemplate($template)
 {
     //Make sure $template is a name, not id
     if (is_numeric($template)) {
         $template = self::getTemplateFileName($template);
     }
     $fullPath = false;
     //Check for windows and unix-type full path
     if (stristr('[A-Z]:', $template) !== false) {
         $fullPath = true;
     } else {
         if (substr($template, 0, 1) == '/') {
             $fullPath = true;
         }
     }
     if ($fullPath && file_exists($template)) {
         return $template;
     }
     static $cache = array();
     global $cfg;
     //Check for cached result
     if (isset($cache[$template])) {
         return $cache[$template];
         //if cached, execution stops here
     }
     //Get the module in which the template reisdes
     $module = MVCUtils::getTemplateModule($template);
     //If the template was found in the database then look for it in the
     //module specified in the database.
     if (!is_null($module)) {
         //Generate the path of the template file
         $path = $cfg['general']['toolkitRoot'] . "/{$module}/templates/{$template}";
         $path = realpath($path);
         //Check the template exists where it should
         if (!file_exists($path)) {
             BasicLogger::logMessage("Template '{$template}' could not be found. I was looking here: {$path}", self::module, 'error');
             return false;
         }
         //Cache the return value
         $cache[$template] = $path;
         return $path;
         //If the template was not found in the database then start searching
         //each modules template directory. The is because templates can
         //request to include a file which is not in the database. This could
         //be more efficiet if there was some method of knowing the directory
         //of the parent template, because only that directory would then need
         //to be searched
     } else {
         foreach ($cfg['modules'] as $module) {
             $path = $cfg['general']['toolkitRoot'] . '/' . $module . '/templates/';
             //Convert relative paths to full paths
             $path = realpath($path);
             if (strlen($path) > 0) {
                 //Recursively search the directory
                 $path = self::findFile($path, $template);
                 if ($path !== false) {
                     //cache the return value
                     $cache[$template] = $path;
                     return $path;
                 }
             }
         }
         return false;
     }
     /*
     		
     		//If execution has got this far then the file has not been found
     		
     		BasicLogger::logMessage("Template '$template' could not be found", self::module, 'error');
     		
     		return false;*/
 }