Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
437 changes: 437 additions & 0 deletions admin/report/fitandproper/cpdactivityadmin.php

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions admin/report/fitandproper/cpdactivityadmin_ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Handles the AJAX call from the CPD Activity Add/Edit form, to get the sub categories from a selected top category
*/

require_once(dirname(__FILE__).'/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
}

require_login();

require_capability('report/fitandproper:viewcpdactivities', get_context_instance(CONTEXT_SYSTEM));

$cid = (int)$_GET['cid'];

if($cid > 0)
{
$categories = $DB->get_records('fais_sub_category',array('fais_category_id'=>$cid,'enabled'=>1,'deleted'=>0),'name','id,name');
$count = count($categories);
if($count > 0)
{
$return = array('categories'=>$categories,'count'=>$count);
print json_encode($return);
}else
{
print json_encode(array('count'=>0));
}
}
?>
144 changes: 144 additions & 0 deletions admin/report/fitandproper/cpdactivityadmin_edit_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
require_once($CFG->libdir.'/formslib.php');

/**
* a Class to diplay the CPD Activities add/edit form
*/
class cpdactivityadmin_edit_form extends moodleform {

function definition()
{
global $DB;

$mform = $this->_form;

$op = $this->_customdata['op'];
$id = $this->_customdata['id'];

/*
* if this is a edit form get the activity data for edit
*/
if($op == 'edit' && $id != null)
{
$data = $DB->get_record('cpd_activity',array('id'=>$id,'deleted'=>0));
}

/*
* get activity types
*/
$dtypes = $DB->get_records('cpd_activity_type');
$types = array();
foreach($dtypes as $t)
{
$types[$t->id] = $t->name;
}

/*
* get list of top level categories
*/
$fais_categories = $DB->get_records('fais_category',array('deleted'=>0,'enabled'=>1),'name','id,name');
$category_list = array('0'=>'Please select ...');
foreach($fais_categories as $category)
{
$category_list[$category->id] = $category->name;
}

$fais_sub_categories = array(0=>'Please select a category');
if($op == 'edit')
{
$mform->setDefault('id', $id);
$mform->setDefault('name', $data->name);
$mform->setDefault('code', $data->code);
$mform->setDefault('hours', $data->hours);
$mform->setDefault('enabled', $data->enabled);
$mform->setDefault('type', $data->cpd_activity_type_id);

//get and set categories
$sub_categories = $DB->get_records_sql('SELECT * FROM {cpd_activity_fais_sub_cat} scl INNER JOIN mdl_fais_sub_category sc ON (scl.fais_sub_category_id = sc.id) WHERE scl.cpd_activity_id = ? ORDER BY sc.name',array($id));
$top = 0;
$fais_sub_categories = array();
$sub_categories_defaults = array();
foreach($sub_categories as $sc)
{
$top = $sc->fais_category_id;
$sub_categories_defaults[] = $sc->fais_sub_category_id;
}

//get all sub categories
$sub_categories = $DB->get_records('fais_sub_category',array('fais_category_id'=>$top,'enabled'=>1,'deleted'=>0),'name','id,name');
foreach($sub_categories as $sc)
{
$fais_sub_categories[$sc->id] = $sc->name;
}

$mform->setDefault('subcategory', $sub_categories_defaults);
$mform->setDefault('category', $top);

}else
{
$mform->setDefault('enabled', 1);
}

$header = ($op == 'edit') ? 'Edit' : 'Add';

$mform->addElement('html', '<div class="institutionsformheader"><h3>'.$header.' CPD Activity</h3></div>');

$mform->addElement('select', 'type', get_string('cpdactivity_type', 'report_fitandproper'), $types);
$mform->addElement('text', 'code', get_string('cpdactivity_code', 'report_fitandproper'));
$mform->addRule('code', null, 'required', null, 'client');
$mform->addRule('code', null, 'maxlength', 255, 'client');
$mform->addRule('code', get_string('cpdactivity_codeformat', 'report_fitandproper'), 'regex', "/^[a-zA-Z0-9_]+$/", 'client');

$mform->addElement('text', 'name', get_string('cpdactivity_name', 'report_fitandproper'));
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', null, 'maxlength', 255, 'client');
$mform->addRule('name', get_string('cpdactivity_nameformat', 'report_fitandproper'), 'regex', "/^[a-zA-Z0-9\s]+$/", 'client');
$mform->addElement('text', 'hours', get_string('cpdactivity_hours', 'report_fitandproper'));
$mform->addRule('hours', null, 'numeric', null, 'client');
$mform->addElement('select', 'category', get_string('cpdactivity_category', 'report_fitandproper'), $category_list);

$subselect = $mform->addElement('select', 'subcategory', get_string('cpdactivity_subcategory', 'report_fitandproper'), $fais_sub_categories);
$subselect->setMultiple(true);
$mform->disabledIf('subcategory', 'category', 'eq', 0);

$mform->addElement('checkbox', 'enabled', get_string('enabled', 'report_fitandproper'));

$mform->addElement('hidden', 'op', $op);
$mform->addElement('hidden', 'id');

$this->add_action_buttons(true,get_string('cpdactivity_submit', 'report_fitandproper'));
}

function validation($data)
{
global $DB;

$errors = array();
//check for duplicate code
$check = $DB->count_records_select('cpd_activity','deleted = 0 and code = ? and id != ?',array($data['code'],$data['id']));

if($check > 0)
{
$errors['code'] = get_string('cpdactivity_submit_duplicate_code', 'report_fitandproper');
}

//check for duplicate name
$check = $DB->count_records_select('cpd_activity','deleted = 0 and name = ? and id != ?',array($data['name'],$data['id']));

if($check > 0)
{
$errors['name'] = get_string('cpdactivity_submit_duplicate_name', 'report_fitandproper');
}

//check that a sub category is selected when top category is selected
if($data['category'] > 0)
{
if(!isset($_POST['subcategory']) || $_POST['subcategory'][0] == '0')
{
$errors['subcategory'] = get_string('cpdactivity_submit_nosub', 'report_fitandproper');
}
}

return $errors;
}
}
49 changes: 49 additions & 0 deletions admin/report/fitandproper/cpdactivityadmin_links_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

require_once($CFG->libdir.'/formslib.php');

/**
* a Class to diplay the CPD Activities edit links report form
*/
class cpdactivityadmin_links_form extends moodleform {

function definition()
{
global $DB;

$mform = $this->_form;

$edit_form = $this->_customdata['edit_form'];
//$can_save = $this->_customdata['can_save'];

$mform->addElement('hidden', 'id', $edit_form->id);
$mform->addElement('hidden', 'name', $edit_form->name);
$mform->addElement('hidden', 'code', $edit_form->code);
$mform->addElement('hidden', 'type', $edit_form->type);
$mform->addElement('hidden', 'hours', $edit_form->hours);
$mform->addElement('hidden', 'enabled', $edit_form->enabled);
$mform->addElement('hidden', 'op', $edit_form->op);
$mform->addElement('hidden', 'step', 2);

//use POST because Moodle does not like a selectbox that was filled by ajax
if($edit_form->op != 'delete')
{
if($_POST['subcategory'])
{
foreach($_POST['subcategory'] as $sc)
{
$mform->addElement('hidden', 'subcategory[]', $sc);
}
}
}

if($edit_form->op == 'edit')
{
$this->add_action_buttons(true,get_string('cpdactivityadmin_report_submit', 'report_fitandproper'));
}else
{
$this->add_action_buttons(true,get_string('cpdactivityadmin_report_submit_delete', 'report_fitandproper'));
}

}
}
Loading