Skip to content
Snippets Groups Projects
dynamic-form.inc.php 9.86 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jared Hancock's avatar
    Jared Hancock committed
    <?php
    
    $info=array();
    
    if($form && $_REQUEST['a']!='add') {
    
        $title = 'Update custom form section';
    
    Jared Hancock's avatar
    Jared Hancock committed
        $action = 'update';
        $submit_text='Save Changes';
    
    Jared Hancock's avatar
    Jared Hancock committed
        $newcount=2;
    } else {
    
        $title = 'Add new custom form section';
    
    Jared Hancock's avatar
    Jared Hancock committed
        $action = 'add';
        $submit_text='Add Form';
        $newcount=4;
    }
    $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
    
    ?>
    
    <form action="?id=<?php echo urlencode($_REQUEST['id']); ?>" method="post" id="save">
    
    Jared Hancock's avatar
    Jared Hancock committed
        <?php csrf_token(); ?>
        <input type="hidden" name="do" value="<?php echo $action; ?>">
        <input type="hidden" name="id" value="<?php echo $info['id']; ?>">
    
        <h2>Custom Form</h2>
    
    Jared Hancock's avatar
    Jared Hancock committed
        <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
        <thead>
            <tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
                    <h4><?php echo $title; ?></h4>
    
                    <em>Custom forms are used to allow custom data to be
    
                    associated with tickets</em>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </th>
            </tr>
        </thead>
    
        <tbody style="vertical-align:top">
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
                <td width="180" class="required">Title:</td>
    
                <td><input type="text" name="title" size="40" value="<?php
    
                    echo $info['title']; ?>"/>
                    <i class="help-tip icon-question-sign" href="#form_title"></i>
    
                    <font class="error"><?php
                        if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
            </tr>
            <tr>
    
                <td width="180">Instructions:</td>
                <td><textarea name="instructions" rows="3" cols="40"><?php
                    echo $info['instructions']; ?></textarea>
    
                    <i class="help-tip icon-question-sign" href="#form_instructions"></i>
    
    Jared Hancock's avatar
    Jared Hancock committed
        </tbody>
    
        </table>
        <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
    
    Jared Hancock's avatar
    Jared Hancock committed
        <?php if ($form && $form->get('type') == 'T') { ?>
    
        <thead>
            <tr>
                <th colspan="7">
    
                    <em><strong>User Information Fields</strong> more information here</em>
                </th>
            </tr>
            <tr>
                <th></th>
                <th>Label</th>
                <th>Type</th>
    
                <th>Required</th>
    
            </tr>
        </thead>
        <tbody>
    
        <?php
            $uform = UserForm::objects()->all();
            $ftypes = FormField::allTypes();
            foreach ($uform[0]->getFields() as $f) {
                if ($f->get('private')) continue;
            ?>
    
                <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 echo $f->get('name'); ?></td>
                <td><input type="checkbox" disabled="disabled"/></td></tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
        <?php } # form->type == 'T' ?>
    
        <thead>
            <tr>
                <th colspan="7">
                    <em><strong>Form Fields</strong> fields available for ticket information</em>
    
                <th nowrap>Sort
                    <i class="help-tip icon-question-sign" href="#field_sort"></i></th>
                <th nowrap>Label
                    <i class="help-tip icon-question-sign" href="#field_label"></i></th>
                <th nowrap>Type
                    <i class="help-tip icon-question-sign" href="#field_type"></i></th>
                <th nowrap>Internal
                    <i class="help-tip icon-question-sign" href="#field_internal"></i></th>
                <th nowrap>Required
                    <i class="help-tip icon-question-sign" href="#field_required"></i></th>
                <th nowrap>Variable
                    <i class="help-tip icon-question-sign" href="#field_variable"></i></th>
                <th nowrap>Delete
                    <i class="help-tip icon-question-sign" href="#field_delete"></i></th>
    
    Jared Hancock's avatar
    Jared Hancock committed
        <tbody class="sortable-rows" data-sort="sort-">
    
        <?php if ($form) foreach ($form->getDynamicFields() as $f) {
    
            $id = $f->get('id');
    
            $deletable = !$f->isDeletable() ? 'disabled="disabled"' : '';
    
    Jared Hancock's avatar
    Jared Hancock committed
            $force_name = $f->isNameForced() ? 'disabled="disabled"' : '';
            $force_privacy = $f->isPrivacyForced() ? 'disabled="disabled"' : '';
            $force_required = $f->isRequirementForced() ? 'disabled="disabled"' : '';
    
            $ferrors = $f->errors(); ?>
    
                <td><i class="icon-sort"></i></td>
    
                <td><input type="text" size="32" name="label-<?php echo $id; ?>"
    
                    value="<?php echo Format::htmlchars($f->get('label')); ?>"/>
    
                    <font class="error"><?php
    
                        if ($ferrors['label']) echo '<br/>'; echo $ferrors['label']; ?>
    
                <td nowrap><select name="type-<?php echo $id; ?>" <?php
    
                    if (!$fi->isChangeable()) echo 'disabled="disabled"'; ?>>
    
                    <?php foreach (FormField::allTypes() as $group=>$types) {
                            ?><optgroup label="<?php echo Format::htmlchars($group); ?>"><?php
                            foreach ($types as $type=>$nfo) {
                                if ($f->get('type') != $type
                                        && isset($nfo[2]) && !$nfo[2]) continue; ?>
    
                    <option value="<?php echo $type; ?>" <?php
                        if ($f->get('type') == $type) echo 'selected="selected"'; ?>>
                        <?php echo $nfo[0]; ?></option>
    
                        <?php } ?>
                    </optgroup>
    
                    <?php } ?>
                </select>
                <?php if ($f->isConfigurable()) { ?>
    
                    <a class="action-button" style="float:none;overflow:inherit"
    
                        href="ajax.php/form/field-config/<?php
                            echo $f->get('id'); ?>"
                        onclick="javascript:
                            $('#overlay').show();
                            $('#field-config .body').load(this.href);
                            $('#field-config').show();
                            return false;
                        "><i class="icon-edit"></i> Config</a>
                <?php } ?></td>
    
                <td><input type="checkbox" name="private-<?php echo $id; ?>"
                    <?php if ($f->get('private')) echo 'checked="checked"'; ?>
                    <?php echo $force_privacy ?>/></td>
                <td><input type="checkbox" name="required-<?php echo $id; ?>"
                    <?php if ($f->get('required')) echo 'checked="checked"'; ?>
                    <?php echo $force_required ?>/>
                </td>
    
                <td>
                    <input type="text" size="20" name="name-<?php echo $id; ?>"
    
                        value="<?php echo Format::htmlchars($f->get('name'));
                        ?>" <?php echo $force_name ?>/>
    
                    <font class="error"><?php
    
                        if ($ferrors['name']) echo '<br/>'; echo $ferrors['name'];
    
                <td><input type="checkbox" name="delete-<?php echo $id; ?>"
                        <?php echo $deletable; ?>/>
                    <input type="hidden" name="sort-<?php echo $id; ?>"
                        value="<?php echo $f->get('sort'); ?>"/>
                    </td>
    
    Jared Hancock's avatar
    Jared Hancock committed
            </tr>
    
        <?php
        }
        for ($i=0; $i<$newcount; $i++) { ?>
    
                    <input type="hidden" name="sort-new-<?php echo $i; ?>"
                        value="<?php echo $info["sort-new-$i"]; ?>"/></td>
                <td><input type="text" size="32" name="label-new-<?php echo $i; ?>"
                    value="<?php echo $info["label-new-$i"]; ?>"/></td>
    
                <td><select name="type-new-<?php echo $i; ?>">
    
                    <?php foreach (FormField::allTypes() as $group=>$types) {
                        ?><optgroup label="<?php echo Format::htmlchars($group); ?>"><?php
    
                        foreach ($types as $type=>$nfo) {
                            if (isset($nfo[2]) && !$nfo[2]) continue; ?>
    
                    <option value="<?php echo $type; ?>"
                        <?php if ($info["type-new-$i"] == $type) echo 'selected="selected"'; ?>>
                        <?php echo $nfo[0]; ?>
                    </option>
    
                        <?php } ?>
                    </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><input type="text" size="20" name="name-new-<?php echo $i; ?>"
                    value="<?php echo $info["name-new-$i"]; ?>"/>
                    <font class="error"><?php
                        if ($errors["new-$i"]['name']) echo '<br/>'; echo $errors["new-$i"]['name'];
                    ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
        </tbody>
    
        <tbody>
            <tr>
                <th colspan="7">
                    <em><strong>Internal Notes:</strong> be liberal, they're internal</em>
                </th>
            </tr>
            <tr>
    
                <td colspan="7"><textarea class="richtext no-bar" name="notes"
                    rows="6" cols="80"><?php
    
                    echo $info['notes']; ?></textarea>
                </td>
            </tr>
        </tbody>
    
    <p class="centered">
    
    Jared Hancock's avatar
    Jared Hancock committed
        <input type="submit" name="submit" value="<?php echo $submit_text; ?>">
        <input type="reset"  name="reset"  value="Reset">
        <input type="button" name="cancel" value="Cancel" onclick='window.location.href="?"'>
    </p>
    </form>
    
    <div style="display:none;" class="dialog draggable" id="field-config">
    
        <div class="body"></div>
    </div>