Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch Teamcal 3.3.009 -> Fix and Extend CSV-Import
diff --git a/includes/csvhandler.class.php b/includes/csvhandler.class.php
index 44788cd..618f664 100755
--- a/includes/csvhandler.class.php
+++ b/includes/csvhandler.class.php
@@ -264,7 +264,7 @@ if (!class_exists("CsvImport")) {
if ($fpointer) {
while ($arr = fgetcsv($fpointer, 10 * 1024, ";")) {
if (is_array($arr) && !empty ($arr)) {
- if (count($arr)<>11) {
+ if ((count($arr)<11) or (count($arr)>12)) {
$this->error = $LANG['uimp_err_col_1'].$arr[0].$LANG['uimp_err_col_2'].count($arr).$LANG['uimp_err_col_3'];
unset ($arr);
fclose($fpointer);
@@ -272,7 +272,8 @@ if (!class_exists("CsvImport")) {
return;
}
else {
- if ( !$U->findByName(trim($arr[0])) && $arr[0]!="admin" ) {
+ # Skip users that are already present, and don't change admin. A user called 'username' intents to be the headline
+ if ( !$U->findByName(trim($arr[0])) && $arr[0]!="admin" && $arr[0]!='username') {
$U->username = trim($arr[0]);
$U->password = crypt("password", $CONF['salt']);
$U->firstname = $arr[1];
@@ -296,7 +297,14 @@ if (!class_exists("CsvImport")) {
$U->notify = 0;
$U->create();
- $UG->createUserGroupEntry($U->username, $defgroup, "member");
+ if ($arr[11]) {
+ $groups=explode(',',$arr[11]);
+ foreach ($groups as $group) {
+ $UG->createUserGroupEntry($U->username, $group, "member");
+ }
+ } else {
+ $UG->createUserGroupEntry($U->username, $group, "member");
+ }
$UO->create($U->username, "owngroupsonly", "no");
if (strtolower($arr[10])=="yes" || strtolower($arr[10])=="1") {
@@ -327,4 +335,4 @@ if (!class_exists("CsvImport")) {
} // End Class CsvImport
} // End if (!class_exists("CsvImport"))
-?>
\ No newline at end of file
+?>
diff --git a/userimport.php b/userimport.php
index 1efe236..b55bb32 100755
--- a/userimport.php
+++ b/userimport.php
@@ -52,7 +52,7 @@ if ( !checkAuth("admin") ) {
*/
global $HTTP_POST_FILES;
if ( isset($_POST['btn_import']) ) {
- $CSV->file_name = $HTTP_POST_FILES['file_source']['tmp_name'];
+ $CSV->file_name = $_FILES['file_source']['tmp_name'];
$CSV->import($_POST['list_defgroup'],$_POST['list_deflang'],$_POST['chk_lockuser'],$_POST['chk_hideuser']);
}
elseif ( isset($_POST['btn_done']) ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.