$search_this = "folder_moved_from_session_id_{$origin_session_id}";
 $search_this2 = $parent_data['url'];
 $sql = "SELECT * FROM {$TBL_STUDENT_PUBLICATION}\n                            \t\tWHERE description like '%{$search_this}%' AND url LIKE '%{$search_this2}%' AND session_id = {$new_session_id} AND c_id = {$course_id}\n                            \t\tORDER BY id desc  LIMIT 1";
 if ($debug) {
     echo $sql;
 }
 $sub_res = Database::query($sql);
 $num_rows = Database::num_rows($sub_res);
 if ($num_rows > 0) {
     $new_result = Database::fetch_array($sub_res, 'ASSOC');
     $created_dir = $new_result['url'];
     $new_parent_id = $new_result['id'];
 } else {
     if ($update_database) {
         $dir_name = substr($parent_data['url'], 1);
         $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
         $created_dir = '/' . $created_dir;
         $now = api_get_utc_datetime();
         //Creating directory
         $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET\n                                           url         = '" . $created_dir . "',\n\t                                       c_id        = {$course_id},\n\t                                       title        = '" . $parent_data['title'] . "',\n\t                                       description  = '" . $parent_data['description'] . " folder_moved_from_session_id_{$origin_session_id} ',\n\t                                       author       = '',\n\t                                       active       = '0',\n\t                                       accepted     = '1',\n\t                                       filetype     = 'folder',\n\t                                       sent_date    = '" . $now . "',\n\t                                       qualification    = '" . $parent_data['qualification'] . "',\n\t                                       parent_id    = '',\n\t                                       qualificator_id  = '',\n\t                                       date_of_qualification    = '0000-00-00 00:00:00',\n\t                                       session_id   = " . $new_session_id;
         $rest_insert = Database::query($sql_add_publication);
         if ($debug) {
             echo $sql_add_publication;
         }
         // add the directory
         $id = Database::insert_id();
         //Folder created
         api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id());
         if ($debug) {
             var_dump($rest_insert);
         }
 $session_id = intval($work['session_id']);
 $group_id = intval($work['post_group_id']);
 $work_key = $session_id . $group_id;
 $dir_name = "default_tasks_" . $group_id . "_" . $session_id;
 // Only create the folder once
 if (!isset($work_dir_created[$work_key])) {
     // 2.1 Creating a new work folder:
     $sql = "INSERT INTO {$work_table} SET\n                                        c_id                = '{$courseId}',\n                                        url         \t\t= 'work/" . $dir_name . "',\n                                        title               = 'Tasks',\n                                        description \t\t= '',\n                                        author      \t\t= '',\n                                        active              = '1',\n                                        accepted\t\t\t= '1',\n                                        filetype            = 'folder',\n                                        post_group_id       = '{$group_id}',\n                                        sent_date           = '" . $today . "',\n                                        parent_id           = '0',\n                                        qualificator_id     = '',\n                                        user_id \t\t\t= '" . $user_id . "'";
     $mainConnection->executeQuery($sql);
     $id = $mainConnection->lastInsertId();
     //2.2 Adding the folder in item property
     if ($id) {
         $sql = "INSERT INTO {$item_table} (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_group_id, visibility, id_session)\n                                            VALUES ('{$courseId}', 'work','{$id}','{$today}', '{$user_id}', '{$today}', 'DirectoryCreated','{$user_id}', '{$group_id}', '1', '{$session_id}')";
         $mainConnection->executeQuery($sql);
         $work_dir_created[$work_key] = $id;
         create_unexisting_work_directory($base_work_dir, $dir_name, $portalSettings);
         $final_dir = $base_work_dir . '/' . $dir_name;
     }
 } else {
     $final_dir = $base_work_dir . '/' . $dir_name;
 }
 // 2.3 Updating the url
 if (!empty($work_dir_created[$work_key])) {
     $parent_id = $work_dir_created[$work_key];
     $new_url = "work/" . $dir_name . '/' . basename($work['url']);
     $sql = "UPDATE {$work_table} SET\n                                            url = '{$new_url}',\n                                            parent_id = {$parent_id},\n                                            contains_file = '1'\n                                        WHERE id = {$work['id']} AND c_id = {$courseId}";
     $mainConnection->executeQuery($sql);
     if (is_dir($final_dir)) {
         rename($course_dir . '/' . $work['url'], $course_dir . '/' . $new_url);
     }
 }
Exemple #3
0
/**
 * Creates a new task (directory) in the assignment tool
 * @param array $params
 * @param int $user_id
 * @param array $courseInfo
 * @param int $group_id
 * @param int $session_id
 * @return bool|int
 * @note $params can have the following elements, but should at least have the 2 first ones: (
 *       'new_dir' => 'some-name',
 *       'description' => 'some-desc',
 *       'qualification' => 20 (e.g. 20),
 *       'weight' => 50 (percentage) to add to gradebook (e.g. 50),
 *       'allow_text_assignment' => 0/1/2,
 * @todo Rename createAssignment or createWork, or something like that
 */
function addDir($params, $user_id, $courseInfo, $group_id, $session_id)
{
    $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);

    $user_id = intval($user_id);
    $group_id = intval($group_id);
    $session_id = intval($session_id);

    $base_work_dir = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work';
    $course_id = $courseInfo['real_id'];

    $directory = replace_dangerous_char($params['new_dir']);
    $directory = disable_dangerous_file($directory);
    $created_dir = create_unexisting_work_directory($base_work_dir, $directory);

    if (!empty($created_dir)) {
        $dirName = '/'.$created_dir;
        $today = api_get_utc_datetime();
        $sql = "INSERT INTO " . $work_table . " SET
                c_id                = $course_id,
                url                 = '".Database::escape_string($dirName)."',
                title               = '".Database::escape_string($params['new_dir'])."',
                description         = '".Database::escape_string($params['description'])."',
                author              = '',
                active              = '1',
                accepted            = '1',
                filetype            = 'folder',
                post_group_id       = '".$group_id."',
                sent_date           = '".$today."',
                qualification       = '".(($params['qualification'] != '') ? Database::escape_string($params['qualification']) : '') ."',
                parent_id           = '',
                qualificator_id     = '',
                date_of_qualification   = '0000-00-00 00:00:00',
                weight              = '".Database::escape_string($params['weight'])."',
                session_id          = '".$session_id."',
                allow_text_assignment = '".Database::escape_string($params['allow_text_assignment'])."',
                contains_file       = 0,
                user_id             = '".$user_id."'";

        Database::query($sql);

        // Add the directory
        $id = Database::insert_id();

        if ($id) {
            // Folder created
            api_item_property_update(
                $courseInfo,
                'work',
                $id,
                'DirectoryCreated',
                $user_id,
                $group_id
            );
            updatePublicationAssignment($id, $params, $courseInfo, $group_id);

            if (api_get_course_setting('email_alert_students_on_new_homework') == 1) {
                send_email_on_homework_creation(api_get_course_id());
            }
            return $id;
        }
    }
    return false;
}
Exemple #4
0
/**
 * Creates a new task (directory) in the assignment tool
 * @param array $params
 * @param int $user_id
 * @param array $courseInfo
 * @param int $group_id
 * @param int $session_id
 * @return bool|int
 * @note $params can have the following elements, but should at least have the 2 first ones: (
 *       'new_dir' => 'some-name',
 *       'description' => 'some-desc',
 *       'qualification' => 20 (e.g. 20),
 *       'weight' => 50 (percentage) to add to gradebook (e.g. 50),
 *       'allow_text_assignment' => 0/1/2,
 * @todo Rename createAssignment or createWork, or something like that
 */
function addDir($formValues, $user_id, $courseInfo, $group_id, $session_id)
{
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $user_id = intval($user_id);
    $group_id = intval($group_id);
    $session_id = intval($session_id);
    $base_work_dir = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/work';
    $course_id = $courseInfo['real_id'];
    $directory = api_replace_dangerous_char($formValues['new_dir']);
    $directory = disable_dangerous_file($directory);
    $created_dir = create_unexisting_work_directory($base_work_dir, $directory);
    if (!empty($created_dir)) {
        $dirName = '/' . $created_dir;
        $today = api_get_utc_datetime();
        $params = ['c_id' => $course_id, 'url' => $dirName, 'title' => $formValues['new_dir'], 'description' => $formValues['description'], 'author' => '', 'active' => '1', 'accepted' => '1', 'filetype' => 'folder', 'post_group_id' => $group_id, 'sent_date' => $today, 'qualification' => $formValues['qualification'] != '' ? $formValues['qualification'] : '', 'parent_id' => '', 'qualificator_id' => '', 'weight' => $formValues['weight'], 'session_id' => $session_id, 'allow_text_assignment' => $formValues['allow_text_assignment'], 'contains_file' => 0, 'user_id' => $user_id];
        $id = Database::insert($work_table, $params);
        if ($id) {
            $sql = "UPDATE {$work_table} SET id = iid WHERE iid = {$id}";
            Database::query($sql);
            // Folder created
            api_item_property_update($courseInfo, 'work', $id, 'DirectoryCreated', $user_id, $group_id);
            updatePublicationAssignment($id, $formValues, $courseInfo, $group_id);
            if (api_get_course_setting('email_alert_students_on_new_homework') == 1) {
                send_email_on_homework_creation($course_id, $session_id, $id);
            }
            return $id;
        }
    }
    return false;
}