Tuesday, August 2, 2011

Calendar Component in Prestashop



Files:
Config.xml
Mycalender.php
Logo.gif

Config.xml codes:
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>mycalender</name>
<displayName>My Calender</displayName>
<version>1</version>
<description>Simple Calender.</description>
<author>MaGp</author>
<tab>front_office_features</tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
</module>

Mycalender.php codes:
<?php
class MyCalender extends Module
{
function __construct()
{
$this->name = 'mycalender';
$this->tab = 'front_office_features';
$this->version = 1.0;
$this->author = 'MaGp';

parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('My Calender');
$this->description = $this->l('Simple Calender.');
}

function install()
{
if (!parent::install())
return false;
if (!$this->registerHook('rightColumn') OR !$this->registerHook('leftColumn'))
return false;
return true;

}


public function getContent()
{

$output='
<div id="calender_block_left" class="block calender_block">
<h4>My Calender</h4>
';

$monthname = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");

if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");

$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prevyear = $cYear;
$nextyear = $cYear;
$prevmonth = $cMonth-1;
$nextmonth = $cMonth+1;
if ($prevmonth == 0 ) {
$prevmonth = 12;
$prevyear = $cYear - 1;
}
if ($nextmonth == 13 ) {
$nextmonth = 1;
$nextyear = $cYear + 1;
}
$skr=date('d');
$output .='
<table width="100%" bgcolor="#eeeeee">
<tr align="center">
<td bgcolor="#eeeeee" style="color:#000099">

</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#DDDDDD" style="color:#666666"><strong>'.$monthname[$cMonth-1].' '.$cYear.' </strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
';

$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];

for ($i=0; $i<($maxday+$startday); $i++) {
if($skr==$i - $startday + 1){$font="#FF0000"; $strong="<strong>";}
else {$font="#000000"; $strong="";}
if(($i % 7) == 0 ) $output .='<tr>';
if($i < $startday) $output .='<td></td>';
else

$output .='
<td align="center" valign="middle" height="20px">'.$strong.'<font color="'.$font.'">'.($i - $startday + 1).' </font></strong></td>';
if(($i % 7) == 6 ) $output .=' </tr>';
}

$output .='
</table>
</td>
</tr>
</table>
</div>
';

return $output;
}

function hookLeftColumn($params)
{
return $this->getContent($params);
}


function hookRightColumn($params)
{
return $this->hookLeftColumn($params);
}

}

Insert config.xml, mycalender.php, logo.gif in mycalender folder, and zip this folder. Then, install this components in backend office prestashop.
Calendar show in configure mycalender component too. Because code for calendar write in public function getContent(), doesn’t in mycalender.tpl.

0 komentar:

Post a Comment

Thanks a lot for your attention...

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Hosting