Hello,
This function would be great to have:
Export the users in csv file with the possibility to modify the order at which the columns are output for maximum compability with other sources.
Thank you.
Ben
Export users as csv
Re: Export users as csv
You can do this but not directly in AppGini in its current state.
Your provider most likely has phpmyAdmin setup and you can export a database in many formats or just the data. Depending on how often you wish to do this doing it in phpmyAdmin or some other app is very easy. I use Navicat and it works for me.
Now if you are doing this very often (once a day or more) then a built in function would make it easier but I cannot figure out an instance where you would need to do this very often. It really comes down to usage and frequency. You can also take the csv data output from phpmyAdmin (as an example) and bring it into excel then have an excel macro sort the columns as you wish.
But you could built it yourself using fputcsv and then write some code which shows you the field names and you could put a 1, 2, etc beside them in a box and then have your code use the ranking to determine the output/sort order. You could have this appear at the bottom of the Members page.
See this link:
http://php.net/manual/en/function.fputcsv.php
Let this list know how often you would need this functionality. It would not be hard to add this into pageViewMembers.php found in the admin folder. As there are a limited # of fields in the members table I most likely would write the code to run a function which displays a field list, and as above, you put numbers beside them to state the output order.
I just tested doing this with Navicat, exported the data with field titles, opened in Excel, re-arranged the columns and it took less than 2 minutes.
Another question I would have is do you need this done by someone who does not have admin access but needs that data?
I know this does not answer your question directly but the answers may help in deciding if such a function is needed or is really a specialized function that may not be used by enough to warrant building it in.
Darn, while writing this I think I have figured it all out. But no time to test/write the code.
Alan
Your provider most likely has phpmyAdmin setup and you can export a database in many formats or just the data. Depending on how often you wish to do this doing it in phpmyAdmin or some other app is very easy. I use Navicat and it works for me.
Now if you are doing this very often (once a day or more) then a built in function would make it easier but I cannot figure out an instance where you would need to do this very often. It really comes down to usage and frequency. You can also take the csv data output from phpmyAdmin (as an example) and bring it into excel then have an excel macro sort the columns as you wish.
But you could built it yourself using fputcsv and then write some code which shows you the field names and you could put a 1, 2, etc beside them in a box and then have your code use the ranking to determine the output/sort order. You could have this appear at the bottom of the Members page.
See this link:
http://php.net/manual/en/function.fputcsv.php
Let this list know how often you would need this functionality. It would not be hard to add this into pageViewMembers.php found in the admin folder. As there are a limited # of fields in the members table I most likely would write the code to run a function which displays a field list, and as above, you put numbers beside them to state the output order.
I just tested doing this with Navicat, exported the data with field titles, opened in Excel, re-arranged the columns and it took less than 2 minutes.
Another question I would have is do you need this done by someone who does not have admin access but needs that data?
I know this does not answer your question directly but the answers may help in deciding if such a function is needed or is really a specialized function that may not be used by enough to warrant building it in.
Darn, while writing this I think I have figured it all out. But no time to test/write the code.
Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -
Re: Export users as csv
Hi Shasta59,
Thank you,
I have added this script inside the site:
It works well but now I am unsure on how to protect it from being executed from the public.
I understand I can put permission to stop this but how Can I call this function inside the appgini app and still get my csv file generated.
As I understand it, php can be executed locally, publicly or by the owner. But how can I stop the public from calling this file in the browser while still being able to call it from inside the appgini admin panel?
Any idea please?
Thank you,
Ben
Thank you,
I have added this script inside the site:
Code: Select all
<?php
require_once './config.php';
$conn = mysqli_connect("localhost", $username, $password, $db_name)or die("cannot connect");
$sql = "SELECT phone_no FROM $tbl_name ORDER BY id";
$results = $conn->query($sql);
// Pick a filename and destination directory for the file
// Remember that the folder where you want to write the file has to be writable
$filename = "sms_user_export_".time().".csv";
// Actually create the file
// The w+ parameter will wipe out and overwrite any existing file with the same name
$handle = fopen($filename, 'w+');
// Write the spreadsheet column titles / labels
fputcsv($handle, array('phone_number'));
// Write all the user records to the spreadsheet
foreach($results as $row)
{
fputcsv($handle, array($row['phone_number']));
}
// Finish writing the file
fclose($handle);
?>
It works well but now I am unsure on how to protect it from being executed from the public.
I understand I can put permission to stop this but how Can I call this function inside the appgini app and still get my csv file generated.
As I understand it, php can be executed locally, publicly or by the owner. But how can I stop the public from calling this file in the browser while still being able to call it from inside the appgini admin panel?
Any idea please?
Thank you,
Ben
Re: Export users as csv
Sorry if this is too late already, but thought it might answer the question for anyone searching for it. You can check the session variables for the current username and if it doesn't match any of the allowed users, then exit:
Code: Select all
session_start();
$allowed_users = array('admin', 'user1', 'user2');
if(!in_array($_SESSION['memberID'], $allowed_users)){
die("Access denied.");
}

- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.
- Need personalized consulting on your specific app and customizations? Book an online call with me here.