Jump to content

Recommended Posts

Posted

In the admin panel, my rank auto-calculate is set to false, so there is a dropdown box to select the pilots rank. This dropdown box always shows the lowest rank "officer cadet". The same thing happens for the custom field dropdowns. I think I've identified the problem codes but cant figure out why they're wrong.

Rank code:

<tr>
<td>Current Rank</td>
<td>
<?php
if(Config::Get('RANKS_AUTOCALCULATE') == false)
{
	$allranks = RanksData::GetAllRanks();
	echo '<select name="rank">';

	foreach($allranks as $rank)
	{
		echo "<option value=\"{$rank->rankid}\">{$rank->rank}</option>";
	}
	echo '</select>';
}
else
{
	echo $pilotinfo->rank;
}
?></td>
</tr>

Custom Field code:

<?php
if($customfields)
{
foreach($customfields as $field)
{
?>
<tr>
	<td><?php echo $field->title;?></td>
	<td>
	<?php
	if($field->type == 'dropdown')
	{
		echo "<select name=\"{$field->fieldname}\">";
		$values = explode(',', $field->fieldvalues);

		if(is_array($values))
		{						
			foreach($values as $val)
			{
				$sel = ($field->value === $val) ? 'sel="selected"' : '';

				$val = trim($val);
				echo "<option value=\"{$val}\" {$sel} >{$val}</option>";
			}
		}

		echo '</select>';
	}
	elseif($field->type == 'textarea')
;... rest doesnt apply because text areas show up fine

What I'm thinking is wrong is that it it loads the options, but it doesn't load the current value. Any suggestions?

Thanks

Posted

I fixed the code for this one, just the formatting messed up now. All the custom field are inline with each other, I tryed adding some </br>'s but none of the worked. Heres the code:

<tr>
<?php
if($customfields)
{
	foreach($customfields as $field)
	{
		echo '<td>'.$field->title.'</td>
			  <td>';

		if($field->type == 'dropdown')
		{
			$field_values = SettingsData::GetField($field->fieldid);				
			$values = explode(',', $field_values->value);


			echo "<select name=\"{$field->fieldname}\">";

			if(is_array($values))
			{						
				foreach($values as $val)
				{
					$val = trim($val);

					if($val == $field->value)
						$sel = " selected ";
					else
						$sel = '';

					echo "<option value=\"{$val}\" {$sel}>{$val}</option>";
				}
			}

			echo '</select>';
		}
		elseif($field->type == 'textarea')
		{
			echo '<textarea class="customfield_textarea"></textarea>';
		}
		else
		{
			echo '<input type="text" name="'.$field->fieldname.'" value="'.$field->value.'" />';
		}

		echo '</td>';
	}
}
?>	
</tr>

Posted

The dropdown is loaded from the database, so it's loading by lowest ID. Try changing:

echo "<option value=\"{$rank->rankid}\">{$rank->rank}</option>";

to:

echo "<option value=\"{$rank->rank}\">{$rank->rank}</option>";

That will sort them alphabetically, not by the unique key from the database table.

  • Administrators
Posted

The dropdown is loaded from the database, so it's loading by lowest ID. Try changing:

echo "<option value=\"{$rank->rankid}\">{$rank->rank}</option>";

to:

echo "<option value=\"{$rank->rank}\">{$rank->rank}</option>";

That will sort them alphabetically, not by the unique key from the database table.

That will break the saving of the rank, as it's relying on the the ID being in the value

Posted

I'll file it on gihub then I guess, whatever it is. If anybody else has any ideas please let me know, my VA almost fully functional except for the rank thing and a little booking module that I'm making.

  • 2 weeks later...
Posted

Couldn't find link on your profile, I fixed it myself. In /admin/templates/pilots_details.tpl replace the ranks section with this one:

<tr>
<td>Current Rank</td>
<td>
<?php
if(Config::Get('RANKS_AUTOCALCULATE') == false)
{
	$allranks = RanksData::GetAllRanks();
	echo '<select name="rank">';
	foreach($allranks as $rank)
	{
		if($pilotinfo->rank == $rank->rank)
			$sel = ' selected';
		else
			$sel = '';

		echo '<option value="'.$rank->rank.'" '.$sel.'>'.$rank->rank.'</option>';
		// echo "<option value=\"{$rank->rankid}\" {$sel}>{$rank->rank}</option>";
	}
	echo '</select>';
}
else
{
	echo $pilotinfo->rank;
}
?></td>
</tr>

  • 3 weeks later...
Posted

Couldn't find link on your profile, I fixed it myself. In /admin/templates/pilots_details.tpl replace the ranks section with this one:

<tr>
<td>Current Rank</td>
<td>
<?php
if(Config::Get('RANKS_AUTOCALCULATE') == false)
{
	$allranks = RanksData::GetAllRanks();
	echo '<select name="rank">';
	foreach($allranks as $rank)
	{
		if($pilotinfo->rank == $rank->rank)
			$sel = ' selected';
		else
			$sel = '';

		echo '<option value="'.$rank->rank.'" '.$sel.'>'.$rank->rank.'</option>';
		// echo "<option value=\"{$rank->rankid}\" {$sel}>{$rank->rank}</option>";
	}
	echo '</select>';
}
else
{
	echo $pilotinfo->rank;
}
?></td>
</tr>

Aaron, I tried it and it works. Great.

At first I put the altered template in my Skins directory but it had no effect. I changed the tpl in the Admin folder and it works.

I suppose it will revert back to the old template with the next update?

Cheers,

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.

Loading...
×
×
  • Create New...