<?php
/**
 * @package linea21.core
 * @subpackage public
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

/**
 * DisplayFilter()
 * Call specific filters functions
 * filters are defined in config/define_globals.php
 * filters methods are declared in this file.
 * @return void
 */
function DisplayFilter() {

  $content='';
  if(is_array($GLOBALS['filters'][LANGUAGE])) {
    $bool = (in_array(1, array_values($GLOBALS['filters'][LANGUAGE]))) ? true : false;
    if($bool) echo '<div id="filtercontent">'.END_LINE;
    while (list($key,$value) = each ($GLOBALS['filters'][LANGUAGE])) {
      if($value['active'] == 1 && function_exists('Get'.ucfirst($key).'Filter')) {
        eval('Get'.ucfirst($key).'Filter();');
      }
    }
    if($bool) echo '</div>'.END_LINE;
  }
}

/**
 * GetPriorityFilter()
 * Display a list of priorities
 * as filter criteria
 * @return void
 */
function GetPriorityFilter() {
  $result=$GLOBALS['sql_object']->DBSelect(SQL_Get_FilterPriority());
  $list="<div id=\"filterpriority\">".END_LINE;
  $list.= "<p>".$GLOBALS['lang']['divers']['priority_choice']."</p>".END_LINE;
  $list.= "<ul>".END_LINE;
  $item_active=ActiveItemAlias($GLOBALS['activeitem']);
  for ($i=0;$i<count($result);$i++){
    $name=formatText(cutText($result[$i]['priority_name'],50), '2HTML');
    if(array_key_exists('filter', $_REQUEST) && $_REQUEST['filter']==$GLOBALS['filters'][LANGUAGE]['priority']['linkvalue'] && $_REQUEST['id']==$result[$i]['priority_id']) {
      $list.="<li>".$name."</li>".END_LINE;
    } else {
      $url = array('rub' => $GLOBALS['links'][LANGUAGE][$item_active]['linkvalue'], 'filter' => $GLOBALS['filters'][LANGUAGE]['priority']['linkvalue'], 'id' => $result[$i]['priority_id'], 'name'=> $result[$i]['priority_name']);
      $list.="<li><a href=\"".Hrefmaker($url)."\" title=\"".$GLOBALS['filters'][LANGUAGE]['priority']['desc'].' : '.$name."\">".$name."</a></li>".END_LINE;
    }
  }
  $list.="</ul></div>".END_LINE;
  echo $list;

}
/**
 * GetThemeFilter()
 * Display a list of themes
 * as filter criteria
 * @return void
 */
function GetThemeFilter() {
  $result_sdtheme=$GLOBALS['sql_object']->DBSelect(SQL_Get_FilterTheme());
  $sdtheme_list="<div id=\"filtertheme\">".END_LINE;
  $sdtheme_list.= "<p>".$GLOBALS['lang']['divers']['themeref_choice']."</p>".END_LINE;
  $sdtheme_list.= "<ul>".END_LINE;
  $item_active=ActiveItemAlias($GLOBALS['activeitem']);
  for ($i=0;$i<count($result_sdtheme);$i++){
    $sdtheme_display=formatText(cutText($result_sdtheme[$i]['sdtheme_name'],50), '2HTML');
    if(array_key_exists('filter', $_REQUEST) && $_REQUEST['filter']==$GLOBALS['filters'][LANGUAGE]['theme']['linkvalue'] && $_REQUEST['id']==$result_sdtheme[$i]['sdtheme_id']) {
      $sdtheme_list.="<li>".$sdtheme_display."</li>".END_LINE;
    } else {
      $URLtheme = array('rub' => $GLOBALS['links'][LANGUAGE][$item_active]['linkvalue'], 'filter' => $GLOBALS['filters'][LANGUAGE]['theme']['linkvalue'], 'id' => $result_sdtheme[$i]['sdtheme_id'], 'name'=> $result_sdtheme[$i]['sdtheme_name']);
      $sdtheme_list.="<li><a href=\"".Hrefmaker($URLtheme)."\" title=\"".$GLOBALS['filters'][LANGUAGE]['theme']['desc'].' : '.$sdtheme_display."\">".$sdtheme_display."</a></li>".END_LINE;
    }
  }
  $sdtheme_list.="</ul></div>".END_LINE;
  echo $sdtheme_list;
}

/**
 * GetLevelFilter()
 * Display a list of levels
 * as filter criteria
 * @return string
 */
function GetLevelFilter() {
  $result_level=$GLOBALS['sql_object']->DBSelect(SQL_Get_FilterLevel());
  $level_list="<div id=\"filterlevel\">".END_LINE;
  $level_list.="<p>".$GLOBALS['lang']['divers']['level_choice']."</p>".END_LINE;
  $level_list.="<ul>".END_LINE;
  $item_active=ActiveItemAlias($GLOBALS['activeitem']);
  for ($i=0;$i<count($result_level);$i++){
    $level_display=formatText(cutText($result_level[$i]['level_name'],50), '2HTML');
    if(array_key_exists('filter', $_REQUEST) && $_REQUEST['filter']==$GLOBALS['filters'][LANGUAGE]['level']['linkvalue'] && $_REQUEST['id']==$result_level[$i]['level_id']) {
      $level_list.="<li>".$level_display."</li>".END_LINE;
    } else {
      $URLlevel= array('rub' => $GLOBALS['links'][LANGUAGE][$item_active]['linkvalue'], 'filter' => $GLOBALS['filters'][LANGUAGE]['level']['linkvalue'], 'id' => $result_level[$i]['level_id'], 'name'=> $result_level[$i]['level_name']);
      $level_list.="<li><a href=\"".Hrefmaker($URLlevel)."\" title=\"".$GLOBALS['filters'][LANGUAGE]['level']['desc'].' : '.$level_display."\">".$level_display."</a></li>".END_LINE;
    }
  }

  $level_list.="</ul></div>".END_LINE;
  echo $level_list;
}

/**
 * GetScaleFilter()
 * Build the form and include
 * a select box filledd-up by scales
 * @return void
 */
function GetScaleFilter() {
  $scale_list='<form action="index.php" method="post">'.END_LINE;
  $scale_list.="<div id=\"filterscale\">".END_LINE;
  $scale_list.="<div class=\"semnone\"><label for=\"id\">".$GLOBALS['lang']['divers']['scale_choice']."</label></div>".END_LINE;
  $scale_list.="<p>".$GLOBALS['lang']['divers']['scale_choice']."</p>".END_LINE;
  $scale_list.=GetScaleSelectBox();
  $scale_list.='<input type="hidden" value="'.$GLOBALS['filters'][LANGUAGE]['scale']['linkvalue'].'" name="filter" id="filter" />'.END_LINE;
  $scale_list.='<input type="hidden" value="'.$GLOBALS['activeitem'].'" name="rub" id="rub_scale" />'.END_LINE;
  $scale_list.='<input type="image" src="../gfx/' .THEME_PUBLIC. '/images/public/btn_go.gif" value="'.$GLOBALS['lang']['btn']['valid'].'" alt="'.$GLOBALS['lang']['btn']['valid'].'" title="'.$GLOBALS['lang']['btn']['valid'].'" size="15" name="valid" id="valid" />'.END_LINE;
  $scale_list.="</div>".END_LINE;
  $scale_list.='</form>'.END_LINE;
  echo $scale_list;
}

/**
 * GetScaleSelectBox()
 * Called by GestFilterScale()
 * Prepare select Box items
 * @return string
 */
function GetScaleSelectBox() {
  if(array_key_exists('filter', $_REQUEST) && $_REQUEST['filter']==$GLOBALS['filters'][LANGUAGE]['scale']['linkvalue']) $current_id=$_REQUEST['id']; else $current_id=-1;
  if (ActiveItemAlias($GLOBALS['activeitem'])==$GLOBALS['links'][LANGUAGE]['news']['linkvalue']) {
    $data=$GLOBALS['sql_object']->DBSelect(SQL_Get_FilterScale("I"));
  }
  else $data=$GLOBALS['sql_object']->DBSelect(SQL_Get_FilterScale());
  $field_name="id";
  $scale_list='';
  $item_active=ActiveItemAlias($GLOBALS['activeitem']);
  for ($i=0;$i<count($data);$i++){
    if($data[$i]['scale_id']==$current_id) {
      $mask=' selected="selected"';
    } else $mask='';
    $scale_display=formatText(cutText($data[$i]['scale_denomination'],20));
    $scale_list.="<option value=\"".$data[$i]['scale_id']."\"".$mask.">".$scale_display."</option>".END_LINE;
  }
  $select_scale ='<select name="'.$field_name.'" id="'.$field_name.'">'.END_LINE;
  $select_scale.='<option value="1">'.$GLOBALS['lang']['divers']['select_choice2'].'</option>'.END_LINE;
  $select_scale.=$scale_list;
  $select_scale.='</select>'.END_LINE;

  return $select_scale;
}

?>