/** * Get document information */ private function get_information($course_id, $link_id) { $course_information = api_get_course_info($course_id); $course_id = $course_information['real_id']; $course_id_alpha = $course_information['id']; if (!empty($course_information)) { $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $link_id = Database::escape_string($link_id); $sql = "SELECT insert_user_id FROM {$item_property_table}\n \t\tWHERE ref = {$link_id} AND tool = '" . TOOL_LINK . "' AND c_id = {$course_id}\n \t\tLIMIT 1"; $name = get_lang('Links'); $url = api_get_path(WEB_PATH) . 'main/link/link.php?cidReq=%s'; $url = sprintf($url, $course_id_alpha); // Get the image path $thumbnail = api_get_path(WEB_IMG_PATH) . 'link.gif'; $image = $thumbnail; //FIXME: use big images // get author $author = ''; $item_result = Database::query($sql); if ($row = Database::fetch_array($item_result)) { $user_data = api_get_user_info($row['insert_user_id']); $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); } return array($thumbnail, $image, $name, $author, $url); } else { return array(); } }
/** * constructor of the class * * @author Olivier Brouckaert * @param int $questionId that answers belong to * @param int $course_id */ public function __construct($questionId, $course_id = null) { $this->questionId = intval($questionId); $this->answer = array(); $this->correct = array(); $this->comment = array(); $this->weighting = array(); $this->position = array(); $this->hotspot_coordinates = array(); $this->hotspot_type = array(); $this->destination = array(); // clears $new_* arrays $this->cancel(); if (!empty($course_id)) { $courseInfo = api_get_course_info_by_id($course_id); } else { $courseInfo = api_get_course_info(); } $this->course = $courseInfo; $this->course_id = $courseInfo['real_id']; // fills arrays $objExercise = new Exercise($this->course_id); $exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null; $objExercise->read($exerciseId); if ($objExercise->random_answers == '1') { $this->readOrderedBy('rand()', ''); // randomize answers } else { $this->read(); // natural order } }
/** * Checking user in DB * @param int $uid */ public static function loginCheck($uid) { $_course = api_get_course_info(); $uid = (int) $uid; $online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); if (!empty($uid)) { $login_ip = ''; if (!empty($_SERVER['REMOTE_ADDR'])) { $login_ip = Database::escape_string($_SERVER['REMOTE_ADDR']); } $login_date = api_get_utc_datetime(); $access_url_id = 1; if (api_get_multiple_access_url() && api_get_current_access_url_id() != -1) { $access_url_id = api_get_current_access_url_id(); } $session_id = api_get_session_id(); // if the $_course array exists this means we are in a course and we have to store this in the who's online table also // to have the x users in this course feature working if (is_array($_course) && count($_course) > 0 && !empty($_course['id'])) { $query = "REPLACE INTO " . $online_table . " (login_id, login_user_id, login_date, login_ip, course, session_id, access_url_id)\n VALUES ({$uid}, {$uid}, '{$login_date}', '{$login_ip}', '" . $_course['id'] . "', '{$session_id}', '{$access_url_id}' )"; } else { $query = "REPLACE INTO " . $online_table . " (login_id,login_user_id,login_date,login_ip, session_id, access_url_id)\n VALUES ({$uid},{$uid},'{$login_date}','{$login_ip}', '{$session_id}', '{$access_url_id}')"; } Database::query($query); } }
/** * Constructor of the class * * @author Olivier Brouckaert * @param integer Question ID that answers belong to * @param int course id * @param \Exercise obj */ public function Answer($questionId, $course_id = null, \Exercise $exercise = null) { $this->questionId = intval($questionId); $this->answer = array(); $this->correct = array(); $this->comment = array(); $this->weighting = array(); $this->position = array(); $this->hotspot_coordinates = array(); $this->hotspot_type = array(); $this->destination = array(); // clears $new_* arrays $this->cancel(); if (!empty($course_id)) { $course_info = api_get_course_info_by_id($course_id); } else { $course_info = api_get_course_info(); } $this->course = $course_info; $this->course_id = $course_info['real_id']; if (isset($exercise)) { if ($exercise->random_answers == '1') { // Randomize answers. $this->readOrderedBy('rand()', ''); } else { // Normal order $this->read(); } } else { $this->read(); } }
/** * @param Application $app * @param int $exerciseId * @param int $questionId * @return Response */ public function copyQuestionAction(Application $app, $exerciseId, $questionId) { $question = \Question::read($questionId); if ($question) { $newQuestionTitle = $question->selectTitle() . ' - ' . get_lang('Copy'); $question->updateTitle($newQuestionTitle); //Duplicating the source question, in the current course $courseInfo = api_get_course_info(); $newId = $question->duplicate($courseInfo); // Reading new question $newQuestion = \Question::read($newId); $newQuestion->addToList($exerciseId); // Reading Answers obj of the current course $newAnswer = new \Answer($questionId); $newAnswer->read(); //Duplicating the Answers in the current course $newAnswer->duplicate($newId); /*$params = array( 'cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $newId, 'exerciseId' => $exerciseId ); $url = $app['url_generator']->generate('exercise_question_pool', $params); return $app->redirect($url);*/ $response = \Display::return_message(get_lang('QuestionCopied') . ": " . $newQuestionTitle); return new Response($response, 200, array()); } }
/** * Validates imported data. */ function validate_data($courses) { $errors = array(); $coursecodes = array(); foreach ($courses as $index => $course) { $course['line'] = $index + 1; // 1. Check whether mandatory fields are set. $mandatory_fields = array('Code', 'Title', 'CourseCategory'); foreach ($mandatory_fields as $field) { if (!isset($course[$field]) || strlen($course[$field]) == 0) { $course['error'] = get_lang($field . 'Mandatory'); $errors[] = $course; } } // 2. Check current course code. if (isset($course['Code']) && strlen($course['Code']) != 0) { // 2.1 Check whether code has been already used by this CVS-file. if (isset($coursecodes[$course['Code']])) { $course['error'] = get_lang('CodeTwiceInFile'); $errors[] = $course; } else { // 2.2 Check whether course code has been occupied. $courseInfo = api_get_course_info($course['Code']); if (!empty($courseInfo)) { $course['error'] = get_lang('CodeExists'); $errors[] = $course; } } $coursecodes[$course['Code']] = 1; } // 3. Check whether teacher exists. $teacherList = getTeacherListInArray($course['Teacher']); if (!empty($teacherList)) { foreach ($teacherList as $teacher) { $teacherInfo = api_get_user_info_from_username($teacher); if (empty($teacherInfo)) { $course['error'] = get_lang('UnknownTeacher') . ' (' . $teacher . ')'; $errors[] = $course; } else { /*if ($teacherInfo['status'] != COURSEMANAGER) { $course['error'] = get_lang('UserIsNotATeacher').' ('.$teacher.')'; $errors[] = $course; }*/ } } } // 4. Check whether course category exists. if (isset($course['CourseCategory']) && strlen($course['CourseCategory']) != 0) { require_once api_get_path(LIBRARY_PATH) . 'course_category.lib.php'; $categoryInfo = getCategory($course['CourseCategory']); if (empty($categoryInfo)) { //@todo this is so bad even all lang variables are wrong ... $course['error'] = get_lang('UnkownCategoryCourseCode') . ' (' . $course['CourseCategory'] . ')'; $errors[] = $course; } } } return $errors; }
public function data() { $_course = api_get_course_info(); if ($_course == '-1') { $_course = array(); } return $_course; }
/** * @param string $name * @param Request $request * @return Response */ public function classicAction($name, Request $request) { // get. $_GET = $request->query->all(); // post. $_POST = $request->request->all(); $rootDir = $this->get('kernel')->getRealRootDir(); //$_REQUEST = $request->request->all(); $mainPath = $rootDir . 'main/'; $fileToLoad = $mainPath . $name; // Setting legacy values inside the container /** @var Connection $dbConnection */ $dbConnection = $this->container->get('database_connection'); $em = $this->get('kernel')->getContainer()->get('doctrine.orm.entity_manager'); $database = new \Database($dbConnection, array()); $database->setConnection($dbConnection); $database->setManager($em); Container::$container = $this->container; Container::$dataDir = $this->container->get('kernel')->getDataDir(); Container::$courseDir = $this->container->get('kernel')->getDataDir(); //Container::$configDir = $this->container->get('kernel')->getConfigDir(); $this->container->get('twig')->addGlobal('api_get_cidreq', api_get_cidreq()); //$breadcrumb = $this->container->get('chamilo_core.block.breadcrumb'); if (is_file($fileToLoad) && \Security::check_abs_path($fileToLoad, $mainPath)) { // Files inside /main need this variables to be set $is_allowed_in_course = api_is_allowed_in_course(); $is_courseAdmin = api_is_course_admin(); $is_platformAdmin = api_is_platform_admin(); $toolNameFromFile = basename(dirname($fileToLoad)); $charset = 'UTF-8'; // Default values $_course = api_get_course_info(); $_user = api_get_user_info(); $debug = $this->container->get('kernel')->getEnvironment() == 'dev' ? true : false; // Loading file ob_start(); require_once $fileToLoad; $out = ob_get_contents(); ob_end_clean(); // No browser cache when executing an exercise. if ($name == 'exercice/exercise_submit.php') { $responseHeaders = array('cache-control' => 'no-store, no-cache, must-revalidate'); } $js = isset($htmlHeadXtra) ? $htmlHeadXtra : array(); // $interbreadcrumb is loaded in the require_once file. $interbreadcrumb = isset($interbreadcrumb) ? $interbreadcrumb : null; $template = Container::$legacyTemplate; $defaultLayout = 'layout_one_col.html.twig'; if (!empty($template)) { $defaultLayout = $template; } return $this->render('ChamiloCoreBundle::' . $defaultLayout, array('legacy_breadcrumb' => $interbreadcrumb, 'content' => $out, 'js' => $js)); } else { // Found does not exist throw new NotFoundHttpException(); } }
/** * @param $course_code * @return array|bool */ function initializeReport($course_code) { $course_info = api_get_course_info($course_code); $table_reporte_semanas = Database::get_main_table('rp_reporte_semanas'); $table_students_report = Database::get_main_table('rp_students_report'); $table_semanas_curso = Database::get_main_table('rp_semanas_curso'); $table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_post = Database::get_course_table(TABLE_FORUM_POST, $course_info['dbName']); $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION, $course_info['dbName']); $course_code = Database::escape_string($course_code); $res = Database::query("SELECT COUNT(*) as cant FROM $table_reporte_semanas WHERE course_code = '" . $course_code . "'"); $sqlWeeks = "SELECT semanas FROM $table_semanas_curso WHERE course_code = '$course_code'"; $resWeeks = Database::query($sqlWeeks); $weeks = Database::fetch_object($resWeeks); $obj = Database::fetch_object($res); $weeksCount = (!isset($_POST['weeksNumber'])) ? (($weeks->semanas == 0) ? 7 : $weeks->semanas) : $_POST['weeksNumber']; $weeksCount = Database::escape_string($weeksCount); Database::query("REPLACE INTO $table_semanas_curso (course_code , semanas) VALUES ('$course_code','$weeksCount')"); if (intval($obj->cant) != $weeksCount) { if (intval($obj->cant) > $weeksCount) { $sql = "DELETE FROM $table_reporte_semanas WHERE week_id > $weeksCount AND course_code = '$course_code'"; Database::query("DELETE FROM $table_reporte_semanas WHERE week_id > $weeksCount AND course_code = '$course_code'"); } else { for ($i = $obj->cant + 1; $i <= $weeksCount; $i++) { if (!Database::query("INSERT INTO $table_reporte_semanas (week_id, course_code, forum_id, work_id, quiz_id, pc_id) VALUES ($i, '$course_code', '0', '0', '0', '0' )")) { return false; } } } } $sql = "REPLACE INTO $table_students_report (user_id, week_report_id, work_ok , thread_ok , quiz_ok , pc_ok) SELECT cu.user_id, rs.id, 0, 0, 0, 0 FROM $table_course_rel_user cu LEFT JOIN $table_reporte_semanas rs ON cu.course_code = rs.course_code WHERE cu.status = 5 AND rs.course_code = '$course_code' ORDER BY cu.user_id, rs.id"; if (!Database::query($sql)) { return false; } else { $page = (!isset($_GET['page'])) ? 1 : $_GET['page']; Database::query("UPDATE $table_students_report sr SET sr.work_ok = 1 WHERE CONCAT (sr.user_id,',',sr.week_report_id) IN (SELECT DISTINCT CONCAT(w.user_id,',',rs.id) FROM $table_work w JOIN $table_reporte_semanas rs ON w.parent_id = rs.work_id)"); Database::query("UPDATE $table_students_report sr SET sr.thread_ok = 1 WHERE CONCAT (sr.user_id,',',sr.week_report_id) IN (SELECT DISTINCT CONCAT(f.poster_id,',',rs.id) FROM $table_post f JOIN $table_reporte_semanas rs ON f.thread_id = rs.forum_id)"); return showResults($course_info, $weeksCount, $page); } }
/** * Show the form to copy courses * @global string $returnLink * @global string $courseCode */ function displayForm() { global $returnLink, $courseCode; $courseInfo = api_get_course_info(); $sessionId = api_get_session_id(); $userId = api_get_user_id(); $sessions = SessionManager::getSessionsCoachedByUser($userId); $html = ''; // Actions $html .= '<div class="actions">'; // Link back to the documents overview $html .= '<a href="' . $returnLink . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('Maintenance'), '', ICON_SIZE_MEDIUM) . '</a>'; $html .= '</div>'; $html .= Display::return_message(get_lang('CopyCourseFromSessionToSessionExplanation')); $html .= '<form name="formulaire" method="post" action="' . api_get_self() . '?' . api_get_cidreq() . '" >'; $html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%">'; // Source $html .= '<tr><td width="15%"><b>' . get_lang('OriginCoursesFromSession') . ':</b></td>'; $html .= '<td width="10%" align="left">' . api_get_session_name($sessionId) . '</td>'; $html .= '<td width="50%">'; $html .= "{$courseInfo['title']} ({$courseInfo['code']})" . '</td></tr>'; // Destination $html .= '<tr><td width="15%"><b>' . get_lang('DestinationCoursesFromSession') . ':</b></td>'; $html .= '<td width="10%" align="left"><div id="ajax_sessions_list_destination">'; $html .= '<select name="sessions_list_destination" onchange="javascript: xajax_searchCourses(this.value,\'destination\');">'; if (empty($sessions)) { $html .= '<option value = "0">' . get_lang('ThereIsNotStillASession') . '</option>'; } else { $html .= '<option value = "0">' . get_lang('SelectASession') . '</option>'; foreach ($sessions as $session) { if ($session['id'] == $sessionId) { continue; } if (!SessionManager::sessionHasCourse($session['id'], $courseCode)) { continue; } $html .= '<option value="' . $session['id'] . '">' . $session['name'] . '</option>'; } } $html .= '</select ></div></td>'; $html .= '<td width="50%">'; $html .= '<div id="ajax_list_courses_destination">'; $html .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" ></select></div></td>'; $html .= '</tr></table>'; $html .= "<fieldset>"; $html .= '<legend>' . get_lang('TypeOfCopy') . ' <small>(' . get_lang('CopyOnlySessionItems') . ')</small></legend>'; $html .= '<label class="radio"><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>'; $html .= get_lang('FullCopy') . '</label>'; $html .= '<label class="radio"><input type="radio" id="copy_option_2" name="copy_option" value="select_items"/>'; $html .= ' ' . get_lang('LetMeSelectItems') . '</label><br/>'; $html .= "</fieldset>"; $html .= '<button class="save" type="submit" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;">' . get_lang('CopyCourse') . '</button>'; $html .= '</form>'; echo $html; }
/** * Organize the saving of a link, using the parent's save method and * updating the item_property table * @param array $params * @param boolean $show_query Whether to show the query in logs when * calling parent's save method * * @return bool True if link could be saved, false otherwise */ public function save($params, $show_query = null) { $course_info = api_get_course_info(); $params['session_id'] = api_get_session_id(); $params['category_id'] = isset($params['category_id']) ? $params['category_id'] : 0; $id = parent::save($params, $show_query); if (!empty($id)) { api_item_property_update($course_info, TOOL_LINK, $id, 'LinkAdded', api_get_user_id()); } return $id; }
public function __construct() { $this->paths = array('root_sys' => api_get_path(SYS_PATH), 'sys_root' => api_get_path(SYS_PATH), 'sys_course_path' => api_get_path(SYS_COURSE_PATH), 'path.temp' => api_get_path(SYS_ARCHIVE_PATH)); /*$this->entityManager = $entityManager; $this->paths = $paths; $this->urlGenerator = $urlGenerator; $this->translator = $translator; $this->security = $security;*/ $this->user = api_get_user_info(); $this->course = api_get_course_info(); $this->driverList = $this->getDefaultDriverList(); }
public function __construct(EntityManager $entityManager, array $paths, Router $urlGenerator, Translator $translator, SecurityContext $security, $user, $course = null) { $this->paths = array('root_sys' => api_get_path(SYS_PATH), 'sys_root' => api_get_path(SYS_PATH), 'sys_course_path' => api_get_path(SYS_COURSE_PATH), 'path.temp' => api_get_path(SYS_ARCHIVE_PATH)); $this->entityManager = $entityManager; //$this->paths = $paths; $this->urlGenerator = $urlGenerator; $this->translator = $translator; $this->security = $security; $this->user = empty($user) ? api_get_user_info() : $user; $this->course = empty($course) ? api_get_course_info() : $course; $this->driverList = $this->getDefaultDriverList(); }
/** * 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); }
/** * @param int $courseId * @param int $announcement */ public function __construct($courseId, $announcement) { if (!empty($courseId)) { $course = api_get_course_info_by_id($courseId); } else { $course = api_get_course_info(); } $this->course = $course; $this->session_id = api_get_session_id(); if (is_numeric($announcement)) { $announcement = AnnouncementManager::get_by_id($course['real_id'], $announcement); } $this->announcement = $announcement; }
/** * Gets the comment about a file from the corresponding database record. * @param string File path * @return string Comment from the database record * Added conditional to the table if is empty. */ function GetComment($path, $course_code = '') { $dbTable = Database::get_course_table(TABLE_DOCUMENT); $course_info = api_get_course_info($course_code); $path = Database::escape_string($path); if (!empty($course_info) && !empty($path)) { $query = "SELECT comment FROM {$dbTable} WHERE c_id = {$course_info['real_id']}"; $result = Database::query($query); while ($row = Database::fetch_array($result)) { return $row[0]; } } return null; }
/** * Unzip the exercise in the temp folder * @param string The path of the temporary directory where the exercise was uploaded and unzipped * @param string * @return bool */ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) { $_course = api_get_course_info(); $_user = api_get_user_info(); //Check if the file is valid (not to big and exists) if (!isset($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) { // upload failed return false; } if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1)) { return true; } return false; }
/** * Saves imported data. */ function save_data($users_courses) { $user_table = Database::get_main_table(TABLE_MAIN_USER); $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); $csv_data = array(); foreach ($users_courses as $user_course) { $csv_data[$user_course['UserName']][$user_course['CourseCode']] = $user_course['Status']; } foreach ($csv_data as $username => $csv_subscriptions) { $sql = "SELECT * FROM {$user_table} u WHERE u.username = '******'"; $res = Database::query($sql); $obj = Database::fetch_object($res); $user_id = $obj->user_id; $sql = "SELECT * FROM {$course_user_table} cu\n\t\t WHERE cu.user_id = {$user_id} AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . " "; $res = Database::query($sql); $db_subscriptions = array(); while ($obj = Database::fetch_object($res)) { $db_subscriptions[$obj->c_id] = $obj->status; } $csvCourseList = array(); foreach ($csv_subscriptions as $courseCode => $status) { $courseInfo = api_get_course_info($courseCode); if ($courseInfo) { $csvCourseList[$courseInfo['real_id']] = $status; } } $to_subscribe = array_diff(array_keys($csvCourseList), array_keys($db_subscriptions)); $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csvCourseList)); global $inserted_in_course; if (!isset($inserted_in_course)) { $inserted_in_course = array(); } if (isset($_POST['subscribe']) && $_POST['subscribe']) { foreach ($to_subscribe as $courseId) { CourseManager::add_user_to_course($user_id, $courseId, $csvCourseList[$courseId]); $course_info = api_get_course_info_by_id($courseId); $inserted_in_course[$courseId] = $course_info['title']; } } if (isset($_POST['unsubscribe']) && $_POST['unsubscribe']) { foreach ($to_unsubscribe as $courseId) { CourseManager::unsubscribe_user($user_id, $courseId); $course_info = api_get_course_info_by_id($courseId); $inserted_in_course[$courseId] = $course_info['title']; } } } }
/** * * @return \Model\Course|null */ public static function current() { $_course = api_get_course_info(); /** * Note that $_course = -1 when not set. */ if (empty($_course) || !is_array($_course)) { return null; } static $result = null; if (empty($result)) { $id = $_course['real_id']; $result = self::query("id = {$id}")->first(); } return $result; }
/** * Reads question information from the data base * * @param int $id - question ID * @param int $course_id * * @return Question * * @author Olivier Brouckaert */ public static function read($id, $course_id = null) { $id = intval($id); if (!empty($course_id)) { $course_info = api_get_course_info_by_id($course_id); } else { $course_info = api_get_course_info(); } $course_id = $course_info['real_id']; if (empty($course_id) || $course_id == -1) { return false; } $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $sql = "SELECT question, description, ponderation, position, type, picture, level, extra\n FROM {$TBL_QUESTIONS}\n WHERE c_id = {$course_id} AND id = {$id} "; $result = Database::query($sql); // if the question has been found if ($object = Database::fetch_object($result)) { $objQuestion = Question::getInstance($object->type); if (!empty($objQuestion)) { $objQuestion->id = $id; $objQuestion->question = $object->question; $objQuestion->description = $object->description; $objQuestion->weighting = $object->ponderation; $objQuestion->position = $object->position; $objQuestion->type = $object->type; $objQuestion->picture = $object->picture; $objQuestion->level = (int) $object->level; $objQuestion->extra = $object->extra; $objQuestion->course = $course_info; $objQuestion->category = TestCategory::getCategoryForQuestion($id); $tblQuiz = Database::get_course_table(TABLE_QUIZ_TEST); $sql = "SELECT DISTINCT q.exercice_id\n FROM {$TBL_EXERCISE_QUESTION} q\n INNER JOIN {$tblQuiz} e\n ON e.c_id = q.c_id AND e.id = q.exercice_id\n WHERE\n q.c_id = {$course_id} AND\n q.question_id = {$id} AND\n e.active >= 0"; $result = Database::query($sql); // fills the array with the exercises which this question is in if ($result) { while ($obj = Database::fetch_object($result)) { $objQuestion->exerciseList[] = $obj->exercice_id; } } return $objQuestion; } } // question not found return false; }
/** * @param FormValidator $form * @param null $objExercise * @return bool */ public function processCreation($form, $objExercise = null) { $file_info = $form->getSubmitValue('imageUpload'); $_course = api_get_course_info(); parent::processCreation($form, $objExercise); if (!empty($file_info['tmp_name'])) { $this->uploadPicture($file_info['tmp_name'], $file_info['name']); $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document'; $picturePath = $documentPath . '/images'; // fixed width ang height if (file_exists($picturePath . '/' . $this->picture)) { $this->resizePicture('width', 800); $this->save(); } else { return false; } } }
/** * Create dummy documents */ function create_dummy_documents() { $course = api_get_course_info(); $course_doc_path = $this->course->backup_path . '/document/'; $number_of_documents = rand(10, 30); $extensions = array('html', 'doc'); $directories = array(); $property = $this->default_property; $property['lastedit_type'] = 'DocumentAdded'; $property['tool'] = TOOL_DOCUMENT; $doc_id = 0; for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id++) { $path = ''; $doc_type = rand(0, count($extensions) - 1); $extension = $extensions[$doc_type]; $filename = $this->get_dummy_content('title') . '_' . $doc_id . '.' . $extension; $content = $this->get_dummy_content('text'); $dirs = rand(0, 3); for ($i = 0; $i < $dirs; $i++) { $path .= 'directory/'; $directories[$path] = 1; } $dir_to_make = $course_doc_path . $path; if (!is_dir($dir_to_make)) { @mkdir($dir_to_make, api_get_permissions_for_new_directories(), true); } $file = $course_doc_path . $path . $filename; $fp = fopen($file, 'w'); fwrite($fp, $content); fclose($fp); $size = filesize($file); $document = new Document($doc_id, '/' . $path . $filename, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'file', $size); $document->item_properties[] = $property; $this->course->add_resource($document); } foreach ($directories as $path => $flag) { $path = substr($path, 0, strlen($path) - 1); $document = new Document($doc_id++, '/' . $path, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'folder', 0); $property['lastedit_type'] = 'FolderCreated'; $document->item_properties[] = $property; $this->course->add_resource($document); } }
/** * Get document information */ private function get_information($course_id, $doc_id) { $course_information = api_get_course_info($course_id); $course_id = $course_information['real_id']; $course_path = $course_information['path']; if (!empty($course_information)) { $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $doc_table = Database::get_course_table(TABLE_DOCUMENT); $doc_id = intval($doc_id); $sql = "SELECT * FROM $doc_table WHERE $doc_table.id = $doc_id AND c_id = $course_id LIMIT 1"; $dk_result = Database::query($sql); $sql = "SELECT insert_user_id FROM $item_property_table WHERE ref = $doc_id AND tool = '" . TOOL_DOCUMENT . "' AND c_id = $course_id LIMIT 1"; $name = ''; if ($row = Database::fetch_array($dk_result)) { $name = $row['title']; $url = api_get_path(WEB_PATH) . 'courses/%s/document%s'; $url = sprintf($url, $course_path, $row['path']); // Get the image path include_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php'; $icon = choose_image(basename($row['path'])); $thumbnail = api_get_path(WEB_CODE_PATH) . 'img/' . $icon; $image = $thumbnail; //FIXME: use big images // get author $author = ''; $item_result = Database::query($sql); if ($row = Database::fetch_array($item_result)) { $user_data = api_get_user_info($row['insert_user_id']); $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); } } return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here? } else { return array(); } }
/** * @param $course_code * @return array|bool */ function initializeReport($course_code) { $course_info = api_get_course_info($course_code); $table_reporte_semanas = Database::get_main_table('rp_reporte_semanas'); $table_students_report = Database::get_main_table('rp_students_report'); $table_semanas_curso = Database::get_main_table('rp_semanas_curso'); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_post = Database::get_course_table(TABLE_FORUM_POST); $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $course_code = Database::escape_string($course_code); $res = Database::query("SELECT COUNT(*) as cant FROM {$table_reporte_semanas} WHERE course_code = '" . $course_code . "'"); $sqlWeeks = "SELECT semanas FROM {$table_semanas_curso} WHERE course_code = '{$course_code}'"; $resWeeks = Database::query($sqlWeeks); $weeks = Database::fetch_object($resWeeks); $obj = Database::fetch_object($res); $weeksCount = !isset($_POST['weeksNumber']) ? $weeks->semanas == 0 ? 7 : $weeks->semanas : $_POST['weeksNumber']; $weeksCount = Database::escape_string($weeksCount); Database::query("REPLACE INTO {$table_semanas_curso} (course_code , semanas) VALUES ('{$course_code}','{$weeksCount}')"); if (intval($obj->cant) != $weeksCount) { if (intval($obj->cant) > $weeksCount) { $sql = "DELETE FROM {$table_reporte_semanas} WHERE week_id > {$weeksCount} AND course_code = '{$course_code}'"; Database::query("DELETE FROM {$table_reporte_semanas} WHERE week_id > {$weeksCount} AND course_code = '{$course_code}'"); } else { for ($i = $obj->cant + 1; $i <= $weeksCount; $i++) { if (!Database::query("INSERT INTO {$table_reporte_semanas} (week_id, course_code, forum_id, work_id, quiz_id, pc_id)\n\t\t\t\t\t\tVALUES ({$i}, '{$course_code}', '0', '0', '0', '0' )")) { return false; } } } } $sql = "REPLACE INTO {$table_students_report} (user_id, week_report_id, work_ok , thread_ok , quiz_ok , pc_ok)\n\t\t\tSELECT cu.user_id, rs.id, 0, 0, 0, 0\n\t\t\tFROM {$table_course_rel_user} cu\n\t\t\tINNER JOIN {$courseTable} c\n\t\t\tON (c.id = cu.c_id)\n\t\t\tLEFT JOIN {$table_reporte_semanas} rs ON c.code = rs.course_code\n\t\t\tWHERE cu.status = 5 AND rs.course_code = '{$course_code}'\n\t\t\tORDER BY cu.user_id, rs.id"; if (!Database::query($sql)) { return false; } else { $page = !isset($_GET['page']) ? 1 : $_GET['page']; Database::query("UPDATE {$table_students_report} sr SET sr.work_ok = 1\n\t\tWHERE CONCAT (sr.user_id,',',sr.week_report_id)\n\t\tIN (SELECT DISTINCT CONCAT(w.user_id,',',rs.id)\n\t\tFROM {$table_work} w JOIN {$table_reporte_semanas} rs ON w.parent_id = rs.work_id)"); Database::query("UPDATE {$table_students_report} sr SET sr.thread_ok = 1\n\t\tWHERE CONCAT (sr.user_id,',',sr.week_report_id)\n\t\tIN (SELECT DISTINCT CONCAT(f.poster_id,',',rs.id)\n\t\tFROM {$table_post} f JOIN {$table_reporte_semanas} rs ON f.thread_id = rs.forum_id)"); return showResults($course_info, $weeksCount, $page); } }
/** * @return the path of the temporary directory where the exercise was uploaded and unzipped */ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) { global $_user; $_course = api_get_course_info(); //Check if the file is valid (not to big and exists) if (!isset($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) { // upload failed return false; } if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && FileManager::handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1)) { if (!function_exists('gzopen')) { //claro_delete_file($uploadPath); return false; } // upload successfull return true; } else { //claro_delete_file($uploadPath); return false; } }
function inicializarReporte($course_code) { $course_info = api_get_course_info($course_code); $table_reporte_semanas = Database::get_main_table('rp_reporte_semanas'); $table_students_report = Database::get_main_table('rp_students_report'); $table_semanas_curso = Database::get_main_table('rp_semanas_curso'); $table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_post = Database::get_course_table(TABLE_FORUM_POST, $course_info['dbName']); $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION, $course_info['dbName']); $res = Database::query("SELECT COUNT(*) as cant FROM {$table_reporte_semanas} WHERE course_code = '" . $course_code . "'"); $sql_semanas = "SELECT semanas FROM {$table_semanas_curso} WHERE course_code = '{$course_code}'"; $res_semanas = Database::query($sql_semanas); $semanas = Database::fetch_object($res_semanas); $obj = Database::fetch_object($res); $numero_semanas = !isset($_POST['numerosemanas']) ? $semanas->semanas == 0 ? 7 : $semanas->semanas : $_POST['numerosemanas']; Database::query("REPLACE INTO {$table_semanas_curso} (course_code , semanas) VALUES ('{$course_code}','{$numero_semanas}')"); if (intval($obj->cant) != $numero_semanas) { if (intval($obj->cant) > $numero_semanas) { $sql = "DELETE FROM {$table_reporte_semanas} WHERE week_id > {$numero_semanas} AND course_code = '{$course_code}'"; Database::query("DELETE FROM {$table_reporte_semanas} WHERE week_id > {$numero_semanas} AND course_code = '{$course_code}'"); } else { for ($i = $obj->cant + 1; $i <= $numero_semanas; $i++) { if (!Database::query("INSERT INTO {$table_reporte_semanas} (week_id,course_code,forum_id,work_id,quiz_id,pc_id)\n\t\t\t\t\t\tVALUES ('{$i}','{$course_code}','0','0','0','0' )")) { return false; } } } } $sql = "REPLACE INTO {$table_students_report} (user_id,week_report_id, work_ok , thread_ok , quiz_ok , pc_ok)\n\t\t\tSELECT cu.user_id, rs.id, 0, 0, 0, 0\n\t\t\tFROM {$table_course_rel_user} cu\n\t\t\tLEFT JOIN {$table_reporte_semanas} rs ON cu.course_code = rs.course_code\n\t\t\tWHERE cu.status = '5' AND rs.course_code = '{$course_code}'\n\t\t\tORDER BY cu.user_id, rs.id"; if (!Database::query($sql)) { return false; } else { $pagina = !isset($_GET['page']) ? 1 : $_GET['page']; Database::query("UPDATE {$table_students_report} sr SET sr.work_ok = 1\n\t\tWHERE CONCAT (sr.user_id,',',sr.week_report_id)\n\t\tIN (SELECT DISTINCT CONCAT(w.user_id,',',rs.id)\n\t\tFROM {$table_work} w JOIN {$table_reporte_semanas} rs ON w.parent_id = rs.work_id)"); Database::query("UPDATE {$table_students_report} sr SET sr.thread_ok = 1\n\t\tWHERE CONCAT (sr.user_id,',',sr.week_report_id)\n\t\tIN (SELECT DISTINCT CONCAT(f.poster_id,',',rs.id)\n\t\tFROM {$table_post} f JOIN {$table_reporte_semanas} rs ON f.thread_id = rs.forum_id)"); return mostrarResultados($course_info, $numero_semanas, $pagina); } }
/** * Get learning path information */ private function get_information($course_id, $lp_id, $has_document_id = TRUE) { $course_information = api_get_course_info($course_id); $course_id = $course_information['real_id']; $course_path = $course_information['path']; if (!empty($course_information)) { $lpi_table = Database::get_course_table(TABLE_LP_ITEM); $lp_table = Database::get_course_table(TABLE_LP_MAIN); $doc_table = Database::get_course_table(TABLE_DOCUMENT); $lp_id = Database::escape_string($lp_id); if ($has_document_id) { $sql = "SELECT {$lpi_table}.id, {$lp_table}.name, {$lp_table}.author, {$doc_table}.path\n FROM {$lp_table}, {$lpi_table}\n INNER JOIN {$doc_table} ON {$lpi_table}.path = {$doc_table}.id AND {$lpi_table}.c_id = {$course_id}\n WHERE {$lpi_table}.c_id = {$course_id} AND \n {$doc_table}.c_id = {$course_id} AND \n {$lpi_table}.lp_id = {$lp_id} AND \n {$lpi_table}.display_order = 1 AND \n {$lp_table}.id = {$lpi_table}.lp_id\n LIMIT 1"; } else { $sql = "SELECT {$lpi_table}.id, {$lp_table}.name, {$lp_table}.author\n FROM {$lp_table}, {$lpi_table}\n WHERE \n {$lpi_table}.c_id = {$course_id} AND \n {$lp_table}.c_id = {$course_id} AND \n {$lpi_table}.lp_id = {$lp_id} AND \n {$lpi_table}.display_order = 1 AND \n {$lp_table}.id = {$lpi_table}.lp_id\n LIMIT 1"; } $dk_result = Database::query($sql); $path = ''; $name = ''; if ($row = Database::fetch_array($dk_result)) { // Get the image path $img_location = api_get_path(WEB_COURSE_PATH) . $course_path . "/document/"; $thumbnail_path = str_replace('.png.html', '_thumb.png', $row['path']); $big_img_path = str_replace('.png.html', '.png', $row['path']); $thumbnail = ''; if (!empty($thumbnail_path)) { $thumbnail = $img_location . $thumbnail_path; } $image = ''; if (!empty($big_img_path)) { $image = $img_location . $big_img_path; } $name = $row['name']; } return array($thumbnail, $image, $name, $row['author']); } else { return array(); } }
/** * Get document information */ private function get_information($course_id, $doc_id) { $course_information = api_get_course_info($course_id); $course_id = $course_information['real_id']; $course_path = $course_information['path']; if (!empty($course_information)) { $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $doc_table = Database::get_course_table(TABLE_DOCUMENT); $doc_id = Database::escape_string($doc_id); $sql = "SELECT * FROM {$doc_table}\n WHERE {$doc_table}.id = {$doc_id} AND c_id = {$course_id}\n LIMIT 1"; $dk_result = Database::query($sql); $sql = "SELECT insert_user_id FROM {$item_property_table}\n WHERE ref = {$doc_id} AND tool = '" . TOOL_DOCUMENT . "' AND c_id = {$course_id}\n LIMIT 1"; $name = ''; if ($row = Database::fetch_array($dk_result)) { $name = $row['title']; $url = api_get_path(WEB_PATH) . 'courses/%s/document%s'; $url = sprintf($url, $course_path, $row['path']); // Get the image path $icon = FileManager::choose_image(basename($row['path'])); $thumbnail = api_get_path(WEB_IMG_PATH) . $icon; $image = $thumbnail; //FIXME: use big images // get author $author = ''; $item_result = Database::query($sql); if ($row = Database::fetch_array($item_result)) { $user_data = api_get_user_info($row['insert_user_id']); $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); } } return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here? } else { return array(); } }
function get_all_users($evals = array(), $links = array()) { $coursecodes = array(); $users = array(); foreach ($evals as $eval) { $coursecode = $eval->get_course_code(); $courseInfo = api_get_course_info($coursecode); // evaluation in course if (isset($coursecode) && !empty($coursecode)) { if (!array_key_exists($coursecode, $coursecodes)) { $coursecodes[$coursecode] = '1'; $users = array_merge($users, get_users_in_course($courseInfo['real_id'])); } } else { // course independent evaluation $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_res = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); $sql = 'SELECT user.user_id,lastname, firstname, user.official_code FROM ' . $tbl_res . ' as res, ' . $tbl_user . ' as user WHERE res.evaluation_id = ' . intval($eval->get_id()) . ' AND res.user_id = user.user_id'; $result = Database::query($sql); $users = array_merge($users, get_user_array_from_sql_result($result)); } } foreach ($links as $link) { // links are always in a course $coursecode = $link->get_course_code(); $courseInfo = api_get_course_info($coursecode); if (!array_key_exists($coursecode, $coursecodes)) { $coursecodes[$coursecode] = '1'; $users = array_merge($users, get_users_in_course($courseInfo['real_id'])); } } unset($coursecodes); return $users; }
/** * @param int $userId * @param int $courseCode * @param int $sessionId * @param boolean $sendEmail Optional. Indicate whether the mail must be sent. Default is true * @return mixed */ public function saveUserLegal($userId, $courseCode, $sessionId, $sendEmail = true) { $courseInfo = api_get_course_info($courseCode); $courseId = $courseInfo['real_id']; $data = $this->getUserAcceptedLegal($userId, $courseId, $sessionId); $id = false; if (empty($data)) { $table = Database::get_main_table('session_rel_course_rel_user_legal'); $uniqueId = api_get_unique_id(); $values = array('user_id' => $userId, 'c_id' => $courseId, 'session_id' => $sessionId, 'web_agreement' => 1, 'web_agreement_date' => api_get_utc_datetime(), 'mail_agreement_link' => $uniqueId); $id = Database::insert($table, $values); if ($sendEmail) { $this->sendMailLink($uniqueId, $userId, $courseId, $sessionId); } } return $id; }