protected function checkEditView($view)
 {
     if (DemoHelper::checkString($view)) {
         $views = array();
         // check if this is a edit view
         if (in_array($view, $views)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Setting the toolbar
  */
 protected function addToolBar()
 {
     JToolBarHelper::title(JText::_('COM_DEMO_IMPORT_TITLE'), 'upload');
     JHtmlSidebar::setAction('index.php?option=com_demo&view=import');
     if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) {
         JToolBarHelper::preferences('com_demo');
     }
     // set help url for this view if found
     $help_url = DemoHelper::getHelpUrl('import');
     if (DemoHelper::checkString($help_url)) {
         JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url);
     }
 }
 protected function getViewRelation($view)
 {
     if (DemoHelper::checkString($view)) {
         $views = array('look' => 'looks', '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()
 {
     $canDo = DemoHelper::getActions('demo');
     JToolBarHelper::title(JText::_('COM_DEMO_DASHBOARD'), 'grid-2');
     // set help url for this view if found
     $help_url = DemoHelper::getHelpUrl('demo');
     if (DemoHelper::checkString($help_url)) {
         JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url);
     }
     if ($canDo->get('core.admin') || $canDo->get('core.options')) {
         JToolBarHelper::preferences('com_demo');
     }
 }
 /**
  * Method to validate the form data.
  *
  * @param   JForm   $form   The form to validate against.
  * @param   array   $data   The data to validate.
  * @param   string  $group  The name of the field group to validate.
  *
  * @return  mixed  Array of filtered data if valid, false otherwise.
  *
  * @see     JFormRule
  * @see     JFilterInput
  * @since   12.2
  */
 public function validate($form, $data, $group = null)
 {
     // check if the not_required field is set
     if (DemoHelper::checkString($data['not_required'])) {
         $requiredFields = (array) explode(',', (string) $data['not_required']);
         $requiredFields = array_unique($requiredFields);
         // now change the required field attributes value
         foreach ($requiredFields as $requiredField) {
             // make sure there is a string value
             if (DemoHelper::checkString($requiredField)) {
                 // change to false
                 $form->setFieldAttribute($requiredField, 'required', 'false');
                 // also clear the data set
                 $data[$requiredField] = '';
             }
         }
     }
     return parent::validate($form, $data, $group);
 }
 /**
  * Setting the toolbar
  */
 protected function addToolBar()
 {
     JFactory::getApplication()->input->set('hidemainmenu', true);
     $user = JFactory::getUser();
     $userId = $user->id;
     $isNew = $this->item->id == 0;
     JToolbarHelper::title(JText::_($isNew ? 'COM_DEMO_HELP_DOCUMENT_NEW' : 'COM_DEMO_HELP_DOCUMENT_EDIT'), 'pencil-2 article-add');
     // Built the actions for new and existing records.
     if ($this->refid || $this->ref) {
         if ($this->canDo->get('help_document.create') && $isNew) {
             // We can create the record.
             JToolBarHelper::save('help_document.save', 'JTOOLBAR_SAVE');
         } elseif ($this->canDo->get('help_document.edit')) {
             // We can save the record.
             JToolBarHelper::save('help_document.save', 'JTOOLBAR_SAVE');
         }
         if ($isNew) {
             // Do not creat but cancel.
             JToolBarHelper::cancel('help_document.cancel', 'JTOOLBAR_CANCEL');
         } else {
             // We can close it.
             JToolBarHelper::cancel('help_document.cancel', 'JTOOLBAR_CLOSE');
         }
     } else {
         if ($isNew) {
             // For new records, check the create permission.
             if ($this->canDo->get('help_document.create')) {
                 JToolBarHelper::apply('help_document.apply', 'JTOOLBAR_APPLY');
                 JToolBarHelper::save('help_document.save', 'JTOOLBAR_SAVE');
                 JToolBarHelper::custom('help_document.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
             }
             JToolBarHelper::cancel('help_document.cancel', 'JTOOLBAR_CANCEL');
         } else {
             if ($this->canDo->get('help_document.edit')) {
                 // We can save the new record
                 JToolBarHelper::apply('help_document.apply', 'JTOOLBAR_APPLY');
                 JToolBarHelper::save('help_document.save', 'JTOOLBAR_SAVE');
                 // We can save this record, but check the create permission to see
                 // if we can return to make a new one.
                 if ($this->canDo->get('help_document.create')) {
                     JToolBarHelper::custom('help_document.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
                 }
             }
             $canVersion = $this->canDo->get('core.version') && $this->canDo->get('help_document.version');
             if ($this->state->params->get('save_history', 1) && $this->canDo->get('help_document.edit') && $canVersion) {
                 JToolbarHelper::versions('com_demo.help_document', $this->item->id);
             }
             if ($this->canDo->get('help_document.create')) {
                 JToolBarHelper::custom('help_document.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
             }
             JToolBarHelper::cancel('help_document.cancel', 'JTOOLBAR_CLOSE');
         }
     }
     JToolbarHelper::divider();
     // set help url for this view if found
     $help_url = DemoHelper::getHelpUrl('help_document');
     if (DemoHelper::checkString($help_url)) {
         JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url);
     }
 }
 /**
  * Method to convert selection values to translatable string.
  *
  * @return translatable string
  */
 public function selectionTranslation($value, $name)
 {
     // Array of type language strings
     if ($name == 'type') {
         $typeArray = array(0 => 'COM_DEMO_HELP_DOCUMENT_SELECT_AN_OPTION', 1 => 'COM_DEMO_HELP_DOCUMENT_JOOMLA_ARTICLE', 2 => 'COM_DEMO_HELP_DOCUMENT_TEXT', 3 => 'COM_DEMO_HELP_DOCUMENT_URL');
         // Now check if value is found in this array
         if (isset($typeArray[$value]) && DemoHelper::checkString($typeArray[$value])) {
             return $typeArray[$value];
         }
     }
     // Array of location language strings
     if ($name == 'location') {
         $locationArray = array(1 => 'COM_DEMO_HELP_DOCUMENT_ADMIN', 2 => 'COM_DEMO_HELP_DOCUMENT_SITE');
         // Now check if value is found in this array
         if (isset($locationArray[$value]) && DemoHelper::checkString($locationArray[$value])) {
             return $locationArray[$value];
         }
     }
     return $value;
 }
 /**
  * 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;
 }
 /**
  * Method to convert selection values to translatable string.
  *
  * @return translatable string
  */
 public function selectionTranslation($value, $name)
 {
     // Array of add language strings
     if ($name == 'add') {
         $addArray = array(1 => 'COM_DEMO_LOOK_YES', 0 => 'COM_DEMO_LOOK_NO');
         // Now check if value is found in this array
         if (isset($addArray[$value]) && DemoHelper::checkString($addArray[$value])) {
             return $addArray[$value];
         }
     }
     return $value;
 }