Statistiques
| Branche: | Révision :

root / src / phpMyEdit.class.php @ a9b72d88

Historique | Voir | Annoter | Télécharger (118,13 ko)

1 1a2be799 Florent Chuffart
<?php
2 1a2be799 Florent Chuffart
3 1a2be799 Florent Chuffart
/*
4 1a2be799 Florent Chuffart
 * phpMyEdit - instant MySQL table editor and code generator
5 1a2be799 Florent Chuffart
 *
6 1a2be799 Florent Chuffart
 * phpMyEdit.class.php - main table editor class definition file
7 1a2be799 Florent Chuffart
 * ____________________________________________________________
8 1a2be799 Florent Chuffart
 *
9 1a2be799 Florent Chuffart
 * Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net>
10 1a2be799 Florent Chuffart
 * Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net>
11 1a2be799 Florent Chuffart
 * Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net>
12 1a2be799 Florent Chuffart
 * Copyright (c) 2002-2006 Platon Group, http://platon.sk/
13 1a2be799 Florent Chuffart
 * All rights reserved.
14 1a2be799 Florent Chuffart
 *
15 1a2be799 Florent Chuffart
 * See README file for more information about this software.
16 1a2be799 Florent Chuffart
 * See COPYING file for license information.
17 1a2be799 Florent Chuffart
 *
18 1a2be799 Florent Chuffart
 * Download the latest version from
19 1a2be799 Florent Chuffart
 * http://platon.sk/projects/phpMyEdit/
20 1a2be799 Florent Chuffart
 */
21 1a2be799 Florent Chuffart
22 1a2be799 Florent Chuffart
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.204 2007-09-16 12:57:07 nepto Exp $ */
23 1a2be799 Florent Chuffart
24 1a2be799 Florent Chuffart
/*  This is a generic table editing program. The table and fields to be
25 1a2be799 Florent Chuffart
        edited are defined in the calling program.
26 1a2be799 Florent Chuffart

27 1a2be799 Florent Chuffart
        This program works in three passes.
28 1a2be799 Florent Chuffart
        * Pass 1 (the last part of the program) displays the selected SQL
29 1a2be799 Florent Chuffart
          table in a scrolling table on the screen. Radio buttons are used to
30 1a2be799 Florent Chuffart
          select a record for editing or deletion. If the user chooses Add,
31 1a2be799 Florent Chuffart
          Change, Copy, View or Delete buttons.
32 1a2be799 Florent Chuffart
        * Pass 2 starts, displaying the selected record. If the user chooses
33 1a2be799 Florent Chuffart
          the Save button from this screen.
34 1a2be799 Florent Chuffart
        * Pass 3 processes the update and the display returns to the
35 1a2be799 Florent Chuffart
          original table view (Pass 1).
36 1a2be799 Florent Chuffart
*/
37 1a2be799 Florent Chuffart
38 1a2be799 Florent Chuffart
class phpMyEdit_timer /* {{{ */
39 1a2be799 Florent Chuffart
{
40 1a2be799 Florent Chuffart
        var $startTime;
41 1a2be799 Florent Chuffart
        var $started;
42 1a2be799 Florent Chuffart
43 1a2be799 Florent Chuffart
        function phpMyEdit_timer($start = true)
44 1a2be799 Florent Chuffart
        {
45 1a2be799 Florent Chuffart
                $this->started = false;
46 1a2be799 Florent Chuffart
                if ($start) {
47 1a2be799 Florent Chuffart
                        $this->start();
48 1a2be799 Florent Chuffart
                }
49 1a2be799 Florent Chuffart
        }
50 1a2be799 Florent Chuffart
51 1a2be799 Florent Chuffart
        function start()
52 1a2be799 Florent Chuffart
        {
53 1a2be799 Florent Chuffart
                $startMtime      = explode(' ', microtime());
54 1a2be799 Florent Chuffart
                $this->startTime = (double) $startMtime[0] + (double) $startMtime[1];
55 1a2be799 Florent Chuffart
                $this->started   = true;
56 1a2be799 Florent Chuffart
        }
57 1a2be799 Florent Chuffart
58 1a2be799 Florent Chuffart
        function end($iterations = 1)
59 1a2be799 Florent Chuffart
        {
60 1a2be799 Florent Chuffart
                // get the time, check whether the timer was started later
61 1a2be799 Florent Chuffart
                $endMtime = explode(' ', microtime());
62 1a2be799 Florent Chuffart
                if ($this->started) {
63 1a2be799 Florent Chuffart
                        $endTime = (double)($endMtime[0])+(double)($endMtime[1]);
64 1a2be799 Florent Chuffart
                        $dur = $endTime - $this->startTime;
65 1a2be799 Florent Chuffart
                        $avg = 1000 * $dur / $iterations;
66 1a2be799 Florent Chuffart
                        $avg = round(1000 * $avg) / 1000;
67 1a2be799 Florent Chuffart
                        return $avg;
68 1a2be799 Florent Chuffart
                } else {
69 1a2be799 Florent Chuffart
                        return 'phpMyEdit_timer ERROR: timer not started';
70 1a2be799 Florent Chuffart
                }
71 1a2be799 Florent Chuffart
        }
72 1a2be799 Florent Chuffart
} /* }}} */
73 1a2be799 Florent Chuffart
74 1a2be799 Florent Chuffart
if (! function_exists('array_search')) { /* {{{ */
75 1a2be799 Florent Chuffart
        function array_search($needle, $haystack)
76 1a2be799 Florent Chuffart
        {
77 1a2be799 Florent Chuffart
                foreach ($haystack as $key => $value) {
78 1a2be799 Florent Chuffart
                        if ($needle == $value)
79 1a2be799 Florent Chuffart
                                return $key;
80 1a2be799 Florent Chuffart
                }
81 1a2be799 Florent Chuffart
                return false;
82 1a2be799 Florent Chuffart
        }
83 1a2be799 Florent Chuffart
} /* }}} */
84 1a2be799 Florent Chuffart
85 1a2be799 Florent Chuffart
if (! function_exists('realpath')) { /* {{{ */
86 1a2be799 Florent Chuffart
        function realpath($path)
87 1a2be799 Florent Chuffart
        {
88 1a2be799 Florent Chuffart
                return $path;
89 1a2be799 Florent Chuffart
        }
90 1a2be799 Florent Chuffart
} /* }}} */
91 1a2be799 Florent Chuffart
92 1a2be799 Florent Chuffart
class phpMyEdit
93 1a2be799 Florent Chuffart
{
94 1a2be799 Florent Chuffart
        // Class variables {{{
95 1a2be799 Florent Chuffart
96 1a2be799 Florent Chuffart
        // Database handling
97 1a2be799 Florent Chuffart
        var $hn;                // hostname
98 1a2be799 Florent Chuffart
        var $un;                // user name
99 1a2be799 Florent Chuffart
        var $pw;                // password
100 1a2be799 Florent Chuffart
        var $tb;                // table
101 1a2be799 Florent Chuffart
        var $db;                // database
102 1a2be799 Florent Chuffart
        var $dbp;                // database with point and delimiters
103 1a2be799 Florent Chuffart
        var $dbh;                // database handle
104 1a2be799 Florent Chuffart
        var $close_dbh;        // if database handle should be closed
105 1a2be799 Florent Chuffart
106 1a2be799 Florent Chuffart
        // Record manipulation
107 1a2be799 Florent Chuffart
        var $key;                // name of field which is the unique key
108 1a2be799 Florent Chuffart
        var $key_num;        // number of field which is the unique key
109 1a2be799 Florent Chuffart
        var $key_type;        // type of key field (int/real/string/date etc.)
110 1a2be799 Florent Chuffart
        var $key_delim;        // character used for key value quoting
111 1a2be799 Florent Chuffart
        var $rec;                // number of record selected for editing
112 1a2be799 Florent Chuffart
        var $inc;                // number of records to display
113 1a2be799 Florent Chuffart
        var $fm;                // first record to display
114 1a2be799 Florent Chuffart
        var $fl;                // is the filter row displayed (boolean)
115 1a2be799 Florent Chuffart
        var $fds;                // sql field names
116 1a2be799 Florent Chuffart
        var $fdn;                // sql field names => $k
117 1a2be799 Florent Chuffart
        var $num_fds;        // number of fields
118 1a2be799 Florent Chuffart
        var $options;        // options for users: ACDFVPI
119 1a2be799 Florent Chuffart
        var $fdd;                // field definitions
120 1a2be799 Florent Chuffart
        var $qfn;                // value of all filters used during the last pass
121 1a2be799 Florent Chuffart
        var $sfn;                // sort field number (- = descending sort order)
122 1a2be799 Florent Chuffart
        var $cur_tab;        // current selected tab
123 1a2be799 Florent Chuffart
124 1a2be799 Florent Chuffart
        // Operation
125 1a2be799 Florent Chuffart
        var $navop;                // navigation buttons/operations
126 1a2be799 Florent Chuffart
        var $sw;                // filter display/hide/clear button
127 1a2be799 Florent Chuffart
        var $operation;        // operation to do: Add, Change, Delete
128 1a2be799 Florent Chuffart
        var $saveadd;
129 1a2be799 Florent Chuffart
        var $moreadd;
130 1a2be799 Florent Chuffart
        var $canceladd;
131 1a2be799 Florent Chuffart
        var $savechange;
132 1a2be799 Florent Chuffart
        var $morechange;
133 1a2be799 Florent Chuffart
        var $cancelchange;
134 1a2be799 Florent Chuffart
        var $savecopy;
135 1a2be799 Florent Chuffart
        var $cancelcopy;
136 1a2be799 Florent Chuffart
        var $savedelete;
137 1a2be799 Florent Chuffart
        var $canceldelete;
138 1a2be799 Florent Chuffart
        var $cancelview;
139 1a2be799 Florent Chuffart
140 1a2be799 Florent Chuffart
        // Additional features
141 1a2be799 Florent Chuffart
        var $labels;                // multilingual labels
142 1a2be799 Florent Chuffart
        var $cgi;                        // CGI variable features array
143 1a2be799 Florent Chuffart
        var $js;                        // JS configuration array
144 1a2be799 Florent Chuffart
        var $dhtml;                        // DHTML configuration array
145 1a2be799 Florent Chuffart
        var $url;                        // URL array
146 1a2be799 Florent Chuffart
        var $message;                // informational message to print
147 1a2be799 Florent Chuffart
        var $notify;                // change notification e-mail adresses
148 1a2be799 Florent Chuffart
        var $logtable;                // name of optional logtable
149 1a2be799 Florent Chuffart
        var $navigation;        // navigation style
150 1a2be799 Florent Chuffart
        var $tabs;                        // TAB names
151 1a2be799 Florent Chuffart
        var $timer = null;        // phpMyEdit_timer object
152 1a2be799 Florent Chuffart
        var $sd; var $ed;        // sql start and end delimiters '`' in case of MySQL
153 1a2be799 Florent Chuffart
154 1a2be799 Florent Chuffart
        // Predefined variables
155 1a2be799 Florent Chuffart
        var $comp_ops  = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>');
156 1a2be799 Florent Chuffart
        var $sql_aggrs = array(
157 1a2be799 Florent Chuffart
                        'sum'   => 'Total',
158 1a2be799 Florent Chuffart
                        'avg'   => 'Average',
159 1a2be799 Florent Chuffart
                        'min'   => 'Minimum',
160 1a2be799 Florent Chuffart
                        'max'   => 'Maximum',
161 1a2be799 Florent Chuffart
                        'count' => 'Count');
162 1a2be799 Florent Chuffart
        var $page_types = array(
163 1a2be799 Florent Chuffart
                        'L' => 'list',
164 1a2be799 Florent Chuffart
                        'F' => 'filter',
165 1a2be799 Florent Chuffart
                        'A' => 'add',
166 1a2be799 Florent Chuffart
                        'V' => 'view',
167 1a2be799 Florent Chuffart
                        'C' => 'change',
168 1a2be799 Florent Chuffart
                        'P' => 'copy',
169 1a2be799 Florent Chuffart
                        'D' => 'delete'
170 1a2be799 Florent Chuffart
                        );
171 1a2be799 Florent Chuffart
        var $default_buttons = array(
172 1a2be799 Florent Chuffart
                        'L' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'),
173 1a2be799 Florent Chuffart
                        'F' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'),
174 1a2be799 Florent Chuffart
                        'A' => array('save','more','cancel'),
175 1a2be799 Florent Chuffart
                        'C' => array('save','more','cancel'),
176 1a2be799 Florent Chuffart
                        'P' => array('save', 'cancel'),
177 1a2be799 Florent Chuffart
                        'D' => array('save','cancel'),
178 1a2be799 Florent Chuffart
                        'V' => array('change','cancel')
179 1a2be799 Florent Chuffart
                        );
180 1a2be799 Florent Chuffart
        // }}}
181 1a2be799 Florent Chuffart
182 1a2be799 Florent Chuffart
        /*
183 1a2be799 Florent Chuffart
         * column specific functions
184 1a2be799 Florent Chuffart
         */
185 1a2be799 Florent Chuffart
186 1a2be799 Florent Chuffart
        function col_has_sql($k)    { return isset($this->fdd[$k]['sql']); }
187 1a2be799 Florent Chuffart
        function col_has_sqlw($k)   { return isset($this->fdd[$k]['sqlw']) && !$this->virtual($k); }
188 1a2be799 Florent Chuffart
        function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); }
189 1a2be799 Florent Chuffart
        function col_has_php($k)    { return isset($this->fdd[$k]['php']); }
190 1a2be799 Florent Chuffart
        function col_has_URL($k)    { return isset($this->fdd[$k]['URL'])
191 1a2be799 Florent Chuffart
                || isset($this->fdd[$k]['URLprefix']) || isset($this->fdd[$k]['URLpostfix']); }
192 1a2be799 Florent Chuffart
        function col_has_multiple($k)
193 1a2be799 Florent Chuffart
        { return $this->col_has_multiple_select($k) || $this->col_has_checkboxes($k); }
194 1a2be799 Florent Chuffart
        function col_has_multiple_select($k)
195 1a2be799 Florent Chuffart
        { return $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; }
196 1a2be799 Florent Chuffart
        function col_has_checkboxes($k)
197 1a2be799 Florent Chuffart
        { return $this->fdd[$k]['select'] == 'C' && ! $this->fdd[$k]['values']['table']; }
198 1a2be799 Florent Chuffart
        function col_has_radio_buttons($k)
199 1a2be799 Florent Chuffart
        { return $this->fdd[$k]['select'] == 'O' && ! $this->fdd[$k]['values']['table']; }
200 1a2be799 Florent Chuffart
        function col_has_datemask($k)
201 1a2be799 Florent Chuffart
        { return isset($this->fdd[$k]['datemask']) || isset($this->fdd[$k]['strftimemask']); }
202 1a2be799 Florent Chuffart
203 1a2be799 Florent Chuffart
        /*
204 1a2be799 Florent Chuffart
         * functions for indicating whether navigation style is enabled
205 1a2be799 Florent Chuffart
     */
206 1a2be799 Florent Chuffart
207 1a2be799 Florent Chuffart
        function nav_buttons()       { return stristr($this->navigation, 'B'); }
208 1a2be799 Florent Chuffart
        function nav_text_links()    { return stristr($this->navigation, 'T'); }
209 1a2be799 Florent Chuffart
        function nav_graphic_links() { return stristr($this->navigation, 'G'); }
210 1a2be799 Florent Chuffart
        function nav_up()            { return (stristr($this->navigation, 'U') && !($this->buttons[$this->page_type]['up'] === false)); }
211 1a2be799 Florent Chuffart
        function nav_down()          { return (stristr($this->navigation, 'D') && !($this->buttons[$this->page_type]['down'] === false)); }
212 1a2be799 Florent Chuffart
213 1a2be799 Florent Chuffart
        /*
214 1a2be799 Florent Chuffart
         * functions for indicating whether operations are enabled
215 1a2be799 Florent Chuffart
         */
216 1a2be799 Florent Chuffart
217 1a2be799 Florent Chuffart
        function add_enabled()    { return stristr($this->options, 'A'); }
218 1a2be799 Florent Chuffart
        function change_enabled() { return stristr($this->options, 'C'); }
219 1a2be799 Florent Chuffart
        function delete_enabled() { return stristr($this->options, 'D'); }
220 1a2be799 Florent Chuffart
        function filter_enabled() { return stristr($this->options, 'F'); }
221 1a2be799 Florent Chuffart
        function view_enabled()   { return stristr($this->options, 'V'); }
222 1a2be799 Florent Chuffart
        function copy_enabled()   { return stristr($this->options, 'P') && $this->add_enabled(); }
223 1a2be799 Florent Chuffart
        function tabs_enabled()   { return $this->display['tabs'] && count($this->tabs) > 0; }
224 1a2be799 Florent Chuffart
        function hidden($k)       { return stristr($this->fdd[$k]['input'],'H'); }
225 1a2be799 Florent Chuffart
        function password($k)     { return stristr($this->fdd[$k]['input'],'W'); }
226 1a2be799 Florent Chuffart
        function readonly($k)     { return stristr($this->fdd[$k]['input'],'R') || $this->virtual($k);     }
227 1a2be799 Florent Chuffart
        function virtual($k)      { return stristr($this->fdd[$k]['input'],'V') && $this->col_has_sql($k); }
228 1a2be799 Florent Chuffart
229 1a2be799 Florent Chuffart
        function add_operation()    { return $this->operation == $this->labels['Add']    && $this->add_enabled();    }
230 1a2be799 Florent Chuffart
        function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); }
231 1a2be799 Florent Chuffart
        function copy_operation()   { return $this->operation == $this->labels['Copy']   && $this->copy_enabled();   }
232 1a2be799 Florent Chuffart
        function delete_operation() { return $this->operation == $this->labels['Delete'] && $this->delete_enabled(); }
233 1a2be799 Florent Chuffart
        function view_operation()   { return $this->operation == $this->labels['View']   && $this->view_enabled();   }
234 1a2be799 Florent Chuffart
        function filter_operation() { return $this->fl && $this->filter_enabled() && $this->list_operation(); }
235 1a2be799 Florent Chuffart
        function list_operation()   { /* covers also filtering page */ return ! $this->change_operation()
236 1a2be799 Florent Chuffart
                                                                                && ! $this->add_operation()    && ! $this->copy_operation()
237 1a2be799 Florent Chuffart
                                                                                && ! $this->delete_operation() && ! $this->view_operation(); }
238 1a2be799 Florent Chuffart
        function next_operation()        { return ($this->navop == $this->labels['Next']) || ($this->navop == '>'); }
239 1a2be799 Florent Chuffart
        function prev_operation()        { return ($this->navop == $this->labels['Prev']) || ($this->navop == '<'); }
240 1a2be799 Florent Chuffart
        function first_operation()        { return ($this->navop == $this->labels['First']) || ($this->navop == '<<'); }
241 1a2be799 Florent Chuffart
        function last_operation()        { return ($this->navop == $this->labels['Last']) || ($this->navop == '>>'); }
242 1a2be799 Florent Chuffart
        function clear_operation()        { return $this->sw == $this->labels['Clear'];  }
243 1a2be799 Florent Chuffart
244 1a2be799 Florent Chuffart
        function add_canceled()    { return $this->canceladd    == $this->labels['Cancel']; }
245 1a2be799 Florent Chuffart
        function view_canceled()   { return $this->cancelview   == $this->labels['Cancel']; }
246 1a2be799 Florent Chuffart
        function change_canceled() { return $this->cancelchange == $this->labels['Cancel']; }
247 1a2be799 Florent Chuffart
        function copy_canceled()   { return $this->cancelcopy   == $this->labels['Cancel']; }
248 1a2be799 Florent Chuffart
        function delete_canceled() { return $this->canceldelete == $this->labels['Cancel']; }
249 1a2be799 Florent Chuffart
250 1a2be799 Florent Chuffart
        function is_values2($k, $val = 'X') /* {{{ */
251 1a2be799 Florent Chuffart
        {
252 1a2be799 Florent Chuffart
                return $val === null ||
253 1a2be799 Florent Chuffart
                        (isset($this->fdd[$k]['values2']) && !isset($this->fdd[$k]['values']['table']));
254 1a2be799 Florent Chuffart
        } /* }}} */
255 1a2be799 Florent Chuffart
256 1a2be799 Florent Chuffart
        function processed($k) /* {{{ */
257 1a2be799 Florent Chuffart
        {
258 1a2be799 Florent Chuffart
                if ($this->virtual($k)) {
259 1a2be799 Florent Chuffart
                        return false;
260 1a2be799 Florent Chuffart
                }
261 1a2be799 Florent Chuffart
                $options = @$this->fdd[$k]['options'];
262 1a2be799 Florent Chuffart
                if (! isset($options)) {
263 1a2be799 Florent Chuffart
                        return true;
264 1a2be799 Florent Chuffart
                }
265 1a2be799 Florent Chuffart
                return
266 1a2be799 Florent Chuffart
                        ($this->saveadd    == $this->labels['Save']  && stristr($options, 'A')) ||
267 1a2be799 Florent Chuffart
                        ($this->moreadd    == $this->labels['More']  && stristr($options, 'A')) ||
268 1a2be799 Florent Chuffart
                        ($this->savechange == $this->labels['Save']  && stristr($options, 'C')) ||
269 1a2be799 Florent Chuffart
                        ($this->morechange == $this->labels['Apply'] && stristr($options, 'C')) ||
270 1a2be799 Florent Chuffart
                        ($this->savecopy   == $this->labels['Save']  && stristr($options, 'P')) ||
271 1a2be799 Florent Chuffart
                        ($this->savedelete == $this->labels['Save']  && stristr($options, 'D'));
272 1a2be799 Florent Chuffart
        } /* }}} */
273 1a2be799 Florent Chuffart
274 1a2be799 Florent Chuffart
        function displayed($k) /* {{{ */
275 1a2be799 Florent Chuffart
        {
276 1a2be799 Florent Chuffart
                if (is_numeric($k)) {
277 1a2be799 Florent Chuffart
                        $k = $this->fds[$k];
278 1a2be799 Florent Chuffart
                }
279 1a2be799 Florent Chuffart
                $options = @$this->fdd[$k]['options'];
280 1a2be799 Florent Chuffart
                if (! isset($options)) {
281 1a2be799 Florent Chuffart
                        return true;
282 1a2be799 Florent Chuffart
                }
283 1a2be799 Florent Chuffart
                return
284 1a2be799 Florent Chuffart
                        ($this->add_operation()    && stristr($options, 'A')) ||
285 1a2be799 Florent Chuffart
                        ($this->view_operation()   && stristr($options, 'V')) ||
286 1a2be799 Florent Chuffart
                        ($this->change_operation() && stristr($options, 'C')) ||
287 1a2be799 Florent Chuffart
                        ($this->copy_operation()   && stristr($options, 'P')) ||
288 1a2be799 Florent Chuffart
                        ($this->delete_operation() && stristr($options, 'D')) ||
289 1a2be799 Florent Chuffart
                        ($this->filter_operation() && stristr($options, 'F')) ||
290 1a2be799 Florent Chuffart
                        ($this->list_operation()   && stristr($options, 'L'));
291 1a2be799 Florent Chuffart
        } /* }}} */
292 1a2be799 Florent Chuffart
        
293 1a2be799 Florent Chuffart
        function debug_var($name, $val) /* {{{ */
294 1a2be799 Florent Chuffart
        {
295 1a2be799 Florent Chuffart
                if (is_array($val) || is_object($val)) {
296 1a2be799 Florent Chuffart
                        echo "<pre>$name\n";
297 1a2be799 Florent Chuffart
                        ob_start();
298 1a2be799 Florent Chuffart
                        //print_r($val);
299 1a2be799 Florent Chuffart
                        var_dump($val);
300 1a2be799 Florent Chuffart
                        $content = ob_get_contents();
301 1a2be799 Florent Chuffart
                        ob_end_clean();
302 1a2be799 Florent Chuffart
                        echo htmlspecialchars($content);
303 1a2be799 Florent Chuffart
                        echo "</pre>\n";
304 1a2be799 Florent Chuffart
                } else {
305 1a2be799 Florent Chuffart
                        echo 'debug_var()::<i>',htmlspecialchars($name),'</i>';
306 1a2be799 Florent Chuffart
                        echo '::<b>',htmlspecialchars($val),'</b>::',"<br />\n";
307 1a2be799 Florent Chuffart
                }
308 1a2be799 Florent Chuffart
        } /* }}} */
309 1a2be799 Florent Chuffart
310 1a2be799 Florent Chuffart
        /*
311 1a2be799 Florent Chuffart
         * sql functions
312 1a2be799 Florent Chuffart
     */
313 1a2be799 Florent Chuffart
        function sql_connect() /* {{{ */
314 1a2be799 Florent Chuffart
        {
315 1a2be799 Florent Chuffart
                $this->dbh = @ini_get('allow_persistent')
316 1a2be799 Florent Chuffart
                        ? @mysql_pconnect($this->hn, $this->un, $this->pw)
317 1a2be799 Florent Chuffart
                        : @mysql_connect($this->hn, $this->un, $this->pw);
318 1a2be799 Florent Chuffart
        } /* }}} */
319 1a2be799 Florent Chuffart
                
320 1a2be799 Florent Chuffart
321 1a2be799 Florent Chuffart
        function sql_disconnect() /* {{{ */
322 1a2be799 Florent Chuffart
        {
323 1a2be799 Florent Chuffart
                if ($this->close_dbh) {
324 1a2be799 Florent Chuffart
                        @mysql_close($this->dbh);
325 1a2be799 Florent Chuffart
                        $this->dbh = null;
326 1a2be799 Florent Chuffart
                }
327 1a2be799 Florent Chuffart
        } /* }}} */
328 1a2be799 Florent Chuffart
329 1a2be799 Florent Chuffart
        function sql_fetch(&$res, $type = 'a') /* {{{ */
330 1a2be799 Florent Chuffart
        {
331 1a2be799 Florent Chuffart
                if($type == 'n') $type = MYSQL_NUM;
332 1a2be799 Florent Chuffart
                else $type = MYSQL_ASSOC;
333 1a2be799 Florent Chuffart
                return @mysql_fetch_array($res, $type);
334 1a2be799 Florent Chuffart
        } /* }}} */
335 1a2be799 Florent Chuffart
336 1a2be799 Florent Chuffart
        function sql_free_result(&$res) /* {{{ */
337 1a2be799 Florent Chuffart
        {
338 1a2be799 Florent Chuffart
                return @mysql_free_result($res);
339 1a2be799 Florent Chuffart
        } /* }}} */
340 1a2be799 Florent Chuffart
341 1a2be799 Florent Chuffart
        function sql_affected_rows(&$dbh) /* {{{ */
342 1a2be799 Florent Chuffart
        {
343 1a2be799 Florent Chuffart
                return @mysql_affected_rows($dbh);
344 1a2be799 Florent Chuffart
        } /* }}} */
345 1a2be799 Florent Chuffart
346 1a2be799 Florent Chuffart
        function sql_field_len(&$res,$field) /* {{{ */
347 1a2be799 Florent Chuffart
        {
348 1a2be799 Florent Chuffart
                return @mysql_field_len($res, $field);
349 1a2be799 Florent Chuffart
        } /* }}} */
350 1a2be799 Florent Chuffart
351 1a2be799 Florent Chuffart
        function sql_insert_id() /* {{{ */
352 1a2be799 Florent Chuffart
        {
353 1a2be799 Florent Chuffart
                return mysql_insert_id($this->dbh);
354 1a2be799 Florent Chuffart
        } /* }}} */
355 1a2be799 Florent Chuffart
356 1a2be799 Florent Chuffart
        function sql_limit($start, $more) /* {{{ */
357 1a2be799 Florent Chuffart
        {
358 1a2be799 Florent Chuffart
                return ' LIMIT '.$start.', '.$more.' ';
359 1a2be799 Florent Chuffart
        } /* }}} */
360 1a2be799 Florent Chuffart
361 1a2be799 Florent Chuffart
        function sql_delimiter() /* {{{ */
362 1a2be799 Florent Chuffart
        {
363 1a2be799 Florent Chuffart
                $this->sd = '`'; $this->ed='`';
364 1a2be799 Florent Chuffart
                return $this->sd;
365 1a2be799 Florent Chuffart
        } /* }}} */
366 1a2be799 Florent Chuffart
367 1a2be799 Florent Chuffart
368 1a2be799 Florent Chuffart
        function myquery($qry, $line = 0, $debug = 0) /* {{{ */
369 1a2be799 Florent Chuffart
        {
370 1a2be799 Florent Chuffart
                global $debug_query;
371 1a2be799 Florent Chuffart
                if ($debug_query || $debug) {
372 1a2be799 Florent Chuffart
                        $line = intval($line);
373 1a2be799 Florent Chuffart
                        echo '<h4>MySQL query at line ',$line,'</h4>',htmlspecialchars($qry),'<hr size="1" />',"\n";
374 1a2be799 Florent Chuffart
                }
375 1a2be799 Florent Chuffart
                if (isset($this->db)) {
376 1a2be799 Florent Chuffart
                        $ret = @mysql_db_query($this->db, $qry, $this->dbh);
377 1a2be799 Florent Chuffart
                } else {
378 1a2be799 Florent Chuffart
                        $ret = @mysql_query($qry, $this->dbh);
379 1a2be799 Florent Chuffart
                }
380 1a2be799 Florent Chuffart
                if (! $ret) {
381 1a2be799 Florent Chuffart
                        echo '<h4>MySQL error ',mysql_errno($this->dbh),'</h4>';
382 1a2be799 Florent Chuffart
                        echo htmlspecialchars(mysql_error($this->dbh)),'<hr size="1" />',"\n";
383 1a2be799 Florent Chuffart
                }
384 1a2be799 Florent Chuffart
                return $ret;
385 1a2be799 Florent Chuffart
        } /* }}} */
386 1a2be799 Florent Chuffart
387 1a2be799 Florent Chuffart
        /* end of sql functions */ 
388 1a2be799 Florent Chuffart
389 1a2be799 Florent Chuffart
        function make_language_labels($language) /* {{{ */
390 1a2be799 Florent Chuffart
        {
391 1a2be799 Florent Chuffart
                // just try the first language and variant
392 1a2be799 Florent Chuffart
                // this isn't content-negotiation rfc compliant
393 1a2be799 Florent Chuffart
                $language = strtoupper($language);
394 1a2be799 Florent Chuffart
395 1a2be799 Florent Chuffart
                // try the full language w/ variant
396 1a2be799 Florent Chuffart
                $file = $this->dir['lang'].'PME.lang.'.$language.'.inc';
397 1a2be799 Florent Chuffart
                while (! file_exists($file)) {
398 1a2be799 Florent Chuffart
                        $pos = strrpos($language, '-');
399 1a2be799 Florent Chuffart
                        if ($pos === false) {
400 1a2be799 Florent Chuffart
                                $file = $this->dir['lang'].'PME.lang.EN.inc';
401 1a2be799 Florent Chuffart
                                break;
402 1a2be799 Florent Chuffart
                        }
403 1a2be799 Florent Chuffart
                        $language = substr($language, 0, $pos);
404 1a2be799 Florent Chuffart
                        $file = $this->dir['lang'].'PME.lang.'.$language.'.inc';
405 1a2be799 Florent Chuffart
                }
406 1a2be799 Florent Chuffart
                $ret = @include($file);
407 1a2be799 Florent Chuffart
                if (! is_array($ret)) {
408 1a2be799 Florent Chuffart
                        return $ret;
409 1a2be799 Florent Chuffart
                }
410 1a2be799 Florent Chuffart
                $small = array(
411 1a2be799 Florent Chuffart
                                'Search' => 'v',
412 1a2be799 Florent Chuffart
                                'Hide'   => '^',
413 1a2be799 Florent Chuffart
                                'Clear'  => 'X',
414 1a2be799 Florent Chuffart
                                'Query'  => htmlspecialchars('>'));
415 1a2be799 Florent Chuffart
                if ((!$this->nav_text_links() && !$this->nav_graphic_links())
416 1a2be799 Florent Chuffart
                                || !isset($ret['Search']) || !isset($ret['Query'])
417 1a2be799 Florent Chuffart
                                || !isset($ret['Hide'])   || !isset($ret['Clear'])) {
418 1a2be799 Florent Chuffart
                        foreach ($small as $key => $val) {
419 1a2be799 Florent Chuffart
                                $ret[$key] = $val;
420 1a2be799 Florent Chuffart
                        }
421 1a2be799 Florent Chuffart
                }
422 1a2be799 Florent Chuffart
                return $ret;
423 1a2be799 Florent Chuffart
        } /* }}} */
424 1a2be799 Florent Chuffart
425 1a2be799 Florent Chuffart
        function set_values($field_num, $prepend = null, $append = null, $strict = false) /* {{{ */
426 1a2be799 Florent Chuffart
        {
427 1a2be799 Florent Chuffart
                return (array) $prepend + (array) $this->fdd[$field_num]['values2']
428 1a2be799 Florent Chuffart
                        + (isset($this->fdd[$field_num]['values']['table']) || $strict
429 1a2be799 Florent Chuffart
                                        ? $this->set_values_from_table($field_num, $strict)
430 1a2be799 Florent Chuffart
                                        : array())
431 1a2be799 Florent Chuffart
                        + (array) $append;
432 1a2be799 Florent Chuffart
        } /* }}} */
433 1a2be799 Florent Chuffart
434 1a2be799 Florent Chuffart
        function set_values_from_table($field_num, $strict = false) /* {{{ */
435 1a2be799 Florent Chuffart
        {
436 1a2be799 Florent Chuffart
                $db    = &$this->fdd[$field_num]['values']['db'];
437 1a2be799 Florent Chuffart
                $table = $this->sd.$this->fdd[$field_num]['values']['table'].$this->ed;
438 1a2be799 Florent Chuffart
                $key   = &$this->fdd[$field_num]['values']['column'];
439 1a2be799 Florent Chuffart
                $desc  = &$this->fdd[$field_num]['values']['description'];
440 1a2be799 Florent Chuffart
                $dbp   = isset($db) ? $this->sd.$db.$this->ed.'.' : $this->dbp;
441 1a2be799 Florent Chuffart
                $qparts['type'] = 'select';
442 1a2be799 Florent Chuffart
                if ($table != $this->sd.$this->ed) {
443 1a2be799 Florent Chuffart
                        $qparts['select'] = 'DISTINCT '.$table.'.'.$this->sd.$key.$this->ed;
444 1a2be799 Florent Chuffart
                        if ($desc && is_array($desc) && is_array($desc['columns'])) {
445 1a2be799 Florent Chuffart
                                $qparts['select'] .= ',CONCAT('; // )
446 1a2be799 Florent Chuffart
                                $num_cols = sizeof($desc['columns']);
447 1a2be799 Florent Chuffart
                                if (isset($desc['divs'][-1])) {
448 1a2be799 Florent Chuffart
                                        $qparts['select'] .= '"'.addslashes($desc['divs'][-1]).'",';
449 1a2be799 Florent Chuffart
                                }
450 1a2be799 Florent Chuffart
                                foreach ($desc['columns'] as $key => $val) {
451 1a2be799 Florent Chuffart
                                        if ($val) {
452 1a2be799 Florent Chuffart
                                                $qparts['select'] .= 'IFNULL(CAST('.$this->sd.$val.$this->ed.' AS CHAR),"")';
453 1a2be799 Florent Chuffart
                                                if ($desc['divs'][$key]) {
454 1a2be799 Florent Chuffart
                                                        $qparts['select'] .= ',"'.addslashes($desc['divs'][$key]).'"';
455 1a2be799 Florent Chuffart
                                                }
456 1a2be799 Florent Chuffart
                                                $qparts['select'] .= ',';
457 1a2be799 Florent Chuffart
                                        }
458 1a2be799 Florent Chuffart
                                }
459 1a2be799 Florent Chuffart
                                $qparts['select']{strlen($qparts['select']) - 1} = ')';
460 1a2be799 Florent Chuffart
                                $qparts['select'] .= ' AS '.$this->sd.'PMEalias'.$field_num.$this->ed;
461 1a2be799 Florent Chuffart
                                $qparts['orderby'] = $this->sd.'PMEalias'.$field_num.$this->ed;
462 1a2be799 Florent Chuffart
                        } else if ($desc && is_array($desc)) {
463 1a2be799 Florent Chuffart
                                // TODO
464 1a2be799 Florent Chuffart
                        } else if ($desc) {
465 1a2be799 Florent Chuffart
                                $qparts['select'] .= ','.$table.'.'.$this->sd.$desc.$this->ed;
466 1a2be799 Florent Chuffart
                                $qparts['orderby'] = $this->sd.$desc.$this->ed;
467 1a2be799 Florent Chuffart
                        } else if ($key) {
468 1a2be799 Florent Chuffart
                                $qparts['orderby'] = $this->sd.$key.$this->ed;
469 1a2be799 Florent Chuffart
                        }
470 1a2be799 Florent Chuffart
                        $qparts['from'] = $dbp.$table;
471 1a2be799 Florent Chuffart
                        $ar = array(
472 1a2be799 Florent Chuffart
                                        'table'       => $table,
473 1a2be799 Florent Chuffart
                                        'column'      => $column,
474 1a2be799 Florent Chuffart
                                        'description' => $desc);
475 1a2be799 Florent Chuffart
                        $qparts['where'] = $this->substituteVars($this->fdd[$field_num]['values']['filters'], $ar);
476 1a2be799 Florent Chuffart
                        if ($this->fdd[$field_num]['values']['orderby']) {
477 1a2be799 Florent Chuffart
                                $qparts['orderby'] = $this->substituteVars($this->fdd[$field_num]['values']['orderby'], $ar);
478 1a2be799 Florent Chuffart
                        }
479 1a2be799 Florent Chuffart
                } else { /* simple value extraction */
480 1a2be799 Florent Chuffart
                        $key = &$this->fds[$field_num];
481 1a2be799 Florent Chuffart
                        $this->virtual($field_num) && $key = $this->fqn($field_num);
482 1a2be799 Florent Chuffart
                        $qparts['select']  = 'DISTINCT '.$this->sd.$key.$this->ed.' AS PMEkey';
483 1a2be799 Florent Chuffart
                        $qparts['orderby'] = 'PMEkey';
484 1a2be799 Florent Chuffart
                        $qparts['from']    = $this->dbp.$this->sd.$this->tb.$this->ed;
485 1a2be799 Florent Chuffart
                }
486 1a2be799 Florent Chuffart
                $values = array();
487 1a2be799 Florent Chuffart
                $res    = $this->myquery($this->get_SQL_query($qparts), __LINE__);
488 1a2be799 Florent Chuffart
                while ($row = $this->sql_fetch($res, 'n')) {
489 1a2be799 Florent Chuffart
                        $values[$row[0]] = $desc ? $row[1] : $row[0];
490 1a2be799 Florent Chuffart
                }
491 1a2be799 Florent Chuffart
                return $values;
492 1a2be799 Florent Chuffart
        } /* }}} */
493 1a2be799 Florent Chuffart
494 1a2be799 Florent Chuffart
        function fqn($field, $dont_desc = false, $dont_cols = false) /* {{{ */
495 1a2be799 Florent Chuffart
        {
496 1a2be799 Florent Chuffart
                is_numeric($field) || $field = array_search($field, $this->fds);
497 1a2be799 Florent Chuffart
                // if read SQL expression exists use it
498 1a2be799 Florent Chuffart
                if ($this->col_has_sql($field) && !$this->col_has_values($field))
499 1a2be799 Florent Chuffart
                        return $this->fdd[$field]['sql'];
500 1a2be799 Florent Chuffart
                // on copy/change always use simple key retrieving
501 1a2be799 Florent Chuffart
                if ($this->add_operation()
502 1a2be799 Florent Chuffart
                                || $this->copy_operation()
503 1a2be799 Florent Chuffart
                                || $this->change_operation()) {
504 1a2be799 Florent Chuffart
                                $ret = $this->sd.'PMEtable0'.$this->ed.'.'.$this->sd.$this->fds[$field].$this->ed;
505 1a2be799 Florent Chuffart
                } else {
506 1a2be799 Florent Chuffart
                        if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) {
507 1a2be799 Florent Chuffart
                                $desc = &$this->fdd[$this->fds[$field]]['values']['description'];
508 1a2be799 Florent Chuffart
                                if (is_array($desc) && is_array($desc['columns'])) {
509 1a2be799 Florent Chuffart
                                        $ret      = 'CONCAT('; // )
510 1a2be799 Florent Chuffart
                                        $num_cols = sizeof($desc['columns']);
511 1a2be799 Florent Chuffart
                                        if (isset($desc['divs'][-1])) {
512 1a2be799 Florent Chuffart
                                                $ret .= '"'.addslashes($desc['divs'][-1]).'",';
513 1a2be799 Florent Chuffart
                                        }
514 1a2be799 Florent Chuffart
                                        foreach ($desc['columns'] as $key => $val) {
515 1a2be799 Florent Chuffart
                                                if ($val) {
516 1a2be799 Florent Chuffart
                                                        $ret .= 'IFNULL(CAST('.$this->sd.'PMEjoin'.$field.$this->ed.'.'.$this->sd.$val.$this->ed.' AS CHAR),"")';
517 1a2be799 Florent Chuffart
                                                        if ($desc['divs'][$key]) {
518 1a2be799 Florent Chuffart
                                                                $ret .= ',"'.addslashes($desc['divs'][$key]).'"';
519 1a2be799 Florent Chuffart
                                                        }
520 1a2be799 Florent Chuffart
                                                        $ret .= ',';
521 1a2be799 Florent Chuffart
                                                }
522 1a2be799 Florent Chuffart
                                        }
523 1a2be799 Florent Chuffart
                                        $ret{strlen($ret) - 1} = ')';
524 1a2be799 Florent Chuffart
                                } else if (is_array($desc)) {
525 1a2be799 Florent Chuffart
                                        // TODO
526 1a2be799 Florent Chuffart
                                } else {
527 1a2be799 Florent Chuffart
                                        $ret = $this->sd.'PMEjoin'.$field.$this->ed.'.'.$this->sd.$this->fdd[$this->fds[$field]]['values']['description'].$this->ed;
528 1a2be799 Florent Chuffart
                                }
529 1a2be799 Florent Chuffart
                        // TODO: remove me
530 1a2be799 Florent Chuffart
                        } elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) {
531 1a2be799 Florent Chuffart
                                $ret = $this->sd.'PMEjoin'.$field.$this->ed.'.'.$this->fdd[$this->fds[$field]]['values']['column'];
532 1a2be799 Florent Chuffart
                        } else {
533 1a2be799 Florent Chuffart
                                $ret = $this->sd.'PMEtable0'.$this->ed.'.'.$this->sd.$this->fds[$field].$this->ed;
534 1a2be799 Florent Chuffart
                        }
535 1a2be799 Florent Chuffart
                        // TODO: not neccessary, remove me!
536 1a2be799 Florent Chuffart
                        if (is_array($this->fdd[$this->fds[$field]]['values2'])) {
537 1a2be799 Florent Chuffart
                        }
538 1a2be799 Florent Chuffart
                }
539 1a2be799 Florent Chuffart
                return $ret;
540 1a2be799 Florent Chuffart
        } /* }}} */
541 1a2be799 Florent Chuffart
542 1a2be799 Florent Chuffart
        function get_SQL_main_list_query($qparts) /* {{{ */
543 1a2be799 Florent Chuffart
        {
544 1a2be799 Florent Chuffart
                 return $this->get_SQL_query($qparts);
545 1a2be799 Florent Chuffart
         } /* }}} */
546 1a2be799 Florent Chuffart
 
547 1a2be799 Florent Chuffart
548 1a2be799 Florent Chuffart
549 1a2be799 Florent Chuffart
        function get_SQL_query($parts) /* {{{ */
550 1a2be799 Florent Chuffart
        {
551 1a2be799 Florent Chuffart
                foreach ($parts as $k => $v) {
552 1a2be799 Florent Chuffart
                        $parts[$k] = trim($parts[$k]);
553 1a2be799 Florent Chuffart
                }
554 1a2be799 Florent Chuffart
                switch ($parts['type']) {
555 1a2be799 Florent Chuffart
                        case 'select':
556 1a2be799 Florent Chuffart
                                $ret  = 'SELECT ';
557 1a2be799 Florent Chuffart
                                if ($parts['DISTINCT'])
558 1a2be799 Florent Chuffart
                                        $ret .= 'DISTINCT ';
559 1a2be799 Florent Chuffart
                                $ret .= $parts['select'];
560 1a2be799 Florent Chuffart
                                $ret .= ' FROM '.$parts['from'];
561 1a2be799 Florent Chuffart
                                if ($parts['where'] != '')
562 1a2be799 Florent Chuffart
                                        $ret .= ' WHERE '.$parts['where'];
563 1a2be799 Florent Chuffart
                                if ($parts['groupby'] != '')
564 1a2be799 Florent Chuffart
                                        $ret .= ' GROUP BY '.$parts['groupby'];
565 1a2be799 Florent Chuffart
                                if ($parts['having'] != '')
566 1a2be799 Florent Chuffart
                                        $ret .= ' HAVING '.$parts['having'];
567 1a2be799 Florent Chuffart
                                if ($parts['orderby'] != '')
568 1a2be799 Florent Chuffart
                                        $ret .= ' ORDER BY '.$parts['orderby'];
569 1a2be799 Florent Chuffart
                                if ($parts['limit'] != '')
570 1a2be799 Florent Chuffart
                                        $ret .= ' '.$parts['limit'];
571 1a2be799 Florent Chuffart
                                if ($parts['procedure'] != '')
572 1a2be799 Florent Chuffart
                                        $ret .= ' PROCEDURE '.$parts['procedure'];
573 1a2be799 Florent Chuffart
                                break;
574 1a2be799 Florent Chuffart
                        case 'update':
575 1a2be799 Florent Chuffart
                                $ret  = 'UPDATE '.$parts['table'];
576 1a2be799 Florent Chuffart
                                $ret .= ' SET '.$parts['fields'];
577 1a2be799 Florent Chuffart
                                if ($parts['where'] != '')
578 1a2be799 Florent Chuffart
                                        $ret .= ' WHERE '.$parts['where'];
579 1a2be799 Florent Chuffart
                                break;
580 1a2be799 Florent Chuffart
                        case 'insert':
581 1a2be799 Florent Chuffart
                                $ret  = 'INSERT INTO '.$parts['table'];
582 1a2be799 Florent Chuffart
                                $ret .= ' VALUES '.$parts['values'];
583 1a2be799 Florent Chuffart
                                break;
584 1a2be799 Florent Chuffart
                        case 'delete':
585 1a2be799 Florent Chuffart
                                $ret  = 'DELETE FROM '.$parts['table'];
586 1a2be799 Florent Chuffart
                                if ($parts['where'] != '')
587 1a2be799 Florent Chuffart
                                        $ret .= ' WHERE '.$parts['where'];
588 1a2be799 Florent Chuffart
                                break;
589 1a2be799 Florent Chuffart
                        default:
590 1a2be799 Florent Chuffart
                                die('unknown query type');
591 1a2be799 Florent Chuffart
                                break;
592 1a2be799 Florent Chuffart
                }
593 1a2be799 Florent Chuffart
                return $ret;
594 1a2be799 Florent Chuffart
        } /* }}} */
595 1a2be799 Florent Chuffart
596 1a2be799 Florent Chuffart
        function get_SQL_column_list() /* {{{ */
597 1a2be799 Florent Chuffart
        {
598 1a2be799 Florent Chuffart
                $fields = array();
599 1a2be799 Florent Chuffart
                for ($k = 0; $k < $this->num_fds; $k++) {
600 1a2be799 Florent Chuffart
                        if (! $this->displayed[$k] && $k != $this->key_num) {
601 1a2be799 Florent Chuffart
                                continue;
602 1a2be799 Florent Chuffart
                        }
603 1a2be799 Florent Chuffart
                        $fields[] = $this->fqn($k).' AS '.$this->sd.'qf'.$k.$this->ed; // no delimiters here, or maybe some yes
604 1a2be799 Florent Chuffart
                        if ($this->col_has_values($k)) {
605 1a2be799 Florent Chuffart
                                if($this->col_has_sql($k)) $fields[] = $this->fdd[$k]['sql'].' AS '.$this->sd.'qf'.$k.'_idx'.$this->ed;
606 1a2be799 Florent Chuffart
                                else $fields[] = $this->fqn($k, true, true).' AS '.$this->sd.'qf'.$k.'_idx'.$this->ed;
607 1a2be799 Florent Chuffart
                        }
608 1a2be799 Florent Chuffart
                        if ($this->col_has_datemask($k)) {
609 1a2be799 Florent Chuffart
                                $fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS '.$this->sd.'qf'.$k.'_timestamp'.$this->ed;
610 1a2be799 Florent Chuffart
                        }
611 1a2be799 Florent Chuffart
                }
612 1a2be799 Florent Chuffart
                return join(',', $fields);
613 1a2be799 Florent Chuffart
        } /* }}} */
614 1a2be799 Florent Chuffart
615 1a2be799 Florent Chuffart
        function get_SQL_join_clause() /* {{{ */
616 1a2be799 Florent Chuffart
        {
617 1a2be799 Florent Chuffart
                $main_table  = $this->sd.'PMEtable0'.$this->ed;
618 1a2be799 Florent Chuffart
                $join_clause = $this->sd.$this->tb.$this->ed." AS $main_table";
619 1a2be799 Florent Chuffart
                for ($k = 0, $numfds = sizeof($this->fds); $k < $numfds; $k++) {
620 1a2be799 Florent Chuffart
                        $main_column = $this->fds[$k];
621 1a2be799 Florent Chuffart
                        if($this->fdd[$main_column]['values']['db']) {
622 1a2be799 Florent Chuffart
                                $dbp = $this->sd.$this->fdd[$main_column]['values']['db'].$this->ed.'.';
623 1a2be799 Florent Chuffart
                        } else {
624 1a2be799 Florent Chuffart
                                //$dbp = $this->dbp;
625 1a2be799 Florent Chuffart
                        }
626 1a2be799 Florent Chuffart
                        $table       = $this->sd.$this->fdd[$main_column]['values']['table'].$this->ed;
627 1a2be799 Florent Chuffart
                        $join_column = $this->sd.$this->fdd[$main_column]['values']['column'].$this->ed;
628 1a2be799 Florent Chuffart
                        $join_desc   = $this->sd.$this->fdd[$main_column]['values']['description'].$this->ed;
629 1a2be799 Florent Chuffart
                        if ($join_desc != $this->sd.$this->ed && $join_column != $this->sd.$this->ed) {
630 1a2be799 Florent Chuffart
                                $join_table = $this->sd.'PMEjoin'.$k.$this->ed;
631 1a2be799 Florent Chuffart
                                $ar = array(
632 1a2be799 Florent Chuffart
                                                'main_table'       => $main_table,
633 1a2be799 Florent Chuffart
                                                'main_column'      => $this->sd.$main_column.$this->ed,
634 1a2be799 Florent Chuffart
                                                'join_table'       => $join_table,
635 1a2be799 Florent Chuffart
                                                'join_column'      => $join_column,
636 1a2be799 Florent Chuffart
                                                'join_description' => $join_desc);
637 1a2be799 Florent Chuffart
                                $join_clause .= " LEFT OUTER JOIN $dbp".$table." AS $join_table ON (";
638 1a2be799 Florent Chuffart
                                $join_clause .= isset($this->fdd[$main_column]['values']['join'])
639 1a2be799 Florent Chuffart
                                        ? $this->substituteVars($this->fdd[$main_column]['values']['join'], $ar)
640 1a2be799 Florent Chuffart
                                        : "$join_table.$join_column = $main_table.".$this->sd.$main_column.$this->ed;
641 1a2be799 Florent Chuffart
                                $join_clause .= ')';
642 1a2be799 Florent Chuffart
                        }
643 1a2be799 Florent Chuffart
                }
644 1a2be799 Florent Chuffart
                return $join_clause;
645 1a2be799 Florent Chuffart
        } /* }}} */
646 1a2be799 Florent Chuffart
647 1a2be799 Florent Chuffart
        function get_SQL_where_from_query_opts($qp = null, $text = 0) /* {{{ */
648 1a2be799 Florent Chuffart
        {
649 1a2be799 Florent Chuffart
                if ($qp == null) {
650 1a2be799 Florent Chuffart
                        $qp = $this->query_opts;
651 1a2be799 Florent Chuffart
                }
652 1a2be799 Florent Chuffart
                $where = array();
653 1a2be799 Florent Chuffart
                foreach ($qp as $field => $ov) {
654 1a2be799 Florent Chuffart
                        if (is_numeric($field)) {
655 1a2be799 Florent Chuffart
                                $tmp_where = array();
656 1a2be799 Florent Chuffart
                                foreach ($ov as $field2 => $ov2) {
657 1a2be799 Florent Chuffart
                                        $tmp_where[] = sprintf('%s %s %s', $field2, $ov2['oper'], $ov2['value']);
658 1a2be799 Florent Chuffart
                                }
659 1a2be799 Florent Chuffart
                                $where[] = '('.join(' OR ', $tmp_where).')';
660 1a2be799 Florent Chuffart
                        } else {
661 1a2be799 Florent Chuffart
                                if (is_array($ov['value'])) {
662 1a2be799 Florent Chuffart
                                        $tmp_ov_val = '';
663 1a2be799 Florent Chuffart
                                        foreach ($ov['value'] as $ov_val) {
664 1a2be799 Florent Chuffart
                                                strlen($tmp_ov_val) > 0 && $tmp_ov_val .= ' OR ';
665 1a2be799 Florent Chuffart
                                                $tmp_ov_val .= sprintf('FIND_IN_SET("%s",%s)', $ov_val, $field);
666 1a2be799 Florent Chuffart
                                        }
667 1a2be799 Florent Chuffart
                                        $where[] = "($tmp_ov_val)";
668 1a2be799 Florent Chuffart
                                } else {
669 1a2be799 Florent Chuffart
                                        $where[] = sprintf('%s %s %s', $field, $ov['oper'], $ov['value']);
670 1a2be799 Florent Chuffart
                                }
671 1a2be799 Florent Chuffart
                        }
672 1a2be799 Florent Chuffart
                }
673 1a2be799 Florent Chuffart
                // Add any coder specified filters
674 1a2be799 Florent Chuffart
                if (! $text && $this->filters) {
675 1a2be799 Florent Chuffart
                        $where[] = '('.$this->filters.')';
676 1a2be799 Florent Chuffart
                }
677 1a2be799 Florent Chuffart
                if (count($where) > 0) {
678 1a2be799 Florent Chuffart
                        if ($text) {
679 1a2be799 Florent Chuffart
                                return str_replace('%', '*', join(' AND ',$where));
680 1a2be799 Florent Chuffart
                        } else {
681 1a2be799 Florent Chuffart
                                return join(' AND ',$where);
682 1a2be799 Florent Chuffart
                        }
683 1a2be799 Florent Chuffart
                }
684 1a2be799 Florent Chuffart
                return ''; /* empty string */
685 1a2be799 Florent Chuffart
        } /* }}} */
686 1a2be799 Florent Chuffart
687 1a2be799 Florent Chuffart
        function gather_query_opts() /* {{{ */
688 1a2be799 Florent Chuffart
        {
689 1a2be799 Florent Chuffart
                $this->query_opts = array();
690 1a2be799 Florent Chuffart
                $this->prev_qfn   = $this->qfn;
691 1a2be799 Florent Chuffart
                $this->qfn        = '';
692 1a2be799 Florent Chuffart
                if ($this->clear_operation()) {
693 1a2be799 Florent Chuffart
                        return;
694 1a2be799 Florent Chuffart
                }
695 1a2be799 Florent Chuffart
                // gathers query options into an array, $this->query_opts
696 1a2be799 Florent Chuffart
                $qo = array();
697 1a2be799 Florent Chuffart
                for ($k = 0; $k < $this->num_fds; $k++) {
698 1a2be799 Florent Chuffart
                        $l    = 'qf'.$k;
699 1a2be799 Florent Chuffart
                        $lc   = 'qf'.$k.'_comp';
700 1a2be799 Florent Chuffart
                        $li   = 'qf'.$k.'_id';
701 1a2be799 Florent Chuffart
                        $m    = $this->get_sys_cgi_var($l);
702 1a2be799 Florent Chuffart
                        $mc   = $this->get_sys_cgi_var($lc);
703 1a2be799 Florent Chuffart
                        $mi   = $this->get_sys_cgi_var($li);
704 1a2be799 Florent Chuffart
                        if (! isset($m) && ! isset($mi)) {
705 1a2be799 Florent Chuffart
                                continue;
706 1a2be799 Florent Chuffart
                        }
707 1a2be799 Florent Chuffart
                        if (is_array($m) || is_array($mi)) {
708 1a2be799 Florent Chuffart
                                if (is_array($mi)) {
709 1a2be799 Florent Chuffart
                                        $m = $mi;
710 1a2be799 Florent Chuffart
                                        $l = $li;
711 1a2be799 Florent Chuffart
                                }
712 1a2be799 Florent Chuffart
                                if (in_array('*', $m)) {
713 1a2be799 Florent Chuffart
                                        continue;
714 1a2be799 Florent Chuffart
                                }
715 1a2be799 Florent Chuffart
                                if ($this->col_has_values($k) && $this->col_has_multiple($k)) {
716 1a2be799 Florent Chuffart
                                        foreach (array_keys($m) as $key) {
717 1a2be799 Florent Chuffart
                                                $m[$key] = addslashes($m[$key]);
718 1a2be799 Florent Chuffart
                                        }
719 1a2be799 Florent Chuffart
                                        $qo[$this->fqn($k)] = array('value' => $m);
720 1a2be799 Florent Chuffart
                                } else {
721 1a2be799 Florent Chuffart
                                        $qf_op = '';
722 1a2be799 Florent Chuffart
                                        foreach (array_keys($m) as $key) {
723 1a2be799 Florent Chuffart
                                                if ($qf_op == '') {
724 1a2be799 Florent Chuffart
                                                        $qf_op   = 'IN';
725 1a2be799 Florent Chuffart
                                                        $qf_val  = '"'.addslashes($m[$key]).'"';
726 1a2be799 Florent Chuffart
                                                        $afilter = ' IN ("'.addslashes($m[$key]).'"'; // )
727 1a2be799 Florent Chuffart
                                                } else {
728 1a2be799 Florent Chuffart
                                                        $afilter = $afilter.',"'.addslashes($m[$key]).'"';
729 1a2be799 Florent Chuffart
                                                        $qf_val .= ',"'.addslashes($m[$key]).'"';
730 1a2be799 Florent Chuffart
                                                }
731 1a2be799 Florent Chuffart
                                                $this->qfn .= '&'.$this->cgi['prefix']['sys'].$l.'['.rawurlencode($key).']='.rawurlencode($m[$key]);
732 1a2be799 Florent Chuffart
                                        }
733 1a2be799 Florent Chuffart
                                        $afilter = $afilter.')';
734 1a2be799 Florent Chuffart
                                        // XXX: $dont_desc and $dont_cols hack
735 1a2be799 Florent Chuffart
                                        $dont_desc = isset($this->fdd[$k]['values']['description']);
736 1a2be799 Florent Chuffart
                                        $dont_cols = isset($this->fdd[$k]['values']['column']);
737 1a2be799 Florent Chuffart
                                        $qo[$this->fqn($k, $dont_desc, $dont_cols)] =
738 1a2be799 Florent Chuffart
                                                array('oper'  => $qf_op, 'value' => "($qf_val)"); // )
739 1a2be799 Florent Chuffart
                                }
740 1a2be799 Florent Chuffart
                        } else if (isset($mi)) {
741 1a2be799 Florent Chuffart
                                if ($mi == '*') {
742 1a2be799 Florent Chuffart
                                        continue;
743 1a2be799 Florent Chuffart
                                }
744 1a2be799 Florent Chuffart
                                if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $mi == '') {
745 1a2be799 Florent Chuffart
                                        continue;
746 1a2be799 Florent Chuffart
                                }
747 1a2be799 Florent Chuffart
                                $afilter = addslashes($mi);
748 1a2be799 Florent Chuffart
                                $qo[$this->fqn($k, true, true)] = array('oper'  => '=', 'value' => "'$afilter'");
749 1a2be799 Florent Chuffart
                                $this->qfn .= '&'.$this->cgi['prefix']['sys'].$li.'='.rawurlencode($mi);
750 1a2be799 Florent Chuffart
                        } else if (isset($m)) {
751 1a2be799 Florent Chuffart
                                if ($m == '*') {
752 1a2be799 Florent Chuffart
                                        continue;
753 1a2be799 Florent Chuffart
                                }
754 1a2be799 Florent Chuffart
                                if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $m == '') {
755 1a2be799 Florent Chuffart
                                        continue;
756 1a2be799 Florent Chuffart
                                }
757 1a2be799 Florent Chuffart
                                $afilter = addslashes($m);
758 1a2be799 Florent Chuffart
                                if ($this->fdd[$k]['select'] == 'N') {
759 1a2be799 Florent Chuffart
                                        $mc = in_array($mc, $this->comp_ops) ? $mc : '=';
760 1a2be799 Florent Chuffart
                                        $qo[$this->fqn($k)] = array('oper' => $mc, 'value' => "'$afilter'");
761 1a2be799 Florent Chuffart
                                        $this->qfn .= '&'.$this->cgi['prefix']['sys'].$l .'='.rawurlencode($m);
762 1a2be799 Florent Chuffart
                                        $this->qfn .= '&'.$this->cgi['prefix']['sys'].$lc.'='.rawurlencode($mc);
763 1a2be799 Florent Chuffart
                                } else {
764 1a2be799 Florent Chuffart
                                        $afilter = '%'.str_replace('*', '%', $afilter).'%';
765 1a2be799 Florent Chuffart
                                        $ids  = array();
766 1a2be799 Florent Chuffart
                                        $ar   = array();
767 1a2be799 Florent Chuffart
                                        $ar[$this->fqn($k)] = array('oper' => 'LIKE', 'value' => "'$afilter'");
768 1a2be799 Florent Chuffart
                                        if (is_array($this->fdd[$k]['values2'])) {
769 1a2be799 Florent Chuffart
                                                foreach ($this->fdd[$k]['values2'] as $key => $val) {
770 1a2be799 Florent Chuffart
                                                        if (strlen($m) > 0 && stristr($val, $m)) {
771 1a2be799 Florent Chuffart
                                                                $ids[] = '"'.addslashes($key).'"';
772 1a2be799 Florent Chuffart
                                                        }
773 1a2be799 Florent Chuffart
                                                }
774 1a2be799 Florent Chuffart
                                                if (count($ids) > 0) {
775 1a2be799 Florent Chuffart
                                                        $ar[$this->fqn($k, true, true)]
776 1a2be799 Florent Chuffart
                                                                = array('oper'  => 'IN', 'value' => '('.join(',', $ids).')');
777 1a2be799 Florent Chuffart
                                                }
778 1a2be799 Florent Chuffart
                                        }
779 1a2be799 Florent Chuffart
                                        $qo[] = $ar;
780 1a2be799 Florent Chuffart
                                        $this->qfn .= '&'.$this->cgi['prefix']['sys'].$l.'='.rawurlencode($m);
781 1a2be799 Florent Chuffart
                                }
782 1a2be799 Florent Chuffart
                        }
783 1a2be799 Florent Chuffart
                }
784 1a2be799 Florent Chuffart
                $this->query_opts = $qo;
785 1a2be799 Florent Chuffart
        } /* }}} */
786 1a2be799 Florent Chuffart
787 1a2be799 Florent Chuffart
        /*
788 1a2be799 Florent Chuffart
         * Create JavaScripts
789 1a2be799 Florent Chuffart
         */
790 1a2be799 Florent Chuffart
791 1a2be799 Florent Chuffart
        function form_begin() /* {{{ */
792 1a2be799 Florent Chuffart
        {
793 1a2be799 Florent Chuffart
                $page_name = htmlspecialchars($this->page_name);
794 1a2be799 Florent Chuffart
                if ($this->add_operation() || $this->change_operation() || $this->copy_operation()
795 1a2be799 Florent Chuffart
                                || $this->view_operation() || $this->delete_operation()) {
796 1a2be799 Florent Chuffart
                        $field_to_tab = array();
797 1a2be799 Florent Chuffart
                        for ($tab = $k = $this->cur_tab = 0; $k < $this->num_fds; $k++) {
798 1a2be799 Florent Chuffart
                                if (isset($this->fdd[$k]['tab'])) {
799 1a2be799 Florent Chuffart
                                        if ($tab == 0 && $k > 0) {
800 1a2be799 Florent Chuffart
                                                $this->tabs[0] = 'PMEtab0';
801 1a2be799 Florent Chuffart
                                                $this->cur_tab = 1;
802 1a2be799 Florent Chuffart
                                                $tab++;
803 1a2be799 Florent Chuffart
                                        }
804 1a2be799 Florent Chuffart
                                        if (is_array($this->fdd[$k]['tab'])) {
805 1a2be799 Florent Chuffart
                                                $this->tabs[$tab] = @$this->fdd[$k]['tab']['name'];
806 1a2be799 Florent Chuffart
                                                $this->fdd[$k]['tab']['default'] && $this->cur_tab = $tab;
807 1a2be799 Florent Chuffart
                                        } else {
808 1a2be799 Florent Chuffart
                                                $this->tabs[$tab] = @$this->fdd[$k]['tab'];
809 1a2be799 Florent Chuffart
                                        }
810 1a2be799 Florent Chuffart
                                        $tab++;
811 1a2be799 Florent Chuffart
                                }
812 1a2be799 Florent Chuffart
                                $field_to_tab[$k] = max(0, $tab - 1);
813 1a2be799 Florent Chuffart
                        }
814 1a2be799 Florent Chuffart
                        if (preg_match('/^'.$this->dhtml['prefix'].'tab(\d+)$/', $this->get_sys_cgi_var('cur_tab'), $parts)) {
815 1a2be799 Florent Chuffart
                                $this->cur_tab = $parts[1];
816 1a2be799 Florent Chuffart
                        }
817 1a2be799 Florent Chuffart
                        if ($this->tabs_enabled()) {
818 1a2be799 Florent Chuffart
                                // initial TAB styles
819 1a2be799 Florent Chuffart
                                echo '<style type="text/css" media="screen">',"\n";
820 1a2be799 Florent Chuffart
                                for ($i = 0; $i < count($this->tabs); $i++) {
821 1a2be799 Florent Chuffart
                                        echo '        #'.$this->dhtml['prefix'].'tab',$i,' { display: ';
822 1a2be799 Florent Chuffart
                                        echo (($i == $this->cur_tab || $this->tabs[$i] == 'PMEtab0' ) ? 'block' : 'none') ,'; }',"\n";
823 1a2be799 Florent Chuffart
                                }
824 1a2be799 Florent Chuffart
                                echo '</style>',"\n";
825 1a2be799 Florent Chuffart
                                // TAB javascripts
826 1a2be799 Florent Chuffart
                                echo '<script type="text/javascript"><!--',"\n\n";
827 1a2be799 Florent Chuffart
                                $css_class_name1 = $this->getCSSclass('tab', $position);
828 1a2be799 Florent Chuffart
                                $css_class_name2 = $this->getCSSclass('tab-selected', $position);
829 1a2be799 Florent Chuffart
                                echo 'var '.$this->js['prefix'].'cur_tab  = "'.$this->dhtml['prefix'].'tab',$this->cur_tab,'";
830 1a2be799 Florent Chuffart

831 1a2be799 Florent Chuffart
function '.$this->js['prefix'].'show_tab(tab_name)
832 1a2be799 Florent Chuffart
{';
833 1a2be799 Florent Chuffart
                                if ($this->nav_up()) {
834 1a2be799 Florent Chuffart
                                        echo '
835 1a2be799 Florent Chuffart
        document.getElementById('.$this->js['prefix'].'cur_tab+"_up_label").className = "',$css_class_name1,'";
836 1a2be799 Florent Chuffart
        document.getElementById('.$this->js['prefix'].'cur_tab+"_up_link").className = "',$css_class_name1,'";
837 1a2be799 Florent Chuffart
        document.getElementById(tab_name+"_up_label").className = "',$css_class_name2,'";
838 1a2be799 Florent Chuffart
        document.getElementById(tab_name+"_up_link").className = "',$css_class_name2,'";';
839 1a2be799 Florent Chuffart
                                }
840 1a2be799 Florent Chuffart
                                if ($this->nav_down()) {
841 1a2be799 Florent Chuffart
                                        echo '
842 1a2be799 Florent Chuffart
        document.getElementById('.$this->js['prefix'].'cur_tab+"_down_label").className = "',$css_class_name1,'";
843 1a2be799 Florent Chuffart
        document.getElementById('.$this->js['prefix'].'cur_tab+"_down_link").className = "',$css_class_name1,'";
844 1a2be799 Florent Chuffart
        document.getElementById(tab_name+"_down_label").className = "',$css_class_name2,'";
845 1a2be799 Florent Chuffart
        document.getElementById(tab_name+"_down_link").className = "',$css_class_name2,'";';
846 1a2be799 Florent Chuffart
                                }
847 1a2be799 Florent Chuffart
                                echo '
848 1a2be799 Florent Chuffart
        document.getElementById('.$this->js['prefix'].'cur_tab).style.display = "none";
849 1a2be799 Florent Chuffart
        document.getElementById(tab_name).style.display = "block";
850 1a2be799 Florent Chuffart
        '.$this->js['prefix'].'cur_tab = tab_name;
851 1a2be799 Florent Chuffart
        document.'.$this->cgi['prefix']['sys'].'form.'.$this->cgi['prefix']['sys'].'cur_tab.value = tab_name;
852 1a2be799 Florent Chuffart
}',"\n\n";
853 1a2be799 Florent Chuffart
                                echo '// --></script>', "\n";
854 1a2be799 Florent Chuffart
                        }
855 1a2be799 Florent Chuffart
                }
856 1a2be799 Florent Chuffart
857 1a2be799 Florent Chuffart
                if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) {
858 1a2be799 Florent Chuffart
                        $first_required = true;
859 1a2be799 Florent Chuffart
                        for ($k = 0; $k < $this->num_fds; $k++) {
860 1a2be799 Florent Chuffart
                                if ($this->displayed[$k] && ! $this->readonly($k) && ! $this->hidden($k)
861 1a2be799 Florent Chuffart
                                                && ($this->fdd[$k]['js']['required'] || isset($this->fdd[$k]['js']['regexp']))) {
862 1a2be799 Florent Chuffart
                                        if ($first_required) {
863 1a2be799 Florent Chuffart
                                                 $first_required = false;
864 1a2be799 Florent Chuffart
                                                echo '<script type="text/javascript"><!--',"\n";
865 1a2be799 Florent Chuffart
                                                echo '
866 1a2be799 Florent Chuffart
function '.$this->js['prefix'].'trim(str)
867 1a2be799 Florent Chuffart
{
868 1a2be799 Florent Chuffart
        while (str.substring(0, 1) == " "
869 1a2be799 Florent Chuffart
                        || str.substring(0, 1) == "\\n"
870 1a2be799 Florent Chuffart
                        || str.substring(0, 1) == "\\r")
871 1a2be799 Florent Chuffart
        {
872 1a2be799 Florent Chuffart
                str = str.substring(1, str.length);
873 1a2be799 Florent Chuffart
        }
874 1a2be799 Florent Chuffart
        while (str.substring(str.length - 1, str.length) == " "
875 1a2be799 Florent Chuffart
                        || str.substring(str.length - 1, str.length) == "\\n"
876 1a2be799 Florent Chuffart
                        || str.substring(str.length - 1, str.length) == "\\r")
877 1a2be799 Florent Chuffart
        {
878 1a2be799 Florent Chuffart
                str = str.substring(0, str.length - 1);
879 1a2be799 Florent Chuffart
        }
880 1a2be799 Florent Chuffart
        return str;
881 1a2be799 Florent Chuffart
}
882 1a2be799 Florent Chuffart

883 1a2be799 Florent Chuffart
function '.$this->js['prefix'].'form_control(theForm)
884 1a2be799 Florent Chuffart
{',"\n";
885 1a2be799 Florent Chuffart
                                        }
886 1a2be799 Florent Chuffart
                                        if ($this->col_has_values($k)) {
887 1a2be799 Florent Chuffart
                                                $condition = 'theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.selectedIndex == -1';
888 1a2be799 Florent Chuffart
                                                $multiple  = $this->col_has_multiple_select($k);
889 1a2be799 Florent Chuffart
                                        } else {
890 1a2be799 Florent Chuffart
                                                $condition = '';
891 1a2be799 Florent Chuffart
                                                $multiple  = false;
892 1a2be799 Florent Chuffart
                                                if ($this->fdd[$k]['js']['required']) {
893 1a2be799 Florent Chuffart
                                                        $condition = $this->js['prefix'].'trim(theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.value) == ""';
894 1a2be799 Florent Chuffart
                                                }
895 1a2be799 Florent Chuffart
                                                if (isset($this->fdd[$k]['js']['regexp'])) {
896 1a2be799 Florent Chuffart
                                                        $condition .= (strlen($condition) > 0 ? ' || ' : '');
897 1a2be799 Florent Chuffart
                                                        $condition .= sprintf('!(%s.test('.$this->js['prefix'].'trim(theForm.%s.value)))',
898 1a2be799 Florent Chuffart
                                                                        $this->fdd[$k]['js']['regexp'], $this->cgi['prefix']['data'].$this->fds[$k]);
899 1a2be799 Florent Chuffart
                                                }
900 1a2be799 Florent Chuffart
                                        }
901 1a2be799 Florent Chuffart
902 1a2be799 Florent Chuffart
                                        /* Multiple selects have their name like ''name[]''.
903 1a2be799 Florent Chuffart
                                           It is not possible to work with them directly, because
904 1a2be799 Florent Chuffart
                                           theForm.name[].something will result into JavaScript
905 1a2be799 Florent Chuffart
                                           syntax error. Following search algorithm is provided
906 1a2be799 Florent Chuffart
                                           as a workaround for this.
907 1a2be799 Florent Chuffart
                                         */
908 1a2be799 Florent Chuffart
                                        if ($multiple) {
909 1a2be799 Florent Chuffart
                                                echo '
910 1a2be799 Florent Chuffart
        multiple_select = null;
911 1a2be799 Florent Chuffart
        for (i = 0; i < theForm.length; i++) {
912 1a2be799 Florent Chuffart
                if (theForm.elements[i].name == "',$this->cgi['prefix']['data'].$this->fds[$k],'[]") {
913 1a2be799 Florent Chuffart
                        multiple_select = theForm.elements[i];
914 1a2be799 Florent Chuffart
                        break;
915 1a2be799 Florent Chuffart
                }
916 1a2be799 Florent Chuffart
        }
917 1a2be799 Florent Chuffart
        if (multiple_select != null && multiple_select.selectedIndex == -1) {';
918 1a2be799 Florent Chuffart
                                        } else {
919 1a2be799 Florent Chuffart
                                                echo '
920 1a2be799 Florent Chuffart
        if (',$condition,') {';
921 1a2be799 Florent Chuffart
                                        }
922 1a2be799 Florent Chuffart
                                        echo '
923 1a2be799 Florent Chuffart
                alert("';
924 1a2be799 Florent Chuffart
                                        if (isset($this->fdd[$k]['js']['hint'])) {
925 1a2be799 Florent Chuffart
                                                echo htmlspecialchars($this->fdd[$k]['js']['hint']);
926 1a2be799 Florent Chuffart
                                        } else {
927 1a2be799 Florent Chuffart
                                                echo $this->labels['Please enter'],' ',$this->fdd[$k]['name'],'.';
928 1a2be799 Florent Chuffart
                                        }
929 1a2be799 Florent Chuffart
                                        echo '");';
930 1a2be799 Florent Chuffart
                                        if ($this->tabs_enabled() && $field_to_tab[$k] >= $this->cur_tab) {
931 1a2be799 Florent Chuffart
                                                echo '
932 1a2be799 Florent Chuffart
                '.$this->js['prefix'].'show_tab("'.$this->dhtml['prefix'].'tab',$field_to_tab[$k],'");';
933 1a2be799 Florent Chuffart
                                        }
934 1a2be799 Florent Chuffart
                                        echo '
935 1a2be799 Florent Chuffart
                theForm.',$this->cgi['prefix']['data'].$this->fds[$k],'.focus();
936 1a2be799 Florent Chuffart
                return false;
937 1a2be799 Florent Chuffart
        }',"\n";
938 1a2be799 Florent Chuffart
                                }
939 1a2be799 Florent Chuffart
                        }
940 1a2be799 Florent Chuffart
                        if (! $first_required) {
941 1a2be799 Florent Chuffart
                                echo '
942 1a2be799 Florent Chuffart
        return true;
943 1a2be799 Florent Chuffart
}',"\n\n";
944 1a2be799 Florent Chuffart
                                echo '// --></script>', "\n";
945 1a2be799 Florent Chuffart
                        }
946 1a2be799 Florent Chuffart
                }
947 1a2be799 Florent Chuffart
948 1a2be799 Florent Chuffart
                if ($this->filter_operation()) {
949 1a2be799 Florent Chuffart
                                echo '<script type="text/javascript"><!--',"\n";
950 1a2be799 Florent Chuffart
                                echo '
951 1a2be799 Florent Chuffart
function '.$this->js['prefix'].'filter_handler(theForm, theEvent)
952 1a2be799 Florent Chuffart
{
953 1a2be799 Florent Chuffart
        var pressed_key = null;
954 1a2be799 Florent Chuffart
        if (theEvent.which) {
955 1a2be799 Florent Chuffart
                pressed_key = theEvent.which;
956 1a2be799 Florent Chuffart
        } else {
957 1a2be799 Florent Chuffart
                pressed_key = theEvent.keyCode;
958 1a2be799 Florent Chuffart
        }
959 1a2be799 Florent Chuffart
        if (pressed_key == 13) { // enter pressed
960 1a2be799 Florent Chuffart
                theForm.submit();
961 1a2be799 Florent Chuffart
                return false;
962 1a2be799 Florent Chuffart
        }
963 1a2be799 Florent Chuffart
        return true;
964 1a2be799 Florent Chuffart
}',"\n\n";
965 1a2be799 Florent Chuffart
                                echo '// --></script>', "\n";
966 1a2be799 Florent Chuffart
                }
967 1a2be799 Florent Chuffart
968 1a2be799 Florent Chuffart
                if ($this->display['form']) {
969 1a2be799 Florent Chuffart
                        echo '<form class="',$this->getCSSclass('form'),'" method="post"';
970 1a2be799 Florent Chuffart
                        echo ' action="',$page_name,'" name="'.$this->cgi['prefix']['sys'].'form">',"\n";
971 1a2be799 Florent Chuffart
                }
972 1a2be799 Florent Chuffart
                return true;
973 1a2be799 Florent Chuffart
        } /* }}} */
974 1a2be799 Florent Chuffart
975 1a2be799 Florent Chuffart
        function form_end() /* {{{ */
976 1a2be799 Florent Chuffart
        {
977 1a2be799 Florent Chuffart
                if ($this->display['form']) {
978 1a2be799 Florent Chuffart
                        echo '</form>',"\n";
979 1a2be799 Florent Chuffart
                }
980 1a2be799 Florent Chuffart
        } /* }}} */
981 1a2be799 Florent Chuffart
982 1a2be799 Florent Chuffart
        function display_tab_labels($position) /* {{{ */
983 1a2be799 Florent Chuffart
        {
984 1a2be799 Florent Chuffart
                if (! is_array($this->tabs)) {
985 1a2be799 Florent Chuffart
                        return false;
986 1a2be799 Florent Chuffart
                }
987 1a2be799 Florent Chuffart
                echo '<table summary="labels" class="',$this->getCSSclass('tab', $position),'">',"\n";
988 1a2be799 Florent Chuffart
                echo '<tr class="',$this->getCSSclass('tab', $position),'">',"\n";
989 1a2be799 Florent Chuffart
                for ($i = ($this->tabs[0] == 'PMEtab0' ? 1 : 0); $i < count($this->tabs); $i++) {
990 1a2be799 Florent Chuffart
                        $css_class_name = $this->getCSSclass($i != $this->cur_tab ? 'tab' : 'tab-selected', $position);
991 1a2be799 Florent Chuffart
                        echo '<td class="',$css_class_name,'" id="'.$this->dhtml['prefix'].'tab',$i,'_',$position,'_label">';
992 1a2be799 Florent Chuffart
                        echo '<a class="',$css_class_name,'" id="'.$this->dhtml['prefix'].'tab',$i,'_',$position,'_link';
993 1a2be799 Florent Chuffart
                        echo '" href="javascript:'.$this->js['prefix'].'show_tab(\''.$this->dhtml['prefix'].'tab',$i,'\')">';
994 1a2be799 Florent Chuffart
                        echo $this->tabs[$i],'</a></td>',"\n";
995 1a2be799 Florent Chuffart
                }
996 1a2be799 Florent Chuffart
                echo '<td class="',$this->getCSSclass('tab-end', $position),'">&nbsp;</td>',"\n";
997 1a2be799 Florent Chuffart
                echo '</tr>',"\n";
998 1a2be799 Florent Chuffart
                echo '</table>',"\n";
999 1a2be799 Florent Chuffart
        } /* }}} */
1000 1a2be799 Florent Chuffart
1001 1a2be799 Florent Chuffart
        /*
1002 1a2be799 Florent Chuffart
         * Display functions
1003 1a2be799 Florent Chuffart
         */
1004 1a2be799 Florent Chuffart
1005 1a2be799 Florent Chuffart
        function display_add_record() /* {{{ */
1006 1a2be799 Florent Chuffart
        {
1007 1a2be799 Florent Chuffart
                for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
1008 1a2be799 Florent Chuffart
                        if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
1009 1a2be799 Florent Chuffart
                                $tab++;
1010 1a2be799 Florent Chuffart
                                echo '</table>',"\n";
1011 1a2be799 Florent Chuffart
                                echo '</div>',"\n";
1012 1a2be799 Florent Chuffart
                                echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n";
1013 1a2be799 Florent Chuffart
                                echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
1014 1a2be799 Florent Chuffart
                        }
1015 1a2be799 Florent Chuffart
                        if (! $this->displayed[$k]) {
1016 1a2be799 Florent Chuffart
                                continue;
1017 1a2be799 Florent Chuffart
                        }
1018 1a2be799 Florent Chuffart
                        if ($this->hidden($k)) {
1019 1a2be799 Florent Chuffart
                                echo $this->htmlHiddenData($this->fds[$k], $this->fdd[$k]['default']);
1020 1a2be799 Florent Chuffart
                                continue;
1021 1a2be799 Florent Chuffart
                        }
1022 1a2be799 Florent Chuffart
                        $css_postfix    = @$this->fdd[$k]['css']['postfix'];
1023 1a2be799 Florent Chuffart
                        $css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix);
1024 1a2be799 Florent Chuffart
                        $escape                        = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true;
1025 1a2be799 Florent Chuffart
                        echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n";
1026 1a2be799 Florent Chuffart
                        echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">';
1027 1a2be799 Florent Chuffart
                        echo $this->fdd[$k]['name'],'</td>',"\n";
1028 1a2be799 Florent Chuffart
                        echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
1029 1a2be799 Florent Chuffart
                        echo $this->getColAttributes($k),">\n";
1030 1a2be799 Florent Chuffart
                        if ($this->col_has_values($k)) {
1031 1a2be799 Florent Chuffart
                                $vals       = $this->set_values($k);
1032 1a2be799 Florent Chuffart
                                $selected   = @$this->fdd[$k]['default'];
1033 1a2be799 Florent Chuffart
                                $multiple   = $this->col_has_multiple($k);
1034 1a2be799 Florent Chuffart
                                $readonly   = $this->readonly($k);
1035 1a2be799 Florent Chuffart
                                $strip_tags = true;
1036 1a2be799 Florent Chuffart
                                //$escape     = true;
1037 1a2be799 Florent Chuffart
                                if ($this->col_has_checkboxes($k) || $this->col_has_radio_buttons($k)) {
1038 1a2be799 Florent Chuffart
                                        echo $this->htmlRadioCheck($this->cgi['prefix']['data'].$this->fds[$k],
1039 1a2be799 Florent Chuffart
                                                        $css_class_name, $vals, $selected, $multiple, $readonly,
1040 1a2be799 Florent Chuffart
                                                        $strip_tags, $escape);
1041 1a2be799 Florent Chuffart
                                } else {
1042 1a2be799 Florent Chuffart
                                        echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k],
1043 1a2be799 Florent Chuffart
                                                        $css_class_name, $vals, $selected, $multiple, $readonly,
1044 1a2be799 Florent Chuffart
                                                        $strip_tags, $escape);
1045 1a2be799 Florent Chuffart
                                }
1046 1a2be799 Florent Chuffart
                        } elseif (isset ($this->fdd[$k]['textarea'])) {
1047 1a2be799 Florent Chuffart
                                echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
1048 1a2be799 Florent Chuffart
                                echo ($this->readonly($k) ? ' disabled' : '');
1049 1a2be799 Florent Chuffart
                                if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
1050 1a2be799 Florent Chuffart
                                        echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
1051 1a2be799 Florent Chuffart
                                }
1052 1a2be799 Florent Chuffart
                                if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
1053 1a2be799 Florent Chuffart
                                        echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
1054 1a2be799 Florent Chuffart
                                }
1055 1a2be799 Florent Chuffart
                                if (isset($this->fdd[$k]['textarea']['wrap'])) {
1056 1a2be799 Florent Chuffart
                                        echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
1057 1a2be799 Florent Chuffart
                                } else {
1058 1a2be799 Florent Chuffart
                                        echo ' wrap="virtual"';
1059 1a2be799 Florent Chuffart
                                }
1060 1a2be799 Florent Chuffart
                                echo '>';
1061 1a2be799 Florent Chuffart
                                if($escape) echo htmlspecialchars($this->fdd[$k]['default']);
1062 1a2be799 Florent Chuffart
                                else echo $this->fdd[$k]['default'];
1063 1a2be799 Florent Chuffart
                                echo '</textarea>',"\n";
1064 1a2be799 Florent Chuffart
                        } elseif ($this->col_has_php($k)) {
1065 1a2be799 Florent Chuffart
                                echo include($this->fdd[$k]['php']);
1066 1a2be799 Florent Chuffart
                        } else {
1067 1a2be799 Florent Chuffart
                                // Simple edit box required
1068 1a2be799 Florent Chuffart
                                $len_props = '';
1069 1a2be799 Florent Chuffart
                                $maxlen = intval($this->fdd[$k]['maxlen']);
1070 1a2be799 Florent Chuffart
                                $size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
1071 1a2be799 Florent Chuffart
                                if ($size > 0) {
1072 1a2be799 Florent Chuffart
                                        $len_props .= ' size="'.$size.'"';
1073 1a2be799 Florent Chuffart
                                }
1074 1a2be799 Florent Chuffart
                                if ($maxlen > 0) {
1075 1a2be799 Florent Chuffart
                                        $len_props .= ' maxlength="'.$maxlen.'"';
1076 1a2be799 Florent Chuffart
                                }
1077 1a2be799 Florent Chuffart
                                echo '<input class="',$css_class_name,'" ';
1078 1a2be799 Florent Chuffart
                                echo ($this->password($k) ? 'type="password"' : 'type="text"');
1079 1a2be799 Florent Chuffart
                                echo ($this->readonly($k) ? ' disabled' : '');
1080 1a2be799 Florent Chuffart
                                echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
1081 1a2be799 Florent Chuffart
                                echo $len_props,' value="';
1082 1a2be799 Florent Chuffart
                                if($escape) echo htmlspecialchars($this->fdd[$k]['default']);
1083 1a2be799 Florent Chuffart
                            else echo $this->fdd[$k]['default'];
1084 1a2be799 Florent Chuffart
                                echo '" />';
1085 1a2be799 Florent Chuffart
                        }
1086 1a2be799 Florent Chuffart
                        echo '</td>',"\n";
1087 1a2be799 Florent Chuffart
                        if ($this->guidance) {
1088 1a2be799 Florent Chuffart
                                $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
1089 1a2be799 Florent Chuffart
                                $cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
1090 1a2be799 Florent Chuffart
                                echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
1091 1a2be799 Florent Chuffart
                        }
1092 1a2be799 Florent Chuffart
                        echo '</tr>',"\n";
1093 1a2be799 Florent Chuffart
                }
1094 1a2be799 Florent Chuffart
        } /* }}} */
1095 1a2be799 Florent Chuffart
1096 1a2be799 Florent Chuffart
        function display_copy_change_delete_record() /* {{{ */
1097 1a2be799 Florent Chuffart
        {
1098 1a2be799 Florent Chuffart
                /*
1099 1a2be799 Florent Chuffart
                 * For delete or change: SQL SELECT to retrieve the selected record
1100 1a2be799 Florent Chuffart
                 */
1101 1a2be799 Florent Chuffart
1102 1a2be799 Florent Chuffart
                $qparts['type']   = 'select';
1103 1a2be799 Florent Chuffart
                $qparts['select'] = $this->get_SQL_column_list();
1104 1a2be799 Florent Chuffart
                $qparts['from']   = $this->get_SQL_join_clause();
1105 1a2be799 Florent Chuffart
                $qparts['where']  = '('.$this->fqn($this->key).'='
1106 1a2be799 Florent Chuffart
                        .$this->key_delim.$this->rec.$this->key_delim.')';
1107 1a2be799 Florent Chuffart
1108 1a2be799 Florent Chuffart
                $res = $this->myquery($this->get_SQL_query($qparts),__LINE__);
1109 1a2be799 Florent Chuffart
                if (! ($row = $this->sql_fetch($res))) {
1110 1a2be799 Florent Chuffart
                        return false;
1111 1a2be799 Florent Chuffart
                }
1112 1a2be799 Florent Chuffart
                for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
1113 1a2be799 Florent Chuffart
                        if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
1114 1a2be799 Florent Chuffart
                                $tab++;
1115 1a2be799 Florent Chuffart
                                echo '</table>',"\n";
1116 1a2be799 Florent Chuffart
                                echo '</div>',"\n";
1117 1a2be799 Florent Chuffart
                                echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n";
1118 1a2be799 Florent Chuffart
                                echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
1119 1a2be799 Florent Chuffart
                        }
1120 1a2be799 Florent Chuffart
                        if (! $this->displayed[$k]) {
1121 1a2be799 Florent Chuffart
                                continue;
1122 1a2be799 Florent Chuffart
                        }
1123 1a2be799 Florent Chuffart
                        if ($this->copy_operation() || $this->change_operation()) {
1124 1a2be799 Florent Chuffart
                                if ($this->hidden($k)) {
1125 1a2be799 Florent Chuffart
                                        if ($k != $this->key_num) {
1126 1a2be799 Florent Chuffart
                                                echo $this->htmlHiddenData($this->fds[$k], $row["qf$k"]);
1127 1a2be799 Florent Chuffart
                                        }
1128 1a2be799 Florent Chuffart
                                        continue;
1129 1a2be799 Florent Chuffart
                                }
1130 1a2be799 Florent Chuffart
                                $css_postfix = @$this->fdd[$k]['css']['postfix'];
1131 1a2be799 Florent Chuffart
                                echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
1132 1a2be799 Florent Chuffart
                                echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">';
1133 1a2be799 Florent Chuffart
                                echo $this->fdd[$k]['name'],'</td>',"\n";
1134 1a2be799 Florent Chuffart
                                /* There are two possibilities of readonly fields handling:
1135 1a2be799 Florent Chuffart
                                   1. Display plain text for readonly timestamps, dates and URLs.
1136 1a2be799 Florent Chuffart
                                   2. Display disabled input field
1137 1a2be799 Florent Chuffart
                                   In all cases particular readonly field will NOT be saved. */
1138 1a2be799 Florent Chuffart
                                if ($this->readonly($k) && ($this->col_has_datemask($k) || $this->col_has_URL($k))) {
1139 1a2be799 Florent Chuffart
                                        echo $this->display_delete_field($row, $k);
1140 1a2be799 Florent Chuffart
                                } elseif ($this->password($k)) {
1141 1a2be799 Florent Chuffart
                                        echo $this->display_password_field($row, $k);
1142 1a2be799 Florent Chuffart
                                } else {
1143 1a2be799 Florent Chuffart
                                        echo $this->display_change_field($row, $k);
1144 1a2be799 Florent Chuffart
                                }
1145 1a2be799 Florent Chuffart
                                if ($this->guidance) {
1146 1a2be799 Florent Chuffart
                                        $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
1147 1a2be799 Florent Chuffart
                                        $cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
1148 1a2be799 Florent Chuffart
                                        echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
1149 1a2be799 Florent Chuffart
                                }
1150 1a2be799 Florent Chuffart
                                echo '</tr>',"\n";
1151 1a2be799 Florent Chuffart
                        } elseif ($this->delete_operation() || $this->view_operation()) {
1152 1a2be799 Florent Chuffart
                                $css_postfix = @$this->fdd[$k]['css']['postfix'];
1153 1a2be799 Florent Chuffart
                                echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
1154 1a2be799 Florent Chuffart
                                echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">';
1155 1a2be799 Florent Chuffart
                                echo $this->fdd[$k]['name'],'</td>',"\n";
1156 1a2be799 Florent Chuffart
                                if ($this->password($k)) {
1157 1a2be799 Florent Chuffart
                                        echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
1158 1a2be799 Florent Chuffart
                                        echo $this->getColAttributes($k),'>',$this->labels['hidden'],'</td>',"\n";
1159 1a2be799 Florent Chuffart
                                } else {
1160 1a2be799 Florent Chuffart
                                        $this->display_delete_field($row, $k);
1161 1a2be799 Florent Chuffart
                                }
1162 1a2be799 Florent Chuffart
                                if ($this->guidance) {
1163 1a2be799 Florent Chuffart
                                        $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
1164 1a2be799 Florent Chuffart
                                        $cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
1165 1a2be799 Florent Chuffart
                                        echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
1166 1a2be799 Florent Chuffart
                                }
1167 1a2be799 Florent Chuffart
                                echo '</tr>',"\n";
1168 1a2be799 Florent Chuffart
                        }
1169 1a2be799 Florent Chuffart
                }
1170 1a2be799 Florent Chuffart
        } /* }}} */
1171 1a2be799 Florent Chuffart
1172 1a2be799 Florent Chuffart
        function display_change_field($row, $k) /* {{{ */ 
1173 1a2be799 Florent Chuffart
        {
1174 1a2be799 Florent Chuffart
                $css_postfix    = @$this->fdd[$k]['css']['postfix'];
1175 1a2be799 Florent Chuffart
                $css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
1176 1a2be799 Florent Chuffart
                $escape         = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true;
1177 1a2be799 Florent Chuffart
                echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
1178 1a2be799 Florent Chuffart
                echo $this->getColAttributes($k),">\n";
1179 1a2be799 Florent Chuffart
                if ($this->col_has_values($k)) {
1180 1a2be799 Florent Chuffart
                        $vals       = $this->set_values($k);
1181 1a2be799 Florent Chuffart
                        $multiple   = $this->col_has_multiple($k);
1182 1a2be799 Florent Chuffart
                        $readonly   = $this->readonly($k);
1183 1a2be799 Florent Chuffart
                        $strip_tags = true;
1184 1a2be799 Florent Chuffart
                        //$escape     = true;
1185 1a2be799 Florent Chuffart
                        if ($this->col_has_checkboxes($k) || $this->col_has_radio_buttons($k)) {
1186 1a2be799 Florent Chuffart
                                echo $this->htmlRadioCheck($this->cgi['prefix']['data'].$this->fds[$k],
1187 1a2be799 Florent Chuffart
                                                $css_class_name, $vals, $row["qf$k"], $multiple, $readonly,
1188 1a2be799 Florent Chuffart
                                                $strip_tags, $escape);
1189 1a2be799 Florent Chuffart
                        } else {
1190 1a2be799 Florent Chuffart
                                echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k],
1191 1a2be799 Florent Chuffart
                                                $css_class_name, $vals, $row["qf$k"], $multiple, $readonly,
1192 1a2be799 Florent Chuffart
                                                $strip_tags, $escape);
1193 1a2be799 Florent Chuffart
                        }
1194 1a2be799 Florent Chuffart
                } elseif (isset($this->fdd[$k]['textarea'])) {
1195 1a2be799 Florent Chuffart
                        echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
1196 1a2be799 Florent Chuffart
                        echo ($this->readonly($k) ? ' disabled' : '');
1197 1a2be799 Florent Chuffart
                        if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
1198 1a2be799 Florent Chuffart
                                echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
1199 1a2be799 Florent Chuffart
                        }
1200 1a2be799 Florent Chuffart
                        if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
1201 1a2be799 Florent Chuffart
                                echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
1202 1a2be799 Florent Chuffart
                        }
1203 1a2be799 Florent Chuffart
                        if (isset($this->fdd[$k]['textarea']['wrap'])) {
1204 1a2be799 Florent Chuffart
                                echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
1205 1a2be799 Florent Chuffart
                        } else {
1206 1a2be799 Florent Chuffart
                                echo ' wrap="virtual"';
1207 1a2be799 Florent Chuffart
                        }
1208 1a2be799 Florent Chuffart
                        echo '>';
1209 1a2be799 Florent Chuffart
                        if($escape) echo htmlspecialchars($row["qf$k"]);
1210 1a2be799 Florent Chuffart
                        else echo $row["qf$k"];
1211 1a2be799 Florent Chuffart
                        echo '</textarea>',"\n";
1212 1a2be799 Florent Chuffart
                } elseif ($this->col_has_php($k)) {
1213 1a2be799 Florent Chuffart
                        echo include($this->fdd[$k]['php']);
1214 1a2be799 Florent Chuffart
                } else {
1215 1a2be799 Florent Chuffart
                        $len_props = '';
1216 1a2be799 Florent Chuffart
                        $maxlen = intval($this->fdd[$k]['maxlen']);
1217 1a2be799 Florent Chuffart
                        $size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
1218 1a2be799 Florent Chuffart
                        if ($size > 0) {
1219 1a2be799 Florent Chuffart
                                $len_props .= ' size="'.$size.'"';
1220 1a2be799 Florent Chuffart
                        }
1221 1a2be799 Florent Chuffart
                        if ($maxlen > 0) {
1222 1a2be799 Florent Chuffart
                                $len_props .= ' maxlength="'.$maxlen.'"';
1223 1a2be799 Florent Chuffart
                        }
1224 1a2be799 Florent Chuffart
                        echo '<input class="',$css_class_name,'" type="text"';
1225 1a2be799 Florent Chuffart
                        echo ($this->readonly($k) ? ' disabled' : '');
1226 1a2be799 Florent Chuffart
                        echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="';
1227 1a2be799 Florent Chuffart
                        if($escape) echo htmlspecialchars($row["qf$k"]);
1228 1a2be799 Florent Chuffart
                        else echo $row["qf$k"];
1229 1a2be799 Florent Chuffart
                        echo '"',$len_props,' />',"\n";
1230 1a2be799 Florent Chuffart
                }
1231 1a2be799 Florent Chuffart
                echo '</td>',"\n";
1232 1a2be799 Florent Chuffart
        } /* }}} */
1233 1a2be799 Florent Chuffart
1234 1a2be799 Florent Chuffart
        function display_password_field($row, $k) /* {{{ */
1235 1a2be799 Florent Chuffart
        {
1236 1a2be799 Florent Chuffart
                $css_postfix = @$this->fdd[$k]['css']['postfix'];
1237 1a2be799 Florent Chuffart
                echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
1238 1a2be799 Florent Chuffart
                echo $this->getColAttributes($k),">\n";
1239 1a2be799 Florent Chuffart
                $len_props = '';
1240 1a2be799 Florent Chuffart
                $maxlen = intval($this->fdd[$k]['maxlen']);
1241 1a2be799 Florent Chuffart
                $size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
1242 1a2be799 Florent Chuffart
                if ($size > 0) {
1243 1a2be799 Florent Chuffart
                        $len_props .= ' size="'.$size.'"';
1244 1a2be799 Florent Chuffart
                }
1245 1a2be799 Florent Chuffart
                if ($maxlen > 0) {
1246 1a2be799 Florent Chuffart
                        $len_props .= ' maxlength="'.$maxlen.'"';
1247 1a2be799 Florent Chuffart
                }
1248 1a2be799 Florent Chuffart
                echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password"';
1249 1a2be799 Florent Chuffart
                echo ($this->readonly($k) ? ' disabled' : '');
1250 1a2be799 Florent Chuffart
                echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="';
1251 1a2be799 Florent Chuffart
                echo htmlspecialchars($row["qf$k"]),'"',$len_props,' />',"\n";
1252 1a2be799 Florent Chuffart
                echo '</td>',"\n";
1253 1a2be799 Florent Chuffart
        } /* }}} */
1254 1a2be799 Florent Chuffart
1255 1a2be799 Florent Chuffart
        function display_delete_field($row, $k) /* {{{ */
1256 1a2be799 Florent Chuffart
        {
1257 1a2be799 Florent Chuffart
                $css_postfix    = @$this->fdd[$k]['css']['postfix'];
1258 1a2be799 Florent Chuffart
                $css_class_name = $this->getCSSclass('value', null, true, $css_postfix);
1259 1a2be799 Florent Chuffart
                echo '<td class="',$css_class_name,'"',$this->getColAttributes($k),">\n";
1260 1a2be799 Florent Chuffart
                echo $this->cellDisplay($k, $row, $css_class_name);
1261 1a2be799 Florent Chuffart
                echo '</td>',"\n";
1262 1a2be799 Florent Chuffart
        } /* }}} */
1263 1a2be799 Florent Chuffart
1264 1a2be799 Florent Chuffart
        /**
1265 1a2be799 Florent Chuffart
         * Returns CSS class name
1266 1a2be799 Florent Chuffart
         */
1267 1a2be799 Florent Chuffart
        function getCSSclass($name, $position  = null, $divider = null, $postfix = null) /* {{{ */
1268 1a2be799 Florent Chuffart
        {
1269 1a2be799 Florent Chuffart
                static $div_idx = -1;
1270 1a2be799 Florent Chuffart
                $elements = array($this->css['prefix'], $name);
1271 1a2be799 Florent Chuffart
                if ($this->page_type && $this->css['page_type']) {
1272 1a2be799 Florent Chuffart
                        if ($this->page_type != 'L' && $this->page_type != 'F') {
1273 1a2be799 Florent Chuffart
                                $elements[] = $this->page_types[$this->page_type];
1274 1a2be799 Florent Chuffart
                        }
1275 1a2be799 Florent Chuffart
                }
1276 1a2be799 Florent Chuffart
                if ($position && $this->css['position']) {
1277 1a2be799 Florent Chuffart
                        $elements[] = $position;
1278 1a2be799 Florent Chuffart
                }
1279 1a2be799 Florent Chuffart
                if ($divider && $this->css['divider']) {
1280 1a2be799 Florent Chuffart
                        if ($divider === 'next') {
1281 1a2be799 Florent Chuffart
                                $div_idx++;
1282 1a2be799 Florent Chuffart
                                if ($this->css['divider'] > 0 && $div_idx >= $this->css['divider']) {
1283 1a2be799 Florent Chuffart
                                        $div_idx = 0;
1284 1a2be799 Florent Chuffart
                                }
1285 1a2be799 Florent Chuffart
                        }
1286 1a2be799 Florent Chuffart
                        $elements[] = $div_idx;
1287 1a2be799 Florent Chuffart
                }
1288 1a2be799 Florent Chuffart
                if ($postfix) {
1289 1a2be799 Florent Chuffart
                        $elements[] = $postfix;
1290 1a2be799 Florent Chuffart
                }
1291 1a2be799 Florent Chuffart
                return join($this->css['separator'], $elements);
1292 1a2be799 Florent Chuffart
        } /* }}} */
1293 1a2be799 Florent Chuffart
1294 1a2be799 Florent Chuffart
        /**
1295 1a2be799 Florent Chuffart
         * Returns field cell HTML attributes
1296 1a2be799 Florent Chuffart
         */
1297 1a2be799 Florent Chuffart
        function getColAttributes($k) /* {{{ */
1298 1a2be799 Florent Chuffart
        {
1299 1a2be799 Florent Chuffart
                $colattrs = '';
1300 1a2be799 Florent Chuffart
                if (isset($this->fdd[$k]['colattrs'])) {
1301 1a2be799 Florent Chuffart
                        $colattrs .= ' ';
1302 1a2be799 Florent Chuffart
                        $colattrs .= trim($this->fdd[$k]['colattrs']);
1303 1a2be799 Florent Chuffart
                }
1304 1a2be799 Florent Chuffart
                if (isset($this->fdd[$k]['nowrap'])) {
1305 1a2be799 Florent Chuffart
                        $colattrs .= ' nowrap';
1306 1a2be799 Florent Chuffart
                }
1307 1a2be799 Florent Chuffart
                return $colattrs;
1308 1a2be799 Florent Chuffart
        } /* }}} */
1309 1a2be799 Florent Chuffart
1310 1a2be799 Florent Chuffart
        /**
1311 1a2be799 Florent Chuffart
         * Substitutes variables in string
1312 1a2be799 Florent Chuffart
         * (this is very simple but secure eval() replacement)
1313 1a2be799 Florent Chuffart
         */
1314 1a2be799 Florent Chuffart
        function substituteVars($str, $subst_ar) /* {{{ */
1315 1a2be799 Florent Chuffart
        {
1316 1a2be799 Florent Chuffart
                $array = preg_split('/(\\$\w+)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
1317 1a2be799 Florent Chuffart
                $count = count($array);
1318 1a2be799 Florent Chuffart
                for ($i = 1; $i < $count; $i += 2) {
1319 1a2be799 Florent Chuffart
                        $key = substr($array[$i], 1);
1320 1a2be799 Florent Chuffart
                        if (isset($subst_ar[$key])) {
1321 1a2be799 Florent Chuffart
                                $array[$i] = $subst_ar[$key];
1322 1a2be799 Florent Chuffart
                        }
1323 1a2be799 Florent Chuffart
                }
1324 1a2be799 Florent Chuffart
                return join('', $array);
1325 1a2be799 Florent Chuffart
        } /* }}} */
1326 1a2be799 Florent Chuffart
1327 1a2be799 Florent Chuffart
        /**
1328 1a2be799 Florent Chuffart
         * Print URL
1329 1a2be799 Florent Chuffart
         */
1330 1a2be799 Florent Chuffart
        function urlDisplay($k, $link_val, $disp_val, $css, $key) /* {{{ */
1331 1a2be799 Florent Chuffart
        {
1332 1a2be799 Florent Chuffart
                $escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true;
1333 1a2be799 Florent Chuffart
                $ret  = '';
1334 1a2be799 Florent Chuffart
                $name = $this->fds[$k];
1335 1a2be799 Florent Chuffart
                $page = $this->page_name;
1336 1a2be799 Florent Chuffart
                $url  = $this->cgi['prefix']['sys'].'rec'.'='.$key.'&'.$this->cgi['prefix']['sys'].'fm'
1337 1a2be799 Florent Chuffart
                        .'='.$this->fm.'&'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl;
1338 1a2be799 Florent Chuffart
                $url .= '&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn).$this->qfn;
1339 1a2be799 Florent Chuffart
                $url .= '&'.$this->get_sfn_cgi_vars().$this->cgi['persist'];
1340 1a2be799 Florent Chuffart
                $ar   = array(
1341 1a2be799 Florent Chuffart
                                'key'   => $key,
1342 1a2be799 Florent Chuffart
                                'name'  => $name,
1343 1a2be799 Florent Chuffart
                                'link'  => $link_val,
1344 1a2be799 Florent Chuffart
                                'value' => $disp_val,
1345 1a2be799 Florent Chuffart
                                'css'   => $css,
1346 1a2be799 Florent Chuffart
                                'page'  => $page,
1347 1a2be799 Florent Chuffart
                                'url'   => $url
1348 1a2be799 Florent Chuffart
                                );
1349 1a2be799 Florent Chuffart
                $urllink = isset($this->fdd[$k]['URL'])
1350 1a2be799 Florent Chuffart
                        ?  $this->substituteVars($this->fdd[$k]['URL'], $ar)
1351 1a2be799 Florent Chuffart
                        : $link_val;
1352 1a2be799 Florent Chuffart
                $urldisp = isset($this->fdd[$k]['URLdisp'])
1353 1a2be799 Florent Chuffart
                        ?  $this->substituteVars($this->fdd[$k]['URLdisp'], $ar)
1354 1a2be799 Florent Chuffart
                        : $disp_val;
1355 1a2be799 Florent Chuffart
                $target = isset($this->fdd[$k]['URLtarget'])
1356 1a2be799 Florent Chuffart
                        ? 'target="'.htmlspecialchars($this->fdd[$k]['URLtarget']).'" '
1357 1a2be799 Florent Chuffart
                        : '';
1358 1a2be799 Florent Chuffart
                $prefix_found  = false;
1359 1a2be799 Florent Chuffart
                $postfix_found = false;
1360 1a2be799 Florent Chuffart
                $prefix_ar     = @$this->fdd[$k]['URLprefix'];
1361 1a2be799 Florent Chuffart
                $postfix_ar    = @$this->fdd[$k]['URLpostfix'];
1362 1a2be799 Florent Chuffart
                is_array($prefix_ar)  || $prefix_ar  = array($prefix_ar);
1363 1a2be799 Florent Chuffart
                is_array($postfix_ar) || $postfix_ar = array($postfix_ar);
1364 1a2be799 Florent Chuffart
                foreach ($prefix_ar as $prefix) {
1365 1a2be799 Florent Chuffart
                        if (! strncmp($prefix, $urllink, strlen($prefix))) {
1366 1a2be799 Florent Chuffart
                                $prefix_found = true;
1367 1a2be799 Florent Chuffart
                                break;
1368 1a2be799 Florent Chuffart
                        }
1369 1a2be799 Florent Chuffart
                }
1370 1a2be799 Florent Chuffart
                foreach ($postfix_ar as $postfix) {
1371 1a2be799 Florent Chuffart
                        if (! strncmp($postfix, $urllink, strlen($postfix))) {
1372 1a2be799 Florent Chuffart
                                $postfix_found = true;
1373 1a2be799 Florent Chuffart
                                break;
1374 1a2be799 Florent Chuffart
                        }
1375 1a2be799 Florent Chuffart
                }
1376 1a2be799 Florent Chuffart
                $prefix_found  || $urllink = array_shift($prefix_ar).$urllink;
1377 1a2be799 Florent Chuffart
                $postfix_found || $urllink = $urllink.array_shift($postfix_ar);
1378 1a2be799 Florent Chuffart
                if (strlen($urllink) <= 0 || strlen($urldisp) <= 0) {
1379 1a2be799 Florent Chuffart
                        $ret = '&nbsp;';
1380 1a2be799 Florent Chuffart
                } else {
1381 1a2be799 Florent Chuffart
                        if ($escape) {
1382 1a2be799 Florent Chuffart
                                $urldisp = htmlspecialchars($urldisp);
1383 1a2be799 Florent Chuffart
                        }
1384 1a2be799 Florent Chuffart
                        $urllink = htmlspecialchars($urllink);
1385 1a2be799 Florent Chuffart
                        $ret = '<a '.$target.'class="'.$css.'" href="'.$urllink.'">'.$urldisp.'</a>';
1386 1a2be799 Florent Chuffart
                }
1387 1a2be799 Florent Chuffart
                return $ret;
1388 1a2be799 Florent Chuffart
        } /* }}} */
1389 1a2be799 Florent Chuffart
1390 1a2be799 Florent Chuffart
        function cellDisplay($k, $row, $css) /* {{{ */
1391 1a2be799 Florent Chuffart
        {
1392 1a2be799 Florent Chuffart
                $escape  = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true;
1393 1a2be799 Florent Chuffart
                $key_rec = $row['qf'.$this->key_num];
1394 1a2be799 Florent Chuffart
                if (@$this->fdd[$k]['datemask']) {
1395 1a2be799 Florent Chuffart
                        $value = intval($row["qf$k".'_timestamp']);
1396 1a2be799 Florent Chuffart
                        $value = $value ? @date($this->fdd[$k]['datemask'], $value) : '';
1397 1a2be799 Florent Chuffart
                } else if (@$this->fdd[$k]['strftimemask']) {
1398 1a2be799 Florent Chuffart
                        $value = intval($row["qf$k".'_timestamp']);
1399 1a2be799 Florent Chuffart
                        $value = $value ? @strftime($this->fdd[$k]['strftimemask'], $value) : '';
1400 1a2be799 Florent Chuffart
                } else if ($this->is_values2($k, $row["qf$k"])) {
1401 1a2be799 Florent Chuffart
                        $value = $row['qf'.$k.'_idx'];
1402 1a2be799 Florent Chuffart
                        if ($this->fdd[$k]['select'] == 'M') {
1403 1a2be799 Florent Chuffart
                                $value_ar  = explode(',', $value);
1404 1a2be799 Florent Chuffart
                                $value_ar2 = array();
1405 1a2be799 Florent Chuffart
                                foreach ($value_ar as $value_key) {
1406 1a2be799 Florent Chuffart
                                        if (isset($this->fdd[$k]['values2'][$value_key])) {
1407 1a2be799 Florent Chuffart
                                                $value_ar2[$value_key] = $this->fdd[$k]['values2'][$value_key];
1408 1a2be799 Florent Chuffart
                                                $escape = false;
1409 1a2be799 Florent Chuffart
                                        }
1410 1a2be799 Florent Chuffart
                                }
1411 1a2be799 Florent Chuffart
                                $value = join(', ', $value_ar2);
1412 1a2be799 Florent Chuffart
                        } else {
1413 1a2be799 Florent Chuffart
                                if (isset($this->fdd[$k]['values2'][$value])) {
1414 1a2be799 Florent Chuffart
                                        $value  = $this->fdd[$k]['values2'][$value];
1415 1a2be799 Florent Chuffart
                                        $escape = false;
1416 1a2be799 Florent Chuffart
                                }
1417 1a2be799 Florent Chuffart
                        }
1418 1a2be799 Florent Chuffart
                } elseif (isset($this->fdd[$k]['values2'][$row["qf$k"]])) {
1419 1a2be799 Florent Chuffart
                        $value = $this->fdd[$k]['values2'][$row["qf$k"]];
1420 1a2be799 Florent Chuffart
                } else {
1421 1a2be799 Florent Chuffart
                        $value = $row["qf$k"];
1422 1a2be799 Florent Chuffart
                }
1423 1a2be799 Florent Chuffart
                $original_value = $value;
1424 1a2be799 Florent Chuffart
                if (@$this->fdd[$k]['strip_tags']) {
1425 1a2be799 Florent Chuffart
                        $value = strip_tags($value);
1426 1a2be799 Florent Chuffart
                }
1427 1a2be799 Florent Chuffart
                if ($num_ar = @$this->fdd[$k]['number_format']) {
1428 1a2be799 Florent Chuffart
                        if (! is_array($num_ar)) {
1429 1a2be799 Florent Chuffart
                                $num_ar = array($num_ar);
1430 1a2be799 Florent Chuffart
                        }
1431 1a2be799 Florent Chuffart
                        if (count($num_ar) == 1) {
1432 1a2be799 Florent Chuffart
                                list($nbDec) = $num_ar;
1433 1a2be799 Florent Chuffart
                                $value = number_format($value, $nbDec);
1434 1a2be799 Florent Chuffart
                        } else if (count($num_ar) == 3) {
1435 1a2be799 Florent Chuffart
                                list($nbDec, $decPoint, $thSep) = $num_ar;
1436 1a2be799 Florent Chuffart
                                $value = number_format($value, $nbDec, $decPoint, $thSep);
1437 1a2be799 Florent Chuffart
                        }
1438 1a2be799 Florent Chuffart
                }
1439 1a2be799 Florent Chuffart
                if (intval($this->fdd[$k]['trimlen']) > 0 && strlen($value) > $this->fdd[$k]['trimlen']) {
1440 1a2be799 Florent Chuffart
                        $value = ereg_replace("[\r\n\t ]+",' ',$value);
1441 1a2be799 Florent Chuffart
                        $value = substr($value, 0, $this->fdd[$k]['trimlen'] - 3).'...';
1442 1a2be799 Florent Chuffart
                }
1443 1a2be799 Florent Chuffart
                if (@$this->fdd[$k]['mask']) {
1444 1a2be799 Florent Chuffart
                        $value = sprintf($this->fdd[$k]['mask'], $value);
1445 1a2be799 Florent Chuffart
                }
1446 1a2be799 Florent Chuffart
                if ($this->col_has_php($k)) {
1447 1a2be799 Florent Chuffart
                        return include($this->fdd[$k]['php']);
1448 1a2be799 Florent Chuffart
                }
1449 1a2be799 Florent Chuffart
                if ($this->col_has_URL($k)) {
1450 1a2be799 Florent Chuffart
                        return $this->urlDisplay($k, $original_value, $value, $css, $key_rec);
1451 1a2be799 Florent Chuffart
                }
1452 1a2be799 Florent Chuffart
                if (strlen($value) <= 0) {
1453 1a2be799 Florent Chuffart
                        return '&nbsp;';
1454 1a2be799 Florent Chuffart
                }
1455 1a2be799 Florent Chuffart
                if ($escape) {
1456 1a2be799 Florent Chuffart
                        $value = htmlspecialchars($value);
1457 1a2be799 Florent Chuffart
                }
1458 1a2be799 Florent Chuffart
                return nl2br($value);
1459 1a2be799 Florent Chuffart
        } /* }}} */
1460 1a2be799 Florent Chuffart
1461 1a2be799 Florent Chuffart
        /**
1462 1a2be799 Florent Chuffart
         * Creates HTML submit input element
1463 1a2be799 Florent Chuffart
         *
1464 1a2be799 Florent Chuffart
         * @param        name                        element name
1465 1a2be799 Florent Chuffart
         * @param        label                        key in the language hash used as label
1466 1a2be799 Florent Chuffart
         * @param        css_class_name        CSS class name
1467 1a2be799 Florent Chuffart
         * @param        js_validation        if add JavaScript validation subroutine to button
1468 1a2be799 Florent Chuffart
         * @param        disabled                if mark the button as disabled
1469 1a2be799 Florent Chuffart
         * @param        js                any extra text in tags
1470 1a2be799 Florent Chuffart
         */
1471 1a2be799 Florent Chuffart
        function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false, $js = NULL) /* {{{ */
1472 1a2be799 Florent Chuffart
        {
1473 1a2be799 Florent Chuffart
                // Note that <input disabled> isn't valid HTML, but most browsers support it
1474 1a2be799 Florent Chuffart
                if($disabled == -1) return;
1475 1a2be799 Florent Chuffart
                $markdisabled = $disabled ? ' disabled' : '';
1476 1a2be799 Florent Chuffart
                $ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name
1477 1a2be799 Florent Chuffart
                        .'" name="'.$this->cgi['prefix']['sys'].ltrim($markdisabled).$name
1478 1a2be799 Florent Chuffart
                        .'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label);
1479 1a2be799 Florent Chuffart
                if ($js_validation) {
1480 1a2be799 Florent Chuffart
                        $ret .= '" onclick="return '.$this->js['prefix'].'form_control(this.form);';
1481 1a2be799 Florent Chuffart
                }
1482 1a2be799 Florent Chuffart
                $ret .='"';
1483 1a2be799 Florent Chuffart
                if(isset($js)) $ret .= ' '.$js;
1484 1a2be799 Florent Chuffart
                $ret .= ' />';
1485 1a2be799 Florent Chuffart
                return $ret;
1486 1a2be799 Florent Chuffart
        } /* }}} */
1487 1a2be799 Florent Chuffart
1488 1a2be799 Florent Chuffart
        /**
1489 1a2be799 Florent Chuffart
         * Creates HTML hidden input element
1490 1a2be799 Florent Chuffart
         *
1491 1a2be799 Florent Chuffart
         * @param        name        element name
1492 1a2be799 Florent Chuffart
         * @param        value        value
1493 1a2be799 Florent Chuffart
         */
1494 1a2be799 Florent Chuffart
1495 1a2be799 Florent Chuffart
        function htmlHiddenSys($name, $value) /* {{{ */
1496 1a2be799 Florent Chuffart
        {
1497 1a2be799 Florent Chuffart
                return $this->htmlHidden($this->cgi['prefix']['sys'].$name, $value);
1498 1a2be799 Florent Chuffart
        } /* }}} */
1499 1a2be799 Florent Chuffart
1500 1a2be799 Florent Chuffart
        function htmlHiddenData($name, $value) /* {{{ */
1501 1a2be799 Florent Chuffart
        {
1502 1a2be799 Florent Chuffart
                return $this->htmlHidden($this->cgi['prefix']['data'].$name, $value);
1503 1a2be799 Florent Chuffart
        } /* }}} */
1504 1a2be799 Florent Chuffart
1505 1a2be799 Florent Chuffart
        function htmlHidden($name, $value) /* {{{ */
1506 1a2be799 Florent Chuffart
        {
1507 1a2be799 Florent Chuffart
                return '<input type="hidden" name="'.htmlspecialchars($name)
1508 1a2be799 Florent Chuffart
                        .'" value="'.htmlspecialchars($value).'" />'."\n";
1509 1a2be799 Florent Chuffart
        } /* }}} */
1510 1a2be799 Florent Chuffart
1511 1a2be799 Florent Chuffart
        /**
1512 1a2be799 Florent Chuffart
         * Creates HTML select element (tag)
1513 1a2be799 Florent Chuffart
         *
1514 1a2be799 Florent Chuffart
         * @param        name                element name
1515 1a2be799 Florent Chuffart
         * @param        css                        CSS class name
1516 1a2be799 Florent Chuffart
         * @param        kv_array        key => value array
1517 1a2be799 Florent Chuffart
         * @param        selected        selected key (it can be single string, array of
1518 1a2be799 Florent Chuffart
         *                                                keys or multiple values separated by comma)
1519 1a2be799 Florent Chuffart
         * @param        multiple        bool for multiple selection
1520 1a2be799 Florent Chuffart
         * @param        readonly        bool for readonly/disabled selection
1521 1a2be799 Florent Chuffart
         * @param        strip_tags        bool for stripping tags from values
1522 1a2be799 Florent Chuffart
         * @param        escape                bool for HTML escaping values
1523 1a2be799 Florent Chuffart
         * @param        js                string to be in the <select >, ususally onchange='..';
1524 1a2be799 Florent Chuffart
         */
1525 1a2be799 Florent Chuffart
        function htmlSelect($name, $css, $kv_array, $selected = null, /* ...) {{{ */
1526 1a2be799 Florent Chuffart
                        /* booleans: */ $multiple = false, $readonly = false, $strip_tags = false, $escape = true, $js = NULL)
1527 1a2be799 Florent Chuffart
        {
1528 1a2be799 Florent Chuffart
                $ret = '<select class="'.htmlspecialchars($css).'" name="'.htmlspecialchars($name);
1529 1a2be799 Florent Chuffart
                if ($multiple) {
1530 1a2be799 Florent Chuffart
                        $ret  .= '[]" multiple size="'.$this->multiple;
1531 1a2be799 Florent Chuffart
                        if (! is_array($selected) && $selected !== null) {
1532 1a2be799 Florent Chuffart
                                $selected = explode(',', $selected);
1533 1a2be799 Florent Chuffart
                        }
1534 1a2be799 Florent Chuffart
                }
1535 1a2be799 Florent Chuffart
                $ret .= '"'.($readonly ? ' disabled ' : ' ').$js.">\n";
1536 1a2be799 Florent Chuffart
                if (! is_array($selected)) {
1537 1a2be799 Florent Chuffart
                        $selected = $selected === null ? array() : array((string)$selected);
1538 1a2be799 Florent Chuffart
                } else {
1539 1a2be799 Florent Chuffart
                        foreach($selected as $val) $selecte2[]=(string)$val;
1540 1a2be799 Florent Chuffart
                        $selected = $selected2;
1541 1a2be799 Florent Chuffart
                }
1542 1a2be799 Florent Chuffart
                $found = false;
1543 1a2be799 Florent Chuffart
                foreach ($kv_array as $key => $value) {
1544 1a2be799 Florent Chuffart
                        $ret .= '<option value="'.htmlspecialchars($key).'"';
1545 1a2be799 Florent Chuffart
                        if ((! $found || $multiple) && in_array((string)$key, $selected, 1)
1546 1a2be799 Florent Chuffart
                                        || (count($selected) == 0 && ! $found && ! $multiple)) {
1547 1a2be799 Florent Chuffart
                                $ret  .= ' selected="selected"';
1548 1a2be799 Florent Chuffart
                                $found = true;
1549 1a2be799 Florent Chuffart
                        }
1550 1a2be799 Florent Chuffart
                        $strip_tags && $value = strip_tags($value);
1551 1a2be799 Florent Chuffart
                        $escape     && $value = htmlspecialchars($value);
1552 1a2be799 Florent Chuffart
                        $ret .= '>'.$value.'</option>'."\n";
1553 1a2be799 Florent Chuffart
                }
1554 1a2be799 Florent Chuffart
                $ret .= '</select>';
1555 1a2be799 Florent Chuffart
                return $ret;
1556 1a2be799 Florent Chuffart
        } /* }}} */
1557 1a2be799 Florent Chuffart
1558 1a2be799 Florent Chuffart
        /**
1559 1a2be799 Florent Chuffart
         * Creates HTML checkboxes or radio buttons
1560 1a2be799 Florent Chuffart
         *
1561 1a2be799 Florent Chuffart
         * @param        name                element name
1562 1a2be799 Florent Chuffart
         * @param        css                        CSS class name
1563 1a2be799 Florent Chuffart
         * @param        kv_array        key => value array
1564 1a2be799 Florent Chuffart
         * @param        selected        selected key (it can be single string, array of
1565 1a2be799 Florent Chuffart
         *                                                keys or multiple values separated by comma)
1566 1a2be799 Florent Chuffart
         * @param        multiple        bool for multiple selection (checkboxes)
1567 1a2be799 Florent Chuffart
         * @param        readonly        bool for readonly/disabled selection
1568 1a2be799 Florent Chuffart
         * @param        strip_tags        bool for stripping tags from values
1569 1a2be799 Florent Chuffart
         * @param        escape                bool for HTML escaping values
1570 1a2be799 Florent Chuffart
         * @param        js                string to be in the <select >, ususally onchange='..';
1571 1a2be799 Florent Chuffart
         */
1572 1a2be799 Florent Chuffart
        function htmlRadioCheck($name, $css, $kv_array, $selected = null, /* ...) {{{ */
1573 1a2be799 Florent Chuffart
                        /* booleans: */ $multiple = false, $readonly = false, $strip_tags = false, $escape = true, $js = NULL)
1574 1a2be799 Florent Chuffart
        {
1575 1a2be799 Florent Chuffart
                $ret = '';
1576 1a2be799 Florent Chuffart
                if ($multiple) {
1577 1a2be799 Florent Chuffart
                        if (! is_array($selected) && $selected !== null) {
1578 1a2be799 Florent Chuffart
                                $selected = explode(',', $selected);
1579 1a2be799 Florent Chuffart
                        }
1580 1a2be799 Florent Chuffart
                }
1581 1a2be799 Florent Chuffart
                if (! is_array($selected)) {
1582 1a2be799 Florent Chuffart
                        $selected = $selected === null ? array() : array($selected);
1583 1a2be799 Florent Chuffart
                }
1584 1a2be799 Florent Chuffart
                $found = false;
1585 1a2be799 Florent Chuffart
                foreach ($kv_array as $key => $value) {
1586 1a2be799 Florent Chuffart
                        $ret .= '<input type="'.($multiple ? 'checkbox' : 'radio').'" name="';
1587 1a2be799 Florent Chuffart
                        $ret .= htmlspecialchars($name).'[]" value="'.htmlspecialchars($key).'"';
1588 1a2be799 Florent Chuffart
                        if ((! $found || $multiple) && in_array((string) $key, $selected, 1)
1589 1a2be799 Florent Chuffart
                                        || (count($selected) == 0 && ! $found && ! $multiple)) {
1590 1a2be799 Florent Chuffart
                                $ret  .= ' checked';
1591 1a2be799 Florent Chuffart
                                $found = true;
1592 1a2be799 Florent Chuffart
                        }
1593 1a2be799 Florent Chuffart
                        if ($readonly) {
1594 1a2be799 Florent Chuffart
                                $ret .= ' disabled';
1595 1a2be799 Florent Chuffart
                        }
1596 1a2be799 Florent Chuffart
                        $strip_tags && $value = strip_tags($value);
1597 1a2be799 Florent Chuffart
                        $escape     && $value = htmlspecialchars($value);
1598 1a2be799 Florent Chuffart
                        $ret .= '>'.$value.'<br>'."\n";
1599 1a2be799 Florent Chuffart
                }
1600 1a2be799 Florent Chuffart
                return $ret;
1601 1a2be799 Florent Chuffart
        } /* }}} */
1602 1a2be799 Florent Chuffart
1603 1a2be799 Florent Chuffart
    /**
1604 1a2be799 Florent Chuffart
     * Returns original variables HTML code for use in forms or links.
1605 1a2be799 Florent Chuffart
     *
1606 1a2be799 Florent Chuffart
     * @param   mixed   $origvars       string or array of original varaibles
1607 1a2be799 Florent Chuffart
     * @param   string  $method         type of method ("POST" or "GET")
1608 1a2be799 Florent Chuffart
     * @param   mixed   $default_value  default value of variables
1609 1a2be799 Florent Chuffart
     *                                  if null, empty values will be skipped
1610 1a2be799 Florent Chuffart
     * @return                          get HTML code of original varaibles
1611 1a2be799 Florent Chuffart
     */
1612 1a2be799 Florent Chuffart
    function get_origvars_html($origvars, $method = 'post', $default_value = '') /* {{{ */
1613 1a2be799 Florent Chuffart
    {
1614 1a2be799 Florent Chuffart
        $ret    = '';
1615 1a2be799 Florent Chuffart
        $method = strtoupper($method);
1616 1a2be799 Florent Chuffart
        if ($method == 'POST') {
1617 1a2be799 Florent Chuffart
            if (! is_array($origvars)) {
1618 1a2be799 Florent Chuffart
                $new_origvars = array();
1619 1a2be799 Florent Chuffart
                foreach (explode('&', $origvars) as $param) {
1620 1a2be799 Florent Chuffart
                    $parts = explode('=', $param, 2);
1621 1a2be799 Florent Chuffart
                    if (! isset($parts[1])) {
1622 1a2be799 Florent Chuffart
                        $parts[1] = $default_value;
1623 1a2be799 Florent Chuffart
                    }
1624 1a2be799 Florent Chuffart
                    if (strlen($parts[0]) <= 0) {
1625 1a2be799 Florent Chuffart
                        continue;
1626 1a2be799 Florent Chuffart
                    }
1627 1a2be799 Florent Chuffart
                    $new_origvars[$parts[0]] = $parts[1];
1628 1a2be799 Florent Chuffart
                }
1629 1a2be799 Florent Chuffart
                $origvars =& $new_origvars;
1630 1a2be799 Florent Chuffart
            }
1631 1a2be799 Florent Chuffart
            foreach ($origvars as $key => $val) {
1632 1a2be799 Florent Chuffart
                if (strlen($val) <= 0 && $default_value === null) {
1633 1a2be799 Florent Chuffart
                    continue;
1634 1a2be799 Florent Chuffart
                }
1635 1a2be799 Florent Chuffart
                $key = rawurldecode($key);
1636 1a2be799 Florent Chuffart
                $val = rawurldecode($val);
1637 1a2be799 Florent Chuffart
                $ret .= $this->htmlHidden($key, $val);
1638 1a2be799 Florent Chuffart
            }
1639 1a2be799 Florent Chuffart
        } else if (! strncmp('GET', $method, 3)) {
1640 1a2be799 Florent Chuffart
            if (! is_array($origvars)) {
1641 1a2be799 Florent Chuffart
                $ret .= $origvars;
1642 1a2be799 Florent Chuffart
            } else {
1643 1a2be799 Florent Chuffart
                foreach ($origvars as $key => $val) {
1644 1a2be799 Florent Chuffart
                    if (strlen($val) <= 0 && $default_value === null) {
1645 1a2be799 Florent Chuffart
                        continue;
1646 1a2be799 Florent Chuffart
                    }
1647 1a2be799 Florent Chuffart
                    $ret == '' || $ret .= '&amp;';
1648 1a2be799 Florent Chuffart
                    $ret .= htmlspecialchars(rawurlencode($key));
1649 1a2be799 Florent Chuffart
                    $ret .= '=';
1650 1a2be799 Florent Chuffart
                    $ret .= htmlspecialchars(rawurlencode($val));
1651 1a2be799 Florent Chuffart
                }
1652 1a2be799 Florent Chuffart
            }
1653 1a2be799 Florent Chuffart
            if ($method[strlen($method) - 1] == '+') {
1654 1a2be799 Florent Chuffart
                $ret = "?$ret";
1655 1a2be799 Florent Chuffart
            }
1656 1a2be799 Florent Chuffart
        } else {
1657 1a2be799 Florent Chuffart
            trigger_error('Unsupported Platon::get_origvars_html() method: '
1658 1a2be799 Florent Chuffart
                    .$method, E_USER_ERROR);
1659 1a2be799 Florent Chuffart
        }
1660 1a2be799 Florent Chuffart
        return $ret;
1661 1a2be799 Florent Chuffart
    } /* }}} */
1662 1a2be799 Florent Chuffart
1663 1a2be799 Florent Chuffart
        function get_sfn_cgi_vars($alternative_sfn = null) /* {{{ */
1664 1a2be799 Florent Chuffart
        {
1665 1a2be799 Florent Chuffart
                if ($alternative_sfn === null) { // FAST! (cached return value)
1666 1a2be799 Florent Chuffart
                        static $ret = null;
1667 1a2be799 Florent Chuffart
                        $ret == null && $ret = $this->get_sfn_cgi_vars($this->sfn);
1668 1a2be799 Florent Chuffart
                        return $ret;
1669 1a2be799 Florent Chuffart
                }
1670 1a2be799 Florent Chuffart
                $ret = '';
1671 1a2be799 Florent Chuffart
                $i   = 0;
1672 1a2be799 Florent Chuffart
                foreach ($alternative_sfn as $val) {
1673 1a2be799 Florent Chuffart
                        $ret != '' && $ret .= '&';
1674 1a2be799 Florent Chuffart
                        $ret .= rawurlencode($this->cgi['prefix']['sys'].'sfn')."[$i]=".rawurlencode($val);
1675 1a2be799 Florent Chuffart
                        $i++;
1676 1a2be799 Florent Chuffart
                }
1677 1a2be799 Florent Chuffart
                return $ret;
1678 1a2be799 Florent Chuffart
        } /* }}} */
1679 1a2be799 Florent Chuffart
1680 1a2be799 Florent Chuffart
        function get_default_cgi_prefix($type) /* {{{ */
1681 1a2be799 Florent Chuffart
        {
1682 1a2be799 Florent Chuffart
                switch ($type) {
1683 1a2be799 Florent Chuffart
                        case 'operation':        return 'PME_op_';
1684 1a2be799 Florent Chuffart
                        case 'sys':                        return 'PME_sys_';
1685 1a2be799 Florent Chuffart
                        case 'data':                return 'PME_data_';
1686 1a2be799 Florent Chuffart
                }
1687 1a2be799 Florent Chuffart
                return '';
1688 1a2be799 Florent Chuffart
        } /* }}} */
1689 1a2be799 Florent Chuffart
1690 1a2be799 Florent Chuffart
        function get_sys_cgi_var($name, $default_value = null) /* {{{ */
1691 1a2be799 Florent Chuffart
        {
1692 1a2be799 Florent Chuffart
                if (isset($this)) {
1693 1a2be799 Florent Chuffart
                        return $this->get_cgi_var($this->cgi['prefix']['sys'].$name, $default_value);
1694 1a2be799 Florent Chuffart
                }
1695 1a2be799 Florent Chuffart
                return phpMyEdit::get_cgi_var(phpMyEdit::get_default_cgi_prefix('sys').$name, $default_value);
1696 1a2be799 Florent Chuffart
        } /* }}} */
1697 1a2be799 Florent Chuffart
1698 1a2be799 Florent Chuffart
        function get_data_cgi_var($name, $default_value = null) /* {{{ */
1699 1a2be799 Florent Chuffart
        {
1700 1a2be799 Florent Chuffart
                if (isset($this)) {
1701 1a2be799 Florent Chuffart
                        return $this->get_cgi_var($this->cgi['prefix']['data'].$name, $default_value);
1702 1a2be799 Florent Chuffart
                }
1703 1a2be799 Florent Chuffart
                return phpMyEdit::get_cgi_var(phpMyEdit::get_default_cgi_prefix('data').$name, $default_value);
1704 1a2be799 Florent Chuffart
        } /* }}} */
1705 1a2be799 Florent Chuffart
1706 1a2be799 Florent Chuffart
    function get_cgi_var($name, $default_value = null) /* {{{ */
1707 1a2be799 Florent Chuffart
    {
1708 1a2be799 Florent Chuffart
                if (isset($this) && isset($this->cgi['overwrite'][$name])) {
1709 1a2be799 Florent Chuffart
                        return $this->cgi['overwrite'][$name];
1710 1a2be799 Florent Chuffart
                }
1711 1a2be799 Florent Chuffart
1712 1a2be799 Florent Chuffart
        static $magic_quotes_gpc = null;
1713 1a2be799 Florent Chuffart
        if ($magic_quotes_gpc === null) {
1714 1a2be799 Florent Chuffart
            $magic_quotes_gpc = get_magic_quotes_gpc();
1715 1a2be799 Florent Chuffart
        }
1716 1a2be799 Florent Chuffart
        $var = @$_GET[$name];
1717 1a2be799 Florent Chuffart
        if (! isset($var)) {
1718 1a2be799 Florent Chuffart
            $var = @$_POST[$name];
1719 1a2be799 Florent Chuffart
        }
1720 1a2be799 Florent Chuffart
        if (isset($var)) {
1721 1a2be799 Florent Chuffart
            if ($magic_quotes_gpc) {
1722 1a2be799 Florent Chuffart
                if (is_array($var)) {
1723 1a2be799 Florent Chuffart
                    foreach (array_keys($var) as $key) {
1724 1a2be799 Florent Chuffart
                        $var[$key] = stripslashes($var[$key]);
1725 1a2be799 Florent Chuffart
                    }
1726 1a2be799 Florent Chuffart
                } else {
1727 1a2be799 Florent Chuffart
                    $var = stripslashes($var);
1728 1a2be799 Florent Chuffart
                }
1729 1a2be799 Florent Chuffart
            }
1730 1a2be799 Florent Chuffart
        } else {
1731 1a2be799 Florent Chuffart
            $var = @$default_value;
1732 1a2be799 Florent Chuffart
        }
1733 1a2be799 Florent Chuffart
                if (isset($this) && $var === null && isset($this->cgi['append'][$name])) {
1734 1a2be799 Florent Chuffart
                        return $this->cgi['append'][$name];
1735 1a2be799 Florent Chuffart
                }
1736 1a2be799 Florent Chuffart
        return $var;
1737 1a2be799 Florent Chuffart
    } /* }}} */
1738 1a2be799 Florent Chuffart
1739 1a2be799 Florent Chuffart
        function get_server_var($name) /* {{{ */
1740 1a2be799 Florent Chuffart
        {
1741 1a2be799 Florent Chuffart
                if (isset($_SERVER[$name])) {
1742 1a2be799 Florent Chuffart
                        return $_SERVER[$name];
1743 1a2be799 Florent Chuffart
                }
1744 1a2be799 Florent Chuffart
                global $HTTP_SERVER_VARS;
1745 1a2be799 Florent Chuffart
                if (isset($HTTP_SERVER_VARS[$name])) {
1746 1a2be799 Florent Chuffart
                        return $HTTP_SERVER_VARS[$name];
1747 1a2be799 Florent Chuffart
                }
1748 1a2be799 Florent Chuffart
                global $$name;
1749 1a2be799 Florent Chuffart
                if (isset($$name)) {
1750 1a2be799 Florent Chuffart
                        return $$name;
1751 1a2be799 Florent Chuffart
                }
1752 1a2be799 Florent Chuffart
                return null;
1753 1a2be799 Florent Chuffart
        } /* }}} */
1754 1a2be799 Florent Chuffart
1755 1a2be799 Florent Chuffart
        /*
1756 1a2be799 Florent Chuffart
         * Debug functions
1757 1a2be799 Florent Chuffart
         */
1758 1a2be799 Florent Chuffart
1759 1a2be799 Florent Chuffart
        function print_get_vars ($miss = 'No GET variables found') // debug only /* {{{ */
1760 1a2be799 Florent Chuffart
        {
1761 1a2be799 Florent Chuffart
                // we parse form GET variables
1762 1a2be799 Florent Chuffart
                if (is_array($_GET)) {
1763 1a2be799 Florent Chuffart
                        echo "<p> Variables per GET ";
1764 1a2be799 Florent Chuffart
                        foreach ($_GET as $k => $v) {
1765 1a2be799 Florent Chuffart
                                if (is_array($v)) {
1766 1a2be799 Florent Chuffart
                                        foreach ($v as $akey => $aval) {
1767 1a2be799 Florent Chuffart
                                                // $_GET[$k][$akey] = strip_tags($aval);
1768 1a2be799 Florent Chuffart
                                                // $$k[$akey] = strip_tags($aval);
1769 1a2be799 Florent Chuffart
                                                echo "$k\[$akey\]=$aval   ";
1770 1a2be799 Florent Chuffart
                                        }
1771 1a2be799 Florent Chuffart
                                } else {
1772 1a2be799 Florent Chuffart
                                        // $_GET[$k] = strip_tags($val);
1773 1a2be799 Florent Chuffart
                                        // $$k = strip_tags($val);
1774 1a2be799 Florent Chuffart
                                        echo "$k=$v   ";
1775 1a2be799 Florent Chuffart
                                }
1776 1a2be799 Florent Chuffart
                        }
1777 1a2be799 Florent Chuffart
                        echo '</p>';
1778 1a2be799 Florent Chuffart
                } else {
1779 1a2be799 Florent Chuffart
                        echo '<p>';
1780 1a2be799 Florent Chuffart
                        echo $miss;
1781 1a2be799 Florent Chuffart
                        echo '</p>';
1782 1a2be799 Florent Chuffart
                }
1783 1a2be799 Florent Chuffart
        } /* }}} */
1784 1a2be799 Florent Chuffart
1785 1a2be799 Florent Chuffart
        function print_post_vars($miss = 'No POST variables found')  // debug only /* {{{ */
1786 1a2be799 Florent Chuffart
        {
1787 1a2be799 Florent Chuffart
                global $_POST;
1788 1a2be799 Florent Chuffart
                // we parse form POST variables
1789 1a2be799 Florent Chuffart
                if (is_array($_POST)) {
1790 1a2be799 Florent Chuffart
                        echo "<p>Variables per POST ";
1791 1a2be799 Florent Chuffart
                        foreach ($_POST as $k => $v) {
1792 1a2be799 Florent Chuffart
                                if (is_array($v)) {
1793 1a2be799 Florent Chuffart
                                        foreach ($v as $akey => $aval) {
1794 1a2be799 Florent Chuffart
                                                // $_POST[$k][$akey] = strip_tags($aval);
1795 1a2be799 Florent Chuffart
                                                // $$k[$akey] = strip_tags($aval);
1796 1a2be799 Florent Chuffart
                                                echo "$k\[$akey\]=$aval   ";
1797 1a2be799 Florent Chuffart
                                        }
1798 1a2be799 Florent Chuffart
                                } else {
1799 1a2be799 Florent Chuffart
                                        // $_POST[$k] = strip_tags($val);
1800 1a2be799 Florent Chuffart
                                        // $$k = strip_tags($val);
1801 1a2be799 Florent Chuffart
                                        echo "$k=$v   ";
1802 1a2be799 Florent Chuffart
                                }
1803 1a2be799 Florent Chuffart
                        }
1804 1a2be799 Florent Chuffart
                        echo '</p>';
1805 1a2be799 Florent Chuffart
                } else {
1806 1a2be799 Florent Chuffart
                        echo '<p>';
1807 1a2be799 Florent Chuffart
                        echo $miss;
1808 1a2be799 Florent Chuffart
                        echo '</p>';
1809 1a2be799 Florent Chuffart
                }
1810 1a2be799 Florent Chuffart
        } /* }}} */
1811 1a2be799 Florent Chuffart
1812 1a2be799 Florent Chuffart
        function print_vars ($miss = 'Current instance variables')  // debug only /* {{{ */
1813 1a2be799 Florent Chuffart
        {
1814 1a2be799 Florent Chuffart
                echo "$miss   ";
1815 1a2be799 Florent Chuffart
                echo 'page_name=',$this->page_name,'   ';
1816 1a2be799 Florent Chuffart
                echo 'hn=',$this->hn,'   ';
1817 1a2be799 Florent Chuffart
                echo 'un=',$this->un,'   ';
1818 1a2be799 Florent Chuffart
                echo 'pw=',$this->pw,'   ';
1819 1a2be799 Florent Chuffart
                echo 'db=',$this->db,'   ';
1820 1a2be799 Florent Chuffart
                echo 'dbp=',$this->dbp,'   ';
1821 1a2be799 Florent Chuffart
                echo 'dbh=',$this->dbh,'   ';
1822 1a2be799 Florent Chuffart
                echo 'tb=',$this->tb,'   ';
1823 1a2be799 Florent Chuffart
                echo 'key=',$this->key,'   ';
1824 1a2be799 Florent Chuffart
                echo 'key_type=',$this->key_type,'   ';
1825 1a2be799 Florent Chuffart
                echo 'inc=',$this->inc,'   ';
1826 1a2be799 Florent Chuffart
                echo 'options=',$this->options,'   ';
1827 1a2be799 Florent Chuffart
                echo 'fdd=',$this->fdd,'   ';
1828 1a2be799 Florent Chuffart
                echo 'fl=',$this->fl,'   ';
1829 1a2be799 Florent Chuffart
                echo 'fm=',$this->fm,'   ';
1830 1a2be799 Florent Chuffart
                echo 'sfn=',htmlspecialchars($this->get_sfn_cgi_vars()),'   ';
1831 1a2be799 Florent Chuffart
                echo 'qfn=',$this->qfn,'   ';
1832 1a2be799 Florent Chuffart
                echo 'sw=',$this->sw,'   ';
1833 1a2be799 Florent Chuffart
                echo 'rec=',$this->rec,'   ';
1834 1a2be799 Florent Chuffart
                echo 'navop=',$this->navop,'   ';
1835 1a2be799 Florent Chuffart
                echo 'saveadd=',$this->saveadd,'   ';
1836 1a2be799 Florent Chuffart
                echo 'moreadd=',$this->moreadd,'   ';
1837 1a2be799 Florent Chuffart
                echo 'canceladd=',$this->canceladd,'   ';
1838 1a2be799 Florent Chuffart
                echo 'savechange=',$this->savechange,'   ';
1839 1a2be799 Florent Chuffart
                echo 'morechange=',$this->morechange,'   ';
1840 1a2be799 Florent Chuffart
                echo 'cancelchange=',$this->cancelchange,'   ';
1841 1a2be799 Florent Chuffart
                echo 'savecopy=',$this->savecopy,'   ';
1842 1a2be799 Florent Chuffart
                echo 'cancelcopy=',$this->cancelcopy,'   ';
1843 1a2be799 Florent Chuffart
                echo 'savedelete=',$this->savedelete,'   ';
1844 1a2be799 Florent Chuffart
                echo 'canceldelete=',$this->canceldelete,'   ';
1845 1a2be799 Florent Chuffart
                echo 'cancelview=',$this->cancelview,'   ';
1846 1a2be799 Florent Chuffart
                echo 'operation=',$this->operation,'   ';
1847 1a2be799 Florent Chuffart
                echo "\n";
1848 1a2be799 Florent Chuffart
        } /* }}} */
1849 1a2be799 Florent Chuffart
1850 1a2be799 Florent Chuffart
        /*
1851 1a2be799 Florent Chuffart
         * Display buttons at top and bottom of page
1852 1a2be799 Florent Chuffart
         */
1853 1a2be799 Florent Chuffart
        function display_list_table_buttons($position, $listall = false) /* {{{ */
1854 1a2be799 Florent Chuffart
        {
1855 1a2be799 Florent Chuffart
                if (($but_str = $this->display_buttons($position)) === null)
1856 1a2be799 Florent Chuffart
                        return;
1857 1a2be799 Florent Chuffart
                if($position == 'down') echo '<hr size="1" class="'.$this->getCSSclass('hr', 'down').'" />'."\n";
1858 1a2be799 Florent Chuffart
                echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n";
1859 1a2be799 Florent Chuffart
                echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
1860 1a2be799 Florent Chuffart
                echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
1861 1a2be799 Florent Chuffart
                echo $but_str,'</td>',"\n";
1862 1a2be799 Florent Chuffart
                // Message is now written here
1863 1a2be799 Florent Chuffart
                if (strlen(@$this->message) > 0) {
1864 1a2be799 Florent Chuffart
                        echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
1865 1a2be799 Florent Chuffart
                }
1866 1a2be799 Florent Chuffart
                if($this->display['num_pages'] || $this->display['num_records'])
1867 1a2be799 Florent Chuffart
                        echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n";
1868 1a2be799 Florent Chuffart
                if($this->display['num_pages']) {
1869 1a2be799 Florent Chuffart
                        if ($listall) {
1870 1a2be799 Florent Chuffart
                                echo $this->labels['Page'],':&nbsp;1&nbsp;',$this->labels['of'],'&nbsp;1';
1871 1a2be799 Florent Chuffart
                        } else {
1872 1a2be799 Florent Chuffart
                                $current_page = intval($this->fm / $this->inc) + 1;
1873 1a2be799 Florent Chuffart
                                $total_pages  = max(1, ceil($this->total_recs / abs($this->inc)));
1874 1a2be799 Florent Chuffart
                                echo $this->labels['Page'],':&nbsp;',$current_page;
1875 1a2be799 Florent Chuffart
                                echo '&nbsp;',$this->labels['of'],'&nbsp;',$total_pages;
1876 1a2be799 Florent Chuffart
                        }
1877 1a2be799 Florent Chuffart
                }
1878 1a2be799 Florent Chuffart
                if($this->display['num_records'])
1879 1a2be799 Florent Chuffart
                        echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$this->total_recs;
1880 1a2be799 Florent Chuffart
                if($this->display['num_pages'] || $this->display['num_records']) echo '</td>';
1881 1a2be799 Florent Chuffart
                echo '</tr></table>',"\n";
1882 1a2be799 Florent Chuffart
                if($position == 'up') echo '<hr size="1" class="'.$this->getCSSclass('hr', 'up').'" />'."\n";
1883 1a2be799 Florent Chuffart
        } /* }}} */
1884 1a2be799 Florent Chuffart
1885 1a2be799 Florent Chuffart
        /*
1886 1a2be799 Florent Chuffart
         * Display buttons at top and bottom of page
1887 1a2be799 Florent Chuffart
         */
1888 1a2be799 Florent Chuffart
        function display_record_buttons($position) /* {{{ */
1889 1a2be799 Florent Chuffart
        {
1890 1a2be799 Florent Chuffart
                if (($but_str = $this->display_buttons($position)) === null)
1891 1a2be799 Florent Chuffart
                        return;
1892 1a2be799 Florent Chuffart
                if ($position == 'down') {
1893 1a2be799 Florent Chuffart
                        if ($this->tabs_enabled()) $this->display_tab_labels('down');
1894 1a2be799 Florent Chuffart
                        echo '<hr size="1" class="',$this->getCSSclass('hr', 'down'),'" />',"\n";
1895 1a2be799 Florent Chuffart
                }
1896 1a2be799 Florent Chuffart
                echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n";
1897 1a2be799 Florent Chuffart
                echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
1898 1a2be799 Florent Chuffart
                echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
1899 1a2be799 Florent Chuffart
                echo $but_str,'</td>',"\n";
1900 1a2be799 Florent Chuffart
                // Message is now written here
1901 1a2be799 Florent Chuffart
                //echo '</td>',"\n";
1902 1a2be799 Florent Chuffart
                if (strlen(@$this->message) > 0) {
1903 1a2be799 Florent Chuffart
                        echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
1904 1a2be799 Florent Chuffart
                }
1905 1a2be799 Florent Chuffart
                echo '</tr></table>',"\n";
1906 1a2be799 Florent Chuffart
                if ($position == 'up') {
1907 1a2be799 Florent Chuffart
                        if ($this->tabs_enabled()) $this->display_tab_labels('up');
1908 1a2be799 Florent Chuffart
                        echo '<hr size="1" class="',$this->getCSSclass('hr', 'up'),'" />',"\n";
1909 1a2be799 Florent Chuffart
                }
1910 1a2be799 Florent Chuffart
        } /* }}} */
1911 1a2be799 Florent Chuffart
1912 1a2be799 Florent Chuffart
        function display_buttons($position) /* {{{ */
1913 1a2be799 Florent Chuffart
        {
1914 1a2be799 Florent Chuffart
                $nav_fnc = 'nav_'.$position;
1915 1a2be799 Florent Chuffart
                if(! $this->$nav_fnc())
1916 1a2be799 Florent Chuffart
                        return;
1917 1a2be799 Florent Chuffart
                $buttons = (is_array($this->buttons[$this->page_type][$position]))
1918 1a2be799 Florent Chuffart
                        ? $this->buttons[$this->page_type][$position]
1919 1a2be799 Florent Chuffart
                        : $this->default_buttons[$this->page_type];
1920 1a2be799 Florent Chuffart
                foreach ($buttons as $name) {
1921 1a2be799 Florent Chuffart
                        $ret .= $this->display_button($name, $position)."\n";
1922 1a2be799 Florent Chuffart
                }
1923 1a2be799 Florent Chuffart
                return $ret;
1924 1a2be799 Florent Chuffart
        } /* }}} */
1925 1a2be799 Florent Chuffart
1926 1a2be799 Florent Chuffart
        function display_button($name, $position = 'up') /* {{{ */
1927 1a2be799 Florent Chuffart
        {
1928 1a2be799 Florent Chuffart
                if (is_array($name)) {
1929 1a2be799 Florent Chuffart
                        if (isset($name['code'])) return $name['code'];
1930 1a2be799 Florent Chuffart
                        return $this->htmlSubmit($name['name'], $name['value'], $name['css'], $name['js_validation'], $name['disabled'], $name['js']);
1931 1a2be799 Florent Chuffart
                }
1932 1a2be799 Florent Chuffart
                $disabled = 1; // show disabled by default
1933 1a2be799 Florent Chuffart
                if ($name[0] == '+') { $name = substr($name, 1); $disabled =  0; } // always show disabled as enabled
1934 1a2be799 Florent Chuffart
                if ($name[0] == '-') { $name = substr($name, 1); $disabled = -1; } // don't show disabled
1935 1a2be799 Florent Chuffart
                if ($name == 'cancel') {
1936 1a2be799 Florent Chuffart
                        return $this->htmlSubmit('cancel'.$this->page_types[$this->page_type], 'Cancel',
1937 1a2be799 Florent Chuffart
                                        $this->getCSSclass('cancel', $position), false);
1938 1a2be799 Florent Chuffart
                }
1939 1a2be799 Florent Chuffart
                if (in_array($name, array('add','view','change','copy','delete'))) {
1940 1a2be799 Florent Chuffart
                        $enabled_fnc = $name.'_enabled';
1941 1a2be799 Florent Chuffart
                        $enabled     = $this->$enabled_fnc();
1942 1a2be799 Florent Chuffart
                        if ($name != 'add' && ! $this->total_recs && strstr('LF', $this->page_type))
1943 1a2be799 Florent Chuffart
                                $enabled = false;
1944 1a2be799 Florent Chuffart
                        return $this->htmlSubmit('operation', ucfirst($name),
1945 1a2be799 Florent Chuffart
                                        $this->getCSSclass($name, $position), false, $enabled ? 0 : $disabled);
1946 1a2be799 Florent Chuffart
                }
1947 1a2be799 Florent Chuffart
                if ($name == 'savedelete') {
1948 1a2be799 Florent Chuffart
                        $enabled     = $this->delete_enabled();
1949 1a2be799 Florent Chuffart
                        $js = 'onclick="return confirm(\''.$this->labels['Delete'].' ?\');"';
1950 1a2be799 Florent Chuffart
                        return $this->htmlSubmit('savedelete', 'Delete',
1951 1a2be799 Florent Chuffart
                                        $this->getCSSclass('save', $position), false, $enabled ? 0 : $disabled, $js);
1952 1a2be799 Florent Chuffart
                }
1953 1a2be799 Florent Chuffart
                if (in_array($name, array('save','more'))) {
1954 1a2be799 Florent Chuffart
                        $validation = true; // if js validation
1955 1a2be799 Florent Chuffart
                        if     ($this->page_type == 'D' && $name == 'save' ) { $value = 'Delete'; $validation = false; }
1956 1a2be799 Florent Chuffart
                        elseif ($this->page_type == 'C' && $name == 'more' ) { $value = 'Apply'; }
1957 1a2be799 Florent Chuffart
                        else $value = ucfirst($name);
1958 1a2be799 Florent Chuffart
                        return $this->htmlSubmit($name.$this->page_types[$this->page_type], $value,
1959 1a2be799 Florent Chuffart
                                        $this->getCSSclass($name, $position), $validation);
1960 1a2be799 Florent Chuffart
                }
1961 1a2be799 Florent Chuffart
                $listall = $this->inc <= 0;
1962 1a2be799 Florent Chuffart
                if ($listall) {
1963 1a2be799 Florent Chuffart
                        $disabledprev = true;
1964 1a2be799 Florent Chuffart
                        $disablednext = true;
1965 1a2be799 Florent Chuffart
                        $total_pages  = 1;
1966 1a2be799 Florent Chuffart
                        $current_page = 1;
1967 1a2be799 Florent Chuffart
                } else {
1968 1a2be799 Florent Chuffart
                        $disabledprev = $this->fm <= 0;
1969 1a2be799 Florent Chuffart
                        $disablednext =  $this->fm + $this->inc >= $this->total_recs;
1970 1a2be799 Florent Chuffart
                        $total_pages  = max(1, ceil($this->total_recs / abs($this->inc)));
1971 1a2be799 Florent Chuffart
                        $current_page = ceil($this->fm / abs($this->inc)); // must + 1
1972 1a2be799 Florent Chuffart
                }
1973 1a2be799 Florent Chuffart
                $disabledfirst = $disabledprev;
1974 1a2be799 Florent Chuffart
                $disabledlast  = $disablednext;
1975 1a2be799 Florent Chuffart
                // some statistics first
1976 1a2be799 Florent Chuffart
                if ($name == 'total_pages') return $total_pages;
1977 1a2be799 Florent Chuffart
                if ($name == 'current_page') return ($current_page+1);
1978 1a2be799 Florent Chuffart
                if ($name == 'total_recs') return ($this->total_recs);
1979 1a2be799 Florent Chuffart
                // now some goto buttons/dropdowns/inputs...
1980 1a2be799 Florent Chuffart
                if ($name == 'goto_text') {
1981 1a2be799 Florent Chuffart
                        $ret = '<input type="text" class="'.$this->getCSSclass('gotopn', $position).'"';
1982 1a2be799 Florent Chuffart
                        $ret .= ' name="'.$this->cgi['prefix']['sys'].'navpn'.$position.'" value="'.($current_page+1).'"';
1983 1a2be799 Florent Chuffart
                        $ret .= ' size="'.(strlen($total_pages)+1).'" maxlength="'.(strlen($total_pages)+1).'"';
1984 1a2be799 Florent Chuffart
                        // TODO some js here.... on enter submit, on click erase ?...
1985 1a2be799 Florent Chuffart
                        $ret .=' oneypress="return PE_filter_handler(this.form, event);" />';
1986 1a2be799 Florent Chuffart
                        return $ret;
1987 1a2be799 Florent Chuffart
                }
1988 1a2be799 Florent Chuffart
                if ($name == 'goto_combo') {
1989 1a2be799 Florent Chuffart
                        $disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
1990 1a2be799 Florent Chuffart
                        if ($disablegoto != '' && $disabled < 0) return;
1991 1a2be799 Florent Chuffart
                        $kv_array = array();
1992 1a2be799 Florent Chuffart
                        for ($i = 0; $i < $total_pages; $i++) {
1993 1a2be799 Florent Chuffart
                                $kv_array[$this->inc * $i] = $i + 1;
1994 1a2be799 Florent Chuffart
                        }
1995 1a2be799 Florent Chuffart
                        // TODO: add onchange="return this.form.submit();" DONE ???
1996 1a2be799 Florent Chuffart
                        return $this->htmlSelect($this->cgi['prefix']['sys'].ltrim($disabledgoto).'navfm'.$position,
1997 1a2be799 Florent Chuffart
                                        $this->getCSSclass('goto', $position), $kv_array, (string)$this->fm, false, $disabledgoto,
1998 1a2be799 Florent Chuffart
                                        false, true, 'onchange="return this.form.submit();"');
1999 1a2be799 Florent Chuffart
                }
2000 1a2be799 Florent Chuffart
                if ($name == 'goto') {
2001 1a2be799 Florent Chuffart
                        return $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $position),
2002 1a2be799 Florent Chuffart
                                        false, ($listall || ($disablednext && $disabledprev)) ? $disabled : 0);
2003 1a2be799 Florent Chuffart
                }
2004 1a2be799 Florent Chuffart
                if (in_array($name, array('first','prev','next','last','<<','<','>','>>'))) {
2005 1a2be799 Florent Chuffart
                        $disabled_var = 'disabled'.$name;
2006 1a2be799 Florent Chuffart
                        $name2 = $name;
2007 1a2be799 Florent Chuffart
                        if (strlen($name) <= 2) {
2008 1a2be799 Florent Chuffart
                                $nav_values = array('<<' => 'first', '<' => 'prev', '>' => 'next', '>>' => 'last');
2009 1a2be799 Florent Chuffart
                                $disabled_var = 'disabled'.$nav_values[$name];
2010 1a2be799 Florent Chuffart
                                $name2 = $nav_values[$name];
2011 1a2be799 Florent Chuffart
                        }
2012 1a2be799 Florent Chuffart
                        return $this->htmlSubmit('navop', ucfirst($name),
2013 1a2be799 Florent Chuffart
                                        $this->getCSSclass($name2, $position), false, $$disabled_var ? $disabled : 0);
2014 1a2be799 Florent Chuffart
                }
2015 1a2be799 Florent Chuffart
                if(isset($this->labels[$name])) return $this->labels[$name];
2016 1a2be799 Florent Chuffart
                return $name;
2017 1a2be799 Florent Chuffart
        } /* }}} */
2018 1a2be799 Florent Chuffart
2019 1a2be799 Florent Chuffart
        function number_of_recs() /* {{{ */
2020 1a2be799 Florent Chuffart
        {
2021 1a2be799 Florent Chuffart
                $count_parts = array(
2022 1a2be799 Florent Chuffart
                                'type'   => 'select',
2023 1a2be799 Florent Chuffart
                                'select' => 'count(*)',
2024 1a2be799 Florent Chuffart
                                'from'   => $this->get_SQL_join_clause(),
2025 1a2be799 Florent Chuffart
                                'where'  => $this->get_SQL_where_from_query_opts());
2026 1a2be799 Florent Chuffart
                $res = $this->myquery($this->get_SQL_main_list_query($count_parts), __LINE__);
2027 1a2be799 Florent Chuffart
                $row = $this->sql_fetch($res, 'n');
2028 1a2be799 Florent Chuffart
                $this->total_recs = $row[0];
2029 1a2be799 Florent Chuffart
        } /* }}} */
2030 1a2be799 Florent Chuffart
2031 1a2be799 Florent Chuffart
        /*
2032 1a2be799 Florent Chuffart
         * Table Page Listing
2033 1a2be799 Florent Chuffart
         */
2034 1a2be799 Florent Chuffart
        function list_table() /* {{{ */
2035 1a2be799 Florent Chuffart
        {
2036 1a2be799 Florent Chuffart
                if ($this->fm == '') {
2037 1a2be799 Florent Chuffart
                        $this->fm = 0;
2038 1a2be799 Florent Chuffart
                }
2039 1a2be799 Florent Chuffart
                $this->fm = $this->navfm;
2040 1a2be799 Florent Chuffart
                if ($this->prev_operation()) {
2041 1a2be799 Florent Chuffart
                        $this->fm = $this->fm - $this->inc;
2042 1a2be799 Florent Chuffart
                        if ($this->fm < 0) {
2043 1a2be799 Florent Chuffart
                                $this->fm = 0;
2044 1a2be799 Florent Chuffart
                        }
2045 1a2be799 Florent Chuffart
                }
2046 1a2be799 Florent Chuffart
                if ($this->first_operation()) {
2047 1a2be799 Florent Chuffart
                        $this->fm = 0;
2048 1a2be799 Florent Chuffart
                } // last operation must be performed below, after retrieving total_recs
2049 1a2be799 Florent Chuffart
                if ($this->next_operation()) {
2050 1a2be799 Florent Chuffart
                        $this->fm += $this->inc;
2051 1a2be799 Florent Chuffart
                }
2052 1a2be799 Florent Chuffart
                $this->number_of_recs();
2053 1a2be799 Florent Chuffart
                if ($this->last_operation() || $this->fm > $this->total_recs) { // if goto_text is badly set
2054 1a2be799 Florent Chuffart
                        $this->fm = (int)(($this->total_recs - 1)/$this->inc)*$this->inc;
2055 1a2be799 Florent Chuffart
                }
2056 1a2be799 Florent Chuffart
                // If sort sequence has changed, restart listing
2057 1a2be799 Florent Chuffart
                $this->qfn != $this->prev_qfn && $this->fm = 0;
2058 1a2be799 Florent Chuffart
                if (0) { // DEBUG
2059 1a2be799 Florent Chuffart
                        echo 'qfn vs. prev_qfn comparsion ';
2060 1a2be799 Florent Chuffart
                        echo '[<b>',htmlspecialchars($this->qfn),'</b>]';
2061 1a2be799 Florent Chuffart
                        echo '[<b>',htmlspecialchars($this->prev_qfn),'</b>]<br />';
2062 1a2be799 Florent Chuffart
                        echo 'comparsion <u>',($this->qfn == $this->prev_qfn ? 'proved' : 'failed'),'</u>';
2063 1a2be799 Florent Chuffart
                        echo '<hr size="1" />';
2064 1a2be799 Florent Chuffart
                }
2065 1a2be799 Florent Chuffart
                /*
2066 1a2be799 Florent Chuffart
                 * If user is allowed to Change/Delete records, we need an extra column
2067 1a2be799 Florent Chuffart
                 * to allow users to select a record
2068 1a2be799 Florent Chuffart
                 */
2069 1a2be799 Florent Chuffart
                $select_recs = $this->key != '' &&
2070 1a2be799 Florent Chuffart
                        ($this->change_enabled() || $this->delete_enabled() || $this->view_enabled());
2071 1a2be799 Florent Chuffart
                // Are we doing a listall?
2072 1a2be799 Florent Chuffart
                $listall = $this->inc <= 0;
2073 1a2be799 Florent Chuffart
                /*
2074 1a2be799 Florent Chuffart
                 * Display the SQL table in an HTML table
2075 1a2be799 Florent Chuffart
                 */
2076 1a2be799 Florent Chuffart
                $this->form_begin();
2077 1a2be799 Florent Chuffart
                echo $this->get_origvars_html($this->get_sfn_cgi_vars());
2078 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('fl', $this->fl);
2079 1a2be799 Florent Chuffart
                // Display buttons at top and/or bottom of page.
2080 1a2be799 Florent Chuffart
                $this->display_list_table_buttons('up', $listall);
2081 1a2be799 Florent Chuffart
                if ($this->cgi['persist'] != '') {
2082 1a2be799 Florent Chuffart
                        echo $this->get_origvars_html($this->cgi['persist']);
2083 1a2be799 Florent Chuffart
                }
2084 1a2be799 Florent Chuffart
                if (! $this->filter_operation()) {
2085 1a2be799 Florent Chuffart
                        echo $this->get_origvars_html($this->qfn);
2086 1a2be799 Florent Chuffart
                }
2087 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('qfn', $this->qfn);
2088 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('fm', $this->fm);
2089 1a2be799 Florent Chuffart
                echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
2090 1a2be799 Florent Chuffart
                echo '<tr class="',$this->getCSSclass('header'),'">',"\n";
2091 1a2be799 Florent Chuffart
                /*
2092 1a2be799 Florent Chuffart
                 * System (navigation, selection) columns counting
2093 1a2be799 Florent Chuffart
                 */
2094 1a2be799 Florent Chuffart
                $sys_cols  = 0;
2095 1a2be799 Florent Chuffart
                $sys_cols += intval($this->filter_enabled() || $select_recs);
2096 1a2be799 Florent Chuffart
                if ($sys_cols > 0) {
2097 1a2be799 Florent Chuffart
                        $sys_cols += intval($this->nav_buttons()
2098 1a2be799 Florent Chuffart
                                        && ($this->nav_text_links() || $this->nav_graphic_links()));
2099 1a2be799 Florent Chuffart
                }
2100 1a2be799 Florent Chuffart
                /*
2101 1a2be799 Florent Chuffart
                 * We need an initial column(s) (sys columns)
2102 1a2be799 Florent Chuffart
                 * if we have filters, Changes or Deletes enabled
2103 1a2be799 Florent Chuffart
                 */
2104 1a2be799 Florent Chuffart
                if ($sys_cols) {
2105 1a2be799 Florent Chuffart
                        echo '<th class="',$this->getCSSclass('header'),'" colspan="',$sys_cols,'">';
2106 1a2be799 Florent Chuffart
                        if ($this->filter_enabled()) {
2107 1a2be799 Florent Chuffart
                                if ($this->filter_operation()) {
2108 1a2be799 Florent Chuffart
                                        echo $this->htmlSubmit('sw', 'Hide', $this->getCSSclass('hide'), false);
2109 1a2be799 Florent Chuffart
                                        echo $this->htmlSubmit('sw', 'Clear', $this->getCSSclass('clear'), false);
2110 1a2be799 Florent Chuffart
                                } else {
2111 1a2be799 Florent Chuffart
                                        echo $this->htmlSubmit('sw', 'Search', $this->getCSSclass('search'), false);
2112 1a2be799 Florent Chuffart
                                }
2113 1a2be799 Florent Chuffart
                        } else {
2114 1a2be799 Florent Chuffart
                                echo '&nbsp;';
2115 1a2be799 Florent Chuffart
                        }
2116 1a2be799 Florent Chuffart
                        echo '</th>',"\n";
2117 1a2be799 Florent Chuffart
                }
2118 1a2be799 Florent Chuffart
                for ($k = 0; $k < $this->num_fds; $k++) {
2119 1a2be799 Florent Chuffart
                        $fd = $this->fds[$k];
2120 1a2be799 Florent Chuffart
                        if (! $this->displayed[$k]) {
2121 1a2be799 Florent Chuffart
                                continue;
2122 1a2be799 Florent Chuffart
                        }
2123 1a2be799 Florent Chuffart
                        $css_postfix    = @$this->fdd[$k]['css']['postfix'];
2124 1a2be799 Florent Chuffart
                        $css_class_name = $this->getCSSclass('header', null, null, $css_postfix);
2125 1a2be799 Florent Chuffart
                        $fdn = $this->fdd[$fd]['name'];
2126 1a2be799 Florent Chuffart
                        if (! $this->fdd[$fd]['sort'] || $this->password($fd)) {
2127 1a2be799 Florent Chuffart
                                echo '<th class="',$css_class_name,'">',$fdn,'</th>',"\n";
2128 1a2be799 Florent Chuffart
                        } else {
2129 1a2be799 Florent Chuffart
                                // Clicking on the current sort field reverses the sort order
2130 1a2be799 Florent Chuffart
                                $new_sfn = $this->sfn;
2131 1a2be799 Florent Chuffart
                                array_unshift($new_sfn, in_array("$k", $new_sfn, 1) ? "-$k" : $k);
2132 1a2be799 Florent Chuffart
                                echo '<th class="',$css_class_name,'">';
2133 1a2be799 Florent Chuffart
                                echo '<a class="',$css_class_name,'" href="';
2134 1a2be799 Florent Chuffart
                                echo htmlspecialchars($this->page_name.'?'.$this->cgi['prefix']['sys'].'fm'.'=0'
2135 1a2be799 Florent Chuffart
                                                .'&'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl
2136 1a2be799 Florent Chuffart
                                                .'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn).$this->qfn
2137 1a2be799 Florent Chuffart
                                                .'&'.$this->get_sfn_cgi_vars($new_sfn).$this->cgi['persist']);
2138 1a2be799 Florent Chuffart
                                echo '">',$fdn,'</a></th>',"\n";
2139 1a2be799 Florent Chuffart
                        }
2140 1a2be799 Florent Chuffart
                }
2141 1a2be799 Florent Chuffart
                echo '</tr>',"\n";
2142 1a2be799 Florent Chuffart
2143 1a2be799 Florent Chuffart
                /*
2144 1a2be799 Florent Chuffart
                 * Prepare the SQL Query from the data definition file
2145 1a2be799 Florent Chuffart
                 */
2146 1a2be799 Florent Chuffart
                $qparts['type']   = 'select';
2147 1a2be799 Florent Chuffart
                $qparts['select'] = $this->get_SQL_column_list();
2148 1a2be799 Florent Chuffart
                // Even if the key field isn't displayed, we still need its value
2149 1a2be799 Florent Chuffart
                if ($select_recs) {
2150 1a2be799 Florent Chuffart
                        if (!in_array ($this->key, $this->fds)) {
2151 1a2be799 Florent Chuffart
                                $qparts['select'] .= ','.$this->fqn($this->key);
2152 1a2be799 Florent Chuffart
                        }
2153 1a2be799 Florent Chuffart
                }
2154 1a2be799 Florent Chuffart
                $qparts['from']  = $this->get_SQL_join_clause();
2155 1a2be799 Florent Chuffart
                $qparts['where'] = $this->get_SQL_where_from_query_opts();
2156 1a2be799 Florent Chuffart
                // build up the ORDER BY clause
2157 1a2be799 Florent Chuffart
                if (isset($this->sfn)) {
2158 1a2be799 Florent Chuffart
                        $sort_fields   = array();
2159 1a2be799 Florent Chuffart
                        $sort_fields_w = array();
2160 1a2be799 Florent Chuffart
                        foreach ($this->sfn as $field) {
2161 1a2be799 Florent Chuffart
                                if ($field[0] == '-') {
2162 1a2be799 Florent Chuffart
                                        $field = substr($field, 1);
2163 1a2be799 Florent Chuffart
                                        $desc  = true;
2164 1a2be799 Florent Chuffart
                                } else {
2165 1a2be799 Florent Chuffart
                                        $field = $field;
2166 1a2be799 Florent Chuffart
                                        $desc  = false;
2167 1a2be799 Florent Chuffart
                                }
2168 1a2be799 Florent Chuffart
                                $sort_field   = $this->fqn($field);
2169 1a2be799 Florent Chuffart
                                $sort_field_w = $this->fdd[$field]['name'];
2170 1a2be799 Florent Chuffart
                                $this->col_has_sql($field) && $sort_field_w .= ' (sql)';
2171 1a2be799 Florent Chuffart
                                if ($desc) {
2172 1a2be799 Florent Chuffart
                                        $sort_field   .= ' DESC';
2173 1a2be799 Florent Chuffart
                                        $sort_field_w .= ' '.$this->labels['descending'];
2174 1a2be799 Florent Chuffart
                                } else {
2175 1a2be799 Florent Chuffart
                                        $sort_field_w .= ' '.$this->labels['ascending'];
2176 1a2be799 Florent Chuffart
                                }
2177 1a2be799 Florent Chuffart
                                $sort_fields[]   = $sort_field;
2178 1a2be799 Florent Chuffart
                                $sort_fields_w[] = $sort_field_w;
2179 1a2be799 Florent Chuffart
                        }
2180 1a2be799 Florent Chuffart
                        if (count($sort_fields) > 0) {
2181 1a2be799 Florent Chuffart
                                $qparts['orderby'] = join(',', $sort_fields);
2182 1a2be799 Florent Chuffart
                        }
2183 1a2be799 Florent Chuffart
                }
2184 1a2be799 Florent Chuffart
                $qparts['limit'] = $listall ? '' : $this->sql_limit($this->fm,$this->inc);
2185 1a2be799 Florent Chuffart
2186 1a2be799 Florent Chuffart
                /*
2187 1a2be799 Florent Chuffart
                 * Main list_table() query
2188 1a2be799 Florent Chuffart
                 *
2189 1a2be799 Florent Chuffart
                 * Each row of the HTML table is one record from the SQL query. We must
2190 1a2be799 Florent Chuffart
                 * perform this query before filter printing, because we want to use
2191 1a2be799 Florent Chuffart
                 * $this->sql_field_len() function. We will also fetch the first row to get
2192 1a2be799 Florent Chuffart
                 * the field names.
2193 1a2be799 Florent Chuffart
                 */
2194 1a2be799 Florent Chuffart
                $query = $this->get_SQL_main_list_query($qparts);
2195 1a2be799 Florent Chuffart
                $res   = $this->myquery($query, __LINE__);
2196 1a2be799 Florent Chuffart
                if ($res == false) {
2197 1a2be799 Florent Chuffart
                        $this->error('invalid SQL query', $query);
2198 1a2be799 Florent Chuffart
                        return false;
2199 1a2be799 Florent Chuffart
                }
2200 1a2be799 Florent Chuffart
                $row = $this->sql_fetch($res);
2201 1a2be799 Florent Chuffart
2202 1a2be799 Florent Chuffart
                /* FILTER {{{
2203 1a2be799 Florent Chuffart
                 *
2204 1a2be799 Florent Chuffart
                 * Draw the filter and fill it with any data typed in last pass and stored
2205 1a2be799 Florent Chuffart
                 * in the array parameter keyword 'filter'. Prepare the SQL WHERE clause.
2206 1a2be799 Florent Chuffart
                 */
2207 1a2be799 Florent Chuffart
                if ($this->filter_operation()) {
2208 1a2be799 Florent Chuffart
                        // Filter row retrieval
2209 1a2be799 Florent Chuffart
                        $fields     = false;
2210 1a2be799 Florent Chuffart
                        $filter_row = $row;
2211 1a2be799 Florent Chuffart
                        if (! is_array($filter_row)) {
2212 1a2be799 Florent Chuffart
                                unset($qparts['where']);
2213 1a2be799 Florent Chuffart
                                $query = $this->get_SQL_query($qparts);
2214 1a2be799 Florent Chuffart
                                $res   = $this->myquery($query, __LINE__);
2215 1a2be799 Florent Chuffart
                                if ($res == false) {
2216 1a2be799 Florent Chuffart
                                        $this->error('invalid SQL query', $query);
2217 1a2be799 Florent Chuffart
                                        return false;
2218 1a2be799 Florent Chuffart
                                }
2219 1a2be799 Florent Chuffart
                                $filter_row = $this->sql_fetch($res);
2220 1a2be799 Florent Chuffart
                        }
2221 1a2be799 Florent Chuffart
                        /* Variable $fields is used to get index of particular field in
2222 1a2be799 Florent Chuffart
                           result. That index can be passed in example to $this->sql_field_len()
2223 1a2be799 Florent Chuffart
                           function. Use field names as indexes to $fields array. */
2224 1a2be799 Florent Chuffart
                        if (is_array($filter_row)) {
2225 1a2be799 Florent Chuffart
                                $fields = array_flip(array_keys($filter_row));
2226 1a2be799 Florent Chuffart
                        }
2227 1a2be799 Florent Chuffart
                        if ($fields != false) {
2228 1a2be799 Florent Chuffart
                                $css_class_name = $this->getCSSclass('filter');
2229 1a2be799 Florent Chuffart
                                echo '<tr class="',$css_class_name,'">',"\n";
2230 1a2be799 Florent Chuffart
                                echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
2231 1a2be799 Florent Chuffart
                                echo $this->htmlSubmit('filter', 'Query', $this->getCSSclass('query'), false);
2232 1a2be799 Florent Chuffart
                                echo '</td>', "\n";
2233 1a2be799 Florent Chuffart
                                for ($k = 0; $k < $this->num_fds; $k++) {
2234 1a2be799 Florent Chuffart
                                        if (! $this->displayed[$k]) {
2235 1a2be799 Florent Chuffart
                                                continue;
2236 1a2be799 Florent Chuffart
                                        }
2237 1a2be799 Florent Chuffart
                                        $css_postfix      = @$this->fdd[$k]['css']['postfix'];
2238 1a2be799 Florent Chuffart
                                        $css_class_name   = $this->getCSSclass('filter', null, null, $css_postfix);
2239 1a2be799 Florent Chuffart
                                        $this->field_name = $this->fds[$k];
2240 1a2be799 Florent Chuffart
                                        $fd               = $this->field_name;
2241 1a2be799 Florent Chuffart
                                        $this->field      = $this->fdd[$fd];
2242 1a2be799 Florent Chuffart
                                        $l  = 'qf'.$k;
2243 1a2be799 Florent Chuffart
                                        $lc = 'qf'.$k.'_comp';
2244 1a2be799 Florent Chuffart
                                        $li = 'qf'.$k.'_id';
2245 1a2be799 Florent Chuffart
                                        if ($this->clear_operation()) {
2246 1a2be799 Florent Chuffart
                                                $m  = null;
2247 1a2be799 Florent Chuffart
                                                $mc = null;
2248 1a2be799 Florent Chuffart
                                                $mi = null;
2249 1a2be799 Florent Chuffart
                                        } else {
2250 1a2be799 Florent Chuffart
                                                $m  = $this->get_sys_cgi_var($l);
2251 1a2be799 Florent Chuffart
                                                $mc = $this->get_sys_cgi_var($lc);
2252 1a2be799 Florent Chuffart
                                                $mi = $this->get_sys_cgi_var($li);
2253 1a2be799 Florent Chuffart
                                        }
2254 1a2be799 Florent Chuffart
                                        echo '<td class="',$css_class_name,'">';
2255 1a2be799 Florent Chuffart
                                        if ($this->password($k)) {
2256 1a2be799 Florent Chuffart
                                                echo '&nbsp;';
2257 1a2be799 Florent Chuffart
                                        } else if ($this->fdd[$fd]['select'] == 'D' || $this->fdd[$fd]['select'] == 'M') {
2258 1a2be799 Florent Chuffart
                                                // Multiple fields processing
2259 1a2be799 Florent Chuffart
                                                // Default size is 2 and array required for values.
2260 1a2be799 Florent Chuffart
                                                $from_table = ! $this->col_has_values($k) || isset($this->fdd[$k]['values']['table']);
2261 1a2be799 Florent Chuffart
                                                $vals       = $this->set_values($k, array('*' => '*'), null, $from_table);
2262 1a2be799 Florent Chuffart
                                                $selected   = $mi;
2263 1a2be799 Florent Chuffart
                                                $multiple   = $this->col_has_multiple_select($k);
2264 1a2be799 Florent Chuffart
                                                $multiple  |= $this->fdd[$fd]['select'] == 'M';
2265 1a2be799 Florent Chuffart
                                                $readonly   = false;
2266 1a2be799 Florent Chuffart
                                                $strip_tags = true;
2267 1a2be799 Florent Chuffart
                                                $escape     = true;
2268 1a2be799 Florent Chuffart
                                                echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_id', $css_class_name,
2269 1a2be799 Florent Chuffart
                                                                $vals, $selected, $multiple, $readonly, $strip_tags, $escape);
2270 1a2be799 Florent Chuffart
                                        } elseif ($this->fdd[$fd]['select'] == 'N' || $this->fdd[$fd]['select'] == 'T') {
2271 1a2be799 Florent Chuffart
                                                $len_props = '';
2272 1a2be799 Florent Chuffart
                                                $maxlen = intval($this->fdd[$k]['maxlen']);
2273 1a2be799 Florent Chuffart
                                                $maxlen > 0 || $maxlen = intval($this->sql_field_len($res, $fields["qf$k"]));
2274 1a2be799 Florent Chuffart
                                                $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size']
2275 1a2be799 Florent Chuffart
                                                        : ($maxlen < 30 ? min($maxlen, 8) : 12);
2276 1a2be799 Florent Chuffart
                                                $len_props .= ' size="'.$size.'"';
2277 1a2be799 Florent Chuffart
                                                $len_props .= ' maxlength="'.$maxlen.'"';
2278 1a2be799 Florent Chuffart
                                                if ($this->fdd[$fd]['select'] == 'N') {
2279 1a2be799 Florent Chuffart
                                                        $mc = in_array($mc, $this->comp_ops) ? $mc : '=';
2280 1a2be799 Florent Chuffart
                                                        echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_comp',
2281 1a2be799 Florent Chuffart
                                                                        $css_class_name, $this->comp_ops, $mc);
2282 1a2be799 Florent Chuffart
                                                }
2283 1a2be799 Florent Chuffart
                                                echo '<input class="',$css_class_name,'" value="',htmlspecialchars(@$m);
2284 1a2be799 Florent Chuffart
                                                echo '" type="text" name="'.$this->cgi['prefix']['sys'].'qf'.$k.'"',$len_props;
2285 1a2be799 Florent Chuffart
                                                echo ' onkeypress="return '.$this->js['prefix'].'filter_handler(this.form, event);" />';
2286 1a2be799 Florent Chuffart
                                        } else {
2287 1a2be799 Florent Chuffart
                                                echo '&nbsp;';
2288 1a2be799 Florent Chuffart
                                        }
2289 1a2be799 Florent Chuffart
                                        echo '</td>',"\n";
2290 1a2be799 Florent Chuffart
                                }
2291 1a2be799 Florent Chuffart
                                echo '</tr>',"\n";
2292 1a2be799 Florent Chuffart
                        }
2293 1a2be799 Florent Chuffart
                } // }}}
2294 1a2be799 Florent Chuffart
                
2295 1a2be799 Florent Chuffart
                /*
2296 1a2be799 Florent Chuffart
                 * Display sorting sequence
2297 1a2be799 Florent Chuffart
                 */
2298 1a2be799 Florent Chuffart
                if ($qparts['orderby'] && $this->display['sort']) {
2299 1a2be799 Florent Chuffart
                        $css_class_name = $this->getCSSclass('sortinfo');
2300 1a2be799 Florent Chuffart
                        echo '<tr class="',$css_class_name,'">',"\n";
2301 1a2be799 Florent Chuffart
                        echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
2302 1a2be799 Florent Chuffart
                        echo '<a class="',$css_class_name,'" href="';
2303 1a2be799 Florent Chuffart
                        echo htmlspecialchars($this->page_name
2304 1a2be799 Florent Chuffart
                                        .'?'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl
2305 1a2be799 Florent Chuffart
                                        .'&'.$this->cgi['prefix']['sys'].'fm'.'='.$this->fm
2306 1a2be799 Florent Chuffart
                                        .'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn)
2307 1a2be799 Florent Chuffart
                                        .$this->qfn.$this->cgi['persist']);
2308 1a2be799 Florent Chuffart
                        echo '">',$this->labels['Clear'],'</a></td>',"\n";
2309 1a2be799 Florent Chuffart
                        echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">';
2310 1a2be799 Florent Chuffart
                        echo $this->labels['Sorted By'],': ',join(', ', $sort_fields_w),'</td></tr>',"\n";
2311 1a2be799 Florent Chuffart
                }
2312 1a2be799 Florent Chuffart
2313 1a2be799 Florent Chuffart
                /*
2314 1a2be799 Florent Chuffart
                 * Display the current query
2315 1a2be799 Florent Chuffart
                 */
2316 1a2be799 Florent Chuffart
2317 1a2be799 Florent Chuffart
                $text_query = $this->get_SQL_where_from_query_opts(null, true);
2318 1a2be799 Florent Chuffart
                if ($text_query != '' && $this->display['query']) {
2319 1a2be799 Florent Chuffart
                        $css_class_name = $this->getCSSclass('queryinfo');
2320 1a2be799 Florent Chuffart
                        echo '<tr class="',$css_class_name,'">',"\n";
2321 1a2be799 Florent Chuffart
                        echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
2322 1a2be799 Florent Chuffart
                        echo '<a class="',$css_class_name,'" href="';
2323 1a2be799 Florent Chuffart
                        echo htmlspecialchars($this->get_server_var('PHP_SELF')
2324 1a2be799 Florent Chuffart
                                        .'?'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl
2325 1a2be799 Florent Chuffart
                                        .'&'.$this->cgi['prefix']['sys'].'fm'.'='.$this->fm
2326 1a2be799 Florent Chuffart
                                        .'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn)
2327 1a2be799 Florent Chuffart
                                        .'&'.$this->get_sfn_cgi_vars().$this->cgi['persist']);
2328 1a2be799 Florent Chuffart
                        echo '">',$this->labels['Clear'],'</a></td>',"\n";
2329 1a2be799 Florent Chuffart
                        echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">';
2330 1a2be799 Florent Chuffart
                        echo $this->labels['Current Query'],': ',htmlspecialchars($text_query),'</td></tr>',"\n";
2331 1a2be799 Florent Chuffart
                }
2332 1a2be799 Florent Chuffart
2333 1a2be799 Florent Chuffart
                if ($this->nav_text_links() || $this->nav_graphic_links()) {
2334 1a2be799 Florent Chuffart
                        $qstrparts = array();
2335 1a2be799 Florent Chuffart
                        strlen($this->fl)             > 0 && $qstrparts[] = $this->cgi['prefix']['sys'].'fl'.'='.$this->fl;
2336 1a2be799 Florent Chuffart
                        strlen($this->fm)             > 0 && $qstrparts[] = $this->cgi['prefix']['sys'].'fm'.'='.$this->fm;
2337 1a2be799 Florent Chuffart
                        count($this->sfn)             > 0 && $qstrparts[] = $this->get_sfn_cgi_vars();
2338 1a2be799 Florent Chuffart
                        strlen($this->cgi['persist']) > 0 && $qstrparts[] = $this->cgi['persist'];
2339 1a2be799 Florent Chuffart
                        $qpview      = $qstrparts;
2340 1a2be799 Florent Chuffart
                        $qpcopy      = $qstrparts;
2341 1a2be799 Florent Chuffart
                        $qpchange    = $qstrparts;
2342 1a2be799 Florent Chuffart
                        $qpdelete    = $qstrparts;
2343 1a2be799 Florent Chuffart
                        $qp_prefix   = $this->cgi['prefix']['sys'].'operation'.'='.$this->cgi['prefix']['operation'];
2344 1a2be799 Florent Chuffart
                        $qpview[]    = $qp_prefix.'View';
2345 1a2be799 Florent Chuffart
                        $qpcopy[]    = $qp_prefix.'Copy';
2346 1a2be799 Florent Chuffart
                        $qpchange[]  = $qp_prefix.'Change';
2347 1a2be799 Florent Chuffart
                        $qpdelete[]  = $qp_prefix.'Delete';
2348 1a2be799 Florent Chuffart
                        $qpviewStr   = htmlspecialchars($this->page_name.'?'.join('&',$qpview).$this->qfn);
2349 1a2be799 Florent Chuffart
                        $qpcopyStr   = htmlspecialchars($this->page_name.'?'.join('&',$qpcopy).$this->qfn);
2350 1a2be799 Florent Chuffart
                        $qpchangeStr = htmlspecialchars($this->page_name.'?'.join('&',$qpchange).$this->qfn);
2351 1a2be799 Florent Chuffart
                        $qpdeleteStr = htmlspecialchars($this->page_name.'?'.join('&',$qpdelete).$this->qfn);
2352 1a2be799 Florent Chuffart
                }
2353 1a2be799 Florent Chuffart
                $fetched  = true;
2354 1a2be799 Florent Chuffart
                $first    = true;
2355 1a2be799 Florent Chuffart
                $rowCount = 0;
2356 1a2be799 Florent Chuffart
                while ((!$fetched && ($row = $this->sql_fetch($res)) != false)
2357 1a2be799 Florent Chuffart
                                || ($fetched && $row != false)) {
2358 1a2be799 Florent Chuffart
                        $fetched = false;
2359 1a2be799 Florent Chuffart
                        echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n";
2360 1a2be799 Florent Chuffart
                        if ($sys_cols) { /* {{{ */
2361 1a2be799 Florent Chuffart
                                $key_rec     = $row['qf'.$this->key_num];
2362 1a2be799 Florent Chuffart
                                $queryAppend = htmlspecialchars('&'.$this->cgi['prefix']['sys'].'rec'.'='.$key_rec);
2363 1a2be799 Florent Chuffart
                                $viewQuery   = $qpviewStr   . $queryAppend;
2364 1a2be799 Florent Chuffart
                                $copyQuery   = $qpcopyStr   . $queryAppend;
2365 1a2be799 Florent Chuffart
                                $changeQuery = $qpchangeStr . $queryAppend;
2366 1a2be799 Florent Chuffart
                                $deleteQuery = $qpdeleteStr . $queryAppend;
2367 1a2be799 Florent Chuffart
                                $viewTitle   = htmlspecialchars($this->labels['View']);
2368 1a2be799 Florent Chuffart
                                $changeTitle = htmlspecialchars($this->labels['Change']);
2369 1a2be799 Florent Chuffart
                                $copyTitle   = htmlspecialchars($this->labels['Copy']);
2370 1a2be799 Florent Chuffart
                                $deleteTitle = htmlspecialchars($this->labels['Delete']);
2371 1a2be799 Florent Chuffart
                                $css_class_name = $this->getCSSclass('navigation', null, true);
2372 1a2be799 Florent Chuffart
                                if ($select_recs) {
2373 1a2be799 Florent Chuffart
                                        if (! $this->nav_buttons() || $sys_cols > 1) {
2374 1a2be799 Florent Chuffart
                                                echo '<td class="',$css_class_name,'">';
2375 1a2be799 Florent Chuffart
                                        }
2376 1a2be799 Florent Chuffart
                                        if ($this->nav_graphic_links()) {
2377 1a2be799 Florent Chuffart
                                                $printed_out = false;
2378 1a2be799 Florent Chuffart
                                                if ($this->view_enabled()) {
2379 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2380 1a2be799 Florent Chuffart
                                                        echo '<a class="',$css_class_name,'" href="',$viewQuery,'"><img class="';
2381 1a2be799 Florent Chuffart
                                                        echo $css_class_name,'" src="',$this->url['images'];
2382 1a2be799 Florent Chuffart
                                                        echo 'pme-view.png" height="15" width="16" border="0" ';
2383 1a2be799 Florent Chuffart
                                                        echo 'alt="',$viewTitle,'" title="',$viewTitle,'" /></a>';
2384 1a2be799 Florent Chuffart
                                                }
2385 1a2be799 Florent Chuffart
                                                if ($this->change_enabled()) {
2386 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2387 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2388 1a2be799 Florent Chuffart
                                                        echo '<a class="',$css_class_name,'" href="',$changeQuery,'"><img class="';
2389 1a2be799 Florent Chuffart
                                                        echo $css_class_name,'" src="',$this->url['images'];
2390 1a2be799 Florent Chuffart
                                                        echo 'pme-change.png" height="15" width="16" border="0" ';
2391 1a2be799 Florent Chuffart
                                                        echo 'alt="',$changeTitle,'" title="',$changeTitle,'" /></a>';
2392 1a2be799 Florent Chuffart
                                                }
2393 1a2be799 Florent Chuffart
                                                if ($this->copy_enabled()) {
2394 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2395 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2396 1a2be799 Florent Chuffart
                                                        echo '<a class="',$css_class_name,'" href="',$copyQuery,'"><img class="';
2397 1a2be799 Florent Chuffart
                                                        echo $css_class_name,'" src="',$this->url['images'];
2398 1a2be799 Florent Chuffart
                                                        echo 'pme-copy.png" height="15" width="16" border="0" ';
2399 1a2be799 Florent Chuffart
                                                        echo 'alt="',$copyTitle,'" title="',$copyTitle,'" /></a>';
2400 1a2be799 Florent Chuffart
                                                }
2401 1a2be799 Florent Chuffart
                                                if ($this->delete_enabled()) {
2402 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2403 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2404 1a2be799 Florent Chuffart
                                                        echo '<a class="',$css_class_name,'" href="',$deleteQuery,'"><img class="';
2405 1a2be799 Florent Chuffart
                                                        echo $css_class_name,'" src="',$this->url['images'];
2406 1a2be799 Florent Chuffart
                                                        echo 'pme-delete.png" height="15" width="16" border="0" ';
2407 1a2be799 Florent Chuffart
                                                        echo 'alt="',$deleteTitle,'" title="',$deleteTitle,'" /></a>';
2408 1a2be799 Florent Chuffart
                                                }
2409 1a2be799 Florent Chuffart
                                        }
2410 1a2be799 Florent Chuffart
                                        if ($this->nav_text_links()) {
2411 1a2be799 Florent Chuffart
                                                if ($this->nav_graphic_links()) {
2412 1a2be799 Florent Chuffart
                                                        echo '<br class="',$css_class_name,'">';
2413 1a2be799 Florent Chuffart
                                                }
2414 1a2be799 Florent Chuffart
                                                $printed_out = false;
2415 1a2be799 Florent Chuffart
                                                if ($this->view_enabled()) {
2416 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2417 1a2be799 Florent Chuffart
                                                        echo '<a href="',$viewQuery,'" title="',$viewTitle,'" class="',$css_class_name,'">V</a>';
2418 1a2be799 Florent Chuffart
                                                }
2419 1a2be799 Florent Chuffart
                                                if ($this->change_enabled()) {
2420 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2421 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2422 1a2be799 Florent Chuffart
                                                        echo '<a href="',$changeQuery,'" title="',$changeTitle,'" class="',$css_class_name,'">C</a>';
2423 1a2be799 Florent Chuffart
                                                }
2424 1a2be799 Florent Chuffart
                                                if ($this->copy_enabled()) {
2425 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2426 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2427 1a2be799 Florent Chuffart
                                                        echo '<a href="',$copyQuery,'" title="',$copyTitle,'" class="',$css_class_name,'">P</a>';
2428 1a2be799 Florent Chuffart
                                                }
2429 1a2be799 Florent Chuffart
                                                if ($this->delete_enabled()) {
2430 1a2be799 Florent Chuffart
                                                        $printed_out && print('&nbsp;');
2431 1a2be799 Florent Chuffart
                                                        $printed_out = true;
2432 1a2be799 Florent Chuffart
                                                        echo '<a href="',$deleteQuery,'" title="',$deleteTitle,'" class="',$css_class_name,'">D</a>';
2433 1a2be799 Florent Chuffart
                                                }
2434 1a2be799 Florent Chuffart
                                        }
2435 1a2be799 Florent Chuffart
                                        if (! $this->nav_buttons() || $sys_cols > 1) {
2436 1a2be799 Florent Chuffart
                                                echo '</td>',"\n";
2437 1a2be799 Florent Chuffart
                                        }
2438 1a2be799 Florent Chuffart
                                        if ($this->nav_buttons()) {
2439 1a2be799 Florent Chuffart
                                                echo '<td class="',$css_class_name,'"><input class="',$css_class_name;
2440 1a2be799 Florent Chuffart
                                                echo '" type="radio" name="'.$this->cgi['prefix']['sys'].'rec';
2441 1a2be799 Florent Chuffart
                                                echo '" value="',htmlspecialchars($key_rec),'"';
2442 1a2be799 Florent Chuffart
                                                if (($this->rec == '' && $first) || ($this->rec == $key_rec)) {
2443 1a2be799 Florent Chuffart
                                                        echo ' checked';
2444 1a2be799 Florent Chuffart
                                                        $first = false;
2445 1a2be799 Florent Chuffart
                                                }
2446 1a2be799 Florent Chuffart
                                                echo ' /></td>',"\n";
2447 1a2be799 Florent Chuffart
                                        }
2448 1a2be799 Florent Chuffart
                                } elseif ($this->filter_enabled()) {
2449 1a2be799 Florent Chuffart
                                        echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">&nbsp;</td>',"\n";
2450 1a2be799 Florent Chuffart
                                }
2451 1a2be799 Florent Chuffart
                        } /* }}} */
2452 1a2be799 Florent Chuffart
                        for ($k = 0; $k < $this->num_fds; $k++) { /* {{{ */
2453 1a2be799 Florent Chuffart
                                $fd = $this->fds[$k];
2454 1a2be799 Florent Chuffart
                                if (! $this->displayed[$k]) {
2455 1a2be799 Florent Chuffart
                                        continue;
2456 1a2be799 Florent Chuffart
                                }
2457 1a2be799 Florent Chuffart
                                $css_postfix    = @$this->fdd[$k]['css']['postfix'];
2458 1a2be799 Florent Chuffart
                                $css_class_name = $this->getCSSclass('cell', null, true, $css_postfix);
2459 1a2be799 Florent Chuffart
                                if ($this->password($k)) {
2460 1a2be799 Florent Chuffart
                                        echo '<td class="',$css_class_name,'">',$this->labels['hidden'],'</td>',"\n";
2461 1a2be799 Florent Chuffart
                                        continue;
2462 1a2be799 Florent Chuffart
                                }
2463 1a2be799 Florent Chuffart
                                echo '<td class="',$css_class_name,'"',$this->getColAttributes($fd),'>';
2464 1a2be799 Florent Chuffart
                                echo $this->cellDisplay($k, $row, $css_class_name);
2465 1a2be799 Florent Chuffart
                                echo '</td>',"\n";
2466 1a2be799 Florent Chuffart
                        } /* }}} */
2467 1a2be799 Florent Chuffart
                        echo '</tr>',"\n";
2468 1a2be799 Florent Chuffart
                }
2469 1a2be799 Florent Chuffart
2470 1a2be799 Florent Chuffart
                /*
2471 1a2be799 Florent Chuffart
                 * Display and accumulate column aggregation info, do totalling query
2472 1a2be799 Florent Chuffart
                 * XXX this feature does not work yet!!!
2473 1a2be799 Florent Chuffart
                 */
2474 1a2be799 Florent Chuffart
                // aggregates listing (if any)
2475 1a2be799 Florent Chuffart
                if ($$var_to_total) {
2476 1a2be799 Florent Chuffart
                        // do the aggregate query if necessary
2477 1a2be799 Florent Chuffart
                        //if ($vars_to_total) {
2478 1a2be799 Florent Chuffart
                                $qp = array();
2479 1a2be799 Florent Chuffart
                                $qp['type'] = 'select';
2480 1a2be799 Florent Chuffart
                                $qp['select'] = $aggr_from_clause;
2481 1a2be799 Florent Chuffart
                                $qp['from']   = $this->get_SQL_join_clause();
2482 1a2be799 Florent Chuffart
                                $qp['where']  = $this->get_SQL_where_from_query_opts();
2483 1a2be799 Florent Chuffart
                                $tot_query    = $this->get_SQL_query($qp);
2484 1a2be799 Florent Chuffart
                                $totals_result = $this->myquery($tot_query,__LINE__);
2485 1a2be799 Florent Chuffart
                                $tot_row       = $this->sql_fetch($totals_result);
2486 1a2be799 Florent Chuffart
                        //}
2487 1a2be799 Florent Chuffart
                        $qp_aggr = $qp;
2488 1a2be799 Florent Chuffart
                        echo "\n",'<tr class="TODO-class">',"\n",'<td class="TODO-class">&nbsp;</td>',"\n";
2489 1a2be799 Florent Chuffart
                        /*
2490 1a2be799 Florent Chuffart
                        echo '<td>';
2491 1a2be799 Florent Chuffart
                        echo printarray($qp_aggr);
2492 1a2be799 Florent Chuffart
                        echo printarray($vars_to_total);
2493 1a2be799 Florent Chuffart
                        echo '</td>';
2494 1a2be799 Florent Chuffart
                        echo '<td colspan="'.($this->num_fds-1).'">'.$var_to_total.' '.$$var_to_total.'</td>';
2495 1a2be799 Florent Chuffart
                        */
2496 1a2be799 Florent Chuffart
                        // display the results
2497 1a2be799 Florent Chuffart
                        for ($k=0;$k<$this->num_fds;$k++) {
2498 1a2be799 Florent Chuffart
                                $fd = $this->fds[$k];
2499 1a2be799 Florent Chuffart
                                if (stristr($this->fdd[$fd]['options'],'L') or !isset($this->fdd[$fd]['options'])) {
2500 1a2be799 Florent Chuffart
                                        echo '<td>';
2501 1a2be799 Florent Chuffart
                                        $aggr_var  = 'qf'.$k.'_aggr';
2502 1a2be799 Florent Chuffart
                                        $$aggr_var = $this->get_sys_cgi_var($aggr_var);
2503 1a2be799 Florent Chuffart
                                        if ($$aggr_var) {
2504 1a2be799 Florent Chuffart
                                                echo $this->sql_aggrs[$$aggr_var],': ',$tot_row[$aggr_var];
2505 1a2be799 Florent Chuffart
                                        } else {
2506 1a2be799 Florent Chuffart
                                                echo '&nbsp;';
2507 1a2be799 Florent Chuffart
                                        }
2508 1a2be799 Florent Chuffart
                                        echo '</td>',"\n";
2509 1a2be799 Florent Chuffart
                                }
2510 1a2be799 Florent Chuffart
                        }
2511 1a2be799 Florent Chuffart
                        echo '</tr>',"\n";
2512 1a2be799 Florent Chuffart
                }
2513 1a2be799 Florent Chuffart
                echo '</table>',"\n"; // end of table rows listing
2514 1a2be799 Florent Chuffart
                $this->display_list_table_buttons('down', $listall);
2515 1a2be799 Florent Chuffart
                $this->form_end();
2516 1a2be799 Florent Chuffart
        } /* }}} */
2517 1a2be799 Florent Chuffart
2518 1a2be799 Florent Chuffart
        function display_record() /* {{{ */
2519 1a2be799 Florent Chuffart
        {
2520 1a2be799 Florent Chuffart
                // PRE Triggers
2521 1a2be799 Florent Chuffart
                $ret = true;
2522 1a2be799 Florent Chuffart
                if ($this->change_operation()) {
2523 1a2be799 Florent Chuffart
                        $ret &= $this->exec_triggers_simple('update', 'pre');
2524 1a2be799 Florent Chuffart
                        // if PRE update fails, then back to view operation
2525 1a2be799 Florent Chuffart
                        if (! $ret) {
2526 1a2be799 Florent Chuffart
                                $this->operation = $this->labels['View'];
2527 1a2be799 Florent Chuffart
                                $ret = true;
2528 1a2be799 Florent Chuffart
                        }
2529 1a2be799 Florent Chuffart
                }
2530 1a2be799 Florent Chuffart
                if ($this->add_operation() || $this->copy_operation()) {
2531 1a2be799 Florent Chuffart
                        $ret &= $this->exec_triggers_simple('insert', 'pre');
2532 1a2be799 Florent Chuffart
                }
2533 1a2be799 Florent Chuffart
                if ($this->view_operation()) {
2534 1a2be799 Florent Chuffart
                        $ret &= $this->exec_triggers_simple('select', 'pre');
2535 1a2be799 Florent Chuffart
                }
2536 1a2be799 Florent Chuffart
                if ($this->delete_operation()) {
2537 1a2be799 Florent Chuffart
                        $ret &= $this->exec_triggers_simple('delete', 'pre');
2538 1a2be799 Florent Chuffart
                }
2539 1a2be799 Florent Chuffart
                // if PRE insert/view/delete fail, then back to the list
2540 1a2be799 Florent Chuffart
                if ($ret == false) {
2541 1a2be799 Florent Chuffart
                        $this->operation = '';
2542 1a2be799 Florent Chuffart
                        $this->list_table();
2543 1a2be799 Florent Chuffart
                        return;
2544 1a2be799 Florent Chuffart
                }
2545 1a2be799 Florent Chuffart
                $this->form_begin();
2546 1a2be799 Florent Chuffart
                if ($this->cgi['persist'] != '') {
2547 1a2be799 Florent Chuffart
                        echo $this->get_origvars_html($this->cgi['persist']);
2548 1a2be799 Florent Chuffart
                }
2549 1a2be799 Florent Chuffart
                echo $this->get_origvars_html($this->get_sfn_cgi_vars());
2550 1a2be799 Florent Chuffart
                echo $this->get_origvars_html($this->qfn);
2551 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('cur_tab', $this->dhtml['prefix'].'tab'.$this->cur_tab);
2552 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('qfn', $this->qfn);
2553 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('rec', $this->copy_operation() ? '' : $this->rec);
2554 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('fm', $this->fm);
2555 1a2be799 Florent Chuffart
                echo $this->htmlHiddenSys('fl', $this->fl);
2556 1a2be799 Florent Chuffart
                $this->display_record_buttons('up');
2557 1a2be799 Florent Chuffart
                if ($this->tabs_enabled()) {
2558 1a2be799 Florent Chuffart
                        echo '<div id="'.$this->dhtml['prefix'].'tab0">',"\n";
2559 1a2be799 Florent Chuffart
                }
2560 1a2be799 Florent Chuffart
                echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
2561 1a2be799 Florent Chuffart
                if ($this->add_operation()) {
2562 1a2be799 Florent Chuffart
                        $this->display_add_record();
2563 1a2be799 Florent Chuffart
                } else {
2564 1a2be799 Florent Chuffart
                        $this->display_copy_change_delete_record();
2565 1a2be799 Florent Chuffart
                }
2566 1a2be799 Florent Chuffart
                echo '</table>',"\n";
2567 1a2be799 Florent Chuffart
                 if ($this->tabs_enabled()) {
2568 1a2be799 Florent Chuffart
                echo '</div>',"\n";
2569 1a2be799 Florent Chuffart
                }                
2570 1a2be799 Florent Chuffart
                $this->display_record_buttons('down');
2571 1a2be799 Florent Chuffart
2572 1a2be799 Florent Chuffart
                $this->form_end();
2573 1a2be799 Florent Chuffart
        } /* }}} */
2574 1a2be799 Florent Chuffart
2575 1a2be799 Florent Chuffart
        /*
2576 1a2be799 Florent Chuffart
         * Action functions
2577 1a2be799 Florent Chuffart
         */
2578 1a2be799 Florent Chuffart
2579 1a2be799 Florent Chuffart
        function do_add_record() /* {{{ */
2580 1a2be799 Florent Chuffart
        {
2581 1a2be799 Florent Chuffart
                // Preparing query
2582 1a2be799 Florent Chuffart
                $query       = '';
2583 1a2be799 Florent Chuffart
                $key_col_val = '';
2584 1a2be799 Florent Chuffart
                $newvals     = array();
2585 1a2be799 Florent Chuffart
                for ($k = 0; $k < $this->num_fds; $k++) {
2586 1a2be799 Florent Chuffart
                        if ($this->processed($k)) {
2587 1a2be799 Florent Chuffart
                                $fd = $this->fds[$k];
2588 1a2be799 Florent Chuffart
                                if ($this->readonly($k)) {
2589 1a2be799 Florent Chuffart
                                        $fn = (string) @$this->fdd[$k]['default'];
2590 1a2be799 Florent Chuffart
                                } else {
2591 1a2be799 Florent Chuffart
                                        $fn = $this->get_data_cgi_var($fd);
2592 1a2be799 Florent Chuffart
                                }
2593 1a2be799 Florent Chuffart
                                if ($fd == $this->key) {
2594 1a2be799 Florent Chuffart
                                        $key_col_val = $fn;
2595 1a2be799 Florent Chuffart
                                }
2596 1a2be799 Florent Chuffart
                                $newvals[$fd] = is_array($fn) ? join(',',$fn) : $fn;
2597 1a2be799 Florent Chuffart
                        }
2598 1a2be799 Florent Chuffart
                }
2599 1a2be799 Florent Chuffart
                // Creating array of changed keys ($changed)
2600 1a2be799 Florent Chuffart
                $changed = array_keys($newvals);
2601 1a2be799 Florent Chuffart
                // Before trigger, newvals can be efectively changed
2602 1a2be799 Florent Chuffart
                if ($this->exec_triggers('insert', 'before', $oldvals, $changed, $newvals) == false) {
2603 1a2be799 Florent Chuffart
                        return false;
2604 1a2be799 Florent Chuffart
                }
2605 1a2be799 Florent Chuffart
                // Real query (no additional query in this method)
2606 1a2be799 Florent Chuffart
                foreach ($newvals as $fd => $val) {
2607 1a2be799 Florent Chuffart
                        if ($fd == '') continue;
2608 1a2be799 Florent Chuffart
                        if ($this->col_has_sqlw($this->fdn[$fd])) {
2609 1a2be799 Florent Chuffart
                                $val_as  = addslashes($val);
2610 1a2be799 Florent Chuffart
                                $val_qas = '"'.addslashes($val).'"';
2611 1a2be799 Florent Chuffart
                                $value = $this->substituteVars(
2612 1a2be799 Florent Chuffart
                                                $this->fdd[$this->fdn[$fd]]['sqlw'], array(
2613 1a2be799 Florent Chuffart
                                                        'val_qas' => $val_qas,
2614 1a2be799 Florent Chuffart
                                                        'val_as'  => $val_as,
2615 1a2be799 Florent Chuffart
                                                        'val'     => $val
2616 1a2be799 Florent Chuffart
                                                        ));
2617 1a2be799 Florent Chuffart
                        } else {
2618 1a2be799 Florent Chuffart
                                $value = "'".addslashes($val)."'";
2619 1a2be799 Florent Chuffart
                        }
2620 1a2be799 Florent Chuffart
                        if ($query == '') {
2621 1a2be799 Florent Chuffart
                                $query = 'INSERT INTO '.$this->sd.$this->tb.$this->ed.' ('.$this->sd.$fd.$this->ed.''; // )
2622 1a2be799 Florent Chuffart
                                $query2 = ') VALUES ('.$value.'';
2623 1a2be799 Florent Chuffart
                        } else {
2624 1a2be799 Florent Chuffart
                                $query  .= ', '.$this->sd.$fd.$this->ed.'';
2625 1a2be799 Florent Chuffart
                                $query2 .= ', '.$value.'';
2626 1a2be799 Florent Chuffart
                        }
2627 1a2be799 Florent Chuffart
                }
2628 1a2be799 Florent Chuffart
                $query .= $query2.')';
2629 1a2be799 Florent Chuffart
                $res    = $this->myquery($query, __LINE__);
2630 1a2be799 Florent Chuffart
                $this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record added'];
2631 1a2be799 Florent Chuffart
                if (! $res) {
2632 1a2be799 Florent Chuffart
                        return false;
2633 1a2be799 Florent Chuffart
                }
2634 1a2be799 Florent Chuffart
                $this->rec = $this->sql_insert_id();
2635 1a2be799 Florent Chuffart
                // Notify list
2636 1a2be799 Florent Chuffart
                if (@$this->notify['insert'] || @$this->notify['all']) {
2637 1a2be799 Florent Chuffart
                        $this->email_notify(false, $newvals);
2638 1a2be799 Florent Chuffart
                }
2639 1a2be799 Florent Chuffart
                // Note change in log table
2640 1a2be799 Florent Chuffart
                if ($this->logtable) {
2641 1a2be799 Florent Chuffart
                        $query = sprintf('INSERT INTO %s'
2642 1a2be799 Florent Chuffart
                                        .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
2643 1a2be799 Florent Chuffart
                                        .' VALUES (NOW(), "%s", "%s", "insert", "%s", "%s", "", "", "%s")',
2644 1a2be799 Florent Chuffart
                                        $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
2645 1a2be799 Florent Chuffart
                                        addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
2646 1a2be799 Florent Chuffart
                                        addslashes($key_col_val), addslashes(serialize($newvals)));
2647 1a2be799 Florent Chuffart
                        $this->myquery($query, __LINE__);
2648 1a2be799 Florent Chuffart
                }
2649 1a2be799 Florent Chuffart
                // After trigger
2650 1a2be799 Florent Chuffart
                if ($this->exec_triggers('insert', 'after', $oldvals, $changed, $newvals) == false) {
2651 1a2be799 Florent Chuffart
                        return false;
2652 1a2be799 Florent Chuffart
                }
2653 1a2be799 Florent Chuffart
                return true;
2654 1a2be799 Florent Chuffart
        } /* }}} */
2655 1a2be799 Florent Chuffart
2656 1a2be799 Florent Chuffart
        function do_change_record() /* {{{ */
2657 1a2be799 Florent Chuffart
        {
2658 1a2be799 Florent Chuffart
                // Preparing queries
2659 1a2be799 Florent Chuffart
                $query_real   = '';
2660 1a2be799 Florent Chuffart
                $query_oldrec = '';
2661 1a2be799 Florent Chuffart
                $newvals      = array();
2662 1a2be799 Florent Chuffart
                $oldvals      = array();
2663 1a2be799 Florent Chuffart
                $changed      = array();
2664 1a2be799 Florent Chuffart
                // Prepare query to retrieve oldvals
2665 1a2be799 Florent Chuffart
                for ($k = 0; $k < $this->num_fds; $k++) {
2666 1a2be799 Florent Chuffart
                        if ($this->processed($k) && !$this->readonly($k)) {
2667 1a2be799 Florent Chuffart
                                $fd = $this->fds[$k];
2668 1a2be799 Florent Chuffart
                                $fn = $this->get_data_cgi_var($fd);
2669 1a2be799 Florent Chuffart
                                $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
2670 1a2be799 Florent Chuffart
                                if ($query_oldrec == '') {
2671 1a2be799 Florent Chuffart
                                        $query_oldrec = 'SELECT '.$this->sd.$fd.$this->ed;
2672 1a2be799 Florent Chuffart
                                } else {
2673 1a2be799 Florent Chuffart
                                        $query_oldrec .= ','.$this->sd.$fd.$this->ed;
2674 1a2be799 Florent Chuffart
                                }
2675 1a2be799 Florent Chuffart
                        }
2676 1a2be799 Florent Chuffart
                }
2677 1a2be799 Florent Chuffart
                $where_part = " WHERE (".$this->sd.$this->key.$this->ed.'='.$this->key_delim.$this->rec.$this->key_delim.')';
2678 1a2be799 Florent Chuffart
                $query_newrec  = $query_oldrec.' FROM ' . $this->tb;
2679 1a2be799 Florent Chuffart
                $query_oldrec .= ' FROM ' . $this->sd.$this->tb.$this->ed . $where_part;
2680 1a2be799 Florent Chuffart
                // Additional query (must go before real query)
2681 1a2be799 Florent Chuffart
                $res     = $this->myquery($query_oldrec, __LINE__);
2682 1a2be799 Florent Chuffart
                $oldvals = $this->sql_fetch($res);
2683 1a2be799 Florent Chuffart
                $this->sql_free_result($res);
2684 1a2be799 Florent Chuffart
                // Creating array of changed keys ($changed)
2685 1a2be799 Florent Chuffart
                foreach ($newvals as $fd => $value) {
2686 1a2be799 Florent Chuffart
                        if ($value != $oldvals[$fd])
2687 1a2be799 Florent Chuffart
                                $changed[] = $fd;
2688 1a2be799 Florent Chuffart
                }
2689 1a2be799 Florent Chuffart
                // Before trigger
2690 1a2be799 Florent Chuffart
                if ($this->exec_triggers('update', 'before', $oldvals, $changed, $newvals) == false) {
2691 1a2be799 Florent Chuffart
                        return false;
2692 1a2be799 Florent Chuffart
                }
2693 1a2be799 Florent Chuffart
                // Build the real query respecting changes to the newvals array
2694 1a2be799 Florent Chuffart
                foreach ($newvals as $fd => $val) {
2695 1a2be799 Florent Chuffart
                        if ($fd == '') continue;
2696 1a2be799 Florent Chuffart
                        if ($this->col_has_sqlw($this->fdn[$fd])) {
2697 1a2be799 Florent Chuffart
                                $val_as  = addslashes($val);
2698 1a2be799 Florent Chuffart
                                $val_qas = '"'.addslashes($val).'"';
2699 1a2be799 Florent Chuffart
                                $value = $this->substituteVars(
2700 1a2be799 Florent Chuffart
                                                $this->fdd[$this->fdn[$fd]]['sqlw'], array(
2701 1a2be799 Florent Chuffart
                                                        'val_qas' => $val_qas,
2702 1a2be799 Florent Chuffart
                                                        'val_as'  => $val_as,
2703 1a2be799 Florent Chuffart
                                                        'val'     => $val
2704 1a2be799 Florent Chuffart
                                                        ));
2705 1a2be799 Florent Chuffart
                        } else {
2706 1a2be799 Florent Chuffart
                                $value = "'".addslashes($val)."'";
2707 1a2be799 Florent Chuffart
                        }
2708 1a2be799 Florent Chuffart
                        if ($query_real == '') {
2709 1a2be799 Florent Chuffart
                                $query_real   = 'UPDATE '.$this->sd.$this->tb.$this->ed.' SET '.$this->sd.$fd.$this->ed.'='.$value;
2710 1a2be799 Florent Chuffart
                        } else {
2711 1a2be799 Florent Chuffart
                                $query_real   .= ','.$this->sd.$fd.$this->ed.'='.$value;
2712 1a2be799 Florent Chuffart
                        }
2713 1a2be799 Florent Chuffart
                }
2714 1a2be799 Florent Chuffart
                $query_real .= $where_part;
2715 1a2be799 Florent Chuffart
                // Real query
2716 1a2be799 Florent Chuffart
                $res = $this->myquery($query_real, __LINE__);
2717 1a2be799 Florent Chuffart
                $this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record changed'];
2718 1a2be799 Florent Chuffart
                if (! $res) {
2719 1a2be799 Florent Chuffart
                        return false;
2720 1a2be799 Florent Chuffart
                }
2721 1a2be799 Florent Chuffart
                // Another additional query (must go after real query)
2722 1a2be799 Florent Chuffart
                if (in_array($this->key, $changed)) {
2723 1a2be799 Florent Chuffart
                        $this->rec = $newvals[$this->key]; // key has changed
2724 1a2be799 Florent Chuffart
                }
2725 1a2be799 Florent Chuffart
                $query_newrec .= ' WHERE ('.$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')';
2726 1a2be799 Florent Chuffart
                $res     = $this->myquery($query_newrec, __LINE__);
2727 1a2be799 Florent Chuffart
                $newvals = $this->sql_fetch($res);
2728 1a2be799 Florent Chuffart
                $this->sql_free_result($res);
2729 1a2be799 Florent Chuffart
                // Creating array of changed keys ($changed)
2730 1a2be799 Florent Chuffart
                $changed = array();
2731 1a2be799 Florent Chuffart
                foreach ($newvals as $fd => $value) {
2732 1a2be799 Florent Chuffart
                        if ($value != $oldvals[$fd])
2733 1a2be799 Florent Chuffart
                                $changed[] = $fd;
2734 1a2be799 Florent Chuffart
                }
2735 1a2be799 Florent Chuffart
                // Notify list
2736 1a2be799 Florent Chuffart
                if (@$this->notify['update'] || @$this->notify['all']) {
2737 1a2be799 Florent Chuffart
                        if (count($changed) > 0) {
2738 1a2be799 Florent Chuffart
                                $this->email_notify($oldvals, $newvals);
2739 1a2be799 Florent Chuffart
                        }
2740 1a2be799 Florent Chuffart
                }
2741 1a2be799 Florent Chuffart
                // Note change in log table
2742 1a2be799 Florent Chuffart
                if ($this->logtable) {
2743 1a2be799 Florent Chuffart
                        foreach ($changed as $key) {
2744 1a2be799 Florent Chuffart
                                $qry = sprintf('INSERT INTO %s'
2745 1a2be799 Florent Chuffart
                                                .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
2746 1a2be799 Florent Chuffart
                                                .' VALUES (NOW(), "%s", "%s", "update", "%s", "%s", "%s", "%s", "%s")',
2747 1a2be799 Florent Chuffart
                                                $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
2748 1a2be799 Florent Chuffart
                                                addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
2749 1a2be799 Florent Chuffart
                                                addslashes($this->rec), addslashes($key),
2750 1a2be799 Florent Chuffart
                                                addslashes($oldvals[$key]), addslashes($newvals[$key]));
2751 1a2be799 Florent Chuffart
                                $this->myquery($qry, __LINE__);
2752 1a2be799 Florent Chuffart
                        }
2753 1a2be799 Florent Chuffart
                }
2754 1a2be799 Florent Chuffart
                // After trigger
2755 1a2be799 Florent Chuffart
                if ($this->exec_triggers('update', 'after', $oldvals, $changed, $newvals) == false) {
2756 1a2be799 Florent Chuffart
                        return false;
2757 1a2be799 Florent Chuffart
                }
2758 1a2be799 Florent Chuffart
                return true;
2759 1a2be799 Florent Chuffart
        } /* }}} */
2760 1a2be799 Florent Chuffart
2761 1a2be799 Florent Chuffart
        function do_delete_record() /* {{{ */
2762 1a2be799 Florent Chuffart
        {
2763 1a2be799 Florent Chuffart
                // Additional query
2764 1a2be799 Florent Chuffart
                $query   = 'SELECT * FROM '.$this->sd.$this->tb.$this->ed.' WHERE ('.$this->sd.$this->key.$this->ed.' = '
2765 1a2be799 Florent Chuffart
                                .$this->key_delim.$this->rec.$this->key_delim.')'; // )
2766 1a2be799 Florent Chuffart
                $res     = $this->myquery($query, __LINE__);
2767 1a2be799 Florent Chuffart
                $oldvals = $this->sql_fetch($res);
2768 1a2be799 Florent Chuffart
                $this->sql_free_result($res);
2769 1a2be799 Florent Chuffart
                // Creating array of changed keys ($changed)
2770 1a2be799 Florent Chuffart
                $changed = is_array($oldvals) ? array_keys($oldvals) : array();
2771 1a2be799 Florent Chuffart
                $newvals = array();
2772 1a2be799 Florent Chuffart
                // Before trigger
2773 1a2be799 Florent Chuffart
                if ($this->exec_triggers('delete', 'before', $oldvals, $changed, $newvals) == false) {
2774 1a2be799 Florent Chuffart
                        return false;
2775 1a2be799 Florent Chuffart
                }
2776 1a2be799 Florent Chuffart
                // Real query
2777 1a2be799 Florent Chuffart
                $query = 'DELETE FROM '.$this->tb.' WHERE ('.$this->key.' = '
2778 1a2be799 Florent Chuffart
                                .$this->key_delim.$this->rec.$this->key_delim.')'; // )
2779 1a2be799 Florent Chuffart
                $res = $this->myquery($query, __LINE__);
2780 1a2be799 Florent Chuffart
                $this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record deleted'];
2781 1a2be799 Florent Chuffart
                if (! $res) {
2782 1a2be799 Florent Chuffart
                        return false;
2783 1a2be799 Florent Chuffart
                }
2784 1a2be799 Florent Chuffart
                // Notify list
2785 1a2be799 Florent Chuffart
                if (@$this->notify['delete'] || @$this->notify['all']) {
2786 1a2be799 Florent Chuffart
                        $this->email_notify($oldvals, false);
2787 1a2be799 Florent Chuffart
                }
2788 1a2be799 Florent Chuffart
                // Note change in log table
2789 1a2be799 Florent Chuffart
                if ($this->logtable) {
2790 1a2be799 Florent Chuffart
                        $query = sprintf('INSERT INTO %s'
2791 1a2be799 Florent Chuffart
                                        .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
2792 1a2be799 Florent Chuffart
                                        .' VALUES (NOW(), "%s", "%s", "delete", "%s", "%s", "%s", "%s", "")',
2793 1a2be799 Florent Chuffart
                                        $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
2794 1a2be799 Florent Chuffart
                                        addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
2795 1a2be799 Florent Chuffart
                                        addslashes($this->rec), addslashes($key), addslashes(serialize($oldvals)));
2796 1a2be799 Florent Chuffart
                        $this->myquery($query, __LINE__);
2797 1a2be799 Florent Chuffart
                }
2798 1a2be799 Florent Chuffart
                // After trigger
2799 1a2be799 Florent Chuffart
                if ($this->exec_triggers('delete', 'after', $oldvals, $changed, $newvals) == false) {
2800 1a2be799 Florent Chuffart
                        return false;
2801 1a2be799 Florent Chuffart
                }
2802 1a2be799 Florent Chuffart
                return true;
2803 1a2be799 Florent Chuffart
        } /* }}} */
2804 1a2be799 Florent Chuffart
2805 1a2be799 Florent Chuffart
        function email_notify($old_vals, $new_vals) /* {{{ */
2806 1a2be799 Florent Chuffart
        {
2807 1a2be799 Florent Chuffart
                if (! function_exists('mail')) {
2808 1a2be799 Florent Chuffart
                        return false;
2809 1a2be799 Florent Chuffart
                }
2810 1a2be799 Florent Chuffart
                if ($old_vals != false && $new_vals != false) {
2811 1a2be799 Florent Chuffart
                        $action  = 'update';
2812 1a2be799 Florent Chuffart
                        $subject = 'Record updated in';
2813 1a2be799 Florent Chuffart
                        $body    = 'An item with '.$this->fdd[$this->key]['name'].' = '
2814 1a2be799 Florent Chuffart
                                .$this->key_delim.$this->rec.$this->key_delim .' was updated in';
2815 1a2be799 Florent Chuffart
                        $vals    = $new_vals;
2816 1a2be799 Florent Chuffart
                } elseif ($new_vals != false) {
2817 1a2be799 Florent Chuffart
                        $action  = 'insert';
2818 1a2be799 Florent Chuffart
                        $subject = 'Record added to';
2819 1a2be799 Florent Chuffart
                        $body    = 'A new item was added into';
2820 1a2be799 Florent Chuffart
                        $vals    = $new_vals;
2821 1a2be799 Florent Chuffart
                } elseif ($old_vals != false) {
2822 1a2be799 Florent Chuffart
                        $action  = 'delete';
2823 1a2be799 Florent Chuffart
                        $subject = 'Record deleted from';
2824 1a2be799 Florent Chuffart
                        $body    = 'An item was deleted from';
2825 1a2be799 Florent Chuffart
                        $vals    = $old_vals;
2826 1a2be799 Florent Chuffart
                } else {
2827 1a2be799 Florent Chuffart
                        return false;
2828 1a2be799 Florent Chuffart
                }
2829 1a2be799 Florent Chuffart
                $addr  = $this->get_server_var('REMOTE_ADDR');
2830 1a2be799 Florent Chuffart
                $user  = $this->get_server_var('REMOTE_USER');
2831 1a2be799 Florent Chuffart
                $body  = 'This notification e-mail was automatically generated by phpMyEdit.'."\n\n".$body;
2832 1a2be799 Florent Chuffart
                $body .= ' table '.$this->tb.' in SQL database '.$this->db.' on '.$this->page_name;
2833 1a2be799 Florent Chuffart
                $body .= ' by '.($user == '' ? 'unknown user' : "user $user").' from '.$addr;
2834 1a2be799 Florent Chuffart
                $body .= ' at '.date('d/M/Y H:i').' with the following fields:'."\n\n";
2835 1a2be799 Florent Chuffart
                $i = 1;
2836 1a2be799 Florent Chuffart
                foreach ($vals as $k => $text) {
2837 1a2be799 Florent Chuffart
                        $name = isset($this->fdd[$k]['name~'])
2838 1a2be799 Florent Chuffart
                                ? $this->fdd[$k]['name~'] : $this->fdd[$k]['name'];
2839 1a2be799 Florent Chuffart
                        if ($action == 'update') {
2840 1a2be799 Florent Chuffart
                                if ($old_vals[$k] == $new_vals[$k]) {
2841 1a2be799 Florent Chuffart
                                        continue;
2842 1a2be799 Florent Chuffart
                                }
2843 1a2be799 Florent Chuffart
                                $body .= sprintf("[%02s] %s (%s)\n      WAS: %s\n      IS:  %s\n",
2844 1a2be799 Florent Chuffart
                                                $i, $name, $k, $old_vals[$k], $new_vals[$k]);
2845 1a2be799 Florent Chuffart
                        } else {
2846 1a2be799 Florent Chuffart
                                $body .= sprintf('[%02s] %s (%s): %s'."\n", $i, $name, $k, $text);
2847 1a2be799 Florent Chuffart
                        }
2848 1a2be799 Florent Chuffart
                        $i++;
2849 1a2be799 Florent Chuffart
                }
2850 1a2be799 Florent Chuffart
                $body    .= "\n--\r\n"; // \r is needed for signature separating
2851 1a2be799 Florent Chuffart
                $body    .= "phpMyEdit\ninstant SQL table editor and code generator\n";
2852 1a2be799 Florent Chuffart
                $body    .= "http://platon.sk/projects/phpMyEdit/\n\n";
2853 1a2be799 Florent Chuffart
                $subject  = @$this->notify['prefix'].$subject.' '.$this->dbp.$this->tb;
2854 1a2be799 Florent Chuffart
                $subject  = trim($subject); // just for sure
2855 1a2be799 Florent Chuffart
                $wrap_w   = intval(@$this->notify['wrap']);
2856 1a2be799 Florent Chuffart
                   $wrap_w > 0 || $wrap_w = 72;
2857 1a2be799 Florent Chuffart
                $from     = (string) @$this->notify['from'];
2858 1a2be799 Florent Chuffart
                $from != '' || $from = 'webmaster@'.strtolower($this->get_server_var('SERVER_NAME'));
2859 1a2be799 Florent Chuffart
                $headers  = 'From: '.$from."\n".'X-Mailer: PHP/'.phpversion().' (phpMyEdit)';
2860 1a2be799 Florent Chuffart
                $body     = wordwrap($body, $wrap_w, "\n", 1);
2861 1a2be799 Florent Chuffart
                $emails   = (array) $this->notify[$action] + (array) $this->notify['all'];
2862 1a2be799 Florent Chuffart
                foreach ($emails as $email) {
2863 1a2be799 Florent Chuffart
                        if (! empty($email)) {
2864 1a2be799 Florent Chuffart
                                mail(trim($email), $subject, $body, $headers);
2865 1a2be799 Florent Chuffart
                        }
2866 1a2be799 Florent Chuffart
                }
2867 1a2be799 Florent Chuffart
                return true;
2868 1a2be799 Florent Chuffart
        } /* }}} */
2869 1a2be799 Florent Chuffart
2870 1a2be799 Florent Chuffart
        /*
2871 1a2be799 Florent Chuffart
         * Apply triggers function
2872 1a2be799 Florent Chuffart
         * Run a (set of) trigger(s). $trigger can be an Array or a filename
2873 1a2be799 Florent Chuffart
         * Break and return false as soon as a trigger return false
2874 1a2be799 Florent Chuffart
         * we need a reference on $newvals to be able to change value before insert/update
2875 1a2be799 Florent Chuffart
         */
2876 1a2be799 Florent Chuffart
        function exec_triggers($op, $step, $oldvals, &$changed, &$newvals) /* {{{ */
2877 1a2be799 Florent Chuffart
        {
2878 1a2be799 Florent Chuffart
                if (! isset($this->triggers[$op][$step])) {
2879 1a2be799 Florent Chuffart
                        return true;
2880 1a2be799 Florent Chuffart
                }
2881 1a2be799 Florent Chuffart
                $ret  = true;
2882 1a2be799 Florent Chuffart
                $trig = $this->triggers[$op][$step];
2883 1a2be799 Florent Chuffart
                if (is_array($trig)) {
2884 1a2be799 Florent Chuffart
                        ksort($trig);
2885 1a2be799 Florent Chuffart
                        for ($t = reset($trig); $t !== false && $ret != false; $t = next($trig)) {
2886 1a2be799 Florent Chuffart
                                $ret = include($t);
2887 1a2be799 Florent Chuffart
                        }
2888 1a2be799 Florent Chuffart
                } else {
2889 1a2be799 Florent Chuffart
                        $ret = include($trig);
2890 1a2be799 Florent Chuffart
                }
2891 1a2be799 Florent Chuffart
                return $ret;
2892 1a2be799 Florent Chuffart
        } /* }}} */
2893 1a2be799 Florent Chuffart
2894 1a2be799 Florent Chuffart
        function exec_triggers_simple($op, $step) /* {{{ */
2895 1a2be799 Florent Chuffart
        {
2896 1a2be799 Florent Chuffart
                $oldvals = $newvals = $changed = array();
2897 1a2be799 Florent Chuffart
                return $this->exec_triggers($op, $step, $oldvals, $changed, $newvals);
2898 1a2be799 Florent Chuffart
        } /* }}} */
2899 1a2be799 Florent Chuffart
        
2900 1a2be799 Florent Chuffart
        /*
2901 1a2be799 Florent Chuffart
         * Recreate functions
2902 1a2be799 Florent Chuffart
         */
2903 1a2be799 Florent Chuffart
        function recreate_fdd($default_page_type = 'L') /* {{{ */
2904 1a2be799 Florent Chuffart
        {
2905 1a2be799 Florent Chuffart
                // TODO: one level deeper browsing
2906 1a2be799 Florent Chuffart
                $this->page_type = $default_page_type;
2907 1a2be799 Florent Chuffart
                $this->filter_operation() && $this->page_type = 'F';
2908 1a2be799 Florent Chuffart
                $this->view_operation()   && $this->page_type = 'V';
2909 1a2be799 Florent Chuffart
                if ($this->add_operation()
2910 1a2be799 Florent Chuffart
                                || $this->saveadd == $this->labels['Save']
2911 1a2be799 Florent Chuffart
                                || $this->moreadd == $this->labels['More']) {
2912 1a2be799 Florent Chuffart
                        $this->page_type = 'A';
2913 1a2be799 Florent Chuffart
                }
2914 1a2be799 Florent Chuffart
                if ($this->change_operation()
2915 1a2be799 Florent Chuffart
                                || $this->savechange == $this->labels['Save']
2916 1a2be799 Florent Chuffart
                                || $this->morechange == $this->labels['Apply']) {
2917 1a2be799 Florent Chuffart
                        $this->page_type = 'C';
2918 1a2be799 Florent Chuffart
                }
2919 1a2be799 Florent Chuffart
                if ($this->copy_operation() || $this->savecopy == $this->labels['Save']) {
2920 1a2be799 Florent Chuffart
                        $this->page_type = 'P';
2921 1a2be799 Florent Chuffart
                }
2922 1a2be799 Florent Chuffart
                if ($this->delete_operation() || $this->savedelete == $this->labels['Delete']) {
2923 1a2be799 Florent Chuffart
                        $this->page_type = 'D';
2924 1a2be799 Florent Chuffart
                }
2925 1a2be799 Florent Chuffart
                // Restore backups (if exists)
2926 1a2be799 Florent Chuffart
                foreach (array_keys($this->fdd) as $column) {
2927 1a2be799 Florent Chuffart
                        foreach (array_keys($this->fdd[$column]) as $col_option) {
2928 1a2be799 Florent Chuffart
                                if ($col_option[strlen($col_option) - 1] != '~')
2929 1a2be799 Florent Chuffart
                                        continue;
2930 1a2be799 Florent Chuffart
2931 1a2be799 Florent Chuffart
                                $this->fdd[$column][substr($col_option, 0, strlen($col_option) - 1)]
2932 1a2be799 Florent Chuffart
                                        = $this->fdd[$column][$col_option];
2933 1a2be799 Florent Chuffart
                                unset($this->fdd[$column][$col_option]);
2934 1a2be799 Florent Chuffart
                        }
2935 1a2be799 Florent Chuffart
                }
2936 1a2be799 Florent Chuffart
                foreach (array_keys($this->fdd) as $column) {
2937 1a2be799 Florent Chuffart
                        foreach (array_keys($this->fdd[$column]) as $col_option) {
2938 1a2be799 Florent Chuffart
                                if (! strchr($col_option, '|')) {
2939 1a2be799 Florent Chuffart
                                        continue;
2940 1a2be799 Florent Chuffart
                                }
2941 1a2be799 Florent Chuffart
                                $col_ar = explode('|', $col_option, 2);
2942 1a2be799 Florent Chuffart
                                if (! stristr($col_ar[1], $this->page_type)) {
2943 1a2be799 Florent Chuffart
                                        continue;
2944 1a2be799 Florent Chuffart
                                }
2945 1a2be799 Florent Chuffart
                                // Make field backups
2946 1a2be799 Florent Chuffart
                                $this->fdd[$column][$col_ar[0] .'~'] = $this->fdd[$column][$col_ar[0]];
2947 1a2be799 Florent Chuffart
                                $this->fdd[$column][$col_option.'~'] = $this->fdd[$column][$col_option];
2948 1a2be799 Florent Chuffart
                                // Set particular field
2949 1a2be799 Florent Chuffart
                                $this->fdd[$column][$col_ar[0]] = $this->fdd[$column][$col_option];
2950 1a2be799 Florent Chuffart
                                unset($this->fdd[$column][$col_option]);
2951 1a2be799 Florent Chuffart
                        }
2952 1a2be799 Florent Chuffart
                }
2953 1a2be799 Florent Chuffart
        } /* }}} */
2954 1a2be799 Florent Chuffart
2955 1a2be799 Florent Chuffart
        function recreate_displayed() /* {{{ */
2956 1a2be799 Florent Chuffart
        {
2957 1a2be799 Florent Chuffart
                $field_num            = 0;
2958 1a2be799 Florent Chuffart
                $num_fields_displayed = 0;
2959 1a2be799 Florent Chuffart
                $this->fds            = array();
2960 1a2be799 Florent Chuffart
                $this->fdn            = array();
2961 1a2be799 Florent Chuffart
                $this->displayed      = array();
2962 1a2be799 Florent Chuffart
                $this->guidance       = false;
2963 1a2be799 Florent Chuffart
                foreach (array_keys($this->fdd) as $key) {
2964 1a2be799 Florent Chuffart
                        if (preg_match('/^\d+$/', $key)) { // skipping numeric keys
2965 1a2be799 Florent Chuffart
                                continue;
2966 1a2be799 Florent Chuffart
                        }
2967 1a2be799 Florent Chuffart
                        $this->fds[$field_num] = $key;
2968 1a2be799 Florent Chuffart
                        $this->fdn[$key] = $field_num;
2969 1a2be799 Florent Chuffart
                        /* We must use here displayed() function, because displayed[] array
2970 1a2be799 Florent Chuffart
                           is not created yet. We will simultaneously create that array as well. */
2971 1a2be799 Florent Chuffart
                        if ($this->displayed[$field_num] = $this->displayed($field_num)) {
2972 1a2be799 Florent Chuffart
                                $num_fields_displayed++;
2973 1a2be799 Florent Chuffart
                        }
2974 1a2be799 Florent Chuffart
                        if (is_array(@$this->fdd[$key]['values']) && ! isset($this->fdd[$key]['values']['table'])) {
2975 1a2be799 Florent Chuffart
                                foreach ($this->fdd[$key]['values'] as $val) {
2976 1a2be799 Florent Chuffart
                                        $this->fdd[$key]['values2'][$val] = $val;
2977 1a2be799 Florent Chuffart
                                }
2978 1a2be799 Florent Chuffart
                                unset($this->fdd[$key]['values']);
2979 1a2be799 Florent Chuffart
                        }
2980 1a2be799 Florent Chuffart
                        isset($this->fdd[$key]['help']) && $this->guidance = true;
2981 1a2be799 Florent Chuffart
                        $this->fdd[$field_num] = $this->fdd[$key];
2982 1a2be799 Florent Chuffart
                        $field_num++;
2983 1a2be799 Florent Chuffart
                }
2984 1a2be799 Florent Chuffart
                $this->num_fds              = $field_num;
2985 1a2be799 Florent Chuffart
                $this->num_fields_displayed = $num_fields_displayed;
2986 1a2be799 Florent Chuffart
                $this->key_num              = array_search($this->key, $this->fds);
2987 1a2be799 Florent Chuffart
                /* Adds first displayed column into sorting fields by replacing last
2988 1a2be799 Florent Chuffart
                   array entry. Also remove duplicite values and change column names to
2989 1a2be799 Florent Chuffart
                   their particular field numbers.
2990 1a2be799 Florent Chuffart

2991 1a2be799 Florent Chuffart
                   Note that entries like [0]=>'9' [1]=>'-9' are correct and they will
2992 1a2be799 Florent Chuffart
                   have desirable sorting behaviour. So there is no need to remove them.
2993 1a2be799 Florent Chuffart
                 */
2994 1a2be799 Florent Chuffart
                $this->sfn = array_unique($this->sfn);
2995 1a2be799 Florent Chuffart
                $check_ar = array();
2996 1a2be799 Florent Chuffart
                foreach ($this->sfn as $key => $val) {
2997 1a2be799 Florent Chuffart
                        if (preg_match('/^[-]?\d+$/', $val)) { // skipping numeric keys
2998 1a2be799 Florent Chuffart
                                $val = abs($val);
2999 1a2be799 Florent Chuffart
                                if (in_array($val, $check_ar) || $this->password($val)) {
3000 1a2be799 Florent Chuffart
                                        unset($this->sfn[$key]);
3001 1a2be799 Florent Chuffart
                                } else {
3002 1a2be799 Florent Chuffart
                                        $check_ar[] = $val;
3003 1a2be799 Florent Chuffart
                                }
3004 1a2be799 Florent Chuffart
                                continue;
3005 1a2be799 Florent Chuffart
                        }
3006 1a2be799 Florent Chuffart
                        if ($val[0] == '-') {
3007 1a2be799 Florent Chuffart
                                $val = substr($val, 1);
3008 1a2be799 Florent Chuffart
                                $minus = '-';
3009 1a2be799 Florent Chuffart
                        } else {
3010 1a2be799 Florent Chuffart
                                $minus = '';
3011 1a2be799 Florent Chuffart
                        }
3012 1a2be799 Florent Chuffart
                        if (($val = array_search($val, $this->fds)) === false || $this->password($val)) {
3013 1a2be799 Florent Chuffart
                                unset($this->sfn[$key]);
3014 1a2be799 Florent Chuffart
                        } else {
3015 1a2be799 Florent Chuffart
                                $val = intval($val);
3016 1a2be799 Florent Chuffart
                                if (in_array($val, $check_ar)) {
3017 1a2be799 Florent Chuffart
                                        unset($this->sfn[$key]);
3018 1a2be799 Florent Chuffart
                                } else {
3019 1a2be799 Florent Chuffart
                                        $this->sfn[$key] = $minus.$val;
3020 1a2be799 Florent Chuffart
                                        $check_ar[] = $val;
3021 1a2be799 Florent Chuffart
                                }
3022 1a2be799 Florent Chuffart
                        }
3023 1a2be799 Florent Chuffart
                }
3024 1a2be799 Florent Chuffart
                $this->sfn = array_unique($this->sfn);
3025 1a2be799 Florent Chuffart
                return true;
3026 1a2be799 Florent Chuffart
        } /* }}} */
3027 1a2be799 Florent Chuffart
3028 1a2be799 Florent Chuffart
        function backward_compatibility() /* {{{ */
3029 1a2be799 Florent Chuffart
        {
3030 1a2be799 Florent Chuffart
                foreach (array_keys($this->fdd) as $column) {
3031 1a2be799 Florent Chuffart
                        // move ['required'] to ['js']['required']
3032 1a2be799 Florent Chuffart
                        if (! isset($this->fdd[$column]['js']['required']) && isset($this->fdd[$column]['required'])) {
3033 1a2be799 Florent Chuffart
                                $this->fdd[$column]['js']['required'] = $this->fdd[$column]['required'];
3034 1a2be799 Florent Chuffart
                        }
3035 1a2be799 Florent Chuffart
                        // move 'HWR' flags from ['options'] into ['input']
3036 1a2be799 Florent Chuffart
                        if (isset($this->fdd[$column]['options'])) {
3037 1a2be799 Florent Chuffart
                                stristr($this->fdd[$column]['options'], 'H') && $this->fdd[$column]['input'] .= 'H';
3038 1a2be799 Florent Chuffart
                                stristr($this->fdd[$column]['options'], 'W') && $this->fdd[$column]['input'] .= 'W';
3039 1a2be799 Florent Chuffart
                                stristr($this->fdd[$column]['options'], 'R') && $this->fdd[$column]['input'] .= 'R';
3040 1a2be799 Florent Chuffart
                        }
3041 1a2be799 Florent Chuffart
                }
3042 1a2be799 Florent Chuffart
        } /* }}} */
3043 1a2be799 Florent Chuffart
3044 1a2be799 Florent Chuffart
        /*
3045 1a2be799 Florent Chuffart
         * Error handling function
3046 1a2be799 Florent Chuffart
         */
3047 1a2be799 Florent Chuffart
        function error($message, $additional_info = '') /* {{{ */
3048 1a2be799 Florent Chuffart
        {
3049 1a2be799 Florent Chuffart
                echo '<h1>phpMyEdit error: ',htmlspecialchars($message),'</h1>',"\n";
3050 1a2be799 Florent Chuffart
                if ($additional_info != '') {
3051 1a2be799 Florent Chuffart
                        echo '<hr size="1" />',htmlspecialchars($additional_info);
3052 1a2be799 Florent Chuffart
                }
3053 1a2be799 Florent Chuffart
                return false;
3054 1a2be799 Florent Chuffart
        } /* }}} */
3055 1a2be799 Florent Chuffart
3056 1a2be799 Florent Chuffart
        /*
3057 1a2be799 Florent Chuffart
         * Database connection function
3058 1a2be799 Florent Chuffart
         */
3059 1a2be799 Florent Chuffart
        function connect() /* {{{ */
3060 1a2be799 Florent Chuffart
        {
3061 1a2be799 Florent Chuffart
                if (isset($this->dbh)) {
3062 1a2be799 Florent Chuffart
                        return true;
3063 1a2be799 Florent Chuffart
                }
3064 1a2be799 Florent Chuffart
                if (!isset($this->db)) {
3065 1a2be799 Florent Chuffart
                        $this->error('no database defined');
3066 1a2be799 Florent Chuffart
                        return false;
3067 1a2be799 Florent Chuffart
                }
3068 1a2be799 Florent Chuffart
                if (!isset ($this->tb)) {
3069 1a2be799 Florent Chuffart
                        $this->error('no table defined');
3070 1a2be799 Florent Chuffart
                        return false;
3071 1a2be799 Florent Chuffart
                }
3072 1a2be799 Florent Chuffart
                $this->sql_connect();
3073 1a2be799 Florent Chuffart
                if (!$this->dbh) {
3074 1a2be799 Florent Chuffart
                        $this->error('could not connect to SQL');
3075 1a2be799 Florent Chuffart
                        return false;
3076 1a2be799 Florent Chuffart
                }
3077 1a2be799 Florent Chuffart
                return true;
3078 1a2be799 Florent Chuffart
        } /* }}} */
3079 1a2be799 Florent Chuffart
        
3080 1a2be799 Florent Chuffart
        /*
3081 1a2be799 Florent Chuffart
         * The workhorse
3082 1a2be799 Florent Chuffart
         */
3083 1a2be799 Florent Chuffart
        function execute() /* {{{ */
3084 1a2be799 Florent Chuffart
        {
3085 1a2be799 Florent Chuffart
                //  DEBUG -  uncomment to enable
3086 1a2be799 Florent Chuffart
                /*
3087 1a2be799 Florent Chuffart
                //phpinfo();
3088 1a2be799 Florent Chuffart
                $this->print_get_vars();
3089 1a2be799 Florent Chuffart
                $this->print_post_vars();
3090 1a2be799 Florent Chuffart
                $this->print_vars();
3091 1a2be799 Florent Chuffart
                echo "<pre>query opts:\n";
3092 1a2be799 Florent Chuffart
                echo print_r($this->query_opts);
3093 1a2be799 Florent Chuffart
                echo "</pre>\n";
3094 1a2be799 Florent Chuffart
                echo "<pre>get vars:\n";
3095 1a2be799 Florent Chuffart
                echo print_r($this->get_opts);
3096 1a2be799 Florent Chuffart
                echo "</pre>\n";
3097 1a2be799 Florent Chuffart
                 */
3098 1a2be799 Florent Chuffart
3099 1a2be799 Florent Chuffart
                // Let's do explicit quoting - it's safer
3100 1a2be799 Florent Chuffart
                // set_magic_quotes_runtime(0);
3101 1a2be799 Florent Chuffart
                // Checking if language file inclusion was successful
3102 1a2be799 Florent Chuffart
                if (! is_array($this->labels)) {
3103 1a2be799 Florent Chuffart
                        $this->error('could not locate language files', 'searched path: '.$this->dir['lang']);
3104 1a2be799 Florent Chuffart
                        return false;
3105 1a2be799 Florent Chuffart
                }
3106 1a2be799 Florent Chuffart
                // Database connection
3107 1a2be799 Florent Chuffart
                if ($this->connect() == false) {
3108 1a2be799 Florent Chuffart
                        return false;
3109 1a2be799 Florent Chuffart
                }
3110 1a2be799 Florent Chuffart
3111 1a2be799 Florent Chuffart
                /*
3112 1a2be799 Florent Chuffart
                 * ======================================================================
3113 1a2be799 Florent Chuffart
                 * Pass 3: process any updates generated if the user has selected
3114 1a2be799 Florent Chuffart
                 * a save or cancel button during Pass 2
3115 1a2be799 Florent Chuffart
                 * ======================================================================
3116 1a2be799 Florent Chuffart
                 */
3117 1a2be799 Florent Chuffart
                // Cancel button - Cancel Triggers
3118 1a2be799 Florent Chuffart
                if ($this->add_canceled() || $this->copy_canceled()) {
3119 1a2be799 Florent Chuffart
                        $this->exec_triggers_simple('insert', 'cancel');
3120 1a2be799 Florent Chuffart
                }
3121 1a2be799 Florent Chuffart
                if ($this->view_canceled()) {
3122 1a2be799 Florent Chuffart
                        $this->exec_triggers_simple('select', 'cancel');
3123 1a2be799 Florent Chuffart
                }
3124 1a2be799 Florent Chuffart
                if ($this->change_canceled()) {
3125 1a2be799 Florent Chuffart
                        $this->exec_triggers_simple('update', 'cancel');
3126 1a2be799 Florent Chuffart
                }
3127 1a2be799 Florent Chuffart
                if ($this->delete_canceled()) {
3128 1a2be799 Florent Chuffart
                        $this->exec_triggers_simple('delete', 'cancel');
3129 1a2be799 Florent Chuffart
                }
3130 1a2be799 Florent Chuffart
                // Save/More Button - database operations
3131 1a2be799 Florent Chuffart
                if ($this->saveadd == $this->labels['Save'] || $this->savecopy == $this->labels['Save']) {
3132 1a2be799 Florent Chuffart
                        $this->add_enabled() && $this->do_add_record();
3133 1a2be799 Florent Chuffart
                        unset($this->saveadd);
3134 1a2be799 Florent Chuffart
                        unset($this->savecopy);
3135 1a2be799 Florent Chuffart
                        $this->recreate_fdd();
3136 1a2be799 Florent Chuffart
                }
3137 1a2be799 Florent Chuffart
                elseif ($this->moreadd == $this->labels['More']) {
3138 1a2be799 Florent Chuffart
                        $this->add_enabled() && $this->do_add_record();
3139 1a2be799 Florent Chuffart
                        $this->operation = $this->labels['Add']; // to force add operation
3140 1a2be799 Florent Chuffart
                        $this->recreate_fdd();
3141 1a2be799 Florent Chuffart
                        $this->recreate_displayed();
3142 1a2be799 Florent Chuffart
                        $this->backward_compatibility();
3143 1a2be799 Florent Chuffart
                }
3144 1a2be799 Florent Chuffart
                elseif ($this->savechange == $this->labels['Save']) {
3145 1a2be799 Florent Chuffart
                        $this->change_enabled() && $this->do_change_record();
3146 1a2be799 Florent Chuffart
                        unset($this->savechange);
3147 1a2be799 Florent Chuffart
                        $this->recreate_fdd();
3148 1a2be799 Florent Chuffart
                }
3149 1a2be799 Florent Chuffart
                elseif ($this->morechange == $this->labels['Apply']) {
3150 1a2be799 Florent Chuffart
                        $this->change_enabled() && $this->do_change_record();
3151 1a2be799 Florent Chuffart
                        $this->operation = $this->labels['Change']; // to force change operation
3152 1a2be799 Florent Chuffart
                        $this->recreate_fdd();
3153 1a2be799 Florent Chuffart
                        $this->recreate_displayed();
3154 1a2be799 Florent Chuffart
                        $this->backward_compatibility();
3155 1a2be799 Florent Chuffart
                }
3156 1a2be799 Florent Chuffart
                elseif ($this->savedelete == $this->labels['Delete']) {
3157 1a2be799 Florent Chuffart
                        $this->delete_enabled() && $this->do_delete_record();
3158 1a2be799 Florent Chuffart
                        unset($this->savedelete);
3159 1a2be799 Florent Chuffart
                        $this->recreate_fdd();
3160 1a2be799 Florent Chuffart
                }
3161 1a2be799 Florent Chuffart
3162 1a2be799 Florent Chuffart
                /*
3163 1a2be799 Florent Chuffart
                 * ======================================================================
3164 1a2be799 Florent Chuffart
                 * Pass 2: display an input/edit/confirmation screen if the user has
3165 1a2be799 Florent Chuffart
                 * selected an editing button on Pass 1 through this page
3166 1a2be799 Florent Chuffart
                 * ======================================================================
3167 1a2be799 Florent Chuffart
                 */
3168 1a2be799 Florent Chuffart
                if ($this->add_operation()
3169 1a2be799 Florent Chuffart
                                || $this->change_operation() || $this->delete_operation()
3170 1a2be799 Florent Chuffart
                                || $this->view_operation()   || $this->copy_operation()) {
3171 1a2be799 Florent Chuffart
                        $this->display_record();
3172 1a2be799 Florent Chuffart
                }
3173 1a2be799 Florent Chuffart
3174 1a2be799 Florent Chuffart
                /*
3175 1a2be799 Florent Chuffart
                 * ======================================================================
3176 1a2be799 Florent Chuffart
                 * Pass 1 and Pass 3: display the SQL table in a scrolling window on
3177 1a2be799 Florent Chuffart
                 * the screen (skip this step in 'Add More' mode)
3178 1a2be799 Florent Chuffart
                 * ======================================================================
3179 1a2be799 Florent Chuffart
                 */
3180 1a2be799 Florent Chuffart
                else {
3181 1a2be799 Florent Chuffart
                        $this->list_table();
3182 1a2be799 Florent Chuffart
                }
3183 1a2be799 Florent Chuffart
3184 1a2be799 Florent Chuffart
                $this->sql_disconnect();
3185 1a2be799 Florent Chuffart
                if ($this->display['time'] && $this->timer != null) {
3186 38e8e479 Florent Chuffart
                        echo $this->timer->end(),' milliseconds';
3187 1a2be799 Florent Chuffart
                }
3188 1a2be799 Florent Chuffart
        } /* }}} */
3189 1a2be799 Florent Chuffart
3190 1a2be799 Florent Chuffart
        /*
3191 1a2be799 Florent Chuffart
         * Class constructor
3192 1a2be799 Florent Chuffart
         */
3193 1a2be799 Florent Chuffart
        function phpMyEdit($opts) /* {{{ */
3194 1a2be799 Florent Chuffart
        {
3195 1a2be799 Florent Chuffart
                // Set desirable error reporting level
3196 1a2be799 Florent Chuffart
                $error_reporting = error_reporting(E_ALL & ~E_NOTICE);
3197 1a2be799 Florent Chuffart
                // Database handle variables
3198 1a2be799 Florent Chuffart
                $this->sql_delimiter();
3199 1a2be799 Florent Chuffart
                if (isset($opts['dbh'])) {
3200 1a2be799 Florent Chuffart
                        $this->close_dbh = false;
3201 1a2be799 Florent Chuffart
                        $this->dbh = $opts['dbh'];
3202 1a2be799 Florent Chuffart
                        $this->dbp = '';
3203 1a2be799 Florent Chuffart
                } else {
3204 1a2be799 Florent Chuffart
                        $this->close_dbh = true;
3205 1a2be799 Florent Chuffart
                        $this->dbh = null;
3206 1a2be799 Florent Chuffart
                        $this->dbp = $this->sd.$opts['db'].$this->ed.'.';
3207 1a2be799 Florent Chuffart
                        $this->hn  = $opts['hn'];
3208 1a2be799 Florent Chuffart
                        $this->un  = $opts['un'];
3209 1a2be799 Florent Chuffart
                        $this->pw  = $opts['pw'];
3210 1a2be799 Florent Chuffart
                        $this->db  = $opts['db'];
3211 1a2be799 Florent Chuffart
                }
3212 1a2be799 Florent Chuffart
                $this->tb  = $opts['tb'];
3213 1a2be799 Florent Chuffart
                // Other variables
3214 1a2be799 Florent Chuffart
                $this->key       = $opts['key'];
3215 1a2be799 Florent Chuffart
                $this->key_type  = $opts['key_type'];
3216 1a2be799 Florent Chuffart
                $this->inc       = $opts['inc'];
3217 1a2be799 Florent Chuffart
                $this->options   = $opts['options'];
3218 1a2be799 Florent Chuffart
                $this->fdd       = $opts['fdd'];
3219 1a2be799 Florent Chuffart
                $this->multiple  = intval($opts['multiple']);
3220 1a2be799 Florent Chuffart
                $this->multiple <= 0 && $this->multiple = 2;
3221 1a2be799 Florent Chuffart
                $this->filters   = is_array(@$opts['filters']) ? join(' AND ', $opts['filters']) : @$opts['filters'];
3222 1a2be799 Florent Chuffart
                $this->triggers  = @$opts['triggers'];
3223 1a2be799 Florent Chuffart
                $this->notify    = @$opts['notify'];
3224 1a2be799 Florent Chuffart
                $this->logtable  = @$opts['logtable'];
3225 1a2be799 Florent Chuffart
                $this->page_name = @$opts['page_name'];
3226 1a2be799 Florent Chuffart
                if (! isset($this->page_name)) {
3227 1a2be799 Florent Chuffart
                        $this->page_name = basename($this->get_server_var('PHP_SELF'));
3228 1a2be799 Florent Chuffart
                        isset($this->page_name) || $this->page_name = $this->tb;
3229 1a2be799 Florent Chuffart
                } 
3230 1a2be799 Florent Chuffart
                $this->display['query'] = @$opts['display']['query'];
3231 1a2be799 Florent Chuffart
                $this->display['sort']  = @$opts['display']['sort'];
3232 1a2be799 Florent Chuffart
                $this->display['time']  = @$opts['display']['time'];
3233 1a2be799 Florent Chuffart
                if ($this->display['time']) {
3234 1a2be799 Florent Chuffart
                        $this->timer = new phpMyEdit_timer();
3235 1a2be799 Florent Chuffart
                }
3236 1a2be799 Florent Chuffart
                $this->display['tabs'] = isset($opts['display']['tabs'])
3237 1a2be799 Florent Chuffart
                        ? $opts['display']['tabs'] : true;
3238 1a2be799 Florent Chuffart
                $this->display['form'] = isset($opts['display']['form'])
3239 1a2be799 Florent Chuffart
                        ? $opts['display']['form'] : true;
3240 1a2be799 Florent Chuffart
                $this->display['num_records'] = isset($opts['display']['num_records'])
3241 1a2be799 Florent Chuffart
                        ? $opts['display']['num_records'] : true;
3242 1a2be799 Florent Chuffart
                $this->display['num_pages'] = isset($opts['display']['num_pages'])
3243 1a2be799 Florent Chuffart
                        ? $opts['display']['num_pages'] : true;
3244 1a2be799 Florent Chuffart
                // Creating directory variables
3245 1a2be799 Florent Chuffart
                $this->dir['root'] = dirname(realpath(__FILE__))
3246 1a2be799 Florent Chuffart
                        . (strlen(dirname(realpath(__FILE__))) > 0 ? '/' : '');
3247 1a2be799 Florent Chuffart
                $this->dir['lang'] = $this->dir['root'].'lang/';
3248 1a2be799 Florent Chuffart
                // Creating URL variables
3249 1a2be799 Florent Chuffart
                $this->url['images'] = 'images/';
3250 1a2be799 Florent Chuffart
                isset($opts['url']['images']) && $this->url['images'] = $opts['url']['images'];
3251 1a2be799 Florent Chuffart
                // CSS classes policy
3252 1a2be799 Florent Chuffart
                $this->css = @$opts['css'];
3253 1a2be799 Florent Chuffart
                !isset($this->css['separator']) && $this->css['separator'] = '-';
3254 1a2be799 Florent Chuffart
                !isset($this->css['prefix'])    && $this->css['prefix']    = 'pme';
3255 1a2be799 Florent Chuffart
                !isset($this->css['page_type']) && $this->css['page_type'] = false;
3256 1a2be799 Florent Chuffart
                !isset($this->css['position'])  && $this->css['position']  = false;
3257 1a2be799 Florent Chuffart
                !isset($this->css['divider'])   && $this->css['divider']   = 2;
3258 1a2be799 Florent Chuffart
                $this->css['divider'] = intval(@$this->css['divider']);
3259 1a2be799 Florent Chuffart
                // JS overall configuration
3260 1a2be799 Florent Chuffart
                $this->js = @$opts['js'];
3261 1a2be799 Florent Chuffart
                !isset($this->js['prefix']) && $this->js['prefix'] = 'PME_js_';
3262 1a2be799 Florent Chuffart
                // DHTML overall configuration
3263 1a2be799 Florent Chuffart
                $this->dhtml = @$opts['dhtml'];
3264 1a2be799 Florent Chuffart
                !isset($this->dhtml['prefix']) && $this->dhtml['prefix'] = 'PME_dhtml_';
3265 1a2be799 Florent Chuffart
                // Navigation
3266 1a2be799 Florent Chuffart
                $this->navigation = @$opts['navigation'];
3267 1a2be799 Florent Chuffart
                if (! $this->nav_buttons() && ! $this->nav_text_links() && ! $this->nav_graphic_links()) {
3268 1a2be799 Florent Chuffart
                        $this->navigation .= 'B'; // buttons are default
3269 1a2be799 Florent Chuffart
                }
3270 1a2be799 Florent Chuffart
                if (! $this->nav_up() && ! $this->nav_down()) {
3271 1a2be799 Florent Chuffart
                        $this->navigation .= 'D'; // down position is default
3272 1a2be799 Florent Chuffart
                }
3273 1a2be799 Florent Chuffart
                $this->buttons = $opts['buttons'];
3274 1a2be799 Florent Chuffart
                // Language labels (must go after navigation)
3275 1a2be799 Florent Chuffart
                $this->labels = $this->make_language_labels(isset($opts['language'])
3276 1a2be799 Florent Chuffart
                                ? $opts['language'] : $this->get_server_var('HTTP_ACCEPT_LANGUAGE'));
3277 1a2be799 Florent Chuffart
                // CGI variables
3278 1a2be799 Florent Chuffart
                $this->cgi = @$opts['cgi'];
3279 1a2be799 Florent Chuffart
                $this->cgi['persist'] = '';
3280 1a2be799 Florent Chuffart
                if (@is_array($opts['cgi']['persist'])) {
3281 1a2be799 Florent Chuffart
                        foreach ($opts['cgi']['persist'] as $key => $val) {
3282 1a2be799 Florent Chuffart
                                if (is_array($val)) {
3283 1a2be799 Florent Chuffart
                                        foreach($val as $key2 => $val2) {
3284 1a2be799 Florent Chuffart
                                                $this->cgi['persist'] .= '&'.rawurlencode($key)
3285 1a2be799 Florent Chuffart
                                                        .'['.rawurlencode($key2).']='.rawurlencode($val2);
3286 1a2be799 Florent Chuffart
                                        }
3287 1a2be799 Florent Chuffart
                                } else {
3288 1a2be799 Florent Chuffart
                                        $this->cgi['persist'] .= '&'.rawurlencode($key).'='.rawurlencode($val);
3289 1a2be799 Florent Chuffart
                                }
3290 1a2be799 Florent Chuffart
                        }
3291 1a2be799 Florent Chuffart
                }
3292 1a2be799 Florent Chuffart
                foreach (array('operation', 'sys', 'data') as $type) {
3293 1a2be799 Florent Chuffart
                        if (! isset($this->cgi['prefix'][$type])) {
3294 1a2be799 Florent Chuffart
                                $this->cgi['prefix'][$type] = $this->get_default_cgi_prefix($type);
3295 1a2be799 Florent Chuffart
                        }
3296 1a2be799 Florent Chuffart
                }
3297 1a2be799 Florent Chuffart
                // Sorting variables
3298 1a2be799 Florent Chuffart
                $this->sfn   = $this->get_sys_cgi_var('sfn');
3299 1a2be799 Florent Chuffart
                isset($this->sfn)             || $this->sfn          = array();
3300 1a2be799 Florent Chuffart
                is_array($this->sfn)          || $this->sfn          = array($this->sfn);
3301 1a2be799 Florent Chuffart
                isset($opts['sort_field'])    || $opts['sort_field'] = array();
3302 1a2be799 Florent Chuffart
                is_array($opts['sort_field']) || $opts['sort_field'] = array($opts['sort_field']);
3303 1a2be799 Florent Chuffart
                $this->sfn   = array_merge($this->sfn, $opts['sort_field']);
3304 1a2be799 Florent Chuffart
                // Form variables all around
3305 1a2be799 Florent Chuffart
                $this->fl    = intval($this->get_sys_cgi_var('fl'));
3306 1a2be799 Florent Chuffart
                $this->fm    = intval($this->get_sys_cgi_var('fm'));
3307 1a2be799 Florent Chuffart
//                $old_page = ceil($this->fm / abs($this->inc)) + 1;
3308 1a2be799 Florent Chuffart
                $this->qfn   = $this->get_sys_cgi_var('qfn');
3309 1a2be799 Florent Chuffart
                $this->sw    = $this->get_sys_cgi_var('sw');
3310 1a2be799 Florent Chuffart
                $this->rec   = $this->get_sys_cgi_var('rec', '');
3311 1a2be799 Florent Chuffart
                $this->navop = $this->get_sys_cgi_var('navop');
3312 1a2be799 Florent Chuffart
                $navfmup     = $this->get_sys_cgi_var('navfmup');
3313 1a2be799 Florent Chuffart
                $navfmdown   = $this->get_sys_cgi_var('navfmdown');
3314 1a2be799 Florent Chuffart
                $navpnup     = $this->get_sys_cgi_var('navpnup');
3315 1a2be799 Florent Chuffart
                $navpndown   = $this->get_sys_cgi_var('navpndown');
3316 1a2be799 Florent Chuffart
                if($navfmdown!=NULL && $navfmdown != $this->fm) $this->navfm = $navfmdown;
3317 1a2be799 Florent Chuffart
                elseif($navfmup!=NULL && $navfmup != $this->fm) $this->navfm = $navfmup;
3318 1a2be799 Florent Chuffart
                elseif($navpndown!=NULL && ($navpndown-1)*$this->inc != $this->fm) $this->navfm = ($navpndown-1)*$this->inc;
3319 1a2be799 Florent Chuffart
                elseif($navpnup!=NULL && ($navpnup-1)*$this->inc != $this->fm) $this->navfm = ($navpnup-1)*$this->inc;
3320 1a2be799 Florent Chuffart
                else $this->navfm = $this->fm; 
3321 1a2be799 Florent Chuffart
                $this->operation = $this->get_sys_cgi_var('operation');
3322 1a2be799 Florent Chuffart
                $oper_prefix_len = strlen($this->cgi['prefix']['operation']);
3323 1a2be799 Florent Chuffart
                if (! strncmp($this->cgi['prefix']['operation'], $this->operation, $oper_prefix_len)) {
3324 1a2be799 Florent Chuffart
                        $this->operation = $this->labels[substr($this->operation, $oper_prefix_len)];
3325 1a2be799 Florent Chuffart
                }
3326 1a2be799 Florent Chuffart
                $this->saveadd      = $this->get_sys_cgi_var('saveadd');
3327 1a2be799 Florent Chuffart
                $this->moreadd      = $this->get_sys_cgi_var('moreadd');
3328 1a2be799 Florent Chuffart
                $this->canceladd    = $this->get_sys_cgi_var('canceladd');
3329 1a2be799 Florent Chuffart
                $this->savechange   = $this->get_sys_cgi_var('savechange');
3330 1a2be799 Florent Chuffart
                $this->morechange   = $this->get_sys_cgi_var('morechange');
3331 1a2be799 Florent Chuffart
                $this->cancelchange = $this->get_sys_cgi_var('cancelchange');
3332 1a2be799 Florent Chuffart
                $this->savecopy     = $this->get_sys_cgi_var('savecopy');
3333 1a2be799 Florent Chuffart
                $this->cancelcopy   = $this->get_sys_cgi_var('cancelcopy');
3334 1a2be799 Florent Chuffart
                $this->savedelete   = $this->get_sys_cgi_var('savedelete');
3335 1a2be799 Florent Chuffart
                $this->canceldelete = $this->get_sys_cgi_var('canceldelete');
3336 1a2be799 Florent Chuffart
                $this->cancelview   = $this->get_sys_cgi_var('cancelview');
3337 1a2be799 Florent Chuffart
                // Filter setting
3338 1a2be799 Florent Chuffart
                if (isset($this->sw)) {
3339 1a2be799 Florent Chuffart
                        $this->sw == $this->labels['Search'] && $this->fl = 1;
3340 1a2be799 Florent Chuffart
                        $this->sw == $this->labels['Hide']   && $this->fl = 0;
3341 1a2be799 Florent Chuffart
                        //$this->sw == $this->labels['Clear']  && $this->fl = 0;
3342 1a2be799 Florent Chuffart
                }
3343 1a2be799 Florent Chuffart
                // TAB names
3344 1a2be799 Florent Chuffart
                $this->tabs = array();
3345 1a2be799 Florent Chuffart
                // Setting key_delim according to key_type
3346 1a2be799 Florent Chuffart
                if ($this->key_type == 'real') {
3347 1a2be799 Florent Chuffart
                        /* If 'real' key_type does not work,
3348 1a2be799 Florent Chuffart
                           try change MySQL datatype from float to double */
3349 1a2be799 Florent Chuffart
                        $this->rec = doubleval($this->rec);
3350 1a2be799 Florent Chuffart
                        $this->key_delim = '';
3351 1a2be799 Florent Chuffart
                } elseif ($this->key_type == 'int') {
3352 1a2be799 Florent Chuffart
                        $this->rec = intval($this->rec);
3353 1a2be799 Florent Chuffart
                        $this->key_delim = '';
3354 1a2be799 Florent Chuffart
                } else {
3355 1a2be799 Florent Chuffart
                        $this->key_delim = '"';
3356 1a2be799 Florent Chuffart
                        // $this->rec remains unmodified
3357 1a2be799 Florent Chuffart
                }
3358 1a2be799 Florent Chuffart
                // Specific $fdd modifications depending on performed action
3359 1a2be799 Florent Chuffart
                $this->recreate_fdd();
3360 1a2be799 Florent Chuffart
                // Extract SQL Field Names and number of fields
3361 1a2be799 Florent Chuffart
                $this->recreate_displayed();
3362 1a2be799 Florent Chuffart
                // Issue backward compatibility
3363 1a2be799 Florent Chuffart
                $this->backward_compatibility();
3364 1a2be799 Florent Chuffart
                // Gathering query options
3365 1a2be799 Florent Chuffart
                $this->gather_query_opts();
3366 1a2be799 Florent Chuffart
                // Call to action
3367 1a2be799 Florent Chuffart
                !isset($opts['execute']) && $opts['execute'] = 1;
3368 1a2be799 Florent Chuffart
                $opts['execute'] && $this->execute();
3369 1a2be799 Florent Chuffart
                // Restore original error reporting level
3370 1a2be799 Florent Chuffart
                error_reporting($error_reporting);
3371 1a2be799 Florent Chuffart
        } /* }}} */
3372 1a2be799 Florent Chuffart
3373 1a2be799 Florent Chuffart
}
3374 1a2be799 Florent Chuffart
3375 1a2be799 Florent Chuffart
/* Modeline for ViM {{{
3376 1a2be799 Florent Chuffart
 * vim:set ts=4:
3377 1a2be799 Florent Chuffart
 * vim600:fdm=marker fdl=0 fdc=0:
3378 1a2be799 Florent Chuffart
 * }}} */
3379 1a2be799 Florent Chuffart
3380 1a2be799 Florent Chuffart
?>