This topic is locked

Import Page - Before Process event needed

6/5/2010 2:36:07 PM
PHPRunner General questions
A
acpan author

Hi, Thanks for the powerful and flexible import events. Now we can do almost everything with import function.

However, I find that we need another event for import, like most other Add and List Pages - The "Import Page - Before Process". even. "Before Process event" in phpr 5.2's Add, Edit and List pages is extremely useful

to capture http post values so that we can process data according to user's specific filter

conditions from another page using http post.
For that i suggest to have it also include in the import page which is exlcuded in 5.2, This event can capture a http post value from another page, such as: indication to delete the data in a table before processing the import, category id etc...:
So putting below at the new "before process event" in import page:

if (isset($_REQUEST["d"]))

{

$_SESSION["d"] = $_REQUEST["d"];

}
P.S. I would used the above to put a customer link at each addressbook table category name and let user click to import page directly. A lot of users always get lost and not able to find the import link in the next child page.
Example: my Phonebook Cateogry fields can be like:

Category_ID |Category_Name | Delete_before_import | import_now
Then user clicks import_now link which stores the http post values of the category,

delete_before_import such as: <a href="_import.php?d=1&cid=123" target = "_blank"></a>
then he can be taken directly to import page and the current import events

in phpr 5.2 can be executed.
////////////////////////////////////////////////////////////////////////

Below are how i use the current import events and found to be very powerful

in phpr 5.2:

////////////////////////////////////////////////////////////////////////
//////////

Event: before import started:

// to set execution time to no limit to handle large file

set_time_limit(0);

//
to set execution time to no limit to handle large file

$_SESSION["counter"] = 0;
// note $_SESSION["d"] below is global session variable to indicate to delete or not,

// all the data in a table before import. currently this value need to be extracted from a

// table and store it in SESSION variables prior to process the events below.

// if before process event is implemented for import function, it can be simplified further.
if ($_SESSION["d"] == 1 )

{

$strSQL_rid = "delete from addressbook where cat_id =".$_SESSION["c"]. " AND id_client=".$_SESSION["id_client"];

if (db_exec($strSQL_rid,$conn))

{

$v_echo = mysql_affected_rows()." old record(s) deleted! proceeding to import...";

echo("<script>alert('".$v_echo."');</script>");

}

}

return true;

//////////
Event: Before insert record

///////////

$_SESSION["counter"] = $_SESSION["counter"] = +1;

$v_cat_id = $_SESSION["c"];

$values["id_client"] = $_SESSION["id_client"];

$values["id_reseller"] = $_SESSION["id_reseller1"];

$values["cat_id"] = $_SESSION["c"];

$values["phone_number"] = trim($values["phone_number"]);
// If excel spreadsheet value is 8 digit, prefix it before import

if (strlen($values["phone_number"]) == 8 )

{

$v_phone_number = $values["phone_number"];

$values["phone_number"] = "00".$values["phone_number"];

echo "
Number modified:".$v_phone_number."->".$values["phone_number"];

}

if ( strlen($values["phone_number"]) == 0 )

{

echo "
Empty record skipped:".$_SESSION["counter"] ;

return false;

}
if( strlen($values["phone_number"]) < 4 )

{

echo "
Invalid number skipped".$values["phone_number"];

return false;

}
global $conn;

$strSQL8a = 'SELECT count(*) as cnt from addressbook where cat_id ='.$_SESSION["c"]. ' AND id_client='.$_SESSION["id_client"];

$strSQL8a .= ' AND phone_number = "'.$values["phone_number"].'"';

$rs8a = db_query($strSQL8a,$conn);

$data8a = db_fetch_array($rs8a);

if($data8a["cnt"] >= 1)

{

echo "
Same record skipped:".$values["phone_number"];

return false;

}
// !!!!!!! Note: return false will skip the current line and proceed to

// import the next line.

// It will be nice to ALSO have a "skip all" command to stop all subsequent imports,

// in case all other lines are suspected to be space or invisible characters.

// then server load can be minimized. Many users who prepare the import files

// include a lot of space in the file and cause the server busy processing

// useless data. So with this, we can have option to stop all processing after

// any empty line or space are detected.
return true;

;

//////////
Event: After Import Finished

/////////

$_SESSION["counter"] = 0;

$v_echo = "Record(s) skipped:".$skipCount.", Record(s) imported:".$count;

echo("<script>alert('".$v_echo."');</script>");

// set execution time back to normal

set_time_limit(180);

//
set execution time back to normal

////////

/////////////////////////////////////////////////////////////////
Thanks

acp