コード例 #1
0
function fast_get_category_ex($hname, &$hstatus, $hparent = 0)
{
    // Find category with the given name and parentID, or create it, in both cases returning a category ID
    /* $hstatus:
           -1  :   Failed to create category
           1   :   Existing category found
           2   :   Created new category successfully
       */
    static $mysqlresource1;
    static $mysqlresource2;
    static $cat;
    static $cname;
    global $CFG;
    global $USER;
    $cname = mystr($hname);
    // Check if a category with the same name and parent ID already exists
    $mysqlresource1 = mysql_query('SELECT `id` FROM `' . $CFG->prefix . 'course_categories` WHERE `name` = ' . $cname . ' AND `parent` = ' . $hparent);
    if (mysql_num_rows($mysqlresource1)) {
        $cat = mysql_fetch_row($mysqlresource1);
        $hstatus = 1;
        return $cat[0];
    } else {
        // Create it - moodle does set sortorder to 999, and doesn't use the description field
        if (!($mysqlresource2 = mysql_query('INSERT INTO `' . $CFG->prefix . 'course_categories` (`name`,`description`,`parent`,`sortorder`,`coursecount`,`visible`,`timemodified`) VALUES (' . $cname . ',\'\',' . $hparent . ',999,0,1,0);'))) {
            // Failed!
            $hstatus = -1;
            return -1;
        } else {
            $hstatus = 2;
            return mysql_insert_id();
        }
    }
}
コード例 #2
0
function fastcreatecourse_ex($hcategory, $course, $header, $validate)
{
    if (!is_array($course) || !is_array($header) || !is_array($validate)) {
        return -2;
    }
    global $CFG;
    // declaring as static prevents object pointers being continually created and destroyed, saving time in theory
    static $courseid;
    static $mysqlresource1;
    static $mysqlresource2;
    static $mysqlresource3;
    static $mysqlresource4;
    static $dcomma;
    // Creating SQL for composite fields
    static $dtopics;
    static $dtopicno;
    static $dtopicname;
    static $dteachers;
    static $dteacherno;
    static $dteacherdata;
    // Dynamically Create Query Based on number of headings excluding Teacher[1,2,...] and Topic[1,2,...]
    // Added for increased functionality with newer versions of moodle
    // Author: Ashley Gooding & Cole Spicer
    static $tempstring;
    $query = 'INSERT INTO `' . $CFG->prefix . 'course` (`category`,';
    foreach ($header as $i => $col) {
        $col = strtolower($col);
        if (preg_match(TOPIC_FIELD, $col) || preg_match(TEACHER_FIELD, $col) || $col == 'category' || $col == 'template') {
            continue;
        }
        $query = $query . '`' . $col . '`,';
    }
    $query = $query . '`modinfo`) VALUES (' . $hcategory . ',';
    foreach ($header as $i => $col) {
        $col = strtolower($col);
        if (preg_match(TOPIC_FIELD, $col) || preg_match(TEACHER_FIELD, $col) || $col == 'category' || $col == 'template') {
            continue;
        }
        if ($col == 'expirythreshold') {
            $course[$col] = $course[$col] * 86400;
        }
        $temparray = explode(',', $validate[$col][1]);
        if ($validate[$col][0] == 1 || $validate[$col][0] == 4 && !checkisint($temparray[0])) {
            //String or Domain with strings
            $query = $query . '' . mystr($course[$col]) . ', ';
        } else {
            $query = $query . '' . $course[$col] . ', ';
        }
    }
    $query = $query . ' \'\');';
    // End Dynamic Query
    if (!($mysqlresource2 = mysql_query($query))) {
        return -2;
    }
    $courseid = mysql_insert_id();
    if (isset($course['template']) && $course['template'] != '') {
        if (!($mysqlresource6 = mysql_query('SELECT `id` FROM `' . $CFG->prefix . 'course` WHERE `shortname`=\'' . $course['template'] . '\';'))) {
            return -7;
        }
        if (!mysql_num_rows($mysqlresource6)) {
            return -7;
        }
        $row = mysql_fetch_row($mysqlresource6);
        $id = $row[0];
        if (!($mysqlresource7 = mysql_query(' INSERT INTO `' . $CFG->prefix . 'block_instance` ( `blockid` , `pageid` , `pagetype` , `position` , `weight` , `visible` , `configdata` ) SELECT `blockid` , ' . $courseid . ', `pagetype` , `position` , `weight` , `visible` , `configdata` FROM `' . $CFG->prefix . 'block_instance` WHERE `pageid` = ' . $id . ';'))) {
            return -8;
        }
    } else {
        $page = page_create_object(PAGE_COURSE_VIEW, $courseid);
        blocks_repopulate_page($page);
        // Setup blocks
    }
    $dtopics = '';
    // String concatenation for topic INSERT
    $dcomma = false;
    // Should we add a comma before the next item?
    if (isset($course['topics'])) {
        // Any topic headings specified ?
        foreach ($course['topics'] as $dtopicno => $dtopicname) {
            if ($dtopicno <= $course['numsections']) {
                // Avoid overflowing topic headings
                if ($dcomma == true) {
                    $dtopics .= ',';
                } else {
                    $dcomma = true;
                }
                $dtopics .= '(' . $courseid . ',' . mystr($dtopicno) . ',' . mystr($dtopicname) . ',\'\',\'1\')';
            }
        }
    }
    if (!isset($course['topics'][0])) {
        // Ensure at least default topic section exists
        if ($dcomma == true) {
            $dtopics .= ',';
        } else {
            $dcomma = true;
        }
        $dtopics .= '(\'' . $courseid . '\',\'0\',\'\',\'\',\'1\');';
    } else {
        $dtopics .= ';';
    }
    if (!($mysqlresource3 = mysql_query('INSERT INTO `' . $CFG->prefix . 'course_sections` (`course`,`section`,`summary`,`sequence`,`visible`) VALUES ' . $dtopics))) {
        return -3;
    }
    $dteachers = '';
    // String concatenation for topic INSERT
    $dcomma = false;
    // Should we add a comma before the next item?
    // SELECT id FROM mdl_role WHERE name = blah
    // use that id and change insert to:
    // mdl_role_assignments
    // roleid   	 contextid   	 userid   	timemodified   	 modifierid   	 enrol
    //               courseshit                                       0         'manual'
    // If SELECT id...  doesnt work (returns false or contians no items) then throw error
    $roleid;
    if (!($context = get_context_instance(CONTEXT_COURSE, $courseid))) {
        return -6;
    }
    if (isset($course['teachers_enrol']) && count($course['teachers_enrol']) > 0) {
        // Any teachers specified?
        foreach ($course['teachers_enrol'] as $dteacherno => $dteacherdata) {
            if (isset($dteacherdata['_account'])) {
                if ($dcomma == true) {
                    $dteachers .= ',';
                } else {
                    $dcomma = true;
                }
                if (!($mysqlresource5 = mysql_query('SELECT `id` FROM `' . $CFG->prefix . 'role` WHERE `shortname`=\'' . $dteacherdata['_role'] . '\';'))) {
                    return -5;
                }
                if (!mysql_num_rows($mysqlresource5)) {
                    return -5;
                }
                $row = mysql_fetch_row($mysqlresource5);
                $dteachers .= '(' . $row[0] . ',' . $context->id . ',' . $dteacherdata['_account'] . ',' . $course['timecreated'] . ',0,\'manual\');';
            }
        }
        if ($dteachers != '') {
            if (!($mysqlresource4 = mysql_query('INSERT INTO `' . $CFG->prefix . 'role_assignments` (`roleid`,`contextid`,`userid`,`timemodified`,`modifierid`,`enrol`) VALUES ' . $dteachers))) {
                return -4;
            }
        }
    }
    return 1;
}
コード例 #3
0
ファイル: getimage.php プロジェクト: tanny2015/DataStructure
function GetRValue($col)
{
    return hexdec(substr($col, 1, 2));
}
function GetGValue($col)
{
    return hexdec(substr($col, 3, 2));
}
function GetBValue($col)
{
    return hexdec(substr($col, 5, 2));
}
header("Content-type: image/png");
$fontface = "./images/courbd.ttf";
$fontcolor = array("#336666", "#336699", "#990066", "#CC6600", "#009933");
$verifyNum = mystr(4);
if (isset($_GET['do']) && $_GET['do'] == "topic") {
    @setcookie("topicVerify", md5(base64_encode(md5(strtolower($verifyNum)))));
}
if (isset($_GET['do']) && $_GET['do'] == "reply") {
    @setcookie("replyVerify", md5(base64_encode(md5(strtolower($verifyNum)))));
}
$im_w = 130;
$im_h = 53;
$im = imagecreate($im_w, $im_h);
imagecolorallocatealpha($im, 255, 255, 255, 100);
$col = $fontcolor[rand(1, count($fontcolor)) - 1];
$color = imagecolorallocate($im, GetRValue($col), GetGValue($col), GetBValue($col));
imagettftext($im, 32, 0, 8, 38, $color, $fontface, $verifyNum);
wave_region($im, 0, 0, $im_w, $im_h, 6);
imagepng($im);