-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountsEdit.php
78 lines (61 loc) · 2.48 KB
/
accountsEdit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* $Id$
*
* @author Claudio Corlatti
*/
require 'library/bootstrap/prepend.php';
IncludeHelper::inc('library/util/SecurityCheck.class.php');
IncludeHelper::inc('library/session/accounting/AccountManagment.class.php');
$tpl = new CCTemplate('static/');
$tpl->cInit('accountsEdit.html');
try {
SecurityCheck::checkSession();
$tpl->cSet('USER_NAME', $_SESSION['user']['name']);
//request parameters
$idAccount = SecurityCheck::sanitize($_GET['idAccount']);
$action = SecurityCheck::sanitize($_GET['action']);
$am = new AccountManagment();
//am i editing?
$tpl->cSet('ID_ACCOUNT', $idAccount);
if(!empty($idAccount)){
//check permission
$idUser = $_SESSION['user']['id'];
$permission = empty($idAccount) ? true : $am->doIHavePermissionForThisAccount($idAccount, $idUser);
if(!$permission){
throw new Exception('Ups! no tenes permiso para operar sobre esta cuenta.');
}
$tpl->cParse('OPT_DELETE_BUTTON');
$tpl->cParse('OPT_DELETE_BUTTON_FOOTER');
$account = $am->getAccountById($idAccount);
$tpl->cSet('ACCOUNT_DESCRIPTION', $account['description']);
$tpl->cSet('BANK_SELECTED', $account['idBank']);
}
//account types
$accountTypes = $am->getAccountTypes($idAccount);
foreach($accountTypes as $accountType){
$tpl->cSet('ACCOUNT_TYPE_ID',$accountType['id']);
$tpl->cSet('ACCOUNT_TYPE_DESCRIPTION',$accountType['description']);
$tpl->cSet('ACCOUNT_TYPE_SELECTED', count($accountType['Account']) > 0 ? 'selected' : '');
$tpl->cSet('REQUIRE_BANK', $accountType['bankRequired'] == 1 ? 'bankRequired' : 'bankOptional');
$tpl->cParse('ROW_ACCOUNT_TYPE');
}
//available currencies
$currencies = $am->getCurrencies($idAccount);
foreach($currencies as $currency){
$tpl->cSet('ACCOUNT_CURRENCY_ID',$currency['id']);
$tpl->cSet('ACCOUNT_CURRENCY_DESCRIPTION',$currency['description'] . ' (' . $currency['symbol'] . ')');
$tpl->cSet('ACCOUNT_CURRENCY_SELECTED', count($currency['Account']) > 0 ? 'selected' : '');
$tpl->cParse('ROW_ACCOUNT_CURRENCY');
}
//country
$tpl->cSet('MY_COUNTRY_ISO',$_SESSION['user']['Userdata'][0]['Country']['iso2']);
$tpl->cSet('MY_COUNTRY_ID',$_SESSION['user']['Userdata'][0]['Country']['country_id']);
$tpl->cSet('MY_COUNTRY_DESCRIPTION',$_SESSION['user']['Userdata'][0]['Country']['short_name']);
$tpl->cParse('OPT_FORM');
} catch (Exception $e){
$tpl->cSet('ERROR', $e->getMessage());
$tpl->cParse('OPT_ERROR');
}
$tpl->cPrint();
?>