Community

Integrating the functionality of my old site into drupal

Hi all,

I'm brand new to drupal this week, so please forgive me if I get nomenclature wrong etc.

on my old, insecure, hand-built php website, I had a custom application, which allowed for the getting, setting, and access of data from a database, using dbconnect.php and a myriad of input forms and ultimately reports for displaying the outcomes.

The data I am now going to use is similar. I need to be able to record user input in a seperate databse:
-Time and Date
-Section
-Throughput
-Number of Staff
-Work On Hand
-Work Failed

Then using this data, I will need to have an output script, which basically allows the supervisor to select what day he wants to view, what time range, and he can see a run-down of each hourly report (each instance of the above data being entered) within that time frame.

My initial thought was "great, I can put all my PHP code into Basic Page types and it will all work as it did before" - but that, I now know, is wrong. For a start, include_once() is blocked out by drupal (for security reasons?)

How would you recommend going about doing this? Is there a module which will do this?

Thanks in advance for your advice.

Martin

Comments

The Drupal way

Well, you could pull the data in from a separate database.

Or you could do it the Drupal way. That would be to create a new content type (alongside "basic page"), which is going to hold one node for each entry in your database. You'd then add a date-type field for the time and date, a text (?) field for the section, perhaps a numeric field for the throughput (I don't know what "throughput" refers to) and so on.

You would then install two contributed modules - ctools and views. Views needs ctools, but it's views you'd use. That module would take you a little while to learn your way around, so allow some time to fiddle and experiment, but with practice you'll find it's very powerful. At the very least, it would allow you to produce the kinds of reports you mention, and it would create filters for the supervisors to filter and aggregate the data.

To do it in a separate database, you'd need to use the Drupal function db_query(). Provided your MySQL user has permissions to read the database that holds this data, you'd be able to run a query with $result=db_query("select * from databasename.tablename GROUP BY foo ORDER BY bar;") and then iterate over $result.

Sticking with the Drupal Way

I'm very keen to stick with the drupal way, so...

If i'm reading you correctly, I need to create a content type. However, this is where I get confused because I don't want the user to have to click "add content" every time they want to report their hourly figures, I would like one node which contains a form, and when that form is completed by the user, the data is stored.

When i'm trying to add this kind of functionality now, i'm finding that the content type is all good, but when I add fields into the content type, I must make a post every time i want to add information to it, which is not quite what i'm after.

generally, I want the whole website to be as static as possible, only with the equivalent of a basic page containing a form, which for instance, allows Joe Bloggs, who is the manager for XYZ section, to input that he had 32 staff this hour, and his throughput was 200 widgets. this info should not show up as a published post, but should be recorded in the database so that, with Views, i can pull this info out.

Or am i over-complicating my understanding?

Getting there

I'm getting there at understanding you.

/node/all/hourly-data would be such a form for a manager to enter his data.

What exactly is it about doing it that way that isn't what you're after. Yes, when he hits "submit" it creates a node, but that never needs to bother the manager in question.

One thing to make sure of is that the node is not "published to front page". By default, the front page of a Drupal website is set to be the teaser view of all recently created nodes, in date order. You can exclude nodes from that by not ticking the "publish to front page" box. You can tweak the content type so that this box is not ticked by default. The other thing you can do is manually set the front page to be some other static node you've set up, so that the front page of the site is no longer a blog-style listing of recent nodes.

If you did all of that, the process of creating a node would be pretty much indistinguishable from completing any other form.

Or, at least, if it's still not quite what you're after, please explain exactly how, and I (or someone else) will try and help further.

getting there

Hi James, and thanks for your continued patience.

What I meant to say above is that I don't like the way you get all the drupal bells and whistles when creating a post - at least, not for the very dim-witted managers we have working in our factory.

is there a way that I can build a form into a basic page that creates a node when you click the submit button?

The only way I can think of comparing it is to a contact form - imagine you wanted to store the contact details in a content type, but you only wanted them to click the menu link for 'contact us' and fill in the boxes and click submit, instead of going through the 'Add Content' screen?

martin

Webform?

Two ways to get there:

1. Give your supervisors a "role" on the site that only lets them post to those node types, and doesn't let them do things like change the URLs for pages, etc., and the node addition page will get much simpler for them when they're logged in. Options / vertical tabs that don't apply to them don't even appear. You can also tweak the admin theme so that the normal theme for your site is used for node addition / editing, as opposed to your custom theme. That will make the page they use look more like the "normal" look of the site.

2. You could look at the Webform module. It may do what you want. Read the documentation, where it explicitly says that Webform doesn't create nodes and therefore doesn't integrate with Views. What you can do, though, is export the results of the Webform input on a periodic basis, then import that data as a bulk operation so that it creates the nodes. That would be a job for you, or another administrator, but the shift supervisors would be presented with a much simpler form.

One more thought

Hi Benaal

One more thought on this: You can write PHP to create a node and populate it with the various fields. But if you did that, you'd have to handle validation. You couldn't have the anonymous user with permission to create nodes - you'd get spammed something crazy. So you'd have to have your supervisors log in, and give them a role to create nodes of the relevant type. You'd also have to ensure that the form you design for doing this is also only visible to people who have that role, which requires using some form of access control module.

Actually writing that PHP isn't too hard, but it is something you might consider offering bounty for over at http://drupal.org/paid-services - if you're new to Drupal, and you wanted to go this route, it's up to you whether you wanted the learning curve before you could get this running.