示例#1
0
function JLMS_edit_event($option, $id)
{
    global $JLMS_DB, $Itemid, $my, $JLMS_CONFIG;
    $id = $JLMS_CONFIG->get('course_id');
    $agenda_id = intval(mosGetParam($_REQUEST, 'agenda_id', 0));
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $AND_ST = "";
    if (false !== ($enroll_period = JLMS_getEnrolPeriod($my->id, $id))) {
        $AND_ST = " AND IF(is_time_related, (show_period < '" . $enroll_period . "' ), 1) ";
    }
    $do_redirect = false;
    $query = "SELECT is_limited, owner_id FROM `#__lms_agenda` WHERE agenda_id = {$agenda_id} AND course_id = {$id}" . $AND_ST;
    $JLMS_DB->setQuery($query);
    $row = $JLMS_DB->loadObject();
    if (is_object($row) && isset($row->is_limited)) {
        $flag = 0;
        if ($row->is_limited == 0 && $row->owner_id != $my->id) {
            $flag = 1;
        }
    } else {
        $do_redirect = true;
    }
    if ($id && $JLMS_ACL->CheckPermissions('announce', 'manage') && !$flag) {
        $where = '';
        if ($assigned_groups_only && $row->is_limited) {
            $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 is_limited = 1 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 OR owner_id = '" . $my->id . "')";
            } else {
                $where .= "\n AND (owner_id = '" . $my->id . "' OR agenda_id = 0) AND groups = ''";
            }
        }
        $query = "SELECT * FROM `#__lms_agenda` WHERE agenda_id = {$agenda_id} AND course_id = {$id}" . $where;
        $JLMS_DB->setQuery($query);
        $agenda_item = $JLMS_DB->loadObject();
        if (is_object($agenda_item) && isset($agenda_item->agenda_id)) {
            if ($JLMS_ACL->CheckPermissions('announce', 'only_own') && $agenda_item->owner_id != $my->id) {
                $do_redirect = true;
            } elseif ($JLMS_ACL->CheckPermissions('announce', 'only_own_role') && $JLMS_ACL->GetRole() != $JLMS_ACL->UserSystemRole($JLMS_DB, $agenda_item->owner_id)) {
                $do_redirect = true;
            } else {
                $groups_arr = array();
                if ($agenda_item->groups) {
                    $groups = substr($agenda_item->groups, 1, strlen($agenda_item->groups) - 2);
                    $groups_arr = explode('|', $groups);
                }
                if ($assigned_groups_only) {
                    $lists['is_limited'] = mosHTML::yesnoRadioList('is_limited', 'disabled="disabled" class="inputbox" ', $agenda_item->is_limited);
                } else {
                    $lists['is_limited'] = mosHTML::yesnoRadioList('is_limited', 'class="inputbox" ', $agenda_item->is_limited);
                }
                $lists['groups'] = JLMSmultiselect($groups_arr, true, $id);
                JLMS_agenda_html::show_add_event($id, $option, $agenda_item, $lists);
            }
        } else {
            $do_redirect = true;
        }
    } else {
        $do_redirect = true;
    }
    if ($do_redirect) {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=agenda&id={$id}"));
    }
}
function JLMS_editHW($id, $course_id, $option)
{
    global $my, $JLMS_DB, $Itemid;
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    //	if ( $course_id && (JLMS_GetUserType($my->id, $course_id) == 1) && ( ($id && (JLMS_GetHWCourse($id) == $course_id)) || !$id ) ) {
    if ($course_id && $JLMS_ACL->CheckPermissions('homework', 'manage') && ($id && JLMS_GetHWCourse($id) == $course_id || !$id)) {
        $AND_ST = "";
        /*
        if( false !== ( $enroll_period = JLMS_getEnrolPeriod( $my->id, $course_id )) ) 
        {
        	$AND_ST = " AND IF(is_time_related, (show_period < '".$enroll_period."' ), 1) ";	
        }
        */
        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)) {
                $AND_ST .= "\n AND (is_limited = 0 OR groups LIKE '%|{$groups_where_admin_manager['0']}|%'";
                for ($i = 1; $i < count($groups_where_admin_manager); $i++) {
                    $AND_ST .= "\n OR groups like '%|{$groups_where_admin_manager[$i]}|%'";
                }
                $AND_ST .= "\n OR owner_id = '" . $my->id . "')";
            } else {
                $AND_ST .= "\n AND (is_limited = 0 OR owner_id = '" . $my->id . "' OR id = 0) AND groups = ''";
            }
        }
        $row = new mos_Joomla_LMS_HomeWork($JLMS_DB);
        $row->addCond($AND_ST);
        $row->load($id);
        $lists = array();
        $groups_arr = array();
        $groups_where_admin_manager = array(59, 69, 71);
        if ($row->groups) {
            $groups = substr($row->groups, 1, strlen($row->groups) - 2);
            $groups_arr = explode('|', $groups);
        } else {
            if (!$row->groups && $groups_where_admin_manager) {
                $groups_arr = $groups_where_admin_manager;
            }
        }
        $lists['groups'] = JLMSmultiselect($groups_arr, true, $course_id);
        if ($assigned_groups_only) {
            //$lists['is_limited'] = mosHTML::yesnoRadioList( 'is_limited', 'disabled="disabled" class="inputbox" ', ($id?$row->is_limited:1));
            $lists['is_limited'] = '';
        } else {
            $lists['is_limited'] = mosHTML::yesnoRadioList('is_limited', 'class="inputbox" ', $row->is_limited);
        }
        $lists['published'] = mosHTML::yesnoRadioList('published', 'class="inputbox" ', $row->published);
        $activity_type[] = mosHTML::makeOption(1, _JLMS_HW_OFFLINE_ACTIVITY);
        $activity_type[] = mosHTML::makeOption(2, _JLMS_HW_WRITE_TEXT);
        $activity_type[] = mosHTML::makeOption(3, _JLMS_HW_UPLOAD_FILE);
        $lists['activity_type'] = mosHTML::selectList($activity_type, 'activity_type', 'class="inputbox" size="1"', 'value', 'text', $row->activity_type);
        $lists['graded_activity'] = mosHTML::yesnoRadioList('graded_activity', 'class="inputbox" ', $row->graded_activity);
        if ($assigned_groups_only) {
            $params['hidden_is_time_related'] = '<input type="hidden" name="is_limited" value="' . ($id ? $row->is_limited : 1) . '">';
        }
        JLMS_homework_html::showEditHW($row, $lists, $option, $course_id, $params);
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=homework&id={$course_id}"));
    }
}