Exemplo n.º 1
0
 /**
  * this merges session data for the fromForm with any request data
  * allowing us to filter data results from both search forms and filters
  *
  * @return array
  */
 function getFilters()
 {
     //form or detailed views should not apply filters? what about querystrings to set up the default values?
     if (JRequest::getCmd('view') == 'details' || JRequest::getCmd('view') == 'form') {
         $this->_request = array();
         return $this->_request;
     }
     if (isset($this->_request)) {
         return $this->_request;
     }
     $filters = array();
     // $$$ rob clears all list filters, and does NOT apply any
     // other filters to the table, even if in querystring
     if (JRequest::getInt('clearfilters') === 1 && $this->activeTable()) {
         $this->clearFilters();
         $this->_request = array();
         return $this->_request;
     }
     if (JRequest::getVar('replacefilters') == 1) {
         $this->clearFilters();
     }
     //$$$ fehers The filter is cleared and applied at once without having to clear it first and then apply it (would have to be two clicks).
     //useful in querystring filters if you want to clear old filters and apply new filters
     // $$$ rob 20/03/2011 - request resetfilters should overwrite menu option - otherwise filter then nav will remove filter.
     if ((JRequest::getVar('filterclear') == 1 || FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request') == 1) && $this->activeTable()) {
         $this->clearFilters();
     }
     //overwrite filters with querystring filter
     $this->getQuerystringFilters($filters);
     FabrikHelperHTML::debug($filters, 'filter array: after querystring filters');
     $request =& $this->getPostFilterArray();
     $this->counter = count(JArrayHelper::getValue($request, 'key', array()));
     //overwrite filters with session filters (fabrik_incsessionfilters set to false in listModel::getRecordCounts / for facted data counts
     if (JRequest::getVar('fabrik_incsessionfilters', true)) {
         $this->getSessionFilters($filters);
     }
     FabrikHelperHTML::debug($filters, 'filter array: after session filters');
     //the search form search all has lower priority than the filter search all and search form filters
     $this->getSearchFormSearchAllFilters($filters);
     //overwrite session filters with search form filters
     $this->getSearchFormFilters($filters);
     FabrikHelperHTML::debug($filters, 'filter array: search form');
     //overwrite filters with 'search all' filter
     $this->getSearchAllFilters($filters);
     //finally overwrite filters with post filters
     $this->getPostFilters($filters);
     FabrikHelperHTML::debug($filters, 'filter array: after getpostfilters');
     $this->_request = $filters;
     FabrikHelperHTML::debug($this->_request, 'filter array');
     $this->checkAccess($filters);
     // echo "<pre>";print_r($filters);echo "</pre>";
     return $filters;
 }
Exemplo n.º 2
0
 /**
  * @access private
  * create the sql query to get the rows data for insertion into the form
  */
 function _buildQuery()
 {
     if (isset($this->query)) {
         return $this->query;
     }
     $db = FabrikWorker::getDbo();
     $conf = JFactory::getConfig();
     $form = $this->getForm();
     if (!$form->record_in_database) {
         return;
     }
     $listModel = $this->getListModel();
     $item = $listModel->getTable();
     $sql = $listModel->_buildQuerySelect();
     $sql .= $listModel->_buildQueryJoin();
     $emptyRowId = $this->_rowId === '' ? true : false;
     $random = JRequest::getVar('random');
     $usekey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot);
     if ($usekey != '') {
         $usekey = explode('|', $usekey);
         foreach ($usekey as &$tmpk) {
             $tmpk = !strstr($tmpk, '.') ? $item->db_table_name . '.' . $tmpk : $tmpk;
             $tmpk = FabrikString::safeColName($tmpk);
         }
         if (!is_array($this->_rowId)) {
             $aRowIds = explode('|', $this->_rowId);
         }
     }
     $comparison = JRequest::getVar('usekey_comparison', '=');
     $viewpk = JRequest::getVar('view_primary_key');
     // $$$ hugh - changed this to !==, as in rowid=-1/usekey situations, we can have a rowid of 0
     // I don't THINK this will have any untoward side effects, but ...
     if (!$random && !$emptyRowId) {
         $sql .= ' WHERE ';
         if (!empty($usekey)) {
             $sql .= "(";
             $parts = array();
             for ($k = 0; $k < count($usekey); $k++) {
                 //ensure that the key value is not quoted as we Quote() afterwards
                 if (strstr($aRowIds[$k], "'")) {
                     $aRowIds[$k] = str_replace("'", '', $aRowIds[$k]);
                 }
                 if ($comparison == '=') {
                     $parts[] = ' ' . $usekey[$k] . ' = ' . $db->quote($aRowIds[$k]);
                 } else {
                     $parts[] = ' ' . $usekey[$k] . ' LIKE ' . $db->quote('%' . $aRowIds[$k] . '%');
                 }
             }
             $sql .= implode(' AND ', $parts);
             $sql .= ')';
         } else {
             $sql .= ' ' . $item->db_primary_key . ' = ' . $db->quote($this->_rowId);
         }
     } else {
         if ($viewpk != '') {
             $sql .= ' WHERE ' . $viewpk . ' ';
         } else {
             if ($random) {
                 // $$$ rob Should this not go after prefilters have been applied ?
                 $sql .= ' ORDER BY RAND() LIMIT 1 ';
             }
         }
     }
     // get prefilter conditions from table and apply them to the record
     //the false, ignores any filters set by the table
     $where = $listModel->_buildQueryWhere(false);
     if (strstr($sql, 'WHERE') && $this->_rowId != '') {
         //do it this way as queries may contain subquerues which we want to keep the where
         $firstword = substr($where, 0, 5);
         if ($firstword == 'WHERE') {
             $where = substr_replace($where, 'AND', 0, 5);
         }
     }
     //set rowId to -2 to indicate random record
     if ($random) {
         $this->_rowId = -2;
     }
     // $$$ rob ensure that all prefilters are wrapped in brackets so that
     // only one record is loaded by the query - might need to set $word = and?
     if (trim($where) != '') {
         $where = explode(' ', $where);
         $word = array_shift($where);
         $sql .= $word . ' (' . implode(' ', $where) . ')';
     }
     if (!$random) {
         // $$$ rob if showing joined repeat groups we want to be able to order them as defined in the table
         $sql .= $listModel->_buildQueryOrder();
     }
     $this->query = $sql;
     return $sql;
 }
Exemplo n.º 3
0
 /**
  * Get the table template
  *
  * @since 3.0
  *
  * @return string template name
  */
 public function getTmpl()
 {
     if (!isset($this->tmpl)) {
         $input = $this->app->input;
         $item = $this->getTable();
         $params = $this->getParams();
         $document = JFactory::getDocument();
         if ($this->app->isAdmin()) {
             $this->tmpl = $input->get('layout', $params->get('admin_template'));
         } else {
             $this->tmpl = $input->get('layout', $item->template);
             if ($this->app->scope !== 'mod_fabrik_list') {
                 $this->tmpl = FabrikWorker::getMenuOrRequestVar('fabriklayout', $this->tmpl, $this->isMambot);
                 /* $$$ rob 10/03/2012 changed menu param to listlayout to avoid the list menu item
                  * options also being used for the form/details view template
                  */
                 $this->tmpl = FabrikWorker::getMenuOrRequestVar('listlayout', $this->tmpl, $this->isMambot);
             }
         }
         if ($this->tmpl == '' || !FabrikWorker::j3() && $this->tmpl === 'bootstrap') {
             $this->tmpl = FabrikWorker::j3() ? 'bootstrap' : 'default';
         }
         if ($this->app->scope !== 'mod_fabrik_list') {
             /* $$$ rob 10/03/2012 changed menu param to listlayout to avoid the list menu item
              * options also being used for the form/details view template
              */
             // $this->tmpl = FabrikWorker::getMenuOrRequestVar('fabriklayout', $this->tmpl, $this->isMambot);
             $this->tmpl = FabrikWorker::getMenuOrRequestVar('listlayout', $this->tmpl, $this->isMambot);
         }
         if ($document->getType() === 'pdf') {
             $this->tmpl = $params->get('pdf_template', $this->tmpl);
         }
         // Migration test
         if (FabrikWorker::j3()) {
             $modFolder = JPATH_SITE . '/templates/' . $this->app->getTemplate() . '/html/com_fabrik/list/' . $this->tmpl;
             $componentFolder = JPATH_SITE . '/components/com_fabrik/views/list/tmpl/' . $this->tmpl;
         } else {
             $modFolder = JPATH_SITE . '/templates/' . $this->app->getTemplate() . '/themes/' . $this->tmpl;
             $componentFolder = JPATH_SITE . '/components/com_fabrik/views/list/tmpl25/' . $this->tmpl;
         }
         if (!JFolder::exists($componentFolder) && !JFolder::exists($modFolder)) {
             $this->tmpl = FabrikWorker::j3() ? 'bootstrap' : 'default';
         }
     }
     return $this->tmpl;
 }
Exemplo n.º 4
0
 /**
  * Display the template
  *
  * @param   sting $tpl template
  *
  * @return void
  */
 public function display($tpl = null)
 {
     if ($this->getLayout() == '_advancedsearch') {
         $this->advancedSearch($tpl);
         return;
     }
     $fbConfig = JComponentHelper::getParams('com_fabrik');
     $profiler = JProfiler::getInstance('Application');
     $input = $this->app->input;
     /** @var FabrikFEModelList $model */
     $model = $this->getModel();
     // Force front end templates
     $tmpl = $model->getTmpl();
     $this->_basePath = COM_FABRIK_FRONTEND . '/views';
     $jTmplFolder = FabrikWorker::j3() ? 'tmpl' : 'tmpl25';
     $this->addTemplatePath($this->_basePath . '/' . $this->_name . '/' . $jTmplFolder . '/' . $tmpl);
     $root = $this->app->isAdmin() ? JPATH_ADMINISTRATOR : JPATH_SITE;
     $this->addTemplatePath($root . '/templates/' . $this->app->getTemplate() . '/html/com_fabrik/list/' . $tmpl);
     $item = $model->getTable();
     $data = $model->render();
     $w = new FabrikWorker();
     // Add in some styling short cuts
     $c = 0;
     $form = $model->getFormModel();
     $nav = $model->getPagination();
     foreach ($data as $groupk => $group) {
         $num_rows = 1;
         foreach (array_keys($group) as $i) {
             $o = new stdClass();
             // $$$ rob moved merge wip code to FabrikModelTable::formatForJoins() - should contain fix for pagination
             $o->data = $data[$groupk][$i];
             $o->cursor = $num_rows + $nav->limitstart;
             $o->total = $nav->total;
             $o->id = 'list_' . $model->getRenderContext() . '_row_' . @$o->data->__pk_val;
             $o->class = 'fabrik_row oddRow' . $c;
             $data[$groupk][$i] = $o;
             $c = 1 - $c;
             $num_rows++;
         }
     }
     $groups = $form->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getPublishedElements();
         foreach ($elementModels as $elementModel) {
             $elementModel->setContext($groupModel, $form, $model);
             $elementModel->setRowClass($data);
         }
     }
     $this->rows = $data;
     reset($this->rows);
     // Cant use numeric key '0' as group by uses grouped name as key
     $firstRow = current($this->rows);
     $this->requiredFiltersFound = $model->getRequiredFiltersFound();
     $this->advancedSearch = $model->getAdvancedSearchLink();
     $this->advancedSearchURL = $model->getAdvancedSearchURL();
     $this->nodata = empty($this->rows) || count($this->rows) == 1 && empty($firstRow) || !$this->requiredFiltersFound ? true : false;
     $this->tableStyle = $this->nodata ? 'display:none' : '';
     $this->emptyStyle = $this->nodata ? '' : 'display:none';
     $params = $model->getParams();
     if (!$this->access($model)) {
         return false;
     }
     if (!class_exists('JSite')) {
         require_once JPATH_ROOT . '/includes/application.php';
     }
     $this->setTitle($w, $params, $model);
     // Deprecated (keep in case people use them in old templates)
     $this->table = new stdClass();
     $this->table->label = FabrikString::translate($w->parseMessageForPlaceHolder($item->label, $_REQUEST));
     $this->table->intro = $params->get('show_into', 1) == 0 ? '' : FabrikString::translate($w->parseMessageForPlaceHolder($item->introduction));
     $this->table->outro = $params->get('show_outro', 1) == 0 ? '' : FabrikString::translate($w->parseMessageForPlaceHolder($params->get('outro')));
     $this->table->id = $item->id;
     $this->table->renderid = $model->getRenderContext();
     $this->table->db_table_name = $item->db_table_name;
     // End deprecated
     $this->list = $this->table;
     $this->list->class = $model->htmlClass();
     $this->group_by = $item->group_by;
     $this->form = new stdClass();
     $this->form->id = $item->form_id;
     $this->renderContext = $model->getRenderContext();
     $this->formid = 'listform_' . $this->renderContext;
     $form = $model->getFormModel();
     $this->table->action = $model->getTableAction();
     $this->showCSV = $model->canCSVExport();
     $this->showCSVImport = $model->canCSVImport();
     $this->toggleCols = $model->toggleCols();
     $this->showToggleCols = (bool) $params->get('toggle_cols', false);
     $this->canGroupBy = $model->canGroupBy();
     $this->navigation = $nav;
     $this->nav = $input->getInt('fabrik_show_nav', $params->get('show-table-nav', 1)) ? $nav->getListFooter($this->renderContext, $model->getTmpl()) : '';
     $this->nav = '<div class="fabrikNav">' . $this->nav . '</div>';
     $this->fabrik_userid = $this->user->get('id');
     $this->canDelete = $model->deletePossible() ? true : false;
     $this->limitLength = $model->limitLength;
     $this->ajax = $model->isAjax();
     $this->showTitle = FabrikWorker::getMenuOrRequestVar('show-title', $params->get('show-title', 1), $this->isMambot, 'request');
     // 3.0 observed in list.js & html moved into fabrik_actions rollover
     $this->showPDF = $params->get('pdf', $fbConfig->get('list_pdf', false));
     if ($this->showPDF) {
         FabrikWorker::canPdf();
     }
     $this->emptyLink = $model->canEmpty() ? '#' : '';
     $this->csvImportLink = $this->showCSVImport ? JRoute::_('index.php?option=com_' . $this->package . '&view=import&filetype=csv&listid=' . $item->id) : '';
     $this->showAdd = $model->canAdd();
     if ($this->showAdd) {
         if ($params->get('show-table-add', 1)) {
             $this->addRecordLink = $model->getAddRecordLink();
         } else {
             $this->showAdd = false;
         }
     }
     $this->addLabel = $model->addLabel();
     $this->showRSS = $params->get('rss', 0) == 0 ? 0 : 1;
     if ($this->showRSS) {
         $this->rssLink = $model->getRSSFeedLink();
         if ($this->rssLink != '') {
             $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
             $this->doc->addHeadLink($this->rssLink, 'alternate', 'rel', $attribs);
         }
     }
     if ($this->app->isAdmin()) {
         // Admin always uses com_fabrik option
         $this->pdfLink = JRoute::_('index.php?option=com_fabrik&task=list.view&listid=' . $item->id . '&format=pdf&tmpl=component');
     } else {
         $pdfLink = 'index.php?option=com_' . $this->package . '&view=list&format=pdf&listid=' . $item->id;
         if (!$this->nodata) {
             // If some data is shown then ensure that menu links reset filters (combined with require filters) doesn't produce an empty data set for the pdf
             $pdfLink .= '&resetfilters=0';
         }
         $this->pdfLink = JRoute::_($pdfLink);
     }
     list($this->headings, $groupHeadings, $this->headingClass, $this->cellClass) = $model->getHeadings();
     $this->groupByHeadings = $model->getGroupByHeadings();
     $this->filter_action = $model->getFilterAction();
     JDEBUG ? $profiler->mark('fabrik getfilters start') : null;
     $this->filters = $model->getFilters('listform_' . $this->renderContext);
     $fKeys = array_keys($this->filters);
     $this->bootShowFilters = count($fKeys) === 1 && $fKeys[0] === 'all' ? false : true;
     $this->clearFliterLink = $model->getClearButton();
     JDEBUG ? $profiler->mark('fabrik getfilters end') : null;
     $this->filterMode = (int) $params->get('show-table-filters');
     $this->toggleFilters = in_array($this->filterMode, array(2, 4, 5));
     $this->showFilters = $model->getShowFilters();
     $this->filterCols = (int) $params->get('list_filter_cols', '1');
     $this->showClearFilters = $this->showFilters || $params->get('advanced-filter') ? true : false;
     $this->emptyDataMessage = $model->getEmptyDataMsg();
     $this->groupheadings = $groupHeadings;
     $this->calculations = $this->_getCalculations($this->headings);
     $this->isGrouped = !($model->getGroupBy() == '');
     $this->colCount = count($this->headings);
     $this->hasButtons = $model->getHasButtons();
     $this->grouptemplates = $model->groupTemplates;
     $this->params = $params;
     $this->loadTemplateBottom();
     $this->getManagementJS($this->rows);
     // Get dropdown list of other tables for quick nav in admin
     $this->tablePicker = $params->get('show-table-picker', $input->get('list-picker', true)) && $this->app->isAdmin() && $this->app->input->get('format') !== 'pdf' ? FabrikHelperHTML::tableList($this->table->id) : '';
     $this->buttons();
     $this->pluginTopButtons = $model->getPluginTopButtons();
 }
Exemplo n.º 5
0
 /**
  * Create the sql query to get the rows data for insertion into the form
  *
  * @param   array  $opts  key: ignoreOrder ignores order by part of query
  *                        Needed for inline edit, as it only selects certain fields, order by on a db join element returns 0 results
  *
  * @return  string  query
  */
 public function buildQuery($opts = array())
 {
     if (isset($this->query)) {
         return $this->query;
     }
     $db = FabrikWorker::getDbo();
     $input = $this->app->input;
     $form = $this->getForm();
     if (!$form->record_in_database) {
         return;
     }
     $listModel = $this->getListModel();
     $item = $listModel->getTable();
     $sql = $listModel->buildQuerySelect('form');
     $sql .= $listModel->buildQueryJoin();
     $emptyRowId = $this->rowId === '' ? true : false;
     $random = $input->get('random');
     $useKey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot, 'var');
     if ($useKey != '') {
         $useKey = explode('|', $useKey);
         foreach ($useKey as &$tmpK) {
             $tmpK = !strstr($tmpK, '.') ? $item->db_table_name . '.' . $tmpK : $tmpK;
             $tmpK = FabrikString::safeColName($tmpK);
         }
         if (!is_array($this->rowId)) {
             $aRowIds = explode('|', $this->rowId);
         }
     }
     $comparison = $input->get('usekey_comparison', '=');
     $viewPk = $input->get('view_primary_key');
     // $$$ hugh - changed this to !==, as in rowid=-1/usekey situations, we can have a rowid of 0
     // I don't THINK this will have any untoward side effects, but ...
     if (!$random && !$emptyRowId || !empty($useKey)) {
         $sql .= ' WHERE ';
         if (!empty($useKey)) {
             $sql .= "(";
             $parts = array();
             for ($k = 0; $k < count($useKey); $k++) {
                 /**
                  *
                  * For gory reasons, we have to assume that an empty string cannot be a valid rowid
                  * when using usekey, so just create a 1=-1 if it is.
                  */
                 if ($aRowIds[$k] === '') {
                     $parts[] = ' 1=-1';
                     continue;
                 }
                 // Ensure that the key value is not quoted as we Quote() afterwards
                 if ($comparison == '=') {
                     $parts[] = ' ' . $useKey[$k] . ' = ' . $db->q($aRowIds[$k]);
                 } else {
                     $parts[] = ' ' . $useKey[$k] . ' LIKE ' . $db->q('%' . $aRowIds[$k] . '%');
                 }
             }
             $sql .= implode(' AND ', $parts);
             $sql .= ')';
         } else {
             $sql .= ' ' . $item->db_primary_key . ' = ' . $db->q($this->rowId);
         }
     } else {
         if ($viewPk != '') {
             $sql .= ' WHERE ' . $viewPk . ' ';
         } elseif ($random) {
             // $$$ rob Should this not go after prefilters have been applied ?
             $sql .= ' ORDER BY RAND() LIMIT 1 ';
         }
     }
     // Get pre-filter conditions from table and apply them to the record
     // the false, ignores any filters set by the table
     $where = $listModel->buildQueryWhere(false);
     if (strstr($sql, 'WHERE')) {
         // Do it this way as queries may contain sub-queries which we want to keep the where
         $firstWord = JString::substr($where, 0, 5);
         if ($firstWord == 'WHERE') {
             $where = JString::substr_replace($where, 'AND', 0, 5);
         }
     }
     // Set rowId to -2 to indicate random record
     if ($random) {
         $this->setRowId(-2);
     }
     // $$$ rob ensure that all prefilters are wrapped in brackets so that
     // only one record is loaded by the query - might need to set $word = and?
     if (trim($where) != '') {
         $where = explode(' ', $where);
         $word = array_shift($where);
         $sql .= $word . ' (' . implode(' ', $where) . ')';
     }
     if (!$random && FArrayHelper::getValue($opts, 'ignoreOrder', false) === false) {
         // $$$ rob if showing joined repeat groups we want to be able to order them as defined in the table
         $sql .= $listModel->buildQueryOrder();
     }
     $this->query = $sql;
     return $sql;
 }
Exemplo n.º 6
0
 /**
  * Draws the html form element
  *
  * @param   array  $data           to pre-populate element with
  * @param   int    $repeatCounter  repeat group counter
  *
  * @return  string	elements html
  */
 public function render($data, $repeatCounter = 0)
 {
     $name = $this->getHTMLName($repeatCounter);
     $id = $this->getHTMLId($repeatCounter);
     $params = $this->getParams();
     $bits = $this->inputProperties($repeatCounter);
     $value = $this->getValue($data, $repeatCounter);
     $opts = array();
     if ($value == '') {
         $value = array('label' => '', 'link' => '');
     } else {
         if (!is_array($value)) {
             $value = FabrikWorker::JSONtoData($value, true);
             /**
              * In some legacy case, data is like ...
              * [{"label":"foo","link":"bar"}]
              * ... I think if it came from 2.1.  So lets check to see if we need
              * to massage that into the right format
              */
             if (array_key_exists(0, $value) && is_object($value[0])) {
                 $value = JArrayHelper::fromObject($value[0]);
             } elseif (array_key_exists(0, $value)) {
                 $value['label'] = $value[0];
             }
         }
     }
     if (count($value) == 0) {
         $value = array('label' => '', 'link' => '');
     }
     if (FabrikWorker::getMenuOrRequestVar('rowid') == 0 && FArrayHelper::getValue($value, 'link', '') === '') {
         $value['link'] = $params->get('link_default_url');
     }
     if (!$this->isEditable()) {
         $lbl = trim(FArrayHelper::getValue($value, 'label'));
         $href = trim(FArrayHelper::getValue($value, 'link'));
         $w = new FabrikWorker();
         $href = is_array($data) ? $w->parseMessageForPlaceHolder($href, $data) : $w->parseMessageForPlaceHolder($href);
         $opts['target'] = trim($params->get('link_target', ''));
         $opts['smart_link'] = $params->get('link_smart_link', false);
         $opts['rel'] = $params->get('rel', '');
         $title = $params->get('link_title', '');
         if ($title !== '') {
             $opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data));
         }
         return FabrikHelperHTML::a($href, $lbl, $opts);
     }
     $labelname = FabrikString::rtrimword($name, '[]') . '[label]';
     $linkname = FabrikString::rtrimword($name, '[]') . '[link]';
     $bits['name'] = $labelname;
     $bits['placeholder'] = FText::_('PLG_ELEMENT_LINK_LABEL');
     $bits['value'] = $value['label'];
     $bits['class'] .= ' fabrikSubElement';
     unset($bits['id']);
     $layout = $this->getLayout('form');
     $layoutData = new stdClass();
     $layoutData->id = $id;
     $layoutData->name = $name;
     $layoutData->linkAttributes = $bits;
     $bits['placeholder'] = FText::_('PLG_ELEMENT_LINK_URL');
     $bits['name'] = $linkname;
     $bits['value'] = FArrayHelper::getValue($value, 'link');
     if (is_a($bits['value'], 'stdClass')) {
         $bits['value'] = $bits['value']->{0};
     }
     $layoutData->labelAttributes = $bits;
     return $layout->render($layoutData);
 }
Exemplo n.º 7
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a JError object.
  */
 public function display($tpl = 'default')
 {
     $app = JFactory::getApplication();
     $Itemid = (int) @$app->getMenu('site')->getActive()->id;
     $pluginManager = FabrikWorker::getPluginManager();
     // Needed to load the language file!
     $plugin = $pluginManager->getPlugIn('calendar', 'visualization');
     $model = $this->getModel();
     $usersConfig = JComponentHelper::getParams('com_fabrik');
     $id = JRequest::getVar('id', $usersConfig->get('visualizationid', JRequest::getInt('visualizationid', 0)));
     $model->setId($id);
     $this->row = $model->getVisualization();
     $params = $model->getParams();
     $this->assign('params', $params);
     $this->assign('containerId', $model->getJSRenderContext());
     $this->assignRef('filters', $this->get('Filters'));
     $this->assign('showFilters', JRequest::getInt('showfilters', $params->get('show_filters')) === 1 ? 1 : 0);
     $this->assign('showTitle', JRequest::getInt('show-title', 1));
     $this->assign('filterFormURL', $this->get('FilterFormURL'));
     $calendar = $model->_row;
     $fbConfig = JComponentHelper::getParams('com_fabrik');
     JHTML::stylesheet('media/com_fabrik/css/list.css');
     $params = $model->getParams();
     $canAdd = $params->get('calendar-read-only', 0) == 1 ? 0 : $this->get('CanAdd');
     $this->assign('requiredFiltersFound', $this->get('RequiredFiltersFound'));
     if ($canAdd && $this->requiredFiltersFound) {
         $app->enqueueMessage(JText::_('PLG_VISUALIZATION_CALENDAR_DOUBLE_CLICK_TO_ADD'));
     }
     $this->assign('canAdd', $canAdd);
     $fbConfig = JComponentHelper::getParams('com_fabrik');
     JHTML::stylesheet('media/com_fabrik/css/list.css');
     $params = $model->getParams();
     // Get the active menu item
     $urlfilters = JRequest::get('get');
     unset($urlfilters['option']);
     unset($urlfilters['view']);
     unset($urlfilters['controller']);
     unset($urlfilters['Itemid']);
     unset($urlfilters['visualizationid']);
     unset($urlfilters['format']);
     if (empty($urlfilters)) {
         $urlfilters = new stdClass();
     }
     $urls = new stdClass();
     // Don't JRoute as its wont load with sef?
     $urls->del = 'index.php?option=com_fabrik&controller=visualization.calendar&view=visualization&task=deleteEvent&format=raw&Itemid=' . $Itemid . '&id=' . $id;
     $urls->add = 'index.php?option=com_fabrik&view=visualization&format=raw&Itemid=' . $Itemid . '&id=' . $id;
     $user = JFactory::getUser();
     $legend = $params->get('show_calendar_legend', 0) ? $model->getLegend() : '';
     $tpl = $params->get('calendar_layout', 'default');
     $options = new stdClass();
     $options->url = $urls;
     $options->deleteables = $this->get('DeleteAccess');
     $options->eventLists = $this->get('eventLists');
     $options->calendarId = $calendar->id;
     $options->popwiny = $params->get('yoffset', 0);
     $options->urlfilters = $urlfilters;
     $options->canAdd = $canAdd;
     $options->restFilterStart = FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request');
     $options->tmpl = $tpl;
     $o = $model->getAddStandardEventFormInfo();
     if ($o != null) {
         $options->listid = $o->id;
     }
     // $$$rob @TODO not sure this is need - it isnt in the timeline viz
     $model->setRequestFilters();
     $options->filters = $model->filters;
     // End not sure
     $options->Itemid = $Itemid;
     $options->show_day = (bool) $params->get('show_day', true);
     $options->show_week = (bool) $params->get('show_week', true);
     $options->days = array(JText::_('SUNDAY'), JText::_('MONDAY'), JText::_('TUESDAY'), JText::_('WEDNESDAY'), JText::_('THURSDAY'), JText::_('FRIDAY'), JText::_('SATURDAY'));
     $options->shortDays = array(JText::_('SUN'), JText::_('MON'), JText::_('TUE'), JText::_('WED'), JText::_('THU'), JText::_('FRI'), JText::_('SAT'));
     $options->months = array(JText::_('JANUARY'), JText::_('FEBRUARY'), JText::_('MARCH'), JText::_('APRIL'), JText::_('MAY'), JText::_('JUNE'), JText::_('JULY'), JText::_('AUGUST'), JText::_('SEPTEMBER'), JText::_('OCTOBER'), JText::_('NOVEMBER'), JText::_('DECEMBER'));
     $options->shortMonths = array(JText::_('JANUARY_SHORT'), JText::_('FEBRUARY_SHORT'), JText::_('MARCH_SHORT'), JText::_('APRIL_SHORT'), JText::_('MAY_SHORT'), JText::_('JUNE_SHORT'), JText::_('JULY_SHORT'), JText::_('AUGUST_SHORT'), JText::_('SEPTEMBER_SHORT'), JText::_('OCTOBER_SHORT'), JText::_('NOVEMBER_SHORT'), JText::_('DECEMBER_SHORT'));
     $options->first_week_day = (int) $params->get('first_week_day', 0);
     $options->monthday = new stdClass();
     $options->monthday->width = (int) $params->get('calendar-monthday-width', 90);
     $options->monthday->height = (int) $params->get('calendar-monthday-height', 80);
     $options->greyscaledweekend = $params->get('greyscaled-week-end', 0);
     $options->viewType = $params->get('calendar_default_view', 'monthView');
     $options->weekday = new stdClass();
     $options->weekday->width = (int) $params->get('calendar-weekday-width', 90);
     $options->weekday->height = (int) $params->get('calendar-weekday-height', 10);
     $options->open = (int) $params->get('open-hour', 0);
     $options->close = (int) $params->get('close-hour', 24);
     $options->showweekends = (bool) $params->get('calendar-show-weekends', true);
     $options->readonly = (bool) $params->get('calendar-read-only', false);
     $json = json_encode($options);
     JText::script('PLG_VISUALIZATION_CALENDAR_NEXT');
     JText::script('PLG_VISUALIZATION_CALENDAR_PREVIOUS');
     JText::script('PLG_VISUALIZATION_CALENDAR_DAY');
     JText::script('PLG_VISUALIZATION_CALENDAR_WEEK');
     JText::script('PLG_VISUALIZATION_CALENDAR_MONTH');
     JText::script('PLG_VISUALIZATION_CALENDAR_KEY');
     JText::script('PLG_VISUALIZATION_CALENDAR_TODAY');
     JText::script('PLG_VISUALIZATION_CALENDAR_CONF_DELETE');
     JText::script('PLG_VISUALIZATION_CALENDAR_DELETE');
     JText::script('PLG_VISUALIZATION_CALENDAR_VIEW');
     JText::script('PLG_VISUALIZATION_CALENDAR_EDIT');
     JText::script('PLG_VISUALIZATION_CALENDAR_ADD_EDIT_EVENT');
     $ref = $model->getJSRenderContext();
     $js = " {$ref} = new fabrikCalendar('{$ref}');\n";
     $js .= " {$ref}.render({$json});\n";
     $js .= "  Fabrik.addBlock('" . $ref . "', {$ref});\n";
     $js .= $legend . "\n";
     $js .= $model->getFilterJs();
     $srcs = FabrikHelperHTML::framework();
     $srcs[] = 'media/com_fabrik/js/listfilter.js';
     $srcs[] = 'plugins/fabrik_visualization/calendar/calendar.js';
     FabrikHelperHTML::script($srcs, $js);
     $viewName = $this->getName();
     $pluginParams = $model->getPluginParams();
     $this->assignRef('params', $model->getParams());
     $tpl = $pluginParams->get('calendar_layout', $tpl);
     $tmplpath = JPATH_ROOT . '/plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl;
     $this->_setPath('template', $tmplpath);
     $ab_css_file = $tmplpath . '/template.css';
     if (JFile::exists($ab_css_file)) {
         JHTML::stylesheet('plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl . '/template.css');
     }
     /* Adding custom.css, just for the heck of it */
     $ab_css_file = $tmplpath . '/custom.css';
     if (JFile::exists($ab_css_file)) {
         JHTML::stylesheet('plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl . '/custom.css');
     }
     return parent::display();
 }
Exemplo n.º 8
0
 /**
  * Get Js Options
  *
  * @return stdClass
  * @throws Exception
  */
 private function jsOptions()
 {
     $model = $this->getModel();
     $app = JFactory::getApplication();
     $package = $app->getUserState('com_fabrik.package', 'fabrik');
     $params = $model->getParams();
     $Itemid = FabrikWorker::itemId();
     $urls = new stdClass();
     $calendar = $this->row;
     $j3 = FabrikWorker::j3();
     $tpl = $params->get('fullcalendar_layout', $j3);
     // Get all list where statements - which are then included in the ajax call to ensure we get the correct data set loaded
     $urlFilters = new stdClass();
     $urlFilters->where = $model->buildQueryWhere();
     // Don't JRoute as its wont load with sef?
     $urls->del = 'index.php?option=com_' . $package . '&controller=visualization.fullcalendar&view=visualization&task=deleteEvent&format=raw&Itemid=' . $Itemid . '&id=' . $model->getId();
     $urls->add = 'index.php?option=com_' . $package . '&view=visualization&format=raw&Itemid=' . $Itemid . '&id=' . $model->getId();
     $options = new stdClass();
     $options->url = $urls;
     $options->dateLimits = $model->getDateLimits();
     $options->deleteables = $model->getDeleteAccess();
     $options->eventLists = $model->getEventLists();
     $options->calendarId = $calendar->id;
     $options->popwiny = $params->get('yoffset', 0);
     $options->urlfilters = $urlFilters;
     $options->canAdd = $this->canAdd;
     $options->showFullDetails = (bool) $params->get('show_full_details', false);
     $options->restFilterStart = FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request');
     $options->tmpl = $tpl;
     // $$$rob @TODO not sure this is need - it isn't in the timeline viz
     $model->setRequestFilters();
     $options->filters = $model->filters;
     // End not sure
     $options->Itemid = $Itemid;
     $options->show_day = (bool) $params->get('show_day', true);
     $options->show_week = (bool) $params->get('show_week', true);
     $options->default_view = $params->get('fullcalendar_default_view', 'month');
     $options->add_type = $params->get('add_type', 'both');
     $options->time_format = $params->get('time_format', 'H(:mm)');
     $options->first_week_day = (int) $params->get('first_week_day', 0);
     $options->minDuration = $params->get('minimum_duration', "00:30:00");
     $options->open = $params->get('open-hour', "00:00:00");
     $options->close = $params->get('close-hour', "23:59:59");
     $options->lang = FabrikWorker::getShortLang();
     $options->showweekends = (bool) $params->get('show-weekends', true);
     $options->greyscaledweekend = (bool) $params->get('greyscaled-weekend', false);
     $options->readonly = (bool) $params->get('calendar-read-only', false);
     $options->timeFormat = $params->get('time_format', '%X');
     $options->readonlyMonth = (bool) $params->get('readonly_monthview', false);
     $options->j3 = FabrikWorker::j3();
     $options->calOptions = $params->get('calOptions', '{}');
     $options->startOffset = (int) $params->get('startdate_hour_offset', '0');
     return $options;
 }
Exemplo n.º 9
0
 /**
  * Synchronize J! users with F! table if empty
  *
  * @return  void
  */
 public function onLoad()
 {
     $params = $this->getParams();
     $formModel = $this->getModel();
     // don't do anything if this is a details view
     if ($this->app->input->get('view') === 'details') {
         return;
     }
     if ($params->get('synchro_users') == 1) {
         $listModel = $formModel->getlistModel();
         $fabrikDb = $listModel->getDb();
         $tableName = $listModel->getTable()->db_table_name;
         $query = $fabrikDb->getQuery(true);
         $query->select('COUNT(*)')->from($tableName);
         // Is there already any record in our F! table Users
         $fabrikDb->setQuery($query);
         $count = (int) $fabrikDb->loadResult();
         if ($count === 0) {
             try {
                 // Load the list of users from #__users
                 $query->clear();
                 $query->select('DISTINCT u.*, ug.group_id')->from($fabrikDb->quoteName('#__users') . 'AS u')->join('LEFT', '#__user_usergroup_map AS ug ON ug.user_id = u.id')->group('u.id')->order('u.id ASC');
                 $fabrikDb->setQuery($query);
                 $origUsers = $fabrikDb->loadObjectList();
                 $count = 0;
                 // @TODO really should batch this stuff up, maybe 100 at a time, rather than an insert for every user!
                 foreach ($origUsers as $o_user) {
                     // Insert into our F! table
                     $query->clear();
                     $fields = array($this->getFieldName('juser_field_userid', true) => $o_user->id, $this->getFieldName('juser_field_block', true) => $o_user->block, $this->getFieldName('juser_field_email', true) => $o_user->email, $this->getFieldName('juser_field_password', true) => $o_user->password, $this->getFieldName('juser_field_name', true) => $o_user->name, $this->getFieldName('juser_field_username', true) => $o_user->username);
                     if (!FabrikWorker::j3()) {
                         $fields[$this->getFieldName('juser_field_usertype', true)] = $o_user->group_id;
                     }
                     $query->insert($tableName);
                     foreach ($fields as $key => $val) {
                         $query->set($fabrikDb->quoteName($key) . ' = ' . $fabrikDb->quote($val));
                     }
                     $fabrikDb->setQuery($query);
                     $fabrikDb->execute();
                     $count++;
                 }
                 $this->app->enqueueMessage(JText::sprintf('PLG_FABRIK_FORM_JUSER_MSG_SYNC_OK', $count, $tableName));
             } catch (Exception $e) {
                 $this->app->enqueueMessage(FText::_('PLG_FABRIK_FORM_JUSER_MSG_SYNC_ERROR'));
             }
         }
     }
     // If we are editing a user, we need to make sure the password field is cleared
     if (FabrikWorker::getMenuOrRequestVar('rowid')) {
         $this->passwordfield = $this->getFieldName('juser_field_password');
         $formModel->data[$this->passwordfield] = '';
         $formModel->data[$this->passwordfield . '_raw'] = '';
         // $$$$ hugh - testing 'sync on edit'
         if ($params->get('juser_sync_on_edit', 0) == 1) {
             $this->useridfield = $this->getFieldName('juser_field_userid');
             $userId = (int) FArrayHelper::getValue($formModel->data, $this->useridfield . '_raw');
             /**
              * $$$ hugh - after a validation failure, userid _raw is an array.
              * Trying to work out why, and fix that, but need a bandaid for now.
              */
             if (is_array($userId)) {
                 $userId = (int) FArrayHelper::getValue($userId, 0, 0);
             }
             if ($userId > 0) {
                 // See https://github.com/Fabrik/fabrik/issues/1026 - don't use JFactory as this loads in session stored user
                 $user = new JUser($userId);
                 if ($user->get('id') == $userId) {
                     $this->namefield = $this->getFieldName('juser_field_name');
                     $formModel->data[$this->namefield] = $user->get('name');
                     $formModel->data[$this->namefield . '_raw'] = $user->get('name');
                     $this->usernamefield = $this->getFieldName('juser_field_username');
                     $formModel->data[$this->usernamefield] = $user->get('username');
                     $formModel->data[$this->usernamefield . '_raw'] = $user->get('username');
                     $this->emailfield = $this->getFieldName('juser_field_email');
                     $formModel->data[$this->emailfield] = $user->get('email');
                     $formModel->data[$this->emailfield . '_raw'] = $user->get('email');
                     // @FIXME this is out of date for J1.7 - no gid field
                     if ($params->get('juser_field_usertype') != '') {
                         $groupElement = FabrikWorker::getPluginManager()->getElementPlugin($params->get('juser_field_usertype'));
                         $groupElementClass = get_class($groupElement);
                         $gid = $user->groups;
                         if ($groupElementClass !== 'PlgFabrik_ElementUsergroup') {
                             $gid = array_shift($gid);
                         }
                         $this->gidfield = $this->getFieldName('juser_field_usertype');
                         $formModel->data[$this->gidfield] = $gid;
                         $formModel->data[$this->gidfield . '_raw'] = $gid;
                     }
                     if ($params->get('juser_field_block') != '') {
                         $this->blockfield = $this->getFieldName('juser_field_block');
                         $formModel->data[$this->blockfield] = $user->get('block');
                         $formModel->data[$this->blockfield . '_raw'] = $user->get('block');
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * This merges session data for the fromForm with any request data
  * allowing us to filter data results from both search forms and filters
  *
  * @return array
  */
 public function getFilters()
 {
     $input = $this->app->input;
     // Form or detailed views should not apply filters? what about querystrings to set up the default values?
     if ($input->get('view') == 'details' || $input->get('view') == 'form') {
         $this->request = array();
         return $this->request;
     }
     if (isset($this->request)) {
         return $this->request;
     }
     $profiler = JProfiler::getInstance('Application');
     $filters = array();
     // $$$ rob clears all list filters, and does NOT apply any
     // other filters to the table, even if in querystring
     if ($input->getInt('clearfilters') === 1 && $this->activeTable()) {
         $this->clearFilters();
         $this->request = array();
         return $this->request;
     }
     if ($input->get('replacefilters') == 1) {
         $this->clearFilters();
     }
     /**
      * $$$ fehers The filter is cleared and applied at once without having to clear it first and then apply it (would have to be two clicks).
      * useful in querystring filters if you want to clear old filters and apply new filters
      */
     // $$$ rob 20/03/2011 - request resetfilters should overwrite menu option - otherwise filter then nav will remove filter.
     if (($input->get('filterclear') == 1 || FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request') == 1) && $this->activeTable()) {
         $this->clearFilters();
     }
     JDEBUG ? $profiler->mark('listfilter:cleared') : null;
     // Overwrite filters with querystring filter
     $this->getQuerystringFilters($filters);
     JDEBUG ? $profiler->mark('listfilter:querystring filters got') : null;
     FabrikHelperHTML::debug($filters, 'filter array: after querystring filters');
     $request = $this->getPostFilterArray();
     JDEBUG ? $profiler->mark('listfilter:request got') : null;
     $this->counter = count(FArrayHelper::getValue($request, 'key', array()));
     // Overwrite filters with session filters (fabrik_incsessionfilters set to false in listModel::getRecordCounts / for faceted data counts
     if ($input->get('fabrik_incsessionfilters', true)) {
         $this->getSessionFilters($filters);
     }
     FabrikHelperHTML::debug($filters, 'filter array: after session filters');
     JDEBUG ? $profiler->mark('listfilter:session filters got') : null;
     // The search form search all has lower priority than the filter search all and search form filters
     $this->getSearchFormSearchAllFilters($filters);
     // Overwrite session filters with search form filters
     $this->getSearchFormFilters($filters);
     FabrikHelperHTML::debug($filters, 'filter array: search form');
     // Overwrite filters with 'search all' filter
     $this->getSearchAllFilters($filters);
     JDEBUG ? $profiler->mark('listfilter:search all done') : null;
     // Finally overwrite filters with post filters
     $this->getPostFilters($filters);
     JDEBUG ? $profiler->mark('listfilter:post filters got') : null;
     FabrikHelperHTML::debug($filters, 'filter array: after getpostfilters');
     $this->request = $filters;
     FabrikHelperHTML::debug($this->request, 'filter array');
     $this->checkAccess($filters);
     $this->normalizeKeys($filters);
     return $filters;
 }
Exemplo n.º 11
0
Arquivo: juser.php Projeto: rw1/fabrik
 function onLoad(&$params, &$formModel)
 {
     if ($params->get('synchro_users') == 1) {
         $listModel = $formModel->getlistModel();
         $fabrikDb = $listModel->getDb();
         $tableName = $listModel->getTable()->db_table_name;
         // Is there already any record in our F! table Users
         $fabrikDb->setQuery("SELECT * FROM {$tableName}");
         $notempty = $fabrikDb->loadResult();
         if (!$notempty) {
             // Load the list of users from #__users
             $old_users = "SELECT * FROM " . $fabrikDb->nameQuote('#__users') . " ORDER BY id ASC";
             $fabrikDb->setQuery($old_users);
             $o_users = $fabrikDb->loadObjectList();
             $count = 0;
             // @TODO really should batch this stuff up, maybe 100 at a time, rather than an insert for every user!
             foreach ($o_users as $o_user) {
                 // Insert into our F! table
                 $sync = "INSERT INTO " . $tableName . " (`" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_userid')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_block')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_usertype')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_email')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_password')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_username')) . "`, `" . preg_replace('/^(' . $tableName . '___)/', '', $this->getFieldName($params, 'juser_field_name')) . "`) VALUES ('" . $o_user->id . "', '" . $o_user->block . "', '" . $o_user->gid . "', '" . $o_user->email . "', '" . $o_user->password . "', '" . $o_user->username . "', '" . $o_user->name . "');";
                 $fabrikDb->setQuery($sync);
                 $import = $fabrikDb->query();
                 $count = $count + 1;
             }
             //@TODO - $$$rob - the $import test below only checks if the LAST query ran ok - should check ALL
             // Display synchonization result
             $app = JFactory::getApplication();
             if ($import) {
                 $app->enqueueMessage(JText::sprintf('%s user(s) successfully synchronized from #__users to %s', $count, $tableName));
             } else {
                 $app->enqueueMessage(JText::_('An error occured while Synchronizing users. Please verify that all fields are correctly set in your Fabrik table and selected in fabrikjuser form plugin'));
             }
         }
     }
     // if we are editing a user, we need to make sure the password field is cleared
     //if (JRequest::getInt('rowid')) {
     if (FabrikWorker::getMenuOrRequestVar('rowid')) {
         $this->passwordfield = $this->getFieldName($params, 'juser_field_password');
         $formModel->_data[$this->passwordfield] = '';
         $formModel->_data[$this->passwordfield . '_raw'] = '';
         // $$$$ hugh - testing 'sync on edit'
         if ($params->get('juser_sync_on_edit', 0) == 1) {
             $this->useridfield = $this->getFieldName($params, 'juser_field_userid');
             $userid = (int) JArrayHelper::getValue($formModel->_data, $this->useridfield . '_raw');
             if ($userid > 0) {
                 $user = JFactory::getUser($userid);
                 if ($user->get('id') == $userid) {
                     $this->namefield = $this->getFieldName($params, 'juser_field_name');
                     $formModel->_data[$this->namefield] = $user->get('name');
                     $formModel->_data[$this->namefield . '_raw'] = $user->get('name');
                     $this->usernamefield = $this->getFieldName($params, 'juser_field_username');
                     $formModel->_data[$this->usernamefield] = $user->get('username');
                     $formModel->_data[$this->usernamefield . '_raw'] = $user->get('username');
                     $this->emailfield = $this->getFieldName($params, 'juser_field_email');
                     $formModel->_data[$this->emailfield] = $user->get('email');
                     $formModel->_data[$this->emailfield . '_raw'] = $user->get('email');
                     //@FIXME this is out of date for J1.7 - no gid field
                     if ($params->get('juser_field_usertype') != '') {
                         $gid = $user->get('gid');
                         $this->gidfield = $this->getFieldName($params, 'juser_field_usertype');
                         $formModel->_data[$this->gidfield] = $gid;
                         $formModel->_data[$this->gidfield . '_raw'] = $gid;
                     }
                     if ($params->get('juser_field_block') != '') {
                         $this->blockfield = $this->getFieldName($params, 'juser_field_block');
                         $formModel->_data[$this->blockfield] = $user->get('block');
                         $formModel->_data[$this->blockfield . '_raw'] = $user->get('block');
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Create the fom bottom hidden fields
  *
  * @param   object  &$form  object containg form view properties
  *
  * @return  void
  */
 protected function _loadTmplBottom(&$form)
 {
     $app = JFactory::getApplication();
     $menuItem = $app->getMenu('site')->getActive();
     $Itemid = $menuItem ? $menuItem->id : 0;
     $model = $this->getModel();
     $listModel = $model->getListModel();
     $canDelete = $listModel->canDelete($model->_data);
     $params = $model->getParams();
     $task = 'form.process';
     $reffer = JRequest::getVar('HTTP_REFERER', '', 'server');
     // $$$rob - if returning from a failed validation then we should use the fabrik_referrer post var
     $reffer = str_replace('&', '&amp;', JRequest::getVar('fabrik_referrer', $reffer));
     $this_rowid = is_array($model->_rowId) ? implode('|', $model->_rowId) : $model->_rowId;
     $fields = array('<input type="hidden" name="listid" value="' . $listModel->getId() . '" />', '<input type="hidden" name="listref" value="' . $listModel->getId() . '" />', '<input type="hidden" name="rowid" value="' . $this_rowid . '" />', '<input type="hidden" name="Itemid" value="' . $Itemid . '" />', '<input type="hidden" name="option" value="com_fabrik" />', '<input type="hidden" name="task" value="' . $task . '" />', '<input type="hidden" name="isMambot" value="' . $this->isMambot . '" />', '<input type="hidden" name="formid" value="' . $model->get('id') . '" />', '<input type="hidden" name="returntoform" value="0" />', '<input type="hidden" name="fabrik_referrer" value="' . $reffer . '" />', '<input type="hidden" name="fabrik_ajax" value="' . (int) $model->isAjax() . '" />');
     $fields[] = '<input type="hidden" name="_packageId" value="' . $model->packageId . '" />';
     if ($usekey = FabrikWorker::getMenuOrRequestVar('usekey', '')) {
         // $$$rob v's been set from -1 to the actual row id - so ignore usekyey not sure if we should comment this out
         // see http://fabrikar.com/forums/showthread.php?t=10297&page=5
         $fields[] = '<input type="hidden" name="usekey" value="' . $usekey . '" />';
         $pk_val = JArrayHelper::getValue($model->_data, FabrikString::safeColNameToArrayKey($listModel->getTable()->db_primary_key));
         if (empty($pk_val)) {
             $fields[] = '<input type="hidden" name="usekey_newrecord" value="1" />';
         }
     }
     /* $$$ hugh - testing a fix for pagination issue when submitting a 'search form'.
      * If this is a search form, we need to clear 'limitstart', otherwise ... say we
      * were last on page 4 of the (unfiltered) target table, and the search yields less than 4 pages,
      * we end up with a blank table 'cos the wrong LIMIT's are applied to the query
      */
     $save_insessions = $params->get('save_insession', '');
     if (is_array($save_insessions)) {
         foreach ($save_insessions as $save_insession) {
             if ($save_insession == '1') {
                 $fields[] = '<input type="hidden" name="limitstart" value="0" />';
                 break;
             }
         }
     }
     $fields[] = JHTML::_('form.token');
     $form->resetButton = $params->get('reset_button', 0) && $this->editable == "1" ? '<input type="reset" class="button btn" name="Reset" value="' . $params->get('reset_button_label') . '" />' : '';
     $form->copyButton = $params->get('copy_button', 0) && $this->editable && $model->_rowId != '' ? '<input type="submit" class="button btn" name="Copy" value="' . $params->get('copy_button_label') . '" />' : '';
     $applyButtonType = $model->isAjax() ? 'button' : 'submit';
     $form->applyButton = $params->get('apply_button', 0) && $this->editable ? '<input type="' . $applyButtonType . '" class="button btn" name="apply" value="' . $params->get('apply_button_label') . '" />' : '';
     $form->deleteButton = $params->get('delete_button', 0) && $canDelete && $this->editable && $this_rowid != 0 ? '<input type="submit" value="' . $params->get('delete_button_label', 'Delete') . '" class="button btn" name="delete" />' : '';
     $form->gobackButton = $params->get('goback_button', 0) == "1" ? '<input type="button" class="button btn" name="Goback" ' . FabrikWorker::goBackAction() . ' value="' . $params->get('goback_button_label') . '" />' : '';
     if ($model->isEditable() && $params->get('submit_button', 1)) {
         $button = $model->isAjax() ? "button" : "submit";
         $submitClass = FabrikString::clean($form->submit_button_label);
         $form->submitButton = '<input type="' . $button . '" class="button ' . $submitClass . ' btn" name="submit" value="' . $form->submit_button_label . '" />';
     } else {
         $form->submitButton = '';
     }
     if ($this->isMultiPage) {
         $form->prevButton = '<input type="button" class="fabrikPagePrevious button" name="fabrikPagePrevious" value="' . JText::_('COM_FABRIK_PREVIOUS') . '" />';
         $form->nextButton = '<input type="button" class="fabrikPageNext button" name="fabrikPageNext" value="' . JText::_('COM_FABRIK_NEXT') . '" />';
     } else {
         $form->nextButton = '';
         $form->prevButton = '';
     }
     // $$$ hugh - hide actions section is we're printing, or if not actions selected
     $noButtons = empty($form->nextButton) && empty($form->prevButton) && empty($form->submitButton) && empty($form->gobackButton) && empty($form->deleteButton) && empty($form->applyButton) && empty($form->copyButton) && empty($form->resetButton);
     if (JRequest::getVar('print', '0') == '1' || $noButtons) {
         $this->hasActions = false;
     } else {
         $this->hasActions = true;
     }
     $format = $model->isAjax() ? 'raw' : 'html';
     $fields[] = '<input type="hidden" name="format" value="' . $format . '" />';
     $groups = $model->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $group = $groupModel->getGroup();
         $c = $groupModel->repeatTotal;
         // Used for validations
         $fields[] = '<input type="hidden" name="fabrik_repeat_group[' . $group->id . ']" value="' . $c . '" id="fabrik_repeat_group_' . $group->id . '_counter" />';
     }
     // $$$ hugh - testing social_profile_hash stuff
     if (JRequest::getVar('fabrik_social_profile_hash', '') != '') {
         $fields[] = '<input type="hidden" name="fabrik_social_profile_hash" value="' . JRequest::getCmd('fabrik_social_profile_hash', '') . '" id="fabrik_social_profile_hash" />';
     }
     $this->_cryptQueryString($fields);
     $this->_cryptViewOnlyElements($fields);
     $this->hiddenFields = implode("\n", $fields);
 }
Exemplo n.º 13
0
 /**
  * get the current records row id
  *  setting a rowid of -1 will load in the current users record (used in
  *  conjunction wth usekey variable
  *
  *  setting a rowid of -2 will load in the last created record
  *
  * @return string rowid
  */
 function getRowId($useMenu = false)
 {
     if (!$useMenu && isset($this->_rowId)) {
         return $this->_rowId;
     }
     $usersConfig =& JComponentHelper::getParams('com_fabrik');
     $user =& JFactory::getUser();
     $pluginManager =& $this->getPluginManager();
     // $$$rob if we show a form module when in a fabrik form component view - we shouldn't use
     // the request rowid for the mambot as that value is destinded for the component
     if ($this->_isMambot && JRequest::getCmd('option') == 'com_fabrik') {
         $this->_rowId = $usersConfig->get('rowid');
     } else {
         if ($useMenu) {
             $this->_rowId = FabrikWorker::getMenuOrRequestVar('rowid', '', $this->_isMambot, 'menu');
         } else {
             $this->_rowId = JRequest::getVar('rowid', $usersConfig->get('rowid'));
         }
     }
     if ($this->getListModel()->getParams()->get('sef-slug') !== '') {
         $this->_rowId = explode(":", $this->_rowId);
         $this->_rowId = array_shift($this->_rowId);
     }
     // $$$ hugh - for some screwed up reason, when using SEF, rowid=-1 ends up as :1
     // $$$ rob === compare as otherwise 0 == ":1" which menat that the users record was  loaded
     if ((string) $this->_rowId === ":1") {
         $this->_rowId = "-1";
     }
     // set rowid to -1 to load in the current users record
     switch ($this->_rowId) {
         case '-1':
             $this->_rowId = $user->get('id');
             break;
         case '-2':
             //set rowid to -2 to load in the last recorded record
             $this->_rowId = $this->getMaxRowId();
             break;
     }
     $pluginManager->runPlugins('onSetRowId', $this);
     return $this->_rowId;
 }
Exemplo n.º 14
0
 /**
  * Synchronize J! users with F! table if empty
  * @param	object	plugin parameters
  * @param	object	form model
  */
 function onLoad(&$params, &$formModel)
 {
     if ($params->get('synchro_users') == 1) {
         $listModel = $formModel->getlistModel();
         $fabrikDb = $listModel->getDb();
         $tableName = $listModel->getTable()->db_table_name;
         $query = $fabrikDb->getQuery(true);
         $query->select('COUNT(*)')->from($tableName);
         // Is there already any record in our F! table Users
         $fabrikDb->setQuery($query);
         $count = (int) $fabrikDb->loadResult();
         if ($count === 0) {
             // Load the list of users from #__users
             $query->clear();
             $query->select('*')->from($fabrikDb->quoteName('#__users'))->order('iD ASC');
             $fabrikDb->setQuery($query);
             $origUsers = $fabrikDb->loadObjectList();
             $count = 0;
             // @TODO really should batch this stuff up, maybe 100 at a time, rather than an insert for every user!
             foreach ($origUsers as $o_user) {
                 // Insert into our F! table
                 $query->clear();
                 $fields = array($this->getFieldName($params, 'juser_field_userid', true) => $o_user->id, $this->getFieldName($params, 'juser_field_block', true) => $o_user->block, $this->getFieldName($params, 'juser_field_email', true) => $o_user->email, $this->getFieldName($params, 'juser_field_password', true) => $o_user->password, $this->getFieldName($params, 'juser_field_name', true) => $o_user->username, $this->getFieldName($params, 'juser_field_username', true) => $o_user->username);
                 $query->insert($tableName);
                 foreach ($fields as $key => $val) {
                     $query->set($fabrikDb->quoteName($key) . ' = ' . $fabrikDb->quote($val));
                 }
                 $fabrikDb->setQuery($query);
                 if (!$fabrikDb->query()) {
                     JError::raiseNotice(400, $fabrikDb->getErrorMsg());
                 }
                 $import = $fabrikDb->query();
                 $count = $count + 1;
             }
             //@TODO - $$$rob - the $import test below only checks if the LAST query ran ok - should check ALL
             // Display synchonization result
             $app = JFactory::getApplication();
             if ($import) {
                 $app->enqueueMessage(JText::sprintf('PLG_FABRIK_FORM_JUSER_MSG_SYNC_OK', $count, $tableName));
             } else {
                 $app->enqueueMessage(JText::_('PLG_FABRIK_FORM_JUSER_MSG_SYNC_ERROR'));
             }
         }
     }
     // if we are editing a user, we need to make sure the password field is cleared
     if (FabrikWorker::getMenuOrRequestVar('rowid')) {
         $this->passwordfield = $this->getFieldName($params, 'juser_field_password');
         $formModel->_data[$this->passwordfield] = '';
         $formModel->_data[$this->passwordfield . '_raw'] = '';
         // $$$$ hugh - testing 'sync on edit'
         if ($params->get('juser_sync_on_edit', 0) == 1) {
             $this->useridfield = $this->getFieldName($params, 'juser_field_userid');
             $userid = (int) JArrayHelper::getValue($formModel->_data, $this->useridfield . '_raw');
             if ($userid > 0) {
                 $user = JFactory::getUser($userid);
                 if ($user->get('id') == $userid) {
                     $this->namefield = $this->getFieldName($params, 'juser_field_name');
                     $formModel->_data[$this->namefield] = $user->get('name');
                     $formModel->_data[$this->namefield . '_raw'] = $user->get('name');
                     $this->usernamefield = $this->getFieldName($params, 'juser_field_username');
                     $formModel->_data[$this->usernamefield] = $user->get('username');
                     $formModel->_data[$this->usernamefield . '_raw'] = $user->get('username');
                     $this->emailfield = $this->getFieldName($params, 'juser_field_email');
                     $formModel->_data[$this->emailfield] = $user->get('email');
                     $formModel->_data[$this->emailfield . '_raw'] = $user->get('email');
                     //@FIXME this is out of date for J1.7 - no gid field
                     if ($params->get('juser_field_usertype') != '') {
                         $gid = $user->get('gid');
                         $this->gidfield = $this->getFieldName($params, 'juser_field_usertype');
                         $formModel->_data[$this->gidfield] = $gid;
                         $formModel->_data[$this->gidfield . '_raw'] = $gid;
                     }
                     if ($params->get('juser_field_block') != '') {
                         $this->blockfield = $this->getFieldName($params, 'juser_field_block');
                         $formModel->_data[$this->blockfield] = $user->get('block');
                         $formModel->_data[$this->blockfield . '_raw'] = $user->get('block');
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Get Playlist
  *
  * @return string
  */
 protected function getPlaylist()
 {
     $app = JFactory::getApplication();
     $package = $app->getUserState('com_fabrik.package', 'fabrik');
     $params = $this->getParams();
     $mediaElement = $params->get('media_media_elementList');
     $mediaElement .= '_raw';
     $titleElement = $params->get('media_title_elementList', '');
     $imageElement = $params->get('media_image_elementList', '');
     if (!empty($imageElement)) {
         $imageElement .= '_raw';
     }
     $infoElement = $params->get('media_info_elementList', '');
     $noteElement = $params->get('media_note_elementList', '');
     $dateElement = $params->get('media_published_elementList', '');
     $listid = $params->get('media_table');
     $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
     $listModel->setId($listid);
     $list = $listModel->getTable();
     $form = $listModel->getFormModel();
     /*
      * remove filters?
      * $$$ hugh - remove pagination BEFORE calling render().  Otherwise render() applies
      * session state/defaults when it calls getPagination, which is then returned as a cached
      * object if we call getPagination after render().  So call it first, then render() will
      * get our cached pagination, rather than vice versa.
      * Changes in f3 seem to mean that we'll have to poke around in the user state,
      * rather than just call getPagination().  So we need to remember previous state of
      * limitstart and limitlength, set them to 0, render the list, then reset to original
      * values (so we don't mess with any instances of the list user may load).  This code
      * seems to kinda work.  Once I've tested it further, will probably move it into to
      * a generic viz model method, so all viz's can call it.
      */
     $context = 'com_' . $package . '.list' . $listModel->getRenderContext() . '.';
     $item = $listModel->getTable();
     $rowsPerPage = FabrikWorker::getMenuOrRequestVar('rows_per_page', $item->rows_per_page);
     $orig_limitstart = $app->getUserState('limitstart', 0);
     $orig_limitlength = $app->getUserState('limitlength', $rowsPerPage);
     $app->setUserState($context . 'limitstart', 0);
     $app->setUserState($context . 'limitlength', 0);
     $nav = $listModel->getPagination(0, 0, 0);
     $listModel->render();
     $alldata = $listModel->getData();
     $app->setUserState($context . 'limitstart', $orig_limitstart);
     $app->setUserState($context . 'limitlength', $orig_limitlength);
     $document = JFactory::getDocument();
     if ($params->get('media_which_player', 'jw') == 'xspf') {
         $retstr = "<?xml version=\"1.0\" encoding=\"" . $document->_charset . "\"?>\n";
         $retstr .= "<playlist version=\"1\" xmlns = \"http://xspf.org/ns/0/\">\n";
         $retstr .= "\t<title>" . $list->label . "</title>\n";
         $retstr .= "\t<trackList>\n";
         foreach ($alldata as $data) {
             foreach ($data as $row) {
                 if (!isset($row->{$mediaElement})) {
                     continue;
                 }
                 $location = $row->{$mediaElement};
                 if (empty($location)) {
                     continue;
                 }
                 $location = str_replace('\\', '/', $location);
                 $location = JString::ltrim($location, '/');
                 $location = COM_FABRIK_LIVESITE . $location;
                 $retstr .= "\t\t<track>\n";
                 $retstr .= "\t\t\t<location>" . $location . "</location>\n";
                 if (!empty($titleElement)) {
                     $title = $row->{$titleElement};
                     $retstr .= "\t\t\t<title>" . $title . "</title>\n";
                 }
                 if (!empty($imageElement)) {
                     $image = $row->{$imageElement};
                     if (!empty($image)) {
                         $image = str_replace('\\', '/', $image);
                         $image = JString::ltrim($image, '/');
                         $image = COM_FABRIK_LIVESITE . $image;
                         $retstr .= "\t\t\t<image>" . $image . "</image>\n";
                     }
                 }
                 if (!empty($noteElement)) {
                     $note = $row->{$noteElement};
                     $retstr .= "\t\t\t<annotation>" . $note . "</annotation>\n";
                 }
                 if (!empty($infoElement)) {
                     $link = $row->{$titleElement};
                     $retstr .= "\t\t\t<info>" . $link . "</info>\n";
                 } else {
                     $link = JRoute::_('index.php?option=com_' . $package . '&view=form&formid=' . $form->getId() . '&rowid=' . $row->__pk_val);
                     $retstr .= "\t\t\t<info>" . $link . "</info>\n";
                 }
                 $retstr .= "\t\t</track>\n";
             }
         }
         $retstr .= "\t</trackList>\n";
         $retstr .= "</playlist>\n";
     } else {
         $retstr = "<?xml version=\"1.0\" encoding=\"" . $document->_charset . "\"?>\n";
         $retstr .= '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">' . "\n";
         $retstr .= "<channel>\n";
         $retstr .= "\t<title>" . $list->label . "</title>\n";
         foreach ($alldata as $data) {
             foreach ($data as $row) {
                 if (!isset($row->{$mediaElement})) {
                     continue;
                 }
                 $location = $row->{$mediaElement};
                 if (empty($location)) {
                     continue;
                 }
                 $location = str_replace('\\', '/', $location);
                 $location = JString::ltrim($location, '/');
                 $location = COM_FABRIK_LIVESITE . $location;
                 $retstr .= "\t\t<item>\n";
                 $retstr .= '			<media:content url="' . $location . '" />' . "\n";
                 if (!empty($titleElement)) {
                     $title = $row->{$titleElement};
                     $retstr .= "\t\t\t<title>" . $title . "</title>\n";
                 }
                 if (!empty($imageElement)) {
                     $image = $row->{$imageElement};
                     if (!empty($image)) {
                         $image = str_replace('\\', '/', $image);
                         $image = JString::ltrim($image, '/');
                         $image = COM_FABRIK_LIVESITE . $image;
                         $retstr .= '			<media:thumbnail url="' . $image . '" />' . "\n";
                     }
                 }
                 if (!empty($noteElement)) {
                     $note = $row->{$noteElement};
                     $retstr .= "\t\t\t<description>" . $note . "</description>\n";
                 }
                 if (!empty($infoElement)) {
                     $link = $row->{$titleElement};
                     $retstr .= "\t\t\t<link>" . $link . "</link>\n";
                 } else {
                     $link = JRoute::_('index.php?option=com_' . $package . '&view=form&formid=' . $form->getId() . '&rowid=' . $row->__pk_val);
                     $retstr .= "\t\t\t<link>" . $link . "</link>\n";
                 }
                 if (!empty($dateElement)) {
                     $pubDate =& JFactory::getDate($row->{$dateElement});
                     $retstr .= "\t\t\t<pubDate>" . htmlspecialchars($pubDate->toRFC822(), ENT_COMPAT, 'UTF-8') . "</pubDate>\n";
                 }
                 $retstr .= "\t\t</item>\n";
             }
         }
         $retstr .= "</channel>\n";
         $retstr .= "</rss>\n";
     }
     return $retstr;
 }
Exemplo n.º 16
0
 /**
  * Create the form bottom hidden fields
  *
  * @param   object &$form Object containing form view properties
  *
  * @return  void
  */
 protected function _loadTmplBottom(&$form)
 {
     $input = $this->app->input;
     $itemId = FabrikWorker::itemId();
     /** @var FabrikFEModelForm $model */
     $model = $this->getModel();
     $listModel = $model->getListModel();
     $row = JArrayHelper::toObject($model->data);
     $canDelete = $listModel->canDelete($row);
     $params = $model->getParams();
     $task = 'form.process';
     $refer = $input->server->get('HTTP_REFERER', '', 'string');
     // $$$rob - if returning from a failed validation then we should use the fabrik_referrer post var
     $refer = str_replace('&', '&amp;', $input->get('fabrik_referrer', $refer, 'string'));
     $thisRowId = is_array($model->getRowId()) ? implode('|', $model->getRowId()) : $model->getRowId();
     $fields = array();
     $fields[] = '<input type="hidden" name="listid" value="' . $listModel->getId() . '" />';
     $fields[] = '<input type="hidden" name="listref" value="' . $listModel->getId() . '" />';
     $fields[] = '<input type="hidden" name="rowid" value="' . $thisRowId . '" />';
     $fields[] = '<input type="hidden" name="Itemid" value="' . $itemId . '" />';
     $fields[] = '<input type="hidden" name="option" value="com_' . $this->package . '" />';
     $fields[] = '<input type="hidden" name="task" value="' . $task . '" />';
     $fields[] = '<input type="hidden" name="isMambot" value="' . $this->isMambot . '" />';
     $fields[] = '<input type="hidden" name="formid" value="' . $model->get('id') . '" />';
     $fields[] = '<input type="hidden" name="returntoform" value="0" />';
     $fields[] = '<input type="hidden" name="fabrik_referrer" value="' . $refer . '" />';
     $fields[] = '<input type="hidden" name="fabrik_ajax" value="' . (int) $model->isAjax() . '" />';
     $fields[] = '<input type="hidden" name="package" value="' . $this->app->getUserState('com_fabrik.package', 'fabrik') . '" />';
     $fields[] = '<input type="hidden" name="packageId" value="' . $model->packageId . '" />';
     if ($useKey = FabrikWorker::getMenuOrRequestVar('usekey', '')) {
         // $$$rob v's been set from -1 to the actual row id - so ignore usekey not sure if we should comment this out
         // see http://fabrikar.com/forums/showthread.php?t=10297&page=5
         $fields[] = '<input type="hidden" name="usekey" value="' . $useKey . '" />';
         $pk_val = FArrayHelper::getValue($model->data, $listModel->getPrimaryKey(true));
         if (empty($pk_val)) {
             $fields[] = '<input type="hidden" name="usekey_newrecord" value="1" />';
         }
     }
     /** $$$ hugh - testing a fix for pagination issue when submitting a 'search form'.
      * If this is a search form, we need to clear 'limitstart', otherwise ... say we
      * were last on page 4 of the (unfiltered) target table, and the search yields less than 4 pages,
      * we end up with a blank table 'cos the wrong LIMIT's are applied to the query
      */
     $saveInSessions = $params->get('save_insession', '');
     if (is_array($saveInSessions)) {
         foreach ($saveInSessions as $saveInSession) {
             if ($saveInSession == '1') {
                 $fields[] = '<input type="hidden" name="limitstart" value="0" />';
                 break;
             }
         }
     }
     $fields[] = JHTML::_('form.token');
     $resetLabel = FText::_($params->get('reset_button_label'));
     $resetIcon = $params->get('reset_icon', '');
     $copyLabel = FText::_($params->get('copy_button_label'));
     $copyIcon = $params->get('copy_icon', '');
     $applyLabel = FText::_($params->get('apply_button_label'));
     $applyIcon = $params->get('apply_icon', '');
     $deleteLabel = FText::_($params->get('delete_button_label', 'Delete'));
     $deleteIcon = $params->get('delete_icon', '');
     $goBackLabel = FText::_($params->get('goback_button_label'));
     $goBackIcon = $params->get('goback_icon', '');
     $btnLayout = FabrikHelperHTML::getLayout('fabrik-button');
     if ($resetIcon !== '') {
         $resetIcon = FabrikHelperHTML::icon($resetIcon);
         $before = $params->get('reset_icon_location', 'before') == 'before';
         $resetLabel = $before ? $resetIcon . '&nbsp;' . $resetLabel : $resetLabel . '&nbsp;' . $resetIcon;
     }
     $layoutData = (object) array('type' => 'reset', 'class' => 'btn-warning button', 'name' => 'Reset', 'label' => $resetLabel);
     $form->resetButton = $params->get('reset_button', 0) && $this->editable == '1' ? $btnLayout->render($layoutData) : '';
     if ($copyIcon !== '') {
         $copyIcon = FabrikHelperHTML::icon($copyIcon);
         $copyLabel = $params->get('copy_icon_location', 'before') == 'before' ? $copyIcon . '&nbsp;' . $copyLabel : $copyLabel . '&nbsp;' . $copyIcon;
     }
     $layoutData = (object) array('type' => 'submit', 'class' => 'button', 'name' => 'Copy', 'label' => $copyLabel);
     $form->copyButton = $params->get('copy_button', 0) && $this->editable && $model->getRowId() != '' ? $btnLayout->render($layoutData) : '';
     if ($applyIcon !== '') {
         $applyIcon = FabrikHelperHTML::icon($applyIcon);
         $before = $params->get('apply_icon_location', 'before') == 'before';
         $applyLabel = $before ? $applyIcon . '&nbsp;' . $applyLabel : $applyLabel . '&nbsp;' . $applyIcon;
     }
     $layoutData = (object) array('type' => $model->isAjax() ? 'button' : 'submit', 'class' => 'button', 'name' => 'apply', 'label' => $applyLabel);
     $form->applyButton = $params->get('apply_button', 0) && $this->editable ? $btnLayout->render($layoutData) : '';
     if ($deleteIcon !== '') {
         $deleteIcon = FabrikHelperHTML::icon($deleteIcon);
         $before = $params->get('delete_icon_location', 'before') == 'before';
         $deleteLabel = $before ? $deleteIcon . '&nbsp;' . $deleteLabel : $deleteLabel . '&nbsp;' . $deleteIcon;
     }
     $layoutData = (object) array('type' => 'submit', 'class' => 'btn-danger button', 'name' => 'delete', 'label' => $deleteLabel);
     $form->deleteButton = $params->get('delete_button', 0) && $canDelete && $this->editable && $thisRowId != '' ? $btnLayout->render($layoutData) : '';
     if ($goBackIcon !== '') {
         $goBackIcon = FabrikHelperHTML::icon($goBackIcon);
         $before = $params->get('goback_icon_location', 'before') == 'before';
         $goBackLabel = $before ? $goBackIcon . '&nbsp;' . $goBackLabel : $goBackLabel . '&nbsp;' . $goBackIcon;
     }
     $layoutData = (object) array('type' => 'button', 'class' => 'button', 'name' => 'Goback', 'label' => $goBackLabel, 'attributes' => $model->isAjax() ? '' : FabrikWorker::goBackAction());
     $form->gobackButton = $params->get('goback_button', 0) ? $btnLayout->render($layoutData) : '';
     if ($model->isEditable() && $params->get('submit_button', 1)) {
         $submitClass = FabrikString::clean($form->submit_button_label);
         $submitIcon = $params->get('save_icon', '');
         $submitLabel = FText::_($form->submit_button_label);
         if ($submitIcon !== '') {
             $submitIcon = FabrikHelperHTML::icon($submitIcon);
             $before = $params->get('save_icon_location', 'before') == 'before';
             $submitLabel = $before ? $submitIcon . '&nbsp;' . $submitLabel : $submitLabel . '&nbsp;' . $submitIcon;
         }
         $layoutData = (object) array('type' => $model->isAjax() ? 'button' : 'submit', 'class' => 'btn-primary button ' . $submitClass, 'name' => 'Submit', 'label' => $submitLabel);
         $form->submitButton = $btnLayout->render($layoutData);
     } else {
         $form->submitButton = '';
     }
     if ($this->isMultiPage) {
         $layoutData = (object) array('type' => 'button', 'class' => 'fabrikPagePrevious button', 'name' => 'fabrikPagePrevious', 'label' => FabrikHelperHTML::icon('icon-previous', FText::_('COM_FABRIK_PREV')));
         $form->prevButton = $btnLayout->render($layoutData);
         $layoutData = (object) array('type' => 'button', 'class' => 'fabrikPageNext button', 'name' => 'fabrikPageNext', 'label' => FText::_('COM_FABRIK_NEXT') . '&nbsp;' . FabrikHelperHTML::icon('icon-next'));
         $form->nextButton = $btnLayout->render($layoutData);
     } else {
         $form->nextButton = '';
         $form->prevButton = '';
     }
     // $$$ hugh - hide actions section is we're printing, or if not actions selected
     $noButtons = empty($form->nextButton) && empty($form->prevButton) && empty($form->submitButton) && empty($form->gobackButton) && empty($form->deleteButton) && empty($form->applyButton) && empty($form->copyButton) && empty($form->resetButton);
     $this->hasActions = $input->get('print', '0') == '1' || $noButtons ? false : true;
     $format = $model->isAjax() ? 'raw' : 'html';
     $fields[] = '<input type="hidden" name="format" value="' . $format . '" />';
     $groups = $model->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         if ($groupModel->isJoin()) {
             $groupPk = $groupModel->getJoinModel()->getForeignId();
             // Use raw otherwise we inject the actual <input> into the hidden field's value
             $groupPk .= '_raw';
             $groupRowIds = (array) FArrayHelper::getValue($this->data, $groupPk, array());
             $groupRowIds = htmlentities(json_encode($groupRowIds));
             // Used to check against in group process(), when deleting removed repeat groups
             $fields[] = '<input type="hidden" name="fabrik_group_rowids[' . $groupModel->getId() . ']" value="' . $groupRowIds . '" />';
         }
         $group = $groupModel->getGroup();
         $c = $groupModel->repeatTotal;
         // Used for validations
         $fields[] = '<input type="hidden" name="fabrik_repeat_group[' . $group->id . ']" value="' . $c . '" id="fabrik_repeat_group_' . $group->id . '_counter" />';
     }
     // $$$ hugh - testing social_profile_hash stuff
     if ($input->get('fabrik_social_profile_hash', '') != '') {
         $fields[] = '<input type="hidden" name="fabrik_social_profile_hash" value="' . $input->get('fabrik_social_profile_hash', '') . '" id="fabrik_social_profile_hash" />';
     }
     $this->_cryptQueryString($fields);
     $this->_cryptViewOnlyElements($fields);
     $this->hiddenFields = implode("\n", $fields);
 }
Exemplo n.º 17
0
Arquivo: list.php Projeto: rw1/fabrik
 /**
  * @since 3.0
  * get the table template
  * @return string template name
  */
 public function getTmpl()
 {
     if (!isset($this->tmpl)) {
         $app = JFactory::getApplication();
         $item = $this->getTable();
         $params = $this->getParams();
         if ($app->isAdmin()) {
             $this->tmpl = JRequest::getVar('layout', $params->get('admin_template'));
         } else {
             $this->tmpl = JRequest::getVar('layout', $item->template);
         }
         if ($this->tmpl == '') {
             $this->tmpl = 'default';
         }
         if ($app->scope !== 'mod_fabrik_list') {
             $this->tmpl = FabrikWorker::getMenuOrRequestVar('fabriklayout', $this->tmpl, $this->isMambot);
             // $$$ rob 10/03/2012 changed menu param to listlayout to avoid the list menu item
             // options also being used for the form/details view template
             $this->tmpl = FabrikWorker::getMenuOrRequestVar('listlayout', $this->tmpl, $this->isMambot);
         }
         // if we are mobilejoomla.com system plugin to detect smartphones
         if (JRequest::getVar('mjmarkup') == 'iphone') {
             $this->tmpl = 'iwebkit';
         }
     }
     return $this->tmpl;
 }
Exemplo n.º 18
0
    /**
     * Execute and display a template script.
     *
     * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
     *
     * @return  mixed  A string if successful, otherwise a JError object.
     */
    public function display($tpl = 'default')
    {
        $app = JFactory::getApplication();
        $package = $app->getUserState('com_fabrik.package', 'fabrik');
        $input = $app->input;
        $j3 = FabrikWorker::j3();
        $Itemid = FabrikWorker::itemId();
        $model = $this->getModel();
        $usersConfig = JComponentHelper::getParams('com_fabrik');
        $id = $input->get('id', $usersConfig->get('visualizationid', $input->get('visualizationid', 0)));
        $model->setId($id);
        $this->row = $model->getVisualization();
        $params = $model->getParams();
        $this->params = $params;
        $this->containerId = $model->getJSRenderContext();
        $this->filters = $this->get('Filters');
        $this->showFilters = $model->showFilters();
        $this->showTitle = $input->getInt('show-title', 1);
        $this->filterFormURL = $this->get('FilterFormURL');
        $calendar = $this->row;
        JHTML::stylesheet('media/com_fabrik/css/list.css');
        $this->canAdd = (bool) $params->get('calendar-read-only', 0) == 1 ? false : $model->getCanAdd();
        $this->requiredFiltersFound = $this->get('RequiredFiltersFound');
        if ($params->get('calendar_show_messages', '1') == '1' && $this->canAdd && $this->requiredFiltersFound) {
            $msg = JText::_('PLG_VISUALIZATION_CALENDAR_DOUBLE_CLICK_TO_ADD');
            $msg .= $model->getDateLimitsMsg();
            $app->enqueueMessage($msg);
        }
        JHTML::stylesheet('media/com_fabrik/css/list.css');
        // Get all list where statements - which are then included in the ajax call to ensure we get the correct data set loaded
        $urlfilters = new stdClass();
        $urlfilters->where = $model->buildQueryWhere();
        $urls = new stdClass();
        // Don't JRoute as its wont load with sef?
        $urls->del = 'index.php?option=com_' . $package . '&controller=visualization.calendar&view=visualization&task=deleteEvent&format=raw&Itemid=' . $Itemid . '&id=' . $id;
        $urls->add = 'index.php?option=com_' . $package . '&view=visualization&format=raw&Itemid=' . $Itemid . '&id=' . $id;
        $user = JFactory::getUser();
        $legend = $params->get('show_calendar_legend', 0) ? $model->getLegend() : '';
        $tpl = $j3 ? 'bootstrap' : 'default';
        $tpl = $params->get('calendar_layout', $j3);
        $options = new stdClass();
        $options->url = $urls;
        $options->dateLimits = $model->getDateLimits();
        $options->deleteables = $model->getDeleteAccess();
        $options->eventLists = $model->getEventLists();
        $options->calendarId = $calendar->id;
        $options->popwiny = $params->get('yoffset', 0);
        $options->urlfilters = $urlfilters;
        $options->canAdd = $this->canAdd;
        $options->showFullDetails = (bool) $params->get('show_full_details', false);
        $options->restFilterStart = FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request');
        $options->tmpl = $tpl;
        $o = $model->getAddStandardEventFormInfo();
        if ($o != null) {
            $options->listid = $o->id;
        }
        // $$$rob @TODO not sure this is need - it isn't in the timeline viz
        $model->setRequestFilters();
        $options->filters = $model->filters;
        // End not sure
        $options->Itemid = $Itemid;
        $options->show_day = (bool) $params->get('show_day', true);
        $options->show_week = (bool) $params->get('show_week', true);
        $options->days = array(JText::_('SUNDAY'), JText::_('MONDAY'), JText::_('TUESDAY'), JText::_('WEDNESDAY'), JText::_('THURSDAY'), JText::_('FRIDAY'), JText::_('SATURDAY'));
        $options->shortDays = array(JText::_('SUN'), JText::_('MON'), JText::_('TUE'), JText::_('WED'), JText::_('THU'), JText::_('FRI'), JText::_('SAT'));
        $options->months = array(JText::_('JANUARY'), JText::_('FEBRUARY'), JText::_('MARCH'), JText::_('APRIL'), JText::_('MAY'), JText::_('JUNE'), JText::_('JULY'), JText::_('AUGUST'), JText::_('SEPTEMBER'), JText::_('OCTOBER'), JText::_('NOVEMBER'), JText::_('DECEMBER'));
        $options->shortMonths = array(JText::_('JANUARY_SHORT'), JText::_('FEBRUARY_SHORT'), JText::_('MARCH_SHORT'), JText::_('APRIL_SHORT'), JText::_('MAY_SHORT'), JText::_('JUNE_SHORT'), JText::_('JULY_SHORT'), JText::_('AUGUST_SHORT'), JText::_('SEPTEMBER_SHORT'), JText::_('OCTOBER_SHORT'), JText::_('NOVEMBER_SHORT'), JText::_('DECEMBER_SHORT'));
        $options->first_week_day = (int) $params->get('first_week_day', 0);
        $options->monthday = new stdClass();
        $options->monthday->width = (int) $params->get('calendar-monthday-width', 90);
        $options->monthday->height = (int) $params->get('calendar-monthday-height', 80);
        $options->greyscaledweekend = $params->get('greyscaled-week-end', 0) === '1';
        $options->viewType = $params->get('calendar_default_view', 'monthView');
        $options->weekday = new stdClass();
        $options->weekday->width = (int) $params->get('calendar-weekday-width', 90);
        $options->weekday->height = (int) $params->get('calendar-weekday-height', 10);
        $options->open = (int) $params->get('open-hour', 0);
        $options->close = (int) $params->get('close-hour', 24);
        $options->showweekends = (bool) $params->get('calendar-show-weekends', true);
        $options->readonly = (bool) $params->get('calendar-read-only', false);
        $options->timeFormat = $params->get('time_format', '%X');
        $options->readonlyMonth = (bool) $params->get('readonly_monthview', false);
        $options->j3 = FabrikWorker::j3();
        if (FabrikWorker::j3()) {
            $options->buttons = new stdClass();
            $options->buttons->del = '<button class="btn popupDelete" data-task="deleteCalEvent"><i class="icon-delete"></i></button>';
            $options->buttons->edit = '<button class="btn popupEdit" data-task="editCalEvent"><i class="icon-edit"></i></button>';
            $options->buttons->view = '<button class="btn popupView" data-task="viewCalEvent"><i class="icon-eye"></i></button>';
        } else {
            $src = COM_FABRIK_LIVESITE . 'plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl . '/images/minus-sign.png';
            $options->buttons = '<img src="' . $src . '"
				alt = "del" class="fabrikDeleteEvent" />' . JText::_('PLG_VISUALIZATION_CALENDAR_DELETE');
        }
        $json = json_encode($options);
        JText::script('PLG_VISUALIZATION_CALENDAR_NEXT');
        JText::script('PLG_VISUALIZATION_CALENDAR_PREVIOUS');
        JText::script('PLG_VISUALIZATION_CALENDAR_DAY');
        JText::script('PLG_VISUALIZATION_CALENDAR_WEEK');
        JText::script('PLG_VISUALIZATION_CALENDAR_MONTH');
        JText::script('PLG_VISUALIZATION_CALENDAR_KEY');
        JText::script('PLG_VISUALIZATION_CALENDAR_TODAY');
        JText::script('PLG_VISUALIZATION_CALENDAR_CONF_DELETE');
        JText::script('PLG_VISUALIZATION_CALENDAR_DELETE');
        JText::script('PLG_VISUALIZATION_CALENDAR_VIEW');
        JText::script('PLG_VISUALIZATION_CALENDAR_EDIT');
        JText::script('PLG_VISUALIZATION_CALENDAR_ADD_EDIT_EVENT');
        JText::script('COM_FABRIK_FORM_SAVED');
        JText::script('PLG_VISUALIZATION_CALENDAR_EVENT_START_END');
        JText::script('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_LATE');
        JText::script('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_EARLY');
        $ref = $model->getJSRenderContext();
        $js = array();
        $js[] = "\tvar {$ref} = new fabrikCalendar('{$ref}');";
        $js[] = "\t{$ref}.render({$json});";
        $js[] = "\tFabrik.addBlock('" . $ref . "', {$ref});";
        $js[] = "\t" . $legend . "";
        $js[] = "" . $model->getFilterJs();
        $js = implode("\n", $js);
        $srcs = FabrikHelperHTML::framework();
        $srcs[] = 'media/com_fabrik/js/listfilter.js';
        $srcs[] = 'plugins/fabrik_visualization/calendar/calendar.js';
        FabrikHelperHTML::iniRequireJs($model->getShim());
        FabrikHelperHTML::script($srcs, $js);
        $viewName = $this->getName();
        $this->params = $model->getParams();
        $tpl = $params->get('calendar_layout', $tpl);
        $tmplpath = JPATH_ROOT . '/plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl;
        $this->_setPath('template', $tmplpath);
        FabrikHelperHTML::stylesheetFromPath('plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl . '/template.css');
        // Adding custom.css, just for the heck of it
        FabrikHelperHTML::stylesheetFromPath('plugins/fabrik_visualization/calendar/views/calendar/tmpl/' . $tpl . '/custom.css');
        return parent::display();
    }
Exemplo n.º 19
0
 /**
  * Draws the html form element
  *
  * @param   array  $data           to preopulate element with
  * @param   int    $repeatCounter  repeat group counter
  *
  * @return  string	elements html
  */
 public function render($data, $repeatCounter = 0)
 {
     $name = $this->getHTMLName($repeatCounter);
     $id = $this->getHTMLId($repeatCounter);
     $params = $this->getParams();
     $bits = $this->inputProperties($repeatCounter);
     $value = $this->getValue($data, $repeatCounter);
     if ($value == "") {
         $value = array('label' => '', 'link' => '');
     } else {
         if (!is_array($value)) {
             $value = FabrikWorker::JSONtoData($value, true);
             if (array_key_exists(0, $value)) {
                 $value['label'] = $value[0];
             }
         }
     }
     if (count($value) == 0) {
         $value = array('label' => '', 'link' => '');
     }
     if (FabrikWorker::getMenuOrRequestVar('rowid') == 0) {
         $value['link'] = $params->get('link_default_url');
     }
     if (!$this->isEditable()) {
         $_lbl = trim($value['label']);
         $_lnk = trim($value['link']);
         $w = new FabrikWorker();
         $_lnk = is_array($data) ? $w->parseMessageForPlaceHolder($_lnk, $data) : $w->parseMessageForPlaceHolder($_lnk);
         if (empty($_lnk) || JString::strtolower($_lnk) == 'http://' || JString::strtolower($_lnk) == 'https://') {
             // Don't return empty links
             return '';
         }
         $target = $params->get('link_target', '');
         $smart_link = $params->get('link_smart_link', false);
         if (empty($_lbl)) {
             // If label is empty, set as a copy of the link
             $_lbl = $_lnk;
         }
         if ($smart_link || $target == 'mediabox') {
             $smarts = $this->_getSmartLinkType($_lnk);
             return '<a href="' . $_lnk . '" rel="lightbox[' . $smarts['type'] . ' ' . $smarts['width'] . ' ' . $smarts['height'] . ']">' . $_lbl . '</a>';
         }
         return '<a href="' . $_lnk . '" target="' . $target . '">' . $_lbl . '</a>';
     }
     $labelname = FabrikString::rtrimword($name, "[]") . '[label]';
     $linkname = FabrikString::rtrimword($name, "[]") . '[link]';
     $html = array();
     $bits['name'] = $labelname;
     $bits['placeholder'] = JText::_('PLG_ELEMENT_LINK_LABEL');
     $bits['value'] = $value['label'];
     $bits['class'] .= ' fabrikSubElement';
     unset($bits['id']);
     $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">';
     $html[] = $this->buildInput('input', $bits);
     $bits['placeholder'] = JText::_('PLG_ELEMENT_LINK_URL');
     $bits['name'] = $linkname;
     $bits['value'] = JArrayHelper::getValue($value, 'link');
     $html[] = $this->buildInput('input', $bits);
     $html[] = '</div>';
     return implode("\n", $html);
 }