//header("Pragma: no-cache");
//header('Content-type: text/html; charset=utf-8');
//header( "Content-type: text/html; charset=iso-8859-1");
// $debug=yes;
/**********************
discussions:
can be started for an event_item, article or nothing(a post)
id_type=event_item: If a discussion does not exists any logged in user can start a discussion about it. This user will be the moderator!
Also event item general info and attedees pictures to this particular item will be shown.
id_type=article: If a discussion does not exists any logged in user can start a discussion about it. This user will be the moderator!
Also article general info will be shown.
id_type=discussion: id_value will point to self! Will show a single discussion. Discussion cannot be auto-created. Moderator is set from the create form.
no parameters: will show list of discussions where id_type=='discussion'
create_discussion=yes: will show the create form
Moderator: will set discussion properties such as name, description, moderated, allow_anonymous_comments, disable_on. Plus will set comment status.
Please note CRM users will have 'moderator like' privileges
// TODO: fix windows.location on chrome
**********************/
//require'../../MASTER/commonfiles/Functions.php';
require'../commonfiles/Functions.php';
require'../commonfiles/MyFunctions.php';
require'../commonfiles/brandconfig.php';
require'../commonfiles/newtemplate.php';
include '../commonfiles/publisher.inc';
// connect mysql
$crm = new MySQL_class;
$crm->Create($crm_db,$crm_user,$crm_host,$crm_pass);
$gc_sql=$crm; // session handling
$db_foo = $crm; // template handling
$cdc = new MySQL_class;
$cdc->Create($cdc_db,$cdc_user,$cdc_host,$cdc_pass);
$brnd = new MySQL_class;
$brnd->Create($db,$user,$host,$pass);
$tmp = new MySQL_class;
$tmp->Create($template_db,$template_user,$template_host,$template_pass);
/*
$dir = new MySQL_class;
$dir->Create($directory_db,$directory_user,$directory_host,$directory_pass);
*/
$files = new MySQL_class;
$files->Create($files_db,$files_user,$files_host,$files_pass);
// start session
start_session($php_sessid);
// log it
app_log('event',$PHP_SELF,$search_word,$event_id,'view',$code,$array);
$staging = "";
if(page_auth(3,$u_type,$cdc) == "yes")
{
$staging = "yes";
}
unset($u_type,$u_id,$session_email);
start_session($sessid);
$message_array = get_messages('event_discussion',$language_c,$TEMPLATE_MESSAGE,$code,$tmp);
if($carry=='')
{
$carry = $u_id;
}
/*
if(!$id_value)
{
header("location: /event/index.html");
exit();
}
if(!$id_type)
{
// a user started a discussion from nothing
$id_type = "nothing";
}*/
// page starts
// download a comment file => has exit
if($download && $file_id)
{
// get the data
$query = "select file_id,file_data,file_type,file_size,file_name
from $FILES
where file_id = '".ass($file_id)."'
and brand = '$code' ";
$data = $files->mydata($query);
if($data[file_id][0])
{
$file = $data[file_data][0];
$type = $data[file_type][0];
$length = $data[file_size][0];
$file_name = str_replace(" ","_",$data[file_name][0]);
// feed it to the browser
Header("Content-disposition: attachment; filename=".$file_name);
Header("Content-type: $type");
Header("Content-length: $length");
echo $file;
exit();
}
//echo "File does not exists.";
echo $message_array['event_discussion_01'];
exit();
}
// via ajax
if($enable_comment)
{
$message = "";
if(!$id_value)
{
//$message .= " Invalid discussion.";
$message .= $message_array['event_discussion_02'];
}
if(!$u_id)
{
//echo "You need to be logged in, in order to perform this action. ";
echo $message_array['event_discussion_03'];
exit();
}
// only moderator can do this!
$query = "select id
from $DISCUSSION
where id_type = '".ass($id_type)."'
and id_value = '".ass($id_value)."'
and moderated_by = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
if(!$data[id][0] && $staging != "yes")
{
//echo "You need to be the moderator in order to perform this action. ";
echo $message_array['event_discussion_04'];
exit();
}
// all fine lets update
$query = "update $DISCUSSION_COMMENT set
status = 'ENABLED'
where id = '".ass($comment_id)."'
and discussion_id = '".($data[id][0])."'
and brand = '$code' ";
$crm->Update($query);
// echo "Comment enabled successfully.";
echo $message_array['event_discussion_05'];
exit();
}
// via ajax
if($disable_comment)
{
$message = "";
if(!$id_value)
{
//$message .= " Invalid discussion.";
$message .= $message_array['event_discussion_06'];
}
if(!$u_id)
{
// echo "You need to be logged in, in order to perform this action. ";
echo $message_array['event_discussion_07'];
exit();
}
// only moderator can do this!
$query = "select id
from $DISCUSSION
where id_type = '".ass($id_type)."'
and id_value = '".ass($id_value)."'
and moderated_by = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
if(!$data[id][0] && $staging != "yes")
{
//echo "You need to be the moderator in order to perform this action. ";
echo $message_array['event_discussion_08'];
exit();
}
// check it doesnot has child comments
$query = "select id
from $DISCUSSION_COMMENT
where discussion_comment_id = '".ass($comment_id)."'
and discussion_id = '".($data[id][0])."'
and brand = '$code' ";
$data_child = $crm->mydata($query);
if($data_child[id][0])
{
//echo "Sorry disabling a comment that has been replied is not allowed.";
echo $message_array['event_discussion_09'];
exit();
}
// all fine lets update
$query = "update $DISCUSSION_COMMENT set
status = 'DISABLED'
where id = '".ass($comment_id)."'
and discussion_id = '".($data[id][0])."'
and brand = '$code' ";
$crm->Update($query);
// echo "Comment disabled successfully.";
echo $message_array['event_discussion_10'];
exit();
}
// via ajax
if($delete_comment)
{
$message = "";
if(!$id_value)
{
//$message .= " Invalid discussion.";
$message .= $message_array['event_discussion_11'];;
}
if(!$u_id)
{
// echo "You need to be logged in, in order to perform this action. ";
echo $message_array['event_discussion_12'];
exit();
}
// only moderator can do this!
$query = "select id
from $DISCUSSION
where id_type = '".ass($id_type)."'
and id_value = '".ass($id_value)."'
and moderated_by = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
if(!$data[id][0] && $staging != "yes")
{
//echo "You need to be the moderator in order to perform this action. ";
echo $message_array['event_discussion_13'];
exit();
}
// check it doesnot has child comments
$query = "select id
from $DISCUSSION_COMMENT
where discussion_comment_id = '".ass($comment_id)."'
and discussion_id = '".($data[id][0])."'
and brand = '$code' ";
$data_child = $crm->mydata($query);
if($data_child[id][0])
{
//echo "Sorry deleting a comment that has been replied is not allowed.";
echo $message_array['event_discussion_14'];
exit();
}
// all fine lets update
$query = "delete from $DISCUSSION_COMMENT
where id = '".ass($comment_id)."'
and discussion_id = '".($data[id][0])."'
and brand = '$code' ";
$crm->Update($query);
// echo "Comment deleted successfully.";
echo $message_array['event_discussion_15'];
exit();
}
// normal post => create standalone discussion => id_type='discussion' and id_value points to self!
if($submit_create_discussion)
{
$message = "";
if(!$discussion_name)
{
//$message .= " Please put a discussion name.";
$message .= $message_array['event_discussion_16'];
}
if(!$discussion_description)
{
//$message .= " Please put a discussion description.";
$message .= $message_array['event_discussion_17'];
}
// only crm user or moderator can update discussion settings
if(!$u_id)
{
//$message .= " You need to be logged in, in order to perform this action. ";
$message .= $message_array['event_discussion_18'];
}
if(!$message)
{
$id_value = make_rand();
$id_type = "discussion";
$query = "insert into $DISCUSSION set
id = '".make_rand()."',
id_value = '".ass($id_value)."',
id_type = '".ass($id_type)."',
name = '".ass($discussion_name)."',
description = '".ass($discussion_description)."',
moderated = '".ass($discussion_moderated)."',
disable_on = '".ass($discussion_disable_on)."',
allow_anonymous_comments = '".ass($discussion_allow_anonymous_comments)."',
moderated_by = '$u_id',
created_on = '".gmdate("Y-m-d H:i:s")."',
brand = '$code' ";
$crm->Insert($query);
// Discussion created successfully.
$message .= $message_array['event_discussion_19'];
header("location: $PHP_SELF?id_type=$id_type&id_value=$id_value&message=$message");
exit();
}
}
// via ajax => update discussion settings by CRM or moderator
if($update_discussion)
{
$message = "";
if(!$id_value)
{
//$message .= " Invalid discussion.";
$message .= $message_array['event_discussion_20'];
}
if(!$discussion_name)
{
//echo "Please put a discussion name.";
echo $message_array['event_discussion_21'];
exit();
}
// only crm user or moderator can update discussion settings
if(!$u_id)
{
//echo "You need to be logged in, in order to perform this action. ";
echo $message_array['event_discussion_22'];
exit();
}
// only moderator can do this!
$query = "select id
from $DISCUSSION
where id_type = '".ass($id_type)."'
and id_value = '".ass($id_value)."'
and moderated_by = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
if(!$data[id][0] && $staging != "yes")
{
//echo "You need to be the moderator in order to perform this action. ";
echo $message_array['event_discussion_23'];
exit();
}
if(!$data[id][0])
{
$query = "insert into $DISCUSSION set
id = '".make_rand()."',
id_value = '".ass($id_value)."',
id_type = '".ass($id_type)."',
name = '".ass($discussion_name)."',
description = '".ass($discussion_description)."',
moderated = '".ass($discussion_moderated)."',
disable_on = '".ass($discussion_disable_on)."',
allow_anonymous_comments = '".ass($discussion_allow_anonymous_comments)."',
moderated_by = '$u_id',
created_on = '".gmdate("Y-m-d H:i:s")."',
brand = '$code' ";
$crm->Insert($query);
//echo "Discussion created successfully.";
echo $message_array['event_discussion_24'];
}
else
{
$query = "update $DISCUSSION set
name = '".ass($discussion_name)."',
description = '".ass($discussion_description)."',
moderated = '".ass($discussion_moderated)."',
disable_on = '".ass($discussion_disable_on)."',
allow_anonymous_comments = '".ass($discussion_allow_anonymous_comments)."'
where id = '".$data[id][0]."'
and brand = '$code' ";
$crm->Insert($query);
//echo "Discussion updated successfully.";
echo $message_array['event_discussion_25'];
}
exit();
}
// normal post
if($submit_comment)
{
$message = "";
if(!$comment)
{
//$message .= " Please type a comment.";
$message .= $message_array['event_discussion_26'];
}
if(!$id_value)
{
//$message .= " Invalid discussion.";
$message .= $message_array['event_discussion_27'];
}
if(!$message)
{
// get discussion id and settings
$query = "select id, name, moderated, allow_anonymous_comments, moderated_by
from $DISCUSSION
where id_value = '".ass($id_value)."'
and id_type = '".ass($id_type)."'
and brand = '$code' ";
$data = $crm->mydata($query);
$discussion_id = $data[id][0];
$discussion_name = $data[name][0];
// if a discussion does not exists for this item
if(!$discussion_id)
{
// if user is logged in the create the discussion with default options => only for item and article discussions
if($u_id)
{
if($id_type == "event_item")
{
$query = "select name
from $EVENT_ITEM
where event_item_id = '".ass($id_value)."'
and brand = '$code' ";
$data_item = $crm->mydata($query);
$item_name = $data_item[name][0];
}
else if($id_type == "article")
{
$query = "select article_title as name
from $TITLE
where article_id = '".ass($id_value)."'
and brand = '$code'";
$data_item = $brnd->mydata($query);
$item_name = $data_item[name][0];
}
else if($id_type == "fundraiser")
{
$query = "select b.company_name, concat(b.first_name,' ',b.last_name) as name, a.type
from $CDC_CAMPAIGN a, $CDC b
where a.cdc_id = b.cdc_id
and a.id = '".ass($id_value)."'
and b.brand = '$code'";
$data_item = $cdc->mydata($query);
if($data_item[type][0] == 'company')
{
$item_name = $data_item[company_name][0];
}
else
{
$item_name = $data_item[name][0];
}
}
// if a discussion does not exists then create it
$discussion_id = make_rand();
$query = "insert into $DISCUSSION set
id = '$discussion_id',
id_value = '".ass($id_value)."',
id_type = '".ass($id_type)."',
name = '".ass($item_name." discussion")."',
description = '".ass("A discussion about an ".str_replace("_"," ",$id_type)." named: $item_name")."',
moderated = 'N',
disable_on = '',
allow_anonymous_comments = 'Y',
moderated_by = '$u_id',
created_on = '".gmdate("Y-m-d H:i:s")."',
brand = '$code' ";
$crm->Insert($query);
$status = "ENABLED";
$moderated = "";
}
else
{
//$message .= " This discussion does not exists, please login to create it";
$message .= $message_array['event_discussion_28'];
}
}
else
{
// if a discussion exists lets get its options and do some more validation
if($data[allow_anonymous_comments][0] != Y && !$u_id)
{
//$message .= " You need to be logged in order to comment on this discussion.";
$message .= $message_array['event_discussion_29'];
}
if($data[moderated][0] != "N")
{
$status = "DISABLED";
$moderated = "Yes";
}
else
{
$status = "ENABLED";
$moderated = "";
}
}
}
// define comment id here because we will need it in several places
$the_comment_id = make_rand();
// lets upload the comment file if any...
if(!$message)
{
// make sure we have a valid file and if so .... open it
$test = @fopen($form_data[tmp_name], "r");
if($test != "")
{
// massage the data ...
$image_size = getimagesize($form_data[tmp_name]);
$width = $image_size[0];
$height = $image_size[1];
$data_file_uploaded = addslashes(fread(fopen($form_data[tmp_name], "r"), $form_data[size]));
}
// lets make sure it is not to big ...
if($form_data[size]>='1073741824')
{
// $message .=" Unfortunately the file you attempted to upload is to big, please make the picture smaller than 1MEG and try again.";
$message .= $message_array['event_discussion_30'];
}
// if no errors ...
if($message=="" && trim($form_data[name]))
{
$file_id = make_rand();
// insert the file
$query = "insert into $FILES set
file_id = '$file_id',
id_type = 'comment',
id_value = '$the_comment_id',
file_data = '$data_file_uploaded',
file_name = '".ss($form_data[name])."',
file_size = '$form_data[size]',
file_type = '$form_data[type]',
employee_id = '$u_id',
brand = '$code' ";
$files->Insert($query);
}
}
// all ok then create the comment
if(!$message)
{
// insert the comment
$query = "insert into $DISCUSSION_COMMENT set
id = '$the_comment_id',
contact_id = '$u_id',
discussion_comment_id = '".ass(strip_tags($discussion_comment_id))."',
comment = '".ass(strip_tags($comment))."',
date_time = '".gmdate("Y-m-d H:i:s")."',
timezone = '".ass(strip_tags($timezone))."',
status = '$status',
discussion_id = '".($discussion_id)."',
brand = '$code' ";
$crm->Insert($query);
$message .= " Comment posted successfully.";
// mail to moderator if moderated is set to Y
unset($system_email_array);
if($moderated)
{
// mail to moderator telling someaone has posted a comment
$aux_arr = get_cdc($data[moderated_by][0],$code,$cdc);
$aux_arr2 = get_cdc($u_id,$code,$cdc);
$the_name = $aux_arr2[first_name]." ".$aux_arr2[last_name];
$system_email_array[comment] = strip_tags($comment);
$system_email_array[name] = $the_name?$the_name:"Anonymous";
$system_email_array[domain] = "$HTTP_HOST";
$system_email_array[idtype] = $id_type;
$system_email_array[idvalue] = $id_value;
$system_email_array[focus] = "focus_$the_comment_id";
$system_email_array[discussion] = $discussion_name;
system_email("24",$aux_arr['email'],$aux_arr['first_name']." ".$aux_arr['last_name'],$system_email_array,$EMAIL,$code,$crm);
}
// mail to father comment user
if($discussion_comment_id)
{
// mail to user whose comment got replied
$query = "select contact_id
from $DISCUSSION_COMMENT
where id = '".ass($discussion_comment_id)."'
and brand = '$code' ";
$data_father = $crm->mydata($query);
$aux_arr = get_cdc($data_father[contact_id][0],$code,$cdc);
$aux_arr2 = get_cdc($u_id,$code,$cdc);
$the_name = $aux_arr2[first_name]." ".$aux_arr2[last_name];
$system_email_array[comment] = strip_tags($comment);
$system_email_array[name] = $the_name?$the_name:"Anonymous";
$system_email_array[domain] = "$HTTP_HOST";
$system_email_array[idtype] = $id_type;
$system_email_array[idvalue] = $id_value;
$system_email_array[focus] = "focus_$the_comment_id";
$system_email_array[discussion] = $discussion_name;
system_email("25",$aux_arr['email'],$aux_arr['first_name']." ".$aux_arr['last_name'],$system_email_array,$EMAIL,$code,$crm);
}
// Comment created successfully.
$message = $message_array['event_discussion_31'];
header("location: $PHP_SELF?id_type=$id_type&id_value=$id_value&message=$message");
exit();
}
}
// start template engine
//$message_array = get_messages('event_long',$language_c,$TEMPLATE_MESSAGE,$code,$tmp);
$tpl = new rFastTemplate(".");
$tpl->no_strict();
$tpl->quiet();
$main = get_template('40',$TEMPLATE,$tmp,$code,$staging);
if($id_type == "event_item")
{
$body = get_template('219',$TEMPLATE,$tmp,$code,$staging);
}
else if($id_type == "article")
{
$main = get_template('10',$TEMPLATE,$brnd,$code,$staging);
$body = get_template('220',$TEMPLATE,$tmp,$code,$staging);
}
else if($id_type == "discussion")
{
$body = get_template('221',$TEMPLATE,$tmp,$code,$staging);
}
else if($id_type == "fundraiser")
{
// generic template !!!
$body = get_template('235',$TEMPLATE,$tmp,$code,$staging);
}
else if($create_discussion)
{
$body = get_template('222',$TEMPLATE,$tmp,$code,$staging);
}
else
{
// landing page => discussion list
$body = get_template('223',$TEMPLATE,$tmp,$code,$staging);
}
$tpl->define_raw(array( main => $main,
body => $body ));
$tpl = publisher_auto_category($tpl,$code,$brnd);
$tpl = publisher_auto_alt_category($tpl,$code,$brnd);
$tpl = show_login($u_id,$tpl);
$tpl = html_chunks($staging,$tpl,$code,$brnd);
$tpl->assign(array( ID_TYPE => $id_type,
ID_VALUE => $id_value
));
$tpl->assign(array( SESSID => $sessid,
MESSAGE => $message,
SELF => $PHP_SELF
));
// different template data
if($id_type == "event_item")
{
// get event item info
$query = "select event_item_id, event_id, description, room_name, room_capacity, event_item_type, name, fee, easy_id,
description_html, description_2, description_3, cancelled,start_time as complete_date,
date_format(start_time, '%l:%i %p') as start_time2,
date_format(start_time, '%W') as day,
date_format(start_time, '%W, %M %D %Y') as nice_date,
date_format(start_time, '%M %D %Y') as nice_date2,
date_format(end_time, '%l:%i %p') as end_time2
from $EVENT_ITEM
where event_item_id = '".ass($id_value)."'
and brand = '$code' ";
$data = $crm->mydata($query);
$item_name = $data[name][0];
// get the speakers
$query = "select event_speaker_id, cdc_id
from $EVENT_SPEAKER
where event_item_id = '".$data[event_item_id][0]."'
and brand = '$code' ";
$s_data = $crm->mydata($query);
// for each speaker
for($a=0;$a$new_array[first_name] $new_array[last_name] \n";
if(!$new_array[image])
{
$new_array[image] = "";
}
$clear_div = "";
if(($a+1)%3 == 0)
{
$clear_div = "";
}
$tpl->assign(array( SPEAKER_ID => $s_data[cdc_id][$a],
SPEAKER_FIRST_NAME => $new_array[first_name],
SPEAKER_LAST_NAME => $new_array[last_name],
SPEAKER_IMAGE => $new_array[image],
SPEAKER_CLEAR_DIV => $clear_div,
));
$tpl->parse("SPEAKERS",".speakers");
}
if($data[description_html][0]=='Y')
{
$description = stripslashes($data[description][0]);
} else {
$description = nl2br(stripslashes($data[description][0]));
}
if($data[cancelled][0]=='Y')
{
$cancelled = '[cancelled]';
} else {
$cancelled = '';
}
// attendees
$query = "select h.contact_id
from $ORDER_HEADER h, $ORDER_DETAIL d
where h.order_header_id = d.order_header_id
and h.status = 'PAID'
and d.product_id = '".($data[event_item_id][0])."'
and h.brand = '$code' ";
$data_attendee = $crm->mydata($query);
// for each attendee
for($a=0;$a";
}
$clear_div = "";
if(($a+1)%10 == 0)
{
$clear_div = "";
}
$tpl->assign(array( ATTENDEE_FIRST_NAME => $new_array[first_name],
ATTENDEE_LAST_NAME => $new_array[last_name],
ATTENDEE_IMAGE => $new_array[image],
ATTENDEE_CLEAR_DIV => $clear_div,
));
$tpl->parse("ATTENDEES",".attendees");
}
$tpl->assign(array( ITEM_NAME => "$cancelled ".stripslashes($item_name)."",
ITEM_DESCRIPTION => $description,
ROOM_NAME => $data[room_name][0],
COMPLETE_DATE => $data[complete_date][0],
ITEM_START_TIME => $data[start_time2][0],
ITEM_END_TIME => $data[end_time2][0],
DAY => $data[nice_date][0],
EVENT_ID => $data[event_id][0],
));
}
else if($id_type == "article")
{
// get article info
$query = "select article_id, article_title, article_small_image, article_description, created_by, timestamp
from $TITLE
where article_id = '".ass($id_value)."'
and brand = '$code'";
$data = $brnd->mydata($query);
$temp_array = get_cdc($data[created_by][0],$code,$cdc);
$tpl->assign(array( ARTICLE_ID => $data[article_id][0],
ARTICLE_TITLE => $data[article_title][0],
ARTICLE_SMALL_IMAGE => $data[article_small_image][0],
ARTICLE_DESCRIPTION => $data[article_description][0],
ARTICLE_CREATED_BY => $temp_array['first_name']." ".$temp_array['last_name'],
ARTICLE_TIMESTAMP => $data[timestamp][0],
));
}
else if($id_type == "fundraiser")
{
// get fundraiser info
$query = "select b.company_name, concat(b.first_name,' ',b.last_name) as name, a.type, b.image
from $CDC_CAMPAIGN a, $CDC b
where a.cdc_id = b.cdc_id
and a.id = '".ass($id_value)."'
and b.brand = '$code'";
$data_item = $cdc->mydata($query);
if($data_item[type][0] == 'company')
{
$item_name = $data_item[company_name][0];
}
else
{
$item_name = $data_item[name][0];
}
$tpl->assign(array( THE_TITLE => $item_name,
THE_IMAGE => $data_item[image][0],
THE_DESCRIPTION => "Fundraiser Discussion",
));
}
else if($id_type == "discussion")
{
// get discussion info => actually this info is always fetched later in the file
}
else
{
// list all discussions
$query = "select a.id, a.id_type, a.id_value, a.name, a.description, a.moderated, a.allow_anonymous_comments, a.moderated_by, a.disable_on,
a.created_on
from $DISCUSSION a
where a.id_type = 'discussion'
and (a.disable_on > '".date("Y-m-d")."' or a.disable_on = '0000-00-00')
and a.brand = '$code'
order by a.name ";
$data = $crm->mydata($query);
// for each discussion
for($a=0;$a";
}
// number of comments
$query = "select count(1) as count
from $DISCUSSION_COMMENT
where discussion_id = '".($data[id][$a])."'
and brand = '$code'";
$data_number_comments = $crm->mydata($query);
$number_of_comments = $data_number_comments[count][0];
$tpl->assign(array( DISCUSSION_ID => $data[id][$a],
DISCUSSION_ID_TYPE => $data[id_type][$a],
DISCUSSION_ID_VALUE => $data[id_value][$a],
MODERATOR_IMAGE => $new_array[image],
MODERATOR_NAME => $new_array[first_name]." ".$new_array[last_name],
DISCUSSION_NAME => $data[name][$a],
DISCUSSION_DESCRIPTION => $data[description][$a],
DISCUSSION_CREATED_ON => $data[created_on][$a]." GMT",
NUMBER_OF_COMMENTS => $number_of_comments
));
$tpl->parse("DISCUSSIONS",".discussions");
}
}
/*
if($data[timezone][0])
{
date_default_timezone_set($data[timezone][0]);
}
$now = date("Y-m-d H:i:s");
*/
// get discussion if any...
$query = "select id, name, description, moderated, allow_anonymous_comments, moderated_by, disable_on, created_on
from $DISCUSSION
where id_value = '".ass($id_value)."'
and id_type = '".ass($id_type)."'
and brand = '$code' ";
$data = $crm->mydata($query);
$discussion_id = $data[id][0];
// if current user is the moderator then show admin options
$is_admin = "";
if(($data[moderated_by][0] && $data[moderated_by][0] == $u_id) || $staging == "yes")
{
$is_admin = 'Y';
}
// see if discussion is disabled at this time => admin can access it anyway
if(!$is_admin && $discussion_id && strtotime($data[disable_on][0]) < time())
{
header("location: $PHP_SELF?message=This discussion is not available right now.");
exit();
}
// if is admin lets show discussion options
if($is_admin && $discussion_id)
{
$discussion_name = $data[name][0];
$discussion_description = $data[description][0];
$discussion_disable_on = $data[disable_on][0];
$discussion_created_on = $data[created_on][0];
if($data[moderated][0] != 'Y')
{
$discussion_moderated = "";
}
else
{
$discussion_moderated = "";
}
if($data[allow_anonymous_comments][0] != 'Y')
{
$discussion_allow_anonymous_comments = "";
}
else
{
$discussion_allow_anonymous_comments = "";
}
$discussion_options_display = "block";
}
else
{
// when creating a discussion
if($discussion_moderated != 'Y')
{
$discussion_moderated = "";
}
else
{
$discussion_moderated = "";
}
if($discussion_allow_anonymous_comments != 'Y')
{
$discussion_allow_anonymous_comments = "";
}
else
{
$discussion_allow_anonymous_comments = "";
}
$discussion_options_display = "none";
}
$tpl->assign(array( DISCUSSION_ID => $discussion_id,
DISCUSSION_NAME => $discussion_name,
DISCUSSION_DESCRIPTION => $discussion_description,
DISCUSSION_DISABLE_ON => $discussion_disable_on,
DISCUSSION_MODERATED => $discussion_moderated,
DISCUSSION_ALLOW_ANONYMOUS_COMMENTS => $discussion_allow_anonymous_comments,
DISCUSSION_CREATED_ON => $discussion_created_on." GMT",
DISCUSSION_OPTIONS_DISPLAY => $discussion_options_display,
));
$tpl->assign(array( TITLE => $discussion_name?$discussion_name:"Discussions",
KEYWORDS => "event registration software",
PAGE_DESCRIPTION => $discussion_description?$discussion_description:"Discussions",
));
// comments foo
$comment_display_number = "";
unset($all_files);
// get the discussion comments
get_discussion_comments("", $discussion_id, $crm, $code, true);
// list all discussion files
for($a=0;$aassign(array( L_FILE_NAME => $all_files[file_name][$a],
L_FILE_ID => $all_files[file_id][$a],
));
$tpl->parse("FILES",".files");
}
$tpl->parse( MAIN, array( "body", "main" ));
$tpl->FastPrint();
exit();
// functions
function get_discussion_comments($father_id, $discussion_id, $crm, $code, $top_level)
{
global $DISCUSSION_COMMENT,$FILES,$tpl,$cdc,$files,$margin,$is_admin,$comment_display_number,$all_files;
if($top_level)
{
$discussion_query = "and discussion_comment_id = ''";
}
else
{
$discussion_query = "and discussion_comment_id = '$father_id'";
}
$query = "select id, contact_id, discussion_comment_id, comment, date_time, timezone, status
from $DISCUSSION_COMMENT
where discussion_id = '$discussion_id'
$discussion_query
and brand = '$code'
order by date_time desc ";
$data_comment = $crm->mydata($query);
if(is_array($data_comment))
{
$margin += 20;
}
else
{
return;
}
// for each child comment of father id
for($a=0;$a remember comments who have the same father also have the same margin
$query = "select id, contact_id, discussion_comment_id, comment, date_time, timezone, status
from $DISCUSSION_COMMENT
where id = '$father_id'
and brand = '$code' ";
$data_aux = $crm->mydata($query);
echo " ".$data_comment[comment][$a]." and father is ".$data_aux[comment][0]." - $margin";
*/
$user_name = get_cdc($data_comment[contact_id][$a],$code,$cdc);
unset($l_enable_button,$l_disable_button,$l_delete_button);
if($is_admin)
{
if($data_comment[status][$a] != "ENABLED")
{
$l_enable_button = "";
}
else
{
$l_disable_button = "";
}
$l_delete_button = "";
}
else
{
if($data_comment[status][$a] != "ENABLED")
{
continue;
}
}
// comment_display_number foo
if($margin == 20)
{
$comment_display_number = ($a+1);
}
else
{
if(!$is_in_same_block)
{
$is_in_same_block = true;
$comment_display_number .= ".".($a+1);
}
else
{
// replace last 2 characters in the string
$comment_display_number = substr_replace($comment_display_number ,".".($a+1),-2);
}
}
// get single file of a comment if any...
$query = "select file_id, file_name
from $FILES
where id_type = 'comment'
and id_value = '$comment_id'
and brand = '$code' ";
$data_file = $files->mydata($query);
if($data_file[file_id][0])
{
$all_files[file_id][] = $data_file[file_id][0];
$all_files[file_name][] = $data_file[file_name][0];
}
$user_complete_name = $user_name['first_name']." ".$user_name['last_name'];
$tpl->assign(array( L_COMMENT_ID => $comment_id,
L_COMMENT => nl2br($data_comment[comment][$a]),
L_USER_NAME => trim($user_complete_name)?$user_complete_name:"Anonymous",
L_USER_IMAGE => $user_name['image'],
L_TIME => $data_comment[date_time][$a]." GMT",
L_DISABLE_BUTTON => $l_disable_button,
L_ENABLE_BUTTON => $l_enable_button,
L_DELETE_BUTTON => $l_delete_button,
MARGIN => $margin,
FILE_NAME => $data_file[file_name][0],
FILE_ID => $data_file[file_id][0],
COMMENT_DISPLAY_NUMBER => $comment_display_number,
));
$tpl->parse("COMMENTS",".comments");
// get the replies
get_discussion_comments($comment_id, $discussion_id, $crm, $code, false);
}
$margin -= 20;
// remove last 2 characters in the string
$comment_display_number = substr_replace($comment_display_number ,"",-2);
}
?>