there are many ways to load existing patrons into the evergreen
database.i created a php script to create the sql for me which i then
executed in a postrgres frontend.
this is the php script i used.its in the attachement .my users were in
a databse so i had to write  some lines to connect to the database and
then get the users.
you can read from the csv file to get the users if thats your purpose
remove parts of the code which arent relevant to you
i  edited the example i saw in the  subversion repositry to suite my purpose
.
but check in the database to see what profile_id corresponds to what
kind of user

.there are a couple of scripts in  tthe repository  that you can use
go here
http://svn.open-ils.org/trac/ILS-Contrib/browser/conifer/trunk/tools/migration-scripts
cheers!!!
On 9/15/09, Levani EL <[email protected]> wrote:
> hello
> I wish to import students to a database to
> (register) know that the information I can find in CARD, usr
> and usr_address. I know that it is necessary to do CSV file look
> attachment. I think that it will go.
>
> i know steps:
> 1) create new table in postgre
> 2) copy csv to table
> 3) import to database
>
> what about home library, address and etc.
> i found script wrote in python but don`t help
> how generate barcodes and passwords?
>
> how write this steps correct in postgresql step by step?
> any documentation?
>
> thank you
>
<?php
//Connection statement
require_once('../../Connections/test.php');


// Load the common classes
//require_once('../../includes/common/KT_common.php');
//$conn_cndeis = new KT_connection($cndeis, $database_cndeis);


$profiles= array();
$profiles[0]=0;//users 
$profiles[1]=4;//administrators
$profiles[5]=5;//circulator ids
$profiles[10]=10;// administrators







$stud_data=array();
$real_stud_array=array();
$username;
$usefname;
$userlname;
$useremail;
$password;
$sql="BEGIN;\n";
$cnt=0;
$server_ip="http://localhost/includes/photos.php?";;
//$staff_data="SELECT users.username as  regno, substring(users.fullname,instr(users.fullname," ")+1) as lname,substring(users.fullname,1,instr(users.fullname," "))as fname,users.email as email FROM users";
//mysql_select_db("deis",$cndeis);
$query_rsTitles = "SELECT  regno,lname,fname,email,mname,studid,doa  from students_db";
$query_res=mysql_query($query_rsTitles) or die(mysql_error());
while($restrow=mysql_fetch_assoc($query_res))
{
 //echo  $restrow['regno']."<br>";

//http://192.168.0.30/includes/studphoto.php?stid=0002878163&doa=MAY2006&lib_stud=true




//this is where the code that would be doing the  insertion of the staff would be 
 $username=$restrow['regno'];
 $password=$restrow['regno'];
 $userlname=$restrow['lname'];
 $userfname=$restrow['fname'];
  $useremail=$restrow['email'];
$secondname=$restrow['mname'];
$studid=$restrow['studid'];
  $photo_url=$server_ip."stid=".$restrow['studid']."&doa=".$restrow['doa']."&lib_stud=true";
//contemplating whether to add dob,hall,phoneid
//  $twodigit = sprintf('%02d', $cnt);
 //echo  $barcode = "1" . "1" . base_convert ($twodigit, 10, 2);
 $sql.="INSERT INTO actor.usr (profile, usrname, passwd, ident_type, ident_value, first_given_name, family_name, home_ou,email,second_given_name,photo_url,) VALUES (1, '$username', '$password', 3, '$studid', '$userfname', '$userlname',4,'$useremail','$secondname','$photo_url');\n
INSERT INTO actor.card (usr, barcode) VALUES (CURRVAL('actor.usr_id_seq'), '$username');\n
INSERT INTO actor.usr_address (usr, street1, city, state, country, post_code) VALUES (CURRVAL('actor.usr_id_seq'), 'Koforidua Campus', 'Koforidua', '  ', 'Ghana', '00233');\n
UPDATE actor.usr SET card = CURRVAL('actor.card_id_seq'), mailing_address = CURRVAL('actor.usr_address_id_seq') WHERE id = CURRVAL('actor.usr_id_seq');\n
INSERT INTO permission.usr_work_ou_map (usr, work_ou) VALUES (CURRVAL('actor.usr_id_seq'),4);\n";
 //if($cnt==5)
//{break;}
$cnt++;
    }


$sql .= "SELECT SETVAL('actor.usr_id_seq', (SELECT MAX(id) FROM actor.usr));\n";
$sql .= "SELECT SETVAL('actor.usr_address_id_seq', (SELECT MAX(id) FROM actor.usr_address));\n";
$sql .= "SELECT SETVAL('actor.card_id_seq', (SELECT MAX(id) FROM actor.card));\n";

 $sql.="END;";

//print_r($sql);




 
$fw = fopen("stud.sql","w")or die ("cant open file"); 
fwrite($fw,$sql)or die("couldent write to file"); 
fclose($fw) or die("couldent close file");
echo "users  data inserted into sql file";
echo "$cnt";

/*
BKF/07/01/0438BKF/07/01/0438AbaloSandra 00110 BKF/07/01/1437BKF/07/01/[email protected] 01111
SELECT 
	users.username as  regno, 
substring(users.fullname,instr(users.fullname," ")+1) as lname,
substring(users.fullname,1,instr(users.fullname," "))as fname,
	users.email as email
FROM users
*/
//fname,lname,mname.email,address,expirydate,phone number,prefix
?>
















Reply via email to