/**
  * @Route("/edit/{tool}")
  * @Method({"GET"})
  *
  * @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('introduction.controller:editAction', array('tool' => $tool, 'course' => api_get_course_id()));
     $form = $this->getForm($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');
     return new Response($response, 200, array());
 }
 /**
  * Sets the surveylist and the plainsurveylist
  */
 public function __construct()
 {
     // Database table definitions
     $table_survey = Database::get_course_table(TABLE_SURVEY);
     $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
     $table_user = Database::get_main_table(TABLE_MAIN_USER);
     // searching
     $search_restriction = SurveyUtil::survey_search_restriction();
     if ($search_restriction) {
         $search_restriction = ' AND ' . $search_restriction;
     }
     $course_id = api_get_course_int_id();
     $sql = "SELECT\n                    survey.survey_id,\n                    survey.parent_id,\n                    survey_version,\n                    survey.code as name\n\t\t\t\tFROM {$table_survey} survey\n\t\t\t\tLEFT JOIN {$table_survey_question}  survey_question\n\t\t\t\tON survey.survey_id = survey_question.survey_id , {$table_user} user\n\t\t\t\tWHERE\n\t\t\t\t\tsurvey.c_id \t\t\t=  {$course_id} AND\n\t\t\t\t\tsurvey_question.c_id \t=  {$course_id} AND\n\t\t\t\t\tsurvey.author \t\t\t= user.user_id\n\t\t\t\tGROUP BY survey.survey_id";
     $res = Database::query($sql);
     $surveys_parents = array();
     $refs = array();
     $list = array();
     $plain_array = array();
     while ($survey = Database::fetch_array($res, 'ASSOC')) {
         $plain_array[$survey['survey_id']] = $survey;
         $surveys_parents[] = $survey['survey_version'];
         $thisref =& $refs[$survey['survey_id']];
         $thisref['parent_id'] = $survey['parent_id'];
         $thisref['name'] = $survey['name'];
         $thisref['id'] = $survey['survey_id'];
         $thisref['survey_version'] = $survey['survey_version'];
         if ($survey['parent_id'] == 0) {
             $list[$survey['survey_id']] =& $thisref;
         } else {
             $refs[$survey['parent_id']]['children'][$survey['survey_id']] =& $thisref;
         }
     }
     $this->surveylist = $list;
     $this->plainsurveylist = $plain_array;
 }
/**
 * Update the file or directory path in the document db document table
 *
 * @author - Hugues Peeters <*****@*****.**>
 * @param  - action (string) - action type require : 'delete' or 'update'
 * @param  - old_path (string) - old path info stored to change
 * @param  - new_path (string) - new path info to substitute
 * @desc Update the file or directory path in the document db document table
 *
 */
function update_db_info($action, $old_path, $new_path = '')
{
    $dbTable = Database::get_course_table(TABLE_DOCUMENT);
    $course_id = api_get_course_int_id();
    switch ($action) {
        case 'delete':
            $old_path = Database::escape_string($old_path);
            $to_delete = "WHERE c_id = {$course_id} AND (path LIKE BINARY '" . $old_path . "' OR path LIKE BINARY '" . $old_path . "/%')";
            $query = "DELETE FROM {$dbTable} " . $to_delete;
            $result = Database::query("SELECT id FROM {$dbTable} " . $to_delete);
            if (Database::num_rows($result)) {
                require_once api_get_path(INCLUDE_PATH) . '../metadata/md_funcs.php';
                $mdStore = new mdstore(TRUE);
                // create if needed
                $md_type = substr($dbTable, -13) == 'scormdocument' ? 'Scorm' : 'Document';
                while ($row = Database::fetch_array($result)) {
                    $eid = $md_type . '.' . $row['id'];
                    $mdStore->mds_delete($eid);
                    $mdStore->mds_delete_offspring($eid);
                }
            }
            Database::query($query);
            break;
        case 'update':
            if ($new_path[0] == '.') {
                $new_path = substr($new_path, 1);
            }
            $new_path = str_replace('//', '/', $new_path);
            // Attempt to update	- tested & working for root	dir
            $new_path = Database::escape_string($new_path);
            $query = "UPDATE {$dbTable} SET\n                        path = CONCAT('" . $new_path . "', SUBSTRING(path, LENGTH('" . $old_path . "')+1) )\n                    WHERE c_id = {$course_id} AND (path LIKE BINARY '" . $old_path . "' OR path LIKE BINARY '" . $old_path . "/%')";
            Database::query($query);
            break;
    }
}
Example #4
0
/**
 * Save the score for a HP quiz. Can be used by the learnpath tool as well
 * for HotPotatoes quizzes. When coming from the learning path, we
 * use the session variables telling us which item of the learning path has to
 * be updated (score-wise)
 * @param	string	File is the exercise name (the file name for a HP)
 * @param	integer	Score to save inside the tracking tables (HP and learnpath)
 * @return	void
 */
function save_scores($file, $score)
{
    global $origin;
    $TABLETRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
    $_user = api_get_user_info();
    // if tracking is disabled record nothing
    $weighting = 100;
    // 100%
    $date = api_get_utc_datetime();
    $c_id = api_get_course_int_id();
    if ($_user['user_id']) {
        $user_id = $_user['user_id'];
    } else {
        // anonymous
        $user_id = "NULL";
    }
    $params = ['exe_name' => $file, 'exe_user_id' => $user_id, 'exe_date' => $date, 'c_id' => $c_id, 'exe_result' => $score, 'exe_weighting' => $weighting];
    Database::insert($TABLETRACK_HOTPOTATOES, $params);
    if ($origin == 'learnpath') {
        //if we are in a learning path, save the score in the corresponding
        //table to get tracking in there as well
        global $jscript2run;
        //record the results in the learning path, using the SCORM interface (API)
        $jscript2run .= "<script>\n            \$(document).ready(function() {\n                //API_obj = window.frames.window.content.API;\n                //API_obj = \$('content_id').context.defaultView.content.API; //works only in FF\n                //API_obj = window.parent.frames.window.top.API;\n                API_obj = window.top.API;\n                API_obj.void_save_asset('{$score}', '{$weighting}', 0, 'completed');\n            });\n        </script>";
    }
}
/**
 * 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);
    $class_user_table = Database::get_main_table(TABLE_MAIN_CLASS_USER);
    $courseId = api_get_course_int_id();
    $em = Database::getManager();
    $res = $em->getRepository('ChamiloCoreBundle:CourseRelClass')->findBy(['courseId' => $courseId]);
    $subscribed_classes = array();
    foreach ($res as $obj) {
        $subscribed_classes[] = $obj->getClassId();
    }
    $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;
}
Example #6
0
 /**
  * @param int $entity_id
  * @param int $row_entity_id
  * @param int $course_id
  * @return array|bool
  */
 public static function get_next_by_row_id($entity_id, $row_entity_id, $course_id = null)
 {
     if (self::_debug) {
         error_log('Entering ' . __FUNCTION__ . ' in ' . __FILE__);
     }
     $row_entity_id = Database::escape_string($row_entity_id);
     $entity_id = Database::escape_string($entity_id);
     $course_id = Database::escape_string($course_id);
     if (is_numeric($row_entity_id) && is_numeric($entity_id)) {
         $row_entity_id = intval($row_entity_id);
         $entity_id = intval($entity_id);
         $course_id = is_numeric($course_id) ? intval($course_id) : api_get_course_int_id();
         $seq_table = Database::get_main_table(TABLE_MAIN_SEQUENCE);
         $row_table = Database::get_main_table(TABLE_SEQUENCE_ROW_ENTITY);
         $sql = "SELECT row.id FROM {$row_table} row\n                    WHERE\n                        row.sequence_type_entity_id = {$entity_id} AND\n                         row.row_id = {$row_entity_id} AND\n                         row.c_id = {$course_id} LIMIT 0, 1";
         $sql = "SELECT main.sequence_row_entity_id_next\n                    FROM {$seq_table} main WHERE main.sequence_row_entity_id_next IN ({$sql})";
         $sql = "SELECT * FROM {$row_table} res\n                    WHERE res.id IN ({$sql})";
         $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             while ($temp_next = Database::fetch_array($result, 'ASSOC')) {
                 $next[] = $temp_next;
             }
             return $next;
         }
     }
     return false;
 }
 /**
  * Get actual array data
  * @return array 2-dimensional array - each array contains the elements:
  * 0: cat/eval/link object
  * 1: item name
  * 2: description
  * 3: weight
  * 4: date
  * 5: student's score (if student logged in)
  */
 public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false)
 {
     //$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
     // do some checks on count, redefine if invalid value
     if (!isset($count)) {
         $count = count($this->items) - $start;
     }
     if ($count < 0) {
         $count = 0;
     }
     $allitems = $this->items;
     // sort array
     if ($sorting & self::GDG_SORT_TYPE) {
         usort($allitems, array('GradebookDataGenerator', 'sort_by_type'));
     } elseif ($sorting & self::GDG_SORT_ID) {
         usort($allitems, array('GradebookDataGenerator', 'sort_by_id'));
     } elseif ($sorting & self::GDG_SORT_NAME) {
         usort($allitems, array('GradebookDataGenerator', 'sort_by_name'));
     } elseif ($sorting & self::GDG_SORT_DESCRIPTION) {
         usort($allitems, array('GradebookDataGenerator', 'sort_by_description'));
     } elseif ($sorting & self::GDG_SORT_WEIGHT) {
         usort($allitems, array('GradebookDataGenerator', 'sort_by_weight'));
     } elseif ($sorting & self::GDG_SORT_DATE) {
         //usort($allitems, array('GradebookDataGenerator', 'sort_by_date'));
     }
     if ($sorting & self::GDG_SORT_DESC) {
         $allitems = array_reverse($allitems);
     }
     // get selected items
     $visibleitems = array_slice($allitems, $start, $count);
     //status de user in course
     $user_id = api_get_user_id();
     $status_user = api_get_status_of_user_in_course($user_id, api_get_course_int_id());
     // generate the data to display
     $data = array();
     foreach ($visibleitems as $item) {
         $row = array();
         $row[] = $item;
         $row[] = $item->get_name();
         // display the 2 first line of description, and all description on mouseover (https://support.chamilo.org/issues/6588)
         $row[] = '<span title="' . api_remove_tags_with_space($item->get_description()) . '">' . api_get_short_text_from_html($item->get_description(), 160) . '</span>';
         $row[] = $item->get_weight();
         /*if (api_is_allowed_to_edit(null, true)) {
         			$row[] = $this->build_date_column($item);
         		}*/
         if (count($this->evals_links) > 0) {
             if (!api_is_allowed_to_edit() || $status_user != 1) {
                 $row[] = $this->build_result_column($item, $ignore_score_color);
                 $row[] = $item;
             }
         }
         $data[] = $row;
     }
     return $data;
 }
 /**
  *
  * @return \Entity\Course 
  */
 public static function current_course()
 {
     static $result = false;
     if ($result === false) {
         $repo = \Entity\Course::repository();
         $course_id = api_get_course_int_id();
         if ($course_id) {
             $result = $repo->find($course_id);
         }
     }
     return $result;
 }
Example #9
0
 /**
  * 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;
 }
 /**
  * Generates an array of all surveys available.
  * @return array 2-dimensional array - every element contains 2 subelements (id, name)
  */
 public function get_all_links()
 {
     if (empty($this->course_code)) {
         die('Error in get_all_links() : course code not set');
     }
     $tbl_survey = $this->get_survey_table();
     $session_id = api_get_session_id();
     $course_id = api_get_course_int_id();
     $sql = 'SELECT survey_id, title, code FROM ' . $tbl_survey . ' WHERE c_id = ' . $course_id . ' AND session_id = ' . intval($session_id) . '';
     $result = Database::query($sql);
     while ($data = Database::fetch_array($result)) {
         $links[] = array($data['survey_id'], Text::api_trunc_str($data['code'] . ': ' . self::html_to_text($data['title']), 80));
     }
     return isset($links) ? $links : null;
 }
 /**
  * @param int $course
  * @param int $announcement
  */
 public function __construct($course, $announcement)
 {
     if (empty($course)) {
         $course = api_get_course_int_id();
         $course = api_get_course_info_by_id($course);
     } else {
         if (is_numeric($course)) {
             $course = api_get_course_info_by_id($course);
         }
     }
     $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;
 }
 /**
  * Returns true if the gradebook is active and visible in a course, false
  * otherwise.
  *
  * @param int $c_id Course integer id, defaults to the current course
  * @return boolean
  */
 public static function is_active($c_id = null)
 {
     $name = 'gradebook';
     $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $sql = "SELECT * from {$table} WHERE variable='course_hide_tools' AND subkey='{$name}'";
     $setting = ResultSet::create($sql)->first();
     $setting = $setting ? $setting : array();
     $inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true';
     if ($inactive) {
         return false;
     }
     $c_id = $c_id ? intval($c_id) : api_get_course_int_id();
     $table = Database::get_course_table(TABLE_TOOL_LIST);
     $sql = "SELECT * from {$table} WHERE c_id = {$c_id} and name='{$name}'";
     $item = ResultSet::create($sql)->first();
     if (empty($item)) {
         return true;
     }
     return $item['visibility'] == '1';
 }
Example #13
0
 /**
  * Update a link in the database
  * @param int $linkId The ID of the link to update
  * @param string $linkUrl The new URL to be saved
  * @param int   Course ID
  * @param int   Session ID
  * @return bool
  */
 public function updateLink($linkId, $linkUrl, $courseId = null, $sessionId = null)
 {
     $tblLink = Database::get_course_table(TABLE_LINK);
     $linkUrl = Database::escape_string($linkUrl);
     $linkId = intval($linkId);
     if (is_null($courseId)) {
         $courseId = api_get_course_int_id();
     }
     $courseId = intval($courseId);
     if (is_null($sessionId)) {
         $sessionId = api_get_session_id();
     }
     $sessionId = intval($sessionId);
     if ($linkUrl != '') {
         $sql = "UPDATE {$tblLink} SET url = '{$linkUrl}'\n                    WHERE id = {$linkId} AND c_id = {$courseId} AND session_id = {$sessionId}";
         $resLink = Database::query($sql);
         return $resLink;
     }
     return false;
 }
/**
 * Update the file or directory path in the document db document table
 *
 * @author - Hugues Peeters <*****@*****.**>
 * @param  - action (string) - action type require : 'delete' or 'update'
 * @param  - old_path (string) - old path info stored to change
 * @param  - new_path (string) - new path info to substitute
 * @desc Update the file or directory path in the document db document table
 *
 */
function update_db_info($action, $old_path, $new_path = '')
{
    $dbTable = Database::get_course_table(TABLE_DOCUMENT);
    $course_id = api_get_course_int_id();
    switch ($action) {
        case 'delete':
            $old_path = Database::escape_string($old_path);
            $query = "DELETE FROM {$dbTable}\n                      WHERE\n                        c_id = {$course_id} AND\n                        (\n                            path LIKE BINARY '" . $old_path . "' OR\n                            path LIKE BINARY '" . $old_path . "/%'\n                        )";
            Database::query($query);
            break;
        case 'update':
            if ($new_path[0] == '.') {
                $new_path = substr($new_path, 1);
            }
            $new_path = str_replace('//', '/', $new_path);
            // Attempt to update	- tested & working for root	dir
            $new_path = Database::escape_string($new_path);
            $query = "UPDATE {$dbTable} SET\n                        path = CONCAT('" . $new_path . "', SUBSTRING(path, LENGTH('" . $old_path . "')+1) )\n                      WHERE c_id = {$course_id} AND (path LIKE BINARY '" . $old_path . "' OR path LIKE BINARY '" . $old_path . "/%')";
            Database::query($query);
            break;
    }
}
Example #15
0
/**
 * Save the score for a HP quiz. Can be used by the learnpath tool as well
 * for HotPotatoes quizzes. When coming from the learning path, we
 * use the session variables telling us which item of the learning path has to
 * be updated (score-wise)
 * @param    string    File is the exercise name (the file name for a HP)
 * @param    integer    Score to save inside the tracking tables (HP and learnpath)
 * @return    void
 */
function save_scores($file, $score)
{
    global $origin, $_user, $TABLETRACK_HOTPOTATOES;
    $weighting = 100;
    // 100%
    $date = api_get_utc_datetime();
    if ($_user['user_id']) {
        $user_id = $_user['user_id'];
    } else {
        // anonymous
        $user_id = "NULL";
    }
    $sql = "INSERT INTO {$TABLETRACK_HOTPOTATOES} (exe_name, exe_user_id, exe_date, c_id, exe_result, exe_weighting) VALUES (\n\t\t\t'" . Database::escape_string($file) . "',\n\t\t\t'" . Database::escape_string($user_id) . "',\n\t\t\t'" . Database::escape_string($date) . "',\n\t\t\t'" . api_get_course_int_id() . "',\n\t\t\t'" . Database::escape_string($score) . "',\n\t\t\t'" . Database::escape_string($weighting) . "')";
    Database::query($sql);
    if ($origin == 'learnpath') {
        //if we are in a learning path, save the score in the corresponding
        //table to get tracking in there as well
        global $jscript2run;
        //record the results in the learning path, using the SCORM interface (API)
        $jscript2run .= "<script>\n            \$(document).ready(function() {\n                //API_obj = window.frames.window.content.API;\n                //API_obj = \$('content_id').context.defaultView.content.API; //works only in FF\n                //API_obj = window.parent.frames.window.top.API;\n                API_obj = window.top.API;\n                API_obj.void_save_asset('{$score}', '{$weighting}', 0, 'completed');\n            });\n        </script>";
    }
}
/**
 * This function returns false if there is at least one item in the path
 * @param	Learnpath ID
 * @return	boolean	True if nothing was found, false otherwise
 */
function is_empty($id)
{
    $tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM);
    $tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
    $course_id = api_get_course_int_id();
    $sql = "SELECT * FROM {$tbl_learnpath_chapter} WHERE c_id = {$course_id} AND lp_id={$id} ORDER BY display_order ASC";
    $result = Database::query($sql);
    $num_modules = Database::num_rows($result);
    $empty = true;
    if ($num_modules != 0) {
        while ($row = Database::fetch_array($result)) {
            $num_items = 0;
            $parent_item_id = $row['id'];
            $sql2 = "SELECT * FROM {$tbl_learnpath_item} WHERE c_id = {$course_id} AND (parent_item_id={$parent_item_id}) ORDER BY display_order ASC";
            $result2 = Database::query($sql2);
            $num_items = Database::num_rows($result2);
            if ($num_items > 0) {
                $empty = false;
            }
        }
    }
    return $empty;
}
Example #17
0
 function addAction(Application $app)
 {
     $timeline = new Timeline();
     $url = $app['url_generator']->generate('add');
     $form = $timeline->return_item_form($url, 'edit');
     // The validation or display
     if ($form->validate()) {
         $values = $form->exportValues();
         $values['type'] = 0;
         $values['status'] = 0;
         $my_timeline = new CTimeline();
         $my_timeline->setCId(api_get_course_int_id());
         $my_timeline->setHeadline($values['headline']);
         $my_timeline->setType($values['type']);
         $my_timeline->setStartDate($values['start_date']);
         $my_timeline->setEndDate($values['end_date']);
         $my_timeline->setText($values['text']);
         $my_timeline->setMedia($values['media']);
         $my_timeline->setMediaCredit($values['media_credit']);
         $my_timeline->setMediaCaption($values['media_caption']);
         $my_timeline->setTitleSlide($values['title_slide']);
         $my_timeline->setParentId($values['parent_id']);
         $my_timeline->setStatus($values['status']);
         $app['orm.em']->persist($my_timeline);
         $app['orm.em']->flush();
         $message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation');
         //$app['session']->setFlash('error', $message);
         return $app->redirect($app['url_generator']->generate('view', array('id' => $my_timeline->getId())), 201);
     } else {
         $actions = '<a href="' . $app['url_generator']->generate('index') . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
         $content = $form->return_form();
     }
     $app['template']->assign('content', $content);
     $response = $app['template']->render_layout('layout_1_col.tpl');
     return new Response($response, 200, array());
 }
Example #18
0
 /**
  * Returns true if the gradebook is active and visible in a course, false
  * otherwise.
  *
  * @param int $c_id Course integer id, defaults to the current course
  * @return boolean
  */
 public static function is_active($c_id = null)
 {
     $name = 'gradebook';
     $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $sql = "SELECT * from {$table}\n                WHERE variable='course_hide_tools' AND subkey='{$name}'\n                LIMIT 1";
     $result = Database::query($sql);
     $setting = Database::store_result($result);
     $setting = isset($setting[0]) ? $setting[0] : null;
     $setting = $setting ? $setting : array();
     $inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true';
     if ($inactive) {
         return false;
     }
     $c_id = $c_id ? intval($c_id) : api_get_course_int_id();
     $table = Database::get_course_table(TABLE_TOOL_LIST);
     $sql = "SELECT * from {$table}\n                WHERE c_id = {$c_id} and name='{$name}'\n                LIMIT 1";
     $result = Database::query($sql);
     $item = Database::store_result($result, 'ASSOC');
     $item = isset($item[0]) ? $item[0] : null;
     if (empty($item)) {
         return true;
     }
     return $item['visibility'] == '1';
 }
 /**
  * Returns an array of question ids for each category
  * $categories[1][30] = 10, array with category id = 1 and question_id = 10
  * A question has "n" categories
  * @param int exercise
  * @param array check question list
  * @param string order by
  * @return array
  */
 static function getQuestionsByCat($exerciseId, $check_in_question_list = array(), $categoriesAddedInExercise = array())
 {
     $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
     $categoryTable = Database::get_course_table(TABLE_QUIZ_CATEGORY);
     $exerciseId = intval($exerciseId);
     $sql = "SELECT DISTINCT qrc.question_id, qrc.category_id\n                FROM {$TBL_QUESTION_REL_CATEGORY} qrc INNER JOIN {$TBL_EXERCICE_QUESTION} eq\n                ON (eq.question_id = qrc.question_id)\n                INNER JOIN {$categoryTable} c\n                ON (c.iid = qrc.category_id)\n                INNER JOIN {$tableQuestion} q\n                ON (q.iid = qrc.question_id )\n                WHERE   exercice_id = {$exerciseId} AND\n                        qrc.c_id = " . api_get_course_int_id() . "\n                ";
     $res = Database::query($sql);
     $categories = array();
     while ($data = Database::fetch_array($res)) {
         if (!empty($check_in_question_list)) {
             if (!in_array($data['question_id'], $check_in_question_list)) {
                 continue;
             }
         }
         if (!isset($categories[$data['category_id']]) or !is_array($categories[$data['category_id']])) {
             $categories[$data['category_id']] = array();
         }
         $categories[$data['category_id']][] = $data['question_id'];
     }
     $newCategoryList = array();
     foreach ($categoriesAddedInExercise as $category) {
         $categoryId = $category['category_id'];
         if (isset($categories[$categoryId])) {
             $newCategoryList[$categoryId] = $categories[$categoryId];
         }
     }
     return $newCategoryList;
 }
Example #20
0
 /**
  * Move a glossary term
  *
  * @param unknown_type $direction
  * @param unknown_type $glossary_id
  *
  * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
  * @version januari 2009, dokeos 1.8.6
  */
 public static function move_glossary($direction, $glossary_id, $message = true)
 {
     // Database table definition
     $t_glossary = Database::get_course_table(TABLE_GLOSSARY);
     // sort direction
     if ($direction == 'up') {
         $sortorder = 'DESC';
     } else {
         $sortorder = 'ASC';
     }
     $course_id = api_get_course_int_id();
     $sql = "SELECT * FROM {$t_glossary}\n                WHERE c_id = {$course_id}\n                ORDER BY display_order {$sortorder}";
     $res = Database::query($sql);
     $found = false;
     while ($row = Database::fetch_array($res)) {
         if ($found && empty($next_id)) {
             $next_id = $row['glossary_id'];
             $next_display_order = $row['display_order'];
         }
         if ($row['glossary_id'] == $glossary_id) {
             $current_id = $glossary_id;
             $current_display_order = $row['display_order'];
             $found = true;
         }
     }
     $sql1 = "UPDATE {$t_glossary} SET display_order = '" . Database::escape_string($next_display_order) . "'\n                 WHERE c_id = {$course_id}  AND glossary_id = '" . Database::escape_string($current_id) . "'";
     $sql2 = "UPDATE {$t_glossary} SET display_order = '" . Database::escape_string($current_display_order) . "'\n                 WHERE c_id = {$course_id}  AND glossary_id = '" . Database::escape_string($next_id) . "'";
     Database::query($sql1);
     Database::query($sql2);
     if ($message) {
         Display::display_confirmation_message(get_lang('TermMoved'));
     }
 }
Example #21
0
             $last_access = empty($last_access) ? "-" : date('d.m.y', strtotime($last_access));
             // END first/last access
             // BEGIN presentation of data
             $line .= $results[$j][1] . " " . $results[$j][2] . ";" . $first_access . ";" . $last_access . ";" . $lpath_pct_completed . "\n";
             // END presentation of data
         }
     } else {
         $line = get_lang('NoResult') . "\n";
     }
 }
 /* 	Main */
 $tempView = $view;
 if ($view[0] == '1') {
     $title[1] = $nameTools;
     $tempView[0] = '0';
     $sql = "SELECT count(*)\n                FROM {$TABLECOURSUSER}\n                WHERE c_id = '" . api_get_course_int_id() . "' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . "";
     $count = StatsUtils::getOneResult($sql);
     $title_line = get_lang('CountUsers') . " ; " . $count . "\n";
 }
 /* 	Access to this course */
 $tempView = $view;
 if ($view[1] == '1') {
     $tempView[1] = '0';
     $title[1] = get_lang('ConnectionsToThisCourse');
     $title_line = '';
     $line = '';
     //Total
     $sql = "SELECT count(*)\n                FROM {$TABLETRACK_ACCESS}\n                WHERE c_id = {$courseId}\n                    AND access_tool IS NULL";
     $count = StatsUtils::getOneResult($sql);
     $line .= get_lang('CountToolAccess') . " ; " . $count . "\n";
     // last 31 days
Example #22
0
    static function display_notes()
    {

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

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

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

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

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

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

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

        $sql = "SELECT * FROM $t_notebook WHERE c_id = $course_id AND user_id = '" . api_get_user_id() . "' $condition_session $cond_extra $order_by";
        $result = Database::query($sql);
        while ($row = Database::fetch_array($result)) {
            //validacion when belongs to a session
            $session_img = api_get_session_image($row['session_id'], $_user['status']);
            $creation_date = api_get_local_time($row['creation_date'], null, date_default_timezone_get());
            $update_date = api_get_local_time($row['update_date'], null, date_default_timezone_get());
            echo '<div class="sectiontitle">';
            echo '<span style="float: right;"> (' . get_lang('CreationDate') . ': ' . date_to_str_ago($creation_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $creation_date . '</span>';
            if ($row['update_date'] <> $row['creation_date']) {
                echo ', ' . get_lang('UpdateDate') . ': ' . date_to_str_ago($update_date) . '&nbsp;&nbsp;<span class="dropbox_date">' . $update_date . '</span>';
            }
            echo ')</span>';
            echo $row['title'] . $session_img;
            echo '</div>';
            echo '<div class="sectioncomment">' . $row['description'] . '</div>';
            echo '<div>';
            echo '<a href="' . api_get_self() . '?action=editnote&amp;notebook_id=' . $row['notebook_id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>';
            echo '<a href="' . api_get_self() . '?action=deletenote&amp;notebook_id=' . $row['notebook_id'] . '" onclick="return confirmation(\'' . $row['title'] . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
            echo '</div>';
        }
    }
 /**
  * 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 . "&nbsp;&nbsp;&nbsp;  " . $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, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 . '&nbsp;-&nbsp;' . get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan') . '&nbsp;' . $weight_category . '<br />';
                     }
                 }
                 if (!empty($warning_message)) {
                     Display::display_warning_message($warning_message, false);
                 }
             }
         }
     }
     return $sortable_data;
 }
Example #24
0
        $actionLabel = get_lang('Modify');
        $actionIcon1 = "edit";
        $actionIcon2 = "delete";
        // We are in the course, question title can be a link to the question edit page
        $questionTagA = 1;
    } else {
        // NOT IN A TEST - NOT IN THE COURSE
        $actionLabel = get_lang('Reuse');
        $actionIcon1 = get_lang('MustBeInATest');
        $actionIcon2 = "";
        // We are not in this course, to messy if we link to the question in another course
        $questionTagA = 0;
    }
} else {
    // IN A TEST - IN THE COURSE
    if ($selected_course == api_get_course_int_id()) {
        $actionLabel = get_lang('Reuse');
        $actionIcon1 = "add";
        $actionIcon2 = "";
        $questionTagA = 1;
    } else {
        // IN A TEST - NOT IN THE COURSE
        $actionLabel = get_lang('Reuse');
        $actionIcon1 = "clone";
        $actionIcon2 = "";
        $questionTagA = 0;
    }
}
// Display table
$header = array(array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style" => "text-align:center"), ''), array(get_lang('Type'), false, array("style" => "text-align:center"), array("style" => "text-align:center"), ''), array(get_lang('QuestionCategory'), false, array("style" => "text-align:center"), array("style" => "text-align:center"), ''), array(get_lang('Difficulty'), false, array("style" => "text-align:center"), array("style" => "text-align:center"), ''), array($actionLabel, false, array("style" => "text-align:center"), array("style" => "text-align:center"), ''));
$data = array();
require 'learnpath_functions.inc.php';
require 'resourcelinker.inc.php';
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if (!$is_allowed_to_edit) {
    header('location:lp_controller.php?action=list&' . api_get_cidreq());
    exit;
}
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list?' . api_get_cidreq(), 'name' => get_lang('LearningPaths'));
$form = new FormValidator('lp_add_category', 'post', 'lp_controller.php?' . api_get_cidreq());
// Form title
$form->addElement('header', null, get_lang('AddLPCategory'));
// Title
$form->addElement('text', 'name', api_ucfirst(get_lang('Name')));
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'action', 'add_lp_category');
$form->addElement('hidden', 'c_id', api_get_course_int_id());
$form->addElement('hidden', 'id', 0);
$form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
    $values = $form->getSubmitValues();
    if (!empty($values['id'])) {
        learnpath::updateCategory($values);
        $url = api_get_self() . '?action=list&' . api_get_cidreq();
        header('Location: ' . $url);
        exit;
    } else {
        learnpath::createCategory($values);
        $url = api_get_self() . '?action=list&' . api_get_cidreq();
        header('Location: ' . $url);
        exit;
    }
Example #26
0
 /**
  * @param string $courseCode
  * @param array $rules
  * @param array $columns
  * @param array $column_model
  * @return array
  */
 public static function getRules($courseCode, &$rules, &$columns, &$column_model, $questionFields, $checkFields = false)
 {
     // sessions
     // course
     // categories
     // exercises
     // difficult
     // type
     if (empty($courseCode)) {
         // Session.
         $sessionList = SessionManager::get_sessions_by_general_coach(api_get_user_id());
         $fields = array();
         if (!empty($sessionList)) {
             $new_options = array();
             $new_options[] = "-1:" . get_lang('All');
             foreach ($sessionList as $session) {
                 $new_options[] = "{$session['id']}:{$session['name']}";
             }
             $string = implode(';', $new_options);
             $fields[] = array('field_display_text' => get_lang('Session'), 'field_variable' => 'session_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
         }
     } else {
         // $courseList = array(api_get_course_info());
         //$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     }
     // Courses.
     $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($courseList as $course) {
             $new_options[] = "{$course['id']}:{$course['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Course'), 'field_variable' => 'c_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Categories.
     $string = null;
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         // Global categories
         // @todo use tree view
         $categories = Testcategory::getCategoriesIdAndName(0);
         if (!empty($categories)) {
             foreach ($categories as $id => $category) {
                 if (!empty($id)) {
                     $new_options[] = "{$id}:[Global] - " . $category;
                 }
             }
         }
         foreach ($courseList as $course) {
             $categories = Testcategory::getCategoriesIdAndName($course['real_id']);
             if (!empty($categories)) {
                 foreach ($categories as $id => $category) {
                     if (!empty($id)) {
                         $new_options[] = "{$id}:" . $course['title'] . " - " . $category;
                     }
                 }
             }
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Category'), 'field_variable' => 'category_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $course = api_get_course_int_id();
     $sessionId = api_get_session_id();
     // Exercises.
     $exerciseList = ExerciseLib::get_all_exercises_for_course_id($sessionId, $course);
     if (!empty($exerciseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         $new_options[] = "0:" . get_lang('Orphan');
         foreach ($exerciseList as $exercise) {
             $new_options[] = "{$exercise['iid']}:{$exercise['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Exercise'), 'field_variable' => 'exercise_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Question type.
     $questionList = Question::get_question_type_list();
     if (!empty($questionList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($questionList as $key => $question) {
             $new_options[] = "{$key}:" . get_lang($question['1']);
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('AnswerType'), 'field_variable' => 'question_type', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Difficult.
     $levels = Question::get_default_levels();
     if (!empty($levels)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($levels as $key => $level) {
             $new_options[] = "{$key}:{$level}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Difficulty'), 'field_variable' => 'difficulty', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $questionFieldsKeys = array();
     if (!empty($questionFields)) {
         foreach ($questionFields as $question) {
             $questionFieldsKeys[] = $question['field'];
         }
     }
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $search_options = array();
             $type = 'text';
             if (in_array($field['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
                 $type = 'select';
                 $search_options['sopt'] = array('eq', 'ne');
                 //equal not equal
                 //$search_options['sopt'] = array('cn', 'nc'); //contains not contains
             } else {
                 $search_options['sopt'] = array('cn', 'nc');
                 //contains not contains
             }
             $search_options['searchhidden'] = 'true';
             $search_options['defaultValue'] = isset($search_options['field_default_value']) ? $search_options['field_default_value'] : null;
             $search_options['value'] = $field['field_options'];
             $column_model[] = array('name' => 'question_' . $field['field_variable'], 'index' => 'question_' . $field['field_variable'], 'width' => '100', 'hidden' => 'true', 'search' => 'true', 'stype' => $type, 'searchoptions' => $search_options);
             $columns[] = $field['field_display_text'];
             $rules[] = array('field' => 'question_' . $field['field_variable'], 'op' => 'eq');
         }
     }
     return $rules;
 }
Example #27
0
// LP image
$form->add_progress_bar();
if (strlen($_SESSION['oLP']->get_preview_image()) > 0) {
    $show_preview_image = '<img src=' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $_SESSION['oLP']->get_preview_image() . '>';
    $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
    $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
$label = $_SESSION['oLP']->get_preview_image() != '' ? get_lang('UpdateImage') : get_lang('AddImage');
$form->addElement('file', 'lp_preview_image', array($label, get_lang('ImageWillResizeMsg')));
$form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
// Search terms (only if search is activated).
if (api_get_setting('search_enabled') === 'true') {
    $specific_fields = get_specific_field_list();
    foreach ($specific_fields as $specific_field) {
        $form->addElement('text', $specific_field['code'], $specific_field['name']);
        $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $_SESSION['oLP']->lp_id, 'tool_id' => '\'' . TOOL_LEARNPATH . '\'');
        $values = get_specific_field_values_list($filter, array('value'));
        if (!empty($values)) {
            $arr_str_values = array();
            foreach ($values as $value) {
                $arr_str_values[] = $value['value'];
            }
            $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
        }
    }
}
$defaults['lp_encoding'] = Security::remove_XSS($_SESSION['oLP']->encoding);
$defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
$defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
$defaults['hide_toc_frame'] = Security::remove_XSS($_SESSION['oLP']->get_hide_toc_frame());
$defaults['category_id'] = intval($_SESSION['oLP']->get_category_id());
Example #28
0
 /**
  * Return the id of the test category with title = $in_title
  * @param $in_title
  * @param int $in_c_id
  *
  * @return int is id of test category
  */
 public static function get_category_id_for_title($title, $courseId = 0)
 {
     $out_res = 0;
     if (empty($courseId)) {
         $courseId = api_get_course_int_id();
     }
     $courseId = intval($courseId);
     $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
     $sql = "SELECT id FROM {$tbl_cat}\n                WHERE c_id = {$courseId} AND title = '" . Database::escape_string($title) . "'";
     $res = Database::query($sql);
     if (Database::num_rows($res) > 0) {
         $data = Database::fetch_array($res);
         $out_res = $data['id'];
     }
     return $out_res;
 }
Example #29
0
require_once api_get_path(SYS_CODE_PATH) . 'document/document.inc.php';
//I'm in the certification module?
$is_certificate_mode = false;
$_course = api_get_course_info();
$groupId = api_get_group_id();
if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
    $is_certificate_mode = true;
}
if ($is_certificate_mode) {
    $nameTools = get_lang('CreateCertificate');
} else {
    $nameTools = get_lang('CreateDocument');
}
/*	Constants and variables */
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
$document_data = DocumentManager::get_document_data_by_id($_REQUEST['id'], api_get_course_id(), true);
if (empty($document_data)) {
    if (api_is_in_group()) {
        $group_properties = GroupManager::get_group_properties($groupId);
        $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
        $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
        $dir = $document_data['path'];
        $folder_id = $document_data['id'];
    } else {
        $dir = '/';
        $folder_id = 0;
    }
} else {
    $folder_id = $document_data['id'];
    $dir = $document_data['path'];
Example #30
0
 /**
  *
  * See : fill_groups
  *       Fill the groups with students.
  *
  * note : optimize fill_groups_list <--> fill_groups
  * @param array $group_ids
  * @return array|bool
  */
 public static function fill_groups_list($group_ids)
 {
     $group_ids = is_array($group_ids) ? $group_ids : array($group_ids);
     $group_ids = array_map('intval', $group_ids);
     /*if (api_is_course_coach()) {
           for ($i = 0; $i < count($group_ids); $i++) {
               if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) {
                   array_splice($group_ids, $i, 1);
                   $i--;
               }
           }
           if (count($group_ids) == 0) {
               return false;
           }
       }*/
     $_course = api_get_course_info();
     $category = self::get_category_from_group($group_ids[0]);
     $groups_per_user = $category['groups_per_user'];
     $group_table = Database::get_course_table(TABLE_GROUP);
     $group_user_table = Database::get_course_table(TABLE_GROUP_USER);
     $session_id = api_get_session_id();
     $complete_user_list = CourseManager::get_real_and_linked_user_list($_course['sysCode'], true, $session_id);
     $number_groups_per_user = $groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user;
     $course_id = api_get_course_int_id();
     /*
      * Retrieve all the groups where enrollment is still allowed
      * (reverse) ordered by the number of place available
      */
     $sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student\n                FROM " . $group_table . " g\n                LEFT JOIN  " . $group_user_table . " ug\n                ON    g.id = ug.group_id\n                WHERE   g.c_id = {$course_id} AND\n                        ug.c_id = {$course_id} AND\n                        g.id IN (" . implode(',', $group_ids) . ")\n                GROUP BY (g.id)";
     $sql_result = Database::query($sql);
     $group_available_place = array();
     while ($group = Database::fetch_array($sql_result, 'ASSOC')) {
         if (!empty($group['max_student'])) {
             $places = intval($group['max_student'] - $group['count_users']);
         } else {
             $places = self::MEMBER_PER_GROUP_NO_LIMIT;
         }
         $group_available_place[$group['gid']] = $places;
     }
     /*
      * Retrieve course users (reverse) ordered by the number
      * of group they are already enrolled
      */
     for ($i = 0; $i < count($complete_user_list); $i++) {
         //find # of groups the user is enrolled in
         $number_of_groups = self::user_in_number_of_groups($complete_user_list[$i]["user_id"], $category['id']);
         //add # of groups to user list
         $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups;
     }
     //first sort by user_id to filter out duplicates
     $complete_user_list = TableSort::sort_table($complete_user_list, 'user_id');
     $complete_user_list = self::filter_duplicates($complete_user_list, 'user_id');
     //$complete_user_list = self :: filter_only_students($complete_user_list);
     //now sort by # of group left
     $complete_user_list = TableSort::sort_table($complete_user_list, 'number_groups_left', SORT_DESC);
     return $complete_user_list;
 }