Skip to content

Commit e13e52f

Browse files
committed
added conditional user active?
1 parent cc3588a commit e13e52f

File tree

1 file changed

+76
-61
lines changed

1 file changed

+76
-61
lines changed

cweb/elcurrencyweb/controllers/Currency_Manager.php

Lines changed: 76 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function listcurrencies()
4444
{
4545
// load user preferences, lib must be init after loading
4646
$this->load->library('Userlib');
47-
$this->userlib->initialize('gonzalez_angel');
47+
// $this->userlib->initialize('gonzalez_angel');
48+
$this->userlib->initialize('lenz_gerardo');
49+
4850
$this->userlib->getID();
4951
$this->load->model('Currency_m','dbcm');
5052
$user_preferences = $this->userlib->getUser();
@@ -54,19 +56,26 @@ public function listcurrencies()
5456
$currency_list_dbarraynow = array();
5557
$currency_list_dbarraypre = array();
5658
// ver si id y status es valido ejemplo $this->userlib->isActive(); solo edita si esta activo
57-
$currency_list_dbarraypre = $this->dbcm->readCurrenciesTodayStored($cur_monedas_base,NULL,$cur_monedas_dest);
59+
$data['active'] = $active = $this->userlib->isActive();
5860
$currency_list_dbarraynow = $this->dbcm->readCurrenciesTodayStored();
61+
if($active){
62+
$currency_list_dbarraypre = $this->dbcm->readCurrenciesTodayStored($cur_monedas_dest,NULL,$cur_monedas_base);
63+
}
5964
$data['user_preferences'] = $user_preferences;
6065
$data['currency_list_dbarraynow'] = $currency_list_dbarraynow;
6166
$data['currency_list_dbarraypre'] = $currency_list_dbarraypre;
6267
$data['currenturl'] = $this->currenturl;
6368

6469
$this->load->view('header.php',$data);
65-
$this->load->view('menu');
70+
$this->load->view('menu',$data);
6671
$this->load->view('currency.php',$data);
6772
}
6873

6974
public function updatecurrency(){
75+
$this->load->library('Userlib');
76+
$this->userlib->initialize('lenz_gerardo');
77+
78+
7079
$this->load->model('Currency_m','dbcm');
7180
$this->load->library('form_validation');
7281
$mon_tasa_moneda = $this->input->post('mon_tasa_moneda', FALSE);
@@ -100,8 +109,10 @@ public function updatecurrency(){
100109
return $error = 0;
101110
}
102111

112+
if($this->userlib->isActive()){
113+
$result = $this->dbcm->updateCurrencyMount($cod_tasa, $mon_tasa_moneda);
114+
}
103115

104-
$result = $this->dbcm->updateCurrencyMount($cod_tasa, $mon_tasa_moneda);
105116
log_message('error', __METHOD__ .' POST : ' . print_r($result, TRUE) . ' why: '.print_r("Ocurrio un error al guardar", TRUE));
106117

107118
echo json_encode(array('result' =>$result));
@@ -117,69 +128,73 @@ public function updatecurrency(){
117128
public function callapitodb($codkey = NULL)
118129
{
119130
$this->load->model('Usuario_m','users');
131+
$this->load->library('Userlib');
132+
$this->userlib->initialize('lenz_gerardo');
133+
134+
if($this->userlib->isActive()){
120135

121-
122-
log_message('info', __METHOD__ .' calltoapi codkey argument method '.print_r($codkey, TRUE));
123-
if($codkey == NULL)
124-
{
125-
log_message('error', __METHOD__ .' missing codkey, checking POST');
126-
$codkey = $this->input->get_post('codkey', FALSE);
127-
if( is_null($codkey) OR empty($codkey) )
128-
return json_encode(array('result'=>'unauthorized access'));
129-
}
130-
$this->load->config('currencyweb');
131-
$codkeyconf = $this->config->item('codkey');
132-
if( $codkey == $codkeyconf)
133-
log_message('error', __METHOD__ .' invalid codkey ' .print_r($codkey,TRUE). ' from config: '.print_r($codkeyconf, TRUE));
134-
135-
$config['language'] = 'spanish';
136-
$data = array();
137-
// example invokation http://localhost/~general/codeigniter-currencylib/cweb/index.php/Currency_Manager/callapitodb/SHAR265ql-23krjhnou2q34rhi2?dateapi=2023-02-03&curbase=USD
138-
// example shot base "index.php/Currency_Manager/callapitodb/SHAR265ql-23krjhnou2q34rhi2?dateapi=2023-02-03&curbase=USD"
139-
$currencyDate = $this->input->get_post('dateapi', FALSE);
140-
$currencyBase = $this->input->get_post('curbase', FALSE);
141-
$currencyDest = $this->input->get_post('curdest', FALSE);
142-
143-
$this->load->library('form_validation');
144-
$missdest = $this->form_validation->required($currencyDest);
145-
$validcurren = $this->form_validation->min_length($currencyDest,3);
146-
$missdate = $this->form_validation->required($currencyDate);
147-
$validfields = $this->form_validation->exact_length($currencyDate,10);
148-
$missbase = $this->form_validation->required($currencyBase);
149-
$validfields = $this->form_validation->exact_length($currencyBase,3);
150-
if($missdate == FALSE)
151-
$currencyDate = date('Y-m-d');
152-
if($missbase == FALSE)
153-
$currencyBase = 'USD';
154-
if($validfields == FALSE)
155-
$currencyBase = 'USD';
156-
if($validcurren == FALSE OR $missdest == FALSE)
157-
{
158-
log_message('info', __METHOD__ .' missing currency rates to convert, we will use all availables from api results ');
159-
$currencyDest = NULL;
160-
}
161-
if(mb_strlen($currencyDest) > 3)
162-
{
163-
if(stripos($currencyDest,',') == FALSE)
136+
log_message('info', __METHOD__ .' calltoapi codkey argument method '.print_r($codkey, TRUE));
137+
if($codkey == NULL)
164138
{
165-
log_message('error', __METHOD__ .' invalid currency set, more than one but missing separator, we will use all');
139+
log_message('error', __METHOD__ .' missing codkey, checking POST');
140+
$codkey = $this->input->get_post('codkey', FALSE);
141+
if( is_null($codkey) OR empty($codkey) )
142+
return json_encode(array('result'=>'unauthorized access'));
143+
}
144+
$this->load->config('currencyweb');
145+
$codkeyconf = $this->config->item('codkey');
146+
if( $codkey == $codkeyconf)
147+
log_message('error', __METHOD__ .' invalid codkey ' .print_r($codkey,TRUE). ' from config: '.print_r($codkeyconf, TRUE));
148+
149+
$config['language'] = 'spanish';
150+
$data = array();
151+
// example invokation http://localhost/~general/codeigniter-currencylib/cweb/index.php/Currency_Manager/callapitodb/SHAR265ql-23krjhnou2q34rhi2?dateapi=2023-02-03&curbase=USD
152+
// example shot base "index.php/Currency_Manager/callapitodb/SHAR265ql-23krjhnou2q34rhi2?dateapi=2023-02-03&curbase=USD"
153+
$currencyDate = $this->input->get_post('dateapi', FALSE);
154+
$currencyBase = $this->input->get_post('curbase', FALSE);
155+
$currencyDest = $this->input->get_post('curdest', FALSE);
156+
157+
$this->load->library('form_validation');
158+
$missdest = $this->form_validation->required($currencyDest);
159+
$validcurren = $this->form_validation->min_length($currencyDest,3);
160+
$missdate = $this->form_validation->required($currencyDate);
161+
$validfields = $this->form_validation->exact_length($currencyDate,10);
162+
$missbase = $this->form_validation->required($currencyBase);
163+
$validfields = $this->form_validation->exact_length($currencyBase,3);
164+
if($missdate == FALSE)
165+
$currencyDate = date('Y-m-d');
166+
if($missbase == FALSE)
167+
$currencyBase = 'USD';
168+
if($validfields == FALSE)
169+
$currencyBase = 'USD';
170+
if($validcurren == FALSE OR $missdest == FALSE)
171+
{
172+
log_message('info', __METHOD__ .' missing currency rates to convert, we will use all availables from api results ');
166173
$currencyDest = NULL;
167174
}
168-
}
175+
if(mb_strlen($currencyDest) > 3)
176+
{
177+
if(stripos($currencyDest,',') == FALSE)
178+
{
179+
log_message('error', __METHOD__ .' invalid currency set, more than one but missing separator, we will use all');
180+
$currencyDest = NULL;
181+
}
182+
}
169183

170184

171-
log_message('debug', __METHOD__ .' getting the data from internet API for : '.print_r($currencyDate, TRUE));
172-
$currency_list_apiarray = array();
173-
$this->load->library('Currencylib');
174-
$currencyDate = date('Y-m-d',strtotime($currencyDate));
175-
$currency_list_apiarray = $this->currencylib->getAllCurrencyByApi($currencyBase,$currencyDest,$currencyDate);
176-
log_message('debug', __METHOD__ .' API already called, now try to store the result into DB for : '.print_r($currencyDate, TRUE));
177-
$this->load->model('Currency_m','dbcm');
178-
$currencyDate = date('Ymd',strtotime($currencyDate)).date('H');
179-
$createdbresult = $this->dbcm->createCurrencyFromApi($currency_list_apiarray, $currencyDate, $currencyBase);
180-
log_message('debug', __METHOD__ .' saved? : ' .print_r($createdbresult,TRUE). ' from parameter: '.print_r($currencyDate, TRUE));
181-
return json_encode(array('result'=>$createdbresult));
182-
// }
185+
log_message('debug', __METHOD__ .' getting the data from internet API for : '.print_r($currencyDate, TRUE));
186+
$currency_list_apiarray = array();
187+
$this->load->library('Currencylib');
188+
$currencyDate = date('Y-m-d',strtotime($currencyDate));
189+
$currency_list_apiarray = $this->currencylib->getAllCurrencyByApi($currencyBase,$currencyDest,$currencyDate);
190+
log_message('debug', __METHOD__ .' API already called, now try to store the result into DB for : '.print_r($currencyDate, TRUE));
191+
$this->load->model('Currency_m','dbcm');
192+
$currencyDate = date('Ymd',strtotime($currencyDate)).date('H');
193+
$createdbresult = $this->dbcm->createCurrencyFromApi($currency_list_apiarray, $currencyDate, $currencyBase);
194+
log_message('debug', __METHOD__ .' saved? : ' .print_r($createdbresult,TRUE). ' from parameter: '.print_r($currencyDate, TRUE));
195+
return json_encode(array('result'=>$createdbresult));
196+
}
197+
log_message('debug', __METHOD__ .' saved? : ' .' Not authorized ');
183198

184199

185200
}

0 commit comments

Comments
 (0)