Ejemplo n.º 1
0
 /**
  * Display the view
  *
  * @param   string  $tpl  Template
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     $this->form = $this->get('Form');
     $this->addToolBar();
     FabrikAdminHelper::setViewLayout($this);
     parent::display($tpl);
 }
Ejemplo n.º 2
0
 /**
  * Show the form in the admin
  *
  * @return null
  */
 public function view()
 {
     $document = JFactory::getDocument();
     $model = JModel::getInstance('Form', 'FabrikFEModel');
     $viewType = $document->getType();
     $this->setPath('view', COM_FABRIK_FRONTEND . '/views');
     $viewLayout = JRequest::getCmd('layout', 'default');
     $view = $this->getView('form', $viewType, '');
     $view->setModel($model, true);
     $view->isMambot = $this->isMambot;
     // Set the layout
     $view->setLayout($viewLayout);
     // @TODO check for cached version
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_FORMS'), 'forms.png');
     if (in_array(JRequest::getCmd('format'), array('raw', 'csv', 'pdf'))) {
         $view->display();
     } else {
         $user = JFactory::getUser();
         $post = JRequest::get('post');
         $cacheid = serialize(array(JRequest::getURI(), $post, $user->get('id'), get_class($view), 'display', $this->cacheId));
         $cache = JFactory::getCache('com_fabrik', 'view');
         ob_start();
         $cache->get($view, 'display', $cacheid);
         $contents = ob_get_contents();
         ob_end_clean();
         $token = JUtility::getToken();
         $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
         $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
         echo preg_replace($search, $replacement, $contents);
     }
     FabrikAdminHelper::addSubmenu(JRequest::getWord('view', 'lists'));
 }
Ejemplo n.º 3
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_CRONS'), 'crons.png');
     JToolBarHelper::custom('crons.run', 'upload.png', 'upload_f2.png', 'Run');
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('cron.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('cron.edit', 'JTOOLBAR_EDIT');
     }
     if ($canDo->get('core.edit.state')) {
         if ($this->state->get('filter.state') != 2) {
             JToolBarHelper::divider();
             JToolBarHelper::custom('crons.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
             JToolBarHelper::custom('crons.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         }
     }
     if (JFactory::getUser()->authorise('core.manage', 'com_checkin')) {
         JToolBarHelper::custom('crons.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
     }
     if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'cron.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('crons.trash', 'JTOOLBAR_TRASH');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_CRONS', false, JText::_('JHELP_COMPONENTS_FABRIK_CRONS'));
 }
Ejemplo n.º 4
0
 /**
  * Display the view
  *
  * @param   boolean  $cachable   If true, the view output will be cached
  * @param   array    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return  void
  */
 public function display($cachable = false, $urlparams = false)
 {
     $this->default_view = 'home';
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     parent::display();
     // Load the submenu.
     FabrikAdminHelper::addSubmenu(JRequest::getWord('view', 'lists'));
 }
Ejemplo n.º 5
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions();
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
 }
Ejemplo n.º 6
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  *
  * @return  void
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(FText::_('COM_FABRIK_MANAGER_PACKAGES'), 'box-add');
     /*
     		if ($canDo->get('core.create'))
     		{
     			JToolBarHelper::addNew('package.add', 'JTOOLBAR_NEW');
     		}
     if ($canDo->get('core.edit'))
     		{
     			JToolBarHelper::editList('package.edit', 'JTOOLBAR_EDIT');
     		}
     JToolBarHelper::custom('package.export', 'export.png', 'export_f2.png', 'COM_FABRIK_MANAGER_PACKAGE_EXPORT', true);
     if ($canDo->get('core.edit.state'))
     		{
     			if ($this->state->get('filter.state') != 2)
     			{
     				JToolBarHelper::divider();
     				JToolBarHelper::custom('packages.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
     				JToolBarHelper::custom('packages.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
     			}
     		}
     if (JFactory::getUser()->authorise('core.manage', 'com_checkin'))
     		{
     			JToolBarHelper::custom('packages.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
     		}
     if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete'))
     		{
     			JToolBarHelper::deleteList('', 'packages.delete', 'JTOOLBAR_EMPTY_TRASH');
     		}
     		elseif ($canDo->get('core.edit.state'))
     		{
     			JToolBarHelper::trash('packages.trash', 'JTOOLBAR_TRASH');
     		}
     */
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_PACKAGES', false, FText::_('JHELP_COMPONENTS_FABRIK_PACKAGES'));
     /*
     if (FabrikWorker::j3())
     {
     	JHtmlSidebar::setAction('index.php?option=com_fabrik&view=packages');
     
     	$publishOpts = JHtml::_('jgrid.publishedOptions', array('archived' => false));
     	JHtmlSidebar::addFilter(
     	FText::_('JOPTION_SELECT_PUBLISHED'),
     	'filter_published',
     	JHtml::_('select.options', $publishOpts, 'value', 'text', $this->state->get('filter.published'), true)
     	);
     }
     */
 }
Ejemplo n.º 7
0
 /**
  * show the form in the admin
  */
 function view()
 {
     $document = JFactory::getDocument();
     $model = JModel::getInstance('Form', 'FabrikFEModel');
     JRequest::setVar('view', 'details');
     $viewType = $document->getType();
     $this->setPath('view', COM_FABRIK_FRONTEND . '/views');
     $viewLayout = JRequest::getCmd('layout', 'default');
     $view = $this->getView('form', $viewType, '');
     $view->setModel($model, true);
     // Set the layout
     $view->setLayout($viewLayout);
     // @Todo check for cached version
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_FORMS'), 'forms.png');
     $view->display();
     FabrikAdminHelper::addSubmenu(JRequest::getWord('view', 'lists'));
 }
Ejemplo n.º 8
0
 /**
  * Show the form in the admin
  *
  * @return  void
  */
 public function view()
 {
     $document = JFactory::getDocument();
     $model = JModelLegacy::getInstance('Form', 'FabrikFEModel');
     $app = JFactory::getApplication();
     $input = $app->input;
     $input->set('view', 'details');
     $viewType = $document->getType();
     $this->setPath('view', COM_FABRIK_FRONTEND . '/views');
     $viewLayout = $input->get('layout', 'default');
     $this->name = 'Fabrik';
     $view = $this->getView('Form', $viewType, '');
     $view->setModel($model, true);
     // Set the layout
     $view->setLayout($viewLayout);
     // @TODO check for cached version
     JToolBarHelper::title(FText::_('COM_FABRIK_MANAGER_FORMS'), 'file-2');
     $view->display();
     FabrikAdminHelper::addSubmenu($input->getWord('view', 'lists'));
 }
Ejemplo n.º 9
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  */
 protected function addToolbar()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $input->set('hidemainmenu', true);
     $user = JFactory::getUser();
     $isNew = $this->item->id == 0;
     $userId = $user->get('id');
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     $title = $isNew ? FText::_('COM_FABRIK_MANAGER_GROUP_NEW') : FText::_('COM_FABRIK_MANAGER_GROUP_EDIT') . ' "' . $this->item->name . '"';
     JToolBarHelper::title($title, 'group.png');
     if ($isNew) {
         // For new records, check the create permission.
         if ($canDo->get('core.create')) {
             JToolBarHelper::apply('group.apply', 'JTOOLBAR_APPLY');
             JToolBarHelper::save('group.save', 'JTOOLBAR_SAVE');
             JToolBarHelper::addNew('group.save2new', 'JTOOLBAR_SAVE_AND_NEW');
         }
         JToolBarHelper::cancel('group.cancel', 'JTOOLBAR_CANCEL');
     } else {
         // Can't save the record if it's checked out.
         if (!$checkedOut) {
             // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
             if ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_by == $userId) {
                 JToolBarHelper::apply('group.apply', 'JTOOLBAR_APPLY');
                 JToolBarHelper::save('group.save', 'JTOOLBAR_SAVE');
                 // We can save this record, but check the create permission to see if we can return to make a new one.
                 if ($canDo->get('core.create')) {
                     JToolBarHelper::addNew('group.save2new', 'JTOOLBAR_SAVE_AND_NEW');
                 }
             }
         }
         if ($canDo->get('core.create')) {
             JToolBarHelper::custom('group.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
         }
         JToolBarHelper::cancel('group.cancel', 'JTOOLBAR_CLOSE');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_GROUPS_EDIT', false, FText::_('JHELP_COMPONENTS_FABRIK_GROUPS_EDIT'));
 }
Ejemplo n.º 10
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_ELEMENTS'), 'elements.png');
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('element.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('element.edit', 'JTOOLBAR_EDIT');
     }
     JToolBarHelper::custom('elements.copySelectGroup', 'copy.png', 'copy_f2.png', 'COM_FABRIK_COPY');
     if ($canDo->get('core.edit.state')) {
         if ($this->state->get('filter.state') != 2) {
             JToolBarHelper::divider();
             JToolBarHelper::custom('elements.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
             JToolBarHelper::custom('elements.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         }
         JToolBarHelper::divider();
         JToolBarHelper::custom('elements.showInListView', 'publish.png', 'publish_f2.png', 'COM_FABRIK_SHOW_IN_LIST_VIEW', true);
         JToolBarHelper::custom('elements.hideFromListView', 'unpublish.png', 'unpublish_f2.png', 'COM_FABRIK_REMOVE_FROM_LIST_VIEW', true);
     }
     if (JFactory::getUser()->authorise('core.manage', 'com_checkin')) {
         JToolBarHelper::custom('elements.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
     }
     if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'elements.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('elements.trash', 'JTOOLBAR_TRASH');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_ELEMENTS', false, JText::_('JHELP_COMPONENTS_FABRIK_ELEMENTS'));
 }
Ejemplo n.º 11
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_LISTS'), 'lists.png');
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('list.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('list.edit', 'JTOOLBAR_EDIT');
     }
     JToolBarHelper::custom('list.copy', 'copy.png', 'copy_f2.png', 'COM_FABRIK_COPY');
     if ($canDo->get('core.edit.state')) {
         if ($this->state->get('filter.state') != 2) {
             JToolBarHelper::divider();
             JToolBarHelper::custom('lists.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
             JToolBarHelper::custom('lists.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         }
     }
     JToolBarHelper::divider();
     if ($canDo->get('core.create')) {
         JToolBarHelper::custom('import.display', 'upload.png', 'upload_f2.png', 'COM_FABRIK_IMPORT', false);
     }
     JToolBarHelper::divider();
     if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'lists.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('lists.trash', 'JTOOLBAR_TRASH');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_LISTS', false, JText::_('JHELP_COMPONENTS_FABRIK_LISTS'));
 }
Ejemplo n.º 12
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title($isNew ? JText::_('COM_FABRIK_MANAGER_FORM_NEW') : JText::_('COM_FABRIK_MANAGER_FORM_EDIT'), 'form.png');
     if ($isNew) {
         // For new records, check the create permission.
         if ($canDo->get('core.create')) {
             JToolBarHelper::apply('form.apply', 'JTOOLBAR_APPLY');
             JToolBarHelper::save('form.save', 'JTOOLBAR_SAVE');
             JToolBarHelper::addNew('form.save2new', 'JTOOLBAR_SAVE_AND_NEW');
         }
         JToolBarHelper::cancel('form.cancel', 'JTOOLBAR_CANCEL');
     } else {
         // Can't save the record if it's checked out.
         if (!$checkedOut) {
             // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
             if ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_by == $userId) {
                 JToolBarHelper::apply('form.apply', 'JTOOLBAR_APPLY');
                 JToolBarHelper::save('form.save', 'JTOOLBAR_SAVE');
                 // We can save this record, but check the create permission to see if we can return to make a new one.
                 if ($canDo->get('core.create')) {
                     JToolBarHelper::addNew('form.save2new', 'JTOOLBAR_SAVE_AND_NEW');
                 }
             }
         }
         // $$$ rob no save as copy as this gets complicated due to renaming lists, groups etc. Users should copy from list view.
         JToolBarHelper::cancel('form.cancel', 'JTOOLBAR_CLOSE');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_FORMS_EDIT', false, JText::_('JHELP_COMPONENTS_FABRIK_FORMS_EDIT'));
 }
Ejemplo n.º 13
0
 /**
  * Save the form
  *
  * @param   array $data the jForm part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $input = $this->app->input;
     $jForm = $input->get('jform', array(), 'array');
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = FArrayHelper::getValue($data, 'id');
     $row->load($id);
     $params = new Registry($row->get('params'));
     $isView = $this->setIsView($params);
     $data['params']['isView'] = (string) $isView;
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->get('form_id'));
     $feModel = $this->getFEModel();
     /** @var $contentTypeModel FabrikAdminModelContentTypeImport */
     $contentTypeModel = JModelLegacy::getInstance('ContentTypeImport', 'FabrikAdminModel', array('listModel' => $this));
     $contentType = ArrayHelper::getValue($jForm, 'contenttype', '');
     if ($contentType !== '') {
         $contentTypeModel->check($contentType);
     }
     // Get original collation
     $db = $feModel->getDb();
     $origCollation = $this->getOriginalCollation($params, $db, FArrayHelper::getValue($data, 'db_table_name', ''));
     $row->bind($data);
     $row->set('order_by', json_encode($input->get('order_by', array(), 'array')));
     $row->set('order_dir', json_encode($input->get('order_dir', array(), 'array')));
     $row->check();
     $isNew = true;
     if ($row->id != 0) {
         $this->collation($feModel, $origCollation, $row);
         $dateNow = JFactory::getDate();
         $row->set('modified', $dateNow->toSql());
         $row->set('modified_by', $this->user->get('id'));
     }
     if ($id == 0) {
         if ($row->get('created', '') == '') {
             $row->set('created', $date->toSql());
         }
         $isNew = false;
         $existingTable = ArrayHelper::getValue($data, 'db_table_name', '');
         $newTable = $existingTable === '' ? trim(FArrayHelper::getValue($data, '_database_name')) : '';
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newTable = FabrikString::clean($newTable);
         // Check the entered database table doesn't already exist
         if ($newTable != '' && $this->databaseTableExists($newTable)) {
             throw new RuntimeException(FText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
         }
         if (!$this->canCreateDbTable()) {
             throw new RuntimeException(FText::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
         }
         // Save the row now
         $row->store();
         // Create fabrik form
         $this->createLinkedForm();
         $row->set('form_id', $this->getState('list.form_id'));
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         if ($newTable == '') {
             // Create fabrik group
             $input->set('_createGroup', 1);
             $groupId = $this->createLinkedGroup($groupData, false);
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->set('db_table_name', $newTable);
             $row->set('auto_inc', 1);
             $dbOpts = array();
             $params = new Registry($row->get('params'));
             $dbOpts['COLLATE'] = $params->get('collation', '');
             $fields = $contentTypeModel->import($contentType, $row->get('db_table_name'), $groupData);
             $res = $this->createDBTable($newTable, $fields, $dbOpts);
             if (is_array($res)) {
                 $row->set('db_primary_key', $newTable . '.' . $res[0]);
             }
         }
     }
     $row->set('publish_down', FabrikAdminHelper::prepareSaveDate($row->get('publish_down')));
     $row->set('created', FabrikAdminHelper::prepareSaveDate($row->get('created')));
     $row->set('publish_up', FabrikAdminHelper::prepareSaveDate($row->get('publish_up')));
     $pk = FArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $pk = $feModel->getPrimaryKeyAndExtra($row->get('db_table_name'));
         $key = $pk[0]['colname'];
         $extra = $pk[0]['extra'];
         // Store without qns as that's db specific
         $row->set('db_primary_key', $row->get('db_primary_key', '') == '' ? $row->get('db_table_name') . '.' . $key : $row->get('db_primary_key'));
         $row->set('auto_inc', JString::stristr($extra, 'auto_increment') ? true : false);
     }
     $row->store();
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->get('db_primary_key'), $row->get('auto_inc'));
     }
     // Make an array of elements and a presumed index size, map is then used in creating indexes
     $this->createIndexes($params, $row);
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->get($pkName));
     }
     /**
      * $$$ hugh - I don't know what this state gets used for, but $iNew is
      * currently ending up the wrong way round.  New tables it's false,
      * existing tables it's true.
      */
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     if ($id == 0) {
         $contentTypeModel->finalise($row);
     }
     return true;
 }
Ejemplo n.º 14
0
 /**
  * Show the lists data in the admin
  *
  * @param   object  $model  list model
  *
  * @return  null
  */
 public function view($model = null)
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $cid = $input->get('cid', array(0), 'array');
     $cid = $cid[0];
     if (is_null($model)) {
         $cid = $input->getInt('listid', $cid);
         // Grab the model and set its id
         $model = JModelLegacy::getInstance('List', 'FabrikFEModel');
         $model->setState('list.id', $cid);
     }
     $app = JFactory::getApplication();
     $input = $app->input;
     $viewType = JFactory::getDocument()->getType();
     // Use the front end renderer to show the table
     $this->setPath('view', COM_FABRIK_FRONTEND . '/views');
     $viewLayout = $input->getWord('layout', 'default');
     $view = $this->getView($this->view_item, $viewType, 'FabrikView');
     $view->setModel($model, true);
     // Set the layout
     $view->setLayout($viewLayout);
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_LISTS'), 'lists.png');
     // Build unique cache id on url, post and user id
     $user = JFactory::getUser();
     $uri = JURI::getInstance();
     $uri = $uri->toString(array('path', 'query'));
     $cacheid = serialize(array($uri, $input->post, $user->get('id'), get_class($view), 'display', $this->cacheId));
     $cache = JFactory::getCache('com_fabrik', 'view');
     if (in_array($input->get('format'), array('raw', 'csv', 'pdf', 'json', 'fabrikfeed'))) {
         $view->display();
     } else {
         $cache->get($view, 'display', $cacheid);
     }
     FabrikAdminHelper::addSubmenu($input->getWord('view', 'lists'));
 }
Ejemplo n.º 15
0
 /**
  * Save the form
  *
  * @param   array  $data  the jform part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $app = JFactory::getApplication();
     $input = $app->input;
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = JArrayHelper::getValue($data, 'id');
     $row->load($id);
     $params = new JRegistry($row->params);
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->form_id);
     $feModel = $this->getFEModel();
     $formModel = $this->getFormModel();
     // Get original collation
     $db = $feModel->getDb();
     if (!empty($data['db_table_name'])) {
         $db->setQuery('SHOW TABLE STATUS LIKE ' . $db->quote($data['db_table_name']));
         $info = $db->loadObject();
         $origCollation = is_object($info) ? $info->Collation : $params->get('collation', 'none');
     } else {
         $origCollation = $params->get('collation', 'none');
     }
     $row->bind($data);
     $row->order_by = json_encode($input->get('order_by', array(), 'array'));
     $row->order_dir = json_encode($input->get('order_dir', array(), 'array'));
     $row->check();
     $this->collation($feModel, $origCollation, $row);
     $isNew = true;
     if ($row->id != 0) {
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toSql();
         $row->modified_by = $user->get('id');
     }
     if ($id == 0) {
         if ($row->created == '') {
             $row->created = $date->toSql();
         }
         // Save the row now
         $row->store();
         $isNew = false;
         $newtable = trim(JArrayHelper::getValue($data, '_database_name'));
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newtable = FabrikString::clean($newtable);
         // Check the entered database table doesnt already exist
         if ($newtable != '' && $this->databaseTableExists($newtable)) {
             throw new RuntimeException(JText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
             return false;
         }
         if (!$this->canCreateDbTable()) {
             throw new RuntimeException(Jtext::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
             return false;
         }
         // Create fabrik form
         $formModel = $this->createLinkedForm();
         $row->form_id = $this->getState('list.form_id');
         // Create fabrik group
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         $input->set('_createGroup', 1, 'post');
         $groupId = $this->createLinkedGroup($groupData, false);
         if ($newtable == '') {
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->db_table_name = $newtable;
             $row->auto_inc = 1;
             $dbOpts = array();
             $params = new JRegistry($row->params);
             $dbOpts['COLLATE'] = $params->get('collation', '');
             $res = $this->createDBTable($newtable, $input->get('defaultfields', array('id' => 'internalid', 'date_time' => 'date'), 'array'), $dbOpts);
             if (is_array($res)) {
                 $row->db_primary_key = $newtable . '.' . $res[0];
             }
         }
     }
     $params = new JRegistry($row->params);
     $params->set('isview', $feModel->isView());
     $row->params = (string) $params;
     FabrikAdminHelper::prepareSaveDate($row->publish_down);
     FabrikAdminHelper::prepareSaveDate($row->created);
     FabrikAdminHelper::prepareSaveDate($row->publish_up);
     $pk = JArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $pk = $feModel->getPrimaryKeyAndExtra($row->db_table_name);
         $key = $pk[0]['colname'];
         $extra = $pk[0]['extra'];
         // Store without quoteNames as thats db specific
         $row->db_primary_key = $row->db_primary_key == '' ? $row->db_table_name . "." . $key : $row->db_primary_key;
         $row->auto_inc = JString::stristr($extra, 'auto_increment') ? true : false;
     }
     $row->store();
     $pk = $row->db_primary_key;
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     // Make an array of elments and a presumed index size, map is then used in creating indexes
     $map = array();
     $groups = $this->getFormModel()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             // Int and DATETIME elements cant have a index size attrib
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } elseif (JString::stristr($coltype, 'datetime')) {
                 $size = '';
             } else {
                 $size = '10';
             }
             $map[$element->getFullName(false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     // Update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $feModel->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $feModel->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if (trim($params->get('group_by_order')) !== '') {
         $feModel->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = (array) $params->get('filter-fields', array());
     foreach ($afilterFields as $field) {
         if (array_key_exists($field, $map)) {
             $feModel->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
         }
     }
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->{$pkName});
     }
     /**
      * $$$ hugh - I don't know what this state gets used for, but $iNew is
      * currently ending up the wrong way round.  New tables it's false,
      * existing tables it's true.
      */
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     return true;
 }
Ejemplo n.º 16
0
 /**
  * Show the lists data in the admin
  *
  * @return  void
  */
 public function view()
 {
     $cid = JRequest::getVar('cid', array(0), 'method', 'array');
     if (is_array($cid)) {
         $cid = $cid[0];
     }
     $cid = JRequest::getInt('listid', $cid);
     // Grab the model and set its id
     $model = JModel::getInstance('List', 'FabrikFEModel');
     $model->setState('list.id', $cid);
     $viewType = JFactory::getDocument()->getType();
     // Use the front end renderer to show the table
     $this->setPath('view', COM_FABRIK_FRONTEND . '/views');
     $viewLayout = JRequest::getCmd('layout', 'default');
     $view = $this->getView($this->view_item, $viewType, '');
     $view->setModel($model, true);
     // Set the layout
     $view->setLayout($viewLayout);
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_LISTS'), 'lists.png');
     $view->display();
     FabrikAdminHelper::addSubmenu(JRequest::getWord('view', 'lists'));
 }
Ejemplo n.º 17
0
 /**
  * Add select content type tool bar
  *
  * @throws Exception
  *
  * @return void
  */
 protected function addSelectSaveToolBar()
 {
     $app = JFactory::getApplication();
     $this->state = $this->get('State');
     $input = $app->input;
     $input->set('hidemainmenu', true);
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(FText::_('COM_FABRIK_MANAGER_SELECT_CONTENT_TYPE'), 'puzzle');
     // For new records, check the create permission.
     if ($canDo->get('core.create')) {
         JToolBarHelper::apply('form.doSave', 'JTOOLBAR_SAVE');
         JToolBarHelper::cancel('form.cancel', 'JTOOLBAR_CANCEL');
     }
 }
Ejemplo n.º 18
0
 /**
  * Save the form
  *
  * @param   array  $data  the jform part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = $data['id'];
     $row->load($id);
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->form_id);
     $feModel = $this->getFEModel();
     $formModel = $this->getFormModel();
     if (!$row->bind($data)) {
         $this->setError($row->getError());
         return false;
     }
     $filter = new JFilterInput(null, null, 1, 1);
     $introduction = JArrayHelper::getValue(JRequest::getVar('jform', array(), 'post', 'array', JREQUEST_ALLOWRAW), 'introduction');
     $row->introduction = $filter->clean($introduction);
     $row->order_by = json_encode(JRequest::getVar('order_by', array(), 'post', 'array'));
     $row->order_dir = json_encode(JRequest::getVar('order_dir', array(), 'post', 'array'));
     if (!$row->check()) {
         $this->setError($row->getError());
         return false;
     }
     $isNew = true;
     if ($id == 0) {
         if ($row->created == '') {
             $row->created = $date->toSql();
         }
         // Save the row now
         $row->store();
         $isNew = false;
         $newtable = trim(JArrayHelper::getValue($data, '_database_name'));
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newtable = FabrikString::clean($newtable);
         // Check the entered database table doesnt already exist
         if ($newtable != '' && $this->databaseTableExists($newtable)) {
             $this->setError(JText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
             return false;
         }
         if (!$this->canCreateDbTable()) {
             $this->setError(Jtext::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
             return false;
         }
         // Create fabrik form
         $formModel = $this->createLinkedForm();
         $row->form_id = $this->getState('list.form_id');
         // Create fabrik group
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         JRequest::setVar('_createGroup', 1, 'post');
         $groupId = $this->createLinkedGroup($groupData, false);
         if ($newtable == '') {
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->db_table_name = $newtable;
             $row->auto_inc = 1;
             $res = $this->createDBTable($newtable, JRequest::getVar('defaultfields', array('id' => 'internalid', 'date_time' => 'date')));
             if (is_array($res)) {
                 $row->db_primary_key = $newtable . '.' . $res[0];
             }
         }
     }
     $params = new JRegistry($row->params);
     if ($row->id != 0) {
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toSql();
         $row->modified_by = $user->get('id');
     }
     FabrikAdminHelper::prepareSaveDate($row->publish_down);
     FabrikAdminHelper::prepareSaveDate($row->created);
     FabrikAdminHelper::prepareSaveDate($row->publish_up);
     $pk = JArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $fields = $row->getFields();
         $key = $row->getKeyName();
         // Store without quoteNames as thats db specific
         $row->db_primary_key = $row->db_primary_key == '' ? $row->db_table_name . "." . $key : $row->db_primary_key;
         $row->auto_inc = JString::stristr($fields[$key]->Extra, 'auto_increment') ? true : false;
     }
     if (!$row->store()) {
         $this->setError($row->getError());
         return false;
     }
     $pk = $row->db_primary_key;
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     // Make an array of elments and a presumed index size, map is then used in creating indexes
     $map = array();
     $groups = $this->getFormModel()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             // Int and DATETIME elements cant have a index size attrib
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } elseif (JString::stristr($coltype, 'datetime')) {
                 $size = '';
             } else {
                 $size = '10';
             }
             $map[$element->getFullName(false, false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     // Update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $feModel->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $feModel->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if (trim($params->get('group_by_order')) !== '') {
         $feModel->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = (array) $params->get('filter-fields', array());
     foreach ($afilterFields as $field) {
         if (array_key_exists($field, $map)) {
             $feModel->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
         }
     }
     $this->updateElements($row);
     /* $$$rob - joomfish not available for j1.7
     		 if (JFolder::exists(JPATH_ADMINISTRATOR . '/components/com_joomfish/contentelements')) {
     		if ($params->get('allow-data-translation')) {
     		if (!$this->makeJoomfishXML()) {
     		$this->setError(JTEXT::_( "Unable to make Joomfish XML file"));
     		return false;
     		}
     		} else {
     		$this->removeJoomfishXML();
     		}
     		} */
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->{$pkName});
     }
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_ELEMENTS'), 'elements.png');
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('element.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('element.edit', 'JTOOLBAR_EDIT');
     }
     JToolBarHelper::custom('elements.copySelectGroup', 'copy.png', 'copy_f2.png', 'COM_FABRIK_COPY');
     if ($canDo->get('core.edit.state')) {
         if ($this->state->get('filter.state') != 2) {
             JToolBarHelper::divider();
             JToolBarHelper::custom('elements.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
             JToolBarHelper::custom('elements.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         }
         JToolBarHelper::divider();
         JToolBarHelper::custom('elements.showInListView', 'publish.png', 'publish_f2.png', 'COM_FABRIK_SHOW_IN_LIST_VIEW', true);
         JToolBarHelper::custom('elements.hideFromListView', 'unpublish.png', 'unpublish_f2.png', 'COM_FABRIK_REMOVE_FROM_LIST_VIEW', true);
     }
     if (JFactory::getUser()->authorise('core.manage', 'com_checkin')) {
         JToolBarHelper::custom('elements.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
     }
     if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'elements.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('elements.trash', 'JTOOLBAR_TRASH');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_ELEMENTS', false, JText::_('JHELP_COMPONENTS_FABRIK_ELEMENTS'));
     if (FabrikWorker::j3()) {
         JHtmlSidebar::setAction('index.php?option=com_fabrik&view=elements');
         if (!empty($this->packageOptions)) {
             array_unshift($this->packageOptions, JHtml::_('select.option', 'fabrik', JText::_('COM_FABRIK_SELECT_PACKAGE')));
             JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'package', JHtml::_('select.options', $this->packageOptions, 'value', 'text', $this->state->get('com_fabrik.package'), true));
         }
         JHtmlSidebar::addFilter(JText::_('COM_FABRIK_SELECT_PLUGIN'), 'filter_plugin', JHtml::_('select.options', $this->pluginOptions, 'value', 'text', $this->state->get('filter.plugin'), true));
         JHtmlSidebar::addFilter(JText::_('COM_FABRIK_SELECT_FORM'), 'filter_form', JHtml::_('select.options', $this->formOptions, 'value', 'text', $this->state->get('filter.form'), true));
         JHtmlSidebar::addFilter(JText::_('COM_FABRIK_SELECT_GROUP'), 'filter_group', JHtml::_('select.options', $this->groupOptions, 'value', 'text', $this->state->get('filter.group'), true));
         $publishOpts = JHtml::_('jgrid.publishedOptions', array('archived' => false));
         JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', $publishOpts, 'value', 'text', $this->state->get('filter.published'), true));
         JHtmlSidebar::addFilter(JText::_('COM_FABRIK_SELECT_SHOW_IN_LIST'), 'filter_showinlist', JHtml::_('select.options', $this->showInListOptions, 'value', 'text', $this->state->get('filter.showinlist'), true));
     }
 }
Ejemplo n.º 20
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/fabrik.php';
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_LISTS'), 'lists.png');
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('list.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('list.edit', 'JTOOLBAR_EDIT');
     }
     JToolBarHelper::custom('list.copy', 'copy.png', 'copy_f2.png', 'COM_FABRIK_COPY');
     if ($canDo->get('core.edit.state')) {
         if ($this->state->get('filter.state') != 2) {
             JToolBarHelper::divider();
             JToolBarHelper::custom('lists.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
             JToolBarHelper::custom('lists.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         }
     }
     JToolBarHelper::divider();
     if ($canDo->get('core.create')) {
         JToolBarHelper::custom('import.display', 'upload.png', 'upload_f2.png', 'COM_FABRIK_IMPORT', false);
     }
     JToolBarHelper::divider();
     if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'lists.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('lists.trash', 'JTOOLBAR_TRASH');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fabrik');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_LISTS', false, JText::_('JHELP_COMPONENTS_FABRIK_LISTS'));
     if (FabrikWorker::j3()) {
         JHtmlSidebar::setAction('index.php?option=com_fabrik&view=lists');
         $publishOpts = JHtml::_('jgrid.publishedOptions', array('archived' => false));
         JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', $publishOpts, 'value', 'text', $this->state->get('filter.published'), true));
         if (!empty($this->packageOptions)) {
             array_unshift($this->packageOptions, JHtml::_('select.option', 'fabrik', JText::_('COM_FABRIK_SELECT_PACKAGE')));
             JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'package', JHtml::_('select.options', $this->packageOptions, 'value', 'text', $this->state->get('com_fabrik.package'), true));
         }
     }
 }