index.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. <?php
  2. /*
  3. Modify by SoulRoot
  4. 09.12.2014
  5. */
  6. if (cfr('ROOT')) {
  7. set_time_limit (0);
  8. /*START ADD*/
  9. function translit($string) {
  10. $converter = array(
  11. 'а' => 'a', 'б' => 'b', 'в' => 'v',
  12. 'г' => 'g', 'д' => 'd', 'е' => 'e',
  13. 'ё' => 'e', 'ж' => 'zh', 'з' => 'z',
  14. 'и' => 'i', 'й' => 'y', 'к' => 'k',
  15. 'л' => 'l', 'м' => 'm', 'н' => 'n',
  16. 'о' => 'o', 'п' => 'p', 'р' => 'r',
  17. 'с' => 's', 'т' => 't', 'у' => 'u',
  18. 'ф' => 'f', 'х' => 'h', 'ц' => 'c',
  19. 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch',
  20. 'ь' => '', 'ы' => 'y', 'ъ' => '',
  21. 'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
  22. 'А' => 'A', 'Б' => 'B', 'В' => 'V',
  23. 'Г' => 'G', 'Д' => 'D', 'Е' => 'E',
  24. 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z',
  25. 'И' => 'I', 'Й' => 'Y', 'К' => 'K',
  26. 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
  27. 'О' => 'O', 'П' => 'P', 'Р' => 'R',
  28. 'С' => 'S', 'Т' => 'T', 'У' => 'U',
  29. 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
  30. 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch',
  31. 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
  32. 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
  33. );
  34. return strtr($string, $converter);
  35. }
  36. /*END ADD*/
  37. function web_MigrationUploadForm() {
  38. $delimiters=array(
  39. ';'=>';',
  40. '|'=>'|',
  41. ','=>','
  42. );
  43. $encodings=array(
  44. 'utf-8'=>'utf-8',
  45. 'windows-1251'=>'windows-1251',
  46. 'koi8-u'=>'koi8-u',
  47. 'cp866'=>'cp866'
  48. );
  49. $uploadinputs=wf_HiddenInput('uploaduserbase','true');
  50. $uploadinputs.=__('Upload userbase').' <input id="fileselector" type="file" name="uluserbase" size="10" /><br>';
  51. $uploadinputs.=wf_Selector('delimiter', $delimiters, __('Delimiter'), '', true);
  52. $uploadinputs.=wf_Selector('encoding', $encodings, __('Encoding'), '', true);
  53. $uploadinputs.=wf_Submit('Upload');
  54. $uploadform=bs_UploadFormBody('', 'POST', $uploadinputs, 'glamour');
  55. return ($uploadform);;
  56. }
  57. function migrate_UploadFile() {
  58. //путь сохранения
  59. $uploaddir = 'exports/';
  60. //белый лист расширений
  61. $allowedExtensions = array("txt","csv");
  62. //по умолчанию надеемся на худшее
  63. $result=false;
  64. //проверяем точно ли текстовку нам подсовывают
  65. foreach ($_FILES as $file) {
  66. if ($file['tmp_name'] > '') {
  67. if (@!in_array(end(explode(".",strtolower($file['name']))),$allowedExtensions)) {
  68. $errormessage='Wrong file type';
  69. die($errormessage);
  70. }
  71. }
  72. }
  73. $filename=vf($_FILES['uluserbase']['name']);
  74. $uploadfile = $uploaddir . $filename;
  75. if (move_uploaded_file($_FILES['uluserbase']['tmp_name'], $uploadfile)) {
  76. $result=$filename;
  77. }
  78. return ($result);
  79. }
  80. function web_MigrationPreprocessing($filename,$delimiter,$encoding) {
  81. $path='exports/';
  82. $raw_data= file_get_contents($path.$filename);
  83. $parsed_data=array();
  84. if ($encoding!='utf-8') {
  85. $raw_data= iconv($encoding, 'utf-8', $raw_data);
  86. }
  87. $raw_data= explodeRows($raw_data);
  88. if (!empty($raw_data)) {
  89. foreach ($raw_data as $eachrow) {
  90. if (!empty($eachrow)) {
  91. $parsed_data[]= explode($delimiter, $eachrow);
  92. }
  93. }
  94. }
  95. if (sizeof($parsed_data)>1) {
  96. $col_count= sizeof($parsed_data[0]);
  97. $cells= wf_TableCell(__('Column number'));
  98. $cells.= wf_TableCell(__('Column content'));
  99. $rows= wf_TableRow($cells, 'row1');
  100. foreach ($parsed_data[0] as $col_num=>$col_data) {
  101. $cells= wf_TableCell($col_num);
  102. $cells.= wf_TableCell($col_data);
  103. $rows.= wf_TableRow($cells, 'row3');
  104. }
  105. $first_row= wf_TableBody($rows, '100%', '0', '');
  106. show_window(__('Found count of data columns'),$col_count);
  107. show_window(__('First of imported data rows'), $first_row);
  108. //construct of data processing form
  109. $rowNumArr=array();
  110. for ($i=0;$i<$col_count;$i++) {
  111. $rowNumArr[$i]=$i;
  112. }
  113. $login_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  114. $password_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  115. $ip_arr = $rowNumArr;
  116. $mac_arr = $rowNumArr + array('RANDOM'=>__('Generate Random'));
  117. $tariff_arr = $rowNumArr;
  118. $cash_arr = $rowNumArr;
  119. $credit_arr = $rowNumArr + array('ZERO'=>__('Set to zero'));
  120. $creditex_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  121. /*Start ADD*/
  122. $city_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  123. $street_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  124. $build_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  125. $apt_entrance_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  126. $apt_floor_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  127. $apt_apt_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  128. /*End ADD*/
  129. $phone_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  130. $mobile_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  131. $email_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  132. $address_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  133. $realname_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  134. $contract_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  135. $contract_d_arr = $rowNumArr + array('NONE'=>__('Set to none'));
  136. $ao_arr = $rowNumArr + array('AO_1'=>__('AlwaysOnline=1'));
  137. $down_arr = $rowNumArr + array('DOWN_0'=>__('Down=0'));
  138. $passive_arr = $rowNumArr + array('PASSIVE_0'=>__('Passive=0'));
  139. $regtype_arr = array('PHP'=>'Show PHP Script','SQL'=>'Show SQL dump','UB'=>'Ubilling live register');
  140. //data column setting form
  141. $inputs= wf_Selector('login_col', $login_arr, __('User login'), '0', true);
  142. $inputs.= wf_Selector('password_col', $password_arr, __('User password'), '1', true);
  143. $inputs.= wf_Selector('ip_col', $ip_arr, __('User IP'), '2', true);
  144. $inputs.= wf_Selector('mac_col', $mac_arr, __('User MAC'), '3', true);
  145. $inputs.= wf_Selector('tariff_col', $tariff_arr, __('User tariff'), '4', true);
  146. $inputs.= wf_Selector('cash_col', $cash_arr, __('User cash'), '5', true);
  147. $inputs.= wf_Selector('credit_col', $credit_arr, __('User credit limit'), '6', true);
  148. $inputs.= wf_Selector('creditex_col', $creditex_arr, __('User credit expire date'), '7', true);
  149. /*START ADD*/
  150. $inputs.= wf_Selector('city_col', $city_arr, __('User city'), '8', true);
  151. $inputs.= wf_Selector('street_col', $street_arr, __('User street'), '9', true);
  152. $inputs.= wf_Selector('build_col', $build_arr, __('User build'), '10', true);
  153. $inputs.= wf_Selector('apt_entrance_col', $apt_entrance_arr, __('User entrance'), '11', true);
  154. $inputs.= wf_Selector('apt_floor_col', $apt_floor_arr, __('User floor'), '12', true);
  155. $inputs.= wf_Selector('apt_apt_col', $apt_apt_arr, __('User apt'), '13', true);
  156. /*END ADD*/
  157. $inputs.= wf_Selector('phone_col', $phone_arr, __('User phone'), '14', true);
  158. $inputs.= wf_Selector('mobile_col', $mobile_arr, __('User mobile'), '15', true);
  159. $inputs.= wf_Selector('email_col', $email_arr, __('User email'), '16', true);
  160. $inputs.= wf_Selector('address_col', $address_arr, __('User address'), '17', true);
  161. $inputs.= wf_Selector('realname_col', $realname_arr, __('User realname'), '18', true);
  162. $inputs.= wf_Selector('contract_col', $contract_arr, __('User contract'), '19', true);
  163. $inputs.= wf_Selector('contract_d_col', $contract_d_arr, __('User contract date'), '20', true);
  164. $inputs.= wf_Selector('ao_col', $ao_arr, __('User AlwaysOnline state'), '21', true);
  165. $inputs.= wf_Selector('down_col', $down_arr, __('User Down state'), '22', true);
  166. $inputs.= wf_Selector('passive_col', $passive_arr, __('User Passive state'), '23', true);
  167. $inputs.= wf_Selector('regtype', $regtype_arr, __('User registration mode'), '24', true);
  168. $inputs.= multinet_network_selector().__('Target network'). wf_delimiter();
  169. $inputs.= wf_HiddenInput('import_rawdata', base64_encode(serialize($parsed_data)));
  170. $inputs.= wf_Submit('Save this column pointers and continue import');
  171. $colform= wf_Form("?module=migration2&setpointers=true", 'POST', $inputs, 'glamour');
  172. show_window(__('Select data columns and their values'),$colform);
  173. } else {
  174. show_error(__('Parsing error'));
  175. }
  176. }
  177. function web_MigrationPrepare($import_rawdata,$import_opts) {
  178. $import_rawdata = unserialize(base64_decode($import_rawdata));
  179. $import_opts = unserialize(base64_decode($import_opts));
  180. $cells = wf_TableCell('#');
  181. $cells.= wf_TableCell('[login]');
  182. $cells.= wf_TableCell('[password]');
  183. $cells.= wf_TableCell('[ip]');
  184. $cells.= wf_TableCell('[mac]');
  185. $cells.= wf_TableCell('[tariff]');
  186. $cells.= wf_TableCell('[cash]');
  187. $cells.= wf_TableCell('[phone]');
  188. $cells.= wf_TableCell('[mobile]');
  189. $cells.= wf_TableCell('[email]');
  190. $cells.= wf_TableCell('[credit]');
  191. $cells.= wf_TableCell('[creditex]');
  192. /*Start ADD*/
  193. $cells.= wf_TableCell('[city]');
  194. $cells.= wf_TableCell('[street]');
  195. $cells.= wf_TableCell('[build]');
  196. $cells.= wf_TableCell('[apt_entrance]');
  197. $cells.= wf_TableCell('[apt_floor]');
  198. $cells.= wf_TableCell('[apt_apt]');
  199. /*End ADD*/
  200. $cells.= wf_TableCell('[address]');
  201. $cells.= wf_TableCell('[realname]');
  202. $cells.= wf_TableCell('[contract]');
  203. $cells.= wf_TableCell('[contract_d]');
  204. $cells.= wf_TableCell('[ao]');
  205. $cells.= wf_TableCell('[down]');
  206. $cells.= wf_TableCell('[passive]');
  207. $rows = wf_TableRow($cells, 'row1');
  208. $regdata=array();
  209. $i=0;
  210. foreach ($import_rawdata as $eachrow) {
  211. $i++;
  212. $cells = wf_TableCell($i);
  213. if ($import_opts['login_col'] != 'RANDOM') {
  214. $login = trim($eachrow[$import_opts['login_col']]);
  215. } else {
  216. $login = 'mi_'.zb_rand_string(8);
  217. }
  218. $cells.= wf_TableCell($login);
  219. if ($import_opts['password_col'] != 'RANDOM') {
  220. $password = $eachrow[$import_opts['password_col']];
  221. } else {
  222. $password = zb_rand_string(10);
  223. }
  224. $cells.= wf_TableCell($password);
  225. $ip = trim($eachrow[$import_opts['ip_col']]);
  226. $cells.= wf_TableCell($ip);
  227. if ($import_opts['mac_col'] != 'RANDOM') {
  228. $mac = trim($eachrow[$import_opts['mac_col']]);
  229. } else {
  230. $mac = '14:'.'88'.':'.rand(10,99).':'.rand(10,99).':'.rand(10,99).':'.rand(10,99);
  231. }
  232. $cells.= wf_TableCell($mac);
  233. $tariff = trim($eachrow[$import_opts['tariff_col']]);
  234. $cells.= wf_TableCell($tariff);
  235. $cash = trim($eachrow[$import_opts['cash_col']]);
  236. $cells.= wf_TableCell($cash);
  237. if ($import_opts['phone_col'] != 'NONE') {
  238. $phone = trim($eachrow[$import_opts['phone_col']]);
  239. } else {
  240. $phone = '';
  241. }
  242. $cells.= wf_TableCell($phone);
  243. if ($import_opts['mobile_col'] != 'NONE') {
  244. $mobile = trim($eachrow[$import_opts['mobile_col']]);
  245. } else {
  246. $mobile = '';
  247. }
  248. $cells.= wf_TableCell($mobile);
  249. if ($import_opts['email_col'] != 'NONE') {
  250. $email = trim($eachrow[$import_opts['email_col']]);
  251. } else {
  252. $email = '';
  253. }
  254. $cells.= wf_TableCell($email);
  255. if ($import_opts['credit_col'] != 'ZERO') {
  256. $credit = trim($eachrow[$import_opts['credit_col']]);
  257. } else {
  258. $credit = 0;
  259. }
  260. $cells.= wf_TableCell($credit);
  261. if ($import_opts['creditex_col'] != 'NONE') {
  262. $creditex = trim($eachrow[$import_opts['creditex_col']]);
  263. } else {
  264. $creditex = '0';
  265. }
  266. $cells.= wf_TableCell($creditex);
  267. /*START ADD*/
  268. if ($import_opts['city_col'] != 'NONE') {
  269. $city = trim($eachrow[$import_opts['city_col']]);
  270. } else {
  271. $city = '';
  272. }
  273. $cells.= wf_TableCell($city);
  274. if ($import_opts['street_col'] != 'NONE') {
  275. $street = trim($eachrow[$import_opts['street_col']]);
  276. } else {
  277. $street = '';
  278. }
  279. $cells.= wf_TableCell($street);
  280. if ($import_opts['build_col'] != 'NONE') {
  281. $build = trim($eachrow[$import_opts['build_col']]);
  282. } else {
  283. $build = '';
  284. }
  285. $cells.= wf_TableCell($build);
  286. if ($import_opts['apt_entrance_col'] != 'NONE') {
  287. $apt_entrance = trim($eachrow[$import_opts['apt_entrance_col']]);
  288. } else {
  289. $apt_entrance = '';
  290. }
  291. $cells.= wf_TableCell($apt_entrance);
  292. if ($import_opts['apt_floor_col'] != 'NONE') {
  293. $apt_floor = trim($eachrow[$import_opts['apt_floor_col']]);
  294. } else {
  295. $apt_floor = '';
  296. }
  297. $cells.= wf_TableCell($apt_floor);
  298. if ($import_opts['apt_apt_col'] != 'NONE') {
  299. $apt_apt = trim($eachrow[$import_opts['apt_apt_col']]);
  300. } else {
  301. $apt_apt = '';
  302. }
  303. $cells.= wf_TableCell($apt_apt);
  304. /*END ADD*/
  305. if ($import_opts['address_col'] != 'NONE') {
  306. $address = trim($eachrow[$import_opts['address_col']]);
  307. } else {
  308. $address = '';
  309. }
  310. $cells.= wf_TableCell($address);
  311. if ($import_opts['realname_col'] != 'NONE') {
  312. $realname = trim($eachrow[$import_opts['realname_col']]);
  313. } else {
  314. $realname = '';
  315. }
  316. $cells.= wf_TableCell($realname);
  317. if ($import_opts['contract_col'] != 'NONE') {
  318. $contract = trim($eachrow[$import_opts['contract_col']]);
  319. } else {
  320. $contract = '';
  321. }
  322. $cells.= wf_TableCell($contract);
  323. if ($import_opts['contract_d_col'] != 'NONE') {
  324. $contract_d = trim($eachrow[$import_opts['contract_d_col']]);
  325. } else {
  326. $contract_d = '';
  327. }
  328. $cells.= wf_TableCell($contract_d);
  329. if ($import_opts['ao_col'] != 'AO_1') {
  330. $ao = trim($eachrow[$import_opts['ao_col']]);
  331. } else {
  332. $ao = 1;
  333. }
  334. $cells.= wf_TableCell($ao);
  335. if ($import_opts['down_col'] != 'DOWN_0') {
  336. $down = trim($eachrow[$import_opts['down_col']]);
  337. } else {
  338. $down = 0;
  339. }
  340. $cells.= wf_TableCell($down);
  341. if ($import_opts['passive_col'] != 'PASSIVE_0') {
  342. $passive = trim($eachrow[$import_opts['passive_col']]);
  343. } else {
  344. $passive = 0;
  345. }
  346. $cells.= wf_TableCell($passive);
  347. $rows.= wf_TableRow($cells, 'row3');
  348. // filling userreg array
  349. $regdata[$login]['login'] = $login;
  350. $regdata[$login]['password'] = $password;
  351. $regdata[$login]['ip'] = $ip;
  352. $regdata[$login]['mac'] = $mac;
  353. $regdata[$login]['tariff'] = $tariff;
  354. $regdata[$login]['cash'] = $cash;
  355. $regdata[$login]['phone'] = $phone;
  356. $regdata[$login]['mobile'] = $mobile;
  357. $regdata[$login]['email'] = $email;
  358. $regdata[$login]['credit'] = $credit;
  359. $regdata[$login]['creditex'] = $creditex;
  360. /*Start ADD*/
  361. $regdata[$login]['city'] = $city;
  362. $regdata[$login]['street'] = $street;
  363. $regdata[$login]['build'] = $build;
  364. $regdata[$login]['apt_entrance'] = $apt_entrance;
  365. $regdata[$login]['apt_floor'] = $apt_floor;
  366. $regdata[$login]['apt_apt'] = $apt_apt;
  367. /*End ADD*/
  368. $regdata[$login]['address'] = $address;
  369. $regdata[$login]['realname'] = $realname;
  370. $regdata[$login]['contract'] = $contract;
  371. $regdata[$login]['contract_d'] = $contract_d;
  372. $regdata[$login]['ao'] = $ao;
  373. $regdata[$login]['down'] = $down;
  374. $regdata[$login]['passive'] = $passive;
  375. }
  376. $regdata_save = serialize($regdata);
  377. $regdata_save = base64_encode($regdata_save);
  378. zb_StorageSet('IMPORT_REGDATA', $regdata_save);
  379. $preparse = wf_TableBody($rows, '100%', '0', '');
  380. show_window(__('All correct').'?',$preparse);
  381. $inputs = wf_Link('?module=migration2', 'No I want to try another import settings', false, 'ubButton');
  382. $inputs.= wf_Link('?module=migration2&setpointers=true&goregister=ok', 'Yes, proceed registeration of this users', false, 'ubButton');
  383. $inputs.= wf_delimiter();
  384. $inputs.= wf_tag('h3', false, '', 'style="color: red; background-color: #F5F5DC"');
  385. $inputs.= 'Creating occupancy(cities, streets, buildings, addresses, etc) for new users avialable ONLY for "Ubilling live register" user registration mode. ';
  386. $inputs.= 'Nevertheless this feature has to be used with GREAT CARE and for your OWN RISK';
  387. $inputs.= wf_tag('h3', true);
  388. $inputs.= wf_Link('?module=migration2&setpointers=true&goregister=ok&create_accupancy=yes',
  389. 'Yes, proceed registeration of this users and create occupancy if not exists.', false, 'ubButton');
  390. show_window('', $inputs);
  391. }
  392. if (!wf_CheckGet(array('setpointers'))) {
  393. if(!wf_CheckPost(array('uploaduserbase'))) {
  394. //show upload form
  395. show_window(__('User database import from text file'), web_MigrationUploadForm());
  396. } else {
  397. //upload file and show preprocessing form
  398. $upload_done = migrate_UploadFile();
  399. if ($upload_done) {
  400. $delimiter = $_POST['delimiter'];
  401. $encoding = $_POST['encoding'];
  402. web_MigrationPreprocessing($upload_done, $delimiter, $encoding);
  403. }
  404. }
  405. } else {
  406. //some pointers already set, load raw data into database for processing
  407. if (wf_CheckPost(array('import_rawdata'))) {
  408. $import_rawdata = $_POST['import_rawdata'];
  409. zb_StorageSet('IMPORT_RAWDATA', $import_rawdata);
  410. $import_opts = array(
  411. 'login_col'=> $_POST['login_col'],
  412. 'password_col'=> $_POST['password_col'],
  413. 'ip_col'=> $_POST['ip_col'],
  414. 'mac_col'=> $_POST['mac_col'],
  415. 'tariff_col'=> $_POST['tariff_col'],
  416. 'cash_col'=> $_POST['cash_col'],
  417. 'phone_col'=> $_POST['phone_col'],
  418. 'mobile_col'=> $_POST['mobile_col'],
  419. 'email_col'=> $_POST['email_col'],
  420. 'credit_col'=> $_POST['credit_col'],
  421. 'creditex_col'=> $_POST['creditex_col'],
  422. /*START ADD*/
  423. 'city_col'=> $_POST['city_col'],
  424. 'street_col'=> $_POST['street_col'],
  425. 'build_col'=> $_POST['build_col'],
  426. 'apt_entrance_col'=> $_POST['apt_entrance_col'],
  427. 'apt_floor_col'=> $_POST['apt_floor_col'],
  428. 'apt_apt_col'=> $_POST['apt_apt_col'],
  429. /*End ADD*/
  430. 'address_col'=> $_POST['address_col'],
  431. 'realname_col'=> $_POST['realname_col'],
  432. 'contract_col'=> $_POST['contract_col'],
  433. 'contract_d_col'=> $_POST['contract_d_col'],
  434. 'ao_col'=> $_POST['ao_col'],
  435. 'down_col'=> $_POST['down_col'],
  436. 'passive_col'=> $_POST['passive_col'],
  437. 'netid'=> $_POST['networkselect'],
  438. 'regtype'=>$_POST['regtype']
  439. );
  440. $import_opts = serialize($import_opts);
  441. $import_opts = base64_encode($import_opts);
  442. zb_StorageSet('IMPORT_OPTS', $import_opts);
  443. } else {
  444. $import_rawdata = zb_StorageGet('IMPORT_RAWDATA');
  445. $import_opts = zb_StorageGet('IMPORT_OPTS');
  446. }
  447. //last checks
  448. if (!wf_CheckGet(array('goregister'))) {
  449. web_MigrationPrepare($import_rawdata, $import_opts);
  450. } else {
  451. $CreateOccupancy = ( wf_CheckGet(array('create_accupancy')) ) ? true : false;
  452. //register imported users
  453. $regdata_raw = zb_StorageGet('IMPORT_REGDATA');
  454. $regdata = unserialize(base64_decode($regdata_raw));
  455. $querybuff = '';
  456. if (!empty($regdata)) {
  457. $iopts = unserialize(base64_decode($import_opts));
  458. $RegAddrs = array();
  459. if ($CreateOccupancy && $iopts['regtype'] == 'UB') {
  460. // getting unique cities and streets names with buildings
  461. foreach ($regdata as $io => $user) {
  462. $tmpRegCity = $user['city'];
  463. $tmpRegStreet = $user['street'];
  464. $tmpRegBuilding = $user['build'];
  465. if (!array_key_exists($tmpRegCity, $RegAddrs)) {
  466. $RegAddrs[$tmpRegCity] = array();
  467. }
  468. if (!array_key_exists($tmpRegStreet, $RegAddrs[$tmpRegCity])) {
  469. $RegAddrs[$tmpRegCity][$tmpRegStreet] = array();
  470. }
  471. if (!in_array($tmpRegBuilding, $RegAddrs[$tmpRegCity][$tmpRegStreet])) {
  472. $RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding] = array('id' => '');
  473. }
  474. }
  475. if ( !empty($RegAddrs) ) {
  476. foreach ($RegAddrs as $tCity => $CityData) {
  477. $CityWasJustCreated = false;
  478. $tmpQuery = "SELECT * FROM `city` WHERE LOWER(`cityname`) = '" . mb_strtolower($tCity) . "';";
  479. $tmpResult = simple_queryall($tmpQuery);
  480. if (!empty($tmpResult)) {
  481. $tCityID = $tmpResult[0]['id'];
  482. } else {
  483. zb_AddressCreateCity($tCity, '');
  484. $tCityID = simple_get_lastid('city');
  485. $CityWasJustCreated = true;
  486. }
  487. foreach ($CityData as $tStreet => $tBuilds) {
  488. $StreetWasJustCreated = false;
  489. $NeedCreateStreet = true;
  490. // if city was not just created - let's check, maybe there is such street in DB already
  491. if (!$CityWasJustCreated) {
  492. $tmpQuery = "SELECT * FROM `street` WHERE `cityid` = '" . $tCityID . "' AND LOWER(`streetname`) = '" . mb_strtolower($tStreet) . "';";
  493. $tmpResult = simple_queryall($tmpQuery);
  494. if (!empty($tmpResult)) {
  495. $tStreetID = $tmpResult[0]['id'];
  496. $NeedCreateStreet = false;
  497. }
  498. }
  499. if ($NeedCreateStreet) {
  500. zb_AddressCreateStreet($tCityID, $tStreet, '');
  501. $tStreetID = simple_get_lastid('street');
  502. $StreetWasJustCreated = true;
  503. }
  504. foreach ($tBuilds as $tBuild => $tID) {
  505. $NeedCreateBuilding = true;
  506. // if street was not just created - let's check, maybe there is such building in DB already
  507. if (!$StreetWasJustCreated) {
  508. $tmpQuery = "SELECT * FROM `build` WHERE `streetid` = '" . $tStreetID . "' AND LOWER(`buildnum`) = '" . mb_strtolower($tBuild) . "';";
  509. $tmpResult = simple_queryall($tmpQuery);
  510. if (!empty($tmpResult)) {
  511. $tBuildingID = $tmpResult[0]['id'];
  512. $NeedCreateBuilding = false;
  513. }
  514. }
  515. if ($NeedCreateBuilding) {
  516. zb_AddressCreateBuild($tStreetID, $tBuild);
  517. $tBuildingID = simple_get_lastid('build');
  518. }
  519. $RegAddrs[$tCity][$tStreet][$tBuild]['id'] = $tBuildingID;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. /*START ADD*/
  526. $buffer="";
  527. $buffer.='function InArray(&$Array,$Value)
  528. {
  529. $ret=false;
  530. foreach ($Array as $key => $value)
  531. {
  532. if ($Value == $value)
  533. {
  534. $ret=true;
  535. break;
  536. }
  537. }
  538. return $ret;
  539. }
  540. '."\n";
  541. /*END ADD*/
  542. foreach ($regdata as $io => $user) {
  543. debarr($user);
  544. //typical register of each user
  545. $login=vf($user['login']);
  546. $password=vf($user['password']);
  547. $ip=$user['ip'];
  548. $iopts= unserialize(base64_decode($import_opts));
  549. $netid=$iopts['netid'];
  550. /*START ADD*/
  551. if ($iopts['regtype']=='PHP') {
  552. $SQL['city_id']="SELECT `id` FROM `city` WHERE `cityname`= '".$user['city']."'";
  553. $SQL['city_add']="INSERT INTO `city` (`id` ,`cityname` ,`cityalias`) VALUES (NULL , '".$user['city']."', '".translit($user['city'])."');";
  554. $buffer.='$city_id=0;'."\n";
  555. $buffer.='$city_id_count=mysql_num_rows( mysql_query( "'.$SQL['city_id'].'" ) );'."\n";
  556. $buffer.='if ($city_id_count==0)
  557. {
  558. $result = mysql_query("'.$SQL['city_add'].'");
  559. if (!$result) { echo \'Error add city: \' . mysql_error();}
  560. }
  561. $row = mysql_fetch_row( mysql_query( "'.$SQL['city_id'].'" ) );
  562. $city_id=$row[0];
  563. '."\n";
  564. $SQL['street_id']="SELECT `id` FROM `street` WHERE `cityid` = '\".\$city_id.\"' AND `streetname` = '".$user['street']."'";
  565. $SQL['street_add']="INSERT INTO `street` (`id`, `cityid`, `streetname`, `streetalias`) VALUES (NULL, '\".\$city_id.\"', '".$user['street']."', '".translit($user['street'])."');";
  566. $buffer.='$street_id=0;'."\n";
  567. $buffer.='$street_id_count=mysql_num_rows( mysql_query( "'.$SQL['street_id'].'" ) );'."\n";
  568. $buffer.='if ($street_id_count==0)
  569. {
  570. $result = mysql_query("'.$SQL['street_add'].'");
  571. if (!$result) { echo \'Error add street: \' . mysql_error();}
  572. }
  573. $row = mysql_fetch_row( mysql_query( "'.$SQL['street_id'].'" ) );
  574. $street_id=$row[0];
  575. ';
  576. $SQL['build_id']="SELECT `id` FROM `build` WHERE `streetid`= '\".\$street_id.\"' and `buildnum` = '".$user['build']."'";
  577. $SQL['build_add']="INSERT INTO `build` (`id`, `streetid`, `buildnum`, `geo`) VALUES (NULL, '\".\$street_id.\"', '".$user['build']."', NULL);";
  578. $buffer.='$build_id=0;'."\n";
  579. $buffer.='$build_id_count=mysql_num_rows( mysql_query( "'.$SQL['build_id'].'" ) );'."\n";
  580. $buffer.='if ($build_id_count==0)
  581. {
  582. $result = mysql_query("'.$SQL['build_add'].'");
  583. if (!$result) { echo \'Error add build: \' . mysql_error();}
  584. }
  585. $row = mysql_fetch_row( mysql_query( "'.$SQL['build_id'].'" ) );
  586. $build_id=$row[0];'."\n\n\n";
  587. $SQL['apt_id']="SELECT `id` FROM `apt` WHERE `buildid` = '\".\$build_id.\"' AND `entrance` = '".$user['apt_entrance']."' AND `floor` = '".$user['apt_floor']."' AND `apt` = '".$user['apt_apt']."'";
  588. $SQL['apt_add']="INSERT INTO `apt` (`id`, `buildid`, `entrance`, `floor`, `apt`) VALUES (NULL, '\".\$build_id.\"', '".$user['apt_entrance']."', '".$user['apt_floor']."', '".$user['apt_apt']."');";
  589. $buffer.='$apt_id=0;'."\n";
  590. $buffer.='$apt_id_count=mysql_num_rows( mysql_query( "'.$SQL['apt_id'].'" ) );'."\n";
  591. $buffer.='if ($apt_id_count==0)
  592. {
  593. $result = mysql_query("'.$SQL['apt_add'].'");
  594. if (!$result) { echo \'Error add apt: \' . mysql_error();}
  595. }
  596. $row = mysql_fetch_row( mysql_query( "'.$SQL['apt_id'].'" ) );
  597. $apt_id=$row[0];'."\n";
  598. $SQL['address_id']="SELECT `id` FROM `address` WHERE `login`= '".$login."'";
  599. $SQL['address_add']="INSERT INTO `address` (`id`, `login`, `aptid`) VALUES (NULL, '".$login."', '\".\$apt_id.\"');";
  600. $buffer.='$address_id=0;'."\n";
  601. $buffer.='$address_id_count=mysql_num_rows( mysql_query( "'.$SQL['address_id'].'" ) );'."\n";
  602. $buffer.='if ($address_id_count==0)
  603. {
  604. $result = mysql_query("'.$SQL['address_add'].'");
  605. if (!$result) { echo \'Error add address: \' . mysql_error();}
  606. }
  607. $row = mysql_fetch_row( mysql_query( "'.$SQL['address_id'].'" ) );
  608. $address_id=$row[0];'."\n";
  609. $SQL['users']="INSERT INTO `users` (`login`,`Password`,`Passive`,`Down`,`DisabledDetailStat`,`AlwaysOnline`,`Tariff`,`Address`,`Phone`,`Email`,`Note`,`RealName`,`StgGroup`,`Credit`,`TariffChange`,`Userdata0`,`Userdata1`,`Userdata2`,`Userdata3`,`Userdata4`,`Userdata5`,`Userdata6`,`Userdata7`,`Userdata8`,`Userdata9`,`CreditExpire`,`IP`,`D0`,`U0`,`D1`,`U1`,`D2`,`U2`,`D3`,`U3`,`D4`,`U4`,`D5`,`U5`, `D6`, `U6`,`D7`, `U7`, `D8`,`U8`,`D9`,`U9`,`Cash`,`FreeMb`,`LastCashAdd`,`LastCashAddTime`,`PassiveTime`,`LastActivityTime`,`NAS`)
  610. VALUES ('".$login."','".$password."','".$user['passive']."','".$user['down']."','1','".$user['ao']."','".$user['tariff']."','\".\$address_id.\"','','','','','','".$user['credit']."','', '','','','', '', '', '', '','', '', '".$user['creditex']."','".$ip."','0','0','0','0','0', '0','0','0', '0','0','0','0','0', '0','0','0', '0', '0', '0', '0', '".$user['cash']."','0','0', '0','0', '0','');";
  611. $SQL['nethosts']="INSERT INTO `nethosts` (`id`,`netid`,`ip`,`mac`,`option`) VALUES ('', '".$netid."' ,'".$ip."', '".$user['mac']."', '');";
  612. $SQL['realname']="INSERT INTO `realname` (`id`,`login`,`realname`) VALUES (NULL, '".$login."','".$user['realname']."');";
  613. $SQL['phones']="INSERT INTO `phones` (`id`,`login`,`phone`,`mobile`) VALUES (NULL, '".$login."','".$user['phone']."','".$user['mobile']."');";
  614. $SQL['contracts']="INSERT INTO `contracts` (`id`,`login`,`contract`) VALUES (NULL, '".$login."','".$user['contract']."');";
  615. $SQL['contracts_d']="INSERT INTO `contractdates` (`id`,`contract`,`date`) VALUES (NULL , '" . $user['contract'] . "', '" . $user['contract_d'] . "');";
  616. $SQL['emails']="INSERT INTO `emails` (`id`,`login`,`email`) VALUES (NULL, '".$login."','".$user['email']."');";
  617. $SQL['userspeeds']="INSERT INTO `userspeeds` (`id`,`login`,`speed`) VALUES (NULL, '".$login."','0');";
  618. $SQL['notes']="INSERT INTO `notes` (`id`,`login`,`note`) VALUES ('', '".$login."','".$user['address']."');";
  619. $buffer.='$result = mysql_query("'.$SQL['users'].'");'."\n";
  620. $buffer.='if (!$result) {
  621. echo \'Query[users] error with '.$login.': \' . mysql_error();
  622. exit;
  623. }';
  624. $buffer.="\n";
  625. $buffer.='$result = mysql_query("'.$SQL['nethosts'].'");'."\n";
  626. $buffer.='if (!$result) {
  627. echo \'Query[nethosts] error with '.$login.': \' . mysql_error();
  628. exit;
  629. }';
  630. $buffer.="\n";
  631. $buffer.='$result = mysql_query("'.$SQL['realname'].'");'."\n";
  632. $buffer.='if (!$result) {
  633. echo \'Query[realname] error with '.$login.': \' . mysql_error();
  634. exit;
  635. }';
  636. $buffer.="\n";
  637. $buffer.='$result = mysql_query("'.$SQL['phones'].'");'."\n";
  638. $buffer.='if (!$result) {
  639. echo \'Query[phones] error with '.$login.': \' . mysql_error();
  640. exit;
  641. }';
  642. $buffer.="\n";
  643. $buffer.='$result = mysql_query("'.$SQL['contracts'].'");'."\n";
  644. $buffer.='if (!$result) {
  645. echo \'Query[contracts] error with '.$login.': \' . mysql_error();
  646. exit;
  647. }';
  648. $buffer.="\n";
  649. $buffer.='$result = mysql_query("'.$SQL['contracts_d'].'");'."\n";
  650. $buffer.='if (!$result) {
  651. echo \'Query[contracts_d] error with '.$login.': \' . mysql_error();
  652. exit;
  653. }';
  654. $buffer.="\n";
  655. $buffer.='$result = mysql_query("'.$SQL['emails'].'");'."\n";
  656. $buffer.='if (!$result) {
  657. echo \'Query[emails] error with '.$login.': \' . mysql_error();
  658. exit;
  659. }';
  660. $buffer.="\n";
  661. $buffer.='$result = mysql_query("'.$SQL['userspeeds'].'");'."\n";
  662. $buffer.='if (!$result) {
  663. echo \'Query[userspeeds] error with '.$login.': \' . mysql_error();
  664. exit;
  665. }';
  666. $buffer.="\n";
  667. $buffer.='$result = mysql_query("'.$SQL['notes'].'");'."\n";
  668. $buffer.='if (!$result) {
  669. echo \'Query[notes] error with '.$login.': \' . mysql_error();
  670. exit;
  671. }';
  672. $buffer.="\n";
  673. }
  674. /*END ADD*/
  675. //Ubilling normal registration mode
  676. if ($iopts['regtype']=='UB') {
  677. $billing->createuser($login);
  678. log_register("StgUser REGISTER ".$login);
  679. $billing->setpassword($login,$password);
  680. log_register("StgUser PASSWORD ".$password);
  681. $billing->setip($login,$ip);
  682. log_register("StgUser IP ".$ip);
  683. multinet_add_host($netid, $ip);
  684. zb_UserCreateRealName($login, $user['realname']);
  685. zb_UserCreatePhone($login, $user['phone'], $user['mobile']);
  686. zb_UserCreateContract($login, $user['contract']);
  687. zb_UserContractDateCreate($user['contract'], date('Y-m-d', strtotime($user['contract_d'])));
  688. zb_UserCreateEmail($login, $user['email']);
  689. zb_UserCreateSpeedOverride($login, 0);
  690. multinet_change_mac($ip, $user['mac']);
  691. multinet_rebuild_all_handlers();
  692. $billing->setao($login,$user['ao']);
  693. $dstat=1;
  694. $billing->setdstat($login,$dstat);
  695. $billing->setdown($login,$user['down']);
  696. $billing->setpassive($login,$user['passive']);
  697. $billing->settariff($login,$user['tariff']);
  698. $billing->setcredit($login,$user['credit']);
  699. $billing->setcash($login,$user['cash']);
  700. $NoOccupancyCreated = true;
  701. if ($CreateOccupancy) {
  702. $tmpRegCity = $user['city'];
  703. $tmpRegStreet = $user['street'];
  704. $tmpRegBuilding = $user['build'];
  705. $tmpRegAptEntrance = $user['apt_entrance'];
  706. $tmpRegAptFloor = $user['apt_floor'];
  707. $tmpRegApt = $user['apt_apt'];
  708. $tBuildingID = '';
  709. // try to get build ID from $RegAddrs array which was processed earlier
  710. // and create araptment and address for the user
  711. if ( !empty($RegAddrs) ) {
  712. if (isset($RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding]['id'])) {
  713. $tBuildingID = $RegAddrs[$tmpRegCity][$tmpRegStreet][$tmpRegBuilding]['id'];
  714. zb_AddressCreateApartment($tBuildingID, $tmpRegAptEntrance, $tmpRegAptFloor, $tmpRegApt);
  715. $tAptID = simple_get_lastid('apt');
  716. zb_AddressCreateAddress($login, $tAptID);
  717. $NoOccupancyCreated = false;
  718. }
  719. }
  720. }
  721. if ($NoOccupancyCreated) { zb_UserCreateNotes($login, $user['address']); }
  722. }
  723. if ($iopts['regtype']=='SQL') {
  724. $querybuff.="
  725. INSERT INTO `users` (
  726. `login`,
  727. `Password`,
  728. `Passive`,
  729. `Down`,
  730. `DisabledDetailStat`,
  731. `AlwaysOnline`,
  732. `Tariff`,
  733. `Address`,
  734. `Phone`,
  735. `Email`,
  736. `Note`,
  737. `RealName`,
  738. `StgGroup`,
  739. `Credit`,
  740. `TariffChange`,
  741. `Userdata0`,
  742. `Userdata1`,
  743. `Userdata2`,
  744. `Userdata3`,
  745. `Userdata4`,
  746. `Userdata5`,
  747. `Userdata6`,
  748. `Userdata7`,
  749. `Userdata8`,
  750. `Userdata9`,
  751. `CreditExpire`,
  752. `IP`,
  753. `D0`,
  754. `U0`,
  755. `D1`,
  756. `U1`,
  757. `D2`,
  758. `U2`,
  759. `D3`,
  760. `U3`,
  761. `D4`,
  762. `U4`,
  763. `D5`,
  764. `U5`,
  765. `D6`,
  766. `U6`,
  767. `D7`,
  768. `U7`,
  769. `D8`,
  770. `U8`,
  771. `D9`,
  772. `U9`,
  773. `Cash`,
  774. `FreeMb`,
  775. `LastCashAdd`,
  776. `LastCashAddTime`,
  777. `PassiveTime`,
  778. `LastActivityTime`,
  779. `NAS`)
  780. VALUES (
  781. '".$login."',
  782. '".$password."',
  783. '".$user['passive']."',
  784. '".$user['down']."',
  785. '1',
  786. '".$user['ao']."',
  787. '".$user['tariff']."',
  788. '',
  789. '',
  790. '',
  791. '',
  792. '',
  793. '',
  794. '".$user['credit']."',
  795. '',
  796. '',
  797. '',
  798. '',
  799. '',
  800. '',
  801. '',
  802. '',
  803. '',
  804. '',
  805. '',
  806. '".$user['creditex']."',
  807. '".$ip."',
  808. '0',
  809. '0',
  810. '0',
  811. '0',
  812. '0',
  813. '0',
  814. '0',
  815. '0',
  816. '0',
  817. '0',
  818. '0',
  819. '0',
  820. '0',
  821. '0',
  822. '0',
  823. '0',
  824. '0',
  825. '0',
  826. '0',
  827. '0',
  828. '".$user['cash']."',
  829. '0',
  830. '0',
  831. '0',
  832. '0',
  833. '0',
  834. '');
  835. "."\n";
  836. //multinet
  837. $querybuff.="INSERT INTO `nethosts` (`id`,`netid`,`ip`,`mac`,`option`) VALUES ('', '".$netid."' ,'".$ip."', '".$user['mac']."', '');"."\n";
  838. //realname
  839. $querybuff.="INSERT INTO `realname` (`id`,`login`,`realname`) VALUES (NULL, '".$login."','".$user['realname']."');"."\n";
  840. //phone & mobile
  841. $querybuff.="INSERT INTO `phones` (`id`,`login`,`phone`,`mobile`) VALUES (NULL, '".$login."','".$user['phone']."','".$user['mobile']."');"."\n";
  842. //contract
  843. $querybuff.="INSERT INTO `contracts` (`id`,`login`,`contract`) VALUES (NULL, '".$login."','".$user['contract']."');"."\n";
  844. //email
  845. $querybuff.="INSERT INTO `emails` (`id`,`login`,`email`) VALUES (NULL, '".$login."','".$user['email']."');"."\n";
  846. //speedoverride
  847. $querybuff.="INSERT INTO `userspeeds` (`id`,`login`,`speed`) VALUES (NULL, '".$login."','0');"."\n";
  848. //notes
  849. $querybuff.="INSERT INTO `notes` (`id`,`login`,`note`) VALUES ('', '".$login."','".$user['address']."');"."\n";
  850. }
  851. }
  852. /*START ADD*/
  853. if ($iopts['regtype']=='PHP')
  854. {
  855. show_window(__('Generated PHP script'), wf_TextArea('sqldump', '', $buffer, true, '170x60'));
  856. }
  857. else show_window(__('Generated SQL dump'), wf_TextArea('sqldump', '', $querybuff, true, '120x20'));
  858. /*END ADD*/
  859. //show_window(__('Generated SQL dump'), wf_TextArea('sqldump', '', $querybuff, true, '120x20'));
  860. }
  861. }
  862. }
  863. } else {
  864. show_error(__('Access denied'));
  865. }
  866. ?>