Best way to handle server-side user files? - php

I'm trying to make a webapp. The application I am making for myself to help with foreign language translations for classes at my college, and I am hoping to make it available online. All the data that the site saves is in a format like:
section 1
foreign text
translated text
section 2
foreign text
translated text
The app relies on javascript and jquery, so I thought JSON would be a good format for the data. I've got a basic user system set up, I just need to know the best way to handle the projects. What seems easiest is to just have a directory on my site in which there is a folder for every user. Every user's folder would have an individual file for each project they've made. In the load dialog the php will print the list of files in the user's directory so as to make a list of saved projects.
I don't believe this is the best solution; I'm kind of hacking this together as I go along. Would one giant json file for each user be better, or just a pain to code?

I would put everything in a database and not in individual files.
Is there a reason you canĀ“t use a database?
Example:
The simple basic setup with a database would be something with 2 tables:
Users:
user_id
name
etc.
Texts:
project_id
user_id
foreign_text
translated_text
Where the foreign_text and translated_text are of type text.

Related

Using Wordpress and Gravity Forms as a front end for querying a database

I have a project that I'd like to integrate into a wordpress site that I run. I realize that wordpress isn't the best way to do this- but it's what I have at the moment.
My project involves taking archival data, uploading it into a relational database, and then being able to query it. the data is in the form of
"reports" each of which have mixed data- ship's names, people's names, locations, all kinds of things.
so I have created a database where I'm uploading all the data- a MySQL database. Because I have phpmyadmin access, adding the 10 or 12 tables or whatever it turns out to be will be extremely easy. I'm not worried about that.
My problem, however, is programming the front end.
The idea is this
Page (not post) 1: User chooses which 1 of a number of pre-set queries they'd like to run (IE retrieve a report, get all data for 1 ship, for 1 officer, 1 location etc), as well as a date range.. (I'm planning to use Gravity Forms for this part)
Page 2: based on what was done the first time, the tables I've added to the WPDB is queried, and whatever is selected is used to populate a drop-down list from which the user can use choose the ship/officer/location etc.
This will result in another query, and the result of which will be the user will be taken to another page where a PDF will be generated of the retrieved data that they can look at/save.
I've looked hard but I can't see any plugins that will actually do this- lots of plugins writing to the DB (or custom tables), but not that focus on retrieving and displaying data from custom tables.
Now, I've seen a bunch of conflicting information
1) That I should do this via adding functions to the theme (Bangkok Press) functions.php file- which I undrestand in concept- but I don't understand how I could then call them
2) I can create a custom plugin- If I could, I'd love to modify Gravity Forms so that the when the form is submitted, a query is triggered that retrieves from the DB- I know I could write the code, I'm just not sure where I would modify the code.
3) I've seen tutorials that talk about custom pages and page templates and putting PHP and HTML in them- I did write a version of this on my home dev server that is just PHP and HTML- if I could put that into a custom page and modify it so that it a) works with the template and b) uses the Wordpress hooks (such as the WPDB object) that would be fine with me too.
I'm going to say again- I know that Wordpress is not the ideal platform for that. At the moment, I don't have the option to change to another platform.
I'm sure that what I want to do is possible- I'm interested in what's the best way to achieve this- and what's probably the easiest way to achieve this (which doesn't have to be the most permanent- I'm looking to take this project to show what I mean by the idea, and then work on a better version after that)
I appreciate all advice, thanks.

Front-End for MySQL Forms (Windows or OSX)

[Edit: I have awarded the bounty but not the question, as I feel there is still a chance for a better answer.]
I usually code my MySQL data entry interfaces in php.
But for quick projects where I would like to focus on the web side of things (pulling data from the database), I am looking for a form front-end to MySQL. Ideally, this would be an off-the-shelf Win or OSX program that I can hand over to a friend or client so she can input data into forms.
An Example
The lines above summarize the question, but here is a typical situation to showcase why "just give them phpMyAdmin" or some other web interface to MySQL generally wont work.
We have two main tables: images and albums. The third is an associative table that associates images with albums.
Images: id (PK), filename
Albums: id (PK), album
Album_Image: id (PK), imageid, albumid (these are foreign keys: the two id PKs from the Images and Albums tables)
For big projects, I don't mind coding a nice "back-end" interface (CRUD) that lets me edit data in a very comfortable, customized way.
For small projects, for instance an image gallery for a friend, I would like to be able to only program the "front-end": web interfaces that pull data from the database.
For the back-end, ideally, I would like to give my friend an off-the-shelf solution so she can enter images, albums, and associations between images and albums.
In the old days (I am thinking of DBaseIII), it was really easy to give interfaces to do that entry side of things.
Here is a crude approach I have tried. I have set up a view of the associative table joined to the parent tables, so it shows albumid, imageid (the PKs) and album, filename (associated fields in the parents) using this query:
SELECT albumid, imageid, album, filename FROM album_image axi
JOIN albums a ON a.`id` = axi.`albumid`
JOIN images i ON i.`id` = axi.`imageid`
The idea with this crude approach is that my friend would enter the parent PKs (albumid and imageid) in the associative table through the view, and that after hitting Insert, the full parent fields (filename and album) would be visible in the View for visual feedback. I have tried this view in three GUI tools: SQLyog (Win), HeidiSQL (Win) and Sequel Pro (OSX).
In Heidi and Sequel Pro, I have not found a way to edit the view.
In SQLyog, I can edit the PK fields (albumid and imageid) in the view, and the parent fields (album and filename) show properly when I hit "refresh". That's great. It works because even though the view shows three tables, we are only editing from one table. But I cannot delete a row as SQLyog doesn't know from which of the three tables we are trying to delete. On the other hand, in SQLyog, I able both able to insert and delete in a Query tab that contains the same query that creates the view, because in this kind of tab SQLyog allows me select the table being edited. So that works, but this workflow might start to be a little complex for my friend: she would have to open SQLyog, connect, open a saved query, select the right table to edit within the query, and make all the other right moves.
Wondering if any one knows an existing tool that is really good at making forms for MySQL---ideally a Windows or OSX binary. I will consider a web solution, but I am not interested in a framework---the key is speed of deployment, and if we went the framework route I would be better off making the interface with my own CRUD libraries. Again, I can code it, but my goal with these kinds of "quickie projects" is to focus my workload on the front end (web interface to the database), leaving the back end to an off-the-shelf tool.
Thanks heaps in advance for any insights. :)
Edit: I see that no one has mentioned Navicat or MySQL Workbench. I haven't tried either, wondering if someone knows off the top of their head whether they would do the trick.
I think what you're looking for is a form front-end for MySQL.
Since it sounds like you are more interested in binaries than web apps, have you looked into Microsoft Access? It can talk to MySQL and could be just what you need.
Open Office Base may not have quite the features you're looking for.
You already have the solution, your attempt at making things simpler is creating the complication.
There is no benefit to your friend in adding album images in a view if that view that only shows the filename and album title after they have entered the IDs and clicked Insert.
Before adding an image, your friend needs to know the album ID and the image ID. This information may not be in the view. She will therefore look at the album table and look at the image table to find this information, cross-referencing the filename with her own list of uploaded images.
Then, having written these two numbers down, she can insert a row directly into the album_image.
For visual feedback, she can check the frontend website.
It is true that a view showing the album name and filename would make deleting entries easier, but I would assume that images and albums are added much more frequently than they are deleted.
The ability to edit an associative table in a view that shows linked information, therefore, should not greatly affect your choice of tool. I could suggest tools, and phpMyAdmin is a logical choice, particularly if it is desirable to teach your friend computer skills that are widely applicable. It appears you have already identified some executable tools.
I imagine that you could add some additional hidden frontend views that could make your friend's workflow easier, such as a list of images and IDs that aren't in albums, a list of album IDs, or a view that shows the IDs. I do recommend you consider extending the frontend with a simple login and Edit options using your CRUD library, rather than devising a separate backend GUI.
I appreciate this is not an answer to the exact question, but it does resolve your problem.
I'm not sure if this will be helpful or not. I was hoping to find a UI with some eye candy/styling, but while searching I stumbled upon this:
https://blogs.oracle.com/MySqlOnWindows/entry/introducing_mysql_for_excel
As part of the new product initiatives of the MySQL on Windows group we released a tool that makes the task of getting data in and out of a MySQL Database very friendly and intuitive, and we paired it with one of the preferred applications for data analysis and manipulation in Windows platforms, MS Excel.
Like I said, not sure if it will help. I'm in a similar situation - low-tech, low budget client. The difference is my weakness in MySQL, but for me I just need a single table, so I think this will work.
There is no tool that will allow you delete such values from such a view, not for mysql, since For a multiple-table updatable view ... DELETE is not supported, see Updatable and Insertable Views
I guess you are looking for the equivelent of the Python based Django admin system which practically builds itself from analysis of the data structure.
Frameworks like Symfony, Cake and Yii have some of this built in, however I'm guessing that your database architecture may not be compatable as these types of systems normally require you to stick to strict naming conventions, but it's certainly worth taking a look.
Playful,
I already posted one answer, but this one is different enough to merit a seperate response, IMO.
Since you are looking for a simple, client-friendly solution, may I suggest Adminer?
http://www.adminer.org/en/?
Specifically, I used the Wordpress plugin here on a site recently:
http://wordpress.org/extend/plugins/adminer/
It provides pretty much full phpMyAdmin funcitonality. Very easy for the client, and if they want to, they can export the database as .csv and edit in excel, then re-upload. Just about everyone is familiar with editing in Excel, and they can make backups regularly.
Hope this helps!
J
You can very quickly and easily make a front-end for this type of use with Xataface. I find it very quick and useful. I would be happy to help you get going with it.
www.xataface.com

In a web application, what's the best way to store custom user data

We have a web application that we're refactoring. We want to make an environment per version with different users (companies) that share the same codebase.
It know this is a somewhat simple question but I just want to make sure we make the right decision (according to webapp best practice).
Say companya.webapp.com points to /1.00/public
and companyb.webapp.com points to /1.30/public
I'm wondering what the best way is to store custom data from these users. Custom data could be uploaded documents, photos and also generated static data like PDF documents/invoices.
When I migrate a user to a different version I want his data to be available in the other version too. The documents also have a record in the database with the path description.
Would it be OK to do something like this structure:
/data/[companyname]/pictures
/data/[companyname]/documents
/data/[companyname]/documents/pdf
/data/[companyname]/documents/csv
/1.00/public
Sure, use whatever structure you like. There's no real "correct" answer, and it's very hard to do it wrong. Just make sure the permissions are properly set, so that each company can't read each other's files.

Are there any PHP Frameworks (e.g. CodeIgniter) that support database connections on a per user account basis for use in a Multi-tenant database?

I'm looking into developing a multi-tenant SaaS application, and I found several sites that describe a solid way to separate the data using tenantIDs and updateable views. e.g. This blog post
It all hinges on the ability to have your user accounts authenticated from a master users table and then having their respective database connections use those user-specific credentials. This way, the views can pull the userid and map it to the tenantID to display that user's view. However, most PHP frameworks tend to be very static when it comes to database connections (stored in text config files). They appear to be at odds.
Does anyone know:
a) how to make CodeIgniter handle this gracefully?
b) a different PHP framework that might?
At a horrendously basic level you can do this:
http://philsturgeon.co.uk/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up
Expand it as required, or move the logic into MY_Controller for more flexibility.
There is a topic talking about this on the Code Igniter forums.
http://codeigniter.com/forums/viewthread/165227/#846845
It looks like you set up your users DB as your main database in the config file, then you generate a config array for a new connection for a user based upon information in that users DB. So, I guess you'd need to at least store the DB name in the users database.
Not sure how well this works though, as I haven't had an occasion to try it out yet.
Sorry if that's not quite what you were looking for, but it should give you an idea of a Code Igniter approach.
Zend Framework.
http://framework.zend.com/manual/en/learning.multiuser.intro.html

Making A Website With Profiles

I am working on a social network, and I am doing it with php and mysql, I need to know how to make users have customizable profiles...
Like editing status, ect...
Also making it so only friends can veiw their profile..
Also how do I add a user's page/directory to the website directory(example: domainname.com/someonesprofile)
Thank You
-Techy
That's a pretty generic question, but I'll give it a whirl.
First of all, you need to determine what a profile should contain and so forth, such as status, relationships, name, addresses, .... The list goes on. You then need to write an interface to a service that provides this information; this can be a PHP function, a class, whatever, really.
Second, you need to access this interface from within your web application. A suitable course of action is probably to have a function that assures that whoever is trying to access the information is logged in, is in the relevant authorization group (friends list), and so on.
The editing part is done quite simply through an HTML form or similar; there's no magick[sic] involved. The function to parse this form would again assure that the logged in user has the appropriate rights to edit the profile (e.g. is the same user or a trustee of some kind, parent, lover, who knows...)
As for the last bit; here mod_rewrite is your friend. You probably would want to have URLs along the line of http://example.org/profile/username , which the server would translate to /?action=profile&user=username, or something to that effect.
The file /profile/username would as such not exist on the server file system in any real sense, but seem to be a completely normal HTML file when viewed from the outside.
You must start with the database. You will need a table for Person, obviously. You will need a table that joins Person to Person many-to-many, for viewing privileges. You will need a table for levels of authorization. And you will need other tables that serve up what privileges go where.
The interface is secondary. Some developers would use something simpler than PHP to develop the UI functions that rely on these database resources.
I know that there are very nice frameworks available which handle the whole profile/login/friends functionality. Pinax for Django springs to mind. Ime quite sure similar things are available in PHP but unfortunatiely I know very little about the PHP community, so I don't have a link.

Categories