Ignore:
Timestamp:
Mar 7, 2011, 4:09:40 PM (13 years ago)
Author:
flop25
Message:

bug:1901
lots of bugs will be solved now, because the plugin were not able to manage users with multiple groups (the groups with an id inferior than the groups of Adultcontent caused bugs).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/adult_content/class.inc.php

    r9530 r9564  
    55{
    66  var $plugin_name, $plugin_path;
    7  
     7  var $idgroups_user = array();
     8  var $idgroups_ad_c = array();// 0=+18 1=16 2=nothing
    89  function Adultcontent($plugin_name, $plugin_path)
    910  {
     
    1112    $this->plugin_name = $plugin_name;
    1213    $this->plugin_path = $plugin_path;
    13     // handler
    14    // $this->initialize_event_handler();
    15   }
    16  
    17   function get_link_icon($main_link, $action)
     14  }
     15  function fill_idgroups_user()
     16  {
     17    global $user;
     18
     19    $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';';
     20    $result = pwg_query($query);
     21    while ($row = mysql_fetch_assoc($result))
     22    {
     23      array_push($this->idgroups_user, $row['group_id']);
     24    }
     25  }
     26  function fill_idgroups_ad_c()
     27  {
     28    global $user;
     29
     30    $query = 'SELECT id FROM ' . GROUPS_TABLE . ' WHERE name IN (\'+18\', \'16-17\', \'nothing\') ORDER BY id';
     31    $result = pwg_query($query);
     32    while ($row = mysql_fetch_assoc($result))
     33    {
     34      array_push($this->idgroups_ad_c, $row['id']);
     35    }
     36  }
     37  function is_in_ad_c_group()
     38  {
     39                foreach( $this->idgroups_ad_c as $id )
     40                {
     41                        if ( in_array($id, $this->idgroups_user))
     42                        {
     43                                return $id;
     44                                exit;
     45                        }
     46                }
     47                return false;
     48        }
     49        function get_link_icon($main_link, $action)
    1850  {
    1951    $link_url = add_url_params($main_link, array('ad' => $action));
     
    2456  {
    2557    global $lang;
    26         load_language('plugin.lang', $this->plugin_path);
     58                load_language('plugin.lang', $this->plugin_path);
    2759  } 
    2860  function var_template()
     
    5587  {
    5688    global $user, $template;
    57         $r_theme_file=array();
    58         $dir = $this->plugin_path.'template/';
    59         $r_theme_file=($template->smarty->template_dir);
     89                $r_theme_file=array();
     90                $dir = $this->plugin_path.'template/';
     91                $r_theme_file=($template->smarty->template_dir);
    6092                foreach( $r_theme_file as $style)
    6193                {
     
    214246    elseif (!is_admin())
    215247    {
    216        
    217248////////////lié à quoi/////     
    218          $query = '
    219 SELECT id FROM '.GROUPS_TABLE.'
    220   WHERE name IN (\'+18\')
    221 ;';
    222      $data_18 = mysql_fetch_array(pwg_query($query));
    223          $query = '
    224 SELECT id FROM '.GROUPS_TABLE.'
    225   WHERE name IN (\'16-17\')
    226 ;';
    227      $data_16 = mysql_fetch_array(pwg_query($query));
    228          $query = '
    229 SELECT id FROM '.GROUPS_TABLE.'
    230   WHERE name IN (\'nothing\')
    231 ;';
    232      $data_no = mysql_fetch_array(pwg_query($query));
    233          $n_query = '
    234 SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.'
    235   WHERE group_id IN (\''.$data_18['id'].'\',\''.$data_16['id'].'\',\''.$data_no['id'].'\') AND user_id IN (\''.$user['id'].'\')
    236 ;';
    237       $data_user = mysql_fetch_array(pwg_query($n_query));
    238           $is_grouped = $data_user['result'];   
    239 
    240           if ( $is_grouped == 0 )
    241           {
    242                 $template->assign(
    243                   array(
    244                         'AC_ETAT' => 'not_defined',
    245                         'AC_MSG' => l10n('ac_charte_user_not')
    246                         ));
    247                 $menu = & $menu_ref_arr[0];
    248     if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
    249                         $block->set_title(l10n('ac_title_choose'));
    250                         $block->template = $this->get_template('choose.tpl');
    251         }
    252 
    253           }
    254           else
    255           {       
    256                         $query = '
    257           SELECT group_id FROM '.USER_GROUP_TABLE.'
    258                 WHERE user_id IN (\''.$user['id'].'\')
    259           ;';
    260                    $data_group = mysql_fetch_array(pwg_query($query));
    261                    $query = '
    262           SELECT name FROM '.GROUPS_TABLE.'
    263                 WHERE id IN (\''.$data_group['group_id'].'\')
    264           ;';
    265                    $data_group_n = mysql_fetch_array(pwg_query($query));
    266                    if ($data_group_n['name'] == '+18')
    267                    {
    268                    $statut = l10n('ac_user_text_18');
    269                    }
    270                    if ($data_group_n['name'] == '16-17')
    271                    {
    272                    $statut = l10n('ac_user_text_16');
    273                    }
    274                    if ($data_group_n['name'] == 'nothing')
    275                    {
    276                    $statut = l10n('ac_user_no_s');
    277                    }
    278                 $template->assign(
    279                   array(
    280                         'AC_ETAT' => 'defined',
    281                         'AC_MSG' => $statut.". ".l10n('ac_charte_user_def')
    282                         ));
    283                 $menu = & $menu_ref_arr[0];
    284     if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
    285                         $block->set_title(l10n('ac_title_menu_statut'));
    286                         $block->template = $this->get_template('choose.tpl');
    287                 }
     249                        $this->fill_idgroups_user();
     250                        $this->fill_idgroups_ad_c();   
     251
     252                        if ( !$this->is_in_ad_c_group() )
     253                        {
     254                                $template->assign(
     255                                        array(
     256                                        'AC_MSG' => l10n('ac_charte_user_not')
     257                                        ));
     258                                $menu = & $menu_ref_arr[0];
     259                                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
     260                                        $block->set_title(l10n('ac_title_choose'));
     261                                        $block->template = $this->get_template('choose.tpl');
     262                                }
     263                        }
     264                        else
     265                        {         
     266                                $link=$this->is_in_ad_c_group();
     267                                if ($link == $this->idgroups_ad_c[0])
     268                                {
     269                                        $statut = l10n('ac_user_text_18');
     270                                }
     271                                if ($link ==  $this->idgroups_ad_c[1])
     272                                {
     273                                        $statut = l10n('ac_user_text_16');
     274                                }
     275                                if ($link ==  $this->idgroups_ad_c[2])
     276                                {
     277                                        $statut = l10n('ac_user_no_s');
     278                                }
     279                                $template->assign(
     280                                array(
     281                                'AC_MSG' => $statut.". ".l10n('ac_charte_user_def')
     282                                ));
     283                                $menu = & $menu_ref_arr[0];
     284                                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
     285                                        $block->set_title(l10n('ac_title_menu_statut'));
     286                                        $block->template = $this->get_template('choose.tpl');
     287                                }
    288288
    289289          }
     
    296296    $user_id = get_userid($_POST['login']);
    297297    log_user( $user_id, false);
    298       redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php?etat=not_defined');
     298      redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php');
    299299  }
    300300}//fin class
Note: See TracChangeset for help on using the changeset viewer.