Ignore:
Timestamp:
Jul 15, 2013, 6:34:44 PM (11 years ago)
Author:
plg
Message:

ability to set any album as a user album

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/main.inc.php

    r23371 r23960  
    658658  }
    659659}
     660
     661// +-----------------------------------------------------------------------+
     662// | User Albums                                                           |
     663// +-----------------------------------------------------------------------+
     664
     665add_event_handler('loc_end_cat_modify', 'community_set_prefilter_cat_modify', 50);
     666// add_event_handler('loc_begin_admin_page', 'community_cat_modify_submit', 45);
     667
     668// Change the variables used by the function that changes the template
     669// add_event_handler('loc_begin_admin_page', 'community_cat_modify_add_vars_to_template');
     670
     671function community_set_prefilter_cat_modify()
     672{
     673        global $template, $conf, $category;
     674
     675  if (!isset($conf['community']['user_albums']) or !$conf['community']['user_albums'])
     676  {
     677    return;
     678  }
     679 
     680  $template->set_prefilter('album_properties', 'community_cat_modify_prefilter');
     681
     682  $query = '
     683SELECT
     684    '.$conf['user_fields']['id'].' AS id,
     685    '.$conf['user_fields']['username'].' AS username
     686  FROM '.USERS_TABLE.' AS u
     687    INNER JOIN '.USER_INFOS_TABLE.' AS uf ON uf.user_id = id
     688  WHERE uf.status IN (\'normal\',\'generic\')
     689;';
     690  $result = pwg_query($query);
     691  $users = array();
     692  while ($row = pwg_db_fetch_assoc($result))
     693  {
     694    $users[$row['id']] = $row['username'];
     695  }
     696
     697  $template->assign(
     698    array(
     699      'community_user_options' => $users,
     700      'community_user_selected' => $category['community_user'],
     701      )
     702    );
     703}
     704
     705function community_cat_modify_prefilter($content, &$smarty)
     706{
     707        $search = "#<strong>{'Name'#";
     708
     709        // We use the <tr> from the Creation date, and give them a new <tr>
     710        $replacement = '<strong>(Community) {\'Album of user\'|@translate}</strong>
     711                <br>
     712                        <select name="community_user">
     713                                <option value="">--</option>
     714                                {html_options options=$community_user_options selected=$community_user_selected}
     715                        </select>
     716      <em>{\'a user can own only one album\'|@translate}</em>
     717                </p>
     718       
     719        </p>
     720  <p>
     721                <strong>{\'Name\'';
     722
     723  return preg_replace($search, $replacement, $content);
     724}
     725
     726add_event_handler('loc_begin_cat_modify', 'community_cat_modify_submit');
     727function community_cat_modify_submit()
     728{
     729  global $category, $conf;
     730
     731  if (!isset($conf['community']['user_albums']) or !$conf['community']['user_albums'])
     732  {
     733    return;
     734  }
     735 
     736  if (isset($_POST['community_user']))
     737  {
     738    // echo '<pre>'; print_r($_POST); echo '</pre>'; exit();
     739    // only one album for each user, first we remove ownership on any other album
     740    single_update(
     741      CATEGORIES_TABLE,
     742      array('community_user' => null),
     743      array('community_user' => $_POST['community_user'])
     744      );
     745
     746    // then we give the album to the user
     747    single_update(
     748      CATEGORIES_TABLE,
     749      array('community_user' => $_POST['community_user']),
     750      array('id' => $category['id'])
     751      );
     752  }
     753}
    660754?>
Note: See TracChangeset for help on using the changeset viewer.