199. File Comparison Report

Produced on Mon May 12 13:05:08 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.

199.1 Files compared

# Location File Last Modified
1 Mon May 12 13:05:08 2008 UTC
2 Dolphin-v.6.1.0\inc\classes BxDolPFM.php Sat Apr 26 12:14:06 2008 UTC

199.2 Comparison summary

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

199.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

199.4 Active regular expressions

No regular expressions were active.

199.5 Comparison detail

    1   <?
    2  
    3   /*
    4       Profil e Fields M anager
    5   */
    6  
    7   class BxDo lPFM {
    8       functi on BxDolPF M( $iArea  ) {
    9           $t his -> aCo lNames = a rray (
    10                1  => ar ray( 'Page ' => 'Join ',   'Orde r' => 'Joi nOrder',          'Bl ock' => 'J oinBlock',          ' ShowSysIte ms' => 'Co uple,Captc ha,TermsOf Use', 'Edi tAdd' => a rray( 'Joi nPage' ) ) ,
    11                
    12                2  => ar ray( 'Page ' => 'Edit ',   'Orde r' => 'Edi tOwnOrder' ,      'Bl ock' => 'E ditOwnBloc k' ),
    13                3  => ar ray( 'Page ' => 'Edit ',   'Orde r' => 'Edi tAdmOrder' ,      'Bl ock' => 'E ditAdmBloc k',      ' ShowSysIte ms' => 'Fe atured,Sta tus' ),
    14                4  => ar ray( 'Page ' => 'Edit ',   'Orde r' => 'Edi tModOrder' ,      'Bl ock' => 'E ditModBloc k',      ' ShowSysIte ms' => 'Fe atured,Sta tus' ),
    15                
    16                5  => ar ray( 'Page ' => 'View ',   'Orde r' => 'Vie wAdmOrder' ,      'Bl ock' => 'V iewAdmBloc k',      ' ShowSysIte ms' => 'ID ,DateReg,D ateLastEdi t,DateLast Login,Stat us' ),
    17                6  => ar ray( 'Page ' => 'View ',   'Orde r' => 'Vie wMembOrder ',     'Bl ock' => 'V iewMembBlo ck',     ' ShowSysIte ms' => 'ID ,DateReg,D ateLastEdi t,DateLast Login,Stat us' ),
    18                7  => ar ray( 'Page ' => 'View ',   'Orde r' => 'Vie wModOrder' ,      'Bl ock' => 'V iewModBloc k',      ' ShowSysIte ms' => 'ID ,DateReg,D ateLastEdi t,DateLast Login,Stat us' ),
    19                8  => ar ray( 'Page ' => 'View ',   'Orde r' => 'Vie wVisOrder' ,      'Bl ock' => 'V iewVisBloc k',      ' ShowSysIte ms' => 'ID ,DateReg,D ateLastEdi t,DateLast Login,Stat us' ),
    20                
    21                9  => ar ray( 'Page ' => 'Sear ch', 'Orde r' => 'Sea rchSimpleO rder', 'Bl ock' => 'S earchSimpl eBlock', ' EditAdd' = > array( ' SearchPara ms' ), 'Sh owSysItems ' => 'ID,K eyword,Loc ation,Coup le' ),
    22                10 => ar ray( 'Page ' => 'Sear ch', 'Orde r' => 'Sea rchQuickOr der',  'Bl ock' => 'S earchQuick Block',  ' EditAdd' = > array( ' SearchPara ms' ), 'Sh owSysItems ' => 'ID,K eyword,Loc ation,Coup le' ),
    23                11 => ar ray( 'Page ' => 'Sear ch', 'Orde r' => 'Sea rchAdvOrde r',    'Bl ock' => 'S earchAdvBl ock',    ' EditAdd' = > array( ' SearchPara ms' ), 'Sh owSysItems ' => 'ID,K eyword,Loc ation,Coup le' ),
    24           );
    25           
    26           $t his -> sLi nkPref = ' #!'; //pre fix for va lues links
    27           
    28           $t his -> aTy pes = arra y(
    29                'text'        => 'T ext',
    30                'area'        => 'T extArea',
    31                'pass'        => 'P assword',
    32                'date'        => 'D ate',
    33                'select_ one' => 'S elector',
    34                'select_ set' => 'M ultiple Se lector',
    35                'num'         => 'N umber',
    36                'range'       => 'R ange',
    37                'bool'        => 'B oolean (ch eckbox)'
    38           );
    39           
    40           // altering t able prope rties
    41           $t his -> aTy pesAlter =  array(
    42                'text'        => "v archar(255 ) NOT NULL  default ' {default}' ",
    43                'area'        => "t ext NOT NU LL",
    44                'pass'        => "v archar(32)  NOT NULL" ,
    45                'date'        => "d ate NOT NU LL default  '{default }'",
    46                'select_ one' => "e num({value s})",
    47                'select_ one_linked ' => "varc har(255) N OT NULL de fault ''",
    48                'select_ set' => "s et({values }) NOT NUL L default  ''",
    49                'select_ set_linked ' => "set( {values})  NOT NULL d efault ''" ,
    50                'num'         => "i nt(10) uns igned NOT  NULL defau lt '{defau lt}'",
    51                'range'       => "v archar(255 ) NOT NULL  default ' {default}' ",
    52                'bool'        => "t inyint(1)  NOT NULL d efault '{d efault}'"
    53           );
    54           
    55           $t his -> iAr eaID = (in t)$iArea;
    56           if ( !( $this  -> iAreaI D > 0 and  isset( $th is -> aCol Names[$thi s -> iArea ID] ) ) )
    57                return f alse;
    58           
    59           //  retrieve  default la nguage
    60           $s LangDfl =  addslashes ( getParam ('lang_def ault') );
    61           $s Query = "S ELECT `ID`  FROM `Loc alizationL anguages`  WHERE `Nam e` = '$sLa ngDfl'";
    62           $t his -> sLa ngID = (in t)db_value ( $sQuery  );
    63           
    64           if ( !$this - > sLangID  )
    65                return p rint 'Cann ot continu e. Default  language  not found. ';
    66           
    67           $t his -> are aPageName     = $this  -> aColNa mes[$this  -> iAreaID ]['Page'];
    68           $t his -> are aOrderCol     = $this  -> aColNa mes[$this  -> iAreaID ]['Order'] ;
    69           $t his -> are aBlockCol     = $this  -> aColNa mes[$this  -> iAreaID ]['Block'] ;
    70           $t his -> are aSysItems     = $this  -> aColNa mes[$this  -> iAreaID ]['ShowSys Items'];
    71           
    72           $t his -> are aEditAddCo ls = $this  -> aColNa mes[$this  -> iAreaID ]['EditAdd '];
    73           
    74           $t his -> aBl ocks = arr ay();
    75           $t his -> aIt ems  = arr ay();
    76           
    77           $t his -> aBl ocksInac =  array();
    78           $t his -> aIt emsInac  =  array();
    79           
    80       }
    81       
    82       functi on genJSON () {
    83           $t his -> fil lMyArrays( );
    84           $t his -> oJS ONObject =  new BxDol PFMAreaJSO NObj( $thi s );
    85           $o JSONConv =  new Servi ces_JSON() ;
    86           re turn $oJSO NConv -> e ncode( $th is -> oJSO NObject );
    87       }
    88       
    89       functi on fillMyA rrays() {
    90           // collect ac tive field s
    91           
    92           // blocks
    93           $s BlocksQuer y = "
    94                SELECT
    95                    `ID` ,
    96                    `Nam e`
    97                FROM `Pr ofileField s`
    98                WHERE
    99                    `{$t his -> are aOrderCol} ` IS NOT N ULL AND
    100                    `Typ e` = 'bloc k'
    101                ORDER BY
    102                    `{$t his -> are aOrderCol} `
    103           ";
    104           
    105           $r Blocks = d b_res( $sB locksQuery  );
    106           
    107           wh ile( $aBlo ck = mysql _fetch_ass oc( $rBloc ks ) ) {
    108                $iBlockI D = $aBloc k['ID'];
    109                
    110                $this ->  aBlocks[  $iBlockID  ] = $aBloc k['Name'];
    111                
    112                //get it ems of thi s block
    113                $sItemsQ uery = "
    114                    SELE CT
    115                         `ID`,
    116                         `Name`
    117                    FROM  `ProfileF ields`
    118                    WHER E
    119                         `Type` !=  'block' AN D
    120                         `{$this ->  areaOrder Col}` IS N OT NULL AN D
    121                         `{$this ->  areaBlock Col}` = $i BlockID AN D
    122                         (
    123                             `Type`  != 'syste m' OR
    124                             (
    125                                 `T ype` = 'sy stem' AND
    126                                 FI ND_IN_SET(  `Name`, ' {$this ->  areaSysIte ms}' )
    127                             )
    128                         )
    129                    ORDE R BY
    130                         `{$this ->  areaOrder Col}`
    131                ";
    132                
    133                $rItems  = db_res(  $sItemsQue ry );
    134                
    135                while( $ aItem = my sql_fetch_ assoc( $rI tems ) )
    136                    $thi s -> aItem s[ $aItem[ 'ID'] ] =  array( $aI tem['Name' ], $iBlock ID );
    137           }
    138           
    139           // collect in active fie lds
    140           
    141           // blocks
    142           $s BlocksInac Query = "
    143                SELECT
    144                    `ID` ,
    145                    `Nam e`
    146                FROM `Pr ofileField s`
    147                WHERE
    148                    `{$t his -> are aOrderCol} ` IS NULL  AND
    149                    `Typ e` = 'bloc k'
    150           ";
    151           
    152           $r BlocksInac  = db_res(  $sBlocksI nacQuery ) ;
    153           
    154           wh ile( $aBlo ck = mysql _fetch_ass oc( $rBloc ksInac ) )
    155                $this ->  aBlocksIn ac[ $aBloc k['ID'] ]  = $aBlock[ 'Name'];
    156           
    157           // items
    158           $s ActiveBloc ksList = i mplode( ', ', array_k eys( $this  -> aBlock s ) );
    159           if ( $sActive BlocksList  == '' )
    160                $sActive BlocksList  = "NULL";
    161           
    162           $s ItemsInacQ uery = "
    163                SELECT
    164                    `ID` ,
    165                    `Nam e`
    166                FROM `Pr ofileField s`
    167                WHERE
    168                    `Typ e` != 'blo ck' AND (
    169                         `{$this ->  areaBlock Col}` = 0  OR
    170                         `{$this ->  areaBlock Col}` NOT  IN ($sActi veBlocksLi st)
    171                    ) AN D (
    172                         `Type` !=  'system' O R (
    173                             `Type`  = 'system ' AND
    174                             FIND_I N_SET( `Na me`, '{$th is -> area SysItems}'  )
    175                         )
    176                    )
    177           ";
    178           
    179           $r ItemsInac  = db_res(  $sItemsIna cQuery );
    180           
    181           wh ile( $aIte m = mysql_ fetch_asso c( $rItems Inac ) )
    182                $this ->  aItemsIna c[ $aItem[ 'ID'] ] =  $aItem['Na me'];
    183           
    184           // echoDbg( $ this );exi t;
    185       }
    186       
    187       functi on savePos itions( $a InArrays )  {
    188           db _res( "UPD ATE `Profi leFields`  SET `{$thi s -> areaO rderCol}`  = NULL" );
    189           db _res( "UPD ATE `Profi leFields`  SET `{$thi s -> areaB lockCol}`  = 0" );
    190           
    191           if ( is_array ( $aInArra ys['blocks '] ) ) {
    192                foreach(  $aInArray s['blocks' ] as $iBlo ckID ) {
    193                    $iBl ockID = (i nt)$iBlock ID;
    194                    
    195                    $iBl ockOrd = ( int)db_val ue( "
    196                         SELECT MAX ( `{$this  -> areaOrd erCol}` )
    197                         FROM `Prof ileFields`
    198                         WHERE `Typ e` = 'bloc k'
    199                    " )  + 1;
    200                    
    201                    db_r es( "
    202                         UPDATE `Pr ofileField s`
    203                         SET `{$thi s -> areaO rderCol}`  = $iBlockO rd
    204                         WHERE `ID`  = $iBlock ID
    205                    " );
    206                }
    207                
    208                if( is_a rray( $aIn Arrays['it ems'] ) an d is_array ( $aInArra ys['items_ blocks'] )  ) {
    209                    fore ach( $aInA rrays['ite ms'] as $i ItemID ) {
    210                         $iItemID =  (int)$iIt emID;
    211                         $iItemBloc kID = (int )$aInArray s['items_b locks'][$i ItemID];
    212                        
    213                         if( in_arr ay( $iItem BlockID, $ aInArrays[ 'blocks']  ) ) {
    214                             $iItem Ord = db_v alue( "
    215                                 SE LECT MAX(  `{$this ->  areaOrder Col}` )
    216                                 FR OM `Profil eFields`
    217                                 WH ERE `Type`  != 'block ' AND `{$t his -> are aBlockCol} ` = $iItem BlockID
    218                             " ) +  1;
    219                             
    220                             db_res ( "
    221                                 UP DATE `Prof ileFields`
    222                                 SE T
    223                                      `{$this  -> areaOrd erCol}` =  $iItemOrd,
    224                                      `{$this  -> areaBlo ckCol}` =  $iItemBloc kID
    225                                 WH ERE `ID` =  $iItemID
    226                             " );
    227                         }
    228                    }
    229                }
    230           }
    231           
    232           ec ho 'OK';
    233       }
    234       
    235       functi on genFiel dEditForm(  $iItemID  ) {
    236           $s Query = "
    237                SELECT
    238                    `Nam e`,
    239                    `Typ e`,
    240                    `Con trol`,
    241                    `Ext ra`,
    242                    `Min `,
    243                    `Max `,
    244                    `Val ues`,
    245                    `Use LKey`,
    246                    `Che ck`,
    247                    `Uni que`,
    248                    `Def ault`,
    249                    `Man datory`,
    250                    `Del etable`,
    251                    `Mat chField`,
    252                    `Mat chPercent` " .
    253                    
    254                    ( $t his -> are aEditAddCo ls ?
    255                         ( ', `' .  implode( ' `, `', $th is -> area EditAddCol s ) . '`'  ) :
    256                         ''
    257                    ) .  "
    258                    
    259                FROM `Pr ofileField s` WHERE ` ID` = $iIt emID";
    260           
    261           $a Field = db _assoc_arr ( $sQuery  );
    262           
    263           if ( !$aField  ) {
    264                echo 'Er ror. Field  not found ';
    265                return;
    266           }
    267           
    268           //  field tit le and des cription
    269           $t his -> fie ldCaption  = "_FieldC aption_{$a Field['Nam e']}_{$thi s -> areaP ageName}";  // _Field Caption_Se x_Join
    270           $t his -> fie ldDesc     = "_FieldD esc_{$aFie ld['Name'] }_{$this - > areaPage Name}";     // _Field Desc_Sex_J oin
    271           
    272           $t his -> sho wFormTabs  = ( $aFiel d['Type']  != 'block'  and $aFie ld['Type']  != 'syste m' );
    273           
    274           
    275           ?>
    276           <i nput type= "hidden" n ame="actio n" value=" saveItem"  />
    277           <i nput type= "hidden" n ame="id" v alue="<?=  $iItemID ? >" />
    278           <i nput type= "hidden" n ame="area"  value="<? = $this ->  iAreaID ? >" />
    279           
    280           <?
    281           if ( $this ->  showFormT abs ) {
    282                ?>
    283           <d iv class=" form_tabs_ cont">
    284                <ul id=" form_tabs_ switcher">
    285                    <li> <a href="# f1">Genera l</a></li>
    286                    <li> <a href="# f2">Advanc ed</a></li >
    287                    <li> <a href="# f3">Messag es</a></li >
    288                    <li> <a href="# f4">Matchi ng</a></li >
    289                </ul>
    290           </ div>
    291                <?
    292           }
    293           ?>
    294           
    295           
    296           <t able class ="field_ed it_tab" id ="f1"> <!- - General  -->
    297                <tr>
    298                    <td  class="lab el">Name:< /td>
    299                    <td  class="val ue">
    300                         <input typ e="text" m axlength=" 255" class ="input_te xt" name=" Name"
    301                           value="< ?= htmlspe cialchars(  $aField[' Name'] );  ?>"
    302                           <? if( $ aField['Ty pe'] == 's ystem' or  !$aField[' Deletable' ] ) echo ' readonly=" readonly"' ; ?> />
    303                    </td >
    304                    <td  class="inf o">
    305           <?
    306           if ( $aField[ 'Type'] !=  'block' a nd $aField ['Type'] ! = 'system'  )
    307                echo $th is -> getI nfoIcon( ' System nam e used for  database.  It must b egin with  a latin le tter and c ontain onl y latin le tters, num bers or un derscores. ');
    308           el se
    309                echo '&n bsp;';
    310           ?>
    311                    </td >
    312                </tr>
    313                <tr>
    314                    <td  class="lab el">Captio n:</td>
    315                    <td  class="val ue">
    316                         <input typ e="text" m axlength=" 255" class ="input_te xt" name=" Caption"
    317                           value="< ?= htmlspe cialchars(  $this ->  getLangStr ing( $this  -> fieldC aption ) ) ; ?>" />
    318                    </td >
    319                    <td  class="inf o">
    320                         <?= $this  -> getInfo Icon( "Tra nslation o f the item  caption o n the {$th is -> area PageName}  page to de fault lang uage. Used  key: <b>{ $this -> f ieldCaptio n}</b>. Do  not type  HTML code  here!" ) ? >
    321                    </td >
    322                </tr>
    323                <tr>
    324                    <td  class="lab el">Descri ption:</td >
    325                    <td  class="val ue">
    326                         <textarea  class="inp ut_text" n ame="Desc" ><?= htmls pecialchar s( $this - > getLangS tring( $th is -> fiel dDesc ) );  ?></texta rea>
    327                    </td >
    328                    <td  class="inf o">
    329                         <?= $this  -> getInfo Icon( "Tra nslation o f the item  descripti on on the  {$this ->  areaPageNa me} page t o default  language.  Used key:  <b>{$this  -> fieldDe sc}</b>."  ) ?>
    330                    </td >
    331                </tr>
    332           <?
    333           
    334           if ( $aField[ 'Type'] ==  'block' )  {
    335                if( $thi s -> iArea ID == 1 )  { //Join
    336                    ?>
    337                <tr>
    338                    <td  class="lab el">Join P age:</td>
    339                    <td  class="val ue">
    340                         <?= $this  -> getJoin PagesSelec tor( $aFie ld['JoinPa ge'] ) ?>
    341                    </td >
    342                    <td  class="inf o">&nbsp;< /td>
    343                </tr>
    344                    <?
    345                }
    346           }  else {
    347                ?>
    348                <tr>
    349                    <td  class="lab el">Type:< /td>
    350                    <td  class="val ue">
    351                <?
    352                if( $aFi eld['Type' ] == 'syst em' )
    353                    echo  'System';
    354                else {
    355                    ?>
    356                         <select na me="Type"  class="sel ect_type"  onchange=" changeFiel dType( thi s.value ); ">
    357                             <?= $t his -> get TypeOption s( $aField ['Type'] )  ?>
    358                         </select>
    359                    <?
    360                }
    361                ?>
    362                    </td >
    363                    <td  class="inf o">&nbsp;< /td>
    364                </tr>
    365                <?
    366           }
    367           
    368           // system fie lds proper ties
    369           if ( $aField[ 'Name'] ==  'Keyword'  ) {
    370                ?>
    371                <tr>
    372                    <td  class="lab el">Search  in fields :</td>
    373                    <td  class="val ue">
    374                         <select na me="Keywor dFields[]"  class="se lect_multi ple" multi ple="multi ple">
    375                             <?= $t his -> get FieldsOpti onsList( $ aField['Ex tra'], 'Ke yword' ) ? >
    376                         </select>
    377                    </td >
    378                    <td  class="inf o">
    379                         <?= $this  -> getInfo Icon( 'Sel ect fields  in which  the Keywor d will be  able to se arch. Use  Ctrl key t o select f ew fields. ' ) ?>
    380                    </td >
    381                </tr>
    382                <?
    383           }  elseif( $a Field['Nam e'] == 'Co uple' ) {
    384                ?>
    385                <tr>
    386                    <td  class="lab el">Mutual  couple fi elds:</td>
    387                    <td  class="val ue">
    388                         <select na me="Couple Fields[]"  class="sel ect_multip le" multip le="multip le">
    389                             <?= $t his -> get FieldsOpti onsList( $ aField['Ex tra'], 'Co uple' ) ?>
    390                         </select>
    391                    </td >
    392                    <td  class="inf o">
    393                         <?= $this  -> getInfo Icon( 'Sel ect fields  which wil l be used  as mutual  for both p ersons in  a couple.  Use Ctrl k ey to sele ct few fie lds.<br /> <b>Note:</ b> NickNam e, Passwor d and Emai l are mand atory mutu al.' ) ?>
    394                    </td >
    395                </tr>
    396                <?
    397           }
    398           
    399           ?>
    400           </ table>
    401           
    402           <?
    403           
    404           if ( $this ->  showFormT abs ) {
    405                $this ->  genFormAd vTab( $aFi eld );
    406                $this ->  genFormMi scTab( $aF ield );
    407                $this ->  genFormMa tchTab( $a Field );
    408           }
    409           
    410           ?>
    411           <t able class ="field_ed it_tab"> < !--Control s-->
    412                <tr>
    413                    <td  class="but tons" cols pan="3">
    414                         <input typ e="submit"  name="act ion" value ="Save" />
    415           <?
    416           
    417           if ( $aField[ 'Type'] !=  'system'  and $aFiel d['Deletab le'] ) {
    418                ?>
    419                         <input typ e="submit"  name="act ion" value ="Delete"  onclick="r eturn conf irm('Are y ou sure wa nt to dele te this it em?\nAtten tion! The  field will  be delete d forever.  This oper ation irre versible!' );" />
    420                <?
    421           }
    422           ?>
    423                         <input typ e="reset"  value="Can cel" />
    424                    </td >
    425                </tr>
    426           </ table>
    427           
    428           <s cript type ="text/jav ascript">
    429                $(docume nt).ready(  function( ){
    430                    $('# form_tabs_ switcher') .tabs();
    431                    chan geFieldTyp e( '<?= $a Field['Typ e'] ?>' );
    432                } );
    433           </ script>
    434           <?
    435       }
    436       
    437       functi on getFiel dsOptionsL ist( $sSel ected, $sT ype ) {
    438           $a Selected =  explode(  "\n", $sSe lected );
    439           fo reach( $aS elected as  $iKey =>  $sValue )
    440                $aSelect ed[$iKey]  = trim( $s Value );
    441           
    442           sw itch( $sTy pe ) {
    443                case 'Ke yword': $s Where = "` Type` = 't ext' OR `T ype` = 'ar ea'"; brea k;
    444                case 'Co uple' : $s Where = "` Type` != ' block' AND  `Type` !=  'system'  AND `Delet able` = 1" ; break;
    445                default        : $s Where = "0 ";
    446           }
    447           
    448           
    449           
    450           $s Query = "S ELECT `Nam e` FROM `P rofileFiel ds` WHERE  $sWhere";
    451           $r Fields = d b_res( $sQ uery );
    452           
    453           $s Ret = '';
    454           wh ile( $aFie ld = mysql _fetch_ass oc( $rFiel ds ) ) {
    455                $sRet .=  '<option  value="' .  $aField[' Name'] . ' "' .
    456                ( in_arr ay( $aFiel d['Name'],  $aSelecte d ) ? 'sel ected="sel ected"' :  '' ) . '>'  .
    457                $aField[ 'Name'] .  '</option> ';
    458           }
    459           
    460           re turn $sRet ;
    461       }
    462       
    463       functi on getJoin PagesSelec tor( $iCur rent ) {
    464           $s Query = "S ELECT MAX(  `JoinPage ` ) FROM ` ProfileFie lds`";
    465           $i MaxPage =  (int)db_va lue( $sQue ry );
    466           
    467           $s Ret = '<se lect name= "JoinPage"  class="se lect_page" >';
    468           fo r( $iPage  = 0; $iPag e <= ( $iM axPage + 1  ); $iPage  ++ ) {
    469                $sRet .=  
    470                    '<op tion value ="' . $iPa ge . '"' .
    471                    ( (  $iPage ==  $iCurrent  ) ? ' sele cted="sele cted"' : ' ' ) . '>'  .
    472                    $iPa ge . '</op tion>';
    473           }
    474           $s Ret .= '</ select>';
    475           
    476           re turn $sRet ;
    477       }
    478       
    479       functi on genForm MatchTab(  $aField )  {
    480           $a Form = arr ay(
    481                'MatchFi eld' => ar ray(
    482                    'lab el' => 'Ma tch with f ield',
    483                    'typ e'  => 'se lect',
    484                    'inf o'  => 'Se lect a fie ld which w ill be mat ched with  the curren t.<br /> < b>Note:</b > We recom mend using  the same  field.',
    485                    'val ue' => $aF ield['Matc hField'],
    486                    'val ues' => $t his -> get MatchField s( $aField  )
    487                ),
    488                'MatchPe rcent' =>  array(
    489                    'lab el' => 'Ma tch percen t',
    490                    'typ e'  => 'te xt',
    491                    'inf o'  => 'En ter percen tage that  this field  will matc h',
    492                    'val ue' => $aF ield['Matc hPercent']
    493                )
    494           );
    495           
    496           $t his -> gen TableEdit(  $aForm, ' f4' );
    497       }
    498       
    499       functi on getMatc hFields( $ aField ) {
    500           $a SelectFiel ds = array ( $aField[ 'Type'] );
    501           
    502           sw itch( $aFi eld['Type' ] ) {
    503                case 'se lect_set':
    504                    $aSe lectFields [] = 'sele ct_one';
    505                break;
    506                
    507                case 'se lect_one':
    508                    $aSe lectFields [] = 'sele ct_set';
    509                break;
    510                
    511                case 'ra nge':
    512                    $aSe lectFields [] = 'num' ;
    513                    $aSe lectFields [] = 'date ';
    514                break;
    515           }
    516           
    517           $s Query = "S ELECT `ID` , `Name` F ROM `Profi leFields`  WHERE FIND _IN_SET( ` Type`, '"  . implode(  ',', $aSe lectFields  ) . "' )" ;
    518           $r MyFields =  db_res( $ sQuery );
    519           
    520           $a MyFields =  array( '0 ' => '-Not  set-' );
    521           wh ile( $aMyF ield = mys ql_fetch_a ssoc( $rMy Fields ) )  {
    522                $aMyFiel ds[ $aMyFi eld['ID']  ] = $aMyFi eld['Name' ];
    523           }
    524           
    525           re turn $aMyF ields;
    526       }
    527       
    528       functi on genForm AdvTab( $a Field ) {
    529           
    530           $a Form = arr ay(
    531                'Control _one' => a rray(
    532                    'lab el'  => 'S elector co ntrol',
    533                    'typ e'   => 's elect',
    534                    'inf o'   => 'T he type of  form inpu t (HTML-el ement).',
    535                    'val ue'  => $a Field['Con trol'],
    536                    'row _id' => 'f ield_contr ol_select_ one',
    537                    'val ues' => ar ray( 
    538                         'select' = > 'Select  (Dropdown  box)',
    539                         'radio'  = > 'Radio-b uttons'
    540                    )
    541                ),
    542                'Control _set' => a rray(
    543                    'lab el'  => 'M ultiple se lector con trol',
    544                    'typ e'   => 's elect',
    545                    'inf o'   => 'T he type of  form inpu t (HTML-el ement).',
    546                    'val ue'  => $a Field['Con trol'],
    547                    'row _id' => 'f ield_contr ol_select_ set',
    548                    'val ues' => ar ray( 
    549                         'select' = > 'Select  (Box)',
    550                         'checkbox'  => 'Check boxes'
    551                    )
    552                ),
    553                'Mandato ry' => arr ay(
    554                    'lab el'  => 'M andatory',
    555                    'typ e'   => 'c heckbox',
    556                    'inf o'   => 'R ed asteris k indicate s a field  which requ ires a man datory ent ry.',
    557                    'val ue'  => $a Field['Man datory']
    558                ),
    559                'Min' =>  array(
    560                    'lab el'  => 'M inimum val ue',
    561                    'typ e'   => 't ext',
    562                    'inf o'   => 'F or "text"  or "passwo rd" - mini mum length , for "num ber" - min imum numbe r, etc. Le ave it emp ty for no  restrictio n.',
    563                    'val ue'  => $a Field['Min '],
    564                    'row _id' => 'f ield_minim um'
    565                ),
    566                'Max' =>  array(
    567                    'lab el'  => 'M aximum val ue',
    568                    'typ e'   => 't ext',
    569                    'inf o'   => 'F or "text"  or "passwo rd" - maxi mum length , for "num ber" - max imum numbe r, etc. Le ave it emp ty for no  restrictio n.',
    570                    'val ue'  => $a Field['Max '],
    571                    'row _id' => 'f ield_maxim um'
    572                ),
    573                'Unique'  => array(
    574                    'lab el'  => 'U nique',
    575                    'typ e'   => 'c heckbox',
    576                    'inf o'   => 'D efine if f ield value  for membe r must be  unique. Fo r example,  NickName  or Email.' ,
    577                    'val ue'  => $a Field['Uni que'],
    578                    'row _id' => 'f ield_uniqu e'
    579                ),
    580                'Check'  => array(
    581                    'lab el'  => 'C heck',
    582                    'typ e'   => 't extarea',
    583                    'inf o'   => 'S ome specif ic check ( PHP-expres sion). For  example,  for checki ng Email,  etc. Atten tion! Do n ot put her e min/max/ unique che cks. They  are define d above.',
    584                    'val ue'  => $a Field['Che ck'],
    585                    'row _id' => 'f ield_check '
    586                ),
    587                'Values'  => array(
    588                    'lab el'  => 'P ossible va lues',
    589                    'typ e'   => 'v alues',
    590                    'inf o'   => 'L ist of pos sible valu es for sel ectors. Us e new line  as divide r. Also it  can be li nk to pred efined lis t. Please  do not cha nge it if  in doubt!' ,
    591                    'val ue'  => $a Field['Val ues'],
    592                    'row _id' => 'f ield_value s'
    593                ),
    594                'UseLKey ' => array (
    595                    'lab el'  => 'U sed lang.  key',
    596                    'typ e'   => 's elect',
    597                    'inf o'   => 'F or selecto rs with "l inked" val ues list y ou can use  different  language  keys. We r ecommend t o not chan ge it if y ou are in  doubt. The  default i s "LKey".' ,
    598                    'val ue'  => $a Field['Use LKey'],
    599                    'row _id' => 'f ield_lkey' ,
    600                    'val ues' => ar ray( 
    601                         'LKey'  =>  'LKey',
    602                         'LKey2' =>  'LKey2',
    603                         'LKey3' =>  'LKey3',
    604                    )
    605                ),
    606                'Default ' => array (
    607                    'lab el'  => 'D efault val ue',
    608                    'typ e'   => 't ext',
    609                    'inf o'   => 'D efault val ue set int o database (!) if not  set by us er. Non-ma ndatory. F or boolean  fields us e 0 or 1.  For dates  use format : YYYY-MM- DD. Please  do not ch ange it if  in doubt! ',
    610                    'val ue'  => $a Field['Def ault'],
    611                    'row _id' => 'f ield_defau lt'
    612                )
    613           );
    614           
    615           $t his -> gen TableEdit(  $aForm, ' f2' );
    616       }
    617       
    618       functi on genTabl eEdit( $aF orm, $sID  = '' ) {
    619           ?>
    620           <t able class ="field_ed it_tab" <? = $sID ? (  'id="' .  $sID . '"'  ) : '' ?> >
    621           
    622           <?
    623           fo reach( $aF orm as $sI nputName = > $aInput  ) {
    624                ?>
    625                <tr <?=  $aInput['r ow_id'] ?  ( 'id="' .  $aInput[' row_id'] .  '"' ) : ' ' ?>>
    626                    <td  class="lab el"><?= $a Input['lab el'] ?>:</ td>
    627                    <td  class="val ue">
    628                <?
    629                switch(  $aInput['t ype'] ) {
    630                    case  'textarea ':
    631                         ?>
    632                         <textarea  name="<?=  $sInputNam e ?>" clas s="input_t ext"><?= h tmlspecial chars( $aI nput['valu e'] ) ?></ textarea>
    633                         <?
    634                    brea k;
    635                    case  'checkbox ':
    636                         ?>
    637                         <input typ e="checkbo x" name="< ?= $sInput Name ?>" v alue="yes"  class="in put_checkb ox"
    638                           <?= $aIn put['value '] ? 'chec ked="check ed"' : ''  ?> />
    639                         <?
    640                    brea k;
    641                    case  'text':
    642                         ?>
    643                         <input typ e="text" n ame="<?= $ sInputName  ?>" value ="<?= html specialcha rs( $aInpu t['value']  ) ?>" cla ss="input_ text" />
    644                         <?
    645                    brea k;
    646                    case  'select':
    647                         ?>
    648                         <select na me="<?= $s InputName  ?>" class= "select_ty pe">
    649                         <?
    650                         foreach( $ aInput['va lues'] as  $sKey => $ sValue ) {
    651                             ?>
    652                             <optio n value="< ?= $sKey ? >" <?= ( $ sKey == $a Input['val ue'] ) ? ' selected=" selected"'  : '' ?>>< ?= $sValue  ?></optio n>
    653                             <?
    654                         }
    655                         ?>
    656                         </select>
    657                         <?
    658                    brea k;
    659                    case  'values':
    660                         if( substr ( $aInput[ 'value'],  0, 2 ) ==  $this -> s LinkPref )  { //it is  link
    661                             $sLink  = substr(  $aInput[' value'], 2  );
    662                             ?>
    663                         <input typ e="hidden"  name="<?=  $sInputNa me ?>" val ue="<?= ht mlspecialc hars( $aIn put['value '] ) ?>" / >
    664                         <a href="p reValues.p hp?list=<? = urlencod e( $sLink  ) ?>" targ et="_blank "
    665                           onclick= "return !w indow.open ( this.hre f + '&popu p=1', 'pre ValuesEdit ', 'width= 750,height =700,resiz able=yes,s crollbars= yes,toolba r=no,statu s=no,menub ar=no' );"
    666                           title="E dit list"> <?= $sLink  ?></a>
    667                        
    668                         <a href="j avascript: void(0);"  onclick="a ctivateVal uesEdit( t his );" ti tle="Chang e link" st yle="margi n-left:20p x;">
    669                             <img s rc="images /edit.gif"  alt="Chan ge" />
    670                         </a>
    671                             <?
    672                         }
    673                         else { //i t is simpl e list
    674                             ?>
    675                         <textarea  class="inp ut_text" n ame="<?= $ sInputName  ?>"><?= h tmlspecial chars( $aI nput['valu e'] ) ?></ textarea>
    676                             <?
    677                         }
    678                    brea k;
    679                }
    680                ?>
    681                    </td >
    682                    <td  class="inf o">
    683                         <?= $this  -> getInfo Icon( $aIn put['info' ] ) ?>
    684                    </td >
    685                </tr>
    686                <?
    687           }
    688           ?>
    689           
    690           </ table>
    691           <?
    692       }
    693       
    694       //used  for parsi ng extra p arameters
    695       functi on parsePa rams( $sPa rams ) {
    696           if ( $sParams  == '' )
    697                return a rray();
    698           
    699           $a Params = a rray();
    700           
    701           $a ParamLines  = explode ( "\n", $s Params );
    702           
    703           fo reach( $aP aramLines  as $sLine  ) {
    704                list( $s Key, $sVal ue) = expl ode( ':',  $sLine, 2  );
    705                $aParams [$sKey] =  $sValue;
    706           }
    707           
    708           re turn $aPar ams;
    709       }
    710       
    711       functi on genForm MiscTab( $ aField ) {
    712           $a Form = arr ay(
    713                'Mandato ry_msg' =>  array(
    714                    'lab el'  => 'M andatory e rror messa ge',
    715                    'typ e'   => 't extarea',
    716                    'inf o'   => 'E rror messa ge returne d if user  didn\'t sp ecify valu e when fie ld is mand atory. Tra nslated to  default l anguage (f or other l anguages -  use key:  _FieldErro r_' . $aFi eld['Name' ] . '_Mand atory). Th is texts i s non-mand atory fiel d is non-m andatory.' ,
    717                    'val ue'  => $t his -> get LangString ( "_FieldE rror_{$aFi eld['Name' ]}_Mandato ry" ),
    718                    /*'r ow_id' =>  'field_man datory_msg '*/
    719                ),
    720                'Min_msg ' => array (
    721                    'lab el'  => 'M inimum exc eed error  message',
    722                    'typ e'   => 't extarea',
    723                    'inf o'   => 'E rror messa ge returne d when fie ld minimum  limit exc eeded. Tra nslated to  default l anguage (f or other l anguages -  use key:  _FieldErro r_' . $aFi eld['Name' ] . '_Min) . Non-mand atory if m inimum lim it is not  defined.',
    724                    'val ue'  => $t his -> get LangString ( "_FieldE rror_{$aFi eld['Name' ]}_Min" ),
    725                    'row _id' => 'f ield_minim um_msg'
    726                ),
    727                'Max_msg ' => array (
    728                    'lab el'  => 'M aximum exc eed error  message',
    729                    'typ e'   => 't extarea',
    730                    'inf o'   => 'E rror messa ge returne d when fie ld maximum  limit exc eeded. Tra nslated to  default l anguage (f or other l anguages -  use key:  _FieldErro r_' . $aFi eld['Name' ] . '_Max) . Non-mand atory if m aximum lim it is not  defined.',
    731                    'val ue'  => $t his -> get LangString ( "_FieldE rror_{$aFi eld['Name' ]}_Max" ),
    732                    'row _id' => 'f ield_maxim um_msg'
    733                ),
    734                'Unique_ msg' => ar ray(
    735                    'lab el'  => 'N on-unique  error mess age',
    736                    'typ e'   => 't extarea',
    737                    'inf o'   => 'E rror messa ge returne d if user  entered no n-unique v alue. Tran slated to  default la nguage (fo r other la nguages -  use key: _ FieldError _' . $aFie ld['Name']  . '_Uniqu e). Non-ma ndatory if  Unique is  not set.' ,
    738                    'val ue'  => $t his -> get LangString ( "_FieldE rror_{$aFi eld['Name' ]}_Unique"  ),
    739                    'row _id' => 'f ield_uniqu e_msg'
    740                ),
    741                'Check_m sg' => arr ay(
    742                    'lab el'  => 'C heck error  message',
    743                    'typ e'   => 't extarea',
    744                    'inf o'   => 'E rror messa ge returne d if field  Check is  failed (fo r other la nguages -  use key: _ FieldError _' . $aFie ld['Name']  . '_Check ). Transla ted to def ault langu age. Non-m andatory i f Check is  not defin ed.',
    745                    'val ue'  => $t his -> get LangString ( "_FieldE rror_{$aFi eld['Name' ]}_Check"  ),
    746                    'row _id' => 'f ield_check _msg'
    747                )
    748           );
    749                
    750           $t his -> gen TableEdit(  $aForm, ' f3' );
    751       }
    752       
    753       functi on getInfo Icon( $sTe xt ) {
    754           re turn '
    755           <i mg src="im ages/info. gif" class ="info_ico n"
    756              onmouseove r="showFlo atDesc(\''  . htmlspe cialchars(  $sText )  . '\');"
    757              onmousemov e="moveFlo atDesc( ev ent )"
    758              onmouseout ="hideFloa tDesc();"  />
    759           ';
    760       }
    761       
    762       functi on getType Options( $ sActive )  {
    763           $s Ret = '';
    764           
    765           fo reach( $th is -> aTyp es as $sKe y => $sVal ue ) {
    766                $sRet .=  '<option  value="' .  $sKey . ' " ' . ( $s Active ==  $sKey ? 's elected="s elected"'  : '') . '> ' . $sValu e . '</opt ion>';
    767           }
    768           
    769           re turn $sRet ;
    770       }
    771       
    772       functi on getLang String( $s Key ) {
    773           if ( $sKey ==  '' )
    774                return ' ';
    775           
    776           $s Key_db     = addslash es( $sKey  );
    777           $s String_db  = addslash es( $sStri ng );
    778           
    779           $s Query = "S ELECT `ID`  FROM `Loc alizationK eys` WHERE  `Key` = ' $sKey_db'" ;
    780           $i KeyID = (i nt)db_valu e( $sQuery  );
    781           
    782           if ( !$iKeyID  )
    783                return ' ';
    784           
    785           $s Query = "
    786                SELECT ` String` FR OM `Locali zationStri ngs`
    787                WHERE `I DKey` = $i KeyID AND  `IDLanguag e` = {$thi s -> sLang ID}";
    788           
    789           re turn (stri ng)db_valu e( $sQuery  );
    790       }
    791       
    792       functi on saveIte m( $aData  ) {
    793           $t his -> gen SaveItemHe ader();
    794           $t his -> isH aveErrors  = false;
    795           // echoDbg( $ aData );
    796           $i ItemID = ( int)$aData ['id'];
    797           
    798           $a Item = db_ assoc_arr(  "SELECT *  FROM `Pro fileFields ` WHERE `I D` = $iIte mID" );
    799           
    800           if ( !$aItem  ) {
    801                $this ->  genSaveIt emError( ' Warning! F ield not f ound.' );
    802                $this ->  genSaveIt emFooter() ;
    803                return f alse;
    804           }
    805           
    806           //  just a fl ag
    807           $b HaveErrors  = false;
    808           
    809           //  this arra y will be  put into d b
    810           $a Update = a rray();
    811           
    812           //  check nam e
    813           if ( $aItem[' Type'] !=  'system' a nd $aItem[ 'Deletable '] ) { //w e can chan ge the nam e
    814                
    815                $sName =  trim( str ip_tags( p rocess_pas s_data( $a Data['Name '] ) ) );
    816                
    817                if( $sNa me === ''  ) {
    818                    $thi s -> genSa veItemErro r( 'You mu st enter t he name.',  'Name' );
    819                    $bHa veErrors =  true;
    820                } elseif ( $aItem[' Type'] !=  'block' an d !preg_ma tch( '/^[a -z][a-z0-9 _]*$/i', $ sName ) )  {
    821                    $thi s -> genSa veItemErro r( 'The na me must be gin with a  latin let ter and co ntain only  latin let ters, numb ers or und erscores.' , 'Name' ) ;
    822                    $bHa veErrors =  true;
    823                } elseif ( db_value ( "SELECT  COUNT(*) F ROM `Profi leFields`  WHERE `Nam e` = '$sNa me' and `I D` != $iIt emID" ) )  {
    824                    $thi s -> genSa veItemErro r( 'A fiel d with suc h name alr eady exist s. Please  select ano ther.', 'N ame' );
    825                    $bHa veErrors =  true;
    826                } elseif ( $sName = = $aItem[' Name'] ) {
    827                    // a ll ok. don 't change
    828                } else
    829                    $aUp date['Name '] = $sNam e; //chang e
    830           }
    831           
    832           $s NewName =  isset( $aU pdate['Nam e'] ) ? $a Update['Na me'] : $aI tem['Name' ];
    833           
    834           $t his -> fie ldCaption  = "_FieldC aption_{$s NewName}_{ $this -> a reaPageNam e}"; // _F ieldCaptio n_Sex_Join
    835           $t his -> fie ldDesc     = "_FieldD esc_{$sNew Name}_{$th is -> area PageName}" ;    // _F ieldDesc_S ex_Join
    836           
    837           //  check Cap tion
    838           $s Caption =  trim( proc ess_pass_d ata( $aDat a['Caption '] ) );
    839           
    840           if ( $sCaptio n === '' )  {
    841                $this ->  genSaveIt emError( ' You must e nter the c aption.',  'Caption'  );
    842                $bHaveEr rors = tru e;
    843           }  elseif( $t his -> get LangString ( $this ->  fieldCapt ion ) == $ sCaption )  {
    844                // all o k dont cha nge
    845           }  else
    846                $this ->  updateLan gString( $ this -> fi eldCaption , $sCaptio n );
    847           
    848           //  check Des cription
    849           $s Desc = tri m( process _pass_data ( $aData[' Desc'] ) ) ;
    850           if ( $this ->  getLangSt ring( $thi s -> field Desc ) !=  $sDesc )
    851                $this ->  updateLan gString( $ this -> fi eldDesc, $ sDesc );
    852           
    853           //  check typ e
    854           if ( $aItem[' Type'] !=  'system' a nd $aItem[ 'Type'] !=  'block' )  {
    855                
    856                //we can  change th e type
    857                $sType =  trim( str ip_tags( p rocess_pas s_data( $a Data['Type '] ) ) );
    858                
    859                if( !iss et( $this  -> aTypes[ $sType] )  ) {
    860                    $thi s -> genSa veItemErro r( 'Don\'t  fuck with  my brain!  I don\'t  know this  type.', 'T ype' );
    861                    $bHa veErrors =  true;
    862                } elseif ( $sType = = $aItem[' Type'] ) {
    863                    // a ll ok. don 't change
    864                } else
    865                    $aUp date['Type '] = $sTyp e; //chang e
    866           
    867                // check  the addit ional prop erties
    868                if( !$bH aveErrors  ) { // do  not contin ue if have  errors
    869                    
    870                    // c heck selec tors contr ols
    871                    if(  $sType ==  'select_on e' ) {
    872                         if( $aData ['Control_ one'] == $ aItem['Con trol'] ) {
    873                             //all  ok
    874                         } elseif(  $aData['Co ntrol_one' ] == 'sele ct' or $aD ata['Contr ol_one'] = = 'radio'  ) {
    875                             $aUpda te['Contro l'] = $aDa ta['Contro l_one'];
    876                         } else {
    877                             $this  -> genSave ItemError(  'I don\'t  know this  control t ype.', 'Co ntrol_one'  );
    878                             $bHave Errors = t rue;
    879                         }
    880                    } el seif( $sTy pe == 'sel ect_set' )  {
    881                         if( $aData ['Control_ set'] == $ aItem['Con trol'] ) {
    882                             //all  ok
    883                         } elseif(  $aData['Co ntrol_set' ] == 'sele ct' or $aD ata['Contr ol_set'] = = 'checkbo x' ) {
    884                             $aUpda te['Contro l'] = $aDa ta['Contro l_set'];
    885                         } else {
    886                             $this  -> genSave ItemError(  'I don\'t  know this  control t ype.', 'Co ntrol_set'  );
    887                             $bHave Errors = t rue;
    888                         }
    889                    } el se
    890                         $aUpdate[' Control']  = '';
    891                    
    892                    //ch eck Min
    893                    $iMi n = trim(  $aData['Mi n'] );
    894                    
    895                    if(  $iMin ===  '' or $sTy pe == 'boo l' or $sTy pe == 'sel ect_one' o r $sType = = 'select_ set' )
    896                         $iMin = nu ll;
    897                    else  {
    898                         $iMin = (i nt)$iMin;
    899                         if( $sType  == 'area'  and $iMin  > 65534 )
    900                             $iMin  = 65535;
    901                         elseif( $s Type != 'a rea' and $ iMin > 254  )
    902                             $iMin  = 65535;
    903                         elseif( $i Min < 0 )
    904                             $iMin  = 0;
    905                    }
    906                    
    907                    $aUp date['Min' ] = $iMin;
    908                    
    909                    
    910                    //ch eck Max
    911                    $iMa x = trim(  $aData['Ma x'] );
    912                    
    913                    if(  $iMax ===  '' or $sTy pe == 'boo l' or $sTy pe == 'sel ect_one' o r $sType = = 'select_ set' )
    914                         $iMax = nu ll;
    915                    else  {
    916                         $iMax = (i nt)$iMax;
    917                         if( $sType  == 'area'  and $iMax  > 65534 )
    918                             $iMax  = 65535;
    919                         elseif( $s Type != 'a rea' and $ iMax > 254  )
    920                             $iMax  = 65535;
    921                         elseif( $i Max < 0 )
    922                             $iMax  = 0;
    923                    }
    924                    
    925                    $aUp date['Max' ] = $iMax;
    926                    
    927                    //ch eck Check  :)
    928                    if(  $sType ==  'select_on e' or $sTy pe == 'sel ect_set' o r $sType = = 'bool' )
    929                         $aUpdate[' Check'] =  '';
    930                    else  {
    931                         $sCheck =  trim( proc ess_pass_d ata( $aDat a['Check']  ) );
    932                        
    933                         if( $aItem ['Check']  != $sCheck  )
    934                             $aUpda te['Check' ] = $sChec k;
    935                    }
    936                    
    937                    //Un ique
    938                    $aUp date['Uniq ue'] = (
    939                         isset( $aD ata['Uniqu e'] ) and
    940                         $aData['Un ique'] ==  'yes' and
    941                         ( $sType = = 'text' o r $sType = = 'area' o r $sType = = 'num' )
    942                    ) ?  1 : 0;
    943                    
    944                    //Ma ndatory
    945                    $aUp date['Mand atory'] =  ( isset( $ aData['Man datory'] )  and $aDat a['Mandato ry'] == 'y es' ) ? 1  : 0;
    946                    
    947                    //ch eck Values
    948                    if(  $sType ==  'select_on e' or $sTy pe == 'sel ect_set' )  {
    949                         $sValues =  trim( str ip_tags( p rocess_pas s_data( $a Data['Valu es'] ) ) ) ;
    950                        
    951                         $sValues =  str_repla ce( "\r",  "\n", $sVa lues );    // for mac
    952                         $sValues =  str_repla ce( "\n\n" , "\n", $s Values );  // for win
    953                                                                             ;  // for *ni x ;)
    954                        
    955                         if( $sValu es === ''  ) {
    956                             $this  -> genSave ItemError(  'You must  enter val ues', 'Val ues' );
    957                             $bHave Errors = t rue;
    958                         } elseif(  $sValues ! = $aItem[' Values'] )  {
    959                             if( su bstr( $sVa lues, 0, 2  ) == $thi s -> sLink Pref and ! $this -> c heckValues Link( subs tr( $sValu es, 2 ) )  ) {
    960                                 $t his -> gen SaveItemEr ror( 'You  entered in correct li nk', 'Valu es' );
    961                                 $b HaveErrors  = true;
    962                             } else
    963                                 $a Update['Va lues'] = $ sValues;
    964                         }
    965                        
    966                         // get LKe y
    967                         $sUseLKey  = trim( pr ocess_pass _data( $aD ata['UseLK ey'] ) );
    968                         if( !$sUse LKey )
    969                             $sUseL Key = 'LKe y';
    970                        
    971                         $aUpdate[' UseLKey']  = $sUseLKe y;
    972                    } el seif( $aIt em['Values '] != '' )
    973                         $aUpdate[' Values'] =  '';
    974                    
    975                    if(  !$bHaveErr ors ) {
    976                         //Default
    977                         switch( $s Type ) {
    978                             case ' text':
    979                                 $a Update['De fault'] =  trim( proc ess_pass_d ata( $aDat a['Default '] ) );
    980                             break;
    981                             case ' pass':
    982                             case ' area':
    983                             case ' select_set ':
    984                                 $a Update['De fault'] =  '';
    985                             break;
    986                             case ' num':
    987                                 $a Update['De fault'] =  (int)$aDat a['Default '];
    988                             break;
    989                             case ' bool':
    990                                 $a Update['De fault'] =  (int)(bool )$aData['D efault'];
    991                             break;
    992                             case ' range':
    993                                 if ( trim( $a Data['Defa ult'] ) ==  '' )
    994                                      $aUpdate ['Default' ] = '';
    995                                 el se {
    996                                      list( $s First, $sS econd ) =  explode( ' -', trim(  $aData['De fault'], 2  ) ); 
    997                                      $sFirst   = (int)tr im( $sFirs t );
    998                                      $sSecond  = (int)tr im( $sSeco nd );
    999                                      $aUpdate ['Default' ] = "$sFir st-$sSecon d";
    1000                                 }
    1001                             break;
    1002                             case ' date':
    1003                                 if ( $aData[' Default']  === '' )
    1004                                      $aUpdate ['Default' ] = '';
    1005                                 el se
    1006                                      $aUpdate ['Default' ] = date(  'Y-m-d', s trtotime(  trim( proc ess_pass_d ata( $aDat a['Default '] ) ) ) ) ;
    1007                             break;
    1008                             
    1009                             case ' select_one ':
    1010                                 $s Default =  trim( proc ess_pass_d ata( $aDat a['Default '] ) );
    1011                                 if ( $sDefaul t === '' )
    1012                                      $aUpdate ['Default' ] = '';
    1013                                 el se {
    1014                                      if( $thi s -> check SelectDefa ult( $sVal ues, $sDef ault ) )
    1015                                          $aUp date['Defa ult'] = $s Default;
    1016                                      else {
    1017                                          $thi s -> genSa veItemErro r( 'You en tered an i ncorrect v alue', 'De fault' );
    1018                                          $bHa veErrors =  true;
    1019                                      }
    1020                                 }
    1021                             break;
    1022                         }
    1023                        
    1024                         //matching . not impl emented ye t
    1025                    }
    1026                }
    1027           }
    1028           
    1029           if ( $aItem[' Type'] ==  'block' an d $this ->  iAreaID = = 1 ) { // Join
    1030                //get Jo inPage
    1031                $iJoinPa ge = (int) $aData['Jo inPage'];
    1032                if( $aIt em['JoinPa ge'] != $i JoinPage )
    1033                    $aUp date['Join Page'] = $ iJoinPage;
    1034           }
    1035           
    1036           // system fie lds proper ties
    1037           if ( $aItem[' Name'] ==  'Keyword'  ) {
    1038                if( is_a rray( $aDa ta['Keywor dFields']  ) ) {
    1039                    $sKe ywordField s = implod e( "\n", $ aData['Key wordFields '] );
    1040                    
    1041                    if(  process_pa ss_data( $ sKeywordFi elds ) !=  $aItem['Ex tra'] )
    1042                         $aUpdate[' Extra'] =  $sKeywordF ields;
    1043                }
    1044           }
    1045           
    1046           if ( $aItem[' Name'] ==  'Couple' )  {
    1047                if( is_a rray( $aDa ta['Couple Fields'] )  ) {
    1048                    $sKe ywordField s = implod e( "\n", $ aData['Cou pleFields' ] );
    1049                    
    1050                    if(  process_pa ss_data( $ sKeywordFi elds ) !=  $aItem['Ex tra'] )
    1051                         $aUpdate[' Extra'] =  $sKeywordF ields;
    1052                }
    1053           }
    1054           
    1055           //  update er ror messag es
    1056           fo reach( arr ay( 'Manda tory', 'Mi n', 'Max',  'Unique',  'Check' )  as $sErrN ame ) {
    1057                $sErrMsg  = trim( p rocess_pas s_data( $a Data[$sErr Name . '_m sg'] ) );
    1058                if( empt y($sErrMsg ) )
    1059                    cont inue;
    1060                
    1061                $sErrKey  = "_Field Error_{$sN ewName}_{$ sErrName}" ;
    1062                
    1063                $this ->  updateLan gString( $ sErrKey, $ sErrMsg );
    1064           }
    1065           
    1066           //  add match ing
    1067           if ( isset( $ aData['Mat chField']  ) and (int )$aData['M atchField' ] != $aIte m['MatchFi eld'] )
    1068                $aUpdate ['MatchFie ld'] = (in t)$aData[' MatchField '];
    1069           
    1070           if ( isset( $ aData['Mat chPercent' ] ) and (i nt)$aData[ 'MatchPerc ent'] != $ aItem['Mat chPercent' ] )
    1071                $aUpdate ['MatchPer cent'] = ( int)$aData ['MatchPer cent'];
    1072           
    1073           if ( !empty(  $aUpdate )  and !$bHa veErrors )  {
    1074                $this ->  doUpdateI tem( $aIte m, $aUpdat e );
    1075                if( isse t( $aUpdat e['Name']  ) )
    1076                    $thi s -> genSa veItemForm Update( 'u pdateItem' , $iItemID , $aUpdate ['Name'] ) ;
    1077                
    1078                if( $aIt em['Type']  == 'block ' and $aUp date['Name '] ) {
    1079                    $sQu ery = "
    1080                         UPDATE `Pa geCompose`  SET
    1081                             `Capti on` = '_Fi eldCaption _" . addsl ashes( $sN ewName ) .  "_View'
    1082                         WHERE
    1083                             `Func`  = 'PFBloc k' AND
    1084                             `Conte nt` = '$iI temID'
    1085                         ";
    1086                    
    1087                    db_r es( $sQuer y );
    1088                }
    1089           }
    1090           
    1091           if ( !$bHaveE rrors )
    1092                $this ->  genSaveIt emFormClos e();
    1093           
    1094           $t his -> gen SaveItemFo oter();
    1095       }
    1096       
    1097       functi on checkVa luesLink(  $sKey ) {
    1098           gl obal $aPre Values;
    1099           
    1100           re turn isset ( $aPreVal ues[$sKey]  );
    1101       }
    1102       
    1103       functi on checkSe lectDefaul t( $sValue s, $sDefau lt ) {
    1104           gl obal $aPre Values;
    1105           
    1106           if ( substr(  $sValues,  0, 2 ) ==  $this -> s LinkPref )  { //it is  link
    1107                $sKey =  substr( $s Values, 2  );
    1108                return i sset( $aPr eValues[$s Key][$sDef ault] );
    1109           }  else {
    1110                $aValues  = explode ( "\n", $s Values );
    1111                return i n_array( $ sDefault,  $aValues ) ;
    1112           }
    1113       }
    1114       
    1115       functi on doUpdat eItem( $aI tem, $aUpd ate ) {
    1116           gl obal $aPre Values;
    1117           
    1118           $a UpdateStrs  = '';
    1119           fo reach( $aU pdate as $ sKey => $s Value ) {
    1120                if( is_n ull( $sVal ue ) )
    1121                    $aUp dateStrs[]  = "`$sKey ` = NULL";
    1122                else
    1123                    $aUp dateStrs[]  = "`$sKey ` = '" . a ddslashes(  $sValue )  . "'";
    1124           }
    1125           
    1126           $s Query = "
    1127                UPDATE ` ProfileFie lds` SET 
    1128                    " .  implode( "
    1129                    ", $ aUpdateStr s ) . "
    1130                WHERE `I D` = {$aIt em['ID']}" ;
    1131           
    1132           db _res( $sQu ery );
    1133           
    1134           if ( //we nee d alter Pr ofiles tab le
    1135                $aItem[' Type'] !=  'block' an d (
    1136                    isse t( $aUpdat e['Type']  ) or
    1137                    isse t( $aUpdat e['Name']  ) or
    1138                    isse t( $aUpdat e['Values' ] ) or
    1139                    isse t( $aUpdat e['Default '] )
    1140                )
    1141           )  {
    1142                $aAlter  = array(
    1143                    'Typ e'    => i sset( $aUp date['Type ']    ) ?  $aUpdate[' Type']     : $aItem[' Type'],
    1144                    'Nam e'    => i sset( $aUp date['Name ']    ) ?  $aUpdate[' Name']     : $aItem[' Name'],
    1145                    'Val ues'  => i sset( $aUp date['Valu es']  ) ?  $aUpdate[' Values']   : $aItem[' Values'],
    1146                    'Def ault' => i sset( $aUp date['Defa ult'] ) ?  $aUpdate[' Default']  : $aItem[' Default'],
    1147                );
    1148                
    1149                if( subs tr( $aAlte r['Values' ], 0, 2 )  == $this - > sLinkPre f )
    1150                    $aAl ter['Type' ] .= '_lin ked';
    1151                
    1152                $sQuery  = "ALTER T ABLE `Prof iles` CHAN GE `{$aIte m['Name']} ` `{$aAlte r['Name']} ` {$this - > aTypesAl ter[$aAlte r['Type']] }";
    1153                $sQuery  = str_repl ace( '{def ault}', ad dslashes(  $aAlter['D efault'] ) , $sQuery  );
    1154                
    1155                if( $aAl ter['Type' ] == 'sele ct_one' or  $aAlter[' Type'] ==  'select_se t' ) { //i nsert valu es
    1156                    $aVa luesAlter  = explode(  "\n", $aA lter['Valu es'] ); // explode va lues to ar ray
    1157                    
    1158                    fore ach( $aVal uesAlter a s $iKey =>  $sValue ) { //add sl ashes to e very value
    1159                         $sValue =  str_replac e( '\\', ' \\\\', $sV alue );
    1160                         $sValue =  str_replac e( '\'', ' \\\'', $sV alue );
    1161                         $aValuesAl ter[$iKey]  = $sValue ;
    1162                    }
    1163                    
    1164                    $sVa luesAlter  = " '" . i mplode( "' , '", $aVa luesAlter  ) . "' ";  // implode  values to  string li ke 'a','b' ,'c\'d'
    1165                    $sQu ery = str_ replace( ' {values}',  $sValuesA lter, $sQu ery ); //r eplace it  in place
    1166                } elseif ( $aAlter[ 'Type'] ==  'select_s et_linked'  ) {
    1167                    $sLi nk = subst r( $aAlter ['Values'] , 2 );
    1168                    $aVa luesAlter  = array_ke ys( $aPreV alues[$sLi nk] );
    1169                    
    1170                    $sVa luesAlter  = implode(  ', ', $aV aluesAlter  );
    1171                    $sVa luesAlter  = str_repl ace( '\\',  '\\\\', $ sValuesAlt er );
    1172                    $sVa luesAlter  = str_repl ace( '\'',  '\\\'', $ sValuesAlt er );
    1173                    
    1174                    $sVa luesAlter  = "'" .str _replace(  ', ', "',  '", $sValu esAlter )  ."'";
    1175                    
    1176                    $sQu ery = str_ replace( ' {values}',  $sValuesA lter, $sQu ery ); //r eplace it  in place
    1177                }
    1178                
    1179                db_res(  $sQuery );
    1180           }
    1181       }
    1182       
    1183       functi on createN ewField()  {
    1184           $i NewID = 0;
    1185           
    1186           // try to ins ert new it em
    1187           if ( db_res(  "INSERT IN TO `Profil eFields` ( `Name`, `T ype` ) VAL UES ('NEW_ ITEM', 'te xt')", 0 )  and $iNew ID = mysql _insert_id () ) {
    1188                //if suc cess - try  to alter  table
    1189                if( !db_ res( "ALTE R TABLE `P rofiles` A DD `NEW_IT EM` varcha r(255) NOT  NULL defa ult ''", 0  ) ) {
    1190                    //if  couldn't  alter - de lete inser ted field
    1191                    db_r es( "DELET E FROM `Pr ofileField s` WHERE ` ID` = $iNe wID" );
    1192                    $iNe wID = 0;
    1193                }
    1194           }
    1195           
    1196           re turn $iNew ID;
    1197       }
    1198       
    1199       functi on createN ewBlock()  {
    1200           db _res( "INS ERT INTO ` ProfileFie lds` (`Nam e`, `Type`  ) VALUES  ('NEW BLOC K', 'block ')", 0 );
    1201           $i NewID = my sql_insert _id();
    1202           
    1203           db _res( "
    1204                INSERT I NTO `PageC ompose`
    1205                    ( `D esc`, `Cap tion`, `Vi sible`, `F unc`, `Con tent`, `Pa ge` )
    1206                VALUES
    1207                    ( 'P rofile Fie lds Block' , '_FieldC aption_NEW  BLOCK_Vie w', 'non,m emb', 'PFB lock', '$i NewID', 'p rofile' )
    1208           "  );
    1209           
    1210           re turn $iNew ID;
    1211       }
    1212       
    1213       functi on updateL angString(  $sKey, $s String ) {
    1214           
    1215           if ( $sKey ==  '' )
    1216                return f alse;
    1217           
    1218           $s Key_db     = addslash es( $sKey  );
    1219           $s String_db  = addslash es( $sStri ng );
    1220           
    1221           $s Query = "S ELECT `ID`  FROM `Loc alizationK eys` WHERE  `Key` = ' $sKey_db'" ;
    1222           $i KeyID = (i nt)db_valu e( $sQuery  );
    1223           
    1224           if ( !$iKeyID  ) { //cre ate key
    1225                $sQuery  = "INSERT  INTO `Loca lizationKe ys` (`IDCa tegory`,`K ey`) VALUE S (32,'$sK ey_db')";
    1226                db_res(  $sQuery );
    1227                $iKeyID  = mysql_in sert_id();
    1228           }
    1229           
    1230           $s Query = "
    1231                SELECT C OUNT( * )  FROM `Loca lizationSt rings`
    1232                WHERE `I DKey` = $i KeyID AND  `IDLanguag e` = {$thi s -> sLang ID}";
    1233           
    1234           $i Count = (i nt)db_valu e( $sQuery  );
    1235           
    1236           if ( $iCount  ) {
    1237                $sQuery  = "
    1238                    UPDA TE `Locali zationStri ngs`
    1239                    SET  `String` =  '$sString _db'
    1240                    WHER E `IDKey`  = $iKeyID  AND `IDLan guage` = { $this -> s LangID}";
    1241                
    1242                db_res(  $sQuery );
    1243           }  else {
    1244                $sQuery  = "INSERT  INTO `Loca lizationSt rings` VAL UES ( $iKe yID, {$thi s -> sLang ID}, '$sSt ring_db' ) ";
    1245                db_res(  $sQuery );
    1246           }
    1247           
    1248           co mpileLangu age( $this  -> sLangI D );
    1249       }
    1250       
    1251       functi on genSave ItemHeader () {
    1252           ?>
    1253   <html><scr ipt type=" text/javas cript">
    1254           <?
    1255       }
    1256       
    1257       functi on genSave ItemError(  $sText, $ sField = ' ' ) {
    1258           $t his -> isH aveErrors  = true;
    1259           
    1260           if ( !$sField  )
    1261                echo "al ert( '" .  addslashes ( $sText )  . "' );";
    1262           el se {
    1263                ?>
    1264                parent.g enEditForm Error( '<? = $sField  ?>', '<?=  addslashes ( $sText )  ?>' );
    1265                <?
    1266           }
    1267       }
    1268       
    1269       functi on genSave ItemFooter () {
    1270           ?>
    1271  
    1272   </script>< /html>
    1273           <?
    1274       }
    1275       
    1276       functi on deleteI tem( $iIte mID ) {
    1277           $t his -> gen SaveItemHe ader();
    1278           
    1279           $a Item = db_ assoc_arr(  "SELECT *  FROM `Pro fileFields ` WHERE `I D` = $iIte mID" );
    1280           
    1281           if ( !$aItem  )
    1282                $this ->  genSaveIt emError( ' Warning! I tem not fo und.' );
    1283           el seif( $aIt em['Type']  == 'syste m' or !(in t)$aItem[' Deletable' ] )
    1284                $this ->  genSaveIt emError( ' The field  cannot be  deleted.'  );
    1285           el se{
    1286                $sQuery  = "DELETE  FROM `Prof ileFields`  WHERE `ID ` = $iItem ID";
    1287                db_res(  $sQuery );
    1288                
    1289                if( $aIt em['Type']  == 'block ' )
    1290                    db_r es( "DELET E FROM `Pa geCompose`  WHERE `Fu nc` = 'PFB lock' AND  `Content`  = '$iItemI D'" );
    1291                else
    1292                    db_r es( "ALTER  TABLE `Pr ofiles` DR OP `{$aIte m['Name']} `" );
    1293                
    1294                $this ->  genSaveIt emFormUpda te( 'delet eItem', $i ItemID );
    1295                //$this  -> genSave ItemFormCl ose();
    1296           }
    1297           $t his -> gen SaveItemFo oter();
    1298       }
    1299       
    1300       functi on genSave ItemFormUp date( $sTe xt, $iItem ID, $sNewN ame = '' )  {
    1301           ?>
    1302           pa rent.updat eBuilder(  '<?= $sTex t ?>', <?=  $iItemID  ?>, '<?= a ddslashes(  $sNewName  ) ?>' );
    1303           <?
    1304       }
    1305       
    1306       functi on genSave ItemFormCl ose() {
    1307           ?>
    1308           pa rent.hideE ditForm();
    1309           <?
    1310       }
    1311   }
    1312  
    1313  
    1314  
    1315   class BxDo lPFMAreaJS ONObj {
    1316       
    1317       functi on BxDolPF MAreaJSONO bj( $oArea  ) {
    1318           $t his -> id  = $oArea - > iAreaID;
    1319           
    1320           $t his -> act ive_blocks    = array ();
    1321           $t his -> ina ctive_bloc ks = array ();
    1322           $t his -> act ive_items     = array ();
    1323           $t his -> ina ctive_item s  = array ();
    1324           
    1325           fo reach( $oA rea -> aBl ocks as $i ID => $sNa me )
    1326                $this ->  active_bl ocks[] = n ew BxDolPF MItem( $iI D, $sName  );
    1327           
    1328           fo reach( $oA rea -> aIt ems as $iI D => $aIte m )
    1329                $this ->  active_it ems[] = ne w BxDolPFM Item( $iID , $aItem[0 ], $aItem[ 1] );
    1330           
    1331           fo reach( $oA rea -> aBl ocksInac a s $iID =>  $sName )
    1332                $this ->  inactive_ blocks[] =  new BxDol PFMItem( $ iID, $sNam e );
    1333           
    1334           fo reach( $oA rea -> aIt emsInac as  $iID => $ sName )
    1335                $this ->  inactive_ items[] =  new BxDolP FMItem( $i ID, $sName  );
    1336       }
    1337   }
    1338  
    1339   /* Used fo r JSON gen eration */
    1340   class BxDo lPFMItem {
    1341       
    1342       functi on BxDolPF MItem( $iI D, $sName,  $iBlock =  0 ) {
    1343           $t his -> id  = $iID;
    1344           $t his -> nam e = $sName ;
    1345           
    1346           $t his -> blo ck = $iBlo ck;
    1347       }
    1348   }
    1349  
    1350  
    1351  
    1352   /*
    1353       Cacher  created o nly for cr eating a c ache :)
    1354   */
    1355  
    1356   class BxDo lPFMCacher  {
    1357       
    1358       var $a AreasProps ;
    1359       var $s CacheFile;
    1360       
    1361       functi on BxDolPF MCacher()  {
    1362           
    1363           // additional  propertie s for cach ing blocks
    1364           $a AddBlockPr ops = arra y( 
    1365                'Join' = > array(
    1366                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Join',
    1367                    'Des c'      =>  '_FieldDe sc_{Name}_ Join'
    1368                ),
    1369                'Edit' = > array(
    1370                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Edit',
    1371                    'Des c'      =>  '_FieldDe sc_{Name}_ Edit'
    1372                ),
    1373                'View' = > array(
    1374                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_View',
    1375                    'Des c'      =>  '_FieldDe sc_{Name}_ View'
    1376                ),
    1377                'Search'  => array(
    1378                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Search' ,
    1379                    'Des c'      =>  '_FieldDe sc_{Name}_ Search'
    1380                )
    1381           );
    1382  
    1383           // additional  propertie s for cach ing items
    1384           $a AddProps =  array( 
    1385                'Join' = > array(
    1386                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Join',
    1387                    'Des c'      =>  '_FieldDe sc_{Name}_ Join',
    1388                    'Man datoryMsg'  => '_Fiel dError_{Na me}_Mandat ory',
    1389                    'Min Msg'    =>  '_FieldEr ror_{Name} _Min',
    1390                    'Max Msg'    =>  '_FieldEr ror_{Name} _Max',
    1391                    'Uni queMsg' =>  '_FieldEr ror_{Name} _Unique',
    1392                    'Che ckMsg'  =>  '_FieldEr ror_{Name} _Check'
    1393                ),
    1394                'Edit' = > array(
    1395                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Edit',
    1396                    'Des c'      =>  '_FieldDe sc_{Name}_ Edit',
    1397                    'Man datoryMsg'   => '_Fie ldError_{N ame}_Manda tory',
    1398                    'Min Msg'    =>  '_FieldEr ror_{Name} _Min',
    1399                    'Max Msg'    =>  '_FieldEr ror_{Name} _Max',
    1400                    'Uni queMsg' =>  '_FieldEr ror_{Name} _Unique',
    1401                    'Che ckMsg'  =>  '_FieldEr ror_{Name} _Check'
    1402                ),
    1403                'View' = > array(
    1404                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_View',
    1405                    'Des c'      =>  '_FieldDe sc_{Name}_ View'
    1406                ),
    1407                'Search'  => array(
    1408                    'Cap tion'   =>  '_FieldCa ption_{Nam e}_Search' ,
    1409                    'Des c'      =>  '_FieldDe sc_{Name}_ Search'
    1410                )
    1411           );
    1412           
    1413           $t his -> aAr easProps =  array (
    1414                1  => ar ray( 'Titl e' => 'Joi n',   'Ord er' => 'Jo inOrder',  'Block' =>  'JoinBloc k', 'AddSe lect' => ' Control,Ex tra,Min,Ma x,Values,C heck,Uniqu e,Mandator y,UseLKey' ,                'Add BlockProps ' => $aAdd BlockProps ['Join'],    'AddProp s' => $aAd dProps['Jo in'] ),
    1415                
    1416                2  => ar ray( 'Titl e' => 'Edi t (Owner)' ,   'Order ' => 'Edit OwnOrder',  'Block' = > 'EditOwn Block', 'A ddSelect'  => 'Contro l,Extra,Mi n,Max,Valu es,Check,U nique,Mand atory,UseL Key', 'Add BlockProps ' => $aAdd BlockProps ['Edit'],    'AddProp s' => $aAd dProps['Ed it'] ),
    1417                3  => ar ray( 'Titl e' => 'Edi t (Admin)' ,   'Order ' => 'Edit AdmOrder',  'Block' = > 'EditAdm Block', 'A ddSelect'  => 'Contro l,Extra,Mi n,Max,Valu es,Check,U nique,Mand atory,UseL Key', 'Add BlockProps ' => $aAdd BlockProps ['Edit'],    'AddProp s' => $aAd dProps['Ed it'] ),
    1418                4  => ar ray( 'Titl e' => 'Edi t (Moder)' ,   'Order ' => 'Edit ModOrder',  'Block' = > 'EditMod Block', 'A ddSelect'  => 'Contro l,Extra,Mi n,Max,Valu es,Check,U nique,Mand atory,UseL Key', 'Add BlockProps ' => $aAdd BlockProps ['Edit'],    'AddProp s' => $aAd dProps['Ed it'] ),
    1419                
    1420                5  => ar ray( 'Titl e' => 'Vie w (Admin)' ,     'Ord er' => 'Vi ewAdmOrder ',  'Block ' => 'View AdmBlock',   'AddSele ct' => 'Va lues,UseLK ey',                           ' AddBlockPr ops' => $a AddBlockPr ops['View' ],   'AddP rops' => $ aAddProps[ 'View'] ),
    1421                6  => ar ray( 'Titl e' => 'Vie w (Member) ',    'Ord er' => 'Vi ewMembOrde r', 'Block ' => 'View MembBlock' , 'AddSele ct' => 'Va lues,UseLK ey',                           ' AddBlockPr ops' => $a AddBlockPr ops['View' ],   'AddP rops' => $ aAddProps[ 'View'] ),
    1422                7  => ar ray( 'Titl e' => 'Vie w (Moder)' ,     'Ord er' => 'Vi ewModOrder ',  'Block ' => 'View ModBlock',   'AddSele ct' => 'Va lues,UseLK ey',                           ' AddBlockPr ops' => $a AddBlockPr ops['View' ],   'AddP rops' => $ aAddProps[ 'View'] ),
    1423                8  => ar ray( 'Titl e' => 'Vie w (Visitor )',   'Ord er' => 'Vi ewVisOrder ',  'Block ' => 'View VisBlock',   'AddSele ct' => 'Va lues,UseLK ey',                           ' AddBlockPr ops' => $a AddBlockPr ops['View' ],   'AddP rops' => $ aAddProps[ 'View'] ),
    1424                
    1425                9  => ar ray( 'Titl e' => 'Sea rch (Simpl e)', 'Orde r' => 'Sea rchSimpleO rder', 'Bl ock' => 'S earchSimpl eBlock', ' AddSelect'  => 'Extra ,Control,U seLKey',               'AddBlock Props' =>  $aAddBlock Props['Sea rch'], 'Ad dProps' =>  $aAddProp s['Search' ] ),
    1426                10 => ar ray( 'Titl e' => 'Sea rch (Quick )',  'Orde r' => 'Sea rchQuickOr der',  'Bl ock' => 'S earchQuick Block',  ' AddSelect'  => 'Extra ,Control,U seLKey',               'AddBlock Props' =>  $aAddBlock Props['Sea rch'], 'Ad dProps' =>  $aAddProp s['Search' ] ),
    1427                11 => ar ray( 'Titl e' => 'Sea rch (Adv)' ,    'Orde r' => 'Sea rchAdvOrde r',    'Bl ock' => 'S earchAdvBl ock',    ' AddSelect'  => 'Extra ,Control,U seLKey',               'AddBlock Props' =>  $aAddBlock Props['Sea rch'], 'Ad dProps' =>  $aAddProp s['Search' ] ),
    1428                
    1429                //specia l areas
    1430                100 => a rray( 'Tit le' => 'Al l Fields.  PC cache',  'AddSelec t' => 'Def ault,Uniqu e,Extra' ) ,
    1431                101 => a rray( 'Tit le' => 'Ma tching Fie lds',        'AddSele ct' => 'Ma tchField,M atchPercen t' ),
    1432           );
    1433           
    1434           $t his -> sCa cheFile =  BX_DIRECTO RY_PATH_IN C . 'db_ca ched/Profi leFields.i nc';
    1435           
    1436       }
    1437       
    1438       functi on createC ache() {
    1439           $r CacheFile  = @fopen(  $this -> s CacheFile,  'w' );
    1440           if ( !$rCache File ) {
    1441                echo '<b r /><b>War ning!</b>  Cannot ope n Profile  Fields cac he file ('  . $this - > sCacheFi le . ') fo r write.';
    1442                return f alse;
    1443           }
    1444           
    1445           $s CacheStrin g = "// ca che of Pro file Field s\n\nretur n array(\n   //areas\ n";
    1446           
    1447           //  get areas
    1448           fo reach ($th is -> aAre asProps as  $iAreaID  => $aArea)  {
    1449                $oArea =  new BxDol ProfileFie ldsArea( $ iAreaID, $ this );
    1450                
    1451                $sCacheS tring .= $ oArea -> g etCacheStr ing();
    1452           }
    1453           
    1454           $s CacheStrin g .= ");\n ";
    1455           
    1456           
    1457           $i Res = fwri te( $rCach eFile, $sC acheString  );
    1458           
    1459           fc lose( $rCa cheFile );
    1460           
    1461           if ( $iRes == = false )  {
    1462                echo '<b r /><b>War ning!</b>  Cannot wri te to Prof ile Fields  cache fil e (' . $th is -> sCac heFile . ' ).';
    1463                return f alse;
    1464           }
    1465           
    1466           re turn true;
    1467       }
    1468       
    1469   }
    1470  
    1471   /*
    1472       Profil eFieldsAre a
    1473       Used p rimarily t o create c ache strin gs
    1474   */
    1475  
    1476   class BxDo lProfileFi eldsArea {
    1477       
    1478       var $i d;
    1479       var $o Parent;
    1480       var $s Title;
    1481       var $s BlockCol;
    1482       var $s OrderCol;
    1483       var $a Blocks;
    1484       var $a Pages;
    1485       
    1486       functi on BxDolPr ofileField sArea( $iA reaID, &$o Parent ) {
    1487           $t his -> id  = $iAreaID ;
    1488           $t his -> oPa rent = &$o Parent;
    1489           
    1490           $t his -> sTi tle          = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['Title'];
    1491           $t his -> sBl ockCol       = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['Block'];
    1492           $t his -> sOr derCol       = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['Order'];
    1493           $t his -> sAd dSelect      = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['AddSelec t'];
    1494           $t his -> aAd dBlockProp s = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['AddBlock Props'];
    1495           $t his -> aAd dProps       = $this  -> oParent  -> aAreas Props[ $th is -> id ] ['AddProps '];
    1496       }
    1497       
    1498       functi on getCach eString()  {
    1499           
    1500           $s CacheStrin g = "\n  / /{$this ->  sTitle}\n   {$this - > id} => a rray(\n";  //!pasd
    1501           
    1502           if ( $this ->  id == 1 )  {
    1503                $this ->  aPages =  $this -> g etJoinPage s();
    1504                
    1505                $sCacheS tring .= "     //page s\n";
    1506                foreach(  $this ->  aPages as  $iPage ){
    1507                    $thi s -> aBloc ks = $this  -> getBlo cks( "`Joi nPage` = $ iPage" );
    1508                    
    1509                    $sCa cheString  .= "    $i Page => ar ray(\n"; / /!pasd
    1510                         $sCacheStr ing .= $th is -> getB locksCache String( '   ' );
    1511                    $sCa cheString  .= "    ), \n";
    1512                }
    1513           }  else {
    1514                if( $thi s -> id ==  100 or $t his -> id  == 101 )
    1515                    $thi s -> aBloc ks = array ( 0 => ''  );
    1516                else
    1517                    $thi s -> aBloc ks = $this  -> getBlo cks();
    1518                
    1519                $sCacheS tring .= $ this -> ge tBlocksCac heString() ;
    1520           }
    1521           
    1522           $s CacheStrin g .= "  ), \n";
    1523           
    1524           re turn $sCac heString;
    1525       }
    1526       
    1527       functi on getBloc ksCacheStr ing( $sPre fix = '' )  {
    1528           $s CacheStrin g = "$sPre fix    //b locks\n";
    1529           
    1530           fo reach ($th is -> aBlo cks as $iB lockID =>  $sBlockNam e) {
    1531                $sBlockN ame = $thi s -> addSl ashes( $sB lockName ) ;
    1532                $sCacheS tring .= " $sPrefix     $iBlockI D => array (\n"; //!p asd
    1533                $sCacheS tring .= " $sPrefix       //bloc k properti es\n";
    1534                
    1535                // add a dditional  properties
    1536                if( is_a rray($this  -> aAddBl ockProps)  )
    1537                    fore ach ($this  -> aAddBl ockProps a s $sProp = > $sValue)  {
    1538                         $sPropValu e = str_re place( '{N ame}', $sB lockName,  $sValue );
    1539                         $sCacheStr ing .= "$s Prefix       '$sProp'  => '$sPro pValue',\n ";
    1540                    }
    1541                
    1542                //proces s items
    1543                $aItems  = $this ->  getItemsO fBlock($iB lockID);
    1544                
    1545                $sCacheS tring .= " $sPrefix       'Items ' => array (\n";
    1546                foreach  ($aItems a s $iBlockI D => $aIte m) {
    1547                    $sCa cheString  .= "$sPref ix         $iBlockID  => array(\ n"; //!pas d
    1548                    $sCa cheString  .= "$sPref ix           //item p roperties\ n";
    1549                    
    1550                    // a dd additio nal proper ties
    1551                    if(  is_array($ this -> aA ddProps) )
    1552                         foreach ($ this -> aA ddProps as  $sProp =>  $sValue)  {
    1553                             $aItem [ $sProp ]  = str_rep lace( '{Na me}', $aIt em['Name'] , $sValue  );
    1554                         }
    1555                    
    1556                    fore ach ($aIte m as $sPro p => $sVal ue) {
    1557                         if( $sProp  == 'ID' )
    1558                             contin ue; //do n ot process  ID it is  already in  key
    1559                        
    1560                         $sCacheStr ing .= "$s Prefix           '$sP rop' => "  . $this ->  processTh isFuckingV alue( $sPr op, $sValu e, "$sPref ix           " ) . ", \n";
    1561                    }
    1562                    
    1563                    $sCa cheString  .= "$sPref ix         ),\n";
    1564                }
    1565                
    1566                $sCacheS tring .= " $sPrefix       ),\n";  //close i tems
    1567                $sCacheS tring .= " $sPrefix     ),\n"; / /close blo ck
    1568           }
    1569           
    1570           re turn $sCac heString;
    1571       }
    1572       
    1573       functi on process ThisFuckin gValue( $s Prop, $sVa lue, $sPre fix = '' )  {
    1574           if ( is_null(  $sValue )  )
    1575                return ' null'; //j ust a null
    1576           
    1577           sw itch( $sPr op ) {
    1578                case 'Na me':
    1579                case 'Ty pe':
    1580                case 'Ca ption':
    1581                case 'De sc':
    1582                case 'Ma ndatoryMsg ':
    1583                case 'Mi nMsg':
    1584                case 'Ma xMsg':
    1585                case 'Un iqueMsg':
    1586                case 'Ch eckMsg':
    1587                    retu rn "'$sVal ue'"; // s tring in s ingle quot es, simple  text (wit hout quote s)
    1588                case 'Mi n':
    1589                case 'Ma x':
    1590                case 'Ma tchPercent ':
    1591                case 'Ma tchField':
    1592                    retu rn "$sValu e"; //inte ger
    1593                case 'Ma ndatory':
    1594                case 'Un ique':
    1595                    retu rn ( $sVal ue == '1'  ? 'true' :  'false' ) ; //boolea n
    1596                case 'Va lues':
    1597                    if(  $sValue ==  '' )
    1598                         return "'' ";
    1599                    else if( substr ( $sValue,  0, 2) ==  '#!' )
    1600                         return '"'  . $this - > addSlash esDblQuot(  $sValue )  . '"'; // string in  double quo tes
    1601                    else  {
    1602                         // WOOW! L ets make i t array! > :-E
    1603                         $aValues =  explode(  "\n", $sVa lue );
    1604                        
    1605                         $sRet = "a rray(\n";
    1606                        
    1607                         foreach( $ aValues as  $iKey =>  $sValue1 )  {
    1608                             $sValu e1 = $this  -> addSla shes( $sVa lue1 );
    1609                             $sRet  .= "$sPref ix  v$iKey  => '$sVal ue1',\n";
    1610                         }
    1611                        
    1612                         $sRet .= " $sPrefix)" ;
    1613                        
    1614                         return $sR et;
    1615                    }
    1616                default:
    1617                    retu rn '"' . $ this -> ad dSlashesDb lQuot( $sV alue ) . ' "'; //stri ng in doub le quotes
    1618           }
    1619       }
    1620       
    1621       functi on addSlas hes( $sTex t ) {
    1622           $s Text = str _replace(  "\\", "\\\ \", $sText  );
    1623           $s Text = str _replace(  "'", "\\'" , $sText ) ;
    1624           
    1625           re turn $sTex t;
    1626       }
    1627       
    1628       functi on addSlas hesDblQuot ( $sText ) {
    1629           $s Text = str _replace(  '\\',  '\\ \\', $sTex t );
    1630           $s Text = str _replace(  '"',   '\" ',   $sTex t );
    1631           $s Text = str _replace(  '$',   '\$ ',   $sTex t );
    1632           $s Text = str _replace(  "\r",  '\r ',   $sTex t );
    1633           $s Text = str _replace(  "\n",  '\n ',   $sTex t );
    1634           $s Text = str _replace(  "\t",  '\t ',   $sTex t );
    1635           $s Text = str _replace(  "\x0", '\x 0',  $sTex t );
    1636           
    1637           re turn $sTex t;
    1638       }
    1639  
    1640       
    1641       functi on getJoin Pages() {
    1642           $a Pages = ar ray();
    1643           
    1644           $s Query = "
    1645                SELECT
    1646                    DIST INCT `Join Page`
    1647                FROM `Pr ofileField s`
    1648                WHERE
    1649                    `Typ e` = 'bloc k' AND
    1650                    `Joi nOrder` IS  NOT NULL
    1651           ";
    1652           
    1653           $r Pages = db _res( $sQu ery );
    1654           
    1655           wh ile( $aPag e = mysql_ fetch_asso c( $rPages  ) ) {
    1656                $aPages[ ] = (int)$ aPage['Joi nPage'];
    1657           }
    1658           
    1659           re turn $aPag es;
    1660       }
    1661       
    1662       //`Joi nPage` = $ iPage
    1663       functi on getBloc ks( $sAddS ort = '1'  ) {
    1664           $a Blocks = a rray();
    1665           
    1666           $s Query = "
    1667                SELECT
    1668                    `ID` ,
    1669                    `Nam e`
    1670                FROM `Pr ofileField s`
    1671                WHERE
    1672                    `Typ e` = 'bloc k' AND
    1673                    `{$t his -> sOr derCol}` I S NOT NULL  AND
    1674                    $sAd dSort
    1675                ORDER BY
    1676                    `{$t his -> sOr derCol}`
    1677           ";
    1678           
    1679           $r Blocks = d b_res( $sQ uery );
    1680           
    1681           wh ile( $aBlo ck = mysql _fetch_ass oc( $rBloc ks ) ) {
    1682                $aBlocks [ $aBlock[ 'ID'] ] =  $aBlock['N ame'];
    1683           }
    1684           
    1685           re turn $aBlo cks;
    1686       }
    1687       
    1688       functi on getItem sOfBlock(  $iBlockID  ) {
    1689           $a Items = ar ray();
    1690           
    1691           $s AddSelect  = '`' . st r_replace(  ',', '`,  `', $this  -> sAddSel ect ) . '` ';
    1692           
    1693           if ( $this ->  id == 100  )
    1694                $sWhere  = '1';
    1695           el seif( $thi s -> id ==  101 )
    1696                $sWhere  = "`MatchF ield` != ' '";
    1697           el se
    1698                $sWhere  = "`{$this  -> sBlock Col}` = $i BlockID AN D `{$this  -> sOrderC ol}` IS NO T NULL";
    1699           
    1700           $s OrderCol =  isset( $t his -> sOr derCol ) ?  $this ->  sOrderCol  : 'ID';
    1701           
    1702           $s Query = "
    1703                SELECT
    1704                    `ID` ,
    1705                    `Nam e`,
    1706                    `Typ e`,
    1707                    $sAd dSelect
    1708                FROM
    1709                    `Pro fileFields `
    1710                WHERE
    1711                    `Typ e` != 'blo ck' AND
    1712                    $sWh ere
    1713                ORDER BY
    1714                    `$sO rderCol`
    1715           ";
    1716           
    1717           $r Items = db _res( $sQu ery );
    1718           
    1719           wh ile( $aIte m = mysql_ fetch_asso c($rItems)  ) {
    1720                $aItems[  $aItem['I D'] ] = $a Item;
    1721           }
    1722           
    1723           re turn $aIte ms;
    1724       }
    1725   }