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 . '&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 = $DB->get_record('company', array('id' => $companyid)); $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)); }
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)); } } }
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)); } } }
} // Print the header. echo $OUTPUT->header(); // Print the form. echo $OUTPUT->heading(get_string('uploaduserspreview', 'tool_uploaduser')); $cir->init(); $availableauths = get_plugin_list('auth'); $availableauths = array_keys($availableauths); $contents = array(); while ($fields = $cir->next()) { $errormsg = array(); $rowcols = array(); foreach ($fields as $key => $field) { $rowcols[$columns[$key]] = $field; } 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']);