Beispiel #1
0
 public function resolve(ResourceLocator $locator)
 {
     if ($locator->hasResourceId()) {
         $context = Claro_Context::getCurrentContext();
         $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId();
         if ($locator->inGroup()) {
             $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId();
         }
         $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId());
         // in a group
         if ($locator->inGroup()) {
             $groupData = claro_get_group_data($context);
             $path .= '/group/' . $groupData['directory'];
             $groupId = $locator->getGroupId();
         } else {
             $path .= '/document';
         }
         $path .= '/' . ltrim($locator->getResourceId(), '/');
         $resourcePath = '/' . ltrim($locator->getResourceId(), '/');
         $path = secure_file_path($path);
         if (!file_exists($path)) {
             throw new Exception("Resource not found {$path}");
         } elseif (is_dir($path)) {
             $url = new Url(get_module_entry_url('CLDOC'));
             $url->addParam('cmd', 'exChDir');
             $url->addParam('file', base64_encode($resourcePath));
             return $url->toUrl();
         } else {
             return get_module_url('CLDOC') . '/connector/cllp.frames.cnr.php';
             return claro_get_file_download_url($resourcePath, Claro_Context::getUrlContext($context));
         }
     } else {
         return get_module_entry_url('CLDOC');
     }
 }
Beispiel #2
0
 /**
  * return the tutor and the member of the group
  *
  * @return array of int: user identification
  */
 public function getRecipientList()
 {
     $userList = array();
     // add user to the list
     $userGroupList = get_group_user_list($this->groupId, $this->courseId);
     if (is_array($userGroupList)) {
         foreach ($userGroupList as $user) {
             $userList[] = $user['id'];
         }
     }
     //add tutor to the list if he exist
     $dataGroup = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $this->courseId, CLARO_CONTEXT_GROUP => $this->groupId), 'tutorId');
     if ($dataGroup['tutorId'] != 0) {
         $userList[] = $dataGroup['tutorId'];
     }
     return $userList;
 }
Beispiel #3
0
} else {
    $_tid = !empty($_SESSION['_tid']) ? $_SESSION['_tid'] : null;
    $_mainToolId = !empty($_SESSION['_mainToolId']) ? $_SESSION['_mainToolId'] : null;
    $_courseTool = !empty($_SESSION['_courseTool']) ? $_SESSION['_courseTool'] : null;
}
/*---------------------------------------------------------------------------
  Group initialisation
 ---------------------------------------------------------------------------*/
// if the requested group is different from the group in session
if ($gidReq && (!isset($_SESSION['_gid']) || $gidReq != $_SESSION['_gid'])) {
    $gidReset = true;
}
if ($gidReset || $cidReset) {
    if ($gidReq && $_cid) {
        $context = array(CLARO_CONTEXT_COURSE => $_cid, CLARO_CONTEXT_GROUP => $gidReq);
        $course_group_data = claro_get_group_data($context, true);
        $_group = $course_group_data;
        if ($_group) {
            $_gid = $course_group_data['id'];
        } else {
            claro_die('WARNING !! Undefined groupd id: the requested group ' . ' doesn\'t exist at line ' . __LINE__ . '.  ' . 'Please contact your platform administrator.');
        }
    } else {
        $_gid = null;
        $_group = null;
    }
} else {
    $_gid = !empty($_SESSION['_gid']) ? $_SESSION['_gid'] : null;
    $_group = !empty($_SESSION['_group']) ? $_SESSION['_group'] : null;
}
/*---------------------------------------------------------------------------
Beispiel #4
0
 public function getResourceList(ResourceLocator $locator)
 {
     $groupId = null;
     if ($locator->inGroup()) {
         $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $locator->getCourseId(), CLARO_CONTEXT_GROUP => $locator->getGroupId()));
         $groupId = $locator->getGroupId();
     }
     $path = $this->getPath($locator);
     if (!$this->isPathNavigable($path)) {
         throw new Exception("{$path} does not exists or is not a directory");
     } else {
         $tbl = get_module_course_tbl(array('document'), $locator->getCourseId());
         $fileProperties = array();
         if (!$locator->inGroup()) {
             $sql = "SELECT `path`, `visibility`, `comment`\n" . "FROM `{$tbl['document']}`\n" . "WHERE 1";
             $res = Claroline::getDatabase()->query($sql);
             foreach ($res as $row) {
                 $fileProperties[$row['path']] = $row;
             }
         }
         $it = new DirectoryIterator($path);
         $dirList = array();
         $fileList = array();
         foreach ($it as $file) {
             if ($file->isDir() && $file->isDot()) {
                 continue;
             }
             $relativePath = str_replace('\\', '/', str_replace($file->getPath(), '', $file->getPathname()));
             if ($locator->hasResourceId()) {
                 $relativePath = '/' . ltrim(ltrim($locator->getResourceId(), '/') . '/' . ltrim($relativePath, '/'), '/');
             }
             if ($file->isDir()) {
                 $dirList[] = $relativePath;
             } elseif ($file->isFile()) {
                 $fileList[] = $relativePath;
             }
         }
         natcasesort($dirList);
         natcasesort($fileList);
         $resourceList = new LinkerResourceIterator();
         foreach ($dirList as $relativePath) {
             $isVisible = true;
             if (array_key_exists($relativePath, $fileProperties)) {
                 $isVisible = $fileProperties[$relativePath]['visibility'] != 'i' ? true : false;
             }
             $resourceList->addResource($this->createResourceLocator($locator->getCourseId(), $relativePath, $isVisible, true, $groupId));
         }
         foreach ($fileList as $relativePath) {
             $isVisible = true;
             if (array_key_exists($relativePath, $fileProperties)) {
                 $isVisible = $fileProperties[$relativePath]['visibility'] != 'i' ? true : false;
             }
             $resourceList->addResource($this->createResourceLocator($locator->getCourseId(), $relativePath, $isVisible, false, $groupId));
         }
         return $resourceList;
     }
 }
Beispiel #5
0
 /**
  * diplay a received message
  *
  * @param ReceivedMessage $message Message to display
  * @param string $action list of action autorised on the message
  * @return string HTML source
  */
 private static function displayReceivedMessage($message, $action)
 {
     $content = '<div id="im_message">' . "\n" . '<h4 class="header">' . claro_htmlspecialchars($message->getSubject()) . '</h4>' . "\n" . '<div class="imInfoBlock">' . "\n" . '<div class="imCmdList">' . $action . '</div>' . "\n\n" . '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Sender') . ' : </span>' . "\n" . ' <span class="imInfoValue">';
     $isAllowed = current_user_is_allowed_to_send_message_to_user($message->getSender());
     if ($isAllowed) {
         $content .= '<a href="sendmessage.php?cmd=rqMessageToUser&amp;userId=' . $message->getSender() . '">';
     }
     $content .= get_lang('%firstName %lastName', array('%firstName' => claro_htmlspecialchars($message->getSenderFirstName()), '%lastName' => claro_htmlspecialchars($message->getSenderLastName())));
     if ($isAllowed) {
         $content .= "</a>";
     }
     $isManager = FALSE;
     $isAdmin = claro_is_user_platform_admin($message->getSender());
     if (!is_null($message->getCourseCode())) {
         $isManager = claro_is_user_course_manager($message->getSender(), $message->getCourseCode());
     }
     if ($isManager) {
         $content .= '&nbsp;<img src="' . get_icon_url('manager') . '" alt="" />';
     } elseif ($isAdmin) {
         $content .= '&nbsp;<img src="' . get_icon_url('platformadmin') . '" alt="" />';
     } else {
         $content .= '&nbsp;<img src="' . get_icon_url('user') . '" alt="" />';
     }
     $content .= '' . ' </span>' . "\n" . '</div>' . "\n\n" . '<div class="imInfo">' . "\n" . '<span class="imInfoTitle">' . get_lang('Date') . ' : </span>' . "\n" . '<span class="imInfoValue">' . claro_html_localised_date(get_locale('dateTimeFormatLong'), strtotime($message->getSendTime())) . '</span>' . "\n" . '</div>' . "\n\n";
     if (!is_null($message->getCourseCode())) {
         $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Course') . '</span>' . "\n" . ' <span class="imInfoValue">' . "\n";
         $courseData = claro_get_course_data($message->getCourseCode());
         if ($courseData) {
             $content .= claro_htmlspecialchars($courseData['officialCode']) . ' - ' . claro_htmlspecialchars($courseData['name']);
         } else {
             $content .= '?';
         }
         $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         if (!is_null($message->getGroupId())) {
             $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Group') . ' : </span>' . "\n" . ' <span class="imInfoValue">' . "\n";
             $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $message->getCourseCode(), CLARO_CONTEXT_GROUP => $message->getGroupId()));
             if ($groupData) {
                 $content .= $groupData['name'];
             } else {
                 $content .= '?';
             }
             $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         }
         if (!is_null($message->getToolsLabel())) {
             $content .= '<div class="imInfo">' . "\n" . ' <span class="imInfoTitle">' . get_lang('Tool') . ' : </span>' . "\n" . ' <span class="imInfoValue">' . "\n";
             $md = get_module_data($message->getToolsLabel());
             if ($md) {
                 $content .= get_lang($md['moduleName']);
             } else {
                 $content .= '?';
             }
             $content .= ' </span>' . "\n" . '</div>' . "\n\n";
         }
     }
     $body = $message->getMessage();
     $body = claro_html_sanitize_all($body);
     $content .= '</div>' . "\n" . '<div class="imContent">' . claro_parse_user_text($body) . '</div>' . "\n" . '</div>' . "\n\n";
     return $content;
 }
Beispiel #6
0
            }
        }
        $content .= ' <a href="readmessage.php?messageId=' . $message->getId() . '&amp;type=sent&amp;userId=' . $currentUserId . '">';
        $content .= claro_htmlspecialchars($message->getSubject()) . '</a></td>' . "\n" . '<td>';
        if ($recipientList['sentTo'] == 'toUser') {
            $content .= claro_htmlspecialchars($recipientList['userList'][0]['firstName']) . " " . claro_htmlspecialchars($recipientList['userList'][0]['lastName']);
            if (count($recipientList['userList']) > 1) {
                $content .= ", " . claro_htmlspecialchars($recipientList['userList'][1]['firstName']) . " " . claro_htmlspecialchars($recipientList['userList'][1]['lastName']);
            }
            if (count($recipientList['userList']) > 2) {
                $content .= ",...";
            }
        } elseif ($recipientList['sentTo'] == 'toCourse') {
            $content .= get_lang('Course: ') . " " . $message->getCourseCode();
        } elseif ($recipientList['sentTo'] == 'toGroup') {
            $groupInfo = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $message->getCourseCode(), CLARO_CONTEXT_GROUP => $message->getGroupId()));
            $courseInfo = claro_get_course_data($message->getCourseCode());
            if (!$groupInfo) {
                $content .= get_lang('Course') . ' : ' . get_lang('unknown') . "; " . get_lang('Group') . ' : ' . get_lang('unknown');
            } else {
                $content .= get_lang('Course') . ' : ' . $courseInfo['officialCode'] . "; " . get_lang('Group') . ' : ' . $groupInfo['name'];
            }
        } elseif ($message->isPlatformMessage()) {
            $content .= get_lang('All users of the platform');
        } else {
            $content .= get_lang('Unknown recipient');
        }
        $content .= '</td>' . '<td>' . claro_html_localised_date(get_locale('dateTimeFormatLong'), strtotime($message->getSendTime())) . '</td>' . "\n";
        $content .= '</tr>' . "\n\n";
    }
}
Beispiel #7
0
 public function getResourceName(ResourceLocator $locator)
 {
     $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $locator->getCourseId(), CLARO_CONTEXT_GROUP => $locator->getGroupId()));
     return $groupData['name'];
 }
Beispiel #8
0
/**
 * Get the path of a group in a course.
 * @param  array $context
 * @return string path
 * @author Christophe Gesche <*****@*****.**>
 * @var $gData use to get groupdata
 * @since 1.8.1
 */
function claro_get_course_group_path($context)
{
    if (is_array($context) && array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
        $cid = $context[CLARO_CONTEXT_COURSE];
    }
    $coursePath = claro_get_course_path($cid);
    $gData = claro_get_group_data($context);
    if (isset($gData['directory'])) {
        return $coursePath . '/group/' . $gData['directory'];
    } else {
        return NULL;
    }
}
Beispiel #9
0
function chat_upgrade_to_19($course_code)
{
    global $currentCourseVersion;
    $versionRequiredToProceed = '/^1.8/';
    $tool = 'CLCHT';
    $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
    if (preg_match($versionRequiredToProceed, $currentCourseVersion)) {
        $coursePath = get_path('coursesRepositorySys') . claro_get_course_path($course_code);
        $courseChatPath = $coursePath . '/chat/';
        $toolId = get_tool_id_from_module_label('CLCHAT');
        if (!$toolId) {
            // get out of here if new chat module is missing
            log_message('New Chat module not found : keep the old one !');
            $step = set_upgrade_status($tool, 0, $course_code);
            return $step;
        }
        // On init , $step = 1
        switch ($step = get_upgrade_status($tool, $course_code)) {
            case 1:
                // get all chat files
                log_message("Search in " . $courseChatPath);
                if (!file_exists($courseChatPath)) {
                    log_message("Cannot save chat : folder {$courseChatPath} does not exists");
                    $error = true;
                } else {
                    try {
                        $it = new DirectoryIterator($courseChatPath);
                        $error = false;
                        foreach ($it as $file) {
                            if (!$file->isFile()) {
                                continue;
                            }
                            if ($file->getFilename() == $course_code . '.chat.html') {
                                // chat de cours
                                log_message("Try to export course chat : " . $file->getFilename());
                                $exportFileDir = $coursePath . '/document/recovered_chat/';
                                $groupId = null;
                            } else {
                                // group chat
                                log_message("Try to export group chat : " . $file->getFilename());
                                // get groupId
                                $matches = array();
                                preg_match('/\\w+\\.(\\d+)\\.chat\\.html/', $file->getFilename(), $matches);
                                if (isset($matches[1])) {
                                    $groupId = (int) $matches[1];
                                } else {
                                    log_message('Cannot find group id in chat filename : ' . $file->getFilename());
                                    break;
                                }
                                if (!($groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $course_code, CLARO_CONTEXT_GROUP => $groupId)))) {
                                    // group cannot be found, save in document
                                    $exportFileDir = $coursePath . '/document/recovered_chat/';
                                    log_message('Cannot find group so save chat filename in course : ' . $file->getFilename());
                                } else {
                                    $exportFileDir = $coursePath . '/group/' . $groupData['directory'] . '/recovered_chat/';
                                }
                            }
                            // create dire
                            claro_mkdir($exportFileDir, CLARO_FILE_PERMISSIONS, true);
                            // try to find a unique filename
                            $fileNamePrefix = 'chat.' . date('Y-m-j') . '_';
                            if (!is_null($groupId)) {
                                $fileNamePrefix .= $groupId . '_';
                            }
                            $i = 1;
                            while (file_exists($exportFileDir . $fileNamePrefix . $i . '.html')) {
                                $i++;
                            }
                            $savedFileName = $fileNamePrefix . $i . '.html';
                            // prepare output
                            $out = '<html>' . '<head>' . '<title>Discussion - archive</title>' . '</head>' . '<body>' . file_get_contents($file->getPathname()) . '</body>' . '</html>';
                            // write to file
                            if (!file_put_contents($exportFileDir . $savedFileName, $out)) {
                                log_message('Cannot save chat : ' . $exportFileDir . $savedFileName);
                                $error = true;
                            }
                        }
                    } catch (Exception $e) {
                        log_message('Cannot save chat : ' . $e->getMessage());
                        $error = true;
                    }
                }
                // save those with group id in group space
                if (!$error) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
            case 2:
                // activate new chat in each course
                $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
                if (!register_module_in_single_course($toolId, $course_code)) {
                    log_message("register_module_in_single_course( {$toolId}, {$course_code} ) failed");
                    return $step;
                }
                $sqlForUpdate[] = "UPDATE `" . $currentCourseDbNameGlu . "tool_list`\n                SET `activated` = 'true',\n                    `installed` = 'false'\n                WHERE tool_id = " . (int) $toolId;
                if (upgrade_apply_sql($sqlForUpdate)) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
                unset($sqlForUpdate);
            default:
                $step = set_upgrade_status($tool, 0, $course_code);
                return $step;
        }
    }
    return false;
}