Fix blocklinkmulti

This commit is contained in:
Michael RICOIS 2017-11-21 10:00:56 +01:00
parent 097ecc3937
commit 1234f7848d

View File

@ -97,29 +97,43 @@ class BlockLinkMulti1 extends Module
// $result[$i]['url'] = ($link['url'] == ''? '': ((!$admin && substr($link['url'], 0, 4) != 'http') ? substr(__PS_BASE_URI__, 0, -1).$link['url'] : $link['url']));
$i++;
}
return $result;
}
public function addLink()
{
/* Url registration */
if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1 VALUES (\'\', \''.pSQL(isset($_POST['url']) && !empty($_POST['url'])? $_POST['url']: '').'\', '.((isset($_POST['newWindow']) AND $_POST['newWindow']) == 'on' ? 1 : 0).')') OR !$lastId = mysql_insert_id())
return false;
/* Multilingual text */
$languages = Language::getLanguages();
if (!$languages) {
return false;
}
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
if (!$languages)
return false;
foreach ($languages AS $language)
if (!empty($_POST['text_'.$language['id_lang']]))
{
if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1_lang VALUES ('.intval($lastId).', '.intval($language['id_lang']).', \''.pSQL($_POST['text_'.$language['id_lang']]).'\')'))
return false;
}
else
if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1_lang VALUES ('.intval($lastId).', '.intval($language['id_lang']).', \''.pSQL($_POST['text_'.$defaultLanguage]).'\')'))
return false;
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1 VALUES (\'\', \''.
pSQL(isset($_POST['url']) && !empty($_POST['url'])? $_POST['url']: '').'\', '.
((isset($_POST['newWindow']) AND $_POST['newWindow']) == 'on' ? 1 : 0).')');
/* Url registration */
if (!$lastId = mysql_insert_id()) {
return false;
}
/* Multilingual text */
foreach ($languages AS $language) {
if (empty($_POST['text_'.$language['id_lang']])) {
$text = $_POST['text_'.$defaultLanguage];
$url = $_POST['url_'.$defaultLanguage];
} else {
$text = $_POST['text_'.$language['id_lang']];
$url = $_POST['url_'.$language['id_lang']];
}
if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1_lang VALUES ('.
intval($lastId).', '.intval($language['id_lang']).', \''.pSQL($text).'\', \''.pSQL($url).'\')')) {
return false;
}
}
return true;
}
@ -130,21 +144,21 @@ class BlockLinkMulti1 extends Module
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
if (!$languages)
return false;
foreach ($languages AS $language)
foreach ($languages AS $language)
if (!empty($_POST['text_'.$language['id_lang']])
&& !empty($_POST['url_'.$language['id_lang']]))
{
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blocklinkmulti1_lang
SET
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blocklinkmulti1_lang
SET
`text` = \''.pSQL($_POST['text_'.$language['id_lang']]).'\' ,
`url` = \''.pSQL($_POST['url_'.$language['id_lang']]).'\'
`url` = \''.pSQL($_POST['url_'.$language['id_lang']]).'\'
WHERE `id_link`='.intval($_POST['id']).' AND `id_lang`='.$language['id_lang']
))
return false;
}
else
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blocklinkmulti1_lang SET `text`=\''.pSQL($_POST['text_'.$defaultLanguage]).'\' WHERE `id_link`='.intval($_POST['id']).' AND `id_lang`='.$language['id_lang']))
return false;
return false;
return true;
}
@ -270,7 +284,7 @@ class BlockLinkMulti1 extends Module
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'url', true);
$this->_html .= '
<div class="clear"></div>
</div>
</div>
<label>'.$this->l('Open in a new window:').'</label>
<div class="margin-form"><input type="checkbox" name="newWindow" id="newWindow" '.(($this->error AND isset($_POST['newWindow'])) ? 'checked="checked"' : '').' /></div>
<div class="margin-form">
@ -319,7 +333,7 @@ class BlockLinkMulti1 extends Module
$links = $this->getLinks(true);
global $currentIndex, $cookie, $adminObj;
$languages = Language::getLanguages(FALSE);
$languages = Language::getLanguages(FALSE);
if ($links)
{
$this->_html .= '
@ -331,7 +345,7 @@ class BlockLinkMulti1 extends Module
{
$this->_html .= '
links['.$link['id'].'] = new Array();
links['.$link['id'].']["newWindow"] = '.$link['newWindow'].'
links['.$link['id'].']["newWindow"] = '.$link['newWindow'].'
';
foreach ($languages AS $language) {
$this->_html.= '