diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..e43b0f9
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1f61ea4
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# usertest
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..d6ce34c
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,34 @@
+Moodle 1.9 Contact Form Block by Daniele Cordella
+
+Originally based on:
+Moodle Web site Contact Form v_5 (by Nicole B. Hansen) (converted to a moodle block by Daryl Hawes)
+Discussion at:
+http://moodle.org/mod/forum/discuss.php?d=12411
+
+This block has had many contributers, from Daryl Hawes in Moodle 1.5, Daniele Cordella in Moodle 1.6, Matt Campbell in Moodle 1.7 & 1.8, and Valery Fremaux in Moodle 1.8.
+
+The Moodle 1.9 Contact Form Block builds upon the work of all these contributers and adds many new features made possible in 1.9.
+
+This block:
+
+1) Links via an html link or form button to a page where the user can submit comments.
+2) Supports different behavior whether the block is displayed on the main site index or in a course.
+3) Includes global configuration options.
+4) Includes per block instance configuration options.
+5) Utilizes two roles, block/user_contact:contactperson and block/user_contact:hiddenrecipient.
+6) Provides ReCAPTCHA support for sites that have this configured.
+
+This block is NOT compatible with Moodle versions prior to 1.9.
+
+HOW TO INSTALL
+
+1) Copy the entire user_contact folder from the blocks folder in the package into your Moodle site's blocks folder
+2) Visit the notifications page of your Moodle site with your browser. This is at Site Admin->Notifications, or you may go to http://YOURMOODLESITE/admin/index.php.
+
+Specific changes from previous versions:
+
+1) Converted block to use the Moodle formslib library.
+2) Added reCaptcha support. To use ReCAPTCHA, you must get a key and configure it on your Moodle install. See http://docs.moodle.org/en/Manage_authentication#ReCAPTCHA for details on enabling ReCAPTCHA.
+3) Added option for return receipts.
+4) Removed previous methods of determining course teachers and replaced with a role. block/user_contact:contactperson is enabled in the Teacher legacy role by default.
+5) Removed previous methods of adding a hidden recipient and replaced with a role. block/user_contact:hiddenrecipient is not enabled for any role when initially installed.
\ No newline at end of file
diff --git a/block_user_contact.php b/block_user_contact.php
new file mode 100644
index 0000000..15bb117
--- /dev/null
+++ b/block_user_contact.php
@@ -0,0 +1,177 @@
+.
+
+
+/**
+ * Contact form block
+ *
+ * @package contrib
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class block_user_contact extends block_base {
+
+ function init() {
+ $this->title = get_string('pluginname', 'block_user_contact');
+ }
+
+ function instance_allow_multiple() {
+ return false;
+ }
+
+ function has_config() {
+ return true;
+ }
+
+ function applicable_formats() {
+ return array('all' => true);
+ //return array('course' => true, 'site' => true);
+ }
+
+ function instance_allow_config() {
+ return true;
+ }
+
+ function has_add_block_capability($page, $capability) {
+ return
+ !get_capability_info($capability)
+ ? false
+ : has_capability($capability, $page->context);
+
+ }
+
+ function specialization() {
+ if (isset($this->config->defaulttitle)) { // local defaultlabel requested
+ $this->title = format_string(get_string('blocktitle','block_user_contact'));
+ } else {
+ if (isset($this->config->title)) { // local defaultlabel requested
+ $this->title = format_string($this->config->title);
+ } else {
+ $this->title = format_string(get_string('blocktitle','block_user_contact'));
+ }
+ }
+ }
+
+ function get_content() {
+ global $USER, $CFG, $OUTPUT;
+
+ require_once($CFG->dirroot.'/blocks/user_contact/lib.php');
+
+ if($this->content !== NULL) {
+ return $this->content;
+ }
+
+ if (empty($this->instance)) {
+ // We're being asked for content without an associated instance
+ $this->content = '';
+ return $this->content;
+ }
+
+ $this->content = new stdClass;
+ //$this->content->header = $this->title;
+ //$this->content->text = ''; //empty to start, will be populated below
+ //$this->content->footer = '';
+
+ $cid = $this->page->course->id; // course id
+ $bid = $this->instance->id; // block id
+
+ $allhiddenrecipients = user_contact_getallhiddenrecipients($cid, $bid);
+ $allstandardrecipients = user_contact_getallstandardrecipients($bid);
+
+ if ( !($allhiddenrecipients || $allstandardrecipients) ) {
+ $this->content->text = format_text(get_string('block_misconfigured', 'block_user_contact'));
+ $this->content->footer = format_text(get_string('block_misconfigured_footer', 'block_user_contact'));
+ } else {
+ // a blocco appena creato, $this->config non esiste
+ // print_object($this->config);
+
+ if (isset($this->config)) {
+ /////////////////////////////////////////////////
+ // esistono dei settings locali
+ /////////////////////////////////////////////////
+
+ //set displaytype to stored value
+ $displaytype = $this->config->displaytype;
+
+ //set defaultlabel to stored value
+ if (isset($this->config->defaultlabel)) { // local defaultlabel requested
+ $defaultlabel = format_string(get_string('defaultlabel','block_user_contact'));
+ } else {
+ $defaultlabel = format_string($this->config->label);
+ }
+ //set receipt to stored value
+ $receipt = $this->config->receipt;
+
+ //set welcometext to stored value
+ if (isset($this->config->defaultwelcometext)) { // local defaultwelcometext requested
+ $welcometext = format_text(get_string('welcometext','block_user_contact'));
+ } else {
+ $welcometext = format_text($this->config->welcometext['text']);
+ }
+ } else {
+ /////////////////////////////////////////////////
+ // non esistono dei settings locali: set defaults
+ /////////////////////////////////////////////////
+
+ //set displaytype to its default
+ $displaytype = 2; // deafult
+
+ //set defaultlabel to its default
+ $defaultlabel = format_string(get_string('defaultlabel','block_user_contact'));
+
+ //set receipt to its default
+ if (isset($CFG->block_user_contact_receipt)) {
+ $receipt = $CFG->block_user_contact_receipt;
+ } else {
+ $receipt = 0; // deafult
+ }
+
+ $welcometext = format_text(get_string('welcometext','block_user_contact'));
+ }
+
+ $debug = false;
+ if ($debug) {
+ echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.' ';
+ echo '$cid = '.$cid.' ';
+ echo '$bid = '.$bid.' ';
+ echo '$rcp = '.$receipt.' ';
+
+ echo 'count($allhiddenrecipients) = '.count($allhiddenrecipients).' ';
+ echo 'count($allstandardrecipients) = '.count($allstandardrecipients).' ';
+ }
+
+ //check our configuration setting to see what format we should display
+ // 0 == display a form button
+ // 1 == display a link
+ $options = array('sesskey'=>sesskey());
+ if ($cid) $options['cid'] = $cid;
+ if ($bid) $options['bid'] = $bid;
+ if ($receipt) $options['rcp'] = $receipt;
+ $address = new moodle_url('/blocks/user_contact/user_contact.php', $options);
+
+ $this->content->text = $OUTPUT->box($welcometext, 'info');
+
+ if ($displaytype == 1){
+ $this->content->text .= $OUTPUT->box(''.$defaultlabel.'', 'info centerpara');
+ } else {
+ $this->content->text .= $OUTPUT->single_button($address, $defaultlabel);
+ }
+ }
+
+ return $this->content;
+ }
+}
diff --git a/db/access.php b/db/access.php
new file mode 100644
index 0000000..258fd5a
--- /dev/null
+++ b/db/access.php
@@ -0,0 +1,58 @@
+ array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ 'archetypes' => array(
+ 'user' => CAP_ALLOW
+ ),
+ 'clonepermissionsfrom' => 'moodle/my:manageblocks'
+ ),
+
+ 'block/user_contact:addinstance' => array(
+ 'riskbitmask' => RISK_SPAM,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_BLOCK,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ ),
+
+ 'clonepermissionsfrom' => 'moodle/site:manageblocks'
+ ),
+
+ 'block/user_contact:hiddenrecipient' => array(
+
+ 'riskbitmask' => RISK_SPAM,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_BLOCK
+ ),
+
+ 'block/user_contact:contactperson' => array(
+
+ 'riskbitmask' => RISK_SPAM,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_BLOCK,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ )
+ )
+
+);
+
diff --git a/edit_form.php b/edit_form.php
new file mode 100644
index 0000000..de41b67
--- /dev/null
+++ b/edit_form.php
@@ -0,0 +1,117 @@
+.
+
+/**
+ * Form for editing Blog tags block instances.
+ *
+ * @package moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Form for editing Blog tags block instances.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class block_user_contact_edit_form extends block_edit_form {
+ protected function specific_definition($mform) {
+ global $CFG;
+
+ // Fields for editing user_contact settings.
+ $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
+
+ // config_title
+ $a = get_string('blocktitle', 'block_user_contact');
+ $objgroup = array();
+ $objgroup[] =& $mform->createElement('text', 'config_title');
+ $objgroup[] =& $mform->createElement('checkbox', 'config_defaulttitle', '', get_string('emptyfordefault', 'block_user_contact', $a));
+ $mform->addGroup($objgroup, 'title_group', get_string('configtitle', 'block_user_contact'), ' ', false);
+ $mform->disabledIf('title_group', 'config_defaulttitle', 'checked');
+ $mform->setDefault('config_title', get_string('pluginname', 'block_user_contact'));
+ $mform->setDefault('config_defaulttitle', 0);
+ $mform->setType('config_title', PARAM_MULTILANG);
+
+ // config_label
+ $a = get_string('defaultlabel', 'block_user_contact');
+ $objgroup = array();
+ $objgroup[] =& $mform->createElement('text', 'config_label');
+ $objgroup[] =& $mform->createElement('checkbox', 'config_defaultlabel', '', get_string('emptyfordefault', 'block_user_contact', $a));
+ $mform->addGroup($objgroup, 'label_group', get_string('configlabel', 'block_user_contact'), ' ', false);
+ $mform->disabledIf('label_group', 'config_defaultlabel', 'checked');
+ $mform->setDefault('config_label', get_string('defaultlabel', 'block_user_contact'));
+ $mform->setDefault('config_defaultlabel', 0);
+ $mform->setType('config_label', PARAM_MULTILANG);
+
+ // config_welcometext
+ $a = get_string('welcometext', 'block_user_contact');
+ $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context);
+ $objgroup = array();
+ $objgroup[] =& $mform->createElement('editor', 'config_welcometext', '', null, $editoroptions);
+ $objgroup[] =& $mform->createElement('checkbox', 'config_defaultwelcometext', '', get_string('emptyfordefault', 'block_user_contact', $a));
+ $mform->addGroup($objgroup, 'welcometext_group', get_string('configwelcometext', 'block_user_contact'), ' ', false);
+ $mform->disabledIf('welcometext_group', 'config_defaultwelcometext', 'checked');
+ $mform->setDefault('config_welcometext', get_string('welcometext', 'block_user_contact'));
+ $mform->setDefault('config_defaultwelcometext', 0);
+ $mform->setType('config_welcometext', PARAM_RAW);
+
+ // config_displaytype
+ $options = array();
+ $options[] = get_string('displayasabutton', 'block_user_contact');
+ $options[] = get_string('displayasalink', 'block_user_contact');
+ $mform->addElement('select', 'config_displaytype', get_string('configdisplaytype', 'block_user_contact'), $options);
+ $mform->setDefault('config_displaytype', get_string('welcometext','block_user_contact'));
+
+ // config_receipt
+ $options = array();
+ $options[] = get_string('receipt_disable', 'block_user_contact');
+ $options[] = get_string('receipt_enable', 'block_user_contact');
+ $mform->addElement('select', 'config_receipt', get_string('configreceipt', 'block_user_contact'), $options);
+ $default = (isset($CFG->block_user_contact_receipt)) ? $CFG->block_user_contact_receipt : 0;
+ $mform->setDefault('config_receipt', $default);
+ }
+
+ function set_data($defaults) {
+ if (!empty($this->block->config) && is_object($this->block->config)) {
+ $defaults->config_welcometext['text'] = $this->block->config->welcometext['text'];
+ $defaults->config_welcometext['itemid'] = file_get_submitted_draft_itemid('config_welcometext');
+ $defaults->config_welcometext['format'] = $this->block->config->welcometext['format'];
+ } else {
+ $defaults->config_welcometext['text'] = get_string('welcometext', 'block_user_contact');
+ $defaults->config_welcometext['itemid'] = file_get_submitted_draft_itemid('config_welcometext');
+ $defaults->config_welcometext['format'] = FORMAT_HTML;
+ }
+ // have to delete text here, otherwise parent::set_data will empty content of editor
+ unset($this->block->config->text);
+
+ //defaulttitle
+ $defaults->config_defaulttitle = isset($this->block->config->defaulttitle) ? 1 : 0;
+ unset($this->block->config->defaulttitle);
+
+ //defaultlabel
+ $defaults->config_defaultlabel = isset($this->block->config->defaultlabel) ? 1 : 0;
+ unset($this->block->config->defaultlabel);
+
+ //defaultwelcometext
+ $defaults->config_defaultwelcometext = isset($this->block->config->defaultwelcometext) ? 1 : 0;
+ unset($this->block->config->defaultwelcometext);
+
+ parent::set_data($defaults);
+ // restore $text
+ }
+}
diff --git a/lang/en/block_user_contact.php b/lang/en/block_user_contact.php
new file mode 100644
index 0000000..632fcbe
--- /dev/null
+++ b/lang/en/block_user_contact.php
@@ -0,0 +1,52 @@
+
teachers to the course or to the block*
and/or hidden recipients to the block*
to configure it.';
+$string['blockname'] = 'Contact us';
+$string['blocktitle'] = 'User contact';
+$string['commentreceived'] = '{$a} sent you a comment from ';
+$string['configdisplaytype'] = 'Display Type';
+$string['configlabel'] = 'Button label or link text';
+$string['configreceipt'] = 'Return receipt';
+$string['configtitle'] = 'Block Title';
+$string['configwelcometext'] = 'Introduction';
+$string['defaultlabel'] = 'Contact Us';
+$string['displayasabutton'] = 'Display as a button';
+$string['displayasalink'] = 'Display as a link';
+$string['displaytypedesc'] = 'How should this block\'s link to the contact form be displayed, as a form button or as a web link?';
+$string['email'] = 'Message';
+$string['emailbody_help'] = 'Use this field to type your message. You can even use html to add link, images and much more to your message.';
+$string['emailbody'] = 'Email html text area';
+$string['emptyfordefault'] = 'empty to accept multilanguage default: [{$a}]';
+$string['fromcourse'] = 'the course "{$a->coursename}" at "{$a->sitename}"';
+$string['fromhompageof'] = 'the home page at "{$a->sitename}"';
+$string['mailbody'] = 'Body';
+$string['mailsubject'] = 'Subject';
+$string['messagesent'] = 'Thank you for your comment. It has been sent and will be reviewed as soon as possible.';
+$string['missingmailbody'] = 'Please, enter the content of the message';
+$string['missingmailsubject'] = 'Please, enter a subject for the message';
+$string['missingrecipient'] = 'Please, select at least a recipient to send the message';
+$string['missingremoteuseremail'] = 'Please, enter your email address';
+$string['missingremoteusername'] = 'Please, enter your name';
+$string['pluginname'] = 'User contact';
+$string['receipt_disable'] = 'Disable return receipt';
+$string['receipt_enable'] = 'Enable return receipt';
+$string['receipt_info'] = 'Defines the return receipts defaults for each instance of user_contact. Locallly you will be always allowed to modify this setting. Return receipt allow students to receive a copy of messages sent by themselves.';
+$string['recipient'] = 'Recipient';
+$string['recipientemail'] = 'Recipient\'s email';
+$string['recipientname'] = 'Recipient';
+$string['recipients'] = 'Recipient(s)';
+$string['sendemail'] = 'Send';
+$string['sender'] = 'Sender';
+$string['subject_prefix_info'] = 'What string should be at the beginning of the subject for all email sent from this block? Entering a value here will make it easier for recipients to filter their email messages.';
+$string['subject_prefix'] = 'Subject prefix';
+$string['subject'] = 'Subject';
+$string['user_contact:contactperson'] = 'Belong to the list of standard recipients for communications';
+$string['user_contact:hiddenrecipient'] = 'Receive a copy of each communication';
+// [NLA] Saving addinstance properties from 1.9 block if needed
+$string['user_contact:addinstance'] = 'Add a new user_contact block';
+$string['user_contact:myaddinstance'] = 'Add a new user_contact block to the My Moodle page';
+$string['usercanceled'] = 'Action was canceled. Not any message was sent.';
+$string['welcome_info'] = 'Use this form to contact us. Note: If you need to report an issue with our training site, please be sure to include a detailed description of the problem and if possible the steps you took to produce the issue.
+Thank you. ';
+$string['welcometext'] = 'Write us to inquire, express opinions, complaints, suggestions or compliments';
diff --git a/lang/it/block_user_contact.php b/lang/it/block_user_contact.php
new file mode 100644
index 0000000..20a63ce
--- /dev/null
+++ b/lang/it/block_user_contact.php
@@ -0,0 +1,48 @@
+
docenti al corso o al blocco*
e/o destinatari nascosti al blocco*
per configurarlo correttamente.';
+$string['blockname'] = 'Sportello utente';
+$string['blocktitle'] = 'Sportello utente';
+$string['commentreceived'] = '{$a} ti ha inviato una comunicazione ';
+$string['configdisplaytype'] = 'Interfaccia';
+$string['configlabel'] = 'Etichetta o link';
+$string['configreceipt'] = 'Ricevuta al mittente';
+$string['configtitle'] = 'Titolo del blocco';
+$string['configwelcometext'] = 'Invito del blocco';
+$string['defaultlabel'] = 'Contattaci';
+$string['displayasabutton'] = 'Mostra come un bottone';
+$string['displayasalink'] = 'Mostra come collegamento';
+$string['displaytypedesc'] = 'In quale modo questo blocco deve consentire l\'accesso alla scheda di invio di una comunicazione, come un bottone o come un link ipertestuale?';
+$string['email'] = 'Comunicazione';
+$string['emailbody_help'] = 'Usa questo campo per scrivere la tua comunicazione. E\' possibile usare l\'html per arricchire il proprio messaggio con link e immagini e quant\'altro.';
+$string['emailbody'] = 'Email html text area';
+$string['emptyfordefault'] = 'Vuoto per accettare il default multilingua: [{$a}]';
+$string['fromcourse'] = 'dal corso "{$a->coursename}" di "{$a->sitename}"';
+$string['fromhompageof'] = 'dalla home page di "{$a->sitename}"';
+$string['mailbody'] = 'Corpo';
+$string['mailsubject'] = 'Soggetto';
+$string['messagesent'] = 'Il messaggio è stato inviato. La ringraziamo per il suo interessamento.';
+$string['missingmailbody'] = 'Si descriva il contenuto della comunicazione';
+$string['missingmailsubject'] = 'Si specifichi un oggetto della comunicazione';
+$string['missingrecipient'] = 'Si selezioni almeno almeno un destinatario della comunicazione';
+$string['missingremoteuseremail'] = 'Si digiti il proprio indirizzo di posta elettronica';
+$string['missingremoteusername'] = 'Si scriva il proprio nome';
+$string['pluginname'] = 'Sportello utente';
+$string['receipt_disable'] = 'Nega la ricevuta ai mittenti';
+$string['receipt_enable'] = 'Forza la ricevuta ai mittenti';
+$string['receipt_info'] = 'Contempla fra i destinatari del messaggio anche il mittente';
+$string['recipient'] = 'Destinatario';
+$string['recipientemail'] = 'Mail del destinatario';
+$string['recipientname'] = 'Destinatario';
+$string['recipients'] = 'Possibili destinatari';
+$string['sendemail'] = 'Invia';
+$string['sender'] = 'Mittente';
+$string['subject_prefix_info'] = 'Usa questo prefisso per caratterizzare le comunicazioni provenienti da questa installazione di moodle';
+$string['subject_prefix'] = 'Prefisso dell\'oggetto delle comunicazioni';
+$string['subject'] = 'Oggetto';
+$string['user_contact:contactperson'] = 'Appartenere alla lista dei destinatari ordinari delle comunicazioni';
+$string['user_contact:hiddenrecipient'] = 'Verificare tutta la messaggistica in copia nascosta';
+$string['usercanceled'] = 'L\'operazione è stata annullata. Nessuna messaggio è stato inviato.';
+$string['welcome_info'] = 'Siamo interssati alle tue idee. Usa questa scheda per inviare la tua comunicazione.';
+$string['welcometext'] = 'Scrivici per chiedere informazioni, esprimere opinioni o inviare segnalazioni, lamentele, suggerimenti o complimenti.';
diff --git a/lang/ja/block_user_contact.php b/lang/ja/block_user_contact.php
new file mode 100644
index 0000000..c207c94
--- /dev/null
+++ b/lang/ja/block_user_contact.php
@@ -0,0 +1,46 @@
+
para configurá-lo.';
+$string['blockname'] = 'Formulário de contacto';
+$string['blocktitle'] = 'Formulário de contacto';
+$string['commentreceived'] = 'Recebeu uma mensagem ';
+$string['configdisplaytype'] = 'Forma de apresentação';
+$string['linkconfiglabeltext'] = 'Texto do botão ou da hiperligação';
+$string['configreceipt'] = 'Recibo';
+$string['configtitle'] = 'Título do bloco';
+
+$string['defaultlabel'] = 'Contactar administrador';
+$string['displayasabutton'] = 'Mostrar como um botão';
+$string['displayasalink'] = 'Mostrar como uma ligação';
+$string['displaytypedesc'] = 'Como deve este bloco ser apresentado? Como um botão ou como uma hiperligação?';
+$string['email'] = 'Mensagem';
+
+
+$string['fromcourse'] = 'da disciplina "{$a->coursename}" de "{$a->sitename}"';
+$string['fromhompageof'] = 'da página inicial de "{$a->sitename}"';
+$string['mailbody'] = 'Texto da mensagem';
+$string['mailsubject'] = 'Assunto';
+$string['messagesent'] = 'Obrigado pelo sua mensagem. Foi enviada e será processada com a brevidade possível.';
+$string['missingmailbody'] = 'Escreva o conte˙do da sua messagem';
+$string['missingmailsubject'] = 'Escreva o assunto';
+$string['missingrecipient'] = 'Seleccione pelo menos um destinatário para a sua mensagem';
+$string['missingremoteuseremail'] = 'Insira o seu endereço de e-mail';
+$string['missingremoteusername'] = 'Insira o seu nome';
+$string['pluginname'] = 'Formulário de contacto';
+$string['receipt_disable'] = 'Não enviar recibos aos remetentes';
+$string['receipt_enable'] = 'Enviar recibos aos remetentes';
+$string['receipt_info'] = 'Permitir enviar uma cópia da mensagem para o remetente.';
+$string['recipient'] = 'Destinatário';
+$string['recipientemail'] = 'Email do destinatário';
+$string['recipientname'] = 'Destinatário';
+$string['recipients'] = 'Destinatário(s)';
+$string['sendemail'] = 'Enviar';
+$string['sender'] = 'Remetente';
+$string['subject_prefix_info'] = 'Conteúdo a constar no início do assunto das mensagens enviadas através deste bloco. Preencher este campo facilita o reconhecimento das mensagens por parte dos destinatários.';
+$string['subject_prefix'] = 'Prefixo a colocar no assunto';
+$string['subject'] = 'Assunto';
+$string['usercanceled'] = 'O envio foi cancelado. Nenhuma mensaem foi enviada.';
+$string['user_contact:contactperson'] = 'Pertence à lista de destinários pré-definidos para as mensagens';
+$string['user_contact:hiddenrecipient'] = 'Receber uma cÛpia de todas as mensagens';
+$string['welcome_info'] = 'Esta é uma forma de facilitar o contacto. Use este formulário para enviar a sua mensaem por correio electrónico.';
diff --git a/lib.php b/lib.php
new file mode 100644
index 0000000..b30ffa7
--- /dev/null
+++ b/lib.php
@@ -0,0 +1,42 @@
+recaptchapublickey) && !empty($CFG->recaptchaprivatekey);
+ }
+
+ function user_contact_getallstandardrecipients($bid) {
+ $debug = false;
+
+ $blockcontext = context_block::instance($bid);
+ $contactpersons = get_users_by_capability($blockcontext, 'block/user_contact:contactperson', 'u.id, u.firstname, u.lastname, u.email, u.mailformat', 'u.lastname ASC','','','','',false);
+ if ($debug) {
+ echo '****** Written from line '.__LINE__.' of '.__FILE__.' ******** ';
+ echo '';
+ echo 'contactperson (block/user_contact:contactperson) ';
+ print_object($contactpersons);
+ }
+
+ return $contactpersons;
+ }
+
+ function user_contact_getallhiddenrecipients($cid,$bid) {
+ global $sid;
+
+ $debug = false;
+
+ if ($cid == SITEID) {
+ $blockcontext = context_system::instance(0);
+ } else {
+ $blockcontext = context_block::instance($bid);
+ }
+ $hiddenrecipients = get_users_by_capability($blockcontext, 'block/user_contact:hiddenrecipient', 'u.id, u.firstname, u.lastname, u.email, u.mailformat', 'u.lastname ASC','','','','',false);
+ if ($debug) {
+ echo '****** Written from line '.__LINE__.' of '.__FILE__.' ******** ';
+ echo '';
+ echo 'hiddencollector (block/user_contact:hiddenrecipients) ';
+ print_object($hiddenrecipients);
+ }
+
+ return $hiddenrecipients;
+ }
+?>
\ No newline at end of file
diff --git a/sendmessage.php b/sendmessage.php
new file mode 100644
index 0000000..a7f8308
--- /dev/null
+++ b/sendmessage.php
@@ -0,0 +1,161 @@
+wwwroot .'/'. $CFG->admin .'/index.php');
+ }
+
+ $debug = false;
+ if ($debug) {
+ echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.' ';
+ echo '$cid = '.$cid.' ';
+ echo '$bid = '.$bid.' ';
+ echo '$rcp = '.$rcp.' ';
+
+ echo 'count($allhiddenrecipients) = '.count($allhiddenrecipients).' ';
+ echo 'count($allstandardrecipients) = '.count($allstandardrecipients).' ';
+ }
+
+ //print_object($fromform);
+
+ // definition of $messagehtml
+ $messagehtml = get_string('commentreceived', 'block_user_contact', $fromform->cf_sendername);
+ // Name Surame sent you a comment from
+ // Nome Cognome ti ha inviato una comunicazione
+
+ $a = new object();
+ $a->sitename = $site->shortname;
+ if ($cid == SITEID) {
+ $messagehtml .= get_string('fromhompageof', 'block_user_contact', $a).' ';
+ // Name Surame sent you a comment from the home page of M19
+ // Nome Cognome ti ha inviato una comunicazione dalla home page di M19
+ } else {
+ $a->coursename = $course->shortname;
+ $messagehtml .= get_string('fromcourse', 'block_user_contact', $a).' ';
+ // Name Surame sent you a comment from course xxx of M19
+ // nome cognome ti ha inviato una comunicazione dal corso xxx di M19
+ }
+
+ $messagehtml .= ' '.format_text($fromform->cf_mailbody['text'],$fromform->cf_mailbody['format']);
+ $messagehtml .= '
+
Client Info
+
+
+
Browser
+
'.$fromform->cf_browser.'
+
+
+
Engine
+
'.$fromform->cf_engine.'
+
+
+
OS Type
+
'.$fromform->cf_os.'
+
+
+
Device
+
'.$fromform->cf_device.'
+
+
';
+ //print_object($fromform);
+ // end of definition of $messagehtml
+
+ // definition of $messagetext
+ $messagetext = str_replace(' ', "\n", $messagehtml);
+ $messagetext = strip_tags($messagetext);
+ // end of definition of $messagetext
+
+ if (false) {
+ echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.' ';
+ echo '$CFG->block_user_contact_subject_prefix = '.$CFG->block_user_contact_subject_prefix.' '; // [M20]
+
+ echo '';
+ echo '$rcp = '.$rcp.' ';
+ echo '';
+
+ echo '
$messagetext =
';
+ echo '';
+
+ echo '
$messagehtml =
';
+ echo '';
+
+ echo '';
+ echo '
$messagetext = ';
+ echo $messagetext;
+ echo '
';
+ echo '
$messagehtml = ';
+ echo $messagehtml;
+ echo '
';
+ echo '';
+ die;
+ }
+
+ //sender infos
+ $from = new object;
+ $from->firstname = $fromform->cf_sendername;
+ $from->lastname = '';
+ $from->email = $fromform->cf_senderemail;
+ $from->maildisplay = true;
+ $from->mailformat = $fromform->cf_sendermailformat;
+
+ //define the subject starting from the pre-defined prefix
+ if ($cid == SITEID) {
+ // as far as I understand, the next if is useless because
+ // it was defined a default for $CFG->block_user_contact_subject_prefix
+ if (!isset($CFG->block_user_contact_subject_prefix)) {
+ $CFG->block_user_contact_subject_prefix = '['.strip_tags($site->shortname).'] ';
+ }
+ $subject = $CFG->block_user_contact_subject_prefix.$fromform->cf_mailsubject;
+ } else {
+ //set the subject to start with [shortname]
+ $subject = '['.$course->shortname.'] '.$fromform->cf_mailsubject;
+ }
+
+
+if (!$debug) {
+ //send emails
+ $fullnamesender = fullname($from);
+ if ($allhiddenrecipients) {
+ foreach ($allhiddenrecipients as $thisrecipient) {
+ $fullnamerecipient = fullname($thisrecipient);
+ $property = 'cf_teacher'.$thisrecipient->id;
+ if ( isset($fromform->{$property}) ) {
+ if ( email_to_user($thisrecipient, $from, $subject, $messagetext, $messagehtml) ) {
+ add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject: '.$subject);
+ } else {
+ echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
+ add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject:'.$subject);
+ }
+ }
+ }
+ }
+
+ if ($allstandardrecipients) {
+ foreach ($allstandardrecipients as $thisrecipient) {
+ $fullnamerecipient = fullname($thisrecipient);
+ $property = 'cf_teacher'.$thisrecipient->id;
+ if ( isset($fromform->{$property}) ) {
+ if ( email_to_user($thisrecipient, $from, $subject, $messagetext, $messagehtml) ) {
+ add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject: '.$subject);
+ } else {
+ echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
+ add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject:'.$subject);
+ }
+ }
+ }
+ }
+
+ if ( $rcp == 1 ) {
+ $subject = get_string('receipt', 'block_user_contact').$subject;
+ if ( email_to_user($from, $from, $subject, $messagetext, $messagehtml) ) {
+ add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamesender.'; From: '.$fullnamesender.'; Subject: '.$subject);
+ } else {
+ echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
+ add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamesender.'; From: '.$fullnamesender.'; Subject:'.$subject);
+ }
+ }
+} // end of: if (!$debug)
+
+?>
\ No newline at end of file
diff --git a/settings.php b/settings.php
new file mode 100644
index 0000000..e34fda8
--- /dev/null
+++ b/settings.php
@@ -0,0 +1,23 @@
+add(
+ new admin_setting_configtext('block_user_contact_subject_prefix',
+ get_string('subject_prefix', 'block_user_contact'),
+ get_string('subject_prefix_info', 'block_user_contact'),
+ '['. strip_tags($SITE->shortname) .']',PARAM_RAW));
+
+$settings->add(
+ new admin_setting_configcheckbox('block_user_contact_receipt',
+ get_string('receipt_enable', 'block_user_contact'),
+ get_string('receipt_info', 'block_user_contact'), 0));
+?>
\ No newline at end of file
diff --git a/user_contact.php b/user_contact.php
new file mode 100644
index 0000000..952482b
--- /dev/null
+++ b/user_contact.php
@@ -0,0 +1,84 @@
+libdir.'/blocklib.php');
+ require_once('user_contact_form.php');
+ require_once($CFG->dirroot.'/blocks/user_contact/lib.php');
+
+ if (!confirm_sesskey()) {
+ print_error('confirmsesskeybad', 'error');
+ }
+
+ $cid = optional_param('cid', 0, PARAM_INT); // course ID
+ $bid = optional_param('bid', 0, PARAM_INT); // block ID
+ $rcp = optional_param('rcp', 0, PARAM_INT); // was receipt requested?
+
+ // if you are reloading the page without resending right parameters,
+ // stop here your work and redirect to the home page.
+ //if ($cid == 0)
+ // redirect($CFG->wwwroot.'/index.php');
+
+ $debug = false;
+ if ($debug) {
+ echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.' ';
+ echo 'course ID: $cid = '.$cid.' ';
+ echo 'block ID: $bid = '.$bid.' ';
+ echo '$rcp = '.$rcp.' ';
+ //die;
+ }
+ if (! $course = $DB->get_record('course', array('id'=>$cid))) {
+ print_error('coursemisconf');
+ }
+
+ //----------------------------------------------------------------------------
+// Initialize $PAGE, compute blocks
+ $PAGE->set_url('/blocks/user_contact/user_contact_form.php', array('cid' => $cid, 'bid' => $bid, 'rcp' => $rcp));
+ $context = context_system::instance(0);
+ $PAGE->set_context($context);
+ $PAGE->set_title($course->shortname.': user_contact');
+ $PAGE->set_heading($course->fullname);
+ $PAGE->set_pagelayout('course');
+ //$PAGE->set_pagetype('course-view-' . $course->format);
+
+
+ //print_object($PAGE);
+ if ($cid == SITEID) { // home page
+ //$PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php?id='.$cid));
+ $PAGE->navbar->add(get_string('pluginname','block_user_contact'));
+ } else {
+ $countcategories = $DB->count_records('course_categories');
+ if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) {
+ $PAGE->navbar->add(get_string('categories'));
+ } else {
+ $PAGE->navbar->add(get_string('courses'), new moodle_url('/course/category.php?id='.$course->category));
+ $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php?id='.$cid));
+ $PAGE->navbar->add(get_string('pluginname','block_user_contact'));
+ }
+ }
+
+ //----------------------------------------------------------------------------
+ $allhiddenrecipients = user_contact_getallhiddenrecipients($cid,$bid);
+ $allstandardrecipients = user_contact_getallstandardrecipients($bid);
+
+ $mform = new block_user_contact_form($CFG->wwwroot.'/blocks/user_contact/user_contact.php');
+ if ($mform->is_cancelled()) {
+ // submission was canceled. Return back.
+ $returnurl = ($cid == SITEID) ? new moodle_url('/index.php') : new moodle_url('/course/view.php', array('id'=>$cid));
+ redirect($returnurl,get_string('usercanceled','block_user_contact'));
+ } else if ($fromform = $mform->get_data()) {
+ // form was successfully submitted. Now send.
+ include_once('sendmessage.php');
+
+ $returnurl = ($cid == SITEID) ? new moodle_url('/index.php') : new moodle_url('/course/view.php', array('id'=>$cid));
+ redirect($returnurl,get_string('messagesent','block_user_contact'));
+ } else {
+ //this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
+ //or on the first display of the form.
+ //put data you want to fill out in the form into array $toform here then :
+ echo $OUTPUT->header();
+ echo $OUTPUT->box(get_string('welcome_info', 'block_user_contact'));
+ $mform->display();
+ /// Finish the page
+ echo $OUTPUT->footer();
+ }
diff --git a/user_contact_form.php b/user_contact_form.php
new file mode 100644
index 0000000..1c8e67a
--- /dev/null
+++ b/user_contact_form.php
@@ -0,0 +1,208 @@
+libdir.'/formslib.php');
+
+class block_user_contact_form extends moodleform {
+ function definition() {
+ global $CFG, $USER, $PAGE, $cid, $bid, $rcp, $allhiddenrecipients, $allstandardrecipients;
+
+ $mform =& $this->_form;
+
+ //From: http://docs.moodle.org/en/Development:Coding
+ // Use 'sesskey' mechanism to protect form handling routines from attack.
+ /* Basic example of use: when form is generated, include . */
+ // When you process the form check with if (!confirm_sesskey()) { print_error('confirmsesskeybad');}
+
+ $PAGE->requires->js('/lib/nla/ua-parser.min.js');
+ $onloadJS = 'var parser = new UAParser();
+var b = parser.getBrowser();
+var e = parser.getEngine();
+var o = parser.getOS();
+var d = parser.getDevice();
+var device_string =
+ (d.model === undefined)
+ ? "Personal Computer"
+ : d.model + " | " + d.type + " | " + d.vendor;
+document.getElementById("ua_browser").innerHTML =
+ document.getElementsByName("cf_browser")[0].value = "" + b.name + " " + b.major + " (" + b.version + ")";
+document.getElementById("ua_engine").innerHTML =
+ document.getElementsByName("cf_engine")[0].value = "" + e.name + " (" + e.version + ")";
+document.getElementById("ua_os").innerHTML =
+ document.getElementsByName("cf_os")[0].value = "" + o.name + " " + o.version;
+document.getElementById("ua_device").innerHTML =
+ document.getElementsByName("cf_device")[0].value = device_string;
+';
+ $PAGE->requires->js_init_code($onloadJS, true);
+ $debug = false;
+ if ($debug) {
+ echo '****** Written from line '.__LINE__.' of '.__FILE__.' ******** ';
+ echo '$cid = '.$cid.' ';
+ echo '$bid = '.$bid.' ';
+ echo '$rcp = '.$rcp.' ';
+ if ($allhiddenrecipients) {
+ $countallhiddenrecipients = count($allhiddenrecipients);
+ } else {
+ $countallhiddenrecipients = 0;
+ }
+ echo 'count($allhiddenrecipients) = '.$countallhiddenrecipients.' ';
+
+ if ($allstandardrecipients) {
+ $countallstandardrecipients = count($allstandardrecipients);
+ } else {
+ $countallstandardrecipients = 0;
+ }
+ echo 'count($allstandardrecipients) = '.$countallstandardrecipients;
+ }
+ // what am I supposed to do if a guy is hiddenrecipient and standardrecipient too?
+
+ // no fieldset needed
+ $mform->addElement('hidden', 'sesskey', sesskey());
+ $mform->addElement('hidden', 'cid', $cid);
+ $mform->addElement('hidden', 'bid', $bid);
+ $mform->addElement('hidden', 'rcp', $rcp);
+
+ // fieldset sender
+ $mform->addElement('header', 'sender', get_string('sender', 'block_user_contact'));
+ if (isloggedin() && (!isguestuser($USER))) {
+ // static_sendername
+ $mform->addElement('static', 'static_sendername', get_string('name'),fullname($USER));
+ $mform->addElement('hidden', 'cf_sendername', fullname($USER));
+
+ // static_senderemail
+ $mform->addElement('static', 'static_senderemail', get_string('email'),$USER->email);
+ $mform->addElement('hidden', 'cf_senderemail', $USER->email);
+ $mform->addElement('hidden', 'cf_sendermailformat', $USER->mailformat);
+ } else {
+ // cf_opensendername
+ $mform->addElement('text', 'cf_sendername', get_string('name'));
+ $mform->addRule('cf_sendername', get_string('missingremoteusername','block_user_contact'), 'required', null, 'client');
+
+ // cf_opensenderemail
+ $mform->addElement('text', 'cf_senderemail', get_string('email'));
+ $mform->addRule('cf_senderemail', get_string('missingremoteuseremail','block_user_contact'), 'required', null, 'client');
+ $mform->addElement('hidden', 'cf_sendermailformat', '1');
+ }
+
+
+ // no fieldset needed
+ if ($allhiddenrecipients) {
+ foreach ($allhiddenrecipients as $recipient) {
+ $mform->addElement('hidden', 'cf_teacher'.$recipient->id, '1');
+ $mform->addElement('hidden', 'cf_emailteacher'.$recipient->id, $recipient->email);
+ }
+ }
+
+
+ // fieldset recipients
+ if ($allstandardrecipients) {
+ // [NLA] commenting out line
+ //$mform->addElement('header', 'recipients', get_string('recipients', 'block_user_contact'));
+ foreach ($allstandardrecipients as $recipient) {
+ // [NLA] original line:
+ //$mform->addElement('checkbox', 'cf_teacher'.$recipient->id, fullname($recipient));
+ $mform->addElement('hidden', 'cf_teacher'.$recipient->id, fullname($recipient));
+ $mform->addElement('hidden', 'cf_emailteacher'.$recipient->id, $recipient->email);
+ }
+ if (count($allstandardrecipients) == 1) {
+ $mform->setDefault('cf_teacher'.$recipient->id, '1');
+ }
+ }
+
+ $mform->addElement('header', 'client', "Client Info");
+ $mform->addElement('static', 'browser', 'Browser', "");
+ $mform->addElement('hidden', 'cf_browser', '');
+ $mform->addElement('static', 'engine', 'Engine', "");
+ $mform->addElement('hidden', 'cf_engine', '');
+ $mform->addElement('static', 'os', 'OS Type', "");
+ $mform->addElement('hidden', 'cf_os', '');
+ $mform->addElement('static', 'device', 'Device', "");
+ $mform->addElement('hidden', 'cf_device', '');
+
+ // fieldset email
+ $mform->addElement('header', 'email', get_string('email', 'block_user_contact'));
+
+ // cf_mailsubject
+ $mform->addElement('text', 'cf_mailsubject', get_string('mailsubject','block_user_contact'));
+ $mform->addRule('cf_mailsubject', get_string('missingmailsubject','block_user_contact'), 'required', null, 'client');
+
+ // cf_mailbody
+ $textfieldoptions = array('trusttext'=>false, 'subdirs'=>true, 'maxfiles'=>3, 'maxbytes'=>1024);
+ $mform->addElement('editor', 'cf_mailbody', get_string('mailbody','block_user_contact'), null, $textfieldoptions);
+ $mform->setType('cf_mailbody', PARAM_RAW);
+ $mform->addRule('cf_mailbody', get_string('missingmailbody','block_user_contact'), 'required', null, 'client');
+ // $mform->addHelpButton('cf_mailbody', 'userdescription');
+ $mform->addHelpButton('cf_mailbody', 'emailbody', 'block_user_contact');
+
+ // recaptcha
+ if (user_contact_recaptchaenabled()) {
+ $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
+ $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth')));
+ $mform->addRule('recaptcha_element', get_string('missingrecaptcha','block_user_contact'), 'required', null, 'client');
+ }
+
+//-------------------------------------------------------------------------------
+ // buttons
+ $this->add_action_buttons(true, get_string('sendemail','block_user_contact'));
+ }
+
+ function definition_after_data() {
+ }
+
+ function validation($data) {
+ global $allhiddenrecipients, $allstandardrecipients;
+//print_object($data);
+
+ $errors = array();
+ if (!confirm_sesskey()) {
+ print_error('confirmsesskeybad');
+ }
+
+ if (!isloggedin()) {
+ if (! validate_email($data['cf_senderemail'])) {
+ $errors['cf_senderemail'] = get_string('invalidemail');
+ }
+ }
+
+ if ($allhiddenrecipients) {
+ $offset = count($allhiddenrecipients);
+ } else {
+ $offset = 0;
+ }
+ // if there are not $allstandardrecipients (alias !isset($allstandardrecipients)) there is nothing to check
+ // so all is right ($allright = true)
+ $allright = empty($allstandardrecipients);
+ if (!$allright) {
+ $i = $offset;
+ foreach ($allstandardrecipients as $recipient) {
+ if ( isset($data['cf_teacher'.$recipient->id]) ) {
+ $allright = true;
+ continue;
+ }
+ }
+ }
+
+ if (!$allright) {
+ foreach ($allstandardrecipients as $recipient) {
+ $errors['cf_teacher'.$recipient->id] = get_string('missingrecipient','block_user_contact');
+ }
+ }
+
+ // controllare il recaptcha
+ if (user_contact_recaptchaenabled()) {
+ $recaptcha_element = $this->_form->getElement('recaptcha_element');
+ if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
+ $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
+ $response_field = $this->_form->_submitValues['recaptcha_response_field'];
+ if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
+ $errors['recaptcha_element'] = $result;
+ }
+ } else {
+ $errors['recaptcha_element'] = get_string('missingrecaptchachallengefield');
+ }
+ }
+
+ return $errors;
+ }
+}
+?>
\ No newline at end of file
diff --git a/version.php b/version.php
new file mode 100644
index 0000000..b3d628c
--- /dev/null
+++ b/version.php
@@ -0,0 +1,22 @@
+.
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2015111601;
+$plugin->requires = 2015111000; // Requires this Moodle version
+$plugin->component = 'block_user_contact'; // Full name of the plugin (used for diagnostics)
\ No newline at end of file