<?php

/**
 * Provides some custom settings for the certificate module
 *
 * @package    mod
 * @subpackage simplecertificate
 * @copyright  Carlos Alexandre S. da Fonseca <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
    require_once "{$CFG->dirroot}/mod/simplecertificate/lib.php";
    //--- general settings -----------------------------------------------------------------------------------
    $settings->add(new admin_setting_configtext('simplecertificate/width', get_string('defaultwidth', 'simplecertificate'), get_string('size_help', 'simplecertificate'), 297, PARAM_INT));
    $settings->add(new admin_setting_configtext('simplecertificate/height', get_string('defaultheight', 'simplecertificate'), get_string('size_help', 'simplecertificate'), 210, PARAM_INT));
    $settings->add(new admin_setting_configtext('simplecertificate/certificatetextx', get_string('defaultcertificatetextx', 'simplecertificate'), get_string('textposition_help', 'simplecertificate'), 50, PARAM_INT));
    $settings->add(new admin_setting_configtext('simplecertificate/certificatetexty', get_string('defaultcertificatetexty', 'simplecertificate'), get_string('textposition_help', 'simplecertificate'), 50, PARAM_INT));
    $settings->add(new admin_setting_configselect('simplecertificate/certdate', get_string('printdate', 'simplecertificate'), get_string('printdate_help', 'simplecertificate'), -2, simplecertificate_get_date_options()));
    $settings->add(new admin_setting_configtext('simplecertificate/certlifetime', get_string('certlifetime', 'simplecertificate'), get_string('certlifetime_help', 'simplecertificate'), 60, PARAM_INT));
    //QR CODE
    $settings->add(new admin_setting_configcheckbox('simplecertificate/printqrcode', get_string('printqrcode', 'simplecertificate'), get_string('printqrcode_help', 'simplecertificate'), 1));
    $settings->add(new admin_setting_configtext('simplecertificate/codex', get_string('defaultcodex', 'simplecertificate'), get_string('qrcodeposition_help', 'simplecertificate'), 10, PARAM_INT));
    $settings->add(new admin_setting_configtext('simplecertificate/codey', get_string('defaultcodey', 'simplecertificate'), get_string('qrcodeposition_help', 'simplecertificate'), 10, PARAM_INT));
    $settings->add(new admin_setting_configcheckbox('simplecertificate/qrcodefirstpage', get_string('qrcodefirstpage', 'simplecertificate'), get_string('qrcodefirstpage_help', 'simplecertificate'), 0));
    //Certificate back page
    $settings->add(new admin_setting_configcheckbox('simplecertificate/enablesecondpage', get_string('enablesecondpage', 'simplecertificate'), get_string('enablesecondpage_help', 'simplecertificate'), 0));
    //Pagination
    $settings->add(new admin_setting_configtext('simplecertificate/perpage', get_string('defaultperpage', 'simplecertificate'), get_string('defaultperpage_help', 'simplecertificate'), 30, PARAM_INT));
}
 public function definition()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     //General options
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('certificatename', 'simplecertificate'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addHelpButton('name', 'certificatename', 'simplecertificate');
     $this->standard_intro_elements(get_string('intro', 'simplecertificate'));
     //--------------------------------------- Design Options----------------------------------------------------
     $mform->addElement('header', 'designoptions', get_string('designoptions', 'simplecertificate'));
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
     //Certificate image file
     $mform->addElement('filemanager', 'certificateimage', get_string('certificateimage', 'simplecertificate'), null, $this->get_filemanager_options_array());
     $mform->addHelpButton('certificateimage', 'certificateimage', 'simplecertificate');
     //Certificate Text HTML editor
     $mform->addElement('editor', 'certificatetext', get_string('certificatetext', 'simplecertificate'), simplecertificate_get_editor_options($this->context));
     $mform->setType('certificatetext', PARAM_RAW);
     $mform->addRule('certificatetext', get_string('error'), 'required', null, 'client');
     $mform->addHelpButton('certificatetext', 'certificatetext', 'simplecertificate');
     //Certificate Width
     $mform->addElement('text', 'width', get_string('width', 'simplecertificate'), array('size' => '5'));
     $mform->setType('width', PARAM_INT);
     $mform->setDefault('width', get_config('simplecertificate', 'width'));
     $mform->setAdvanced('width');
     $mform->addHelpButton('width', 'size', 'simplecertificate');
     //Certificate Height
     $mform->addElement('text', 'height', get_string('height', 'simplecertificate'), array('size' => '5'));
     $mform->setType('height', PARAM_INT);
     $mform->setDefault('height', get_config('simplecertificate', 'height'));
     $mform->setAdvanced('height');
     $mform->addHelpButton('height', 'size', 'simplecertificate');
     //Certificate Position X
     $mform->addElement('text', 'certificatetextx', get_string('certificatetextx', 'simplecertificate'), array('size' => '5'));
     $mform->setType('certificatetextx', PARAM_INT);
     $mform->setDefault('certificatetextx', get_config('simplecertificate', 'certificatetextx'));
     $mform->setAdvanced('certificatetextx');
     $mform->addHelpButton('certificatetextx', 'textposition', 'simplecertificate');
     //Certificate Position Y
     $mform->addElement('text', 'certificatetexty', get_string('certificatetexty', 'simplecertificate'), array('size' => '5'));
     $mform->setType('certificatetexty', PARAM_INT);
     $mform->setDefault('certificatetexty', get_config('simplecertificate', 'certificatetexty'));
     $mform->setAdvanced('certificatetexty');
     $mform->addHelpButton('certificatetexty', 'textposition', 'simplecertificate');
     //-----------------------------------------Second page
     $mform->addElement('header', 'secondpageoptions', get_string('secondpageoptions', 'simplecertificate'));
     //Enable back page text
     $mform->addElement('selectyesno', 'enablesecondpage', get_string('enablesecondpage', 'simplecertificate'));
     $mform->setDefault('enablesecondpage', get_config('simplecertificate', 'enablesecondpage'));
     $mform->addHelpButton('enablesecondpage', 'enablesecondpage', 'simplecertificate');
     //Certificate secondimage file
     $mform->addElement('filemanager', 'secondimage', get_string('secondimage', 'simplecertificate'), null, $this->get_filemanager_options_array());
     $mform->addHelpButton('secondimage', 'secondimage', 'simplecertificate');
     $mform->disabledIf('secondimage', 'enablesecondpage', 'eq', 0);
     //Certificate secondText HTML editor
     $mform->addElement('editor', 'secondpagetext', get_string('secondpagetext', 'simplecertificate'), simplecertificate_get_editor_options($this->context));
     $mform->setType('secondpagetext', PARAM_RAW);
     $mform->addHelpButton('secondpagetext', 'certificatetext', 'simplecertificate');
     $mform->disabledIf('secondpagetext', 'enablesecondpage', 'eq', 0);
     //Certificate Position X
     $mform->addElement('text', 'secondpagex', get_string('secondpagex', 'simplecertificate'), array('size' => '5'));
     $mform->setType('secondpagex', PARAM_INT);
     $mform->setDefault('secondpagex', get_config('simplecertificate', 'certificatetextx'));
     $mform->setAdvanced('secondpagex');
     $mform->addHelpButton('secondpagex', 'secondtextposition', 'simplecertificate');
     $mform->disabledIf('secondpagex', 'enablesecondpage', 'eq', 0);
     //Certificate Position Y
     $mform->addElement('text', 'secondpagey', get_string('secondpagey', 'simplecertificate'), array('size' => '5'));
     $mform->setType('secondpagey', PARAM_INT);
     $mform->setDefault('secondpagey', get_config('simplecertificate', 'certificatetexty'));
     $mform->setAdvanced('secondpagey');
     $mform->addHelpButton('secondpagey', 'secondtextposition', 'simplecertificate');
     $mform->disabledIf('secondpagey', 'enablesecondpage', 'eq', 0);
     //--------------------Variable options
     $mform->addElement('header', 'variablesoptions', get_string('variablesoptions', 'simplecertificate'));
     //Certificate Alternative Course Name
     $mform->addElement('text', 'coursename', get_string('coursename', 'simplecertificate'), array('size' => '64'));
     $mform->setType('coursename', PARAM_TEXT);
     $mform->setAdvanced('coursename');
     $mform->addHelpButton('coursename', 'coursename', 'simplecertificate');
     //Certificate Outcomes
     $outcomeoptions = simplecertificate_get_outcomes();
     $mform->addElement('select', 'outcome', get_string('printoutcome', 'simplecertificate'), $outcomeoptions);
     $mform->setDefault('outcome', 0);
     $mform->addHelpButton('outcome', 'printoutcome', 'simplecertificate');
     //Certificate date options
     $mform->addElement('select', 'certdate', get_string('printdate', 'simplecertificate'), simplecertificate_get_date_options());
     $mform->setDefault('certdate', get_config('simplecertificate', 'certdate'));
     $mform->addHelpButton('certdate', 'printdate', 'simplecertificate');
     //Certificate date format
     $mform->addElement('text', 'certdatefmt', get_string('datefmt', 'simplecertificate'));
     $mform->setDefault('certdatefmt', '');
     $mform->setType('certdatefmt', PARAM_TEXT);
     $mform->addHelpButton('certdatefmt', 'datefmt', 'simplecertificate');
     $mform->setAdvanced('certdatefmt');
     //Certificate timestart date format
     $mform->addElement('text', 'timestartdatefmt', get_string('timestartdatefmt', 'simplecertificate'));
     $mform->setDefault('timestartdatefmt', '');
     $mform->setType('timestartdatefmt', PARAM_TEXT);
     $mform->addHelpButton('timestartdatefmt', 'timestartdatefmt', 'simplecertificate');
     $mform->setAdvanced('timestartdatefmt');
     //Certificare grade Options
     $mform->addElement('select', 'certgrade', get_string('printgrade', 'simplecertificate'), simplecertificate_get_grade_options());
     $mform->setDefault('certgrade', 0);
     $mform->addHelpButton('certgrade', 'printgrade', 'simplecertificate');
     //Certificate grade format
     $gradeformatoptions = array(1 => get_string('gradepercent', 'simplecertificate'), 2 => get_string('gradepoints', 'simplecertificate'), 3 => get_string('gradeletter', 'simplecertificate'));
     $mform->addElement('select', 'gradefmt', get_string('gradefmt', 'simplecertificate'), $gradeformatoptions);
     $mform->setDefault('gradefmt', 0);
     $mform->addHelpButton('gradefmt', 'gradefmt', 'simplecertificate');
     //QR code
     $mform->addElement('selectyesno', 'printqrcode', get_string('printqrcode', 'simplecertificate'));
     $mform->setDefault('printqrcode', get_config('simplecertificate', 'printqrcode'));
     $mform->addHelpButton('printqrcode', 'printqrcode', 'simplecertificate');
     $mform->addElement('text', 'codex', get_string('codex', 'simplecertificate'), array('size' => '5'));
     $mform->setType('codex', PARAM_INT);
     $mform->setDefault('codex', get_config('simplecertificate', 'codex'));
     $mform->setAdvanced('codex');
     $mform->addHelpButton('codex', 'qrcodeposition', 'simplecertificate');
     $mform->addElement('text', 'codey', get_string('codey', 'simplecertificate'), array('size' => '5'));
     $mform->setType('codey', PARAM_INT);
     $mform->setDefault('codey', get_config('simplecertificate', 'codey'));
     $mform->setAdvanced('codey');
     $mform->addHelpButton('codey', 'qrcodeposition', 'simplecertificate');
     $mform->addElement('selectyesno', 'qrcodefirstpage', get_string('qrcodefirstpage', 'simplecertificate'));
     $mform->setDefault('qrcodefirstpage', get_config('simplecertificate', 'qrcodefirstpage'));
     $mform->addHelpButton('qrcodefirstpage', 'qrcodefirstpage', 'simplecertificate');
     //-------------------------------Issue options----------------------------------
     $mform->addElement('header', 'issueoptions', get_string('issueoptions', 'simplecertificate'));
     //Email to teachers ?
     $mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'simplecertificate'));
     $mform->setDefault('emailteachers', 0);
     $mform->addHelpButton('emailteachers', 'emailteachers', 'simplecertificate');
     //Email Others
     $mform->addElement('text', 'emailothers', get_string('emailothers', 'simplecertificate'), array('size' => '40', 'maxsize' => '200'));
     $mform->setType('emailothers', PARAM_TEXT);
     $mform->addHelpButton('emailothers', 'emailothers', 'simplecertificate');
     //Email From
     $mform->addElement('text', 'emailfrom', get_string('emailfrom', 'simplecertificate'), array('size' => '40', 'maxsize' => '200'));
     $mform->setDefault('emailfrom', $CFG->supportname);
     $mform->setType('emailfrom', PARAM_EMAIL);
     $mform->addHelpButton('emailfrom', 'emailfrom', 'simplecertificate');
     $mform->setAdvanced('emailfrom');
     //Delivery Options (Email, Download,...)
     $deliveryoptions = array(0 => get_string('openbrowser', 'simplecertificate'), 1 => get_string('download', 'simplecertificate'), 2 => get_string('emailcertificate', 'simplecertificate'), 3 => get_string('nodelivering', 'simplecertificate'));
     $mform->addElement('select', 'delivery', get_string('delivery', 'simplecertificate'), $deliveryoptions);
     $mform->setDefault('delivery', 0);
     $mform->addHelpButton('delivery', 'delivery', 'simplecertificate');
     //Report Cert
     //TODO acredito que seja para verificar o certificado pelo código, se for isto pode remover.
     $reportfile = "{$CFG->dirroot}/simplecertificates/index.php";
     if (file_exists($reportfile)) {
         $mform->addElement('selectyesno', 'reportcert', get_string('reportcert', 'simplecertificate'));
         $mform->setDefault('reportcert', 0);
         $mform->addHelpButton('reportcert', 'reportcert', 'simplecertificate');
     }
     $this->standard_coursemodule_elements();
     $this->add_action_buttons();
 }