Пример #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     //Table definitions
     $this->tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
     $this->tbl_personal_agenda = Database::get_user_personal_table(TABLE_PERSONAL_AGENDA);
     $this->tbl_course_agenda = Database::get_course_table(TABLE_AGENDA);
     $this->table_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
     //Setting the course object if we are in a course
     $this->course = null;
     $courseInfo = api_get_course_info();
     if (!empty($courseInfo)) {
         $this->course = $courseInfo;
     }
     $this->setSessionId(api_get_session_id());
     $this->setSenderId(api_get_user_id());
     $this->events = array();
     // Event colors
     $this->event_platform_color = 'red';
     //red
     $this->event_course_color = '#458B00';
     //green
     $this->event_group_color = '#A0522D';
     //siena
     $this->event_session_color = '#00496D';
     // kind of green
     $this->event_personal_color = 'steel blue';
     //steel blue
 }
Пример #2
0
 /**
  * Creates the mPDF object
  * @param string  $pageFormat format A4 A4-L see  http://mpdf1.com/manual/index.php?tid=184&searchstring=format
  * @param string  $orientation orientation "P" = Portrait "L" = Landscape
  * @param array $params
  * @param Template $template
  */
 public function __construct($pageFormat = 'A4', $orientation = 'P', $params = array(), $template = null)
 {
     $this->template = $template;
     /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF
      * mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
      */
     if (!in_array($orientation, array('P', 'L'))) {
         $orientation = 'P';
     }
     //$this->pdf = $pdf = new mPDF('UTF-8', $pageFormat, '', '', 30, 20, 27, 25, 16, 13, $orientation);
     //left, right, top, bottom, margin_header, margin footer
     $params['left'] = isset($params['left']) ? $params['left'] : 15;
     $params['right'] = isset($params['right']) ? $params['right'] : 15;
     $params['top'] = isset($params['top']) ? $params['top'] : 20;
     $params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15;
     $this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_local_time();
     $this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled');
     $this->params['course_info'] = isset($params['course_info']) ? $params['course_info'] : api_get_course_info();
     $this->params['session_info'] = isset($params['session_info']) ? $params['session_info'] : api_get_session_info(api_get_session_id());
     $this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id();
     $this->params['add_signatures'] = isset($params['add_signatures']) ? $params['add_signatures'] : false;
     $this->params['show_real_course_teachers'] = isset($params['show_real_course_teachers']) ? $params['show_real_course_teachers'] : false;
     $this->params['student_info'] = isset($params['student_info']) ? $params['student_info'] : false;
     $this->params['show_grade_generated_date'] = isset($params['show_grade_generated_date']) ? $params['show_grade_generated_date'] : false;
     $this->params['show_teacher_as_myself'] = isset($params['show_teacher_as_myself']) ? $params['show_teacher_as_myself'] : true;
     $this->params['pdf_date'] = isset($params['pdf_date']) ? $params['pdf_date'] : api_format_date(api_get_local_time(), DATE_TIME_FORMAT_LONG);
     $this->pdf = new mPDF('UTF-8', $pageFormat, '', '', $params['left'], $params['right'], $params['top'], $params['bottom'], 8, 8, $orientation);
 }
Пример #3
0
 /**
  * Setups the folder
  */
 public function setup()
 {
     $userId = api_get_user_id();
     $userInfo = api_get_user_info();
     $sessionId = api_get_session_id();
     $courseInfo = $this->connector->course;
     if (!empty($courseInfo)) {
         $coursePath = api_get_path(SYS_COURSE_PATH);
         $courseDir = $courseInfo['directory'] . '/document';
         $baseDir = $coursePath . $courseDir;
         // Creates shared folder
         if (!file_exists($baseDir . '/shared_folder')) {
             $title = get_lang('UserFolders');
             $folderName = '/shared_folder';
             //$groupId = 0;
             $visibility = 0;
             create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
         }
         // Creates user-course folder
         if (!file_exists($baseDir . '/shared_folder/sf_user_' . $userId)) {
             $title = $userInfo['complete_name'];
             $folderName = '/shared_folder/sf_user_' . $userId;
             $visibility = 1;
             create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
         }
     }
 }
 /**
  *
  * @param array $breadcrumbs
  */
 protected function setBreadcrumb($breadcrumbs)
 {
     $course = $this->getCourse();
     //$session =  $this->getSession();
     // Adding course breadcrumb.
     if (!empty($course)) {
         $courseBreadcrumb = array('name' => \Display::return_icon('home.png') . ' ' . $course->getTitle(), 'url' => array('route' => 'course', 'routeParameters' => array('cidReq' => $course->getCode(), 'id_session' => api_get_session_id())));
         array_unshift($breadcrumbs, $courseBreadcrumb);
     }
     $app = $this->app;
     $app['main_breadcrumb'] = function ($app) use($breadcrumbs) {
         /** @var  \Knp\Menu\MenuItem $menu */
         $menu = $app['knp_menu.factory']->createItem('root', array('childrenAttributes' => array('class' => 'breadcrumb', 'currentClass' => 'active')));
         if (!empty($breadcrumbs)) {
             foreach ($breadcrumbs as $item) {
                 if (empty($item['url'])) {
                     $item['url'] = array();
                 }
                 $menu->addChild($item['name'], $item['url']);
             }
         }
         return $menu;
     };
     $matcher = new Matcher();
     $voter = new \Knp\Menu\Silex\Voter\RouteVoter();
     $voter->setRequest($this->getRequest());
     $matcher->addVoter($voter);
     $renderer = new \Knp\Menu\Renderer\TwigRenderer($this->get('twig'), 'bread.tpl', $matcher);
     $bread = $renderer->render($this->get('main_breadcrumb'), array('template' => 'default/layout/bread.tpl'));
     $app['breadcrumbs'] = $bread;
 }
 /**
  * @Route("/edit/{tool}")
  * @Method({"GET"})
  *
  * @param string $tool
  * @return Response
  */
 public function editAction($tool)
 {
     $message = null;
     // @todo use proper functions not api functions.
     $courseId = api_get_course_int_id();
     $sessionId = api_get_session_id();
     $tool = \Database::escape_string($tool);
     $TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO);
     $url = $this->generateUrl('introduction.controller:editAction', array('tool' => $tool, 'course' => api_get_course_id()));
     $form = $this->getForm($url, $tool);
     if ($form->validate()) {
         $values = $form->exportValues();
         $content = $values['content'];
         $sql = "REPLACE {$TBL_INTRODUCTION}\n                    SET c_id = {$courseId},\n                        id = '{$tool}',\n                        intro_text='" . \Database::escape_string($content) . "',\n                        session_id='" . intval($sessionId) . "'";
         \Database::query($sql);
         $message = \Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false);
     } else {
         $sql = "SELECT intro_text FROM {$TBL_INTRODUCTION}\n                    WHERE c_id = {$courseId} AND id='" . $tool . "' AND session_id = '" . intval($sessionId) . "'";
         $result = \Database::query($sql);
         $content = null;
         if (\Database::num_rows($result) > 0) {
             $row = \Database::fetch_array($result);
             $content = $row['intro_text'];
         }
         $form->setDefaults(array('content' => $content));
     }
     $this->getTemplate()->assign('content', $form->return_form());
     $this->getTemplate()->assign('message', $message);
     $response = $this->getTemplate()->renderLayout('layout_1_col.tpl');
     return new Response($response, 200, array());
 }
Пример #6
0
 /**
  * Checking user in DB
  * @param int $uid
  */
 public static function loginCheck($uid)
 {
     $_course = api_get_course_info();
     $uid = (int) $uid;
     $online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
     if (!empty($uid)) {
         $login_ip = '';
         if (!empty($_SERVER['REMOTE_ADDR'])) {
             $login_ip = Database::escape_string($_SERVER['REMOTE_ADDR']);
         }
         $login_date = api_get_utc_datetime();
         $access_url_id = 1;
         if (api_get_multiple_access_url() && api_get_current_access_url_id() != -1) {
             $access_url_id = api_get_current_access_url_id();
         }
         $session_id = api_get_session_id();
         // if the $_course array exists this means we are in a course and we have to store this in the who's online table also
         // to have the x users in this course feature working
         if (is_array($_course) && count($_course) > 0 && !empty($_course['id'])) {
             $query = "REPLACE INTO " . $online_table . " (login_id, login_user_id, login_date, login_ip, course, session_id, access_url_id)\n                          VALUES ({$uid}, {$uid}, '{$login_date}', '{$login_ip}', '" . $_course['id'] . "', '{$session_id}', '{$access_url_id}' )";
         } else {
             $query = "REPLACE INTO " . $online_table . " (login_id,login_user_id,login_date,login_ip, session_id, access_url_id)\n                          VALUES ({$uid},{$uid},'{$login_date}','{$login_ip}', '{$session_id}', '{$access_url_id}')";
         }
         Database::query($query);
     }
 }
 public function __construct()
 {
     $current_course = self::current_course();
     if ($current_course) {
         $this->defaults('c_id', self::current_course()->get_id());
     }
     $this->defaults('session_id', api_get_session_id());
 }
Пример #8
0
 /**
  * Returns the course parameters. If null default to the current user parameters.
  * 
  * @param string $course_code
  * @param string|int $session_id
  * @param string|int $group_id
  * @return type 
  */
 public static function course_params($course_code = null, $session_id = null, $group_id = null)
 {
     $course_code = is_null($course_code) ? api_get_course_id() : $course_code;
     $session_id = is_null($session_id) ? api_get_session_id() : $session_id;
     $session_id = $session_id ? $session_id : '0';
     $group_id = is_null($group_id) ? '' : $group_id;
     $group_id = $group_id ? $group_id : '0';
     return array('cidReq' => $course_code, 'id_session' => $session_id, 'gidReq' => $group_id);
 }
/**
 * Show the form to copy courses
 * @global string $returnLink
 * @global string $courseCode
 */
function displayForm()
{
    global $returnLink, $courseCode;
    $courseInfo = api_get_course_info();
    $sessionId = api_get_session_id();
    $userId = api_get_user_id();
    $sessions = SessionManager::getSessionsCoachedByUser($userId);
    $html = '';
    // Actions
    $html .= '<div class="actions">';
    // Link back to the documents overview
    $html .= '<a href="' . $returnLink . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('Maintenance'), '', ICON_SIZE_MEDIUM) . '</a>';
    $html .= '</div>';
    $html .= Display::return_message(get_lang('CopyCourseFromSessionToSessionExplanation'));
    $html .= '<form name="formulaire" method="post" action="' . api_get_self() . '?' . api_get_cidreq() . '" >';
    $html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%">';
    // Source
    $html .= '<tr><td width="15%"><b>' . get_lang('OriginCoursesFromSession') . ':</b></td>';
    $html .= '<td width="10%" align="left">' . api_get_session_name($sessionId) . '</td>';
    $html .= '<td width="50%">';
    $html .= "{$courseInfo['title']} ({$courseInfo['code']})" . '</td></tr>';
    // Destination
    $html .= '<tr><td width="15%"><b>' . get_lang('DestinationCoursesFromSession') . ':</b></td>';
    $html .= '<td width="10%" align="left"><div id="ajax_sessions_list_destination">';
    $html .= '<select name="sessions_list_destination" onchange="javascript: xajax_searchCourses(this.value,\'destination\');">';
    if (empty($sessions)) {
        $html .= '<option value = "0">' . get_lang('ThereIsNotStillASession') . '</option>';
    } else {
        $html .= '<option value = "0">' . get_lang('SelectASession') . '</option>';
        foreach ($sessions as $session) {
            if ($session['id'] == $sessionId) {
                continue;
            }
            if (!SessionManager::sessionHasCourse($session['id'], $courseCode)) {
                continue;
            }
            $html .= '<option value="' . $session['id'] . '">' . $session['name'] . '</option>';
        }
    }
    $html .= '</select ></div></td>';
    $html .= '<td width="50%">';
    $html .= '<div id="ajax_list_courses_destination">';
    $html .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" ></select></div></td>';
    $html .= '</tr></table>';
    $html .= "<fieldset>";
    $html .= '<legend>' . get_lang('TypeOfCopy') . ' <small>(' . get_lang('CopyOnlySessionItems') . ')</small></legend>';
    $html .= '<label class="radio"><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>';
    $html .= get_lang('FullCopy') . '</label>';
    $html .= '<label class="radio"><input type="radio" id="copy_option_2" name="copy_option" value="select_items"/>';
    $html .= ' ' . get_lang('LetMeSelectItems') . '</label><br/>';
    $html .= "</fieldset>";
    $html .= '<button class="save" type="submit" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;">' . get_lang('CopyCourse') . '</button>';
    $html .= '</form>';
    echo $html;
}
Пример #10
0
 public function save($params, $show_query = null)
 {
     $course_info = api_get_course_info();
     $params['session_id'] = api_get_session_id();
     $params['category_id'] = isset($params['category_id']) ? $params['category_id'] : 0;
     $id = parent::save($params, $show_query);
     if (!empty($id)) {
         api_item_property_update($course_info, TOOL_LINK, $id, 'LinkAdded', api_get_user_id());
     }
     return $id;
 }
Пример #11
0
 /**
  * Room constructor.
  */
 public function __construct()
 {
     $this->table = \Database::get_main_table('plugin_openmeetings');
     $this->name = 'C' . api_get_real_course_id() . '-' . api_get_session_id();
     $accessUrl = api_get_access_url(api_get_current_access_url_id());
     $this->externalRoomType = substr($accessUrl['url'], strpos($accessUrl['url'], '://') + 3, -1);
     if (strcmp($this->externalRoomType, 'localhost') == 0) {
         $this->externalRoomType = substr(api_get_path(WEB_PATH), strpos(api_get_path(WEB_PATH), '://') + 3, -1);
     }
     $this->externalRoomType = 'chamilolms.' . $this->externalRoomType;
 }
Пример #12
0
 function __construct($data = null)
 {
     if ($data) {
         foreach ($this as $key => $value) {
             if (isset($data->{$key})) {
                 $this->{$key} = $data->{$key};
             }
         }
     }
     $this->defaults('session_id', api_get_session_id());
 }
Пример #13
0
function GetFoldersAndFiles($resourceType, $currentFolder)
{
    // Map the virtual path to the local server path.
    $sServerDir = ServerMapFolder($resourceType, $currentFolder, 'GetFoldersAndFiles');
    // Arrays that will hold the folders and files names.
    $aFolders = array();
    $aFiles = array();
    $oCurrentFolder = @opendir($sServerDir);
    $in_group = api_is_in_group();
    if ($currentFolder == '/shared_folder/' || $currentFolder == '/shared_folder_session_' . api_get_session_id() . '/') {
        $in_shared_folder = true;
    } else {
        $in_shared_folder = false;
    }
    $user_id = api_get_user_id();
    if ($oCurrentFolder !== false) {
        while ($sFile = readdir($oCurrentFolder)) {
            $is_dir = @is_dir($sServerDir . $sFile);
            if ($sFile != '.' && $sFile != '..' && strpos($sFile, '_DELETED_') === false && strpos($sFile, 'chat_files') === false && strpos($sFile, 'HotPotatoes_files') === false && ($in_group || !$in_group && strpos($sFile, '_groupdocs') === false) && (!$in_shared_folder || $in_shared_folder && (!$is_dir || $is_dir && $sFile == $user_id)) && $sFile != '.thumbs' && strpos($sFile, '.editor_') === false && $sFile != '.svn') {
                if ($is_dir) {
                    $aFolders[] = '<Folder name="' . ConvertToXmlAttribute($sFile) . '" />';
                } else {
                    $iFileSize = @filesize($sServerDir . $sFile);
                    if (!$iFileSize) {
                        $iFileSize = 0;
                    }
                    if ($iFileSize > 0) {
                        $iFileSize = round($iFileSize / 1024);
                        if ($iFileSize < 1) {
                            $iFileSize = 1;
                        }
                    }
                    $aFiles[] = '<File name="' . ConvertToXmlAttribute($sFile) . '" size="' . $iFileSize . '" />';
                }
            }
        }
        closedir($oCurrentFolder);
    }
    // Send the folders
    natcasesort($aFolders);
    echo '<Folders>';
    foreach ($aFolders as $sFolder) {
        echo $sFolder;
    }
    echo '</Folders>';
    // Send the files
    natcasesort($aFiles);
    echo '<Files>';
    foreach ($aFiles as $sFiles) {
        echo $sFiles;
    }
    echo '</Files>';
}
Пример #14
0
 /**
  * Setting parameters: course id, session id, etc
  * @param    array
  */
 public function set_parameters($params = array())
 {
     //Setting course id
     if (isset($params['course_id'])) {
         $this->course_id = intval($params['course_id']);
     } else {
         $this->course_id = $params['course_id'] = api_get_course_int_id();
     }
     //Setting course info
     if (isset($this->course_id)) {
         $this->course_info = api_get_course_info_by_id($this->course_id);
     }
     //Setting session id
     if (isset($params['session_id'])) {
         $this->session_id = intval($params['session_id']);
     } else {
         $this->session_id = $params['session_id'] = api_get_session_id();
     }
     //Setting user ids
     if (isset($params['user_id'])) {
         $this->user_id = intval($params['user_id']);
     } else {
         $this->user_id = $params['user_id'] = api_get_user_id();
     }
     //Setting user ids
     if (isset($params['exercise_id'])) {
         $this->exercise_id = intval($params['exercise_id']);
     } else {
         $this->exercise_id = 0;
     }
     //Setting user ids
     if (isset($params['question_id'])) {
         $this->question_id = intval($params['question_id']);
     } else {
         $this->question_id = 0;
     }
     $this->can_edit = false;
     if (api_is_allowed_to_edit()) {
         $this->can_edit = true;
     } else {
         if ($this->user_id == api_get_user_id()) {
             $this->can_edit = true;
         }
     }
     //Settings the params array
     $this->params = $params;
     $this->store_path = api_get_path(SYS_COURSE_PATH) . $this->course_info['path'] . '/exercises/';
     $this->create_user_folder();
     $this->store_path = $this->store_path . implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)) . '/';
     $this->filename = $this->generate_filename();
     $this->store_filename = $this->store_path . $this->filename;
 }
Пример #15
0
 /**
  * @param int $courseId
  * @param int $announcement
  */
 public function __construct($courseId, $announcement)
 {
     if (!empty($courseId)) {
         $course = api_get_course_info_by_id($courseId);
     } else {
         $course = api_get_course_info();
     }
     $this->course = $course;
     $this->session_id = api_get_session_id();
     if (is_numeric($announcement)) {
         $announcement = AnnouncementManager::get_by_id($course['real_id'], $announcement);
     }
     $this->announcement = $announcement;
 }
 /**
  * @param int $course
  * @param int $announcement
  */
 public function __construct($course, $announcement)
 {
     if (empty($course)) {
         $course = api_get_course_int_id();
         $course = CourseManager::get_course_information_by_id($course);
     } else {
         if (is_numeric($course)) {
             $course = CourseManager::get_course_information_by_id($course);
         }
     }
     $this->course = $course;
     $this->session_id = api_get_session_id();
     if (is_numeric($announcement)) {
         $announcement = AnnouncementManager::get_by_id($course['real_id'], $announcement);
     }
     $this->announcement = $announcement;
 }
 private function get_announcements($username, $course_code, $announcement_id = 0)
 {
     $session_id = api_get_session_id();
     $condition_session = api_get_session_condition($session_id);
     $announcement_id = $announcement_id == 0 ? "" : "AND announcement.id=" . $announcement_id;
     $user_id = UserManager::get_user_id_from_username($username);
     //$listOfCourses = CourseManager::get_course_information_by_id($course_id);
     $course_info = CourseManager::get_course_information($course_code);
     $course_db = $course_info['db_name'];
     $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db);
     $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT, $course_db);
     $maximum = '12';
     $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $user_id);
     if (api_get_group_id() == 0) {
         $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "'" . "OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ";
     } else {
         $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "'" . "OR ip.to_group_id IN (0, " . api_get_group_id() . ")) ";
     }
     // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
     if (is_array($group_memberships) && count($group_memberships) > 0) {
         $sql = "SELECT\n                            announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            AND ip.visibility='1'\n                            {$announcement_id}\n                            {$cond_user_id}\n                            {$condition_session}\n                            GROUP BY ip.ref\n                            ORDER BY display_order DESC\n                            LIMIT 0,{$maximum}";
     } else {
         // the user is not member of any group
         // this is an identified user => show the general announcements AND his personal announcements
         if ($user_id) {
             if (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) {
                 $cond_user_id = " AND (ip.lastedit_user_id = '" . api_get_user_id() . "' OR ( ip.to_user_id='" . $user_id . "' OR ip.to_group_id='0')) ";
             } else {
                 $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "' OR ip.to_group_id='0') ";
             }
             $sql = "SELECT\n                                    announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                                    FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                                    WHERE announcement.id = ip.ref\n                                    AND ip.tool='announcement'\n                                    AND ip.visibility='1'\n                                    {$announcement_id}\n                                    {$cond_user_id}\n                                    {$condition_session}\n                                    GROUP BY ip.ref\n                                    ORDER BY display_order DESC\n                                    LIMIT 0,{$maximum}";
         } else {
             if (api_get_course_setting('allow_user_edit_announcement')) {
                 $cond_user_id = " AND (ip.lastedit_user_id = '" . api_get_user_id() . "' OR ip.to_group_id='0') ";
             } else {
                 $cond_user_id = " AND ip.to_group_id='0' ";
             }
             // the user is not identiefied => show only the general announcements
             $sql = "SELECT\n                                    announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                                    FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                                    WHERE announcement.id = ip.ref\n                                    AND ip.tool='announcement'\n                                    AND ip.visibility='1'\n                                    AND ip.to_group_id='0'\n                                    {$announcement_id}\n                                    {$condition_session}\n                                    GROUP BY ip.ref\n                                    ORDER BY display_order DESC\n                                    LIMIT 0,{$maximum}";
         }
     }
     $result = Database::query($sql);
     return $result;
 }
Пример #18
0
 /**
  * Update a link in the database
  * @param int $linkId The ID of the link to update
  * @param string $linkUrl The new URL to be saved
  * @param int   Course ID
  * @param int   Session ID
  * @return bool
  */
 public function updateLink($linkId, $linkUrl, $courseId = null, $sessionId = null)
 {
     $tblLink = Database::get_course_table(TABLE_LINK);
     $linkUrl = Database::escape_string($linkUrl);
     $linkId = intval($linkId);
     if (is_null($courseId)) {
         $courseId = api_get_course_int_id();
     }
     $courseId = intval($courseId);
     if (is_null($sessionId)) {
         $sessionId = api_get_session_id();
     }
     $sessionId = intval($sessionId);
     if ($linkUrl != '') {
         $sql = "UPDATE {$tblLink} SET url = '{$linkUrl}'\n                    WHERE id = {$linkId} AND c_id = {$courseId} AND session_id = {$sessionId}";
         $resLink = Database::query($sql);
         return $resLink;
     }
     return false;
 }
/**
 * returns users within a course given by param
 * @param $course_id
 */
function get_users_in_course($courseId)
{
    $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
    $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
    $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname ASC' : ' ORDER BY lastname, firstname ASC';
    $current_session = api_get_session_id();
    $courseId = Database::escape_string($courseId);
    if (!empty($current_session)) {
        $sql = "SELECT user.user_id, user.username, lastname, firstname, official_code\n\t\t\t \tFROM {$tbl_session_course_user} as scru, {$tbl_user} as user\n\t\t\t \tWHERE scru.id_user=user.user_id\n                    AND scru.status=0\n                    AND scru.c_id ='{$courseId}' AND id_session = '{$current_session}'\n\t\t\t \t{$order_clause} ";
    } else {
        $sql = 'SELECT user.user_id, user.username, lastname, firstname, official_code
                FROM ' . $tbl_course_user . ' as course_rel_user, ' . $tbl_user . ' as user
                WHERE   course_rel_user.user_id=user.user_id AND
                        course_rel_user.status=' . STUDENT . ' AND
                        course_rel_user.c_id = ' . $courseId . '
                ' . $order_clause;
    }
    $result = Database::query($sql);
    return get_user_array_from_sql_result($result);
}
Пример #20
0
 /**
  * Export the given HTML to PDF, using a global template
  * @param string the HTML content
  * @uses export/table_pdf.tpl
  */
 function html_to_pdf_with_template($content)
 {
     Display::display_no_header();
     //Assignments
     Display::$global_template->assign('pdf_content', $content);
     $organization = api_get_setting('Institution');
     $img = api_get_path(SYS_CODE_PATH) . 'css/' . api_get_visual_theme() . '/images/header-logo.png';
     if (file_exists($img)) {
         $img = api_get_path(WEB_CODE_PATH) . 'css/' . api_get_visual_theme() . '/images/header-logo.png';
         $organization = "<img src='{$img}'>";
     } else {
         if (!empty($organization)) {
             $organization = '<h2 align="left">' . $organization . '</h2>';
         }
     }
     Display::$global_template->assign('organization', $organization);
     //Showing only the current teacher/admin instead the all teacherlist name see BT#4080
     $user_info = api_get_user_info();
     $teacher_list = $user_info['complete_name'];
     $session_name = api_get_session_name(api_get_session_id());
     if (!empty($session_name)) {
         Display::$global_template->assign('pdf_session', $session_name);
     }
     Display::$global_template->assign('pdf_course', $this->params['course_code']);
     Display::$global_template->assign('pdf_date', api_format_date(api_get_utc_datetime(), DATE_TIME_FORMAT_LONG));
     Display::$global_template->assign('pdf_teachers', $teacher_list);
     Display::$global_template->assign('pdf_title', $this->params['pdf_title']);
     Display::$global_template->assign('add_signatures', $this->params['add_signatures']);
     //Getting template
     $tpl = Display::$global_template->get_template('export/table_pdf.tpl');
     $html = Display::$global_template->fetch($tpl);
     $html = api_utf8_encode($html);
     $css_file = api_get_path(TO_SYS, WEB_CSS_PATH) . '/print.css';
     $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
     self::content_to_pdf($html, $css, $this->params['filename'], $this->params['course_code']);
 }
Пример #21
0
    $filename = FileManager::disable_dangerous_file($filename);
    return !file_exists($filepath . $filename . '.html');
}
// Add group to the form
if ($is_certificate_mode) {
    $form->addElement('text', 'title', get_lang('CertificateName'), array('id' => 'document_title'));
} else {
    $form->addElement('text', 'title', get_lang('Title'), array('id' => 'document_title'));
}
// Show read-only box only in groups
if (!empty($groupId)) {
    $group[] = $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
}
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists');
$current_session_id = api_get_session_id();
$form->add_html_editor('content', '', false, false, $html_editor_config);
// Comment-field
$folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit);
// If we are not in the certificates creation, display a folder chooser for the
// new document created
if (!$is_certificate_mode && !is_my_shared_folder($_user['user_id'], $dir, $current_session_id)) {
    $folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit);
    $parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory')));
    // Following two conditions copied from document.inc.php::build_directory_selector()
    $folder_titles = array();
    if (is_array($folders)) {
        $escaped_folders = array();
        foreach ($folders as $key => &$val) {
            //Hide some folders
            if ($val == '/HotPotatoes_files' || $val == '/certificates' || basename($val) == 'css') {
Пример #22
0
 /**
  * @param string $courseCode
  * @param array $rules
  * @param array $columns
  * @param array $column_model
  * @return array
  */
 public static function getRules($courseCode, &$rules, &$columns, &$column_model, $questionFields, $checkFields = false)
 {
     // sessions
     // course
     // categories
     // exercises
     // difficult
     // type
     if (empty($courseCode)) {
         // Session.
         $sessionList = SessionManager::get_sessions_by_general_coach(api_get_user_id());
         $fields = array();
         if (!empty($sessionList)) {
             $new_options = array();
             $new_options[] = "-1:" . get_lang('All');
             foreach ($sessionList as $session) {
                 $new_options[] = "{$session['id']}:{$session['name']}";
             }
             $string = implode(';', $new_options);
             $fields[] = array('field_display_text' => get_lang('Session'), 'field_variable' => 'session_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
         }
     } else {
         // $courseList = array(api_get_course_info());
         //$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     }
     // Courses.
     $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($courseList as $course) {
             $new_options[] = "{$course['id']}:{$course['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Course'), 'field_variable' => 'c_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Categories.
     $string = null;
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         // Global categories
         // @todo use tree view
         $categories = Testcategory::getCategoriesIdAndName(0);
         if (!empty($categories)) {
             foreach ($categories as $id => $category) {
                 if (!empty($id)) {
                     $new_options[] = "{$id}:[Global] - " . $category;
                 }
             }
         }
         foreach ($courseList as $course) {
             $categories = Testcategory::getCategoriesIdAndName($course['real_id']);
             if (!empty($categories)) {
                 foreach ($categories as $id => $category) {
                     if (!empty($id)) {
                         $new_options[] = "{$id}:" . $course['title'] . " - " . $category;
                     }
                 }
             }
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Category'), 'field_variable' => 'category_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $course = api_get_course_int_id();
     $sessionId = api_get_session_id();
     // Exercises.
     $exerciseList = ExerciseLib::get_all_exercises_for_course_id($sessionId, $course);
     if (!empty($exerciseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         $new_options[] = "0:" . get_lang('Orphan');
         foreach ($exerciseList as $exercise) {
             $new_options[] = "{$exercise['iid']}:{$exercise['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Exercise'), 'field_variable' => 'exercise_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Question type.
     $questionList = Question::get_question_type_list();
     if (!empty($questionList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($questionList as $key => $question) {
             $new_options[] = "{$key}:" . get_lang($question['1']);
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('AnswerType'), 'field_variable' => 'question_type', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Difficult.
     $levels = Question::get_default_levels();
     if (!empty($levels)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($levels as $key => $level) {
             $new_options[] = "{$key}:{$level}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Difficulty'), 'field_variable' => 'difficulty', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $questionFieldsKeys = array();
     if (!empty($questionFields)) {
         foreach ($questionFields as $question) {
             $questionFieldsKeys[] = $question['field'];
         }
     }
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $search_options = array();
             $type = 'text';
             if (in_array($field['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
                 $type = 'select';
                 $search_options['sopt'] = array('eq', 'ne');
                 //equal not equal
                 //$search_options['sopt'] = array('cn', 'nc'); //contains not contains
             } else {
                 $search_options['sopt'] = array('cn', 'nc');
                 //contains not contains
             }
             $search_options['searchhidden'] = 'true';
             $search_options['defaultValue'] = isset($search_options['field_default_value']) ? $search_options['field_default_value'] : null;
             $search_options['value'] = $field['field_options'];
             $column_model[] = array('name' => 'question_' . $field['field_variable'], 'index' => 'question_' . $field['field_variable'], 'width' => '100', 'hidden' => 'true', 'search' => 'true', 'stype' => $type, 'searchoptions' => $search_options);
             $columns[] = $field['field_display_text'];
             $rules[] = array('field' => 'question_' . $field['field_variable'], 'op' => 'eq');
         }
     }
     return $rules;
 }
 function add_docs_to_visio($files = array())
 {
     global $_course;
     foreach ($files as $file) {
         list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents).
         $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
         $slide_name = str_replace('&rsquo;', '\'', $slide_name);
         $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);
         $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());
         $did = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name);
         if ($did) {
             api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, null, null, null, api_get_session_id());
         }
     }
 }
Пример #24
0
/**
 * Handles a given Excel spreadsheets as in the template provided
 */
function lp_upload_quiz_action_handling()
{
    global $debug;
    $_course = api_get_course_info();
    $courseId = $_course['real_id'];
    if (!isset($_POST['submit_upload_quiz'])) {
        return;
    }
    // Get the extension of the document.
    $path_info = pathinfo($_FILES['user_upload_quiz']['name']);
    // Check if the document is an Excel document
    if ($path_info['extension'] != 'xls') {
        return;
    }
    // Read the Excel document
    $data = new Spreadsheet_Excel_Reader();
    // Set output Encoding.
    $data->setOutputEncoding(api_get_system_encoding());
    // Reading the xls document.
    $data->read($_FILES['user_upload_quiz']['tmp_name']);
    $correctScore = isset($_POST['correct_score']) ? $_POST['correct_score'] : null;
    $incorrectScore = isset($_POST['incorrect_score']) ? $_POST['incorrect_score'] : null;
    $useCustomScore = isset($_POST['user_custom_score']) ? true : false;
    $propagateNegative = 0;
    if ($useCustomScore && !empty($incorrectScore)) {
        if ($incorrectScore < 0) {
            $propagateNegative = 1;
        }
    }
    // Variables
    $quiz_index = 0;
    $question_title_index = array();
    $question_name_index_init = array();
    $question_name_index_end = array();
    $score_index = array();
    $feedback_true_index = array();
    $feedback_false_index = array();
    $number_questions = 0;
    $question_description_index = array();
    // Reading all the first column items sequentially to create breakpoints
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
        if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) {
            $quiz_index = $i;
            // Quiz title position, only occurs once
        } elseif ($data->sheets[0]['cells'][$i][1] == 'Question') {
            $question_title_index[] = $i;
            // Question title position line
            $question_name_index_init[] = $i + 1;
            // Questions name 1st position line
            $number_questions++;
        } elseif ($data->sheets[0]['cells'][$i][1] == 'Score') {
            $question_name_index_end[] = $i - 1;
            // Question name position
            $score_index[] = $i;
            // Question score position
        } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackTrue') {
            $feedback_true_index[] = $i;
            // FeedbackTrue position (line)
        } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackFalse') {
            $feedback_false_index[] = $i;
            // FeedbackFalse position (line)
        } elseif ($data->sheets[0]['cells'][$i][1] == 'EnrichQuestion') {
            $question_description_index[] = $i;
        }
    }
    // Variables
    $quiz = array();
    $question = array();
    $new_answer = array();
    $score_list = array();
    $feedback_true_list = array();
    $feedback_false_list = array();
    $question_description = array();
    // Getting questions.
    $k = $z = $q = $l = $m = 0;
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
        if (is_array($data->sheets[0]['cells'][$i])) {
            $column_data = $data->sheets[0]['cells'][$i];
            // Fill all column with data to have a full array
            for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) {
                if (empty($column_data[$x])) {
                    $data->sheets[0]['cells'][$i][$x] = '';
                }
            }
            // Array filled with data
            $column_data = $data->sheets[0]['cells'][$i];
        } else {
            $column_data = '';
        }
        // Fill quiz data
        if ($quiz_index == $i) {
            // The title always in the first position
            $quiz = $column_data;
        } elseif (in_array($i, $question_title_index)) {
            //a complete line where 1st column is 'Question'
            $question[$k] = $column_data;
            $k++;
        } elseif (in_array($i, $score_index)) {
            //a complete line where 1st column is 'Score'
            $score_list[$z] = $column_data;
            $z++;
        } elseif (in_array($i, $feedback_true_index)) {
            //a complete line where 1st column is 'FeedbackTrue'
            $feedback_true_list[$q] = $column_data;
            $q++;
        } elseif (in_array($i, $feedback_false_index)) {
            //a complete line where 1st column is 'FeedbackFalse' for wrong answers
            $feedback_false_list[$l] = $column_data;
            $l++;
        } elseif (in_array($i, $question_description_index)) {
            //a complete line where 1st column is 'EnrichQuestion'
            $question_description[$m] = $column_data;
            $m++;
        }
    }
    // Get answers
    for ($i = 0; $i < count($question_name_index_init); $i++) {
        for ($j = $question_name_index_init[$i]; $j <= $question_name_index_end[$i]; $j++) {
            if (is_array($data->sheets[0]['cells'][$j])) {
                $column_data = $data->sheets[0]['cells'][$j];
                // Fill all column with data
                for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) {
                    if (empty($column_data[$x])) {
                        $data->sheets[0]['cells'][$j][$x] = '';
                    }
                }
                $column_data = $data->sheets[0]['cells'][$j];
                // Array filled of data
                if (is_array($data->sheets[0]['cells'][$j]) && count($data->sheets[0]['cells'][$j]) > 0) {
                    $new_answer[$i][$j] = $data->sheets[0]['cells'][$j];
                }
            }
        }
    }
    // Quiz title.
    $quiz_title = $quiz[2];
    if ($quiz_title != '') {
        // Variables
        $type = 2;
        $random = $active = $results = $max_attempt = $expired_time = 0;
        // Make sure feedback is enabled (3 to disable), otherwise the fields
        // added to the XLS are not shown, which is confusing
        $feedback = 0;
        // Quiz object
        $exercise = new Exercise();
        //
        $quiz_id = $exercise->createExercise($quiz_title, $expired_time, $type, $random, $active, $results, $max_attempt, $feedback, $propagateNegative);
        if ($quiz_id) {
            // insert into the item_property table
            api_item_property_update($_course, TOOL_QUIZ, $quiz_id, 'QuizAdded', api_get_user_id());
            // Import questions.
            for ($i = 0; $i < $number_questions; $i++) {
                // Question name
                $question_title = $question[$i][2];
                $question_description_text = "<p></p>";
                if (isset($question_description[$i][2])) {
                    // Question description.
                    $question_description_text = "<p>" . $question_description[$i][2] . "</p>";
                }
                // Unique answers are the only question types available for now
                // through xls-format import
                $question_id = null;
                $detectQuestionType = detectQuestionType($new_answer[$i], $score_list);
                /** @var Question $answer */
                switch ($detectQuestionType) {
                    case FREE_ANSWER:
                        $answer = new FreeAnswer();
                        break;
                    case GLOBAL_MULTIPLE_ANSWER:
                        $answer = new GlobalMultipleAnswer();
                        break;
                    case MULTIPLE_ANSWER:
                        $answer = new MultipleAnswer();
                        break;
                    case UNIQUE_ANSWER:
                    default:
                        $answer = new UniqueAnswer();
                        break;
                }
                if ($question_title != '') {
                    $question_id = $answer->create_question($quiz_id, $question_title, $question_description_text, 0, $answer->type);
                }
                $total = 0;
                if (is_array($new_answer[$i]) && !empty($question_id)) {
                    $id = 1;
                    $answers_data = $new_answer[$i];
                    $globalScore = null;
                    $objAnswer = new Answer($question_id, $courseId);
                    $globalScore = $score_list[$i][3];
                    // Calculate the number of correct answers to divide the
                    // score between them when importing from CSV
                    $numberRightAnswers = 0;
                    foreach ($answers_data as $answer_data) {
                        if (strtolower($answer_data[3]) == 'x') {
                            $numberRightAnswers++;
                        }
                    }
                    foreach ($answers_data as $answer_data) {
                        $answerValue = $answer_data[2];
                        $correct = 0;
                        $score = 0;
                        if (strtolower($answer_data[3]) == 'x') {
                            $correct = 1;
                            $score = $score_list[$i][3];
                            $comment = $feedback_true_list[$i][2];
                        } else {
                            $comment = $feedback_false_list[$i][2];
                            $floatVal = (double) $answer_data[3];
                            if (is_numeric($floatVal)) {
                                $score = $answer_data[3];
                            }
                        }
                        if ($useCustomScore) {
                            if ($correct) {
                                $score = $correctScore;
                            } else {
                                $score = $incorrectScore;
                            }
                        }
                        // Fixing scores:
                        switch ($detectQuestionType) {
                            case GLOBAL_MULTIPLE_ANSWER:
                                $score /= $numberRightAnswers;
                                break;
                            case UNIQUE_ANSWER:
                                break;
                            case MULTIPLE_ANSWER:
                                if (!$correct) {
                                    //$total = $total - $score;
                                }
                                break;
                        }
                        $objAnswer->createAnswer($answerValue, $correct, $comment, $score, $id);
                        $total += $score;
                        $id++;
                    }
                    $objAnswer->save();
                    $questionObj = Question::read($question_id, $courseId);
                    switch ($detectQuestionType) {
                        case GLOBAL_MULTIPLE_ANSWER:
                            $questionObj->updateWeighting($globalScore);
                            break;
                        case UNIQUE_ANSWER:
                        case MULTIPLE_ANSWER:
                        default:
                            $questionObj->updateWeighting($total);
                            break;
                    }
                    $questionObj->save();
                } else {
                    if ($detectQuestionType === FREE_ANSWER) {
                        $questionObj = Question::read($question_id, $courseId);
                        $globalScore = $score_list[$i][3];
                        $questionObj->updateWeighting($globalScore);
                        $questionObj->save();
                    }
                }
            }
        }
        if (isset($_SESSION['lpobject'])) {
            if ($debug > 0) {
                error_log('New LP - SESSION[lpobject] is defined', 0);
            }
            $oLP = unserialize($_SESSION['lpobject']);
            if (is_object($oLP)) {
                if ($debug > 0) {
                    error_log('New LP - oLP is object', 0);
                }
                if (empty($oLP->cc) or $oLP->cc != api_get_course_id()) {
                    if ($debug > 0) {
                        error_log('New LP - Course has changed, discard lp object', 0);
                    }
                    $oLP = null;
                    Session::erase('oLP');
                    Session::erase('lpobject');
                } else {
                    $_SESSION['oLP'] = $oLP;
                }
            }
        }
        if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) {
            $previous = $_SESSION['oLP']->select_previous_item_id();
            $parent = 0;
            // Add a Quiz as Lp Item
            $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, '');
            // Redirect to home page for add more content
            header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id']));
            exit;
        } else {
            //  header('location: exercise.php?' . api_get_cidreq());
            echo '<script>window.location.href = "' . api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidReq() . '&exerciseId=' . $quiz_id . '&session_id=' . api_get_session_id() . '"</script>';
        }
    }
}
 /**
  * Get URL where to go to if the user clicks on the link.
  */
 public function get_link()
 {
     $url = api_get_path(WEB_PATH) . 'main/newscorm/lp_controller.php?cidReq=' . $this->get_course_code() . '&gradebook=view';
     $session_id = api_get_session_id();
     if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) {
         $url .= '&action=view&session_id=' . $session_id . '&lp_id=' . $this->get_ref_id();
     } else {
         $url .= '&action=build&session_id=' . $session_id . '&lp_id=' . $this->get_ref_id();
     }
     return $url;
 }
Пример #26
0
    /**
     * Set footer parameters
     */
    private function set_footer_parameters()
    {
        global $_configuration;

        //Show admin data
        //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));

        if (api_get_setting('show_administrator_data') == 'true') {
            //Administrator name
            $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
                    api_get_setting('emailAdministrator'),
                    api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
                );
            $this->assign('administrator_name', $administrator_data);
        }

        //Loading footer extra content
        if (!api_is_platform_admin()) {
            $extra_footer = trim(api_get_setting('footer_extra_content'));
            if (!empty($extra_footer)) {
                $this->assign('footer_extra_content', $extra_footer);
            }
        }

        //Tutor name
        if (api_get_setting('show_tutor_data') == 'true') {
            // Course manager
            $id_course  = api_get_course_id();
            $id_session = api_get_session_id();
            if (isset($id_course) && $id_course != -1) {
                $tutor_data = '';
                if ($id_session != 0) {
                    $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
                    $email_link   = array();
                    foreach ($coachs_email as $coach) {
                        $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
                    }
                    if (count($coachs_email) > 1) {
                        $tutor_data .= get_lang('Coachs').' : ';
                        $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
                    } elseif (count($coachs_email) == 1) {
                        $tutor_data .= get_lang('Coach').' : ';
                        $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
                    } elseif (count($coachs_email) == 0) {
                        $tutor_data .= '';
                    }
                }
                $this->assign('session_teachers', $tutor_data);
            }
        }

        if (api_get_setting('show_teacher_data') == 'true') {
            // course manager
            $id_course = api_get_course_id();
            if (isset($id_course) && $id_course != -1) {
                $teacher_data = '';
                $mail         = CourseManager::get_emails_of_tutors_to_course($id_course);
                if (!empty($mail)) {
                    $teachers_parsed = array();
                    foreach ($mail as $value) {
                        foreach ($value as $email => $name) {
                            $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
                        }
                    }
                    $label = get_lang('Teacher');
                    if (count($mail) > 1) {
                        $label = get_lang('Teachers');
                    }
                    $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
                }
                $this->assign('teachers', $teacher_data);
            }
        }
        /* $stats = '';
          $this->assign('execution_stats', $stats); */
    }
 /**
  * Get URL where to go to if the user clicks on the link.
  * First we go to exercise_jump.php and then to the result page.
  * Check this php file for more info.
  */
 public function get_link()
 {
     //status student
     $user_id = api_get_user_id();
     //$course_code = $this->get_course_code();
     $status_user = api_get_status_of_user_in_course($user_id, $this->course_id);
     $session_id = api_get_session_id();
     $url = api_get_path(WEB_PATH) . 'main/gradebook/exercise_jump.php?session_id=' . $session_id . '&cidReq=' . $this->get_course_code() . '&gradebook=view&exerciseId=' . $this->get_ref_id();
     if (!api_is_allowed_to_edit() && $this->calc_score(api_get_user_id()) == null || $status_user != 1) {
         $url .= '&amp;doexercise=' . $this->get_ref_id();
     }
     return $url;
 }
Пример #28
0
         $line = '';
         $title_line = get_lang('Name') . ";" . get_lang('FirstAccess') . ";" . get_lang('LastAccess') . ";" . get_lang('Visited') . "\n";
         for ($j = 0; $j < count($results); $j++) {
             // BEGIN % visited
             // sum of all items (= multiple learningpaths + SCORM imported paths)
             $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) FROM {$tbl_learnpath_item_view} iv " . "INNER JOIN {$tbl_learnpath_view} v\n                        ON iv.lp_view_id = v.id " . "WHERE\n                        \tv.c_id = {$course_id} AND\n                        \tiv.c_id = {$course_id} AND\n                \t\tv.user_id = " . $results[$j][0];
             $total_lpath_items = StatsUtils::getOneResult($sql);
             // sum of all completed items (= multiple learningpaths + SCORM imported paths)
             $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) " . "FROM {$tbl_learnpath_item_view} iv " . "INNER JOIN {$tbl_learnpath_view} v ON iv.lp_view_id = v.id " . "WHERE\n                        \tv.c_id = {$course_id} AND\n                        \tiv.c_id = {$course_id} AND\n                        \tv.user_id = " . $results[$j][0] . " " . "AND (status = 'completed' OR status='passed')";
             $total_lpath_items_completed = StatsUtils::getOneResult($sql);
             // calculation & bgcolor setting
             $lpath_pct_completed = empty($total_lpath_items) ? "-" : round($total_lpath_items_completed / $total_lpath_items * 100);
             // END % visited
             // BEGIN first/last access
             // first access
             $sql = "SELECT access_date FROM {$TABLETRACK_ACCESS_2}\n                        WHERE access_user_id = '" . $results[$j][0] . "' AND c_id = '" . $courseId . "' AND access_tool = 'learnpath' AND access_session_id = '" . api_get_session_id() . "'\n                        ORDER BY access_id ASC LIMIT 1";
             $first_access = StatsUtils::getOneResult($sql);
             $first_access = empty($first_access) ? "-" : date('d.m.y', strtotime($first_access));
             // last access
             $sql = "SELECT access_date FROM {$TABLETRACK_ACCESS} WHERE access_user_id = '" . $results[$j][0] . "' AND c_id = '" . $courseId . "' AND access_tool = 'learnpath'";
             $last_access = StatsUtils::getOneResult($sql);
             $last_access = empty($last_access) ? "-" : date('d.m.y', strtotime($last_access));
             // END first/last access
             // BEGIN presentation of data
             $line .= $results[$j][1] . " " . $results[$j][2] . ";" . $first_access . ";" . $last_access . ";" . $lpath_pct_completed . "\n";
             // END presentation of data
         }
     } else {
         $line = get_lang('NoResult') . "\n";
     }
 }
        }
    }
}
$token = Security::get_token();
echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
//@todo replace all this code with something like get_total_weight()
$cats = Category::load($cat_id, null, null, null, null, null, false);
if (!empty($cats)) {
    //with this fix the teacher only can view 1 gradebook
    if (api_is_platform_admin()) {
        $stud_id = api_is_allowed_to_edit() ? null : api_get_user_id();
    } else {
        $stud_id = api_get_user_id();
    }
    $total_weight = $cats[0]->get_weight();
    $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id());
    $alleval = $cats[0]->get_evaluations($stud_id);
    $alllink = $cats[0]->get_links($stud_id);
    $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink);
    $total_resource_weight = 0;
    if (!empty($datagen)) {
        $data_array = $datagen->get_data(GradebookDataGenerator::GDG_SORT_NAME, 0, null, true);
        if (!empty($data_array)) {
            $newarray = array();
            foreach ($data_array as $data) {
                $newarray[] = array_slice($data, 1);
            }
            foreach ($newarray as $item) {
                $total_resource_weight = $total_resource_weight + $item['2'];
            }
        }
 /**
  * This is a function to show the generated data
  * @param bool $displayWarning
  * @return array
  */
 public function get_data_to_graph2($displayWarning = true)
 {
     // do some checks on users/items counts, redefine if invalid values
     $usertable = array();
     foreach ($this->users as $user) {
         $usertable[] = $user;
     }
     // sort users array
     usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name'));
     // generate actual data array
     $scoredisplay = ScoreDisplay::instance();
     $data = array();
     $displaytype = SCORE_DIV;
     $selected_users = $usertable;
     foreach ($selected_users as $user) {
         $row = array();
         $row[] = $user[0];
         // user id
         $item_value = 0;
         $item_total = 0;
         $final_score = 0;
         $item_value_total = 0;
         $convert_using_the_global_weight = true;
         $course_code = api_get_course_id();
         $session_id = api_get_session_id();
         $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id');
         if ($parent_id == 0 && !empty($allcat)) {
             foreach ($allcat as $sub_cat) {
                 $score = $sub_cat->calc_score($user[0]);
                 $real_score = $score;
                 $main_weight = $this->category->get_weight();
                 $divide = $score[1] == 0 ? 1 : $score[1];
                 $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
                 $item_value = $score[0] / $divide * $main_weight;
                 $item_total += $sub_cat->get_weight();
                 $row[] = array($item_value, trim($scoredisplay->display_score($real_score, SCORE_CUSTOM, null, true)));
                 $item_value_total += $item_value;
                 $final_score += $score[0];
                 //$final_score = ($final_score / $item_total) * 100;
             }
             $total_score = array($final_score, $item_total);
             $row[] = array($final_score, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
         } else {
             for ($count = 0; $count < count($this->evals_links); $count++) {
                 $item = $this->evals_links[$count];
                 $score = $item->calc_score($user[0]);
                 $divide = $score[1] == 0 ? 1 : $score[1];
                 $item_value += $score[0] / $divide * $item->get_weight();
                 $item_total += $item->get_weight();
                 $score_denom = $score[1] == 0 ? 1 : $score[1];
                 $score_final = $score[0] / $score_denom * 100;
                 $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true)));
             }
             $total_score = array($item_value, $item_total);
             $score_final = $item_value / $item_total * 100;
             if ($displayWarning) {
                 Display::display_warning_message(Display::display_warning_message($total_score[1]));
             }
             $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
         }
         $data[] = $row;
     }
     return $data;
 }