superedit-USERS2_OFFERS_GROUPS.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  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 fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  824. <div class="modal-dialog">
  825. <div class="modal-content">
  826. <form action="" id="conf2-modal-frm" class="form-horizontal">
  827. <div class="modal-header">
  828. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  829. <h3 id="myModalLabel">Grupa ofert</h3>
  830. </div>
  831. <div class="modal-body">
  832. <input type="hidden" name="f_ID" value="">
  833. <div class="form-group">
  834. <label for="f_COM" class="col-sm-3 control-label">P SERVICE COMPANY </label>
  835. <div class="col-sm-9">
  836. <input type="text" name="f_COM" value="<?php echo $model->getCache('fltr_COM', 'BN'); ?>">
  837. </div>
  838. </div>
  839. <div class="form-group">
  840. <label for="f_S_ALIAS" class="col-sm-3 control-label">[1615] S ALIAS </label>
  841. <div class="col-sm-9">
  842. <input type="text" name="f_S_ALIAS" value="<?php echo $model->getCache('fltr_p_1615'); ?>">
  843. </div>
  844. </div>
  845. <div class="form-group">
  846. <label for="f_P_PROMOTION_NAME" class="col-sm-3 control-label">[1616] P PROMOTION NAME </label>
  847. <div class="col-sm-9">
  848. <input type="text" name="f_P_PROMOTION_NAME" value="<?php echo $model->getCache('fltr_p_1616'); ?>">
  849. </div>
  850. </div>
  851. <div class="form-group">
  852. <label for="f_P_DEALTERM_MONTHS" class="col-sm-3 control-label">[1617] P DEALTERM MONTHS </label>
  853. <div class="col-sm-9">
  854. <input type="text" name="f_P_DEALTERM_MONTHS" value="<?php echo $model->getCache('fltr_p_1617'); ?>">
  855. </div>
  856. </div>
  857. <div class="form-group">
  858. <label for="f_P_OFFER_TERM_BEGIN" class="col-sm-3 control-label">[1618] P OFFER TERM BEGIN </label>
  859. <div class="col-sm-9">
  860. <input type="text" name="f_P_OFFER_TERM_BEGIN" value="<?php echo $model->getCache('fltr_p_1618'); ?>">
  861. </div>
  862. </div>
  863. <div class="form-group">
  864. <label for="f_P_OFFER_TERM" class="col-sm-3 control-label">[1619] P OFFER TERM </label>
  865. <div class="col-sm-9">
  866. <input type="text" name="f_P_OFFER_TERM" value="<?php echo $model->getCache('fltr_p_1619'); ?>">
  867. </div>
  868. </div>
  869. <div class="form-group">
  870. <label for="f_M_REWIR" class="col-sm-3 control-label">[1627] M REWIR </label>
  871. <div class="col-sm-9">
  872. <input type="text" name="f_M_REWIR" value="<?php echo $model->getCache('fltr_p_1627'); ?>">
  873. </div>
  874. </div>
  875. <div class="form-group">
  876. <label for="f_ID_NET" class="col-sm-3 control-label">[1743] ID_NET </label>
  877. <div class="col-sm-9">
  878. <select name="f_ID_NET"></select>
  879. </div>
  880. </div>
  881. <div class="form-group">
  882. <label for="f_ID_TV" class="col-sm-3 control-label">[1744] ID_TV </label>
  883. <div class="col-sm-9">
  884. <select name="f_ID_TV"></select>
  885. </div>
  886. </div>
  887. <div class="form-group">
  888. <label for="f_ID_TVC" class="col-sm-3 control-label">[1745] ID_TVC </label>
  889. <div class="col-sm-9">
  890. <select name="f_ID_TVC"></select>
  891. </div>
  892. </div>
  893. <div class="form-group">
  894. <label for="f_ID_TEL" class="col-sm-3 control-label">[1747] ID_TEL </label>
  895. <div class="col-sm-9">
  896. <select name="f_ID_TEL"></select>
  897. </div>
  898. </div>
  899. </div>
  900. <div class="modal-footer">
  901. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  902. <button class="btn btn-primary" class="btn-save">Zapisz/Dodaj</button>
  903. </div>
  904. </form>
  905. </div>
  906. </div>
  907. </div>
  908. <script>
  909. var Konfigurator2 = {
  910. groups_sorted: [],
  911. groups: [],
  912. services: [],
  913. srv_offer_ids: [],
  914. offers: [],
  915. editInd: 0,
  916. editModal: function(ind) {
  917. var $modal = jQuery('#conf2-Modal'),
  918. $frm = jQuery('#conf2-modal-frm'),
  919. group = null;
  920. this.editInd = ind;
  921. console.log('conf2-Modal show', this.groups_sorted[ind]);
  922. if (this.groups_sorted[ind]['gID']) {
  923. group = this.groups[this.groups_sorted[ind]['gID']];
  924. }
  925. $frm.find("[name='f_ID']").val('');
  926. if (group) {
  927. $frm.find("[name='f_ID']").val(group['ID']);
  928. $frm.find("[name='f_COM']").val(group['P_SERVICE_COMPANY']);
  929. $frm.find("[name='f_S_ALIAS']").val(group['S_ALIAS']);
  930. $frm.find("[name='f_P_PROMOTION_NAME']").val(group['P_PROMOTION_NAME']);
  931. $frm.find("[name='f_M_REWIR']").val(group['M_REWIR']);
  932. $frm.find("[name='f_P_DEALTERM_MONTHS']").val(group['P_DEALTERM_MONTHS']);
  933. $frm.find("[name='f_P_OFFER_TERM']").val(group['P_OFFER_TERM']);
  934. $frm.find("[name='f_P_OFFER_TERM_BEGIN']").val(group['P_OFFER_TERM_BEGIN']);
  935. } else {
  936. var Conf2 = jQuery('#conf2');
  937. $frm.find("[name='f_COM']").val(Conf2.find("[name='fltr_COM']").val());
  938. $frm.find("[name='f_S_ALIAS']").val(Conf2.find("[name='fltr_p_1615']").val());
  939. $frm.find("[name='f_P_PROMOTION_NAME']").val(Conf2.find("[name='fltr_p_1616']").val());
  940. $frm.find("[name='f_M_REWIR']").val(Conf2.find("[name='fltr_p_1627']").val());
  941. $frm.find("[name='f_P_DEALTERM_MONTHS']").val(Conf2.find("[name='fltr_p_1617']").val());
  942. $frm.find("[name='f_P_OFFER_TERM']").val(Conf2.find("[name='fltr_p_1619']").val());
  943. $frm.find("[name='f_P_OFFER_TERM_BEGIN']").val(Conf2.find("[name='fltr_p_1618']").val());
  944. }
  945. console.log('conf2-Modal this.srv_offer_ids', this.srv_offer_ids);
  946. for (var s in this.services) {// s: NET, TV, TVC, TEL
  947. var fName = 'f_ID_' + s,
  948. $fld = $frm.find("[name='" + fName + "']");
  949. $fld.find('option').remove();
  950. if (s in this.groups_sorted[ind]['_params']) {
  951. var srvVal = this.groups_sorted[ind]['_params'][s];
  952. $fld.val('TEST: ' + srvVal);
  953. for (var i in this.srv_offer_ids[s][srvVal]) {
  954. var oID = this.srv_offer_ids[s][srvVal][i];
  955. var o = this.offers[oID];
  956. var oLabel = '[' + o.ID + '] ' + o.P_PROMO_MONTH_PRICE + '/' + o.P_CONTRACT_PRICE;
  957. var sel = '';
  958. if (group) {
  959. if (group['ID_' + s] > 0 && group['ID_' + s] == oID) {
  960. sel = ' selected="selected"';
  961. }
  962. }
  963. $fld.append('<option value="' + oID + '"' + sel + '>' + oLabel + '</option>');
  964. }
  965. } else {
  966. $fld.append('<option value="0">0</option>');
  967. }
  968. }
  969. $modal.find('.modal-body');
  970. //.html(this.groups_sorted[ind]);
  971. $modal.modal('show');
  972. return false;
  973. },
  974. saveModal: function(evt) {
  975. var $frm = jQuery('#conf2-modal-frm'),
  976. params = $frm.serialize();
  977. console.log('conf2-Modal saveModal', this.groups_sorted[this.editInd], ' frm: ', params);
  978. $.ajax({
  979. url: 'index.php?FUNCTION_INIT=USERS2_OFFERS_GROUPS&HEADER_NOT_INIT=YES&task=KONFIGURATOR2&subtask=ajax_save',
  980. type: 'POST',
  981. dataType: 'json',
  982. data: params,
  983. async: true,
  984. success: function (data) {
  985. console.log('save data: ', data);
  986. var Conf2 = jQuery('#conf2');
  987. Konfigurator2.refresh(Conf2, evt);
  988. },
  989. error: function (err) {
  990. console.log('err');
  991. }
  992. });
  993. return false;
  994. },
  995. find_group_id: function(params, dbg) {
  996. var groupID = null,
  997. paramsTotal = 0,
  998. services = ['NET','TV','TVC','TEL'],
  999. dbg = dbg || false;
  1000. for (var i in params) {
  1001. paramsTotal++;
  1002. }
  1003. var dbg_limit = 2;
  1004. for (var g in this.groups) {
  1005. var paramsCmp = 0;
  1006. for (var srv in this.services) {
  1007. if (!this.groups[g]['_params']) continue;
  1008. //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]);}
  1009. if (srv in this.groups[g]['_params']) {
  1010. if (srv in params) {
  1011. if (params[srv] == this.groups[g]['_params'][srv]) {
  1012. paramsCmp++;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. if (paramsCmp == paramsTotal) {
  1018. groupID = this.groups[g]['ID'];
  1019. }
  1020. }
  1021. return groupID;
  1022. },
  1023. sort_groups: function() {
  1024. this.groups_sorted = [];// all combinations
  1025. //for (var g in this.groups) this.groups_sorted[g] = this.groups[g];
  1026. var ind = 90000;
  1027. //console.log('services: ', this.services);
  1028. for (var s in this.services) {
  1029. for (var p in this.services[s]) {
  1030. var group = {_params:{}, gID:null};
  1031. group['_params'][s] = this.services[s][p];
  1032. console.log('group add: ', group);
  1033. this.groups_sorted[ind++] = group;
  1034. }
  1035. }
  1036. // pakiety 2w1
  1037. for (var s in this.services) {
  1038. for (var p in this.services[s]) {
  1039. for (var s2 in this.services) {
  1040. if (s2 == s) continue;
  1041. if (s2 == 'TVC' && s == 'TV') continue;
  1042. if (s2 == 'TV' && s == 'TVC') continue;
  1043. for (var p2 in this.services[s2]) {
  1044. var group = {_params:{}, gID:null};
  1045. group['_params'][s] = this.services[s][p];
  1046. group['_params'][s2] = this.services[s2][p2];
  1047. group['gID'] = this.find_group_id(group['_params']);
  1048. this.groups_sorted[ind++] = group;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. // pakiety 3w1
  1054. for (var s in this.services) {
  1055. for (var p in this.services[s]) {
  1056. var lastS = s;
  1057. for (var s2 in this.services) {
  1058. if (lastS == s2) {
  1059. lastS = true;
  1060. continue;
  1061. }
  1062. if (lastS !== true) continue;
  1063. if (s2 == s) continue;
  1064. if (s2 == 'TVC' && s == 'TV') continue;
  1065. if (s2 == 'TV' && s == 'TVC') continue;
  1066. for (var p2 in this.services[s2]) {
  1067. var lastS2 = s2;
  1068. for (var s3 in this.services) {
  1069. if (lastS2 == s3) {
  1070. lastS2 = true;
  1071. continue;
  1072. }
  1073. if (lastS2 !== true) continue;
  1074. if (s3 == s) continue;
  1075. if (s3 == s2) continue;
  1076. if (s3 == 'TV' && (s == 'TVC' || s2 == 'TVC')) continue;
  1077. if (s3 == 'TVC' && (s == 'TV' || s2 == 'TV')) continue;
  1078. for (var p3 in this.services[s3]) {
  1079. var group = {_params:{}, gID:null};
  1080. group['_params'][s] = this.services[s][p];
  1081. group['_params'][s2] = this.services[s2][p2];
  1082. group['_params'][s3] = this.services[s3][p3];
  1083. group['gID'] = this.find_group_id(group['_params']);
  1084. console.log('group 3w1 add: (',s,',',s2,',',s3,') ', group);
  1085. this.groups_sorted[ind++] = group;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return this.groups_sorted;
  1093. },
  1094. refresh: function(Conf2, evt){
  1095. console.log('TODO: update filters dbg-offers-filter, dbg-groups-filter ... evt:', evt);
  1096. jQuery('#dbg-offers-filter')
  1097. var params = {};
  1098. params['fltr_o_od'] = Conf2.find("input[name='fltr_o_od']").val();
  1099. params['fltr_COM'] = Conf2.find("input[name='fltr_COM']").val();
  1100. //params['fltr_o_do'] = Conf2.find("input[name='fltr_o_do']").val();
  1101. params['fltr_p_1615'] = Conf2.find("input[name='fltr_p_1615']").val();
  1102. params['fltr_p_1616'] = Conf2.find("input[name='fltr_p_1616']").val();
  1103. params['fltr_p_1617'] = Conf2.find("input[name='fltr_p_1617']").val();
  1104. params['fltr_p_1618'] = Conf2.find("input[name='fltr_p_1618']").val();
  1105. params['fltr_p_1619'] = Conf2.find("input[name='fltr_p_1619']").val();
  1106. params['fltr_p_1627'] = Conf2.find("input[name='fltr_p_1627']").val();
  1107. console.log('TODO: params: ', params);
  1108. // 4968 KOMORKA A_RECORD_CREATE_DATE
  1109. $.ajax({
  1110. url: 'index.php?FUNCTION_INIT=USERS2_OFFERS_GROUPS&HEADER_NOT_INIT=YES&task=KONFIGURATOR2&subtask=ajax_fltrs',
  1111. type: 'GET',
  1112. dataType: 'json',
  1113. data: params,
  1114. async: true,
  1115. success: function (data) {
  1116. //console.log('data: ', data);
  1117. var out_offers_total = 0, out_groups_total = 0
  1118. , out_offers = '', out_groups = ''
  1119. , out_cnt = '', out_services = '';
  1120. if (data.offers) {
  1121. for (var i in data.offers) {
  1122. out_offers_total += 1;
  1123. out_offers += '<tr>' +
  1124. '<td>' + data.offers[i]['ID'] + '</td>' +
  1125. '<td>' + data.offers[i]['P_NAME'] + '</td>' +
  1126. '<td>' + data.offers[i]['P_SERVICE_NAME'] + '</td>' +
  1127. '<td>' + data.offers[i]['P_S_PARAM1'] + '</td>' +
  1128. '<td>' + data.offers[i]['P_INSTALL_QUOTE'] + '</td>' +
  1129. '<td>' + data.offers[i]['P_CONTRACT_PRICE'] + '</td>' +
  1130. '<td>' + data.offers[i]['P_PROMO_MONTH_PRICE'] + '</td>' +
  1131. '<td>' + data.offers[i]['P_NORMAL_PRICE'] + '</td>' +
  1132. '</tr>';
  1133. }
  1134. }
  1135. for (var i in data.groups) {
  1136. out_groups_total += 1;
  1137. out_groups += '<tr>' +
  1138. '<td>' + data.groups[i]['ID'] + '</td>' +
  1139. '<td>' + data.groups[i]['ID_TEL'] + '</td>' +
  1140. '<td>' + data.groups[i]['ID_TV'] + '</td>' +
  1141. '<td>' + data.groups[i]['ID_TVC'] + '</td>' +
  1142. '<td>' + data.groups[i]['ID_TEL'] + '</td>' +
  1143. '<td>' + data.groups[i]['S_ALIAS'] + '</td>' +
  1144. '<td>' + data.groups[i]['P_PROMOTION_NAME'] + '</td>' +
  1145. '<td>' + data.groups[i]['P_DEALTERM_MONTHS'] + '</td>' +
  1146. '<td>' + data.groups[i]['P_OFFER_TERM_BEGIN'] + '</td>' +
  1147. '<td>' + data.groups[i]['P_OFFER_TERM'] + '</td>' +
  1148. '<td>' + data.groups[i]['M_REWIR'] + '</td>' +
  1149. '</tr>';
  1150. }
  1151. if (data.services) {
  1152. out_services += '<td class="conf2-fun">&nbsp;</td>';
  1153. for (var j in data.services) {
  1154. for (var k in data.services[j]) {
  1155. out_services += '<th>' + data.services[j][k] + '</th>';
  1156. }
  1157. }
  1158. }
  1159. Konfigurator2.groups = data.groups;
  1160. Konfigurator2.services = data.services;
  1161. Konfigurator2.srv_offer_ids = data.srv_offer_ids;
  1162. Konfigurator2.offers = data.offers;
  1163. groups_sorted = Konfigurator2.sort_groups();
  1164. console.log('groups_sorted:', groups_sorted);
  1165. console.log('groups_sorted Konfigurator2:', Konfigurator2);
  1166. for (var i in groups_sorted) {
  1167. var out_fun = (groups_sorted[i].gID > 0)? '#' : '+';
  1168. out_fun = '<a href="#" onclick="return Konfigurator2.editModal(' + i + ');">' + out_fun + '</a>';
  1169. out_cnt += '<tr id="edit-group-' + i + '">';
  1170. out_cnt += '<th class="conf2-fun">' + out_fun + '</th>';
  1171. for (var j in data.services) {
  1172. for (var k in data.services[j]) {
  1173. out_cnt += '<td>';
  1174. if (j in groups_sorted[i]._params && k == groups_sorted[i]._params[j]) {
  1175. out_cnt += 'X';
  1176. } else {
  1177. out_cnt += '---';
  1178. }
  1179. out_cnt += '</td>';
  1180. }
  1181. }
  1182. out_cnt += '</tr>';
  1183. }
  1184. jQuery('#dbg-offers-filter_total').text(out_offers_total);
  1185. jQuery('#dbg-offers-filter').html(out_offers);
  1186. jQuery('#dbg-groups-filter_total').text(out_groups_total);
  1187. jQuery('#dbg-groups-filter').html(out_groups);
  1188. jQuery('#conf2-cnt-services').html(out_services);
  1189. jQuery('#conf2-cnt').html(out_cnt);
  1190. },
  1191. error: function (err) {
  1192. console.log('err');
  1193. }
  1194. });
  1195. }
  1196. };
  1197. jQuery(document).ready(function(){
  1198. var Conf2 = jQuery('#conf2');
  1199. Conf2.find('.conf2-head input').on('change', function(evt){
  1200. Konfigurator2.refresh(Conf2, evt);
  1201. });
  1202. Conf2.find(".conf2-head button[name='refresh']").on('click', function(evt){
  1203. Konfigurator2.refresh(Conf2, evt);
  1204. });
  1205. jQuery('#dbg-offers-filter_toggle').on('click', function(){
  1206. jQuery('#dbg-offers-filter').toggle();
  1207. return false;
  1208. });
  1209. jQuery('#dbg-groups-filter_toggle').on('click', function(){
  1210. jQuery('#dbg-groups-filter').toggle();
  1211. return false;
  1212. });
  1213. jQuery('#conf2-modal-frm').submit(function(evt){
  1214. evt.preventDefault();
  1215. Konfigurator2.saveModal(evt);
  1216. return false;
  1217. });
  1218. });
  1219. </script>
  1220. <?php
  1221. }
  1222. function USERS2_OFFERS_GROUPS_konfigurator2_ajax_save() {
  1223. $db = DB::getDB();
  1224. $obj = new stdClass();
  1225. $obj->ID = V::get('f_ID', 0, $_POST, 'int');
  1226. $obj->P_SERVICE_COMPANY = V::get('f_COM', '', $_POST);
  1227. $obj->S_ALIAS = V::get('f_S_ALIAS', '', $_POST);
  1228. $obj->P_PROMOTION_NAME = V::get('f_P_PROMOTION_NAME', '', $_POST);
  1229. $obj->P_DEALTERM_MONTHS = V::get('f_P_DEALTERM_MONTHS', '', $_POST);
  1230. $obj->P_OFFER_TERM_BEGIN = V::get('f_P_OFFER_TERM_BEGIN', '', $_POST);
  1231. $obj->P_OFFER_TERM = V::get('f_P_OFFER_TERM', '', $_POST);
  1232. $obj->M_REWIR = V::get('f_M_REWIR', '', $_POST);
  1233. $obj->ID_NET = V::get('f_ID_NET', 0, $_POST, 'int');
  1234. $obj->ID_TV = V::get('f_ID_TV', 0, $_POST, 'int');
  1235. $obj->ID_TVC = V::get('f_ID_TVC', 0, $_POST, 'int');
  1236. $obj->ID_TEL = V::get('f_ID_TEL', 0, $_POST, 'int');
  1237. $data = new stdClass();
  1238. $data->ret = null;
  1239. if ($obj->ID > 0) {
  1240. $data->ret = $db->UPDATE_OBJ('USERS2_OFFERS_GROUPS', $obj);
  1241. } else {
  1242. $data->ret = $db->ADD_NEW_OBJ('USERS2_OFFERS_GROUPS', $obj);
  1243. }
  1244. echo json_encode($data);
  1245. exit;
  1246. }
  1247. function USERS2_OFFERS_GROUPS_konfigurator2_ajax_fltrs() {
  1248. $model = new Offers_Groups_Konfigurator2_Model();
  1249. $data = new stdClass();
  1250. $data->offers = array();
  1251. $data->groups = array();
  1252. $data->services = array();
  1253. $data->services['NET'] = array();
  1254. $data->services['TV'] = array();
  1255. $data->services['TVC'] = array();
  1256. $data->services['TEL'] = array();
  1257. $data->srv_offer_ids = array();
  1258. $params = array();
  1259. $params['fltr_o_od'] = V::get('fltr_o_od', '', $_GET);
  1260. $params['fltr_COM'] = V::get('fltr_COM', '', $_GET);
  1261. $params['fltr_p_1615'] = V::get('fltr_p_1615', '', $_GET);
  1262. $params['fltr_p_1616'] = V::get('fltr_p_1616', '', $_GET);
  1263. $params['fltr_p_1617'] = V::get('fltr_p_1617', '', $_GET);
  1264. $params['fltr_p_1618'] = V::get('fltr_p_1618', '', $_GET);
  1265. $params['fltr_p_1619'] = V::get('fltr_p_1619', '', $_GET);
  1266. $params['fltr_p_1627'] = V::get('fltr_p_1627', '', $_GET);
  1267. $model->setCache('fltr_o_od', $params['fltr_o_od']);
  1268. $model->setCache('fltr_COM', $params['fltr_COM']);
  1269. $model->setCache('fltr_p_1615', $params['fltr_p_1615']);
  1270. $model->setCache('fltr_p_1616', $params['fltr_p_1616']);
  1271. $model->setCache('fltr_p_1617', $params['fltr_p_1617']);
  1272. $model->setCache('fltr_p_1618', $params['fltr_p_1618']);
  1273. $model->setCache('fltr_p_1619', $params['fltr_p_1619']);
  1274. $model->setCache('fltr_p_1627', $params['fltr_p_1627']);
  1275. if (empty($params['fltr_p_1615'])) {
  1276. $params['fltr_p_1615'] = '%';
  1277. }
  1278. if (empty($params['fltr_p_1616'])) {
  1279. $params['fltr_p_1616'] = '%';
  1280. }
  1281. if (empty($params['fltr_p_1617'])) {
  1282. $params['fltr_p_1617'] = '%';
  1283. }
  1284. if (empty($params['fltr_p_1618'])) {
  1285. $params['fltr_p_1618'] = '%';
  1286. }
  1287. if (empty($params['fltr_p_1619'])) {
  1288. $params['fltr_p_1619'] = '%';
  1289. }
  1290. if (empty($params['fltr_p_1627'])) {
  1291. $params['fltr_p_1627'] = '%';
  1292. }
  1293. 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>';}
  1294. if (empty($params['fltr_o_od'])) {
  1295. $data->err_msg = "Ustaw pole OD (fltr_o_od)";
  1296. echo json_encode($data);
  1297. exit;
  1298. }
  1299. $db = DB::getDB();
  1300. $sql = "select o.`ID`
  1301. , o.`P_NAME`
  1302. , o.`P_SERVICE_NAME`
  1303. , o.`P_S_PARAM1`
  1304. , o.`P_INSTALL_QUOTE`
  1305. , o.`P_CONTRACT_PRICE`
  1306. , o.`P_PROMO_MONTH_PRICE`
  1307. , o.`P_NORMAL_PRICE`
  1308. , o.`P_SERVICE`
  1309. , o.`P_SERVICE_COMPANY`
  1310. from `USERS2_OFFERS` as o
  1311. where o.`A_RECORD_CREATE_DATE`>'{$params['fltr_o_od']}'
  1312. and o.`A_STATUS` in('WAITING', 'NORMAL')
  1313. and o.`P_SERVICE` in('NET','TV','TVC','TEL')
  1314. and o.`P_SERVICE_COMPANY`='{$params['fltr_COM']}'
  1315. limit 1000
  1316. ";
  1317. 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>';}
  1318. $res = $db->query($sql);
  1319. while ($r = $db->fetch($res)) {
  1320. $data->offers[$r->ID] = $r;
  1321. if ($r->P_SERVICE == 'NET') {
  1322. $data->services[$r->P_SERVICE][$r->P_S_PARAM1] = $r->P_S_PARAM1;
  1323. $data->srv_offer_ids[$r->P_SERVICE][$r->P_S_PARAM1][] = $r->ID;
  1324. }
  1325. else if ($r->P_SERVICE == 'TV') {
  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 == 'TVC') {
  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. else if ($r->P_SERVICE == 'TEL') {
  1334. $data->services[$r->P_SERVICE][$r->P_SERVICE_NAME] = $r->P_SERVICE_NAME;
  1335. $data->srv_offer_ids[$r->P_SERVICE][$r->P_SERVICE_NAME][] = $r->ID;
  1336. }
  1337. }
  1338. foreach ($data->services as $k => $v) {
  1339. asort($data->services[$k]);
  1340. }
  1341. $sql = "select g.`ID`
  1342. , g.`S_ALIAS`
  1343. , g.`P_PROMOTION_NAME`
  1344. , g.`P_DEALTERM_MONTHS`
  1345. , g.`P_OFFER_TERM_BEGIN`
  1346. , g.`P_OFFER_TERM`
  1347. , g.`M_REWIR`
  1348. , g.`ID_NET`
  1349. , g.`ID_TV`
  1350. , g.`ID_TVC`
  1351. , g.`ID_TEL`
  1352. from `USERS2_OFFERS_GROUPS` as g
  1353. where g.`S_ALIAS` like '{$params['fltr_p_1615']}'
  1354. and g.`P_PROMOTION_NAME` like '{$params['fltr_p_1616']}'
  1355. and g.`P_DEALTERM_MONTHS` like '{$params['fltr_p_1617']}'
  1356. and g.`P_OFFER_TERM_BEGIN` like '{$params['fltr_p_1618']}'
  1357. and g.`P_OFFER_TERM` like '{$params['fltr_p_1619']}'
  1358. and g.`M_REWIR` like '{$params['fltr_p_1627']}'
  1359. and g.`A_STATUS` in('WAITING', 'NORMAL','MONITOR')
  1360. and g.`P_SERVICE_COMPANY`='{$params['fltr_COM']}'
  1361. limit 1000
  1362. ";
  1363. 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>';}
  1364. $res = $db->query($sql);
  1365. while ($r = $db->fetch($res)) {
  1366. $r->_params = array();
  1367. if ($r->ID_NET > 0) {
  1368. if (empty($data->offers[$r->ID_NET])) {
  1369. continue;
  1370. }
  1371. $r->_params['NET'] = $data->offers[$r->ID_NET]->P_S_PARAM1;
  1372. }
  1373. if ($r->ID_TV > 0) {
  1374. if (empty($data->offers[$r->ID_TV])) {
  1375. continue;
  1376. }
  1377. $r->_params['TV'] = $data->offers[$r->ID_TV]->P_SERVICE_NAME;
  1378. }
  1379. if ($r->ID_TVC > 0) {
  1380. if (empty($data->offers[$r->ID_TVC])) {
  1381. continue;
  1382. }
  1383. $r->_params['TVC'] = $data->offers[$r->ID_TVC]->P_SERVICE_NAME;
  1384. }
  1385. if ($r->ID_TEL > 0) {
  1386. if (empty($data->offers[$r->ID_TEL])) {
  1387. continue;
  1388. }
  1389. $r->_params['TEL'] = $data->offers[$r->ID_TEL]->P_SERVICE_NAME;
  1390. }
  1391. $data->groups[$r->ID] = $r;
  1392. }
  1393. 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>';}}
  1394. echo json_encode($data);
  1395. exit;
  1396. }
  1397. class Offers_Groups_Konfigurator2_Model {
  1398. public function __construct() {
  1399. if (!isset($_SESSION['Offers_Groups_Konfigurator2_Model'])) {
  1400. $_SESSION['Offers_Groups_Konfigurator2_Model'] = array();
  1401. }
  1402. }
  1403. public function getCache($key, $default = '') {
  1404. return V::get($key, $default, $_SESSION['Offers_Groups_Konfigurator2_Model']);
  1405. }
  1406. public function setCache($key, $val) {
  1407. $_SESSION['Offers_Groups_Konfigurator2_Model'][$key] = $val;
  1408. }
  1409. }
  1410. class Offers_Groups_Konfigurator_Model {
  1411. function get_base_params() {
  1412. $ret = array();
  1413. $ret['NET'] = array();
  1414. $ret['TV'] = array();
  1415. $ret['TVC'] = array();
  1416. $ret['TVCP'] = array();// multi
  1417. $ret['TEL'] = array();
  1418. return $ret;
  1419. }
  1420. function get_params_from_items(&$items) {
  1421. $ret = self::get_base_params();
  1422. if (empty($items)) {
  1423. return $ret;
  1424. }
  1425. foreach ($items as $g_id => $v_group) {
  1426. foreach ($v_group->oferty as $o_id => $v_offer) {
  1427. switch ($v_offer->P_SERVICE) {
  1428. case 'NET':
  1429. $ret['NET'] [$v_offer->P_S_PARAM1] = true;
  1430. break;
  1431. case 'TV':
  1432. $ret['TV'] [$v_offer->P_SERVICE_NAME] = true;
  1433. break;
  1434. case 'TVC':
  1435. $ret['TVC'] [$v_offer->P_SERVICE_NAME] = true;
  1436. break;
  1437. case 'TVCP':
  1438. $ret['TVCP'] [$v_offer->P_SERVICE_NAME] = true;
  1439. break;
  1440. case 'TEL':
  1441. $ret['TEL'] [$v_offer->P_SERVICE_NAME] = true;
  1442. break;
  1443. default:
  1444. }
  1445. }
  1446. }
  1447. // reverse keys - values
  1448. foreach ($ret as $k_service => $v_arr) {
  1449. $ret [$k_service] = array_keys($v_arr);
  1450. }
  1451. uasort($ret['NET'], array('self', 'sort_net_by_param1_callback'));
  1452. return $ret;
  1453. }
  1454. public static function sort_net_by_param1_callback( $a1, $a2 ) {
  1455. // clean vars
  1456. $args = array($a1, $a2);
  1457. foreach ($args as $k => $v_arg) {
  1458. $arg = $v_arg;
  1459. if (strpos($arg, 'Mb/s') !== false) $arg = str_replace('Mb/s', '', $arg);
  1460. else if (strpos($arg, 'kb/s') !== false) $arg = str_replace('kb/s', '', $arg);
  1461. if (is_numeric($arg)) {
  1462. $args[$k] = $arg;
  1463. }
  1464. }
  1465. if ($args[0] < $args[1]) {
  1466. return -1;
  1467. } else if ($args[0] > $args[1]) {
  1468. return 1;
  1469. } else {
  1470. return 0;
  1471. }
  1472. }
  1473. function get_items_by_params(&$items, &$user_params) {
  1474. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$user_params: ';print_r($user_params);echo'</pre>';
  1475. $user_params_checked_ok = 0;
  1476. foreach ($user_params as $k_type => $v_params) {
  1477. $user_params_checked_ok += count($v_params);
  1478. }
  1479. $ret = array();
  1480. foreach ($items as $item) {
  1481. $user_params_checked = 0;
  1482. foreach ($user_params as $k_type => $v_params) {
  1483. if (empty($v_params)) continue;
  1484. // if $k_type != 'TVCP' - jesli BRAK to powinno nie byc danej oferty
  1485. if ($k_type != 'TVCP') {
  1486. $v_param = reset($v_params);
  1487. if ($v_param == 'BRAK') {
  1488. $field_id_offer = "ID_" . $k_type;
  1489. if ($item->$field_id_offer <= 0) {
  1490. $user_params_checked++;
  1491. }
  1492. continue;
  1493. }
  1494. }
  1495. $v_offer = null;
  1496. $field_id_offer = "ID_" . $k_type;
  1497. if ($k_type == 'TVCP') {// ID_TVCP_1, ID_TVCP_2, ID_TVCP_3, ID_TVCP_4
  1498. for ($i = 1; $i <= 4; $i++) {
  1499. $field_id_offer_tvcp = $field_id_offer . "_" . $i;
  1500. if ($item->$field_id_offer_tvcp > 0) {
  1501. $v_offer = V::get($item->$field_id_offer_tvcp, '', $item->oferty);
  1502. if ($v_offer && in_array($v_offer->P_SERVICE_NAME, $v_params)) {
  1503. $user_params_checked++;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. if ($item->$field_id_offer > 0) {
  1509. $v_offer = V::get($item->$field_id_offer, '', $item->oferty);
  1510. }
  1511. if (!$v_offer) continue;
  1512. switch ($k_type) {
  1513. case 'NET':
  1514. if (in_array($v_offer->P_S_PARAM1, $v_params)) {
  1515. $user_params_checked++;
  1516. }
  1517. break;
  1518. case 'TV':
  1519. case 'TVC':
  1520. //case 'TVCP':
  1521. case 'TEL':
  1522. if (in_array($v_offer->P_SERVICE_NAME, $v_params)) {
  1523. $user_params_checked++;
  1524. }
  1525. break;
  1526. default:
  1527. }
  1528. }
  1529. if ($user_params_checked == $user_params_checked_ok) {
  1530. $ret [$item->ID] = $item;
  1531. }
  1532. }
  1533. return $ret;
  1534. }
  1535. }
  1536. class Offers_Groups_View {
  1537. function show_css() {
  1538. ?>
  1539. <style type="text/css">
  1540. .t-collapse {margin:0 0 10px 0; padding:0;}
  1541. .t-collapse dt {display:block; margin:0; padding:3px 10px; background:#812EA5; color:white; cursor:pointer;}
  1542. .t-collapse dd {display:block; margin:0; padding:4px 10px; background:#E5E5E5; color:black; overflow:hidden; border:1px solid #812EA5;}
  1543. .t-collapse dt em {}
  1544. .t-collapse dd .box {display:block; float:left; width:98px; height:120px; text-align:center; font-size:11px; color:#999;}
  1545. .t-collapse dd .box img {clear:both; margin:0 0 3px 0;}
  1546. .t-collapse dd .tbl-view {background:#fff;}
  1547. .t-collapse dt .add-show,
  1548. .t-collapse dt .add-hidden {font-size:normal; font-family:monospace; font-weight:bold;}
  1549. .t-collapse-hide dd {display:none;}
  1550. .t-collapse dt .add-show {display:inline;}
  1551. .t-collapse dt .add-hidden {display:none;}
  1552. .t-collapse-hide dt .add-show {display:none;}
  1553. .t-collapse-hide dt .add-hidden {display:inline;}
  1554. .t-collapse .tbl-view th,
  1555. .t-collapse .tbl-view td {font-size:small;}
  1556. .tbl-top td{vertical-align:top;}
  1557. </style>
  1558. <?php
  1559. }
  1560. function show_js() {
  1561. ?>
  1562. <script type="text/javascript">
  1563. jQuery(document).ready(function(){
  1564. jQuery(".t-collapse dt").click(function(){
  1565. jQuery(this).parent().toggleClass('t-collapse-hide');
  1566. return false
  1567. });
  1568. });
  1569. </script>
  1570. <?php
  1571. }
  1572. function filters($filters, $args) {
  1573. echo '<form action="" method="get">';
  1574. echo '<table class="tbl-view" cellpadding="0" cellspacing="0" border="1">';
  1575. echo '<caption>' . "Konfigurator - filtr pakietów" . '</caption>';
  1576. echo '<tr>';
  1577. foreach ($filters as $k_field_name => $v_req_field_name) {
  1578. echo '<th>';
  1579. echo $k_field_name;
  1580. echo '</th>';
  1581. }
  1582. echo '<th>' . "&nbsp;" . '</th>';
  1583. echo '</tr>';
  1584. echo '<tr>';
  1585. foreach ($filters as $k_field_name => $v_req_field_name) {
  1586. echo '<td>';
  1587. if ($k_field_name == 'A_STATUS') {
  1588. $filter_values = array();
  1589. $filter_values['%'] = "%";
  1590. $filter_values['WAITING'] = "WAITING";
  1591. $filter_values['NORMAL'] = "NORMAL";
  1592. $filter_values['MONITOR'] = "MONITOR";
  1593. $filter_values['OFF_HARD'] = "OFF_HARD";
  1594. $filter_values['WAITING_NORMAL'] = "NORMAL + WAITING";
  1595. echo '<select name="' . $v_req_field_name .'">';
  1596. $filter_value_selected = V::get($k_field_name, '', $args);
  1597. foreach ($filter_values as $k_filter_value => $v_filter_label) {
  1598. $sel = ($k_filter_value == $filter_value_selected)? 'selected="selected"' : '';
  1599. echo '<option value="' . $k_filter_value . '"' . $sel . '>' . $v_filter_label . '</option>';
  1600. }
  1601. echo '</select>';
  1602. } else {
  1603. echo '<input name="' . $v_req_field_name . '" type="text" value="' . V::get($k_field_name, '', $args) . '" />';
  1604. }
  1605. echo '</td>';
  1606. }
  1607. echo '<td>';
  1608. echo '<input type="hidden" name="' . "MENU_INIT" . '" value="' . "USERS2_OFFERS_GROUPS" .'" />';
  1609. echo '<input type="hidden" name="' . "task" . '" value="' . "KONFIGURATOR" .'" />';
  1610. echo '<input type="submit" value="' . "Wyślij" . '" />';
  1611. echo '</td>';
  1612. echo '</tr>';
  1613. echo '</table>';
  1614. echo '</form>';
  1615. }
  1616. function items($items) {
  1617. Lib::loadClass('PokazOfertyView');
  1618. $view = new PokazOfertyView();
  1619. echo $view->print_css();
  1620. echo $view->print_jquery_ui();
  1621. $cols = array();
  1622. $cols []= 'ID';
  1623. $cols []= 'S_ALIAS';
  1624. $cols []= 'P_PROMOTION_NAME';
  1625. $cols []= 'P_DEALTERM_MONTHS';
  1626. $cols []= 'P_OFFER_TERM_BEGIN';
  1627. $cols []= 'P_OFFER_TERM';
  1628. $cols []= 'P_SERVICE_COMPANY';
  1629. $cols []= 'ID_NET';
  1630. $cols []= 'ID_TEL';
  1631. $cols []= 'ID_TV';
  1632. $cols []= 'ID_TVC';
  1633. //$cols []= 'ID_TVCP'; - niużywane pole
  1634. $cols []= 'ID_TVCP_1';
  1635. $cols []= 'ID_TVCP_2';
  1636. $cols []= 'ID_TVCP_3';
  1637. $cols []= 'ID_TVCP_4';
  1638. //$cols []= 'S_OTHER_INFO';
  1639. $cols []= 'M_REWIR';
  1640. $cols []= 'A_STATUS';
  1641. $cols []= 'OFERTA_WWW';
  1642. $view->set('show_zysk', true);
  1643. $www_action = '<form action="" method="POST" style="display:inline">';
  1644. $www_action .= '<input type="hidden" name="sub_task" value="GROUP_WWW_ALL" />';
  1645. $www_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1646. $www_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1647. $www_action .= '</form>';
  1648. $view->set('show_www', $www_action);
  1649. $status_action = '<form action="" method="POST" style="display:inline">';
  1650. $status_action .= '<input type="hidden" name="sub_task" value="GROUP_STATUS_ALL" />';
  1651. $status_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1652. $status_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1653. $status_action .= '</form>';
  1654. $view->set('show_status', $status_action);
  1655. $view->set('show_rewir', true);
  1656. $view->print_groups_info_header();
  1657. foreach ($items as $item) {
  1658. $www_action = '<form action="" method="POST" style="display:inline">';
  1659. $www_action .= '<input type="hidden" name="sub_task" value="GROUP_WWW" />';
  1660. $www_action .= '<input type="hidden" name="group_id" value="' . $item->ID . '" />';
  1661. $www_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1662. $www_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1663. $www_action .= '</form>';
  1664. $view->set('show_www', $www_action);
  1665. $status_action = '<form action="" method="POST" style="display:inline">';
  1666. $status_action .= '<input type="hidden" name="sub_task" value="GROUP_STATUS" />';
  1667. $status_action .= '<input type="hidden" name="group_id" value="' . $item->ID . '" />';
  1668. $status_action .= '<input type="submit" name="change" value="+" title="Activate" />';
  1669. $status_action .= '<input type="submit" name="change" value="-" title="Deactivate" />';
  1670. $status_action .= '</form>';
  1671. $view->set('show_status', $status_action);
  1672. $group = new X_Column_users2_offers_groups();
  1673. $group->set_from_raw_data($item);
  1674. $group->set_offers($item->oferty);
  1675. $view->print_group_info($group, array('hide_header'=>true));
  1676. }
  1677. $view->print_groups_info_footer();
  1678. echo $view->print_js_show_hide_groups();
  1679. if (false) {// TODO: RMME
  1680. echo '<table class="tbl-view" cellspacing="0" cellpadding="0" border="1">';
  1681. echo '<thead>';
  1682. echo '<tr>';
  1683. foreach ($cols as $field_name) {
  1684. echo '<th>' . str_replace('_', ' ', $field_name) . '</th>';
  1685. }
  1686. echo '<th title="' . "Suma abonamentów w promocyjnych miesiącach" . '">' . "cena" . '</th>';
  1687. echo '<th title="' . "Suma opłat instalacyjnych" . '">' . "cena instalacji" . '</th>';
  1688. //echo '<th title="' . "Średnia" . '">' . "średnia" . '</th>';
  1689. echo '</tr>';
  1690. echo '</thead>';
  1691. echo '<tbody>';
  1692. foreach ($items as $item) {
  1693. $suma_P_PROMO_MONTH_PRICE = 0;
  1694. $suma_P_PROMO_INSTALL_PRICE = 0;
  1695. $suma_P_OFFER_SREDNIA = 0;
  1696. //$suma_P_OFFER_COSTS = 0;
  1697. foreach ($item->oferty as $v_oferta) {
  1698. $suma_P_PROMO_MONTH_PRICE += $v_oferta->P_PROMO_MONTH_PRICE;
  1699. $suma_P_PROMO_INSTALL_PRICE += $v_oferta->P_PROMO_INSTALL_PRICE;
  1700. // 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`,
  1701. $srednia = 0;
  1702. $srednia += ($item->P_DEALTERM_MONTHS - $v_oferta->P_DEAL_PROMO_MONTHS) * $v_oferta->P_CONTRACT_PRICE;
  1703. $srednia += $v_oferta->P_DEAL_PROMO_MONTHS * $v_oferta->P_PROMO_MONTH_PRICE;
  1704. $srednia += $v_oferta->P_INSTALL_QUOTE;
  1705. $srednia = round($srednia / $item->P_DEALTERM_MONTHS, 2);
  1706. $suma_P_OFFER_SREDNIA += $srednia;
  1707. }
  1708. echo '<tr>';
  1709. foreach ($cols as $field_name) {
  1710. echo '<td>' . $item->$field_name . '</td>';
  1711. }
  1712. echo '<td>' . '<nobr style="font-weight:bold;">' . number_format($suma_P_PROMO_MONTH_PRICE, 2, ',', ' ') . '</nobr>' . '</td>';
  1713. echo '<td>' . '<nobr>' . number_format($suma_P_PROMO_INSTALL_PRICE, 2, ',', ' ') . '</nobr>' . '</td>';
  1714. //echo '<td>' . '<nobr>' . number_format($suma_P_OFFER_SREDNIA, 2, ',', ' ') . '</nobr>' . '</td>';
  1715. echo '</tr>';
  1716. }
  1717. echo '</tbody>';
  1718. echo '</table>';
  1719. }
  1720. }
  1721. }
  1722. class Offers_Groups_Model {
  1723. function cols_groups() {
  1724. $cols = array();
  1725. $cols []= 'ID';
  1726. $cols []= 'S_ALIAS';
  1727. $cols []= 'P_PROMOTION_NAME';
  1728. $cols []= 'P_DEALTERM_MONTHS';
  1729. $cols []= 'P_OFFER_TERM_BEGIN';
  1730. $cols []= 'P_OFFER_TERM';
  1731. $cols []= 'P_SERVICE_COMPANY';
  1732. $cols []= 'ID_NET';
  1733. $cols []= 'ID_TEL';
  1734. $cols []= 'ID_TV';
  1735. $cols []= 'ID_TVC';
  1736. $cols []= 'ID_TVCP_1';
  1737. $cols []= 'ID_TVCP_2';
  1738. $cols []= 'ID_TVCP_3';
  1739. $cols []= 'ID_TVCP_4';
  1740. $cols []= 'S_OTHER_INFO';
  1741. $cols []= 'A_STATUS';
  1742. $cols []= 'M_REWIR';
  1743. $cols []= 'OFERTA_WWW';
  1744. return $cols;
  1745. }
  1746. function cols_offers() {
  1747. $cols = array();
  1748. $cols []= 'ID';
  1749. $cols []= 'A_STATUS';
  1750. $cols []= 'S_ALIAS';
  1751. $cols []= 'P_SERVICE';
  1752. $cols []= 'P_SERVICE_PARENT';
  1753. $cols []= 'P_SERVICE_NAME';
  1754. $cols []= 'P_PROMOTION_NAME';
  1755. $cols []= 'P_S_PARAM1';
  1756. $cols []= 'P_S_PARAM2';
  1757. $cols []= 'P_DEALTERM_MONTHS';
  1758. $cols []= 'P_DEAL_PROMO_MONTHS';
  1759. $cols []= 'P_INSTALL_QUOTE';
  1760. $cols []= 'P_INSTALL_QUOTE_NORMAL';
  1761. $cols []= 'P_CONTRACT_PRICE';
  1762. $cols []= 'P_PROMO_MONTH_PRICE';
  1763. $cols []= 'P_NORMAL_PRICE';
  1764. $cols []= 'P_OFFER_TERM_BEGIN';
  1765. $cols []= 'P_OFFER_TERM';
  1766. $cols []= 'P_PROMO_MONTH_PRICE_NETTO';
  1767. $cols []= 'P_CONTRACT_PRICE_NETTO';
  1768. $cols []= 'S_OTHER_INFO';
  1769. return $cols;
  1770. }
  1771. function get_buildings_cols() {
  1772. $buildings_sql_cols = array();
  1773. $buildings_sql_cols ['ID']= "ID";
  1774. $buildings_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
  1775. $buildings_sql_cols ['P_ADDRESS_STREET']= "P ADDRESS STREET";
  1776. $buildings_sql_cols ['A_STATUS']= "A STATUS";
  1777. $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>';
  1778. $buildings_sql_cols ['T_BUILDING_TYPE']= "T BUILDING TYPE";
  1779. $buildings_sql_cols ['M_REWIR']= "M REWIR";
  1780. $buildings_sql_cols ['M_PARAMETRY']= "M PARAMETRY";
  1781. $buildings_sql_cols ['M_DIRECT_MARKETING_DATE']= "M DIRECT MARKETING DATE";
  1782. $buildings_sql_cols ['M_DATA_ZASIEDLENIA']= "M DATA ZASIEDLENIA";
  1783. return $buildings_sql_cols;
  1784. }
  1785. function get_marketing_cols() {
  1786. $marketing_sql_cols = array();
  1787. $marketing_sql_cols ['ID']= "ID";
  1788. $marketing_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
  1789. $marketing_sql_cols ['A_RECORD_UPDATE_DATE']= "A RECORD UPDATE DATE";
  1790. $marketing_sql_cols ['A_RECORD_UPDATE_AUTHOR']= "A RECORD UPDATE AUTHOR";
  1791. $marketing_sql_cols ['L_APPOITMENT_DATE']= "L APPOITMENT DATE";
  1792. $marketing_sql_cols ['L_APPOITMENT_USER']= "L APPOITMENT USER";
  1793. $marketing_sql_cols ['L_APPOITMENT_INFO']= "L APPOITMENT INFO";
  1794. return $marketing_sql_cols;
  1795. }
  1796. function get_buildings_by_mieszk($street) {
  1797. $buildings = array();
  1798. if (empty($street)) {
  1799. //return self::get_buildings($street);
  1800. return $buildings;
  1801. }
  1802. $db = DB::getDB();
  1803. $sql_cols_alias = array();
  1804. $buildings_sql_cols = self::get_buildings_cols();
  1805. foreach ($buildings_sql_cols as $k => $v) {
  1806. $sql_cols_alias []= 'b.' . $k;
  1807. }
  1808. $marketing_sql_cols = self::get_marketing_cols();
  1809. foreach ($marketing_sql_cols as $k => $v) {
  1810. $sql_cols_alias []= 'm.' . $k . ' as m__' . $k;
  1811. }
  1812. $sql_cols_alias []= 'm.`T_TELBOX_BUILDING_IN` as m__T_TELBOX_BUILDING_IN';
  1813. $sql_where_and = array();
  1814. $sql_where_and []= "1=1";
  1815. $sql_where_and []= "m.`A_STATUS` in('WAITING','NORMAL','MONITOR','WARNING','OFF_SOFT','OFF_HARD')";
  1816. $sql_where_and []= "m.`S_ADDRESS_STREET`='" . $db->_($street) . "'";
  1817. $sql_where = implode(" and ", $sql_where_and);
  1818. $sql = "select " . implode(", ", $sql_cols_alias) . "
  1819. from `USERS2_MARKETING` as m
  1820. left join `BUILDINGS` as b on(b.`S_ADDRESS_STREET`=m.`T_TELBOX_BUILDING_IN`)
  1821. where {$sql_where}
  1822. group by b.`ID`
  1823. order by b.`S_ADDRESS_STREET`
  1824. ";
  1825. DEBUG_S(6, "dbg sql:", $sql, __FILE__, __FUNCTION__, __LINE__);
  1826. $res = $db->query($sql);
  1827. while ($r = $db->fetch($res)) {
  1828. $buildings [$r->ID]= $r;
  1829. }
  1830. return $buildings;
  1831. }
  1832. function _parse_where($args) {
  1833. $sql_where_and_arr = array();
  1834. foreach ($args as $k_field => $v_value) {
  1835. if ($k_field == 'A_STATUS') {
  1836. if ($v_value == '%') {
  1837. }
  1838. else if ($v_value == 'WAITING_NORMAL') {
  1839. $sql_where_and_arr []= "g.`" . $k_field . "` in('WAITING', 'NORMAL')";
  1840. } else {
  1841. $sql_where_and_arr []= "g.`" . $k_field . "`='" . DB::_($v_value) . "'";
  1842. }
  1843. }
  1844. else if ($k_field == 'S_ADDRESS_STREET') {
  1845. if (!empty($v_value) && $v_value != '%') {
  1846. $buildings = self::get_buildings_by_mieszk($v_value);
  1847. $building = reset($buildings);
  1848. if ($building) {
  1849. $sql_where_and_arr []= "'{$building->M_REWIR}' like g.`M_REWIR`";
  1850. } else {
  1851. echo '<p style="color:red">' . "Nie odnaleziono mieszkania {$v_value}" . '</p>';
  1852. }
  1853. }
  1854. }
  1855. else {
  1856. $sql_where_and_arr []= "g.`" . $k_field . "` like '" . DB::_($v_value) . "'";
  1857. }
  1858. }
  1859. $sql_where = (!empty($sql_where_and_arr))? implode(" and ", $sql_where_and_arr) : "";
  1860. if (1 == V::get('DBG', '', $_GET)) {
  1861. 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>';
  1862. }
  1863. return $sql_where;
  1864. }
  1865. function get_total($args) {
  1866. $ret = 0;
  1867. $sql_where = self::_parse_where($args);
  1868. $sql = "select count(1) as cnt
  1869. from `USERS2_OFFERS_GROUPS` as g
  1870. where $sql_where
  1871. ";
  1872. $res = DB::query($sql);
  1873. if ($r = DB::fetch($res)) {
  1874. $ret = $r->cnt;
  1875. }
  1876. return $ret;
  1877. }
  1878. function get_items($args) {
  1879. $db = DB::getDB();
  1880. $external_offer_fields = array();
  1881. $external_offer_fields []= 'ID_NET';
  1882. $external_offer_fields []= 'ID_TEL';
  1883. $external_offer_fields []= 'ID_TV';
  1884. $external_offer_fields []= 'ID_TVC';
  1885. $external_offer_fields []= 'ID_TVCP_1';
  1886. $external_offer_fields []= 'ID_TVCP_2';
  1887. $external_offer_fields []= 'ID_TVCP_3';
  1888. $external_offer_fields []= 'ID_TVCP_4';
  1889. $oferty_ids = array();
  1890. $ret = array();
  1891. $sql_where = self::_parse_where($args);
  1892. $sql_select = array();
  1893. $cols = self::cols_groups();
  1894. foreach ($cols as $v_col) {
  1895. $sql_select []= "g.`" . $v_col . "`";
  1896. }
  1897. $sql_select = implode(", ", $sql_select);
  1898. $sql = "select {$sql_select}
  1899. from `USERS2_OFFERS_GROUPS` as g
  1900. where {$sql_where}
  1901. order by ID DESC
  1902. ";
  1903. $res = $db->query($sql);
  1904. while ($r = $db->fetch($res)) {
  1905. $ret [$r->ID] = $r;
  1906. foreach ($external_offer_fields as $external_offer_field) {
  1907. if ($r->$external_offer_field > 0) $oferty_ids [$r->$external_offer_field] []= $r->ID;
  1908. }
  1909. }
  1910. if (!empty($oferty_ids)) {
  1911. $sql_oferty_ids = array();
  1912. foreach ($oferty_ids as $k_offer_id => $v) {
  1913. $sql_oferty_ids []= "'" . $k_offer_id . "'";
  1914. }
  1915. $sql_select = array();
  1916. $cols = self::cols_offers();
  1917. foreach ($cols as $v_col) {
  1918. $sql_select []= "o.`" . $v_col . "`";
  1919. }
  1920. //$sql_select []= "'' as upust";
  1921. //$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`";
  1922. //$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";
  1923. //$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";
  1924. $sql_select = implode(", ", $sql_select);
  1925. $sql = "select {$sql_select}
  1926. from `USERS2_OFFERS` as o
  1927. where
  1928. o.`ID` in(" . implode(", ", $sql_oferty_ids) . ")
  1929. ";
  1930. $res = $db->query($sql);
  1931. while ($r = $db->fetch($res)) {
  1932. $group_ids_to_add = $oferty_ids[$r->ID];
  1933. foreach ($group_ids_to_add as $v_group_id) {
  1934. if (!isset($ret [$v_group_id]->oferty)) $ret [$v_group_id]->oferty = array();
  1935. $ret [$v_group_id]->oferty [$r->ID] = clone $r;
  1936. }
  1937. }
  1938. }
  1939. return $ret;
  1940. }
  1941. function get_offers_costs_by_offer_ids($offer_ids = array()) {
  1942. $oferty_costs = array();
  1943. $sql_where = "";
  1944. if (!empty($offer_ids)) {
  1945. $sql_where = "where o.`ID` in (" . implode(",", $offer_ids) . ")";
  1946. }
  1947. $sql = "select
  1948. o.`ID` as ID_OFERTY
  1949. , c.`P_OFFER_COSTS`
  1950. from `USERS2_OFFERS` as o
  1951. join `USERS2_OFFERS_COSTS_GROUPS` as c on (c.`ID`=o.`ID_COSTS_GROUPS`)
  1952. $sql_where
  1953. ";
  1954. $res = DB::query( $sql );
  1955. while ($r = DB::fetch( $res )) {
  1956. $oferty_costs[ $r->ID_OFERTY ] = $r->P_OFFER_COSTS;
  1957. }
  1958. return $oferty_costs;
  1959. }
  1960. }
  1961. class X_Column_Base {
  1962. var $_data;
  1963. var $_errors;
  1964. function __construct() {
  1965. $this->_errors = array();
  1966. $this->_data = array();
  1967. }
  1968. function get($field) {
  1969. return (array_key_exists($field, $this->_data))? $this->_data[$field] : '';
  1970. }
  1971. function set($field, $value) {
  1972. if (array_key_exists($field, $this->_data)) {
  1973. $this->_data[$field] = $value;
  1974. }
  1975. }
  1976. function get_cols() {
  1977. return array_keys($this->_data);
  1978. }
  1979. function get_data() {
  1980. return $this->_data;
  1981. }
  1982. function add_error($msg) {
  1983. $this->_errors []= $msg;
  1984. }
  1985. function get_errors() {
  1986. return $this->_errors;
  1987. }
  1988. function has_errors() {
  1989. return !empty($this->_errors);
  1990. }
  1991. }
  1992. class X_Column_users2_offers_groups extends X_Column_Base {
  1993. var $_offers;
  1994. var $_offers_by_id;
  1995. var $_id_options;
  1996. var $_group_external_offers_id;
  1997. var $suma_P_PROMO_INSTALL_PRICE = 0;
  1998. var $suma_P_PROMO_MONTH_PRICE = 0;
  1999. var $suma_P_CONTRACT_PRICE = 0;
  2000. var $suma_P_OFFER_SREDNIA = 0;
  2001. var $suma_P_OFFER_SREDNIA_NETTO = 0;
  2002. var $suma_P_OFFER_COSTS = 0;
  2003. function __construct() {
  2004. parent::__construct();
  2005. $this->_offers = array();
  2006. $this->_offers_by_id = array();
  2007. $this->_id_options = array();
  2008. $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');
  2009. $this->suma_P_PROMO_INSTALL_PRICE = 0;
  2010. $this->suma_P_PROMO_MONTH_PRICE = 0;
  2011. $this->suma_P_CONTRACT_PRICE = 0;
  2012. $this->suma_P_OFFER_SREDNIA = 0;
  2013. $this->suma_P_OFFER_SREDNIA_NETTO = 0;
  2014. $this->suma_P_OFFER_COSTS = 0;
  2015. }
  2016. function set_from_raw_data($db_row) {
  2017. foreach ($db_row as $k_field => $v_value) {
  2018. $this->_data[$k_field] = $v_value;
  2019. }
  2020. }
  2021. function has_offers() {
  2022. return !empty($this->_offers_by_id);
  2023. }
  2024. function get_offers() {
  2025. return $this->_offers;
  2026. }
  2027. function get_offers_by_id() {
  2028. return $this->_offers_by_id;
  2029. }
  2030. function set_offers($offers) {
  2031. $this->_offers_by_id = $offers;
  2032. $this->recount_costs();
  2033. $this->_convert_offers();
  2034. }
  2035. function set_id_options($id_options) {
  2036. $this->_id_options = $id_options;
  2037. }
  2038. function get_offers_ids() {
  2039. return array_keys($this->_offers_by_id);
  2040. }
  2041. function fetch_offers() {
  2042. $offers = array();
  2043. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2044. if ($this->get($k_external_id) > 0) {
  2045. $offers[$this->get($k_external_id)] = null;
  2046. }
  2047. }
  2048. foreach ($this->_id_options as $k_service => $v_options) {
  2049. if (empty($v_options)) continue;
  2050. foreach ($v_options as $v_option_id) {
  2051. if ($v_option_id > 0) {
  2052. $offers[$v_option_id] = null;
  2053. }
  2054. }
  2055. }
  2056. //$offers = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2057. $this->_offers_by_id = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2058. $this->recount_costs();
  2059. $this->_convert_offers();
  2060. }
  2061. /**
  2062. * Fetch offers by given ids and set _id_options.
  2063. * @param array $ids_offers - array of int - offers id
  2064. */
  2065. function fetch_offers_by_ids($ids_offers) {
  2066. $offers = array();
  2067. $options = array();
  2068. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2069. if ($this->get($k_external_id) > 0) {
  2070. $offers[$this->get($k_external_id)] = null;
  2071. }
  2072. }
  2073. foreach ($ids_offers as $v_offer_id) {
  2074. if (!array_key_exists($v_offer_id, $offers)) {
  2075. $offers[$v_offer_id] = null;
  2076. $options []= $v_offer_id;
  2077. }
  2078. }
  2079. $this->_offers_by_id = PokazOfertyHelper::get_offers_by_id(array_keys($offers), array('P_DEALTERM_MONTHS'=>$this->get('P_DEALTERM_MONTHS')));
  2080. $this->recount_costs();
  2081. foreach ($this->_offers_by_id as $v_offer) {
  2082. if (in_array($v_offer->ID, $options)) {
  2083. $this->_id_options[$v_offer->P_SERVICE_PARENT] []= $v_offer->ID;
  2084. }
  2085. }
  2086. $this->_convert_offers();
  2087. }
  2088. function get_options_by_service($p_service) {
  2089. if (array_key_exists($p_service, $this->_id_options)) {
  2090. $options = array();
  2091. foreach ($this->_id_options[$p_service] as $v_id_option) {
  2092. $option = V::get($v_id_option, '', $this->_offers_by_id);
  2093. if ($option) {
  2094. $options [$v_id_option] = $option;
  2095. }
  2096. }
  2097. return $options;
  2098. }
  2099. return null;
  2100. }
  2101. /**
  2102. * Convert $this->_offers_by_id to $this->_offers.
  2103. * Note: first run fetch_offers() or set_offers($offers) to set up $this->_offers;
  2104. */
  2105. function _convert_offers() {
  2106. $tmp_srv_id = array();// 'NET'=>1, 'TV'=>0, 'TEL'=>0, 'OPCJA_NET'=>2, 'OPCJA_TV'=>2
  2107. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2108. if ($this->get($k_external_id) > 0) {
  2109. $v_offer = $this->_offers_by_id[$this->get($k_external_id)];
  2110. if ($v_offer) {
  2111. $v_offer->out_id = $v_p_service;
  2112. // wiele uslug tego samego typu np. TVC
  2113. $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;
  2114. $v_offer->out_id = $v_offer->out_id . '_' . $tmp_srv_id[$v_offer->out_id];
  2115. $this->_offers [$v_offer->out_id] [$v_offer->ID] = $v_offer;
  2116. if (!empty($this->_id_options[$v_p_service])) {
  2117. foreach ($this->_id_options[$v_p_service] as $v_option_id) {
  2118. if ($v_option_id > 0) {
  2119. $v_option = V::get($v_option_id, null, $this->_offers);
  2120. if ($v_option) {
  2121. $v_option->out_id = 'OPCJA_' . $v_option->P_SERVICE_PARENT;
  2122. $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;
  2123. $v_option->out_id = $v_option->out_id . '_' . $tmp_srv_id[$v_option->out_id];
  2124. $this->_offers [$v_option->out_id] [$v_option->ID] = $v_option;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. unset($tmp_srv_id);
  2133. }
  2134. function recount_costs() {
  2135. $this->suma_P_PROMO_INSTALL_PRICE = 0;
  2136. $this->suma_P_PROMO_MONTH_PRICE = 0;
  2137. $this->suma_P_CONTRACT_PRICE = 0;
  2138. $this->suma_P_OFFER_SREDNIA = 0;
  2139. $this->suma_P_OFFER_SREDNIA_NETTO = 0;
  2140. $this->suma_P_OFFER_COSTS = 0;
  2141. $oferty_costs = Offers_Groups_Model::get_offers_costs_by_offer_ids(array_keys($this->_offers_by_id));
  2142. foreach ($this->_offers_by_id as $v_offer) {
  2143. $this->suma_P_PROMO_INSTALL_PRICE += $v_offer->P_INSTALL_QUOTE;
  2144. $this->suma_P_PROMO_MONTH_PRICE += $v_offer->P_PROMO_MONTH_PRICE;
  2145. $this->suma_P_CONTRACT_PRICE += $v_offer->P_CONTRACT_PRICE;
  2146. if (!isset($v_offer->srednia)) {
  2147. $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);
  2148. }
  2149. $this->suma_P_OFFER_SREDNIA += $v_offer->srednia;
  2150. if (!isset($v_offer->srednia_netto)) {
  2151. $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);
  2152. }
  2153. $this->suma_P_OFFER_SREDNIA_NETTO += $v_offer->srednia_netto;
  2154. if (isset($oferty_costs[$v_offer->ID])) {
  2155. $this->suma_P_OFFER_COSTS += $oferty_costs[$v_offer->ID];
  2156. }
  2157. }
  2158. }
  2159. function get_zysk_netto() {
  2160. $this->recount_costs();
  2161. return $this->suma_P_OFFER_SREDNIA_NETTO - $this->suma_P_OFFER_COSTS;
  2162. }
  2163. function has_service($p_service) {
  2164. foreach ($this->_group_external_offers_id as $k_external_id => $v_p_service) {
  2165. if ($v_p_service == $p_service) {
  2166. if ($this->get($k_external_id) > 0) {
  2167. return true;
  2168. }
  2169. }
  2170. }
  2171. return false;
  2172. }
  2173. }