[5179] | 1 | <?php |
---|
| 2 | |
---|
| 3 | //language select creation |
---|
| 4 | function news_language_select($available_lang,$default, $select_name = "language") |
---|
| 5 | { |
---|
| 6 | $lang_select = '<select name="' . $select_name . '">'; |
---|
| 7 | foreach ($available_lang as $code => $displayname) |
---|
| 8 | { |
---|
| 9 | $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : ''; |
---|
| 10 | $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>'; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | $lang_select .= '</select>'; |
---|
| 14 | |
---|
| 15 | return $lang_select; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | function display_select_news_wrapper($query, $selecteds, $blockname) |
---|
| 19 | { |
---|
| 20 | $result = pwg_query($query); |
---|
| 21 | |
---|
| 22 | $news = array(); |
---|
| 23 | |
---|
| 24 | if (!empty($result)) |
---|
| 25 | { |
---|
| 26 | while ($row = mysql_fetch_array($result)) |
---|
| 27 | { |
---|
| 28 | array_push($news, $row); |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | display_select_news($news, $selecteds, $blockname); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function display_select_news($news, $selecteds, $blockname) |
---|
| 35 | { |
---|
| 36 | global $template; |
---|
| 37 | |
---|
| 38 | foreach ($news as $new) |
---|
| 39 | { |
---|
| 40 | $selected = ''; |
---|
| 41 | if (in_array($new['id'], $selecteds)) |
---|
| 42 | { |
---|
| 43 | $selected = ' selected="selected"'; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | $option = '['.$new['new_id'].'] - '.$new['title']; |
---|
| 47 | |
---|
| 48 | $template->assign_block_vars( |
---|
| 49 | $blockname, |
---|
| 50 | array('SELECTED'=>$selected, |
---|
| 51 | 'VALUE'=>$new['new_id'], |
---|
| 52 | 'OPTION'=>$option |
---|
| 53 | )); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | function calculate_news_permissions($user_id) |
---|
| 59 | { |
---|
| 60 | global $user; |
---|
| 61 | |
---|
| 62 | $private_array = array(); |
---|
| 63 | $authorized_array = array(); |
---|
| 64 | $refused_array = array(); |
---|
| 65 | |
---|
| 66 | $query = ' |
---|
| 67 | SELECT id |
---|
| 68 | FROM '.NEWS_TABLE.' |
---|
| 69 | WHERE status = \'private\' |
---|
| 70 | ;'; |
---|
| 71 | $result = pwg_query($query); |
---|
| 72 | |
---|
| 73 | while ($row = mysql_fetch_array($result)) |
---|
| 74 | { |
---|
| 75 | array_push($private_array, $row['id']); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | // retrieve news ids directly refused to the user |
---|
| 79 | $query = ' |
---|
| 80 | SELECT new_id |
---|
| 81 | FROM '.NEWS_USER_REFUSED_TABLE.' |
---|
| 82 | WHERE user_id = '.$user_id.' |
---|
| 83 | ;'; |
---|
| 84 | $refused_array = array_from_query($query, 'new_id'); |
---|
| 85 | |
---|
| 86 | // retrieve news ids directly authorized to the user |
---|
| 87 | $query = ' |
---|
| 88 | SELECT new_id |
---|
| 89 | FROM '.NEWS_USER_ACCESS_TABLE.' |
---|
| 90 | WHERE user_id = '.$user_id.' |
---|
| 91 | ;'; |
---|
| 92 | $authorized_array = array_from_query($query, 'new_id'); |
---|
| 93 | |
---|
| 94 | // retrieve news ids refuseded to the groups the user belongs to |
---|
| 95 | $query = ' |
---|
| 96 | SELECT new_id |
---|
| 97 | FROM '.NEWS_GROUP_REFUSED_TABLE.' AS ngr |
---|
| 98 | INNER JOIN '.USER_GROUP_TABLE.' AS ug ON ug.group_id = ngr.group_id |
---|
| 99 | WHERE ug.user_id = '.$user_id.' |
---|
| 100 | ;'; |
---|
| 101 | $refused_array = array_unique(array_merge($refused_array, array_from_query($query, 'new_id'))); |
---|
| 102 | |
---|
| 103 | // retrieve news ids authorized to the groups the user belongs to |
---|
| 104 | $query = ' |
---|
| 105 | SELECT new_id |
---|
| 106 | FROM '.NEWS_GROUP_ACCESS_TABLE.' AS nga |
---|
| 107 | INNER JOIN '.USER_GROUP_TABLE.' AS ug ON ug.group_id = nga.group_id |
---|
| 108 | WHERE ug.user_id = '.$user_id.' |
---|
| 109 | ;'; |
---|
| 110 | $authorized_array = array_unique(array_merge($authorized_array, array_from_query($query, 'new_id'))); |
---|
| 111 | |
---|
| 112 | // only unauthorized private + refused categories are forbidden |
---|
| 113 | $forbidden_array = array_unique(array_merge($refused_array, array_diff($private_array, $authorized_array))); |
---|
| 114 | |
---|
| 115 | if ( empty($forbidden_array) ) |
---|
| 116 | {// at least, the list contains 0 value. This news does not exists so |
---|
| 117 | // where clauses such as "WHERE news_id NOT IN(0)" will always be |
---|
| 118 | // true. |
---|
| 119 | array_push($forbidden_array, 0); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | return implode(',', $forbidden_array); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | ?> |
---|