Changeset 2084


Ignore:
Timestamp:
Sep 11, 2007, 4:24:51 AM (17 years ago)
Author:
rvelices
Message:

feature 731: permissions at image level

  • this is the first version - I wait for feedback before changing help files
Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/action.php

    r1912 r2084  
    9090  WHERE image_id = '.$_GET['id'].'
    9191'.get_sql_condition_FandF(
    92   array('forbidden_categories' => 'category_id'),
     92  array(
     93      'forbidden_categories' => 'category_id',
     94      'forbidden_images' => 'image_id',
     95    ),
    9396  '    AND'
    9497  ).'
  • trunk/admin/element_set_global.php

    r2003 r2084  
    137137  $dbfields = array('primary' => array('id'), 'update' => array());
    138138
    139   $formfields = array('author', 'name', 'date_creation');
     139  $formfields = array('author', 'name', 'date_creation', 'level');
    140140  foreach ($formfields as $formfield)
    141141  {
     
    164164      {
    165165        $data['author'] = $_POST['author'];
    166 
    167166        if ('' == $data['author'])
    168167        {
     
    174173      {
    175174        $data['name'] = $_POST['name'];
    176 
    177175        if ('' == $data['name'])
    178176        {
     
    188186          .'-'.$_POST['date_creation_day']
    189187          ;
     188      }
     189
     190      if ('set' == $_POST['level_action'])
     191      {
     192        $data['level'] = $_POST['level'];
    190193      }
    191194
     
    346349$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
    347350
     351// image level options
     352$blockname = 'level_option';
     353foreach ($conf['available_permission_levels'] as $level)
     354{
     355  $template->assign_block_vars(
     356    $blockname,
     357    array(
     358      'VALUE' => $level,
     359      'CONTENT' => l10n( sprintf('Level %d', $level) ),
     360      ));
     361}
     362
    348363// +-----------------------------------------------------------------------+
    349364// |                        global mode thumbnails                         |
     
    378393
    379394  $query = '
    380 SELECT id,path,tn_ext,file,filesize
     395SELECT id,path,tn_ext,file,filesize,level
    381396  FROM '.IMAGES_TABLE.'
    382397  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
     
    406421        )
    407422      );
     423
     424    if ( $row['level']>0 )
     425    {
     426      $template->assign_block_vars('thumbnails.thumbnail.level',
     427          array(
     428              'LEVEL' => $row['level'],
     429              'TITLE' => l10n( sprintf('Level %d', $row['level']) ),
     430            )
     431        );
     432    }
    408433  }
    409434}
  • trunk/admin/user_list.php

    r2041 r2084  
    9898                ui.status,
    9999                ui.adviser,
    100                 ui.enabled_high
     100                ui.enabled_high,
     101                ui.level
    101102  FROM '.USERS_TABLE.' AS u
    102103    INNER JOIN '.USER_INFOS_TABLE.' AS ui
     
    257258    array_push($page['errors'], l10n('Guest cannot be deleted'));
    258259  }
    259   if (($conf['guest_id'] != $conf['default_user_id']) and 
     260  if (($conf['guest_id'] != $conf['default_user_id']) and
    260261      in_array($conf['default_user_id'], $collection))
    261262  {
     
    352353    array('nb_image_line', 'nb_line_page', 'template', 'language',
    353354          'recent_period', 'maxwidth', 'expand', 'show_nb_comments',
    354           'show_nb_hits', 'maxheight', 'status', 'enabled_high');
    355 
    356   $true_false_fields = array('expand', 'show_nb_comments',
     355          'show_nb_hits', 'maxheight', 'status', 'enabled_high',
     356          'level');
     357
     358  $true_false_fields = array('expand', 'show_nb_comments',
    357359                       'show_nb_hits', 'enabled_high');
    358360  if ($conf['allow_adviser'])
     
    757759}
    758760
     761// user level options
     762$blockname = 'level_option';
     763foreach ($conf['available_permission_levels'] as $level)
     764{
     765  $template->assign_block_vars(
     766    $blockname,
     767    array(
     768      'VALUE' => $level,
     769      'CONTENT' => l10n( sprintf('Level %d', $level) ),
     770      'SELECTED' => $level==$default_user['level'] ? 'selected="selected"' : '',
     771      ));
     772}
     773
    759774// +-----------------------------------------------------------------------+
    760775// |                            navigation bar                             |
     
    818833    $checked = '';
    819834  }
     835
     836  $properties = array();
     837  $properties[] =
     838    (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
     839        ? $lang['is_high_enabled'] : $lang['is_high_disabled'];
     840
     841  $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
    820842
    821843  $template->assign_block_vars(
     
    837859      'EMAIL' => get_email_address_as_display_text($local_user['email']),
    838860      'GROUPS' => $groups_string,
    839       'PROPERTIES' =>
    840         (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
    841         ? $lang['is_high_enabled'] : $lang['is_high_disabled']
     861      'PROPERTIES' => implode( ',', $properties),
     862
    842863      )
    843864    );
  • trunk/include/config_default.inc.php

    r2029 r2084  
    169169//
    170170// Advenced use:
    171 //  You can also used special options. Instead to pass a string like parameter value 
     171//  You can also used special options. Instead to pass a string like parameter value
    172172//  you can pass a array with different optional parameter values
    173173//  $conf['links'] = array(
     
    175175//    'http://forum.phpwebgallery.net' => array('label' => 'For ADMIN', 'new_window' => true, 'eval_visible' => 'return is_admin();'),
    176176//    'http://phpwebgallery.net/doc' => array('label' => 'For Guest', 'new_window' => true, 'eval_visible' => 'return is_a_guest();'),
    177 //    'http://download.gna.org/phpwebgallery/' => 
    178 //      array('label' => 'PopUp', 'new_window' => true, 
     177//    'http://download.gna.org/phpwebgallery/' =>
     178//      array('label' => 'PopUp', 'new_window' => true,
    179179//      'nw_name' => 'PopUp', 'nw_features' => 'width=800,height=450,location=no,status=no,toolbar=no,scrollbars=no,menubar=no'),
    180180//    );
     
    264264$conf['users_page'] = 20;
    265265
     266// image level permissions available in the admin interface
     267$conf['available_permission_levels'] = array(0,1,2,4,8);
     268
    266269// mail_options: only set it true if you have a send mail warning with
    267270// "options" parameter missing on mail() function execution.
     
    615618
    616619// On Access control false / Admim Web Service need Php cURL extension
    617 // Controls are done on public basis or 
     620// Controls are done on public basis or
    618621// if connected on member authorization basis
    619622$conf['ws_access_control'] = false;
    620  
    621 // On Access control true 
     623
     624// On Access control true
    622625// Additionnal controls are made based on Web Service Access Table
    623626
     
    629632  $conf['ws_postponed_start'] = array(0,1,2,3,5,7,14,30); /* In days */
    630633
    631 // By default 10, 5, 2, 1 year(s) or 6, 3, 1 month(s) 
     634// By default 10, 5, 2, 1 year(s) or 6, 3, 1 month(s)
    632635// or 15, 10, 7, 5, 1, 0 day(s)
    633636// 0 it's temporary closed (Useful for one access)
    634   $conf['ws_durations'] = array(3650,1825,730,365,182,91,30,15,10,7,5,1,0); 
     637  $conf['ws_durations'] = array(3650,1825,730,365,182,91,30,15,10,7,5,1,0);
    635638
    636639// +-----------------------------------------------------------------------+
     
    676679// | Light slideshow                                                       |
    677680// +-----------------------------------------------------------------------+
    678 // $conf['light_slideshow'] indicates to use slideshow.tpl in state of 
     681// $conf['light_slideshow'] indicates to use slideshow.tpl in state of
    679682// picture.tpl for slideshow
    680683// Take care to have slideshow.tpl in all available templates
     
    682685// Check if Picture's plugins are compliant with it
    683686// Every plugin from 1.7 would be design to manage light_slideshow case.
    684 $conf['light_slideshow'] = true; 
     687$conf['light_slideshow'] = true;
    685688
    686689?>
  • trunk/include/functions_user.inc.php

    r2055 r2084  
    258258        calculate_permissions($userdata['id'], $userdata['status']);
    259259
     260      /* now we build the list of forbidden images (this list does not contain
     261      images that are not in at least an authorized category)*/
     262      $query = '
     263SELECT DISTINCT(id)
     264  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     265  WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
     266    AND level>'.$userdata['level'];
     267      $forbidden_ids = array_from_query($query, 'id');
     268
     269      if ( empty($forbidden_ids) )
     270      {
     271        array_push( $forbidden_ids, 0 );
     272      }
     273      $userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
     274      $userdata['image_access_list'] = implode(',',$forbidden_ids);
     275
    260276      update_user_cache_categories($userdata);
    261277
     
    270286  FROM '.IMAGE_CATEGORY_TABLE.'
    271287  WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
     288    AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
    272289;';
    273290      list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
     
    282299      $query = '
    283300INSERT INTO '.USER_CACHE_TABLE.'
    284   (user_id, need_update, forbidden_categories, nb_total_images)
     301  (user_id, need_update, forbidden_categories, nb_total_images,
     302    image_access_type, image_access_list)
    285303  VALUES
    286304  ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
    287   .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].')
     305  .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
     306  .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
    288307;';
    289308      pwg_query($query);
     
    528547
    529548  $query = 'SELECT c.id cat_id, global_rank';
    530   if ( !isset($filter_days) )
    531   {
    532     $query .= ',
    533     date_last cat_date_last,
    534     nb_images cat_nb_images
    535   FROM '.CATEGORIES_TABLE.' as c';
    536   }
    537   else
    538   {
    539     // Count by date_available to avoid count null
    540     $query .= ',
    541     MAX(date_available) cat_date_last,
    542     COUNT(date_available) cat_nb_images
    543   FROM '.CATEGORIES_TABLE.' as c
    544     LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
    545     LEFT JOIN '.IMAGES_TABLE.' AS i
    546       ON ic.image_id = i.id AND
    547           i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
    548     $group_by = 'c.id';
    549   }
     549  // Count by date_available to avoid count null
     550  $query .= ',
     551  MAX(date_available) cat_date_last,  COUNT(date_available) cat_nb_images
     552FROM '.CATEGORIES_TABLE.' as c
     553  LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
     554  LEFT JOIN '.IMAGES_TABLE.' AS i
     555    ON ic.image_id = i.id
     556      AND i.level<='.$userdata['level'];
     557
     558  if ( isset($filter_days) )
     559  {
     560    $query .= ' AND i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
     561  }
     562  $group_by = 'c.id';
    550563
    551564  if ( !empty($userdata['forbidden_categories']) )
     
    720733{
    721734  global $page, $conf;
    722  
     735
    723736  if (!isset($page['cache_default_user']))
    724737  {
     
    728741    $result = pwg_query($query);
    729742    $page['cache_default_user'] = mysql_fetch_assoc($result);
    730    
     743
    731744    if ($page['cache_default_user'] !== false)
    732745    {
     
    840853    foreach ($user_ids as $user_id)
    841854    {
     855      $level= isset($default_user['level']) ? $default_user['level'] : 0;
    842856      if ($user_id == $conf['webmaster_id'])
    843857      {
    844858        $status = 'webmaster';
    845       }
    846       else if (($user_id == $conf['guest_id']) or
     859        $level = max( $conf['available_permission_levels'] );
     860      }
     861      else if (($user_id == $conf['guest_id']) or
    847862               ($user_id == $conf['default_user_id']))
    848863      {
     
    859874          'user_id' => $user_id,
    860875          'status' => $status,
    861           'registration_date' => $dbnow
     876          'registration_date' => $dbnow,
     877          'level' => $level
    862878          ));
    863879
    864880      array_push($inserts, $insert);
    865       }
     881    }
    866882
    867883    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     
    902918 * availability of the file
    903919 *
    904  * in descending order of preference: 
     920 * in descending order of preference:
    905921 *   param language, user language, default language
    906922 * PhpWebGallery default language.
     
    12911307      }
    12921308      case 'visible_images':
    1293       {
    12941309        if (!empty($filter['visible_images']))
    12951310        {
     
    12971312            $field_name.' IN ('.$filter['visible_images'].')';
    12981313        }
     1314        // note there is no break - visible include forbidden
     1315      case 'forbidden_images':
     1316        if (
     1317            !empty($user['image_access_list'])
     1318            or $user['image_access_type']!='NOT IN'
     1319            )
     1320        {
     1321          $table_prefix=null;
     1322          if ($field_name=='id')
     1323          {
     1324            $table_prefix = '';
     1325          }
     1326          elseif ($field_name=='i.id')
     1327          {
     1328            $table_prefix = 'i.';
     1329          }
     1330          if ( isset($table_prefix) )
     1331          {
     1332            $sql_list[]=$table_prefix.'level<='.$user['level'];
     1333          }
     1334          else
     1335          {
     1336            $sql_list[]=$field_name.' '.$user['image_access_type']
     1337                .' ('.$user['image_access_list'].')';
     1338          }
     1339        }
    12991340        break;
    1300       }
    13011341      default:
    13021342      {
  • trunk/install/phpwebgallery_structure.sql

    r1963 r2084  
    199199  `storage_category_id` smallint(5) unsigned default NULL,
    200200  `high_filesize` mediumint(9) unsigned default NULL,
     201  `level` tinyint unsigned NOT NULL default '0',
    201202  PRIMARY KEY  (`id`),
    202203  KEY `images_i2` (`date_available`),
     
    329330  `forbidden_categories` text,
    330331  `nb_total_images` mediumint(8) unsigned default NULL,
     332  `image_access_type` enum('NOT IN','IN') NOT NULL default 'NOT IN',
     333  `image_access_list` text default NULL,
    331334  PRIMARY KEY  (`user_id`)
    332335) TYPE=MyISAM;
     
    390393  `registration_date` datetime NOT NULL default '0000-00-00 00:00:00',
    391394  `enabled_high` enum('true','false') NOT NULL default 'true',
     395  `level` tinyint unsigned NOT NULL default '0',
    392396  UNIQUE KEY `user_infos_ui1` (`user_id`)
    393397) TYPE=MyISAM;
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r2068 r2084  
    642642$lang['Thumbnails'] = 'Thumbnails';
    643643$lang['obligatory_user_mail_address'] = 'Mail address is obligatory for all users';
     644$lang['Minimum privacy level'] = 'Minimum privacy level';
     645$lang['Privacy level'] = 'Privacy level';
     646$lang['Level 0'] = 'Public';
     647$lang['Level 1'] = 'Contacts';
     648$lang['Level 2'] = 'Friends';
     649$lang['Level 4'] = 'Family';
     650$lang['Level 8'] = 'Admins';
    644651?>
  • trunk/language/fr_FR.iso-8859-1/admin.lang.php

    r2068 r2084  
    643643$lang['Thumbnails'] = 'Miniatures';
    644644$lang['obligatory_user_mail_address'] = 'L\'adresse mail est obligatoire pour tous les utilisateurs';
     645$lang['Minimum privacy level'] = 'Niveau minimal de confidentialité';
     646$lang['Privacy level'] = 'Niveau de confidentialité';
     647$lang['Level 0'] = 'Public';
     648$lang['Level 1'] = 'Contacts';
     649$lang['Level 2'] = 'Amis';
     650$lang['Level 4'] = 'Famille';
     651$lang['Level 8'] = 'Admins';
    645652?>
  • trunk/template/yoga/admin/element_set_global.tpl

    r1902 r2084  
    3535    <li><span class="wrap1">
    3636        <label>
    37           <span class="wrap2"><span>
     37          <span class="wrap2">
     38                        <!-- BEGIN level -->
     39                        <em class="levelIndicatorB">{thumbnails.thumbnail.level.LEVEL}</em><em class="levelIndicatorF" title="{thumbnails.thumbnail.level.TITLE}">{thumbnails.thumbnail.level.LEVEL}</em>
     40                        <!-- END level -->
     41          <span>
    3842            <img src="{thumbnails.thumbnail.SRC}"
    3943               alt="{thumbnails.thumbnail.ALT}"
     
    134138    </tr>
    135139
     140        <tr>
     141                <td>{lang:Minimum privacy level}</td>
     142                <td>
     143                        <label><input type="radio" name="level_action" value="leave" checked="checked" />{lang:leave}</label>
     144                        <label><input type="radio" name="level_action" value="set" id="level_action_set" />{lang:set to}</label>
     145                        <select onmousedown="document.getElementById('level_action_set').checked = true;" name="level" size="1">
     146                        <!-- BEGIN level_option -->
     147                        <option {level_option.SELECTED} value="{level_option.VALUE}">{level_option.CONTENT} ({level_option.VALUE})</option>
     148                        <!-- END level_option -->
     149                        </select>
     150          </td>
     151        </tr>
     152
    136153  </table>
    137154
  • trunk/template/yoga/admin/user_list.tpl

    r2041 r2084  
    191191    </tr>
    192192
     193        <tr>
     194                <td>{lang:Privacy level}</td>
     195                <td>
     196                        <label><input type="radio" name="level_action" value="leave" checked="checked" />{lang:leave}</label>
     197                        <label><input type="radio" name="level_action" value="set" id="level_action_set" />{lang:set to}</label>
     198                        <select onmousedown="document.getElementById('level_action_set').checked = true;" name="level" size="1">
     199                        <!-- BEGIN level_option -->
     200                        <option {level_option.SELECTED} value="{level_option.VALUE}">{level_option.CONTENT} ({level_option.VALUE})</option>
     201                        <!-- END level_option -->
     202                        </select>
     203          </td>
     204        </tr>
     205
    193206  </table>
    194207
  • trunk/template/yoga/menubar.css

    r1900 r2084  
    4848    font-size: 100%;
    4949    margin-top: 0;
     50    margin-bottom: 0;
    5051}
    5152
  • trunk/template/yoga/thumbnails.css

    r1900 r2084  
    5252}
    5353 
     54UL.thumbnails .levelIndicatorB {
     55display:block; position:absolute; z-index:100;padding:0px 0 0 14px; color:black; font-weight:bold; fontsize:120%;
     56}
     57
     58UL.thumbnails .levelIndicatorF {
     59display:block; position:absolute; z-index:101;padding:1px 0 0 15px; color:white; font-weight:bold; fontsize:120%;
     60}
Note: See TracChangeset for help on using the changeset viewer.