public function exportData() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); // check if export is allowed for this user. $user = JFactory::getUser(); if ($user->authorise('look.export', 'com_demo') && $user->authorise('core.export', 'com_demo')) { // Get the input $input = JFactory::getApplication()->input; $pks = $input->post->get('cid', array(), 'array'); // Sanitize the input JArrayHelper::toInteger($pks); // Get the model $model = $this->getModel('Looks'); // get the data to export $data = $model->getExportData($pks); if (DemoHelper::checkArray($data)) { // now set the data to the spreadsheet $date = JFactory::getDate(); DemoHelper::xls($data, 'Looks_' . $date->format('jS_F_Y'), 'Looks exported (' . $date->format('jS F, Y') . ')', 'looks'); } } // Redirect to the list screen with error. $message = JText::_('COM_DEMO_EXPORT_FAILED'); $this->setRedirect(JRoute::_('index.php?option=com_demo&view=looks', false), $message, 'error'); return; }
/** * display task * * @return void */ function display($cachable = false, $urlparams = false) { // set default view if not set $view = $this->input->getCmd('view', 'Demo'); $data = $this->getViewRelation($view); $layout = $this->input->get('layout', null, 'WORD'); $id = $this->input->getInt('id'); // Check for edit form. if (DemoHelper::checkArray($data)) { if ($data['edit'] && $layout == 'edit' && !$this->checkEditId('com_demo.edit.' . $data['view'], $id)) { // Somehow the person just went to the form - we don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); // check if item was opend from other then its own list view $ref = $this->input->getCmd('ref', 0); $refid = $this->input->getInt('refid', 0); // set redirect if ($refid > 0 && DemoHelper::checkString($ref)) { // redirect to item of ref $this->setRedirect(JRoute::_('index.php?option=com_demo&view=' . (string) $ref . '&layout=edit&id=' . (int) $refid, false)); } elseif (DemoHelper::checkString($ref)) { // redirect to ref $this->setRedirect(JRoute::_('index.php?option=com_demo&view=' . (string) $ref, false)); } else { // normal redirect back to the list view $this->setRedirect(JRoute::_('index.php?option=com_demo&view=' . $data['views'], false)); } return false; } } return parent::display($cachable, $urlparams); }
<div id="j-sidebar-container" class="span2"> <?php echo $this->sidebar; ?> </div> <div id="j-main-container" class="span10"> <?php } else { ?> <div id="j-main-container"> <?php } ?> <?php if ($this->hasPackage && DemoHelper::checkArray($this->headerList) && DemoHelper::checkArray($this->headers)) { ?> <fieldset class="uploadform"> <legend><?php echo JText::_('COM_DEMO_IMPORT_LINK_FILE_TO_TABLE_COLUMNS'); ?> </legend> <div class="control-group"> <label class="control-label" ><h4><?php echo JText::_('COM_DEMO_IMPORT_TABLE_COLUMNS'); ?> </h4></label> <div class="controls"> <label class="control-label" ><h4><?php echo JText::_('COM_DEMO_IMPORT_FILE_COLUMNS'); ?>
/** * 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 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('look', 'demoTable'); if ($table->load(array('alias' => $data['alias'])) && ($table->id != $data['id'] || $data['id'] == 0)) { $msg = JText::_('COM_DEMO_LOOK_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 (DemoHelper::checkArray($uniqeFields)) { foreach ($uniqeFields as $uniqeField) { $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]); } } } if (parent::save($data)) { return true; } return false; }
/** * Save the data from the file to the database * * @param string $package Paths to the uploaded package file * * @return boolean false on failure * **/ protected function save($data, $table) { // import the data if there is any if (DemoHelper::checkArray($data['array'])) { // get user object $user = JFactory::getUser(); // remove header if it has headers $id_key = $data['target_headers']['id']; $published_key = $data['target_headers']['published']; $ordering_key = $data['target_headers']['ordering']; // get the first array set $firstSet = reset($data['array']); // check if first array is a header array and remove if true if ($firstSet[$id_key] == 'id' || $firstSet[$published_key] == 'published' || $firstSet[$ordering_key] == 'ordering') { array_shift($data['array']); } // make sure there is still values in array and that it was not only headers if (DemoHelper::checkArray($data['array']) && $user->authorise($table . '.import', 'com_demo') && $user->authorise('core.import', 'com_demo')) { // set target. $target = array_flip($data['target_headers']); // Get a db connection. $db = JFactory::getDbo(); // set some defaults $todayDate = JFactory::getDate()->toSql(); // get global action permissions $canDo = DemoHelper::getActions($table); $canEdit = $canDo->get('core.edit'); $canState = $canDo->get('core.edit.state'); $canCreate = $canDo->get('core.create'); $hasAlias = $this->getAliasesUsed($table); // prosses the data foreach ($data['array'] as $row) { $found = false; if (isset($row[$id_key]) && is_numeric($row[$id_key]) && $row[$id_key] > 0) { // raw items import & update! $query = $db->getQuery(true); $query->select('version')->from($db->quoteName('#__demo_' . $table))->where($db->quoteName('id') . ' = ' . $db->quote($row[$id_key])); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); $found = $db->getNumRows(); } if ($found && $canEdit) { // update item $id = $row[$id_key]; $version = $db->loadResult(); // reset all buckets $query = $db->getQuery(true); $fields = array(); // Fields to update. foreach ($row as $key => $cell) { // ignore column if ('IGNORE' == $target[$key]) { continue; } // update modified if ('modified_by' == $target[$key]) { continue; } // update modified if ('modified' == $target[$key]) { continue; } // update version if ('version' == $target[$key]) { $cell = (int) $version + 1; } // verify publish authority if ('published' == $target[$key] && !$canState) { continue; } // set to update array if (in_array($key, $data['target_headers']) && is_numeric($cell)) { $fields[] = $db->quoteName($target[$key]) . ' = ' . $cell; } elseif (in_array($key, $data['target_headers']) && is_string($cell)) { $fields[] = $db->quoteName($target[$key]) . ' = ' . $db->quote($cell); } elseif (in_array($key, $data['target_headers']) && is_null($cell)) { // if import data is null then set empty $fields[] = $db->quoteName($target[$key]) . " = ''"; } } // load the defaults $fields[] = $db->quoteName('modified_by') . ' = ' . $db->quote($user->id); $fields[] = $db->quoteName('modified') . ' = ' . $db->quote($todayDate); // Conditions for which records should be updated. $conditions = array($db->quoteName('id') . ' = ' . $id); $query->update($db->quoteName('#__demo_' . $table))->set($fields)->where($conditions); $db->setQuery($query); $db->execute(); } elseif ($canCreate) { // insert item $query = $db->getQuery(true); // reset all buckets $columns = array(); $values = array(); $version = false; // Insert columns. Insert values. foreach ($row as $key => $cell) { // ignore column if ('IGNORE' == $target[$key]) { continue; } // remove id if ('id' == $target[$key]) { continue; } // update created if ('created_by' == $target[$key]) { continue; } // update created if ('created' == $target[$key]) { continue; } // Make sure the alias is incremented if ('alias' == $target[$key]) { $cell = $this->getAlias($cell, $table); } // update version if ('version' == $target[$key]) { $cell = 1; $version = true; } // set to insert array if (in_array($key, $data['target_headers']) && is_numeric($cell)) { $columns[] = $target[$key]; $values[] = $cell; } elseif (in_array($key, $data['target_headers']) && is_string($cell)) { $columns[] = $target[$key]; $values[] = $db->quote($cell); } elseif (in_array($key, $data['target_headers']) && is_null($cell)) { // if import data is null then set empty $columns[] = $target[$key]; $values[] = "''"; } } // load the defaults $columns[] = 'created_by'; $values[] = $db->quote($user->id); $columns[] = 'created'; $values[] = $db->quote($todayDate); if (!$version) { $columns[] = 'version'; $values[] = 1; } // Prepare the insert query. $query->insert($db->quoteName('#__demo_' . $table))->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) { $aId = $db->insertid(); // make sure the access of asset is set DemoHelper::setAsset($aId, $table); } } else { return false; } } return true; } } return false; }
</a></li> <li><b><?php echo JText::_('COM_DEMO_LICENSE'); ?> :</b> <?php echo $manifest->license; ?> </li> <li><b><?php echo $manifest->copyright; ?> </b></li> </ul> <div class="clearfix"></div> <?php if (DemoHelper::checkArray($this->contributors)) { if (count($this->contributors) > 1) { ?> <h3><?php echo JText::_('COM_DEMO_CONTRIBUTORS'); ?> </h3> <?php } else { ?> <h3><?php echo JText::_('COM_DEMO_CONTRIBUTOR'); ?> </h3> <?php }
/** * 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("#__demo_help_document"); if (DemoHelper::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; }
/** * Setting the toolbar */ protected function addToolBar() { JToolBarHelper::title(JText::_('COM_DEMO_HELP_DOCUMENTS'), 'support'); JHtmlSidebar::setAction('index.php?option=com_demo&view=help_documents'); JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields'); if ($this->canCreate) { JToolBarHelper::addNew('help_document.add'); } // Only load if there are items if (DemoHelper::checkArray($this->items)) { if ($this->canEdit) { JToolBarHelper::editList('help_document.edit'); } if ($this->canState) { JToolBarHelper::publishList('help_documents.publish'); JToolBarHelper::unpublishList('help_documents.unpublish'); JToolBarHelper::archiveList('help_documents.archive'); if ($this->canDo->get('core.admin')) { JToolBarHelper::checkin('help_documents.checkin'); } } // Add a batch button if ($this->canBatch && $this->canCreate && $this->canEdit && $this->canState) { // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); // set the batch button name $title = JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button $layout = new JLayoutFile('joomla.toolbar.batch'); // add the button to the page $dhtml = $layout->render(array('title' => $title)); $bar->appendButton('Custom', $dhtml, 'batch'); } if ($this->state->get('filter.published') == -2 && ($this->canState && $this->canDelete)) { JToolbarHelper::deleteList('', 'help_documents.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($this->canState && $this->canDelete) { JToolbarHelper::trash('help_documents.trash'); } if ($this->canDo->get('core.export') && $this->canDo->get('help_document.export')) { JToolBarHelper::custom('help_documents.exportData', 'download', '', 'COM_DEMO_EXPORT_DATA', true); } } if ($this->canDo->get('core.import') && $this->canDo->get('help_document.import')) { JToolBarHelper::custom('help_documents.importData', 'upload', '', 'COM_DEMO_IMPORT_DATA', false); } // set help url for this view if found $help_url = DemoHelper::getHelpUrl('help_documents'); if (DemoHelper::checkString($help_url)) { JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url); } // add the options comp button if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) { JToolBarHelper::preferences('com_demo'); } if ($this->canState) { JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)); // only load if batch allowed if ($this->canBatch) { JHtmlBatch_::addListSelection(JText::_('COM_DEMO_KEEP_ORIGINAL_STATE'), 'batch[published]', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions', array('all' => false)), 'value', 'text', '', true)); } } JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_ACCESS'), 'filter_access', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'))); if ($this->canBatch && $this->canCreate && $this->canEdit) { JHtmlBatch_::addListSelection(JText::_('COM_DEMO_KEEP_ORIGINAL_ACCESS'), 'batch[access]', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text')); } // Set Type Selection $this->typeOptions = $this->getTheTypeSelections(); if ($this->typeOptions) { // Type Filter JHtmlSidebar::addFilter('- Select ' . JText::_('COM_DEMO_HELP_DOCUMENT_TYPE_LABEL') . ' -', 'filter_type', JHtml::_('select.options', $this->typeOptions, 'value', 'text', $this->state->get('filter.type'))); if ($this->canBatch && $this->canCreate && $this->canEdit) { // Type Batch Selection JHtmlBatch_::addListSelection('- Keep Original ' . JText::_('COM_DEMO_HELP_DOCUMENT_TYPE_LABEL') . ' -', 'batch[type]', JHtml::_('select.options', $this->typeOptions, 'value', 'text')); } } // Set Location Selection $this->locationOptions = $this->getTheLocationSelections(); if ($this->locationOptions) { // Location Filter JHtmlSidebar::addFilter('- Select ' . JText::_('COM_DEMO_HELP_DOCUMENT_LOCATION_LABEL') . ' -', 'filter_location', JHtml::_('select.options', $this->locationOptions, 'value', 'text', $this->state->get('filter.location'))); if ($this->canBatch && $this->canCreate && $this->canEdit) { // Location Batch Selection JHtmlBatch_::addListSelection('- Keep Original ' . JText::_('COM_DEMO_HELP_DOCUMENT_LOCATION_LABEL') . ' -', 'batch[location]', JHtml::_('select.options', $this->locationOptions, 'value', 'text')); } } // Set Admin View Selection $this->admin_viewOptions = $this->getTheAdmin_viewSelections(); if ($this->admin_viewOptions) { // Admin View Filter JHtmlSidebar::addFilter('- Select ' . JText::_('COM_DEMO_HELP_DOCUMENT_ADMIN_VIEW_LABEL') . ' -', 'filter_admin_view', JHtml::_('select.options', $this->admin_viewOptions, 'value', 'text', $this->state->get('filter.admin_view'))); if ($this->canBatch && $this->canCreate && $this->canEdit) { // Admin View Batch Selection JHtmlBatch_::addListSelection('- Keep Original ' . JText::_('COM_DEMO_HELP_DOCUMENT_ADMIN_VIEW_LABEL') . ' -', 'batch[admin_view]', JHtml::_('select.options', $this->admin_viewOptions, 'value', 'text')); } } // Set Site View Selection $this->site_viewOptions = $this->getTheSite_viewSelections(); if ($this->site_viewOptions) { // Site View Filter JHtmlSidebar::addFilter('- Select ' . JText::_('COM_DEMO_HELP_DOCUMENT_SITE_VIEW_LABEL') . ' -', 'filter_site_view', JHtml::_('select.options', $this->site_viewOptions, 'value', 'text', $this->state->get('filter.site_view'))); if ($this->canBatch && $this->canCreate && $this->canEdit) { // Site View Batch Selection JHtmlBatch_::addListSelection('- Keep Original ' . JText::_('COM_DEMO_HELP_DOCUMENT_SITE_VIEW_LABEL') . ' -', 'batch[site_view]', JHtml::_('select.options', $this->site_viewOptions, 'value', 'text')); } } }
public function getIcons() { // load user for access menus $user = JFactory::getUser(); // reset icon array $icons = array(); // view groups array $viewGroups = array('main' => array('png.look.add', 'png.looks', 'png.help_documents')); // view access array $viewAccess = array('look.create' => 'look.create', 'looks.access' => 'look.access', 'look.access' => 'look.access', 'looks.submenu' => 'look.submenu', 'looks.dashboard_list' => 'look.dashboard_list', 'look.dashboard_add' => 'look.dashboard_add', 'help_document.create' => 'help_document.create', 'help_documents.access' => 'help_document.access', 'help_document.access' => 'help_document.access', 'help_documents.submenu' => 'help_document.submenu', 'help_documents.dashboard_list' => 'help_document.dashboard_list'); foreach ($viewGroups as $group => $views) { $i = 0; if (DemoHelper::checkArray($views)) { foreach ($views as $view) { $add = false; if (strpos($view, '.') !== false) { $dwd = explode('.', $view); if (count($dwd) == 3) { list($type, $name, $action) = $dwd; } elseif (count($dwd) == 2) { list($type, $name) = $dwd; $action = false; } if ($action) { $viewName = $name; switch ($action) { case 'add': $url = 'index.php?option=com_demo&view=' . $name . '&layout=edit'; $image = $name . '_' . $action . '.' . $type; $alt = $name . ' ' . $action; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U') . '_ADD'; $add = true; break; default: $url = 'index.php?option=com_categories&view=categories&extension=com_demo.' . $name; $image = $name . '_' . $action . '.' . $type; $alt = $name . ' ' . $action; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U') . '_' . DemoHelper::safeString($action, 'U'); break; } } else { $viewName = $name; $alt = $name; $url = 'index.php?option=com_demo&view=' . $name; $image = $name . '.' . $type; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U'); $hover = false; } } else { $viewName = $view; $alt = $view; $url = 'index.php?option=com_demo&view=' . $view; $image = $view . '.png'; $name = ucwords($view) . '<br /><br />'; $hover = false; } // first make sure the view access is set if (DemoHelper::checkArray($viewAccess)) { // setup some defaults $dashboard_add = false; $dashboard_list = false; $accessTo = ''; $accessAdd = ''; // acces checking start $accessCreate = isset($viewAccess[$viewName . '.create']) ? DemoHelper::checkString($viewAccess[$viewName . '.create']) : false; $accessAccess = isset($viewAccess[$viewName . '.access']) ? DemoHelper::checkString($viewAccess[$viewName . '.access']) : false; // set main controllers $accessDashboard_add = isset($viewAccess[$viewName . '.dashboard_add']) ? DemoHelper::checkString($viewAccess[$viewName . '.dashboard_add']) : false; $accessDashboard_list = isset($viewAccess[$viewName . '.dashboard_list']) ? DemoHelper::checkString($viewAccess[$viewName . '.dashboard_list']) : false; // check for adding access if ($add && $accessCreate) { $accessAdd = $viewAccess[$viewName . '.create']; } elseif ($add) { $accessAdd = 'core.create'; } // check if acces to view is set if ($accessAccess) { $accessTo = $viewAccess[$viewName . '.access']; } // set main access controllers if ($accessDashboard_add) { $dashboard_add = $user->authorise($viewAccess[$viewName . '.dashboard_add'], 'com_demo'); } if ($accessDashboard_list) { $dashboard_list = $user->authorise($viewAccess[$viewName . '.dashboard_list'], 'com_demo'); } if (DemoHelper::checkString($accessAdd) && DemoHelper::checkString($accessTo)) { // check access if ($user->authorise($accessAdd, 'com_demo') && $user->authorise($accessTo, 'com_demo') && $dashboard_add) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } elseif (DemoHelper::checkString($accessTo)) { // check access if ($user->authorise($accessTo, 'com_demo') && $dashboard_list) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } elseif (DemoHelper::checkString($accessAdd)) { // check access if ($user->authorise($accessAdd, 'com_demo') && $dashboard_add) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } else { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } else { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } $i++; } } else { $icons[$group][$i] = false; } } return $icons; }