index.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. <?php
  2. if (cfr('ROOT')) {
  3. set_time_limit (0);
  4. function web_MigrationUploadFormExten() {
  5. $delimiters = array(
  6. ';'=>';',
  7. '|'=>'|',
  8. ','=>','
  9. );
  10. $encodings = array(
  11. 'utf-8'=>'utf-8',
  12. 'windows-1251'=>'windows-1251',
  13. 'koi8-u'=>'koi8-u',
  14. 'cp866'=>'cp866'
  15. );
  16. $uploadinputs = wf_HiddenInput('uploaduserbase','true');
  17. $uploadinputs.= __('Upload userbase').' <input id="fileselector" type="file" name="uluserbase" size="10" /><br>';
  18. $uploadinputs.= wf_Selector('delimiter', $delimiters, __('Delimiter'), '', true);
  19. $uploadinputs.= wf_Selector('encoding', $encodings, __('Encoding'), '', true);
  20. $uploadinputs.= wf_Submit('Upload');
  21. $uploadform = bs_UploadFormBody('', 'POST', $uploadinputs, 'glamour');
  22. return ($uploadform);
  23. }
  24. function migrate_UploadFileExten() {
  25. //путь сохранения
  26. $uploaddir = 'exports/';
  27. //белый лист расширений
  28. $allowedExtensions = array("txt", "csv");
  29. //по умолчанию надеемся на худшее
  30. $result = false;
  31. //проверяем точно ли текстовку нам подсовывают
  32. foreach ($_FILES as $file) {
  33. if ($file['tmp_name'] > '') {
  34. if (@!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) {
  35. $errormessage = 'Wrong file type';
  36. die($errormessage);
  37. }
  38. }
  39. }
  40. $filename = vf($_FILES['uluserbase']['name']);
  41. $uploadfile = $uploaddir . $filename;
  42. if (move_uploaded_file($_FILES['uluserbase']['tmp_name'], $uploadfile)) {
  43. $result = $filename;
  44. }
  45. return ($result);
  46. }
  47. function web_MigrationPreprocessingExten($filename, $delimiter, $encoding) {
  48. $path = 'exports/';
  49. $raw_data = file_get_contents($path . $filename);
  50. $parsed_data = array();
  51. if ($encoding != 'utf-8') {
  52. $raw_data = iconv($encoding, 'utf-8', $raw_data);
  53. }
  54. $raw_data = explodeRows($raw_data);
  55. if (!empty($raw_data)) {
  56. foreach ($raw_data as $eachrow) {
  57. if (!empty($eachrow)) {
  58. $parsed_data[] = explode($delimiter, $eachrow);
  59. }
  60. }
  61. }
  62. if (sizeof($parsed_data) > 1) {
  63. $col_count = sizeof($parsed_data[0]);
  64. $cells = wf_TableCell(__('Column number'));
  65. $cells.= wf_TableCell(__('Column content'));
  66. $rows = wf_TableRow($cells, 'row1');
  67. foreach ($parsed_data[0] as $col_num => $col_data) {
  68. $cells = wf_TableCell($col_num);
  69. $cells.= wf_TableCell($col_data);
  70. $rows.= wf_TableRow($cells, 'row3');
  71. }
  72. $first_row = wf_TableBody($rows, '100%', '0', '');
  73. show_window(__('Found count of data columns'), $col_count);
  74. show_window(__('First of imported data rows'), $first_row);
  75. //construct of data processing form
  76. $rowNumArr = array();
  77. for ($i = 0; $i < $col_count; $i++) {
  78. $rowNumArr[$i] = $i;
  79. }
  80. $login_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  81. $password_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  82. $ip_arr = $rowNumArr;
  83. $mac_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  84. $tariff_arr = $rowNumArr;
  85. $cash_arr = $rowNumArr;
  86. $credit_arr = $rowNumArr + array('ZERO'=>__('Set to zero'));
  87. $creditex_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  88. $city_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  89. $street_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  90. $build_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  91. $apt_entrance_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  92. $apt_floor_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  93. $apt_apt_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  94. $phone_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  95. $mobile_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  96. $email_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  97. $address_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  98. $realname_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  99. $contract_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  100. $contract_d_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  101. $pasp_num_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  102. $pasp_date_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  103. $pasp_granted_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  104. $usr_comments_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  105. $tags_ids_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  106. $tags_names_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  107. $nas_ip_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  108. $ao_arr = $rowNumArr + array('AO_1'=>__('AlwaysOnline=1'));
  109. $down_arr = $rowNumArr + array('DOWN_0'=>__('Down=0'));
  110. $passive_arr = $rowNumArr + array('PASSIVE_0'=>__('Passive=0'));
  111. $regtype_arr = array('UB'=>'Ubilling live register');
  112. //data column setting form
  113. $inputs = wf_Selector('login_col', $login_arr, __('User login'), '0', true);
  114. $inputs.= wf_Selector('password_col', $password_arr, __('User password'), '1', true);
  115. $inputs.= wf_Selector('ip_col', $ip_arr, __('User IP (will get first free IP from chosen subnet/NAS subnet if the field will be actually empty)'), '2', true);
  116. $inputs.= wf_Selector('mac_col', $mac_arr, __('User MAC'), '3', true);
  117. $inputs.= wf_Selector('tariff_col', $tariff_arr, __('User tariff'), '4', true);
  118. $inputs.= wf_Selector('cash_col', $cash_arr, __('User cash'), '5', true);
  119. $inputs.= wf_Selector('credit_col', $credit_arr, __('User credit limit'), '6', true);
  120. $inputs.= wf_Selector('creditex_col', $creditex_arr, __('User credit expire date'), '7', true);
  121. $inputs.= wf_Selector('city_col', $city_arr, __('User city'), '8', true);
  122. $inputs.= wf_Selector('street_col', $street_arr, __('User street'), '9', true);
  123. $inputs.= wf_Selector('build_col', $build_arr, __('User build'), '10', true);
  124. $inputs.= wf_Selector('apt_entrance_col', $apt_entrance_arr, __('User entrance'), '11', true);
  125. $inputs.= wf_Selector('apt_floor_col', $apt_floor_arr, __('User floor'), '12', true);
  126. $inputs.= wf_Selector('apt_apt_col', $apt_apt_arr, __('User apt'), '13', true);
  127. $inputs.= wf_Selector('phone_col', $phone_arr, __('User phone'), '14', true);
  128. $inputs.= wf_Selector('mobile_col', $mobile_arr, __('User mobile'), '15', true);
  129. $inputs.= wf_Selector('email_col', $email_arr, __('User email'), '16', true);
  130. $inputs.= wf_Selector('address_col', $address_arr, __('User address (will be added to user notes if no occupancy created for user)'), '17', true);
  131. $inputs.= wf_Selector('realname_col', $realname_arr, __('User realname'), '18', true);
  132. $inputs.= wf_Selector('contract_col', $contract_arr, __('User contract'), '19', true);
  133. $inputs.= wf_Selector('contract_d_col', $contract_d_arr, __('User contract date'), '20', true);
  134. $inputs.= wf_Selector('pasp_num_col', $pasp_num_arr, __('User passport number'), '21', true);
  135. $inputs.= wf_Selector('pasp_date_col', $pasp_date_arr, __('User passport date'), '22', true);
  136. $inputs.= wf_Selector('pasp_granted_col', $pasp_granted_arr, __('User passport granted by'), '23', true);
  137. $inputs.= wf_Selector('usr_comments_col', $usr_comments_arr, __('User comments'), '24', true);
  138. $inputs.= wf_Selector('tags_ids_col', $tags_ids_arr, __('Tags IDs to assign with user delimited with ","'), '25', true);
  139. $inputs.= wf_Selector('tags_names_col', $tags_names_arr, __('Tags names to assign with user delimited with ","'), '26', true);
  140. $inputs.= wf_Selector('ao_col', $ao_arr, __('User AlwaysOnline state'), '27', true);
  141. $inputs.= wf_Selector('down_col', $down_arr, __('User Down state'), '28', true);
  142. $inputs.= wf_Selector('passive_col', $passive_arr, __('User Passive state'), '29', true);
  143. $inputs.= wf_Selector('nas_ip_col', $nas_ip_arr, __('NAS IP address - for NASes with UNIQUE IPs ONLY. Use NAS IP to get user\'s subnet ID and fallback to chosen in a field below, if NAS IP is empty'), '31', true);
  144. $inputs.= multinet_network_selector() . __('Target network') . wf_delimiter();
  145. $inputs.= wf_Selector('regtype', $regtype_arr, __('User registration mode'), '30', true);
  146. $inputs.= wf_delimiter(0);
  147. $inputs.= wf_TextInput('skiprowscount', __('Skip specified numbers of rows from the beginning of .CSV/.TXT file (if those rows are empty, or contain fields captions, or whatever)'), 0, true, '4', 'digits');
  148. $inputs.= wf_delimiter(0);
  149. $inputs.= wf_Plate('Please, split your import CSV data to a smaller chunks (by settlement, street, NAS, targeted network or whatever) to prevent import issues and reduce import time',
  150. '', '', 'glamour', 'color: red;');
  151. $inputs.= wf_delimiter(2);
  152. $inputs.= wf_HiddenInput('import_rawdata', base64_encode(serialize($parsed_data)));
  153. $inputs.= wf_Submit('Save this column pointers and continue import');
  154. $colform = wf_Form("?module=migration2_exten&setpointers=true", 'POST', $inputs, 'glamour');
  155. show_window(__('Select data columns and their values'), $colform);
  156. } else {
  157. show_error(__('Parsing error'));
  158. }
  159. }
  160. function web_MigrationPrepareExten($import_rawdata, $import_opts, $skiprowscnt) {
  161. $import_rawdata = unserialize(base64_decode($import_rawdata));
  162. $import_opts = unserialize(base64_decode($import_opts));
  163. $cells = wf_TableCell('#');
  164. $cells.= wf_TableCell('[login]');
  165. $cells.= wf_TableCell('[password]');
  166. $cells.= wf_TableCell('[ip]');
  167. $cells.= wf_TableCell('[mac]');
  168. $cells.= wf_TableCell('[tariff]');
  169. $cells.= wf_TableCell('[cash]');
  170. $cells.= wf_TableCell('[phone]');
  171. $cells.= wf_TableCell('[mobile]');
  172. $cells.= wf_TableCell('[email]');
  173. $cells.= wf_TableCell('[credit]');
  174. $cells.= wf_TableCell('[creditex]');
  175. $cells.= wf_TableCell('[city]');
  176. $cells.= wf_TableCell('[street]');
  177. $cells.= wf_TableCell('[build]');
  178. $cells.= wf_TableCell('[apt_entrance]');
  179. $cells.= wf_TableCell('[apt_floor]');
  180. $cells.= wf_TableCell('[apt_apt]');
  181. $cells.= wf_TableCell('[address]');
  182. $cells.= wf_TableCell('[realname]');
  183. $cells.= wf_TableCell('[contract]');
  184. $cells.= wf_TableCell('[contract_d]');
  185. $cells.= wf_TableCell('[pasp_num]');
  186. $cells.= wf_TableCell('[pasp_date]');
  187. $cells.= wf_TableCell('[pasp_granted]');
  188. $cells.= wf_TableCell('[usr_comments]');
  189. $cells.= wf_TableCell('[tags_ids]');
  190. $cells.= wf_TableCell('[tags_names]');
  191. $cells.= wf_TableCell('[ao]');
  192. $cells.= wf_TableCell('[down]');
  193. $cells.= wf_TableCell('[passive]');
  194. $cells.= wf_TableCell('[nas_ip]');
  195. $rows = wf_TableRow($cells, 'row1');
  196. $regdata = array();
  197. $i = 0;
  198. foreach ($import_rawdata as $eachrow) {
  199. $i++;
  200. if (!empty($skiprowscnt) and $i <= $skiprowscnt) {
  201. continue;
  202. }
  203. // mandatory columns values
  204. $ip = $eachrow[$import_opts['ip_col']];
  205. $tariff = $eachrow[$import_opts['tariff_col']];
  206. $cash = $eachrow[$import_opts['cash_col']];
  207. // optional columns values
  208. if ($import_opts['login_col'] != 'RANDOM') {
  209. $login = $eachrow[$import_opts['login_col']];
  210. } else {
  211. $login = 'mi_'.zb_rand_string(8);
  212. }
  213. if ($import_opts['password_col'] != 'RANDOM') {
  214. $password=$eachrow[$import_opts['password_col']];
  215. } else {
  216. $password = zb_rand_string(10);
  217. }
  218. if ($import_opts['mac_col'] != 'RANDOM') {
  219. $mac=$eachrow[$import_opts['mac_col']];
  220. } else {
  221. $mac = '11:' . '77' . ':' . rand(10,99) . ':' . rand(10,99) . ':' . rand(10,99) . ':' . rand(10,99);
  222. }
  223. if ($import_opts['phone_col'] != 'NONE') {
  224. $phone=$eachrow[$import_opts['phone_col']];
  225. } else {
  226. $phone = '';
  227. }
  228. if ($import_opts['mobile_col'] != 'NONE') {
  229. $mobile=$eachrow[$import_opts['mobile_col']];
  230. } else {
  231. $mobile = '';
  232. }
  233. if ($import_opts['email_col'] != 'NONE') {
  234. $email = str_replace('"', '', $eachrow[$import_opts['email_col']]);
  235. } else {
  236. $email = '';
  237. }
  238. if ($import_opts['credit_col'] != 'ZERO') {
  239. $credit = $eachrow[$import_opts['credit_col']];
  240. } else {
  241. $credit = 0;
  242. }
  243. if ($import_opts['creditex_col'] != 'NONE') {
  244. $creditex = $eachrow[$import_opts['creditex_col']];
  245. } else {
  246. $creditex = '0';
  247. }
  248. if ($import_opts['city_col'] != 'NONE') {
  249. $city = str_replace('"', '', $eachrow[$import_opts['city_col']]);
  250. } else {
  251. $city = '';
  252. }
  253. if ($import_opts['street_col'] != 'NONE') {
  254. $street = str_replace('"', '', $eachrow[$import_opts['street_col']]);
  255. } else {
  256. $street = '';
  257. }
  258. if ($import_opts['build_col'] != 'NONE') {
  259. $build = str_replace('"', '', $eachrow[$import_opts['build_col']]);
  260. } else {
  261. $build = '';
  262. }
  263. if ($import_opts['apt_entrance_col'] != 'NONE') {
  264. $apt_entrance = str_replace('"', '', $eachrow[$import_opts['apt_entrance_col']]);
  265. } else {
  266. $apt_entrance = '';
  267. }
  268. if ($import_opts['apt_floor_col'] != 'NONE') {
  269. $apt_floor = str_replace('"', '', $eachrow[$import_opts['apt_floor_col']]);
  270. } else {
  271. $apt_floor = '';
  272. }
  273. if ($import_opts['apt_apt_col'] != 'NONE') {
  274. $apt_apt = str_replace('"', '', $eachrow[$import_opts['apt_apt_col']]);
  275. } else {
  276. $apt_apt = '';
  277. }
  278. if ($import_opts['address_col'] != 'NONE') {
  279. $address = str_replace('"', '', $eachrow[$import_opts['address_col']]);
  280. } else {
  281. $address = '';
  282. }
  283. if ($import_opts['realname_col'] != 'NONE') {
  284. $realname = str_replace('"', '', $eachrow[$import_opts['realname_col']]);
  285. } else {
  286. $realname = '';
  287. }
  288. if ($import_opts['contract_col'] != 'NONE') {
  289. $contract = str_replace('"', '', $eachrow[$import_opts['contract_col']]);
  290. } else {
  291. $contract = '';
  292. }
  293. if ($import_opts['contract_d_col'] != 'NONE') {
  294. $contract_d = $eachrow[$import_opts['contract_d_col']];
  295. } else {
  296. $contract_d = '';
  297. }
  298. if ($import_opts['pasp_num_col'] != 'NONE') {
  299. $pasp_num = str_replace('"', '', $eachrow[$import_opts['pasp_num_col']]);
  300. } else {
  301. $pasp_num = '';
  302. }
  303. if ($import_opts['pasp_date_col'] != 'NONE') {
  304. $pasp_date = str_replace('"', '', $eachrow[$import_opts['pasp_date_col']]);
  305. } else {
  306. $pasp_date = '';
  307. }
  308. if ($import_opts['pasp_granted_col'] != 'NONE') {
  309. $pasp_granted = str_replace('"', '', $eachrow[$import_opts['pasp_granted_col']]);
  310. } else {
  311. $pasp_granted = '';
  312. }
  313. if ($import_opts['usr_comments_col'] != 'NONE') {
  314. $usr_comments = str_replace('"', '', $eachrow[$import_opts['usr_comments_col']]);
  315. } else {
  316. $usr_comments = '';
  317. }
  318. if ($import_opts['tags_ids_col'] != 'NONE') {
  319. $tags_ids = $eachrow[$import_opts['tags_ids_col']];
  320. } else {
  321. $tags_ids = '';
  322. }
  323. if ($import_opts['tags_names_col'] != 'NONE') {
  324. $tags_names = str_replace('"', '', $eachrow[$import_opts['tags_names_col']]);
  325. } else {
  326. $tags_names = '';
  327. }
  328. if ($import_opts['ao_col'] != 'AO_1') {
  329. $ao=$eachrow[$import_opts['ao_col']];
  330. } else {
  331. $ao=1;
  332. }
  333. if ($import_opts['down_col'] != 'DOWN_0') {
  334. $down=$eachrow[$import_opts['down_col']];
  335. } else {
  336. $down=0;
  337. }
  338. if ($import_opts['passive_col'] != 'PASSIVE_0') {
  339. $passive=$eachrow[$import_opts['passive_col']];
  340. } else {
  341. $passive=0;
  342. }
  343. if ($import_opts['nas_ip_col'] != 'NONE') {
  344. $nas_ip = $eachrow[$import_opts['nas_ip_col']];
  345. } else {
  346. $nas_ip = '';
  347. }
  348. // getting table row
  349. $cells = wf_TableCell($i);
  350. $cells.= wf_TableCell($login);
  351. $cells.= wf_TableCell($password);
  352. $cells.= wf_TableCell($ip);
  353. $cells.= wf_TableCell($mac);
  354. $cells.= wf_TableCell($tariff);
  355. $cells.= wf_TableCell($cash);
  356. $cells.= wf_TableCell($phone);
  357. $cells.= wf_TableCell($mobile);
  358. $cells.= wf_TableCell($email);
  359. $cells.= wf_TableCell($credit);
  360. $cells.= wf_TableCell($creditex);
  361. $cells.= wf_TableCell($city);
  362. $cells.= wf_TableCell($street);
  363. $cells.= wf_TableCell($build);
  364. $cells.= wf_TableCell($apt_entrance);
  365. $cells.= wf_TableCell($apt_floor);
  366. $cells.= wf_TableCell($apt_apt);
  367. $cells.= wf_TableCell($address);
  368. $cells.= wf_TableCell($realname);
  369. $cells.= wf_TableCell($contract);
  370. $cells.= wf_TableCell($contract_d);
  371. $cells.= wf_TableCell($pasp_num);
  372. $cells.= wf_TableCell($pasp_date);
  373. $cells.= wf_TableCell($pasp_granted);
  374. $cells.= wf_TableCell($usr_comments);
  375. $cells.= wf_TableCell($tags_ids);
  376. $cells.= wf_TableCell($tags_names);
  377. $cells.= wf_TableCell($ao);
  378. $cells.= wf_TableCell($down);
  379. $cells.= wf_TableCell($passive);
  380. $cells.= wf_TableCell($nas_ip);
  381. $rows.= wf_TableRow($cells, 'row3');
  382. // filling userreg array
  383. $regdata[$login]['login'] = $login;
  384. $regdata[$login]['password'] = $password;
  385. $regdata[$login]['ip'] = $ip;
  386. $regdata[$login]['mac'] = $mac;
  387. $regdata[$login]['tariff'] = $tariff;
  388. $regdata[$login]['cash'] = $cash;
  389. $regdata[$login]['phone'] = $phone;
  390. $regdata[$login]['mobile'] = $mobile;
  391. $regdata[$login]['email'] = $email;
  392. $regdata[$login]['credit'] = $credit;
  393. $regdata[$login]['creditex'] = $creditex;
  394. $regdata[$login]['city'] = $city;
  395. $regdata[$login]['street'] = $street;
  396. $regdata[$login]['build'] = $build;
  397. $regdata[$login]['apt_entrance'] = $apt_entrance;
  398. $regdata[$login]['apt_floor'] = $apt_floor;
  399. $regdata[$login]['apt_apt'] = $apt_apt;
  400. $regdata[$login]['address'] = $address;
  401. $regdata[$login]['realname'] = $realname;
  402. $regdata[$login]['contract'] = $contract;
  403. $regdata[$login]['contract_d'] = $contract_d;
  404. $regdata[$login]['pasp_num'] = $pasp_num;
  405. $regdata[$login]['pasp_date'] = $pasp_date;
  406. $regdata[$login]['pasp_granted'] = $pasp_granted;
  407. $regdata[$login]['usr_comments'] = $usr_comments;
  408. $regdata[$login]['tags_ids'] = $tags_ids;
  409. $regdata[$login]['tags_names'] = $tags_names;
  410. $regdata[$login]['ao'] = $ao;
  411. $regdata[$login]['down'] = $down;
  412. $regdata[$login]['passive'] = $passive;
  413. $regdata[$login]['nas_ip'] = $nas_ip;
  414. }
  415. $regdata_save = serialize($regdata);
  416. $regdata_save = base64_encode($regdata_save);
  417. zb_StorageSet('IMPORT_REGDATA', $regdata_save);
  418. $preparse = wf_TableBody($rows, '100%', '0', '');
  419. show_window(__('All correct') . '?', $preparse);
  420. $inputs = wf_tag('h3', false, '', 'style="font: bold;"');
  421. $inputs.= $skiprowscnt . wf_nbsp(2) . 'rows skipped from the beginning of the import file';
  422. $inputs.= wf_tag('h3', true);
  423. $inputs.= wf_delimiter(0);
  424. $inputs.= wf_Link('?module=migration2_exten', 'No I want to try another import settings', false, 'ubButton');
  425. $inputs.= wf_delimiter(2);
  426. $inputs.= wf_Link('?module=migration2_exten&setpointers=true&goregister=ok', 'Yes, proceed registration of this users (no occupancy and tags will be created)', false, 'ubButton');
  427. $inputs.= wf_delimiter();
  428. $inputs.= wf_tag('h3', false, '', 'style="color: red; background-color: #F5F5DC"');
  429. $inputs.= 'Creating occupancy(cities, streets, buildings, addresses, tags, etc) for new users avialable ONLY for "Ubilling live register" user registration mode. ';
  430. $inputs.= wf_delimiter(0);
  431. $inputs.= 'Nevertheless this feature has to be used with GREAT CARE and for your OWN RISK';
  432. $inputs.= wf_tag('h3', true);
  433. $inputs.= wf_Link('?module=migration2_exten&setpointers=true&goregister=ok&create_accupancy=yes&create_tags=yes',
  434. 'Yes, proceed registration of this users and create occupancy and tags if not exists.', false, 'ubButton');
  435. show_window('', $inputs);
  436. }
  437. if (!ubRouting::checkGet('setpointers')) {
  438. if(!ubRouting::checkPost('uploaduserbase')) {
  439. //show upload form
  440. show_window(__('User database import from text file'), web_MigrationUploadFormExten());
  441. } else {
  442. //upload file and show preprocessing form
  443. $upload_done = migrate_UploadFileExten();
  444. if ($upload_done) {
  445. $delimiter = ubRouting::post('delimiter');
  446. $encoding = ubRouting::post('encoding');
  447. web_MigrationPreprocessingExten($upload_done, $delimiter, $encoding);
  448. }
  449. }
  450. } else {
  451. //some pointers already set, load raw data into database for processing
  452. if (ubRouting::checkPost('import_rawdata')) {
  453. $import_rawdata = ubRouting::post('import_rawdata');
  454. zb_StorageSet('IMPORT_RAWDATA', $import_rawdata);
  455. $import_opts = array(
  456. 'login_col' => ubRouting::post('login_col'),
  457. 'password_col' => ubRouting::post('password_col'),
  458. 'ip_col' => ubRouting::post('ip_col'),
  459. 'mac_col' => ubRouting::post('mac_col'),
  460. 'tariff_col' => ubRouting::post('tariff_col'),
  461. 'cash_col' => ubRouting::post('cash_col'),
  462. 'phone_col' => ubRouting::post('phone_col'),
  463. 'mobile_col' => ubRouting::post('mobile_col'),
  464. 'email_col' => ubRouting::post('email_col'),
  465. 'credit_col' => ubRouting::post('credit_col'),
  466. 'creditex_col' => ubRouting::post('creditex_col'),
  467. 'city_col' => ubRouting::post('city_col'),
  468. 'street_col' => ubRouting::post('street_col'),
  469. 'build_col' => ubRouting::post('build_col'),
  470. 'apt_entrance_col' => ubRouting::post('apt_entrance_col'),
  471. 'apt_floor_col' => ubRouting::post('apt_floor_col'),
  472. 'apt_apt_col' => ubRouting::post('apt_apt_col'),
  473. 'address_col' => ubRouting::post('address_col'),
  474. 'contract_col' => ubRouting::post('contract_col'),
  475. 'realname_col' => ubRouting::post('realname_col'),
  476. 'contract_d_col' => ubRouting::post('contract_d_col'),
  477. 'pasp_num_col' => ubRouting::post('pasp_num_col'),
  478. 'pasp_date_col' => ubRouting::post('pasp_date_col'),
  479. 'pasp_granted_col' => ubRouting::post('pasp_granted_col'),
  480. 'usr_comments_col' => ubRouting::post('usr_comments_col'),
  481. 'tags_ids_col' => ubRouting::post('tags_ids_col'),
  482. 'tags_names_col' => ubRouting::post('tags_names_col'),
  483. 'nas_ip_col' => ubRouting::post('nas_ip_col'),
  484. 'ao_col' => ubRouting::post('ao_col'),
  485. 'down_col' => ubRouting::post('down_col'),
  486. 'passive_col' => ubRouting::post('passive_col'),
  487. 'netid' => ubRouting::post('networkselect'),
  488. 'regtype' => ubRouting::post('regtype')
  489. );
  490. $import_opts = serialize($import_opts);
  491. $import_opts = base64_encode($import_opts);
  492. zb_StorageSet('IMPORT_OPTS', $import_opts);
  493. } else {
  494. $import_rawdata = zb_StorageGet('IMPORT_RAWDATA');
  495. $import_opts = zb_StorageGet('IMPORT_OPTS');
  496. }
  497. //last checks
  498. if (!ubRouting::checkGet('goregister')) {
  499. $skiprowscnt = ubRouting::post('skiprowscount');
  500. web_MigrationPrepareExten($import_rawdata, $import_opts, $skiprowscnt);
  501. } else {
  502. $createOccupancy = ( ubRouting::checkGet('create_accupancy') ? true : false );
  503. $createTags = ( ubRouting::checkGet('create_tags') ? true : false );
  504. //register imported users
  505. $regdata_raw = zb_StorageGet('IMPORT_REGDATA');
  506. $regdata = unserialize(base64_decode($regdata_raw));
  507. $querybuff = '';
  508. if (!empty($regdata)) {
  509. $RegAddrs = array();
  510. $iopts = unserialize(base64_decode($import_opts));
  511. $allTags = stg_get_alltagnames();
  512. $allTagsReversed = array_flip($allTags);
  513. $allNASes = zb_NasGetAllData();
  514. $randomBuilds = array();
  515. // creating tags in tags table
  516. if ($createTags && $iopts['regtype'] == 'UB') {
  517. $allTagsNamesToImport = array();
  518. // getting unique tag names
  519. foreach ($regdata as $io => $user) {
  520. if (!empty($user['tags_names'])) {
  521. $tArr = explode(',', $user['tags_names']);
  522. foreach ($tArr as $item) {
  523. $tagName = trim($item);
  524. if (array_key_exists($tagName, $allTagsReversed) or in_array($tagName, $allTagsNamesToImport)) {
  525. continue;
  526. } else {
  527. $allTagsNamesToImport[] = $tagName;
  528. }
  529. }
  530. }
  531. }
  532. if (!empty($allTagsNamesToImport)) {
  533. foreach ($allTagsNamesToImport as $tag) {
  534. $tagColor = '#' . rand(11, 99) . rand(11, 99) . rand(11, 99);
  535. $tagPriority = 4;
  536. $text = mysql_real_escape_string($tag);
  537. $query = "INSERT INTO `tagtypes` (`id` ,`tagcolor` ,`tagsize` ,`tagname`) VALUES (NULL , '" . $tagColor . "', '" . $tagPriority . "', '" . $text . "');";
  538. nr_query($query);
  539. $newId = simple_get_lastid('tagtypes');
  540. log_register('TAGTYPE ADD `' . $text . '` [' . $newId . ']');
  541. }
  542. }
  543. }
  544. // creating settlements, streets, addresses and so on
  545. if ($createOccupancy && $iopts['regtype'] == 'UB') {
  546. // getting unique cities and streets names with buildings
  547. foreach ($regdata as $io => $user) {
  548. $tmpRegCity = (empty($user['city'])) ? 'Unknown_city' : $user['city'];
  549. $tmpRegStreet = (empty($user['street'])) ? 'Unknown_street' : $user['street'];
  550. if (empty($user['build'])) {
  551. $tmpRegBuilding = 4000 + rand(1, 9999);
  552. $randomBuilds[$user['login']] = $tmpRegBuilding;
  553. } else {
  554. $tmpRegBuilding = $user['build'];
  555. }
  556. if (!array_key_exists($tmpRegCity, $RegAddrs)) {
  557. $RegAddrs[$tmpRegCity] = array();
  558. }
  559. if (!array_key_exists($tmpRegStreet, $RegAddrs[$tmpRegCity])) {
  560. $RegAddrs[$tmpRegCity][$tmpRegStreet] = array();
  561. }
  562. if (!in_array($tmpRegBuilding, $RegAddrs[$tmpRegCity][$tmpRegStreet])) {
  563. $RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding] = array('id' => '');
  564. }
  565. }
  566. if ( !empty($RegAddrs) ) {
  567. foreach ($RegAddrs as $tCity => $CityData) {
  568. $CityWasJustCreated = false;
  569. $tmpQuery = "SELECT * FROM `city` WHERE LOWER(`cityname`) = '" . mb_strtolower($tCity) . "';";
  570. $tmpResult = simple_queryall($tmpQuery);
  571. if (!empty($tmpResult)) {
  572. $tCityID = $tmpResult[0]['id'];
  573. } else {
  574. zb_AddressCreateCity($tCity, '');
  575. $tCityID = simple_get_lastid('city');
  576. $CityWasJustCreated = true;
  577. }
  578. foreach ($CityData as $tStreet => $tBuilds) {
  579. $StreetWasJustCreated = false;
  580. $NeedCreateStreet = true;
  581. // if city was not just created - let's check, maybe there is such street in DB already
  582. if (!$CityWasJustCreated) {
  583. $tmpQuery = "SELECT * FROM `street` WHERE `cityid` = '" . $tCityID . "' AND LOWER(`streetname`) = '" . mb_strtolower($tStreet) . "';";
  584. $tmpResult = simple_queryall($tmpQuery);
  585. if (!empty($tmpResult)) {
  586. $tStreetID = $tmpResult[0]['id'];
  587. $NeedCreateStreet = false;
  588. }
  589. }
  590. if ($NeedCreateStreet) {
  591. zb_AddressCreateStreet($tCityID, $tStreet, '');
  592. $tStreetID = simple_get_lastid('street');
  593. $StreetWasJustCreated = true;
  594. }
  595. foreach ($tBuilds as $tBuild => $tID) {
  596. $NeedCreateBuilding = true;
  597. // if street was not just created - let's check, maybe there is such building in DB already
  598. if (!$StreetWasJustCreated) {
  599. $tmpQuery = "SELECT * FROM `build` WHERE `streetid` = '" . $tStreetID . "' AND LOWER(`buildnum`) = '" . mb_strtolower($tBuild) . "';";
  600. $tmpResult = simple_queryall($tmpQuery);
  601. if (!empty($tmpResult)) {
  602. $tBuildingID = $tmpResult[0]['id'];
  603. $NeedCreateBuilding = false;
  604. }
  605. }
  606. if ($NeedCreateBuilding) {
  607. zb_AddressCreateBuild($tStreetID, $tBuild);
  608. $tBuildingID = simple_get_lastid('build');
  609. }
  610. $RegAddrs[$tCity][$tStreet][$tBuild]['id'] = $tBuildingID;
  611. }
  612. }
  613. }
  614. }
  615. }
  616. foreach ($regdata as $io => $user) {
  617. debarr($user);
  618. //typical register of each user
  619. $login = vf($user['login']);
  620. $password = vf($user['password']);
  621. $ip = $user['ip'];
  622. $iopts = unserialize(base64_decode($import_opts));
  623. $netid = $iopts['netid'];
  624. if (empty($ip)) {
  625. $netidNAS = 0;
  626. if (!empty($user['nas_ip'])) {
  627. foreach ($allNASes as $eachNAS) {
  628. if ($eachNAS['nasip'] == $user['nas_ip']) {
  629. $netidNAS = $eachNAS['netid'];
  630. break;
  631. }
  632. }
  633. }
  634. // trying to get first free IP either from NAS's or chosen net ID
  635. if (empty($netidNAS)) {
  636. $ip = multinet_get_next_freeip('nethosts', 'ip', $netid);
  637. } else {
  638. $ip = multinet_get_next_freeip('nethosts', 'ip', $netidNAS);
  639. $netid = $netidNAS;
  640. }
  641. }
  642. //Ubilling normal registration mode
  643. if ($iopts['regtype'] == 'UB') {
  644. $billing->createuser($login);
  645. log_register("StgUser REGISTER " . $login);
  646. $billing->setpassword($login, $password);
  647. log_register("StgUser PASSWORD " . $password);
  648. $billing->setip($login, $ip);
  649. log_register("StgUser IP " . $ip);
  650. multinet_add_host($netid, $ip);
  651. zb_UserCreateRealName($login, $user['realname']);
  652. zb_UserCreatePhone($login, $user['phone'], $user['mobile']);
  653. zb_UserCreateContract($login, $user['contract']);
  654. zb_UserContractDateCreate($user['contract'], date('Y-m-d', strtotime($user['contract_d'])));
  655. zb_UserCreateEmail($login, $user['email']);
  656. zb_UserCreateSpeedOverride($login, 0);
  657. multinet_change_mac($ip, $user['mac']);
  658. multinet_rebuild_all_handlers();
  659. $billing->setao($login, $user['ao']);
  660. $dstat = 1;
  661. $billing->setdstat($login, $dstat);
  662. $billing->setdown($login, $user['down']);
  663. $billing->setpassive($login, $user['passive']);
  664. $billing->settariff($login, $user['tariff']);
  665. $billing->setcredit($login, $user['credit']);
  666. $billing->setcash($login, $user['cash']);
  667. zb_UserPassportDataCreate($login, '', $user['pasp_num'], $user['pasp_date'], $user['pasp_granted'], '', '', '', '');
  668. // assign tags to users
  669. if ($createTags) {
  670. if (empty($allTagsReversed)) {
  671. $allTags = (empty($allTags) ? stg_get_alltagnames() : $allTags);
  672. $allTagsReversed = array_flip($allTags);
  673. }
  674. if (!empty($allTagsReversed)) {
  675. $usrTagsIDs = explode(',', $user['tags_ids']);
  676. $usrTagsNames = explode(',', $user['tags_names']);
  677. if (!empty($usrTagsIDs)) {
  678. foreach ($usrTagsIDs as $usrTagsID) {
  679. $tagID = trim($usrTagsID);
  680. // if such tagID even exists?
  681. if (!empty($allTags[$tagID])) {
  682. stg_add_user_tag($login, $tagID);
  683. }
  684. }
  685. }
  686. if (!empty($usrTagsNames)) {
  687. foreach ($usrTagsNames as $usrTagsName) {
  688. $tagName = trim($usrTagsName);
  689. // if such tagName even exists?
  690. if (!empty($allTagsReversed[$tagName])) {
  691. stg_add_user_tag($login, $allTagsReversed[$tagName]);
  692. }
  693. }
  694. }
  695. }
  696. }
  697. $NoOccupancyCreated = true;
  698. if ($createOccupancy) {
  699. $tmpRegCity = (empty($user['city'])) ? 'Unknown_city' : $user['city'];
  700. $tmpRegStreet = (empty($user['street'])) ? 'Unknown_street' : $user['street'];
  701. $tmpRegBuilding = (empty($user['build']) and !empty($randomBuilds[$login])) ? $randomBuilds[$login] : $user['build'];
  702. $tmpRegAptEntrance = $user['apt_entrance'];
  703. $tmpRegAptFloor = $user['apt_floor'];
  704. $tmpRegApt = $user['apt_apt'];
  705. $tBuildingID = '';
  706. // try to get build ID from $RegAddrs array which was processed earlier
  707. // and create araptment and address for the user
  708. if ( !empty($RegAddrs) ) {
  709. if (isset($RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding]['id'])) {
  710. $tBuildingID = $RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding]['id'];
  711. zb_AddressCreateApartment($tBuildingID, $tmpRegAptEntrance, $tmpRegAptFloor, $tmpRegApt);
  712. $tAptID = simple_get_lastid('apt');
  713. zb_AddressCreateAddress($login, $tAptID);
  714. $NoOccupancyCreated = false;
  715. }
  716. }
  717. }
  718. $userNotes = $user['usr_comments'];
  719. if ($NoOccupancyCreated) {
  720. zb_UserCreateNotes($login, $user['address'] . ' ' . $userNotes);
  721. } elseif (!empty($userNotes)) {
  722. zb_UserCreateNotes($login, $userNotes);
  723. }
  724. }
  725. }
  726. }
  727. }
  728. }
  729. } else {
  730. show_error(__('Access denied'));
  731. }
  732. ?>