/**
  * Form tweaks that depend on current data.
  */
 public function definition_after_data()
 {
     global $USER, $SESSION;
     $mform =& $this->_form;
     $columns =& $this->_customdata;
     foreach ($columns as $column) {
         if ($mform->elementExists($column)) {
             $mform->removeElement($column);
         }
     }
     // Set the companyid to bypass the company select form if possible.
     if (!empty($SESSION->currenteditingcompany)) {
         $companyid = $SESSION->currenteditingcompany;
     } else {
         $companyid = company_user::companyid();
     }
     // Get the department list.
     $parentlevel = company::get_company_parentnode($companyid);
     if (iomad::has_capability('block/iomad_company_admin:edit_all_departments', context_system::instance())) {
         $userhierarchylevel = $parentlevel->id;
     } else {
         $userlevel = company::get_userlevel($USER);
         $userhierarchylevel = $userlevel->id;
     }
     $this->departmentid = $userhierarchylevel;
     $subhierarchieslist = company::get_all_subdepartments($userhierarchylevel);
     //  Department drop down.
     $mform->insertElementBefore($mform->createElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $subhierarchieslist, $userhierarchylevel), 'uutypelabel');
     $this->courseselector = $this->add_course_selector();
     $this->add_action_buttons(true, get_string('uploadusers', 'tool_uploaduser'));
 }
Example #2
0
function theme_gourmet_get_html_for_settings(renderer_base $output, moodle_page $page)
{
    global $CFG, $USER, $DB;
    $return = new stdClass();
    $return->navbarclass = '';
    if (!empty($page->theme->settings->invert)) {
        $return->navbarclass .= ' navbar-inverse';
    }
    // get logos
    $theme = $page->theme;
    $logo = $theme->setting_file_url('logo', 'logo');
    if (empty($logo)) {
        $logo = $CFG->wwwroot . '/theme/gourmet/pix/gourmet_logo.png';
    }
    $clientlogo = '';
    $companycss = '';
    if ($companyid = iomad::is_company_user()) {
        $context = context_system::instance();
        if ($files = $DB->get_records('files', array('contextid' => $context->id, 'component' => 'theme_gourmet', 'filearea' => 'companylogo', 'itemid' => $companyid))) {
            // print_object($files);
            foreach ($files as $file) {
                if ($file->filename != '.') {
                    $clientlogo = $CFG->wwwroot . "/pluginfile.php/{$context->id}/theme_gourmet/companylogo/{$companyid}/{$file->filename}";
                }
            }
        }
        company_user::load_company();
        $companycss = ".header, .navbar { background: [[company:bgcolor_header]]; }\n                       .block .content { background: [[company:bgcolor_content]]; }";
        foreach ($USER->company as $key => $value) {
            if (isset($value)) {
                $companycss = preg_replace("/\\[\\[company:{$key}\\]\\]/", $value, $companycss);
            }
        }
    }
    /*
        $return->heading = '<div id="sitelogo">' . 
            '<a href="' . $CFG->wwwroot . '" ><img src="' . $logo . '" /></a></div>';
        $return->heading .= '<div id="siteheading">' . $output->page_heading() . '</div>';
    */
    if ($clientlogo) {
        $return->heading .= '<div id="clientlogo">' . '<a href="' . $CFG->wwwroot . '" ><img src="' . $clientlogo . '" /></a></div>';
    }
    $return->footnote = '';
    if (!empty($page->theme->settings->footnote)) {
        $return->footnote = '<div class="footnote text-center">' . $page->theme->settings->footnote . '</div>';
    }
    $return->companycss = $companycss;
    return $return;
}
 function onordercomplete($invoiceitem, $invoice)
 {
     global $DB;
     $transaction = $DB->start_delegated_transaction();
     if ($DB->get_record('iomad_courses', array('courseid' => $invoiceitem->invoiceableitemid, 'licensed' => 1))) {
         // Get the item's single purchase details.
         $courseinfo = $DB->get_record('course_shopsettings', array('courseid' => $invoiceitem->invoiceableitemid));
         // Get name for company license.
         $company = company::get_company_byuserid($invoice->userid);
         $course = $DB->get_record('course', array('id' => $invoiceitem->invoiceableitemid), 'id, shortname', MUST_EXIST);
         $licensename = $company->shortname . " [" . $course->shortname . "] " . date("Y-m-d");
         $count = $DB->count_records_sql("SELECT COUNT(*) FROM {companylicense} WHERE name LIKE '" . str_replace("'", "\\'", $licensename) . "%'");
         if ($count) {
             $licensename .= ' (' . ($count + 1) . ')';
         }
         // Create mdl_companylicense record.
         $companylicense = new stdClass();
         $companylicense->name = $licensename;
         $companylicense->allocation = 1;
         $companylicense->used = 1;
         $companylicense->validlength = $courseinfo->single_purchase_validlength;
         if (!empty($courseinfo->single_purchase_shelflife)) {
             $companylicense->expirydate = $courseinfo->single_purchase_shelflife * 86400 + time();
             // 86400 = 24*60*60 = number of seconds in a day.
         } else {
             $companylicense->expirydate = 0;
         }
         $companylicense->companyid = $company->id;
         $companylicenseid = $DB->insert_record('companylicense', $companylicense);
         // Create mdl_companylicense_courses record for the course.
         $clc = new stdClass();
         $clc->licenseid = $companylicenseid;
         $clc->courseid = $course->id;
         $DB->insert_record('companylicense_courses', $clc);
         //  Assign the license to the user.
         $DB->insert_record('companylicense_users', array('userid' => $invoice->userid, 'licenseid' => $companylicenseid));
     } else {
         // Enrol user into course.
         $user = new stdClass();
         $user->id = $invoice->userid;
         company_user::enrol($user, array($invoiceitem->invoiceableitemid));
     }
     // Mark the invoice item as processed.
     $invoiceitem->processed = 1;
     $DB->update_record('invoiceitem', $invoiceitem);
     $transaction->allow_commit();
 }
Example #4
0
 public function definition()
 {
     global $USER, $SESSION, $DB;
     $mform =& $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('trainingeventname', 'trainingevent'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->add_intro_editor(true, get_string('trainingeventintro', 'trainingevent'));
     $mform->addElement('date_time_selector', 'startdatetime', get_string('startdatetime', 'trainingevent'));
     $mform->addRule('startdatetime', get_string('missingstartdatetime', 'trainingevent'), 'required', null, 'client');
     $mform->addElement('date_time_selector', 'enddatetime', get_string('enddatetime', 'trainingevent'));
     $mform->addRule('enddatetime', get_string('missingenddatetime', 'trainingevent'), 'required', null, 'client');
     // Set the companyid to bypass the company select form if possible.
     $params = array();
     if (!empty($SESSION->currenteditingcompany)) {
         $params['companyid'] = $SESSION->currenteditingcompany;
     } else {
         if (!empty($USER->company)) {
             $params['companyid'] = company_user::companyid();
         }
     }
     $choices = array();
     if ($rooms = $DB->get_recordset('classroom', $params, 'name', '*')) {
         foreach ($rooms as $room) {
             $choices[$room->id] = $room->name;
         }
         $rooms->close();
     }
     $choices = array('' => get_string('selectaroom', 'trainingevent') . '...') + $choices;
     $mform->addElement('select', 'classroomid', get_string('selectaroom', 'trainingevent'), $choices);
     $mform->addRule('classroomid', get_string('required'), 'required', null, 'client');
     $choices = array(get_string('none', 'trainingevent'), get_string('manager', 'trainingevent'), get_string('companymanager', 'trainingevent'), get_string('both', 'trainingevent'), get_string('enrolonly', 'trainingevent'));
     $mform->addElement('select', 'approvaltype', get_string('approvaltype', 'trainingevent'), $choices);
     $this->standard_grading_coursemodule_elements();
     $this->standard_coursemodule_elements();
     // Add the buttons.
     $this->add_action_buttons(true, false, null);
 }
Example #5
0
function xmldb_local_iomad_upgrade($oldversion)
{
    global $CFG, $DB;
    $result = true;
    $dbman = $DB->get_manager();
    if ($oldversion < 2011090600) {
        // Define table department to be created.
        $table = new xmldb_table('department');
        // Adding fields to table department.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('shortname', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
        $table->add_field('company', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('parent', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null);
        // Adding keys to table department.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for department.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table department_users to be created.
        $table = new xmldb_table('department_users');
        // Adding fields to table department_users.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('departmentid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table department_users.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for department_users.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table department_courses to be created.
        $table = new xmldb_table('department_courses');
        // Adding fields to table department_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('departmentid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table department_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for department_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011090600, 'local', 'iomad');
    }
    // Licensing added.
    if ($oldversion < 2011091500) {
        // Define table companylicense to be created.
        $table = new xmldb_table('companylicense');
        // Adding fields to table companylicense.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('allocation', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('validlength', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('expirydate', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('used', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null);
        // Adding keys to table companylicense.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for companylicense.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table companylicense_users to be created.
        $table = new xmldb_table('companylicense_users');
        // Adding fields to table companylicense_users.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('licenseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table companylicense_users.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for companylicense_users.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table companylicense_courses to be created.
        $table = new xmldb_table('companylicense_courses');
        // Adding fields to table companylicense_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('licenseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table companylicense_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for companylicense_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011091500, 'local', 'iomad');
    }
    if ($oldversion < 2011092300) {
        // Define field id to be added to companylicense_users.
        $table = new xmldb_table('companylicense_users');
        $field = new xmldb_field('isusing', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid');
        // Conditionally launch add field id.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011092300, 'local', 'iomad');
    }
    if ($oldversion < 2011092600) {
        // Define field timecompleted to be added to companylicense_users.
        $table = new xmldb_table('companylicense_users');
        $field = new xmldb_field('timecompleted', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'isusing');
        // Conditionally launch add field timecompleted.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field score to be added to companylicense_users.
        $table = new xmldb_table('companylicense_users');
        $field = new xmldb_field('score', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'timecompleted');
        // Conditionally launch add field score.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field result to be added to companylicense_users.
        $table = new xmldb_table('companylicense_users');
        $field = new xmldb_field('result', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'score');
        // Conditionally launch add field result.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011092600, 'local', 'iomad');
    }
    if ($oldversion < 2011103000) {
        // Define table company_course_groups to be created.
        $table = new xmldb_table('company_course_groups');
        // Adding fields to table company_course_groups.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('groupid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table company_course_groups.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for company_course_groups.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table iomad_courses to be created.
        $table = new xmldb_table('iomad_courses');
        // Adding fields to table iomad_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('licensed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('shared', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        // Adding keys to table iomad_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for iomad_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011103000, 'local', 'iomad');
    }
    if ($oldversion < 2011111000) {
        // Define table iomad_courses to be created.
        $table = new xmldb_table('iomad_courses');
        // Adding fields to table iomad_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('licensed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0');
        $table->add_field('shared', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0');
        // Adding keys to table iomad_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for iomad_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011111000, 'local', 'iomad');
    }
    if ($oldversion < 2011111401) {
        // Define table classroom to be created.
        $table = new xmldb_table('classroom');
        // Adding fields to table classroom.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
        $table->add_field('address', XMLDB_TYPE_CHAR, '70', null, null, null, null);
        $table->add_field('city', XMLDB_TYPE_CHAR, '120', null, null, null, null);
        $table->add_field('country', XMLDB_TYPE_CHAR, '2', null, null, null, null);
        $table->add_field('postcode', XMLDB_TYPE_CHAR, '20', null, null, null, null);
        $table->add_field('capacity', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table classroom.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for classroom.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint(true, 2011111401, 'local', 'iomad');
    }
    if ($oldversion < 2011111800) {
        // Define field validlength to be added to iomad_courses.
        $table = new xmldb_table('iomad_courses');
        $field = new xmldb_field('validlength', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'shared');
        // Conditionally launch add field validlength.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011111800, 'local', 'iomad');
    }
    if ($oldversion < 2011111801) {
        // Define field warnexpire to be added to iomad_courses.
        $table = new xmldb_table('iomad_courses');
        $field = new xmldb_field('warnexpire', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'validlength');
        // Conditionally launch add field warnexpire.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field warncompletion to be added to iomad_courses.
        $table = new xmldb_table('iomad_courses');
        $field = new xmldb_field('warncompletion', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'warnexpire');
        // Conditionally launch add field warncompletion.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011111801, 'local', 'iomad');
    }
    if ($oldversion < 2011112000) {
        // Define field category to be added to company.
        $table = new xmldb_table('company');
        $field = new xmldb_field('category', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'theme');
        // Conditionally launch add field category.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2011112000, 'local', 'iomad');
    }
    if ($oldversion < 2012012500) {
        // Define table company_course_groups to be created.
        // ADDED AGAIN DUE TO git branching timelines.
        $table = new xmldb_table('company_course_groups');
        // Adding fields to table company_course_groups.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('groupid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table company_course_groups.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for company_course_groups.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table company_shared_courses to be created.
        $table = new xmldb_table('company_shared_courses');
        // Adding fields to table company_shared_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table company_shared_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for company_shared_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2012012500, 'local', 'iomad');
    }
    if ($oldversion < 2012051500) {
        // Change the role permissions for company and create the department manager role.
        $systemcontext = context_system::instance();
        // Create the Company Manager role.
        if (!($companymanager = $DB->get_record('role', array('shortname' => 'companymanager')))) {
            $companymanagerid = create_role('Company Manager', 'companymanager', '(Iomad) Manages individual companies - can upload users etc.');
        } else {
            $companymanagerid = $companymanager->id;
        }
        // If not done already, allow assignment at system context.
        $levels = get_role_contextlevels($companymanagerid);
        if (empty($levels)) {
            $level = null;
            $level->roleid = $companymanagerid;
            $level->contextlevel = CONTEXT_SYSTEM;
            $DB->insert_record('role_context_levels', $level);
        }
        // Create new Company Department Manager role.
        if (!($companydepartmentmanager = $DB->get_record('role', array('shortname' => 'companydepartmentmanager')))) {
            $companydepartmentmanagerid = create_role('Company Department Manager', 'companydepartmentmanager', '(Iomad) Manages departments within companies - can upload users etc.');
        } else {
            $companydepartmentmanagerid = $companydepartmentmanager->id;
        }
        // If not done already, allow assignment at system context.
        $levels = get_role_contextlevels($companydepartmentmanagerid);
        if (empty($levels)) {
            $level = null;
            $level->roleid = $companydepartmentmanagerid;
            $level->contextlevel = CONTEXT_SYSTEM;
            $DB->insert_record('role_context_levels', $level);
        }
        $companydepartmentmanagercaps = array('block/iomad_reports:view', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:allocate_licenses', 'local/iomad_dashboard:view');
        if ($DB->get_records('role_capabilities', array('roleid' => $companydepartmentmanagerid))) {
            $DB->delete_records('role_capabilities', array('roleid' => $companydepartmentmanagerid));
        }
        foreach ($companydepartmentmanagercaps as $cap) {
            assign_capability($cap, CAP_ALLOW, $companydepartmentmanagerid, $systemcontext->id);
        }
        $companymanagercaps = array('block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:allocate_licenses', 'block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:classrooms', 'block/iomad_company_admin:classrooms_delete', 'block/iomad_company_admin:classrooms_edit', 'block/iomad_company_admin:company_edit', 'block/iomad_company_admin:company_course_unenrol', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:company_user_profiles', 'block/iomad_company_admin:createcourse', 'local/iomad_dashboard:view');
        if ($DB->get_records('role_capabilities', array('roleid' => $companymanagerid))) {
            $DB->delete_records('role_capabilities', array('roleid' => $companymanagerid));
        }
        foreach ($companymanagercaps as $cap) {
            assign_capability($cap, CAP_ALLOW, $companymanagerid, $systemcontext->id);
        }
        //  Deal with the database.
        // Define field id to be added to companymanager.
        $table = new xmldb_table('companymanager');
        $field = new xmldb_field('departmentmanager', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid');
        // Conditionally launch add field departmentmanager.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Conditionally launch add field id.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $DB->set_field('companymanager', 'departmentmanager', 0);
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2012051500, 'local', 'iomad');
    }
    if ($oldversion < 2012052200) {
        // Define table company_created_courses to be created.
        $table = new xmldb_table('company_created_courses');
        // Adding fields to table company_created_courses.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        // Adding keys to table company_created_courses.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for company_created_courses.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Change the role permissions for company and create the department manager role..
        $systemcontext = context_system::instance();
        // Create the Company Course Editor.
        if (!($companycourseeditor = $DB->get_record('role', array('shortname' => 'companycourseeditor')))) {
            $companycourseeditorid = create_role('Company Course Editor', 'companycourseeditor', '(Iomad) Teacher style role for Company manager provided to them when they create their own course.');
        } else {
            $companycourseeditorid = $companycourseeditor->id;
        }
        // If not done already, allow assignment at system context.
        $levels = get_role_contextlevels($companycourseeditorid);
        if (empty($levels)) {
            $level = null;
            $level->roleid = $companycourseeditorid;
            $level->contextlevel = CONTEXT_COURSE;
            $DB->insert_record('role_context_levels', $level);
        }
        // Create new Company Course Non Editor role.
        if (!($companycoursenoneditor = $DB->get_record('role', array('shortname' => 'companycoursenoneditor')))) {
            $companycoursenoneditorid = create_role('Company Course Non Editor', 'companycoursenoneditor', '(Iomad) Non editing teacher style role form Company and department managers');
        } else {
            $companycoursenoneditorid = $companycoursenoneditor->id;
        }
        // If not done already, allow assignment at system context.
        $levels = get_role_contextlevels($companycoursenoneditorid);
        if (empty($levels)) {
            $level = null;
            $level->roleid = $companycoursenoneditorid;
            $level->contextlevel = CONTEXT_COURSE;
            $DB->insert_record('role_context_levels', $level);
        }
        if ($DB->get_records('role_capabilities', array('roleid' => $companycourseeditorid))) {
            $DB->delete_records('role_capabilities', array('roleid' => $companycourseeditorid));
        }
        $companycourseeditorcaps = array('block/side_bar_block:editblock', 'block/side_bar_block:viewblock', 'booktool/importhtml:import', 'booktool/print:print', 'enrol/authorize:manage', 'enrol/license:manage', 'enrol/license:unenrol', 'enrol/manual:enrol', 'enrol/manual:unenrol', 'gradereport/grader:view', 'gradereport/overview:view', 'gradereport/user:view', 'mod/assignment:exportownsubmission', 'mod/assignment:grade', 'mod/assignment:view', 'mod/book:edit', 'mod/book:read', 'mod/book:viewhiddenchapters', 'mod/certificate:manage', 'mod/certificate:view', 'mod/choice:choose', 'mod/choice:deleteresponses', 'mod/choice:downloadresponses', 'mod/choice:readresponses', 'mod/courseclassroom:grade', 'mod/courseclassroom:invite', 'mod/courseclassroom:viewattendees', 'mod/forum:addnews', 'mod/forum:addquestion', 'mod/forum:createattachment', 'mod/forum:deleteanypost', 'mod/forum:deleteownpost', 'mod/forum:editanypost', 'mod/forum:exportdiscussion', 'mod/forum:exportownpost', 'mod/forum:exportpost', 'mod/forum:managesubscriptions', 'mod/forum:movediscussions', 'mod/forum:postwithoutthrottling', 'mod/forum:rate', 'mod/forum:replynews', 'mod/forum:replypost', 'mod/forum:splitdiscussions', 'mod/forum:startdiscussion', 'mod/forum:viewallratings', 'mod/forum:viewanyrating', 'mod/forum:viewdiscussion', 'mod/forum:viewhiddentimedposts', 'mod/forum:viewqandawithoutposting', 'mod/forum:viewrating', 'mod/forum:viewsubscribers', 'mod/page:view', 'mod/resource:view', 'mod/scorm:deleteresponses', 'mod/scorm:savetrack', 'mod/scorm:viewreport', 'mod/scorm:viewscores', 'mod/url:view', 'moodle/block:edit', 'moodle/block:view', 'moodle/calendar:manageentries', 'moodle/calendar:managegroupentries', 'moodle/calendar:manageownentries', 'moodle/course:activityvisibility', 'moodle/course:changefullname', 'moodle/course:changesummary', 'moodle/course:manageactivities', 'moodle/course:managefiles', 'moodle/course:managegroups', 'moodle/course:markcomplete', 'moodle/course:reset', 'moodle/course:sectionvisibility', 'moodle/course:setcurrentsection', 'moodle/course:update', 'moodle/course:viewhiddenactivities', 'moodle/course:viewhiddensections', 'moodle/course:viewparticipants', 'moodle/grade:edit', 'moodle/grade:hide', 'moodle/grade:lock', 'moodle/grade:manage', 'moodle/grade:managegradingforms', 'moodle/grade:manageletters', 'moodle/grade:manageoutcomes', 'moodle/grade:unlock', 'moodle/grade:viewall', 'moodle/grade:viewhidden', 'moodle/notes:manage', 'moodle/notes:view', 'moodle/rating:rate', 'moodle/rating:view', 'moodle/rating:viewall', 'moodle/rating:viewany', 'moodle/role:switchroles', 'moodle/site:accessallgroups', 'moodle/site:manageblocks', 'moodle/site:trustcontent', 'moodle/site:viewfullnames', 'moodle/site:viewreports', 'moodle/site:viewuseridentity', 'moodle/user:viewdetails', 'report/courseoverview:view', 'report/log:view', 'report/log:viewtoday', 'report/loglive:view', 'report/outline:view', 'report/participation:view', 'report/progress:view');
        foreach ($companycourseeditorcaps as $rolecapability) {
            // Assign_capability will update rather than insert if capability exists.
            assign_capability($rolecapability, CAP_ALLOW, $companycourseeditorid, $systemcontext->id);
        }
        if ($DB->get_records('role_capabilities', array('roleid' => $companycoursenoneditorid))) {
            $DB->delete_records('role_capabilities', array('roleid' => $companycoursenoneditorid));
        }
        $companycoursenoneditorcaps = array('block/side_bar_block:viewblock', 'gradereport/grader:view', 'gradereport/user:view', 'mod/assignment:view', 'mod/book:read', 'mod/certificate:manage', 'mod/certificate:view', 'mod/choice:readresponses', 'mod/feedback:view', 'mod/forum:addquestion', 'mod/forum:createattachment', 'mod/forum:deleteownpost', 'mod/forum:replypost', 'mod/forum:startdiscussion', 'mod/forum:viewdiscussion', 'mod/forum:viewqandawithoutposting', 'mod/page:view', 'mod/quiz:attempt', 'mod/quiz:view', 'mod/resource:view', 'mod/survey:participate', 'moodle/block:view', 'moodle/grade:viewall', 'moodle/site:viewfullnames', 'moodle/site:viewuseridentity');
        foreach ($companycoursenoneditorcaps as $rolecapability) {
            // Assign_capability will update rather than insert if capability exists.
            assign_capability($rolecapability, CAP_ALLOW, $companycoursenoneditorid, $systemcontext->id);
        }
        // Deal with role assignments.
        // Get the list of company courses.
        $companycourses = $DB->get_records('companycourse');
        // Get the managers.
        foreach ($companycourses as $companycourse) {
            $companymanagers = $DB->get_records('companymanager', array('companyid' => $companycourse->companyid));
            if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                if ($DB->record_exists('scorm', array('course' => $companycourse->courseid))) {
                    // This is a scorm course so only noneditor role to be applied.
                    foreach ($companymanagers as $companymanager) {
                        if ($user = $DB->get_record('user', array('id' => $companymanager->userid, 'deleted' => 0))) {
                            company_user::enrol($user, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorid);
                        }
                    }
                } else {
                    // Add it to the company created courses.
                    $DB->insert_record('company_created_courses', array('companyid' => $companycourse->companyid, 'courseid' => $companycourse->courseid));
                    // Set up the manager roles.
                    foreach ($companymanagers as $companymanager) {
                        if ($user = $DB->get_record('user', array('id' => $companymanager->userid, 'deleted' => 0))) {
                            if ($companymanager->departmentmanager) {
                                // Lowly department manager, no more than that.
                                company_user::enrol($user, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorid);
                            } else {
                                company_user::enrol($user, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorid);
                            }
                        }
                    }
                }
            }
        }
        // Restrict the default modules.
        $allowedmodules = '1,3,5,7,10,12,14,15,17,20,21,22';
        set_config('restrictbydefault', 1);
        set_config('restrictmodulesfor', 'all');
        set_config('defaultallowedmodules', $allowedmodules);
        // Restrict the modules for every course.
        $sitecourses = $DB->get_records_select('course', "id != " . SITEID);
        foreach ($sitecourses as $sitecourse) {
            foreach (explode(',', $allowedmodules) as $module) {
                $DB->insert_record('course_allowed_modules', array('course' => $sitecourse->id, 'module' => $module));
                $DB->set_field('course', 'restrictmodules', '1', array('id' => $sitecourse->id));
            }
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2012052200, 'local', 'iomad');
    }
    if ($oldversion < 2013050100) {
        // Define table companyusers to be created.
        $table = new xmldb_table('companyusers');
        // Adding fields to table companyusers.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('usserid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        // Adding keys to table companyusers.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for companyusers.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Need to deal with current company allocations.
        /*if ($companyfield = $DB->get_record('user_info_field', array('shortname' => 'company'))) {
            if ($companyusers = $DB->get_records('user_info_data', array('fieldid' => $companyfield->id))) {
                foreach($companyusers as $companyuser) {
          */
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2013050100, 'local', 'iomad');
    }
    if ($oldversion < 2014012400) {
        $systemcontext = context_system::instance();
        // Get the Company Manager role.
        if ($companymanager = $DB->get_record('role', array('shortname' => 'companymanager'))) {
            $companymanagerid = $companymanager->id;
            $companymanagercaps = array('local/iomad_dashboard:view', 'block/iomad_reports:view', 'local_report_attendance:view', 'local_report_completion:view', 'local_report_users:view', 'local_report_scorm_overview:view');
            foreach ($companymanagercaps as $cap) {
                assign_capability($cap, CAP_ALLOW, $companymanagerid, $systemcontext->id);
            }
        }
        // Get the Company Department Manager role.
        if ($companydepartmentmanager = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'))) {
            $companydepartmentmanagerid = $companydepartmentmanager->id;
            $companydepartmentmanagercaps = array('local/iomad_dashboard:view', 'block/iomad_reports:view', 'local_report_attendance:view', 'local_report_completion:view', 'local_report_users:view', 'local_report_scorm_overview:view');
            foreach ($companydepartmentmanagercaps as $cap) {
                assign_capability($cap, CAP_ALLOW, $companydepartmentmanagerid, $systemcontext->id);
            }
        }
        // Get the Client Administrator role.
        if ($clientadministrator = $DB->get_record('role', array('shortname' => 'clientadministrator'))) {
            $clientadministratorid = $clientadministrator->id;
            $clientadministratorcaps = array('local/iomad_dashboard:view', 'block/iomad_reports:view', 'local_report_attendance:view', 'local_report_completion:view', 'local_report_users:view', 'local_report_scorm_overview:view');
            foreach ($clientadministratorcaps as $cap) {
                assign_capability($cap, CAP_ALLOW, $clientadministratorid, $systemcontext->id);
            }
        }
    }
    if ($oldversion < 2014022600) {
        // Change the site to force user allowed themes.
        set_config('allowuserthemes', 1);
    }
    if ($oldversion < 2014052700) {
        // Define field suspended to be added to company_users.
        $table = new xmldb_table('company_users');
        $field = new xmldb_field('suspended', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'departmentid');
        // Conditionally launch add field suspended.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field suspended to be added to company.
        $table = new xmldb_table('company');
        $field = new xmldb_field('suspended', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'profileid');
        // Conditionally launch add field suspended.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2014052700, 'local', 'iomad');
    }
    if ($oldversion < 2014052702) {
        // Define new table company_role_restriction
        $table = new xmldb_table('company_role_restriction');
        // Adding fields to table department.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('roleid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        // Adding keys to table department.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('company_roleidcompanyid', XMLDB_KEY_UNIQUE, array('roleid', 'companyid', 'capability'));
        // Conditionally launch create table for company_role_restriction.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
    }
    if ($oldversion < 2014120400) {
        // Define field licensecourseid to be added to companylicense_users.
        $table = new xmldb_table('companylicense_users');
        $field = new xmldb_field('licensecourseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'userid');
        // Conditionally launch add field licensecourseid.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2014120400, 'local', 'iomad');
    }
    if ($oldversion < 2014121900) {
        // Deal with licenseses which have already been allocated.
        $licenseusers = $DB->get_records('companylicense_users', array('licensecourseid' => 0));
        foreach ($licenseusers as $licenseuser) {
            if ($licenseuser->timecompleted != null) {
                continue;
            }
            // Are they using the license?
            if ($licenseuser->isusing == 1) {
                // Get the course.
                $enrolrecords = $DB->get_records_sql("SELECT e.courseid,ue.userid\n                                                    FROM {enrol} e JOIN {user_enrolments} ue\n                                                    ON e.id=ue.enrolid\n                                                    WHERE userid = :userid\n                                                    AND courseid IN\n                                                     (SELECT courseid FROM {companylicense_courses}\n                                                      WHERE licenseid = :licenseid)", array('userid' => $licenseuser->userid, 'licenseid' => $licenseuser->licenseid));
                // Do we have more than one record?
                if (count($enrolrecords > 1)) {
                    foreach ($enrolrecords as $enrolrecord) {
                        // Check if we already have a record for this course.
                        if ($DB->get_record('companylicense_users', array('userid' => $licenseuser->userid, 'licenseid' => $licenseuser->licenseid, 'licensecourseid' => $enrolrecord->courseid))) {
                            continue;
                        } else {
                            $licenseuser->licensecourseid = $enrolrecord->courseid;
                            $DB->update_record('companylicense_users', $licenseuser);
                        }
                    }
                } else {
                    list($enrolcourseid, $enroluserid) = each($enrolrecords);
                    $licenseuser->licensecourseid = $enrolcourseid;
                    $DB->update_record('companylicense_users', $licenseuser);
                }
            } else {
                // Get the courses.
                $licensecourses = $DB->get_records('companylicense_courses', array('licenseid' => $licenseuser->licenseid));
                if (count($licensecourses) == 1) {
                    // Only one course so add it.
                    $licensecourse = array_pop($licensecourses);
                    $licenseuser->licensecourseid = $licensecourse->id;
                    $DB->update_record('companylicense_users', $licenseuser);
                } else {
                    //  Dont know which course to assign so we are going to remove the record as its not being used.
                    $DB->delete_records('companylicense_users', array('id' => $licenseuser->id));
                }
            }
        }
        //  Update the used counts for each license.
        $licenses = $DB->get_records('companylicense');
        foreach ($licenses as $license) {
            $licensecount = $DB->count_records('companylicense_users', array('licenseid' => $license->id));
            $license->used = $licensecount;
            $DB->update_record('companylicense', $license);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2014121900, 'local', 'iomad');
    }
    if ($oldversion < 2015020800) {
        // Define table company_domains to be created.
        $table = new xmldb_table('company_domains');
        // Adding fields to table company_domains.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('companyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('domain', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
        // Adding keys to table company_domains.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for company_domains.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Iomad savepoint reached.
        upgrade_plugin_savepoint(true, 2015020800, 'local', 'iomad');
    }
    return $result;
}
Example #6
0
 public function definition()
 {
     global $PAGE, $USER;
     if (!company_user::is_company_user()) {
         $mform =& $this->_form;
         // Then show the fields about where this block appears.
         $mform->addElement('header', 'header', get_string('company', 'block_iomad_company_admin'));
         if ($this->add_company_selector()) {
             // Only display buttons if user doesnt use javascript.
             if ($USER->ajax != 1) {
                 $this->add_action_buttons(true, $this->submitlabel);
             }
             // Make form auto submit on change of selected company.
             $formid = $mform->getAttribute("id");
             $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array($formid, "id_companyid", null));
         }
     }
 }
 public function cron()
 {
     global $DB;
     if ($DB->count_records('user_preferences', array('name' => 'iomad_send_password', 'value' => '1'))) {
         mtrace('creating passwords for new users');
         $newusers = $DB->get_records_sql("SELECT u.id as id, u.email, u.firstname,\n                                                     u.lastname, u.username,\n                                                     p.id as prefid,\n                                                     p.value as prefvalue\n                                                FROM {user} u\n                                                JOIN {user_preferences} p ON u.id=p.userid\n                                                JOIN {user_preferences} p2 ON u.id=p2.userid\n                                               WHERE p.name='iomad_temporary'\n                                                 AND u.email !=''\n                                                 AND p2.name='iomad_send_password'\n                                                 AND p2.value='1' ");
         mtrace('sending passwords to ' . count($newusers) . ' new users');
         foreach ($newusers as $newuserid => $newuser) {
             // Email user.
             if ($this->mail_password($newuser, company_user::rc4decrypt($newuser->prefvalue))) {
                 // Remove user pref.
                 unset_user_preference('iomad_send_password', $newuser);
             } else {
                 trigger_error("Could not mail new user password!");
             }
         }
     }
 }
Example #8
0
 public static function get_completion($companyid, $courseid = 0, $wantedusers = null, $compfrom = 0, $compto = 0)
 {
     global $DB, $CFG;
     // Get list of course ids.
     $courseids = array();
     if ($courseid == 0) {
         if (!($courses = $DB->get_records_sql("SELECT c.id AS courseid FROM {course} c\n                                                  WHERE c.id in (\n                                                    SELECT courseid FROM {companycourse}\n                                                    WHERE companyid = {$companyid} )\n                                                  OR c.id in (\n                                                    SELECT pc.courseid FROM {iomad_courses} pc\n                                                    INNER JOIN {company_shared_courses} csc\n                                                    ON pc.courseid=csc.courseid\n                                                    WHERE pc.shared=2\n                                                    AND csc.companyid = {$companyid} )\n                                                  OR c.id in (\n                                                    SELECT pc.courseid FROM {iomad_courses} pc\n                                                    WHERE pc.shared=1)"))) {
             // No courses for company, so exit.
             return false;
         }
         foreach ($courses as $course) {
             $courseids[] = $course->courseid;
         }
     } else {
         $courseids[] = $courseid;
     }
     // Going to build an array for the data.
     $data = array();
     // Count the three statii for the graph.
     $notstarted = 0;
     $inprogress = 0;
     $completed = 0;
     // Get completion data for each course.
     foreach ($courseids as $courseid) {
         // Get course object.
         if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
             error('unable to find course record');
         }
         $datum = null;
         $datum->coursename = $course->fullname;
         // Instantiate completion info thingy.
         $info = new completion_info($course);
         // If completion is not enabled on the course
         // there's no point carrying on.
         if (!$info->is_enabled()) {
             $datum->enabled = false;
             $data[$courseid] = $datum;
             continue;
         } else {
             $datum->enabled = true;
         }
         // Get criteria for coursed.
         // This is an array of tracked activities (only tracked ones).
         $criteria = $info->get_criteria();
         // Number of tracked activities to complete.
         $trackedcount = count($criteria);
         $datum->trackedcount = $trackedcount;
         // Get data for all users in course.
         // This is an array of users in the course. It contains a 'progress'
         // array showing completed *tracked* activities.
         $progress = $info->get_progress_all();
         // Iterate over users to get info.
         $users = array();
         $numusers = 0;
         $numprogress = 0;
         $numcomplete = 0;
         $numnotstarted = 0;
         foreach ($wantedusers as $wanteduser) {
             if (empty($progress[$wanteduser])) {
                 continue;
             }
             $user = $progress[$wanteduser];
             ++$numusers;
             $u = null;
             $u->fullname = fullname($user);
             // Count of progress is the number they have completed.
             $u->completed_count = count($user->progress);
             if ($trackedcount > 0) {
                 $u->completed_percent = round(100 * $u->completed_count / $trackedcount, 2);
             } else {
                 $u->completed_percent = '0';
             }
             // Find user's completion info for this course.
             if ($completioninfo = $DB->get_record('course_completions', array('userid' => $user->id, 'course' => $courseid))) {
                 if ((!empty($compfrom) || !empty($compto)) && empty($completioninfo->timecompleted)) {
                     continue;
                 } else {
                     if (!empty($compfrom) && $completioninfo->timecompleted < $compfrom) {
                         continue;
                     } else {
                         if (!empty($compto) && $completioninfo->timecompleted > $compto) {
                             continue;
                         } else {
                             $u->timeenrolled = $completioninfo->timeenrolled;
                             if (!empty($completioninfo->timestarted)) {
                                 $u->timestarted = $completioninfo->timestarted;
                                 if (!empty($completioninfo->timecompleted)) {
                                     $u->timecompleted = $completioninfo->timecompleted;
                                     $u->status = 'completed';
                                     ++$numcomplete;
                                 } else {
                                     $u->timecompleted = 0;
                                     $u->status = 'inprogress';
                                     ++$numprogress;
                                 }
                             } else {
                                 $u->timestarted = 0;
                                 $u->status = 'notstarted';
                                 ++$numnotstarted;
                             }
                         }
                     }
                 }
             } else {
                 $u->timeenrolled = 0;
                 $u->timecompleted = 0;
                 $u->timestarted = 0;
                 $u->status = 'notstarted';
                 ++$numnotstarted;
             }
             // Get the users score.
             $gbsql = "select gg.finalgrade as result from {grade_grades} gg, {grade_items} gi\n                          WHERE gi.courseid={$courseid} AND gi.itemtype='course' AND gg.userid=" . $user->id . "\n                          AND gi.id=gg.itemid";
             if (!($gradeinfo = $DB->get_record_sql($gbsql))) {
                 $gradeinfo = new object();
                 $gradeinfo->result = null;
             }
             $u->result = round($gradeinfo->result, 0);
             $userinfo = $DB->get_record('user', array('id' => $user->id));
             $u->email = $userinfo->email;
             $u->id = $user->id;
             $u->department = company_user::get_department_name($user->id);
             // Add to revised user array.
             $users[$user->id] = $u;
         }
         $datum->users = $users;
         $datum->completed = $numcomplete;
         $datum->numusers = $numusers;
         $datum->started = $numnotstarted;
         $datum->inprogress = $numprogress;
         $data[$courseid] = $datum;
     }
     // Make the data for the graph.
     $graphdata = array('notstarted' => $notstarted, 'inprogress' => $inprogress, 'completed' => $completed);
     // Make return object.
     $returnobj = null;
     $returnobj->data = $data;
     $returnobj->graphdata = $graphdata;
     return $returnobj;
 }
 public function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     if (!isloggedin()) {
         $this->content->text = get_string('pleaselogin', 'block_iomad_online_users');
         return $this->content;
     }
     $timetoshowusers = 300;
     // Seconds default.
     if (isset($CFG->block_iomad_online_users_timetosee)) {
         $timetoshowusers = $CFG->block_iomad_online_users_timetosee * 60;
     }
     $timefrom = 100 * floor((time() - $timetoshowusers) / 100);
     // Round to nearest 100 seconds for better query cache.
     $now = time();
     // Calculate if we are in separate groups.
     $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !iomad::has_capability('moodle/site:accessallgroups', $this->page->context);
     // Get the user current group.
     $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : null;
     $groupmembers = "";
     $groupselect = "";
     $rafrom = "";
     $rawhere = "";
     $params = array();
     $params['now'] = $now;
     $params['timefrom'] = $timefrom;
     // Add this to the SQL to show only group users.
     if ($currentgroup !== null) {
         $groupmembers = ", {groups_members} gm";
         $groupselect = "AND u.id = gm.userid AND gm.groupid = :currentgroup";
         $params['currentgroup'] = $currentgroup;
     }
     $companyselect = "";
     $companyusersjoin = "";
     if (company_user::is_company_user()) {
         company_user::load_company();
         $companyusersjoin = ", {user_info_data} muid, {user_info_field} muif";
         $companyselect = " AND muif.id = muid.fieldid\n                               AND u.id = muid.userid\n                               AND muif.shortname = 'company'\n                               AND muid.data = :companyshortname ";
         $params['companyshortname'] = $USER->company->shortname;
     }
     $userfields = user_picture::fields('u', array('username'));
     if ($this->page->course->id == SITEID) {
         // Site-level.
         $sql = "SELECT {$userfields}, MAX(u.lastaccess) AS lastaccess\n                      FROM {user} u {$groupmembers} {$companyusersjoin}\n                     WHERE u.lastaccess > {$timefrom}\n                           {$groupselect}\n                           {$companyselect}\n                  GROUP BY {$userfields}\n                  ORDER BY lastaccess DESC ";
         $csql = "SELECT COUNT(u.id), u.id\n                       FROM {user} u {$groupmembers} {$companyusersjoin}\n                      WHERE u.lastaccess > {$timefrom}\n                            {$groupselect}\n                            {$companyselect}\n                   GROUP BY u.id";
     } else {
         // Course level - show only enrolled users for now.
         // TODO: add a new capability for viewing of all users (guests+enrolled+viewing).
         list($esqljoin, $eparams) = get_enrolled_sql($this->page->context);
         $params = array_merge($params, $eparams);
         $sql = "SELECT {$userfields}, MAX(ul.timeaccess) AS lastaccess\n                      FROM {user_lastaccess} ul {$groupmembers}, {user} u\n                      JOIN ({$esqljoin}) euj ON euj.id = u.id\n                     WHERE ul.timeaccess > :timefrom\n                           AND u.id = ul.userid\n                           AND ul.courseid = :courseid\n                           AND ul.timeaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}\n                  GROUP BY {$userfields}\n                  ORDER BY lastaccess DESC";
         $csql = "SELECT COUNT(u.id)\n                      FROM {user_lastaccess} ul {$groupmembers}, {user} u\n                      JOIN ({$esqljoin}) euj ON euj.id = u.id\n                     WHERE ul.timeaccess > :timefrom\n                           AND u.id = ul.userid\n                           AND ul.courseid = :courseid\n                           AND ul.timeaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}";
         $params['courseid'] = $this->page->course->id;
     }
     // Calculate minutes.
     $minutes = floor($timetoshowusers / 60);
     // Verify if we can see the list of users, if not just print number of users.
     if (!iomad::has_capability('block/online_users:viewlist', $this->page->context)) {
         if (!($usercount = $DB->count_records_sql($csql, $params))) {
             $usercount = get_string("none");
         }
         $this->content->text = "<div class=\"info\">" . get_string("periodnminutes", "block_iomad_online_users", $minutes) . ": {$usercount}</div>";
         return $this->content;
     }
     if ($users = $DB->get_records_sql($sql, $params, 0, 50)) {
         // We'll just take the most recent 50 maximum.
         foreach ($users as $user) {
             $users[$user->id]->fullname = fullname($user);
         }
     } else {
         $users = array();
     }
     if (count($users) < 50) {
         $usercount = "";
     } else {
         $usercount = $DB->count_records_sql($csql, $params);
         $usercount = ": {$usercount}";
     }
     $this->content->text = "<h3>Recent Online Company Users</h3><div class=\"info\">(" . get_string("periodnminutes", "block_iomad_online_users", $minutes) . "{$usercount})</div>";
     // Now, we have in users, the list of users to show.
     // Because they are online.
     if (!empty($users)) {
         // Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link
         // (existing lang string).
         // Accessibility: Converted <div> to <ul>, inherit existing classes & styles.
         $this->content->text .= "<ul class='list'>\n";
         if (isloggedin() && iomad::has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) {
             $canshowicon = true;
         } else {
             $canshowicon = false;
         }
         foreach ($users as $user) {
             $this->content->text .= '<li class="listentry">';
             $timeago = format_time(time() - $user->lastaccess);
             // Bruno to calculate correctly on frontpage.
             if (isguestuser($user)) {
                 $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16));
                 $this->content->text .= get_string('guestuser') . '</div>';
             } else {
                 $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16));
                 $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $this->page->course->id . '" title="' . $timeago . '">' . $user->fullname . '</a></div>';
             }
             if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) {
                 // Only when logged in and messaging active etc.
                 $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />';
                 $anchortag = '<a href="' . $CFG->wwwroot . '/message/index.php?id=' . $user->id . '" title="' . get_string('messageselectadd') . '">' . $anchortagcontents . '</a>';
                 $this->content->text .= '<div class="message">' . $anchortag . '</div>';
             }
             $this->content->text .= "</li>\n";
         }
         $this->content->text .= '</ul><div class="clearer"><!-- --></div>';
     } else {
         $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>";
     }
     return $this->content;
 }
     $companydetails->category = $coursecat->id;
     $DB->update_record('company', $companydetails);
     // code by GWL
     $transaction->allow_commit();
     // End of code
 } else {
     $data->id = $companyid;
     $company = new company($companyid);
     $oldtheme = $company->get_theme();
     $themechanged = $oldtheme != $data->theme;
     $DB->update_record('company', $data);
     if ($themechanged) {
         $company->update_theme($data->theme);
     }
     if (company_user::is_company_user()) {
         company_user::reload_company();
     }
 }
 if (!empty($data->companylogo)) {
     //echo "COMPANYLOGO HERE"; die;
     file_save_draft_area_files($data->companylogo, $context->id, 'theme_' . $data->theme, 'companylogo', $data->id, array('subdirs' => 0, 'maxbytes' => 150 * 1024, 'maxfiles' => 1));
 }
 if (!empty($data->companydomains)) {
     $domainsarray = preg_split('/[\\r\\n]+/', $data->companydomains, -1, PREG_SPLIT_NO_EMPTY);
     // Delete any recorded domains for this company.
     $DB->delete_records('company_domains', array('companyid' => $companyid));
     foreach ($domainsarray as $domain) {
         if (!empty($domain)) {
             $DB->insert_record('company_domains', array('companyid' => $companyid, 'domain' => $domain));
         }
     }
Example #11
0
 public function definition()
 {
     global $PAGE, $USER;
     if (!company_user::is_company_user()) {
         $mform =& $this->_form;
         // Code added by sumit
         $mform->addElement('hidden', 'returnurl', $this->returnurl);
         $mform->setType('returnurl', PARAM_LOCALURL);
         // end of code
         // Then show the fields about where this block appears.
         $mform->addElement('header', 'header', get_string('company', 'block_iomad_company_admin'));
         if ($this->add_company_selector()) {
             // Make form auto submit on change of selected company.
             $formid = $mform->getAttribute("id");
             $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array($formid, "id_companyid", null));
         }
     }
 }
$templatename = optional_param('templatename', '', PARAM_NOTAGS);
$new = optional_param('createnew', 0, PARAM_INTEGER);
$context = context_system::instance();
require_login();
$PAGE->set_context($context);
$urlparams = array('templateid' => $templateid, 'templatename' => $templatename);
if ($returnurl) {
    $urlparams['returnurl'] = $returnurl;
}
$templatelist = new moodle_url('/local/email/template_list.php', $urlparams);
// Set the companyid to bypass the company select form if possible.
if (!empty($SESSION->currenteditingcompany)) {
    $companyid = $SESSION->currenteditingcompany;
} else {
    if (!empty($USER->company)) {
        $companyid = company_user::companyid();
    } else {
        if (!iomad::has_capability('local/email:edit', context_system::instance())) {
            print_error('There has been a configuration error, please contact the site administrator');
        } else {
            $blockpage->display_header();
            redirect(new moodle_url('/local/iomad_dashboard/index.php'), 'Please select a company from the dropdown first');
        }
    }
}
iomad::require_capability('local/email:send', $context);
if ($templateid) {
    $templaterecord = $DB->get_record('email_template', array('id' => $templateid), '*', MUST_EXIST);
} else {
    if ($templatename) {
        if (!($templaterecord = $DB->get_record('email_template', array('companyid' => $companyid, 'name' => $templatename), '*'))) {
 public function process()
 {
     global $DB, $CFG;
     $this->create_user_selectors();
     // Process incoming enrolments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstoassign = $this->potentialusers->get_selected_users();
         if (!empty($userstoassign)) {
             foreach ($userstoassign as $adduser) {
                 $allow = true;
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($allow) {
                     company_user::enrol($adduser, array($this->course->id), $this->selectedcompany);
                     EmailTemplate::send('user_added_to_course', array('course' => $this->course, 'user' => $adduser));
                 }
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
     // Process incoming unenrolments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstounassign = $this->currentusers->get_selected_users();
         if (!empty($userstounassign)) {
             foreach ($userstounassign as $removeuser) {
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 company_user::unenrol($removeuser, array($this->course->id), $this->selectedcompany);
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
 }
Example #14
0
 /**
  * Sets up the page
  *
  * Paramters -
  *             $urlparams = array().
  *
  **/
 public function setup($urlparams = null)
 {
     global $USER;
     // All iomad_company_admin pages require login.
     require_login(null, false);
     // Adds to $PAGE, creates $OUTPUT.
     // Make sure a company user can not retrieve pages for other companies.
     $companyid = optional_param('companyid', 0, PARAM_INTEGER);
     if ($companyid && !company_user::can_see_company($companyid)) {
         throw new Exception(self::get_string('notallowedtoaccessothercompaniesdata'));
     }
     $this->page->set_url($this->get_relative_url($urlparams));
     $this->page->set_context(context_system::instance());
     $this->page->set_pagelayout('mydashboard');
     $blocktitle = self::get_string('blocktitle');
     /**
      * *Think* this bit is deprecated
     $entryurl = optional_param('entryurl', '', PARAM_LOCALURL);
     $entrytitle = optional_param('entrytitle', '', PARAM_TEXT);
     
     if ( $entryurl || $entrytitle ) {
         if ( !isset($USER->iomad) ) {
             $USER->iomad = new stdClass();
         }
     
         if ( $entryurl == (new moodle_url('/')) ) {
             unset($USER->iomad->entrypoint);
             unset($USER->iomad->entrytitle);
         } else {
             $USER->iomad->entrypoint = $entryurl;
             $USER->iomad->entrytitle = $entrytitle;
         }
     }
     */
     $this->page->set_title($this->pagetitle);
     $this->page->set_heading($blocktitle);
 }
Example #15
0
/**
 * Gets the list of outstanding approvals for the current user.
 *
 * returns array
 *
 **/
function approve_enroll_get_my_users()
{
    global $CFG, $DB, $USER, $SESSION;
    require_once $CFG->dirroot . '/local/iomad/lib/company.php';
    require_once $CFG->dirroot . '/local/iomad/lib/user.php';
    // Set the companyid to bypass the company select form if possible.
    if (!empty($SESSION->currenteditingcompany)) {
        $companyid = $SESSION->currenteditingcompany;
    } else {
        if (!empty($USER->company)) {
            $companyid = company_user::companyid();
        } else {
            return false;
        }
    }
    // Check if we can have users of my type.
    if (is_siteadmin($USER->id)) {
        $approvaltype = 'both';
    } else {
        // What type of manager am I?
        if ($manageruser = $DB->get_record('company_users', array('userid' => $USER->id))) {
            if ($manageruser->managertype == 2) {
                $approvaltype = 'manager';
            } else {
                if ($manageruser->managertype == 1) {
                    $approvaltype = 'company';
                } else {
                    return false;
                }
            }
        }
    }
    // Get the list of users I am responsible for.
    $myuserids = company::get_my_users_list($companyid);
    if (!empty($myuserids)) {
        if ($approvaltype == 'manager') {
            //  Need to deal with departments here.
            if ($userarray = $DB->get_records_sql("SELECT beae.* FROM {block_iomad_approve_access} beae\n                                               RIGHT JOIN {trainingevent} cc ON cc.id=beae.activityid\n                                               AND cc.approvaltype in (1,3)\n                                               WHERE beae.companyid=:companyid AND beae.manager_ok = 0\n                                               AND beae.userid != :myuserid\n                                               AND beae.userid\n                                               IN ({$myuserids})", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
        if ($approvaltype == 'company') {
            if ($userarray = $DB->get_records_sql("SELECT beae.* FROM {block_iomad_approve_access} beae\n                                               RIGHT JOIN {trainingevent} cc ON cc.id=beae.activityid\n                                               WHERE beae.companyid=:companyid\n                                               AND beae.userid != :myuserid\n                                               AND beae.userid IN ({$myuserids})\n                                               AND (\n                                                cc.approvaltype in (2,3)\n                                                AND beae.tm_ok = 0 )\n                                               OR (\n                                                cc.approvaltype = 1\n                                                AND beae.manager_ok = 0)", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
        if ($approvaltype == 'both') {
            if ($userarray = $DB->get_records_sql("SELECT * FROM {block_iomad_approve_access}\n                                                   WHERE companyid=:companyid\n                                                   AND (tm_ok = 0 OR manager_ok = 0)\n                                                   AND userid != :myuserid\n                                                   AND userid IN ({$myuserids})", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
    }
    return array();
}
 public function process()
 {
     global $DB, $CFG;
     $this->create_course_selectors();
     // Process incoming enrolments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestoassign = $this->potentialcourses->get_selected_courses();
         if (!empty($coursestoassign)) {
             foreach ($coursestoassign as $addcourse) {
                 $allow = true;
                 if ($allow) {
                     company_user::enrol($this->user, array($addcourse->id));
                     EmailTemplate::send('user_added_to_course', array('course' => $addcourse, 'user' => $this->user));
                 }
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
     // Process incoming unenrolments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestounassign = $this->currentcourses->get_selected_courses();
         if (!empty($coursestounassign)) {
             foreach ($coursestounassign as $removecourse) {
                 company_user::unenrol($this->user, array($removecourse->id));
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
 }
Example #17
0
function theme_bootstrap_process_company_css($css, $theme)
{
    global $USER;
    company_user::load_company();
    if (isset($USER->company)) {
        // replace company properties
        foreach ($USER->company as $key => $value) {
            if (isset($value)) {
                $css = preg_replace("/\\[\\[company:{$key}\\]\\]/", $value, $css);
            }
        }
    }
    return $css;
}
if ($companies = company::get_companies_rs($page, $perpage)) {
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $strusers = $blockpage->get_string('company_users');
    $strnewuser = $blockpage->get_string('newuser');
    $strmanagers = $blockpage->get_string('company_managers');
    $strcourses = $blockpage->get_string('company_courses');
    $strcreatecourse = $blockpage->get_string('newcourse');
    $strcourseusers = $blockpage->get_string('courseusers');
    $strusersdownload = $blockpage->get_string('users_download');
    $table = new html_table();
    $table->head = array("Name", "Short name", "City", "", "", "", "", "", "", "", "", "");
    $table->align = array("left", "left", "left", "center", "center", "center", "center", "center", "center", "center", "center", "center");
    $table->width = "95%";
    foreach ($companies as $company) {
        if (company_user::can_see_company($company)) {
            if (iomad::has_capability('block/iomad_company_admin:company_delete', $context)) {
                $deletebutton = "<a href=\"company_list.php?delete={$company->id}&amp;sesskey=" . sesskey() . "\">{$strdelete}</a>";
            } else {
                $deletebutton = "";
            }
            if (iomad::has_capability('block/iomad_company_admin:company_edit', $context)) {
                $editbutton = "<a href='" . new moodle_url('company_edit_form.php', array("companyid" => $company->id)) . "'>{$stredit}</a>";
            } else {
                $editbutton = "";
            }
            if (iomad::has_capability('block/iomad_company_admin:company_user', $context)) {
                $usersbutton = "<a href='" . new moodle_url('company_users_form.php', array("companyid" => $company->id)) . "'>{$strusers}</a>";
            } else {
                $usersbutton = "";
            }
 public function process($departmentid, $roletype)
 {
     global $DB, $USER;
     $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
     $departmentmanagerrole = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'));
     $companycoursenoneditorrole = $DB->get_record('role', array('shortname' => 'companycoursenoneditor'));
     $companycourseeditorrole = $DB->get_record('role', array('shortname' => 'companycourseeditor'));
     // Process incoming assignments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstoassign = $this->potentialusers->get_selected_users();
         if (!empty($userstoassign)) {
             foreach ($userstoassign as $adduser) {
                 $allow = true;
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($allow) {
                     if ($roletype != 0) {
                         // Adding a manager type.
                         // Add user to the company manager table.
                         if ($userrecord = $DB->get_record('company_users', array('companyid' => $this->selectedcompany, 'userid' => $adduser->id))) {
                             if ($roletype == 1 && $userrecord->managertype == 0) {
                                 // Give them the company manager role.
                                 role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
                                 // Deal with company courses.
                                 if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                     foreach ($companycourses as $companycourse) {
                                         if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                             if ($DB->record_exists('company_created_courses', array('companyid' => $companycourse->companyid, 'courseid' => $companycourse->courseid))) {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                                             } else {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($roletype == 2 && $userrecord->managertype == 0) {
                                     // Give them the department manager role.
                                     role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                     // Deal with company courses.
                                     if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                         foreach ($companycourses as $companycourse) {
                                             if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                             }
                                         }
                                     }
                                 } else {
                                     if ($roletype == 1 && ($userrecord->managertype = 2)) {
                                         // Give them the department manager role.
                                         role_unassign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                         role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
                                         // Deal with course permissions.
                                         if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                             foreach ($companycourses as $companycourse) {
                                                 if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                     // If its a company created course then assign the editor role to the user.
                                                     if ($DB->record_exists('company_created_courses', array('companyid' => $this->selectedcompany, 'courseid' => $companycourse->courseid))) {
                                                         company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                                                     } else {
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($roletype == 2 && ($userrecord->managertype = 1)) {
                                             // Give them the department manager role.
                                             role_unassign($companymanagerrole->id, $adduser->id, $this->context->id);
                                             role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                             // Deal with company course roles.
                                             if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                                 foreach ($companycourses as $companycourse) {
                                                     if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                         company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             $userrecord->managertype = $roletype;
                             $DB->update_record('company_users', $userrecord);
                         } else {
                             if ($roletype == 1 && $DB->get_records_sql('SELECT id FROM {company_users}
                                                         WHERE
                                                         userid = :userid
                                                         AND managertype = :roletype
                                                         AND companyid != :companyid', array('userid' => $adduser->id, 'roletype' => 1, 'companyid' => $this->selectedcompany))) {
                                 // We have a company manager from another company.
                                 // We need to add another record.
                                 $company = new company($this->selectedcompany);
                                 $company->assign_user_to_company($adduser->id);
                                 $DB->set_field('company_users', 'managertype', 1, array('userid' => $adduser->id, 'companyid' => $this->selectedcompany));
                                 // Deal with company courses.
                                 if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                     foreach ($companycourses as $companycourse) {
                                         if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                             if ($DB->record_exists('company_created_courses', array('companyid' => $companycourse->companyid, 'courseid' => $companycourse->courseid))) {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                                             } else {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 // Assign the user to department as staff.
                                 company::assign_user_to_department($departmentid, $adduser->id);
                             }
                         }
                     } else {
                         // Assign the user to department as staff.
                         company::assign_user_to_department($departmentid, $adduser->id);
                     }
                 }
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
     // Process incoming unassignments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstounassign = $this->currentusers->get_selected_users();
         if (!empty($userstounassign)) {
             // Check if we are mearly removing the manager role.
             if ($roletype != 0) {
                 foreach ($userstounassign as $removeuser) {
                     // GWL : Check the userid is valid.
                     if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                         print_error('invaliduserdepartment', 'block_iomad_company_management');
                     }
                     $userrecord = $DB->get_record('company_users', array('companyid' => $this->selectedcompany, 'userid' => $removeuser->id));
                     // Is this a manager from another company?
                     if ($DB->get_records_sql("SELECT id FROM {company_users}\n                                                  WHERE userid = :userid\n                                                  AND companyid != :companyid\n                                                  AND managertype = 1", array('userid' => $removeuser->id, 'companyid' => $this->selectedcompany))) {
                         // Remove the user from this company.
                         $DB->delete_records('company_users', (array) $userrecord);
                     } else {
                         // Remove the manager status from the user.
                         $userrecord->managertype = 0;
                         $DB->update_record('company_users', $userrecord);
                         role_unassign($companymanagerrole->id, $removeuser->id, $this->context->id);
                         role_unassign($departmentmanagerrole->id, $removeuser->id, $this->context->id);
                     }
                     // Remove their capabilities from the company courses.
                     if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                         foreach ($companycourses as $companycourse) {
                             if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                 company_user::unenrol($removeuser, array($companycourse->courseid), $companycourse->companyid);
                             }
                         }
                     }
                 }
             } else {
                 foreach ($userstounassign as $removeuser) {
                     // GWL : Check the userid is valid.
                     if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
                         print_error('invaliduserdepartment', 'block_iomad_company_management');
                     }
                     // Assign the user to parent department as staff.
                     company::assign_user_to_department($this->companydepartment, $removeuser->id);
                 }
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
 }
function user_download_csv($userids, $fields, $includecompanyfield)
{
    global $CFG, $SESSION, $DB;
    require_once $CFG->dirroot . '/user/profile/lib.php';
    $filename = clean_filename(get_string('users') . '.csv');
    header("Content-Type: application/download\n");
    header("Content-Disposition: attachment; filename={$filename}");
    header("Expires: 0");
    header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
    header("Pragma: public");
    $delimiter = get_string('listsep', 'langconfig');
    $encdelim = '&#' . ord($delimiter);
    $row = array();
    foreach ($fields as $fieldname) {
        if ($includecompanyfield || $fieldname != "profile_field_company") {
            $row[] = str_replace($delimiter, $encdelim, $fieldname);
        }
    }
    $row[] = "temppassword";
    echo implode($delimiter, $row) . "\n";
    foreach ($userids as $userid) {
        // Stop the script from timing out on large numbers of users.
        set_time_limit(30);
        $row = array();
        if (!($user = $DB->get_record('user', array('id' => $userid)))) {
            continue;
        }
        profile_load_data($user);
        foreach ($fields as $field => $unused) {
            // Stop the script from timing out on large numbers of users.
            set_time_limit(30);
            if ($includecompanyfield || $field != "profile_field_company") {
                $row[] = str_replace($delimiter, $encdelim, $user->{$field});
            }
        }
        $row[] = str_replace($delimiter, $encdelim, company_user::get_temporary_password($user));
        echo implode($delimiter, $row) . "\n";
    }
    die;
}
Example #21
0
function unassign_courses_to_user($department, $title, $companyid, $courses, $userid = null)
{
    global $DB;
    $whereconditon = array('department' => $department, 'title' => $title, 'company' => $companyid);
    $companycourses = $DB->get_records('local_dept_title_courses', $whereconditon);
    if ($courses) {
        if (!is_null($userid)) {
            // get all users match with provided department & title
            $whereconditon['user'] = $userid;
        }
        $userorusers = $DB->get_records('local_dept_title_user', $whereconditon);
        foreach ($userorusers as $companyuser) {
            $user = $DB->get_record('user', array('id' => $companyuser->user, 'deleted' => 0), '*', MUST_EXIST);
            company_user::unenrol($user, $courses, $companyid);
        }
    }
}
        //
        // Code End
        // Code added by Sumit here we asign region or location to user and assign manager to company
        $data->userdepartment = $userlocation ? $userlocation : $data->userregion;
        $data->userdepartment = $data->managertype || !$data->userdepartment ? $parentnode->id : $data->userdepartment;
        company::assign_user_to_department($data->userdepartment, $userid);
        /* END -  GWL  : Assign user to department */
        // Code added by Sumit here we asign region or location to user and assign manager to company
        $data->userdepartment = $userlocation ? $userlocation : $data->userregion;
        $data->userdepartment = $data->managertype || !$data->userdepartment ? $parentnode->id : $data->userdepartment;
        company::assign_user_to_department($data->userdepartment, $userid);
        /* END -  GWL  : Assign user to department */
        // Enrol the user on the courses.
        if (!empty($createcourses)) {
            $userdata = $DB->get_record('user', array('id' => $userid));
            company_user::enrol($userdata, $createcourses, $companyid);
        }
        if (isset($data->submitandback)) {
            // redirect($returnurl);
            // Code by sumit
            redirect(new moodle_url('/blocks/iomad_company_admin/editusers.php'));
            // end of code
        } else {
            redirect($linkurl . "?createdok=1");
        }
    }
}
$blockpage->display_header();
// GWL : Check the department is valid.
if (!empty($departmentid) && !company::check_valid_department($companyid, $departmentid)) {
    print_error('invaliddepartment', 'block_iomad_company_admin');
Example #23
0
    } else {
        if (!($event = $DB->get_record('trainingevent', array('id' => $dodownload)))) {
            die;
        }
        $location = $DB->get_record('classroom', array('id' => $event->classroomid));
        // Output everything to a file.
        header("Content-Type: application/download\n");
        header("Content-Disposition: attachment; filename=\"" . $event->name . ".csv\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
        header("Pragma: public");
        $locationinfo = "{$location->name}, {$location->address}, {$location->city},";
        $locationinfo .= " {$location->country}, {$location->postcode}";
        echo "\"{$event->name}, {$locationinfo}\"\n";
        echo "\"" . get_string('fullname') . "\",\"" . get_string('email') . "\"\n";
        if ($users = $DB->get_records_sql('SELECT userid AS id FROM {trainingevent_users}
                                           WHERE trainingeventid=' . $event->id . '
                                           AND userid IN (' . $allowedlist . ')')) {
            foreach ($users as $user) {
                $fulluserdata = $DB->get_record('user', array('id' => $user->id));
                $fulluserdata->department = company_user::get_department_name($user->id);
                $fullname = "{$fulluserdata->firstname} {$fulluserdata->lastname}";
                echo "\"{$fullname}\", \"{$fulluserdata->department}\", \"{$fulluserdata->email}\"\n";
            }
        }
    }
}
if (!empty($dodownload)) {
    exit;
}
echo $OUTPUT->footer();
Example #24
0
 /**
  * Associates a course to a company
  *
  * Parameters -
  *              $course = stdclass();
  *              $departmentid = int;
  *              $own = boolean;
  *
  * */
 public function add_course($course, $departmentid = 0, $own = false, $licensed = false)
 {
     global $DB;
     if ($departmentid != 0) {
         // Adding to a specified department.
         $companydepartment = $departmentid;
     } else {
         // Put course in default company department.
         $companydepartmentnode = self::get_company_parentnode($this->id);
         $companydepartment = $companydepartmentnode->id;
     }
     if (!$DB->record_exists('company_course', array('companyid' => $this->id, 'courseid' => $course->id))) {
         $DB->insert_record('company_course', array('companyid' => $this->id, 'courseid' => $course->id, 'departmentid' => $companydepartment));
     }
     // Set up defaults for course management.
     if (!$DB->get_record('iomad_courses', array('courseid' => $course->id))) {
         $DB->insert_record('iomad_courses', array('courseid' => $course->id, 'licensed' => $licensed, 'shared' => 0));
     }
     // Set up manager roles.
     if (!$licensed) {
         if ($companymanagers = $DB->get_records_sql("SELECT * FROM {company_users}\n                                                         WHERE companyid = :companyid\n                                                         AND managertype != 0", array('companyid' => $this->id))) {
             $companycoursenoneditorrole = $DB->get_record('role', array('shortname' => 'companycoursenoneditor'));
             $companycourseeditorrole = $DB->get_record('role', array('shortname' => 'companycourseeditor'));
             foreach ($companymanagers as $companymanager) {
                 if ($user = $DB->get_record('user', array('id' => $companymanager->userid, 'deleted' => 0))) {
                     if ($DB->record_exists('course', array('id' => $course->id))) {
                         if (!$own) {
                             // Not created by a company manager.
                             company_user::enrol($user, array($course->id), $this->id, $companycoursenoneditorrole->id);
                         } else {
                             if ($companymanager->managertype == 2) {
                                 // Assign the department manager course access role.
                                 company_user::enrol($user, array($course->id), $this->id, $companycoursenoneditorrole->id);
                             } else {
                                 // Assign the company manager course access role.
                                 company_user::enrol($user, array($course->id), $this->id, $companycourseeditorrole->id);
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($own && $departmentid == 0) {
         // Add it to the list of company created courses.
         if (!$DB->record_exists('company_created_courses', array('companyid' => $this->id, 'courseid' => $course->id))) {
             $DB->insert_record('company_created_courses', array('companyid' => $this->id, 'courseid' => $course->id));
         }
     }
 }
                 //  $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
                 role_unassign_all(array('roleid' => $departmentmanagerrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
                 role_unassign_all(array('roleid' => $companyinstructorrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
                 // role_unassign_all(array('roleid' => $companymanagerrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
                 // Assign the user as a company manager.
                 $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
                 // Give them the manager role.        else if ($usernew->managertype == 1) {
                 role_assign($companymanagerrole->id, $usernew->id, $systemcontext->id);
                 if ($companycourses = $DB->get_records('company_course', array('companyid' => $companyid))) {
                     foreach ($companycourses as $companycourse) {
                         if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                             // If its a company created course then assign the editor role to the user.
                             if ($DB->record_exists('company_created_courses', array('companyid' => $companyid, 'courseid' => $companycourse->courseid))) {
                                 company_user::enrol($user, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                             } else {
                                 company_user::enrol($user, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                             }
                         }
                     }
                 }
             } else {
                 $departmentmanagerrole = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'));
                 $companyinstructorrole = $DB->get_record('role', array('shortname' => 'instructor'));
                 $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
                 role_unassign_all(array('roleid' => $departmentmanagerrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
                 role_unassign_all(array('roleid' => $companyinstructorrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
                 role_unassign_all(array('roleid' => $companymanagerrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
             }
         }
     }
 }
Example #26
0
     if (!company::check_canedit_user($companyid, $user->id)) {
         print_error('invaliduserid');
     }
     if (is_primary_admin($user->id)) {
         print_error('nopermissions', 'error', '', 'delete the primary admin user');
     }
     if ($confirm != md5($unsuspend)) {
         $fullname = fullname($user, true);
         echo $OUTPUT->heading(get_string('unsuspenduser', 'block_iomad_company_admin') . " " . $fullname);
         $optionsyes = array('unsuspend' => $unsuspend, 'confirm' => md5($unsuspend), 'sesskey' => sesskey());
         echo $OUTPUT->confirm(get_string('unsuspendcheckfull', 'block_iomad_company_admin', "'{$fullname}'"), new moodle_url('editusers.php', $optionsyes), 'editusers.php');
         echo $OUTPUT->footer();
         die;
     } else {
         // Actually unsuspend the user.
         company_user::unsuspend($user->id);
     }
 } else {
     if ($acl and confirm_sesskey()) {
         if (!iomad::has_capability('block/iomad_company_admin:editusers', $systemcontext)) {
             // TODO: this should be under a separate capability.
             print_error('nopermissions', 'error', '', 'modify the NMET access control list');
         }
         if (!($user = $DB->get_record('user', array('id' => $acl)))) {
             print_error('nousers', 'error');
         }
         if (!is_mnet_remote_user($user)) {
             print_error('usermustbemnet', 'error');
         }
         $accessctrl = strtolower(required_param('accessctrl', PARAM_ALPHA));
         if ($accessctrl != 'allow' and $accessctrl != 'deny') {
 if ((!isset($rowcols['profile_field_company']) || empty($rowcols['profile_field_company'])) && !company_user::is_company_user() && $companyid == 0) {
     $errormsg['profile_field_company'] = get_string('profile_field_company_not_set', 'block_iomad_company_admin');
 }
 if (isset($rowcols['profile_field_company']) && !company_user::can_see_company($rowcols['profile_field_company'])) {
     $errormsg['profile_field_company'] = get_string('invalid_company', 'block_iomad_company_admin');
 }
 if ($companyid > 0 && isset($rowcols['profile_field_company']) && !empty($rowcols['profile_field_company']) && $rowcols['profile_field_company'] != $companyshortname) {
     $errormsg['profile_field_company'] = get_string('profile_field_company_not_empty_does_not_match_selected', 'block_iomad_company_admin');
 }
 if ((!isset($rowcols['username']) || empty($rowcols['username'])) && isset($rowcols['email']) && !empty($rowcols['email'])) {
     // No username given, try to find an existing user via the email address.
     if ($perfexistinguser = $DB->get_record('user', array('email' => $rowcols['email']))) {
         $rowcols['username'] = $perfexistinguser->username;
     } else {
         // No existing user matches, generate a new username.
         $rowcols['username'] = company_user::generate_username($rowcols['email']);
     }
 }
 $usernameexist = $DB->record_exists('user', array('username' => $rowcols['username']));
 $emailexist = $DB->record_exists('user', array('email' => $rowcols['email']));
 $cleanusername = clean_param($rowcols['username'], PARAM_USERNAME);
 $validusername = strcmp($rowcols['username'], $cleanusername);
 $validemail = validate_email($rowcols['email']);
 if ($validusername != 0 || !$validemail) {
     if ($validusername != 0) {
         $errormsg['username'] = get_string('invalidusernameupload');
     }
     if (!$validemail) {
         $errormsg['email'] = get_string('invalidemail');
     }
 }