| 1 | <?php |
|---|
| 2 | /******************************************************************************/ |
|---|
| 3 | // // |
|---|
| 4 | // InstantCMS v1.8 // |
|---|
| 5 | // http://www.instantcms.ru/ // |
|---|
| 6 | // // |
|---|
| 7 | // written by InstantCMS Team, 2007-2010 // |
|---|
| 8 | // produced by InstantSoft, (www.instantsoft.ru) // |
|---|
| 9 | // // |
|---|
| 10 | // LICENSED BY GNU/GPL v2 // |
|---|
| 11 | // // |
|---|
| 12 | /******************************************************************************/ |
|---|
| 13 | |
|---|
| 14 | if(!defined('VALID_CMS')) { die('ACCESS DENIED'); } |
|---|
| 15 | |
|---|
| 16 | function clubRootAlbumId($club_id){ |
|---|
| 17 | $inDB = cmsDatabase::getInstance(); |
|---|
| 18 | return $inDB->get_field('cms_photo_albums', "parent_id=0 AND NSDiffer='club".$club_id."'", 'id'); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | function clubRepairAlbums(){ |
|---|
| 22 | $inDB = cmsDatabase::getInstance(); |
|---|
| 23 | $sql = "UPDATE cms_photo_albums SET NSDiffer = CONCAT('club', user_id) WHERE NSDiffer = 'club'"; |
|---|
| 24 | $inDB->query($sql); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | function setClubRating($club_id){ |
|---|
| 28 | $inDB = cmsDatabase::getInstance(); |
|---|
| 29 | $sql = "SELECT SUM( u.rating ) AS rating |
|---|
| 30 | FROM cms_user_clubs c |
|---|
| 31 | LEFT JOIN cms_users u ON u.id = c.user_id |
|---|
| 32 | WHERE c.club_id = '$club_id'"; |
|---|
| 33 | $rs = $inDB->query($sql); |
|---|
| 34 | if ($inDB->num_rows($rs)){ |
|---|
| 35 | $data = $inDB->fetch_assoc($rs); |
|---|
| 36 | $rating = $data['rating'] * 5; |
|---|
| 37 | } else { |
|---|
| 38 | $rating = 0; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | $sql = "UPDATE cms_clubs SET rating = $rating WHERE id = $club_id"; |
|---|
| 42 | $inDB->query($sql); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | function cmsUserClubs($user_id){ |
|---|
| 46 | $inDB = cmsDatabase::getInstance(); |
|---|
| 47 | $userclubs['member'] = array(); |
|---|
| 48 | $userclubs['moder'] = array(); |
|---|
| 49 | $userclubs['admin'] = array(); |
|---|
| 50 | |
|---|
| 51 | //check member/moder |
|---|
| 52 | $sql = "SELECT u.*, c.title as title, c.id as id |
|---|
| 53 | FROM cms_user_clubs u, cms_clubs c |
|---|
| 54 | WHERE u.user_id = $user_id AND u.club_id = c.id AND c.published = 1 |
|---|
| 55 | ORDER BY c.title DESC"; |
|---|
| 56 | $rs = $inDB->query($sql); |
|---|
| 57 | if ($inDB->num_rows($rs)){ |
|---|
| 58 | while ($record = $inDB->fetch_assoc($rs)){ |
|---|
| 59 | if ($record['role'] == 'moderator'){ |
|---|
| 60 | $userclubs['moder'][] = $record; |
|---|
| 61 | } |
|---|
| 62 | if ($record['role'] == 'member'){ |
|---|
| 63 | $userclubs['member'][] = $record; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | //check admin |
|---|
| 69 | $sql = "SELECT title, id, admin_id |
|---|
| 70 | FROM cms_clubs |
|---|
| 71 | WHERE admin_id = $user_id AND published = 1 |
|---|
| 72 | ORDER BY title DESC"; |
|---|
| 73 | $rs = $inDB->query($sql); |
|---|
| 74 | if ($inDB->num_rows($rs)){ |
|---|
| 75 | while ($record = $inDB->fetch_assoc($rs)){ |
|---|
| 76 | $userclubs['admin'][] = $record; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | if ($userclubs['admin'] || $userclubs['member'] || $userclubs['moder']){ |
|---|
| 81 | return $userclubs; |
|---|
| 82 | } else { |
|---|
| 83 | return false; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | function clubBlogId($club_id){ |
|---|
| 88 | $inDB = cmsDatabase::getInstance(); |
|---|
| 89 | $id = $inDB->get_field('cms_blogs', "owner='club' AND user_id=$club_id", 'id'); |
|---|
| 90 | if (!$id){ |
|---|
| 91 | $sql = "INSERT INTO cms_blogs (user_id, title, pubdate, allow_who, view_type, showcats, ownertype, premod, forall, owner) |
|---|
| 92 | VALUES ('$club_id', 'Áëîã', NOW(), 'all', 'list', 1, 'multi', 0, 0, 'club')"; |
|---|
| 93 | $inDB->query($sql); |
|---|
| 94 | $id = $inDB->get_field('cms_blogs', "owner='club' AND user_id=$club_id", 'id'); |
|---|
| 95 | } |
|---|
| 96 | return $id; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | function clubBlogContent($blog_id, $is_admin=false, $is_moder=false, $is_member=false){ |
|---|
| 100 | |
|---|
| 101 | if (!$blog_id) { exit; } |
|---|
| 102 | |
|---|
| 103 | $inCore = cmsCore::getInstance(); |
|---|
| 104 | $inDB = cmsDatabase::getInstance(); |
|---|
| 105 | |
|---|
| 106 | $inCore->loadModel('blogs'); |
|---|
| 107 | |
|---|
| 108 | $model = new cms_model_blogs(); |
|---|
| 109 | |
|---|
| 110 | $html = ''; |
|---|
| 111 | $sql = "SELECT p.*, b.seolink as bloglink, p.pubdate as fpubdate |
|---|
| 112 | FROM cms_blog_posts p |
|---|
| 113 | LEFT JOIN cms_blogs b ON b.id = p.blog_id |
|---|
| 114 | WHERE p.blog_id = $blog_id AND p.published = 1 |
|---|
| 115 | ORDER BY pubdate DESC |
|---|
| 116 | LIMIT 10"; |
|---|
| 117 | |
|---|
| 118 | $rs = $inDB->query($sql); |
|---|
| 119 | |
|---|
| 120 | if ($inDB->num_rows($rs) || $blog_id){ |
|---|
| 121 | |
|---|
| 122 | $on_moderate = $inDB->rows_count('cms_blog_posts', 'blog_id='.$blog_id.' AND published = 0'); |
|---|
| 123 | $html = '<ul>'; |
|---|
| 124 | while ($post = $inDB->fetch_assoc($rs)){ |
|---|
| 125 | $bloglink = $post['bloglink']; |
|---|
| 126 | $html .= '<li><a href="'.$model->getPostURL(null, $post['bloglink'], $post['seolink']).'">'.$post['title'].'</a> — '.$inCore->dateFormat($post['fpubdate']).'</li>'; |
|---|
| 127 | } |
|---|
| 128 | if ($is_member || $is_moder || $is_admin){ |
|---|
| 129 | $html .= '<li class="service"><a href="/blogs/'.$blog_id.'/newpost.html">Äîáàâèòü íîâûé ïîñò</li>'; |
|---|
| 130 | } |
|---|
| 131 | if (($is_admin || $is_moder) && $on_moderate){ |
|---|
| 132 | $html .= '<li><a class="on_moder" href="/blogs/'.$blog_id.'/moderate.html">Çàïèñè íà ìîäåðàöèþ</a> ('.$on_moderate.')</li>'; |
|---|
| 133 | } |
|---|
| 134 | $html .= '<li class="all"><a href="'.$model->getBlogURL(null, $bloglink).'">Âñå çàïèñè</a> ('.$inDB->rows_count('cms_blog_posts', "blog_id=$blog_id AND published=1").')</li>'; |
|---|
| 135 | $html .= '</ul>'; |
|---|
| 136 | |
|---|
| 137 | } else { |
|---|
| 138 | |
|---|
| 139 | if ($is_member || $is_moder || $is_admin){ |
|---|
| 140 | $html .= '<ul>'; |
|---|
| 141 | $html .= '<li class="service"><a href="/blogs/'.$blog_id.'/newpost.html">Äîáàâèòü íîâûé ïîñò</a></li>'; |
|---|
| 142 | $html .= '</ul>'; |
|---|
| 143 | } else { |
|---|
| 144 | $html = '<p>Â êëóáíîì áëîãå íåò çàïèñåé.</p>'; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | return $html; |
|---|
| 150 | |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | function clubPhotoAlbums($club_id, $is_admin=false, $is_moder=false, $is_member=false){ |
|---|
| 154 | $inCore = cmsCore::getInstance(); |
|---|
| 155 | $inDB = cmsDatabase::getInstance(); |
|---|
| 156 | if (!$club_id) { exit; } |
|---|
| 157 | |
|---|
| 158 | $sql = "SELECT a.id, a.title, a.pubdate, f.file, IFNULL(COUNT(f.id), 0) as content_count |
|---|
| 159 | FROM cms_photo_albums a |
|---|
| 160 | LEFT JOIN cms_photo_files f ON f.album_id = a.id AND f.published = 1 |
|---|
| 161 | WHERE a.NSDiffer='club$club_id' AND a.user_id = '$club_id' AND a.parent_id > 0 |
|---|
| 162 | GROUP BY a.id |
|---|
| 163 | ORDER BY a.id DESC LIMIT 6"; |
|---|
| 164 | |
|---|
| 165 | $rs = $inDB->query($sql); |
|---|
| 166 | |
|---|
| 167 | $albums = array(); |
|---|
| 168 | |
|---|
| 169 | if ($inDB->num_rows($rs)){ |
|---|
| 170 | while ($album = $inDB->fetch_assoc($rs)){ |
|---|
| 171 | $on_moderate = ''; |
|---|
| 172 | $delete = ''; |
|---|
| 173 | $add_to_album = ''; |
|---|
| 174 | if ($is_admin || $is_moder){ |
|---|
| 175 | $unpub = $inDB->rows_count('cms_photo_files', 'album_id='.$album['id'].' AND published = 0'); |
|---|
| 176 | if ($unpub) { |
|---|
| 177 | $album['on_moderate'] = $unpub; |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | $album['file'] = $album['file'] ? $album['file'] : 'no_image.png'; |
|---|
| 181 | $album['pubdate'] = $inCore->dateFormat($album['pubdate']); |
|---|
| 182 | $albums[] = $album; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | ob_start(); |
|---|
| 187 | |
|---|
| 188 | $smarty = $inCore->initSmarty('components', 'com_clubs_albums.tpl'); |
|---|
| 189 | $smarty->assign('albums', $albums); |
|---|
| 190 | $smarty->assign('club_id', $club_id); |
|---|
| 191 | $smarty->assign('is_admin', $is_admin); |
|---|
| 192 | $smarty->assign('is_moder', $is_moder); |
|---|
| 193 | $smarty->assign('is_member', $is_member); |
|---|
| 194 | $smarty->display('com_clubs_albums.tpl'); |
|---|
| 195 | |
|---|
| 196 | return ob_get_clean(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | function clubUserIsRole($club_id, $user_id, $role='member'){ |
|---|
| 200 | $inDB = cmsDatabase::getInstance(); |
|---|
| 201 | if (!$club_id) { return; } |
|---|
| 202 | return $inDB->rows_count('cms_user_clubs', "club_id = '$club_id' AND user_id = '$user_id' AND role='$role'")? true: false; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | function clubUserIsMember($club_id, $user_id){ |
|---|
| 206 | $inDB = cmsDatabase::getInstance(); |
|---|
| 207 | if (!$club_id) { return; } |
|---|
| 208 | return $inDB->rows_count('cms_user_clubs', "club_id = '$club_id' AND user_id = '$user_id'")? true: false; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | function clubUserIsAdmin($club_id, $user_id){ |
|---|
| 212 | $inDB = cmsDatabase::getInstance(); |
|---|
| 213 | if (!$club_id) { return; } |
|---|
| 214 | return $inDB->rows_count('cms_clubs', "id = '$club_id' AND admin_id = '$user_id'")? true: false; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | function clubModerators($club_id){ |
|---|
| 218 | $inDB = cmsDatabase::getInstance(); |
|---|
| 219 | if (!$club_id) { exit; } |
|---|
| 220 | $moders = array(); |
|---|
| 221 | $sql = "SELECT c.user_id |
|---|
| 222 | FROM cms_user_clubs c |
|---|
| 223 | WHERE c.club_id = '$club_id' AND c.role = 'moderator'"; |
|---|
| 224 | $rs = $inDB->query($sql); |
|---|
| 225 | if ($inDB->num_rows($rs)){ |
|---|
| 226 | while ($u = $inDB->fetch_assoc($rs)){ |
|---|
| 227 | if (!in_array($u['user_id'], $moders)){ |
|---|
| 228 | $moders[] = $u['user_id']; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | return $moders; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | function clubMembers($club_id){ |
|---|
| 236 | $inDB = cmsDatabase::getInstance(); |
|---|
| 237 | if (!$club_id) { exit; } |
|---|
| 238 | $members = array(); |
|---|
| 239 | $sql = "SELECT c.user_id |
|---|
| 240 | FROM cms_user_clubs c |
|---|
| 241 | WHERE c.club_id = '$club_id' AND c.role = 'member'"; |
|---|
| 242 | $rs = $inDB->query($sql); |
|---|
| 243 | if ($inDB->num_rows($rs)){ |
|---|
| 244 | while ($u = $inDB->fetch_assoc($rs)){ |
|---|
| 245 | if (!in_array($u['user_id'], $members)){ |
|---|
| 246 | $members[] = $u['user_id']; |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | return $members; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | function clubTotalMembers($club_id){ |
|---|
| 254 | $inDB = cmsDatabase::getInstance(); |
|---|
| 255 | if (!$club_id) { exit; } |
|---|
| 256 | $members = array(); |
|---|
| 257 | $sql = "SELECT 1 |
|---|
| 258 | FROM cms_user_clubs c |
|---|
| 259 | WHERE c.club_id = '$club_id' AND c.role = 'member'"; |
|---|
| 260 | $rs = $inDB->query($sql); |
|---|
| 261 | if ($inDB->num_rows($rs)){ |
|---|
| 262 | return $inDB->num_rows($rs) +1; //+1 ïîòîìó ÷òî ñ÷èòàåì åùå è àäìèíà, íå òîëüêî þçåðîâ |
|---|
| 263 | } else { |
|---|
| 264 | return 1; |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | function clubAddUser($club_id, $user_id, $role='member'){ |
|---|
| 269 | $inDB = cmsDatabase::getInstance(); |
|---|
| 270 | $inDB->query("INSERT INTO cms_user_clubs (user_id, club_id, role) VALUES ($user_id, $club_id, '$role')"); |
|---|
| 271 | return; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | function clubRemoveUser($club_id, $user_id){ |
|---|
| 275 | $inDB = cmsDatabase::getInstance(); |
|---|
| 276 | $inDB->query("DELETE FROM cms_user_clubs WHERE user_id=$user_id AND club_id=$club_id"); |
|---|
| 277 | return; |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | function clubSaveUsers($club_id, $list, $role, $clubtype='public', $cfg=false){ |
|---|
| 281 | $inCore = cmsCore::getInstance(); |
|---|
| 282 | $inDB = cmsDatabase::getInstance(); |
|---|
| 283 | $inUser = cmsUser::getInstance(); |
|---|
| 284 | if ($list){ |
|---|
| 285 | //get current club users list |
|---|
| 286 | $current_list = $inDB->get_table('cms_user_clubs', "club_id={$club_id} AND role='{$role}'", 'user_id'); |
|---|
| 287 | |
|---|
| 288 | //delete users which missed in new list |
|---|
| 289 | foreach ($current_list as $key=>$user){ |
|---|
| 290 | if (!in_array($user['user_id'], $list)){ |
|---|
| 291 | $inDB->query("DELETE FROM cms_user_clubs WHERE club_id={$club_id} AND user_id={$user['user_id']} AND role='{$role}' LIMIT 1"); |
|---|
| 292 | //send notice |
|---|
| 293 | if($cfg['notify_out'] && ($user_id != $inUser->id)){ |
|---|
| 294 | $club_title = $inDB->get_field('cms_clubs', 'id='.$club_id, 'title'); |
|---|
| 295 | cmsUser::sendMessage(USER_UPDATER, $user_id, 'Ïîëüçîâàòåëü <a href="'.cmsUser::getProfileURL($inUser->login).'">'.$inUser->nickname.'</a> èñêëþ÷èë Âàñ èç ÷èñëà ó÷àñòíèêîâ êëóáà <a href="http://'.$_SERVER['HTTP_HOST'].'/clubs/'.$club_id.'">'.$club_title.'</a>.'); |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | //add new users and update old |
|---|
| 301 | foreach ($list as $key=>$user_id){ |
|---|
| 302 | $user_id = (int)$user_id; |
|---|
| 303 | $already = $inDB->get_field('cms_user_clubs', "user_id={$user_id} AND club_id={$club_id}", 'role'); |
|---|
| 304 | if (!$already){ |
|---|
| 305 | //user first time in this club |
|---|
| 306 | $sql = "INSERT INTO cms_user_clubs (user_id, club_id, role) |
|---|
| 307 | VALUES ($user_id, $club_id, '$role')"; |
|---|
| 308 | $inDB->query($sql); |
|---|
| 309 | |
|---|
| 310 | //send notice |
|---|
| 311 | if($cfg['notify_in'] && ($user_id != $inUser->id)){ |
|---|
| 312 | $club_title = $inDB->get_field('cms_clubs', 'id='.$club_id, 'title'); |
|---|
| 313 | cmsUser::sendMessage(USER_UPDATER, $user_id, '<b>Ïîëó÷åíî ïðèãëàøåíèå â êëóá.</b> Ïîëüçîâàòåëü <a href="'.cmsUser::getProfileURL($inUser->login).'">'.$inUser->nickname.'</a> äîáàâèë Âàñ â ÷èñëî ó÷àñòíèêîâ êëóáà <a href="http://'.$_SERVER['HTTP_HOST'].'/clubs/'.$club_id.'">'.$club_title.'</a>.'); |
|---|
| 314 | } |
|---|
| 315 | } else { |
|---|
| 316 | //user already in club, update his role if necessary |
|---|
| 317 | if ($already != $role){ |
|---|
| 318 | $sql = "UPDATE cms_user_clubs |
|---|
| 319 | SET role='{$role}' |
|---|
| 320 | WHERE user_id={$user_id} AND club_id={$club_id}"; |
|---|
| 321 | $inDB->query($sql); |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | } else { |
|---|
| 326 | //if new users list is empty, drop everyone from this club |
|---|
| 327 | $inDB->query("DELETE FROM cms_user_clubs WHERE club_id={$club_id} AND role='{$role}' LIMIT 1"); |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | function clubAdminLink($club_id){ |
|---|
| 332 | $inCore = cmsCore::getInstance(); |
|---|
| 333 | $inDB = cmsDatabase::getInstance(); |
|---|
| 334 | $sql = "SELECT u.id as id, u.nickname as nickname, u.login as login, p.gender as gender |
|---|
| 335 | FROM cms_clubs c |
|---|
| 336 | LEFT JOIN cms_users u ON u.id = c.admin_id |
|---|
| 337 | LEFT JOIN cms_user_profiles p ON p.user_id = u.id |
|---|
| 338 | WHERE c.id = '$club_id'"; |
|---|
| 339 | $rs = $inDB->query($sql); |
|---|
| 340 | $html = ''; |
|---|
| 341 | if ($inDB->num_rows($rs) == 1){ |
|---|
| 342 | $usr = $inDB->fetch_assoc($rs); |
|---|
| 343 | $html .= cmsUser::getGenderLink($usr['id'], $usr['nickname'], null, $usr['gender'], $usr['login']); |
|---|
| 344 | } |
|---|
| 345 | return $html; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | function clubMembersList($club_id){ |
|---|
| 349 | $inCore = cmsCore::getInstance(); |
|---|
| 350 | $inDB = cmsDatabase::getInstance(); |
|---|
| 351 | |
|---|
| 352 | $sql = "SELECT u.id as id, u.nickname as nickname, u.login as login, p.gender as gender |
|---|
| 353 | FROM cms_user_clubs c |
|---|
| 354 | LEFT JOIN cms_users u ON u.id = c.user_id |
|---|
| 355 | LEFT JOIN cms_user_profiles p ON p.user_id = u.id |
|---|
| 356 | WHERE c.club_id = '$club_id'"; |
|---|
| 357 | |
|---|
| 358 | $rs = $inDB->query($sql); |
|---|
| 359 | $total = $inDB->num_rows($rs); |
|---|
| 360 | |
|---|
| 361 | $now=0; $html = ''; |
|---|
| 362 | |
|---|
| 363 | while($usr = $inDB->fetch_assoc($rs)){ |
|---|
| 364 | $html .= cmsUser::getGenderLink($usr['id'], $usr['nickname'], null, $usr['gender'], $usr['login']); |
|---|
| 365 | if ($now < $total-1) { $html .= ', '; } |
|---|
| 366 | $now ++; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | return $html; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | ?> |
|---|