Ignore:
Timestamp:
Nov 23, 2004, 11:31:24 PM (19 years ago)
Author:
plg
Message:
  • global categories' options : instead of N horizontal tabs on a single page, N options in the left menu (but the same backend)
  • categories.global_rank : new calculated field. It gives a global rank of the category among all others (updated during ordering)
  • category.php page : menu is generated faster thanks to categories.global_rank, recursivity becomes useless :-)
  • new function to display select box with a set of categories : display_select_cat_wrapper
  • cat_options : instead of using 1 multiselect for true/false items, using 1 multiselect for true, and another one for false. The form provides buttons with arrows to switch categories from one multiselect to another
  • deletion of obsolete function display_categories (working with the old template system)
  • deletion of obsolete functions get_user_plain_structure, create_user_structure, get_user_subcat_ids, update_structure, count_images : useless thanks to global_rank
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_options.php

    r604 r614  
    3737// print_r($_POST);
    3838// print '</pre>';
    39 if (isset($_POST['submit']) and count($_POST['cat']) > 0)
     39if (isset($_POST['falsify']) and count($_POST['cat_true']) > 0)
    4040{
    4141  switch ($_GET['section'])
     
    4545      $query = '
    4646UPDATE '.CATEGORIES_TABLE.'
    47   SET uploadable = \''.$_POST['option'].'\'
    48   WHERE id IN ('.implode(',', $_POST['cat']).')
     47  SET uploadable = \'false\'
     48  WHERE id IN ('.implode(',', $_POST['cat_true']).')
    4949;';
    5050      pwg_query($query);
     
    5555      $query = '
    5656UPDATE '.CATEGORIES_TABLE.'
    57   SET commentable = \''.$_POST['option'].'\'
    58   WHERE id IN ('.implode(',', $_POST['cat']).')
     57  SET commentable = \'false\'
     58  WHERE id IN ('.implode(',', $_POST['cat_true']).')
    5959;';
    6060      pwg_query($query);
     
    6464    {
    6565      // locking a category   => all its child categories become locked
    66       if ($_POST['option'] == 'false')
    67       {
    68         $subcats = get_subcat_ids($_POST['cat']);
    69         $query = '
     66      $subcats = get_subcat_ids($_POST['cat_true']);
     67      $query = '
    7068UPDATE '.CATEGORIES_TABLE.'
    7169  SET visible = \'false\'
    7270  WHERE id IN ('.implode(',', $subcats).')
    7371;';
    74         pwg_query($query);
     72      pwg_query($query);
     73      break;
     74    }
     75    case 'status' :
     76    {
     77      // make a category private => all its child categories become private
     78      $subcats = get_subcat_ids($_POST['cat_true']);
     79      $query = '
     80UPDATE '.CATEGORIES_TABLE.'
     81  SET status = \'private\'
     82  WHERE id IN ('.implode(',', $subcats).')
     83;';
     84      pwg_query($query);
     85      break;
     86    }
     87  }
     88}
     89else if (isset($_POST['trueify']) and count($_POST['cat_false']) > 0)
     90{
     91  switch ($_GET['section'])
     92  {
     93    case 'upload' :
     94    {
     95      $query = '
     96UPDATE '.CATEGORIES_TABLE.'
     97  SET uploadable = \'true\'
     98  WHERE id IN ('.implode(',', $_POST['cat_false']).')
     99;';
     100      pwg_query($query);
     101      break;
     102    }
     103    case 'comments' :
     104    {
     105      $query = '
     106UPDATE '.CATEGORIES_TABLE.'
     107  SET commentable = \'true\'
     108  WHERE id IN ('.implode(',', $_POST['cat_false']).')
     109;';
     110      pwg_query($query);
     111      break;
     112    }
     113    case 'visible' :
     114    {
     115      // unlocking a category => all its parent categories become unlocked
     116      $uppercats = array();
     117      $query = '
     118SELECT uppercats
     119  FROM '.CATEGORIES_TABLE.'
     120  WHERE id IN ('.implode(',', $_POST['cat_false']).')
     121;';
     122      $result = pwg_query($query);
     123      while ($row = mysql_fetch_array($result))
     124      {
     125        $uppercats = array_merge($uppercats,
     126                                 explode(',', $row['uppercats']));
    75127      }
    76       // unlocking a category => all its parent categories become unlocked
    77       if ($_POST['option'] == 'true')
    78       {
    79         $uppercats = array();
    80         $query = '
    81 SELECT uppercats
    82   FROM '.CATEGORIES_TABLE.'
    83   WHERE id IN ('.implode(',', $_POST['cat']).')
    84 ;';
    85         $result = pwg_query($query);
    86         while ($row = mysql_fetch_array($result))
    87         {
    88           $uppercats = array_merge($uppercats,
    89                                    explode(',', $row['uppercats']));
    90         }
    91         $uppercats = array_unique($uppercats);
    92 
    93         $query = '
     128      $uppercats = array_unique($uppercats);
     129     
     130      $query = '
    94131UPDATE '.CATEGORIES_TABLE.'
    95132  SET visible = \'true\'
    96133  WHERE id IN ('.implode(',', $uppercats).')
    97134;';
    98         pwg_query($query);
     135      pwg_query($query);
     136      break;
     137    }
     138    case 'status' :
     139    {
     140      // make public a category => all its parent categories become public
     141      $uppercats = array();
     142      $query = '
     143SELECT uppercats
     144  FROM '.CATEGORIES_TABLE.'
     145  WHERE id IN ('.implode(',', $_POST['cat_false']).')
     146;';
     147      $result = pwg_query($query);
     148      while ($row = mysql_fetch_array($result))
     149      {
     150        $uppercats = array_merge($uppercats,
     151                                 explode(',', $row['uppercats']));
    99152      }
    100       break;
    101     }
    102     case 'status' :
    103     {
    104       // make a category private => all its child categories become private
    105       if ($_POST['option'] == 'false')
    106       {
    107         $subcats = get_subcat_ids($_POST['cat']);
    108         $query = '
    109 UPDATE '.CATEGORIES_TABLE.'
    110   SET status = \'private\'
    111   WHERE id IN ('.implode(',', $subcats).')
    112 ;';
    113         pwg_query($query);
    114       }
    115       // make public a category => all its parent categories become public
    116       if ($_POST['option'] == 'true')
    117       {
    118         $uppercats = array();
    119         $query = '
    120 SELECT uppercats
    121   FROM '.CATEGORIES_TABLE.'
    122   WHERE id IN ('.implode(',', $_POST['cat']).')
    123 ;';
    124         $result = pwg_query($query);
    125         while ($row = mysql_fetch_array($result))
    126         {
    127           $uppercats = array_merge($uppercats,
    128                                    explode(',', $row['uppercats']));
    129         }
    130         $uppercats = array_unique($uppercats);
    131 
    132         $query = '
     153      $uppercats = array_unique($uppercats);
     154     
     155      $query = '
    133156UPDATE '.CATEGORIES_TABLE.'
    134157  SET status = \'public\'
    135158  WHERE id IN ('.implode(',', $uppercats).')
    136159;';
    137         pwg_query($query);
    138       }
     160      pwg_query($query);
    139161      break;
    140162    }
     
    160182    'L_SUBMIT'=>$lang['submit'],
    161183    'L_RESET'=>$lang['reset'],
    162     'L_CAT_OPTIONS_MENU_UPLOAD'=>$lang['cat_options_menu_upload'],
    163     'L_CAT_OPTIONS_MENU_VISIBLE'=>$lang['cat_options_menu_visible'],
    164     'L_CAT_OPTIONS_MENU_COMMENTS'=>$lang['cat_options_menu_comments'],
    165     'L_CAT_OPTIONS_MENU_STATUS'=>$lang['cat_options_menu_status'],
    166     'L_CAT_OPTIONS_UPLOAD_INFO'=>$lang['cat_options_upload_info'],
    167     'L_CAT_OPTIONS_UPLOAD_TRUE'=>$lang['cat_options_upload_true'],
    168     'L_CAT_OPTIONS_UPLOAD_FALSE'=>$lang['cat_options_upload_false'],
    169     'L_CAT_OPTIONS_COMMENTS_INFO'=>$lang['cat_options_comments_info'],
    170     'L_CAT_OPTIONS_COMMENTS_TRUE'=>$lang['cat_options_comments_true'],
    171     'L_CAT_OPTIONS_COMMENTS_FALSE'=>$lang['cat_options_comments_false'],
    172     'L_CAT_OPTIONS_VISIBLE_INFO'=>$lang['cat_options_visible_info'],
    173     'L_CAT_OPTIONS_VISIBLE_TRUE'=>$lang['cat_options_visible_true'],
    174     'L_CAT_OPTIONS_VISIBLE_FALSE'=>$lang['cat_options_visible_false'],
    175     'L_CAT_OPTIONS_STATUS_INFO'=>$lang['cat_options_status_info'],
    176     'L_CAT_OPTIONS_STATUS_TRUE'=>$lang['cat_options_status_true'],
    177     'L_CAT_OPTIONS_STATUS_FALSE'=>$lang['cat_options_status_false'],
    178184   
    179185    'U_UPLOAD'=>add_session_id($base_url.'upload'),
     
    206212  case 'upload' :
    207213  {
    208     $query = '
    209 SELECT id
     214    $query_true = '
     215SELECT id,name,uppercats,global_rank
    210216  FROM '.CATEGORIES_TABLE.'
    211217  WHERE uploadable = \'true\'
     
    213219    AND site_id = 1
    214220;';
    215     $result = pwg_query($query);
    216     while ($row = mysql_fetch_array($result))
    217     {
    218       array_push($cats_true, $row['id']);
    219     }
    220     $query = '
    221 SELECT id
     221    $query_false = '
     222SELECT id,name,uppercats,global_rank
    222223  FROM '.CATEGORIES_TABLE.'
    223224  WHERE uploadable = \'false\'
     
    225226    AND site_id = 1
    226227;';
    227     $result = pwg_query($query);
    228     while ($row = mysql_fetch_array($result))
    229     {
    230       array_push($cats_false, $row['id']);
    231     }
    232    
     228    $template->assign_vars(
     229      array(
     230        'L_TITLE' => $lang['cat_options_upload_title'],
     231        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_upload_true'],
     232        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_upload_false'],
     233        'L_CAT_OPTIONS_INFO' => $lang['cat_options_upload_info'],
     234        )
     235      );
    233236    $template->assign_block_vars('upload', array());
    234 
    235237    break;
    236238  }
    237239  case 'comments' :
    238240  {
    239     $query = '
    240 SELECT id
     241    $query_true = '
     242SELECT id,name,uppercats,global_rank
    241243  FROM '.CATEGORIES_TABLE.'
    242244  WHERE commentable = \'true\'
    243245;';
    244     $result = pwg_query($query);
    245     while ($row = mysql_fetch_array($result))
    246     {
    247       array_push($cats_true, $row['id']);
    248     }
    249     $query = '
    250 SELECT id
     246    $query_false = '
     247SELECT id,name,uppercats,global_rank
    251248  FROM '.CATEGORIES_TABLE.'
    252249  WHERE commentable = \'false\'
    253250;';
    254     $result = pwg_query($query);
    255     while ($row = mysql_fetch_array($result))
    256     {
    257       array_push($cats_false, $row['id']);
    258     }
    259    
     251    $template->assign_vars(
     252      array(
     253        'L_TITLE' => $lang['cat_options_comments_title'],
     254        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_comments_true'],
     255        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_comments_false'],
     256        'L_CAT_OPTIONS_INFO' => $lang['cat_options_comments_info'],
     257        )
     258      );
    260259    $template->assign_block_vars('comments', array());
    261    
    262260    break;
    263261  }
    264262  case 'visible' :
    265263  {
    266     $query = '
    267 SELECT id
     264    $query_true = '
     265SELECT id,name,uppercats,global_rank
    268266  FROM '.CATEGORIES_TABLE.'
    269267  WHERE visible = \'true\'
    270268;';
    271     $result = pwg_query($query);
    272     while ($row = mysql_fetch_array($result))
    273     {
    274       array_push($cats_true, $row['id']);
    275     }
    276     $query = '
    277 SELECT id
     269    $query_false = '
     270SELECT id,name,uppercats,global_rank
    278271  FROM '.CATEGORIES_TABLE.'
    279272  WHERE visible = \'false\'
    280273;';
    281     $result = pwg_query($query);
    282     while ($row = mysql_fetch_array($result))
    283     {
    284       array_push($cats_false, $row['id']);
    285     }
    286    
     274    $template->assign_vars(
     275      array(
     276        'L_TITLE' => $lang['cat_options_visible_title'],
     277        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_visible_true'],
     278        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_visible_false'],
     279        'L_CAT_OPTIONS_INFO' => $lang['cat_options_visible_info'],
     280        )
     281      );
    287282    $template->assign_block_vars('visible', array());
    288    
    289283    break;
    290284  }
    291285  case 'status' :
    292286  {
    293     $query = '
    294 SELECT id
     287    $query_true = '
     288SELECT id,name,uppercats,global_rank
    295289  FROM '.CATEGORIES_TABLE.'
    296290  WHERE status = \'public\'
    297291;';
    298     $result = pwg_query($query);
    299     while ($row = mysql_fetch_array($result))
    300     {
    301       array_push($cats_true, $row['id']);
    302     }
    303     $query = '
    304 SELECT id
     292    $query_false = '
     293SELECT id,name,uppercats,global_rank
    305294  FROM '.CATEGORIES_TABLE.'
    306295  WHERE status = \'private\'
    307296;';
    308     $result = pwg_query($query);
    309     while ($row = mysql_fetch_array($result))
    310     {
    311       array_push($cats_false, $row['id']);
    312     }
    313    
     297    $template->assign_vars(
     298      array(
     299        'L_TITLE' => $lang['cat_options_status_title'],
     300        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_status_true'],
     301        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_status_false'],
     302        'L_CAT_OPTIONS_INFO' => $lang['cat_options_status_info'],
     303        )
     304      );
    314305    $template->assign_block_vars('status', array());
    315    
    316306    break;
    317307  }
    318308}
    319 $CSS_classes = array('optionTrue'=>$cats_true,
    320                      'optionFalse'=>$cats_false);
    321  
    322 $user['expand'] = true;
    323 $structure = create_user_structure('');
    324 display_select_categories($structure,
    325                           '&nbsp;',
    326                           array(),
    327                           'category_option',
    328                           $CSS_classes);
     309display_select_cat_wrapper($query_true,array(),'category_option_true');
     310display_select_cat_wrapper($query_false,array(),'category_option_false');
    329311// +-----------------------------------------------------------------------+
    330312// |                           sending html code                           |
Note: See TracChangeset for help on using the changeset viewer.