Solved

Groupware Mass User Import using Form

Posted on 2003-11-05
35
293 Views
Last Modified: 2013-12-12
I need to import ~500 users to Group-Office (www.group-office.com) but simply importing users to SQL from CSV doesn't create the directories required or run the ACL (Access Control List) which individualizes Calendars/Address Books/File Databases, etc... This leaves me with a "logon-able" user but no features. The only way i know to be able to add a user is by using the form that one has to enter manually.  Is there a way to manipulate the form fields to correspond to a fopen() command?  I've heard of CURL, but I'm on a shared webhost, and they won't compile PHP with CURL installed...  I can provide you with the source code if you need, but it's the same as can be found at www.group-office.com.

Help is MUCH APPRECIATED!!! I'm almost always online, so feel free to e-mail me at ericdpowers@naicapital.com or IM at EPowers or EPowersWORK.

THANKS!
-Eric D. Powers
0
Comment
Question by:EPisKing
  • 21
  • 14
35 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 125 total points
ID: 9691600
hi,

i'll tell you the steps you need to take to get this working:

firstly you need to include the class your database is running and the classes associated to creating users:

require_once(database/mysql.class.inc");
require(classes/users.class.inc");
$users = new users();

you might need the language files too:

require($GO_LANGUAGE->get_language_file('users'));
require($GO_LANGUAGE->get_language_file('common'));

then you need to take apart your CSV, exploding by a line break to have an array of the rows, then explode by comma to seperate the columns. this shoudl leave you with a multidimensional array containing the entire spreadsheet. you probably want to take off the quotes on either side, so substr() will be needed to reduce the function by 1 character each side. now you can loop through the array of users and add their details to the database:

$filename = "users.csv";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
$contents = explode("\n", $contents);
$size = count($contents);
for($x = 0; $x < $size; $x++) {
  $csv[$x] = explode(",", $contents[$x]);
  foreach($csv[$key] as $key => $val) {
    $csv[$x][$key] = substr($csv[$x][$key], 1, -1);
  }
}

so now you have your entire spreadsheet in $csv as a multidimensional array. each row is held in $csv[0], $csv[1] etc. to access each column you would go to $csv[0][0], $csv[0][1] etc. at this stage it might be easiest to assign a variable to hold each column for each row before sticking it through the group office function for adding users

$numrows = count($csv);
for($i = 0; $i < $numrows; $i++) {
  $username = $csv[$i][0];
  $password = $csv[$i][1];
  $name = $csv[$i][2]; # etc - you need to have a corresponding variable for each one

then when we have the variables built up, we can put it through that function:

  if ($new_user_id = $users->add_user($username,$pass1, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user)) {
    print "Successfully added: $username<br />\n";
  } else {
    print "Error adding: $username<br />\n";
  }
}

well, that seems to me to go through and do it, the only thing is i obviously haven't tested it and i'm not sure if any more files will be required.. if necessary you can just take the whole of the top of the document from the register.php as follows:

require("../../Group-Office.php");
$GO_SECURITY->authenticate(true);
require($GO_LANGUAGE->get_language_file('users'));
require($GO_LANGUAGE->get_language_file('common'));
require($GO_CONFIG->class_path."users.class.inc");
$users = new users();

$page_title = $registration_title;
require($GO_THEME->theme_path."header.inc");

require($GO_CONFIG->class_path."/validate.class.inc");
$val = new validate;

$module_acl = isset($module_acl) ? $module_acl : array();

and stick that at the top of the page instead of the first two code chunks i gave you. anyway, tell me how you get on

cheers,

loz
0
 

Author Comment

by:EPisKing
ID: 9697663
Alright... still got a problem.  Thanks for helping, i totally appreciate it.  Below is the code i'm using in the file "CSV.php":

<?php

// start config
require("../../Group-Office.php");
$GO_SECURITY->authenticate(true);
require($GO_LANGUAGE->get_language_file('users'));
require($GO_LANGUAGE->get_language_file('common'));
require($GO_CONFIG->class_path."users.class.inc");
$users = new users();

$page_title = $registration_title;
require($GO_THEME->theme_path."header.inc");

require($GO_CONFIG->class_path."/validate.class.inc");
$val = new validate;

$module_acl = isset($module_acl) ? $module_acl : array();

// start file process

$filename = "data.csv";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
$contents = explode("\n", $contents);
$size = count($contents);
for($x = 0; $x < $size; $x++) {
  $csv[$x] = explode(",", $contents[$x]);
  foreach($csv[$key] as $key => $val) {
    $csv[$x][$key] = substr($csv[$x][$key], 1, -1);
  }
}

$numrows = count($csv);
for($i = 0; $i < $numrows; $i++) {
  $username = $csv[$i][1];
  $pass1 = $csv[$i][2];
  $name = $csv[$i][3];
  $email = $csv[$i][4];
  $company = $csv[$i][5];
  $department = $csv[$i][6];
  $function = $csv[$i][7];
  $home_phone = $csv[$i][8];
  $work_phone = $csv[$i][9];
  $fax = $csv[$i][10];
  $cellular = $csv[$i][11];
  $country = $csv[$i][12];
  $state = $csv[$i][13];
  $city = $csv[$i][14];
  $zip = $csv[$i][15];
  $address = $csv[$i][16];
  $homepage = $csv[$i][17];
  $work_address = $csv[$i][18];
  $work_zip = $csv[$i][19];
  $work_country = $csv[$i][20];
  $work_state = $csv[$i][21];
  $work_city = $csv[$i][22];
  $work_fax = $csv[$i][23];
  $date_format = $csv[$i][24];
  $thousands_seperator = $csv[$i][25];
  $decimal_seperator = $csv[$i][26];
  $currency = $csv[$i][27];
  $region = $csv[$i][28];
 
  if ($new_user_id = $users->add_user($username,$pass1, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user)) {
    print "Successfully added: $username<br />\n";
  } else {
    print "Error adding: $username<br />\n";
  }
}
// end
?>

Alright...  the stuff gets imported into mySQL, but doesn't run the ACL still... ACL controls which modules will be used, and generates and $authcode, along with a couple other functions... (btw, there's a table in the db called "db_sequence" that contains two fields called "seq_name" and "nextid".  I don't know if that means much....)  Below are the errors I'm recieving...

Warning: Invalid argument supplied for foreach() in /home/aglender/public_html/office2/administrator/users/csv.php on line 29 <---- there's about 400 of these errors (line 29 is:"   foreach($csv[$key] as $key => $val) {  ")

then it shows: "Successfully added: abundiss" etc... a bunch of them...

and then this...:

Database error: Invalid SQL: INSERT INTO users (id, username,password, name, email, authcode, work_phone, home_phone, fax, cellular, state, country, city, zip, address, company, work_country, work_state, work_city, work_zip, work_address, work_fax, homepage, department, function, acl_id, registration_time, samba_user, currency, max_rows_list) VALUES ('272', 'o'delld','password', 'Donald O'Dell', 'donald.odell at farmcreditwest', '', '', 'Lender', '(phone), '(otherphone)', '','Ca.', 'USA', 'Visalia', '93291', '"FLBA of Kingsburg', '', '', '', '', '', '', 'ADDRESS', ' FLCA"', '', '', '1068159824','0', '€', '15')

MySQL Error: 1064 (You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'delld','password', 'Donald O'Dell', 'donald.odell at farmcreditwes)
Session halted.

I'm willing to bet that the fact that this guy's last name is o'dell is the problem... do i need to stripslashes before i submit?  Is there a way to add them back in?  (no problem if no).

THANKS A BUNCH!!!!!!!
0
 

Author Comment

by:EPisKing
ID: 9697714
and also... in the CSV, i have the fields set so that if there is an apostrophe, the field will have a set of quotes around it, as in: "Sun West Farms, Inc.",,Farm Management,,(xxx) xxx-xxxx

Don't know if the php command for parsing a CSV has an option for this or not...

THANKS!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698064
hi,

foreach($csv[$key] as $key => $val) { should be foreach($csv[$x] as $key => $val) { - my mistake

i had a look through the register file again and found i probably missed some stuff out but i don't really understand what acl is and the how the groups work. i assume this is the extra stuff you need, it should replace your last few lines in the code (after $region = etc.):

  if ($acl_id = $GO_SECURITY->get_new_acl($email))
    {
    $create_samba_user = isset($create_samba_user) ? true : false;
    if ($new_user_id = $users->add_user($username,$pass1, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user)) {
      print "Successfully added: $username<br />\n";
    } else {
      print "Error adding: $username<br />\n";
    }
  } print "Error doing ACL stuff for $username<br />\n";

  //add the user to the everyone group

  require_once($GO_CONFIG->class_path."groups.class.inc");
  $groups = new groups();
  $groups->add_user_to_group($new_user_id,$GO_SECURITY->group_everyone);

  //add administrator to the users acl
  $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);

  //if user want's to be visible to any one add the everyone group to the users acl_id
  if (isset($visible))
  {
    $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_everyone, $acl_id);
  }

  //set module permissions
  for ($i=0;$i<count($module_acl);$i++)
  {
    $GO_SECURITY->add_user_to_acl($new_user_id, $module_acl[$i]);
  }
}
// end
?>

that should do group and acl things, im not sure about module permissions and visibility but if you don't think they should be there, you can take them out. incidentally, does your csv have column A as if field?

you're right about the o'delld surname, it might be best if you add an addslashes() function around each field, e.g. $username = addslashes($csv[$i][1]);

to check for double quotes around your fields, you can just do:

$first = substr($csv[$i][1], 1);
$last = substr($csv[$i][1], -1);
if($first == "\"" && $last == "\"") {
  $csv[$i][1] = substr($csv[$i][1], 1, -1);
}

probably best to create a function to do all this formatting:

function format($field) {
  $first = substr($field, 1);
  $last = substr($field, -1);
  if($first == "\"" && $last == "\"") {
    $csv[$i][1] = substr($field, 1, -1);
  }
  $field = addslashes($field);
  return $field;
}

and then use this by doing $username = format($csv[$i][1]); etc..

by the way, looking at your query, i dont know why FLBA of Kingsburg has a single double quote at the front, and the same after FLCA.. they'll still be present after the CSV is parsed by the script since both need to be present to be removed.

cheers,

loz
0
 

Author Comment

by:EPisKing
ID: 9698355
Alright... we're def. getting closer... go to: http://www.pastebin.com/23976 <- this is the current code i've got going... (line 82 needs to be the same order of columns as is in SQL, right?).

Let me give you a sample line from my CSV, so you can see what's going on...

abundiss,password,Sasquatch Abundis,,Bank of America,,Lender,,(559) 555-5555,(559) 555-5556,,Ca.,USA,Fresno,955555,5555 Cool guy Lane,,,,,,,,m-d-Y H:i,",",.,$,en-us,15

here's the error i'm getting:

Error adding: asswor
Error doing ACL stuff for asswor

I don't know where "asswor" is coming from... there are no users with that name... could it be your function?  Wait... it could be "password" (i inserted the field names in the first row...) so your function is cutting off the first and last letter?  It's also putting $pass1 into $user... any ideas??

THANKS!!!!!
0
 

Author Comment

by:EPisKing
ID: 9698359
OH, i just saw there's a SQL error too... (at the bottom of the page...)

Database error: Invalid SQL: INSERT INTO users_groups (user_id,group_id) VALUES (, 2)
MySQL Error: 1064 (You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' 2)' at line 1)
Session halted.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698410
regarding line 82, no the order of the variables needs to be the order that they have defined in the class - heres how they've done it:

function add_user($username, $password, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user=false, $user_id=-1)

so it looks like you need to reorder the vars you've put into line 82

change the function format to be this:

function format($field) {
  $first = substr($field, 1);
  $last = substr($field, -1);
  if($first == chr(24) && $last == chr(34)) {
    $csv[$i][1] = substr($field, 1, -1);
  }
  $field = addslashes($field);
  return $field;
}

it's meant to be password there but the functions taking the front and back off and i don't know why, but hopefully the code above will fix it..

unless you have an extra column in your sheet before the username, all the indexes should be one back for $csv as arrays start with an index of 0. so $username would become format($csv[$i][0]); etc. this would explain why pass is being put in for user

that sql error at the bottom should go away when we mix the rest of the script since the first value will then be supplied

cheers,

loz
0
 

Author Comment

by:EPisKing
ID: 9698467
alrighty... check http://www.pastebin.com/23980 for current code.

here is the first line of my csv file  (header):

username,password,name,email,company,department,function,home_phone,work_phone,fax,cellular,country,state,city,zip,address,homepage,work_address,work_zip,work_country,work_state,work_city,work_fax,date_format,thousands_seperator,decimal_seperator,currency,region,max_rows_list

now it's importing, but its saving as this: (exported to CSV)

"1";"administrator";"password";"authcode";"NAME";"admin at aglenders.org";"NAI Capital Commercial";"IT";"Manager";"661-864-1555 x21";;"661-864-1555";"661-555-5555";"USA";"CA";"Bakersfield";"93355";"15552 55th St., Suite 555";;;;;;;;"1";"d-m-Y H:i";".";",";"€";"1";"2";"1068170145";"1068158116";"0";;"15"

"12086";"sernam";"asswor";;"am";"mai";"ompan";"epartmen";"unctio";"ome_phon";"ork_phon";"a";"ellula";"tat";"ountr";"it";"i";"ddres";"omepag";"ork_addres";"ork_zi";"ork_countr";"ork_stat";"ork_cit";"ork_fa";"12101";"d-m-Y H:i";".";",";"€";"1";"0";"0";"1068171063";"0";;"15"

"12087";"bundis";"glende";;"usan Abundi";;"ank of Americ";;"ende";;"559) 445-759";"559) 445-771";;"S";"a";"resn";"370";"292 N. Palm Avenu";;;;;;;;"12102";"d-m-Y H:i";".";",";"€";"1";"0";"0";"1068171063";"1";;"15"

"12088";"bundis";"glende";;"usan Abundi";;"ank of Americ";;"ende";;"559) 445-759";"559) 445-771";;"S";"a";"resn";"370";"292 N. Palm Avenu";;;;;;;;"12103";"d-m-Y H:i";".";",";"€";"1";"0";"0";"1068171063";"1";;"15"

and it does an endless loop of that same line until i stop it...  So i don't get any error messages...

You're a HUGE help bro!  Let me know if you need more information about my specific CSV or whatever...

THANKS!!!!!
0
 

Author Comment

by:EPisKing
ID: 9698504
also, check out http://www.pastebin.com/23988 it's the users.class.inc file.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698508
looks like we've been using $i too many times - its used again on line 111 and 112, replace $i for $d there in each case, tell me if its still giving problems

loz
0
 

Author Comment

by:EPisKing
ID: 9698562
It's still deleting the first and last characters in each and every cell... I'm working on it right now... brb
0
 

Author Comment

by:EPisKing
ID: 9698604
It's also not working correctly when i have a row like this:

adamsj,password,John Adams,blah@blah.com,"Adams, Inc.",,Recruiter,,(555) 555-3009,(555) 355-3448,,STate.,USA,CITY,68144,"15555 Gold Circle, Ste 101",,,,,,,,m-d-Y H:i,",",.,$,en-us,15

(note ,"Adams, Inc.") when that happens, it shifts the "Inc." to the next column...
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698626
the function should be this:

function format($field) {
  $first = substr($field, 1);
  $last = substr($field, -1);
  if($first == chr(34) && $last == chr(34)) {
    $field = substr($field, 1, -1);
  }
  $field = addslashes($field);
  return $field;
}

that doesn't strip the first and last char off for me

loz
0
 

Author Comment

by:EPisKing
ID: 9698713
K, it's still cutting off the first and last characters, but no worries... i'll fix that.  Still getting an error, (see below)

Successfully added: sernam
Error doing ACL stuff for sernam
Successfully added: bundis
Error doing ACL stuff for bundis
Successfully added: dams
Error doing ACL stuff for dams

Any ideas?  If you need ANYTHING else to help with this, let me know.  Also, it's still moving every CSV value with a , or ' in it to the next field... Any way to fix that?  stripslashes maybe?

THANKS!!!!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698714
right, to sort out the csv problems i found a proper function for importing data from a csv file.. if this doesn't work it might be necessary to try and edit the way your csv is built (i.e. change it so that there are double quotes around every field)

$filename = "data.csv";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
$contents = explode("\n", $contents);
$size = count($contents);
for($x = 0; $x < $size; $x++) {
  $csv[$x] = explode(",", $contents[$x]);
  foreach($csv[$x] as $key => $val) {
    $csv[$x][$key] = substr($csv[$x][$key], 1, -1);
  }
}

please replace all the above with the below (the above was taking off the first and last letter as well - i must have assumed every field had quotes around it when i was writing that code)

$filename = "data.csv";
$handle = fopen($filename, "rb"); //open the file
while ($data = fgetcsv($id, filesize($filename))) //start a loop
$contents[] = $data; //put each line into its own entry in the $table array
$size = count($contents);
fclose($handle); //close file
for($x = 0; $x < $size; $x++) {
  $csv[$x] = explode(",", $contents[$x]);
}
0
 

Author Comment

by:EPisKing
ID: 9698727
It's importing "Array" into username field, and nothing into every other column...
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698751
change the code above for

$filename = "data.csv";
$handle = fopen($filename, "rb"); //open the file
while ($data = fgetcsv($id, filesize($filename))) //start a loop
$csv[] = $data; //put each line into its own entry in the $table array
$size = count($contents);
fclose($handle); //close file

i think this should work... sorry for all the mistakes, its just quite hard to do without being able to see and modify the code myself

loz
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:lozloz
ID: 9698752
arse!

that should be

$size = count($csv);

for the second last line there

loz
0
 

Author Comment

by:EPisKing
ID: 9698805
ALRIGHT!!!! ALL USERS IMPORTED CORRECTLY!!!  Whew.. that part's done... but i still get an error of:

Successfully added: adamsj
Error doing ACL stuff for adamsj
Successfully added: akkermanj
Error doing ACL stuff for akkermanj
Successfully added: albizoa
Error doing ACL stuff for albizoa

when importing... the ACL id column in table `data` is working... (the numbers are auto. increasing) but it's not assigning the right stuff for them... How would i go about setting automatic user permissions and stuff?

THANKS!!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698865
do you know what are these permissions for? can i see a code dump at this point?

loz
0
 

Author Comment

by:EPisKing
ID: 9698910
Yeah... the permissions have to do with the modules inside of Group-Office... I believe, on a new user creation, a folder is created for that person, and the user has permission to upload/download from that folder and any "shared" folder.

The modules I'm using, for every user, are Addressbook, Files, and Scheduler.  I also want each and every user to be visible...

code dump:

<?php

// start config
require("../../Group-Office.php");
$GO_SECURITY->authenticate(true);
require($GO_LANGUAGE->get_language_file('users'));
require($GO_LANGUAGE->get_language_file('common'));
require($GO_CONFIG->class_path."users.class.inc");
$users = new users();

$page_title = $registration_title;
require($GO_THEME->theme_path."header.inc");

require($GO_CONFIG->class_path."/validate.class.inc");
$val = new validate;

$module_acl = isset($module_acl) ? $module_acl : array();

// end config
// start formatting function


function format($field) {
  $first = substr($field, 1);
  $last = substr($field, -1);
  if($first == chr(34) && $last == chr(34)) {
    $field = substr($field, 1, -1);
  }
  $field = addslashes($field);
  return $field;
}


// end formatting function
// start file process

$filename = "data.csv";
$handle = fopen($filename, "rb"); //open the file
while ($data = fgetcsv($handle, filesize($filename))) //start a loop
$csv[] = $data; //put each line into its own entry in the $table array
$size = count($csv);
fclose($handle); //close file

// end file process
// start naming columns

$numrows = count($csv);
for($i = 0; $i < $numrows; $i++) {
  $username = format($csv[$i][0]);
  $pass1 = $csv[$i][1];
  $name = format($csv[$i][2]);
  $email = $csv[$i][3];
  $company = format($csv[$i][4]);
  $department = $csv[$i][5];
  $function = $csv[$i][6];
  $home_phone = $csv[$i][7];
  $work_phone = $csv[$i][8];
  $fax = $csv[$i][9];
  $cellular = $csv[$i][10];
  $country = $csv[$i][11];
  $state = $csv[$i][12];
  $city = $csv[$i][13];
  $zip = $csv[$i][14];
  $address = format($csv[$i][15]);
  $homepage = $csv[$i][16];
  $work_address = $csv[$i][17];
  $work_zip = $csv[$i][18];
  $work_country = $csv[$i][19];
  $work_state = $csv[$i][20];
  $work_city = $csv[$i][21];
  $work_fax = $csv[$i][22];
  $date_format = $csv[$i][23];
  $thousands_seperator = format($csv[$i][24]);
  $decimal_seperator = $csv[$i][25];
  $currency = $csv[$i][26];
  $region = $csv[$i][27];
 
if ($acl_id = $GO_SECURITY->get_new_acl($email))
    {
    $create_samba_user = isset($create_samba_user) ? true : false;
if ($new_user_id = $users->add_user($username,$pass1, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user)) {
      print "Successfully added: $username<br />\n";
    } else {
      print "Error adding: $username<br />\n";
    }
  } print "Error doing ACL stuff for $username<br />\n";

  //add the user to the everyone group

  require_once($GO_CONFIG->class_path."groups.class.inc");
  $groups = new groups();
  $groups->add_user_to_group($new_user_id,$GO_SECURITY->group_everyone);

  //add administrator to the users acl
  $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);

  //if user want's to be visible to any one add the everyone group to the users acl_id
  if (isset($visible))
  {
    $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_everyone, $acl_id);
  }

  //set module permissions
  for ($d=0;$d<count($module_acl);$d++)
  {
    $GO_SECURITY->add_user_to_acl($new_user_id, $module_acl[$i]);
  }
}
// end
?>

THANKS!!!! Let me know if you need any of the code from the includes (they're 'stock')
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698924
                       //create Group-Office home directory
                        $old_umask = umask(000);
                        mkdir($GO_CONFIG->file_storage_path.$username, $GO_CONFIG->create_mode);
                        umask($old_umask);

                        //add the automatic bookmarks that the administrator has created
                        //load the autobookmarks setting into an xpath object
                        require($GO_CONFIG->class_path.'xpath.class.inc');
                        $xpath = new xpath();
                        if (!$xml = $GO_CONFIG->get_setting('autobookmarks'))
                        {
                              $xml = '<bookmarks></bookmarks>';
                        }
                        $xpath->importFromString($xml);
                        $auto_bookmarks = $xpath->match('/bookmarks/bookmark');
                        require_once($GO_CONFIG->class_path.'bookmarks.class.inc');
                        $bookmarks = new bookmarks();
                        if (count($auto_bookmarks) > 0)
                        {
                              while($bookmark = array_shift($auto_bookmarks))
                              {
                                    $bookmark = $xpath->getAttributes($bookmark);
                                    $new_window = ($bookmark['new_window'] == 'true') ? 1 : 0;
                                    $bookmarks->add_bookmark($new_user_id, $bookmark['url'], $bookmark['name'], $new_window);
                              }
                        }

you probably want to add all that after the 2nd last } then

loz
0
 

Author Comment

by:EPisKing
ID: 9698972
K... do you want to see code from xpath.class.inc?
Here's the error:

---------------------------------------

Successfully added: username
Error doing ACL stuff for username

Successfully added: abundiss
Error doing ACL stuff for abundiss

Fatal error: Cannot redeclare class xpathbase in /(PATH)/xpath.class.inc on line 169
0
 

Author Comment

by:EPisKing
ID: 9698975
COMPLETE CODE:

<?php

// start config
require("../../Group-Office.php");
$GO_SECURITY->authenticate(true);
require($GO_LANGUAGE->get_language_file('users'));
require($GO_LANGUAGE->get_language_file('common'));
require($GO_CONFIG->class_path."users.class.inc");
$users = new users();

$page_title = $registration_title;
require($GO_THEME->theme_path."header.inc");

require($GO_CONFIG->class_path."/validate.class.inc");
$val = new validate;

$module_acl = isset($module_acl) ? $module_acl : array();

// end config
// start formatting function


function format($field) {
  $first = substr($field, 1);
  $last = substr($field, -1);
  if($first == chr(34) && $last == chr(34)) {
    $field = substr($field, 1, -1);
  }
  $field = addslashes($field);
  return $field;
}


// end formatting function
// start file process

$filename = "data.csv";
$handle = fopen($filename, "rb"); //open the file
while ($data = fgetcsv($handle, filesize($filename))) //start a loop
$csv[] = $data; //put each line into its own entry in the $table array
$size = count($csv);
fclose($handle); //close file

// end file process
// start naming columns

$numrows = count($csv);
for($i = 0; $i < $numrows; $i++) {
  $username = format($csv[$i][0]);
  $pass1 = $csv[$i][1];
  $name = format($csv[$i][2]);
  $email = $csv[$i][3];
  $company = format($csv[$i][4]);
  $department = $csv[$i][5];
  $function = $csv[$i][6];
  $home_phone = $csv[$i][7];
  $work_phone = $csv[$i][8];
  $fax = $csv[$i][9];
  $cellular = $csv[$i][10];
  $country = $csv[$i][11];
  $state = $csv[$i][12];
  $city = $csv[$i][13];
  $zip = $csv[$i][14];
  $address = format($csv[$i][15]);
  $homepage = $csv[$i][16];
  $work_address = $csv[$i][17];
  $work_zip = $csv[$i][18];
  $work_country = $csv[$i][19];
  $work_state = $csv[$i][20];
  $work_city = $csv[$i][21];
  $work_fax = $csv[$i][22];
  $date_format = $csv[$i][23];
  $thousands_seperator = format($csv[$i][24]);
  $decimal_seperator = $csv[$i][25];
  $currency = $csv[$i][26];
  $region = $csv[$i][27];
 
if ($acl_id = $GO_SECURITY->get_new_acl($email))
    {
    $create_samba_user = isset($create_samba_user) ? true : false;
if ($new_user_id = $users->add_user($username,$pass1, $name, $email, $authcode, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $acl_id, $create_samba_user)) {
      print "Successfully added: $username<br />\n";
    } else {
      print "Error adding: $username<br />\n";
    }
  } print "Error doing ACL stuff for $username<br />\n";

  //add the user to the everyone group

  require_once($GO_CONFIG->class_path."groups.class.inc");
  $groups = new groups();
  $groups->add_user_to_group($new_user_id,$GO_SECURITY->group_everyone);

  //add administrator to the users acl
  $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);

  //if user want's to be visible to any one add the everyone group to the users acl_id
  if (isset($visible))
  {
    $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_everyone, $acl_id);
  }

  //set module permissions
  for ($d=0;$d<count($module_acl);$d++)
  {
    $GO_SECURITY->add_user_to_acl($new_user_id, $module_acl[$i]);
  }
 //create Group-Office home directory
                    $old_umask = umask(000);
                    mkdir($GO_CONFIG->file_storage_path.$username, $GO_CONFIG->create_mode);
                    umask($old_umask);

                    //add the automatic bookmarks that the administrator has created
                    //load the autobookmarks setting into an xpath object
                    require($GO_CONFIG->class_path.'xpath.class.inc');
                    $xpath = new xpath();
                    if (!$xml = $GO_CONFIG->get_setting('autobookmarks'))
                    {
                         $xml = '<bookmarks></bookmarks>';
                    }
                    $xpath->importFromString($xml);
                    $auto_bookmarks = $xpath->match('/bookmarks/bookmark');
                    require_once($GO_CONFIG->class_path.'bookmarks.class.inc');
                    $bookmarks = new bookmarks();
                    if (count($auto_bookmarks) > 0)
                    {
                         while($bookmark = array_shift($auto_bookmarks))
                         {
                              $bookmark = $xpath->getAttributes($bookmark);
                              $new_window = ($bookmark['new_window'] == 'true') ? 1 : 0;
                              $bookmarks->add_bookmark($new_user_id, $bookmark['url'], $bookmark['name'], $new_window);
                         }
                    }

}
// end
?>
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9698996
try taking out the line $xpath = new xpath(); and putting it under the new users() line

i dont know what these bookmarks do though..

loz
0
 

Author Comment

by:EPisKing
ID: 9699055
I had to move the " require($GO_CONFIG->class_path.'xpath.class.inc'); " line to the top of the code... and i get this error:

Successfully added: abundiss
Error doing ACL stuff for abundiss
XPath error in xpath.class.inc:1692 In importFromString(): Called when this object already contains xml data. Use reset() or pass the parent Xpath as 2ed param to where tie data will append.
Successfully added: adamsj
Error doing ACL stuff for adamsj
XPath error in xpath.class.inc:1692 In importFromString(): Called when this object already contains xml data. Use reset() or pass the parent Xpath as 2ed param to where tie data will append.

hmm...

THANKS!!!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9699073
try adding

$xpath->reset($xml);

before

if (!$xml = $GO_CONFIG->get_setting('autobookmarks'))

loz
0
 

Author Comment

by:EPisKing
ID: 9699112
AWESOME!!! SO FAR IT'S WORKING!

Let me test around with it for a bit, and I'll get you the points tomorrow!

THANKS A MILLION!! I owe you man!

-Eric
0
 

Author Comment

by:EPisKing
ID: 9703373
Alright... The modules are showing up just fine, but the permissions aren't right... Any idea what the ACL does to allocate the permissions? Here's my current code: http://pastebin.com/24102

Thanks Again!
-Eric
0
 

Author Comment

by:EPisKing
ID: 9703404
check out controls.class.inc in the classes directory on lines 85-582.  Should that be included in the PHP?
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9703432
line 107 the $i needs to be $d
0
 

Author Comment

by:EPisKing
ID: 9703921
Everything seems to be working except for two things... 1st, the MASTER calendar (created by administrator) should be seen by group: Everyone by default.  (they should not be able to write).  Also, there the ACL (or DB function) that creates the field: authcode in the table: users is not being populated.

THANKS!!!!
-Eric
0
 

Author Comment

by:EPisKing
ID: 9704856
I'm getting a bunch of wierd stuff... Some of the users can view the file storage, and some can't.  I've been looking at what the differences are between ones that work and ones that don't, and i have no idea what's causing this... Check the code i'm using to import please...

http://www.pastebin.com/24132

thanks!!
-EP
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9705589
$authcode = $users->random_password();
add this below line 72

i don't know what this master calendar thing is or where it should be viewed.. as far as i can see there's no mention of any calendars in this register script. i don't know what the file storage is either, the only line i can see that does anything to this is line 107 and it's a copy of the one in register.php

loz
0
 

Author Comment

by:EPisKing
ID: 9706135
It's cool. I'll figure it out.  Thanks for all the help!!! You're AWESOME!

-Eric
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP/Magento not logging 2 35
what is best version of php to use 6 46
php refresh button on the browser 2 35
php string masking 4 28
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now