1<?php
2
3$status = '';
4
5if (empty($_REQUEST['id'])) {
6    $id = '';
7} else {
8    $id = $_REQUEST['id'];
9    if (!isset($default_config[$id])) {
10        echo $GLOBALS['I18N']->get('invalid request');
11
12        return;
13    }
14}
15
16/*
17printf('<script type="text/javascript">
18$(".configValue").each(function() {
19  if (this.id != "edit_%s") {
20    this.innerHTML = "Not editing";
21  }
22});
23</script>',$id);
24*/
25
26$configItem = $default_config[$id];
27printf('<div class="configEditing" id="descriptionitem_'.$id.'">'.s('Editing').' <b>%s</b></div>',
28    $configItem['description']);
29printf('<div class="configValue" id="edit_%s"><input type="hidden" name="id" value="%s" />', $id, $id);
30$dbval = getConfig($id);
31//  print $dbval.'<br/>';
32if (isset($dbval)) {
33    $value = $dbval;
34} else {
35    $value = $configItem['value'];
36}
37//  print $id.' '.$value . " ".$website . " ".$domain.'<br/>';
38
39if ($id != 'website' && $id != 'domain') {
40    $value = str_replace($GLOBALS['website'], '[WEBSITE]', $value);
41    $value = str_replace($GLOBALS['domain'], '[DOMAIN]', $value);
42}
43
44//  print "VALUE:".$value . '<br/>';
45if ($configItem['type'] == 'textarea') {
46    printf('<textarea name="values[%s]" rows=25 cols=55>%s</textarea>',
47        $id, htmlspecialchars(stripslashes($value)));
48} elseif (
49    $configItem['type'] == 'text' || $configItem['type'] == 'url' ||
50    $configItem['type'] == 'email' || $configItem['type'] == 'emaillist'
51) {
52    printf('<input type="text" name="values[%s]" size="70" value="%s" />',
53        $id, htmlspecialchars(stripslashes($value)));
54} elseif ($configItem['type'] == 'integer') {
55    printf('<input type="text" name="values[%s]" size="70" value="%d" />',
56        $id, htmlspecialchars(stripslashes($value)));
57} elseif ($configItem['type'] == 'boolean') {
58    printf('<select name="values[%s]">', $id);
59    echo '<option value="true" ';
60    if ($value === true || $value == 'true' || $value == 1) {
61        echo 'selected="selected"';
62    }
63    echo '>';
64    echo $GLOBALS['I18N']->get('Yes');
65    echo '  </option>';
66    echo '<option value="false" ';
67    if ($value === false || $value == 'false' || $value == 0) {
68        echo 'selected="selected"';
69    }
70    echo '>';
71    echo $GLOBALS['I18N']->get('No');
72    echo '  </option>';
73    echo '</select>';
74} elseif ($configItem['type'] == 'image') {
75    echo '<br/><p>'.s('Please upload an image file, PNG or JPG.').'</p>';
76    include 'class.image.inc';
77    $image = new imageUpload();
78    printf('<input type="hidden" name="values[%s]" value="%s" />', $id, $value); //# to trigger the saving of the value
79    echo $image->showInput($id, $value, 0);
80} elseif ($configItem['type'] == 'select') {
81    echo '<select name="values['.$id.']">';
82    foreach ($configItem['values'] as $key => $label) {
83        print '<option value="'.$key.'"';
84        if ($key == $value) {
85            print ' selected="selected"';
86        }
87        print '>'.$label.'</option>';
88    }
89
90
91} else {
92    echo s('Don\'t know how to handle type '.$configItem['type']);
93}
94if (isset($_GET['ret']) && $_GET['ret'] == 'catlists') {
95    echo '<input type="hidden" name="ret" value="catlists" />';
96}
97echo '<input type="hidden" name="save" value="item_'.$id.'" />
98<button class="submit" type="submit" name="savebutton">' .s('save changes').'</button>';
99
100//# for cancellation, we use a reset button, but that will reset all values in the entire page
101//# https://mantis.phplist.org/view.php?id=16924
102
103//# UX wise, it would be good to close the editing DIV again.
104echo '<button class="dontsavebutton" id="dontsaveitem_'.$id.'" type="reset">'.s('undo').'</button>';
105
106//# another option is to use a link back to configure, but that will go back to top, which isn't great UX either.
107//print '<a href="./?page=configure" class="button">'.s('cancel changes').'</a>';
108
109echo '</div>';
110
111echo '<script type="text/javascript">
112
113  $(".dontsavebutton").click(function() {
114     item = $(this).attr(\'id\');
115     item = item.replace(/dontsave/,\'\');
116     desc = $("#description"+item).html();
117     $("#"+item).html(desc+\' <i>' .str_replace("'", "\'", s('editing cancelled')).'</i>\');
118  });
119
120</script>';
121