/modules/static_page/static_page.inc.php

https://github.com/axxtel/agilebill · PHP · 423 lines · 291 code · 69 blank · 63 comment · 37 complexity · b7a741e35cc1c3b6d8482ac06f17b465 MD5 · raw file

  1. <?php
  2. /**
  3. * AgileBill - Open Billing Software
  4. *
  5. * This body of work is free software; you can redistribute it and/or
  6. * modify it under the terms of the Open AgileBill License
  7. * License as published at http://www.agileco.com/agilebill/license1-4.txt
  8. *
  9. * For questions, help, comments, discussion, etc., please join the
  10. * Agileco community forums at http://forum.agileco.com/
  11. *
  12. * @link http://www.agileco.com/
  13. * @copyright 2004-2008 Agileco, LLC.
  14. * @license http://www.agileco.com/agilebill/license1-4.txt
  15. * @author Tony Landis <tony@agileco.com>
  16. * @package AgileBill
  17. * @version 1.4.93
  18. */
  19. class static_page
  20. {
  21. # Open the constructor for this mod
  22. function static_page()
  23. {
  24. # name of this module:
  25. $this->module = "static_page";
  26. # location of the construct XML file:
  27. $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
  28. # open the construct file for parsing
  29. $C_xml = new CORE_xml;
  30. $construct = $C_xml->xml_to_array($this->xml_construct);
  31. $this->method = $construct["construct"]["method"];
  32. $this->trigger = $construct["construct"]["trigger"];
  33. $this->field = $construct["construct"]["field"];
  34. $this->table = $construct["construct"]["table"];
  35. $this->module = $construct["construct"]["module"];
  36. $this->cache = $construct["construct"]["cache"];
  37. $this->order_by = $construct["construct"]["order_by"];
  38. $this->limit = $construct["construct"]["limit"];
  39. }
  40. ##############################
  41. ## GET AUTH CATEGORIES ##
  42. ##############################
  43. function page_list($VAR)
  44. {
  45. /* check if current session is authorized for any ticket departments..
  46. and return true/false...
  47. */
  48. global $smarty;
  49. if(!isset($VAR['id']))
  50. {
  51. global $C_debug;
  52. $smarty->assign('static_page_display', false);
  53. return false;
  54. }
  55. ### Check if user is auth for the selected category:
  56. $db = &DB();
  57. $sql = 'SELECT DISTINCT id,name,group_avail FROM ' . AGILE_DB_PREFIX . 'static_page_category WHERE
  58. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  59. status = ' . $db->qstr('1') .' AND
  60. id = ' . $db->qstr($VAR['id']);
  61. $result = $db->Execute($sql);
  62. if($result->RecordCount() == 0)
  63. {
  64. global $C_debug;
  65. $smarty->assign('static_page_display', false);
  66. return false;
  67. }
  68. global $C_auth;
  69. $iii = 0;
  70. while(!$result->EOF)
  71. {
  72. @$arr = unserialize($result->fields['group_avail']);
  73. for($i=0; $i<count($arr); $i++)
  74. {
  75. if($C_auth->auth_group_by_id($arr[$i]))
  76. {
  77. $iii++;
  78. $i=count($arr);
  79. }
  80. }
  81. $result->MoveNext();
  82. }
  83. if($iii == 0)
  84. {
  85. global $C_debug;
  86. $smarty->assign('static_page_display', false);
  87. return false;
  88. }
  89. $sql = 'SELECT id,name,date_expire,date_start
  90. FROM ' . AGILE_DB_PREFIX . 'static_page WHERE
  91. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  92. static_page_category_id = ' . $db->qstr($VAR['id']) . ' AND
  93. status = ' . $db->qstr('1') .'
  94. ORDER BY sort_order,date_orig,name';
  95. $result = $db->Execute($sql);
  96. if($result->RecordCount() == 0)
  97. {
  98. $smarty->assign('static_page_category_display', false);
  99. return false;
  100. }
  101. global $C_auth;
  102. $ii = 0;
  103. while(!$result->EOF)
  104. {
  105. $start = $result->fields['date_start'];
  106. $expire= $result->fields['date_expire'];
  107. ### Check that it is not expired
  108. if (( $start == "0" || $start <= time()+2 ) &&
  109. ( $expire == "0" || $expire >= time() ) )
  110. {
  111. ### Get the translated name, for the current session language
  112. $sql = 'SELECT body_intro, title, language_id
  113. FROM ' . AGILE_DB_PREFIX . 'static_page_translate WHERE
  114. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  115. static_page_id = ' . $db->qstr($result->fields['id']) . ' AND
  116. language_id = ' . $db->qstr(SESS_LANGUAGE);
  117. $translate = $db->Execute($sql);
  118. if($translate->RecordCount() > 0)
  119. {
  120. $arr_smarty[] = Array (
  121. 'name' => $result->fields['name'],
  122. 'title' => $translate->fields['title'],
  123. 'intro' => $translate->fields['body_intro'],
  124. );
  125. $ii++;
  126. }
  127. else
  128. {
  129. ### Get the translated name, for the default langauge
  130. $sql = 'SELECT body_intro, title, language_id
  131. FROM ' . AGILE_DB_PREFIX . 'static_page_translate WHERE
  132. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  133. static_page_id = ' . $db->qstr($result->fields['id']) . ' AND
  134. language_id = ' . $db->qstr(DEFAULT_LANGUAGE);
  135. $translate = $db->Execute($sql);
  136. if($translate->RecordCount() > 0)
  137. {
  138. $arr_smarty[] = Array (
  139. 'name' => $result->fields['name'],
  140. 'title' => $translate->fields['title'],
  141. 'intro' => $translate->fields['body_intro'],
  142. );
  143. $ii++;
  144. }
  145. }
  146. }
  147. $result->MoveNext();
  148. }
  149. if($ii == "0")
  150. {
  151. $smarty->assign('static_page_display', false);
  152. return false;
  153. }
  154. else
  155. {
  156. $smarty->assign('static_page_display', true);
  157. $smarty->assign('static_page_results', $arr_smarty);
  158. return true;
  159. }
  160. }
  161. ########################################################################
  162. ### Show the page
  163. function page_show($VAR)
  164. {
  165. /* check if current session is authorized for any ticket departments..
  166. and return true/false...
  167. */
  168. global $smarty;
  169. if(!isset($VAR['id']) && !isset($VAR['name']))
  170. {
  171. global $C_debug;
  172. $smarty->assign('static_page_display', false);
  173. return false;
  174. }
  175. ### Check if user is auth for the selected category:
  176. $db = &DB();
  177. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'static_page WHERE
  178. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  179. status = ' . $db->qstr('1') .' AND
  180. name = ' . $db->qstr(@$VAR['name']) .' OR
  181. id = ' . $db->qstr(@$VAR['id']);
  182. $page = $db->Execute($sql);
  183. if($page->RecordCount() == 0)
  184. {
  185. global $C_debug;
  186. $smarty->assign('static_page_display', false);
  187. return false;
  188. }
  189. $category_id = $page->fields['static_page_category_id'];
  190. $page_id = $page->fields['id'];
  191. ### Check if user is auth for the selected category:
  192. $db = &DB();
  193. $sql = 'SELECT DISTINCT id,name,group_avail FROM ' . AGILE_DB_PREFIX . 'static_page_category WHERE
  194. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  195. status = ' . $db->qstr('1') .' AND
  196. id = ' . $db->qstr($category_id);
  197. $result = $db->Execute($sql);
  198. if($result->RecordCount() == 0)
  199. {
  200. global $C_debug;
  201. $smarty->assign('static_page_display', false);
  202. return false;
  203. }
  204. global $C_auth;
  205. $iii = 0;
  206. $id = $result->fields['id'];
  207. while(!$result->EOF)
  208. {
  209. @$arr = unserialize($result->fields['group_avail']);
  210. for($i=0; $i<count($arr); $i++)
  211. {
  212. if($C_auth->auth_group_by_id($arr[$i]))
  213. {
  214. $iii++;
  215. $i=count($arr);
  216. }
  217. }
  218. $result->MoveNext();
  219. }
  220. if($iii == 0)
  221. {
  222. global $C_debug;
  223. $smarty->assign('static_page_display', false);
  224. return false;
  225. }
  226. ### Check that it is not expired
  227. $ii = 0;
  228. $start = $page->fields['date_start'];
  229. $expire= $page->fields['date_expire'];
  230. ### Check that it is not expired
  231. if (( $start == "0" || $start <= time()+2 ) &&
  232. ( $expire == "0" || $expire >= time() ) )
  233. {
  234. ### Get the translated name, for the current session language
  235. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'static_page_translate WHERE
  236. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  237. static_page_id = ' . $db->qstr($page->fields['id']) . ' AND
  238. language_id = ' . $db->qstr(SESS_LANGUAGE);
  239. $translate = $db->Execute($sql);
  240. if($translate->RecordCount() > 0)
  241. {
  242. $arr_smarty = Array (
  243. 'name' => $result->fields['name'],
  244. 'title' => $translate->fields['title'],
  245. 'body' => $translate->fields['body_full'],
  246. );
  247. $ii++;
  248. }
  249. else
  250. {
  251. ### Get the translated name, for the default langauge
  252. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'static_page_translate WHERE
  253. site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
  254. static_page_id = ' . $db->qstr($page->fields['id']) . ' AND
  255. language_id = ' . $db->qstr(DEFAULT_LANGUAGE);
  256. $translate = $db->Execute($sql);
  257. if($translate->RecordCount() > 0)
  258. {
  259. $arr_smarty = Array (
  260. 'name' => $result->fields['name'],
  261. 'title' => $translate->fields['title'],
  262. 'body' => $translate->fields['body_full'],
  263. );
  264. $ii++;
  265. }
  266. }
  267. }
  268. if($ii == "0")
  269. {
  270. $smarty->assign('static_page_display', false);
  271. return false;
  272. }
  273. else
  274. {
  275. $smarty->assign('static_page_display', true);
  276. $smarty->assign('static_page_results', $arr_smarty);
  277. return true;
  278. }
  279. }
  280. ##############################
  281. ## ADD ##
  282. ##############################
  283. function add($VAR)
  284. {
  285. $type = "add";
  286. $this->method["$type"] = explode(",", $this->method["$type"]);
  287. $db = new CORE_database;
  288. $db->add($VAR, $this, $type);
  289. }
  290. ##############################
  291. ## VIEW ##
  292. ##############################
  293. function view($VAR)
  294. {
  295. $type = "view";
  296. $this->method["$type"] = explode(",", $this->method["$type"]);
  297. $db = new CORE_database;
  298. $db->view($VAR, $this, $type);
  299. }
  300. ##############################
  301. ## UPDATE ##
  302. ##############################
  303. function update($VAR)
  304. {
  305. $type = "update";
  306. $this->method["$type"] = explode(",", $this->method["$type"]);
  307. $db = new CORE_database;
  308. $db->update($VAR, $this, $type);
  309. }
  310. ##############################
  311. ## DELETE ##
  312. ##############################
  313. function delete($VAR)
  314. {
  315. $this->associated_DELETE[] =
  316. Array(
  317. 'table' => 'static_page_translate',
  318. 'field' => 'static_page_id'
  319. );
  320. $db = new CORE_database;
  321. $db->mass_delete($VAR, $this, "");
  322. }
  323. ##############################
  324. ## SEARCH FORM ##
  325. ##############################
  326. function search_form($VAR)
  327. {
  328. $type = "search";
  329. $this->method["$type"] = explode(",", $this->method["$type"]);
  330. $db = new CORE_database;
  331. $db->search_form($VAR, $this, $type);
  332. }
  333. ##############################
  334. ## SEARCH ##
  335. ##############################
  336. function search($VAR)
  337. {
  338. $type = "search";
  339. $this->method["$type"] = explode(",", $this->method["$type"]);
  340. $db = new CORE_database;
  341. $db->search($VAR, $this, $type);
  342. }
  343. ##############################
  344. ## SEARCH SHOW ##
  345. ##############################
  346. function search_show($VAR)
  347. {
  348. $type = "search";
  349. $this->method["$type"] = explode(",", $this->method["$type"]);
  350. $db = new CORE_database;
  351. $db->search_show($VAR, $this, $type);
  352. }
  353. }
  354. ?>