diff options
Diffstat (limited to '')
-rw-r--r-- | frontend/payments/classes/class.UserNarocila.php | 229 |
1 files changed, 200 insertions, 29 deletions
diff --git a/frontend/payments/classes/class.UserNarocila.php b/frontend/payments/classes/class.UserNarocila.php index e831e33..cc562c2 100644 --- a/frontend/payments/classes/class.UserNarocila.php +++ b/frontend/payments/classes/class.UserNarocila.php @@ -32,6 +32,39 @@ class UserNarocila{ }
+ // Dobimo podatke zadnjega narocila za dolocenega uporabnika
+ public function getNarocilo($narocilo_id){
+ global $admin_type;
+
+ $return = array();
+
+ // Dobimo narocilo uporabnika
+ $sqlNarocilo = sisplet_query("SELECT un.*, up.name AS package_name, up.description AS package_description, up.price AS package_price
+ FROM user_access_narocilo un, user_access_paket up
+ WHERE un.id='".$narocilo_id."' AND un.package_id=up.id
+ ");
+
+ // Uporabnik nima se nobenega narocila
+ if(mysqli_num_rows($sqlNarocilo) == 0){
+ $return['id'] = '0';
+ }
+ else{
+ $row = mysqli_fetch_array($sqlNarocilo);
+ $return = $row;
+
+ // Cena
+ $cena = $this->getPrice($row['package_name'], $row['trajanje'], $row['discount'], $row['time']);
+
+ // Zavezanec iz tujine nima ddv-ja
+ if($this->isWithoutDDV($row['id']))
+ $return['koncna_cena'] = $cena['final_without_tax'];
+ else
+ $return['koncna_cena'] = $cena['final'];
+ }
+
+ return $return;
+ }
+
// Dobimo array narocil (vseh oz. za dolocenega uporabnika)
private function getNarocila($usr_id=0){
global $admin_type;
@@ -77,6 +110,30 @@ class UserNarocila{ return $narocila;
}
+ // Dobimo podatke zadnjega narocila za dolocenega uporabnika
+ public function getLastNarocilo($usr_id){
+ global $admin_type;
+
+ $return = array();
+
+ // Dobimo zadnje narocilo uporabnika
+ $sqlNarocilo = sisplet_query("SELECT un.*, up.name AS package_name, up.description AS package_description, up.price AS package_price
+ FROM user_access_narocilo un, user_access_paket up
+ WHERE un.usr_id='".$usr_id."' AND un.package_id=up.id
+ ORDER BY un.time DESC
+ ");
+
+ // Uporabnik nima se nobenega narocila
+ if(mysqli_num_rows($sqlNarocilo) == 0){
+ $return['id'] = '0';
+ }
+ else{
+ $return = mysqli_fetch_array($sqlNarocilo);
+ }
+
+ return $return;
+ }
+
// Izracunamo koncno ceno glede na paket, trajanje in popust (v eur)
public function getPrice($package_name, $trajanje, $discount=0, $time=''){
@@ -294,16 +351,71 @@ class UserNarocila{ $ua = UserAccess::getInstance($global_user_id);
$user_access = $ua->getAccess();
- // Ce ni polja v bazi oz je nastavljen paket na 1 ima osnovni paket
- if(!$user_access || $user_access['package_id'] == '1'){
- echo '<p>'.$lang['srv_narocila_current_package'].':</span> <span class="bold">1KA</span></p>';
+ $sqlA = sisplet_query("SELECT ua.time_activate, ua.time_expire, uap.id AS package_id, uap.name AS package_name
+ FROM user_access ua, user_access_paket uap
+ WHERE ua.usr_id='$global_user_id' AND uap.id=ua.package_id
+ ");
+ $rowA = mysqli_fetch_array($sqlA);
+
+ echo '<div id="user_info_segment_narocila">';
+
+ echo '<div class="user_info text">';
+ if(AppSettings::getInstance()->getSetting('app_settings-commercial_packages') === true){
+ echo '<div class="setting_holder">'.$lang['srv_access_package'].':</div>';
+ if($rowA['package_id'] == '2' || $rowA['package_id'] == '3'){
+ echo '<div class="setting_holder">'.$lang['srv_narocila_current_start'].':</div>';
+ echo '<div class="setting_holder">'.$lang['srv_narocila_current_expire'].':</div>';
+ }
+ }
+ echo '</div>';
+
+ echo '<div class="user_info data bold">';
+
+ // Trenutni paket funkcionalnosti
+
+ $drupal_url = ($lang['id'] == '2') ? $site_url.'d/en/' : $site_url.'d/';
+
+ // Ni nobenega paketa
+ if(mysqli_num_rows($sqlA) == 0){
+
+ $package_string = '<div class="setting_holder">'.$lang['paket_opis_1ka'].' ('.$lang['srv_access_package_free'].')</div>';
+ $package_string .= '<div class="setting_holder"><button class="medium yellow" type="button" onClick="window.location.href=\''.$drupal_url.''.$lang['srv_narocila_buyurl'].'\';">'.$lang['srv_narocila_buy'].'</button></div>';
}
- // Imamo aktiviran paket - izpisemo podatke
else{
- echo '<div class="data"><span class="setting_title">'.$lang['srv_narocila_current_package'].':</span> <span class="bold">'.$user_access['package_name'],'</span></div>';
- echo '<div class="data"><span class="setting_title">'.$lang['srv_narocila_current_start'].':</span> <span class="bold">'.date( 'd.m.Y', strtotime($user_access['time_activate'])).'</span></div>';
- echo '<div class="data"><span class="setting_title">'.$lang['srv_narocila_current_expire'].':</span> <span class="bold">'.date( 'd.m.Y', strtotime($user_access['time_expire'])),'</span></div>';
+
+ $userAccess = UserAccess::getInstance($global_user_id);
+ $package_name = $userAccess->getPackageName($rowA['package_id']);
+
+ // Ce ima paket 2 ali 3
+ if($rowA['package_id'] == '2' || $rowA['package_id'] == '3'){
+
+ // Ce je paket ze potekel
+ if(strtotime($rowA['time_expire']) < time()){
+
+ $package_string = '<div class="setting_holder">'.$package_name.'</div>';
+ $package_string .= '<div class="setting_holder">'.date("d.m.Y", strtotime($rowA['time_activate'])).'</div>';
+ $package_string .= '<div class="setting_holder">'.$lang['srv_access_package_expire'].' '.date("d.m.Y", strtotime($rowA['time_expire'])).'</div>';
+
+ $package_string .= '<div class="setting_holder"><button class="medium yellow" type="button" onClick="window.location.href=\''.$drupal_url.'izvedi-nakup/'.$rowA['package_id'].'/podatki/\';">'.$lang['srv_narocila_extend'].'</button></div>';
+ }
+ else{
+ $package_string = '<div class="setting_holder">'.$package_name.'</div>';
+ $package_string .= '<div class="setting_holder">'.date("d.m.Y", strtotime($rowA['time_activate'])).'</div>';
+ $package_string .= '<div class="setting_holder">'.date("d.m.Y", strtotime($rowA['time_expire'])).'</div>';
+
+ $package_string .= '<div class="setting_holder"><button class="medium yellow" type="button" onClick="window.location.href=\''.$drupal_url.'izvedi-nakup/'.$rowA['package_id'].'/podatki/\';">'.$lang['srv_narocila_extend'].'</button></div>';
+ }
+ }
+ else{
+ $package_string = '<div class="setting_holder">'.$package_name.' ('.$lang['srv_access_package_free'].')</div>';
+ $package_string .= '<div class="setting_holder"><button class="medium yellow" type="button" onClick="window.location.href=\''.$drupal_url.''.$lang['srv_narocila_buyurl'].'\';">'.$lang['srv_narocila_buy'].'</button></div>';
+ }
}
+ echo $package_string;
+
+ echo '</div>';
+
+ echo '</div>';
echo '</fieldset>';
@@ -337,37 +449,55 @@ class UserNarocila{ echo ' <thead>';
echo ' <tr>';
- echo ' <th>'.$lang['srv_narocilo_paket'].'</th>';
- echo ' <th>'.$lang['srv_narocilo_trajanje'].' ('.$lang['srv_narocilo_trajanje_mesecev'].')</th>';
echo ' <th>'.$lang['srv_narocilo_cas'].'</th>';
- echo ' <th>'.$lang['srv_narocilo_nacin_placila'].'</th>';
- echo ' <th>'.$lang['srv_narocilo_cena'].'</th>';
+ echo ' <th>'.$lang['srv_narocilo_paket'].'</th>';
+ echo ' <th>'.$lang['srv_narocilo_veljavnodo'].'</th>';
+ echo ' <th>'.$lang['srv_narocilo_samo_cena'].'</th>';
echo ' <th>'.$lang['srv_narocilo_status'].'</th>';
- echo ' <th>'.$lang['srv_narocilo_pdf'].'</th>';
-
+ echo ' <th class="center">'.$lang['srv_narocilo_pdf_predracun'].'</th>';
+ echo ' <th class="center">'.$lang['srv_narocilo_pdf_racun'].'</th>';
echo ' </tr>';
echo ' </thead>';
// Vsebina tabele
echo ' <tbody>';
+ $userAccess = UserAccess::getInstance($global_user_id);
+
foreach($data as $usr_id => $data_row){
+ $package_name = $userAccess->getPackageName($data_row['package_id']);
+
echo '<tr>';
- echo '<td>'.$data_row['package_name'].'</td>';
- echo '<td>'.$data_row['trajanje'].'</td>';
echo '<td>'.date("j.n.Y H:i", strtotime($data_row['time'])).'</td>';
- echo '<td>'.$data_row['payment_method'].'</td>';
+
+ //Sklanjanje za število mesecev
+ if ($data_row['trajanje'] == 1)
+ $trajanje = $data_row['trajanje'] .' '. $lang['srv_narocilo_trajanje_1'];
+ else if ($data_row['trajanje'] == 2)
+ $trajanje = $data_row['trajanje'] .' '. $lang['srv_narocilo_trajanje_2'];
+ else if ($data_row['trajanje'] == 3 || $data_row['trajanje'] == 4)
+ $trajanje = $data_row['trajanje'] .' '. $lang['srv_narocilo_trajanje_3_4'];
+ else
+ $trajanje = $data_row['trajanje'] .' '. $lang['srv_narocilo_trajanje_5'];
+
+ echo '<td>'.$package_name.' ('.$trajanje.')</td>';
+
+ //Veljavnost paketa
+ $meseci = $data_row['trajanje'];
+ $veljaven_do = date("j.n.Y H:i", strtotime("+$meseci months", strtotime($data_row['time'])));
+
+ echo '<td>'.$veljaven_do.'</td>';
// Cena
$cena = $this->getPrice($data_row['package_name'], $data_row['trajanje'], $data_row['discount'], $data_row['time']);
// Zavezanec iz tujine nima ddv-ja
if($this->isWithoutDDV($data_row['id']))
- echo '<td>'.$cena['final_without_tax'].'</td>';
+ echo '<td>'.$cena['final_without_tax'].'€</td>';
else
- echo '<td>'.$cena['final'].'</td>';
+ echo '<td>'.$cena['final'].'€</td>';
if($data_row['status'] == '0')
$status_color = 'red';
@@ -378,12 +508,13 @@ class UserNarocila{ echo '<td class="'.$status_color.'">'.$lang['srv_narocilo_status_'.$data_row['status']].'</td>';
// PDF
- echo '<td>';
- echo '<span class="pointer as_link" onClick="getNarociloPredracun(\''.$data_row['id'].'\')">'.$lang['srv_narocilo_pdf_predracun'].'</span>';
+ echo '<td class="center"><span class="faicon pdf empty red pointer" onClick="getNarociloPredracun(\''.$data_row['id'].'\')"></span></td>';
+
if($data_row['status'] == '1'){
- echo ' | <span class="pointer as_link" onClick="getNarociloRacun(\''.$data_row['id'].'\')">'.$lang['srv_narocilo_pdf_racun'].'</span>';
+ echo '<td class="center"><span class="faicon pdf empty red pointer" onClick="getNarociloRacun(\''.$data_row['id'].'\')"></span></td>';
}
- echo '</td>';
+ else
+ echo '<td></td>';
echo '</tr>';
}
@@ -395,16 +526,16 @@ class UserNarocila{ // Izpisemo seznam vseh narocil - admin
public function displayNarocilaTableAdmin(){
- global $lang, $global_user_id, $app_settings;
+ global $lang, $global_user_id;
// Admini vidijo vsa narocila
$data = $this->getNarocila();
// Filtri po statusu
echo '<div class="narocila_filters">';
- echo '<label for="filter_narocila_0"><input type="checkbox" id="filter_narocila_0" '.($this->narocila_filter['neplacana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'0\', this.checked)">'.$lang['srv_narocilo_filter_status_0'].'</label>';
- echo '<label for="filter_narocila_1"><input type="checkbox" id="filter_narocila_1" '.($this->narocila_filter['placana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'1\', this.checked)">'.$lang['srv_narocilo_filter_status_1'].'</label>';
- echo '<label for="filter_narocila_2"><input type="checkbox" id="filter_narocila_2" '.($this->narocila_filter['stornirana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'2\', this.checked)">'.$lang['srv_narocilo_filter_status_2'].'</label>';
+ echo ' <input type="checkbox" id="filter_narocila_0" '.($this->narocila_filter['neplacana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'0\', this.checked)"><label for="filter_narocila_0">'.$lang['srv_narocilo_filter_status_0'].'</label>';
+ echo ' <input type="checkbox" id="filter_narocila_1" '.($this->narocila_filter['placana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'1\', this.checked)"><label for="filter_narocila_1">'.$lang['srv_narocilo_filter_status_1'].'</label>';
+ echo ' <input type="checkbox" id="filter_narocila_2" '.($this->narocila_filter['stornirana'] == 1 ? 'checked="checked"' : '').' onClick="filterNarocila(\'2\', this.checked)"><label for="filter_narocila_2">'.$lang['srv_narocilo_filter_status_2'].'</label>';
echo '</div>';
echo '<table id="user_narocila" class="dataTable user_narocila_admin" style="width:100%">';
@@ -468,7 +599,7 @@ class UserNarocila{ echo $lang['srv_narocilo_status_'.$data_row['status']];
// Na www.1ka.si lahko narocilo placa samo Goran
- if($data_row['status'] != '1' && $data_row['status'] != '2' && ($app_settings['app_name'] != 'www.1ka.si' || $global_user_id == '112696')){
+ if($data_row['status'] != '1' && $data_row['status'] != '2' && (AppSettings::getInstance()->getSetting('app_settings-app_name') != 'www.1ka.si' || $global_user_id == '112696')){
echo '<br />';
echo '<span class="as_link" onClick="urediNarociloPay(\''.$data_row['id'].'\')">'.$lang['srv_narocilo_placaj'].'</span>';
@@ -761,6 +892,10 @@ class UserNarocila{ return $response;
}
+
+ // Ce je slucajno drzava prazna jo nastavimo na slovenijo - zankrat pustimo, da vidimo, ce se se kdaj poslje prazno polje (naceloma se nebi smelo)
+ /*if($podjetje_drzava == '')
+ $podjetje_drzava = 'Slovenija';*/
// Nastavimo ce placa DDV (zavezanci iz EU ga ne placajo)
if(self::checkPayDDV($podjetje_davcna, $podjetje_drzava))
@@ -1112,8 +1247,27 @@ class UserNarocila{ // Ustvarimo racun
- $cebelica = new UserNarocilaCebelica($narocilo_id);
- $response['racun'] = $cebelica->getNarociloRacun();
+ try{
+ $cebelica = new UserNarocilaCebelica($narocilo_id);
+ $response['racun'] = $cebelica->getNarociloRacun();
+ }
+ // Napaka pri komunikaciji s cebelco - posljemo mail Goranu
+ catch (Exception $e){
+
+ // Posljemo mail Goranu, da je prislo do napake pri generiranju racuna
+ $subject = '1ka - napaka pri generiranju računa';
+ $content = 'Prišlo je do napake pri generiranju računa (komunikacija s čebelco) pri naročilu št. '.$rowNarocilo['id'].' (uporabnik '.$rowNarocilo['email'].')!';
+ $content .= '<br /><br />Preveri in samo še enkrat odpri račun za to plačilo preko vmesnika (ga bo zgeneriralo avtomatsko).';
+
+ $MA = new MailAdapter($anketa=null, $type='payments');
+ $MA->addRecipients('goran@go-tel.si');
+ $MA->addRecipients('peter@1ka.si');
+ $resultX = $MA->sendMail($content, $subject);
+
+ $response['false'] = true;
+
+ return $response;
+ }
// Posljemo mail z racunom
@@ -1314,6 +1468,22 @@ class UserNarocila{ // Lastna instalacija - paket
$strinjanje_s_pogoji = isset($narocilo_data['strinjanje_s_pogoji']) ? $narocilo_data['strinjanje_s_pogoji'] : '';
+ // Varnostno preverimo, če robot izpolni polje
+ $varnostno_polje = isset($narocilo_data['varnostno-polje']) ? $narocilo_data['varnostno-polje'] : '';
+ if(!empty($varnostno_polje)){
+ return ['false' => true];
+ }
+
+ // Preverimo ReCaptcha
+ if (in_array($paket, [1,2,3]) && AppSettings::getInstance()->getSetting('google-secret_captcha') !== false) {
+ $recaptchaResponse = isset($narocilo_data['g-recaptcha-response']) ? $narocilo_data['g-recaptcha-response'] : '';
+ $requestReCaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . AppSettings::getInstance()->getSetting('google-secret_captcha') . '&response=' . $recaptchaResponse);
+
+ if (!strstr($requestReCaptcha, 'true')) {
+ return ['false' => true];
+ }
+ }
+
// Posljemo mail s podatki povprasevanja
$subject = $lang['srv_narocilo_poslovni_email_1ka_subject'];
@@ -1414,6 +1584,7 @@ class UserNarocila{ $countries_eu['Bulgaria'] = 'BG';
$countries_eu['Cyprus'] = 'CY';
$countries_eu['Czech Republic'] = 'CZ';
+ $countries_eu['Czechia'] = 'CZ';
$countries_eu['Germany'] = 'DE';
$countries_eu['Denmark'] = 'DK';
$countries_eu['Estonia'] = 'EE';
|