4138.opcje-rezygnacja.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. $umowaOdt = new ZasobFileOdt(4138, $druki_path, dirname(__FILE__));
  43. if (false == $umowaOdt->find_odt_file()) {
  44. die("Error: cant find file! [" . $umowaOdt->zasob_id . "]");
  45. }
  46. if (false == $umowaOdt->find_xsl_file()) {
  47. die("Template file not exists! - [" . $umowaOdt->zasob_id . "]");
  48. }
  49. if (V::get('test', 0, $_GET, 'int') == 1) {
  50. $odt_file_arr = explode('/', $umowaOdt->odt_file);
  51. array_pop($odt_file_arr);
  52. $umowaOdt->odt_file = implode('/', $odt_file_arr) . '/STARE/test.odt';
  53. }
  54. Lib::loadClass('Odt2xhtml');
  55. if (!class_exists('DOMDocument')) {
  56. die('require class DOMDocument');
  57. }
  58. if (!class_exists('XSLTProcessor')) {
  59. die('require class XSLTProcessor');
  60. }
  61. if (!function_exists('zip_open')) {
  62. die('NO ZIP FUNCTIONS DETECTED. Do you have the PECL ZIP extensions loaded?');
  63. }
  64. $conv = new Odt2xhtml;
  65. if ($umowaOdt->fetch_content_from_odt_by_converter($conv)) {
  66. die("Conversion odt to html error! - [" . $umowaOdt->zasob_id . "]");
  67. }
  68. // fetch data from DB
  69. $allowed_options = array('NET', 'TEL', 'TV', 'TVC');//, 'TVC', 'TVCP');
  70. $args = array();
  71. $args['id_user'] = V::get('id_user', 0, $_GET, 'int');
  72. $args['id_options'] = array();
  73. foreach ($allowed_options as $v_option) {
  74. $args['id_options'][$v_option] = V::get('id_options_' . $v_option . '', 0, $_GET, 'array');
  75. }
  76. if (!empty($args['id_options'])) {
  77. /*
  78. * <span id="cell-OPCJA_NET_1_450"></span>
  79. * <span id="cell-OPCJA_NET_1_1385"></span>
  80. * <span id="cell-OPCJA_NET_1_459"></span>
  81. * <span id="cell-OPCJA_NET_1_1580"></span>
  82. * <span id="cell-OPCJA_NET_1_457"></span>
  83. * <span id="cell-OPCJA_NET_1_460"></span>
  84. * <span id="cell-OPCJA_NET_1_458"></span>
  85. *
  86. * <span id="cell-OPCJA_TEL_1_450"></span>
  87. *
  88. * <span id="cell-OPCJA_TV_1_450"></span>
  89. *
  90. * , '' as OPCJA_NET_1_450 -- P_SERVICE_NAME - nazwa
  91. * , '' as OPCJA_NET_1_1385 -- ID
  92. * , '' as OPCJA_NET_1_459 -- P_CONTRACT_PRICE - abonament
  93. * -- , 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`
  94. * , '' as OPCJA_NET_1_1580 -- upust od ceny nominalnej
  95. * , '' as OPCJA_NET_1_457 -- P_DEAL_PROMO_MONTHS - liczba miesiecy promocyjnych
  96. * , '' as OPCJA_NET_1_460 -- P_PROMO_MONTH_PRICE - cena abonamentu w promocyjnych miesiacach
  97. * , '' as OPCJA_NET_1_458 -- P_INSTALL_QUOTE - cena promocyjna
  98. */
  99. $options_to_load = array();
  100. foreach ($args['id_options'] as $k_service => $v_options) {
  101. if (empty($v_options)) continue;
  102. foreach ($v_options as $v_option_id) {
  103. if ($v_option_id > 0) {
  104. $options_to_load[$k_service] []= $v_option_id;
  105. }
  106. }
  107. }
  108. if (V::get('DBG', 0, $_GET, 'int')) {
  109. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">args: ';print_r($args);echo'</pre>';
  110. if (!empty($options_to_load)) {
  111. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">options_to_load: ';print_r($options_to_load);echo'</pre>';
  112. }
  113. }
  114. $sql_ids = array();
  115. foreach ($options_to_load as $k_service => $v_options_arr) {
  116. foreach ($v_options_arr as $v_offerr_id) {
  117. $sql_ids []= "'" . $v_offerr_id . "'";
  118. }
  119. }
  120. if (!empty($sql_ids)) {
  121. $options_to_load_counter = array();
  122. foreach ($options_to_load as $k_service => $v_arr) {
  123. $options_to_load_counter[$k_service] = 0;
  124. }
  125. $to_convert_encoding = array();
  126. $to_convert_encoding []= 'z_450';
  127. $oferty_opcje = array();
  128. $sql = "select
  129. t.`ID` as z_1385
  130. , t.`P_SERVICE` as `z_449`
  131. , t.`P_SERVICE_PARENT` as `z_3280`
  132. , t.`P_SERVICE_NAME` as z_450
  133. , t.`P_CONTRACT_PRICE` as z_459
  134. , '' as z_1580
  135. , t.`P_DEALTERM_MONTHS` as z_456
  136. , t.`P_DEAL_PROMO_MONTHS` as z_457
  137. , t.`P_PROMO_MONTH_PRICE` as z_460
  138. , t.`P_INSTALL_QUOTE` as z_458
  139. FROM `USERS2_OFFERS` as t
  140. WHERE
  141. t.`ID` in(" . implode(",", $sql_ids) . ")
  142. and t.`P_SERVICE`='OPCJE'
  143. -- t.`P_SERVICE_COMPANY`='BN'
  144. -- AND ( t.`A_STATUS` = 'NORMAL' OR t.`A_STATUS`='WAITING' )
  145. ";
  146. $res = DB::query($sql);
  147. while ($h = DB::fetch_assoc($res)) {
  148. foreach ($to_convert_encoding as $v_field) {
  149. if (array_key_exists($v_field, $h)) {
  150. $h[$v_field] = iconv('latin2', 'utf-8', $h[$v_field]);
  151. }
  152. }
  153. $oferty_opcje[ $h['z_1385'] ] = $h;
  154. }
  155. 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>';}
  156. $replace_fields = array();
  157. foreach ($oferty_opcje as $k_id => $h) {
  158. $cur_option_service = $h['z_3280'];
  159. if (!array_key_exists($cur_option_service, $options_to_load)) {
  160. // TODO: error
  161. continue;
  162. }
  163. $options_to_load_counter[$cur_option_service]++;
  164. $cur_option_index = $options_to_load_counter[$cur_option_service];
  165. $replace_key_prefix = 'OPCJA_' . $cur_option_service . '_' . $cur_option_index . '_';
  166. $replace_fields[$replace_key_prefix . '450'] = $h['z_450'];
  167. $replace_fields[$replace_key_prefix . '1385'] = $h['z_1385'];
  168. $replace_fields[$replace_key_prefix . '459'] = $h['z_459'];
  169. $replace_fields[$replace_key_prefix . '1580'] = $h['z_1580'];
  170. $replace_fields[$replace_key_prefix . '456'] = $h['z_456'];
  171. $replace_fields[$replace_key_prefix . '457'] = $h['z_457'];
  172. $replace_fields[$replace_key_prefix . '460'] = $h['z_460'];
  173. $replace_fields[$replace_key_prefix . '458'] = $h['z_458'];
  174. }
  175. 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>';}
  176. if (!empty($replace_fields)) {
  177. $umowaOdt->add_data($replace_fields);
  178. }
  179. }
  180. }
  181. /*
  182. * <span id="cell-779"></span> - data
  183. */
  184. $replace_fields = array();
  185. $replace_fields['779'] = date('Y-m-d');
  186. $umowaOdt->add_data($replace_fields);
  187. if ($args['id_user'] > 0) {
  188. /*
  189. * <span id="cell-KLIENT_ID"></span>
  190. * <span id="cell-KLIENT_P_NAME"></span>
  191. * <span id="cell-KLIENT_P_NAME_SECOND"></span>
  192. * <span id="cell-KLIENT_P_PHONE"></span>
  193. * <span id="cell-KLIENT_user_mail_contact"></span>
  194. */
  195. $sql = "select bua.`id_users`
  196. , bua.`id_users` as ID_BILLING_USERS
  197. , bua.`is_firma`
  198. , bua.`P_NAME`
  199. , bua.`P_NAME_SECOND`
  200. , bua.`P_NIP`
  201. , bua.`P_PESEL`
  202. , bua.`P_PHONE`
  203. , bua.`P_ADDRESS_REGION`
  204. , bua.`P_ADDRESS_CITY`
  205. , bua.`P_ADDRESS_POST_CODE`
  206. , bua.`P_ADDRESS_STREET`
  207. , bua.`P_ADDRESS_HOME`
  208. , bua.`P_ADDRESS_HOUSE`
  209. , bua.`user_mail_contact`
  210. from `BILLING_USERS_ADD` as bua
  211. where bua.`id_users`='{$args['id_user']}'
  212. ";
  213. $res = DB::query($sql);
  214. if ($r = DB::fetch($res)) {
  215. $replace_fields = array();
  216. $replace_fields['KLIENT_ID'] = $r->ID_BILLING_USERS;
  217. $replace_fields['KLIENT_P_NAME'] = iconv('latin2', 'utf-8', $r->P_NAME);
  218. $replace_fields['KLIENT_P_NAME_SECOND'] = iconv('latin2', 'utf-8', $r->P_NAME_SECOND);
  219. $replace_fields['KLIENT_P_PHONE'] = $r->P_PHONE;
  220. $replace_fields['KLIENT_user_mail_contact'] = $r->user_mail_contact;
  221. $umowaOdt->add_data($replace_fields);
  222. }
  223. }
  224. echo $umowaOdt->get_content();
  225. ?>