PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/album/ip_root/album_edit.php

https://github.com/MightyGorgon/icy_phoenix_plugins
PHP | 182 lines | 111 code | 30 blank | 41 comment | 15 complexity | f46e60e15fac8e0a82e5e57c95b83e56 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Smartor (smartor_xp@hotmail.com)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  20. // Start session management
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23. $user->setup();
  24. // End session management
  25. // Get general album information
  26. $plugin_name = 'album';
  27. if (empty($config['plugins'][$plugin_name]['enabled']))
  28. {
  29. message_die(GENERAL_MESSAGE, 'PLUGIN_DISABLED');
  30. }
  31. $cms_page['page_id'] = 'album_edit';
  32. $cms_page['page_nav'] = (!empty($cms_config_layouts[$cms_page['page_id']]['page_nav']) ? true : false);
  33. $cms_page['global_blocks'] = (!empty($cms_config_layouts[$cms_page['page_id']]['global_blocks']) ? true : false);
  34. $cms_auth_level = (isset($cms_config_layouts[$cms_page['page_id']]['view']) ? $cms_config_layouts[$cms_page['page_id']]['view'] : AUTH_ALL);
  35. check_page_auth($cms_page['page_id'], $cms_auth_level);
  36. include(IP_ROOT_PATH . PLUGINS_PATH . $config['plugins'][$plugin_name]['dir'] . 'common.' . PHP_EXT);
  37. // ------------------------------------
  38. // Check the request
  39. // ------------------------------------
  40. $pic_id = request_var('pic_id', 0);
  41. if ($pic_id <= 0)
  42. {
  43. message_die(GENERAL_MESSAGE, $lang['NO_PICS_SPECIFIED']);
  44. }
  45. // ------------------------------------
  46. // Get this pic info and current Category Info
  47. // ------------------------------------
  48. $sql = "SELECT p.*, c.*
  49. FROM ". ALBUM_TABLE ." AS p, ". ALBUM_CAT_TABLE ." AS c
  50. WHERE p.pic_id = '$pic_id'
  51. AND c.cat_id = p.pic_cat_id";
  52. $result = $db->sql_query($sql);
  53. $thispic = $db->sql_fetchrow($result);
  54. $cat_id = $thispic['cat_id'];
  55. $album_user_id = $thispic['cat_user_id'];
  56. $pic_filename = $thispic['pic_filename'];
  57. $pic_thumbnail = $thispic['pic_thumbnail'];
  58. if( empty($thispic) )
  59. {
  60. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  61. }
  62. // ------------------------------------
  63. // Check the permissions
  64. // ------------------------------------
  65. $album_user_access = album_permissions($album_user_id, $cat_id, ALBUM_AUTH_EDIT, $thispic);
  66. if ($album_user_access['edit'] == 0)
  67. {
  68. if (!$user->data['session_logged_in'])
  69. {
  70. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=album_edit.' . PHP_EXT . '?pic_id=' . $pic_id));
  71. }
  72. else
  73. {
  74. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  75. }
  76. }
  77. else
  78. {
  79. if((!$album_user_access['moderator']) && ($user->data['user_level'] != ADMIN))
  80. {
  81. if ($thispic['pic_user_id'] != $user->data['user_id'])
  82. {
  83. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  84. }
  85. }
  86. }
  87. /*
  88. +----------------------------------------------------------
  89. | Main work here...
  90. +----------------------------------------------------------
  91. */
  92. $pic_title = request_post_var('pic_title', '', true);
  93. $pic_desc = request_post_var('pic_desc', '', true);
  94. $pic_desc = substr($pic_desc, 0, $album_config['desc_length']);
  95. if(empty($pic_title))
  96. {
  97. $html_status = ($config['allow_html']) ? $lang['HTML_is_ON'] : $lang['HTML_is_OFF'];
  98. $bbcode_status = ($config['allow_bbcode']) ? $lang['BBCode_is_ON'] : $lang['BBCode_is_OFF'];
  99. $bbcode_status = sprintf($bbcode_status, '<a href="' . append_sid('faq.' . PHP_EXT . '?mode=bbcode') . '" target="_blank">', '</a>');
  100. $smilies_status = ($config['allow_smilies']) ? $lang['Smilies_are_ON'] : $lang['Smilies_are_OFF'];
  101. $formatting_status = '<br />' . $html_status . '<br />' . $bbcode_status . '<br />' . $smilies_status . '<br />';
  102. $template->assign_vars(array(
  103. 'L_EDIT_PIC_INFO' => $lang['Edit_Pic_Info'],
  104. 'CAT_TITLE' => $thispic['cat_title'],
  105. 'U_VIEW_CAT' => append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id)),
  106. 'L_PIC_ID' => $lang['Pic_ID'],
  107. 'L_PIC_TITLE' => $lang['Pic_Image'],
  108. 'PIC_ID' => $pic_id,
  109. 'PIC_TITLE' => $thispic['pic_title'],
  110. 'PIC_DESC' => $thispic['pic_desc'],
  111. 'L_PIC_DESC' => $lang['Pic_Desc'],
  112. //'L_PLAIN_TEXT_ONLY' => $lang['Plain_text_only'],
  113. 'L_PLAIN_TEXT_ONLY' => $formatting_status,
  114. 'L_MAX_LENGTH' => $lang['Max_length'],
  115. 'L_UPLOAD_NO_TITLE' => $lang['Upload_no_title'],
  116. 'L_DESC_TOO_LONG' => $lang['Desc_too_long'],
  117. 'S_PIC_DESC_MAX_LENGTH' => $album_config['desc_length'],
  118. 'L_RESET' => $lang['Reset'],
  119. 'L_SUBMIT' => $lang['Submit'],
  120. 'S_ALBUM_ACTION' => append_sid(album_append_uid('album_edit.' . PHP_EXT . '?pic_id=' . $pic_id)),
  121. )
  122. );
  123. $template_to_parse = $class_plugins->get_tpl_file(ALBUM_TPL_PATH, 'album_edit_body.tpl');
  124. full_page_generation($template_to_parse, $lang['Album'], '', '');
  125. }
  126. else
  127. {
  128. // --------------------------------
  129. // Check posted info
  130. // --------------------------------
  131. if(empty($pic_title))
  132. {
  133. message_die(GENERAL_ERROR, $lang['Missed_pic_title']);
  134. }
  135. // --------------------------------
  136. // Update the DB
  137. // --------------------------------
  138. $sql = "UPDATE ". ALBUM_TABLE ."
  139. SET pic_title = '" . $db->sql_escape($pic_title) . "', pic_desc= '" . $db->sql_escape($pic_desc) . "'
  140. WHERE pic_id = '" . $pic_id . "'";
  141. $result = $db->sql_query($sql);
  142. // --------------------------------
  143. // Complete... now send a message to user
  144. // --------------------------------
  145. $message = $lang['Pics_updated_successfully'];
  146. $redirect_url = append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id));
  147. meta_refresh(3, $redirect_url);
  148. $message .= '<br /><br />' . sprintf($lang['Click_return_category'], '<a href="' . append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id)) . '">', '</a>');
  149. $message .= '<br /><br />' . sprintf($lang['Click_return_album_index'], '<a href="' . append_sid('album.' . PHP_EXT) . '">', '</a>');
  150. message_die(GENERAL_MESSAGE, $message);
  151. }
  152. ?>