view compos.inc.php @ 120:2c594958050e

Make test vote keys "testN" where N >= 1
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Oct 2013 14:22:26 +0300
parents 5bc8bd5c7ecc
children 0980e705dea0
line wrap: on
line source

<?
echo stGetSetting("compoDescription");

function stConvSwitchMode(&$str, &$mode, $newMode)
{
  if ($newMode != $mode)
  {
    if ($mode != "")
      $str .= "\n</".$mode.">\n";

    $mode = $newMode;

    if ($mode != "")
      $str .= "<".$mode.">\n";
  }
}


function stConvertCompoDesc($desc)
{
  global $stDescConversion;
  $str = "";
  $mode = "";

  foreach (explode("\n", $desc) as $line)
  {
    if (preg_match("/^\s*\s*\*(.+)$/", $line, $m))
    {
      stConvSwitchMode($str, $mode, "ol");
      $str .= "<li>".$m[1]."</li>\n";
    }
    else
    if (preg_match("/^\s*-\s*(.+)$/", $line, $m))
    {
      stConvSwitchMode($str, $mode, "ul");
      $str .= "<li>".$m[1]."</li>\n";
    }
    else
    {
      stConvSwitchMode($str, $mode, "p");
      $str .= $line;
    }
  }

  stConvSwitchMode($str, $mode, "");

  return $str;
}

$sql = "SELECT * FROM compos WHERE visible<>0 ORDER BY id ASC";

if (($res = stExecSQL($sql)) !== FALSE)
{
  foreach ($res as $item)
  {
    echo
    "<div id=\"compo".$item["id"]."\">\n".
    "<h2>".chentities($item["name"])."</h2>\n".
    stConvertCompoDesc($item["description"]).
    "</div>\n";
  }
}
?>