dynamic-form.inc.php 12.8 KB
Newer Older
Jared Hancock's avatar
Jared Hancock committed
1
2
3
<?php

$info=array();
4
if($form && $_REQUEST['a']!='add') {
5
    $title = 'Mettre à jour la rubrique de formulaire personnalisé';
6
    $action = 'Mettre à jour';
7
    $url = "?id=".urlencode($_REQUEST['id']);
8
    $submit_text='Sauvegarder les modifications';
9
    $info = $form->ht;
Jared Hancock's avatar
Jared Hancock committed
10
11
    $newcount=2;
} else {
12
13
    $title = 'Ajouter une rubrique de formulaire personnalisé';
    $action = 'Ajouter';
14
    $url = '?a=add';
15
    $submit_text='Ajouter un formulaire';
Jared Hancock's avatar
Jared Hancock committed
16
17
18
19
20
    $newcount=4;
}
$info=Format::htmlchars(($errors && $_POST)?$_POST:$info);

?>
21
<form class="manage-form" action="<?php echo $url ?>" method="post" id="save">
Jared Hancock's avatar
Jared Hancock committed
22
23
    <?php csrf_token(); ?>
    <input type="hidden" name="do" value="<?php echo $action; ?>">
24
    <input type="hidden" name="a" value="<?php echo $action; ?>">
Jared Hancock's avatar
Jared Hancock committed
25
    <input type="hidden" name="id" value="<?php echo $info['id']; ?>">
26
    <h2>Formulaire personnalisé</h2>
Jared Hancock's avatar
Jared Hancock committed
27
28
29
    <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
    <thead>
        <tr>
30
            <th colspan="2">
Jared Hancock's avatar
Jared Hancock committed
31
                <h4><?php echo $title; ?></h4>
32
                <em>Les formulaires personnalisés sont utilisés pour permettre d’associer des données personnalisées aux tickets.</em>
Jared Hancock's avatar
Jared Hancock committed
33
34
35
            </th>
        </tr>
    </thead>
36
    <tbody style="vertical-align:top">
Jared Hancock's avatar
Jared Hancock committed
37
        <tr>
38
            <td width="180" class="required">Titre</td>
39
            <td><input type="text" name="title" size="40" value="<?php
40
41
                echo $info['title']; ?>"/>
                <i class="help-tip icon-question-sign" href="#form_title"></i>
42
43
                <font class="error"><?php
                    if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></font>
44
            </td>
Jared Hancock's avatar
Jared Hancock committed
45
46
        </tr>
        <tr>
47
            <td width="180">Instructions</td>
48
49
            <td><textarea name="instructions" rows="3" cols="40"><?php
                echo $info['instructions']; ?></textarea>
50
                <i class="help-tip icon-question-sign" href="#form_instructions"></i>
51
52
            </td>
        </tr>
Jared Hancock's avatar
Jared Hancock committed
53
    </tbody>
54
55
    </table>
    <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
Jared Hancock's avatar
Jared Hancock committed
56
    <?php if ($form && $form->get('type') == 'T') { ?>
57
58
59
    <thead>
        <tr>
            <th colspan="7">
60
                <em><strong>Champs relatifs aux informations de l’utilisateur</strong>&nbsp;: plus d’informations ici</em>
61
62
63
64
            </th>
        </tr>
        <tr>
            <th></th>
65
            <th>Étiquette</th> <!-- J’hésite à traduire 'Label' -->
66
            <th>Type</th>
67
68
            <th>Interne</th>
            <th>Requis</th>
69
            <th>Variable</th>
70
            <th>Supprimer</th>
71
72
73
        </tr>
    </thead>
    <tbody>
74
75
76
77
78
79
    <?php
        $uform = UserForm::objects()->all();
        $ftypes = FormField::allTypes();
        foreach ($uform[0]->getFields() as $f) {
            if ($f->get('private')) continue;
        ?>
80
        <tr>
81
            <td></td>
82
83
            <td><?php echo $f->get('label'); ?></td>
            <td><?php $t=FormField::getFieldType($f->get('type')); echo $t[0]; ?></td>
84
            <td><input type="checkbox" disabled="disabled"/></td>
85
            <td><input type="checkbox" disabled="disabled"
86
87
88
                <?php echo $f->get('required') ? 'checked="checked"' : ''; ?>/></td>
            <td><?php echo $f->get('name'); ?></td>
            <td><input type="checkbox" disabled="disabled"/></td></tr>
89
90

        <?php } ?>
91
    </tbody>
Jared Hancock's avatar
Jared Hancock committed
92
    <?php } # form->type == 'T' ?>
93
94
95
    <thead>
        <tr>
            <th colspan="7">
96
                <em><strong>Champs du formulaire</strong>&nbsp;: champs disponibles pour les informations sur les tickets</em>
97
98
99
            </th>
        </tr>
        <tr>
100
            <th nowrap>Tri
101
                <i class="help-tip icon-question-sign" href="#field_sort"></i></th>
102
            <th nowrap>Étiquette
103
104
105
                <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>
106
            <th nowrap>Interne
107
                <i class="help-tip icon-question-sign" href="#field_internal"></i></th>
108
            <th nowrap>Requis
109
110
111
                <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>
112
            <th nowrap>Supprimer
113
                <i class="help-tip icon-question-sign" href="#field_delete"></i></th>
114
115
        </tr>
    </thead>
Jared Hancock's avatar
Jared Hancock committed
116
    <tbody class="sortable-rows" data-sort="sort-">
117
    <?php if ($form) foreach ($form->getDynamicFields() as $f) {
118
        $id = $f->get('id');
119
        $deletable = !$f->isDeletable() ? 'disabled="disabled"' : '';
Jared Hancock's avatar
Jared Hancock committed
120
121
122
        $force_name = $f->isNameForced() ? 'disabled="disabled"' : '';
        $force_privacy = $f->isPrivacyForced() ? 'disabled="disabled"' : '';
        $force_required = $f->isRequirementForced() ? 'disabled="disabled"' : '';
123
        $fi = $f->getImpl();
124
        $ferrors = $f->errors(); ?>
125
        <tr>
126
            <td><i class="icon-sort"></i></td>
127
            <td><input type="text" size="32" name="label-<?php echo $id; ?>"
128
                value="<?php echo Format::htmlchars($f->get('label')); ?>"/>
129
                <font class="error"><?php
130
                    if ($ferrors['label']) echo '<br/>'; echo $ferrors['label']; ?>
131
            </td>
132
            <td nowrap><select name="type-<?php echo $id; ?>" <?php
133
                if (!$fi->isChangeable()) echo 'disabled="disabled"'; ?>>
134
135
136
137
138
                <?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; ?>
139
140
141
                <option value="<?php echo $type; ?>" <?php
                    if ($f->get('type') == $type) echo 'selected="selected"'; ?>>
                    <?php echo $nfo[0]; ?></option>
142
143
                    <?php } ?>
                </optgroup>
144
145
146
                <?php } ?>
            </select>
            <?php if ($f->isConfigurable()) { ?>
147
                <a class="action-button" style="float:none;overflow:inherit"
148
                    href="#ajax.php/form/field-config/<?php
149
150
151
                        echo $f->get('id'); ?>"
                    onclick="javascript:
                        $('#overlay').show();
152
                        $('#field-config .body').load($(this).attr('href').substr(1));
153
154
155
                        $('#field-config').show();
                        return false;
                    "><i class="icon-edit"></i> Config</a>
156
157
158
159
160
            <?php } ?>
            <div class="error" style="white-space:normal"><?php
                if ($ferrors['type']) echo $ferrors['type'];
            ?></div>
            </td>
161
162
163
164
165
166
167
            <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>
168
169
            <td>
                <input type="text" size="20" name="name-<?php echo $id; ?>"
170
171
                    value="<?php echo Format::htmlchars($f->get('name'));
                    ?>" <?php echo $force_name ?>/>
172
                <font class="error"><?php
173
                    if ($ferrors['name']) echo '<br/>'; echo $ferrors['name'];
174
175
                ?></font>
                </td>
176
177
178
            <td><input class="delete-box" type="checkbox" name="delete-<?php echo $id; ?>"
                    data-field-label="<?php echo $f->get('label'); ?>"
                    data-field-id="<?php echo $id; ?>"
179
180
181
182
                    <?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
183
        </tr>
184
185
186
    <?php
    }
    for ($i=0; $i<$newcount; $i++) { ?>
187
            <td><em>+</em>
188
189
190
191
                <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>
192
            <td><select name="type-new-<?php echo $i; ?>">
193
194
                <?php foreach (FormField::allTypes() as $group=>$types) {
                    ?><optgroup label="<?php echo Format::htmlchars($group); ?>"><?php
195
196
                    foreach ($types as $type=>$nfo) {
                        if (isset($nfo[2]) && !$nfo[2]) continue; ?>
197
198
199
200
                <option value="<?php echo $type; ?>"
                    <?php if ($info["type-new-$i"] == $type) echo 'selected="selected"'; ?>>
                    <?php echo $nfo[0]; ?>
                </option>
201
202
                    <?php } ?>
                </optgroup>
203
204
                <?php } ?>
            </select></td>
205
            <td><input type="checkbox" name="private-new-<?php echo $i; ?>"
206
207
            <?php if ($info["private-new-$i"]
                || (!$_POST && $form && $form->get('type') == 'U'))
208
                    echo 'checked="checked"'; ?>/></td>
209
210
211
212
213
214
215
            <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>
216
            <td></td>
217
218
        </tr>
    <?php } ?>
Jared Hancock's avatar
Jared Hancock committed
219
    </tbody>
220
221
222
    <tbody>
        <tr>
            <th colspan="7">
223
                <em><strong>Notes internes</strong>&nbsp;: soyez prolixes, elles sont internes</em>
224
225
226
            </th>
        </tr>
        <tr>
227
228
            <td colspan="7"><textarea class="richtext no-bar" name="notes"
                rows="6" cols="80"><?php
229
230
231
232
                echo $info['notes']; ?></textarea>
            </td>
        </tr>
    </tbody>
233
    </table>
234
<p class="centered">
Jared Hancock's avatar
Jared Hancock committed
235
    <input type="submit" name="submit" value="<?php echo $submit_text; ?>">
236
237
    <input type="reset"  name="reset"  value="Réinitialiser">
    <input type="button" name="cancel" value="Annuler" onclick='window.location.href="?"'>
Jared Hancock's avatar
Jared Hancock committed
238
</p>
239

240
<div style="display:none;" class="draggable dialog" id="delete-confirm">
241
    <h3><i class="icon-trash"></i> Supprimer les données existantes&nbsp;?</h3>
242
243
    <a class="close" href=""><i class="icon-remove-circle"></i></a>
    <hr/>
244
    <p>
245
246
247
248
        <strong>Vous êtes sur le point de supprimer <span id="deleted-count"></span> champs.</strong>
        Souhaitez-vous également supprimer les données actuellement entrées dans ce(s) champs&nbsp;?
        <em>Si vous choisissez de ne pas supprimer ces données maintenant, vous aurez la possibilité
        de supprimer ces données en les éditant.</em>
249
    </p><p style="color:red">
250
        Les données supprimées ne POURRONT PAS être récupérées.
251
    </p>
252
253
    <hr>
    <div id="deleted-fields"></div>
254
255
256
    <hr style="margin-top:1em"/>
    <p class="full-width">
        <span class="buttons" style="float:left">
257
            <input type="button" value="Non, annuler" class="close">
258
259
        </span>
        <span class="buttons" style="float:right">
260
            <input type="submit" value="Continuer" class="confirm">
261
262
263
264
        </span>
     </p>
    <div class="clear"></div>
</div>
Jared Hancock's avatar
Jared Hancock committed
265
</form>
266

267
<div style="display:none;" class="dialog draggable" id="field-config">
268
269
    <div class="body"></div>
</div>
270
271

<script type="text/javascript">
272
$('form.manage-form').on('submit.inline', function(e) {
273
274
    var formObj = this, deleted = $('input.delete-box:checked', this);
    if (deleted.length) {
275
        e.stopImmediatePropagation();
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
        $('#overlay').show();
        $('#deleted-fields').empty();
        deleted.each(function(i, e) {
            $('#deleted-fields').append($('<p></p>')
                .append($('<input/>').attr({type:'checkbox',name:'delete-data-'
                    + $(e).data('fieldId')})
                ).append($('<strong>').html(
                    'Remove all data entered for <u>' + $(e).data('fieldLabel') + '</u>'
                ))
            );
        });
        $('#delete-confirm').show().delegate('input.confirm', 'click.confirm', function() {
            $('.dialog#delete-confirm').hide();
            $(formObj).unbind('submit.inline');
            $(window).unbind('beforeunload');
            $('#loading').show();
        })
        return false;
    }
    // TODO: Popup the 'please wait' dialog
    $(window).unbind('beforeunload');
    $('#loading').show();
});
</script>