static function getCompanies() { $options = array(); $options[] = JHtml::_('select.option', 0, 'Select a Company'); $db = JFactory::getDBO(); $query = $db->getQuery(true)->select('id, name')->from('#__fleet_entity as h')->where('h.entity_type=2'); // if user is at company level if ($GLOBALS['user_companies']) { $query = $query->where("id in (" . implode(',', $GLOBALS['user_companies']) . ")"); } elseif ($GLOBALS['user_groups']) { $ctrl = new JFormFieldSearchGroup(); $userCompany = $ctrl->getCompany($GLOBALS['user_groups']); $companyEntityId = $userCompany[0]->value; $query = $query->where('h.id=' . $companyEntityId); } $db->setQuery((string) $query); // echo "kelvin_com3: ".$userCompany[0]->value; // echo (string)$query; $companies = $db->loadObjectList(); if ($companies) { if (sizeof($companies) == 1) { $options = array(); } foreach ($companies as $company) { $options[] = JHtml::_('select.option', $company->id, $company->name); } } return $options; }
require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchcompany.php'; $ctrl = new JFormFieldSearchCompany(); foreach ($ctrl->getCompanies() as $option) { $selected = ''; if ($option->value == $this->company) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } ?> </select> <select name="group" id="group"> <?php require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchgroup.php'; $ctrl = new JFormFieldSearchGroup(); $company = JRequest::getInt('company', 0); foreach ($ctrl->getGroups($company) as $option) { $selected = ''; if ($option->value == $this->group) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } ?> </select> <script> var processCompany = true; function groupChange() { var val = jQuery('#group').val();
require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchcompany.php'; $ctrl = new JFormFieldSearchCompany(); foreach ($ctrl->getCompanies() as $option) { $selected = ''; if ($option->value == $this->company) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } ?> </select> <select name="group" id="group"> <?php require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchgroup.php'; $ctrl = new JFormFieldSearchGroup(); foreach ($ctrl->getGroups() as $option) { $selected = ''; if ($option->value == $this->group) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } ?> </select> <button type="submit" id="update" class="button" onclick="jQuery('#task').val('');"><?php echo JText::_('Update'); ?> </button> <script>
<?php // No direct access to this file defined('_JEXEC') or die('Restricted Access'); include JPATH_COMPONENT . DS . 'models' . DS . 'group_controls.php'; ?> <select name="vehicle" id="vehicle"> <?php require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchgroup.php'; $ctrl = new JFormFieldSearchGroup(); $group = JRequest::getInt('group', 0); if (!$group) { echo '<option value="0">Select Company and Group</option>'; } else { foreach ($ctrl->getVehicles($group) as $option) { $selected = ''; if ($option->value == $this->vehicle) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } } ?> </select> <script> function vehicleChange() { var val = jQuery('#vehicle').val(); if (val != "0" && val != undefined) { url = "<?php
<?php // No direct access to this file defined('_JEXEC') or die('Restricted Access'); include JPATH_COMPONENT . DS . 'models' . DS . 'search_controls.php'; ?> <select name="driver" id="driver"> <?php require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchgroup.php'; $ctrl = new JFormFieldSearchGroup(); $group = JRequest::getInt('group', 0); if (!$group) { echo '<option value="0">Select Company and Group</option>'; } else { foreach ($ctrl->getDrivers($group) as $option) { $selected = ''; if ($option->value == $this->driver) { $selected = ' selected="selected"'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } } ?> </select> <script> var driverChanged = 0; function driverChange() { var val = jQuery('#driver').val(); var trend = jQuery('#trend').val();
function display($tpl = null) { $task = JRequest::getCmd('task', NULL); $cmd = JRequest::getCmd('val', NULL); $select = JRequest::getInt('select', 0); switch ($task) { case 'vehicle': $groups = JFormFieldSelectGroup::getVehicles($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; case 'group': $groups = JFormFieldSearchGroup::getGroups($cmd); $output = ''; foreach ($groups as $group) { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } $data = $output; break; case 'vgroup': $groups = JFormFieldSearchGroup::getGroup($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; case 'select_driver': $groups = JFormFieldSelectGroup::getDriver($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; case 'company': $groups = JFormFieldSearchGroup::getCompany($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; default: break; } $document =& JFactory::getDocument(); $document->setMimeEncoding('application/json'); echo json_encode($data); return false; }
function display($tpl = null) { $task = JRequest::getCmd('task', NULL); $cmd = JRequest::getCmd('val', NULL); $cpval = JRequest::getCmd('cpval', NULL); $val = JRequest::getCmd('cval', NULL); switch ($task) { case 'vehicle': $groups = JFormFieldSearchGroup::getVehicles($cmd); $output = ''; $select = 1; if (!$cmd) { $output .= '<option value="0">Select Company and Group</option>'; } else { foreach ($groups as $group) { if ($val && $group->value == $val && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } } $data = $output; break; case 'driver': $groups = JFormFieldSearchGroup::getDrivers($cmd); $output = ''; $select = 1; if (!$cmd) { $output .= '<option value="0">Select Company and Group</option>'; } else { foreach ($groups as $group) { if ($val && $group->value == $val && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } } $data = $output; break; case 'group': $groups = JFormFieldSearchGroup::getGroups($cmd); $output = ''; foreach ($groups as $group) { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } $data = $output; break; case 'dgroup': $groups = JFormFieldSearchGroup::getDriverGroup($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; case 'vgroup': $groups = JFormFieldSearchGroup::getVehicleGroup($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; case 'company': $groups = JFormFieldSearchGroup::getCompany($cmd); $output = ''; $select = 1; $db =& JFactory::getDBO(); $query = 'select parent_entity_id from #__fleet_entity where id=' . $cmd; $db->setQuery($query); $value = $db->loadResult(); foreach ($groups as $group) { if ($cmd && $group->value == $value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; default: break; } $document =& JFactory::getDocument(); $document->setMimeEncoding('application/json'); echo json_encode($data); return false; }
<?php // No direct access to this file defined('_JEXEC') or die('Restricted Access'); include JPATH_COMPONENT . DS . 'models' . DS . 'group_controls.php'; ?> <select name="vehicle" id="vehicle"> <?php require_once JPATH_COMPONENT . DS . 'models' . DS . 'fields' . DS . 'searchgroup.php'; $ctrl = new JFormFieldSearchGroup(); foreach ($ctrl->getVehicles() as $option) { $selected = ''; if ($option->value == $this->vehicle) { $selected = ' selected'; } echo '<option value="' . $option->value . '"' . $selected . '>' . $option->text . '</option>'; } ?> </select> <script> function vehicleChange() { var val = jQuery('#vehicle').val(); if (val != "0") { url = "<?php echo JRoute::_($this->getRoute() . '&layout=json&format=raw&task=vgroup&val='); ?> "+val; jQuery.getJSON(url, function(data) { jQuery('#company').html(data);