function my_homeworks($course_id, $hp_items, $user_id) { global $JLMS_DB; if (!$course_id) { return array(); } $my_hw = array(); $JLMS_ACL =& JLMSFactory::getACL(); $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only'); $members = "'0'"; $where = ''; if ($JLMS_ACL->_role_type == 2 || $JLMS_ACL->_role_type == 3 || $JLMS_ACL->_role_type == 4) { if ($assigned_groups_only) { $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($user_id); $groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($user_id); $groups_where_admin_manager = array_merge($groups_where_admin_manager, $groups_where_isset_user); if (count($groups_where_admin_manager)) { $where .= "\n AND (is_limited = 0 OR `groups` LIKE '%|{$groups_where_admin_manager['0']}|%'"; for ($i = 1; $i < count($groups_where_admin_manager); $i++) { $where .= "\n OR `groups` like '%|{$groups_where_admin_manager[$i]}|%'"; } $where .= "\n OR a.owner_id = '" . $user_id . "')"; } else { $where .= "\n AND (is_limited = 0 OR a.owner_id = '" . $user_id . "' OR a.id = 0) AND groups = ''"; } } } else { if ($JLMS_ACL->_role_type < 2) { $query = "select a.group_id FROM #__lms_users_in_global_groups as a WHERE a.user_id = '" . $user_id . "' AND a.subgroup1_id = 0 AND a.group_id > 0"; $JLMS_DB->setQuery($query); $temp1 = $JLMS_DB->loadResultArray(); $query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '" . $user_id . "' AND subgroup1_id > 0"; $JLMS_DB->setQuery($query); $temp2 = $JLMS_DB->loadResultArray(); $group_where_isset_user = array_merge($temp1, $temp2); $where .= "\n AND (a.is_limited = 0"; if (isset($group_where_isset_user) && count($group_where_isset_user)) { $where .= "\n OR (a.is_limited = 1" . "\n AND (a.groups LIKE '%|{$group_where_isset_user['0']}|%'"; for ($i = 1; $i < count($group_where_isset_user); $i++) { $where .= "\n OR a.groups like '%|{$group_where_isset_user[$i]}|%'"; } $where .= "\n )))"; } else { $where .= "\n )"; } } } $query = "SELECT a.*, d.hw_status, c.user_id as stu_id, e.user_id as teach_id" . "\n FROM (#__lms_homework as a, #__lms_courses as b)" . "\n LEFT JOIN #__lms_users_in_groups as c ON c.user_id = '" . $user_id . "' AND c.course_id = b.id" . "\n LEFT JOIN #__lms_homework_results as d ON d.course_id = b.id AND d.user_id = " . $user_id . " AND d.hw_id = a.id" . "\n LEFT JOIN #__lms_user_courses as e ON e.course_id = b.id AND e.user_id = '" . $user_id . "'" . "\n WHERE (ISNULL(d.hw_status) OR d.hw_status = 0)" . "\n AND a.course_id IN ({$course_id})" . "\n AND a.course_id = b.id AND a.end_date >= '" . date('Y-m-d', time()) . "'" . $where . "\n LIMIT 0, {$hp_items}"; $JLMS_DB->SetQuery($query); $my_hw = $JLMS_DB->LoadObjectList(); if ($JLMS_ACL->_role_type < 2) { $my_hw = filterByShowPeriod($my_hw); } return $my_hw; }
function sendNotification($params) { $db = JFactory::getDBO(); $mailManager =& MailManager::getChildInstance(); $app = JFactory::getApplication(); $notification_event = NotificationsManager::getNotificationEventByActionName($params['action_name']); if (!$notification_event) { return ''; } if (!isset($params['sender'])) { $params['sender'] = array($app->getCfg('mailfrom'), $app->getCfg('fromname')); } $sql = "SELECT learner_template, manager_template, selected_manager_roles, learner_template_disabled, manager_template_disabled, disabled FROM #__lms_email_notifications WHERE id = " . $db->quote($notification_event->id); $db->setQuery($sql); $row = $db->loadObject(); if ($row) { $notification_event->disabled = $row->disabled; $notification_event->learner_template = $row->learner_template; $notification_event->manager_template = $row->manager_template; $notification_event->learner_template_disabled = $row->learner_template_disabled; $notification_event->manager_template_disabled = $row->manager_template_disabled; $notification_event->selected_manager_roles = explode(',', $row->selected_manager_roles); } if ($notification_event->disabled || !$notification_event->learner_template && !$notification_event->manager_template) { return ''; } $learner_template = ''; $manager_template = ''; if ($notification_event->learner_template) { $learner_template = NotificationsManager::getEmailTemplate($notification_event->learner_template); } if ($notification_event->manager_template) { $manager_template = NotificationsManager::getEmailTemplate($notification_event->manager_template); } if (!is_object($learner_template) && !is_object($manager_template)) { return ''; } if (isset($params['markers']) && is_array($params['markers'])) { $params['markers'] = NotificationsManager::addDateTimeMarkers($params['markers']); } else { $params['markers'] = NotificationsManager::addDateTimeMarkers(array()); } if (isset($params['markers']) && count($params['markers'])) { $markers_keys = array_keys($params['markers']); $markers_values = array_values($params['markers']); if (isset($params['markers_nohtml']) && is_array($params['markers_nohtml'])) { $markers_nohtml_keys = array_keys($params['markers_nohtml']); $markers_nohtml_values = array_values($params['markers_nohtml']); } else { $markers_nohtml_keys = array(); $markers_nohtml_values = array(); } if (is_object($learner_template) && $notification_event->learner_template && $notification_event->use_learner_template) { $learner_template->subject = str_replace($markers_keys, $markers_values, $learner_template->subject); $learner_template->template_html = str_replace($markers_keys, $markers_values, $learner_template->template_html); $learner_template->template_alt_text = str_replace($markers_nohtml_keys, $markers_nohtml_values, $learner_template->template_alt_text); $learner_template->template_alt_text = str_replace($markers_keys, $markers_values, $learner_template->template_alt_text); } if (is_object($manager_template) && $notification_event->manager_template && $notification_event->use_manager_template && !$notification_event->skip_managers) { $manager_template->subject = str_replace($markers_keys, $markers_values, $manager_template->subject); $manager_template->template_html = str_replace($markers_keys, $markers_values, $manager_template->template_html); $manager_template->template_alt_text = str_replace($markers_nohtml_keys, $markers_nohtml_values, $manager_template->template_alt_text); $manager_template->template_alt_text = str_replace($markers_keys, $markers_values, $manager_template->template_alt_text); } } if (isset($params['wrappers']) && count($params['wrappers'])) { if (is_object($learner_template) && $notification_event->learner_template && $notification_event->use_learner_template) { $learner_template->subject = NotificationsManager::replaceWrappers($params['wrappers'], $learner_template->subject); $learner_template->template_html = NotificationsManager::replaceWrappers($params['wrappers'], $learner_template->template_html); $learner_template->template_alt_text = NotificationsManager::replaceWrappers($params['wrappers'], $learner_template->template_alt_text); } if (is_object($manager_template) && $notification_event->manager_template && $notification_event->use_manager_template && !$notification_event->skip_managers) { $manager_template->subject = NotificationsManager::replaceWrappers($params['wrappers'], $manager_template->subject); $manager_template->template_html = NotificationsManager::replaceWrappers($params['wrappers'], $manager_template->template_html); $manager_template->template_alt_text = NotificationsManager::replaceWrappers($params['wrappers'], $manager_template->template_alt_text); } } $managers_array = array(); $already_sent_users = array(); if (is_object($learner_template) && $notification_event->use_learner_template && !$notification_event->learner_template_disabled) { if (isset($params['user_id']) && $params['user_id']) { $sql = "SELECT email, name FROM #__users WHERE id = " . $db->quote($params['user_id']); $db->setQuery($sql); $user = $db->loadObject(); $params['recipient'] = $user->email; //array( $user->name, $user->email ); $params['subject'] = $learner_template->subject; $params['body'] = $learner_template->template_html; $params['alttext'] = $learner_template->template_alt_text; if (isset($notification_event->notification_type) && $notification_event->notification_type == 2) { $params['attachment']->file_source = getCertificateFile($params); $params['attachment']->file_name = 'Certificate.png'; } $mailManager->prepareEmail($params); $mailManager->sendEmail(); $already_sent_users[] = intval($params['user_id']); unset($params['attachment']); } } if (is_object($manager_template) && $notification_event->use_manager_template && !$notification_event->manager_template_disabled && !$notification_event->skip_managers) { if (isset($params['course_id']) && $params['course_id'] && isset($notification_event->selected_manager_roles[0])) { $all_teachers_role_ids = JLMS_ACL_HELPER::getTeachersRoleIds(); $teachers_role_ids = array_intersect($notification_event->selected_manager_roles, $all_teachers_role_ids); $teachers = JLMS_ACL_HELPER::getCourseTeachers($params['course_id'], $teachers_role_ids); $all_assistans_role_ids = JLMS_ACL_HELPER::getAssistansRolesIds(); $assistans_role_ids = array_intersect($notification_event->selected_manager_roles, $all_assistans_role_ids); $teachers = JLMS_ACL_HELPER::getCourseTeachers($params['course_id'], $teachers_role_ids); $assistans = JLMS_ACL_HELPER::getCourseAssistans($params['course_id'], $assistans_role_ids); if (isset($teachers[0])) { foreach ($teachers as $teacher) { if (!in_array($teacher->id, $already_sent_users)) { $params['recipient'] = $teacher->email; //array( $teacher->name, $teacher->email ); $params['subject'] = $manager_template->subject; $params['body'] = $manager_template->template_html; $params['alttext'] = $manager_template->template_alt_text; $mailManager->prepareEmail($params); $mailManager->sendEmail(); $already_sent_users[] = $teacher->id; } } } if (isset($assistans[0])) { foreach ($assistans as $assistan) { if (!in_array($assistan->id, $already_sent_users)) { $params['recipient'] = $assistan->email; //array( $assistan->name, $assistan->email ); $params['subject'] = $manager_template->subject; $params['body'] = $manager_template->template_html; $params['alttext'] = $manager_template->template_alt_text; $mailManager->prepareEmail($params); $mailManager->sendEmail(); $already_sent_users[] = $assistan->id; } } } } if (isset($params['user_id']) && $params['user_id'] && isset($notification_event->selected_manager_roles[0])) { $all_CEO_role_ids = JLMS_ACL_HELPER::getCEORoleIds(); $CEO_role_ids = array_intersect($notification_event->selected_manager_roles, $all_CEO_role_ids); $all_user_CEO = JLMS_ACL_HELPER::getUserCEO($params['user_id'], $CEO_role_ids); if (isset($all_user_CEO[0])) { foreach ($all_user_CEO as $CEO) { if (!in_array($CEO->id, $already_sent_users)) { $params['recipient'] = $CEO->email; //array( $CEO->name, $CEO->email ); $params['subject'] = $manager_template->subject; $params['body'] = $manager_template->template_html; $params['alttext'] = $manager_template->template_alt_text; $mailManager->prepareEmail($params); $mailManager->sendEmail(); $already_sent_users[] = $CEO->id; } } } } if (isset($notification_event->selected_manager_roles[0])) { $all_admin_role_ids = JLMS_ACL_HELPER::getAdminsRoleIds(); $admin_role_ids = array_intersect($notification_event->selected_manager_roles, $all_admin_role_ids); $admins = JLMS_ACL_HELPER::getAdmins($admin_role_ids); if (isset($admins[0])) { foreach ($admins as $admin) { if (!in_array($admin->id, $already_sent_users)) { $params['recipient'] = $admin->email; //array( $admin->name, $admin->email ); $params['subject'] = $manager_template->subject; $params['body'] = $manager_template->template_html; $params['alttext'] = $manager_template->template_alt_text; $mailManager->prepareEmail($params); $mailManager->sendEmail(); $already_sent_users[] = $admin->id; } } } } } }
function JLMS_delete_event($option, $id) { global $JLMS_DB, $my, $Itemid, $JLMS_CONFIG; $agenda_id = intval(mosGetParam($_REQUEST, 'agenda_id', 0)); $id = $JLMS_CONFIG->get('course_id'); $JLMS_ACL =& JLMSFactory::getACL(); $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only'); $query = "SELECT is_limited, owner_id FROM `#__lms_agenda` WHERE agenda_id = {$agenda_id} AND course_id = {$id}"; $JLMS_DB->setQuery($query); $row = $JLMS_DB->loadObject(); if (is_object($row) && isset($row->is_limited)) { $flag = 0; $flag1 = 0; if ($row->is_limited == 0 && $row->owner_id != $my->id) { $flag1 = 1; } $flag = 0; if ($JLMS_ACL->CheckPermissions('announce', 'manage') && !$flag1) { $where = ''; if ($assigned_groups_only) { $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my->id, $id); //$groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($my->id, $id); //$groups_where_admin_manager = array_merge($groups_where_admin_manager,$groups_where_isset_user); if (count($groups_where_admin_manager)) { // $where .= "\n AND ( `groups` LIKE '%|$groups_where_admin_manager[0]|%'"; // for($i=1;$i<count($groups_where_admin_manager);$i++) { // $where .= "\n OR `groups` like '%|$groups_where_admin_manager[$i]|%'"; // } // $where .= "\n )"; } else { $where .= "\n AND agenda_id = 0 "; } $groups_in_db_arr = array(); $query = "SELECT groups FROM #__lms_agenda WHERE agenda_id = {$agenda_id} AND course_id = {$id}"; $JLMS_DB->setQuery($query); $groups_in_db = $JLMS_DB->LoadResult(); $query = "SELECT is_limited FROM #__lms_agenda WHERE agenda_id = {$agenda_id} AND course_id = {$id}"; $JLMS_DB->SetQuery($query); $is_limited = $JLMS_DB->LoadResult(); if ($is_limited) { if ($groups_in_db) { $groups_in_db = substr($groups_in_db, 1, strlen($groups_in_db) - 2); $groups_in_db_arr = explode('|', $groups_in_db); $groups_in_db_arr_str = implode(',', $groups_in_db_arr); $query = "SELECT id FROM #__lms_usergroups WHERE id IN ({$groups_in_db_arr_str})"; $JLMS_DB->setQuery($query); $groups_in_db_arr = $JLMS_DB->LoadResultArray(); for ($i = 0; $i < count($groups_in_db_arr); $i++) { if (!in_array($groups_in_db_arr[$i], $groups_where_admin_manager)) { $flag = 1; break; } } } } } $query = "SELECT owner_id FROM #__lms_agenda WHERE agenda_id = {$agenda_id} AND course_id = {$id}"; $JLMS_DB->SetQuery($query); $agenda_owner = $JLMS_DB->LoadResult(); $proceed_with_removal = true; if ($agenda_owner) { // if owner there if ($JLMS_ACL->CheckPermissions('announce', 'only_own') && $agenda_owner != $my->id && $flag) { $proceed_with_removal = false; } elseif ($JLMS_ACL->CheckPermissions('announce', 'only_own_role') && $JLMS_ACL->GetRole() != $JLMS_ACL->UserSystemRole($JLMS_DB, $agenda_owner)) { $proceed_with_removal = false; } } if ($proceed_with_removal && !$flag) { $query = "DELETE FROM #__lms_agenda WHERE agenda_id = {$agenda_id} AND course_id = {$id}" . $where; $JLMS_DB->setQuery($query); $JLMS_DB->query(); } } } JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=agenda&id={$id}")); }
function JLMS_deleteHW($course_id, $option) { global $my, $JLMS_DB, $Itemid; // if ( $course_id && (JLMS_GetUserType($my->id, $course_id) == 1) ) { $JLMS_ACL =& JLMSFactory::getACL(); if ($course_id && $JLMS_ACL->CheckPermissions('homework', 'manage')) { $cid = mosGetParam($_POST, 'cid', array(0)); if (!is_array($cid)) { $cid = array(0); } $i = 0; while ($i < count($cid)) { $cid[$i] = intval($cid[$i]); $i++; } $cids = implode(',', $cid); //new proverka $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only'); $query = "SELECT id, is_limited, owner_id FROM #__lms_homework WHERE id IN ({$cids})"; $JLMS_DB->setQuery($query); $rows = $JLMS_DB->loadObjectList(); $flag = 0; $array_not_delete = array(); for ($i = 0; $i < count($rows); $i++) { if ($rows[$i]->is_limited == 0 && $rows[$i]->owner_id != $my->id) { $array_not_delete[] = $rows[$i]->id; } } $flag = 0; $where = ''; if ($assigned_groups_only) { $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my->id, $course_id); $groups_in_db_arr = array(); $query = "SELECT * FROM #__lms_homework WHERE id IN ({$cids})"; $JLMS_DB->setQuery($query); $rows = $JLMS_DB->LoadObjectList(); for ($i = 0; $i < count($rows); $i++) { if ($rows[$i]->is_limited && $rows[$i]->groups) { $groups_in_db = substr($rows[$i]->groups, 1, strlen($rows[$i]->groups) - 2); $groups_in_db_arr = explode('|', $groups_in_db); $groups_in_db_arr_str = implode(',', $groups_in_db_arr); $query = "SELECT id FROM #__lms_usergroups WHERE id IN ({$groups_in_db_arr_str})"; $JLMS_DB->setQuery($query); $groups_in_db_arr = $JLMS_DB->LoadResultArray(); for ($j = 0; $j < count($groups_in_db_arr); $j++) { if (!in_array($groups_in_db_arr[$j], $groups_where_admin_manager)) { $array_not_delete[] = $rows[$i]->id; break; } } } } } // --- $cid = array_diff($cid, $array_not_delete); $cids = implode(',', $cid); $query = "SELECT id FROM #__lms_homework WHERE id IN ({$cids}) AND course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $cid = $JLMS_DB->LoadResultArray(); if (count($cid)) { $cids = implode(',', $cid); $query = "DELETE FROM #__lms_homework WHERE id IN ({$cids}) AND course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); $query = "DELETE FROM #__lms_homework_results WHERE hw_id IN ({$cids}) AND course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=homework&id={$course_id}")); }