Jump to content

Q&A for Guests


SeNioR-

Recommended Posts

Why is the Q&A Challenge for guests still not added? If captcha has been added then Q&A should also 🙂 

Can we expect it in the near future? Thanks.

qa-guest.png.faf97e155f96a947dc7d652f3c47633b.png

system\Content\Item.php (public static function formElements)

if ( !\IPS\Member::loggedIn()->member_id )
{
//ADD Q&A
      $question = FALSE;
		try
		{
			$question = \IPS\Db::i()->select( '*', 'core_question_and_answer', NULL, "RAND()" )->first();
		}
			catch ( \UnderflowException $e ) {}
			
			$return['qagp']	= new \IPS\Helpers\Form\Text( 'qagp', NULL, TRUE, array(), function( $val )
			{
				$qanda  = intval( \IPS\Request::i()->qagp_id );
				$pass = true;
			
				if( $qanda )
				{
					try
					{
						$question = \IPS\Db::i()->select( '*', 'core_question_and_answer', array( 'qa_id=?', $qanda ) )->first();
					}
					catch( \UnderflowException $e )
					{
						throw new \DomainException( 'qagp_incorrect' );
					}
						$answers = json_decode( $question['qa_answers'] );
						if( $answers )
					{
						$answers = is_array( $answers ) ? $answers : array( $answers );
						$pass = FALSE;
					
						foreach( $answers as $answer )
						{
							$answer = trim( $answer );
								if( mb_strlen( $answer ) AND mb_strtolower( $answer ) == mb_strtolower( $val ) )
							{
								$pass = TRUE;
							}
						}
					}
				}
				else
				{
					$questions = \IPS\Db::i()->select( 'count(*)', 'core_question_and_answer', 'qa_id > 0' )->first();
					if( $questions )
					{
						$pass = FALSE;
					}
				}
	
				if( !$pass )
				{
					throw new \DomainException( 'qagp_incorrect' );
				}
			} );

\IPS\Member::loggedIn()->language()->words['qagp'] = \IPS\Member::loggedIn()->language()->addToStack( 'core_question_and_answer_' . $question['qa_id'], FALSE );
}

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...