HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/kamforum.ru/jscripts/ipb_poll.js
//------------------------------------------
// Invision Power Board v2.1
// POLL JS File
// (c) 2005 Invision Power Services, Inc.
//
// http://www.invisionboard.com
// ASSUMES 'ipb_global.php' as been loaded
//------------------------------------------

/*--------------------------------------------*/
// INIT
/*--------------------------------------------*/

//-------------------------------
// DIV & FORM id names
//-------------------------------

var open_div   = 'poll-box-open';
var closed_div = 'poll-box-closed';
var stat_div   = 'poll-box-stat';
var main_div   = 'poll-box-main';
var form_id    = 'postingform';

//-------------------------------
// DIV AND FORM objects
//-------------------------------

var openobj;
var closedobj;
var formobj;
var statobj;
var mainobj;

//-------------------------------
// Counters
//-------------------------------

var used_questions = 0;

/*--------------------------------------------*/
// INIT STATE
/*--------------------------------------------*/

function poll_init_state()
{
	//-------------------------------
	// Get objects
	//-------------------------------
	
	openobj   = document.getElementById( open_div );
	closedobj = document.getElementById( closed_div );
	formobj   = document.getElementById( form_id );
	statobj   = document.getElementById( stat_div );
	mainobj   = document.getElementById( main_div );
	
	//-------------------------------
	// Open and close divs
	//-------------------------------
	
	if ( showfullonload )
	{
		my_show_div(  openobj  );
		my_hide_div( closedobj );
	}
	else
	{
		my_show_div( closedobj );
		my_hide_div(  openobj  );
	}
	
	poll_draw_main_box();
}

/*--------------------------------------------*/
// DRAW MAIN BOX
/*--------------------------------------------*/

function poll_draw_main_box()
{
	var html       = '';
	used_questions = 0;
	
	//-------------------------------
	// Draw all current questions
	//-------------------------------
	
	for( var i in poll_questions )
	{
		var qhtml = '';
		used_questions++;
		
		//-------------------------------
		// Show question box
		//-------------------------------
		
		var question  = poll_questions[i];
		var inputhtml = lang_build_string( html_question_box, i, _poll_make_form_safe( question ) ); 
		
		qhtml += "\n" + inputhtml + "\n";
		
		//-------------------------------
		// Now, to add the poll choices..
		//-------------------------------
		
		var choices       = '';
		var choices_count = 0;
		
		for ( var c in poll_choices )
		{
			var votes_box;
			
			//-------------------------------
			// Is this a choice for this q?
			//-------------------------------
			
			var id = c.replace( new RegExp( "^" + i + "_(\\d+)$" ), "$1" );
			
			if ( ! isNaN( id ) )
			{
				if ( is_mod )
				{
					votes_box = lang_build_string( html_votes_box, i, id, poll_votes[c]);
				}
				else
				{
					votes_box = '';
				}
				
				choices_count++;
				
				choices += "\n" + lang_build_string( html_choice_box, i, id, _poll_make_form_safe( poll_choices[c] ), votes_box );
			}
		}
		
		//-------------------------------
		// Not used max questions?
		//-------------------------------
		
		if ( choices_count < max_poll_choices )
		{
			choices += lang_build_string( html_add_choice, i );
		}
		
		if ( choices != '' )
		{
			qhtml += "\n" + lang_build_string( html_choice_wrap, choices ) + "\n";
		}
		
		//-------------------------------
		// Add wrapped question w/choice
		//-------------------------------
		
		html += lang_build_string(html_question_wrap, qhtml );
	}
	
	//-------------------------------
	// Add a question link?
	//-------------------------------
	
	if ( used_questions < max_poll_questions )
	{
		html += lang_build_string( html_question_wrap, html_add_question );
	}
	
	mainobj.innerHTML = html;
	
	poll_update_state();
}

/*--------------------------------------------*/
// WRITE FORM TO ARRAY
/*--------------------------------------------*/

function poll_write_form_to_array()
{
	//-------------------------------
	// Update question array with form
	//-------------------------------
	
	var tmp_poll_questions = {};
	var tmp_poll_choices   = {};
	
	for ( var i in poll_questions )
	{
		//-------------------------------
		// Get form value...
		//-------------------------------
		
		try
		{
			tmp_poll_questions[ i ] = document.getElementById( 'question_' + i ).value;
		}
		catch(e) { }
	}
	
	for ( var c in poll_choices )
	{
		//-------------------------------
		// Get form value...
		//-------------------------------
		
		try
		{
			tmp_poll_choices[ c ] = document.getElementById( 'choice_' + c ).value;
		}
		catch(e) { }
	}
	
	//-------------------------------
	// Update
	//-------------------------------
	
	poll_questions = tmp_poll_questions;
	poll_choices   = tmp_poll_choices;
}

/*--------------------------------------------*/
// ADD POLL QUESTION
/*--------------------------------------------*/

function poll_add_question()
{
	var maxid = 0;
	
	//-------------------------------
	// Get max choice ID
	//-------------------------------
	
	for ( var i in poll_questions )
	{
		if ( i > maxid )
		{
			maxid = parseInt(i);
		}
	}
	
	maxid = maxid + 1;
	
	poll_write_form_to_array();
	
	poll_questions[ maxid ] = '';
	
	poll_draw_main_box();
	
	return false;
}


/*--------------------------------------------*/
// ADD POLL CHOICE
/*--------------------------------------------*/

function poll_add_choice( qid )
{
	var maxid = 0;
	
	//-------------------------------
	// Get max choice ID
	//-------------------------------
	
	for ( var c in poll_choices )
	{
		//-------------------------------
		// Is this a choice for this q?
		//-------------------------------
		
		var id = c.replace( new RegExp( "^" + qid + "_(\\d+)$" ), "$1" );
		
		if ( ! isNaN( id ) )
		{
			if ( id > maxid )
			{
				maxid = parseInt(id);
			}
		}
	}
	
	maxid = maxid + 1;
	
	poll_write_form_to_array();
	
	poll_choices[ qid +'_'+maxid ] = '';
	
	if ( is_mod )
	{
		poll_votes[ qid +'_'+maxid ] = 0;
	}
	
	poll_draw_main_box();
	
	return false;
}

/*--------------------------------------------*/
// REMOVE POLL CHOICE
/*--------------------------------------------*/

function poll_remove_choice( mainid )
{
	if ( confirm( js_lang_confirm ) )
	{
		delete( poll_choices[ mainid ] );
		
		if ( is_mod )
		{
			delete( poll_votes[ mainid ] );
		}
		
		poll_write_form_to_array();
		poll_draw_main_box();
	}
	
	return false;
}

/*--------------------------------------------*/
// REMOVE POLL QUESTION
/*--------------------------------------------*/

function poll_remove_question( mainid )
{
	if ( confirm( js_lang_confirm ) )
	{
		//-------------------------------
		// Delete question
		//-------------------------------
		
		delete( poll_questions[ mainid ] );
		
		//-------------------------------
		// Delete choices
		//-------------------------------
		
		for ( var c in poll_choices )
		{
			//-------------------------------
			// Is this a choice for this q?
			//-------------------------------
			
			var id = c.replace( new RegExp( "^" + mainid + "_(\\d+)$" ), "$1" );
			
			if ( ! isNaN( id ) )
			{
				delete( poll_choices[ c ] );
				
				if ( is_mod )
				{
					delete( poll_votes[ c ] );
				}
			}
		}
		
		poll_write_form_to_array();
		poll_draw_main_box();
	}
	
	return false;
}

/*--------------------------------------------*/
// UPDATE POLL STATE
/*--------------------------------------------*/

function poll_update_state()
{
	used = max_poll_questions - used_questions;
	
	var tmp_lang      = lang_build_string( poll_stat_lang, used, max_poll_choices );
	statobj.innerHTML = lang_build_string( html_stat_wrap, tmp_lang );
}

/*--------------------------------------------*/
// SHOW POLL FORM
/*--------------------------------------------*/

function show_poll_form()
{
	my_show_div(  openobj  );
	my_hide_div( closedobj );
}

/*--------------------------------------------*/
// CLOSE POLL FORM
/*--------------------------------------------*/

function close_poll_form()
{
	my_show_div( closedobj );
	my_hide_div(  openobj  );
}

/*--------------------------------------------*/
// FORM MAKE SAFE
/*--------------------------------------------*/

function _poll_make_form_safe( t )
{
	t = t.replace( /'/g, '&#039;' );
	t = t.replace( /"/g, '&quot;' );
	
	return t;
}