usr_i18n.'.xml') )
$xmlTopics = GV_RootPath.'config/topics/topics_'.$session->usr_i18n.'.xml';
if(!$xmlTopics)
{
if( file_exists(GV_RootPath.'config/topics/topics.xml') )
{
$xmlTopics = 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()
{
$session = session::getInstance();
if( file_exists(GV_RootPath.'config/topics/topics_'.$session->usr_i18n.'.xml') )
return true;
if( file_exists(GV_RootPath.'config/topics/topics.xml') )
return true;
return false;
}
public static function dropdown_topics()
{
$session = session::getInstance();
$out = '';
$xmlTopics = '';
$sxTopics = null;
if( file_exists(GV_RootPath.'config/topics/topics_'.$session->usr_i18n.'.xml') )
$xmlTopics = GV_RootPath.'config/topics/topics_'.$session->usr_i18n.'.xml';
if($xmlTopics == '')
{
if( file_exists(GV_RootPath.'config/topics/topics.xml') )
{
$xmlTopics = 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()
{
$conn = connection::getInstance();
$session = session::getInstance();
$usr_id = $session->usr_id;
$sql = "SELECT query from dsel where usr_id='" . $conn->escape_string($usr_id). "' ORDER BY id DESC LIMIT 0,25";
$history = '';
if($rs = $conn->query($sql))
{
while($row = $conn->fetch_assoc($rs))
{
$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;
}
}