Fix delete of member

This commit is contained in:
Laurent Destailleur 2017-06-09 17:02:05 +02:00
parent def784a5fe
commit 3347316d3c
7 changed files with 177 additions and 176 deletions

View File

@ -182,7 +182,7 @@ abstract class ActionsAdherentCardCommon
$this->object->old_name = $_POST["old_name"]; $this->object->old_name = $_POST["old_name"];
$this->object->old_firstname = $_POST["old_firstname"]; $this->object->old_firstname = $_POST["old_firstname"];
$result = $this->object->delete(); $result = $this->object->delete(0, $user, 0);
if ($result > 0) if ($result > 0)
{ {
header("Location: list.php"); header("Location: list.php");

View File

@ -585,7 +585,7 @@ if (empty($reshook))
if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
{ {
$result=$object->delete($id); $result=$object->delete($id, $user);
if ($result > 0) if ($result > 0)
{ {
if (! empty($backtopage)) if (! empty($backtopage))

View File

@ -705,11 +705,13 @@ class Adherent extends CommonObject
* Fonction qui supprime l'adherent et les donnees associees * Fonction qui supprime l'adherent et les donnees associees
* *
* @param int $rowid Id of member to delete * @param int $rowid Id of member to delete
* @param User $user User object
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if KO, 0=nothing to do, >0 if OK * @return int <0 if KO, 0=nothing to do, >0 if OK
*/ */
function delete($rowid) function delete($rowid, $user, $notrigger=0)
{ {
global $conf, $langs, $user; global $conf, $langs;
$result = 0; $result = 0;
$error=0; $error=0;
@ -720,6 +722,14 @@ class Adherent extends CommonObject
$this->db->begin(); $this->db->begin();
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('MEMBER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
// Remove category // Remove category
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid; $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
@ -787,16 +797,6 @@ class Adherent extends CommonObject
} }
} }
if (! $error)
{
// Call trigger
$result=$this->call_trigger('MEMBER_DELETE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();

View File

@ -250,11 +250,7 @@ class Members extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
// The Adherent::delete() method uses the global variable $user. if (! $member->delete($member->id, DolibarrApiAccess::$user)) {
global $user;
$user = DolibarrApiAccess::$user;
if (! $member->delete($member->id)) {
throw new RestException(401,'error when deleting member'); throw new RestException(401,'error when deleting member');
} }

View File

@ -31,13 +31,17 @@ require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$langs->load("members"); $langs->loadLangs(array("members","companies"));
$langs->load("companies");
$action=GETPOST('action','aZ09');
$massaction=GETPOST('massaction','alpha');
$show_files=GETPOST('show_files','int');
$confirm=GETPOST('confirm','alpha');
$toselect = GETPOST('toselect', 'array');
// Security check // Security check
$result=restrictedArea($user,'adherent'); $result=restrictedArea($user,'adherent');
$action=GETPOST('action','aZ09');
$filter=GETPOST("filter"); $filter=GETPOST("filter");
$statut=GETPOST("statut"); $statut=GETPOST("statut");
$search=GETPOST("search"); $search=GETPOST("search");
@ -53,7 +57,7 @@ $search_country=GETPOST("search_country");
$search_phone=GETPOST("search_phone"); $search_phone=GETPOST("search_phone");
$search_phone_perso=GETPOST("search_phone_perso"); $search_phone_perso=GETPOST("search_phone_perso");
$search_phone_mobile=GETPOST("search_phone_mobile"); $search_phone_mobile=GETPOST("search_phone_mobile");
$type=GETPOST("type"); $search_type=GETPOST("search_type");
$search_email=GETPOST("search_email"); $search_email=GETPOST("search_email");
$search_categ = GETPOST("search_categ",'int'); $search_categ = GETPOST("search_categ",'int');
$catid = GETPOST("catid",'int'); $catid = GETPOST("catid",'int');
@ -155,7 +159,7 @@ if (empty($reshook))
$search_firstname=""; $search_firstname="";
$search_login=""; $search_login="";
$search_company=""; $search_company="";
$type=""; $search_type="";
$search_email=""; $search_email="";
$search_address=""; $search_address="";
$search_zip=""; $search_zip="";
@ -173,6 +177,14 @@ if (empty($reshook))
$toselect=''; $toselect='';
$search_array_options=array(); $search_array_options=array();
} }
// Mass actions
$objectclass='Adherent';
$objectlabel='Members';
$permtoread = $user->rights->adherent->lire;
$permtodelete = $user->rights->adherent->supprimer;
$uploaddir = $conf->adherent->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
} }
@ -193,8 +205,8 @@ $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.skype, d.birth, d.pu
$sql.= " d.fk_adherent_type as type_id, d.morphy, d.statut, d.datec as date_creation, d.tms as date_update,"; $sql.= " d.fk_adherent_type as type_id, d.morphy, d.statut, d.datec as date_creation, d.tms as date_update,";
$sql.= " t.libelle as type, t.subscription,"; $sql.= " t.libelle as type, t.subscription,";
$sql.= " state.code_departement as state_code, state.nom as state_name"; $sql.= " state.code_departement as state_code, state.nom as state_name";
// Add fields for extrafields // Add fields from extrafields
foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key; foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
@ -212,7 +224,7 @@ if ($search_categ > 0) $sql.= " AND cm.fk_categorie = ".$db->escape($search_ca
if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL"; if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL";
$sql.= " AND d.entity IN (".getEntity('adherent').")"; $sql.= " AND d.entity IN (".getEntity('adherent').")";
if ($sall) $sql.=natural_search(array_keys($fieldstosearchall), $sall); if ($sall) $sql.=natural_search(array_keys($fieldstosearchall), $sall);
if ($type > 0) $sql.=" AND t.rowid=".$db->escape($type); if ($search_type > 0) $sql.=" AND t.rowid=".$db->escape($search_type);
if ($statut != '') $sql.=" AND d.statut in (".$db->escape($statut).")"; // Peut valoir un nombre ou liste de nombre separes par virgules if ($statut != '') $sql.=" AND d.statut in (".$db->escape($statut).")"; // Peut valoir un nombre ou liste de nombre separes par virgules
if ($search_ref) if ($search_ref)
{ {
@ -298,10 +310,10 @@ elseif ($action == 'search')
$titre=$langs->trans("MembersListQualified"); $titre=$langs->trans("MembersListQualified");
} }
if ($type > 0) if ($search_type > 0)
{ {
$membertype=new AdherentType($db); $membertype=new AdherentType($db);
$result=$membertype->fetch(GETPOST("type")); $result=$membertype->fetch(GETPOST("type",'int'));
$titre.=" (".$membertype->libelle.")"; $titre.=" (".$membertype->libelle.")";
} }
@ -326,7 +338,7 @@ if ($search_phone != '') $param.= "&search_phone=".urlencode($search_phone);
if ($search_phone_perso != '') $param.= "&search_phone_perso=".urlencode($search_phone_perso); if ($search_phone_perso != '') $param.= "&search_phone_perso=".urlencode($search_phone_perso);
if ($search_phone_mobile != '') $param.= "&search_phone_mobile=".urlencode($search_phone_mobile); if ($search_phone_mobile != '') $param.= "&search_phone_mobile=".urlencode($search_phone_mobile);
if ($filter) $param.="&filter=".urlencode($filter); if ($filter) $param.="&filter=".urlencode($filter);
if ($type > 0) $param.="&type=".urlencode($type); if ($search_type > 0) $param.="&search_type=".urlencode($search_type);
if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
// Add $param from extra fields // Add $param from extra fields
foreach ($search_array_options as $key => $val) foreach ($search_array_options as $key => $val)
@ -346,7 +358,7 @@ if ($user->rights->adherent->supprimer) $arrayofmassactions['delete']=$langs->tr
//if ($massaction == 'presend' || $massaction == 'createbills') $arrayofmassactions=array(); //if ($massaction == 'presend' || $massaction == 'createbills') $arrayofmassactions=array();
$massactionbutton=$form->selectMassAction('', $arrayofmassactions); $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
@ -444,7 +456,7 @@ if (! empty($arrayfields['t.libelle']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
$listetype=$membertypestatic->liste_array(); $listetype=$membertypestatic->liste_array();
print $form->selectarray("type", $listetype, $type, 1, 0, 0, '', 0, 32); print $form->selectarray("search_type", $listetype, $type, 1, 0, 0, '', 0, 32);
print '</td>'; print '</td>';
} }
@ -832,20 +844,13 @@ while ($i < min($num, $limit))
} }
// Action column // Action column
print '<td align="center">'; print '<td align="center">';
if ($user->rights->adherent->creer) if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{ {
print "<a href=\"card.php?rowid=".$obj->rowid."&action=edit&backtopage=1\">".img_edit()."</a>"; $selected=0;
if (in_array($obj->rowid, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
} }
print '&nbsp;'; print '</td>';
if ($user->rights->adherent->supprimer && $obj->statut == -1)
{
print "<a href=\"card.php?rowid=".$obj->rowid."&action=delete&backtopage=1\">".img_picto($langs->trans("Delete"),'disable.png')."</a>";
}
if ($user->rights->adherent->supprimer && $obj->statut == 1)
{
print "<a href=\"card.php?rowid=".$obj->rowid."&action=resign&backtopage=1\">".img_picto($langs->trans("Resiliate"),'disable.png')."</a>";
}
print "</td>";
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
print "</tr>\n"; print "</tr>\n";

View File

@ -45,7 +45,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills')); $langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills'));
$action=GETPOST('action','alpha'); $action=GETPOST('action','aZ09');
$massaction=GETPOST('massaction','alpha'); $massaction=GETPOST('massaction','alpha');
$show_files=GETPOST('show_files','int'); $show_files=GETPOST('show_files','int');
$confirm=GETPOST('confirm','alpha'); $confirm=GETPOST('confirm','alpha');

View File

@ -536,7 +536,7 @@ if (! $error && $massaction == 'delete' && $permtodelete)
$result=$objecttmp->fetch($toselectid); $result=$objecttmp->fetch($toselectid);
if ($result > 0) if ($result > 0)
{ {
if ($objecttmp->element == 'societe') $result = $objecttmp->delete($objecttmp->id, $user, 1); if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
else $result = $objecttmp->delete($user); else $result = $objecttmp->delete($user);
if ($result <= 0) if ($result <= 0)
{ {