superedit-USERS2_OFFERS_GROUPS.php 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  1. <?php
  2. if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
  3. if (!defined('APP_PATH_ROOT')) define('APP_PATH_ROOT', dirname(__FILE__));
  4. if (!defined('APP_PATH_WWW')) define('APP_PATH_WWW', dirname(__FILE__));
  5. if (!defined('APP_PATH_CONFIG')) define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
  6. /**
  7. * Module init.
  8. */
  9. function USERS2_OFFERS_GROUPS() {
  10. global $thiss;
  11. require_once dirname(__FILE__) . '/' . 'se-lib' . '/' . 'Lib.php';
  12. Lib::loadClass('V');
  13. Lib::loadClass('DB');
  14. // init columns if not set
  15. if (empty($_SESSION['USERS2_OFFERS_GROUPS' . "_COLUMN"]['ID'])) {
  16. SEF('USERS_COLUMN_INIT2');
  17. USERS_COLUMN_INIT2('USERS2_OFFERS_GROUPS', '', 'RWXC');
  18. }
  19. // router
  20. $task = V::get('task', '', $_REQUEST);
  21. $sub_task = V::get('sub_task', '', $_REQUEST);
  22. switch ($sub_task) {
  23. case 'GROUP_STATUS': {// POST: sub_task=GROUP_STATUS&group_id=
  24. USERS2_OFFERS_GROUPS_group_status();
  25. break;
  26. }
  27. case 'GROUP_WWW': {// POST: sub_task=GROUP_WWW&group_id=
  28. USERS2_OFFERS_GROUPS_group_www();
  29. break;
  30. }
  31. case 'GROUP_STATUS_ALL': {// POST: sub_task=GROUP_STATUS_ALL
  32. USERS2_OFFERS_GROUPS_group_status_all();
  33. break;
  34. }
  35. case 'GROUP_WWW_ALL': {// POST: sub_task=GROUP_WWW_ALL
  36. USERS2_OFFERS_GROUPS_group_www_all();
  37. break;
  38. }
  39. }
  40. $params = array();
  41. $params['toolbar'] = array();
  42. $params['toolbar'] []= '<a href="' . "?MENU_INIT=USERS2_OFFERS_GROUPS" . "&task=KONFIGURATOR" . '">' . "KONFIGURATOR" . '</a>';
  43. switch ($task) {
  44. case 'KONFIGURATOR': {
  45. USERS2_OFFERS_GROUPS_konfigurator();
  46. break;
  47. }
  48. case 'KONFIGURATOR2': {
  49. $subtask = V::get('subtask', '', $_REQUEST);
  50. switch ($subtask) {
  51. case 'ajax_save': {
  52. USERS2_OFFERS_GROUPS_konfigurator2_ajax_save();
  53. break;
  54. }
  55. case 'ajax_fltrs': {
  56. USERS2_OFFERS_GROUPS_konfigurator2_ajax_fltrs();
  57. break;
  58. }
  59. default:
  60. USERS2_OFFERS_GROUPS_konfigurator2();
  61. }
  62. break;
  63. }
  64. default:
  65. WIEVTABLE( $params );// TODO: redirect to index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=1614
  66. }
  67. }
  68. function USERS2_OFFERS_GROUPS_EDIT() {
  69. SEF('EDIT_TABLE_RECORD');
  70. EDIT_TABLE_RECORD();
  71. }
  72. function USERS2_OFFERS_GROUPS_HIST() {
  73. SEF('WIEVTABLE_HIST');
  74. WIEVTABLE_HIST();
  75. }
  76. function USERS2_OFFERS_GROUPS_group_status() {
  77. $group_id = V::get('group_id', '', $_REQUEST, 'int');
  78. $change = V::get('change', '', $_REQUEST);
  79. if ($change == '-') {
  80. $change = 'OFF_HARD';
  81. }
  82. else if ($change == '+') {
  83. $change = 'NORMAL';
  84. }
  85. if ($group_id <= 0 || !in_array($change, array('NORMAL', 'OFF_HARD'))) {
  86. return;
  87. }
  88. $db = DB::getDB();
  89. $sqlObj = new stdClass();
  90. $sqlObj->ID = $group_id;
  91. $sqlObj->A_STATUS = $change;
  92. $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $sqlObj);
  93. }
  94. function USERS2_OFFERS_GROUPS_group_www() {
  95. $group_id = V::get('group_id', '', $_REQUEST, 'int');
  96. $change = V::get('change', '', $_REQUEST);
  97. if ($change == '-') {
  98. $change = 'NIE';
  99. }
  100. else if ($change == '+') {
  101. $change = 'TAK';
  102. }
  103. if ($group_id <= 0 || !in_array($change, array('NIE', 'TAK'))) {
  104. return;
  105. }
  106. $db = DB::getDB();
  107. $sqlObj = new stdClass();
  108. $sqlObj->ID = $group_id;
  109. $sqlObj->OFERTA_WWW = $change;
  110. $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $sqlObj);
  111. }
  112. function USERS2_OFFERS_GROUPS_group_status_all() {
  113. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_POST);echo'</pre>';
  114. $change = V::get('change', '', $_REQUEST);
  115. $sqlChange = '';
  116. if ($change == '-') {
  117. $sqlChange = 'OFF_HARD';
  118. }
  119. else if ($change == '+') {
  120. $sqlChange = 'NORMAL';
  121. }
  122. if (!in_array($sqlChange, array('NORMAL', 'OFF_HARD'))) {
  123. return;
  124. }
  125. $filters = array();// sql field -> form field name
  126. $filters ['P_PROMOTION_NAME']= 'f_P_PROMOTION_NAME';
  127. $filters ['P_OFFER_TERM_BEGIN']= 'f_P_OFFER_TERM_BEGIN';
  128. $filters ['P_OFFER_TERM']= 'f_P_OFFER_TERM';
  129. $filters ['P_SERVICE_COMPANY']= 'f_P_SERVICE_COMPANY';
  130. $filters ['A_STATUS']= 'f_A_STATUS';
  131. $filters ['S_ADDRESS_STREET']= 'f_S_ADDRESS_STREET';
  132. $args = array();
  133. foreach ($filters as $k_field_name => $v_req_field_name) {
  134. $args[$k_field_name] = V::get($v_req_field_name, '%', $_REQUEST);
  135. }
  136. $filters_empty = true;
  137. foreach ($args as $k => $v_value) {
  138. if ($v_value != '%') {
  139. $filters_empty = false;
  140. }
  141. }
  142. if (!$filters_empty) {
  143. $items = array();
  144. $total = 0;
  145. $totalAll = Offers_Groups_Model::get_total($args);
  146. if ($totalAll > 0) {
  147. $items = Offers_Groups_Model::get_items($args);
  148. $params = Offers_Groups_Konfigurator_Model::get_params_from_items($items);
  149. // user selected params
  150. $user_params_empty = true;
  151. $user_params = array();
  152. foreach ($params as $k_type => $v_params) {
  153. if (empty($v_params)) continue;
  154. $k_field_name = "p_" . $k_type;// "[]"
  155. $user_params[$k_type] = V::get($k_field_name, null, $_GET, 'array');
  156. if (!empty($user_params[$k_type])) {
  157. $user_params_empty = false;
  158. }
  159. }
  160. $user_items = Offers_Groups_Konfigurator_Model::get_items_by_params($items, $user_params);
  161. $total = count($user_items);
  162. }
  163. echo '<p>' . "Do zmiany ({$total}) rekordów:";
  164. echo '<form action="" method="POST" style="display:inline">';
  165. echo '<input type="hidden" name="sub_task" value="GROUP_STATUS_ALL" />';
  166. foreach ($_POST as $k => $v) {
  167. if ($k == 'sub_task') continue;
  168. if ($k == 'confirm') continue;
  169. if ($k == 'change') continue;
  170. echo '<input type="hidden" name="'.$k.'" value="'.$v.'" />';
  171. }
  172. echo '<input type="hidden" name="confirm" value="YES" />';
  173. echo " Aktualizuj wszystkie zmiany";
  174. echo '<input type="submit" name="change" value="'.$change.'" />';
  175. echo '</form>';
  176. echo '</p>';
  177. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  178. if ($total > 0) {
  179. $db = DB::getDB();
  180. foreach ($user_items as $item) {
  181. $sqlObj = new stdClass();
  182. $sqlObj->ID = $item->ID;
  183. $sqlObj->A_STATUS = $sqlChange;
  184. echo "TODO: " . json_encode($sqlObj) . "...";
  185. if ('YES' == V::get('confirm', '', $_REQUEST)) {
  186. echo " TODO-SQL";
  187. if (false) {
  188. $ret = $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $sqlObj);
  189. if ($ret > 0) {
  190. echo " DONE ({$ret})";
  191. } else {
  192. echo " ERR";
  193. }
  194. }
  195. }
  196. echo "\n";
  197. }
  198. }
  199. echo'</pre>';
  200. }
  201. }
  202. function USERS2_OFFERS_GROUPS_group_www_all() {
  203. $change = V::get('change', '', $_REQUEST);
  204. $sqlChange = '';
  205. if ($change == '-') {
  206. $sqlChange = 'NIE';
  207. }
  208. else if ($change == '+') {
  209. $sqlChange = 'TAK';
  210. }
  211. if (!in_array($sqlChange, array('NIE', 'TAK'))) {
  212. return;
  213. }
  214. $filters = array();// sql field -> form field name
  215. $filters ['P_PROMOTION_NAME']= 'f_P_PROMOTION_NAME';
  216. $filters ['P_OFFER_TERM_BEGIN']= 'f_P_OFFER_TERM_BEGIN';
  217. $filters ['P_OFFER_TERM']= 'f_P_OFFER_TERM';
  218. $filters ['P_SERVICE_COMPANY']= 'f_P_SERVICE_COMPANY';
  219. $filters ['A_STATUS']= 'f_A_STATUS';
  220. $filters ['S_ADDRESS_STREET']= 'f_S_ADDRESS_STREET';
  221. $args = array();
  222. foreach ($filters as $k_field_name => $v_req_field_name) {
  223. $args[$k_field_name] = V::get($v_req_field_name, '%', $_REQUEST);
  224. }
  225. $filters_empty = true;
  226. foreach ($args as $k => $v_value) {
  227. if ($v_value != '%') {
  228. $filters_empty = false;
  229. }
  230. }
  231. if (!$filters_empty) {
  232. $items = array();
  233. $total = 0;
  234. $totalAll = Offers_Groups_Model::get_total($args);
  235. if ($totalAll > 0) {
  236. $items = Offers_Groups_Model::get_items($args);
  237. $params = Offers_Groups_Konfigurator_Model::get_params_from_items($items);
  238. // user selected params
  239. $user_params_empty = true;
  240. $user_params = array();
  241. foreach ($params as $k_type => $v_params) {
  242. if (empty($v_params)) continue;
  243. $k_field_name = "p_" . $k_type;// "[]"
  244. $user_params[$k_type] = V::get($k_field_name, null, $_GET, 'array');
  245. if (!empty($user_params[$k_type])) {
  246. $user_params_empty = false;
  247. }
  248. }
  249. $user_items = Offers_Groups_Konfigurator_Model::get_items_by_params($items, $user_params);
  250. $total = count($user_items);
  251. }
  252. echo '<p>' . "Do zmiany ({$total}) rekordów:";
  253. echo '<form action="" method="POST" style="display:inline">';
  254. echo '<input type="hidden" name="sub_task" value="GROUP_WWW_ALL" />';
  255. foreach ($_POST as $k => $v) {
  256. if ($k == 'sub_task') continue;
  257. if ($k == 'confirm') continue;
  258. if ($k == 'change') continue;
  259. echo '<input type="hidden" name="'.$k.'" value="'.$v.'" />';
  260. }
  261. echo '<input type="hidden" name="confirm" value="YES" />';
  262. echo " Aktualizuj wszystkie zmiany";
  263. echo '<input type="submit" name="change" value="'.$change.'" />';
  264. echo '</form>';
  265. echo '</p>';
  266. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  267. if ($total > 0) {
  268. $db = DB::getDB();
  269. foreach ($user_items as $item) {
  270. $sqlObj = new stdClass();
  271. $sqlObj->ID = $item->ID;
  272. $sqlObj->OFERTA_WWW = $sqlChange;
  273. echo "TODO: " . json_encode($sqlObj) . "...";
  274. if ('YES' == V::get('confirm', '', $_REQUEST)) {
  275. echo " TODO-SQL";
  276. if (false) {
  277. $ret = $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $sqlObj);
  278. if ($ret > 0) {
  279. echo " DONE ({$ret})";
  280. } else {
  281. echo " ERR";
  282. }
  283. }
  284. }
  285. echo "\n";
  286. }
  287. }
  288. echo'</pre>';
  289. }
  290. }
  291. function USERS2_OFFERS_GROUPS_konfigurator() {
  292. global $thiss;
  293. //echo '<a href="' . "?MENU_INIT=USERS2_OFFERS_GROUPS" . '">' . "USERS2_OFFERS_GROUPS" . '</a>';
  294. echo '<a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=1614">[1614] USERS2_OFFERS_GROUPS</a>';
  295. $filters = array();// sql field -> form field name
  296. $filters ['P_PROMOTION_NAME']= 'f_P_PROMOTION_NAME';
  297. $filters ['P_OFFER_TERM_BEGIN']= 'f_P_OFFER_TERM_BEGIN';
  298. $filters ['P_OFFER_TERM']= 'f_P_OFFER_TERM';
  299. $filters ['P_SERVICE_COMPANY']= 'f_P_SERVICE_COMPANY';
  300. $filters ['A_STATUS']= 'f_A_STATUS';
  301. $filters ['S_ADDRESS_STREET']= 'f_S_ADDRESS_STREET';
  302. $args = array();
  303. foreach ($filters as $k_field_name => $v_req_field_name) {
  304. $args[$k_field_name] = V::get($v_req_field_name, '%', $_REQUEST);
  305. }
  306. Offers_Groups_View::filters($filters, $args);
  307. $filters_empty = true;
  308. foreach ($args as $k => $v_value) {
  309. if ($v_value != '%') {
  310. $filters_empty = false;
  311. }
  312. }
  313. if ($filters_empty) {
  314. echo '<p class="red">' . "Wybierz parametry pakietów" . '</p>';
  315. } else {
  316. Offers_Groups_View::show_css();
  317. echo '<br />';
  318. echo '<dl class="t-collapse' . ((V::get('sub_task', '', $_REQUEST))? '' : ' t-collapse-hide') . '">';
  319. $items = array();
  320. $total = Offers_Groups_Model::get_total($args);
  321. if ($total > 0) {
  322. echo '<dt>' . "Znaleziono " . $total . " rekordów.";
  323. echo '<span class="add-show">' . " (+ ukryj)" . '</span>';
  324. echo '<span class="add-hidden">' . " (+ pokaż)" . '</span>';
  325. echo '</dt>';
  326. } else {
  327. echo '<dt class="red">' . "Nie znaleziono pakietów pasujących do podanych kryteriów." . '</dt>';
  328. }
  329. if ($total > 0) {
  330. echo '<dd>';
  331. $items = Offers_Groups_Model::get_items($args);
  332. Offers_Groups_View::items($items);
  333. echo '</dd>';
  334. }
  335. echo '</dl>';// .t-collapse
  336. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">items: ';print_r($items);echo'</pre>';
  337. $params = Offers_Groups_Konfigurator_Model::get_params_from_items($items);
  338. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">params: ';print_r($params);echo'</pre>';
  339. // user selected params
  340. $user_params_empty = true;
  341. $user_params = array();
  342. foreach ($params as $k_type => $v_params) {
  343. if (empty($v_params)) continue;
  344. $k_field_name = "p_" . $k_type;// "[]"
  345. $user_params[$k_type] = V::get($k_field_name, null, $_GET, 'array');
  346. if (!empty($user_params[$k_type])) {
  347. $user_params_empty = false;
  348. }
  349. }
  350. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$user_params: ';print_r($user_params);echo'</pre>';
  351. if (!$user_params_empty) {
  352. // tylko pakiety pasujące do wybranych parametrów
  353. }
  354. // konfigurator form
  355. echo '<form action="" method="get">';
  356. foreach ($filters as $k_field_name => $v_req_field_name) {
  357. $v_value = V::get($k_field_name, '', $args);
  358. if (!empty($v_value) && $v_value != '%') {
  359. echo '<input type="hidden" name="' . $v_req_field_name . '" value="' . $v_value .'" />';
  360. }
  361. }
  362. echo '<input type="hidden" name="' . "MENU_INIT" . '" value="' . "USERS2_OFFERS_GROUPS" .'" />';
  363. echo '<input type="hidden" name="' . "task" . '" value="' . "KONFIGURATOR" .'" />';
  364. echo '<table cellspacing="0" cellpadding="0" border="1" class="tbl-view tbl-top">';
  365. echo '<tr>';
  366. foreach ($params as $k_type => $v_params) {
  367. if (empty($v_params)) continue;
  368. echo '<th>' . $k_type . '</th>';
  369. }
  370. echo '</tr>';
  371. echo '<tr>';
  372. foreach ($params as $k_type => $v_params) {
  373. if (empty($v_params)) continue;
  374. echo '<td>';
  375. if ($k_type != 'TVCP') {
  376. $val = "BRAK";
  377. $k_field_name = "p_" . $k_type;
  378. $chkd = (!empty($user_params[$k_type]) && in_array($val, $user_params[$k_type]))? ' checked="checked"' : '';
  379. echo '<input type="radio" name="' . $k_field_name . '" value="' . $val . '" ' . $chkd . '/>';
  380. echo " " . $val . '<br />';
  381. }
  382. foreach ($v_params as $key => $val) {
  383. if ($k_type == 'TVCP') {
  384. $chkd = (!empty($user_params[$k_type]) && in_array($val, $user_params[$k_type]))? ' checked="checked"' : '';
  385. $k_field_name = "p_" . $k_type . "[]";
  386. echo '<input type="checkbox" name="' . $k_field_name . '" value="' . $val . '" ' . $chkd . '/>';
  387. } else {
  388. $chkd = (!empty($user_params[$k_type]) && in_array($val, $user_params[$k_type]))? ' checked="checked"' : '';
  389. $k_field_name = "p_" . $k_type;
  390. echo '<input type="radio" name="' . $k_field_name . '" value="' . $val . '" ' . $chkd . '/>';
  391. }
  392. echo " " . $val . '<br />';
  393. }
  394. echo '</td>';
  395. }
  396. echo '</tr>';
  397. echo '</table>';
  398. echo '<input type="submit" value="' . "Wyślij" . '" />';
  399. echo '</form>';
  400. if (!$user_params_empty) {
  401. // tylko pakiety pasujące do wybranych parametrów
  402. $user_items = Offers_Groups_Konfigurator_Model::get_items_by_params($items, $user_params);
  403. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$user_items: ';print_r($user_items);echo'</pre>';
  404. if (empty($user_items)) {
  405. echo '<p class="red">' . "Brak ofert pasujących do wybranych kryteriów." . '</p>';
  406. } else {
  407. echo '<br />' . "\n";
  408. echo '<dl class="t-collapse t-collapse-hide">';
  409. echo '<dt>' . "Oferty pasujące do wybranych kryteriów (" . count($user_items) . "):";
  410. echo '<span class="add-show">' . " (+ ukryj)" . '</span>';
  411. echo '<span class="add-hidden">' . " (+ pokaż)" . '</span>';
  412. echo '</dt>';
  413. echo '<dd>';
  414. Offers_Groups_View::items($user_items);
  415. echo '</dd>';
  416. echo '</dl>';
  417. }
  418. }
  419. Offers_Groups_View::show_js();
  420. }
  421. }
  422. function USERS2_OFFERS_GROUPS_konfigurator2() {
  423. $model = new Offers_Groups_Konfigurator2_Model();
  424. ?>
  425. <style type="text/css">
  426. .conf2 { width:100%; }
  427. .conf2 thead th { background:#eee; }
  428. .conf2-cnt { width:100%; table-layout:fixed; }
  429. .conf2-cnt thead th { background:#FFEFC6; font-size:10px; }
  430. .conf2-cnt tbody td { text-align:center; }
  431. .conf2-cnt tbody td,
  432. .conf2-cnt thead th { border:1px solid #eee; }
  433. .conf2-cnt tbody tr:hover td{ background:#eee; }
  434. .conf2-cnt thead > tr, .conf2-cnt tbody{ display:block; }
  435. .conf2-cnt thead > tr th, .conf2-cnt tbody td{ width:100px; }
  436. #conf2-cnt { height:300px; overflow:auto; }
  437. .conf2-fun { width:30px; }
  438. </style>
  439. <table class="conf2" id="conf2">
  440. <thead class="conf2-head">
  441. <tr>
  442. <th>Oferty Filtr</th>
  443. <td style="text-align:right">[4968] OD <input type="date" name="fltr_o_od" value="<?php echo $model->getCache('fltr_o_od'); ?>"></td>
  444. <td style="text-align:right">P SERVICE COMPANY <input type="text" name="fltr_COM" value="<?php echo $model->getCache('fltr_COM', 'BN'); ?>"></td>
  445. <!-- <td style="text-align:right">[4968] DO <input type="date" name="fltr_o_do" value=""></td> -->
  446. <td><button name="refresh">odśwież</button></td>
  447. </tr>
  448. <tr>
  449. <th>
  450. Pakiety
  451. Filtr / Dodaj
  452. </th>
  453. <td style="text-align:right">
  454. [1615] S ALIAS <input type="text" name="fltr_p_1615" value="<?php echo $model->getCache('fltr_p_1615'); ?>"><br>
  455. [1616] P PROMOTION NAME <input type="text" name="fltr_p_1616" value="<?php echo $model->getCache('fltr_p_1616'); ?>"><br>
  456. [1617] P DEALTERM MONTHS <input type="text" name="fltr_p_1617" value="<?php echo $model->getCache('fltr_p_1617'); ?>">
  457. </td>
  458. <td style="text-align:right">
  459. [1618] P OFFER TERM BEGIN <input type="text" name="fltr_p_1618" value="<?php echo $model->getCache('fltr_p_1618'); ?>"><br>
  460. [1619] P OFFER TERM <input type="text" name="fltr_p_1619" value="<?php echo $model->getCache('fltr_p_1619'); ?>"><br>
  461. [1627] M REWIR <input type="text" name="fltr_p_1627" value="<?php echo $model->getCache('fltr_p_1627'); ?>">
  462. </td>
  463. <td></td>
  464. </tr>
  465. </thead>
  466. <tbody>
  467. <tr>
  468. <td colspan="4">
  469. <table class="conf2-cnt">
  470. <thead>
  471. <tr id="conf2-cnt-services">
  472. <td class="conf2-fun">&nbsp;</td>
  473. <th>12Mb/s</th>
  474. <th>50Mb/s</th>
  475. <th>100Mb/s</th>
  476. <th>150Mb/s</th>
  477. <th>TV1</th>
  478. <th>TV2</th>
  479. <th>TV3</th>
  480. <th>TV4</th>
  481. <th>TEL1</th>
  482. <th>TEL2</th>
  483. <th>TEL3</th>
  484. <th>TEL4</th>
  485. </tr>
  486. </thead>
  487. <tbody id="conf2-cnt">
  488. <tr>
  489. <th class="conf2-fun">&nbsp;</th>
  490. <td>12Mb/s</td>
  491. <td>50Mb/s</td>
  492. <td>100Mb/s</td>
  493. <td>150Mb/s</td>
  494. <td>TV1</td>
  495. <td>TV2</td>
  496. <td>TV3</td>
  497. <td>TV4</td>
  498. <td>TEL1</td>
  499. <td>TEL2</td>
  500. <td>TEL3</td>
  501. <td>TEL4</td>
  502. </tr>
  503. <tr>
  504. <th class="conf2-fun">&nbsp;</th>
  505. <td>12Mb/s</td>
  506. <td>50Mb/s</td>
  507. <td>100Mb/s</td>
  508. <td>150Mb/s</td>
  509. <td>TV1</td>
  510. <td>TV2</td>
  511. <td>TV3</td>
  512. <td>TV4</td>
  513. <td>TEL1</td>
  514. <td>TEL2</td>
  515. <td>TEL3</td>
  516. <td>TEL4</td>
  517. </tr>
  518. <tr>
  519. <th class="conf2-fun">&nbsp;</th>
  520. <td>12Mb/s</td>
  521. <td>50Mb/s</td>
  522. <td>100Mb/s</td>
  523. <td>150Mb/s</td>
  524. <td>TV1</td>
  525. <td>TV2</td>
  526. <td>TV3</td>
  527. <td>TV4</td>
  528. <td>TEL1</td>
  529. <td>TEL2</td>
  530. <td>TEL3</td>
  531. <td>TEL4</td>
  532. </tr>
  533. <tr>
  534. <th class="conf2-fun">&nbsp;</th>
  535. <td>12Mb/s</td>
  536. <td>50Mb/s</td>
  537. <td>100Mb/s</td>
  538. <td>150Mb/s</td>
  539. <td>TV1</td>
  540. <td>TV2</td>
  541. <td>TV3</td>
  542. <td>TV4</td>
  543. <td>TEL1</td>
  544. <td>TEL2</td>
  545. <td>TEL3</td>
  546. <td>TEL4</td>
  547. </tr>
  548. <tr>
  549. <th class="conf2-fun">&nbsp;</th>
  550. <td>12Mb/s</td>
  551. <td>50Mb/s</td>
  552. <td>100Mb/s</td>
  553. <td>150Mb/s</td>
  554. <td>TV1</td>
  555. <td>TV2</td>
  556. <td>TV3</td>
  557. <td>TV4</td>
  558. <td>TEL1</td>
  559. <td>TEL2</td>
  560. <td>TEL3</td>
  561. <td>TEL4</td>
  562. </tr>
  563. <tr>
  564. <th class="conf2-fun">&nbsp;</th>
  565. <td>12Mb/s</td>
  566. <td>50Mb/s</td>
  567. <td>100Mb/s</td>
  568. <td>150Mb/s</td>
  569. <td>TV1</td>
  570. <td>TV2</td>
  571. <td>TV3</td>
  572. <td>TV4</td>
  573. <td>TEL1</td>
  574. <td>TEL2</td>
  575. <td>TEL3</td>
  576. <td>TEL4</td>
  577. </tr>
  578. <tr>
  579. <th class="conf2-fun">&nbsp;</th>
  580. <td>12Mb/s</td>
  581. <td>50Mb/s</td>
  582. <td>100Mb/s</td>
  583. <td>150Mb/s</td>
  584. <td>TV1</td>
  585. <td>TV2</td>
  586. <td>TV3</td>
  587. <td>TV4</td>
  588. <td>TEL1</td>
  589. <td>TEL2</td>
  590. <td>TEL3</td>
  591. <td>TEL4</td>
  592. </tr>
  593. <tr>
  594. <th class="conf2-fun">&nbsp;</th>
  595. <td>12Mb/s</td>
  596. <td>50Mb/s</td>
  597. <td>100Mb/s</td>
  598. <td>150Mb/s</td>
  599. <td>TV1</td>
  600. <td>TV2</td>
  601. <td>TV3</td>
  602. <td>TV4</td>
  603. <td>TEL1</td>
  604. <td>TEL2</td>
  605. <td>TEL3</td>
  606. <td>TEL4</td>
  607. </tr>
  608. <tr>
  609. <th class="conf2-fun">&nbsp;</th>
  610. <td>12Mb/s</td>
  611. <td>50Mb/s</td>
  612. <td>100Mb/s</td>
  613. <td>150Mb/s</td>
  614. <td>TV1</td>
  615. <td>TV2</td>
  616. <td>TV3</td>
  617. <td>TV4</td>
  618. <td>TEL1</td>
  619. <td>TEL2</td>
  620. <td>TEL3</td>
  621. <td>TEL4</td>
  622. </tr>
  623. <tr>
  624. <th class="conf2-fun">&nbsp;</th>
  625. <td>12Mb/s</td>
  626. <td>50Mb/s</td>
  627. <td>100Mb/s</td>
  628. <td>150Mb/s</td>
  629. <td>TV1</td>
  630. <td>TV2</td>
  631. <td>TV3</td>
  632. <td>TV4</td>
  633. <td>TEL1</td>
  634. <td>TEL2</td>
  635. <td>TEL3</td>
  636. <td>TEL4</td>
  637. </tr>
  638. <tr>
  639. <th class="conf2-fun">&nbsp;</th>
  640. <td>12Mb/s</td>
  641. <td>50Mb/s</td>
  642. <td>100Mb/s</td>
  643. <td>150Mb/s</td>
  644. <td>TV1</td>
  645. <td>TV2</td>
  646. <td>TV3</td>
  647. <td>TV4</td>
  648. <td>TEL1</td>
  649. <td>TEL2</td>
  650. <td>TEL3</td>
  651. <td>TEL4</td>
  652. </tr>
  653. <tr>
  654. <th class="conf2-fun">&nbsp;</th>
  655. <td>12Mb/s</td>
  656. <td>50Mb/s</td>
  657. <td>100Mb/s</td>
  658. <td>150Mb/s</td>
  659. <td>TV1</td>
  660. <td>TV2</td>
  661. <td>TV3</td>
  662. <td>TV4</td>
  663. <td>TEL1</td>
  664. <td>TEL2</td>
  665. <td>TEL3</td>
  666. <td>TEL4</td>
  667. </tr>
  668. <tr>
  669. <th class="conf2-fun">&nbsp;</th>
  670. <td>12Mb/s</td>
  671. <td>50Mb/s</td>
  672. <td>100Mb/s</td>
  673. <td>150Mb/s</td>
  674. <td>TV1</td>
  675. <td>TV2</td>
  676. <td>TV3</td>
  677. <td>TV4</td>
  678. <td>TEL1</td>
  679. <td>TEL2</td>
  680. <td>TEL3</td>
  681. <td>TEL4</td>
  682. </tr>
  683. <tr>
  684. <th class="conf2-fun">&nbsp;</th>
  685. <td>12Mb/s</td>
  686. <td>50Mb/s</td>
  687. <td>100Mb/s</td>
  688. <td>150Mb/s</td>
  689. <td>TV1</td>
  690. <td>TV2</td>
  691. <td>TV3</td>
  692. <td>TV4</td>
  693. <td>TEL1</td>
  694. <td>TEL2</td>
  695. <td>TEL3</td>
  696. <td>TEL4</td>
  697. </tr>
  698. <tr>
  699. <th class="conf2-fun">&nbsp;</th>
  700. <td>12Mb/s</td>
  701. <td>50Mb/s</td>
  702. <td>100Mb/s</td>
  703. <td>150Mb/s</td>
  704. <td>TV1</td>
  705. <td>TV2</td>
  706. <td>TV3</td>
  707. <td>TV4</td>
  708. <td>TEL1</td>
  709. <td>TEL2</td>
  710. <td>TEL3</td>
  711. <td>TEL4</td>
  712. </tr>
  713. <tr>
  714. <th class="conf2-fun">&nbsp;</th>
  715. <td>12Mb/s</td>
  716. <td>50Mb/s</td>
  717. <td>100Mb/s</td>
  718. <td>150Mb/s</td>
  719. <td>TV1</td>
  720. <td>TV2</td>
  721. <td>TV3</td>
  722. <td>TV4</td>
  723. <td>TEL1</td>
  724. <td>TEL2</td>
  725. <td>TEL3</td>
  726. <td>TEL4</td>
  727. </tr>
  728. <tr>
  729. <th class="conf2-fun">&nbsp;</th>
  730. <td>12Mb/s</td>
  731. <td>50Mb/s</td>
  732. <td>100Mb/s</td>
  733. <td>150Mb/s</td>
  734. <td>TV1</td>
  735. <td>TV2</td>
  736. <td>TV3</td>
  737. <td>TV4</td>
  738. <td>TEL1</td>
  739. <td>TEL2</td>
  740. <td>TEL3</td>
  741. <td>TEL4</td>
  742. </tr>
  743. <tr>
  744. <th class="conf2-fun">&nbsp;</th>
  745. <td>12Mb/s</td>
  746. <td>50Mb/s</td>
  747. <td>100Mb/s</td>
  748. <td>150Mb/s</td>
  749. <td>TV1</td>
  750. <td>TV2</td>
  751. <td>TV3</td>
  752. <td>TV4</td>
  753. <td>TEL1</td>
  754. <td>TEL2</td>
  755. <td>TEL3</td>
  756. <td>TEL4</td>
  757. </tr>
  758. <tr>
  759. <th class="conf2-fun">&nbsp;</th>
  760. <td>12Mb/s</td>
  761. <td>50Mb/s</td>
  762. <td>100Mb/s</td>
  763. <td>150Mb/s</td>
  764. <td>TV1</td>
  765. <td>TV2</td>
  766. <td>TV3</td>
  767. <td>TV4</td>
  768. <td>TEL1</td>
  769. <td>TEL2</td>
  770. <td>TEL3</td>
  771. <td>TEL4</td>
  772. </tr>
  773. <tr>
  774. <th class="conf2-fun">&nbsp;</th>
  775. <td>12Mb/s</td>
  776. <td>50Mb/s</td>
  777. <td>100Mb/s</td>
  778. <td>150Mb/s</td>
  779. <td>TV1</td>
  780. <td>TV2</td>
  781. <td>TV3</td>
  782. <td>TV4</td>
  783. <td>TEL1</td>
  784. <td>TEL2</td>
  785. <td>TEL3</td>
  786. <td>TEL4</td>
  787. </tr>
  788. <tr>
  789. <th class="conf2-fun">&nbsp;</th>
  790. <td>12Mb/s</td>
  791. <td>50Mb/s</td>
  792. <td>100Mb/s</td>
  793. <td>150Mb/s</td>
  794. <td>TV1</td>
  795. <td>TV2</td>
  796. <td>TV3</td>
  797. <td>TV4</td>
  798. <td>TEL1</td>
  799. <td>TEL2</td>
  800. <td>TEL3</td>
  801. <td>TEL4</td>
  802. </tr>
  803. </tbody>
  804. </table>
  805. </td>
  806. </tr>
  807. </tbody>
  808. </table>
  809. <table cellspacing="0" cellpadding="0" border="1">
  810. <thead>
  811. <tr colspan="99"><a href="#" id="dbg-offers-filter_toggle">Oferty pasujące do filtra <b id="dbg-offers-filter_total"></b></a></tr>
  812. </thead>
  813. <tbody id="dbg-offers-filter" style="display:none;">
  814. </tbody>
  815. </table>
  816. <table cellspacing="0" cellpadding="0" border="1">
  817. <thead>
  818. <tr colspan="99"><a href="#" id="dbg-groups-filter_toggle">Grupy pasujące do filtra <b id="dbg-groups-filter_total"></b></a></tr>
  819. </thead>
  820. <tbody id="dbg-groups-filter" style="display:none;">
  821. </tbody>
  822. </table>
  823. <div id="conf2-Modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  824. <form action="" id="conf2-modal-frm" class="form-horizontal">
  825. <div class="modal-header">
  826. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  827. <h3 id="myModalLabel">Grupa ofert</h3>
  828. </div>
  829. <div class="modal-body">
  830. <input type="hidden" name="f_ID" value="">
  831. <div class="control-group">
  832. <label for="f_COM" class="control-label">P SERVICE COMPANY </label>
  833. <div class="controls">
  834. <input type="text" name="f_COM" value="<?php echo $model->getCache('fltr_COM', 'BN'); ?>">
  835. </div>
  836. </div>
  837. <div class="control-group">
  838. <label for="f_S_ALIAS" class="control-label">[1615] S ALIAS </label>
  839. <div class="controls">
  840. <input type="text" name="f_S_ALIAS" value="<?php echo $model->getCache('fltr_p_1615'); ?>">
  841. </div>
  842. </div>
  843. <div class="control-group">
  844. <label for="f_P_PROMOTION_NAME" class="control-label">[1616] P PROMOTION NAME </label>
  845. <div class="controls">
  846. <input type="text" name="f_P_PROMOTION_NAME" value="<?php echo $model->getCache('fltr_p_1616'); ?>">
  847. </div>
  848. </div>
  849. <div class="control-group">
  850. <label for="f_P_DEALTERM_MONTHS" class="control-label">[1617] P DEALTERM MONTHS </label>
  851. <div class="controls">
  852. <input type="text" name="f_P_DEALTERM_MONTHS" value="<?php echo $model->getCache('fltr_p_1617'); ?>">
  853. </div>
  854. </div>
  855. <div class="control-group">
  856. <label for="f_P_OFFER_TERM_BEGIN" class="control-label">[1618] P OFFER TERM BEGIN </label>
  857. <div class="controls">
  858. <input type="text" name="f_P_OFFER_TERM_BEGIN" value="<?php echo $model->getCache('fltr_p_1618'); ?>">
  859. </div>
  860. </div>
  861. <div class="control-group">
  862. <label for="f_P_OFFER_TERM" class="control-label">[1619] P OFFER TERM </label>
  863. <div class="controls">
  864. <input type="text" name="f_P_OFFER_TERM" value="<?php echo $model->getCache('fltr_p_1619'); ?>">
  865. </div>
  866. </div>
  867. <div class="control-group">
  868. <label for="f_M_REWIR" class="control-label">[1627] M REWIR </label>
  869. <div class="controls">
  870. <input type="text" name="f_M_REWIR" value="<?php echo $model->getCache('fltr_p_1627'); ?>">
  871. </div>
  872. </div>
  873. <div class="control-group">
  874. <label for="f_ID_NET" class="control-label">[1743] ID_NET </label>
  875. <div class="controls">
  876. <select name="f_ID_NET"></select>
  877. </div>
  878. </div>
  879. <div class="control-group">
  880. <label for="f_ID_TV" class="control-label">[1744] ID_TV </label>
  881. <div class="controls">
  882. <select name="f_ID_TV"></select>
  883. </div>
  884. </div>
  885. <div class="control-group">
  886. <label for="f_ID_TVC" class="control-label">[1745] ID_TVC </label>
  887. <div class="controls">
  888. <select name="f_ID_TVC"></select>
  889. </div>
  890. </div>
  891. <div class="control-group">
  892. <label for="f_ID_TEL" class="control-label">[1747] ID_TEL </label>
  893. <div class="controls">
  894. <select name="f_ID_TEL"></select>
  895. </div>
  896. </div>
  897. </div>
  898. <div class="modal-footer">
  899. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  900. <button class="btn btn-primary" class="btn-save">Zapisz/Dodaj</button>
  901. </div>
  902. </form>
  903. </div>
  904. <script>
  905. var Konfigurator2 = {
  906. groups_sorted: [],
  907. groups: [],
  908. services: [],
  909. srv_offer_ids: [],
  910. offers: [],
  911. editInd: 0,
  912. editModal: function(ind) {
  913. var $modal = jQuery('#conf2-Modal'),
  914. $frm = jQuery('#conf2-modal-frm'),
  915. group = null;
  916. this.editInd = ind;
  917. console.log('conf2-Modal show', this.groups_sorted[ind]);
  918. if (this.groups_sorted[ind]['gID']) {
  919. group = this.groups[this.groups_sorted[ind]['gID']];
  920. }
  921. $frm.find("[name='f_ID']").val('');
  922. if (group) {
  923. $frm.find("[name='f_ID']").val(group['ID']);
  924. $frm.find("[name='f_COM']").val(group['P_SERVICE_COMPANY']);
  925. $frm.find("[name='f_S_ALIAS']").val(group['S_ALIAS']);
  926. $frm.find("[name='f_P_PROMOTION_NAME']").val(group['P_PROMOTION_NAME']);
  927. $frm.find("[name='f_M_REWIR']").val(group['M_REWIR']);
  928. $frm.find("[name='f_P_DEALTERM_MONTHS']").val(group['P_DEALTERM_MONTHS']);
  929. $frm.find("[name='f_P_OFFER_TERM']").val(group['P_OFFER_TERM']);
  930. $frm.find("[name='f_P_OFFER_TERM_BEGIN']").val(group['P_OFFER_TERM_BEGIN']);
  931. } else {
  932. var Conf2 = jQuery('#conf2');
  933. $frm.find("[name='f_COM']").val(Conf2.find("[name='fltr_COM']").val());
  934. $frm.find("[name='f_S_ALIAS']").val(Conf2.find("[name='fltr_p_1615']").val());
  935. $frm.find("[name='f_P_PROMOTION_NAME']").val(Conf2.find("[name='fltr_p_1616']").val());
  936. $frm.find("[name='f_M_REWIR']").val(Conf2.find("[name='fltr_p_1627']").val());
  937. $frm.find("[name='f_P_DEALTERM_MONTHS']").val(Conf2.find("[name='fltr_p_1617']").val());
  938. $frm.find("[name='f_P_OFFER_TERM']").val(Conf2.find("[name='fltr_p_1619']").val());
  939. $frm.find("[name='f_P_OFFER_TERM_BEGIN']").val(Conf2.find("[name='fltr_p_1618']").val());
  940. }
  941. console.log('conf2-Modal this.srv_offer_ids', this.srv_offer_ids);
  942. for (var s in this.services) {// s: NET, TV, TVC, TEL
  943. var fName = 'f_ID_' + s,
  944. $fld = $frm.find("[name='" + fName + "']");
  945. $fld.find('option').remove();
  946. if (s in this.groups_sorted[ind]['_params']) {
  947. var srvVal = this.groups_sorted[ind]['_params'][s];
  948. $fld.val('TEST: ' + srvVal);
  949. for (var i in this.srv_offer_ids[s][srvVal]) {
  950. var oID = this.srv_offer_ids[s][srvVal][i];
  951. var o = this.offers[oID];
  952. var oLabel = '[' + o.ID + '] ' + o.P_PROMO_MONTH_PRICE + '/' + o.P_CONTRACT_PRICE;
  953. var sel = '';
  954. if (group) {
  955. if (group['ID_' + s] > 0 && group['ID_' + s] == oID) {
  956. sel = ' selected="selected"';
  957. }
  958. }
  959. $fld.append('<option value="' + oID + '"' + sel + '>' + oLabel + '</option>');
  960. }
  961. } else {
  962. $fld.append('<option value="0">0</option>');
  963. }
  964. }
  965. $modal.find('.modal-body');
  966. //.html(this.groups_sorted[ind]);
  967. $modal.modal('show');
  968. return false;
  969. },
  970. saveModal: function(evt) {
  971. var $frm = jQuery('#conf2-modal-frm'),
  972. params = $frm.serialize();
  973. console.log('conf2-Modal saveModal', this.groups_sorted[this.editInd], ' frm: ', params);
  974. $.ajax({
  975. url: 'index.php?FUNCTION_INIT=USERS2_OFFERS_GROUPS&HEADER_NOT_INIT=YES&task=KONFIGURATOR2&subtask=ajax_save',
  976. type: 'POST',
  977. dataType: 'json',
  978. data: params,
  979. async: true,
  980. success: function (data) {
  981. console.log('save data: ', data);
  982. var Conf2 = jQuery('#conf2');
  983. Konfigurator2.refresh(Conf2, evt);
  984. },
  985. error: function (err) {
  986. console.log('err');
  987. }
  988. });
  989. return false;
  990. },
  991. find_group_id: function(params, dbg) {
  992. var groupID = null,
  993. paramsTotal = 0,
  994. services = ['NET','TV','TVC','TEL'],
  995. dbg = dbg || false;
  996. for (var i in params) {
  997. paramsTotal++;
  998. }
  999. var dbg_limit = 2;
  1000. for (var g in this.groups) {
  1001. var paramsCmp = 0;
  1002. for (var srv in this.services) {
  1003. if (!this.groups[g]['_params']) continue;
  1004. //if(dbg_limit--){console.log('find_group_id, srv(',srv,') paramsTotal:', paramsTotal, ', params:', params, ', 1:', (srv in this.groups[g]['_params']), ', 2:', (srv in params), ', 3:', params[srv], ' == ', this.groups[g]['_params'][srv]);}
  1005. if (srv in this.groups[g]['_params']) {
  1006. if (srv in params) {
  1007. if (params[srv] == this.groups[g]['_params'][srv]) {
  1008. paramsCmp++;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. if (paramsCmp == paramsTotal) {
  1014. groupID = this.groups[g]['ID'];
  1015. }
  1016. }
  1017. return groupID;
  1018. },
  1019. sort_groups: function() {
  1020. this.groups_sorted = [];// all combinations
  1021. //for (var g in this.groups) this.groups_sorted[g] = this.groups[g];
  1022. var ind = 90000;
  1023. //console.log('services: ', this.services);
  1024. for (var s in this.services) {
  1025. for (var p in this.services[s]) {
  1026. var group = {_params:{}, gID:null};
  1027. group['_params'][s] = this.services[s][p];
  1028. console.log('group add: ', group);
  1029. this.groups_sorted[ind++] = group;
  1030. }
  1031. }
  1032. // pakiety 2w1
  1033. for (var s in this.services) {
  1034. for (var p in this.services[s]) {
  1035. for (var s2 in this.services) {
  1036. if (s2 == s) continue;
  1037. if (s2 == 'TVC' && s == 'TV') continue;
  1038. if (s2 == 'TV' && s == 'TVC') continue;
  1039. for (var p2 in this.services[s2]) {
  1040. var group = {_params:{}, gID:null};
  1041. group['_params'][s] = this.services[s][p];
  1042. group['_params'][s2] = this.services[s2][p2];
  1043. group['gID'] = this.find_group_id(group['_params']);
  1044. this.groups_sorted[ind++] = group;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. // pakiety 3w1
  1050. for (var s in this.services) {
  1051. for (var p in this.services[s]) {
  1052. var lastS = s;
  1053. for (var s2 in this.services) {
  1054. if (lastS == s2) {
  1055. lastS = true;
  1056. continue;
  1057. }
  1058. if (lastS !== true) continue;
  1059. if (s2 == s) continue;
  1060. if (s2 == 'TVC' && s == 'TV') continue;
  1061. if (s2 == 'TV' && s == 'TVC') continue;
  1062. for (var p2 in this.services[s2]) {
  1063. var lastS2 = s2;
  1064. for (var s3 in this.services) {
  1065. if (lastS2 == s3) {
  1066. lastS2 = true;
  1067. continue;
  1068. }
  1069. if (lastS2 !== true) continue;
  1070. if (s3 == s) continue;
  1071. if (s3 == s2) continue;
  1072. if (s3 == 'TV' && (s == 'TVC' || s2 == 'TVC')) continue;
  1073. if (s3 == 'TVC' && (s == 'TV' || s2 == 'TV')) continue;
  1074. for (var p3 in this.services[s3]) {
  1075. var group = {_params:{}, gID:null};
  1076. group['_params'][s] = this.services[s][p];
  1077. group['_params'][s2] = this.services[s2][p2];
  1078. group['_params'][s3] = this.services[s3][p3];
  1079. group['gID'] = this.find_group_id(group['_params']);
  1080. console.log('group 3w1 add: (',s,',',s2,',',s3,') ', group);
  1081. this.groups_sorted[ind++] = group;
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. return this.groups_sorted;
  1089. },
  1090. refresh: function(Conf2, evt){
  1091. console.log('TODO: update filters dbg-offers-filter, dbg-groups-filter ... evt:', evt);
  1092. jQuery('#dbg-offers-filter')
  1093. var params = {};
  1094. params['fltr_o_od'] = Conf2.find("input[name='fltr_o_od']").val();
  1095. params['fltr_COM'] = Conf2.find("input[name='fltr_COM']").val();
  1096. //params['fltr_o_do'] = Conf2.find("input[name='fltr_o_do']").val();
  1097. params['fltr_p_1615'] = Conf2.find("input[name='fltr_p_1615']").val();
  1098. params['fltr_p_1616'] = Conf2.find("input[name='fltr_p_1616']").val();
  1099. params['fltr_p_1617'] = Conf2.find("input[name='fltr_p_1617']").val();
  1100. params['fltr_p_1618'] = Conf2.find("input[name='fltr_p_1618']").val();
  1101. params['fltr_p_1619'] = Conf2.find("input[name='fltr_p_1619']").val();
  1102. params['fltr_p_1627'] = Conf2.find("input[name='fltr_p_1627']").val();
  1103. console.log('TODO: params: ', params);
  1104. // 4968 KOMORKA A_RECORD_CREATE_DATE
  1105. $.ajax({
  1106. url: 'index.php?FUNCTION_INIT=USERS2_OFFERS_GROUPS&HEADER_NOT_INIT=YES&task=KONFIGURATOR2&subtask=ajax_fltrs',
  1107. type: 'GET',
  1108. dataType: 'json',
  1109. data: params,
  1110. async: true,
  1111. success: function (data) {
  1112. //console.log('data: ', data);
  1113. var out_offers_total = 0, out_groups_total = 0
  1114. , out_offers = '', out_groups = ''
  1115. , out_cnt = '', out_services = '';
  1116. if (data.offers) {
  1117. for (var i in data.offers) {
  1118. out_offers_total += 1;
  1119. out_offers += '<tr>' +
  1120. '<td>' + data.offers[i]['ID'] + '</td>' +
  1121. '<td>' + data.offers[i]['P_NAME'] + '</td>' +
  1122. '<td>' + data.offers[i]['P_SERVICE_NAME'] + '</td>' +
  1123. '<td>' + data.offers[i]['P_S_PARAM1'] + '</td>' +
  1124. '<td>' + data.offers[i]['P_INSTALL_QUOTE'] + '</td>' +
  1125. '<td>' + data.offers[i]['P_CONTRACT_PRICE'] + '</td>' +
  1126. '<td>' + data.offers[i]['P_PROMO_MONTH_PRICE'] + '</td>' +
  1127. '<td>' + data.offers[i]['P_NORMAL_PRICE'] + '</td>' +
  1128. '</tr>';
  1129. }
  1130. }
  1131. for (var i in data.groups) {
  1132. out_groups_total += 1;
  1133. out_groups += '<tr>' +
  1134. '<td>' + data.groups[i]['ID'] + '</td>' +
  1135. '<td>' + data.groups[i]['ID_TEL'] + '</td>' +
  1136. '<td>' + data.groups[i]['ID_TV'] + '</td>' +
  1137. '<td>' + data.groups[i]['ID_TVC'] + '</td>' +
  1138. '<td>' + data.groups[i]['ID_TEL'] + '</td>' +
  1139. '<td>' + data.groups[i]['S_ALIAS'] + '</td>' +
  1140. '<td>' + data.groups[i]['P_PROMOTION_NAME'] + '</td>' +
  1141. '<td>' + data.groups[i]['P_DEALTERM_MONTHS'] + '</td>' +
  1142. '<td>' + data.groups[i]['P_OFFER_TERM_BEGIN'] + '</td>' +
  1143. '<td>' + data.groups[i]['P_OFFER_TERM'] + '</td>' +
  1144. '<td>' + data.groups[i]['M_REWIR'] + '</td>' +
  1145. '</tr>';
  1146. }
  1147. if (data.services) {
  1148. out_services += '<td class="conf2-fun">&nbsp;</td>';
  1149. for (var j in data.services) {
  1150. for (var k in data.services[j]) {
  1151. out_services += '<th>' + data.services[j][k] + '</th>';
  1152. }
  1153. }
  1154. }
  1155. Konfigurator2.groups = data.groups;
  1156. Konfigurator2.services = data.services;
  1157. Konfigurator2.srv_offer_ids = data.srv_offer_ids;
  1158. Konfigurator2.offers = data.offers;
  1159. groups_sorted = Konfigurator2.sort_groups();
  1160. console.log('groups_sorted:', groups_sorted);
  1161. console.log('groups_sorted Konfigurator2:', Konfigurator2);
  1162. for (var i in groups_sorted) {
  1163. var out_fun = (groups_sorted[i].gID > 0)? '#' : '+';
  1164. out_fun = '<a href="#" onclick="return Konfigurator2.editModal(' + i + ');">' + out_fun + '</a>';
  1165. out_cnt += '<tr id="edit-group-' + i + '">';
  1166. out_cnt += '<th class="conf2-fun">' + out_fun + '</th>';
  1167. for (var j in data.services) {
  1168. for (var k in data.services[j]) {
  1169. out_cnt += '<td>';
  1170. if (j in groups_sorted[i]._params && k == groups_sorted[i]._params[j]) {
  1171. out_cnt += 'X';
  1172. } else {
  1173. out_cnt += '---';
  1174. }
  1175. out_cnt += '</td>';
  1176. }
  1177. }
  1178. out_cnt += '</tr>';
  1179. }
  1180. jQuery('#dbg-offers-filter_total').text(out_offers_total);
  1181. jQuery('#dbg-offers-filter').html(out_offers);
  1182. jQuery('#dbg-groups-filter_total').text(out_groups_total);
  1183. jQuery('#dbg-groups-filter').html(out_groups);
  1184. jQuery('#conf2-cnt-services').html(out_services);
  1185. jQuery('#conf2-cnt').html(out_cnt);
  1186. },
  1187. error: function (err) {
  1188. console.log('err');
  1189. }
  1190. });
  1191. }
  1192. };
  1193. jQuery(document).ready(function(){
  1194. var Conf2 = jQuery('#conf2');
  1195. Conf2.find('.conf2-head input').on('change', function(evt){
  1196. Konfigurator2.refresh(Conf2, evt);
  1197. });
  1198. Conf2.find(".conf2-head button[name='refresh']").on('click', function(evt){
  1199. Konfigurator2.refresh(Conf2, evt);
  1200. });
  1201. jQuery('#dbg-offers-filter_toggle').on('click', function(){
  1202. jQuery('#dbg-offers-filter').toggle();
  1203. return false;
  1204. });
  1205. jQuery('#dbg-groups-filter_toggle').on('click', function(){
  1206. jQuery('#dbg-groups-filter').toggle();
  1207. return false;
  1208. });
  1209. jQuery('#conf2-modal-frm').submit(function(evt){
  1210. evt.preventDefault();
  1211. Konfigurator2.saveModal(evt);
  1212. return false;
  1213. });
  1214. });
  1215. </script>
  1216. <?php
  1217. }
  1218. function USERS2_OFFERS_GROUPS_konfigurator2_ajax_save() {
  1219. $db = DB::getDB();
  1220. $obj = new stdClass();
  1221. $obj->ID = V::get('f_ID', 0, $_POST, 'int');
  1222. $obj->P_SERVICE_COMPANY = V::get('f_COM', '', $_POST);
  1223. $obj->S_ALIAS = V::get('f_S_ALIAS', '', $_POST);
  1224. $obj->P_PROMOTION_NAME = V::get('f_P_PROMOTION_NAME', '', $_POST);
  1225. $obj->P_DEALTERM_MONTHS = V::get('f_P_DEALTERM_MONTHS', '', $_POST);
  1226. $obj->P_OFFER_TERM_BEGIN = V::get('f_P_OFFER_TERM_BEGIN', '', $_POST);
  1227. $obj->P_OFFER_TERM = V::get('f_P_OFFER_TERM', '', $_POST);
  1228. $obj->M_REWIR = V::get('f_M_REWIR', '', $_POST);
  1229. $obj->ID_NET = V::get('f_ID_NET', 0, $_POST, 'int');
  1230. $obj->ID_TV = V::get('f_ID_TV', 0, $_POST, 'int');
  1231. $obj->ID_TVC = V::get('f_ID_TVC', 0, $_POST, 'int');
  1232. $obj->ID_TEL = V::get('f_ID_TEL', 0, $_POST, 'int');
  1233. $data = new stdClass();
  1234. $data->ret = null;
  1235. if ($obj->ID > 0) {
  1236. $data->ret = $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $obj);
  1237. } else {
  1238. $data->ret = $db->ADD_NEW_OBJ('USERS2_OFFERS_GROUPS', $obj);
  1239. }
  1240. echo json_encode($data);
  1241. exit;
  1242. }
  1243. function USERS2_OFFERS_GROUPS_konfigurator2_ajax_fltrs() {
  1244. $model = new Offers_Groups_Konfigurator2_Model();
  1245. $data = new stdClass();
  1246. $data->offers = array();
  1247. $data->groups = array();
  1248. $data->services = array();
  1249. $data->services['NET'] = array();
  1250. $data->services['TV'] = array();
  1251. $data->services['TVC'] = array();
  1252. $data->services['TEL'] = array();
  1253. $data->srv_offer_ids = array();
  1254. $params = array();
  1255. $params['fltr_o_od'] = V::get('fltr_o_od', '', $_GET);
  1256. $params['fltr_COM'] = V::get('fltr_COM', '', $_GET);
  1257. $params['fltr_p_1615'] = V::get('fltr_p_1615', '', $_GET);
  1258. $params['fltr_p_1616'] = V::get('fltr_p_1616', '', $_GET);
  1259. $params['fltr_p_1617'] = V::get('fltr_p_1617', '', $_GET);
  1260. $params['fltr_p_1618'] = V::get('fltr_p_1618', '', $_GET);
  1261. $params['fltr_p_1619'] = V::get('fltr_p_1619', '', $_GET);
  1262. $params['fltr_p_1627'] = V::get('fltr_p_1627', '', $_GET);
  1263. $model->setCache('fltr_o_od', $params['fltr_o_od']);
  1264. $model->setCache('fltr_COM', $params['fltr_COM']);
  1265. $model->setCache('fltr_p_1615', $params['fltr_p_1615']);
  1266. $model->setCache('fltr_p_1616', $params['fltr_p_1616']);
  1267. $model->setCache('fltr_p_1617', $params['fltr_p_1617']);
  1268. $model->setCache('fltr_p_1618', $params['fltr_p_1618']);
  1269. $model->setCache('fltr_p_1619', $params['fltr_p_1619']);
  1270. $model->setCache('fltr_p_1627', $params['fltr_p_1627']);
  1271. if (empty($params['fltr_p_1615'])) {
  1272. $params['fltr_p_1615'] = '%';
  1273. }
  1274. if (empty($params['fltr_p_1616'])) {
  1275. $params['fltr_p_1616'] = '%';
  1276. }
  1277. if (empty($params['fltr_p_1617'])) {
  1278. $params['fltr_p_1617'] = '%';
  1279. }
  1280. if (empty($params['fltr_p_1618'])) {
  1281. $params['fltr_p_1618'] = '%';
  1282. }
  1283. if (empty($params['fltr_p_1619'])) {
  1284. $params['fltr_p_1619'] = '%';
  1285. }
  1286. if (empty($params['fltr_p_1627'])) {
  1287. $params['fltr_p_1627'] = '%';
  1288. }
  1289. if(V::get('DBG', '', $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$params (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($params);echo'</pre>';}
  1290. if (empty($params['fltr_o_od'])) {
  1291. $data->err_msg = "Ustaw pole OD (fltr_o_od)";
  1292. echo json_encode($data);
  1293. exit;
  1294. }
  1295. $db = DB::getDB();
  1296. $sql = "select o.`ID`
  1297. , o.`P_NAME`
  1298. , o.`P_SERVICE_NAME`
  1299. , o.`P_S_PARAM1`
  1300. , o.`P_INSTALL_QUOTE`
  1301. , o.`P_CONTRACT_PRICE`
  1302. , o.`P_PROMO_MONTH_PRICE`
  1303. , o.`P_NORMAL_PRICE`
  1304. , o.`P_SERVICE`
  1305. , o.`P_SERVICE_COMPANY`
  1306. from `USERS2_OFFERS` as o
  1307. where o.`A_RECORD_CREATE_DATE`>'{$params['fltr_o_od']}'
  1308. and o.`A_STATUS` in('WAITING', 'NORMAL')
  1309. and o.`P_SERVICE` in('NET','TV','TVC','TEL')
  1310. and o.`P_SERVICE_COMPANY`='{$params['fltr_COM']}'
  1311. limit 1000
  1312. ";
  1313. if(V::get('DBG', '', $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$sql-offers (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  1314. $res = $db->query($sql);
  1315. while ($r = $db->fetch($res)) {
  1316. $data->offers[$r->ID] = $r;
  1317. if ($r->P_SERVICE == 'NET') {
  1318. $data->services[$r->P_SERVICE][$r->P_S_PARAM1] = $r->P_S_PARAM1;
  1319. $data->srv_offer_ids[$r->P_SERVICE][$r->P_S_PARAM1][] = $r->ID;
  1320. }
  1321. else if ($r->P_SERVICE == 'TV') {
  1322. $data->services[$r->P_SERVICE][$r->P_SERVICE_NAME] = $r->P_SERVICE_NAME;
  1323. $data->srv_offer_ids[$r->P_SERVICE][$r->P_SERVICE_NAME][] = $r->ID;
  1324. }
  1325. else if ($r->P_SERVICE == 'TVC') {
  1326. $data->services[$r->P_SERVICE][$r->P_SERVICE_NAME] = $r->P_SERVICE_NAME;
  1327. $data->srv_offer_ids[$r->P_SERVICE][$r->P_SERVICE_NAME][] = $r->ID;
  1328. }
  1329. else if ($r->P_SERVICE == 'TEL') {
  1330. $data->services[$r->P_SERVICE][$r->P_SERVICE_NAME] = $r->P_SERVICE_NAME;
  1331. $data->srv_offer_ids[$r->P_SERVICE][$r->P_SERVICE_NAME][] = $r->ID;
  1332. }
  1333. }
  1334. foreach ($data->services as $k => $v) {
  1335. asort($data->services[$k]);
  1336. }
  1337. $sql = "select g.`ID`
  1338. , g.`S_ALIAS`
  1339. , g.`P_PROMOTION_NAME`
  1340. , g.`P_DEALTERM_MONTHS`
  1341. , g.`P_OFFER_TERM_BEGIN`
  1342. , g.`P_OFFER_TERM`
  1343. , g.`M_REWIR`
  1344. , g.`ID_NET`
  1345. , g.`ID_TV`
  1346. , g.`ID_TVC`
  1347. , g.`ID_TEL`
  1348. from `USERS2_OFFERS_GROUPS` as g
  1349. where g.`S_ALIAS` like '{$params['fltr_p_1615']}'
  1350. and g.`P_PROMOTION_NAME` like '{$params['fltr_p_1616']}'
  1351. and g.`P_DEALTERM_MONTHS` like '{$params['fltr_p_1617']}'
  1352. and g.`P_OFFER_TERM_BEGIN` like '{$params['fltr_p_1618']}'
  1353. and g.`P_OFFER_TERM` like '{$params['fltr_p_1619']}'
  1354. and g.`M_REWIR` like '{$params['fltr_p_1627']}'
  1355. and g.`A_STATUS` in('WAITING', 'NORMAL','MONITOR')
  1356. and g.`P_SERVICE_COMPANY`='{$params['fltr_COM']}'
  1357. limit 1000
  1358. ";
  1359. if(V::get('DBG', '', $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$sql-offers (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  1360. $res = $db->query($sql);
  1361. while ($r = $db->fetch($res)) {
  1362. $r->_params = array();
  1363. if ($r->ID_NET > 0) {
  1364. if (empty($data->offers[$r->ID_NET])) {
  1365. continue;
  1366. }
  1367. $r->_params['NET'] = $data->offers[$r->ID_NET]->P_S_PARAM1;
  1368. }
  1369. if ($r->ID_TV > 0) {
  1370. if (empty($data->offers[$r->ID_TV])) {
  1371. continue;
  1372. }
  1373. $r->_params['TV'] = $data->offers[$r->ID_TV]->P_SERVICE_NAME;
  1374. }
  1375. if ($r->ID_TVC > 0) {
  1376. if (empty($data->offers[$r->ID_TVC])) {
  1377. continue;
  1378. }
  1379. $r->_params['TVC'] = $data->offers[$r->ID_TVC]->P_SERVICE_NAME;
  1380. }
  1381. if ($r->ID_TEL > 0) {
  1382. if (empty($data->offers[$r->ID_TEL])) {
  1383. continue;
  1384. }
  1385. $r->_params['TEL'] = $data->offers[$r->ID_TEL]->P_SERVICE_NAME;
  1386. }
  1387. $data->groups[$r->ID] = $r;
  1388. }
  1389. if(V::get('DBG', '', $_GET) > 0){foreach ($data as $kFld => $v) {echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">data:'.$kFld.'('.count($v).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($v);echo'</pre>';}}
  1390. echo json_encode($data);
  1391. exit;
  1392. }
  1393. class Offers_Groups_Konfigurator2_Model {
  1394. public function __construct() {
  1395. if (!isset($_SESSION['Offers_Groups_Konfigurator2_Model'])) {
  1396. $_SESSION['Offers_Groups_Konfigurator2_Model'] = array();
  1397. }
  1398. }
  1399. public function getCache($key, $default = '') {
  1400. return V::get($key, $default, $_SESSION['Offers_Groups_Konfigurator2_Model']);
  1401. }
  1402. public function setCache($key, $val) {
  1403. $_SESSION['Offers_Groups_Konfigurator2_Model'][$key] = $val;
  1404. }
  1405. }
  1406. class Offers_Groups_Konfigurator_Model {
  1407. function get_base_params() {
  1408. $ret = array();
  1409. $ret['NET'] = array();
  1410. $ret['TV'] = array();
  1411. $ret['TVC'] = array();
  1412. $ret['TVCP'] = array();// multi
  1413. $ret['TEL'] = array();
  1414. return $ret;
  1415. }
  1416. function get_params_from_items(&$items) {
  1417. $ret = self::get_base_params();
  1418. if (empty($items)) {
  1419. return $ret;
  1420. }
  1421. foreach ($items as $g_id => $v_group) {
  1422. foreach ($v_group->oferty as $o_id => $v_offer) {
  1423. switch ($v_offer->P_SERVICE) {
  1424. case 'NET':
  1425. $ret['NET'] [$v_offer->P_S_PARAM1] = true;
  1426. break;
  1427. case 'TV':
  1428. $ret['TV'] [$v_offer->P_SERVICE_NAME] = true;
  1429. break;
  1430. case 'TVC':
  1431. $ret['TVC'] [$v_offer->P_SERVICE_NAME] = true;
  1432. break;
  1433. case 'TVCP':
  1434. $ret['TVCP'] [$v_offer->P_SERVICE_NAME] = true;
  1435. break;
  1436. case 'TEL':
  1437. $ret['TEL'] [$v_offer->P_SERVICE_NAME] = true;
  1438. break;
  1439. default:
  1440. }
  1441. }
  1442. }
  1443. // reverse keys - values
  1444. foreach ($ret as $k_service => $v_arr) {
  1445. $ret [$k_service] = array_keys($v_arr);
  1446. }
  1447. uasort($ret['NET'], array('self', 'sort_net_by_param1_callback'));
  1448. return $ret;
  1449. }
  1450. public static function sort_net_by_param1_callback( $a1, $a2 ) {
  1451. // clean vars
  1452. $args = array($a1, $a2);
  1453. foreach ($args as $k => $v_arg) {
  1454. $arg = $v_arg;
  1455. if (strpos($arg, 'Mb/s') !== false) $arg = str_replace('Mb/s', '', $arg);
  1456. else if (strpos($arg, 'kb/s') !== false) $arg = str_replace('kb/s', '', $arg);
  1457. if (is_numeric($arg)) {
  1458. $args[$k] = $arg;
  1459. }
  1460. }
  1461. if ($args[0] < $args[1]) {
  1462. return -1;
  1463. } else if ($args[0] > $args[1]) {
  1464. return 1;
  1465. } else {
  1466. return 0;
  1467. }
  1468. }
  1469. function get_items_by_params(&$items, &$user_params) {
  1470. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$user_params: ';print_r($user_params);echo'</pre>';
  1471. $user_params_checked_ok = 0;
  1472. foreach ($user_params as $k_type => $v_params) {
  1473. $user_params_checked_ok += count($v_params);
  1474. }
  1475. $ret = array();
  1476. foreach ($items as $item) {
  1477. $user_params_checked = 0;
  1478. foreach ($user_params as $k_type => $v_params) {
  1479. if (empty($v_params)) continue;
  1480. // if $k_type != 'TVCP' - jesli BRAK to powinno nie byc danej oferty
  1481. if ($k_type != 'TVCP') {
  1482. $v_param = reset($v_params);
  1483. if ($v_param == 'BRAK') {
  1484. $field_id_offer = "ID_" . $k_type;
  1485. if ($item->$field_id_offer <= 0) {
  1486. $user_params_checked++;
  1487. }
  1488. continue;
  1489. }
  1490. }
  1491. $v_offer = null;
  1492. $field_id_offer = "ID_" . $k_type;
  1493. if ($k_type == 'TVCP') {// ID_TVCP_1, ID_TVCP_2, ID_TVCP_3, ID_TVCP_4
  1494. for ($i = 1; $i <= 4; $i++) {
  1495. $field_id_offer_tvcp = $field_id_offer . "_" . $i;
  1496. if ($item->$field_id_offer_tvcp > 0) {
  1497. $v_offer = V::get($item->$field_id_offer_tvcp, '', $item->oferty);
  1498. if ($v_offer && in_array($v_offer->P_SERVICE_NAME, $v_params)) {
  1499. $user_params_checked++;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. if ($item->$field_id_offer > 0) {
  1505. $v_offer = V::get($item->$field_id_offer, '', $item->oferty);
  1506. }
  1507. if (!$v_offer) continue;
  1508. switch ($k_type) {
  1509. case 'NET':
  1510. if (in_array($v_offer->P_S_PARAM1, $v_params)) {
  1511. $user_params_checked++;
  1512. }
  1513. break;
  1514. case 'TV':
  1515. case 'TVC':
  1516. //case 'TVCP':
  1517. case 'TEL':
  1518. if (in_array($v_offer->P_SERVICE_NAME, $v_params)) {
  1519. $user_params_checked++;
  1520. }
  1521. break;
  1522. default:
  1523. }
  1524. }
  1525. if ($user_params_checked == $user_params_checked_ok) {
  1526. $ret [$item->ID] = $item;
  1527. }
  1528. }
  1529. return $ret;
  1530. }
  1531. }
  1532. class Offers_Groups_View {
  1533. function show_css() {
  1534. ?>
  1535. <style type="text/css">
  1536. .t-collapse {margin:0 0 10px 0; padding:0;}
  1537. .t-collapse dt {display:block; margin:0; padding:3px 10px; background:#812EA5; color:white; cursor:pointer;}
  1538. .t-collapse dd {display:block; margin:0; padding:4px 10px; background:#E5E5E5; color:black; overflow:hidden; border:1px solid #812EA5;}
  1539. .t-collapse dt em {}
  1540. .t-collapse dd .box {display:block; float:left; width:98px; height:120px; text-align:center; font-size:11px; color:#999;}
  1541. .t-collapse dd .box img {clear:both; margin:0 0 3px 0;}
  1542. .t-collapse dd .tbl-view {background:#fff;}
  1543. .t-collapse dt .add-show,
  1544. .t-collapse dt .add-hidden {font-size:normal; font-family:monospace; font-weight:bold;}
  1545. .t-collapse-hide dd {display:none;}
  1546. .t-collapse dt .add-show {display:inline;}
  1547. .t-collapse dt .add-hidden {display:none;}
  1548. .t-collapse-hide dt .add-show {display:none;}
  1549. .t-collapse-hide dt .add-hidden {display:inline;}
  1550. .t-collapse .tbl-view th,
  1551. .t-collapse .tbl-view td {font-size:small;}
  1552. .tbl-top td{vertical-align:top;}
  1553. </style>
  1554. <?php
  1555. }
  1556. function show_js() {
  1557. ?>
  1558. <script type="text/javascript">
  1559. jQuery(document).ready(function(){
  1560. jQuery(".t-collapse dt").click(function(){
  1561. jQuery(this).parent().toggleClass('t-collapse-hide');
  1562. return false
  1563. });
  1564. });
  1565. </script>
  1566. <?php
  1567. }
  1568. function filters($filters, $args) {
  1569. echo '<form action="" method="get">';
  1570. echo '<table class="tbl-view" cellpadding="0" cellspacing="0" border="1">';
  1571. echo '<caption>' . "Konfigurator - filtr pakietów" . '</caption>';
  1572. echo '<tr>';
  1573. foreach ($filters as $k_field_name => $v_req_field_name) {
  1574. echo '<th>';
  1575. echo $k_field_name;
  1576. echo '</th>';
  1577. }
  1578. echo '<th>' . "&nbsp;" . '</th>';
  1579. echo '</tr>';
  1580. echo '<tr>';
  1581. foreach ($filters as $k_field_name => $v_req_field_name) {
  1582. echo '<td>';
  1583. if ($k_field_name == 'A_STATUS') {
  1584. $filter_values = array();
  1585. $filter_values['%'] = "%";
  1586. $filter_values['WAITING'] = "WAITING";
  1587. $filter_values['NORMAL'] = "NORMAL";
  1588. $filter_values['MONITOR'] = "MONITOR";
  1589. $filter_values['OFF_HARD'] = "OFF_HARD";
  1590. $filter_values['WAITING_NORMAL'] = "NORMAL + WAITING";
  1591. echo '<select name="' . $v_req_field_name .'">';
  1592. $filter_value_selected = V::get($k_field_name, '', $args);
  1593. foreach ($filter_values as $k_filter_value => $v_filter_label) {
  1594. $sel = ($k_filter_value == $filter_value_selected)? 'selected="selected"' : '';
  1595. echo '<option value="' . $k_filter_value . '"' . $sel . '>' . $v_filter_label . '</option>';
  1596. }
  1597. echo '</select>';
  1598. } else {
  1599. echo '<input name="' . $v_req_field_name . '" type="text" value="' . V::get($k_field_name, '', $args) . '" />';
  1600. }
  1601. echo '</td>';
  1602. }
  1603. echo '<td>';
  1604. echo '<input type="hidden" name="' . "MENU_INIT" . '" value="' . "USERS2_OFFERS_GROUPS" .'" />';
  1605. echo '<input type="hidden" name="' . "task" . '" value="' . "KONFIGURATOR" .'" />';
  1606. echo '<input type="submit" value="' . "Wyślij" . '" />';
  1607. echo '</td>';
  1608. echo '</tr>';
  1609. echo '</table>';
  1610. echo '</form>';
  1611. }
  1612. function items($items) {
  1613. Lib::loadClass('PokazOfertyView');
  1614. $view = new PokazOfertyView();
  1615. echo $view->print_css();
  1616. echo $view->print_jquery_ui();
  1617. $cols = array();
  1618. $cols []= 'ID';
  1619. $cols []= 'S_ALIAS';
  1620. $cols []= 'P_PROMOTION_NAME';
  1621. $cols []= 'P_DEALTERM_MONTHS';
  1622. $cols []= 'P_OFFER_TERM_BEGIN';
  1623. $cols []= 'P_OFFER_TERM';
  1624. $cols []= 'P_SERVICE_COMPANY';
  1625. $cols []= 'ID_NET';
  1626. $cols []= 'ID_TEL';
  1627. $cols []= 'ID_TV';
  1628. $cols []= 'ID_TVC';
  1629. //$cols []= 'ID_TVCP'; - niużywane pole
  1630. $cols []= 'ID_TVCP_1';
  1631. $cols []= 'ID_TVCP_2';
  1632. $cols []= 'ID_TVCP_3';
  1633. $cols []= 'ID_TVCP_4';
  1634. //$cols []= 'S_OTHER_INFO';
  1635. $cols []= 'M_REWIR';
  1636. $cols []= 'A_STATUS';
  1637. $cols []= 'OFERTA_WWW';
  1638. $view->set('show_zysk', true);
  1639. $www_action = '<form action="" method="POST" style="display:inline">';
  1640. $www_action .= '<input type="hidden" name="sub_task" value="GROUP_WWW_ALL" />';
  1641. $www_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1642. $www_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1643. $www_action .= '</form>';
  1644. $view->set('show_www', $www_action);
  1645. $status_action = '<form action="" method="POST" style="display:inline">';
  1646. $status_action .= '<input type="hidden" name="sub_task" value="GROUP_STATUS_ALL" />';
  1647. $status_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1648. $status_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1649. $status_action .= '</form>';
  1650. $view->set('show_status', $status_action);
  1651. $view->set('show_rewir', true);
  1652. $view->print_groups_info_header();
  1653. foreach ($items as $item) {
  1654. $www_action = '<form action="" method="POST" style="display:inline">';
  1655. $www_action .= '<input type="hidden" name="sub_task" value="GROUP_WWW" />';
  1656. $www_action .= '<input type="hidden" name="group_id" value="' . $item->ID . '" />';
  1657. $www_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1658. $www_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1659. $www_action .= '</form>';
  1660. $view->set('show_www', $www_action);
  1661. $status_action = '<form action="" method="POST" style="display:inline">';
  1662. $status_action .= '<input type="hidden" name="sub_task" value="GROUP_STATUS" />';
  1663. $status_action .= '<input type="hidden" name="group_id" value="' . $item->ID . '" />';
  1664. $status_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1665. $status_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1666. $status_action .= '</form>';
  1667. $view->set('show_status', $status_action);
  1668. $group = new X_Column_users2_offers_groups();
  1669. $group->set_from_raw_data($item);
  1670. $group->set_offers($item->oferty);
  1671. $view->print_group_info($group, array('hide_header'=>true));
  1672. }
  1673. $view->print_groups_info_footer();
  1674. echo $view->print_js_show_hide_groups();
  1675. if (false) {// TODO: RMME
  1676. echo '<table class="tbl-view" cellspacing="0" cellpadding="0" border="1">';
  1677. echo '<thead>';
  1678. echo '<tr>';
  1679. foreach ($cols as $field_name) {
  1680. echo '<th>' . str_replace('_', ' ', $field_name) . '</th>';
  1681. }
  1682. echo '<th title="' . "Suma abonamentów w promocyjnych miesiącach" . '">' . "cena" . '</th>';
  1683. echo '<th title="' . "Suma opłat instalacyjnych" . '">' . "cena instalacji" . '</th>';
  1684. //echo '<th title="' . "Średnia" . '">' . "średnia" . '</th>';
  1685. echo '</tr>';
  1686. echo '</thead>';
  1687. echo '<tbody>';
  1688. foreach ($items as $item) {
  1689. $suma_P_PROMO_MONTH_PRICE = 0;
  1690. $suma_P_PROMO_INSTALL_PRICE = 0;
  1691. $suma_P_OFFER_SREDNIA = 0;
  1692. //$suma_P_OFFER_COSTS = 0;
  1693. foreach ($item->oferty as $v_oferta) {
  1694. $suma_P_PROMO_MONTH_PRICE += $v_oferta->P_PROMO_MONTH_PRICE;
  1695. $suma_P_PROMO_INSTALL_PRICE += $v_oferta->P_PROMO_INSTALL_PRICE;
  1696. // ROUND(( (t0.P_DEALTERM_MONTHS-t3.P_DEAL_PROMO_MONTHS)*t3.P_CONTRACT_PRICE + t3.P_DEAL_PROMO_MONTHS*t3.P_PROMO_MONTH_PRICE + t3.P_INSTALL_QUOTE)/t0.P_DEALTERM_MONTHS, 2) as `t3_srednia`,
  1697. $srednia = 0;
  1698. $srednia += ($item->P_DEALTERM_MONTHS - $v_oferta->P_DEAL_PROMO_MONTHS) * $v_oferta->P_CONTRACT_PRICE;
  1699. $srednia += $v_oferta->P_DEAL_PROMO_MONTHS * $v_oferta->P_PROMO_MONTH_PRICE;
  1700. $srednia += $v_oferta->P_INSTALL_QUOTE;
  1701. $srednia = round($srednia / $item->P_DEALTERM_MONTHS, 2);
  1702. $suma_P_OFFER_SREDNIA += $srednia;
  1703. }
  1704. echo '<tr>';
  1705. foreach ($cols as $field_name) {
  1706. echo '<td>' . $item->$field_name . '</td>';
  1707. }
  1708. echo '<td>' . '<nobr style="font-weight:bold;">' . number_format($suma_P_PROMO_MONTH_PRICE, 2, ',', ' ') . '</nobr>' . '</td>';
  1709. echo '<td>' . '<nobr>' . number_format($suma_P_PROMO_INSTALL_PRICE, 2, ',', ' ') . '</nobr>' . '</td>';
  1710. //echo '<td>' . '<nobr>' . number_format($suma_P_OFFER_SREDNIA, 2, ',', ' ') . '</nobr>' . '</td>';
  1711. echo '</tr>';
  1712. }
  1713. echo '</tbody>';
  1714. echo '</table>';
  1715. }
  1716. }
  1717. }
  1718. class Offers_Groups_Model {
  1719. function cols_groups() {
  1720. $cols = array();
  1721. $cols []= 'ID';
  1722. $cols []= 'S_ALIAS';
  1723. $cols []= 'P_PROMOTION_NAME';
  1724. $cols []= 'P_DEALTERM_MONTHS';
  1725. $cols []= 'P_OFFER_TERM_BEGIN';
  1726. $cols []= 'P_OFFER_TERM';
  1727. $cols []= 'P_SERVICE_COMPANY';
  1728. $cols []= 'ID_NET';
  1729. $cols []= 'ID_TEL';
  1730. $cols []= 'ID_TV';
  1731. $cols []= 'ID_TVC';
  1732. $cols []= 'ID_TVCP_1';
  1733. $cols []= 'ID_TVCP_2';
  1734. $cols []= 'ID_TVCP_3';
  1735. $cols []= 'ID_TVCP_4';
  1736. $cols []= 'S_OTHER_INFO';
  1737. $cols []= 'A_STATUS';
  1738. $cols []= 'M_REWIR';
  1739. $cols []= 'OFERTA_WWW';
  1740. return $cols;
  1741. }
  1742. function cols_offers() {
  1743. $cols = array();
  1744. $cols []= 'ID';
  1745. $cols []= 'A_STATUS';
  1746. $cols []= 'S_ALIAS';
  1747. $cols []= 'P_SERVICE';
  1748. $cols []= 'P_SERVICE_PARENT';
  1749. $cols []= 'P_SERVICE_NAME';
  1750. $cols []= 'P_PROMOTION_NAME';
  1751. $cols []= 'P_S_PARAM1';
  1752. $cols []= 'P_S_PARAM2';
  1753. $cols []= 'P_DEALTERM_MONTHS';
  1754. $cols []= 'P_DEAL_PROMO_MONTHS';
  1755. $cols []= 'P_INSTALL_QUOTE';
  1756. $cols []= 'P_INSTALL_QUOTE_NORMAL';
  1757. $cols []= 'P_CONTRACT_PRICE';
  1758. $cols []= 'P_PROMO_MONTH_PRICE';
  1759. $cols []= 'P_NORMAL_PRICE';
  1760. $cols []= 'P_OFFER_TERM_BEGIN';
  1761. $cols []= 'P_OFFER_TERM';
  1762. $cols []= 'P_PROMO_MONTH_PRICE_NETTO';
  1763. $cols []= 'P_CONTRACT_PRICE_NETTO';
  1764. $cols []= 'S_OTHER_INFO';
  1765. return $cols;
  1766. }
  1767. function get_buildings_cols() {
  1768. $buildings_sql_cols = array();
  1769. $buildings_sql_cols ['ID']= "ID";
  1770. $buildings_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
  1771. $buildings_sql_cols ['P_ADDRESS_STREET']= "P ADDRESS STREET";
  1772. $buildings_sql_cols ['A_STATUS']= "A STATUS";
  1773. $buildings_sql_cols ['T_INSTALACJA_W_CIAGU_DNI']= '<span title="'."informacje o terminach instalacji moze byc data lub daty na kazdy z rodzai uslug. Moga byc inforamcje na indywidualne klatki".'">'."T INSTALACJA W CIAGU DNI".'</span>';
  1774. $buildings_sql_cols ['T_BUILDING_TYPE']= "T BUILDING TYPE";
  1775. $buildings_sql_cols ['M_REWIR']= "M REWIR";
  1776. $buildings_sql_cols ['M_PARAMETRY']= "M PARAMETRY";
  1777. $buildings_sql_cols ['M_DIRECT_MARKETING_DATE']= "M DIRECT MARKETING DATE";
  1778. $buildings_sql_cols ['M_DATA_ZASIEDLENIA']= "M DATA ZASIEDLENIA";
  1779. return $buildings_sql_cols;
  1780. }
  1781. function get_marketing_cols() {
  1782. $marketing_sql_cols = array();
  1783. $marketing_sql_cols ['ID']= "ID";
  1784. $marketing_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
  1785. $marketing_sql_cols ['A_RECORD_UPDATE_DATE']= "A RECORD UPDATE DATE";
  1786. $marketing_sql_cols ['A_RECORD_UPDATE_AUTHOR']= "A RECORD UPDATE AUTHOR";
  1787. $marketing_sql_cols ['L_APPOITMENT_DATE']= "L APPOITMENT DATE";
  1788. $marketing_sql_cols ['L_APPOITMENT_USER']= "L APPOITMENT USER";
  1789. $marketing_sql_cols ['L_APPOITMENT_INFO']= "L APPOITMENT INFO";
  1790. return $marketing_sql_cols;
  1791. }
  1792. function get_buildings_by_mieszk($street) {
  1793. $buildings = array();
  1794. if (empty($street)) {
  1795. //return self::get_buildings($street);
  1796. return $buildings;
  1797. }
  1798. $db = DB::getDB();
  1799. $sql_cols_alias = array();
  1800. $buildings_sql_cols = self::get_buildings_cols();
  1801. foreach ($buildings_sql_cols as $k => $v) {
  1802. $sql_cols_alias []= 'b.' . $k;
  1803. }
  1804. $marketing_sql_cols = self::get_marketing_cols();
  1805. foreach ($marketing_sql_cols as $k => $v) {
  1806. $sql_cols_alias []= 'm.' . $k . ' as m__' . $k;
  1807. }
  1808. $sql_cols_alias []= 'm.`T_TELBOX_BUILDING_IN` as m__T_TELBOX_BUILDING_IN';
  1809. $sql_where_and = array();
  1810. $sql_where_and []= "1=1";
  1811. $sql_where_and []= "m.`A_STATUS` in('WAITING','NORMAL','MONITOR','WARNING','OFF_SOFT','OFF_HARD')";
  1812. $sql_where_and []= "m.`S_ADDRESS_STREET`='" . $db->_($street) . "'";
  1813. $sql_where = implode(" and ", $sql_where_and);
  1814. $sql = "select " . implode(", ", $sql_cols_alias) . "
  1815. from `USERS2_MARKETING` as m
  1816. left join `BUILDINGS` as b on(b.`S_ADDRESS_STREET`=m.`T_TELBOX_BUILDING_IN`)
  1817. where {$sql_where}
  1818. group by b.`ID`
  1819. order by b.`S_ADDRESS_STREET`
  1820. ";
  1821. DEBUG_S(6, "dbg sql:", $sql, __FILE__, __FUNCTION__, __LINE__);
  1822. $res = $db->query($sql);
  1823. while ($r = $db->fetch($res)) {
  1824. $buildings [$r->ID]= $r;
  1825. }
  1826. return $buildings;
  1827. }
  1828. function _parse_where($args) {
  1829. $sql_where_and_arr = array();
  1830. foreach ($args as $k_field => $v_value) {
  1831. if ($k_field == 'A_STATUS') {
  1832. if ($v_value == '%') {
  1833. }
  1834. else if ($v_value == 'WAITING_NORMAL') {
  1835. $sql_where_and_arr []= "g.`" . $k_field . "` in('WAITING', 'NORMAL')";
  1836. } else {
  1837. $sql_where_and_arr []= "g.`" . $k_field . "`='" . DB::_($v_value) . "'";
  1838. }
  1839. }
  1840. else if ($k_field == 'S_ADDRESS_STREET') {
  1841. if (!empty($v_value) && $v_value != '%') {
  1842. $buildings = self::get_buildings_by_mieszk($v_value);
  1843. $building = reset($buildings);
  1844. if ($building) {
  1845. $sql_where_and_arr []= "'{$building->M_REWIR}' like g.`M_REWIR`";
  1846. } else {
  1847. echo '<p style="color:red">' . "Nie odnaleziono mieszkania {$v_value}" . '</p>';
  1848. }
  1849. }
  1850. }
  1851. else {
  1852. $sql_where_and_arr []= "g.`" . $k_field . "` like '" . DB::_($v_value) . "'";
  1853. }
  1854. }
  1855. $sql_where = (!empty($sql_where_and_arr))? implode(" and ", $sql_where_and_arr) : "";
  1856. if (1 == V::get('DBG', '', $_GET)) {
  1857. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql_where (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql_where);echo'</pre>';
  1858. }
  1859. return $sql_where;
  1860. }
  1861. function get_total($args) {
  1862. $ret = 0;
  1863. $sql_where = self::_parse_where($args);
  1864. $sql = "select count(1) as cnt
  1865. from `USERS2_OFFERS_GROUPS` as g
  1866. where $sql_where
  1867. ";
  1868. $res = DB::query($sql);
  1869. if ($r = DB::fetch($res)) {
  1870. $ret = $r->cnt;
  1871. }
  1872. return $ret;
  1873. }
  1874. function get_items($args) {
  1875. $db = DB::getDB();
  1876. $external_offer_fields = array();
  1877. $external_offer_fields []= 'ID_NET';
  1878. $external_offer_fields []= 'ID_TEL';
  1879. $external_offer_fields []= 'ID_TV';
  1880. $external_offer_fields []= 'ID_TVC';
  1881. $external_offer_fields []= 'ID_TVCP_1';
  1882. $external_offer_fields []= 'ID_TVCP_2';
  1883. $external_offer_fields []= 'ID_TVCP_3';
  1884. $external_offer_fields []= 'ID_TVCP_4';
  1885. $oferty_ids = array();
  1886. $ret = array();
  1887. $sql_where = self::_parse_where($args);
  1888. $sql_select = array();
  1889. $cols = self::cols_groups();
  1890. foreach ($cols as $v_col) {
  1891. $sql_select []= "g.`" . $v_col . "`";
  1892. }
  1893. $sql_select = implode(", ", $sql_select);
  1894. $sql = "select {$sql_select}
  1895. from `USERS2_OFFERS_GROUPS` as g
  1896. where {$sql_where}
  1897. order by ID DESC
  1898. ";
  1899. $res = $db->query($sql);
  1900. while ($r = $db->fetch($res)) {
  1901. $ret [$r->ID] = $r;
  1902. foreach ($external_offer_fields as $external_offer_field) {
  1903. if ($r->$external_offer_field > 0) $oferty_ids [$r->$external_offer_field] []= $r->ID;
  1904. }
  1905. }
  1906. if (!empty($oferty_ids)) {
  1907. $sql_oferty_ids = array();
  1908. foreach ($oferty_ids as $k_offer_id => $v) {
  1909. $sql_oferty_ids []= "'" . $k_offer_id . "'";
  1910. }
  1911. $sql_select = array();
  1912. $cols = self::cols_offers();
  1913. foreach ($cols as $v_col) {
  1914. $sql_select []= "o.`" . $v_col . "`";
  1915. }
  1916. //$sql_select []= "'' as upust";
  1917. //$sql_select []= "o.P_NORMAL_PRICE*12 - o.P_DEAL_PROMO_MONTHS*o.P_PROMO_MONTH_PRICE - (12 - o.P_DEAL_PROMO_MONTHS)*o.P_CONTRACT_PRICE + (o.P_INSTALL_QUOTE_NORMAL - o.P_INSTALL_QUOTE) as `test_upust`";
  1918. //$sql_select []= "ROUND(( ((12 - o.P_DEAL_PROMO_MONTHS)*o.P_CONTRACT_PRICE) + (o.P_DEAL_PROMO_MONTHS*o.P_PROMO_MONTH_PRICE) + (o.P_INSTALL_QUOTE))/12, 2) as test_srednia";
  1919. //$sql_select []= "ROUND(( ((12 - o.P_DEAL_PROMO_MONTHS)*o.P_CONTRACT_PRICE_NETTO) + (o.P_DEAL_PROMO_MONTHS*o.P_PROMO_MONTH_PRICE_NETTO) + (o.P_INSTALL_QUOTE/1.23))/12, 2) as test_srednia_netto";
  1920. $sql_select = implode(", ", $sql_select);
  1921. $sql = "select {$sql_select}
  1922. from `USERS2_OFFERS` as o
  1923. where
  1924. o.`ID` in(" . implode(", ", $sql_oferty_ids) . ")
  1925. ";
  1926. $res = $db->query($sql);
  1927. while ($r = $db->fetch($res)) {
  1928. $group_ids_to_add = $oferty_ids[$r->ID];
  1929. foreach ($group_ids_to_add as $v_group_id) {
  1930. if (!isset($ret [$v_group_id]->oferty)) $ret [$v_group_id]->oferty = array();
  1931. $ret [$v_group_id]->oferty [$r->ID] = clone $r;
  1932. }
  1933. }
  1934. }
  1935. return $ret;
  1936. }
  1937. function get_offers_costs_by_offer_ids($offer_ids = array()) {
  1938. $oferty_costs = array();
  1939. $sql_where = "";
  1940. if (!empty($offer_ids)) {
  1941. $sql_where = "where o.`ID` in (" . implode(",", $offer_ids) . ")";
  1942. }
  1943. $sql = "select
  1944. o.`ID` as ID_OFERTY
  1945. , c.`P_OFFER_COSTS`
  1946. from `USERS2_OFFERS` as o
  1947. join `USERS2_OFFERS_COSTS_GROUPS` as c on (c.`ID`=o.`ID_COSTS_GROUPS`)
  1948. $sql_where
  1949. ";
  1950. $res = DB::query( $sql );
  1951. while ($r = DB::fetch( $res )) {
  1952. $oferty_costs[ $r->ID_OFERTY ] = $r->P_OFFER_COSTS;
  1953. }
  1954. return $oferty_costs;
  1955. }
  1956. }
  1957. class X_Column_Base {
  1958. var $_data;
  1959. var $_errors;
  1960. function __construct() {
  1961. $this->_errors = array();
  1962. $this->_data = array();
  1963. }
  1964. function get($field) {
  1965. return (array_key_exists($field, $this->_data))? $this->_data[$field] : '';
  1966. }
  1967. function set($field, $value) {
  1968. if (array_key_exists($field, $this->_data)) {
  1969. $this->_data[$field] = $value;
  1970. }
  1971. }
  1972. function get_cols() {
  1973. return array_keys($this->_data);
  1974. }
  1975. function get_data() {
  1976. return $this->_data;
  1977. }
  1978. function add_error($msg) {
  1979. $this->_errors []= $msg;
  1980. }
  1981. function get_errors() {
  1982. return $this->_errors;
  1983. }
  1984. function has_errors() {
  1985. return !empty($this->_errors);
  1986. }
  1987. }
  1988. class X_Column_users2_offers_groups extends X_Column_Base {
  1989. var $_offers;
  1990. var $_offers_by_id;
  1991. var $_id_options;
  1992. var $_group_external_offers_id;
  1993. var $suma_P_PROMO_INSTALL_PRICE = 0;
  1994. var $suma_P_PROMO_MONTH_PRICE = 0;
  1995. var $suma_P_CONTRACT_PRICE = 0;
  1996. var $suma_P_OFFER_SREDNIA = 0;
  1997. var $suma_P_OFFER_SREDNIA_NETTO = 0;
  1998. var $suma_P_OFFER_COSTS = 0;
  1999. function __construct() {
  2000. parent::__construct();
  2001. $this->_offers = array();
  2002. $this->_offers_by_id = array();
  2003. $this->_id_options = array();
  2004. $this->_group_external_offers_id = array('ID_NET'=>'NET','ID_TV'=>'TV','ID_TVC'=>'TVC','ID_TVCP_1'=>'TVC','ID_TVCP_2'=>'TVC','ID_TVCP_3'=>'TVC','ID_TVCP_4'=>'TVC','ID_TEL'=>'TEL');
  2005. $this->suma_P_PROMO_INSTALL_PRICE = 0;
  2006. $this->suma_P_PROMO_MONTH_PRICE = 0;
  2007. $this->suma_P_CONTRACT_PRICE = 0;
  2008. $this->suma_P_OFFER_SREDNIA = 0;
  2009. $this->suma_P_OFFER_SREDNIA_NETTO = 0;
  2010. $this->suma_P_OFFER_COSTS = 0;
  2011. }
  2012. function set_from_raw_data($db_row) {
  2013. foreach ($db_row as $k_field => $v_value) {
  2014. $this->_data[$k_field] = $v_value;
  2015. }
  2016. }
  2017. function has_offers() {
  2018. return !empty($this->_offers_by_id);
  2019. }
  2020. function get_offers() {
  2021. return $this->_offers;
  2022. }
  2023. function get_offers_by_id() {
  2024. return $this->_offers_by_id;
  2025. }
  2026. function set_offers($offers) {
  2027. $this->_offers_by_id = $offers;
  2028. $this->recount_costs();
  2029. $this->_convert_offers();
  2030. }
  2031. function set_id_options($id_options) {
  2032. $this->_id_options = $id_options;
  2033. }
  2034. function get_offers_ids() {
  2035. return array_keys($this->_offers_by_id);
  2036. }
  2037. function fetch_offers() {
  2038. $offers = array();
  2039. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2040. if ($this->get($k_external_id) > 0) {
  2041. $offers[$this->get($k_external_id)] = null;
  2042. }
  2043. }
  2044. foreach ($this->_id_options as $k_service => $v_options) {
  2045. if (empty($v_options)) continue;
  2046. foreach ($v_options as $v_option_id) {
  2047. if ($v_option_id > 0) {
  2048. $offers[$v_option_id] = null;
  2049. }
  2050. }
  2051. }
  2052. //$offers = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2053. $this->_offers_by_id = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2054. $this->recount_costs();
  2055. $this->_convert_offers();
  2056. }
  2057. /**
  2058. * Fetch offers by given ids and set _id_options.
  2059. * @param array $ids_offers - array of int - offers id
  2060. */
  2061. function fetch_offers_by_ids($ids_offers) {
  2062. $offers = array();
  2063. $options = array();
  2064. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2065. if ($this->get($k_external_id) > 0) {
  2066. $offers[$this->get($k_external_id)] = null;
  2067. }
  2068. }
  2069. foreach ($ids_offers as $v_offer_id) {
  2070. if (!array_key_exists($v_offer_id, $offers)) {
  2071. $offers[$v_offer_id] = null;
  2072. $options []= $v_offer_id;
  2073. }
  2074. }
  2075. $this->_offers_by_id = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2076. $this->recount_costs();
  2077. foreach ($this->_offers_by_id as $v_offer) {
  2078. if (in_array($v_offer->ID, $options)) {
  2079. $this->_id_options[$v_offer->P_SERVICE_PARENT] []= $v_offer->ID;
  2080. }
  2081. }
  2082. $this->_convert_offers();
  2083. }
  2084. function get_options_by_service($p_service) {
  2085. if (array_key_exists($p_service, $this->_id_options)) {
  2086. $options = array();
  2087. foreach ($this->_id_options[$p_service] as $v_id_option) {
  2088. $option = V::get($v_id_option, '', $this->_offers_by_id);
  2089. if ($option) {
  2090. $options [$v_id_option] = $option;
  2091. }
  2092. }
  2093. return $options;
  2094. }
  2095. return null;
  2096. }
  2097. /**
  2098. * Convert $this->_offers_by_id to $this->_offers.
  2099. * Note: first run fetch_offers() or set_offers($offers) to set up $this->_offers;
  2100. */
  2101. function _convert_offers() {
  2102. $tmp_srv_id = array();// 'NET'=>1, 'TV'=>0, 'TEL'=>0, 'OPCJA_NET'=>2, 'OPCJA_TV'=>2
  2103. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2104. if ($this->get($k_external_id) > 0) {
  2105. $v_offer = $this->_offers_by_id[$this->get($k_external_id)];
  2106. if ($v_offer) {
  2107. $v_offer->out_id = $v_p_service;
  2108. // wiele uslug tego samego typu np. TVC
  2109. $tmp_srv_id[$v_offer->out_id] = (!array_key_exists($v_offer->out_id, $tmp_srv_id))? 1 : $tmp_srv_id[$v_offer->out_id] + 1;
  2110. $v_offer->out_id = $v_offer->out_id . '_' . $tmp_srv_id[$v_offer->out_id];
  2111. $this->_offers [$v_offer->out_id] [$v_offer->ID] = $v_offer;
  2112. if (!empty($this->_id_options[$v_p_service])) {
  2113. foreach ($this->_id_options[$v_p_service] as $v_option_id) {
  2114. if ($v_option_id > 0) {
  2115. $v_option = V::get($v_option_id, null, $this->_offers);
  2116. if ($v_option) {
  2117. $v_option->out_id = 'OPCJA_' . $v_option->P_SERVICE_PARENT;
  2118. $tmp_srv_id[$v_option->out_id] = (!array_key_exists($v_option->out_id, $tmp_srv_id))? 1 : $tmp_srv_id[$v_option->out_id] + 1;
  2119. $v_option->out_id = $v_option->out_id . '_' . $tmp_srv_id[$v_option->out_id];
  2120. $this->_offers [$v_option->out_id] [$v_option->ID] = $v_option;
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. unset($tmp_srv_id);
  2129. }
  2130. function recount_costs() {
  2131. $this->suma_P_PROMO_INSTALL_PRICE = 0;
  2132. $this->suma_P_PROMO_MONTH_PRICE = 0;
  2133. $this->suma_P_CONTRACT_PRICE = 0;
  2134. $this->suma_P_OFFER_SREDNIA = 0;
  2135. $this->suma_P_OFFER_SREDNIA_NETTO = 0;
  2136. $this->suma_P_OFFER_COSTS = 0;
  2137. $oferty_costs = Offers_Groups_Model::get_offers_costs_by_offer_ids(array_keys($this->_offers_by_id));
  2138. foreach ($this->_offers_by_id as $v_offer) {
  2139. $this->suma_P_PROMO_INSTALL_PRICE += $v_offer->P_INSTALL_QUOTE;
  2140. $this->suma_P_PROMO_MONTH_PRICE += $v_offer->P_PROMO_MONTH_PRICE;
  2141. $this->suma_P_CONTRACT_PRICE += $v_offer->P_CONTRACT_PRICE;
  2142. if (!isset($v_offer->srednia)) {
  2143. $v_offer->srednia = round(( (($this->get('P_DEALTERM_MONTHS') - $v_offer->P_DEAL_PROMO_MONTHS) * $v_offer->P_CONTRACT_PRICE) + ($v_offer->P_DEAL_PROMO_MONTHS * $v_offer->P_PROMO_MONTH_PRICE) + ($v_offer->P_INSTALL_QUOTE)) / $this->get('P_DEALTERM_MONTHS'), 2);
  2144. }
  2145. $this->suma_P_OFFER_SREDNIA += $v_offer->srednia;
  2146. if (!isset($v_offer->srednia_netto)) {
  2147. $v_offer->srednia_netto = round(( (($this->get('P_DEALTERM_MONTHS') - $v_offer->P_DEAL_PROMO_MONTHS) * $v_offer->P_CONTRACT_PRICE_NETTO) + ($v_offer->P_DEAL_PROMO_MONTHS * $v_offer->P_PROMO_MONTH_PRICE_NETTO) + ($v_offer->P_INSTALL_QUOTE/1.23)) / $this->get('P_DEALTERM_MONTHS'), 2);
  2148. }
  2149. $this->suma_P_OFFER_SREDNIA_NETTO += $v_offer->srednia_netto;
  2150. if (isset($oferty_costs[$v_offer->ID])) {
  2151. $this->suma_P_OFFER_COSTS += $oferty_costs[$v_offer->ID];
  2152. }
  2153. }
  2154. }
  2155. function get_zysk_netto() {
  2156. $this->recount_costs();
  2157. return $this->suma_P_OFFER_SREDNIA_NETTO - $this->suma_P_OFFER_COSTS;
  2158. }
  2159. function has_service($p_service) {
  2160. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2161. if ($v_p_service == $p_service) {
  2162. if ($this->get($k_external_id) > 0) {
  2163. return true;
  2164. }
  2165. }
  2166. }
  2167. return false;
  2168. }
  2169. }