function uninstall()
 {
     $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
     $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
     //Delete settings
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'ticket_tool_enable'";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_ticket";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_status";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_project";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_priority";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_message_attch";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_message";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_category";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_assigned_log";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS ticket_ticket";
     Database::query($sql);
     //Deleting course settings
     $this->uninstall_course_fields_in_all_courses();
 }
 /**
  * Get document information
  */
 private function get_information($course_id, $link_id)
 {
     $course_information = api_get_course_info($course_id);
     $course_id = $course_information['real_id'];
     $course_id_alpha = $course_information['id'];
     if (!empty($course_information)) {
         $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $link_id = Database::escape_string($link_id);
         $sql = "SELECT insert_user_id FROM {$item_property_table}\n              \t\tWHERE ref = {$link_id} AND tool = '" . TOOL_LINK . "' AND c_id = {$course_id}\n              \t\tLIMIT 1";
         $name = get_lang('Links');
         $url = api_get_path(WEB_PATH) . 'main/link/link.php?cidReq=%s';
         $url = sprintf($url, $course_id_alpha);
         // Get the image path
         $thumbnail = api_get_path(WEB_IMG_PATH) . 'link.gif';
         $image = $thumbnail;
         //FIXME: use big images
         // get author
         $author = '';
         $item_result = Database::query($sql);
         if ($row = Database::fetch_array($item_result)) {
             $user_data = api_get_user_info($row['insert_user_id']);
             $author = api_get_person_name($user_data['firstName'], $user_data['lastName']);
         }
         return array($thumbnail, $image, $name, $author, $url);
     } else {
         return array();
     }
 }
 public function uninstall()
 {
     $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
     $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
     //New settings
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_tool_enable'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_salt'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_host'";
     Database::query($sql);
     //Old settings deleting just in case
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_plugin'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_options} WHERE variable  = 'bbb_plugin'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_plugin_host'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'bbb_plugin_salt'";
     Database::query($sql);
     //hack to get rid of Database::query warning (please add c_id...)
     $sql = "DELETE FROM {$t_tool} WHERE name = 'bbb' AND c_id != 0";
     Database::query($sql);
     $t = Database::get_main_table('plugin_bbb_meeting');
     $sql = "DROP TABLE IF EXISTS {$t}";
     Database::query($sql);
     //Deleting course settings
     $this->uninstall_course_fields_in_all_courses($this->course_settings);
 }
/**
 *
 */
function get_course_usage($course_code, $session_id = 0)
{
    $table = Database::get_main_table(TABLE_MAIN_COURSE);
    $course_code = Database::escape_string($course_code);
    $sql = "SELECT * FROM {$table} WHERE code='" . $course_code . "'";
    $res = Database::query($sql);
    $course = Database::fetch_object($res);
    // Learnpaths
    $table = Database::get_course_table(TABLE_LP_MAIN);
    $usage[] = array(get_lang(ucfirst(TOOL_LEARNPATH)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Forums
    $table = Database::get_course_table(TABLE_FORUM);
    $usage[] = array(get_lang('Forums'), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Quizzes
    $table = Database::get_course_table(TABLE_QUIZ_TEST);
    $usage[] = array(get_lang(ucfirst(TOOL_QUIZ)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Documents
    $table = Database::get_course_table(TABLE_DOCUMENT);
    $usage[] = array(get_lang(ucfirst(TOOL_DOCUMENT)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Groups
    $table = Database::get_course_table(TABLE_GROUP);
    $usage[] = array(get_lang(ucfirst(TOOL_GROUP)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Calendar
    $table = Database::get_course_table(TABLE_AGENDA);
    $usage[] = array(get_lang(ucfirst(TOOL_CALENDAR_EVENT)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Link
    $table = Database::get_course_table(TABLE_LINK);
    $usage[] = array(get_lang(ucfirst(TOOL_LINK)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    // Announcements
    $table = Database::get_course_table(TABLE_ANNOUNCEMENT);
    $usage[] = array(get_lang(ucfirst(TOOL_ANNOUNCEMENT)), CourseManager::count_rows_course_table($table, $session_id, $course->id));
    return $usage;
}
Example #5
0
 function mdobject($_course, $eid)
 {
     if (!($dotpos = strpos($eid, '.'))) {
         return;
     }
     $this->mdo_course = $_course;
     $this->mdo_eid = $eid;
     $this->mdo_type = $type = substr($eid, 0, $dotpos);
     $this->mdo_id = $id = substr($eid, $dotpos + 1);
     if ($type == 'Document' || $type == 'Scorm') {
         $table = $type == 'Scorm' ? Database::get_course_table(TABLE_SCORMDOC) : Database::get_course_table(TABLE_DOCUMENT);
         if ($dotpos = strpos($id, '.')) {
             $urlp = '?sid=' . urlencode(substr($id, $dotpos + 1));
             $id = substr($id, 0, $dotpos);
         }
         if ($docinfo = @mysql_fetch_array(Database::query("SELECT path,comment,filetype FROM\n                 {$table} WHERE id='" . addslashes($id) . "'"))) {
             $this->mdo_path = $docinfo['path'];
             $this->mdo_comment = $docinfo['comment'];
             $this->mdo_filetype = $docinfo['filetype'];
             if ($type == 'Scorm') {
                 $this->mdo_base_url = get_course_web() . $this->mdo_course['path'] . '/scorm' . $this->mdo_path;
                 $this->mdo_url = $this->mdo_base_url . '/index.php' . $urlp;
             } else {
                 $this->mdo_url = api_get_path(WEB_PATH) . 'main/document/' . ($this->mdo_filetype == 'file' ? 'download' : 'document') . '.php?' . ($this->mdo_filetype == 'file' ? 'doc_url=' : 'curdirpath=') . urlencode($this->mdo_path);
             }
         }
     } elseif ($type == 'Link') {
         $link_table = Database::get_course_table(TABLE_LINK);
         if ($linkinfo = @mysql_fetch_array(Database::query("SELECT url,title,description,category_id FROM\n                 {$link_table} WHERE id='" . addslashes($id) . "'"))) {
             $this->mdo_url = $linkinfo['url'];
         }
     }
 }
Example #6
0
 function mdobject($_course, $id)
 {
     global $ieee_dcmap_e, $ieee_dcmap_v;
     // md_funcs
     $scormdocument = Database::get_course_table(TABLE_LP_MAIN);
     $this->mdo_course = $_course;
     $this->mdo_type = 'Scorm';
     $this->mdo_id = $id;
     $this->mdo_eid = $this->mdo_type . '.' . $id;
     $this->mdo_dcmap_e = $ieee_dcmap_e;
     $this->mdo_dcmap_v = $ieee_dcmap_v;
     $sql = "SELECT path,description,lp_type FROM {$scormdocument} WHERE id='" . addslashes($id) . "'";
     if ($docinfo = @Database::fetch_array(Database::query($sql))) {
         $this->mdo_path = $docinfo['path'];
         //Sometimes the new scorm-tool adds '/.' at the end of a directory name, so remove this before continue
         //the process -- bmol
         if (substr($this->mdo_path, -2) == '/.') {
             $this->mdo_path = substr($this->mdo_path, 0, strlen($this->mdo_path) - 2);
         }
         $this->mdo_comment = $docinfo['description'];
         //Don't think the next line is correct. There used to be a 'type' field in the scormdocument table.
         //This metadata tool only works on folder types -- bmol
         $this->mdo_filetype = $docinfo['lp_type'] == 2 ? 'folder' : 'xxx';
         $this->mdo_url = get_course_web() . $this->mdo_course['path'] . '/scorm/' . $this->mdo_path . '/index.php';
     }
 }
 /**
  * @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());
 }
 public function uninstall()
 {
     $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
     $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
     //New settings
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'openmeetings_tool_enable'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'openmeetings_pass'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'openmeetings_user'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'openmeetings_host'";
     Database::query($sql);
     //Old settings deleting just in case
     $sql = "DELETE FROM {$t_settings} WHERE variable = 'openmeetings_plugin'";
     Database::query($sql);
     $sql = "DELETE FROM {$t_options} WHERE variable  = 'openmeetings_plugin'";
     Database::query($sql);
     //        $sql = "DELETE FROM $t_settings WHERE variable = 'openmeetings_plugin_host'";
     //        Database::query($sql);
     //        $sql = "DELETE FROM $t_settings WHERE variable = 'openmeetings_plugin_salt'";
     //        Database::query($sql);
     //hack to get rid of Database::query warning (please add c_id...)
     $sql = "DELETE FROM {$t_tool} WHERE name = 'openmeetings' AND c_id = c_id";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS plugin_openmeetings";
     Database::query($sql);
     //Deleting course settings
     $this->uninstall_course_fields_in_all_courses();
 }
 /**
  * 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;
    }
}
/**
 *	@package chamilo.survey
 *	@author Arnaud Ligot <*****@*****.**>
 *	@version $Id: $
 *
 *	A small peace of code to enable user to access images included into survey
 *	which are accessible by non authenticated users. This file is included
 *	by document/download.php
 */
function check_download_survey($course, $invitation, $doc_url)
{
    require_once 'survey.lib.php';
    // Getting all the course information
    $_course = CourseManager::get_course_information($course);
    $course_id = $_course['real_id'];
    // Database table definitions
    $table_survey = Database::get_course_table(TABLE_SURVEY);
    $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
    $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
    $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
    // Now we check if the invitationcode is valid
    $sql = "SELECT * FROM {$table_survey_invitation}\n\t        WHERE\n\t            c_id = {$course_id} AND\n\t            invitation_code = '" . Database::escape_string($invitation) . "'";
    $result = Database::query($sql);
    if (Database::num_rows($result) < 1) {
        Display::display_error_message(get_lang('WrongInvitationCode'), false);
        Display::display_footer();
        exit;
    }
    $survey_invitation = Database::fetch_assoc($result);
    // Now we check if the user already filled the survey
    if ($survey_invitation['answered'] == 1) {
        Display::display_error_message(get_lang('YouAlreadyFilledThisSurvey'), false);
        Display::display_footer();
        exit;
    }
    // Very basic security check: check if a text field from a survey/answer/option contains the name of the document requested
    // Fetch survey ID
    // If this is the case there will be a language choice
    $sql = "SELECT * FROM {$table_survey}\n\t        WHERE\n\t            c_id = {$course_id} AND\n\t            code='" . Database::escape_string($survey_invitation['survey_code']) . "'";
    $result = Database::query($sql);
    if (Database::num_rows($result) > 1) {
        if ($_POST['language']) {
            $survey_invitation['survey_id'] = $_POST['language'];
        } else {
            echo '<form id="language" name="language" method="POST" action="' . api_get_self() . '?course=' . $_GET['course'] . '&invitationcode=' . $_GET['invitationcode'] . '">';
            echo '  <select name="language">';
            while ($row = Database::fetch_assoc($result)) {
                echo '<option value="' . $row['survey_id'] . '">' . $row['lang'] . '</option>';
            }
            echo '</select>';
            echo '  <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />';
            echo '</form>';
            display::display_footer();
            exit;
        }
    } else {
        $row = Database::fetch_assoc($result);
        $survey_invitation['survey_id'] = $row['survey_id'];
    }
    $sql = "SELECT count(*)\n\t        FROM {$table_survey}\n\t        WHERE\n\t            c_id = {$course_id} AND\n\t            survey_id = " . $survey_invitation['survey_id'] . " AND (\n                    title LIKE '%{$doc_url}%'\n                    or subtitle LIKE '%{$doc_url}%'\n                    or intro LIKE '%{$doc_url}%'\n                    or surveythanks LIKE '%{$doc_url}%'\n                )\n\t\t    UNION\n\t\t        SELECT count(*)\n\t\t        FROM {$table_survey_question}\n\t\t        WHERE\n\t\t            c_id = {$course_id} AND\n\t\t            survey_id = " . $survey_invitation['survey_id'] . " AND (\n                        survey_question LIKE '%{$doc_url}%'\n                        or survey_question_comment LIKE '%{$doc_url}%'\n                    )\n\t\t    UNION\n\t\t        SELECT count(*)\n\t\t        FROM {$table_survey_question_option}\n\t\t        WHERE\n\t\t            c_id = {$course_id} AND\n\t\t            survey_id = " . $survey_invitation['survey_id'] . " AND (\n                        option_text LIKE '%{$doc_url}%'\n                    )";
    $result = Database::query($sql);
    if (Database::num_rows($result) == 0) {
        Display::display_error_message(get_lang('WrongInvitationCode'), false);
        Display::display_footer();
        exit;
    }
    return $_course;
}
Example #12
0
 /**
  * Update in database
  */
 public function update_in_bdd()
 {
     $item_view_table = Database::get_course_table(TABLE_LP_ITEM);
     if ($this->c_id > 0 && $this->id > 0) {
         $sql = "UPDATE {$item_view_table} SET\n                        lp_id = '" . intval($this->lp_id) . "' ,\n                        item_type = '" . Database::escape_string($this->item_type) . "' ,\n                        ref = '" . Database::escape_string($this->ref) . "' ,\n                        title = '" . Database::escape_string($this->title) . "' ,\n                        description = '" . Database::escape_string($this->description) . "' ,\n                        path = '" . Database::escape_string($this->path) . "' ,\n                        min_score = '" . Database::escape_string($this->min_score) . "' ,\n                        max_score = '" . Database::escape_string($this->max_score) . "' ,\n                        mastery_score = '" . Database::escape_string($this->mastery_score) . "' ,\n                        parent_item_id = '" . Database::escape_string($this->parent_item_id) . "' ,\n                        previous_item_id = '" . Database::escape_string($this->previous_item_id) . "' ,\n                        next_item_id = '" . Database::escape_string($this->next_item_id) . "' ,\n                        display_order = '" . Database::escape_string($this->display_order) . "' ,\n                        prerequisite = '" . Database::escape_string($this->prerequisite) . "' ,\n                        parameters = '" . Database::escape_string($this->parameters) . "' ,\n                        launch_data = '" . Database::escape_string($this->launch_data) . "' ,\n                        max_time_allowed = '" . Database::escape_string($this->max_time_allowed) . "' ,\n                        terms = '" . Database::escape_string($this->terms) . "' ,\n                        search_did = '" . Database::escape_string($this->search_did) . "' ,\n                        audio = '" . Database::escape_string($this->audio) . "'\n                    WHERE c_id=" . $this->c_id . " AND id=" . $this->id;
         Database::query($sql);
     }
 }
Example #13
0
 /**
  * Get glossary term by glossary id
  * @author Isaac Flores <*****@*****.**>
  * @param String The glossary term name
  * @return String The glossary description
  */
 public static function get_glossary_term_by_glossary_name($glossary_name)
 {
     global $_course;
     $glossary_table = Database::get_course_table(TABLE_GLOSSARY);
     $sql = 'SELECT description FROM ' . $glossary_table . ' WHERE name like trim("' . Database::escape_string($glossary_name) . '") ';
     $rs = Database::query($sql, __FILE__, __LINE__);
     $row = Database::fetch_array($rs);
     return $row['description'];
 }
Example #14
0
function get_cat($catname)
{
    global $_course; $cateq = "category_title='". addslashes($catname) . "'";

    $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
    $result = Database::query("SELECT id FROM $linkcat_table WHERE " . $cateq);

    if (Database::num_rows($result) >= 1 && ($row = Database::fetch_array($result)))
        return $row['id'];  // several categories with same name: take first

    return FALSE;
}
Example #15
0
function reports_modules_quiz_init_forEachCourses($course_code, $course_id, $course_db) {
	global $reports_modules;
	
	$reports_modules_quiz_toolid = reports_getToolId(TOOL_QUIZ);

	array_push($reports_modules['quiz'], 
	  array('keys_query' =>  
		'select '.$course_id.' as course_id, '.
		$reports_modules_quiz_toolid.' as tool_id, '.
		'q.id as child_id, q.title as child_name, '.
		"'".$course_code."'".' as course_code from '.Database::get_course_table(TABLE_QUIZ_TEST).' q ',
		'values_query_function' => 'reports_modules_quiz_quizVal'));		
}
/**
 * Gets the comment about a file from the corresponding database record.
 * @param   string    File path
 * @return  string    Comment from the database record
 * Added conditional to the table if is empty.
 */
function GetComment($path, $course_code = '')
{
    $dbTable = Database::get_course_table(TABLE_DOCUMENT);
    $course_info = api_get_course_info($course_code);
    $path = Database::escape_string($path);
    if (!empty($course_info) && !empty($path)) {
        $query = "SELECT comment FROM {$dbTable} WHERE c_id = {$course_info['real_id']}";
        $result = Database::query($query);
        while ($row = Database::fetch_array($result)) {
            return $row[0];
        }
    }
    return null;
}
Example #17
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // Database table definition
     $this->tbl_wiki = Database::get_course_table(TABLE_WIKI);
     $this->tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS);
     $this->tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE);
     $this->tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
     $this->session_id = api_get_session_id();
     $this->condition_session = api_get_session_condition($this->session_id);
     $this->course_id = api_get_course_int_id();
     $this->group_id = api_get_group_id();
     if (!empty($this->group_id)) {
         $this->groupfilter = ' group_id="' . $this->group_id . '"';
     }
     $this->courseInfo = api_get_course_info();
     $this->url = api_get_path(WEB_CODE_PATH) . 'wiki/index.php?' . api_get_cidreq();
 }
 private function get_announcements($username, $course_code, $announcement_id = 0)
 {
     $session_id = api_get_session_id();
     $condition_session = api_get_session_condition($session_id);
     $announcement_id = $announcement_id == 0 ? "" : "AND announcement.id=" . $announcement_id;
     $user_id = UserManager::get_user_id_from_username($username);
     //$listOfCourses = CourseManager::get_course_information_by_id($course_id);
     $course_info = CourseManager::get_course_information($course_code);
     $course_db = $course_info['db_name'];
     $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db);
     $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT, $course_db);
     $maximum = '12';
     $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $user_id);
     if (api_get_group_id() == 0) {
         $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "'" . "OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ";
     } else {
         $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "'" . "OR ip.to_group_id IN (0, " . api_get_group_id() . ")) ";
     }
     // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
     if (is_array($group_memberships) && count($group_memberships) > 0) {
         $sql = "SELECT\n                            announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                            FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                            WHERE announcement.id = ip.ref\n                            AND ip.tool='announcement'\n                            AND ip.visibility='1'\n                            {$announcement_id}\n                            {$cond_user_id}\n                            {$condition_session}\n                            GROUP BY ip.ref\n                            ORDER BY display_order DESC\n                            LIMIT 0,{$maximum}";
     } else {
         // the user is not member of any group
         // this is an identified user => show the general announcements AND his personal announcements
         if ($user_id) {
             if (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) {
                 $cond_user_id = " AND (ip.lastedit_user_id = '" . api_get_user_id() . "' OR ( ip.to_user_id='" . $user_id . "' OR ip.to_group_id='0')) ";
             } else {
                 $cond_user_id = " AND ( ip.to_user_id='" . $user_id . "' OR ip.to_group_id='0') ";
             }
             $sql = "SELECT\n                                    announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                                    FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                                    WHERE announcement.id = ip.ref\n                                    AND ip.tool='announcement'\n                                    AND ip.visibility='1'\n                                    {$announcement_id}\n                                    {$cond_user_id}\n                                    {$condition_session}\n                                    GROUP BY ip.ref\n                                    ORDER BY display_order DESC\n                                    LIMIT 0,{$maximum}";
         } else {
             if (api_get_course_setting('allow_user_edit_announcement')) {
                 $cond_user_id = " AND (ip.lastedit_user_id = '" . api_get_user_id() . "' OR ip.to_group_id='0') ";
             } else {
                 $cond_user_id = " AND ip.to_group_id='0' ";
             }
             // the user is not identiefied => show only the general announcements
             $sql = "SELECT\n                                    announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id\n                                    FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n                                    WHERE announcement.id = ip.ref\n                                    AND ip.tool='announcement'\n                                    AND ip.visibility='1'\n                                    AND ip.to_group_id='0'\n                                    {$announcement_id}\n                                    {$condition_session}\n                                    GROUP BY ip.ref\n                                    ORDER BY display_order DESC\n                                    LIMIT 0,{$maximum}";
         }
     }
     $result = Database::query($sql);
     return $result;
 }
 /**
  * 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 #20
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;
 }
    /**
     * Get document information
     */
    private function get_information($course_id, $doc_id) {
        $course_information = api_get_course_info($course_id);
        $course_id = $course_information['real_id'];
        $course_path = $course_information['path'];
        if (!empty($course_information)) {
            $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
            $doc_table = Database::get_course_table(TABLE_DOCUMENT);

            $doc_id = intval($doc_id);
            $sql = "SELECT * FROM       $doc_table
                    WHERE      $doc_table.id = $doc_id AND c_id = $course_id 
                    LIMIT 1";
            $dk_result = Database::query($sql);

            $sql = "SELECT insert_user_id FROM       $item_property_table
                    WHERE   ref = $doc_id AND tool = '" . TOOL_DOCUMENT . "' AND c_id = $course_id 
                    LIMIT 1";
            $name = '';
            if ($row = Database::fetch_array($dk_result)) {
                $name = $row['title'];
                $url = api_get_path(WEB_PATH) . 'courses/%s/document%s';
                $url = sprintf($url, $course_path, $row['path']);
                // Get the image path
                include_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php';
                $icon = choose_image(basename($row['path']));
                $thumbnail = api_get_path(WEB_CODE_PATH) . 'img/' . $icon;
                $image = $thumbnail;
                //FIXME: use big images
                // get author
                $author = '';
                $item_result = Database::query($sql);
                if ($row = Database::fetch_array($item_result)) {
                    $user_data = api_get_user_info($row['insert_user_id']);
                    $author = api_get_person_name($user_data['firstName'], $user_data['lastName']);
                }
            }
            return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here?
        } else {
            return array();
        }
    }
 /**
  * Uninstall the ticket plugin
  */
 public function uninstall()
 {
     $tblSettings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
     $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $tblTicketTicket = Database::get_main_table(TABLE_TICKET_TICKET);
     $tblTicketStatus = Database::get_main_table(TABLE_TICKET_STATUS);
     $tblTicketProject = Database::get_main_table(TABLE_TICKET_PROJECT);
     $tblTicketPriority = Database::get_main_table(TABLE_TICKET_PRIORITY);
     $tblTicketMesAttch = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
     $tblTicketMessage = Database::get_main_table(TABLE_TICKET_MESSAGE);
     $tblTicketCategory = Database::get_main_table(TABLE_TICKET_CATEGORY);
     $tblTicketAssgLog = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
     $settings = $this->get_settings();
     $plugSetting = current($settings);
     //Delete settings
     $sql = "DELETE FROM {$tblSettings} WHERE variable = 'ticket_tool_enable'";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketTicket}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketStatus}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketProject}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketPriority}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketMesAttch}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketMessage}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketCategory}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketAssgLog}";
     Database::query($sql);
     $sql = "DROP TABLE IF EXISTS {$tblTicketTicket}";
     Database::query($sql);
     $rsTab = $this->deleteTab($plugSetting['comment']);
     if ($rsTab) {
         echo "<script>location.href = '" . $_SERVER['REQUEST_URI'] . "';</script>";
     }
 }
/**
 * 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;
    }
}
 /**
  * Get learning path information
  */
 private function get_information($course_id, $lp_id, $has_document_id = TRUE)
 {
     $course_information = api_get_course_info($course_id);
     $course_id = $course_information['real_id'];
     $course_path = $course_information['path'];
     if (!empty($course_information)) {
         $lpi_table = Database::get_course_table(TABLE_LP_ITEM);
         $lp_table = Database::get_course_table(TABLE_LP_MAIN);
         $doc_table = Database::get_course_table(TABLE_DOCUMENT);
         $lp_id = Database::escape_string($lp_id);
         if ($has_document_id) {
             $sql = "SELECT {$lpi_table}.id, {$lp_table}.name, {$lp_table}.author, {$doc_table}.path\n                    FROM       {$lp_table}, {$lpi_table}\n                    INNER JOIN {$doc_table} ON {$lpi_table}.path = {$doc_table}.id  AND {$lpi_table}.c_id = {$course_id}\n                    WHERE       {$lpi_table}.c_id = {$course_id} AND \n                                {$doc_table}.c_id = {$course_id} AND \n                                {$lpi_table}.lp_id = {$lp_id}  AND        \n                                {$lpi_table}.display_order = 1 AND        \n                                {$lp_table}.id = {$lpi_table}.lp_id\n                    LIMIT 1";
         } else {
             $sql = "SELECT {$lpi_table}.id, {$lp_table}.name, {$lp_table}.author\n                    FROM       {$lp_table}, {$lpi_table}\n                    WHERE      \n                                {$lpi_table}.c_id = {$course_id} AND \n                                {$lp_table}.c_id = {$course_id} AND \n                                {$lpi_table}.lp_id = {$lp_id} AND        \n                                {$lpi_table}.display_order = 1 AND      \n                                {$lp_table}.id = {$lpi_table}.lp_id\n                    LIMIT 1";
         }
         $dk_result = Database::query($sql);
         $path = '';
         $name = '';
         if ($row = Database::fetch_array($dk_result)) {
             // Get the image path
             $img_location = api_get_path(WEB_COURSE_PATH) . $course_path . "/document/";
             $thumbnail_path = str_replace('.png.html', '_thumb.png', $row['path']);
             $big_img_path = str_replace('.png.html', '.png', $row['path']);
             $thumbnail = '';
             if (!empty($thumbnail_path)) {
                 $thumbnail = $img_location . $thumbnail_path;
             }
             $image = '';
             if (!empty($big_img_path)) {
                 $image = $img_location . $big_img_path;
             }
             $name = $row['name'];
         }
         return array($thumbnail, $image, $name, $row['author']);
     } else {
         return array();
     }
 }
/**
 * @param bool $debug
 *
 * @return int total size in MB
 */
function calculateTotalPortalSize($debug)
{
    $table = Database::get_course_table(TABLE_DOCUMENT);
    // Documents
    $sql = "SELECT SUM(size) total FROM {$table}\n            WHERE filetype = 'file' AND c_id <> ''";
    $result = Database::query($sql);
    $row = Database::fetch_array($result, 'ASSOC');
    $totalSize = $row['total'];
    if ($debug) {
        echo "Total size in table {$table} " . round($totalSize / 1024) . " MB \n";
    }
    $table = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
    $sql = "SELECT SUM(size) total FROM {$table} WHERE c_id <> ''";
    $result = Database::query($sql);
    $row = Database::fetch_array($result, 'ASSOC');
    $subTotal = $row['total'];
    $totalSize += $subTotal;
    if ($debug) {
        echo "Total size in table {$table} " . round($subTotal / 1024) . " MB \n";
    }
    $totalSize = $totalSize / 1024;
    return $totalSize;
}
 /**
  * @param array $params
  * @return int
  */
 public function saveMedia($params)
 {
     $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $course_id = '';
     $questionName = '';
     if (!empty($this->course['real_id'])) {
         $course_id = $this->course['real_id'];
     } else {
         throw new Exception('Missing $this->course info in MediaQuestion::saveMedia()');
     }
     if (isset($params['questionName'])) {
         $questionName = $params['questionName'];
     } else {
         throw new Exception('Missing questionName in $params in MediaQuestion::saveMedia()');
     }
     $questionDescription = isset($params['questionDescription']) ? $params['questionDescription'] : '';
     $new_params = array('c_id' => $course_id, 'question' => $questionName, 'description' => $questionDescription, 'parent_id' => 0, 'type' => MEDIA_QUESTION);
     if (isset($this->id) && !empty($this->id)) {
         Database::update($table_question, $new_params, array('iid = ? and c_id = ?' => array($this->id, $course_id)));
     } else {
         return Database::insert($table_question, $new_params);
     }
 }
/**
 * 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;
}
 /**
  * Get document information
  */
 private function get_information($course_id, $doc_id)
 {
     $course_information = api_get_course_info($course_id);
     $course_id = $course_information['real_id'];
     $course_path = $course_information['path'];
     if (!empty($course_information)) {
         $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $doc_table = Database::get_course_table(TABLE_DOCUMENT);
         $doc_id = Database::escape_string($doc_id);
         $sql = "SELECT * FROM       {$doc_table}\n                    WHERE      {$doc_table}.id = {$doc_id} AND c_id = {$course_id}\n                    LIMIT 1";
         $dk_result = Database::query($sql);
         $sql = "SELECT insert_user_id FROM       {$item_property_table}\n                    WHERE   ref = {$doc_id} AND tool = '" . TOOL_DOCUMENT . "' AND c_id = {$course_id}\n                    LIMIT 1";
         $name = '';
         if ($row = Database::fetch_array($dk_result)) {
             $name = $row['title'];
             $url = api_get_path(WEB_PATH) . 'courses/%s/document%s';
             $url = sprintf($url, $course_path, $row['path']);
             // Get the image path
             $icon = FileManager::choose_image(basename($row['path']));
             $thumbnail = api_get_path(WEB_IMG_PATH) . $icon;
             $image = $thumbnail;
             //FIXME: use big images
             // get author
             $author = '';
             $item_result = Database::query($sql);
             if ($row = Database::fetch_array($item_result)) {
                 $user_data = api_get_user_info($row['insert_user_id']);
                 $author = api_get_person_name($user_data['firstName'], $user_data['lastName']);
             }
         }
         return array($thumbnail, $image, $name, $author, $url);
         // FIXME: is it posible to get an author here?
     } else {
         return array();
     }
 }
Example #29
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';
 }
Example #30
0
</script>';
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'];