/** * @Route("/edit/{tool}") * @Method({"GET|POST"}) * * @param string $tool * @return Response */ public function editAction($tool) { $message = null; // @todo use proper functions not api functions. $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); $tool = \Database::escape_string($tool); $TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO); $url = $this->generateUrl('chamilo_course_introduction_introduction_edit', array('tool' => $tool, 'course' => api_get_course_id())); $form = $this->getFormValidator($url, $tool); if ($form->validate()) { $values = $form->exportValues(); $content = $values['content']; $sql = "REPLACE {$TBL_INTRODUCTION}\n SET c_id = {$courseId},\n id = '{$tool}',\n intro_text='" . \Database::escape_string($content) . "',\n session_id='" . intval($sessionId) . "'"; \Database::query($sql); $message = \Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false); } else { $sql = "SELECT intro_text FROM {$TBL_INTRODUCTION}\n WHERE c_id = {$courseId} AND id='" . $tool . "' AND session_id = '" . intval($sessionId) . "'"; $result = \Database::query($sql); $content = null; if (\Database::num_rows($result) > 0) { $row = \Database::fetch_array($result); $content = $row['intro_text']; } $form->setDefaults(array('content' => $content)); } /*$this->getTemplate()->assign('content', $form->return_form()); $this->getTemplate()->assign('message', $message); $response = $this->getTemplate()->renderLayout('layout_1_col.tpl');*/ $response = null; return $this->render('ChamiloCoreBundle:Legacy:index.html.twig', array('content' => $form->return_form(), 'message' => $message)); }
/** * Get the classes to display on the current page. */ function get_class_data($from, $number_of_items, $column, $direction) { $class_table = Database::get_main_table(TABLE_MAIN_CLASS); $course_class_table = Database::get_main_table(TABLE_MAIN_COURSE_CLASS); $class_user_table = Database::get_main_table(TABLE_MAIN_CLASS_USER); $courseCode = api_get_course_id(); $sql = "SELECT * FROM {$course_class_table} WHERE course_code = '" . $courseCode . "'"; $res = Database::query($sql); $subscribed_classes = array(); while ($obj = Database::fetch_object($res)) { $subscribed_classes[] = $obj->class_id; } $sql = "SELECT\n c.id AS col0,\n c.name AS col1,\n COUNT(cu.user_id) AS col2,\n c.id AS col3\n FROM {$class_table} c "; $sql .= " LEFT JOIN {$class_user_table} cu ON cu.class_id = c.id"; $sql .= " WHERE 1 = 1"; if (isset($_GET['keyword'])) { $keyword = Database::escape_string(trim($_GET['keyword'])); $sql .= " AND (c.name LIKE '%" . $keyword . "%')"; } if (count($subscribed_classes) > 0) { $sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')"; } $sql .= " GROUP BY c.id, c.name "; $sql .= " ORDER BY col{$column} {$direction} "; $sql .= " LIMIT {$from},{$number_of_items}"; $res = Database::query($sql); $classes = array(); while ($class = Database::fetch_row($res)) { $classes[] = $class; } return $classes; }
/** * Creates the mPDF object * @param string $pageFormat format A4 A4-L see http://mpdf1.com/manual/index.php?tid=184&searchstring=format * @param string $orientation orientation "P" = Portrait "L" = Landscape * @param array $params * @param Template $template */ public function __construct($pageFormat = 'A4', $orientation = 'P', $params = array(), $template = null) { $this->template = $template; /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF * mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]]) */ if (!in_array($orientation, array('P', 'L'))) { $orientation = 'P'; } //$this->pdf = $pdf = new mPDF('UTF-8', $pageFormat, '', '', 30, 20, 27, 25, 16, 13, $orientation); //left, right, top, bottom, margin_header, margin footer $params['left'] = isset($params['left']) ? $params['left'] : 15; $params['right'] = isset($params['right']) ? $params['right'] : 15; $params['top'] = isset($params['top']) ? $params['top'] : 20; $params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15; $this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_local_time(); $this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled'); $this->params['course_info'] = isset($params['course_info']) ? $params['course_info'] : api_get_course_info(); $this->params['session_info'] = isset($params['session_info']) ? $params['session_info'] : api_get_session_info(api_get_session_id()); $this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id(); $this->params['add_signatures'] = isset($params['add_signatures']) ? $params['add_signatures'] : false; $this->params['show_real_course_teachers'] = isset($params['show_real_course_teachers']) ? $params['show_real_course_teachers'] : false; $this->params['student_info'] = isset($params['student_info']) ? $params['student_info'] : false; $this->params['show_grade_generated_date'] = isset($params['show_grade_generated_date']) ? $params['show_grade_generated_date'] : false; $this->params['show_teacher_as_myself'] = isset($params['show_teacher_as_myself']) ? $params['show_teacher_as_myself'] : true; $this->params['pdf_date'] = isset($params['pdf_date']) ? $params['pdf_date'] : api_format_date(api_get_local_time(), DATE_TIME_FORMAT_LONG); $this->pdf = new mPDF('UTF-8', $pageFormat, '', '', $params['left'], $params['right'], $params['top'], $params['bottom'], 8, 8, $orientation); }
/** * Returns the course parameters. If null default to the current user parameters. * * @param string $course_code * @param string|int $session_id * @param string|int $group_id * @return type */ public static function course_params($course_code = null, $session_id = null, $group_id = null) { $course_code = is_null($course_code) ? api_get_course_id() : $course_code; $session_id = is_null($session_id) ? api_get_session_id() : $session_id; $session_id = $session_id ? $session_id : '0'; $group_id = is_null($group_id) ? '' : $group_id; $group_id = $group_id ? $group_id : '0'; return array('cidReq' => $course_code, 'id_session' => $session_id, 'gidReq' => $group_id); }
/** * @Route("/courses/{cidReq}/{sessionId}") * @Method({"GET"}) * * @param string $cidReq * @param int $id_session * @return Response */ public function indexAction($cidReq, $id_session = null) { $courseCode = api_get_course_id(); $sessionId = api_get_session_id(); $userId = $this->getUser()->getUserId(); $coursesAlreadyVisited = $this->getRequest()->getSession()->get('coursesAlreadyVisited'); $result = $this->autolaunch(); $showAutoLaunchLpWarning = $result['show_autolaunch_lp_warning']; $showAutoLaunchExerciseWarning = $result['show_autolaunch_exercise_warning']; if ($showAutoLaunchLpWarning) { $this->getTemplate()->assign('lp_warning', Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'), 'warning')); } if ($showAutoLaunchExerciseWarning) { $this->getTemplate()->assign('exercise_warning', Display::return_message(get_lang('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'), 'warning')); } if ($this->isCourseTeacher()) { $editIcons = Display::url(Display::return_icon('edit.png'), $this->generateUrl('course_home.controller:iconListAction', array('course' => api_get_course_id()))); $this->getTemplate()->assign('edit_icons', $editIcons); } if (!isset($coursesAlreadyVisited[$courseCode])) { event_access_course(); $coursesAlreadyVisited[$courseCode] = 1; $this->getRequest()->getSession()->set('coursesAlreadyVisited', $coursesAlreadyVisited); } $this->getRequest()->getSession()->remove('toolgroup'); $this->getRequest()->getSession()->remove('_gid'); $isSpecialCourse = \CourseManager::is_special_course($courseCode); if ($isSpecialCourse) { $autoreg = $this->getRequest()->get('autoreg'); if ($autoreg == 1) { \CourseManager::subscribe_user($userId, $courseCode, STUDENT); } } $script = 'activity.php'; if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') { $script = 'activity.php'; } elseif (api_get_setting('homepage_view') == '2column') { $script = '2column.php'; } elseif (api_get_setting('homepage_view') == '3column') { $script = '3column.php'; } elseif (api_get_setting('homepage_view') == 'vertical_activity') { $script = 'vertical_activity.php'; } $result = (require_once api_get_path(SYS_CODE_PATH) . 'course_home/' . $script); $toolList = $result['tool_list']; $this->getTemplate()->assign('icons', $result['content']); $introduction = Display::return_introduction_section($this->get('url_generator'), TOOL_COURSE_HOMEPAGE, $toolList); $this->getTemplate()->assign('introduction_text', $introduction); if (api_get_setting('show_session_data') == 'true' && $sessionId) { $sessionInfo = \CourseHome::show_session_data($sessionId); $this->getTemplate()->assign('session_info', $sessionInfo); } $response = $this->get('template')->render_template($this->getTemplatePath() . 'index.tpl'); return new Response($response, 200, array()); }
/** * Handles default Chamilo scripts handled by Display::display_header() and display_footer() * * @param \Silex\Application $app * @param string $file * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|void */ public function classicAction(Application $app, $file) { $responseHeaders = array(); /** @var Request $request */ $request = $app['request']; // get. $_GET = $request->query->all(); // post. $_POST = $request->request->all(); // echo $request->getMethod(); //$_REQUEST = $request->request->all(); $mainPath = $app['paths']['sys_root'] . 'main/'; $fileToLoad = $mainPath . $file; if (is_file($fileToLoad) && \Security::check_abs_path($fileToLoad, $mainPath)) { // Default values $_course = api_get_course_info(); $_user = api_get_user_info(); $charset = 'UTF-8'; $debug = $app['debug']; $text_dir = api_get_text_direction(); $is_platformAdmin = api_is_platform_admin(); $_cid = api_get_course_id(); // Loading file ob_start(); require_once $mainPath . $file; $out = ob_get_contents(); ob_end_clean(); // No browser cache when executing an exercise. if ($file == 'exercice/exercise_submit.php') { $responseHeaders = array('cache-control' => 'no-store, no-cache, must-revalidate'); } // Setting page header/footer conditions (important for LPs) $app['template']->setFooter($app['template.show_footer']); $app['template']->setHeader($app['template.show_header']); if (isset($htmlHeadXtra)) { $app['template']->addJsFiles($htmlHeadXtra); } if (isset($interbreadcrumb)) { $app['template']->setBreadcrumb($interbreadcrumb); $app['template']->loadBreadcrumbToTemplate(); } if (isset($tpl)) { $response = $app['twig']->render($app['default_layout']); } else { $app['template']->assign('content', $out); $response = $app['twig']->render($app['default_layout']); } } else { return $app->abort(404, 'File not found'); } return new Response($response, 200, $responseHeaders); }
/** * Writes an item's new values into the database and returns the operation result * @param integer Learnpath ID * @param integer User ID * @param integer View ID * @param integer Item ID * @param array Objectives array */ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array()) { global $_configuration; $debug = 0; $return = ''; if ($debug > 0) { error_log('In xajax_save_objectives(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $item_id . ',"' . (count($objectives) > 0 ? count($objectives) : '') . '")', 0); } //$objResponse = new xajaxResponse(); require_once 'learnpath.class.php'; require_once 'scorm.class.php'; require_once 'aicc.class.php'; require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; $mylp = ''; if (isset($_SESSION['lpobject'])) { if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } $oLP = unserialize($_SESSION['lpobject']); if (!is_object($oLP)) { if ($debug > 2) { error_log(print_r($oLP, true), 0); } if ($debug > 2) { error_log('Building new lp', 0); } unset($oLP); $code = api_get_course_id(); $mylp = new learnpath($code, $lp_id, $user_id); } else { if ($debug > 2) { error_log('Reusing session lp', 0); } $mylp = $oLP; } } $mylpi =& $mylp->items[$item_id]; //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true), 0); if (is_array($objectives) && count($objectives) > 0) { foreach ($objectives as $index => $objective) { //error_log(__FILE__.' '.__LINE__.' '.$objectives[$index][0], 0); $mylpi->add_objective($index, $objectives[$index]); } $mylpi->write_objectives_to_db(); } //return $objResponse; return $return; }
/** * @Route("/", name="course_home") * @Route("/index.php") * @Method({"GET"}) * * @param Request $request * @return Response */ public function indexAction(Request $request) { $sessionId = api_get_session_id(); $course = $this->getCourse(); $courseCode = $course->getId(); $result = $this->autoLaunch(); $showAutoLaunchLpWarning = $result['show_autolaunch_lp_warning']; $showAutoLaunchExerciseWarning = $result['show_autolaunch_exercise_warning']; if ($showAutoLaunchLpWarning) { $this->addFlash('warning', $this->trans('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP')); } if ($showAutoLaunchExerciseWarning) { $this->addFlash('warning', $this->trans('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise')); } if (true) { $editIcons = Display::url(Display::return_icon('edit.png'), $this->generateUrl('chamilo_course_home_home_iconlist', array('course' => api_get_course_id()))); } $isSpecialCourse = \CourseManager::isSpecialCourse($courseCode); if ($isSpecialCourse) { $user = $this->getUser(); if (!empty($user)) { $userId = $this->getUser()->getId(); $autoreg = $request->get('autoreg'); if ($autoreg == 1) { \CourseManager::subscribe_user($userId, $courseCode, STUDENT); } } } $homeView = api_get_setting('course.homepage_view'); if ($homeView == 'activity' || $homeView == 'activity_big') { $result = $this->renderActivityView(); } elseif ($homeView == '2column') { $result = $this->render2ColumnView(); } elseif ($homeView == '3column') { $result = $this->render3ColumnView(); } elseif ($homeView == 'vertical_activity') { $result = $this->renderVerticalActivityView(); } $toolList = $result['tool_list']; $introduction = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, $toolList); $sessionInfo = null; if (api_get_setting('session.show_session_data') == 'true' && $sessionId) { $sessionInfo = CourseHome::show_session_data($sessionId); } return $this->render('ChamiloCourseBundle:Home:index.html.twig', array('course' => $course, 'session_info' => $sessionInfo, 'icons' => $result['content'], 'edit_icons' => $editIcons, 'introduction_text' => $introduction, 'exercise_warning' => null, 'lp_warning' => null)); }
/** * Writes an item's new values into the database and returns the operation result * @param integer Learnpath ID * @param integer User ID * @param integer View ID * @param integer Item ID * @param array Objectives array */ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array()) { $debug = 0; $return = ''; if ($debug > 0) { error_log('In xajax_save_objectives(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $item_id . ',"' . (count($objectives) > 0 ? count($objectives) : '') . '")', 0); } $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $mylpi =& $mylp->items[$item_id]; if (is_array($objectives) && count($objectives) > 0) { foreach ($objectives as $index => $objective) { $mylpi->add_objective($index, $objectives[$index]); } $mylpi->write_objectives_to_db(); } return $return; }
/** * @Route("/delete/{tool}") * @Method({"GET"}) * * @param string $tool * @return Response */ public function deleteAction($tool) { $request = $this->getRequest(); $courseId = $request->get('courseId'); $sessionId = $request->get('sessionId'); $criteria = array('sessionId' => $sessionId, 'id' => $tool, 'cId' => $courseId); $toolIntro = $this->getRepository()->findOneBy($criteria); if ($toolIntro) { $this->getManager()->remove($toolIntro); $this->getManager()->flush(); $this->get('session')->getFlashBag()->add('success', "IntroductionTextDeleted"); } $url = $this->generateUrl('introduction.controller:editAction', array('tool' => $tool, 'course' => api_get_course_id())); $form = $this->getForm($url, $tool); $this->getTemplate()->assign('content', $form->return_form()); $response = $this->getTemplate()->renderLayout('layout_1_col.tpl'); return new Response($response, 200, array()); }
/** * Creates the mPDF object * @param string format A4 A4-L see http://mpdf1.com/manual/index.php?tid=184&searchstring=format * @param string orientation "P" = Portrait "L" = Landscape */ public function __construct($page_format = 'A4', $orientation = 'P', $params = array()) { /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF * mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]]) */ if (!in_array($orientation, array('P', 'L'))) { $orientation = 'P'; } //$this->pdf = $pdf = new mPDF('UTF-8', $page_format, '', '', 30, 20, 27, 25, 16, 13, $orientation); //left, right, top, bottom, margin_header, margin footer $params['left'] = isset($params['left']) ? $params['left'] : 15; $params['right'] = isset($params['right']) ? $params['right'] : 15; $params['top'] = isset($params['top']) ? $params['top'] : 20; $params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15; $this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_local_time(); $this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled'); $this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id(); $this->params['add_signatures'] = isset($params['add_signatures']) ? $params['add_signatures'] : false; $this->pdf = new mPDF('UTF-8', $page_format, '', '', $params['left'], $params['right'], $params['top'], $params['bottom'], 8, 8, $orientation); }
/** * This is a function to show the generated data * @param bool $displayWarning * @return array */ public function get_data_to_graph2($displayWarning = true) { // do some checks on users/items counts, redefine if invalid values $usertable = array(); foreach ($this->users as $user) { $usertable[] = $user; } // sort users array usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name')); // generate actual data array $scoredisplay = ScoreDisplay::instance(); $data = array(); $displaytype = SCORE_DIV; $selected_users = $usertable; foreach ($selected_users as $user) { $row = array(); $row[] = $user[0]; // user id $item_value = 0; $item_total = 0; $final_score = 0; $item_value_total = 0; $convert_using_the_global_weight = true; $course_code = api_get_course_id(); $session_id = api_get_session_id(); $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); if ($parent_id == 0 && !empty($allcat)) { foreach ($allcat as $sub_cat) { $score = $sub_cat->calc_score($user[0]); $real_score = $score; $main_weight = $this->category->get_weight(); $divide = $score[1] == 0 ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; $item_value = $score[0] / $divide * $main_weight; $item_total += $sub_cat->get_weight(); $row[] = array($item_value, trim($scoredisplay->display_score($real_score, SCORE_CUSTOM, null, true))); $item_value_total += $item_value; $final_score += $score[0]; //$final_score = ($final_score / $item_total) * 100; } $total_score = array($final_score, $item_total); $row[] = array($final_score, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); } else { for ($count = 0; $count < count($this->evals_links); $count++) { $item = $this->evals_links[$count]; $score = $item->calc_score($user[0]); $divide = $score[1] == 0 ? 1 : $score[1]; $item_value += $score[0] / $divide * $item->get_weight(); $item_total += $item->get_weight(); $score_denom = $score[1] == 0 ? 1 : $score[1]; $score_final = $score[0] / $score_denom * 100; $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true))); } $total_score = array($item_value, $item_total); $score_final = $item_value / $item_total * 100; if ($displayWarning) { Display::display_warning_message(Display::display_warning_message($total_score[1])); } $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); } $data[] = $row; } return $data; }
/** * */ public static function export_to_pdf() { $data = GlossaryManager::get_glossary_data(0, GlossaryManager::get_number_glossary_terms(api_get_session_id()), 0, 'ASC'); $html = '<html><body>'; $html .= '<h2>' . get_lang('Glossary') . '</h2><hr><br><br>'; foreach ($data as $item) { $term = $item[0]; $description = $item[1]; $html .= '<h4>' . $term . '</h4><p>' . $description . '<p><hr>'; } $html .= '</body></html>'; $course_code = api_get_course_id(); $pdf = new PDF(); //$pdf->set_custom_header($title); /*$css_file = api_get_path(SYS_CODE_PATH).'css/print.css'; if (file_exists($css_file)) { $css = @file_get_contents($css_file); } else { $css = ''; }*/ $pdf->content_to_pdf($html, '', get_lang('Glossary') . '_' . $course_code, $course_code); }
lesson_status = 'completed'; } <?php } ?> param = 'id='+lms_item_id+'&origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data; url="http://<?php $self = api_get_self(); $url = $_SERVER['HTTP_HOST'] . $self; $url = substr($url, 0, -14); // 14 is the length of this file's name (/scorm_api.php). echo $url; ?> /lp_controller.php?cidReq=<?php echo api_get_course_id(); ?> &action=save&lp_id=<?php echo $oLP->get_id(); ?> &" + param + ""; logit_lms('saving data (status='+lesson_status+')',1); xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location); //xajax_update_pgs(); //xajax_update_toc(); } function LMSCommit(val) { logit_scorm('LMSCommit()',0); commit = true ; savedata('commit');
/** * Returns the form to update or create a document * * @param string Action (add/edit) * @param integer ID of the lp_item (if already exists) * @param mixed Integer if document ID, string if info ('new') * @return string HTML form */ function display_document_form($action = 'add', $id = 0, $extra_info = 'new') { global $charset, $_course; require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); $path_parts = pathinfo($extra_info['dir']); $no_display_edit_textarea = false; //If action==edit document //We don't display the document form if it's not an editable document (html or txt file) if ($action == "edit") { if (is_array($extra_info)) { if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") { $no_display_edit_textarea = true; } } } $no_display_add = false; //If action==add an existing document //We don't display the document form if it's not an editable document (html or txt file) if ($action == "add") { if (is_numeric($extra_info)) { $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info); $result = Database::query($sql_doc, __FILE__, __LINE__); $path_file = Database::result($result, 0, 0); $path_parts = pathinfo($path_file); if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") { $no_display_add = true; } } } // create css folder $css_name = api_get_setting('stylesheets'); $perm = api_get_setting('permissions_for_new_directories'); $perm = octdec(!empty($perm) ? $perm : '0770'); $css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css'; if (!is_dir($css_folder)) { mkdir($css_folder); chmod($css_folder, $perm); $doc_id = add_document($_course, '/css', 'folder', 0, 'css'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']); } if (!file_exists($css_folder . '/templates.css')) { if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) { $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')); $template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content); file_put_contents($css_folder . '/templates.css', $template_content); } } if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) { $table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE); $user_id = api_get_user_id(); // Session used by the ajax request when we are using php 5.3 $_SESSION['dbName'] = $_course['dbName']; // setting some paths $img_dir = api_get_path(REL_CODE_PATH) . 'img/'; $default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/'; if (!isset($_GET['resource'])) { // Load a template into a document $query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid'])); $result = Database::query($query, __FILE__, __LINE__); $obj = Database::fetch_object($result); $valcontent = $obj->content; $valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty'); if (isset($_GET['tplid']) && $_GET['tplid'] == 0) { $valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>'; } $template_css = ''; if (strpos($valcontent, '/css/templates.css') === false) { $template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />'; } $js = ''; if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) { $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>'; $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL; if (api_get_setting('show_glossary_in_documents') != 'none') { $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>'; if (api_get_setting('show_glossary_in_documents') == 'ismanual') { $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>'; } else { $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>'; } } } $valcontent = str_replace('{CSS}', $template_css . $js, $valcontent); if (strpos($valcontent, '/css/templates.css') === false) { $valcontent = str_replace('</head>', $template_css . '</head>', $valcontent); } if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) { $valcontent = str_replace('</head>', $js . '</head>', $valcontent); } $valcontent = str_replace('{IMG_DIR}', $img_dir, $valcontent); $valcontent = str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent); $valcontent = str_replace('{COURSE_DIR}', $default_course_dir, $valcontent); } elseif (isset($_GET['resource']) && $_GET['resource'] == 'mindmap' || $_GET['resource'] == 'video') { // Load a mindmap or video into a document $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY); $curdirpath = '/mindmaps/'; if ($_GET['resource'] == 'video') { $curdirpath = '/video/'; $curdirpath_flv = '/video/flv/'; } $my_course = api_get_course_id(); $src_path = api_get_path(WEB_COURSE_PATH) . $my_course . '/document'; $sql = "SELECT path,title FROM {$tbl_doc} doc,{$propTable} prop WHERE doc.id = prop.ref AND prop.tool = '" . TOOL_DOCUMENT . "'\n AND doc.filetype = 'file' AND (doc.path LIKE '" . $curdirpath . "%' OR doc.path LIKE '" . $curdirpath_flv . "%') AND (doc.path NOT LIKE '" . $curdirpath . "%/%' OR doc.path NOT LIKE '" . $curdirpath_flv . "%/%')\n AND prop.visibility = 1 AND doc.id = '" . Database::escape_string(Security::remove_XSS($_GET['tplid'])) . "'"; $rs = Database::query($sql); $row = Database::fetch_array($rs); $resource = $src_path . $row['path']; $valtitle = $row['title']; if ($valtitle != '') { $search = array('.png', '.gif', '.jpg', '.mpg', '.flv', '.swf'); // Add other extensions $replace = array('', '', '', '', '', ''); $valtitle = str_replace($search, $replace, $valtitle); } if ($_GET['resource'] == 'mindmap') { $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;"> <tbody> <tr> <td valign="top"><img border="0" vspace="0" hspace="0" src="' . $resource . '" alt="' . $title . '" title="' . $title . '"/></td> </tr> </tbody> </table>'; } elseif ($_GET['resource'] == 'video') { $sys_resource = api_get_path(SYS_COURSE_PATH) . $my_course . '/document' . $row['path']; $resource_info = pathinfo($sys_resource); //$video_web_path = api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/flvPlayer/'; $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;"> <tbody> <tr> <td valign="top"> <!-- Video player plugin --> <div id="player986311-parent" align="left"> <div style="border-style: none; height: 240px; width: 375px; overflow: hidden; background-color: rgb(220, 220, 220);" id="test"> <div style="display: none; visibility: hidden; width: 0px; height: 0px; overflow: hidden;" id="player986311-config">url=' . $resource . ' width=375 height=240 loop=1 play=true downloadable=false fullscreen=true</div> <div class="thePlayer" id="player986311">'; if (in_array($resource_info['extension'], array('flv', 'mp4', 'mov'))) { /*if (!api_is_windows_os()) { $valcontent .= ' <script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script> <object id="player986311-parent2" name="player986311-parent2" width="375" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="movie" value="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /> <param name="seamlesstabbing" value="true" /> <param name="wmode" value="transparent" /> <param name="flashvars" value="id=player986311-parent2&autostart=true&repeat=false&file='.$resource.'&skin='.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip&controlbar.position=over" /> </object> '; } else {*/ $valcontent .= ' <script src="' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script> <div id="player986311-parent2">Loading the player ...</div> <script type="text/javascript">jwplayer("player986311-parent2").setup({flashplayer: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf",autostart: "true",repeat: "always",file: "' . $resource . '",height: 240,width: 375,skin: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip"});</script>'; //} } else { $sType = ''; if ($resource_info['extension'] == 'mpg' || $resource_info['extension'] == 'mpeg') { $sType = 'video/mpeg'; } else { if ($resource_info['extension'] == 'avi' || $resource_info['extension'] == 'wmv' || $resource_info['extension'] == 'asf') { $sType = 'video/x-msvideo'; } } $valcontent .= '<embed type="' . $sType . '" src="' . $resource . '" autosize = "false" autostart = "true" loop = "false" fullscreen = "true" showcontrols = "true" showpositioncontrols = "false" showtracker = "true" showaudiocontrols = "true" showgotobar = "true" showstatusbar = "true" pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/" codebase = "http://www.microsoft.com/Windows/MediaPlayer/"'; $valcontent .= 'width="375px" height="240px"'; $valcontent .= '></embed>'; } $valcontent .= ' </div> </div> </div> </td> </tr> </tbody> </table>'; } } } if ($id != 0 && is_array($extra_info)) { $item_title = stripslashes($extra_info['title']); $item_description = stripslashes($extra_info['description']); $item_terms = stripslashes($extra_info['terms']); if (empty($item_title)) { $path_parts = pathinfo($extra_info['path']); $item_title = stripslashes($path_parts['filename']); } } elseif (is_numeric($extra_info)) { $sql_doc = "SELECT path, title\n\t\t\t\t\t\t\t\t\tFROM " . $tbl_doc . "\n\t\t\t\t\t\t\t\t\tWHERE id = " . Database::escape_string($extra_info); $result = Database::query($sql_doc, __FILE__, __LINE__); $row = Database::fetch_array($result); $explode = explode('.', $row['title']); if (count($explode) > 1) { for ($i = 0; $i < count($explode) - 1; $i++) { $item_title .= $explode[$i]; } } else { $item_title = $row['title']; } $item_title = str_replace('_', ' ', $item_title); if (empty($item_title)) { $path_parts = pathinfo($row['path']); $item_title = stripslashes($path_parts['filename']); } } else { $item_title = ''; $item_description = ''; } /* $return = ' <div class="row"> <div class="form_header">'; */ if ($id != 0 && is_array($extra_info)) { $parent = $extra_info['parent_item_id']; } else { $parent = 0; } $sql = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM " . $tbl_lp_item . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlp_id = " . $this->lp_id; $result = Database::query($sql, __FILE__, __LINE__); $arrLP = array(); while ($row = Database::fetch_array($result)) { $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']); } $this->tree_array($arrLP); $arrLP = $this->arrMenu; unset($this->arrMenu); if (isset($_GET['edit']) && $_GET['edit'] == 'true') { $return .= Display::return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false); } require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'; $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"'); $defaults["title"] = Security::remove_XSS(api_convert_encoding($item_title, api_get_system_encoding(), $this->encoding)); if (empty($item_title)) { $defaults["title"] = Security::remove_XSS($item_title); } $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding); $form->addElement('html', $return); if ($action != 'move') { $form->addElement('html', '<div style="float:left;padding-right:135px;">'); $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%'); $form->applyFilter('title', 'html_filter'); $form->addElement('html', '</div>'); } //$arrHide = array($id); $arrHide[0]['value'] = $this->name; $arrHide[0]['padding'] = 3; for ($i = 0; $i < count($arrLP); $i++) { if ($action != 'add') { if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) { $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title']; $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10; if ($parent == $arrLP[$i]['id']) { $s_selected_parent = $arrHide[$arrLP[$i]['id']]; } } } else { if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') { $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title']; $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10; if ($parent == $arrLP[$i]['id']) { $s_selected_parent = $arrHide[$arrLP[$i]['id']]; } } } } //$parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"'); $parent_select =& $form->addElement('select', 'parent', '', '', 'class="learnpath_item_form" style="width:40%;display:none;float:left" onchange="load_cbo(this.value);"'); $my_count = 0; foreach ($arrHide as $key => $value) { if ($my_count != 0) { // the LP name is also the first section and is not in the same charset like the other sections $value['value'] = Security::remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding)); $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"'); } else { $value['value'] = Security::remove_XSS($value['value']); $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"'); } $my_count++; } if (!empty($id)) { $parent_select->setSelected($parent); } else { $parent_item_id = $_SESSION['parent_item_id']; $parent_select->setSelected($parent_item_id); } if (is_array($arrLP)) { reset($arrLP); } $arrHide = array(); //POSITION for ($i = 0; $i < count($arrLP); $i++) { if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) { if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) { $s_selected_position = $arrLP[$i]['id']; } elseif ($action == 'add') { $s_selected_position = $arrLP[$i]['id']; } $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"'; } } //$position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"'); $position =& $form->addElement('select', 'previous', '', '', 'id="idPosition" class="learnpath_item_form" style="width:40%;float:left;display:none;"'); $position->addOption(get_lang("FirstPosition"), 0); foreach ($arrHide as $key => $value) { $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"'); } $position->setSelected($s_selected_position); if (is_array($arrLP)) { reset($arrLP); } if ($action != 'move') { $id_prerequisite = 0; if (is_array($arrLP)) { foreach ($arrLP as $key => $value) { if ($value['id'] == $id) { $id_prerequisite = $value['prerequisite']; break; } } } //comented the prerequisites, only visible in edit (new document) //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"'); //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0); // form element for uploading an mp3 file //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"'); //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/'); /* Code deprecated - moved to lp level (not lp-item) if ( api_get_setting('search_enabled') === 'true' ) { //add terms field $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').' :','id="idTerms" class="learnpath_item_form"'); $terms->setValue($item_terms); } */ $arrHide = array(); for ($i = 0; $i < count($arrLP); $i++) { if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') { if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) { $s_selected_position = $arrLP[$i]['id']; } elseif ($action == 'add') { $s_selected_position = $arrLP[$i]['id']; } $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding); } } /* foreach($arrHide as $key => $value){ $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"'); if($key==$s_selected_position && $action == 'add'){ $select_prerequisites -> setSelected(0); } elseif($key==$id_prerequisite && $action == 'edit'){ $select_prerequisites -> setSelected($id_prerequisite); } } */ if (!$no_display_add) { if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') { if (isset($_POST['content'])) { $content = stripslashes($_POST['content']); } elseif (is_array($extra_info)) { //If it's an html document or a text file if (!$no_display_edit_textarea) { $content = $this->display_document($extra_info['path'], false, false); } } elseif (is_numeric($extra_info)) { $content = $this->display_document($extra_info, false, false); } else { $content = ''; } if (!$no_display_edit_textarea) { // We need to claculate here some specific settings for the online editor. // The calculated settings work for documents in the Documents tool // (on the root or in subfolders). // For documents in native scorm packages it is unclear whether the // online editor should be activated or not. $relative_path = $extra_info['dir']; if ($relative_path == 'n/') { // A new document, it is in the root of the repository. $relative_path = ''; $relative_prefix = ''; } else { // The document already exists. Whe have to determine its relative path towards the repository root. $relative_path = explode('/', $relative_path); $cnt = count($relative_path) - 2; if ($cnt < 0) { $cnt = 0; } $relative_prefix = str_repeat('../', $cnt); $relative_path = array_slice($relative_path, 1, $cnt); $relative_path = implode('/', $relative_path); if (strlen($relative_path) > 0) { $relative_path = $relative_path . '/'; } } $editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path); if ($_GET['action'] == 'add_item') { $class = 'save'; $text = get_lang('Validate'); } else { if ($_GET['action'] == 'edit_item') { $class = 'save'; $text = get_lang('SaveDocument'); } } $form->addElement('html', '<div style="float:right;margin-top:-55px">'); $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"'); $form->addElement('html', '</div>'); $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('{label}{element}', 'content_lp'); //$form->addElement('html', '<div'); $form->addElement('html_editor', 'content_lp', '', null, $editor_config); //$form->addElement('html', '</div>'); $defaults["content_lp"] = $content; } } elseif (is_numeric($extra_info)) { $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"'); $return = $this->display_document($extra_info, true, true, true); $form->addElement('html', $return); } } } // Add template to content if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) { $defaults["content_lp"] = $valcontent; $defaults["title"] = $valtitle; } if ($action == 'move') { $form->addElement('hidden', 'title', $item_title); $form->addElement('hidden', 'description', $item_description); } if (is_numeric($extra_info)) { $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"'); $form->addElement('hidden', 'path', $extra_info); } elseif (is_array($extra_info)) { $form->addElement('html', '<div style="float:right;margin-top:-55px">'); $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"'); $form->addElement('hidden', 'path', $extra_info['path']); $form->addElement('html', '</div>'); } $form->addElement('hidden', 'type', TOOL_DOCUMENT); $form->addElement('hidden', 'post_time', time()); $form->setDefaults($defaults); return $form->return_form(); }
/** * Get all questions * @param Application $app * @param int $categoryId * @param int $exerciseId * @param int $courseId * @param array $options * @param bool $get_count * @return array */ public static function getQuestions($app, $categoryId, $exerciseId, $courseId, $options, $get_count = false) { $questionTable = Database::get_course_table(TABLE_QUIZ_QUESTION); $questionPoolFields = array('question_session_id' => array('innerjoin' => " INNER JOIN " . Database::get_course_table(TABLE_QUIZ_TEST_QUESTION) . " as quiz_rel_question_session ON (quiz_rel_question_session.question_id = s.iid)\n INNER JOIN " . Database::get_course_table(TABLE_QUIZ_TEST) . " as quizsession ON (quizsession.iid = quiz_rel_question_session.exercice_id)\n INNER JOIN " . Database::get_main_table(TABLE_MAIN_SESSION) . " session ON (session.id = quizsession.session_id)", 'where' => 'session_id', 'inject_fields' => 'session.name as question_session_id, '), 'question_category_id' => array('innerjoin' => " INNER JOIN " . Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY) . " as quiz_rel_cat ON (quiz_rel_cat.question_id = s.iid)\n INNER JOIN " . Database::get_course_table(TABLE_QUIZ_CATEGORY) . " as cat ON (cat.iid = quiz_rel_cat.category_id)", 'where' => 'quiz_rel_cat.category_id', 'inject_fields' => 'cat.title as question_category_id, '), 'question_exercise_id' => array('innerjoin' => " INNER JOIN " . Database::get_course_table(TABLE_QUIZ_TEST_QUESTION) . " as quiz_rel_question ON (quiz_rel_question.question_id = s.iid)\n INNER JOIN " . Database::get_course_table(TABLE_QUIZ_TEST) . " as quizexercise ON (quizexercise.iid = quiz_rel_question.exercice_id) ", 'where' => 'quiz_rel_question.exercice_id', 'inject_fields' => 'quizexercise.title as question_exercise_id, '), 'question_c_id' => array('where' => 's.c_id', 'innerjoin' => " INNER JOIN " . Database::get_main_table(TABLE_MAIN_COURSE) . " as course ON (course.id = s.c_id) ", 'inject_fields' => 'course.title as question_c_id, '), 'question_question_type' => array('where' => 's.type ', 'inject_fields' => 's.type as question_question_type,'), 'question_difficulty' => array('where' => 's.level', 'inject_fields' => 's.level as question_difficulty, ')); // Checking if you're looking for orphan questions. $isOrphanQuestion = false; if (isset($options['question'])) { foreach ($options['question'] as $option) { if (isset($option['field']) && $option['field'] == 'question_exercise_id') { if ($option['data'] == 0) { $isOrphanQuestion = true; break; } } } } // Special case for orphan questions. if ($isOrphanQuestion) { $questionPoolFields['question_exercise_id'] = array('innerjoin' => " LEFT JOIN " . Database::get_course_table(TABLE_QUIZ_TEST_QUESTION) . " as quiz_rel_question ON (quiz_rel_question.question_id = s.iid)\n LEFT JOIN " . Database::get_course_table(TABLE_QUIZ_TEST) . " as quizexercise ON (quizexercise.iid = quiz_rel_question.exercice_id) ", 'where' => 'quiz_rel_question.exercice_id', 'inject_fields' => 'quizexercise.title as question_exercise_id, '); } $inject_extra_fields = null; $inject_joins = null; $where = $options['where']; $newQuestionPoolField = array(); if (isset($options['question'])) { foreach ($options['question'] as $question) { if (isset($questionPoolFields[$question['field']])) { $newQuestionPoolField[$question['field']] = $questionPoolFields[$question['field']]; } } } $inject_question_fields = null; $questionPoolFields = $newQuestionPoolField; // Injecting inner joins. foreach ($questionPoolFields as $field => $option) { $where = str_replace($field, $option['where'], $where); if (isset($option['innerjoin']) && !empty($option['innerjoin'])) { $inject_joins .= $option['innerjoin']; } if (isset($option['inject_fields']) && !empty($option['inject_fields'])) { $inject_question_fields .= $option['inject_fields']; } } $options['where'] = $where; $extra_field = new ExtraField('question'); $conditions = $extra_field->parseConditions($options); $inject_joins .= $conditions['inject_joins']; $where = $conditions['where']; $inject_where = $conditions['inject_where']; $inject_extra_fields = $conditions['inject_extra_fields']; $order = $conditions['order']; $limit = $conditions['limit']; if ($get_count == true) { $select = " SELECT count(*) as total_rows"; } else { $select = " SELECT s.*, {$inject_extra_fields} {$inject_question_fields} 1 "; } $extraCondition = null; // Used by the question manager if (!empty($categoryId)) { $categoryRelQuestionTable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $extraCondition = " INNER JOIN {$categoryRelQuestionTable} c ON (s.iid = c.question_id)"; $categoryId = intval($categoryId); $where .= " AND category_id = {$categoryId} "; } /*if (!empty($exerciseId)) { $exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $extraCondition .= " INNER JOIN $exerciseRelQuestionTable e ON (s.iid = e.question_id)"; $exerciseId = intval($exerciseId); $where .= " AND exercice_id = $exerciseId "; }*/ // Orphan questions if ($isOrphanQuestion) { //$exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); //$extraCondition .= " INNER JOIN $exerciseRelQuestionTable e ON (s.iid = e.question_id)"; $where .= " OR quizexercise.active = -1 OR quiz_rel_question.exercice_id IS NULL"; } if (!empty($courseId)) { $courseId = intval($courseId); $where .= " AND s.c_id = {$courseId} "; } if (isset($options['question'])) { $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id()); foreach ($options['question'] as $questionOption) { if ($questionOption['field'] == 'question_c_id') { if (isset($questionOption['data'])) { if (!isset($courseList[$questionOption['data']])) { return array(); } } } } } //var_dump(CourseManager::get_teacher_list_from_course_code()) //var_dump($inject_joins); $query = " {$select} FROM {$questionTable} s {$inject_joins} {$extraCondition} WHERE 1=1 {$where} {$inject_where} {$order} {$limit}"; //echo $query.'<br />'; //var_dump($extraCondition); //var_dump($where); $result = Database::query($query); $questions = array(); $exerciseList = null; if (!empty($exerciseId)) { $exercise = new Exercise(); $exercise->read($exerciseId); $exerciseList = $exercise->questionList; } if (Database::num_rows($result)) { $questions = Database::store_result($result, 'ASSOC'); if ($get_count) { return $questions[0]['total_rows']; } $previewIcon = Display::return_icon('preview.gif', get_lang('View'), array(), ICON_SIZE_SMALL); $copyIcon = Display::return_icon('copy.png', get_lang('Copy'), array(), ICON_SIZE_SMALL); $reuseIcon = Display::return_icon('view_more_stats.gif', get_lang('InsertALinkToThisQuestionInTheExercise'), array(), ICON_SIZE_SMALL); $editIcon = Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); //$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); //var_dump($exerciseId); // Including actions foreach ($questions as &$question) { $type = self::get_question_type($question['type']); $question['type'] = get_lang($type[1]); $question['question_question_type'] = get_lang($type[1]); if (empty($exerciseId)) { // View. $actions = Display::url($previewIcon, $app['url_generator']->generate('admin_questions_show', array('id' => $question['iid']))); // Edit. $actions .= Display::url($editIcon, $app['url_generator']->generate('admin_questions_edit', array('id' => $question['iid']))); } else { // View. $actions = Display::url($previewIcon, $app['url_generator']->generate('question_show', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'exerciseId' => $exerciseId, 'id' => $question['iid']))); if (isset($exerciseList) && !empty($exerciseList) && in_array($question['iid'], $exerciseList)) { // Copy. //$actions .= $copyIconDisabled; } else { // Copy. $actions .= Display::url($copyIcon, 'javascript:void(0);', array('onclick' => 'ajaxAction(this);', 'data-url' => $app['url_generator']->generate('exercise_copy_question', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'questionId' => $question['iid'], 'exerciseId' => $exerciseId)))); // Reuse. $actions .= Display::url($reuseIcon, 'javascript:void(0);', array('onclick' => 'ajaxAction(this);', 'data-url' => $app['url_generator']->generate('exercise_reuse_question', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'questionId' => $question['iid'], 'exerciseId' => $exerciseId)))); } // Edit. $actions .= Display::url($editIcon, $app['url_generator']->generate('exercise_question_edit', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $question['iid']))); } $question['actions'] = $actions; } } return $questions; }
/** * Handles a given Excel spreadsheets as in the template provided */ function lp_upload_quiz_action_handling() { global $debug; $_course = api_get_course_info(); $courseId = $_course['real_id']; if (!isset($_POST['submit_upload_quiz'])) { return; } // Get the extension of the document. $path_info = pathinfo($_FILES['user_upload_quiz']['name']); // Check if the document is an Excel document if ($path_info['extension'] != 'xls') { return; } // Read the Excel document $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding(api_get_system_encoding()); // Reading the xls document. $data->read($_FILES['user_upload_quiz']['tmp_name']); $correctScore = isset($_POST['correct_score']) ? $_POST['correct_score'] : null; $incorrectScore = isset($_POST['incorrect_score']) ? $_POST['incorrect_score'] : null; $useCustomScore = isset($_POST['user_custom_score']) ? true : false; $propagateNegative = 0; if ($useCustomScore && !empty($incorrectScore)) { if ($incorrectScore < 0) { $propagateNegative = 1; } } // Variables $quiz_index = 0; $question_title_index = array(); $question_name_index_init = array(); $question_name_index_end = array(); $score_index = array(); $feedback_true_index = array(); $feedback_false_index = array(); $number_questions = 0; $question_description_index = array(); // Reading all the first column items sequentially to create breakpoints for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) { $quiz_index = $i; // Quiz title position, only occurs once } elseif ($data->sheets[0]['cells'][$i][1] == 'Question') { $question_title_index[] = $i; // Question title position line $question_name_index_init[] = $i + 1; // Questions name 1st position line $number_questions++; } elseif ($data->sheets[0]['cells'][$i][1] == 'Score') { $question_name_index_end[] = $i - 1; // Question name position $score_index[] = $i; // Question score position } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackTrue') { $feedback_true_index[] = $i; // FeedbackTrue position (line) } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackFalse') { $feedback_false_index[] = $i; // FeedbackFalse position (line) } elseif ($data->sheets[0]['cells'][$i][1] == 'EnrichQuestion') { $question_description_index[] = $i; } } // Variables $quiz = array(); $question = array(); $new_answer = array(); $score_list = array(); $feedback_true_list = array(); $feedback_false_list = array(); $question_description = array(); // Getting questions. $k = $z = $q = $l = $m = 0; for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { if (is_array($data->sheets[0]['cells'][$i])) { $column_data = $data->sheets[0]['cells'][$i]; // Fill all column with data to have a full array for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { if (empty($column_data[$x])) { $data->sheets[0]['cells'][$i][$x] = ''; } } // Array filled with data $column_data = $data->sheets[0]['cells'][$i]; } else { $column_data = ''; } // Fill quiz data if ($quiz_index == $i) { // The title always in the first position $quiz = $column_data; } elseif (in_array($i, $question_title_index)) { //a complete line where 1st column is 'Question' $question[$k] = $column_data; $k++; } elseif (in_array($i, $score_index)) { //a complete line where 1st column is 'Score' $score_list[$z] = $column_data; $z++; } elseif (in_array($i, $feedback_true_index)) { //a complete line where 1st column is 'FeedbackTrue' $feedback_true_list[$q] = $column_data; $q++; } elseif (in_array($i, $feedback_false_index)) { //a complete line where 1st column is 'FeedbackFalse' for wrong answers $feedback_false_list[$l] = $column_data; $l++; } elseif (in_array($i, $question_description_index)) { //a complete line where 1st column is 'EnrichQuestion' $question_description[$m] = $column_data; $m++; } } // Get answers for ($i = 0; $i < count($question_name_index_init); $i++) { for ($j = $question_name_index_init[$i]; $j <= $question_name_index_end[$i]; $j++) { if (is_array($data->sheets[0]['cells'][$j])) { $column_data = $data->sheets[0]['cells'][$j]; // Fill all column with data for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { if (empty($column_data[$x])) { $data->sheets[0]['cells'][$j][$x] = ''; } } $column_data = $data->sheets[0]['cells'][$j]; // Array filled of data if (is_array($data->sheets[0]['cells'][$j]) && count($data->sheets[0]['cells'][$j]) > 0) { $new_answer[$i][$j] = $data->sheets[0]['cells'][$j]; } } } } // Quiz title. $quiz_title = $quiz[2]; if ($quiz_title != '') { // Variables $type = 2; $random = $active = $results = $max_attempt = $expired_time = 0; // Make sure feedback is enabled (3 to disable), otherwise the fields // added to the XLS are not shown, which is confusing $feedback = 0; // Quiz object $exercise = new Exercise(); // $quiz_id = $exercise->createExercise($quiz_title, $expired_time, $type, $random, $active, $results, $max_attempt, $feedback, $propagateNegative); if ($quiz_id) { // insert into the item_property table api_item_property_update($_course, TOOL_QUIZ, $quiz_id, 'QuizAdded', api_get_user_id()); // Import questions. for ($i = 0; $i < $number_questions; $i++) { // Question name $question_title = $question[$i][2]; $question_description_text = "<p></p>"; if (isset($question_description[$i][2])) { // Question description. $question_description_text = "<p>" . $question_description[$i][2] . "</p>"; } // Unique answers are the only question types available for now // through xls-format import $question_id = null; $detectQuestionType = detectQuestionType($new_answer[$i], $score_list); /** @var Question $answer */ switch ($detectQuestionType) { case FREE_ANSWER: $answer = new FreeAnswer(); break; case GLOBAL_MULTIPLE_ANSWER: $answer = new GlobalMultipleAnswer(); break; case MULTIPLE_ANSWER: $answer = new MultipleAnswer(); break; case UNIQUE_ANSWER: default: $answer = new UniqueAnswer(); break; } if ($question_title != '') { $question_id = $answer->create_question($quiz_id, $question_title, $question_description_text, 0, $answer->type); } $total = 0; if (is_array($new_answer[$i]) && !empty($question_id)) { $id = 1; $answers_data = $new_answer[$i]; $globalScore = null; $objAnswer = new Answer($question_id, $courseId); $globalScore = $score_list[$i][3]; // Calculate the number of correct answers to divide the // score between them when importing from CSV $numberRightAnswers = 0; foreach ($answers_data as $answer_data) { if (strtolower($answer_data[3]) == 'x') { $numberRightAnswers++; } } foreach ($answers_data as $answer_data) { $answerValue = $answer_data[2]; $correct = 0; $score = 0; if (strtolower($answer_data[3]) == 'x') { $correct = 1; $score = $score_list[$i][3]; $comment = $feedback_true_list[$i][2]; } else { $comment = $feedback_false_list[$i][2]; $floatVal = (double) $answer_data[3]; if (is_numeric($floatVal)) { $score = $answer_data[3]; } } if ($useCustomScore) { if ($correct) { $score = $correctScore; } else { $score = $incorrectScore; } } // Fixing scores: switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: $score /= $numberRightAnswers; break; case UNIQUE_ANSWER: break; case MULTIPLE_ANSWER: if (!$correct) { //$total = $total - $score; } break; } $objAnswer->createAnswer($answerValue, $correct, $comment, $score, $id); $total += $score; $id++; } $objAnswer->save(); $questionObj = Question::read($question_id, $courseId); switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: $questionObj->updateWeighting($globalScore); break; case UNIQUE_ANSWER: case MULTIPLE_ANSWER: default: $questionObj->updateWeighting($total); break; } $questionObj->save(); } else { if ($detectQuestionType === FREE_ANSWER) { $questionObj = Question::read($question_id, $courseId); $globalScore = $score_list[$i][3]; $questionObj->updateWeighting($globalScore); $questionObj->save(); } } } } if (isset($_SESSION['lpobject'])) { if ($debug > 0) { error_log('New LP - SESSION[lpobject] is defined', 0); } $oLP = unserialize($_SESSION['lpobject']); if (is_object($oLP)) { if ($debug > 0) { error_log('New LP - oLP is object', 0); } if (empty($oLP->cc) or $oLP->cc != api_get_course_id()) { if ($debug > 0) { error_log('New LP - Course has changed, discard lp object', 0); } $oLP = null; Session::erase('oLP'); Session::erase('lpobject'); } else { $_SESSION['oLP'] = $oLP; } } } if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) { $previous = $_SESSION['oLP']->select_previous_item_id(); $parent = 0; // Add a Quiz as Lp Item $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, ''); // Redirect to home page for add more content header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id'])); exit; } else { // header('location: exercise.php?' . api_get_cidreq()); echo '<script>window.location.href = "' . api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidReq() . '&exerciseId=' . $quiz_id . '&session_id=' . api_get_session_id() . '"</script>'; } } }
/** * Set footer parameters */ private function set_footer_parameters() { global $_configuration; //Show admin data //$this->assign('show_administrator_data', api_get_setting('show_administrator_data')); if (api_get_setting('show_administrator_data') == 'true') { //Administrator name $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link( api_get_setting('emailAdministrator'), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) ); $this->assign('administrator_name', $administrator_data); } //Loading footer extra content if (!api_is_platform_admin()) { $extra_footer = trim(api_get_setting('footer_extra_content')); if (!empty($extra_footer)) { $this->assign('footer_extra_content', $extra_footer); } } //Tutor name if (api_get_setting('show_tutor_data') == 'true') { // Course manager $id_course = api_get_course_id(); $id_session = api_get_session_id(); if (isset($id_course) && $id_course != -1) { $tutor_data = ''; if ($id_session != 0) { $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course); $email_link = array(); foreach ($coachs_email as $coach) { $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']); } if (count($coachs_email) > 1) { $tutor_data .= get_lang('Coachs').' : '; $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR); } elseif (count($coachs_email) == 1) { $tutor_data .= get_lang('Coach').' : '; $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR); } elseif (count($coachs_email) == 0) { $tutor_data .= ''; } } $this->assign('session_teachers', $tutor_data); } } if (api_get_setting('show_teacher_data') == 'true') { // course manager $id_course = api_get_course_id(); if (isset($id_course) && $id_course != -1) { $teacher_data = ''; $mail = CourseManager::get_emails_of_tutors_to_course($id_course); if (!empty($mail)) { $teachers_parsed = array(); foreach ($mail as $value) { foreach ($value as $email => $name) { $teachers_parsed[] = Display::encrypted_mailto_link($email, $name); } } $label = get_lang('Teacher'); if (count($mail) > 1) { $label = get_lang('Teachers'); } $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR); } $this->assign('teachers', $teacher_data); } } /* $stats = ''; $this->assign('execution_stats', $stats); */ }
/** * Constructor * To add link, define category_object and link_type * To edit link, define link_object */ function LinkAddEditForm($form_type, $category_object, $link_type, $link_object, $form_name, $action = null) { parent::__construct($form_name, 'post', $action); // set or create link object if (isset($link_object)) { $link = $link_object; } elseif (isset($link_type) && isset($category_object)) { $link = LinkFactory::create($link_type); $link->set_course_code(api_get_course_id()); } else { die('LinkAddEditForm error: define link_type/category_object or link_object'); } $defaults = array(); $this->addElement('hidden', 'zero', 0); if (!empty($_GET['editlink'])) { $this->addElement('header', '', get_lang('EditLink')); } // ELEMENT: name if ($form_type == self::TYPE_ADD || $link->is_allowed_to_change_name()) { if ($link->needs_name_and_description()) { $this->add_textfield('name', get_lang('Name'), true, array('size' => '40', 'maxlength' => '40')); } else { $select = $this->addElement('select', 'select_link', get_lang('ChooseItem')); foreach ($link->get_all_links() as $newlink) { $select->addoption($newlink[1], $newlink[0]); } } } else { $this->addElement('label', get_lang('Name'), '<span class="freeze">' . $link->get_name() . ' [' . $link->get_type_name() . ']</span>'); $this->addElement('hidden', 'name_link', $link->get_name(), array('id' => 'name_link')); } if (count($category_object) == 1) { $this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id()); } else { $select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id')); $this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero'); $default_weight = 0; if (!empty($category_object)) { foreach ($category_object as $my_cat) { if ($my_cat->get_course_code() == api_get_course_id()) { $grade_model_id = $my_cat->get_grade_model_id(); if (empty($grade_model_id)) { if ($my_cat->get_parent_id() == 0) { $default_weight = $my_cat->get_weight(); $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); } else { $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); } } else { $select_gradebook->addoption(get_lang('Select'), 0); } if ($link->get_category_id() == $my_cat->get_id()) { $default_weight = $my_cat->get_weight(); } } } } } $this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. ' . $category_object[0]->get_weight() . '] '), true, array('size' => '4', 'maxlength' => '5', 'class' => 'span1')); $this->addElement('hidden', 'weight'); /* // ELEMENT: weight $this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array ( 'size' => '4', 'maxlength' => '5', 'class' => 'span1' ));*/ $this->addRule('weight_mask', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>='); if ($form_type == self::TYPE_EDIT) { $parent_cat = Category::load($link->get_category_id()); if ($parent_cat[0]->get_parent_id() == 0) { $values['weight'] = $link->get_weight(); } else { $cat = Category::load($parent_cat[0]->get_parent_id()); //$global_weight = $cat[0]->get_weight(); //$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight; //$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight; //$values['weight'] = $weight; $values['weight'] = $link->get_weight(); } $defaults['weight_mask'] = $values['weight']; $defaults['select_gradebook'] = $link->get_category_id(); } // ELEMENT: max if ($link->needs_max()) { if ($form_type == self::TYPE_EDIT && $link->has_results()) { $this->add_textfield('max', get_lang('QualificationNumeric'), false, array('size' => '4', 'maxlength' => '5', 'disabled' => 'disabled')); } else { $this->add_textfield('max', get_lang('QualificationNumeric'), true, array('size' => '4', 'maxlength' => '5')); $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('max', 'zero'), get_lang('NegativeValue'), 'compare', '>='); } if ($form_type == self::TYPE_EDIT) { $defaults['max'] = $link->get_max(); } } // ELEMENT: date //$this->add_datepicker('date',get_lang('Date')); //$defaults['date'] = ($form_type == self :: TYPE_EDIT ? $link->get_date() : time()); // ELEMENT: description if ($link->needs_name_and_description()) { $this->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3', 'cols' => '34')); if ($form_type == self::TYPE_EDIT) { $defaults['description'] = $link->get_description(); } } // ELEMENT: visible $visible = $form_type == self::TYPE_EDIT && $link->is_visible() ? '1' : '0'; $this->addElement('checkbox', 'visible', null, get_lang('Visible'), $visible); if ($form_type == self::TYPE_EDIT) { $defaults['visible'] = $link->is_visible(); } // ELEMENT: add results if ($form_type == self::TYPE_ADD && $link->needs_results()) { $this->addElement('checkbox', 'addresult', get_lang('AddResult')); } // submit button if ($form_type == self::TYPE_ADD) { $this->addElement('style_submit_button', 'submit', get_lang('CreateLink'), 'class="save"'); } else { $this->addElement('style_submit_button', 'submit', get_lang('LinkMod'), 'class="save"'); } if ($form_type == self::TYPE_ADD) { $setting = api_get_setting('tool_visible_by_default_at_creation'); $visibility_default = 1; if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { $visibility_default = 0; } $defaults['visible'] = $visibility_default; } // set default values $this->setDefaults($defaults); }
} } } $token = Security::get_token(); echo Display::page_header(get_lang('GradebookListOfStudentsCertificates')); //@todo replace all this code with something like get_total_weight() $cats = Category::load($cat_id, null, null, null, null, null, false); if (!empty($cats)) { //with this fix the teacher only can view 1 gradebook if (api_is_platform_admin()) { $stud_id = api_is_allowed_to_edit() ? null : api_get_user_id(); } else { $stud_id = api_get_user_id(); } $total_weight = $cats[0]->get_weight(); $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id()); $alleval = $cats[0]->get_evaluations($stud_id); $alllink = $cats[0]->get_links($stud_id); $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink); $total_resource_weight = 0; if (!empty($datagen)) { $data_array = $datagen->get_data(GradebookDataGenerator::GDG_SORT_NAME, 0, null, true); if (!empty($data_array)) { $newarray = array(); foreach ($data_array as $data) { $newarray[] = array_slice($data, 1); } foreach ($newarray as $item) { $total_resource_weight = $total_resource_weight + $item['2']; } }
[<a href='".api_get_self()."?view=1111111'>".get_lang('ShowAll')."</a>] [<a href='".api_get_self()."?view=0000000'>".get_lang('ShowNone')."</a>] </div><br> "; */ if (!isset($view)) { $view = "0000000"; } /* Reporting */ $tempView = $view; if ($view[6] == '1') { $tempView[6] = '0'; // BEGIN users in this course $sql = "SELECT {$TABLECOURSUSER}.user_i, {$table_user}.lastname, {$table_user}.firstname\n FROM {$TABLECOURSUSER}, {$table_user}\n WHERE\n {$TABLECOURSUSER}.c_id = '" . api_get_course_int_id() . "' AND\n {$TABLECOURSUSER}.user_id = {$table_user}.user_id AND\n {$TABLECOURSUSER}.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "\n ORDER BY {$table_user}.lastname"; $results = StatsUtils::getManyResults3Col($sql); //BUGFIX: get visual code instead of real course code. Scormpaths use the visual code... (should be fixed in future versions) $sql = "SELECT visual_code FROM {$TABLECOURSE} WHERE code = '" . api_get_course_id() . "'"; $_course['visual_code'] = StatsUtils::getOneResult($sql); if (is_array($results)) { $line = ''; $title_line = get_lang('Name') . ";" . get_lang('FirstAccess') . ";" . get_lang('LastAccess') . ";" . get_lang('Visited') . "\n"; for ($j = 0; $j < count($results); $j++) { // BEGIN % visited // sum of all items (= multiple learningpaths + SCORM imported paths) $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) FROM {$tbl_learnpath_item_view} iv " . "INNER JOIN {$tbl_learnpath_view} v\n ON iv.lp_view_id = v.id " . "WHERE\n \tv.c_id = {$course_id} AND\n \tiv.c_id = {$course_id} AND\n \t\tv.user_id = " . $results[$j][0]; $total_lpath_items = StatsUtils::getOneResult($sql); // sum of all completed items (= multiple learningpaths + SCORM imported paths) $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) " . "FROM {$tbl_learnpath_item_view} iv " . "INNER JOIN {$tbl_learnpath_view} v ON iv.lp_view_id = v.id " . "WHERE\n \tv.c_id = {$course_id} AND\n \tiv.c_id = {$course_id} AND\n \tv.user_id = " . $results[$j][0] . " " . "AND (status = 'completed' OR status='passed')"; $total_lpath_items_completed = StatsUtils::getOneResult($sql); // calculation & bgcolor setting $lpath_pct_completed = empty($total_lpath_items) ? "-" : round($total_lpath_items_completed / $total_lpath_items * 100); // END % visited
/** * Function used by SortableTable to generate the data to display * @param int $from * @param int $per_page * @param int $column * @param string $direction * @param int $sort * @return array|mixed */ public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) { //variables load in index.php global $my_score_in_gradebook, $certificate_min_score; $scoretotal = 0; // determine sorting type $col_adjust = api_is_allowed_to_edit() ? 1 : 0; // By id $this->column = 5; switch ($this->column) { // Type case 0 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_TYPE; break; case 1 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_NAME; break; case 2 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION; break; case 3 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_WEIGHT; break; case 4 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_DATE; case 5 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_ID; break; } if ($this->direction == 'DESC') { $sorting |= GradebookDataGenerator::GDG_SORT_DESC; } else { $sorting |= GradebookDataGenerator::GDG_SORT_ASC; } //status of user in course $user_id = api_get_user_id(); $course_code = api_get_course_id(); $courseId = api_get_course_int_id(); $session_id = api_get_session_id(); $status_user = api_get_status_of_user_in_course($user_id, $courseId); $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); // generate the data to display $sortable_data = array(); $weight_total_links = 0; $main_categories = array(); $main_cat = Category::load(null, null, $course_code, null, null, $session_id, false); $total_categories_weight = 0; $scoredisplay = ScoreDisplay::instance(); //Categories foreach ($data_array as $data) { // list of items inside the gradebook (exercises, lps, forums, etc) $row = array(); $item = $item_category = $data[0]; $id = $item->get_id(); //if the item is invisible, wrap it in a span with class invisible $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : ''; $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; if (api_is_allowed_to_edit(null, true)) { //id $row[] = $this->build_id_column($item); } //Type $row[] = $this->build_type_column($item); //Name if (get_class($item) == 'Category') { $row[] = $invisibility_span_open . '<h3>' . $item->get_name() . '</h3>' . $invisibility_span_close; $main_categories[$item->get_id()]['name'] = $item->get_name(); } else { $row[] = $invisibility_span_open . $this->build_name_link($item) . $invisibility_span_close; $main_categories[$item->get_id()]['name'] = $this->build_name_link($item); } $main_categories[$item->get_id()]['weight'] = $item->get_weight(); $total_categories_weight += $item->get_weight(); //Description $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close; //Weight //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close; //$average = $data['3']/$this->currentcat->get_weight()*100; $average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_SIMPLE, SCORE_BOTH, true); if (api_is_allowed_to_edit(null, true)) { $row[] = $invisibility_span_open . Display::tag('h4', $average) . $invisibility_span_close; } else { $row[] = $invisibility_span_open . $average . $invisibility_span_close; } $category_weight = $item->get_weight(); if (api_is_allowed_to_edit(null, true)) { $weight_total_links += $data[3]; } else { $cattotal = Category::load($_GET['selectcat']); $scoretotal = $cattotal[0]->calc_score(api_get_user_id()); $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); } //Date //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; //Edit (for admins) if (api_is_allowed_to_edit(null, true)) { $cat = new Category(); $show_message = $cat->show_message_resource_delete($item->get_course_code()); if ($show_message === false) { $row[] = $this->build_edit_column($item); } } else { //students get the results and certificates columns if (count($this->evals_links) > 0 && $status_user != 1) { $value_data = isset($data[4]) ? $data[4] : null; if (!is_null($value_data)) { $row[] = Display::tag('h4', $value_data); } else { $row[] = $this->build_edit_column($item); } } else { $score = $item->calc_score(api_get_user_id()); if (!empty($score[1])) { $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); $score = $score[0] / $score[1] * $item->get_weight(); $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); $row[] = Display::tip($score, $complete_score); } else { $row[] = '-'; } if (!empty($this->cats)) { $row[] = $this->build_edit_column($item); } } } //Category added $sortable_data[] = $row; // Loading childrens if (get_class($item) == 'Category') { $stud_id = api_get_user_id(); $course_code = api_get_course_id(); $session_id = api_get_session_id(); $parent_id = $item->get_id(); $cats = Category::load($parent_id, null, null, null, null, null); if (isset($cats[0])) { $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id); $alleval = $cats[0]->get_evaluations($stud_id); $alllink = $cats[0]->get_links($stud_id); $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); $data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page); $total_weight = 0; //Links foreach ($data_array as $data) { $row = array(); $item = $data[0]; //if the item is invisible, wrap it in a span with class invisible $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : ''; $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); if (api_is_allowed_to_edit(null, true)) { $row[] = $this->build_id_column($item); } $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); //Name $row[] = $invisibility_span_open . " " . $this->build_name_link($item) . $invisibility_span_close; //Description $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close; //Weight //$weight = $data[3]/$category_weight*$main_cat[0]->get_weight(); $weight = $data[3]; //$extra = " - $data[3] $category_weight -".$main_cat[0]->get_weight(); $total_weight += $weight; $row[] = $invisibility_span_open . $weight . $invisibility_span_close; if (api_is_allowed_to_edit(null, true)) { //$weight_total_links += intval($data[3]); } else { $cattotal = Category::load($_GET['selectcat']); $scoretotal = $cattotal[0]->calc_score(api_get_user_id()); $item_value = $scoretotal[0]; } //Date //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; //Admins get an edit column if (api_is_allowed_to_edit(null, true)) { $cat = new Category(); $show_message = $cat->show_message_resource_delete($item->get_course_code()); if ($show_message === false) { $row[] = $this->build_edit_column($item); } } else { //students get the results and certificates columns $eval_n_links = array_merge($alleval, $alllink); if (count($eval_n_links) > 0 && $status_user != 1) { $value_data = isset($data[4]) ? $data[4] : null; if (!is_null($value_data)) { $score = $item->calc_score(api_get_user_id()); $new_score = $data[3] * $score[0] / $score[1]; $new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals'))); $row[] = Display::tip($new_score, $data[4]); } } if (!empty($cats)) { $row[] = null; } } $row['child_of'] = $parent_id; $sortable_data[] = $row; } //"Warning row" if (!empty($data_array)) { if (api_is_allowed_to_edit()) { // Compare the category weight to the sum of all weights inside the category if (intval($total_weight) == $category_weight) { $label = null; $total = score_badges(array($total_weight . ' / ' . $category_weight, '100')); } else { $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $category_weight)); $total = Display::badge($total_weight . ' / ' . $category_weight, 'warning'); } $row = array(null, null, " <h5>" . get_lang('SubTotal') . '</h5>', null, $total . ' ' . $label, 'child_of' => $parent_id); $sortable_data[] = $row; } } } } //end looping categories } //end looping categories if (api_is_allowed_to_edit()) { if (count($main_cat) > 1) { $main_weight = intval($main_cat[0]->get_weight()); if (intval($total_categories_weight) == $main_weight) { $total = score_badges(array($total_categories_weight . ' / ' . $main_weight, '100')); } else { $total = Display::badge($total_categories_weight . ' / ' . $main_weight, 'warning'); } $row = array(null, null, '<h3>' . get_lang('Total') . '</h3>', null, $total); $sortable_data[] = $row; } } // warning messages $view = isset($_GET['view']) ? $_GET['view'] : null; if (api_is_allowed_to_edit()) { if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view != 'presence') { $id_cat = intval($_GET['selectcat']); $category = Category::load($id_cat); //$weight_category = intval($this->build_weight($category[0])); $weight_category = intval($this->build_weight($category[0])); $course_code = $this->build_course_code($category[0]); $weight_total_links = round($weight_total_links); if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) { $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); $modify_icons = '<a class="right_link" href="gradebook_edit_cat.php?editcat=' . $id_cat . '&cidReq=' . $course_code . '">' . Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL) . '</a>'; $warning_message .= $modify_icons; Display::display_warning_message($warning_message, false); } $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code); if (!empty($content_html)) { $new_content = explode('</head>', $content_html['content']); } if (empty($new_content[0])) { $warning_message = get_lang('ThereIsNotACertificateAvailableByDefault'); $cert_icon = '<a class="right_link" href="../document/document.php?curdirpath=/certificates&' . $course_code . '&origin=gradebook&selectcat=' . $id_cat . '">' . Display::return_icon('certificate.png', get_lang('AttachCertificate'), array(), ICON_SIZE_SMALL) . '</a>'; Display::display_warning_message($warning_message . $cert_icon, false); } } if (empty($_GET['selectcat'])) { $categories = Category::load(); $weight_categories = $certificate_min_scores = $course_codes = array(); foreach ($categories as $category) { $course_code_category = $this->build_course_code($category); if (!empty($course_code)) { if ($course_code_category == $course_code) { $weight_categories[] = intval($this->build_weight($category)); $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); $course_codes[] = $course_code; break; } } else { $weight_categories[] = intval($this->build_weight($category)); $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); $course_codes[] = $course_code_category; } } if (is_array($weight_categories) && is_array($certificate_min_scores) && is_array($course_codes)) { $warning_message = ''; for ($x = 0; $x < count($weight_categories); $x++) { $weight_category = intval($weight_categories[$x]); $certificate_min_score = intval($certificate_min_scores[$x]); $course_code = $course_codes[$x]; if (empty($certificate_min_score) || $certificate_min_score > $weight_category) { $warning_message .= $course_code . ' - ' . get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan') . ' ' . $weight_category . '<br />'; } } if (!empty($warning_message)) { Display::display_warning_message($warning_message, false); } } } } return $sortable_data; }
private function build_edit_column($item) { $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id()); $locked_status = $this->evaluation->get_locked(); if (api_is_allowed_to_edit(null, true) && $locked_status == 0) { //api_is_course_admin() $edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '">' . Display::return_icon('edit.png', get_lang('Modify'), '', '22') . '</a>'; $edit_column .= ' <a href="' . api_get_self() . '?delete_mark=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '">' . Display::return_icon('delete.png', get_lang('Delete'), '', '22') . '</a>'; } if ($this->evaluation->get_course_code() == null) { $edit_column .= ' <a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();"> <img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>'; $edit_column .= ' <a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '"> <img src="../img/statistics.gif" width="17px" border="0" title="' . get_lang('Statistics') . '" alt="" /></a>'; } // Evaluation's origin is a link if ($this->evaluation->get_category_id() < 0) { $link = LinkFactory::get_evaluation_link($this->evaluation->get_id()); $doc_url = $link->get_view_url($item['id']); if ($doc_url != null) { $edit_column .= ' <a href="' . $doc_url . '" target="_blank">' . '<img src="' . api_get_path(WEB_CODE_PATH) . 'img/link.gif" border="0" title="' . get_lang('OpenDocument') . '" alt="" />' . '</a>'; } } return $edit_column; }
$view = isset($_REQUEST['view']) ? $_REQUEST['view'] : ''; $nameTools = get_lang('Tracking'); // Display the header. Display::display_header($nameTools, 'Tracking'); // getting all the students of the course if (empty($session_id)) { // Registered students in a course outside session. $a_students = CourseManager::get_student_list_from_course_code( api_get_course_id() ); } else { // Registered students in session. $a_students = CourseManager::get_student_list_from_course_code( api_get_course_id(), true, $sessionId ); } $nbStudents = count($a_students); $extra_info = array(); // Getting all the additional information of an additional profile field. if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field']) ) { $user_array = array(); foreach ($a_students as $key => $item) { $user_array[] = $key;
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>'; }
if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) { api_not_allowed(); } //Checking visibility (eye icon) $visibility = api_get_item_visibility(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id(), api_get_session_id()); if (!api_is_allowed_to_edit(null, true) && intval($visibility) == 0) { api_not_allowed(); } if (empty($_SESSION['oLP'])) { api_not_allowed(true); } $debug = 0; if ($debug) { error_log('------ Entering lp_impress.php -------'); } $course_code = api_get_course_id(); $course_id = api_get_course_int_id(); $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH) . 'javascript/impress/impress-demo.css'); $list = $_SESSION['oLP']->get_toc(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false); if ($is_allowed_to_edit) { echo '<div style="position: fixed; top: 0px; left: 0px; pointer-events: auto;width:100%">'; global $interbreadcrumb; $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list&isStudentView=false', 'name' => get_lang('LearningPaths')); $interbreadcrumb[] = array('url' => api_get_self() . "?action=add_item&type=step&lp_id=" . $_SESSION['oLP']->lp_id . "&isStudentView=false", 'name' => $_SESSION['oLP']->get_name()); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Preview')); echo return_breadcrumb($interbreadcrumb, null, null); echo '</div>'; } $html = ''; $step = 1;
public function make_lp($files = array()) { global $_course; $previous = 0; $i = 0; if (!is_dir($this->base_work_dir.$this->created_dir)) return false; foreach ($files as $file) { /* '||' is used as separator between fields: slide name (with accents) || file name (without accents) || all slide text (to be indexed). */ list($slide_name, $file_name, $slide_body) = explode('||', $file); // Filename is utf8 encoded, but when we decode, some chars are not translated (like quote ’). // so we remove these chars by translating it in htmlentities and the reconvert it in want charset. $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset); $slide_name = str_replace('’', '\'', $slide_name); $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset); $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding()); if ($this->take_slide_name === true) { $slide_name = str_replace('_', ' ', $slide_name); $slide_name = api_ucfirst($slide_name); } else { $slide_name = 'slide'.str_repeat('0', 2 - strlen($i)).$i; } $i++; // Add the png to documents. $document_id = add_document( $_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name ); api_item_property_update( $_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), 0, 0, null, null, api_get_session_id() ); // Generating the thumbnail. $image = $this->base_work_dir.$this->created_dir .'/'. $file_name; $pattern = '/(\w+)\.png$/'; $replacement = '${1}_thumb.png'; $thumb_name = preg_replace($pattern, $replacement, $file_name); // Calculate thumbnail size. $image_size = api_getimagesize($image); $width = $image_size['width']; $height = $image_size['height']; $thumb_width = 300; $thumb_height = floor($height * ($thumb_width / $width)); $my_new_image = new Image($image); $my_new_image->resize($thumb_width, $thumb_height); $my_new_image->send_image($this->base_work_dir.$this->created_dir .'/'. $thumb_name, -1, 'png'); // Adding the thumbnail to documents. $document_id_thumb = add_document( $_course, $this->created_dir.'/'.urlencode($thumb_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$thumb_name), $slide_name ); api_item_property_update($_course, TOOL_THUMBNAIL, $document_id_thumb, 'DocumentAdded', api_get_user_id(), 0, 0); // Create an html file. $html_file = $file_name.'.html'; $fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+'); $slide_src = api_get_path(REL_COURSE_PATH).$_course['path'].'/document/'.$this->created_dir.'/'.utf8_encode($file_name); $slide_src = str_replace('//', '/', $slide_src); fwrite($fp, '<html> <head> </head> <body> <img src="'.$slide_src.'" /> </body> </html>'); // This indentation is to make the generated html files to look well. fclose($fp); $document_id = add_document( $_course, $this->created_dir.'/'.urlencode($html_file), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$html_file), $slide_name ); if ($document_id) { // Put the document in item_property update. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), 0, 0, null, null, api_get_session_id()); $previous = $this->add_item(0, $previous, 'document', $document_id, $slide_name, ''); if ($this->first_item == 0) { $this->first_item = $previous; } } // Code for text indexing. if (api_get_setting('search_enabled') == 'true') { if (isset($_POST['index_document']) && $_POST['index_document']) { $di = new ChamiloIndexer(); isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english'; $di->connectDb(NULL, NULL, $lang); $ic_slide = new IndexableChunk(); $ic_slide->addValue('title', $slide_name); $specific_fields = get_specific_field_list(); $all_specific_terms = ''; foreach ($specific_fields as $specific_field) { if (isset($_REQUEST[$specific_field['code']])) { $sterms = trim($_REQUEST[$specific_field['code']]); $all_specific_terms .= ' '. $sterms; if (!empty($sterms)) { $sterms = explode(',', $sterms); foreach ($sterms as $sterm) { $ic_slide->addTerm(trim($sterm), $specific_field['code']); } } } } $slide_body = $all_specific_terms .' '. $slide_body; $ic_slide->addValue('content', $slide_body); /* FIXME: cidReq:lp_id:doc_id al indexar */ // Add a comment to say terms separated by commas. $courseid = api_get_course_id(); $ic_slide->addCourseId($courseid); $ic_slide->addToolId(TOOL_LEARNPATH); $lp_id = $this->lp_id; $xapian_data = array( SE_COURSE_ID => $courseid, SE_TOOL_ID => TOOL_LEARNPATH, SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id), SE_USER => (int)api_get_user_id(), ); $ic_slide->xapian_data = serialize($xapian_data); $di->addChunk($ic_slide); // Index and return search engine document id. $did = $di->index(); if ($did) { // Save it to db. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did) VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)'; $sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did); Database::query($sql); } } } } }
// Adavanced Parameters if (Gradebook::is_active()) { if (!empty($attendance_qualify_title) || !empty($attendance_weight)) { $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="id_qualify_options" style="display:block">'); $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), array('checked' => 'true', 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}')); $form->addElement('html', '<div id="options_field" style="display:block">'); } else { $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="id_qualify_options" style="display:none">'); $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'); $form->addElement('html', '<div id="options_field" style="display:none">'); } load_gradebook_select_in_tool($form); $form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook')); $form->applyFilter('attendance_qualify_title', 'html_filter'); $form->addElement('text', 'attendance_weight', get_lang('QualifyWeight'), 'value="0.00" Style="width:40px" onfocus="javascript: this.select();"'); $form->applyFilter('attendance_weight', 'html_filter'); $form->addElement('html', '</div>'); $form->addElement('html', '</div>'); } $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); // set default values $default['title'] = Security::remove_XSS($title); $default['description'] = Security::remove_XSS($description, STUDENT); $default['attendance_qualify_title'] = $attendance_qualify_title; $default['attendance_weight'] = $attendance_weight; $link_info = is_resource_in_course_gradebook(api_get_course_id(), 7, $attendance_id, api_get_session_id()); $default['category_id'] = $link_info['category_id']; $form->setDefaults($default); $form->display();
Display::display_header($nameTools, 'Doc'); Display::display_error_message(get_lang('Impossible')); Display::display_footer(); } } else { // Interbreadcrumb for the current directory root path // Copied from document.php $dir_array = explode('/', $dir); $array_len = count($dir_array); // Interbreadcrumb for the current directory root path if (empty($document_data['parents'])) { $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); } else { foreach ($document_data['parents'] as $document_sub_data) { $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); } } $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools); Display::display_header($nameTools, "Doc"); if ($is_certificate_mode) { $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id()); $str_info = ''; foreach ($all_information_by_create_certificate[0] as $info_value) { $str_info .= $info_value . '<br/>'; } $create_certificate = get_lang('CreateCertificateWithTags'); Display::display_normal_message($create_certificate . ': <br /><br/>' . $str_info, false); } echo $form->return_form(); Display::display_footer(); }
/** * This functions updates the note in the database * * @param array $values * * @author Christian Fasanando <*****@*****.**> * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ static function update_note($values) { if (!is_array($values) or empty($values['note_title'])) { return false; } // Database table definition $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); $course_id = api_get_course_int_id(); $sql = "UPDATE $t_notebook SET user_id = '" . api_get_user_id() . "', course = '" . Database::escape_string(api_get_course_id()) . "', session_id = '" . intval($_SESSION['id_session']) . "', title = '" . Database::escape_string($values['note_title']) . "', description = '" . Database::escape_string($values['note_comment']) . "', update_date = '" . Database::escape_string(date('Y-m-d H:i:s')) . "' WHERE c_id = $course_id AND notebook_id = '" . Database::escape_string($values['notebook_id']) . "'"; $result = Database::query($sql); //update item_property (update) api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $values['notebook_id'], 'NotebookUpdated', api_get_user_id()); $affected_rows = Database::affected_rows(); if (!empty($affected_rows)) { return true; } }