Exemple #1
0
/**
 * @param array $workInfo
 * @param array $values
 * @param array $courseInfo
 * @param int $sessionId
 * @param int $groupId
 * @param int $userId
 * @return null|string
 */
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId)
{
    $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);

    $courseId = $courseInfo['real_id'];
    $groupId = intval($groupId);
    $sessionId = intval($sessionId);
    $userId = intval($userId);

    $title  = $values['title'];
    $description = $values['description'];
    $contains_file = isset($values['contains_file']) && !empty($values['contains_file']) ? intval($values['contains_file']): 0;

    $saveWork = true;
    $message = null;
    $filename = null;
    $url = null;

    if ($values['contains_file']) {
        $result = uploadWork($workInfo, $courseInfo);
        if (isset($result['error'])) {
            $message = $result['error'];
            $saveWork = false;
        }
        $filename = isset($result['filename']) ? $result['filename'] : null;
        if (empty($title)) {
            $title = isset($result['title']) && !empty($result['title']) ? $result['title'] : get_lang('Untitled');
        }
        $url = $result['url'];
    }

    if (empty($title)) {
        $title = get_lang('Untitled');
    }

    if ($saveWork) {
        $active = '1';
        $sql = "INSERT INTO ".$work_table." SET
                   c_id         = $courseId ,
                   url          = '".$url . "',
                   title        = '".Database::escape_string($title)."',
                   description  = '".Database::escape_string($description)."',
                   contains_file = '".$contains_file."',
                   active       = '".$active."',
                   accepted     = '1',
                   post_group_id = '".$groupId."',
                   sent_date    =  '".api_get_utc_datetime()."',
                   parent_id    =  '".$workInfo['id']."' ,
                   session_id   = '".$sessionId."',
                   user_id      = '".$userId."'";

        Database::query($sql);
        $workId = Database::insert_id();

        if ($workId) {
            if (array_key_exists('filename', $workInfo) && !empty($filename)) {
                $filename = Database::escape_string($filename);
                $sql = "UPDATE $work_table SET
                            filename = '$filename'
                        WHERE c_id = $courseId AND id = $workId";
                Database::query($sql);
            }

            if (array_key_exists('document_id', $workInfo)) {
                $documentId = isset($values['document_id']) ? intval($values['document_id']) : 0;
                $sql = "UPDATE $work_table SET
                            document_id = '$documentId'
                        WHERE c_id = $courseId AND id = $workId";
                Database::query($sql);
            }
            api_item_property_update(
                $courseInfo,
                'work',
                $workId,
                'DocumentAdded',
                $userId,
                $groupId
            );
            sendAlertToTeacher($workId, $courseInfo, $sessionId);
            event_upload($workId, $userId, $courseInfo['code'], $sessionId);
            $message = Display::return_message(get_lang('DocAdd'));
        }
    } else {
        if (empty($message)) {
            $message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
        }
    }

    return $message;
}
Exemple #2
0
            }
            $subject = "[" . api_get_setting('siteName') . "] " . get_lang('SendMailBody') . "\n" . get_lang('CourseName') . " : " . $_course['name'] . "  ";
            foreach ($user_list as $user_data) {
                $to_user_id = $user_data['user_id'];
                $emailbody = get_lang('SendMailBody') . "\n" . get_lang('CourseName') . " : " . $_course['name'] . "\n";
                $user_info = api_get_user_info($user_id);
                $emailbody .= get_lang('UserName') . " : " . api_get_person_name($user_info['firstname'], $user_info['lastname']) . "\n";
                $emailbody .= get_lang('DateSent') . " : " . api_format_date(api_get_local_time()) . "\n";
                $emailbody .= get_lang('WorkName') . " : " . $title . "\n\n" . get_lang('DownloadLink') . "\n";
                $url = api_get_path(WEB_CODE_PATH) . "work/work.php?" . api_get_cidreq() . "&id=" . $work_id;
                $emailbody .= $url;
                MessageManager::send_message_simple($to_user_id, $subject, $emailbody);
            }
        }
        $message = get_lang('DocAdd');
        event_upload($id);
        $error_message .= Display::return_message(get_lang('DocAdd'));
        $script = 'work_list.php';
        if ($is_allowed_to_edit) {
            $script = 'work_list_all.php';
        }
        header('Location: ' . api_get_path(WEB_CODE_PATH) . 'work/' . $script . '?' . api_get_cidreq() . '&id=' . $work_id . '&error_message=' . $error_message);
        exit;
    }
}
$htmlHeadXtra[] = to_javascript_work();
Display::display_header(null);
if (!empty($work_id)) {
    echo $message;
    if ($is_allowed_to_edit) {
        if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {