Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
2shediac committed Mar 31, 2016
0 parents commit 61da303
Show file tree
Hide file tree
Showing 16 changed files with 1,120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# usertest
34 changes: 34 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -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.
177 changes: 177 additions & 0 deletions block_user_contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* 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__.'<br />';
echo '$cid = '.$cid.'<br />';
echo '$bid = '.$bid.'<br />';
echo '$rcp = '.$receipt.'<br />';

echo 'count($allhiddenrecipients) = '.count($allhiddenrecipients).'<br />';
echo 'count($allstandardrecipients) = '.count($allstandardrecipients).'<br />';
}

//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('<a href="'.$address.'">'.$defaultlabel.'</a>', 'info centerpara');
} else {
$this->content->text .= $OUTPUT->single_button($address, $defaultlabel);
}
}

return $this->content;
}
}
58 changes: 58 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
// This file is part of user_contact block maintained by NLA.

/**
* Contact form block
*
* @package contrib
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$capabilities = array(

'block/user_contact:myaddinstance' => 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
)
)

);

117 changes: 117 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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
}
}
Loading

0 comments on commit 61da303

Please sign in to comment.