)
* in combination with fillform.
*
* This script contains two similar functions:
*
* fillForm is used on anonymous posting forms
* fillConds is used on search forms
*
* Function fillForm
*
* Prints a JavaScript function which refills form fields with values from database.
*
* You must supply the var $my_item_id with the item id.
*
* Works well with HTML - Plain text radio buttons and with Dates
* represented by 3 select boxes.
*
* Function fillConds
*
* Prints a JavaScript function which refills form fields with name conds[][] with
* previous values.
*
* Uses the array conds and function setControlOrAADate - see fillformutils to get a feel
* about which form control types are supported (most of them are).
*
* @param array dateConds Special feature: contains names of textfields which are
* dates represented by 3 select boxes in the way of AA. E.g.
* dateConds[3]="mydate" means:
* conds[3]['value'] is a date in some strtotime format,
* mydate_day is the select box cotaining day, mydate_month contains month,
* mydate_year contains year
*
* @package UserInput
* @version $Id: fillform.php3 2666 2008-08-28 11:18:30Z honzam $
* @author Jakub Adamek
* @copyright Copyright (C) 1999, 2000 Association for Progressive Communications
*/
/*
Copyright (C) 1999, 2000 Association for Progressive Communications
http://www.apc.org/
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.
You should have received a copy of the GNU General Public License
along with this program (LICENSE); if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!isset ($form)) $form = "f";
$encap = ( ($encap=="false") ? false : true );
/** APC-AA configuration file */
require_once "include/config.php3";
/** Defines simplified class for page scroller */
require_once AA_INC_PATH."easy_scroller.php3";
/** Set of useful functions used on most pages */
require_once AA_INC_PATH."util.php3";
/** Defines class for item manipulation (shows item in compact or fulltext format, replaces aliases ...) */
require_once AA_INC_PATH."item.php3";
/** parses view settings, gets view data and other functions */
require_once AA_INC_PATH."view.php3";
/** defines PageCache class used for caching informations into database */
require_once AA_INC_PATH."pagecache.php3";
/** functions for searching and filtering items */
require_once AA_INC_PATH."searchlib.php3";
/** discussion utility functions */
require_once AA_INC_PATH."discussion.php3";
/** Defines class for inserting and updating database fields */
require_once AA_INC_PATH."varset.php3";
/** Main include file for using session management function on a page */
require_once AA_INC_PATH."locsess.php3";
require_once AA_BASE_PATH."modules/alerts/util.php3";
/** Used for getFrmJavascript() */
require_once AA_INC_PATH."formutil.php3";
/** Some functions pulled from here to allow inclusion elsewhere */
require_once AA_INC_PATH."fillform.php3";
page_open(array("sess" => "AA_SL_Session"));
function RestoreVariables() {
$r_state_vars = unserialize($GLOBALS['r_packed_state_vars']);
if (isset($r_state_vars) AND is_array($r_state_vars)) {
foreach ( $r_state_vars as $k=>$v ) {
$GLOBALS[$k] = $v;
}
}
}
RestoreVariables();
echo fillFormFromVars($fillConds);
if ($show_result) {
if ($result) {
readfile(con_url($show_result, "result=".urlencode(serialize($result))));
} else {
readfile($show_result);
}
} elseif (is_array($result)) {
echo "";
foreach ( $result as $k => $v) {
echo $k.": ";
if (is_array($v)) {
foreach ($v as $kk => $vv) {
echo "$kk - $vv ";
}
} else {
echo $v;
}
echo " \n";
}
echo "";
}
?>
$v) {
$kk = AddslashesDeep($v);
}
foreach ($_POST as $k => $v) {
$kk = AddslashesDeep($v);
}
foreach ($_COOKIE as $k => $v) {
$kk = AddslashesDeep($v);
}
}
$encap = ( ($encap=="false") ? false : true );
require_once "./include/config.php3";
require_once AA_INC_PATH."easy_scroller.php3";
require_once AA_INC_PATH."util.php3";
require_once AA_INC_PATH."item.php3";
require_once AA_INC_PATH."view.php3";
require_once AA_INC_PATH."pagecache.php3";
require_once AA_INC_PATH."searchlib.php3";
require_once AA_INC_PATH."discussion.php3";
require_once AA_INC_PATH."mgettext.php3";
require_once AA_INC_PATH."slice.class.php3";
require_once AA_INC_PATH."hitcounter.class.php3";
// function definitions:
require_once AA_INC_PATH."slice.php3";
require_once AA_INC_PATH."locsess.php3";
$slice_starttime = get_microtime();
//MLX stuff
require_once AA_INC_PATH."mlx.php";
page_open(array("sess" => "AA_SL_Session"));
$sess->register(r_packed_state_vars);
$sess->register(slices);
$r_state_vars = unserialize($r_packed_state_vars);
// there was problems with storing too much ids in session veriable,
// so I commented it out. It is not necessary to have it in session. The only
// reason to have it there is the display speed, but because of impementing
// pagecache.php3, it is not so big problem now
//$sess->register(item_ids);
if ($encap) { // adds values from QUERY_STRING_UNESCAPED
add_vars(""); // and REDIRECT_STRING_UNESCAPED
}
if (($key != $lock) OR $scrl) { // command is for other slice on page
RestoreVariables(); // or scroller
}
// url posted command to display specified text instead of slice content -------
if ($slicetext) {
echo $slicetext;
ExitPage();
}
// url posted command to display another file ----------------------------------
if ( $inc ) { // this section must be after add_vars()
// StoreVariables(array("inc")); // store in session
if ( !eregi("^([0-9a-z_])+(\.[0-9a-z]*)?$", $inc) ) {
echo _m("Bad inc parameter - included file must be in the same directory as this .shtml file and must contain only alphanumeric characters"). " $inc";
ExitPage();
} else {
$fp = @fopen(shtml_base().$inc, "r"); // if encapsulated
if (!$fp) {
echo _m("No such file") ." $inc";
} else {
FPassThru($fp);
}
ExitPage();
}
}
// Take any slice to work with
if (!$slice_id AND is_array($slices)) {
reset ($slices);
$slice_id = current($slices);
}
// if someone breaks ';
ExitPage();
}
$add_aliases = $aliases = GetAliasesFromUrl($als);
// this is not good way - aliases are then different on each call, so it isn't
// cached. The better way is below
// $add_aliases['_#SESSION_'] = GetAliasDef( 'f_s:'. $sess->id, '', _m('session id'));
$add_aliases['_#SESSION_'] = GetAliasDef( 'f_e:session', 'id..............', _m('session id'));
// if banner parameter supplied => set format
$slice_info = array_merge( $slice_info, ParseBannerParam($banner));
// get alias list from database and possibly from url
// if working with multi-slice, get aliases for all slices
if (!is_array($slices)) {
$aliases = GetAliasesFromFields($fields);
array_add($add_aliases, $aliases);
} else {
foreach ($slices as $sid) {
list($fields) = GetSliceFields($sid);
// hack for searching in multiple slices. This is not so nice part
// of code - we mix there $aliases[] with $aliases[][]
// it is needed by itemview::set_column() (see include/itemview.php3)
$aliases[q_pack_id($sid)] = GetAliasesFromFields($fields,$als);
array_add($add_aliases, $aliases[q_pack_id($sid)]);
}
}
// fulltext view ---------------------------------------------------------------
if ( $sh_itm OR $x OR $o ) {
// $r_state_vars = StoreVariables(array("sh_itm")); // store in session
if ( $x ) {
$zid = new zids((int)$x, 's');
AA_Hitcounter::hit($zid);
}
elseif ( $o ) {
$zid = new zids((int)$o, 's');
} else {
$zid = new zids($sh_itm, 'l');
AA_Hitcounter::hit($zid);
}
if (!isset ($hideFulltext)) {
$itemview = new itemview($slice_info, $fields, $aliases, $zid, 0, 1, $sess->MyUrl($slice_id, $encap));
$itemview->print_item();
}
// show discussion if assigned
$discussion_vid = ( isset($dview) ? $dview : $slice_info['vid']);
// you can set dview=0 to not show discussion
if ($discussion_vid > 0) {
$db->query("SELECT view.*, slice.flag FROM view, slice
WHERE slice.id='".q_pack_id($slice_id)."' AND view.id=$discussion_vid");
if ($db->next_record()) {
$view_info = $db->Record;
// create array of parameters
$disc = array('ids' => $all_ids ? "" : $ids,
'type' => $add_disc ? "adddisc" : (($sel_ids || $all_ids) ? "fulltext" : "thread"),
'item_id' => $zid->longids(0),
'vid' => $view_info['id'],
'html_format' => $view_info['flag'] & DISCUS_HTML_FORMAT,
'parent_id' => $parent_id
);
$aliases = GetDiscussionAliases();
$format = GetDiscussionFormat($view_info);
$format['id'] = $p_slice_id; // set slice_id because of caching
$itemview = new itemview($format, "", $aliases, null,"", "", $sess->MyUrl($slice_id, $encap), $disc);
$itemview->print_discussion('nocache'); // discussions should not be
// cached or even better (TODO) discussions should have its separate slice
// which is cached independently form the item itself through standard
// AA caching
}
}
ExitPage();
}
// multiple items fulltext view ------------------------------------------------
if ( $items AND is_array($items) ) { // shows all $items[] as fulltext one after one
// $r_state_vars = StoreVariables(array("items")); // store in session
while (list($k) = each( $items )) {
$ids[] = substr($k,1); //delete starting character ('x') - used for interpretation of index as string, not number (by PHP)
}
$zids = new zids($ids,"l");
$itemview = new itemview($slice_info, $fields, $aliases, $zids, 0,$zids->count(), $sess->MyUrl($slice_id, $encap));
$itemview->print_itemlist();
ExitPage();
}
// compact view ----------------------------------------------------------------
if (!is_object($scr)) {
$sess->register('scr');
if ( isset($als) AND is_array($als)) {
$scr_als_param = '&'. htmlentities(HttpGetParameters(array('als'=>$als)));
}
$scr_url_param = ($scr_url ? $sess->url("$scr_url") : $sess->MyUrl($slice_id, $encap)).$scr_als_param."&";
$scr = new easy_scroller( 'scr', $scr_url_param, $slice_info['d_listlen'], 0);
}
// display 'All' option in scroller
if ($all_scr) { $scr->setShowAll($all_scr); }
// change number of listed items
if ($listlen) { $scr->setMetapage($listlen); }
// default start page = 1
if (!$scr_go) { $scr_go = 1; }
// $scrl comes from easy_scroller
if ($scrl) { $scr->update(); }
/** Add scroller aliases - page number, listlen */
$scr_aliases['_#PAGE_NO_'] = GetAliasDef( 'f_s:'. $scr->current, '', _m('number of current page (on pagescroller)'));
$scr_aliases['_#PAGE_LEN'] = GetAliasDef( 'f_s:'. $scr->metapage, '', _m('page length (number of items)'));
// aliases array have two form (quite stupid - will be changed in future - TODO)
// depending on listing for one slice or many slices
if (!is_array($slices)) {
array_add($scr_aliases, $aliases);
} else {
foreach ($slices as $sid) {
// hack for searching in multiple slices. This is not so nice part
// of code - we mix there $aliases[] with $aliases[][]
// it is needed by itemview::set_column() (see include/itemview.php3)
array_add($scr_aliases, $aliases[q_pack_id($sid)]);
}
}
/* old version of automatiocaly created search form - not used in AA > 1.2
$easy_query .. easy query form
$srch .. bigsrch form ??
*/
if (($easy_query || $srch) AND !(is_array($conds) OR isset($group_by) OR isset($sort))) {
if ($easy_query) { // posted by easy query form ----------------
$r_state_vars = StoreVariables(array("listlen","no_scr","scr_go","srch_fld","srch_from", "srch_to",
"easy_query", "qry", "srch_relev", "mlx")); // store in session, added mlx
$item_ids = GetIDs_EasyQuery($fields, $db, $p_slice_id, $srch_fld, $srch_from, $srch_to, $qry, $srch_relev);
if ( isset($item_ids) AND !is_array($item_ids) ) {
echo "$item_ids ";
}
if ( !$scrl ) {
$scr->current = $scr_go;
}
}
elseif ($srch) { // posted by bigsrch form -------------------
$r_state_vars = StoreVariables(array("listlen","no_scr","scr_go","big","search", "s_col", "mlx")); // store in session
if ( !$big ) {
$search['slice'] = $slice_id;
}
$item_ids = SearchWhere($search, $s_col);
if ( !$scrl ) {
$scr->current = $scr_go;
}
}
elseif ($debug) {
echo "ERROR: This branch should never be entered.";
}
} else {
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Parse parameters posted by query form and from $slice_info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
$r_state_vars = StoreVariables(array("no_scr","scr_go","order","cat_id", "cat_name",
"exact","restrict","res_val","highlight","conds","group_by", "sort","als","defaultCondsOperator","mlx")); // store in session, added mlx
// ***** CONDS *****
if ($cat_id) { // optional parameter cat_id - deprecated - slow ------
$tmpobj = $slice->getFields();
$cat_field = $tmpobj->getCategoryFieldId();
$cat_group = GetCategoryGroup($slice_id);
$SQL = "SELECT value FROM constant
WHERE group_id = '$cat_group' AND id='". q_pack_id($cat_id) ."'";
$db->query($SQL);
if ( $db->next_record() ) {
$conds[] = array( $cat_field => 1,
'value' => $db->f('value'),
'operator' => ($exact ? '=' : 'LIKE'));
}
} elseif ($cat_name) { // optional parameter cat_name -------
$tmpobj = $slice->getFields();
$cat_field = $tmpobj->getCategoryFieldId();
$conds[] = array( $cat_field => 1,
'value' => $cat_name,
'operator' => ($exact ? '=' : 'LIKE'));
}
if ($restrict) {
$conds[] = array( $restrict => 1,
'value' => ((($res_val[0] == '"' OR $res_val[0] == "'") AND $exact != 2 ) ? $res_val : "\"$res_val\""),
'operator' => ($exact ? '=' : 'LIKE'));
}
if ($highlight != "") {
$conds[] = array('highlight.......' => 1);
}
if (!isset($defaultCondsOperator)) {
$defaultCondsOperator = 'LIKE';
}
if (is_array($conds)) {
ParseEasyConds($conds, $defaultCondsOperator);
foreach ( $conds as $k => $v ) {
SubstituteAliases( $als, $conds[$k]['value'] );
}
}
// ***** SORT *****
/** order by field xy if other than publish date.
* Syntax: [number]field_id[-]
* (add minus sign for descending order (like "headline.......1-")
* (add number before the field if you want to group limit (limit number of items of the same value))
*/
if ($order) {
$set = new AA_Set;
$set->addSortFromString($order);
$order = reset($set->getSort()); // get the first from array
list($order, $orderdirection) = each($order);
}
if ($debug) {
echo " Group by: -$group_by- Slice_info[category_sort] -$slice_info[category_sort]- slice_info[group_by] -$slice_info[group_by]-";
}
$sort_tmp = array();
if ($group_by) {
$set = new AA_Set;
$set->addSortFromString($group_by);
$sort_tmp = $set->getSort();
$slice_info["group_by"] = key($sort_tmp[0]);
}
elseif ($slice_info['category_sort']) {
$tmpobj = $slice->getFields();
$group_field = $tmpobj->getCategoryFieldId();
$grp_odir = (($order==$group_field) AND ($orderdirection!='d')) ? 'a' : 'd';
$sort_tmp[] = array( $group_field => $grp_odir );
}
elseif ($slice_info['group_by']) {
switch( (string)$slice_info['gb_direction'] ) { // gb_direction is number
case '1': $gbd = '1'; break; // 1 (1)- ascending by priority
case 'd': // d - descending - goes from view (iview) settings
case '8': $gbd = 'd'; break; // d (8)- descending
case '9': $gbd = '9'; break; // 9 (9)- descending by priority (for fields using constants)
default: $gbd = 'a'; // 2 (2)- ascending;
}
$sort_tmp[] = array($slice_info['group_by'] => $gbd);
}
$sort_tmp = array_merge($sort_tmp, getSortFromUrl($sort));
if ($order) {
add2sort($sort_tmp, array($order => (strstr('aAdD19',$orderdirection) ? $orderdirection : 'a')));
}
// time order the fields in compact view
add2sort($sort_tmp, array('publish_date....' => (($timeorder == "rev") ? 'a' : 'd')));
$sort = $sort_tmp;
//mlx stuff
if (isMLXSlice($slice_info)) {
if (!$mlxView) {
$mlxView = new MLXView($mlx);
}
$mlxView->preQueryZIDs(unpack_id128($slice_info[MLX_SLICEDB_COLUMN]),$conds,$slices);
}
$zids = QueryZIDs( ($slices ? $slices : array($slice_id)), $conds, $sort, "ACTIVE", $neverAllItems, 0, $defaultCondsOperator, true );
if (isMLXSlice($slice_info)) {
$mlxView->postQueryZIDs($zids,unpack_id128($slice_info[MLX_SLICEDB_COLUMN]),$slice_id, $conds, $sort, $slice_info['group_by'],"ACTIVE", $slices, $neverAllItems, 0, $defaultCondsOperator,$nocache);
}
if ( !$scrl ) {
$scr->current = $scr_go;
}
}
if ( !$srch AND !$encap AND !$easy_query ) {
$cur_cats=GetCategories($db,$p_slice_id); // get list of categories
pCatSelector($sess->name,$sess->id,$sess->MyUrl($slice_id, $encap, true),$cur_cats,$scr->filters[category_id]['value'], $slice_id, $encap);
}
if ($zids->count() > 0) {
$scr->countPages( $zids->count() );
$itemview = new itemview($slice_info, $fields, $aliases, $zids, $scr->metapage * ($scr->current - 1),
($group_n ? -$group_n : $scr->metapage), // negative number used for displaying n-th group
$sess->MyUrl($slice_id, $encap) );
$itemview->print_view();
if (($scr->pageCount() > 1) AND !$no_scr AND !$group_n) {
$scr->pnavbar();
}
} else {
// test if the the noitem_msg is filled (be carefull - "0" should be considered as filled)
echo (isset($slice_info['noitem_msg']) AND (strlen($slice_info['noitem_msg']) > 0)) ? // is keyword for removing 'no item message'
str_replace( '', '', AA_Stringexpand::unalias($slice_info['noitem_msg'])) : (""._m("No item found") ." ");
}
if ($searchlog) {
PutSearchLog();
}
if ($debug) {
$timeend = get_microtime();
$time = $timeend - $slice_starttime;
echo "
Page generation time: $time";
}
ExitPage();
?>
|