Advertisement
Guest User

pck_apex_demo AUTH

a guest
Oct 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. create or replace package pck_apex_demo as
  2.  
  3. --
  4. procedure print_html_region;
  5.  
  6. --
  7. function user_is_admin(p_username in varchar2)
  8. return boolean;
  9.  
  10. --
  11. function get_broj_racuna return varchar2;
  12.  
  13. --
  14. procedure parse_csv(p_name in apex_application_temp_files.name%type);
  15.  
  16. --
  17. function custom_app_auth (
  18. p_username in varchar2
  19. ,p_password in varchar2
  20. ) return boolean;
  21.  
  22. end pck_apex_demo;
  23. /
  24.  
  25.  
  26.  
  27.  
  28.  
  29. create or replace package body pck_apex_demo as
  30.  
  31. --
  32. procedure print_html_region is
  33. begin
  34. htp.p('<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>');
  35. end print_html_region;
  36.  
  37. --
  38. function user_is_admin(p_username in varchar2)
  39. return boolean is
  40. begin
  41. if p_username = 'USER_ADMIN' then
  42. return true;
  43. else
  44. return false;
  45. end if;
  46. end user_is_admin;
  47. --
  48. function get_broj_racuna return varchar2 is
  49. v_count pls_integer;
  50. begin
  51. select count(*)
  52. into v_count
  53. from racun;
  54.  
  55. return lpad(v_count+1, 5, '0')||'-'||to_char(sysdate, 'rrrr');
  56. end get_broj_racuna;
  57.  
  58. --
  59. procedure parse_csv(p_name in apex_application_temp_files.name%type) is
  60. v_blob_data apex_application_temp_files.blob_content%type;
  61. v_wwv_id wwv_flow_files.id%type;
  62. v_blob_len number;
  63. v_position number;
  64. v_raw_chunk raw(10000);
  65. v_char varchar2(50);
  66. c_chunk_len number := 1;
  67. v_line varchar2(32767) := null;
  68. v_data_array wwv_flow_global.vc_arr2;
  69. v_sr_no number := 1;
  70. v_string varchar2(2000);
  71. v_index number;
  72. v_exit number;
  73. ex_no_csv exception;
  74. ex_wrong_param exception;
  75. v_rownum number;
  76. v_datum date;
  77. v_interna_oznaka number(10);
  78. v_br_sati_rada number(3);
  79. v_number15_2 number(15, 2);
  80. v_odaa_faktor varchar2(2000);
  81. v_data_type_num number(1);
  82. v_param_errm varchar2(4000);
  83.  
  84.  
  85. -------------------------------------------------------------------------------------------
  86. -- uklanja novi redak, tab, radi trim
  87. function f_remove_special_chars(p_in varchar2) return varchar2 is
  88. v_ret varchar2(30000);
  89. begin
  90. v_ret := replace(trim(replace(replace(replace(p_in, chr(10), ' '), chr(13), ' ')
  91. ,chr(9)
  92. ,' '))
  93. ,'.'
  94. ,'');
  95. return v_ret;
  96. end;
  97.  
  98. -----------------------------------------------------------------------------------
  99. -- funkcija konvertira hex vrijednosti u decimalne
  100. function hex_to_decimal(p_hex_str in varchar2) return number is
  101. v_dec number;
  102. v_hex varchar2(16) := '0123456789ABCDEF';
  103. begin
  104. v_dec := 0;
  105. for indx in 1 .. length(p_hex_str)
  106. loop
  107. v_dec := v_dec * 16 + instr(v_hex, upper(substr(p_hex_str, indx, 1))) - 1;
  108. end loop;
  109. return v_dec;
  110. end hex_to_decimal;
  111. ---------------------------------------------------------------------------
  112. -- funkcija konvertira decimalnu vrijednost column indexa u ascii vrijednost
  113. function convert_colnum_to_letter(p_colnum number) return varchar2 is
  114. begin
  115. if p_colnum > 26 then
  116. return CHR(trunc((p_colnum - 1) / 26) + 64) || CHR(((p_colnum - 1) mod 26) + 65);
  117. else
  118. return CHR(p_colnum + 64);
  119. end if;
  120. end convert_colnum_to_letter;
  121.  
  122.  
  123. begin
  124. if p_name is null then
  125. raise ex_no_csv;
  126. end if;
  127. delete from tmp_import;
  128.  
  129. delete from apex_application_temp_files f where upper(f.name) != upper(p_name);
  130.  
  131. -- Read data from wwv_flow_files
  132. select f.blob_content, f.id
  133. into v_blob_data, v_wwv_id
  134. from apex_application_temp_files f
  135. where upper(f.name) = upper(p_name);
  136.  
  137. v_blob_len := dbms_lob.getlength(v_blob_data);
  138. v_position := 1;
  139. -- Read and convert binary to char
  140. while (v_position <= v_blob_len)
  141. loop
  142. v_raw_chunk := dbms_lob.substr(v_blob_data, c_chunk_len, v_position);
  143. v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
  144. v_line := v_line || v_char;
  145. v_position := v_position + c_chunk_len;
  146. v_index := 1;
  147. -- When a whole line is retrieved
  148. if v_char = chr(10) or v_position > v_blob_len then
  149. -- Convert each column separated by ; into array of data
  150. for i in (select substr(str
  151. ,instr(str, ';', 1, level) + 1
  152. ,instr(str, ';', 1, level + 1) -
  153. instr(str, ';', 1, level) - 1) element
  154. from (select ';' || v_line || ';' str from dual)
  155. connect by level <= length(str) - length(replace(str, ';')) - 1)
  156.  
  157. loop
  158. if v_index = 2 and i.element is null then
  159. -- ako je kolona sa siframa prazna
  160. v_exit := 1;
  161. end if;
  162. exit when v_exit = 1;
  163. v_exit := 0;
  164. v_data_array(v_index) := i.element;
  165. v_index := v_index + 1;
  166.  
  167. end loop;
  168. if v_exit = 0 then
  169. v_string := 'insert into tmp_import (id, ';
  170. for i in 1 .. v_data_array.count
  171. loop
  172. v_string := v_string || 'COL' || i || ',';
  173. end loop;
  174.  
  175. v_string := substr(v_string, 1, length(v_string) - 1) ||
  176. ') values (zaposlenik_seq.nextval,';
  177.  
  178. for j in 1 .. v_data_array.count
  179. loop
  180. v_string := v_string || chr(39) || f_remove_special_chars(v_data_array(j)) || chr(39) || ',';
  181. end loop;
  182. v_string := substr(v_string, 1, length(v_string) - 1) || ')';
  183. execute immediate (v_string);
  184. end if;
  185.  
  186. v_line := null;
  187. v_sr_no := v_sr_no + 1;
  188. end if;
  189. end loop;
  190.  
  191. end parse_csv;
  192.  
  193. --
  194. function custom_app_auth (
  195. p_username in varchar2
  196. ,p_password in varchar2
  197. ) return boolean is
  198. v_ret boolean := false;
  199. v_count pls_integer := 0;
  200. begin
  201. begin
  202. if p_username is not null and p_password is not null then
  203. select count(*)
  204. into v_count
  205. from my_app_users
  206. where upper(username) = p_username
  207. and password = p_password;
  208. end if;
  209.  
  210. v_ret := v_count > 0;
  211.  
  212. exception
  213. when others then
  214. v_ret := false;
  215. end;
  216.  
  217. return v_ret;
  218.  
  219. end custom_app_auth;
  220.  
  221. end pck_apex_demo;
  222. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement