76. File Comparison Report

Produced on Mon May 12 13:04:40 2008 UTC. This report uses XHTML and CSS2, and is best viewed with a reasonably standards compliant browser such as the latest version of Firefox or Internet Explorer. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

76.1 Files compared

# Location File Last Modified
1 Dolphin-v.6.0.5\admin profile_fields.php Thu Sep 20 08:58:42 2007 UTC
2 Mon May 12 13:04:40 2008 UTC

76.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 2177

76.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

76.4 Active regular expressions

No regular expressions were active.

76.5 Comparison detail

1   <?php    
2      
3   /********* ********** ********** ********** ********** ********** ********** ******    
4   *                              D olphin Sma rt Communi ty Builder    
5   *                                 --------- --------    
6   *     begi n                 : M on Mar 23  2006    
7   *     copy right             : ( C) 2006 Bo onEx Group    
8   *     webs ite               : h ttp://www. boonex.com /    
9   * This fil e is part  of Dolphin  - Smart C ommunity B uilder    
10   *    
11   * Dolphin  is free so ftware. Th is work is  licensed  under a Cr eative Com mons Attri bution 3.0  License.     
12   * http://c reativecom mons.org/l icenses/by /3.0/    
13   *    
14   * Dolphin  is distrib uted in th e hope tha t it will  be useful,  but WITHO UT ANY WAR RANTY;    
15   * without  even the i mplied war ranty of   MERCHANTAB ILITY or F ITNESS FOR  A PARTICU LAR PURPOS E.    
16   * See the  Creative C ommons Att ribution 3 .0 License  for more  details.     
17   * You shou ld have re ceived a c opy of the  Creative  Commons At tribution  3.0 Licens e along wi th Dolphin    
18   * see lice nse.txt fi le; if not , write to  marketing @boonex.co m    
19   ********** ********** ********** ********** ********** ********** ********** *****/    
20      
21   /*    
22    * Page fo r displayi ng and edi ting profi le fields.    
23    */    
24      
25   require_on ce( '../in c/header.i nc.php' );    
26   require_on ce( BX_DIR ECTORY_PAT H_INC . 'd esign.inc. php' );    
27   require_on ce( BX_DIR ECTORY_PAT H_INC . 'p rofiles.in c.php' );    
28   require_on ce( BX_DIR ECTORY_PAT H_INC . 'a dmin_desig n.inc.php'  );    
29   require_on ce( BX_DIR ECTORY_PAT H_INC . 'u tils.inc.p hp' );    
30   require_on ce( BX_DIR ECTORY_PAT H_INC . 'l anguages.i nc.php' );    
31      
32   // Check i f administ rator is l ogged in.   If not di splay logi n form.    
33   $logged['a dmin'] = m ember_auth ( 1 );    
34      
35   $_page['he ader'] = ' Profile Fi elds';    
36   $_page['cs s_name'] =  'profile_ fields.css ';    
37      
38      
39   // List of  mandatory  fields.    
40   $mandatory  = array (    
41       'NickN ame',    
42       'Sex',    
43       'Email ',    
44       'Looki ngFor',    
45       'Passw ord',    
46       'Passw ord,Passwo rd1',    
47       'Statu s',    
48       'Count ry',    
49       'City' ,    
50       'Tags' ,    
51       'zip',    
52       'Headl ine',    
53       'Descr iptionMe',    
54       'DateO fBirth',    
55       'Email Flag',    
56       'Email Notify',    
57       );    
58      
59   TopCodeAdm in();    
60   ContentBlo ckHead("") ;    
61      
62   // Check G ET variabl es.    
63   if ( $_GET ['ID'] &&  ( 'move_up ' == $_GET ['action']  ) )    
64   {    
65       $query _str = "SE LECT * FRO M `Profile sDesc` ORD ER BY `ord er` ASC";    
66       $res =  db_res( $ query_str  );    
67       // Pro cess movin g    
68       if ( ! move_up( $ _GET['ID'] , $res ) )    
69           ec ho "<p><sp an style=\ "color:#ff 6666;font- weight:bol d\">Can't  move up fi eld.</span ></p>\n";    
70       else    
71           $m odified =  (int)$_GET ['ID'];    
72   }    
73      
74   if ( $_GET ['ID'] &&  ( 'move_do wn' == $_G ET['action '] ) )    
75   {    
76       $query _str = "SE LECT * FRO M `Profile sDesc` ORD ER BY `ord er` ASC";    
77       $res =  db_res( $ query_str  );    
78       // Pro cess movin g    
79       if ( ! move_down(  $_GET['ID '], $res )  )    
80           ec ho "<p><sp an style=\ "color:#ff 6666;font- weight:bol d\">Can't  move down  field.</sp an></p>\n" ;    
81       else    
82           $m odified =  (int)$_GET ['ID'];    
83   }    
84      
85   if ( $_GET ['ID'] &&  ( 'delete'  == $_GET[ 'action']  ) )    
86   {    
87       $query _str = "SE LECT * FRO M `Profile sDesc` ORD ER BY `ord er` ASC";    
88       $res =  db_res( $ query_str  );    
89       // Pro cess delet ing    
90       delete _field( $_ GET['ID'],  $res );    
91       echo " <p><span s tyle=\"col or:#ff6666 ;font-weig ht:bold\"> Field dele ted.</span ></p>\n";    
92   }    
93      
94   // Display  add or ed it form    
95   if ( 'add'  == $_GET[ 'action']  || 'edit'  == $_GET[' action'] )    
96   {    
97       // Dis play if us er just go t into the  page, or  refreshed  field type ,    
98       // oth erwise if  the user p ressed 'Ad d' button,  add new f ield.    
99       if ( ! $_POST['ad d_button']  )    
100       {    
101           di splay_cont rols();    
102       }    
103       else    
104       {    
105           //  Check inp ut paramet ers.    
106           $e rrors = ch eck_parame ters( $_PO ST['field_ type'] );    
107           if  ( count(  $errors )  > 0 )    
108           {    
109                // Displ ay error m essages an d controls  for enter ing.    
110                foreach  ( $errors  as $value  )    
111                {    
112                    echo  "<span st yle=\"colo r:#ff6666; font-weigh t:bold\">E rror: $val ue</span>< br />";    
113                }    
114                display_ controls() ;    
115           }    
116           el se    
117           {    
118                // Perfo rm databas e actions    
119                edit_or_ add_field( );    
120           }    
121       }    
122   }    
123   else    
124   {    
125       echo " <p class=t ext><a hre f=\"profil e_fields.p hp?action= add\">Add  new field< /a></p>\n" ;    
126       // Get  a list of  all field s.    
127       $query _str = "SE LECT * FRO M `Profile sDesc` ORD ER BY `ord er` ASC";    
128       $res =  db_res( $ query_str  );    
129       displa y_fields(  $res );    
130   }    
131      
132   ContentBlo ckFoot();    
133      
134   BottomCode ();    
135      
136   /**    
137    * Display  profile f ields in a  table.    
138    * @param  $res       Recordset  of profile  fields.    
139    */    
140   function d isplay_fie lds( $res  )    
141   {    
142       global  $modified ;    
143       global  $mandator y;    
144      
145       echo " <table wid th=\"100%\ " border=\ "1\" class =\"profile _fields\"> \n";    
146       echo '    
147           <t r style="f ont-weight :bold">    
148                <td>name </td>    
149                <td>capt ion</td>    
150                <td>type </td>    
151                <td cols pan="2">or der</td>    
152                <td>del< /td>    
153                <td>edit </td>    
154           </ tr>    
155           ';    
156       $odd_c nt = 0;    
157       $cnt =  0;    
158       $total _rows = my sql_num_ro ws( $res ) ;    
159       // Col lect all f ields and  determine  which of t hem are gr oup    
160       while  ( $row = m ysql_fetch _array( $r es ) )    
161       {    
162           $r ows[$cnt]  = $row;    
163           $f name = get _field_nam e( $row );    
164           $r ows[$cnt][ 'db_name']  = $fname;    
165           $f ield_group s[$fname][ 'count']++ ;    
166           $c nt++;    
167       }    
168      
169       for ($ cnt = 0; $ cnt < $tot al_rows; $ cnt++)    
170       {    
171           if  ( $modifi ed == $row s[$cnt]['I D'] )    
172           {    
173                // Class  for modif ied row.    
174                $class =  'class="m odified_ro w"';    
175           }    
176           el se if ( '0 ' == $rows [$cnt]['ty pe'] )    
177           {    
178                // Class  for secti on row.    
179                $class =  'class="s ection"';    
180           }    
181           el se if ( 0  == $odd_cn t % 2 )    
182           {    
183                // Class  for even  row.    
184                $class =  'class="e ven_row"';    
185           }    
186           el se    
187           {    
188                $class =  'class="o dd_row"';    
189           }    
190           ec ho "<tr $c lass>\n";    
191      
192           //  Generate  table data  class.    
193           $n amedisp =  _t( $rows[ $cnt]['nam edisp'] );    
194           if  ( '0' ==  $rows[$cnt ]['type']  )    
195           {    
196                if ( $mo dified ==  $rows[$cnt ]['ID'] )    
197                {    
198                    $cla ss = 'clas s="modifie d_row"';    
199                }    
200                else    
201                {    
202                    $cla ss = 'clas s="section "';    
203                }    
204                echo "<t d colspan= \"3\">$nam edisp</td> \n";    
205                $odd_cnt  = 0;    
206           }    
207           el se    
208           {    
209                if ( $mo dified ==  $rows[$cnt ]['ID'] )    
210                {    
211                    $cla ss = 'clas s="modifie d_row"';    
212                }    
213                else if  ( 0 == $od d_cnt % 2  )    
214                {    
215                    $cla ss = 'clas s="odd_row "';    
216                }    
217                else    
218                {    
219                    $cla ss = '';    
220                }    
221      
222                if ( $ro ws[$cnt][' group_mark '] != '' )    
223                {    
224                    $row _style = ' style="col or:#777777 "';    
225                }    
226                else    
227                {    
228                    $row _style = ' ';    
229                }    
230      
231                $type_na me = get_t ype_name(  $rows[$cnt ]['type']  );    
232                echo "<t d width=\" 30%\" $row _style>{$r ows[$cnt][ 'name']}</ td>\n";    
233                echo "<t d width=\" 30%\" $row _style>$na medisp</td >\n";    
234                echo "<t d $row_sty le>$type_n ame</td>\n ";    
235                $odd_cnt ++;    
236           }    
237      
238           //  Generate  links.    
239           //  Generate  'Move up'  link.    
240           if  ( 0 == $c nt )    
241           {    
242                // Don't  generate  any link f or the fir st field.    
243                echo "<t d width=\" 15px\"></t d>\n";    
244           }    
245           el se    
246           {    
247                $move_up  = "profil e_fields.p hp?ID={$ro ws[$cnt][' ID']}&acti on=move_up ";    
248                echo "<t d width=\" 15px\"><a  href=\"$mo ve_up\"><i mg src=\"i mages/arro w_up.gif\"  alt=\"Mov e up\" bor der=\"0\"/ ></a></td> \n";    
249           }    
250           //  Generate  'Move down ' link.    
251           if  ( $cnt ==  ($total_r ows - 1) )    
252           {    
253                // Don't  generate  any link f or the las t field.    
254                echo "<t d width=\" 15px\">&nb sp;</td>\n ";    
255           }    
256           el se    
257           {    
258                $move_do wn = "prof ile_fields .php?ID={$ rows[$cnt] ['ID']}&ac tion=move_ down";    
259                echo "<t d width=\" 15px\"><a  href=\"$mo ve_down\"> <img src=\ "images/ar row_down.g if\" alt=\ "Move down \" border= \"0\"/></a ></td>\n";    
260           }    
261      
262           //  Check if  field can  be deleted .    
263           if  ( !in_arr ay( $rows[ $cnt]['db_ name'], $m andatory )  )    
264           {    
265                echo "<t d width=\" 15px\" ali gn=\"cente r\"><a hre f=\"profil e_fields.p hp?ID={$ro ws[$cnt][I D]}&action =delete\"> <img src=\ "images/de lete.gif\"  alt=\"Del ete\" bord er=\"0\" t itle=\"Del ete\" /></ a></td>\n" ;    
266           }    
267           el se    
268           {    
269                echo "<t d width=\" 15px\">&nb sp;</td>\n ";    
270           }    
271      
272           if  ( false ! = field_ed itable( $r ows[$cnt]  ) )    
273           {    
274                echo "<t d width=\" 15px\" ali gn=\"cente r\"><a hre f=\"profil e_fields.p hp?ID={$ro ws[$cnt][' ID']}&acti on=edit\"> <img src=\ "images/ed it.gif\" a lt=\"Edit\ " border=\ "0\" title =\"Edit\"  /></a></td >\n";    
275           }    
276           el se    
277           {    
278                echo "<t d width=\" 15px\"></t d>\n";    
279           }    
280      
281           ec ho "</tr>\ n";    
282       }    
283       echo " </table>\n ";    
284   }    
285      
286      
287   /**    
288    * Move th e field up .    
289    * @param  $ID        Field ID.    
290    */    
291   function m ove_up( $I D, $res )    
292   {    
293       // Mak e int from  ID    
294       $ID =  (int) $ID;    
295      
296       // Col lect field s and dete rmine whic h of them  are group    
297       $cnt =  0;    
298       while  ( $row = m ysql_fetch _array( $r es ) )    
299       {    
300           $r ows[$cnt]  = $row;    
301           $f name = get _field_nam e( $row );    
302           $r ows[$cnt][ 'db_name']  = $fname;    
303           $f ield_group s[$fname][ 'count']++ ;    
304           if  ( $row['I D'] == $ID  )    
305                $field_i ndex = $cn t;    
306           $c nt++;    
307       }    
308      
309       // Num ber of fie lds in cur rent group    
310       $src_g roup_field s_num = $f ield_group s[$rows[$f ield_index ]['db_name ']]['count '];    
311       // Num ber of fie lds in des tination g roup    
312       $dest_ group_fiel ds_num = $ field_grou ps[$rows[$ field_inde x - 1]['db _name']][' count'];    
313      
314       if ( $ field_inde x == 0 )    
315           re turn false ;    
316      
317       // Get  the order  of the gi ven field.    
318       $src_o rder = $ro ws[$field_ index]['or der'];    
319       $src_i d = $rows[ $field_ind ex]['ID'];    
320      
321       // Get  the order  of the fi eld preced ing the gi ven one.    
322       $dest_ order = $r ows[$field _index - 1 ]['order'] ;    
323       $dest_ id = $rows [$field_in dex - 1][' ID'];    
324      
325       // Thi s is for p revent gro up interse ction    
326       if ( $ src_group_ fields_num  > 1 )    
327           $s rc_group_c har = 'G';    
328       else    
329           $s rc_group_c har = ( $r ows[$field _index]['g roup_mark' ] == '' ?  ' ' : $row s[$field_i ndex]['gro up_mark']  );    
330       if ( $ dest_group _fields_nu m > 1 )    
331           $d est_group_ char = 'G' ;    
332       else    
333           $d est_group_ char = ( $ rows[$fiel d_index -  1]['group_ mark'] ==  '' ? ' ' :  $rows[$fi eld_index  - 1]['grou p_mark'] ) ;    
334       if ( $ dest_group _char . $s rc_group_c har == 'GG ' && $rows [$field_in dex]['db_n ame'] == $ rows[$fiel d_index -  1]['db_nam e'] )    
335       {    
336           $s rc_group_c har = ( $r ows[$field _index]['g roup_mark' ] == '' ?  ' ' : $row s[$field_i ndex]['gro up_mark']  );    
337           $d est_group_ char = ( $ rows[$fiel d_index -  1]['group_ mark'] ==  '' ? ' ' :  $rows[$fi eld_index  - 1]['grou p_mark'] ) ;    
338       }    
339      
340       switch  ( $dest_g roup_char  . $src_gro up_char )    
341       {    
342           ca se 'GG':    
343                $border_ info['firs t_start']  = $field_i ndex - $de st_group_f ields_num;    
344                $border_ info['firs t_end'] =  $field_ind ex - 1;    
345                $border_ info['seco nd_start']  = $field_ index;    
346                $border_ info['seco nd_end'] =  $field_in dex + $src _group_fie lds_num -  1;    
347                swap_gro ups_order(  $rows, $b order_info  );    
348                break;    
349      
350           ca se 'Gb':    
351                $border_ info['firs t_start']  = $field_i ndex - $de st_group_f ields_num;    
352                $border_ info['firs t_end'] =  $field_ind ex - 1;    
353                $border_ info['seco nd_start']  = $field_ index;    
354                // Deter mine index  of last f ield in th e row    
355                $row_end _index = $ field_inde x + 1;    
356                while (  $rows[$row _end_index ]['group_m ark'] != ' e' && $row s[$row_end _index]['g roup_mark' ] != '' )    
357                    $row _end_index ++;    
358                if ( $ro ws[$row_en d_index][' group_mark '] == '' )    
359                    $row _end_index --;    
360                $border_ info['seco nd_end'] =  $row_end_ index;    
361                swap_gro ups_order(  $rows, $b order_info  );    
362                break;    
363      
364           ca se 'eG':    
365                // Deter mine index  of last f ield in th e row    
366                $row_sta rt_index =  $field_in dex - 2;    
367                while (  $rows[$row _start_ind ex]['group _mark'] !=  'b' && $r ows[$row_s tart_index ]['group_m ark'] != ' ' )    
368                    $row _start_ind ex--;    
369                if ( $ro ws[$row_st art_index] ['group_ma rk'] == ''  )    
370                    $row _start_ind ex++;    
371                $border_ info['firs t_start']  = $row_sta rt_index;    
372                $border_ info['firs t_end'] =  $field_ind ex - 1;    
373                $border_ info['seco nd_start']  = $field_ index;    
374                $border_ info['seco nd_end'] =  $field_in dex + $src _group_fie lds_num -  1;    
375                swap_gro ups_order(  $rows, $b order_info  );    
376                break;    
377      
378           ca se 'G ':    
379                // Move  lower fiel d up    
380                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$field_in dex - $des t_group_fi elds_num][ 'order'] . " WHERE `I D` = $src_ id";    
381                db_res(  $query_str  );    
382                for ($i  = $field_i ndex - $de st_group_f ields_num;  $i < $fie ld_index;  $i++)    
383                {    
384                    // C hange orde r of the c urrent fie ld.    
385                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i +  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
386                    db_r es( $query _str );    
387                }    
388                break;    
389      
390           ca se ' G':    
391                // Move  upper fiel d down    
392                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$field_in dex + $src _group_fie lds_num -  1]['order' ] ." WHERE  `ID` = $d est_id";    
393                db_res(  $query_str  );    
394                for ($i  = $field_i ndex; $i <  $field_in dex + $src _group_fie lds_num; $ i++)    
395                {    
396                    // C hange orde r of the c urrent fie ld.    
397                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i -  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
398                    db_r es( $query _str );    
399                }    
400                break;    
401      
402           ca se ' b':    
403                // Deter mine index  of last f ield in th e row    
404                $row_end _index = $ field_inde x + 1;    
405                while (  $rows[$row _end_index ]['group_m ark'] != ' e' && $row s[$row_end _index]['g roup_mark' ] != '' )    
406                    $row _end_index ++;    
407                if ( $ro ws[$row_en d_index][' group_mark '] == '' )    
408                    $row _end_index --;    
409      
410                // Move  upper fiel d down    
411                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$row_end_ index]['or der'] ." W HERE `ID`  = $dest_id ";    
412                db_res(  $query_str  );    
413                for ($i  = $field_i ndex; $i < = $row_end _index; $i ++)    
414                {    
415                    // C hange orde r of the c urrent fie ld.    
416                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i -  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
417                    db_r es( $query _str );    
418                }    
419      
420                break;    
421      
422           ca se 'bc':    
423                // Chang e order fo r the give n field.    
424                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'b' WHERE  `ID` = $sr c_id";    
425                db_res(  $query_str  );    
426      
427                // Chang e order fo r the prec eding fiel d.    
428                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' c' WHERE ` ID` = $des t_id";    
429                db_res(  $query_str  );    
430      
431                break;    
432      
433           ca se 'be':    
434                // Chang e order fo r the give n field.    
435                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'b' WHERE  `ID` = $sr c_id";    
436                db_res(  $query_str  );    
437      
438                // Chang e order fo r the prec eding fiel d.    
439                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' e' WHERE ` ID` = $des t_id";    
440                db_res(  $query_str  );    
441      
442                break;    
443      
444           ca se 'ce':    
445                // Chang e order fo r the give n field.    
446                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'c' WHERE  `ID` = $sr c_id";    
447                db_res(  $query_str  );    
448      
449                // Chang e order fo r the prec eding fiel d.    
450                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' e' WHERE ` ID` = $des t_id";    
451                db_res(  $query_str  );    
452      
453                break;    
454      
455           ca se 'e ':    
456                // Deter mine index  of last f ield in th e row    
457                $row_sta rt_index =  $field_in dex - 2;    
458                while (  $rows[$row _start_ind ex]['group _mark'] !=  'b' && $r ows[$row_s tart_index ]['group_m ark'] != ' ' )    
459                    $row _start_ind ex--;    
460                if ( $ro ws[$row_st art_index] ['group_ma rk'] == ''  )    
461                    $row _start_ind ex++;    
462                // Move  lower fiel d up    
463                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$row_star t_index][' order'] ."  WHERE `ID ` = $src_i d";    
464                db_res(  $query_str  );    
465                for ($i  = $row_sta rt_index;  $i < $fiel d_index; $ i++)    
466                {    
467                    // C hange orde r of the c urrent fie ld.    
468                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i +  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
469                    db_r es( $query _str );    
470                }    
471      
472                break;    
473      
474           ca se '  ':    
475           ca se 'cc':    
476                // Chang e order fo r the give n field.    
477                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der WHERE  `ID` = $sr c_id";    
478                db_res(  $query_str  );    
479      
480                // Chang e order fo r the prec eding fiel d.    
481                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er WHERE ` ID` = $des t_id";    
482                db_res(  $query_str  );    
483       }    
484      
485       return  true;    
486   }    
487      
488   /**    
489    * Move th e field do wn.    
490    * @param  $ID        Field ID.    
491    */    
492   function m ove_down(  $ID, $res  )    
493   {    
494       // Mak e int from  ID    
495       $ID =  (int) $ID;    
496      
497       // Col lect field s and dete rmine whic h of them  are group    
498       $cnt =  0;    
499       $total _rows = my sql_num_ro ws( $res ) ;    
500       while  ( $row = m ysql_fetch _array( $r es ) )    
501       {    
502           $r ows[$cnt]  = $row;    
503           $f name = get _field_nam e( $row );    
504           $r ows[$cnt][ 'db_name']  = $fname;    
505           $f ield_group s[$fname][ 'count']++ ;    
506           if  ( $row['I D'] == $ID  )    
507                $field_i ndex = $cn t;    
508           $c nt++;    
509       }    
510      
511       // Num ber of fie lds in cur rent group    
512       $src_g roup_field s_num = $f ield_group s[$rows[$f ield_index ]['db_name ']]['count '];    
513       // Num ber of fie lds in des tination g roup    
514       $dest_ group_fiel ds_num = $ field_grou ps[$rows[$ field_inde x + 1]['db _name']][' count'];    
515      
516       if ( $ field_inde x == ($tot al_rows -  1) )    
517           re turn false ;    
518      
519       // Get  the order  of the gi ven field.    
520       $src_o rder = $ro ws[$field_ index]['or der'];    
521       $src_i d = $rows[ $field_ind ex]['ID'];    
522      
523       // Get  the order  of the fi eld preced ing the gi ven one.    
524       $dest_ order = $r ows[$field _index + 1 ]['order'] ;    
525       $dest_ id = $rows [$field_in dex + 1][' ID'];    
526      
527       // Thi s is for p revent gro up interse ction    
528       if ( $ src_group_ fields_num  > 1 )    
529           $s rc_group_c har = 'G';    
530       else    
531           $s rc_group_c har = ( $r ows[$field _index]['g roup_mark' ] == '' ?  ' ' : $row s[$field_i ndex]['gro up_mark']  );    
532       if ( $ dest_group _fields_nu m > 1 )    
533           $d est_group_ char = 'G' ;    
534       else    
535           $d est_group_ char = ( $ rows[$fiel d_index +  1]['group_ mark'] ==  '' ? ' ' :  $rows[$fi eld_index  + 1]['grou p_mark'] ) ;    
536       if ( $ src_group_ char . $de st_group_c har == 'GG ' && $rows [$field_in dex]['db_n ame'] == $ rows[$fiel d_index +  1]['db_nam e'] )    
537       {    
538           $s rc_group_c har = ( $r ows[$field _index]['g roup_mark' ] == '' ?  ' ' : $row s[$field_i ndex]['gro up_mark']  );    
539           $d est_group_ char = ( $ rows[$fiel d_index +  1]['group_ mark'] ==  '' ? ' ' :  $rows[$fi eld_index  + 1]['grou p_mark'] ) ;    
540       }    
541      
542       switch  ( $src_gr oup_char .  $dest_gro up_char )    
543       {    
544           ca se 'GG':    
545                $border_ info['firs t_start']  = $field_i ndex - $sr c_group_fi elds_num +  1;    
546                $border_ info['firs t_end'] =  $field_ind ex;    
547                $border_ info['seco nd_start']  = $field_ index + 1;    
548                $border_ info['seco nd_end'] =  $field_in dex + $des t_group_fi elds_num;    
549                swap_gro ups_order(  $rows, $b order_info  );    
550                break;    
551      
552           ca se 'Gb':    
553                $border_ info['firs t_start']  = $field_i ndex - $sr c_group_fi elds_num +  1;    
554                $border_ info['firs t_end'] =  $field_ind ex;    
555                $border_ info['seco nd_start']  = $field_ index + 1;    
556                // Deter mine index  of last f ield in th e row    
557                $row_end _index = $ field_inde x + 2;    
558                while (  $rows[$row _end_index ]['group_m ark'] != ' e' && $row s[$row_end _index]['g roup_mark' ] != '' )    
559                    $row _end_index ++;    
560                if ( $ro ws[$row_en d_index][' group_mark '] == '' )    
561                    $row _end_index --;    
562                $border_ info['seco nd_end'] =  $row_end_ index;    
563                swap_gro ups_order(  $rows, $b order_info  );    
564                break;    
565      
566           ca se 'eG':    
567                // Deter mine index  of last f ield in th e row    
568                $row_sta rt_index =  $field_in dex - 1;    
569                while (  $rows[$row _start_ind ex]['group _mark'] !=  'b' && $r ows[$row_s tart_index ]['group_m ark'] != ' ' )    
570                    $row _start_ind ex--;    
571                if ( $ro ws[$row_st art_index] ['group_ma rk'] == ''  )    
572                    $row _start_ind ex++;    
573                $border_ info['firs t_start']  = $row_sta rt_index;    
574                $border_ info['firs t_end'] =  $field_ind ex;    
575                $border_ info['seco nd_start']  = $field_ index + 1;    
576                $border_ info['seco nd_end'] =  $field_in dex + $des t_group_fi elds_num;    
577                swap_gro ups_order(  $rows, $b order_info  );    
578                break;    
579      
580           ca se 'G ':    
581                // Move  lower fiel d up    
582                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$field_in dex - $src _group_fie lds_num +  1]['order' ] ." WHERE  `ID` = $d est_id";    
583                db_res(  $query_str  );    
584                for ($i  = $field_i ndex - $sr c_group_fi elds_num +  1; $i <=  $field_ind ex; $i++)    
585                {    
586                    // C hange orde r of the c urrent fie ld.    
587                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i +  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
588                    db_r es( $query _str );    
589                }    
590                break;    
591      
592           ca se ' G':    
593                // Move  upper fiel d down    
594                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$field_in dex + $des t_group_fi elds_num][ 'order'] . " WHERE `I D` = $src_ id";    
595                db_res(  $query_str  );    
596                for ($i  = $field_i ndex + 1;  $i <= $fie ld_index +  $dest_gro up_fields_ num; $i++)    
597                {    
598                    // C hange orde r of the c urrent fie ld.    
599                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i -  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
600                    db_r es( $query _str );    
601                }    
602                break;    
603      
604           ca se ' b':    
605                // Deter mine index  of last f ield in th e row    
606                $row_end _index = $ field_inde x + 2;    
607                while (  $rows[$row _end_index ]['group_m ark'] != ' e' && $row s[$row_end _index]['g roup_mark' ] != '' )    
608                    $row _end_index ++;    
609                if ( $ro ws[$row_en d_index][' group_mark '] == '' )    
610                    $row _end_index --;    
611      
612                // Move  upper fiel d down    
613                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$row_end_ index]['or der'] ." W HERE `ID`  = $src_id" ;    
614                db_res(  $query_str  );    
615                for ($i  = $field_i ndex + 1;  $i <= $row _end_index ; $i++)    
616                {    
617                    // C hange orde r of the c urrent fie ld.    
618                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i -  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
619                    db_r es( $query _str );    
620                }    
621      
622                break;    
623      
624           ca se 'bc':    
625                // Chang e order fo r the give n field.    
626                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'c' WHERE  `ID` = $sr c_id";    
627                db_res(  $query_str  );    
628      
629                // Chang e order fo r the foll owing fiel d.    
630                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' b' WHERE ` ID` = $des t_id";    
631                db_res(  $query_str  );    
632      
633                break;    
634      
635           ca se 'be':    
636                // Chang e order fo r the give n field.    
637                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'e' WHERE  `ID` = $sr c_id";    
638                db_res(  $query_str  );    
639      
640                // Chang e order fo r the foll owing fiel d.    
641                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' b' WHERE ` ID` = $des t_id";    
642                db_res(  $query_str  );    
643      
644                break;    
645      
646           ca se 'ce':    
647                // Chang e order fo r the give n field.    
648                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der, `grou p_mark` =  'e' WHERE  `ID` = $sr c_id";    
649                db_res(  $query_str  );    
650      
651                // Chang e order fo r the foll owing fiel d.    
652                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er, `group _mark` = ' c' WHERE ` ID` = $des t_id";    
653                db_res(  $query_str  );    
654      
655                break;    
656      
657           ca se 'e ':    
658                // Deter mine index  of last f ield in th e row    
659                $row_sta rt_index =  $field_in dex - 1;    
660                while (  $rows[$row _start_ind ex]['group _mark'] !=  'b' && $r ows[$row_s tart_index ]['group_m ark'] != ' ' )    
661                    $row _start_ind ex--;    
662                if ( $ro ws[$row_st art_index] ['group_ma rk'] == ''  )    
663                    $row _start_ind ex++;    
664      
665                // Move  lower fiel d up    
666                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = ". $rows [$row_star t_index][' order'] ."  WHERE `ID ` = $dest_ id";    
667                db_res(  $query_str  );    
668                for ($i  = $row_sta rt_index;  $i <= $fie ld_index;  $i++)    
669                {    
670                    // C hange orde r of the c urrent fie ld.    
671                    $que ry_str = " UPDATE `Pr ofilesDesc ` SET `ord er` = ". $ rows[$i +  1]['order' ] ." WHERE  `ID` = ".  $rows[$i] ['ID'];    
672                    db_r es( $query _str );    
673                }    
674      
675                break;    
676      
677           ca se '  ':    
678           ca se 'cc':    
679                // Chang e order fo r the give n field.    
680                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $dest_or der WHERE  `ID` = $sr c_id";    
681                db_res(  $query_str  );    
682      
683                // Chang e order fo r the foll owing fiel d.    
684                $query_s tr = "UPDA TE `Profil esDesc` SE T `order`  = $src_ord er WHERE ` ID` = $des t_id";    
685                db_res(  $query_str  );    
686       }    
687      
688       return  true;    
689   }    
690      
691   /**    
692    * Get typ e name giv en its abb reviation.    
693    * @param  $abbr      Type name  abbreviati on.    
694    * @retval            Type full  name.    
695    */    
696   function g et_type_na me( $abbr  )    
697   {    
698       switch  ( $abbr )    
699       {    
700           ca se 'c': re turn 'edit  box';    
701           ca se 'e': re turn 'drop -down box' ;    
702           ca se 'en': r eturn 'dro p-down box  (numeric) ';    
703           ca se 'a': re turn 'memo ';    
704           ca se '0': re turn 'divi der';    
705           ca se 'r': re turn 'refe rence';    
706           ca se 'rb': r eturn 'set  of radio  buttons';    
707           ca se 'set':  return 'se t of check boxes';    
708           ca se 'p': re turn 'pass word';    
709           ca se 'rr': r eturn 'ref erence to  reference' ;    
710           de fault: ret urn $abbr;    
711       }    
712   }    
713      
714   /**    
715    * Display  controls  for adding  new field .    
716    */    
717   function d isplay_con trols()    
718   {    
719       // Dis play contr ols for ad ding new f ield or ed iting exis ting one.    
720      
721       //  Se lect value s from dat abase    
722       if ( ' edit' == $ _GET['acti on'] && $_ GET['ID']  )    
723       {    
724           $q _str = "SE LECT * FRO M `Profile sDesc` WHE RE `ID` =  {$_GET['ID ']}";    
725           $f ield = db_ arr( $q_st r );    
726       }    
727      
728       // Sta rt display ing...    
729       if ( ! $field )    
730       {    
731           //  'Add' for m.    
732           ec ho "<form  name=\"add _field\" a ction=\"pr ofile_fiel ds.php?act ion=add\"  method=\"p ost\">\n";    
733       }    
734       else    
735       {    
736           //  'Edit' fo rm.    
737           ec ho "<form  name=\"add _field\" a ction=\"pr ofile_fiel ds.php?act ion=edit&I D={$_GET[' ID']}\" me thod=\"pos t\">\n";    
738       }    
739       echo " <input typ e=\"hidden \" name=\" reenter\"  value=\"on \" />";    
740       echo " <table sty le=\"font- size: 11px \" width=\ "100%\" ce llspacing= \"10px\">\ n";    
741       echo " <tr><td wi dth=\"30%\ ">\n";    
742      
743      
744       // Dis play field  type.    
745       echo " <tr><td>Fi eld type</ td>\n";    
746       // Get  value.    
747       if ( i sset( $fie ld ) )    
748       {    
749           $v alue = $fi eld['type' ];    
750       }    
751       else    
752       {    
753           $v alue = iss et( $_GET[ 'field_typ e'] ) ? $_ GET['field _type'] :  ( isset( $ _POST['fie ld_type']  ) ? $_POST ['field_ty pe'] : 'c'  ) ;    
754       }    
755       $read_ only = iss et( $field  );    
756       displa y_field_ty pe( $value , $read_on ly );    
757       // Set  field typ e.    
758       $field _type = $v alue;    
759      
760       // Dis play drop- down box f or selecti ng the fie ld    
761       // aft er which t o insert t he new one .    
762       if ( ! isset( $fi eld ) )    
763       {    
764           ec ho "<tr><t d>Add new  field</td> \n";    
765           //  Get defau lt value.    
766           $v alue = $_P OST['inser t_after']  ? $_POST[' insert_aft er'] : '';    
767           di splay_inse rt_after(  $value );    
768       }    
769      
770       // Dis play contr ol for fie ld name.    
771       $value  = isset(  $field ) ?  $field['n ame'] : $_ POST['fiel d_name'];    
772       displa y_field_na me( $value , $read_on ly );    
773      
774       // Dis play contr ol for ent ering capt ion.    
775       echo " <tr><td>Ca ption</td> \n";    
776       if ( $ field && ! $_POST['re enter'] )    
777       {    
778           $v alue = $fi eld['named isp'];    
779           $v alue = _t(  $value );    
780       }    
781       else    
782       {    
783           $v alue = $_P OST['capti on'];    
784       }    
785       echo " <td><input  type=\"te xt\" name= \"caption\ " value=\" $value\" s ize=\"60\"  />\n";    
786      
787       // Dis play contr ol for des cription.    
788       if ( $ field_type  != '0' )    
789       {    
790           ec ho "<tr><t d>Descript ion</td>\n ";    
791           if  ( $field  && !$_POST ['reenter' ] )    
792           {    
793                $value =  $field['n amenote'];    
794                $value =  _t( $valu e );    
795           }    
796           el se    
797           {    
798                $value =  $_POST['d esc'];    
799           }    
800           ec ho "<td><i nput type= \"text\" n ame=\"desc \" value=\ "$value\"  size=\"60\ " /></td>\ n";    
801       }    
802      
803       // Dis play contr ol for 'ma ndatory' f ield.    
804       echo " <tr><td>Ma ndatory</t d>";    
805       $check ed = '';    
806       if ( $ field && ! $_POST['re enter'] )    
807       {    
808           if  ( strlen(  $field['c heck'] ) >  0 )    
809           {    
810                $checked  = 'checke d';    
811           }    
812       }    
813       else i f ( 'on' = = $_POST[' mandatory' ] )    
814       {    
815           $c hecked = ' checked';    
816       }    
817       echo " <td><input  type=\"ch eckbox\" n ame=\"mand atory\" $c hecked />< /td></tr>" ;    
818      
819       // Dis play contr ol for err or message .    
820       echo " <tr><td>Er ror messag e</td>";    
821       $value  = '';    
822       if ( $ field && ! $_POST['re enter'] )    
823       {    
824           $v alue = $fi eld['becau se'];    
825           $v alue = _t(  $value );    
826       }    
827       else    
828       {    
829           $v alue = $_P OST['err_m sg'];    
830       }    
831       echo " <td><input  type=\"te xt\" name= \"err_msg\ " value=\" $value\" s ize=\"60\"  /></td></ tr>";    
832      
833       // Dis play contr ol for use r visibili ty.    
834       echo " <tr><td>Vi sible to</ td>\n";    
835       // Che ck if chec kbox is ch ecked :)    
836       $check ed = '';    
837       if ( $ field && ! $_POST['re enter'] )    
838       {    
839           //  Check if  visible to  user.    
840           if  ( strpos(  $field['v isible'],  'user' ) ! == false )    
841           {    
842                $checked  = 'checke d';    
843           }    
844       }    
845       else i f ( 'on' = = $_POST[' visible_to _visitor']  )    
846       {    
847           $c hecked = ' checked';    
848       }    
849       echo " <td><input  type=\"ch eckbox\" n ame=\"visi ble_to_vis itor\" $ch ecked />Vi sitor<br / >";    
850      
851       $check ed = '';    
852       if ( $ field && ! $_POST['re enter'] )    
853       {    
854           //  Check if  visible to  member.    
855           if  ( strpos(  $field['v isible'],  'memb' ) ! == false )    
856           {    
857                $checked  = 'checke d';    
858           }    
859       }    
860       else i f ( 'on' = = $_POST[' visible_to _member']  )    
861       {    
862           $c hecked = ' checked';    
863       }    
864       echo " <input typ e=\"checkb ox\" name= \"visible_ to_member\ " $checked  />Member< br />";    
865      
866       $check ed = '';    
867       if ( $ field && ! $_POST['re enter'] )    
868       {    
869           //  Check if  visible to  admin.    
870           if  ( strpos(  $field['v isible'],  'adm' ) != = false  )    
871           {    
872                $checked  = 'checke d';    
873           }    
874       }    
875       else i f ( 'on' = = $_POST[' visible_to _admin'] )    
876       {    
877           $c hecked = ' checked';    
878       }    
879       echo " <input typ e=\"checkb ox\" name= \"visible_ to_admin\"  $checked  />Admin<br  /></td></ tr>\n";    
880      
881       // Dis play contr ol for edi t possibil ity.    
882       echo " <tr><td>Ed itable for </td>\n";    
883       // Che ck if chec kbox is ch ecked :)    
884       $check ed = '';    
885       if ( $ field && ! $_POST['re enter'] )    
886       {    
887           //  Check if  editable f or member.    
888           if  ( strpos(  $field['e ditable'],  'memb' )  !== false  )    
889           {    
890                $checked  = 'checke d';    
891           }    
892       }    
893       else i f ( 'on' = = $_POST[' editable_f or_member' ] )    
894       {    
895           $c hecked = ' checked';    
896       }    
897       echo " <td><input  type=\"ch eckbox\" n ame=\"edit able_for_m ember\" $c hecked />M ember<br / >";    
898      
899       $check ed = '';    
900       if ( $ field && ! $_POST['re enter'] )    
901       {    
902           //  Check if  editable f or admin.    
903           if  ( strpos(  $field['e ditable'],  'adm' ) ! == false   )    
904           {    
905                $checked  = 'checke d';    
906           }    
907       }    
908       else i f ( 'on' = = $_POST[' editable_f or_admin']  )    
909       {    
910           $c hecked = ' checked';    
911       }    
912       echo " <input typ e=\"checkb ox\" name= \"editable _for_admin \" $checke d />Admin< br /></td> </tr>\n";    
913      
914       // Dis play contr ols for pa ge visibil ity.    
915       echo " <tr><td>Sh ow on page </td>\n";    
916       $check ed = '';    
917       if ( $ field && ! $_POST['re enter'] )    
918       {    
919           //  Check if  visible on  all pages .    
920           if  ( strpos(  $field['s how_on_pag e'], '0' )  !== false  )    
921           {    
922                $checked  = 'checke d';    
923           }    
924       }    
925       else i f ( 'on' = = $_POST[' show_on_al l'] )    
926       {    
927           $c hecked = ' checked';    
928       }    
929       echo " <td><input  type=\"ch eckbox\" n ame=\"show _on_all\"  $checked/> All<br />" ;    
930       $check ed = '';    
931       if ( $ field && ! $_POST['re enter'] )    
932       {    
933           //  Check if  visible on  join page .    
934           if  ( strpos(  $field['s how_on_pag e'], '3' )  !== false  )    
935           {    
936                $checked  = 'checke d';    
937           }    
938       }    
939       else i f ( 'on' = = $_POST[' show_on_jo in'] )    
940       {    
941           $c hecked = ' checked';    
942       }    
943       echo " <input typ e=\"checkb ox\" name= \"show_on_ join\" $ch ecked/>Joi n page<br  />";    
944       $check ed = '';    
945       if ( $ field && ! $_POST['re enter'] )    
946       {    
947           //  Check if  visible on  view prof ile page.    
948           if  ( strpos(  $field['s how_on_pag e'], '7' )  !== false  )    
949           {    
950                $checked  = 'checke d';    
951           }    
952       }    
953       else i f ( 'on' = = $_POST[' show_on_vi ew_profile '] )    
954       {    
955           $c hecked = ' checked';    
956       }    
957       echo " <input typ e=\"checkb ox\" name= \"show_on_ view_profi le\" $chec ked/>View  Profile pa ge<br />";    
958       $check ed = '';    
959       if ( $ field && ! $_POST['re enter'] )    
960       {    
961           //  Check if  visible on  edit prof ile page.    
962           if  ( strpos(  $field['s how_on_pag e'], '25'  ) !== fals e )    
963           {    
964                $checked  = 'checke d';    
965           }    
966       }    
967       else i f ( 'on' = = $_POST[' show_on_ed it_profile '] )    
968       {    
969           $c hecked = ' checked';    
970       }    
971       echo " <input typ e=\"checkb ox\" name= \"show_on_ edit_profi le\" $chec ked/>Edit  Profile pa ge</td></t r>";    
972      
973       // Dis play contr ols specif ic to diff erent inpu t types.    
974       switch  ( $field_ type )    
975       {    
976       case ' c':    
977       case ' p':    
978           ec ho "<tr><t d>Edit box  length</t d>";    
979           if  ( $field  && !$_POST ['reenter' ] )    
980                $value =  $field['e xtra'];    
981           el se    
982                $value =  $_POST['e dit_box_le ngth'];    
983               
984           ec ho "<td><i nput type= \"text\" n ame=\"edit _box_lengt h\" value= \"$value\"  size=\"5\ " /></td>< /tr>";    
985           ec ho "<tr><t d>Min leng th</td>";    
986               
987           if  ( $field  && !$_POST ['reenter' ] )    
988                $value =  $field['m in_length' ];    
989           el se    
990                $value =  $_POST['m in_value'] ;    
991               
992           ec ho "<td><i nput type= \"text\" n ame=\"min_ value\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
993           ec ho "<tr><t d>Max leng th</td>";    
994               
995           if  ( $field  && !$_POST ['reenter' ] )    
996                $value =  $field['m ax_length' ];    
997           el se    
998                $value =  $_POST['m ax_value'] ;    
999               
1000           ec ho "<td><i nput type= \"text\" n ame=\"max_ value\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
1001       break;    
1002       case ' date':    
1003           ec ho "<tr><t d>Max and  Min age</t d>";    
1004           if  ( $field  && !$_POST ['reenter' ] )    
1005                $value =  $field['e xtra'];    
1006           el se    
1007                $value =  $_POST['e dit_box_le ngth'];    
1008               
1009           ec ho "<td><i nput type= \"text\" n ame=\"edit _box_lengt h\" value= \"$value\"  size=\"5\ " /></td>< /tr>";    
1010       break;    
1011      
1012       case ' e':    
1013       case ' rb':    
1014       case ' set':    
1015           if  ( 'e' ==  $field_typ e )    
1016           {    
1017                $caption  = 'Drop-d own choice s<br>(line  by line)' ;    
1018           }    
1019           el se if ( 'r b' == $fie ld_type )    
1020           {    
1021                $caption  = 'Radio  button cho ices<br>(l ine by lin e)';    
1022           }    
1023           el se if ( 's et' == $fi eld_type )    
1024           {    
1025                $caption  = 'Set ch oices<br>( line by li ne)';    
1026           }    
1027           ec ho "<tr><t d>$caption </td>";    
1028           if  ( $field  && !$_POST ['reenter' ] )    
1029           {    
1030                $temp =  explode( " ,", $field ['extra']  );    
1031                // Strip  single qu otes from  beginning  and end an d pass thr ough langu age.    
1032                array_wa lk( $temp,  create_fu nction( '& $value', ' $value = _ t(\'_\'.tr im($value,  "\'"));'  ) );    
1033                $value =  implode(  "\r\n", $t emp );    
1034           }    
1035           el se    
1036           {    
1037                $value =  $_POST['c hoices'];    
1038           }    
1039           // $value = (  $_POST['c hoices'] )  ? $_POST[ 'choices']  : '';    
1040           ec ho "<td><t extarea st yle=\"font -family:Co urier\" na me=\"choic es\" cols= \"30\" row s=\"10\">$ value</tex tarea>";    
1041       break;    
1042      
1043       case ' a':    
1044           ec ho "<tr><t d>Memo row s</td>";    
1045           if  ( $field  && !$_POST ['reenter' ] )    
1046           {    
1047                list( $c ols, $rows  ) = split ( 'x', $fi eld['extra '] );    
1048                $value =  $cols;    
1049      
1050           }    
1051           el se    
1052           {    
1053                $value =  $_POST['m emo_cols'] ;    
1054           }    
1055           ec ho "<td><i nput type= \"text\" n ame=\"memo _rows\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
1056           ec ho "<tr><t d>Memo col umns</td>" ;    
1057           $v alue = $ro ws ? $rows  : $_POST[ 'memo_cols '];    
1058           ec ho "<td><i nput type= \"text\" n ame=\"memo _cols\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
1059           ec ho "<tr><t d>Min leng th</td>";    
1060           if  ( $field  && !$_POST ['reenter' ] )    
1061           {    
1062                $value =  $field['m in_length' ];    
1063           }    
1064           el se    
1065           {    
1066                $value =  $_POST['m in_value'] ;    
1067           }    
1068           ec ho "<td><i nput type= \"text\" n ame=\"min_ value\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
1069           if  ( $field  && !$_POST ['reenter' ] )    
1070           {    
1071                $value =  $field['m ax_length' ];    
1072           }    
1073           el se    
1074           {    
1075                $value =  $_POST['m ax_value'] ;    
1076           }    
1077           ec ho "<tr><t d>Max leng th</td>";    
1078           ec ho "<td><i nput type= \"text\" n ame=\"max_ value\" va lue=\"$val ue\" size= \"5\" /></ td></tr>";    
1079       break;    
1080       }    
1081      
1082       // Dis play contr ols for se arch.    
1083       // 'Al low search ' checkbox .    
1084       if ( $ field_type  != '0' )    
1085       {    
1086           ec ho "<tr><t d>Search t ype</td>";    
1087      
1088           //  Full list    
1089   /*    
1090           $s earch_type s = array  (    
1091                'none' = > 'non-sea rchable',    
1092                'radio'  => 'radio  search',    
1093                'list' = > 'list se arch',    
1094                'check'  => 'enum s earch',    
1095                'dateran ge' => 'da te range s earch',    
1096                'check_s et' => 'ch eckboxes s et search' ,    
1097                'text' = > 'text se arch'    
1098           );    
1099   */    
1100           //  Limited l ist    
1101           sw itch ( $fi eld_type )    
1102           {    
1103                case 'r' :    
1104                case 'e' :    
1105                    $sea rch_types  = array (    
1106                         'none' =>  'non-searc hable',    
1107                         'radio' =>  'radio se arch',    
1108                         'list' =>  'list sear ch',    
1109                         'check' =>  'enum sea rch'    
1110                    );    
1111                break;    
1112                    
1113                case 'da te':    
1114                    $sea rch_types  = array (    
1115                         'none' =>  'non-searc hable',    
1116                         'daterange ' => 'date  range sea rch'    
1117                    );    
1118                break;    
1119      
1120                case 'c' :    
1121                case 'a' :    
1122                case 'p' :    
1123                    $sea rch_types  = array (    
1124                         'none' =>  'non-searc hable',    
1125                         'radio' =>  'radio se arch',    
1126                         'text' =>  'text sear ch'    
1127                    );    
1128                break;    
1129      
1130                case 'rb ':    
1131                    $sea rch_types  = array (    
1132                         'none' =>  'non-searc hable',    
1133                         'radio' =>  'radio se arch',    
1134                         'list' =>  'list sear ch'    
1135                    );    
1136                break;    
1137      
1138                case 'se t':    
1139                    $sea rch_types  = array (    
1140                         'none' =>  'non-searc hable',    
1141                         'check_set ' => 'chec kboxes set  search'    
1142                    );    
1143                break;    
1144      
1145                default:    
1146                    $sea rch_types  = array (    
1147                         'none' =>  'non-searc hable'    
1148                    );    
1149                break;    
1150           }    
1151      
1152           $v alue = 'no ne';    
1153           if  ( $field  && !$_POST ['reenter' ] )    
1154           {    
1155                $value =  $field['s earch_type '];    
1156           }    
1157           el se    
1158           {    
1159                if ( $_G ET['search _t'] )    
1160                    $val ue = $_GET ['search_t '];    
1161                else    
1162                    $val ue = ( iss et( $_POST ['search_t '] ) ? $_P OST['searc h_t'] : 'n one' );    
1163           }    
1164           $s earch_type  = $value;    
1165      
1166           ec ho "<td><s elect name =\"search_ t\" onChan ge=\"javas cript: var  val = thi s.value; w indow.loca tion.href  = 'profile _fields.ph p?action=a dd&field_t ype={$fiel d_type}&se arch_t=' +  val;\">\n ";    
1167           fo reach ( $s earch_type s as $key  => $val )    
1168           {    
1169                if ( 0 = = strcmp(  $value, $k ey ) )    
1170                {    
1171                    echo  "<option  value=\"$k ey\" selec ted>$val</ option>\n" ;    
1172                }    
1173                else    
1174                {    
1175                    echo  "<option  value=\"$k ey\">$val< /option>\n ";    
1176                }    
1177           }    
1178           ec ho "</td>< /tr>\n";    
1179       }    
1180      
1181       // 'In itially hi dden' chec kbox.    
1182       echo " <tr><td>In itially hi dden on se arch page< /td>";    
1183       $check ed = '';    
1184       if ( $ field && ! $_POST['re enter'] )    
1185       {    
1186           $c hecked = ( 1 == $_POS T['search_ hide'] ? ' checked' :  '');    
1187       }    
1188       else i f ( 'on' = = $_POST[' search_hid den'] )    
1189       {    
1190           $c hecked = ' checked';    
1191       }    
1192       echo " <td><input  type=\"ch eckbox\" n ame=\"sear ch_hidden\ " $checked  /></td></ tr>";    
1193      
1194       if ( ' radio' ==  $search_ty pe || 'che ck' == $se arch_type  || 'check_ set' == $s earch_type  )    
1195       {    
1196           //  'Search c olumns' co ntrol.    
1197           $a rr = array ( 1 => '1' , 2 => '2' , 3 => '3' , 4 => '4' , 5 => '5' );    
1198           $i ndex = 0;    
1199           if  ( $field  && !$_POST ['reenter' ] )    
1200           {    
1201                $index =  $field['s earch_cols '];    
1202           }    
1203           el se if ( $_ POST['sear ch_cols']  )    
1204           {    
1205                $index =  $_POST['s earch_cols '];    
1206           }    
1207           ec ho "<tr><t d>Search c olumns<br> (Number of  columns o n search p age)</td>\ n";    
1208           ec ho "<td><s elect name =\"search_ cols\">";    
1209           fo reach ( $a rr as $key  => $value  )    
1210           {    
1211                if ( $in dex == $ke y )    
1212                {    
1213                    echo  "<option  value=\"$k ey\" selec ted>$value </option>\ n";    
1214                }    
1215                else    
1216                {    
1217                    echo  "<option  value=\"$k ey\">$valu e</option> \n";    
1218                }    
1219           }    
1220           ec ho "</sele ct>";    
1221           ec ho "</td>< /tr>";    
1222       }    
1223      
1224       if ( $ field_type  != '0' )    
1225       {    
1226           //  Match typ e combo bo x    
1227           ec ho "<tr><t d>Match ty pe</td>";    
1228           sw itch ( $fi eld_type )    
1229           {    
1230                case 'r' :    
1231                case 'rb ':    
1232                case 'e' :    
1233                    $mat ch_types =  array (    
1234                         'none' =>  'non-match able',    
1235                         'enum' =>  'radio mat ch',    
1236                         'enum_ref'  => 'refer ence match '    
1237                    );    
1238                break;    
1239      
1240                case 'se t':    
1241                    $mat ch_types =  array (    
1242                         'none' =>  'non-match able',    
1243                         'set' => ' checkboxes  set match '    
1244                    );    
1245                break;    
1246      
1247                default:    
1248                    $mat ch_types =  array (    
1249                         'none' =>  'non-match able'    
1250                    );    
1251                break;    
1252           }    
1253      
1254           $v alue = 'no ne';    
1255           if  ( $field  && !$_POST ['reenter' ] )    
1256           {    
1257                $value =  $field['m atch_type' ];    
1258           }    
1259           el se    
1260           {    
1261                $value =  ( isset(  $_POST['ma tch_t'] )  ? $_POST[' match_t']  : 'none' ) ;    
1262           }    
1263      
1264           ec ho "<td><s elect name =\"match_t \" >\n";    
1265           fo reach ( $m atch_types  as $key = > $val )    
1266           {    
1267                if ( 0 = = strcmp(  $value, $k ey ) )    
1268                {    
1269                    echo  "<option  value=\"$k ey\" selec ted>$val</ option>\n" ;    
1270                }    
1271                else    
1272                {    
1273                    echo  "<option  value=\"$k ey\">$val< /option>\n ";    
1274                }    
1275           }    
1276           ec ho "</td>< /tr>\n";    
1277      
1278           //  Match fie ld combo b ox    
1279           ec ho "<tr><t d>Match fi eld</td>\n ";    
1280           //  Get defau lt value.    
1281           if  ( $field  && !$_POST ['reenter' ] )    
1282           {    
1283                $value =  $field['m atch_field '];    
1284           }    
1285           el se    
1286           {    
1287                $value =  $_POST['m atch_f'] ?  $_POST['m atch_f'] :  'none';    
1288           }    
1289           di splay_matc h_field( $ value );    
1290      
1291           //  Match ext ra edit    
1292           ec ho "<tr><t d>Match pe rcents (%) </td>";    
1293           if  ( $field  && !$_POST ['reenter' ] )    
1294           {    
1295                $value =  $field['m atch_extra '];    
1296           }    
1297           el se    
1298           {    
1299                $value =  $_POST['m atch_perc' ];    
1300           }    
1301           ec ho "<td><i nput type= \"text\" n ame=\"matc h_perc\" v alue=\"$va lue\" size =\"5\" />< /td></tr>" ;    
1302       }    
1303      
1304       // Dis play submi t button.    
1305       if ( $ field )    
1306       {    
1307           $c aption = ' Update';    
1308       }    
1309       else    
1310       {    
1311           $c aption = ' Add';    
1312       }    
1313       echo " <tr><td co lspan=\"2\ " align=\" center\">< input type =\"submit\ " name=\"a dd_button\ " value=\" $caption\"  /></td></ tr>";    
1314      
1315       echo " </table>\n ";    
1316       echo " </form>\n" ;    
1317       echo " <a href=\" profile_fi elds.php\" >Back</a>" ;    
1318   }    
1319      
1320   /**    
1321    * Perform  edit ar a dd field d atabase ac tions    
1322    * @param    
1323    */    
1324   function e dit_or_add _field()    
1325   {    
1326       // Get  field typ e.    
1327       $field _type = $_ POST['fiel d_type'];    
1328      
1329       // Sel ect old fi eld values    
1330       if ( ' add' != $_ GET['actio n'] )    
1331       {    
1332           $q _str = "SE LECT * FRO M `Profile sDesc` WHE RE `ID` =  {$_GET['ID ']}";    
1333           $f ield = db_ arr( $q_st r );    
1334       }    
1335      
1336       // Get  new field  order.    
1337       if ( ' add' == $_ GET['actio n'] )    
1338       {    
1339           $o rder = get _field_ord er( $_POST ['insert_a fter'] );    
1340       }    
1341      
1342       // Get  field nam e.    
1343       $name  = process_ pass_data( $_POST['fi eld_name'] );    
1344       $name  = str_repl ace(' ', ' _', $name) ;    
1345       $name  = str_repl ace("'", ' _', $name) ;    
1346      
1347       // Get  caption a nd determ  if it was  changed    
1348       if ( ' add' == $_ GET['actio n'] )    
1349       {    
1350           $n amedisp =  '_' . $nam e . '_capt ion';    
1351           $n amedisp_ch anged = tr ue;    
1352       }    
1353       else    
1354       {    
1355           if  ( $_POST[ 'caption']  == _t( $f ield['name disp'] ) )    
1356           {    
1357                $namedis p = $field ['namedisp '];    
1358                $namedis p_changed  = false;    
1359           }    
1360           el se    
1361           {    
1362                $namedis p = '_' .  $name . '_ caption';    
1363                $namedis p_changed  = true;    
1364           }    
1365       }    
1366      
1367       // Get  field des cription.    
1368       if ( ' add' == $_ GET['actio n'] )    
1369       {    
1370           $n amenote =  ( $_POST[' desc'] ? ' _' . $name  . '_desc'  : '' );    
1371           $n amenote_ch anged = tr ue;    
1372       }    
1373       else    
1374       {    
1375           if  ( $_POST[ 'desc'] ==  _t( $fiel d['namenot e'] ) )    
1376           {    
1377                $namenot e = $field ['namedisp '];    
1378                $namenot e_changed  = false;    
1379           }    
1380           el se    
1381           {    
1382                $namenot e = ( $_PO ST['desc']  ? '_' . $ name . '_d esc' : ''  );    
1383                $namenot e_changed  = true;    
1384           }    
1385       }    
1386      
1387       // Get  user visi bility.    
1388       $visib le = '';    
1389       if ( ' on' == $_P OST['visib le_to_visi tor'] )    
1390       {    
1391           $v isible .=  'user';    
1392       }    
1393       if ( ' on' == $_P OST['visib le_to_memb er'] )    
1394       {    
1395           $v isible = c at_string(  $visible,  'memb' );    
1396       }    
1397       if ( ' on' == $_P OST['visib le_to_admi n'] )    
1398       {    
1399           $v isible = c at_string(  $visible,  'adm' );    
1400       }    
1401      
1402       // Get  user edit  possibili ty.    
1403       $edita ble = '';    
1404       if ( ' on' == $_P OST['edita ble_for_me mber'] )    
1405       {    
1406           $e ditable .=  'memb';    
1407       }    
1408       if ( ' on' == $_P OST['edita ble_for_ad min'] )    
1409       {    
1410           $e ditable =  cat_string ( $editabl e, 'adm' ) ;    
1411       }    
1412      
1413       // Get  page visi bility.    
1414       $show_ on_page =  '';    
1415       if ( ' on' == $_P OST['show_ on_all'] )    
1416       {    
1417           $s how_on_pag e = '0';    
1418       }    
1419       if ( ' on' == $_P OST['show_ on_join']  )    
1420       {    
1421           $s how_on_pag e = cat_st ring( $sho w_on_page,  '3' );    
1422       }    
1423       if ( ' on' == $_P OST['show_ on_view_pr ofile'] )    
1424       {    
1425           $s how_on_pag e = cat_st ring( $sho w_on_page,  '7' );    
1426       }    
1427       if ( ' on' == $_P OST['show_ on_edit_pr ofile'] )    
1428       {    
1429           $s how_on_pag e = cat_st ring( $sho w_on_page,  '25' );    
1430       }    
1431      
1432       // Gen erate extr a field co ntent.    
1433       $extra  = '';    
1434       switch  ( $field_ type )    
1435       {    
1436       case ' p':    
1437       case ' c':    
1438           $e xtra = (in t)$_POST[' edit_box_l ength'];    
1439           br eak;    
1440      
1441       case ' date':    
1442           $e xtra = pro cess_db_in put( $_POS T['edit_bo x_length']  );    
1443           br eak;    
1444           
1445       case ' e':    
1446       case ' rb':    
1447       case ' set':    
1448           $t emp = expl ode( "\r\n ", $_POST[ 'choices']  );    
1449           $e xtra = '';    
1450           fo reach ( $t emp as $va lue )    
1451           {    
1452                $value =  process_p ass_data($ value);    
1453                $value =  str_repla ce("'", '` ', $value) ;    
1454                $replace _arr = arr ay(' ', '. ', ',', "\ \");    
1455                $value =  str_repla ce($replac e_arr, '_' , $value);    
1456                $extra =  cat_strin g( $extra,  "\'$value \'" );    
1457           }    
1458      
1459           $r esult = db _arr("SHOW  COLUMNS F ROM `Profi les` LIKE  '$name'");    
1460           $e xtratmp =  str_replac e("\\", "" , $extra);    
1461      
1462           //  Alter exi sting fiel d    
1463           if  ( $result ['Default' ] )    
1464           {    
1465                $alter_f ield_type  = ($field_ type == 's et' ? "SET ($extratmp )" : "ENUM ($extratmp )");    
1466                if ( str str($extra tmp, "'".  $result['D efault'] . "'") )    
1467                {    
1468                    db_r es("ALTER  TABLE `Pro files` MOD IFY `$name ` $alter_f ield_type  NOT NULL D EFAULT '{$ result['De fault']}'" );    
1469                }    
1470                else    
1471                {    
1472                    $def val = subs tr($extrat mp, 0, str pos($extra tmp, ",")) ;    
1473                    db_r es("ALTER  TABLE `Pro files` MOD IFY `$name ` $alter_f ield_type  NOT NULL D EFAULT {$d efval}");    
1474                }    
1475           }    
1476       break;    
1477      
1478       case ' a':    
1479           $e xtra = (in t)$_POST[' memo_rows' ] ."x". (i nt)$_POST[ 'memo_cols '];    
1480       break;    
1481       }    
1482      
1483       // Gen erate chec k script.    
1484       if ( ' Email' !=  $name && ' Email,Emai l1' != $na me && 'Nic kName' !=  $name && ' Password,P assword1'  != $name )    
1485       {    
1486           if  ( $_POST[ 'min_value '] && $_PO ST['max_va lue'] )    
1487           {    
1488                $check =  'return ( strlen($ar g0) >= '.  $_POST['mi n_value']  .' && strl en($arg0)  <= '. $_PO ST['max_va lue'] .' )  ? true :  false;';    
1489           }    
1490           el se if ( $_ POST['min_ value'] )    
1491           {    
1492                $check =  'return ( strlen($ar g0) >= '.  $_POST['mi n_value']  .') ? true  : false;' ;    
1493           }    
1494           el se if ( $_ POST['max_ value'] )    
1495           {    
1496                $check =  'return ( strlen($ar g0) <= '.  $_POST['ma x_value']  .') ? true  : false;' ;    
1497           }    
1498           el se if ( 'o n' == $_PO ST['mandat ory'] )    
1499           {    
1500                $check =  'return s trlen($arg 0) > 0 ? t rue : fals e;';    
1501           }    
1502       }    
1503       else    
1504       {    
1505           $l ength_chec k = ( $_PO ST['min_va lue'] ? 's trlen($arg 0) >= '.$_ POST['min_ value'] .  ' && ' : " " );    
1506           $l ength_chec k .= ( $_P OST['max_v alue'] ? '  strlen($a rg0) <= '. $_POST['ma x_value'].  ' && ' :  "" );    
1507           if  ( 'Email'  == $name  )    
1508           {    
1509                $check =  'return ( ' . $lengt h_check .  'strstr($a rg0,"@") & & strstr($ arg0,".")   && conf_e mail($arg0 ,$_COOKIE[ memberID]) )  ? true  : false;';    
1510           }    
1511           el se if ( 'N ickName' = = $name )    
1512           {    
1513                $check =  'return ( ' . $lengt h_check .  'conf_nick ($arg0,$_C OOKIE[memb erID]) &&  preg_match ("/^[0-9A- Za-z]+$/", $arg0)) ?  true : fal se;';    
1514           }    
1515           el se if ( 'P assword,Pa ssword1' = = $name )    
1516           {    
1517                $check =  'return ( ' . $lengt h_check .  '!strcmp($ arg0,$_POS T[Password 2])) ? tru e : false; ';    
1518           }    
1519           el se if ( 'E mail,Email 1' == $nam e )    
1520           {    
1521                $check =  'return ( eregi("^[_ \.0-9a-z-] +@([0-9a-z ][0-9a-z-] +\.)+[a-z] {2,4}$", $ arg0) && ! strcmp($ar g0,$_POST[ Email2]) & & conf_ema il($arg0,$ _COOKIE[me mberID]))  ? true : f alse;';    
1522           }    
1523           el se    
1524           {    
1525                $check =  '';    
1526           }    
1527       }    
1528      
1529       // Gen erate erro r message.    
1530       if ( ' add' == $_ GET['actio n'] )    
1531       {    
1532           $e rr_msg = ' _' . $name  . '_err_m sg';    
1533           $e rr_msg_cha nged = tru e;    
1534       }    
1535       else    
1536       {    
1537           if  ( $_POST[ 'err_msg']  == _t( $f ield['beca use'] ) )    
1538           {    
1539                $err_msg  = $field[ 'because'] ;    
1540                $err_msg _changed =  false;    
1541           }    
1542           el se    
1543           {    
1544                $err_msg  = '_' . $ name . '_e rr_msg';    
1545                $err_msg _changed =  true;    
1546           }    
1547       }    
1548      
1549       // Gen erate sear ch type.    
1550       $searc h_type = (  $_POST['s earch_t']  ? $_POST[' search_t']  : 'none'  );    
1551      
1552       // Gen erate 'sea rch_hide'  value.    
1553       $searc h_hide = 0 ;    
1554       if ( ' on' == $_P OST['searc h_hidden']  )    
1555       {    
1556           $s earch_hide  = 1;    
1557       }    
1558      
1559       // Gen erate 'sea rch_cols'  value.    
1560       $searc h_cols = (  $_POST['s earch_cols '] ? (int) $_POST['se arch_cols' ] : 0 );    
1561      
1562       // Gen erate 'sea rch_order'  value.    
1563       $q_str  = 'SELECT  `search_o rder` FROM  `Profiles Desc` ORDE R BY `sear ch_order`  DESC LIMIT  1';    
1564       $row =  db_arr( $ q_str );    
1565       $searc h_order =  $row['sear ch_order']  + 1;    
1566      
1567       // Gen erate matc h type    
1568       $match _type = (  $_POST['ma tch_t'] ?  $_POST['ma tch_t'] :  'none' );    
1569      
1570       // Gen erate matc h field    
1571       $match _field = (  $_POST['m atch_f'] & & $_POST[' match_f']  != 'none'  ? $_POST[' match_f']  : '' );    
1572      
1573       // Gen erate matc h extra    
1574       $match _extra = (  $_POST['m atch_perc' ] ? $_POST ['match_pe rc'] : ''  );    
1575      
1576       $min_l ength = pr ocess_db_i nput($_POS T['min_val ue']);    
1577       $max_l ength = pr ocess_db_i nput($_POS T['max_val ue']);    
1578      
1579       if ( ' add' == $_ GET['actio n'] )    
1580       {    
1581           //  Generate  query to a dd record  to Profile sDesc.    
1582           $q _str = "IN SERT INTO  `ProfilesD esc` (`nam e`, `named isp`, `nam enote`, `e xtra`, `ty pe`, `orde r`, `visib le`, `edit able`, `sh ow_on_page `, `check` , `because `, `min_le ngth`, `ma x_length`,  `search_t ype`, `sea rch_hide`,  `search_c ols`, `sea rch_order` , `match_t ype`, `mat ch_field`,  `match_ex tra`)";    
1583           $q _str .= "V ALUES ('$n ame', '$na medisp', ' $namenote' , '$extra' , '$field_ type', '$o rder', '$v isible', ' $editable' , '$show_o n_page', ' $check', ' $err_msg',  '$min_len gth', '$ma x_length',  '$search_ type', '$s earch_hide ', '$searc h_cols', ' $search_or der', '$ma tch_type',  '$match_f ield', '$m atch_extra ')";    
1584       }    
1585       elseif  ( 'edit'  == $_GET[' action'] )    
1586       {    
1587           $n amedisp_sq l = ( $nam edisp_chan ged ? "`na medisp` =  '$namedisp '," : "" ) ;    
1588           $n amenote_sq l = ( $nam enote_chan ged ? "`na menote` =  '$namenote '," : "" ) ;    
1589           $e rr_msg_sql  = ( $err_ msg_change d ? "`beca use` = '$e rr_msg',"  : "" );    
1590           $q _str = "UP DATE `Prof ilesDesc`  SET {$name disp_sql}  {$namenote _sql} `ext ra` = '$ex tra', `vis ible` = '$ visible',  `editable`  = '$edita ble', `sho w_on_page`  = '$show_ on_page',  `check` =  '$check',  {$err_msg_ sql} `min_ length` =  '$min_leng th', `max_ length` =  '$max_leng th', `sear ch_type` =  '$search_ type', `se arch_hide`  = '$searc h_hide', ` search_col s` = '$sea rch_cols',  `match_ty pe` = '$ma tch_type',  `match_fi eld` = '$m atch_field ', `match_ extra` = ' $match_ext ra' WHERE  ID = {$_GE T['ID']}";    
1591       }    
1592       // Exe cute query .    
1593       db_res ( $q_str ) ;    
1594      
1595       $type  = '';    
1596       // Gen erate fiel d type for  Profiles  table.    
1597       switch  ( $field_ type )    
1598       {    
1599       case ' c':    
1600           $t ype = 'VAR CHAR(255)' ;    
1601           br eak;    
1602      
1603       case ' e':    
1604       case ' rb':    
1605           $a rr = explo de( "\r\n" , $_POST[' choices']  );    
1606           $t ype = '';    
1607           fo reach ( $a rr as $val ue )    
1608           {    
1609                $value =  process_p ass_data($ value);    
1610                $value =  str_repla ce("'", '` ', $value) ;    
1611                $replace _arr = arr ay(' ', '. ', ',', "\ \");    
1612                $value =  str_repla ce($replac e_arr, '_' , $value);    
1613                $type =  cat_string ( $type, " '$value'"  );    
1614           }    
1615           $t ype = "ENU M ($type)" ;    
1616       break;    
1617      
1618       case ' a':    
1619           $t ype = 'MED IUMTEXT';    
1620           br eak;    
1621      
1622       case ' set':    
1623           $a rr = explo de( "\r\n" , $_POST[' choices']  );    
1624           $t ype = '';    
1625           fo reach ( $a rr as $val ue )    
1626           {    
1627                $value =  process_p ass_data($ value);    
1628                $value =  str_repla ce("'", '` ', $value) ;    
1629                $replace _arr = arr ay(' ', '. ', ',', "\ \");    
1630                $value =  str_repla ce($replac e_arr, '_' , $value);    
1631                $type =  cat_string ( $type, " '$value'"  );    
1632           }    
1633           $t ype = "SET  ($type)";    
1634       break;    
1635       }    
1636      
1637       if ( $ field_type  != '0' &&  'add' ==  $_GET['act ion'] )    
1638       {    
1639           //  Generate  query to a dd new fie ld to Prof iles.    
1640           $v als = spli t (",", $n ame);    
1641           $d b_name = $ vals[0];    
1642           $q _str = "AL TER TABLE  `Profiles`  ADD `$db_ name` {$ty pe} NOT NU LL";    
1643           db _res( $q_s tr );    
1644       }    
1645      
1646       // Gen erate lang uage file  content.    
1647       $lang_ file = '';    
1648       $langF ailFields  = '';    
1649       if ( $ namedisp_c hanged )    
1650       {    
1651           $l ang_file . = "'{$_POS T['caption ']}';<br / >";    
1652           if  ( !addStr ingToLangu age( $name disp, $_PO ST['captio n'] ) && ! updateStri ngInLangua ge( $named isp, $_POS T['caption '] ) )    
1653           {    
1654                $langFai lFields .=  "'$namedi sp';<br /> ";    
1655           }    
1656       }    
1657       if ( $ namenote_c hanged &&  $namenote  )    
1658       {    
1659           $l ang_file . = "'{$_POS T['desc']} ';<br />";    
1660           if  ( !addStr ingToLangu age( $name note, $_PO ST['desc']  ) && !upd ateStringI nLanguage(  $namenote , $_POST[' desc'] ) )    
1661           {    
1662                $langFai lFields .=  "'$nameno te';<br /> ";    
1663           }    
1664       }    
1665       // Err or message .    
1666       if ( $ err_msg_ch anged )    
1667       {    
1668           $l ang_file . = "'{$_POS T['err_msg ']}';<br / >";    
1669           if  ( !addStr ingToLangu age( $err_ msg, $_POS T['err_msg '] ) && !u pdateStrin gInLanguag e( $err_ms g, $_POST[ 'err_msg']  ) )    
1670           {    
1671                $langFai lFields .=  "'$err_ms g';<br />" ;    
1672           }    
1673       }    
1674       // Dro p-down box  options.    
1675       if ( $ _POST['cho ices'] )    
1676       {    
1677           $a rr = explo de( "\r\n" , $_POST[' choices']  );    
1678           fo reach( $ar r as $valu e )    
1679           {    
1680                $value =  process_p ass_data($ value);    
1681                $entered _value = $ value;    
1682                $value =  str_repla ce("'", '` ', $value) ;    
1683                $replace _arr = arr ay(' ', '. ', ',', "\ \");    
1684                $value =  str_repla ce($replac e_arr, '_' , $value);    
1685                $lang_fi le .= "'{$ entered_va lue}';<br  />";    
1686                if ( !ad dStringToL anguage( " _{$value}" , $entered _value ) & & !updateS tringInLan guage( "_{ $value}",  $entered_v alue ) )    
1687                {    
1688                    $lan gFailField s .= "'{$e ntered_val ue}';<br / >";    
1689                }    
1690           }    
1691       }    
1692      
1693       // Com pile langu age files  if needed    
1694       if ( s trlen($lan g_file) )    
1695           co mpileLangu age();    
1696      
1697       if ( ' add' == $_ GET['actio n'] )    
1698       {    
1699           ec ho "<p><sp an style=\ "color:#ff 6666;font- weight:bol d\">New fi eld has be en added.< /span></p> ";    
1700       }    
1701       else i f ( 'edit'  == $_GET[ 'action']  )    
1702       {    
1703           ec ho "<p><sp an style=\ "color:#ff 6666;font- weight:bol d\">Field  has been u pdated.</s pan></p>";    
1704       }    
1705      
1706       if ( s trlen($lan g_file) )    
1707       {    
1708           ec ho "Follow ing string s were add ed or upda ted in you r language  files:<br  />";    
1709           ec ho "<pre>$ lang_file< /pre>";    
1710           if  ( strlen( $langFailF ields) )    
1711           {    
1712                echo "Fa il to inse rt or upda te followi ng strings :<br />";    
1713                echo "<p re>$langFa ilFields</ pre>";    
1714           }    
1715       }    
1716       echo " <p><a href =\"profile _fields.ph p\">Contin ue</a></p> ";    
1717   }    
1718      
1719   /**    
1720    * Check g eneral pur pose and t ype-specif ic paramet ers.    
1721    * @param  $field_typ e       Fi eld type.    
1722    * @retval                    Ar ray of err or message s.    
1723    */    
1724   function c heck_param eters( $fi eld_type )    
1725   {    
1726       $retva l = array  ();    
1727       // Che ck general  purpose p arameters.    
1728      
1729       // Che ck field n ame.    
1730       if ( ! $_POST['fi eld_name']  )    
1731       {    
1732           ar ray_push(  $retval, ' Field name  may not b e empty.'  );    
1733       }    
1734      
1735       // Che ck caption .    
1736       if ( ! $_POST['ca ption'] )    
1737       {    
1738           ar ray_push(  $retval, ' Caption ma y not be e mpty.' );    
1739       }    
1740   /*    
1741       // Che ck member  visibility .    
1742       if ( ' on' != $_P OST['visib le_to_visi tor']    
1743           &&  'on' != $ _POST['vis ible_to_me mber']    
1744           &&  'on' != $ _POST['vis ible_to_ad min'] )    
1745       {    
1746           ar ray_push(  $retval, ' You must s pecify who  is author ized to se e the fiel d ("Visibl e to" prop erty).' );    
1747       }    
1748   */    
1749       // Che ck page vi sibility.    
1750       if ( ' on' != $_P OST['show_ on_all']    
1751           &&  'on' != $ _POST['sho w_on_join' ]    
1752           &&  'on' != $ _POST['sho w_on_view_ profile']    
1753           &&  'on' != $ _POST['sho w_on_edit_ profile']  )    
1754       {    
1755           ar ray_push(  $retval, ' You must s pecify whe re to disp lay the fi eld ("Show  on page"  property). ' );    
1756       }    
1757      
1758       // Che ck field t ype specif ic values.    
1759       switch  ( $field_ type )    
1760       {    
1761       case ' c':    
1762           $l en = $_POS T['edit_bo x_length'] ;    
1763           if  ( !$len | | !is_nume ric( $len  ) || $len  < 0 || $le n > 100 )    
1764           {    
1765                array_pu sh( $retva l, 'Invali d edit box  length (m ust be a n umber betw een 0 and  100).' );    
1766           }    
1767           $m in_value =  $_POST['m in_value'] ;    
1768           if  ( $min_va lue && !is _numeric(  $min_value  ) )    
1769           {    
1770                array_pu sh( $retva l, 'Invali d min leng th value ( must be a  number or  empty).' ) ;    
1771           }    
1772           $m ax_value =  $_POST['m ax_value'] ;    
1773           if  ( $max_va lue && !is _numeric(  $max_value  ) )    
1774           {    
1775                array_pu sh( $retva l, 'Invali d max leng th value ( must be a  number or  empty).' ) ;    
1776           }    
1777       break;    
1778      
1779       case ' e':    
1780       case ' rb':    
1781       case ' set':    
1782           if  ( 'e' ==  $field_typ e )    
1783           {    
1784                $msg = ' Drop-down  box choice s are not  set.';    
1785           }    
1786           el se if ( 'r b' == $fie ld_type )    
1787           {    
1788                $msg = ' Radio butt on choices  are not s et.';    
1789           }    
1790           el se if ( 's et' == $fi eld_type )    
1791           {    
1792                $msg = ' Set choice s are not  set.';    
1793           }    
1794           $o ptions = $ _POST['cho ices'];    
1795           if  ( 0 == st rlen( $opt ions ) )    
1796           {    
1797                array_pu sh( $retva l, $msg );    
1798           }    
1799       break;    
1800      
1801       case ' a':    
1802           $m emo_rows =  $_POST['m emo_rows'] ;    
1803           if  ( !$memo_ rows || !i s_numeric(  $memo_row s ) || $me mo_rows <  0 || $memo _rows > 10 0)    
1804           {    
1805                array_pu sh( $retva l, 'Invali d number o f memo row s (must be  a number  between 0  and 100).'  );    
1806           }    
1807           $m emo_cols =  $_POST['m emo_cols'] ;    
1808           if  ( !$memo_ cols || !i s_numeric(  $memo_col s ) || $me mo_cols <  0 || $memo _cols > 10 0 )    
1809           {    
1810                array_pu sh( $retva l, 'Invali d number o f memo col umns (must  be a numb er between  0 and 100 ).' );    
1811           }    
1812           $m in_value =  $_POST['m in_value'] ;    
1813           if  ( $min_va lue && !is _numeric(  $min_value  ) )    
1814           {    
1815                array_pu sh( $retva l, 'Invali d min leng th value ( must be a  number or  empty).' ) ;    
1816           }    
1817           $m ax_value =  $_POST['m ax_value'] ;    
1818           if  ( $max_va lue && !is _numeric(  $max_value  ) )    
1819           {    
1820                array_pu sh( $retva l, 'Invali d max leng th value ( must be a  number or  empty).' ) ;    
1821           }    
1822       break;    
1823       }    
1824      
1825       return  $retval;    
1826   }    
1827      
1828   /**    
1829    * Get new  field ord er relativ e to anoth er field.    
1830    * @param  $order         The or der of ano ther field  (this can  be 'begin ',    
1831    *                        'end',  or id of  the preced ing field) .    
1832    * @retval                Field  order.    
1833    */    
1834   function g et_field_o rder( $ord er )    
1835   {    
1836       $order  = (int)$o rder;    
1837      
1838       $retva l = 0;    
1839       if ( ' begin' ==  $order )    
1840       {    
1841           $q _str = "SE LECT `orde r` FROM Pr ofilesDesc  ORDER BY  `order` AS C LIMIT 1" ;    
1842           $r ow = db_ar r( $q_str  );    
1843           $r etval = $r ow['order' ] - 0.1;    
1844       }    
1845       else i f ( 'end'  == $order  )    
1846       {    
1847           $q _str = "SE LECT `orde r` FROM Pr ofilesDesc  ORDER BY  `order` DE SC LIMIT 1 ";    
1848           $r ow = db_ar r( $q_str  );    
1849           $r etval = $r ow['order' ] + 1;    
1850       }    
1851       else    
1852       {    
1853           //  Get upper  order.    
1854           $q _str = "SE LECT `orde r` FROM Pr ofilesDesc  WHERE ID  = $order";    
1855           $r ow = db_ar r( $q_str  );    
1856           $l ower_order  = $row['o rder'];    
1857      
1858           //  Get lower  order.    
1859           $q _str = "SE LECT `orde r` FROM Pr ofilesDesc  WHERE `or der` > $lo wer_order  ORDER BY ` order` ASC ";    
1860           $r ow = db_ar r( $q_str  );    
1861           if  ( !$row )    
1862           {    
1863                $retval  = $lower_o rder + 1;    
1864           }    
1865           el se    
1866           {    
1867                $upper_o rder = $ro w['order'] ;    
1868                $retval  = ($lower_ order + $u pper_order ) / 2;    
1869           }    
1870       }    
1871       return  $retval;    
1872   }    
1873      
1874   /**    
1875    * Concate nate strin gs adding  a comma.    
1876    * @param  $str1          First  string.    
1877    * @param  $str1          Second  string.    
1878    * @retval                Concat enated str ing.    
1879    */    
1880   function c at_string(  $str1, $s tr2 )    
1881   {    
1882       if ( s trlen( $st r1 ) > 0 )    
1883       {    
1884           $s tr1 .= ',' ;    
1885       }    
1886       $str1  .= $str2;    
1887       return  $str1;    
1888   }    
1889      
1890   /**    
1891    * Delete  profile fi eld.    
1892    */    
1893   function d elete_fiel d( $ID, $r es )    
1894   {    
1895       // Mak e int from  ID    
1896       $ID =  (int)$ID;    
1897      
1898       // Col lect all f ields and  determine  which of t hem are gr oup    
1899       $cnt =  0;    
1900       $total _rows = my sql_num_ro ws( $res ) ;    
1901       while  ( $row = m ysql_fetch _array( $r es ) )    
1902       {    
1903           $r ows[$cnt]  = $row;    
1904           $f name = get _field_nam e( $row );    
1905           $r ows[$cnt][ 'db_name']  = $fname;    
1906           $f ield_group s[$fname][ 'count']++ ;    
1907           if  ( $row['I D'] == $ID  )    
1908                $field_i ndex = $cn t;    
1909           $c nt++;    
1910       }    
1911      
1912       // Num ber of fie lds in cur rent group    
1913       $group _fields_nu m = $field _groups[$r ows[$field _index]['d b_name']][ 'count'];    
1914      
1915       // Get  field nam e and type    
1916       $name  = $rows[$f ield_index ]['db_name '];    
1917       $type  = $rows[$f ield_index ]['type'];    
1918      
1919       // Bre ak row gro up    
1920       if ( $ rows[$fiel d_index][' group_mark '] != '' )    
1921       {    
1922           $i  = $field_ index - 1;    
1923           wh ile ( $row s[$i]['gro up_mark']  != '' && $ i >= 0 )    
1924           {    
1925                $query_s tr = "UPDA TE `Profil esDesc` SE T `group_m ark` = ''  WHERE ID =  {$rows[$i ]['ID']}";    
1926                db_res(  $query_str  );    
1927                $i--;    
1928           }    
1929           $i  = $field_ index + 1;    
1930           wh ile ( $row s[$i]['gro up_mark']  != '' && $ i < $total _rows )    
1931           {    
1932                $query_s tr = "UPDA TE `Profil esDesc` SE T `group_m ark` = ''  WHERE ID =  {$rows[$i ]['ID']}";    
1933                db_res(  $query_str  );    
1934                $i++;    
1935           }    
1936       }    
1937      
1938       // Del ete record s from Pro filesDesc  table    
1939       if ( $ group_fiel ds_num > 1  )    
1940       {    
1941           fo r ( $i = 0 ; $i < $to tal_rows;  $i++ )    
1942                if ( $ro ws[$i]['db _name'] ==  $rows[$fi eld_index] ['db_name' ] )    
1943                {    
1944                    $que ry_str = " DELETE FRO M `Profile sDesc` WHE RE ID = {$ rows[$i][' ID']}";    
1945                    db_r es( $query _str );    
1946                }    
1947       }    
1948       else    
1949       {    
1950           $q uery_str =  "DELETE F ROM `Profi lesDesc` W HERE ID =  {$rows[$fi eld_index] ['ID']}";    
1951           db _res( $que ry_str );    
1952       }    
1953      
1954       if ( $ type != '0 ' )    
1955       {    
1956           //  Delete fi eld from P rofiles ta ble.    
1957           $q uery_str =  "ALTER TA BLE `Profi les` DROP  `$name`";    
1958           db _res( $que ry_str );    
1959       }    
1960   }    
1961      
1962   /**    
1963    * Display  field typ e control.    
1964    * @param  $value             De fault valu e.    
1965    * @param  $read_only         Is  read only .    
1966    */    
1967   function d isplay_fie ld_type( $ value, $re ad_only )    
1968   {    
1969       $types  = array (    
1970           'c ' => 'edit  box',    
1971           'e ' => 'drop -down box' ,    
1972           'a ' => 'memo ',    
1973           '0 ' => 'divi der',    
1974           'r b' => 'set  of radio  buttons',    
1975           's et' => 'se t of check boxes',    
1976           'p ' => 'pass word',    
1977           'd ate' => 'd ate'    
1978       );    
1979      
1980       if ( f alse != $r ead_only )    
1981       {    
1982           ec ho "<td><i nput type= \"hidden\"  name=\"fi eld_type\"  value=\"$ value\" /> $types[$va lue]</td>\ n";    
1983       }    
1984       else    
1985       {    
1986           ec ho "<td><s elect name =\"field_t ype\" onCh ange=\"jav ascript: v ar val = t his.value;  window.lo cation.hre f = 'profi le_fields. php?action =add&field _type=' +  val;\">\n" ;    
1987           fo reach ( $t ypes as $k ey => $val  )    
1988           {    
1989                if ( 0 = = strcmp(  $value, $k ey ) )    
1990                {    
1991                    echo  "<option  value=\"$k ey\" selec ted=\"sele cted\">$va l</option> \n";    
1992                }    
1993                else    
1994                {    
1995                    echo  "<option  value=\"$k ey\">$val< /option>\n ";    
1996                }    
1997           }    
1998           ec ho "</td>< /tr>\n";    
1999       }    
2000   }    
2001      
2002   /**    
2003    * Display  control f or selecti ng 'insert  after' va lue.    
2004    * @param  $value             De fault valu e.    
2005    */    
2006   function d isplay_ins ert_after(  $value )    
2007   {    
2008       // Gen erate an a rray of po ssible val ues.    
2009       $inser t_after =  array ( 'b egin' => ' At the beg inning', ' end' => 'A t the end'  );    
2010       $q_str  = "SELECT  `ID`, `na me` FROM ` ProfilesDe sc` ORDER  BY `order`  ASC";    
2011       $res =  db_res( $ q_str );    
2012       while  ( $row = m ysql_fetch _array( $r es ) )    
2013       {    
2014           $i nsert_afte r[$row['ID ']] = "Aft er {$row[' name']}";    
2015       }    
2016       // Dis play value s.    
2017       echo " <td><selec t name=\"i nsert_afte r\">\n";    
2018       foreac h ( $inser t_after as  $key => $ val )    
2019       {    
2020           if  ( $key ==  $value )    
2021           {    
2022                $selecte d = 'selec ted';    
2023           }    
2024           el se    
2025           {    
2026                $selecte d = '';    
2027           }    
2028           ec ho "<optio n value=\" $key\" $se lected>$va l</option> \n";    
2029       }    
2030       echo " </select>< /td></tr>\ n";    
2031   }    
2032      
2033   /**    
2034    * Display  control f or selecti ng 'match  field' val ue.    
2035    * @param  $value             De fault valu e.    
2036    */    
2037   function d isplay_mat ch_field(  $value )    
2038   {    
2039       // Gen erate an a rray of po ssible val ues.    
2040       $match _field = a rray ( 'no ne' => 'No ne' );    
2041       $q_str  = "SELECT  `ID`, `na me` FROM ` ProfilesDe sc` WHERE  `type` !=  '0' ORDER  BY `order`  ASC";    
2042       $res =  db_res( $ q_str );    
2043       while  ( $row = m ysql_fetch _array( $r es ) )    
2044       {    
2045           $f name = get _field_nam e( $row );    
2046           $f ield_group s[$fname][ 'count']++ ;    
2047           if  ( $field_ groups[$fn ame]['coun t'] == 1 )    
2048                $match_f ield[$fnam e] = $fnam e;    
2049       }    
2050       // Dis play value s.    
2051       echo " <td><selec t name=\"m atch_f\">\ n";    
2052       foreac h ( $match _field as  $key => $v al )    
2053       {    
2054           if  ( $key ==  $value )    
2055           {    
2056                $selecte d = 'selec ted';    
2057           }    
2058           el se    
2059           {    
2060                $selecte d = '';    
2061           }    
2062           ec ho "<optio n value=\" $key\" $se lected>$va l</option> \n";    
2063       }    
2064       echo " </select>< /td></tr>\ n";    
2065   }    
2066      
2067   /**    
2068    * Display  field nam e.    
2069    * @param  $value             De fault valu e.    
2070    * @param  $read_only         Is  field rea d-only.    
2071    */    
2072   function d isplay_fie ld_name( $ value, $re ad_only )    
2073   {    
2074       if ( f alse != $r ead_only )    
2075       {    
2076           ec ho "<tr><t d>Field na me</td>\n" ;    
2077           ec ho "<td><i nput type= \"hidden\"  name=\"fi eld_name\"  value=\"$ value\" /> $value</td >\n";    
2078       }    
2079       else    
2080       {    
2081           ec ho "<tr><t d>Field na me<br>(Ple ase use al phanumeric al chars o nly)</td>\ n";    
2082           ec ho "<td><i nput type= \"text\" n ame=\"fiel d_name\" v alue=\"$va lue\"/></t d></tr>\n" ;    
2083       }    
2084   }    
2085      
2086   /**    
2087    * Display  field des cription.    
2088    * @param  $value             De fault valu e.    
2089    * @param  $read_only         Is  field rea d-only.    
2090    */    
2091   function d isplay_fie ld_desc( $ value, $re ad_only )    
2092   {    
2093       if ( f alse != $r ead_only )    
2094       {    
2095           ec ho "<td><i nput type= \"hidden\"  name=\"de sc\" value =\"$value\ " />$value </td></tr> \n";    
2096       }    
2097       else    
2098       {    
2099           ec ho "<td><i nput type= \"text\" n ame=\"desc \" value=\ "$value\"  size=\"60\ " /></td>< /tr>\n";    
2100       }    
2101   }    
2102      
2103   /**    
2104    * Determi ne if fiel d could be  edited fr om admin p anel.    
2105    * @param  $field             Ar ray of ext racted fro m database  values    
2106    */    
2107   function f ield_edita ble( $fiel d )    
2108   {    
2109       $aForb id = array ( 'Status' /*'EmailNo tify'*/);    
2110       if (!i n_array($f ield['name '], $aForb id))    
2111       {    
2112           sw itch ( $fi eld['type' ] )    
2113           {    
2114                case 'r' :    
2115                case 'rr ':    
2116                case 'en ':    
2117                case 'en y':    
2118                    retu rn false;    
2119                    brea k;    
2120                default:    
2121                    retu rn true;    
2122           }    
2123       }    
2124       else    
2125       {    
2126           re turn false ;    
2127       }    
2128   }    
2129      
2130   /**    
2131    * Swap or der of two  field gro ups    
2132    * @param  $field_buf fer - arra y of field s in forma t [$index] ['value']    
2133    * @param  $border_in fo - info  about fiel d groups b orders    
2134    *      $b order_info ['first_st art'] - st art of fir st group    
2135    *      $b order_info ['first_en d'] - end  of first g roup    
2136    *      $b order_info ['second_s tart'] - s tart of se cond group    
2137    *      $b order_info ['second_e nd'] - end  of second  group    
2138    *      WA RNING!!! $ border_inf o['first_e nd'] + 1 =  $border_i nfo['secon d_start']    
2139    */    
2140   function s wap_groups _order( $f ield_buffe r, $border _info )    
2141   {    
2142       // Fir st swap ac tion    
2143       $offse t = 0;    
2144       for ($ i = $borde r_info['se cond_start ']; $i <=  $border_in fo['second _end']; $i ++)    
2145       {    
2146           //  Get the o rder of th e given fi eld.    
2147           $s rc_order =  $field_bu ffer[$bord er_info['f irst_start '] + $offs et]['order '];    
2148      
2149           //  Get the o rder of th e field pr eceding th e given on e.    
2150           $d est_id = $ field_buff er[$i]['ID '];    
2151      
2152           //  Change or der for th e given fi eld.    
2153           $q uery_str =  "UPDATE ` ProfilesDe sc` SET `o rder` = $s rc_order W HERE `ID`  = $dest_id ";    
2154           db _res( $que ry_str );    
2155      
2156           $o ffset++;    
2157       }    
2158      
2159       // Sec ond swap a ction    
2160       $offse t = $borde r_info['se cond_end']  - $border _info['sec ond_start' ] - $borde r_info['fi rst_end']  + $border_ info['firs t_start'];    
2161       for ($ i = $borde r_info['fi rst_start' ]; $i <= $ border_inf o['first_e nd']; $i++ )    
2162       {    
2163           //  Get the o rder of th e given fi eld.    
2164           $s rc_order =  $field_bu ffer[$bord er_info['s econd_star t'] + $off set]['orde r'];    
2165      
2166           //  Get the o rder of th e field pr eceding th e given on e.    
2167           $d est_id = $ field_buff er[$i]['ID '];    
2168      
2169           //  Change or der for th e given fi eld.    
2170           $q uery_str =  "UPDATE ` ProfilesDe sc` SET `o rder` = $s rc_order W HERE `ID`  = $dest_id ";    
2171           db _res( $que ry_str );    
2172      
2173           $o ffset++;    
2174       }    
2175      
2176   }    
2177   ?>