public function is_allowed_to_edit()
 {
     if (Request::is_student_view()) {
         return false;
     }
     $session_id = Request::get_session_id();
     if ($session_id != 0 && api_is_allowed_to_session_edit(false, true) == false) {
         return false;
     }
     if (!api_is_allowed_to_edit(false, true, true)) {
         return false;
     }
     return true;
 }
 public function is_allowed_to_edit()
 {
     if (Request::is_student_view()) {
         return false;
     }
     //$c_id = self::params()->get_c_id();
     //$id = self::params()->get_id();
     $session_id = Request::get_session_id();
     if ($session_id != 0 && api_is_allowed_to_session_edit(false, true) == false) {
         return false;
     }
     if (!api_is_allowed_to_edit(false, true, true)) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
$tpl->assign('day_names', json_encode($days));
$tpl->assign('day_names_short', json_encode($day_short));
$tpl->assign('button_text', json_encode(array('today' => get_lang('Today'), 'month' => get_lang('Month'), 'week' => get_lang('Week'), 'day' => get_lang('Day'))));
//see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
$tpl->assign('js_format_date', 'D d M yy');
$region_value = api_get_language_isocode();
if ($region_value == 'en') {
    $region_value = 'en-GB';
}
$tpl->assign('region_value', $region_value);
$export_icon = '../img/export.png';
$export_icon_low = '../img/export_low_fade.png';
$export_icon_high = '../img/export_high_fade.png';
$tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')));
$actions = null;
if (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true) or $is_group_tutor) {
    if ($type == 'course') {
        if (isset($_GET['user_id'])) {
            $filter = $_GET['user_id'];
        }
        $actions = display_courseadmin_links($filter);
    }
    $tpl->assign('actions', $actions);
}
//Calendar Type : course, admin, personal
$tpl->assign('type', $type);
$type_event_class = $type . '_event';
$type_label = get_lang(ucfirst($type) . 'Calendar');
if ($type == 'course' && !empty($group_id)) {
    $type_event_class = 'group_event';
    $type_label = get_lang('GroupCalendar');
Exemplo n.º 4
0
    static function display_notes()
    {

        global $_user;
        if (!$_GET['direction']) {
            $sort_direction = 'ASC';
            $link_sort_direction = 'DESC';
        } elseif ($_GET['direction'] == 'ASC') {
            $sort_direction = 'ASC';
            $link_sort_direction = 'DESC';
        } else {
            $sort_direction = 'DESC';
            $link_sort_direction = 'ASC';
        }

        // action links
        echo '<div class="actions">';
        if (!api_is_anonymous()) {
            if (api_get_session_id() == 0)
                echo '<a href="index.php?' . api_get_cidreq() . '&amp;action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
            elseif (api_is_allowed_to_session_edit(false, true)) {
                echo '<a href="index.php?' . api_get_cidreq() . '&amp;action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
            }
        } else {
            echo '<a href="javascript:void(0)">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
        }

        echo '<a href="index.php?' . api_get_cidreq() . '&amp;action=changeview&amp;view=creation_date&amp;direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32') . '</a>';
        echo '<a href="index.php?' . api_get_cidreq() . '&amp;action=changeview&amp;view=update_date&amp;direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32') . '</a>';
        echo '<a href="index.php?' . api_get_cidreq() . '&amp;action=changeview&amp;view=title&amp;direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32') . '</a>';
        echo '</div>';

        if (!in_array($_SESSION['notebook_view'], array('creation_date', 'update_date', 'title'))) {
            $_SESSION['notebook_view'] = 'creation_date';
        }

        // Database table definition
        $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
        $order_by = "";
        if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') {
            $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction ";
        } else {
            $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction ";
        }

        //condition for the session
        $session_id = api_get_session_id();
        $condition_session = api_get_session_condition($session_id);

        $cond_extra = ($_SESSION['notebook_view'] == 'update_date') ? " AND update_date <> '0000-00-00 00:00:00'" : " ";
        $course_id = api_get_course_int_id();

        $sql = "SELECT * FROM $t_notebook WHERE c_id = $course_id AND user_id = '" . api_get_user_id() . "' $condition_session $cond_extra $order_by";
        $result = Database::query($sql);
        while ($row = Database::fetch_array($result)) {
            //validacion when belongs to a session
            $session_img = api_get_session_image($row['session_id'], $_user['status']);
            $creation_date = api_get_local_time($row['creation_date'], null, date_default_timezone_get());
            $update_date = api_get_local_time($row['update_date'], null, date_default_timezone_get());
            echo '<div class="sectiontitle">';
            echo '<span style="float: right;"> (' . get_lang('CreationDate') . ': ' . date_to_str_ago($creation_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $creation_date . '</span>';
            if ($row['update_date'] <> $row['creation_date']) {
                echo ', ' . get_lang('UpdateDate') . ': ' . date_to_str_ago($update_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $update_date . '</span>';
            }
            echo ')</span>';
            echo $row['title'] . $session_img;
            echo '</div>';
            echo '<div class="sectioncomment">' . $row['description'] . '</div>';
            echo '<div>';
            echo '<a href="' . api_get_self() . '?action=editnote&amp;notebook_id=' . $row['notebook_id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>';
            echo '<a href="' . api_get_self() . '?action=deletenote&amp;notebook_id=' . $row['notebook_id'] . '" onclick="return confirmation(\'' . $row['title'] . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
            echo '</div>';
        }
    }
Exemplo n.º 5
0
            $form->setConstants(array('sec_token' => $token));
            $form->display();
        }
        break;
    case 'delete':
        // Action handling: delete
        if ($check) {
            $res = $career->delete($_GET['id']);
            if ($res) {
                Display::display_confirmation_message(get_lang('ItemDeleted'));
            }
        }
        $career->display();
        break;
    case 'copy':
        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
            api_not_allowed();
        }
        if ($check) {
            $res = $career->copy($_GET['id'], true);
            //copy career and promotions inside
            if ($res) {
                Display::display_confirmation_message(get_lang('ItemCopied'));
            }
        }
        $career->display();
        break;
    default:
        $career->display();
        break;
}
Exemplo n.º 6
0
        }
        if ($action == 'upload_form') {
            $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UploadADocument'));
        }
        if ($action == 'settings') {
            $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditToolOptions'));
        }
        if ($action == 'create_dir') {
            $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateAssignment'));
        }
    }
}
// Stats
Event::event_access_tool(TOOL_STUDENTPUBLICATION);
$is_allowed_to_edit = api_is_allowed_to_edit();
$student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
/*	Display links to upload form and tool options */
if (!in_array($action, array('add', 'create_dir'))) {
    $token = Security::get_token();
}
$courseInfo = api_get_course_info();
$currentUrl = api_get_path(WEB_CODE_PATH) . 'work/work.php?' . api_get_cidreq();
$content = null;
// For teachers
switch ($action) {
    case 'settings':
        //if posts
        if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
            updateSettings($course, $_POST['show_score'], $_POST['student_delete_own_publication']);
            Session::write('message', Display::return_message(get_lang('Saved'), 'success'));
            header('Location: ' . $currentUrl);
Exemplo n.º 7
0
 /**
  * @param int $filter
  * @param string $view
  * @return string
  */
 public function displayActions($view, $filter = 0)
 {
     $courseInfo = api_get_course_info();
     $actionsLeft = '';
     $actionsLeft .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php?type={$this->type}'>" . Display::return_icon('calendar.png', get_lang('Calendar'), '', ICON_SIZE_MEDIUM) . "</a>";
     $courseCondition = '';
     if (!empty($courseInfo)) {
         $courseCondition = api_get_cidreq();
     }
     $actionsLeft .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_list.php?type={$this->type}&" . $courseCondition . "'>" . Display::return_icon('week.png', get_lang('AgendaList'), '', ICON_SIZE_MEDIUM) . "</a>";
     $form = '';
     if (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true) || GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
         $actionsLeft .= Display::url(Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=add&type=" . $this->type);
         $actionsLeft .= Display::url(Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=importical&type=" . $this->type);
         if ($this->type == 'course') {
             if (!isset($_GET['action'])) {
                 $form = new FormValidator('form-search', 'post', '', '', array(), FormValidator::LAYOUT_INLINE);
                 $attributes = array('multiple' => false, 'id' => 'select_form_id_search');
                 $selectedValues = $this->parseAgendaFilter($filter);
                 $this->showToForm($form, $selectedValues, $attributes);
                 $form = $form->returnForm();
             }
         }
     }
     if (api_is_platform_admin() || api_is_teacher() || api_is_student_boss() || api_is_drh() || api_is_session_admin() || api_is_coach()) {
         if ($this->type == 'personal') {
             $form = null;
             if (!isset($_GET['action'])) {
                 $form = new FormValidator('form-search', 'get', api_get_self() . '?type=personal&', '', array(), FormValidator::LAYOUT_INLINE);
                 $sessions = SessionManager::get_sessions_by_user(api_get_user_id());
                 $form->addHidden('type', 'personal');
                 $sessions = array_column($sessions, 'session_name', 'session_id');
                 $sessions = ['0' => get_lang('SelectAnOption')] + $sessions;
                 $form->addSelect('session_id', get_lang('Session'), $sessions, ['id' => 'session_id', 'onchange' => 'submit();']);
                 //$form->addButtonFilter(get_lang('Filter'));
                 //$renderer = $form->defaultRenderer();
                 //$renderer->setCustomElementTemplate('<div class="col-md-6">{element}</div>');
                 $form->addButtonReset(get_lang('Reset'));
                 $form = $form->returnForm();
             }
         }
     }
     $actionsRight = '';
     if ($view == 'calendar') {
         $actionsRight .= $form;
     }
     $toolbar = Display::toolbarAction('toolbar-agenda', array(0 => $actionsLeft, 1 => $actionsRight), 2, false);
     return $toolbar;
 }
Exemplo n.º 8
0
 /**
  * Display the exercise results
  * @param Exercise $objExercise
  * @param int $exe_id
  * @param bool $save_user_result save users results (true) or just show the results (false)
  */
 public static function display_question_list_by_attempt($objExercise, $exe_id, $save_user_result = false)
 {
     global $origin;
     // Getting attempt info
     $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
     // Getting question list
     $question_list = array();
     if (!empty($exercise_stat_info['data_tracking'])) {
         $question_list = explode(',', $exercise_stat_info['data_tracking']);
     } else {
         // Try getting the question list only if save result is off
         if ($save_user_result == false) {
             $question_list = $objExercise->get_validated_question_list();
         }
     }
     $counter = 1;
     $total_score = $total_weight = 0;
     $exercise_content = null;
     // Hide results
     $show_results = false;
     $show_only_score = false;
     if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) {
         $show_results = true;
     }
     if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
         $show_only_score = true;
     }
     // Not display expected answer, but score, and feedback
     $show_all_but_expected_answer = false;
     if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END) {
         $show_all_but_expected_answer = true;
         $show_results = true;
         $show_only_score = false;
     }
     if ($show_results || $show_only_score) {
         $user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
         //Shows exercise header
         echo $objExercise->show_exercise_result_header($user_info, api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration'], $exercise_stat_info['user_ip']);
     }
     // Display text when test is finished #4074 and for LP #4227
     $end_of_message = $objExercise->selectTextWhenFinished();
     if (!empty($end_of_message)) {
         Display::display_normal_message($end_of_message, false);
         echo "<div class='clear'>&nbsp;</div>";
     }
     $question_list_answers = array();
     $media_list = array();
     $category_list = array();
     // Loop over all question to show results for each of them, one by one
     if (!empty($question_list)) {
         foreach ($question_list as $questionId) {
             // creates a temporary Question object
             $objQuestionTmp = Question::read($questionId);
             // This variable came from exercise_submit_modal.php
             ob_start();
             // We're inside *one* question. Go through each possible answer for this question
             $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), array());
             if (empty($result)) {
                 continue;
             }
             // In case of global score, make sure the calculated total score is integer
             /*if (!is_int($result['score'])) {
                   $result['score'] = round($result['score']);
               }*/
             $total_score += $result['score'];
             $total_weight += $result['weight'];
             $question_list_answers[] = array('question' => $result['open_question'], 'answer' => $result['open_answer'], 'answer_type' => $result['answer_type']);
             $my_total_score = $result['score'];
             $my_total_weight = $result['weight'];
             // Category report
             $category_was_added_for_this_test = false;
             if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
                 if (!isset($category_list[$objQuestionTmp->category]['score'])) {
                     $category_list[$objQuestionTmp->category]['score'] = 0;
                 }
                 if (!isset($category_list[$objQuestionTmp->category]['total'])) {
                     $category_list[$objQuestionTmp->category]['total'] = 0;
                 }
                 $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
                 $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
                 $category_was_added_for_this_test = true;
             }
             if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
                 foreach ($objQuestionTmp->category_list as $category_id) {
                     $category_list[$category_id]['score'] += $my_total_score;
                     $category_list[$category_id]['total'] += $my_total_weight;
                     $category_was_added_for_this_test = true;
                 }
             }
             // No category for this question!
             if ($category_was_added_for_this_test == false) {
                 if (!isset($category_list['none']['score'])) {
                     $category_list['none']['score'] = 0;
                 }
                 if (!isset($category_list['none']['total'])) {
                     $category_list['none']['total'] = 0;
                 }
                 $category_list['none']['score'] += $my_total_score;
                 $category_list['none']['total'] += $my_total_weight;
             }
             if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
                 $my_total_score = 0;
             }
             $comnt = null;
             if ($show_results) {
                 $comnt = Event::get_comments($exe_id, $questionId);
                 if (!empty($comnt)) {
                     echo '<b>' . get_lang('Feedback') . '</b>';
                     echo '<div id="question_feedback">' . $comnt . '</div>';
                 }
             }
             if ($show_results) {
                 $score = array('result' => get_lang('Score') . " : " . self::show_score($my_total_score, $my_total_weight, false, true), 'pass' => $my_total_score >= $my_total_weight ? true : false, 'score' => $my_total_score, 'weight' => $my_total_weight, 'comments' => $comnt);
             } else {
                 $score = array();
             }
             $contents = ob_get_clean();
             $question_content = '';
             if ($show_results) {
                 $question_content = '<div class="question_row_answer">';
                 $show_media = false;
                 /*if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) {
                       $show_media = true;
                       $media_list[] = $objQuestionTmp->parent_id;
                   }*/
                 //Shows question title an description
                 $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
             }
             $counter++;
             $question_content .= $contents;
             if ($show_results) {
                 $question_content .= '</div>';
             }
             $exercise_content .= $question_content;
         }
         // end foreach() block that loops over all questions
     }
     $total_score_text = null;
     if ($origin != 'learnpath') {
         if ($show_results || $show_only_score) {
             $total_score_text .= '<div class="question_row_score">';
             $total_score_text .= self::get_question_ribbon($objExercise, $total_score, $total_weight, true);
             $total_score_text .= '</div>';
         }
     }
     if (!empty($category_list) && ($show_results || $show_only_score)) {
         //Adding total
         $category_list['total'] = array('score' => $total_score, 'total' => $total_weight);
         echo TestCategory::get_stats_table_by_attempt($objExercise->id, $category_list);
     }
     if ($show_all_but_expected_answer) {
         $exercise_content .= "<div class='normal-message'>" . get_lang("ExerciseWithFeedbackWithoutCorrectionComment") . "</div>";
     }
     // Remove audio auto play from questions on results page - refs BT#7939
     $exercise_content = preg_replace(['/autoplay[\\=\\".+\\"]+/', '/autostart[\\=\\".+\\"]+/'], '', $exercise_content);
     echo $total_score_text;
     echo $exercise_content;
     if (!$show_only_score) {
         echo $total_score_text;
     }
     if ($save_user_result) {
         // Tracking of results
         $learnpath_id = $exercise_stat_info['orig_lp_id'];
         $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
         $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
         if (api_is_allowed_to_session_edit()) {
             Event::update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], $question_list, '', array());
         }
         // Send notification ..
         if (!api_is_allowed_to_edit(null, true) && !api_is_excluded_user_type()) {
             if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1) {
                 $objExercise->send_mail_notification_for_exam($question_list_answers, $origin, $exe_id);
             }
             $objExercise->send_notification_for_open_questions($question_list_answers, $origin, $exe_id);
             $objExercise->send_notification_for_oral_questions($question_list_answers, $origin, $exe_id);
         }
     }
 }
Exemplo n.º 9
0
    $id_list = explode('_', $eventId);
    $eventId = $id_list[1];
    $event_type = $id_list[0];
}
if (!api_is_allowed_to_edit(null, true) && $event_type == 'course') {
    api_not_allowed(true);
}
if ($event_type == 'course') {
    $agendaUrl = api_get_path(WEB_CODE_PATH) . 'calendar/agenda_js.php?' . api_get_cidreq() . '&type=course';
} else {
    $agendaUrl = api_get_path(WEB_CODE_PATH) . 'calendar/agenda_js.php?&type=' . $event_type;
}
$course_info = api_get_course_info();
$agenda->type = $event_type;
$content = null;
if (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true) || GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)) {
    switch ($action) {
        case 'add':
            $actionName = get_lang('Add');
            $form = $agenda->getForm(array('action' => 'add'));
            if ($form->validate()) {
                $values = $form->getSubmitValues();
                $sendEmail = isset($values['add_announcement']) ? true : false;
                $allDay = isset($values['all_day']) ? 'true' : 'false';
                $sendAttachment = isset($_FILES['user_upload']) ? true : false;
                $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
                $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
                $comment = isset($values['comment']) ? $values['comment'] : null;
                $startDate = $values['date_range_start'];
                $endDate = $values['date_range_end'];
                $eventId = $agenda->addEvent($startDate, $endDate, $allDay, $values['title'], $values['content'], $values['users_to_send'], $sendEmail, null, $attachment, $attachmentComment, $comment);
Exemplo n.º 10
0
 /**
  * Kind of controller
  * @param string $action
  */
 public function handleAction($action)
 {
     $page = $this->page;
     switch ($action) {
         case 'export_to_pdf':
             if (isset($_GET['wiki_id'])) {
                 self::export_to_pdf($_GET['wiki_id'], api_get_course_id());
                 exit;
             }
             break;
         case 'export2doc':
             if (isset($_GET['wiki_id'])) {
                 $export2doc = self::export2doc($_GET['wiki_id']);
                 if ($export2doc) {
                     self::setMessage(Display::display_confirmation_message(get_lang('ThePageHasBeenExportedToDocArea'), false, true));
                 }
             }
             break;
         case 'restorepage':
             self::restorePage();
             break;
         case 'more':
             self::getStatsTable();
             break;
         case 'statistics':
             self::getStats();
             break;
         case 'mactiveusers':
             self::getActiveUsers($action);
             break;
         case 'usercontrib':
             self::getUserContributions($_GET['user_id'], $action);
             break;
         case 'mostchanged':
             $this->getMostChangedPages($action);
             break;
         case 'mvisited':
             self::getMostVisited();
             break;
         case 'wanted':
             $this->getWantedPages();
             break;
         case 'orphaned':
             self::getOrphaned();
             break;
         case 'mostlinked':
             self::getMostLinked();
             break;
         case 'delete':
             self::deletePageWarning($page);
             break;
         case 'deletewiki':
             $title = '<div class="actions">' . get_lang('DeleteWiki') . '</div>';
             if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
                 $message = get_lang('ConfirmDeleteWiki');
                 $message .= '<p>
                     <a href="index.php?' . api_get_cidreq() . '">' . get_lang('No') . '</a>
                     &nbsp;&nbsp;|&nbsp;&nbsp;
                     <a href="' . api_get_self() . '?' . api_get_cidreq() . '&action=deletewiki&delete=yes">' . get_lang('Yes') . '</a>
                 </p>';
                 if (!isset($_GET['delete'])) {
                     self::setMessage($title . Display::display_warning_message($message, false, true));
                 }
             } else {
                 self::setMessage(Display::display_normal_message(get_lang("OnlyAdminDeleteWiki"), false, true));
             }
             if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
                 if (isset($_GET['delete']) && $_GET['delete'] == 'yes') {
                     $return_message = self::delete_wiki();
                     self::setMessage(Display::display_confirmation_message($return_message, false, true));
                     $this->redirectHome();
                 }
             }
             break;
         case 'searchpages':
             self::getSearchPages($action);
             break;
         case 'links':
             self::getLinks($page);
             break;
         case 'addnew':
             if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
                 api_not_allowed();
             }
             echo '<div class="actions">' . get_lang('AddNew') . '</div>';
             echo '<br/>';
             //first, check if page index was created. chektitle=false
             if (self::checktitle('index')) {
                 if (api_is_allowed_to_edit(false, true) || api_is_platform_admin() || GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())) {
                     self::setMessage(Display::display_normal_message(get_lang('GoAndEditMainPage'), false, true));
                 } else {
                     self::setMessage(Display::display_normal_message(get_lang('WikiStandBy'), false, true));
                 }
             } elseif (self::check_addnewpagelock() == 0 && (api_is_allowed_to_edit(false, true) == false || api_is_platform_admin() == false)) {
                 self::setMessage(Display::display_error_message(get_lang('AddPagesLocked'), false, true));
             } else {
                 if (api_is_allowed_to_edit(false, true) || api_is_platform_admin() || GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) || $_GET['group_id'] == 0) {
                     self::display_new_wiki_form();
                 } else {
                     self::setMessage(Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers'), false, true));
                 }
             }
             break;
         case 'show':
             self::display_wiki_entry($page);
             break;
         case 'showpage':
             self::display_wiki_entry($page);
             break;
         case 'edit':
             self::editPage();
             break;
         case 'history':
             self::getHistory();
             break;
         case 'recentchanges':
             self::recentChanges($page, $action);
             break;
         case 'allpages':
             self::allPages($action);
             break;
         case 'discuss':
             self::getDiscuss($page);
             break;
         case 'export_to_doc_file':
             self::exportTo($_GET['id'], 'odt');
             exit;
             break;
     }
 }
Exemplo n.º 11
0
 /**
  * @param int $filter
  * @param string $view
  * @return string
  */
 public function displayActions($view, $filter = 0)
 {
     $actions = "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php?type={$this->type}'>" . Display::return_icon('calendar.png', get_lang('Calendar'), '', ICON_SIZE_MEDIUM) . "</a>";
     $actions .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_list.php?type={$this->type}&" . api_get_cidreq() . "'>" . Display::return_icon('week.png', get_lang('AgendaList'), '', ICON_SIZE_MEDIUM) . "</a>";
     if (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true) or GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
         if ($this->type == 'course') {
             $form = null;
             if (!isset($_GET['action'])) {
                 $form = new FormValidator('form-search');
                 $attributes = array('multiple' => false, 'id' => 'select_form_id_search');
                 $selectedValues = $this->parseAgendaFilter($filter);
                 $this->showToForm($form, $selectedValues, $attributes);
                 $form = $form->return_form();
             }
             $actions .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=add&type=course'>" . Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM) . "</a>";
             $actions .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=importical&type=course'>" . Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM) . "</a>";
             if ($view == 'calendar') {
                 $actions .= $form;
             }
         }
     }
     return $actions;
 }
Exemplo n.º 12
0
 /**
  * @param int $question_id
  * @param int $questionNum
  * @param array $questions_in_media
  * @param string $currentAnswer
  * @return string
  */
 public function show_button($question_id, $questionNum, $questions_in_media = array(), $currentAnswer = '')
 {
     global $origin, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id;
     $nbrQuestions = $this->get_count_question_list();
     $all_button = $html = $label = '';
     $hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']) : null;
     if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) {
         $html .= '<a href="exercise_submit_modal.php?learnpath_id=' . $safe_lp_id . '&learnpath_item_id=' . $safe_lp_item_id . '&learnpath_item_view_id=' . $safe_lp_item_view_id . '&origin=' . $origin . '&hotspot=' . $hotspot_get . '&nbrQuestions=' . $nbrQuestions . '&num=' . $questionNum . '&exerciseType=' . $this->type . '&exerciseId=' . $this->id . '&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox btn">';
         if ($questionNum == count($this->questionList)) {
             $html .= get_lang('EndTest') . '</a>';
         } else {
             $html .= get_lang('ContinueTest') . '</a>';
         }
         $html .= '<br />';
     } else {
         // User
         if (api_is_allowed_to_session_edit()) {
             if ($this->type == ALL_ON_ONE_PAGE || $nbrQuestions == $questionNum) {
                 if ($this->review_answers) {
                     $label = get_lang('ReviewQuestions');
                     $class = 'btn btn-success';
                 } else {
                     $label = get_lang('EndTest');
                     $class = 'btn btn-warning';
                 }
             } else {
                 $label = get_lang('NextQuestion');
                 $class = 'btn btn-primary';
             }
             $class .= ' question-validate-btn';
             // used to select it with jquery
             if ($this->type == ONE_PER_PAGE) {
                 if ($questionNum != 1) {
                     $prev_question = $questionNum - 2;
                     $all_button .= '<a href="javascript://" class="btn" onclick="previous_question_and_save(' . $prev_question . ', ' . $question_id . ' ); ">' . get_lang('PreviousQuestion') . '</a>';
                 }
                 //Next question
                 if (!empty($questions_in_media)) {
                     $questions_in_media = "['" . implode("','", $questions_in_media) . "']";
                     $all_button .= '&nbsp;<a href="javascript://" class="' . $class . '" onclick="save_question_list(' . $questions_in_media . '); ">' . $label . '</a>';
                 } else {
                     $all_button .= '&nbsp;<a href="javascript://" class="' . $class . '" onclick="save_now(' . $question_id . ', \'\', \'' . $currentAnswer . '\'); ">' . $label . '</a>';
                 }
                 $all_button .= '<span id="save_for_now_' . $question_id . '" class="exercise_save_mini_message"></span>&nbsp;';
                 $html .= $all_button;
             } else {
                 if ($this->review_answers) {
                     $all_label = get_lang('ReviewQuestions');
                     $class = 'btn btn-success';
                 } else {
                     $all_label = get_lang('EndTest');
                     $class = 'btn btn-warning';
                 }
                 $class .= ' question-validate-btn';
                 // used to select it with jquery
                 $all_button = '&nbsp;<a href="javascript://" class="' . $class . '" onclick="validate_all(); ">' . $all_label . '</a>';
                 $all_button .= '&nbsp;<span id="save_all_reponse"></span>';
                 $html .= $all_button;
             }
         }
     }
     return $html;
 }
Exemplo n.º 13
0
/**
 * @param int $start
 * @param int $limit
 * @param int $column
 * @param string $direction
 * @param int $work_id
 * @param array $where_condition
 * @param int $studentId
 * @param bool $getCount
 * @return array
 */
function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition = null, $studentId = null, $getCount = false)
{
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $session_id = api_get_session_id();
    $group_id = api_get_group_id();
    $course_info = api_get_course_info();
    $course_id = $course_info['real_id'];
    $work_id = intval($work_id);
    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);
    if (!in_array($direction, array('asc', 'desc'))) {
        $direction = 'desc';
    }
    $work_data = get_work_data_by_id($work_id);
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
    $condition_session = api_get_session_condition($session_id, true, false, 'work.session_id');
    $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION);
    $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), $course_info);
    if (!empty($work_data)) {
        if (!empty($group_id)) {
            $extra_conditions = " work.post_group_id = '" . intval($group_id) . "' ";
            // set to select only messages posted by the user's group
        } else {
            $extra_conditions = " work.post_group_id = '0' ";
        }
        if ($is_allowed_to_edit || $isDrhOfCourse) {
            $extra_conditions .= ' AND work.active IN (0, 1) ';
        } else {
            if (isset($course_info['show_score']) && $course_info['show_score'] == 1) {
                $extra_conditions .= " AND (u.user_id = " . api_get_user_id() . " AND work.active IN (0, 1)) ";
            } else {
                $extra_conditions .= ' AND work.active IN (0, 1) ';
            }
        }
        $extra_conditions .= " AND parent_id  = " . $work_id . " ";
        $select = 'SELECT DISTINCT
                        u.user_id,
                        work.id as id,
                        title as title,
                        description,
                        url,
                        sent_date,
                        contains_file,
                        has_properties,
                        view_properties,
                        qualification,
                        weight,
                        allow_text_assignment,
                        u.firstname,
                        u.lastname,
                        u.username,
                        parent_id,
                        accepted,
                        qualificator_id,
                        url_correction
                        ';
        if ($getCount) {
            $select = "SELECT DISTINCT count(u.user_id) as count ";
        }
        $user_condition = "INNER JOIN {$user_table} u  ON (work.user_id = u.user_id) ";
        $work_condition = "{$iprop_table} prop INNER JOIN {$work_table} work\n                           ON (prop.ref = work.id AND prop.c_id = {$course_id} AND work.c_id = {$course_id} ) ";
        $work_assignment = get_work_assignment_by_id($work_id);
        if (!empty($studentId)) {
            $where_condition .= " AND u.user_id = " . intval($studentId);
        }
        $sql = " {$select}\n                FROM {$work_condition}  {$user_condition}\n                WHERE {$extra_conditions} {$where_condition} {$condition_session}\n                    AND u.status != " . INVITEE . "\n                ORDER BY {$column} {$direction}";
        if (!empty($start) && !empty($limit)) {
            $sql .= " LIMIT {$start}, {$limit}";
        }
        $result = Database::query($sql);
        $works = array();
        if ($getCount) {
            $work = Database::fetch_array($result, 'ASSOC');
            return $work['count'];
        }
        $url = api_get_path(WEB_CODE_PATH) . 'work/';
        $unoconv = api_get_configuration_value('unoconv.binaries');
        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $item_id = $work['id'];
            // Get the author ID for that document from the item_property table
            $is_author = false;
            $can_read = false;
            $owner_id = $work['user_id'];
            /* Because a bug found when saving items using the api_item_property_update()
               the field $item_property_data['insert_user_id'] is not reliable. */
            if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) {
                $is_author = true;
            }
            if ($course_info['show_score'] == 0) {
                $can_read = true;
            }
            if ($work['accepted'] == '0') {
                $class = 'invisible';
            } else {
                $class = '';
            }
            $qualification_exists = false;
            if (!empty($work_data['qualification']) && intval($work_data['qualification']) > 0) {
                $qualification_exists = true;
            }
            $qualification_string = '';
            if ($qualification_exists) {
                if ($work['qualification'] == '') {
                    $qualification_string = Display::label('-');
                } else {
                    $label = 'info';
                    $relativeScore = $work['qualification'] / $work_data['qualification'];
                    if ($relativeScore < 0.5) {
                        $label = 'important';
                    } elseif ($relativeScore < 0.75) {
                        $label = 'warning';
                    }
                    $qualification_string = Display::label($work['qualification'] . ' / ' . $work_data['qualification'], $label);
                }
            }
            $work['qualification_score'] = $work['qualification'];
            $add_string = '';
            $time_expires = '';
            if (!empty($work_assignment['expires_on'])) {
                $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC');
            }
            if (!empty($work_assignment['expires_on']) && !empty($time_expires) && $time_expires < api_strtotime($work['sent_date'], 'UTC')) {
                $add_string = Display::label(get_lang('Expired'), 'important');
            }
            if ($can_read && $work['accepted'] == '1' || $is_author && in_array($work['accepted'], array('1', '0')) || ($is_allowed_to_edit || api_is_drh())) {
                // Firstname, lastname, username
                $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
                $work['lastname'] = Display::div($work['lastname'], array('class' => $class));
                $work['title_clean'] = $work['title'];
                if (strlen($work['title']) > 30) {
                    $short_title = substr($work['title'], 0, 27) . '...';
                    $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title']));
                } else {
                    $work['title'] = Display::div($work['title'], array('class' => $class));
                }
                // Type.
                $work['type'] = DocumentManager::build_document_icon_tag('file', $work['url']);
                // File name.
                $link_to_download = null;
                // If URL is present then there's a file to download keep BC.
                if ($work['contains_file'] || !empty($work['url'])) {
                    $link_to_download = '<a href="' . $url . 'download.php?id=' . $item_id . '&' . api_get_cidreq() . '">' . Display::return_icon('save.png', get_lang('Save'), array(), ICON_SIZE_SMALL) . '</a> ';
                }
                $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;'));
                $feedback = null;
                $count = getWorkCommentCount($item_id, $course_info);
                if (!is_null($count) && !empty($count)) {
                    if ($qualification_exists) {
                        $feedback .= "<br />";
                    }
                    $feedback .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::label($count . ' ' . get_lang('Feedback'), 'info') . '</a> ';
                }
                $work['qualification'] = $qualification_string . $feedback;
                $work['qualification_only'] = $qualification_string;
                // Date.
                $work_date = api_convert_and_format_date($work['sent_date']);
                $work['sent_date_from_db'] = $work['sent_date'];
                $work['sent_date'] = '<div class="date-time">' . date_to_str_ago(api_get_local_time($work['sent_date'])) . ' ' . $add_string . ' ' . $work_date . '</div>';
                // Actions.
                $correction = '';
                $action = '';
                if (api_is_allowed_to_edit()) {
                    if (!empty($work['url_correction'])) {
                        $action .= Display::url(Display::return_icon('check-circle.png', get_lang('Correction'), null, ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/download.php?id=' . $item_id . '&' . api_get_cidreq() . '&correction=1');
                    }
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a> ';
                    if ($unoconv && empty($work['contains_file'])) {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=export_to_doc&item_id=' . $item_id . '" title="' . get_lang('ExportToDoc') . '" >' . Display::return_icon('export_doc.png', get_lang('ExportToDoc'), array(), ICON_SIZE_SMALL) . '</a> ';
                    }
                    $correction = '
                        <form
                        id="file_upload_' . $item_id . '"
                        class="work_correction_file_upload file_upload_small"
                        action="' . api_get_path(WEB_AJAX_PATH) . 'work.ajax.php?' . api_get_cidreq() . '&a=upload_correction_file&item_id=' . $item_id . '" method="POST" enctype="multipart/form-data"
                        >
                        <div class="button-load">
                            ' . get_lang('ClickOrDropFilesHere') . '
                        </div>
                        <input type="file" name="file" multiple>
                        <button type="submit"></button>
                        </form>
                    ';
                    $correction .= "\n                        <script>\n                        \$(document).ready(function() {\n                            \$('#file_upload_" . $item_id . "').fileupload({\n                                uploadTable: \$('.files'),\n                                downloadTable: \$('.files'),\n                                buildUploadRow: function (files, index) {\n                                    \$('.files').show();\n                                    return\n                                        \$('<tr><td>' + files[index].name + '<\\/td>' +\n                                        '<td class=\"file_upload_progress\"><div><\\/div><\\/td>' +\n                                        '<td class=\"file_upload_cancel\">' +\n                                        '<button class=\"ui-state-default ui-corner-all\" title=\"" . get_lang('Cancel') . "\">' +\n                                        '<span class=\"ui-icon ui-icon-cancel\">" . get_lang('Cancel') . "<\\/span>' +'<\\/button>'+\n                                        '<\\/td><\\/tr>');\n                                },\n                                buildDownloadRow: function (file) {\n                                    return \$('<tr><td>' + file.name + '<\\/td> <td> ' + file.size + ' <\\/td>  <td>&nbsp;' + file.result + ' <\\/td> <\\/tr>');\n                                }\n                            });\n                        });\n                        </script>\n                    ";
                    if ($locked) {
                        if ($qualification_exists) {
                            $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= Display::return_icon('edit_na.png', get_lang('Comment'), array(), ICON_SIZE_SMALL);
                        }
                    } else {
                        if ($qualification_exists) {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Edit') . '"  >' . Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL) . '</a>';
                        } else {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                    }
                    if ($work['contains_file']) {
                        if ($locked) {
                            $action .= Display::return_icon('move_na.png', get_lang('Move'), array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=move&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Move') . '">' . Display::return_icon('move.png', get_lang('Move'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                    }
                    if ($work['accepted'] == '1') {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=make_invisible&item_id=' . $item_id . '" title="' . get_lang('Invisible') . '" >' . Display::return_icon('visible.png', get_lang('Invisible'), array(), ICON_SIZE_SMALL) . '</a>';
                    } else {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=make_visible&item_id=' . $item_id . '" title="' . get_lang('Visible') . '" >' . Display::return_icon('invisible.png', get_lang('Visible'), array(), ICON_SIZE_SMALL) . '</a> ';
                    }
                    if ($locked) {
                        $action .= Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
                    } else {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=delete&item_id=' . $item_id . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '" >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
                    }
                } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>';
                    if (api_get_course_setting('student_delete_own_publication') == 1) {
                        if (api_is_allowed_to_session_edit(false, true)) {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Comment'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                        $action .= ' <a href="' . $url . 'work_list.php?' . api_get_cidreq() . '&action=delete&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '"  >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
                    } else {
                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL);
                    }
                } else {
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>';
                    $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL);
                }
                // Status.
                if (empty($work['qualificator_id'])) {
                    $qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
                } else {
                    $qualificator_id = Display::label(get_lang('Revised'), 'success');
                }
                $work['qualificator_id'] = $qualificator_id;
                $work['actions'] = $send_to . $link_to_download . $action;
                $work['correction'] = $correction;
                $works[] = $work;
            }
        }
        return $works;
    }
}
Exemplo n.º 14
0
            'pdf'
        );
        break;
}

Display :: display_header(null);

echo $message;

$documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);

echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
    Display::return_icon('back.png', get_lang('BackToWorksList'), '', ICON_SIZE_MEDIUM).'</a>';

if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfCourse) {
    /*echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'">';
    echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';*/

    if (ADD_DOCUMENT_TO_WORK) {
        echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/add_document.php?'.api_get_cidreq().'&id='.$workId.'">';
        echo Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).'</a>';

        echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/add_user.php?'.api_get_cidreq().'&id='.$workId.'">';
        echo Display::return_icon('user.png', get_lang('AddUsers'), '', ICON_SIZE_MEDIUM).'</a>';

        echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=export_pdf">';
        echo Display::return_icon('pdf.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
    }

    $display_output = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_missing.php?'.api_get_cidreq().'&amp;id='.$workId.'&amp;list=without">'.
Exemplo n.º 15
0
/**
 * @param int $start
 * @param int $limit
 * @param int $column
 * @param string $direction
 * @param int $work_id
 * @param array $where_condition
 * @param int $studentId
 * @param bool $getCount
 * @return array
 */
function get_work_user_list(
    $start,
    $limit,
    $column,
    $direction,
    $work_id,
    $where_condition = null,
    $studentId = null,
    $getCount = false
) {
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
    $user_table = Database::get_main_table(TABLE_MAIN_USER);

    $session_id = api_get_session_id();
    $course_id = api_get_course_int_id();
    $group_id = api_get_group_id();
    $course_info = api_get_course_info(api_get_course_id());

    $work_id = intval($work_id);
    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);

    if (!in_array($direction, array('asc','desc'))) {
        $direction = 'desc';
    }

    $work_data = get_work_data_by_id($work_id);
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
    $condition_session  = api_get_session_condition($session_id);
    $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION);

    $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
        api_get_user_id(),
        $course_info
    );

    if (!empty($work_data)) {
        if (!empty($group_id)) {
            $extra_conditions = " work.post_group_id = '".intval($group_id)."' ";
            // set to select only messages posted by the user's group
        } else {
            $extra_conditions = " work.post_group_id = '0' ";
        }

        if ($is_allowed_to_edit || $isDrhOfCourse) {
            $extra_conditions .= ' AND work.active IN (0, 1) ';
        } else {
            if (isset($course_info['show_score']) &&
                $course_info['show_score'] == 1
            ) {
                $extra_conditions .= " AND (u.user_id = ".api_get_user_id()." AND work.active IN (0, 1)) ";
            } else {
                $extra_conditions .= ' AND work.active IN (0, 1) ';
            }
        }

        $extra_conditions .= " AND parent_id  = ".$work_id." ";

        $select = 'SELECT DISTINCT
                        u.user_id,
                        work.id as id,
                        title as title,
                        description,
                        url,
                        sent_date,
                        contains_file,
                        has_properties,
                        view_properties,
                        qualification,
                        weight,
                        allow_text_assignment,
                        u.firstname,
                        u.lastname,
                        u.username,
                        parent_id,
                        accepted,
                        qualificator_id';
        if ($getCount) {
            $select = "SELECT DISTINCT count(u.user_id) as count ";
        }

        $user_condition = "INNER JOIN $user_table u  ON (work.user_id = u.user_id) ";
        $work_condition = "$iprop_table prop INNER JOIN $work_table work
                           ON (prop.ref = work.id AND prop.c_id = $course_id AND work.c_id = $course_id ) ";

        $work_assignment = get_work_assignment_by_id($work_id);

        if (!empty($studentId)) {
            $where_condition.= " AND u.user_id = ".intval($studentId);
        }

        $sql = " $select
                FROM $work_condition  $user_condition
                WHERE $extra_conditions $where_condition $condition_session
                ORDER BY $column $direction";

        if (!empty($start) && !empty($limit)) {
            $sql .= " LIMIT $start, $limit";
        }
        $result = Database::query($sql);
        $works = array();

        if ($getCount) {
            $work = Database::fetch_array($result, 'ASSOC');
            return $work['count'];
        }

        $url = api_get_path(WEB_CODE_PATH).'work/';

        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $item_id = $work['id'];

            // Get the author ID for that document from the item_property table
            $is_author  = false;
            $can_read   = false;

            $owner_id = $work['user_id'];

            /* Because a bug found when saving items using the api_item_property_update()
               the field $item_property_data['insert_user_id'] is not reliable. */

            if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) {
                $is_author = true;
            }

            if ($course_info['show_score'] == 0) {
                $can_read = true;
            }

            if ($work['accepted'] == '0') {
                $class = 'invisible';
            } else {
                $class = '';
            }

            $qualification_exists = false;
            if (!empty($work_data['qualification']) &&
                intval($work_data['qualification']) > 0
            ) {
                $qualification_exists = true;
            }

            $qualification_string = '';
            if ($qualification_exists) {
                if ($work['qualification'] == '') {
                    $qualification_string = Display::label('-');
                } else {
                    $label = 'info';
                    $relativeScore = $work['qualification']/$work_data['qualification'];
                    if ($relativeScore < 0.5) {
                        $label = 'important';
                    } elseif ($relativeScore < 0.75) {
                        $label = 'warning';
                    }
                    $qualification_string = Display::label(
                        $work['qualification'].' / '.$work_data['qualification'],
                        $label
                    );
                }
            }

            $work['qualification_score'] = $work['qualification'];

            $add_string = '';
            $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC');

            if (!empty($work_assignment['expires_on']) &&
                $work_assignment['expires_on'] != '0000-00-00 00:00:00' &&
                $time_expires && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) {
                $add_string = Display::label(get_lang('Expired'), 'important');
            }

            if (($can_read && $work['accepted'] == '1') ||
                ($is_author && in_array($work['accepted'], array('1', '0'))) ||
                ($is_allowed_to_edit || api_is_drh())
            ) {
                // Firstname, lastname, username
                $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
                $work['lastname'] = Display::div($work['lastname'], array('class' => $class));

                if (strlen($work['title']) > 30) {
                    $short_title = substr($work['title'], 0, 27).'...';
                    $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title']));
                } else {
                    $work['title'] = Display::div($work['title'], array('class' => $class));
                }

                // Type.
                $work['type'] = build_document_icon_tag('file', $work['url']);

                // File name.
                $link_to_download = null;

                // If URL is present then there's a file to download keep BC.
                if ($work['contains_file'] || !empty($work['url'])) {
                    $link_to_download = '<a href="'.$url.'download.php?id='.$item_id.'&'.api_get_cidreq().'">'.
                        Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
                }

                $send_to = Portfolio::share('work', $work['id'],  array('style' => 'white-space:nowrap;'));

                $feedback = null;
                $count = getWorkCommentCount($item_id, $course_info);
                if (!is_null($count) && !empty($count)) {
                    if ($qualification_exists) {
                        $feedback .= "<br />";
                    }
                    $feedback .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::label($count.' '.get_lang('Feedback'), 'info').'</a> ';
                }

                $work['qualification'] = $qualification_string.$feedback;
                $work['qualification_only'] = $qualification_string;

                // Date.
                $work_date = api_convert_and_format_date($work['sent_date']);

                $work['sent_date_from_db'] = $work['sent_date'];
                $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])) . ' ' . $add_string . '<br />' . $work_date;

                // Actions.

                $action = '';
                if (api_is_allowed_to_edit()) {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';

                    if ($locked) {
                        if ($qualification_exists) {
                            $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= Display::return_icon('edit_na.png', get_lang('Comment'),array(), ICON_SIZE_SMALL);
                        }
                    } else {
                        if ($qualification_exists) {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Edit').'"  >'.
                                Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL).'</a>';
                        } else {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Modify').'">'.
                                Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
                        }
                    }

                    if ($work['contains_file']) {
                        if ($locked) {
                            $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= '<a href="'.$url.'work.php?'.api_get_cidreq().'&action=move&item_id='.$item_id.'" title="'.get_lang('Move').'">'.
                                Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
                        }
                    }

                    if ($work['accepted'] == '1') {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=make_invisible&item_id='.$item_id.'" title="'.get_lang('Invisible').'" >'.
                            Display::return_icon('visible.png', get_lang('Invisible'),array(), ICON_SIZE_SMALL).'</a>';
                    } else {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=make_visible&item_id='.$item_id.'" title="'.get_lang('Visible').'" >'.
                            Display::return_icon('invisible.png', get_lang('Visible'),array(), ICON_SIZE_SMALL).'</a> ';
                    }

                    if ($locked) {
                        $action .= Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
                    } else {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'.
                            Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                    }
                } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';

                    if (api_get_course_setting('student_delete_own_publication') == 1) {
                        if (api_is_allowed_to_session_edit(false, true)) {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Modify').'">'.
                                Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).'</a>';
                        }
                        $action .= ' <a href="'.$url.'work_list.php?'.api_get_cidreq().'&action=delete&item_id='.$item_id.'&id='.$work['parent_id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'.
                            Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                    } else {
                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                    }
                } else {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';
                    $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                }

                // Status.
                if (empty($work['qualificator_id'])) {
                    $qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
                } else {
                    $qualificator_id = Display::label(get_lang('Revised'), 'success');
                }
                $work['qualificator_id'] = $qualificator_id;
                $work['actions'] = $send_to.$link_to_download.$action;
                $works[] = $work;
            }
        }
        return $works;
    }
}
Exemplo n.º 16
0
// If no actions we proceed to show the document (Hack in order to use document.php?id=X)
if (isset($document_id) && empty($action)) {
    // Get the document data from the ID
    $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true, $sessionId);
    if ($sessionId != 0 && !$document_data) {
        // If there is a session defined and asking for the
        // document * from the session* didn't work, try it from the course
        // (out of a session context)
        $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true, 0);
    }
    // If the document is not a folder we show the document.
    if ($document_data) {
        $parent_id = $document_data['parent_id'];
        $visibility = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), $sessionId, api_get_user_id(), $groupId);
        if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
            if ($visibility && api_is_allowed_to_session_edit()) {
                $url = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document' . $document_data['path'] . '?' . api_get_cidreq();
                header("Location: {$url}");
            }
            exit;
        } else {
            if (!$visibility && !api_is_allowed_to_edit()) {
                api_not_allowed();
            }
        }
        $_GET['curdirpath'] = $document_data['path'];
    }
    // What's the current path?
    // We will verify this a bit further down
    if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
        $curdirpath = Security::remove_XSS($_GET['curdirpath']);
 public function is_allowed_to_edit()
 {
     $session_id = Request::get_session_id();
     if ($session_id != 0 && api_is_allowed_to_session_edit(false, true) == false) {
         return false;
     }
     //        if (!Security::check_token('get')) {
     //            return false;
     //        }
     if (!api_is_allowed_to_edit(false, true, true)) {
         return false;
     }
     return true;
 }
    /**
     * Writes the current data to the database
     * @return    boolean    Query result
     */
    public function write_to_db()
    {
        if (self::debug > 0) {
            error_log('learnpathItem::write_to_db()', 0);
        }
        // Check the session visibility.
        if (!api_is_allowed_to_session_edit()) {
            if (self::debug > 0) {
                error_log('return false api_is_allowed_to_session_edit');
            }
            return false;
        }
        $course_id = api_get_course_int_id();
        $mode = $this->get_lesson_mode();
        $credit = $this->get_credit();
        $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
        $sql_verified = 'SELECT status FROM ' . $item_view_table . '
		                 WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;';
        $rs_verified = Database::query($sql_verified);
        $row_verified = Database::fetch_array($rs_verified);
        $my_case_completed = array('completed', 'passed', 'browsed', 'failed');
        $save = true;
        if (isset($row_verified) && isset($row_verified['status'])) {
            if (in_array($row_verified['status'], $my_case_completed)) {
                $save = false;
            }
        }
        if (($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' or $mode == 'review' or $mode == 'browse')) && ($this->seriousgame_mode != 1 && $this->type == 'sco')) {
            if (self::debug > 1) {
                error_log("This info shouldn't be saved as the credit or lesson mode info prevent it");
                error_log('learnpathItem::write_to_db() - credit(' . $credit . ') or lesson_mode(' . $mode . ') prevent recording!', 0);
            }
        } else {
            // Check the row exists.
            $inserted = false;
            // This a special case for multiple attempts and Chamilo exercises.
            if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') {
                // We force the item to be restarted.
                $this->restart();
                $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')";
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql, 0);
                }
                $res = Database::query($sql);
                $this->db_item_view_id = Database::insert_id();
                $inserted = true;
            }
            $check_attempts = self::check_attempts($this->get_attempt_id());
            if (!$check_attempts) {
                return false;
            }
            $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
            $check = "SELECT * FROM {$item_view_table}\n                        WHERE\n                            c_id = {$course_id} AND\n                            lp_item_id = " . $this->db_id . " AND\n                            lp_view_id = " . $this->view_id . " AND\n                            view_count = " . $this->get_attempt_id();
            if (self::debug > 2) {
                error_log('learnpathItem::write_to_db() - Querying item_view: ' . $check, 0);
            }
            $check_res = Database::query($check);
            // Depending on what we want (really), we'll update or insert a new row
            // now save into DB.
            $res = 0;
            if (!$inserted && Database::num_rows($check_res) < 1) {
                $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')";
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Inserting into item_view: ' . $sql, 0);
                }
                $res = Database::query($sql);
                $this->db_item_view_id = Database::insert_id();
            } else {
                $sql = '';
                if ($this->type == 'hotpotatoes') {
                    $sql = "UPDATE {$item_view_table} " . "SET total_time = " . $this->get_total_time() . ", " . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . " status = '" . $this->get_status(false) . "'," . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                } else {
                    // For all other content types...
                    if ($this->type == 'quiz') {
                        $my_status = ' ';
                        $total_time = ' ';
                        if (!empty($_REQUEST['exeId'])) {
                            $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
                            $safe_exe_id = Database::escape_string($_REQUEST['exeId']);
                            $sql = 'SELECT start_date,exe_date FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . (int) $safe_exe_id;
                            $res = Database::query($sql);
                            $row_dates = Database::fetch_array($res);
                            $time_start_date = api_convert_sql_date($row_dates['start_date']);
                            $time_exe_date = api_convert_sql_date($row_dates['exe_date']);
                            $mytime = (int) $time_exe_date - (int) $time_start_date;
                            $total_time = " total_time = " . $mytime . ", ";
                        }
                    } else {
                        $my_type_lp = learnpath::get_type_static($this->lp_id);
                        // This is a array containing values finished
                        $case_completed = array('completed', 'passed', 'browsed', 'failed');
                        //is not multiple attempts
                        if ($this->seriousgame_mode == 1 && $this->type == 'sco') {
                            $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                            $my_status = " status = '" . $this->get_status(false) . "' ,";
                        } elseif ($this->get_prevent_reinit() == 1) {
                            // Process of status verified into data base.
                            $sql_verified = 'SELECT status FROM ' . $item_view_table . '
                                             WHERE c_id = ' . $course_id . ' AND lp_item_id = "' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;';
                            $rs_verified = Database::query($sql_verified);
                            $row_verified = Database::fetch_array($rs_verified);
                            // Get type lp: 1=lp dokeos and  2=scorm.
                            // If not is completed or passed or browsed and learning path is scorm.
                            if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                //&& $this->type!='dir'
                                $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } else {
                                // Verified into data base.
                                if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) {
                                    //&& $this->type!='dir'
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                    $my_status = " status = '" . $this->get_status(false) . "' ,";
                                } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') {
                                    //&& $this->type!='dir'
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                    $my_status = " status = '" . $this->get_status(false) . "' ,";
                                } else {
                                    //&& !in_array($row_verified['status'], $case_completed)
                                    //is lp dokeos
                                    if ($my_type_lp == 1 && $this->type != 'chapter') {
                                        $total_time = " total_time = total_time + " . $this->get_total_time() . ", ";
                                        $my_status = " status = '" . $this->get_status(false) . "' ,";
                                    }
                                }
                            }
                        } else {
                            // Multiple attempts are allowed.
                            if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                // Reset zero new attempt ?
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                $total_time = " total_time = " . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } else {
                                // It is dokeos LP.
                                $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            }
                            // Code added by Isaac Flores.
                            // This code line fixes the problem of wrong status.
                            if ($my_type_lp == 2) {
                                // Verify current status in multiples attempts.
                                $sql_status = 'SELECT status FROM ' . $item_view_table . '
                                               WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ';
                                $rs_status = Database::query($sql_status);
                                $current_status = Database::result($rs_status, 0, 'status');
                                if (in_array($current_status, $case_completed)) {
                                    $my_status = '';
                                    $total_time = '';
                                } else {
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                }
                            }
                        }
                    }
                    if ($this->type == 'sco') {
                        //IF scorm scorm_update_time has already updated total_tim in db
                        $sql = "UPDATE {$item_view_table} " . " SET " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                    } else {
                        $sql = "UPDATE {$item_view_table} " . "SET " . $total_time . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                    }
                    $this->current_start_time = time();
                }
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0);
                }
                $res = Database::query($sql);
            }
            if (is_array($this->interactions) && count($this->interactions) > 0) {
                // Save interactions.
                $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
                $sql = "SELECT id FROM {$tbl} " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND   lp_view_id = " . $this->view_id . " " . "AND   view_count = " . $this->get_attempt_id();
                $res = Database::query($sql);
                if (Database::num_rows($res) > 0) {
                    $row = Database::fetch_array($res);
                    $lp_iv_id = $row[0];
                    if (self::debug > 2) {
                        error_log('learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0);
                    }
                    foreach ($this->interactions as $index => $interaction) {
                        $correct_resp = '';
                        if (is_array($interaction[4]) && !empty($interaction[4][0])) {
                            foreach ($interaction[4] as $resp) {
                                $correct_resp .= $resp . ',';
                            }
                            $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1);
                        }
                        $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
                        $iva_sql = "SELECT id FROM {$iva_table} " . "WHERE c_id = {$course_id} AND lp_iv_id = {$lp_iv_id} " . "AND (order_id = {$index} " . "OR interaction_id = '" . Database::escape_string($interaction[0]) . "')";
                        $iva_res = Database::query($iva_sql);
                        // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
                        if (Database::num_rows($iva_res) > 0) {
                            // Update (or don't).
                            $iva_row = Database::fetch_array($iva_res);
                            $iva_id = $iva_row[0];
                            $ivau_sql = "UPDATE {$iva_table} " . "SET interaction_id = '" . Database::escape_string($interaction[0]) . "'," . "interaction_type = '" . Database::escape_string($interaction[1]) . "'," . "weighting = '" . Database::escape_string($interaction[3]) . "'," . "completion_time = '" . Database::escape_string($interaction[2]) . "'," . "correct_responses = '" . Database::escape_string($correct_resp) . "'," . "student_response = '" . Database::escape_string($interaction[5]) . "'," . "result = '" . Database::escape_string($interaction[6]) . "'," . "latency = '" . Database::escape_string($interaction[7]) . "'" . "WHERE c_id = {$course_id} AND id = {$iva_id}";
                            Database::query($ivau_sql);
                        } else {
                            // Insert new one.
                            $ivai_sql = "INSERT INTO {$iva_table} (c_id, order_id, lp_iv_id, interaction_id, interaction_type, " . "weighting, completion_time, correct_responses, " . "student_response, result, latency)" . "VALUES" . "({$course_id}, " . $index . "," . $lp_iv_id . ",'" . Database::escape_string($interaction[0]) . "','" . Database::escape_string($interaction[1]) . "'," . "'" . Database::escape_string($interaction[3]) . "','" . Database::escape_string($interaction[2]) . "','" . Database::escape_string($correct_resp) . "'," . "'" . Database::escape_string($interaction[5]) . "','" . Database::escape_string($interaction[6]) . "','" . Database::escape_string($interaction[7]) . "'" . ")";
                            Database::query($ivai_sql);
                        }
                    }
                }
            }
        }
        if (self::debug > 2) {
            error_log('End of learnpathItem::write_to_db()', 0);
        }
        return true;
    }
Exemplo n.º 19
0
         $html .= '<div class="thumbnail">' . display_user_image($row['user_id'], $name) . '</div>';
     }
     $html .= Display::tag('h4', display_user_link($row['user_id'], $name), array('class' => 'title-username'));
 } else {
     $html .= Display::tag('span', $name, array('title' => api_htmlentities($username, ENT_QUOTES)));
 }
 $html .= Display::tag('p', api_convert_and_format_date($row['post_date']), array('class' => 'post-date'));
 // get attach id
 $attachment_list = get_attachment($row['post_id']);
 $id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
 $iconEdit = '';
 // The user who posted it can edit his thread only if the course admin allowed
 // this in the properties of the forum
 // The course admin him/herself can do this off course always
 if (GroupManager::is_tutor_of_group($userId, $groupId) || $current_forum['allow_edit'] == 1 && $row['user_id'] == $_user['user_id'] || api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)) {
     if (api_is_allowed_to_session_edit(false, true)) {
         if ($locked == false) {
             $iconEdit .= "<a href=\"editpost.php?" . api_get_cidreq() . "&forum=" . $clean_forum_id . "&thread=" . $clean_thread_id . "&post=" . $row['post_id'] . "&origin=" . $origin . "&edit=edition&id_attach=" . $id_attach . "\">" . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . "</a>";
         }
     }
 }
 if ($origin != 'learnpath') {
     if (GroupManager::is_tutor_of_group($userId, $groupId) || api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)) {
         if ($locked == false) {
             $iconEdit .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&forum=" . $clean_forum_id . "&thread=" . $clean_thread_id . "&action=delete&content=post&id=" . $row['post_id'] . "&origin=" . $origin . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES)) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . "</a>";
         }
     }
     if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)) {
         $iconEdit .= return_visible_invisible_icon('post', $row['post_id'], $row['visible'], array('forum' => $clean_forum_id, 'thread' => $clean_thread_id, 'origin' => $origin));
         $iconEdit .= "";
         if ($increment > 0) {
Exemplo n.º 20
0
    }

    $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'group/group.php', 'name' => get_lang('Groups'));
    $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
}

$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId, 'name' =>  $my_folder_data['title']);

$documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);

Display :: display_header(null);

echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&origin='.$origin.'">'.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
    echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'">';
    echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';

if (!empty($my_folder_data['title'])) {
    echo Display::page_subheader($my_folder_data['title']);
}

$error_message = Session::read('error_message');
if (!empty($error_message)) {
    echo $error_message;
    Session::erase('error_message');
}
Exemplo n.º 21
0
 /**
  * Writes the current data to the database
  * @return    boolean    Query result
  */
 public function write_to_db()
 {
     if (self::debug > 0) {
         error_log('learnpathItem::write_to_db()', 0);
     }
     // Check the session visibility.
     if (!api_is_allowed_to_session_edit()) {
         if (self::debug > 0) {
             error_log('return false api_is_allowed_to_session_edit');
         }
         return false;
     }
     $course_id = api_get_course_int_id();
     $mode = $this->get_lesson_mode();
     $credit = $this->get_credit();
     $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
     $sql = 'SELECT status FROM ' . $item_view_table . '
             WHERE
                 c_id = ' . $course_id . ' AND
                 lp_item_id="' . $this->db_id . '" AND
                 lp_view_id="' . $this->view_id . '" AND
                 view_count="' . $this->get_attempt_id() . '" ';
     $rs_verified = Database::query($sql);
     $row_verified = Database::fetch_array($rs_verified);
     $my_case_completed = array('completed', 'passed', 'browsed', 'failed');
     $save = true;
     if (isset($row_verified) && isset($row_verified['status'])) {
         if (in_array($row_verified['status'], $my_case_completed)) {
             $save = false;
         }
     }
     if (($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' || $mode == 'review' || $mode == 'browse')) && ($this->seriousgame_mode != 1 && $this->type == 'sco')) {
         if (self::debug > 1) {
             error_log("This info shouldn't be saved as the credit or lesson mode info prevent it");
             error_log('learnpathItem::write_to_db() - credit(' . $credit . ') or' . ' lesson_mode(' . $mode . ') prevent recording!', 0);
         }
     } else {
         // Check the row exists.
         $inserted = false;
         // This a special case for multiple attempts and Chamilo exercises.
         if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') {
             // We force the item to be restarted.
             $this->restart();
             $params = array("c_id" => $course_id, "total_time" => $this->get_total_time(), "start_time" => $this->current_start_time, "score" => $this->get_score(), "status" => $this->get_status(false), "max_score" => $this->get_max(), "lp_item_id" => $this->db_id, "lp_view_id" => $this->view_id, "view_count" => $this->get_attempt_id(), "suspend_data" => $this->current_data, "lesson_location" => $this->lesson_location);
             if (self::debug > 2) {
                 error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1), 0);
             }
             $this->db_item_view_id = Database::insert($item_view_table, $params);
             if ($this->db_item_view_id) {
                 $sql = "UPDATE {$item_view_table} SET id = iid\n                            WHERE iid = " . $this->db_item_view_id;
                 Database::query($sql);
                 $inserted = true;
             }
         }
         $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
         $sql = "SELECT * FROM {$item_view_table}\n                    WHERE\n                        c_id = {$course_id} AND\n                        lp_item_id = " . $this->db_id . " AND\n                        lp_view_id = " . $this->view_id . " AND\n                        view_count = " . intval($this->get_attempt_id());
         if (self::debug > 2) {
             error_log('learnpathItem::write_to_db() - Querying item_view: ' . $sql, 0);
         }
         $check_res = Database::query($sql);
         // Depending on what we want (really), we'll update or insert a new row
         // now save into DB.
         if (!$inserted && Database::num_rows($check_res) < 1) {
             $params = array("c_id" => $course_id, "total_time" => $this->get_total_time(), "start_time" => $this->current_start_time, "score" => $this->get_score(), "status" => $this->get_status(false), "max_score" => $this->get_max(), "lp_item_id" => $this->db_id, "lp_view_id" => $this->view_id, "view_count" => $this->get_attempt_id(), "suspend_data" => $this->current_data, "lesson_location" => $this->lesson_location);
             if (self::debug > 2) {
                 error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1), 0);
             }
             $this->db_item_view_id = Database::insert($item_view_table, $params);
             if ($this->db_item_view_id) {
                 $sql = "UPDATE {$item_view_table} SET id = iid\n                            WHERE iid = " . $this->db_item_view_id;
                 Database::query($sql);
             }
         } else {
             if ($this->type == 'hotpotatoes') {
                 $params = array('total_time' => $this->get_total_time(), 'start_time' => $this->get_current_start_time(), 'score' => $this->get_score(), 'status' => $this->get_status(false), 'max_score' => $this->get_max(), 'suspend_data' => $this->current_data, 'lesson_location' => $this->lesson_location);
                 $where = array('c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => array($course_id, $this->db_id, $this->view_id, $this->get_attempt_id()));
                 Database::update($item_view_table, $params, $where);
             } else {
                 // For all other content types...
                 $my_status = ' ';
                 $total_time = ' ';
                 if ($this->type == 'quiz') {
                     if (!empty($_REQUEST['exeId'])) {
                         $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
                         $safe_exe_id = intval($_REQUEST['exeId']);
                         $sql = "SELECT start_date,exe_date\n                                    FROM {$TBL_TRACK_EXERCICES}\n                                    WHERE exe_id = {$safe_exe_id}";
                         $res = Database::query($sql);
                         $row_dates = Database::fetch_array($res);
                         $time_start_date = convert_sql_date($row_dates['start_date']);
                         $time_exe_date = convert_sql_date($row_dates['exe_date']);
                         $mytime = (int) $time_exe_date - (int) $time_start_date;
                         $total_time = " total_time = " . $mytime . ", ";
                     }
                 } else {
                     $my_type_lp = learnpath::get_type_static($this->lp_id);
                     // This is a array containing values finished
                     $case_completed = array('completed', 'passed', 'browsed', 'failed');
                     // Is not multiple attempts
                     if ($this->seriousgame_mode == 1 && $this->type == 'sco') {
                         $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                         $my_status = " status = '" . $this->get_status(false) . "' ,";
                     } elseif ($this->get_prevent_reinit() == 1) {
                         // Process of status verified into data base.
                         $sql = 'SELECT status FROM ' . $item_view_table . '
                                 WHERE
                                     c_id = ' . $course_id . ' AND
                                     lp_item_id="' . $this->db_id . '" AND
                                     lp_view_id="' . $this->view_id . '" AND
                                     view_count="' . $this->get_attempt_id() . '"
                                 ';
                         $rs_verified = Database::query($sql);
                         $row_verified = Database::fetch_array($rs_verified);
                         // Get type lp: 1=lp dokeos and  2=scorm.
                         // If not is completed or passed or browsed and learning path is scorm.
                         if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                             $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                             $my_status = " status = '" . $this->get_status(false) . "' ,";
                         } else {
                             // Verified into database.
                             if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) {
                                 $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                 $my_status = " status = '" . $this->get_status(false) . "' ,";
                             } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') {
                                 $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                 $my_status = " status = '" . $this->get_status(false) . "' ,";
                             } else {
                                 if ($my_type_lp == 3 && $this->type == 'au' || $my_type_lp == 1 && $this->type != 'chapter') {
                                     // Is AICC or Chamilo LP
                                     $total_time = " total_time = total_time + " . $this->get_total_time() . ", ";
                                     $my_status = " status = '" . $this->get_status(false) . "' ,";
                                 }
                             }
                         }
                     } else {
                         // Multiple attempts are allowed.
                         if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                             // Reset zero new attempt ?
                             $my_status = " status = '" . $this->get_status(false) . "' ,";
                         } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                             $total_time = " total_time = " . $this->get_total_time() . ", ";
                             $my_status = " status = '" . $this->get_status(false) . "' ,";
                         } else {
                             // It is chamilo LP.
                             $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                             $my_status = " status = '" . $this->get_status(false) . "' ,";
                         }
                         // This code line fixes the problem of wrong status.
                         if ($my_type_lp == 2) {
                             // Verify current status in multiples attempts.
                             $sql = 'SELECT status FROM ' . $item_view_table . '
                                     WHERE
                                         c_id = ' . $course_id . ' AND
                                         lp_item_id="' . $this->db_id . '" AND
                                         lp_view_id="' . $this->view_id . '" AND
                                         view_count="' . $this->get_attempt_id() . '" ';
                             $rs_status = Database::query($sql);
                             $current_status = Database::result($rs_status, 0, 'status');
                             if (in_array($current_status, $case_completed)) {
                                 $my_status = '';
                                 $total_time = '';
                             } else {
                                 $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                             }
                         }
                     }
                 }
                 if ($this->type == 'sco') {
                     //IF scorm scorm_update_time has already updated total_time in db
                     //" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it
                     ////" max_time_allowed = '".$this->get_max_time_allowed()."'," .
                     $sql = "UPDATE {$item_view_table} SET\n                                    score = " . $this->get_score() . ",\n                                    {$my_status}\n                                    max_score = '" . $this->get_max() . "',\n                                    suspend_data = '" . Database::escape_string($this->current_data) . "',\n                                    lesson_location = '" . $this->lesson_location . "'\n                                WHERE\n                                    c_id = {$course_id} AND\n                                    lp_item_id = " . $this->db_id . " AND\n                                    lp_view_id = " . $this->view_id . "  AND\n                                    view_count = " . $this->get_attempt_id();
                 } else {
                     //" max_time_allowed = '".$this->get_max_time_allowed()."'," .
                     $sql = "UPDATE {$item_view_table} SET\n                                    {$total_time}\n                                    start_time = " . $this->get_current_start_time() . ",\n                                    score = " . $this->get_score() . ",\n                                    {$my_status}\n                                    max_score = '" . $this->get_max() . "',\n                                    suspend_data = '" . Database::escape_string($this->current_data) . "',\n                                    lesson_location = '" . $this->lesson_location . "'\n                                WHERE\n                                    c_id = {$course_id} AND\n                                    lp_item_id = " . $this->db_id . " AND\n                                    lp_view_id = " . $this->view_id . " AND\n                                    view_count = " . $this->get_attempt_id();
                 }
                 $this->current_start_time = time();
             }
             if (self::debug > 2) {
                 error_log('learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0);
             }
             Database::query($sql);
         }
         if (is_array($this->interactions) && count($this->interactions) > 0) {
             // Save interactions.
             $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
             $sql = "SELECT id FROM {$tbl}\n                        WHERE\n                            c_id = {$course_id} AND\n                            lp_item_id = " . $this->db_id . " AND\n                            lp_view_id = " . $this->view_id . " AND\n                            view_count = " . $this->get_attempt_id();
             $res = Database::query($sql);
             if (Database::num_rows($res) > 0) {
                 $row = Database::fetch_array($res);
                 $lp_iv_id = $row[0];
                 if (self::debug > 2) {
                     error_log('learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0);
                 }
                 foreach ($this->interactions as $index => $interaction) {
                     $correct_resp = '';
                     if (is_array($interaction[4]) && !empty($interaction[4][0])) {
                         foreach ($interaction[4] as $resp) {
                             $correct_resp .= $resp . ',';
                         }
                         $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1);
                     }
                     $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
                     //also check for the interaction ID as it must be unique for this SCO view
                     $iva_sql = "SELECT id FROM {$iva_table}\n                                    WHERE\n                                        c_id = {$course_id} AND\n                                        lp_iv_id = {$lp_iv_id} AND\n                                        (\n                                            order_id = {$index} OR\n                                            interaction_id = '" . Database::escape_string($interaction[0]) . "'\n                                        )\n                                    ";
                     $iva_res = Database::query($iva_sql);
                     // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
                     if (Database::num_rows($iva_res) > 0) {
                         // Update (or don't).
                         $iva_row = Database::fetch_array($iva_res);
                         $iva_id = $iva_row[0];
                         // Insert new one.
                         $params = array('interaction_id' => $interaction[0], 'interaction_type' => $interaction[1], 'weighting' => $interaction[3], 'completion_time' => $interaction[2], 'correct_responses' => $correct_resp, 'student_response' => $interaction[5], 'result' => $interaction[6], 'latency' => $interaction[7]);
                         Database::update($iva_table, $params, array('c_id = ? AND id = ?' => array($course_id, $iva_id)));
                     } else {
                         // Insert new one.
                         $params = array('c_id' => $course_id, 'order_id' => $index, 'lp_iv_id' => $lp_iv_id, 'interaction_id' => $interaction[0], 'interaction_type' => $interaction[1], 'weighting' => $interaction[3], 'completion_time' => $interaction[2], 'correct_responses' => $correct_resp, 'student_response' => $interaction[5], 'result' => $interaction[6], 'latency' => $interaction[7]);
                         $insertId = Database::insert($iva_table, $params);
                         if ($insertId) {
                             $sql = "UPDATE {$iva_table} SET id = iid\n                                        WHERE iid = {$insertId}";
                             Database::query($sql);
                         }
                     }
                 }
             }
         }
     }
     if (self::debug > 2) {
         error_log('End of learnpathItem::write_to_db()', 0);
     }
     return true;
 }
Exemplo n.º 22
0
 /**
  * @param int $question_id
  * @param int $questionNum
  * @param array $questions_in_media
  * @param string $currentAnswer
  * @return string
  */
 public function show_button($question_id, $questionNum, $questions_in_media = array(), $currentAnswer = '')
 {
     global $origin, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id;
     $nbrQuestions = $this->get_count_question_list();
     $all_button = $html = $label = '';
     $hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']) : null;
     if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) {
         $urlTitle = get_lang('ContinueTest');
         if ($questionNum == count($this->questionList)) {
             $urlTitle = get_lang('EndTest');
         }
         $html .= Display::url($urlTitle, 'exercise_submit_modal.php?' . http_build_query(['learnpath_id' => $safe_lp_id, 'learnpath_item_id' => $safe_lp_item_id, 'learnpath_item_view_id' => $safe_lp_item_view_id, 'origin' => $origin, 'hotspot' => $hotspot_get, 'nbrQuestions' => $nbrQuestions, 'num' => $questionNum, 'exerciseType' => $this->type, 'exerciseId' => $this->id]), ['class' => 'ajax btn btn-default', 'data-title' => $urlTitle, 'data-size' => 'md']);
         $html .= '<br />';
     } else {
         // User
         if (api_is_allowed_to_session_edit()) {
             if ($this->type == ALL_ON_ONE_PAGE || $nbrQuestions == $questionNum) {
                 if ($this->review_answers) {
                     $label = get_lang('ReviewQuestions');
                     $class = 'btn btn-success';
                 } else {
                     $label = get_lang('EndTest');
                     $class = 'btn btn-warning';
                 }
             } else {
                 $label = get_lang('NextQuestion');
                 $class = 'btn btn-primary';
             }
             $class .= ' question-validate-btn';
             // used to select it with jquery
             if ($this->type == ONE_PER_PAGE) {
                 if ($questionNum != 1) {
                     $prev_question = $questionNum - 2;
                     $all_button .= '<a href="javascript://" class="btn btn-default" onclick="previous_question_and_save(' . $prev_question . ', ' . $question_id . ' ); ">' . get_lang('PreviousQuestion') . '</a>';
                 }
                 //Next question
                 if (!empty($questions_in_media)) {
                     $questions_in_media = "['" . implode("','", $questions_in_media) . "']";
                     $all_button .= '&nbsp;<a href="javascript://" class="' . $class . '" onclick="save_question_list(' . $questions_in_media . '); ">' . $label . '</a>';
                 } else {
                     $all_button .= '&nbsp;<a href="javascript://" class="' . $class . '" onclick="save_now(' . $question_id . ', \'\', \'' . $currentAnswer . '\'); ">' . $label . '</a>';
                 }
                 $all_button .= '<span id="save_for_now_' . $question_id . '" class="exercise_save_mini_message"></span>&nbsp;';
                 $html .= $all_button;
             } else {
                 if ($this->review_answers) {
                     $all_label = get_lang('ReviewQuestions');
                     $class = 'btn btn-success';
                 } else {
                     $all_label = get_lang('EndTest');
                     $class = 'btn btn-warning';
                 }
                 $class .= ' question-validate-btn';
                 // used to select it with jquery
                 $all_button = '&nbsp;<a href="javascript://" class="' . $class . '" onclick="validate_all(); ">' . $all_label . '</a>';
                 $all_button .= '&nbsp;' . Display::span(null, ['id' => 'save_all_reponse']);
                 $html .= $all_button;
             }
         }
     }
     return $html;
 }
Exemplo n.º 23
0
    if (!api_is_allowed_to_edit()) {
        api_not_allowed(true);
    }
}
// Header
Display::display_header(get_lang('SurveyPreview'));
// We exit here is the first or last question is a pagebreak (which causes errors)
SurveyUtil::check_first_last_question($survey_id, false);
// Only a course admin is allowed to preview a survey: you are NOT a course admin => error message
/*
if (!api_is_allowed_to_edit(false, true)) {
	Display :: display_error_message(get_lang('NotAllowed'), false);
}*/
$counter_question = 0;
// Only a course admin is allowed to preview a survey: you are a course admin
if (api_is_course_admin() || api_is_course_admin() && $_GET['isStudentView'] == 'true' || api_is_allowed_to_session_edit(false, true)) {
    // Survey information
    echo '<div id="survey_title">' . $survey_data['survey_title'] . '</div>';
    echo '<div id="survey_subtitle">' . $survey_data['survey_subtitle'] . '</div>';
    // Displaying the survey introduction
    if (!isset($_GET['show'])) {
        if (!empty($survey_data['survey_introduction'])) {
            echo '<div id="survey_content" class="survey_content">' . $survey_data['survey_introduction'] . '</div>';
        }
        $limit = 0;
    }
    // Displaying the survey thanks message
    if (isset($_POST['finish_survey'])) {
        Display::display_confirmation_message(get_lang('SurveyFinished'));
        echo $survey_data['survey_thanks'];
        Display::display_footer();
Exemplo n.º 24
0
         if (isset($_GET['id']) && $_GET['id']) {
             if ($sessionId != 0 && api_is_allowed_to_session_edit(false, true) == false) {
                 api_not_allowed();
             }
             if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) {
                 AnnouncementManager::change_visibility_announcement($_course, $_GET['id']);
                 Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
                 header('Location: ' . $homeUrl);
                 exit;
             }
         }
     }
     break;
 case 'add':
 case 'modify':
     if ($sessionId != 0 && api_is_allowed_to_session_edit(false, true) == false) {
         api_not_allowed(true);
     }
     // DISPLAY ADD ANNOUNCEMENT COMMAND
     $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     $url = api_get_self() . '?action=' . $action . '&id=' . $id . '&' . api_get_cidreq();
     $form = new FormValidator('f1', 'post', $url, null, array('enctype' => 'multipart/form-data'));
     if (empty($id)) {
         $form_name = get_lang('AddAnnouncement');
     } else {
         $form_name = get_lang('ModifyAnnouncement');
     }
     $form->addElement('header', $form_name);
     $to = [];
     if (empty($group_id)) {
         if (isset($_GET['remind_inactive'])) {
Exemplo n.º 25
0
 /**
  * Display the exercise results
  * @param int  $exe_id
  * @param bool $saveUserResult save users results (true) or just show the results (false)
  * @param bool $returnExerciseResult return array with exercise result info
  * @return mixed
  */
 public function displayQuestionListByAttempt($exe_id, $saveUserResult = false, $returnExerciseResult = false)
 {
     global $origin, $debug;
     //Getting attempt info
     $exercise_stat_info = $this->getStatTrackExerciseInfoByExeId($exe_id);
     //Getting question list
     $question_list = array();
     if (!empty($exercise_stat_info['data_tracking'])) {
         $question_list = explode(',', $exercise_stat_info['data_tracking']);
     } else {
         //Try getting the question list only if save result is off
         if ($saveUserResult == false) {
             $question_list = $this->selectQuestionList();
         }
         error_log("Data tracking is empty! exe_id: {$exe_id}");
     }
     $counter = 1;
     $total_score = 0;
     $total_weight = 0;
     $exercise_content = null;
     //Hide results
     $show_results = false;
     $show_only_score = false;
     if ($this->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) {
         $show_results = true;
     }
     if (in_array($this->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
         $show_only_score = true;
     }
     if ($show_results || $show_only_score) {
         $user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
         // Shows exercise header.
         echo $this->show_exercise_result_header($user_info['complete_name'], api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration']);
     }
     // Display text when test is finished #4074 and for LP #4227
     $end_of_message = $this->selectTextWhenFinished();
     if (!empty($end_of_message)) {
         Display::display_normal_message($end_of_message, false);
         echo "<div class='clear'>&nbsp;</div>";
     }
     $question_list_answers = array();
     $media_list = array();
     $category_list = array();
     $tempParentId = null;
     $mediaCounter = 0;
     $exerciseResultInfo = array();
     // Loop over all question to show results for each of them, one by one
     if (!empty($question_list)) {
         if ($debug) {
             error_log('Looping question_list ' . print_r($question_list, 1));
         }
         foreach ($question_list as $questionId) {
             // Creates a temporary Question object
             $objQuestionTmp = Question::read($questionId);
             // This variable commes from exercise_submit_modal.php
             ob_start();
             $hotspot_delineation_result = null;
             // We're inside *one* question. Go through each possible answer for this question
             $result = $this->manageAnswers($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $saveUserResult, true, $show_results, $hotspot_delineation_result);
             if (empty($result)) {
                 continue;
             }
             $total_score += $result['score'];
             $total_weight += $result['weight'];
             $question_list_answers[] = array('question' => $result['open_question'], 'answer' => $result['open_answer'], 'answer_type' => $result['answer_type']);
             $my_total_score = $result['score'];
             $my_total_weight = $result['weight'];
             // Category report
             $category_was_added_for_this_test = false;
             $categoryExerciseList = $this->getListOfCategoriesWithQuestionForTest();
             $category_list = array();
             if (isset($categoryExerciseList) && !empty($categoryExerciseList)) {
                 foreach ($categoryExerciseList as $category_id => $categoryInfo) {
                     if (!isset($category_list[$category_id])) {
                         $category_list[$category_id] = array();
                         $category_list[$category_id]['score'] = 0;
                         $category_list[$category_id]['total'] = 0;
                     }
                     $category_list[$category_id]['score'] += $my_total_score;
                     $category_list[$category_id]['total'] += $my_total_weight;
                     $category_was_added_for_this_test = true;
                 }
             }
             // No category for this question!
             if ($category_was_added_for_this_test == false) {
                 if (!isset($category_list['none'])) {
                     $category_list['none'] = array();
                     $category_list['none']['score'] = 0;
                     $category_list['none']['total'] = 0;
                 }
                 $category_list['none']['score'] += $my_total_score;
                 $category_list['none']['total'] += $my_total_weight;
             }
             if ($this->selectPropagateNeg() == 0 && $my_total_score < 0) {
                 $my_total_score = 0;
             }
             $comnt = null;
             if ($show_results) {
                 $comnt = get_comments($exe_id, $questionId);
                 if (!empty($comnt)) {
                     echo '<b>' . get_lang('Feedback') . '</b>';
                     echo '<div id="question_feedback">' . $comnt . '</div>';
                 }
             }
             $score = array();
             $score['result'] = get_lang('Score') . " : " . ExerciseLib::show_score($my_total_score, $my_total_weight, false, true);
             $score['pass'] = $my_total_score >= $my_total_weight ? true : false;
             $score['score'] = $my_total_score;
             $score['weight'] = $my_total_weight;
             $score['comments'] = $comnt;
             $exerciseResultInfo[$questionId]['score'] = $score;
             $exerciseResultInfo[$questionId]['details'] = $result;
             // If no results we hide the results
             if ($show_results == false) {
                 $score = array();
             }
             $contents = ob_get_clean();
             $question_content = '<div class="question_row">';
             if ($show_results) {
                 $show_media = false;
                 $counterToShow = $counter;
                 if ($objQuestionTmp->parent_id != 0) {
                     if (!in_array($objQuestionTmp->parent_id, $media_list)) {
                         $media_list[] = $objQuestionTmp->parent_id;
                         $show_media = true;
                     }
                     if ($tempParentId == $objQuestionTmp->parent_id) {
                         $mediaCounter++;
                     } else {
                         $mediaCounter = 0;
                     }
                     $counterToShow = chr(97 + $mediaCounter);
                     $tempParentId = $objQuestionTmp->parent_id;
                 }
                 // Shows question title an description.
                 $question_content .= $objQuestionTmp->return_header(null, $counterToShow, $score, $show_media, $this->getHideQuestionTitle());
                 // display question category, if any
                 $question_content .= TestCategory::getCategoryNamesForQuestion($questionId, null, true, $this->categoryMinusOne);
             }
             $counter++;
             $question_content .= $contents;
             $question_content .= '</div>';
             $exercise_content .= $question_content;
         }
         // end foreach() block that loops over all questions
     }
     $total_score_text = null;
     if ($returnExerciseResult) {
         return $exerciseResultInfo;
     }
     if ($origin != 'learnpath') {
         if ($show_results || $show_only_score) {
             $total_score_text .= $this->get_question_ribbon($total_score, $total_weight, true);
         }
     }
     if (!empty($category_list) && ($show_results || $show_only_score)) {
         //Adding total
         $category_list['total'] = array('score' => $total_score, 'total' => $total_weight);
         echo TestCategory::get_stats_table_by_attempt($this->id, $category_list, $this->categoryMinusOne);
     }
     echo $total_score_text;
     echo $exercise_content;
     if (!$show_only_score) {
         echo $total_score_text;
     }
     if ($saveUserResult) {
         // Tracking of results
         $learnpath_id = $exercise_stat_info['orig_lp_id'];
         $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
         $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
         if (api_is_allowed_to_session_edit()) {
             update_event_exercise($exercise_stat_info['exe_id'], $this->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array());
         }
         // Send notification.
         if (!api_is_allowed_to_edit(null, true)) {
             $isSuccess = ExerciseLib::is_success_exercise_result($total_score, $total_weight, $this->selectPassPercentage());
             $this->sendCustomNotification($exe_id, $exerciseResultInfo, $isSuccess);
             $this->sendNotificationForOpenQuestions($question_list_answers, $origin, $exe_id);
             $this->sendNotificationForOralQuestions($question_list_answers, $origin, $exe_id);
         }
     }
 }
Exemplo n.º 26
0
                    } else {
                        echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;forum=' . Security::remove_XSS($my_forum) . '&amp;action=delete&amp;content=thread&id=' . $row['thread_id'] . $origin_string . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('DeleteCompleteThread'), ENT_QUOTES)) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
                    }
                    display_visible_invisible_icon('thread', $row['thread_id'], $row['visibility'], array('forum' => $my_forum, 'origin' => $origin, 'gidReq' => $groupId));
                    display_lock_unlock_icon('thread', $row['thread_id'], $row['locked'], array('forum' => $my_forum, 'origin' => $origin, 'gidReq' => api_get_group_id()));
                    echo '<a href="viewforum.php?' . api_get_cidreq() . '&amp;forum=' . Security::remove_XSS($my_forum) . '&amp;action=move&thread=' . $row['thread_id'] . $origin_string . '">' . Display::return_icon('move.png', get_lang('MoveThread'), array(), ICON_SIZE_SMALL) . '</a>';
                }
            }
            $iconnotify = 'send_mail.gif';
            if (is_array(isset($_SESSION['forum_notification']['thread']) ? $_SESSION['forum_notification']['thread'] : null)) {
                if (in_array($row['thread_id'], $_SESSION['forum_notification']['thread'])) {
                    $iconnotify = 'send_mail_checked.gif';
                }
            }
            $icon_liststd = 'user.png';
            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
                echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;forum=' . Security::remove_XSS($my_forum) . '&amp;origin=' . $origin . '&amp;action=notify&amp;content=thread&id=' . $row['thread_id'] . '">' . Display::return_icon($iconnotify, get_lang('NotifyMe')) . '</a>';
            }
            if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
                echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;forum=' . Security::remove_XSS($my_forum) . '&amp;origin=' . $origin . '&amp;action=liststd&amp;content=thread&id=' . $row['thread_id'] . '">' . Display::return_icon($icon_liststd, get_lang('StudentList'), array(), ICON_SIZE_SMALL) . '</a>';
            }
            echo '</td></tr>';
        }
        $counter++;
    }
}
echo '</table>';
echo isset($table_list) ? $table_list : '';
/* FOOTER */
if ($origin != 'learnpath') {
    Display::display_footer();
Exemplo n.º 27
0
 /**
  * Display notes
  */
 public static function display_notes()
 {
     $_user = api_get_user_info();
     if (!isset($_GET['direction'])) {
         $sort_direction = 'ASC';
         $link_sort_direction = 'DESC';
     } elseif ($_GET['direction'] == 'ASC') {
         $sort_direction = 'ASC';
         $link_sort_direction = 'DESC';
     } else {
         $sort_direction = 'DESC';
         $link_sort_direction = 'ASC';
     }
     // action links
     echo '<div class="actions">';
     if (!api_is_anonymous()) {
         if (api_get_session_id() == 0) {
             echo '<a href="index.php?' . api_get_cidreq() . '&action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
         } elseif (api_is_allowed_to_session_edit(false, true)) {
             echo '<a href="index.php?' . api_get_cidreq() . '&action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
         }
     } else {
         echo '<a href="javascript:void(0)">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>';
     }
     echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=creation_date&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32') . '</a>';
     echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=update_date&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32') . '</a>';
     echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=title&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32') . '</a>';
     echo '</div>';
     if (!isset($_SESSION['notebook_view']) || !in_array($_SESSION['notebook_view'], array('creation_date', 'update_date', 'title'))) {
         $_SESSION['notebook_view'] = 'creation_date';
     }
     // Database table definition
     $t_notebook = Database::get_course_table(TABLE_NOTEBOOK);
     $order_by = "";
     if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') {
         $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " {$sort_direction} ";
     } else {
         $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " {$sort_direction} ";
     }
     //condition for the session
     $session_id = api_get_session_id();
     $condition_session = api_get_session_condition($session_id);
     $cond_extra = $_SESSION['notebook_view'] == 'update_date' ? " AND update_date <> '0000-00-00 00:00:00'" : " ";
     $course_id = api_get_course_int_id();
     $sql = "SELECT * FROM {$t_notebook}\n                WHERE\n                    c_id = {$course_id} AND\n                    user_id = '" . api_get_user_id() . "'\n                    {$condition_session}\n                    {$cond_extra} {$order_by}\n                ";
     $result = Database::query($sql);
     while ($row = Database::fetch_array($result)) {
         // Validation when belongs to a session
         $session_img = api_get_session_image($row['session_id'], $_user['status']);
         $creation_date = api_get_local_time($row['creation_date'], null, date_default_timezone_get());
         $update_date = api_get_local_time($row['update_date'], null, date_default_timezone_get());
         $updateValue = '';
         if ($row['update_date'] != $row['creation_date']) {
             $updateValue = ', ' . get_lang('UpdateDate') . ': ' . date_to_str_ago($update_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $update_date . '</span>';
         }
         $actions = '<a href="' . api_get_self() . '?action=editnote&notebook_id=' . $row['notebook_id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>';
         $actions .= '<a href="' . api_get_self() . '?action=deletenote&notebook_id=' . $row['notebook_id'] . '" onclick="return confirmation(\'' . $row['title'] . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
         echo Display::panel($row['description'], $row['title'] . $session_img . ' <div class="pull-right">' . $actions . '</div>', get_lang('CreationDate') . ': ' . date_to_str_ago($creation_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $creation_date . $updateValue . "</span>");
     }
 }
Exemplo n.º 28
0
if (!empty($exercise_stat_info)) {
    $total_score = $exercise_stat_info['exe_result'];
}
$max_score = $objExercise->get_max_score();
Display::display_normal_message(get_lang('Saved') . '<br />', false);
// Display and save questions
ExerciseLib::display_question_list_by_attempt($objExercise, $exe_id, true);
//Unset session for clock time
ExerciseLib::exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id);
ExerciseLib::delete_chat_exercise_session($exe_id);
if ($origin != 'learnpath') {
    echo '<hr>';
    echo Display::url(get_lang('ReturnToCourseHomepage'), api_get_course_url(), array('class' => 'btn btn-primary'));
    if (api_is_allowed_to_session_edit()) {
        Session::erase('objExercise');
        Session::erase('exe_id');
    }
    Display::display_footer();
} else {
    $lp_mode = Session::read('lp_mode');
    $url = '../newscorm/lp_controller.php?cidReq=' . api_get_course_id() . '&action=view&lp_id=' . $learnpath_id . '&lp_item_id=' . $learnpath_item_id . '&exeId=' . $exercise_stat_info['exe_id'] . '&fb_type=' . $objExercise->feedback_type;
    $href = $lp_mode == 'fullscreen' ? ' window.opener.location.href="' . $url . '" ' : ' top.location.href="' . $url . '"';
    if (api_is_allowed_to_session_edit()) {
        Session::erase('objExercise');
        Session::erase('exe_id');
    }
    // Record the results in the learning path, using the SCORM interface (API)
    echo "<script>window.parent.API.void_save_asset('{$total_score}', '{$max_score}', 0, 'completed');</script>";
    echo '<script type="text/javascript">' . $href . '</script>';
    echo '</body></html>';
}
Exemplo n.º 29
0
/**
 * This function displays a wiki entry
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Juan Carlos Raña Trabado
 * @return html code
 **/
function display_wiki_entry($newtitle)
{
    global $charset, $tbl_wiki, $tbl_wiki_conf, $groupfilter, $condition_session, $page;
    $course_id = api_get_course_int_id();
    if ($newtitle) {
        $pageMIX = $newtitle;
        //display the page after it is created
    } else {
        $pageMIX = $page;
        //display current page
    }
    $_clean['group_id'] = (int) $_SESSION['_gid'];
    $session_id = api_get_session_id();
    if ($_GET['view']) {
        $_clean['view'] = (int) Database::escape_string($_GET['view']);
        $filter = ' AND w.id="' . $_clean['view'] . '"';
    }
    //first, check page visibility in the first page version
    $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = ' . $course_id . ' AND reflink="' . Database::escape_string($pageMIX) . '" AND ' . $groupfilter . $condition_session . ' ORDER BY id ASC';
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    $KeyVisibility = $row['visibility'];
    // second, show the last version
    $sql = 'SELECT * FROM ' . $tbl_wiki . ' w , ' . $tbl_wiki_conf . ' wc
    	  WHERE wc.c_id 	  = ' . $course_id . ' AND
    	  		w.c_id 		  = ' . $course_id . ' AND
    			wc.page_id	  = w.page_id AND
    			w.reflink	  = "' . Database::escape_string($pageMIX) . '" AND
    			w.session_id  = ' . $session_id . ' AND
    			w.' . $groupfilter . '  ' . $filter . '
    			ORDER BY id DESC';
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    // we do not need a while loop since we are always displaying the last version
    //update visits
    if ($row['id']) {
        $sql = 'UPDATE ' . $tbl_wiki . ' SET hits=(hits+1) WHERE c_id = ' . $course_id . ' AND id=' . $row['id'] . '';
        Database::query($sql);
    }
    // if both are empty and we are displaying the index page then we display the default text.
    if ($row['content'] == '' and $row['title'] == '' and $page == 'index') {
        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin() || GroupManager::is_user_in_group(api_get_user_id(), $_SESSION['_gid'])) {
            //Table structure for better export to pdf
            $default_table_for_content_Start = '<table align="center" border="0"><tr><td align="center">';
            $default_table_for_content_End = '</td></tr></table>';
            $content = $default_table_for_content_Start . sprintf(get_lang('DefaultContent'), api_get_path(WEB_IMG_PATH)) . $default_table_for_content_End;
            $title = get_lang('DefaultTitle');
        } else {
            return Display::display_normal_message(get_lang('WikiStandBy'));
        }
    } else {
        $content = Security::remove_XSS($row['content'], COURSEMANAGERLOWSECURITY);
        $title = $row['title'];
    }
    //assignment mode: identify page type
    if ($row['assignment'] == 1) {
        $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
    } elseif ($row['assignment'] == 2) {
        $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
    }
    //task mode
    if (!empty($row['task'])) {
        $icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL);
    }
    //Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
    if ($KeyVisibility == "1" || api_is_allowed_to_edit(false, true) || api_is_platform_admin() || $row['assignment'] == 2 && $KeyVisibility == "0" && api_get_user_id() == $row['user_id']) {
        echo '<div id="wikititle">';
        // page action: protecting (locking) the page
        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
            if (check_protect_page() == 1) {
                $protect_page = Display::return_icon('lock.png', get_lang('PageLockedExtra'), '', ICON_SIZE_SMALL);
                $lock_unlock_protect = 'unlock';
            } else {
                $protect_page = Display::return_icon('unlock.png', get_lang('PageUnlockedExtra'), '', ICON_SIZE_SMALL);
                $lock_unlock_protect = 'lock';
            }
        }
        if ($row['id']) {
            echo '<span style="float:right;">';
            echo '<a href="index.php?action=showpage&amp;actionpage=' . $lock_unlock_protect . '&amp;title=' . api_htmlentities(urlencode($page)) . '">' . $protect_page . '</a>';
            echo '</span>';
        }
        //page action: visibility
        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
            if (check_visibility_page() == 1) {
                // TODO: FIX  This hides the icon eye closed to users of work they can see yours
                //if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false)
                //{
                //
                // }
                $visibility_page = Display::return_icon('visible.png', get_lang('ShowPageExtra'), '', ICON_SIZE_SMALL);
                $lock_unlock_visibility = 'invisible';
            } else {
                $visibility_page = Display::return_icon('invisible.png', get_lang('HidePageExtra'), '', ICON_SIZE_SMALL);
                $lock_unlock_visibility = 'visible';
            }
        }
        if ($row['id']) {
            echo '<span style="float:right;">';
            echo '<a href="index.php?action=showpage&amp;actionpage=' . $lock_unlock_visibility . '&amp;title=' . api_htmlentities(urlencode($page)) . '">' . $visibility_page . '</a>';
            echo '</span>';
        }
        //page action: notification
        if (api_is_allowed_to_session_edit()) {
            if (check_notify_page($page) == 1) {
                $notify_page = Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'), '', ICON_SIZE_SMALL);
                $lock_unlock_notify_page = 'unlocknotify';
            } else {
                $notify_page = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'), '', ICON_SIZE_SMALL);
                $lock_unlock_notify_page = 'locknotify';
            }
        }
        echo '<span style="float:right;">';
        echo '<a href="index.php?action=showpage&amp;actionpage=' . $lock_unlock_notify_page . '&amp;title=' . api_htmlentities(urlencode($page)) . '">' . $notify_page . '</a>';
        echo '</span>';
        //ONly available if row['id'] is set
        if ($row['id']) {
            //page action: export to pdf
            echo '<span style="float:right;padding-top:5px;">';
            echo '<form name="form_export2PDF" method="post" action="index.php">';
            echo '<input type="hidden" name="action" value="export_to_pdf">';
            echo '<input type="hidden" name="wiki_id" value="' . $row['id'] . '">';
            echo '<input type="image" src="../img/icons/22/pdf.png" border ="0" title="' . get_lang('ExportToPDF') . '" alt="' . get_lang('ExportToPDF') . '" style=" width:22px; border:none; margin-top: -9px">';
            echo '</form>';
            echo '</span>';
            //page action: copy last version to doc area
            if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
                echo '<span style="float:right;">';
                echo '<form name="form_export2DOC" method="post" action="index.php" >';
                echo '<input type=hidden name="export2DOC" value="export2doc">';
                echo '<input type=hidden name="doc_id" value="' . $row['id'] . '">';
                echo '<input type="image" src="../img/icons/22/export_to_documents.png" border ="0" title="' . get_lang('ExportToDocArea') . '" alt="' . get_lang('ExportToDocArea') . '" style=" width:22px; border:none; margin-top: -6px">';
                echo '</form>';
                echo '</span>';
            }
        }
        //export to print
        ?>

    <script>
        function goprint() {
            var a = window.open('', '', 'width=800,height=600');
            a.document.open("text/html");
            a.document.write(document.getElementById('wikicontent').innerHTML);
            a.document.close();
            a.print();
        }
    </script>
    <?php 
        echo '<span style="float:right; cursor: pointer;">';
        echo Display::return_icon('printer.png', get_lang('Print'), array('onclick' => "javascript: goprint();"), ICON_SIZE_SMALL);
        echo '</span>';
        if (empty($title)) {
            $title = get_lang('DefaultTitle');
        }
        if (wiki_exist($title)) {
            echo $icon_assignment . '&nbsp;' . $icon_task . '&nbsp;' . api_htmlentities($title);
        } else {
            echo api_htmlentities($title);
        }
        echo '</div>';
        echo '<div id="wikicontent">' . make_wiki_link_clickable(detect_external_link(detect_anchor_link(detect_mail_link(detect_ftp_link(detect_irc_link(detect_news_link($content))))))) . '</div>';
        echo '<div id="wikifooter">' . get_lang('Progress') . ': ' . $row['progress'] . '%&nbsp;&nbsp;&nbsp;' . get_lang('Rating') . ': ' . $row['score'] . '&nbsp;&nbsp;&nbsp;' . get_lang('Words') . ': ' . word_count($content) . '</div>';
    }
    //end filter visibility
}