/**
  * 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);
     }
 }
Esempio n. 2
0
 protected function getModuleLinkList()
 {
     //$toolNameList = claro_get_tool_name_list();
     $claro_notifier = Claroline::getInstance()->notification;
     // Get tool id where new events have been recorded since last login
     if ($this->userId) {
         $date = $claro_notifier->get_notification_date($this->userId);
         $modified_tools = $claro_notifier->get_notified_tools($this->courseCode, $date, $this->userId);
     } else {
         $modified_tools = array();
     }
     $toolLinkList = array();
     $toolName = get_lang('Course homepage');
     // Trick to find how to build URL, must be IMPROVED
     $url = claro_htmlspecialchars(Url::Contextualize(get_path('url') . '/claroline/course/index.php?cid=' . $this->courseCode));
     $icon = get_icon_url('coursehome');
     $htmlId = 'id="courseHomePage"';
     $removableTool = false;
     $classCurrent = empty($GLOBALS['tlabelReq']) ? ' currentTool' : '';
     $toolLinkList[] = '<a ' . $htmlId . 'class="item' . $classCurrent . '" href="' . $url . '">' . '<img class="clItemTool"  src="' . $icon . '" alt="" />&nbsp;' . $toolName . '</a>' . "\n";
     // Generate tool lists
     $toolListSource = claro_get_course_tool_list($this->courseCode, $this->profileId, true);
     foreach ($toolListSource as $thisTool) {
         // Special case when display mode is student and tool invisible doesn't display it
         if ($this->viewMode == 'STUDENT' && !$thisTool['visibility']) {
             continue;
         }
         if (isset($thisTool['label'])) {
             $thisToolName = $thisTool['name'];
             $toolName = get_lang($thisToolName);
             // Trick to find how to build URL, must be IMPROVED
             $url = claro_htmlspecialchars(Url::Contextualize(get_module_url($thisTool['label']) . '/' . $thisTool['url'], $this->currentCourseContext));
             $icon = get_module_url($thisTool['label']) . '/' . $thisTool['icon'];
             $htmlId = 'id="' . $thisTool['label'] . '"';
             $removableTool = false;
         } else {
             if (!empty($thisTool['external_name'])) {
                 $toolName = $thisTool['external_name'];
             } else {
                 $toolName = '<i>no name</i>';
             }
             $url = claro_htmlspecialchars(trim($thisTool['url']));
             $icon = get_icon_url('link');
             $htmlId = '';
             $removableTool = true;
         }
         $style = !$thisTool['visibility'] ? 'invisible ' : '';
         $classItem = in_array($thisTool['id'], $modified_tools) ? ' hot' : '';
         $classCurrent = isset($thisTool['label']) && $thisTool['label'] == $GLOBALS['tlabelReq'] ? ' currentTool' : '';
         if (!empty($url)) {
             $toolLinkList[] = '<a ' . $htmlId . 'class="' . $style . 'item' . $classItem . $classCurrent . '" href="' . $url . '">' . '<img class="clItemTool"  src="' . $icon . '" alt="" />&nbsp;' . $toolName . '</a>' . "\n";
         } else {
             $toolLinkList[] = '<span ' . $style . '>' . '<img class="clItemTool" src="' . $icon . '" alt="" />&nbsp;' . $toolName . '</span>' . "\n";
         }
     }
     return $toolLinkList;
 }
Esempio n. 3
0
 /**
  * Render the template
  * @return  string
  * @throws  Exception if file not found or error/exception in the template
  */
 public function render()
 {
     if (file_exists($this->_templatePath)) {
         $claroline = Claroline::getInstance();
         claro_ob_start();
         include $this->_templatePath;
         $render = claro_ob_get_contents();
         claro_ob_end_clean();
         return $render;
     } else {
         throw new Exception("Template file not found {$this->_templatePath}");
     }
 }
Esempio n. 4
0
/**
 * delete a course of the plateform
 *
 * TODO detect failure with claro_failure
 *
 * @param string $cid
 *
 * @return boolean TRUE        if suceed
 *         boolean FALSE       otherwise.
 */
function delete_course($code, $sourceCourseId)
{
    global $eventNotifier;
    // Declare needed tables
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_course = $tbl_mdb_names['course'];
    $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
    $tbl_course_class = $tbl_mdb_names['rel_course_class'];
    $tbl_rel_course_category = $tbl_mdb_names['rel_course_category'];
    $tbl_rel_course_portlet = $tbl_mdb_names['rel_course_portlet'];
    $this_course = claro_get_course_data($code);
    if (!$this_course) {
        // This is bad !
        throw new Exception("Course not found");
    }
    $currentCourseId = trim($this_course['sysCode']);
    if (empty($currentCourseId)) {
        // This is bad !
        throw new Exception("Missing course id");
    }
    // Delete user registrations into this course
    $sql = 'DELETE FROM `' . $tbl_rel_course_user . '`
            WHERE code_cours="' . $currentCourseId . '"';
    claro_sql_query($sql);
    // Remove any recording in rel_cours_class
    $sql = "DELETE FROM `" . $tbl_course_class . "`\n            WHERE courseId ='" . claro_sql_escape($currentCourseId) . "'";
    claro_sql_query($sql);
    // Remove links between this course and categories
    $sql = "DELETE FROM `" . $tbl_rel_course_category . "`\n            WHERE courseId ='" . $this_course['id'] . "'";
    claro_sql_query($sql);
    // Remove links between this course and portlets
    $sql = "DELETE FROM `" . $tbl_rel_course_portlet . "`\n            WHERE courseId ='" . $this_course['id'] . "'";
    claro_sql_query($sql);
    // Delete the course inside the platform course registery
    $sql = 'DELETE FROM `' . $tbl_course . '`
            WHERE code= "' . claro_sql_escape($currentCourseId) . '"';
    claro_sql_query($sql);
    // Is it a session course ?
    if (!is_null($sourceCourseId)) {
        // Does the source course still have session courses ?
        $sql = "SELECT COUNT(cours_id) AS nbSessionCourses\n                FROM `" . $tbl_course . "`\n                WHERE sourceCourseId = " . (int) $sourceCourseId;
        $result = claro_sql_query_get_single_row($sql);
        if ($result['nbSessionCourses'] == 0) {
            $sql = "UPDATE `" . $tbl_course . "`\n                    SET isSourceCourse = 0\n                    WHERE cours_id = " . (int) $sourceCourseId;
            claro_sql_query($sql);
        }
    }
    // Delete course right
    RightCourseProfileToolRight::resetAllRightProfile($currentCourseId);
    // Delete course module tables
    // FIXME handle errors
    list($success, $log) = delete_all_modules_from_course($currentCourseId);
    // Notify the course deletion event
    $args['cid'] = $this_course['sysCode'];
    $args['tid'] = null;
    $args['rid'] = null;
    $args['gid'] = null;
    $args['uid'] = $GLOBALS['_uid'];
    $eventNotifier->notifyEvent("course_deleted", $args);
    if ($currentCourseId == $code) {
        $currentCourseDbName = trim($this_course['dbName']);
        $currentCourseDbNameGlu = trim($this_course['dbNameGlu']);
        $currentCoursePath = trim($this_course['path']);
        if (empty($currentCourseDbName)) {
            // This is bad !
            throw new Exception("Missing db name");
        }
        if (empty($currentCourseDbNameGlu)) {
            // This is bad !
            throw new Exception("Missing db name glu");
        }
        if (get_conf('singleDbEnabled')) {
            // SEARCH ALL TABLES RELATED TO THE CURRENT COURSE
            claro_sql_query("use " . get_conf('mainDbName'));
            $tbl_to_delete = claro_sql_get_course_tbl(claro_get_course_db_name_glued($currentCourseId));
            foreach ($tbl_to_delete as $tbl_name) {
                $sql = 'DROP TABLE IF EXISTS `' . $tbl_name . '`';
                claro_sql_query($sql);
            }
            // Underscores must be replaced because they are used as wildcards in LIKE sql statement
            $cleanCourseDbNameGlu = str_replace("_", "\\_", $currentCourseDbNameGlu);
            $sql = 'SHOW TABLES LIKE "' . $cleanCourseDbNameGlu . '%"';
            $result = claro_sql_query($sql);
            // DELETE ALL TABLES OF THE CURRENT COURSE
            $tblSurvivor = array();
            while (false !== ($courseTable = mysql_fetch_array($result, MYSQL_NUM))) {
                $tblSurvivor[] = $courseTable[0];
                //$tblSurvivor[$courseTable]='not deleted';
            }
            if (sizeof($tblSurvivor) > 0) {
                Claroline::getInstance()->log('DELETE_COURSE', array_merge(array('DELETED_COURSE_CODE' => $code, 'UNDELETED_TABLE_COUNTER' => sizeof($tblSurvivor)), $tblSurvivor));
            }
        } else {
            $sql = "DROP DATABASE `" . $currentCourseDbName . "`";
            claro_sql_query($sql);
        }
        // MOVE THE COURSE DIRECTORY INTO THE COURSE GARBAGE COLLECTOR
        if (!empty($currentCoursePath)) {
            if (file_exists(get_conf('coursesRepositorySys') . $currentCoursePath . '/')) {
                claro_mkdir(get_conf('garbageRepositorySys'), CLARO_FILE_PERMISSIONS, true);
                rename(get_conf('coursesRepositorySys') . $currentCoursePath . '/', get_conf('garbageRepositorySys', 'garbage') . '/' . $currentCoursePath . '_' . date('YmdHis'));
            } else {
                Console::warning("DELETE_COURSE : Course directory not found {$currentCoursePath} for course {$currentCourseId}");
            }
            Claroline::log('COURSE_DELETED', array('courseCode' => $currentCourseId, 'courseDbName' => $currentCourseDbName, 'courseDbNameGlu' => $currentCourseDbNameGlu, 'coursePath' => $currentCoursePath));
            return true;
        } else {
            Console::error("DELETE_COURSE : Try to delete a course repository with no folder name {$currentCourseId} !");
            return true;
        }
    } else {
        return false;
    }
}
Esempio n. 5
0
/**
 * Unset the current module label at run time
 *  (Warning : does not alter tlabelReq or _courseTool)
 *  @param string label module label
 *  @return string old label or false if no old label defined
 */
function clear_current_module_label()
{
    return Claroline::getInstance()->popModuleLabel();
}
Esempio n. 6
0
/**
 * Returns a courses list for the current user.
 *
 * @return string       list of courses (HTML format)
 * @deprecated use UserCourseList and CourseTreeView instead
 */
function render_user_course_list()
{
    // Get the list of personnal courses marked as contening new events
    $date = Claroline::getInstance()->notification->get_notification_date(claro_get_current_user_id());
    $modified_course = Claroline::getInstance()->notification->get_notified_courses($date, claro_get_current_user_id());
    // Get all the user's courses
    $userCourseList = claro_get_user_course_list();
    // Use the course id as array index, exclude disable courses
    // and flag hot courses
    $reorganizedUserCourseList = array();
    $tempSessionCourses = array();
    foreach ($userCourseList as $course) {
        // Do not include "disable", "pending", "trash" or "date" courses
        // (if we're not in the date limits)
        $curdate = claro_mktime();
        $courseIsEnable = (bool) ($course['status'] == 'enable' || $course['status'] == 'date' && (!isset($course['creationDate']) || strtotime($course['creationDate']) <= $curdate) && (!isset($course['expirationDate']) || strtotime($course['expirationDate']) >= $curdate));
        // Flag hot courses
        $course['hot'] = (bool) in_array($course['sysCode'], $modified_course);
        if (!isset($reorganizedUserCourseList[$course['courseId']]) && $courseIsEnable) {
            // If it's not a session course, include it in the final list
            if (empty($course['sourceCourseId'])) {
                $reorganizedUserCourseList[$course['courseId']] = $course;
            } else {
                $tempSessionCourses[$course['sourceCourseId']][] = $course;
            }
        }
    }
    unset($userCourseList);
    // Merge courses and their session courses (if any)
    foreach ($tempSessionCourses as $sourceCourseId => $sessionCourses) {
        /*
         * Sometimes, a session course could not find its associated source
         * course in the user course list.  Simply because, for some reason,
         * this user isn't registered to the source course anymore, but is
         * still registered in the session course.
         */
        if (!empty($reorganizedUserCourseList[$sourceCourseId])) {
            $reorganizedUserCourseList[$sourceCourseId]['sessionCourses'] = $sessionCourses;
        } else {
            foreach ($sessionCourses as $course) {
                $reorganizedUserCourseList[$course['courseId']] = $course;
            }
        }
    }
    unset($tempSessionCourses);
    // Now, $reorganizedUserCourseList contains all user's courses and, for
    // each course, its eventual session courses.
    // Display
    $out = '';
    // Courses organized by categories
    if (get_conf('userCourseListGroupByCategories')) {
        // Get all the categories names (used to build trails)
        $categoryList = ClaroCategory::getAllCategories(0, 0, 1);
        // Get the categories informations for these courses
        $userCategoryList = ClaroCategory::getCoursesCategories($reorganizedUserCourseList);
        // Use the category id as array index
        $reorganizedUserCategoryList = array();
        foreach ($userCategoryList as $category) {
            // Flag root courses and put it aside
            $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 0;
            if ($category['rootCourse']) {
                $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 1;
            }
            if (!isset($reorganizedUserCategoryList[$category['categoryId']])) {
                $reorganizedUserCategoryList[$category['categoryId']] = $category;
                //We won't need that key anymore
                unset($reorganizedUserCategoryList[$category['categoryId']]['courseId']);
            }
            // Initialise the category's course list
            $reorganizedUserCategoryList[$category['categoryId']]['courseList'] = array();
        }
        // Place courses in the right categories and build categories' trails
        $currentCategoryId = null;
        foreach ($userCategoryList as $category) {
            // Build the full trail for each category (excepted root category)
            if ($category['categoryId'] == 0) {
                $trail = $category['name'];
            } else {
                $trail = build_category_trail($categoryList, $category['categoryId']);
            }
            $reorganizedUserCategoryList[$category['categoryId']]['trail'] = $trail;
            // Put root courses aside
            if ($reorganizedUserCourseList[$category['courseId']]['rootCourse']) {
                $reorganizedUserCategoryList[$category['categoryId']]['rootCourse'] = $reorganizedUserCourseList[$category['courseId']];
            } else {
                // Do not include source courses (only display session courses)
                // (excepted if the user is manager of the course)
                if (!$reorganizedUserCourseList[$category['courseId']]['isSourceCourse'] || $reorganizedUserCourseList[$category['courseId']]['isCourseManager']) {
                    $reorganizedUserCategoryList[$category['categoryId']]['courseList'][] = $reorganizedUserCourseList[$category['courseId']];
                }
            }
        }
        unset($userCategoryList);
        if (count($reorganizedUserCategoryList) > 0) {
            $out .= '<dl class="courseList">';
            foreach ($reorganizedUserCategoryList as $category) {
                if (!empty($category['courseList']) || !empty($category['rootCourse'])) {
                    $out .= '<dt>' . "\n" . '<h4 id="' . $category['categoryId'] . '">' . $category['trail'] . (!empty($category['rootCourse']) ? ' [<a href="' . get_path('url') . '/claroline/course/index.php?cid=' . claro_htmlspecialchars($category['rootCourse']['sysCode']) . '">' . get_lang('Infos') . '</a>]' : '') . '</h4>' . "\n" . '</dt>' . "\n";
                    if (!empty($category['courseList'])) {
                        foreach ($category['courseList'] as $course) {
                            $out .= render_course_in_dl_list($course, $course['hot']);
                        }
                    } else {
                        $out .= '<dt>' . get_lang('There are no courses in this category') . '</dt>';
                    }
                }
            }
        }
        $out .= '</dl>';
    } else {
        if (count($reorganizedUserCourseList) > 0) {
            $out .= '<dl class="courseList">';
            foreach ($reorganizedUserCourseList as $course) {
                $displayIconAccess = $course['isCourseManager'] || claro_is_platform_admin() ? true : false;
                $out .= render_course_in_dl_list($course, $course['hot'], $displayIconAccess);
            }
            $out .= '</dl>' . "\n";
        }
    }
    return $out;
}
 function getSingleResource($args)
 {
     $tlabelReq = 'MOBILE';
     $thisFile = isset($args['resID']) ? $args['resID'] : null;
     $cid = claro_get_current_course_id();
     if (is_null($cid) || is_null($thisFile)) {
         throw new InvalidArgumentException('Missing cid or resourceId argument!');
     }
     if (claro_is_course_allowed()) {
         /* INITIALISATION
         		 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
         $tableName = get_module_main_tbl(array('mobile_tokens'));
         $tableName = $tableName['mobile_tokens'];
         $limit = 5;
         $baseWorkDir = get_path('coursesRepositorySys') . claro_get_course_path($cid) . '/document';
         if (is_dir($baseWorkDir . $thisFile) || is_file($baseWorkDir . $thisFile)) {
             if (is_dir($baseWorkDir . $thisFile)) {
                 if ($is_allowedToEdit || get_conf('cldoc_allowNonManagersToDownloadFolder', true) || get_conf('cldoc_allowNonManagersToDownloadFolder', true) && get_conf('cldoc_allowAnonymousToDownloadFolder', true)) {
                     /*
                      * PREPARE THE FILE COLLECTION
                      */
                     if (!$is_allowedToEdit) {
                         // Build an exclude file list to prevent simple user
                         // to see document contained in "invisible" directories
                         $searchExcludeList = getInvisibleDocumentList($baseWorkDir);
                     } else {
                         $searchExcludeList = array();
                     }
                     $filePathList = claro_search_file(search_string_to_pcre(''), $baseWorkDir . $thisFile, true, 'FILE', $searchExcludeList);
                     /*
                      * BUILD THE ZIP ARCHIVE
                      */
                     require_once get_path('incRepositorySys') . '/lib/thirdparty/pclzip/pclzip.lib.php';
                     // Build archive in tmp course folder
                     $downloadArchivePath = get_conf('cldoc_customTmpPath', '');
                     if (empty($downloadArchivePath)) {
                         $downloadArchivePath = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/zip';
                         $downloadArchiveFile = $downloadArchivePath . '/' . uniqid('') . '.zip';
                     } else {
                         $downloadArchiveFile = rtrim($downloadArchivePath, '/') . '/' . claro_get_current_course_id() . '_CLDOC_' . uniqid('') . '.zip';
                     }
                     if (!is_dir($downloadArchivePath)) {
                         mkdir($downloadArchivePath, CLARO_FILE_PERMISSIONS, true);
                     }
                     $downloadArchive = new PclZip($downloadArchiveFile);
                     $downloadArchive->add($filePathList, PCLZIP_OPT_REMOVE_PATH, $baseWorkDir . $thisFile);
                     if (file_exists($downloadArchiveFile)) {
                         $pathInfo = $downloadArchiveFile;
                     } else {
                         throw new RuntimeException('Internal Server Error', 500);
                     }
                 } else {
                     throw new RuntimeException('Not allowed', 403);
                 }
             } elseif (is_file($baseWorkDir . $thisFile)) {
                 require_once get_path('incRepositorySys') . '/lib/file/downloader.lib.php';
                 Claroline::getInstance()->notification->addListener('download', 'trackInCourse');
                 $connectorPath = secure_file_path(get_module_path($tlabelReq) . '/connector/downloader.cnr.php');
                 require_once $connectorPath;
                 $className = $tlabelReq . '_Downloader';
                 $downloader = new $className($tlabelReq, $cid, claro_get_current_user_id());
                 if ($downloader && $downloader->isAllowedToDownload($thisFile)) {
                     $pathInfo = $downloader->getFilePath($thisFile);
                     $pathInfo = secure_file_path($pathInfo);
                     // Check if path exists in course folder
                     if (!file_exists($pathInfo) || is_dir($pathInfo)) {
                         throw new RuntimeException('Resource not found', 404);
                     }
                 } else {
                     throw new RuntimeException('Not allowed', 403);
                 }
             }
             for ($result = $try = 0; $try < $limit && $result < 1; $try++) {
                 /* Create token and register into the db. Retry until the registration complete or fail $limit times.
                 		 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
                 $token = bin2hex(openssl_random_pseudo_bytes(15));
                 $sql = 'REPLACE INTO `' . $tableName . '` (`userId`, `token`, `requestedPath`, `requestTime`, `wasFolder`, `canRetry`) ' . 'VALUES (\'' . claro_get_current_user_id() . '\', \'' . $token . '\', \'' . claro_sql_escape($pathInfo) . '\', NOW(), \'' . (is_dir($baseWorkDir . $thisFile) ? 1 : 0) . '\' , \'' . (isset($args['platform']) && $args['platform'] == 'WP' ? 1 : 0) . '\');';
                 $result = Claroline::getDatabase()->exec($sql);
             }
             $response['token'] = $try == $limit ? null : $token;
             return $response;
         } else {
             throw new RuntimeException('Resource not found', 404);
         }
     } else {
         throw new RuntimeException('Not allowed', 403);
     }
 }
Esempio n. 8
0
 /**
  * Exceute the controller bound to the requested key
  * @param   string $request requestable key, if null, trys to serve the default
  *  Controller if any
  * @throws  Claro_FrontController_Exception if if the requested key is not bound
  * @return  string controller output
  */
 public function serve($request = null)
 {
     if (empty($request) && $this->defaultController) {
         $request = $this->defaultController;
     }
     if (array_key_exists($request, $this->registry)) {
         $userInput = Claro_UserInput::getInstance();
         $claroline = Claroline::getInstance();
         $svc = $this->registry[$request];
         return $svc->handleRequest($userInput, $claroline);
     } else {
         throw new Claro_FrontController_Exception("No controller bound to {$request}");
     }
 }
Esempio n. 9
0
 /**
  * Constructor
  * @param String date (format: 2011-11-09 14:39:00; default: null)
  * @param int $userId 
  */
 public function __construct($userId, $date = null)
 {
     if (empty($date)) {
         $date = Claroline::getInstance()->notification->getNotificationDate($userId);
     }
     $this->notifiedCourseIdList = Claroline::getInstance()->notification->get_notified_courses($date, $userId);
 }
Esempio n. 10
0
/**
 * delete a list of user id from a list of courses
 * @param array $userIdList list of user id to remove
 * @param array|string $courseCodeList array of course codes or one single course code
 * @param bool $force forece the deletion
 * @param bool $delTrackData delete tracking data
 * @param bool $unregister_by_class unregister by class
 * @return int number of deleted users
 */
function user_remove_userlist_from_course($userIdList, $courseCodeList = array(), $force = false, $delTrackData = false, $unregister_by_class = false)
{
    $tbl = claro_sql_get_main_tbl();
    $userDeletedCount = 0;
    if (!is_array($courseCodeList)) {
        $courseCodeList = array($courseCodeList);
    }
    foreach ($userIdList as $userIdToProcess) {
        $userId = is_numeric($userIdToProcess) ? $userIdToProcess : $userIdToProcess['user_id'];
        if (!$force && $userId == $GLOBALS['_uid']) {
            // PREVIOUSLY CHECK THE USER IS NOT COURSE ADMIN OF THESE COURSES
            $sql = "SELECT COUNT(user_id)\n                    FROM `" . $tbl['rel_course_user'] . "`\n                    WHERE user_id = " . (int) $userId . "\n                      AND isCourseManager = 1\n                      AND code_cours IN ('" . implode("', '", array_map('claro_sql_escape', $courseCodeList)) . "') ";
            if (claro_sql_query_get_single_value($sql) > 0) {
                Claroline::getInstance()->log('DELETE_USER_FAILED', array('USER' => $userId, 'failure' => 'course_manager_cannot_unsubscribe_himself'));
                continue;
            }
        }
        $sql = "SELECT code_cours , count_user_enrol, count_class_enrol\n                FROM `" . $tbl['rel_course_user'] . "`\n                WHERE `code_cours` IN ('" . implode("', '", array_map('claro_sql_escape', $courseCodeList)) . "')\n                AND   `user_id` = " . $userId;
        $userEnrolCourseList = claro_sql_query_fetch_all($sql);
        foreach ($userEnrolCourseList as $thisUserEnrolCourse) {
            $thisCourseCode = $thisUserEnrolCourse['code_cours'];
            $count_user_enrol = $thisUserEnrolCourse['count_user_enrol'];
            $count_class_enrol = $thisUserEnrolCourse['count_class_enrol'];
            if ($count_user_enrol + $count_class_enrol <= 1) {
                // remove user from course
                if (user_remove_from_group($userId, $thisCourseCode) == false) {
                    return false;
                }
                $dbNameGlued = claro_get_course_db_name_glued($thisCourseCode);
                $tbl_cdb_names = claro_sql_get_course_tbl($dbNameGlued);
                $tbl_bb_notify = $tbl_cdb_names['bb_rel_topic_userstonotify'];
                $tbl_group_team = $tbl_cdb_names['group_team'];
                $tbl_userinfo_content = $tbl_cdb_names['userinfo_content'];
                $sqlList = array();
                $toolCLFRM = get_module_data('CLFRM');
                if (is_tool_activated_in_course($toolCLFRM['id'], $thisUserEnrolCourse['code_cours'])) {
                    $sqlList = array("DELETE FROM `" . $tbl_bb_notify . "` WHERE user_id = " . (int) $userId);
                }
                array_push($sqlList, "DELETE FROM `" . $tbl_userinfo_content . "` WHERE user_id = " . (int) $userId, "UPDATE `" . $tbl_group_team . "` SET `tutor` = NULL WHERE `tutor`='" . (int) $userId . "'");
                foreach ($sqlList as $thisSql) {
                    if (claro_sql_query($thisSql) == false) {
                        continue;
                    }
                }
                if ($delTrackData) {
                    if (user_delete_course_tracking_data($userId, $thisCourseCode) == false) {
                        continue;
                    }
                }
                $sql = "DELETE FROM `" . $tbl['rel_course_user'] . "`\n                    WHERE user_id = " . (int) $userId . "\n                      AND code_cours = '" . claro_sql_escape($thisCourseCode) . "'";
                if (claro_sql_query($sql) == false) {
                    continue;
                }
            } else {
                // decrement the count of registration by the user or class
                if (!$unregister_by_class) {
                    $count_user_enrol--;
                } else {
                    $count_class_enrol--;
                }
                // update enrol count in table rel_course_user
                $sql = "UPDATE `" . $tbl['rel_course_user'] . "`\n                          SET `count_user_enrol` = '" . $count_user_enrol . "',\n                            `count_class_enrol` = '" . $count_class_enrol . "'\n                          WHERE `user_id`   =  " . (int) $userId . "\n                          AND  `code_cours` = '" . claro_sql_escape($thisCourseCode) . "'";
                if (!claro_sql_query($sql)) {
                    continue;
                }
            }
        }
        $userDeletedCount++;
    }
    return $userDeletedCount;
}
Esempio n. 11
0
 public function run()
 {
     if (!file_exists($this->scriptPath)) {
         throw new Exception("File not found " . $this->scriptPath);
         return false;
     } else {
         $claroline = Claroline::getInstance();
         ob_start();
         require_once $this->scriptPath;
         $output = ob_get_contents();
         ob_end_clean();
         $this->setOutput($output);
         return true;
     }
 }
 /**
  * Retrieve the notified items for the current user. Do not mark them as showed.
  * @webservice{/module/MOBILE/User/getUpdates}
  * @ws_arg{Method, getUpdates}
  * @return empty array if no notification.
  * 		   Else, return array([SYSCODE] => array([LABEL] => notified resource object, ...), ...)
  */
 function getUpdates($args)
 {
     $claroNotification = Claroline::getInstance()->notification;
     $date = isset($args['date']) ? $args['date'] : $claroNotification->getLastActionBeforeLoginDate(claro_get_current_user_id());
     $gid = 0;
     $result = array();
     foreach ($claroNotification->getNotifiedCourses($date, claro_get_current_user_id()) as $cid) {
         foreach ($claroNotification->getNotifiedTools($cid, $date, claro_get_current_user_id()) as $tid) {
             $result[$cid][get_module_label_from_tool_id($tid)] = $claroNotification->getNotifiedRessources($cid, $date, claro_get_current_user_id(), $gid, $tid);
         }
     }
     return $result;
 }
Esempio n. 13
0
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 *
 * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
 *
 * @see http://www.claroline.net/wiki/config_def/
 *
 * @package EDITOR
 *
 * @author Claro Team <*****@*****.**>
 * @author Sebastien Piraux <*****@*****.**>
 *
 */
/**
 * Add javascript var for mimetex URL
 */
Claroline::getInstance()->display->header->addInlineJavascript('var mimeTexURL = "' . get_conf('claro_texRendererUrl') . '"');
require_once dirname(__FILE__) . '/../GenericEditor.class.php';
/**
 * Class to manage htmlarea overring simple textarea html
 * @package EDITOR
 */
class editor extends GenericEditor
{
    /**
     * @var $_tag metadata comment added to identify editor
     */
    private $_tag;
    /**
     * constructor
     *
     * @author Sebastien Piraux <*****@*****.**>
Esempio n. 14
0
<?php

/**
 * CLAROLINE Applet
 *
 * @author Loic Fortemps
 *
 * @package MOBILE
 *
 */
$tlabelReq = 'MOBILE';
require_once dirname(__FILE__) . '/../../claroline/inc/claro_init_global.inc.php';
Claroline::initDisplay(Claroline::POPUP);
CssLoader::getInstance()->load('mobile', 'all');
$pageTitle = array('mainTitle' => get_lang('Mobile Apps Configuration'), 'subTitle' => get_lang('Configuration helper'));
ClaroBreadCrumbs::getInstance()->append($pageTitle['mainTitle'], $_SERVER['PHP_SELF']);
ClaroBreadCrumbs::getInstance()->append($pageTitle['subTitle']);
$template = new ModuleTemplate($tlabelReq, 'popup.tpl.php');
Claroline::getInstance()->display->body->appendContent(claro_html_tool_title($pageTitle) . $template->render());
echo Claroline::getInstance()->display->render();
 /**
  * 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);
     }
 }
Esempio n. 16
0
 * @author      Claroline Team <*****@*****.**>
 * @author      Christophe Mertens <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html
 *              GNU GENERAL PUBLIC LICENSE version 2 or later
 * @package     internal_messaging
 */
$cidReset = true;
require_once dirname(__FILE__) . '/../../claroline/inc/claro_init_global.inc.php';
// manager of the admin message box
require_once dirname(__FILE__) . '/lib/messagebox/adminmessagebox.lib.php';
require_once dirname(__FILE__) . '/lib/tools.lib.php';
require_once dirname(__FILE__) . '/lib/displaymessage.lib.php';
// search user info
require_once get_path('incRepositorySys') . '/lib/user.lib.php';
// move to kernel
$claroline = Claroline::getInstance();
// ------------- permission ---------------------------
if (!claro_is_user_authenticated()) {
    claro_disp_auth_form(false);
}
if (!claro_is_platform_admin()) {
    claro_die(get_lang('Not allowed'));
}
// -------------- business logic ----------------------
$content = "";
$arguments = array();
$displayTable = true;
$acceptedSearch = array('fromUser', 'olderThan', 'timeInterval', 'platformMessage');
$acceptedCommand = array('rqDeleteSelection', 'exDeleteSelection', 'rqDeleteMessage', 'exDeleteMessage');
$box = new AdminMessageBox();
$strategy = $box->getSelector();
Esempio n. 17
0
/**
 * Terminate the script and display message
 *
 * @param string message
 */
function claro_die($message)
{
    FromKernel::uses('display/dialogBox.lib');
    $dialogBox = new DialogBox();
    $dialogBox->error($message);
    Claroline::getInstance()->display->setContent($dialogBox->render());
    if (claro_debug_mode()) {
        pushClaroMessage(var_export(debug_backtrace(), true), 'debug');
    }
    echo Claroline::getInstance()->display->render();
    die;
    // necessary to prevent any continuation of the application
}