/**
  * Returns a single resquested announce.
  * @param array $args must contain 'resID' key with the resource identifier of the requested resource
  * @throws InvalidArgumentException if one of the paramaters is missing
  * @webservice{/module/MOBILE/CLANN/getSingleResource/cidReq/resId}
  * @ws_arg{Method,getSingleResource}
  * @ws_arg{cidReq,SYSCODE of requested cours}
  * @ws_arg{resID,Resource Id of requested resource}
  * @return announce object (can be null if not visible for the current user)
  */
 function getSingleResource($args)
 {
     $resourceId = isset($args['resID']) ? $args['resID'] : null;
     $cid = claro_get_current_course_id();
     if ($cid == null || $resourceId == null) {
         throw new InvalidArgumentException('Missing cid or resourceId argument!');
     }
     $claroNotification = Claroline::getInstance()->notification;
     $date = $claroNotification->getLastActionBeforeLoginDate(claro_get_current_user_id());
     $d = new DateTime($date);
     $d->sub(new DateInterval('PT1M'));
     From::Module('CLANN')->uses('announcement.lib');
     if ($announce = $this->announcement_get_item($resourceId, $cid)) {
         $notified = $claroNotification->isANotifiedRessource($cid, $date, claro_get_current_user_id(), claro_get_current_group_id(), get_tool_id_from_module_label('CLANN'), $announce['id'], false);
         $announce['visibility'] = $announce['visibility'] != 'HIDE';
         $announce['content'] = trim(strip_tags($announce['content']));
         $announce['cours']['sysCode'] = $cid;
         $announce['resourceId'] = $announce['id'];
         $announce['date'] = $announce['time'];
         $announce['notifiedDate'] = $notified ? $date : $announce['time'];
         $announce['seenDate'] = $d->format('Y-m-d H:i');
         unset($announce['id']);
         return claro_is_allowed_to_edit() || $announce['visibility'] ? $announce : null;
     } else {
         throw new RuntimeException('Resource not found', 404);
     }
 }
Beispiel #2
0
    public function renderContent()
    {
        $output = '';
        $course = claro_get_current_course_data();
        $course['db'] = $course['dbName'];
        $toolId = get_tool_id_from_module_label('CLANN');
        if (is_module_installed_in_course('CLANN', claro_get_current_course_id()) && is_tool_activated_in_course($toolId, claro_get_current_course_id()) && claro_is_tool_visible($toolId, claro_get_current_course_id())) {
            $announcementList = announcement_get_course_item_list_portlet($course);
            // Manage announcement's datas
            if ($announcementList) {
                $output .= '<dl id="portletAnnouncements">' . "\n";
                $i = 0;
                foreach ($announcementList as $announcementItem) {
                    // Generate announcement URL
                    $announcementItem['url'] = get_path('url') . '/claroline/announcements/announcements.php?cidReq=' . $course['sysCode'];
                    // Generate announcement title and content
                    $announcementItem['title'] = trim(strip_tags($announcementItem['title']));
                    if ($announcementItem['title'] == '') {
                        $announcementItem['title'] = substr($announcementItem['title'], 0, 60) . (strlen($announcementItem['title']) > 60 ? ' (...)' : '');
                    }
                    $announcementItem['content'] = trim(strip_tags($announcementItem['content']));
                    if ($announcementItem['content'] == '') {
                        $announcementItem['content'] = substr($announcementItem['content'], 0, 60) . (strlen($announcementItem['content']) > 60 ? ' (...)' : '');
                    }
                    // Don't display hidden and expired elements
                    $isVisible = (bool) ($announcementItem['visibility'] == 'SHOW') ? 1 : 0;
                    $isOffDeadline = (bool) (isset($announcementItem['visibleFrom']) && strtotime($announcementItem['visibleFrom']) > time() || isset($announcementItem['visibleUntil']) && time() >= strtotime($announcementItem['visibleUntil'])) ? 1 : 0;
                    // Prepare the render
                    $displayChar = 250;
                    if (strlen($announcementItem['content']) > $displayChar) {
                        $content = substr($announcementItem['content'], 0, $displayChar) . '... <a href="' . claro_htmlspecialchars(Url::Contextualize($announcementItem['url'])) . '">' . '<b>' . get_lang('Read more &raquo;') . '</b></a>';
                    } else {
                        $content = $announcementItem['content'];
                    }
                    if ($isVisible && !$isOffDeadline) {
                        $output .= '<dt>' . "\n" . '<h2> ' . '<a href="' . $announcementItem['url'] . '#item' . $announcementItem['id'] . '">' . (!empty($announcementItem['title']) ? $announcementItem['title'] : get_lang('No title')) . '</a></h2>' . "\n" . '</dt>' . "\n" . '<dd' . ($i == count($announcementList) - 1 ? ' class="last"' : '') . '>' . "\n" . $content . "\n" . (claro_is_allowed_to_edit() ? '<div class="manageTools"><a
                                        href="' . claro_htmlspecialchars(Url::Contextualize(get_module_url('CLANN') . '/announcements.php?cmd=rqEdit&id=' . $announcementItem['id'])) . '"
                                        title="' . get_lang('Edit this item') . '">
                                        <img src="' . get_icon_url('edit') . '" alt="' . get_lang('Edit') . '" />
                                    </a>

                                    <a
                                        href="' . claro_htmlspecialchars(Url::Contextualize(get_module_url('CLANN') . '/announcements.php?cmd=exDelete&id=' . $announcementItem['id'])) . '"
                                        title="' . get_lang('Delete this item') . '">
                                        <img src="' . get_icon_url('delete') . '" alt="' . get_lang('Delete') . '" />
                                    </a></div>' : '') . '</dd>' . "\n";
                    }
                    $i++;
                }
                $output .= '</dl>';
            } else {
                $output .= "\n" . '<dl>' . "\n" . '<dt></dt>' . "\n" . '<dd class="last">' . ' ' . get_lang('No announcement') . "\n" . '</dd>' . "\n" . '</dl>' . "\n\n";
            }
        }
        return $output;
    }
Beispiel #3
0
 protected function isModuleAllowed()
 {
     $moduleData = get_module_data($this->moduleLabel);
     if ($moduleData['type'] == 'tool') {
         $contextList = get_module_context_list($this->moduleLabel);
         if (claro_is_in_a_course()) {
             $_mainToolId = get_tool_id_from_module_label($this->moduleLabel);
             $_profileId = claro_get_current_user_profile_id_in_course();
             $_cid = claro_get_current_course_id();
             if (claro_is_in_a_group()) {
                 $_groupProperties = claro_get_main_group_properties(claro_get_current_course_id());
                 $_mainToolId = get_tool_id_from_module_label('CLGRP');
                 $is_toolAllowed = array_key_exists($this->moduleLabel, $_groupProperties['tools']) && $_groupProperties['tools'][$this->moduleLabel] && claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid);
                 if ($_groupProperties['private']) {
                     $is_toolAllowed = $is_toolAllowed && (claro_is_group_member() || claro_is_group_tutor());
                 }
                 $is_toolAllowed = $is_toolAllowed || (claro_is_course_manager() || claro_is_platform_admin());
             } else {
                 // we ignore course visibility
                 if (!claro_is_allowed_tool_edit($_mainToolId, $_profileId, $_cid) && !claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid)) {
                     $is_toolAllowed = false;
                 } else {
                     $is_toolAllowed = true;
                 }
             }
         } else {
             if (in_array('platform', iterator_to_array($contextList))) {
                 $is_toolAllowed = get_module_data($this->moduleLabel, 'activation') == 'activated';
             } else {
                 $is_toolAllowed = false;
             }
         }
         return $is_toolAllowed;
     } else {
         // if an applet "tool", return true if activated
         // and let module manage it's access by itself
         return $moduleData['activation'] == 'activated';
     }
 }
Beispiel #4
0
function announcement_get_items_portlet($personnalCourseList)
{
    $courseDigestList = array();
    $clannToolId = get_tool_id_from_module_label('CLANN');
    foreach ($personnalCourseList as $thisCourse) {
        if (is_module_installed_in_course_lightversion('CLANN', $thisCourse) && is_tool_activated_in_course_lightversion($clannToolId, $thisCourse) && is_tool_visible_for_portlet($clannToolId, $thisCourse['sysCode'])) {
            $courseEventList = announcement_get_course_item_list_portlet($thisCourse, get_conf('announcementPortletMaxItems', 3));
            if (is_array($courseEventList)) {
                foreach ($courseEventList as $thisEvent) {
                    $courseTitle = trim(strip_tags($thisCourse['title']));
                    if ($courseTitle == '') {
                        $courseTitle = substr($courseTitle, 0, 60) . (strlen($courseTitle) > 60 ? ' (...)' : '');
                    }
                    $eventContent = trim(strip_tags($thisEvent['content']));
                    if ($eventContent == '') {
                        $eventContent = substr($eventContent, 0, 60) . (strlen($eventContent) > 60 ? ' (...)' : '');
                    }
                    $courseOfficialCode = $thisEvent['courseOfficialCode'];
                    if (!array_key_exists($courseOfficialCode, $courseDigestList)) {
                        $courseDigestList[$courseOfficialCode] = array();
                        $courseDigestList[$courseOfficialCode]['eventList'] = array();
                        $courseDigestList[$courseOfficialCode]['id'] = $thisEvent['id'];
                        $courseDigestList[$courseOfficialCode]['courseOfficialCode'] = $courseOfficialCode;
                        $courseDigestList[$courseOfficialCode]['title'] = $courseTitle;
                        $courseDigestList[$courseOfficialCode]['visibility'] = $thisEvent['visibility'];
                        $courseDigestList[$courseOfficialCode]['visibleFrom'] = $thisEvent['visibleFrom'];
                        $courseDigestList[$courseOfficialCode]['visibleUntil'] = $thisEvent['visibleUntil'];
                        $courseDigestList[$courseOfficialCode]['url'] = get_path('url') . '/claroline/announcements/announcements.php?cidReq=' . $thisEvent['courseSysCode'];
                    }
                    $courseDigestList[$courseOfficialCode]['eventList'][] = array('id' => $thisEvent['id'], 'courseSysCode' => $thisEvent['courseSysCode'], 'toolLabel' => $thisEvent['toolLabel'], 'title' => $thisEvent['title'], 'content' => $eventContent, 'date' => $thisEvent['date'], 'url' => get_path('url') . '/claroline/announcements/announcements.php?cidReq=' . $thisEvent['courseSysCode'] . '#item' . $thisEvent['id']);
                }
            }
        }
    }
    return $courseDigestList;
}
Beispiel #5
0
    // user group access is allowed or user is group member or user is admin
    $is_groupAllowed = (bool) (!$_groupProperties['private'] || $is_groupMember || $is_courseAdmin || claro_is_group_tutor() || $is_platformAdmin);
} else {
    $_groupUser = !empty($_SESSION['_groupUser']) ? $_SESSION['_groupUser'] : null;
    $is_groupMember = !empty($_SESSION['is_groupMember']) ? $_SESSION['is_groupMember'] : null;
    $is_groupTutor = !empty($_SESSION['is_groupTutor']) ? $_SESSION['is_groupTutor'] : null;
    $is_groupAllowed = !empty($_SESSION['is_groupAllowed']) ? $_SESSION['is_groupAllowed'] : null;
}
/*---------------------------------------------------------------------------
  COURSE TOOL / USER / GROUP REL. INIT
 ---------------------------------------------------------------------------*/
if ($uidReset || $cidReset || $gidReset || $tidReset) {
    if ($_tid && $_gid) {
        //echo 'passed here';
        $toolLabel = trim($_courseTool['label'], '_');
        $is_toolAllowed = array_key_exists($toolLabel, $_groupProperties['tools']) && $_groupProperties['tools'][$toolLabel] && claro_is_allowed_tool_read(get_tool_id_from_module_label('CLGRP'), $_profileId, $_cid);
        if ($_groupProperties['private']) {
            $is_toolAllowed = $is_toolAllowed && ($is_groupMember || claro_is_group_tutor());
        }
        $is_toolAllowed = $is_toolAllowed || ($is_courseAdmin || $is_platformAdmin);
    } elseif ($_tid) {
        if (!$_courseTool['visibility'] && !claro_is_allowed_tool_edit($_mainToolId, $_profileId, $_cid) || !claro_is_allowed_tool_read($_mainToolId, $_profileId, $_cid)) {
            $is_toolAllowed = false;
        } else {
            $is_toolAllowed = true;
        }
    } else {
        $is_toolAllowed = false;
    }
} else {
    $is_toolAllowed = !empty($_SESSION['is_toolAllowed']) ? $_SESSION['is_toolAllowed'] : null;
Beispiel #6
0
/**
 * build the rss file and place it in directory
 *
 * @param array $context context of claroline
 * @param string $calType : ics,xcs,rdf
 * @return string ical file path
 */
function buildICal($context, $calType = 'ics')
{
    if (is_array($context) && count($context) > 0) {
        $iCalRepositorySys = get_path('rootSys') . get_conf('iCalRepositoryCache', 'tmp/cache/iCal/');
        if (!file_exists($iCalRepositorySys)) {
            require_once dirname(__FILE__) . '/fileManage.lib.php';
            claro_mkdir($iCalRepositorySys, CLARO_FILE_PERMISSIONS, true);
            if (!file_exists($iCalRepositorySys)) {
                claro_failure::set_failure('CANT_CREATE_ICAL_DIR');
            }
        }
        $iCal = (object) new iCal('', 0, $iCalRepositorySys);
        // (ProgrammID, Method (1 = Publish | 0 = Request), Download Directory)
        $toolLabelList = ical_get_tool_compatible_list();
        foreach ($toolLabelList as $toolLabel) {
            if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) {
                if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) {
                    install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]);
                }
                $icalToolLibPath = get_module_path($toolLabel) . '/connector/ical.write.cnr.php';
                $icalToolFuncName = $toolLabel . '_write_ical';
                if (file_exists($icalToolLibPath)) {
                    require_once $icalToolLibPath;
                    if (function_exists($icalToolFuncName)) {
                        $iCal = call_user_func($icalToolFuncName, $iCal, $context);
                    }
                }
            }
        }
        $iCalFilePath = $iCalRepositorySys;
        if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
            $iCalFilePath .= $context[CLARO_CONTEXT_COURSE] . '.';
        }
        if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) {
            $iCalFilePath .= 'g' . $context[CLARO_CONTEXT_GROUP] . '.';
        }
        if ('ics' == $calType || get_conf('iCalGenStandard', true)) {
            $stdICalFilePath = $iCalFilePath . 'ics';
            if (false !== ($fpICal = @fopen($stdICalFilePath, 'w'))) {
                fwrite($fpICal, $iCal->getOutput('ics'));
                fclose($fpICal);
            }
        }
        if ('xcs' == $calType || get_conf('iCalGenXml', true)) {
            $xmlICalFilePath = $iCalFilePath . 'xml';
            if (false !== ($fpICal = @fopen($xmlICalFilePath, 'w'))) {
                fwrite($fpICal, $iCal->getOutput('xcs'));
                fclose($fpICal);
            }
        }
        if ('rdf' == $calType || get_conf('iCalGenRdf', false)) {
            $rdfICalFilePath = $iCalFilePath . 'rdf';
            if (false !== ($fpICal = @fopen($rdfICalFilePath, 'w'))) {
                fwrite($fpICal, $iCal->getOutput('rdf'));
                fclose($fpICal);
            }
        }
        switch ($calType) {
            case 'xcs':
                return $xmlICalFilePath;
                break;
            case 'rdf':
                return $rdfICalFilePath;
                break;
            default:
                return $stdICalFilePath;
                break;
        }
    }
    return false;
}
 /**
  * Returns a single resquested topic.
  * @param array $args must contain 'resID' key with the resource identifier of the requested resource
  * @throws InvalidArgumentException if one of the paramaters is missing
  * @webservice{/module/MOBILE/CLANN/getSingleResource/cidReq/resId}
  * @ws_arg{Method,getSingleResource}
  * @ws_arg{cidReq,SYSCODE of requested cours}
  * @ws_arg{resID,Resource Id of requested resource}
  * @return announce object (can be null if not visible for the current user)
  */
 function getSingleResource($args)
 {
     $resourceId = isset($args['resID']) ? $args['resID'] : null;
     $cid = claro_get_current_course_id();
     if ($cid == null || $resourceId == null) {
         throw new InvalidArgumentException('Missing cid or resourceId argument!');
     }
     FromKernel::uses('forum.lib');
     $claroNotification = Claroline::getInstance()->notification;
     $date = $claroNotification->getLastActionBeforeLoginDate(claro_get_current_user_id());
     $d = new DateTime($date);
     $d->sub(new DateInterval('PT1M'));
     $item = null;
     foreach (get_forum_list() as $forum) {
         if ($forum['forum_id'] == $resourceID) {
             $item = $forum;
             break;
         }
     }
     if ($item) {
         $item['resourceId'] = $item['forum_id'];
         $item['title'] = $item['forum_name'];
         foreach (get_category_list as $cat) {
             if ($cat['cat_id'] == $item['cat_id']) {
                 $item['cat_title'] = $cat['cat_title'];
                 $item['cat_order'] = $cat['cat_order'];
                 break;
             }
         }
         $item['topics'] = array();
         $topics = new topicLister($item['forum_id'], 0, $item['forum_topics']);
         foreach ($topics->get_topic_list() as $topic) {
             $topic['resourceId'] = $topic['topic_id'];
             $topic['title'] = $topic['topic_title'];
             $topic['poster_firstname'] = $topic['prenom'];
             $topic['poster_lastname'] = $topic['nom'];
             $topic['date'] = $topic['topic_time'];
             $topic['posts'] = array();
             $posts = new postLister($topic['topic_id'], 0, $topic['topic_replies'] + 1);
             foreach ($posts->get_post_list() as $post) {
                 $notified = $claroNotification->isANotifiedRessource($cid, $date, claro_get_current_user_id(), claro_get_current_group_id(), get_tool_id_from_module_label('CLFRM'), $item['forum_id'] . '-' . $topic['topic_id'] . '-' . $post['post_id'], false);
                 $post['notifiedDate'] = $notified ? $date : $post['post_time'];
                 $post['seenDate'] = $d->format('Y-m-d H:i');
                 $post['post_text'] = trim(strip_tags($post['post_text']));
                 $post['resourceId'] = $post['post_id'];
                 $post['date'] = $post['post_time'];
                 unset($post['post_id']);
                 unset($post['topic_id']);
                 unset($post['forum_id']);
                 unset($post['poster_id']);
                 unset($post['post_time']);
                 unset($post['poster_ip']);
                 $topic['posts'][] = $post;
             }
             unset($topic['topic_id']);
             unset($topic['topic_title']);
             unset($topic['topic_poster']);
             unset($topic['topic_time']);
             unset($topic['topic_replies']);
             unset($topic['topic_last_post_id']);
             unset($topic['forum_id']);
             unset($topic['topic_notify']);
             unset($topic['nom']);
             unset($topic['prenom']);
             unset($topic['post_time']);
             $item['topics'][] = $topic;
         }
         unset($item['forum_id']);
         unset($item['forum_name']);
         unset($item['forum_moderator']);
         unset($item['forum_topics']);
         unset($item['forum_posts']);
         unset($item['forum_last_post_id']);
         unset($item['forum_type']);
         unset($item['group_id']);
         unset($item['poster_id']);
         unset($item['post_time']);
         return $item;
     } else {
         throw new RuntimeException('Resource not found', 404);
     }
 }
Beispiel #8
0
/**
 * Create a new group
 *
 * @param  string $groupName - name of the group
 * @param  integer $maxMember  - max user allowed for this group
 * @return integer : id of the new group
 *
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 */
function create_group($prefixGroupName, $maxMember)
{
    require_once dirname(__FILE__) . '/forum.lib.php';
    require_once dirname(__FILE__) . '/fileManage.lib.php';
    $tbl_cdb_names = claro_sql_get_course_tbl();
    $tbl_groups = $tbl_cdb_names['group_team'];
    // Check name of group
    $sql = "SELECT name FROM  `" . $tbl_groups . "` WHERE name LIKE  '" . claro_sql_escape($prefixGroupName) . "%'";
    $existingGroupList = claro_sql_query_fetch_all_cols($sql);
    $existingGroupList = $existingGroupList['name'];
    $i = 1;
    do {
        $groupName = $prefixGroupName . str_pad($i, 4, ' ', STR_PAD_LEFT);
        $i++;
        if ($i - 2 > count($existingGroupList)) {
            die($groupName . 'infiniteloop');
        }
    } while (in_array($groupName, $existingGroupList));
    /**
     * Create a directory allowing group student to upload documents
     */
    //  Create a Unique ID path preventing other enter
    $globalPath = $GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/';
    do {
        $groupRepository = str_replace(' ', '_', substr(uniqid(substr($groupName, 0, 19) . ' ', ''), 0, 30));
    } while (check_name_exist($globalPath . $groupRepository));
    claro_mkdir($globalPath . $groupRepository, CLARO_FILE_PERMISSIONS);
    /*
     * Insert a new group in the course group table and keep its ID
     */
    $sql = "INSERT INTO `" . $tbl_groups . "`\n            SET name = '" . $groupName . "',\n               `maxStudent`  = " . (is_null($maxMember) ? 'NULL' : "'" . (int) $maxMember . "'") . ",\n                secretDirectory = '" . claro_sql_escape($groupRepository) . "'";
    $createdGroupId = claro_sql_query_insert_id($sql);
    /*
     * Create a forum for the group in the forum table
     */
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLFRM'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLFRM')) {
        create_forum($groupName . ' - ' . strtolower(get_lang('Forum')), '', 2, (int) GROUP_FORUMS_CATEGORY, '', $createdGroupId);
    }
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLWIKI'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLWIKI')) {
        require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php';
        create_wiki($createdGroupId, $groupName . ' - Wiki');
    }
    return $createdGroupId;
}
Beispiel #9
0
/**
 * Activate the module in all courses
 * @param string $moduleLabel
 * @return array array( Backlog $backlog, boolean $success );
 * @todo remove the need of the Backlog and use Exceptions instead
 */
function activate_module_in_all_courses($toolLabel)
{
    $toolId = get_tool_id_from_module_label($toolLabel);
    $tbl = claro_sql_get_main_tbl();
    $sql = "SELECT `code` FROM `" . $tbl['course'] . "`";
    $courseList = claro_sql_query_fetch_all($sql);
    foreach ($courseList as $course) {
        if (!update_course_tool_activation_in_course($toolId, $course['code'], true)) {
            return false;
        }
    }
    return true;
}
Beispiel #10
0
/**
 * Is the given module installed in the given course ? This version does not call
 * claro_get_course_data and should be used in conjunction with get_user_course_list
 * @param string $toolLabel module label
 * @param array $course course( 'sysCode' => sysCode, 'db' => dbName
 * @return boolean
 */
function is_module_installed_in_course_lightversion($toolLabel, $course, $forceCacheRefresh = false)
{
    static $courseInstalledToolList = false;
    $toolId = get_tool_id_from_module_label($toolLabel);
    if (!$courseInstalledToolList) {
        $courseInstalledToolList = array();
    }
    $courseIdReq = $course['sysCode'];
    if (!isset($courseInstalledToolList[$courseIdReq]) || $forceCacheRefresh) {
        $courseInstalledToolList[$courseIdReq] = array();
        $tbl_cdb_names = claro_sql_get_course_tbl(get_conf('courseTablePrefix') . $course['db'] . get_conf('dbGlu'));
        $tbl_course_tool_list = $tbl_cdb_names['tool'];
        $sql = "SELECT tool_id \n" . "FROM `{$tbl_course_tool_list}`\n" . "WHERE `installed` = 'true'";
        $result = claro_sql_query_fetch_all_rows($sql);
        foreach ($result as $tool) {
            $courseInstalledToolList[$courseIdReq][$tool['tool_id']] = true;
        }
    }
    if (isset($courseInstalledToolList[$courseIdReq][$toolId])) {
        return true;
    } else {
        return false;
    }
}
Beispiel #11
0
            } else {
                $dialogBox->error(get_lang('Cannot remove tool from course'));
            }
        } else {
            $dialogBox->error(get_lang('Not a valid tool'));
        }
    }
}
if ('exAddTool' == $cmd) {
    if (is_null($toolLabel)) {
        $dialogBox->error(get_lang('Missing tool label'));
    } else {
        $moduleData = get_module_data($toolLabel);
        if ($moduleData['access_manager'] == 'COURSE_ADMIN' || claro_is_platform_admin()) {
            // get tool id
            $toolId = get_tool_id_from_module_label($toolLabel);
            if ($toolId) {
                if (!is_module_registered_in_course($toolId, claro_get_current_course_id())) {
                    register_module_in_single_course($toolId, claro_get_current_course_id());
                }
                // update course_tool.activated
                if (update_course_tool_activation_in_course($toolId, claro_get_current_course_id(), true)) {
                    set_module_visibility_in_course($toolId, $_cid, true);
                    $dialogBox->success(get_lang('Tool added to course'));
                    $cidReset = TRUE;
                    $cidReq = claro_get_current_course_id();
                    $groupToolList = get_group_tool_label_list();
                    foreach ($groupToolList as $group) {
                        if ($group['label'] == $toolLabel) {
                            // this is a group tool, enable it in groups
                            activate_module_in_groups(Claroline::getDatabase(), $toolLabel, claro_get_current_course_id());
Beispiel #12
0
      */
     if (is_tool_activated_in_course(get_tool_id_from_module_label('CLANN'), $thisCourse['sysCode'])) {
         $tableAnn = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'announcement';
         $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`,\n                       '" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`,\n                       'CLANN'                                          AS `toolLabel`,\n                       CONCAT(`temps`, ' ', '00:00:00')                 AS `date`,\n                       CONCAT(`title`,' - ',`contenu`)                  AS `content`\n    \n                FROM `" . $tableAnn . "`\n                WHERE CONCAT(`title`, `contenu`) != ''\n                  AND DATE_FORMAT( `temps`, '%Y %m %d') >= '" . date('Y m d', claro_get_current_user_data('lastLogin')) . "'\n                  AND visibility = 'SHOW'\n                ORDER BY `date` DESC\n                LIMIT 1";
         $resultList = claro_sql_query_fetch_all_cols($sql);
         foreach ($resultList as $colName => $colValue) {
             if (count($colValue) == 0) {
                 break;
             }
             $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue);
         }
     }
     /*
      * AGENDA : get the next agenda entries of this course from now
      */
     if (is_tool_activated_in_course(get_tool_id_from_module_label('CLCAL'), $thisCourse['sysCode'])) {
         $tableCal = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'calendar_event';
         $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`,\n                           '" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`,\n                           'CLCAL' AS `toolLabel`,\n                           CONCAT(`day`, ' ',`hour`) AS `date`,\n                           CONCAT(`titre`,' - ',`contenu`) AS `content`\n                    FROM `" . $tableCal . "`\n                    \n                    WHERE CONCAT(`day`, ' ',`hour`) >= CURDATE()\n                    AND CONCAT(`titre`, `contenu`) != ''\n                    AND visibility = 'SHOW'\n                    \n                    ORDER BY `date`\n                    LIMIT 1";
         $resultList = claro_sql_query_fetch_all_cols($sql);
         foreach ($resultList as $colName => $colValue) {
             if (count($colValue) == 0) {
                 break;
             }
             $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue);
         }
     }
 }
 // end foreach($personnalCourseList as $thisCourse)
 /*
  * Sort all these digest by date
  */
Beispiel #13
0
function get_agenda_items_compact_mode($userCourseList, $month, $year)
{
    $courseDigestList = array();
    $toolId = get_tool_id_from_module_label('CLCAL');
    // get agenda-items for every course
    foreach ($userCourseList as $thisCourse) {
        if (is_module_installed_in_course_lightversion('CLCAL', $thisCourse) && is_tool_activated_in_course_lightversion($toolId, $thisCourse) && is_tool_visible_for_portlet($toolId, $thisCourse['sysCode'])) {
            $courseEventList = get_agenda_items_list($thisCourse, $month, $year);
            if (is_array($courseEventList)) {
                foreach ($courseEventList as $thisEvent) {
                    $eventLine = trim(strip_tags($thisEvent['title']));
                    if ($eventLine == '') {
                        $eventContent = trim(strip_tags($thisEvent['content']));
                        $eventLine = substr($eventContent, 0, 60) . (strlen($eventContent) > 60 ? ' (...)' : '');
                    }
                    $eventDate = explode('-', $thisEvent['day']);
                    $day = intval($eventDate[2]);
                    if (!array_key_exists($day, $courseDigestList)) {
                        $courseDigestList[$day] = array();
                        $courseDigestList[$day]['eventList'] = array();
                        $courseDigestList[$day]['date'] = $thisEvent['day'];
                    }
                    $courseDigestList[$day]['eventList'][] = array('hour' => $thisEvent['hour'], 'courseOfficialCode' => $thisCourse['officialCode'], 'courseSysCode' => $thisCourse['sysCode'], 'content' => $eventLine, 'url' => get_path('url') . '/claroline/calendar/agenda.php?cidReq=' . $thisCourse['sysCode'] . '#item' . $thisEvent['id']);
                }
            }
        }
        ksort($courseDigestList);
    }
    return $courseDigestList;
}
Beispiel #14
0
function build_rss($context)
{
    if (is_array($context) && count($context) > 0) {
        $rss = new UniversalFeedCreator();
        if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
            // $rssFilePath .= $context[CLARO_CONTEXT_COURSE] . '.';
            $_course = claro_get_course_data($context[CLARO_CONTEXT_COURSE]);
            $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode'];
            $rss->description = $_course['name'];
            $rss->editor = $_course['titular'] == '' ? get_conf('administrator_name') : $_course['titular'];
            $rss->editorEmail = $_course['email'] == '' ? get_conf('administrator_email') : $_course['email'];
            $rss->link = get_path('rootWeb') . get_path('coursesRepositoryAppend') . claro_get_course_path();
            $rss->generator = 'Feedcreator';
            if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) {
                // $rssFilePath .= 'g'.$context[CLARO_CONTEXT_GROUP] . '.';
                $rss->title .= '[' . get_lang('Group') . $context[CLARO_CONTEXT_GROUP] . ']';
                $rss->description .= get_lang('Group') . $context[CLARO_CONTEXT_GROUP];
            }
        } else {
            $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode'];
            $rss->description = $_course['name'];
            $rss->editor = get_conf('administrator_name');
            $rss->editorEmail = get_conf('administrator_email');
            $rss->link = get_path('rootWeb');
        }
        $rss->language = get_locale('iso639_1_code');
        $rss->docs = 'http://blogs.law.harvard.edu/tech/rss';
        $rss->pubDate = date("r", time());
        $toolLabelList = rss_get_tool_compatible_list();
        //var_dump($toolLabelList);
        $rssItems = array();
        foreach ($toolLabelList as $toolLabel) {
            /*var_dump(is_tool_activated_in_course(
                  get_tool_id_from_module_label( $toolLabel ),
                  $context[CLARO_CONTEXT_COURSE]
              ));*/
            if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) {
                if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) {
                    install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]);
                }
                $rssToolLibPath = get_module_path($toolLabel) . '/connector/rss.write.cnr.php';
                $rssToolFuncName = $toolLabel . '_write_rss';
                if (file_exists($rssToolLibPath)) {
                    include_once $rssToolLibPath;
                    if (function_exists($rssToolFuncName)) {
                        $rssItems = array_merge($rssItems, call_user_func($rssToolFuncName, $context));
                    }
                }
            }
        }
        $sortDate = array();
        foreach ($rssItems as $key => $rssItem) {
            $sortDate[$key] = $rssItem['pubDate'];
        }
        // die(var_export($sortDate, true));
        array_multisort($sortDate, SORT_DESC, $rssItems);
        foreach ($rssItems as $rssItem) {
            $item = new FeedItem();
            $item->title = claro_utf8_encode($rssItem['title'], get_conf('charset'));
            $item->description = claro_utf8_encode($rssItem['description']);
            $item->category = $rssItem['category'];
            $item->guid = $rssItem['guid'];
            $item->link = $rssItem['link'];
            $item->date = $rssItem['pubDate'];
            $rss->addItem($item);
        }
        return $rss->outputFeed("RSS2.0");
    }
    return false;
}
Beispiel #15
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;
}