/** * Returns an array of objects of type CourseDescription corresponding to * a specific course, without session ids (session id = 0) * * @param int $course_id * * @return array Array of CourseDescriptions */ public static function get_descriptions($course_id) { // Get course code $course_info = api_get_course_info_by_id($course_id); if (!empty($course_info)) { $course_id = $course_info['real_id']; } else { return array(); } $t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION); $sql = "SELECT * FROM {$t_course_desc}\n WHERE c_id = {$course_id} AND session_id = '0'"; $sql_result = Database::query($sql); $results = array(); while ($row = Database::fetch_array($sql_result)) { $desc_tmp = new CourseDescription(); $desc_tmp->set_id($row['id']); $desc_tmp->set_title($row['title']); $desc_tmp->set_content($row['content']); $desc_tmp->set_session_id($row['session_id']); $desc_tmp->set_description_type($row['description_type']); $desc_tmp->set_progress($row['progress']); $results[] = $desc_tmp; } return $results; }
/** * 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 } }
/** * 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(); } }
/** * Constructor of the class * * @author Olivier Brouckaert */ public function __construct($course_id = null) { $this->id = 0; $this->exercise = ''; $this->description = ''; $this->sound = ''; $this->type = ALL_ON_ONE_PAGE; $this->random = 0; $this->random_answers = 0; $this->active = 1; $this->questionList = array(); $this->timeLimit = 0; $this->end_time = '0000-00-00 00:00:00'; $this->start_time = '0000-00-00 00:00:00'; $this->results_disabled = 1; $this->expired_time = '0000-00-00 00:00:00'; $this->propagate_neg = 0; $this->review_answers = false; $this->randomByCat = 0; $this->text_when_finished = ''; $this->display_category_name = 0; $this->pass_percentage = ''; if (!empty($course_id)) { $course_info = api_get_course_info_by_id($course_id); } else { $course_info = api_get_course_info(); } $this->course_id = $course_info['real_id']; $this->course = $course_info; $this->sessionId = api_get_session_id(); }
/** * @param array $options * * @return array */ public function get_all($options = array()) { $gradebooks = parent::get_all($options); foreach ($gradebooks as &$gradebook) { if (!empty($gradebook['name'])) { continue; } $courseInfo = api_get_course_info_by_id($gradebook['c_id']); $gradebook['name'] = $courseInfo['code']; } return $gradebooks; }
/** * Setting parameters: course id, session id, etc * @param array */ public function set_parameters($params = array()) { //Setting course id if (isset($params['course_id'])) { $this->course_id = intval($params['course_id']); } else { $this->course_id = $params['course_id'] = api_get_course_int_id(); } //Setting course info if (isset($this->course_id)) { $this->course_info = api_get_course_info_by_id($this->course_id); } //Setting session id if (isset($params['session_id'])) { $this->session_id = intval($params['session_id']); } else { $this->session_id = $params['session_id'] = api_get_session_id(); } //Setting user ids if (isset($params['user_id'])) { $this->user_id = intval($params['user_id']); } else { $this->user_id = $params['user_id'] = api_get_user_id(); } //Setting user ids if (isset($params['exercise_id'])) { $this->exercise_id = intval($params['exercise_id']); } else { $this->exercise_id = 0; } //Setting user ids if (isset($params['question_id'])) { $this->question_id = intval($params['question_id']); } else { $this->question_id = 0; } $this->can_edit = false; if (api_is_allowed_to_edit()) { $this->can_edit = true; } else { if ($this->user_id == api_get_user_id()) { $this->can_edit = true; } } //Settings the params array $this->params = $params; $this->store_path = api_get_path(SYS_COURSE_PATH) . $this->course_info['path'] . '/exercises/'; $this->create_user_folder(); $this->store_path = $this->store_path . implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)) . '/'; $this->filename = $this->generate_filename(); $this->store_filename = $this->store_path . $this->filename; }
/** * @param int $courseId * @param int $announcement */ public function __construct($courseId, $announcement) { if (!empty($courseId)) { $course = api_get_course_info_by_id($courseId); } else { $course = api_get_course_info(); } $this->course = $course; $this->session_id = api_get_session_id(); if (is_numeric($announcement)) { $announcement = AnnouncementManager::get_by_id($course['real_id'], $announcement); } $this->announcement = $announcement; }
/** * * @param int $c_id * @param string $sub_path * @return FileStore */ static function course($c_id, $sub_path = '') { $sys_path = api_get_path(SYS_COURSE_PATH); $course = api_get_course_info_by_id($c_id); $course_path = $course['path']; $path = $sys_path . $course_path . $sub_path; if (!is_dir($path)) { $mode = api_get_permissions_for_new_directories(); $success = mkdir($path, $mode, true); if (!$success) { return false; } } return new self($path); }
/** * 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; }
/** * @Route("/editor/connector", name="editor_connector") * @Method({"GET|POST"}) */ public function editorConnector(Request $request) { error_reporting(-1); $courseId = $request->get('course_id'); $sessionId = $request->get('session_id'); $courseInfo = []; if (!empty($courseId)) { $courseInfo = api_get_course_info_by_id($courseId); } /** @var Connector $connector */ $connector = new Connector($this->container->get('doctrine')->getManager(), [], $this->container->get('router'), $this->container->get('translator.default'), $this->container->get('security.context'), $this->getUser(), $courseInfo); $driverList = array('PersonalDriver', 'CourseDriver'); $connector->setDriverList($driverList); $operations = $connector->getOperations(); // Run elFinder ob_start(); $finder = new Finder($operations); $elFinderConnector = new ElFinderConnector($finder); $elFinderConnector->run(); $content = ob_get_contents(); return $this->render('@ChamiloCore/layout_empty.html.twig', ['content' => $content]); }
/** * */ function sync() { $tableBuySessionRelCourse = Database::get_main_table(TABLE_BUY_SESSION_COURSE); $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $sql = "UPDATE {$tableBuySessionRelCourse} SET sync = 0"; Database::query($sql); $sql = "SELECT session_id, c_id, nbr_users FROM {$tableSessionRelCourse}"; $res = Database::query($sql); while ($row = Database::fetch_assoc($res)) { $sql = "SELECT 1 FROM {$tableBuySessionRelCourse} WHERE session_id=" . $row['session_id']; $result = Database::query($sql); if (Database::affected_rows($result) > 0) { $sql = "UPDATE {$tableBuySessionRelCourse} SET sync = 1 WHERE session_id=" . $row['session_id']; Database::query($sql); } else { $courseCode = api_get_course_info_by_id($row['c_id'])['code']; $sql = "INSERT INTO {$tableBuySessionRelCourse} (session_id, course_code, nbr_users, sync)\r\n VALUES (" . $row['session_id'] . ", '" . $courseCode . "', " . $row['nbr_users'] . ", 1);"; Database::query($sql); } } $sql = "DELETE FROM {$tableBuySessionRelCourse} WHERE sync = 0;"; Database::query($sql); $tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE); $tableCourse = Database::get_main_table(TABLE_MAIN_COURSE); $sql = "UPDATE {$tableBuyCourse} SET sync = 0"; Database::query($sql); $sql = "SELECT id, code, title FROM {$tableCourse}"; $res = Database::query($sql); while ($row = Database::fetch_assoc($res)) { $sql = "SELECT session_id FROM {$tableBuySessionRelCourse}\r\n WHERE course_code = '" . $row['code'] . "' LIMIT 1"; $courseIdSession = Database::fetch_assoc(Database::query($sql))['session_id']; if (!is_numeric($courseIdSession)) { $courseIdSession = 0; } $sql = "SELECT 1 FROM {$tableBuyCourse} WHERE course_id='" . $row['id'] . "';"; $result = Database::query($sql); if (Database::affected_rows($result) > 0) { $sql = "UPDATE {$tableBuyCourse} SET sync = 1, session_id = {$courseIdSession} WHERE course_id='" . $row['id'] . "';"; Database::query($sql); } else { $sql = "INSERT INTO {$tableBuyCourse} (session_id, course_id, code, title, visible, sync)\r\n VALUES ('" . $courseIdSession . "', '" . $row['id'] . "', '" . $row['code'] . "', '" . $row['title'] . "', 0, 1);"; Database::query($sql); } } $sql = "DELETE FROM {$tableBuyCourse} WHERE sync = 0;"; Database::query($sql); $tableBuySession = Database::get_main_table(TABLE_BUY_SESSION); $tableSession = Database::get_main_table(TABLE_MAIN_SESSION); $sql = "UPDATE {$tableBuySession} SET sync = 0"; Database::query($sql); $sql = "SELECT id, name, access_start_date, access_end_date FROM {$tableSession}"; $res = Database::query($sql); while ($row = Database::fetch_assoc($res)) { $sql = "SELECT 1 FROM {$tableBuySession} WHERE session_id='" . $row['id'] . "';"; $result = Database::query($sql); if (Database::affected_rows($result) > 0) { $sql = "UPDATE {$tableBuySession} SET sync = 1 WHERE session_id='" . $row['id'] . "';"; Database::query($sql); } else { $sql = "INSERT INTO {$tableBuySession} (session_id, name, date_start, date_end, visible, sync)\r\n VALUES ('" . $row['id'] . "', '" . $row['name'] . "', '" . $row['access_start_date'] . "', '" . $row['access_end_date'] . "', 0, 1);"; Database::query($sql); } } $sql = "DELETE FROM {$tableBuySession} WHERE sync = 0;"; Database::query($sql); }
cu.c_id = c.id AND cu.relation_type <> ' . COURSE_RELATION_TYPE_RRHH . ' '; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $header = array(array(get_lang('Code'), true), array(get_lang('Title'), true), array(get_lang('Status'), true), array(get_lang('TimeSpentInTheCourse'), true), array(get_lang('TotalPostsInAllForums'), true), array('', false)); $headerList = array(); foreach ($header as $item) { $headerList[] = $item[0]; } $csvContent[] = array(); $csvContent[] = array(get_lang('Courses')); $csvContent[] = $headerList; $data = array(); $courseToolInformationTotal = null; while ($course = Database::fetch_object($res)) { $courseInfo = api_get_course_info_by_id($course->c_id); $courseCode = $courseInfo['code']; $courseToolInformation = null; $tools = '<a href="course_information.php?code=' . $courseCode . '">' . Display::return_icon('synthese_view.gif', get_lang('Overview')) . '</a>' . '<a href="' . $courseInfo['course_public_url'] . '">' . Display::return_icon('course_home.gif', get_lang('CourseHomepage')) . '</a>' . '<a href="course_edit.php?course_code=' . $courseCode . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; if ($course->status == STUDENT) { $tools .= '<a href="user_information.php?action=unsubscribe&course_code=' . $courseCode . '&user_id=' . $user['user_id'] . '">' . Display::return_icon('delete.png', get_lang('Delete')) . '</a>'; } $timeSpent = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseInfo['real_id'], 0)); $totalForumMessages = CourseManager::getCountPostInForumPerUser($user['user_id'], $course->id, 0); $row = array(Display::url($courseCode, $courseInfo['course_public_url']), $course->title, $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'), $timeSpent, $totalForumMessages, $tools); $csvContent[] = array_map('strip_tags', $row); $data[] = $row; $result = TrackingUserLogCSV::getToolInformation($user['user_id'], $courseInfo, 0); $courseToolInformationTotal .= $result['html']; $csvContent = array_merge($csvContent, $result['array']); }
/** * Displays the student publications for a specific user in a specific course. * @todo remove globals */ public function display_student_publications_tracking_info($view, $user_id, $course_id) { global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK; $_course = api_get_course_info_by_id($course_id); if (substr($view, 2, 1) == '1') { $new_view = substr_replace($view, '0', 2, 1); echo "<tr>\n <td valign='top'>\n <font color='#0000FF'>- </font><b>" . get_lang('WorkUploads') . "</b> [<a href='" . api_get_self() . "?uInfo=" . Security::remove_XSS($user_id) . "&view=" . Security::remove_XSS($new_view) . "'>" . get_lang('Close') . "</a>] [<a href='userLogCSV.php?" . api_get_cidreq() . "&uInfo=" . Security::remove_XSS($_GET['uInfo']) . "&view=00100'>" . get_lang('ExportAsCSV') . "</a>]\n </td>\n </tr>"; echo "<tr><td style='padding-left : 40px;' valign='top'>" . get_lang('WorksDetails') . "<br>"; $sql = "SELECT u.upload_date, w.title, w.author,w.url\n FROM {$TABLETRACK_UPLOADS} u , {$TABLECOURSE_WORK} w\n WHERE u.upload_work_id = w.id\n AND u.upload_user_id = '" . intval($user_id) . "'\n AND u.c_id = '" . intval($course_id) . "'\n ORDER BY u.upload_date DESC"; echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>"; $results = StatsUtils::getManyResultsXCol($sql, 4); echo "<table cellpadding='2' cellspacing='1' border='0' align=center>"; echo "<tr>\n <td class='secLine' width='40%'>\n " . get_lang('WorkTitle') . "\n </td>\n <td class='secLine' width='30%'>\n " . get_lang('WorkAuthors') . "\n </td>\n <td class='secLine' width='30%'>\n " . get_lang('Date') . "\n </td>\n </tr>"; if (is_array($results)) { for ($j = 0; $j < count($results); $j++) { $pathToFile = api_get_path(WEB_COURSE_PATH) . $_course['path'] . "/" . $results[$j][3]; $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get()); echo "<tr>"; echo "<td class='content'>" . "<a href ='" . $pathToFile . "'>" . $results[$j][1] . "</a>" . "</td>"; echo "<td class='content'>" . $results[$j][2] . "</td>"; echo "<td class='content'>" . $beautifulDate . "</td>"; echo "</tr>"; } } else { echo "<tr>"; echo "<td colspan='3'><center>" . get_lang('NoResult') . "</center></td>"; echo "</tr>"; } echo "</table>"; echo "</td></tr>"; } else { $new_view = substr_replace($view, '1', 2, 1); echo "\n <tr>\n <td valign='top'>\n +<font color='#0000FF'> </font><a href='" . api_get_self() . "?uInfo=" . Security::remove_XSS($user_id) . "&view=" . Security::remove_XSS($new_view) . "' class='specialLink'>" . get_lang('WorkUploads') . "</a>\n </td>\n </tr>\n "; } }
api_protect_course_script(true); // Configuration settings $display_announcement_list = true; $display_form = false; $display_title_list = true; // Maximum title messages to display $maximum = '12'; // Length of the titles $length = '36'; // Database Table Definitions $tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_id = api_get_course_int_id(); $_course = api_get_course_info_by_id($course_id); $group_id = api_get_group_id(); $sessionId = api_get_session_id(); api_protect_course_group(GroupManager::GROUP_TOOL_ANNOUNCEMENT); /* Tracking */ Event::event_access_tool(TOOL_ANNOUNCEMENT); $announcement_id = isset($_GET['id']) ? intval($_GET['id']) : null; $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null; $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'list'; $announcement_number = AnnouncementManager::getNumberAnnouncements(); $homeUrl = api_get_self() . '?action=list&' . api_get_cidreq(); $content = ''; $searchFormToString = ''; switch ($action) { case 'move': /* Move announcement up/down */
/** * Modify category name or description of category with id=in_id */ public function modifyCategory() { $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $v_id = intval($this->id); $v_name = Database::escape_string($this->name); $v_description = Database::escape_string($this->description); $sql = "UPDATE {$table} SET\n title = '{$v_name}',\n description = '{$v_description}'\n WHERE id = {$v_id} AND c_id=" . api_get_course_int_id(); $result = Database::query($sql); if (Database::affected_rows($result) <= 0) { return false; } else { // item_property update $course_id = api_get_course_int_id(); $course_info = api_get_course_info_by_id($course_id); api_item_property_update($course_info, TOOL_TEST_CATEGORY, $this->id, 'TestCategoryModified', api_get_user_id()); return true; } }
/** * Shows statistics about the time of last visit to each course. */ public static function printCourseLastVisit() { $access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $current_url_id = api_get_current_access_url_id(); $columns[0] = 'c_id'; $columns[1] = 'access_date'; $sql_order[SORT_ASC] = 'ASC'; $sql_order[SORT_DESC] = 'DESC'; $per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 10; $page_nr = isset($_GET['page_nr']) ? intval($_GET['page_nr']) : 1; $column = isset($_GET['column']) ? intval($_GET['column']) : 0; $date_diff = isset($_GET['date_diff']) ? intval($_GET['date_diff']) : 60; $direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC; if (!in_array($direction, array(SORT_ASC, SORT_DESC))) { $direction = SORT_ASC; } $form = new FormValidator('courselastvisit', 'get'); $form->addElement('hidden', 'report', 'courselastvisit'); $form->addText('date_diff', get_lang('Days'), true); $form->addRule('date_diff', 'InvalidNumber', 'numeric'); $form->addButtonSearch(get_lang('Search'), 'submit'); if (!isset($_GET['date_diff'])) { $defaults['date_diff'] = 60; } else { $defaults['date_diff'] = Security::remove_XSS($_GET['date_diff']); } $form->setDefaults($defaults); $form->display(); $values = $form->exportValues(); $date_diff = $values['date_diff']; $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); if (api_is_multiple_url_enabled()) { $sql = "SELECT * FROM {$table} t , {$access_url_rel_course_table} a\n WHERE\n t.c_id = a.c_id AND\n access_url_id='" . $current_url_id . "'\n GROUP BY c_id\n HAVING c_id <> ''\n AND DATEDIFF( '" . date('Y-m-d h:i:s') . "' , access_date ) <= " . $date_diff; } else { $sql = "SELECT * FROM {$table}\n GROUP BY c_id\n HAVING c_id <> ''\n AND DATEDIFF( '" . date('Y-m-d h:i:s') . "' , access_date ) <= " . $date_diff; } $sql .= ' ORDER BY ' . $columns[$column] . ' ' . $sql_order[$direction]; $from = ($page_nr - 1) * $per_page; $sql .= ' LIMIT ' . $from . ',' . $per_page; echo '<p>' . get_lang('LastAccess') . ' >= ' . $date_diff . ' ' . get_lang('Days') . '</p>'; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $courses = array(); while ($obj = Database::fetch_object($res)) { $courseInfo = api_get_course_info_by_id($obj->c_id); if (empty($courseInfo)) { continue; } $course = array(); $course[] = '<a href="' . api_get_path(WEB_COURSE_PATH) . $courseInfo['code'] . '">' . $courseInfo['code'] . ' <a>'; // Allow sort by date hiding the numerical date $course[] = '<span style="display:none;">' . $obj->access_date . '</span>' . api_convert_and_format_date($obj->access_date); $courses[] = $course; } $parameters['date_diff'] = $date_diff; $parameters['report'] = 'courselastvisit'; $table_header[] = array(get_lang("CourseCode"), true); $table_header[] = array(get_lang("LastAccess"), true); Display::display_sortable_table($table_header, $courses, array('column' => $column, 'direction' => $direction), array(), $parameters); } else { echo get_lang('NoSearchResults'); } }
/** * Get personal agenda items between two dates (=all events from all registered courses) * @param int user ID of the user * @param string Optional start date in datetime format (if no start date is given, uses today) * @param string Optional end date in datetime format (if no date is given, uses one year from now) * @return array Array of events ordered by start date, in * [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, * where datestart and dateend are in yyyyMMddhhmmss format. * @TODO Implement really personal events (from user DB) and global events (from main DB) */ public static function get_personal_agenda_items_between_dates($user_id, $date_start = '', $date_end = '') { $items = array(); if ($user_id != strval(intval($user_id))) { return $items; } if (empty($date_start)) { $date_start = date('Y-m-d H:i:s'); } if (empty($date_end)) { $date_end = date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1)); } $expr = '/\\d{4}-\\d{2}-\\d{2}\\ \\d{2}:\\d{2}:\\d{2}/'; if (!preg_match($expr, $date_start)) { return $items; } if (!preg_match($expr, $date_end)) { return $items; } // get agenda-items for every course $courses = api_get_user_courses($user_id, false); foreach ($courses as $id => $course) { $c = api_get_course_info_by_id($course['real_id']); //databases of the courses $t_a = Database::get_course_table(TABLE_AGENDA, $course['db']); $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course['db']); // get the groups to which the user belong $group_memberships = GroupManager::get_group_ids($course['db'], $user_id); // if the user is administrator of that course we show all the agenda items if ($course['status'] == '1') { //echo "course admin"; $sqlquery = "SELECT " . " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref " . " FROM " . $t_a . " agenda, " . $t_ip . " ip " . " WHERE agenda.id = ip.ref " . " AND agenda.start_date>='{$date_start}' " . " AND agenda.end_date<='{$date_end}' " . " AND ip.tool='" . TOOL_CALENDAR_EVENT . "' " . " AND ip.visibility='1' " . " GROUP BY agenda.id " . " ORDER BY start_date "; } else { // if the user is not an administrator of that course, then... if (is_array($group_memberships) && count($group_memberships) > 0) { $sqlquery = "SELECT " . "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref " . " FROM " . $t_a . " agenda, " . $t_ip . " ip " . " WHERE agenda.id = ip.ref " . " AND agenda.start_date>='{$date_start}' " . " AND agenda.end_date<='{$date_end}' " . " AND ip.tool='" . TOOL_CALENDAR_EVENT . "' " . " AND\t( ip.to_user_id='" . $user_id . "' OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ) " . " AND ip.visibility='1' " . " ORDER BY start_date "; } else { $sqlquery = "SELECT " . "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref " . " FROM " . $t_a . " agenda, " . $t_ip . " ip " . " WHERE agenda.id = ip.ref " . " AND agenda.start_date>='{$date_start}' " . " AND agenda.end_date<='{$date_end}' " . " AND ip.tool='" . TOOL_CALENDAR_EVENT . "' " . " AND ( ip.to_user_id='" . $user_id . "' OR ip.to_group_id='0' OR ip.to_group_id IS NULL) " . " AND ip.visibility='1' " . " ORDER BY start_date "; } } $result = Database::query($sqlquery); while ($item = Database::fetch_array($result)) { $agendaday = date("j", strtotime($item['start_date'])); $month = date("n", strtotime($item['start_date'])); $year = date("Y", strtotime($item['start_date'])); $URL = api_get_path(WEB_PATH) . "main/calendar/agenda.php?cidReq=" . urlencode($course["code"]) . "&day={$agendaday}&month={$month}&year={$year}#{$agendaday}"; list($year, $month, $day, $hour, $min, $sec) = split('[-: ]', $item['start_date']); $start_date = $year . $month . $day . $hour . $min; list($year, $month, $day, $hour, $min, $sec) = split('[-: ]', $item['end_date']); $end_date = $year . $month . $day . $hour . $min; $items[] = array('datestart' => $start_date, 'dateend' => $end_date, 'title' => $item['title'], 'link' => $URL, 'coursetitle' => $c['name']); } } return $items; }
/** * @param string $exercisePath * @param int $userId * @param int $courseId * @param int $sessionId * * @return array */ public static function getLatestHotPotatoResult($exercisePath, $userId, $courseId, $sessionId) { $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $courseInfo = api_get_course_info_by_id($courseId); $exercisePath = Database::escape_string($exercisePath); $userId = intval($userId); $sql = "SELECT * FROM {$table}\n WHERE\n c_id = {$courseId} AND\n exe_name LIKE '{$exercisePath}%' AND\n exe_user_id = {$userId}\n ORDER BY id\n LIMIT 1"; $result = Database::query($sql); $attempt = array(); if (Database::num_rows($result)) { $attempt = Database::fetch_array($result, 'ASSOC'); } return $attempt; }
/** * 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(); $inserted_in_course = array(); foreach ($users_courses as $user_course) { $csv_data[$user_course['Email']][$user_course['CourseCode']] = $user_course['Status']; } foreach ($csv_data as $email => $csv_subscriptions) { $sql = "SELECT * FROM {$user_table} u\n WHERE u.email = '" . Database::escape_string($email) . "' LIMIT 1"; $res = Database::query($sql); $obj = Database::fetch_object($res); $user_id = $obj->user_id; $sql = "SELECT * FROM {$course_user_table} cu\n 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; } $to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions)); $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions)); if ($_POST['subscribe']) { foreach ($to_subscribe as $courseId) { $courseInfo = api_get_course_info_by_id($courseId); $course_code = $courseInfo['code']; if (CourseManager::course_exists($course_code)) { $course_info = CourseManager::get_course_information($course_code); $inserted_in_course[$course_code] = $course_info['title']; CourseManager::subscribe_user($user_id, $course_code, $csv_subscriptions[$course_code]); $inserted_in_course[$course_info['code']] = $course_info['title']; } } } if ($_POST['unsubscribe']) { foreach ($to_unsubscribe as $courseId) { $courseInfo = api_get_course_info_by_id($courseId); $course_code = $courseInfo['code']; if (CourseManager::course_exists($course_code)) { CourseManager::unsubscribe_user($user_id, $course_code); $course_info = CourseManager::get_course_information($course_code); CourseManager::unsubscribe_user($user_id, $course_code); $inserted_in_course[$course_info['code']] = $course_info['title']; } } } } return $inserted_in_course; }
if (!empty($exercises[$cnt - 4]['title'])) { $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title']))); } $columns[] = 'exer' . $i; $column_names[] = $title; $i++; break; } } $quizIds = array(); if (!empty($exercises)) { foreach ($exercises as $exercise) { $quizIds[] = $exercise['id']; } } $course = api_get_course_info_by_id($_GET['course_id']); $listUserSess = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']); $usersId = array_keys($listUserSess); $users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "{$start} , {$limit}"); $exeResults = $objExercise->getExerciseAndResult($_GET['course_id'], $_GET['session_id'], $quizIds); $arrGrade = array(); foreach ($exeResults as $exeResult) { $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result']; } $result = array(); $i = 0; foreach ($users as $user) { $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']); $result[$i]['session'] = $sessionInfo['name']; $result[$i]['username'] = $user['username']; $result[$i]['name'] = $user['lastname'] . " " . $user['firstname'];
/** * @param string $file * @param bool $moveFile * * @return int */ private function importCalendarStatic($file, $moveFile = true) { $data = Import::csv_to_array($file); if (!empty($data)) { $this->logger->addInfo(count($data) . " records found."); $eventsToCreate = array(); $errorFound = false; foreach ($data as $row) { $sessionId = null; $externalSessionId = null; if (isset($row['external_sessionID'])) { $externalSessionId = $row['external_sessionID']; $sessionId = SessionManager::get_session_id_from_original_id($externalSessionId, $this->extraFieldIdNameList['session']); } $courseCode = null; if (isset($row['coursecode'])) { $courseCode = $row['coursecode']; } $courseInfo = api_get_course_info($courseCode); if (empty($courseInfo)) { $this->logger->addInfo("Course '{$courseCode}' does not exists"); } if (empty($sessionId)) { $this->logger->addInfo("external_sessionID: " . $externalSessionId . " does not exists."); } $teacherId = null; if (!empty($sessionId) && !empty($courseInfo)) { $courseIncluded = SessionManager::relation_session_course_exist($sessionId, $courseInfo['code']); if ($courseIncluded == false) { $this->logger->addInfo("Course '{$courseCode}' is not included in session: {$sessionId}"); $errorFound = true; } else { $teachers = CourseManager::get_coach_list_from_course_code($courseInfo['code'], $sessionId); // Getting first teacher. if (!empty($teachers)) { $teacher = current($teachers); $teacherId = $teacher['user_id']; } else { $sessionInfo = api_get_session_info($sessionId); $teacherId = $sessionInfo['id_coach']; } } } else { $errorFound = true; } if (empty($teacherId)) { $errorFound = true; $this->logger->addInfo("No teacher found in course code : '{$courseCode}' and session: '{$sessionId}'"); } $date = $row['date']; $startTime = $row['time_start']; $endTime = $row['time_end']; $title = $row['title']; $comment = $row['comment']; $color = isset($row['color']) ? $row['color'] : ''; $startDateYear = substr($date, 0, 4); $startDateMonth = substr($date, 4, 2); $startDateDay = substr($date, 6, 8); $startDate = $startDateYear . '-' . $startDateMonth . '-' . $startDateDay . ' ' . $startTime . ":00"; $endDate = $startDateYear . '-' . $startDateMonth . '-' . $startDateDay . ' ' . $endTime . ":00"; if (!api_is_valid_date($startDate) || !api_is_valid_date($endDate)) { $this->logger->addInfo("Verify your dates: '{$startDate}' : '{$endDate}' "); $errorFound = true; } // If old events do nothing. /*if (api_strtotime($startDate) < time()) { continue; }*/ if ($errorFound == false) { $eventsToCreate[] = array('start' => $startDate, 'end' => $endDate, 'title' => $title, 'sender_id' => $teacherId, 'course_id' => $courseInfo['real_id'], 'session_id' => $sessionId, 'comment' => $comment, 'color' => $color, $this->extraFieldIdNameList['calendar_event'] => $row['external_calendar_itemID']); } } if (empty($eventsToCreate)) { $this->logger->addInfo("No events to add"); return 0; } $this->logger->addInfo("Ready to insert events"); $agenda = new Agenda(); $extraFieldValue = new ExtraFieldValue('calendar_event'); $extraFieldName = $this->extraFieldIdNameList['calendar_event']; $externalEventId = null; $extraField = new ExtraField('calendar_event'); $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable($extraFieldName); if (empty($extraFieldInfo)) { $this->logger->addInfo("No calendar event extra field created: {$extraFieldName}"); return 0; } foreach ($eventsToCreate as $event) { $update = false; $item = null; if (!isset($event[$extraFieldName])) { $this->logger->addInfo("No external_calendar_itemID found. Skipping ..."); continue; } else { $externalEventId = $event[$extraFieldName]; if (empty($externalEventId)) { $this->logger->addInfo("external_calendar_itemID was set but empty. Skipping ..."); continue; } $items = $extraFieldValue->get_item_id_from_field_variable_and_field_value($extraFieldName, $externalEventId, false, false, true); $item = null; foreach ($items as $tempItem) { if ($tempItem['c_id'] == $event['course_id']) { $item = $tempItem; } } if (!empty($item)) { $this->logger->addInfo("Event #{$externalEventId} was already added. Updating ..."); $update = true; //continue; } } $courseInfo = api_get_course_info_by_id($event['course_id']); $agenda->set_course($courseInfo); $agenda->setType('course'); $agenda->setSessionId($event['session_id']); $agenda->setSenderId($event['sender_id']); $agenda->setIsAllowedToEdit(true); $eventComment = $event['comment']; $color = $event['color']; // To use the event comment you need // ALTER TABLE c_calendar_event ADD COLUMN comment TEXT; // add in configuration.php allow_agenda_event_comment = true if (empty($courseInfo)) { $this->logger->addInfo("No course found for added: #" . $event['course_id'] . " Skipping ..."); continue; } if (empty($event['sender_id'])) { $this->logger->addInfo("No sender found: #" . $event['sender_id'] . " Skipping ..."); continue; } $content = ''; if ($update && isset($item['calendar_event_id'])) { //the event already exists, just update $eventId = $agenda->edit_event($item['calendar_event_id'], $event['start'], $event['end'], false, $event['title'], $content, array('everyone'), array(), null, $eventComment, $color); if ($eventId !== false) { $this->logger->addInfo("Event updated: #{$eventId}"); } else { $this->logger->addInfo("Error while updating event."); } } else { // New event. Create it. $eventId = $agenda->add_event($event['start'], $event['end'], false, $event['title'], $content, array('everyone'), false, null, array(), null, $eventComment, $color); if (!empty($eventId)) { $extraFieldValue->is_course_model = true; $extraFieldValue->save(array('field_value' => $externalEventId, 'field_id' => $extraFieldInfo['id'], 'calendar_event_id' => $eventId, 'c_id' => $event['course_id'])); $this->logger->addInfo("Event added: #{$eventId}"); } else { $this->logger->addInfo("Error while creating event."); } } } } if ($moveFile) { $this->moveFile($file); } }
if (api_is_platform_admin()) { $courseInfo = api_get_course_info(); if (!empty($course_list)) { $courseIdList = array_keys($course_list); if (!in_array($courseInfo['real_id'], $courseIdList)) { $course_list = array_merge($course_list, array($courseInfo)); } } else { $course_list = array($courseInfo); } } } $course_select_list = array(); foreach ($course_list as $item) { $courseItemId = $item['real_id']; $courseInfo = api_get_course_info_by_id($courseItemId); $course_select_list[$courseItemId] = ""; if ($courseItemId == api_get_course_int_id()) { $course_select_list[$courseItemId] = "> "; } $course_select_list[$courseItemId] .= $courseInfo['title']; } $select_course_html = Display::select('selected_course', $course_select_list, $selected_course, array('class' => 'chzn-select', 'onchange' => 'mark_course_id_changed(); submit_form(this);')); echo Display::form_row(get_lang('Course'), $select_course_html); if (empty($selected_course) || $selected_course == '-1') { $course_info = api_get_course_info(); // no course selected, reset menu test / difficult� / type de reponse reset_menu_exo_lvl_type(); } else { $course_info = CourseManager::get_course_information_by_id($selected_course); }
$new_course_list[] = $course_reg['code'] . '_' . $course_reg['session_id']; } $course_list = get_courses_list_by_user_id_based_in_exercises($user_id); if (is_array($course_list) && !empty($course_list)) { foreach ($course_list as $my_course) { $courseInfo = api_get_course_info_by_id($my_course['c_id']); $my_course['real_id'] = $my_course['c_id']; $key = $courseInfo['code'] . '_' . $my_course['session_id']; if (!in_array($key, $new_course_list)) { $my_course['not_registered'] = 1; $course_list_registered[] = $my_course; } } } foreach ($course_list_registered as &$course) { $courseInfo = api_get_course_info_by_id($course['real_id']); $course['name'] = $courseInfo['name']; } $course_list = $course_list_registered; echo '<div>'; echo '<table class="data_table">'; echo '<tr>'; echo '<th style="text-align:left;" colspan="' . count($course_list) . '">'; echo "<h3>{$name} #{$user_id} </h3> "; echo '</th>'; echo '</tr>'; if (!empty($course_list)) { echo '<tr>'; foreach ($course_list as $course) { echo '<td>'; if (isset($course['id_session']) && !empty($course['id_session'])) {
/** * @param $course_id */ public function updateCourse($course_id) { $this->course = api_get_course_info_by_id($course_id); }
*/ $cidReset = true; require_once '../../../main/inc/global.inc.php'; api_protect_admin_script(true); $plugin = BuyCoursesPlugin::create(); $paypalEnable = $plugin->get('paypal_enable'); $commissionsEnable = $plugin->get('commissions_enable'); $action = isset($_GET['a']) ? $_GET['a'] : null; switch ($action) { case 'saleInfo': //$saleId is only used in getSale() and is always filtered there $saleId = isset($_POST['id']) ? $_POST['id'] : ''; $sale = $plugin->getSale($saleId); $productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session'); $paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer'); $productInfo = $sale['product_type'] == 1 ? api_get_course_info_by_id($sale['product_id']) : api_get_session_info($sale['product_id']); $currency = $plugin->getSelectedCurrency(); if ($sale['product_type'] == 1) { $productImage = $productInfo['course_image_large']; } else { $productImage = $productInfo['image'] ? $productInfo['image'] : Template::get_icon_path('session_default.png'); } $userInfo = api_get_user_info($sale['user_id']); $html = '<h2>' . $sale['product_name'] . '</h2>'; $html .= '<div class="row">'; $html .= '<div class="col-sm-6 col-md-6">'; $html .= '<ul>'; $html .= '<li><b>' . $plugin->get_lang('OrderPrice') . ':</b> ' . $sale['price'] . '</li>'; $html .= '<li><b>' . $plugin->get_lang('CurrencyType') . ':</b> ' . $currency['iso_code'] . '</li>'; $html .= '<li><b>' . $plugin->get_lang('ProductType') . ':</b> ' . $productType . '</li>'; $html .= '<li><b>' . $plugin->get_lang('OrderDate') . ':</b> ' . api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H) . '</li>';
/** * Publishes a learnpath. This basically means show or hide the learnpath * to normal users. * Can be used as abstract * @param integer Learnpath ID * @param string New visibility */ public function toggle_visibility($lp_id, $set_visibility = 1, $course_id = null) { //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); } $action = 'visible'; if ($set_visibility != 1) { $action = 'invisible'; } if (!empty($course_id)) { $course = api_get_course_info_by_id($course_id); } else { $course = api_get_course_info(); } return api_item_property_update($course, TOOL_LEARNPATH, $lp_id, $action, api_get_user_id()); }
/** * Subscribe users to a group * @param int $usergroup_id usergroup id * @param array $list list of user ids * * @param bool $delete_users_not_present_in_list * @param array $relationType */ public function subscribe_users_to_usergroup($usergroup_id, $list, $delete_users_not_present_in_list = true, $relationType = '') { $current_list = self::get_users_by_usergroup($usergroup_id); $course_list = self::get_courses_by_usergroup($usergroup_id); $session_list = self::get_sessions_by_usergroup($usergroup_id); $delete_items = array(); $new_items = array(); if (!empty($list)) { foreach ($list as $user_id) { if (!in_array($user_id, $current_list)) { $new_items[] = $user_id; } } } if (!empty($current_list)) { foreach ($current_list as $user_id) { if (!in_array($user_id, $list)) { $delete_items[] = $user_id; } } } // Deleting items if (!empty($delete_items) && $delete_users_not_present_in_list) { foreach ($delete_items as $user_id) { // Removing courses if (!empty($course_list)) { foreach ($course_list as $course_id) { $course_info = api_get_course_info_by_id($course_id); CourseManager::unsubscribe_user($user_id, $course_info['code']); } } // Removing sessions if (!empty($session_list)) { foreach ($session_list as $session_id) { SessionManager::unsubscribe_user_from_session($session_id, $user_id); } } Database::delete($this->usergroup_rel_user_table, array('usergroup_id = ? AND user_id = ? AND relation_type = ?' => array($usergroup_id, $user_id, $relationType))); } } // Adding new relationships if (!empty($new_items)) { // Adding sessions if (!empty($session_list)) { foreach ($session_list as $session_id) { SessionManager::suscribe_users_to_session($session_id, $new_items, null, false); } } foreach ($new_items as $user_id) { // Adding courses if (!empty($course_list)) { foreach ($course_list as $course_id) { $course_info = api_get_course_info_by_id($course_id); CourseManager::subscribe_user($user_id, $course_info['code']); } } $params = array('user_id' => $user_id, 'usergroup_id' => $usergroup_id, 'relation_type' => $relationType); Database::insert($this->usergroup_rel_user_table, $params); } } }
} else { exit; } } elseif ($is_allowed_to_edit || is_my_shared_folder(api_get_user_id(), $_POST['curdirpath'], api_get_session_id())) { } else { // No course admin and no group member... exit; } if (!empty($_FILES)) { $file = $_FILES['file']; $result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $file['name'], null, 0, 'overwrite', false, false); $json = array(); $json['name'] = Display::url(api_htmlentities($file['name']), api_htmlentities($result['url']), array('target' => '_blank')); $json['type'] = api_htmlentities($file['type']); $json['size'] = Text::format_file_size($file['size']); if (!empty($result) && is_array($result)) { $json['result'] = Display::return_icon('accept.png', get_lang('Uploaded')); } else { $json['result'] = Display::return_icon('exclamation.png', get_lang('Error')); } echo json_encode($json); } break; case 'document_preview': $course_info = api_get_course_info_by_id($_REQUEST['course_id']); if (!empty($course_info) && is_array($course_info)) { echo DocumentManager::get_document_preview($course_info, false, '_blank', $_REQUEST['session_id']); } break; } exit;
/** * @param int $courseId * @param int $sessionId * * @return string */ public function getCurrentFile($courseId, $sessionId) { $data = $this->getData($courseId, $sessionId); if (isset($data['filename']) && !empty($data['filename'])) { $course = api_get_course_info_by_id($courseId); $coursePath = api_get_path(SYS_COURSE_PATH) . $course['directory'] . '/courselegal'; $file = $coursePath . '/' . $data['filename']; if (file_exists($file)) { return Display::url($data['filename'], api_get_path(WEB_COURSE_PATH) . $course['directory'] . '/courselegal/' . $data['filename'], array('target' => '_blank')); } } }
} // destruction of the Question object unset($objQuestionTmp); if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } // adds the question ID represented by $recup into the list of questions for the current exercise $objExercise->addToList($recup); Session::write('objExercise', $objExercise); } else { if (isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) { $list_recup = $_POST['recup']; foreach ($list_recup as $course_id => $question_data) { $origin_course_id = intval($course_id); $origin_course_info = api_get_course_info_by_id($origin_course_id); $current_course = api_get_course_info(); foreach ($question_data as $old_question_id) { //Reading the source question $old_question_obj = Question::read($old_question_id, $origin_course_id); if ($old_question_obj) { $old_question_obj->updateTitle($old_question_obj->selectTitle() . ' - ' . get_lang('Copy')); //Duplicating the source question, in the current course $new_id = $old_question_obj->duplicate($current_course); //Reading new question $new_question_obj = Question::read($new_id); $new_question_obj->addToList($fromExercise); //Reading Answers obj of the current course $new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj->read(); //Duplicating the Answers in the current course