<?php
define('CMM', 'comm/'); // the directory with classes for comments
define('CMINCLS', 'commincls/'); // the directory with files for forms, JS code, css style
include(CMM.'config.php'); // file with main configurations
// include and uses classes according to request, to set or get comments
// if form submited (to add, modify, delete), or URL for unsubscribe
if(isset($_POST['sbmt']) || (isset($_GET['unsub']) && preg_match('/^[0-9]+_[0-9]+$/', $_GET['unsub']))) {
include(CMM.'class.SetComm.php'); // class used to add, modify, delete comments
$objCom = new SetComm($cmysql);
}
else {
include(CMM.'class.GetComm.php');
$objCom = new GetComm($cmysql);
// if admin logged, sets button to delete comments, and session with the current page
if(isset($_SESSION['adminlog'])) {
$delcmm = '<button class="delcmm">'.$clsite['delsel'].'</button><br class="clr"/>';
$_SESSION['logout_redir'] = $objCom->page;
}
else $delcmm = '';
ob_start(); // start storing output in buffer (comments area)
echo $delcmm.$objCom->linkspgs; // Afiseaza link-uri deasupra
echo $objCom->comments; // Afisare comentarii
echo $delcmm.$objCom->linkspgs; // Afiseaza link-uri dedesubt
if((isset($_SESSION['adminlog']) && $_SESSION['adminlog']==md5(CMANAME.CMAPASS))) {
include(CMINCLS.'form_moddel.php');
}
$comments = ob_get_contents(); // stores the buffer content
ob_end_clean();
// if access from POST, with 'isajax', adds comments content in DIV, loggadmin form, and form to add comment
if(!isset($_POST['isajax'])) {
ob_start(); // start seccond buffer
// add comments content into a DIV
$comments = '<a id="cm"></a><h2 id="coments_t"> ֩ '.$clsite['comments']['title'].' <i>('.$objCom->totalcomm.')</i></h2>
<div id="coments">'.$comments.'</div>';
include(CMINCLS.'form_adminlog.php'); // form to log Admin, or link to logout
echo jscTexts($clsite); // include the JSon with texts for JavaScript mesags in the defined language
// if $addcomm not 1 and $nameusr not defined, show message that only logged user can add comment
// else, include the form
if($addcomm !== 1 && !isset($nameusr)) echo '<h3 id="adcomm">'.$clsite['comments']['allowcmm'].'</h3>';
else include(CMINCLS.'form_add.php'); // Include formularul pt. adaugare comentarii
echo '<!-- Script Comments with Pagination, http://www.coursesweb.net/php-mysql/ -->';
$comments .= ob_get_contents(); // adds seccond the buffer content
ob_end_clean();
}
if(isset($_REQUEST['pg']) && isset($_REQUEST['nrp'])) echo $comments; // output the content when Ajax
}