Is there a way to call a function from my module that is located in another module? I thought that I read somewhere you can do this, but I can't seem to find where that is done. I am trying to call a function from ubercart.
Saturday, February 28, 2009
PHP If Statment Fundamentals short form shorthand
by Bret I’ve been doing a lot of work over the past year with PHP, and have been loving this language for dynamic web page development. I program in a couple of other languages so I have a few personal preferences for how I write code regardless of the language. Therefore, I often write standard if statements in PHP the same way I do in other languages; however, there are at least two other ways to write a PHP if statement that I often forget (old habits die hard) and am writing today’s post a quick “cheat sheet” type of reference for myself, and anyone else that needs a quick reminder of the available PHP if statement styles.
Please Note: All examples begin and end with the standard PHP preprocessing instructions: <?php and ?> However, in order to avoid these examples from appearing to the server as executable PHP code, I’ve intentionally inserted a space in these preprocessing instructions. In other words, “I meant to do that.”
The standard PHP if statement
PHP if statements work the same way as nearly all other programming languages: A conditional statement is evaluated and then additional code is, or is not, executed depending on the results of the conditional test:
< ?php
$number = 15;
if ($number > 10) {
echo "The number tested is greater than 10";
}
? >
No else section is necessary; however, if you need an else section, the format looks as follows:
< ?php
$number = 5;
if ($number > 10) {
echo "The number tested is greater than 10.";
} else {
echo "The number tested is less than 10.";
}
? >
Please note, while an if condition followed by a single line of then execution requires no curly brackets, I have shown my examples with curly brackets for readability and I believe it’s good programming practice.
If you need to extend your if statement but not by enough to justify using a switch statement, or a switch statement simply won’t work for a given situation, then add an elseif section:
< ?php
$number = 15;
if ($number > 10) {
echo "The number tested is greater than 10.";
} elseif ($number > 5) {
echo "The number tested is greater than 5 but less than 10.";
} else {
echo "The number tested is less than 5.";
}
? >
The abbreviated PHP if statement
The short form of the standard if statement drops the common if, else, and curly brackets to construct a condensed conditional statement that fits nicely on one line. The question mark character “?” separates the conditional section from the then section and then the colon character “:” separates the then and else sections. I often use this form in the header of some html documents that might be expecting a GET or POST values or when I’m checking for, and assigning, SESSION variables.
< ?php $username = (!empty($_SESSION['username']) ? $_SESSION['username'] : “”); ? >
I find using the abbreviated form to quickly test and set variables extremely valuable.
The extended PHP if statement
If you’ve ever examined the inner workings of a complex dynamic PHP and MySQL driven web page, then you’ve probably seen this extended form. This form allows you to contain the conditional, then, and else sections between their own preprocessor statements. The benefit is realized when you want to display a large chunk of html code for a then section and perhaps and equally large chunk for the else section. Normally, if you couldn’t “extend” the if statement in this manner, you’d have to write an awful lot of echo statements.
< ?php if ($number > 10): ?>
< table>
< tr>
< td>100< /td>< td>200< /td>< td> ...etc, etc < /td>
< /tr>
< /table>
< ?php else: ?>
< table>
< tr>
< td>10< /td>< td>20< /td>< td> ...etc, etc< /td>
< /tr>
< /table>
< ?php endif; ?>
To use this form, end the conditional statement with a colon “:” and enclose the statement in the standard preprocessor opening and closing tags. Write whatever chunk of html code you want to appear if the conditional criteria is met. Add an else section using the same format as the conditional statement section. Finally, end the entire if statement with an endif followed by a semi-colon and enclose it (same as the other sections) in the standard preprocessor opening and closing tags.
Keep in mind, it’s easy to get lost in an extended if statement because there is often a lot of code between the various sections; however, this form of the if statement can save a lot of typing because you won’t need to precede ever line you want printed with echo.
When to use each type of PHP if statement formats
There is no hard and fast rule about when to use each if format; however, for what it’s worth, here are my personal recommendations:
Standard: Use when there are only a couple of lines of code that follow a then or else section.
Abbreviated: Use when you want to assign a value to a variable based on a conditional statement and only have one line per then or else section.
Extended: Use when you have a significant amount of html code to display for each then and else sections. Be aware that it’s easy to get lost trying to following this format.
Friday, February 27, 2009
Upcoming event calendar using date, views and cck
Post installation · Drupal 6.xfhsm - October 25, 2008 - 17:16
I’m trying to use a combination of date, calendar, views, and cck to make a calendar of upcoming events and I’m not having much luck. The basic problem is that my calendar view is sorting based on the changed field in the node table, not on the date and time set for my events.
I'm going to make this detailed so thanks so much in advance for your help!
To get to this point I:
I used CCK to make a new content type event to which I added one additional field event_datetime of type datetime using the text field custom input format as Mo/Da/Year – TimeAM/PM (ex: 10/25/2008 – 11:45am).
Then in views I cloned the default calendar view. I used filter to set Node: Type = Events to remove non-events from my calendar and Content: Event Date and Time (field_event_datetime value) asc to hopefully sort get events to show up on the correct days. I will include a full copy of my calendar view's 'default' settings pain at the end of the post.
This isn't working. Instead I’m getting a great calendar view that shows all of my events nodes on the date the event is created / updated (today) not the date set for the event to occur in the event creation process (some time in the future).
The MySQL table content_type_event shows the values I set when creating my events as field_event_datetime_value and field_event_datetime_value2. Manually editing the created feild and changed feild in the nodes table moves them on the calendar view. In sum it appears my calendar is sorting based on node creation and not event datetime.
Bottom Line: Can someone please tell me how in the world I make views sort based on the correct field?
Views keeps coughing up a huge SQL query that looks like it would be helpful to someone with more knowledge, so here that is:
SELECT node.nid AS nid,
node.changed AS node_changed,
node.title AS node_title,
node_data_field_event_datetime.field_event_datetime_value AS node_data_field_event_datetime_field_event_datetime_value,
node.type AS node_type
FROM node node
LEFT JOIN content_type_event node_data_field_event_datetime ON node.vid = node_data_field_event_datetime.vid
WHERE ((node.status <> 0) AND (node.type in ('event')))
AND ((ADDTIME(FROM_UNIXTIME(node.changed), SEC_TO_TIME(-14400)) <= '2008-10-31 23:59:59' AND ADDTIME(FROM_UNIXTIME(node.changed), SEC_TO_TIME(-14400)) >= '2008-10-01 00:00:00'))
ORDER BY node_data_field_event_datetime_field_event_datetime_value ASC
I tried just blindly dropping that into phpMyAdmin and got back reasonable results:
nid node_changed node_title node_data_field_event_datetime_field_event_datetime_value node_type
7 1224949001 Test Event 1 2008-11-04 11:36:41 event
8 1224949115 Event Test 2 2008-11-25 11:38:35 event
This just makes me think that I'm not smart enough to figure views out because it is clearly getting the right info out of MySQL it's just sorting on the wrong column.
Settings from my testcalendar view's default settings tab:
View settings
Tag: Calendar
Basic settings
Name: Defaults
Title: None
Style: Calendar navigation
Use AJAX: No
Use pager: No
Items to display: Unlimited
More link: No
Distinct: No
Access: Unrestricted
Link display: Calendar page
Exposed form in block: No
Header: None
Footer: None
Empty text: None
Theme: Information
Relationships:
None defined
Arguments:
Date: Date (node.changed)
Fields:
Node: Title Title
Sort criteria:
Content: Event Date and Time (field_event_datetime value) asc
Filters:
Node: Published True
Node: Type = Events
» Login or register to post comments
Arguments are the solution!
fhsm - October 25, 2008 - 19:43
I was able to solve my problem after a bit of time digging around in the source and blindly slamming on the UI. The problem was the Arguments section of the views setup.
Arguments:
Date: Date (node.changed)
Should be switched to
Content: Event Date and Time (field_event_datetime value) (or whatever else you want to sort using.
This was super frustrating. I did a lot of googleing and didn't really turn up anything that got me where I needed to go.
http://support.bryght.com/node/569 and http://drupal.org/node/133341 were somewhat helpful but left out a key detail.
I'd like to write up a bit of documentation for the next newbie with the same problem. Where should I put such a writeup? Here in the forum or elsewhere on drupal.org?
Login or register to post commentsHow to make a calendar of upcoming events
fhsm - October 25, 2008 - 21:15
I recently setup an upcoming event calendar on Drupal 6.x. I had a hard time finding instructions so here's my experience...
I did not use the event module because a version for 6.x isn’t out yet; however, there are other reasons not to do so discussed in the forums.
Instead I used:
CCK
Views
Calendar
Date
Download and install the above modules to /sites/all/modules and enable them at Administer › Site building > Modules
Step 1: make a custom ‘event’ content type using CCK
Go to Administer › Content management › Content types > add content type
Name = “Group Event”
Type = “event”
Description = “Create a new event to appear on the sites calendar of upcoming events”
The following settings are largely a matter of site needs and personal preference:
Under “Submission form settings”
Title = “Event”
Body = “Details”
Under “Work flow settings”
Decide to best fit your site. It is worth considering unchecking “Promoted to front page” if you expect to have numerous small events posted.
Under “Comment settings”
Make decisions which are appropriate for your site.
Save your new event content type.
From the content type screen (Administer › Content management) select manage fields next to your new content type.
Add a new field
Label = “Event Date and Time”
Field name = “event_datetime”
Type = “Datetime”
Widget type = “text field with custom input format”
There is some debate over the correct type to select here.
The widget type dictates the input UI and is really a matter of preference. It’s easy to change after the fact so try them all and see what you like best.
Save your newly created event date/time field.
The field options on the following page are reasonably self explanatory and a matter of taste.
Pay attention to the “To Date” option as it will allow you to set the end of your event (more important if you want an iCal feed ultimately).
For most people
Granularity = year, month, day, hour, minute (not second) selected
To Date = optional will be correct
You can of course add any number of additional fields to your event content type at this point using CCK. I've added location and contact information for my application and tied those to weather and profiles which is kind of cool (but way beyond this little write up) and testament to how amazing Drupal really is.
Step 2: Create your first event
Create content > Group Event
Fill out the form for your event and save it.
Step 3: Configure your calendar view
Administer > Site building > Views
This is where the hurt started for me 6 hours ago...
Enable the Default Node view: calendar (Calendar)
Clone the default view
View name = “calendar”
View description = “Calendar of group events”
Nextshould take you to the views edit screen
Down the right side you'll see all the different types of calendar (page, block etc) just work with the default view to start (it should be where you are by default).
In the Arguments panel
Click Date: Date (node.changed)
Near the bottom of the page under Date field(s):
uncheck = Node: Update date
check Content: Event Date and Time (field_event_datetime value)
Click Update
This set the start time of your event instead of the node update time as the argument for the view.
On the Filters panel click the “+” logo to add a new filter
Check = Node: Type
Click add
On the following screen
Leave operator = “Is one of” and check = Events to limit your calendar to only the event content type.
Click Update
On the Sort criteria click the “+” to add a new criteria
Check = Content: Event Date and Time (field_event_datetime value)
click Add
Save it all by clicking Save
Step 4: make sure it works
Use the View "Calendar page link to confirm your new calendar is up and working.
That will at least get you to a working calendar of coming events for your site. Obviously you’ve got a ton of configuration options to play with form here.
This is a very powerful package. While it's not hard to setup it's got a lot of steps and many opportunities to go wrong. The key here is to set the argument / sort / filter bit of views configuration. This combination of modules seems to want to create a calendar widget for digging into the archives by default but it is easy enough to have it do otherwise.
Hope this is helpful for someone down the road.
Login or register to post comments
wow--- excellent writeup.
WorldFallz - October 25, 2008 - 21:18
wow--- excellent writeup. you should definitely make this a handbook page for the calendar/date modules.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Login or register to post commentsMulti-Day Events & Timezones
Daniel Berman - October 27, 2008 - 17:06
Thanks for the writeup fhsm! Two questions.
- Any ideas as to how the procedure changes for handling multi-day events, especially in terms of displaying properly within the calendar view?
- For an international audience, whats the best way to handle a timezone field?
The reason I am asking is because, I am trying to set up an international events calendar, on my site, www.issacharnetwork.org/calendar. I need people to be able to enter the local time of their event, but have the time properly converted for others who may be joining the event electronically from different timezones.
My inituition, would be that I would need the event's location, the user's location, and the internal server time to anchor the calculations. So then, if the event location could be picked up by the location module. I would just need the other two data points, and then run it through views properly. Am I heading in the right direction, or right off a cliff?
Login or register to post comments
partial answer here
Daniel Berman - October 27, 2008 - 17:24
--> http://drupal.org/node/114282#comment-971331
Login or register to post comments
This was very helpful for
knaa - October 28, 2008 - 15:32
This was very helpful for me, particularly the part about setting the start time of an event in the calendar, instead of the update time. I wonder why the module maintainer have it set to the update time by default. I guess everyone has different uses for a calendar. Like you, I use it primarily for upcoming events.
Thank you for the excellent write-up. I agree this write-up should become part of the Calendar handbook.
Login or register to post commentshappy coincidence
justageek - October 28, 2008 - 21:20
Here are a couple of ways to use the repeating-date api with the event calendar as described in your post, note, you will have to choose the one that fits based on caveats listed.
When created your event_date_time field, choose the option to automatically include a 'To' field. Drupal will add a second field, so you can enter a From and To date. Also, when adding your field using CCK, for the Widget Type, make sure you choose one that includes "repeat options. This allows you to indicate how your event repeats, there are many, many great ways to repeat dates
Caveats with this method - If you create a date that starts on 10/28/2008 at 3:00PM and the To date is 10/31/2008 at 4:00PM, the calendar view will basically show the date 10/30/2008 instance of your event as All Day. In other words, Drupal assumes that your date starts at 3:00 PM on 10/28 and ends on 10/31 at 4:00PM. So, if you are wanting to show, say, a training class that goes from 1:00 PM to 3:00 PM each day, this will not work properly.
So, to create an event like this training class, you should create a single event that starts on 10/28/2008 at 1:00 PM and ends on 10/28/2008 at 3:00PM, then use the "repeat" feature to repeat the event until Nov 1. You need it to repeat until Nov 1, because apparently the end date for your repeat is not included, so it causes your class to show on 10/28,10/29, 10/30, and 10/31. NOTE: the start and end times only show on day 1, which would be the 28th.
So, you need to figure the following before you do your work:
Do I need to use the repeat function to repeat single days within an event, where the days have their own start and end time, or do I need to repeat events throughout the years, such as monthly meetings or something like that.
The cool thing is, there are a bunch of ways to do all this stuff, you could create separate start and end time fields and make your event date field the date portion only, this would give you more flexibility.
I hope this helps someone, my experiments have really enlightened me.
UPDATE:
I think that it is much more flexible to store your event start and end times in separate fields. You can create multi-day events that also repeat throughout the year this way.
Login or register to post comments
and another approach without using repeat, when node is same
zilla - October 31, 2008 - 04:46
if node is same and only date changes and does not specifically 'repeat at same time' AND you don't want that big nerdy 'repeat interface' that scares users, you can use cck unlimited on just date element in event custom type, details and write up here: (somebody oughta pull this all into a handbook page!)
http://drupal.org/node/317844#comment-1046675
(question related to a movie theatre with movies (where title/body stays the same) and many 'show times' that may or may not repeat...but need to come up in a view (calendar, block, page, etc) - also quite detailed for a new user...
........................................................................
i love to waste time: http://twitter.com/passingnotes
Login or register to post comments
Thanks for this great
elektro - November 20, 2008 - 19:40
Thanks for this great howto!
I have the same problem when I use date with repeats. My block shows the same events.
I can't use the CCK unlimited setting because I use the jQuery input format and not the "text field with custom input format".
I would need a solution that makes the view distinct by the node id.
Thanks.
Login or register to post comments
Fantastic - thank you!
Sloane DellOrto - October 31, 2008 - 03:58
fhsm - Can't thank you enough for taking the time to write these instructions ... have been too afraid to try this module until now, and thanks to you I have a calendar up and working perfectly! This knocks the socks off of Events in many ways - thank you thank you thank you! And of course a HUGE nod at Earl and everyone else involved with Views. This is just damn cool stuff, even if I don't understand half of it. ;-)
Login or register to post commentsVery helpful...but now I'm stuck
bixwilson - October 31, 2008 - 18:14
fhsm, thank you for putting this guide together. I had installed all those modules and was trying to get my View running, but I wasn't using the default calendar view. You helped me get back on track.
BUT, now that I've followed your instructions and set up the calendar view, the preview is broken....I'm getting a message that says "An error occurred at /acdrupal/admin/build/views/ajax/preview/classes_calendar."
The preview is not working, and the path to the view, /calendar, brings up a blank page.
Do you or anyone else know anything about this ajax error?
Thanks.
Login or register to post comments
might be version issues
justageek - November 3, 2008 - 16:36
I had the blank page suddenly happen, and by turning on php errors, I found that the calendar is calling a missing function in the Date module, the latest dev version of the Date module has it in there. Since these are still actively developed, I think this might happen from time to time. Try upgrading the Date module and see if the blank page issue is fixed.
Login or register to post comments
Just what I needed
danimagoo - November 1, 2008 - 23:18
Thank you so much for this, I was trying to use the Events module and it wouldn't do everything I needed. Views has always intimidated me a bit. Your step-by-step instructions worked perfectly. Thanks!
Login or register to post commentsAdvanced Help
kwgossett - November 3, 2008 - 15:32
fhsm - this is awesome. In addition to the Handbook, see if they will include the code in the Advanced Help module as an example - typically found at example.com/admin/advanced_help/views?popup=1
I'm not sure if you would ask the maintainer of Advanced Help or views (merlinofchaos) or the maintainer of Calendar (KarenS)...still, I'm sure it has a place among their current examples.
Thanks!
kelly
Login or register to post commentsChange date color...
Dr. Rhomboid Go... - November 3, 2008 - 23:28
Love the calendar, and now I want to get fancy. Any thoughts on how to change the background color of a date on the calendar based on the content of a field in the event node?
I'm building a calendar for a sport league and added a field to the event (called event_type) that is a radio button with the options of Home, Away, or Other.
I'd like to make the background of the date change color based on the event_type field (ie. days of home matches would have a blue background or whatever).
Any ideas?
Dashingly,
Dr. Rhomboid Goatcabin
Login or register to post comments
Hi There
richard.e.morton - February 10, 2009 - 22:18
Did you get a reply or discover an answer to this colour issue with calendar? I have found a patch for calendar 5.x but not 6.x and it really would be a cool feature so that it is easier to understand, like the event module.
thanks
Richard
Login or register to post comments
Hey all, is anybody here
yoda-fr - November 17, 2008 - 10:57
Hey all,
is anybody here know if is it possible to hide all the views week, year,.. and to make a direct link to the article from the calendar displayed.
Thanks for your help!
Login or register to post commentsremoving it
kurosevic - November 17, 2008 - 21:24
Hey fhsm,
your tutorial kickstarted my learning of views. thank you very much.
I've started creating variations of what you taught me with your tutorial, and and the calandar clone view you helped me create works well, however now i need to disable it because i have another one doing the same thing.
how do i disable it?
Login or register to post commentsMy Things Show Up Twice
MrBT - November 19, 2008 - 16:18
One problem I'm seeing is when I add something to a date, say today, and that thing happens in 2 months, then that thing shows up both today (where I don't want it) and again in 2 months (where I do want it).
What am I doing wrong?
Login or register to post commentsRSVP?
kurosevic - November 20, 2008 - 02:16
Does anyone know how to extend this event with an RSVP option?
I was thinking of making a custom poll that was selected in VIEWS and then just making it in the format
Q: Attending?
A: Y/N
while inheriting the event date as the time when the poll would close.
HOWEVER, I CANNOT FIND A SINGLE WAY TO MAKE A POLL INTO A CUSTOM NODE. Anyone know how?
Login or register to post comments
Take a look at the SignUp
adamwebb - November 27, 2008 - 17:13
Take a look at the SignUp module.
Login or register to post commentsUse the RSVP module for
ulf1 - January 9, 2009 - 01:43
Use the RSVP module for invitations,
and use the views/calendar to show the events.
~
Ulf
Login or register to post comments
Hours of the Day
mediamob - November 20, 2008 - 20:54
This is a really great write up that saved me hours upon hours of fiddling around with these calendar view arguments and what not I'm sure. Thanks fhsm for sharing this with the community.
The thing I'd really like to get out of this tool is for the calendar to display in week and day view with the hours of the day laid out. So, for example when something is happening from 12:00 - 15:00 you can see the rest of the day is open. This would be the final punch as far as I'm concerned to making this thing viable for a long list of solutions. Has anybody got it to do that yet?
Login or register to post commentsCalendar Day View Weirdness
ortizmj12 - November 24, 2008 - 03:19
First off, great write-up, fhsm! Very easy instructions to follow and work like a charm. I've just got one problem...
I've created a test event to make sure it was all working. I've noticed that when I bring up my calendar in a day view to look at my test event, the enlarged time in the left column does not match the start time for the event. Reference the link to see what I mean:
http://i36.tinypic.com/zo86yc.jpg
Anybody know how to fix this? Thanks in advance! :)
Login or register to post commentsDidn't work for me
atuline - November 27, 2008 - 17:05
This was a well written tutorial and I was doing great with a fresh/latest install of D6 (with 2.0 rc5 of date and calendar modules and CCK 2.1 and pathauto). I created an event content type and an article of that content type.
The problem started with the arguments panel in step 3.
The tutorial says:
In the Arguments panel
Click Date: Date (node.changed)
Near the bottom of the page under Date field(s):
uncheck = Node: Update date
check Content: Event Date and Time (field_event_datetime value)
I'm sorry, but there was no entry called Content: Event Date and Time (field_event_datetime value), nor any other 'Content' options.
At this point, the tutorial fell apart on me since I had no field to check.
Update: Also tried the latest dev versions of CCK, Date, Calendar, Views with similar results.
Login or register to post comments
Same here
layoric - December 1, 2008 - 21:35
Also didn't have the field_event_datetime value options listed. What gives?
Login or register to post comments
Did you make sure to create
ortizmj12 - December 11, 2008 - 03:48
Did you make sure to create the new field after you created the new content type? Only thing that comes to mind right now...
Login or register to post comments
Yes, the field was missing.
atuline - December 19, 2008 - 17:28
One important item missing from the original article was to add the Field to your Calendar View. So, prior to adding the argument as outlined in Step 3, you need to add the Field. So, while editing the new Calendar View I went to the 'Fields' selector and:
Click Add and select the following:
Content: Event Date and Time (field_event_datetime value) Default
Once I did that, the argument will now work as described.
Login or register to post comments
How to make a calendar of upcoming events
brecko - December 1, 2008 - 21:42
I followed all the steps. The Calendar itself works great.
However, when I click on the date of the event that was created in step 2, the calendar page for the day of the event comes up but it is empty.
Shouldn't the text of the event I created appear here? What am I missing?
breck@astorholdings.com
Login or register to post comments
What does your fields
ortizmj12 - December 11, 2008 - 03:50
What does your fields section look like for that calendar view?
Login or register to post comments
Awesome!
dennots - December 3, 2008 - 20:55
Thanks for the excellent guide. It really showed me how to use the Calendar / Views.
This should definitely be added to the module help.
Login or register to post commentsSome Problems for my Calendar
hujia - December 7, 2008 - 02:29
Hello there,
Thanks for your excellent and detailed write-up! It serves for me both as a tutorial/learning documents and also very pragmatic instruction. I followed your instruction as given above carefully and closely to the letter for twice. I think i have succeeded in setting the Calendar in working nexus with the Event content and View correctly, with only one exception:
1) all the events I entered, like 12-26 and 12-25 (following the format given) all fell on the same day 12-06-2008 which is today as i type, regardless the FROM and TO times that I created for the Events. I checked the mysql, there are correct, in format of 2008-12-25 00:00:00.
2) The Events' titles show up correctly on the Calendar (though again on the wrong date). But, when I clicked on any of the events, which erroneously fall on 12-06, there is no description or detail which I typed. I am not sure if this is because the dates are wrong for Calendar in the first place? I tested the sql query for Views for these times, and they resulted in the correct times. but in Calendar, there are incorrect.
I am sure where goes wrong? Appreciate if you could help!
thanks in advance, hujia
Login or register to post comments
Please help with this Calendar of Mine ...
hujia - December 8, 2008 - 04:16
For the problems I reported here I found that the events are all located on the calendar according to their POST DATE, not FROM and TO dates. I check the setting for View and the event content type I created, as well as data for event, esp. FROM and TO, and cannot detect obvious wrong place... So if you could help me with this.
UPDATE: Hello, I would like to append this piece of information that may help for the user like me. What I found is there is a lacuna, or a missing step, maybe an important one at least for me, for the nice write up for setting the calendar up. It is the "Fields" configuration. Here is what I found as a necessary step to make the Calendar work: You need also, in addition to all the instructions given, to do the following forthe "Fields":
1. Click Add ... for Fields, and select the following:
Content: Event Date and Time (field_event_datetime value) Default
Content: Event Date and Time (field_event_datetime value2) Default
2. Delete (remove) the default item "Node: Published"
That would solve the problem I encountered. Hope that may help for somebody.
Best hujia
Login or register to post commentsSame problem as hujia but slightly different workaround
penteri - January 28, 2009 - 12:51
I've got the same problem as you: all my events' starting time fell on the current moment I was watching them. For example: an event's starting time is 2008-01-29 00:00:00 and ending time is 2008-01-29 01:00:00. If I check out the calendar for that event there is for the starting time current moment 2008-01-28 14:36:00. Ending time is however correct 2008-01-29 01:00:00.
My solution: In Calendar view's Fields-panel there were
1. Content: Event Date and Time (field_event_datetime value) Default
2. Content: Event Date and Time (field_event_datetime value2) Default.
I remove the first one
Content: Event Date and Time (field_event_datetime value)
When I check out the calendar for that event starting and ending time are correct
2008-01-29 00:00:00 - 2008-01-29 01:00:00
Login or register to post comments
I get to step 3 "Enable the
poobah - December 12, 2008 - 19:26
I get to step 3
"Enable the Default Node view: calendar (Calendar)
Clone the default view"
I don't see that as an option, mine goes from
Default Node view: backlinks (default) Enable
Path: node/%/backlinks
Block, Page
Displays a list of nodes that link to the node, using the search backlinks table.
to
Default Comment view: comments_recent (default) Enable
Title: Recent comments
Path: comments/recent
Block, Page
Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.
Login or register to post comments
Did you enable the
ortizmj12 - December 14, 2008 - 02:17
Did you enable the "calendar" module?
Login or register to post comments
Error Message on Step 2
bobwhitleyjr - December 30, 2008 - 16:29
When I go to create the content on Step 2 I get the following error.
warning: Missing argument 3 for content_permissions_field_access() in /home/whoyou/public_html/cms/sites/all/modules/cck/modules/content_permissions/content_permissions.module on line 21.
Did I miss something on the cck install/Setup?
Thanks for any help.
Login or register to post commentsThanks a ton!
ternto333 - January 7, 2009 - 22:13
You saved my bacon
Login or register to post comments...
seanmalley - January 27, 2009 - 16:50
This method worked perfectly for me, thanks for the well written instructions! I do have one question though...when I was entering a test date into the calendar, it appeared like the time was showing up incorrectly in the calendar view for me, but showed correctly when clicking on it. After some messing around with it, I figured out it was just displaying the time I "created" the actual event on the calendar, not the time of the event. Is there any way to remove this, or at least have it show the event's actual time on the calendar instead?
Login or register to post comments
error after adding "sort" criteria
cdragin - October 28, 2008 - 20:19
I followed the instructions but get this error after adding the sort criteria:
user warning: Unknown column 'node_data_field_datetime_field_datetime_value' in 'order clause' query: SELECT node.type AS node_type FROM node node LEFT JOIN content_type_event node_data_field_datetime ON node.vid = node_data_field_datetime.vid LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid WHERE 0 ORDER BY node_data_field_datetime_field_datetime_value ASC in /home/icatri/public_html/drupal/sites/all/modules/views/includes/view.inc on line 727.
Seems to work without adding any sort criteria, so I will remove it and hope for the best.
Login or register to post commentserror after adding "sort" criteria
cdragin - October 28, 2008 - 20:20
oops, sorry for the duplicate entry
Login or register to post commentsdates are off-kilter
Dr. Rhomboid Go... - November 2, 2008 - 00:50
Tremendous write-up -- I would've been flailing in vain for hours, however I ran into a problem. When finished, my calendar shows the week running from Monday thru Sunday (any way toi change to Sun thru Sat -- I couldn't find anything for this, but I'm new to this module).
Also, it shows that Nov 1, 2008 is Sunday (when its really Saturday all dates are offset by +1), and the pink highlighted box indicating today (I think), is on Nov 2, 2008 (when its really Nov 1, 2008).
How I can fix...?
Dashingly,
Dr. Rhomboid Goatcabin
Login or register to post comments
Fixed...
Dr. Rhomboid Go... - November 2, 2008 - 14:35
If anyone out there sees the same thing, all I did to fix was wander into Administer>>Site Configuration>>Date and Time. I had set all this originally, and when I went there, I didn't change anything, just apparently had to open and save again.
Again, kudos to fhsm, brilliant write-up -- thanks for letting everyone benefit from your experience.
Dashingly,
Dr. Rhomboid Goatcabin
Login or register to post comments
example upcoming events block
dugh - November 3, 2008 - 03:00
If you want to just show upcoming events, remember to filter by event dates >= now
I created an upcoming events block using date/calendar/views2, see:
http://itls.usu.edu/calendar/upcoming
http://itls.usu.edu/ (block on right)
http://itls.usu.edu/calendar (regular calendar view)
The one extra thing I did was give each group their own calendar, and let people filter the calendar view by group. To do this I had to hack og, the simple patch wasn't understood by the og maintainer:
http://drupal.org/node/279942#comment-913175
Login or register to post comments
Great example!
justageek - November 3, 2008 - 14:39
Your site / example is great. My calendar view uses the dhtml / ajax popups when you click and event, and I can't quickly figure out how to turn that off.
Good stuff, though.
Login or register to post comments
off w/ popup dates
Dr. Rhomboid Go... - November 3, 2008 - 23:22
I'm no expert, but I think I know the answer, on your Module page, under the 'Date/Time' twistie, disable 'Calendar Popup'. That's how I did it at least.
Dashingly,
Dr. Rhomboid Goatcabin
Login or register to post comments
@dugh - any interest in walking through those OG tabs!? (offtopi
zilla - November 4, 2008 - 03:14
sorry, not meaning to hijack this issue BUT i am trying to do exactly what you're doing with those tabs on your groub home pages - is that via a module? could this also be done with tabs in views? i'm still having trouble with both....
thanks in advance for any insights ;)
........................................................................
i love to waste time: http://twitter.com/passingnotes
Login or register to post comments
yeah use views and arguments
dugh - November 6, 2008 - 21:13
Yeah use the special $group argument like so:
Check provide page view.
Set the url of the page view:
node/$group/calendar
Under the 'menu' section check
'Provide Menu'
and
'Provide Menu as Tab'
(or at least the 2nd one?)
Set the menu title ('Calendar') and so forth.
In the arguments section, make the first argument:
OG: Group nid(s)
I am using drupal 5 on that site, I haven't tested group tabs in drupal 6 yet. I hope they still work.
Login or register to post comments
@dugh
vjordan - November 6, 2008 - 15:15
dugh - you have a very clean looking theme there. Well done.
Can you explain how you did the upcoming events listing? Is it a single block view used in both the right sidebar and on calendar/upcoming? Did you base the view on a cloned calendar view or did you craft the view from scratch? If the former, could you explain how you eliminated the calendar navigation information - through theme changes or view configuration?
If you crafted from scratch, how did you configure it so that repeat events are shown with the correct date? I've tried this approach and can't get repeat events to list against the repeat dates - I only seem to get the date of the first event.
Login or register to post comments
info
dugh - November 6, 2008 - 21:17
The upcoming block and page is a new view.
The block is a table view with these fields:
Node:Title
and Date: Date (field_eventdatetime in my case)
I filter by
Node Published = yes
Node: Type = my event node type
Date: Date - Date (field_eventdatetime) is greater than or equal to now (actually 'now-1day' so events don't disappear the instant they start).
And I sort by:
Date: Date (field_eventdatetime) ascending
I'm not sure how to fix the repeat date issue. I would create a new support request for the date module, and KarenS or someone can likely help.
But look through the calendar and date configurations for help too.
Login or register to post comments
Dugh, can you explain how
jeremy_a - November 6, 2008 - 21:37
Dugh, can you explain how you achieved both putting your main calendar at www.site.com/calendar & then Upcoming at www.site.com/calendar/upcoming? I'm trying to replicate this pattern but the main calendar view overrides the upcoming because the view expects site.com/calendar/2008-11 as an argument, not "upcoming"
Cheers
Login or register to post comments
don't know
dugh - November 9, 2008 - 04:44
Sorry, I don't know why it wouldn't be working for you.
A few things (just grasping at straws):
-My argument looks like /calendar/2008/11 not /calendar/2008-11
Don't know if that makes a difference.
-Maybe the order of the views or the order of the URL aliases (/admin/build/path) has some effect, I don't know.
-Also, I am using global redirect, which forces one alias per page/node/view.
Login or register to post comments
I see
vjordan - November 7, 2008 - 11:05
Thanks for the details dugh. I see ITLS is built on D5. I'm tackling this problem on D6, views2 and it works somewhat differently.
In the meantime I've discovered KarenS has done some work here (http://drupal.org/node/290365#comment-1064092). I've downloaded the dev version which includes a default "upcoming" block. Not helping a lot (yet) as I'm getting WSOD but hopefully I'll be able to troubleshoot that.
Login or register to post comments
can someone provide a
bjraines - December 31, 2008 - 00:09
can someone provide a working view that lists entries by the time they are put on and not the time the node was created?
Login or register to post comments
Thanks for the above
didymo - January 6, 2009 - 21:23
Thanks for the above howto.
I had the calendar working very rapidly.
However after spending quite a few hours over a cuople of days I am clearly not doing something correctly in the Upcoming Block View.
I have set the date format to be dd/mm/yyyy. This works throughout the site, and in the views calendar. However no matter what I do the date of the event in the upcoming is registered as mm/dd/yyyy. I even removed the modules and started form scratch, more than once. I have emptied the cache tables. I just really do not know what to try next. This is clearly my fault. As everything else just works i have no idea what I mucked up.
Thanks to anybody with suggestions.
Regards,
Ashley
Login or register to post commentsbroken in latest date/calendar drupal 5 modules
dugh - January 12, 2009 - 17:22
I upgraded the date and calendar modules the other week, and not repeating dates just show the first instance. So now my upcoming events block is broken. I reported the bug here but nothing came of it:
http://drupal.org/node/352753
I usually test it out first on a staging site, but our server admin had everything else down.
When I upgrade to drupal 6 this summer, I'm probably going to just use the event module instead. It appears to be more stable now (although 6 months ago the reverse was the case).
Login or register to post commentsMy Filters look like
kwgossett - January 20, 2009 - 03:48
@Dugh
My Filters look like this:
Node: Type = Event
Node: Title != something_I_wanted_excluded
Date: Date Content: Start Time (field_time value) >= now - 1day
Node: Published Yes
yet, my upcoming events view still shows past events.
I notice that you have:
Date:Date - Date (field.....) vs. my
Date:Date Content: Start Time (field....).
I've got no idea what's going on, or how to remove past events :(
Any ideas?
Login or register to post comments
refresh maybe
dugh - January 25, 2009 - 04:41
you may need to clear your views cache - go to the tools tab under views to see a button to clear the cache.
or check for typos perhaps? like "now - 1 day" instead of "now - 1day" which might not be parsed correctly perhaps
Login or register to post comments
I have the same issue, that
ulf1 - February 12, 2009 - 21:10
I have the same issue, that older events still show up.
Clearing the cache did not help.
Interestingly if I display the query, like followed, it replaces "now" with '2008-11-01', and that causes the problem, but I am not sure how to tell the view module to use the current date .
Thanksm
Ulf
SELECT node.nid AS nid,
node_data_field_startdate.field_startdate_value AS node_data_field_startdate_field_startdate_value,
node_data_field_startdate.field_startdate_value2 AS node_data_field_startdate_field_startdate_value2,
node_data_field_startdate.field_startdate_rrule AS node_data_field_startdate_field_startdate_rrule,
node_data_field_startdate.delta AS node_data_field_startdate_delta,
node.title AS node_title,
node_revisions.body AS node_revisions_body,
node_revisions.format AS node_revisions_format,
node_data_field_startdate.nid AS node_data_field_startdate_nid,
node.type AS node_type,
node_data_field_highpriority.field_highpriority_value AS node_data_field_highpriority_field_highpriority_value
FROM calheat_node node
LEFT JOIN calheat_content_field_startdate node_data_field_startdate ON node.vid = node_data_field_startdate.vid
LEFT JOIN calheat_content_field_highpriority node_data_field_highpriority ON node.vid = node_data_field_highpriority.vid
LEFT JOIN calheat_node_revisions node_revisions ON node.vid = node_revisions.vid
WHERE ((node.type in ('calheatevent')) AND (node_data_field_highpriority.field_highpriority_value <= 2))
AND (DATE_FORMAT(ADDTIME(node_data_field_startdate.field_startdate_value, SEC_TO_TIME(-28800)), '%Y-%m-%d') >= '2008-11-01')
ORDER BY node_data_field_highpriority_field_highpriority_value ASC, node_data_field_startdate_field_startdate_value ASC
Login or register to post comments
weird timezone issue
jewhite - January 8, 2009 - 04:20
First of all .. great write up. Breaks it down nicely ... but not too simple to obfuscate what *can* be done ...
My Time zone was 5 hours off (I'm at GMT -5 ... EST) in the display of events. The machine is set to American/New York (EST), Drupal is set to America/New York, User is the same and the event is posted as America/New York. Whenever I saved an event, it incremented the time up 5 hours (to GMT). I turned off user configurable time zones and now it holds time correctly. Anyone else experienced this or have an idea as to why?
Cheers!
Login or register to post comments
Extra Help
fhsm - January 10, 2009 - 23:03
Hi All -
Looks like this thread hit a bit of a nerve with people. I've had a number of folks send me messages asking particular questions. Unfortunately I included 100% of what I know about this problem. Sorry to not be more help. Perhaps someone more active in the involved projects could document this use. Mine should not be the definitive word on how to accomplish this.
Login or register to post comments
repeating events
beg - February 20, 2009 - 20:46
Hi,
While configurating the event page I run into some new questions:
How can I support the creation of repeating events with cck/date/calendar/event modules? e.g. similar events every week, same day, same time. I have to have the possibility to create day/time once and say to repeat every weak, since it's no option to do that for every week manually.
and/or is there any possibility of "saving" kind of templates for events in order to save basic information of a repeating event and just creat a new entry by adding date/time information?
Background is a calendar for new and repeating events. (different events each of them being the same event, same description, weekly with some breaks for holidays..)
I also tried to get different colors for the different events with the node.color module, which would be very usefull. I created different event types with different colors, but they still dont show up in different colors in the Calendar..
thx,
Bernhard
Login or register to post commentsDon't use the date and calendar module
dugh - February 27, 2009 - 15:54
In Drupal 5, repeating events broke 3 months ago, and bug reports for the drupal 5 version of the date module are pretty much being ignored now.
If you are stuck like me, you'll have to downgrade to a version of the module before November 2008.
Introduction to CCK
Presentation on Sunday 20 July 2008
at 11:00 AM
Presenters
Alan Palazzolo
Description
This presentation aims to give a basic understanding of the powerful Drupal Module, CCK (Content Construction Kit). This module is so powerful in fact it is supposed to be in Drupal 7 core (meaning it will come with Drupal itself). Basically CCK allows site administrators to add fields to a content type other than the usual Title and Body. This presentation will begin with a brief overview of Drupal basics like nodes and content types. We will then cover the core CCK module, then dive into modules that extend CCK. Please feel free to ask questions.
Prerequisites
This presentation will use Drupal 5 modules. The same basic principles apply for Drupal 6 but the details can vary. And, as of this presentation CCK for Drupal 6 is not stable (but close).
Drupal Basics
Node
The term node in Drupal is a very abstract concept. The Node Module which handles nodes is a core module in Drupal, meaning that it works just like any other module but is required for Drupal to function. A node is any piece of content. (The other main pieces in Drupal are Blocks, Comments, and Users.) By default, a node simply holds a title and a body. In Drupal core, we can define different types of nodes.
Content Types
Drupal separates different types of nodes into content types. By default, Drupal comes with the page and story content types. Really the only difference in these two content types is that a story gets promoted to the front page and allows for comments; otherwise there is no actual difference. Drupal allows site administrators to add different content types. This is really helpful (and necessary) to organize content in a meaningful manner for your site. Also, by default Drupal allows for access management based on content type, so different content types will help with security.
Content types basically become your input forms for content. This could mean that you have a content type for a blog post that only bloggers can create. You may also have a content type for Movie Reviews that you only want registered users to create. By default, both these input forms (content types) will only have a title and a body.
But what if you want your Movie Review to include the movie title that it is referring to; then you want that movie title to be formatted a specific way. This is where CCK comes in. Without CCK, you would either have to develop a module that explicitly creates a new input for the movie title, or you would have to depend on the user to format the body of the node in a specific manner. Both are less than ideal.
CCK
CCK allows the site administrator, through the web interface, to create custom fields for any content type. This means that we can easily create a text-field for the movie title of the Movie Review content type. This new text-field allows for the content creator to have a more focused input mechanism and allows for the end user to have a well-formatted display.
Field Types and Widgets
In this context of CCK, text is a field type. Field types are types of data that are collected for a content type; for example, this could be text, an integer, a node ID, latitude and longitude. The base install of CCK comes with a number of field types such as text, integer, nodereference. Field types are not restricted to a single piece of data.
Widgets are the objects or mechanisms that these field types are gathered with and possibly displayed. For example, you could collect text data through a text-field, text-area, a drop-down menu, etc. You could also collect latitude and longitude data with two text-fields or through a web map.
Also, once you have defined a field type for a specific content type, CCK makes it easy to simply add that field type to a different content type.
Management and Display
Within each content type, CKK allows you to group different fields together and assign order by using the usual Drupal weighting system.
CCK also allows you to determine how each field within each content type will be displayed for either the teaser or full views of each node. CCK allows for modules to define different types of views for different field types. For example, and image field type can display an image at one resolution for the teaser view and a different resolution for the full view.
CCK, Extended
There are huge number of CCK Related Modules for Drupal. The following modules are some important or interesting ones that extend CCK in a number of ways. Together we will install and take a look at the functionality of each. Please click on each link to get a detailed description of each.
Computed Field
Date
Image Field
Link
AJAX Select
File Field
CCK Blocks
CCK Currency
CCK Field Permission (Integrated into CCK for Drupal 6)
CCK Map
Education Field
Phone
Related Modules
The following modules do not actually create any different CCK field types but are important on how CCK is accessed and displayed.
Node Profile
ConTemplate
Theming
This presentation will not go into theming CCK fields, but Chach Sikes will be giving a presentation entitled Theming CCK: working with fields, content types and template files at 3:00PM on Sunday July 20, 2008 which will cover this topic in detail
Mistakes made when using Drupal as personal blog
Submitted by dag on Sat, 2007/10/06 - 20:57
Being fallible (not being the pope) I learned some things from my Drupal installation. Dries asked me to keep a list of things, and this is a record of what I still remember.
Beware though that this list is focused on using Drupal for a personal blog.
You do not need the Blog module !
If you just want a personal blog, you really don't. I consider this vital advise, especially because not using Blog seems counter-intuitive and because it is described as:
Blog: Enables keeping easily and regularly updated user web pages or blogs.
You can simply use the Story content type for writing your blog articles and it makes your Drupal structure much more simple. The Blog module is really meant to allow individual users to have their own Blog, which is definitely not what I wanted. If you however made the same mistake as I did, here is the medicine:
mysql> UPDATE node SET type = 'story' WHERE type = 'blog';
Don't create Vocabularies or Terms individually
Don't do like I did and create your "tags" in advance, you really do not have to. And definitely do not start to put them in different categories and all that. Just create one Vocabulary called "Tags", enable free-tagging and be done with it. Every article you can simply add your tags in a comma seperated list.
The whole Taxonomy idea is a nice and abstract idea that covers all possible uses that far outreach the goals you have for a personal blog, so don't bother. You can always start using it if you are ready for it and if there is a *real* use.
Get used to and remember the Administer menu
I had a hard time finding exactly where some things resided in the menu and literally searched for more than 30 minutes to find where I could re-enable the Menu block for Anonymous users. This was not a pleasant experience, especially since I disabled it myself and couldn't remember where or how.
Maybe I have to add that late night hours are not the best times to contemplate something like this :)
Play with it and then start over
This is something I should have done, but time-constraints (a night only has 8 hours!) and other responsibilities of course get in the way. It is so easy to set op a second Drupal instance once you want to do it properly that you shouldn't care of breaking things.
Select a good set of modules
Some of the shortcomings I felt after I finished my setup actually were taken care of by powerful modules, only I didn't know of them. Of course I browsed the list by module name, but if you're not looking for something in particular you won't notice the interesting ones.
I ended up with the following list of additional modules, but I appreciate if you fill in some you use for a personal Drupal blog:
Captcha: prevent spam, but don't set it too difficult !
Event: nice if you want to tell visitors where they can meet you
Pathauto: important if you want a link that contains keywords (your title)
Recent Blocks: by default Drupal only has a Recent Comments block, which I didn't find that useful for my bog
Update status: this one is a *must-have* module, it can mail you a report when Drupal or modules get outdated (or have security related fixes)
I played with much more modules, but none of them survived the test of time :) Let me remind you that this article is about using Drupal for a personal blog. There are many many more modules that are useful, but less so if you only want a personal blog.
Disable what you don't need
I noticed that there was a lot included that I didn't need and I probably enabled stuff that I thought was useful. However I ended up with the following short list of non-core modules:
Comment, Menu, Path, Search, Statistics, Taxonomy, Tracker
Do you still remember your mistakes with Drupal ? Let us hear them !
blog drupal modules taxonomy
What about blog api
Submitted by Elito (not verified) on Sat, 2008/01/26 - 06:11.
Thanks for the tips! I've been playing around with drupal and messed up my site.
If you disable the blog module, what about blog api? Can you still use blog client like Blogdesk?
reply Personlised Menu navigation for Personal blog
Submitted by Anonymous (not verified) on Sun, 2008/02/03 - 15:42.
How could we define a personlised Menu navigation containing posts for a particular blog? Something in the tunes of wordpress and blogger blogs, it should be auto-updating. It shouldn't be like latest posts module. The blog menu should be native to its' blog owner. Any idea? I am using Drupal 4.7.
reply Thanks for suggestions,but...
Submitted by Technology on Leisure (not verified) on Wed, 2008/02/06 - 18:28.
I have a question.After reading your post,i think,for the same set of requirements that you gave,wordpress would be a much better option.I find drupal much complicated for being a personal site.Please suggest.
reply
No experience with Wordpress
Submitted by dag on Wed, 2008/02/06 - 23:47.
I cannot compare Drupal against Wordpress, but I have to say that I am very pleased with Drupal. I am using it for our family community site as well and that is much more than just a blog.
The modular design of Drupal makes it possible to use it for much more than a personal blog, and the acquired knowledge and experience can be shared for various projects. That was one of the reasons I chose Drupal over any of the other projects.
In total since november 2007 I have set up (or helped set up) 7 different websites.
reply
Wordpress for blogging, Drupal for anything more
Submitted by Jon (not verified) on Fri, 2008/06/20 - 21:50.
I switched from Wordpress to Drupal, and my opinion is that, for a site that is strictly a blog with perhaps a few static pages, go with Wordpress. It's optimized for blogging, and handles pretty much everything you might want to do with a blog right out of the box.
If you want more than that, go with Drupal. It will do much more, but the default installation is much less convenient for blogging than Wordpress. To really get the most out of Drupal, you have to go find (or write) modules to do what you want.
I think both are excellent options for website building, but targeted at different types of sites.
reply
Thanks for the tips
Submitted by Mel D. (not verified) on Wed, 2008/02/13 - 20:01.
I was planning on giving Drupal a try so your post comes very handy. Bookmarked! Thanks
reply You're right, Wordpress is
Submitted by Digi (not verified) on Wed, 2008/02/13 - 23:52.
You're right, Wordpress is much easier to use but it's no real CMS. There's no workflow for example.
reply I can relate
Submitted by Gerald (not verified) on Tue, 2008/03/11 - 20:20.
I also started my own blog with the blog module and ended up starting over.
Things I can share:
FCKEditor worked much better with my theme (GlossyBlue) than TinyMCE
FCKEditor has a nicely integrated file and picture upload
There is a "Read More Tweak" module that allows you to place the "Read More" text at the end of the teaser text and also to adjust the text itself.
You have to hack the theme to get rid of the "(not verified)" message in comments
The Fuzzy Search module allows for substrings to be found
The Views module allows nice archive and tags grouping (including count)
It wasn't a good idea to deploy Drupal in the root HTML directory - it makes upgrades much harder.
reply
Monday, February 23, 2009
embedded php in bat (batch) script. Winrar Backup Development files Example on Windows
@GOTO START
<?php
### embedded php in bat (batch) script.
// put some php code here
$now = date("ymd_his");
# where to store tar file.
$tarName = 'backup/' . $now . '_drupal.rar';
# specify a list of filename / folder name, separating by space.
$listFiles = 'drupal-6.9_Danny drupal-6.9_Karl';
exec( '"C:\\Program Files\\WinRAR\\WinRAR.exe"' . ' a ' . $tarName . ' -r ' . $listFiles );
/*
:START
@D:\UO\WebSites\PHP5.2.8\php.exe %0
@pause
@exit
*/
?>
PHP Version:
<?php
### embedded php in bat (batch) script.
// put some php code here
$now = date("ymd_his");
# where to store tar file.
$tarName = 'backup/' . $now . '_drupal.rar';
# specify a list of filename / folder name, separating by space.
$listFiles = 'drupal-6.10_dev drupal-6.9_Danny drupal-6.9_Karl';
hardFlush('Processing');
for($i=0; $i<3;$i++) {
echo ' . ';
ob_flush();
flush();
usleep(1000000);
}
echo 'Please Wait . . . Be patient ^_<';
ob_flush();
flush();
exec( '"C:\\Program Files\\WinRAR\\WinRAR.exe"' . ' a ' . $tarName . ' -r ' . $listFiles );
echo 'Done :)
';
function hardFlush($msg = '') {
// Like said in PHP description above, some version of IE (7.0 for example)
// will not 'update' the page if less then 256 bytes are received
// Send 250 characters extra
echo str_pad(" ",250);
echo $msg;
ob_flush();
flush();
}
?>
How do I stop Drupal from displaying a blank white screen?
Category:
User
Topic:
Module configuration
When you receive a blank white screen there are a couple of things that may be going on. Review the following issues below.
Memory Limit
When you're setting up a site with a large module set like Ubercart, you may run into the issue where your Drupal site becomes non-responsive and instead displays a blank white screen (also know as the White Screen of Death). This is most commonly due to the amount of memory required to run a site using so much code. While some major memory issues will be fixed in Drupal 6, for users of Drupal 5 you should try one of the following solutions.
* Add memory_limit = 32M to your php.ini file (recommended, if you have access)
* Add ini_set('memory_limit', '32M'); in your site's settings.php file
* Add php_value memory_limit 32M in your .htaccess file in the Drupal root
Depending on your site host, one or more of these options may not be available to you. Try them to see what works, and if you still can't solve the problem talk with your host about them increasing the limit for you.
These solutions and more information available here.
Error Reporting
If adjusting the memory limit isn't the culprit, another issue is that PHP could be failing somewhere, but not reporting the error to the screen. Inserting the following lines into the Drupal's index.php should set PHP to report all errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
?>
After inserting the code, load the same page that caused the same error in the first place. If any PHP errors are causing the page to load they should be displayed on the screen. From there the PHP error might give you a better indication of what's causing Drupal to fail.
Wednesday, February 18, 2009
How to make SELECT LIMIT (from, to) in MSSQL 2005
Lots of developers complain, that Microsoft SQL hasn't something similar to LIMIT(from, to) as MySQL has. In past time there was a solution by SELECT TOP n and inserted SELECT TOP n- With new T-SQL commands in Miscrosoft SQL Server 2005 is situation simpler.
DECLARE @rowsperpage INT
DECLARE @start INT
SET @start = 10002
SET @rowsperpage = 5
SELECT *
FROM (
SELECT row_number()
OVER (ORDER BY id desc) AS rownum, *
FROM my_member
) AS A
WHERE A.rownum BETWEEN (@start) AND (@start + @rowsperpage - 1)
go
Another example:
DECLARE @rowsperpage INT
DECLARE @start INT
SET @start = 10002
SET @rowsperpage = 5
SELECT *
FROM (
SELECT ROW_NUMBER()
OVER (ORDER BY id DESC) AS Row, *
FROM my_member
) AS LogWithRowNumbers
WHERE Row >= @start AND Row <=(@start + @rowsperpage - 1)
My Drupal Note
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
- Debug functions
dpm() prints a simple variable
dvm prints a var_dump()
dpr() prints a complex variable at the top of a page using a special recursive function (dprint_r()) that gives nicely formatted output
dvr() prints a nicely formatted var_dump() to the top of the page
Quick Note:
- Find out how come hook_menu() 遇到 %user_uid_optional 時 (or more than certain 段),它的 breadcrumb 就斷掉了? (還是有辦法弄回來,只是要有點 trick [有關 menu parent/child 的排列, 還有 MENU_NORMAL_ITEM, MENU_CALLBACK 好像也有關係?],覺得麻煩的話,直接用 drupal_set_breadcrumb() 吧
- 把 select content type 的 sql statement 寫成 function. companygossip_page_user()
- Hook_View()
- Hook_Load()
- Hook_nodeapi()
- 查 node / node type / term 之間的關係
- 如果 breadcrumb / Navigation 有問題時,
- 觀察 nai_menu_links table,
- 以及 menu.inc 的 array_pop($breadcrumb);
- 還有 兩層時 %user/% 會怪怪的,第二層用 MENU_DEFAULT_LOCAL_TASK ?
- Nainews.module 的 id_comp (and count ceo msg) 的問題還沒有解決!
- 如果 menu 的 page arguments
- The callback arguments you define in page arguments will be passed to the callback function BEFORE (that is, placed first in the list of parameter values that are passed to the callback) any arguments generated from the path. The arguments from the URL are still available; to access them, you would change the function signature of your callback to add parameters from the URL. P. 66.
Keys in keyed arrays are ignored in page callback argumnets, so you can't use keys to map to function parameters; only order is important. P. 66.
- off-site links:
- http://stevelockwood.net/index.php?q=cms
-
- 要研究的幾個 function
pager_query // query db related
db_rewrite_sql // query db related
variable_get // 從 database 裡的 table 調 value.
l // You can add additional values, such as 'class', in the array to customize the link.
t // Translate to human readble
check_plain // The solution is to use an appropriate filter when needed. For example, just before sending plain text to the browser or mixing plain text with HTML, escape it with check_plain.
drupal_get_form // function handles retrieving, processing, and displaying a rendered HTML form for modules automatically.
// Note that the form builder function always takes $form_state as its first argument
drupal_execute // Forms can also be built and submitted programmatically without any user input using the drupal_execute() function.
module_invoke // To call another block within inside another block.
// Sample:
// $block = module_invoke('nainews', 'hookName', 'arg0', 'arg1');
// print $block['content'];
module_invoke_all // If you are interested in seeing the function taht drives the hook mechanism, see the module_invoke_all() function in includes/module.inc.
module_implements //
drupal_goto // similiar to $form['#redirect'] or $form_state['redirect']
url //
drupal_set_message // Set a message which reflects the status of the performed operation.
// Call a function from another module.
// The module_exists() function is a Drupal API call that tells you if a module is enabled. function_exists() is a PHP function that tells you if the function is defined and available to you.
// Of course, if the other module is not enabled you should handle accordingly. But there exists a method in teh .info file to specify dependancy on other modules.
// Note: the correct one is just the functionName().
// Or try http://drupal.org/handbook/customization/php-snippets
if (module_exists('module_name') && function_exists('module_name_function_name')) {
module_name_function_name();
}
drupal_set_content // Content can be manually set inside regions with drupal_set_content
// http://drupal.org/node/171224
arg // Get parameters in url
// http://api.drupal.org/api/function/arg/6
file_create_url // Create the download path to a file.
theme('image', 'sites/all/themes/acquia_marina/icons/ceo.gif', $alt, $alt, '', FALSE) // show display image.
profile_load_profile // can be used to load profile fields.
module_implements // Determine which modules are implementing a hook.
node_invoke // Invoke a node hook.
node_invoke_nodeapi // Invoke a hook_nodeapi() operation in all modules.
- 建議要裝的 module
- devel.module // For Development Debugging. There are more useful functions in this module.
- Firebug (Firfox Extension / Add-on)
- CCK
- date.module
- views.module
- Calendar.module
- flag.module
- Advanced_help.module // The advanced help module allows module developers to store their help outside the module system, in pure .html files. The files can be easily translated simply by copying them into the right translations directory. The entire system can appear in a popup or not as the module prefers (and by taking away access to view the popups, a site can force the popups to not exist).
- Captcha: prevent spam, but don't set it too difficult !
- Panels
- Mailing List
- *** Simplenews
- Mailman Manager
- Groups / Forums
- Organic groups
- Rating (投票/按好/push)
- NodeReview.module
- Suggested link
- *** FiveStar
- FCKeditor // WYSIWYG HTML editor
- Navigation / Breadcrumbs
- Custom Breadcrumbs (with token.module)
- Node breadcrumbs
- Taxonomy Breadcrumb
- schema // Schema documentation: hyperlinked display of the schema's embedded documentation explaining what each table and field is for.
- 建議要裝的 theme
- Zen
- Acquia Marina
- Advanced Theme Construction Kit (ATCK)
- 幾個可以 study 一下的 module
- built-in search.module
- announcements.module // Great. block, hook, theme, and more.
- currency.module // Retrieve data from other sites.
- calendar_block.module // study cache.
- 幾個重要的 topic
- Drupal API
http://api.drupal.org/
- Module
- Module HowTos
http://drupal.org/node/22573
- How to update a module's weight
http://drupal.org/node/110238
- Block
- The appearance of a block is controlled in a theme by the (code: block($subject, $content, $region = "main") method.
http://drupal.org/getting-started/before/terminology
http://drupal.org/node/17170
- Block: controlling content in the sidebars
http://drupal.org/handbook/modules/block
- Hook
- hook_menu
http://api.drupal.org/api/function/hook_menu/6
- *** Menu
Define the navigation menus, and route page requests to code based on URLs.
The Drupal menu system drives both the navigation system from a user perspective and the callback system that Drupal uses to respond to URLs passed from the browser. For this reason, a good understanding of the menu system is fundamental to the creation of complex modules.
http://api.drupal.org/api/group/menu/6
// 有講解一些 array 裡的 elements 的 definition 和 用法
http://api.drupal.org/api/function/hook_menu/6
// arg( )
http://api.drupal.org/api/function/arg/6
http://api.drupal.org/api/file/developer/examples/page_example.module/6 (點選 view source,詳讀 hook_menu() )
- Menu.inc
http://api.drupal.org/api/file/includes/menu.inc/6/source
- Wildcard usage and core's wildcards
http://drupal.org/node/209056
- *** Dynamic argument replacement (wildcard)
http://drupal.org/node/109153
- Wildcard Loader Arguments
http://drupal.org/node/224170
- Form
- Form generation
http://api.drupal.org/api/group/form_api/6
- Forms API Quickstart Guide
http://api.drupal.org/api/file/developer/topics/forms_api.html/6
- forms_api_reference.html
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6
- Views
- The Views module provides a flexible method to control how lists of posts are retrieved and presented.
See the Views Module Developer API for detailed instructions on how to expose your module's tables and fields to views operations.
http://drupal.org/handbook/modules/views/api
- Why use Views? Why not write your own queries?
http://drupal.org/node/242311
- Managing views in code
http://drupal.org/node/272912
- Theme
- ***** Using the theme layer (Drupal 6.x)
http://drupal.org/node/165706
- If you are developing a module that outputs presentation data, then please read the module developer's guide Using the theme layer section.
http://drupal.org/node/165706
- Default theme implementations
http://api.drupal.org/api/group/themeable/6
- theme
http://api.drupal.org/api/function/theme/6
- hook_theme
http://api.drupal.org/api/function/hook_theme/6
- How to write themable modules
http://drupal.org/node/306
- About theming
http://drupal.org/node/221881
- Drupal 6 theme guide
http://drupal.org/theme-guide/6
- Tools, best practices and conventions
http://drupal.org/node/341707
- HTML and CSS techniques and tools
http://drupal.org/node/37156
- There are two ways to provide a default implementation. The easier but less recommend way is to provide a function, and the recommended way is to provide a template and a corresponding preprocessor function.
- *** Assigning content to regions
http://drupal.org/node/171224
- *** Setting up variables for use in a template (preprocess functions)
http://drupal.org/node/223430
- ***** About overriding themable output
http://drupal.org/node/173880
- *** Theme developer module for Drupal 6 - Screencast
http://drupal.org/node/209561
- Regions in themes (Drupal 4, 5)
http://drupal.org/node/29140
- Totally customize the LOOK of your front page
http://drupal.org/node/317461
- Core templates and suggestions
http://drupal.org/node/190815#template-suggestions
- Structure of the .info file
http://drupal.org/node/171205#regions
- Action
http://drupal.org/node/172152
- Database
- Database abstraction layer
http://api.drupal.org/api/group/database
- How to write database independent code
http://drupal.org/node/1395
- How to write efficient database JOINs
http://drupal.org/node/2041
- So, once more; There are three kind of errors you need to avoid: XSS with proper checking, SQL injections with proper db_query usage and node access bypass by utilizing db_rewrite_sql.
- When to use db_rewrite_sql
db_rewrite_sql() provides a method for modules to extend your SQL queries. This kind of functionality is especially important to modules which control access to nodes.
http://drupal.org/node/93737
- Others
- How to use watchdog() in your own code
http://drupal.org/node/86124
- How to measure the execution time of your Drupal scripts
http://drupal.org/node/320208
- How to make tablesorting work with multiple tables on the same page
http://drupal.org/node/98097
- Updating your modules
http://drupal.org/update/modules
- Tools, tips and tricks
http://drupal.org/node/188989
- Main content-related hooks
http://drupal.org/node/112180
- 'Status' field values for nodes and comments
http://drupal.org/node/4739
- Why does Drupal filter on output?
http://drupal.org/node/263002
- A beginner's guide to using PHP snippets
http://drupal.org/node/337959
- PHP snippets
http://drupal.org/handbook/customization/php-snippets
- Creating, displaying and combining content
http://drupal.org/node/206673
- Slashes in URL's instead of PHP parameters
http://drupal.org/node/1650
-
Must read:
Form:
http://api.drupal.org/api/file/developer/topics/forms_api.html
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html
Writing Secure Code:
http://drupal.org/writing-secure-code
Coding standards:
http://drupal.org/node/318
- 一個 module 的 permissions 不能隨便改!它是把 string 寫到 database 的
Your permission strings are arbitrary, but each must be unique among all installed modules. Otherwise, one occurrence of the name will take the permissions of the other. The permission strings should each usually contain your module name, since this helps avoid name space conflicts with other modules.
- drupal 是利用透過 網址上的 slash 來當做 hook_functions( ) 的 argument (parameter)
- Another very important point to note: we are dealing with nodes and the node access mechanism kicks in via db_rewrite_sql so we are utilizing it. It's really easy and yet it's so often neglected! See When to use db_rewrite_sql for further details.
http://drupal.org/node/93737
So, once more; There are three kind of errors you need to avoid: XSS with proper checking, SQL injections with proper db_query usage and node access bypass by utilizing db_rewrite_sql.
- Inline documentation for source files should follow the Doxygen formatting conventions.
http://drupal.org/node/1354
- Note that as of Drupal 4.7, the ?> at the end of code files is purposely omitted. This includes for module and include files. The reasons for this can be summarized as:
Removing it eliminates the possibility for unwanted whitespace at the end of files which can cause "header already sent" errors, XHTML/XML validation issues, and other problems.
The closing delimiter at the end of a file is optional.
PHP.net itself removes the closing delimiter from the end of its files
(example: prepend.inc), so this can be seen as a "best practice."
- two time-related functions:
strtotime( )
mktime( )
- Share a single database across multiple sites
http://drupal.org/node/2622
- Define shared variables for all sites
http://drupal.org/node/70472
- We use variable_get( ) to retrieve the value of the system configuration variable "onthisdate_maxdisp", and define the default value to be
look at the "variable" table in database
http://drupal.org/node/206761
Forms API Quickstart Guide
*** http://api.drupal.org/api/file/developer/topics/forms_api.html/6
- drupal_get_form( ) does the following:
* Starts the entire form-building process by getting the $form from the builder function
* Translates the $form['name'] items into actual form elements
* Performs any validation and "clean-up" that needs to be done, and calls custom validation functions if declared
* Submits the form if a submit function is declared, and the form has been submitted
* Calls any custom theming functions that have been declared
* Returns an HTML string which contains the actual form.
For more detailed information, also see the API page for drupal_get_form()
- An important thing to note: notice that $form['access'] has a '#tree' => TRUE attribute. this setting retains the full tree structure for all elements under it when it is passed to $form_state['values']. you must explicitly declare this anywhere you wish to retain an array's full hierarchy when it is passed.
- Use CCK (Content Construction Kit). This module allows you to create custom content types, containing all sorts of fields: text, numbers, image upload, node reference. For categorization, use the core module called taxonomy (find it at /admin/content/taxonomy).
- Drupal menu system
http://drupal.org/node/102338
- hook_menu( ) 是重點!
感覺一個 module 以 hook_menu( ) 為核心,根據在 hook_menu( ) 裡所定義的設定,去呼叫要做哪些事。
Contrary to all our other functions, 'all' and 'admin' (from the previous tutorial), are not Drupal hooks.
If you want to call this function from another module, use the standard naming scheme we've been using: modulename_action. It can be called using the function module_invoke function. If you want the function to remain private (because, say, it's merely a helper function in your module) and easily accessible by only your module, prefix the function name with an underscore.
- Drupal 的設計思想之一,跟 URL 所傳來的 parameters 有很大的關聯,並且還以 forward-Slash 分別代表 calling a function 的 parameters,例如 http://MyDomain/?q=MyModuleName/MyFirstName/MyLastName 那麼,假設今天我們 access 該 URL,該 URL 接著 call 一個我們所定義的 function,例如 MyModuleName_showAllContent ,那麼 MyModuleName_showAllContent( $firstName, $lastName ) function 可以以它的 parameter 來接收 URL 所傳來的值。
- 有不同的 theme when viewing different modules
- theme 的多格編排方式
- menu_router( ) table stores block access permissions and more!
- 在 function name 前加 底線 表示 a private function
- *** Must Read All - Terminology 術語
http://drupal.org/node/937
- How to troubleshoot (read this first)
Try the devel.module
http://drupal.org/node/72108
- Views is your friend. It allows you to filter the nodes you need, specify the fields you want to display and choose how to publish it.
- As mentioned previously, the function we just wrote isn't a 'hook': it's not a Drupal recognized name. We need to tell Drupal how to access the function when displaying a page. We do this with Drupal's hook_menu. Remember that we have already used hook_menu in the seventh tutorial in this series. The hook_menu defines the association between a URL and the function that creates the content for that url. The hook also does permission checking, if desired. We will use the hook_menu made previously and continue with it.
http://drupal.org/node/206764
- Drupal Programming from an Object-Oriented Perspective
http://api.drupal.org/api/file/developer/topics/oop.html/6
- String translation is mandatory; use it and love it
- String Accessibility
- String Security
http://drupal.org/node/299085
- UI (Theme) elements in Drupal 6
http://drupal.org/node/366887
- Doxygen formatting conventions
Drupal uses Doxygen to automatically generate documentation from the latest Drupal sources
http://drupal.org/node/1354
- navigation = breadcrumb
- showcase / case study / website
- Scalability options
For large sites, Drupal 6 performs properly when running behind a reverse proxy like Squid or Pound.
- Enabling user pictures / member picture / user photo / member photo / user avatars / member avatars
Note:
對於不同使用需求的 Drupal 入門玩家,你會給些什麼建議?
1. 架網站前,與其去了解 Drupal,不如先去思考架的網站類型(Portal, Forum, Blog, ...)有哪些類型的內容。這時完全不要去理會版型、網站呈現、配色或任何其它會把你注意力放到「畫面」的事務上,只要專心在內容的類型與分類,還有他們之間的關係就行。這絕對會花上好一段時間,而且花上一個禮拜或一個月都是正常的。
2. 對於入門 Drupal 的玩家來說,首要任務是了解 Node, Taxonomy, Menu 與 Block 這四個 Drupal 核心就「宅配」的模組。他們分別處理了「內容」「分類」「導覽式選單」「各式各樣組織過的區塊」。
3. 假設你作到了前兩點,那你可以開始使用 CCK 搭配 Views,把你之前提畫的內容類型,一一實現出來,而且重點是,只需要透過決定欄位,打打幾個欄位名稱與說明,然後用滑鼠點一點就行了,一丁點兒都不需要去寫什麼程式才對。對了,再次聲明,還是不需要在這個階段理會版型。
4. 再次回來認真看待 Views,這時你得開始用 Views 產生你要的 Page View(或 Block View),然後 key 一些資料進去,看看產生的 views 正不正常。我實在很想強調,一個使用 Drupal 架的網站,只要好好搞定 CCK 與 Views,你就可以不用再回來操心這類與「資料」有關的事了。
5. 插曲:為了讓你 key 資料方便些,你可以安裝一些 TinyMCE, FCKEditor(我最愛的), BBUEditor, ... 很多。可以在 http://drupal.org/project/Modules/category/63 找到你需要的。
6. 如果你一開始要架設的網站,屬於個人性質的,那接下來就是先去套用幾個你愛的版型(theme),然後就好了。真的,你現在最最需要的就是堆資料了,在沒有夠份量內容前,做再多都是白費力氣。
最後,一些很實用的模組的推薦列表:
* Drupal Podcast No. 40: Top 40 Projects
* 10 must have Drupal Modules
* Most Downloaded Drupal Modules
* Drupal Projects usage
http://drupaltaiwan.org/forum/20081110/2768
Tuesday, February 17, 2009
Call a function from another module
Call a function from another module
Calling a function from
Calling a function from module to another is simply a matter of calling the function just like any other. However, be awares that if the module is not enabled you'll throw a PHP error. To avoid this wrap any calls going out inside of a test like this:-
<?php
if (module_exists('module_name')) {
module_name_function_name();
}
?>
if you are truely paranoid you could do this also:-
<?php
if (module_exists('module_name') && function_exists('module_name_function_name')) {
module_name_function_name();
}
?>
or simply
<?php
if (function_exists('module_name_function_name')) {
module_name_function_name();
}
?>
The module_exists() function is a Drupal API call that tells you if a module is enabled. function_exists() is a PHP function that tells you if the function is defined and available to you.
Of course, if the other module is not enabled you should handle accordingly. But there exists a method in teh .info file to specify dependancy on other modules.
Tuesday, February 10, 2009
Installing MSSQL for PHP
Installing MSSQL for PHP
From MoodleDocs
Jump to: navigation, search
Moodle1.7
Contents[hide]
1 Introduction
2 Installation overview
3 Using FreeTDS on Unix
4 Using FreeTDS on Windows
4.1 Troubleshooting
5 Using ODBTP on Unix or Windows
6 Using ODBC on Windows
7 Related links
if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); }
Introduction
This short manual is suitable if you are trying to run Moodle 1.7 (and upwards) using the SQL*Server (MSSQL) RDBMS. Steps detailed below must be performed before installing Moodle itself.
First of all, minimum required version of MSSQL has been stabilised to MSSQL 2005 (v.9), although it might work with MSSQL 2000 (v.8) or newer. All the development process has been performed using MSSQL 2005 and there could be some unknown problems with previous releases.
While PHP comes with one, more or less, standard extension (mssql) that provides access to MSSQL databases, early we found some hard limits on it. Basically such default extension has some limits that prevent us to use it at all (you can find more info about these problems here).
So, in order to allow PHP (i.e. Moodle) to access to MSSQL DBs properly we have to install a mssql extension alternative to save us from the problems related above. See the sections below for details about the various options.
Installation overview
1. Get MSSQL Server installed and running. (A free limited version, SQL Server Express Edition is available for testing.)
Make sure that you choose mixed authentication (Windows and local accounts) to keep things simpler later. You'll be asked to define the "sa" account password (it's the default System Administrator account which has full access to all databases by default).
2. Make sure MS SQL Server can accept incoming TCP/IP connections on port 1433 (the standard one).
You might need to explicitly allow this in your Windows firewall (see the Control Panel). You may also need to edit options in the :SQL Server Configuration Manager -> Network Configuration -> Protocols -> TCP/IP enabled
3. Open the "SQL Server Management Studio" and create a new empty database. If you are using the "sa" account then you don't need to do anything else here.
4. Configure these settings in your created (and still empty) database:
ANSI NULLS Enabled = true (ALTER DATABASE mdl_HEAD SET ANSI_NULLS ON GO)
Quoted Identifiers Enabled = true (ALTER DATABASE mdl_HEAD SET QUOTED_IDENTIFIER ON GO)
5. Get PHP installed with a web server. Unless you want to do it under IIS or some other way, the packages on the Moodle download page are a good solution.
6. Choose one of the following specific sections for your server to install the mssql extension alternative installed and running properly on your PHP box.
7. Set the following settings in your php.ini file
mssql.textlimit = 20971520
mssql.textsize = 20971520
Also, don't forget to set one of the following alternatives, in order to get all the data properly "slashed":
magic_quotes_gpc = Off or
magic_quotes_gpc = On and magic_quotes_sybase = On
8. With all this properly configured, you can continue with a standard Moodle installation.
Using FreeTDS on Unix
Important Note 1: Due to one bug in PHP it's highly recommendable to use PHP > 5.1.6 with FreeTDS (more info).
Important Note 2: Due to one bug in how FreeTDS handles nulls and empty values for some text types it's highly recommendable to use a recent version of FreeTDS (0.64 + official patches) (more info).
If you web server is on Linux or some other flavour of Unix, try FreeTDS, http://www.freetds.org/ (documentation at http://www.freetds.org/docs.html)
Note that the download link above is a source download, so you will need to install and compile it properly.
Once downloaded and uncompressed you must "configure, make, make install" it. This will deploy some stuff in the "/usr/local" directory of your machine, mainly:
/usr/local/etc: where the freetds conf files will reside.
/usr/local/lib: where compiled libraries will reside.
/usr/local/bin: where some executables will reside.
Then, you must configure FreeTDS to point to your MSSQL DB server. To do so, edit (or create) the /usr/local/etc/freetds.conf file and put in there exclusively these lines: [global]
host = xxx.xxx.xxx.xxx (ip of the MSSQL server)
port = 1433
client charset = UTF-8
tds version = 7.0
text size = 20971520
At this point, and previously to build the mssql extension alternative, you can test conectivity with your MSSQL DB using the "/usr/local/bin/tsql" executable. Just do this: tsql -S serverhost -U dbowner -P dbpassword
If everything is ok, you'll get this output: locale is "es_ES.UTF-8"
locale charset is "UTF-8"
1>
just type, for example: sp_help sysobjects
and you might get some output from DB. Finally type: exit
and you'll be out from the "tsql" command line interpreter.
Now that you've successfully built, configured and tested FreeTDS it is time to create the mssql extension alternative that will provide us with the capacity of handling MSSQL DBs from within Moodle. To do so, you'll need configure your PHP server adding this new option to the usual ones: --with-mssql=/usr/local/
then, after the standard "make and make install" steps, your PHP server will be built with MSSQL support provided by FreeTDS.
Finally, configure your Moodle config.php with this DB related info and continue with a normal Moodle install: $CFG->dbtype = 'mssql_n'; // Required
$CFG->dbhost = 'xxx.xxx.xxx.xxx'; // IP of the MSSQL server (also proper hostname is allowed)
$CFG->dbname = 'moodle'; // or whatever you called the database you created
$CFG->dbuser = 'yourusername'; // I usually use the 'sa' account (dbowner perms are enough)
$CFG->dbpass = 'yourpassword';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_'; //Prefix, you can change it, but never leave it blank.
Using FreeTDS on Windows
If your web server is on Windows, use php_dblib.dll from Frank Kromann (original details here). Despite the name, it's FreeTDS compiled for Windows. Many thanks to Frank for providing this DLL. Here's how to set it up:
1. Download the appropriate copy of php_dblib.dll from the list below, and save it into your /PHP/ext directory. (php_dblib.dll does not appear to be available for PHP 4.x at this time.)
php_dblib.dll for PHP 5.1.x
php_dblib.dll for PHP 5.2.x
php_dblib.dll for PHP 6.x
(here you can find some instructions to build those freetds extensions under win32 yourself)
2. FreeTDS requires the .NET Framework v1.1 to be installed. You can download it from the Microsoft website along with its service pack. Alternatively, if you do not wish to install this framework, you can download the required DLL from Frank's site, and save it into your /PHP root directory.
3. Edit your /PHP/php.ini file and add this line: extension=php_dblib.dll
Make sure that any lines referring to the php_mssql.dll extension are DISABLED (commented out).
4. Create a file called C:\freetds.conf with: [global]
host = xxx.xxx.xxx.xxx (ip of the MSSQL server)
port = 1433
client charset = UTF-8
tds version = 7.0
text size = 20971520
5. Your Moodle config.php should include lines like these: $CFG->dbtype = 'mssql_n'; // Required
$CFG->dbhost = 'localhost'; // assuming MS SQL is on the same server, otherwise use an IP
$CFG->dbname = 'moodle'; // or whatever you called the database you created
$CFG->dbuser = 'yourusername'; // I usually use the 'sa' account (dbowner perms are enough)
$CFG->dbpass = 'yourpassword';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_'; //Prefix, you can change it, but never leave it blank.
If you don't have a config.php file yet, it can be generated as normal from the Moodle installer.
6. Restart or start your web server. If Moodle still cannot communicate with the database server, please turn display_startup_errors to "On" in your /PHP/php.ini file, then restart the web server and check for any errors that may indicate incorrect DLL versions or missing dependencies. These error reports, turned off by default in PHP, can be vital in locating a problem with new extension installations.
7. Install Moodle as usual. Good luck!
Troubleshooting
If you encounter some problems you can try:
check that you have DotNet framework 1.1 installed (later version are installed on Vista, but you could need this specific one)
enable TCP/IP for MSSQL: SQL Server 2005 Network Configuration -> Protocols for MSSQLSERVER -> TCP/IP (Enable) -> Properties -> Ip Addresses -> 127.0.0.1 (Active+Enable)
if you are using SQL Server 2005 and you have the error 4004: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier, try the ODBTP method (next chapter). The SQL Server complaining that it doesn't support pure Unicode via TDS or older versions of ODBC. Microsoft has deprecated DB-Library a long ago, in favor of ODBC, OLE DB, or SQL Native Client. Many new features of SQL 2005 aren't accessible via DB-Library so if you need them, you could have to switch away from tools based on TDS and DB-Library :(
Using ODBTP on Unix or Windows
You can download ODBTP from http://odbtp.sourceforge.net/. Also you will access to the documentation from the same page.
The downloaded package includes both the source code and some binaries to be installed in the server and some ready-to-use mssql extension alternatives for some platforms/PHP versions (so you won't need to compile it if your PHP server/version binary package is present).
First of all, we have to install the Win32 service that comes with the package. Let's assume that it's going to run in the same Win32 machine where your MSSQL server is running (although it can run in any other Win32 server in your network).
To do do, following the instructions present in http://odbtp.sourceforge.net/install.html, you must:
Create a directory on the Windows host where the service program files will reside, i.e., md odbtp.
Copy the files odbtpctl.exe, odbtpsrv.exe and odbtpsrv.ini files from the winservice directory into the directory created in step 1.
Edit the file odbtpsrv.ini of the previous step and this line: MaxRequestSize=20971520
Open a command prompt (cmd) window on the Windows host.
Change to the directory to which the service program files were copied, i.e., cd odbtp.
Run the following commands to install and start the service:
odbtpctl install (NOTE: at the date this note is written -23/06/08- the ODBTP service can only be installed on Windows NT 4.0, 2000 or XP Pro. The service cannot be installed on Microsoft Windows Vista)
odbtpctl start
With these steps you should have one new service running in your host called "odbtp". Verify it's present and running in the "Services" control panel.
Don't forget to enable TCP/IP incoming connections to port 2799 in the host you have installed the service!
Now it's time to build the mssql extension alternative. First of all, verify if, in the downloaded package, under the "php" dir, there is one extension suitable for your PHP server/version. If it's present, you can simply copy it to the php/extensions dir in your PHP server and skip next points about compiling it from source. It's important to point that, inside each directory, you'll find two different libraries/dll files. The one that must be copied to the extensions dir is the one called "php_odbtp_mssql.xxx"!
If in the downloaded package isn't present the extension matching your PHP platform/version, you should build if from source files. To do that, just "configure, make, make install". That will create some stuff under "/usr/local".
Now that you've successfully built ODBTP is time to create the mssql extension alternative that will provide us with the capacity of handling MSSQL DBs from within Moodle. To do so, just configure your PHP server adding this new option to the usual ones: --with-odbtp-mssql
then, after the standard "make and make install" steps, your PHP server will be built with MSSQL support provided by ODBTP.
Finally, independently if we are using the binary extension provided in the download or if you have built it from source files, it's time to configure the extension. To do so, add this lines, if no present, to your php.ini file: extension=php_odbtp.dll
(only for Win32 PHP servers!)
And, for all the server platforms: [odbtp]
odbtp.interface_file = "/path/to/your/odbtp.conf"
odbtp.datetime_format = mdyhmsf
odbtp.detach_default_queries = yes
(where /path/to/your/odbtp.conf" is usually "/usr/local/etc/odbtp.conf"" for Unix systems and "C:\odbtp\odbtp.conf" for Windows systems)
Then, edit such "odbtp.conf" file and put there these contents: [global]
odbtp host = xxx.xxx.xxx (ip or hostname of the Win32 box running the ODBTP service)
type = mssql
unicode sql = yes
use row cache = yes
right trim text = yes
var data size = 20971520
With this, your PHP server will be able to connect with the MSSQL DB server using ODBTP. From here, just continue with the installation.
Finally, if you find the ODBTP executables and mssql extension alternative in binary formats, it only will be necessary to install them in your server (binary packages...) without the need to recompile anything (just the php.ini and odbtp.conf edition steps above will be necessary). Of course, it will be really welcome to have all those binary alternatives documented here.
Once ODBTP is working, Moodle config.php should include lines like these: $CFG->dbtype = 'mssql_n'; // Required
$CFG->dbhost = 'localhost'; // assuming MS SQL is on the same server, otherwise use an IP
$CFG->dbname = 'moodle'; // or whatever you called the database you created
$CFG->dbuser = 'yourusername'; // I usually use the 'sa' account (dbowner perms are enough)
$CFG->dbpass = 'yourpassword';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_'; //Prefix, you can change it, but never leave it blank.
If you don't have a config.php file yet, it can be generated as normal from the Moodle installer.
Using ODBC on Windows
This functionality is EXPERIMENTAL and must not be used on production environments!
1. Go to the Administrative Tools control panel, then the Data Sources (ODBC) panel.
2. Configure one new System/User DSN (call it, for example "moodle"). Dont forget to enable these options if the driver asks for them:
ANSI NULLS Enabled = true
Quoted Identifiers Enabled = true
3. Your Moodle config.php should include lines like these: $CFG->dbtype = 'odbc_mssql'; // Note this is different to all the other configs on this page!
$CFG->dbhost = 'moodle'; // Where this matches the Data source name you chose above
$CFG->dbname = ''; // Keep it blank!!
$CFG->dbuser = 'yourusername'; // I usually use the 'sa' account (dbowner perms are enough)
$CFG->dbpass = 'yourpassword';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_'; //Prefix, you can change it, but never leave it blank.
4. Install Moodle as usual. Good luck!
Related links
Installing Oracle for PHP
Retrieved from "http://docs.moodle.org/en/Installing_MSSQL_for_PHP"
Categories: Moodle 1.7 Experimental Features Installation Developer XMLDB