Пример #1
0
 function doListAnnotations($url, $username, $block)
 {
     $query = new AnnotationSummaryQuery($url, $username, null, null);
     if ($query->error) {
         $this->httpError(400, 'Bad Request', 'Bad URL');
         return null;
     } elseif (isguest() && ANNOTATION_REQUIRE_USER) {
         $this->httpError(403, 'Forbidden', 'Anonymous listing not allowed');
         return null;
     } else {
         $querySql = $query->sql('section_type, section_name, quote_title');
         $annotationSet = get_records_sql($querySql);
         $annotations = array();
         if ($annotationSet) {
             $i = 0;
             foreach ($annotationSet as $r) {
                 $annotations[$i++] = AnnotationGlobals::recordToAnnotation($r);
             }
         }
         $format = $this->getQueryParam('format', 'atom');
         $logUrl = 'annotate.php?format=' . $format . ($username ? '&user='******'') . '&url=' . $url;
         add_to_log($query->handler->courseId, 'annotation', 'list', $logUrl);
         return $annotations;
     }
 }
 /**
  * gets all workshops for the config tree
  */
 function get_all_gradable_items()
 {
     global $CFG;
     $sql = "SELECT w.id, w.course, w.name, w.description as summary, c.id as cmid\n                  FROM {$CFG->prefix}workshop w\n            INNER JOIN {$CFG->prefix}course_modules c\n                    ON w.id = c.instance\n                 WHERE c.module = {$this->mainobject->modulesettings['workshop']->id}\n                   AND c.visible = 1\n                   AND w.course IN ({$this->mainobject->course_ids})\n              ORDER BY w.id";
     $workshops = get_records_sql($sql);
     $this->assessments = $workshops;
 }
function map_get_cells($brainstormid, $userid = null, $groupid = 0, $configdata = null)
{
    global $CFG;
    $accessClause = brainstorm_get_accessclauses($userid, $groupid);
    $sql = "\r\n        SELECT\r\n            id,\r\n            itemsource,\r\n            itemdest,\r\n            intvalue,\r\n            floatvalue,\r\n            blobvalue\r\n         FROM\r\n            {$CFG->prefix}brainstorm_operatordata AS od\r\n         WHERE\r\n            brainstormid = {$brainstormid} AND\r\n            operatorid = 'map'\r\n            {$accessClause}\r\n    ";
    $map = array();
    if ($maprecords = get_records_sql($sql)) {
        foreach ($maprecords as $record) {
            if (!$configdata || !@$configdata->quantified) {
                $map[$record->itemsource][$record->itemdest] = 1;
            } else {
                switch ($configdata->quantifiertype) {
                    case 'integer':
                        $map[$record->itemsource][$record->itemdest] = $record->intvalue;
                        break;
                    case 'float':
                        $map[$record->itemsource][$record->itemdest] = $record->floatvalue;
                        break;
                    case 'multiple':
                        $map[$record->itemsource][$record->itemdest] = unserialize($record->blobvalue);
                        break;
                    default:
                }
            }
        }
    }
    return $map;
}
function ma_delete_execute($modids)
{
    global $CFG;
    $in_list = "(" . join(", ", $modids) . ")";
    $sql = "SELECT cm.id as coursemodule, cm.section, cm.course, mo.name as modulename, instance\n        FROM {$CFG->prefix}course_modules cm\n        LEFT JOIN {$CFG->prefix}modules mo on mo.id=cm.module\n        WHERE cm.id IN {$in_list}";
    $records = get_records_sql($sql);
    $courses = array();
    $message = '';
    if ($records) {
        foreach ($records as $id => $record) {
            $modlib = "{$CFG->dirroot}/mod/{$record->modulename}/lib.php";
            $courses[] = $record->course;
            if (file_exists($modlib)) {
                include_once $modlib;
            } else {
                $message .= "This module is missing important code! ({$modlib})  ";
                continue;
            }
            $deleteinstancefunction = $record->modulename . "_delete_instance";
            if (!$deleteinstancefunction($record->instance)) {
                $message .= "Could not delete the {$record->modulename} (instance)  ";
                continue;
            }
            if (!delete_course_module($record->coursemodule)) {
                $message .= "Could not delete the {$record->modulename} (coursemodule)  ";
                continue;
            }
            if (!delete_mod_from_section($record->coursemodule, "{$record->section}")) {
                $message .= "Could not delete the {$record->modulename} from that section  ";
                continue;
            }
        }
    }
    return $message;
}
function resource_get_links(&$course, &$mod, $exclude_sitefile = true)
{
    global $CFG;
    $sql = "SELECT r.id, r.reference, r.name, r.summary, r.alltext, cm.id AS cmid\r\n             FROM {$CFG->prefix}resource r,\r\n                  {$CFG->prefix}course_modules cm,\r\n                  {$CFG->prefix}modules m\r\n             WHERE r.course    = '{$course->id}'\r\n               AND m.name      = 'resource'\r\n               AND cm.module   = m.id\r\n               AND cm.instance = r.id\r\n               AND cm.id = {$mod->id}";
    if ($resources = get_records_sql($sql)) {
        // 各テキストの取得
        $links = array();
        foreach ($resources as $resource) {
            preg_match_all('|/file.php/([^\\"]+)|', $resource->alltext, $matches);
            $links = array_merge($links, $matches[1]);
            preg_match_all('|/file.php/([^\\"]+)|', $resource->summary, $matches);
            $links = array_merge($links, $matches[1]);
            if (trim($resource->reference) && stristr($resource->reference, 'http://') === false || stristr($resources->reference, 'file.php/')) {
                $links[] = $course->id . '/' . $resource->reference;
            }
        }
        // 2008-10-29 暫定処置
        if ($exclude_sitefile) {
            $links = array_filter($links, 'is_not_sitefile');
        }
        return $links;
    } else {
        return null;
    }
}
 function get_content()
 {
     global $THEME, $CFG, $USER;
     // only for logged in users!
     if (!isloggedin() || isguest()) {
         return false;
     }
     // check for outgoing roaming permission first
     if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
         return '';
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     // TODO: Test this query - it's appropriate? It works?
     // get the hosts and whether we are doing SSO with them
     $sql = "\n             SELECT DISTINCT \n                 h.id, \n                 h.name,\n                 h.wwwroot,\n                 a.name as application,\n                 a.display_name\n             FROM \n                 {$CFG->prefix}mnet_host h,\n                 {$CFG->prefix}mnet_application a,\n                 {$CFG->prefix}mnet_host2service h2s_IDP,\n                 {$CFG->prefix}mnet_service s_IDP,\n                 {$CFG->prefix}mnet_host2service h2s_SP,\n                 {$CFG->prefix}mnet_service s_SP\n             WHERE\n                 h.id != '{$CFG->mnet_localhost_id}' AND\n                 h.id = h2s_IDP.hostid AND\n                 h.applicationid = a.id AND\n                 h2s_IDP.serviceid = s_IDP.id AND\n                 s_IDP.name = 'sso_idp' AND\n                 h2s_IDP.publish = '1' AND\n                 h.id = h2s_SP.hostid AND\n                 h2s_SP.serviceid = s_SP.id AND\n                 s_SP.name = 'sso_idp' AND\n                 h2s_SP.publish = '1'\n             ORDER BY\n                 a.display_name,\n                 h.name";
     $hosts = get_records_sql($sql);
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if ($hosts) {
         foreach ($hosts as $host) {
             $icon = '<img src="' . $CFG->pixpath . '/i/' . $host->application . '_host.gif"' . ' class="icon" alt="' . get_string('server', 'block_mnet_hosts') . '" />';
             $this->content->icons[] = $icon;
             if ($host->id == $USER->mnethostid) {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$host->wwwroot}\">" . s($host->name) . "</a>";
             } else {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) . "</a>";
             }
         }
     }
     return $this->content;
 }
Пример #7
0
 function display_search_field($content = '')
 {
     global $CFG;
     $varcharcontent = sql_compare_text('content', 255);
     $sql = "SELECT DISTINCT {$varcharcontent} AS content\n                  FROM {$CFG->prefix}data_content\n                 WHERE fieldid={$this->field->id} AND content IS NOT NULL";
     $usedoptions = array();
     if ($used = get_records_sql($sql)) {
         foreach ($used as $data) {
             $value = $data->content;
             if ($value === '') {
                 continue;
             }
             $usedoptions[$value] = $value;
         }
     }
     $options = array();
     foreach (explode("\n", $this->field->param1) as $option) {
         $option = trim($option);
         if (!isset($usedoptions[$option])) {
             continue;
         }
         $options[$option] = $option;
     }
     if (!$options) {
         // oh, nothing to search for
         return '';
     }
     return choose_from_menu($options, 'f_' . $this->field->id, stripslashes($content), 'choose', '', 0, true);
 }
Пример #8
0
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function question_dataset_dependent_items_form($submiturl, $question, $regenerate)
 {
     global $QTYPES, $SESSION, $CFG;
     $this->regenerate = $regenerate;
     $this->question = $question;
     $this->qtypeobj =& $QTYPES[$this->question->qtype];
     //get the dataset defintions for this question
     if (empty($question->id)) {
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->datasetdependent->definitionform->dataset);
     } else {
         if (empty($question->options)) {
             $this->get_question_options($question);
         }
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
     }
     foreach ($this->datasetdefs as $datasetdef) {
         // Get maxnumber
         if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
             $this->maxnumber = $datasetdef->itemcount;
         }
     }
     foreach ($this->datasetdefs as $defid => $datasetdef) {
         if (isset($datasetdef->id)) {
             $this->datasetdefs[$defid]->items = get_records_sql(" SELECT itemnumber, definition, id, value\n                          FROM {$CFG->prefix}question_dataset_items\n                          WHERE definition = {$datasetdef->id} ");
         }
     }
     parent::moodleform($submiturl);
 }
Пример #9
0
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function question_dataset_dependent_items_form($submiturl, $question, $regenerate)
 {
     global $QTYPES, $SESSION, $CFG;
     $this->regenerate = $regenerate;
     $this->question = $question;
     $this->qtypeobj =& $QTYPES[$this->question->qtype];
     // Validate the question category.
     if (!($category = get_record('question_categories', 'id', $question->category))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = get_context_instance_by_id($category->contextid);
     //get the dataset defintions for this question
     if (empty($question->id)) {
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->datasetdependent->definitionform->dataset);
     } else {
         if (empty($question->options)) {
             $this->get_question_options($question);
         }
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
     }
     foreach ($this->datasetdefs as $datasetdef) {
         // Get maxnumber
         if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
             $this->maxnumber = $datasetdef->itemcount;
         }
     }
     foreach ($this->datasetdefs as $defid => $datasetdef) {
         if (isset($datasetdef->id)) {
             $this->datasetdefs[$defid]->items = get_records_sql(" SELECT itemnumber, definition, id, value\n                          FROM {$CFG->prefix}question_dataset_items\n                          WHERE definition = {$datasetdef->id} ");
         }
     }
     parent::moodleform($submiturl);
 }
Пример #10
0
function data_filter($courseid, $text)
{
    global $CFG;
    static $nothingtodo;
    static $contentlist;
    if (!empty($nothingtodo)) {
        // We've been here in this page already
        return $text;
    }
    // if we don't have a courseid, we can't run the query, so
    if (empty($courseid)) {
        return $text;
    }
    // Create a list of all the resources to search for. It may be cached already.
    if (empty($contentlist)) {
        // We look for text field contents only, and only if the field has
        // autolink enabled (param1).
        $sql = 'SELECT dc.id AS contentid, ' . 'dr.id AS recordid, ' . 'dc.content AS content, ' . 'd.id AS dataid ' . 'FROM ' . $CFG->prefix . 'data d, ' . $CFG->prefix . 'data_fields df, ' . $CFG->prefix . 'data_records dr, ' . $CFG->prefix . 'data_content dc ' . "WHERE (d.course = '{$courseid}' or d.course = '" . SITEID . "')" . 'AND d.id = df.dataid ' . 'AND df.id = dc.fieldid ' . 'AND d.id = dr.dataid ' . 'AND dr.id = dc.recordid ' . "AND df.type = 'text' " . "AND " . sql_compare_text('df.param1', 1) . " = '1'";
        if (!($datacontents = get_records_sql($sql))) {
            return $text;
        }
        $contentlist = array();
        foreach ($datacontents as $datacontent) {
            $currentcontent = trim($datacontent->content);
            $strippedcontent = strip_tags($currentcontent);
            if (!empty($strippedcontent)) {
                $contentlist[] = new filterobject($currentcontent, '<a class="data autolink" title="' . $strippedcontent . '" href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $datacontent->dataid . '&amp;rid=' . $datacontent->recordid . '" ' . $CFG->frametarget . '>', '</a>', false, true);
            }
        }
        // End foreach
    }
    return filter_phrases($text, $contentlist);
    // Look for all these links in the text
}
Пример #11
0
/**
 * Load the question data necessary in the reports.
 * - Remove description questions.
 * - Order questions in order that they are in the quiz
 * - Add question numbers.
 * - Add grade from quiz_questions_instance
 */
function quiz_report_load_questions($quiz)
{
    global $CFG;
    $questionlist = quiz_questions_in_quiz($quiz->questions);
    //In fact in most cases the id IN $questionlist below is redundant
    //since we are also doing a JOIN on the qqi table. But will leave it in
    //since this double check will probably do no harm.
    if (!($questions = get_records_sql("SELECT q.*, qqi.grade " . "FROM {$CFG->prefix}question q, " . "{$CFG->prefix}quiz_question_instances qqi " . "WHERE q.id IN ({$questionlist}) AND " . "qqi.question = q.id AND " . "qqi.quiz =" . $quiz->id))) {
        print_error('No questions found');
    }
    //Now we have an array of questions from a quiz we work out there question nos and remove
    //questions with zero length ie. description questions etc.
    //also put questions in order.
    $number = 1;
    $realquestions = array();
    $questionids = explode(',', $questionlist);
    foreach ($questionids as $id) {
        if ($questions[$id]->length) {
            // Ignore questions of zero length
            $realquestions[$id] = $questions[$id];
            $realquestions[$id]->number = $number;
            $number += $questions[$id]->length;
        }
    }
    return $realquestions;
}
Пример #12
0
 function get_question_options(&$question)
 {
     // Get the question answers and their respective tolerances
     // Note: question_numerical is an extension of the answer table rather than
     //       the question table as is usually the case for qtype
     //       specific tables.
     global $CFG;
     if (!($question->options->answers = get_records_sql("SELECT a.*, n.tolerance " . "FROM {$CFG->prefix}question_answers a, " . "     {$CFG->prefix}question_numerical n " . "WHERE a.question = {$question->id} " . "    AND   a.id = n.answer " . "ORDER BY a.id ASC"))) {
         notify('Error: Missing question answer!');
         return false;
     }
     $this->get_numerical_units($question);
     // If units are defined we strip off the default unit from the answer, if
     // it is present. (Required for compatibility with the old code and DB).
     if ($defaultunit = $this->get_default_numerical_unit($question)) {
         foreach ($question->options->answers as $key => $val) {
             $answer = trim($val->answer);
             $length = strlen($defaultunit->unit);
             if ($length && substr($answer, -$length) == $defaultunit->unit) {
                 $question->options->answers[$key]->answer = substr($answer, 0, strlen($answer) - $length);
             }
         }
     }
     return true;
 }
Пример #13
0
 function get_content()
 {
     global $USER, $CFG;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) {
         return $this->content;
     }
     $this->content->footer = '<a href="' . $CFG->wwwroot . '/message/index.php" onclick="this.target=\'message\'; return openpopup(\'/message/index.php\', \'message\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">' . get_string('messages', 'message') . '</a>...';
     $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,\n                                         u.firstname, u.lastname, u.picture, u.lastaccess\n                                       FROM {$CFG->prefix}user u, \n                                            {$CFG->prefix}message m \n                                       WHERE m.useridto = '{$USER->id}' \n                                         AND u.id = m.useridfrom\n                                    GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess");
     //Now, we have in users, the list of users to show
     //Because they are online
     if (!empty($users)) {
         $this->content->text .= '<ul class="list">';
         foreach ($users as $user) {
             $timeago = format_time(time() - $user->lastaccess);
             $this->content->text .= '<li class="listentry"><div class="user"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $this->instance->pageid . '" title="' . $timeago . '">';
             $this->content->text .= print_user_picture($user->id, $this->instance->pageid, $user->picture, 0, true, false, '', false);
             $this->content->text .= fullname($user) . '</a></div>';
             $this->content->text .= '<div class="message"><a href="' . $CFG->wwwroot . '/message/discussion.php?id=' . $user->id . '" onclick="this.target=\'message_' . $user->id . '\'; return openpopup(\'/message/discussion.php?id=' . $user->id . '\', \'message_' . $user->id . '\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);"><img class="iconsmall" src="' . $CFG->pixpath . '/t/message.gif" alt="" />&nbsp;' . $user->count . '</a>';
             $this->content->text .= '</div></li>';
         }
         $this->content->text .= '</ul>';
     } else {
         $this->content->text .= '<div class="info">';
         $this->content->text .= get_string('nomessages', 'message');
         $this->content->text .= '</div>';
     }
     return $this->content;
 }
Пример #14
0
/**
 * Retrieve the wall for a given userid.
 *
 * @return mixed Array of comment objects, else returns false.
 * @param unknown_type $userid The user / wall we are retrieving
 * @param unknown_type $limit Limit on the search
 * @param unknown_type $offset Offset
 */
function commentwall_getwall($userid, $limit = 3, $offset = 0)
{
    global $CFG;
    $query = "SELECT * from {$CFG->prefix}commentwall where wallowner={$userid} order by posted desc limit {$offset},{$limit}";
    // echo $query;
    return get_records_sql($query);
}
Пример #15
0
 function doListAnnotations($url, $username, $block, $all)
 {
     $handler = annotation_summary_query::handler_for_url($url);
     $user = get_record('user', 'username', $username);
     $summary = new annotation_summary_query($url, $handler, null, $user, null, false, $all);
     if ($summary->error) {
         $this->httpError(400, 'Bad Request', 'Bad URL 1');
         return null;
     } elseif (!isloggedin() && ANNOTATION_REQUIRE_USER) {
         $this->httpError(403, 'Forbidden', 'Anonymous listing not allowed');
         return null;
     } else {
         $querysql = $summary->sql('section_type, section_name, quote_title, start_block, start_line, start_word, start_char, end_block, end_line, end_word, end_char');
         $annotation_set = get_records_sql($querysql);
         $annotations = array();
         if ($annotation_set) {
             $i = 0;
             foreach ($annotation_set as $r) {
                 $annotations[$i++] = annotation_globals::record_to_annotation($r);
             }
         }
         $format = $this->getQueryParam('format', 'atom');
         $logurl = 'annotate.php?format=' . $format . ($user ? '&user='******'') . '&url=' . $url;
         add_to_log($summary->handler->courseid, 'annotation', 'list', $logurl);
         return $annotations;
     }
 }
Пример #16
0
/**
 * External function for retrieving module data.
 *
 * Using external method so we can cache results
 * to improve performance for all page_module
 * instances.
 *
 * @param int $cmid Course Module ID
 * @return array
 **/
function block_page_module_init($cmid)
{
    global $COURSE, $CFG, $PAGE, $BLOCK_PAGE_MODULE;
    static $page = false, $baseurl = '';
    if (!$page) {
        if (!empty($PAGE) and get_class($PAGE) == 'format_page') {
            $page = $PAGE->get_formatpage();
        } else {
            require_once $CFG->dirroot . '/course/format/page/lib.php';
            if (!($page = page_get_current_page())) {
                $page = new stdClass();
                $page->id = 0;
            }
        }
        if ($COURSE->id == SITEID) {
            $baseurl = "{$CFG->wwwroot}/index.php?id={$COURSE->id}&amp;page={$page->id}";
        } else {
            $baseurl = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}&amp;page={$page->id}";
        }
        if (!empty($page->id)) {
            // Since we know what page will be printed, lets
            // get all of our records in bulk and cache the results
            if ($cms = get_records_sql("SELECT c.*\n                                           FROM {$CFG->prefix}course_modules c,\n                                                {$CFG->prefix}format_page p,\n                                                {$CFG->prefix}format_page_items i\n                                          WHERE i.cmid = c.id\n                                            AND p.id = i.pageid\n                                            AND p.id = {$page->id}")) {
                // Save for later
                $BLOCK_PAGE_MODULE['cms'] = $cms;
                if ($modules = get_records('modules')) {
                    // Save for later
                    $BLOCK_PAGE_MODULE['modules'] = $modules;
                    $mods = array();
                    foreach ($cms as $cm) {
                        $mods[$modules[$cm->module]->name][] = $cm->instance;
                    }
                    $instances = array();
                    foreach ($mods as $modname => $instanceids) {
                        if ($records = get_records_list($modname, 'id', implode(',', $instanceids))) {
                            $instances[$modname] = $records;
                        }
                    }
                    // Save for later
                    $BLOCK_PAGE_MODULE['instances'] = $instances;
                }
            }
        } else {
            // OK, we cannot do anything cool, make sure we dont break rest of the script
            $BLOCK_PAGE_MODULE = array('cms' => array(), 'modules' => array(), 'instances' => array());
        }
    }
    if (!($cm = block_page_module_get_cm($cmid, $page->id))) {
        return false;
    }
    if (!($module = block_page_module_get_module($cm->module))) {
        return false;
    }
    if (!($moduleinstance = block_page_module_get_instance($module->name, $cm->instance))) {
        return false;
    }
    return array($cm, $module, $moduleinstance, $COURSE, $page, $baseurl);
}
Пример #17
0
function get_friends($username)
{
    global $CFG;
    $uname = addslashes($username);
    if ($data = get_records_sql("\n        SELECT\n            uf.userid || ':' || uf.friendid AS id,\n            uf.userid, u.username, uf.friendid, f.username AS friendusername, uf.approved\n        FROM\n            {$CFG->prefix}user_friend uf\n            JOIN {$CFG->prefix}user u ON uf.userid = u.id\n            JOIN {$CFG->prefix}user f ON uf.friendid = f.id\n        WHERE\n            u.username = '******'\n            OR (f.username = '******' AND uf.approved = 0)")) {
        return $data;
    }
    return array();
}
/**
*
* @uses CFG
* @param int $brainstormid
* @param int $userid
* @param int $groupid
* @param boolean $excludemyself
* @param object $configdata
*/
function merge_get_merges($brainstormid, $userid = null, $groupid = 0, $excludemyself = false, $configdata)
{
    global $CFG;
    $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
    $sql = "\r\n        SELECT\r\n            r.*,\r\n            od.intvalue as slotid,\r\n            od.blobvalue as merged\r\n        FROM\r\n            {$CFG->prefix}brainstorm_responses as r,\r\n            {$CFG->prefix}brainstorm_operatordata as od\r\n        WHERE\r\n            r.id = od.itemsource AND\r\n            r.brainstormid = {$brainstormid} AND\r\n            od.operatorid = 'merge' AND\r\n            od.itemdest IS NOT NULL\r\n            {$accessClause}\r\n        ORDER BY\r\n            od.intvalue,\r\n            userid\r\n    ";
    if (!($merges = get_records_sql($sql))) {
        return array();
    }
    return $merges;
}
/**
* get ordering on distinct contexts. Knows how to get an incomplete ordering.
* @param int $brainstormid
* @param int $userid
* @param int $groupid
* @param boolean $excludemyself
*/
function order_get_ordering($brainstormid, $userid = null, $groupid = 0, $excludemyself = false)
{
    global $CFG;
    $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
    $sql = "\r\n        SELECT\r\n            r.id,\r\n            r.response,\r\n            od.intvalue,\r\n            od.userid,\r\n            od.groupid\r\n        FROM\r\n            {$CFG->prefix}brainstorm_responses as r\r\n        LEFT JOIN\r\n            {$CFG->prefix}brainstorm_operatordata as od\r\n        ON\r\n            r.id = od.itemsource AND\r\n            (od.operatorid = 'order'\r\n            {$accessClause})\r\n        WHERE\r\n            r.brainstormid = {$brainstormid}\r\n         ORDER BY\r\n            od.intvalue, \r\n            od.userid\r\n    ";
    if (!($records = get_records_sql($sql))) {
        return array();
    }
    return $records;
}
/**
*
* @uses CFG, USER
* @param int $brainstormid
* @param int $userid
* @param int $groupid 
* @param boolean $excludemyself
*/
function filter_get_status($brainstormid, $userid = null, $groupid = 0, $excludemyself = false)
{
    global $CFG;
    $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
    $sql = "\r\n        SELECT\r\n            itemsource,\r\n            intvalue,\r\n            od.userid,\r\n            od.groupid,\r\n            response\r\n         FROM\r\n            {$CFG->prefix}brainstorm_operatordata AS od,\r\n            {$CFG->prefix}brainstorm_responses AS r\r\n         WHERE\r\n            od.brainstormid = {$brainstormid} AND\r\n            od.itemsource = r.id AND\r\n            operatorid = 'filter'\r\n            {$accessClause}\r\n    ";
    if (!($statusrecords = get_records_sql($sql))) {
        $statusrecords = array();
    }
    return $statusrecords;
}
/**
*
*
*/
function scale_get_meanscalings($brainstormid, $userid = null, $groupid = 0, $excludemyself = false, $configdata)
{
    global $CFG;
    $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
    $orderClause = @$configdata->ordereddisplay ? ' ORDER BY intvalue, floatvalue ' : '';
    $sql = "\r\n        SELECT\r\n            r.id,\r\n            r.response,\r\n            SUM(od.intvalue) as sumintvalue,\r\n            SUM(od.floatvalue) as sumfloatvalue,\r\n            SUM(od.blobvalue) as sumblobvalue,\r\n            MIN(od.intvalue) as minintvalue,\r\n            MIN(od.floatvalue) as minfloatvalue,\r\n            MIN(od.blobvalue) as minblobvalue,\r\n            MAX(od.intvalue) as maxintvalue,\r\n            MAX(od.floatvalue) as maxfloatvalue,\r\n            MAX(od.blobvalue) as maxblobvalue,\r\n            COUNT(od.intvalue) as countintvalue,\r\n            COUNT(od.floatvalue) as countfloatvalue,\r\n            COUNT(od.blobvalue) as countblobvalue,\r\n            od.userid,\r\n            od.groupid\r\n        FROM\r\n            {$CFG->prefix}brainstorm_responses as r,\r\n            {$CFG->prefix}brainstorm_operatordata as od\r\n        WHERE\r\n            r.id = od.itemsource AND\r\n            operatorid = 'scale' AND\r\n            r.brainstormid = {$brainstormid}\r\n            {$accessClause}\r\n        {$orderClause}\r\n        GROUP BY\r\n            r.id\r\n    ";
    if (!($records = get_records_sql($sql))) {
        return array();
    }
    return $records;
}
 /**
  * This is to build the initial non-ajax set of html nodes for accessibility and non-javascript
  * browsers. It will eventually (hopefully) be used in a progressive enhancement way so that the
  * block exhibits gracful degradation, but this may prove awkward to implement.
  *
  * The output is a ul indented list of courses and assessment items with counts, with each
  * assessment item as a link to the grading page.
  *
  * The ul list can be recycled to make an accessible config tree in time.
  */
 function make_html_list()
 {
     global $CFG;
     $this->initial_setup(true);
     // get each module to do the sorting out - perhaps do this once when the request goes out
     // first.
     $this->html_list = '';
     // Foreach course, ask each module for all of the nodes to be returned as an array, with
     // each item having all the node details.
     foreach ($this->courses as $course) {
         $course_output = '';
         $course_count = 0;
         $courseid = $course->id;
         if (!$course->visible) {
             continue;
         }
         $this->get_course_students($courseid);
         if (!isset($this->student_ids->{$courseid}) || empty($this->student_ids->{$courseid})) {
             // no students in this course
             continue;
         }
         // see which modules are currently enabled
         $sql = "\n                SELECT name \n                FROM {$CFG->prefix}modules\n                WHERE visible = 1\n            ";
         $enabledmods = get_records_sql($sql);
         $enabledmods = array_keys($enabledmods);
         // loop through each module, getting a count for this course id from each one.
         foreach ($this->modulesettings as $modname => $module) {
             if (in_array($modname, $enabledmods)) {
                 $mod_output = $this->{$modname}->course_assessment_nodes($course->id, true);
                 if ($mod_output['count'] > 0) {
                     $course_count += $mod_output['count'];
                     $course_output .= $mod_output['data'];
                 }
             }
         }
         if ($course_count > 0) {
             $this->html_list .= '<ul class="AMB_html">';
             $this->html_list .= '<li class="AMB_html_course">';
             $this->html_list .= $this->add_icon('course');
             $this->html_list .= '<strong>(' . $course_count . ')</strong> ';
             $this->html_list .= $course->shortname;
             $this->html_list .= '</li>';
             $this->html_list .= '<ul class="AMB_html_items">';
             $this->html_list .= $course_output;
             $this->html_list .= '</ul>';
             $this->html_list .= '</ul>';
         }
     }
     if ($this->html_list) {
         return $this->html_list;
     } else {
         return get_string('nothing', 'block_ajax_marking');
     }
 }
Пример #23
0
 /**
  * CUSTOMIZED FOR PAIRFORMANCE
  * needs to get additional information about TAO classification
  *
  */
 function preprocess_data()
 {
     global $COURSE, $CFG;
     $sql = "\r\n            SELECT \r\n                ct.name,\r\n                cv.value\r\n            FROM\r\n                {$CFG->prefix}classification_type ct,\r\n                {$CFG->prefix}classification_value cv,\r\n                {$CFG->prefix}course_classification cc\r\n            WHERE\r\n                ct.id = cv.type AND\r\n                cc.value = cv.id AND\r\n                cc.course = {$COURSE->id}                \r\n        ";
     if ($classification = get_records_sql($sql)) {
         foreach ($classification as $qualifier) {
             $name = $qualifier->name;
             $this->data->{$name} = $qualifier->value;
         }
     }
 }
Пример #24
0
/**
 * Get the number of members in all groups the user can select from in this activity
 *
 * @param $cm Course module slot of the groupselect instance
 * @param $targetgrouping The id of grouping the user can select a group from
 * @return array of objects: [id] => object(->usercount ->id) where id is group id
 */
function groupselect_group_member_counts($cm, $targetgrouping = 0)
{
    global $CFG;
    if (empty($CFG->enablegroupings) or empty($cm->groupingid) or empty($targetgrouping)) {
        //all groups
        $sql = "SELECT g.id, COUNT(gm.userid) AS usercount\n                  FROM {$CFG->prefix}groups_members gm\n                       JOIN {$CFG->prefix}groups g ON g.id = gm.groupid\n                 WHERE g.courseid = {$cm->course}\n              GROUP BY g.id";
    } else {
        $sql = "SELECT g.id, COUNT(gm.userid) AS usercount\n                  FROM {$CFG->prefix}groups_members gm\n                       JOIN {$CFG->prefix}groups g            ON g.id = gm.groupid\n                       JOIN {$CFG->prefix}groupings_groups gg ON gg.groupid = g.id\n                 WHERE g.courseid = {$cm->course}\n                       AND gg.groupingid = {$targetgrouping}\n              GROUP BY g.id";
    }
    return get_records_sql($sql);
}
function tracker_rpc_get_infos($trackerid, $nojson = false)
{
    global $CFG;
    $tracker = get_record('tracker', 'id', "{$trackerid}");
    $query = "\n        SELECT\n            te.name,\n            te.description,\n            te.type \n        FROM\n            {$CFG->prefix}tracker_element te,\n            {$CFG->prefix}tracker_elementused teu\n        WHERE\n            te.id = teu.elementid AND\n            teu.trackerid = {$trackerid}\n    ";
    $elementused = get_records_sql($query);
    $tracker->elements = $elementused;
    if ($nojson) {
        return $tracker;
    }
    return json_encode($tracker);
}
Пример #26
0
function get_profilefields()
{
    global $CFG;
    //get elis user fields as it appears in the db
    //unset any fields that should never be allowed to be changed eg. the id field
    $sql = 'SELECT u.* FROM ' . $CFG->prefix . 'crlm_user AS u HAVING min(id)';
    $profile_fields = get_object_vars(current(get_records_sql($sql)));
    unset($profile_fields['id']);
    unset($profile_fields['idnumber']);
    $profile_fields = array_keys($profile_fields);
    return array_combine($profile_fields, $profile_fields);
}
Пример #27
0
 function display_search_field($value = '')
 {
     global $CFG;
     if (is_array($value)) {
         $content = $value['selected'];
         $allrequired = $value['allrequired'] ? 'checked = "checked"' : '';
     } else {
         $content = array();
         $allrequired = '';
     }
     static $c = 0;
     $str = '<select name="f_' . $this->field->id . '[]" multiple="multiple">';
     // display only used options
     $varcharcontent = sql_compare_text('content', 255);
     $sql = "SELECT DISTINCT {$varcharcontent} AS content\n                  FROM {$CFG->prefix}data_content\n                 WHERE fieldid={$this->field->id} AND content IS NOT NULL";
     $usedoptions = array();
     if ($used = get_records_sql($sql)) {
         foreach ($used as $data) {
             $valuestr = $data->content;
             if ($valuestr === '') {
                 continue;
             }
             $values = explode('##', $valuestr);
             foreach ($values as $value) {
                 $usedoptions[$value] = $value;
             }
         }
     }
     $found = false;
     foreach (explode("\n", $this->field->param1) as $option) {
         $option = trim($option);
         if (!isset($usedoptions[$option])) {
             continue;
         }
         $found = true;
         $str .= '<option value="' . s($option) . '"';
         if (in_array(addslashes($option), $content)) {
             // Selected by user.
             $str .= ' selected = "selected"';
         }
         $str .= '>' . $option . '</option>';
     }
     if (!$found) {
         // oh, nothing to search for
         return '';
     }
     $str .= '</select>';
     $str .= '&nbsp;<input name="f_' . $this->field->id . '_allreq" id="f_' . $this->field->id . '_allreq' . $c . '" type="checkbox" ' . $allrequired . '/>';
     $str .= '<label for="f_' . $this->field->id . '_allreq' . $c . '">' . get_string('selectedrequired', 'data') . '</label>';
     $c++;
     return $str;
 }
Пример #28
0
function template_user_delete($object_type, $event, $object)
{
    global $CFG, $data;
    if (!empty($object->ident) && $object_type == "user" && $event == "delete") {
        if ($templates = get_records_sql("select * from {$CFG->prefix}templates where owner = {$object->ident}")) {
            foreach ($templates as $template) {
                delete_records('template_elements', 'template_id', $template->ident);
            }
        }
        delete_records('templates', 'owner', $object->ident);
    }
    return $object;
}
 function add_items($list, $block)
 {
     global $CFG, $COURSE;
     // get list of mods used in course
     $modrecords = get_records_sql("SELECT DISTINCT m.id, m.name\n        FROM {$CFG->prefix}modules m, {$CFG->prefix}course_modules cm\n        WHERE cm.course = '{$COURSE->id}'\n        AND cm.module = m.id\n        AND cm.visible > 0\n        AND m.name != 'label'");
     // ignore labels
     if (!$modrecords) {
         return;
     }
     foreach ($modrecords as $mod) {
         $list["mod_{$mod->name}"] = new yui_menu_item_link($this, get_string('modulenameplural', $mod->name), "{$CFG->wwwroot}/mod/{$mod->name}/?id={$COURSE->id}", "{$CFG->modpixpath}/{$mod->name}/icon.gif");
     }
 }
/**
* refreshes the tree data if new responses where in in the meanwhile
*
*/
function hierarchize_refresh_tree($brainstormid, $groupid = 0)
{
    global $CFG, $USER;
    // get those responses who are new
    $sql = "\r\n        SELECT\r\n            r.id,r.id\r\n        FROM\r\n            {$CFG->prefix}brainstorm_responses as r\r\n        WHERE\r\n            r.brainstormid = {$brainstormid} AND\r\n            r.groupid = {$groupid} AND\r\n            r.id NOT IN\r\n        (SELECT\r\n            od.itemsource\r\n        FROM\r\n            {$CFG->prefix}brainstorm_operatordata as od\r\n        WHERE\r\n            od.brainstormid = {$brainstormid} AND\r\n            operatorid = 'hierarchize' AND\r\n            od.groupid = {$groupid} AND\r\n            od.userid = {$USER->id})\r\n    ";
    // echo $sql;
    $diff = get_records_sql($sql);
    $maxordering = brainstorm_tree_get_max_ordering($brainstormid, null, $groupid, 1, 0);
    if ($diff) {
        $treerecord->brainstormid = $brainstormid;
        $treerecord->userid = $USER->id;
        $treerecord->groupid = $groupid;
        $treerecord->operatorid = 'hierarchize';
        $treerecord->itemdest = 0;
        $treerecord->intvalue = $maxordering + 1;
        $treerecord->timemodified = time();
        foreach ($diff as $adif) {
            $treerecord->itemsource = $adif->id;
            if (!insert_record('brainstorm_operatordata', $treerecord)) {
                error("Could not insert tree regeneration records");
            }
            $treerecord->intvalue++;
        }
    }
}