Jump to content

Search code auto populating a 0 in text fields


sfraise

Recommended Posts

I'm running community builder with Joomla and am having an issue with the search function.

It is auto populating a 0 in text fields if left blank which is causing the search results to only show results with a 0 in those fields.

I've been sifting through the code but I can't figure out what is causing this.

Here's a snippet of the code that handles the search function, maybe one of you guys can spot the error:

$search					=	null;
//	$searchPOST				=	stripslashes( cbGetParam( $_POST, 'search' ) );
$searchGET				=	cbGetParam( $_GET, 'search' );
$limitstart				=	(int) cbGetParam( $_REQUEST, 'limitstart', 0 );
$searchmode				=	(int) cbGetParam( $_REQUEST, 'searchmode', 0 );

// old search on formated name:

/*	if ( $searchPOST || count( $_POST ) ) {
	// simple spoof check security
	cbSpoofCheck( 'usersList' );
	if ( cbGetParam( $_GET, "action" ) == "search" ) {
		$search			=	$searchPOST;
	}
} else
	if ( isset( $_GET['limitstart'] ) ) {
		$search				=	stripslashes( $searchGET );
	}
*/
// get my user and gets the list of user lists he is allowed to see (ACL):

$myCbUser				=&	CBuser::getInstance( $uid );
if ( $myCbUser === null ) {
	$myCbUser			=&	CBuser::getInstance( null );
}
$myUser					=&	$myCbUser->getUserData();
/*
$myUser					=	new moscomprofilerUser( $_CB_database );
if ( $uid ) {
	$myUser->load( (int) $uid );
}
*/
$useraccessgroupSQL		=	" AND useraccessgroupid IN (".implode(',',getChildGIDS(userGID($uid))).")";
$_CB_database->setQuery( "SELECT listid, title FROM #__comprofiler_lists WHERE published=1" . $useraccessgroupSQL . " ORDER BY ordering" );
$plists					=	$_CB_database->loadObjectList();
$lists					=	array();
$publishedlists			=	array();

for ( $i=0, $n=count( $plists ); $i < $n; $i++ ) {
	$plist				=&	$plists[$i];
	$listTitleNoHtml	=	strip_tags( cbReplaceVars( getLangDefinition( $plist->title ), $myUser, false, false ) );
   	$publishedlists[]	=	moscomprofilerHTML::makeOption( $plist->listid, $listTitleNoHtml );
}

// select either list selected or default list to which he has access (ACL):

if ( isset( $_POST['listid'] ) ) {
	$listid				=	(int) cbGetParam( $_POST, 'listid', 0 );
} else {
	$listid				=	(int) cbGetParam( $_GET, 'listid', 0 );
}
if ( $listid == 0 ) {
	$_CB_database->setQuery( "SELECT listid FROM #__comprofiler_lists "
	. "\n WHERE `default`=1 AND published=1" . $useraccessgroupSQL );
	$listid				=	(int) $_CB_database->loadresult();
	if ( $listid == 0 && ( count( $plists ) > 0 ) ) {
		$listid			=	(int) $plists[0]->listid;
	}
}
if ( ! ( $listid > 0 ) ) {
	echo _UE_NOLISTFOUND;
	return;
}

// generates the drop-down list of lists:

if ( count( $plists ) > 1 ) {
	$lists['plists']	=	moscomprofilerHTML::selectList( $publishedlists, 'listid', 'class="inputbox" size="1" onchange="this.form.submit();"', 'value', 'text', $listid, 1 );
}

// loads the list record:

$row					=	new moscomprofilerLists( $_CB_database );
if ( ( ! $row->load( (int) $listid ) ) || ( $row->published != 1 ) ) {
	echo _UE_LIST_DOES_NOT_EXIST;
	return;
}
if ( ! allowAccess( $row->useraccessgroupid,'RECURSE', userGID($uid) ) ) {
	echo _UE_NOT_AUTHORIZED;
	return;
}

$params					=	new cbParamsBase( $row->params );

$hotlink_protection		=	$params->get( 'hotlink_protection', 0 );
if ( $hotlink_protection == 1 ) {
	if ( ( $searchGET !== null ) || $limitstart ) {
		cbSpoofCheck( 'usersList', 'GET' );
	}
}

$limit					=	(int) $params->get( 'list_limit' );
if ( $limit == 0 ) {
	$limit				=	(int) $ueConfig['num_per_page'];
}

$showPaging				=	$params->get( 'list_paging', 1 );
if ( $showPaging != 1 ) {
	$limitstart			=	0;
}

$isModerator			=	isModerator( $_CB_framework->myId() );

$_PLUGINS->loadPluginGroup( 'user' );
// $plugSearchFieldsArray	=	$_PLUGINS->trigger( 'onStartUsersList', array( &$listid, &$row, &$search, &$limitstart, &$limit ) );
$_PLUGINS->trigger( 'onStartUsersList', array( &$listid, &$row, &$search, &$limitstart, &$limit ) );

// handles the users allowed to be listed in the list by ACL:

$allusergids			=	array();
$usergids				=	explode( ',', $row->usergroupids );
/*	This was a bug tending to list admins when "public backend" was checked, and all frontend users when "public backend was checked. Now just ignore them:
foreach( $usergids AS $usergid ) {
	$allusergids[]		=	$usergid;
	if ($usergid==29 || $usergid==30) {
		$groupchildren	=	array();
		$groupchildren	=	$_CB_framework->acl->get_group_children( $usergid, 'ARO','RECURSE' );
		$allusergids	=	array_merge($allusergids,$groupchildren);
	}
}
*/
$allusergids			=	array_diff( $usergids, array( 29, 30 ) );
$usergids				=	implode( ",", $allusergids );

// build SQL Select query:

if( $row->sortfields != '' ) {
	$orderby			=	"\n ORDER BY " . $row->sortfields;
}
$filterby				=	'';
if ( $row->filterfields != '' ) {
	$filterRules		=	utf8RawUrlDecode( substr( $row->filterfields, 1 ) );

	if ( $_CB_framework->myId() ) {
		$user			=	new moscomprofilerUser( $_CB_database );
		if ( $user->load( (int) $_CB_framework->myId() ) ) {
			$filterRules	=	cbReplaceVars( $filterRules, $user, array( $_CB_database, 'getEscaped' ), false, array() );
		}
	}
	$filterby			=	" AND ". $filterRules;
}

// Prepare part after SELECT .... " and before "FROM" :

$tableReferences		=	array( '#__comprofiler' => 'ue', '#__users' => 'u' );

// Fetch all fields:

$tabs					=	$myCbUser->_getCbTabs();		//	new cbTabs( 0, 1 );		//TBD: later: this private method should not be called here, but the whole users-list should go into there and be called here.

$allFields				=	$tabs->_getTabFieldsDb( null, $myUser, 'list' );
// $_CB_database->setQuery( "SELECT * FROM #__comprofiler_fields WHERE published = 1" );
// $allFields				=	$_CB_database->loadObjectList( 'fieldid', 'moscomprofilerFields', array( &$_CB_database ) );


//Make columns array. This array will later be constructed from the tabs table:

$columns				=	array();

for ( $i = 1; $i < 50; ++$i ) {
	$enabledVar			=	"col".$i."enabled";

	if ( ! isset( $row->$enabledVar ) ) {
		break;
	}
	$titleVar			=	"col".$i."title";
	$fieldsVar			=	"col".$i."fields";
	$captionsVar		=	"col".$i."captions";

	if ( $row->$enabledVar == 1 ) {
		$col			=	new stdClass();
		$col->fields	=	( $row->$fieldsVar ? explode( '|*|', $row->$fieldsVar ) : array() );
		$col->title		=	$row->$titleVar;
		$col->titleRendered		=	$myCbUser->replaceUserVars( $col->title );
		$col->captions	=	$row->$captionsVar;
		// $col->sort	=	1; //All columns can be sorted
		$columns[$i]	=	$col;
	}
}

// build fields and tables accesses, also check for searchable fields:

$searchableFields		=	array();
$fieldsSQL				=	getFieldsSQL( $columns, $allFields, $tableReferences, $searchableFields, $params );

$_PLUGINS->trigger( 'onAfterUsersListFieldsSql', array( &$columns, &$allFields, &$tableReferences ) );

$tablesSQL				=	array();
$joinsSQL				=	array();
$tablesWhereSQL			=	array(	'block'		=>	'u.block = 0',
									'approved'	=>	'ue.approved = 1',
									'confirmed'	=>	'ue.confirmed = 1'
								 );
if ( ! $isModerator ) {
	$tablesWhereSQL['banned']	=	'ue.banned = 0';
}
if ( $usergids ) {
	$tablesWhereSQL['gid']		=	'u.gid IN (' . $usergids . ')';
}

foreach ( $tableReferences as $table => $name ) {
	$tablesSQL[]				=	$table . ' ' . $name;
	if ( $name != 'u' ) {
		$tablesWhereSQL[]		=	"u.`id` = " . $name . ".`id`";
	}
}

// handles search criterias:

$list_compare_types		=	$params->get( 'list_compare_types', 0 );
$searchVals				=	new stdClass();
$searchesFromFields		=	$tabs->applySearchableContents( $searchableFields, $searchVals, $_GET, $list_compare_types );
$whereFields			=	$searchesFromFields->reduceSqlFormula( $tableReferences, $joinsSQL, TRUE );
if ( $whereFields ) {
	$tablesWhereSQL[]	=	'(' . $whereFields . ')';
/*
	if ( $search === null ) {
		$search			=	'';
	}
*/
}

$_PLUGINS->trigger( 'onBeforeUsersListBuildQuery', array( &$tablesSQL, &$joinsSQL, &$tablesWhereSQL ) );

$queryFrom				=	"FROM " . implode( ', ', $tablesSQL )
						.	( count( $joinsSQL ) ? "\n " . implode( "\n ", $joinsSQL ) : '' )
						.	"\n WHERE " . implode( "\n AND ", $tablesWhereSQL );

// handles old formatted names search:
/*
if ( $search != '' ) {
	$searchSQL			=	cbEscapeSQLsearch( strtolower( $_CB_database->getEscaped( $search ) ) );
	$queryFrom 			.=	" AND (";

	$searchFields		=	array();
	if ( $ueConfig['name_format']!='3' ) {
		$searchFields[]	=	"u.name LIKE '%%s%'";
	}
	if ( $ueConfig['name_format']!='1' ) {
		$searchFields[]	=	"u.username LIKE '%%s%'";
	}
	if ( is_array( $plugSearchFieldsArray ) ) {
		foreach ( $plugSearchFieldsArray as $v ) {
			if ( is_array( $v ) ) {
				$searchFields	=	array_merge( $searchFields, $v );
			}
		}
	}
	$queryFrom			.=	str_replace( '%s', $searchSQL, implode( " OR ", $searchFields ) );
	$queryFrom			.=	")";
}
*/
$queryFrom				.=	" " . $filterby;

$_PLUGINS->trigger( 'onBeforeUsersListQuery', array( &$queryFrom, 1 ) );	// $uid = 1

$errorMsg		=	null;

// counts number of users and loads the listed fields of the users if not in search-form-only mode:

if ( $searchmode == 0 ) {
	$_CB_database->setQuery( "SELECT COUNT(*) " . $queryFrom );
	$total					=	$_CB_database->loadResult();

	if ( ( $limit > $total ) || ( $limitstart >= $total ) ) {
		$limitstart			=	0;
	}

	// $query					=	"SELECT u.id, ue.banned, '' AS 'NA' " . ( $fieldsSQL ? ", " . $fieldsSQL . " " : '' ) . $queryFrom . " " . $orderby
	$query					=	"SELECT ue.*, u.*, '' AS 'NA' " . ( $fieldsSQL ? ", " . $fieldsSQL . " " : '' ) . $queryFrom . " " . $orderby
	.	"\n LIMIT " . (int) $limitstart . ", " . (int) $limit;

	$_CB_database->setQuery($query);
	$users				=	$_CB_database->loadObjectList( null, 'moscomprofilerUser', array( &$_CB_database ) );

	if ( is_array( $users ) ) {
		// creates the CBUsers in cache corresponding to the $users:
		foreach ( array_keys( $users ) as $k) {
			CBuser::setUserGetCBUserInstance( $users[$k] );
		}
	} else {
		$users			=	array();
		$errorMsg		=	_UE_ERROR_IN_QUERY_TURN_SITE_DEBUG_ON_TO_VIEW;
	}

	if ( count( get_object_vars( $searchVals ) ) > 0 ) {
		$search			=	'';
	} else {
		$search			=	null;
	}

} else {
	$total				=	null;
	$users				=	array();
	if ( $search === null ) {
		$search			=	'';
	}
}

// Compute itemId of users in users-list:

if ( $Itemid ) {
	$option_itemid		=	(int) $Itemid;
} else {
	$option_itemid		=	getCBprofileItemid( 0 );
}

HTML_comprofiler::usersList( $row, $users, $columns, $allFields, $lists, $listid, $search, $searchmode, $option_itemid, $limitstart, $limit, $total, $myUser, $searchableFields, $searchVals, $tabs, $list_compare_types, $showPaging, $hotlink_protection, $errorMsg );
}
/**
* Creates the column references for the userlist query
*
* @param  array         $columns
* @param  array         $allFields
* @param  array         $tables
* @param  array         $searchableFields
* @param  cbParamsBase  $params
* @return string
*/
function getFieldsSQL( &$columns, &$allFields, &$tables, &$searchableFields, &$params ){
$colRefs										=	array();

$newtableindex									=	0;

$list_search									=	(int) $params->get( 'list_search', 1 );

foreach ( $columns as $i => $column ) {
	foreach ( $column->fields as $k => $fieldid ) {
		if ( isset( $allFields[$fieldid] ) ) {
			// now done in field fetching:
			//	if ( ! is_object( $allFields[$fieldid]->params ) ) {
			//		$allFields[$fieldid]->params	=	new cbParamsBase( $allFields[$fieldid]->params );
			//	}
			$field								=	$allFields[$fieldid];
			if ( ! array_key_exists( $field->table, $tables ) ) {
				$newtableindex++;
				$tables[$field->table]			=  't'.$newtableindex;
			}
/*
			if ( $field->name == 'avatar' ) {
				$colRefs['avatarapproved']		=	'ue.`avatarapproved`';
				$colRefs['name']				=	'u.`name`';
				$colRefs['username']			=	'u.`username`';
			}
			if ( $field->type == 'formatname' ) {
				$colRefs['name']				=	'u.`name`';
				$colRefs['username']			=	'u.`username`';
			}
*/
			if ( ( $tables[$field->table][0] != 'u' ) && ( $field->name != 'NA' ) ) {		// CB 1.1 table compatibility : TBD: remove after CB 1.2
				foreach ( $field->getTableColumns() as $col ) {
					$colRefs[$col]				=	$tables[$field->table] . '.' . $field->_db->NameQuote( $col );
				}
			}
			if ( $field->searchable && ( $list_search == 1 ) ) {
				$searchableFields[]				=&	$allFields[$fieldid];
			}
			$allFields[$fieldid]->_listed		=	true;
		} else {
			// field unpublished or deleted but still in list: remove field from columns, so that we don't handle it:
			unset( $columns[$i]->fields[$k] );
		}
	}
}

if ( $list_search == 2 ) {
	foreach ( $allFields as $fieldid => $field ) {
		if ( $field->searchable ) {
			$searchableFields[]					=&	$allFields[$fieldid];
		}
	}
}
return implode( ', ', $colRefs );
}

Link to comment
Share on other sites

Yeah I posted in the CB forum but no replies so far.

It's gotta be in the '0' handling somewhere in the code where instead of calling '0' as nothing it's literally calling 0 and using it as a search criteria. I just don't see where it would be doing that though.

 

Hopefully someone will respond in the CB forum.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.