Link to home
Start Free TrialLog in
Avatar of agilentwax
agilentwax

asked on

comment php in joomla

hi guys,,i'm looking for code that user can only comment the restaurant page when they login...means that the comment box display when user login if not it disabled...this is my code but when i try login the comment box still not display...please check my code
<?php
include 'modules/mod_hot_newsflash/tmpl/dbConnection.php';
// require('../script/rating/_drawrating.php');

//get session

$session =& JFactory::getSession();


$sid = $session->getId('session_id');
//echo "session=" . $sid ."<br/>";

// Take in user id parameter to only show for a specific user
$user =& JFactory::getUser();

$usertype = $user->get('usertype');
$username = $user->get('username');
$useremail = $user->get('email');
echo "userid=".$userid ."<br/>";
echo "usertype=".$usertype."<br/>";
echo "username=".$username."<br/>";
echo "useremail=".$useremail."<br/>";


//set country
if(empty($_GET['rest_id'])) {
$rest_id = '';
}
else {
$rest_id = $_GET['rest_id'];
}
?>
<?php

$query = "select rest_id, rest_name, address, s_address, city, country, tel, fax, email, opinion, times, web_site, acc_cc, price, parking, attire, good_groups, good_kit,

takes_reserv, delivery, take_out, waiter_serv, wheelchair_access, outdoor_seat, good_for, alcohol, rest_image, signature_dish, sample_dish From jos_restaurant where

rest_id=".$rest_id."";

//echo $query;
$result = mysql_query($query) or die(mysql_error());
$row=mysql_fetch_array($result)


?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="modules/mod_hot_newsflash/tmpl/animatedcollapse.js">
</script>


<script type="text/javascript">
animatedcollapse.addDiv('jason', 'fade=1,height=80px')
animatedcollapse.addDiv('kelly', 'fade=1,height=100px')
animatedcollapse.addDiv('michael', 'fade=1,height=120px')

animatedcollapse.addDiv('cat', 'fade=1,speed=400,group=pets')
animatedcollapse.addDiv('dog', 'fade=1,speed=400,group=pets')
animatedcollapse.addDiv('rabbit', 'fade=1,speed=400,group=pets')

animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
    //$: Access to jQuery
    //divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
    //state: "block" or "none", depending on state
}

animatedcollapse.init()

</script>


<style type="text/css">


.star
{
color:#FF0000; font-size:11px; font-weight:bold;
padding-left:5px;
}

</style>

<form id="formMenu" name="formMenu" method="get" action="http://localhost/malaysiakitchen/index.php" target="_parent">
<input type="hidden" name="option" id="option" value="com_content"/>
<input type="hidden" name="view" id="view" value="article"/>
<input type="hidden" name="id" id="id" value="157"/>
<input name="rest_id" type="hidden" id="rest_id" value="<?php echo $row['rest_id']; ?>">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>

<table width="100%" border="0" valign="top">
<tr>
<td valign="top" colspan="2" style="font-size:1.4em; font-family:Verdana, Arial, Helvetica, sans-serif; color:#f05a28; valign:top" valign="top"><strong><?php echo $row['rest_name']; ?></strong></td>
</tr>
<tr>
<td colspan="2"><b><?php echo $row['s_address']; ?></td>
</tr>
<tr>
<td colspan="2"><b><?php echo $row['city']; ?></td>
</tr>
<tr>
<td colspan="2"><b><?php echo $row['country']; ?></b></td>
</tr>

<td height ="10"></td>
<tr>
<td colspan="2" width="34%"><b>Tel: </b><?php echo $row['tel']; ?></td>
</tr>
<tr>
<td colspan="2" ><b>Fax: </b><?php echo $row['fax']; ?></td>
</tr>
<tr><br>
<td height ="10" ></td>
</tr>
<tr><br>
<td valign="top"><b>Opening Time:</td>
<td valign="top"><?php echo $row['times']?></td>
</tr>

<tr>
<td ></td>
<td ></td>
</tr>


</table>


</td>
<td>


</td>
<td><?php
if($row['rest_image']==''){
echo "<img src=modules/mod_hot_newsflash/images/no_image-large.png>";}
else{
echo "<img width=300 height=200 border= 2 src= ".$row['rest_image'] .">";
}
?></td>
</tr>

<tr>
<td >&nbsp;</td>
<td >&nbsp;</td>
<td style="font-size:1.0em; font-family:VerdanaArial, Helvetica, sans-serif; color:#f05a28; valign:top" valign="middle">&nbsp;</td>
</tr>

<tr>
<td >&nbsp;</td>
<td ><img src="modules/mod_hot_newsflash/images/blank.png"></td>
<td style="color:#f05a28; valign:middle"><strong>Restaurant Map</strong></td>
<br>

</tr>

<tr>
<td >&nbsp;</td>
<td >&nbsp;</td>
<td style="font-size:1.0em; font-family:VerdanaArial, Helvetica, sans-serif; color:#f05a28; valign:top" valign="middle">&nbsp;</td>
</tr>

<tr>
<td width="100%" style="vertical-align:top">
<!--menu tab -->


<a href="#" rel="toggle[cat]" data-openimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" data-closedimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/expand.jpg"><img src="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" border="0" /></a>
<div id="cat" style="width: 300px; background:; display:none">

<table width="100%" border="0" style="margin-top:10px">
    <tr>
    <td><?php echo $row['opinion']; ?></td>
    </tr>
    
</table>

    </div>
    <br/><br/>

<a href="#" rel="toggle[dog]" data-openimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" data-closedimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/expand.jpg"><img src="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" border="0" /></a>
<div id="dog" style="width: 300px; background:; display:none">
    <table width="100%" border="0" style="margin-top:10px">
    <tr>
    <td align="left" style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#f05a28">Signature Dish</td>
    </tr>
    <tr>
    <td align="left" style="font-family:Arial, Helvetica, sans-serif; font-size:11px"><?php echo $row['signature_dish']; ?></td>
    </tr>
    <tr>
    <td align="left" style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#f05a28">Sample Dishes</td>
    </tr>
    <tr>
    <td align="left" style="font-family:Arial, Helvetica, sans-serif; font-size:11px"><?php echo $row['simple_dish']; ?></td>
    </tr>
</table>
</div>
    <br/><br/>
    

    <a href="#" rel="toggle[rabbit]" data-openimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" data-closedimage="../mk4theworld/modules/mod_hot_newsflash/tmpl/expand.jpg"><img src="../mk4theworld/modules/mod_hot_newsflash/tmpl/collapse.jpg" border="0" /></a>

<div id="rabbit" style="width: 300px; background:; display:none">
    <table width="100%" border="0" style="margin-top:10px">
    <!--?php while ($row2= mysql_fetch_array($result2)) { ?-->
    <tr>
    <td><font size="1px" face=" Arial, Helvetica, sans-serif" color="#000000">
    Accepts Credit Cards: <?php echo $row['acc_crdt_crd']; ?><br/>
    Price: <?php echo $row['price'];?><br/>
    Parking: <?php echo $row['parking'];?><br/>
    Attire: <?php echo $row['attire'];?><br/>
    Good for Groups: <?php echo $row['good_groups'];?><br/>
    Good for Kids: <?php echo $row['good_kit'];?><br/>
    Takes Reservations: <?php echo $row['takes_reserv'];?><br/></font></td>
    <td><font size="1px" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">
    Delivery: <?php echo $row['delivery']; ?><br/>
    Take-out: <?php echo $row['take_out'];?><br/>
    Waiter Service: <?php echo $row['waiter_serv'];?><br/>
    Wheelchair Accessible: <?php echo $row['wheelchair_access'];?><br/>
    Outdoor Seating: <?php echo $row['outdoor_seat'];?><br/>
    Good for: <?php echo $row['good_for'];?><br/>
    Alcohol: <?php echo $row['alcohol'];?><br/></font></td>
    
    </tr>
<!--?php }?-->
</table>
</div>

</td>
<td></td>
<td align="left" valign="top"><iframe height="290" width="300" frameborder="0" scrolling="no" src="modules/mod_hot_newsflash/tmpl/GoogleAPI/googlemap.php"></iframe></td></tr>
</table>

</td>

</tr>
</table>

</table>

    <?php
    //insert comment data to database
    
    $username = mysql_real_escape_string($user->get('username'));
    $email = mysql_real_escape_string($user->get('email'));
    $comment = $_GET['comment'];
    if ($_GET['submit'])
    {
     $sql = "INSERT INTO jos_comment(username, useremail, comment, rest_id, com_date)
     VALUES ('$username', '$email', '$comment', '$rest_id', Now())";
     //echo $sql;
     $ResultSql = mysql_query($sql) or die (mysql_error());;
    }
    
    $page_name=""; // If you use this code with a different page ( or file ) name then change this
    $start=$_GET['start'];
    if(strlen($start) > 0 and !is_numeric($start)){
    echo "Data Error";
    exit;
    }
    $eu = ($start - 0);
    $limit = 4; // No of records to be shown per page.
    $this1 = $eu + $limit;
    $back = $eu - $limit;
    $next = $eu + $limit;

    
    //select comment data from database
    /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
    $query2="SELECT username, useremail, comment, rest_id, com_date FROM jos_comment WHERE rest_id=".$rest_id."";
    //echo $query;
    $result2 = mysql_query($query2) or die(mysql_error());
    $nume=mysql_num_rows($result2);
    /////// The variable nume above will store the total number of records in the table////
//echo $result;
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query="SELECT username, useremail, comment, rest_id, com_date FROM jos_comment WHERE rest_id=".$rest_id." ORDER BY com_id desc limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();
    ?>
    
    <table width="200" border="0" align="left">
    <tr>
    <td>
     <?php while ($row= mysql_fetch_assoc($result)) { ?>
<table align="left" width="200" border="0" style="vertical-align:top" >
    <tr>
    <!--td rowspan="2"><img src='<?php echo $row['userimage']; ?>'></td-->
    <td style="font-size:11px;font-family:Arial, Helvetica, sans-serif"><?php echo $row['username']; ?></td>
    </tr>
    <tr>
    <td style="font-size:11px;font-family:Arial, Helvetica, sans-serif"> <?php echo $row['com_date']; ?></td>
    </tr>
    <tr>
    <td colspan="2" style=" border-bottom:1px dashed #999; font-size:11px;font-family:Arial, Helvetica, sans-serif""><?php echo $row['comment']; ?></td>
    </tr>
</table>

    <?php }
    
    if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging

/////////////// Start the bottom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print "<a href='$page_name?option=com_content&view=article&id=157&rest_id=".$rest_id."&start=$back'><font face='Verdana' size='2'>PREV</font></a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?option=com_content&view=article&id=157&rest_id=".$rest_id."&start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}


echo "</td><td align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print "<a href='$page_name?option=com_content&view=article&id=157&rest_id=".$rest_id."&start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td></tr></table>";

}// end of if checking sufficient records are there to display bottom navigational link.
    ?>
    
    </td>
    </tr>
    <tr>
    <td><?php if(isset($_SESSION['session_id'])){?>
    <table width="200" border="0" style="vertical-align:top">

    <tr>
    <td> 
    <textarea name="comment" id="comment" title=""></textarea></td>
    <td style="vertical-align:top; font-size:11px; font-family:Arial, Helvetica, sans-serif">Comment<span class="star">*</span></td>
     
    <tr>
    <td colspan="3"><input type="submit" name="submit" value="Submit Comment"/></td>
   <?php }else{?> <?php }?> </tr> </tr>
</table>

    
    </td>
    </tr>
</table>
        
</form>

Open in new window

Avatar of amrish80
amrish80
Flag of India image

Tell me exactly where u are getting error

or the solution is set the $_SESSION['login']=1 variable and where ur code is displaying comment box check
if(isset($_SESSION['login']) && $_SESSION['login']==1)
{
//ur code
}
ASKER CERTIFIED SOLUTION
Avatar of Jesse Matlock
Jesse Matlock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad that worked for you.. best of luck to you agilentwax !