text velden

Hulp nodig bij een modificaties of op zoek naar een MOD? Bekijk ons archief. Support wordt helaas niet meer verleend.
Forumregels

Sinds 1 januari 2009 wordt phpBB2 niet meer ondersteund.
Onderstaande informatie is verouderd en dient uitsluitend als archief.
phpBB2.0.x
Gesloten
jeroendegier
Berichten: 77
Lid geworden op: 07 feb 2007, 17:49

text velden

Bericht door jeroendegier » 13 mar 2007, 02:14

ik heb hier een script om extra velden toe te voegen in posting... alleen wil ik de velden veranderen er zit een radio button in bv en die wil ik er uit en wat extra text velden erin zetten weet iemand waar ik die velden kan veranderen



Code: Selecteer alles

//
// Here we'll initialize MOD-wide vars & configuration
//
function ntraf_initialize()
{
	//
	// define MOD-wide global vars
	//
	global $ntraf_field_name, $ntraf_field_id, $ntraf_answer;
	global $ntraf_field_missing;
	$ntraf_field_name = array();
	$ntraf_field_id = array();
	$ntraf_answer = array();
	$ntraf_field_missing = array();

	//
	// let's read MOD-wide configuration from database ... 
	//
	global $db;
	global $ntraf_config;
	$ntraf_config = array();
	
	$sql = "SELECT *
		FROM " . NTRAF_CONFIG_TABLE;
	if( !($result = $db->sql_query($sql)) )
	{
		message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
	}
	
	while ( $row = $db->sql_fetchrow($result) )
	{
		$ntraf_config[$row['ntraf_config_name']] = $row['ntraf_config_value'];
	}

		//
		// ****************************************************************************************************************
		// generate Copyright & Version-Information for this MOD ...
		//
		$tmp_mod_name        = $ntraf_config['mod_name'];
		$tmp_mod_version     = $ntraf_config['mod_version'];
		$tmp_copyright_years = $ntraf_config['copyright_years'];
		$tmp_author_link     = '<a href="http://' . $ntraf_config['author_website'] . '" target="_blank">mad-manne</a>';
		
			// now let's compose the complete line ...
			$tmp_copyright_notice = '[' . $tmp_mod_name . '-<b>MOD</b> ';
			$tmp_copyright_notice.= '<i>version ' . $tmp_mod_version .'</i>';
			$tmp_copyright_notice.= '] &copy;' . $tmp_copyright_years . ' by ';
			$tmp_copyright_notice.= $tmp_author_link;
	
		// and finally assign it to a CONSTANT !
		define('NTRAF_COPYRIGHT_NOTICE', $tmp_copyright_notice);
		//
		// ... done with Copyright & Version-Information for this MOD
		// ****************************************************************************************************************
		// 
}

//
// This function generates the complete input-fields required while posting, editing RAFs
//
function ntraf_gen_inputfields($my_template_id, $my_post_id, $my_mode)
{
	// global vars to used outside ...
	global $db, $userdata;
		
	global $ntraf_title, $ntraf_info, $ntraf_warning;
	global $ntraf_field_id, $ntraf_answer, $ntraf_field_count;
	global $ntraf_field_caption, $ntraf_field_explain, $ntraf_field_code;
		
	//$ntraf_field_id = array();
	
	// internal vars
	$my_type = array();
	$my_mainoption = array();
	$my_name = array();
	
	// set some vars to default
	$ntraf_field_count = 0;
	

	// First we'll have to get the more infos about this template !
	$sql = "SELECT template_form_title, template_form_info, template_form_warning 
	FROM " . NTRAF_TEMPLATES_TABLE . " 
	WHERE ntraf_template_id = $my_template_id";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[template] Error reading data for RequiredAdditionalFields'); 
	} // end IF --> result from database was O.K.

	if ( $template = $db->sql_fetchrow($result) )
	{
		$ntraf_title = $template['template_form_title'];
		$ntraf_info = $template['template_form_info'];
		$ntraf_warning = $template['template_form_warning'];
	}

	
	// Now we'll have to get the field-list for this template !
	$sql = "SELECT ntraf_field_id, field_type, field_mainoption, field_caption, field_explain 
	FROM " . NTRAF_FIELDS_TABLE . " 
	WHERE ntraf_template_id = $my_template_id
	ORDER BY field_order";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[field-list] Error reading data for RequiredAdditionalFields'); 
	} // end IF --> result from database was O.K.

	if ( $tpl_fields = $db->sql_fetchrow($result) )
	{
		do
		{
			$ntraf_field_count++;
			
			array_push($ntraf_field_id, $tpl_fields['ntraf_field_id']);
			array_push($my_type, $tpl_fields['field_type']);
			array_push($my_mainoption, $tpl_fields['field_mainoption']);
			array_push($ntraf_field_caption, $tpl_fields['field_caption']);
			array_push($ntraf_field_explain, $tpl_fields['field_explain']);
			array_push($my_name, 'RAF#' . $tpl_fields['ntraf_field_id']);
		}
		while ( $tpl_fields = $db->sql_fetchrow($result) );
	} // done reading field-list for this template
	$db->sql_freeresult($result);
	
	// Before we can start composing the HTML-Code for all fields, there's one more task!
	//  [1] If we are in newtopic-mode ...
	//      ... we should check if the user has answers remembered for this template
	//  [2] If this is about editing an existing topic-starter ...
	//      ... let's get the answers submitted with that $post_id
	// To check this, we'll just try and see if the array contains any data.

	switch ( $my_mode )
	{
		case 'newtopic':
			// We won't do anything for guests ...
			if ( $userdata['session_logged_in'] )
			{
				// we will only fill-in remembered answers, if the array of answers is still empty!
				if ( implode('', $ntraf_answer) == '' )
				{
					$debug = '[LAST ANSWERS ...] ';
					/*
					$ntraf_answer[0] = 'Yes';
					$ntraf_answer[1] = 'boardname remembered!';
					$ntraf_answer[2] = 'password';
					*/
				}// end IF ( answers are ALL empty )
			} // end IF ( member )
			break;
		
		case 'editpost':
			$debug = '[EDITING] ';
			break;
	} // end SWITCH ( $my_mode )

	// just debug-INFO
	// $ntraf_title = $debug . $ntraf_title;
	// just debug-INFO
	
	// Now we want to compose the input-field code. Here's how it goes:
	//  [1] For every single field we'll read all config-data for that field
	//  [2] Depending on the type-definition of the field make the according code
	//  [3] Set every field-value either to it's default(first call) or POST-value(script is in progress)
	
	// let's go for it and iterate over the field-list array(s)
	for ($i=0; $i < $ntraf_field_count; $i++)
	{
		// let's get the according values from the db

		$sql = "SELECT fieldoption_name, fieldoption_value
		FROM " . NTRAF_FIELDOPTIONS_TABLE . " 
		WHERE ntraf_field_id  = $ntraf_field_id[$i]
		ORDER BY fieldoption_name";

		if ( (!$result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_MESSAGE, $ntraf_field_count . '[field-options] Error reading data for RequiredAdditionalFields'); 
		} // end IF --> result from database was O.K.

		
		// let's reset this for every new set of field-options !
		$my_field_options = array();
		$my_field_default = '';
		
		while ( $row = $db->sql_fetchrow($result) )
		{
			if ( $row['fieldoption_name'] == 'default' ) 
			{
				// here's the default value for the current field :-)
				$my_field_default = $row['fieldoption_value'];
			} else
			{
				// field-options go into array
				$my_field_options[$row['fieldoption_name']] = $row['fieldoption_value'];
			}
		}

			switch ( $my_type[$i] )
			{
				case NTRAF_FIELDTYPE_TEXT:
					if ( $my_mainoption[$i] == 'PASSWORD' )
					{
						// let's generate an input-field for passwords
						$tmp_code = '<input type="password" class="post" name="' . $my_name[$i] . '"';
					} else
					{
						// let's generate an normal text-field 
						$tmp_code = '<input type="text" class="post" name="' . $my_name[$i] . '"';
					}

					$tmp_code.= ' size="' . $my_field_options['input_length'] . '"';
					$tmp_code.= ' maxlength="' . $my_field_options['max_length'] . '"';
						if ( empty($ntraf_answer[$i]) )
						{
							// seems to be the first call of the script ... let's assign default-value
							$tmp_code.= ' value="' . $my_field_default .'">';
						} else 
						{
							// obviously we have POST-data for this var ... let's assign it!
							$tmp_code.= ' value="' . $ntraf_answer[$i] .'">';
						}

					// O.K. code has been composed ... let's go
					array_push($ntraf_field_code, $tmp_code);
					break;
	
				case NTRAF_FIELDTYPE_RADIOBUTTONS:
					$button_count = count($my_field_options);
					$tmp_code = '';
				
					for ($button=0; $button < $button_count; $button++)
					{
						$button_index = 'radio_button' . strval(($button+1)*10);
						
						$tmp_code.= '<input type="radio" name="' . $my_name[$i] . '"';
						$tmp_code.= ' value="' . $my_field_options[$button_index] .'"';

						if ( empty($ntraf_answer[$i]) )
						{
							if ( $my_field_options[$button_index] == $my_field_default )
							{
								$tmp_code.= ' checked="checked" ';
							}
						} else
						{
							if ( $my_field_options[$button_index] == $ntraf_answer[$i] )
							{
								$tmp_code.= ' checked="checked" ';
							}
						}
						
						$tmp_code.= '>' . $my_field_options[$button_index] .'&nbsp;';

						// if values should be displayed VERTICALLY ... let's do it!
						if ( $my_mainoption[$i] == 'VERTICAL' )
						{
							$tmp_code.= NTRAF_VERTICAL_CODE;
						}
					} // end iterating over buttons
					
					// If VERTICAL was active ... 
					// ... we'll have to strip the last substring(NTRAF_VERTICAL_CODE) from the string
					if ( $my_mainoption[$i] == 'VERTICAL' )
					{
						$tmp_code = substr($tmp_code, 0, (strlen($tmp_code) - strlen(NTRAF_VERTICAL_CODE)));
					}

					// O.K. code has been composed ... let's go
					array_push($ntraf_field_code, $tmp_code);
					break;
	
				case NTRAF_FIELDTYPE_CHECKBOXES:
					$checkbox_count = count($my_field_options);
					$tmp_code = '';
				
					for ($checkbox=0; $checkbox < $checkbox_count; $checkbox++)
					{
						$checkbox_index = 'checkbox' . strval(($checkbox+1)*10);
						
						$tmp_code.= '<input type="checkbox" name="' . $my_name[$i] . '[]"';
						$tmp_code.= ' value="' . $my_field_options[$checkbox_index] .'"';

						// now we'll creep into this inner array and see what has to be checked !
						$checkbox_selected = ( is_array($ntraf_answer[$i]) ) ? TRUE : FALSE ;
						
						if ( $checkbox_selected  )
						{
							// iterate over the selected fields
							for ($j=0 ; $j < count($ntraf_answer[$i]); $j++)
							{
								if ( $my_field_options[$checkbox_index] == $ntraf_answer[$i][$j] )
								{
									$tmp_code.= ' checked="checked" ';
								}
							}// done iterating on selected boxes
						}// end IF checkbox has been selected
						
						$tmp_code.= '>' . $my_field_options[$checkbox_index] .'&nbsp;';
						// if values should be displayed VERTICALLY ... let's do it!
						if ( $my_mainoption[$i] == 'VERTICAL' )
						{
							$tmp_code.= '<br />&nbsp;';
						}
					} // end iterating over buttons

					// If VERTICAL was active ... we'll have to strip the last '<br />&nbsp;' from the string
					if ( $my_mainoption[$i] == 'VERTICAL' )
					{
						$tmp_code = substr($tmp_code, 0, (strlen($tmp_code) - 12));
					}

					// O.K. code has been composed ... let's go
					array_push($ntraf_field_code, $tmp_code);
					break;
	
				case NTRAF_FIELDTYPE_DROPDOWNLIST:
					$list_count = count($my_field_options);
					if ( empty($my_mainoption[$i]) )
					{
						// let's generate a standard dropdown-list ...
						$tmp_code = '<select name="' . $my_name[$i] . '">';
						$tmp_code.= '<option value="">&nbsp;&nbsp;Make your choice!</option>';
						$tmp_code.= '<option value="">--------------------</option>';
					} else
					{
						// let's generate a multiple-selection list with a given size ...
						$tmp_code = '<select name="' . $my_name[$i] . '[]"';
						$tmp_code.= ' size="' . intval($my_mainoption[$i]) . '" multiple>';
					}

				
					// now let's iterate over the options available !
					for ($list=0; $list < $list_count; $list++)
					{
						$list_index = 'list_item' . strval(($list+1)*10);

						$tmp_code.= '<option value="' . $my_field_options[$list_index] .'"';

						// depending on what type of list this is ...
						// ... different ways to assign defaults or actual POST-vars !
						if ( empty($my_mainoption[$i]) )
						{
							// standard dropdown-list ...
							if ( empty($ntraf_answer[$i]) )
							{
								if ( $my_field_options[$list_index] == $my_field_default )
								{
									$tmp_code.= ' selected="selected" ';
								}
							} else 
							{
								if ( $my_field_options[$list_index] == $ntraf_answer[$i] )
								{
									$tmp_code.= ' selected="selected" ';
								}
							} // done assigning default or actual POST-var to standard dropdown-list
						}
						else
						{
							// O.K. this is a multiple-choice list ...
							// ... now we'll creep into this inner array and see what needs to be checked !
							$list_selected = ( is_array($ntraf_answer[$i]) ) ? TRUE : FALSE ;

							if ( $list_selected  )
							{
								// iterate over the selected fields
								for ($j=0 ; $j < count($ntraf_answer[$i]); $j++)
								{
									if ( $my_field_options[$list_index] == $ntraf_answer[$i][$j] )
									{
										$tmp_code.= ' selected="selected" ';
									}
								}// done iterating on select-box
							}// end IF checkbox has been selected

						} // PHEW ... done assigning defaults or actual POST-vars for both types of list :-)
						
						$tmp_code.= '>' . $my_field_options[$list_index] .'</option>';
					} // end iterating over list-items
					$tmp_code.= '</select>';

					// O.K. code has been composed ... let's go
					array_push($ntraf_field_code, $tmp_code);
					break;
			} // end of switch
	
	}// done iterating over the field-list
	
	
}// end of function

//
// This function generates the complete output-fields required to display what user's submitted into RAFs
//
function ntraf_gen_outputfields($my_template_id, $my_topic_id)
{
	// global vars to used outside ...
	global $db;
		
	global $ntraf_title, $ntraf_info, $ntraf_warning;
	global $ntraf_field_id, $ntraf_answer, $ntraf_field_count;
	global $ntraf_field_caption, $ntraf_field_explain, $ntraf_field_code;
	
	global $ntraf_display_caption;
	global $ntraf_title_bar;
	global $ntraf_field_count;
		
	// internal vars
	$my_type = array();
	$my_mainoption = array();
	$my_name = array();
	$ntraf_display_caption = array();
	
	// set some vars to default
	$ntraf_field_count = 0;
	
	// First we'll have to get the more infos about this template !
	$sql = "SELECT template_display_title
	FROM " . NTRAF_TEMPLATES_TABLE . " 
	WHERE ntraf_template_id = $my_template_id";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[template] Error reading data for RequiredAdditionalFields'); 
	} // end IF --> result from database was O.K.

	if ( $template = $db->sql_fetchrow($result) )
	{
		$ntraf_title_bar = $template['template_display_title'];
	}

	
	// Now we'll have to get the field-list for this template !
	$sql = "SELECT ntraf_field_id, field_type, field_mainoption, display_caption
	FROM " . NTRAF_FIELDS_TABLE . " 
	WHERE ntraf_template_id = $my_template_id
	ORDER BY field_order";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[field-list] Error reading data for RequiredAdditionalFields'); 
	} // end IF --> result from database was O.K.

	if ( $tpl_fields = $db->sql_fetchrow($result) )
	{
		do
		{
			$ntraf_field_count++;
			
			array_push($ntraf_field_id, $tpl_fields['ntraf_field_id']);
			array_push($my_type, $tpl_fields['field_type']);
			array_push($my_mainoption, $tpl_fields['field_mainoption']);
			array_push($ntraf_display_caption, $tpl_fields['display_caption']);
			
			// some answers might be empty because template might have had fields added ...
			$ntraf_field_code[intval($ntraf_field_id)] = ' n/a ';
			
		}
		while ( $tpl_fields = $db->sql_fetchrow($result) );
	} // done reading field-list for this template
	$db->sql_freeresult($result);


	// O.K. We're done with the field-list ... let's get the answers!
	$sql = "SELECT *
	FROM " . NTRAF_ANSWERS_TABLE . " 
	WHERE topic_id = $my_topic_id
	ORDER BY ntraf_field_id";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[answer-list] Error reading answers for RequiredAdditionalFields of this topic'); 
	} // end IF --> result from database was O.K.

	if ( $my_answers = $db->sql_fetchrow($result) )
	{
		do
		{
			// Arrays of answers must be imploded while single answers don't !
			$tmp_answer = '';
			if ( intval($my_answers['answer_isarray']) == 1 )
			{
				$tmp_answer = implode(NTRAF_VERTICAL_CODE, unserialize($my_answers['ntraf_answer']));
			}
			else
			{
				$tmp_answer = $my_answers['ntraf_answer'];
			}
			
			$ntraf_field_code[$my_answers['ntraf_field_id']] = $tmp_answer;
		}
		while ( $my_answers = $db->sql_fetchrow($result) );
	} // done reading answers for this topic
	$db->sql_freeresult($result);
	
}// end of function

//
// reads the basic field-information for a specific template
//
function ntraf_gen_fieldlist($my_template_id)
{
	global $db;

	global $ntraf_field_count;
	global $ntraf_field_name;
	global $ntraf_field_id;

	// set some vars to default
	$ntraf_field_count = 0;
	
	// First we'll have to get the field-list for this template !
	$sql = "SELECT ntraf_field_id
	FROM " . NTRAF_FIELDS_TABLE . " 
	WHERE ntraf_template_id = $my_template_id
	ORDER BY field_order";

	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_MESSAGE, '[GEN field-list] Error reading data for RequiredAdditionalFields'); 
	} // end IF --> result from database was O.K.

	if ( $tpl_fields = $db->sql_fetchrow($result) )
	{
		do
		{
			$ntraf_field_count++;
			
			array_push($ntraf_field_id, $tpl_fields['ntraf_field_id']);
			array_push($ntraf_field_name, 'RAF#' . $tpl_fields['ntraf_field_id']);
		}
		while ( $tpl_fields = $db->sql_fetchrow($result) );
	} // done reading field-list for this template
	$db->sql_freeresult($result);

}// end of function

//
// Here we'll store the information submitted with RAFs into the database!
//
function ntraf_submit_answers($my_topic_id, $my_post_id)
{
	global $db;
	global $ntraf_field_count;
	global $ntraf_field_id, $ntraf_answer;
	
	// local vars
	$my_answer = '';
	
	// let's go for it and iterate over the field-list array(s)
	for ($i=0; $i < $ntraf_field_count; $i++)
	{
		// check if the answer is an array !
		if ( is_array($ntraf_answer[$i]) )
		{
			$my_answer = serialize($ntraf_answer[$i]);
			$answer_isarray = TRUE;
		}
		else
		{
			$my_answer = $ntraf_answer[$i];
			$answer_isarray = FALSE;
		}

		// save the answers with the topic !
		$sql = "INSERT INTO " . NTRAF_ANSWERS_TABLE . " (topic_id, post_id, ntraf_field_id, ntraf_answer,answer_isarray)
		 VALUES ('" . intval($my_topic_id) . "', '" . intval($my_post_id) . "', '" . intval($ntraf_field_id[$i]) ."','" . $my_answer . "', '" . intval($answer_isarray) ."')";
	
		
		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, "Could not insert RequiredAdditionalFields", "", __LINE__, __FILE__, $sql);
		}

	}// end of FOR-iteration ...
	

}// end of function



function ntraf_template_list($my_id, $my_rights, $show_authors)
{
	global $db;
	global $lang;

	// first list-entry doesn't come from DB, because it's for configuring
	// "standard"-forums, that don't require any additional fields!
	if ($my_id == NTRAF_NOT_REQUIRED)
	{
		$s = ' selected="selected"';
	}
	$my_template_list  = '<option value="' . NTRAF_NOT_REQUIRED .'"' . $s . '>' . $lang['Forum_ntraf_not_required'] . '</option>';
	//$my_template_list .= '<option value="' . NTRAF_NOT_REQUIRED .'" >- - - - - - - - - - - - - - - - - - - - - - - -</option>';

	// O.K. The rest of the list is derived from the DB ...
	$sql = "SELECT t.ntraf_template_id, t.template_name, u.username
		FROM ( " . NTRAF_TEMPLATES_TABLE ." t
		LEFT JOIN " . USERS_TABLE . " u ON u.user_id = t.template_author_id )
		ORDER BY template_name";

	if( !$result = $db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
	}


	// now let's build the list
	while( $row = $db->sql_fetchrow($result) )
	{
		$tmp_author = ( $show_authors ) ? '&nbsp;&nbsp;[' . $row['username'] . ']' : '';
		$s = '';
		if ($row['ntraf_template_id'] == $my_id)
		{
			$s = ' selected="selected"';
		}
		$my_template_list .= '<option value="' . $row['ntraf_template_id'] . '"' . $s . '>' . $row['template_name'] . $tmp_author .'</option>';
	}

	return($my_template_list);
}

?>

Coen
Berichten: 5387
Lid geworden op: 03 aug 2004, 10:25

Bericht door Coen » 13 mar 2007, 10:25

Naar mijn weten is deze MOD daar beter voor geschikt. Jouw MOD werkt op een complexe manier om aan extra velden in de database te komen... :roll:

jeroendegier
Berichten: 77
Lid geworden op: 07 feb 2007, 17:49

Bericht door jeroendegier » 13 mar 2007, 22:53

de box die jij liet zien is voor je profiel... ik moest er een hebben voor posting maar ik heb hem bewerkt en het is helemaal gelukt

Gesloten