Esempio n. 1
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);
 }
 /**
  * @todo implement for all types only work for sessions
  *
  * @param int $resourceId
  * @param int $type
  *
  * @return array
  */
 public function getRequirementAndDependencies($resourceId, $type)
 {
     $sequence = $this->findRequirementForResource($resourceId, $type);
     $result = ['requirements' => '', 'dependencies' => ''];
     if ($sequence && $sequence->hasGraph()) {
         $graph = $sequence->getSequence()->getUnSerializeGraph();
         $vertex = $graph->getVertex($resourceId);
         $from = $vertex->getVerticesEdgeFrom();
         foreach ($from as $subVertex) {
             $vertexId = $subVertex->getId();
             $sessionInfo = api_get_session_info($vertexId);
             $sessionInfo['admin_link'] = '<a href="' . \SessionManager::getAdminPath($vertexId) . '">' . $sessionInfo['name'] . '</a>';
             $result['requirements'][] = $sessionInfo;
         }
         $to = $vertex->getVerticesEdgeTo();
         foreach ($to as $subVertex) {
             $vertexId = $subVertex->getId();
             $sessionInfo = api_get_session_info($vertexId);
             $sessionInfo['admin_link'] = '<a href="' . \SessionManager::getAdminPath($vertexId) . '">' . $sessionInfo['name'] . '</a>';
             $result['dependencies'][] = $sessionInfo;
         }
     }
     return $result;
 }
Esempio n. 3
0
SessionManager::protectSession($sessionId);
$tool_name = get_lang('SessionOverview');
//$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$orig_param = '&origin=resume_session';
// Database Table Definitions
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sessionInfo = api_get_session_info($sessionId);
$session = Database::getManager()->find('ChamiloCoreBundle:Session', $sessionId);
$sessionCategory = $session->getCategory();
$action = isset($_GET['action']) ? $_GET['action'] : null;
$url_id = api_get_current_access_url_id();
switch ($action) {
    case 'move_up':
        SessionManager::moveUp($sessionId, $_GET['course_id']);
        header('Location: resume_session.php?id_session=' . $sessionId);
        exit;
        break;
    case 'move_down':
        SessionManager::moveDown($sessionId, $_GET['course_id']);
        header('Location: resume_session.php?id_session=' . $sessionId);
        exit;
        break;
 /**
  * Shows the general data for a particular meeting
  *
  * @param id	session id
  * @return string	session data
  */
 public static function show_session_data($id_session)
 {
     if ($id_session != strval(intval($id_session))) {
         return '';
     } else {
         $id_session = intval($id_session);
     }
     $session_info = api_get_session_info($id_session);
     $session_category = SessionManager::get_session_category($session_info['session_category_id']);
     $session_category_name = null;
     if (!empty($session_category)) {
         $session_category_name = $session_category['name'];
     }
     $user_info = api_get_user_info($session_info['id_coach']);
     $general_coach = null;
     if (!empty($user_info)) {
         $general_coach = $user_info['complete_name'] . ' (' . $user_info['username'] . ')';
     }
     $msg_date = SessionManager::parse_session_dates($session_info);
     $output = '';
     if (!empty($session_category)) {
         $output .= '<tr><td>' . get_lang('SessionCategory') . ': ' . '<b>' . $session_category_name . '</b></td></tr>';
     }
     $output .= '<tr>
                     <td style="width:50%">' . get_lang('SessionName') . ': ' . '<b>' . $session_info['name'] . '</b></td>
                     <td>' . get_lang('GeneralCoach') . ': ' . '<b>' . $general_coach . '</b></td></tr>';
     $output .= '<tr><td>' . get_lang('SessionIdentifier') . ': ' . Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) . '</td>
                     <td>' . get_lang('Date') . ': ' . '<b>' . $msg_date . '</b></td></tr>';
     return $output;
 }
Esempio n. 5
0
 /**
  * Return true if coach is allowed to access this session
  * @param int $sessionId
  * @return bool
  */
 public static function isSessionDateOkForCoach($sessionId)
 {
     return api_get_session_visibility($sessionId);
     $listSessionInfo = api_get_session_info($sessionId);
     $dateStart = $listSessionInfo['date_start'];
     $dateEnd = $listSessionInfo['date_end'];
     $nbDaysAccessBeforeBeginning = $listSessionInfo['nb_days_access_before_beginning'];
     $nbDaysAccessAfterEnd = $listSessionInfo['nb_days_access_after_end'];
     // no start date
     if ($dateStart == '0000-00-00') {
         return true;
     }
     $now = time();
     $dateStartForCoach = api_strtotime($dateStart . ' 00:00:00') - $nbDaysAccessBeforeBeginning * 86400;
     $dateEndForCoach = api_strtotime($dateEnd . ' 00:00:00') + $nbDaysAccessAfterEnd * 86400;
     if ($dateEnd == '0000-00-00') {
         // start date but no end date
         if ($dateStartForCoach <= $now) {
             return true;
         }
     } else {
         // start date and end date
         if ($dateStartForCoach <= $now && $now <= $dateEndForCoach) {
             return true;
         }
     }
     return false;
 }
Esempio n. 6
0
 /**
  * @param string $file
  */
 private function importUnsubscribeStatic($file, $moveFile = false, &$teacherBackup = array(), &$groupBackup = array())
 {
     $data = Import::csv_reader($file);
     if (!empty($data)) {
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $chamiloUserName = $row['UserName'];
             $chamiloCourseCode = $row['CourseCode'];
             $chamiloSessionId = $row['SessionID'];
             $sessionInfo = api_get_session_info($chamiloSessionId);
             if (empty($sessionInfo)) {
                 $this->logger->addError('Session does not exists: ' . $chamiloSessionId);
                 continue;
             }
             $courseInfo = api_get_course_info($chamiloCourseCode);
             if (empty($courseInfo)) {
                 $this->logger->addError('Course does not exists: ' . $courseInfo);
                 continue;
             }
             $userId = Usermanager::get_user_id_from_username($chamiloUserName);
             if (empty($userId)) {
                 $this->logger->addError('User does not exists: ' . $chamiloUserName);
                 continue;
             }
             $sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "\n                        WHERE\n                            user_id = " . $userId . " AND\n                            course_code = '" . $courseInfo['code'] . "'\n                        ";
             $result = Database::query($sql);
             $userCourseData = Database::fetch_array($result, 'ASSOC');
             $teacherBackup[$userId][$courseInfo['code']] = $userCourseData;
             $sql = "SELECT * FROM " . Database::get_course_table(TABLE_GROUP_USER) . "\n                        WHERE\n                            user_id = " . $userId . " AND\n                            c_id = '" . $courseInfo['real_id'] . "'\n                        ";
             $result = Database::query($sql);
             while ($groupData = Database::fetch_array($result, 'ASSOC')) {
                 $groupBackup['user'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
             }
             $sql = "SELECT * FROM " . Database::get_course_table(TABLE_GROUP_TUTOR) . "\n                        WHERE\n                            user_id = " . $userId . " AND\n                            c_id = '" . $courseInfo['real_id'] . "'\n                        ";
             $result = Database::query($sql);
             while ($groupData = Database::fetch_array($result, 'ASSOC')) {
                 $groupBackup['tutor'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
             }
             CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId);
             $this->logger->addError("User '{$chamiloUserName}' was removed from session: #{$chamiloSessionId}, Course: " . $courseInfo['code']);
         }
     }
 }
function WSSubscribeUserToSessionSimple($params)
{
    global $debug;
    if ($debug) {
        error_log('WSSubscribeUserToSessionSimple with params=[' . serialize($params) . ']');
    }
    // Check security key
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    // Get input parameters
    $session_id = intval($params['session']);
    // Session ID
    $user_id = intval($params['user_id']);
    // Chamilo user id
    // Get user id
    $user_data = api_get_user_info($user_id);
    // Prepare answer
    $result = 0;
    if (empty($user_data)) {
        $result = "User {$user_id} does not exist";
        if ($debug) {
            error_log($result);
        }
        return $result;
    }
    if (!empty($session_id) && is_numeric($session_id)) {
        $session_data = api_get_session_info($session_id);
        if (empty($session_data)) {
            $result = "Session {$session_id} does not exist.";
            if ($debug) {
                error_log($result);
            }
        } else {
            SessionManager::suscribe_users_to_session($session_id, array($user_id), SESSION_VISIBLE_READ_ONLY, false);
            if ($debug) {
                error_log('User registered to the course: ' . $session_id);
            }
            $result = 1;
        }
    }
    return $result;
}
Esempio n. 8
0
 /**
  * @param int $userId
  * @param int $categoryId
  * @param bool $saveToFile
  * @param bool $saveToHtmlFile
  *
  * @return string
  */
 public static function generateTable($userId, $categoryId, $saveToFile = false, $saveToHtmlFile = false)
 {
     $courseInfo = api_get_course_info();
     $userInfo = api_get_user_info($userId);
     $cats = Category::load($categoryId, null, null, null, null, null, false);
     $cat = $cats[0];
     $allcat = $cats[0]->get_subcategories($userId, api_get_course_id(), api_get_session_id());
     $alleval = $cats[0]->get_evaluations($userId);
     $alllink = $cats[0]->get_links($userId);
     $gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, null, true, false, $userId);
     if (api_is_allowed_to_edit()) {
         $gradebooktable->td_attributes = [4 => 'class=centered'];
     } else {
         $gradebooktable->td_attributes = [3 => 'class=centered', 4 => 'class=centered', 5 => 'class=centered', 6 => 'class=centered', 7 => 'class=centered'];
     }
     $table = $gradebooktable->return_table();
     $graph = $gradebooktable->getGraph();
     $sessionName = api_get_session_name(api_get_session_id());
     $sessionName = !empty($sessionName) ? " - {$sessionName}" : '';
     $params = array('pdf_title' => $courseInfo['title'] . $sessionName, 'course_code' => api_get_course_id(), 'session_info' => api_get_session_info(api_get_session_id()), 'add_signatures' => false, 'student_info' => $userInfo, 'show_grade_generated_date' => true, 'show_real_course_teachers' => true);
     $file = api_get_path(SYS_ARCHIVE_PATH) . uniqid() . '.html';
     $content = $table . $graph . '<br />' . get_lang('Feedback') . '<br />
         <textarea rows="5" cols="100" ></textarea>';
     $pdf = new PDF('A4', $params['orientation'], $params);
     $result = $pdf->html_to_pdf_with_template($content, $saveToFile, $saveToHtmlFile);
     if ($saveToHtmlFile) {
         file_put_contents($file, $result);
         return $file;
     }
     return $file;
 }
 /**
  * Subscribes users (students)  to the given session and optionally (default) unsubscribes previous users
  * @author Carlos Vargas from existing code
  * @param    integer        Session ID
  * @param    array        List of user IDs
  * @param    bool        Whether to unsubscribe existing users (true, default) or not (false)
  * @return    void        Nothing, or false on error
  **/
 public static function suscribe_users_to_session($id_session, $user_list, $session_visibility = SESSION_VISIBLE_READ_ONLY, $empty_users = true, $send_email = false)
 {
     if ($id_session != strval(intval($id_session))) {
         return false;
     }
     foreach ($user_list as $intUser) {
         if ($intUser != strval(intval($intUser))) {
             return false;
         }
     }
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $session_info = api_get_session_info($id_session);
     if ($session_info) {
         $session_name = $session_info['name'];
     } else {
         return false;
     }
     //from function parameter
     if (empty($session_visibility)) {
         $session_visibility = $session_info['visibility'];
         //loaded from DB
         //default status loaded if empty
         if (empty($session_visibility)) {
             $session_visibility = SESSION_VISIBLE_READ_ONLY;
         }
         // by default readonly 1
     } else {
         if (!in_array($session_visibility, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_INVISIBLE))) {
             $session_visibility = SESSION_VISIBLE_READ_ONLY;
         }
     }
     $sql = "SELECT id_user FROM {$tbl_session_rel_course_rel_user} WHERE id_session = '{$id_session}' AND status = 0";
     $result = Database::query($sql);
     $existingUsers = array();
     while ($row = Database::fetch_array($result)) {
         $existingUsers[] = $row['id_user'];
     }
     $sql = "SELECT c_id FROM {$tbl_session_rel_course} WHERE id_session = '{$id_session}'";
     $result = Database::query($sql);
     $course_list = array();
     while ($row = Database::fetch_array($result)) {
         $course_list[] = $row['c_id'];
     }
     if ($send_email) {
         //sending emails only
         if (is_array($user_list) && count($user_list) > 0) {
             foreach ($user_list as $user_id) {
                 if (!in_array($user_id, $existingUsers)) {
                     $subject = '[' . get_setting('siteName') . '] ' . get_lang('YourReg') . ' ' . get_setting('siteName');
                     $user_info = api_get_user_info($user_id);
                     $content = get_lang('Dear') . " " . stripslashes($user_info['complete_name']) . ",\n\n" . sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) . " \n\n" . get_lang('Address') . " " . api_get_setting('siteName') . " " . get_lang('Is') . " : " . api_get_path(WEB_PATH) . "\n\n" . get_lang('Problem') . "\n\n" . get_lang('Formula') . ",\n\n" . get_setting('administratorName') . " " . get_setting('administratorSurname') . "\n" . get_lang('Manager') . " " . get_setting('siteName') . "\nT. " . get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . get_setting('emailAdministrator');
                     MessageManager::send_message($user_id, $subject, $content, array(), array(), null, null, null, null, null);
                 }
             }
         }
     }
     foreach ($course_list as $courseId) {
         // for each course in the session
         $nbr_users = 0;
         $courseId = Database::escape_string($courseId);
         // delete existing users
         if ($empty_users) {
             foreach ($existingUsers as $existing_user) {
                 if (!in_array($existing_user, $user_list)) {
                     $sql = "DELETE FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND c_id ='{$courseId}' AND id_user='******' AND status = 0";
                     $result = Database::query($sql);
                     if (Database::affected_rows($result)) {
                         $nbr_users--;
                     }
                 }
             }
         }
         //Replace with this new function
         //
         // insert new users into session_rel_course_rel_user and ignore if they already exist
         foreach ($user_list as $enreg_user) {
             if (!in_array($enreg_user, $existingUsers)) {
                 $enreg_user = Database::escape_string($enreg_user);
                 $insert_sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(id_session, c_id, id_user, visibility, status) VALUES('{$id_session}','{$courseId}','{$enreg_user}','{$session_visibility}', '0')";
                 $result = Database::query($insert_sql);
                 if (Database::affected_rows($result)) {
                     $nbr_users++;
                 }
             }
         }
         // count users in this session-course relation
         $sql = "SELECT COUNT(id_user) as nbUsers FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND c_id ='{$courseId}' AND status<>2";
         $rs = Database::query($sql);
         list($nbr_users) = Database::fetch_array($rs);
         // update the session-course relation to add the users total
         $update_sql = "UPDATE {$tbl_session_rel_course} SET nbr_users = {$nbr_users} WHERE id_session='{$id_session}' AND c_id ='{$courseId}'";
         Database::query($update_sql);
     }
     // Delete users from the session
     if ($empty_users === true) {
         Database::query("DELETE FROM {$tbl_session_rel_user} WHERE id_session = {$id_session} AND relation_type<>" . SESSION_RELATION_TYPE_RRHH . "");
     }
     // Insert missing users into session
     $nbr_users = 0;
     foreach ($user_list as $enreg_user) {
         $enreg_user = Database::escape_string($enreg_user);
         $insert_sql = "INSERT IGNORE INTO {$tbl_session_rel_user} (id_session, id_user) VALUES ('{$id_session}', '{$enreg_user}')";
         Database::query($insert_sql);
         //Reset moved_to just in case
         $update_sql = "UPDATE {$tbl_session_rel_user} SET moved_to = 0, moved_status = 0, moved_at ='0000-00-00 00:00:00'\n                           WHERE id_session = {$id_session} AND id_user = {$enreg_user}";
         Database::query($update_sql);
         $nbr_users++;
     }
     // update number of users in the session
     $nbr_users = count($user_list);
     if ($empty_users) {
         // update number of users in the session
         $update_sql = "UPDATE {$tbl_session} SET nbr_users = {$nbr_users} WHERE id='{$id_session}' ";
         Database::query($update_sql);
     } else {
         $update_sql = "UPDATE {$tbl_session} SET nbr_users = nbr_users + {$nbr_users} WHERE id='{$id_session}' ";
         Database::query($update_sql);
     }
 }
Esempio n. 10
0
/**
 * @param int $workId
 * @param array $courseInfo
 * @param int $sessionId
 * @param string $format
 * @return bool
 */
function exportAllStudentWorkFromPublication(
    $workId,
    $courseInfo,
    $sessionId,
    $format = 'pdf'
) {
    if (empty($courseInfo)) {
        return false;
    }

    $workData = get_work_data_by_id($workId);

    if (empty($workData)) {
        return false;
    }

    $assignment = get_work_assignment_by_id($workId);

    $courseCode = $courseInfo['code'];
    $header = get_lang('Course').': '.$courseInfo['title'];
    $teachers = CourseManager::get_teacher_list_from_course_code_to_string(
        $courseCode
    );

    if (!empty($sessionId)) {
        $sessionInfo = api_get_session_info($sessionId);
        if (!empty($sessionInfo)) {
            $header .= ' - ' . $sessionInfo['name'];
            $header .= '<br />' . $sessionInfo['description'];
            $teachers = SessionManager::getCoachesByCourseSessionToString(
                $sessionId,
                $courseCode
            );
        }
    }

    $header .= '<br />'.get_lang('Teachers').': '.$teachers.'<br />';
    $header .= '<br />'.get_lang('Date').': '.api_get_local_time().'<br />';
    $header .= '<br />'.get_lang('StudentPublication').': '.$workData['title'].'<br />';

    $content = null;
    $expiresOn = null;

    if (!empty($assignment) && isset($assignment['expires_on'])) {
        $content .= '<br /><strong>' . get_lang('ExpiryDate') . '</strong>: ' . api_get_local_time($assignment['expires_on']);
        $expiresOn = api_get_local_time($assignment['expires_on']);
    }

    if (!empty($workData['description'])) {
        $content .= '<br /><strong>' . get_lang('Description') . '</strong>: ' . $workData['description'];
    }

    $workList = get_work_user_list(null, null, null, null, $workId);

    switch ($format) {
        case 'pdf':
            if (!empty($workList)) {
                require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';

                $table = new HTML_Table(array('class' => 'data_table'));
                $headers = array(
                    get_lang('Name'),
                    get_lang('User'),
                    get_lang('HandOutDateLimit'),
                    get_lang('SentDate'),
                    get_lang('Filename'),
                    get_lang('Score'),
                    get_lang('Feedback')
                );

                $column = 0;
                foreach($headers as $header) {
                    $table->setHeaderContents(0, $column, $header);
                    $column++;
                }

                $row = 1;

                //$pdf->set_custom_header($header);
                foreach ($workList as $work) {
                    $content .= '<hr />';
                    // getWorkComments need c_id
                    $work['c_id'] = $courseInfo['real_id'];

                    //$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />';
                    $score = null;
                    if (!empty($work['qualification_only'])) {
                        $score = $work['qualification_only'];
                    }
                    //$content .= get_lang('Description').': '.$work['description'].'<br />';
                    $comments = getWorkComments($work);

                    $feedback = null;
                    if (!empty($comments)) {
                        $content .= '<h4>'.get_lang('Feedback').': </h4>';
                        foreach ($comments as $comment) {
                            $feedback .= get_lang('User').': '.api_get_person_name(
                                $comment['firstname'],
                                $comment['lastname']
                            ).'<br />';
                            $feedback .= $comment['comment'].'<br />';
                        }
                    }

                    $table->setCellContents($row, 0, strip_tags($workData['title']));
                    $table->setCellContents($row, 1, api_get_person_name(strip_tags($work['firstname']), strip_tags($work['lastname'])));
                    $table->setCellContents($row, 2, $expiresOn);
                    $table->setCellContents($row, 3, api_get_local_time($work['sent_date_from_db']));
                    $table->setCellContents($row, 4, strip_tags($work['title']));
                    $table->setCellContents($row, 5, $score);
                    $table->setCellContents($row, 6, $feedback);

                    $row++;
                }

                $content = $table->toHtml();

                if (!empty($content)) {
                    $params = array(
                        'filename' => $workData['title'] . '_' . api_get_local_time(),
                        'pdf_title' => replace_dangerous_char($workData['title']),
                        'course_code' => $courseInfo['code'],
                        'add_signatures' => false
                    );
                    $pdf = new PDF('A4', null, $params);
                    $pdf->html_to_pdf_with_template($content);
                }
                exit;
            }
            break;
    }
}
Esempio n. 11
0
                     if ($id == 'name') {
                         $item2['text'] = $internal;
                     }
                 }
                 $results2[] = $item2;
             }
             $results2[] = array('T', 'text' => 'TODOS', 'id' => 'T');
             echo json_encode($results2);
         } else {
             echo json_encode(array(array('T', 'text' => 'TODOS', 'id' => 'T')));
         }
     }
     break;
 case 'get_description':
     if (isset($_GET['session'])) {
         $sessionInfo = api_get_session_info($_GET['session']);
         echo '<h2>' . $sessionInfo['name'] . '</h2>';
         echo '<div class="home-course-intro"><div class="page-course"><div class="page-course-intro">';
         echo $sessionInfo['show_description'] == 1 ? $sessionInfo['description'] : get_lang('None');
         echo '</div></div></div>';
     }
     break;
 case 'search_general_coach':
     header('Content-Type: application/json');
     if (api_is_anonymous()) {
         echo '';
         break;
     }
     $list = ['items' => []];
     $entityManager = Database::getManager();
     $usersRepo = $entityManager->getRepository('ChamiloUserBundle:User');
    }
    $sessionsByCourse = SessionManager::get_session_by_course($course['real_id']);
    foreach ($sessionsByCourse as $session) {
        $coaches = CourseManager::get_coachs_from_course($session['id'], $course['real_id']);
        if ($coaches) {
            foreach ($coaches as $coach) {
                $totalTime = UserManager::getTimeSpentInCourses($coach['user_id'], $course['real_id'], $session['id'], $selectedFrom, $selectedUntil);
                $formattedTime = api_format_time($totalTime);
                $timeReport->data[] = array('session' => array('id' => $session['id'], 'name' => $session['name']), 'course' => array('id' => $course['real_id'], 'name' => $course['title']), 'coach' => array('userId' => $coach['user_id'], 'lastname' => $coach['lastname'], 'firstname' => $coach['firstname'], 'username' => $coach['username'], 'completeName' => api_get_person_name($coach['firstname'], $coach['lastname'])), 'totalTime' => $formattedTime);
            }
        }
    }
}
if (!empty($selectedSession)) {
    $withFilter = true;
    $session = api_get_session_info($selectedSession);
    $sessionData = array('id' => $session['id'], 'name' => $session['name']);
    $reportTitle = sprintf(get_lang('TimeReportForSessionX'), $session['name']);
    $courses = SessionManager::get_course_list_by_session_id($selectedSession);
    foreach ($courses as $course) {
        $courseData = array('id' => $course['id'], 'name' => $course['title']);
        $coaches = CourseManager::get_coachs_from_course($selectedSession, $course['id']);
        if ($coaches) {
            foreach ($coaches as $coach) {
                $totalTime = UserManager::getTimeSpentInCourses($coach['user_id'], $course['id'], $selectedSession, $selectedFrom, $selectedUntil);
                $formattedTime = api_format_time($totalTime);
                $timeReport->data[] = array('session' => $sessionData, 'course' => $courseData, 'coach' => array('userId' => $coach['user_id'], 'lastname' => $coach['lastname'], 'firstname' => $coach['firstname'], 'username' => $coach['username'], 'completeName' => api_get_person_name($coach['firstname'], $coach['lastname'])), 'totalTime' => $formattedTime);
            }
        }
    }
}
 static function transaction_10($data, $web_service_details)
 {
     $uidIdPrograma = $data['item_id'];
     global $data_list;
     $session_id = self::get_session_id_by_programa_id($uidIdPrograma, $data_list);
     if (!empty($session_id)) {
         $session_info = Migration::soap_call($web_service_details, 'programaDetalles', array('intIdSede' => $data['branch_id'], 'uididprograma' => $data['item_id']));
         if ($session_info['error'] == false) {
             self::fix_access_dates($session_info);
             $session_info['id'] = $session_id;
             unset($session_info['error']);
             $session_info_before = api_get_session_info($session_id, true);
             SessionManager::update($session_info);
             $session_info = api_get_session_info($session_id, true);
             return array('entity' => 'session', 'before' => $session_info_before, 'after' => $session_info, 'message' => "Session updated {$uidIdPrograma} with data: " . print_r($session_info, 1), 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
         } else {
             return $session_info;
         }
     } else {
         return array('message' => "Session does not exists {$uidIdPrograma}", 'status_id' => self::TRANSACTION_STATUS_FAILED);
     }
 }
Esempio n. 14
0
// Get validation hash
$hash = Security::remove_XSS($_REQUEST['v']);
// Get data from request (GET or POST)
$data['action'] = 'confirm';
$data['currentUserId'] = 1;
$data['queueId'] = 0;
$data['is_connected'] = true;
$data['profile_completed'] = 90.0;
// Init result array
$data['sessionId'] = 1;
$data['studentUserId'] = 4;
// Prepare data
// Get session data
// Assign variables
$fieldsArray = array('description', 'target', 'mode', 'publication_end_date', 'recommended_number_of_participants');
$sessionArray = api_get_session_info($data['sessionId']);
$extraSession = new ExtraFieldValue('session');
$extraField = new ExtraField('session');
// Get session fields
$fieldList = $extraField->get_all(array('variable IN ( ?, ?, ?, ?, ?)' => $fieldsArray));
$fields = array();
// Index session fields
foreach ($fieldList as $field) {
    $fields[$field['id']] = $field['variable'];
}
$mergedArray = array_merge(array($data['sessionId']), array_keys($fields));
$sessionFieldValueList = $extraSession->get_all(array('item_id = ? field_id IN ( ?, ?, ?, ?, ?, ?, ? )' => $mergedArray));
foreach ($sessionFieldValueList as $sessionFieldValue) {
    // Check if session field value is set in session field list
    if (isset($fields[$sessionFieldValue['field_id']])) {
        $var = $fields[$sessionFieldValue['field_id']];
Esempio n. 15
0
                    if (!empty($grade_models[$grade_model_id])) {
                        Display::display_normal_message(get_lang('GradeModel') . ': ' . $grade_models[$grade_model_id]['name']);
                    }
                }
                $exportToPdf = false;
                if ($action == 'export_table') {
                    $exportToPdf = true;
                }
                $gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams, $exportToPdf);
                if (api_is_allowed_to_edit()) {
                    $gradebooktable->td_attributes = [4 => 'class=centered'];
                } else {
                    $gradebooktable->td_attributes = [3 => 'class=centered', 4 => 'class=centered', 5 => 'class=centered', 6 => 'class=centered', 7 => 'class=centered'];
                }
                $table = $gradebooktable->return_table();
                $graph = $gradebooktable->getGraph();
                if ($action == 'export_table') {
                    ob_clean();
                    $params = array('pdf_title' => get_lang('Report'), 'course_code' => api_get_course_id(), 'session_info' => api_get_session_info(api_get_session_id()), 'add_signatures' => false, 'student_info' => api_get_user_info());
                    $pdf = new PDF('A4', $params['orientation'], $params);
                    $pdf->html_to_pdf_with_template($table . $graph);
                } else {
                    echo $table;
                    echo $graph;
                }
            }
        }
    }
}
api_set_in_gradebook();
Display::display_footer();
Esempio n. 16
0
/**
 * Gets the session visibility by session id
 * @param int       session id
 * @return int      0 = session still available, SESSION_VISIBLE_READ_ONLY = 1, SESSION_VISIBLE = 2, SESSION_INVISIBLE = 3
 */
function api_get_session_visibility($session_id, $course_code = null, $ignore_visibility_for_admins = true)
{
    if (api_is_platform_admin()) {
        if ($ignore_visibility_for_admins) {
            return SESSION_AVAILABLE;
        }
    }
    $session_info = api_get_session_info($session_id);
    $visibility = SESSION_AVAILABLE;
    if (!empty($session_info)) {
        $visibility = $session_info['visibility'];
        // 1. Checking session date validation
        $date_validation = api_get_session_date_validation($session_info, $course_code, $ignore_visibility_for_admins);
        if ($date_validation) {
            return SessionManager::DEFAULT_VISIBILITY;
            //visible
        } else {
            /*
                        $is_coach = api_is_coach($session_id, $course_code);
                        if (!$is_coach) {
                            //Student - check the moved_to variable
                            $user_status = SessionManager::get_user_status_in_session($session_id, api_get_user_id());
                            if (isset($user_status['moved_to']) && $user_status['moved_to'] != 0) {
                                return $visibility;
                            }
                        }*/
            return $visibility;
        }
    }
    return $visibility;
}
Esempio n. 17
0
$plugin = AdvancedSubscriptionPlugin::create();
// Session ID
$sessionId = isset($_REQUEST['s']) ? intval($_REQUEST['s']) : null;
// Init template
$tpl = new Template($plugin->get_lang('plugin_title'));
// Get all sessions
$sessionList = $plugin->listAllSessions();
if (!empty($sessionId)) {
    // Get student list in queue
    $studentList = $plugin->listAllStudentsInQueueBySession($sessionId);
    // Set selected to current session
    $sessionList[$sessionId]['selected'] = 'selected="selected"';
    $studentList['session']['id'] = $sessionId;
    // Assign variables
    $fieldsArray = array('description', 'target', 'mode', 'publication_end_date', 'recommended_number_of_participants', 'vacancies');
    $sessionArray = api_get_session_info($sessionId);
    $extraSession = new ExtraFieldValue('session');
    $extraField = new ExtraField('session');
    // Get session fields
    $fieldList = $extraField->get_all(array('variable IN ( ?, ?, ?, ?, ?, ?)' => $fieldsArray));
    // Index session fields
    foreach ($fieldList as $field) {
        $fields[$field['id']] = $field['variable'];
    }
    $params = array(' item_id = ? ' => $sessionId);
    $sessionFieldValueList = $extraSession->get_all(array('where' => $params));
    foreach ($sessionFieldValueList as $sessionFieldValue) {
        // Check if session field value is set in session field list
        if (isset($fields[$sessionFieldValue['field_id']])) {
            $var = $fields[$sessionFieldValue['field_id']];
            $val = $sessionFieldValue['value'];
Esempio n. 18
0
 /**
  * @param int $start
  * @param int $end
  * @param array $courseInfo
  * @param int $groupId
  * @param int $session_id
  * @param int $user_id
  * @param string $color
  *
  * @return array
  */
 public function getCourseEvents($start, $end, $courseInfo, $groupId = 0, $session_id = 0, $user_id = 0, $color = '')
 {
     $start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null;
     $end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null;
     if (empty($courseInfo)) {
         return array();
     }
     $course_id = $courseInfo['real_id'];
     if (empty($course_id)) {
         return array();
     }
     $session_id = intval($session_id);
     $user_id = intval($user_id);
     $groupList = GroupManager::get_group_list(null, $courseInfo['code']);
     $group_name_list = array();
     if (!empty($groupList)) {
         foreach ($groupList as $group) {
             $group_name_list[$group['id']] = $group['name'];
         }
     }
     $group_memberships = [];
     if (!empty($groupId)) {
         if (!api_is_allowed_to_edit()) {
             $user_id = api_get_user_id();
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         } else {
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         }
     } else {
         // if no group was defined but I am a student reviewing his agenda,
         // group events should show, so we should fetch those groups to which
         // I belong
         if (!api_is_allowed_to_edit()) {
             $user_id = api_get_user_id();
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         } else {
             // If no group was defined and I am a teacher/admin reviewing
             // someone else's agenda, we should fetch this person's groups
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         }
     }
     $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
     $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     if (!empty($groupId)) {
         $group_memberships = array($groupId);
     }
     if (is_array($group_memberships) && count($group_memberships) > 0) {
         if (api_is_allowed_to_edit()) {
             if (!empty($groupId)) {
                 $where_condition = "( ip.to_group_id IN (" . implode(", ", $group_memberships) . ") ) ";
             } else {
                 if (!empty($user_id)) {
                     $where_condition = "( ip.to_user_id = {$user_id} OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ) ";
                 } else {
                     $where_condition = "( ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ") ) ";
                 }
             }
         } else {
             $where_condition = "( ip.to_user_id = {$user_id} OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ) ";
         }
         $sessionCondition = '';
         if (empty($session_id)) {
             $sessionCondition = "\n                (\n                    agenda.session_id = 0 AND\n                    ip.session_id IS NULL\n                ) ";
         } else {
             $sessionCondition = "\n                (\n                    agenda.session_id = {$session_id} AND\n                    ip.session_id = {$session_id}\n                ) ";
         }
         $sql = "SELECT DISTINCT\n                        agenda.*,\n                        ip.visibility,\n                        ip.to_group_id,\n                        ip.insert_user_id,\n                        ip.ref,\n                        to_user_id\n                    FROM {$tlb_course_agenda} agenda\n                    INNER JOIN {$tbl_property} ip\n                    ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id)\n                    WHERE\n                        ip.tool = '" . TOOL_CALENDAR_EVENT . "' AND\n                        {$where_condition} AND\n                        ip.visibility = '1' AND\n                        agenda.c_id = {$course_id} AND\n                        ip.c_id = agenda.c_id AND\n                        {$sessionCondition}\n                    ";
     } else {
         $visibilityCondition = " ip.visibility='1' AND ";
         $sessionCondition = '';
         if (api_is_allowed_to_edit()) {
             if ($user_id == 0) {
                 $where_condition = "";
             } else {
                 $where_condition = " (ip.to_user_id = " . $user_id . " OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL AND ";
             }
             $visibilityCondition = " (ip.visibility IN ('1', '0')) AND ";
         } else {
             $where_condition = " ( (ip.to_user_id = " . api_get_user_id() . " OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL) AND ";
         }
         if (empty($session_id)) {
             $sessionCondition = "\n                (\n                    agenda.session_id = 0 AND\n                    ip.session_id IS NULL\n                ) ";
         } else {
             $sessionCondition = "\n                (\n                    agenda.session_id = {$session_id} AND\n                    ip.session_id = {$session_id}\n                ) ";
         }
         $sql = "SELECT DISTINCT\n                        agenda.*,\n                        ip.visibility,\n                        ip.to_group_id,\n                        ip.insert_user_id,\n                        ip.ref,\n                        to_user_id\n                    FROM {$tlb_course_agenda} agenda\n                    INNER JOIN {$tbl_property} ip\n                    ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id)\n                    WHERE\n                        ip.tool='" . TOOL_CALENDAR_EVENT . "' AND\n                        {$where_condition}\n                        {$visibilityCondition}\n                        agenda.c_id = {$course_id} AND\n                        {$sessionCondition}\n                    ";
     }
     $dateCondition = null;
     if (!empty($start) && !empty($end)) {
         $dateCondition .= "AND (\n                 agenda.start_date BETWEEN '" . $start . "' AND '" . $end . "' OR\n                 agenda.end_date BETWEEN '" . $start . "' AND '" . $end . "' OR\n                 (\n                     agenda.start_date IS NOT NULL AND agenda.end_date IS NOT NULL AND\n                     YEAR(agenda.start_date) = YEAR(agenda.end_date) AND\n                     MONTH('{$start}') BETWEEN MONTH(agenda.start_date) AND MONTH(agenda.end_date)\n                 )\n            )";
     }
     $sql .= $dateCondition;
     $result = Database::query($sql);
     $coachCanEdit = false;
     if (!empty($session_id)) {
         $coachCanEdit = api_is_coach($session_id, $course_id);
     }
     if (Database::num_rows($result)) {
         $eventsAdded = array_column($this->events, 'unique_id');
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             $eventId = $row['ref'];
             $items = $this->getUsersAndGroupSubscribedToEvent($eventId, $course_id, $this->sessionId);
             $group_to_array = $items['groups'];
             $user_to_array = $items['users'];
             $event = array();
             $event['id'] = 'course_' . $row['id'];
             $event['unique_id'] = 'course_' . $row['id'] . intval($row['session_id']);
             // To avoid doubles
             if (in_array($event['unique_id'], $eventsAdded)) {
                 continue;
             }
             $eventsAdded[] = $event['unique_id'];
             $attachment = $this->getAttachment($row['id'], $courseInfo);
             if (!empty($attachment)) {
                 $has_attachment = Display::return_icon('attachment.gif', get_lang('Attachment'));
                 $user_filename = $attachment['filename'];
                 $url = api_get_path(WEB_CODE_PATH) . 'calendar/download.php?file=' . $attachment['path'] . '&course_id=' . $course_id . '&' . api_get_cidreq();
                 $event['attachment'] = $has_attachment . Display::url($user_filename, $url);
             } else {
                 $event['attachment'] = '';
             }
             $event['title'] = $row['title'];
             $event['className'] = 'course';
             $event['allDay'] = 'false';
             $event['course_id'] = $course_id;
             $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color;
             $sessionInfo = [];
             if (isset($row['session_id']) && !empty($row['session_id'])) {
                 $sessionInfo = api_get_session_info($session_id);
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color;
             }
             $event['session_name'] = isset($sessionInfo['name']) ? $sessionInfo['name'] : '';
             $event['course_name'] = isset($courseInfo['title']) ? $courseInfo['title'] : '';
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
             }
             if (!empty($color)) {
                 $event['borderColor'] = $event['backgroundColor'] = $color;
             }
             if (isset($row['color']) && !empty($row['color'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $row['color'];
             }
             $event['editable'] = false;
             if (api_is_allowed_to_edit() && $this->type == 'course') {
                 $event['editable'] = true;
                 if (!empty($session_id)) {
                     if ($coachCanEdit == false) {
                         $event['editable'] = false;
                     }
                 }
             }
             if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
                 $event['start'] = $this->formatEventDate($row['start_date']);
                 $event['start_date_localtime'] = api_get_local_time($row['start_date']);
             }
             if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
                 $event['end'] = $this->formatEventDate($row['end_date']);
                 $event['end_date_localtime'] = api_get_local_time($row['end_date']);
             }
             $event['sent_to'] = '';
             $event['type'] = 'course';
             if ($row['session_id'] != 0) {
                 $event['type'] = 'session';
             }
             // Event Sent to a group?
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $sent_to = array();
                 if (!empty($group_to_array)) {
                     foreach ($group_to_array as $group_item) {
                         $sent_to[] = $group_name_list[$group_item];
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
                 $event['type'] = 'group';
             }
             //Event sent to a user?
             if (isset($row['to_user_id'])) {
                 $sent_to = array();
                 if (!empty($user_to_array)) {
                     foreach ($user_to_array as $item) {
                         $user_info = api_get_user_info($item);
                         // Add username as tooltip for $event['sent_to'] - ref #4226
                         $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
                         $sent_to[] = "<span title='" . $username . "'>" . $user_info['complete_name'] . "</span>";
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
             }
             //Event sent to everyone!
             if (empty($event['sent_to'])) {
                 $event['sent_to'] = '<div class="label_tag notice">' . get_lang('Everyone') . '</div>';
             }
             $event['description'] = $row['content'];
             $event['visibility'] = $row['visibility'];
             $event['real_id'] = $row['id'];
             $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
             $event['parent_event_id'] = $row['parent_event_id'];
             $event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0;
             $event['comment'] = $row['comment'];
             $this->events[] = $event;
         }
     }
     return $this->events;
 }
Esempio n. 19
0
/**
 * This function retrieves forum thread users not qualify
 * @param   int Thread ID
 * @param   string  Course DB name (optional)
 * @return  array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
 * @author   Jhon Hinojosa<*****@*****.**>,
 * @version oct 2008, dokeos 1.8
 */
function get_thread_users_not_qualify($thread_id)
{
    $t_posts = Database::get_course_table(TABLE_FORUM_POST);
    $t_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
    $t_users = Database::get_main_table(TABLE_MAIN_USER);
    $t_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $t_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
    $is_western_name_order = api_is_western_name_order();
    if ($is_western_name_order) {
        $orderby = 'ORDER BY user.firstname, user.lastname ';
    } else {
        $orderby = 'ORDER BY user.lastname, user.firstname';
    }
    $course_id = api_get_course_int_id();
    $sql1 = "SELECT user_id FROM  {$t_qualify}\n             WHERE c_id = {$course_id} AND thread_id = '" . $thread_id . "'";
    $result1 = Database::query($sql1);
    $cad = '';
    while ($row = Database::fetch_array($result1)) {
        $cad .= $row['user_id'] . ',';
    }
    if ($cad == '') {
        $cad = '0';
    } else {
        $cad = substr($cad, 0, strlen($cad) - 1);
    }
    if (api_get_session_id()) {
        $session_info = api_get_session_info(api_get_session_id());
        $user_to_avoid = "'" . $session_info['id_coach'] . "', '" . $session_info['session_admin_id'] . "'";
        //not showing coaches
        $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, post.thread_id\n                FROM {$t_posts} post , {$t_users} user, {$t_session_rel_user} session_rel_user_rel_course\n                WHERE poster_id = user.id\n                    AND user.id NOT IN (" . $cad . ")\n                    AND user.id = session_rel_user_rel_course.user_id\n                    AND session_rel_user_rel_course.status<>'2'\n                    AND session_rel_user_rel_course.user_id NOT IN ({$user_to_avoid})\n                    AND post.thread_id = " . intval($thread_id) . "\n                    AND session_id = " . api_get_session_id() . "\n                    AND session_rel_user_rel_course.c_id = {$course_id} AND post.c_id = {$course_id} {$orderby} ";
    } else {
        $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, post.thread_id\n                FROM {$t_posts} post, {$t_users} user,{$t_course_user} course_user\n                WHERE post.poster_id = user.id\n                AND user.id NOT IN (" . $cad . ")\n                AND user.id = course_user.user_id\n                AND course_user.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "\n                AND post.thread_id = " . intval($thread_id) . "\n                AND course_user.status not in('1')\n                AND course_user.c_id = {$course_id} AND post.c_id = {$course_id}  {$orderby}";
    }
    $result = Database::query($sql);
    return $result;
}
        exit;
    }
    $courses = SessionManager::get_course_list_by_session_id($data['sessionId']);
    $course = current($courses);
    $data['courseId'] = $course['id'];
    $legalEnabled = api_get_plugin_setting('courselegal', 'tool_enable');
    if ($legalEnabled) {
        $courseLegal = CourseLegalPlugin::create();
        $termsAndConditions = $courseLegal->getData($data['courseId'], $data['sessionId']);
        $termsAndConditions = $termsAndConditions['content'];
        $termFiles = $courseLegal->getCurrentFile($data['courseId'], $data['sessionId']);
    } else {
        $termsAndConditions = $plugin->get('terms_and_conditions');
        $termFiles = '';
    }
    $data['session'] = api_get_session_info($data['sessionId']);
    $data['student'] = api_get_user_info($data['studentUserId']);
    $data['course'] = api_get_course_info_by_id($data['courseId']);
    $data['acceptTermsUrl'] = $plugin->getQueueUrl($data);
    $data['rejectTermsUrl'] = $plugin->getTermsUrl($data, ADVANCED_SUBSCRIPTION_TERMS_MODE_REJECT);
    // Use Twig with String loader
    $termsContent = $plugin->renderTemplateString($termsAndConditions, $data);
} else {
    $termsContent = '';
    $termFiles = '';
    $data['acceptTermsUrl'] = '#';
    $data['rejectTermsUrl'] = '#';
}
// Assign into content
$tpl->assign('termsRejected', $data['termsRejected']);
$tpl->assign('acceptTermsUrl', $data['acceptTermsUrl']);
 /**
  * Gets attendance base in the table:
  * TABLE_STATISTIC_TRACK_E_COURSE_ACCESS
  * @param bool $showForm
  * @throws ViewException
  */
 public function getAttendanceBaseInLogin($showForm = false, $exportToPdf = true)
 {
     $table = null;
     $formToDisplay = null;
     $startDate = null;
     $endDate = null;
     $sessionId = api_get_session_id();
     if ($showForm) {
         $form = new FormValidator('search', 'post', api_get_self() . '?' . api_get_cidreq() . '&action=calendar_logins');
         $form->addDateRangePicker('range', get_lang('DateRange'));
         $form->addButton('submit', get_lang('Submit'));
         if ($form->validate()) {
             $values = $form->getSubmitValues();
             $startDate = api_get_utc_datetime($values['range_start']);
             $endDate = api_get_utc_datetime($values['range_end']);
         }
         $formToDisplay = $form->returnForm();
     } else {
         if (!empty($sessionId)) {
             $sessionInfo = api_get_session_info($sessionId);
             $startDate = $sessionInfo['access_start_date'];
             $endDate = $sessionInfo['access_end_date'];
         }
     }
     $attendance = new Attendance();
     if ($exportToPdf) {
         $result = $attendance->exportAttendanceLogin($startDate, $endDate);
         if (empty($result)) {
             api_not_allowed(true, get_lang('NoDataAvailable'));
         }
     }
     $table = $attendance->getAttendanceLoginTable($startDate, $endDate);
     $data = array('form' => $formToDisplay, 'table' => $table);
     $this->view->set_data($data);
     $this->view->set_layout('layout');
     $this->view->set_template('calendar_logins');
     $this->view->render();
 }
Esempio n. 22
0
 /**
  * @param string $file
  */
 private function importUnsubscribeStatic($file)
 {
     $data = Import::csv_reader($file);
     if (!empty($data)) {
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $chamiloUserName = $row['UserName'];
             $chamiloCourseCode = $row['CourseCode'];
             $chamiloSessionId = $row['SessionID'];
             $sessionInfo = api_get_session_info($chamiloSessionId);
             if (empty($sessionInfo)) {
                 $this->logger->addError('Session does not exists: ' . $chamiloSessionId);
                 continue;
             }
             $courseInfo = api_get_course_info($chamiloCourseCode);
             if (empty($courseInfo)) {
                 $this->logger->addError('Course does not exists: ' . $courseInfo);
                 continue;
             }
             $userId = Usermanager::get_user_id_from_username($chamiloUserName);
             if (empty($userId)) {
                 $this->logger->addError('User does not exists: ' . $chamiloUserName);
                 continue;
             }
             CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId);
             $this->logger->addError("User '{$chamiloUserName}' was removed from session: #{$chamiloSessionId}, Course: " . $courseInfo['code']);
         }
     }
 }
Esempio n. 23
0
 /**
  * Gives a list of courses for the given user in the given session
  * @param integer $user_id
  * @param integer $session_id
  * @return array  list of statuses (session_id-course_code => status)
  */
 public static function get_courses_list_by_session($user_id, $session_id)
 {
     // Database Table Definitions
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     //we filter the courses from the URL
     $join_access_url = $where_access_url = '';
     if (api_get_multiple_access_url()) {
         $urlId = api_get_current_access_url_id();
         if ($urlId != -1) {
             $tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $join_access_url = " ,  {$tbl_url_session} url_rel_session ";
             $where_access_url = " AND access_url_id = {$urlId} AND url_rel_session.session_id = {$session_id} ";
         }
     }
     $personal_course_list = array();
     $courses = array();
     /* This query is very similar to the query below, but it will check the
        session_rel_course_user table if there are courses registered
        to our user or not */
     $sql = "SELECT DISTINCT\n                    c.visibility,\n                    c.id as real_id\n                FROM {$tbl_session_course_user} as scu\n                INNER JOIN {$tbl_session_course} sc\n                ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id)\n                INNER JOIN {$tableCourse} as c\n                ON (scu.c_id = c.id)\n                {$join_access_url}\n                WHERE\n                    scu.user_id = {$user_id} AND\n                    scu.session_id = {$session_id}\n                    {$where_access_url}\n                ORDER BY sc.position ASC";
     $result = Database::query($sql);
     if (Database::num_rows($result) > 0) {
         while ($result_row = Database::fetch_array($result, 'ASSOC')) {
             $result_row['status'] = 5;
             if (!in_array($result_row['real_id'], $courses)) {
                 $personal_course_list[] = $result_row;
                 $courses[] = $result_row['real_id'];
             }
         }
     }
     if (api_is_allowed_to_create_course()) {
         $sql = "SELECT DISTINCT\n                        c.visibility, c.id as real_id\n                    FROM {$tbl_session_course_user} as scu\n                    INNER JOIN {$tbl_session} as s\n                    ON (scu.session_id = s.id)\n                    INNER JOIN {$tbl_session_course} sc\n                    ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id)\n                    INNER JOIN {$tableCourse} as c\n                    ON (scu.c_id = c.id)\n                    {$join_access_url}\n                    WHERE\n                      s.id = {$session_id} AND\n                      (\n                        (scu.user_id={$user_id} AND scu.status=2) OR\n                        s.id_coach = {$user_id}\n                      )\n                    {$where_access_url}\n                    ORDER BY sc.position ASC";
         $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             while ($result_row = Database::fetch_array($result, 'ASSOC')) {
                 $result_row['status'] = 2;
                 if (!in_array($result_row['real_id'], $courses)) {
                     $personal_course_list[] = $result_row;
                     $courses[] = $result_row['real_id'];
                 }
             }
         }
     }
     if (api_is_drh()) {
         $session_list = SessionManager::get_sessions_followed_by_drh($user_id);
         $session_list = array_keys($session_list);
         if (in_array($session_id, $session_list)) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     $personal_course_list[] = $course;
                 }
             }
         }
     } else {
         //check if user is general coach for this session
         $s = api_get_session_info($session_id);
         if ($s['id_coach'] == $user_id) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     if (!in_array($course['id'], $courses)) {
                         $personal_course_list[] = $course;
                     }
                 }
             }
         }
     }
     return $personal_course_list;
 }
Esempio n. 24
0
 /**
  * Shows the general data for a particular meeting
  *
  * @param id	session id
  * @return string	session data
  */
 public static function show_session_data($id_session)
 {
     $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
     $user_table = Database::get_main_table(TABLE_MAIN_USER);
     $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
     $sessionInfo = api_get_session_info($id_session);
     if (empty($sessionInfo)) {
         return '';
     }
     $sql = 'SELECT name FROM ' . $session_category_table . '
             WHERE id = "' . intval($sessionInfo['session_category_id']) . '"';
     $rs_category = Database::query($sql);
     $session_category = '';
     if (Database::num_rows($rs_category) > 0) {
         $rows_session_category = Database::store_result($rs_category);
         $rows_session_category = $rows_session_category[0];
         $session_category = $rows_session_category['name'];
     }
     $coachInfo = api_get_user_info($sessionInfo['id_coach']);
     $output = '';
     if (!empty($session_category)) {
         $output .= '<tr><td>' . get_lang('SessionCategory') . ': ' . '<b>' . $session_category . '</b></td></tr>';
     }
     $dateInfo = SessionManager::parseSessionDates($sessionInfo);
     $msgDate = $dateInfo['access'];
     $output .= '<tr>
                 <td style="width:50%">' . get_lang('SessionName') . ': ' . '<b>' . $sessionInfo['name'] . '</b></td>
                 <td>' . get_lang('GeneralCoach') . ': ' . '<b>' . $coachInfo['complete_name'] . '</b></td></tr>';
     $output .= '<tr>
                     <td>' . get_lang('SessionIdentifier') . ': ' . Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) . '
                     </td>
                     <td>' . get_lang('Date') . ': ' . '<b>' . $msgDate . '</b>
                     </td>
                 </tr>';
     return $output;
 }
Esempio n. 25
0
 /**
  * Get the progress of a exercise
  * @param   int $sessionId  The session ID (session.id)
  * @param   int $courseId   The course ID (course.id)
  * @param   int $exerciseId The quiz ID (c_quiz.id)
  * @param   int $answer     The answer status (0 = incorrect, 1 = correct, 2 = both)
  * @param   array   $options    An array of options you can pass to the query (limit, where and order)
  * @return array An array with the data of exercise(s) progress
  */
 public static function get_exercise_progress($sessionId = 0, $courseId = 0, $exerciseId = 0, $date_from = null, $date_to = null, $options = array())
 {
     $sessionId = intval($sessionId);
     $courseId = intval($courseId);
     $exerciseId = intval($exerciseId);
     $date_from = Database::escape_string($date_from);
     $date_to = Database::escape_string($date_to);
     /*
      * This method gets the data by blocks, as previous attempts at one single
      * query made it take ages. The logic of query division is described below
      */
     // Get tables names
     $tuser = Database::get_main_table(TABLE_MAIN_USER);
     $tquiz = Database::get_course_table(TABLE_QUIZ_TEST);
     $tquiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $tquiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $tquiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $ttrack_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $ttrack_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $sessions = array();
     $courses = array();
     // if session ID is defined but course ID is empty, get all the courses
     // from that session
     if (!empty($sessionId) && empty($courseId)) {
         // $courses is an array of course int id as index and course details hash as value
         $courses = SessionManager::get_course_list_by_session_id($sessionId);
         $sessions[$sessionId] = api_get_session_info($sessionId);
     } elseif (empty($sessionId) && !empty($courseId)) {
         // if, to the contrary, course is defined but not sessions, get the sessions that include this course
         // $sessions is an array like: [0] => ('id' => 3, 'name' => 'Session 35'), [1] => () etc;
         $course = api_get_course_info_by_id($courseId);
         $sessionsTemp = SessionManager::get_session_by_course($courseId);
         $courses[$courseId] = $course;
         foreach ($sessionsTemp as $sessionItem) {
             $sessions[$sessionItem['id']] = $sessionItem;
         }
     } elseif (!empty($courseId) && !empty($sessionId)) {
         //none is empty
         $course = api_get_course_info_by_id($courseId);
         $courses[$courseId] = array($course['code']);
         $courses[$courseId]['code'] = $course['code'];
         $sessions[$sessionId] = api_get_session_info($sessionId);
     } else {
         //both are empty, not enough data, return an empty array
         return array();
     }
     // Now we have two arrays of courses and sessions with enough data to proceed
     // If no course could be found, we shouldn't return anything.
     // Sessions can be empty (then we only return the pure-course-context results)
     if (count($courses) < 1) {
         return array();
     }
     $data = array();
     // The following loop is less expensive than what it seems:
     // - if a course was defined, then we only loop through sessions
     // - if a session was defined, then we only loop through courses
     // - if a session and a course were defined, then we only loop once
     foreach ($courses as $courseIdx => $courseData) {
         $where = '';
         $whereParams = array();
         $whereSessionParams = '';
         if (count($sessions > 0)) {
             foreach ($sessions as $sessionIdx => $sessionData) {
                 if (!empty($sessionIdx)) {
                     $whereSessionParams .= $sessionIdx . ',';
                 }
             }
             $whereSessionParams = substr($whereSessionParams, 0, -1);
         }
         if (!empty($exerciseId)) {
             $exerciseId = intval($exerciseId);
             $where .= ' AND q.id = %d ';
             $whereParams[] = $exerciseId;
         }
         /*
          * This feature has been disabled for now, to avoid having to
          * join two very large tables
         //2 = show all questions (wrong and correct answered)
         if ($answer != 2) {
             $answer = intval($answer);
             //$where .= ' AND qa.correct = %d';
             //$whereParams[] = $answer;
         }
         */
         $limit = '';
         if (!empty($options['limit'])) {
             $limit = " LIMIT " . $options['limit'];
         }
         if (!empty($options['where'])) {
             $where .= ' AND ' . Database::escape_string($options['where']);
         }
         $order = '';
         if (!empty($options['order'])) {
             $order = " ORDER BY " . $options['order'];
         }
         if (!empty($date_to) && !empty($date_from)) {
             $where .= sprintf(" AND (te.start_date BETWEEN '%s 00:00:00' AND '%s 23:59:59')", $date_from, $date_to);
         }
         $sql = "SELECT\n                te.session_id,\n                ta.id as attempt_id,\n                te.exe_user_id as user_id,\n                te.exe_id as exercise_attempt_id,\n                ta.question_id,\n                ta.answer as answer_id,\n                ta.tms as time,\n                te.exe_exo_id as quiz_id,\n                CONCAT ('c', q.c_id, '_e', q.id) as exercise_id,\n                q.title as quiz_title,\n                qq.description as description\n                FROM {$ttrack_exercises} te\n                INNER JOIN {$ttrack_attempt} ta ON ta.exe_id = te.exe_id\n                INNER JOIN {$tquiz} q ON q.id = te.exe_exo_id\n                INNER JOIN {$tquiz_rel_question} rq ON rq.exercice_id = q.id AND rq.c_id = q.c_id\n                INNER JOIN {$tquiz_question} qq\n                ON\n                    qq.id = rq.question_id AND\n                    qq.c_id = rq.c_id AND\n                    qq.position = rq.question_order AND\n                    ta.question_id = rq.question_id\n                WHERE\n                    te.c_id = {$courseIdx} " . (empty($whereSessionParams) ? '' : "AND te.session_id IN ({$whereSessionParams})") . "\n                    AND q.c_id = {$courseIdx}\n                    {$where} {$order} {$limit}";
         $sql_query = vsprintf($sql, $whereParams);
         // Now browse through the results and get the data
         $rs = Database::query($sql_query);
         $userIds = array();
         $questionIds = array();
         $answerIds = array();
         while ($row = Database::fetch_array($rs)) {
             //only show if exercise is visible
             if (api_get_item_visibility($courseData, 'quiz', $row['exercise_id'])) {
                 $userIds[$row['user_id']] = $row['user_id'];
                 $questionIds[$row['question_id']] = $row['question_id'];
                 $answerIds[$row['question_id']][$row['answer_id']] = $row['answer_id'];
                 $row['session'] = $sessions[$row['session_id']];
                 $data[] = $row;
             }
         }
         // Now fill questions data. Query all questions and answers for this test to avoid
         $sqlQuestions = "SELECT tq.c_id, tq.id as question_id, tq.question, tqa.id_auto,\n                            tqa.answer, tqa.correct, tq.position, tqa.id_auto as answer_id\n                            FROM {$tquiz_question} tq, {$tquiz_answer} tqa\n                            WHERE\n                                tqa.question_id = tq.id AND\n                                tqa.c_id = tq.c_id AND\n                                tq.c_id = {$courseIdx} AND\n                                tq.id IN (" . implode(',', $questionIds) . ")";
         $resQuestions = Database::query($sqlQuestions);
         $answer = array();
         $question = array();
         while ($rowQuestion = Database::fetch_assoc($resQuestions)) {
             $questionId = $rowQuestion['question_id'];
             $answerId = $rowQuestion['answer_id'];
             $answer[$questionId][$answerId] = array('position' => $rowQuestion['position'], 'question' => $rowQuestion['question'], 'answer' => $rowQuestion['answer'], 'correct' => $rowQuestion['correct']);
             $question[$questionId]['question'] = $rowQuestion['question'];
         }
         // Now fill users data
         $sqlUsers = "SELECT user_id, username, lastname, firstname\n                         FROM {$tuser}\n                         WHERE user_id IN (" . implode(',', $userIds) . ")";
         $resUsers = Database::query($sqlUsers);
         while ($rowUser = Database::fetch_assoc($resUsers)) {
             $users[$rowUser['user_id']] = $rowUser;
         }
         foreach ($data as $id => $row) {
             $rowQuestId = $row['question_id'];
             $rowAnsId = $row['answer_id'];
             $data[$id]['session'] = $sessions[$row['session_id']]['name'];
             $data[$id]['firstname'] = $users[$row['user_id']]['firstname'];
             $data[$id]['lastname'] = $users[$row['user_id']]['lastname'];
             $data[$id]['username'] = $users[$row['user_id']]['username'];
             $data[$id]['answer'] = $answer[$rowQuestId][$rowAnsId]['answer'];
             $data[$id]['correct'] = $answer[$rowQuestId][$rowAnsId]['correct'] == 0 ? get_lang('No') : get_lang('Yes');
             $data[$id]['question'] = $question[$rowQuestId]['question'];
             $data[$id]['question_id'] = $rowQuestId;
             $data[$id]['description'] = $row['description'];
         }
         /*
         The minimum expected array structure at the end is:
         attempt_id,
         session name,
         exercise_id,
         quiz_title,
         username,
         lastname,
         firstname,
         time,
         question_id,
         question,
         answer,
         */
     }
     return $data;
 }
Esempio n. 26
0
SessionManager::protect_session_edit();
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('Sessions'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui-i18n'));
$htmlHeadXtra = api_get_datetime_picker_js($htmlHeadXtra);
$id = null;
$urlAction = api_get_self();
if (isset($_GET['id'])) {
    $id = intval($_GET['id']);
    $urlAction = '?id=' . $id;
}
$add_coach = null;
if ($id) {
    $tool_name = get_lang('EditSession');
    SessionManager::protect_session_edit($id);
    $session_info = api_get_session_info($id);
    if (!empty($session_info['id_coach'])) {
        $user_info = api_get_user_info($session_info['id_coach']);
        $add_coach = '$("#coach_id").trigger("addItem", [{"title": "' . $user_info['complete_name'] . '", "value": "' . $session_info['id_coach'] . '"}]);';
    }
    $button = get_lang('Update');
} else {
    $tool_name = get_lang('AddSession');
    $button = get_lang('Add');
}
$url = api_get_path(WEB_AJAX_PATH) . 'admin.ajax.php?1=1';
$htmlHeadXtra[] = '
<script>
function check() {
    $("#coach_id option:selected").each(function() {
        var id = $(this).val();
Esempio n. 27
0
 */
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
api_protect_admin_script(true);
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$commissionsEnable = $plugin->get('commissions_enable');
$action = isset($_GET['a']) ? $_GET['a'] : null;
switch ($action) {
    case 'saleInfo':
        //$saleId is only used in getSale() and is always filtered there
        $saleId = isset($_POST['id']) ? $_POST['id'] : '';
        $sale = $plugin->getSale($saleId);
        $productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session');
        $paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer');
        $productInfo = $sale['product_type'] == 1 ? api_get_course_info_by_id($sale['product_id']) : api_get_session_info($sale['product_id']);
        $currency = $plugin->getSelectedCurrency();
        if ($sale['product_type'] == 1) {
            $productImage = $productInfo['course_image_large'];
        } else {
            $productImage = $productInfo['image'] ? $productInfo['image'] : Template::get_icon_path('session_default.png');
        }
        $userInfo = api_get_user_info($sale['user_id']);
        $html = '<h2>' . $sale['product_name'] . '</h2>';
        $html .= '<div class="row">';
        $html .= '<div class="col-sm-6 col-md-6">';
        $html .= '<ul>';
        $html .= '<li><b>' . $plugin->get_lang('OrderPrice') . ':</b> ' . $sale['price'] . '</li>';
        $html .= '<li><b>' . $plugin->get_lang('CurrencyType') . ':</b> ' . $currency['iso_code'] . '</li>';
        $html .= '<li><b>' . $plugin->get_lang('ProductType') . ':</b> ' . $productType . '</li>';
        $html .= '<li><b>' . $plugin->get_lang('OrderDate') . ':</b> ' . api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H) . '</li>';
Esempio n. 28
0
 /**
  * Get the session coached by a user (general coach and course-session coach)
  * @param int $coachId The coach id
  * @param boolean $checkSessionRelUserVisibility Check the session visibility
  * @param boolean $asPlatformAdmin The user is a platform admin and we want all sessions
  * @return array The session list
  */
 public static function getSessionsCoachedByUser($coachId, $checkSessionRelUserVisibility = false, $asPlatformAdmin = false)
 {
     // Get all sessions where $coachId is the general coach
     $sessions = self::get_sessions_by_general_coach($coachId, $asPlatformAdmin);
     // Get all sessions where $coachId is the course - session coach
     $courseSessionList = self::getCoursesListByCourseCoach($coachId);
     $sessionsByCoach = array();
     if (!empty($courseSessionList)) {
         foreach ($courseSessionList as $userCourseSubscription) {
             $session = $userCourseSubscription->getSession();
             $sessionsByCoach[$session->getId()] = api_get_session_info($session->getId());
         }
     }
     if (!empty($sessionsByCoach)) {
         $sessions = array_merge($sessions, $sessionsByCoach);
     }
     // Remove repeated sessions
     if (!empty($sessions)) {
         $cleanSessions = array();
         foreach ($sessions as $session) {
             $cleanSessions[$session['id']] = $session;
         }
         $sessions = $cleanSessions;
     }
     if ($checkSessionRelUserVisibility) {
         if (!empty($sessions)) {
             $newSessions = array();
             foreach ($sessions as $session) {
                 $visibility = api_get_session_visibility($session['id']);
                 if ($visibility == SESSION_INVISIBLE) {
                     continue;
                 }
                 $newSessions[] = $session;
             }
             $sessions = $newSessions;
         }
     }
     return $sessions;
 }
 /**
  * @param string $uniqueId
  * @param int    $userId
  * @param int    $courseId
  * @param int    $sessionId
  */
 public function sendMailLink($uniqueId, $userId, $courseId, $sessionId)
 {
     $courseInfo = api_get_course_info_by_id($courseId);
     $courseCode = $courseInfo['code'];
     $url = api_get_path(WEB_CODE_PATH) . 'course_info/legal.php?web_agreement_link=' . $uniqueId . '&course_code=' . Security::remove_XSS($courseCode) . '&session_id=' . $sessionId;
     $courseUrl = Display::url($url, $url);
     $sessionInfo = api_get_session_info($sessionId);
     $sesstionTitle = null;
     if (!empty($sessionInfo)) {
         $sesstionTitle = ' (' . $sessionInfo['name'] . ')';
     }
     $courseTitle = $courseInfo['title'] . $sesstionTitle;
     $subject = $this->get_lang("MailAgreement");
     $message = sprintf($this->get_lang("MailAgreementWasSentWithClickX"), $courseTitle, $courseUrl);
     MessageManager::send_message_simple($userId, $subject, $message);
 }
Esempio n. 30
0
*	@author Bart Mollet, Julio Montoya lot of fixes
*	@package chamilo.admin
*/
/*		INIT SECTION */
// name of the language file that needs to be included
$language_file = 'admin';
$cidReset = true;
//require_once '../inc/global.inc.php';
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
$id_session = (int) $_GET['id_session'];
SessionManager::protect_session_edit($id_session);
$tool_name = get_lang('SessionOverview');
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('Sessions'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$session = api_get_session_info($id_session);
$session_cat_info = SessionManager::get_session_category($session['session_category_id']);
$session_category = null;
if (!empty($session_cat_info)) {
    $session_category = $session_cat_info['name'];
}
$action = isset($_GET['action']) ? $_GET['action'] : null;
$url_id = api_get_current_access_url_id();
switch ($action) {
    case 'add_user_to_url':
        $user_id = $_REQUEST['user_id'];
        $result = UrlManager::add_user_to_url($user_id, $url_id);
        $user_info = api_get_user_info($user_id);
        if ($result) {
            $message = Display::return_message(get_lang('UserAdded') . ' ' . api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
        }