Merge pull request #11920 from ptibogxiv/patch-264

NEW translation for member type
This commit is contained in:
Laurent Destailleur 2019-10-08 09:00:49 +02:00 committed by GitHub
commit d55b7689bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 575 additions and 3 deletions

View File

@ -88,6 +88,8 @@ class AdherentType extends CommonObject
/** @var array Array of members */
public $members=array();
public $multilangs=array();
/**
@ -101,6 +103,185 @@ class AdherentType extends CommonObject
$this->statut = 1;
}
/**
* Load array this->multilangs
*
* @return int <0 if KO, >0 if OK
*/
public function getMultiLangs()
{
global $langs;
$current_lang = $langs->getDefaultLang();
$sql = "SELECT lang, label, description, email";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
$sql.= " WHERE fk_type=".$this->id;
$result = $this->db->query($sql);
if ($result) {
while ($obj = $this->db->fetch_object($result))
{
//print 'lang='.$obj->lang.' current='.$current_lang.'<br>';
if ($obj->lang == $current_lang) // si on a les traduct. dans la langue courante on les charge en infos principales.
{
$this->label = $obj->label;
$this->description = $obj->description;
$this->email = $obj->email;
}
$this->multilangs["$obj->lang"]["label"] = $obj->label;
$this->multilangs["$obj->lang"]["description"] = $obj->description;
$this->multilangs["$obj->lang"]["email"] = $obj->email;
}
return 1;
}
else
{
$this->error="Error: ".$this->db->lasterror()." - ".$sql;
return -1;
}
}
/**
* Update or add a translation for a product
*
* @param User $user Object user making update
* @return int <0 if KO, >0 if OK
*/
public function setMultiLangs($user)
{
global $conf, $langs;
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
$current_lang = $langs->getDefaultLang();
foreach ($langs_available as $key => $value)
{
if ($key == $current_lang) {
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
$sql.= " WHERE fk_type=".$this->id;
$sql.= " AND lang='".$key."'";
$result = $this->db->query($sql);
if ($this->db->num_rows($result)) // if there is already a description line for this language
{
$sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
$sql2.= " SET ";
$sql2.= " label='".$this->db->escape($this->label)."',";
$sql2.= " description='".$this->db->escape($this->description)."'";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", email='".$this->db->escape($this->other)."'";
}
$sql2.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'";
}
else
{
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.=", email";
}
$sql2.= ")";
$sql2.= " VALUES(".$this->id.",'".$this->db->escape($key)."','". $this->db->escape($this->label)."',";
$sql2.= " '".$this->db->escape($this->description)."'";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", '".$this->db->escape($this->other)."'";
}
$sql2.= ")";
}
dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key);
if (! $this->db->query($sql2)) {
$this->error=$this->db->lasterror();
return -1;
}
}
elseif (isset($this->multilangs[$key])) {
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
$sql.= " WHERE fk_type=".$this->id;
$sql.= " AND lang='".$key."'";
$result = $this->db->query($sql);
if ($this->db->num_rows($result)) // if there is already a description line for this language
{
$sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
$sql2.= " SET ";
$sql2.= " label='".$this->db->escape($this->multilangs["$key"]["label"])."',";
$sql2.= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", email='".$this->db->escape($this->multilangs["$key"]["other"])."'";
}
$sql2.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'";
}
else
{
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.=", email";
}
$sql2.= ")";
$sql2.= " VALUES(".$this->id.",'".$this->db->escape($key)."','". $this->db->escape($this->multilangs["$key"]["label"])."',";
$sql2.= " '".$this->db->escape($this->multilangs["$key"]["description"])."'";
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", '".$this->db->escape($this->multilangs["$key"]["other"])."'";
}
$sql2.= ")";
}
// We do not save if main fields are empty
if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) {
if (! $this->db->query($sql2)) {
$this->error=$this->db->lasterror();
return -1;
}
}
}
else
{
// language is not current language and we didn't provide a multilang description for this language
}
}
// Call trigger
$result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user);
if ($result < 0) {
$this->error = $this->db->lasterror();
return -1;
}
// End call triggers
return 1;
}
/**
* Delete a language for this product
*
* @param string $langtodelete Language code to delete
* @param User $user Object user making delete
*
* @return int <0 if KO, >0 if OK
*/
public function delMultiLangs($langtodelete, $user)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang";
$sql.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($langtodelete)."'";
dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
// Call trigger
$result = $this->call_trigger('ADHERENT_TYPE_DEL_MULTILANGS', $user);
if ($result < 0) {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
return -1;
}
// End call triggers
return 1;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
return -1;
}
}
/**
* Fonction qui permet de creer le status de l'adherent
@ -111,7 +292,7 @@ class AdherentType extends CommonObject
*/
public function create($user, $notrigger = 0)
{
global $conf;
global $langs, $conf;
$error=0;
@ -180,7 +361,7 @@ class AdherentType extends CommonObject
*/
public function update($user, $notrigger = 0)
{
global $conf, $hookmanager;
global $langs, $conf, $hookmanager;
$error=0;
@ -202,6 +383,17 @@ class AdherentType extends CommonObject
$result = $this->db->query($sql);
if ($result)
{
$this->description = $this->db->escape($this->note);
// Multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) {
if ($this->setMultiLangs($user) < 0) {
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
return -2;
}
}
$action='update';
// Actions on extra fields
@ -283,6 +475,8 @@ class AdherentType extends CommonObject
*/
public function fetch($rowid)
{
global $langs, $conf;
$sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut, d.subscription, d.mail_valid, d.note, d.vote";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
$sql .= " WHERE d.rowid = ".(int) $rowid;
@ -299,12 +493,17 @@ class AdherentType extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->label = $obj->label;
$this->morphy = $obj->morphy;
$this->morphy = $obj->morphy;
$this->statut = $obj->statut;
$this->subscription = $obj->subscription;
$this->mail_valid = $obj->mail_valid;
$this->note = $obj->note;
$this->vote = $obj->vote;
// multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) {
$this->getMultiLangs();
}
}
return 1;

View File

@ -0,0 +1,323 @@
<?php
/* Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2010-2012 Destailleur Laurent <eldy@users.sourceforge.net>
* Copyright (C) 2014 Henry Florian <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/adherents/type_translation.php
* \ingroup product
* \brief Page de traduction des produits
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
// Load translation files required by the page
$langs->loadLangs(array('members', 'languages'));
$id = GETPOST('rowid', 'int');
$action=GETPOST('action', 'alpha');
$cancel=GETPOST('cancel', 'alpha');
// Security check
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
if ($user->societe_id) $socid=$user->societe_id;
// Security check
$result=restrictedArea($user, 'adherent', $id, 'adherent_type');
/*
* Actions
*/
// retour a l'affichage des traduction si annulation
if ($cancel == $langs->trans("Cancel"))
{
$action = '';
}
if ($action == 'delete' && GETPOST('langtodelete', 'alpha'))
{
$object = new AdherentType($db);
$object->fetch($id);
$object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
}
// Add translation
if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
{
$object = new AdherentType($db);
$object->fetch($id);
$current_lang = $langs->getDefaultLang();
// update de l'objet
if ( $_POST["forcelangprod"] == $current_lang )
{
$object->label = $_POST["libelle"];
$object->description = dol_htmlcleanlastbr($_POST["desc"]);
$object->other = dol_htmlcleanlastbr($_POST["other"]);
}
else
{
$object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
$object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
$object->multilangs[$_POST["forcelangprod"]]["other"] = dol_htmlcleanlastbr($_POST["other"]);
}
// sauvegarde en base
if ( $object->setMultiLangs($user) > 0 )
{
$action = '';
}
else
{
$action = 'add';
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Edit translation
if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
{
$object = new AdherentType($db);
$object->fetch($id);
$current_lang = $langs->getDefaultLang();
foreach ($object->multilangs as $key => $value) // enregistrement des nouvelles valeurs dans l'objet
{
if ( $key == $current_lang )
{
$object->label = $_POST["libelle-".$key];
$object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
$object->other = dol_htmlcleanlastbr($_POST["other-".$key]);
}
else
{
$object->multilangs[$key]["label"] = $_POST["libelle-".$key];
$object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
$object->multilangs[$key]["other"] = dol_htmlcleanlastbr($_POST["other-".$key]);
}
}
if ( $object->setMultiLangs($user) > 0 )
{
$action = '';
}
else
{
$action = 'edit';
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Delete translation
if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
{
$object = new AdherentType($db);
$object->fetch($id);
$langtodelete=GETPOST('langdel', 'alpha');
if ( $object->delMultiLangs($langtodelete, $user) > 0 )
{
$action = '';
}
else
{
$action = 'edit';
setEventMessages($object->error, $object->errors, 'errors');
}
}
$object = new AdherentType($db);
$result = $object->fetch($id);
/*
* View
*/
$title = $langs->trans('MemberTypeCard');
$helpurl = '';
$shortlabel = dol_trunc($object->label, 16);
$title = $langs->trans('MemberType')." ". $shortlabel ." - ".$langs->trans('Translation');
$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
llxHeader('', $title, $helpurl);
$form = new Form($db);
$formadmin=new FormAdmin($db);
$head = member_type_prepare_head($object);
$titre=$langs->trans("MemberType".$object->type);
// Calculate $cnt_trans
$cnt_trans = 0;
if (! empty($object->multilangs))
{
foreach ($object->multilangs as $key => $value)
{
$cnt_trans++;
}
}
dol_fiche_head($head, 'translation', $titre, 0, 'group');
$linkback = '<a href="'.dol_buildpath('/adherents/type.php', 1).'">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'rowid', $linkback);
dol_fiche_end();
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n";
if ($action == '')
{
if ($user->rights->produit->creer || $user->rights->service->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=add&rowid='.$object->id.'">'.$langs->trans("Add").'</a>';
if ($cnt_trans > 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=edit&rowid='.$object->id.'">'.$langs->trans("Update").'</a>';
}
}
print "\n</div>\n";
if ($action == 'edit')
{
//WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="vedit">';
print '<input type="hidden" name="rowid" value="'.$object->id.'">';
if (! empty($object->multilangs))
{
foreach ($object->multilangs as $key => $value)
{
$s=picto_from_langcode($key);
print "<br>".($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"')."</a><br>";
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.dol_escape_htmltag($object->multilangs[$key]["label"]).'"></td></tr>';
print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
$doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
$doleditor->Create();
print '</td></tr>';
print '</td></tr>';
print '</table>';
}
}
print '<br>';
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>';
}
elseif ($action != 'add')
{
if (! empty($object->multilangs))
{
foreach ($object->multilangs as $key => $value)
{
$s=picto_from_langcode($key);
print ($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"').'</a>';
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
print '</table>';
print '</div>';
}
}
if (! $cnt_trans && $action != 'add') print '<div class="opacitymedium">'. $langs->trans('NoTranslation').'</div>';
}
/*
* Form to add a new translation
*/
if ($action == 'add' && $user->rights->adherent->configurer)
{
//WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print '<br>';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="vadd">';
print '<input type="hidden" name="rowid" value="'.GETPOST("rowid", 'int').'">';
dol_fiche_head();
print '<table class="border" width="100%">';
print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
print $formadmin->select_language('', 'forcelangprod', 0, $object->multilangs, 1);
print '</td></tr>';
print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
$doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
$doleditor->Create();
print '</td></tr>';
print '</table>';
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>';
print '<br>';
}
// End of page
llxFooter();
$db->close();

View File

@ -127,6 +127,15 @@ function member_type_prepare_head(AdherentType $object)
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
// Multilangs
if (! empty($conf->global->MAIN_MULTILANGS))
{
$head[$h][0] = DOL_URL_ROOT."/adherents/type_translation.php?rowid=".$object->id;
$head[$h][1] = $langs->trans("Translation");
$head[$h][2] = 'translation';
$h++;
}
if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE))
&& (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin)))

View File

@ -226,6 +226,17 @@ INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, m
INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, month, day, active) VALUES('IN-REPUBLICDAY', 0, 117, '', 0, 1, 26, 1);
INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, month, day, active) VALUES('IN-GANDI', 0, 117, '', 0, 10, 2, 1);
create table llx_adherent_type_lang
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_type integer DEFAULT 0 NOT NULL,
lang varchar(5) DEFAULT 0 NOT NULL,
label varchar(255) NOT NULL,
description text,
email text,
import_key varchar(14) DEFAULT NULL
)ENGINE=innodb;
create table llx_fichinter_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,

View File

@ -0,0 +1,30 @@
-- ============================================================================
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_adherent_type_lang
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_type integer DEFAULT 0 NOT NULL,
lang varchar(5) DEFAULT 0 NOT NULL,
label varchar(255) NOT NULL,
description text,
email text,
import_key varchar(14) DEFAULT NULL
)ENGINE=innodb;