<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/21/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tanthalas</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/21/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tanthalas"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/Special:Contributions/Tanthalas"/>
	<updated>2026-05-09T06:18:14Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/status&amp;diff=96130</id>
		<title>blocks/moodletxt/status</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/status&amp;diff=96130"/>
		<updated>2012-11-01T10:32:30Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of the documentation for the message status page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Message Status Page ==&lt;br /&gt;
&lt;br /&gt;
The message status page gives full details on the recipients of a given message, along with the status of the text messages sent. When the page loads, the details of the message sent will appear at the top left.  This includes the Moodle user from which the message was sent, the time at which it was sent, the time it was scheduled to be sent at, and the actual text of the message.  Below this, the recipients of the message are listed.&lt;br /&gt;
&lt;br /&gt;
For each recipient, the following information is shown:&lt;br /&gt;
&lt;br /&gt;
; Recipient : This field shows the name of the recipient, whether they are a Moodle user or a contact in your address book.&lt;br /&gt;
&lt;br /&gt;
; Destination Number : The phone number to which the text message was sent.&lt;br /&gt;
&lt;br /&gt;
; Time of Update : The time and date at which this message&#039;s status information was last updated by the ConnectTxt system.&lt;br /&gt;
&lt;br /&gt;
; Message Status :  The current status of this text message.  There are three icons that are used to denote the status of a message.  A red icon with a cross through it means that the message has failed.  The recipient will not receive the message, and it should be checked and re-sent to this recipient.  A green icon with no cross or tick means that the message has been sent, and no further information has yet been received.  A green icon with a tick means that the message was received by the recipient.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The listing table can be edited and re-ordered like any other Moodle data table. Once you are happy with the data currently onscreen, you can also export it to a spreadsheet or similar file using the download options at the bottom of the table. Simply select the type of export you would like from the provided drop-down list, and then click the download button. &lt;br /&gt;
&lt;br /&gt;
=== Updating Message Statuses ===&lt;br /&gt;
&lt;br /&gt;
If your MoodleTxt installation has been configured correctly, it will automatically update message statuses in the background, without your intervention. However, if you wish to check for updated information, simply click the &amp;quot;Update&amp;quot; button, above the status listing on the left of the page.  The page will refresh (this may take a moment while the ConnectTxt system is contacted), and the most up-to-date information will be displayed.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Status Messages]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtfilters&amp;diff=96129</id>
		<title>admin/setting/moodletxtfilters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtfilters&amp;diff=96129"/>
		<updated>2012-11-01T10:31:09Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Documentation for MoodleTxt&amp;#039;s filter management page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Managing Inbound Filters in MoodleTxt ==&lt;br /&gt;
&lt;br /&gt;
This page allows you to edit MoodleTxt&#039;s inbound message filters. These filters are used when incoming messages are received from the ConnectTxt system, to forward them to the appropriate Moodle user&#039;s inbox. This form uses a step-by-step process to edit the filters in place, and add new ones. Fields within the form that are not ready for use, or depend on user input, will be locked until they are ready, so don&#039;t worry if you can&#039;t immediately access some parts of the form.&lt;br /&gt;
&lt;br /&gt;
=== Selecting a ConnectTxt Account ===&lt;br /&gt;
&lt;br /&gt;
Firstly, select the ConnectTxt account within the system you wish to apply filters on from the first drop-down box in the form.  You will see a loading icon appear for a short period whilst MoodleTxt loads the existing filter structure for that account.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In terms of filtering, ConnectTxt accounts are independent of one another.  It is quite possible to have the same keyword filter on several different accounts, routing messages to different users.  Similarly, it is possible to set up one keyword across all accounts that is always filtered to the same user.&lt;br /&gt;
&lt;br /&gt;
=== Selecting or Creating a Filter ===&lt;br /&gt;
&lt;br /&gt;
Once the loading icon has disappeared, the two lists of existing filters will be populated and unlocked.  You now have two options.  &lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;To edit an existing filter&#039;&#039;&#039; on the system, select it from either the keyword or phone number filter list.  You will see another loading message while the details of that particular filter are pulled out of the database. When this disappears, you should be able to see the filter&#039;s current recipients in the large select box underneath.&lt;br /&gt;
# &#039;&#039;&#039;To create a new filter&#039;&#039;&#039;, click the green &amp;quot;add&amp;quot; icon to the right of either the keyword or phone number filter lists, depending on which you wish to create.  The filter list will be replaced with a text box.  In this box you enter the operand for your new filter – that is the keyword or phone number on which you wish to filter messages.  Once you have done this, the large recipient list underneath should be unlocked.&lt;br /&gt;
&lt;br /&gt;
You have now specified the filter you wish to edit.  Below the two filter options on the page is a larger select box.  This box holds a list of all the recipients specified for a particular filter.  For a new filter, this will be blank, and for an existing filter, it will show the list of previously selected recipients for that filter.&lt;br /&gt;
&lt;br /&gt;
=== Adding and Removing Filter Recipients ===&lt;br /&gt;
&lt;br /&gt;
To add a new recipient to a filter, locate the textbox labelled &amp;quot;Add users to filter&amp;quot;. This is an auto-completing search box.  As you type in it, it searches the Moodle database for the user you are looking for and displays possible selections onscreen.  You can search by either first name, last name or username.  For example, typing &amp;quot;Pre&amp;quot; into our MoodleTxt test server would display &amp;quot;Preece, Greg J (admin)&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
Once the user you are looking for is displayed, select them by either highlighting them with the arrow keys and hitting return, or by clicking on them with the mouse.  You should see the user being added to the recipient list.&lt;br /&gt;
&lt;br /&gt;
To remove a recipient from a filter, select them from the recipients list and click the &amp;quot;Remove selected users from filter&amp;quot; button below it.  They will be immediately removed from the recipients list. You can remove multiple users at the same time by either holding CTRL to select multiple individual entries, or holding SHIFT to select a consecutive group.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once the filter has been edited/created to your satisfaction, and the recipients list appears correct, click the &amp;quot;Save the filter&amp;quot; button at the bottom of the form, and it will be saved back to the database.  If you have removed all recipients from an existing filter, then that filter will also be deleted once the recipients have been removed.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Settings Filters]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtaccountsnew&amp;diff=96128</id>
		<title>admin/setting/moodletxtaccountsnew</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtaccountsnew&amp;diff=96128"/>
		<updated>2012-11-01T10:28:29Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of documentation for MoodleTxt&amp;#039;s &amp;quot;add account&amp;quot; page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding a New ConnectTxt Account to MoodleTxt ==&lt;br /&gt;
&lt;br /&gt;
This page allows you to register a new ConnectTxt account with the MoodleTxt block. It should be one of your first stops after installing the block, and you will be redirected to it if you attempt to access other account-related pages when no accounts have been added to MoodleTxt. &lt;br /&gt;
&lt;br /&gt;
If no accounts have been added to MoodleTxt when you go to this page, then some introductory text will be displayed explaining the purpose of the block and providing useful contact information. Beneath this, you will find the form for entering a new ConnectTxt account. Enter the username and password of the ConnectTxt account you wish to add to MoodleTxt.  You may also enter a short description of the account if you wish.  &lt;br /&gt;
&lt;br /&gt;
With this done, please select a user to use as the default inbox for incoming messages on this account. The user with the default inbox is the one that will receive any inbound text messages that do not match any user filters within the MoodleTxt installation. This is to prevent unfiltered messages being lost.  It is required that you select a default inbox owner even if you do not intend to use MoodleTxt for inbound messaging.  Only users with the [[Moodletxt_capabilities|&amp;quot;block/moodletxt:defaultinbox&amp;quot; capability]] can own default inboxes.&lt;br /&gt;
&lt;br /&gt;
Once you are done, click “Add Account.”  The page will refresh.  As it does so, the account details entered will be validated with  the ConnectTxt system.  This ensures that all the ConnectTxt accounts you save in MoodleTxt exist on the ConnectTxt system, that the passwords are correct, and that the accounts have been enabled for use with MoodleTxt.  If no errors are found, you will be taken to the [[admin/setting/moodletxtaccounts|MoodleTxt account listing page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Settings Account New]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-accounts-updater.png&amp;diff=96127</id>
		<title>File:moodletxt-accounts-updater.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-accounts-updater.png&amp;diff=96127"/>
		<updated>2012-11-01T10:26:53Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of an account update in progress on the MoodleTxt account listing page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of an account update in progress on the MoodleTxt account listing page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-access-toggles.png&amp;diff=96126</id>
		<title>File:moodletxt-access-toggles.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-access-toggles.png&amp;diff=96126"/>
		<updated>2012-11-01T10:26:04Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the account access toggles within MoodleTxt&amp;#039;s account listing page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the account access toggles within MoodleTxt&#039;s account listing page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-access-form.png&amp;diff=96125</id>
		<title>File:moodletxt-account-access-form.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-access-form.png&amp;diff=96125"/>
		<updated>2012-11-01T10:25:15Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the account restriction form in use within the MoodleTxt control panel&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the account restriction form in use within the MoodleTxt control panel&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-access-button.png&amp;diff=96124</id>
		<title>File:moodletxt-account-access-button.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-access-button.png&amp;diff=96124"/>
		<updated>2012-11-01T10:24:20Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96123</id>
		<title>File:moodletxt-account-edit-button.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96123"/>
		<updated>2012-11-01T10:22:58Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: uploaded a new version of &amp;amp;quot;File:moodletxt-account-edit-button.png&amp;amp;quot;: Reverted to version as of 10:21, 1 November 2012&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96122</id>
		<title>File:moodletxt-account-edit-button.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96122"/>
		<updated>2012-11-01T10:22:35Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: uploaded a new version of &amp;amp;quot;File:moodletxt-account-edit-button.png&amp;amp;quot;: Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96121</id>
		<title>File:moodletxt-account-edit-button.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-account-edit-button.png&amp;diff=96121"/>
		<updated>2012-11-01T10:21:54Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shot of the button to click if you want to edit outbound access on a ConnectTxt account in MoodleTxt.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtaccounts&amp;diff=96120</id>
		<title>admin/setting/moodletxtaccounts</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=admin/setting/moodletxtaccounts&amp;diff=96120"/>
		<updated>2012-11-01T10:20:52Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Completing initial documentation for the account listing page in MoodleTxt 3.0&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Moodletxt: ConnectTxt Account Listings ==&lt;br /&gt;
&lt;br /&gt;
On this page, you can get an overview of all the ConnectTxt SMS messaging accounts that have been registered within MoodleTxt. When you first load the page, you will be shown a list of all currently saved ConnectTxt accounts, along with their basic details. You can use this page to edit an account&#039;s details, along with which users can access each account.&lt;br /&gt;
&lt;br /&gt;
=== Adding a New Account ===&lt;br /&gt;
&lt;br /&gt;
[[admin/setting/moodletxtaccountsnew|Adding new accounts]] is handled on a separate page. To add a new ConnectTxt account to the MoodleTxt system, click the &amp;quot;Add New Account&amp;quot; link in the paragraph at the top of the page. If you attempt to view the account listings page, and no ConnectTxt accounts have been added to MoodleTxt, you will be automatically redirected to this link (this only occurs at first installation).&lt;br /&gt;
&lt;br /&gt;
=== Account Listing ===&lt;br /&gt;
&lt;br /&gt;
The onscreen table shows all ConnectTxt accounts currently stored within the MoodleTxt block. At first glance, the following fields are displayed:&lt;br /&gt;
&lt;br /&gt;
; Username : The username of the ConnectTxt account.&lt;br /&gt;
; Description : The description you gave the ConnectTxt account when adding it to MoodleTxt.&lt;br /&gt;
; Messages Sent : The total number of messages sent through this account.&lt;br /&gt;
; Allow Outbound : Whether outbound access (message sending) is enabled on this account. If outbound messaging is enabled, you will see an icon showing 4 outbound arrows. If outbound messaging is disabled, you will see a red cross.&lt;br /&gt;
; Allow Inbound :  Whether inbound access (receiving messages) is enabled on this account. If inbound messaging is enabled, you will see an icon showing 4 inbound arrows. If inbound messaging is disabled, you will see a red cross.&lt;br /&gt;
; Credits Used : The number of credits that have been used on your ConnectTxt account. This includes all messages sent, not just those sent via MoodleTxt. This figure is updated via [[Moodletxt_cron|cron]], or manually [[#updateInfo|via the controls on this page]].&lt;br /&gt;
; Credits Remaining : The number of remaining credits on your ConnectTxt account. If your account is invoiced, this will show as an &amp;amp;infin; infinity symbol.&lt;br /&gt;
; Account Type : What type of account billing this ConnectTxt account has enabled. This is typically either invoiced or pre-paid.&lt;br /&gt;
; Last Update : The time at which this account&#039;s online details (credits used/remaining, account type) were last updated from the ConnectTxt system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Changing an Account&#039;s Password or Description ===&lt;br /&gt;
&lt;br /&gt;
On the far left of an account&#039;s listing, before its username, you will find the edit button. &lt;br /&gt;
[[Image:moodletxt-account-edit-button.png|border|none]]&lt;br /&gt;
Clicking this button will open a modal dialog box containing the account&#039;s description, and a field allowing you to enter a new password. Edit the description as you see fit.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The password field is optional, and should only be filled in if you need to change the password on the account.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once the fields in the dialog box are complete, click the &amp;quot;Save&amp;quot; button. The system will contact ConnectTxt to validate the details entered, and to fetch the latest credit data for the account. If the account is successfully validated, the dialog box will close and you will be returned to the main account listing.&lt;br /&gt;
&lt;br /&gt;
=== Changing Which Users can Send Messages Via an Account ===&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-account-access-button.png|border|none]]&lt;br /&gt;
MoodleTxt allows you to restrict outbound access to ConnectTxt accounts to a given list of Moodle users. If you would like to restrict access to an account, click on the &amp;quot;edit access&amp;quot; icon at the front of the account&#039;s &amp;quot;Allow Outbound&amp;quot; field. A modal dialog box will open containing a form that will allow you to restrict user access.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-account-access-form.png|frame|center|Access restriction form]]&lt;br /&gt;
The list labelled &amp;quot;Allowed Users&amp;quot; is the list of Moodle users that this account will be restricted to. If this list is blank, then the account will be unrestricted. To add users to the list, begin typing their name or username in the search box at the top of the form. This is an auto-completion search box, and will automatically perform a background search for the entered name (or partial name) when you stop typing. &lt;br /&gt;
&lt;br /&gt;
When the user you wish to add appears in the auto-complete list, select them using the mouse or arrow and enter keys. They will be added to the list of users allowed to access the account. To remove one or more users from the list, click on their username(s) and then click the &amp;quot;Remove User(s)&amp;quot; button below the list. Removing all users from the list will make the account unrestricted.&lt;br /&gt;
&lt;br /&gt;
Once you are happy with the restrictions applied to (or removed from) the account, click the &amp;quot;Save&amp;quot; button. The account&#039;s restrictions will be updated in the database, and you will be taken back to the account listing.&lt;br /&gt;
&lt;br /&gt;
=== Disabling/Enabling Inbound and Outbound Access on an Account ===&lt;br /&gt;
&lt;br /&gt;
You can completely turn off inbound or outbound access for any given ConnectTxt account. This is a simple matter of toggling the switches displayed under the &amp;quot;Allow Outbound&amp;quot; and &amp;quot;Allow Inbound&amp;quot; fields for an account. If your chosen route is enabled, you will see an icon featuring 4 green arrows. If it is disabled, you will see a red cross. Clicking on an enabled route will turn it off, and vice versa. For example, in this screenshot, the account has outbound messaging enabled, but is disabled for inbound messaging:&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-access-toggles.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span id=&amp;quot;updateInfo&amp;quot;&amp;gt;Updating Account Information&amp;lt;/span&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
If you have [[Moodletxt_cron|cron-based updates]] enabled, then credit information for all your ConnectTxt accounts will be updated at regular intervals. If not, you can manually fetch updates from the account listing page, simply by clicking the &amp;quot;Update Credit Info&amp;quot; button at the top of the page. When you click this button, a progress bar will appear, and the system will run through each account in turn, updating the information on the page as it goes. Any information that has been updated will be displayed in bold. When the progress bar reaches 100% and all accounts have been processed, it will hide itself again, and the update button will be re-enabled.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-accounts-updater.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Settings Account Listing]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=admin/setting/blocksettingmoodletxt&amp;diff=96119</id>
		<title>admin/setting/blocksettingmoodletxt</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=admin/setting/blocksettingmoodletxt&amp;diff=96119"/>
		<updated>2012-11-01T10:18:57Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Removing unnecessary link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt Settings ==&lt;br /&gt;
&lt;br /&gt;
This page contains all the common configuration options for MoodleTxt. At the top of the page you will see two links:&lt;br /&gt;
&lt;br /&gt;
; ConnectTxt Accounts : This link will take you to the ConnectTxt account admin pages, which will allow you to add, update and restrict these accounts. If you have just installed MoodleTxt, this should be your first stop.&lt;br /&gt;
; Inbound Message Filters : This link will take you to the inbound filter management page, which will allow you to create filters for inbound SMS messages, routing them to particular Moodle users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send/Receive Settings ===&lt;br /&gt;
&lt;br /&gt;
The first 4 settings in this section relate to how MoodleTxt gets both message status updates and new inbound messages from the ConnectTxt system. By default, MoodleTxt pulls these updates on a per-request basis, whenever users visit certain pages. However, it can be configured to get these updates automatically, which improves the performance of the block and results in far fewer outbound connections. The available automatic update methods are [[Moodletxt_cron | cron]] and [[Moodletxt_push | push]]. We &#039;&#039;&#039;highly&#039;&#039;&#039; recommend taking the time to set up push functionality, as it is the fastest and most efficient method of obtaining updates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Get_Status_On_View&lt;br /&gt;
| Automatically get status updates on &amp;quot;View Message&amp;quot; page&lt;br /&gt;
| If this box is checked, then whenever a user views the current status of a sent message, the block will first connect to the ConnectTxt system in order to fetch updates. You should uncheck this if you have configured an automatic update option as mentioned above.&lt;br /&gt;
|-&lt;br /&gt;
| Get_Inbound_On_View&lt;br /&gt;
| Automatically get inbound messages on Inbox page&lt;br /&gt;
| If this box is checked, then whenever a user views their inbox, the block will first connect to the ConnectTxt system in order to fetch new messages. You should uncheck this if you have configured an automatic update option as mentioned above.&lt;br /&gt;
|-&lt;br /&gt;
| Push_Username&lt;br /&gt;
| XML Push Username&lt;br /&gt;
| If you have set up XML push updates (highly recommended) then this is the username you provided to ConnectTxt as part of that setup. ConnectTxt uses this username to authenticate itself with your MoodleTxt installation when connecting to it.&lt;br /&gt;
|-&lt;br /&gt;
| Push_Password&lt;br /&gt;
| XML Push Password&lt;br /&gt;
| If you have set up XML push updates (highly recommended) then this is the password you provided to ConnectTxt as part of that setup. ConnectTxt uses this password to authenticate itself with your MoodleTxt installation when connecting to it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The last two settings in this category control other parameters related to message sending via ConnectTxt.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Protocol_Warnings_On&lt;br /&gt;
| Display SSL security warnings&lt;br /&gt;
| If you do not have SSL connections to the ConnectTxt server enabled, MoodleTxt will generally display warnings that your data is being transmitted in an unsecure manner. To disable these warnings, uncheck this box.&lt;br /&gt;
|-&lt;br /&gt;
| Event_Messaging_Account&lt;br /&gt;
| Event Messaging Account&lt;br /&gt;
| This is the ConnectTxt account that MoodleTxt will use when it is asked to send automatic messages out in response to system events. By extension, this is the ConnectTxt account that will be used to send any messages originating via the MoodleTxt Plus message processor plugin. If no account is selected, then MoodleTxt will be unable to send event-generated messages.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Recipient Settings ===&lt;br /&gt;
&lt;br /&gt;
The settings in this section relate to how MoodleTxt captures user phone/name information from the Moodle system, and how it processes that information in order to send SMS messages out. (Future versions of the block will feature improvements in international phone number handling.)&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| National_Prefix&lt;br /&gt;
| National Prefix&lt;br /&gt;
| This is the default dialling prefix for phone numbers within your country. It is the digit or set of digits that all phone numbers begin with when being dialled within the country. This defaults to 0, the UK domestic dialling prefix. (&#039;&#039;&#039;Note:&#039;&#039;&#039; If the phone numbers you enter into MoodleTxt are already formatted internationally, e.g. +441234567890, then this setting is ignored.)&lt;br /&gt;
|-&lt;br /&gt;
| Default_International_Prefix&lt;br /&gt;
| Default International Prefix&lt;br /&gt;
| This is the international dialling prefix for phone numbers within your country. This usually consists of a plus &#039;+&#039; sign, along with two or three digits, and is used when dialling into your country from another location. This defaults to +44, the UK international dialling prefix. (&#039;&#039;&#039;Note:&#039;&#039;&#039; If the phone numbers you enter into MoodleTxt are already formatted internationally, e.g. +441234567890, then this setting is ignored.)&lt;br /&gt;
|-&lt;br /&gt;
| Phone_Number_Source&lt;br /&gt;
| Take phone numbers from&lt;br /&gt;
| This option allows you to choose the field in your user database table that MoodleTxt will search for mobile phone numbers (phone1 or phone2). This is largely redundant in modern Moodle setups, where phone2 has been standardised as the mobile phone field, and exists for long-running installations where things may be different. If mobile phone numbers are populated to the phone1 field in your system, then select it from this drop-down.&lt;br /&gt;
|-&lt;br /&gt;
| Default_Recipient_Name&lt;br /&gt;
| Default Recipient Name&lt;br /&gt;
| When Moodle cannot find a recipient&#039;s name in the database, or cannot match an incoming phone number to any known contact, this is the name/identifier it will record against that message.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Settings ===&lt;br /&gt;
&lt;br /&gt;
If connections between your MoodleTxt installation and ConnectTxt need to be routed via a proxy server, then you can enter the details of that proxy server in this section. &#039;&#039;&#039;Please note:&#039;&#039;&#039; MoodleTxt currently only supports proxy servers that use either BASIC authentication, or no authentication at all. Newer versions of Moodle have their own proxy settings within the system, and future versions of the block will migrate to use those settings for proxy support.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Host&lt;br /&gt;
| Proxy Address&lt;br /&gt;
| The host/IP address of your proxy server.&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Port&lt;br /&gt;
| Proxy Port&lt;br /&gt;
| The TCP/IP port your proxy server listens on for connections.&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Username&lt;br /&gt;
| Proxy Username&lt;br /&gt;
| If your proxy server requires a username for authentication, then enter it here (BASIC authentication only).&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Password&lt;br /&gt;
| Proxy Password&lt;br /&gt;
| If your proxy server requires a password for authentication, then enter it here (BASIC authentication only).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous Settings ===&lt;br /&gt;
&lt;br /&gt;
This section contains any other global settings for MoodleTxt that do not fall into one of the earlier categories.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| jQuery_Include_Enabled&lt;br /&gt;
| Include main jQuery package&lt;br /&gt;
| MoodleTxt uses the popular jQuery library within its user interface. Some Moodle installations already include this library within their active themes. If this is the case, then attempting to load both libraries can cause problems with the system. To turn off MoodleTxt&#039;s jQuery installation and have it use the one provided with your theme, uncheck this box. (&#039;&#039;&#039;Note:&#039;&#039;&#039; You will require at least jQuery 1.6 for this to work.)&lt;br /&gt;
|-&lt;br /&gt;
| jQuery_UI_Include_Enabled&lt;br /&gt;
| Include jQuery UI Library&lt;br /&gt;
| MoodleTxt uses the jQuery User Interface library for many common widgets/user interface components. Some Moodle installations already include this library within their active themes. If this is the case, then attempting to load both libraries can cause problems with the system. To turn off MoodleTxt&#039;s jQuery UI installation and have it use the one provided with your theme, uncheck this box. (&#039;&#039;&#039;Note:&#039;&#039;&#039; You will require at least jQuery UI 1.7 for this to work.)&lt;br /&gt;
|-&lt;br /&gt;
| Show_Inbound_Numbers&lt;br /&gt;
| Show source names/numbers in inbox (Default)&lt;br /&gt;
| In a classroom situation, such as a survey, where many people can see the messages that are coming into the system, you may wish to anonymise them by hiding the source of the messages. In current versions of MoodleTxt, inbound messages are anonymised by default. To show those message sources on inbox pages by default, then check this box. Since MoodleTxt 3.0, users can override these settings for their own inboxes, so this setting is now a default.&lt;br /&gt;
|-&lt;br /&gt;
| RSS_Update_Interval&lt;br /&gt;
| RSS Update Interval&lt;br /&gt;
| This setting controls how often MoodleTxt should check with the RSS feed on the ConnectTxt servers for new updates. (This is being retired, as Moodle 2.3 and up can find updates automatically.)&lt;br /&gt;
|-&lt;br /&gt;
| RSS_Expiry_Length&lt;br /&gt;
| RSS items expire after&lt;br /&gt;
| This setting controls how long an update notification from ConnectTxt should be displayed on the MoodleTxt admin panel. (This is being retired, as Moodle 2.3 and up can find updates automatically.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Settings]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=admin/setting/blocksettingmoodletxt&amp;diff=96118</id>
		<title>admin/setting/blocksettingmoodletxt</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=admin/setting/blocksettingmoodletxt&amp;diff=96118"/>
		<updated>2012-11-01T10:18:29Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Documentation for the main admin settings page in MoodleTxt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt Settings ==&lt;br /&gt;
&lt;br /&gt;
This page contains all the common configuration options for MoodleTxt. At the top of the page you will see two links:&lt;br /&gt;
&lt;br /&gt;
; ConnectTxt Accounts : This link will take you to the ConnectTxt account admin pages, which will allow you to add, update and restrict these accounts. If you have just installed MoodleTxt, this should be your first stop.&lt;br /&gt;
; Inbound Message Filters : This link will take you to the inbound filter management page, which will allow you to create filters for inbound SMS messages, routing them to particular Moodle users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Send/Receive Settings ===&lt;br /&gt;
&lt;br /&gt;
The first 4 settings in this section relate to how MoodleTxt gets both message status updates and new inbound messages from the ConnectTxt system. By default, MoodleTxt pulls these updates on a per-request basis, whenever users visit certain pages. However, it can be configured to get these updates automatically, which improves the performance of the block and results in far fewer outbound connections. The available automatic update methods are [[Moodletxt_cron | cron]] and [[Moodletxt_push | push]]. We &#039;&#039;&#039;highly&#039;&#039;&#039; recommend taking the time to set up push functionality, as it is the fastest and most efficient method of obtaining updates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Get_Status_On_View&lt;br /&gt;
| Automatically get status updates on &amp;quot;View Message&amp;quot; page&lt;br /&gt;
| If this box is checked, then whenever a user views the current status of a sent message, the block will first connect to the ConnectTxt system in order to fetch updates. You should uncheck this if you have configured an automatic update option as mentioned above.&lt;br /&gt;
|-&lt;br /&gt;
| Get_Inbound_On_View&lt;br /&gt;
| Automatically get inbound messages on Inbox page&lt;br /&gt;
| If this box is checked, then whenever a user views their inbox, the block will first connect to the ConnectTxt system in order to fetch new messages. You should uncheck this if you have configured an automatic update option as mentioned above.&lt;br /&gt;
|-&lt;br /&gt;
| Push_Username&lt;br /&gt;
| XML Push Username&lt;br /&gt;
| If you have set up XML push updates (highly recommended) then this is the username you provided to ConnectTxt as part of that setup. ConnectTxt uses this username to authenticate itself with your MoodleTxt installation when connecting to it.&lt;br /&gt;
|-&lt;br /&gt;
| Push_Password&lt;br /&gt;
| XML Push Password&lt;br /&gt;
| If you have set up XML push updates (highly recommended) then this is the password you provided to ConnectTxt as part of that setup. ConnectTxt uses this password to authenticate itself with your MoodleTxt installation when connecting to it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The last two settings in this category control other parameters related to message sending via ConnectTxt.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Protocol_Warnings_On&lt;br /&gt;
| Display SSL security warnings&lt;br /&gt;
| If you do not have SSL connections to the ConnectTxt server enabled, MoodleTxt will generally display warnings that your data is being transmitted in an unsecure manner. To disable these warnings, uncheck this box.&lt;br /&gt;
|-&lt;br /&gt;
| Event_Messaging_Account&lt;br /&gt;
| Event Messaging Account&lt;br /&gt;
| This is the ConnectTxt account that MoodleTxt will use when it is asked to send automatic messages out in response to system events. By extension, this is the ConnectTxt account that will be used to send any messages originating via the MoodleTxt Plus message processor plugin. If no account is selected, then MoodleTxt will be unable to send event-generated messages.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Recipient Settings ===&lt;br /&gt;
&lt;br /&gt;
The settings in this section relate to how MoodleTxt captures user phone/name information from the Moodle system, and how it processes that information in order to send SMS messages out. (Future versions of the block will feature improvements in international phone number handling.)&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| National_Prefix&lt;br /&gt;
| National Prefix&lt;br /&gt;
| This is the default dialling prefix for phone numbers within your country. It is the digit or set of digits that all phone numbers begin with when being dialled within the country. This defaults to 0, the UK domestic dialling prefix. (&#039;&#039;&#039;Note:&#039;&#039;&#039; If the phone numbers you enter into MoodleTxt are already formatted internationally, e.g. +441234567890, then this setting is ignored.)&lt;br /&gt;
|-&lt;br /&gt;
| Default_International_Prefix&lt;br /&gt;
| Default International Prefix&lt;br /&gt;
| This is the international dialling prefix for phone numbers within your country. This usually consists of a plus &#039;+&#039; sign, along with two or three digits, and is used when dialling into your country from another location. This defaults to +44, the UK international dialling prefix. (&#039;&#039;&#039;Note:&#039;&#039;&#039; If the phone numbers you enter into MoodleTxt are already formatted internationally, e.g. +441234567890, then this setting is ignored.)&lt;br /&gt;
|-&lt;br /&gt;
| Phone_Number_Source&lt;br /&gt;
| Take phone numbers from&lt;br /&gt;
| This option allows you to choose the field in your user database table that MoodleTxt will search for mobile phone numbers (phone1 or phone2). This is largely redundant in modern Moodle setups, where phone2 has been standardised as the mobile phone field, and exists for long-running installations where things may be different. If mobile phone numbers are populated to the phone1 field in your system, then select it from this drop-down.&lt;br /&gt;
|-&lt;br /&gt;
| Default_Recipient_Name&lt;br /&gt;
| Default Recipient Name&lt;br /&gt;
| When Moodle cannot find a recipient&#039;s name in the database, or cannot match an incoming phone number to any known contact, this is the name/identifier it will record against that message.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Settings ===&lt;br /&gt;
&lt;br /&gt;
If connections between your MoodleTxt installation and ConnectTxt need to be routed via a proxy server, then you can enter the details of that proxy server in this section. &#039;&#039;&#039;Please note:&#039;&#039;&#039; MoodleTxt currently only supports proxy servers that use either BASIC authentication, or no authentication at all. Newer versions of Moodle have their own proxy settings within the system, and future versions of the block will migrate to use those settings for proxy support.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Host&lt;br /&gt;
| Proxy Address&lt;br /&gt;
| The host/IP address of your proxy server.&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Port&lt;br /&gt;
| Proxy Port&lt;br /&gt;
| The TCP/IP port your proxy server listens on for connections.&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Username&lt;br /&gt;
| Proxy Username&lt;br /&gt;
| If your proxy server requires a username for authentication, then enter it here (BASIC authentication only).&lt;br /&gt;
|-&lt;br /&gt;
| Proxy_Password&lt;br /&gt;
| Proxy Password&lt;br /&gt;
| If your proxy server requires a password for authentication, then enter it here (BASIC authentication only).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous Settings ===&lt;br /&gt;
&lt;br /&gt;
This section contains any other global settings for MoodleTxt that do not fall into one of the earlier categories.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field Name&lt;br /&gt;
! Field Label&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| jQuery_Include_Enabled&lt;br /&gt;
| Include main jQuery package&lt;br /&gt;
| MoodleTxt uses the popular jQuery library within its user interface. Some Moodle installations already include this library within their active themes. If this is the case, then attempting to load both libraries can cause problems with the system. To turn off MoodleTxt&#039;s jQuery installation and have it use the one provided with your theme, uncheck this box. (&#039;&#039;&#039;Note:&#039;&#039;&#039; You will require at least jQuery 1.6 for this to work.)&lt;br /&gt;
|-&lt;br /&gt;
| jQuery_UI_Include_Enabled&lt;br /&gt;
| Include jQuery UI Library&lt;br /&gt;
| MoodleTxt uses the jQuery User Interface library for many common widgets/user interface components. Some Moodle installations already include this library within their active themes. If this is the case, then attempting to load both libraries can cause problems with the system. To turn off MoodleTxt&#039;s jQuery UI installation and have it use the one provided with your theme, uncheck this box. (&#039;&#039;&#039;Note:&#039;&#039;&#039; You will require at least jQuery UI 1.7 for this to work.)&lt;br /&gt;
|-&lt;br /&gt;
| Show_Inbound_Numbers&lt;br /&gt;
| Show source names/numbers in inbox (Default)&lt;br /&gt;
| In a classroom situation, such as a survey, where many people can see the messages that are coming into the system, you may wish to anonymise them by hiding the source of the messages. In current versions of MoodleTxt, inbound messages are anonymised by default. To show those message sources on inbox pages by default, then check this box. Since MoodleTxt 3.0, users can override these settings for their own inboxes, so this setting is now a default.&lt;br /&gt;
|-&lt;br /&gt;
| RSS_Update_Interval&lt;br /&gt;
| RSS Update Interval&lt;br /&gt;
| This setting controls how often MoodleTxt should check with the RSS feed on the ConnectTxt servers for new updates. (This is being retired, as Moodle 2.3 and up can find updates automatically.)&lt;br /&gt;
|-&lt;br /&gt;
| RSS_Expiry_Length&lt;br /&gt;
| RSS items expire after&lt;br /&gt;
| This setting controls how long an update notification from ConnectTxt should be displayed on the MoodleTxt admin panel. (This is being retired, as Moodle 2.3 and up can find updates automatically.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[:Category:MoodleTxt | View all MoodleTxt documentation]]&lt;br /&gt;
[[Category:MoodleTxt|Settings]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-sent-user-list.png&amp;diff=96117</id>
		<title>File:moodletxt-sent-user-list.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-sent-user-list.png&amp;diff=96117"/>
		<updated>2012-11-01T10:14:25Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the user selection list on the MoodleTxt sent message page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the user selection list on the MoodleTxt sent message page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-sent-type-list.png&amp;diff=96116</id>
		<title>File:moodletxt-sent-type-list.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-sent-type-list.png&amp;diff=96116"/>
		<updated>2012-11-01T10:05:58Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: MoodleTxt screenshot showing the message type selector on the sent messages screen.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MoodleTxt screenshot showing the message type selector on the sent messages screen.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/sent&amp;diff=96115</id>
		<title>blocks/moodletxt/sent</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/sent&amp;diff=96115"/>
		<updated>2012-11-01T10:04:50Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of the documentation for the sent message listing page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Sent Message Listing ==&lt;br /&gt;
&lt;br /&gt;
This page lists all the messages sent out by the existing Moodle user, as well as (if you have the right permissions enabled) all messages sent out by other Moodle users. Some general statistics regarding messages sent are shown at the top left of the page. The sent message listing contains the following columns:&lt;br /&gt;
&lt;br /&gt;
; User Account : The name of the Moodle user that sent this message out. Clicking on the linked username within this column will take you to that user&#039;s Moodle profile page.&lt;br /&gt;
&lt;br /&gt;
; ConnectTxt Account : The ConnectTxt account through which this message was sent.&lt;br /&gt;
&lt;br /&gt;
; Message Text : A shortened summary of the message sent. Clicking on this text summary will take you to [[blocks/moodletxt/status|a page detailing its current status]].&lt;br /&gt;
&lt;br /&gt;
; Time Sent : The time at which this message was sent from the system, adjusted to your timezone.&lt;br /&gt;
&lt;br /&gt;
; Created by : Whether the message was written by the user or [[#event_gen|generated by a system event]]. (Only displayed when you have selected to view event-generated messages alongside your own created messages.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The listing table can be edited and re-ordered like any other Moodle data table. Once you are happy with the data currently onscreen, you can also export it to a spreadsheet or similar file using the download options at the bottom of the table. Simply select the type of export you would like from the provided drop-down list, and then click the download button.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span id=&amp;quot;event_gen&amp;quot;&amp;gt;Viewing Event-Generated Messages&amp;lt;/span&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
As of MoodleTxt 3, messages can be generated by system events (such as those arriving via MoodleTxt Plus), as well as by the user. These messages are recorded like any other message, but are hidden on the sent message listing by default. If you wish to view any event-generated messages that have been sent out automatically from your account to another user, then you can enable them using the drop-down box at the top left of the screen.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-sent-type-list.png|frame|center|Allows you to show or hide event-generated messages.]]&lt;br /&gt;
&lt;br /&gt;
The options in this drop-down box are pretty self-explanatory. You can opt to either hide all event-generated messages (the default option), show the event-generated messages inline with your other sent messages, or show the event-generated messages on their own. If you decide to show event-generated messages alongside your own user-created messages, then an additional column is displayed showing whether the message was written by the user or generated by an event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Viewing Other User&#039;s Messages ===&lt;br /&gt;
&lt;br /&gt;
If you have the correct [[Moodletxt_capabilities|user capabilities]] assigned, you can view messages sent out by other users within the system. An additional drop-down box will be displayed at the top left of the page:&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-sent-user-list.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
Select the user you wish to view, and the page will reload with that user&#039;s messages listed. Alternatively, you can select &amp;quot;All Users&amp;quot; to view every message sent out via your MoodleTxt installation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Sent]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-counters.png&amp;diff=96114</id>
		<title>File:moodletxt-compose-counters.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-counters.png&amp;diff=96114"/>
		<updated>2012-11-01T09:55:08Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the message character counters on the MoodleTxt compose page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the message character counters on the MoodleTxt compose page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-recipient-selectors.png&amp;diff=96113</id>
		<title>File:moodletxt-compose-recipient-selectors.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-recipient-selectors.png&amp;diff=96113"/>
		<updated>2012-11-01T09:53:21Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Recipient selector buttons on the MoodleTxt compose page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Recipient selector buttons on the MoodleTxt compose page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-recipient-lists.png&amp;diff=96112</id>
		<title>File:moodletxt-compose-recipient-lists.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-recipient-lists.png&amp;diff=96112"/>
		<updated>2012-11-01T09:51:30Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the &amp;quot;potential&amp;quot; and &amp;quot;selected&amp;quot; recipient lists on the MoodleTxt compose page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the &amp;quot;potential&amp;quot; and &amp;quot;selected&amp;quot; recipient lists on the MoodleTxt compose page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-nav.png&amp;diff=96111</id>
		<title>File:moodletxt-compose-nav.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-nav.png&amp;diff=96111"/>
		<updated>2012-11-01T09:36:12Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: A screenshot of the navigation tabs in MoodleTxt&amp;#039;s compose page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A screenshot of the navigation tabs in MoodleTxt&#039;s compose page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/send&amp;diff=96110</id>
		<title>blocks/moodletxt/send</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/send&amp;diff=96110"/>
		<updated>2012-10-31T23:49:07Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Documentation for the compose page in&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Sending a Message via MoodleTxt ==&lt;br /&gt;
&lt;br /&gt;
This page will run you through the process of sending out a message from the MoodleTxt compose page. Given the wide number of options that MoodleTxt provides for outbound messaging, this page is designed as a wizard, to easily section off the various stages of composing a new message. You can move forwards and backwards through the steps of the wizard by clicking on their titles at the top of the form.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-nav.png|frame|center|The compose wizard is organised into 4 steps. Click on a step to zoom to it]]&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Recipients ===&lt;br /&gt;
&lt;br /&gt;
Firstly, you must select the recipients for the message.  You may send a text message to one or more individuals, to a pre-defined group of users/contacts, to additional recipients you specify on the page, or any combination of the three. &lt;br /&gt;
&lt;br /&gt;
On the left of the screen you will see the &amp;quot;Potential Recipients&amp;quot; list. This list holds all the recipients (of a given type) that were found in your Moodle system. These are the recipients that you can add to the message. On the right of the screen you will see the &amp;quot;Selected Recipients&amp;quot; list. Any recipient that is in this list when the form is submitted will receive the message. &lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-recipient-lists.png|frame|center|The &amp;quot;potential&amp;quot; and &amp;quot;selected&amp;quot; recipient lists for MoodleTxt. Clicking the &amp;gt;&amp;gt; and &amp;lt;&amp;lt; buttons will add or remove selected recipients to/from the message.]]&lt;br /&gt;
&lt;br /&gt;
To add a recipient to the message, find them in the list on the left, select them, and click the button with the right-facing arrows (&amp;gt;&amp;gt;). The recipient will move across to the selected list. To remove them from the message, click the button with the left-facing arrows (&amp;lt;&amp;lt;). The recipient will be removed from the selected list, and reappear in the potential list on the left; they will no longer receive a copy of the message.&lt;br /&gt;
&lt;br /&gt;
You will notice that the recipients you are selecting are colour-coded. These colours designate the type of recipient that you are selecting. Underneath the two lists you will notice a number of coloured buttons: &amp;quot;Users&amp;quot;, &amp;quot;User Groups&amp;quot;, &amp;quot;Addressbook Contacts&amp;quot;, &amp;quot;Addressbook Groups&amp;quot;. Users are the user accounts and user groups defined in your Moodle installation.  Address Books contain the contacts and groups you define within MoodleTxt.  Click on one of these buttons to display the appropriate contact list.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-recipient-selectors.png|frame|center|Clicking on one of these colour-coded buttons displays the appropriate contacts in the &amp;quot;Potential Recipients&amp;quot; list]]&lt;br /&gt;
&lt;br /&gt;
(To select more than one contact from a list, hold down CTRL on Windows/Linux, or the Apple/cloverleaf key on a Mac, and click on each contact. You can also select a group of sequential contacts by clicking on the first contact, then holding the SHIFT key and selecting a contact further up/down the list.  This will select every contact in a range.)&lt;br /&gt;
&lt;br /&gt;
Finally, if you wish to add recipients to the message that are not already stored within Moodle or MoodleTxt, you can use the &amp;quot;Add Additional Contact&amp;quot; form, which you will find underneath the recipient lists at the bottom of the slide.  Enter the contact&#039;s first name, last name and phone number in the appropriate boxes, and click the “Add Contact” button.  The new contact will be added to the “Selected Recipients” list on the right of the page.&lt;br /&gt;
&lt;br /&gt;
 Any contacts you added from the “Additional Recipients” form will be destroyed when removed from the &amp;quot;Selected Recipients&amp;quot; list.&lt;br /&gt;
&lt;br /&gt;
Once you are satisfied with your recipient selections, click on &amp;quot;Step 2&amp;quot; in the navigation bar at the top, and you&#039;ll be taken to the Compose Message screen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compose Message ===&lt;br /&gt;
&lt;br /&gt;
On this slide of the wizard, you will compose the actual message that is to be sent out to course participants. You can utilise pre-saved [[blocks/moodletxt/preferences|templates]] for sending out commonly used messages/notices, or write the message free-hand. You can also customise the message by merging in the recipient&#039;s name, and sign it with your own custom [[blocks/moodletxt/preferences|signature]].&lt;br /&gt;
&lt;br /&gt;
Inside the large textbox marked &amp;quot;Message&amp;quot;, please type your intended text message.  As you type, you should see the number of characters you have used displayed directly above the message box, along with the number of individual SMS messages your text will be broken into.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-counters.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
If you wish to use a pre-defined message template, select it from the drop-down list marked “Message Templates”, and it will automatically fill the textbox with the template for you. Message length counters will update automatically.  If you wish to add your own customised signature to the message, checking the &amp;quot;Add Signature&amp;quot; checkbox will append your signature to the end of the message in the textbox.  &lt;br /&gt;
&lt;br /&gt;
Also, underneath the message text box. you will find three buttons, labelled &amp;quot;First Name,&amp;quot; &amp;quot;Last Name,&amp;quot; and &amp;quot;Full Name.&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-tag-buttons.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
Clicking on any of these buttons will insert a &amp;quot;tag&amp;quot; into the message.  This tag will be automatically replaced, for each recipient, with the appropriate name, allowing you to add a personal touch to the message.  For example:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Hello %FIRSTNAME%, welcome to DMU.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Will be converted automatically to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Hello Jaime, welcome to DMU.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Unicode Messages ====&lt;br /&gt;
&lt;br /&gt;
If you use any characters that do not fit within the standard [http://en.wikipedia.org/wiki/GSM_03.38 GSM alphabet] used by SMS messages, then these will be sent as Unicode messages. This does not affect message delivery in any way, but it does reduce the number of characters allowed per message from 160 to 70. MoodleTxt checks your text automatically as you type, and if you use characters that require a Unicode message, then a warning message will be displayed below the textbox. The &amp;quot;characters per message&amp;quot; field will also change to 70 to reflect this, and &amp;quot;characters/messages used&amp;quot; will be recalculated according to the new message length.&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Message Options ===&lt;br /&gt;
&lt;br /&gt;
This step of the wizard allows you to schedule a message to be delivered at a later date, along with any other options that relate to message delivery.&lt;br /&gt;
&lt;br /&gt;
==== Unicode Messaging Options ====&lt;br /&gt;
&lt;br /&gt;
Firstly, if your message contains unicode message characters, as detailed above, you can opt to disable these characters in the outgoing message. If you decide to suppress these characters in the message, they may appear garbled on the recipient&#039;s phone (though the rest of the message should appear OK). However, doing so will restore the 160 character length of the message, and remove the restriction to 70 characters that unicode messages normally have.&lt;br /&gt;
&lt;br /&gt;
To suppress unicode characters, select &amp;quot;Restrict message to GSM character set only&amp;quot; in the first option set, under the heading &amp;quot;Unicode Messaging Options&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Scheduling ====&lt;br /&gt;
&lt;br /&gt;
To schedule your message for delivery at a later point, first you need to select the &amp;quot;Schedule to send later&amp;quot; option under the &amp;quot;Scheduling&amp;quot; heading. Once you have done this, select a time and date using the combo boxes provided. The date and time you enter is according to your own timezone on your Moodle user account; this will be converted automatically by MoodleTxt to Universal Time before sending.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Review &amp;amp; Send ===&lt;br /&gt;
&lt;br /&gt;
The final step of the wizard exists simply to allow you to review all the details of the message in one place, prior to it being sent. The recipients of the message are displayed, along with the message text, how many characters and messages per recipient will be used, and any unicode warnings that are relevant. Once you are happy with the information displayed on this last screen, click the &amp;quot;Send Message&amp;quot; button at the bottom to send the message to ConnectTxt.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Send]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Moodletxt_push&amp;diff=96109</id>
		<title>Moodletxt push</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Moodletxt_push&amp;diff=96109"/>
		<updated>2012-10-31T11:01:50Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: XML push documentation for MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt and Pushed Updates ==&lt;br /&gt;
&lt;br /&gt;
=== What is XML Push? ===&lt;br /&gt;
&lt;br /&gt;
For those MoodleTxt administrators whose Moodle installations are publicly accessible from outside their local network, ConnectTxt offers a free service that automatically sends updates to sent messages, along with any new inbound messages, directly to your MoodleTxt installation.  &lt;br /&gt;
&lt;br /&gt;
=== Why should I use it? ===&lt;br /&gt;
&lt;br /&gt;
XML Push updates are sent out as soon as they are received by the ConnectTxt system. As a result, this solution provides the quickest and most convenient update of message status records, and ensures that the information contained within your installation is up-to-date and useful. It also provides a performance boost for your MoodleTxt installation, as once XML Push is enabled you can disable the default update methods within MoodleTxt.&lt;br /&gt;
&lt;br /&gt;
=== Information required for setup ===&lt;br /&gt;
&lt;br /&gt;
To use XML Push, please first ensure that you are certain of the URL (web address) for your your Moodle installation.  Beneath this, the XML Push script is located at “/blocks/moodletxt/push.php.”  For example, if your URL for Moodle is normally:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;https://www.yoursite.com/moodle&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then the path to XML Push will be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;https://www.yoursite.com/moodle/blocks/moodletxt/push.php&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have made a note of this URL, you must decide on a username and password for ConnectTxt to use to authenticate themselves on your installation.  This username is used so that only ConnectTxt may send data through to your system, and helps to keep your installation secure – if the correct username and password are not supplied, XML Push simply shuts itself down, not accepting any further data.&lt;br /&gt;
&lt;br /&gt;
When you have decided on a username and password for XML Push to use, please save them in [[admin/setting/blocksettingmoodletxt|MoodleTxt&#039;s system settings]] to enable the XML Push system.&lt;br /&gt;
&lt;br /&gt;
=== Passing information to ConnectTxt ===&lt;br /&gt;
&lt;br /&gt;
Now you should have all the information necessary to activate XML Push with ConnectTxt.  Please contact the ConnectTxt support team (using the contact information displayed at the end of this document) with:&lt;br /&gt;
&lt;br /&gt;
# A list of all the ConnectTxt accounts that will need to be enabled for use with XML Push (this is normally a list of all the accounts stored in MoodleTxt).&lt;br /&gt;
# The URL path to XML Push on your installation.&lt;br /&gt;
# The XML Push username and password you defined above and stored on the setting screen.&lt;br /&gt;
&lt;br /&gt;
ConnectTxt will then activate your account(s) for use with XML Push.  This process is normally completed quickly, but can take up to 24 hours.&lt;br /&gt;
&lt;br /&gt;
=== After setup ===&lt;br /&gt;
&lt;br /&gt;
If your change your XML Push username or password in the future, or add/remove any ConnectTxt accounts from the MoodleTxt system, please notify ConnectTxt of any changes that need to be made.&lt;br /&gt;
&lt;br /&gt;
Once you have configured cron according to your needs, it is wise to turn off the per-request updates from the [[admin/setting/blocksettingmoodletxt|MoodleTxt Settings page]]. (These are the Get_Status_On_View and  Get_Inbound_On_View settings.) These will no longer be needed, and you will gain a performance boost by disabling them.&lt;br /&gt;
&lt;br /&gt;
=== ConnectTxt Contact Details ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Telephone : +44 (0) 113 234 2111&lt;br /&gt;
; E-mail : txttoolssupport@blackboard.com&lt;br /&gt;
; Live Chat : [http://messenger.providesupport.com/messenger/txttools.html Click here to chat live with our support team].&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Push Updates]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/preferences&amp;diff=96108</id>
		<title>blocks/moodletxt/preferences</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/preferences&amp;diff=96108"/>
		<updated>2012-10-31T10:54:06Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Documentation for preferences page in MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt User Preferences ==&lt;br /&gt;
&lt;br /&gt;
On this page of the block, you can configure your user-specific preferences. These include your message templates, SMS signature, and various other options that relate to how you use the messaging block.&lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
A message signature is a short piece of text (up to 25 characters) that you can optionally append to the end of your outgoing messages within MoodleTxt. This signature is useful for identifying yourself to the recipient, or for including common reply information (such as &amp;quot;reply with keyword BEN&amp;quot;). If you already have a message signature stored within MoodleTxt, it will appear in the textbox labelled &amp;quot;signature&amp;quot;, otherwise this block will be blank. To edit your signature, simply enter the text you would like to use in this box. You will notice the character counter above it decreasing from 25 towards 0 as you type, indicating the number of usable characters you have remaining. Once you hit 25 characters, you will be unable to type any further.&lt;br /&gt;
&lt;br /&gt;
When you are happy with your signature text, click the &amp;quot;Save&amp;quot; button at the bottom of the page. The page will refresh, and you should receive a short notification that the signature text has been updated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Message Templates ===&lt;br /&gt;
&lt;br /&gt;
Message templates can be used to store and re-use commonly sent messages, making sending these messages quick and easy. Templates can be selected from the [[blocks/moodletxt/send|message composition page]], instead of filling in the message text by hand, and can contain any text that a regular message can.&lt;br /&gt;
&lt;br /&gt;
You will notice two sections on the page, &#039;&#039;&#039;My Message Templates&#039;&#039;&#039; and &#039;&#039;&#039;Add New Template&#039;&#039;&#039;. The first of these lists all your existing message templates (if you have any), and allows you to select them for editing or deletion. The second section contains a text area in which you can add a new template to the system, or edit one you have selected from the existing list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adding a New Template ===&lt;br /&gt;
&lt;br /&gt;
To add a new template, click inside the box labelled &amp;quot;Template Text&amp;quot;, and enter your message.  As you type, you should see the number of characters you have used displayed directly above the message box, along with the number of individual SMS messages your text will be broken into. For example, the display &#039;&#039;&#039;172 / 2&#039;&#039;&#039; means you have used 172 characters, and that this will be split into two messages when sent. &lt;br /&gt;
&lt;br /&gt;
Also, underneath the message text box. you will find three buttons, labelled &amp;quot;First Name,&amp;quot; &amp;quot;Last Name,&amp;quot; and &amp;quot;Full Name.&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-compose-tag-buttons.png|border|center]]&lt;br /&gt;
&lt;br /&gt;
Clicking on any of these buttons will insert a &amp;quot;tag&amp;quot; into the message.  This tag will be automatically replaced, for each recipient, with the appropriate name, allowing you to add a personal touch to the message.  For example:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Hello %FIRSTNAME%, welcome to DMU.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Will be converted automatically to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Hello Jaime, welcome to DMU.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are satisfied with the text in the template editing box, click the &amp;quot;Save&amp;quot; button at the bottom of the page. The page will refresh, and you should see a short notice at the top of the screen indicating that the template has been saved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Editing an Existing Template ===&lt;br /&gt;
&lt;br /&gt;
To edit a template that has already been saved in the MoodleTxt block, go to the section headed &#039;&#039;&#039;My Message Templates&#039;&#039;&#039;. Select the template you wish to edit from the list and click the &amp;quot;Edit Template&amp;quot; button below it. The &#039;&#039;&#039;Add New Template&#039;&#039;&#039; section will be retitled to &#039;&#039;&#039;Edit Existing Template&#039;&#039;&#039;, and your template will appear in the editing box. You can now make your desired changes to it, exactly as if you were adding a new template to the system. When you are satisfied with your changes, click the &amp;quot;Save&amp;quot; button at the bottom of the page. The page will refresh, and you should see a short notice at the top of the screen indicating that the template has been updated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Deleting a Template ===&lt;br /&gt;
&lt;br /&gt;
To remove a template from MoodleTxt, go to the section headed &#039;&#039;&#039;My Message Templates&#039;&#039;&#039;. Select the template you wish to delete from the list and click the &amp;quot;Delete Template&amp;quot; button below it. A confirmation message will be displayed over the page. If you are happy to delete the template, click the &amp;quot;OK&amp;quot; button. The page will refresh, and a short message should be displayed at the top of the screen, indicating that the template has been deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Inbox Preferences ===&lt;br /&gt;
&lt;br /&gt;
Several options exist that relate to how MoodleTxt displays messages in your [[blocks/moodletxt/received|inbox]], and these are listed here. Firstly, you can instruct MoodleTxt to hide the names and phone numbers of received messages within the inbox listing. This is useful in classroom or group situations, where you wish to receive feedback or opinions from a number of people whilst keeping their responses anonymous. With this box checked, MoodleTxt will hide sender information for these messages.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the option to determine how often MoodleTxt&#039;s dynamic inbox checks for new messages with the Moodle system. If you are on the [[blocks/moodletxt/received|inbox]] page, it will check with the database for new messages at the interval you set here. Please note that this is separate from checking with the ConnectTxt system for new messages, and will only pick up messages that have already been received by the Moodle system. Administrators wanting more information on how messages are received by MoodleTxt can find it in the documentation for the [[admin/setting/blocksettingmoodletxt|main settings page]].&lt;br /&gt;
&lt;br /&gt;
When you have edited your inbox preferences accordingly, click the &amp;quot;Save&amp;quot; button at the bottom of the page. The page will refresh, and you should see a short message at the top of the screen, indicating that your preferences have been updated.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Preferences]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-tag-buttons.png&amp;diff=96107</id>
		<title>File:moodletxt-compose-tag-buttons.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-compose-tag-buttons.png&amp;diff=96107"/>
		<updated>2012-10-31T10:52:54Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the MoodleTxt message tagging buttons.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the MoodleTxt message tagging buttons.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errornopermissionmessage&amp;diff=96106</id>
		<title>error/block moodletxt/errornopermissionmessage</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errornopermissionmessage&amp;diff=96106"/>
		<updated>2012-10-31T10:44:23Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Error documentation for when a user attempts to view someone else&amp;#039;s message in MoodleTxt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Attempting to Access a Message You Do Not Have Permission to View ==&lt;br /&gt;
&lt;br /&gt;
You have attempted to view the details of a sent message within MoodleTxt, and received the following message:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;You are not authorised to view this message.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cause ===&lt;br /&gt;
The message you have attempted to view does not belong to you, and you do not have the [[Moodletxt_capabilities|necessary access level]] to view another user&#039;s message details.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Error]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errornoaccountspresent&amp;diff=96105</id>
		<title>error/block moodletxt/errornoaccountspresent</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errornoaccountspresent&amp;diff=96105"/>
		<updated>2012-10-31T10:41:16Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Error documentation for when no ConnectTxt accounts have been linked to MoodleTxt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== No ConnectTxt Accounts Present Within MoodleTxt ==&lt;br /&gt;
&lt;br /&gt;
You have gone to the &amp;quot;Compose a Message&amp;quot; page within MoodleTxt, and received the error message:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;No ConnectTxt accounts have been added to moodletxt. The system administrator must link moodletxt to one or more ConnectTxt accounts before messages can be sent.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cause ===&lt;br /&gt;
MoodleTxt uses SMS messaging accounts on the [http://www.bbconnecttxt.com/ ConnectTxt] messaging system to send and receive SMS messages. Before MoodleTxt can be used to send out messages, one or more ConnectTxt accounts must be made available to you via MoodleTxt&#039;s control panel. &lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
Your system administrator must make one or more ConnectTxt accounts available for you to use.&lt;br /&gt;
&lt;br /&gt;
If you are the system administrator, then you can find out more information about how to do this in the [[admin/setting/blocksettingmoodletxt|MoodleTxt settings documentation]].&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Error]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errorbadmessageid&amp;diff=96104</id>
		<title>error/block moodletxt/errorbadmessageid</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errorbadmessageid&amp;diff=96104"/>
		<updated>2012-10-31T10:37:13Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Error documentation for invalid message IDs within MoodleTxt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Attempting to View a Message That Does Not Exist ==&lt;br /&gt;
&lt;br /&gt;
You have attempted to view a sent message within MoodleTxt, and received the error message:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The message ID given does not exist, or does not belong to the user ID found. Please select a valid message to view.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cause ===&lt;br /&gt;
There are several potential causes for this error:&lt;br /&gt;
&lt;br /&gt;
# The ID of the message you are attempting to view is incorrect. If you are copying and pasting a link to a message, please ensure that you have included all the page&#039;s parameters in the link.&lt;br /&gt;
# The message you are attempting to view no longer exists within the database.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Error]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errorbadbookid&amp;diff=96103</id>
		<title>error/block moodletxt/errorbadbookid</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=error/block_moodletxt/errorbadbookid&amp;diff=96103"/>
		<updated>2012-10-31T10:34:42Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Error documentation for invalid address book IDs within MoodleTxt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Attempting to View/Edit an Address Book That Is Not Yours ==&lt;br /&gt;
&lt;br /&gt;
You have attempted to view or edit a MoodleTxt addressbook, or the contacts within it, and received the error message:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The address book selected was invalid, or you do not own the address book you are attempting to edit.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cause ===&lt;br /&gt;
Address books created within MoodleTxt can only be edited by the user that created them, and in most cases this applies to viewing the address book also. You are attempting to edit an address book that you do not have ownership of, and as such MoodleTxt has blocked this action.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Error]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Moodletxt_cron&amp;diff=96102</id>
		<title>Moodletxt cron</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Moodletxt_cron&amp;diff=96102"/>
		<updated>2012-10-31T10:15:54Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Documentation for enabling cron updates within MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt Updates Via Cron ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== What is cron? ===&lt;br /&gt;
&lt;br /&gt;
; Cron job : The term generally used (in Unix circles) to refer to a user-defined script or program that is automatically run at regular intervals.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
MoodleTxt can optionally use a cron job to fetch regular updates from the ConnectTxt server, including new inbound messages, and status updates for previously sent messages.&lt;br /&gt;
&lt;br /&gt;
=== Why use cron? ===&lt;br /&gt;
&lt;br /&gt;
The recommended method of acquiring updates from the ConnectTxt system is [[Moodletxt_push|XML Push]]. However, this requires an inbound connection to your Moodle server. If you cannot configure this connection, but still wish to receive updates from the ConnectTxt system automatically, then you can use MoodleTxt&#039;s local cron job to automatically poll the ConnectTxt system for updates at regular intervals. This is much more efficient than the default update settings (where checks are made when certain pages are loaded) and will result in a performance increase for MoodleTxt.&lt;br /&gt;
&lt;br /&gt;
=== Automatic Setup ===&lt;br /&gt;
&lt;br /&gt;
As of MoodleTxt 2.4, this cron script automatically adds itself to the main Moodle maintenance script, so if you already have this running at short, regular intervals, no action is required to enable cron – MoodleTxt will automatically fetch inbound messages and status updates every time the Moodle maintenance script runs.&lt;br /&gt;
&lt;br /&gt;
=== Custom Setup ===&lt;br /&gt;
&lt;br /&gt;
If your Moodle maintenance script is not enabled, or does not run often enough for MoodleTxt use, you can still use cron to fetch message details.  MoodleTxt provides a script that is another entry point to the cron system, which you can set to run at shorter intervals separate from the Moodle maintenance script. The path to this script is “/blocks/moodletxt/cron.php”, under your main Moodle installation directory.  For example, if you have Moodle installed on Linux at:&lt;br /&gt;
&lt;br /&gt;
/srv/www/moodle/&lt;br /&gt;
&lt;br /&gt;
Then the path to the cron script would be:&lt;br /&gt;
&lt;br /&gt;
/srv/www/moodle/blocks/moodletxt/cron.php&lt;br /&gt;
&lt;br /&gt;
By specifying this file to be run in your chosen scheduling software, at an interval of your choosing, you can emulate the efficiency of the [[Moodletxt_push|XML Push]] service without changing your security configuration.&lt;br /&gt;
&lt;br /&gt;
=== Steps to Take After Setup ===&lt;br /&gt;
&lt;br /&gt;
Once you have configured cron according to your needs, it is wise to turn off the per-request updates from the [[admin/setting/blocksettingmoodletxt|MoodleTxt Settings page]]. (These are the Get_Status_On_View and  Get_Inbound_On_View settings.) These will no longer be needed, and you will gain a performance boost by disabling them.&lt;br /&gt;
&lt;br /&gt;
[[:Category:MoodleTxt | View all MoodleTxt documentation]]&lt;br /&gt;
[[Category:MoodleTxt|Cron]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Moodletxt_capabilities&amp;diff=96101</id>
		<title>Moodletxt capabilities</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Moodletxt_capabilities&amp;diff=96101"/>
		<updated>2012-10-31T10:11:50Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Detailed listing of all capabilities installed by MoodleTxt.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== List of all capabilities installed by MoodleTxt ==&lt;br /&gt;
&lt;br /&gt;
This page is an administrator&#039;s reference for the user capabilities that will be installed into your Moodle installation by MoodleTxt. You can use these to grant or deny access to the various sections of MoodleTxt using these capabilities in the standard Moodle control panel.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Capability Name&lt;br /&gt;
! Default Assignment&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:addressbooks&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| Granting this permission allows a user to create addressbooks within MoodleTxt&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:adminsettings&lt;br /&gt;
| Admins only&lt;br /&gt;
| Allows a user to use the MoodleTxt control panel and see error messages intended for administrators.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:adminusers&lt;br /&gt;
| Admins only&lt;br /&gt;
| Allows a user to admin user information within MoodleTxt, such as editing a user&#039;s message filters, or viewing their message history.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:defaultinbox&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| If a user has this capability assigned to them at system level, then they can be selected as the &amp;quot;default inbox&amp;quot; when creating message filters. (A default inbox is where any unfiltered messages for a given account are deposited.)&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:globaladdressbooks&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| If this user can create address books within MoodleTxt, they can create global address books that can be viewed and used by all users within the system.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:personalsettings&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| Having this capability assigned to a user allows them to edit their own messaging preferences. This includes message templates and signatures, as well as options related to message display.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:receivemessages&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| Any user that has this capability assigned can receive inbound messages within the block.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:sendmessages&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| Any user that has this capability assigned can send messages out from the block.&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:viewstats&lt;br /&gt;
| Teachers and admins&lt;br /&gt;
| Any user that has this capability assigned can view user/message statistics. (Coming in 3.1)&lt;br /&gt;
|-&lt;br /&gt;
| block/moodletxt:viewmoodletxtpluslogs&lt;br /&gt;
| Admins only&lt;br /&gt;
| Allows the user to view the logs of event-based messaging. (Largely redundant, may be removed in 3.1. Users that have the :adminusers permission can use the sent page, which was upgraded since 3.0 beta 2, to view these logs already.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Capabilities]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbooks&amp;diff=96100</id>
		<title>blocks/moodletxt/addressbooks</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbooks&amp;diff=96100"/>
		<updated>2012-10-31T09:59:12Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of documentation for MoodleTxt&amp;#039;s addressbook management page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MoodleTxt: Managing Address Books ==&lt;br /&gt;
&lt;br /&gt;
MoodleTxt allows you to create your own address books of contacts for sending messages to. These are generally contacts who do not have accounts within the Moodle system themselves, such as the parents of students.&lt;br /&gt;
&lt;br /&gt;
Your existing address books (if you have any) are displayed at the top of the page. Clicking on the name of an address book will open it for browsing and editing on another page. The icon next to an address book indicates whether it is a private or global addressbook.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-addressbook-icons.png|frame|none|Example of a global and private addressbook, with icons.]]&lt;br /&gt;
&lt;br /&gt;
; Private Address Books : These are address books visible only to you, and can only have messages sent to them from your account.&lt;br /&gt;
; Global Address Books : These are visible to all users within the Moodle system, and messages can be sent to them from anywhere. However, the address book can still only be edited/maintained by you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adding a New Address Book ===&lt;br /&gt;
&lt;br /&gt;
Adding a new address book to MoodleTxt is simple. Under the &#039;&#039;&#039;Add a new address book&#039;&#039;&#039; heading, type the name of the new address book into the box labelled &amp;quot;Address book name&amp;quot;. Below that, select whether you want the address book to be private (only usable by you) or global (usable by anyone). &lt;br /&gt;
&lt;br /&gt;
When you are happy with your selections, click the &amp;quot;Add&amp;quot; button below the form. The page will refresh, and your new address book should appear in the list at the top of the page, along with a short success message indicating that the address book was saved to the database successfully. You can now click into the address book and begin adding contacts to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Deleting an Existing Address Book ===&lt;br /&gt;
&lt;br /&gt;
This section allows you to permanently delete an address book from the MoodleTxt block, or optionally merge it into another existing address book.&lt;br /&gt;
&lt;br /&gt;
Firstly, select the address book you wish to delete from the first drop-down box in this section. Next, you have the option to either delete the contacts in the address book, or merge them into another one. If you select the first option, then when the address book is deleted, all contacts and contact groups within it will also be permanently deleted. If you select the second option, then when the address book is deleted, all of its contacts and groups will be moved into another address book within the system. In order to use this option, you must select the destination address book from the second drop-down list provided.&lt;br /&gt;
&lt;br /&gt;
Once you are happy with the options selected, click the &amp;quot;Delete/Merge&amp;quot; button below the form. The page will be refreshed, and your selected address book should have been removed from the list of existing address books at the top of the page. A short notification message should also be displayed, indicating that the address book was successfully deleted from the database.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Addressbooks]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-addressbook-icons.png&amp;diff=96099</id>
		<title>File:moodletxt-addressbook-icons.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-addressbook-icons.png&amp;diff=96099"/>
		<updated>2012-10-31T09:57:57Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of existing address books listed on the MoodleTxt addressbook management page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of existing address books listed on the MoodleTxt addressbook management page.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_view&amp;diff=96098</id>
		<title>blocks/moodletxt/addressbook view</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_view&amp;diff=96098"/>
		<updated>2012-10-31T09:46:21Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of documentation for MoodleTxt&amp;#039;s addressbook listing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Viewing a MoodleTxt Address Book ==&lt;br /&gt;
&lt;br /&gt;
This page exists displays all contacts available within the selected address book. It allows you to browse, edit and delete them, as well as export the list to a file for download. If you wish to add a new contact to the address book, or edit your address book&#039;s contact groups, two links to the pages that handle this functionality are available at the top-left of the page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Contact Listing ===&lt;br /&gt;
&lt;br /&gt;
The primary feature of this page is a listing of all contacts contained within the address book. The table of contacts shows the following fields:&lt;br /&gt;
&lt;br /&gt;
*Contact&#039;s first name&lt;br /&gt;
*Contact&#039;s last name&lt;br /&gt;
*Name of company (if contact is a company, or represents one)&lt;br /&gt;
*Contact&#039;s phone number&lt;br /&gt;
&lt;br /&gt;
The list displayed is a standard Moodle table, and can be re-ordered, edited and navigated like any other tabular list in Moodle.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Editing a Listed Contact ===&lt;br /&gt;
&lt;br /&gt;
MoodleTxt supports inline editing of the contacts displayed in the contact list. To edit a contact, simply double-click on it. The text row representing that contact will be automatically converted into a form.&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-addressbook-contact-edit.png|border|none]]&lt;br /&gt;
&lt;br /&gt;
You can then make the appropriate corrections to the contact directly within the listing. Once you are satisfied with your changes, click the &amp;quot;Save&amp;quot; button at the right of the contact row, and the contact will be saved back into the listing. Clicking &amp;quot;Cancel&amp;quot; will revert any changes and restore the contact&#039;s entry to its previous state.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Deleting One or More Contacts ===&lt;br /&gt;
&lt;br /&gt;
To delete contacts from your address book, first select them in the contact listing by checking the box at the left of each contact entry. (You can also select or deselect all contacts on the page by using the &amp;quot;Check all&amp;quot;/&amp;quot;Uncheck all&amp;quot; links at the bottom left of the table.) Once you have the contacts you wish to delete selected, click the &amp;quot;Delete the selected records&amp;quot; link underneath the contact listing, and the contacts will be removed from the address book.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if the set of contacts you wish to retain in the address book is smaller than the set you wish to delete, you can select the contacts you wish to keep, and then click the link labelled &amp;quot;Delete all records except those currently selected&amp;quot; underneath the contact listing. This will delete all contacts in the address book except for those that you have selected from the contact listing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Changing the Address Book&#039;s Name and Visibility ===&lt;br /&gt;
&lt;br /&gt;
If you wish to change the details of the address book, they are displayed as an inline form at the top-left of the page, just above the contact listing. Simply edit the address book&#039;s name and visibility level and click the &amp;quot;Save&amp;quot; button. The page will refresh, and a short notification should be displayed indicating that the address book&#039;s details were updated in the database.&lt;br /&gt;
&lt;br /&gt;
Possible visibility levels for the address book:&lt;br /&gt;
&lt;br /&gt;
; Private Address Books : These are address books visible only to you, and can only have messages sent to them from your account.&lt;br /&gt;
; Global Address Books : These are visible to all users within the Moodle system, and messages can be sent to them from anywhere. However, the address book can still only be edited/maintained by you.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Addressbook Listing]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-addressbook-contact-edit.png&amp;diff=96097</id>
		<title>File:moodletxt-addressbook-contact-edit.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-addressbook-contact-edit.png&amp;diff=96097"/>
		<updated>2012-10-31T09:45:33Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of a contact being edited in the MoodleTxt address book.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of a contact being edited in the MoodleTxt address book.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_groups&amp;diff=96096</id>
		<title>blocks/moodletxt/addressbook groups</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_groups&amp;diff=96096"/>
		<updated>2012-10-31T09:37:38Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of the MoodleTxt group management page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Managing your MoodleTxt Addressbook Groups ==&lt;br /&gt;
&lt;br /&gt;
This page consists of three forms, allowing you to add, edit and delete groups.&lt;br /&gt;
&lt;br /&gt;
=== Adding a Group ===&lt;br /&gt;
&lt;br /&gt;
Adding a group to the address book couldn&#039;t be simpler.  Locate the form at the top of the page headed &#039;&#039;&#039;Add a Group&#039;&#039;&#039;.  This form has a single text box for the name of the group.  Give the group a name, and then click the &amp;quot;Add Group&amp;quot; button, and the new contact group will be created.&lt;br /&gt;
&lt;br /&gt;
=== Updating Group Members ===&lt;br /&gt;
&lt;br /&gt;
If you wish to add or remove members from a group, first select the group you wish to modify from the large drop-down box at the top of the form labelled &#039;&#039;&#039;Update Group Members&#039;&#039;&#039;. When you have selected a group, you should see the form update, with the current group members being moved from the list of potential members on the left to the list of current members on the right (assuming that the group already has members).&lt;br /&gt;
&lt;br /&gt;
[[Image:moodletxt-group-member-selector.png|frame|center|Group membership selector]]&lt;br /&gt;
&lt;br /&gt;
To add contacts to the group, select them from the list of potential members on the left, and click the &amp;quot;&amp;gt;&amp;gt;&amp;quot; button.  You will see them move to the list of group members on the right.  To remove contacts from the group, select them from the right hand list and click the &amp;quot;&amp;lt;&amp;lt;&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
Once you are satisfied with the list of group members, click the &amp;quot;Update Group&amp;quot; button, and the group membership list will be updated. The page will refresh, and a short notification should be displayed indicating that the group has been saved to the database.&lt;br /&gt;
&lt;br /&gt;
=== Deleting Groups ===&lt;br /&gt;
&lt;br /&gt;
The first step to deleting a group is to select the one you wish to delete from the drop-down list at the top of the form labelled &#039;&#039;&#039;Delete a Group&#039;&#039;&#039;. (You&#039;ll find it at the bottom of the page.)&lt;br /&gt;
&lt;br /&gt;
When you have done this, you need to confirm what should happen to the contacts that are already in the group being deleted.  Three options are available, and are shown below the group list.  &lt;br /&gt;
&lt;br /&gt;
; Preserve Contacts : Will remove the group without affecting the contacts contained within it.&lt;br /&gt;
; Delete Contacts : This will remove the group and delete its members from the address book.  This is useful for erasing old classes/years from the book.  &lt;br /&gt;
; Merge Contacts : This will remove the group and transfer its contacts into another group, allowing you to merge groups together.  If you select this option, be sure to select a destination group from the drop-down list provided.&lt;br /&gt;
&lt;br /&gt;
Once you have decided what you want to happen to the group&#039;s members, click the &amp;quot;Delete Group&amp;quot; button and the group will be erased from the address book.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Addressbook Groups]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:moodletxt-group-member-selector.png&amp;diff=96095</id>
		<title>File:moodletxt-group-member-selector.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:moodletxt-group-member-selector.png&amp;diff=96095"/>
		<updated>2012-10-31T09:37:06Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Screenshot of the MoodleTxt group membership selector.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the MoodleTxt group membership selector.&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_contact_add&amp;diff=96094</id>
		<title>blocks/moodletxt/addressbook contact add</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/moodletxt/addressbook_contact_add&amp;diff=96094"/>
		<updated>2012-10-31T09:25:16Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of MoodleTxt &amp;quot;add contact&amp;quot; page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding a Contact to a MoodleTxt Address Book ==&lt;br /&gt;
&lt;br /&gt;
This page allows you to add a new contact to your address book. The first section allows you to enter some basic information about the contact:&lt;br /&gt;
&lt;br /&gt;
*Contact&#039;s first name&lt;br /&gt;
*Contact&#039;s last name&lt;br /&gt;
*Name of company (if contact is a company, or represents one)&lt;br /&gt;
*Contact&#039;s phone number&lt;br /&gt;
&lt;br /&gt;
=== Group Membership ===&lt;br /&gt;
&lt;br /&gt;
Any groups that already exist within your address book are displayed in the &amp;quot;Addressbook Groups&amp;quot; list on the left of the page. If you want to add this new contact to any of these groups, select them from the list on the left and click the &amp;gt;&amp;gt; button. This will move them to the list on the right hand side of the page. The new contact will be added to any groups that are shown in this list on the right when it is saved to the address book.&lt;br /&gt;
&lt;br /&gt;
=== Saving the Contact ===&lt;br /&gt;
&lt;br /&gt;
When you are satisfied with the details you have entered for the new contact, you have two options when saving it. You can either save the contact, and return to the address book&#039;s listing page, or you can clear the form to add another contact. Select the appropriate button from the bottom of the form, and the contact will be saved to the database.&lt;br /&gt;
&lt;br /&gt;
[[Category:MoodleTxt|Addressbook Add Contact]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Category:MoodleTxt&amp;diff=96093</id>
		<title>Category:MoodleTxt</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Category:MoodleTxt&amp;diff=96093"/>
		<updated>2012-10-31T09:19:53Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Initial commit of MoodleTxt category page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This category contains all documentation for the MoodleTxt 2-way SMS messaging block, provided and powered by [http://www.bbconnecttxt.com/ ConnectTxt]. It also contains information on the related messaging processor, MoodleTxt Plus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://moodle.org/plugins/view.php?plugin=block_moodletxt MoodleTxt block in the plugin repository]&lt;br /&gt;
&lt;br /&gt;
[https://moodle.org/plugins/view.php?plugin=message_moodletxtplus MoodleTxt+ message processor add-on in the plugin repository]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86652</id>
		<title>User:Greg Preece</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86652"/>
		<updated>2011-07-29T15:26:41Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Editing to match the /dev wiki&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Greg J Preece =&lt;br /&gt;
&lt;br /&gt;
Greg J Preece is a PHP developer, who develops and maintains the moodletxt SMS messaging block for Moodle.&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/user/view.php?id=146613 Greg&#039;s Moodle Profile]&lt;br /&gt;
&lt;br /&gt;
== Work and Contribs ==&lt;br /&gt;
&lt;br /&gt;
Greg contributes updates to the [[Blocks|Moodle blocks developer documentation]].&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=958&amp;amp;filter=1 moodletxt SMS block - Development and Maintenance]&lt;br /&gt;
&lt;br /&gt;
[http://www.txttools.co.uk/preloginjsp/txttools/developers.jsp txttools PHP API - Development and Maintenance]&lt;br /&gt;
&lt;br /&gt;
[http://www.txttools.co.uk txttools Homepage]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86488</id>
		<title>User:Greg Preece</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86488"/>
		<updated>2011-07-27T08:06:53Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Greg J Preece is a PHP developer, who develops and maintains the moodletxt SMS messaging block for Moodle. He also contributes to MoodleDocs when he can, and is currently re-writing the block developer documentation, based on his experiences with redeveloping moodletxt.&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/user/view.php?id=146613 Greg&#039;s Moodle Profile]&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=958&amp;amp;filter=1 moodletxt Block]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86487</id>
		<title>User:Greg Preece</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=86487"/>
		<updated>2011-07-27T08:06:29Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Greg J Preece is a PHP developer, who develops and maintains the moodletxt SMS messaging block for Moodle. He also contributes to MoodleDocs when he can, and is currently re-writing the block developer documentation, based on his experiences with redeveloping moodletxt.&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/user/view.php?id=146613|Greg&#039;s Moodle Profile]&lt;br /&gt;
&lt;br /&gt;
[http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=958&amp;amp;filter=1|moodletxt Block]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Installing_and_upgrading_plugin_database_tables&amp;diff=74902</id>
		<title>Development:Installing and upgrading plugin database tables</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Installing_and_upgrading_plugin_database_tables&amp;diff=74902"/>
		<updated>2010-08-18T10:08:51Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
If you have done the right thing, Moodle will automatically create the database tables for your plugin when you visit the Admin notifications page (.../admin/index.php). This process is controlled by three files within your plugin:&lt;br /&gt;
;version.php : This records the version of the plugin code (&#039;&#039;&#039;Please note:&#039;&#039;&#039; In Moodle installations below v2.0, this is not required for blocks, which use the version number returned by the block&#039;s init() method - see [[Development:Blocks#Ready.2C_Set.2C_Go.21|the blocks development page]])&lt;br /&gt;
;db/install.xml : This is used when someone installs your plugin for the first time.&lt;br /&gt;
;db/upgrade.php : This is used when someone who had an older version of your plugin installed upgrades to the latest version.&lt;br /&gt;
&lt;br /&gt;
In addition, Moodle also stores in the database the currently installed version of each plugin.&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9 and before, this is stored in the mdl_config table, in a row with the name &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version. For example qtype_myqtype_version. The exception to this rule are modules and blocks. Installed module version numbers are stored in the mdl_modules table. Block version numbers are in mdl_block.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 an beyond, plugin version numbers are stored in the mdl_config_plugins table, with &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039; in the plugin column, and &#039;version&#039; in the name column - with the same exception for modules and blocks.&lt;br /&gt;
&lt;br /&gt;
==A specific example==&lt;br /&gt;
&lt;br /&gt;
For the rest of this document, I will use a particular example, because it should make the explanation easier. You should be able to see how to generalise it.&lt;br /&gt;
&lt;br /&gt;
We will suppose you that you are making a new question type myqtype. This is plugin type qtype, and the code will be in the question/type/myqtype folder. The currently installed version number will be stored in the qtype_myqtype_version row of the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
In addition, we will just consider the first two releases of the plugin. The first release will have version number 2008080100, and will just use one database table mdl_question_myqtype, with two columns col1 and col2. Then we will suppose that the second release is 2008080200, and that requires an extra column, newcol, to be added to the mdl_question_myqtype table.&lt;br /&gt;
&lt;br /&gt;
==The files you need for the first release==&lt;br /&gt;
&lt;br /&gt;
In what follows, the bits of code you need to replace are &#039;&#039;&#039;in bold&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
;version.php&lt;br /&gt;
 $plugin-&amp;gt;version  = 2008080100;&lt;br /&gt;
 $plugin-&amp;gt;requires = &#039;&#039;&#039;XXXXXXXXXX; // Copy the current value from the top-level version.php file.&#039;&#039;&#039;&lt;br /&gt;
;db/install.xml&lt;br /&gt;
:This file, which you should [[XMLDB editor|create with the XMLDB editor]], should contain the definition for your mdl_question_myqtype table, with the two columns col1 and col2.&lt;br /&gt;
&lt;br /&gt;
At this stage, you do not need a db/upgrade.php file.&lt;br /&gt;
&lt;br /&gt;
==The files you need for the second release==&lt;br /&gt;
&lt;br /&gt;
;version.php&lt;br /&gt;
 $plugin-&amp;gt;version  = 2008080200;&lt;br /&gt;
 $plugin-&amp;gt;requires = &#039;&#039;&#039;XXXXXXXXXX; // Copy the current value from the top-level version.php file.&#039;&#039;&#039;&lt;br /&gt;
;db/install.xml : This file should now contain the updated definition for your mdl_question_myqtype table, with three columns col1, col2 and newcol. You modify this file using the XMLDB editor.&lt;br /&gt;
;db/upgrade.php&lt;br /&gt;
:This file should contain the code that people need to run to upgrade from version 2008080100 of your plugin. That is, the code to add a column newcol to the mdl_question_myqtype table. You don&#039;t have to write this code yourself as the XMLDB editor will generate it for you. The upgrade.php file should contain a single function xmldb_qtype_myqtype_upgrade that looks a bit like:&lt;br /&gt;
 function xmldb_qtype_myqtype_upgrade($oldversion = 0) {&lt;br /&gt;
     $result = true;&lt;br /&gt;
 &lt;br /&gt;
     /// Add a new column newcol to the mdl_question_myqtype&lt;br /&gt;
     if ($result &amp;amp;&amp;amp; $oldversion &amp;lt; 2008080200) {&lt;br /&gt;
         &#039;&#039;&#039;// Code to add the column, generated by the &#039;View PHP Code&#039; option of the XMLDB editor.&#039;&#039;&#039;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     return $result;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Hint: If you are modifying or adding a field/table, get the XMLDB editor to generate the PHP update code for you &#039;&#039;&#039;after&#039;&#039;&#039; making the changes in the editor. If you are deleting one, you need to generate the PHP code &#039;&#039;&#039;before&#039;&#039;&#039; making the change - or you won&#039;t be able to select the field/table to write the code for, because it no longer exists.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==What happens when a user installs or upgrades your plugin==&lt;br /&gt;
&lt;br /&gt;
The process is triggered when an administrator goes to the Admin notifications page (.../admin/index.php). The code that does the work is the upgrade_plugins function in lib/adminlib.php and reading this code is the best way to find out exactly what happens. In pseudo-code, what it does is:&lt;br /&gt;
&lt;br /&gt;
 For each plugin of this type (e.g. all qtype plugins) {&lt;br /&gt;
     // For the body of this loop, suppose the current plugin being processed is myqtype.&lt;br /&gt;
 &lt;br /&gt;
     Check that question/type/myqtype/version.php, .../db/upgrade.php and .../db/install.xml exist.&lt;br /&gt;
 &lt;br /&gt;
     if ($CFG-&amp;gt;qtype_myqtype_version exists, and is less than the number in version.php) {&lt;br /&gt;
         Call the upgrade function xmldb_qtype_myqtype_upgrade from&lt;br /&gt;
                 upgrade.php, passing the old version number ($CFG-&amp;gt;qtype_myqtype_version)&lt;br /&gt;
                 which says what is currently installed&lt;br /&gt;
         Update $CFG-&amp;gt;qtype_myqtype_version to the latest number from version.php&lt;br /&gt;
                 to record what is currently installed&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     else if ($CFG-&amp;gt;qtype_myqtype_version does not exist) {&lt;br /&gt;
         Create the tables from the definitions in install.xml&lt;br /&gt;
         Update $CFG-&amp;gt;qtype_myqtype_version to the latest number from version.php&lt;br /&gt;
                 to record what is currently installed&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Of course, it is a bit more complex that than. However, the code in the upgrade_plugins is quite clear, and I encourage you to go and have a look at it so you can see all the details of how it works.&lt;br /&gt;
&lt;br /&gt;
Let us now look at some worked examples:&lt;br /&gt;
&lt;br /&gt;
===User installs version 2008080100 of myqtype===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype does not exist, and there will not be a qtype_myqtype_version row in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
# The user will unzip myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for the qtype_myqtype plugin is now present, but there is no trace of it in the database, so it will install the plugin from the install.xml file.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will exist with the two columns col1 and col2; and the qtype_myqtype_version row in the mdl_config table will contain 2008080100.&lt;br /&gt;
&lt;br /&gt;
===User upgrades from version 2008080100 to version 2008080200 of myqtype===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype table will exist with the two columns col1 and col2; and the qtype_myqtype_version row in the mdl_config table will contain 2008080100.&lt;br /&gt;
&lt;br /&gt;
# The user will delete the old question/type/myqtype folder.&lt;br /&gt;
# The user will unzip the new myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for version 2008080200 the qtype_myqtype plugin is now present, but the installed version of the the database tables (qtype_myqtype_version) is 2008080100. Therefore, it will call xmldb_qtype_myqtype_upgrade from upgrade.php, passing 2008080100 as the $oldversion argument.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will now have three columns col1, col2 and newcol; and the qtype_myqtype_version row in the mdl_config table will contain 2008080200.&lt;br /&gt;
&lt;br /&gt;
===User installs version 2008080200 of myqtype into a clean Moodle install===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype does not exist, and there will not be a qtype_myqtype_version row in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
# The user will unzip the 2008080200 version of myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for the qtype_myqtype plugin is now present, but there is no trace of it in the database, so it will install the plugin from the install.xml file.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will exist with three columns col1, col2 and newcol; and the qtype_myqtype_version row in the mdl_config table will contain 2008080200.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
The first time a user installs any version of your plugin, the install.xml file will be used to create all the required database tables. Therefore install.xml should always contain the definition of the up-to-date database structure. Moodle recognises this situation because there is a version.php file on disc, but there is no &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version value in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
If the user already had a version of your plugin installed, and then upgrades to a newer version, Moodle will detect this because the version.php file will contain a newer version number than the &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version value in the mdl_config table. In this case, Moodle will run the code in the upgrade.php file, passing in the old version number, so that the correct bits of upgrade can be run, as controlled by the if ($oldversion &amp;lt; XXXXXXXXXX) blocks of code.&lt;br /&gt;
&lt;br /&gt;
The contents of the install.xml and upgrade.php files should be generated using the XMLDB editor.&lt;br /&gt;
&lt;br /&gt;
==Database upgrades and stable branches==&lt;br /&gt;
&lt;br /&gt;
The simple rule is, never make any database changes on a stable branch. You only need to read this section in the rare situations where a database change on the stable branch is unavoidable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning!!! advanced material follows.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Suppose, in order to fix a bug, you need to make a database change in Moodle 1.9.3+ (which must also be merged into HEAD). The root of the problem is that people may upgrade their Moodle in three different ways, which &lt;br /&gt;
&lt;br /&gt;
* Upgrade from &amp;lt;=1.9.3 to 1.9.4 - this executes the ugprade script on the 1.9 branch.&lt;br /&gt;
* Upgrade from &amp;lt;=1.9.3 directly to &amp;gt;=2.0 - this executes the upgrade script on the HEAD branch.&lt;br /&gt;
* Upgrade from 1.9.4 to &amp;gt;=2.0 - in this case, you must ensure that the upgrade on HEAD is not executed.&lt;br /&gt;
&lt;br /&gt;
The normal way to do this is ensure that your database upgrade is idempotent. That is, it does not matter if you do it twice. So for example, instead of doing&lt;br /&gt;
&lt;br /&gt;
        $dbman-&amp;gt;create_table($table);&lt;br /&gt;
&lt;br /&gt;
you should do&lt;br /&gt;
&lt;br /&gt;
        if (!$dbman-&amp;gt;table_exists($table)) {&lt;br /&gt;
            $dbman-&amp;gt;create_table($table);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
You should also think about what version numbers to put in your version.php file on each branch. Above all, test carefully.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:XMLDB_Documentation|XMLDB_Documentation]]&lt;br /&gt;
* [[Development:Coding|Coding guidelines]]&lt;br /&gt;
* [[Development:DDL functions|DDL functions]]&lt;br /&gt;
* [[Development:XMLDB defining an XML structure|install.xml file documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:XMLDB]]&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Installing_and_upgrading_plugin_database_tables&amp;diff=73331</id>
		<title>Development:Installing and upgrading plugin database tables</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Installing_and_upgrading_plugin_database_tables&amp;diff=73331"/>
		<updated>2010-06-25T08:53:50Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Noting that version.php is not required for blocks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
If you have done the right thing, Moodle will automatically create the database tables for your plugin when you visit the Admin notifications page (.../admin/index.php). This process is controlled by three files within your plugin:&lt;br /&gt;
;version.php : This records the version of the plugin code (&#039;&#039;&#039;Please note:&#039;&#039;&#039; not required for blocks, which use the version number returned by the block&#039;s init() method - see [[Development:Blocks#Ready.2C_Set.2C_Go.21|the blocks development page]])&lt;br /&gt;
;db/install.xml : This is used when someone installs your plugin for the first time.&lt;br /&gt;
;db/upgrade.php : This is used when someone who had an older version of your plugin installed upgrades to the latest version.&lt;br /&gt;
&lt;br /&gt;
In addition, Moodle also stores in the database the currently installed version of each plugin.&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9 and before, this is stored in the mdl_config table, in a row with the name &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version. For example qtype_myqtype_version. The exception to this rule are modules and blocks. Installed module version numbers are stored in the mdl_modules table. Block version numbers are in mdl_block.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 an beyond, plugin version numbers are stored in the mdl_config_plugins table, with &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039; in the plugin column, and &#039;version&#039; in the name column - with the same exception for modules and blocks.&lt;br /&gt;
&lt;br /&gt;
==A specific example==&lt;br /&gt;
&lt;br /&gt;
For the rest of this document, I will use a particular example, because it should make the explanation easier. You should be able to see how to generalise it.&lt;br /&gt;
&lt;br /&gt;
We will suppose you that you are making a new question type myqtype. This is plugin type qtype, and the code will be in the question/type/myqtype folder. The currently installed version number will be stored in the qtype_myqtype_version row of the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
In addition, we will just consider the first two releases of the plugin. The first release will have version number 2008080100, and will just use one database table mdl_question_myqtype, with two columns col1 and col2. Then we will suppose that the second release is 2008080200, and that requires an extra column, newcol, to be added to the mdl_question_myqtype table.&lt;br /&gt;
&lt;br /&gt;
==The files you need for the first release==&lt;br /&gt;
&lt;br /&gt;
In what follows, the bits of code you need to replace are &#039;&#039;&#039;in bold&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
;version.php&lt;br /&gt;
 $plugin-&amp;gt;version  = 2008080100;&lt;br /&gt;
 $plugin-&amp;gt;requires = &#039;&#039;&#039;XXXXXXXXXX; // Copy the current value from the top-level version.php file.&#039;&#039;&#039;&lt;br /&gt;
;db/install.xml&lt;br /&gt;
:This file, which you should [[XMLDB editor|create with the XMLDB editor]], should contain the definition for your mdl_question_myqtype table, with the two columns col1 and col2.&lt;br /&gt;
&lt;br /&gt;
At this stage, you do not need a db/upgrade.php file.&lt;br /&gt;
&lt;br /&gt;
==The files you need for the second release==&lt;br /&gt;
&lt;br /&gt;
;version.php&lt;br /&gt;
 $plugin-&amp;gt;version  = 2008080200;&lt;br /&gt;
 $plugin-&amp;gt;requires = &#039;&#039;&#039;XXXXXXXXXX; // Copy the current value from the top-level version.php file.&#039;&#039;&#039;&lt;br /&gt;
;db/install.xml : This file should now contain the updated definition for your mdl_question_myqtype table, with three columns col1, col2 and newcol. You modify this file using the XMLDB editor.&lt;br /&gt;
;db/upgrade.php&lt;br /&gt;
:This file should contain the code that people need to run to upgrade from version 2008080100 of your plugin. That is, the code to add a column newcol to the mdl_question_myqtype table. You don&#039;t have to write this code yourself as the XMLDB editor will generate it for you. The upgrade.php file should contain a single function xmldb_qtype_myqtype_upgrade that looks a bit like:&lt;br /&gt;
 function xmldb_qtype_myqtype_upgrade($oldversion = 0) {&lt;br /&gt;
     $result = true;&lt;br /&gt;
 &lt;br /&gt;
     /// Add a new column newcol to the mdl_question_myqtype&lt;br /&gt;
     if ($result &amp;amp;&amp;amp; $oldversion &amp;lt; 2008080200) {&lt;br /&gt;
         &#039;&#039;&#039;// Code to add the column, generated by the &#039;View PHP Code&#039; option of the XMLDB editor.&#039;&#039;&#039;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     return $result;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Hint: If you are modifying or adding a field/table, get the XMLDB editor to generate the PHP update code for you &#039;&#039;&#039;after&#039;&#039;&#039; making the changes in the editor. If you are deleting one, you need to generate the PHP code &#039;&#039;&#039;before&#039;&#039;&#039; making the change - or you won&#039;t be able to select the field/table to write the code for, because it no longer exists.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==What happens when a user installs or upgrades your plugin==&lt;br /&gt;
&lt;br /&gt;
The process is triggered when an administrator goes to the Admin notifications page (.../admin/index.php). The code that does the work is the upgrade_plugins function in lib/adminlib.php and reading this code is the best way to find out exactly what happens. In pseudo-code, what it does is:&lt;br /&gt;
&lt;br /&gt;
 For each plugin of this type (e.g. all qtype plugins) {&lt;br /&gt;
     // For the body of this loop, suppose the current plugin being processed is myqtype.&lt;br /&gt;
 &lt;br /&gt;
     Check that question/type/myqtype/version.php, .../db/upgrade.php and .../db/install.xml exist.&lt;br /&gt;
 &lt;br /&gt;
     if ($CFG-&amp;gt;qtype_myqtype_version exists, and is less than the number in version.php) {&lt;br /&gt;
         Call the upgrade function xmldb_qtype_myqtype_upgrade from&lt;br /&gt;
                 upgrade.php, passing the old version number ($CFG-&amp;gt;qtype_myqtype_version)&lt;br /&gt;
                 which says what is currently installed&lt;br /&gt;
         Update $CFG-&amp;gt;qtype_myqtype_version to the latest number from version.php&lt;br /&gt;
                 to record what is currently installed&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     else if ($CFG-&amp;gt;qtype_myqtype_version does not exist) {&lt;br /&gt;
         Create the tables from the definitions in install.xml&lt;br /&gt;
         Update $CFG-&amp;gt;qtype_myqtype_version to the latest number from version.php&lt;br /&gt;
                 to record what is currently installed&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Of course, it is a bit more complex that than. However, the code in the upgrade_plugins is quite clear, and I encourage you to go and have a look at it so you can see all the details of how it works.&lt;br /&gt;
&lt;br /&gt;
Let us now look at some worked examples:&lt;br /&gt;
&lt;br /&gt;
===User installs version 2008080100 of myqtype===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype does not exist, and there will not be a qtype_myqtype_version row in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
# The user will unzip myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for the qtype_myqtype plugin is now present, but there is no trace of it in the database, so it will install the plugin from the install.xml file.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will exist with the two columns col1 and col2; and the qtype_myqtype_version row in the mdl_config table will contain 2008080100.&lt;br /&gt;
&lt;br /&gt;
===User upgrades from version 2008080100 to version 2008080200 of myqtype===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype table will exist with the two columns col1 and col2; and the qtype_myqtype_version row in the mdl_config table will contain 2008080100.&lt;br /&gt;
&lt;br /&gt;
# The user will delete the old question/type/myqtype folder.&lt;br /&gt;
# The user will unzip the new myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for version 2008080200 the qtype_myqtype plugin is now present, but the installed version of the the database tables (qtype_myqtype_version) is 2008080100. Therefore, it will call xmldb_qtype_myqtype_upgrade from upgrade.php, passing 2008080100 as the $oldversion argument.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will now have three columns col1, col2 and newcol; and the qtype_myqtype_version row in the mdl_config table will contain 2008080200.&lt;br /&gt;
&lt;br /&gt;
===User installs version 2008080200 of myqtype into a clean Moodle install===&lt;br /&gt;
&lt;br /&gt;
To start with, the mdl_question_myqtype does not exist, and there will not be a qtype_myqtype_version row in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
# The user will unzip the 2008080200 version of myqtype.zip into the question/type folder.&lt;br /&gt;
# The user will visit the Admin notifications page.&lt;br /&gt;
# This will trigger Moodle to search for plugings to upgrade. It will find that the code for the qtype_myqtype plugin is now present, but there is no trace of it in the database, so it will install the plugin from the install.xml file.&lt;br /&gt;
&lt;br /&gt;
At the end of this process, the mdl_question_myqtype table will exist with three columns col1, col2 and newcol; and the qtype_myqtype_version row in the mdl_config table will contain 2008080200.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
The first time a user installs any version of your plugin, the install.xml file will be used to create all the required database tables. Therefore install.xml should always contain the definition of the up-to-date database structure. Moodle recognises this situation because there is a version.php file on disc, but there is no &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version value in the mdl_config table.&lt;br /&gt;
&lt;br /&gt;
If the user already had a version of your plugin installed, and then upgrades to a newer version, Moodle will detect this because the version.php file will contain a newer version number than the &#039;&#039;plugintype&#039;&#039;_&#039;&#039;pluginname&#039;&#039;_version value in the mdl_config table. In this case, Moodle will run the code in the upgrade.php file, passing in the old version number, so that the correct bits of upgrade can be run, as controlled by the if ($oldversion &amp;lt; XXXXXXXXXX) blocks of code.&lt;br /&gt;
&lt;br /&gt;
The contents of the install.xml and upgrade.php files should be generated using the XMLDB editor.&lt;br /&gt;
&lt;br /&gt;
==Database upgrades and stable branches==&lt;br /&gt;
&lt;br /&gt;
The simple rule is, never make any database changes on a stable branch. You only need to read this section in the rare situations where a database change on the stable branch is unavoidable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning!!! advanced material follows.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Suppose, in order to fix a bug, you need to make a database change in Moodle 1.9.3+ (which must also be merged into HEAD). The root of the problem is that people may upgrade their Moodle in three different ways, which &lt;br /&gt;
&lt;br /&gt;
* Upgrade from &amp;lt;=1.9.3 to 1.9.4 - this executes the ugprade script on the 1.9 branch.&lt;br /&gt;
* Upgrade from &amp;lt;=1.9.3 directly to &amp;gt;=2.0 - this executes the upgrade script on the HEAD branch.&lt;br /&gt;
* Upgrade from 1.9.4 to &amp;gt;=2.0 - in this case, you must ensure that the upgrade on HEAD is not executed.&lt;br /&gt;
&lt;br /&gt;
The normal way to do this is ensure that your database upgrade is idempotent. That is, it does not matter if you do it twice. So for example, instead of doing&lt;br /&gt;
&lt;br /&gt;
        $dbman-&amp;gt;create_table($table);&lt;br /&gt;
&lt;br /&gt;
you should do&lt;br /&gt;
&lt;br /&gt;
        if (!$dbman-&amp;gt;table_exists($table)) {&lt;br /&gt;
            $dbman-&amp;gt;create_table($table);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
You should also think about what version numbers to put in your version.php file on each branch. Above all, test carefully.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:XMLDB_Documentation|XMLDB_Documentation]]&lt;br /&gt;
* [[Development:Coding|Coding guidelines]]&lt;br /&gt;
* [[Development:DDL functions|DDL functions]]&lt;br /&gt;
* [[Development:XMLDB defining an XML structure|install.xml file documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:XMLDB]]&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=38306</id>
		<title>User:Greg Preece</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=User:Greg_Preece&amp;diff=38306"/>
		<updated>2008-06-25T11:54:26Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: New page: Greg Preece is a PHP developer, who develops and maintains the moodletxt SMS messaging block for Moodle.  See: http://moodle.org/user/view.php?id=146613&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Greg Preece is a PHP developer, who develops and maintains the moodletxt SMS messaging block for Moodle.&lt;br /&gt;
&lt;br /&gt;
See: http://moodle.org/user/view.php?id=146613&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Blocks&amp;diff=38305</id>
		<title>Development:Blocks</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Blocks&amp;diff=38305"/>
		<updated>2008-06-25T11:53:02Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: Added after_install and before_delete methods to appendix. Noted when methods were first introduced.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039; A Step-by-step Guide To Creating Blocks &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Original Author: Jon Papaioannou (pj@moodle.org)&lt;br /&gt;
&lt;br /&gt;
The present document serves as a guide to developers who want to create their own blocks for use in Moodle. It applies to the 1.5 development version of Moodle (and any newer) &#039;&#039;&#039;only&#039;&#039;&#039;, as the blocks subsystem was rewritten and expanded for the 1.5 release. However, you can also find it useful if you want to modify blocks written for Moodle 1.3 and 1.4 to work with the latest versions (look at [[Blocks_Howto#appendix_b| Appendix B]]).&lt;br /&gt;
The guide is written as an interactive course which aims to develop a configurable, multi-purpose block that displays arbitrary HTML. It&#039;s targeted mainly at people with little experience with Moodle or programming in general and aims to show how easy it is to create new blocks for Moodle. A certain small amount of PHP programming knowledge is still required, though. Experienced developers and those who just want a reference text should refer to [[Blocks_Howto#appendix_a| Appendix A]] because the main guide has a rather low concentration of pure information in the text.&lt;br /&gt;
&lt;br /&gt;
== Basic Concepts ==&lt;br /&gt;
Through this guide, we will be following the creation of an &amp;quot;HTML&amp;quot; block from scratch in order to demonstrate most of the block features at our disposal. Our block will be named &amp;quot;SimpleHTML&amp;quot;. This does not constrain us regarding the name of the actual directory on the server where the files for our block will be stored, but for consistency we will follow the practice of using the lowercased form &amp;quot;simplehtml&amp;quot; in any case where such a name is required. Whenever we refer to a file or directory name which contains &amp;quot;simplehtml&amp;quot;, it&#039;s important to remember that &#039;&#039;only&#039;&#039; the &amp;quot;simplehtml&amp;quot; part is up to us to change; the rest is standardized and essential for Moodle to work correctly.&lt;br /&gt;
Whenever a file&#039;s path is mentioned in this guide, it will always start with a slash. This refers to the Moodle home directory; all files and directories will be referred to with respect to that directory.&lt;br /&gt;
&lt;br /&gt;
== Ready, Set, Go! ==&lt;br /&gt;
To define a &amp;quot;block&amp;quot; in Moodle, in the most basic case we need to provide just one source code file. We start by creating the directory &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/&amp;lt;/span&amp;gt; and creating a file named &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/block_simplehtml.php&amp;lt;/span&amp;gt; which will hold our code. We then begin coding the block:&lt;br /&gt;
     &amp;lt;?php&lt;br /&gt;
     class block_simplehtml extends block_base {&lt;br /&gt;
     function init() {&lt;br /&gt;
         $this-&amp;gt;title = get_string(&#039;simplehtml&#039;, &#039;block_simplehtml&#039;);&lt;br /&gt;
         $this-&amp;gt;version = 2004111200;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
The first line is our block class definition; it must be named exactly in the manner shown. Again, only the &amp;quot;simplehtml&amp;quot; part can (and indeed must) change; everything else is standardized.&lt;br /&gt;
Our class is then given a small method: [[Blocks_Howto#method_init| init]]. This is essential for all blocks, and its purpose is to set the two class member variables listed inside it. But what do these values actually mean? Here&#039;s a more detailed description.&lt;br /&gt;
[[Blocks_Howto#variable_title| $this-&amp;gt;title]] is the title displayed in the header of our block. We can set it to whatever we like; in this case it&#039;s set to read the actual title from a language file we are presumably distributing together with the block. I &#039;ll skip ahead a bit here and say that if you want your block to display &#039;&#039;&#039;no&#039;&#039;&#039; title at all, then you should set this to any descriptive value you want (but &#039;&#039;&#039;not&#039;&#039;&#039; make it an empty string). We will later see [[Blocks_Howto#section_eye_candy| how to disable the title&#039;s display]].&lt;br /&gt;
[[Blocks_Howto#variable_version| $this-&amp;gt;version]] is the version of our block. This actually would only make a difference if your block wanted to keep its own data in special tables in the database (i.e. for very complex blocks). In that case the version number is used exactly as it&#039;s used in activities; an upgrade script uses it to incrementally upgrade an &amp;quot;old&amp;quot; version of the block&#039;s data to the latest. We will outline this process further ahead, since blocks tend to be relatively simple and not hold their own private data. In our example, &lt;br /&gt;
this is certainly the case so we just set [[Blocks_Howto#variable_version| $this-&amp;gt;version]] to &#039;&#039;&#039;YYYYMMDD00&#039;&#039;&#039; and forget about it.&lt;br /&gt;
&#039;&#039;&#039;UPDATING:&#039;&#039;&#039; Prior to version 1.5, the basic structure of each block class was slightly different. Refer to [[Blocks_Howto#appendix_b| Appendix B]] for more information on the changes that old blocks have to make to conform to the new standard.&lt;br /&gt;
&lt;br /&gt;
== I Just Hear Static ==&lt;br /&gt;
In order to get our block to actually display something on screen, we need to add one more method to our class (before the final closing brace in our file). The new code is:&lt;br /&gt;
 function get_content() {&lt;br /&gt;
     if ($this-&amp;gt;content !== NULL) {&lt;br /&gt;
         return $this-&amp;gt;content;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     $this-&amp;gt;content = new stdClass;&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;text = &#039;The content of our SimpleHTML block!&#039;;&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
 &lt;br /&gt;
     return $this-&amp;gt;content;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
It can&#039;t get any simpler than that, can it? Let&#039;s dissect this method to see what&#039;s going on...&lt;br /&gt;
First of all, there is a check that returns the current value of [[Blocks_Howto#variable_content| $this-&amp;gt;content]] if it&#039;s not NULL; otherwise we proceed with &amp;quot;computing&amp;quot; it. Since the computation is potentially a time-consuming operation and it &#039;&#039;&#039;will&#039;&#039;&#039; be called several times for each block (Moodle works that way internally), we take a precaution and include this time-saver.&lt;br /&gt;
Supposing the content had not been computed before (it was NULL), we then define it from scratch. The code speaks for itself there, so there isn&#039;t much to say. Just keep in mind that we can use HTML both in the text &#039;&#039;&#039;and&#039;&#039;&#039; in the footer, if we want to.&lt;br /&gt;
At this point our block should be capable of being automatically installed in Moodle and added to courses; visit your administration page to install it and after seeing it in action come back to continue our tutorial.&lt;br /&gt;
&lt;br /&gt;
== Configure That Out ==&lt;br /&gt;
The current version of our block doesn&#039;t really do much; it just displays a fixed message, which is not very useful. What we &#039;d really like to do is allow the teachers to customize what goes into the block. This, in block-speak, is called &amp;quot;instance configuration&amp;quot;. So let&#039;s give our block some instance configuration...&lt;br /&gt;
First of all, we need to tell Moodle that we want it to provide instance-specific configuration amenities to our block. That&#039;s as simple as adding one more method to our block class:&lt;br /&gt;
 function instance_allow_config() {&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
This small change is enough to make Moodle display an &amp;quot;Edit...&amp;quot; icon in our block&#039;s header when we turn editing mode on in any course. However, if you try to click on that icon you will be presented with a notice that complains about the block&#039;s configuration not being implemented correctly. Try it, it&#039;s harmless.&lt;br /&gt;
Moodle&#039;s complaints do make sense. We told it that we want to have configuration, but we didn&#039;t say &#039;&#039;what&#039;&#039; kind of configuration we want, or how it should be displayed. To do that, we need to create one more file: &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/config_instance.html&amp;lt;/span&amp;gt; (which has to be named exactly like that). For the moment, copy paste the following into it and save:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;table cellpadding=&amp;quot;9&amp;quot; cellspacing=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;tr valign=&amp;quot;top&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;td align=&amp;quot;right&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;?php print_string(&#039;configcontent&#039;, &#039;block_simplehtml&#039;); ?&amp;gt;:&lt;br /&gt;
     &amp;lt;/td&amp;gt;&lt;br /&gt;
     &amp;lt;td&amp;gt;&lt;br /&gt;
         &amp;lt;?php print_textarea(true, 10, 50, 0, 0, &#039;text&#039;, $this-&amp;gt;config-&amp;gt;text); ?&amp;gt;&lt;br /&gt;
     &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &amp;lt;tr&amp;gt;&lt;br /&gt;
     &amp;lt;td colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;&amp;lt;?php print_string(&#039;savechanges&#039;) ?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
     &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &amp;lt;/table&amp;gt;&lt;br /&gt;
 &amp;lt;?php use_html_editor(); ?&amp;gt;&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
It isn&#039;t difficult to see that the above code just provides us with a wysiwyg-editor-enabled textarea to write our block&#039;s desired content in and a submit button to save. But... what&#039;s $this-&amp;gt;config-&amp;gt;text? Well...&lt;br /&gt;
Moodle goes a long way to make things easier for block developers. Did you notice that the textarea is actually named &amp;quot;text&amp;quot;? When the submit button is pressed, Moodle saves each and every field it can find in our &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config_instance.html&amp;lt;/span&amp;gt; file as instance configuration data. We can then access that data as &#039;&#039;&#039;$this-&amp;gt;config-&amp;gt;&#039;&#039;variablename&#039;&#039;&#039;&#039;&#039;, where &#039;&#039;variablename&#039;&#039; is the actual name we used for our field; in this case, &amp;quot;text&amp;quot;. So in essence, the above form just pre-populates the textarea with the current content of the block (as indeed it should) and then allows us to change it.&lt;br /&gt;
You also might be surprised by the presence of a submit button and the absence of any &amp;lt;form&amp;gt; element at the same time. But the truth is, we don&#039;t need to worry about that at all; Moodle goes a really long way to make things easier for developers! We just print the configuration options we want, in any format we want; include a submit button, and Moodle will handle all the rest itself. The instance configuration variables are automatically at our disposal to access from any of the class methods &#039;&#039;except&#039;&#039; [[Blocks_Howto#method_init| init]].&lt;br /&gt;
In the event where the default behavior is not satisfactory, we can still override it. However, this requires advanced modifications to our block class and will not be covered here; refer to [[Blocks_Howto#appendix_a| Appendix A]] for more details.&lt;br /&gt;
Having now the ability to refer to this instance configuration data through [[Blocks_Howto#variable_config| $this-&amp;gt;config]], the final twist is to tell our block to actually &#039;&#039;display&#039;&#039; what is saved in is configuration data. To do that, find this snippet in &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/block_simplehtml.php&amp;lt;/span&amp;gt;&amp;lt;nowiki&amp;gt;:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 $this-&amp;gt;content = new stdClass;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;text = &#039;The content of our SimpleHTML block!&#039;;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
and change it to:&lt;br /&gt;
 &lt;br /&gt;
 $this-&amp;gt;content = new stdClass;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;text = $this-&amp;gt;config-&amp;gt;text;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
Oh, and since the footer isn&#039;t really exciting at this point, we remove it from our block because it doesn&#039;t contribute anything. We could just as easily have decided to make the footer configurable in the above way, too. So for our latest code, the snippet becomes:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 $this-&amp;gt;content = new stdClass;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;text = $this-&amp;gt;config-&amp;gt;text;&lt;br /&gt;
 $this-&amp;gt;content-&amp;gt;footer = &#039;&#039;;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
After this discussion, our block is ready for prime time! Indeed, if you now visit any course with a SimpleHTML block, you will see that modifying its contents is now a snap.&lt;br /&gt;
&lt;br /&gt;
== The Specialists ==&lt;br /&gt;
Implementing instance configuration for the block&#039;s contents was good enough to whet our appetite, but who wants to stop there? Why not customize the block&#039;s title, too?&lt;br /&gt;
Why not, indeed. Well, our first attempt to achieve this is natural enough: let&#039;s add another field to &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/config_instance.html&amp;lt;/span&amp;gt;. Here goes:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;tr valign=&amp;quot;top&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;td align=&amp;quot;right&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;?php print_string(&#039;configtitle&#039;, &#039;block_simplehtml&#039;); ?&amp;gt;:&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
     &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;title&amp;quot; size=&amp;quot;30&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;config-&amp;gt;title; ?&amp;gt;&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
We save the edited file, go to a course, edit the title of the block and... nothing happens! The instance configuration is saved correctly, all right (editing it once more proves that) but it&#039;s not being displayed. All we get is just the simple &amp;quot;SimpleHTML&amp;quot; title.&lt;br /&gt;
That&#039;s not too wierd, if we think back a bit. Do you remember that [[Blocks_Howto#method_init| init]] method, where we set [[Blocks_Howto#variable_title| $this-&amp;gt;title]]? We didn&#039;t actually change its value from then, and [[Blocks_Howto#variable_title| $this-&amp;gt;title]] is definitely not the same as $this-&amp;gt;config-&amp;gt;title (to Moodle, at least). What we need is a way to update [[Blocks_Howto#variable_title| $this-&amp;gt;title]] with the value in the instance configuration. But as we said a bit earlier, we can use [[Blocks_Howto#variable_config| $this-&amp;gt;config]] in all methods &#039;&#039;except&#039;&#039; [[Blocks_Howto#method_init| init]]&amp;lt;nowiki&amp;gt;! So what can we do?&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Let&#039;s pull out another ace from our sleeve, and add this small method to our block class:&lt;br /&gt;
 &lt;br /&gt;
 function specialization() {&lt;br /&gt;
     if(!empty($this-&amp;gt;config-&amp;gt;title)){&lt;br /&gt;
         $this-&amp;gt;title = $this-&amp;gt;config-&amp;gt;title;&lt;br /&gt;
     }&lt;br /&gt;
     else{&lt;br /&gt;
         $this-&amp;gt;config-&amp;gt;title = &#039;&#039;&#039;&#039;&#039;&#039;&#039;;&lt;br /&gt;
     }&lt;br /&gt;
     if(empty($this-&amp;gt;config-&amp;gt;text)){&lt;br /&gt;
         $this-&amp;gt;config-&amp;gt;text = &#039;&#039;&#039;&#039;&#039;&#039;&#039;;&lt;br /&gt;
     }    &lt;br /&gt;
 }&lt;br /&gt;
Aha, here&#039;s what we wanted to do all along! But what&#039;s going on with the [[Blocks_Howto#method_specialization| specialization]] method?&lt;br /&gt;
This &amp;quot;magic&amp;quot; method has actually a very nice property: it&#039;s &#039;&#039;guaranteed&#039;&#039; to be automatically called by Moodle as soon as our instance configuration is loaded and available (that is, immediately after [[Blocks_Howto#method_init| init]] is called). That means before the block&#039;s content is computed for the first time, and indeed before &#039;&#039;anything&#039;&#039; else is done with the block. Thus, providing a [[Blocks_Howto#method_specialization| specialization]] method is the natural choice for any configuration data that needs to be acted upon &amp;quot;as soon as possible&amp;quot;, as in this case.&lt;br /&gt;
&lt;br /&gt;
== Now You See Me, Now You Don&#039;t ==&lt;br /&gt;
Now would be a good time to mention another nifty technique that can be used in blocks, and which comes in handy quite often. Specifically, it may be the case that our block will have something interesting to display some of the time; but in some other cases, it won&#039;t have anything useful to say. (An example here would be the &amp;quot;Recent Activity&amp;quot; block, in the case where no recent activity in fact exists. However in that case the block chooses to explicitly inform you of the lack of said activity, which is arguably useful). It would be nice, then, to be able to have our block &amp;quot;disappear&amp;quot; if it&#039;s not needed to display it.&lt;br /&gt;
This is indeed possible, and the way to do it is to make sure that after the [[Blocks_Howto#method_get_content| get_content]]&amp;lt;nowiki&amp;gt; method is called, the block is completely void of content. Specifically, &amp;quot;void of content&amp;quot; means that both $this-&amp;gt;content-&amp;gt;text and $this-&amp;gt;content-&amp;gt;footer are each equal to the empty string (&#039;&#039;). Moodle performs this check by calling the block&#039;s &amp;lt;/nowiki&amp;gt;[[Blocks_Howto#method_is_empty| is_empty()]] method, and if the block is indeed empty then it is not displayed at all.&lt;br /&gt;
Note that the exact value of the block&#039;s title and the presence or absence of a [[Blocks_Howto#method_hide_header| hide_header]] method do &#039;&#039;not&#039;&#039; affect this behavior. A block is considered empty if it has no content, irrespective of anything else.&lt;br /&gt;
== We Are Legion ==&lt;br /&gt;
Right now our block is fully configurable, both in title and content. It&#039;s so versatile, in fact, that we could make pretty much anything out of it. It would be really nice to be able to add multiple blocks of this type to a single course. And, as you might have guessed, doing that is as simple as adding another small method to our block class:&lt;br /&gt;
 &lt;br /&gt;
 function instance_allow_multiple() {&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
This tells Moodle that it should allow any number of instances of the SimpleHTML block in any course. After saving the changes to our file, Moodle immediately allows us to add multiple copies of the block without further ado!&lt;br /&gt;
There are a couple more of interesting points to note here. First of all, even if a block itself allows multiple instances in the same page, the administrator still has the option of disallowing such behavior. This setting can be set separately for each block from the Administration / Configuration / Blocks page.&lt;br /&gt;
And finally, a nice detail is that as soon as we defined an [[Blocks_Howto#method_instance_allow_multiple| instance_allow_multiple]] method, the method [[Blocks_Howto#method_instance_allow_config| instance_allow_config]] that was already defined became obsolete. Moodle assumes that if a block allows multiple instances of itself, those instances will want to be configured (what is the point of same multiple instances in the same page if they are identical?) and thus automatically provides an &amp;quot;Edit&amp;quot; icon. So, we can also remove the whole [[Blocks_Howto#method_instance_allow_config| instance_allow_config]] method now without harm. We had only needed it when multiple instances of the block were not allowed.&lt;br /&gt;
== The Effects of Globalization ==&lt;br /&gt;
Configuring each block instance with its own personal data is cool enough, but sometimes administrators need some way to &amp;quot;touch&amp;quot; all instances of a specific block at the same time. In the case of our SimpleHTML block, a few settings that would make sense to apply to all instances aren&#039;t that hard to come up with. For example, we might want to limit the contents of each block to only so many characters, or we might have a setting that filters HTML out of the block&#039;s contents, only allowing pure text in. Granted, such a feature wouldn&#039;t win us any awards for naming our block &amp;quot;SimpleHTML&amp;quot; but some tormented administrator somewhere might actually find it useful.&lt;br /&gt;
This kind of configuration is called &amp;quot;global configuration&amp;quot; and applies only to a specific block type (all instances of that block type are affected, however). Implementing such configuration for our block is quite similar to implementing the instance configuration. We will now see how to implement the second example, having a setting that only allows text and not HTML in the block&#039;s contents.&lt;br /&gt;
First of all, we need to tell Moodle that we want our block to provide global configuration by, what a surprise, adding a small method to our block class:&lt;br /&gt;
 &lt;br /&gt;
 function has_config() {&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
Then, we need to create a HTML file that actually prints out the configuration screen. In our case, we &#039;ll just print out a checkbox saying &amp;quot;Do not allow HTML in the content&amp;quot; and a &amp;quot;submit&amp;quot; button. Let&#039;s create the file &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/config_global.html&amp;lt;/span&amp;gt; which again must be named just so, and copy paste the following into it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div style=&amp;quot;text-align: center;&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;block_simplehtml_strict&amp;quot; value=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
 &amp;lt;input type=&amp;quot;checkbox&amp;quot; name=&amp;quot;block_simplehtml_strict&amp;quot; value=&amp;quot;1&amp;quot;&lt;br /&gt;
   &amp;lt;?php if(!empty($CFG-&amp;gt;block_simplehtml_strict)) echo &#039;checked=&amp;quot;checked&amp;quot;&#039;; ?&amp;gt; /&amp;gt;&lt;br /&gt;
 &amp;lt;?php print_string(&#039;donotallowhtml&#039;, &#039;block_simplehtml&#039;); ?&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;&amp;lt;?php print_string(&#039;savechanges&#039;); ?&amp;gt;&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
True to our block&#039;s name, this looks simple enough. What it does is that it displays a checkbox named &amp;quot;block_simplehtml_strict&amp;quot; and if the Moodle configuration variable with the same name (i.e., $CFG-&amp;gt;block_simplehtml_strict) is set and not empty (that means it&#039;s not equal to an empty string, to zero, or to boolean false) it displays the box as pre-checked (reflecting the current status). Why does it check the configuration setting with the same name? Because the default implementation of the global configuration saving code takes all the variables we have in our form and saves them as Moodle configuration options with the same name. Thus, it&#039;s good practice to use a descriptive name and also one that won&#039;t possibly conflict with the name of another setting. &amp;quot;block_simplehtml_strict&amp;quot; clearly satisfies both requirements.&lt;br /&gt;
The astute reader may have noticed that we actually have &#039;&#039;two&#039;&#039; input fields named &amp;quot;block_simplehtml_strict&amp;quot; in our configuration file. One is hidden and its value is always 0; the other is the checkbox and its value is 1. What gives? Why have them both there?&lt;br /&gt;
Actually, this is a small trick we use to make our job as simple as possible. HTML forms work this way: if a checkbox in a form is not checked, its name does not appear at all in the variables passed to PHP when the form is submitted. That effectively means that, when we uncheck the box and click submit, the variable is not passed to PHP at all. Thus, PHP does not know to update its value to &amp;quot;0&amp;quot;, and our &amp;quot;strict&amp;quot; setting cannot be turned off at all once we turn it on for the first time. Not the behavior we want, surely.&lt;br /&gt;
However, when PHP handles received variables from a form, the variables are processed in the order in which they appear in the form. If a variable comes up having the same name with an already-processed variable, the new value overwrites the old one. Taking advantage of this, our logic runs as follows: the variable &amp;quot;block_simplehtml_strict&amp;quot; is first unconditionally set to &amp;quot;0&amp;quot;. Then, &#039;&#039;if&#039;&#039; the box is checked, it is set to &amp;quot;1&amp;quot;, overwriting the previous value as discussed. The net result is that our configuration setting behaves as it should.&lt;br /&gt;
To round our bag of tricks up, notice that the use of if(!empty($CFG-&amp;gt;block_simplehtml_strict)) in the test for &amp;quot;should the box be checked by default?&amp;quot; is quite deliberate. The first time this script runs, the variable $CFG-&amp;gt;block_simplehtml_strict will not exist at all. After it&#039;s set for the first time, its value can be either &amp;quot;0&amp;quot; or &amp;quot;1&amp;quot;. Given that both &amp;quot;not set&amp;quot; and the string &amp;quot;0&amp;quot; evaluate as empty while the sting &amp;quot;1&amp;quot; does not, we manage to avoid any warnings from PHP regarding the variable not being set at all, &#039;&#039;and&#039;&#039; have a nice human-readable representation for its two possible values (&amp;quot;0&amp;quot; and &amp;quot;1&amp;quot;).&lt;br /&gt;
Now that we have managed to cram a respectable amount of tricks into a few lines of HTML, we might as well discuss the alternative in case that tricks are not enough for a specific configuration setup we have in mind. Saving the data is done in the method [[Blocks_Howto#method_config_save| config_save]], the default implementation of which is as follows:&lt;br /&gt;
 &lt;br /&gt;
 function config_save($data) {&lt;br /&gt;
     // Default behavior: save all variables as $CFG properties&lt;br /&gt;
     foreach ($data as $name =&amp;gt; $value) {&lt;br /&gt;
         set_config($name, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
As can be clearly seen, Moodle passes this method an associative array $data which contains all the variables coming in from our configuration screen. If we wanted to do the job without the &amp;quot;hidden variable with the same name&amp;quot; trick we used above, one way to do it would be by overriding this method with the following:&lt;br /&gt;
 &lt;br /&gt;
 function config_save($data) {&lt;br /&gt;
     if(isset($data[&#039;block_simplehtml_strict&#039;])) {&lt;br /&gt;
         set_config(&#039;block_simplehtml_strict&#039;, &#039;1&#039;);&lt;br /&gt;
     }&lt;br /&gt;
     else {&lt;br /&gt;
         set_config(&#039;block_simplehtml_strict&#039;, &#039;0&#039;);&lt;br /&gt;
     }&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
Quite straightfoward: if the variable &amp;quot;block_simplehtml_strict&amp;quot; is passed to us, then it can only mean that the user has checked it, so set the configuration variable with the same name to &amp;quot;1&amp;quot;. Otherwise, set it to &amp;quot;0&amp;quot;. Of course, this version would need to be updated if we add more configuration options because it doesn&#039;t respond to them as the default implementation does. Still, it&#039;s useful to know how we can override the default implementation if it does not fit our needs (for example, we might not want to save the variable as part of the Moodle configuration but do something else with it).&lt;br /&gt;
So, we are now at the point where we know if the block should allow HTML tags in its content or not. How do we get the block to actually respect that setting?&lt;br /&gt;
We could decide to do one of two things: either have the block &amp;quot;clean&amp;quot; HTML out from the input before saving it in the instance configuration and then display it as-is (the &amp;quot;eager&amp;quot; approach); or have it save the data &amp;quot;as is&amp;quot; and then clean it up each time just before displaying it (the &amp;quot;lazy&amp;quot; approach). The eager approach involves doing work once when saving the configuration; the lazy approach means doing work each time the block is displayed and thus it promises to be worse performance-wise. We shall hence go with the eager approach.&lt;br /&gt;
Much as we did just before with overriding [[Blocks_Howto#method_config_save| config_save]], what is needed here is overriding the method [[Blocks_Howto#method_instance_config_save| instance_config_save]] which handles the instance configuration. The default implementation is as follows:&lt;br /&gt;
 &lt;br /&gt;
 function instance_config_save($data) {&lt;br /&gt;
     $data = stripslashes_recursive($data);&lt;br /&gt;
     $this-&amp;gt;config = $data;&lt;br /&gt;
     return set_field(&#039;block_instance&#039;, &#039;configdata&#039;, base64_encode(serialize($data)),&lt;br /&gt;
                      &#039;id&#039;, $this-&amp;gt;instance-&amp;gt;id);&lt;br /&gt;
 }&lt;br /&gt;
This may look intimidating at first (what&#039;s all this stripslashes_recursive() and base64_encode() and serialize() stuff?) but do not despair; we won&#039;t have to touch any of it. We will only add some extra validation code in the beginning and then instruct Moodle to additionally call this default implementation to do the actual storing of the data. Specifically, we will add a method to our class which goes like this:&lt;br /&gt;
 &lt;br /&gt;
 function instance_config_save($data) {&lt;br /&gt;
     // Clean the data if we have to&lt;br /&gt;
     global $CFG;&lt;br /&gt;
     if(!empty($CFG-&amp;gt;block_simplehtml_strict)) {&lt;br /&gt;
         $data-&amp;gt;text = strip_tags($data-&amp;gt;text);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     // And now forward to the default implementation defined in the parent class&lt;br /&gt;
     return parent::instance_config_save($data);&lt;br /&gt;
 }&lt;br /&gt;
At last! Now the administrator has absolute power of life and death over what type of content is allowed in our &amp;quot;SimpleHTML&amp;quot; block! Absolute? Well... not exactly. In fact, if we think about it for a while, it will become apparent that if at some point in time HTML is allowed and some blocks have saved their content with HTML included, and afterwards the administrator changes the setting to &amp;quot;off&amp;quot;, this will only prevent subsequent content changes from including HTML. Blocks which already had HTML in their content would continue to display it!&lt;br /&gt;
Following that train of thought, the next stop is realizing that we wouldn&#039;t have this problem if we had chosen the lazy approach a while back, because in that case we would &amp;quot;sanitize&amp;quot; each block&#039;s content just before it was displayed. The only thing we can do with the eager approach is strip all the tags from the content of all SimpleHTML instances as soon as the admin setting is changed to &amp;quot;HTML off&amp;quot;; but even then, turning the setting back to &amp;quot;HTML on&amp;quot; won&#039;t bring back the tags we stripped away. On the other hand, the lazy approach might be slower, but it&#039;s more versatile; we can choose whether to strip or keep the HTML before displaying the content, and we won&#039;t lose it at all if the admin toggles the setting off and on again. Isn&#039;t the life of a developer simple and wonderful?&lt;br /&gt;
We will let this part of the tutorial come to a close with the obligatory excercise for the reader: in order to have the SimpleHTML block work &amp;quot;correctly&amp;quot;, find out how to strengthen the eager approach to strip out all tags from the existing configuration of all instances of our block, &#039;&#039;&#039;or&#039;&#039;&#039; go back and implement the lazy approach instead. (Hint: do that in the [[Blocks_Howto#method_get_content| get_content]] method)&lt;br /&gt;
&#039;&#039;&#039;UPDATING&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;: Prior to version 1.5, the file &amp;lt;/nowiki&amp;gt;&amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config_global.html&amp;lt;/span&amp;gt; was named simply &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config.html&amp;lt;/span&amp;gt;. Also, the methods [[Blocks_Howto#method_config_save| config_save]] and [[Blocks_Howto#method_config_print| config_print]] were named &#039;&#039;&#039;handle_config&#039;&#039;&#039; and &#039;&#039;&#039;print_config&#039;&#039;&#039; respectively. Upgrading a block to work with Moodle 1.5 involves updating these aspects; refer to [[Blocks_Howto#appendix_b| Appendix B]] for more information.&lt;br /&gt;
&lt;br /&gt;
== Eye Candy ==&lt;br /&gt;
Our block is just about complete functionally, so now let&#039;s take a look at some of the tricks we can use to make its behavior customized in a few more useful ways.&lt;br /&gt;
First of all, there are a couple of ways we can adjust the visual aspects of our block. For starters, it might be useful to create a block that doesn&#039;t display a header (title) at all. You can see this effect in action in the Course Description block that comes with Moodle. This behavior is achieved by, you guessed it, adding one more method to our block class:&lt;br /&gt;
 &lt;br /&gt;
 function hide_header() {&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
One more note here: we cannot just set an empty title inside the block&#039;s [[Blocks_Howto#method_init| init]] method; it&#039;s necessary for each block to have a unique, non-empty title after [[Blocks_Howto#method_init| init]] is called so that Moodle can use those titles to differentiate between all of the installed blocks.&lt;br /&gt;
Another adjustment we might want to do is instruct our block to take up a certain amount of width on screen. Moodle handles this as a two-part process: first, it queries each block about its preferred width and takes the maximum number as the desired value. Then, the page that&#039;s being displayed can choose to use this value or, more probably, bring it within some specific range of values if it isn&#039;t already. That means that the width setting is a best-effort settlement; your block can &#039;&#039;request&#039;&#039; a certain width and Moodle will &#039;&#039;try&#039;&#039; to provide it, but there&#039;s no guarantee whatsoever about the end result. As a concrete example, all standard Moodle course formats will deliver any requested width between 180 and 210 pixels, inclusive.&lt;br /&gt;
To instruct Moodle about our block&#039;s preferred width, we add one more method to the block class:&lt;br /&gt;
 &lt;br /&gt;
 function preferred_width() {&lt;br /&gt;
     // The preferred value is in pixels&lt;br /&gt;
     return 200;&lt;br /&gt;
 }&lt;br /&gt;
This will make our block (and all the other blocks displayed at the same side of the page) a bit wider than standard.&lt;br /&gt;
Finally, we can also affect some properties of the actual HTML that will be used to print our block. Each block is fully contained within a &amp;amp;lt;table&amp;amp;gt; element, inside which all the HTML for that block is printed. We can instruct Moodle to add HTML attributes with specific values to that container. This would be done to either a) directly affect the end result (if we say, assign bgcolor=&amp;quot;black&amp;quot;), or b) give us freedom to customize the end result using CSS (this is in fact done by default as we &#039;ll see below).&lt;br /&gt;
The default behavior of this feature in our case will assign to our block&#039;s container the class HTML attribute with the value &amp;quot;sideblock block_simplehtml&amp;quot; (the prefix &amp;quot;block_&amp;quot; followed by the name of our block, lowercased). We can then use that class to make CSS selectors in our theme to alter this block&#039;s visual style (for example, &amp;quot;.sideblock.block_simplehtml { border: 1px black solid}&amp;quot;).&lt;br /&gt;
To change the default behavior, we will need to define a method which returns an associative array of attribute names and values. For example, the version&lt;br /&gt;
 &lt;br /&gt;
 function html_attributes() {&lt;br /&gt;
     return array(&lt;br /&gt;
         &#039;class&#039;       =&amp;gt; &#039;sideblock block_&#039;. $this-&amp;gt;name(),&lt;br /&gt;
         &#039;onmouseover&#039; =&amp;gt; &amp;quot;alert(&#039;Mouseover on our block!&#039;);&amp;quot;&lt;br /&gt;
     );&lt;br /&gt;
 }&lt;br /&gt;
will result in a mouseover event being added to our block using JavaScript, just as if we had written the onmouseover=&amp;quot;alert(...)&amp;quot; part ourselves in HTML. Note that we actually duplicate the part which sets the class attribute (we want to keep that, and since we override the default behavior it&#039;s our responsibility to emulate it if required). And the final elegant touch is that we don&#039;t set the class to the hard-coded value &amp;quot;block_simplehtml&amp;quot; but instead use the [[Blocks_Howto#method_name| name]] method to make it dynamically match our block&#039;s name.&lt;br /&gt;
&lt;br /&gt;
== Authorized Personnel Only ==&lt;br /&gt;
It&#039;s not difficult to imagine a block which is very useful in some circumstances but it simply cannot be made meaningful in others. An example of this would be the &amp;quot;Social Activities&amp;quot; block which is indeed useful in a course with the social format, but doesn&#039;t do anything useful in a course with the weeks format. There should be some way of allowing the use of such blocks only where they are indeed meaningful, and not letting them confuse users if they are not.&lt;br /&gt;
Moodle allows us to declare which course formats each block is allowed to be displayed in, and enforces these restrictions as set by the block developers at all times. The information is given to Moodle as a standard associative array, with each key corresponding to a page format and defining a boolean value (true/false) that declares whether the block should be allowed to appear in that page format.&lt;br /&gt;
Notice the deliberate use of the term &#039;&#039;page&#039;&#039; instead of &#039;&#039;course&#039;&#039; in the above paragraph. This is because in Moodle 1.5 and onwards, blocks can be displayed in any page that supports them. The best example of such pages are the course pages, but we are not restricted to them. For instance, the quiz view page (the first one we see when we click on the name of the quiz) also supports blocks.&lt;br /&gt;
The format names we can use for the pages derive from the name of the script which is actually used to display that page. For example, when we are looking at a course, the script is &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/course/view.php&amp;lt;/span&amp;gt; (this is evident from the browser&#039;s address line). Thus, the format name of that page is &#039;&#039;&#039;course-view&#039;&#039;&#039;. It follows easily that the format name for a quiz view page is &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039;. This rule of thumb does have a few exceptions, however:&lt;br /&gt;
#* The format name for the front page of Moodle is &#039;&#039;&#039;site-index&#039;&#039;&#039;.&lt;br /&gt;
#* The format name for courses is actually not just &#039;&#039;&#039;course-view&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;; it is &amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;course-view-weeks&#039;&#039;&#039;, &#039;&#039;&#039;course-view-topics&#039;&#039;&#039;, etc.&lt;br /&gt;
#* Even though there is no such page, the format name &#039;&#039;&#039;all&#039;&#039;&#039; can be used as a catch-all option.&lt;br /&gt;
We can include as many format names as we want in our definition of the applicable formats. Each format can be allowed or disallowed, and there are also three more rules that help resolve the question &amp;quot;is this block allowed into this page or not?&amp;quot;:&lt;br /&gt;
#* Prefixes of a format name will match that format name; for example, &#039;&#039;&#039;mod&#039;&#039;&#039; will match all the activity modules. &#039;&#039;&#039;course-view&#039;&#039;&#039; will match any course, regardless of the course format. And finally, &#039;&#039;&#039;site&#039;&#039;&#039; will also match the front page (remember that its full format name is &#039;&#039;&#039;site-index&#039;&#039;&#039;).&lt;br /&gt;
#* The more specialized a format name that matches our page is, the higher precedence it has when deciding if the block will be allowed. For example, &#039;&#039;&#039;mod&#039;&#039;&#039;, &#039;&#039;&#039;mod-quiz&#039;&#039;&#039; and &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; all match the quiz view page. But if all three are present, &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; will take precedence over the other two because it is a better match.&lt;br /&gt;
#* The character &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039; can be used in place of any word. For example, &#039;&#039;&#039;mod&#039;&#039;&#039; and &#039;&#039;&#039;mod-*&#039;&#039;&#039; are equivalent. At the time of this document&#039;s writing, there is no actual reason to utilize this &amp;quot;wildcard matching&amp;quot; feature, but it exists for future usage.&lt;br /&gt;
#* The order that the format names appear does not make any difference.&lt;br /&gt;
All of the above are enough to make the situation sound complex, so let&#039;s look at some specific examples. First of all, to have our block appear &#039;&#039;&#039;only&#039;&#039;&#039; in the site front page, we would use:&lt;br /&gt;
 &lt;br /&gt;
 function applicable_formats() {&lt;br /&gt;
     return array(&#039;site&#039; =&amp;gt; true);&lt;br /&gt;
 }&lt;br /&gt;
Since &#039;&#039;&#039;all&#039;&#039;&#039; is missing, the block is disallowed from appearing in &#039;&#039;any&#039;&#039; course format; but then &#039;&#039;&#039;site&#039;&#039;&#039; is set to true, so it&#039;s explicitly allowed to appear in the site front page (remember that &#039;&#039;&#039;site&#039;&#039;&#039; matches &#039;&#039;&#039;site-index&#039;&#039;&#039; because it&#039;s a prefix).&lt;br /&gt;
For another example, if we wanted to allow the block to appear in all course formats &#039;&#039;except&#039;&#039; social, and also to &#039;&#039;not&#039;&#039; be allowed anywhere but in courses, we would use:&lt;br /&gt;
 &lt;br /&gt;
 function applicable_formats() {&lt;br /&gt;
     return array(&#039;course-view&#039; =&amp;gt; true, &#039;course-view-social&#039; =&amp;gt; false);&lt;br /&gt;
 }&lt;br /&gt;
This time, we first allow the block to appear in all courses and then we explicitly disallow the social format.&lt;br /&gt;
For our final, most complicated example, suppose that a block can be displayed in the site front page, in courses (but not social courses) and also when we are viewing any activity module, &#039;&#039;except&#039;&#039; quiz. This would be:&lt;br /&gt;
 &lt;br /&gt;
 function applicable_formats() {&lt;br /&gt;
     return array(&#039;site-index&#039; =&amp;gt; true,&lt;br /&gt;
                  &#039;course-view&#039; =&amp;gt; true, &#039;course-view-social&#039; =&amp;gt; false,&lt;br /&gt;
                  &#039;mod&#039; =&amp;gt; true, &#039;mod-quiz&#039; =&amp;gt; false);&lt;br /&gt;
 }&lt;br /&gt;
It is not difficult to realize that the above accomplishes the objective if we remember that there is a &amp;quot;best match&amp;quot; policy to determine the end result.&lt;br /&gt;
&#039;&#039;&#039;UPDATING:&#039;&#039;&#039; Prior to version 1.5, blocks were only allowed in courses (and in Moodle 1.4, in the site front page). Also, the keywords used to describe the valid course formats at the time were slightly different and had to be changed in order to allow for a more open architecture. Refer to [[Blocks_Howto#appendix_b| Appendix B]] for more information on the changes that old blocks have to make to conform to the new standard.&lt;br /&gt;
== Lists and Icons ==&lt;br /&gt;
In this final part of the guide we will briefly discuss an additional capability of Moodle&#039;s block system, namely the ability to very easily create blocks that display a list of choices to the user. This list is displayed with one item per line, and an optional image (icon) next to the item. An example of such a &#039;&#039;list block&#039;&#039; is the standard Moodle &amp;quot;admin&amp;quot; block, which illustrates all the points discussed in this section.&lt;br /&gt;
As we have seen so far, blocks use two properties of [[Blocks_Howto#variable_content| $this-&amp;gt;content]]&amp;lt;nowiki&amp;gt;: &amp;quot;text&amp;quot; and &amp;quot;footer&amp;quot;. The text is displayed as-is as the block content, and the footer is displayed below the content in a smaller font size. List blocks use $this-&amp;gt;content-&amp;gt;footer in the exact same way, but they ignore $this-&amp;gt;content-&amp;gt;text.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Instead, Moodle expects such blocks to set two other properties when the [[Blocks_Howto#method_get_content| get_content]] method is called: $this-&amp;gt;content-&amp;gt;items and $this-&amp;gt;content-&amp;gt;icons. $this-&amp;gt;content-&amp;gt;items should be a numerically indexed array containing elements that represent the HTML for each item in the list that is going to be displayed. Usually these items will be HTML anchor tags which provide links to some page. $this-&amp;gt;content-&amp;gt;icons should also be a numerically indexed array, with exactly as many items as $this-&amp;gt;content-&amp;gt;items has. Each of these items should be a fully qualified HTML &amp;lt;img&amp;gt; tag, with &amp;quot;src&amp;quot;, &amp;quot;height&amp;quot;, &amp;quot;width&amp;quot; and &amp;quot;alt&amp;quot; attributes. Obviously, it makes sense to keep the images small and of a uniform size.&lt;br /&gt;
In order to tell Moodle that we want to have a list block instead of the standard text block, we need to make a small change to our block class declaration. Instead of extending class &#039;&#039;&#039;block_base&#039;&#039;&#039;, our block will extend class &#039;&#039;&#039;block_list&#039;&#039;&#039;. For example:&lt;br /&gt;
 &lt;br /&gt;
 class block_my_menu extends block_list {&lt;br /&gt;
     // The init() method does not need to change at all&lt;br /&gt;
 }&lt;br /&gt;
In addition to making this change, we must of course also modify the [[Blocks_Howto#method_get_content| get_content]] method to construct the [[Blocks_Howto#variable_content| $this-&amp;gt;content]] variable as discussed above:&lt;br /&gt;
 &lt;br /&gt;
 function get_content() {&lt;br /&gt;
     if ($this-&amp;gt;content !== NULL) {&lt;br /&gt;
         return $this-&amp;gt;content;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     $this-&amp;gt;content = new stdClass;&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;items = array();&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;icons = array();&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
 &lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;items[] = &#039;&amp;lt;a href=&amp;quot;some_file.php&amp;quot;&amp;gt;Menu Option 1&amp;lt;/a&amp;gt;&#039;;&lt;br /&gt;
     $this-&amp;gt;content-&amp;gt;icons[] = &#039;&amp;lt;img src=&amp;quot;images/icons/1.gif&amp;quot; class=&amp;quot;icon&amp;quot; alt=&amp;quot;&amp;quot; /&amp;gt;&#039;;&lt;br /&gt;
 &lt;br /&gt;
     // Add more list items here&lt;br /&gt;
 &lt;br /&gt;
     return $this-&amp;gt;content;&lt;br /&gt;
 }&lt;br /&gt;
To summarize, if we want to create a list block instead of a text block, we just need to change the block class declaration and the [[Blocks_Howto#method_get_content| get_content]] method. Adding the mandatory [[Blocks_Howto#method_init| init]] method as discussed earlier will then give us our first list block in no time!&lt;br /&gt;
&lt;br /&gt;
== Appendix A: Reference ==&lt;br /&gt;
&lt;br /&gt;
This Appendix will discuss the base class &#039;&#039;&#039;block_base&#039;&#039;&#039; from which all other block classes derive, and present each and every method that can be overridden by block developers in detail. Methods that should &#039;&#039;&#039;not&#039;&#039;&#039; be overridden are explicitly referred to as such. After reading this Appendix, you will have a clear understanding of every method which you should or could override to implement functionality for your block.&lt;br /&gt;
&lt;br /&gt;
The methods are divided into three categories: those you may use and override in your block, those that you may &#039;&#039;&#039;not&#039;&#039;&#039; override but might want to use, and those internal methods that should &#039;&#039;&#039;neither&#039;&#039;&#039; be used &#039;&#039;&#039;nor&#039;&#039;&#039; overridden. In each category, methods are presented in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
=== Methods you can freely use and override: ===&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;after_install&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 function after_install() {&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Available in Moodle 1.7 and later&lt;br /&gt;
&lt;br /&gt;
This method is designed to be overridden by block subclasses, and allows you to specify a set of tasks to be executed after the block is installed.  For example, you may wish to store the date on which the block was installed.  However, each database type has its own way of getting the current date, and when using XMLDB to install your block, these operations are also unsupported. So the best way to complete such a task while maintaining database abstraction is to use XMLDB to install the block, and then use the after_install() method to perform the insertion before the block is used.&lt;br /&gt;
&lt;br /&gt;
Please note that after_install() is called once per block, not once per instance.&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;applicable_formats&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 function applicable_formats() {&lt;br /&gt;
     // Default case: the block can be used in courses and site index, but not in activities&lt;br /&gt;
     return array(&#039;all&#039; =&amp;gt; true, &#039;mod&#039; =&amp;gt; false);&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method allows you to control which pages your block can be added to. Page formats are formulated from the full path of the script that is used to display that page. You should return an array with the keys being page format names and the values being booleans (true or false). Your block is only allowed to appear in those formats where the value is true.&lt;br /&gt;
Example format names are: &#039;&#039;&#039;course-view&#039;&#039;&#039;, &#039;&#039;&#039;site-index&#039;&#039;&#039; (this is an exception, referring front page of the Moodle site), &#039;&#039;&#039;course-format-weeks&#039;&#039;&#039; (referring to a specific course format), &#039;&#039;&#039;mod-quiz&#039;&#039;&#039; (referring to the quiz module) and &#039;&#039;&#039;all&#039;&#039;&#039; (this will be used for those formats you have not explicitly allowed or disallowed).&lt;br /&gt;
The full matching rules are:&lt;br /&gt;
*** Prefixes of a format name will match that format name; for example, &#039;&#039;&#039;mod&#039;&#039;&#039; will match all the activity modules. &#039;&#039;&#039;course-view&#039;&#039;&#039; will match any course, regardless of the course format. And finally, &#039;&#039;&#039;site&#039;&#039;&#039; will also match the front page (remember that its full format name is &#039;&#039;&#039;site-index&#039;&#039;&#039;).&lt;br /&gt;
*** The more specialized a format name that matches our page is, the higher precedence it has when deciding if the block will be allowed. For example, &#039;&#039;&#039;mod&#039;&#039;&#039;, &#039;&#039;&#039;mod-quiz&#039;&#039;&#039; and &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; all match the quiz view page. But if all three are present, &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; will take precedence over the other two because it is a better match.&lt;br /&gt;
*** The character &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039; can be used in place of any word. For example, &#039;&#039;&#039;mod&#039;&#039;&#039; and &#039;&#039;&#039;mod-*&#039;&#039;&#039; are equivalent. At the time of this document&#039;s writing, there is no actual reason to utilize this &amp;quot;wildcard matching&amp;quot; feature, but it exists for future usage.&lt;br /&gt;
*** The order that the format names appear does not make any difference.&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;before_delete&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 function before_delete() {&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Available in Moodle 1.7 and later&lt;br /&gt;
&lt;br /&gt;
This method is called when an administrator removes a block from the Moodle installation, immediately before the relevant database tables are deleted.  It allows block authors to perform any necessary cleanup - removing temporary files and so on - before the block is deleted.&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;config_print&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 function config_print() {&lt;br /&gt;
     // Default behavior: print the config_global.html file&lt;br /&gt;
     // You don&#039;t need to override this if you&#039;re satisfied with the above&lt;br /&gt;
     if (!$this-&amp;gt;has_config()) {&lt;br /&gt;
         return false;&lt;br /&gt;
     }&lt;br /&gt;
     global $CFG, $THEME;&lt;br /&gt;
     print_simple_box_start(&#039;center&#039;, &#039;&#039;, $THEME-&amp;gt;cellheading);&lt;br /&gt;
     include($CFG-&amp;gt;dirroot.&#039;/blocks/&#039;. $this-&amp;gt;name() .&#039;/config_global.html&#039;);&lt;br /&gt;
     print_simple_box_end();&lt;br /&gt;
     return true;&lt;br /&gt;
 }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method allows you to choose how to display the global configuration screen for your block. This is the screen that the administrator is presented with when he chooses &amp;quot;Settings...&amp;quot; for a specific block. Override it if you need something much more complex than the default implementation allows you to do. However, keep these points in mind:&lt;br /&gt;
**# If you save your configuration options in $CFG, you will probably need to use global $CFG; before including any HTML configuration screens.&lt;br /&gt;
**# The HTML &amp;lt;input&amp;gt; elements that you include in your method&#039;s output will be automatically enclosed in a &amp;lt;form&amp;gt; element. You do not need to worry about where and how that form is submitted; however, you &#039;&#039;&#039;must&#039;&#039;&#039; provide a way to submit it (i.e., an &amp;lt;input type=&amp;quot;submit&amp;quot; /&amp;gt;.&lt;br /&gt;
You should return a boolean value denoting the success or failure of your method&#039;s actions.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;config_save&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function config_save($data) {&lt;br /&gt;
     // Default behavior: save all variables as $CFG properties&lt;br /&gt;
     // You don&#039;t need to override this if you &#039;re satisfied with the above&lt;br /&gt;
     foreach ($data as $name =&amp;gt; $value) {&lt;br /&gt;
         set_config($name, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return true;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method allows you to override the storage mechanism for your global configuration data. The received argument is an associative array, with the keys being setting names and the values being setting values. The default implementation saves everything as Moodle $CFG variables.&lt;br /&gt;
Note that $data does not hold all of the submitted POST data because Moodle adds some hidden fields to the form in order to be able to process it. However, before calling this method it strips the hidden fields from the received data and so when this method is called only the &amp;quot;real&amp;quot; configuration data remain.&lt;br /&gt;
You should return a boolean value denoting the success or failure of your method&#039;s actions.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;get_content&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function get_content() {&lt;br /&gt;
     // This should be implemented by the derived class.&lt;br /&gt;
     return NULL;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should, when called, populate the [[Blocks_Howto#variable_content| $this-&amp;gt;content]] variable of your block. Populating the variable means:&lt;br /&gt;
&#039;&#039;&#039;EITHER&#039;&#039;&#039;&amp;lt;br /&amp;gt;defining $this-&amp;gt;content-&amp;gt;text and $this-&amp;gt;content-&amp;gt;footer if your block derives from &#039;&#039;&#039;block_base&#039;&#039;&#039;. Both of these should be strings, and can contain arbitrary HTML.&lt;br /&gt;
&#039;&#039;&#039;OR&#039;&#039;&#039;&amp;lt;br /&amp;gt;defining $this-&amp;gt;content-&amp;gt;items, $this-&amp;gt;content-&amp;gt;icons and $this-&amp;gt;content-&amp;gt;footer if your block derives from &#039;&#039;&#039;block_list&#039;&#039;&#039;. The first two should be numerically indexed arrays having the exact same number of elements. $this-&amp;gt;content-&amp;gt;items is an array of strings that can contain arbitrary HTML while $this-&amp;gt;content-&amp;gt;icons also contains should strings, but those must be fully-qualified HTML &amp;lt;img&amp;gt; tags &#039;&#039;&#039;and nothing else&#039;&#039;&#039;. $this-&amp;gt;content-&amp;gt;footer is a string, as above.&lt;br /&gt;
If you set &#039;&#039;all&#039;&#039; of these variables to their default &amp;quot;empty&amp;quot; values (empty arrays for the arrays and empty strings for the strings), the block will &#039;&#039;&#039;not&#039;&#039;&#039; be displayed at all except to editing users. This is a good way of having your block hide itself to unclutter the screen if there is no reason to have it displayed.&lt;br /&gt;
Before starting to populate [[Blocks_Howto#variable_content| $this-&amp;gt;content]], you should also include a simple caching check. If [[Blocks_Howto#variable_content| $this-&amp;gt;content]] is exactly equal to NULL then proceed as normally, while if it is not, return the existing value instead of calculating it once more. If you fail to do this, Moodle will suffer a performance hit.&lt;br /&gt;
In any case, your method should return the fully constructed [[Blocks_Howto#variable_content| $this-&amp;gt;content]] variable.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;has_config&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function has_config() {&lt;br /&gt;
     return false;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value that denotes whether your block wants to present a configuration interface to site admins or not. The configuration that this interface offers will impact all instances of the block equally.&lt;br /&gt;
To actually implement the configuration interface, you will either need to rely on the default [[Blocks_Howto#method_instance_config_print| config_print]] method or override it. The full guide contains [[Blocks_Howto#section_effects_of_globalization| more information on this]].&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;hide_header&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function hide_header() {&lt;br /&gt;
     //Default, false--&amp;gt; the header is shown&lt;br /&gt;
     return false;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value that denotes whether your block wants to hide its header (or title). Thus, if you override it to return true, your block will not display a title unless the current user is in editing mode.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;html_attributes&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function html_attributes() {&lt;br /&gt;
     // Default case: an id with the instance and a class with our name in it&lt;br /&gt;
     return array(&#039;id&#039; =&amp;gt; &#039;inst&#039;.$this-&amp;gt;instance-&amp;gt;id, &#039;class&#039; =&amp;gt; &#039;block_&#039;. $this-&amp;gt;name());&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return an associative array of HTML attributes that will be given to your block&#039;s container element when Moodle constructs the output HTML. No sanitization will be performed in these elements at all.&lt;br /&gt;
If you intend to override this method, you should return the default attributes as well as those you add yourself. The recommended way to do this is:&lt;br /&gt;
 &lt;br /&gt;
 function html_attributes() {&lt;br /&gt;
     $attrs = parent::html_attributes();&lt;br /&gt;
     // Add your own attributes here, e.g.&lt;br /&gt;
     // $attrs[&#039;width&#039;] = &#039;50%&#039;;&lt;br /&gt;
     return $attrs;&lt;br /&gt;
 }&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;init&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function init() {&lt;br /&gt;
     $this-&amp;gt;title = get_string(&#039;simplehtml&#039;, &#039;block_simplehtml&#039;);&lt;br /&gt;
     $this-&amp;gt;version = 2004111200;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method must be implemented for all blocks. It has to assign meaningful values to the object variables [[Blocks_Howto#variable_title| $this-&amp;gt;title]] and [[Blocks_Howto#variable_version| $this-&amp;gt;version]] (which is used by Moodle for performing automatic updates when available).&lt;br /&gt;
No return value is expected from this method.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;instance_allow_config&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function instance_allow_config() {&lt;br /&gt;
     return false;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value. True indicates that your block wants to have per-instance configuration, while false means it does not. If you do want to implement instance configuration, you will need to take some additional steps apart from overriding this method; refer to the full guide for [[Blocks_Howto#section_configure_that_out| more information]].&lt;br /&gt;
This method&#039;s return value is irrelevant if [[Blocks_Howto#method_instance_allow_multiple| instance_allow_multiple]] returns true; it is assumed that if you want multiple instances then each instance needs its own configuration.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;instance_allow_multiple&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function instance_allow_multiple() {&lt;br /&gt;
     // Are you going to allow multiple instances of each block?&lt;br /&gt;
     // If yes, then it is assumed that the block WILL USE per-instance configuration&lt;br /&gt;
     return false;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value, indicating whether you want to allow multiple instances of this block in the same page or not. If you do allow multiple instances, it is assumed that you will also be providing per-instance configuration for the block. Thus, you will need to take some additional steps apart from overriding this method; refer to the full guide for [[Blocks_Howto#section_configure_that_out| more information]].&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;instance_config_print&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
 function instance_config_print() {&lt;br /&gt;
     // Default behavior: print the config_instance.html file&lt;br /&gt;
     // You don&#039;t need to override this if you&#039;re satisfied with the above&lt;br /&gt;
     if (!$this-&amp;gt;instance_allow_multiple() &amp;amp;&amp;amp; !$this-&amp;gt;instance_allow_config()) {&lt;br /&gt;
         return false;&lt;br /&gt;
     }&lt;br /&gt;
     global $CFG, $THEME;&lt;br /&gt;
 &lt;br /&gt;
     if (is_file($CFG-&amp;gt;dirroot .&#039;/blocks/&#039;. $this-&amp;gt;name() .&#039;/config_instance.html&#039;)) {&lt;br /&gt;
         print_simple_box_start(&#039;center&#039;, &#039;&#039;, $THEME-&amp;gt;cellheading);&lt;br /&gt;
         include($CFG-&amp;gt;dirroot .&#039;/blocks/&#039;. $this-&amp;gt;name() .&#039;/config_instance.html&#039;);&lt;br /&gt;
         print_simple_box_end();&lt;br /&gt;
     } else {&lt;br /&gt;
         notice(get_string(&#039;blockconfigbad&#039;),&lt;br /&gt;
                str_replace(&#039;blockaction=&#039;, &#039;dummy=&#039;, qualified_me()));&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     return true;&lt;br /&gt;
 }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method allows you to choose how to display the instance configuration screen for your block. Override it if you need something much more complex than the default implementation allows you to do. Keep in mind that whatever you do output from [[Blocks_Howto#method_instance_config_print| config_print]], it will be enclosed in a HTML form automatically. You only need to provide a way to submit that form.&lt;br /&gt;
You should return a boolean value denoting the success or failure of your method&#039;s actions.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;instance_config_save&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function instance_config_save($data) {&lt;br /&gt;
     $data = stripslashes_recursive($data);&lt;br /&gt;
     $this-&amp;gt;config = $data;&lt;br /&gt;
     return set_field(&#039;block_instance&#039;, &#039;configdata&#039;, base64_encode(serialize($data)),&lt;br /&gt;
                      &#039;id&#039;, $this-&amp;gt;instance-&amp;gt;id);&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method allows you to override the storage mechanism for your instance configuration data. The received argument is an associative array, with the keys being setting names and the values being setting values.&lt;br /&gt;
The configuration must be stored in the &amp;quot;configdata&amp;quot; field of your instance record in the database so that Moodle can auto-load it when your block is constructed. However, you may still want to override this method if you need to take some additional action apart from saving the data. In that case, you really should do what data processing you want and then call parent::instance_config_save($data) with your new $data array. This will keep your block from becoming broken if the default implementation of instance_config_save changes in the future.&lt;br /&gt;
Note that $data does not hold all of the submitted POST data because Moodle adds some hidden fields to the form in order to be able to process it. However, before calling this method it strips the hidden fields from the received data and so when this method is called only the &amp;quot;real&amp;quot; configuration data remain.&lt;br /&gt;
If you want to update the stored copy of the configuration data at run time (for example to persist some changes you made programmatically), you should not use this method. The correct procedure for that purpose is to call [[Blocks_Howto#method_instance_config_commit| instance_config_commit]].&lt;br /&gt;
You should return a boolean value denoting the success or failure of your method&#039;s actions.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;preferred_width&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function preferred_width() {&lt;br /&gt;
     // Default case: the block wants to be 180 pixels wide&lt;br /&gt;
     return 180;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should return an integer value, which is the number of pixels of width your block wants to take up when displayed. Moodle will try to honor your request, but this is actually up to the implementation of the format of the page your block is being displayed in and therefore no guarantee is given. You might get exactly what you want or any other width the format decides to give you, although obviously an effort to accomodate your block will be made.&lt;br /&gt;
Most display logic at this point allocates the maximum width requested by the blocks that are going to be displayed, bounding it both downwards and upwards to avoid having a bad-behaving block break the format.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;refresh_content&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function refresh_content() {&lt;br /&gt;
     // Nothing special here, depends on content()&lt;br /&gt;
     $this-&amp;gt;content = NULL;&lt;br /&gt;
     return $this-&amp;gt;get_content();&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method should cause your block to recalculate its content immediately. If you follow the guidelines for [[Blocks_Howto#get_content| get_content]], which say to respect the current content value unless it is NULL, then the default implementation will do the job just fine.&lt;br /&gt;
You should return the new value of [[Blocks_Howto#variable_content| $this-&amp;gt;content]] after refreshing it.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;specialization&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function specialization() {&lt;br /&gt;
     // Just to make sure that this method exists.&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method is automatically called by the framework immediately after your instance data (which includes the page type and id and all instance configuration data) is loaded from the database. If there is some action that you need to take as soon as this data becomes available and which cannot be taken earlier, you should override this method.&lt;br /&gt;
The instance data will be available in the variables [[Blocks_Howto#variable_instance| $this-&amp;gt;instance]] and [[Blocks_Howto#variable_config| $this-&amp;gt;config]].&lt;br /&gt;
This method should not return anything at all.&lt;br /&gt;
=== Methods which you should &#039;&#039;not&#039;&#039; override but may want to use: ===&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;instance_config_commit&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function instance_config_commit() {&lt;br /&gt;
     return set_field(&#039;block_instance&#039;,&lt;br /&gt;
                      &#039;configdata&#039;, base64_encode(serialize($this-&amp;gt;config)),&lt;br /&gt;
                      &#039;id&#039;, $this-&amp;gt;instance-&amp;gt;id);&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method saves the current contents of [[Blocks_Howto#variable_config| $this-&amp;gt;config]] to the database. If you need to make a change to the configuration settings of a block instance at run time (and not through the usual avenue of letting the user change it), just make the changes you want to [[Blocks_Howto#variable_config| $this-&amp;gt;config]] and then call this method.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;get_content_type&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function get_content_type() {&lt;br /&gt;
     return $this-&amp;gt;content_type;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method returns the value of [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]], and is the preferred way of accessing that variable. It is guaranteed to always work, now and forever. Directly accessing the variable is &#039;&#039;&#039;not recommended&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;; future library changes may break compatibility with code that does so.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;get_title&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function get_title() {&lt;br /&gt;
     return $this-&amp;gt;title;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method returns the value of [[Blocks_Howto#variable_title| $this-&amp;gt;title]], and is the preferred way of accessing that variable. It is guaranteed to always work, now and forever. Directly accessing the variable is &#039;&#039;&#039;not recommended&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;; future library changes may break compatibility with code that does so.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;get_version&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function get_version() {&lt;br /&gt;
     return $this-&amp;gt;version;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method returns the value of [[Blocks_Howto#variable_version| $this-&amp;gt;version]], and is the preferred way of accessing that variable. It is guaranteed to always work, now and forever. Directly accessing the variable is &#039;&#039;&#039;not recommended&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;; future library changes may break compatibility with code that does so.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;is_empty&amp;lt;/div&amp;gt;&lt;br /&gt;
For blocks that extend class &#039;&#039;&#039;block_base&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function is_empty() {&lt;br /&gt;
     $this-&amp;gt;get_content();&lt;br /&gt;
     return(empty($this-&amp;gt;content-&amp;gt;text) &amp;amp;&amp;amp; empty($this-&amp;gt;content-&amp;gt;footer));&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
For blocks that extend class &#039;&#039;&#039;block_list&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function is_empty() {&lt;br /&gt;
     $this-&amp;gt;get_content();&lt;br /&gt;
     return (empty($this-&amp;gt;content-&amp;gt;items) &amp;amp;&amp;amp; empty($this-&amp;gt;content-&amp;gt;footer));&lt;br /&gt;
 }&lt;br /&gt;
This method returns the a boolean true/false value, depending on whether the block has any content at all to display. Blocks without content are not displayed by the framework.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;name&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 function name() {&lt;br /&gt;
     static $myname;&lt;br /&gt;
     if ($myname === NULL) {&lt;br /&gt;
         $myname = strtolower(get_class($this));&lt;br /&gt;
         $myname = substr($myname, strpos($myname, &#039;_&#039;) + 1);&lt;br /&gt;
     }&lt;br /&gt;
     return $myname;&lt;br /&gt;
 }&lt;br /&gt;
Available in Moodle 1.5 and later&lt;br /&gt;
&lt;br /&gt;
This method returns the internal name of your block inside Moodle, without the &#039;&#039;&#039;block_&#039;&#039;&#039; prefix. Obtaining the name of a block object is sometimes useful because it can be used to write code that is agnostic to the actual block&#039;s name (and thus more generic and reusable). For an example of this technique, see the [[Blocks_Howto#method_config_print| config_print]] method.&lt;br /&gt;
=== Methods which you should &#039;&#039;not&#039;&#039; override and &#039;&#039;not&#039;&#039; use at all: ===&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;_self_test&amp;lt;/div&amp;gt;&lt;br /&gt;
This is a private method; no description is given.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;_add_edit_controls&amp;lt;/div&amp;gt;&lt;br /&gt;
This is a private method; no description is given.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;_load_instance&amp;lt;/div&amp;gt;&lt;br /&gt;
This is a private method; no description is given.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;_print_block&amp;lt;/div&amp;gt;&lt;br /&gt;
This is a private method; no description is given.&lt;br /&gt;
** &amp;lt;div class=&amp;quot;function_title&amp;quot;&amp;gt;_print_shadow&amp;lt;/div&amp;gt;&lt;br /&gt;
This is a private method; no description is given.&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;block_base&#039;&#039;&#039; also has a few standard member variables which its methods manipulate. These variables, the purpose of each and the type of data they are expected to hold is explained in the next section of this Appendix.&lt;br /&gt;
&lt;br /&gt;
=== Class variables: ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;config&amp;lt;/div&amp;gt;&lt;br /&gt;
This variable holds all the specialized instance configuration data that have been provided for this specific block instance (object). It is an object of type stdClass, with member variables directly corresponding to the HTML &amp;lt;input&amp;gt; elements in the block&#039;s &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config_instance.html&amp;lt;/span&amp;gt; file.&lt;br /&gt;
The variable is initialized just after the block object is constructed, immediately before [[Blocks_Howto#method_specialization| specialization]] is called for the object. It is possible that the block has no instance configuration, in which case the variable will be NULL.&lt;br /&gt;
It is obvious that there is a direct relationship between this variable and the configdata field in the mdl_block_instance table. However, it is &#039;&#039;strongly&#039;&#039; advised that you refrain from accessing the configdata field yourself. If you absolutely must update its value at any time, it is recommended that you call the method [[Blocks_Howto#method_instance_config_commit| instance_config_commit]] to do the actual work.&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;content_type&amp;lt;/div&amp;gt;&lt;br /&gt;
This variable instructs Moodle on what type of content it should assume the block has, and is used to differentiate text blocks from list blocks. It is essential that it has a meaningful value, as Moodle depends on this for correctly displaying the block on screen. Consequently, this variable is closely tied with the variable [[Blocks_Howto#variable_content| $this-&amp;gt;content]]. The variable is expected to have a valid value after the framework calls the [[Blocks_Howto#method_init| init]] method for each block.&lt;br /&gt;
The only valid values for this variable are the two named constants [[Blocks_Howto#constant_block_type_text| BLOCK_TYPE_TEXT]] and [[Blocks_Howto#constant_block_type_list| BLOCK_TYPE_LIST]].&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;content&amp;lt;/div&amp;gt;&lt;br /&gt;
This variable holds all the actual content that is displayed inside each block. Valid values for it are either NULL or an object of class stdClass, which must have specific member variables set as explained below. Normally, it begins life with a value of NULL and it becomes fully constructed (i.e., an object) when [[Blocks_Howto#method_get_content| get_content]] is called.&lt;br /&gt;
After it is fully constructed, this object is expected to have certain properties, depending on the value of [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]]. Specifically:&lt;br /&gt;
** If [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]] is [[Blocks_Howto#constant_block_type_text| BLOCK_TYPE_TEXT]], then [[Blocks_Howto#variable_content| $this-&amp;gt;content]] is expected to have the following member variables:&lt;br /&gt;
*** &amp;lt;div&amp;gt;&#039;&#039;&#039;text&#039;&#039;&#039;&amp;lt;/div&amp;gt;This is a string of arbitrary length and content. It is displayed inside the main area of the block, and can contain HTML.&lt;br /&gt;
*** &amp;lt;div&amp;gt;&#039;&#039;&#039;footer&#039;&#039;&#039;&amp;lt;/div&amp;gt;This is a string of arbitrary length and contents. It is displayed below the text, using a smaller font size. It can also contain HTML.&lt;br /&gt;
** If [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]] is [[Blocks_Howto#constant_block_type_list| BLOCK_TYPE_LIST]], then [[Blocks_Howto#variable_content| $this-&amp;gt;content]] is expected to have the following member variables:&lt;br /&gt;
*** &amp;lt;div&amp;gt;&#039;&#039;&#039;items&#039;&#039;&#039;&amp;lt;/div&amp;gt;This is a numerically indexed array of strings which holds the title for each item in the list that will be displayed in the block&#039;s area. Since usually such lists function like menus, the title for each item is normally a fully qualified HTML &amp;lt;a&amp;gt; tag.&lt;br /&gt;
*** &amp;lt;div&amp;gt;&#039;&#039;&#039;icons&#039;&#039;&#039;&amp;lt;/div&amp;gt;This is a numerically indexed array of strings which represent the images displayed before each item of the list. It therefore follows that it should have the exact number of elements as the items member variable. Each item in this array should be a fully qualified HTML &amp;lt;img&amp;gt; tag.&lt;br /&gt;
*** &amp;lt;div&amp;gt;&#039;&#039;&#039;footer&#039;&#039;&#039;&amp;lt;/div&amp;gt;This is a string of arbitrary length and contents. It is displayed below the text, using a smaller font size. It can also contain HTML.&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;instance&amp;lt;/div&amp;gt;&lt;br /&gt;
This member variable holds all the specific information that differentiates one block instance (i.e., the PHP object that embodies it) from another. It is an object of type stdClass retrieved by calling get_record on the table mdl_block_instance. Its member variables, then, directly correspond to the fields of that table. It is initialized immediately after the block object itself is constructed.&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;title&amp;lt;/div&amp;gt;&lt;br /&gt;
This variable is a string that contains the human-readable name of the block. It is used to refer to blocks of that type throughout Moodle, for example in the administrator&#039;s block configuration screen and in the editing teacher&#039;s add block menu. It is also the title that is printed when the block is displayed on screen, although blocks can specifically change this title to something else if they wish (see below). The variable is expected to have a valid value after the framework calls the [[Blocks_Howto#method_init| init]] method for each object.&lt;br /&gt;
In the case of blocks which may want to configure their title dynamically through instance configuration, it is still essential to provide a valid title inside [[Blocks_Howto#method_init| init]]. This title may then be overridden when the [[Blocks_Howto#method_specialization| specialization]] method is called by the framework:&lt;br /&gt;
 &lt;br /&gt;
 function specialization() {&lt;br /&gt;
     // At this point, $this-&amp;gt;instance and $this-&amp;gt;config are available&lt;br /&gt;
     // for use. We can now change the title to whatever we want.&lt;br /&gt;
     $this-&amp;gt;title = $this-&amp;gt;config-&amp;gt;variable_holding_the_title;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A lot of blocks seem to use &lt;br /&gt;
&lt;br /&gt;
 $this-&amp;gt;title = get_string(&#039;blockname&#039;, ... );&lt;br /&gt;
&lt;br /&gt;
to set the title of the block (and then put a more specific title inside the language file)&lt;br /&gt;
If there is no proper language string, the title of the block will then be set to &#039;&#039;blockname&#039;&#039;. If there is another block with the same generic title, then an error will show up: Naming conflict.&lt;br /&gt;
&lt;br /&gt;
To avoid this error on installations with missing language strings, use a more specific name when calling the language string...&lt;br /&gt;
&lt;br /&gt;
 $this-&amp;gt;title = get_string(&#039;simplehtml&#039;, ... );&lt;br /&gt;
&lt;br /&gt;
That way all blocks will show up with a unique title in the admin area, even if people have not yet succeeded in placing language files in the correct location&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;div class=&amp;quot;variable_title&amp;quot;&amp;gt;$this-&amp;gt;version&amp;lt;/div&amp;gt;&lt;br /&gt;
This variable should hold each block&#039;s version number in the form &#039;&#039;&#039;YYYYMMDDXX&#039;&#039;&#039;, as per the convention throughout Moodle. The version number is used by Moodle to detect when a block has been upgraded and it consequently needs to run the block&#039;s upgrade code to bring the &amp;quot;old&amp;quot; version of the block&#039;s data up to date. The variable is expected to have a valid value after the framework calls the [[Blocks_Howto#method_init| init]] method for each block.&lt;br /&gt;
Most blocks do not keep complex data of their own in the database the way that modules do, so in most cases nothing actually happens during a block version upgrade. However, the version number is displayed in the administration interface for blocks. It is good practice therefore to change your block&#039;s version number when it gains new functionality or receives important bug fixes, to enable site administrators to easily identify the exact version of the block they are working with.&lt;br /&gt;
&lt;br /&gt;
Appearing throughout the code related to the Blocks API, there is a number of predefined constants that are utilized to avoid the use of &amp;quot;magic numbers&amp;quot; in the code. These constants are:&lt;br /&gt;
&lt;br /&gt;
=== Named constants: ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;div class=&amp;quot;named_constant&amp;quot;&amp;gt;BLOCK_TYPE_LIST&amp;lt;/div&amp;gt;&lt;br /&gt;
This is one of the two valid values for the [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]] member variable of every block. Its value specifies the exact requirements that Moodle will then have for [[Blocks_Howto#variable_content| $this-&amp;gt;content]].&lt;br /&gt;
* &amp;lt;div class=&amp;quot;named_constant&amp;quot;&amp;gt;BLOCK_TYPE_TEXT&amp;lt;/div&amp;gt;&lt;br /&gt;
This is one of the two valid values for the [[Blocks_Howto#variable_content_type| $this-&amp;gt;content_type]] member variable of every block. Its value specifies the exact requirements that Moodle will then have for [[Blocks_Howto#variable_content| $this-&amp;gt;content]].&lt;br /&gt;
&lt;br /&gt;
== Appendix B: Differences in the Blocks API for Moodle versions prior to 1.5 ==&lt;br /&gt;
&lt;br /&gt;
This Appendix will discuss what changes in the Blocks API were introduced by Moodle 1.5 and what steps developers need to take to update their blocks to be fully compatible with Moodle 1.5. Unfortunately, with these changes backward compatibility is broken; this means that blocks from Moodle 1.4 will never work with 1.5 and vice versa.&lt;br /&gt;
&lt;br /&gt;
=== Class naming conventions changed ===&lt;br /&gt;
In Moodle 1.4, all block classes were required to have a name like &#039;&#039;&#039;CourseBlock_something&#039;&#039;&#039; and the base class from which the derived was &#039;&#039;&#039;MoodleBlock&#039;&#039;&#039;. This has changed in Moodle 1.5, to bring the naming conventions in line with other object-oriented aspects of Moodle (for example there are classes enrolment_base, resource_base etc). The new block classes should instead be named like &#039;&#039;&#039;block_something&#039;&#039;&#039; and derive from &#039;&#039;&#039;block_base&#039;&#039;&#039;. This means that in order to make a block compatible with Moodle 1.5, you need to change the class definition&lt;br /&gt;
 &lt;br /&gt;
 class CourseBlock_online_users extends MoodleBlock { ... }&lt;br /&gt;
to&lt;br /&gt;
 &lt;br /&gt;
 class block_online_users extends block_base { ... }&lt;br /&gt;
An exception to the above is the special case where the block is intended to display a list of items instead of arbitrary text; in this case the block class must derive from class &#039;&#039;&#039;block_list&#039;&#039;&#039; instead, like this:&lt;br /&gt;
 &lt;br /&gt;
 class block_admin extends block_list { ... }&lt;br /&gt;
&lt;br /&gt;
=== Constructor versus init() ===&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.4, in each block class it was mandatory to define a constructor which accepted a course data record as an argument (the example is from the actual Online Users block):&lt;br /&gt;
 &lt;br /&gt;
     function CourseBlock_online_users ($course) {&lt;br /&gt;
         $this-&amp;gt;title = get_string(&#039;blockname&#039;,&#039;block_online_users&#039;);&lt;br /&gt;
         $this-&amp;gt;content_type = BLOCK_TYPE_TEXT;&lt;br /&gt;
         $this-&amp;gt;course = $course;&lt;br /&gt;
         $this-&amp;gt;version = 2004052700;&lt;br /&gt;
     }&lt;br /&gt;
In contrast, Moodle 1.5 does away with the constructor and instead requires you to define an init() method that takes no arguments:&lt;br /&gt;
 &lt;br /&gt;
     function init() {&lt;br /&gt;
         $this-&amp;gt;title = get_string(&#039;blockname&#039;,&#039;block_online_users&#039;);&lt;br /&gt;
         $this-&amp;gt;version = 2004111600;&lt;br /&gt;
     }&lt;br /&gt;
Of course, this leaves you without access to the $course object, which you might actually need. Since that&#039;s probably going to be needed inside [[Blocks_Howto#method_get_content| get_content]], the way to retrieve it is by using this code:&lt;br /&gt;
 &lt;br /&gt;
     $course = get_record(&#039;course&#039;, &#039;id&#039;, $this-&amp;gt;instance-&amp;gt;pageid);&lt;br /&gt;
If you are going to need access to $course from inside other methods in addition to [[Blocks_Howto#method_get_content| get_content]], you might fetch the $course object inside the [[Blocks_Howto#method_specialization| specialization]] method and save it as a class variable for later use, in order to avoid executing the same query multiple times:&lt;br /&gt;
 &lt;br /&gt;
     function specialization() {&lt;br /&gt;
         $this-&amp;gt;course = get_record(&#039;course&#039;, &#039;id&#039;, $this-&amp;gt;instance-&amp;gt;pageid);&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
=== Blocks with configuration ===&lt;br /&gt;
In Moodle 1.4, blocks could only have what are now (in Moodle 1.5) called &amp;quot;global configuration&amp;quot; options, to differentiate from the new &amp;quot;instance configuration&amp;quot; options. If your block has support for configuration, you will need to take these steps:&lt;br /&gt;
## Rename your &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config.html&amp;lt;/span&amp;gt; file to &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;config_global.html&amp;lt;/span&amp;gt;.&lt;br /&gt;
## Edit the newly renamed file and completely remove the &amp;lt;form&amp;gt; tag (Moodle now wraps your configuration in a form automatically).&lt;br /&gt;
## If you are using any HTML &amp;lt;input&amp;gt; tags other than those that directly affect your configuration (for example, &amp;quot;sesskey&amp;quot;), REMOVE those too (Moodle will add them automatically as required).&lt;br /&gt;
## If you have overridden &#039;&#039;&#039;print_config&#039;&#039;&#039;, rename your method to &#039;&#039;&#039;config_print&#039;&#039;&#039;.&lt;br /&gt;
## If you have overridden &#039;&#039;&#039;handle_config&#039;&#039;&#039;, rename your method to &#039;&#039;&#039;config_save&#039;&#039;&#039;.&lt;br /&gt;
=== Blocks with customized applicable formats ===&lt;br /&gt;
The correct way to specify the formats you want to allow or disallow your block to exist has been reworked for Moodle 1.5 to take account of the fact that blocks are no longer restricted to just courses. To have a block retain its intended behavior, you must change these format names (array keys in the return value of [[Blocks_Howto#method_applicable_formats| applicable_formats]]) if they are used in your block:&lt;br /&gt;
#* &#039;&#039;&#039;social&#039;&#039;&#039; should become &#039;&#039;&#039;course-view-social&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;topics&#039;&#039;&#039; should become &#039;&#039;&#039;course-view-topics&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;weeks&#039;&#039;&#039; should become &#039;&#039;&#039;course-view-weeks&#039;&#039;&#039;&lt;br /&gt;
You should also keep in mind that there is now the possibility of blocks being displayed in other pages too, like the introductory page that users see when they enter an activity module. You might therefore need to make the specification for applicable formats more restrictive to keep your block out of pages it is not supposed to be shown in. Also, there are subtle changes to the way that the final decision to allow or disallow a block is made. For the technical details refer to the definition of [[Blocks_Howto#method_applicable_formats| applicable_formats]], and for a more extended example read [[Blocks_Howto#section_authorized_personnel_only| the section dedicated to this subject]].&lt;br /&gt;
That&#039;s everything; your block will now be ready for use in Moodle 1.5!&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Blocks]]&lt;br /&gt;
&lt;br /&gt;
[[es:Desarrollo de bloques]]&lt;br /&gt;
&lt;br /&gt;
== Creating Database Tables for Blocks ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The following describes what to do in Moodle &amp;lt;= 1.6. For Moodle &amp;gt;= 1.7, you need to use [[Development:XMLDB_Documentation|XMLDB]], that is, create an install.xml file, instead of *.sql files.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can easily create a database table for your block by adding&lt;br /&gt;
two files mysql.sql and postgres7.sql to a subdirectory db/ of&lt;br /&gt;
your block. The tables HAVE TO be named the same way as the&lt;br /&gt;
block (e.g. block_rss2_feeds) otherwise moodle will not be able&lt;br /&gt;
to drop the table upon removal of the block from the system.&lt;br /&gt;
Here is an example for mysql.sql:&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE prefix_rss2_feeds (&lt;br /&gt;
 `id` int(11) NOT NULL auto_increment,&lt;br /&gt;
 `userid` int(11) NOT NULL default &#039;0&#039;,&lt;br /&gt;
 `title` text NOT NULL default &#039;&#039;,&lt;br /&gt;
 `description` text NOT NULL default &#039;&#039;,&lt;br /&gt;
 `url` varchar(255) NOT NULL default &#039;&#039;,&lt;br /&gt;
 `pingbacktokenurl` varchar(255) NOT NULL default &#039;&#039;,&lt;br /&gt;
 PRIMARY KEY  (`id`)&lt;br /&gt;
) TYPE=MyISAM  COMMENT=&#039;Remote news feed information.&#039;;&lt;br /&gt;
&lt;br /&gt;
Pay attention that, furthermore, you might want to add a&lt;br /&gt;
mysql.php and postgres7.php page that contains update&lt;br /&gt;
routines for upgrading the database tables with evolving&lt;br /&gt;
version numbers of the block. In case you use that be sure&lt;br /&gt;
that you provide the necessary structure (again function&lt;br /&gt;
name should be like the block name + &amp;quot;_upgrade&amp;quot;!).&lt;br /&gt;
Here is an example:&lt;br /&gt;
&lt;br /&gt;
function rss_pingback_upgrade( $oldversion ) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    if ($oldversion &amp;lt; 2003111500) {&lt;br /&gt;
       # Do something ...&lt;br /&gt;
    }&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Windows_installation&amp;diff=26947</id>
		<title>Windows installation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Windows_installation&amp;diff=26947"/>
		<updated>2007-09-12T14:40:13Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Manual Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Installation Packages==&lt;br /&gt;
If you are running a small (less than 30 users) Moodle server or just want to test Moodle on your Windows XP PC, pre-built packages are available for you to use. Here are links to pages containing step-by-step instructions for installing Moodle using install packages:&lt;br /&gt;
&lt;br /&gt;
*[[Complete install packages]] for most Windows versions&lt;br /&gt;
&lt;br /&gt;
*[[Installing_AMP#Windows| This section has a quick]] way to install a complete package on a Windows XP machine&lt;br /&gt;
&lt;br /&gt;
*[[Windows installation using XAMPP|Installation guide for Windows using XAMPP]] in case you want to retrofit&lt;br /&gt;
&lt;br /&gt;
*[[Installation guide for Windows using EasyPHP]]&lt;br /&gt;
&lt;br /&gt;
*[[Installation guide - Moodle for Windows on a USB Memory Stick]]&lt;br /&gt;
&lt;br /&gt;
== Manual Installation ==&lt;br /&gt;
For medium to large installations (e.g. a college, university or business), it is best practice to install Moodle on your server manually. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Plan your system capacity&#039;&#039;&#039;. This involves estimating the appropriate hardware to support the number of users in your organisation. See [[Installing Moodle]] in the How Many Users section for a method of doing this.&lt;br /&gt;
* &#039;&#039;&#039;Install your database server&#039;&#039;&#039;. You have a choice of [http://dev.mysql.com/downloads/ MySQL] (recommended), [http://www.postgresql.org/download/ PostgreSQL], [[Installing MSSQL for PHP | Microsoft SQL Server 2005]] (only for Moodle 1.7 or later) or Oracle.&lt;br /&gt;
* &#039;&#039;&#039;Install PHP&#039;&#039;&#039;. See [http://www.peterguy.com/php/install_IIS6.html How to install PHP 5.x on Windows Server 2003 with IIS 6] for instructions.&lt;br /&gt;
* &#039;&#039;&#039;Install your web server&#039;&#039;&#039;. You have several choices - the decision as to which one to use will depend on your in-house expertise and your required level of sustainability:&lt;br /&gt;
**Apache 2 is recommended as the most tested and popular for Moodle installations. See these instructions for [[Installing Apache on Windows |manually installing Apache 2 on Windows]].&lt;br /&gt;
**IIS 6 can also be used. See the Windows forum for guidance on installation and, in particular, permission settings for using Moodle with IIS.&lt;br /&gt;
**Other webservers are known to install on Windows, e.g. Lighttpd, so you may wish to experiment with these if available memory is low on your server.&lt;br /&gt;
* &#039;&#039;&#039;Install Moodle&#039;&#039;&#039; by getting the standard installation for Moodle from [http://download.moodle.org/ http://download.moodle.org/] and read [[Installing Moodle]] which has detailed generic information.&lt;br /&gt;
* &#039;&#039;&#039;Setup backups&#039;&#039;&#039;. Once Moodle is setup and configured, you should setup backups of the system in case of failure or loss of data. &lt;br /&gt;
** &#039;&#039;&#039;To perform full site backups&#039;&#039;&#039; you need to backup the moodledata and moodle directories, Apache webserver configuration (httpd.conf) if you&#039;re using Apache, PHP configuration (php.ini) and any php extensions which are non-standard, and the mysql database. To do this use the integrated backup program (Start -&amp;gt; All Programs -&amp;gt; Accessories -&amp;gt; System Tools -&amp;gt; Backup) or your own proprietary backup software (e.g. BackupExec). To backup your mysql database see the [[Backup FAQ]].&lt;br /&gt;
** &#039;&#039;&#039;To perform course backups&#039;&#039;&#039; see the [[Course backup]] page.&lt;br /&gt;
** You should also perform a &#039;&#039;&#039;state backup&#039;&#039;&#039; of the [http://technet2.microsoft.com/WindowsServer/en/library/921f0ed5-523d-48ac-8825-e850b0e548841033.mspx?mfr=true server] or [http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntbackup_backup_sysstate.mspx?mfr=true PC]. This is especially important if you&#039;re using IIS as this will backup the IIS metabase. &lt;br /&gt;
* &#039;&#039;&#039;Check your server security and performance&#039;&#039;&#039;. It is also good practice to read the [[Performance]] and [[Security]] documentation. Although much of the content is targetted at Linux/Unix users, there is a growing amount for Windows systems.&lt;br /&gt;
* Set-up your &#039;&#039;&#039;Active Directory authentication&#039;&#039;&#039;. You can use the standard [[LDAP authentication]] which prompts users with a username/password, or [[NTLM authentication | integrated NTLM authentication]] which does not require campus users to enter their credentials.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/view.php?id=6799 Windows-based server forum] is the main forum for asking questions about your Moodle Windows installation.&lt;br /&gt;
* [[Installing APC in Windows]] contains instructions for using a PHP accelerator to reduce processor load.&lt;br /&gt;
* [[Cron | Installing Cron on Windows]] for setting up the Moodle scheduled task.&lt;br /&gt;
* [[Configuring aspell on Windows 2003 Server]] for setting up the Moodle spell checker.&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=56835 Running Apache and IIS on the same server] forum discussion.&lt;br /&gt;
* [http://moodle.org/blog/index.php?userid=212926&amp;amp;courseid=55 A Windows installation log.]&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26893</id>
		<title>Installing MSSQL for PHP</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26893"/>
		<updated>2007-09-11T11:28:58Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Using FreeTDS on Windows */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.7}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;before&#039;&#039;&#039; installing Moodle itself.&lt;br /&gt;
&lt;br /&gt;
First of all, minimum required version of MSSQL has been stabilised to MSSQL 2005 (v.9), although it &#039;&#039;&#039;might work with MSSQL 2000 (v.8) or newer&#039;&#039;&#039;. All the development process has been performed using MSSQL 2005 and there could be some &#039;&#039;&#039;unknown problems&#039;&#039;&#039; with previous releases.&lt;br /&gt;
&lt;br /&gt;
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 this problems [[Development:XMLDB problems#MSSQL, PHP, UTF-8 and UCS-2|here]].&lt;br /&gt;
&lt;br /&gt;
So, in order to allow PHP (i.e. Moodle) to access to MSSQL DBs properly we have to install a &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; to save us from the problems related above. See the sections below for details about the various options.&lt;br /&gt;
&lt;br /&gt;
== Installation overview ==&lt;br /&gt;
&lt;br /&gt;
1. Get MSSQL Server installed and running.&lt;br /&gt;
:Make sure that you choose mixed authentication (Windows and local accounts) to keep things simpler later.  You&#039;ll be asked to define the  &amp;quot;sa&amp;quot; account password (it&#039;s the default System Administrator account which has full access to all databases by default).&lt;br /&gt;
&lt;br /&gt;
2. Make sure MS SQL Server can accept incoming TCP/IP connections on port 1433 (the standard one).&lt;br /&gt;
:You might need to explicitly allow this in your Windows firewall (see the Control Panel).  You may also need to edit options in the :&#039;&#039;&#039;SQL Server Configuration Manager&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Network Configuration&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Protocols&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;TCP/IP enabled&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
3. Open the &amp;quot;SQL Server Management Studio&amp;quot; and create a new empty database.  If you are using the &amp;quot;sa&amp;quot; account then you don&#039;t need to do anything else here.&lt;br /&gt;
&lt;br /&gt;
4. Configure these settings in your created (and still empty) database:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
5. Get PHP installed with a web server.   Unless you want to do it under IIS or some other way, the packages on the [http://download.moodle.org Moodle download page] are a good solution.&lt;br /&gt;
&lt;br /&gt;
6. Choose one of the following specific sections for your server to install the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; installed and running properly on your PHP box.&lt;br /&gt;
&lt;br /&gt;
7. Set the following settings in your php.ini file&lt;br /&gt;
:* mssql.textlimit = 20971520&lt;br /&gt;
:* mssql.textsize = 20971520&lt;br /&gt;
:Also, don&#039;t forget to set one of the following &#039;&#039;&#039;alternatives&#039;&#039;&#039;, in order to get all the data properly &amp;quot;slashed&amp;quot;:&lt;br /&gt;
:* magic_quotes_gpc = Off  &#039;&#039;&#039;or&#039;&#039;&#039;&lt;br /&gt;
:* magic_quotes_gpc = On &#039;&#039;&#039;and&#039;&#039;&#039; magic_quotes_sybase = On &lt;br /&gt;
&lt;br /&gt;
8. With all this properly configured, you can continue with a [[Installing Moodle|standard Moodle installation]].&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Unix ==&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
Note that the download link above is a &#039;&#039;&#039;source download&#039;&#039;&#039;, so you will need to install and compile it properly.&lt;br /&gt;
&lt;br /&gt;
Once downloaded and uncompressed you must &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039; it. This will deploy some stuff in the &amp;quot;/usr/local&amp;quot; directory of your machine, mainly:&lt;br /&gt;
* /usr/local/etc: where the freetds conf files will reside.&lt;br /&gt;
* /usr/local/lib: where compiled libraries will reside.&lt;br /&gt;
* /usr/local/bin: where some executables will reside.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
At this point, and previously to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;, you can test conectivity with your MSSQL DB using the &amp;quot;/usr/local/bin/tsql&amp;quot; executable. Just do this:&lt;br /&gt;
&lt;br /&gt;
  tsql -S serverhost -U dbowner -P dbpassword&lt;br /&gt;
&lt;br /&gt;
If everything is ok, you&#039;ll get this output:&lt;br /&gt;
&lt;br /&gt;
  locale is &amp;quot;es_ES.UTF-8&amp;quot;&lt;br /&gt;
  locale charset is &amp;quot;UTF-8&amp;quot;&lt;br /&gt;
  1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
just type, for example:&lt;br /&gt;
&lt;br /&gt;
  sp_help sysobjects&lt;br /&gt;
&lt;br /&gt;
and you might get some output from DB. Finally type:&lt;br /&gt;
&lt;br /&gt;
  exit&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be out from the &amp;quot;tsql&amp;quot; command line interpreter.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built, configured and tested FreeTDS it is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; that will provide us with the capacity of handling MSSQL DBs from within Moodle. To do so, you&#039;ll need configure your PHP server adding this new option to the usual ones:&lt;br /&gt;
&lt;br /&gt;
  --with-mssql=/usr/local/ &lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by FreeTDS.&lt;br /&gt;
&lt;br /&gt;
Finally, configure your Moodle config.php with this DB related info and continue with a normal Moodle install:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;         // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;xxx.xxx.xxx.xxx&#039;; // IP of the MSSQL server (also proper hostname is allowed)&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;          // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;    // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Windows ==&lt;br /&gt;
&lt;br /&gt;
If your web server is on Windows, use &#039;&#039;&#039;php_dblib.dll&#039;&#039;&#039; from Frank Kromann ([http://kromann.info/article.php?Id=11062598797760000 original details here]). Despite the name, it&#039;s FreeTDS compiled for Windows.  Many thanks to Frank for providing this DLL.  Here&#039;s how to set it up:&lt;br /&gt;
&lt;br /&gt;
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.)  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_1-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.1.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_2-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.2.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php6-Release_TS/php_dblib.dll php_dblib.dll for PHP 6.x]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. FreeTDS requires the .NET Framework v1.1 to be installed.  You can [http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&amp;amp;DisplayLang=en download it from the Microsoft website] along with its [http://www.microsoft.com/downloads/details.aspx?FamilyID=a8f5654f-088e-40b2-bbdb-a83353618b38&amp;amp;DisplayLang=en service pack].  Alternatively, if you do not wish to install this framework, you can [http://kromann.info/ms-libs/msvcr71.dll download the required DLL] from Frank&#039;s site, and save it into your /PHP root directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Edit your /PHP/php.ini file and add this line:&lt;br /&gt;
&lt;br /&gt;
  extension=php_dblib.dll &lt;br /&gt;
&lt;br /&gt;
Make sure that any lines referring to the php_mssql.dll extension are DISABLED (commented out).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a file called C:\freetds.conf with:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;        // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;localhost&#039;;      // assuming MS SQL is on the same server, otherwise use an IP&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;         // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have a config.php file yet, it can be generated as normal from the Moodle installer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Restart or start your web server.  If Moodle still cannot communicate with the database server, please turn display_startup_errors to &amp;quot;On&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Using ODBTP on Unix or Windows ==&lt;br /&gt;
&lt;br /&gt;
You can download ODBTP from http://odbtp.sourceforge.net/. Also you will access to the documentation from the same page.&lt;br /&gt;
&lt;br /&gt;
The downloaded package includes both the source code and some binaries to be installed in the server and some ready-to-use &#039;&#039;&#039;mssql extension alternatives&#039;&#039;&#039; for some platforms/PHP versions (so you won&#039;t need to compile it if your PHP server/version binary package is present).&lt;br /&gt;
&lt;br /&gt;
First of all, we have to install the Win32 service that comes with the package. Let&#039;s assume that it&#039;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).&lt;br /&gt;
&lt;br /&gt;
To do do, following the instructions present in http://odbtp.sourceforge.net/install.html, you must:&lt;br /&gt;
&lt;br /&gt;
# Create a directory on the Windows host where the service program files will reside, i.e., md odbtp.&lt;br /&gt;
# Copy the files odbtpctl.exe, odbtpsrv.exe and odbtpsrv.ini files from the winservice directory into the directory created in step 1.&lt;br /&gt;
# Edit the file odbtpsrv.ini of the previous step and this line: &amp;lt;pre&amp;gt;MaxRequestSize=20971520&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open a command prompt (cmd) window on the Windows host.&lt;br /&gt;
# Change to the directory to which the service program files were copied, i.e., cd odbtp.&lt;br /&gt;
# Run the following commands to install and start the service:&lt;br /&gt;
#*   odbtpctl install&lt;br /&gt;
#*   odbtpctl start&lt;br /&gt;
# With these steps you should have one new service running in your host called &amp;quot;odbtp&amp;quot;. Verify it&#039;s present and running in the &amp;quot;Services&amp;quot; control panel.&lt;br /&gt;
# Don&#039;t forget to enable TCP/IP incoming connections to port 2799 in the host you have installed the service!&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;. First of all, verify if, in the downloaded package, under the &amp;quot;php&amp;quot; dir, there is one extension suitable for your PHP server/version. If it&#039;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&#039;s important to point that, inside each directory, you&#039;ll find &#039;&#039;&#039;two different&#039;&#039;&#039; libraries/dll files. The one that must be copied to the extensions dir is the one called &#039;&#039;&#039;&amp;quot;php_odbtp_mssql.xxx&amp;quot;&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
If in the downloaded package isn&#039;t present the extension matching your PHP platform/version, you should build if from source files. To do that, just &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039;. That will create some stuff under &amp;quot;/usr/local&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built ODBTP is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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:&lt;br /&gt;
&lt;br /&gt;
  --with-odbtp-mssql&lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by ODBTP.&lt;br /&gt;
&lt;br /&gt;
Finally, independently if we are using the binary extension provided in the download or if you have built it from source files, it&#039;s time to configure the extension. To do so, add this lines, if no present, to your php.ini file:&lt;br /&gt;
&lt;br /&gt;
  extension=php_odbtp.dll&lt;br /&gt;
&lt;br /&gt;
(only for Win32 PHP servers!)&lt;br /&gt;
&lt;br /&gt;
And, for all the server platforms: &lt;br /&gt;
&lt;br /&gt;
  [odbtp]&lt;br /&gt;
  odbtp.interface_file = &amp;quot;/path/to/your/odbtp.conf&amp;quot;&lt;br /&gt;
  odbtp.datetime_format = mdyhmsf&lt;br /&gt;
  odbtp.detach_default_queries = yes&lt;br /&gt;
&lt;br /&gt;
(where &#039;&#039;/path/to/your/odbtp.conf&amp;quot; is usually &amp;quot;/usr/local/etc/odbtp.conf&amp;quot;&amp;quot; for Unix systems and &amp;quot;C:\odbtp\odbtp.conf&amp;quot; for Windows systems)&lt;br /&gt;
&lt;br /&gt;
Then, edit such &amp;quot;odbtp.conf&amp;quot; file and put there these contents:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
  odbtp host = xxx.xxx.xxx (ip or hostname of the Win32 box running the ODBTP service)&lt;br /&gt;
  type = mssql&lt;br /&gt;
  unicode sql = yes&lt;br /&gt;
  use row cache = yes&lt;br /&gt;
  right trim text = yes&lt;br /&gt;
  var data size = 20971520&lt;br /&gt;
&lt;br /&gt;
With this, your PHP server will be able to connect with the MSSQL DB server using ODBTP. From here, just continue with the installation.&lt;br /&gt;
&lt;br /&gt;
Finally, if you find the ODBTP executables and &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
== Using ODBC on Windows ==&lt;br /&gt;
&lt;br /&gt;
{{Not for production sites}}&lt;br /&gt;
&lt;br /&gt;
1. Go to the &#039;&#039;&#039;Administrative Tools&#039;&#039;&#039;  control panel, then the &#039;&#039;&#039;Data Sources (ODBC)&#039;&#039;&#039; panel.&lt;br /&gt;
&lt;br /&gt;
2. Configure one new System/User DSN (call it, for example &amp;quot;moodle&amp;quot;). Dont forget to enable these options if the driver asks for them:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
3. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;odbc_mssql&#039;;     // Note this is different to all the other configs on this page!&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;moodle&#039;;         // Where this matches the Data source name you chose above&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;&#039;&#039;&#039;&#039;&#039;&#039;;               // Keep it blank!!&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
4. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Related links ==&lt;br /&gt;
&lt;br /&gt;
[[Installing Oracle for PHP]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:XMLDB]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26807</id>
		<title>Installing MSSQL for PHP</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26807"/>
		<updated>2007-09-10T09:50:55Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Using FreeTDS on Windows */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.7}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;before&#039;&#039;&#039; installing Moodle itself.&lt;br /&gt;
&lt;br /&gt;
First of all, minimum required version of MSSQL has been stabilised to MSSQL 2005 (v.9), although it &#039;&#039;&#039;might work with MSSQL 2000 (v.8) or newer&#039;&#039;&#039;. All the development process has been performed using MSSQL 2005 and there could be some &#039;&#039;&#039;unknown problems&#039;&#039;&#039; with previous releases.&lt;br /&gt;
&lt;br /&gt;
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 this problems [[Development:XMLDB problems#MSSQL, PHP, UTF-8 and UCS-2|here]].&lt;br /&gt;
&lt;br /&gt;
So, in order to allow PHP (i.e. Moodle) to access to MSSQL DBs properly we have to install a &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; to save us from the problems related above. See the sections below for details about the various options.&lt;br /&gt;
&lt;br /&gt;
== Installation overview ==&lt;br /&gt;
&lt;br /&gt;
1. Get MSSQL Server installed and running.&lt;br /&gt;
:Make sure that you choose mixed authentication (Windows and local accounts) to keep things simpler later.  You&#039;ll be asked to define the  &amp;quot;sa&amp;quot; account password (it&#039;s the default System Administrator account which has full access to all databases by default).&lt;br /&gt;
&lt;br /&gt;
2. Make sure MS SQL Server can accept incoming TCP/IP connections on port 1433 (the standard one).&lt;br /&gt;
:You might need to explicitly allow this in your Windows firewall (see the Control Panel).  You may also need to edit options in the :&#039;&#039;&#039;SQL Server Configuration Manager&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Network Configuration&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Protocols&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;TCP/IP enabled&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
3. Open the &amp;quot;SQL Server Management Studio&amp;quot; and create a new empty database.  If you are using the &amp;quot;sa&amp;quot; account then you don&#039;t need to do anything else here.&lt;br /&gt;
&lt;br /&gt;
4. Configure these settings in your created (and still empty) database:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
5. Get PHP installed with a web server.   Unless you want to do it under IIS or some other way, the packages on the [http://download.moodle.org Moodle download page] are a good solution.&lt;br /&gt;
&lt;br /&gt;
6. Choose one of the following specific sections for your server to install the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; installed and running properly on your PHP box.&lt;br /&gt;
&lt;br /&gt;
7. Set the following settings in your php.ini file&lt;br /&gt;
:* mssql.textlimit = 20971520&lt;br /&gt;
:* mssql.textsize = 20971520&lt;br /&gt;
:Also, don&#039;t forget to set one of the following &#039;&#039;&#039;alternatives&#039;&#039;&#039;, in order to get all the data properly &amp;quot;slashed&amp;quot;:&lt;br /&gt;
:* magic_quotes_gpc = Off  &#039;&#039;&#039;or&#039;&#039;&#039;&lt;br /&gt;
:* magic_quotes_gpc = On &#039;&#039;&#039;and&#039;&#039;&#039; magic_quotes_sybase = On &lt;br /&gt;
&lt;br /&gt;
8. With all this properly configured, you can continue with a [[Installing Moodle|standard Moodle installation]].&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Unix ==&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
Note that the download link above is a &#039;&#039;&#039;source download&#039;&#039;&#039;, so you will need to install and compile it properly.&lt;br /&gt;
&lt;br /&gt;
Once downloaded and uncompressed you must &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039; it. This will deploy some stuff in the &amp;quot;/usr/local&amp;quot; directory of your machine, mainly:&lt;br /&gt;
* /usr/local/etc: where the freetds conf files will reside.&lt;br /&gt;
* /usr/local/lib: where compiled libraries will reside.&lt;br /&gt;
* /usr/local/bin: where some executables will reside.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
At this point, and previously to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;, you can test conectivity with your MSSQL DB using the &amp;quot;/usr/local/bin/tsql&amp;quot; executable. Just do this:&lt;br /&gt;
&lt;br /&gt;
  tsql -S serverhost -U dbowner -P dbpassword&lt;br /&gt;
&lt;br /&gt;
If everything is ok, you&#039;ll get this output:&lt;br /&gt;
&lt;br /&gt;
  locale is &amp;quot;es_ES.UTF-8&amp;quot;&lt;br /&gt;
  locale charset is &amp;quot;UTF-8&amp;quot;&lt;br /&gt;
  1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
just type, for example:&lt;br /&gt;
&lt;br /&gt;
  sp_help sysobjects&lt;br /&gt;
&lt;br /&gt;
and you might get some output from DB. Finally type:&lt;br /&gt;
&lt;br /&gt;
  exit&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be out from the &amp;quot;tsql&amp;quot; command line interpreter.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built, configured and tested FreeTDS it is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; that will provide us with the capacity of handling MSSQL DBs from within Moodle. To do so, you&#039;ll need configure your PHP server adding this new option to the usual ones:&lt;br /&gt;
&lt;br /&gt;
  --with-mssql=/usr/local/ &lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by FreeTDS.&lt;br /&gt;
&lt;br /&gt;
Finally, configure your Moodle config.php with this DB related info and continue with a normal Moodle install:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;         // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;xxx.xxx.xxx.xxx&#039;; // IP of the MSSQL server (also proper hostname is allowed)&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;          // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;    // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Windows ==&lt;br /&gt;
&lt;br /&gt;
If your web server is on Windows, use &#039;&#039;&#039;php_dblib.dll&#039;&#039;&#039; from Frank Kromann ([http://kromann.info/article.php?Id=11062598797760000 original details here]). Despite the name, it&#039;s FreeTDS compiled for Windows.  Many thanks to Frank for providing this DLL.  Here&#039;s how to set it up:&lt;br /&gt;
&lt;br /&gt;
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.)  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_1-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.1.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_2-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.2.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php6-Release_TS/php_dblib.dll php_dblib.dll for PHP 6.x]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. FreeTDS requires the .NET Framework v1.1 to be installed.  You can [http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&amp;amp;DisplayLang=en download it from the Microsoft website] along with its [http://www.microsoft.com/downloads/details.aspx?FamilyID=a8f5654f-088e-40b2-bbdb-a83353618b38&amp;amp;DisplayLang=en service pack].  Alternatively, if you do not wish to install this framework, you can [http://kromann.info/ms-libs/msvcr71.dll download the required DLL] from Frank&#039;s site, and save it into your /PHP root directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Edit your /PHP/php.ini file and add this line:&lt;br /&gt;
&lt;br /&gt;
  extension=php_dblib.dll &lt;br /&gt;
&lt;br /&gt;
Make sure that any lines referring to the php_mssql.dll extension are DISABLED (commented out).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a file called C:\freetds.conf with:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;        // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;localhost&#039;;      // assuming MS SQL is on the same server, otherwise use an IP&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;         // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have a config.php file yet, it can be generated as normal from the Moodle installer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Restart or start your web server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Using ODBTP on Unix or Windows ==&lt;br /&gt;
&lt;br /&gt;
You can download ODBTP from http://odbtp.sourceforge.net/. Also you will access to the documentation from the same page.&lt;br /&gt;
&lt;br /&gt;
The downloaded package includes both the source code and some binaries to be installed in the server and some ready-to-use &#039;&#039;&#039;mssql extension alternatives&#039;&#039;&#039; for some platforms/PHP versions (so you won&#039;t need to compile it if your PHP server/version binary package is present).&lt;br /&gt;
&lt;br /&gt;
First of all, we have to install the Win32 service that comes with the package. Let&#039;s assume that it&#039;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).&lt;br /&gt;
&lt;br /&gt;
To do do, following the instructions present in http://odbtp.sourceforge.net/install.html, you must:&lt;br /&gt;
&lt;br /&gt;
# Create a directory on the Windows host where the service program files will reside, i.e., md odbtp.&lt;br /&gt;
# Copy the files odbtpctl.exe, odbtpsrv.exe and odbtpsrv.ini files from the winservice directory into the directory created in step 1.&lt;br /&gt;
# Edit the file odbtpsrv.ini of the previous step and this line: &amp;lt;pre&amp;gt;MaxRequestSize=20971520&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open a command prompt (cmd) window on the Windows host.&lt;br /&gt;
# Change to the directory to which the service program files were copied, i.e., cd odbtp.&lt;br /&gt;
# Run the following commands to install and start the service:&lt;br /&gt;
#*   odbtpctl install&lt;br /&gt;
#*   odbtpctl start&lt;br /&gt;
# With these steps you should have one new service running in your host called &amp;quot;odbtp&amp;quot;. Verify it&#039;s present and running in the &amp;quot;Services&amp;quot; control panel.&lt;br /&gt;
# Don&#039;t forget to enable TCP/IP incoming connections to port 2799 in the host you have installed the service!&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;. First of all, verify if, in the downloaded package, under the &amp;quot;php&amp;quot; dir, there is one extension suitable for your PHP server/version. If it&#039;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&#039;s important to point that, inside each directory, you&#039;ll find &#039;&#039;&#039;two different&#039;&#039;&#039; libraries/dll files. The one that must be copied to the extensions dir is the one called &#039;&#039;&#039;&amp;quot;php_odbtp_mssql.xxx&amp;quot;&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
If in the downloaded package isn&#039;t present the extension matching your PHP platform/version, you should build if from source files. To do that, just &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039;. That will create some stuff under &amp;quot;/usr/local&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built ODBTP is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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:&lt;br /&gt;
&lt;br /&gt;
  --with-odbtp-mssql&lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by ODBTP.&lt;br /&gt;
&lt;br /&gt;
Finally, independently if we are using the binary extension provided in the download or if you have built it from source files, it&#039;s time to configure the extension. To do so, add this lines, if no present, to your php.ini file:&lt;br /&gt;
&lt;br /&gt;
  extension=php_odbtp.dll&lt;br /&gt;
&lt;br /&gt;
(only for Win32 PHP servers!)&lt;br /&gt;
&lt;br /&gt;
And, for all the server platforms: &lt;br /&gt;
&lt;br /&gt;
  [odbtp]&lt;br /&gt;
  odbtp.interface_file = &amp;quot;/path/to/your/odbtp.conf&amp;quot;&lt;br /&gt;
  odbtp.datetime_format = mdyhmsf&lt;br /&gt;
  odbtp.detach_default_queries = yes&lt;br /&gt;
&lt;br /&gt;
(where &#039;&#039;/path/to/your/odbtp.conf&amp;quot; is usually &amp;quot;/usr/local/etc/odbtp.conf&amp;quot;&amp;quot; for Unix systems and &amp;quot;C:\odbtp\odbtp.conf&amp;quot; for Windows systems)&lt;br /&gt;
&lt;br /&gt;
Then, edit such &amp;quot;odbtp.conf&amp;quot; file and put there these contents:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
  odbtp host = xxx.xxx.xxx (ip or hostname of the Win32 box running the ODBTP service)&lt;br /&gt;
  type = mssql&lt;br /&gt;
  unicode sql = yes&lt;br /&gt;
  use row cache = yes&lt;br /&gt;
  right trim text = yes&lt;br /&gt;
  var data size = 20971520&lt;br /&gt;
&lt;br /&gt;
With this, your PHP server will be able to connect with the MSSQL DB server using ODBTP. From here, just continue with the installation.&lt;br /&gt;
&lt;br /&gt;
Finally, if you find the ODBTP executables and &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
== Using ODBC on Windows ==&lt;br /&gt;
&lt;br /&gt;
{{Not for production sites}}&lt;br /&gt;
&lt;br /&gt;
1. Go to the &#039;&#039;&#039;Administrative Tools&#039;&#039;&#039;  control panel, then the &#039;&#039;&#039;Data Sources (ODBC)&#039;&#039;&#039; panel.&lt;br /&gt;
&lt;br /&gt;
2. Configure one new System/User DSN (call it, for example &amp;quot;moodle&amp;quot;). Dont forget to enable these options if the driver asks for them:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
3. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;odbc_mssql&#039;;     // Note this is different to all the other configs on this page!&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;moodle&#039;;         // Where this matches the Data source name you chose above&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;&#039;&#039;&#039;&#039;&#039;&#039;;               // Keep it blank!!&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
4. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Related links ==&lt;br /&gt;
&lt;br /&gt;
[[Installing Oracle for PHP]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:XMLDB]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26806</id>
		<title>Installing MSSQL for PHP</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26806"/>
		<updated>2007-09-10T09:29:35Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Using FreeTDS on Windows */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.7}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;before&#039;&#039;&#039; installing Moodle itself.&lt;br /&gt;
&lt;br /&gt;
First of all, minimum required version of MSSQL has been stabilised to MSSQL 2005 (v.9), although it &#039;&#039;&#039;might work with MSSQL 2000 (v.8) or newer&#039;&#039;&#039;. All the development process has been performed using MSSQL 2005 and there could be some &#039;&#039;&#039;unknown problems&#039;&#039;&#039; with previous releases.&lt;br /&gt;
&lt;br /&gt;
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 this problems [[Development:XMLDB problems#MSSQL, PHP, UTF-8 and UCS-2|here]].&lt;br /&gt;
&lt;br /&gt;
So, in order to allow PHP (i.e. Moodle) to access to MSSQL DBs properly we have to install a &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; to save us from the problems related above. See the sections below for details about the various options.&lt;br /&gt;
&lt;br /&gt;
== Installation overview ==&lt;br /&gt;
&lt;br /&gt;
1. Get MSSQL Server installed and running.&lt;br /&gt;
:Make sure that you choose mixed authentication (Windows and local accounts) to keep things simpler later.  You&#039;ll be asked to define the  &amp;quot;sa&amp;quot; account password (it&#039;s the default System Administrator account which has full access to all databases by default).&lt;br /&gt;
&lt;br /&gt;
2. Make sure MS SQL Server can accept incoming TCP/IP connections on port 1433 (the standard one).&lt;br /&gt;
:You might need to explicitly allow this in your Windows firewall (see the Control Panel).  You may also need to edit options in the :&#039;&#039;&#039;SQL Server Configuration Manager&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Network Configuration&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;Protocols&#039;&#039;&#039; -&amp;gt; &#039;&#039;&#039;TCP/IP enabled&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
3. Open the &amp;quot;SQL Server Management Studio&amp;quot; and create a new empty database.  If you are using the &amp;quot;sa&amp;quot; account then you don&#039;t need to do anything else here.&lt;br /&gt;
&lt;br /&gt;
4. Configure these settings in your created (and still empty) database:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
5. Get PHP installed with a web server.   Unless you want to do it under IIS or some other way, the packages on the [http://download.moodle.org Moodle download page] are a good solution.&lt;br /&gt;
&lt;br /&gt;
6. Choose one of the following specific sections for your server to install the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; installed and running properly on your PHP box.&lt;br /&gt;
&lt;br /&gt;
7. Set the following settings in your php.ini file&lt;br /&gt;
:* mssql.textlimit = 20971520&lt;br /&gt;
:* mssql.textsize = 20971520&lt;br /&gt;
:Also, don&#039;t forget to set one of the following &#039;&#039;&#039;alternatives&#039;&#039;&#039;, in order to get all the data properly &amp;quot;slashed&amp;quot;:&lt;br /&gt;
:* magic_quotes_gpc = Off  &#039;&#039;&#039;or&#039;&#039;&#039;&lt;br /&gt;
:* magic_quotes_gpc = On &#039;&#039;&#039;and&#039;&#039;&#039; magic_quotes_sybase = On &lt;br /&gt;
&lt;br /&gt;
8. With all this properly configured, you can continue with a [[Installing Moodle|standard Moodle installation]].&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Unix ==&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
Note that the download link above is a &#039;&#039;&#039;source download&#039;&#039;&#039;, so you will need to install and compile it properly.&lt;br /&gt;
&lt;br /&gt;
Once downloaded and uncompressed you must &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039; it. This will deploy some stuff in the &amp;quot;/usr/local&amp;quot; directory of your machine, mainly:&lt;br /&gt;
* /usr/local/etc: where the freetds conf files will reside.&lt;br /&gt;
* /usr/local/lib: where compiled libraries will reside.&lt;br /&gt;
* /usr/local/bin: where some executables will reside.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
At this point, and previously to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;, you can test conectivity with your MSSQL DB using the &amp;quot;/usr/local/bin/tsql&amp;quot; executable. Just do this:&lt;br /&gt;
&lt;br /&gt;
  tsql -S serverhost -U dbowner -P dbpassword&lt;br /&gt;
&lt;br /&gt;
If everything is ok, you&#039;ll get this output:&lt;br /&gt;
&lt;br /&gt;
  locale is &amp;quot;es_ES.UTF-8&amp;quot;&lt;br /&gt;
  locale charset is &amp;quot;UTF-8&amp;quot;&lt;br /&gt;
  1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
just type, for example:&lt;br /&gt;
&lt;br /&gt;
  sp_help sysobjects&lt;br /&gt;
&lt;br /&gt;
and you might get some output from DB. Finally type:&lt;br /&gt;
&lt;br /&gt;
  exit&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be out from the &amp;quot;tsql&amp;quot; command line interpreter.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built, configured and tested FreeTDS it is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; that will provide us with the capacity of handling MSSQL DBs from within Moodle. To do so, you&#039;ll need configure your PHP server adding this new option to the usual ones:&lt;br /&gt;
&lt;br /&gt;
  --with-mssql=/usr/local/ &lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by FreeTDS.&lt;br /&gt;
&lt;br /&gt;
Finally, configure your Moodle config.php with this DB related info and continue with a normal Moodle install:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;         // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;xxx.xxx.xxx.xxx&#039;; // IP of the MSSQL server (also proper hostname is allowed)&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;          // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;    // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
== Using FreeTDS on Windows ==&lt;br /&gt;
&lt;br /&gt;
If your web server is on Windows, use &#039;&#039;&#039;php_dblib.dll&#039;&#039;&#039; from Frank Kromann ([http://kromann.info/article.php?Id=11062598797760000 original details here]). Despite the name, it&#039;s FreeTDS compiled for Windows.  Many thanks to Frank for providing this DLL.  Here&#039;s how to set it up:&lt;br /&gt;
&lt;br /&gt;
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.)  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_1-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.1.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php5_2-Release_TS/php_dblib.dll php_dblib.dll for PHP 5.2.x]&lt;br /&gt;
&lt;br /&gt;
[http://kromann.info/php6-Release_TS/php_dblib.dll php_dblib.dll for PHP 6.x]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Edit your php.ini and add this line:&lt;br /&gt;
&lt;br /&gt;
  extension=php_dblib.dll &lt;br /&gt;
&lt;br /&gt;
Make sure that any lines referring to the php_mssql.dll extension are DISABLED (commented out).&lt;br /&gt;
&lt;br /&gt;
3. Create a file called C:\freetds.conf with:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
      host = xxx.xxx.xxx.xxx (ip of the MSSQL server)&lt;br /&gt;
      port = 1433&lt;br /&gt;
      client charset = UTF-8&lt;br /&gt;
      tds version = 7.0&lt;br /&gt;
      text size = 20971520&lt;br /&gt;
&lt;br /&gt;
4. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;mssql_n&#039;;        // Required&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;localhost&#039;;      // assuming MS SQL is on the same server, otherwise use an IP&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;moodle&#039;;         // or whatever you called the database you created&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
4. Restart or start your web server.&lt;br /&gt;
&lt;br /&gt;
5. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Using ODBTP on Unix or Windows ==&lt;br /&gt;
&lt;br /&gt;
You can download ODBTP from http://odbtp.sourceforge.net/. Also you will access to the documentation from the same page.&lt;br /&gt;
&lt;br /&gt;
The downloaded package includes both the source code and some binaries to be installed in the server and some ready-to-use &#039;&#039;&#039;mssql extension alternatives&#039;&#039;&#039; for some platforms/PHP versions (so you won&#039;t need to compile it if your PHP server/version binary package is present).&lt;br /&gt;
&lt;br /&gt;
First of all, we have to install the Win32 service that comes with the package. Let&#039;s assume that it&#039;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).&lt;br /&gt;
&lt;br /&gt;
To do do, following the instructions present in http://odbtp.sourceforge.net/install.html, you must:&lt;br /&gt;
&lt;br /&gt;
# Create a directory on the Windows host where the service program files will reside, i.e., md odbtp.&lt;br /&gt;
# Copy the files odbtpctl.exe, odbtpsrv.exe and odbtpsrv.ini files from the winservice directory into the directory created in step 1.&lt;br /&gt;
# Edit the file odbtpsrv.ini of the previous step and this line: &amp;lt;pre&amp;gt;MaxRequestSize=20971520&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open a command prompt (cmd) window on the Windows host.&lt;br /&gt;
# Change to the directory to which the service program files were copied, i.e., cd odbtp.&lt;br /&gt;
# Run the following commands to install and start the service:&lt;br /&gt;
#*   odbtpctl install&lt;br /&gt;
#*   odbtpctl start&lt;br /&gt;
# With these steps you should have one new service running in your host called &amp;quot;odbtp&amp;quot;. Verify it&#039;s present and running in the &amp;quot;Services&amp;quot; control panel.&lt;br /&gt;
# Don&#039;t forget to enable TCP/IP incoming connections to port 2799 in the host you have installed the service!&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to build the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039;. First of all, verify if, in the downloaded package, under the &amp;quot;php&amp;quot; dir, there is one extension suitable for your PHP server/version. If it&#039;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&#039;s important to point that, inside each directory, you&#039;ll find &#039;&#039;&#039;two different&#039;&#039;&#039; libraries/dll files. The one that must be copied to the extensions dir is the one called &#039;&#039;&#039;&amp;quot;php_odbtp_mssql.xxx&amp;quot;&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
If in the downloaded package isn&#039;t present the extension matching your PHP platform/version, you should build if from source files. To do that, just &#039;&#039;&#039;&amp;quot;configure, make, make install&amp;quot;&#039;&#039;&#039;. That will create some stuff under &amp;quot;/usr/local&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve successfully built ODBTP is time to create the &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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:&lt;br /&gt;
&lt;br /&gt;
  --with-odbtp-mssql&lt;br /&gt;
&lt;br /&gt;
then, after the standard &amp;quot;make and make install&amp;quot; steps, your PHP server will be built with MSSQL support provided by ODBTP.&lt;br /&gt;
&lt;br /&gt;
Finally, independently if we are using the binary extension provided in the download or if you have built it from source files, it&#039;s time to configure the extension. To do so, add this lines, if no present, to your php.ini file:&lt;br /&gt;
&lt;br /&gt;
  extension=php_odbtp.dll&lt;br /&gt;
&lt;br /&gt;
(only for Win32 PHP servers!)&lt;br /&gt;
&lt;br /&gt;
And, for all the server platforms: &lt;br /&gt;
&lt;br /&gt;
  [odbtp]&lt;br /&gt;
  odbtp.interface_file = &amp;quot;/path/to/your/odbtp.conf&amp;quot;&lt;br /&gt;
  odbtp.datetime_format = mdyhmsf&lt;br /&gt;
  odbtp.detach_default_queries = yes&lt;br /&gt;
&lt;br /&gt;
(where &#039;&#039;/path/to/your/odbtp.conf&amp;quot; is usually &amp;quot;/usr/local/etc/odbtp.conf&amp;quot;&amp;quot; for Unix systems and &amp;quot;C:\odbtp\odbtp.conf&amp;quot; for Windows systems)&lt;br /&gt;
&lt;br /&gt;
Then, edit such &amp;quot;odbtp.conf&amp;quot; file and put there these contents:&lt;br /&gt;
&lt;br /&gt;
  [global]&lt;br /&gt;
  odbtp host = xxx.xxx.xxx (ip or hostname of the Win32 box running the ODBTP service)&lt;br /&gt;
  type = mssql&lt;br /&gt;
  unicode sql = yes&lt;br /&gt;
  use row cache = yes&lt;br /&gt;
  right trim text = yes&lt;br /&gt;
  var data size = 20971520&lt;br /&gt;
&lt;br /&gt;
With this, your PHP server will be able to connect with the MSSQL DB server using ODBTP. From here, just continue with the installation.&lt;br /&gt;
&lt;br /&gt;
Finally, if you find the ODBTP executables and &#039;&#039;&#039;mssql extension alternative&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
== Using ODBC on Windows ==&lt;br /&gt;
&lt;br /&gt;
{{Not for production sites}}&lt;br /&gt;
&lt;br /&gt;
1. Go to the &#039;&#039;&#039;Administrative Tools&#039;&#039;&#039;  control panel, then the &#039;&#039;&#039;Data Sources (ODBC)&#039;&#039;&#039; panel.&lt;br /&gt;
&lt;br /&gt;
2. Configure one new System/User DSN (call it, for example &amp;quot;moodle&amp;quot;). Dont forget to enable these options if the driver asks for them:&lt;br /&gt;
&lt;br /&gt;
:* ANSI NULLS Enabled = true&lt;br /&gt;
:* Quoted Identifiers Enabled = true&lt;br /&gt;
&lt;br /&gt;
3. Your Moodle config.php should include lines like these:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;dbtype    = &#039;odbc_mssql&#039;;     // Note this is different to all the other configs on this page!&lt;br /&gt;
 $CFG-&amp;gt;dbhost    = &#039;moodle&#039;;         // Where this matches the Data source name you chose above&lt;br /&gt;
 $CFG-&amp;gt;dbname    = &#039;&#039;&#039;&#039;&#039;&#039;&#039;;               // Keep it blank!!&lt;br /&gt;
 $CFG-&amp;gt;dbuser    = &#039;yourusername&#039;;   // I usually use the &#039;sa&#039; account (dbowner perms are enough)&lt;br /&gt;
 $CFG-&amp;gt;dbpass    = &#039;yourpassword&#039;;&lt;br /&gt;
 $CFG-&amp;gt;dbpersist =  false;&lt;br /&gt;
 $CFG-&amp;gt;prefix    = &#039;mdl_&#039;;            //Prefix, you can change it, but &#039;&#039;&#039;never&#039;&#039;&#039; leave it blank.&lt;br /&gt;
&lt;br /&gt;
4. Install Moodle as usual.  Good luck!&lt;br /&gt;
&lt;br /&gt;
== Related links ==&lt;br /&gt;
&lt;br /&gt;
[[Installing Oracle for PHP]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:XMLDB]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Coding&amp;diff=14826</id>
		<title>Development:Coding</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Coding&amp;diff=14826"/>
		<updated>2006-08-24T15:14:21Z</updated>

		<summary type="html">&lt;p&gt;Tanthalas: /* Database structures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Any collaborative project needs consistency and stability to stay strong.&lt;br /&gt;
&lt;br /&gt;
These &#039;&#039;&#039;coding guidelines&#039;&#039;&#039; are to provide a goal for all Moodle code to strive to. It&#039;s true that some of the older existing code falls short in a few areas, but it will all be fixed eventually. All new code definitely must adhere to these standards as closely as possible.&lt;br /&gt;
&lt;br /&gt;
==General rules==&lt;br /&gt;
&lt;br /&gt;
# All code files should use the .php extension.&lt;br /&gt;
# All template files should use the .html extension.&lt;br /&gt;
# All text files should use Unix-style text format (most text editors have this as an option).&lt;br /&gt;
# All php tags must be &#039;full&#039; tags like &amp;lt;?php ?&amp;gt; ... not &#039;short&#039; tags like &amp;lt;? ?&amp;gt;.&lt;br /&gt;
# All existing copyright notices must be retained. You can add your own if necessary.&lt;br /&gt;
# Each file should include the main config.php file.&lt;br /&gt;
# Each file should check that the user is authenticated correctly, using require_login() and isadmin(), isteacher(), iscreator() or isstudent().&lt;br /&gt;
# All access to databases should use the functions in &#039;&#039;lib/datalib.php&#039;&#039; whenever possible - this allows compatibility across a wide range of databases. You should find that almost anything is possible using these functions. If you must write SQL code then make sure it is: cross-platform; restricted to specific functions within your code (usually a lib.php file); and clearly marked.&lt;br /&gt;
# Don&#039;t create or use global variables except for the standard $CFG, $SESSION, $THEME, $SITE, $COURSE and $USER.&lt;br /&gt;
# All variables should be initialised or at least tested for existence using isset() or empty() before they are used.&lt;br /&gt;
# All strings should be translatable - create new texts in the &amp;quot;lang/en_utf8&amp;quot; files with concise English lowercase names and retrieve them from your code using get_string() or print_string().&lt;br /&gt;
# All help files should be translatable - create new texts in the &amp;quot;lang/en_utf8/help&amp;quot; directory and call them using helpbutton(). If you need to update a help file:&lt;br /&gt;
#* with a minor change, where an old translation of the file would still make sense, then it&#039;s OK to make the change but you should notify translation AT moodle DOT org.&lt;br /&gt;
#* for a major change you should create a new file by adding an incrementing number (eg filename2.html) so that translators can easily see it&#039;s a new version of the file. Obviously the new code and the help index files should also be modified to point to the newest versions.&lt;br /&gt;
# Incoming data from the browser (sent via GET or POST) automatically has magic_quotes applied (regardless of the PHP settings) so that you can safely insert it straight into the database. All other raw data (from files, or from databases) must be escaped with addslashes() before inserting it into the database.&lt;br /&gt;
# VERY IMPORTANT: All texts within Moodle, especially those that have come from users, should be printed using the format_text() function. This ensures that text is filtered and cleaned correctly.&lt;br /&gt;
# User actions should be logged using the [[add_to_log|add_to_log()]] function. These logs are used for [[Settings#Show_activity_reports|activity reports]] and [[Logs]].&lt;br /&gt;
&lt;br /&gt;
==Coding style==&lt;br /&gt;
&lt;br /&gt;
I know it can be a little annoying to change your style if you&#039;re used to something else, but balance that annoyance against the annoyance of all the people trying later on to make sense of Moodle code with mixed styles. There are obviously many good points for and against any style that people use, but the current style just is, so please stick to it.&lt;br /&gt;
&lt;br /&gt;
1. Indenting should be consistently 4 spaces. Don&#039;t use tabs AT ALL.&lt;br /&gt;
&lt;br /&gt;
2. Variable names should always be easy-to-read, meaningful lowercase English words. If you really need more than one word then run them together, but keep them short as possible. Use plural names for arrays of objects.&lt;br /&gt;
&lt;br /&gt;
      GOOD: $quiz&lt;br /&gt;
      GOOD: $errorstring&lt;br /&gt;
      GOOD: $assignments (for an array of objects)&lt;br /&gt;
      GOOD: $i (but only in little loops)&lt;br /&gt;
&lt;br /&gt;
      BAD: $Quiz&lt;br /&gt;
      BAD: $aReallyLongVariableNameWithoutAGoodReason&lt;br /&gt;
      BAD: $error_string&lt;br /&gt;
&lt;br /&gt;
3. Constants should always be in upper case, and always start with the name of the module. They should have words separated by underscores.&lt;br /&gt;
&lt;br /&gt;
      define(&amp;quot;FORUM_MODE_FLATOLDEST&amp;quot;, 1);&lt;br /&gt;
4. Function names should be simple English lowercase words, and start with the name of the module to avoid conflicts between modules. Words should be separated by underscores. Parameters should always have sensible defaults if possible. Note there is no space between the function name and the following (brackets).&lt;br /&gt;
&lt;br /&gt;
      function forum_set_display_mode($mode=0) {&lt;br /&gt;
          global $USER, $CFG;&lt;br /&gt;
          &lt;br /&gt;
          if ($mode) {&lt;br /&gt;
              $USER-&amp;gt;mode = $mode;&lt;br /&gt;
          } else if (empty($USER-&amp;gt;mode)) {&lt;br /&gt;
              $USER-&amp;gt;mode = $CFG-&amp;gt;forum_displaymode;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
5. Blocks must always be enclosed in curly braces (even if there is only one line). Moodle uses this style:&lt;br /&gt;
&lt;br /&gt;
      if ($quiz-&amp;gt;attempts) {&lt;br /&gt;
          if ($numattempts &amp;gt; $quiz-&amp;gt;attempts) {&lt;br /&gt;
              error($strtoomanyattempts, &amp;quot;view.php?id=$cm-&amp;gt;id&amp;quot;);&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
6. Strings should be defined using single quotes where possible, for increased speed.&lt;br /&gt;
&lt;br /&gt;
      $var = &#039;some text without any variables&#039;;&lt;br /&gt;
      $var = &amp;quot;with special characters like a new line \n&amp;quot;;&lt;br /&gt;
      $var = &#039;a very, very long string with a &#039;.$single.&#039; variable in it&#039;;&lt;br /&gt;
      $var = &amp;quot;some $text with $many variables $within it&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
7. Comments should be added as much as is practical, to explain the code flow and the purpose of functions and variables.&lt;br /&gt;
&lt;br /&gt;
* Every function (and class) should use the popular [http://www.phpdoc.org/ phpDoc format]. This allows code documentation to be generated automatically.&lt;br /&gt;
* Inline comments should use the // style, laid out neatly so that it fits among the code and lines up with it.&lt;br /&gt;
&lt;br /&gt;
      /**&lt;br /&gt;
      * The description should be first, with asterisks laid out exactly&lt;br /&gt;
      * like this example. If you want to refer to a another function,&lt;br /&gt;
      * do it like this: {@link clean_param()}. Then, add descriptions&lt;br /&gt;
      * for each parameter as follows.&lt;br /&gt;
      *&lt;br /&gt;
      * @param int $postid The PHP type is followed by the variable name&lt;br /&gt;
      * @param array $scale The PHP type is followed by the variable name&lt;br /&gt;
      * @param array $ratings The PHP type is followed by the variable name&lt;br /&gt;
      * @return mixed&lt;br /&gt;
      */&lt;br /&gt;
      function forum_get_ratings_mean($postid, $scale, $ratings=NULL) {&lt;br /&gt;
          if (!$ratings) {&lt;br /&gt;
              $ratings = array();     // Initialize the empty array&lt;br /&gt;
              if ($rates = get_records(&amp;quot;forum_ratings&amp;quot;, &amp;quot;post&amp;quot;, $postid)) {&lt;br /&gt;
                  // Process each rating in turn&lt;br /&gt;
                  foreach ($rates as $rate) {&lt;br /&gt;
      ....etc&lt;br /&gt;
&lt;br /&gt;
8. Space should be used liberally - don&#039;t be afraid to spread things out a little to gain some clarity. Generally, there should be one space between brackets and normal statements, but no space between brackets and variables or functions:&lt;br /&gt;
&lt;br /&gt;
      foreach ($objects as $key =&amp;gt; $thing) {&lt;br /&gt;
          process($thing);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      if ($x == $y) {&lt;br /&gt;
          $a = $b;&lt;br /&gt;
      } else if ($x == $z) {&lt;br /&gt;
          $a = $c;&lt;br /&gt;
      } else {&lt;br /&gt;
          $a = $d;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
9. When making a COPY of an object, always use the php5 clone() function (otherwise you may end up with just a reference to the first object).  Moodle will make sure this works consistently on php4 too.&lt;br /&gt;
&lt;br /&gt;
      BAD:   $b = $a;&lt;br /&gt;
      GOOD:  $b = clone($a);&lt;br /&gt;
&lt;br /&gt;
If the thing you want to copy is not an object, but may contain objects (eg an array of objects) then use fullclone() instead.&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
# Every table must have an auto-incrementing id field (INT10) as primary index. (see [[IdColumnReasons]])&lt;br /&gt;
# The main table containing instances of each module must have the same name as the module (eg widget) and contain the following minimum fields:&lt;br /&gt;
#* id - as described above&lt;br /&gt;
#* course - the id of the course that each instance belongs to&lt;br /&gt;
#* name - the full name of each instance of the module&lt;br /&gt;
# Other tables associated with a module that contain information about &#039;things&#039; should be named widget_things (note the plural).&lt;br /&gt;
# Table and column names should avoid using [[Database reserved words|reserved words in any database]]. Please check them before creation.&lt;br /&gt;
# Column names should be always lowercase, simple and short, following the same rules as for variable names.&lt;br /&gt;
# Where possible, columns that contain a reference to the id field of another table (eg widget) should be called widgetid. (Note that this convention is newish and not followed in some older tables)&lt;br /&gt;
# Boolean fields should be implemented as small integer fields (eg INT4) containing 0 or 1, to allow for later expansion of values if necessary.&lt;br /&gt;
# Most tables should have a timemodified field (INT10) which is updated with a current timestamp obtained with the PHP time() function.&lt;br /&gt;
# Always define a default value for each field (and make it sensible)&lt;br /&gt;
# Each table name should start with the database prefix ($CFG-&amp;gt;prefix). In a lot of cases, this is taken care of for you automatically. Also, under Postgres, the name of every index must start with the prefix too.&lt;br /&gt;
&lt;br /&gt;
==Security issues (and handling form and URL data)==&lt;br /&gt;
&lt;br /&gt;
# Do not rely on &#039;register_globals&#039;. Every variable must be properly initialised in every code file. It must be obvious where the variable came from&lt;br /&gt;
# Initialise all arrays and objects, even if empty. $a = array() or $obj = new stdClass();.&lt;br /&gt;
# Do not use the optional_variable() function (this function is now deprecated). Use the optional_param() function instead. Pick the correct PARAM_XXXX value for the data type you expect.&lt;br /&gt;
# Do not use the require_variable() function (this function is now deprecated). Use the required_param() function instead. Pick the correct PARAM_XXXX value for the data type you expect.&lt;br /&gt;
# Use data_submitted(), with care. Data must still be cleaned before use.&lt;br /&gt;
# Do not use $_GET, $_POST or $_REQUEST. Use the appropriate required_param() or optional_param() appropriate to your need.&lt;br /&gt;
# Do not check for an action using something like if (isset($_GET[&#039;something&#039;])). Use, e.g., $something = optional_param( &#039;something&#039;,-1,PARAM_INT ) and then perform proper test for it being in its expected range of values e.g., if ($something&amp;gt;=0) {....&lt;br /&gt;
# Wherever possible group all your required_param(), optional_param() and other variables initialisation at the beginning of each file to make them easy to find.&lt;br /&gt;
# Use &#039;sesskey&#039; mechanism to protect form handling routines from attack. Basic example of use: when form is generated, include &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;sesskey&amp;quot; value=&amp;quot;&amp;lt;?php echo sesskey(); ?&amp;gt;&amp;quot; /&amp;gt;. When you process the form check with if (!confirm_sesskey()) {error(&#039;Bad Session Key&#039;);}.&lt;br /&gt;
# All filenames must be &#039;cleaned&#039; using the clean_filename() function, if this has not been done already by appropriate use of required_param() or optional_param()&lt;br /&gt;
# Any data read from the database must have addslashes() applied to it before it can be written back. A whole object of data can be hit at once with addslashes_object().&lt;br /&gt;
# Wherever possible, data to be stored in the database must come from POST data (from a form with method=&amp;quot;POST&amp;quot;) as opposed to GET data (ie, data from the URL line).&lt;br /&gt;
# Do not use data from $_SERVER if you can avoid it. This has portability issues.&lt;br /&gt;
# If it hasn&#039;t been done somewhere else, make sure all data written to the database has been through the clean_param() function using the appropriate PARAM_XXXX for the datatype.&lt;br /&gt;
# If you write custom SQL code, make very sure it is correct. In particular watch out for missing quotes around values. Possible SQL &#039;injection&#039; exploit.&lt;br /&gt;
# Check all data (particularly that written to the database) in every file it is used. Do not expect or rely on it being done somewhere else.&lt;br /&gt;
# Blocks of code to be included should contain a definite PHP structure (e.g, a class declaration, function definition(s) etc.) - straight blocks of code promote uninitialised variable usage.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
&lt;br /&gt;
[[es:Manual de Estilo de Código]]&lt;/div&gt;</summary>
		<author><name>Tanthalas</name></author>
	</entry>
</feed>