Log in

View Full Version : Time(date-year) is wrong in this code. please help



winpeace
11-14-2006, 07:40 AM
<?/*
* $Id: combomax.php
*/?><?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once( $mainframe->getPath( 'front_html' ) );
require_once( $mainframe->getPath( 'class' ) );
require_once("includes/patTemplate/patTemplate.php");

$mainframe->setPageTitle('Comment on article');

$tmpl = new patTemplate();
$tmpl->setBasedir("components/com_combomax/templates/");
$tmpl->setNameSpace('pxt');

$task = mosGetParam($_REQUEST,'task','');
$page = mosGetParam($_REQUEST,'page','');

switch ($task) {

case "save":
saveComment($database, $tmpl);
break;

case "preview":
PreviewComments($database, $tmpl);
break;

case "sendreport":
sendreport($database, $tmpl);
break;

default:
break;

}

switch ($page) {
case "reportComment":
reportComment($database);
break;
}

function PreviewComments($database, $tmpl) {
global $mosConfig_offset;

$tmpl->readTemplatesFromFile("previewcomments.tpl");

$name = mosGetParam($_POST,'name','');
$email = mosGetParam($_POST,'email','');
$url = mosGetParam($_POST,'url','');

// look for images in template if available
$starImageOn = mosAdminMenus::ImageCheck( 'rating_star.png', '/images/M_images/' );
$starImageOff = mosAdminMenus::ImageCheck( 'rating_star_blank.png', '/images/M_images/' );

$row->rating = mosGetParam($_POST,'user_rating','');
$img = "";
for ($i=0; $i < $row->rating; $i++) {
$img .= $starImageOn;
}
for ($i=$row->rating; $i < 5; $i++) {
$img .= $starImageOff;
}
$html = '<span class="content_rating">';
$html .= $img;
$html .= "</span>";
$tmpl->addVar("previewForm", 'ratingimage', $html);

$comment = mosGetParam($_POST,'comment','');
$comment = mosHTML::cleanText($comment);
$comment = smile::smileReplace($comment);
$comment = replace_linebreaks($comment);
$comment = stripslashes($comment);

$rawcomment = mosGetParam($_POST,'comment','');
$rawcomment = mosHTML::cleanText($rawcomment);
$rawcomment = replace_linebreaks($rawcomment);
$rawcomment = stripslashes(stripslashes($rawcomment));

$tmpl->addVar("previewForm", 'name', stripslashes(mosGetParam($_POST,'name','')));
$tmpl->addVar("previewForm", 'contentid', stripslashes(mosGetParam($_POST,'contentid','')));
$tmpl->addVar("previewForm", 'email', stripslashes(mosGetParam($_POST,'email','')));
$tmpl->addVar("previewForm", 'url', stripslashes(mosGetParam($_POST,'url','')));
$tmpl->addVar("previewForm", 'comment', $comment);
$tmpl->addVar("previewForm", 'rawcomment', ($rawcomment));
$tmpl->addVar("previewForm", 'ip', stripslashes(mosGetParam($_SERVER,'REMOTE_ADDR','')));
$tmpl->addVar("previewForm", 'browser', stripslashes(mosGetParam($_SERVER,'HTTP_USER_AGENT','')));
$tmpl->addVar("previewForm", 'user_rating', stripslashes(mosGetParam($_POST,'user_rating','')));
$tmpl->addVar("previewForm", 'vote'.$row->rating, " checked=\"checked\" ");


$d = date( "Y-m-d H:i:s" );
$d = mosFormatDate( $d, '%Y-%m-%d %H:%M:%S', -$mosConfig_offset * 60 * 60 );
$tmpl->addVar("previewForm", 'date', $d);

$tmpl->parseTemplate("previewForm");
$tmpl->displayParsedTemplate("previewForm") ;
}

function saveComment($database, $tmpl) {

global $my, $mosConfig_offset, $maxLanguage, $mosConfig_live_site, $mainframe;

$maxConfig = new maxConfig();

$row = new mosComment($database);
$_contentid = mosGetParam($_POST,'contentid','');
$row->bind($_POST);
$comment =$row->comment;
$comment = addslashes($comment);
$row->comment = $comment;
$row->myid = $my->id;
$row->state = $maxConfig->auto_publish;
$row->approved = $maxConfig->auto_approve;
$row->ip = mosGetParam($_SERVER,'REMOTE_ADDR','');
$row->browser = mosGetParam($_SERVER,'HTTP_USER_AGENT','');
$d = date( "Y-m-d H:i:s" );
$row->date = mosFormatDate( $d, '%Y-%m-%d %H:%M:%S', -$mosConfig_offset * 60 * 60 );
$row->store();

$subject = $maxLanguage->EMAIL_SUBJECT_ADMIN_ALERT;

$tmpl = new patTemplate();
$tmpl->setBasedir("components/com_combomax/templates/");
$tmpl->setNameSpace('pxt');
$tmpl->readTemplatesFromFile("showcomment.tpl");
$tmpl->addVar("emailcomment", "NAME", stripslashes(stripslashes($row->name)));
$tmpl->addVar("emailcomment", 'email', stripslashes($row->email));
$tmpl->addVar("emailcomment", 'url', stripslashes($row->url));
$tmpl->addVar("emailcomment", 'comment', smile::smileReplace(stripslashes(stripslashes($row->comment))));
$tmpl->addVar("emailcomment", 'ip', stripslashes($row->ip));
$tmpl->addVar("emailcomment", 'browser', stripslashes($row->browser));
$tmpl->addVar("emailcomment", 'date', stripslashes($row->date));
$tmpl->addVar("emailcomment", 'reporturl', 'index.php?option=com_combomax&page=reportComment&commentid='.$row->id.'');

$tmpl->addVar("emailcomment", 'livesite', $mosConfig_live_site);
$tmpl->addVar("emailcomment", 'template', $mainframe->getTemplate());

$tmpl->addVar("emailcomment", 'contenttitle', getContentTitle($row->contentid));
$tmpl->addVar("emailcomment", 'linktocontent', $mosConfig_live_site.'/index.php?option=com_content&task=view&Itemid=1&id='.$row->contentid);

$tmpl->parseTemplate("emailcomment");
$message = $tmpl->getParsedTemplate("emailcomment");

// SEND Email to admins
if ($maxConfig->alert_admin == 1) {
$database->setQuery( "SELECT name, email FROM #__users"
."\n WHERE LOWER(usertype)='superadministrator' OR LOWER(usertype)='super administrator'" );
$rows = $database->loadObjectList();
foreach ($rows as $row){
$adminName = $row->name;
$adminEmail = $row->email;
mosMail($adminEmail, $adminName, $adminEmail, $subject, $message,1);
}
}

// Send emails to subscribed Users
if ($maxConfig->alert_users == 1) {
$database->SetQuery("SELECT email from #__combomax WHERE subscribe = 1 AND contentid = ".$_contentid);
$rows = $database->loadobjectlist();

foreach ($rows as $row){
mosMail($adminEmail,$adminName,$row->email,$subject,$message,1);
}
}

//record vote
$user_rating = mosGetParam($_REQUEST,'user_rating',null);
if ($user_rating){
comment_recordVote($user_rating,$_contentid,$database);
}
mosRedirect(sefRelToAbs('index.php?option=com_content&task=view&id='.$_contentid.'#read-comments'),'Comment Saved');

}

function reportComment($database){

$commentid = mosGetParam($_REQUEST,'commentid','');

$tmpl = new patTemplate();
$tmpl->setBasedir("components/com_combomax/templates/");
$tmpl->setNameSpace('pxt');
$tmpl->readTemplatesFromFile("showcomment.tpl");

$database->SetQuery("SELECT * from #__combomax WHERE id ='".$commentid."'");
$rows = $database->loadObjectList();
$row = $rows[0];

$tmpl->addVar("showcomment", "NAME", stripslashes(stripslashes($row->name)));
$tmpl->addVar("showcomment", 'email', stripslashes($row->email));
$tmpl->addVar("showcomment", 'url', stripslashes($row->url));
$tmpl->addVar("showcomment", 'comment', smile::smileReplace(stripslashes(stripslashes($row->comment))));
$tmpl->addVar("showcomment", 'ip', stripslashes($row->ip));
$tmpl->addVar("showcomment", 'browser', stripslashes($row->browser));
$tmpl->addVar("showcomment", 'date', stripslashes($row->date));
$tmpl->addVar("showcomment", 'reporturl', 'index.php?option=com_combomax&page=reportComment&commentid='.$row->id.'');

$tmpl->parseTemplate("showcomment");
$commentHTML = $tmpl->getParsedTemplate("showcomment");

$tmpl->readTemplatesFromFile("reportcomment.tpl");
$tmpl->addVar("reportcomment", 'comment_to_report', $commentHTML);
$tmpl->addVar("reportcomment", 'commentid', $commentid);
$tmpl->displayParsedTemplate("reportcomment");
}

function sendreport($database, $tmpl){

global $maxLanguage, $mosConfig_live_site, $mainframe;

$subject = $maxLanguage->EMAIL_SUBJECT_REPORTED_COMMENT;

$commentid = mosGetParam($_REQUEST,'commentid','');

$row = new mosComment($database);
$row->load($commentid);

$tmpl = new patTemplate();
$tmpl->setBasedir("components/com_combomax/templates/");
$tmpl->setNameSpace('pxt');
$tmpl->readTemplatesFromFile("reportcomment.tpl");
$tmpl->addVar("reportcommentemail", "NAME", stripslashes(stripslashes($row->name)));
$tmpl->addVar("reportcommentemail", 'email', stripslashes($row->email));
$tmpl->addVar("reportcommentemail", 'url', stripslashes($row->url));
$tmpl->addVar("reportcommentemail", 'comment', smile::smileReplace(stripslashes(stripslashes($row->comment))));
$tmpl->addVar("reportcommentemail", 'ip', stripslashes($row->ip));
$tmpl->addVar("reportcommentemail", 'browser', stripslashes($row->browser));
$tmpl->addVar("reportcommentemail", 'date', stripslashes($row->date));
$tmpl->addVar("reportcommentemail", 'reporturl', 'index.php?option=com_combomax&page=reportComment&commentid='.$row->id.'');

$tmpl->addVar("reportcommentemail", 'livesite', $mosConfig_live_site);
$tmpl->addVar("reportcommentemail", 'template', $mainframe->getTemplate());

$tmpl->addVar("reportcommentemail", 'contenttitle', getContentTitle($row->contentid));
$tmpl->addVar("reportcommentemail", 'linktocontent', $mosConfig_live_site.'/index.php?option=com_content&task=view&Itemid=1&id='.$row->contentid);

$tmpl->addVar("reportcommentemail", 'reportersname', mosGetParam($_REQUEST,'name',''));
$tmpl->addVar("reportcommentemail", 'reportersemail', mosGetParam($_REQUEST,'email',''));
$tmpl->addVar("reportcommentemail", 'reportersreason', mosGetParam($_REQUEST,'reason',''));

$tmpl->parseTemplate("reportcommentemail");
$message = $tmpl->getParsedTemplate("reportcommentemail");

// SEND Email to admins
$database->setQuery( "SELECT name, email FROM #__users"
."\n WHERE usertype='superadministrator' OR usertype='Super
}
?>


this code says 2003-04-05 07:34
how to solve this problem.
how to year-date-time get server in this code.
please help me

winpeace
11-14-2006, 09:27 AM
I remove mosformat date and add this code;
$zone=3600*3//TURKEY
$d = date( "Y-m-d H:i:s" );
$d = gmdate( $d, "D M Y H:i", time() + $zone);


but this error comes:
Parse error: parse error, unexpected T_VARIABLE in /home/content/m/e/l/melgulg/html/components/com_combomax/combomax.php on line 93

djr33
11-14-2006, 09:39 AM
//TURKEY is a random comment... no idea what it's done there. Remove it. Doesn't hurt... but doesn't do anything.

What is line 93?

winpeace
11-14-2006, 09:42 AM
this---> $d = date( "Y-m-d H:i:s" );

djr33
11-14-2006, 09:47 AM
Remove //TURKEY and put a semicolon at the end of the line.

winpeace
11-14-2006, 09:49 AM
what is semicolon.I don't know.I am new php :( . Please give me an example

djr33
11-14-2006, 09:52 AM
;

As with almost all programming languages, each line must* end with a semi-colon.

(*in some language, NOT php, such as Javascript, the semi-colon is optional some of the time.)


Example:

a = b; c = d;

AND

a = b;
c = d;

do the same exact thing... the semi-colon ends the line, not the line break.

In fact,

a =
b;

is valid... I think.

However, use the
a = b;
c = d;
format just to stay standard and have your code easy to edit.

Twey
11-14-2006, 06:37 PM
There are a few instances where it's prettier to use a linebreak. For example, multiple inline assignments:
$a
= $b
= $c
= $d;Or a very long left operand:
$myClass->getThing()->returnSomething()->instances['creature']->getOwner()->name
= 'John';

djr33
11-15-2006, 12:19 AM
Sure, there are exceptions.
At times, I also toss three or four short commands onto one line, just to save space.

But... generally... stick to the standards.

Let's just say... if you don't, then have a reason for doing so.

mwinter
11-15-2006, 01:31 AM
$zone=3600*3//TURKEY

//TURKEY is a random comment... no idea what it's done there.

If I had to guess, I would say that it refers to the country, Turkey, in that 10800 is its offset, in seconds, from GMT.

I thought Turkey was two hours ahead, myself.

Mike

djr33
11-15-2006, 02:31 AM
Or it's the work of a programmer who was bored out of his mind. :D