PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gallery/index.php

https://bitbucket.org/ryanhowdy/family-connections
PHP | 1584 lines | 1097 code | 241 blank | 246 comment | 100 complexity | c0b9dfe85a16d827be4ccd257a30e073 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. <?php
  2. /**
  3. * Photo Gallery
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * @category FCMS
  8. * @package FamilyConnections
  9. * @author Ryan Haudenschilt <r.haudenschilt@gmail.com>
  10. * @copyright 2007 Haudenschilt LLC
  11. * @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
  12. * @link http://www.familycms.com/wiki/
  13. */
  14. session_start();
  15. define('URL_PREFIX', '../');
  16. define('GALLERY_PREFIX', '');
  17. require URL_PREFIX.'fcms.php';
  18. load('gallery');
  19. init('gallery/');
  20. // Globals
  21. $gallery = new PhotoGallery($fcmsUser->id);
  22. $TMPL = array(
  23. 'currentUserId' => $fcmsUser->id,
  24. 'sitename' => getSiteName(),
  25. 'nav-link' => getNavLinks(),
  26. 'pagetitle' => T_('Photo Gallery'),
  27. 'path' => URL_PREFIX,
  28. 'displayname' => $fcmsUser->displayName,
  29. 'version' => getCurrentVersion(),
  30. 'year' => date('Y')
  31. );
  32. control();
  33. exit();
  34. /**
  35. * control
  36. *
  37. * The controlling structure for this script.
  38. *
  39. * @return void
  40. */
  41. function control ()
  42. {
  43. // Edit Photo
  44. if (isset($_POST['editphoto']))
  45. {
  46. displayEditPhotoForm();
  47. }
  48. elseif (isset($_POST['add_editphoto']))
  49. {
  50. displayEditPhotoSubmit();
  51. }
  52. // Delete Photo
  53. elseif (isset($_POST['deletephoto']))
  54. {
  55. if (isset($_GET['confirmed']))
  56. {
  57. displayDeletePhotoSubmit();
  58. }
  59. else
  60. {
  61. displayConfirmDeletePhotoForm();
  62. }
  63. }
  64. // Delete Category
  65. elseif (isset($_POST['delcat']) || isset($_GET['delcat']))
  66. {
  67. if (isset($_GET['confirmed']))
  68. {
  69. displayDeleteCategorySubmit();
  70. }
  71. else
  72. {
  73. displayConfirmDeleteCategoryForm();
  74. }
  75. }
  76. // Delete Comment
  77. elseif (isset($_POST['delcom']))
  78. {
  79. if (isset($_GET['confirmed']))
  80. {
  81. displayDeleteCommentSubmit();
  82. }
  83. else
  84. {
  85. displayConfirmDeleteCommentForm();
  86. }
  87. }
  88. // Mass Tagging
  89. elseif (isset($_GET['tag']))
  90. {
  91. displayMassTagForm();
  92. }
  93. elseif (isset($_POST['submit_mass_tag']))
  94. {
  95. displayMassTagFormSubmit();
  96. }
  97. // Description
  98. elseif (isset($_GET['description']))
  99. {
  100. displayEditDescriptionForm();
  101. }
  102. elseif (isset($_POST['save-description']))
  103. {
  104. displayEditDescriptionFormSubmit();
  105. }
  106. // Actions
  107. elseif (isset($_GET['action']))
  108. {
  109. checkActionPermissions();
  110. if ($_GET['action'] == "upload")
  111. {
  112. if (isset($_POST['addphoto']))
  113. {
  114. displayUploadFormSubmit();
  115. }
  116. elseif (isset($_POST['instagram']))
  117. {
  118. displayInstagramUploadFormSubmit();
  119. }
  120. else
  121. {
  122. displayUploadForm();
  123. }
  124. }
  125. elseif ($_GET['action'] == 'advanced')
  126. {
  127. if (isset($_POST['submit_advanced_edit']))
  128. {
  129. displayUploadAdvancedFormSubmit();
  130. }
  131. else
  132. {
  133. displayUploadAdvancedForm();
  134. }
  135. }
  136. elseif ($_GET['action'] == "category")
  137. {
  138. if (isset($_POST['editcat']))
  139. {
  140. displayEditCategoryFormSubmit();
  141. }
  142. else
  143. {
  144. displayEditCategoryForm();
  145. }
  146. }
  147. }
  148. elseif (isset($_POST['addcatcom']))
  149. {
  150. displayAddCategoryCommentSubmit();
  151. }
  152. elseif (isset($_POST['addcom']))
  153. {
  154. displayAddPhotoCommentSubmit();
  155. }
  156. elseif (isset($_GET['vote']))
  157. {
  158. displayAddVoteSubmit();
  159. }
  160. elseif (isset($_GET['search']))
  161. {
  162. displaySearchForm();
  163. }
  164. // User / Category / Photo - Views
  165. elseif (isset($_GET['uid']))
  166. {
  167. if (isset($_GET['cid']))
  168. {
  169. if (isset($_GET['pid']))
  170. {
  171. displayPhoto();
  172. }
  173. else
  174. {
  175. displayCategory();
  176. }
  177. }
  178. else
  179. {
  180. displayUserCategory();
  181. }
  182. }
  183. // Frontpage
  184. else
  185. {
  186. displayLatest();
  187. }
  188. }
  189. /**
  190. * displayHeader
  191. *
  192. * @return void
  193. */
  194. function displayHeader ()
  195. {
  196. global $fcmsUser, $TMPL;
  197. $TMPL['javascript'] = '
  198. <script type="text/javascript">
  199. //<![CDATA[
  200. Event.observe(window, \'load\', function() {
  201. initChatBar(\''.T_('Chat').'\', \''.$TMPL['path'].'\');
  202. hideUploadOptions(
  203. \''.T_('Rotate Photo').'\',
  204. \''.T_('Use Existing Category').'\',
  205. \''.T_('Create New Category').'\'
  206. );
  207. hidePhotoDetails(\''.T_('More Details').'\');
  208. deleteConfirmationLink("deletephoto", "'.T_('Are you sure you want to DELETE this Photo?').'");
  209. deleteConfirmationLinks("gal_delcombtn", "'.T_('Are you sure you want to DELETE this Comment?').'");
  210. deleteConfirmationLinks("delcategory", "'.T_('Are you sure you want to DELETE this Category?').'");
  211. initNewWindow();
  212. });
  213. //]]>
  214. </script>';
  215. include_once getTheme($fcmsUser->id, $TMPL['path']).'header.php';
  216. echo '
  217. <div id="gallery" class="centercontent">';
  218. }
  219. /**
  220. * displayFooter
  221. *
  222. * @return void
  223. */
  224. function displayFooter ()
  225. {
  226. global $fcmsUser, $TMPL;
  227. echo '
  228. </div><!-- #gallery .centercontent -->';
  229. include_once getTheme($fcmsUser->id, $TMPL['path']).'footer.php';
  230. }
  231. /**
  232. * displayEditPhotoForm
  233. *
  234. * @return void
  235. */
  236. function displayEditPhotoForm ()
  237. {
  238. global $gallery;
  239. displayHeader();
  240. $gallery->displayEditPhotoForm($_POST['photo'], $_POST['url']);
  241. displayFooter();
  242. }
  243. /**
  244. * displayEditPhotoSubmit
  245. *
  246. * @return void
  247. */
  248. function displayEditPhotoSubmit ()
  249. {
  250. $uid = (int)$_GET['uid'];
  251. $photo_caption = strip_tags($_POST['photo_caption']);
  252. $photo_caption = escape_string($photo_caption);
  253. $category = strip_tags($_POST['category']);
  254. $category = escape_string($category);
  255. $cid = $category;
  256. $pid = (int)$_POST['photo_id'];
  257. $sql = "UPDATE `fcms_gallery_photos`
  258. SET `category` = '$category',
  259. `caption` = '$photo_caption'
  260. WHERE `id` = '$pid'";
  261. if (!mysql_query($sql))
  262. {
  263. displayHeader();
  264. displaySqlError($sql, mysql_error());
  265. displayFooter();
  266. return;
  267. }
  268. $tagged = isset($_POST['tagged']) ? $_POST['tagged'] : null;
  269. $prev = isset($_POST['prev_tagged_users']) ? $_POST['prev_tagged_users'] : null;
  270. if (!tagMembersInPhoto($pid, $tagged, $prev))
  271. {
  272. // error handled by tagMembersInPhoto()
  273. return;
  274. }
  275. $_SESSION['message'] = 1;
  276. header('Location: index.php?uid='.$uid.'&cid='.$cid.'&pid='.$pid);
  277. }
  278. /**
  279. * tagMembersInPhoto
  280. *
  281. * Will tag a group of members in a photo. Will also remove members who were
  282. * tagged, but now are not.
  283. *
  284. * Since 2.9 - Adds a new record to the notification table.
  285. *
  286. * @param int $photoId Id of photo
  287. * @param array $taggedMembers Array of member id's who are being tagged
  288. * @param array $prevTaggedMembers Array of member id's who are being untagged
  289. *
  290. * @return boolean
  291. */
  292. function tagMembersInPhoto ($photoId, $taggedMembers = null, $prevTaggedMembers = null)
  293. {
  294. $ids = getAddRemoveTaggedMembers($taggedMembers, $prevTaggedMembers);
  295. if ($ids === false)
  296. {
  297. $error = T_('Invalid tagged member data.');
  298. displayHeader();
  299. echo '<div class="error-alert">'.$error.'</div>';
  300. logError(__FILE__.' ['.__LINE__.'] - '.$error);
  301. displayFooter();
  302. return false;
  303. }
  304. // Nothing to add or remove
  305. if ($ids === true)
  306. {
  307. return true;
  308. }
  309. if (count($ids['add']) > 0)
  310. {
  311. $values = implode(",$photoId),(", $ids['add']);
  312. $sql = "INSERT INTO `fcms_gallery_photos_tags` (`user`, `photo`)
  313. VALUES ($values, $photoId)";
  314. if (!mysql_query($sql))
  315. {
  316. displayHeader();
  317. displaySqlError($sql, mysql_error());
  318. displayFoote();
  319. return false;
  320. }
  321. addTaggedNotifications($photoId, $ids['add']);
  322. }
  323. if (count($ids['remove']) > 0)
  324. {
  325. $in = implode(",", $ids['remove']);
  326. $sql = "DELETE FROM `fcms_gallery_photos_tags`
  327. WHERE `photo` = '$photoId'
  328. AND `user` IN ($in)";
  329. if (!mysql_query($sql))
  330. {
  331. displayHeader();
  332. displaySqlError($sql, mysql_error());
  333. displayFooter();
  334. return false;
  335. }
  336. }
  337. return true;
  338. }
  339. /**
  340. * addTaggedNotifications
  341. *
  342. * @param int $photoId
  343. * @param array $ids
  344. *
  345. * @return void
  346. */
  347. function addTaggedNotifications ($photoId, $ids)
  348. {
  349. // Get photo info
  350. $sql = "SELECT `user`, `category`, `filename`
  351. FROM `fcms_gallery_photos`
  352. WHERE `id` = '$photoId'";
  353. $result = mysql_query($sql);
  354. if (!$result)
  355. {
  356. displayHeader();
  357. displaySqlError($sql, mysql_error());
  358. displayFooter();
  359. return;
  360. }
  361. $photoInfo = array();
  362. $photoInfo = mysql_fetch_assoc($result);
  363. $values = '';
  364. $data = $photoInfo['user'].':'.$photoInfo['category'].':'.$photoId.':'.$photoInfo['filename'];
  365. foreach ($ids as $id)
  366. {
  367. $values .= "('$id', '".$photoInfo['user']."', 'tagged_photo', '$data', 0, NOW(), NOW()),";
  368. }
  369. if (strlen($values) > 0)
  370. {
  371. $values = substr($values, 0, -1); // remove trailing comma
  372. $sql = "INSERT INTO `fcms_notification` (`user`, `created_id`, `notification`, `data`, `read`, `created`, `updated`)
  373. VALUES $values";
  374. if (!mysql_query($sql))
  375. {
  376. displayHeader();
  377. displaySqlError($sql, mysql_error());
  378. displayFooter();
  379. return;
  380. }
  381. }
  382. }
  383. /**
  384. * displayConfirmDeletePhotoForm
  385. *
  386. * @return void
  387. */
  388. function displayConfirmDeletePhotoForm ()
  389. {
  390. displayHeader();
  391. echo '
  392. <div class="info-alert">
  393. <form action="index.php?confirmed=1" method="post">
  394. <h2>'.T_('Are you sure you want to DELETE this Photo?').'</h2>
  395. <p><b><i>'.T_('This can NOT be undone.').'</i></b></p>
  396. <div>
  397. <input style="float:left;" type="submit" id="deletephoto" name="deletephoto" value="'.T_('Yes').'"/>
  398. <a style="float:right;" href="index.php?'.$_POST['url'].'">'.T_('Cancel').'</a>
  399. </div>
  400. </form>
  401. </div>';
  402. displayFooter();
  403. }
  404. /**
  405. * displayDeletePhotoSubmit
  406. *
  407. * @return void
  408. */
  409. function displayDeletePhotoSubmit ()
  410. {
  411. global $gallery;
  412. $cleanPhotoId = (int)$_POST['photo'];
  413. $uploadsPath = getUploadsAbsolutePath();
  414. // Get photo info
  415. $sql = "SELECT `user`, `category`, `filename`
  416. FROM `fcms_gallery_photos`
  417. WHERE `id` = '$cleanPhotoId'";
  418. $result = mysql_query($sql);
  419. if (!$result)
  420. {
  421. displayHeader();
  422. displaySqlError($sql, mysql_error());
  423. displayFooter();
  424. return;
  425. }
  426. $filerow = mysql_fetch_array($result);
  427. $photoFilename = $filerow['filename'];
  428. $photoUserId = $filerow['user'];
  429. $photoCategory = $filerow['category'];
  430. // Remove the photo from the DB
  431. $sql = "DELETE FROM `fcms_gallery_photos`
  432. WHERE `id` = '$cleanPhotoId'";
  433. if (!mysql_query($sql))
  434. {
  435. displayHeader();
  436. displaySqlError($sql, mysql_error());
  437. displayFooter();
  438. return;
  439. }
  440. // Remove any comments for this photo
  441. $sql = "DELETE FROM `fcms_gallery_photo_comment`
  442. WHERE `photo` = '$cleanPhotoId'";
  443. if (!mysql_query($sql))
  444. {
  445. displayHeader();
  446. displaySqlError($sql, mysql_error());
  447. displayFooter();
  448. return;
  449. }
  450. // Remove the Photo from the server
  451. unlink($uploadsPath.'photos/member'.$photoUserId.'/'.basename($photoFilename));
  452. unlink($uploadsPath.'photos/member'.$photoUserId.'/tb_'.basename($photoFilename));
  453. if ($gallery->usingFullSizePhotos())
  454. {
  455. unlink($uploadsPath.'photos/member'.$photoUserId.'/full_'.basename($photoFilename));
  456. }
  457. $_SESSION['message'] = 1;
  458. header("Location: index.php?uid=$photoUserId&cid=$photoCategory");
  459. }
  460. /**
  461. * checkActionPermissions
  462. *
  463. * @return void
  464. */
  465. function checkActionPermissions ()
  466. {
  467. global $fcmsUser;
  468. $access = checkAccess($fcmsUser->id);
  469. // Catch users who can't upload photos, create categories, etc.
  470. if ( $access == NON_POSTER_USER
  471. || $access == PHOTOGRAPHER_USER
  472. || $access == GUEST_USER
  473. || $access == NON_EDIT_USER
  474. )
  475. {
  476. displayHeader();
  477. echo '
  478. <div class="error-alert">'.T_('You do NOT have access to perform this action.').'</div>';
  479. displayFooter();
  480. die();
  481. }
  482. }
  483. /**
  484. * displayUploadForm
  485. *
  486. * @return void
  487. */
  488. function displayUploadForm ()
  489. {
  490. global $fcmsUser, $gallery;
  491. displayHeader();
  492. $gallery->displayGalleryMenu('none');
  493. if (isset($_SESSION['error_message']))
  494. {
  495. echo '
  496. <div class="error-alert">
  497. '.$_SESSION['error_message'].'
  498. </div>';
  499. unset($_SESSION['error_message']);
  500. }
  501. // Turn on advanced uploader
  502. if (isset($_GET['advanced']))
  503. {
  504. $sql = "UPDATE `fcms_user_settings`
  505. SET `advanced_upload` = '1'
  506. WHERE `user` = '$fcmsUser->id'";
  507. if (!mysql_query($sql))
  508. {
  509. displaySqlError($sql, mysql_error());
  510. }
  511. }
  512. // Special upload type?
  513. if (isset($_GET['type']))
  514. {
  515. if ($_GET['type'] == 'instagram')
  516. {
  517. $gallery->displayInstagramUploadForm();
  518. displayFooter();
  519. return;
  520. }
  521. }
  522. // Advanced Uploader
  523. if (usingAdvancedUploader($fcmsUser->id))
  524. {
  525. $gallery->displayJavaUploadForm();
  526. }
  527. // Basic Uploader
  528. else
  529. {
  530. $overrideMemoryLimit = isset($_GET['memory']) ? true : false;
  531. $gallery->displayUploadForm($overrideMemoryLimit);
  532. }
  533. displayFooter();
  534. }
  535. /**
  536. * displayUploadFormSubmit
  537. *
  538. * @return void
  539. */
  540. function displayUploadFormSubmit ()
  541. {
  542. global $gallery, $fcmsUser;
  543. // Catch photos that are too large
  544. if ($_FILES['photo_filename']['error'] == 1)
  545. {
  546. $max = ini_get('upload_max_filesize');
  547. $link = 'index.php?action=upload&amp;advanced=1';
  548. $_SESSION['error_message'] = '<p>'.sprintf(T_('Your photo exceeds the maximum size allowed by your PHP settings [%s].'), $max).'</p>';
  549. $_SESSION['error_message'] .= '<p>'.sprintf(T_('Would you like to use the <a href="%s">Advanced Photo Uploader</a> instead?.'), $link).'</p>';
  550. header('Location: index.php?action=upload');
  551. return;
  552. }
  553. // Make sure we have a category
  554. if (empty($_POST['new-category']) && empty($_POST['category']))
  555. {
  556. $_SESSION['error_message'] = '<p>'.T_('You must choose a category first.').'</p>';
  557. header('Location: index.php?action=upload');
  558. return;
  559. }
  560. // Make sure we have a photo
  561. if ($_FILES['photo_filename']['error'] == 4)
  562. {
  563. $_SESSION['error_message'] = '<p>'.T_('You must choose a photo first.').'</p>';
  564. header('Location: index.php?action=upload');
  565. return;
  566. }
  567. // Create a new category
  568. if (!empty($_POST['new-category']))
  569. {
  570. $newCategory = strip_tags($_POST['new-category']);
  571. $newCategory = escape_string($newCategory);
  572. $sql = "INSERT INTO `fcms_category`(`name`, `type`, `user`)
  573. VALUES (
  574. '$newCategory',
  575. 'gallery',
  576. '$fcmsUser->id'
  577. )";
  578. if (!mysql_query($sql))
  579. {
  580. displayHeader();
  581. displaySqlError($sql, mysql_error());
  582. displayFooter();
  583. return;
  584. }
  585. $cleanCategory = mysql_insert_id();
  586. }
  587. // Existing category
  588. else
  589. {
  590. $cleanCategory = (int)$_POST['category'];
  591. }
  592. // Rotate photo
  593. $cleanRotate = '0';
  594. if (isset($_POST['rotate']))
  595. {
  596. $cleanRotate = escape_string($_POST['rotate']);
  597. }
  598. $caption = strip_tags($_POST['photo_caption']);
  599. $cleanCaption = escape_string($caption);
  600. $memory = isset($_POST['memory_override']) ? true : false;
  601. displayHeader();
  602. $gallery->displayGalleryMenu('none');
  603. // Upload photo
  604. $newPhotoId = $gallery->uploadPhoto($cleanCategory, $_FILES['photo_filename'], $cleanCaption, $cleanRotate, $memory);
  605. // Upload failed
  606. if ($newPhotoId == false)
  607. {
  608. displayFooter();
  609. return;
  610. }
  611. // Tag photo
  612. if (isset($_POST['tagged']))
  613. {
  614. if (!tagMembersInPhoto($newPhotoId, $_POST['tagged']))
  615. {
  616. // error handled by tagMembersInPhoto()
  617. return;
  618. }
  619. }
  620. // Email members
  621. $sql = "SELECT u.`email`, s.`user`
  622. FROM `fcms_user_settings` AS s, `fcms_users` AS u
  623. WHERE `email_updates` = '1'
  624. AND u.`id` = s.`user`";
  625. $result = mysql_query($sql);
  626. if (!$result)
  627. {
  628. displaySqlError($sql, mysql_error());
  629. displayFooter();
  630. return;
  631. }
  632. if (mysql_num_rows($result) > 0)
  633. {
  634. while ($r = mysql_fetch_array($result))
  635. {
  636. $name = getUserDisplayName($fcmsUser->id);
  637. $to = getUserDisplayName($r['user']);
  638. $subject = sprintf(T_('%s has added a new photo.'), $name);
  639. $email = $r['email'];
  640. $url = getDomainAndDir();
  641. $email_headers = getEmailHeaders();
  642. $msg = T_('Dear').' '.$to.',
  643. '.$subject.'
  644. '.$url.'index.php?uid='.$fcmsUser->id.'&cid='.$cleanCategory.'
  645. ----
  646. '.T_('To stop receiving these notifications, visit the following url and change your \'Email Update\' setting to No:').'
  647. '.$url.'settings.php
  648. ';
  649. mail($email, $subject, $msg, $email_headers);
  650. }
  651. }
  652. displayFooter();
  653. }
  654. /**
  655. * displayInstagramUploadFormSubmit
  656. *
  657. * @return void
  658. */
  659. function displayInstagramUploadFormSubmit ()
  660. {
  661. global $gallery, $fcmsUser;
  662. // Turn on auto upload for Instagram
  663. if (isset($_POST['automatic']))
  664. {
  665. $sql = "UPDATE `fcms_user_settings`
  666. SET `instagram_auto_upload` = '1'
  667. WHERE `user` = '$fcmsUser->id'";
  668. $result = mysql_query($sql);
  669. if (!$result)
  670. {
  671. displayHeader();
  672. displaySqlError($sql, mysql_error());
  673. displayFooter();
  674. return;
  675. }
  676. displayHeader();
  677. $gallery->displayGalleryMenu('none');
  678. echo '
  679. <div class="info-alert">
  680. <p>'.T_('Your Instagram photos will be automatically imported into the site soon.').'</p>
  681. </div>';
  682. displayFooter();
  683. return;
  684. }
  685. // Turn off auto upload for Instagram
  686. elseif (!isset($_POST['photos']))
  687. {
  688. $sql = "UPDATE `fcms_user_settings`
  689. SET `instagram_auto_upload` = '0'
  690. WHERE `user` = '$fcmsUser->id'";
  691. $result = mysql_query($sql);
  692. if (!$result)
  693. {
  694. displayHeader();
  695. displaySqlError($sql, mysql_error());
  696. displayFooter();
  697. return;
  698. }
  699. displayHeader();
  700. $gallery->displayGalleryMenu('none');
  701. echo '
  702. <div class="info-alert">
  703. <p>'.T_('Your Instagram photos will no longer be automatically imported into the site soon.').'</p>
  704. </div>';
  705. displayFooter();
  706. return;
  707. }
  708. // Upload individual photos
  709. if (isset($_POST['photos']))
  710. {
  711. $categoryId = getUserInstagramCategory($fcmsUser->id);
  712. $existingIds = getExistingInstagramIds();
  713. foreach ($_POST['photos'] AS $data)
  714. {
  715. list($sourceId, $thumbnail, $medium, $full, $caption) = explode('|', $data);
  716. // Skip existing photos
  717. if (isset($existingIds[$sourceId]))
  718. {
  719. continue;
  720. }
  721. // Save external paths
  722. $sql = "INSERT INTO `fcms_gallery_external_photo`
  723. (`source_id`, `thumbnail`, `medium`, `full`)
  724. VALUES
  725. ('$sourceId', '$thumbnail', '$medium', '$full')";
  726. $result = mysql_query($sql);
  727. if (!$result)
  728. {
  729. displayHeader();
  730. displaySqlError($sql, mysql_error());
  731. displayFooter();
  732. return;
  733. }
  734. $id = mysql_insert_id();
  735. // Insert new photo
  736. $sql = "INSERT INTO `fcms_gallery_photos`
  737. (`date`, `external_id`, `caption`, `category`, `user`)
  738. VALUES
  739. (NOW(), '$id', '$caption', '$categoryId', '$fcmsUser->id')";
  740. $result = mysql_query($sql);
  741. if (!$result)
  742. {
  743. displayHeader();
  744. displaySqlError($sql, mysql_error());
  745. displayFooter();
  746. return;
  747. }
  748. }
  749. // Email members
  750. $sql = "SELECT u.`email`, s.`user`
  751. FROM `fcms_user_settings` AS s, `fcms_users` AS u
  752. WHERE `email_updates` = '1'
  753. AND u.`id` = s.`user`";
  754. $result = mysql_query($sql);
  755. if (!$result)
  756. {
  757. displaySqlError($sql, mysql_error());
  758. displayFooter();
  759. return;
  760. }
  761. if (mysql_num_rows($result) > 0)
  762. {
  763. while ($r = mysql_fetch_array($result))
  764. {
  765. $name = getUserDisplayName($fcmsUser->id);
  766. $to = getUserDisplayName($r['user']);
  767. $subject = sprintf(T_('%s has added new photos.'), $name);
  768. $email = $r['email'];
  769. $url = getDomainAndDir();
  770. $email_headers = getEmailHeaders();
  771. $msg = T_('Dear').' '.$to.',
  772. '.$subject.'
  773. '.$url.'index.php?uid='.$fcmsUser->id.'&cid='.$categoryId.'
  774. ----
  775. '.T_('To stop receiving these notifications, visit the following url and change your \'Email Update\' setting to No:').'
  776. '.$url.'settings.php
  777. ';
  778. mail($email, $subject, $msg, $email_headers);
  779. }
  780. }
  781. header('Location: index.php?uid='.$fcmsUser->id.'&cid='.$categoryId);
  782. }
  783. }
  784. /**
  785. * displayUploadAdvancedForm
  786. *
  787. * @return void
  788. */
  789. function displayUploadAdvancedForm ()
  790. {
  791. global $gallery;
  792. displayHeader();
  793. $gallery->displayAdvancedUploadEditForm();
  794. // clear the photos in the session
  795. unset($_SESSION['photos']);
  796. unset($_SESSION['mass_photos_category']);
  797. displayFooter();
  798. }
  799. /**
  800. * displayUploadAdvancedFormSubmit
  801. *
  802. * @return void
  803. */
  804. function displayUploadAdvancedFormSubmit ()
  805. {
  806. global $fcmsUser;
  807. // Categories should all be the same
  808. $cleanCategory = (int)$_POST['category'][0];
  809. // Loop through each photo
  810. for ($i=0; $i < count($_POST['id']); $i++)
  811. {
  812. $caption = strip_tags($_POST['caption'][$i]);
  813. $cleanCaption = escape_string($caption);
  814. $cleanId = (int)$_POST['id'][$i];
  815. // Update the caption
  816. $sql = "UPDATE `fcms_gallery_photos`
  817. SET `category` = '$cleanCategory',
  818. `caption` = '$cleanCaption'
  819. WHERE `id` = '$cleanId'";
  820. if (!mysql_query($sql))
  821. {
  822. displayHeader();
  823. displaySqlError($sql, mysql_error());
  824. displayFooter();
  825. return;
  826. }
  827. // Tag members
  828. if (isset($_POST['tagged']))
  829. {
  830. if (isset($_POST['tagged'][$i]))
  831. {
  832. if (!tagMembersInPhoto($cleanId, $_POST['tagged'][$i]))
  833. {
  834. // error handled by tagMembersInPhoto()
  835. return;
  836. }
  837. }
  838. }
  839. }
  840. header("Location: index.php?uid=$fcmsUser->id&cid=$cleanCategory");
  841. }
  842. /**
  843. * displayEditCategoryFormSubmit
  844. *
  845. * @return void
  846. */
  847. function displayEditCategoryFormSubmit ()
  848. {
  849. $categoryId = (int)$_POST['cid'];
  850. $categoryName = strip_tags($_POSt['cat_name']);
  851. $cleanCategoryName = escape_string($categoryName);
  852. if (empty($categoryName))
  853. {
  854. displayHeader();
  855. echo '
  856. <p class="error-alert">'.T_('Category name cannot be blank.').'</p>';
  857. displayFooter();
  858. }
  859. $sql = "UPDATE fcms_category
  860. SET `name` = '$cleanCategoryName'
  861. WHERE `id` = '$categoryId'";
  862. if (!mysql_query($sql))
  863. {
  864. displayHeader();
  865. displaySqlError($sql, mysql_error());
  866. displayFooter();
  867. return;
  868. }
  869. $_SESSION['message'] = sprintf(T_('The Category %s was Updated Successfully'), "<b>".$categoryName."</b>");
  870. header("Location: index.php?action=category");
  871. }
  872. /**
  873. * displayEditCategoryForm
  874. *
  875. * @return void
  876. */
  877. function displayEditCategoryForm ()
  878. {
  879. global $gallery;
  880. displayHeader();
  881. if (isset($_SESSION['message']))
  882. {
  883. displayOkMessage($_SESSION['message']);
  884. unset($_SESSION['message']);
  885. }
  886. $gallery->displayGalleryMenu();
  887. $gallery->displayCategoryForm();
  888. displayFooter();
  889. }
  890. /**
  891. * displayConfirmDeleteCategoryForm
  892. *
  893. * @return void
  894. */
  895. function displayConfirmDeleteCategoryForm ()
  896. {
  897. displayHeader();
  898. echo '
  899. <div class="info-alert">
  900. <form action="index.php?confirmed=1" method="post">
  901. <h2>'.T_('Are you sure you want to DELETE this category?').'</h2>
  902. <p><b><i>'.T_('This can NOT be undone.').'</i></b></p>
  903. <div>
  904. <input type="hidden" name="cid" value="'.(int)$_POST['cid'].'"/>
  905. <input style="float:left;" type="submit" id="delcat" name="delcat" value="'.T_('Yes').'"/>
  906. <a style="float:right;" href="index.php?action=category">'.T_('Cancel').'</a>
  907. </div>
  908. </form>
  909. </div>';
  910. displayFooter();
  911. }
  912. /**
  913. * displayDeleteCategorySubmit
  914. *
  915. * @return void
  916. */
  917. function displayDeleteCategorySubmit ()
  918. {
  919. global $fcmsUser;
  920. $cid = 0;
  921. if (isset($_GET['delcat']))
  922. {
  923. $cid = (int)$_GET['delcat'];
  924. }
  925. elseif (isset($_POST['cid']))
  926. {
  927. $cid = (int)$_POST['cid'];
  928. }
  929. else
  930. {
  931. displayHeader();
  932. echo '<p class="error-alert">'.T_('Missing or invalid id.').'</p>';
  933. displayFooter();
  934. return;
  935. }
  936. // Get category info
  937. $sql = "SELECT `user`
  938. FROM `fcms_category`
  939. WHERE `id` = '$cid'
  940. LIMIT 1";
  941. $result = mysql_query($sql);
  942. if (!$result)
  943. {
  944. displayHeader();
  945. displaySqlError($sql, mysql_error());
  946. displayFooter();
  947. return;
  948. }
  949. $row = mysql_fetch_array($result);
  950. // Do you permission to delete?
  951. if ($fcmsUser->id != $row['user'])
  952. {
  953. displayHeader();
  954. echo '<p class="error-alert">'.T_('You do not have permission to perform this task.').'</p>';
  955. displayFooter();
  956. return;
  957. }
  958. $sql = "DELETE FROM fcms_category
  959. WHERE `id` = '$cid'
  960. AND `user` = '$fcmsUser->id'";
  961. if (!mysql_query($sql))
  962. {
  963. displayHeader();
  964. displaySqlError($sql, mysql_error());
  965. displayFooter();
  966. return;
  967. }
  968. $_SESSION['message'] = T_('Category Deleted Successfully');
  969. header("Location: index.php?action=category");
  970. }
  971. /**
  972. * displayMassTagForm
  973. *
  974. * @return void
  975. */
  976. function displayMassTagForm ()
  977. {
  978. global $gallery;
  979. displayHeader();
  980. $category = (int)$_GET['tag'];
  981. $user = (int)$_GET['user'];
  982. $gallery->displayMassTagCategory($category, $user);
  983. displayFooter();
  984. }
  985. /**
  986. * displayMassTagFormSubmit
  987. *
  988. * @return void
  989. */
  990. function displayMassTagFormSubmit ()
  991. {
  992. $uid = (int)$_GET['uid'];
  993. $cid = (int)$_GET['cid'];
  994. $photos = array();
  995. $photos1 = array();
  996. $photos2 = array();
  997. // Get all photo ids
  998. if (isset($_POST['tagged']))
  999. {
  1000. $photos1 = array_keys($_POST['tagged']);
  1001. }
  1002. if (isset($_POST['prev_tagged_users']))
  1003. {
  1004. $photos2 = array_keys($_POST['prev_tagged_users']);
  1005. }
  1006. $photos = array_merge($photos1, $photos2);
  1007. $photos = array_unique($photos);
  1008. // Loop through each photo
  1009. foreach ($photos as $pid)
  1010. {
  1011. $tagged = isset($_POST['tagged'][$pid]) ? $_POST['tagged'][$pid] : null;
  1012. $prev = isset($_POST['prev_tagged_users'][$pid]) ? $_POST['prev_tagged_users'][$pid] : null;
  1013. if (!tagMembersInPhoto($pid, $tagged, $prev))
  1014. {
  1015. // error handled by tagMembersInPhoto()
  1016. return;
  1017. }
  1018. }
  1019. $_SESSION['message'] = 1;
  1020. header("Location: index.php?uid=$uid&cid=$cid");
  1021. }
  1022. /**
  1023. * displayPhoto
  1024. *
  1025. * @return void
  1026. */
  1027. function displayPhoto ()
  1028. {
  1029. global $gallery;
  1030. displayHeader();
  1031. if (isset($_SESSION['message']))
  1032. {
  1033. unset($_SESSION['message']);
  1034. displayOkMessage();
  1035. }
  1036. $uid = (int)$_GET['uid'];
  1037. $cid = $_GET['cid']; // not always an #
  1038. $pid = (int)$_GET['pid'];
  1039. $gallery->showPhoto($uid, $cid, $pid);
  1040. displayFooter();
  1041. }
  1042. /**
  1043. * displayCategory
  1044. *
  1045. * @return void
  1046. */
  1047. function displayCategory ()
  1048. {
  1049. global $gallery;
  1050. displayHeader();
  1051. if (isset($_SESSION['message']))
  1052. {
  1053. unset($_SESSION['message']);
  1054. displayOkMessage();
  1055. }
  1056. $page = getPage();
  1057. $gallery->displayGalleryMenu($_GET['uid'], $_GET['cid']);
  1058. $gallery->showCategories($page, $_GET['uid'], $_GET['cid']);
  1059. displayFooter();
  1060. }
  1061. /**
  1062. * displayUserCategory
  1063. *
  1064. * @return void
  1065. */
  1066. function displayUserCategory ()
  1067. {
  1068. global $gallery;
  1069. displayHeader();
  1070. $page = getPage();
  1071. $gallery->displayGalleryMenu($_GET['uid']);
  1072. $gallery->showCategories($page, $_GET['uid']);
  1073. displayFooter();
  1074. }
  1075. /**
  1076. * displayAddCategoryCommentSubmit
  1077. *
  1078. * @return void
  1079. */
  1080. function displayAddCategoryCommentSubmit ()
  1081. {
  1082. global $fcmsUser;
  1083. $uid = (int)$_GET['uid'];
  1084. $cid = (int)$_GET['cid'];
  1085. $com = ltrim($_POST['comment']);
  1086. $com = strip_tags($com);
  1087. $cleanCom = escape_string($com);
  1088. if (!empty($com))
  1089. {
  1090. $sql = "INSERT INTO `fcms_gallery_category_comment` (
  1091. `category_id`, `comment`, `created`, `created_id`
  1092. ) VALUES (
  1093. '$cid',
  1094. '$cleanCom',
  1095. NOW(),
  1096. '$fcmsUser->id'
  1097. )";
  1098. if (!mysql_query($sql))
  1099. {
  1100. displayHeader();
  1101. displaySqlError($sql, mysql_error());
  1102. displayFooter();
  1103. return;
  1104. }
  1105. }
  1106. $commentId = mysql_insert_id();
  1107. header('Location: index.php?uid='.$uid.'&cid='.$cid.'#comment'.$commentId);
  1108. }
  1109. /**
  1110. * displayAddPhotoCommentSubmit
  1111. *
  1112. * @return void
  1113. */
  1114. function displayAddPhotoCommentSubmit ()
  1115. {
  1116. global $fcmsUser;
  1117. $uid = (int)$_GET['uid'];
  1118. $cid = $_GET['cid']; // not always an #
  1119. $pid = (int)$_GET['pid'];
  1120. $com = ltrim($_POST['post']);
  1121. $com = strip_tags($com);
  1122. $cleanCom = escape_string($com);
  1123. if (!empty($com))
  1124. {
  1125. $sql = "INSERT INTO `fcms_gallery_photo_comment` (
  1126. `photo`, `comment`, `date`, `user`
  1127. ) VALUES (
  1128. '$pid',
  1129. '$cleanCom',
  1130. NOW(),
  1131. '$fcmsUser->id'
  1132. )";
  1133. if (!mysql_query($sql))
  1134. {
  1135. displayHeader();
  1136. displaySqlError($sql, mysql_error());
  1137. displayFooter();
  1138. return;
  1139. }
  1140. }
  1141. $commentId = mysql_insert_id();
  1142. header('Location: index.php?uid='.$uid.'&cid='.$cid.'&pid='.$pid.'#comment'.$commentId);
  1143. }
  1144. /**
  1145. * displayAddVoteSubmit
  1146. *
  1147. * @return void
  1148. */
  1149. function displayAddVoteSubmit ()
  1150. {
  1151. $uid = (int)$_GET['uid'];
  1152. $cid = $_GET['cid']; // not always an #
  1153. $pid = (int)$_GET['pid'];
  1154. $vote = (int)$_GET['vote'];
  1155. $sql = "UPDATE `fcms_gallery_photos`
  1156. SET `votes` = `votes`+1,
  1157. `rating` = `rating`+$vote
  1158. WHERE `id` = '$pid'";
  1159. if (!mysql_query($sql))
  1160. {
  1161. displayHeader();
  1162. displaySqlError($sql, mysql_error());
  1163. displayFooter();
  1164. return;
  1165. }
  1166. header('Location: index.php?uid='.$uid.'&cid='.$cid.'&pid='.$pid);
  1167. }
  1168. /**
  1169. * displayDeleteCommentSubmit
  1170. *
  1171. * @return void
  1172. */
  1173. function displayDeleteCommentSubmit ()
  1174. {
  1175. $uid = (int)$_POST['uid'];
  1176. $cid = $_POST['cid']; // not always an #
  1177. $pid = (int)$_POST['pid'];
  1178. $id = (int)$_POST['id'];
  1179. $sql = "DELETE FROM `fcms_gallery_photo_comment`
  1180. WHERE `id` = '$id'";
  1181. if (!mysql_query($sql))
  1182. {
  1183. displayHeader();
  1184. displaySqlError($sql, mysql_error());
  1185. displayFooter();
  1186. return;
  1187. }
  1188. header('Location: index.php?uid='.$uid.'&cid='.$cid.'&pid='.$pid);
  1189. }
  1190. /**
  1191. * displayConfirmDeleteCommentForm
  1192. *
  1193. * @return void
  1194. */
  1195. function displayConfirmDeleteCommentForm ()
  1196. {
  1197. $uid = (int)$_GET['uid'];
  1198. $cid = $_GET['cid']; // not always an #
  1199. $pid = (int)$_GET['pid'];
  1200. $id = (int)$_POST['id'];
  1201. displayHeader();
  1202. echo '
  1203. <div class="info-alert">
  1204. <form action="index.php?confirmed=1" method="post">
  1205. <h2>'.T_('Are you sure you want to DELETE this Comment?').'</h2>
  1206. <p><b><i>'.T_('This can NOT be undone.').'</i></b></p>
  1207. <div>
  1208. <input type="hidden" name="uid" value="'.$uid.'"/>
  1209. <input type="hidden" name="cid" value="'.cleanOutput($cid).'"/>
  1210. <input type="hidden" name="pid" value="'.$pid.'"/>
  1211. <input type="hidden" name="id" value="'.$id.'"/>
  1212. <input style="float:left;" type="submit" id="delcom" name="delcom" value="'.T_('Yes').'"/>
  1213. <a style="float:right;" href="index.php?uid='.$uid.'&amp;cid='.cleanOutput($cid).'&amp;pid='.$pid.'">'.T_('Cancel').'</a>
  1214. </div>
  1215. </form>
  1216. </div>';
  1217. displayFooter();
  1218. }
  1219. /**
  1220. * displaySearchForm
  1221. *
  1222. * @return void
  1223. */
  1224. function displaySearchForm ()
  1225. {
  1226. global $gallery;
  1227. displayHeader();
  1228. $gallery->displayGalleryMenu();
  1229. $gallery->displaySearchForm();
  1230. displayFooter();
  1231. }
  1232. /**
  1233. * displayLatest
  1234. *
  1235. * @return void
  1236. */
  1237. function displayLatest ()
  1238. {
  1239. global $gallery;
  1240. displayHeader();
  1241. $gallery->displayGalleryMenu();
  1242. $foundPhotos = $gallery->displayLatestCategories();
  1243. if ($foundPhotos)
  1244. {
  1245. $gallery->showCategories(-1, '0', 'comments');
  1246. echo '
  1247. <p class="alignright"><a class="rss" href="../rss.php?feed=gallery">'.T_('RSS Feed').'</a></p>';
  1248. }
  1249. displayFooter();
  1250. }
  1251. /**
  1252. * displayEditDescriptionForm
  1253. *
  1254. * @param int $uid
  1255. * @param int $cid
  1256. *
  1257. * @return void
  1258. */
  1259. function displayEditDescriptionForm ()
  1260. {
  1261. displayHeader();
  1262. $uid = (int)$_GET['user'];
  1263. $cid = (int)$_GET['description'];
  1264. $sql = "SELECT `user`, `description`
  1265. FROM `fcms_category`
  1266. WHERE `id` = '$cid'";
  1267. $result = mysql_query($sql);
  1268. if (!$result)
  1269. {
  1270. displaySqlError($sql, mysql_error());
  1271. displayFooter();
  1272. return;
  1273. }
  1274. if (mysql_num_rows($result) <= 0)
  1275. {
  1276. echo '
  1277. <div class="error-alert">'.T_('Invalid ID.').'</div>';
  1278. displayFooter();
  1279. return;
  1280. }
  1281. $row = mysql_fetch_assoc($result);
  1282. // Can the member edit description
  1283. if ($row['user'] != $uid)
  1284. {
  1285. echo '
  1286. <div class="error-alert">'.T_('You do NOT have access to perform this action.').'</div>';
  1287. displayFooter();
  1288. return;
  1289. }
  1290. echo '
  1291. <fieldset>
  1292. <legend><span>'.T_('Category Description').'</span></legend>
  1293. <form action="index.php" method="post">
  1294. <div class="field-row">
  1295. <div class="field-label"></div>
  1296. <div class="field-widget">
  1297. <textarea id="description" name="description" cols="63" rows="10">'.$row['description'].'</textarea>
  1298. </div>
  1299. </div>
  1300. <p>
  1301. <input type="hidden" name="uid" id="uid" value="'.$uid.'"/>
  1302. <input type="hidden" name="cid" id="cid" value="'.$cid.'"/>
  1303. <input class="sub1" type="submit" name="save-description" value="'.T_('Edit').'"/>
  1304. '.T_('or').' <a href="index.php?uid='.$uid.'&amp;cid='.$cid.'">'.T_('Cancel').'</a>
  1305. </p>
  1306. </form>
  1307. </fieldset>';
  1308. displayFooter();
  1309. }
  1310. /**
  1311. * displayEditDescriptionFormSubmit
  1312. *
  1313. * @return void
  1314. */
  1315. function displayEditDescriptionFormSubmit ()
  1316. {
  1317. $uid = (int)$_POST['uid'];
  1318. $cid = (int)$_POST['cid'];
  1319. $description = strip_tags($_POST['description']);
  1320. $description = escape_string($description);
  1321. $sql = "UPDATE `fcms_category`
  1322. SET `description` = '$description'
  1323. WHERE `id` = $cid";
  1324. if (!mysql_query($sql))
  1325. {
  1326. displayHeader();
  1327. displaySqlError($sql, mysql_error());
  1328. displayFooter();
  1329. return;
  1330. }
  1331. $_SESSION['message'] = T_('Changes Updated Successfully');
  1332. header('Location: index.php?uid='.$uid.'&cid='.$cid);
  1333. }