1657.opcje-zamowienie.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE);
  3. define('DS', DIRECTORY_SEPARATOR);
  4. define('APP_PATH_ROOT', realpath(dirname(__FILE__) . DS . '..'));
  5. define('APP_PATH_WWW', realpath(dirname(__FILE__) . DS . '..'));
  6. define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
  7. //session_save_path("../session") ;
  8. session_start();
  9. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  10. header('Content-Type: text/html; charset=utf-8');
  11. // SEF - SE file loader
  12. function SEF($ARG1) {
  13. if (!function_exists($ARG1)) {
  14. if (file_exists(APP_PATH_ROOT . DS . "superedit-".$ARG1.".php")) include(APP_PATH_ROOT . DS . "superedit-".$ARG1.".php");
  15. else if (file_exists(APP_PATH_ROOT . DS . "billing-".$ARG1.".php")) include(APP_PATH_ROOT . DS . "billing-".$ARG1.".php");
  16. else if (file_exists(APP_PATH_ROOT . DS . $ARG1.".php")) include(APP_PATH_ROOT . DS . $ARG1.".php");
  17. else echo ("\n<br>Function SEF : can't find function ".$ARG1);
  18. }
  19. }
  20. SEF("DEBUG_S");
  21. if (file_exists(APP_PATH_ROOT . DS . ".config.php")) include(APP_PATH_ROOT . DS . ".config.php");
  22. require_once APP_PATH_ROOT . '/' . 'se-lib' . '/' . 'Lib.php';
  23. Lib::loadClass('V');
  24. Lib::loadClass('User');
  25. Lib::loadClass('Config');
  26. Lib::loadClass('App');
  27. Lib::loadClass('DB');
  28. Lib::loadClass('S');
  29. if (!User::logged()) {
  30. die("Require login!");
  31. }
  32. //if (User::get('ADM_ADMIN_LEVEL') != 0) {
  33. // die("Access denied!");
  34. //}
  35. Lib::loadClass('ZasobFileOdt');
  36. $druki_path = '/home/samba/DRUKI';
  37. if ($_SERVER['SERVER_NAME'] == 'se.dev.webone.pl.devpl') {
  38. $druki_path = realpath(APP_PATH_ROOT . '/../../samba/DRUKI/');
  39. } else if ($_SERVER['SERVER_NAME'] == 'biuro.biall-net.pl') {
  40. $druki_path = '/Library/Server/Web/Data/Sites/Default/PLIKI/DRUKI/';
  41. }
  42. $allowed_options = array('NET', 'TEL', 'TV', 'TVC');
  43. $args = array();
  44. $args['id_user'] = V::get('id_user', 0, $_GET, 'int');
  45. $args['id_options'] = array();
  46. foreach ($allowed_options as $v_option) {
  47. $args['id_options'][$v_option] = V::get('id_options_' . $v_option . '', 0, $_GET, 'array');
  48. }
  49. $user = null;
  50. if ($args['id_user'] > 0) {
  51. /*
  52. * <span id="cell-KLIENT_ID"></span>
  53. * <span id="cell-KLIENT_P_NAME"></span>
  54. * <span id="cell-KLIENT_P_NAME_SECOND"></span>
  55. * <span id="cell-KLIENT_P_PHONE"></span>
  56. * <span id="cell-KLIENT_user_mail_contact"></span>
  57. */
  58. $db = DB::getDB();
  59. $sql = "select bua.`id_users`
  60. , bua.`id_users` as ID_BILLING_USERS
  61. , bua.`is_firma`
  62. , bua.`P_NAME`
  63. , bua.`P_NAME_SECOND`
  64. , bua.`P_NIP`
  65. , bua.`P_PESEL`
  66. , bua.`P_PHONE`
  67. , bua.`P_ADDRESS_REGION`
  68. , bua.`P_ADDRESS_CITY`
  69. , bua.`P_ADDRESS_POST_CODE`
  70. , bua.`P_ADDRESS_STREET`
  71. , bua.`P_ADDRESS_HOME`
  72. , bua.`P_ADDRESS_HOUSE`
  73. , bua.`user_mail_contact`
  74. , bu.`BILLING_OWNER`
  75. from `BILLING_USERS_ADD` as bua
  76. left join `BILLING_USERS` as bu on(bu.`ID`=bua.`id_users`)
  77. where bua.`id_users`='{$args['id_user']}'
  78. ";
  79. $res = $db->query($sql);
  80. if ($r = $db->fetch($res)) {
  81. $user = $r;
  82. }
  83. }
  84. $umowaOdt = null;
  85. if ($user) {
  86. if ($user->BILLING_OWNER == 1) {// BN
  87. $umowaOdt = new ZasobFileOdt(1657, $druki_path, dirname(__FILE__), 1657);
  88. } else if ($user->BILLING_OWNER == 2) {// ND
  89. $umowaOdt = new ZasobFileOdt(1657, $druki_path, dirname(__FILE__), 4357);
  90. }
  91. }
  92. if (!$umowaOdt) {
  93. $umowaOdt = new ZasobFileOdt(1657, $druki_path, dirname(__FILE__));
  94. }
  95. if (false == $umowaOdt->find_odt_file()) {
  96. die("Error: cant find file! [" . $umowaOdt->zasob_id . "]");
  97. }
  98. if (false == $umowaOdt->find_xsl_file()) {
  99. die("Template file not exists! - [" . $umowaOdt->zasob_id . "]");
  100. }
  101. if (V::get('test', 0, $_GET, 'int') == 1) {
  102. $odt_file_arr = explode('/', $umowaOdt->odt_file);
  103. array_pop($odt_file_arr);
  104. $umowaOdt->odt_file = implode('/', $odt_file_arr) . '/STARE/test.odt';
  105. }
  106. if (123 == V::get('DBG', 0, $_GET, 'int')) {
  107. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($umowaOdt);echo'</pre>';
  108. }
  109. Lib::loadClass('Odt2xhtml');
  110. if (!class_exists('DOMDocument')) {
  111. die('require class DOMDocument');
  112. }
  113. if (!class_exists('XSLTProcessor')) {
  114. die('require class XSLTProcessor');
  115. }
  116. if (!function_exists('zip_open')) {
  117. die('NO ZIP FUNCTIONS DETECTED. Do you have the PECL ZIP extensions loaded?');
  118. }
  119. $conv = new Odt2xhtml;
  120. if ($umowaOdt->fetch_content_from_odt_by_converter($conv)) {
  121. die("Conversion odt to html error! - [" . $umowaOdt->zasob_id . "]");
  122. }
  123. // fetch data from DB
  124. if (!empty($args['id_options'])) {
  125. /*
  126. * <span id="cell-OPCJA_NET_1_450"></span>
  127. * <span id="cell-OPCJA_NET_1_1385"></span>
  128. * <span id="cell-OPCJA_NET_1_459"></span>
  129. * <span id="cell-OPCJA_NET_1_1580"></span>
  130. * <span id="cell-OPCJA_NET_1_457"></span>
  131. * <span id="cell-OPCJA_NET_1_460"></span>
  132. * <span id="cell-OPCJA_NET_1_458"></span>
  133. *
  134. * <span id="cell-OPCJA_TEL_1_450"></span>
  135. *
  136. * <span id="cell-OPCJA_TV_1_450"></span>
  137. *
  138. * , '' as OPCJA_NET_1_450 -- P_SERVICE_NAME - nazwa
  139. * , '' as OPCJA_NET_1_1385 -- ID
  140. * , '' as OPCJA_NET_1_459 -- P_CONTRACT_PRICE - abonament
  141. * -- , t4.P_NORMAL_PRICE * t0.P_DEALTERM_MONTHS - t4.P_DEAL_PROMO_MONTHS * t4.P_PROMO_MONTH_PRICE - (t0.P_DEALTERM_MONTHS - t4.P_DEAL_PROMO_MONTHS) * t4.P_CONTRACT_PRICE + (t4.P_INSTALL_QUOTE_NORMAL - t4.P_INSTALL_QUOTE) as `t4_1580`
  142. * , '' as OPCJA_NET_1_1580 -- upust od ceny nominalnej
  143. * , '' as OPCJA_NET_1_457 -- P_DEAL_PROMO_MONTHS - liczba miesiecy promocyjnych
  144. * , '' as OPCJA_NET_1_460 -- P_PROMO_MONTH_PRICE - cena abonamentu w promocyjnych miesiacach
  145. * , '' as OPCJA_NET_1_458 -- P_INSTALL_QUOTE - cena promocyjna
  146. */
  147. $options_to_load = array();
  148. foreach ($args['id_options'] as $k_service => $v_options) {
  149. if (empty($v_options)) continue;
  150. foreach ($v_options as $v_option_id) {
  151. if ($v_option_id > 0) {
  152. $options_to_load[$k_service] []= $v_option_id;
  153. }
  154. }
  155. }
  156. if (V::get('DBG', 0, $_GET, 'int')) {
  157. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">args: ';print_r($args);echo'</pre>';
  158. if (!empty($options_to_load)) {
  159. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">options_to_load: ';print_r($options_to_load);echo'</pre>';
  160. }
  161. }
  162. $sql_ids = array();
  163. foreach ($options_to_load as $k_service => $v_options_arr) {
  164. foreach ($v_options_arr as $v_offerr_id) {
  165. $sql_ids []= "'" . $v_offerr_id . "'";
  166. }
  167. }
  168. if (!empty($sql_ids)) {
  169. $options_to_load_counter = array();
  170. foreach ($options_to_load as $k_service => $v_arr) {
  171. $options_to_load_counter[$k_service] = 0;
  172. }
  173. $to_convert_encoding = array();
  174. $to_convert_encoding []= 'z_450';
  175. $oferty_opcje = array();
  176. $sql = "select
  177. t.`ID` as z_1385
  178. , t.`P_SERVICE` as `z_449`
  179. , t.`P_SERVICE_PARENT` as `z_3280`
  180. , t.`P_SERVICE_NAME` as z_450
  181. , t.`P_CONTRACT_PRICE` as z_459
  182. , '' as z_1580
  183. , t.`P_DEALTERM_MONTHS` as z_456
  184. , t.`P_DEAL_PROMO_MONTHS` as z_457
  185. , t.`P_PROMO_MONTH_PRICE` as z_460
  186. , t.`P_INSTALL_QUOTE` as z_458
  187. FROM `USERS2_OFFERS` as t
  188. WHERE
  189. t.`ID` in(" . implode(",", $sql_ids) . ")
  190. and t.`P_SERVICE`='OPCJE'
  191. -- t.`P_SERVICE_COMPANY`='BN'
  192. -- AND ( t.`A_STATUS` = 'NORMAL' OR t.`A_STATUS`='WAITING' )
  193. ";
  194. $res = DB::query($sql);
  195. while ($h = DB::fetch_assoc($res)) {
  196. //foreach ($to_convert_encoding as $v_field) {
  197. // if (array_key_exists($v_field, $h)) {
  198. // $h[$v_field] = iconv('latin2', 'utf-8', $h[$v_field]);
  199. // }
  200. //}
  201. $oferty_opcje[ $h['z_1385'] ] = $h;
  202. }
  203. if (V::get('DBG', 0, $_GET, 'int')) {echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">oferty_opcje: ';print_r($oferty_opcje);echo'</pre>';}
  204. $replace_fields = array();
  205. foreach ($oferty_opcje as $k_id => $h) {
  206. $cur_option_service = $h['z_3280'];
  207. if (!array_key_exists($cur_option_service, $options_to_load)) {
  208. // TODO: error
  209. continue;
  210. }
  211. $options_to_load_counter[$cur_option_service]++;
  212. $cur_option_index = $options_to_load_counter[$cur_option_service];
  213. $replace_key_prefix = 'OPCJA_' . $cur_option_service . '_' . $cur_option_index . '_';
  214. $replace_fields[$replace_key_prefix . '450'] = $h['z_450'];
  215. $replace_fields[$replace_key_prefix . '1385'] = $h['z_1385'];
  216. $replace_fields[$replace_key_prefix . '459'] = $h['z_459'];
  217. $replace_fields[$replace_key_prefix . '1580'] = $h['z_1580'];
  218. $replace_fields[$replace_key_prefix . '456'] = $h['z_456'];
  219. $replace_fields[$replace_key_prefix . '457'] = $h['z_457'];
  220. $replace_fields[$replace_key_prefix . '460'] = $h['z_460'];
  221. $replace_fields[$replace_key_prefix . '458'] = $h['z_458'];
  222. }
  223. if (V::get('DBG', 0, $_GET, 'int')) {echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">replace_fields: ';print_r($replace_fields);echo'</pre>';}
  224. if (!empty($replace_fields)) {
  225. $umowaOdt->add_data($replace_fields);
  226. }
  227. }
  228. }
  229. /*
  230. * <span id="cell-779"></span> - data
  231. */
  232. $replace_fields = array();
  233. $replace_fields['779'] = date('Y-m-d');
  234. $umowaOdt->add_data($replace_fields);
  235. if ($args['id_user'] > 0) {
  236. /*
  237. * <span id="cell-KLIENT_ID"></span>
  238. * <span id="cell-KLIENT_P_NAME"></span>
  239. * <span id="cell-KLIENT_P_NAME_SECOND"></span>
  240. * <span id="cell-KLIENT_P_PHONE"></span>
  241. * <span id="cell-KLIENT_user_mail_contact"></span>
  242. */
  243. if ($user) {
  244. $replace_fields = array();
  245. $replace_fields['KLIENT_ID'] = $user->ID_BILLING_USERS;
  246. $replace_fields['KLIENT_P_NAME'] = $user->P_NAME;//iconv('latin2', 'utf-8', $user->P_NAME);
  247. $replace_fields['KLIENT_P_NAME_SECOND'] = $user->P_NAME_SECOND;//iconv('latin2', 'utf-8', $user->P_NAME_SECOND);
  248. $replace_fields['KLIENT_P_PHONE'] = $user->P_PHONE;
  249. $replace_fields['KLIENT_user_mail_contact'] = $user->user_mail_contact;
  250. $umowaOdt->add_data($replace_fields);
  251. }
  252. }
  253. echo $umowaOdt->get_content();
  254. ?>