admin_utils.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. <?php
  2. class admin_utils {
  3. // Bcrypt hash for an admin password.
  4. static function hashPassword($plain) {
  5. return password_hash($plain, PASSWORD_DEFAULT);
  6. }
  7. // Verify a plain password against a stored value.
  8. // Returns true on match. Handles legacy plaintext passwords:
  9. // if the stored value is not a recognised hash, it falls back to a
  10. // direct comparison so existing accounts keep working until rehashed.
  11. static function verifyPassword($plain, $stored) {
  12. $info = password_get_info($stored);
  13. if ($info['algo'] !== null && $info['algo'] !== 0) {
  14. return password_verify($plain, $stored);
  15. }
  16. // Legacy plaintext fallback.
  17. return hash_equals((string)$stored, (string)$plain);
  18. }
  19. // Whether a stored password value is still legacy plaintext and should
  20. // be upgraded to a proper hash after a successful login.
  21. static function passwordNeedsRehash($stored) {
  22. $info = password_get_info($stored);
  23. return ($info['algo'] === null || $info['algo'] === 0);
  24. }
  25. static function dbconnect() {
  26. global $config;
  27. global $conn;
  28. $conn = mysqli_connect($config['db_host'],$config['db_username'],$config['db_password'],$config['db_name']);
  29. mysqli_query($conn,"SET NAMES utf8");
  30. mysqli_set_charset($conn, 'utf8mb4');
  31. return true;
  32. }
  33. static function getText($id, $field) {
  34. self::dbconnect();
  35. global $conn;
  36. $res = mysqli_query($conn,"SELECT * FROM azonics_text_pages WHERE page_id='".$id."';");
  37. if (mysqli_num_rows($res)>0) {
  38. $row = mysqli_fetch_array($res);
  39. $text = $row[$field];
  40. $text = str_replace("<div>","",$text);
  41. $text = str_replace("</div>","",$text);
  42. $text = str_replace("<p>","",$text);
  43. $text = str_replace("</p>","",$text);
  44. $text = str_replace("<span>","",$text);
  45. $text = str_replace("</span>","",$text);
  46. return $text;
  47. }
  48. else {
  49. return 'No data available';
  50. }
  51. }
  52. static function getAdminName() {
  53. return $_SESSION['admin_user']->admin_real_name;
  54. }
  55. static function getAdminAccessLevels($selected='') {
  56. self::dbconnect();
  57. global $conn;
  58. $result = mysqli_query($conn,"select * from azonics_roles where role_status='1' order by role_name asc;");
  59. $temp = '<option value="">'.lang::_('Please select admin user access level...').'</option>';
  60. if (mysqli_num_rows($result)>0) {
  61. while ($row = mysqli_fetch_array($result)) {
  62. if ($_SESSION['access_level'] == 11) {
  63. if ($selected==$row['role_id']) {
  64. $temp.= '<option value="'.$row['role_id'].'" selected>'.$row['role_name'].'</option>';
  65. }
  66. else {
  67. $temp.= '<option value="'.$row['role_id'].'">'.$row['role_name'].'</option>';
  68. }
  69. }
  70. else if ($_SESSION['access_level'] == 13) {
  71. if ($row['role_id'] == 14) {
  72. $temp.= '<option value="'.$row['role_id'].'" selected>'.$row['role_name'].'</option>';
  73. }
  74. }
  75. }
  76. }
  77. else {
  78. $temp.= '<option value="">'.lang::_('Actually no active role group...').'</option>';
  79. }
  80. return $temp;
  81. }
  82. static function getUserTypes($selected='') {
  83. self::dbconnect();
  84. global $conn;
  85. $result = mysqli_query($conn,"select * from azonics_user_types where user_type_status='1' order by user_type_name asc;");
  86. $temp = '<option value="">'.lang::_('Please select user type...').'</option>';
  87. if (mysqli_num_rows($result)>0) {
  88. while ($row = mysqli_fetch_array($result)) {
  89. if ($selected==$row['user_type_id']) {
  90. $temp.= '<option value="'.$row['user_type_id'].'" selected>'.$row['user_type_name'].'</option>';
  91. }
  92. else {
  93. $temp.= '<option value="'.$row['user_type_id'].'">'.$row['user_type_name'].'</option>';
  94. }
  95. }
  96. }
  97. else {
  98. $temp.= '<option value="">'.lang::_('Actually no active user type...').'</option>';
  99. }
  100. return $temp;
  101. }
  102. static function getUserTypeName($type='') {
  103. self::dbconnect();
  104. global $conn;
  105. if ($type!='') {
  106. $result = mysqli_query($conn,"select * from azonics_user_types where user_type_id='".$type."';");
  107. if (mysqli_num_rows($result)>0) {
  108. $row = mysqli_fetch_array($result);
  109. return '<span class="'.$row['user_type_color'].'">'.$row['user_type_name'].'</span>';
  110. }
  111. else {
  112. return false;
  113. }
  114. }
  115. else {
  116. return false;
  117. }
  118. }
  119. static function getUserState($user_id='') {
  120. self::dbconnect();
  121. global $conn;
  122. if ($user_id!='') {
  123. $result = mysqli_query($conn,"select * from users where id='".$user_id."';");
  124. if (mysqli_num_rows($result)>0) {
  125. $row = mysqli_fetch_array($result);
  126. if ($row['status']=='1') {
  127. return ' checked';
  128. }
  129. else {
  130. return '';
  131. }
  132. }
  133. else {
  134. return '';
  135. }
  136. }
  137. else {
  138. return '';
  139. }
  140. }
  141. static function getUserName($user_id='') {
  142. self::dbconnect();
  143. global $conn;
  144. if ($user_id!='') {
  145. $result = mysqli_query($conn,"select * from azonics_users where user_id='".$user_id."';");
  146. if (mysqli_num_rows($result)>0) {
  147. $row = mysqli_fetch_array($result);
  148. return $row['user_first_name']." ".$row['user_last_name'];
  149. }
  150. else {
  151. return '';
  152. }
  153. }
  154. else {
  155. return '';
  156. }
  157. }
  158. static function getUserDefaultMailerState($user_id='') {
  159. self::dbconnect();
  160. global $conn;
  161. if ($user_id!='') {
  162. $result = mysqli_query($conn,"select * from azonics_users where user_id='".$user_id."';");
  163. if (mysqli_num_rows($result)>0) {
  164. $row = mysqli_fetch_array($result);
  165. if ($row['user_default_mailer_status']=='1') {
  166. return ' checked';
  167. }
  168. else {
  169. return '';
  170. }
  171. }
  172. else {
  173. return '';
  174. }
  175. }
  176. else {
  177. return '';
  178. }
  179. }
  180. static function checkAdminAccessToModule($module='') {
  181. self::dbconnect();
  182. global $conn;
  183. if ($module!='') {
  184. $result = mysqli_query($conn,"select * from azonics_modules_role where "
  185. . "modrole_role_id='".$_SESSION['admin_user']->admin_access_level."' and "
  186. . "modrole_module_id='".$module."' and "
  187. . "modrole_status='1';");
  188. if (mysqli_num_rows($result)>0) {
  189. return true;
  190. }
  191. else {
  192. return false;
  193. }
  194. }
  195. else {
  196. return false;
  197. }
  198. }
  199. static function getMenu($parent=0) {
  200. self::dbconnect();
  201. global $conn;
  202. $result = mysqli_query($conn,"select * from azonics_modules where module_status='1' and module_display_parent='".$parent."' order by display_order asc;") or die(mysql_error());
  203. $resultObjects = null;
  204. if (mysqli_num_rows($result)>0) {
  205. while($row = mysqli_fetch_object($result)) {
  206. if (self::checkAdminAccessToModule($row->module_id)) {
  207. $resultObjects[] = $row;
  208. }
  209. }
  210. return $resultObjects;
  211. }
  212. else {
  213. return $resultObjects;
  214. }
  215. }
  216. static function checkMenuActive($slug='') {
  217. if (stristr($_SERVER['REQUEST_URI'],$slug)) {
  218. return ' active';
  219. }
  220. else {
  221. return '';
  222. }
  223. }
  224. static function checkSubmenuActive($moduleID='') {
  225. self::dbconnect();
  226. global $conn;
  227. $temp = explode('/',$_SERVER['REQUEST_URI']);
  228. $slug = $temp[2];
  229. $res_check = mysqli_query($conn,"select * from azonics_modules where module_controller='".$slug."' and module_status='1';");
  230. if (mysqli_num_rows($res_check)>0) {
  231. $row_check = mysqli_fetch_array($res_check);
  232. if ($row_check['module_display_parent']==$moduleID) {
  233. return ' active';
  234. }
  235. else {
  236. return '';
  237. }
  238. }
  239. else {
  240. return '';
  241. }
  242. }
  243. static function reloadAccount() {
  244. self::dbconnect();
  245. global $conn;
  246. if ($_SESSION['admin_user']->admin_id!='') {
  247. $res = mysqli_query($conn,"select * from azonics_admin_users where admin_id='".$_SESSION['admin_user']->admin_id."';");
  248. if (mysqli_num_rows($res)>0) {
  249. $_SESSION['admin_user'] = mysqli_fetch_object($res);
  250. return true;
  251. }
  252. else {
  253. return false;
  254. }
  255. }
  256. else {
  257. return false;
  258. }
  259. }
  260. static function isLanguageModuleEnabled($admin_id='') {
  261. self::dbconnect();
  262. global $conn;
  263. if ($admin_id!='') {
  264. $res_module_access = mysqli_query($conn,"select * from "
  265. . "azonics_modules, "
  266. . "azonics_modules_role, "
  267. . "azonics_admin_users where "
  268. . "module_controller='translator' and "
  269. . "module_status='1' and "
  270. . "admin_id='".$admin_id."' and "
  271. . "admin_status<>'0' and "
  272. . "modrole_role_id=admin_access_level and "
  273. . "modrole_module_id=module_id and "
  274. . "modrole_status='1';");
  275. if (mysqli_num_rows($res_module_access)>0) {
  276. return true;
  277. }
  278. else {
  279. return false;
  280. }
  281. }
  282. else {
  283. return false;
  284. }
  285. }
  286. static function loadSystemSettings() {
  287. self::dbconnect();
  288. global $conn;
  289. $res = mysqli_query($conn,"select * from azonics_settings where setting_status='1';");
  290. if (mysqli_num_rows($res)>0) {
  291. while ($row = mysqli_fetch_object($res)) {
  292. $hash = $row->setting_name;
  293. $data[$hash] = $row;
  294. }
  295. return $data;
  296. }
  297. else {
  298. return false;
  299. }
  300. }
  301. static function getSystemParam($paramName='') {
  302. self::dbconnect();
  303. global $conn;
  304. $res = mysqli_query($conn,"select * from azonics_settings where setting_name='".$paramName."';");
  305. if (mysqli_num_rows($res)>0) {
  306. $row = mysqli_fetch_object($res);
  307. if ($_SESSION['admin_lang'] == 'hu') {
  308. return $row->setting_value_text;
  309. }
  310. else {
  311. return $row->setting_value_text;
  312. }
  313. }
  314. else {
  315. return false;
  316. }
  317. }
  318. static function getAccessLevelName($level_id='') {
  319. self::dbconnect();
  320. global $conn;
  321. if ($level_id!='') {
  322. $res = mysqli_query($conn,"select * from azonics_roles where role_id='".$level_id."';");
  323. if (mysqli_num_rows($res)>0) {
  324. $row = mysqli_fetch_array($res);
  325. return '<span class="'.$row['role_color'].'">'.$row['role_name'].'</span>';
  326. }
  327. else {
  328. return '';
  329. }
  330. }
  331. else {
  332. return '';
  333. }
  334. }
  335. static function checkForUpdates() {
  336. global $config;
  337. $update_xml_file = file_get_contents('http://updates.kreatio.hu/updates.php?key='.$config['licence_key']);
  338. $update_xml = file_get_contents($update_xml_file);
  339. if ($update_xml!='') {
  340. $dom = simplexml_load_string($update_xml);
  341. $ftp = ftp_connect('ftp.kreatio.hu');
  342. $login = ftp_login($ftp,'updates@kreatio.hu','zTaD[fIGpgCI');
  343. foreach ($dom->file as $file) {
  344. ftp_get($ftp,$file['path'],$file['path'],FTP_ASCII);
  345. }
  346. return $dom->message;
  347. }
  348. else {
  349. return '';
  350. }
  351. }
  352. static function getSiteName($default='') {
  353. self::dbconnect();
  354. global $conn;
  355. $res = mysqli_query($conn,"select * from azonics_settings where setting_name='SITENAME' and setting_status='1';");
  356. if (mysqli_num_rows($res)>0) {
  357. $row = mysqli_fetch_array($res);
  358. return $row['setting_value_text'];
  359. }
  360. else {
  361. return $default;
  362. }
  363. }
  364. static function getPageName() {
  365. self::dbconnect();
  366. global $conn;
  367. $res = mysqli_query($conn,"select * from azonics_settings where setting_name='PAGENAME' and setting_status='1';");
  368. if (mysqli_num_rows($res)>0) {
  369. $row = mysqli_fetch_array($res);
  370. return $row['setting_value_text'];
  371. }
  372. else {
  373. return '';
  374. }
  375. }
  376. static function getBaseColorScheme($default='') {
  377. self::dbconnect();
  378. global $conn;
  379. $res = mysqli_query($conn,"select * from azonics_settings where setting_name='COLOR' and setting_status='1';");
  380. if (mysqli_num_rows($res)>0) {
  381. $row = mysqli_fetch_array($res);
  382. return $row['setting_value_text'];
  383. }
  384. else {
  385. return $default;
  386. }
  387. }
  388. static function getSlogan($default='') {
  389. self::dbconnect();
  390. global $conn;
  391. $res = mysqli_query($conn,"select * from azonics_settings where setting_name='SLOGAN' and setting_status='1';");
  392. if (mysqli_num_rows($res)>0) {
  393. $row = mysqli_fetch_array($res);
  394. return $row['setting_value_text'];
  395. }
  396. else {
  397. return $default;
  398. }
  399. }
  400. static function userComboBox($sel='') {
  401. self::dbconnect();
  402. global $conn;
  403. $res = mysqli_query($conn,"select * from azonics_users where user_status<>'0' order by user_nick asc;");
  404. $result = '<option value="">'.lang::_('Choose user').'</option>';
  405. if (mysqli_num_rows($res)>0) {
  406. while ($row = mysqli_fetch_array($res)) {
  407. if ($sel==$row['user_id']) {
  408. $result.= '<option value="'.$row['user_id'].'" selected>'.$row['user_nick'].' ('.$row['user_first_name'].' '.$row['user_last_name'].')</option>';
  409. }
  410. else {
  411. $result.= '<option value="'.$row['user_id'].'">'.$row['user_nick'].' ('.$row['user_first_name'].' '.$row['user_last_name'].')</option>';
  412. }
  413. }
  414. }
  415. return $result;
  416. }
  417. static function getUserNameByID($user_id='') {
  418. self::dbconnect();
  419. global $conn;
  420. $user_id = mysql_real_escape_string($user_id);
  421. $res = mysqli_query($conn,"select * from azonics_users where user_id='".$user_id."';");
  422. if (mysqli_num_rows($res)>0) {
  423. $row = mysqli_fetch_array($res);
  424. return $row['user_first_name'].' '.$row['user_last_name'].' ('.$row['user_nick'].')';
  425. }
  426. else {
  427. return false;
  428. }
  429. }
  430. static function categoryComboBox($sel='') {
  431. self::dbconnect();
  432. global $conn;
  433. $res = mysqli_query($conn,"select * from azonics_categories where category_status<>'0' order by category_name asc;");
  434. $result = '<option value="">'.lang::_('Choose category').'</option>';
  435. if (mysqli_num_rows($res)>0) {
  436. while ($row = mysqli_fetch_array($res)) {
  437. if ($sel==$row['category_id']) {
  438. $result.= '<option value="'.$row['category_id'].'" selected>'.$row['category_name'].'</option>';
  439. }
  440. else {
  441. $result.= '<option value="'.$row['category_id'].'">'.$row['category_name'].'</option>';
  442. }
  443. }
  444. }
  445. return $result;
  446. }
  447. static function getProfileCategory($id='') {
  448. self::dbconnect();
  449. global $conn;
  450. if ($id!='') {
  451. $res = mysqli_query($conn,"select * from azonics_categories where category_id='".$id."';");
  452. $row = mysqli_fetch_array($res);
  453. return $row['category_name'];
  454. }
  455. else {
  456. return false;
  457. }
  458. }
  459. static function getProductStatus($status='',$pid='') {
  460. if ($status=='1') {
  461. return '<div class="btn-group">'
  462. . '<button type="button" class="btn btn-success">'.lang::_('Active').'</button>'
  463. . '<button aria-expanded="false" type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown">'
  464. . '<span class="caret"></span>'
  465. . '<span class="sr-only">Toggle Dropdown</span>'
  466. . '</button>'
  467. . '<ul class="dropdown-menu" role="menu">'
  468. . '<li><a href="/admin/products/set/?status=3&id='.$pid.'">'.lang::_('Set inactive').'</a></li>'
  469. . '<li><a href="/admin/products/delete/?id='.$pid.'">'.lang::_('Delete').'</a></li>'
  470. . '</ul>'
  471. . '</div>';
  472. }
  473. else if ($status=='3') {
  474. return '<div class="btn-group">'
  475. . '<button type="button" class="btn btn-default">'.lang::_('Inactive').'</button>'
  476. . '<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">'
  477. . '<span class="caret"></span>'
  478. . '<span class="sr-only">Toggle Dropdown</span>'
  479. . '</button>'
  480. . '<ul class="dropdown-menu" role="menu">'
  481. . '<li><a href="/admin/products/set/?status=1&id='.$pid.'">'.lang::_('Set active').'</a></li>'
  482. . '<li><a href="/admin/products/delete/?id='.$pid.'">'.lang::_('Delete').'</a></li>'
  483. . '</ul>'
  484. . '</div>';
  485. }
  486. }
  487. static function getProfileStatus($status='',$pid='') {
  488. if ($status=='1') {
  489. return '<div class="btn-group">'
  490. . '<button type="button" class="btn btn-xs btn-success">'.lang::_('Active').'</button>'
  491. . '<button aria-expanded="false" type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown">'
  492. . '<span class="caret"></span>'
  493. . '<span class="sr-only">Toggle Dropdown</span>'
  494. . '</button>'
  495. . '<ul class="dropdown-menu" role="menu">'
  496. . '<li><a href="/admin/profiles/set/?status=2&id='.$pid.'">'.lang::_('Set inactive').'</a></li>'
  497. . '<li><a href="/admin/profiles/delete/?id='.$pid.'">'.lang::_('Delete').'</a></li>'
  498. . '</ul>'
  499. . '</div>';
  500. }
  501. else if ($status=='2') {
  502. return '<div class="btn-group">'
  503. . '<button type="button" class="btn btn-xs btn-default">'.lang::_('Inactive').'</button>'
  504. . '<button aria-expanded="false" type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">'
  505. . '<span class="caret"></span>'
  506. . '<span class="sr-only">Toggle Dropdown</span>'
  507. . '</button>'
  508. . '<ul class="dropdown-menu" role="menu">'
  509. . '<li><a href="/admin/profiles/set/?status=1&id='.$pid.'">'.lang::_('Set active').'</a></li>'
  510. . '<li><a href="/admin/profiles/delete/?id='.$pid.'">'.lang::_('Delete').'</a></li>'
  511. . '</ul>'
  512. . '</div>';
  513. }
  514. else if ($status=='3') {
  515. return '<div class="btn-group">'
  516. . '<button type="button" class="btn btn-xs btn-info">'.lang::_('Waiting').'</button>'
  517. . '<button aria-expanded="false" type="button" class="btn btn-info btn-xs dropdown-toggle" data-toggle="dropdown">'
  518. . '<span class="caret"></span>'
  519. . '<span class="sr-only">Toggle Dropdown</span>'
  520. . '</button>'
  521. . '<ul class="dropdown-menu" role="menu">'
  522. . '<li><a href="/admin/profiles/set/?status=1&id='.$pid.'">'.lang::_('Enable').'</a></li>'
  523. . '<li><a href="/admin/profiles/delete/?id='.$pid.'">'.lang::_('Delete').'</a></li>'
  524. . '</ul>'
  525. . '</div>';
  526. }
  527. }
  528. static function getMainImage($pid) {
  529. self::dbconnect();
  530. global $conn;
  531. $res2 = mysqli_query($conn,"select * from azonics_galeries where "
  532. . "galery_design_id='".$pid."' and "
  533. . "galery_status='1' and galery_main_image='1';");
  534. if (mysqli_num_rows($res2)>0) {
  535. $row2 = mysqli_fetch_array($res2);
  536. return '<img src="'.BASE_URL.$row2['galery_image'].'" alt="Image" />';
  537. }
  538. else {
  539. return '<img src="http://placehold.it/500x500" alt="Image" />';
  540. }
  541. }
  542. static function battleTypesOptions($sel='') {
  543. self::dbconnect();
  544. global $conn;
  545. $res_bt = mysqli_query($conn,"select * from azonics_battle_types where "
  546. . "battle_type_status='1' "
  547. . "order by battle_type_name asc;");
  548. $temp = '<option value="">Choose battle type</option>';
  549. if (mysqli_num_rows($res_bt)>0) {
  550. while ($row_bt = mysqli_fetch_array($res_bt)) {
  551. if ($sel==$row_bt['battle_type_id']) {
  552. $temp.= '<option value="'.$row_bt['battle_type_id'].'" selected>'.$row_bt['battle_type_name'].'</option>';
  553. }
  554. else {
  555. $temp.= '<option value="'.$row_bt['battle_type_id'].'">'.$row_bt['battle_type_name'].'</option>';
  556. }
  557. }
  558. }
  559. return $temp;
  560. }
  561. static function battleAwardsOptions($sel='') {
  562. self::dbconnect();
  563. global $conn;
  564. $res_bw = mysqli_query($conn,"select * from azonics_awards where "
  565. . "award_status='1' "
  566. . "order by award_name asc;");
  567. $temp = '<option value="">Choose award</option>';
  568. if (mysqli_num_rows($res_bw)>0) {
  569. while ($row_bw = mysqli_fetch_array($res_bw)) {
  570. if ($sel==$row_bw['award_id']) {
  571. $temp.= '<option value="'.$row_bw['award_id'].'" selected>'.$row_bw['award_name'].'</option>';
  572. }
  573. else {
  574. $temp.= '<option value="'.$row_bw['award_id'].'">'.$row_bw['award_name'].'</option>';
  575. }
  576. }
  577. }
  578. return $temp;
  579. }
  580. static function getBattleType($type_id='') {
  581. self::dbconnect();
  582. global $conn;
  583. if ($type_id!='') {
  584. $res_type = mysqli_query($conn,"select * from azonics_battle_types where battle_type_id='".$type_id."';");
  585. if (mysqli_num_rows($res_type)>0) {
  586. $row_type = mysqli_fetch_array($res_type);
  587. return $row_type['battle_type_name'];
  588. }
  589. else {
  590. return false;
  591. }
  592. }
  593. else {
  594. return false;
  595. }
  596. }
  597. static function getBattleAward($award_id='') {
  598. self::dbconnect();
  599. global $conn;
  600. if ($award_id!='') {
  601. $res_award = mysqli_query($conn,"select * from azonics_awards where award_id='".$award_id."';");
  602. if (mysqli_num_rows($res_award)>0) {
  603. $row_award = mysqli_fetch_array($res_award);
  604. return $row_award['award_name'];
  605. }
  606. else {
  607. return false;
  608. }
  609. }
  610. else {
  611. return false;
  612. }
  613. }
  614. static function generateSlug($name='') {
  615. if ($name!='') {
  616. $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  617. $text = trim($text, '-');
  618. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  619. $text = strtolower($text);
  620. $text = preg_replace('~[^-\w]+~', '', $text);
  621. if (empty($text)) return time();
  622. return $text;
  623. }
  624. else {
  625. return time();
  626. }
  627. }
  628. static function getProductTags($product_category='') {
  629. $tags = explode(",",$product_category);
  630. foreach ($tags as $tag) {
  631. if ($tag!='') $list.= '<span class="label label-info">'.$tag.'</span>&nbsp;';
  632. }
  633. return $list;
  634. }
  635. static function getProductMeta($product_id='') {
  636. self::dbconnect();
  637. global $conn;
  638. $list = '';
  639. if ($product_id!='') {
  640. $res = mysqli_query($conn,"select * from azonics_product_meta where "
  641. . "meta_pid='".$product_id."' and "
  642. . "meta_status='1' order by meta_date asc;");
  643. if (mysqli_num_rows($res)>0) {
  644. while ($row = mysqli_fetch_array($res)) {
  645. $list.= '<!--Metarow:'.$row['meta_id'].'-->'
  646. . '<tr>'
  647. . '<td><input type="text" name="meta_key" onblur="save_product_meta_data($(this))" value="'.$row['meta_key'].'" class="form-control" data-mid="'.$row['meta_id'].'" /></td>'
  648. . '<td><input type="text" name="meta_value" onblur="save_product_meta_data($(this))" value="'.$row['meta_value'].'" class="form-control" data-mid="'.$row['meta_id'].'" /></td>'
  649. . '<td><button type="button" name="meta_delete" class="btn btn-danger" data-mid="'.$row['meta_id'].'" data-pid="'.$row['meta_pid'].'" onclick="delete_product_meta($(this))"><i class="fa fa-trash"></i></button></td>'
  650. . '</tr>';
  651. }
  652. }
  653. }
  654. return $list;
  655. }
  656. static function bannerZones($selectedZone='') {
  657. $temp = '<option value="">'.lang::_('Choose banner zone!').'</option>';
  658. if ($selectedZone=='zone1') {
  659. $temp.= '<option value="zone1" selected>'.lang::_('Főoldali slider').'</option>';
  660. }
  661. else {
  662. $temp.= '<option value="zone1">'.lang::_('Főoldali slider').'</option>';
  663. }
  664. return $temp;
  665. }
  666. static function getBannerZoneName($zone_id) {
  667. if ($zone_id=='zone1') {
  668. return lang::_('Speciális kínálat');
  669. }
  670. else {
  671. return lang::_('Rólunk mondták');
  672. }
  673. }
  674. static function trim_url($url) {
  675. if ($url!='') {
  676. $url = str_replace("http://","",$url);
  677. }
  678. return $url;
  679. }
  680. static function add_url_prefix($url) {
  681. if ($url!='') {
  682. $url = "http://".$url;
  683. }
  684. return $url;
  685. }
  686. static function get_category_selector($selected) {
  687. self::dbconnect();
  688. global $conn;
  689. $res = mysqli_query($conn,"select * from azonics_categories where category_status='0' order by category_name asc;");
  690. $options = '';
  691. if (mysqli_num_rows($res)>0) {
  692. while ($row = mysqli_fetch_object($res)) {
  693. if ($_SESSION['category']=='') $_SESSION['category'] = $row->category_id;
  694. if ($selected==$row->category_id) {
  695. $options.= '<option value="'.$row->category_id.'" selected>'.$row->category_name.'</option>';
  696. }
  697. else {
  698. $options.= '<option value="'.$row->category_id.'">'.$row->category_name.'</option>';
  699. }
  700. }
  701. }
  702. if ($_SESSION['category']=='') $_SESSION['category'] = '0';
  703. $options.= '<option value="0">'.lang::_('Minden kategória').'</option>';
  704. return $options;
  705. }
  706. static function getLendingStatusByID($status_id='1',$field='ls_name') {
  707. self::dbconnect();
  708. global $conn;
  709. if ($status_id!='') {
  710. $res_item = mysqli_query($conn,"select * from mingo_lending_status where ls_id='".$status_id."';");
  711. $row_item = mysqli_fetch_array($res_item);
  712. return $row_item[$field];
  713. }
  714. else {
  715. return false;
  716. }
  717. }
  718. static function getLendingStatusCombo($selected='1',$lending_id='') {
  719. self::dbconnect();
  720. global $conn;
  721. $res = mysqli_query($conn,"select * from mingo_lending_status where ls_status='1' order by ls_id asc;");
  722. if ($selected=='') $selected='1';
  723. $result = '<div class="btn-group">';
  724. $result.= '<button type="button" class="btn '.self::getLendingStatusByID($selected,'ls_color').'">'.self::getLendingStatusByID($selected,'ls_name').'</button>';
  725. $result.= '<button aria-expanded="false" type="button" class="btn '.self::getLendingStatusByID($selected,'ls_color').' dropdown-toggle" data-toggle="dropdown">
  726. <span class="caret"></span>
  727. <span class="sr-only">Toggle Dropdown</span>
  728. </button>
  729. <ul class="dropdown-menu" role="menu">';
  730. if (mysqli_num_rows($res)>0) {
  731. while ($row = mysqli_fetch_array($res)) {
  732. $result.= '<li><a href="/admin/lendings/set/?status='.$row['ls_id'].'&lending_id='.$lending_id.'">'.$row['ls_name'].'</a></li>';
  733. }
  734. }
  735. $result.= '</ul></div>';
  736. return $result;
  737. }
  738. static function lendingStatusComboBox($selected='') {
  739. self::dbconnect();
  740. global $conn;
  741. $res = mysqli_query($conn,"select * from mingo_lending_status where ls_status='1' order by ls_id asc;");
  742. if (mysqli_num_rows($res)>0) {
  743. while ($row = mysqli_fetch_array($res)) {
  744. if ($selected==$row['ls_id']) {
  745. $result.= '<option value="'.$row['ls_id'].'" selected>'.$row['ls_name'].'</option>';
  746. }
  747. else {
  748. $result.= '<option value="'.$row['ls_id'].'">'.$row['ls_name'].'</option>';
  749. }
  750. }
  751. }
  752. else {
  753. $result.= '<option value="0">Nem lehet státuszt állítani!</option>';
  754. }
  755. return $result;
  756. }
  757. static function get_todos($show_all='all',$uid=0,$lending_id=0,$limit=10,$orderby='todo_date',$order='asc',$comments=false,$finished=true) {
  758. self::dbconnect();
  759. global $conn;
  760. if ($comments==true) {
  761. $comments_selector = " and todo_date<>'NULL'";
  762. }
  763. else {
  764. $comments_selector = '';
  765. }
  766. if ($finished==false) {
  767. $finish = " and todo_finished<>'1'";
  768. }
  769. else {
  770. $finish = "";
  771. }
  772. if ($show_all=='all') {
  773. $res = mysqli_query($conn,"select * from mingo_todos where todo_status='1'".$comments_selector." and todo_admin_id='".$_SESSION['admin_user']->admin_id."'".$finish." order by ".$orderby." ".$order." limit 0,".$limit.";");
  774. }
  775. elseif ($show_all=='users') {
  776. $res = mysqli_query($conn,"select * from mingo_todos where todo_status='1'".$comments_selector." and todo_user_id<>'0' and todo_admin_id='".$_SESSION['admin_user']->admin_id."'".$finish." order by ".$orderby." ".$order." limit 0,".$limit.";");
  777. }
  778. elseif ($show_all=='lendings') {
  779. $res = mysqli_query($conn,"select * from mingo_todos where todo_status='1'".$comments_selector." and todo_lending_id<>'0' and todo_admin_id='".$_SESSION['admin_user']->admin_id."'".$finish." order by ".$orderby." ".$order." limit 0,".$limit.";");
  780. }
  781. elseif ($uid>0) {
  782. $res = mysqli_query($conn,"select * from mingo_todos where todo_status='1'".$comments_selector." and todo_user_id='".$uid."' and todo_admin_id='".$_SESSION['admin_user']->admin_id."'".$finish." order by ".$orderby." ".$order." limit 0,".$limit.";");
  783. }
  784. elseif ($lending_id>0) {
  785. $res = mysqli_query($conn,"select * from mingo_todos where todo_status='1'".$comments_selector." and todo_lending_id='".$lending_id."' and todo_admin_id='".$_SESSION['admin_user']->admin_id."'".$finish." order by ".$orderby." ".$order." limit 0,".$limit.";");
  786. }
  787. if (mysqli_num_rows($res)>0) {
  788. while ($row = mysqli_fetch_object($res)) {
  789. $result[] = $row;
  790. }
  791. return $result;
  792. }
  793. else {
  794. return false;
  795. }
  796. }
  797. function get_todo_object($id) {
  798. self::dbconnect();
  799. global $conn;
  800. $res = mysqli_query($conn,"select * from mingo_todos where todo_id='".$id."';");
  801. if (mysqli_num_rows($res)>0) {
  802. return mysqli_fetch_object($res);
  803. }
  804. else {
  805. return false;
  806. }
  807. }
  808. function get_group_options($group,$selected='') {
  809. self::dbconnect();
  810. global $conn;
  811. $res = mysqli_query($conn,"SELECT * FROM sc_variants WHERE variant_group='".$group."' AND variant_status='1' ORDER BY variant_name ASC;");
  812. $result = '<option value="">Válasszon!</option>';
  813. if (mysqli_num_rows($res)>0) {
  814. while ($row = mysqli_fetch_array($res)) {
  815. if ($selected==$row['variant_id']) {
  816. $result.= '<option value="'.$row['variant_id'].'" selected>'.$row['variant_name'].'</option>';
  817. }
  818. else {
  819. $result.= '<option value="'.$row['variant_id'].'">'.$row['variant_name'].'</option>';
  820. }
  821. }
  822. }
  823. return $result;
  824. }
  825. function get_rajz($cikkszam='') {
  826. self::dbconnect();
  827. global $conn;
  828. if ($cikkszam!='') {
  829. $res = mysqli_query($conn,"select * from sc_rajzok where rajz_cikkszam='".$cikkszam."' and rajz_status='1';");
  830. if (mysqli_num_rows($res)>0) {
  831. $row = mysqli_fetch_array($res);
  832. return $row['rajz_file'];
  833. }
  834. else {
  835. return false;
  836. }
  837. }
  838. else {
  839. return false;
  840. }
  841. }
  842. function has_rajz($cikkszam='') {
  843. self::dbconnect();
  844. global $conn;
  845. if ($cikkszam!='') {
  846. $res = mysqli_query($conn,"select * from sc_rajzok where rajz_cikkszam='".$cikkszam."' and rajz_status='1';");
  847. if (mysqli_num_rows($res)>0) {
  848. return true;
  849. }
  850. else {
  851. return false;
  852. }
  853. }
  854. else {
  855. return false;
  856. }
  857. }
  858. function has_document($id) {
  859. self::dbconnect();
  860. global $conn;
  861. if ($id!='') {
  862. $res = mysqli_query($conn,"select * from sc_beszerzes where beszer_id='".$id."';");
  863. if (mysqli_num_rows($res)>0) {
  864. $row = mysqli_fetch_array($res);
  865. return $row['beszer_document'];
  866. }
  867. else {
  868. return false;
  869. }
  870. }
  871. else {
  872. return false;
  873. }
  874. }
  875. function has_bill_image($bill_number='') {
  876. self::dbconnect();
  877. global $conn;
  878. if ($bill_number!='') {
  879. $res = mysqli_query($conn,"select * from sc_bills where bill_number='".$bill_number."' and bill_status='1';");
  880. if (mysqli_num_rows($res)>0) {
  881. return true;
  882. }
  883. else {
  884. return false;
  885. }
  886. }
  887. else {
  888. return false;
  889. }
  890. }
  891. function get_bill_image($bill_number='') {
  892. self::dbconnect();
  893. global $conn;
  894. if ($bill_number!='') {
  895. $res = mysqli_query($conn,"select * from sc_bills where bill_number='".$bill_number."' and bill_status='1';");
  896. if (mysqli_num_rows($res)>0) {
  897. $row = mysqli_fetch_array($res);
  898. return $row['bill_image'];
  899. }
  900. else {
  901. return false;
  902. }
  903. }
  904. else {
  905. return false;
  906. }
  907. }
  908. function check_admin_access_to_action() {
  909. if ($_SESSION['admin_user']->admin_access_level=='1' || $_SESSION['admin_user']->admin_access_level=='11') {
  910. return true;
  911. }
  912. else {
  913. return false;
  914. }
  915. }
  916. function get_modules_select($selected='') {
  917. self::dbconnect();
  918. global $conn;
  919. $res = mysqli_query($conn,"SELECT * FROM azonics_modules WHERE module_status='1' ORDER BY display_order ASC;");
  920. $result = '';
  921. if (mysqli_num_rows($res)>0) {
  922. while ($row = mysqli_fetch_array($res)) {
  923. if ($selected==$row['module_controller']) {
  924. $result.= '<option value="'.$row['module_controller'].'" selected>'.$row['module_name'].'</option>';
  925. }
  926. else {
  927. $result.= '<option value="'.$row['module_controller'].'">'.$row['module_name'].'</option>';
  928. }
  929. }
  930. }
  931. return $result;
  932. }
  933. static function get_product_data($pid) {
  934. self::dbconnect();
  935. global $conn;
  936. if ($pid!=='') {
  937. $res = mysqli_query($conn,"SELECT * FROM products_temp WHERE id='".$pid."';");
  938. if (mysqli_num_rows($res)>0) {
  939. $row = mysqli_fetch_object($res);
  940. $result = 'Termék név: '.$row->name.'<br>Brand: '.$row->brand.'<br>Part.no.: '.$row->part_no.'<br>Short desc.: '.$row->short_description.'<br>Price: '.$row->price.'<br>Type: '.$row->type;
  941. return $result;
  942. }
  943. else {
  944. return false;
  945. }
  946. }
  947. else {
  948. return false;
  949. }
  950. }
  951. static function get_product_image($pid,$type) {
  952. self::dbconnect();
  953. global $conn;
  954. if ($pid!=='' && $type!=='') {
  955. $res = mysqli_query($conn,"SELECT * FROM products_temp WHERE id='".$pid."';");
  956. if (mysqli_num_rows($res)>0) {
  957. $row = mysqli_fetch_object($res);
  958. if ($row->$type!==NULL) {
  959. $result = '<img src="http://webshop.rackmester.hu/'.$row->$type.'" style="width: 50px;" />';
  960. }
  961. else {
  962. $result = ' - ';
  963. }
  964. return $result;
  965. }
  966. else {
  967. return false;
  968. }
  969. }
  970. else {
  971. return false;
  972. }
  973. }
  974. static function get_ertekkeszlet($kategoria,$mezo) {
  975. self::dbconnect();
  976. global $conn;
  977. if ($kategoria!=='' && $mezo!=='') {
  978. $res = mysqli_query($conn,"SELECT * FROM azonics_codomains WHERE kategoria='".$kategoria."' AND mezo='".$mezo."' AND status='1' ORDER BY ertek ASC;");
  979. if (mysqli_num_rows($res)>0) {
  980. while ($row = mysqli_fetch_array($res)) {
  981. $result[] = $row['ertek'];
  982. }
  983. return $result;
  984. }
  985. else {
  986. return false;
  987. }
  988. }
  989. else {
  990. return false;
  991. }
  992. }
  993. static function get_category_factor($category) {
  994. self::dbconnect();
  995. global $conn;
  996. if ($category!='') {
  997. $res = mysqli_query($conn,"SELECT * FROM azonics_category_price_factors WHERE category='".$category."' AND status='1';");
  998. if (mysqli_num_rows($res)>0) {
  999. return mysqli_fetch_object($res);
  1000. }
  1001. else {
  1002. return false;
  1003. }
  1004. }
  1005. else {
  1006. return false;
  1007. }
  1008. }
  1009. static function get_velemenyek_by_agent_id($agentid) {
  1010. self::dbconnect();
  1011. global $conn;
  1012. if ($agentid!='') {
  1013. $res = mysqli_query($conn,"SELECT * FROM velemenyek WHERE agent_id='".$agentid."';");
  1014. return mysqli_num_rows($res);
  1015. }
  1016. else {
  1017. return 0;
  1018. }
  1019. }
  1020. }