Example #1
0
 /**
  * Add the page title and toolbar.
  *
  * @return void
  *
  * @since        1.6
  */
 protected function initToolbar()
 {
     $bar = JToolBar::getInstance('toolbar');
     $edition = defined('JSN_UNIFORM_EDITION') ? JSN_UNIFORM_EDITION : "free";
     if (strtolower($edition) == "free") {
         $dataListForm = JSNUniformHelper::getForms();
         $countForm = 3 - count($dataListForm) > 0 ? 3 - count($dataListForm) : 0;
         $msg = JText::sprintf('JSN_UNIFORM_YOU_HAVE_REACHED_THE_LIMITATION_OF_3_FORM_IN_FREE_EDITION', (int) $countForm) . ' <a class="jsn-link-action" href="index.php?option=com_uniform&view=upgrade">' . JText::_("JSN_UNIFORM_UPGRADE_EDITION") . '</a>';
         if (count($dataListForm) < 3) {
             JToolBarHelper::addNew('form.add', 'JTOOLBAR_NEW');
             JToolBarHelper::editList('form.edit', 'JTOOLBAR_EDIT');
             JToolBarHelper::custom('forms.duplicate', 'copy.png', 'copy_f2.png', 'JTOOLBAR_DUPLICATE', true);
             JFactory::getApplication()->enqueueMessage($msg);
         } else {
             $bar->appendButton('Custom', '<button class="btn btn-small btn-success disabled jsn-popup-upgrade" onclick="return false;"><i class="icon-new icon-white"></i>' . JText::_('JTOOLBAR_NEW') . '</button>');
             JToolBarHelper::editList('form.edit', 'JTOOLBAR_EDIT');
             $bar->appendButton('Custom', '<button class="btn btn-small disabled jsn-popup-upgrade" onclick="return false;"><i class="icon-copy "></i>' . JText::_('JTOOLBAR_DUPLICATE') . '</button>');
             $session = JFactory::getSession();
             $seesionQueue = $session->get('application.queue');
             if ($seesionQueue[0]['type'] != "error") {
                 JError::raiseNotice(100, $msg);
             }
         }
     } else {
         JSNUniformHelper::buttonAddNewForm();
         JToolBarHelper::editList('form.edit', 'JTOOLBAR_EDIT');
         JToolBarHelper::custom('forms.duplicate', 'copy.png', 'copy_f2.png', 'JTOOLBAR_DUPLICATE', true);
     }
     JToolBarHelper::publish('forms.publish', 'JSN_UNIFORM_PUBLISH', true);
     JToolBarHelper::unpublish('forms.unpublish', 'JSN_UNIFORM_UNPUBLISH', true);
     JToolBarHelper::deleteList('JSN_UNIFROM_CONFIRM_DELETE', 'forms.delete', 'JTOOLBAR_DELETE');
     JSNUniformHelper::initToolbar('JSN_UNIFORM_FORMS_MANAGER', 'uniform-forms');
 }
 /**
  * Get the button.
  *
  * @return  string
  */
 public function fetchButton()
 {
     $subMenuItemLists = JSNUniformHelper::getForms(5);
     // Build options
     //	$options[] = array(
     //	    'title'    => JText::_('JSN_UNIFORM_SUBMENU_LAUNCHPAD'),
     //	    'link'     => 'index.php?option=com_uniform',
     //	    'class'    => 'parent primary',
     //	    'icon'     => 'icon-off'
     //	);
     $options[] = array('title' => JText::_('JSN_UNIFORM_SUBMENU_FORMS'), 'link' => 'index.php?option=com_uniform&view=forms', 'class' => 'parent primary', 'sub_menu_link' => 'index.php?option=com_uniform&view=form&task=form.edit&form_id={$form_id}', 'sub_menu_field_title' => 'form_title', 'sub_menu_link_add_title' => 'Create new forms', 'sub_menu_link_add' => 'index.php?option=com_uniform&view=form&layout=edit', 'data_sub_menu' => $subMenuItemLists, 'icon' => 'jsn-icon-finder');
     $options[] = array('title' => JText::_('JSN_UNIFORM_SUBMENU_SUBMISSION'), 'link' => 'index.php?option=com_uniform&view=submissions', 'class' => 'parent primary', 'icon' => 'jsn-icon-file');
     $options[] = array('class' => 'separator');
     $options[] = array('title' => JText::_('JSN_UNIFORM_SUBMENU_CONFIGURATION'), 'link' => 'index.php?option=com_uniform&view=configuration');
     $options[] = array('title' => JText::_('JSN_UNIFORM_SUBMENU_ABOUT'), 'link' => 'index.php?option=com_uniform&view=about');
     // Generate HTML code for sub-menu
     $html = JSNHtmlGenerate::menuToolbar($options);
     return $html;
 }
Example #3
0
 /**
  * Method to duplicate modules.
  *
  * @param   array  &$pks  An array of primary key IDs.
  *
  * @return  boolean  True if successful.
  *
  * @since   1.6
  * @throws  Exception
  */
 public function duplicate(&$pks)
 {
     // Initialise variables.
     $user = JFactory::getUser();
     $db = $this->getDbo();
     // Access checks.
     if (!$user->authorise('core.create', 'com_uniform')) {
         throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
     }
     $table = $this->getTable();
     $checkCreate = true;
     foreach ($pks as $pk) {
         $edition = defined('JSN_UNIFORM_EDITION') ? JSN_UNIFORM_EDITION : "free";
         if (strtolower($edition) == "free") {
             $dataListForm = JSNUniformHelper::getForms();
             if (count($dataListForm) >= 3) {
                 $checkCreate = false;
             }
         }
         if ($checkCreate) {
             if ($table->load($pk, true)) {
                 // Reset the id to create a new record.
                 $table->form_id = 0;
                 // Alter the title.
                 $m = null;
                 if (preg_match('#\\((\\d+)\\)$#', $table->form_title, $m)) {
                     $table->form_title = preg_replace('#\\(\\d+\\)$#', '(' . ($m[1] + 1) . ')', $table->form_title);
                 } else {
                     $table->form_title .= ' (2)';
                 }
                 // Unpublish duplicate module
                 $table->form_state = 0;
                 $table->form_submission_cout = 0;
                 $table->form_last_submitted = '';
                 if (!$table->check() || !$table->store()) {
                     throw new Exception($table->getError());
                 }
                 // Email
                 $query = $db->getQuery(true);
                 $query->select('*');
                 $query->from('#__jsn_uniform_emails');
                 $query->where('form_id=' . (int) $pk);
                 $this->_db->setQuery((string) $query);
                 $emails = $this->_db->loadObjectList();
                 foreach ($emails as $email) {
                     $email->email_id = 0;
                     $email->form_id = $table->form_id;
                     $tableEmail = JTable::getInstance('JsnEmail', 'JSNUniformTable');
                     $tableEmail->bind($email);
                     if (!$tableEmail->store()) {
                         $this->setError($tableEmail->getError());
                     }
                 }
                 //Email template
                 $query = $db->getQuery(true);
                 $query->select('*');
                 $query->from('#__jsn_uniform_templates');
                 $query->where('form_id=' . (int) $pk);
                 $this->_db->setQuery((string) $query);
                 $templates = $this->_db->loadObjectList();
                 foreach ($templates as $template) {
                     $template->template_id = 0;
                     $template->form_id = $table->form_id;
                     $tableTemplate = JTable::getInstance('JSNTemplate', 'JSNUniformTable');
                     $tableTemplate->bind($template);
                     if (!$tableTemplate->store()) {
                         $this->setError($tableTemplate->getError());
                     }
                 }
                 //Page and Field
                 $query = $db->getQuery(true);
                 $query->select('*');
                 $query->from('#__jsn_uniform_form_pages');
                 $query->where('form_id=' . (int) $pk);
                 $query->order("page_id ASC");
                 $this->_db->setQuery((string) $query);
                 $pages = $this->_db->loadObjectList();
                 foreach ($pages as $page) {
                     $dataField = array();
                     $fields = json_decode($page->page_content);
                     $pageTemplate = json_decode($page->page_template);
                     $formPages = array();
                     $parsedFields = array();
                     foreach ($fields as $index => $item) {
                         $tableField = JTable::getInstance('JsnField', 'JSNUniformTable');
                         $tableField->bind(array('form_id' => $table->form_id, 'field_type' => $item->type, 'field_identifier' => $item->identify, 'field_title' => $item->label, 'field_instructions' => isset($item->instruction) ? $item->instruction : null, 'field_position' => $item->position, 'field_ordering' => $index));
                         if (!$tableField->store()) {
                             $this->setError($tableField->getError());
                         }
                         $fieldSettings = $item;
                         $fieldSettings->id = $tableField->field_id;
                         $tableUpdateField = JTable::getInstance('JsnField', 'JSNUniformTable');
                         $tableUpdateField->bind(array('field_settings' => $fieldSettings, 'field_id' => $tableField->field_id));
                         if (!$tableUpdateField->store()) {
                             $this->setError($tableUpdateField->getError());
                         }
                         $parsedFields[] = $fieldSettings;
                     }
                     $formPages['page_id'] = 0;
                     $formPages['page_title'] = $page->page_title;
                     $formPages['page_container'] = $page->page_container;
                     $formPages['form_id'] = $table->form_id;
                     $formPages['page_content'] = isset($parsedFields) ? json_encode($parsedFields) : "";
                     $tablePage = JTable::getInstance('JsnPage', 'JSNUniformTable');
                     $tablePage->bind($formPages);
                     if (!$tablePage->store()) {
                         $this->setError($tablePage->getError());
                     }
                 }
             } else {
                 throw new Exception($table->getError());
             }
         }
     }
     if (!$checkCreate) {
         $msg = JText::sprintf('JSN_UNIFORM_YOU_HAVE_REACHED_THE_LIMITATION_OF_3_FORM_IN_FREE_EDITION', 0) . ' <a class="jsn-link-action" href="index.php?option=com_uniform&view=upgrade">' . JText::_("JSN_UNIFORM_UPGRADE_EDITION") . '</a>';
         throw new Exception($msg);
     }
     return true;
 }
Example #4
0
 /**
  * get List form 
  */
 public function getListForm()
 {
     $listForm = JSNUniformHelper::getForms();
     echo json_encode($listForm);
     jexit();
 }