<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/401/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Trick</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/401/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Trick"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/Special:Contributions/Trick"/>
	<updated>2026-04-23T02:46:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=CAS_server_(SSO)_authentication&amp;diff=76063</id>
		<title>CAS server (SSO) authentication</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=CAS_server_(SSO)_authentication&amp;diff=76063"/>
		<updated>2010-09-22T18:44:03Z</updated>

		<summary type="html">&lt;p&gt;Trick: /* Overview */ fixed link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Location: Settings link in &#039;&#039;Administration &amp;gt; Users &amp;gt; [[Authentication]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
CAS is &amp;quot;Single Sign-on for the Web&amp;quot; and is developed by [http://www.ja-sig.org/products/cas/ JA-SIG] in an open-source, collaborative manner.  CAS is very beneficial in environments where a number of different web applications share a set of common users.  If all the web applications were &amp;lt;em&amp;gt;&amp;quot;CASified&amp;quot;&amp;lt;/em&amp;gt; a user would log in once and would then be able to move between the various web applications without ever having to present authentication credentials again.  CAS is similar to the [[Shibboleth]] authentication mechanism, but it is vastly simpler to set up and lacks a number of broader features like federated trust and authorization infrastructure.&lt;br /&gt;
&lt;br /&gt;
The details for how CAS works are [http://www.jasig.org/cas/cas2-architecture well documented], but CAS essentially works by configuring a web application (moodle.example.com) to not do authentication itself, but to instead forward unauthenticated users to a &amp;lt;em&amp;gt;&amp;quot;CAS Server&amp;quot;&amp;lt;/em&amp;gt; (cas.example.com) which will then return an authentication token to the original web application (moodle.example.com).  Moodle can extract the username from the token and then use its internal authorization mechanisms (roles, enrollments, capabilities) and user attributes (name, picture, etc.).  The advantage is that the moodle.example.com service never has to handle passwords and that users, once they&#039;ve authenticated the first time, can move seamlessly to another web application without having to present their credentials again.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
Assuming that you already have a working CAS server, configuration is fairly straightforward through the web interface.  &lt;br /&gt;
&lt;br /&gt;
One caveat for those converting from LDAP or other authentication mechanisms:&lt;br /&gt;
&lt;br /&gt;
* For any user that you wish to authenticate with CAS but which already has been using Moodle, and thus has an entry in the Moodle database, you will need to change the value of the &amp;quot;auth&amp;quot; field for the user in the mdl_user table.  So, if they used LDAP before, but now you wish for them to use CAS and their username is &amp;quot;foobar&amp;quot; you&#039;ll need to edit the database with some SQL something like: &amp;lt;code&amp;gt;UPDATE mdl_user SET auth=&#039;cas&#039; where auth=&#039;ldap&#039; and username=&#039;foobar&#039;;&amp;lt;/code&amp;gt;  Without this change the user will constantly be presented with a failed login message, but otherwise no clue as to why login failed even though their credentials were accepted by the CAS server.&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Utiliser un serveur CAS (SSO)]]&lt;br /&gt;
[[de:Authentifizierung über einen CAS-Server (SSO)]]&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Development:Modules&amp;diff=57134</id>
		<title>Development:Modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Development:Modules&amp;diff=57134"/>
		<updated>2009-06-03T18:25:44Z</updated>

		<summary type="html">&lt;p&gt;Trick: /* Activity modules */ backwards slash&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Activity modules === &lt;br /&gt;
&lt;br /&gt;
Activity modules reside in the &#039;&#039;&#039;/mod&#039;&#039;&#039; directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;mod_form.php&#039;&#039; - a form to set up or update an instance of this module&lt;br /&gt;
* &#039;&#039;version.php&#039;&#039; - defines some meta-info&lt;br /&gt;
* &#039;&#039;icon.gif&#039;&#039; - a 16x16 icon for the module&lt;br /&gt;
* &#039;&#039;db/install.xml&#039;&#039; - defines the structure of db tables for all database types. Is used during module installation&lt;br /&gt;
* &#039;&#039;db/upgrade.php&#039;&#039; - defines changes in the structure of db tables. Is used during module upgrade&lt;br /&gt;
* &#039;&#039;db/access.php&#039;&#039; - defines module capabilities&lt;br /&gt;
* &#039;&#039;index.php&#039;&#039; - a page to list all instances in a course&lt;br /&gt;
* &#039;&#039;view.php&#039;&#039; - a page to view a particular instance&lt;br /&gt;
* &#039;&#039;lib.php&#039;&#039; - any/all functions defined by the module should be in here. If the module name is called &#039;&#039;&#039;widget&#039;&#039;&#039;, then the required functions include:&lt;br /&gt;
:* widget_install() - will be called during the installation of the module&lt;br /&gt;
:* widget_add_instance() - code to add a new instance of widget&lt;br /&gt;
:* widget_update_instance() - code to update an existing instance&lt;br /&gt;
:* widget_delete_instance() - code to delete an instance&lt;br /&gt;
:* widget_user_outline() - given an instance, return a summary of a user&#039;s contribution&lt;br /&gt;
:* widget_user_complete() - given an instance, print details of a user&#039;s contribution&lt;br /&gt;
:* widget_get_view_actions() / widget_get_view_actions() - Used by the participation report (course/report/participation/index.php) to classify actions in the logs table.&lt;br /&gt;
:* Other functions available but not required are:&lt;br /&gt;
:** widget_delete_course() - code to clean up anything that would be leftover after all instances are deleted&lt;br /&gt;
:** widget_process_options() - code to pre-process the form data from module settings&lt;br /&gt;
:** [[Development:Implementing Reset course functionality in a module|widget_reset_course_form() and widget_delete_userdata()]] - used to implement [[Reset course]] feature.&lt;br /&gt;
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_&lt;br /&gt;
* &#039;&#039;backuplib.php&#039;&#039; and &#039;&#039;restorelib.php&#039;&#039; (optional)&lt;br /&gt;
* &#039;&#039;settings.php&#039;&#039; or &#039;&#039;settingstree.php&#039;&#039; - (optional) a definition of an admin settings page for this module. mod/assignment/settings.php is a good simple example. mod/quiz/settingstree.php is a more complex example.&lt;br /&gt;
* &#039;&#039;defaults.php&#039;&#039; - lets you easily define default values for your configuration variables. It is included by upgrade_activity_modules in lib/adminlib.php. It should define an array $defaults. These values are then loaded into the config table. Alternatively, if you set $defaults[&#039;_use_config_plugins&#039;] to true, the values are instead loaded into the config_plugins table, which is better practice. See mod/quiz/defaults.php for an example.&lt;br /&gt;
* &#039;&#039;lang/en_utf8/widget.php&#039;&#039; - (optional) Lastly, each module will have some language files that contain strings for that module.&lt;br /&gt;
&lt;br /&gt;
=== IMPORTANT: ===&lt;br /&gt;
* When creating a new module, the new name of the module must not contain numbers or other special characters!&lt;br /&gt;
&lt;br /&gt;
* You need a &#039;&#039;data base table&#039;&#039; with the same name as your module. This table must have at least three fields: &lt;br /&gt;
*# id &lt;br /&gt;
*# course &lt;br /&gt;
*# name&lt;br /&gt;
&lt;br /&gt;
* You should also make sure that your activity module provides appropriate support for groups and meta-courses. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Blocks]]&lt;br /&gt;
* [[Development:Backup]]&lt;br /&gt;
* Tracker issue [http://tracker.moodle.org/browse/CONTRIB-52 CONTRIB-52 Improvements to make NEWMODULE really useful] - including download link for new module template supporting roles, formslib etc. (unfinished) &lt;br /&gt;
* http://download.moodle.org/plugins16/mod/NEWMODULE.zip - new module template for versions of Moodle prior to 1.7. Please follow the README instructions inside the zip.&lt;br /&gt;
* [[Development:NEWMODULE_Documentation]]&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=66165 A new resource type: where do I put the language strings?]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=65986 New Module Template Code for Moodle 1.7]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=90154 LEGACY roles and capabilities]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Modules]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Tutorial]]&lt;br /&gt;
&lt;br /&gt;
[[es:Módulos de actividades (desarrollador)]]&lt;br /&gt;
[[fr:Modules (développeur)]]&lt;br /&gt;
[[ja:モジュール (開発者)]]&lt;br /&gt;
[[zh:开发:模块_(开发者)]]&lt;br /&gt;
[[de:Entwickler:Module]]&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Development:Developer_FAQ&amp;diff=57089</id>
		<title>Development:Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Development:Developer_FAQ&amp;diff=57089"/>
		<updated>2009-06-02T23:45:25Z</updated>

		<summary type="html">&lt;p&gt;Trick: block instance config&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Help for new coders==&lt;br /&gt;
&lt;br /&gt;
===Where can I start?===&lt;br /&gt;
&lt;br /&gt;
See [[Development:Finding your way into the Moodle code]].&lt;br /&gt;
&lt;br /&gt;
===Where can &amp;quot;newbies&amp;quot; to Moodle get help?===&lt;br /&gt;
&lt;br /&gt;
The [http://moodle.org/mod/forum/view.php?f=33 General developer forum]! Feel free to ask any question, no matter how basic or advanced. Many people ask different levels of question every day, and the community is generally welcoming and quick to respond.&lt;br /&gt;
&lt;br /&gt;
===How do I create a patch?===&lt;br /&gt;
&lt;br /&gt;
See [[Development:How to create a patch]].&lt;br /&gt;
&lt;br /&gt;
===Is there any information on creating a new module or plugin?===&lt;br /&gt;
&lt;br /&gt;
See [[Development:Modules]], [[Development:Blocks]] and [[Development:Authentication plugins]], or the [[Development:Developer_documentation#Make_a_new_plugin|full list of plugin types]].&lt;br /&gt;
&lt;br /&gt;
===Is there any information on backup and restore?===&lt;br /&gt;
&lt;br /&gt;
See [[Development:Backup]].&lt;br /&gt;
&lt;br /&gt;
==I can&#039;t use one of the available plug-in points to make my change. What alternative is there?==&lt;br /&gt;
&lt;br /&gt;
See [[Development:Local customisation]].&lt;br /&gt;
&lt;br /&gt;
==Moodle&#039;s database==&lt;br /&gt;
&lt;br /&gt;
===Where can I see a schema for the structure of the Moodle database?===&lt;br /&gt;
&lt;br /&gt;
[[Development:Database_schema_introduction]] gives a high level overview of the database schema.&lt;br /&gt;
&lt;br /&gt;
Because of Moodle&#039;s modular nature, there is no single, detailed representation of the full database schema. Instead, the tables for each part of Moodle are defined in a database-neutral XML format, see [[XMLDB]], in each part of moodle. Look for files called install.xml in folders called db throughout the code. Alternatively, from Moodle 2.0 onwards, go to Administration -&amp;gt; Development -&amp;gt; XMLDB editor, and use the [Doc] links to see automatically generated documentation built form the comments in the install.xml files.&lt;br /&gt;
&lt;br /&gt;
==How to get/set information when writing new Moodle code==&lt;br /&gt;
&lt;br /&gt;
===How do I find out the currently-logged-on user?===&lt;br /&gt;
&lt;br /&gt;
The global object $USER, which contains the numeric $USER-&amp;gt;id among other things.&lt;br /&gt;
&lt;br /&gt;
===How do I find out the current course?===&lt;br /&gt;
The global object $COURSE, which contains the numeric $COURSE-&amp;gt;id&lt;br /&gt;
&lt;br /&gt;
===How do I insert/retrieve records in the database, without creating my own database connections?===&lt;br /&gt;
&lt;br /&gt;
Always use the &amp;quot;datalib&amp;quot; functions, such as insert_record() or get_record(). Since Moodle 1.7 these are found in lib/dmllib.php. Using these functions helps with database abstraction (e.g. running on either MySQL or Postgres) as well as maintaining a single database connection. Moodle uses ADODB for database abstraction.&lt;br /&gt;
&lt;br /&gt;
Look at [http://phpdocs.moodle.org/19/moodlecore/_lib---datalib.php.html  the documentation for datalib.php] for the list of functions and details of use.&lt;br /&gt;
&lt;br /&gt;
===How do I get/set configuration settings?===&lt;br /&gt;
&lt;br /&gt;
To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these &amp;quot;main&amp;quot; config values use set_config($name, $value). The values are stored in the Moodle &amp;quot;config&amp;quot; database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.&lt;br /&gt;
&lt;br /&gt;
There is also a second table of config settings specifically for plugins (&amp;quot;config_plugin&amp;quot;). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).&lt;br /&gt;
&lt;br /&gt;
On top of those global configuration values, individual blocks may also have configuration &amp;quot;object&amp;quot; associated with it (the data is serialized and stored in the &amp;quot;block_instance&amp;quot; table). Within blocks, this data is automatically loaded into the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; attribute of the block.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Contributed code FAQ]]&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?f=33 General developer forum]&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category: Developer]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ Desarrollador]]&lt;br /&gt;
[[fr:FAQ de développement]]&lt;br /&gt;
[[pl:Developer FAQ]]&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Development_talk:Navigation_2.0&amp;diff=56603</id>
		<title>Development talk:Navigation 2.0</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Development_talk:Navigation_2.0&amp;diff=56603"/>
		<updated>2009-05-26T20:30:22Z</updated>

		<summary type="html">&lt;p&gt;Trick: added tracker link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Navigation menu ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m the lead developer of the [[YUI menu]]. IMHO, it&#039;s the closest contender as far as actual written code goes. That&#039;s why I wrote it in the first place, because nothing else would work for us.&lt;br /&gt;
&lt;br /&gt;
That said, the YUI menu as it is right now probably isn&#039;t good enough. Here are some caveats:&lt;br /&gt;
&lt;br /&gt;
* At the moment, the code isn&#039;t bad, but it could be better. Some of this is due to compensating for stuff that should really be elsewhere. I&#039;m currently working on a rewrite that will fix some of that.&lt;br /&gt;
* YUI&#039;s treeview has no form of non-javascript fallback and it uses HTML tables like there&#039;s no tomorrow. If we want accessibility (and I know I do), I&#039;ll have to throw out YUI all together and either find something else or write something myself.&lt;br /&gt;
&lt;br /&gt;
I&#039;m willing and able to do make these changes if it will help. See MDL-19300. -[[User:Alan Trick|Alan Trick]] 20:25, 26 May 2009 (UTC)&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Development_talk:Navigation_2.0&amp;diff=56601</id>
		<title>Development talk:Navigation 2.0</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Development_talk:Navigation_2.0&amp;diff=56601"/>
		<updated>2009-05-26T20:25:35Z</updated>

		<summary type="html">&lt;p&gt;Trick: Navigation menu&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Navigation menu ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m the lead developer of the [[YUI menu]]. IMHO, it&#039;s the closest contender as far as actual written code goes. That&#039;s why I wrote it in the first place, because nothing else would work for us.&lt;br /&gt;
&lt;br /&gt;
That said, the YUI menu as it is right now probably isn&#039;t good enough. Here are some caveats:&lt;br /&gt;
&lt;br /&gt;
* At the moment, the code isn&#039;t bad, but it could be better. Some of this is due to compensating for stuff that should really be elsewhere. I&#039;m currently working on a rewrite that will fix some of that.&lt;br /&gt;
* YUI&#039;s treeview has no form of non-javascript fallback and it uses HTML tables like there&#039;s no tomorrow. If we want accessibility (and I know I do), I&#039;ll have to throw out YUI all together and either find something else or write something myself.&lt;br /&gt;
&lt;br /&gt;
I&#039;m willing and able to do make these changes if it will help. -[[User:Alan Trick|Alan Trick]] 20:25, 26 May 2009 (UTC)&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=56077</id>
		<title>File:YUI Menu.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=56077"/>
		<updated>2009-05-19T19:55:28Z</updated>

		<summary type="html">&lt;p&gt;Trick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Menu in 1.9.4 with a custom theme (twu). Taken from the [http://demo.mytwu.ca/moodle/course/view.php?id=2 demo site].&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=56076</id>
		<title>File:YUI Menu.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=56076"/>
		<updated>2009-05-19T19:54:35Z</updated>

		<summary type="html">&lt;p&gt;Trick: uploaded a new version of &amp;quot;Image:YUI Menu.png&amp;quot;: menu in 1.9.4 with a custom theme (twu). Taken from [http://demo.mytwu.ca/moodle/course/view.php?id=2 demo site]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Original picture of the YUI menu. It&#039;s dated, but nothing has changed.&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Development:Coding_style&amp;diff=56020</id>
		<title>Development:Coding style</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Development:Coding_style&amp;diff=56020"/>
		<updated>2009-05-19T17:30:04Z</updated>

		<summary type="html">&lt;p&gt;Trick: /* String concatenation */ removed non-standard MySQL code.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
===Scope===&lt;br /&gt;
&lt;br /&gt;
This document describes &#039;&#039;&#039;style&#039;&#039;&#039; guidelines for developers working on or with Moodle code.  It talks purely about the mechanics of code layout and the choices we have made for Moodle.&lt;br /&gt;
&lt;br /&gt;
For details about using the Moodle API to get things done, see the [[Development:Coding|coding guidelines]].&lt;br /&gt;
&lt;br /&gt;
===Goals===&lt;br /&gt;
&lt;br /&gt;
Consistent coding style is important in any development project, and particularly when many developers are involved.  A standard style helps to ensure that the code is easier to read and understand, which helps overall quality.&lt;br /&gt;
&lt;br /&gt;
Abstract goals we strive for:&lt;br /&gt;
&lt;br /&gt;
* simplicity&lt;br /&gt;
* readability&lt;br /&gt;
* tool friendliness, such as use of method signatures, constants, and patterns that support IDE tools and auto-completion of method, class, and constant names.&lt;br /&gt;
&lt;br /&gt;
When considering the goals above, each situation requires an examination of the circumstances and balancing of various trade-offs.&lt;br /&gt;
&lt;br /&gt;
Note that much of the existing Moodle code may not follow all of these guidelines - we continue to upgrade this code when we see it.&lt;br /&gt;
&lt;br /&gt;
==File Formatting==&lt;br /&gt;
&lt;br /&gt;
===PHP tags===&lt;br /&gt;
&lt;br /&gt;
Always use &amp;quot;long&amp;quot; php tags.  However, to avoid whitespace problems, DO NOT include the closing tag at the very end of the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
include(&#039;config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Indentation===&lt;br /&gt;
&lt;br /&gt;
Use an indent of &#039;&#039;&#039;4 spaces&#039;&#039;&#039; with no tab characters. Editors should be configured to treat tabs as spaces in order to prevent injection of new tab characters into the source code.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t indent the main script level:&lt;br /&gt;
&lt;br /&gt;
GOOD:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php // $Id$&lt;br /&gt;
$a = required_param(&#039;a&#039;, PARAM_INT);&lt;br /&gt;
if ($a &amp;gt; 10) {&lt;br /&gt;
    call_some_error($a);&lt;br /&gt;
} else {&lt;br /&gt;
    do_something_with($a);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BAD:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php // $Id$&lt;br /&gt;
    $a = required_param(&#039;a&#039;, PARAM_INT);&lt;br /&gt;
    if ($a &amp;gt; 10) {&lt;br /&gt;
        call_some_error($a);&lt;br /&gt;
    } else {&lt;br /&gt;
        do_something_with($a);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maximum Line Length===&lt;br /&gt;
&lt;br /&gt;
Aim for 80 characters if it is convenient.  &lt;br /&gt;
&lt;br /&gt;
However, you can go up to 120 characters if it helps overall readability.&lt;br /&gt;
&lt;br /&gt;
===Line Termination===&lt;br /&gt;
&lt;br /&gt;
Use standard &#039;&#039;&#039;Unix&#039;&#039;&#039; text format. Lines must end only with a linefeed (LF). Linefeeds are represented as ordinal 10, or hexadecimal 0x0A.&lt;br /&gt;
&lt;br /&gt;
Do not use carriage returns (CR) like &#039;&#039;Macintosh&#039;&#039; computers (0x0D).&lt;br /&gt;
&lt;br /&gt;
Do not use the carriage return/linefeed combination (CRLF) as &#039;&#039;Windows&#039;&#039; computers (0x0D, 0x0A).&lt;br /&gt;
&lt;br /&gt;
Lines should not contain trailing spaces. In order to facilitate this convention, most editors can be configured to strip trailing spaces, such as upon a save operation.&lt;br /&gt;
&lt;br /&gt;
==Naming Conventions==&lt;br /&gt;
&lt;br /&gt;
===Filenames===&lt;br /&gt;
&lt;br /&gt;
Filenames should :&lt;br /&gt;
* be whole english words&lt;br /&gt;
* be as short as possible&lt;br /&gt;
* use lowercase letters only &lt;br /&gt;
* end in .php, .html, .js, or .xml &lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class names should always be lowercase english words, separated by underscores:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class some_custom_class {&lt;br /&gt;
    function class_method() {&lt;br /&gt;
        echo &amp;quot;foo&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functions and Methods===&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
Verbosity is encouraged: function names should be as illustrative as is practical to enhance understanding.&lt;br /&gt;
&lt;br /&gt;
Note there is no space between the function name and the following (brackets). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;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;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Function Parameters====&lt;br /&gt;
&lt;br /&gt;
Parameters are always simple lowercase English words (sometimes more than one, like $initialvalue), and should always have sensible defaults if possible. &lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;null&amp;quot; as the default value instead of &amp;quot;false&amp;quot; for situations like this where a default value isn&#039;t needed.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function foo($required, $optional = null)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, if an optional parameter is boolean, and its logical default value should be true, or false, then using true or false is acceptable.&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
&lt;br /&gt;
Variable names should always be easy-to-read, meaningful lower-case English words. If you really need more than one word then run them together, but keep them short as possible. Use &#039;&#039;&#039;plural&#039;&#039;&#039; 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: $camelCase&lt;br /&gt;
 BAD: $aReallyLongVariableNameWithoutAGoodReason&lt;br /&gt;
 BAD: $error_string&lt;br /&gt;
&lt;br /&gt;
Core global variables in Moodle are identified using uppercase variables (ie $CFG, $SESSION, $USER, $COURSE, $SITE, $PAGE, $DB and $THEME).  Don&#039;t create any more!&lt;br /&gt;
&lt;br /&gt;
===Constants===&lt;br /&gt;
&lt;br /&gt;
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;
&amp;lt;code php&amp;gt;&lt;br /&gt;
define(&amp;quot;FORUM_MODE_FLATOLDEST&amp;quot;, 1);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Booleans and the NULL Value===&lt;br /&gt;
&lt;br /&gt;
Use lower case for &#039;&#039;&#039;true&#039;&#039;&#039;, &#039;&#039;&#039;false&#039;&#039;&#039; and &#039;&#039;&#039;null&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Strings ==&lt;br /&gt;
&lt;br /&gt;
Since string performance is not an issue in current versions of PHP, the main criteria for strings is readability. &lt;br /&gt;
&lt;br /&gt;
===Single quotes===&lt;br /&gt;
&lt;br /&gt;
Always use single quotes when a string is literal, or contains a lot of double quotes (like HTML):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$a = &#039;Example String&#039;; &lt;br /&gt;
echo &#039;&amp;lt;span class=&amp;quot;&#039;.s($class).&#039;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&#039;; &lt;br /&gt;
$html = &#039;&amp;lt;a href=&amp;quot;http://something&amp;quot; title=&amp;quot;something&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Double quotes===&lt;br /&gt;
&lt;br /&gt;
These are a lot less useful in Moodle.  &lt;br /&gt;
&lt;br /&gt;
Use double quotes when you need to include plain variables or a lot of single quotes.  In Moodle 2.0 or later you won&#039;t need to be doing a lot of single quotes for SQL so that&#039;s not an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo &amp;quot;&amp;lt;span&amp;gt;$string&amp;lt;/span&amp;gt;&amp;quot;; &lt;br /&gt;
$statement = &amp;quot;You aren&#039;t serious!&amp;quot;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Variable substitution===&lt;br /&gt;
&lt;br /&gt;
Variable substitution can use either of these forms:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$greeting = &amp;quot;Hello $name, welcome back!&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$greeting = &amp;quot;Hello {$name}, welcome back!&amp;quot;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===String concatenation===&lt;br /&gt;
&lt;br /&gt;
Strings must be concatenated using the &amp;quot;.&amp;quot; operator.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$longstring = $several.$short.&#039;strings&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the lines are long, break the statement into multiple lines to improve readability.  In these cases, put the &amp;quot;dot&amp;quot; at the end of each line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$sql = &amp;quot;SELECT id, username FROM user &amp;quot;.&lt;br /&gt;
       &amp;quot;WHERE username = &#039;susan&#039; &amp;quot;.&lt;br /&gt;
       &amp;quot;ORDER BY id ASC &amp;quot;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Arrays==&lt;br /&gt;
&lt;br /&gt;
===Numerically indexed arrays===&lt;br /&gt;
&lt;br /&gt;
Negative numbers are not permitted as indices.&lt;br /&gt;
&lt;br /&gt;
An indexed array may start with any non-negative number, however all base indices besides 0 are discouraged.&lt;br /&gt;
&lt;br /&gt;
When declaring indexed arrays with the array function, a trailing space must be added after each comma delimiter to improve readability:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$myarray = array(1, 2, 3, &#039;Stuff&#039;, &#039;Here&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line indexed arrays are fine, but pad each successive line with spaces so that the beginning of each line is aligned:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$myarray = array(1, 2, 3, &#039;Stuff&#039;, &#039;Here&#039;,&lt;br /&gt;
                 $a, $b, $c,&lt;br /&gt;
                 56.44, $d, 500);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Associative arrays===&lt;br /&gt;
&lt;br /&gt;
Use multiple lines where possible, and pad the successive lines with spaces like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$myarray = array(&#039;firstkey&#039;  =&amp;gt; &#039;firstvalue&#039;,&lt;br /&gt;
                 &#039;secondkey&#039; =&amp;gt; &#039;secondvalue&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
=== Class declarations ===&lt;br /&gt;
&lt;br /&gt;
* Classes must be named according to Moodle&#039;s naming conventions.&lt;br /&gt;
* The brace should always be written on the line beside the class name.&lt;br /&gt;
* Every class must have a documentation block that conforms to the PHPDocumentor standard.&lt;br /&gt;
* All code in a class must be indented with 4 spaces.&lt;br /&gt;
* Only one class is permitted in each PHP file.&lt;br /&gt;
&lt;br /&gt;
* Placing additional code in class files is permitted but discouraged. In such files, two blank lines must separate the class from any additional PHP code in the class file.&lt;br /&gt;
&lt;br /&gt;
: An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Documentation Block Here&lt;br /&gt;
 */&lt;br /&gt;
class SampleClass {&lt;br /&gt;
    // all contents of class&lt;br /&gt;
    // must be indented 4 spaces&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Class member variables===&lt;br /&gt;
&lt;br /&gt;
Member variables must be named according to Moodle&#039;s variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Any variables declared in a class must be listed at the top of the class, above the declaration of any methods.&lt;br /&gt;
&lt;br /&gt;
The var construct is not permitted. Member variables always declare their visibility by using one of the &#039;&#039;&#039;private&#039;&#039;&#039;, &#039;&#039;&#039;protected&#039;&#039;&#039;, or &#039;&#039;&#039;public&#039;&#039;&#039; modifiers. Giving access to member variables directly by declaring them as public is permitted but discouraged in favor of accessor methods (set/get).&lt;br /&gt;
&lt;br /&gt;
==Functions and methods==&lt;br /&gt;
===Function and method declaration===&lt;br /&gt;
&lt;br /&gt;
Functions must be named according to the Moodle function naming conventions.&lt;br /&gt;
&lt;br /&gt;
Methods inside classes must always declare their visibility by using one of the private, protected, or public modifiers.&lt;br /&gt;
&lt;br /&gt;
As with classes, the brace should always be written on same line as the function name. &lt;br /&gt;
&lt;br /&gt;
Don&#039;t leave spaces between the function name and the opening parenthesis for the arguments.&lt;br /&gt;
&lt;br /&gt;
Functions in the global scope are strongly discouraged.&lt;br /&gt;
&lt;br /&gt;
The return value must not be enclosed in parentheses. This can hinder readability, in additional to breaking code if a method is later changed to return by reference. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Documentation Block Here&lt;br /&gt;
 */&lt;br /&gt;
class sample_class {&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * Documentation Block Here&lt;br /&gt;
     */&lt;br /&gt;
    public function sample_function () {&lt;br /&gt;
        // all contents of function&lt;br /&gt;
        // must be indented four spaces&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Function and method usage===&lt;br /&gt;
&lt;br /&gt;
Function arguments should be separated by a single trailing space after the comma delimiter. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
threeArguments(1, 2, 3);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Control statements==&lt;br /&gt;
&lt;br /&gt;
In general, use white space liberally between lines and so on, to add clarity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===If / else===&lt;br /&gt;
&lt;br /&gt;
Put a space before and after the control statement in brackets, and separate the operators by spaces within the brackets.  Use inner brackets to improve logical grouping if it helps. &lt;br /&gt;
&lt;br /&gt;
Indent with four spaces. &lt;br /&gt;
&lt;br /&gt;
Don&#039;t use elseif !&lt;br /&gt;
&lt;br /&gt;
Always use braces (even if the block is one line and PHP doesn&#039;t require it).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;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;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Switch===&lt;br /&gt;
&lt;br /&gt;
Put a space before and after the control statement in brackets, and separate the operators by spaces within the brackets.  Use inner brackets to improve logical grouping if it helps. &lt;br /&gt;
&lt;br /&gt;
Always indent with four spaces.  Content under each case statement should be indented a further four spaces.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
switch ($something) {&lt;br /&gt;
    case 1:&lt;br /&gt;
        break;&lt;br /&gt;
&lt;br /&gt;
    case 2:&lt;br /&gt;
        break;&lt;br /&gt;
&lt;br /&gt;
    default:&lt;br /&gt;
        break;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Foreach===&lt;br /&gt;
&lt;br /&gt;
As above, uses spaces like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
foreach ($objects as $key =&amp;gt; $thing) {&lt;br /&gt;
    process($thing);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Require / include==&lt;br /&gt;
&lt;br /&gt;
Each file should start by including the main config.php file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once(&#039;../config.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Any other include/require should use an absolute path beginning with $CFG-&amp;gt;dirroot or  $CFG-&amp;gt;libdir, not relative includes, which [http://uk.php.net/manual/en/function.include.php sometimes behave strangely under PHP].&lt;br /&gt;
&lt;br /&gt;
Includes should generally only be done at the top of files or inside functions/methods that need them, it&#039;s insecure to use include/require in the middle of file in global scope.&lt;br /&gt;
&lt;br /&gt;
==Documentation and comments==&lt;br /&gt;
&lt;br /&gt;
Inline documentation explains the code flow and the purpose of functions and variables.  Use it whenever practical.&lt;br /&gt;
&lt;br /&gt;
Moodle uses the [http://www.phpdoc.org/ phpDoc format]. This allows our code documentation to be generated automatically (see [http://phpdocs.moodle.org phpdocs.moodle.org].&lt;br /&gt;
&lt;br /&gt;
===Inline comments===&lt;br /&gt;
&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;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function forum_get_ratings_mean($postid, $scale, $ratings=NULL) {&lt;br /&gt;
    if (!$ratings) {&lt;br /&gt;
&lt;br /&gt;
        $ratings = array();     // Initialize the empty array&lt;br /&gt;
&lt;br /&gt;
        if ($rates = get_records(&amp;quot;forum_ratings&amp;quot;, &amp;quot;post&amp;quot;, $postid)) {&lt;br /&gt;
&lt;br /&gt;
            // Process each rating in turn&lt;br /&gt;
            foreach ($rates as $rate) {&lt;br /&gt;
                ...&lt;br /&gt;
            }&lt;br /&gt;
            // Do something else here &lt;br /&gt;
            something_else();&lt;br /&gt;
&lt;br /&gt;
     ... etc.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Files===&lt;br /&gt;
&lt;br /&gt;
All files that contain PHP code should contain a full GPL copyright statement at the top, plus a separate docblock right under it containing:&lt;br /&gt;
* A short one-line description of the file&lt;br /&gt;
* A longer description of the file&lt;br /&gt;
* A @package tag, describing the part of Moodle this part of&lt;br /&gt;
* A @copyright tag, with year and copyright holder (creator) of the original file&lt;br /&gt;
* A @license tag, which must contain &amp;quot;http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
// This file is part of Moodle - http://moodle.org/ &lt;br /&gt;
// &lt;br /&gt;
// Moodle is free software: you can redistribute it and/or modify&lt;br /&gt;
// it under the terms of the GNU General Public License as published by&lt;br /&gt;
// the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
// (at your option) any later version.&lt;br /&gt;
//&lt;br /&gt;
// Moodle is distributed in the hope that it will be useful,&lt;br /&gt;
// but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
// GNU General Public License for more details.&lt;br /&gt;
// &lt;br /&gt;
// You should have received a copy of the GNU General Public License&lt;br /&gt;
// along with Moodle.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * This is a one-line short description of the file&lt;br /&gt;
 *&lt;br /&gt;
 * You can have a rather longer description of the file as well, &lt;br /&gt;
 * if you like, and it can span multiple lines.&lt;br /&gt;
 * &lt;br /&gt;
 * @package   moodlecore&lt;br /&gt;
 * @copyright 2008 Kim Bloggs&lt;br /&gt;
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later&lt;br /&gt;
 */&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Packages ====&lt;br /&gt;
&lt;br /&gt;
The package keyword MUST be included and tags a file as being part of a group of files.  Conventions are:&lt;br /&gt;
&lt;br /&gt;
# If it&#039;s part of Moodle core libraries, use &#039;&#039;&#039;moodlecore&#039;&#039;&#039;&lt;br /&gt;
# If it&#039;s part of a module, use the path of the module with hyphens:  eg &#039;&#039;&#039;mod-forum&#039;&#039;&#039; or &#039;&#039;&#039;grade-report-visual&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
All classes should have a docblock with the following minimum information:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Short description for class&lt;br /&gt;
 *&lt;br /&gt;
 * Long description for class (if any)...&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright 2008 Kim Bloggs&lt;br /&gt;
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later&lt;br /&gt;
 */&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functions===&lt;br /&gt;
&lt;br /&gt;
All functions and methods should have a docblock like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;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 and the return value 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;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Exceptions==&lt;br /&gt;
&lt;br /&gt;
Use exceptions to report errors, especially in library code.&lt;br /&gt;
&lt;br /&gt;
Throwing an exception has almost exactly the same effect as calling print_error, but it is more flexible. For example, the caller can choose to catch the exception and handle it in some way. It also makes it easier to write unit tests.&lt;br /&gt;
&lt;br /&gt;
Any exception that is not caught will trigger an appropriate call to print_error, to report the problem to the user.&lt;br /&gt;
&lt;br /&gt;
Do not abuse exceptions for normal code flow. Exceptions should only be used in erroneous situations.&lt;br /&gt;
&lt;br /&gt;
===Exception classes===&lt;br /&gt;
&lt;br /&gt;
We have a set of custom exception classes. The base class is moodle_exception. You will see that the arguments you pass to new moodle_exception(...) are very similar to the ones you would pass to print_error. There are more specific subclasses for particular types of error.&lt;br /&gt;
&lt;br /&gt;
To get the full list of exception types, search for the regular expression &#039;class +\w+_exception +extends&#039; or ask your IDE to list all the subclasses of moodle_exception.&lt;br /&gt;
&lt;br /&gt;
Where appropriate, you should create new subclasses of moodle_exception for use in your code.&lt;br /&gt;
&lt;br /&gt;
A few notable exception types:&lt;br /&gt;
; moodle_exception : base class for exceptions in Moodle. Use this when a more specific type is not appropriate.&lt;br /&gt;
; coding_exception : thrown when the problem seems to be caused by a developer&#039;s mistake. Often thrown by core code that interacts with plugins. If you throw an exception of this type, try to make the error message helpful to the plugin author, so they know how to fix their code.&lt;br /&gt;
; dml_exception (and subclasses) : thrown when a database query fails.&lt;br /&gt;
; file_exception : thrown by the File API.&lt;br /&gt;
&lt;br /&gt;
==Credits==&lt;br /&gt;
&lt;br /&gt;
This document was drawn from the following sources:&lt;br /&gt;
&lt;br /&gt;
# The original [https://docs.moodle.org/en/index.php?title=Development:Coding&amp;amp;oldid=53799 Coding guidelines] page&lt;br /&gt;
# The [http://framework.zend.com/manual/en/coding-standard.html Zend guidelines] and &lt;br /&gt;
# Feedback from all core Moodle developers&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
[[Development:Coding]]&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=GNU_General_Public_License&amp;diff=55549</id>
		<title>GNU General Public License</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=GNU_General_Public_License&amp;diff=55549"/>
		<updated>2009-05-11T18:23:56Z</updated>

		<summary type="html">&lt;p&gt;Trick: short page with most relevant info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;GNU General Public License&#039;&#039;&#039; (&#039;&#039;&#039;GPL&#039;&#039;&#039;) is the the [[License|software license used by Moodle]]. It is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is designed to give users free use of their software and also make sure that freedom can not be taken away from them.&lt;br /&gt;
&lt;br /&gt;
== Using the GPL ==&lt;br /&gt;
&lt;br /&gt;
At the moment, there are 3 versions of the GPL, and this is unlikely to change any time soon. Version 3 is the current version and is the one recommended by the Free Software Foundation. Version 2 is usually used by software projects that started before the GPL 3 was available and have not made the effort to shift over. Version 1 is more or less completely gone.&lt;br /&gt;
&lt;br /&gt;
These new versions of the GPL have been released in response to holes that people and companies have found and exploited in the older versions. For example, with the GPL 2 it was possible to create a product using DRM technology and deny its users the right to modify the software on it, even though the GPL was supposed to uphold this right. As a result, each version of the GPL must be incompatible with each other, otherwise the company could just make up some code under the old license, lock it down, and thus by pass the whole point of the new license.&lt;br /&gt;
&lt;br /&gt;
As a result, the typical way to license is under &#039;&#039;GPL &amp;lt;version&amp;gt; or later&#039;&#039;. For example, Moodle is licensed under the GPL 2 or later. In this case, the user can use it under the GPL 2 license or the GLP 3, thus the software is compatible with future GPL licenses. New software should probably use &#039;&#039;GPL 3 or later&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.gnu.org/copyleft/gpl.html Official GPL page]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GNU_General_Public_License Wikipedia on the GPL]&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55492</id>
		<title>Template:Plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55492"/>
		<updated>2009-05-08T21:53:51Z</updated>

		<summary type="html">&lt;p&gt;Trick: best to removed caption altogether if it&amp;#039;s not going to be used&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;table class=&amp;quot;infobox&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;width: 22em; text-align: left; font-size: 88%; line-height: 1.5em; border: 1px solid #aaa; background-color: #f9f9f9; margin: 0.5em 0 0.5em 1em; padding: 0.2em; float: right; clear: right; vertical-align: top&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt; {{{screenshot}}} &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;{{{caption|}}}&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{type}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Download&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{download}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Source Code&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{source}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Bug Tracker&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{tracker}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;License&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{license}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55491</id>
		<title>Template:Plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55491"/>
		<updated>2009-05-08T21:53:03Z</updated>

		<summary type="html">&lt;p&gt;Trick: using PAGENAME is redundant&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;table class=&amp;quot;infobox&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;width: 22em; text-align: left; font-size: 88%; line-height: 1.5em; border: 1px solid #aaa; background-color: #f9f9f9; margin: 0.5em 0 0.5em 1em; padding: 0.2em; float: right; clear: right; vertical-align: top&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption style=&amp;quot;font-size: 125%; font-weight: bold;&amp;quot;&amp;gt;{{{name|}}}&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt; {{{screenshot}}} &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;{{{caption|}}}&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{type}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Download&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{download}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Source Code&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{source}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Bug Tracker&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{tracker}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;License&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{license}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55488</id>
		<title>Template:Plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55488"/>
		<updated>2009-05-08T20:35:44Z</updated>

		<summary type="html">&lt;p&gt;Trick: moved license to the bottom&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;table class=&amp;quot;infobox&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;width: 22em; text-align: left; font-size: 88%; line-height: 1.5em; border: 1px solid #aaa; background-color: #f9f9f9; margin: 0.5em 0 0.5em 1em; padding: 0.2em; float: right; clear: right; vertical-align: top&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption style=&amp;quot;font-size: 125%; font-weight: bold;&amp;quot;&amp;gt;{{{name|{{PAGENAME}}}}}&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt; {{{screenshot}}} &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;{{{caption|}}}&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{type}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Download&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{download}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Source Code&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{source}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Bug Tracker&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{tracker}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;License&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{license}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55485</id>
		<title>Template:Plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Template:Plugin&amp;diff=55485"/>
		<updated>2009-05-08T20:22:35Z</updated>

		<summary type="html">&lt;p&gt;Trick: a wanabe infobox&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;table class=&amp;quot;infobox&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;width: 22em; text-align: left; font-size: 88%; line-height: 1.5em; border: 1px solid #aaa; background-color: #f9f9f9; margin: 0.5em 0 0.5em 1em; padding: 0.2em; float: right; clear: right; vertical-align: top&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption style=&amp;quot;font-size: 125%; font-weight: bold;&amp;quot;&amp;gt;{{{name|{{PAGENAME}}}}}&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt; {{{screenshot}}} &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;{{{caption|}}}&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{type}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;License&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{license}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Download&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{download}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Source Code&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{source}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Bug Tracker&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;{{{tracker}}}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=User:Alan_Trick&amp;diff=55015</id>
		<title>User:Alan Trick</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=User:Alan_Trick&amp;diff=55015"/>
		<updated>2009-04-28T23:51:22Z</updated>

		<summary type="html">&lt;p&gt;Trick: New page: I’m the lead developer for the online course system at Trinity Western University. I’m also a student in Computer Science and Linguistics.  == Moodle Projects ==  * YUI menu — Le...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I’m the lead developer for the online course system at Trinity Western University. I’m also a student in Computer Science and Linguistics.&lt;br /&gt;
&lt;br /&gt;
== Moodle Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[YUI menu]] — Lead developer&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=55012</id>
		<title>File:YUI Menu.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=55012"/>
		<updated>2009-04-28T23:41:41Z</updated>

		<summary type="html">&lt;p&gt;Trick: uploaded a new version of &amp;quot;Image:YUI Menu.png&amp;quot;: cropped some of the background portion out&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Original picture of the YUI menu. It&#039;s dated, but nothing has changed.&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=55011</id>
		<title>File:YUI Menu.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=File:YUI_Menu.png&amp;diff=55011"/>
		<updated>2009-04-28T23:35:50Z</updated>

		<summary type="html">&lt;p&gt;Trick: Original picture of the YUI menu. It&amp;#039;s dated, but nothing has changed.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Original picture of the YUI menu. It&#039;s dated, but nothing has changed.&lt;/div&gt;</summary>
		<author><name>Trick</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/401/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26648</id>
		<title>Installing MSSQL for PHP</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/401/en/index.php?title=Installing_MSSQL_for_PHP&amp;diff=26648"/>
		<updated>2007-09-05T18:03:02Z</updated>

		<summary type="html">&lt;p&gt;Trick: /* Installation overview */  added textlimit/size config for php.ini&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.  Assuming that you have PHP 5.1.x, here how to set it up:&lt;br /&gt;
&lt;br /&gt;
1. [http://download.moodle.org/download.php/windows/php5.1/php_dblib.dll Download php_dblib.dll for PHP 5.1.x] and save it into your PHP extensions directory.&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;
&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>Trick</name></author>
	</entry>
</feed>