/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ public function getOptions() { // Get the user object. $user = JFactory::getUser(); // Create a new query object. $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id', 'a.name'), array('id', 'testcompanies_name'))); $query->from($db->quoteName('#__costbenefitprojection_company', 'a')); $query->where($db->quoteName('a.published') . ' = 1'); if (!$user->authorise('core.options', 'com_costbenefitprojection')) { $companies = CostbenefitprojectionHelper::hisCompanies($user->id); if (CostbenefitprojectionHelper::checkArray($companies)) { $companies = implode(',', $companies); // only load this users companies $query->where('a.id IN (' . $companies . ')'); } else { // dont allow user to see any companies $query->where('a.id = -4'); } } $query->order('a.name ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); if ($items) { foreach ($items as $item) { $tmp = array('value' => $item->id, 'text' => ' <strong>' . $item->testcompanies_name . '</strong>', 'checked' => false); $options[] = (object) $tmp; } } return $options; }
public function importData() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); // check if import is allowed for this user. $user = JFactory::getUser(); if ($user->authorise('help_document.import', 'com_costbenefitprojection') && $user->authorise('core.import', 'com_costbenefitprojection')) { // Get the import model $model = $this->getModel('Help_documents'); // get the headers to import $headers = $model->getExImPortHeaders(); if (CostbenefitprojectionHelper::checkObject($headers)) { // Load headers to session. $session = JFactory::getSession(); $headers = json_encode($headers); $session->set('help_document_VDM_IMPORTHEADERS', $headers); $session->set('backto_VDM_IMPORT', 'help_documents'); $session->set('dataType_VDM_IMPORTINTO', 'help_document'); // Redirect to import view. $message = JText::_('COM_COSTBENEFITPROJECTION_IMPORT_SELECT_FILE_FOR_HELP_DOCUMENTS'); $this->setRedirect(JRoute::_('index.php?option=com_costbenefitprojection&view=import', false), $message); return; } } // Redirect to the list screen with error. $message = JText::_('COM_COSTBENEFITPROJECTION_IMPORT_FAILED'); $this->setRedirect(JRoute::_('index.php?option=com_costbenefitprojection&view=help_documents', false), $message, 'error'); return; }
protected function checkEditView($view) { if (CostbenefitprojectionHelper::checkString($view)) { $views = array('company', 'scaling_factor', 'intervention'); // check if this is a edit view if (in_array($view, $views)) { return true; } } return false; }
/** * Setting the toolbar */ protected function addToolBar() { $canDo = CostbenefitprojectionHelper::getActions('costbenefitprojection'); JToolBarHelper::title(JText::_('COM_COSTBENEFITPROJECTION_DASHBOARD'), 'grid-2'); // set help url for this view if found $help_url = CostbenefitprojectionHelper::getHelpUrl('costbenefitprojection'); if (CostbenefitprojectionHelper::checkString($help_url)) { JToolbarHelper::help('COM_COSTBENEFITPROJECTION_HELP_MANAGER', false, $help_url); } if ($canDo->get('core.admin') || $canDo->get('core.options')) { JToolBarHelper::preferences('com_costbenefitprojection'); } }
protected function getViewRelation($view) { if (CostbenefitprojectionHelper::checkString($view)) { $views = array('company' => 'companies', 'service_provider' => 'service_providers', 'country' => 'countries', 'causerisk' => 'causesrisks', 'health_data' => 'health_data_sets', 'scaling_factor' => 'scaling_factors', 'intervention' => 'interventions', 'currency' => 'currencies', 'help_document' => 'help_documents'); // check if this is a list view if (in_array($view, $views)) { return array('edit' => false, 'view' => array_search($view, $views), 'views' => $view); } elseif (array_key_exists($view, $views)) { return array('edit' => true, 'view' => $view, 'views' => $views[$view]); } } return false; }
/** * Setting the toolbar */ protected function addToolBar() { JToolBarHelper::title(JText::_('COM_COSTBENEFITPROJECTION_IMPORT_TITLE'), 'upload'); JHtmlSidebar::setAction('index.php?option=com_costbenefitprojection&view=import'); if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) { JToolBarHelper::preferences('com_costbenefitprojection'); } // set help url for this view if found $help_url = CostbenefitprojectionHelper::getHelpUrl('import'); if (CostbenefitprojectionHelper::checkString($help_url)) { JToolbarHelper::help('COM_COSTBENEFITPROJECTION_HELP_MANAGER', false, $help_url); } }
/** * Method override to check if you can edit an existing record. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // get user object. $user = JFactory::getUser(); // get record id. $recordId = (int) isset($data[$key]) ? $data[$key] : 0; if (!$user->authorise('core.options', 'com_costbenefitprojection')) { // make absolutely sure that this health data can be edited $is = CostbenefitprojectionHelper::userIs($user->id); $countries = CostbenefitprojectionHelper::hisCountries($user->id); $country = CostbenefitprojectionHelper::getId('health_data', $recordId, 'id', 'country'); if (3 != $is || !CostbenefitprojectionHelper::checkArray($countries) || !in_array($country, $countries)) { return false; } } // Access check. $access = $user->authorise('health_data.access', 'com_costbenefitprojection.health_data.' . (int) $recordId) && $user->authorise('health_data.access', 'com_costbenefitprojection'); if (!$access) { return false; } if ($recordId) { // The record has been set. Check the record permissions. $permission = $user->authorise('health_data.edit', 'com_costbenefitprojection.health_data.' . (int) $recordId); if (!$permission && !is_null($permission)) { if ($user->authorise('health_data.edit.own', 'com_costbenefitprojection.health_data.' . $recordId)) { // Now test the owner is the user. $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; if (empty($ownerId)) { // Need to do a lookup from the model. $record = $this->getModel()->getItem($recordId); if (empty($record)) { return false; } $ownerId = $record->created_by; } // If the owner matches 'me' then allow. if ($ownerId == $user->id) { if ($user->authorise('health_data.edit.own', 'com_costbenefitprojection')) { return true; } } } return false; } } // Since there is no permission, revert to the component permissions. return $user->authorise('health_data.edit', $this->option); }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ public function getOptions() { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id', 'a.name', 'a.ref'), array('id', 'causesrisks_name', 'ref'))); $query->from($db->quoteName('#__costbenefitprojection_causerisk', 'a')); $query->where($db->quoteName('a.published') . ' = 1'); $query->order('a.ref ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); $counter = 0; if ($items) { foreach ($items as $item) { $ref = explode('.', $item->ref); $target_id = implode('-', $ref); $key = explode('.0', $item->ref); $key = implode('.', $key); $spacer = array(); $sub = ''; $sub_ = ''; foreach ($ref as $nr => $space) { if ($nr > 1) { $spacer[] = '<span class=\'gi\'>|—</span>'; } if ($nr > 2) { $sub = '<em>'; $sub_ = '</em>'; } } if (CostbenefitprojectionHelper::checkArray($spacer)) { $tmp = array('value' => $item->id, 'text' => '<span id=' . $target_id . ' style=\'color:' . $color . ';\'> ' . implode('', $spacer) . ' ' . $sub . $item->causesrisks_name . $sub_ . ' <small>(' . $key . ')</small></span>', 'checked' => false); $options[] = (object) $tmp; } else { if ($counter & 1) { $color = '#0C5B00'; } else { $color = '#1A3867'; } $tmp = array('value' => $item->id, 'text' => '<span id=' . $target_id . ' style=\'color:' . $color . ';\'> <strong>' . strtoupper($item->causesrisks_name) . '</strong> <small>(' . $key . ')</small></span>', 'checked' => false); $options[] = (object) $tmp; $counter++; } } } return $options; }
/** * Escapes a value for output in a view script. * * @param mixed $var The output to escape. * * @return mixed The escaped value. */ public function escape($var) { // use the helper htmlEscape method instead. return CostbenefitprojectionHelper::htmlEscape($var, $this->_charset); }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ public function getOptions() { // get the input from url $jinput = JFactory::getApplication()->input; // get the view name & id $interId = $jinput->getInt('id', 0); // Get the user object. $user = JFactory::getUser(); $userIs = CostbenefitprojectionHelper::userIs($user->id); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id', 'a.name', 'a.company', 'a.share'), array('id', 'interventions_name', 'company', 'share'))); $query->from($db->quoteName('#__costbenefitprojection_intervention', 'a')); $query->where($db->quoteName('a.published') . ' = 1'); $query->where($db->quoteName('a.id') . ' != ' . $interId); if (!$user->authorise('core.admin')) { $companies = CostbenefitprojectionHelper::hisCompanies($user->id); if (CostbenefitprojectionHelper::checkArray($companies)) { $companies = implode(',', $companies); // only load this users companies $query->where('a.company IN (' . $companies . ')'); } else { // dont allow user to see any companies $query->where('a.company = -4'); } } $query->order('a.name ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); if ($items) { foreach ($items as $item) { if (!CostbenefitprojectionHelper::checkIntervetionAccess($item->id, $item->share, $item->company)) { continue; } if (1 == $userIs) { $options[] = JHtml::_('select.option', $item->id, $item->interventions_name); } else { $compName = CostbenefitprojectionHelper::getId('company', $item->company, 'id', 'name'); $options[] = JHtml::_('select.option', $item->id, $item->interventions_name . ' (' . $compName . ')'); } } } return $options; }
/** * Get UIKIT Components **/ public static function getUikitComp($content, $classes = array()) { if (strpos($content, 'class="uk-') !== false) { // reset $temp = array(); foreach (self::$uk_components as $looking => $add) { if (strpos($content, $looking) !== false) { $temp[] = $looking; } } // make sure uikit is loaded to config if (strpos($content, 'class="uk-') !== false) { self::$uikit = true; } // sorter if (self::checkArray($temp)) { // merger if (self::checkArray($classes)) { $newTemp = array_merge($temp, $classes); $temp = array_unique($newTemp); } return $temp; } } if (self::checkArray($classes)) { return $classes; } return false; }
@owner Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb @copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html /-------------------------------------------------------------------------------------------------------/ Cost Benefit Projection Tool. /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $edit = "index.php?option=com_costbenefitprojection&view=help_documents&task=help_document.edit"; foreach ($this->items as $i => $item) { ?> <?php $canCheckin = $this->user->authorise('core.manage', 'com_checkin') || $item->checked_out == $this->user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = CostbenefitprojectionHelper::getActions('help_document', $item, 'help_documents'); ?> <tr class="row<?php echo $i % 2; ?> "> <td class="order nowrap center hidden-phone"> <?php if ($canDo->get('help_document.edit.state')) { ?> <?php if ($this->saveOrder) { $iconClass = ' inactive'; } else { $iconClass = ' inactive tip-top" hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ public function getOptions() { $jinput = JFactory::getApplication()->input; $client = $jinput->get('id', 0, 'INT'); $countries = CostbenefitprojectionHelper::hisCountries(null, $client, 'company'); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.year', 'a.country'), array('year', 'country'))); $query->from($db->quoteName('#__costbenefitprojection_health_data', 'a')); $query->where($db->quoteName('a.published') . ' = 1'); if (CostbenefitprojectionHelper::checkArray($countries)) { $query->where($db->quoteName('a.country') . ' IN (' . implode(',', $countries) . ')'); } $query->order('a.country ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); if ($items) { $years = array(); foreach ($items as $item) { if (!CostbenefitprojectionHelper::checkArray($years) || !in_array($item->year . '_' . $item->country, $years)) { if (!CostbenefitprojectionHelper::checkArray($countries) || $client == 0) { $countryName = ' (' . CostbenefitprojectionHelper::getCountryName($item->country) . ')'; } else { $countryName = ''; } $options[] = JHtml::_('select.option', $item->year, $item->year . $countryName); $years[$item->year] = $item->year . '_' . $item->country; } } } return $options; }
<?php } ?> </dl> </div> </div> </div> </li> <li> <div data-uk-margin> <?php echo $agepercents_numbers; ?> <div class="uk-visible-large"> <?php $chartsId = CostbenefitprojectionHelper::randomkey(3); ?> <button class="uk-button uk-width-1-1 charttab" data-uk-toggle="{target:'#<?php echo $chartsId; ?> '}"><?php echo JText::_('COM_COSTBENEFITPROJECTION_AGE_GROUP_CHARTS'); ?> </button> <div id="<?php echo $chartsId; ?> " class="uk-hidden"><?php echo $agepercents; ?> </div>
echo JText::_('COM_COSTBENEFITPROJECTION_RELEASE_DATE'); ?> <em><?php echo $manifest->creationDate; ?> </em></li> <li><i class="uk-icon-copyright"></i> <?php echo JText::_('COM_COSTBENEFITPROJECTION_COPYRIGHT_GIZ'); ?> </li> <li><i class="uk-icon-legal"></i> <?php echo JText::_('COM_COSTBENEFITPROJECTION_LICENSE_A_TARGET_BLANK_HREFHTTPSWWWGNUORGLICENSESGPLTWOZEROHTMLGNUGPLA_COMMERCIAL'); ?> </li> <?php if (CostbenefitprojectionHelper::checkArray($contributors)) { foreach ($contributors as $contributor) { ?> <li><i class="uk-icon-stack-overflow"></i> <?php echo $contributor['title']; ?> <br /><?php echo $contributor['name']; ?> </li> <?php } } ?> <li><i class="uk-icon-code"></i> <?php echo JText::_('COM_COSTBENEFITPROJECTION_APPLICATION_DEVELOPER');
</th> <th width="5" data-type="numeric" data-hide="phone,tablet"> <?php echo JText::_('COM_COSTBENEFITPROJECTION_COMPANY_ID'); ?> </th> </tr> </thead> <tbody> <?php foreach ($items as $i => $item) { ?> <?php $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = CostbenefitprojectionHelper::getActions('company', $item, 'companies'); ?> <tr> <td class="nowrap"> <?php if ($canDo->get('company.edit')) { ?> <a href="<?php echo $edit; ?> &id=<?php echo $item->id; ?> &ref=service_provider&refid=<?php echo $id; ?>
/** * Escapes a value for output in a view script. * * @param mixed $var The output to escape. * * @return mixed The escaped value. */ public function escape($var, $sorten = false, $length = 40) { // use the helper htmlEscape method instead. return CostbenefitprojectionHelper::htmlEscape($var, $this->_charset, $sorten, $length); }
</th> <?php foreach ($this->usagedata->items as $items) { ?> <?php foreach ($items as $key => $value) { ?> <?php if ('name' == $key) { break; } elseif (strpos($key, 'employees') !== false) { continue; } ?> <th class="nowrap center" width="16%"><?php echo CostbenefitprojectionHelper::safeString($key, 'Ww'); ?> </th> <?php } ?> <?php break; ?> <?php } ?> </tr> </thead> <tbody> <?php
/** * Escapes a value for output in a view script. * * @param mixed $var The output to escape. * * @return mixed The escaped value. */ public function escape($var) { if (strlen($var) > 50) { // use the helper htmlEscape method instead and shorten the string return CostbenefitprojectionHelper::htmlEscape($var, $this->_charset, true); } // use the helper htmlEscape method instead. return CostbenefitprojectionHelper::htmlEscape($var, $this->_charset); }
</th> <th width="5" data-type="numeric" data-hide="phone,tablet"> <?php echo JText::_('COM_COSTBENEFITPROJECTION_SERVICE_PROVIDER_ID'); ?> </th> </tr> </thead> <tbody> <?php foreach ($items as $i => $item) { ?> <?php $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = CostbenefitprojectionHelper::getActions('service_provider', $item, 'service_providers'); ?> <tr> <td class="nowrap"> <?php if ($canDo->get('service_provider.edit')) { ?> <a href="<?php echo $edit; ?> &id=<?php echo $item->id; ?> &ref=country&refid=<?php echo $id; ?>
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ public function getOptions() { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id', 'a.name', 'a.ref'), array('id', 'causerisk_name', 'ref'))); $query->from($db->quoteName('#__costbenefitprojection_causerisk', 'a')); $query->where($db->quoteName('a.published') . ' = 1'); $query->order('a.ref ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); if ($items) { foreach ($items as $item) { $ref = explode('.', $item->ref); $key = explode('.0', $item->ref); $key = implode('.', $key); $spacer = array(); foreach ($ref as $nr => $space) { if ($nr > 1) { $spacer[] = '|—'; } } if (CostbenefitprojectionHelper::checkArray($spacer)) { $options[] = JHtml::_('select.option', $item->id, implode('', $spacer) . ' ' . $item->causerisk_name . ' (' . $key . ')'); } else { $options[] = JHtml::_('select.option', $item->id, $item->causerisk_name . ' (' . $key . ')'); } } } return $options; }
/-------------------------------------------------------------------------------------------------------/ Cost Benefit Projection Tool. /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $scaled = array('unscaled', 'scaled'); ?> <div id="view_wdls"> <h1><?php echo JText::_('COM_COSTBENEFITPROJECTION_WORK_DAYS_LOST_SUMMARY'); ?> </h1> <?php echo JText::_('COM_COSTBENEFITPROJECTION_TOTAL_DAYS_LOST_AND_CONTRIBUTION_OF_MORBIDITY_MORTALITY_AND_RISK_FACTORS'); if (isset($this->results->items) && CostbenefitprojectionHelper::checkObject($this->results->items)) { ?> <br /><?php echo JText::_('COM_COSTBENEFITPROJECTION_PERCENT_OF_BESTIMATED_BURDENB_BEING_TARGETED_BY_THIS_DISEASERISK_SELECTION'); ?> <b>(<?php echo round($this->results->totals->total_estimated_burden, 3) . '%'; ?> )</b> <?php foreach ($scaled as $scale) { ?> <table id="theTableWDLS_<?php echo $scale; ?> " class="footable table data metro-blue <?php
@owner Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb @copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html /-------------------------------------------------------------------------------------------------------/ Cost Benefit Projection Tool. /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $edit = "index.php?option=com_costbenefitprojection&view=interventions&task=intervention.edit"; foreach ($this->items as $i => $item) { ?> <?php $canCheckin = $this->user->authorise('core.manage', 'com_checkin') || $item->checked_out == $this->user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = CostbenefitprojectionHelper::getActions('intervention', $item, 'interventions'); ?> <tr class="row<?php echo $i % 2; ?> "> <td class="order nowrap center hidden-phone"> <?php if ($canDo->get('intervention.edit.state')) { ?> <?php if ($this->saveOrder) { $iconClass = ' inactive'; } else { $iconClass = ' inactive tip-top" hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); }
} } } } ?> <div id="view_icb"> <div style="margin:0 auto; width: <?php echo $this->Chart['width']; ?> px; height: 100%;"> <h1><?php echo JText::_('COM_COSTBENEFITPROJECTION_INTERVENTION_COST_BENEFIT'); ?> </h1> <?php if (isset($this->results->interventions) && CostbenefitprojectionHelper::checkArray($this->results->interventions)) { ?> <?php $intervention_number = 0; ?> <?php foreach ($this->results->interventions as $intervention) { ?> <?php if (isset($intervention->items)) { ?> <?php foreach ($scaled as $scale) { ?> <div id="icb_<?php echo $intervention_number;
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); // set the metadata to the Item Data if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); $metadata = new JRegistry(); $metadata->loadArray($data['metadata']); $data['metadata'] = (string) $metadata; } // Set the empty causesrisks item to data if (!isset($data['causesrisks'])) { $data['causesrisks'] = ''; } // Set the causesrisks string to JSON string. if (isset($data['causesrisks'])) { $data['causesrisks'] = (string) json_encode($data['causesrisks']); } // Set the Params Items to data if (isset($data['params']) && is_array($data['params'])) { $params = new JRegistry(); $params->loadArray($data['params']); $data['params'] = (string) $params; } // Alter the name for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['published'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (int) $input->get('id') == 0) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['name']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['name']); } $table = JTable::getInstance('country', 'costbenefitprojectionTable'); if ($table->load(array('alias' => $data['alias'])) && ($table->id != $data['id'] || $data['id'] == 0)) { $msg = JText::_('COM_COSTBENEFITPROJECTION_COUNTRY_SAVE_WARNING'); } list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } // Alter the uniqe field for save as copy if ($input->get('task') == 'save2copy') { // Automatic handling of other uniqe fields $uniqeFields = $this->getUniqeFields(); if (CostbenefitprojectionHelper::checkArray($uniqeFields)) { foreach ($uniqeFields as $uniqeField) { $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]); } } } if (parent::save($data)) { return true; } return false; }
?> </option> <?php foreach ($this->headers as $value => $option) { ?> <?php $selected = strtolower($option) == strtolower($title) || strtolower($option) == strtolower($name) ? 'selected="selected"' : ''; ?> <option value="<?php echo CostbenefitprojectionHelper::htmlEscape($value); ?> " class="required" <?php echo $selected; ?> ><?php echo CostbenefitprojectionHelper::htmlEscape($option); ?> </option> <?php } ?> </select> </div> </div> <?php } ?> <div class="form-actions"> <input class="btn btn-primary" type="button" value="<?php echo JText::_('COM_COSTBENEFITPROJECTION_IMPORT_CONTINUE'); ?>
@owner Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb @copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html /-------------------------------------------------------------------------------------------------------/ Cost Benefit Projection Tool. /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $edit = "index.php?option=com_costbenefitprojection&view=countries&task=country.edit"; foreach ($this->items as $i => $item) { ?> <?php $canCheckin = $this->user->authorise('core.manage', 'com_checkin') || $item->checked_out == $this->user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = CostbenefitprojectionHelper::getActions('country', $item, 'countries'); ?> <tr class="row<?php echo $i % 2; ?> "> <td class="order nowrap center hidden-phone"> <?php if ($canDo->get('country.edit.state')) { ?> <?php if ($this->saveOrder) { $iconClass = ' inactive'; } else { $iconClass = ' inactive tip-top" hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); }
/** * Function that allows child controller access to model data * after the data has been saved. * * @param JModel &$model The data model object. * @param array $validData The validated data. * * @return void * * @since 11.1 */ protected function postSaveHook(JModelLegacy $model, $validData = array()) { if ($validData['id'] >= 0) { // get user object $user = JFactory::getUser(); // if id is 0 get id if (0 >= (int) $validData['id']) { // Get the created by id $created_by = isset($validData['created_by']) && $validData['created_by'] > 0 ? $validData['created_by'] : $user->id; // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Select id of this company $query->select($db->quoteName(array('id'))); $query->from($db->quoteName('#__costbenefitprojection_company')); $query->where($db->quoteName('name') . ' = ' . $db->quote($validData['name'])); $query->where($db->quoteName('email') . ' = ' . $db->quote($validData['email'])); $query->where($db->quoteName('country') . ' = ' . (int) $validData['country']); $query->where($db->quoteName('service_provider') . ' = ' . (int) $validData['service_provider']); $query->where($db->quoteName('created_by') . ' = ' . (int) $created_by); if (isset($validData['created'])) { $query->where($db->quoteName('created') . ' = ' . $db->quote($validData['created'])); } $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $validData['id'] = $db->loadResult(); } else { return; } } // user setup if not set if (0 >= (int) $validData['user'] && (int) $validData['id'] > 0) { $userIs = CostbenefitprojectionHelper::userIs($user->id); if (1 == $userIs) { // this is a company so just use its id $userId = $user->id; // add this user id to this company $validData['user'] = $userId; $model->save($validData); } else { // setup config array $newUser = array('name' => $validData['name'], 'email' => $validData['email']); $userId = CostbenefitprojectionHelper::createUser($newUser); if (!is_int($userId)) { $this->setMessage($userId, 'error'); } else { // add this user id to this company $validData['user'] = $userId; $model->save($validData); } } } // only continue if we have a company id if ((int) $validData['id'] > 0) { // get params $params = JComponentHelper::getParams('com_costbenefitprojection'); // get all this users companies $hisCompanies = CostbenefitprojectionHelper::hisCompanies($validData['user']); if (CostbenefitprojectionHelper::checkArray($hisCompanies)) { // set the user group based on the overall status of its companies $departments = CostbenefitprojectionHelper::getVars('company', $hisCompanies, 'id', 'department'); if (in_array(2, $departments)) { $memberGroups = $params->get('advancedmembergroup'); } else { $memberGroups = $params->get('memberbasicgroup'); } } else { // first company so act simply on this company department status if (2 == $validData['department']) { $memberGroups = $params->get('advancedmembergroup'); } else { $memberGroups = $params->get('memberbasicgroup'); } } // update the user groups JUserHelper::setUserGroups((int) $validData['user'], (array) $memberGroups); // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Select all records in scaling factors the belong to this company $query->select($db->quoteName(array('id', 'causerisk', 'published'))); $query->from($db->quoteName('#__costbenefitprojection_scaling_factor')); $query->where($db->quoteName('company') . ' = ' . (int) $validData['id']); $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { // load the scaling factors already set $already = $db->loadObjectList(); $publish = array(); $archive = array(); $bucket = array(); foreach ($already as $scale) { if (CostbenefitprojectionHelper::checkArray($validData['causesrisks'])) { if (in_array($scale->causerisk, $validData['causesrisks']) && $scale->published != 1) { // publish the scaling factor (update) $publish[$scale->id] = $scale->id; } elseif (!in_array($scale->causerisk, $validData['causesrisks'])) { // archive the scaling factor (update) $archive[$scale->id] = $scale->id; } $bucket[] = $scale->causerisk; } else { // archive the scaling factor (update) $archive[$scale->id] = $scale->id; } } // update the needed records $types = array('publish' => 1, 'archive' => 2); foreach ($types as $type => $int) { if (CostbenefitprojectionHelper::checkArray(${$type})) { foreach (${$type} as $id) { $query = $db->getQuery(true); // Fields to update. $fields = array($db->quoteName('published') . ' = ' . (int) $int); // Conditions for which records should be updated. $conditions = array($db->quoteName('id') . ' = ' . (int) $id); $query->update($db->quoteName('#__costbenefitprojection_scaling_factor'))->set($fields)->where($conditions); $db->setQuery($query); $db->execute(); } } } } if (CostbenefitprojectionHelper::checkArray($validData['causesrisks'])) { // remove those already set from the saved list of causesrisks if (CostbenefitprojectionHelper::checkArray($bucket)) { $insert = array(); foreach ($validData['causesrisks'] as $causerisk) { if (!in_array($causerisk, $bucket)) { $insert[] = $causerisk; } } } else { $insert = $validData['causesrisks']; } } // insert the new records if (CostbenefitprojectionHelper::checkArray($insert)) { $created = $db->quote(JFactory::getDate()->toSql()); $created_by = JFactory::getUser()->get('id'); $company = $validData['id']; // Create a new query object. $query = $db->getQuery(true); // Insert columns. $columns = array('causerisk', 'company', 'mortality_scaling_factor_females', 'mortality_scaling_factor_males', 'presenteeism_scaling_factor_females', 'presenteeism_scaling_factor_males', 'yld_scaling_factor_females', 'yld_scaling_factor_males', 'published', 'created_by', 'created'); // setup the values $values = array(); foreach ($insert as $new) { $array = array($new, $company, 1, 1, 1, 1, 1, 1, 1, $created_by, $created); $values[] = implode(',', $array); } // Prepare the insert query. $query->insert($db->quoteName('#__costbenefitprojection_scaling_factor'))->columns($db->quoteName($columns))->values(implode('), (', $values)); // Set the query using our newly populated query object and execute it. $db->setQuery($query); $done = $db->execute(); if ($done) { // we must set the assets foreach ($insert as $causerisk) { // get all the ids. Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('id'))); $query->from($db->quoteName('#__costbenefitprojection_scaling_factor')); $query->where($db->quoteName('causerisk') . ' = ' . (int) $causerisk); $query->where($db->quoteName('company') . ' = ' . (int) $company); $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $aId = $db->loadResult(); // make sure the access of asset is set CostbenefitprojectionHelper::setAsset($aId, 'scaling_factor'); } } } } } } return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); // set the metadata to the Item Data if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); $metadata = new JRegistry(); $metadata->loadArray($data['metadata']); $data['metadata'] = (string) $metadata; } // Set the empty testcompanies item to data if (!isset($data['testcompanies'])) { $data['testcompanies'] = ''; } // Set the testcompanies string to JSON string. if (isset($data['testcompanies'])) { $data['testcompanies'] = (string) json_encode($data['testcompanies']); } // Set the Params Items to data if (isset($data['params']) && is_array($data['params'])) { $params = new JRegistry(); $params->loadArray($data['params']); $data['params'] = (string) $params; } // Alter the uniqe field for save as copy if ($input->get('task') == 'save2copy') { // Automatic handling of other uniqe fields $uniqeFields = $this->getUniqeFields(); if (CostbenefitprojectionHelper::checkArray($uniqeFields)) { foreach ($uniqeFields as $uniqeField) { $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]); } } } if (parent::save($data)) { return true; } return false; }
/** * Method to get header. * * @return mixed An array of data items on success, false on failure. */ public function getExImPortHeaders() { // Get a db connection. $db = JFactory::getDbo(); // get the columns $columns = $db->getTableColumns("#__costbenefitprojection_causerisk"); if (CostbenefitprojectionHelper::checkArray($columns)) { // remove the headers you don't import/export. unset($columns['asset_id']); unset($columns['checked_out']); unset($columns['checked_out_time']); $headers = new stdClass(); foreach ($columns as $column => $type) { $headers->{$column} = $column; } return $headers; } return false; }