get_session();
$registry = $appbox->get_registry();
$out = '';
$xmlTopics = null;
$sxTopics = null;
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml'))
$xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml';
if (!$xmlTopics)
{
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml'))
{
$xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics.xml';
}
}
$cssTopics = '';
if ($xmlTopics && ($sxTopics = simplexml_load_file($xmlTopics)))
{
$cssTopics = (string) ($sxTopics->display->css);
}
$out .= '';
$out .='
';
if ($sxTopics)
{
$defaultview = mb_strtolower($sxTopics->display->defaultview);
if (!$defaultview)
$defaultview = 'static';
$out .= ( "
\n");
$out .= self::drawTopics($sxTopics->topics, 0, '', $defaultview);
$out .= ( "\n
\n");
}
$out .= '
';
return $out;
}
public static function topics_exists()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$registry = $appbox->get_registry();
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml'))
return true;
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml'))
return true;
return false;
}
public static function dropdown_topics()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$registry = $appbox->get_registry();
$out = '';
$xmlTopics = '';
$sxTopics = null;
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml'))
$xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml';
if ($xmlTopics == '')
{
if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml'))
{
$xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics.xml';
}
}
if ($xmlTopics == '')
{
return '';
}
$jsTopics = 'null';
$maxdepth = 0;
if (($sxTopics = simplexml_load_file($xmlTopics)))
{
$jsTopics = self::topicsAsJS($sxTopics->topics, 0, $maxdepth);
}
$out .= ' ';
$out .= '
';
return $out;
}
public static function history()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$conn = $appbox->get_connection();
$usr_id = $session->get_usr_id();
$sql = "SELECT query from dsel where usr_id = :usr_id
ORDER BY id DESC LIMIT 0,25";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':usr_id' => $usr_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$history = '';
foreach ($rs as $row)
{
$longueur = strlen($row["query"]);
$history .= '- ' . $row["query"] . '
';
}
$history .= '';
return $history;
}
private static function hastopics(&$topics)
{
foreach ($topics->topics as $subtopic)
return true;
return false;
}
private static function topicsAsJS($topics, $depth, &$maxdepth)
{
if ($depth > $maxdepth)
$maxdepth = $depth;
$t = '';
$tab = str_repeat("\t", $depth);
foreach ($topics->topic as $subtopic)
{
$t .= $t ? "$tab, " : "$tab ";
$t .= '{ ';
$t .= 'label:"' . p4string::MakeString(utf8_decode($subtopic->label), 'js') . '"';
if ($q = $subtopic->query)
{
$q = str_replace(array("\\", "'", "\r", "\n"), array("\\\\", "\\'", "\\r", "\\n"), $subtopic->query);
$t .= ", query:'" . $q . "'";
}
else
{
$t .= ', query:null';
}
if (self::hastopics($subtopic))
{
$t .= ', topics:' . "\n" . self::topicsAsJS($subtopic->topics, $depth + 1, $maxdepth); //, $fullquery) ;
}
else
{
$t .= ', topics:null';
}
$t .= " }\n";
}
return("$tab" . "[\n" . $t . "\n$tab]");
}
private static function drawTopics($topics, $depth=0, $triid='', $defaultview)
{
$n = 0;
$out = '';
foreach ($topics->topic as $subtopic)
{
$tid = $triid . '_' . $n;
$s = $subtopic->label;
$l = p4string::MakeString($s, 'html');
$l = '' . $l . '';
if ($subtopic->query)
{
$q = str_replace(array("\\", "\"", "'", "\r", "\n"), array("\\\\", """, "\\'", "\\r", "\\n"), $subtopic->query);
$q = '' . $l . '';
}
else
{
$q = $l;
}
if (self::hastopics($subtopic))
{
$view = mb_strtolower($subtopic['view']);
if (!$view)
$view = $defaultview;
switch ($view)
{
case 'opened':
$out .= ( '- ' . $q . '
' . "\n");
$out .= ( "\n");
$out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview);
$out .= ( "
\n\n");
break;
case 'closed':
$out .= ( '- ' . $q . '
' . "\n");
$out .= ( "\n");
$out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview);
$out .= ( "
\n\n");
break;
case 'static':
default:
$out .= ( '-   ' . $q . '
' . "\n");
$out .= ( "\n");
$out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview);
$out .= ( "
\n\n");
break;
}
}
else
{
$out .= ( '-   ' . $q . '
' . "\n");
}
$n++;
}
return $out;
}
}