<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class pg_advsearch extends pg_helper {
public static $PFEAT= Array();
public static $AJAX = Array();
public static $PARG = Array('savedadv');
private $PROFILE;
public function __construct($pageid=NULL, $args=NULL){
if ( $pageid !== NULL AND $args !== NULL ){ parent::__construct($pageid, $args, self::$PFEAT, self::$AJAX); }
$this->PROFILE = new profile('site_profile');
}
public static function getpfeats(){ return self::$PFEAT; }
public function send_header(){
$hdata['title'] = langs::translate('pgtitle', NULL, 'advsearch');
if ( isset($_POST['saveadvas']) ){
$_POST['advname'] = stripslashes($_POST['advname']);
$id = md5($_POST['advname']);
if ( $this->PROFILE->isdefined('savedadv') ){
$adv = $this->PROFILE->read('savedadv');
}
if ( isset($adv[$id]) ){ unset($adv[$id]); }
$adv[$id]['name'] = $_POST['advname'];
$adv[$id]['filter'] = stripslashes($_POST['search_filter']);
unset($_POST['saveadvas'], $_POST['advname'], $_POST['search_filter'], $_POST['savedadv']);
$adv[$id]['vars'] = $_POST;
$this->PROFILE->set('savedadv', $adv);
pagegen::add_event('Advanced Search "'.$adv[$id]['name'].'" has been saved.');
unset($adv);
$this->args['savedadv'] = $id; //better then a forward eh ;)
//header("Location : /search/nbrid/1/$id");
}
return themes::send_header($hdata);
}
public function send_footer(){ return themes::send_footer(); }
public function send_content($pdata){
$tpl = new template();
$tpl->output_function('langs::output_for_client');
$adv = $this->PROFILE->read('savedadv');
foreach($adv as $id => &$vars ){ $vars['name'] = htmlentities($vars['name'], ENT_QUOTES, CORE::getintcharset()); }
$grp = $this->PROFILE->read('savedgrp');
foreach($grp as $id => &$vars ){
$vars['name'] = htmlentities($vars['name'], ENT_QUOTES, CORE::getintcharset());
$buf = split("\n", $vars['grp']);
foreach($buf as $k => &$v){ $v = trim($v); }
$vars['grp'] = implode(',', $buf);
}
if ( isset($this->args['savedadv']) ){ //restored from savedadv
if ( $this->PROFILE->isdefined('savedadv') ){
if ( isset($adv[$this->args['savedadv']]) ){
$data = $adv[$this->args['savedadv']];
foreach($data['vars'] as $k => &$val){ $data[$k] = $val; }
unset($data['vars']);
}
}
} elseif ( sessions::isdefined('last_advsearch', 'profile') ){ //restored from last adv in sess
$data = sessions::read('last_advsearch', 'profile');
$data['name'] = '';
$data['filter'] = sessions::read('last_advfilter', 'profile');
$this->args['savedadv'] = 'last';
} else {
$data = Array( 'name'=>'', 'filter'=>'', 'group'=>'', 'category'=>'-1','u_post_larger_than'=>'', 'u_post_smaller_than'=>'',
'q_url'=>'', 'u_username'=>'','a_name'=>'','u_nfo_posts_only'=>"0", 'u_comment_posts_only'=>"0",
'u_url_posts_only'=>"0", 'u_v3_retention'=>"0",'sort'=>'ps_edit_date', 'order'=>'desc');
$this->args['savedadv'] = 'none';
}
if ( FALSE === $tpl->load_file('pages/advsearch/pg_advsearch.tpl') ){ return FALSE; }
$attribs = Array('region', 'os', 'platform_console', 'platform_pda', 'media', 'source', 'video_format', 'video_genre', 'language',
'subtitle','pda','game_genre','audio_format','audio_genre','music_info', 'book_type', 'book_genre', 'anime',
'xxx_genre', 'resource_type');
foreach($attribs as $k => &$attr){
$k = "ps_rb_$attr";
if ( isset($data[$k]) ){
if ( is_array($data[$k]) ){
foreach($data[$k] as $opt => $val ){ $data[$k."_$val"] = TRUE; }
}
unset($data[$k]);
}
}
$tpl->setdata($data);
unset($data);
$tpl->appendata($this->PROFILE->isdefined('savedadv'), 'showrestore');
//$tpl->appendata($this->PROFILE->read('savedadv'), 'savedadv');
$tpl->appendata($adv, 'savedadv');
$tpl->appendata($grp, 'savedgrp');
$tpl->appendata($this->args['savedadv'], 'restored');
$tpl->appendata(sessions::isdefined('last_advsearch', 'profile'), 'showlast');
$tpl->parse();
return TRUE;
}
}