Tuesday 28 February 2012

Changing Rentalotplus so I can a selection of units if wished to the Calendar view.

When creating a menu item for RentalotPlus I get the option to enter 'Unit ID'

If I select '0' then front end I get a calendar with a dropdown that I can select the venue I want.

Or I can enter a unit value - in which case I get a calender for the one unit.

What it doesn't do and what I'd like it to do is for me to enter '1,5,6' etc and be able to choose a selection of units.


OPEN


administrator/components/com_rentalotplus/helpers/view_helper.php

REPLACE the function draw_UC_selectors with the following

[code]

function draw_UC_selectors(&$unit_id, $unit_list, $front_unit_name, $currency_list, $current_currency_code, $controller)
{
$unit_id = trim($unit_id);
$unit_id_list = array();

if ($unit_list === false)
{
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_ERROR_NO_UNITS');
}

if (!empty($unit_id))
// if a specific unit id is specified, check it exists
//$pos = strpos($unit_id, ',');
//echo $pos;
if(strpos($unit_id, ',') || strpos($unit_id, ',')===true){
$unit_ids = explode(',',$unit_id);
//print_r($unit_ids);
foreach($unit_ids as $uid){
if(!empty($uid) && $uid>0){
if(array_key_exists($uid,$unit_list)){

$unit_id_list[$uid] = $unit_list[$uid];
}
}
}
}
else if (!array_key_exists($unit_id,$unit_list)){
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_INVALID_UNIT_ID').' ('.$unit_id.')';

}

if ($currency_list === false)
{
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_ERROR_NO_CURRENCIES');
}

$num_units = count($unit_list);
$num_currencies = count($currency_list);
$unit_html = '';
$html = '';
$draw_form = false;

// if no unit was specified, either select the one and only unit, or draw a select list

if ( empty($unit_id) ) // unit_id can an empty string or zero for automatic selection
{
$unit_id = key($unit_list); // get the first unit id
$unit_html = "\n".'<input type="hidden" name="unit_id" value="'.$unit_id.'" />';
if ($num_units > 1) // if more than one ...
{
$draw_form = true;
$unit_id = JRequest::getVar('unit_id',$unit_id); // get currently selected unit id
$list_html = LA_view::make_list('unit_id', $unit_id, $unit_list, 0 ,'onchange="this.form.submit()"');
$unit_html = "\n".$front_unit_name.' '.$list_html."  ";
}
}


else if(count($unit_id_list)>0){

$unit_id = key($unit_id_list); // get the first unit id
$unit_html = "\n".'<input type="hidden" name="unit_id" value="'.$unit_id.'" />';
if (count($unit_id_list) > 1) // if more than one ...
{
$draw_form = true;
$unit_id = JRequest::getVar('unit_id',$unit_id); // get currently selected unit id
$list_html = LA_view::make_list('unit_id', $unit_id, $unit_id_list, 0 ,'onchange="this.form.submit()"');
$unit_html = "\n".$front_unit_name.' '.$list_html."  ";
}


}
else{ // if unit_id is not empty, pass back the one already selected
$unit_html = "\n".'<input type="hidden" name="unit_id" value="'.$unit_id.'" />';
}
if ($num_currencies > 1)
{
$draw_form = true;
$currency_html = "\n".LA_view::make_list('currency', $current_currency_code, $currency_list, 0, 'onchange="this.form.submit()"');
}
else
$currency_html = '';

if ($draw_form)
{
$html = "\n".'<div class="rentalot_selectors">';
$uri =& JFactory::getURI();
$myuri = $uri->toString();
$html .= "\n".'<form name="selector_form" action="'.$myuri.'" method="post">';
if ($controller != '')
$html .= "\n".'<input type="hidden" name="controller" value="'.$controller.'" />';
$html .= $unit_html;
$html .= $currency_html;

// 4.14.02 - preserve all context

$call_type = JRequest::getVar('call_type', '');
if ($call_type != '')
$html .= "\n".'<input type="hidden" name="call_type" value="'.$call_type.'" />';

$task = JRequest::getVar('task', '');
if ($task != '')
$html .= "\n".'<input type="hidden" name="task" value="'.$task.'" />';

$datefrom = JRequest::getVar('datefrom', '');
if ($datefrom != '')
$html .= "\n".'<input type="hidden" name="datefrom" value="'.$datefrom.'" />';

$dateto = JRequest::getVar('dateto', '');
if ($dateto != '')
$html .= "\n".'<input type="hidden" name="dateto" value="'.$dateto.'" />';

$html .= '</form></div><br /><br />';
}
return $html;

}


function draw_UC_selectors_backup(&$unit_id, $unit_list, $front_unit_name, $currency_list, $current_currency_code, $controller)
{
if ($unit_list === false)
{
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_ERROR_NO_UNITS');
}

if (!empty($unit_id)) // if a specific unit id is specified, check it exists
if (!array_key_exists($unit_id,$unit_list))
{
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_INVALID_UNIT_ID').' ('.$unit_id.')';
}

if ($currency_list === false)
{
$unit_id = -1;
return JText::_('COM_RENTALOTPLUS_ERROR_NO_CURRENCIES');
}

$num_units = count($unit_list);
$num_currencies = count($currency_list);
$unit_html = '';
$html = '';
$draw_form = false;

// if no unit was specified, either select the one and only unit, or draw a select list

if (empty($unit_id)) // unit_id can an empty string or zero for automatic selection
{
$unit_id = key($unit_list); // get the first unit id
$unit_html = "\n".'<input type="hidden" name="unit_id" value="'.$unit_id.'" />';
if ($num_units > 1) // if more than one ...
{
$draw_form = true;
$unit_id = JRequest::getVar('unit_id',$unit_id); // get currently selected unit id
$list_html = LA_view::make_list('unit_id', $unit_id, $unit_list, 0 ,'onchange="this.form.submit()"');
$unit_html = "\n".$front_unit_name.' '.$list_html."  ";
}
}
else // if unit_id is not empty, pass back the one already selected
$unit_html = "\n".'<input type="hidden" name="unit_id" value="'.$unit_id.'" />';

if ($num_currencies > 1)
{
$draw_form = true;
$currency_html = "\n".LA_view::make_list('currency', $current_currency_code, $currency_list, 0, 'onchange="this.form.submit()"');
}
else
$currency_html = '';

if ($draw_form)
{
$html = "\n".'<div class="rentalot_selectors">';
$uri =& JFactory::getURI();
$myuri = $uri->toString();
$html .= "\n".'<form name="selector_form" action="'.$myuri.'" method="post">';
if ($controller != '')
$html .= "\n".'<input type="hidden" name="controller" value="'.$controller.'" />';
$html .= $unit_html;
$html .= $currency_html;

// 4.14.02 - preserve all context

$call_type = JRequest::getVar('call_type', '');
if ($call_type != '')
$html .= "\n".'<input type="hidden" name="call_type" value="'.$call_type.'" />';

$task = JRequest::getVar('task', '');
if ($task != '')
$html .= "\n".'<input type="hidden" name="task" value="'.$task.'" />';

$datefrom = JRequest::getVar('datefrom', '');
if ($datefrom != '')
$html .= "\n".'<input type="hidden" name="datefrom" value="'.$datefrom.'" />';

$dateto = JRequest::getVar('dateto', '');
if ($dateto != '')
$html .= "\n".'<input type="hidden" name="dateto" value="'.$dateto.'" />';

$html .= '</form></div><br /><br />';
}
return $html;

}

{[/code]

No comments: