Revize 2a7bec72
Přidáno uživatelem Ondřej Fibich před více než 6 roky(ů)
application/controllers/members.php | ||
---|---|---|
$grid->datasource($query);
|
||
}
|
||
|
||
if ($this->acl_check_delete(get_class($this), 'members'))
|
||
{
|
||
$actions->add_conditional_action('id')
|
||
->condition('is_former_for_more_than_limit_years')
|
||
->icon_action('delete')
|
||
->url('members/delete_former')
|
||
->label('Delete member')
|
||
->class('delete_link');
|
||
}
|
||
|
||
if (isset($_POST) && count($_POST) > 1)
|
||
{
|
||
$ids = $_POST["ids"];
|
||
... | ... | |
$member_links = array();
|
||
$user_links = array();
|
||
|
||
// member edit link
|
||
if (!$is_former &&
|
||
$this->acl_check_edit(get_class($this), 'members', $member->id))
|
||
// member delete/edit link
|
||
if ($is_former)
|
||
{
|
||
if ($this->acl_check_delete(get_class($this), 'members')
|
||
&& condition::is_former_for_more_than_limit_years($member))
|
||
{
|
||
$member_links[] = html::anchor(
|
||
'members/delete_former/'.$member->id,
|
||
__('Delete'),
|
||
array
|
||
(
|
||
'title' => __('Delete'),
|
||
'class' => 'delete_link'
|
||
)
|
||
);
|
||
}
|
||
}
|
||
else if ($this->acl_check_edit(get_class($this), 'members', $member->id))
|
||
{
|
||
$member_links[] = html::anchor(
|
||
'members/edit/'.$member->id,
|
||
... | ... | |
$view->render(TRUE);
|
||
} // end of edit function
|
||
|
||
/**
|
||
* Delete former member that has left at least before 5 years.
|
||
*
|
||
* @param int $member_id id of member to delete
|
||
*/
|
||
public function delete_former($member_id = NULL)
|
||
{
|
||
if (!isset($member_id) || !is_numeric($member_id))
|
||
{
|
||
self::warning(PARAMETER);
|
||
}
|
||
|
||
$member = new Member_Model($member_id);
|
||
|
||
// member doesn't exist
|
||
if (!$member->id)
|
||
{
|
||
self::error(RECORD);
|
||
}
|
||
|
||
// access control
|
||
if (!$this->acl_check_delete(get_class($this), 'members'))
|
||
{
|
||
self::error(ACCESS);
|
||
}
|
||
|
||
if (!condition::is_former_for_more_than_limit_years($member))
|
||
{
|
||
self::error(ACCESS);
|
||
}
|
||
|
||
try
|
||
{
|
||
$ba_model = new Bank_account_Model();
|
||
$bank_trans_model = new Bank_transfer_Model();
|
||
|
||
$member->transaction_start();
|
||
|
||
// change member credit account name
|
||
$credit_account = $member->get_credit_account();
|
||
if ($credit_account->id)
|
||
{
|
||
$credit_account->name = __('Former member') . ' ' . $member->id;
|
||
$credit_account->save_throwable();
|
||
}
|
||
|
||
// delete bank accounts and their transfers with owner set to the
|
||
// member
|
||
$bank_accounts = $ba_model->get_member_bank_accounts($member->id);
|
||
|
||
foreach ($bank_accounts as $bank_account)
|
||
{
|
||
$bank_trans_model->delete_all_with_origin($bank_account->id);
|
||
$ba_model->delete_throwable($bank_account->id);
|
||
}
|
||
|
||
// delete bank tranfers that was assigned to the member but does not
|
||
// come from his bank account (e.g. from post service)
|
||
$bank_trans_model->delete_all_with_transfer_to($member->id);
|
||
|
||
// delete member, user, jobs, job reports, contacts, etc.
|
||
$member->delete_throwable();
|
||
|
||
$member->transaction_commit();
|
||
|
||
status::success('Member has been successfully removed.');
|
||
url::redirect('members/show_all');
|
||
}
|
||
catch (Exception $ex)
|
||
{
|
||
$member->transaction_rollback();
|
||
Log::add_exception($ex);
|
||
status::error('Error - cannot remove member.', $ex);
|
||
url::redirect('members/show_all');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Enables to edid member settings (e.g. notification settings).
|
||
*
|
application/controllers/transfers.php | ||
---|---|---|
$breadcrumbs = breadcrumbs::add()
|
||
->link('members/show_all', 'Members',
|
||
$this->acl_check_view('Members_Controller', 'members')
|
||
)->disable_translation()
|
||
->link('members/show/' . $account->member_id,
|
||
'ID ' . $account->member->id . ' - ' . $account->member->name,
|
||
$this->acl_check_view(
|
||
'Members_Controller', 'members',
|
||
$account->member_id
|
||
)
|
||
)->enable_translation()
|
||
->text('Transfers');
|
||
)->disable_translation();
|
||
if ($account->member_id) {
|
||
$breadcrumbs->link('members/show/' . $account->member_id,
|
||
'ID ' . $account->member->id . ' - ' . $account->member->name,
|
||
$this->acl_check_view(
|
||
'Members_Controller', 'members',
|
||
$account->member_id
|
||
)
|
||
);
|
||
}
|
||
$breadcrumbs->enable_translation()->text('Transfers');
|
||
|
||
$view = new View('main');
|
||
$view->title = $headline;
|
application/helpers/condition.php | ||
---|---|---|
return FALSE;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Checks whether given member is former and has left before X years.
|
||
*
|
||
* @param object $item member query item
|
||
* @return boolean
|
||
*/
|
||
public static function is_former_for_more_than_limit_years($item)
|
||
{
|
||
$Xyears = Settings::get('member_former_limit_years');
|
||
$date_Xyears_before = date('Y-m-d', strtotime('-' . $Xyears . ' years'));
|
||
return ($item->type == Member_Model::TYPE_FORMER)
|
||
&& ($item->leaving_date <= $date_Xyears_before);
|
||
}
|
||
|
||
}
|
application/i18n/cs_CZ/texts.php | ||
---|---|---|
'delete device' => 'Smazat zařízení',
|
||
'delete users devices' => 'Smazat zařízení uživatele',
|
||
'delete ip address' => 'Smazat IP adresu',
|
||
'delete member' => 'Smazat člena',
|
||
'delete membership transfer' => 'Smazat převod členství',
|
||
'delete own records' => 'Smazat vlastní záznamy',
|
||
'delete selection' => 'Smazat výběr',
|
||
... | ... | |
'error - cannot recalculate fees' => 'Chyba - nelze přepočítat příspěvky.',
|
||
'error - cannot remove admin of cloud' => 'Chyba - nelze odebrat admina oblasti',
|
||
'error - cannot remove device from monitoring' => 'Chyba - nelze odstranit zařízení z monitoringu.',
|
||
'error - cannot remove member' => 'Chyba - nelze odstranit člena.',
|
||
'error - cannot save data' => 'Chyba - nelze uložit data.',
|
||
'error - cannot send email to applicant about approval of membership' => 'Chyba - nepodařilo se poslat email žadateli s vyhověním jeho žádosti o členství',
|
||
'error - cannot send email to applicant about deny of membership' => 'Chyba - nepodařilo se poslat email žadateli s nevyhověním jeho žádosti o členství',
|
||
... | ... | |
'format' => 'Formát',
|
||
'former member' => 'Bývalý člen',
|
||
'former member message' => 'Zpráva pro bývalého člena',
|
||
'former members (%d years)' => 'Bývalý členi (%d let)',
|
||
'forum' => 'fórum',
|
||
'forward dns' => 'Dopředné DNS',
|
||
'forward dns zone file was successfully generated' => 'Dopředný zónový soubor DNS byl úspěšně vygenerován',
|
||
... | ... | |
'member fee payment by cash' => 'Platba členského příspěvku hotově',
|
||
'member has been successfully added' => 'Člen byl úspěšně přidán.',
|
||
'member has been successfully updated' => 'Člen byl úspěšně upraven.',
|
||
'member has been successfully removed' => 'Člen byl úspěšně smazán.',
|
||
'member id' => 'ID člena',
|
||
'member name' => 'Jméno člena (organizace)',
|
||
'member settings has been successfully updated' => 'Nastavení člena byla úspěšně upravena',
|
application/libraries/MY_Controller.php | ||
---|---|---|
$menu->addItem(
|
||
'members/show_all', __('Members'), 'users');
|
||
}
|
||
|
||
// list of former members to delete
|
||
if ($this->acl_check_delete('Members_Controller', 'members'))
|
||
{
|
||
$Xyears = intval(Settings::get('member_former_limit_years'));
|
||
$date_Xyears_before = date('Y-m-d', strtotime('-' . $Xyears . ' years'));
|
||
// TODO: add support for building link in Filter_form library
|
||
$menu->addItem(
|
||
'members/show_all?on[0]=1&types[0]=type&opers[0]=3&values[0][]=15'
|
||
. '&tables[type]=m&tables[leaving_date]=m&on[1]=1'
|
||
. '&types[1]=leaving_date&opers[1]=8&values[1][0]=' . $date_Xyears_before
|
||
. '&types[2]=type&opers[2]=3&values[2][0]=1',
|
||
__('Former members (%d years)', array($Xyears)), 'users', array
|
||
(
|
||
'count' => $pm->count_of_former_members_to_delete($Xyears),
|
||
'color' => 'red'
|
||
));
|
||
}
|
||
|
||
/**
|
||
* @todo Add own AXO
|
application/libraries/Settings.php | ||
---|---|---|
|
||
// username regex #360
|
||
'username_regex' => '/^[a-z][a-z0-9_]{4,}$/',
|
||
|
||
// former member delete limit
|
||
'member_former_limit_years' => 5,
|
||
);
|
||
|
||
/**
|
application/models/bank_account.php | ||
---|---|---|
");
|
||
}
|
||
|
||
/**
|
||
* Gets bank account of specified member.
|
||
*
|
||
* @param int $member_id
|
||
* @return Mysql_Result
|
||
*/
|
||
public function get_member_bank_accounts($member_id)
|
||
{
|
||
return $this->db->query("
|
||
SELECT ba.*
|
||
FROM bank_accounts ba
|
||
WHERE ba.member_id = ?
|
||
", intval($member_id));
|
||
}
|
||
|
||
/**
|
||
* It gets all bank accounts except bank accounts of association.
|
||
* @return Mysql_Result
|
application/models/bank_transfer.php | ||
---|---|---|
return NULL;
|
||
}
|
||
|
||
/**
|
||
* Deletes all bank transactions that has specified bank account set as
|
||
* origin.
|
||
*
|
||
* @param int $bank_account_id
|
||
*/
|
||
public function delete_all_with_origin($bank_account_id)
|
||
{
|
||
$this->db->query("
|
||
DELETE FROM bank_transfers
|
||
WHERE origin_id = ?
|
||
", intval($bank_account_id));
|
||
}
|
||
|
||
/**
|
||
* Deletes all bank transactions that is bound to transfer with assigned
|
||
* specified member.
|
||
*
|
||
* @param int $member_id
|
||
*/
|
||
public function delete_all_with_transfer_to($member_id)
|
||
{
|
||
$this->db->query("
|
||
DELETE bank_transfers FROM bank_transfers
|
||
INNER JOIN transfers ON bank_transfers.transfer_id = transfers.id
|
||
WHERE transfers.member_id = ?
|
||
", intval($member_id));
|
||
}
|
||
|
||
}
|
application/models/preprocessor.php | ||
---|---|---|
", $user_id)->current()->count > 0;
|
||
}
|
||
|
||
/**
|
||
* Gets count of former members that can be deleted.
|
||
*
|
||
* constant 15 equals Member_Model::TYPE_FORMER - memory consumption hack
|
||
*
|
||
* @param integer $limit_years former member limit years
|
||
* @return integer
|
||
*/
|
||
public function count_of_former_members_to_delete($limit_years)
|
||
{
|
||
$time_Xyears_before = strtotime('-' . intval($limit_years) . ' years');
|
||
$date_Xyears_before = date('Y-m-d', $time_Xyears_before);
|
||
return $this->db->query("
|
||
SELECT COUNT(m.id) AS count
|
||
FROM members m
|
||
WHERE m.type = ? && m.leaving_date <= ?
|
||
", 15, $date_Xyears_before)->current()->count;
|
||
}
|
||
|
||
/**
|
||
* Returns count of all unread inbox messages of user
|
||
*
|
application/views/transfers/show_by_account.php | ||
---|---|---|
</tr>
|
||
<tr>
|
||
<th><?php echo __('Owner of account')?></th>
|
||
<td><?php echo html::anchor('members/show/'.$account->member_id, $account->member->name) ?></td>
|
||
<td><?php if ($account->member_id) { echo html::anchor('members/show/'.$account->member_id, $account->member->name); } ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo __('Type of double-entry account')?></th>
|
db_upgrades/upgrade_1.1.22.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is released under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Alters foreign keys in order to allow member delete. Names of foreign keys is
|
||
* not fixed (auto-creation) thus for some deployments this can cause some
|
||
* failures.
|
||
*
|
||
* @author Ondřej Fibich <ondrej.fibich@gmail.com>
|
||
*/
|
||
$upgrade_sql['1.1.22'] = array
|
||
(
|
||
"ALTER TABLE watchers DROP FOREIGN KEY watchers_ibfk_1;",
|
||
"ALTER TABLE watchers ADD CONSTRAINT watchers_ibfk_1 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
|
||
|
||
"ALTER TABLE jobs DROP FOREIGN KEY jobs_ibfk_2;",
|
||
"ALTER TABLE jobs ADD CONSTRAINT jobs_ibfk_2 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
|
||
|
||
"ALTER TABLE job_reports DROP FOREIGN KEY job_reports_ibfk_1;",
|
||
"ALTER TABLE job_reports ADD CONSTRAINT job_reports_ibfk_1 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
|
||
|
||
"ALTER TABLE requests DROP FOREIGN KEY requests_ibfk_1;",
|
||
"ALTER TABLE requests ADD CONSTRAINT requests_ibfk_1 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
|
||
);
|
Také k dispozici: Unified diff
Fixes #1094: Allows to delete former member older than 5 years.