Просмотр файла album.php

Размер файла: 131.55Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', true);
  7. $phpbb_root_path = './';
  8. $album_root_path = $phpbb_root_path . 'album_mod/';
  9. $opera_mini = "./opera_mini";
  10. include($phpbb_root_path . 'extension.inc');
  11. include($phpbb_root_path . 'common.'.$phpEx);
  12. include($phpbb_root_path . 'includes/functions_validate.'.$phpEx);
  13. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  14.  
  15. $userdata = session_pagestart($user_ip, PAGE_ALBUM);
  16. init_userprefs($userdata);
  17.  
  18. include($album_root_path . 'album_common.'.$phpEx);
  19.  
  20. if ( isset($HTTP_GET_VARS['action']) || isset($HTTP_POST_VARS['action']) )
  21. {
  22. $action = ( isset($HTTP_POST_VARS['action']) ) ? htmlspecialchars($HTTP_POST_VARS['action']) : htmlspecialchars($HTTP_GET_VARS['action']);
  23. }
  24. else
  25. {
  26. $action = '';
  27. }
  28.  
  29. if ( $action == 'cat' )
  30. {
  31. if( isset($HTTP_POST_VARS['cat_id']) )
  32. {
  33. $cat_id = intval($HTTP_POST_VARS['cat_id']);
  34. }
  35. else if( isset($HTTP_GET_VARS['cat_id']) )
  36. {
  37. $cat_id = intval($HTTP_GET_VARS['cat_id']);
  38. }
  39. else
  40. {
  41. message_die(GENERAL_ERROR, 'No categories specified');
  42. }
  43.  
  44. if ($cat_id == PERSONAL_GALLERY)
  45. {
  46. redirect(append_sid("album.$phpEx?action=personal"));
  47. }
  48.  
  49. $sql = "SELECT c.*, COUNT(p.pic_id) AS count
  50. FROM ". ALBUM_CAT_TABLE ." AS c LEFT JOIN ". ALBUM_TABLE ." AS p ON c.cat_id = p.pic_cat_id
  51. WHERE c.cat_id <> 0
  52. GROUP BY c.cat_id
  53. ORDER BY cat_order";
  54. if( !($result = $db->sql_query($sql)) )
  55. {
  56. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  57. }
  58.  
  59. $thiscat = array();
  60. $catrows = array();
  61.  
  62. while( $row = $db->sql_fetchrow($result) )
  63. {
  64. $album_user_access = album_user_access($row['cat_id'], $row, 1, 0, 0, 0, 0, 0); // VIEW
  65. if ($album_user_access['view'] == 1)
  66. {
  67. $catrows[] = $row;
  68.  
  69. if( $row['cat_id'] == $cat_id )
  70. {
  71. $thiscat = $row;
  72. $auth_data = album_user_access($cat_id, $row, 1, 1, 1, 1, 1, 1); // ALL
  73. $total_pics = $thiscat['count'];
  74. }
  75. }
  76. }
  77.  
  78. if (empty($thiscat))
  79. {
  80. message_die(GENERAL_MESSAGE, $lang['Category_not_exist']);
  81. }
  82.  
  83. if( !$auth_data['view'] )
  84. {
  85. if (!$userdata['session_logged_in'])
  86. {
  87. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=cat&cat_id=$cat_id"));
  88. }
  89. else
  90. {
  91. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  92. }
  93. }
  94.  
  95. $auth_key = array_keys($auth_data);
  96.  
  97. $auth_list = '';
  98. for ($i = 0; $i < (count($auth_data) - 1); $i++)
  99. {
  100. if( ( ($album_config['rate'] == 0) and ($auth_key[$i] == 'rate') ) or ( ($album_config['comment'] == 0) and ($auth_key[$i] == 'comment') ) )
  101. {
  102. continue;
  103. }
  104.  
  105. $auth_list .= ($auth_data[$auth_key[$i]] == 1) ? $lang['Album_'. $auth_key[$i] .'_can'] : $lang['Album_'. $auth_key[$i] .'_cannot'];
  106. $auth_list .= '<br />';
  107. }
  108.  
  109. if( ($userdata['user_level'] == ADMIN) or ($auth_data['moderator'] == 1) )
  110. {
  111. $auth_list .= sprintf($lang['Album_moderate_can'], '<a href="'. append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") .'">', '</a>');
  112. $moderka = '<a href="'. append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") .'">'.$lang['Album_moderka'].'</a>';
  113. }
  114.  
  115. $grouprows = array();
  116. $moderators_list = '';
  117.  
  118. if ($thiscat['cat_moderator_groups'] != '')
  119. {
  120. $sql = "SELECT group_id, group_name, group_type, group_single_user
  121. FROM " . GROUPS_TABLE . "
  122. WHERE group_single_user <> 1
  123. AND group_type <> ". GROUP_HIDDEN ."
  124. AND group_id IN (". $thiscat['cat_moderator_groups'] .")
  125. ORDER BY group_name ASC";
  126. if ( !$result = $db->sql_query($sql) )
  127. {
  128. message_die(GENERAL_ERROR, 'Could not get group list', '', __LINE__, __FILE__, $sql);
  129. }
  130.  
  131. while( $row = $db->sql_fetchrow($result) )
  132. {
  133. $grouprows[] = $row;
  134. }
  135.  
  136. if( count($grouprows) > 0 )
  137. {
  138. for ($j = 0; $j < count($grouprows); $j++)
  139. {
  140. $group_link = '<a href="'. append_sid("groupcp.$phpEx?". POST_GROUPS_URL .'='. $grouprows[$j]['group_id']) .'">'. $grouprows[$j]['group_name'] .'</a>';
  141. $moderators_list .= ($moderators_list == '') ? $group_link : ', ' . $group_link;
  142. }
  143. }
  144. }
  145.  
  146. if( empty($moderators_list) )
  147. {
  148. $moderators_list = $lang['None'];
  149. }
  150.  
  151. if( isset($HTTP_GET_VARS['start']) )
  152. {
  153. $start = intval($HTTP_GET_VARS['start']);
  154. }
  155. else if( isset($HTTP_POST_VARS['start']) )
  156. {
  157. $start = intval($HTTP_POST_VARS['start']);
  158. }
  159. else
  160. {
  161. $start = 0;
  162. }
  163. $start = ($start < 0) ? 0 : $start;
  164.  
  165. if( isset($HTTP_GET_VARS['sort_method']) )
  166. {
  167. switch ($HTTP_GET_VARS['sort_method'])
  168. {
  169. case 'pic_time':
  170. $sort_method = 'p.pic_time';
  171. break;
  172. case 'pic_title':
  173. $sort_method = 'p.pic_title';
  174. break;
  175. case 'username':
  176. $sort_method = 'u.username';
  177. break;
  178. case 'pic_view_count':
  179. $sort_method = 'p.pic_view_count';
  180. break;
  181. case 'rating':
  182. $sort_method = 'rating';
  183. break;
  184. case 'comments':
  185. $sort_method = 'comments';
  186. break;
  187. case 'new_comment':
  188. $sort_method = 'new_comment';
  189. break;
  190. default:
  191. $sort_method = $album_config['sort_method'];
  192. }
  193. }
  194. else if( isset($HTTP_POST_VARS['sort_method']) )
  195. {
  196. switch ($HTTP_POST_VARS['sort_method'])
  197. {
  198. case 'pic_time':
  199. $sort_method = 'p.pic_time';
  200. break;
  201. case 'pic_title':
  202. $sort_method = 'p.pic_title';
  203. break;
  204. case 'username':
  205. $sort_method = 'u.username';
  206. break;
  207. case 'pic_view_count':
  208. $sort_method = 'p.pic_view_count';
  209. break;
  210. case 'rating':
  211. $sort_method = 'rating';
  212. break;
  213. case 'comments':
  214. $sort_method = 'comments';
  215. break;
  216. case 'new_comment':
  217. $sort_method = 'new_comment';
  218. break;
  219. default:
  220. $sort_method = $album_config['sort_method'];
  221. }
  222. }
  223. else
  224. {
  225. $sort_method = $album_config['sort_method'];
  226. }
  227.  
  228. if( isset($HTTP_GET_VARS['sort_order']) )
  229. {
  230. switch ($HTTP_GET_VARS['sort_order'])
  231. {
  232. case 'ASC':
  233. $sort_order = 'ASC';
  234. break;
  235. case 'DESC':
  236. $sort_order = 'DESC';
  237. break;
  238. default:
  239. $sort_order = $album_config['sort_order'];
  240. }
  241. }
  242. else if( isset($HTTP_POST_VARS['sort_order']) )
  243. {
  244. switch ($HTTP_POST_VARS['sort_order'])
  245. {
  246. case 'ASC':
  247. $sort_order = 'ASC';
  248. break;
  249. case 'DESC':
  250. $sort_order = 'DESC';
  251. break;
  252. default:
  253. $sort_order = $album_config['sort_order'];
  254. }
  255. }
  256. else
  257. {
  258. $sort_order = $album_config['sort_order'];
  259. }
  260.  
  261. $pics_per_page = $album_config['rows_per_page'] * $album_config['cols_per_page'];
  262.  
  263. if ($total_pics > 0)
  264. {
  265. $limit_sql = ($start == 0) ? $pics_per_page : $start .','. $pics_per_page;
  266.  
  267. $pic_approval_sql = 'AND p.pic_approval = 1';
  268. if ($thiscat['cat_approval'] != ALBUM_USER)
  269. {
  270. if( ($userdata['user_level'] == ADMIN) or (($auth_data['moderator'] == 1) and ($thiscat['cat_approval'] == ALBUM_MOD)) )
  271. {
  272. $pic_approval_sql = '';
  273. }
  274. }
  275.  
  276. $sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_view_count, p.pic_lock, p.pic_approval, u.user_id, u.username, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments, MAX(c.comment_id) as new_comment
  277. FROM ". ALBUM_TABLE ." AS p
  278. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  279. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  280. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  281. WHERE p.pic_cat_id = '$cat_id' $pic_approval_sql
  282. GROUP BY p.pic_id
  283. ORDER BY $sort_method $sort_order
  284. LIMIT $limit_sql";
  285. if( !($result = $db->sql_query($sql)) )
  286. {
  287. message_die(GENERAL_ERROR, 'Could not query pics information', '', __LINE__, __FILE__, $sql);
  288. }
  289.  
  290. $picrow = array();
  291.  
  292. while( $row = $db->sql_fetchrow($result) )
  293. {
  294. $picrow[] = $row;
  295. }
  296.  
  297.  
  298. for ($i = 0; $i < count($picrow); $i += $album_config['cols_per_page'])
  299. {
  300. for ($j = $i; $j < ($i + $album_config['cols_per_page']); $j++)
  301. {
  302. if( $j >= count($picrow) )
  303. {
  304. break;
  305. }
  306.  
  307. if(!$picrow[$j]['rating'])
  308. {
  309. $picrow[$j]['rating'] = $lang['Not_rated'];
  310. }
  311. else
  312. {
  313. $picrow[$j]['rating'] = round($picrow[$j]['rating'], 2);
  314. }
  315.  
  316. if ($thiscat['cat_approval'] != ALBUM_USER)
  317. {
  318. if( ($userdata['user_level'] == ADMIN) or (($auth_data['moderator'] == 1) and ($thiscat['cat_approval'] == ALBUM_MOD)) )
  319. {
  320. $approval_mode = ($picrow[$j]['pic_approval'] == 0) ? 'approval' : 'unapproval';
  321. $approval_link = '<a href="'. append_sid("album.$phpEx?action=modcp&amp;mode=$approval_mode&amp;pic_id=". $picrow[$j]['pic_id']) .'">';
  322. $approval_link .= ($picrow[$j]['pic_approval'] == 0) ? '<b>'. $lang['Approve'] .'</b>' : $lang['Unapprove'];
  323. $approval_link .= '</a><br/>';
  324. }
  325. }
  326.  
  327. if( ($picrow[$j]['user_id'] == ALBUM_GUEST) or ($picrow[$j]['username'] == '') )
  328. {
  329. $pic_poster = ($picrow[$j]['pic_username'] == '') ? $lang['Guest'] : $picrow[$j]['pic_username'];
  330. }
  331. else
  332. {
  333. $pic_poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $picrow[$j]['user_id']) .'">'. $picrow[$j]['username'] .'</a>';
  334. }
  335.  
  336. $template->assign_block_vars('picrow', array(
  337. 'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=". $picrow[$j]['pic_id']) : append_sid("album.$phpEx?action=page&amp;pic_id=". $picrow[$j]['pic_id']),
  338. 'TITLE' => $picrow[$j]['pic_title'],
  339. 'ROW_CLASS' => $row_class,
  340. 'POSTER' => $pic_poster,
  341. 'TIME' => create_date($board_config['default_dateformat'], $picrow[$j]['pic_time'], $board_config['board_timezone']),
  342. 'VIEW' => $picrow[$j]['pic_view_count'],
  343. 'RATING' => ($album_config['rate'] == 1) ? ( '<a href="'. append_sid("album.$phpEx?action=rate&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Rating'] . '</a>: ' . $picrow[$j]['rating'] . '<br />') : '',
  344. 'COMMENTS' => ($album_config['comment'] == 1) ? ( '<a href="'. append_sid("album.$phpEx?action=comment&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Comments'] . '</a>: ' . $picrow[$j]['comments'] . '<br />') : '',
  345. 'EDIT' => ( ( $auth_data['edit'] and ($picrow[$j]['pic_user_id'] == $userdata['user_id']) ) or ($auth_data['moderator'] and ($thiscat['cat_edit_level'] != ALBUM_ADMIN) ) or ($userdata['user_level'] == ADMIN) ) ? '<a href="'. append_sid("album.$phpEx?action=edit&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Edit_pic'] . '</a>|' : '',
  346. 'DELETE' => ( ( $auth_data['delete'] and ($picrow[$j]['pic_user_id'] == $userdata['user_id']) ) or ($auth_data['moderator'] and ($thiscat['cat_delete_level'] != ALBUM_ADMIN) ) or ($userdata['user_level'] == ADMIN) ) ? '<a href="'. append_sid("album.$phpEx?action=delete&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Delete_pic'] . '</a>|' : '',
  347. 'MOVE' => ($auth_data['moderator']) ? '<a href="'. append_sid("album.$phpEx?action=modcp&amp;mode=move&amp;pic_id=". $picrow[$j]['pic_id']) .'">'. $lang['Move'] .'</a>' : '',
  348. 'LOCK' => ($auth_data['moderator']) ? '<a href="'. append_sid("album.$phpEx?action=modcp&amp;mode=". (($picrow[$j]['pic_lock'] == 0) ? 'lock' : 'unlock') ."&amp;pic_id=". $picrow[$j]['pic_id']) .'">'. (($picrow[$j]['pic_lock'] == 0) ? $lang['Lock'] : $lang['Unlock']) .'</a>|' : '',
  349. 'IP' => ($userdata['user_level'] == ADMIN) ? $lang['IP_Address'] . ': ' . decode_ip($picrow[$j]['pic_user_ip']) .'<br />' : ''
  350. )
  351. );
  352.  
  353. $template->assign_block_vars('picrow.piccol', array(
  354. 'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=". $picrow[$j]['pic_id']) : append_sid("album.$phpEx?action=page&amp;pic_id=". $picrow[$j]['pic_id']),
  355. 'THUMBNAIL' => append_sid("album.$phpEx?action=thumbnail&amp;pic_id=". $picrow[$j]['pic_id']),
  356. 'DESC' => $picrow[$j]['pic_desc'],
  357. 'APPROVAL' => $approval_link,
  358. )
  359. );
  360. }
  361. }
  362.  
  363. $template->assign_vars(array(
  364. 'PAGINATION' => generate_pagination(append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id&amp;sort_method=$sort_method&amp;sort_order=$sort_order"), $total_pics, $pics_per_page, $start))
  365. );
  366. }
  367. else
  368. {
  369. $template->assign_block_vars('no_pics', array());
  370. }
  371.  
  372. $album_jumpbox = '<form name="jumpbox" action="'. append_sid("album.$phpEx?action=cat") .'" method="get">';
  373. $album_jumpbox .= $lang['Jump_to'] . ':&nbsp;<select name="cat_id" onChange="forms[\'jumpbox\'].submit()">';
  374. for ($i = 0; $i < count($catrows); $i++)
  375. {
  376. $album_jumpbox .= '<option value="'. $catrows[$i]['cat_id'] .'"';
  377. $album_jumpbox .= ($catrows[$i]['cat_id'] == $cat_id) ? 'selected="selected"' : '';
  378. $album_jumpbox .= '>' . $catrows[$i]['cat_title'] .'</option>';
  379. }
  380. $album_jumpbox .= '</select>';
  381. $album_jumpbox .= '&nbsp;<input type="submit" class="liteoption" value="'. $lang['Go'] .'" />';
  382. $album_jumpbox .= '<input type="hidden" name="sid" value="'. $userdata['session_id'] .'" />';
  383. $album_jumpbox .= '</form>';
  384.  
  385. $sort_rating_option = '';
  386. $sort_comments_option = '';
  387. if( $album_config['rate'] == 1 )
  388. {
  389. $sort_rating_option = '<option value="rating" ';
  390. $sort_rating_option .= ($sort_method == 'rating') ? 'selected="selected"' : '';
  391. $sort_rating_option .= '>' . $lang['Rating'] .'</option>';
  392. }
  393. if( $album_config['comment'] == 1 )
  394. {
  395. $sort_comments_option = '<option value="comments" ';
  396. $sort_comments_option .= ($sort_method == 'comments') ? 'selected="selected"' : '';
  397. $sort_comments_option .= '>' . $lang['Comments'] .'</option>';
  398. $sort_new_comment_option = '<option value="new_comment" ';
  399. $sort_new_comment_option .= ($sort_method == 'new_comment') ? 'selected="selected"' : '';
  400. $sort_new_comment_option .= '>' . $lang['New_Comment'] .'</option>';
  401. }
  402.  
  403. $page_title = 'Галерея сайта';
  404. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  405.  
  406. $template->set_filenames(array(
  407. 'body' => 'album_cat_body.tpl')
  408. );
  409.  
  410. $template->assign_vars(array(
  411. 'U_VIEW_CAT' => append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id"),
  412. 'CAT_TITLE' => $thiscat['cat_title'],
  413. 'L_MODERATORS' => $lang['Moderators'],
  414. 'MODERATORS' => $moderators_list,
  415. 'U_UPLOAD_PIC' => append_sid("album.$phpEx?action=upload&amp;cat_id=$cat_id"),
  416. 'UPLOAD_PIC_IMG' => $images['upload_pic'],
  417. 'L_UPLOAD_PIC' => $lang['Upload_Pic'],
  418. 'L_CATEGORY' => $lang['Category'],
  419. 'L_NO_PICS' => $lang['No_Pics'],
  420. 'S_COLS' => $album_config['cols_per_page'],
  421. 'S_COL_WIDTH' => (100/$album_config['cols_per_page']) . '%',
  422. 'L_VIEW' => $lang['View'],
  423. 'L_POSTER' => $lang['Poster'],
  424. 'L_POSTED' => $lang['Posted'],
  425. 'ALBUM_JUMPBOX' => $album_jumpbox,
  426. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id"),
  427. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  428. 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
  429. 'L_ORDER' => $lang['Order'],
  430. 'L_SORT' => $lang['Sort'],
  431. 'L_TIME' => $lang['Time'],
  432. 'L_PIC_TITLE' => $lang['Pic_Title'],
  433. 'L_USERNAME' => $lang['Sort_Username'],
  434. 'SORT_TIME' => ($sort_method == 'pic_time') ? 'selected="selected"' : '',
  435. 'SORT_PIC_TITLE' => ($sort_method == 'pic_title') ? 'selected="selected"' : '',
  436. 'SORT_USERNAME' => ($sort_method == 'pic_user_id') ? 'selected="selected"' : '',
  437. 'SORT_VIEW' => ($sort_method == 'pic_view_count') ? 'selected="selected"' : '',
  438. 'SORT_RATING_OPTION' => $sort_rating_option,
  439. 'SORT_COMMENTS_OPTION' => $sort_comments_option,
  440. 'SORT_NEW_COMMENT_OPTION' => $sort_new_comment_option,
  441. 'L_ASC' => $lang['Sort_Ascending'],
  442. 'L_DESC' => $lang['Sort_Descending'],
  443. 'SORT_ASC' => ($sort_order == 'ASC') ? 'selected="selected"' : '',
  444. 'SORT_DESC' => ($sort_order == 'DESC') ? 'selected="selected"' : '',
  445. 'U_MODERKA' => $moderka,
  446. 'S_AUTH_LIST' => $auth_list)
  447. );
  448.  
  449. $template->pparse('body');
  450.  
  451. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  452.  
  453. } elseif ( $action == 'comment' ) {
  454.  
  455. if( $album_config['comment'] == 0 )
  456. {
  457. message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
  458. }
  459.  
  460. if( isset($HTTP_GET_VARS['pic_id']) )
  461. {
  462. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  463. }
  464. else if( isset($HTTP_POST_VARS['pic_id']) )
  465. {
  466. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  467. }
  468. else
  469. {
  470. if( isset($HTTP_GET_VARS['comment_id']) )
  471. {
  472. $comment_id = intval($HTTP_GET_VARS['comment_id']);
  473. }
  474. else if( isset($HTTP_POST_VARS['comment_id']) )
  475. {
  476. $comment_id = intval($HTTP_POST_VARS['comment_id']);
  477. }
  478. else
  479. {
  480. message_die(GENERAL_ERROR, 'Bad request');
  481. }
  482. }
  483.  
  484. if( isset($comment_id) )
  485. {
  486. $sql = "SELECT comment_id, comment_pic_id
  487. FROM ". ALBUM_COMMENT_TABLE ."
  488. WHERE comment_id = '$comment_id'";
  489.  
  490. if( !($result = $db->sql_query($sql)) )
  491. {
  492. message_die(GENERAL_ERROR, 'Could not query comment and pic information', '', __LINE__, __FILE__, $sql);
  493. }
  494.  
  495. $row = $db->sql_fetchrow($result);
  496.  
  497. if( empty($row) )
  498. {
  499. message_die(GENERAL_ERROR, 'This comment does not exist');
  500. }
  501.  
  502. $pic_id = $row['comment_pic_id'];
  503. }
  504.  
  505. $sql = "SELECT p.*, u.user_id, u.username, COUNT(c.comment_id) as comments_count
  506. FROM ". ALBUM_TABLE ." AS p
  507. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  508. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  509. WHERE pic_id = '$pic_id'
  510. GROUP BY p.pic_id
  511. LIMIT 1";
  512. if( !($result = $db->sql_query($sql)) )
  513. {
  514. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  515. }
  516. $thispic = $db->sql_fetchrow($result);
  517.  
  518. $cat_id = $thispic['pic_cat_id'];
  519. $user_id = $thispic['pic_user_id'];
  520.  
  521. $total_comments = $thispic['comments_count'];
  522. $comments_per_page = $board_config['posts_per_page'];
  523.  
  524. if( empty($thispic) )
  525. {
  526. message_die(GENERAL_ERROR, $lang['Pic_not_exist'] . ' -> ' . $pic_id);
  527. }
  528.  
  529. if ($cat_id != PERSONAL_GALLERY)
  530. {
  531. $sql = "SELECT *
  532. FROM ". ALBUM_CAT_TABLE ."
  533. WHERE cat_id = '$cat_id'";
  534. if( !($result = $db->sql_query($sql)) )
  535. {
  536. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  537. }
  538.  
  539. $thiscat = $db->sql_fetchrow($result);
  540. }
  541. else
  542. {
  543. $thiscat = init_personal_gallery_cat($user_id);
  544. }
  545.  
  546. if (empty($thiscat))
  547. {
  548. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  549. }
  550.  
  551. $auth_data = album_user_access($cat_id, $thiscat, 1, 0, 0, 1, 1, 1);
  552.  
  553. if ($auth_data['view'] == 0)
  554. {
  555. if (!$userdata['session_logged_in'])
  556. {
  557. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=comment&pic_id=$pic_id"));
  558. exit;
  559. }
  560. else
  561. {
  562. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  563. }
  564. }
  565.  
  566. if( !isset($HTTP_POST_VARS['comment']) )
  567. {
  568. if( !isset($comment_id) )
  569. {
  570. if( isset($HTTP_GET_VARS['start']) )
  571. {
  572. $start = intval($HTTP_GET_VARS['start']);
  573. }
  574. else if( isset($HTTP_POST_VARS['start']) )
  575. {
  576. $start = intval($HTTP_POST_VARS['start']);
  577. }
  578. else
  579. {
  580. $start = 0;
  581. }
  582. $start = ($start < 0) ? 0 : $start;
  583. }
  584. else
  585. {
  586. $sql = "SELECT COUNT(comment_id) AS count
  587. FROM ". ALBUM_COMMENT_TABLE ."
  588. WHERE comment_pic_id = $pic_id
  589. AND comment_id < $comment_id";
  590.  
  591. if( !$result = $db->sql_query($sql) )
  592. {
  593. message_die(GENERAL_ERROR, 'Could not obtain comments information from the database', '', __LINE__, __FILE__, $sql);
  594. }
  595.  
  596. $row = $db->sql_fetchrow($result);
  597.  
  598. if( !empty($row) )
  599. {
  600. $start = floor( $row['count'] / $comments_per_page ) * $comments_per_page;
  601. }
  602. else
  603. {
  604. $start = 0;
  605. }
  606. }
  607.  
  608. if( isset($HTTP_GET_VARS['sort_order']) )
  609. {
  610. switch ($HTTP_GET_VARS['sort_order'])
  611. {
  612. case 'ASC':
  613. $sort_order = 'ASC';
  614. break;
  615. default:
  616. $sort_order = 'DESC';
  617. }
  618. }
  619. else if( isset($HTTP_POST_VARS['sort_order']) )
  620. {
  621. switch ($HTTP_POST_VARS['sort_order'])
  622. {
  623. case 'ASC':
  624. $sort_order = 'ASC';
  625. break;
  626. default:
  627. $sort_order = 'DESC';
  628. }
  629. }
  630. else
  631. {
  632. $sort_order = 'ASC';
  633. }
  634.  
  635. if ($total_comments > 0)
  636. {
  637. $limit_sql = ($start == 0) ? $comments_per_page : $start .','. $comments_per_page;
  638.  
  639. $sql = "SELECT c.*, u.user_id, u.username
  640. FROM ". ALBUM_COMMENT_TABLE ." AS c
  641. LEFT JOIN ". USERS_TABLE ." AS u ON c.comment_user_id = u.user_id
  642. WHERE c.comment_pic_id = '$pic_id'
  643. ORDER BY c.comment_id $sort_order
  644. LIMIT $limit_sql";
  645.  
  646. if( !$result = $db->sql_query($sql) )
  647. {
  648. message_die(GENERAL_ERROR, 'Could not obtain comments information from the database', '', __LINE__, __FILE__, $sql);
  649. }
  650.  
  651. $commentrow = array();
  652.  
  653. while( $row = $db->sql_fetchrow($result) )
  654. {
  655. $commentrow[] = $row;
  656. }
  657.  
  658. for ($i = 0; $i < count($commentrow); $i++)
  659. {
  660. if( ($commentrow[$i]['user_id'] == ALBUM_GUEST) or ($commentrow[$i]['username'] == '') )
  661. {
  662. $poster = ($commentrow[$i]['comment_username'] == '') ? $lang['Guest'] : $commentrow[$i]['comment_username'];
  663. }
  664. else
  665. {
  666. $poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $commentrow[$i]['user_id']) .'">'. $commentrow[$i]['username'] .'</a>';
  667. }
  668.  
  669. if ($commentrow[$i]['comment_edit_count'] > 0)
  670. {
  671. $sql = "SELECT c.comment_id, c.comment_edit_user_id, u.user_id, u.username
  672. FROM ". ALBUM_COMMENT_TABLE ." AS c
  673. LEFT JOIN ". USERS_TABLE ." AS u ON c.comment_edit_user_id = u.user_id
  674. WHERE c.comment_id = '".$commentrow[$i]['comment_id']."'
  675. LIMIT 1";
  676.  
  677. if( !$result = $db->sql_query($sql) )
  678. {
  679. message_die(GENERAL_ERROR, 'Could not obtain last edit information from the database', '', __LINE__, __FILE__, $sql);
  680. }
  681.  
  682. $lastedit_row = $db->sql_fetchrow($result);
  683.  
  684. $edit_info = ($commentrow[$i]['comment_edit_count'] == 1) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
  685.  
  686. $edit_info = '<br /><br />&raquo;&nbsp;'. sprintf($edit_info, $lastedit_row['username'], create_date($board_config['default_dateformat'], $commentrow[$i]['comment_edit_time'], $board_config['board_timezone']), $commentrow[$i]['comment_edit_count']) .'<br />';
  687. }
  688. else
  689. {
  690. $edit_info = '';
  691. }
  692. $commentrow[$i]['comment_text'] = smilies_pass($commentrow[$i]['comment_text']);
  693. $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
  694.  
  695. $template->assign_block_vars('commentrow', array(
  696. 'ID' => $commentrow[$i]['comment_id'],
  697. 'ROW_CLASS' => $row_class,
  698. 'POSTER' => $poster,
  699. 'TIME' => create_date($board_config['default_dateformat'], $commentrow[$i]['comment_time'], $board_config['board_timezone']),
  700. 'IP' => ($userdata['user_level'] == ADMIN) ? '<br/>' . $lang['IP_Address'] . ': ' . decode_ip($commentrow[$i]['comment_user_ip']) : '',
  701. 'TEXT' => nl2br($commentrow[$i]['comment_text']),
  702. 'EDIT_INFO' => $edit_info,
  703. 'EDIT' => ( ( $auth_data['edit'] and ($commentrow[$i]['comment_user_id'] == $userdata['user_id']) ) or ($auth_data['moderator'] and ($thiscat['cat_edit_level'] != ALBUM_ADMIN) ) or ($userdata['user_level'] == ADMIN) ) ? '<a href="'. append_sid("album.$phpEx?action=comment_edit&amp;comment_id=". $commentrow[$i]['comment_id']) .'">ред</a>|':'',
  704. 'DELETE' => ( ( $auth_data['delete'] and ($commentrow[$i]['comment_user_id'] == $userdata['user_id']) ) or ($auth_data['moderator'] and ($thiscat['cat_delete_level'] != ALBUM_ADMIN) ) or ($userdata['user_level'] == ADMIN) ) ? '<a href="'. append_sid("album.$phpEx?action=comment_delete&amp;comment_id=". $commentrow[$i]['comment_id']) .'">уд</a>':''
  705. )
  706. );
  707. }
  708.  
  709. $template->assign_block_vars('switch_comment', array());
  710.  
  711. $template->assign_vars(array(
  712. 'PAGINATION' => generate_pagination(append_sid("album.$phpEx?action=comment&amp;pic_id=$pic_id&amp;sort_order=$sort_order"), $total_comments, $comments_per_page, $start),
  713. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $comments_per_page ) + 1 ), ceil( $total_comments / $comments_per_page ))
  714. )
  715. );
  716. }
  717.  
  718. $page_title = 'Галерея сайта';
  719. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  720.  
  721. $template->set_filenames(array(
  722. 'body' => 'album_comment_body.tpl')
  723. );
  724.  
  725. if( ($thispic['pic_user_id'] == ALBUM_GUEST) or ($thispic['username'] == '') )
  726. {
  727. $poster = ($thispic['pic_username'] == '') ? $lang['Guest'] : $thispic['pic_username'];
  728. }
  729. else
  730. {
  731. $poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $thispic['user_id']) .'">'. $thispic['username'] .'</a>';
  732. }
  733.  
  734. if ($auth_data['comment'] == 1)
  735. {
  736. $template->assign_block_vars('switch_comment_post', array());
  737.  
  738. if( !$userdata['session_logged_in'] )
  739. {
  740. $template->assign_block_vars('switch_comment_post.logout', array());
  741. }
  742. }
  743.  
  744. $template->assign_vars(array(
  745. 'CAT_TITLE' => $thiscat['cat_title'],
  746. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  747. 'U_THUMBNAIL' => append_sid("album.$phpEx?action=thumbnail&amp;pic_id=$pic_id"),
  748. 'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=$pic_id") : append_sid("album.$phpEx?action=page&amp;pic_id=$pic_id"),
  749. 'PIC_TITLE' => $thispic['pic_title'],
  750. 'PIC_DESC' => nl2br($thispic['pic_desc']),
  751. 'POSTER' => $poster,
  752. 'PIC_TIME' => create_date($board_config['default_dateformat'], $thispic['pic_time'], $board_config['board_timezone']),
  753. 'PIC_VIEW' => $thispic['pic_view_count'],
  754. 'PIC_COMMENTS' => $total_comments,
  755. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  756. 'L_PIC_TITLE' => $lang['Pic_Title'],
  757. 'L_PIC_DESC' => $lang['Pic_Desc'],
  758. 'L_POSTER' => $lang['Poster'],
  759. 'L_POSTED' => $lang['Posted'],
  760. 'L_VIEW' => $lang['View'],
  761. 'L_COMMENTS' => $lang['Comments'],
  762. 'L_POST_YOUR_COMMENT' => $lang['Post_your_comment'],
  763. 'L_MESSAGE' => $lang['Message'],
  764. 'L_USERNAME' => $lang['Username'],
  765. 'L_COMMENT_NO_TEXT' => $lang['Comment_no_text'],
  766. 'L_COMMENT_TOO_LONG' => $lang['Comment_too_long'],
  767. 'L_MAX_LENGTH' => $lang['Max_length'],
  768. 'S_MAX_LENGTH' => $album_config['desc_length'],
  769. 'L_ORDER' => $lang['Order'],
  770. 'L_SORT' => $lang['Sort'],
  771. 'L_ASC' => $lang['Sort_Ascending'],
  772. 'L_DESC' => $lang['Sort_Descending'],
  773. 'SORT_ASC' => ($sort_order == 'ASC') ? 'selected="selected"' : '',
  774. 'SORT_DESC' => ($sort_order == 'DESC') ? 'selected="selected"' : '',
  775. 'L_SUBMIT' => $lang['Submit'],
  776. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=comment&amp;pic_id=$pic_id")
  777. )
  778. );
  779.  
  780. $template->pparse('body');
  781.  
  782. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  783. }
  784. else
  785. {
  786. if ($auth_data['comment'] == 0)
  787. {
  788. if (!$userdata['session_logged_in'])
  789. {
  790. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=comment&pic_id=$pic_id"));
  791. }
  792. else
  793. {
  794. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  795. }
  796. }
  797.  
  798. $comment_text = str_replace("\'", "''", htmlspecialchars(substr(trim($HTTP_POST_VARS['comment']), 0, $album_config['desc_length'])));
  799. $comment_username = (!$userdata['session_logged_in']) ? str_replace("\'", "''", substr(htmlspecialchars(trim($HTTP_POST_VARS['comment_username'])), 0, 32)) : str_replace("'", "''", htmlspecialchars(trim($userdata['username'])));
  800.  
  801. if( empty($comment_text) )
  802. {
  803. message_die(GENERAL_ERROR, $lang['Comment_no_text']);
  804. }
  805.  
  806. if( ($thispic['pic_lock'] == 1) and (!$auth_data['moderator']) )
  807. {
  808. message_die(GENERAL_ERROR, $lang['Pic_Locked']);
  809. }
  810.  
  811. if (!$userdata['session_logged_in'])
  812. {
  813. if ($comment_username != '')
  814. {
  815. $result = validate_username($comment_username);
  816. if ( $result['error'] )
  817. {
  818. message_die(GENERAL_MESSAGE, $result['error_msg']);
  819. }
  820. }
  821. }
  822.  
  823. $comment_time = time();
  824. $comment_user_id = $userdata['user_id'];
  825. $comment_user_ip = $userdata['session_ip'];
  826.  
  827. $sql = "SELECT MAX(comment_id) AS max
  828. FROM ". ALBUM_COMMENT_TABLE;
  829.  
  830. if( !$result = $db->sql_query($sql) )
  831. {
  832. message_die(GENERAL_ERROR, 'Could not found comment_id', '', __LINE__, __FILE__, $sql);
  833. }
  834.  
  835. $row = $db->sql_fetchrow($result);
  836.  
  837. $comment_id = $row['max'] + 1;
  838.  
  839. $sql = "INSERT INTO ". ALBUM_COMMENT_TABLE ." (comment_id, comment_pic_id, comment_user_id, comment_username, comment_user_ip, comment_time, comment_text)
  840. VALUES ('$comment_id', '$pic_id', '$comment_user_id', '$comment_username', '$comment_user_ip', '$comment_time', '$comment_text')";
  841. if( !$result = $db->sql_query($sql) )
  842. {
  843. message_die(GENERAL_ERROR, 'Could not insert new entry', '', __LINE__, __FILE__, $sql);
  844. }
  845.  
  846. $template->assign_vars(array(
  847. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=comment&amp;comment_id=$comment_id") . '#'.$comment_id.'">')
  848. );
  849.  
  850. $message = $lang['Stored'] . "<br /><br />" . sprintf($lang['Click_view_message'], "<a href=\"" . append_sid("album.$phpEx?action=comment&amp;comment_id=$comment_id") . "#$comment_id\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  851.  
  852. message_die(GENERAL_MESSAGE, $message);
  853. }
  854.  
  855. } elseif ( $action == 'comment_delete' ) {
  856.  
  857. if( $album_config['comment'] == 0 )
  858. {
  859. message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
  860. }
  861.  
  862. if( isset($HTTP_GET_VARS['comment_id']) )
  863. {
  864. $comment_id = intval($HTTP_GET_VARS['comment_id']);
  865. }
  866. else if( isset($HTTP_POST_VARS['comment_id']) )
  867. {
  868. $comment_id = intval($HTTP_POST_VARS['comment_id']);
  869. }
  870. else
  871. {
  872. message_die(GENERAL_ERROR, 'No comment_id specified');
  873. }
  874.  
  875. $sql = "SELECT *
  876. FROM ". ALBUM_COMMENT_TABLE ."
  877. WHERE comment_id = '$comment_id'";
  878.  
  879. if( !($result = $db->sql_query($sql)) )
  880. {
  881. message_die(GENERAL_ERROR, 'Could not query this comment information', '', __LINE__, __FILE__, $sql);
  882. }
  883.  
  884. $thiscomment = $db->sql_fetchrow($result);
  885.  
  886. if( empty($thiscomment) )
  887. {
  888. message_die(GENERAL_ERROR, 'This comment does not exist');
  889. }
  890.  
  891. $sql = "SELECT comment_id, comment_pic_id
  892. FROM ". ALBUM_COMMENT_TABLE ."
  893. WHERE comment_id = '$comment_id'";
  894.  
  895. if( !($result = $db->sql_query($sql)) )
  896. {
  897. message_die(GENERAL_ERROR, 'Could not query comment and pic information', '', __LINE__, __FILE__, $sql);
  898. }
  899.  
  900. $row = $db->sql_fetchrow($result);
  901.  
  902. if( empty($row) )
  903. {
  904. message_die(GENERAL_ERROR, 'This comment does not exist');
  905. }
  906.  
  907. $pic_id = $row['comment_pic_id'];
  908.  
  909. $sql = "SELECT p.*, u.user_id, u.username, COUNT(c.comment_id) as comments_count
  910. FROM ". ALBUM_TABLE ." AS p
  911. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  912. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  913. WHERE pic_id = '$pic_id'
  914. GROUP BY p.pic_id
  915. LIMIT 1";
  916. if( !($result = $db->sql_query($sql)) )
  917. {
  918. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  919. }
  920. $thispic = $db->sql_fetchrow($result);
  921.  
  922. $cat_id = $thispic['pic_cat_id'];
  923. $user_id = $thispic['pic_user_id'];
  924.  
  925. $total_comments = $thispic['comments_count'];
  926. $comments_per_page = $board_config['posts_per_page'];
  927.  
  928. $pic_filename = $thispic['pic_filename'];
  929. $pic_thumbnail = $thispic['pic_thumbnail'];
  930.  
  931. if( empty($thispic) )
  932. {
  933. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  934. }
  935.  
  936. if ($cat_id != PERSONAL_GALLERY)
  937. {
  938. $sql = "SELECT *
  939. FROM ". ALBUM_CAT_TABLE ."
  940. WHERE cat_id = '$cat_id'";
  941. if( !($result = $db->sql_query($sql)) )
  942. {
  943. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  944. }
  945.  
  946. $thiscat = $db->sql_fetchrow($result);
  947. }
  948. else
  949. {
  950. $thiscat = init_personal_gallery_cat($user_id);
  951. }
  952.  
  953. if (empty($thiscat))
  954. {
  955. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  956. }
  957.  
  958. $album_user_access = album_user_access($thispic['pic_cat_id'], $thiscat, 0, 0, 0, 1, 0, 1);
  959.  
  960. if( ($album_user_access['comment'] == 0) or ($album_user_access['delete'] == 0) )
  961. {
  962. if (!$userdata['session_logged_in'])
  963. {
  964. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=comment_delete&comment_id=$comment_id"));
  965. }
  966. else
  967. {
  968. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  969. }
  970. }
  971. else
  972. {
  973. if( (!$album_user_access['moderator']) or ($userdata['user_level'] != ADMIN) )
  974. {
  975. if ($thiscomment['comment_user_id'] != $userdata['user_id'])
  976. {
  977. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  978. }
  979. }
  980. }
  981.  
  982. if( !isset($HTTP_POST_VARS['confirm']) )
  983. {
  984. if( isset($HTTP_POST_VARS['cancel']) )
  985. {
  986. redirect(append_sid("album.$phpEx?action=comment&comment_id=$comment_id"));
  987. exit;
  988. }
  989.  
  990. $page_title = 'Галерея сайта';
  991. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  992.  
  993. $template->set_filenames(array(
  994. 'body' => 'confirm_body.tpl')
  995. );
  996.  
  997. $template->assign_vars(array(
  998. 'MESSAGE_TITLE' => $lang['Confirm'],
  999.  
  1000. 'MESSAGE_TEXT' => $lang['Comment_delete_confirm'],
  1001.  
  1002. 'L_NO' => $lang['No'],
  1003. 'L_YES' => $lang['Yes'],
  1004.  
  1005. 'S_CONFIRM_ACTION' => append_sid("album.$phpEx?action=comment_delete&amp;comment_id=$comment_id"),
  1006. )
  1007. );
  1008.  
  1009. $template->pparse('body');
  1010.  
  1011. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1012. }
  1013. else
  1014. {
  1015. $sql = "DELETE
  1016. FROM ". ALBUM_COMMENT_TABLE ."
  1017. WHERE comment_id = '$comment_id'";
  1018.  
  1019. if( !$result = $db->sql_query($sql) )
  1020. {
  1021. message_die(GENERAL_ERROR, 'Could not delete this comment', '', __LINE__, __FILE__, $sql);
  1022. }
  1023.  
  1024. $message = $lang['Deleted'];
  1025.  
  1026. if ($cat_id != PERSONAL_GALLERY)
  1027. {
  1028. $template->assign_vars(array(
  1029. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . '">')
  1030. );
  1031.  
  1032. $message .= "<br /><br />" . sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>");
  1033. }
  1034. else
  1035. {
  1036. $template->assign_vars(array(
  1037. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=personal&amp;user_id=$user_id") . '">')
  1038. );
  1039.  
  1040. $message .= "<br /><br />" . sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal&amp;user_id=$user_id") . "\">", "</a>");
  1041. }
  1042.  
  1043. $message .= "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  1044.  
  1045. message_die(GENERAL_MESSAGE, $message);
  1046. }
  1047.  
  1048. } elseif ( $action == 'comment_edit' ) {
  1049.  
  1050. if( $album_config['comment'] == 0 )
  1051. {
  1052. message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
  1053. }
  1054.  
  1055. if( isset($HTTP_GET_VARS['comment_id']) )
  1056. {
  1057. $comment_id = intval($HTTP_GET_VARS['comment_id']);
  1058. }
  1059. else if( isset($HTTP_POST_VARS['comment_id']) )
  1060. {
  1061. $comment_id = intval($HTTP_POST_VARS['comment_id']);
  1062. }
  1063. else
  1064. {
  1065. message_die(GENERAL_ERROR, 'No comment_id specified');
  1066. }
  1067.  
  1068. $sql = "SELECT *
  1069. FROM ". ALBUM_COMMENT_TABLE ."
  1070. WHERE comment_id = '$comment_id'";
  1071.  
  1072. if( !($result = $db->sql_query($sql)) )
  1073. {
  1074. message_die(GENERAL_ERROR, 'Could not query this comment information', '', __LINE__, __FILE__, $sql);
  1075. }
  1076.  
  1077. $thiscomment = $db->sql_fetchrow($result);
  1078.  
  1079. if( empty($thiscomment) )
  1080. {
  1081. message_die(GENERAL_ERROR, 'This comment does not exist');
  1082. }
  1083.  
  1084. $sql = "SELECT comment_id, comment_pic_id
  1085. FROM ". ALBUM_COMMENT_TABLE ."
  1086. WHERE comment_id = '$comment_id'";
  1087.  
  1088. if( !($result = $db->sql_query($sql)) )
  1089. {
  1090. message_die(GENERAL_ERROR, 'Could not query comment and pic information', '', __LINE__, __FILE__, $sql);
  1091. }
  1092.  
  1093. $row = $db->sql_fetchrow($result);
  1094.  
  1095. $pic_id = $row['comment_pic_id'];
  1096.  
  1097. $sql = "SELECT p.*, u.user_id, u.username, COUNT(c.comment_id) as comments_count
  1098. FROM ". ALBUM_TABLE ." AS p
  1099. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  1100. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  1101. WHERE pic_id = '$pic_id'
  1102. GROUP BY p.pic_id
  1103. LIMIT 1";
  1104. if( !($result = $db->sql_query($sql)) )
  1105. {
  1106. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  1107. }
  1108. $thispic = $db->sql_fetchrow($result);
  1109.  
  1110. $cat_id = $thispic['pic_cat_id'];
  1111. $user_id = $thispic['pic_user_id'];
  1112.  
  1113. $total_comments = $thispic['comments_count'];
  1114. $comments_per_page = $board_config['posts_per_page'];
  1115.  
  1116. $pic_filename = $thispic['pic_filename'];
  1117. $pic_thumbnail = $thispic['pic_thumbnail'];
  1118.  
  1119. if( empty($thispic) )
  1120. {
  1121. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  1122. }
  1123.  
  1124. if ($cat_id != PERSONAL_GALLERY)
  1125. {
  1126. $sql = "SELECT *
  1127. FROM ". ALBUM_CAT_TABLE ."
  1128. WHERE cat_id = '$cat_id'";
  1129. if( !($result = $db->sql_query($sql)) )
  1130. {
  1131. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  1132. }
  1133.  
  1134. $thiscat = $db->sql_fetchrow($result);
  1135. }
  1136. else
  1137. {
  1138. $thiscat = init_personal_gallery_cat($user_id);
  1139. }
  1140.  
  1141. if (empty($thiscat))
  1142. {
  1143. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  1144. }
  1145.  
  1146. $album_user_access = album_user_access($thispic['pic_cat_id'], $thiscat, 0, 0, 0, 1, 1, 0);
  1147.  
  1148. if( ($album_user_access['comment'] == 0) or ($album_user_access['edit'] == 0) )
  1149. {
  1150. if (!$userdata['session_logged_in'])
  1151. {
  1152. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=comment_edit&comment_id=$comment_id"));
  1153. }
  1154. else
  1155. {
  1156. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1157. }
  1158. }
  1159. else
  1160. {
  1161. if( (!$album_user_access['moderator']) or ($userdata['user_level'] != ADMIN) )
  1162. {
  1163. if ($thiscomment['comment_user_id'] != $userdata['user_id'])
  1164. {
  1165. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1166. }
  1167. }
  1168. }
  1169.  
  1170. if( !isset($HTTP_POST_VARS['comment']) )
  1171. {
  1172. if( ($thispic['pic_user_id'] == ALBUM_GUEST) or ($thispic['username'] == '') )
  1173. {
  1174. $poster = ($thispic['pic_username'] == '') ? $lang['Guest'] : $thispic['pic_username'];
  1175. }
  1176. else
  1177. {
  1178. $poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $thispic['user_id']) .'">'. $thispic['username'] .'</a>';
  1179. }
  1180.  
  1181. $page_title = 'Галерея сайта';
  1182. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1183.  
  1184. $template->set_filenames(array(
  1185. 'body' => 'album_comment_body.tpl')
  1186. );
  1187.  
  1188. $template->assign_block_vars('switch_comment_post', array());
  1189.  
  1190. $template->assign_vars(array(
  1191. 'CAT_TITLE' => $thiscat['cat_title'],
  1192. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  1193.  
  1194. 'U_THUMBNAIL' => append_sid("album.$phpEx?action=thumbnail&amp;pic_id=$pic_id"),
  1195. 'U_PIC' => append_sid("album.$phpEx?action=pic&amp;pic_id=$pic_id"),
  1196.  
  1197. 'PIC_TITLE' => $thispic['pic_title'],
  1198. 'PIC_DESC' => nl2br($thispic['pic_desc']),
  1199. 'POSTER' => $poster,
  1200. 'PIC_TIME' => create_date($board_config['default_dateformat'], $thispic['pic_time'], $board_config['board_timezone']),
  1201. 'PIC_VIEW' => $thispic['pic_view_count'],
  1202. 'PIC_COMMENTS' => $total_comments,
  1203. 'S_MESSAGE' => $thiscomment['comment_text'],
  1204.  
  1205. 'L_PIC_TITLE' => $lang['Pic_Title'],
  1206. 'L_PIC_DESC' => $lang['Pic_Desc'],
  1207. 'L_POSTER' => $lang['Poster'],
  1208. 'L_POSTED' => $lang['Posted'],
  1209. 'L_VIEW' => $lang['View'],
  1210. 'L_COMMENTS' => $lang['Comments'],
  1211.  
  1212. 'L_POST_YOUR_COMMENT' => $lang['Post_your_comment'],
  1213. 'L_MESSAGE' => $lang['Message'],
  1214. 'L_USERNAME' => $lang['Username'],
  1215. 'L_COMMENT_NO_TEXT' => $lang['Comment_no_text'],
  1216. 'L_COMMENT_TOO_LONG' => $lang['Comment_too_long'],
  1217. 'L_MAX_LENGTH' => $lang['Max_length'],
  1218. 'S_MAX_LENGTH' => $album_config['desc_length'],
  1219.  
  1220. 'L_SUBMIT' => $lang['Submit'],
  1221.  
  1222. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=comment_edit&amp;comment_id=$comment_id")
  1223. )
  1224. );
  1225.  
  1226. $template->pparse('body');
  1227.  
  1228. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1229. }
  1230. else
  1231. {
  1232. $comment_text = str_replace("\'", "''", htmlspecialchars(substr(trim($HTTP_POST_VARS['comment']), 0, $album_config['desc_length'])));
  1233.  
  1234. if( empty($comment_text) )
  1235. {
  1236. message_die(GENERAL_ERROR, $lang['Comment_no_text']);
  1237. }
  1238.  
  1239. $comment_edit_time = time();
  1240. $comment_edit_user_id = $userdata['user_id'];
  1241.  
  1242. $sql = "UPDATE ". ALBUM_COMMENT_TABLE ."
  1243. SET comment_text = '$comment_text', comment_edit_time = '$comment_edit_time', comment_edit_count = comment_edit_count + 1, comment_edit_user_id = '$comment_edit_user_id'
  1244. WHERE comment_id = '$comment_id'";
  1245.  
  1246. if( !$result = $db->sql_query($sql) )
  1247. {
  1248. message_die(GENERAL_ERROR, 'Could not update comment data', '', __LINE__, __FILE__, $sql);
  1249. }
  1250.  
  1251. $template->assign_vars(array(
  1252. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=comment&amp;comment_id=$comment_id") . '#'.$comment_id.'">')
  1253. );
  1254.  
  1255. $message = $lang['Stored'] . "<br /><br />" . sprintf($lang['Click_view_message'], "<a href=\"" . append_sid("album.$phpEx?action=comment&amp;comment_id=$comment_id") . "#$comment_id\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  1256.  
  1257. message_die(GENERAL_MESSAGE, $message);
  1258. }
  1259.  
  1260. } elseif ( $action == 'delete' ) {
  1261.  
  1262. if( isset($HTTP_GET_VARS['pic_id']) )
  1263. {
  1264. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  1265. }
  1266. else if( isset($HTTP_POST_VARS['pic_id']) )
  1267. {
  1268. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  1269. }
  1270. else
  1271. {
  1272. message_die(GENERAL_ERROR, 'No pics specified');
  1273. }
  1274.  
  1275. $sql = "SELECT *
  1276. FROM ". ALBUM_TABLE ."
  1277. WHERE pic_id = '$pic_id'";
  1278. if( !($result = $db->sql_query($sql)) )
  1279. {
  1280. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  1281. }
  1282. $thispic = $db->sql_fetchrow($result);
  1283.  
  1284. $cat_id = $thispic['pic_cat_id'];
  1285. $user_id = $thispic['pic_user_id'];
  1286.  
  1287. $pic_filename = $thispic['pic_filename'];
  1288. $pic_thumbnail = $thispic['pic_thumbnail'];
  1289.  
  1290. if( empty($thispic) )
  1291. {
  1292. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  1293. }
  1294.  
  1295. if ($cat_id != PERSONAL_GALLERY)
  1296. {
  1297. $sql = "SELECT *
  1298. FROM ". ALBUM_CAT_TABLE ."
  1299. WHERE cat_id = '$cat_id'";
  1300. if( !($result = $db->sql_query($sql)) )
  1301. {
  1302. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  1303. }
  1304.  
  1305. $thiscat = $db->sql_fetchrow($result);
  1306. }
  1307. else
  1308. {
  1309. $thiscat = init_personal_gallery_cat($user_id);
  1310. }
  1311.  
  1312. if (empty($thiscat))
  1313. {
  1314. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  1315. }
  1316.  
  1317. $album_user_access = album_user_access($cat_id, $thiscat, 0, 0, 0, 0, 0, 1);
  1318.  
  1319. if ($album_user_access['delete'] == 0)
  1320. {
  1321. if (!$userdata['session_logged_in'])
  1322. {
  1323. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=delete&pic_id=$pic_id"));
  1324. }
  1325. else
  1326. {
  1327. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if( (!$album_user_access['moderator']) and ($userdata['user_level'] != ADMIN) )
  1333. {
  1334. if ($thispic['pic_user_id'] != $userdata['user_id'])
  1335. {
  1336. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1337. }
  1338. }
  1339. }
  1340.  
  1341. if( !isset($HTTP_POST_VARS['confirm']) )
  1342. {
  1343. if( isset($HTTP_POST_VARS['cancel']) )
  1344. {
  1345. redirect(append_sid("album.$phpEx?action=cat&cat_id=$cat_id"));
  1346. exit;
  1347. }
  1348.  
  1349. $page_title = 'Галерея сайта';
  1350. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1351.  
  1352. $template->set_filenames(array(
  1353. 'body' => 'confirm_body.tpl')
  1354. );
  1355.  
  1356. $template->assign_vars(array(
  1357. 'MESSAGE_TITLE' => $lang['Confirm'],
  1358.  
  1359. 'MESSAGE_TEXT' => $lang['Album_delete_confirm'],
  1360.  
  1361. 'L_NO' => $lang['No'],
  1362. 'L_YES' => $lang['Yes'],
  1363.  
  1364. 'S_CONFIRM_ACTION' => append_sid("album.$phpEx?action=delete&amp;pic_id=$pic_id"),
  1365. )
  1366. );
  1367.  
  1368. $template->pparse('body');
  1369.  
  1370. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1371. }
  1372. else
  1373. {
  1374. $sql = "DELETE FROM ". ALBUM_COMMENT_TABLE ."
  1375. WHERE comment_pic_id = '$pic_id'";
  1376. if( !$result = $db->sql_query($sql) )
  1377. {
  1378. message_die(GENERAL_ERROR, 'Could not delete related comments', '', __LINE__, __FILE__, $sql);
  1379. }
  1380.  
  1381. $sql = "DELETE FROM ". ALBUM_RATE_TABLE ."
  1382. WHERE rate_pic_id = '$pic_id'";
  1383. if( !$result = $db->sql_query($sql) )
  1384. {
  1385. message_die(GENERAL_ERROR, 'Could not delete related ratings', '', __LINE__, __FILE__, $sql);
  1386. }
  1387.  
  1388. if(($thispic['pic_thumbnail'] != '') and @file_exists(ALBUM_CACHE_PATH . $thispic['pic_thumbnail']))
  1389. {
  1390. @unlink(ALBUM_CACHE_PATH . $thispic['pic_thumbnail']);
  1391. }
  1392.  
  1393. @unlink(ALBUM_UPLOAD_PATH . $thispic['pic_filename']);
  1394.  
  1395. $sql = "DELETE FROM ". ALBUM_TABLE ."
  1396. WHERE pic_id = '$pic_id'";
  1397. if( !$result = $db->sql_query($sql) )
  1398. {
  1399. message_die(GENERAL_ERROR, 'Could not delete DB entry', '', __LINE__, __FILE__, $sql);
  1400. }
  1401.  
  1402. $message = $lang['Pics_deleted_successfully'];
  1403.  
  1404. if ($cat_id != PERSONAL_GALLERY)
  1405. {
  1406. $template->assign_vars(array(
  1407. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . '">')
  1408. );
  1409.  
  1410. $message .= "<br /><br />" . sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>");
  1411. }
  1412. else
  1413. {
  1414. $template->assign_vars(array(
  1415. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=personal") . '">')
  1416. );
  1417.  
  1418. $message .= "<br /><br />" . sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal") . "\">", "</a>");
  1419. }
  1420.  
  1421. $message .= "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  1422.  
  1423. message_die(GENERAL_MESSAGE, $message);
  1424.  
  1425. }
  1426.  
  1427. } elseif ( $action == 'edit' ) {
  1428.  
  1429. if( isset($HTTP_GET_VARS['pic_id']) )
  1430. {
  1431. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  1432. }
  1433. else if( isset($HTTP_POST_VARS['pic_id']) )
  1434. {
  1435. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  1436. }
  1437. else
  1438. {
  1439. message_die(GENERAL_ERROR, 'No pics specified');
  1440. }
  1441.  
  1442. $sql = "SELECT *
  1443. FROM ". ALBUM_TABLE ."
  1444. WHERE pic_id = '$pic_id'";
  1445. if( !($result = $db->sql_query($sql)) )
  1446. {
  1447. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  1448. }
  1449. $thispic = $db->sql_fetchrow($result);
  1450.  
  1451. $cat_id = $thispic['pic_cat_id'];
  1452. $user_id = $thispic['pic_user_id'];
  1453.  
  1454. $pic_filename = $thispic['pic_filename'];
  1455. $pic_thumbnail = $thispic['pic_thumbnail'];
  1456.  
  1457. if( empty($thispic) )
  1458. {
  1459. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  1460. }
  1461.  
  1462. if ($cat_id != PERSONAL_GALLERY)
  1463. {
  1464. $sql = "SELECT *
  1465. FROM ". ALBUM_CAT_TABLE ."
  1466. WHERE cat_id = '$cat_id'";
  1467. if( !($result = $db->sql_query($sql)) )
  1468. {
  1469. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  1470. }
  1471.  
  1472. $thiscat = $db->sql_fetchrow($result);
  1473. }
  1474. else
  1475. {
  1476. $thiscat = init_personal_gallery_cat($user_id);
  1477. }
  1478.  
  1479. if (empty($thiscat))
  1480. {
  1481. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  1482. }
  1483.  
  1484. $album_user_access = album_user_access($cat_id, $thiscat, 0, 0, 0, 0, 1, 0);
  1485.  
  1486. if ($album_user_access['edit'] == 0)
  1487. {
  1488. if (!$userdata['session_logged_in'])
  1489. {
  1490. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=edit&pic_id=$pic_id"));
  1491. }
  1492. else
  1493. {
  1494. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1495. }
  1496. }
  1497. else
  1498. {
  1499. if( (!$album_user_access['moderator']) and ($userdata['user_level'] != ADMIN) )
  1500. {
  1501. if ($thispic['pic_user_id'] != $userdata['user_id'])
  1502. {
  1503. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1504. }
  1505. }
  1506. }
  1507.  
  1508. if( !isset($HTTP_POST_VARS['pic_title']) )
  1509. {
  1510. $page_title = 'Галерея сайта';
  1511. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1512.  
  1513. $template->set_filenames(array(
  1514. 'body' => 'album_edit_body.tpl')
  1515. );
  1516.  
  1517. $template->assign_vars(array(
  1518. 'L_EDIT_PIC_INFO' => $lang['Edit_Pic_Info'],
  1519.  
  1520. 'CAT_TITLE' => $thiscat['cat_title'],
  1521. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  1522.  
  1523. 'L_PIC_TITLE' => $lang['Pic_Title'],
  1524. 'PIC_TITLE' => $thispic['pic_title'],
  1525. 'PIC_DESC' => $thispic['pic_desc'],
  1526.  
  1527. 'L_PIC_DESC' => $lang['Pic_Desc'],
  1528. 'L_PLAIN_TEXT_ONLY' => $lang['Plain_text_only'],
  1529. 'L_MAX_LENGTH' => $lang['Max_length'],
  1530.  
  1531. 'L_UPLOAD_NO_TITLE' => $lang['Upload_no_title'],
  1532. 'L_DESC_TOO_LONG' => $lang['Desc_too_long'],
  1533. 'S_PIC_DESC_MAX_LENGTH' => $album_config['desc_length'],
  1534.  
  1535. 'L_RESET' => $lang['Reset'],
  1536. 'L_SUBMIT' => $lang['Submit'],
  1537.  
  1538. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=edit&amp;pic_id=$pic_id"),
  1539. )
  1540. );
  1541. $template->pparse('body');
  1542.  
  1543. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1544. }
  1545. else
  1546. {
  1547. $pic_title = str_replace("\'", "''", htmlspecialchars(trim($HTTP_POST_VARS['pic_title'])));
  1548. $pic_desc = str_replace("\'", "''", htmlspecialchars(substr(trim($HTTP_POST_VARS['pic_desc']), 0, $album_config['desc_length'])));
  1549.  
  1550. if( empty($pic_title) )
  1551. {
  1552. message_die(GENERAL_ERROR, $lang['Missed_pic_title']);
  1553. }
  1554.  
  1555. $sql = "UPDATE ". ALBUM_TABLE ."
  1556. SET pic_title = '$pic_title', pic_desc= '$pic_desc'
  1557. WHERE pic_id = '$pic_id'";
  1558. if( !$result = $db->sql_query($sql) )
  1559. {
  1560. message_die(GENERAL_ERROR, 'Could not update pic information', '', __LINE__, __FILE__, $sql);
  1561. }
  1562.  
  1563. $message = $lang['Pics_updated_successfully'];
  1564.  
  1565. if ($cat_id != PERSONAL_GALLERY)
  1566. {
  1567. $template->assign_vars(array(
  1568. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . '">')
  1569. );
  1570.  
  1571. $message .= "<br /><br />" . sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>");
  1572. }
  1573. else
  1574. {
  1575. $template->assign_vars(array(
  1576. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=personal") . '">')
  1577. );
  1578.  
  1579. $message .= "<br /><br />" . sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal") . "\">", "</a>");
  1580. }
  1581.  
  1582. $message .= "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  1583.  
  1584. message_die(GENERAL_MESSAGE, $message);
  1585.  
  1586. }
  1587.  
  1588. } elseif ( $action == 'modcp' ) {
  1589.  
  1590. if( isset($HTTP_GET_VARS['pic_id']) )
  1591. {
  1592. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  1593. }
  1594. else
  1595. {
  1596. $pic_id = FALSE;
  1597. }
  1598.  
  1599. if( $pic_id != FALSE )
  1600. {
  1601. $sql = "SELECT *
  1602. FROM ". ALBUM_TABLE ."
  1603. WHERE pic_id = '$pic_id'";
  1604. if( !($result = $db->sql_query($sql)) )
  1605. {
  1606. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  1607. }
  1608. $thispic = $db->sql_fetchrow($result);
  1609. if( empty($thispic) )
  1610. {
  1611. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  1612. }
  1613. $cat_id = $thispic['pic_cat_id'];
  1614. $user_id = $thispic['pic_user_id'];
  1615. }
  1616. else
  1617. {
  1618. if( isset($HTTP_POST_VARS['cat_id']) )
  1619. {
  1620. $cat_id = intval($HTTP_POST_VARS['cat_id']);
  1621. }
  1622. else if( isset($HTTP_GET_VARS['cat_id']) )
  1623. {
  1624. $cat_id = intval($HTTP_GET_VARS['cat_id']);
  1625. }
  1626. else
  1627. {
  1628. message_die(GENERAL_ERROR, 'No categories specified');
  1629. }
  1630. }
  1631.  
  1632. if( ($cat_id == PERSONAL_GALLERY) and (($HTTP_GET_VARS['mode'] == 'lock') or ($HTTP_GET_VARS['mode'] == 'unlock')) )
  1633. {
  1634. $thiscat = init_personal_gallery_cat($user_id);
  1635. }
  1636. else
  1637. {
  1638. $sql = "SELECT *
  1639. FROM ". ALBUM_CAT_TABLE ."
  1640. WHERE cat_id = '$cat_id'";
  1641. if( !($result = $db->sql_query($sql)) )
  1642. {
  1643. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  1644. }
  1645.  
  1646. $thiscat = $db->sql_fetchrow($result);
  1647. }
  1648.  
  1649. if (empty($thiscat))
  1650. {
  1651. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  1652. }
  1653.  
  1654. $auth_data = album_user_access($cat_id, $thiscat, 0, 0, 0, 0, 0, 0);
  1655.  
  1656. if( isset($HTTP_POST_VARS['mode']) )
  1657. {
  1658. if( isset($HTTP_POST_VARS['move']) )
  1659. {
  1660. $mode = 'move';
  1661. }
  1662. else if( isset($HTTP_POST_VARS['lock']) )
  1663. {
  1664. $mode = 'lock';
  1665. }
  1666. else if( isset($HTTP_POST_VARS['unlock']) )
  1667. {
  1668. $mode = 'unlock';
  1669. }
  1670. else if( isset($HTTP_POST_VARS['delete']) )
  1671. {
  1672. $mode = 'delete';
  1673. }
  1674. else if( isset($HTTP_POST_VARS['approval']) )
  1675. {
  1676. $mode = 'approval';
  1677. }
  1678. else if( isset($HTTP_POST_VARS['unapproval']) )
  1679. {
  1680. $mode = 'unapproval';
  1681. }
  1682. else
  1683. {
  1684. $mode = '';
  1685. }
  1686. }
  1687. else if( isset($HTTP_GET_VARS['mode']) )
  1688. {
  1689. $mode = trim($HTTP_GET_VARS['mode']);
  1690. }
  1691. else
  1692. {
  1693. $mode = '';
  1694. }
  1695.  
  1696. if ($auth_data['moderator'] == 0)
  1697. {
  1698. if (!$userdata['session_logged_in'])
  1699. {
  1700. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=modcp&cat_id=$cat_id"));
  1701. }
  1702. else
  1703. {
  1704. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  1705. }
  1706. }
  1707.  
  1708. if ($mode == '')
  1709. {
  1710. if( isset($HTTP_GET_VARS['start']) )
  1711. {
  1712. $start = intval($HTTP_GET_VARS['start']);
  1713. }
  1714. else if( isset($HTTP_POST_VARS['start']) )
  1715. {
  1716. $start = intval($HTTP_POST_VARS['start']);
  1717. }
  1718. else
  1719. {
  1720. $start = 0;
  1721. }
  1722. $start = ($start < 0) ? 0 : $start;
  1723.  
  1724. if( isset($HTTP_GET_VARS['sort_method']) )
  1725. {
  1726. switch ($HTTP_GET_VARS['sort_method'])
  1727. {
  1728. case 'pic_title':
  1729. $sort_method = 'pic_title';
  1730. break;
  1731. case 'pic_user_id':
  1732. $sort_method = 'pic_user_id';
  1733. break;
  1734. case 'pic_view_count':
  1735. $sort_method = 'pic_view_count';
  1736. break;
  1737. case 'rating':
  1738. $sort_method = 'rating';
  1739. break;
  1740. case 'comments':
  1741. $sort_method = 'comments';
  1742. break;
  1743. case 'new_comment':
  1744. $sort_method = 'new_comment';
  1745. break;
  1746. default:
  1747. $sort_method = 'pic_time';
  1748. }
  1749. }
  1750. else if( isset($HTTP_POST_VARS['sort_method']) )
  1751. {
  1752. switch ($HTTP_POST_VARS['sort_method'])
  1753. {
  1754. case 'pic_title':
  1755. $sort_method = 'pic_title';
  1756. break;
  1757. case 'pic_user_id':
  1758. $sort_method = 'pic_user_id';
  1759. break;
  1760. case 'pic_view_count':
  1761. $sort_method = 'pic_view_count';
  1762. break;
  1763. case 'rating':
  1764. $sort_method = 'rating';
  1765. break;
  1766. case 'comments':
  1767. $sort_method = 'comments';
  1768. break;
  1769. case 'new_comment':
  1770. $sort_method = 'new_comment';
  1771. break;
  1772. default:
  1773. $sort_method = 'pic_time';
  1774. }
  1775. }
  1776. else
  1777. {
  1778. $sort_method = 'pic_time';
  1779. }
  1780.  
  1781. if( isset($HTTP_GET_VARS['sort_order']) )
  1782. {
  1783. switch ($HTTP_GET_VARS['sort_order'])
  1784. {
  1785. case 'ASC':
  1786. $sort_order = 'ASC';
  1787. break;
  1788. default:
  1789. $sort_order = 'DESC';
  1790. }
  1791. }
  1792. else if( isset($HTTP_POST_VARS['sort_order']) )
  1793. {
  1794. switch ($HTTP_POST_VARS['sort_order'])
  1795. {
  1796. case 'ASC':
  1797. $sort_order = 'ASC';
  1798. break;
  1799. default:
  1800. $sort_order = 'DESC';
  1801. }
  1802. }
  1803. else
  1804. {
  1805. $sort_order = 'DESC';
  1806. }
  1807.  
  1808. $sql = "SELECT COUNT(pic_id) AS count
  1809. FROM ". ALBUM_TABLE ."
  1810. WHERE pic_cat_id = '$cat_id'";
  1811. if( !($result = $db->sql_query($sql)) )
  1812. {
  1813. message_die(GENERAL_ERROR, 'Could not count pics in this category', '', __LINE__, __FILE__, $sql);
  1814. }
  1815. $row = $db->sql_fetchrow($result);
  1816.  
  1817. $total_pics = $row['count'];
  1818.  
  1819. $pics_per_page = $board_config['topics_per_page'];
  1820.  
  1821. if ($total_pics > 0)
  1822. {
  1823. $limit_sql = ($start == 0) ? $pics_per_page : $start .', '. $pics_per_page;
  1824.  
  1825. $pic_approval_sql = '';
  1826. if( ($userdata['user_level'] != ADMIN) and ($thiscat['cat_approval'] == ALBUM_ADMIN) )
  1827. {
  1828. $pic_approval_sql = 'AND p.pic_approval = 1';
  1829. }
  1830.  
  1831. $sql = "SELECT p.pic_id, p.pic_title, p.pic_user_id, p.pic_user_ip, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_view_count, p.pic_lock, p.pic_approval, u.user_id, u.username, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(c.comment_id) AS comments, MAX(c.comment_id) AS new_comment
  1832. FROM ". ALBUM_TABLE ." AS p
  1833. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  1834. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  1835. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  1836. WHERE p.pic_cat_id = '$cat_id' $pic_approval_sql
  1837. GROUP BY p.pic_id
  1838. ORDER BY $sort_method $sort_order
  1839. LIMIT $limit_sql";
  1840. if( !($result = $db->sql_query($sql)) )
  1841. {
  1842. message_die(GENERAL_ERROR, 'Could not query pics information', '', __LINE__, __FILE__, $sql);
  1843. }
  1844.  
  1845. $picrow = array();
  1846.  
  1847. while( $row = $db->sql_fetchrow($result) )
  1848. {
  1849. $picrow[] = $row;
  1850. }
  1851.  
  1852. for ($i = 0; $i <count($picrow); $i++)
  1853. {
  1854. if( ($picrow[$i]['user_id'] == ALBUM_GUEST) or ($picrow[$i]['username'] == '') )
  1855. {
  1856. $pic_poster = ($picrow[$i]['pic_username'] == '') ? $lang['Guest'] : $picrow[$i]['pic_username'];
  1857. }
  1858. else
  1859. {
  1860. $pic_poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $picrow[$i]['user_id']) .'">'. $picrow[$i]['username'] .'</a>';
  1861. }
  1862. $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
  1863.  
  1864. $template->assign_block_vars('picrow', array(
  1865. 'PIC_ID' => $picrow[$i]['pic_id'],
  1866. 'ROW_CLASS' => $row_class,
  1867. 'PIC_TITLE' => '<a href="'. append_sid("album.$phpEx?action=pic&amp;pic_id=". $picrow[$i]['pic_id']) .'" target="_blank">'. $picrow[$i]['pic_title'] .'</a>',
  1868. 'POSTER' => $pic_poster,
  1869. 'TIME' => create_date($board_config['default_dateformat'], $picrow[$i]['pic_time'], $board_config['board_timezone']),
  1870. 'RATING' => ($picrow[$i]['rating'] == 0) ? $lang['Not_rated'] : round($picrow[$i]['rating'], 2),
  1871. 'COMMENTS' => $picrow[$i]['comments'],
  1872. 'LOCK' => ($picrow[$i]['pic_lock'] == 0) ? '' : $lang['Locked'],
  1873. 'APPROVAL' => ($picrow[$i]['pic_approval'] == 0) ? $lang['Not_approved'] : $lang['Approved']
  1874. )
  1875. );
  1876. }
  1877.  
  1878. $template->assign_vars(array(
  1879. 'PAGINATION' => generate_pagination(append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id&amp;sort_method=$sort_method&amp;sort_order=$sort_order"), $total_pics, $pics_per_page, $start),
  1880. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $pics_per_page ) + 1 ), ceil( $total_pics / $pics_per_page ))
  1881. )
  1882. );
  1883. }
  1884. else
  1885. {
  1886. $template->assign_block_vars('no_pics', array());
  1887. }
  1888.  
  1889. $page_title = 'Галерея сайта';
  1890. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1891.  
  1892. $template->set_filenames(array(
  1893. 'body' => 'album_modcp_body.tpl')
  1894. );
  1895.  
  1896. $sort_rating_option = '';
  1897. $sort_comments_option = '';
  1898. if( $album_config['rate'] == 1 )
  1899. {
  1900. $sort_rating_option = '<option value="rating" ';
  1901. $sort_rating_option .= ($sort_method == 'rating') ? 'selected="selected"' : '';
  1902. $sort_rating_option .= '>' . $lang['Rating'] .'</option>';
  1903. }
  1904. if( $album_config['comment'] == 1 )
  1905. {
  1906. $sort_comments_option = '<option value="comments" ';
  1907. $sort_comments_option .= ($sort_method == 'comments') ? 'selected="selected"' : '';
  1908. $sort_comments_option .= '>' . $lang['Comments'] .'</option>';
  1909. $sort_new_comment_option = '<option value="new_comment" ';
  1910. $sort_new_comment_option .= ($sort_method == 'new_comment') ? 'selected="selected"' : '';
  1911. $sort_new_comment_option .= '>' . $lang['New_Comment'] .'</option>';
  1912. }
  1913.  
  1914. $template->assign_vars(array(
  1915. 'U_VIEW_CAT' => append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id"),
  1916. 'CAT_TITLE' => $thiscat['cat_title'],
  1917. 'L_CATEGORY' => $lang['Category'],
  1918. 'L_MODCP' => $lang['Mod_CP'],
  1919. 'L_NO_PICS' => $lang['No_Pics'],
  1920. 'L_VIEW' => $lang['View'],
  1921. 'L_POSTER' => $lang['Poster'],
  1922. 'L_POSTED' => $lang['Posted'],
  1923. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id"),
  1924. 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
  1925. 'L_ORDER' => $lang['Order'],
  1926. 'L_SORT' => $lang['Sort'],
  1927. 'L_TIME' => $lang['Time'],
  1928. 'L_PIC_TITLE' => $lang['Pic_Title'],
  1929. 'L_POSTER' => $lang['Poster'],
  1930. 'L_RATING' => $lang['Rating'],
  1931. 'L_COMMENTS' => $lang['Comments'],
  1932. 'L_STATUS' => $lang['Status'],
  1933. 'L_APPROVAL' => $lang['Approval'],
  1934. 'L_SELECT' => $lang['Select'],
  1935. 'L_DELETE' => $lang['Delete'],
  1936. 'L_MOVE' => $lang['Move'],
  1937. 'L_LOCK' => $lang['Lock'],
  1938. 'L_UNLOCK' => $lang['Unlock'],
  1939. 'DELETE_BUTTON' => ($auth_data['delete'] == 1) ? '<input type="submit" name="delete" value="'. $lang['Delete'] .'" />' : '',
  1940. 'APPROVAL_BUTTON' => ( ($userdata['user_level'] != ADMIN) and ($thiscat['cat_approval'] == ALBUM_ADMIN) ) ? '' : '<input type="submit" name="approval" value="'. $lang['Approve'] .'" />',
  1941. 'UNAPPROVAL_BUTTON' => ( ($userdata['user_level'] != ADMIN) and ($thiscat['cat_approval'] == ALBUM_ADMIN) ) ? '' : '<input type="submit" name="unapproval" value="'. $lang['Unapprove'] .'" />',
  1942. 'L_USERNAME' => $lang['Sort_Username'],
  1943. 'SORT_TIME' => ($sort_method == 'pic_time') ? 'selected="selected"' : '',
  1944. 'SORT_PIC_TITLE' => ($sort_method == 'pic_title') ? 'selected="selected"' : '',
  1945. 'SORT_USERNAME' => ($sort_method == 'pic_user_id') ? 'selected="selected"' : '',
  1946. 'SORT_VIEW' => ($sort_method == 'pic_view_count') ? 'selected="selected"' : '',
  1947. 'SORT_RATING_OPTION' => $sort_rating_option,
  1948. 'SORT_COMMENTS_OPTION' => $sort_comments_option,
  1949. 'SORT_NEW_COMMENT_OPTION' => $sort_new_comment_option,
  1950. 'L_ASC' => $lang['Sort_Ascending'],
  1951. 'L_DESC' => $lang['Sort_Descending'],
  1952. 'SORT_ASC' => ($sort_order == 'ASC') ? 'selected="selected"' : '',
  1953. 'SORT_DESC' => ($sort_order == 'DESC') ? 'selected="selected"' : ''
  1954. )
  1955. );
  1956.  
  1957. $template->pparse('body');
  1958.  
  1959. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1960. }
  1961. else
  1962. {
  1963. if ($mode == 'move')
  1964. {
  1965. if( !isset($HTTP_POST_VARS['target']) )
  1966. {
  1967. $pic_id_array = array();
  1968. if ($pic_id != FALSE)
  1969. {
  1970. $pic_id_array[] = $pic_id;
  1971. }
  1972. else
  1973. {
  1974. if( isset($HTTP_POST_VARS['pic_id']) )
  1975. {
  1976. $pic_id_array = $HTTP_POST_VARS['pic_id'];
  1977. if( !is_array($pic_id_array) )
  1978. {
  1979. message_die(GENERAL_ERROR, 'Invalid request');
  1980. }
  1981. }
  1982. else
  1983. {
  1984. message_die(GENERAL_ERROR, 'No pics specified');
  1985. }
  1986. }
  1987. for ($i = 0; $i < count($pic_id_array); $i++)
  1988. {
  1989. $template->assign_block_vars('pic_id_array', array(
  1990. 'VALUE' => $pic_id_array[$i])
  1991. );
  1992. }
  1993.  
  1994. $sql = "SELECT *
  1995. FROM ". ALBUM_CAT_TABLE ."
  1996. WHERE cat_id <> '$cat_id'
  1997. ORDER BY cat_order ASC";
  1998. if( !($result = $db->sql_query($sql)) )
  1999. {
  2000. message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
  2001. }
  2002.  
  2003. $catrows = array();
  2004.  
  2005. while( $row = $db->sql_fetchrow($result) )
  2006. {
  2007. $album_user_access = album_user_access($row['cat_id'], $row, 0, 1, 0, 0, 0, 0);
  2008.  
  2009. if ($album_user_access['upload'] == 1)
  2010. {
  2011. $catrows[] = $row;
  2012. }
  2013. }
  2014.  
  2015. if( count($catrows) == 0 )
  2016. {
  2017. message_die(GENERAL_MESSAGE, 'There is no more categories which you have permisson to move pics to');
  2018. }
  2019.  
  2020. $category_select = '<select name="target">';
  2021.  
  2022. for ($i = 0; $i < count($catrows); $i++)
  2023. {
  2024. $category_select .= '<option value="'. $catrows[$i]['cat_id'] .'">'. $catrows[$i]['cat_title'] .'</option>';
  2025. }
  2026.  
  2027. $category_select .= '</select>';
  2028.  
  2029. $page_title = 'Галерея сайта';
  2030. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  2031.  
  2032. $template->set_filenames(array(
  2033. 'body' => 'album_move_body.tpl')
  2034. );
  2035.  
  2036. $template->assign_vars(array(
  2037. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=modcp&amp;mode=move&amp;cat_id=$cat_id"),
  2038. 'L_MOVE' => $lang['Move'],
  2039. 'L_MOVE_TO_CATEGORY' => $lang['Move_to_Category'],
  2040. 'S_CATEGORY_SELECT' => $category_select)
  2041. );
  2042.  
  2043. $template->pparse('body');
  2044.  
  2045. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  2046. }
  2047. else
  2048. {
  2049. if( isset($HTTP_POST_VARS['pic_id']) )
  2050. {
  2051. $pic_id = $HTTP_POST_VARS['pic_id'];
  2052. if( is_array($pic_id) )
  2053. {
  2054. $pic_id_sql = implode(',', $pic_id);
  2055. }
  2056. else
  2057. {
  2058. message_die(GENERAL_ERROR, 'Invalid request');
  2059. }
  2060. }
  2061. else
  2062. {
  2063. message_die(GENERAL_ERROR, 'No pics specified');
  2064. }
  2065.  
  2066. $sql = "SELECT pic_id
  2067. FROM ". ALBUM_TABLE ."
  2068. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2069. if( !$result = $db->sql_query($sql) )
  2070. {
  2071. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2072. }
  2073. if( $db->sql_numrows($result) > 0 )
  2074. {
  2075. message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
  2076. }
  2077.  
  2078. $sql = "UPDATE ". ALBUM_TABLE ."
  2079. SET pic_cat_id = ". intval($HTTP_POST_VARS['target']) ."
  2080. WHERE pic_id IN ($pic_id_sql)";
  2081. if( !$result = $db->sql_query($sql) )
  2082. {
  2083. message_die(GENERAL_ERROR, 'Could not update album information', '', __LINE__, __FILE__, $sql);
  2084. }
  2085.  
  2086. $message = $lang['Pics_moved_successfully'] .'<br /><br />'. sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2087.  
  2088. message_die(GENERAL_MESSAGE, $message);
  2089. }
  2090. }
  2091. else if ($mode == 'lock')
  2092. {
  2093. if ($pic_id != FALSE)
  2094. {
  2095. $pic_id_sql = $pic_id;
  2096. }
  2097. else
  2098. {
  2099. if( isset($HTTP_POST_VARS['pic_id']) )
  2100. {
  2101. $pic_id = $HTTP_POST_VARS['pic_id'];
  2102. if( is_array($pic_id) )
  2103. {
  2104. $pic_id_sql = implode(',', $pic_id);
  2105. }
  2106. else
  2107. {
  2108. message_die(GENERAL_ERROR, 'Invalid request');
  2109. }
  2110. }
  2111. else
  2112. {
  2113. message_die(GENERAL_ERROR, 'No pics specified');
  2114. }
  2115. }
  2116.  
  2117. $sql = "SELECT pic_id
  2118. FROM ". ALBUM_TABLE ."
  2119. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2120. if( !$result = $db->sql_query($sql) )
  2121. {
  2122. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2123. }
  2124. if( $db->sql_numrows($result) > 0 )
  2125. {
  2126. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2127. }
  2128.  
  2129. $sql = "UPDATE ". ALBUM_TABLE ."
  2130. SET pic_lock = 1
  2131. WHERE pic_id IN ($pic_id_sql)";
  2132. if( !$result = $db->sql_query($sql) )
  2133. {
  2134. message_die(GENERAL_ERROR, 'Could not update album information', '', __LINE__, __FILE__, $sql);
  2135. }
  2136.  
  2137. $message = $lang['Pics_locked_successfully'] .'<br /><br />';
  2138.  
  2139. if ($cat_id != PERSONAL_GALLERY)
  2140. {
  2141. $message .= sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />";
  2142. }
  2143. else
  2144. {
  2145. $message .= sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal") . "\">", "</a>");
  2146. }
  2147.  
  2148. $message .= '<br /><br />' . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2149.  
  2150. message_die(GENERAL_MESSAGE, $message);
  2151. }
  2152. else if ($mode == 'unlock')
  2153. {
  2154. if ($pic_id != FALSE)
  2155. {
  2156. $pic_id_sql = $pic_id;
  2157. }
  2158. else
  2159. {
  2160. if( isset($HTTP_POST_VARS['pic_id']) )
  2161. {
  2162. $pic_id = $HTTP_POST_VARS['pic_id'];
  2163. if( is_array($pic_id) )
  2164. {
  2165. $pic_id_sql = implode(',', $pic_id);
  2166. }
  2167. else
  2168. {
  2169. message_die(GENERAL_ERROR, 'Invalid request');
  2170. }
  2171. }
  2172. else
  2173. {
  2174. message_die(GENERAL_ERROR, 'No pics specified');
  2175. }
  2176. }
  2177.  
  2178. $sql = "SELECT pic_id
  2179. FROM ". ALBUM_TABLE ."
  2180. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2181. if( !$result = $db->sql_query($sql) )
  2182. {
  2183. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2184. }
  2185. if( $db->sql_numrows($result) > 0 )
  2186. {
  2187. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2188. }
  2189.  
  2190. $sql = "UPDATE ". ALBUM_TABLE ."
  2191. SET pic_lock = 0
  2192. WHERE pic_id IN ($pic_id_sql)";
  2193. if( !$result = $db->sql_query($sql) )
  2194. {
  2195. message_die(GENERAL_ERROR, 'Could not update album information', '', __LINE__, __FILE__, $sql);
  2196. }
  2197.  
  2198. $message = $lang['Pics_unlocked_successfully'] .'<br /><br />';
  2199.  
  2200. if ($cat_id != PERSONAL_GALLERY)
  2201. {
  2202. $message .= sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />";
  2203. }
  2204. else
  2205. {
  2206. $message .= sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal") . "\">", "</a>");
  2207. }
  2208.  
  2209. $message .= '<br /><br />' . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2210.  
  2211. message_die(GENERAL_MESSAGE, $message);
  2212. }
  2213. else if ($mode == 'approval')
  2214. {
  2215. if ($pic_id != FALSE)
  2216. {
  2217. $pic_id_sql = $pic_id;
  2218. }
  2219. else
  2220. {
  2221. if( isset($HTTP_POST_VARS['pic_id']) )
  2222. {
  2223. $pic_id = $HTTP_POST_VARS['pic_id'];
  2224. if( is_array($pic_id) )
  2225. {
  2226. $pic_id_sql = implode(',', $pic_id);
  2227. }
  2228. else
  2229. {
  2230. message_die(GENERAL_ERROR, 'Invalid request');
  2231. }
  2232. }
  2233. else
  2234. {
  2235. message_die(GENERAL_ERROR, 'No pics specified');
  2236. }
  2237. }
  2238.  
  2239. $sql = "SELECT pic_id
  2240. FROM ". ALBUM_TABLE ."
  2241. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2242. if( !$result = $db->sql_query($sql) )
  2243. {
  2244. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2245. }
  2246. if( $db->sql_numrows($result) > 0 )
  2247. {
  2248. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2249. }
  2250.  
  2251. $sql = "UPDATE ". ALBUM_TABLE ."
  2252. SET pic_approval = 1
  2253. WHERE pic_id IN ($pic_id_sql)";
  2254. if( !$result = $db->sql_query($sql) )
  2255. {
  2256. message_die(GENERAL_ERROR, 'Could not update album information', '', __LINE__, __FILE__, $sql);
  2257. }
  2258.  
  2259. $message = $lang['Pics_approved_successfully'] .'<br /><br />'. sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2260.  
  2261. message_die(GENERAL_MESSAGE, $message);
  2262. }
  2263. else if ($mode == 'unapproval')
  2264. {
  2265. if ($pic_id != FALSE)
  2266. {
  2267. $pic_id_sql = $pic_id;
  2268. }
  2269. else
  2270. {
  2271. if( isset($HTTP_POST_VARS['pic_id']) )
  2272. {
  2273. $pic_id = $HTTP_POST_VARS['pic_id'];
  2274. if( is_array($pic_id) )
  2275. {
  2276. $pic_id_sql = implode(',', $pic_id);
  2277. }
  2278. else
  2279. {
  2280. message_die(GENERAL_ERROR, 'Invalid request');
  2281. }
  2282. }
  2283. else
  2284. {
  2285. message_die(GENERAL_ERROR, 'No pics specified');
  2286. }
  2287. }
  2288.  
  2289. $sql = "SELECT pic_id
  2290. FROM ". ALBUM_TABLE ."
  2291. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2292. if( !$result = $db->sql_query($sql) )
  2293. {
  2294. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2295. }
  2296. if( $db->sql_numrows($result) > 0 )
  2297. {
  2298. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2299. }
  2300.  
  2301. $sql = "UPDATE ". ALBUM_TABLE ."
  2302. SET pic_approval = 0
  2303. WHERE pic_id IN ($pic_id_sql)";
  2304. if( !$result = $db->sql_query($sql) )
  2305. {
  2306. message_die(GENERAL_ERROR, 'Could not update album information', '', __LINE__, __FILE__, $sql);
  2307. }
  2308.  
  2309. $message = $lang['Pics_unapproved_successfully'] .'<br /><br />'. sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2310.  
  2311. message_die(GENERAL_MESSAGE, $message);
  2312. }
  2313. else if ($mode == 'delete')
  2314. {
  2315. if ($auth_data['delete'] == 0)
  2316. {
  2317. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2318. }
  2319.  
  2320. if( !isset($HTTP_POST_VARS['confirm']) )
  2321. {
  2322. $pic_id_array = array();
  2323. if ($pic_id != FALSE)
  2324. {
  2325. $pic_id_array[] = $pic_id;
  2326. }
  2327. else
  2328. {
  2329. if( isset($HTTP_POST_VARS['pic_id']) )
  2330. {
  2331. $pic_id_array = $HTTP_POST_VARS['pic_id'];
  2332. if( !is_array($pic_id_array) )
  2333. {
  2334. message_die(GENERAL_ERROR, 'Invalid request');
  2335. }
  2336. }
  2337. else
  2338. {
  2339. message_die(GENERAL_ERROR, 'No pics specified');
  2340. }
  2341. }
  2342.  
  2343. if ( isset($HTTP_POST_VARS['cancel']) )
  2344. {
  2345. $redirect = "album.$phpEx?action=modcp&cat_id=$cat_id";
  2346. redirect(append_sid($redirect, true));
  2347. }
  2348.  
  2349. $hidden_field = '';
  2350. for ($i = 0; $i < count($pic_id_array); $i++)
  2351. {
  2352. $hidden_field .= '<input name="pic_id[]" type="hidden" value="'. $pic_id_array[$i] .'" />' . "\n";
  2353. }
  2354.  
  2355. $page_title = 'Галерея сайта';
  2356. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  2357.  
  2358. $template->set_filenames(array(
  2359. 'body' => 'confirm_body.tpl')
  2360. );
  2361.  
  2362. $template->assign_vars(array(
  2363. 'MESSAGE_TITLE' => $lang['Confirm'],
  2364. 'MESSAGE_TEXT' => $lang['Album_delete_confirm'],
  2365. 'S_HIDDEN_FIELDS' => $hidden_field,
  2366. 'L_NO' => $lang['No'],
  2367. 'L_YES' => $lang['Yes'],
  2368. 'S_CONFIRM_ACTION' => append_sid("album.$phpEx?action=modcp&amp;mode=delete&amp;cat_id=$cat_id"),
  2369. )
  2370. );
  2371.  
  2372. $template->pparse('body');
  2373.  
  2374. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  2375. }
  2376. else
  2377. {
  2378. if( isset($HTTP_POST_VARS['pic_id']) )
  2379. {
  2380. $pic_id = $HTTP_POST_VARS['pic_id'];
  2381. if( is_array($pic_id) )
  2382. {
  2383. $pic_id_sql = implode(',', $pic_id);
  2384. }
  2385. else
  2386. {
  2387. message_die(GENERAL_ERROR, 'Invalid request');
  2388. }
  2389. }
  2390. else
  2391. {
  2392. message_die(GENERAL_ERROR, 'No pics specified');
  2393. }
  2394. $sql = "SELECT pic_id
  2395. FROM ". ALBUM_TABLE ."
  2396. WHERE pic_id IN ($pic_id_sql) AND pic_cat_id <> $cat_id";
  2397. if( !$result = $db->sql_query($sql) )
  2398. {
  2399. message_die(GENERAL_ERROR, 'Could not obtain album information', '', __LINE__, __FILE__, $sql);
  2400. }
  2401. if( $db->sql_numrows($result) > 0 )
  2402. {
  2403. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2404. }
  2405.  
  2406. $sql = "DELETE FROM ". ALBUM_COMMENT_TABLE ."
  2407. WHERE comment_pic_id IN ($pic_id_sql)";
  2408. if( !$result = $db->sql_query($sql) )
  2409. {
  2410. message_die(GENERAL_ERROR, 'Could not delete related comments', '', __LINE__, __FILE__, $sql);
  2411. }
  2412.  
  2413. $sql = "DELETE FROM ". ALBUM_RATE_TABLE ."
  2414. WHERE rate_pic_id IN ($pic_id_sql)";
  2415. if( !$result = $db->sql_query($sql) )
  2416. {
  2417. message_die(GENERAL_ERROR, 'Could not delete related ratings', '', __LINE__, __FILE__, $sql);
  2418. }
  2419.  
  2420. $sql = "SELECT pic_filename, pic_thumbnail
  2421. FROM ". ALBUM_TABLE ."
  2422. WHERE pic_id IN ($pic_id_sql)";
  2423. if( !$result = $db->sql_query($sql) )
  2424. {
  2425. message_die(GENERAL_ERROR, 'Could not obtain filenames', '', __LINE__, __FILE__, $sql);
  2426. }
  2427. $filerow = array();
  2428. while( $row = $db->sql_fetchrow($result) )
  2429. {
  2430. $filerow[] = $row;
  2431. }
  2432. for ($i = 0; $i < count($filerow); $i++)
  2433. {
  2434. if( ($filerow[$i]['pic_thumbnail'] != '') and (@file_exists(ALBUM_CACHE_PATH . $filerow[$i]['pic_thumbnail'])) )
  2435. {
  2436. @unlink(ALBUM_CACHE_PATH . $filerow[$i]['pic_thumbnail']);
  2437. }
  2438. @unlink(ALBUM_UPLOAD_PATH . $filerow[$i]['pic_filename']);
  2439. }
  2440.  
  2441. $sql = "DELETE FROM ". ALBUM_TABLE ."
  2442. WHERE pic_id IN ($pic_id_sql)";
  2443. if( !$result = $db->sql_query($sql) )
  2444. {
  2445. message_die(GENERAL_ERROR, 'Could not delete DB entry', '', __LINE__, __FILE__, $sql);
  2446. }
  2447.  
  2448. $message = $lang['Pics_deleted_successfully'] .'<br /><br />'. sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>") .'<br /><br />'. sprintf($lang['Click_return_modcp'], "<a href=\"" . append_sid("album.$phpEx?action=modcp&amp;cat_id=$cat_id") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  2449.  
  2450. message_die(GENERAL_MESSAGE, $message);
  2451. }
  2452. }
  2453. else
  2454. {
  2455. message_die(GENERAL_ERROR, 'Invalid_mode');
  2456. }
  2457. }
  2458.  
  2459. } elseif ( $action == 'page' ) {
  2460.  
  2461. if( isset($HTTP_GET_VARS['pic_id']) )
  2462. {
  2463. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  2464. }
  2465. else if( isset($HTTP_POST_VARS['pic_id']) )
  2466. {
  2467. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  2468. }
  2469. else
  2470. {
  2471. message_die(GENERAL_ERROR, 'No pic_id set');
  2472. }
  2473.  
  2474. if( isset($HTTP_GET_VARS['mode']) )
  2475. {
  2476. if( ($HTTP_GET_VARS['mode'] == 'next') or ($HTTP_GET_VARS['mode'] == 'previous') )
  2477. {
  2478. $sql = "SELECT pic_id, pic_cat_id, pic_user_id
  2479. FROM ". ALBUM_TABLE ."
  2480. WHERE pic_id = $pic_id";
  2481.  
  2482. if( !($result = $db->sql_query($sql)) )
  2483. {
  2484. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  2485. }
  2486. $row = $db->sql_fetchrow($result);
  2487. $cur_pic_cat = $row['pic_cat_id'];
  2488.  
  2489. if( empty($row) )
  2490. {
  2491. message_die(GENERAL_ERROR, 'Bad pic_id');
  2492. }
  2493.  
  2494. $sql = "SELECT new.pic_id, new.pic_time
  2495. FROM ". ALBUM_TABLE ." AS new, ". ALBUM_TABLE ." AS cur
  2496. WHERE cur.pic_id = $pic_id
  2497. AND new.pic_id <> cur.pic_id
  2498. AND new.pic_cat_id = cur.pic_cat_id";
  2499. $sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " AND new.pic_time >= cur.pic_time" : " AND new.pic_time <= cur.pic_time";
  2500. $sql .= ($row['pic_cat_id'] == PERSONAL_GALLERY) ? " AND new.pic_user_id = cur.pic_user_id" : "";
  2501. $sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " ORDER BY pic_time ASC LIMIT 1" : " ORDER BY pic_time DESC LIMIT 1";
  2502. if( !($result = $db->sql_query($sql)) )
  2503. {
  2504. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  2505. }
  2506.  
  2507. $row = $db->sql_fetchrow($result);
  2508.  
  2509. $sql = "SELECT min(pic_id), max(pic_id)
  2510. FROM ". ALBUM_TABLE ."
  2511. WHERE pic_cat_id = $cur_pic_cat";
  2512.  
  2513. if( !($result = $db->sql_query($sql)) )
  2514. {
  2515. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  2516. }
  2517.  
  2518. $next = $db->sql_fetchrow($result);
  2519. $first_pic = $next['min(pic_id)'];
  2520. $last_pic = $next['max(pic_id)'];
  2521. if( empty($row) AND ($HTTP_GET_VARS['mode'] == 'next'))
  2522. {
  2523. redirect(append_sid("album.$phpEx?action=page&pic_id=$first_pic"));
  2524. }
  2525. if( empty($row) AND ($HTTP_GET_VARS['mode'] == 'previous'))
  2526. {
  2527. redirect(append_sid("album.$phpEx?action=page&pic_id=$last_pic"));
  2528. }
  2529. $pic_id = $row['pic_id'];
  2530. }
  2531. }
  2532.  
  2533. $sql = "SELECT p.*, u.user_id, u.username, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments
  2534. FROM ". ALBUM_TABLE ." AS p
  2535. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  2536. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  2537. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  2538. WHERE pic_id = '$pic_id'
  2539. GROUP BY p.pic_id";
  2540. if( !($result = $db->sql_query($sql)) )
  2541. {
  2542. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  2543. }
  2544. $thispic = $db->sql_fetchrow($result);
  2545.  
  2546. $cat_id = $thispic['pic_cat_id'];
  2547. $user_id = $thispic['pic_user_id'];
  2548.  
  2549. if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) )
  2550. {
  2551. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  2552. }
  2553.  
  2554. if ($cat_id != PERSONAL_GALLERY)
  2555. {
  2556. $sql = "SELECT *
  2557. FROM ". ALBUM_CAT_TABLE ."
  2558. WHERE cat_id = '$cat_id'";
  2559. if( !($result = $db->sql_query($sql)) )
  2560. {
  2561. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  2562. }
  2563.  
  2564. $thiscat = $db->sql_fetchrow($result);
  2565. }
  2566. else
  2567. {
  2568. $thiscat = init_personal_gallery_cat($user_id);
  2569. }
  2570.  
  2571. if (empty($thiscat))
  2572. {
  2573. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  2574. }
  2575.  
  2576. $album_user_access = album_user_access($cat_id, $thiscat, 1, 0, 0, 0, 0, 0);
  2577.  
  2578. if ($album_user_access['view'] == 0)
  2579. {
  2580. if (!$userdata['session_logged_in'])
  2581. {
  2582. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=page&pic_id=$pic_id"));
  2583. }
  2584. else
  2585. {
  2586. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2587. }
  2588. }
  2589.  
  2590. if ($userdata['user_level'] != ADMIN)
  2591. {
  2592. if( ($thiscat['cat_approval'] == ADMIN) or (($thiscat['cat_approval'] == MOD) and !$album_user_access['moderator']) )
  2593. {
  2594. if ($thispic['pic_approval'] != 1)
  2595. {
  2596. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2597. }
  2598. }
  2599. }
  2600.  
  2601. $page_title = 'Галерея сайта';
  2602. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  2603.  
  2604. $template->set_filenames(array(
  2605. 'body' => 'album_page_body.tpl')
  2606. );
  2607.  
  2608. if( ($thispic['pic_user_id'] == ALBUM_GUEST) or ($thispic['username'] == '') )
  2609. {
  2610. $poster = ($thispic['pic_username'] == '') ? $lang['Guest'] : $thispic['pic_username'];
  2611. }
  2612. else
  2613. {
  2614. $poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $thispic['user_id']) .'">'. $thispic['username'] .'</a>';
  2615. }
  2616.  
  2617.  
  2618. $template->assign_vars(array(
  2619. 'CAT_TITLE' => $thiscat['cat_title'],
  2620. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  2621. 'U_PIC' => append_sid("album.$phpEx?action=pic&amp;pic_id=$pic_id"),
  2622. 'PIC_TITLE' => $thispic['pic_title'],
  2623. 'PIC_DESC' => nl2br($thispic['pic_desc']),
  2624. 'POSTER' => $poster,
  2625. 'PIC_TIME' => create_date($board_config['default_dateformat'], $thispic['pic_time'], $board_config['board_timezone']),
  2626. 'PIC_VIEW' => $thispic['pic_view_count'],
  2627. 'PIC_RATING' => ($thispic['rating'] != 0) ? round($thispic['rating'], 2) : $lang['Not_rated'],
  2628. 'PIC_COMMENTS' => $thispic['comments'],
  2629. 'U_RATE' => append_sid("album.$phpEx?action=rate&amp;pic_id=$pic_id"),
  2630. 'U_COMMENT' => append_sid("album.$phpEx?action=comment&amp;pic_id=$pic_id"),
  2631. 'U_NEXT' => append_sid("album.$phpEx?action=page&amp;pic_id=$pic_id&amp;mode=next"),
  2632. 'U_PREVIOUS' => append_sid("album.$phpEx?action=page&amp;pic_id=$pic_id&amp;mode=previous"),
  2633. 'L_NEXT' => $lang['Next'],
  2634. 'L_PREVIOUS' => $lang['Previous'],
  2635. 'L_RATING' => $lang['Rating'],
  2636. 'L_PIC_TITLE' => $lang['Pic_Title'],
  2637. 'L_PIC_DESC' => $lang['Pic_Desc'],
  2638. 'L_POSTER' => $lang['Poster'],
  2639. 'L_POSTED' => $lang['Posted'],
  2640. 'L_VIEW' => $lang['View'],
  2641. 'L_COMMENTS' => $lang['Comments'])
  2642. );
  2643.  
  2644. if ($album_config['rate'])
  2645. {
  2646. $template->assign_block_vars('rate_switch', array());
  2647. }
  2648.  
  2649. if ($album_config['comment'])
  2650. {
  2651. $template->assign_block_vars('comment_switch', array());
  2652. }
  2653.  
  2654. $template->pparse('body');
  2655.  
  2656. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  2657.  
  2658. } elseif ( $action == 'personal' ) {
  2659.  
  2660. if( isset($HTTP_POST_VARS['user_id']) )
  2661. {
  2662. $user_id = intval($HTTP_POST_VARS['user_id']);
  2663. }
  2664. else if( isset($HTTP_GET_VARS['user_id']) )
  2665. {
  2666. $user_id = intval($HTTP_GET_VARS['user_id']);
  2667. }
  2668. else
  2669. {
  2670. $user_id = $userdata['user_id'];
  2671. }
  2672.  
  2673. if( ($user_id < 1) and (!$userdata['session_logged_in']) )
  2674. {
  2675. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=personal"));
  2676. }
  2677.  
  2678. $sql = "SELECT username
  2679. FROM ". USERS_TABLE ."
  2680. WHERE user_id = $user_id";
  2681.  
  2682. if( !($result = $db->sql_query($sql)) )
  2683. {
  2684. message_die(GENERAL_ERROR, 'Could not get the username of this category owner', '', __LINE__, __FILE__, $sql);
  2685. }
  2686.  
  2687. $row = $db->sql_fetchrow($result);
  2688.  
  2689. $username = $row['username'];
  2690.  
  2691. if( empty($username) )
  2692. {
  2693. message_die(GENERAL_ERROR, 'Sorry, this user does not exist');
  2694. }
  2695.  
  2696. $personal_gallery_access = personal_gallery_access(1,1);
  2697.  
  2698. if( $personal_gallery_access['view'] == 0 )
  2699. {
  2700. if (!$userdata['session_logged_in'])
  2701. {
  2702. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=personal&user_id=$user_id"));
  2703. }
  2704. else
  2705. {
  2706. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  2707. }
  2708. }
  2709.  
  2710. if ($user_id == $userdata['user_id'])
  2711. {
  2712. if( $personal_gallery_access['upload'] == 0 )
  2713. {
  2714. message_die(GENERAL_MESSAGE, $lang['Not_allowed_to_create_personal_gallery']);
  2715. }
  2716. }
  2717.  
  2718. if( isset($HTTP_GET_VARS['start']) )
  2719. {
  2720. $start = intval($HTTP_GET_VARS['start']);
  2721. }
  2722. else if( isset($HTTP_POST_VARS['start']) )
  2723. {
  2724. $start = intval($HTTP_POST_VARS['start']);
  2725. }
  2726. else
  2727. {
  2728. $start = 0;
  2729. }
  2730. $start = ($start < 0) ? 0 : $start;
  2731.  
  2732. if( isset($HTTP_GET_VARS['sort_method']) )
  2733. {
  2734. switch ($HTTP_GET_VARS['sort_method'])
  2735. {
  2736. case 'pic_title':
  2737. $sort_method = 'pic_title';
  2738. break;
  2739. case 'pic_view_count':
  2740. $sort_method = 'pic_view_count';
  2741. break;
  2742. case 'rating':
  2743. $sort_method = 'rating';
  2744. break;
  2745. case 'comments':
  2746. $sort_method = 'comments';
  2747. break;
  2748. case 'new_comment':
  2749. $sort_method = 'new_comment';
  2750. break;
  2751. default:
  2752. $sort_method = $album_config['sort_method'];
  2753. }
  2754. }
  2755. else if( isset($HTTP_POST_VARS['sort_method']) )
  2756. {
  2757. switch ($HTTP_POST_VARS['sort_method'])
  2758. {
  2759. case 'pic_title':
  2760. $sort_method = 'pic_title';
  2761. break;
  2762. case 'pic_view_count':
  2763. $sort_method = 'pic_view_count';
  2764. break;
  2765. case 'rating':
  2766. $sort_method = 'rating';
  2767. break;
  2768. case 'comments':
  2769. $sort_method = 'comments';
  2770. break;
  2771. case 'new_comment':
  2772. $sort_method = 'new_comment';
  2773. break;
  2774. default:
  2775. $sort_method = $album_config['sort_method'];
  2776. }
  2777. }
  2778. else
  2779. {
  2780. $sort_method = $album_config['sort_method'];
  2781. }
  2782.  
  2783. if( isset($HTTP_GET_VARS['sort_order']) )
  2784. {
  2785. switch ($HTTP_GET_VARS['sort_order'])
  2786. {
  2787. case 'ASC':
  2788. $sort_order = 'ASC';
  2789. break;
  2790. case 'DESC':
  2791. $sort_order = 'DESC';
  2792. break;
  2793. default:
  2794. $sort_order = $album_config['sort_order'];
  2795. }
  2796. }
  2797. else if( isset($HTTP_POST_VARS['sort_order']) )
  2798. {
  2799. switch ($HTTP_POST_VARS['sort_order'])
  2800. {
  2801. case 'ASC':
  2802. $sort_order = 'ASC';
  2803. break;
  2804. case 'DESC':
  2805. $sort_order = 'DESC';
  2806. break;
  2807. default:
  2808. $sort_order = $album_config['sort_order'];
  2809. }
  2810. }
  2811. else
  2812. {
  2813. $sort_order = $album_config['sort_order'];
  2814. }
  2815.  
  2816. $pics_per_page = $album_config['rows_per_page'] * $album_config['cols_per_page'];
  2817.  
  2818. $sql = "SELECT COUNT(pic_id) AS count
  2819. FROM ". ALBUM_TABLE ."
  2820. WHERE pic_cat_id = ". PERSONAL_GALLERY ."
  2821. AND pic_user_id = $user_id";
  2822. if( !($result = $db->sql_query($sql)) )
  2823. {
  2824. message_die(GENERAL_ERROR, 'Could not count pics', '', __LINE__, __FILE__, $sql);
  2825. }
  2826.  
  2827. $row = $db->sql_fetchrow($result);
  2828.  
  2829. $total_pics = $row['count'];
  2830.  
  2831. if ($total_pics > 0)
  2832. {
  2833. $limit_sql = ($start == 0) ? $pics_per_page : $start .','. $pics_per_page;
  2834.  
  2835. $sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_time, p.pic_view_count, p.pic_lock, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments, MAX(c.comment_id) as new_comment
  2836. FROM ". ALBUM_TABLE ." AS p
  2837. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  2838. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  2839. WHERE p.pic_cat_id = ". PERSONAL_GALLERY ."
  2840. AND p.pic_user_id = $user_id
  2841. GROUP BY p.pic_id
  2842. ORDER BY $sort_method $sort_order
  2843. LIMIT $limit_sql";
  2844. if( !($result = $db->sql_query($sql)) )
  2845. {
  2846. message_die(GENERAL_ERROR, 'Could not query pics information', '', __LINE__, __FILE__, $sql);
  2847. }
  2848.  
  2849. $picrow = array();
  2850.  
  2851. while( $row = $db->sql_fetchrow($result) )
  2852. {
  2853. $picrow[] = $row;
  2854. }
  2855.  
  2856. for ($i = 0; $i < count($picrow); $i += $album_config['cols_per_page'])
  2857. {
  2858.  
  2859. for ($j = $i; $j < ($i + $album_config['cols_per_page']); $j++)
  2860. {
  2861. if( $j >= count($picrow) )
  2862. {
  2863. break;
  2864. }
  2865.  
  2866. if(!$picrow[$j]['rating'])
  2867. {
  2868. $picrow[$j]['rating'] = $lang['Not_rated'];
  2869. }
  2870. else
  2871. {
  2872. $picrow[$j]['rating'] = round($picrow[$j]['rating'], 2);
  2873. }
  2874.  
  2875. $row_class = ( !($j % 2) ) ? 'row_easy' : 'row_hard';
  2876.  
  2877. $template->assign_block_vars('picrow', array(
  2878. 'TITLE' => $picrow[$j]['pic_title'],
  2879. 'ROW_CLASS' => $row_class,
  2880. 'TIME' => create_date($board_config['default_dateformat'], $picrow[$j]['pic_time'], $board_config['board_timezone']),
  2881. 'VIEW' => $picrow[$j]['pic_view_count'],
  2882. 'RATING' => ($album_config['rate'] == 1) ? ( '<a href="'. append_sid("album.$phpEx?action=rate&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Rating'] . '</a>: ' . $picrow[$j]['rating'] . '<br />') : '',
  2883. 'COMMENTS' => ($album_config['comment'] == 1) ? ( '<a href="'. append_sid("album.$phpEx?action=comment&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Comments'] . '</a>: ' . $picrow[$j]['comments'] . '<br />') : '',
  2884. 'EDIT' => ( ($userdata['user_level'] == ADMIN) or ($userdata['user_id'] == $picrow[$j]['pic_user_id']) ) ? '<a href="'. append_sid("album.$phpEx?action=edit&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Edit_pic'] . '</a>|' : '',
  2885. 'DELETE' => ( ($userdata['user_level'] == ADMIN) or ($userdata['user_id'] == $picrow[$j]['pic_user_id']) ) ? '<a href="'. append_sid("album.$phpEx?action=delete&amp;pic_id=". $picrow[$j]['pic_id']) . '">' . $lang['Delete_pic'] . '</a>|' : '',
  2886. 'LOCK' => ($userdata['user_level'] == ADMIN) ? '<a href="'. append_sid("album.$phpEx?action=modcp&amp;mode=". (($picrow[$j]['pic_lock'] == 0) ? 'lock' : 'unlock') ."&amp;pic_id=". $picrow[$j]['pic_id']) .'">'. (($picrow[$j]['pic_lock'] == 0) ? $lang['Lock'] : $lang['Unlock']) .'</a>' : '',
  2887. 'IP' => ($userdata['user_level'] == ADMIN) ? $lang['IP_Address'] . ': ' . decode_ip($picrow[$j]['pic_user_ip']) .'<br />' : ''
  2888. )
  2889. );
  2890.  
  2891. $template->assign_block_vars('picrow.piccol', array(
  2892. 'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=". $picrow[$j]['pic_id']) : append_sid("album.$phpEx?action=page&amp;pic_id=". $picrow[$j]['pic_id']),
  2893. 'THUMBNAIL' => append_sid("album.$phpEx?action=thumbnail&amp;pic_id=". $picrow[$j]['pic_id']),
  2894. 'DESC' => $picrow[$j]['pic_desc']
  2895. )
  2896. );
  2897. }
  2898. }
  2899.  
  2900. $template->assign_vars(array(
  2901. 'PAGINATION' => generate_pagination(append_sid("album.$phpEx?action=personal&amp;user_id=$user_id&amp;sort_method=$sort_method&amp;sort_order=$sort_order"), $total_pics, $pics_per_page, $start))
  2902. );
  2903. }
  2904. else
  2905. {
  2906. $template->assign_block_vars('no_pics', array());
  2907. }
  2908.  
  2909. $sort_rating_option = '';
  2910. $sort_comments_option = '';
  2911. if( $album_config['rate'] == 1 )
  2912. {
  2913. $sort_rating_option = '<option value="rating" ';
  2914. $sort_rating_option .= ($sort_method == 'rating') ? 'selected="selected"' : '';
  2915. $sort_rating_option .= '>' . $lang['Rating'] .'</option>';
  2916. }
  2917. if( $album_config['comment'] == 1 )
  2918. {
  2919. $sort_comments_option = '<option value="comments" ';
  2920. $sort_comments_option .= ($sort_method == 'comments') ? 'selected="selected"' : '';
  2921. $sort_comments_option .= '>' . $lang['Comments'] .'</option>';
  2922.  
  2923. $sort_new_comment_option = '<option value="new_comment" ';
  2924. $sort_new_comment_option .= ($sort_method == 'new_comment') ? 'selected="selected"' : '';
  2925. $sort_new_comment_option .= '>' . $lang['New_Comment'] .'</option>';
  2926. }
  2927.  
  2928. $page_title = 'Галерея сайта';
  2929. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  2930.  
  2931. $template->set_filenames(array(
  2932. 'body' => 'album_personal_body.tpl')
  2933. );
  2934.  
  2935. if( $user_id == $userdata['user_id'] )
  2936. {
  2937. $template->assign_block_vars('your_personal_gallery', array());
  2938. }
  2939.  
  2940. $template->assign_vars(array(
  2941. 'U_UPLOAD_PIC' => append_sid("album.$phpEx?action=upload&amp;cat_id=". PERSONAL_GALLERY),
  2942. 'UPLOAD_PIC_IMG' => $images['upload_pic'],
  2943. 'L_UPLOAD_PIC' => $lang['Upload_Pic'],
  2944. 'L_PERSONAL_GALLERY_NOT_CREATED' => sprintf($lang['Personal_gallery_not_created'], $username),
  2945. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  2946. 'S_COLS' => $album_config['cols_per_page'],
  2947. 'S_COL_WIDTH' => (100/$album_config['cols_per_page']) . '%',
  2948. 'L_VIEW' => $lang['View'],
  2949. 'L_POSTED' => $lang['Posted'],
  2950. 'U_PERSONAL_GALLERY' => append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  2951. 'L_YOUR_PERSONAL_GALLERY' => $lang['Your_Personal_Gallery'],
  2952. 'L_PERSONAL_GALLERY_EXPLAIN' => $lang['Personal_Gallery_Explain'],
  2953. 'L_PERSONAL_GALLERY_OF_USER' => sprintf($lang['Personal_Gallery_Of_User'], $username),
  2954. 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
  2955. 'L_ORDER' => $lang['Order'],
  2956. 'L_SORT' => $lang['Sort'],
  2957. 'L_NO_PICS' => $lang['No_Pics'],
  2958. 'L_TIME' => $lang['Time'],
  2959. 'L_PIC_TITLE' => $lang['Pic_Title'],
  2960. 'SORT_TIME' => ($sort_method == 'pic_time') ? 'selected="selected"' : '',
  2961. 'SORT_PIC_TITLE' => ($sort_method == 'pic_title') ? 'selected="selected"' : '',
  2962. 'SORT_VIEW' => ($sort_method == 'pic_view_count') ? 'selected="selected"' : '',
  2963. 'SORT_RATING_OPTION' => $sort_rating_option,
  2964. 'SORT_COMMENTS_OPTION' => $sort_comments_option,
  2965. 'SORT_NEW_COMMENT_OPTION' => $sort_new_comment_option,
  2966. 'L_ASC' => $lang['Sort_Ascending'],
  2967. 'L_DESC' => $lang['Sort_Descending'],
  2968. 'SORT_ASC' => ($sort_order == 'ASC') ? 'selected="selected"' : '',
  2969. 'SORT_DESC' => ($sort_order == 'DESC') ? 'selected="selected"' : '')
  2970. );
  2971.  
  2972. $template->pparse('body');
  2973.  
  2974. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  2975.  
  2976. } elseif ( $action == 'personal_index' ) {
  2977.  
  2978. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  2979. $start = ($start < 0) ? 0 : $start;
  2980.  
  2981. if ( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
  2982. {
  2983. $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  2984. }
  2985. else
  2986. {
  2987. $mode = 'joined';
  2988. }
  2989.  
  2990. if(isset($HTTP_POST_VARS['order']))
  2991. {
  2992. $sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
  2993. }
  2994. else if(isset($HTTP_GET_VARS['order']))
  2995. {
  2996. $sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
  2997. }
  2998. else
  2999. {
  3000. $sort_order = 'ASC';
  3001. }
  3002.  
  3003. $mode_types_text = array($lang['Sort_Joined'], $lang['Sort_Username'], $lang['Pics'], $lang['Last_Pic']);
  3004. $mode_types = array('joindate', 'username', 'pics', 'last_pic');
  3005.  
  3006. $select_sort_mode = '<select name="mode">';
  3007. for($i = 0; $i < count($mode_types_text); $i++)
  3008. {
  3009. $selected = ( $mode == $mode_types[$i] ) ? ' selected="selected"' : '';
  3010. $select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
  3011. }
  3012. $select_sort_mode .= '</select>';
  3013.  
  3014. $select_sort_order = '<select name="order">';
  3015. if($sort_order == 'ASC')
  3016. {
  3017. $select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
  3018. }
  3019. else
  3020. {
  3021. $select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
  3022. }
  3023. $select_sort_order .= '</select>';
  3024.  
  3025. $page_title = 'Галерея сайта';
  3026. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  3027.  
  3028. $template->set_filenames(array(
  3029. 'body' => 'album_personal_index_body.tpl')
  3030. );
  3031.  
  3032. $template->assign_vars(array(
  3033. 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
  3034. 'L_ORDER' => $lang['Order'],
  3035. 'L_SORT' => $lang['Sort'],
  3036. 'L_JOINED' => $lang['Joined'],
  3037. 'L_PICS' => $lang['Pics'],
  3038. 'L_USERS_PERSONAL_GALLERIES' => $lang['Users_Personal_Galleries'],
  3039. 'S_MODE_SELECT' => $select_sort_mode,
  3040. 'S_ORDER_SELECT' => $select_sort_order,
  3041. 'S_MODE_ACTION' => append_sid("album.$phpEx?action=personal_index")
  3042. )
  3043. );
  3044.  
  3045.  
  3046. switch( $mode )
  3047. {
  3048. case 'joined':
  3049. $order_by = "user_regdate ASC LIMIT $start, " . $board_config['topics_per_page'];
  3050. break;
  3051. case 'username':
  3052. $order_by = "username $sort_order LIMIT $start, " . $board_config['topics_per_page'];
  3053. break;
  3054. case 'pics':
  3055. $order_by = "pics $sort_order LIMIT $start, " . $board_config['topics_per_page'];
  3056. break;
  3057. case 'last_pic':
  3058. $order_by = "last_pic $sort_order LIMIT $start, " . $board_config['topics_per_page'];
  3059. break;
  3060. default:
  3061. $order_by = "user_regdate $sort_order LIMIT $start, " . $board_config['topics_per_page'];
  3062. break;
  3063. }
  3064.  
  3065. $sql = "SELECT u.username, u.user_id, u.user_regdate, COUNT(p.pic_id) AS pics, MAX(p.pic_id) AS last_pic
  3066. FROM ". USERS_TABLE ." AS u, ". ALBUM_TABLE ." as p
  3067. WHERE u.user_id <> ". ANONYMOUS ."
  3068. AND u.user_id = p.pic_user_id
  3069. AND p.pic_cat_id = ". PERSONAL_GALLERY ."
  3070. GROUP BY user_id
  3071. ORDER BY $order_by";
  3072.  
  3073. if( !($result = $db->sql_query($sql)) )
  3074. {
  3075. message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
  3076. }
  3077.  
  3078. $memberrow = array();
  3079.  
  3080. while( $row = $db->sql_fetchrow($result) )
  3081. {
  3082. $memberrow[] = $row;
  3083. }
  3084.  
  3085. for ($i = 0; $i < count($memberrow); $i++)
  3086. {
  3087. $template->assign_block_vars('memberrow', array(
  3088. 'ROW_CLASS' => ( !($i % 2) ) ? 'row_easy' : 'row_hard',
  3089. 'USERNAME' => $memberrow[$i]['username'],
  3090. 'U_VIEWGALLERY' => append_sid("album.$phpEx?action=personal&amp;user_id=". $memberrow[$i]['user_id']),
  3091. 'JOINED' => create_date($lang['DATE_FORMAT'], $memberrow[$i]['user_regdate'], $board_config['board_timezone']),
  3092. 'PICS' => $memberrow[$i]['pics'])
  3093. );
  3094. }
  3095.  
  3096. $sql = "SELECT COUNT(DISTINCT u.user_id) AS total
  3097. FROM ". USERS_TABLE ." AS u, ". ALBUM_TABLE ." AS p
  3098. WHERE u.user_id <> ". ANONYMOUS ."
  3099. AND u.user_id = p.pic_user_id
  3100. AND p.pic_cat_id = ". PERSONAL_GALLERY;
  3101.  
  3102. if ( !($result = $db->sql_query($sql)) )
  3103. {
  3104. message_die(GENERAL_ERROR, 'Error getting total galleries', '', __LINE__, __FILE__, $sql);
  3105. }
  3106.  
  3107. if ( $total = $db->sql_fetchrow($result) )
  3108. {
  3109. $total_galleries = $total['total'];
  3110.  
  3111. $pagination = ( $total_galleries > $board_config['topics_per_page'] ) ? generate_pagination("album.$phpEx?action=personal_index&amp;mode=$mode&amp;order=$sort_order", $total_galleries, $board_config['topics_per_page'], $start) : '';
  3112. }
  3113.  
  3114. $template->assign_vars(array(
  3115. 'PAGINATION' => $pagination,
  3116. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_galleries / $board_config['topics_per_page'] ))
  3117. )
  3118. );
  3119.  
  3120. if ( $total_galleries == 0 )
  3121. {
  3122. $template->assign_block_vars('no_pics', array());
  3123. }
  3124.  
  3125. $template->pparse('body');
  3126.  
  3127. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  3128.  
  3129. } elseif ( $action == 'pic' ) {
  3130.  
  3131. if( isset($HTTP_GET_VARS['pic_id']) )
  3132. {
  3133. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  3134. }
  3135. else if( isset($HTTP_POST_VARS['pic_id']) )
  3136. {
  3137. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  3138. }
  3139. else
  3140. {
  3141. die('No pics specified');
  3142. }
  3143.  
  3144. $sql = "SELECT *
  3145. FROM ". ALBUM_TABLE ."
  3146. WHERE pic_id = '$pic_id'";
  3147. if( !($result = $db->sql_query($sql)) )
  3148. {
  3149. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  3150. }
  3151. $thispic = $db->sql_fetchrow($result);
  3152.  
  3153. $cat_id = $thispic['pic_cat_id'];
  3154. $user_id = $thispic['pic_user_id'];
  3155.  
  3156. $pic_filetype = substr($thispic['pic_filename'], strlen($thispic['pic_filename']) - 4, 4);
  3157. $pic_filename = $thispic['pic_filename'];
  3158. $pic_thumbnail = $thispic['pic_thumbnail'];
  3159.  
  3160. if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) )
  3161. {
  3162. die($lang['Pic_not_exist']);
  3163. }
  3164.  
  3165. if ($cat_id != PERSONAL_GALLERY)
  3166. {
  3167. $sql = "SELECT *
  3168. FROM ". ALBUM_CAT_TABLE ."
  3169. WHERE cat_id = '$cat_id'";
  3170. if( !($result = $db->sql_query($sql)) )
  3171. {
  3172. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  3173. }
  3174.  
  3175. $thiscat = $db->sql_fetchrow($result);
  3176. }
  3177. else
  3178. {
  3179. $thiscat = init_personal_gallery_cat($user_id);
  3180. }
  3181.  
  3182. if (empty($thiscat))
  3183. {
  3184. die($lang['Category_not_exist']);
  3185. }
  3186.  
  3187. $album_user_access = album_user_access($cat_id, $thiscat, 1, 0, 0, 0, 0, 0);
  3188. if ($album_user_access['view'] == 0)
  3189. {
  3190. die($lang['Not_Authorised']);
  3191. }
  3192.  
  3193. if ($userdata['user_level'] != ADMIN)
  3194. {
  3195. if( ($thiscat['cat_approval'] == ADMIN) or (($thiscat['cat_approval'] == MOD) and !$album_user_access['moderator']) )
  3196. {
  3197. if ($thispic['pic_approval'] != 1)
  3198. {
  3199. die($lang['Not_Authorised']);
  3200. }
  3201. }
  3202. }
  3203.  
  3204. if( ($album_config['hotlink_prevent'] == 1) and (isset($HTTP_SERVER_VARS['HTTP_REFERER'])) )
  3205. {
  3206. $check_referer = explode('?', $HTTP_SERVER_VARS['HTTP_REFERER']);
  3207. $check_referer = trim($check_referer[0]);
  3208.  
  3209. $good_referers = array();
  3210.  
  3211. if ($album_config['hotlink_allowed'] != '')
  3212. {
  3213. $good_referers = explode(',', $album_config['hotlink_allowed']);
  3214. }
  3215.  
  3216. $good_referers[] = $board_config['server_name'] . $board_config['script_path'];
  3217.  
  3218. $errored = TRUE;
  3219.  
  3220. for ($i = 0; $i < count($good_referers); $i++)
  3221. {
  3222. $good_referers[$i] = trim($good_referers[$i]);
  3223.  
  3224. if( (strstr($check_referer, $good_referers[$i])) and ($good_referers[$i] != '') )
  3225. {
  3226. $errored = FALSE;
  3227. }
  3228. }
  3229.  
  3230. if ($errored)
  3231. {
  3232. die($lang['Not_Authorised']);
  3233. }
  3234. }
  3235.  
  3236. $sql = "UPDATE ". ALBUM_TABLE ."
  3237. SET pic_view_count = pic_view_count + 1
  3238. WHERE pic_id = '$pic_id'";
  3239. if( !($result = $db->sql_query($sql)) )
  3240. {
  3241. message_die(GENERAL_ERROR, 'Could not update pic information', '', __LINE__, __FILE__, $sql);
  3242. }
  3243.  
  3244. switch ( $pic_filetype )
  3245. {
  3246. case '.png':
  3247. header('Content-type: image/png');
  3248. break;
  3249. case '.gif':
  3250. header('Content-type: image/gif');
  3251. break;
  3252. case '.jpg':
  3253. header('Content-type: image/jpeg');
  3254. break;
  3255. default:
  3256. die('The filename data in the DB was corrupted');
  3257. }
  3258.  
  3259. readfile(ALBUM_UPLOAD_PATH . $thispic['pic_filename']);
  3260.  
  3261. exit;
  3262.  
  3263. } elseif ( $action == 'rate' ) {
  3264.  
  3265. if( $album_config['rate'] == 0 )
  3266. {
  3267. message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
  3268. }
  3269.  
  3270. if( isset($HTTP_GET_VARS['pic_id']) )
  3271. {
  3272. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  3273. }
  3274. else if( isset($HTTP_POST_VARS['pic_id']) )
  3275. {
  3276. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  3277. }
  3278. else
  3279. {
  3280. message_die(GENERAL_ERROR, 'No pics specified');
  3281. }
  3282.  
  3283. $sql = "SELECT p.*, u.user_id, u.username, r.rate_pic_id, AVG(r.rate_point) AS rating
  3284. FROM ". ALBUM_TABLE ." AS p
  3285. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  3286. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  3287. WHERE pic_id = '$pic_id'
  3288. GROUP BY p.pic_id";
  3289. if( !($result = $db->sql_query($sql)) )
  3290. {
  3291. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  3292. }
  3293. $thispic = $db->sql_fetchrow($result);
  3294.  
  3295. $cat_id = $thispic['pic_cat_id'];
  3296. $user_id = $thispic['pic_user_id'];
  3297.  
  3298. $pic_filename = $thispic['pic_filename'];
  3299. $pic_thumbnail = $thispic['pic_thumbnail'];
  3300.  
  3301. if( empty($thispic) )
  3302. {
  3303. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  3304. }
  3305.  
  3306. if ($cat_id != PERSONAL_GALLERY)
  3307. {
  3308. $sql = "SELECT *
  3309. FROM ". ALBUM_CAT_TABLE ."
  3310. WHERE cat_id = '$cat_id'";
  3311. if( !($result = $db->sql_query($sql)) )
  3312. {
  3313. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  3314. }
  3315.  
  3316. $thiscat = $db->sql_fetchrow($result);
  3317. }
  3318. else
  3319. {
  3320. $thiscat = init_personal_gallery_cat($user_id);
  3321. }
  3322.  
  3323. if (empty($thiscat))
  3324. {
  3325. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  3326. }
  3327.  
  3328. $album_user_access = album_user_access($cat_id, $thiscat, 0, 0, 1, 0, 0, 0);
  3329.  
  3330. if ($album_user_access['rate'] == 0)
  3331. {
  3332. if (!$userdata['session_logged_in'])
  3333. {
  3334. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=rate&pic_id=$pic_id"));
  3335. }
  3336. else
  3337. {
  3338. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  3339. }
  3340. }
  3341.  
  3342. if( $userdata['session_logged_in'] )
  3343. {
  3344. $sql = "SELECT *
  3345. FROM ". ALBUM_RATE_TABLE ."
  3346. WHERE rate_pic_id = '$pic_id'
  3347. AND rate_user_id = '". $userdata['user_id'] ."'
  3348. LIMIT 1";
  3349.  
  3350. if( !$result = $db->sql_query($sql) )
  3351. {
  3352. message_die(GENERAL_ERROR, 'Could not query rating information', '', __LINE__, __FILE__, $sql);
  3353. }
  3354.  
  3355. if ($db->sql_numrows($result) > 0)
  3356. {
  3357. $already_rated = TRUE;
  3358. }
  3359. else
  3360. {
  3361. $already_rated = FALSE;
  3362. }
  3363. }
  3364.  
  3365. if( !isset($HTTP_POST_VARS['rate']) )
  3366. {
  3367. if (!$already_rated)
  3368. {
  3369. for ($i = 0; $i < $album_config['rate_scale']; $i++)
  3370. {
  3371. $template->assign_block_vars('rate_row', array(
  3372. 'POINT' => ($i + 1)
  3373. )
  3374. );
  3375. }
  3376. }
  3377.  
  3378. $page_title = 'Галерея сайта';
  3379. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  3380.  
  3381. $template->set_filenames(array(
  3382. 'body' => 'album_rate_body.tpl')
  3383. );
  3384.  
  3385. if( ($thispic['pic_user_id'] == ALBUM_GUEST) or ($thispic['username'] == '') )
  3386. {
  3387. $poster = ($thispic['pic_username'] == '') ? $lang['Guest'] : $thispic['pic_username'];
  3388. }
  3389. else
  3390. {
  3391. $poster = '<a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $thispic['user_id']) .'">'. $thispic['username'] .'</a>';
  3392. }
  3393.  
  3394. $template->assign_vars(array(
  3395. 'CAT_TITLE' => $thiscat['cat_title'],
  3396. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal&amp;user_id=$user_id"),
  3397. 'U_THUMBNAIL' => append_sid("album.$phpEx?action=thumbnail&amp;pic_id=$pic_id"),
  3398. 'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=$pic_id") : append_sid("album.$phpEx?action=page&amp;pic_id=$pic_id"),
  3399. 'PIC_TITLE' => $thispic['pic_title'],
  3400. 'PIC_DESC' => nl2br($thispic['pic_desc']),
  3401. 'POSTER' => $poster,
  3402. 'PIC_TIME' => create_date($board_config['default_dateformat'], $thispic['pic_time'], $board_config['board_timezone']),
  3403. 'PIC_VIEW' => $thispic['pic_view_count'],
  3404. 'PIC_RATING' => ($thispic['rating'] != 0) ? round($thispic['rating'], 2) : $lang['Not_rated'],
  3405. 'S_RATE_MSG' => ($already_rated) ? $lang['Already_rated'] : $lang['Rating'],
  3406. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  3407. 'L_RATING' => $lang['Rating'],
  3408. 'L_PIC_TITLE' => $lang['Pic_Title'],
  3409. 'L_PIC_DESC' => $lang['Pic_Desc'],
  3410. 'L_POSTER' => $lang['Poster'],
  3411. 'L_POSTED' => $lang['Posted'],
  3412. 'L_VIEW' => $lang['View'],
  3413. 'L_CURRENT_RATING' => $lang['Current_Rating'],
  3414. 'L_PLEASE_RATE_IT' => $lang['Please_Rate_It'],
  3415. 'L_SUBMIT' => $lang['Submit'],
  3416. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=rate&amp;pic_id=$pic_id"),
  3417.  
  3418. )
  3419. );
  3420.  
  3421. $template->pparse('body');
  3422.  
  3423. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  3424. }
  3425. else
  3426. {
  3427. $rate_point = intval($HTTP_POST_VARS['rate']);
  3428.  
  3429. if( ($rate_point <= 0) or ($rate_point > $album_config['rate_scale']) )
  3430. {
  3431. message_die(GENERAL_ERROR, 'Bad submited value');
  3432. }
  3433.  
  3434. $rate_user_id = $userdata['user_id'];
  3435. $rate_user_ip = $userdata['session_ip'];
  3436.  
  3437. if ($already_rated)
  3438. {
  3439. message_die(GENERAL_ERROR, $lang['Already_rated']);
  3440. }
  3441.  
  3442. $sql = "INSERT INTO ". ALBUM_RATE_TABLE ." (rate_pic_id, rate_user_id, rate_user_ip, rate_point)
  3443. VALUES ('$pic_id', '$rate_user_id', '$rate_user_ip', '$rate_point')";
  3444.  
  3445. if( !$result = $db->sql_query($sql) )
  3446. {
  3447. message_die(GENERAL_ERROR, 'Could not insert new rating', '', __LINE__, __FILE__, $sql);
  3448. }
  3449.  
  3450. $message = $lang['Album_rate_successfully'];
  3451.  
  3452. if ($cat_id != PERSONAL_GALLERY)
  3453. {
  3454. $template->assign_vars(array(
  3455. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . '">')
  3456. );
  3457.  
  3458. $message .= "<br /><br />" . sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>");
  3459. }
  3460. else
  3461. {
  3462. $template->assign_vars(array(
  3463. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("album.$phpEx?action=personal&amp;user_id=$user_id") . '">')
  3464. );
  3465.  
  3466. $message .= "<br /><br />" . sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal&amp;user_id=$user_id") . "\">", "</a>");
  3467. }
  3468.  
  3469. $message .= "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  3470.  
  3471. message_die(GENERAL_MESSAGE, $message);
  3472. }
  3473.  
  3474. } elseif ( $action == 'thumbnail' ) {
  3475.  
  3476. if( isset($HTTP_GET_VARS['pic_id']) )
  3477. {
  3478. $pic_id = intval($HTTP_GET_VARS['pic_id']);
  3479. }
  3480. else if( isset($HTTP_POST_VARS['pic_id']) )
  3481. {
  3482. $pic_id = intval($HTTP_POST_VARS['pic_id']);
  3483. }
  3484. else
  3485. {
  3486. die('No pics specified');
  3487. }
  3488.  
  3489. $sql = "SELECT *
  3490. FROM ". ALBUM_TABLE ."
  3491. WHERE pic_id = '$pic_id'";
  3492. if( !($result = $db->sql_query($sql)) )
  3493. {
  3494. message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
  3495. }
  3496. $thispic = $db->sql_fetchrow($result);
  3497.  
  3498. $cat_id = $thispic['pic_cat_id'];
  3499. $user_id = $thispic['pic_user_id'];
  3500.  
  3501. $pic_filetype = substr($thispic['pic_filename'], strlen($thispic['pic_filename']) - 4, 4);
  3502. $pic_filename = $thispic['pic_filename'];
  3503. $pic_thumbnail = $thispic['pic_thumbnail'];
  3504.  
  3505. if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) )
  3506. {
  3507. die($lang['Pic_not_exist']);
  3508. }
  3509.  
  3510. if ($cat_id != PERSONAL_GALLERY)
  3511. {
  3512. $sql = "SELECT *
  3513. FROM ". ALBUM_CAT_TABLE ."
  3514. WHERE cat_id = '$cat_id'";
  3515. if( !($result = $db->sql_query($sql)) )
  3516. {
  3517. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  3518. }
  3519.  
  3520. $thiscat = $db->sql_fetchrow($result);
  3521. }
  3522. else
  3523. {
  3524. $thiscat = init_personal_gallery_cat($user_id);
  3525. }
  3526.  
  3527. if (empty($thiscat))
  3528. {
  3529. die($lang['Category_not_exist']);
  3530. }
  3531.  
  3532. $album_user_access = album_user_access($cat_id, $thiscat, 1, 0, 0, 0, 0, 0);
  3533.  
  3534. if ($album_user_access['view'] == 0)
  3535. {
  3536. die($lang['Not_Authorised']);
  3537. }
  3538.  
  3539. if ($userdata['user_level'] != ADMIN)
  3540. {
  3541. if( ($thiscat['cat_approval'] == ADMIN) or (($thiscat['cat_approval'] == MOD) and !$album_user_access['moderator']) )
  3542. {
  3543. if ($thispic['pic_approval'] != 1)
  3544. {
  3545. die($lang['Not_Authorised']);
  3546. }
  3547. }
  3548. }
  3549.  
  3550. if( ($album_config['hotlink_prevent'] == 1) and (isset($HTTP_SERVER_VARS['HTTP_REFERER'])) )
  3551. {
  3552. $check_referer = explode('?', $HTTP_SERVER_VARS['HTTP_REFERER']);
  3553. $check_referer = trim($check_referer[0]);
  3554.  
  3555. $good_referers = array();
  3556.  
  3557. if ($album_config['hotlink_allowed'] != '')
  3558. {
  3559. $good_referers = explode(',', $album_config['hotlink_allowed']);
  3560. }
  3561.  
  3562. $good_referers[] = $board_config['server_name'] . $board_config['script_path'];
  3563.  
  3564. $errored = TRUE;
  3565.  
  3566. for ($i = 0; $i < count($good_referers); $i++)
  3567. {
  3568. $good_referers[$i] = trim($good_referers[$i]);
  3569.  
  3570. if( (strstr($check_referer, $good_referers[$i])) and ($good_referers[$i] != '') )
  3571. {
  3572. $errored = FALSE;
  3573. }
  3574. }
  3575.  
  3576. if ($errored)
  3577. {
  3578. die($lang['Not_Authorised']);
  3579. }
  3580. }
  3581.  
  3582. if( ($pic_filetype != '.jpg') and ($pic_filetype != '.png') and ($pic_filetype != '.gif') )
  3583. {
  3584. header('Content-type: image/jpeg');
  3585. readfile($images['no_thumbnail']);
  3586. exit;
  3587. }
  3588. else
  3589. {
  3590. if( ($album_config['thumbnail_cache'] == 1) and ($pic_thumbnail != '') and file_exists(ALBUM_CACHE_PATH . $pic_thumbnail) )
  3591. {
  3592. switch ($pic_filetype)
  3593. {
  3594. case '.gif':
  3595. case '.jpg':
  3596. header('Content-type: image/jpeg');
  3597. break;
  3598. case '.png':
  3599. header('Content-type: image/png');
  3600. break;
  3601. }
  3602.  
  3603. readfile(ALBUM_CACHE_PATH . $pic_thumbnail);
  3604. exit;
  3605. }
  3606.  
  3607. $pic_size = @getimagesize(ALBUM_UPLOAD_PATH . $pic_filename);
  3608. $pic_width = $pic_size[0];
  3609. $pic_height = $pic_size[1];
  3610.  
  3611. $gd_errored = FALSE;
  3612. switch ($pic_filetype)
  3613. {
  3614. case '.gif':
  3615. $read_function = 'imagecreatefromgif';
  3616. $pic_filetype = '.jpg';
  3617. break;
  3618. case '.jpg':
  3619. $read_function = 'imagecreatefromjpeg';
  3620. break;
  3621. case '.png':
  3622. $read_function = 'imagecreatefrompng';
  3623. break;
  3624. }
  3625.  
  3626. $src = @$read_function(ALBUM_UPLOAD_PATH . $pic_filename);
  3627.  
  3628. if (!$src)
  3629. {
  3630. $gd_errored = TRUE;
  3631. $pic_thumbnail = '';
  3632. }
  3633. else if( ($pic_width > $album_config['thumbnail_size']) or ($pic_height > $album_config['thumbnail_size']) )
  3634. {
  3635. if ($pic_width > $pic_height)
  3636. {
  3637. $thumbnail_width = $album_config['thumbnail_size'];
  3638. $thumbnail_height = $album_config['thumbnail_size'] * ($pic_height/$pic_width);
  3639. }
  3640. else
  3641. {
  3642. $thumbnail_height = $album_config['thumbnail_size'];
  3643. $thumbnail_width = $album_config['thumbnail_size'] * ($pic_width/$pic_height);
  3644. }
  3645.  
  3646. $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height);
  3647.  
  3648. $resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled';
  3649.  
  3650. @$resize_function($thumbnail, $src, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height);
  3651. }
  3652. else
  3653. {
  3654. $thumbnail = $src;
  3655. }
  3656.  
  3657. if (!$gd_errored)
  3658. {
  3659. if ($album_config['thumbnail_cache'] == 1)
  3660. {
  3661. $pic_thumbnail = $pic_filename;
  3662.  
  3663. switch ($pic_filetype)
  3664. {
  3665. case '.jpg':
  3666. @imagejpeg($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail, $album_config['thumbnail_quality']);
  3667. break;
  3668. case '.png':
  3669. @imagepng($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail);
  3670. break;
  3671. }
  3672.  
  3673. @chmod(ALBUM_CACHE_PATH . $pic_thumbnail, 0777);
  3674. }
  3675.  
  3676. switch ($pic_filetype)
  3677. {
  3678. case '.jpg':
  3679. @imagejpeg($thumbnail, '', $album_config['thumbnail_quality']);
  3680. break;
  3681. case '.png':
  3682. @imagepng($thumbnail);
  3683. break;
  3684. }
  3685.  
  3686. exit;
  3687. }
  3688. else
  3689. {
  3690. header('Content-type: image/jpeg');
  3691. readfile('images/nothumbnail.jpg');
  3692. exit;
  3693. }
  3694. }
  3695.  
  3696. } elseif ( $action == 'upload' ) {
  3697.  
  3698. if( isset($HTTP_POST_VARS['cat_id']) )
  3699. {
  3700. $cat_id = intval($HTTP_POST_VARS['cat_id']);
  3701. }
  3702. else if( isset($HTTP_GET_VARS['cat_id']) )
  3703. {
  3704. $cat_id = intval($HTTP_GET_VARS['cat_id']);
  3705. }
  3706. else
  3707. {
  3708. message_die(GENERAL_ERROR, 'No categories specified');
  3709. }
  3710.  
  3711. if ($cat_id != PERSONAL_GALLERY)
  3712. {
  3713. $sql = "SELECT c.*, COUNT(p.pic_id) AS count
  3714. FROM ". ALBUM_CAT_TABLE ." AS c
  3715. LEFT JOIN ". ALBUM_TABLE ." AS p ON c.cat_id = p.pic_cat_id
  3716. WHERE c.cat_id = '$cat_id'
  3717. GROUP BY c.cat_id
  3718. LIMIT 1";
  3719. if( !($result = $db->sql_query($sql)) )
  3720. {
  3721. message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
  3722. }
  3723.  
  3724. $thiscat = $db->sql_fetchrow($result);
  3725. }
  3726. else
  3727. {
  3728. $thiscat = init_personal_gallery_cat($user_data['user_id']);
  3729. }
  3730.  
  3731. $current_pics = $thiscat['count'];
  3732.  
  3733. if (empty($thiscat))
  3734. {
  3735. message_die(GENERAL_ERROR, $lang['Category_not_exist']);
  3736. }
  3737.  
  3738. $album_user_access = album_user_access($cat_id, $thiscat, 0, 1, 0, 0, 0, 0);
  3739.  
  3740. if ($album_user_access['upload'] == 0)
  3741. {
  3742. if (!$userdata['session_logged_in'])
  3743. {
  3744. redirect(append_sid("login.$phpEx?redirect=album.$phpEx&action=upload&cat_id=$cat_id"));
  3745. }
  3746. else
  3747. {
  3748. message_die(GENERAL_ERROR, $lang['Not_Authorised']);
  3749. }
  3750. }
  3751.  
  3752. if ($cat_id != PERSONAL_GALLERY)
  3753. {
  3754. if ($album_config['max_pics'] >= 0)
  3755. {
  3756. if( $current_pics >= $album_config['max_pics'] )
  3757. {
  3758. message_die(GENERAL_MESSAGE, $lang['Album_reached_quota']);
  3759. }
  3760. }
  3761.  
  3762. $check_user_limit = FALSE;
  3763.  
  3764. if( ($userdata['user_level'] != ADMIN) and ($userdata['session_logged_in']) )
  3765. {
  3766. if ($album_user_access['moderator'])
  3767. {
  3768. if ($album_config['mod_pics_limit'] >= 0)
  3769. {
  3770. $check_user_limit = 'mod_pics_limit';
  3771. }
  3772. }
  3773. else
  3774. {
  3775. if ($album_config['user_pics_limit'] >= 0)
  3776. {
  3777. $check_user_limit = 'user_pics_limit';
  3778. }
  3779. }
  3780. }
  3781.  
  3782. if ($check_user_limit != FALSE)
  3783. {
  3784. $sql = "SELECT COUNT(pic_id) AS count
  3785. FROM ". ALBUM_TABLE ."
  3786. WHERE pic_user_id = '". $userdata['user_id'] ."'
  3787. AND pic_cat_id = '$cat_id'";
  3788. if( !($result = $db->sql_query($sql)) )
  3789. {
  3790. message_die(GENERAL_ERROR, 'Could not count your pic', '', __LINE__, __FILE__, $sql);
  3791. }
  3792. $row = $db->sql_fetchrow($result);
  3793. $own_pics = $row['count'];
  3794.  
  3795. if( $own_pics >= $album_config[$check_user_limit] )
  3796. {
  3797. message_die(GENERAL_MESSAGE, $lang['User_reached_pics_quota']);
  3798. }
  3799. }
  3800. }
  3801. else
  3802. {
  3803. if( ($current_pics >= $album_config['personal_gallery_limit']) and ($album_config['personal_gallery_limit'] >= 0) )
  3804. {
  3805. message_die(GENERAL_MESSAGE, $lang['Album_reached_quota']);
  3806. }
  3807. }
  3808.  
  3809. if( !isset($HTTP_POST_VARS['pic_title']) )
  3810. {
  3811. $sql = "SELECT *
  3812. FROM " . ALBUM_CAT_TABLE ."
  3813. ORDER BY cat_order ASC";
  3814. if( !($result = $db->sql_query($sql)) )
  3815. {
  3816. message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
  3817. }
  3818.  
  3819. $catrows = array();
  3820.  
  3821. while( $row = $db->sql_fetchrow($result) )
  3822. {
  3823. $thiscat_access = album_user_access($row['cat_id'], $row, 0, 1, 0, 0, 0, 0);
  3824.  
  3825. if ($thiscat_access['upload'] == 1)
  3826. {
  3827. $catrows[] = $row;
  3828. }
  3829. }
  3830.  
  3831. $select_cat = '<select name="cat_id">';
  3832.  
  3833. if ($cat_id == PERSONAL_GALLERY)
  3834. {
  3835. $select_cat .= '<option value="$cat_id" selected="selected">';
  3836. $select_cat .= sprintf($lang['Personal_Gallery_Of_User'], $userdata['username']);
  3837. $select_cat .= '</option>';
  3838. }
  3839.  
  3840. for ($i = 0; $i < count($catrows); $i++)
  3841. {
  3842. $select_cat .= '<option value="'. $catrows[$i]['cat_id'] .'" ';
  3843. $select_cat .= ($cat_id == $catrows[$i]['cat_id']) ? 'selected="selected"' : '';
  3844. $select_cat .= '>'. $catrows[$i]['cat_title'] .'</option>';
  3845. }
  3846.  
  3847. $select_cat .= '</select>';
  3848.  
  3849. $page_title = 'Галерея сайта';
  3850. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  3851.  
  3852. $template->set_filenames(array(
  3853. 'body' => ($result_ua) ? 'album_upload_body_om.tpl' : 'album_upload_body.tpl')
  3854. );
  3855.  
  3856. $template->assign_vars(array(
  3857. 'U_VIEW_CAT' => ($cat_id != PERSONAL_GALLERY) ? append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") : append_sid("album.$phpEx?action=personal"),
  3858. 'CAT_TITLE' => $thiscat['cat_title'],
  3859.  
  3860. 'L_UPLOAD_PIC' => $lang['Upload_Pic'],
  3861.  
  3862. 'L_USERNAME' => $lang['Username'],
  3863. 'L_PIC_TITLE' => $lang['Pic_Title'],
  3864.  
  3865. 'L_PIC_DESC' => $lang['Pic_Desc'],
  3866. 'L_PLAIN_TEXT_ONLY' => $lang['Plain_text_only'],
  3867. 'L_MAX_LENGTH' => $lang['Max_length'],
  3868. 'S_PIC_DESC_MAX_LENGTH' => $album_config['desc_length'],
  3869.  
  3870. 'L_UPLOAD_PIC_FROM_MACHINE' => $lang['Upload_pic_from_machine'],
  3871. 'L_UPLOAD_PIC_FROM_MACHINE_OM' => $lang['Upload_pic_from_machine_om'],
  3872. 'L_UPLOAD_TO_CATEGORY' => $lang['Upload_to_Category'],
  3873.  
  3874. 'SELECT_CAT' => $select_cat,
  3875.  
  3876. 'L_MAX_FILESIZE' => $lang['Max_file_size'],
  3877. 'S_MAX_FILESIZE' => $album_config['max_file_size'],
  3878.  
  3879. 'L_MAX_WIDTH' => $lang['Max_width'],
  3880. 'L_MAX_HEIGHT' => $lang['Max_height'],
  3881.  
  3882. 'S_MAX_WIDTH' => $album_config['max_width'],
  3883. 'S_MAX_HEIGHT' => $album_config['max_height'],
  3884.  
  3885. 'L_ALLOWED_JPG' => $lang['JPG_allowed'],
  3886. 'L_ALLOWED_PNG' => $lang['PNG_allowed'],
  3887. 'L_ALLOWED_GIF' => $lang['GIF_allowed'],
  3888.  
  3889. 'S_JPG' => ($album_config['jpg_allowed'] == 1) ? $lang['Yes'] : $lang['No'],
  3890. 'S_PNG' => ($album_config['png_allowed'] == 1) ? $lang['Yes'] : $lang['No'],
  3891. 'S_GIF' => ($album_config['gif_allowed'] == 1) ? $lang['Yes'] : $lang['No'],
  3892.  
  3893. 'L_UPLOAD_NO_TITLE' => $lang['Upload_no_title'],
  3894. 'L_UPLOAD_NO_FILE' => $lang['Upload_no_file'],
  3895. 'L_DESC_TOO_LONG' => $lang['Desc_too_long'],
  3896.  
  3897. 'L_UPLOAD_THUMBNAIL' => $lang['Upload_thumbnail'],
  3898. 'L_UPLOAD_THUMBNAIL_EXPLAIN' => $lang['Upload_thumbnail_explain'],
  3899. 'L_THUMBNAIL_SIZE' => $lang['Thumbnail_size'],
  3900. 'S_THUMBNAIL_SIZE' => $album_config['thumbnail_size'],
  3901.  
  3902. 'L_RESET' => $lang['Reset'],
  3903. 'L_SUBMIT' => $lang['Submit'],
  3904.  
  3905. 'S_ALBUM_ACTION' => append_sid("album.$phpEx?action=upload&amp;cat_id=$cat_id"),
  3906. )
  3907. );
  3908.  
  3909. if ($album_config['gd_version'] == 0)
  3910. {
  3911. $template->assign_block_vars('switch_manual_thumbnail', array());
  3912. }
  3913.  
  3914. $template->pparse('body');
  3915.  
  3916. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  3917. }
  3918. else
  3919. {
  3920. $pic_title = str_replace("\'", "''", htmlspecialchars(trim($HTTP_POST_VARS['pic_title'])));
  3921. $pic_desc = str_replace("\'", "''", htmlspecialchars(substr(trim($HTTP_POST_VARS['pic_desc']), 0, $album_config['desc_length'])));
  3922. $pic_username = (!$userdata['session_logged_in']) ? substr(str_replace("\'", "''", htmlspecialchars(trim($HTTP_POST_VARS['pic_username']))), 0, 32) : str_replace("'", "''", $userdata['username']);
  3923.  
  3924. if( empty($pic_title) )
  3925. {
  3926. message_die(GENERAL_ERROR, $lang['Missed_pic_title']);
  3927. }
  3928.  
  3929. if ($result_ua)
  3930. {
  3931. if( !isset($HTTP_POST_VARS['picupload']) )
  3932. {
  3933. message_die(GENERAL_ERROR, 'Bad Upload');
  3934. }
  3935. } else {
  3936. if( !isset($HTTP_POST_FILES['pic_file']) )
  3937. {
  3938. message_die(GENERAL_ERROR, 'Bad Upload');
  3939. }
  3940. }
  3941.  
  3942. if (!$userdata['session_logged_in'])
  3943. {
  3944. if ($pic_username != '')
  3945. {
  3946. $result = validate_username($pic_username);
  3947. if ( $result['error'] )
  3948. {
  3949. message_die(GENERAL_MESSAGE, $result['error_msg']);
  3950. }
  3951. }
  3952. }
  3953.  
  3954. if ($result_ua)
  3955. {
  3956. $uploadedfile = $HTTP_POST_VARS['picupload'];
  3957.  
  3958. if (strlen($uploadedfile))
  3959. {
  3960. $array = explode('file=', $uploadedfile);
  3961. $tmp_name = $array[0];
  3962. $filebase64 = $array[1];
  3963. }
  3964.  
  3965. $tmp_name = basename($tmp_name);
  3966.  
  3967. if (strlen($filebase64))
  3968. {
  3969. $filedata = base64_decode($filebase64);
  3970. }
  3971.  
  3972. $fileom = @fopen($opera_mini . "/" . $tmp_name, "wb");
  3973.  
  3974. if($fileom)
  3975. {
  3976. if(flock($fileom, LOCK_EX))
  3977. {
  3978. fwrite($fileom, $filedata);
  3979. flock($fileom, LOCK_UN);
  3980. }
  3981. fclose($fileom);
  3982. }
  3983.  
  3984. $filetmp = $opera_mini . "/" . $tmp_name;
  3985. $filesize = @filesize($filetmp);
  3986. $tmp_name_type = strrchr($tmp_name, '.');
  3987. $repl=array("."=>"");
  3988. $type = strtr($tmp_name_type, $repl);
  3989. $filetype = 'image/'.$type;
  3990.  
  3991. } else {
  3992. $filetype = $HTTP_POST_FILES['pic_file']['type'];
  3993. $filesize = $HTTP_POST_FILES['pic_file']['size'];
  3994. $filetmp = $HTTP_POST_FILES['pic_file']['tmp_name'];
  3995. }
  3996.  
  3997. if ($album_config['gd_version'] == 0)
  3998. {
  3999. $thumbtype = $HTTP_POST_FILES['pic_thumbnail']['type'];
  4000. $thumbsize = $HTTP_POST_FILES['pic_thumbnail']['size'];
  4001. $thumbtmp = $HTTP_POST_FILES['pic_thumbnail']['tmp_name'];
  4002. }
  4003.  
  4004. $pic_time = time();
  4005. $pic_user_id = $userdata['user_id'];
  4006. $pic_user_ip = $userdata['session_ip'];
  4007.  
  4008. if( ($filesize == 0) or ($filesize > $album_config['max_file_size']) )
  4009. {
  4010. @unlink($filetmp);
  4011. message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
  4012. }
  4013.  
  4014. if ($album_config['gd_version'] == 0)
  4015. {
  4016. if( ($thumbsize == 0) or ($thumbsize > $album_config['max_file_size']) )
  4017. {
  4018. @unlink($filetmp);
  4019. message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
  4020. }
  4021. }
  4022.  
  4023. switch ($filetype)
  4024. {
  4025. case 'image/jpeg':
  4026. case 'image/jpg':
  4027. case 'image/pjpeg':
  4028. if ($album_config['jpg_allowed'] == 0)
  4029. {
  4030. @unlink($filetmp);
  4031. message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
  4032. }
  4033. $pic_filetype = '.jpg';
  4034. break;
  4035.  
  4036. case 'image/png':
  4037. case 'image/x-png':
  4038. if ($album_config['png_allowed'] == 0)
  4039. {
  4040. @unlink($filetmp);
  4041. message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
  4042. }
  4043. $pic_filetype = '.png';
  4044. break;
  4045.  
  4046. case 'image/gif':
  4047. if ($album_config['gif_allowed'] == 0)
  4048. {
  4049. @unlink($filetmp);
  4050. message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
  4051. }
  4052. $pic_filetype = '.gif';
  4053. break;
  4054. default:
  4055. @unlink($filetmp);
  4056. message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
  4057. }
  4058.  
  4059. if ($album_config['gd_version'] == 0)
  4060. {
  4061. if ($filetype != $thumbtype)
  4062. {
  4063. @unlink($filetmp);
  4064. message_die(GENERAL_ERROR, $lang['Filetype_and_thumbtype_do_not_match']);
  4065. }
  4066. }
  4067.  
  4068. srand((double)microtime()*1000000);
  4069.  
  4070. do
  4071. {
  4072. $pic_filename = md5(uniqid(rand())) . $pic_filetype;
  4073. }
  4074. while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) );
  4075.  
  4076. if ($album_config['gd_version'] == 0)
  4077. {
  4078. $pic_thumbnail = $pic_filename;
  4079. }
  4080.  
  4081. $ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
  4082.  
  4083. if ( @$ini_val('open_basedir') != '' )
  4084. {
  4085. if ( @phpversion() < '4.0.3' )
  4086. {
  4087. @unlink($filetmp);
  4088. message_die(GENERAL_ERROR, 'open_basedir is set and your PHP version does not allow move_uploaded_file<br /><br />Please contact your server admin', '', __LINE__, __FILE__);
  4089. }
  4090.  
  4091. $move_file = 'move_uploaded_file';
  4092. }
  4093. else
  4094. {
  4095. $move_file = 'copy';
  4096. }
  4097.  
  4098. if ($result_ua)
  4099. {
  4100. $move_file = 'copy';
  4101. }
  4102.  
  4103. $move_file($filetmp, ALBUM_UPLOAD_PATH . $pic_filename);
  4104.  
  4105. @chmod(ALBUM_UPLOAD_PATH . $pic_filename, 0777);
  4106.  
  4107. if ($album_config['gd_version'] == 0)
  4108. {
  4109. $move_file($thumbtmp, ALBUM_CACHE_PATH . $pic_thumbnail);
  4110.  
  4111. @chmod(ALBUM_CACHE_PATH . $pic_thumbnail, 0777);
  4112. }
  4113.  
  4114. $pic_size = getimagesize(ALBUM_UPLOAD_PATH . $pic_filename);
  4115.  
  4116. $pic_width = $pic_size[0];
  4117. $pic_height = $pic_size[1];
  4118.  
  4119. if ( ($pic_width > $album_config['max_width']) or ($pic_height > $album_config['max_height']) )
  4120. {
  4121. @unlink(ALBUM_UPLOAD_PATH . $pic_filename);
  4122.  
  4123. if ($album_config['gd_version'] == 0)
  4124. {
  4125. @unlink(ALBUM_CACHE_PATH . $pic_thumbnail);
  4126. }
  4127. @unlink($filetmp);
  4128. message_die(GENERAL_ERROR, $lang['Upload_image_size_too_big']);
  4129. }
  4130.  
  4131. if ($album_config['gd_version'] == 0)
  4132. {
  4133. $thumb_size = getimagesize(ALBUM_CACHE_PATH . $pic_thumbnail);
  4134.  
  4135. $thumb_width = $thumb_size[0];
  4136. $thumb_height = $thumb_size[1];
  4137.  
  4138. if ( ($thumb_width > $album_config['thumbnail_size']) or ($thumb_height > $album_config['thumbnail_size']) )
  4139. {
  4140. @unlink(ALBUM_UPLOAD_PATH . $pic_filename);
  4141.  
  4142. @unlink(ALBUM_CACHE_PATH . $pic_thumbnail);
  4143.  
  4144. @unlink($filetmp);
  4145. message_die(GENERAL_ERROR, $lang['Upload_thumbnail_size_too_big']);
  4146. }
  4147. }
  4148.  
  4149. if( ($album_config['thumbnail_cache'] == 1) and ($pic_filetype != '.gif') and ($album_config['gd_version'] > 0) )
  4150. {
  4151. $gd_errored = FALSE;
  4152.  
  4153. switch ($pic_filetype)
  4154. {
  4155. case '.jpg':
  4156. $read_function = 'imagecreatefromjpeg';
  4157. break;
  4158. case '.png':
  4159. $read_function = 'imagecreatefrompng';
  4160. break;
  4161. }
  4162.  
  4163. $src = @$read_function(ALBUM_UPLOAD_PATH . $pic_filename);
  4164.  
  4165. if (!$src)
  4166. {
  4167. $gd_errored = TRUE;
  4168. $pic_thumbnail = '';
  4169. }
  4170. else if( ($pic_width > $album_config['thumbnail_size']) or ($pic_height > $album_config['thumbnail_size']) )
  4171. {
  4172. if ($pic_width > $pic_height)
  4173. {
  4174. $thumbnail_width = $album_config['thumbnail_size'];
  4175. $thumbnail_height = $album_config['thumbnail_size'] * ($pic_height/$pic_width);
  4176. }
  4177. else
  4178. {
  4179. $thumbnail_height = $album_config['thumbnail_size'];
  4180. $thumbnail_width = $album_config['thumbnail_size'] * ($pic_width/$pic_height);
  4181. }
  4182.  
  4183. $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height);
  4184.  
  4185. $resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled';
  4186.  
  4187. @$resize_function($thumbnail, $src, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height);
  4188. }
  4189. else
  4190. {
  4191. $thumbnail = $src;
  4192. }
  4193.  
  4194. if (!$gd_errored)
  4195. {
  4196. $pic_thumbnail = $pic_filename;
  4197.  
  4198. switch ($pic_filetype)
  4199. {
  4200. case '.jpg':
  4201. @imagejpeg($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail, $album_config['thumbnail_quality']);
  4202. break;
  4203. case '.png':
  4204. @imagepng($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail);
  4205. break;
  4206. }
  4207.  
  4208. @chmod(ALBUM_CACHE_PATH . $pic_thumbnail, 0777);
  4209.  
  4210. }
  4211.  
  4212. }
  4213. else if ($album_config['gd_version'] > 0)
  4214. {
  4215. $pic_thumbnail = '';
  4216. }
  4217.  
  4218. $pic_approval = ($thiscat['cat_approval'] == 0) ? 1 : 0;
  4219.  
  4220. $sql = "INSERT INTO ". ALBUM_TABLE ." (pic_filename, pic_thumbnail, pic_title, pic_desc, pic_user_id, pic_user_ip, pic_username, pic_time, pic_cat_id, pic_approval)
  4221. VALUES ('$pic_filename', '$pic_thumbnail', '$pic_title', '$pic_desc', '$pic_user_id', '$pic_user_ip', '$pic_username', '$pic_time', '$cat_id', '$pic_approval')";
  4222. if( !$result = $db->sql_query($sql) )
  4223. {
  4224. @unlink($filetmp);
  4225. message_die(GENERAL_ERROR, 'Could not insert new entry', '', __LINE__, __FILE__, $sql);
  4226. }
  4227.  
  4228. if ($thiscat['cat_approval'] == 0)
  4229. {
  4230. $message = $lang['Album_upload_successful'];
  4231. }
  4232. else
  4233. {
  4234. $message = $lang['Album_upload_need_approval'];
  4235. }
  4236. @unlink($filetmp);
  4237.  
  4238. if ($cat_id != PERSONAL_GALLERY)
  4239. {
  4240. if ($thiscat['cat_approval'] == 0)
  4241. {
  4242. $template->assign_vars(array(
  4243. 'META' => '<meta http-equiv="refresh" content="2;url=' . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . '">')
  4244. );
  4245. }
  4246.  
  4247. $message .= "<br /><br />" . sprintf($lang['Click_return_category'], "<a href=\"" . append_sid("album.$phpEx?action=cat&amp;cat_id=$cat_id") . "\">", "</a>");
  4248. }
  4249. else
  4250. {
  4251. if ($thiscat['cat_approval'] == 0)
  4252. {
  4253. $template->assign_vars(array(
  4254. 'META' => '<meta http-equiv="refresh" content="2;url=' . append_sid("album.$phpEx?action=personal") . '">')
  4255. );
  4256. }
  4257.  
  4258. $message .= "<br /><br />" . sprintf($lang['Click_return_personal_gallery'], "<a href=\"" . append_sid("album.$phpEx?action=personal") . "\">", "</a>");
  4259. }
  4260.  
  4261. $message .= "<br /><br />" . sprintf($lang['Click_return_album_index'], "<a href=\"" . append_sid("album.$phpEx") . "\">", "</a>");
  4262.  
  4263. message_die(GENERAL_MESSAGE, $message);
  4264. }
  4265.  
  4266. } else {
  4267.  
  4268. $sql = "SELECT c.*, COUNT(p.pic_id) AS count
  4269. FROM ". ALBUM_CAT_TABLE ." AS c
  4270. LEFT JOIN ". ALBUM_TABLE ." AS p ON c.cat_id = p.pic_cat_id
  4271. WHERE cat_id <> 0
  4272. GROUP BY cat_id
  4273. ORDER BY cat_order ASC";
  4274. if( !($result = $db->sql_query($sql)) )
  4275. {
  4276. message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
  4277. }
  4278.  
  4279. $catrows = array();
  4280.  
  4281. while( $row = $db->sql_fetchrow($result) )
  4282. {
  4283. $album_user_access = album_user_access($row['cat_id'], $row, 1, 0, 0, 0, 0, 0);
  4284. if ($album_user_access['view'] == 1)
  4285. {
  4286. $catrows[] = $row;
  4287. }
  4288. }
  4289.  
  4290. $allowed_cat = '';
  4291.  
  4292. for ($i = 0; $i < count($catrows); $i++)
  4293. {
  4294. $allowed_cat .= ($allowed_cat == '') ? $catrows[$i]['cat_id'] : ',' . $catrows[$i]['cat_id'];
  4295. $l_moderators = '';
  4296. $moderators_list = '';
  4297.  
  4298. $grouprows= array();
  4299.  
  4300. if( $catrows[$i]['cat_moderator_groups'] != '')
  4301. {
  4302. $sql = "SELECT group_id, group_name
  4303. FROM " . GROUPS_TABLE . "
  4304. WHERE group_single_user <> 1
  4305. AND group_type <> ". GROUP_HIDDEN ."
  4306. AND group_id IN (". $catrows[$i]['cat_moderator_groups'] .")
  4307. ORDER BY group_name ASC";
  4308. if ( !$result = $db->sql_query($sql) )
  4309. {
  4310. message_die(GENERAL_ERROR, 'Could not obtain usergroups data', '', __LINE__, __FILE__, $sql);
  4311. }
  4312.  
  4313. while( $row = $db->sql_fetchrow($result) )
  4314. {
  4315. $grouprows[] = $row;
  4316. }
  4317. }
  4318.  
  4319. if( count($grouprows) > 0 )
  4320. {
  4321. $l_moderators = $lang['Moderators'];
  4322.  
  4323. for ($j = 0; $j < count($grouprows); $j++)
  4324. {
  4325. $group_link = '<a href="'. append_sid("groupcp.$phpEx?". POST_GROUPS_URL .'='. $grouprows[$j]['group_id']) .'">'. $grouprows[$j]['group_name'] .'</a>';
  4326.  
  4327. $moderators_list .= ($moderators_list == '') ? $group_link : ', ' . $group_link;
  4328. }
  4329. }
  4330.  
  4331. if ($catrows[$i]['count'] == 0)
  4332. {
  4333. $last_pic_info = $lang['No_Pics'];
  4334. $u_last_pic = '';
  4335. $last_pic_title = '';
  4336. }
  4337. else
  4338. {
  4339. if(($catrows[$i]['cat_approval'] == ALBUM_ADMIN) or ($catrows[$i]['cat_approval'] == ALBUM_MOD))
  4340. {
  4341. $pic_approval_sql = 'AND p.pic_approval = 1';
  4342. }
  4343. else
  4344. {
  4345. $pic_approval_sql = '';
  4346. }
  4347.  
  4348. $sql = "SELECT p.pic_id, p.pic_title, p.pic_user_id, p.pic_username, p.pic_time, p.pic_cat_id, u.user_id, u.username
  4349. FROM ". ALBUM_TABLE ." AS p LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  4350. WHERE p.pic_cat_id = '". $catrows[$i]['cat_id'] ."' $pic_approval_sql
  4351. ORDER BY p.pic_time DESC
  4352. LIMIT 1";
  4353. if ( !$result = $db->sql_query($sql) )
  4354. {
  4355. message_die(GENERAL_ERROR, 'Could not get last pic information', '', __LINE__, __FILE__, $sql);
  4356. }
  4357. $lastrow = $db->sql_fetchrow($result);
  4358.  
  4359. $last_pic_info = create_date($board_config['default_dateformat'], $lastrow['pic_time'], $board_config['board_timezone']);
  4360.  
  4361. $last_pic_info .= '<br />';
  4362.  
  4363. if( ($lastrow['user_id'] == ALBUM_GUEST) or ($lastrow['username'] == '') )
  4364. {
  4365. $last_pic_info .= ($lastrow['pic_username'] == '') ? $lang['Guest'] : $lastrow['pic_username'];
  4366. }
  4367. else
  4368. {
  4369. $last_pic_info .= $lang['Poster'] .': <a href="'. append_sid("../pages/profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $lastrow['user_id']) .'">'. $lastrow['username'] .'</a>';
  4370. }
  4371.  
  4372. if( !isset($album_config['last_pic_title_length']) )
  4373. {
  4374. $album_config['last_pic_title_length'] = 25;
  4375. }
  4376.  
  4377. $lastrow['pic_title'] = $lastrow['pic_title'];
  4378.  
  4379. if (strlen($lastrow['pic_title']) > $album_config['last_pic_title_length'])
  4380. {
  4381. $lastrow['pic_title'] = substr($lastrow['pic_title'], 0, $album_config['last_pic_title_length']) . '...';
  4382. }
  4383.  
  4384. $last_pic_info .= '<br />'. $lang['Pic_Title'] .': <a href="';
  4385.  
  4386. $last_pic_info .= ($album_config['fullpic_popup']) ? append_sid("album.$phpEx?action=pic&amp;pic_id=". $lastrow['pic_id']) .'" target="_blank">' : append_sid("album.$phpEx?action=page&amp;pic_id=". $lastrow['pic_id']) .'">' ;
  4387.  
  4388. $last_pic_info .= $lastrow['pic_title'] .'</a>';
  4389. }
  4390.  
  4391. $template->assign_block_vars('catrow', array(
  4392. 'U_VIEW_CAT' => append_sid("album.$phpEx?action=cat&amp;cat_id=". $catrows[$i]['cat_id']),
  4393. 'CAT_TITLE' => $catrows[$i]['cat_title'],
  4394. 'CAT_DESC' => $catrows[$i]['cat_desc'],
  4395. 'L_MODERATORS' => $l_moderators,
  4396. 'MODERATORS' => $moderators_list,
  4397. 'PICS' => $catrows[$i]['count'],
  4398. 'LAST_PIC_INFO' => $last_pic_info)
  4399. );
  4400. }
  4401.  
  4402. if ($allowed_cat == '')
  4403. {
  4404. $template->assign_block_vars('no_cats', array());
  4405. }
  4406.  
  4407. $page_title = 'Галерея сайта';
  4408. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  4409.  
  4410. $template->set_filenames(array(
  4411. 'body' => 'album_index_body.tpl')
  4412. );
  4413.  
  4414. // Общее количество фото
  4415. $result = mysql_query("SELECT count(*) AS total FROM " . ALBUM_TABLE);
  4416. $album = mysql_fetch_array($result);
  4417. $album = $album['total'];
  4418.  
  4419. $template->assign_vars(array(
  4420. 'ALBUM' => $album,
  4421. 'L_CATEGORY' => $lang['Category'],
  4422. 'L_PICS' => $lang['Pics'],
  4423. 'L_LAST_PIC' => $lang['Last_Pic'],
  4424.  
  4425. 'U_YOUR_PERSONAL_GALLERY' => append_sid("album.$phpEx?action=personal&amp;user_id=". $userdata['user_id']),
  4426. 'L_YOUR_PERSONAL_GALLERY' => $lang['Your_Personal_Gallery'],
  4427.  
  4428. 'U_USERS_PERSONAL_GALLERIES' => append_sid("album.$phpEx?action=personal_index"),
  4429. 'L_USERS_PERSONAL_GALLERIES' => $lang['Users_Personal_Galleries'],
  4430.  
  4431. 'S_COLS' => $album_config['cols_per_page'],
  4432. 'S_COL_WIDTH' => (100/$album_config['cols_per_page']) . '%',
  4433. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  4434. 'L_RECENT_PUBLIC_PICS' => $lang['Recent_Public_Pics'],
  4435. 'L_NO_PICS' => $lang['No_Pics'],
  4436. 'L_PIC_TITLE' => $lang['Pic_Title'],
  4437. 'L_VIEW' => $lang['View'],
  4438. 'L_POSTER' => $lang['Poster'],
  4439. 'L_POSTED' => $lang['Posted'],
  4440. 'L_PUBLIC_CATS' => $lang['Public_Categories'])
  4441. );
  4442.  
  4443. $template->pparse('body');
  4444.  
  4445. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  4446.  
  4447. }
  4448.  
  4449. ?>