New: big refactorization and uniformize code

This commit is contained in:
Regis Houssin 2017-09-16 10:54:20 +02:00
parent 767240698f
commit 9653280be9
7 changed files with 378 additions and 203 deletions

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012-2016 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2012-2016 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
@ -121,7 +121,16 @@ $hookmanager->initHooks(array('membercard','globalcard'));
* Actions * Actions
*/ */
if ($cancel) $action=''; if ($cancel) {
$action='';
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
}
$parameters=array('id'=>$id, 'rowid'=>$id, 'objcanvas'=>$objcanvas); $parameters=array('id'=>$id, 'rowid'=>$id, 'objcanvas'=>$objcanvas);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
@ -813,6 +822,7 @@ else
print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">'; print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
dol_fiche_head(''); dol_fiche_head('');
@ -957,7 +967,7 @@ else
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("AddMember").'">'; print '<input type="submit" name="button" class="button" value="'.$langs->trans("AddMember").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" />'; print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print "</form>\n"; print "</form>\n";
@ -1225,7 +1235,7 @@ else
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" />'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print '</form>'; print '</form>';

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2017 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com> * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
@ -22,7 +22,6 @@
* \file htdocs/adherents/class/adherent_type.class.php * \file htdocs/adherents/class/adherent_type.class.php
* \ingroup member * \ingroup member
* \brief File of class to manage members types * \brief File of class to manage members types
* \author Rodolphe Quiedeville
*/ */
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
@ -64,140 +63,192 @@ class AdherentType extends CommonObject
public $mail_valid; public $mail_valid;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
*/ */
function __construct($db) function __construct($db)
{ {
$this->db = $db; $this->db = $db;
$this->statut = 1; $this->statut = 1;
} }
/** /**
* Fonction qui permet de creer le status de l'adherent * Fonction qui permet de creer le status de l'adherent
* *
* @param User $user User making creation * @param User $user User making creation
* @return int >0 if OK, < 0 if KO * @param int $notrigger 1=do not execute triggers, 0 otherwise
*/ * @return int >0 if OK, < 0 if KO
function create($user) */
{ function create($user,$notrigger=0)
global $conf; {
global $conf;
$this->statut=(int) $this->statut; $error=0;
$this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label));
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type ("; $this->statut=(int) $this->statut;
$sql.= "libelle"; $this->label=trim($this->label);
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'".$this->db->escape($this->label)."'";
$sql.= ", ".$conf->entity;
$sql.= ")";
dol_syslog("Adherent_type::create", LOG_DEBUG); $this->db->begin();
$result = $this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
return $this->update($user);
}
else
{
$this->error=$this->db->error().' sql='.$sql;
return -1;
}
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
$sql.= "libelle";
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'".$this->db->escape($this->label)."'";
$sql.= ", ".$conf->entity;
$sql.= ")";
/** dol_syslog("Adherent_type::create", LOG_DEBUG);
* Met a jour en base donnees du type $result = $this->db->query($sql);
* if ($result)
* @param User $user Object user making change {
* @return int >0 if OK, < 0 if KO $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
*/
function update($user)
{
global $hookmanager,$conf;
$error=0; $result = $this->update($user,1);
if ($result < 0)
{
$this->db->rollback();
return -3;
}
$this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label)); if (! $notrigger)
{
// Call trigger
$result=$this->call_trigger('MEMBER_TYPE_CREATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type "; if (! $error)
$sql.= "SET "; {
$sql.= "statut = ".$this->statut.","; $this->db->commit();
$sql.= "libelle = '".$this->db->escape($this->label) ."',"; return $this->id;
$sql.= "subscription = '".$this->db->escape($this->subscription)."',"; }
$sql.= "note = '".$this->db->escape($this->note)."',"; else
$sql.= "vote = '".$this->db->escape($this->vote)."',"; {
$sql.= "mail_valid = '".$this->db->escape($this->mail_valid)."'"; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
$sql.= " WHERE rowid =".$this->id; $this->db->rollback();
return -2;
}
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
}
$result = $this->db->query($sql); /**
if ($result) * Met a jour en base donnees du type
{ *
$action='update'; * @param User $user Object user making change
* @param int $notrigger 1=do not execute triggers, 0 otherwise
* @return int >0 if OK, < 0 if KO
*/
function update($user,$notrigger=0)
{
global $conf, $hookmanager;
// Actions on extra fields (by external module or standard code) $error=0;
$hookmanager->initHooks(array('membertypedao'));
$parameters=array('membertype'=>$this->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
$this->label=trim($this->label);
return 1; $this->db->begin();
}
else
{
$this->error=$this->db->error().' sql='.$sql;
return -1;
}
}
/** $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
* Fonction qui permet de supprimer le status de l'adherent $sql.= "SET ";
* $sql.= "statut = ".$this->statut.",";
* @param int $rowid Id of member type to delete $sql.= "libelle = '".$this->db->escape($this->label) ."',";
* @return int >0 if OK, 0 if not found, < 0 if KO $sql.= "subscription = '".$this->db->escape($this->subscription)."',";
*/ $sql.= "note = '".$this->db->escape($this->note)."',";
function delete($rowid='') $sql.= "vote = '".$this->db->escape($this->vote)."',";
{ $sql.= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
if (empty($rowid)) $rowid=$this->id; $sql.= " WHERE rowid =".$this->id;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type WHERE rowid = ".$rowid; $result = $this->db->query($sql);
if ($result)
{
$action='update';
$resql=$this->db->query($sql); // Actions on extra fields (by external module or standard code)
if ($resql) $hookmanager->initHooks(array('membertypedao'));
{ $parameters=array('membertype'=>$this->id);
if ($this->db->affected_rows($resql)) $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
{ if (empty($reshook))
return 1; {
} if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
else {
{ $result=$this->insertExtraFields();
return 0; if ($result < 0)
} {
} $error++;
else }
{ }
print "Err : ".$this->db->error(); }
return 0; else if ($reshook < 0) $error++;
}
} if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('MEMBER_TYPE_MODIFY',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
return -$error;
}
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
}
/**
* Fonction qui permet de supprimer le status de l'adherent
*
* @return int >0 if OK, 0 if not found, < 0 if KO
*/
function delete()
{
global $user;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
$sql.= " WHERE rowid = ".$this->id;
$resql=$this->db->query($sql);
if ($resql)
{
// Call trigger
$result=$this->call_trigger('MEMBER_TYPE_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -2; }
// End call triggers
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
}
/** /**
* Fonction qui permet de recuperer le status de l'adherent * Fonction qui permet de recuperer le status de l'adherent
@ -223,7 +274,6 @@ class AdherentType extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->label = $obj->label; $this->label = $obj->label;
$this->libelle = $obj->label; // For backward compatibility
$this->statut = $obj->statut; $this->statut = $obj->statut;
$this->subscription = $obj->subscription; $this->subscription = $obj->subscription;
$this->mail_valid = $obj->mail_valid; $this->mail_valid = $obj->mail_valid;
@ -250,7 +300,7 @@ class AdherentType extends CommonObject
$adherenttypes = array(); $adherenttypes = array();
$sql = "SELECT rowid, libelle"; $sql = "SELECT rowid, libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
$sql.= " WHERE entity IN (".getEntity('adherent').")"; $sql.= " WHERE entity IN (".getEntity('adherent').")";
@ -266,7 +316,7 @@ class AdherentType extends CommonObject
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$adherenttypes[$obj->rowid] = $langs->trans($obj->libelle); $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
$i++; $i++;
} }
} }
@ -278,12 +328,11 @@ class AdherentType extends CommonObject
return $adherenttypes; return $adherenttypes;
} }
/** /**
* Return clicable name (with picto eventually) * Return clicable name (with picto eventually)
* *
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param int $maxlen length max libelle * @param int $maxlen length max label
* @return string String with URL * @return string String with URL
*/ */
function getNomUrl($withpicto=0,$maxlen=0) function getNomUrl($withpicto=0,$maxlen=0)
@ -291,7 +340,7 @@ class AdherentType extends CommonObject
global $langs; global $langs;
$result=''; $result='';
$label=$langs->trans("ShowTypeCard",$this->libelle); $label=$langs->trans("ShowTypeCard",$this->label);
$link = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $link = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>'; $linkend='</a>';
@ -300,20 +349,101 @@ class AdherentType extends CommonObject
if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$link.($maxlen?dol_trunc($this->libelle,$maxlen):$this->libelle).$linkend; $result.=$link.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend;
return $result; return $result;
} }
/** /**
* getLibStatut * getLibStatut
* *
* @return string Return status of a type of member * @return string Return status of a type of member
*/ */
function getLibStatut() function getLibStatut()
{ {
return ''; return '';
} }
/**
* Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
*
* @param array $info Info array loaded by _load_ldap_info
* @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
* 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
* 2=Return key only (uid=qqq)
* @return string DN
*/
function _load_ldap_dn($info,$mode=0)
{
global $conf;
$dn='';
if ($mode==0) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN;
if ($mode==1) $dn=$conf->global->LDAP_MEMBER_TYPE_DN;
if ($mode==2) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
return $dn;
}
/**
* Initialize the info array (array of LDAP values) that will be used to call LDAP functions
*
* @return array Tableau info des attributs
*/
function _load_ldap_info()
{
global $conf,$langs;
$info=array();
// Object classes
$info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
// Champs
if ($this->label && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
if ($this->note && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = $this->note;
if (! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS))
{
$valueofldapfield=array();
foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database.
{
$member=new Adherent($this->db);
$member->fetch($val->id);
$info2 = $member->_load_ldap_info();
$valueofldapfield[] = $member->_load_ldap_dn($info2);
}
$info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:'');
}
return $info;
}
/**
* Initialise an instance with random values.
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @return void
*/
function initAsSpecimen()
{
global $conf, $user, $langs;
// Initialise parametres
$this->id = 0;
$this->ref = 0;
$this->specimen=1;
$this->label='MEMBERS TYPE SPECIMEN';
$this->note='This is a note';
$this->mail_valid='This is welcome email';
$this->subscription=1;
$this->vote=0;
$this->statut=1;
// Members of this member type is just me
$this->members=array(
$user->id => $user
);
}
/** /**
* getMailOnValid * getMailOnValid

View File

@ -272,7 +272,6 @@ class MembersTypes extends DolibarrApi
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->cotisation); unset($object->cotisation);
unset($object->libelle);
unset($object->array_options); unset($object->array_options);
unset($object->linkedObjectsIds); unset($object->linkedObjectsIds);

View File

@ -59,7 +59,7 @@ $AdherentsResilies=array();
$AdherentType=array(); $AdherentType=array();
// Liste les adherents // Liste les adherents
$sql = "SELECT t.rowid, t.libelle, t.subscription,"; $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
$sql.= " d.statut, count(d.rowid) as somme"; $sql.= " d.statut, count(d.rowid) as somme";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
@ -81,7 +81,7 @@ if ($result)
$adhtype=new AdherentType($db); $adhtype=new AdherentType($db);
$adhtype->id=$objp->rowid; $adhtype->id=$objp->rowid;
$adhtype->subscription=$objp->subscription; $adhtype->subscription=$objp->subscription;
$adhtype->libelle=$objp->libelle; $adhtype->label=$objp->label;
$AdherentType[$objp->rowid]=$adhtype; $AdherentType[$objp->rowid]=$adhtype;
if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; } if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
@ -273,7 +273,7 @@ $max=5;
$sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,"; $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
$sql.= " a.tms as datem, datefin as date_end_subscription,"; $sql.= " a.tms as datem, datefin as date_end_subscription,";
$sql.= " ta.rowid as typeid, ta.libelle, ta.subscription"; $sql.= " ta.rowid as typeid, ta.libelle as label, ta.subscription";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
$sql.= " WHERE a.entity IN (".getEntity('adherent').")"; $sql.= " WHERE a.entity IN (".getEntity('adherent').")";
$sql.= " AND a.fk_adherent_type = ta.rowid"; $sql.= " AND a.fk_adherent_type = ta.rowid";
@ -310,7 +310,7 @@ if ($resql)
} }
$staticmember->ref=$staticmember->getFullName($langs); $staticmember->ref=$staticmember->getFullName($langs);
$statictype->id=$obj->typeid; $statictype->id=$obj->typeid;
$statictype->libelle=$obj->libelle; $statictype->label=$obj->label;
print '<td>'.$staticmember->getNomUrl(1,32).'</td>'; print '<td>'.$staticmember->getNomUrl(1,32).'</td>';
print '<td>'.$statictype->getNomUrl(1,32).'</td>'; print '<td>'.$statictype->getNomUrl(1,32).'</td>';
print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>'; print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';

View File

@ -315,7 +315,7 @@ if ($search_type > 0)
{ {
$membertype=new AdherentType($db); $membertype=new AdherentType($db);
$result=$membertype->fetch(GETPOST("type",'int')); $result=$membertype->fetch(GETPOST("type",'int'));
$titre.=" (".$membertype->libelle.")"; $titre.=" (".$membertype->label.")";
} }
$param=''; $param='';
@ -698,7 +698,7 @@ while ($i < min($num, $limit))
if (! empty($arrayfields['t.libelle']['checked'])) if (! empty($arrayfields['t.libelle']['checked']))
{ {
$membertypestatic->id=$obj->type_id; $membertypestatic->id=$obj->type_id;
$membertypestatic->libelle=$obj->type; $membertypestatic->label=$obj->type;
print '<td class="nowrap">'; print '<td class="nowrap">';
print $membertypestatic->getNomUrl(1,32); print $membertypestatic->getNomUrl(1,32);
print '</td>'; print '</td>';

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
@ -37,6 +37,7 @@ $langs->load("members");
$rowid = GETPOST('rowid','int'); $rowid = GETPOST('rowid','int');
$action = GETPOST('action','alpha'); $action = GETPOST('action','alpha');
$cancel = GETPOST('cancel','alpha'); $cancel = GETPOST('cancel','alpha');
$backtopage = GETPOST('backtopage','alpha');
$search_lastname = GETPOST('search_lastname','alpha'); $search_lastname = GETPOST('search_lastname','alpha');
$search_login = GETPOST('search_login','alpha'); $search_login = GETPOST('search_login','alpha');
@ -64,6 +65,8 @@ $mail_valid=GETPOST("mail_valid");
// Security check // Security check
$result=restrictedArea($user,'adherent',$rowid,'adherent_type'); $result=restrictedArea($user,'adherent',$rowid,'adherent_type');
$object = new AdherentType($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels
@ -87,73 +90,95 @@ $hookmanager->initHooks(array('membertypecard','globalcard'));
* Actions * Actions
*/ */
if ($cancel) {
$action='';
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
}
if ($action == 'add' && $user->rights->adherent->configurer) if ($action == 'add' && $user->rights->adherent->configurer)
{ {
if (! $cancel) $object->label = trim($label);
$object->subscription = (int) trim($subscription);
$object->note = trim($comment);
$object->mail_valid = trim($mail_valid);
$object->vote = (boolean) trim($vote);
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if ($object->label)
{ {
$object = new AdherentType($db); $id=$object->create($user);
if ($id > 0)
$object->label = trim($label);
$object->subscription = (int) trim($subscription);
$object->note = trim($comment);
$object->mail_valid = (boolean) trim($mail_valid);
$object->vote = (boolean) trim($vote);
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if ($object->label)
{ {
$id=$object->create($user); header("Location: ".$_SERVER["PHP_SELF"]);
if ($id > 0) exit;
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$mesg=$object->error;
$action = 'create';
}
} }
else else
{ {
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); $mesg=$object->error;
$action = 'create'; $action = 'create';
} }
} }
else
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
$action = 'create';
}
} }
if ($action == 'update' && $user->rights->adherent->configurer) if ($action == 'update' && $user->rights->adherent->configurer)
{ {
if (! $cancel) $object->fetch($rowid);
$object->label = trim($label);
$object->subscription = (int) trim($subscription);
$object->note = trim($comment);
$object->mail_valid = trim($mail_valid);
$object->vote = (boolean) trim($vote);
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$ret=$object->update($user);
if ($ret >= 0 && ! count($object->errors))
{ {
$object = new AdherentType($db); setEventMessages($langs->trans("MemberTypeModified"), null, 'mesgs');
$object->id = $rowid;
$object->label = trim($label);
$object->subscription = (int) trim($subscription);
$object->note = trim($comment);
$object->mail_valid = (boolean) trim($mail_valid);
$object->vote = (boolean) trim($vote);
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$object->update($user);
header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$_POST["rowid"]);
exit;
} }
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id);
exit;
} }
if ($action == 'delete' && $user->rights->adherent->configurer) if ($action == 'confirm_delete' && $user->rights->adherent->configurer)
{ {
$object = new AdherentType($db); $object->fetch($rowid);
$object->delete($rowid); $res=$object->delete();
header("Location: ".$_SERVER["PHP_SELF"]);
exit; if ($res > 0)
{
setEventMessages($langs->trans("MemberTypeDeleted"), null, 'mesgs');
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
setEventMessages($langs->trans("MemberTypeCanNotBeDeleted"), null, 'errors');
$action='';
}
} }
@ -308,7 +333,15 @@ if ($rowid > 0)
{ {
$object = new AdherentType($db); $object = new AdherentType($db);
$object->fetch($rowid); $object->fetch($rowid);
$object->fetch_optionals($rowid,$extralabels); $object->fetch_optionals($object->id,$extralabels);
/*
* Confirmation suppression
*/
if ($action == 'delete')
{
print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id,$langs->trans("DeleteAMemberType"),$langs->trans("ConfirmDeleteMemberType",$object->label),"confirm_delete", '',0,1);
}
$head = member_type_prepare_head($object); $head = member_type_prepare_head($object);
@ -337,15 +370,14 @@ if ($rowid > 0)
print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>'; print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
print nl2br($object->mail_valid)."</td></tr>"; print nl2br($object->mail_valid)."</td></tr>";
// Other attributes // Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
dol_fiche_end(); dol_fiche_end();
/* /*
* Buttons * Buttons
*/ */
@ -359,7 +391,7 @@ if ($rowid > 0)
} }
// Add // Add
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=create&typeid='.$object->id.'">'.$langs->trans("AddMember").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=create&typeid='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.$langs->trans("AddMember").'</a></div>';
// Delete // Delete
if ($user->rights->adherent->configurer) if ($user->rights->adherent->configurer)
@ -459,7 +491,7 @@ if ($rowid > 0)
$titre.=" (".$membertype->label.")"; $titre.=" (".$membertype->label.")";
} }
$param="&rowid=".$rowid; $param="&rowid=".$object->id;
if (! empty($status)) $param.="&status=".$status; if (! empty($status)) $param.="&status=".$status;
if (! empty($search_lastname)) $param.="&search_lastname=".$search_lastname; if (! empty($search_lastname)) $param.="&search_lastname=".$search_lastname;
if (! empty($search_firstname)) $param.="&search_firstname=".$search_firstname; if (! empty($search_firstname)) $param.="&search_firstname=".$search_firstname;
@ -473,7 +505,7 @@ if ($rowid > 0)
} }
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input class="flat" type="hidden" name="rowid" value="'.$rowid.'" size="12"></td>'; print '<input class="flat" type="hidden" name="rowid" value="'.$object->id.'" size="12"></td>';
print '<br>'; print '<br>';
print_barre_liste('',$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); print_barre_liste('',$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
@ -593,12 +625,12 @@ if ($rowid > 0)
print '<td align="center">'; print '<td align="center">';
if ($user->rights->adherent->creer) if ($user->rights->adherent->creer)
{ {
print '<a href="card.php?rowid='.$objp->rowid.'&action=edit&return=list.php">'.img_edit().'</a>'; print '<a href="card.php?rowid='.$objp->rowid.'&action=edit&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.img_edit().'</a>';
} }
print '&nbsp;'; print '&nbsp;';
if ($user->rights->adherent->supprimer) if ($user->rights->adherent->supprimer)
{ {
print '<a href="card.php?rowid='.$objp->rowid.'&action=resign&return=list.php">'.img_picto($langs->trans("Resiliate"),'disable.png').'</a>'; print '<a href="card.php?rowid='.$objp->rowid.'&action=resign">'.img_picto($langs->trans("Resiliate"),'disable.png').'</a>';
} }
print "</td>"; print "</td>";
@ -631,15 +663,14 @@ if ($rowid > 0)
if ($action == 'edit') if ($action == 'edit')
{ {
$object = new AdherentType($db); $object = new AdherentType($db);
$object->id = $rowid;
$object->fetch($rowid); $object->fetch($rowid);
$object->fetch_optionals($rowid,$extralabels); $object->fetch_optionals($object->id,$extralabels);
$head = member_type_prepare_head($object); $head = member_type_prepare_head($object);
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">'; print '<input type="hidden" name="rowid" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
dol_fiche_head($head, 'card', $langs->trans("MemberType"), 0, 'group'); dol_fiche_head($head, 'card', $langs->trans("MemberType"), 0, 'group');
@ -706,7 +737,7 @@ if ($rowid > 0)
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'">'; print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print "</form>"; print "</form>";

View File

@ -57,6 +57,11 @@ NewCotisation=New contribution
PaymentSubscription=New contribution payment PaymentSubscription=New contribution payment
SubscriptionEndDate=Subscription's end date SubscriptionEndDate=Subscription's end date
MembersTypeSetup=Members type setup MembersTypeSetup=Members type setup
MemberTypeModified=Member type modified
DeleteAMemberType=Delete a member type
ConfirmDeleteMemberType=Are you sure you want to delete this member type?
MemberTypeDeleted=Member type deleted
MemberTypeCanNotBeDeleted=Member type can not be deleted
NewSubscription=New subscription NewSubscription=New subscription
NewSubscriptionDesc=This form allows you to record your subscription as a new member of the foundation. If you want to renew your subscription (if already a member), please contact foundation board instead by email %s. NewSubscriptionDesc=This form allows you to record your subscription as a new member of the foundation. If you want to renew your subscription (if already a member), please contact foundation board instead by email %s.
Subscription=Subscription Subscription=Subscription