PageRenderTime 24ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/shop/internals/user_import.php

http://avecms.googlecode.com/
PHP | 344 lines | 286 code | 26 blank | 32 comment | 45 complexity | 081f0c73850243d8a5b1cbfbd90a0e6a MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. if (!defined('USER_IMPORT')) exit;
  3. $csv_available_fields = array(
  4. 'Id' => $GLOBALS['config_vars']['UserImport_Id'],
  5. 'password' => $GLOBALS['config_vars']['UserImport_Kennwort'],
  6. 'email' => $GLOBALS['config_vars']['UserImport_Email'],
  7. 'street' => $GLOBALS['config_vars']['UserImport_Strasse'],
  8. 'street_nr' => $GLOBALS['config_vars']['UserImport_HausNr'],
  9. 'zipcode' => $GLOBALS['config_vars']['UserImport_Postleitzahl'],
  10. 'city' => $GLOBALS['config_vars']['UserImport_City'],
  11. 'phone' => $GLOBALS['config_vars']['UserImport_Telefon'],
  12. 'telefax' => $GLOBALS['config_vars']['UserImport_Telefax'],
  13. 'description' => $GLOBALS['config_vars']['UserImport_Bemerkungen'],
  14. 'firstname' => $GLOBALS['config_vars']['UserImport_Vorname'],
  15. 'lastname' => $GLOBALS['config_vars']['UserImport_Nachname'],
  16. 'user_name' => $GLOBALS['config_vars']['UserImport_UserName'],
  17. 'user_group' => $GLOBALS['config_vars']['UserImport_Benutzergruppe'],
  18. 'reg_time' => $GLOBALS['config_vars']['UserImport_Registriert'],
  19. 'Status' => $GLOBALS['config_vars']['UserImport_Status'],
  20. 'last_visit' => $GLOBALS['config_vars']['UserImport_ZuletztGesehen'],
  21. 'country' => $GLOBALS['config_vars']['UserImport_Land'],
  22. 'birthday' => $GLOBALS['config_vars']['UserImport_GebTag'],
  23. 'emc' => $GLOBALS['config_vars']['UserImport_emc'],
  24. 'reg_ip' => $GLOBALS['config_vars']['UserImport_IpReg'],
  25. 'new_pass' => $GLOBALS['config_vars']['UserImport_newPass'],
  26. 'company' => $GLOBALS['config_vars']['UserImport_Firma'],
  27. 'taxpay' => $GLOBALS['config_vars']['UserImport_UStPflichtig']
  28. );
  29. $AVE_Template->assign('method', 'shop');
  30. $AVE_Template->assign('next', 0);
  31. if (!empty($_REQUEST['sub']))
  32. {
  33. switch ($_REQUEST['sub'])
  34. {
  35. case 'importcsv':
  36. $TempDir = BASE_DIR . '/modules/shop/uploads/';
  37. $tpl_in = $AVE_Template->fetch($tpl_dir . 'shop_import_user.tpl');
  38. $error = false;
  39. $gone = true;
  40. $ValidFiles = array('text/csv','text/plain', 'application/csv', 'application/octet-stream', 'text/comma-separated-values', 'text/x-comma-separated-values', 'text/x-csv', 'application/vnd.ms-excel');
  41. if (isset($_FILES['csvfile']) && ( !in_array($_FILES['csvfile']['type'],$ValidFiles) ) )
  42. {
  43. $AVE_Template->assign('error', $GLOBALS['config_vars']['ImportDataWrong']);
  44. $AVE_Template->assign('content', $tpl_in);
  45. $error = true;
  46. $gone = false;
  47. }
  48. // ========================================================
  49. // Datei leer?
  50. // ========================================================
  51. if (($error == true || !isset($_FILES['csvfile']) || $_FILES['csvfile']['size']<10) && ($gone == true))
  52. {
  53. $AVE_Template->assign('error', $GLOBALS['config_vars']['ImportNoData']);
  54. $AVE_Template->assign('content', $tpl_in);
  55. $error = true;
  56. }
  57. // ========================================================
  58. // In den tempor?ren Ordner kopieren
  59. // ========================================================
  60. if ($error == false)
  61. {
  62. $fileid = md5(microtime().time().mt_rand(0, 1000));
  63. if (!move_uploaded_file($_FILES['csvfile']['tmp_name'], $TempDir . '/CSVIMPORT_user_' . $_SESSION['user_id'] . '_'.$fileid.'.txt'))
  64. {
  65. $AVE_Template->assign('error', $GLOBALS['config_vars']['ImportNotReadable']);
  66. $AVE_Template->assign('content', $tpl_in);
  67. }
  68. // ========================================================
  69. // Datei ?ffnen und Kopfzeile einlesen
  70. // ========================================================
  71. $fp = fopen($TempDir . '/CSVIMPORT_user_' . $_SESSION['user_id'] . '_'.$fileid.'.txt', 'r');
  72. $csv = new CSVReader($fp);
  73. $fields = $csv->Fields();
  74. fclose($fp);
  75. // ========================================================
  76. // valid?
  77. // ========================================================
  78. if ($csv->NumFields() < 1)
  79. {
  80. $AVE_Template->assign('error', $GLOBALS['config_vars']['ImportDataError']);
  81. $AVE_Template->assign('content', $tpl_in);
  82. }
  83. // ========================================================
  84. // Try to guess the fields
  85. // ========================================================
  86. $field_table = array();
  87. foreach ($fields as $csv_field)
  88. {
  89. $my_field = @$csv_assocs[$csv_field];
  90. if ($csv_field != 'deleted' && $csv_field != 'del_time')
  91. {
  92. $field_table[] = array(
  93. 'id' => md5($csv_field),
  94. 'csv_field' => $csv_field,
  95. 'my_field' => $my_field
  96. );
  97. }
  98. }
  99. $ugroups = array();
  100. $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_user_groups");
  101. while ($row = $sql->FetchRow())
  102. {
  103. array_push($ugroups, $row);
  104. }
  105. // ========================================================
  106. // Werte zuweisen
  107. // ========================================================
  108. $AVE_Template->assign('Ugroups', $ugroups);
  109. $AVE_Template->assign('fileid', $fileid);
  110. $AVE_Template->assign('field_table', $field_table);
  111. $AVE_Template->assign('available_fields', $csv_available_fields);
  112. $AVE_Template->assign('next', 1);
  113. $AVE_Template->assign('datas', $csv->NumFields());
  114. $AVE_Template->assign('content', $tpl_in);
  115. }
  116. if ($error == true)
  117. {
  118. $AVE_Template->assign('content', $tpl_in);
  119. }
  120. break;
  121. case 'importcsv2':
  122. $error=false;
  123. $TempDir = BASE_DIR . '/modules/shop/uploads/';
  124. // ========================================================
  125. // Nach tempor?rere Datei suchen...
  126. // ========================================================
  127. $fileid = preg_replace('/[^0-9a-zA-Z]*/', '', $_REQUEST['fileid']);
  128. if (!file_exists($TempDir . '/CSVIMPORT_user_' . $_SESSION['user_id'] . '_'.$fileid.'.txt'))
  129. {
  130. $AVE_Template->assign('error', $GLOBALS['config_vars']['ImportNotReadable']);
  131. $AVE_Template->assign('content', $tpl_in);
  132. $error = true;
  133. }
  134. switch ($_REQUEST['existing'])
  135. {
  136. case 'replace': $existing = 'replace'; break;
  137. case 'ignore' : $existing = 'ignore'; break;
  138. default : $existing = 'replace'; break;
  139. }
  140. // ========================================================
  141. // Datei ?ffnen
  142. // ========================================================
  143. $fp = fopen($TempDir . '/CSVIMPORT_user_' . $_SESSION['user_id'] . '_'.$fileid.'.txt', 'r');
  144. $csv = new CSVReader($fp);
  145. $fields = $csv->Fields();
  146. if ($error == true)
  147. {
  148. $AVE_Template->assign('content', $tpl_in);
  149. }
  150. while ($row = $csv->FetchRow())
  151. {
  152. if (count($row) == $csv->NumFields())
  153. {
  154. $Id = '';
  155. $password = '';
  156. $email = '';
  157. $street = '';
  158. $street_nr = '';
  159. $zipcode = '';
  160. $City = '';
  161. $phone = '';
  162. $telefax = '';
  163. $description = '';
  164. $firstname = '';
  165. $lastname = '';
  166. $user_name = '';
  167. $user_group = '';
  168. $reg_time = '';
  169. $status = '';
  170. $last_visit = '';
  171. $country = '';
  172. $birthday = '';
  173. $emc = '';
  174. $reg_ip = '';
  175. $new_pass = '';
  176. $company = '';
  177. $taxpay = '';
  178. $i = 0;
  179. foreach ($row as $key=>$value)
  180. {
  181. // ========================================================
  182. // Feld erkennen...
  183. // ========================================================
  184. $field = @$_REQUEST['field_' . md5($key)];
  185. switch ($field)
  186. {
  187. case 'Id' : $Id = $value; break;
  188. case 'password' : $password = $value; break;
  189. case 'email' : $email = $value; break;
  190. case 'street' : $street = $value; break;
  191. case 'street_nr' : $street_nr = $value; break;
  192. case 'zipcode' : $zipcode = $value; break;
  193. case 'city' : $city = $value; break;
  194. case 'phone' : $phone = $value; break;
  195. case 'telefax' : $telefax = $value; break;
  196. case 'description' : $description = $value; break;
  197. case 'firstname' : $firstname = $value; break;
  198. case 'lastname' : $lastname = $value; break;
  199. case 'user_name' : $user_name = $value; break;
  200. case 'user_group' : $user_group = $value; break;
  201. case 'reg_time' : $reg_time = $value; break;
  202. case 'Status' : $status = $value; break;
  203. case 'last_visit' : $last_visit = $value; break;
  204. case 'country' : $country = $value; break;
  205. case 'birthday' : $birthday = $value; break;
  206. case 'emc' : $emc = $value; break;
  207. case 'reg_ip' : $reg_ip = $value; break;
  208. case 'new_pass' : $new_pass = $value; break;
  209. case 'company' : $company = $value; break;
  210. case 'taxpay' : $taxpay = $value; break;
  211. }
  212. }
  213. // ========================================================
  214. // Wenn Produkt existiert, nicht aktualisieren
  215. // ========================================================
  216. if (trim($Id) != '')
  217. {
  218. $update = false;
  219. if ($existing == 'replace')
  220. {
  221. $sql = $AVE_DB->Query("
  222. SELECT COUNT(*)
  223. FROM " . PREFIX . "_users
  224. WHERE Id = '" . $Id . "'
  225. ");
  226. $row = $sql->FetchArray();
  227. if ($row[0] > 0)
  228. $update = true;
  229. }
  230. if ($update)
  231. {
  232. $user_group = (isset($_REQUEST['user_group']) && $_REQUEST['user_group'] != 'FILE') ? $_REQUEST['user_group'] : $user_group;
  233. $AVE_DB->Query("
  234. UPDATE " . PREFIX . "_users
  235. SET
  236. password = '" . $password . "',
  237. email = '" . $email . "',
  238. street = '" . $street . "',
  239. street_nr = '" . $street_nr . "',
  240. zipcode = '" . $zipcode . "',
  241. city = '" . $city . "',
  242. phone = '" . $phone . "',
  243. telefax = '" . $telefax . "',
  244. description = '" . $description . "',
  245. firstname = '" . $firstname . "',
  246. lastname = '" . $lastname . "',
  247. user_name = '" . $user_name . "',
  248. user_group = '" . $user_group . "',
  249. reg_time = '" . $reg_time . "',
  250. status = '" . $status . "',
  251. last_visit = '" . $last_visit . "',
  252. country = '" . $country . "',
  253. birthday = '" . $birthday . "',
  254. emc = '" . $emc . "',
  255. reg_ip = '" . $reg_ip . "',
  256. new_pass = '" . $new_pass . "',
  257. company = '" . $company . "',
  258. taxpay = '" . $taxpay . "'
  259. WHERE
  260. Id = '" . $Id . "'
  261. AND
  262. Id != '" . $_SESSION['user_id'] . "'
  263. ");
  264. }
  265. else
  266. {
  267. if (isset($_REQUEST['DelData']) && $_REQUEST['DelData'] == '1')
  268. {
  269. $AVE_DB->Query("DELETE FROM " . PREFIX . "_users WHERE Id != '" . $_SESSION['user_id'] . "'");
  270. $AVE_DB->Query("ALTER TABLE " . PREFIX . "_users PACK_KEYS = 0 CHECKSUM = 0 DELAY_KEY_WRITE = 0 AUTO_INCREMENT = 1");
  271. }
  272. if ($Id != $_SESSION['user_id']) {
  273. $AVE_DB->Query("
  274. INSERT
  275. INTO " . PREFIX . "_users
  276. SET
  277. Id = '" . $Id . "',
  278. password = '" . $password . "',
  279. email = '" . $email . "',
  280. street = '" . $street . "',
  281. street_nr = '" . $street_nr . "',
  282. zipcode = '" . $zipcode . "',
  283. city = '" . $city . "',
  284. phone = '" . $phone . "',
  285. telefax = '" . $telefax . "',
  286. description = '" . $description . "',
  287. firstname = '" . $firstname . "',
  288. lastname = '" . $lastname . "',
  289. user_name = '" . $user_name . "',
  290. user_group = '" . $user_group . "',
  291. reg_time = '" . $reg_time . "',
  292. status = '" . $status . "',
  293. last_visit = '" . $last_visit . "',
  294. country = '" . $country . "',
  295. birthday = '" . $birthday . "',
  296. emc = '" . $emc . "',
  297. reg_ip = '" . $reg_ip . "',
  298. new_pass = '" . $new_pass . "',
  299. company = '" . $company . "',
  300. taxpay = '" . $taxpay . "'
  301. ");
  302. }
  303. }
  304. }
  305. }
  306. }
  307. fclose($fp);
  308. unset($_REQUEST['action']);
  309. @unlink($TempDir . '/CSVIMPORT_user_' . $_SESSION['user_id'] . '_'.$fileid.'.txt');
  310. //header("Location:index.php?do=modules&action=modedit&mod=shop&moduleaction=shopimport&cp=".SESSION."&pop=1");
  311. echo '<script>window.close();</ script>';
  312. exit;
  313. //$AVE_Template->assign('ImportOk', 1);
  314. break;
  315. }
  316. }
  317. $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'shop_import_user.tpl'));
  318. ?>