[+] Project : default theme added

This commit is contained in:
mMarinetti
2011-12-02 15:24:40 +00:00
parent a2be24ee90
commit 7320307212
431 changed files with 21629 additions and 1679 deletions
+274 -149
View File
@@ -1,13 +1,13 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2010 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
@@ -18,189 +18,314 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* @author Prestashop SA <contact@prestashop.com>
* @copyright 2007-2010 Prestashop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_CAN_LOAD_FILES_'))
if (!defined('_PS_VERSION_'))
exit;
class blockreinsurance extends Module
class Blockreinsurance extends Module
{
protected $_html = '';
public function __construct()
{
$this->name = 'blockreinsurance';
if(version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
$this->tab = 'front_office_features';
else
$this->tab = 'Blocks';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Bloc reinsurance');
$this->description = $this->l('Add a block to display more infos to reassure your customers');
$this->displayName = $this->l('Block reinsurance');
$this->description = $this->l('Adds a block to display more infos to reassure your customers');
}
public function install()
{
return (parent::install() AND $this->installDB() AND Configuration::updateValue('blockreinsurance_nbblocks', 5) AND $this->registerHook('footer'));
}
public function installDB()
{
return Db::getInstance()->execute('
// Module installation
$res = parent::install();
// Table creation
$res &= Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance` (
`id_contactinfos` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_reinsurance` INT UNSIGNED NOT NULL,
`filename` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id_reinsurance`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
$res &= Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance_lang` (
`id_reinsurance` INT UNSIGNED NOT NULL,
`id_lang` INT UNSIGNED NOT NULL,
`text` VARCHAR(300) NOT NULL,
PRIMARY KEY (`id_contactinfos`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;');
PRIMARY KEY (`id_reinsurance`, `id_lang`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
$res &= $this->registerHook('header') AND $this->example();
return $res;
}
public function uninstall()
{
//Delete configuration
return (Configuration::deleteByName('blockreinsurance_nbblocks') AND $this->uninstallDB() AND parent::uninstall());
// Drop table
$res = Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'reinsurance`');
$res &= Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'reinsurance_lang`');
// Uninstall module
$res &= parent::uninstall();
return $res;
}
public function uninstallDB()
private function example()
{
return Db::getInstance()->execute('
DROP TABLE IF EXISTS `'._DB_PREFIX_.'reinsurance`');
$res = Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."reinsurance` VALUES
(1, '10299ef6635307f2b4da1e04471ec981.jpg'),
(2, 'd02eaac9390f84f26fe9c5cae966a8f7.jpg'),
(3, 'b889e72091b006fd444f63e5de030604.jpg'),
(4, 'a215cb7a215c6976be8b2b80f02765b0.jpg'),
(5, '0f9d7fd7d13cfb5672ac7830be60d6a8.jpg');");
$res &= Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."reinsurance_lang` VALUES
(1, 1, 'Money-back guarantee'),
(1, 2, 'SATISFAIT OU REMBOURSE'),
(1, 3, 'Money-back guarantee'),
(1, 4, 'Money-back guarantee'),
(1, 5, 'Money-back guarantee'),
(2, 1, 'Satisfied or refunded'),
(2, 2, 'ECHANGE EN MAGASIN'),
(2, 3, 'Satisfied or refunded'),
(2, 4, 'Satisfied or refunded'),
(2, 5, 'Satisfied or refunded'),
(3, 1, 'Shipped and paid'),
(3, 2, 'PAIEMENT A L''EXPEDITION'),
(3, 3, 'Shipped and paid'),
(3, 4, 'Shipped and paid'),
(3, 5, 'Shipped and paid'),
(4, 1, 'Free delivery'),
(4, 2, 'LIVRAISON GRATUITE'),
(4, 3, 'Free delivery'),
(4, 4, 'Free delivery'),
(4, 5, 'Free delivery'),
(5, 1, 'Secure payment'),
(5, 2, 'PAIEMENT 100% SECURISE'),
(5, 3, 'Secure payment'),
(5, 4, 'Secure payment'),
(5, 5, 'Secure payment');");
return $res;
}
public function addToDB()
{
if(isset($_POST['nbblocks']))
{
for($i = 1; $i <= (int)$_POST['nbblocks']; $i++)
{
$filename = explode('.', $_FILES['info'.$i.'_file']['name']);
if (isset($_FILES['info'.$i.'_file']) AND isset($_FILES['info'.$i.'_file']['tmp_name']) AND !empty($_FILES['info'.$i.'_file']['tmp_name']))
{
if ($error = checkImage($_FILES['info'.$i.'_file']))
return false;
elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['info'.$i.'_file']['tmp_name'], $tmpName))
return false;
elseif (!imageResize($tmpName, dirname(__FILE__).'/img/'.$filename[0].'.jpg'))
return false;
unlink($tmpName);
}
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'reinsurance` (`filename`,`text`)
VALUES ("'.((isset($filename[0]) AND $filename[0] != '') ? pSQL($filename[0]) : '').
'", "'.((isset($_POST['info'.$i.'_text']) AND $_POST['info'.$i.'_text'] != '') ? pSQL($_POST['info'.$i.'_text']) : '').'")');
}
return true;
} else
return false;
}
public function removeFromDB()
{
$dir = opendir(dirname(__FILE__).'/img');
while (false !== ($file = readdir($dir)))
{
$path = dirname(__FILE__).'/img/'.$file;
if ($file != ".." AND $file != "." AND !is_dir($file))
{
unlink($path);
}
}
closedir($dir);
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'reinsurance`');
}
public function getAllFromDB()
{
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'reinsurance`');
}
public function getContent()
{
// If we try to update the settings
if (isset($_POST['submitModule']))
{
Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) AND $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : ''));
if($this->removeFromDB() && $this->addToDB())
echo '<div class="conf confirm"><img src="../img/admin/ok.gif"/>'.$this->l('Configuration updated').'</div>';
else
echo '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred during the save').'</div>';
$this->_html = '<h2>'.$this->displayName.'.</h2>';
if (Tools::isSubmit('submitBlock'))
$this->postProcess();
$this->displayForm();
return $this->_html;
}
protected function displayForm()
{
$languages = Language::getLanguages(false);
$default_language = Configuration::get('PS_LANG_DEFAULT');
$div_id_language = 'block_1_language¤block_2_language¤block_3_language¤block_4_language¤block_5_language';
$data = $this->getAllReinsurances();
$reinssuarances = array();
foreach ($data as $row)
$reinssuarances[$row['id_reinsurance']][$row['id_lang']] = $row;
$this->_html .= '
<script type="text/javascript">id_language = Number('.$default_language.');</script>
<form method="POST" action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" enctype="multipart/form-data">
<fieldset class="width2">
<legend>'.$this->l('Block configuration').'</legend>
';
for ($i = 1; $i != 6; $i++)
{
$this->_html .= '
<h3>Block '.$i.'</h3>
';
if ($i == 1)
$this->_html .= '<p style="color: red;">'.$this->l('This block is required').'</p>';
if (isset($reinssuarances[$i][$default_language]) && $reinssuarances[$i][$default_language]['filename'] != null)
$this->_html .= '<div class="margin-form">
<img src="'.$this->_path.'/img/'.$reinssuarances[$i][$default_language]['filename'].'" alt="'.$reinssuarances[$i][$default_language]['text'].'" />
</div>';
$this->_html .= '
<label>'.$this->l('Image:').'</label>
<div class="margin-form">
<input type="file" name="images['.$i.']" />
</div>
';
foreach ($languages as $lang)
$this->_html .= '
<div id="block_'.$i.'_language_'.$lang['id_lang'].'" style="display: '.($lang['id_lang'] == $default_language ? 'block' : 'none').'; float:left;">
<label>'.$this->l('Text:').'</label>
<input type="text" name="texts['.$i.']['.$lang['id_lang'].']" value="'.((isset($reinssuarances[$i][$lang['id_lang']]) && $reinssuarances[$i][$lang['id_lang']]['text']) ? Tools::htmlentitiesUTF8($reinssuarances[$i][$lang['id_lang']]['text']) : 'default').'" />
</div>
';
$this->_html .= $this->displayFlags($languages, $default_language, $div_id_language, 'block_'.$i.'_language', true);
$this->_html .= '
<div class="clear"></div>
';
if ($i != 5)
$this->_html.= '<hr />';
}
$this->_html .= '
<p class="center">
<input type="submit" class="button" name="submitBlock" value="'.$this->l('Save').'" />
</p>
</fieldset>
</form>
';
return $this->_html;
}
protected function postProcess()
{
$languages = Language::getLanguages(false);
$default_language = Configuration::get('PS_LANG_DEFAULT');
$max_image_size = 2 * 1024 * 1024; // 2 Mb
$errors = array();
$res = 1;
for ($i = 1; $i < 6; $i++)
{
$image_name = $_FILES['images']['name'][$i];
if ($image_name != null)
{
$new_image_name = md5($image_name).'.jpg';
$file = array();
$file['name'] = $_FILES['images']['name'][$i];
$file['tmp_name'] = $_FILES['images']['tmp_name'][$i];
$file['type'] = $_FILES['images']['type'][$i];
$file['error'] = $_FILES['images']['error'][$i];
$file['size'] = $_FILES['images']['size'][$i];
if ($error = checkImage($file, $max_image_size))
$errors[] = $error;
elseif (!move_uploaded_file($file['tmp_name'], dirname(__FILE__).'/img/'.$new_image_name))
$errors[] = $this->l('An error occurred during the image upload.');
if (!sizeof($errors))
{
// Clear old rows
$res &= $this->cleanDb($i);
// New rows
$res &= Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'reinsurance` (`id_reinsurance`, `filename`)
VALUES (\''.(int)$i.'\', \''.(isset($new_image_name) ? pSQL($new_image_name) : '').'\')
');
}
}
}
$nb_blocks = Configuration::get('blockreinsurance_nbblocks');
$infos = $this->getAllFromDB();
$content = '
<script type="text/javascript">
$(document).ready(function(){
var nb_blocks = 5;
nb_blocks = $("select[name=nbblocks]").val();
$("div.container_infos").each(function(){
id_div = $(this).attr("id").split("container_infos");
if(parseInt(id_div[1]) <= nb_blocks)
$(this).show();
else
$(this).hide();
});
$("select[name=nbblocks]").change(function(){
nb_blocks = $("select[name=nbblocks]").val();
$("div.container_infos").each(function(){
id_div = $(this).attr("id").split("container_infos");
if(parseInt(id_div[1]) <= nb_blocks)
$(this).show();
else
$(this).hide();
});
});
});
</script>
<h2>'.$this->displayName.'</h2>
<form method="post" action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" enctype="multipart/form-data">
<fieldset class="width2">
<select name="nbblocks">';
// Show by default 5 blocks maximum
for($i = 1; $i <= 5; $i++)
{
$content .= '<option value="'.$i.'" '.(($i == $nb_blocks) ? 'selected="selected"' : '').'>'.$i.' '.$this->l('block(s)').'</option>';
}
$content .= '</select>
<div class="clear">&nbsp;</div>';
// Show by default 5 blocks maximum
for($i = 1; $i <= 5; $i++)
foreach ($_POST['texts'] as $key => $text)
{
$res &= $this->cleanTxt($key);
if ($text[$default_language] != null && Validate::isCleanHtml($text[$default_language]))
{
if (!sizeof($errors))
{
$content .= '<div id="container_infos'.$i.'" class="container_infos"><h3>'.$this->l('Block number').' '.$i.'</h3>'.
((!empty($infos[$i-1]) && $infos[$i-1]['filename'] != '') ? '<img src="'.Tools::getHttpHost(true)._MODULE_DIR_.$this->name.'/img/'.$infos[$i-1]['filename'].'.jpg" />' : '').
'<div class="clear">&nbsp;</div>
<p><label for="info'.$i.'_file">'.$this->l('Image for this block').' :</label>
<input type="file" name="info'.$i.'_file" /></p>
<p><label for="info'.$i.'_text">'.$this->l('Alternative text for this block').' :</label>
<input type="text" id="info'.$i.'_text" name="info'.$i.'_text" value="'.((!empty($infos[$i-1]) && $infos[$i-1]['text'] != '') ? $infos[$i-1]['text'] : '').'" /></p></div>';
}
$content .= '<div class="clear">&nbsp;</div>
<br /><center><input type="submit" name="submitModule" value="'.$this->l('Update settings').'" class="button" /></center>
</fieldset>
</form>';
foreach ($languages as $lang)
{
if ($text[$lang['id_lang']] == '' || !Validate::isCleanHtml($text[$lang['id_lang']]))
$text[$lang['id_lang']] = $text[$default_language];
$res &= Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'reinsurance_lang` (`id_reinsurance`, `id_lang`, `text`)
VALUES (\''.(int)$key.'\', \''.(int)$lang['id_lang'].'\', \''.pSQL($text[$lang['id_lang']]).'\')
');
}
if (!$res)
$errors[] = $this->l('An error occured on save');
}
}
else
{
if ($key == 1)
$errors[] = $this->l('The block 1 is required');
else
// check if another language aren't empty
foreach ($text as $id_lang => $val)
if ($id_lang != $default_language)
if ($val != null)
$errors[] = $this->l('The text for the block number').' '.$key.' '.$this->l('is incorrect, the default language information is required ');
}
}
return $content;
if (!sizeof($errors))
$this->_html .= $this->displayConfirmation($this->l('Configuration updated'));
else
$this->_html .= $this->displayError(implode('<br />', $errors));
}
protected function cleanDb($key)
{
$image = Db::getInstance()->ExecuteS('
SELECT `filename`
FROM `'._DB_PREFIX_.'reinsurance`
WHERE `id_reinsurance` = '.(int)$key);
// Delete image
if (file_exists(dirname(__FILE__).'/images/'.$image))
@unlink(dirname(__FILE__).'/images/'.$image);
// Delete rows
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'reinsurance` WHERE `id_reinsurance` = '.(int)$key) &&
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'reinsurance_lang` WHERE `id_reinsurance` = '.(int)$key);
}
protected function cleanTxt($key)
{
// Delete rows
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'reinsurance_lang` WHERE `id_reinsurance` = '.(int)$key);
}
protected function getAllReinsurances($id_lang = null)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'reinsurance` r
LEFT JOIN `'._DB_PREFIX_.'reinsurance_lang` rl ON (r.`id_reinsurance` = rl.`id_reinsurance`)
'.($id_lang ? 'WHERE rl.`id_lang` = '.(int)$id_lang : ''));
}
public function hookHeader()
{
$this->context->controller->addCSS(($this->_path).'style.css', 'all');
}
public function hookFooter($params)
{
global $smarty;
$infos = $this->getAllFromDB();
{
global $smarty, $cookie;
$reinssuarances = $this->getAllReinsurances($cookie->id_lang);
if (!$nb_reinssurance = sizeof($reinssuarances))
return;
$smarty->assign(array(
'nbblocks' => Configuration::get('blockreinsurance_nbblocks'),
'infos' => $infos
'nb_blocks' => $nb_reinssurance,
'reinssurances' => $reinssuarances
));
return $this->display(__FILE__, 'blockreinsurance.tpl');
}
}
?>
@@ -23,12 +23,11 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<!-- MODULE Block reinsurance -->
<div id="reinsurance_block" class="clearfix">
<ul class="width{$nbblocks}">
{foreach from=$infos item=info}
<li><img src="{$module_dir}img/{$info.filename}.jpg" alt="{$info.text}" /> <span>{$info.text}</span></li>
<ul class="width{$nb_blocks}">
{foreach from=$reinssurances item=reinssurance}
<li>{if $reinssurance.filename}<img src="{$module_dir}img/{$reinssurance.filename}" alt="{$reinssurance.text}" />{/if} <span>{$reinssurance.text}</span></li>
{/foreach}
</ul>
</div>
Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

+24
View File
@@ -0,0 +1,24 @@
/* BLOCK #reinsurance_block ******************************************************************** */
#reinsurance_block {background:url(../blockreinsurance/img/bg_reinsurance_block.gif) repeat-x 0 0 #c3c7cb}
#reinsurance_block li {
float:left;
padding:15px 10px !important;
font-size:13px;
color:#333;
text-transform:uppercase;
text-shadow:0 1px 0 #fff
}
#reinsurance_block .width1 li {width:960px}
#reinsurance_block .width2 li {width:470px}
#reinsurance_block .width3 li {width:305px}
#reinsurance_block .width4 li {width:224px}
#reinsurance_block .width5 li {width:175px}
#reinsurance_block li img{
float:left;
margin-right:10px;
}
#reinsurance_block li span {
float:left;
padding-top:12px;
width:65%;
}