require_once('/home/castalbums/website/includes/cr-ezsql.php');
require_once('/home/castalbums/website/includes/cr-template.php');
require_once('/home/castalbums/website/includes/cr-functions.php');
require_once('/home/castalbums/website/includes/cr-bbcode.php');
require_once('/home/castalbums/website/includes/cr-forums.php');
RequireLogIn();
if (($action="Post") && $forum_id && $thread_title && $thread_contents)
{
$thread_contents = $crdb->escape(strip_tags($thread_contents));
if (!$thread_contents) RedirectPage('/forums/');
$now = date('Y-m-d H:i:s', time());
$crdb->query('INSERT INTO forum_replies SET forum_id="'.$forum_id.'", thread_id="0", '.
'reply_date="'.$now.'", reply_contents="'.$thread_contents.'", reply_first="1", '.
'reply_user_id="'.$a_user->user_id.'", reply_user_name="'.$a_user->user_name.'", reply_user_email="'.$a_user->user_email.'";');
$new_reply_id = $crdb->insert_id;
if ($related_type=='0') $related_type='';
$crdb->query('INSERT INTO forum_threads SET '.
'forum_id="'.$forum_id.'", '.
'thread_database_type="'.$related_type.'", '.
'thread_database_id="'.$related_id.'", '.
'thread_last_reply_id="'.$new_reply_id.'", '.
'thread_last_reply_date="'.$now.'", '.
'thread_last_reply_user_id="'.$a_user->user_id.'", '.
'thread_last_reply_user_name="'.$a_user->user_name.'", '.
'thread_last_reply_user_email="'.$a_user->user_email.'", '.
'thread_first_reply_id="'.$new_reply_id.'", '.
'thread_first_reply_date="'.$now.'", '.
'thread_first_reply_user_id="'.$a_user->user_id.'", '.
'thread_first_reply_user_name="'.$a_user->user_name.'", '.
'thread_first_reply_user_email="'.$a_user->user_email.'", '.
'thread_title="'.$crdb->escape($thread_title).'", '.
'thread_slug="'.createSlug($thread_title).'" ');
$new_thread_id = $crdb->insert_id;
$crdb->query('UPDATE forum_replies SET thread_id="'.$new_thread_id.'" WHERE reply_id="'.$new_reply_id.'"');
$crdb->query('UPDATE users SET posts=(SELECT count(*) FROM forum_replies WHERE reply_user_id="'.$a_user->user_id.'") WHERE user_id="'.$a_user->user_id.'"');
updateForum($forum_id);
updateThreadTaxonomy($new_thread_id);
RedirectPage(R_URL_to_Thread($new_thread_id));
}
$cr_page->breadcrumbs[] = R_Link('Forums', '/forums');
$cr_page->breadcrumbs[] = 'Post a New Thread';
$cr_page->title = 'Post a New Thread';
$cr_page->current_nav = 'Forums';
$cr_page->Start();
if (isset($related_type))
{
if ($related_type=='recording') $link = R_Link_to_Recording($related_id);
elseif ($related_type=='show') $link = R_Link_to_Show($related_id);
elseif ($related_type=='song') $link = R_Link_to_Song($related_id);
elseif ($related_type=='person') $link = R_Link_to_Person($related_id);
if (!$thread_title) $thread_title = preg_replace('/ \(\d+\)/', '', strip_tags($link));
E_Row_Start();
E_Col_Start(4, 'push=8');
if ($link)
{
E_Message('This thread will be associated with the '.$related_type.' '.$link);
p(R_Button_Link('Search for a different database link', '/forums/post'));
}
else E_Message('You have not associated this post with a particular item from the database.', 'dismiss=FALSE');
E_Message('This website does not approve of the selling and/or trading of illegal copies and illegal bootlegs of commercially available
cast recordings & soundtracks. We reserve the right to delete any message or notation that, in our opinion, violates these rules.');
E_Col_End();
E_Col_Start(8, 'pull=4');
if ($thread_text)
{
E_Header('Preview');
E_Panel(BBCodeParse($thread_text), 'header='.URLEncode($thread_title));
}
E_Form_Start();
E_Form_Row('Thread Title',
R_Form_Input('thread_title', $thread_title),
(($link)?'help='.URLEncode('You can change the title of your thread, but please make sure it can help people identify
what you\'re writing about.'):'')
);
if (!$forum_id)
{
if ($related_type=='show') $forum_id=2;
elseif ($related_type=='recording') $forum_id=3;
elseif ($related_type=='person') $forum_id=4;
elseif ($related_type=='song') $forum_id=5;
elseif ($related_type=='0') $forum_id=8;
}
$forums=array();
if ($fs = $crdb->get_results('SELECT forum_id, forum_name FROM forums WHERE forum_visible=1 AND forum_locked=0 ORDER BY forum_id'))
{
foreach ($fs as $f) $forums[]=array($f->forum_id, $f->forum_name);
}
E_Form_Row('In Forum', R_Form_Select('forum_id', $forums, 'inline=TRUE&empty=0', $forum_id));
E_Form_Row('Content',
R_BBCode_Buttons('thread_contents').
R_Form_Textarea('thread_contents', $thread_contents, 'rows=8')
);
E_Form_Row('', R_Form_Submit('Post New Thread').' '.R_Form_Reset());
E_Form_Hidden('related_type', $related_type);
E_Form_Hidden('related_id', $related_id);
E_Form_End();
E_Col_End();
E_Row_End();
}
else
{
E_Row_Start();
E_Col_Start(4, 'push=8');
E_Message('In order to post a new topic to the Forums, you must first search for a
recording, show,
person, or song to link your post with.
You can skip this step by clicking "Post a New Thread" from a database page (or see
if there\'s an existing thread).');
p(R_Button_Link('Or, post in the "General" thread', '?related_type=0'));
E_Col_End();
E_Col_Start(8, 'pull=4');
E_Form_Start('GET', '', 'type=inline');
if (!$search_type) $search_type='Recording';
p(
R_Form_Select('search_type', array('Recording', 'Show', 'Person', 'Song'), '', $search_type).' '.
R_Form_Input('search_text', $search_text, 'placeholder=Search+for...').' '.
R_Form_Submit('Search Database')
);
E_Form_End();
if ($search_type=='Recording') $q = 'SELECT SQL_CALC_FOUND_ROWS * FROM recordings WHERE recording_title LIKE "%'.$crdb->escape($search_text).'%" ORDER BY recording_title, year';
elseif ($search_type=='Show') $q = 'SELECT SQL_CALC_FOUND_ROWS * FROM shows WHERE show_title LIKE "%'.$crdb->escape($search_text).'%" ORDER BY show_title';
elseif ($search_type=='Song') $q = 'SELECT SQL_CALC_FOUND_ROWS * FROM songs WHERE song_title LIKE "%'.$crdb->escape($search_text).'%" ORDER BY song_title';
elseif ($search_type=='Person') $q = 'SELECT SQL_CALC_FOUND_ROWS * FROM people WHERE (person_name LIKE "%'.$crdb->escape($search_text).'%" OR person_name LIKE "'.$crdb->escape(LastNameFirst($search_text)).'%") ORDER BY person_name';
if (!$limit) $limit=20;
if (!$page) $page=1;
if ($search_text) if ($rows = $crdb->get_results($q.' LIMIT '.((($page-1)*$limit)).', '.$limit))
{
$total = $crdb->get_var("SELECT FOUND_ROWS();");
$pages = numPages($total, $limit);
if ($pages>1) p(Pager($_SERVER['REQUEST_URI'], $page, $pages));
function database_page_link($link)
{
return R_Button_Link('Database Link', $link, 'size=xs');
//return '(Database Link)';
}
E_Table_Start();
foreach ($rows as $row)
{
$row->year = substr($row->year, 0, 4);
if ($row->year=='0000') $row->year='';
if ($search_type=='Recording')
{
$db_link = R_Link_to_Recording($row);
$select = R_Button_Link('Post new Thread', '?related_type=recording&related_id='.$row->recording_id, 'type=primary&size=sm');
E_Table_Row(array($select, Thumbnail_from_ID($row->recording_image_id, 48), $db_link));
}
else
{
if ($search_type=='Show')
{
$db_link = R_Link_to_Show($row);
$select = R_Button_Link('Post new Thread', '?related_type=show&related_id='.$row->show_id, 'type=primary&size=sm');
}
elseif ($search_type=='Song')
{
$db_link = R_Link_to_Song($row);
$select = R_Button_Link('Post new Thread', '?related_type=song&related_id='.$row->song_id, 'type=primary&size=sm');
}
elseif ($search_type=='Person')
{
$db_link = R_Link_to_Person($row);
$select = R_Button_Link('Post new Thread', '?related_type=person&related_id='.$row->person_id, 'type=primary&size=sm');
}
E_Table_Row(array($select, $db_link));
}
}
E_Table_End();
}
else E_Well('No results matching '.$search_text.'.');
E_Col_End();
E_Row_End();
}
$cr_page->End();
?>