diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 2cf45e83cb460d9fe946eb63db28ce1bdd40cf55..039189a2788f365212629b66674c73b5da7a14fe 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -411,6 +411,15 @@ class DynamicFormField extends VerySimpleModel { var $_field; + const REQUIRE_NOBODY = 0; + const REQUIRE_EVERYONE = 1; + const REQUIRE_ENDUSER = 2; + const REQUIRE_AGENT = 3; + + const VISIBLE_EVERYONE = 0; + const VISIBLE_AGENTONLY = 1; + const VISIBLE_ENDUSERONLY = 2; + // Multiple inheritance -- delegate to FormField function __call($what, $args) { return call_user_func_array( @@ -481,23 +490,26 @@ class DynamicFormField extends VerySimpleModel { } function allRequirementModes() { - $modes = array( - 'a' => array('desc' => 'Optional', - 'private' => 0, 'required' => 0), - 'b' => array('desc' => 'Required', - 'private' => 0, 'required' => 1), - 'c' => array('desc' => 'Required for Users', - 'private' => 0, 'required' => 2), - 'd' => array('desc' => 'Required for Agents', - 'private' => 0, 'required' => 3), - 'e' => array('desc' => 'Internal, Optional', - 'private' => 1, 'required' => 0), - 'f' => array('desc' => 'Internal, Required', - 'private' => 1, 'required' => 1), - 'g' => array('desc' => 'For Users Only', - 'private' => 2, 'required' => 2), + return array( + 'a' => array('desc' => __('Optional'), + 'private' => self::VISIBLE_EVERYONE, 'required' => self::REQUIRE_NOBODY), + 'b' => array('desc' => __('Required'), + 'private' => self::VISIBLE_EVERYONE, 'required' => self::REQUIRE_EVERYONE), + 'c' => array('desc' => __('Required for EndUsers'), + 'private' => self::VISIBLE_EVERYONE, 'required' => self::REQUIRE_ENDUSER), + 'd' => array('desc' => __('Required for Agents'), + 'private' => self::VISIBLE_EVERYONE, 'required' => self::REQUIRE_AGENT), + 'e' => array('desc' => __('Internal, Optional'), + 'private' => self::VISIBLE_AGENTONLY, 'required' => self::REQUIRE_NOBODY), + 'f' => array('desc' => __('Internal, Required'), + 'private' => self::VISIBLE_AGENTONLY, 'required' => self::REQUIRE_EVERYONE), + 'g' => array('desc' => __('For EndUsers Only'), + 'private' => self::VISIBLE_ENDUSERONLY, 'required' => self::REQUIRE_ENDUSER), ); + } + function getAllRequirementModes() { + $modes = static::allRequirementModes(); if ($this->isPrivacyForced()) { // Required to be internal foreach ($modes as $m=>$info) { @@ -517,7 +529,7 @@ class DynamicFormField extends VerySimpleModel { } function getRequirementMode() { - foreach ($this->allRequirementModes() as $m=>$info) { + foreach ($this->getAllRequirementModes() as $m=>$info) { if ($this->get('private') == $info['private'] && $this->get('required') == $info['required']) return $m; @@ -526,7 +538,7 @@ class DynamicFormField extends VerySimpleModel { } function setRequirementMode($mode) { - $modes = $this->allRequirementModes(); + $modes = $this->getAllRequirementModes(); if (!isset($modes[$mode])) return false; @@ -536,16 +548,20 @@ class DynamicFormField extends VerySimpleModel { } function isRequiredForStaff() { - return in_array($this->get('required'), array(1, 3)); + return in_array($this->get('required'), + array(self::REQUIRE_EVERYONE, self::REQUIRE_AGENT)); } function isRequiredForUsers() { - return in_array($this->get('required'), array(1, 2)); + return in_array($this->get('required'), + array(self::REQUIRE_EVERYONE, self::REQUIRE_ENDUSER)); } function isVisibleToStaff() { - return in_array($this->get('private'), array(0, 1)); + return in_array($this->get('private'), + array(self::VISIBLE_EVERYONE, self::VISIBLE_AGENTONLY)); } function isVisibleToUsers() { - return in_array($this->get('private'), array(0, 2)); + return in_array($this->get('private'), + array(self::VISIBLE_EVERYONE, self::VISIBLE_ENDUSERONLY)); } /** @@ -562,9 +578,13 @@ class DynamicFormField extends VerySimpleModel { if ($this->get('required') && !$this->get('name')) $this->addError( __("Variable name is required for required fields" - /* `required` is a flag on fields */ + /* `required` is a visibility setting fields */ /* `variable` is used for automation. Internally it's called `name` */ ), "name"); + if (preg_match('/[.{}\'"`; ]/u', $this->get('name'))) + $this->addError(__( + 'Invalid character in variable name. Please use letters and numbers only.' + ), 'name'); return count($this->errors()) == 0; } diff --git a/include/class.forms.php b/include/class.forms.php index c80c9a6827ea85344ce9cab356fd3048e2dd0e96..04bfb303f1370772ccef1a347b12ea935384e04f 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -179,7 +179,7 @@ class FormField { 'choices' => array( /* @trans */ 'Choices', 'ChoiceField'), 'files' => array( /* @trans */ 'File Upload', 'FileUploadField'), 'break' => array( /* @trans */ 'Section Break', 'SectionBreakField'), - 'free' => array( /* @trans */ 'Free Text', 'FreeTextField'), + 'info' => array( /* @trans */ 'Information', 'FreeTextField'), ), ); static $more_types = array(); @@ -1736,7 +1736,9 @@ class TextareaWidget extends Widget { if (isset($config['length']) && $config['length']) $maxlength = "maxlength=\"{$config['length']}\""; if (isset($config['html']) && $config['html']) { - $class = 'class="richtext no-bar small"'; + $class = array('richtext', 'no-bar'); + $class[] = @$config['size'] ?: 'small'; + $class = sprintf('class="%s"', implode(' ', $class)); $this->value = Format::viewableImages($this->value); } ?> @@ -2132,7 +2134,7 @@ class FreeTextField extends FormField { function getConfigurationOptions() { return array( 'content' => new TextareaField(array( - 'configuration' => array('html' => true), + 'configuration' => array('html' => true, 'size'=>'large'), 'label'=>__('Content'), 'required'=>true, 'default'=>'', 'hint'=>__('Free text shown in the form, such as a disclaimer'), )), diff --git a/include/staff/dynamic-form.inc.php b/include/staff/dynamic-form.inc.php index 44d41081dfb8e866b1167af4b24a888b3f5e5bb5..db879cc5f4690b226bc99370382be28b11fd62ec 100644 --- a/include/staff/dynamic-form.inc.php +++ b/include/staff/dynamic-form.inc.php @@ -69,8 +69,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <th></th> <th><?php echo __('Label'); ?></th> <th><?php echo __('Type'); ?></th> - <th><?php echo __('Internal'); ?></th> - <th><?php echo __('Required'); ?></th> + <th><?php echo __('Visibility'); ?></th> <th><?php echo __('Variable'); ?></th> <th><?php echo __('Delete'); ?></th> </tr> @@ -86,9 +85,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <td></td> <td><?php echo $f->get('label'); ?></td> <td><?php $t=FormField::getFieldType($f->get('type')); echo __($t[0]); ?></td> - <td><input type="checkbox" disabled="disabled"/></td> - <td><input type="checkbox" disabled="disabled" - <?php echo $f->get('required') ? 'checked="checked"' : ''; ?>/></td> + <td><?php + $rmode = $f->getRequirementMode(); + $modes = $f->getAllRequirementModes(); + echo $modes[$rmode]['desc']; + ?></td> <td><?php echo $f->get('name'); ?></td> <td><input type="checkbox" disabled="disabled"/></td></tr> @@ -109,10 +110,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <i class="help-tip icon-question-sign" href="#field_label"></i></th> <th nowrap><?php echo __('Type'); ?> <i class="help-tip icon-question-sign" href="#field_type"></i></th> - <th nowrap><?php echo __('Internal'); ?> - <i class="help-tip icon-question-sign" href="#field_internal"></i></th> - <th nowrap><?php echo __('Required'); ?> - <i class="help-tip icon-question-sign" href="#field_required"></i></th> + <th nowrap><?php echo __('Visibility'); ?> + <i class="help-tip icon-question-sign" href="#field_visibility"></i></th> <th nowrap><?php echo __('Variable'); ?> <i class="help-tip icon-question-sign" href="#field_variable"></i></th> <th nowrap><?php echo __('Delete'); ?> @@ -157,11 +156,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); return false; "><i class="icon-edit"></i> <?php echo __('Config'); ?></a> <?php } ?></td> - <td colspan="2"> - <select name="requirement-<?php echo $id; ?>"> -<?php foreach ($f->allRequirementModes() as $m=>$info) { ?> + <td> + <select name="visibility-<?php echo $id; ?>"> +<?php foreach ($f->getAllRequirementModes() as $m=>$I) { ?> <option value="<?php echo $m; ?>" <?php if ($rmode == $m) - echo 'selected="selected"'; ?>><?php echo $info['desc']; ?></option> + echo 'selected="selected"'; ?>><?php echo $I['desc']; ?></option> <?php } ?> <select> </td> @@ -202,12 +201,15 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </optgroup> <?php } ?> </select></td> - <td><input type="checkbox" name="private-new-<?php echo $i; ?>" - <?php if ($info["private-new-$i"] - || (!$_POST && $form && $form->get('type') == 'U')) - echo 'checked="checked"'; ?>/></td> - <td><input type="checkbox" name="required-new-<?php echo $i; ?>" - <?php if ($info["required-new-$i"]) echo 'checked="checked"'; ?>/></td> + <td> + <select name="visibility-new-<?php echo $i; ?>"> +<?php + $rmode = $info['visibility-new-'.$i]; + foreach (DynamicFormField::allRequirementModes() as $m=>$I) { ?> + <option value="<?php echo $m; ?>" <?php if ($rmode == $m) + echo 'selected="selected"'; ?>><?php echo $I['desc']; ?></option> +<?php } ?> + <select> <td><input type="text" size="20" name="name-new-<?php echo $i; ?>" value="<?php echo $info["name-new-$i"]; ?>"/> <font class="error"><?php diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js index 0cf266156a1471c7036e63ab89cbece9fcf231c1..b15c3eecd9343263d0ab31a6e3f54fa542b39747 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -215,7 +215,12 @@ $(function() { }, redact = $.redact = function(el, options) { var el = $(el), - options = $.extend({ + sizes = {'small': 75, 'medium': 150, 'large': 225}, + selectedSize = sizes['medium']; + $.each(sizes, function(k, v) { + if (el.hasClass(k)) selectedSize = v; + }); + var options = $.extend({ 'air': el.hasClass('no-bar'), 'airButtons': ['formatting', '|', 'bold', 'italic', 'underline', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'image'], 'buttons': ['html', '|', 'formatting', '|', 'bold', @@ -224,7 +229,7 @@ $(function() { 'file', 'table', 'link', '|', 'alignment', '|', 'horizontalrule'], 'autoresize': !el.hasClass('no-bar'), - 'minHeight': el.hasClass('small') ? 75 : 150, + 'minHeight': selectedSize, 'focus': false, 'plugins': ['fontcolor','fontfamily', 'signature'], 'imageGetJson': 'ajax.php/draft/images/browse', diff --git a/scp/forms.php b/scp/forms.php index 5d174d5a359846bdb2a6c90b5a66ba4eec48f1a5..8b315061435edc03f5f8f4a824e5bff0088bafb4 100644 --- a/scp/forms.php +++ b/scp/forms.php @@ -38,7 +38,7 @@ if($_POST) { if (isset($_POST["name-$id"]) && !$field->isNameForced()) $field->set('name', $_POST["name-$id"]); # TODO: make sure all help topics still have all required fields - $field->setRequirementMode($_POST["requirement-$id"]); + $field->setRequirementMode($_POST["visibility-$id"]); foreach (array('sort','label') as $f) { if (isset($_POST["$f-$id"])) { @@ -47,8 +47,6 @@ if($_POST) { } if (in_array($field->get('name'), $names)) $field->addError(__('Field variable name is not unique'), 'name'); - if (preg_match('/[.{}\'"`; ]/u', $field->get('name'))) - $field->addError(__('Invalid character in variable name. Please use letters and numbers only.'), 'name'); // Subject (Issue Summary) must always have data if ($form->get('type') == 'T' && $field->get('name') == 'subject') { if (($f = $field->getField(false)->getImpl()) && !$f->hasData()) @@ -113,12 +111,15 @@ if($_POST) { 'label'=>$_POST["label-new-$i"], 'type'=>$_POST["type-new-$i"], 'name'=>$_POST["name-new-$i"], - 'private'=>$_POST["private-new-$i"] == 'on' ? 1 : 0, - 'required'=>$_POST["required-new-$i"] == 'on' ? 1 : 0 )); + $field->setRequirementMode($_POST["visibility-new-$i"]); $field->setForm($form); - if ($field->isValid()) + if (in_array($field->get('name'), $names)) + $field->addError(__('Field variable name is not unique'), 'name'); + if ($field->isValid()) { $form_fields[] = $field; + $names[] = $field->get('name'); + } else $errors["new-$i"] = $field->errors(); }