Пример #1
0
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}&amp;Itemid={$Itemid}&amp;task=agenda&amp;id={$id}"));
}
Пример #2
0
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;
}
Пример #3
0
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}"));
}