/**
  * Method to get the field input markup for a generic list.
  * Use the multiple attribute to enable multiselect.
  *
  * @return  string  The field input markup.
  *
  * @since   11.1
  */
 protected function getInput()
 {
     $html = array();
     $attr = '';
     // Initialize some field attributes.
     $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
     $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
     $attr .= $this->multiple ? ' multiple' : '';
     $attr .= $this->required ? ' required aria-required="true"' : '';
     $attr .= $this->autofocus ? ' autofocus' : '';
     // To avoid user's confusion, readonly="true" should imply disabled="true".
     if ((string) $this->readonly == '1' || (string) $this->readonly == 'true' || (string) $this->disabled == '1' || (string) $this->disabled == 'true') {
         $attr .= ' disabled="disabled"';
     }
     // Initialize JavaScript field attributes.
     //different onclick handler if field is used in an equalTo statement
     $form = $this->form;
     $label = $form->getFieldAttribute($this->fieldname, 'label');
     //get field defaultvalues
     $model = new VisformsModelVisfield();
     if ($restrictions = $model->getRestrictions($form->getValue('id', null, 0))) {
         $rfieldNames = array();
         foreach ($restrictions as $r => $value) {
             $rfieldNames[] = implode(', ', array_keys($value));
         }
         $fieldNames = implode(', ', $rfieldNames);
         //as long as the restrictions are not empty we do not allow to change the typefield
         $attr .= ' onchange="fieldUsed(this, \'' . $this->value . '\', \'' . JText::sprintf("COM_VISFORMS_FIELD_HAS_RESTICTIONS_JS", $fieldNames, JText::_($label)) . '\')"';
     } else {
         //we allow typefield change
         $attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
     }
     // Get the field options.
     $options = (array) $this->getOptions();
     // Create a read-only list (no name) with a hidden input to store the value.
     if ((string) $this->readonly == '1' || (string) $this->readonly == 'true') {
         $html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $this->value, $this->id);
         $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"/>';
     } else {
         $html[] = JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id);
     }
     return implode($html);
 }
示例#2
0
 /**
  * Delete field when deleting a form and delete field in data table when deleting a field
  * @param	string	The context for the content passed to the plugin.
  * @param	object	The data relating to the content that was deleted.
  * @return	boolean
  * @since	1.6
  */
 public function onContentBeforeDelete($context, $data)
 {
     // Skip plugin if we are deleting something other than a visforms form or field
     if ($context != 'com_visforms.visfield' && $context != 'com_visforms.visform') {
         return true;
     }
     if ($context == 'com_visforms.visfield') {
         $success = true;
         $fid = $data->fid;
         $id = $data->id;
         // Convert the defaultvalues field to an array.
         $registry = new JRegistry();
         $registry->loadString($data->defaultvalue);
         $defaultvalues = $registry->toArray();
         //Remove restrtictions
         $model = new VisformsModelVisfield();
         //getRestricts
         if ($restricts = $model->getRestricts($data->id, $data->name, $defaultvalues)) {
             //remove Restrictions
             //ToDo set an errror and return false if something went wrong
             try {
                 $model->removeRestrictions($restricts);
             } catch (RuntimeException $e) {
                 JError::raiseWarning(500, $e->getMessage);
                 return false;
             }
         }
         $db = JFactory::getDbo();
         $tablesAllowed = $db->getTableList();
         $tablesToDeleteFrom = array("visforms_" . $fid, "visforms_" . $fid . "_save");
         foreach ($tablesToDeleteFrom as $tn) {
             $tnfull = $db->getPrefix() . $tn;
             //Delete field in data table when deleting a field
             if (in_array($tnfull, $tablesAllowed)) {
                 $tableFields = $db->getTableColumns('#__' . $tn, false);
                 $fieldname = "F" . $id;
                 if (isset($tableFields[$fieldname])) {
                     $query = "ALTER TABLE #__" . $tn . " DROP " . $fieldname;
                     $db->setQuery($query);
                     try {
                         $db->execute();
                     } catch (RuntimeException $e) {
                         //set already deleted restrictions again
                         $model->setRestrictions($restricts);
                         JError::raiseWarning(500, $e->getMessage);
                         $success = false;
                         continue;
                     }
                 }
             }
         }
         if (!$success) {
             //set already deleted restrictions again
             $model->setRestrictions($restricts);
         }
         return $success;
     }
     //Delete fields in visfields table when deleting a form and delete datatable if table exists
     if ($context == 'com_visforms.visform') {
         $success = true;
         $fid = $data->id;
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->delete($db->quoteName('#__visfields'))->where($db->quoteName('fid') . " = " . $fid);
         $db->setQuery($query);
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             JError::raiseWarning(500, $e->getMessage);
             $success = false;
         }
         $tablesAllowed = $db->getTableList();
         $tablesToDelete = array("visforms_" . $fid, "visforms_" . $fid . "_save");
         foreach ($tablesToDelete as $tn) {
             $tnfull = $db->getPrefix() . $tn;
             if (in_array($tnfull, $tablesAllowed)) {
                 //no datatable exists, nothing to do
                 $db->setQuery("drop table if exists #__" . $tn);
                 try {
                     $db->execute();
                 } catch (RuntimeException $e) {
                     JError::raiseWarning(500, $e->getMessage);
                     $success = false;
                 }
             }
         }
     }
     return $success;
 }
示例#3
0
 /**
  * Batch copy fields to new forms.
  *
  * @param   int   $pk  form id of original form that is to be copied
  * @param int $newId form id of new form
  * @param   array    $contexts  An array of forms contexts.
  *
  * @return  mixed  An array of new IDs on success, boolean false on failure.
  *
  * @since	11.1
  */
 protected function batchCopyFields($pk, $newId, $contexts)
 {
     $fieldsModel = new VisformsModelVisfield();
     $fieldsTable = $fieldsModel->getTable();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     //Select Ids of Fields of copied form in Table visfields
     $query->select('a.id')->from('#__visfields AS a')->where('a.fid = ' . $pk);
     $db->setQuery($query);
     $results = $db->loadColumn();
     $fieldsModel->batch(array('form_id' => $newId, 'unpublish' => false), $results, $contexts);
     // Clean the cache
     $this->cleanCache();
 }