function add() { if (!logged_user()->isAdministrator()) { flash_error(lang("no access permissions")); ajx_current("empty"); return; } $billingCategory = new BillingCategory(); $billing_data = array_var($_POST, 'billing'); if (!is_array($billing_data)) { $billing_data = array('name' => '', 'description' => '', 'default_value' => 0, 'report_name' => ''); } else { $billingCategory = new BillingCategory(); $billingCategory->setFromAttributes($billing_data); try { DB::beginWork(); $billingCategory->save(); DB::commit(); flash_success(lang("success add billing category")); ajx_current("back"); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } } tpl_assign('billing', $billingCategory); tpl_assign('billing_data', $billing_data); }
function add() { if (!can_manage_billing(logged_user())) { flash_error(lang("no access permissions")); ajx_current("empty"); return; } $billingCategory = new BillingCategory(); $billing_data = array_var($_POST, 'billing'); if (!is_array($billing_data)) { // set layout for modal form if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); tpl_assign('modal', true); } $billing_data = array('name' => '', 'description' => '', 'default_value' => 0, 'report_name' => ''); } else { $billingCategory = new BillingCategory(); $billingCategory->setFromAttributes($billing_data); try { DB::beginWork(); $billingCategory->save(); DB::commit(); flash_success(lang("success add billing category")); if (array_var($_REQUEST, 'modal')) { evt_add("reload current panel"); } else { ajx_current("back"); } } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } } tpl_assign('billing', $billingCategory); tpl_assign('billing_data', $billing_data); }